summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/command.c69
-rw-r--r--lib/command.h1
-rw-r--r--vtysh/vtysh.c52
3 files changed, 54 insertions, 68 deletions
diff --git a/lib/command.c b/lib/command.c
index 20841604..37767e92 100644
--- a/lib/command.c
+++ b/lib/command.c
@@ -2794,34 +2794,69 @@ cmd_execute_command_strict (vector vline, struct vty *vty,
return cmd_execute_command_real(vline, FILTER_STRICT, vty, cmd);
}
+/**
+ * Parse one line of config, walking up the parse tree attempting to find a match
+ *
+ * @param vty The vty context in which the command should be executed.
+ * @param cmd Pointer where the struct cmd_element* of the match command
+ * will be stored, if any. May be set to NULL if this info is
+ * not needed.
+ * @param use_daemon Boolean to control whether or not we match on CMD_SUCCESS_DAEMON
+ * or not.
+ * @return The status of the command that has been executed or an error code
+ * as to why no command could be executed.
+ */
+int
+command_config_read_one_line (struct vty *vty, struct cmd_element **cmd, int use_daemon)
+{
+ vector vline;
+ int saved_node;
+ int ret;
+
+ vline = cmd_make_strvec (vty->buf);
+
+ /* In case of comment line */
+ if (vline == NULL)
+ return CMD_SUCCESS;
+
+ /* Execute configuration command : this is strict match */
+ ret = cmd_execute_command_strict (vline, vty, cmd);
+
+ saved_node = vty->node;
+
+ while (!(use_daemon && ret == CMD_SUCCESS_DAEMON) &&
+ ret != CMD_SUCCESS && ret != CMD_WARNING &&
+ ret != CMD_ERR_NOTHING_TODO && vty->node != CONFIG_NODE) {
+ vty->node = node_parent(vty->node);
+ ret = cmd_execute_command_strict (vline, vty, NULL);
+ }
+
+ // If climbing the tree did not work then ignore the command and
+ // stay at the same node
+ if (!(use_daemon && ret == CMD_SUCCESS_DAEMON) &&
+ ret != CMD_SUCCESS && ret != CMD_WARNING &&
+ ret != CMD_ERR_NOTHING_TODO)
+ {
+ vty->node = saved_node;
+ }
+
+ cmd_free_strvec (vline);
+
+ return ret;
+}
+
/* Configration make from file. */
int
config_from_file (struct vty *vty, FILE *fp, unsigned int *line_num)
{
int ret;
*line_num = 0;
- vector vline;
while (fgets (vty->buf, VTY_BUFSIZ, fp))
{
++(*line_num);
- vline = cmd_make_strvec (vty->buf);
-
- /* In case of comment line */
- if (vline == NULL)
- continue;
- /* Execute configuration command : this is strict match */
- ret = cmd_execute_command_strict (vline, vty, NULL);
-
- /* Try again with setting node to CONFIG_NODE */
- while (ret != CMD_SUCCESS && ret != CMD_WARNING
- && ret != CMD_ERR_NOTHING_TODO && vty->node != CONFIG_NODE)
- {
- vty->node = node_parent(vty->node);
- ret = cmd_execute_command_strict (vline, vty, NULL);
- }
- cmd_free_strvec (vline);
+ ret = command_config_read_one_line (vty, NULL, 0);
if (ret != CMD_SUCCESS && ret != CMD_WARNING
&& ret != CMD_ERR_NOTHING_TODO)
diff --git a/lib/command.h b/lib/command.h
index bb0122fa..6030069a 100644
--- a/lib/command.h
+++ b/lib/command.h
@@ -527,6 +527,7 @@ extern void cmd_free_strvec (vector);
extern vector cmd_describe_command (vector, struct vty *, int *status);
extern char **cmd_complete_command (vector, struct vty *, int *status);
extern const char *cmd_prompt (enum node_type);
+extern int command_config_read_one_line (struct vty *vty, struct cmd_element **, int use_config_node);
extern int config_from_file (struct vty *, FILE *, unsigned int *line_num);
extern enum node_type node_parent (enum node_type);
extern int cmd_execute_command (vector, struct vty *, struct cmd_element **, int);
diff --git a/vtysh/vtysh.c b/vtysh/vtysh.c
index 783c383c..b55c6719 100644
--- a/vtysh/vtysh.c
+++ b/vtysh/vtysh.c
@@ -251,14 +251,6 @@ vtysh_client_execute (struct vtysh_client *vclient, const char *line, FILE *fp)
}
}
-static void
-vtysh_exit_ripd_only (void)
-{
- if (ripd_client)
- vtysh_client_execute (ripd_client, "exit", stdout);
-}
-
-
void
vtysh_pager_init (void)
{
@@ -457,53 +449,11 @@ int
vtysh_config_from_file (struct vty *vty, FILE *fp)
{
int ret;
- vector vline;
struct cmd_element *cmd;
while (fgets (vty->buf, VTY_BUFSIZ, fp))
{
- if (vty->buf[0] == '!' || vty->buf[1] == '#')
- continue;
-
- vline = cmd_make_strvec (vty->buf);
-
- /* In case of comment line. */
- if (vline == NULL)
- continue;
-
- /* Execute configuration command : this is strict match. */
- ret = cmd_execute_command_strict (vline, vty, &cmd);
-
- /* Try again with setting node to CONFIG_NODE. */
- if (ret != CMD_SUCCESS
- && ret != CMD_SUCCESS_DAEMON
- && ret != CMD_WARNING)
- {
- if (vty->node == KEYCHAIN_KEY_NODE)
- {
- vty->node = KEYCHAIN_NODE;
- vtysh_exit_ripd_only ();
- ret = cmd_execute_command_strict (vline, vty, &cmd);
-
- if (ret != CMD_SUCCESS
- && ret != CMD_SUCCESS_DAEMON
- && ret != CMD_WARNING)
- {
- vtysh_exit_ripd_only ();
- vty->node = CONFIG_NODE;
- ret = cmd_execute_command_strict (vline, vty, &cmd);
- }
- }
- else
- {
- vtysh_execute ("end");
- vtysh_execute ("configure terminal");
- vty->node = CONFIG_NODE;
- ret = cmd_execute_command_strict (vline, vty, &cmd);
- }
- }
-
- cmd_free_strvec (vline);
+ ret = command_config_read_one_line (vty, &cmd, 1);
switch (ret)
{