summaryrefslogtreecommitdiff
path: root/lib/command.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/command.c')
-rw-r--r--lib/command.c202
1 files changed, 120 insertions, 82 deletions
diff --git a/lib/command.c b/lib/command.c
index de8899687c..a631cf1c6e 100644
--- a/lib/command.c
+++ b/lib/command.c
@@ -433,27 +433,27 @@ static int
config_write_host (struct vty *vty)
{
if (host.name)
- vty_outln (vty, "hostname %s", host.name);
+ vty_out (vty, "hostname %s\n", host.name);
if (host.encrypt)
{
if (host.password_encrypt)
- vty_outln (vty, "password 8 %s", host.password_encrypt);
+ vty_out (vty, "password 8 %s\n", host.password_encrypt);
if (host.enable_encrypt)
- vty_outln (vty, "enable password 8 %s", host.enable_encrypt);
+ vty_out (vty, "enable password 8 %s\n", host.enable_encrypt);
}
else
{
if (host.password)
- vty_outln (vty, "password %s", host.password);
+ vty_out (vty, "password %s\n", host.password);
if (host.enable)
- vty_outln (vty, "enable password %s", host.enable);
+ vty_out (vty, "enable password %s\n", host.enable);
}
if (zlog_default->default_lvl != LOG_DEBUG)
{
- vty_outln (vty,"! N.B. The 'log trap' command is deprecated.");
- vty_outln (vty, "log trap %s",
+ vty_out (vty,"! N.B. The 'log trap' command is deprecated.\n");
+ vty_out (vty, "log trap %s\n",
zlog_priority[zlog_default->default_lvl]);
}
@@ -463,7 +463,7 @@ config_write_host (struct vty *vty)
if (zlog_default->maxlvl[ZLOG_DEST_FILE] != zlog_default->default_lvl)
vty_out (vty, " %s",
zlog_priority[zlog_default->maxlvl[ZLOG_DEST_FILE]]);
- vty_out (vty, VTYNL);
+ vty_out (vty, "\n");
}
if (zlog_default->maxlvl[ZLOG_DEST_STDOUT] != ZLOG_DISABLED)
@@ -472,13 +472,13 @@ config_write_host (struct vty *vty)
if (zlog_default->maxlvl[ZLOG_DEST_STDOUT] != zlog_default->default_lvl)
vty_out (vty, " %s",
zlog_priority[zlog_default->maxlvl[ZLOG_DEST_STDOUT]]);
- vty_out (vty, VTYNL);
+ vty_out (vty, "\n");
}
if (zlog_default->maxlvl[ZLOG_DEST_MONITOR] == ZLOG_DISABLED)
- vty_outln (vty,"no log monitor");
+ vty_out (vty,"no log monitor\n");
else if (zlog_default->maxlvl[ZLOG_DEST_MONITOR] != zlog_default->default_lvl)
- vty_outln (vty,"log monitor %s",
+ vty_out (vty,"log monitor %s\n",
zlog_priority[zlog_default->maxlvl[ZLOG_DEST_MONITOR]]);
if (zlog_default->maxlvl[ZLOG_DEST_SYSLOG] != ZLOG_DISABLED)
@@ -487,33 +487,33 @@ config_write_host (struct vty *vty)
if (zlog_default->maxlvl[ZLOG_DEST_SYSLOG] != zlog_default->default_lvl)
vty_out (vty, " %s",
zlog_priority[zlog_default->maxlvl[ZLOG_DEST_SYSLOG]]);
- vty_out (vty, VTYNL);
+ vty_out (vty, "\n");
}
if (zlog_default->facility != LOG_DAEMON)
- vty_outln (vty, "log facility %s",
+ vty_out (vty, "log facility %s\n",
facility_name(zlog_default->facility));
if (zlog_default->record_priority == 1)
- vty_outln (vty, "log record-priority");
+ vty_out (vty, "log record-priority\n");
if (zlog_default->timestamp_precision > 0)
- vty_outln (vty, "log timestamp precision %d",
+ vty_out (vty, "log timestamp precision %d\n",
zlog_default->timestamp_precision);
if (host.advanced)
- vty_outln (vty, "service advanced-vty");
+ vty_out (vty, "service advanced-vty\n");
if (host.encrypt)
- vty_outln (vty, "service password-encryption");
+ vty_out (vty, "service password-encryption\n");
if (host.lines >= 0)
- vty_outln (vty, "service terminal-length %d",host.lines);
+ vty_out (vty, "service terminal-length %d\n",host.lines);
if (host.motdfile)
- vty_outln (vty, "banner motd file %s", host.motdfile);
+ vty_out (vty, "banner motd file %s\n", host.motdfile);
else if (! host.motd)
- vty_outln (vty, "no banner motd");
+ vty_out (vty, "no banner motd\n");
return 1;
}
@@ -715,6 +715,40 @@ cmd_variable_complete (struct cmd_token *token, const char *arg, vector comps)
vector_free(tmpcomps);
}
+#define AUTOCOMP_INDENT 5
+
+char *
+cmd_variable_comp2str(vector comps, unsigned short cols)
+{
+ size_t bsz = 16;
+ char *buf = XCALLOC(MTYPE_TMP, bsz);
+ int lc = AUTOCOMP_INDENT;
+ size_t cs = AUTOCOMP_INDENT;
+ size_t itemlen;
+ snprintf(buf, bsz, "%*s", AUTOCOMP_INDENT, "");
+ for (size_t j = 0; j < vector_active (comps); j++)
+ {
+ char *item = vector_slot (comps, j);
+ itemlen = strlen(item);
+
+ if (cs + itemlen + AUTOCOMP_INDENT + 3 >= bsz)
+ buf = XREALLOC(MTYPE_TMP, buf, (bsz *= 2));
+
+ if (lc + itemlen + 1 >= cols)
+ {
+ cs += snprintf(&buf[cs], bsz - cs, "\n%*s", AUTOCOMP_INDENT, "");
+ lc = AUTOCOMP_INDENT;
+ }
+
+ size_t written = snprintf(&buf[cs], bsz - cs, "%s ", item);
+ lc += written;
+ cs += written;
+ XFREE (MTYPE_COMPLETION, item);
+ vector_set_index (comps, j, NULL);
+ }
+ return buf;
+}
+
void
cmd_variable_handler_register (const struct cmd_variable_handler *cvh)
{
@@ -875,6 +909,9 @@ node_parent ( enum node_type node )
case BGP_IPV6L_NODE:
ret = BGP_NODE;
break;
+ case BGP_EVPN_VNI_NODE:
+ ret = BGP_EVPN_NODE;
+ break;
case KEYCHAIN_KEY_NODE:
ret = KEYCHAIN_NODE;
break;
@@ -1149,8 +1186,8 @@ DEFUN (config_terminal,
vty->node = CONFIG_NODE;
else
{
- vty_outln (vty, "VTY configuration is locked by other VTY");
- return CMD_WARNING;
+ vty_out (vty, "VTY configuration is locked by other VTY\n");
+ return CMD_WARNING_CONFIG_FAILED;
}
return CMD_SUCCESS;
}
@@ -1244,6 +1281,9 @@ cmd_exit (struct vty *vty)
case BGP_IPV6L_NODE:
vty->node = BGP_NODE;
break;
+ case BGP_EVPN_VNI_NODE:
+ vty->node = BGP_EVPN_NODE;
+ break;
case LDP_IPV4_NODE:
case LDP_IPV6_NODE:
vty->node = LDP_NODE;
@@ -1312,6 +1352,7 @@ DEFUN (config_end,
case BGP_IPV6_NODE:
case BGP_IPV6M_NODE:
case BGP_EVPN_NODE:
+ case BGP_EVPN_VNI_NODE:
case BGP_IPV6L_NODE:
case RMAP_NODE:
case OSPF_NODE:
@@ -1346,10 +1387,10 @@ DEFUN (show_version,
SHOW_STR
"Displays zebra version\n")
{
- vty_outln (vty, "%s %s (%s).", FRR_FULL_NAME, FRR_VERSION,
+ vty_out (vty, "%s %s (%s).\n", FRR_FULL_NAME, FRR_VERSION,
host.name ? host.name : "");
- vty_outln (vty, "%s%s", FRR_COPYRIGHT, GIT_INFO);
- vty_outln (vty, "configured with:%s %s", VTYNL,
+ vty_out (vty, "%s%s\n", FRR_COPYRIGHT, GIT_INFO);
+ vty_out (vty, "configured with:\n %s\n",
FRR_CONFIG_ARGS);
return CMD_SUCCESS;
@@ -1373,21 +1414,19 @@ DEFUN (config_help,
"help",
"Description of the interactive help system\n")
{
- vty_outln (vty,
- "Quagga VTY provides advanced help feature. When you need help,%s\
-anytime at the command line please press '?'.%s\
-%s\
-If nothing matches, the help list will be empty and you must backup%s\
- until entering a '?' shows the available options.%s\
-Two styles of help are provided:%s\
-1. Full help is available when you are ready to enter a%s\
-command argument (e.g. 'show ?') and describes each possible%s\
-argument.%s\
-2. Partial help is provided when an abbreviated argument is entered%s\
- and you want to know what arguments match the input%s\
- (e.g. 'show me?'.)%s", VTYNL, VTYNL, VTYNL,
- VTYNL, VTYNL, VTYNL, VTYNL, VTYNL,
- VTYNL, VTYNL, VTYNL, VTYNL);
+ vty_out (vty,
+ "Quagga VTY provides advanced help feature. When you need help,\n\
+anytime at the command line please press '?'.\n\
+\n\
+If nothing matches, the help list will be empty and you must backup\n\
+ until entering a '?' shows the available options.\n\
+Two styles of help are provided:\n\
+1. Full help is available when you are ready to enter a\n\
+command argument (e.g. 'show ?') and describes each possible\n\
+argument.\n\
+2. Partial help is provided when an abbreviated argument is entered\n\
+ and you want to know what arguments match the input\n\
+ (e.g. 'show me?'.)\n\n");
return CMD_SUCCESS;
}
@@ -1421,7 +1460,7 @@ permute (struct graph_node *start, struct vty *vty)
}
if (gn == start)
vty_out (vty, "...");
- vty_out (vty, VTYNL);
+ vty_out (vty, "\n");
}
else
{
@@ -1455,7 +1494,7 @@ cmd_list_cmds (struct vty *vty, int do_permute)
if ((element = vector_slot (node->cmd_vector, i)) &&
element->attr != CMD_ATTR_DEPRECATED &&
element->attr != CMD_ATTR_HIDDEN)
- vty_outln (vty, " %s", element->string);
+ vty_out (vty, " %s\n", element->string);
}
return CMD_SUCCESS;
}
@@ -1488,25 +1527,25 @@ vty_write_config (struct vty *vty)
if (vty->type == VTY_TERM)
{
- vty_outln (vty, "%sCurrent configuration:",VTYNL);
- vty_outln (vty, "!");
+ vty_out (vty, "\nCurrent configuration:\n");
+ vty_out (vty, "!\n");
}
- vty_outln (vty, "frr version %s", FRR_VER_SHORT);
- vty_outln (vty, "frr defaults %s", DFLT_NAME);
- vty_outln (vty, "!");
+ vty_out (vty, "frr version %s\n", FRR_VER_SHORT);
+ vty_out (vty, "frr defaults %s\n", DFLT_NAME);
+ vty_out (vty, "!\n");
for (i = 0; i < vector_active (cmdvec); i++)
if ((node = vector_slot (cmdvec, i)) && node->func
&& (node->vtysh || vty->type != VTY_SHELL))
{
if ((*node->func) (vty))
- vty_outln (vty, "!");
+ vty_out (vty, "!\n");
}
if (vty->type == VTY_TERM)
{
- vty_outln (vty, "end");
+ vty_out (vty, "end\n");
}
}
@@ -1543,7 +1582,7 @@ DEFUN (config_write,
/* Check and see if we are operating under vtysh configuration */
if (host.config == NULL)
{
- vty_outln (vty,"Can't save to configuration file, using vtysh.");
+ vty_out (vty,"Can't save to configuration file, using vtysh.\n");
return CMD_WARNING;
}
@@ -1578,12 +1617,12 @@ DEFUN (config_write,
fd = mkstemp (config_file_tmp);
if (fd < 0)
{
- vty_outln (vty, "Can't open configuration file %s.",config_file_tmp);
+ vty_out (vty, "Can't open configuration file %s.\n",config_file_tmp);
goto finished;
}
if (fchmod (fd, CONFIGFILE_MASK) != 0)
{
- vty_outln (vty, "Can't chmod configuration file %s: %s (%d).",
+ vty_out (vty, "Can't chmod configuration file %s: %s (%d).\n",
config_file_tmp, safe_strerror(errno), errno);
goto finished;
}
@@ -1605,13 +1644,13 @@ DEFUN (config_write,
if (unlink (config_file_sav) != 0)
if (errno != ENOENT)
{
- vty_outln (vty, "Can't unlink backup configuration file %s.",
+ vty_out (vty, "Can't unlink backup configuration file %s.\n",
config_file_sav);
goto finished;
}
if (link (config_file, config_file_sav) != 0)
{
- vty_outln (vty, "Can't backup old configuration file %s.",
+ vty_out (vty, "Can't backup old configuration file %s.\n",
config_file_sav);
goto finished;
}
@@ -1620,13 +1659,13 @@ DEFUN (config_write,
}
if (rename (config_file_tmp, config_file) != 0)
{
- vty_outln (vty, "Can't save configuration file %s.",config_file);
+ vty_out (vty, "Can't save configuration file %s.\n",config_file);
goto finished;
}
if (dirfd >= 0)
fsync (dirfd);
- vty_outln (vty, "Configuration saved to %s",config_file);
+ vty_out (vty, "Configuration saved to %s\n",config_file);
ret = CMD_SUCCESS;
finished:
@@ -1681,7 +1720,7 @@ DEFUN (show_startup_config,
confp = fopen (host.config, "r");
if (confp == NULL)
{
- vty_outln (vty, "Can't open configuration file [%s] due to '%s'",
+ vty_out (vty, "Can't open configuration file [%s] due to '%s'\n",
host.config, safe_strerror(errno));
return CMD_WARNING;
}
@@ -1694,7 +1733,7 @@ DEFUN (show_startup_config,
cp++;
*cp = '\0';
- vty_outln (vty, "%s", buf);
+ vty_out (vty, "%s\n", buf);
}
fclose (confp);
@@ -1721,8 +1760,8 @@ DEFUN (config_hostname,
if (!isalpha((int) word->arg[0]))
{
- vty_outln (vty, "Please specify string starting with alphabet");
- return CMD_WARNING;
+ vty_out (vty, "Please specify string starting with alphabet\n");
+ return CMD_WARNING_CONFIG_FAILED;
}
return cmd_hostname_set (word->arg);
@@ -1761,9 +1800,9 @@ DEFUN (config_password,
if (!isalnum (argv[idx_8]->arg[0]))
{
- vty_outln (vty,
- "Please specify string starting with alphanumeric");
- return CMD_WARNING;
+ vty_out (vty,
+ "Please specify string starting with alphanumeric\n");
+ return CMD_WARNING_CONFIG_FAILED;
}
if (host.password)
@@ -1811,16 +1850,16 @@ DEFUN (config_enable_password,
}
else
{
- vty_outln (vty, "Unknown encryption type.");
- return CMD_WARNING;
+ vty_out (vty, "Unknown encryption type.\n");
+ return CMD_WARNING_CONFIG_FAILED;
}
}
if (!isalnum (argv[idx_8]->arg[0]))
{
- vty_outln (vty,
- "Please specify string starting with alphanumeric");
- return CMD_WARNING;
+ vty_out (vty,
+ "Please specify string starting with alphanumeric\n");
+ return CMD_WARNING_CONFIG_FAILED;
}
if (host.enable)
@@ -1968,7 +2007,7 @@ DEFUN_HIDDEN (do_echo,
{
char *message;
- vty_outln (vty, "%s",
+ vty_out (vty, "%s\n",
((message = argv_concat(argv, argc, 1)) ? message : ""));
if (message)
XFREE(MTYPE_TMP, message);
@@ -2012,7 +2051,7 @@ DEFUN (show_logging,
vty_out (vty, "level %s, facility %s, ident %s",
zlog_priority[zl->maxlvl[ZLOG_DEST_SYSLOG]],
facility_name(zl->facility), zl->ident);
- vty_out (vty, VTYNL);
+ vty_out (vty, "\n");
vty_out (vty, "Stdout logging: ");
if (zl->maxlvl[ZLOG_DEST_STDOUT] == ZLOG_DISABLED)
@@ -2020,7 +2059,7 @@ DEFUN (show_logging,
else
vty_out (vty, "level %s",
zlog_priority[zl->maxlvl[ZLOG_DEST_STDOUT]]);
- vty_out (vty, VTYNL);
+ vty_out (vty, "\n");
vty_out (vty, "Monitor logging: ");
if (zl->maxlvl[ZLOG_DEST_MONITOR] == ZLOG_DISABLED)
@@ -2028,7 +2067,7 @@ DEFUN (show_logging,
else
vty_out (vty, "level %s",
zlog_priority[zl->maxlvl[ZLOG_DEST_MONITOR]]);
- vty_out (vty, VTYNL);
+ vty_out (vty, "\n");
vty_out (vty, "File logging: ");
if ((zl->maxlvl[ZLOG_DEST_FILE] == ZLOG_DISABLED) ||
@@ -2038,13 +2077,13 @@ DEFUN (show_logging,
vty_out (vty, "level %s, filename %s",
zlog_priority[zl->maxlvl[ZLOG_DEST_FILE]],
zl->filename);
- vty_out (vty, VTYNL);
+ vty_out (vty, "\n");
- vty_outln (vty, "Protocol name: %s",
+ vty_out (vty, "Protocol name: %s\n",
zl->protoname);
- vty_outln (vty, "Record priority: %s",
+ vty_out (vty, "Record priority: %s\n",
(zl->record_priority ? "enabled" : "disabled"));
- vty_outln (vty, "Timestamp precision: %d",
+ vty_out (vty, "Timestamp precision: %d\n",
zl->timestamp_precision);
return CMD_SUCCESS;
@@ -2134,14 +2173,14 @@ set_log_file(struct vty *vty, const char *fname, int loglevel)
if (getcwd (cwd, MAXPATHLEN) == NULL)
{
zlog_err ("config_log_file: Unable to alloc mem!");
- return CMD_WARNING;
+ return CMD_WARNING_CONFIG_FAILED;
}
if ( (p = XMALLOC (MTYPE_TMP, strlen (cwd) + strlen (fname) + 2))
== NULL)
{
zlog_err ("config_log_file: Unable to alloc mem!");
- return CMD_WARNING;
+ return CMD_WARNING_CONFIG_FAILED;
}
sprintf (p, "%s/%s", cwd, fname);
fullpath = p;
@@ -2157,7 +2196,7 @@ set_log_file(struct vty *vty, const char *fname, int loglevel)
if (!ret)
{
vty_out (vty, "can't open logfile %s\n", fname);
- return CMD_WARNING;
+ return CMD_WARNING_CONFIG_FAILED;
}
if (host.logfile)
@@ -2200,7 +2239,6 @@ DEFUN (no_config_log_file,
"Logging control\n"
"Cancel logging to file\n"
"Logging file name\n"
- "Logging file name\n"
"Logging level\n")
{
zlog_reset_file ();
@@ -2372,7 +2410,7 @@ cmd_banner_motd_file (const char *file)
host.motdfile = XSTRDUP (MTYPE_HOST, file);
}
else
- success = CMD_WARNING;
+ success = CMD_WARNING_CONFIG_FAILED;
return success;
}
@@ -2391,7 +2429,7 @@ DEFUN (banner_motd_file,
if (cmd == CMD_ERR_NO_FILE)
vty_out (vty, "%s does not exist", filename);
- else if (cmd == CMD_WARNING)
+ else if (cmd == CMD_WARNING_CONFIG_FAILED)
vty_out (vty, "%s must be in %s", filename, SYSCONFDIR);
return cmd;