diff options
author | Daniel Walton <dwalton@cumulusnetworks.com> | 2015-07-28 05:30:22 +0200 |
---|---|---|
committer | Daniel Walton <dwalton@cumulusnetworks.com> | 2015-07-28 05:30:22 +0200 |
commit | 5689fe5fefdb6f9f4f5dcb73cc863f44db76aa78 (patch) | |
tree | aa155c345c9f4f2e763827f9f19982103724d5b2 /lib | |
parent | Cause warnings to not build correctly in debian packaging (diff) | |
download | frr-5689fe5fefdb6f9f4f5dcb73cc863f44db76aa78.tar.xz frr-5689fe5fefdb6f9f4f5dcb73cc863f44db76aa78.zip |
Quagga processes should not die if they read an unrecognized line in
their config file
Ticket: CM-6738
Reviewed By: Donald and Dinesh
Testing Done:
<DETAILED DESCRIPTION (REPLACE)>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/command.c | 47 | ||||
-rw-r--r-- | lib/vty.c | 15 | ||||
-rw-r--r-- | lib/vty.h | 3 |
3 files changed, 45 insertions, 20 deletions
diff --git a/lib/command.c b/lib/command.c index b034369d9..d487ce4e7 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", @@ -322,6 +322,7 @@ vty_new () new->obuf = buffer_new(0); /* Use default buffer size. */ new->buf = XCALLOC (MTYPE_VTY, VTY_BUFSIZ); + new->error_buf = XCALLOC (MTYPE_VTY, VTY_BUFSIZ); new->max = VTY_BUFSIZ; return new; @@ -478,6 +479,7 @@ vty_ensure (struct vty *vty, int length) { vty->max *= 2; vty->buf = XREALLOC (MTYPE_VTY, vty->buf, vty->max); + vty->error_buf = XREALLOC (MTYPE_VTY, vty->error_buf, vty->max); } } @@ -2195,6 +2197,9 @@ vty_close (struct vty *vty) if (vty->buf) XFREE (MTYPE_VTY, vty->buf); + if (vty->error_buf) + XFREE (MTYPE_VTY, vty->error_buf); + /* Check configure. */ vty_config_unlock (vty); @@ -2243,16 +2248,14 @@ vty_read_file (FILE *confp) switch (ret) { case CMD_ERR_AMBIGUOUS: - fprintf (stderr, "Ambiguous command.\n"); + fprintf (stderr, "\nAmbiguous command."); break; case CMD_ERR_NO_MATCH: - fprintf (stderr, "There is no such command.\n"); + fprintf (stderr, "\nThere is no such command."); break; } - fprintf (stderr, "Error occured during reading below line.\n%s\n", - vty->buf); - vty_close (vty); - exit (1); + fprintf (stderr, "\nError occured during reading below line.\n%s\n", + vty->error_buf); } vty_close (vty); @@ -49,6 +49,9 @@ struct vty /* Command input buffer */ char *buf; + /* Command input error buffer */ + char *error_buf; + /* Command cursor point */ int cp; |