[PATCH] libosmocore[master]: VTY: never look for matching commands on parent node

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

Neels Hofmeyr gerrit-no-reply at lists.osmocom.org
Thu Sep 7 04:09:50 UTC 2017


Review at  https://gerrit.osmocom.org/3881

VTY: never look for matching commands on parent node

For interactive telnet VTY, remove the implicit move up to the parent node when
a command did not succeed on the current node level.

When reading config files, this behavior was useful to allow skipping explicit
'exit' commands. (A different patch deals with that.)

In the telnet VTY, this behavior was never necessary. Explicit 'exit' commands
can move to the parent node, and typically uninformed users expect to require
that.

On a telnet VTY, counting indents like for reading config files is not an
option: a user will always type from the first column or may paste some leading
spaces without intended meaning.

After this patch, it is thus no longer possible to paste a complete config
across several node levels directly to a telnet session, unless it contains
'exit' commands.

Change-Id: Id73cba2dd34676bad8a130e9c45e67a272f19588
---
M src/vty/command.c
M tests/vty/vty_test.c
M tests/vty/vty_test.ok
3 files changed, 5 insertions(+), 33 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/81/3881/1

diff --git a/src/vty/command.c b/src/vty/command.c
index aa5d0d8..9161bf5 100644
--- a/src/vty/command.c
+++ b/src/vty/command.c
@@ -2155,12 +2155,10 @@
 cmd_execute_command(vector vline, struct vty *vty, struct cmd_element **cmd,
 		    int vtysh)
 {
-	int ret, saved_ret, tried = 0;
+	int ret;
 	enum node_type onode;
-	void *oindex;
 
 	onode = vty->node;
-	oindex = vty->index;
 
 	if (cmd_try_do_shortcut(vty->node, vector_slot(vline, 0))) {
 		vector shifted_vline;
@@ -2183,29 +2181,7 @@
 		return ret;
 	}
 
-	saved_ret = ret = cmd_execute_command_real(vline, vty, cmd);
-
-	if (vtysh)
-		return saved_ret;
-
-	/* Go to parent for config nodes to attempt to find the right command */
-	while (ret != CMD_SUCCESS && ret != CMD_WARNING
-	       && is_config_child(vty)) {
-		vty_go_parent(vty);
-		ret = cmd_execute_command_real(vline, vty, cmd);
-		tried = 1;
-		if (ret == CMD_SUCCESS || ret == CMD_WARNING) {
-			/* succesfull command, leave the node as is */
-			return ret;
-		}
-	}
-	/* no command succeeded, reset the vty to the original node and
-	   return the error for this node */
-	if (tried) {
-		vty->node = onode;
-		vty->index = oindex;
-	}
-	return saved_ret;
+	return cmd_execute_command_real(vline, vty, cmd);
 }
 
 /* Execute command by argument readline. */
diff --git a/tests/vty/vty_test.c b/tests/vty/vty_test.c
index e24045c..63b0b03 100644
--- a/tests/vty/vty_test.c
+++ b/tests/vty/vty_test.c
@@ -156,14 +156,12 @@
 	OSMO_ASSERT(vty->node == ENABLE_NODE);
 
 
-	/* Check searching the parents nodes for matching commands. */
+	/* Check for not searching the parent node for matching commands. */
 	OSMO_ASSERT(do_vty_command(vty, "configure terminal") == CMD_SUCCESS);
 	OSMO_ASSERT(vty->node == CONFIG_NODE);
 	OSMO_ASSERT(do_vty_command(vty, "log stderr") == CMD_SUCCESS);
 	OSMO_ASSERT(vty->node == CFG_LOG_NODE);
-	OSMO_ASSERT(do_vty_command(vty, "line vty") == CMD_SUCCESS);
-	OSMO_ASSERT(vty->node == VTY_NODE);
-	OSMO_ASSERT(do_vty_command(vty, "log stderr") == CMD_SUCCESS);
+	OSMO_ASSERT(do_vty_command(vty, "line vty") == CMD_ERR_NO_MATCH);
 	OSMO_ASSERT(vty->node == CFG_LOG_NODE);
 	OSMO_ASSERT(do_vty_command(vty, "end") == CMD_SUCCESS);
 	OSMO_ASSERT(vty->node == ENABLE_NODE);
diff --git a/tests/vty/vty_test.ok b/tests/vty/vty_test.ok
index 00b0853..0da0c2f 100644
--- a/tests/vty/vty_test.ok
+++ b/tests/vty/vty_test.ok
@@ -36,9 +36,7 @@
 Going to execute 'log stderr'
 Returned: 0, Current node: 7 '%s(config-log)# '
 Going to execute 'line vty'
-Returned: 0, Current node: 9 '%s(config-line)# '
-Going to execute 'log stderr'
-Returned: 0, Current node: 7 '%s(config-log)# '
+Returned: 2, Current node: 7 '%s(config-log)# '
 Going to execute 'end'
 Returned: 0, Current node: 3 '%s# '
 Going to execute 'exit'

-- 
To view, visit https://gerrit.osmocom.org/3881
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Id73cba2dd34676bad8a130e9c45e67a272f19588
Gerrit-PatchSet: 1
Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Owner: Neels Hofmeyr <nhofmeyr at sysmocom.de>



More information about the gerrit-log mailing list