diff options
Diffstat (limited to 'lib/command.c')
| -rw-r--r-- | lib/command.c | 47 |
1 files changed, 33 insertions, 14 deletions
diff --git a/lib/command.c b/lib/command.c index b034369d98..d487ce4e73 100644 --- a/lib/command.c +++ b/lib/command.c @@ -2761,11 +2761,12 @@ cmd_execute_command_strict (vector vline, struct vty *vty, return cmd_execute_command_real(vline, FILTER_STRICT, vty, cmd); } -/* Configration make from file. */ +/* Configuration make from file. */ int config_from_file (struct vty *vty, FILE *fp) { - int ret; + int ret, error_ret=0; + int saved_node; vector vline; while (fgets (vty->buf, VTY_BUFSIZ, fp)) @@ -2778,24 +2779,42 @@ config_from_file (struct vty *vty, FILE *fp) /* 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); - } + // Climb the tree and try the command again at each node + if (ret != CMD_SUCCESS && ret != CMD_WARNING && + ret != CMD_ERR_NOTHING_TODO && vty->node != CONFIG_NODE) { - cmd_free_strvec (vline); + saved_node = vty->node; - if (ret != CMD_SUCCESS && ret != CMD_WARNING - && ret != CMD_ERR_NOTHING_TODO) - return ret; + 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); + } + + // If climbing the tree did not work then ignore the command and + // stay at the same node + if (ret != CMD_SUCCESS && ret != CMD_WARNING && + ret != CMD_ERR_NOTHING_TODO) { + vty->node = saved_node; + + if (!error_ret) { + memcpy(vty->error_buf, vty->buf, VTY_BUFSIZ); + error_ret = ret; + } + } + } + + cmd_free_strvec (vline); } + + if (error_ret) { + return error_ret; + } + return CMD_SUCCESS; } -/* Configration from terminal */ +/* Configuration from terminal */ DEFUN (config_terminal, config_terminal_cmd, "configure terminal", |
