summaryrefslogtreecommitdiffstats
path: root/vtysh
diff options
context:
space:
mode:
authorhasso <hasso>2005-01-23 22:42:25 +0100
committerhasso <hasso>2005-01-23 22:42:25 +0100
commit13bfca7a1059a73a836f4813170f296a82266211 (patch)
treeb22e29cb43472038769502685209badf3302e7dd /vtysh
parent * vtysh.conf.sample: Fix typo "integrated-vtysh-conf" -> (diff)
downloadfrr-13bfca7a1059a73a836f4813170f296a82266211.tar.xz
frr-13bfca7a1059a73a836f4813170f296a82266211.zip
* lib/command.[ch]: Make node_parent() function nonstatic. vtyh.c will
use it as well. * vtysh/vtysh.c: Implement walkup in node tree for vtysh as it already works in vty.
Diffstat (limited to 'vtysh')
-rw-r--r--vtysh/ChangeLog2
-rw-r--r--vtysh/vtysh.c47
2 files changed, 47 insertions, 2 deletions
diff --git a/vtysh/ChangeLog b/vtysh/ChangeLog
index 1cc1fb8ff..e142f150a 100644
--- a/vtysh/ChangeLog
+++ b/vtysh/ChangeLog
@@ -2,6 +2,8 @@
* vtysh.conf.sample: Fix typo "integrated-vtysh-conf" ->
"integrated-vtysh-config".
+ * vtysh/vtysh.c: Implement walkup in node tree for vtysh as it
+ already works in vty.
2005-01-10 Hasso Tepper <hasso at quagga.net>
diff --git a/vtysh/vtysh.c b/vtysh/vtysh.c
index 6ece45f84..a9929c525 100644
--- a/vtysh/vtysh.c
+++ b/vtysh/vtysh.c
@@ -254,7 +254,9 @@ vtysh_execute_func (const char *line, int pager)
vector vline;
struct cmd_element *cmd;
FILE *fp = NULL;
- int closepager=0;
+ int closepager = 0;
+ int tried = 0;
+ int saved_ret, saved_node;
/* Split readline string up into the vector. */
vline = cmd_make_strvec (line);
@@ -262,7 +264,48 @@ vtysh_execute_func (const char *line, int pager)
if (vline == NULL)
return;
- ret = cmd_execute_command (vline, vty, &cmd, 1);
+ saved_ret = ret = cmd_execute_command (vline, vty, &cmd, 1);
+ saved_node = vty->node;
+
+ /* If command doesn't succeeded in current node, try to walk up in node tree.
+ * Changing vty->node is enough to try it just out without actual walkup in
+ * the vtysh. */
+ while (ret != CMD_SUCCESS && ret != CMD_SUCCESS_DAEMON && ret != CMD_WARNING
+ && vty->node > CONFIG_NODE)
+ {
+ vty->node = node_parent(vty->node);
+ ret = cmd_execute_command (vline, vty, &cmd, 1);
+ tried++;
+ }
+
+ vty->node = saved_node;
+
+ /* If command succeeded in any other node than current (tried > 0) we have
+ * to move into node in the vtysh where it succeeded. */
+ if (ret == CMD_SUCCESS || ret == CMD_SUCCESS_DAEMON || ret == CMD_WARNING)
+ {
+ if ((saved_node == BGP_VPNV4_NODE || saved_node == BGP_IPV4_NODE
+ || saved_node == BGP_IPV6_NODE || saved_node == BGP_IPV4M_NODE)
+ && (tried == 1))
+ {
+ vtysh_execute("exit-address-family");
+ }
+ else if ((saved_node == KEYCHAIN_KEY_NODE) && (tried == 1))
+ {
+ vtysh_execute("exit");
+ }
+ else if (tried)
+ {
+ vtysh_execute ("end");
+ vtysh_execute ("configure terminal");
+ }
+ }
+ /* If command didn't succeed in any node, continue with return value from
+ * first try. */
+ else if (tried)
+ {
+ ret = saved_ret;
+ }
cmd_free_strvec (vline);