[PATCH] libosmocore[master]: vty: install 'exit', 'end', ... commands on *all* nodes

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
Sun Sep 24 21:01:51 UTC 2017


Hello Harald Welte, Jenkins Builder,

I'd like you to reexamine a change.  Please visit

    https://gerrit.osmocom.org/3998

to look at the new patch set (#3).

vty: install 'exit', 'end',... commands on *all* nodes

In many callers of the VTY API, we are lacking the vty_install_default() step
at certain node levels. This creates nodes that lack the 'exit' command, and
hence the only way to exit such a node is to restart the telnet session.

Historically, the VTY looked for missing commands on the immediate parent node,
and hence possibly found the parent's 'exit' command when the local node was
missing it. That is why we so far did not notice the missing default commands.

Furthermore, some callers call install_default() instead of
vty_install_default(). Only vty_install_default() also includes the 'exit' and
'end' commands. There is no reason why there are two sets of default commands.

To end this confusion, to catch all missing 'exit' commands and to prevent this
from re-appearing in the future, simply *always* install all default commands
implicitly when calling install_node().

In cmd_init(), there are some top-level nodes that apparently do not want the
default commands installed. Keep those the way they are, by changing the
invocation to new install_node_bare() ({VIEW,AUTH,AUTH_ENABLE}_NODE).

Make both install_default() and vty_install_default() no-ops so that users of
the API may still call them without harm. Do not yet deprecate yet, which
follows in Icf5d83f641e838cebcccc635a043e94ba352abff.

Drop all invocations to these two functions found in libosmocore.

Change-Id: I5021c64a787b63314e0f2f1cba0b8fc7bff4f09b
---
M include/osmocom/vty/command.h
M src/ctrl/control_vty.c
M src/gb/gprs_bssgp_vty.c
M src/gb/gprs_ns_vty.c
M src/vty/command.c
M src/vty/logging_vty.c
M src/vty/stats_vty.c
M src/vty/vty.c
M tests/vty/vty_test.c
9 files changed, 31 insertions(+), 25 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/98/3998/3

diff --git a/include/osmocom/vty/command.h b/include/osmocom/vty/command.h
index 58f248f..8fbdb7b 100644
--- a/include/osmocom/vty/command.h
+++ b/include/osmocom/vty/command.h
@@ -27,6 +27,8 @@
 #include <sys/types.h>
 #include "vector.h"
 
+#include <osmocom/core/defs.h>
+
 /*! \defgroup command VTY Command
  *  @{
  * \file command.h */
@@ -363,9 +365,6 @@
 void install_element_ve(struct cmd_element *cmd);
 void sort_node(void);
 
-/* This is similar to install_default() but it also creates
- * 'exit' and 'end' commands.
- */
 void vty_install_default(int node_type);
 
 /* Concatenates argv[shift] through argv[argc-1] into a single NUL-terminated
diff --git a/src/ctrl/control_vty.c b/src/ctrl/control_vty.c
index 97f42de..a968bc0 100644
--- a/src/ctrl/control_vty.c
+++ b/src/ctrl/control_vty.c
@@ -82,7 +82,6 @@
 	ctrl_vty_ctx = ctx;
 	install_element(CONFIG_NODE, &cfg_ctrl_cmd);
 	install_node(&ctrl_node, config_write_ctrl);
-	vty_install_default(L_CTRL_NODE);
 
 	install_element(L_CTRL_NODE, &cfg_ctrl_bind_addr_cmd);
 	return 0;
diff --git a/src/gb/gprs_bssgp_vty.c b/src/gb/gprs_bssgp_vty.c
index 703d130..2953f88 100644
--- a/src/gb/gprs_bssgp_vty.c
+++ b/src/gb/gprs_bssgp_vty.c
@@ -211,7 +211,6 @@
 
 	install_element(CONFIG_NODE, &cfg_bssgp_cmd);
 	install_node(&bssgp_node, config_write_bssgp);
-	install_default(L_BSSGP_NODE);
 	install_element(L_BSSGP_NODE, &libgb_exit_cmd);
 	install_element(L_BSSGP_NODE, &libgb_end_cmd);
 
diff --git a/src/gb/gprs_ns_vty.c b/src/gb/gprs_ns_vty.c
index e320ba2..547c9b8 100644
--- a/src/gb/gprs_ns_vty.c
+++ b/src/gb/gprs_ns_vty.c
@@ -594,7 +594,6 @@
 
 	install_element(CONFIG_NODE, &cfg_ns_cmd);
 	install_node(&ns_node, config_write_ns);
-	install_default(L_NS_NODE);
 	install_element(L_NS_NODE, &libgb_exit_cmd);
 	install_element(L_NS_NODE, &libgb_end_cmd);
 	install_element(L_NS_NODE, &cfg_nse_nsvci_cmd);
diff --git a/src/vty/command.c b/src/vty/command.c
index 8ad2e97..21b26b4 100644
--- a/src/vty/command.c
+++ b/src/vty/command.c
@@ -149,14 +149,23 @@
 	return name_buf;
 }
 
-/*! Install top node of command vector. */
-void install_node(struct cmd_node *node, int (*func) (struct vty *))
+static void install_basic_node_commands(int node);
+
+/*! Install top node of command vector, without adding basic node commands. */
+static void install_node_bare(struct cmd_node *node, int (*func) (struct vty *))
 {
 	vector_set_index(cmdvec, node->node, node);
 	node->func = func;
 	node->cmd_vector = vector_init(VECTOR_MIN_SIZE);
 	if (!*node->name)
 		node_name_from_prompt(node->prompt, node->name, sizeof(node->name));
+}
+
+/*! Install top node of command vector. */
+void install_node(struct cmd_node *node, int (*func) (struct vty *))
+{
+	install_node_bare(node, func);
+	install_basic_node_commands(node->node);
 }
 
 /* Compare two command's string.  Used in sort_node (). */
@@ -3599,7 +3608,22 @@
 	host.config = talloc_strdup(tall_vty_cmd_ctx, filename);
 }
 
+/*! Deprecated, now happens implicitly when calling install_node().
+ * Users of the API may still attempt to call this function, hence
+ * leave it here as a no-op. */
 void install_default(int node)
+{
+}
+
+/*! Deprecated, now happens implicitly when calling install_node().
+ * Users of the API may still attempt to call this function, hence
+ * leave it here as a no-op. */
+void vty_install_default(int node)
+{
+}
+
+/*! Install common commands like 'exit' and 'list'. */
+static void install_basic_node_commands(int node)
 {
 	install_element(node, &config_help_cmd);
 	install_element(node, &config_list_cmd);
@@ -3609,11 +3633,6 @@
 	install_element(node, &config_write_memory_cmd);
 	install_element(node, &config_write_cmd);
 	install_element(node, &show_running_config_cmd);
-}
-
-void vty_install_default(int node)
-{
-	install_default(node);
 
 	install_element(node, &config_exit_cmd);
 
@@ -3681,10 +3700,10 @@
 	host.motdfile = NULL;
 
 	/* Install top nodes. */
-	install_node(&view_node, NULL);
+	install_node_bare(&view_node, NULL);
 	install_node(&enable_node, NULL);
-	install_node(&auth_node, NULL);
-	install_node(&auth_enable_node, NULL);
+	install_node_bare(&auth_node, NULL);
+	install_node_bare(&auth_enable_node, NULL);
 	install_node(&config_node, config_write_host);
 
 	/* Each node's basic commands. */
@@ -3701,7 +3720,6 @@
 	}
 
 	if (terminal) {
-		vty_install_default(ENABLE_NODE);
 		install_element(ENABLE_NODE, &config_disable_cmd);
 		install_element(ENABLE_NODE, &config_terminal_cmd);
 		install_element (ENABLE_NODE, &copy_runningconfig_startupconfig_cmd);
@@ -3714,8 +3732,6 @@
 		install_element(ENABLE_NODE, &config_terminal_length_cmd);
 		install_element(ENABLE_NODE, &config_terminal_no_length_cmd);
 		install_element(ENABLE_NODE, &echo_cmd);
-
-		vty_install_default(CONFIG_NODE);
 	}
 
 	install_element(CONFIG_NODE, &hostname_cmd);
diff --git a/src/vty/logging_vty.c b/src/vty/logging_vty.c
index 01480b1..0ab7686 100644
--- a/src/vty/logging_vty.c
+++ b/src/vty/logging_vty.c
@@ -776,7 +776,6 @@
 	install_element_ve(&show_alarms_cmd);
 
 	install_node(&cfg_log_node, config_write_log);
-	vty_install_default(CFG_LOG_NODE);
 	install_element(CFG_LOG_NODE, &logging_fltr_all_cmd);
 	install_element(CFG_LOG_NODE, &logging_use_clr_cmd);
 	install_element(CFG_LOG_NODE, &logging_prnt_timestamp_cmd);
diff --git a/src/vty/stats_vty.c b/src/vty/stats_vty.c
index 57cdd30..a4c73fa 100644
--- a/src/vty/stats_vty.c
+++ b/src/vty/stats_vty.c
@@ -594,7 +594,6 @@
 	install_element(CONFIG_NODE, &cfg_stats_interval_cmd);
 
 	install_node(&cfg_stats_node, config_write_stats);
-	vty_install_default(CFG_STATS_NODE);
 
 	install_element(CFG_STATS_NODE, &cfg_stats_reporter_local_ip_cmd);
 	install_element(CFG_STATS_NODE, &cfg_no_stats_reporter_local_ip_cmd);
diff --git a/src/vty/vty.c b/src/vty/vty.c
index bd0d2c3..3d76b7a 100644
--- a/src/vty/vty.c
+++ b/src/vty/vty.c
@@ -1798,7 +1798,6 @@
 	install_element(ENABLE_NODE, &terminal_monitor_cmd);
 	install_element(ENABLE_NODE, &terminal_no_monitor_cmd);
 
-	vty_install_default(VTY_NODE);
 	install_element(VTY_NODE, &vty_login_cmd);
 	install_element(VTY_NODE, &no_vty_login_cmd);
 	install_element(VTY_NODE, &vty_bind_cmd);
diff --git a/tests/vty/vty_test.c b/tests/vty/vty_test.c
index fe50e4c..2542baf 100644
--- a/tests/vty/vty_test.c
+++ b/tests/vty/vty_test.c
@@ -386,17 +386,14 @@
 {
 	install_element(CONFIG_NODE, &cfg_level1_cmd);
 	install_node(&level1_node, NULL);
-	vty_install_default(LEVEL1_NODE);
 	install_element(LEVEL1_NODE, &cfg_level1_child_cmd);
 	install_element(LEVEL1_NODE, &cfg_level2_cmd);
 
 	install_node(&level2_node, NULL);
-	vty_install_default(LEVEL2_NODE);
 	install_element(LEVEL2_NODE, &cfg_level2_child_cmd);
 	install_element(LEVEL2_NODE, &cfg_level3_cmd);
 
 	install_node(&level3_node, NULL);
-	vty_install_default(LEVEL3_NODE);
 	install_element(LEVEL3_NODE, &cfg_level3_child_cmd);
 }
 

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

Gerrit-MessageType: newpatchset
Gerrit-Change-Id: I5021c64a787b63314e0f2f1cba0b8fc7bff4f09b
Gerrit-PatchSet: 3
Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Owner: Neels Hofmeyr <nhofmeyr at sysmocom.de>
Gerrit-Reviewer: Harald Welte <laforge at gnumonks.org>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: Neels Hofmeyr <nhofmeyr at sysmocom.de>



More information about the gerrit-log mailing list