summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/.gitignore3
-rw-r--r--lib/Makefile.am13
-rw-r--r--lib/bfd.h5
-rw-r--r--lib/command.c3361
-rw-r--r--lib/command.h408
-rw-r--r--lib/command_lex.l71
-rw-r--r--lib/command_match.c850
-rw-r--r--lib/command_match.h96
-rw-r--r--lib/command_parse.y544
-rw-r--r--lib/distribute.c654
-rw-r--r--lib/filter.c390
-rw-r--r--lib/grammar_sandbox.c386
-rw-r--r--lib/grammar_sandbox.h65
-rw-r--r--lib/graph.c138
-rw-r--r--lib/graph.h101
-rw-r--r--lib/if.c101
-rw-r--r--lib/if_rmap.c46
-rw-r--r--lib/json.c5
-rw-r--r--lib/json.h2
-rw-r--r--lib/keychain.c221
-rw-r--r--lib/log.h4
-rw-r--r--lib/ns.c16
-rw-r--r--lib/plist.c555
-rw-r--r--lib/route_types.txt2
-rw-r--r--lib/routemap.c1341
-rw-r--r--lib/routemap.h168
-rw-r--r--lib/smux.c29
-rw-r--r--lib/str.c8
-rw-r--r--lib/str.h2
-rw-r--r--lib/thread.c20
-rw-r--r--lib/vrf.h4
-rw-r--r--lib/vty.c1145
32 files changed, 6097 insertions, 4657 deletions
diff --git a/lib/.gitignore b/lib/.gitignore
index fe75137bca..e45fec1786 100644
--- a/lib/.gitignore
+++ b/lib/.gitignore
@@ -15,4 +15,7 @@ gitversion.h.tmp
*~
*.loT
route_types.h
+command_lex.c
+command_parse.c
+command_parse.h
refix
diff --git a/lib/Makefile.am b/lib/Makefile.am
index 1c0906837a..f0d5bd53db 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -4,13 +4,16 @@ AM_CPPFLAGS = -I.. -I$(top_srcdir) -I$(top_srcdir)/lib -I$(top_builddir)/lib \
-DVTY_DEPRECATE_INDEX
AM_CFLAGS = $(WERROR)
DEFS = @DEFS@ -DSYSCONFDIR=\"$(sysconfdir)/\"
+AM_YFLAGS = -d
lib_LTLIBRARIES = libzebra.la
libzebra_la_LDFLAGS = -version-info 0:0:0
libzebra_la_SOURCES = \
network.c pid_output.c getopt.c getopt1.c daemon.c \
- checksum.c vector.c linklist.c vty.c command.c \
+ checksum.c vector.c linklist.c vty.c \
+ graph.c command_parse.y command_lex.l command_match.c \
+ command.c \
sockunion.c prefix.c thread.c if.c buffer.c table.c hash.c \
filter.c routemap.c distribute.c stream.c str.c log.c plist.c \
zclient.c sockopt.c smux.c agentx.c snmp.c md5.c if_rmap.c keychain.c privs.c \
@@ -20,15 +23,17 @@ libzebra_la_SOURCES = \
qobj.c \
event_counter.c
-BUILT_SOURCES = route_types.h gitversion.h
+BUILT_SOURCES = route_types.h gitversion.h command_parse.h
libzebra_la_DEPENDENCIES = @LIB_REGEX@
libzebra_la_LIBADD = @LIB_REGEX@ @LIBCAP@
pkginclude_HEADERS = \
- buffer.h checksum.h command.h filter.h getopt.h hash.h \
+ buffer.h checksum.h filter.h getopt.h hash.h \
if.h linklist.h log.h \
+ graph.h command_match.h \
+ command.h \
memory.h network.h prefix.h routemap.h distribute.h sockunion.h \
str.h stream.h table.h thread.h vector.h version.h vty.h zebra.h \
plist.h zclient.h sockopt.h smux.h md5.h if_rmap.h keychain.h \
@@ -65,7 +70,7 @@ GITH=gitversion.h
gitversion.h.tmp: $(srcdir)/../.git
@PERL@ $(srcdir)/gitversion.pl $(srcdir) > ${GITH}.tmp
gitversion.h: gitversion.h.tmp
- { test -f ${GITH} && diff -s -q ${GITH}.tmp ${GITH}; } || cp -v ${GITH}.tmp ${GITH}
+ { test -f ${GITH} && diff -s -q ${GITH}.tmp ${GITH}; } || cp -v ${GITH}.tmp ${GITH}
else
.PHONY: gitversion.h
diff --git a/lib/bfd.h b/lib/bfd.h
index bbe96b07b4..e636e4426f 100644
--- a/lib/bfd.h
+++ b/lib/bfd.h
@@ -26,11 +26,6 @@
#include "lib/json.h"
-#define BFD_CMD_DETECT_MULT_RANGE "<2-255> "
-#define BFD_CMD_MIN_RX_RANGE "<50-60000> "
-#define BFD_CMD_MIN_TX_RANGE "<50-60000>"
-#define BFD_CMD_TYPE "(multihop|singlehop)"
-
#define BFD_DEF_MIN_RX 300
#define BFD_MIN_MIN_RX 50
#define BFD_MAX_MIN_RX 60000
diff --git a/lib/command.c b/lib/command.c
index 56c262a647..f9c4107745 100644
--- a/lib/command.c
+++ b/lib/command.c
@@ -1,25 +1,29 @@
/*
- Command interpreter routine for virtual terminal [aka TeletYpe]
- Copyright (C) 1997, 98, 99 Kunihiro Ishiguro
- Copyright (C) 2013 by Open Source Routing.
- Copyright (C) 2013 by Internet Systems Consortium, Inc. ("ISC")
-
-This file is part of GNU Zebra.
-
-GNU Zebra is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published
-by the Free Software Foundation; either version 2, or (at your
-option) any later version.
-
-GNU Zebra is distributed in the hope that it will be useful, but
-WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with GNU Zebra; see the file COPYING. If not, write to the
-Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-Boston, MA 02111-1307, USA. */
+ * CLI backend interface.
+ *
+ * --
+ * Copyright (C) 2016 Cumulus Networks, Inc.
+ * Copyright (C) 1997, 98, 99 Kunihiro Ishiguro
+ * Copyright (C) 2013 by Open Source Routing.
+ * Copyright (C) 2013 by Internet Systems Consortium, Inc. ("ISC")
+ *
+ * This file is part of GNU Zebra.
+ *
+ * GNU Zebra is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2, or (at your option) any
+ * later version.
+ *
+ * GNU Zebra is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GNU Zebra; see the file COPYING. If not, write to the Free
+ * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ */
#include <zebra.h>
@@ -29,10 +33,13 @@ Boston, MA 02111-1307, USA. */
#include <lib/version.h>
#include "thread.h"
#include "vector.h"
+#include "linklist.h"
#include "vty.h"
#include "command.h"
#include "workqueue.h"
#include "vrf.h"
+#include "command_match.h"
+#include "command_parse.h"
#include "qobj.h"
DEFINE_MTYPE( LIB, HOST, "Host config")
@@ -43,44 +50,6 @@ DEFINE_MTYPE_STATIC(LIB, CMD_TOKENS, "Command desc")
each daemon maintains each own cmdvec. */
vector cmdvec = NULL;
-struct cmd_token token_cr;
-char *command_cr = NULL;
-
-/**
- * Filter types. These tell the parser whether to allow
- * partial matching on tokens.
- */
-enum filter_type
-{
- FILTER_RELAXED,
- FILTER_STRICT
-};
-
-/**
- * Command matcher result value.
- */
-enum matcher_rv
-{
- MATCHER_OK,
- MATCHER_COMPLETE,
- MATCHER_INCOMPLETE,
- MATCHER_NO_MATCH,
- MATCHER_AMBIGUOUS,
- MATCHER_EXCEED_ARGC_MAX
-};
-
-/**
- * Defines which matcher_rv values constitute
- * an error. Should be used against matcher_rv
- * return values to do basic error checking.
- */
-#define MATCHER_ERROR(matcher_rv) \
- ( (matcher_rv) == MATCHER_INCOMPLETE \
- || (matcher_rv) == MATCHER_NO_MATCH \
- || (matcher_rv) == MATCHER_AMBIGUOUS \
- || (matcher_rv) == MATCHER_EXCEED_ARGC_MAX \
- )
-
/* Host information structure. */
struct host host;
@@ -128,7 +97,7 @@ static const struct facility_map {
int facility;
const char *name;
size_t match;
-} syslog_facilities[] =
+} syslog_facilities[] =
{
{ LOG_KERN, "kern", 1 },
{ LOG_USER, "user", 2 },
@@ -180,7 +149,7 @@ static int
level_match(const char *s)
{
int level ;
-
+
for ( level = 0 ; zlog_priority [level] != NULL ; level ++ )
if (!strncmp (s, zlog_priority[level], 2))
return level;
@@ -200,7 +169,7 @@ print_version (const char *progname)
/* Utility function to concatenate argv argument into a single string
with inserting ' ' character between each argument. */
char *
-argv_concat (const char **argv, int argc, int shift)
+argv_concat (struct cmd_token **argv, int argc, int shift)
{
int i;
size_t len;
@@ -209,14 +178,14 @@ argv_concat (const char **argv, int argc, int shift)
len = 0;
for (i = shift; i < argc; i++)
- len += strlen(argv[i])+1;
+ len += strlen(argv[i]->arg)+1;
if (!len)
return NULL;
p = str = XMALLOC(MTYPE_TMP, len);
for (i = shift; i < argc; i++)
{
size_t arglen;
- memcpy(p, argv[i], (arglen = strlen(argv[i])));
+ memcpy(p, argv[i]->arg, (arglen = strlen(argv[i]->arg)));
p += arglen;
*p++ = ' ';
}
@@ -224,6 +193,26 @@ argv_concat (const char **argv, int argc, int shift)
return str;
}
+/**
+ * Convenience function for accessing argv data.
+ *
+ * @param argc
+ * @param argv
+ * @param text definition snippet of the desired token
+ * @param index the starting index, and where to store the
+ * index of the found token if it exists
+ * @return 1 if found, 0 otherwise
+ */
+int
+argv_find (struct cmd_token **argv, int argc, const char *text, int *index)
+{
+ int found = 0;
+ for (int i = *index; i < argc && found == 0; i++)
+ if ((found = strmatch (text, argv[i]->text)))
+ *index = i;
+ return found;
+}
+
static unsigned int
cmd_hash_key (void *p)
{
@@ -238,12 +227,16 @@ cmd_hash_cmp (const void *a, const void *b)
/* Install top node of command vector. */
void
-install_node (struct cmd_node *node,
- int (*func) (struct vty *))
+install_node (struct cmd_node *node,
+ int (*func) (struct vty *))
{
vector_set_index (cmdvec, node->node, node);
node->func = func;
+ node->cmdgraph = graph_new ();
node->cmd_vector = vector_init (VECTOR_MIN_SIZE);
+ // add start node
+ struct cmd_token *token = new_cmd_token (START_TKN, NULL, NULL);
+ graph_new_node (node->cmdgraph, token, (void (*)(void *)) &del_cmd_token);
node->cmd_hash = hash_create (cmd_hash_key, cmd_hash_cmp);
}
@@ -257,10 +250,10 @@ cmd_make_strvec (const char *string)
char *token;
int strlen;
vector strvec;
-
+
if (string == NULL)
return NULL;
-
+
cp = string;
/* Skip white spaces. */
@@ -278,12 +271,12 @@ cmd_make_strvec (const char *string)
strvec = vector_init (VECTOR_MIN_SIZE);
/* Copy each command piece and set into vector. */
- while (1)
+ while (1)
{
start = cp;
while (!(isspace ((int) *cp) || *cp == '\r' || *cp == '\n') &&
- *cp != '\0')
- cp++;
+ *cp != '\0')
+ cp++;
strlen = cp - start;
token = XMALLOC (MTYPE_STRVEC, strlen + 1);
memcpy (token, start, strlen);
@@ -291,11 +284,11 @@ cmd_make_strvec (const char *string)
vector_set (strvec, token);
while ((isspace ((int) *cp) || *cp == '\n' || *cp == '\r') &&
- *cp != '\0')
- cp++;
+ *cp != '\0')
+ cp++;
if (*cp == '\0')
- return strvec;
+ return strvec;
}
}
@@ -316,387 +309,22 @@ cmd_free_strvec (vector v)
vector_free (v);
}
-/**
- * State structure for command format parser. Tracks
- * parse tree position and miscellaneous state variables.
- * Used when building a command vector from format strings.
- */
-struct format_parser_state
-{
- vector topvect; /* Top level vector */
- vector intvect; /* Intermediate level vector, used when there's
- a multiple in a keyword. */
- vector curvect; /* current vector where read tokens should be
- appended. */
-
- const char *string; /* pointer to command string, not modified */
- const char *cp; /* pointer in command string, moved along while
- parsing */
- const char *dp; /* pointer in description string, moved along while
- parsing */
-
- int in_keyword; /* flag to remember if we are in a keyword group */
- int in_multiple; /* flag to remember if we are in a multiple group */
- int just_read_word; /* flag to remember if the last thing we read was a
- real word and not some abstract token */
-};
-
-static void
-format_parser_error(struct format_parser_state *state, const char *message)
-{
- int offset = state->cp - state->string + 1;
-
- fprintf(stderr, "\nError parsing command: \"%s\"\n", state->string);
- fprintf(stderr, " %*c\n", offset, '^');
- fprintf(stderr, "%s at offset %d.\n", message, offset);
- fprintf(stderr, "This is a programming error. Check your DEFUNs etc.\n");
- exit(1);
-}
-
-/**
- * Reads out one section of a help string from state->dp.
- * Leading whitespace is trimmed and the string is read until
- * a newline is reached.
- *
- * @param[out] state format parser state
- * @return the help string token read
- */
-static char *
-format_parser_desc_str(struct format_parser_state *state)
-{
- const char *cp, *start;
- char *token;
- int strlen;
-
- cp = state->dp;
-
- if (cp == NULL)
- return NULL;
-
- /* Skip white spaces. */
- while (isspace ((int) *cp) && *cp != '\0')
- cp++;
-
- /* Return if there is only white spaces */
- if (*cp == '\0')
- return NULL;
-
- start = cp;
-
- while (!(*cp == '\r' || *cp == '\n') && *cp != '\0')
- cp++;
-
- strlen = cp - start;
- token = XMALLOC (MTYPE_CMD_TOKENS, strlen + 1);
- memcpy (token, start, strlen);
- *(token + strlen) = '\0';
-
- state->dp = cp;
-
- return token;
-}
-
-/**
- * Transitions format parser state into keyword parsing mode.
- * A cmd_token struct, `token`, representing this keyword token is initialized
- * and appended to state->curvect. token->keyword is initialized as a vector of
- * vector, a new vector is initialized and added to token->keyword, and
- * state->curvect is set to point at this vector. When control returns to the
- * caller newly parsed tokens will be added to this vector.
- *
- * In short:
- * state->curvect[HEAD] = new cmd_token
- * state->curvect[HEAD]->keyword[0] = new vector
- * state->curvect = state->curvect[HEAD]->keyword[0]
- *
- * @param[out] state state struct to transition
- */
-static void
-format_parser_begin_keyword(struct format_parser_state *state)
-{
- struct cmd_token *token;
- vector keyword_vect;
-
- if (state->in_keyword
- || state->in_multiple)
- format_parser_error(state, "Unexpected '{'");
-
- state->cp++;
- state->in_keyword = 1;
-
- token = XCALLOC(MTYPE_CMD_TOKENS, sizeof(*token));
- token->type = TOKEN_KEYWORD;
- token->keyword = vector_init(VECTOR_MIN_SIZE);
-
- keyword_vect = vector_init(VECTOR_MIN_SIZE);
- vector_set(token->keyword, keyword_vect);
-
- vector_set(state->curvect, token);
- state->curvect = keyword_vect;
-}
-
-/**
- * Transitions format parser state into multiple parsing mode.
- * A cmd_token struct, `token`, representing this multiple token is initialized
- * and appended to state->curvect. token->multiple is initialized as a vector
- * of cmd_token and state->curvect is set to point at token->multiple. If
- * state->curvect != state->topvect (i.e. this multiple token is nested inside
- * another composite token) then a pointer to state->curvect is saved in
- * state->intvect.
- *
- * In short:
- * state->curvect[HEAD] = new cmd_token
- * state->curvect[HEAD]->multiple = new vector
- * state->intvect = state->curvect IFF nested token
- * state->curvect = state->curvect[HEAD]->multiple
- *
- * @param[out] state state struct to transition
- */
-static void
-format_parser_begin_multiple(struct format_parser_state *state)
-{
- struct cmd_token *token;
-
- if (state->in_keyword == 1)
- format_parser_error(state, "Keyword starting with '('");
-
- if (state->in_multiple)
- format_parser_error(state, "Nested group");
-
- state->cp++;
- state->in_multiple = 1;
- state->just_read_word = 0;
-
- token = XCALLOC(MTYPE_CMD_TOKENS, sizeof(*token));
- token->type = TOKEN_MULTIPLE;
- token->multiple = vector_init(VECTOR_MIN_SIZE);
-
- vector_set(state->curvect, token);
- if (state->curvect != state->topvect)
- state->intvect = state->curvect;
- state->curvect = token->multiple;
-}
-
-/**
- * Transition format parser state out of keyword parsing mode.
- * This function is called upon encountering '}'.
- * state->curvect is reassigned to the top level vector (as
- * keywords cannot be nested) and state flags are set appropriately.
- *
- * @param[out] state state struct to transition
- */
-static void
-format_parser_end_keyword(struct format_parser_state *state)
-{
- if (state->in_multiple
- || !state->in_keyword)
- format_parser_error(state, "Unexpected '}'");
-
- if (state->in_keyword == 1)
- format_parser_error(state, "Empty keyword group");
-
- state->cp++;
- state->in_keyword = 0;
- state->curvect = state->topvect;
-}
-
-/**
- * Transition format parser state out of multiple parsing mode.
- * This function is called upon encountering ')'.
- * state->curvect is reassigned to its parent vector (state->intvect
- * if the multiple token being exited was nested inside another token,
- * state->topvect otherwise) and state flags are set appropriately.
- *
- * @param[out] state state struct to transition
- */
-static void
-format_parser_end_multiple(struct format_parser_state *state)
-{
- char *dummy;
-
- if (!state->in_multiple)
- format_parser_error(state, "Unexpected ')'");
-
- if (vector_active(state->curvect) == 0)
- format_parser_error(state, "Empty multiple section");
-
- if (!state->just_read_word)
- {
- /* There are constructions like
- * 'show ip ospf database ... (self-originate|)'
- * in use.
- * The old parser reads a description string for the
- * word '' between |) which will never match.
- * Simulate this behvaior by dropping the next desc
- * string in such a case. */
-
- dummy = format_parser_desc_str(state);
- XFREE(MTYPE_CMD_TOKENS, dummy);
- }
-
- state->cp++;
- state->in_multiple = 0;
-
- if (state->intvect)
- state->curvect = state->intvect;
- else
- state->curvect = state->topvect;
-}
-
-/**
- * Format parser handler for pipe '|' character.
- * This character separates subtokens in multiple and keyword type tokens.
- * If the current token is a multiple keyword, the position pointer is
- * simply moved past the pipe and state flags are set appropriately.
- * If the current token is a keyword token, the position pointer is moved
- * past the pipe. Then the cmd_token struct for the keyword is fetched and
- * a new vector of cmd_token is appended to its vector of vector. Finally
- * state->curvect is set to point at this new vector.
- *
- * In short:
- * state->curvect = state->topvect[HEAD]->keyword[HEAD] = new vector
- *
- * @param[out] state state struct to transition
- */
-static void
-format_parser_handle_pipe(struct format_parser_state *state)
-{
- struct cmd_token *keyword_token;
- vector keyword_vect;
-
- if (state->in_multiple)
- {
- state->just_read_word = 0;
- state->cp++;
- }
- else if (state->in_keyword)
- {
- state->in_keyword = 1;
- state->cp++;
-
- keyword_token = vector_slot(state->topvect,
- vector_active(state->topvect) - 1);
- keyword_vect = vector_init(VECTOR_MIN_SIZE);
- vector_set(keyword_token->keyword, keyword_vect);
- state->curvect = keyword_vect;
- }
- else
- {
- format_parser_error(state, "Unexpected '|'");
- }
-}
-
-/**
- * Format parser handler for terminal tokens.
- * Parses the token, appends it to state->curvect, and sets
- * state flags appropriately.
- *
- * @param[out] state state struct for current format parser state
- */
-static void
-format_parser_read_word(struct format_parser_state *state)
-{
- const char *start;
- int len;
- char *cmd;
- struct cmd_token *token;
-
- start = state->cp;
-
- while (state->cp[0] != '\0'
- && !strchr("\r\n(){}|", state->cp[0])
- && !isspace((int)state->cp[0]))
- state->cp++;
-
- len = state->cp - start;
- cmd = XMALLOC(MTYPE_CMD_TOKENS, len + 1);
- memcpy(cmd, start, len);
- cmd[len] = '\0';
-
- token = XCALLOC(MTYPE_CMD_TOKENS, sizeof(*token));
- token->type = TOKEN_TERMINAL;
- if (strcmp (cmd, "A.B.C.D") == 0)
- token->terminal = TERMINAL_IPV4;
- else if (strcmp (cmd, "A.B.C.D/M") == 0)
- token->terminal = TERMINAL_IPV4_PREFIX;
- else if (strcmp (cmd, "X:X::X:X") == 0)
- token->terminal = TERMINAL_IPV6;
- else if (strcmp (cmd, "X:X::X:X/M") == 0)
- token->terminal = TERMINAL_IPV6_PREFIX;
- else if (cmd[0] == '[')
- token->terminal = TERMINAL_OPTION;
- else if (cmd[0] == '.')
- token->terminal = TERMINAL_VARARG;
- else if (cmd[0] == '<')
- token->terminal = TERMINAL_RANGE;
- else if (cmd[0] >= 'A' && cmd[0] <= 'Z')
- token->terminal = TERMINAL_VARIABLE;
- else
- token->terminal = TERMINAL_LITERAL;
-
- token->cmd = cmd;
- token->desc = format_parser_desc_str(state);
- vector_set(state->curvect, token);
-
- if (state->in_keyword == 1)
- state->in_keyword = 2;
-
- state->just_read_word = 1;
-}
-
-/**
- * Parse a given command format string and build a tree of tokens from
- * it that is suitable to be used by the command subsystem.
- *
- * @param string Command format string.
- * @param descstr Description string.
- * @return A vector of struct cmd_token representing the given command,
- * or NULL on error.
- */
-static vector
-cmd_parse_format(const char *string, const char *descstr)
+char *
+cmd_concat_strvec (vector v)
{
- struct format_parser_state state;
-
- if (string == NULL)
- return NULL;
-
- memset(&state, 0, sizeof(state));
- state.topvect = state.curvect = vector_init(VECTOR_MIN_SIZE);
- state.cp = state.string = string;
- state.dp = descstr;
+ size_t strsize = 0;
+ for (unsigned int i = 0; i < vector_active (v); i++)
+ if (vector_slot (v, i))
+ strsize += strlen ((char *) vector_slot (v, i)) + 1;
- while (1)
- {
- while (isspace((int)state.cp[0]) && state.cp[0] != '\0')
- state.cp++;
+ char *concatenated = calloc (sizeof (char), strsize);
+ for (unsigned int i = 0; i < vector_active (v); i++)
+ {
+ strlcat (concatenated, (char *) vector_slot (v, i), strsize);
+ strlcat (concatenated, " ", strsize);
+ }
- switch (state.cp[0])
- {
- case '\0':
- if (state.in_keyword
- || state.in_multiple)
- format_parser_error(&state, "Unclosed group/keyword");
- return state.topvect;
- case '{':
- format_parser_begin_keyword(&state);
- break;
- case '(':
- format_parser_begin_multiple(&state);
- break;
- case '}':
- format_parser_end_keyword(&state);
- break;
- case ')':
- format_parser_end_multiple(&state);
- break;
- case '|':
- format_parser_handle_pipe(&state);
- break;
- default:
- format_parser_read_word(&state);
- }
- }
+ return concatenated;
}
/* Return prompt character of specified node. */
@@ -714,7 +342,7 @@ void
install_element (enum node_type ntype, struct cmd_element *cmd)
{
struct cmd_node *cnode;
-
+
/* cmd_init hasn't been called */
if (!cmdvec)
{
@@ -725,11 +353,11 @@ install_element (enum node_type ntype, struct cmd_element *cmd)
cnode = vector_slot (cmdvec, ntype);
- if (cnode == NULL)
+ if (cnode == NULL)
{
fprintf (stderr, "Command node %d doesn't exist, please check it\n",
- ntype);
- exit (1);
+ ntype);
+ exit (EXIT_FAILURE);
}
if (hash_lookup (cnode->cmd_hash, cmd) != NULL)
@@ -742,9 +370,8 @@ install_element (enum node_type ntype, struct cmd_element *cmd)
assert (hash_get (cnode->cmd_hash, cmd, hash_alloc_intern));
+ command_parse_format (cnode->cmdgraph, cmd);
vector_set (cnode->cmd_vector, cmd);
- if (cmd->tokens == NULL)
- cmd->tokens = cmd_parse_format(cmd->string, cmd->doc);
if (ntype == VIEW_NODE)
install_element (ENABLE_NODE, cmd);
@@ -756,7 +383,7 @@ static const unsigned char itoa64[] =
static void
to64(char *s, long v, int n)
{
- while (--n >= 0)
+ while (--n >= 0)
{
*s++ = itoa64[v&0x3f];
v >>= 6;
@@ -771,7 +398,7 @@ zencrypt (const char *passwd)
char *crypt (const char *, const char *);
gettimeofday(&tv,0);
-
+
to64(&salt[0], random(), 3);
to64(&salt[3], tv.tv_usec, 3);
salt[5] = '\0';
@@ -789,9 +416,9 @@ config_write_host (struct vty *vty)
if (host.encrypt)
{
if (host.password_encrypt)
- vty_out (vty, "password 8 %s%s", host.password_encrypt, VTY_NEWLINE);
+ vty_out (vty, "password 8 %s%s", host.password_encrypt, VTY_NEWLINE);
if (host.enable_encrypt)
- vty_out (vty, "enable password 8 %s%s", host.enable_encrypt, VTY_NEWLINE);
+ vty_out (vty, "enable password 8 %s%s", host.enable_encrypt, VTY_NEWLINE);
}
else
{
@@ -804,17 +431,17 @@ config_write_host (struct vty *vty)
if (zlog_default->default_lvl != LOG_DEBUG)
{
vty_out (vty, "! N.B. The 'log trap' command is deprecated.%s",
- VTY_NEWLINE);
+ VTY_NEWLINE);
vty_out (vty, "log trap %s%s",
- zlog_priority[zlog_default->default_lvl], VTY_NEWLINE);
+ zlog_priority[zlog_default->default_lvl], VTY_NEWLINE);
}
if (host.logfile && (zlog_default->maxlvl[ZLOG_DEST_FILE] != ZLOG_DISABLED))
{
vty_out (vty, "log file %s", host.logfile);
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, " %s",
+ zlog_priority[zlog_default->maxlvl[ZLOG_DEST_FILE]]);
vty_out (vty, "%s", VTY_NEWLINE);
}
@@ -822,8 +449,8 @@ config_write_host (struct vty *vty)
{
vty_out (vty, "log stdout");
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, " %s",
+ zlog_priority[zlog_default->maxlvl[ZLOG_DEST_STDOUT]]);
vty_out (vty, "%s", VTY_NEWLINE);
}
@@ -831,27 +458,27 @@ config_write_host (struct vty *vty)
vty_out(vty,"no log monitor%s",VTY_NEWLINE);
else if (zlog_default->maxlvl[ZLOG_DEST_MONITOR] != zlog_default->default_lvl)
vty_out(vty,"log monitor %s%s",
- zlog_priority[zlog_default->maxlvl[ZLOG_DEST_MONITOR]],VTY_NEWLINE);
+ zlog_priority[zlog_default->maxlvl[ZLOG_DEST_MONITOR]],VTY_NEWLINE);
if (zlog_default->maxlvl[ZLOG_DEST_SYSLOG] != ZLOG_DISABLED)
{
vty_out (vty, "log syslog");
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, " %s",
+ zlog_priority[zlog_default->maxlvl[ZLOG_DEST_SYSLOG]]);
vty_out (vty, "%s", VTY_NEWLINE);
}
if (zlog_default->facility != LOG_DAEMON)
vty_out (vty, "log facility %s%s",
- facility_name(zlog_default->facility), VTY_NEWLINE);
+ facility_name(zlog_default->facility), VTY_NEWLINE);
if (zlog_default->record_priority == 1)
vty_out (vty, "log record-priority%s", VTY_NEWLINE);
if (zlog_default->timestamp_precision > 0)
vty_out (vty, "log timestamp precision %d%s",
- zlog_default->timestamp_precision, VTY_NEWLINE);
+ zlog_default->timestamp_precision, VTY_NEWLINE);
if (host.advanced)
vty_out (vty, "service advanced-vty%s", VTY_NEWLINE);
@@ -861,7 +488,7 @@ config_write_host (struct vty *vty)
if (host.lines >= 0)
vty_out (vty, "service terminal-length %d%s", host.lines,
- VTY_NEWLINE);
+ VTY_NEWLINE);
if (host.motdfile)
vty_out (vty, "banner motd file %s%s", host.motdfile, VTY_NEWLINE);
@@ -871,1376 +498,132 @@ config_write_host (struct vty *vty)
return 1;
}
-/* Utility function for getting command vector. */
-static vector
-cmd_node_vector (vector v, enum node_type ntype)
+/* Utility function for getting command graph. */
+static struct graph *
+cmd_node_graph (vector v, enum node_type ntype)
{
struct cmd_node *cnode = vector_slot (v, ntype);
- return cnode->cmd_vector;
-}
-
-/* Completion match types. */
-enum match_type
-{
- no_match,
- extend_match,
- ipv4_prefix_match,
- ipv4_match,
- ipv6_prefix_match,
- ipv6_match,
- range_match,
- vararg_match,
- partly_match,
- exact_match
-};
-
-static enum match_type
-cmd_ipv4_match (const char *str)
-{
- const char *sp;
- int dots = 0, nums = 0;
- char buf[4];
-
- if (str == NULL)
- return partly_match;
-
- for (;;)
- {
- memset (buf, 0, sizeof (buf));
- sp = str;
- while (*str != '\0')
- {
- if (*str == '.')
- {
- if (dots >= 3)
- return no_match;
-
- if (*(str + 1) == '.')
- return no_match;
-
- if (*(str + 1) == '\0')
- return partly_match;
-
- dots++;
- break;
- }
- if (!isdigit ((int) *str))
- return no_match;
-
- str++;
- }
-
- if (str - sp > 3)
- return no_match;
-
- strncpy (buf, sp, str - sp);
- if (atoi (buf) > 255)
- return no_match;
-
- nums++;
-
- if (*str == '\0')
- break;
-
- str++;
- }
-
- if (nums < 4)
- return partly_match;
-
- return exact_match;
-}
-
-static enum match_type
-cmd_ipv4_prefix_match (const char *str)
-{
- const char *sp;
- int dots = 0;
- char buf[4];
-
- if (str == NULL)
- return partly_match;
-
- for (;;)
- {
- memset (buf, 0, sizeof (buf));
- sp = str;
- while (*str != '\0' && *str != '/')
- {
- if (*str == '.')
- {
- if (dots == 3)
- return no_match;
-
- if (*(str + 1) == '.' || *(str + 1) == '/')
- return no_match;
-
- if (*(str + 1) == '\0')
- return partly_match;
-
- dots++;
- break;
- }
-
- if (!isdigit ((int) *str))
- return no_match;
-
- str++;
- }
-
- if (str - sp > 3)
- return no_match;
-
- strncpy (buf, sp, str - sp);
- if (atoi (buf) > 255)
- return no_match;
-
- if (dots == 3)
- {
- if (*str == '/')
- {
- if (*(str + 1) == '\0')
- return partly_match;
-
- str++;
- break;
- }
- else if (*str == '\0')
- return partly_match;
- }
-
- if (*str == '\0')
- return partly_match;
-
- str++;
- }
-
- sp = str;
- while (*str != '\0')
- {
- if (!isdigit ((int) *str))
- return no_match;
-
- str++;
- }
-
- if (atoi (sp) > 32)
- return no_match;
-
- return exact_match;
-}
-
-#define IPV6_ADDR_STR "0123456789abcdefABCDEF:."
-#define IPV6_PREFIX_STR "0123456789abcdefABCDEF:./"
-
-#ifdef HAVE_IPV6
-
-static enum match_type
-cmd_ipv6_match (const char *str)
-{
- struct sockaddr_in6 sin6_dummy;
- int ret;
-
- if (str == NULL)
- return partly_match;
-
- if (strspn (str, IPV6_ADDR_STR) != strlen (str))
- return no_match;
-
- /* use inet_pton that has a better support,
- * for example inet_pton can support the automatic addresses:
- * ::1.2.3.4
- */
- ret = inet_pton(AF_INET6, str, &sin6_dummy.sin6_addr);
-
- if (ret == 1)
- return exact_match;
-
- return no_match;
-}
-
-static enum match_type
-cmd_ipv6_prefix_match (const char *str)
-{
- struct sockaddr_in6 sin6_dummy;
- const char *delim = "/\0";
- char *dupe, *prefix, *mask, *context, *endptr;
- int nmask = -1;
-
- if (str == NULL)
- return partly_match;
-
- if (strspn (str, IPV6_PREFIX_STR) != strlen (str))
- return no_match;
-
- /* tokenize to address + mask */
- dupe = XMALLOC(MTYPE_TMP, strlen(str)+1);
- strncpy(dupe, str, strlen(str)+1);
- prefix = strtok_r(dupe, delim, &context);
- mask = strtok_r(NULL, delim, &context);
-
- if (!mask)
- return partly_match;
-
- /* validate prefix */
- if (inet_pton(AF_INET6, prefix, &sin6_dummy.sin6_addr) != 1)
- return no_match;
-
- /* validate mask */
- nmask = strtol (mask, &endptr, 10);
- if (*endptr != '\0' || nmask < 0 || nmask > 128)
- return no_match;
-
- XFREE(MTYPE_TMP, dupe);
-
- return exact_match;
+ return cnode->cmdgraph;
}
-#endif /* HAVE_IPV6 */
-
-#define DECIMAL_STRLEN_MAX 20
-
static int
-cmd_range_match (const char *range, const char *str)
-{
- char *p;
- char buf[DECIMAL_STRLEN_MAX + 1];
- char *endptr = NULL;
- signed long long min, max, val;
-
- if (str == NULL)
+cmd_try_do_shortcut (enum node_type node, char* first_word) {
+ if ( first_word != NULL &&
+ node != AUTH_NODE &&
+ node != VIEW_NODE &&
+ node != AUTH_ENABLE_NODE &&
+ node != ENABLE_NODE &&
+ 0 == strcmp( "do", first_word ) )
return 1;
-
- val = strtoll (str, &endptr, 10);
- if (*endptr != '\0')
- return 0;
- val = llabs(val);
-
- range++;
- p = strchr (range, '-');
- if (p == NULL)
- return 0;
- if (p - range > DECIMAL_STRLEN_MAX)
- return 0;
- strncpy (buf, range, p - range);
- buf[p - range] = '\0';
- min = strtoll (buf, &endptr, 10);
- if (*endptr != '\0')
- return 0;
-
- range = p + 1;
- p = strchr (range, '>');
- if (p == NULL)
- return 0;
- if (p - range > DECIMAL_STRLEN_MAX)
- return 0;
- strncpy (buf, range, p - range);
- buf[p - range] = '\0';
- max = strtoll (buf, &endptr, 10);
- if (*endptr != '\0')
- return 0;
-
- if (val < min || val > max)
- return 0;
-
- return 1;
-}
-
-static enum match_type
-cmd_word_match(struct cmd_token *token,
- enum filter_type filter,
- const char *word)
-{
- const char *str;
- enum match_type match_type;
-
- str = token->cmd;
-
- if (filter == FILTER_RELAXED)
- if (!word || !strlen(word))
- return partly_match;
-
- if (!word)
- return no_match;
-
- switch (token->terminal)
- {
- case TERMINAL_VARARG:
- return vararg_match;
-
- case TERMINAL_RANGE:
- if (cmd_range_match(str, word))
- return range_match;
- break;
-
- case TERMINAL_IPV6:
- match_type = cmd_ipv6_match(word);
- if ((filter == FILTER_RELAXED && match_type != no_match)
- || (filter == FILTER_STRICT && match_type == exact_match))
- return ipv6_match;
- break;
-
- case TERMINAL_IPV6_PREFIX:
- match_type = cmd_ipv6_prefix_match(word);
- if ((filter == FILTER_RELAXED && match_type != no_match)
- || (filter == FILTER_STRICT && match_type == exact_match))
- return ipv6_prefix_match;
- break;
-
- case TERMINAL_IPV4:
- match_type = cmd_ipv4_match(word);
- if ((filter == FILTER_RELAXED && match_type != no_match)
- || (filter == FILTER_STRICT && match_type == exact_match))
- return ipv4_match;
- break;
-
- case TERMINAL_IPV4_PREFIX:
- match_type = cmd_ipv4_prefix_match(word);
- if ((filter == FILTER_RELAXED && match_type != no_match)
- || (filter == FILTER_STRICT && match_type == exact_match))
- return ipv4_prefix_match;
- break;
-
- case TERMINAL_OPTION:
- case TERMINAL_VARIABLE:
- return extend_match;
-
- case TERMINAL_LITERAL:
- if (filter == FILTER_RELAXED && !strncmp(str, word, strlen(word)))
- {
- if (!strcmp(str, word))
- return exact_match;
- return partly_match;
- }
- if (filter == FILTER_STRICT && !strcmp(str, word))
- return exact_match;
- break;
-
- default:
- assert (0);
- }
-
- return no_match;
-}
-
-struct cmd_matcher
-{
- struct cmd_element *cmd; /* The command element the matcher is using */
- enum filter_type filter; /* Whether to use strict or relaxed matching */
- vector vline; /* The tokenized commandline which is to be matched */
- unsigned int index; /* The index up to which matching should be done */
-
- /* If set, construct a list of matches at the position given by index */
- enum match_type *match_type;
- vector *match;
-
- unsigned int word_index; /* iterating over vline */
-};
-
-static int
-push_argument(int *argc, const char **argv, const char *arg)
-{
- if (!arg || !strlen(arg))
- arg = NULL;
-
- if (!argc || !argv)
- return 0;
-
- if (*argc >= CMD_ARGC_MAX)
- return -1;
-
- argv[(*argc)++] = arg;
return 0;
}
-static void
-cmd_matcher_record_match(struct cmd_matcher *matcher,
- enum match_type match_type,
- struct cmd_token *token)
-{
- if (matcher->word_index != matcher->index)
- return;
-
- if (matcher->match)
- {
- if (!*matcher->match)
- *matcher->match = vector_init(VECTOR_MIN_SIZE);
- vector_set(*matcher->match, token);
- }
-
- if (matcher->match_type)
- {
- if (match_type > *matcher->match_type)
- *matcher->match_type = match_type;
- }
-}
-
-static int
-cmd_matcher_words_left(struct cmd_matcher *matcher)
-{
- return matcher->word_index < vector_active(matcher->vline);
-}
-
-static const char*
-cmd_matcher_get_word(struct cmd_matcher *matcher)
-{
- assert(cmd_matcher_words_left(matcher));
-
- return vector_slot(matcher->vline, matcher->word_index);
-}
-
-static enum matcher_rv
-cmd_matcher_match_terminal(struct cmd_matcher *matcher,
- struct cmd_token *token,
- int *argc, const char **argv)
-{
- const char *word;
- enum match_type word_match;
-
- assert(token->type == TOKEN_TERMINAL);
-
- if (!cmd_matcher_words_left(matcher))
- {
- if (token->terminal == TERMINAL_OPTION)
- return MATCHER_OK; /* missing optional args are NOT pushed as NULL */
- else
- return MATCHER_INCOMPLETE;
- }
-
- word = cmd_matcher_get_word(matcher);
- word_match = cmd_word_match(token, matcher->filter, word);
- if (word_match == no_match)
- return MATCHER_NO_MATCH;
-
- /* We have to record the input word as argument if it matched
- * against a variable. */
- if (TERMINAL_RECORD (token->terminal))
- {
- if (push_argument(argc, argv, word))
- return MATCHER_EXCEED_ARGC_MAX;
- }
-
- cmd_matcher_record_match(matcher, word_match, token);
-
- matcher->word_index++;
-
- /* A vararg token should consume all left over words as arguments */
- if (token->terminal == TERMINAL_VARARG)
- while (cmd_matcher_words_left(matcher))
- {
- word = cmd_matcher_get_word(matcher);
- if (word && strlen(word))
- push_argument(argc, argv, word);
- matcher->word_index++;
- }
-
- return MATCHER_OK;
-}
-
-static enum matcher_rv
-cmd_matcher_match_multiple(struct cmd_matcher *matcher,
- struct cmd_token *token,
- int *argc, const char **argv)
-{
- enum match_type multiple_match;
- unsigned int multiple_index;
- const char *word;
- const char *arg = NULL;
- struct cmd_token *word_token;
- enum match_type word_match;
-
- assert(token->type == TOKEN_MULTIPLE);
-
- multiple_match = no_match;
-
- if (!cmd_matcher_words_left(matcher))
- return MATCHER_INCOMPLETE;
-
- word = cmd_matcher_get_word(matcher);
- for (multiple_index = 0;
- multiple_index < vector_active(token->multiple);
- multiple_index++)
- {
- word_token = vector_slot(token->multiple, multiple_index);
-
- word_match = cmd_word_match(word_token, matcher->filter, word);
- if (word_match == no_match)
- continue;
-
- cmd_matcher_record_match(matcher, word_match, word_token);
-
- if (word_match > multiple_match)
- {
- multiple_match = word_match;
- arg = word;
- }
- /* To mimic the behavior of the old command implementation, we
- * tolerate any ambiguities here :/ */
- }
-
- matcher->word_index++;
-
- if (multiple_match == no_match)
- return MATCHER_NO_MATCH;
-
- if (push_argument(argc, argv, arg))
- return MATCHER_EXCEED_ARGC_MAX;
-
- return MATCHER_OK;
-}
-
-static enum matcher_rv
-cmd_matcher_read_keywords(struct cmd_matcher *matcher,
- struct cmd_token *token,
- vector args_vector)
-{
- unsigned int i;
- unsigned long keyword_mask;
- unsigned int keyword_found;
- enum match_type keyword_match;
- enum match_type word_match;
- vector keyword_vector;
- struct cmd_token *word_token;
- const char *word;
- int keyword_argc;
- const char **keyword_argv;
- enum matcher_rv rv = MATCHER_OK;
-
- keyword_mask = 0;
- while (1)
- {
- if (!cmd_matcher_words_left(matcher))
- return MATCHER_OK;
-
- word = cmd_matcher_get_word(matcher);
-
- keyword_found = -1;
- keyword_match = no_match;
- for (i = 0; i < vector_active(token->keyword); i++)
- {
- if (keyword_mask & (1 << i))
- continue;
-
- keyword_vector = vector_slot(token->keyword, i);
- word_token = vector_slot(keyword_vector, 0);
-
- word_match = cmd_word_match(word_token, matcher->filter, word);
- if (word_match == no_match)
- continue;
-
- cmd_matcher_record_match(matcher, word_match, word_token);
-
- if (word_match > keyword_match)
- {
- keyword_match = word_match;
- keyword_found = i;
- }
- else if (word_match == keyword_match)
- {
- if (matcher->word_index != matcher->index || args_vector)
- return MATCHER_AMBIGUOUS;
- }
- }
-
- if (keyword_found == (unsigned int)-1)
- return MATCHER_NO_MATCH;
-
- matcher->word_index++;
-
- if (matcher->word_index > matcher->index)
- return MATCHER_OK;
-
- keyword_mask |= (1 << keyword_found);
-
- if (args_vector)
- {
- keyword_argc = 0;
- keyword_argv = XMALLOC(MTYPE_TMP, (CMD_ARGC_MAX + 1) * sizeof(char*));
- /* We use -1 as a marker for unused fields as NULL might be a valid value */
- for (i = 0; i < CMD_ARGC_MAX + 1; i++)
- keyword_argv[i] = (void*)-1;
- vector_set_index(args_vector, keyword_found, keyword_argv);
- }
- else
- {
- keyword_argv = NULL;
- }
-
- keyword_vector = vector_slot(token->keyword, keyword_found);
- /* the keyword itself is at 0. We are only interested in the arguments,
- * so start counting at 1. */
- for (i = 1; i < vector_active(keyword_vector); i++)
- {
- word_token = vector_slot(keyword_vector, i);
-
- switch (word_token->type)
- {
- case TOKEN_TERMINAL:
- rv = cmd_matcher_match_terminal(matcher, word_token,
- &keyword_argc, keyword_argv);
- break;
- case TOKEN_MULTIPLE:
- rv = cmd_matcher_match_multiple(matcher, word_token,
- &keyword_argc, keyword_argv);
- break;
- case TOKEN_KEYWORD:
- assert(!"Keywords should never be nested.");
- break;
- }
-
- if (MATCHER_ERROR(rv))
- return rv;
-
- if (matcher->word_index > matcher->index)
- return MATCHER_OK;
- }
- }
- /* not reached */
-}
-
-static enum matcher_rv
-cmd_matcher_build_keyword_args(struct cmd_matcher *matcher,
- struct cmd_token *token,
- int *argc, const char **argv,
- vector keyword_args_vector)
-{
- unsigned int i, j;
- const char **keyword_args;
- vector keyword_vector;
- struct cmd_token *word_token;
- const char *arg;
- enum matcher_rv rv;
-
- rv = MATCHER_OK;
-
- if (keyword_args_vector == NULL)
- return rv;
-
- for (i = 0; i < vector_active(token->keyword); i++)
- {
- keyword_vector = vector_slot(token->keyword, i);
- keyword_args = vector_lookup(keyword_args_vector, i);
-
- if (vector_active(keyword_vector) == 1)
- {
- /* this is a keyword without arguments */
- if (keyword_args)
- {
- word_token = vector_slot(keyword_vector, 0);
- arg = word_token->cmd;
- XFREE (MTYPE_TMP, keyword_args);
- }
- else
- {
- arg = NULL;
- }
-
- if (push_argument(argc, argv, arg))
- rv = MATCHER_EXCEED_ARGC_MAX;
- }
- else
- {
- /* this is a keyword with arguments */
- if (keyword_args)
- {
- /* the keyword was present, so just fill in the arguments */
- for (j = 0; keyword_args[j] != (void*)-1; j++)
- if (push_argument(argc, argv, keyword_args[j]))
- rv = MATCHER_EXCEED_ARGC_MAX;
- XFREE(MTYPE_TMP, keyword_args);
- }
- else
- {
- /* the keyword was not present, insert NULL for the arguments
- * the keyword would have taken. */
- for (j = 1; j < vector_active(keyword_vector); j++)
- {
- word_token = vector_slot(keyword_vector, j);
- if ((word_token->type == TOKEN_TERMINAL
- && TERMINAL_RECORD (word_token->terminal))
- || word_token->type == TOKEN_MULTIPLE)
- {
- if (push_argument(argc, argv, NULL))
- rv = MATCHER_EXCEED_ARGC_MAX;
- }
- }
- }
- }
- }
- vector_free(keyword_args_vector);
- return rv;
-}
-
-static enum matcher_rv
-cmd_matcher_match_keyword(struct cmd_matcher *matcher,
- struct cmd_token *token,
- int *argc, const char **argv)
-{
- vector keyword_args_vector;
- enum matcher_rv reader_rv;
- enum matcher_rv builder_rv;
-
- assert(token->type == TOKEN_KEYWORD);
-
- if (argc && argv)
- keyword_args_vector = vector_init(VECTOR_MIN_SIZE);
- else
- keyword_args_vector = NULL;
-
- reader_rv = cmd_matcher_read_keywords(matcher, token, keyword_args_vector);
- builder_rv = cmd_matcher_build_keyword_args(matcher, token, argc,
- argv, keyword_args_vector);
- /* keyword_args_vector is consumed by cmd_matcher_build_keyword_args */
-
- if (!MATCHER_ERROR(reader_rv) && MATCHER_ERROR(builder_rv))
- return builder_rv;
-
- return reader_rv;
-}
-
-static void
-cmd_matcher_init(struct cmd_matcher *matcher,
- struct cmd_element *cmd,
- enum filter_type filter,
- vector vline,
- unsigned int index,
- enum match_type *match_type,
- vector *match)
-{
- memset(matcher, 0, sizeof(*matcher));
-
- matcher->cmd = cmd;
- matcher->filter = filter;
- matcher->vline = vline;
- matcher->index = index;
-
- matcher->match_type = match_type;
- if (matcher->match_type)
- *matcher->match_type = no_match;
- matcher->match = match;
-
- matcher->word_index = 0;
-}
-
-static enum matcher_rv
-cmd_element_match(struct cmd_element *cmd_element,
- enum filter_type filter,
- vector vline,
- unsigned int index,
- enum match_type *match_type,
- vector *match,
- int *argc,
- const char **argv)
-{
- struct cmd_matcher matcher;
- unsigned int token_index;
- enum matcher_rv rv = MATCHER_OK;
-
- cmd_matcher_init(&matcher, cmd_element, filter,
- vline, index, match_type, match);
-
- if (argc != NULL)
- *argc = 0;
-
- for (token_index = 0;
- token_index < vector_active(cmd_element->tokens);
- token_index++)
- {
- struct cmd_token *token = vector_slot(cmd_element->tokens, token_index);
-
- switch (token->type)
- {
- case TOKEN_TERMINAL:
- rv = cmd_matcher_match_terminal(&matcher, token, argc, argv);
- break;
- case TOKEN_MULTIPLE:
- rv = cmd_matcher_match_multiple(&matcher, token, argc, argv);
- break;
- case TOKEN_KEYWORD:
- rv = cmd_matcher_match_keyword(&matcher, token, argc, argv);
- }
-
- if (MATCHER_ERROR(rv))
- return rv;
-
- if (matcher.word_index > index)
- return MATCHER_OK;
- }
-
- /* return MATCHER_COMPLETE if all words were consumed */
- if (matcher.word_index >= vector_active(vline))
- return MATCHER_COMPLETE;
-
- /* return MATCHER_COMPLETE also if only an empty word is left. */
- if (matcher.word_index == vector_active(vline) - 1
- && (!vector_slot(vline, matcher.word_index)
- || !strlen((char*)vector_slot(vline, matcher.word_index))))
- return MATCHER_COMPLETE;
-
- return MATCHER_NO_MATCH; /* command is too long to match */
-}
-
-/**
- * Filter a given vector of commands against a given commandline and
- * calculate possible completions.
- *
- * @param commands A vector of struct cmd_element*. Commands that don't
- * match against the given command line will be overwritten
- * with NULL in that vector.
- * @param filter Either FILTER_RELAXED or FILTER_STRICT. This basically
- * determines how incomplete commands are handled, compare with
- * cmd_word_match for details.
- * @param vline A vector of char* containing the tokenized commandline.
- * @param index Only match up to the given token of the commandline.
- * @param match_type Record the type of the best match here.
- * @param matches Record the matches here. For each cmd_element in the commands
- * vector, a match vector will be created in the matches vector.
- * That vector will contain all struct command_token* of the
- * cmd_element which matched against the given vline at the given
- * index.
- * @return A code specifying if an error occured. If all went right, it's
- * CMD_SUCCESS.
- */
-static int
-cmd_vector_filter(vector commands,
- enum filter_type filter,
- vector vline,
- unsigned int index,
- enum match_type *match_type,
- vector *matches)
-{
- unsigned int i;
- struct cmd_element *cmd_element;
- enum match_type best_match;
- enum match_type element_match;
- enum matcher_rv matcher_rv;
-
- best_match = no_match;
- *matches = vector_init(VECTOR_MIN_SIZE);
-
- for (i = 0; i < vector_active (commands); i++)
- if ((cmd_element = vector_slot (commands, i)) != NULL)
- {
- vector_set_index(*matches, i, NULL);
- matcher_rv = cmd_element_match(cmd_element, filter,
- vline, index,
- &element_match,
- (vector*)&vector_slot(*matches, i),
- NULL, NULL);
- if (MATCHER_ERROR(matcher_rv))
- {
- vector_slot(commands, i) = NULL;
- if (matcher_rv == MATCHER_AMBIGUOUS)
- return CMD_ERR_AMBIGUOUS;
- if (matcher_rv == MATCHER_EXCEED_ARGC_MAX)
- return CMD_ERR_EXEED_ARGC_MAX;
- }
- else if (element_match > best_match)
- {
- best_match = element_match;
- }
- }
- *match_type = best_match;
- return CMD_SUCCESS;
-}
-
/**
- * Check whether a given commandline is complete if used for a specific
- * cmd_element.
- *
- * @param cmd_element A cmd_element against which the commandline should be
- * checked.
- * @param vline The tokenized commandline.
- * @return 1 if the given commandline is complete, 0 otherwise.
+ * Compare function for cmd_token.
+ * Used with qsort to sort command completions.
*/
static int
-cmd_is_complete(struct cmd_element *cmd_element,
- vector vline)
+compare_completions (const void *fst, const void *snd)
{
- enum matcher_rv rv;
-
- rv = cmd_element_match(cmd_element,
- FILTER_RELAXED,
- vline, -1,
- NULL, NULL,
- NULL, NULL);
- return (rv == MATCHER_COMPLETE);
+ struct cmd_token *first = *(struct cmd_token **) fst,
+ *secnd = *(struct cmd_token **) snd;
+ return strcmp (first->text, secnd->text);
}
/**
- * Parse a given commandline and construct a list of arguments for the
- * given command_element.
+ * Takes a list of completions returned by command_complete,
+ * dedeuplicates them based on both text and description,
+ * sorts them, and returns them as a vector.
*
- * @param cmd_element The cmd_element for which we want to construct arguments.
- * @param vline The tokenized commandline.
- * @param argc Where to store the argument count.
- * @param argv Where to store the argument list. Should be at least
- * CMD_ARGC_MAX elements long.
- * @return CMD_SUCCESS if everything went alright, an error otherwise.
+ * @param completions linked list of cmd_token
+ * @return deduplicated and sorted vector with
*/
-static int
-cmd_parse(struct cmd_element *cmd_element,
- vector vline,
- int *argc, const char **argv)
+static vector
+completions_to_vec (struct list *completions)
{
- enum matcher_rv rv = cmd_element_match(cmd_element,
- FILTER_RELAXED,
- vline, -1,
- NULL, NULL,
- argc, argv);
- switch (rv)
- {
- case MATCHER_COMPLETE:
- return CMD_SUCCESS;
+ vector comps = vector_init (VECTOR_MIN_SIZE);
- case MATCHER_NO_MATCH:
- return CMD_ERR_NO_MATCH;
-
- case MATCHER_AMBIGUOUS:
- return CMD_ERR_AMBIGUOUS;
-
- case MATCHER_EXCEED_ARGC_MAX:
- return CMD_ERR_EXEED_ARGC_MAX;
+ struct listnode *ln;
+ struct cmd_token *token, *cr = NULL;
+ unsigned int i, exists;
+ for (ALL_LIST_ELEMENTS_RO(completions,ln,token))
+ {
+ if (token->type == END_TKN && (cr = token))
+ continue;
- default:
- return CMD_ERR_INCOMPLETE;
+ // linear search for token in completions vector
+ exists = 0;
+ for (i = 0; i < vector_active (comps) && !exists; i++)
+ {
+ struct cmd_token *curr = vector_slot (comps, i);
+ exists = !strcmp (curr->text, token->text) &&
+ !strcmp (curr->desc, token->desc);
}
-}
-
-/* Check ambiguous match */
-static int
-is_cmd_ambiguous (vector cmd_vector,
- const char *command,
- vector matches,
- enum match_type type)
-{
- unsigned int i;
- unsigned int j;
- const char *str = NULL;
- const char *matched = NULL;
- vector match_vector;
- struct cmd_token *cmd_token;
- if (command == NULL)
- command = "";
-
- for (i = 0; i < vector_active (matches); i++)
- if ((match_vector = vector_slot (matches, i)) != NULL)
- {
- int match = 0;
-
- for (j = 0; j < vector_active (match_vector); j++)
- if ((cmd_token = vector_slot (match_vector, j)) != NULL)
- {
- enum match_type ret;
-
- assert(cmd_token->type == TOKEN_TERMINAL);
- if (cmd_token->type != TOKEN_TERMINAL)
- continue;
-
- str = cmd_token->cmd;
-
- switch (type)
- {
- case exact_match:
- if (!TERMINAL_RECORD (cmd_token->terminal)
- && strcmp (command, str) == 0)
- match++;
- break;
- case partly_match:
- if (!TERMINAL_RECORD (cmd_token->terminal)
- && strncmp (command, str, strlen (command)) == 0)
- {
- if (matched && strcmp (matched, str) != 0)
- return 1; /* There is ambiguous match. */
- else
- matched = str;
- match++;
- }
- break;
- case range_match:
- if (cmd_range_match (str, command))
- {
- if (matched && strcmp (matched, str) != 0)
- return 1;
- else
- matched = str;
- match++;
- }
- break;
-#ifdef HAVE_IPV6
- case ipv6_match:
- if (cmd_token->terminal == TERMINAL_IPV6)
- match++;
- break;
- case ipv6_prefix_match:
- if ((ret = cmd_ipv6_prefix_match (command)) != no_match)
- {
- if (ret == partly_match)
- return 2; /* There is incomplete match. */
-
- match++;
- }
- break;
-#endif /* HAVE_IPV6 */
- case ipv4_match:
- if (cmd_token->terminal == TERMINAL_IPV4)
- match++;
- break;
- case ipv4_prefix_match:
- if ((ret = cmd_ipv4_prefix_match (command)) != no_match)
- {
- if (ret == partly_match)
- return 2; /* There is incomplete match. */
-
- match++;
- }
- break;
- case extend_match:
- if (TERMINAL_RECORD (cmd_token->terminal))
- match++;
- break;
- case no_match:
- default:
- break;
- }
- }
- if (!match)
- vector_slot (cmd_vector, i) = NULL;
- }
- return 0;
-}
-
-/* If src matches dst return dst string, otherwise return NULL */
-static const char *
-cmd_entry_function (const char *src, struct cmd_token *token)
-{
- const char *dst = token->cmd;
-
- /* Skip variable arguments. */
- if (TERMINAL_RECORD (token->terminal))
- return NULL;
-
- /* In case of 'command \t', given src is NULL string. */
- if (src == NULL)
- return dst;
-
- /* Matched with input string. */
- if (strncmp (src, dst, strlen (src)) == 0)
- return dst;
-
- return NULL;
-}
-
-/* If src matches dst return dst string, otherwise return NULL */
-/* This version will return the dst string always if it is
- CMD_VARIABLE for '?' key processing */
-static const char *
-cmd_entry_function_desc (const char *src, struct cmd_token *token)
-{
- const char *dst = token->cmd;
-
- switch (token->terminal)
- {
- case TERMINAL_VARARG:
- return dst;
-
- case TERMINAL_RANGE:
- if (cmd_range_match (dst, src))
- return dst;
- else
- return NULL;
-
- case TERMINAL_IPV6:
- if (cmd_ipv6_match (src))
- return dst;
- else
- return NULL;
-
- case TERMINAL_IPV6_PREFIX:
- if (cmd_ipv6_prefix_match (src))
- return dst;
- else
- return NULL;
-
- case TERMINAL_IPV4:
- if (cmd_ipv4_match (src))
- return dst;
- else
- return NULL;
-
- case TERMINAL_IPV4_PREFIX:
- if (cmd_ipv4_prefix_match (src))
- return dst;
- else
- return NULL;
-
- /* Optional or variable commands always match on '?' */
- case TERMINAL_OPTION:
- case TERMINAL_VARIABLE:
- return dst;
-
- case TERMINAL_LITERAL:
- /* In case of 'command \t', given src is NULL string. */
- if (src == NULL)
- return dst;
-
- if (strncmp (src, dst, strlen (src)) == 0)
- return dst;
- else
- return NULL;
+ if (!exists)
+ vector_set (comps, copy_cmd_token (token));
+ }
- default:
- assert(0);
- return NULL;
- }
-}
+ // sort completions
+ qsort (comps->index,
+ vector_active (comps),
+ sizeof (void *),
+ &compare_completions);
-/**
- * Check whether a string is already present in a vector of strings.
- * @param v A vector of char*.
- * @param str A char*.
- * @return 0 if str is already present in the vector, 1 otherwise.
- */
-static int
-cmd_unique_string (vector v, const char *str)
-{
- unsigned int i;
- char *match;
+ if (cr)
+ {
+ vector_set_index (comps, vector_active (comps), NULL);
+ memmove (comps->index + 1, comps->index, (comps->alloced - 1) * sizeof (void *));
+ vector_set_index (comps, 0, copy_cmd_token (cr));
+ }
- for (i = 0; i < vector_active (v); i++)
- if ((match = vector_slot (v, i)) != NULL)
- if (strcmp (match, str) == 0)
- return 0;
- return 1;
+ return comps;
}
-
/**
- * Check whether a struct cmd_token matching a given string is already
- * present in a vector of struct cmd_token.
- * @param v A vector of struct cmd_token*.
- * @param str A char* which should be searched for.
- * @return 0 if there is a struct cmd_token* with its cmd matching str,
- * 1 otherwise.
+ * Generates a vector of cmd_token representing possible completions
+ * on the current input.
+ *
+ * @param vline the vectorized input line
+ * @param vty the vty with the node to match on
+ * @param status pointer to matcher status code
*/
-static int
-desc_unique_string (vector v, const char *str)
-{
- unsigned int i;
- struct cmd_token *token;
-
- for (i = 0; i < vector_active (v); i++)
- if ((token = vector_slot (v, i)) != NULL)
- if (strcmp (token->cmd, str) == 0)
- return 0;
- return 1;
-}
-
-static int
-cmd_try_do_shortcut (enum node_type node, char* first_word) {
- if ( first_word != NULL &&
- node != AUTH_NODE &&
- node != VIEW_NODE &&
- node != AUTH_ENABLE_NODE &&
- node != ENABLE_NODE &&
- 0 == strcmp( "do", first_word ) )
- return 1;
- return 0;
-}
-
-static void
-cmd_matches_free(vector *matches)
-{
- unsigned int i;
- vector cmd_matches;
-
- for (i = 0; i < vector_active(*matches); i++)
- if ((cmd_matches = vector_slot(*matches, i)) != NULL)
- vector_free(cmd_matches);
- vector_free(*matches);
- *matches = NULL;
-}
-
-static int
-cmd_describe_cmp(const void *a, const void *b)
-{
- const struct cmd_token *first = *(struct cmd_token * const *)a;
- const struct cmd_token *second = *(struct cmd_token * const *)b;
-
- return strcmp(first->cmd, second->cmd);
-}
-
-static void
-cmd_describe_sort(vector matchvec)
-{
- qsort(matchvec->index, vector_active(matchvec),
- sizeof(void*), cmd_describe_cmp);
-}
-
-/* '?' describe command support. */
static vector
-cmd_describe_command_real (vector vline, struct vty *vty, int *status)
+cmd_complete_command_real (vector vline, struct vty *vty, int *status)
{
- unsigned int i;
- vector cmd_vector;
-#define INIT_MATCHVEC_SIZE 10
- vector matchvec;
- struct cmd_element *cmd_element;
- unsigned int index;
- int ret;
- enum match_type match;
- char *command;
- vector matches = NULL;
- vector match_vector;
- uint32_t command_found = 0;
- const char *last_word;
-
- /* Set index. */
- if (vector_active (vline) == 0)
- {
- *status = CMD_ERR_NO_MATCH;
- return NULL;
- }
-
- index = vector_active (vline) - 1;
+ struct list *completions;
+ struct graph *cmdgraph = cmd_node_graph (cmdvec, vty->node);
- /* Make copy vector of current node's command vector. */
- cmd_vector = vector_copy (cmd_node_vector (cmdvec, vty->node));
+ enum matcher_rv rv = command_complete (cmdgraph, vline, &completions);
- /* Prepare match vector */
- matchvec = vector_init (INIT_MATCHVEC_SIZE);
-
- /* Filter commands and build a list how they could possibly continue. */
- for (i = 0; i <= index; i++)
+ if (MATCHER_ERROR(rv))
+ {
+ switch (rv)
{
- command = vector_slot (vline, i);
-
- if (matches)
- cmd_matches_free(&matches);
-
- ret = cmd_vector_filter(cmd_vector,
- FILTER_RELAXED,
- vline, i,
- &match,
- &matches);
-
- if (ret != CMD_SUCCESS)
- {
- vector_free (cmd_vector);
- vector_free (matchvec);
- cmd_matches_free(&matches);
- *status = ret;
- return NULL;
- }
-
- /* The last match may well be ambigious, so break here */
- if (i == index)
- break;
-
- if (match == vararg_match)
- {
- /* We found a vararg match - so we can throw out the current matches here
- * and don't need to continue checking the command input */
- unsigned int j, k;
-
- for (j = 0; j < vector_active (matches); j++)
- if ((match_vector = vector_slot (matches, j)) != NULL)
- for (k = 0; k < vector_active (match_vector); k++)
- {
- struct cmd_token *token = vector_slot (match_vector, k);
- vector_set (matchvec, token);
- }
-
- *status = CMD_SUCCESS;
- vector_set(matchvec, &token_cr);
- vector_free (cmd_vector);
- cmd_matches_free(&matches);
- cmd_describe_sort(matchvec);
- return matchvec;
- }
-
- ret = is_cmd_ambiguous(cmd_vector, command, matches, match);
- if (ret == 1)
- {
- vector_free (cmd_vector);
- vector_free (matchvec);
- cmd_matches_free(&matches);
- *status = CMD_ERR_AMBIGUOUS;
- return NULL;
- }
- else if (ret == 2)
- {
- vector_free (cmd_vector);
- vector_free (matchvec);
- cmd_matches_free(&matches);
- *status = CMD_ERR_NO_MATCH;
- return NULL;
- }
+ case MATCHER_AMBIGUOUS:
+ *status = CMD_ERR_AMBIGUOUS;
+ default:
+ *status = CMD_ERR_NO_MATCH;
}
-
- /* Make description vector. */
- for (i = 0; i < vector_active (matches); i++) {
- if ((cmd_element = vector_slot (cmd_vector, i)) != NULL &&
- !(cmd_element->attr == CMD_ATTR_DEPRECATED ||
- cmd_element->attr == CMD_ATTR_HIDDEN))
- {
- unsigned int j;
- vector vline_trimmed;
-
- command_found++;
- last_word = vector_slot(vline, vector_active(vline) - 1);
- if (last_word == NULL || !strlen(last_word))
- {
- vline_trimmed = vector_copy(vline);
- vector_unset(vline_trimmed, vector_active(vline_trimmed) - 1);
-
- if (cmd_is_complete(cmd_element, vline_trimmed)
- && desc_unique_string(matchvec, command_cr))
- {
- if (match != vararg_match)
- vector_set(matchvec, &token_cr);
- }
-
- vector_free(vline_trimmed);
- }
-
- match_vector = vector_slot (matches, i);
- if (match_vector)
- for (j = 0; j < vector_active(match_vector); j++)
- {
- struct cmd_token *token = vector_slot(match_vector, j);
- const char *string;
-
- string = cmd_entry_function_desc(command, token);
- if (string && desc_unique_string(matchvec, string))
- vector_set(matchvec, token);
- }
- }
- }
-
- /*
- * We can get into this situation when the command is complete
- * but the last part of the command is an optional piece of
- * cli.
- */
- last_word = vector_slot(vline, vector_active(vline) - 1);
- if (command_found == 0 && (last_word == NULL || !strlen(last_word))) {
- vector_set(matchvec, &token_cr);
+ return NULL;
}
- vector_free (cmd_vector);
- cmd_matches_free(&matches);
+ vector comps = completions_to_vec (completions);
+ list_delete (completions);
- if (vector_slot (matchvec, 0) == NULL)
- {
- vector_free (matchvec);
+ // set status code appropriately
+ switch (vector_active (comps))
+ {
+ case 0:
*status = CMD_ERR_NO_MATCH;
- return NULL;
- }
+ break;
+ case 1:
+ *status = CMD_COMPLETE_FULL_MATCH;
+ break;
+ default:
+ *status = CMD_COMPLETE_LIST_MATCH;
+ }
- *status = CMD_SUCCESS;
- cmd_describe_sort(matchvec);
- return matchvec;
+ return comps;
}
vector
@@ -2260,285 +643,67 @@ cmd_describe_command (vector vline, struct vty *vty, int *status)
shifted_vline = vector_init (vector_count(vline));
/* use memcpy? */
- for (index = 1; index < vector_active (vline); index++)
- {
- vector_set_index (shifted_vline, index-1, vector_lookup(vline, index));
- }
+ for (index = 1; index < vector_active (vline); index++)
+ {
+ vector_set_index (shifted_vline, index-1, vector_lookup(vline, index));
+ }
- ret = cmd_describe_command_real (shifted_vline, vty, status);
+ ret = cmd_complete_command_real (shifted_vline, vty, status);
vector_free(shifted_vline);
vty->node = onode;
return ret;
}
-
- return cmd_describe_command_real (vline, vty, status);
+ return cmd_complete_command_real (vline, vty, status);
}
-
-/* Check LCD of matched command. */
-static int
-cmd_lcd (char **matched)
-{
- int i;
- int j;
- int lcd = -1;
- char *s1, *s2;
- char c1, c2;
-
- if (matched[0] == NULL || matched[1] == NULL)
- return 0;
-
- for (i = 1; matched[i] != NULL; i++)
- {
- s1 = matched[i - 1];
- s2 = matched[i];
-
- for (j = 0; (c1 = s1[j]) && (c2 = s2[j]); j++)
- if (c1 != c2)
- break;
-
- if (lcd < 0)
- lcd = j;
- else
- {
- if (lcd > j)
- lcd = j;
- }
- }
- return lcd;
-}
-
-static int
-cmd_complete_cmp(const void *a, const void *b)
-{
- const char *first = *(char * const *)a;
- const char *second = *(char * const *)b;
-
- if (!first)
- {
- if (!second)
- return 0;
- return 1;
- }
- if (!second)
- return -1;
-
- return strcmp(first, second);
-}
-
-static void
-cmd_complete_sort(vector matchvec)
-{
- qsort(matchvec->index, vector_active(matchvec),
- sizeof(void*), cmd_complete_cmp);
-}
-
-/* Command line completion support. */
-static char **
-cmd_complete_command_real (vector vline, struct vty *vty, int *status, int islib)
+char **
+cmd_complete_command_lib (vector vline, struct vty *vty, int *status, int islib)
{
- unsigned int i;
- vector cmd_vector = vector_copy (cmd_node_vector (cmdvec, vty->node));
-#define INIT_MATCHVEC_SIZE 10
- vector matchvec;
- unsigned int index;
- char **match_str;
- struct cmd_token *token;
- char *command;
- int lcd;
- vector matches = NULL;
- vector match_vector;
+ char **ret = NULL;
+ int original_node = vty->node;
+ vector input_line = vector_init (vector_count (vline));
- if (vector_active (vline) == 0)
- {
- vector_free (cmd_vector);
- *status = CMD_ERR_NO_MATCH;
- return NULL;
- }
- else
- index = vector_active (vline) - 1;
+ // if the first token is 'do' we'll want to execute the command in the enable node
+ int do_shortcut = cmd_try_do_shortcut (vty->node, vector_slot (vline, 0));
+ vty->node = do_shortcut ? ENABLE_NODE : original_node;
- /* First, filter by command string */
- for (i = 0; i <= index; i++)
- {
- command = vector_slot (vline, i);
- enum match_type match;
- int ret;
-
- if (matches)
- cmd_matches_free(&matches);
-
- /* First try completion match, if there is exactly match return 1 */
- ret = cmd_vector_filter(cmd_vector,
- FILTER_RELAXED,
- vline, i,
- &match,
- &matches);
-
- if (ret != CMD_SUCCESS)
- {
- vector_free(cmd_vector);
- cmd_matches_free(&matches);
- *status = ret;
- return NULL;
- }
-
- /* Break here - the completion mustn't be checked to be non-ambiguous */
- if (i == index)
- break;
-
- /* If there is exact match then filter ambiguous match else check
- ambiguousness. */
- ret = is_cmd_ambiguous (cmd_vector, command, matches, match);
- if (ret == 1)
- {
- vector_free (cmd_vector);
- cmd_matches_free(&matches);
- *status = CMD_ERR_AMBIGUOUS;
- return NULL;
- }
- }
-
- /* Prepare match vector. */
- matchvec = vector_init (INIT_MATCHVEC_SIZE);
+ // construct the input line we'll be matching on
+ unsigned int offset = (do_shortcut) ? 1 : 0;
+ for (unsigned index = 0; index + offset < vector_active (vline); index++)
+ vector_set_index (input_line, index + offset, vector_lookup (vline, index));
- /* Build the possible list of continuations into a list of completions */
- for (i = 0; i < vector_active (matches); i++)
- if ((match_vector = vector_slot (matches, i)))
+ // get token completions -- this is a copying operation
+ vector comps = cmd_complete_command_real (input_line, vty, status);
+ if (!MATCHER_ERROR (*status))
+ {
+ // copy completions text into an array of char*
+ ret = XMALLOC (MTYPE_TMP, vector_active (comps) * sizeof (char *) + 1);
+ unsigned int i;
+ for (i = 0; i < vector_active (comps); i++)
{
- const char *string;
- unsigned int j;
-
- for (j = 0; j < vector_active (match_vector); j++)
- if ((token = vector_slot (match_vector, j)))
- {
- string = cmd_entry_function (vector_slot (vline, index),
- token);
- if (string && cmd_unique_string (matchvec, string))
- vector_set (matchvec, (islib != 0 ?
- XSTRDUP (MTYPE_TMP, string) :
- strdup (string) /* rl freed */));
- }
+ struct cmd_token *token = vector_slot (comps, i);
+ ret[i] = XSTRDUP (MTYPE_TMP, token->text);
+ vector_unset (comps, i);
+ del_cmd_token (token);
}
+ // set the last element to NULL, which vty/vtysh uses as a sentinel value
+ ret[i] = NULL;
+ vector_free (comps);
+ comps = NULL;
+ }
- /* We don't need cmd_vector any more. */
- vector_free (cmd_vector);
- cmd_matches_free(&matches);
-
- /* No matched command */
- if (vector_slot (matchvec, 0) == NULL)
- {
- vector_free (matchvec);
-
- /* In case of 'command \t' pattern. Do you need '?' command at
- the end of the line. */
- if (vector_slot (vline, index) == '\0')
- *status = CMD_ERR_NOTHING_TODO;
- else
- *status = CMD_ERR_NO_MATCH;
- return NULL;
- }
-
- /* Only one matched */
- if (vector_slot (matchvec, 1) == NULL)
- {
- size_t index_size = matchvec->alloced * sizeof (void *);
- match_str = XMALLOC (MTYPE_TMP, index_size);
- memcpy (match_str, matchvec->index, index_size);
- vector_free (matchvec);
-
- *status = CMD_COMPLETE_FULL_MATCH;
- return match_str;
- }
- /* Make it sure last element is NULL. */
- vector_set (matchvec, NULL);
-
- /* Check LCD of matched strings. */
- if (vector_slot (vline, index) != NULL)
- {
- lcd = cmd_lcd ((char **) matchvec->index);
-
- if (lcd)
- {
- int len = strlen (vector_slot (vline, index));
-
- if (len < lcd)
- {
- char *lcdstr;
-
- lcdstr = (islib != 0 ?
- XMALLOC (MTYPE_TMP, lcd + 1) :
- malloc(lcd + 1));
- memcpy (lcdstr, matchvec->index[0], lcd);
- lcdstr[lcd] = '\0';
-
- /* Free matchvec. */
- for (i = 0; i < vector_active (matchvec); i++)
- {
- if (vector_slot (matchvec, i))
- {
- if (islib != 0)
- XFREE (MTYPE_TMP, vector_slot (matchvec, i));
- else
- free (vector_slot (matchvec, i));
- }
- }
- vector_free (matchvec);
-
- /* Make new matchvec. */
- matchvec = vector_init (INIT_MATCHVEC_SIZE);
- vector_set (matchvec, lcdstr);
-
- size_t index_size = matchvec->alloced * sizeof (void *);
- match_str = XMALLOC (MTYPE_TMP, index_size);
- memcpy (match_str, matchvec->index, index_size);
- vector_free (matchvec);
-
- *status = CMD_COMPLETE_MATCH;
- return match_str;
- }
- }
- }
-
- match_str = (char **) matchvec->index;
- cmd_complete_sort(matchvec);
- vector_only_wrapper_free (matchvec);
- *status = CMD_COMPLETE_LIST_MATCH;
- return match_str;
-}
-
-char **
-cmd_complete_command_lib (vector vline, struct vty *vty, int *status, int islib)
-{
- char **ret;
-
- if ( cmd_try_do_shortcut(vty->node, vector_slot(vline, 0) ) )
- {
- enum node_type onode;
- vector shifted_vline;
- unsigned int index;
-
- onode = vty->node;
- vty->node = ENABLE_NODE;
- /* We can try it on enable node, cos' the vty is authenticated */
-
- shifted_vline = vector_init (vector_count(vline));
- /* use memcpy? */
- for (index = 1; index < vector_active (vline); index++)
- {
- vector_set_index (shifted_vline, index-1, vector_lookup(vline, index));
- }
+ // comps should always be null here
+ assert (!comps);
- ret = cmd_complete_command_real (shifted_vline, vty, status, islib);
+ // free the adjusted input line
+ vector_free (input_line);
- vector_free(shifted_vline);
- vty->node = onode;
- return ret;
- }
+ // reset vty->node to its original value
+ vty->node = original_node;
- return cmd_complete_command_real (vline, vty, status, islib);
+ return ret;
}
char **
@@ -2563,8 +728,8 @@ node_parent ( enum node_type node )
case BGP_ENCAP_NODE:
case BGP_ENCAPV6_NODE:
case BGP_VNC_DEFAULTS_NODE:
- case BGP_VNC_NVE_GROUP_NODE:
- case BGP_VNC_L2_GROUP_NODE:
+ case BGP_VNC_NVE_GROUP_NODE:
+ case BGP_VNC_L2_GROUP_NODE:
case BGP_IPV4_NODE:
case BGP_IPV4M_NODE:
case BGP_IPV6_NODE:
@@ -2601,109 +766,52 @@ node_parent ( enum node_type node )
/* Execute command by argument vline vector. */
static int
cmd_execute_command_real (vector vline,
- enum filter_type filter,
- struct vty *vty,
- struct cmd_element **cmd)
+ enum filter_type filter,
+ struct vty *vty,
+ struct cmd_element **cmd)
{
- unsigned int i;
- unsigned int index;
- vector cmd_vector;
- struct cmd_element *cmd_element;
- struct cmd_element *matched_element;
- unsigned int matched_count, incomplete_count;
- int argc;
- const char *argv[CMD_ARGC_MAX];
- enum match_type match = 0;
- char *command;
- int ret;
- vector matches;
-
- /* Make copy of command elements. */
- cmd_vector = vector_copy (cmd_node_vector (cmdvec, vty->node));
-
- for (index = 0; index < vector_active (vline); index++)
- {
- command = vector_slot (vline, index);
- ret = cmd_vector_filter(cmd_vector,
- filter,
- vline, index,
- &match,
- &matches);
-
- if (ret != CMD_SUCCESS)
- {
- cmd_matches_free(&matches);
- return ret;
- }
-
- if (match == vararg_match)
- {
- cmd_matches_free(&matches);
- break;
- }
-
- ret = is_cmd_ambiguous (cmd_vector, command, matches, match);
- cmd_matches_free(&matches);
-
- if (ret == 1)
- {
- vector_free(cmd_vector);
- return CMD_ERR_AMBIGUOUS;
- }
- else if (ret == 2)
- {
- vector_free(cmd_vector);
- return CMD_ERR_NO_MATCH;
- }
- }
+ struct list *argv_list;
+ enum matcher_rv status;
+ struct cmd_element *matched_element = NULL;
- /* Check matched count. */
- matched_element = NULL;
- matched_count = 0;
- incomplete_count = 0;
+ struct graph *cmdgraph = cmd_node_graph (cmdvec, vty->node);
+ status = command_match (cmdgraph, vline, &argv_list, &matched_element);
- for (i = 0; i < vector_active (cmd_vector); i++)
- if ((cmd_element = vector_slot (cmd_vector, i)))
- {
- if (cmd_is_complete(cmd_element, vline))
- {
- matched_element = cmd_element;
- matched_count++;
- }
- else
- {
- incomplete_count++;
- }
- }
-
- /* Finish of using cmd_vector. */
- vector_free (cmd_vector);
+ if (cmd)
+ *cmd = matched_element;
- /* To execute command, matched_count must be 1. */
- if (matched_count == 0)
+ // if matcher error, return corresponding CMD_ERR
+ if (MATCHER_ERROR(status))
+ switch (status)
{
- if (incomplete_count)
- return CMD_ERR_INCOMPLETE;
- else
- return CMD_ERR_NO_MATCH;
+ case MATCHER_INCOMPLETE:
+ return CMD_ERR_INCOMPLETE;
+ case MATCHER_AMBIGUOUS:
+ return CMD_ERR_AMBIGUOUS;
+ default:
+ return CMD_ERR_NO_MATCH;
}
- if (matched_count > 1)
- return CMD_ERR_AMBIGUOUS;
-
- ret = cmd_parse(matched_element, vline, &argc, argv);
- if (ret != CMD_SUCCESS)
- return ret;
+ // build argv array from argv list
+ struct cmd_token **argv = XMALLOC (MTYPE_TMP, argv_list->count * sizeof (struct cmd_token *));
+ struct listnode *ln;
+ struct cmd_token *token;
+ unsigned int i = 0;
+ for (ALL_LIST_ELEMENTS_RO(argv_list,ln,token))
+ argv[i++] = token;
- /* For vtysh execution. */
- if (cmd)
- *cmd = matched_element;
+ int argc = argv_list->count;
+ int ret;
if (matched_element->daemon)
- return CMD_SUCCESS_DAEMON;
+ ret = CMD_SUCCESS_DAEMON;
+ else
+ ret = matched_element->func (matched_element, vty, argc, argv);
+
+ // delete list and cmd_token's in it
+ list_delete (argv_list);
- /* Execute matched command. */
- return (*matched_element->func) (matched_element, vty, argc, argv);
+ return ret;
}
/**
@@ -2723,8 +831,8 @@ cmd_execute_command_real (vector vline,
*/
int
cmd_execute_command (vector vline, struct vty *vty, struct cmd_element **cmd,
- int vtysh) {
- int ret, saved_ret, tried = 0;
+ int vtysh) {
+ int ret, saved_ret = 0;
enum node_type onode, try_node;
onode = try_node = vty->node;
@@ -2739,10 +847,8 @@ cmd_execute_command (vector vline, struct vty *vty, struct cmd_element **cmd,
shifted_vline = vector_init (vector_count(vline));
/* use memcpy? */
- for (index = 1; index < vector_active (vline); index++)
- {
- vector_set_index (shifted_vline, index-1, vector_lookup(vline, index));
- }
+ for (index = 1; index < vector_active (vline); index++)
+ vector_set_index (shifted_vline, index-1, vector_lookup(vline, index));
ret = cmd_execute_command_real (shifted_vline, FILTER_RELAXED, vty, cmd);
@@ -2757,24 +863,22 @@ cmd_execute_command (vector vline, struct vty *vty, struct cmd_element **cmd,
if (vtysh)
return saved_ret;
- /* This assumes all nodes above CONFIG_NODE are childs of CONFIG_NODE */
- while ( ret != CMD_SUCCESS && ret != CMD_WARNING
- && vty->node > CONFIG_NODE )
+ if (ret != CMD_SUCCESS && ret != CMD_WARNING)
{
- try_node = node_parent(try_node);
- vty->node = try_node;
- ret = cmd_execute_command_real (vline, FILTER_RELAXED, vty, cmd);
- tried = 1;
- if (ret == CMD_SUCCESS || ret == CMD_WARNING)
- {
- /* succesfull command, leave the node as is */
- return ret;
- }
+ /* This assumes all nodes above CONFIG_NODE are childs of CONFIG_NODE */
+ while (vty->node > CONFIG_NODE)
+ {
+ try_node = node_parent(try_node);
+ vty->node = try_node;
+ ret = cmd_execute_command_real (vline, FILTER_RELAXED, vty, cmd);
+ if (ret == CMD_SUCCESS || ret == CMD_WARNING)
+ return ret;
+ }
+ /* no command succeeded, reset the vty to the original node */
+ vty->node = onode;
}
- /* no command succeeded, reset the vty to the original node and
- return the error for this node */
- if ( tried )
- vty->node = onode;
+
+ /* return command status for original node */
return saved_ret;
}
@@ -2793,7 +897,7 @@ cmd_execute_command (vector vline, struct vty *vty, struct cmd_element **cmd,
*/
int
cmd_execute_command_strict (vector vline, struct vty *vty,
- struct cmd_element **cmd)
+ struct cmd_element **cmd)
{
return cmd_execute_command_real(vline, FILTER_STRICT, vty, cmd);
}
@@ -2837,7 +941,7 @@ command_config_read_one_line (struct vty *vty, struct cmd_element **cmd, int use
while (!(use_daemon && ret == CMD_SUCCESS_DAEMON) &&
!(!use_daemon && ret == CMD_ERR_NOTHING_TODO) &&
- ret != CMD_SUCCESS &&
+ ret != CMD_SUCCESS &&
ret != CMD_WARNING &&
vty->node > CONFIG_NODE) {
vty->node = node_parent(vty->node);
@@ -2848,14 +952,16 @@ command_config_read_one_line (struct vty *vty, struct cmd_element **cmd, int use
// stay at the same node
if (!(use_daemon && ret == CMD_SUCCESS_DAEMON) &&
!(!use_daemon && ret == CMD_ERR_NOTHING_TODO) &&
- ret != CMD_SUCCESS &&
+ ret != CMD_SUCCESS &&
ret != CMD_WARNING)
{
- vty->node = saved_node;
- memcpy(vty->error_buf, vty->buf, VTY_BUFSIZ);
+ vty->node = saved_node;
}
}
+ if (ret != CMD_SUCCESS && ret != CMD_WARNING)
+ memcpy (vty->error_buf, vty->buf, VTY_BUFSIZ);
+
cmd_free_strvec (vline);
return ret;
@@ -2871,13 +977,13 @@ config_from_file (struct vty *vty, FILE *fp, unsigned int *line_num)
while (fgets (vty->buf, VTY_BUFSIZ, fp))
{
if (!error_ret)
- ++(*line_num);
+ ++(*line_num);
ret = command_config_read_one_line (vty, NULL, 0);
if (ret != CMD_SUCCESS && ret != CMD_WARNING &&
- ret != CMD_ERR_NOTHING_TODO)
- error_ret = ret;
+ ret != CMD_ERR_NOTHING_TODO)
+ error_ret = ret;
}
if (error_ret) {
@@ -2905,7 +1011,7 @@ DEFUN (config_terminal,
}
/* Enable command */
-DEFUN (enable,
+DEFUN (enable,
config_enable_cmd,
"enable",
"Turn on privileged mode command\n")
@@ -2921,7 +1027,7 @@ DEFUN (enable,
}
/* Disable command */
-DEFUN (disable,
+DEFUN (disable,
config_disable_cmd,
"disable",
"Turn off privileged mode command\n")
@@ -2942,9 +1048,9 @@ DEFUN (config_exit,
case VIEW_NODE:
case ENABLE_NODE:
if (vty_shell (vty))
- exit (0);
+ exit (0);
else
- vty->status = VTY_CLOSE;
+ vty->status = VTY_CLOSE;
break;
case CONFIG_NODE:
vty->node = ENABLE_NODE;
@@ -3007,12 +1113,16 @@ DEFUN (config_exit,
return CMD_SUCCESS;
}
-/* quit is alias of exit. */
-ALIAS (config_exit,
+/* ALIAS_FIXME */
+DEFUN (config_quit,
config_quit_cmd,
"quit",
"Exit current mode and down to previous mode\n")
-
+{
+ return config_exit (self, vty, argc, argv);
+}
+
+
/* End of configuration. */
DEFUN (config_end,
config_end_cmd,
@@ -3078,7 +1188,7 @@ DEFUN (show_version,
"Displays zebra version\n")
{
vty_out (vty, "Quagga %s (%s).%s", QUAGGA_VERSION, host.name?host.name:"",
- VTY_NEWLINE);
+ VTY_NEWLINE);
vty_out (vty, "%s%s%s", QUAGGA_COPYRIGHT, GIT_INFO, VTY_NEWLINE);
vty_out (vty, "configured with:%s %s%s", VTY_NEWLINE,
QUAGGA_CONFIG_ARGS, VTY_NEWLINE);
@@ -3092,8 +1202,8 @@ DEFUN (config_help,
"help",
"Description of the interactive help system\n")
{
- vty_out (vty,
- "Quagga VTY provides advanced help feature. When you need help,%s\
+ vty_out (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\
@@ -3105,37 +1215,90 @@ 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%s", VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE,
- VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE,
- VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE);
+ VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE,
+ VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE);
return CMD_SUCCESS;
}
+static void
+permute (struct graph_node *start, struct vty *vty)
+{
+ static struct list *position = NULL;
+ if (!position) position = list_new ();
+
+ // recursive dfs
+ listnode_add (position, start);
+ for (unsigned int i = 0; i < vector_active (start->to); i++)
+ {
+ struct graph_node *gn = vector_slot (start->to, i);
+ struct cmd_token *tok = gn->data;
+ if (tok->type == END_TKN || gn == start)
+ {
+ struct graph_node *gnn;
+ struct listnode *ln;
+ vty_out (vty, " ");
+ for (ALL_LIST_ELEMENTS_RO (position,ln,gnn))
+ {
+ struct cmd_token *tt = gnn->data;
+ if (tt->type < SELECTOR_TKN)
+ vty_out (vty, " %s", tt->text);
+ }
+ if (gn == start)
+ vty_out (vty, "...");
+ vty_out (vty, VTY_NEWLINE);
+ }
+ else
+ permute (gn, vty);
+ }
+ list_delete_node (position, listtail(position));
+}
+
/* Help display function for all node. */
DEFUN (config_list,
config_list_cmd,
- "list",
- "Print command list\n")
+ "list [permutations]",
+ "Print command list\n"
+ "Print all possible command permutations\n")
{
- unsigned int i;
- struct cmd_node *cnode = vector_slot (cmdvec, vty->node);
- struct cmd_element *cmd;
-
- for (i = 0; i < vector_active (cnode->cmd_vector); i++)
- if ((cmd = vector_slot (cnode->cmd_vector, i)) != NULL
- && !(cmd->attr == CMD_ATTR_DEPRECATED
- || cmd->attr == CMD_ATTR_HIDDEN))
- vty_out (vty, " %s%s", cmd->string,
- VTY_NEWLINE);
+ vty_out (vty, "Current node id: %d%s", vty->node, VTY_NEWLINE);
+ struct cmd_node *node = vector_slot (cmdvec, vty->node);
+
+ if ((strmatch (argv[0]->text, "list") && argc == 2) ||
+ (strmatch (argv[0]->text, "show") && argc == 3))
+ permute (vector_slot (node->cmdgraph->nodes, 0), vty);
+ else
+ {
+ /* loop over all commands at this node */
+ struct cmd_element *element = NULL;
+ for (unsigned int i = 0; i < vector_active(node->cmd_vector); i++)
+ if ((element = vector_slot (node->cmd_vector, i)) &&
+ element->attr != CMD_ATTR_DEPRECATED &&
+ element->attr != CMD_ATTR_HIDDEN)
+ vty_out (vty, " %s%s", element->string, VTY_NEWLINE);
+ }
return CMD_SUCCESS;
}
+DEFUN (show_commandtree,
+ show_commandtree_cmd,
+ "show commandtree [permutations]",
+ SHOW_STR
+ "Show command tree\n")
+{
+ return config_list (self, vty, argc, argv);
+}
+
/* Write current configuration into file. */
-DEFUN (config_write_file,
- config_write_file_cmd,
- "write file",
+
+DEFUN (config_write,
+ config_write_cmd,
+ "write [<file|memory|terminal>]",
"Write running configuration to memory, network, or terminal\n"
- "Write to configuration file\n")
+ "Write to configuration file\n"
+ "Write configuration currently in memory\n"
+ "Write configuration to terminal\n")
{
+ int idx_type = 1;
unsigned int i;
int fd;
struct cmd_node *node;
@@ -3146,17 +1309,48 @@ DEFUN (config_write_file,
struct vty *file_vty;
struct stat conf_stat;
+ // if command was 'write terminal', 'write memory' or 'show running-config'
+ if (argc == 2 && (!strcmp(argv[idx_type]->text, "terminal") ||
+ !strcmp(argv[idx_type]->text, "memory") ||
+ !strcmp(argv[0]->text, "show")))
+ {
+ if (vty->type == VTY_SHELL_SERV)
+ {
+ for (i = 0; i < vector_active (cmdvec); i++)
+ if ((node = vector_slot (cmdvec, i)) && node->func && node->vtysh)
+ {
+ if ((*node->func) (vty))
+ vty_out (vty, "!%s", VTY_NEWLINE);
+ }
+ }
+ else
+ {
+ vty_out (vty, "%sCurrent configuration:%s", VTY_NEWLINE,
+ VTY_NEWLINE);
+ vty_out (vty, "!%s", VTY_NEWLINE);
+
+ for (i = 0; i < vector_active (cmdvec); i++)
+ if ((node = vector_slot (cmdvec, i)) && node->func)
+ {
+ if ((*node->func) (vty))
+ vty_out (vty, "!%s", VTY_NEWLINE);
+ }
+ vty_out (vty, "end%s",VTY_NEWLINE);
+ }
+ return CMD_SUCCESS;
+ }
+
/* Check and see if we are operating under vtysh configuration */
if (host.config == NULL)
{
vty_out (vty, "Can't save to configuration file, using vtysh.%s",
- VTY_NEWLINE);
+ VTY_NEWLINE);
return CMD_WARNING;
}
/* Get filename. */
config_file = host.config;
-
+
config_file_sav =
XMALLOC (MTYPE_TMP, strlen (config_file) + strlen (CONF_BACKUP_EXT) + 1);
strcpy (config_file_sav, config_file);
@@ -3165,16 +1359,16 @@ DEFUN (config_write_file,
config_file_tmp = XMALLOC (MTYPE_TMP, strlen (config_file) + 8);
sprintf (config_file_tmp, "%s.XXXXXX", config_file);
-
+
/* Open file to configuration write. */
fd = mkstemp (config_file_tmp);
if (fd < 0)
{
vty_out (vty, "Can't open configuration file %s.%s", config_file_tmp,
- VTY_NEWLINE);
+ VTY_NEWLINE);
goto finished;
}
-
+
/* Make vty for configuration file. */
file_vty = vty_new ();
file_vty->wfd = fd;
@@ -3188,51 +1382,51 @@ DEFUN (config_write_file,
for (i = 0; i < vector_active (cmdvec); i++)
if ((node = vector_slot (cmdvec, i)) && node->func)
{
- if ((*node->func) (file_vty))
- vty_out (file_vty, "!\n");
+ if ((*node->func) (file_vty))
+ vty_out (file_vty, "!\n");
}
vty_close (file_vty);
if (stat(config_file, &conf_stat) >= 0)
{
if (unlink (config_file_sav) != 0)
- if (errno != ENOENT)
- {
- vty_out (vty, "Can't unlink backup configuration file %s.%s", config_file_sav,
- VTY_NEWLINE);
- goto finished;
- }
+ if (errno != ENOENT)
+ {
+ vty_out (vty, "Can't unlink backup configuration file %s.%s", config_file_sav,
+ VTY_NEWLINE);
+ goto finished;
+ }
if (link (config_file, config_file_sav) != 0)
- {
- vty_out (vty, "Can't backup old configuration file %s.%s", config_file_sav,
- VTY_NEWLINE);
- goto finished;
- }
+ {
+ vty_out (vty, "Can't backup old configuration file %s.%s", config_file_sav,
+ VTY_NEWLINE);
+ goto finished;
+ }
sync ();
if (unlink (config_file) != 0)
- {
- vty_out (vty, "Can't unlink configuration file %s.%s", config_file,
- VTY_NEWLINE);
- goto finished;
- }
+ {
+ vty_out (vty, "Can't unlink configuration file %s.%s", config_file,
+ VTY_NEWLINE);
+ goto finished;
+ }
}
if (link (config_file_tmp, config_file) != 0)
{
vty_out (vty, "Can't save configuration file %s.%s", config_file,
- VTY_NEWLINE);
+ VTY_NEWLINE);
goto finished;
}
sync ();
-
+
if (chmod (config_file, CONFIGFILE_MASK) != 0)
{
- vty_out (vty, "Can't chmod configuration file %s: %s (%d).%s",
- config_file, safe_strerror(errno), errno, VTY_NEWLINE);
+ vty_out (vty, "Can't chmod configuration file %s: %s (%d).%s",
+ config_file, safe_strerror(errno), errno, VTY_NEWLINE);
goto finished;
}
vty_out (vty, "Configuration saved to %s%s", config_file,
- VTY_NEWLINE);
+ VTY_NEWLINE);
ret = CMD_SUCCESS;
finished:
@@ -3242,73 +1436,34 @@ finished:
return ret;
}
-ALIAS (config_write_file,
- config_write_cmd,
- "write",
- "Write running configuration to memory, network, or terminal\n")
-
-ALIAS (config_write_file,
- config_write_memory_cmd,
- "write memory",
- "Write running configuration to memory, network, or terminal\n"
- "Write configuration to the file (same as write file)\n")
+/* ALIAS_FIXME for 'write <terminal|memory>' */
+DEFUN (show_running_config,
+ show_running_config_cmd,
+ "show running-config",
+ SHOW_STR
+ "running configuration (same as write terminal/memory)\n")
+{
+ return config_write (self, vty, argc, argv);
+}
-ALIAS (config_write_file,
- copy_runningconfig_startupconfig_cmd,
- "copy running-config startup-config",
+/* ALIAS_FIXME for 'write file' */
+DEFUN (copy_runningconf_startupconf,
+ copy_runningconf_startupconf_cmd,
+ "copy running-config startup-config",
"Copy configuration\n"
"Copy running config to... \n"
"Copy running config to startup config (same as write file)\n")
-
-/* Write current configuration into the terminal. */
-DEFUN (config_write_terminal,
- config_write_terminal_cmd,
- "write terminal",
- "Write running configuration to memory, network, or terminal\n"
- "Write to terminal\n")
{
- unsigned int i;
- struct cmd_node *node;
-
- if (vty->type == VTY_SHELL_SERV)
- {
- for (i = 0; i < vector_active (cmdvec); i++)
- if ((node = vector_slot (cmdvec, i)) && node->func && node->vtysh)
- {
- if ((*node->func) (vty))
- vty_out (vty, "!%s", VTY_NEWLINE);
- }
- }
- else
- {
- vty_out (vty, "%sCurrent configuration:%s", VTY_NEWLINE,
- VTY_NEWLINE);
- vty_out (vty, "!%s", VTY_NEWLINE);
-
- for (i = 0; i < vector_active (cmdvec); i++)
- if ((node = vector_slot (cmdvec, i)) && node->func)
- {
- if ((*node->func) (vty))
- vty_out (vty, "!%s", VTY_NEWLINE);
- }
- vty_out (vty, "end%s",VTY_NEWLINE);
- }
- return CMD_SUCCESS;
+ return config_write (self, vty, argc, argv);
}
-
-/* Write current configuration into the terminal. */
-ALIAS (config_write_terminal,
- show_running_config_cmd,
- "show running-config",
- SHOW_STR
- "running configuration\n")
+/** -- **/
/* Write startup configuration into the terminal. */
DEFUN (show_startup_config,
show_startup_config_cmd,
"show startup-config",
SHOW_STR
- "Contentes of startup configuration\n")
+ "Contents of startup configuration\n")
{
char buf[BUFSIZ];
FILE *confp;
@@ -3317,7 +1472,7 @@ DEFUN (show_startup_config,
if (confp == NULL)
{
vty_out (vty, "Can't open configuration file [%s] due to '%s'%s",
- host.config, safe_strerror(errno), VTY_NEWLINE);
+ host.config, safe_strerror(errno), VTY_NEWLINE);
return CMD_WARNING;
}
@@ -3326,7 +1481,7 @@ DEFUN (show_startup_config,
char *cp = buf;
while (*cp != '\r' && *cp != '\n' && *cp != '\0')
- cp++;
+ cp++;
*cp = '\0';
vty_out (vty, "%s%s", buf, VTY_NEWLINE);
@@ -3338,13 +1493,15 @@ DEFUN (show_startup_config,
}
/* Hostname configuration */
-DEFUN (config_hostname,
+DEFUN (config_hostname,
hostname_cmd,
"hostname WORD",
"Set system's network name\n"
"This system's network name\n")
{
- if (!isalpha((int) *argv[0]))
+ struct cmd_token *word = argv[1];
+
+ if (!isalpha((int) word->arg[0]))
{
vty_out (vty, "Please specify string starting with alphabet%s", VTY_NEWLINE);
return CMD_WARNING;
@@ -3352,12 +1509,12 @@ DEFUN (config_hostname,
if (host.name)
XFREE (MTYPE_HOST, host.name);
-
- host.name = XSTRDUP (MTYPE_HOST, argv[0]);
+
+ host.name = XSTRDUP (MTYPE_HOST, word->arg);
return CMD_SUCCESS;
}
-DEFUN (config_no_hostname,
+DEFUN (config_no_hostname,
no_hostname_cmd,
"no hostname [HOSTNAME]",
NO_STR
@@ -3371,43 +1528,30 @@ DEFUN (config_no_hostname,
}
/* VTY interface password set. */
-DEFUN (config_password, password_cmd,
- "password (8|) WORD",
+DEFUN (config_password,
+ password_cmd,
+ "password [(8-8)] WORD",
"Assign the terminal connection password\n"
"Specifies a HIDDEN password will follow\n"
- "dummy string \n"
- "The HIDDEN line password string\n")
+ "The password string\n")
{
- /* Argument check. */
- if (argc == 0)
- {
- vty_out (vty, "Please specify password.%s", VTY_NEWLINE);
- return CMD_WARNING;
- }
-
- if (argc == 2)
- {
- if (*argv[0] == '8')
- {
- if (host.password)
- XFREE (MTYPE_HOST, host.password);
- host.password = NULL;
- if (host.password_encrypt)
- XFREE (MTYPE_HOST, host.password_encrypt);
- host.password_encrypt = XSTRDUP (MTYPE_HOST, argv[1]);
- return CMD_SUCCESS;
- }
- else
- {
- vty_out (vty, "Unknown encryption type.%s", VTY_NEWLINE);
- return CMD_WARNING;
- }
- }
+ int idx_8 = 1;
+ int idx_word = 2;
+ if (argc == 3) // '8' was specified
+ {
+ if (host.password)
+ XFREE (MTYPE_HOST, host.password);
+ host.password = NULL;
+ if (host.password_encrypt)
+ XFREE (MTYPE_HOST, host.password_encrypt);
+ host.password_encrypt = XSTRDUP (MTYPE_HOST, argv[idx_word]->arg);
+ return CMD_SUCCESS;
+ }
- if (!isalnum ((int) *argv[0]))
+ if (!isalnum (argv[idx_8]->arg[0]))
{
- vty_out (vty,
- "Please specify string starting with alphanumeric%s", VTY_NEWLINE);
+ vty_out (vty,
+ "Please specify string starting with alphanumeric%s", VTY_NEWLINE);
return CMD_WARNING;
}
@@ -3418,62 +1562,54 @@ DEFUN (config_password, password_cmd,
if (host.encrypt)
{
if (host.password_encrypt)
- XFREE (MTYPE_HOST, host.password_encrypt);
- host.password_encrypt = XSTRDUP (MTYPE_HOST, zencrypt (argv[0]));
+ XFREE (MTYPE_HOST, host.password_encrypt);
+ host.password_encrypt = XSTRDUP (MTYPE_HOST, zencrypt (argv[idx_8]->arg));
}
else
- host.password = XSTRDUP (MTYPE_HOST, argv[0]);
+ host.password = XSTRDUP (MTYPE_HOST, argv[idx_8]->arg);
return CMD_SUCCESS;
}
-ALIAS (config_password, password_text_cmd,
- "password LINE",
- "Assign the terminal connection password\n"
- "The UNENCRYPTED (cleartext) line password\n")
-
/* VTY enable password set. */
-DEFUN (config_enable_password, enable_password_cmd,
- "enable password (8|) WORD",
+DEFUN (config_enable_password,
+ enable_password_cmd,
+ "enable password [(8-8)] WORD",
"Modify enable password parameters\n"
"Assign the privileged level password\n"
"Specifies a HIDDEN password will follow\n"
"dummy string \n"
"The HIDDEN 'enable' password string\n")
{
- /* Argument check. */
- if (argc == 0)
- {
- vty_out (vty, "Please specify password.%s", VTY_NEWLINE);
- return CMD_WARNING;
- }
+ int idx_8 = 2;
+ int idx_word = 3;
/* Crypt type is specified. */
- if (argc == 2)
+ if (argc == 4)
{
- if (*argv[0] == '8')
- {
- if (host.enable)
- XFREE (MTYPE_HOST, host.enable);
- host.enable = NULL;
-
- if (host.enable_encrypt)
- XFREE (MTYPE_HOST, host.enable_encrypt);
- host.enable_encrypt = XSTRDUP (MTYPE_HOST, argv[1]);
-
- return CMD_SUCCESS;
- }
+ if (argv[idx_8]->arg[0] == '8')
+ {
+ if (host.enable)
+ XFREE (MTYPE_HOST, host.enable);
+ host.enable = NULL;
+
+ if (host.enable_encrypt)
+ XFREE (MTYPE_HOST, host.enable_encrypt);
+ host.enable_encrypt = XSTRDUP (MTYPE_HOST, argv[idx_word]->arg);
+
+ return CMD_SUCCESS;
+ }
else
- {
- vty_out (vty, "Unknown encryption type.%s", VTY_NEWLINE);
- return CMD_WARNING;
- }
+ {
+ vty_out (vty, "Unknown encryption type.%s", VTY_NEWLINE);
+ return CMD_WARNING;
+ }
}
- if (!isalnum ((int) *argv[0]))
+ if (!isalnum (argv[idx_8]->arg[0]))
{
- vty_out (vty,
- "Please specify string starting with alphanumeric%s", VTY_NEWLINE);
+ vty_out (vty,
+ "Please specify string starting with alphanumeric%s", VTY_NEWLINE);
return CMD_WARNING;
}
@@ -3485,24 +1621,18 @@ DEFUN (config_enable_password, enable_password_cmd,
if (host.encrypt)
{
if (host.enable_encrypt)
- XFREE (MTYPE_HOST, host.enable_encrypt);
- host.enable_encrypt = XSTRDUP (MTYPE_HOST, zencrypt (argv[0]));
+ XFREE (MTYPE_HOST, host.enable_encrypt);
+ host.enable_encrypt = XSTRDUP (MTYPE_HOST, zencrypt (argv[idx_8]->arg));
}
else
- host.enable = XSTRDUP (MTYPE_HOST, argv[0]);
+ host.enable = XSTRDUP (MTYPE_HOST, argv[idx_8]->arg);
return CMD_SUCCESS;
}
-ALIAS (config_enable_password,
- enable_password_text_cmd,
- "enable password LINE",
- "Modify enable password parameters\n"
- "Assign the privileged level password\n"
- "The UNENCRYPTED (cleartext) 'enable' password\n")
-
/* VTY enable password delete. */
-DEFUN (no_config_enable_password, no_enable_password_cmd,
+DEFUN (no_config_enable_password,
+ no_enable_password_cmd,
"no enable password",
NO_STR
"Modify enable password parameters\n"
@@ -3518,7 +1648,7 @@ DEFUN (no_config_enable_password, no_enable_password_cmd,
return CMD_SUCCESS;
}
-
+
DEFUN (service_password_encrypt,
service_password_encrypt_cmd,
"service password-encryption",
@@ -3533,13 +1663,13 @@ DEFUN (service_password_encrypt,
if (host.password)
{
if (host.password_encrypt)
- XFREE (MTYPE_HOST, host.password_encrypt);
+ XFREE (MTYPE_HOST, host.password_encrypt);
host.password_encrypt = XSTRDUP (MTYPE_HOST, zencrypt (host.password));
}
if (host.enable)
{
if (host.enable_encrypt)
- XFREE (MTYPE_HOST, host.enable_encrypt);
+ XFREE (MTYPE_HOST, host.enable_encrypt);
host.enable_encrypt = XSTRDUP (MTYPE_HOST, zencrypt (host.enable));
}
@@ -3569,16 +1699,18 @@ DEFUN (no_service_password_encrypt,
return CMD_SUCCESS;
}
-DEFUN (config_terminal_length, config_terminal_length_cmd,
- "terminal length <0-512>",
+DEFUN (config_terminal_length,
+ config_terminal_length_cmd,
+ "terminal length (0-512)",
"Set terminal line parameters\n"
"Set number of lines on a screen\n"
"Number of lines on screen (0 for no pausing)\n")
{
+ int idx_number = 2;
int lines;
char *endptr = NULL;
- lines = strtol (argv[0], &endptr, 10);
+ lines = strtol (argv[idx_number]->arg, &endptr, 10);
if (lines < 0 || lines > 512 || *endptr != '\0')
{
vty_out (vty, "length is malformed%s", VTY_NEWLINE);
@@ -3589,7 +1721,8 @@ DEFUN (config_terminal_length, config_terminal_length_cmd,
return CMD_SUCCESS;
}
-DEFUN (config_terminal_no_length, config_terminal_no_length_cmd,
+DEFUN (config_terminal_no_length,
+ config_terminal_no_length_cmd,
"terminal no length",
"Set terminal line parameters\n"
NO_STR
@@ -3599,16 +1732,18 @@ DEFUN (config_terminal_no_length, config_terminal_no_length_cmd,
return CMD_SUCCESS;
}
-DEFUN (service_terminal_length, service_terminal_length_cmd,
- "service terminal-length <0-512>",
+DEFUN (service_terminal_length,
+ service_terminal_length_cmd,
+ "service terminal-length (0-512)",
"Set up miscellaneous service\n"
"System wide terminal length configuration\n"
"Number of lines of VTY (0 means no line control)\n")
{
+ int idx_number = 2;
int lines;
char *endptr = NULL;
- lines = strtol (argv[0], &endptr, 10);
+ lines = strtol (argv[idx_number]->arg, &endptr, 10);
if (lines < 0 || lines > 512 || *endptr != '\0')
{
vty_out (vty, "length is malformed%s", VTY_NEWLINE);
@@ -3619,8 +1754,9 @@ DEFUN (service_terminal_length, service_terminal_length_cmd,
return CMD_SUCCESS;
}
-DEFUN (no_service_terminal_length, no_service_terminal_length_cmd,
- "no service terminal-length [<0-512>]",
+DEFUN (no_service_terminal_length,
+ no_service_terminal_length_cmd,
+ "no service terminal-length [(0-512)]",
NO_STR
"Set up miscellaneous service\n"
"System wide terminal length configuration\n"
@@ -3631,15 +1767,15 @@ DEFUN (no_service_terminal_length, no_service_terminal_length_cmd,
}
DEFUN_HIDDEN (do_echo,
- echo_cmd,
- "echo .MESSAGE",
- "Echo a message back to the vty\n"
- "The message to echo\n")
+ echo_cmd,
+ "echo MESSAGE...",
+ "Echo a message back to the vty\n"
+ "The message to echo\n")
{
char *message;
- vty_out (vty, "%s%s", ((message = argv_concat(argv, argc, 0)) ? message : ""),
- VTY_NEWLINE);
+ vty_out (vty, "%s%s", ((message = argv_concat (argv, argc, 1)) ? message : ""),
+ VTY_NEWLINE);
if (message)
XFREE(MTYPE_TMP, message);
return CMD_SUCCESS;
@@ -3647,18 +1783,20 @@ DEFUN_HIDDEN (do_echo,
DEFUN (config_logmsg,
config_logmsg_cmd,
- "logmsg "LOG_LEVELS" .MESSAGE",
+ "logmsg <emergencies|alerts|critical|errors|warnings|notifications|informational|debugging> MESSAGE...",
"Send a message to enabled logging destinations\n"
LOG_LEVEL_DESC
"The message to send\n")
{
+ int idx_log_level = 1;
+ int idx_message = 2;
int level;
char *message;
- if ((level = level_match(argv[0])) == ZLOG_DISABLED)
+ if ((level = level_match(argv[idx_log_level]->arg)) == ZLOG_DISABLED)
return CMD_ERR_NO_MATCH;
- zlog(NULL, level, "%s", ((message = argv_concat(argv, argc, 1)) ? message : ""));
+ zlog(NULL, level, "%s", ((message = argv_concat(argv, argc, idx_message)) ? message : ""));
if (message)
XFREE(MTYPE_TMP, message);
@@ -3678,8 +1816,8 @@ DEFUN (show_logging,
vty_out (vty, "disabled");
else
vty_out (vty, "level %s, facility %s, ident %s",
- zlog_priority[zl->maxlvl[ZLOG_DEST_SYSLOG]],
- facility_name(zl->facility), zl->ident);
+ zlog_priority[zl->maxlvl[ZLOG_DEST_SYSLOG]],
+ facility_name(zl->facility), zl->ident);
vty_out (vty, "%s", VTY_NEWLINE);
vty_out (vty, "Stdout logging: ");
@@ -3687,7 +1825,7 @@ DEFUN (show_logging,
vty_out (vty, "disabled");
else
vty_out (vty, "level %s",
- zlog_priority[zl->maxlvl[ZLOG_DEST_STDOUT]]);
+ zlog_priority[zl->maxlvl[ZLOG_DEST_STDOUT]]);
vty_out (vty, "%s", VTY_NEWLINE);
vty_out (vty, "Monitor logging: ");
@@ -3695,7 +1833,7 @@ DEFUN (show_logging,
vty_out (vty, "disabled");
else
vty_out (vty, "level %s",
- zlog_priority[zl->maxlvl[ZLOG_DEST_MONITOR]]);
+ zlog_priority[zl->maxlvl[ZLOG_DEST_MONITOR]]);
vty_out (vty, "%s", VTY_NEWLINE);
vty_out (vty, "File logging: ");
@@ -3704,40 +1842,37 @@ DEFUN (show_logging,
vty_out (vty, "disabled");
else
vty_out (vty, "level %s, filename %s",
- zlog_priority[zl->maxlvl[ZLOG_DEST_FILE]],
- zl->filename);
+ zlog_priority[zl->maxlvl[ZLOG_DEST_FILE]],
+ zl->filename);
vty_out (vty, "%s", VTY_NEWLINE);
vty_out (vty, "Protocol name: %s%s",
- zlog_proto_names[zl->protocol], VTY_NEWLINE);
+ zlog_proto_names[zl->protocol], VTY_NEWLINE);
vty_out (vty, "Record priority: %s%s",
- (zl->record_priority ? "enabled" : "disabled"), VTY_NEWLINE);
+ (zl->record_priority ? "enabled" : "disabled"), VTY_NEWLINE);
vty_out (vty, "Timestamp precision: %d%s",
- zl->timestamp_precision, VTY_NEWLINE);
+ zl->timestamp_precision, VTY_NEWLINE);
return CMD_SUCCESS;
}
DEFUN (config_log_stdout,
config_log_stdout_cmd,
- "log stdout",
- "Logging control\n"
- "Set stdout logging level\n")
-{
- zlog_set_level (NULL, ZLOG_DEST_STDOUT, zlog_default->default_lvl);
- return CMD_SUCCESS;
-}
-
-DEFUN (config_log_stdout_level,
- config_log_stdout_level_cmd,
- "log stdout "LOG_LEVELS,
+ "log stdout [<emergencies|alerts|critical|errors|warnings|notifications|informational|debugging>]",
"Logging control\n"
"Set stdout logging level\n"
LOG_LEVEL_DESC)
{
+ int idx_log_level = 2;
+
+ if (argc == idx_log_level)
+ {
+ zlog_set_level (NULL, ZLOG_DEST_STDOUT, zlog_default->default_lvl);
+ return CMD_SUCCESS;
+ }
int level;
- if ((level = level_match(argv[0])) == ZLOG_DISABLED)
+ if ((level = level_match(argv[idx_log_level]->arg)) == ZLOG_DISABLED)
return CMD_ERR_NO_MATCH;
zlog_set_level (NULL, ZLOG_DEST_STDOUT, level);
return CMD_SUCCESS;
@@ -3745,11 +1880,11 @@ DEFUN (config_log_stdout_level,
DEFUN (no_config_log_stdout,
no_config_log_stdout_cmd,
- "no log stdout [LEVEL]",
+ "no log stdout [<emergencies|alerts|critical|errors|warnings|notifications|informational|debugging>]",
NO_STR
"Logging control\n"
"Cancel logging to stdout\n"
- "Logging level\n")
+ LOG_LEVEL_DESC)
{
zlog_set_level (NULL, ZLOG_DEST_STDOUT, ZLOG_DISABLED);
return CMD_SUCCESS;
@@ -3757,24 +1892,21 @@ DEFUN (no_config_log_stdout,
DEFUN (config_log_monitor,
config_log_monitor_cmd,
- "log monitor",
- "Logging control\n"
- "Set terminal line (monitor) logging level\n")
-{
- zlog_set_level (NULL, ZLOG_DEST_MONITOR, zlog_default->default_lvl);
- return CMD_SUCCESS;
-}
-
-DEFUN (config_log_monitor_level,
- config_log_monitor_level_cmd,
- "log monitor "LOG_LEVELS,
+ "log monitor [<emergencies|alerts|critical|errors|warnings|notifications|informational|debugging>]",
"Logging control\n"
"Set terminal line (monitor) logging level\n"
LOG_LEVEL_DESC)
{
+ int idx_log_level = 2;
+
+ if (argc == idx_log_level)
+ {
+ zlog_set_level (NULL, ZLOG_DEST_MONITOR, zlog_default->default_lvl);
+ return CMD_SUCCESS;
+ }
int level;
- if ((level = level_match(argv[0])) == ZLOG_DISABLED)
+ if ((level = level_match(argv[idx_log_level]->arg)) == ZLOG_DISABLED)
return CMD_ERR_NO_MATCH;
zlog_set_level (NULL, ZLOG_DEST_MONITOR, level);
return CMD_SUCCESS;
@@ -3782,11 +1914,11 @@ DEFUN (config_log_monitor_level,
DEFUN (no_config_log_monitor,
no_config_log_monitor_cmd,
- "no log monitor [LEVEL]",
+ "no log monitor [<emergencies|alerts|critical|errors|warnings|notifications|informational|debugging>]",
NO_STR
"Logging control\n"
"Disable terminal line (monitor) logging\n"
- "Logging level\n")
+ LOG_LEVEL_DESC)
{
zlog_set_level (NULL, ZLOG_DEST_MONITOR, ZLOG_DISABLED);
return CMD_SUCCESS;
@@ -3798,19 +1930,19 @@ set_log_file(struct vty *vty, const char *fname, int loglevel)
int ret;
char *p = NULL;
const char *fullpath;
-
+
/* Path detection. */
if (! IS_DIRECTORY_SEP (*fname))
{
char cwd[MAXPATHLEN+1];
cwd[MAXPATHLEN] = '\0';
-
+
if (getcwd (cwd, MAXPATHLEN) == NULL)
{
zlog_err ("config_log_file: Unable to alloc mem!");
return CMD_WARNING;
}
-
+
if ( (p = XMALLOC (MTYPE_TMP, strlen (cwd) + strlen (fname) + 2))
== NULL)
{
@@ -3848,36 +1980,34 @@ set_log_file(struct vty *vty, const char *fname, int loglevel)
DEFUN (config_log_file,
config_log_file_cmd,
- "log file FILENAME",
- "Logging control\n"
- "Logging to file\n"
- "Logging filename\n")
-{
- return set_log_file(vty, argv[0], zlog_default->default_lvl);
-}
-
-DEFUN (config_log_file_level,
- config_log_file_level_cmd,
- "log file FILENAME "LOG_LEVELS,
+ "log file FILENAME [<emergencies|alerts|critical|errors|warnings|notifications|informational|debugging>]",
"Logging control\n"
"Logging to file\n"
"Logging filename\n"
LOG_LEVEL_DESC)
{
- int level;
-
- if ((level = level_match(argv[1])) == ZLOG_DISABLED)
- return CMD_ERR_NO_MATCH;
- return set_log_file(vty, argv[0], level);
+ int idx_filename = 2;
+ int idx_log_levels = 3;
+ if (argc == 4)
+ {
+ int level;
+ if ((level = level_match(argv[idx_log_levels]->arg)) == ZLOG_DISABLED)
+ return CMD_ERR_NO_MATCH;
+ return set_log_file(vty, argv[idx_filename]->arg, level);
+ }
+ else
+ return set_log_file(vty, argv[idx_filename]->arg, zlog_default->default_lvl);
}
DEFUN (no_config_log_file,
no_config_log_file_cmd,
- "no log file [FILENAME]",
+ "no log file [FILENAME [LEVEL]]",
NO_STR
"Logging control\n"
"Cancel logging to file\n"
- "Logging file name\n")
+ "Logging file name\n"
+ "Logging file name\n"
+ "Logging level\n")
{
zlog_reset_file (NULL);
@@ -3889,52 +2019,38 @@ DEFUN (no_config_log_file,
return CMD_SUCCESS;
}
-ALIAS (no_config_log_file,
- no_config_log_file_level_cmd,
- "no log file FILENAME LEVEL",
- NO_STR
- "Logging control\n"
- "Cancel logging to file\n"
- "Logging file name\n"
- "Logging level\n")
-
DEFUN (config_log_syslog,
config_log_syslog_cmd,
- "log syslog",
- "Logging control\n"
- "Set syslog logging level\n")
-{
- zlog_set_level (NULL, ZLOG_DEST_SYSLOG, zlog_default->default_lvl);
- return CMD_SUCCESS;
-}
-
-DEFUN (config_log_syslog_level,
- config_log_syslog_level_cmd,
- "log syslog "LOG_LEVELS,
+ "log syslog [<emergencies|alerts|critical|errors|warnings|notifications|informational|debugging>]",
"Logging control\n"
"Set syslog logging level\n"
LOG_LEVEL_DESC)
{
- int level;
-
- if ((level = level_match(argv[0])) == ZLOG_DISABLED)
- return CMD_ERR_NO_MATCH;
- zlog_set_level (NULL, ZLOG_DEST_SYSLOG, level);
- return CMD_SUCCESS;
+ int idx_log_levels = 2;
+ if (argc == 3)
+ {
+ int level;
+ if ((level = level_match (argv[idx_log_levels]->arg)) == ZLOG_DISABLED)
+ return CMD_ERR_NO_MATCH;
+ zlog_set_level (NULL, ZLOG_DEST_SYSLOG, level);
+ return CMD_SUCCESS;
+ }
+ else
+ {
+ zlog_set_level (NULL, ZLOG_DEST_SYSLOG, zlog_default->default_lvl);
+ return CMD_SUCCESS;
+ }
}
DEFUN_DEPRECATED (config_log_syslog_facility,
- config_log_syslog_facility_cmd,
- "log syslog facility "LOG_FACILITIES,
- "Logging control\n"
- "Logging goes to syslog\n"
- "(Deprecated) Facility parameter for syslog messages\n"
- LOG_FACILITY_DESC)
+ config_log_syslog_facility_cmd,
+ "log syslog facility (kern|user|mail|daemon|auth|syslog|lpr|news|uucp|cron|local0|local1|local2|local3|local4|local5|local6|local7)",
+ "Logging control\n"
+ "Logging goes to syslog\n"
+ "(Deprecated) Facility parameter for syslog messages\n"
+ LOG_FACILITY_DESC)
{
- int facility;
-
- if ((facility = facility_match(argv[0])) < 0)
- return CMD_ERR_NO_MATCH;
+ int facility = facility_match(argv[3]->arg);
zlog_set_level (NULL, ZLOG_DEST_SYSLOG, zlog_default->default_lvl);
zlog_default->facility = facility;
@@ -3943,63 +2059,54 @@ DEFUN_DEPRECATED (config_log_syslog_facility,
DEFUN (no_config_log_syslog,
no_config_log_syslog_cmd,
- "no log syslog [LEVEL]",
+ "no log syslog [<kern|user|mail|daemon|auth|syslog|lpr|news|uucp|cron|local0|local1|local2|local3|local4|local5|local6|local7>] [<emergencies|alerts|critical|errors|warnings|notifications|informational|debugging>]",
NO_STR
"Logging control\n"
"Cancel logging to syslog\n"
- "Logging level\n")
+ LOG_FACILITY_DESC
+ LOG_LEVEL_DESC)
{
zlog_set_level (NULL, ZLOG_DEST_SYSLOG, ZLOG_DISABLED);
return CMD_SUCCESS;
}
-ALIAS (no_config_log_syslog,
- no_config_log_syslog_facility_cmd,
- "no log syslog facility "LOG_FACILITIES,
- NO_STR
- "Logging control\n"
- "Logging goes to syslog\n"
- "Facility parameter for syslog messages\n"
- LOG_FACILITY_DESC)
-
DEFUN (config_log_facility,
config_log_facility_cmd,
- "log facility "LOG_FACILITIES,
+ "log facility <kern|user|mail|daemon|auth|syslog|lpr|news|uucp|cron|local0|local1|local2|local3|local4|local5|local6|local7>",
"Logging control\n"
"Facility parameter for syslog messages\n"
LOG_FACILITY_DESC)
{
- int facility;
+ int idx_target = 2;
+ int facility = facility_match(argv[idx_target]->arg);
- if ((facility = facility_match(argv[0])) < 0)
- return CMD_ERR_NO_MATCH;
zlog_default->facility = facility;
return CMD_SUCCESS;
}
DEFUN (no_config_log_facility,
no_config_log_facility_cmd,
- "no log facility [FACILITY]",
+ "no log facility [<kern|user|mail|daemon|auth|syslog|lpr|news|uucp|cron|local0|local1|local2|local3|local4|local5|local6|local7>]",
NO_STR
"Logging control\n"
"Reset syslog facility to default (daemon)\n"
- "Syslog facility\n")
+ LOG_FACILITY_DESC)
{
zlog_default->facility = LOG_DAEMON;
return CMD_SUCCESS;
}
DEFUN_DEPRECATED (config_log_trap,
- config_log_trap_cmd,
- "log trap "LOG_LEVELS,
- "Logging control\n"
- "(Deprecated) Set logging level and default for all destinations\n"
- LOG_LEVEL_DESC)
+ config_log_trap_cmd,
+ "log trap <emergencies|alerts|critical|errors|warnings|notifications|informational|debugging>",
+ "Logging control\n"
+ "(Deprecated) Set logging level and default for all destinations\n"
+ LOG_LEVEL_DESC)
{
int new_level ;
int i;
-
- if ((new_level = level_match(argv[0])) == ZLOG_DISABLED)
+
+ if ((new_level = level_match(argv[2]->arg)) == ZLOG_DISABLED)
return CMD_ERR_NO_MATCH;
zlog_default->default_lvl = new_level;
@@ -4010,12 +2117,12 @@ DEFUN_DEPRECATED (config_log_trap,
}
DEFUN_DEPRECATED (no_config_log_trap,
- no_config_log_trap_cmd,
- "no log trap [LEVEL]",
- NO_STR
- "Logging control\n"
- "Permit all logging information\n"
- "Logging level\n")
+ no_config_log_trap_cmd,
+ "no log trap [emergencies|alerts|critical|errors|warnings|notifications|informational|debugging]",
+ NO_STR
+ "Logging control\n"
+ "Permit all logging information\n"
+ LOG_LEVEL_DESC)
{
zlog_default->default_lvl = LOG_DEBUG;
return CMD_SUCCESS;
@@ -4044,20 +2151,15 @@ DEFUN (no_config_log_record_priority,
DEFUN (config_log_timestamp_precision,
config_log_timestamp_precision_cmd,
- "log timestamp precision <0-6>",
+ "log timestamp precision (0-6)",
"Logging control\n"
"Timestamp configuration\n"
"Set the timestamp precision\n"
"Number of subsecond digits\n")
{
- if (argc != 1)
- {
- vty_out (vty, "Insufficient arguments%s", VTY_NEWLINE);
- return CMD_WARNING;
- }
-
+ int idx_number = 3;
VTY_GET_INTEGER_RANGE("Timestamp Precision",
- zlog_default->timestamp_precision, argv[0], 0, 6);
+ zlog_default->timestamp_precision, argv[idx_number]->arg, 0, 6);
return CMD_SUCCESS;
}
@@ -4088,7 +2190,7 @@ cmd_banner_motd_file (const char *file)
if (in == rpath)
{
if (host.motdfile)
- XFREE (MTYPE_HOST, host.motdfile);
+ XFREE (MTYPE_HOST, host.motdfile);
host.motdfile = XSTRDUP (MTYPE_HOST, file);
}
else
@@ -4105,13 +2207,14 @@ DEFUN (banner_motd_file,
"Banner from a file\n"
"Filename\n")
{
- int cmd = cmd_banner_motd_file (argv[0]);
+ int idx_file = 3;
+ const char *filename = argv[idx_file]->arg;
+ int cmd = cmd_banner_motd_file (filename);
if (cmd == CMD_ERR_NO_FILE)
- vty_out (vty, "%s does not exist", argv[0]);
+ vty_out (vty, "%s does not exist", filename);
else if (cmd == CMD_WARNING)
- vty_out (vty, "%s must be in %s",
- argv[0], SYSCONFDIR);
+ vty_out (vty, "%s must be in %s", filename, SYSCONFDIR);
return cmd;
}
@@ -4135,43 +2238,12 @@ DEFUN (no_banner_motd,
"Strings for motd\n")
{
host.motd = NULL;
- if (host.motdfile)
+ if (host.motdfile)
XFREE (MTYPE_HOST, host.motdfile);
host.motdfile = NULL;
return CMD_SUCCESS;
}
-DEFUN (show_commandtree,
- show_commandtree_cmd,
- "show commandtree",
- NO_STR
- "Show command tree\n")
-{
- /* TBD */
- vector cmd_vector;
- unsigned int i;
-
- vty_out (vty, "Current node id: %d%s", vty->node, VTY_NEWLINE);
-
- /* vector of all commands installed at this node */
- cmd_vector = vector_copy (cmd_node_vector (cmdvec, vty->node));
-
- /* loop over all commands at this node */
- for (i = 0; i < vector_active(cmd_vector); ++i)
- {
- struct cmd_element *cmd_element;
-
- /* A cmd_element (seems to be) is an individual command */
- if ((cmd_element = vector_slot (cmd_vector, i)) == NULL)
- continue;
-
- vty_out (vty, " %s%s", cmd_element->string, VTY_NEWLINE);
- }
-
- vector_free (cmd_vector);
- return CMD_SUCCESS;
-}
-
/* Set config filename. Called from vty.c */
void
host_config_set (const char *filename)
@@ -4196,9 +2268,6 @@ install_default (enum node_type node)
install_element (node, &config_help_cmd);
install_element (node, &config_list_cmd);
- install_element (node, &config_write_terminal_cmd);
- install_element (node, &config_write_file_cmd);
- install_element (node, &config_write_memory_cmd);
install_element (node, &config_write_cmd);
install_element (node, &show_running_config_cmd);
}
@@ -4209,12 +2278,6 @@ cmd_init (int terminal)
{
qobj_init ();
- command_cr = XSTRDUP(MTYPE_CMD_TOKENS, "<cr>");
- token_cr.type = TOKEN_TERMINAL;
- token_cr.terminal = TERMINAL_LITERAL;
- token_cr.cmd = command_cr;
- token_cr.desc = XSTRDUP(MTYPE_CMD_TOKENS, "");
-
/* Allocate initial top vector of commands. */
cmdvec = vector_init (VECTOR_MIN_SIZE);
@@ -4256,10 +2319,7 @@ cmd_init (int terminal)
install_element (ENABLE_NODE, &config_end_cmd);
install_element (ENABLE_NODE, &config_disable_cmd);
install_element (ENABLE_NODE, &config_terminal_cmd);
- install_element (ENABLE_NODE, &copy_runningconfig_startupconfig_cmd);
- install_element (ENABLE_NODE, &config_write_terminal_cmd);
- install_element (ENABLE_NODE, &config_write_file_cmd);
- install_element (ENABLE_NODE, &config_write_memory_cmd);
+ install_element (ENABLE_NODE, &copy_runningconf_startupconf_cmd);
install_element (ENABLE_NODE, &config_write_cmd);
install_element (ENABLE_NODE, &show_running_config_cmd);
}
@@ -4270,33 +2330,24 @@ cmd_init (int terminal)
install_element (ENABLE_NODE, &config_logmsg_cmd);
install_default (CONFIG_NODE);
}
-
+
install_element (CONFIG_NODE, &hostname_cmd);
install_element (CONFIG_NODE, &no_hostname_cmd);
if (terminal)
{
install_element (CONFIG_NODE, &password_cmd);
- install_element (CONFIG_NODE, &password_text_cmd);
install_element (CONFIG_NODE, &enable_password_cmd);
- install_element (CONFIG_NODE, &enable_password_text_cmd);
install_element (CONFIG_NODE, &no_enable_password_cmd);
install_element (CONFIG_NODE, &config_log_stdout_cmd);
- install_element (CONFIG_NODE, &config_log_stdout_level_cmd);
install_element (CONFIG_NODE, &no_config_log_stdout_cmd);
install_element (CONFIG_NODE, &config_log_monitor_cmd);
- install_element (CONFIG_NODE, &config_log_monitor_level_cmd);
install_element (CONFIG_NODE, &no_config_log_monitor_cmd);
install_element (CONFIG_NODE, &config_log_file_cmd);
- install_element (CONFIG_NODE, &config_log_file_level_cmd);
install_element (CONFIG_NODE, &no_config_log_file_cmd);
- install_element (CONFIG_NODE, &no_config_log_file_level_cmd);
install_element (CONFIG_NODE, &config_log_syslog_cmd);
- install_element (CONFIG_NODE, &config_log_syslog_level_cmd);
- install_element (CONFIG_NODE, &config_log_syslog_facility_cmd);
install_element (CONFIG_NODE, &no_config_log_syslog_cmd);
- install_element (CONFIG_NODE, &no_config_log_syslog_facility_cmd);
install_element (CONFIG_NODE, &config_log_facility_cmd);
install_element (CONFIG_NODE, &no_config_log_facility_cmd);
install_element (CONFIG_NODE, &config_log_trap_cmd);
@@ -4314,7 +2365,7 @@ cmd_init (int terminal)
install_element (CONFIG_NODE, &no_service_terminal_length_cmd);
install_element (VIEW_NODE, &show_thread_cpu_cmd);
-
+
install_element (ENABLE_NODE, &clear_thread_cpu_cmd);
install_element (VIEW_NODE, &show_work_queues_cmd);
@@ -4323,87 +2374,89 @@ cmd_init (int terminal)
srandom(time(NULL));
}
-static void
-cmd_terminate_token(struct cmd_token *token)
+struct cmd_token *
+new_cmd_token (enum cmd_token_type type, char *text, char *desc)
{
- unsigned int i, j;
- vector keyword_vect;
+ struct cmd_token *token = XMALLOC (MTYPE_CMD_TOKENS, sizeof (struct cmd_token));
+ token->type = type;
+ token->text = text;
+ token->desc = desc;
+ token->arg = NULL;
- if (token->multiple)
- {
- for (i = 0; i < vector_active(token->multiple); i++)
- cmd_terminate_token(vector_slot(token->multiple, i));
- vector_free(token->multiple);
- token->multiple = NULL;
- }
+ return token;
+}
- if (token->keyword)
- {
- for (i = 0; i < vector_active(token->keyword); i++)
- {
- keyword_vect = vector_slot(token->keyword, i);
- for (j = 0; j < vector_active(keyword_vect); j++)
- cmd_terminate_token(vector_slot(keyword_vect, j));
- vector_free(keyword_vect);
- }
- vector_free(token->keyword);
- token->keyword = NULL;
- }
+void
+del_cmd_token (struct cmd_token *token)
+{
+ if (!token) return;
- XFREE(MTYPE_CMD_TOKENS, token->cmd);
- XFREE(MTYPE_CMD_TOKENS, token->desc);
+ if (token->text)
+ free (token->text);
+ if (token->desc)
+ free (token->desc);
+ if (token->arg)
+ free (token->arg);
- XFREE(MTYPE_CMD_TOKENS, token);
+ free (token);
}
-static void
-cmd_terminate_element(struct cmd_element *cmd)
+struct cmd_token *
+copy_cmd_token (struct cmd_token *token)
{
- unsigned int i;
+ struct cmd_token *copy = new_cmd_token (token->type, NULL, NULL);
+ copy->max = token->max;
+ copy->min = token->min;
+ copy->text = token->text ? XSTRDUP (MTYPE_CMD_TOKENS, token->text) : NULL;
+ copy->desc = token->desc ? XSTRDUP (MTYPE_CMD_TOKENS, token->desc) : NULL;
+ copy->arg = token->arg ? XSTRDUP (MTYPE_CMD_TOKENS, token->arg) : NULL;
- if (cmd->tokens == NULL)
- return;
+ return copy;
+}
- for (i = 0; i < vector_active(cmd->tokens); i++)
- cmd_terminate_token(vector_slot(cmd->tokens, i));
+void
+del_cmd_element(struct cmd_element *cmd)
+{
+ if (!cmd) return;
+ free ((char *) cmd->string);
+ free ((char *) cmd->doc);
+ free (cmd);
+}
- vector_free(cmd->tokens);
- cmd->tokens = NULL;
+struct cmd_element *
+copy_cmd_element(struct cmd_element *cmd)
+{
+ struct cmd_element *el = XMALLOC(MTYPE_CMD_TOKENS, sizeof (struct cmd_element));
+ el->string = cmd->string ? XSTRDUP(MTYPE_CMD_TOKENS, cmd->string) : NULL;
+ el->func = cmd->func;
+ el->doc = cmd->doc ? XSTRDUP(MTYPE_CMD_TOKENS, cmd->doc) : NULL;
+ el->daemon = cmd->daemon;
+ el->attr = cmd->attr;
+ return el;
}
void
cmd_terminate ()
{
- unsigned int i, j;
struct cmd_node *cmd_node;
- struct cmd_element *cmd_element;
- vector cmd_node_v;
if (cmdvec)
{
- for (i = 0; i < vector_active (cmdvec); i++)
+ for (unsigned int i = 0; i < vector_active (cmdvec); i++)
if ((cmd_node = vector_slot (cmdvec, i)) != NULL)
- {
- cmd_node_v = cmd_node->cmd_vector;
-
- for (j = 0; j < vector_active (cmd_node_v); j++)
- if ((cmd_element = vector_slot (cmd_node_v, j)) != NULL)
- cmd_terminate_element(cmd_element);
-
- vector_free (cmd_node_v);
- hash_clean (cmd_node->cmd_hash, NULL);
- hash_free (cmd_node->cmd_hash);
- cmd_node->cmd_hash = NULL;
- }
+ {
+ // deleting the graph delets the cmd_element as well
+ graph_delete_graph (cmd_node->cmdgraph);
+ vector_free (cmd_node->cmd_vector);
+ hash_clean (cmd_node->cmd_hash, NULL);
+ hash_free (cmd_node->cmd_hash);
+ cmd_node->cmd_hash = NULL;
+ }
vector_free (cmdvec);
cmdvec = NULL;
}
- if (command_cr)
- XFREE(MTYPE_CMD_TOKENS, command_cr);
- if (token_cr.desc)
- XFREE(MTYPE_CMD_TOKENS, token_cr.desc);
if (host.name)
XFREE (MTYPE_HOST, host.name);
if (host.password)
diff --git a/lib/command.h b/lib/command.h
index e4aa10196f..4d60c5b4fe 100644
--- a/lib/command.h
+++ b/lib/command.h
@@ -8,7 +8,7 @@
* it under the terms of the GNU General Public License as published
* by the Free Software Foundation; either version 2, or (at your
* option) any later version.
- *
+ *
* GNU Zebra is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
@@ -26,6 +26,7 @@
#include "vector.h"
#include "vty.h"
#include "lib/route_types.h"
+#include "graph.h"
#include "memory.h"
#include "hash.h"
@@ -67,42 +68,42 @@ struct host
};
/* There are some command levels which called from command node. */
-enum node_type
+enum node_type
{
- AUTH_NODE, /* Authentication mode of vty interface. */
- VIEW_NODE, /* View node. Default mode of vty interface. */
- AUTH_ENABLE_NODE, /* Authentication mode for change enable. */
- ENABLE_NODE, /* Enable node. */
- CONFIG_NODE, /* Config node. Default mode of config file. */
- SERVICE_NODE, /* Service node. */
- DEBUG_NODE, /* Debug node. */
+ AUTH_NODE, /* Authentication mode of vty interface. */
+ VIEW_NODE, /* View node. Default mode of vty interface. */
+ AUTH_ENABLE_NODE, /* Authentication mode for change enable. */
+ ENABLE_NODE, /* Enable node. */
+ CONFIG_NODE, /* Config node. Default mode of config file. */
+ SERVICE_NODE, /* Service node. */
+ DEBUG_NODE, /* Debug node. */
VRF_DEBUG_NODE, /* Vrf Debug node. */
DEBUG_VNC_NODE, /* Debug VNC node. */
- AAA_NODE, /* AAA node. */
- KEYCHAIN_NODE, /* Key-chain node. */
- KEYCHAIN_KEY_NODE, /* Key-chain key node. */
- NS_NODE, /* Logical-Router node. */
- VRF_NODE, /* VRF mode node. */
- INTERFACE_NODE, /* Interface mode node. */
- ZEBRA_NODE, /* zebra connection node. */
- TABLE_NODE, /* rtm_table selection node. */
- RIP_NODE, /* RIP protocol mode node. */
- RIPNG_NODE, /* RIPng protocol mode node. */
- BGP_NODE, /* BGP protocol mode which includes BGP4+ */
- BGP_VPNV4_NODE, /* BGP MPLS-VPN PE exchange. */
- BGP_VPNV6_NODE, /* BGP MPLS-VPN PE exchange. */
- BGP_IPV4_NODE, /* BGP IPv4 unicast address family. */
- BGP_IPV4M_NODE, /* BGP IPv4 multicast address family. */
- BGP_IPV6_NODE, /* BGP IPv6 address family */
- BGP_IPV6M_NODE, /* BGP IPv6 multicast address family. */
- BGP_ENCAP_NODE, /* BGP ENCAP SAFI */
- BGP_ENCAPV6_NODE, /* BGP ENCAP SAFI */
+ AAA_NODE, /* AAA node. */
+ KEYCHAIN_NODE, /* Key-chain node. */
+ KEYCHAIN_KEY_NODE, /* Key-chain key node. */
+ NS_NODE, /* Logical-Router node. */
+ VRF_NODE, /* VRF mode node. */
+ INTERFACE_NODE, /* Interface mode node. */
+ ZEBRA_NODE, /* zebra connection node. */
+ TABLE_NODE, /* rtm_table selection node. */
+ RIP_NODE, /* RIP protocol mode node. */
+ RIPNG_NODE, /* RIPng protocol mode node. */
+ BGP_NODE, /* BGP protocol mode which includes BGP4+ */
+ BGP_VPNV4_NODE, /* BGP MPLS-VPN PE exchange. */
+ BGP_VPNV6_NODE, /* BGP MPLS-VPN PE exchange. */
+ BGP_IPV4_NODE, /* BGP IPv4 unicast address family. */
+ BGP_IPV4M_NODE, /* BGP IPv4 multicast address family. */
+ BGP_IPV6_NODE, /* BGP IPv6 address family */
+ BGP_IPV6M_NODE, /* BGP IPv6 multicast address family. */
+ BGP_ENCAP_NODE, /* BGP ENCAP SAFI */
+ BGP_ENCAPV6_NODE, /* BGP ENCAP SAFI */
BGP_VNC_DEFAULTS_NODE, /* BGP VNC nve defaults */
BGP_VNC_NVE_GROUP_NODE, /* BGP VNC nve group */
BGP_VNC_L2_GROUP_NODE, /* BGP VNC L2 group */
RFP_DEFAULTS_NODE, /* RFP defaults node */
- OSPF_NODE, /* OSPF protocol mode */
- OSPF6_NODE, /* OSPF protocol for IPv6 mode */
+ OSPF_NODE, /* OSPF protocol mode */
+ OSPF6_NODE, /* OSPF protocol for IPv6 mode */
LDP_NODE, /* LDP protocol mode */
LDP_IPV4_NODE, /* LDP IPv4 address family */
LDP_IPV6_NODE, /* LDP IPv6 address family */
@@ -110,43 +111,46 @@ enum node_type
LDP_IPV6_IFACE_NODE, /* LDP IPv6 Interface */
LDP_L2VPN_NODE, /* LDP L2VPN node */
LDP_PSEUDOWIRE_NODE, /* LDP Pseudowire node */
- ISIS_NODE, /* ISIS protocol mode */
- PIM_NODE, /* PIM protocol mode */
- MASC_NODE, /* MASC for multicast. */
- IRDP_NODE, /* ICMP Router Discovery Protocol mode. */
- IP_NODE, /* Static ip route node. */
- ACCESS_NODE, /* Access list node. */
- PREFIX_NODE, /* Prefix list node. */
- ACCESS_IPV6_NODE, /* Access list node. */
- PREFIX_IPV6_NODE, /* Prefix list node. */
- AS_LIST_NODE, /* AS list node. */
- COMMUNITY_LIST_NODE, /* Community list node. */
- RMAP_NODE, /* Route map node. */
- SMUX_NODE, /* SNMP configuration node. */
- DUMP_NODE, /* Packet dump node. */
- FORWARDING_NODE, /* IP forwarding node. */
+ ISIS_NODE, /* ISIS protocol mode */
+ PIM_NODE, /* PIM protocol mode */
+ MASC_NODE, /* MASC for multicast. */
+ IRDP_NODE, /* ICMP Router Discovery Protocol mode. */
+ IP_NODE, /* Static ip route node. */
+ ACCESS_NODE, /* Access list node. */
+ PREFIX_NODE, /* Prefix list node. */
+ ACCESS_IPV6_NODE, /* Access list node. */
+ PREFIX_IPV6_NODE, /* Prefix list node. */
+ AS_LIST_NODE, /* AS list node. */
+ COMMUNITY_LIST_NODE, /* Community list node. */
+ RMAP_NODE, /* Route map node. */
+ SMUX_NODE, /* SNMP configuration node. */
+ DUMP_NODE, /* Packet dump node. */
+ FORWARDING_NODE, /* IP forwarding node. */
PROTOCOL_NODE, /* protocol filtering node */
MPLS_NODE, /* MPLS config node */
- VTY_NODE, /* Vty node. */
- LINK_PARAMS_NODE, /* Link-parameters node */
+ VTY_NODE, /* Vty node. */
+ LINK_PARAMS_NODE, /* Link-parameters node */
};
/* Node which has some commands and prompt string and configuration
function pointer . */
-struct cmd_node
+struct cmd_node
{
/* Node index. */
- enum node_type node;
+ enum node_type node;
/* Prompt character at vty interface. */
- const char *prompt;
+ const char *prompt;
/* Is this node's configuration goes to vtysh ? */
int vtysh;
-
+
/* Node's configuration write function */
int (*func) (struct vty *);
+ /* Node's command graph */
+ struct graph *cmdgraph;
+
/* Vector of this node's command list. */
vector cmd_vector;
@@ -154,63 +158,61 @@ struct cmd_node
struct hash *cmd_hash;
};
-enum
+/**
+ * Types for tokens.
+ *
+ * The type determines what kind of data the token can match (in the
+ * matching use case) or hold (in the argv use case).
+ */
+enum cmd_token_type
{
- CMD_ATTR_DEPRECATED = 1,
- CMD_ATTR_HIDDEN,
+ WORD_TKN, // words
+ VARIABLE_TKN, // almost anything
+ RANGE_TKN, // integer range
+ IPV4_TKN, // IPV4 addresses
+ IPV4_PREFIX_TKN, // IPV4 network prefixes
+ IPV6_TKN, // IPV6 prefixes
+ IPV6_PREFIX_TKN, // IPV6 network prefixes
+
+ /* plumbing types */
+ SELECTOR_TKN, // marks beginning of selector
+ OPTION_TKN, // marks beginning of option
+ NUL_TKN, // dummy token
+ START_TKN, // first token in line
+ END_TKN, // last token in line
};
-/* Structure of command element. */
-struct cmd_element
+/**
+ * Token struct.
+ */
+struct cmd_token
{
- const char *string; /* Command specification by string. */
- int (*func) (struct cmd_element *, struct vty *, int, const char *[]);
- const char *doc; /* Documentation of this command. */
- int daemon; /* Daemon to which this command belong. */
- vector tokens; /* Vector of cmd_tokens */
- u_char attr; /* Command attributes */
-};
+ enum cmd_token_type type; // token type
+ char *text; // token text
+ char *desc; // token description
-enum cmd_token_type
-{
- TOKEN_TERMINAL = 0,
- TOKEN_MULTIPLE,
- TOKEN_KEYWORD,
+ long long min, max; // for ranges
+
+ char *arg; // user input that matches this token
};
-enum cmd_terminal_type
+enum
{
- _TERMINAL_BUG = 0,
- TERMINAL_LITERAL,
- TERMINAL_OPTION,
- TERMINAL_VARIABLE,
- TERMINAL_VARARG,
- TERMINAL_RANGE,
- TERMINAL_IPV4,
- TERMINAL_IPV4_PREFIX,
- TERMINAL_IPV6,
- TERMINAL_IPV6_PREFIX,
+ CMD_ATTR_DEPRECATED = 1,
+ CMD_ATTR_HIDDEN,
};
-/* argument to be recorded on argv[] if it's not a literal */
-#define TERMINAL_RECORD(t) ((t) >= TERMINAL_OPTION)
-
-/* Command description structure. */
-struct cmd_token
+/* Structure of command element. */
+struct cmd_element
{
- enum cmd_token_type type;
- enum cmd_terminal_type terminal;
-
- /* Used for type == MULTIPLE */
- vector multiple; /* vector of cmd_token, type == FINAL */
-
- /* Used for type == KEYWORD */
- vector keyword; /* vector of vector of cmd_tokens */
+ const char *string; /* Command specification by string. */
+ const char *doc; /* Documentation of this command. */
+ int daemon; /* Daemon to which this command belong. */
+ u_char attr; /* Command attributes */
- /* Used for type == TERMINAL */
- char *cmd; /* Command string. */
- char *desc; /* Command's description. */
+ /* handler function for command */
+ int (*func) (struct cmd_element *, struct vty *, int, struct cmd_token *[]);
};
/* Return value of the commands. */
@@ -231,7 +233,7 @@ struct cmd_token
#define CMD_ARGC_MAX 25
/* Turn off these macros when uisng cpp with extract.pl */
-#ifndef VTYSH_EXTRACT_PL
+#ifndef VTYSH_EXTRACT_PL
/* helper defines for end-user DEFUN* macros */
#define DEFUN_CMD_ELEMENT(funcname, cmdname, cmdstr, helpstr, attrs, dnum) \
@@ -245,179 +247,15 @@ struct cmd_token
};
#define DEFUN_CMD_FUNC_DECL(funcname) \
- static int funcname (struct cmd_element *, struct vty *, int, const char *[]);
+ static int funcname (struct cmd_element *, struct vty *, int, struct cmd_token *[]);
#define DEFUN_CMD_FUNC_TEXT(funcname) \
static int funcname \
(struct cmd_element *self __attribute__ ((unused)), \
struct vty *vty __attribute__ ((unused)), \
int argc __attribute__ ((unused)), \
- const char *argv[] __attribute__ ((unused)) )
+ struct cmd_token *argv[] __attribute__ ((unused)) )
-/* DEFUN for vty command interafce. Little bit hacky ;-).
- *
- * DEFUN(funcname, cmdname, cmdstr, helpstr)
- *
- * funcname
- * ========
- *
- * Name of the function that will be defined.
- *
- * cmdname
- * =======
- *
- * Name of the struct that will be defined for the command.
- *
- * cmdstr
- * ======
- *
- * The cmdstr defines the command syntax. It is used by the vty subsystem
- * and vtysh to perform matching and completion in the cli. So you have to take
- * care to construct it adhering to the following grammar. The names used
- * for the production rules losely represent the names used in lib/command.c
- *
- * cmdstr = cmd_token , { " " , cmd_token } ;
- *
- * cmd_token = cmd_terminal
- * | cmd_multiple
- * | cmd_keyword ;
- *
- * cmd_terminal_fixed = fixed_string
- * | variable
- * | range
- * | ipv4
- * | ipv4_prefix
- * | ipv6
- * | ipv6_prefix ;
- *
- * cmd_terminal = cmd_terminal_fixed
- * | option
- * | vararg ;
- *
- * multiple_part = cmd_terminal_fixed ;
- * cmd_multiple = "(" , multiple_part , ( "|" | { "|" , multiple_part } ) , ")" ;
- *
- * keyword_part = fixed_string , { " " , ( cmd_terminal_fixed | cmd_multiple ) } ;
- * cmd_keyword = "{" , keyword_part , { "|" , keyword_part } , "}" ;
- *
- * lowercase = "a" | ... | "z" ;
- * uppercase = "A" | ... | "Z" ;
- * digit = "0" | ... | "9" ;
- * number = digit , { digit } ;
- *
- * fixed_string = (lowercase | digit) , { lowercase | digit | uppercase | "-" | "_" } ;
- * variable = uppercase , { uppercase | "_" } ;
- * range = "<" , number , "-" , number , ">" ;
- * ipv4 = "A.B.C.D" ;
- * ipv4_prefix = "A.B.C.D/M" ;
- * ipv6 = "X:X::X:X" ;
- * ipv6_prefix = "X:X::X:X/M" ;
- * option = "[" , variable , "]" ;
- * vararg = "." , variable ;
- *
- * To put that all in a textual description: A cmdstr is a sequence of tokens,
- * separated by spaces.
- *
- * Terminal Tokens:
- *
- * A very simple cmdstring would be something like: "show ip bgp". It consists
- * of three Terminal Tokens, each containing a fixed string. When this command
- * is called, no arguments will be passed down to the function implementing it,
- * as it only consists of fixed strings.
- *
- * Apart from fixed strings, Terminal Tokens can also contain variables:
- * An example would be "show ip bgp A.B.C.D". This command expects an IPv4
- * as argument. As this is a variable, the IP address entered by the user will
- * be passed down as an argument. Apart from two exceptions, the other options
- * for Terminal Tokens behave exactly as we just discussed and only make a
- * difference for the CLI. The two exceptions will be discussed in the next
- * paragraphs.
- *
- * A Terminal Token can contain a so called option match. This is a simple
- * string variable that the user may omit. An example would be:
- * "show interface [IFNAME]". If the user calls this without an interface as
- * argument, no arguments will be passed down to the function implementing
- * this command. Otherwise, the interface name will be provided to the function
- * as a regular argument.
-
- * Also, a Terminal Token can contain a so called vararg. This is used e.g. in
- * "show ip bgp regexp .LINE". The last token is a vararg match and will
- * consume all the arguments the user inputs on the command line and append
- * those to the list of arguments passed down to the function implementing this
- * command. (Therefore, it doesn't make much sense to have any tokens after a
- * vararg because the vararg will already consume all the words the user entered
- * in the CLI)
- *
- * Multiple Tokens:
- *
- * The Multiple Token type can be used if there are multiple possibilities what
- * arguments may be used for a command, but it should map to the same function
- * nonetheless. An example would be "ip route A.B.C.D/M (reject|blackhole)"
- * In that case both "reject" and "blackhole" would be acceptable as last
- * arguments. The words matched by Multiple Tokens are always added to the
- * argument list, even if they are matched by fixed strings. Such a Multiple
- * Token can contain almost any type of token that would also be acceptable
- * for a Terminal Token, the exception are optional variables and varag.
- *
- * There is one special case that is used in some places of Quagga that should be
- * pointed out here shortly. An example would be "password (8|) WORD". This
- * construct is used to have fixed strings communicated as arguments. (The "8"
- * will be passed down as an argument in this case) It does not mean that
- * the "8" is optional. Another historic and possibly surprising property of
- * this construct is that it consumes two parts of helpstr. (Help
- * strings will be explained later)
- *
- * Keyword Tokens:
- *
- * There are commands that take a lot of different and possibly optional arguments.
- * An example from ospf would be the "default-information originate" command. This
- * command takes a lot of optional arguments that may be provided in any order.
- * To accomodate such commands, the Keyword Token has been implemented.
- * Using the keyword token, the "default-information originate" command and all
- * its possible options can be represented using this single cmdstr:
- * "default-information originate \
- * {always|metric <0-16777214>|metric-type (1|2)|route-map WORD}"
- *
- * Keywords always start with a fixed string and may be followed by arguments.
- * Except optional variables and vararg, everything is permitted here.
- *
- * For the special case of a keyword without arguments, either NULL or the
- * keyword itself will be pushed as an argument, depending on whether the
- * keyword is present.
- * For the other keywords, arguments will be only pushed for
- * variables/Multiple Tokens. If the keyword is not present, the arguments that
- * would have been pushed will be substituted by NULL.
- *
- * A few examples:
- * "default information originate metric-type 1 metric 1000"
- * would yield the following arguments:
- * { NULL, "1000", "1", NULL }
- *
- * "default information originate always route-map RMAP-DEFAULT"
- * would yield the following arguments:
- * { "always", NULL, NULL, "RMAP-DEFAULT" }
- *
- * helpstr
- * =======
- *
- * The helpstr is used to show a short explantion for the commands that
- * are available when the user presses '?' on the CLI. It is the concatenation
- * of the helpstrings for all the tokens that make up the command.
- *
- * There should be one helpstring for each token in the cmdstr except those
- * containing other tokens, like Multiple or Keyword Tokens. For those, there
- * will only be the helpstrings of the contained tokens.
- *
- * The individual helpstrings are expected to be in the same order as their
- * respective Tokens appear in the cmdstr. They should each be terminated with
- * a linefeed. The last helpstring should be terminated with a linefeed as well.
- *
- * Care should also be taken to avoid having similar tokens with different
- * helpstrings. Imagine e.g. the commands "show ip ospf" and "show ip bgp".
- * they both contain a helpstring for "show", but only one will be displayed
- * when the user enters "sh?". If those two helpstrings differ, it is not
- * defined which one will be shown and the behavior is therefore unpredictable.
- */
#define DEFUN(funcname, cmdname, cmdstr, helpstr) \
DEFUN_CMD_FUNC_DECL(funcname) \
DEFUN_CMD_ELEMENT(funcname, cmdname, cmdstr, helpstr, 0, 0) \
@@ -497,7 +335,6 @@ struct cmd_token
*/
#define CMD_CREATE_STR(s) CMD_CREATE_STR_HELPER(s)
#define CMD_CREATE_STR_HELPER(s) #s
-#define CMD_RANGE_STR(a,s) "<" CMD_CREATE_STR(a) "-" CMD_CREATE_STR(s) ">"
/* Common descriptions. */
#define SHOW_STR "Show running system information\n"
@@ -530,16 +367,16 @@ struct cmd_token
#define IP6_STR "IPv6 Information\n"
#define OSPF6_STR "Open Shortest Path First (OSPF) for IPv6\n"
#define OSPF6_ROUTER_STR "Enable a routing process\n"
-#define OSPF6_INSTANCE_STR "<1-65535> Instance ID\n"
-#define SECONDS_STR "<1-65535> Seconds\n"
+#define OSPF6_INSTANCE_STR "(1-65535) Instance ID\n"
+#define SECONDS_STR "(1-65535) Seconds\n"
#define ROUTE_STR "Routing Table\n"
#define PREFIX_LIST_STR "Build a prefix list\n"
#define OSPF6_DUMP_TYPE_LIST \
-"(neighbor|interface|area|lsa|zebra|config|dbex|spf|route|lsdb|redistribute|hook|asbr|prefix|abr)"
+"<neighbor|interface|area|lsa|zebra|config|dbex|spf|route|lsdb|redistribute|hook|asbr|prefix|abr>"
#define ISIS_STR "IS-IS information\n"
#define AREA_TAG_STR "[area tag]\n"
-#define COMMUNITY_AANN_STR "Community number where AA and NN are <0-65535>\n"
-#define COMMUNITY_VAL_STR "Community number in AA:NN format (where AA and NN are <0-65535>) or local-AS|no-advertise|no-export|internet or additive\n"
+#define COMMUNITY_AANN_STR "Community number where AA and NN are (0-65535)\n"
+#define COMMUNITY_VAL_STR "Community number in AA:NN format (where AA and NN are (0-65535)) or local-AS|no-advertise|no-export|internet or additive\n"
#define MPLS_TE_STR "MPLS-TE specific commands\n"
#define LINK_PARAMS_STR "Configure interface link parameters\n"
#define OSPF_RI_STR "OSPF Router Information specific commands\n"
@@ -551,28 +388,18 @@ struct cmd_token
/* IPv4 only machine should not accept IPv6 address for peer's IP
address. So we replace VTY command string like below. */
#ifdef HAVE_IPV6
-#define NEIGHBOR_CMD "neighbor (A.B.C.D|X:X::X:X) "
-#define NO_NEIGHBOR_CMD "no neighbor (A.B.C.D|X:X::X:X) "
#define NEIGHBOR_ADDR_STR "Neighbor address\nIPv6 address\n"
-#define NEIGHBOR_CMD2 "neighbor (A.B.C.D|X:X::X:X|WORD) "
-#define NO_NEIGHBOR_CMD2 "no neighbor (A.B.C.D|X:X::X:X|WORD) "
#define NEIGHBOR_ADDR_STR2 "Neighbor address\nNeighbor IPv6 address\nInterface name or neighbor tag\n"
#define NEIGHBOR_ADDR_STR3 "Neighbor address\nIPv6 address\nInterface name\n"
#else
-#define NEIGHBOR_CMD "neighbor A.B.C.D "
-#define NO_NEIGHBOR_CMD "no neighbor A.B.C.D "
#define NEIGHBOR_ADDR_STR "Neighbor address\n"
-#define NEIGHBOR_CMD2 "neighbor (A.B.C.D|WORD) "
-#define NO_NEIGHBOR_CMD2 "no neighbor (A.B.C.D|WORD) "
#define NEIGHBOR_ADDR_STR2 "Neighbor address\nNeighbor tag\n"
#endif /* HAVE_IPV6 */
/* Dynamic neighbor (listen range) configuration */
#ifdef HAVE_IPV6
-#define LISTEN_RANGE_CMD "bgp listen range (A.B.C.D/M|X:X::X:X/M) "
#define LISTEN_RANGE_ADDR_STR "Neighbor address\nNeighbor IPv6 address\n"
#else
-#define LISTEN_RANGE_CMD "bgp listen range A.B.C.D/M "
#define LISTEN_RANGE_ADDR_STR "Neighbor address\n"
#endif /* HAVE_IPV6 */
@@ -584,10 +411,12 @@ extern void install_element (enum node_type, struct cmd_element *);
/* Concatenates argv[shift] through argv[argc-1] into a single NUL-terminated
string with a space between each element (allocated using
XMALLOC(MTYPE_TMP)). Returns NULL if shift >= argc. */
-extern char *argv_concat (const char **argv, int argc, int shift);
+extern char *argv_concat (struct cmd_token **argv, int argc, int shift);
+extern int argv_find (struct cmd_token **argv, int argc, const char *text, int *index);
extern vector cmd_make_strvec (const char *);
extern void cmd_free_strvec (vector);
+extern char *cmd_concat_strvec (vector);
extern vector cmd_describe_command (vector, struct vty *, int *status);
extern char **cmd_complete_command (vector, struct vty *, int *status);
extern char **cmd_complete_command_lib (vector, struct vty *, int *status, int islib);
@@ -600,6 +429,20 @@ extern int cmd_execute_command_strict (vector, struct vty *, struct cmd_element
extern void cmd_init (int);
extern void cmd_terminate (void);
+/* memory management for cmd_element */
+void
+del_cmd_element(struct cmd_element *);
+struct cmd_element *
+copy_cmd_element(struct cmd_element *cmd);
+
+/* memory management for cmd_token */
+struct cmd_token *
+new_cmd_token (enum cmd_token_type, char *, char *);
+void
+del_cmd_token (struct cmd_token *);
+struct cmd_token *
+copy_cmd_token (struct cmd_token *);
+
/* Export typical functions. */
extern struct cmd_element config_end_cmd;
extern struct cmd_element config_exit_cmd;
@@ -614,8 +457,9 @@ extern void print_version (const char *);
extern int cmd_banner_motd_file (const char *);
/* struct host global, ick */
-extern struct host host;
+extern struct host host;
+
+/* text for <cr> command */
+#define CMD_CR_TEXT "<cr>"
-/* "<cr>" global */
-extern char *command_cr;
#endif /* _ZEBRA_COMMAND_H */
diff --git a/lib/command_lex.l b/lib/command_lex.l
new file mode 100644
index 0000000000..5c709dce22
--- /dev/null
+++ b/lib/command_lex.l
@@ -0,0 +1,71 @@
+/*
+ * Command format string lexer for CLI backend.
+ *
+ * --
+ * Copyright (C) 2015 Cumulus Networks, Inc.
+ *
+ * This file is part of GNU Zebra.
+ *
+ * GNU Zebra is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2, or (at your option) any
+ * later version.
+ *
+ * GNU Zebra is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GNU Zebra; see the file COPYING. If not, write to the Free
+ * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ */
+
+%{
+#include "command_parse.h"
+
+extern void set_lexer_string (const char *);
+extern void cleanup_lexer (void);
+YY_BUFFER_STATE buffer;
+%}
+
+WORD (\-|\+)?[a-z\*][-+_a-zA-Z0-9\*]*
+IPV4 A\.B\.C\.D
+IPV4_PREFIX A\.B\.C\.D\/M
+IPV6 X:X::X:X
+IPV6_PREFIX X:X::X:X\/M
+VARIABLE [A-Z][-_a-zA-Z:0-9]+
+NUMBER (\-|\+)?[0-9]{1,20}
+RANGE \({NUMBER}[ ]?\-[ ]?{NUMBER}\)
+
+/* yytext shall be a pointer */
+%pointer
+%option noyywrap
+%option nounput
+%option noinput
+%option outfile="command_lex.c"
+
+%%
+[ /t] /* ignore whitespace */;
+{WORD} {yylval.string = XSTRDUP(MTYPE_TMP, yytext); return WORD;}
+{IPV4} {yylval.string = XSTRDUP(MTYPE_TMP, yytext); return IPV4;}
+{IPV4_PREFIX} {yylval.string = XSTRDUP(MTYPE_TMP, yytext); return IPV4_PREFIX;}
+{IPV6} {yylval.string = XSTRDUP(MTYPE_TMP, yytext); return IPV6;}
+{IPV6_PREFIX} {yylval.string = XSTRDUP(MTYPE_TMP, yytext); return IPV6_PREFIX;}
+{VARIABLE} {yylval.string = XSTRDUP(MTYPE_TMP, yytext); return VARIABLE;}
+{RANGE} {yylval.string = XSTRDUP(MTYPE_TMP, yytext); return RANGE;}
+. {return yytext[0];}
+%%
+
+void
+set_lexer_string (const char *string)
+{
+ buffer = yy_scan_string (string);
+}
+
+void
+cleanup_lexer ()
+{
+ yy_delete_buffer (buffer);
+}
diff --git a/lib/command_match.c b/lib/command_match.c
new file mode 100644
index 0000000000..42788ecb01
--- /dev/null
+++ b/lib/command_match.c
@@ -0,0 +1,850 @@
+/*
+ * Input matching routines for CLI backend.
+ *
+ * --
+ * Copyright (C) 2016 Cumulus Networks, Inc.
+ *
+ * This file is part of GNU Zebra.
+ *
+ * GNU Zebra is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2, or (at your option) any
+ * later version.
+ *
+ * GNU Zebra is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GNU Zebra; see the file COPYING. If not, write to the Free
+ * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ */
+
+#include <zebra.h>
+
+#include "command_match.h"
+#include "command_parse.h"
+#include "memory.h"
+
+DEFINE_MTYPE_STATIC(LIB, CMD_TOKENS, "Command Tokens")
+
+/* matcher helper prototypes */
+static int
+add_nexthops (struct list *, struct graph_node *);
+
+static struct list *
+command_match_r (struct graph_node *, vector, unsigned int);
+
+static int
+score_precedence (enum cmd_token_type);
+
+static enum match_type
+min_match_level (enum cmd_token_type);
+
+static void
+del_arglist (struct list *);
+
+static struct cmd_token *
+disambiguate_tokens (struct cmd_token *, struct cmd_token *, char *);
+
+static struct list *
+disambiguate (struct list *, struct list *, vector, unsigned int);
+
+int
+compare_completions (const void *, const void *);
+
+/* token matcher prototypes */
+static enum match_type
+match_token (struct cmd_token *, char *);
+
+static enum match_type
+match_ipv4 (const char *);
+
+static enum match_type
+match_ipv4_prefix (const char *);
+
+static enum match_type
+match_ipv6 (const char *);
+
+static enum match_type
+match_ipv6_prefix (const char *);
+
+static enum match_type
+match_range (struct cmd_token *, const char *);
+
+static enum match_type
+match_word (struct cmd_token *, const char *);
+
+static enum match_type
+match_variable (struct cmd_token *, const char *);
+
+/* matching functions */
+static enum matcher_rv matcher_rv;
+
+enum matcher_rv
+command_match (struct graph *cmdgraph,
+ vector vline,
+ struct list **argv,
+ struct cmd_element **el)
+{
+ matcher_rv = MATCHER_NO_MATCH;
+
+ // prepend a dummy token to match that pesky start node
+ vector vvline = vector_init (vline->alloced + 1);
+ vector_set_index (vvline, 0, (void *) XSTRDUP (MTYPE_TMP, "dummy"));
+ memcpy (vvline->index + 1, vline->index, sizeof (void *) * vline->alloced);
+ vvline->active = vline->active + 1;
+
+ struct graph_node *start = vector_slot (cmdgraph->nodes, 0);
+ if ((*argv = command_match_r (start, vvline, 0))) // successful match
+ {
+ struct listnode *head = listhead (*argv);
+ struct listnode *tail = listtail (*argv);
+
+ // delete dummy start node
+ del_cmd_token ((struct cmd_token *) head->data);
+ list_delete_node (*argv, head);
+
+ // get cmd_element out of list tail
+ *el = listgetdata (tail);
+ list_delete_node (*argv, tail);
+
+ // now argv is an ordered list of cmd_token matching the user
+ // input, with each cmd_token->arg holding the corresponding input
+ assert (*el);
+ }
+
+#ifdef TRACE_MATCHER
+ if (!*el)
+ fprintf (stdout, "No match\n");
+ else
+ fprintf (stdout, "Matched command\n->string %s\n->desc %s\n", (*el)->string, (*el)->doc);
+#endif
+
+ // free the leader token we alloc'd
+ XFREE (MTYPE_TMP, vector_slot (vvline, 0));
+ // free vector
+ vector_free (vvline);
+
+ return matcher_rv;
+}
+
+/**
+ * Builds an argument list given a DFA and a matching input line.
+ *
+ * First the function determines if the node it is passed matches the first
+ * token of input. If it does not, it returns NULL (MATCHER_NO_MATCH). If it
+ * does match, then it saves the input token as the head of an argument list.
+ *
+ * The next step is to see if there is further input in the input line. If
+ * there is not, the current node's children are searched to see if any of them
+ * are leaves (type END_TKN). If this is the case, then the bottom of the
+ * recursion stack has been reached, the leaf is pushed onto the argument list,
+ * the current node is pushed, and the resulting argument list is
+ * returned (MATCHER_OK). If it is not the case, NULL is returned, indicating
+ * that there is no match for the input along this path (MATCHER_INCOMPLETE).
+ *
+ * If there is further input, then the function recurses on each of the current
+ * node's children, passing them the input line minus the token that was just
+ * matched. For each child, the return value of the recursive call is
+ * inspected. If it is null, then there is no match for the input along the
+ * subgraph headed by that child. If it is not null, then there is at least one
+ * input match in that subgraph (more on this in a moment).
+ *
+ * If a recursive call on a child returns a non-null value, then it has matched
+ * the input given it on the subgraph that starts with that child. However, due
+ * to the flexibility of the grammar, it is sometimes the case that two or more
+ * child graphs match the same input (two or more of the recursive calls have
+ * non-NULL return values). This is not a valid state, since only one true
+ * match is possible. In order to resolve this conflict, the function keeps a
+ * reference to the child node that most specifically matches the input. This
+ * is done by assigning each node type a precedence. If a child is found to
+ * match the remaining input, then the precedence values of the current
+ * best-matching child and this new match are compared. The node with higher
+ * precedence is kept, and the other match is discarded. Due to the recursive
+ * nature of this function, it is only necessary to compare the precedence of
+ * immediate children, since all subsequent children will already have been
+ * disambiguated in this way.
+ *
+ * In the event that two children are found to match with the same precedence,
+ * then the input is ambiguous for the passed cmd_element and NULL is returned.
+ *
+ * The ultimate return value is an ordered linked list of nodes that comprise
+ * the best match for the command, each with their `arg` fields pointing to the
+ * matching token string.
+ *
+ * @param[in] start the start node.
+ * @param[in] vline the vectorized input line.
+ * @param[in] n the index of the first input token.
+ */
+static struct list *
+command_match_r (struct graph_node *start, vector vline, unsigned int n)
+{
+ assert (n < vector_active (vline));
+
+ // get the minimum match level that can count as a full match
+ struct cmd_token *token = start->data;
+ enum match_type minmatch = min_match_level (token->type);
+
+ // get the current operating input token
+ char *input_token = vector_slot (vline, n);
+
+#ifdef TRACE_MATCHER
+ fprintf (stdout, "\"%-20s\" matches \"%-30s\" ? ", input_token, token->text);
+ enum match_type mt = match_token (token, input_token);
+ fprintf (stdout, "min: %d - ", minmatch);
+ switch (mt)
+ {
+ case trivial_match:
+ fprintf (stdout, "trivial_match ");
+ break;
+ case no_match:
+ fprintf (stdout, "no_match ");
+ break;
+ case partly_match:
+ fprintf (stdout, "partly_match ");
+ break;
+ case exact_match:
+ fprintf (stdout, "exact_match ");
+ break;
+ }
+ if (mt >= minmatch) fprintf (stdout, " MATCH");
+ fprintf (stdout, "\n");
+#endif
+
+ // if we don't match this node, die
+ if (match_token (token, input_token) < minmatch)
+ return NULL;
+
+ // pointers for iterating linklist
+ struct listnode *ln;
+ struct graph_node *gn;
+
+ // get all possible nexthops
+ struct list *next = list_new();
+ add_nexthops (next, start);
+
+ // determine the best match
+ int ambiguous = 0;
+ struct list *currbest = NULL;
+ for (ALL_LIST_ELEMENTS_RO (next,ln,gn))
+ {
+ // if we've matched all input we're looking for END_TKN
+ if (n+1 == vector_active (vline))
+ {
+ struct cmd_token *tok = gn->data;
+ if (tok->type == END_TKN)
+ {
+ currbest = list_new();
+ // node should have one child node with the element
+ struct graph_node *leaf = vector_slot (gn->to, 0);
+ // last node in the list will hold the cmd_element;
+ // this is important because list_delete() expects
+ // that all nodes have the same data type, so when
+ // deleting this list the last node must be
+ // manually deleted
+ struct cmd_element *el = leaf->data;
+ listnode_add (currbest, copy_cmd_element (el));
+ currbest->del = (void (*)(void *)) &del_cmd_token;
+ break;
+ }
+ else continue;
+ }
+
+ // else recurse on candidate child node
+ struct list *result = command_match_r (gn, vline, n+1);
+
+ // save the best match
+ if (result && currbest)
+ {
+ // pick the best of two matches
+ struct list *newbest = disambiguate (currbest, result, vline, n+1);
+ // set ambiguity flag
+ ambiguous = !newbest || (ambiguous && newbest == currbest);
+ // delete the unnecessary result
+ struct list *todelete = ((newbest && newbest == result) ? currbest : result);
+ del_arglist (todelete);
+
+ currbest = newbest ? newbest : currbest;
+ }
+ else if (result)
+ currbest = result;
+ }
+
+ if (currbest)
+ {
+ if (ambiguous)
+ {
+ del_arglist (currbest);
+ currbest = NULL;
+ matcher_rv = MATCHER_AMBIGUOUS;
+ }
+ else
+ {
+ // copy token, set arg and prepend to currbest
+ struct cmd_token *token = start->data;
+ struct cmd_token *copy = copy_cmd_token (token);
+ copy->arg = XSTRDUP (MTYPE_CMD_TOKENS, input_token);
+ listnode_add_before (currbest, currbest->head, copy);
+ matcher_rv = MATCHER_OK;
+ }
+ }
+ else if (n+1 == vector_active (vline) && matcher_rv == MATCHER_NO_MATCH)
+ matcher_rv = MATCHER_INCOMPLETE;
+
+ // cleanup
+ list_delete (next);
+
+ return currbest;
+}
+
+enum matcher_rv
+command_complete (struct graph *graph,
+ vector vline,
+ struct list **completions)
+{
+ // pointer to next input token to match
+ char *input_token;
+
+ struct list *current = list_new(), // current nodes to match input token against
+ *next = list_new(); // possible next hops after current input token
+
+ // pointers used for iterating lists
+ struct graph_node *gn;
+ struct listnode *node;
+
+ // add all children of start node to list
+ struct graph_node *start = vector_slot (graph->nodes, 0);
+ add_nexthops (next, start);
+
+ unsigned int idx;
+ for (idx = 0; idx < vector_active (vline) && next->count > 0; idx++)
+ {
+ list_delete (current);
+ current = next;
+ next = list_new();
+
+ input_token = vector_slot (vline, idx);
+
+ for (ALL_LIST_ELEMENTS_RO (current,node,gn))
+ {
+ struct cmd_token *token = gn->data;
+ enum match_type minmatch = min_match_level (token->type);
+#ifdef TRACE_MATCHER
+ fprintf (stdout, "\"%s\" matches \"%s\" (%d) ? ", input_token, token->text, token->type);
+#endif
+
+ switch (match_token (token, input_token))
+ {
+ case trivial_match:
+#ifdef TRACE_MATCHER
+ fprintf (stdout, "trivial_match\n");
+#endif
+ case partly_match:
+#ifdef TRACE_MATCHER
+ fprintf (stdout, "partly_match\n");
+#endif
+ if (idx == vector_active (vline) - 1)
+ {
+ listnode_add (next, gn);
+ break;
+ }
+ if (minmatch > partly_match)
+ break;
+ case exact_match:
+#ifdef TRACE_MATCHER
+ fprintf (stdout, "exact_match\n");
+#endif
+ add_nexthops (next, gn);
+ break;
+ default:
+#ifdef TRACE_MATCHER
+ fprintf (stdout, "no_match\n");
+#endif
+ break;
+ }
+ }
+ }
+
+ /* Variable summary
+ * -----------------------------------------------------------------
+ * token = last input token processed
+ * idx = index in `command` of last token processed
+ * current = set of all transitions from the previous input token
+ * next = set of all nodes reachable from all nodes in `matched`
+ */
+
+ matcher_rv =
+ idx == vector_active(vline) && next->count ?
+ MATCHER_OK :
+ MATCHER_NO_MATCH;
+
+ // extract cmd_token into list
+ *completions = list_new ();
+ for (ALL_LIST_ELEMENTS_RO (next,node,gn))
+ listnode_add (*completions, gn->data);
+
+ list_delete (current);
+ list_delete (next);
+
+ return matcher_rv;
+}
+
+/**
+ * Adds all children that are reachable by one parser hop to the given list.
+ * NUL_TKN, SELECTOR_TKN, and OPTION_TKN nodes are treated as transparent.
+ *
+ * @param[in] list to add the nexthops to
+ * @param[in] node to start calculating nexthops from
+ * @return the number of children added to the list
+ */
+static int
+add_nexthops (struct list *list, struct graph_node *node)
+{
+ int added = 0;
+ struct graph_node *child;
+ for (unsigned int i = 0; i < vector_active (node->to); i++)
+ {
+ child = vector_slot (node->to, i);
+ struct cmd_token *token = child->data;
+ switch (token->type)
+ {
+ case OPTION_TKN:
+ case SELECTOR_TKN:
+ case NUL_TKN:
+ added += add_nexthops (list, child);
+ break;
+ default:
+ listnode_add (list, child);
+ added++;
+ }
+ }
+
+ return added;
+}
+
+/**
+ * Determines the node types for which a partial match may count as a full
+ * match. Enables command abbrevations.
+ *
+ * @param[in] type node type
+ * @return minimum match level needed to for a token to fully match
+ */
+static enum match_type
+min_match_level (enum cmd_token_type type)
+{
+ switch (type)
+ {
+ // anything matches a start node, for the sake of recursion
+ case START_TKN:
+ return no_match;
+ // allowing words to partly match enables command abbreviation
+ case WORD_TKN:
+ return partly_match;
+ default:
+ return exact_match;
+ }
+}
+
+/**
+ * Assigns precedence scores to node types.
+ *
+ * @param[in] type node type to score
+ * @return precedence score
+ */
+static int
+score_precedence (enum cmd_token_type type)
+{
+ switch (type)
+ {
+ // some of these are mutually exclusive, so they share
+ // the same precedence value
+ case IPV4_TKN:
+ case IPV4_PREFIX_TKN:
+ case IPV6_TKN:
+ case IPV6_PREFIX_TKN:
+ case RANGE_TKN:
+ return 2;
+ case WORD_TKN:
+ return 3;
+ case VARIABLE_TKN:
+ return 4;
+ default:
+ return 10;
+ }
+}
+
+/**
+ * Picks the better of two possible matches for a token.
+ *
+ * @param[in] first candidate node matching token
+ * @param[in] second candidate node matching token
+ * @param[in] token the token being matched
+ * @return the best-matching node, or NULL if the two are entirely ambiguous
+ */
+static struct cmd_token *
+disambiguate_tokens (struct cmd_token *first,
+ struct cmd_token *second,
+ char *input_token)
+{
+ // if the types are different, simply go off of type precedence
+ if (first->type != second->type)
+ {
+ int firstprec = score_precedence (first->type);
+ int secndprec = score_precedence (second->type);
+ if (firstprec != secndprec)
+ return firstprec < secndprec ? first : second;
+ else
+ return NULL;
+ }
+
+ // if they're the same, return the more exact match
+ enum match_type fmtype = match_token (first, input_token);
+ enum match_type smtype = match_token (second, input_token);
+ if (fmtype != smtype)
+ return fmtype > smtype ? first : second;
+
+ return NULL;
+}
+
+/**
+ * Picks the better of two possible matches for an input line.
+ *
+ * @param[in] first candidate list of cmd_token matching vline
+ * @param[in] second candidate list of cmd_token matching vline
+ * @param[in] vline the input line being matched
+ * @param[in] n index into vline to start comparing at
+ * @return the best-matching list, or NULL if the two are entirely ambiguous
+ */
+static struct list *
+disambiguate (struct list *first,
+ struct list *second,
+ vector vline,
+ unsigned int n)
+{
+ // doesn't make sense for these to be inequal length
+ assert (first->count == second->count);
+ assert (first->count == vector_active (vline) - n+1);
+
+ struct listnode *fnode = listhead (first),
+ *snode = listhead (second);
+ struct cmd_token *ftok = listgetdata (fnode),
+ *stok = listgetdata (snode),
+ *best = NULL;
+
+ // compare each token, if one matches better use that one
+ for (unsigned int i = n; i < vector_active (vline); i++)
+ {
+ char *token = vector_slot(vline, i);
+ if ((best = disambiguate_tokens (ftok, stok, token)))
+ return best == ftok ? first : second;
+ fnode = listnextnode (fnode);
+ snode = listnextnode (snode);
+ ftok = listgetdata (fnode);
+ stok = listgetdata (snode);
+ }
+
+ return NULL;
+}
+
+/*
+ * Deletion function for arglist.
+ *
+ * Since list->del for arglists expects all listnode->data to hold cmd_token,
+ * but arglists have cmd_element as the data for the tail, this function
+ * manually deletes the tail before deleting the rest of the list as usual.
+ *
+ * @param list the arglist to delete
+ */
+static void
+del_arglist (struct list *list)
+{
+ // manually delete last node
+ struct listnode *tail = listtail (list);
+ del_cmd_element (tail->data);
+ tail->data = NULL;
+ list_delete_node (list, tail);
+
+ // delete the rest of the list as usual
+ list_delete (list);
+}
+
+/*---------- token level matching functions ----------*/
+
+static enum match_type
+match_token (struct cmd_token *token, char *input_token)
+{
+ // nothing trivially matches everything
+ if (!input_token)
+ return trivial_match;
+
+ switch (token->type) {
+ case WORD_TKN:
+ return match_word (token, input_token);
+ case IPV4_TKN:
+ return match_ipv4 (input_token);
+ case IPV4_PREFIX_TKN:
+ return match_ipv4_prefix (input_token);
+ case IPV6_TKN:
+ return match_ipv6 (input_token);
+ case IPV6_PREFIX_TKN:
+ return match_ipv6_prefix (input_token);
+ case RANGE_TKN:
+ return match_range (token, input_token);
+ case VARIABLE_TKN:
+ return match_variable (token, input_token);
+ case END_TKN:
+ default:
+ return no_match;
+ }
+}
+
+#define IPV4_ADDR_STR "0123456789."
+#define IPV4_PREFIX_STR "0123456789./"
+
+static enum match_type
+match_ipv4 (const char *str)
+{
+ const char *sp;
+ int dots = 0, nums = 0;
+ char buf[4];
+
+ for (;;)
+ {
+ memset (buf, 0, sizeof (buf));
+ sp = str;
+ while (*str != '\0')
+ {
+ if (*str == '.')
+ {
+ if (dots >= 3)
+ return no_match;
+
+ if (*(str + 1) == '.')
+ return no_match;
+
+ if (*(str + 1) == '\0')
+ return partly_match;
+
+ dots++;
+ break;
+ }
+ if (!isdigit ((int) *str))
+ return no_match;
+
+ str++;
+ }
+
+ if (str - sp > 3)
+ return no_match;
+
+ strncpy (buf, sp, str - sp);
+ if (atoi (buf) > 255)
+ return no_match;
+
+ nums++;
+
+ if (*str == '\0')
+ break;
+
+ str++;
+ }
+
+ if (nums < 4)
+ return partly_match;
+
+ return exact_match;
+}
+
+static enum match_type
+match_ipv4_prefix (const char *str)
+{
+ const char *sp;
+ int dots = 0;
+ char buf[4];
+
+ for (;;)
+ {
+ memset (buf, 0, sizeof (buf));
+ sp = str;
+ while (*str != '\0' && *str != '/')
+ {
+ if (*str == '.')
+ {
+ if (dots == 3)
+ return no_match;
+
+ if (*(str + 1) == '.' || *(str + 1) == '/')
+ return no_match;
+
+ if (*(str + 1) == '\0')
+ return partly_match;
+
+ dots++;
+ break;
+ }
+
+ if (!isdigit ((int) *str))
+ return no_match;
+
+ str++;
+ }
+
+ if (str - sp > 3)
+ return no_match;
+
+ strncpy (buf, sp, str - sp);
+ if (atoi (buf) > 255)
+ return no_match;
+
+ if (dots == 3)
+ {
+ if (*str == '/')
+ {
+ if (*(str + 1) == '\0')
+ return partly_match;
+
+ str++;
+ break;
+ }
+ else if (*str == '\0')
+ return partly_match;
+ }
+
+ if (*str == '\0')
+ return partly_match;
+
+ str++;
+ }
+
+ sp = str;
+ while (*str != '\0')
+ {
+ if (!isdigit ((int) *str))
+ return no_match;
+
+ str++;
+ }
+
+ if (atoi (sp) > 32)
+ return no_match;
+
+ return exact_match;
+}
+
+#ifdef HAVE_IPV6
+#define IPV6_ADDR_STR "0123456789abcdefABCDEF:."
+#define IPV6_PREFIX_STR "0123456789abcdefABCDEF:./"
+
+static enum match_type
+match_ipv6 (const char *str)
+{
+ struct sockaddr_in6 sin6_dummy;
+ int ret;
+
+ if (strspn (str, IPV6_ADDR_STR) != strlen (str))
+ return no_match;
+
+ ret = inet_pton(AF_INET6, str, &sin6_dummy.sin6_addr);
+
+ if (ret == 1)
+ return exact_match;
+
+ return no_match;
+}
+
+static enum match_type
+match_ipv6_prefix (const char *str)
+{
+ struct sockaddr_in6 sin6_dummy;
+ const char *delim = "/\0";
+ char *tofree, *dupe, *prefix, *mask, *endptr;
+ int nmask = -1;
+
+ if (strspn (str, IPV6_PREFIX_STR) != strlen (str))
+ return no_match;
+
+ /* tokenize to prefix + mask */
+ tofree = dupe = XSTRDUP (MTYPE_TMP, str);
+ prefix = strsep (&dupe, delim);
+ mask = dupe;
+
+ /* validate prefix */
+ if (inet_pton (AF_INET6, prefix, &sin6_dummy.sin6_addr) != 1)
+ {
+ XFREE (MTYPE_TMP, tofree);
+ return no_match;
+ }
+
+ /* validate mask */
+ if (!mask)
+ {
+ XFREE (MTYPE_TMP, tofree);
+ return partly_match;
+ }
+
+ nmask = strtoimax (mask, &endptr, 10);
+ if (*endptr != '\0' || nmask < 0 || nmask > 128)
+ {
+ XFREE (MTYPE_TMP, tofree);
+ return no_match;
+ }
+
+ XFREE (MTYPE_TMP, tofree);
+ return exact_match;
+}
+#endif
+
+static enum match_type
+match_range (struct cmd_token *token, const char *str)
+{
+ assert (token->type == RANGE_TKN);
+
+ char *endptr = NULL;
+ long long val;
+
+ val = strtoll (str, &endptr, 10);
+ if (*endptr != '\0')
+ return no_match;
+
+ if (val < token->min || val > token->max)
+ return no_match;
+ else
+ return exact_match;
+}
+
+static enum match_type
+match_word (struct cmd_token *token, const char *word)
+{
+ assert (token->type == WORD_TKN);
+
+ // if the passed token is 0 length, partly match
+ if (!strlen(word))
+ return partly_match;
+
+ // if the passed token is strictly a prefix of the full word, partly match
+ if (strlen (word) < strlen (token->text))
+ return !strncmp (token->text, word, strlen (word)) ?
+ partly_match :
+ no_match;
+
+ // if they are the same length and exactly equal, exact match
+ else if (strlen (word) == strlen (token->text))
+ return !strncmp (token->text, word, strlen (word)) ? exact_match : no_match;
+
+ return no_match;
+}
+
+#define VARIABLE_ALPHABET \
+"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890:/._"
+
+static enum match_type
+match_variable (struct cmd_token *token, const char *word)
+{
+ assert (token->type == VARIABLE_TKN);
+
+ return strlen (word) == strspn(word, VARIABLE_ALPHABET) ?
+ exact_match : no_match;
+}
diff --git a/lib/command_match.h b/lib/command_match.h
new file mode 100644
index 0000000000..ac4e70c316
--- /dev/null
+++ b/lib/command_match.h
@@ -0,0 +1,96 @@
+/*
+ * Input matching routines for CLI backend.
+ *
+ * --
+ * Copyright (C) 2016 Cumulus Networks, Inc.
+ *
+ * This file is part of GNU Zebra.
+ *
+ * GNU Zebra is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2, or (at your option) any
+ * later version.
+ *
+ * GNU Zebra is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GNU Zebra; see the file COPYING. If not, write to the Free
+ * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ */
+
+#ifndef _ZEBRA_COMMAND_MATCH_H
+#define _ZEBRA_COMMAND_MATCH_H
+
+#include "graph.h"
+#include "linklist.h"
+#include "command.h"
+
+/* These definitions exist in command.c in the current engine but should be
+ * relocated here in the new engine
+ */
+enum filter_type
+{
+ FILTER_RELAXED,
+ FILTER_STRICT
+};
+
+/* matcher result value */
+enum matcher_rv
+{
+ MATCHER_NO_MATCH,
+ MATCHER_INCOMPLETE,
+ MATCHER_AMBIGUOUS,
+ MATCHER_OK,
+};
+
+/* completion match types */
+enum match_type
+{
+ trivial_match, // the input is null
+ no_match, // the input does not match
+ partly_match, // the input matches but is incomplete
+ exact_match // the input matches and is complete
+};
+
+/* Defines which matcher_rv values constitute an error. Should be used with
+ * matcher_rv return values to do basic error checking.
+ */
+#define MATCHER_ERROR(matcher_rv) \
+ ( (matcher_rv) == MATCHER_INCOMPLETE \
+ || (matcher_rv) == MATCHER_NO_MATCH \
+ || (matcher_rv) == MATCHER_AMBIGUOUS \
+ )
+
+/**
+ * Attempt to find an exact command match for a line of user input.
+ *
+ * @param[in] cmdgraph command graph to match against
+ * @param[in] vline vectorized input string
+ * @param[out] argv pointer to argument list if successful match
+ * @param[out] element pointer to matched cmd_element if successful match
+ * @return matcher status
+ */
+enum matcher_rv
+command_match (struct graph *cmdgraph,
+ vector vline,
+ struct list **argv,
+ struct cmd_element **element);
+
+/**
+ * Compiles possible completions for a given line of user input.
+ *
+ * @param[in] start the start node of the DFA to match against
+ * @param[in] vline vectorized input string
+ * @param[in] completions pointer to list of cmd_token representing
+ * acceptable next inputs
+ */
+enum matcher_rv
+command_complete (struct graph *cmdgraph,
+ vector vline,
+ struct list **completions);
+
+#endif /* _ZEBRA_COMMAND_MATCH_H */
diff --git a/lib/command_parse.y b/lib/command_parse.y
new file mode 100644
index 0000000000..89c0e47f83
--- /dev/null
+++ b/lib/command_parse.y
@@ -0,0 +1,544 @@
+/*
+ * Command format string parser for CLI backend.
+ *
+ * --
+ * Copyright (C) 2016 Cumulus Networks, Inc.
+ *
+ * This file is part of GNU Zebra.
+ *
+ * GNU Zebra is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2, or (at your option) any
+ * later version.
+ *
+ * GNU Zebra is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GNU Zebra; see the file COPYING. If not, write to the Free
+ * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ */
+
+%{
+// compile with debugging facilities
+#define YYDEBUG 1
+%}
+
+/* names for generated header and parser files */
+%defines "command_parse.h"
+%output "command_parse.c"
+
+/* required external units */
+%code requires {
+ #include "stdlib.h"
+ #include "string.h"
+ #include "command.h"
+ #include "graph.h"
+
+ extern int
+ yylex (void);
+
+ extern void
+ set_lexer_string (const char *);
+
+ extern void
+ cleanup_lexer (void);
+}
+
+/* functionality this unit exports */
+%code provides {
+ void
+ command_parse_format (struct graph *, struct cmd_element *);
+
+ /* maximum length of a number, lexer will not match anything longer */
+ #define DECIMAL_STRLEN_MAX 20
+}
+
+/* valid semantic types for tokens and rules */
+%union {
+ long long number;
+ char *string;
+ struct graph_node *node;
+ struct subgraph *subgraph;
+}
+
+/* union types for lexed tokens */
+%token <string> WORD
+%token <string> IPV4
+%token <string> IPV4_PREFIX
+%token <string> IPV6
+%token <string> IPV6_PREFIX
+%token <string> VARIABLE
+%token <string> RANGE
+
+/* union types for parsed rules */
+%type <node> start
+%type <node> sentence_root
+%type <node> literal_token
+%type <node> placeholder_token
+%type <node> simple_token
+%type <subgraph> option
+%type <subgraph> option_token
+%type <subgraph> option_token_seq
+%type <subgraph> selector
+%type <subgraph> selector_token
+%type <subgraph> selector_token_seq
+%type <subgraph> selector_seq_seq
+%type <subgraph> compound_token
+
+%code {
+ /* bison declarations */
+ void
+ yyerror (struct graph *, struct cmd_element *el, char const *msg);
+
+ /* subgraph semantic value */
+ struct subgraph {
+ struct graph_node *start, *end;
+ };
+
+ struct graph_node *currnode, *startnode;
+
+ /* pointers to copy of command docstring */
+ char *docstr_start, *docstr;
+
+ /* helper functions for parser */
+ static char *
+ doc_next (void);
+
+ static struct graph_node *
+ node_adjacent (struct graph_node *, struct graph_node *);
+
+ static struct graph_node *
+ add_edge_dedup (struct graph_node *, struct graph_node *);
+
+ static int
+ cmp_token (struct cmd_token *, struct cmd_token *);
+
+ static struct graph_node *
+ new_token_node (struct graph *,
+ enum cmd_token_type type,
+ char *text, char *doc);
+
+ static void
+ terminate_graph (struct graph *,
+ struct graph_node *,
+ struct cmd_element *);
+
+ static void
+ cleanup (void);
+}
+
+/* yyparse parameters */
+%parse-param { struct graph *graph }
+%parse-param { struct cmd_element *element }
+
+/* called automatically before yyparse */
+%initial-action {
+ /* clear state pointers */
+ currnode = startnode = NULL;
+
+ startnode = vector_slot (graph->nodes, 0);
+
+ /* set string to parse */
+ set_lexer_string (element->string);
+
+ /* copy docstring and keep a pointer to the copy */
+ docstr = element->doc ? strdup(element->doc) : NULL;
+ docstr_start = docstr;
+}
+
+%%
+
+start:
+ sentence_root cmd_token_seq
+{
+ // tack on the command element
+ terminate_graph (graph, currnode, element);
+}
+| sentence_root cmd_token_seq placeholder_token '.' '.' '.'
+{
+ if ((currnode = add_edge_dedup (currnode, $3)) != $3)
+ graph_delete_node (graph, $3);
+
+ // adding a node as a child of itself accepts any number
+ // of the same token, which is what we want for varags
+ add_edge_dedup (currnode, currnode);
+
+ // tack on the command element
+ terminate_graph (graph, currnode, element);
+}
+;
+
+sentence_root: WORD
+{
+ struct graph_node *root =
+ new_token_node (graph, WORD_TKN, strdup ($1), doc_next());
+
+ if ((currnode = add_edge_dedup (startnode, root)) != root)
+ graph_delete_node (graph, root);
+
+ free ($1);
+ $$ = currnode;
+}
+;
+
+cmd_token_seq:
+ %empty
+| cmd_token_seq cmd_token
+;
+
+cmd_token:
+ simple_token
+{
+ if ((currnode = add_edge_dedup (currnode, $1)) != $1)
+ graph_delete_node (graph, $1);
+}
+| compound_token
+{
+ graph_add_edge (currnode, $1->start);
+ currnode = $1->end;
+ free ($1);
+}
+;
+
+simple_token:
+ literal_token
+| placeholder_token
+;
+
+compound_token:
+ selector
+| option
+;
+
+literal_token: WORD
+{
+ $$ = new_token_node (graph, WORD_TKN, strdup($1), doc_next());
+ free ($1);
+}
+;
+
+placeholder_token:
+ IPV4
+{
+ $$ = new_token_node (graph, IPV4_TKN, strdup($1), doc_next());
+ free ($1);
+}
+| IPV4_PREFIX
+{
+ $$ = new_token_node (graph, IPV4_PREFIX_TKN, strdup($1), doc_next());
+ free ($1);
+}
+| IPV6
+{
+ $$ = new_token_node (graph, IPV6_TKN, strdup($1), doc_next());
+ free ($1);
+}
+| IPV6_PREFIX
+{
+ $$ = new_token_node (graph, IPV6_PREFIX_TKN, strdup($1), doc_next());
+ free ($1);
+}
+| VARIABLE
+{
+ $$ = new_token_node (graph, VARIABLE_TKN, strdup($1), doc_next());
+ free ($1);
+}
+| RANGE
+{
+ $$ = new_token_node (graph, RANGE_TKN, strdup($1), doc_next());
+ struct cmd_token *token = $$->data;
+
+ // get the numbers out
+ yylval.string++;
+ token->min = strtoll (yylval.string, &yylval.string, 10);
+ strsep (&yylval.string, "-");
+ token->max = strtoll (yylval.string, &yylval.string, 10);
+
+ // validate range
+ if (token->min > token->max) yyerror (graph, element, "Invalid range.");
+
+ free ($1);
+}
+
+/* <selector|set> productions */
+selector: '<' selector_seq_seq '>'
+{
+ $$ = malloc (sizeof (struct subgraph));
+ $$->start = new_token_node (graph, SELECTOR_TKN, NULL, NULL);
+ $$->end = new_token_node (graph, NUL_TKN, NULL, NULL);
+ for (unsigned int i = 0; i < vector_active ($2->start->to); i++)
+ {
+ struct graph_node *sn = vector_slot ($2->start->to, i),
+ *en = vector_slot ($2->end->from, i);
+ graph_add_edge ($$->start, sn);
+ graph_add_edge (en, $$->end);
+ }
+ graph_delete_node (graph, $2->start);
+ graph_delete_node (graph, $2->end);
+ free ($2);
+};
+
+selector_seq_seq:
+ selector_seq_seq '|' selector_token_seq
+{
+ $$ = malloc (sizeof (struct subgraph));
+ $$->start = graph_new_node (graph, NULL, NULL);
+ $$->end = graph_new_node (graph, NULL, NULL);
+
+ // link in last sequence
+ graph_add_edge ($$->start, $3->start);
+ graph_add_edge ($3->end, $$->end);
+
+ for (unsigned int i = 0; i < vector_active ($1->start->to); i++)
+ {
+ struct graph_node *sn = vector_slot ($1->start->to, i),
+ *en = vector_slot ($1->end->from, i);
+ graph_add_edge ($$->start, sn);
+ graph_add_edge (en, $$->end);
+ }
+ graph_delete_node (graph, $1->start);
+ graph_delete_node (graph, $1->end);
+ free ($1);
+ free ($3);
+}
+| selector_token_seq '|' selector_token_seq
+{
+ $$ = malloc (sizeof (struct subgraph));
+ $$->start = graph_new_node (graph, NULL, NULL);
+ $$->end = graph_new_node (graph, NULL, NULL);
+ graph_add_edge ($$->start, $1->start);
+ graph_add_edge ($1->end, $$->end);
+ graph_add_edge ($$->start, $3->start);
+ graph_add_edge ($3->end, $$->end);
+ free ($1);
+ free ($3);
+}
+;
+
+selector_token_seq:
+ simple_token
+{
+ $$ = malloc (sizeof (struct subgraph));
+ $$->start = $$->end = $1;
+}
+| selector_token_seq selector_token
+{
+ $$ = malloc (sizeof (struct subgraph));
+ graph_add_edge ($1->end, $2->start);
+ $$->start = $1->start;
+ $$->end = $2->end;
+ free ($1);
+ free ($2);
+}
+;
+
+selector_token:
+ simple_token
+{
+ $$ = malloc (sizeof (struct subgraph));
+ $$->start = $$->end = $1;
+}
+| option
+| selector
+;
+
+/* [option] productions */
+option: '[' option_token_seq ']'
+{
+ // make a new option
+ $$ = malloc (sizeof (struct subgraph));
+ $$->start = new_token_node (graph, OPTION_TKN, NULL, NULL);
+ $$->end = new_token_node (graph, NUL_TKN, NULL, NULL);
+ // add a path through the sequence to the end
+ graph_add_edge ($$->start, $2->start);
+ graph_add_edge ($2->end, $$->end);
+ // add a path directly from the start to the end
+ graph_add_edge ($$->start, $$->end);
+ free ($2);
+}
+;
+
+option_token_seq:
+ option_token
+| option_token_seq option_token
+{
+ $$ = malloc (sizeof (struct subgraph));
+ graph_add_edge ($1->end, $2->start);
+ $$->start = $1->start;
+ $$->end = $2->end;
+ free ($1);
+}
+;
+
+option_token:
+ simple_token
+{
+ $$ = malloc (sizeof (struct subgraph));
+ $$->start = $$->end = $1;
+}
+| compound_token
+;
+
+%%
+
+void
+command_parse_format (struct graph *graph, struct cmd_element *cmd)
+{
+ // set to 1 to enable parser traces
+ yydebug = 0;
+
+ // parse command into DFA
+ yyparse (graph, cmd);
+
+ // cleanup
+ cleanup ();
+}
+
+/* parser helper functions */
+
+void
+yyerror (struct graph *graph, struct cmd_element *el, char const *msg)
+{
+ zlog_err ("%s: FATAL parse error: %s", __func__, msg);
+ zlog_err ("while parsing this command definition: \n\t%s\n", el->string);
+ //exit(EXIT_FAILURE);
+}
+
+static void
+cleanup()
+{
+ /* free resources */
+ free (docstr_start);
+
+ /* cleanup lexer */
+ cleanup_lexer ();
+
+ /* clear state pointers */
+ currnode = NULL;
+ docstr_start = docstr = NULL;
+}
+
+static void
+terminate_graph (struct graph *graph, struct graph_node *finalnode, struct cmd_element *element)
+{
+ // end of graph should look like this
+ // * -> finalnode -> END_TKN -> cmd_element
+ struct graph_node *end_token_node =
+ new_token_node (graph,
+ END_TKN,
+ strdup (CMD_CR_TEXT),
+ strdup (""));
+ struct graph_node *end_element_node =
+ graph_new_node (graph, element, (void (*)(void *)) &del_cmd_element);
+
+ if (node_adjacent (finalnode, end_token_node))
+ yyerror (graph, element, "Duplicate command.");
+
+ graph_add_edge (finalnode, end_token_node);
+ graph_add_edge (end_token_node, end_element_node);
+}
+
+static char *
+doc_next()
+{
+ char *piece = NULL;
+ if (!docstr || !(piece = strsep (&docstr, "\n")))
+ return strdup ("");
+ return strdup (piece);
+}
+
+static struct graph_node *
+new_token_node (struct graph *graph, enum cmd_token_type type, char *text, char *doc)
+{
+ struct cmd_token *token = new_cmd_token (type, text, doc);
+ return graph_new_node (graph, token, (void (*)(void *)) &del_cmd_token);
+}
+
+/**
+ * Determines if there is an out edge from the first node to the second
+ */
+static struct graph_node *
+node_adjacent (struct graph_node *first, struct graph_node *second)
+{
+ struct graph_node *adj;
+ for (unsigned int i = 0; i < vector_active (first->to); i++)
+ {
+ adj = vector_slot (first->to, i);
+ struct cmd_token *ftok = adj->data,
+ *stok = second->data;
+ if (cmp_token (ftok, stok))
+ return adj;
+ }
+ return NULL;
+}
+
+/**
+ * Creates an edge betwen two nodes, unless there is already an edge to an
+ * equivalent node.
+ *
+ * The first node's out edges are searched to see if any of them point to a
+ * node that is equivalent to the second node. If such a node exists, it is
+ * returned. Otherwise an edge is created from the first node to the second.
+ *
+ * @param from start node for edge
+ * @param to end node for edge
+ * @return the node which the new edge points to
+ */
+static struct graph_node *
+add_edge_dedup (struct graph_node *from, struct graph_node *to)
+{
+ struct graph_node *existing = node_adjacent (from, to);
+ return existing ? existing : graph_add_edge (from, to);
+}
+
+/**
+ * Compares two cmd_token's for equality,
+ *
+ * As such, this function is the working definition of token equality
+ * for parsing purposes and determines overall graph structure.
+ */
+static int
+cmp_token (struct cmd_token *first, struct cmd_token *second)
+{
+ // compare types
+ if (first->type != second->type) return 0;
+
+ switch (first->type) {
+ case WORD_TKN:
+ case VARIABLE_TKN:
+ if (first->text && second->text)
+ {
+ if (strcmp (first->text, second->text))
+ return 0;
+ }
+ else if (first->text != second->text) return 0;
+ break;
+ case RANGE_TKN:
+ if (first->min != second->min || first->max != second->max)
+ return 0;
+ break;
+ /* selectors and options should be equal if their subgraphs are equal,
+ * but the graph isomorphism problem is not known to be solvable in
+ * polynomial time so we consider selectors and options inequal in all
+ * cases; ultimately this forks the graph, but the matcher can handle
+ * this regardless
+ */
+ case SELECTOR_TKN:
+ case OPTION_TKN:
+ return 0;
+
+ /* end nodes are always considered equal, since each node may only
+ * have one END_TKN child at a time
+ */
+ case START_TKN:
+ case END_TKN:
+ case NUL_TKN:
+ default:
+ break;
+ }
+ return 1;
+}
diff --git a/lib/distribute.c b/lib/distribute.c
index 498410c22d..8726e993c5 100644
--- a/lib/distribute.c
+++ b/lib/distribute.c
@@ -161,8 +161,8 @@ distribute_cmp (const struct distribute *dist1, const struct distribute *dist2)
}
/* Set access-list name to the distribute list. */
-static struct distribute *
-distribute_list_set (const char *ifname, enum distribute_type type,
+static void
+distribute_list_set (const char *ifname, enum distribute_type type,
const char *alist_name)
{
struct distribute *dist;
@@ -175,14 +175,12 @@ distribute_list_set (const char *ifname, enum distribute_type type,
/* Apply this distribute-list to the interface. */
(*distribute_add_hook) (dist);
-
- return dist;
}
/* Unset distribute-list. If matched distribute-list exist then
return 1. */
static int
-distribute_list_unset (const char *ifname, enum distribute_type type,
+distribute_list_unset (const char *ifname, enum distribute_type type,
const char *alist_name)
{
struct distribute *dist;
@@ -192,9 +190,9 @@ distribute_list_unset (const char *ifname, enum distribute_type type,
return 0;
if (!dist->list[type])
- return 0;
+ return 0;
if (strcmp (dist->list[type], alist_name) != 0)
- return 0;
+ return 0;
XFREE(MTYPE_DISTRIBUTE_NAME, dist->list[type]);
dist->list[type] = NULL;
@@ -208,7 +206,7 @@ distribute_list_unset (const char *ifname, enum distribute_type type,
}
/* Set access-list name to the distribute list. */
-static struct distribute *
+static void
distribute_list_prefix_set (const char *ifname, enum distribute_type type,
const char *plist_name)
{
@@ -222,8 +220,6 @@ distribute_list_prefix_set (const char *ifname, enum distribute_type type,
/* Apply this distribute-list to the interface. */
(*distribute_add_hook) (dist);
-
- return dist;
}
/* Unset distribute-list. If matched distribute-list exist then
@@ -239,9 +235,9 @@ distribute_list_prefix_unset (const char *ifname, enum distribute_type type,
return 0;
if (!dist->prefix[type])
- return 0;
+ return 0;
if (strcmp (dist->prefix[type], plist_name) != 0)
- return 0;
+ return 0;
XFREE(MTYPE_DISTRIBUTE_NAME, dist->prefix[type]);
dist->prefix[type] = NULL;
@@ -254,212 +250,70 @@ distribute_list_prefix_unset (const char *ifname, enum distribute_type type,
return 1;
}
-DEFUN (distribute_list_all,
- distribute_list_all_cmd,
- "distribute-list WORD (in|out)",
- "Filter networks in routing updates\n"
- "Access-list name\n"
- "Filter incoming routing updates\n"
- "Filter outgoing routing updates\n")
-{
- enum distribute_type type;
-
- /* Check of distribute list type. */
- if (strncmp (argv[1], "i", 1) == 0)
- type = DISTRIBUTE_V4_IN;
- else if (strncmp (argv[1], "o", 1) == 0)
- type = DISTRIBUTE_V4_OUT;
- else
- {
- vty_out (vty, "distribute list direction must be [in|out]%s",
- VTY_NEWLINE);
- return CMD_WARNING;
- }
-
- /* Get interface name corresponding distribute list. */
- distribute_list_set (NULL, type, argv[0]);
-
- return CMD_SUCCESS;
-}
-
-DEFUN (ipv6_distribute_list_all,
- ipv6_distribute_list_all_cmd,
- "ipv6 distribute-list WORD (in|out)",
- "Filter networks in routing updates\n"
- "Access-list name\n"
- "Filter incoming routing updates\n"
- "Filter outgoing routing updates\n")
-{
- enum distribute_type type;
-
- /* Check of distribute list type. */
- if (strncmp (argv[1], "i", 1) == 0)
- type = DISTRIBUTE_V6_IN;
- else if (strncmp (argv[1], "o", 1) == 0)
- type = DISTRIBUTE_V6_OUT;
- else
- {
- vty_out (vty, "distribute list direction must be [in|out]%s",
- VTY_NEWLINE);
- return CMD_WARNING;
- }
-
- /* Get interface name corresponding distribute list. */
- distribute_list_set (NULL, type, argv[0]);
-
- return CMD_SUCCESS;
-}
-
-ALIAS (ipv6_distribute_list_all,
- ipv6_as_v4_distribute_list_all_cmd,
- "distribute-list WORD (in|out)",
- "Filter networks in routing updates\n"
- "Access-list name\n"
- "Filter incoming routing updates\n"
- "Filter outgoing routing updates\n")
-
-DEFUN (no_distribute_list_all,
- no_distribute_list_all_cmd,
- "no distribute-list WORD (in|out)",
- NO_STR
- "Filter networks in routing updates\n"
- "Access-list name\n"
- "Filter incoming routing updates\n"
- "Filter outgoing routing updates\n")
-{
- int ret;
- enum distribute_type type;
-
- /* Check of distribute list type. */
- if (strncmp (argv[1], "i", 1) == 0)
- type = DISTRIBUTE_V4_IN;
- else if (strncmp (argv[1], "o", 1) == 0)
- type = DISTRIBUTE_V4_OUT;
- else
- {
- vty_out (vty, "distribute list direction must be [in|out]%s",
- VTY_NEWLINE);
- return CMD_WARNING;
- }
-
- ret = distribute_list_unset (NULL, type, argv[0]);
- if (! ret)
- {
- vty_out (vty, "distribute list doesn't exist%s", VTY_NEWLINE);
- return CMD_WARNING;
- }
- return CMD_SUCCESS;
-}
-
-DEFUN (no_ipv6_distribute_list_all,
- no_ipv6_distribute_list_all_cmd,
- "no ipv6 distribute-list WORD (in|out)",
- NO_STR
- "Filter networks in routing updates\n"
- "Access-list name\n"
- "Filter incoming routing updates\n"
- "Filter outgoing routing updates\n")
-{
- int ret;
- enum distribute_type type;
-
- /* Check of distribute list type. */
- if (strncmp (argv[1], "i", 1) == 0)
- type = DISTRIBUTE_V6_IN;
- else if (strncmp (argv[1], "o", 1) == 0)
- type = DISTRIBUTE_V6_OUT;
- else
- {
- vty_out (vty, "distribute list direction must be [in|out]%s",
- VTY_NEWLINE);
- return CMD_WARNING;
- }
-
- ret = distribute_list_unset (NULL, type, argv[0]);
- if (! ret)
- {
- vty_out (vty, "distribute list doesn't exist%s", VTY_NEWLINE);
- return CMD_WARNING;
- }
- return CMD_SUCCESS;
-}
-
-ALIAS (no_ipv6_distribute_list_all,
- no_ipv6_as_v4_distribute_list_all_cmd,
- "no distribute-list WORD (in|out)",
- NO_STR
- "Filter networks in routing updates\n"
- "Access-list name\n"
- "Filter incoming routing updates\n"
- "Filter outgoing routing updates\n")
-
DEFUN (distribute_list,
distribute_list_cmd,
- "distribute-list WORD (in|out) WORD",
+ "distribute-list [prefix] WORD <in|out> [WORD]",
"Filter networks in routing updates\n"
"Access-list name\n"
"Filter incoming routing updates\n"
"Filter outgoing routing updates\n"
"Interface name\n")
{
- enum distribute_type type;
+ int prefix = (argv[1]->type == WORD_TKN) ? 1 : 0;
/* Check of distribute list type. */
- if (strncmp (argv[1], "i", 1) == 0)
- type = DISTRIBUTE_V4_IN;
- else if (strncmp (argv[1], "o", 1) == 0)
- type = DISTRIBUTE_V4_OUT;
- else
- {
- vty_out (vty, "distribute list direction must be [in|out]%s", VTY_NEWLINE);
- return CMD_WARNING;
- }
+ enum distribute_type type = argv[2 + prefix]->arg[0] == 'i' ?
+ DISTRIBUTE_V4_IN : DISTRIBUTE_V4_OUT;
+
+ /* Set appropriate function call */
+ void (*distfn)(const char *, enum distribute_type, const char *) = prefix ?
+ &distribute_list_prefix_set : &distribute_list_set;
+
+ /* if interface is present, get name */
+ const char *ifname = NULL;
+ if (argv[argc - 1]->type == VARIABLE_TKN)
+ ifname = argv[argc - 1]->arg;
/* Get interface name corresponding distribute list. */
- distribute_list_set (argv[2], type, argv[0]);
+ distfn (ifname, type, argv[1 + prefix]->arg);
return CMD_SUCCESS;
}
DEFUN (ipv6_distribute_list,
ipv6_distribute_list_cmd,
- "ipv6 distribute-list WORD (in|out) WORD",
+ "ipv6 distribute-list [prefix] WORD <in|out> [WORD]",
+ "IPv6\n"
"Filter networks in routing updates\n"
"Access-list name\n"
"Filter incoming routing updates\n"
"Filter outgoing routing updates\n"
"Interface name\n")
{
- enum distribute_type type;
+ int prefix = (argv[2]->type == WORD_TKN) ? 1 : 0;
/* Check of distribute list type. */
- if (strncmp (argv[1], "i", 1) == 0)
- type = DISTRIBUTE_V6_IN;
- else if (strncmp (argv[1], "o", 1) == 0)
- type = DISTRIBUTE_V6_OUT;
- else
- {
- vty_out (vty, "distribute list direction must be [in|out]%s", VTY_NEWLINE);
- return CMD_WARNING;
- }
+ enum distribute_type type = argv[3 + prefix]->arg[0] == 'i' ?
+ DISTRIBUTE_V6_IN : DISTRIBUTE_V6_OUT;
+
+ /* Set appropriate function call */
+ void (*distfn)(const char *, enum distribute_type, const char *) = prefix ?
+ &distribute_list_prefix_set : &distribute_list_set;
+
+ /* if interface is present, get name */
+ const char *ifname = NULL;
+ if (argv[argc - 1]->type == VARIABLE_TKN)
+ ifname = argv[argc - 1]->arg;
/* Get interface name corresponding distribute list. */
- distribute_list_set (argv[2], type, argv[0]);
+ distfn (ifname, type, argv[1 + prefix]->arg);
return CMD_SUCCESS;
}
-
-ALIAS (ipv6_distribute_list,
- ipv6_as_v4_distribute_list_cmd,
- "distribute-list WORD (in|out) WORD",
- "Filter networks in routing updates\n"
- "Access-list name\n"
- "Filter incoming routing updates\n"
- "Filter outgoing routing updates\n"
- "Interface name\n")
-
-DEFUN (no_distribute_list, no_distribute_list_cmd,
- "no distribute-list WORD (in|out) WORD",
+
+DEFUN (no_distribute_list,
+ no_distribute_list_cmd,
+ "no [ipv6] distribute-list [prefix] WORD <in|out> [WORD]",
NO_STR
"Filter networks in routing updates\n"
"Access-list name\n"
@@ -467,312 +321,29 @@ DEFUN (no_distribute_list, no_distribute_list_cmd,
"Filter outgoing routing updates\n"
"Interface name\n")
{
- int ret;
- enum distribute_type type;
-
- /* Check of distribute list type. */
- if (strncmp (argv[1], "i", 1) == 0)
- type = DISTRIBUTE_V4_IN;
- else if (strncmp (argv[1], "o", 1) == 0)
- type = DISTRIBUTE_V4_OUT;
- else
- {
- vty_out (vty, "distribute list direction must be [in|out]%s", VTY_NEWLINE);
- return CMD_WARNING;
- }
-
- ret = distribute_list_unset (argv[2], type, argv[0]);
- if (! ret)
- {
- vty_out (vty, "distribute list doesn't exist%s", VTY_NEWLINE);
- return CMD_WARNING;
- }
- return CMD_SUCCESS;
-}
+ int ipv6 = strmatch(argv[1]->text, "ipv6");
+ int prefix = (argv[2 + ipv6]->type == WORD_TKN) ? 1 : 0;
-DEFUN (no_ipv6_distribute_list,
- no_ipv6_distribute_list_cmd,
- "no ipv6 distribute-list WORD (in|out) WORD",
- NO_STR
- "Filter networks in routing updates\n"
- "Access-list name\n"
- "Filter incoming routing updates\n"
- "Filter outgoing routing updates\n"
- "Interface name\n")
-{
- int ret;
- enum distribute_type type;
+ int idx_alname = 2 + ipv6 + prefix;
+ int idx_disttype = idx_alname + 1;
/* Check of distribute list type. */
- if (strncmp (argv[1], "i", 1) == 0)
- type = DISTRIBUTE_V6_IN;
- else if (strncmp (argv[1], "o", 1) == 0)
- type = DISTRIBUTE_V6_OUT;
- else
- {
- vty_out (vty, "distribute list direction must be [in|out]%s", VTY_NEWLINE);
- return CMD_WARNING;
- }
+ enum distribute_type distin = (ipv6) ? DISTRIBUTE_V6_IN : DISTRIBUTE_V4_IN;
+ enum distribute_type distout = (ipv6) ? DISTRIBUTE_V6_OUT : DISTRIBUTE_V4_OUT;
- ret = distribute_list_unset (argv[2], type, argv[0]);
- if (! ret)
- {
- vty_out (vty, "distribute list doesn't exist%s", VTY_NEWLINE);
- return CMD_WARNING;
- }
- return CMD_SUCCESS;
-}
-
-ALIAS (no_ipv6_distribute_list,
- no_ipv6_as_v4_distribute_list_cmd,
- "no distribute-list WORD (in|out) WORD",
- NO_STR
- "Filter networks in routing updates\n"
- "Access-list name\n"
- "Filter incoming routing updates\n"
- "Filter outgoing routing updates\n"
- "Interface name\n")
-
-DEFUN (distribute_list_prefix_all,
- distribute_list_prefix_all_cmd,
- "distribute-list prefix WORD (in|out)",
- "Filter networks in routing updates\n"
- "Filter prefixes in routing updates\n"
- "Name of an IP prefix-list\n"
- "Filter incoming routing updates\n"
- "Filter outgoing routing updates\n")
-{
- enum distribute_type type;
-
- /* Check of distribute list type. */
- if (strncmp (argv[1], "i", 1) == 0)
- type = DISTRIBUTE_V4_IN;
- else if (strncmp (argv[1], "o", 1) == 0)
- type = DISTRIBUTE_V4_OUT;
- else
- {
- vty_out (vty, "distribute list direction must be [in|out]%s",
- VTY_NEWLINE);
- return CMD_WARNING;
- }
-
- /* Get interface name corresponding distribute list. */
- distribute_list_prefix_set (NULL, type, argv[0]);
-
- return CMD_SUCCESS;
-}
-
-DEFUN (ipv6_distribute_list_prefix_all,
- ipv6_distribute_list_prefix_all_cmd,
- "ipv6 distribute-list prefix WORD (in|out)",
- "Filter networks in routing updates\n"
- "Filter prefixes in routing updates\n"
- "Name of an IP prefix-list\n"
- "Filter incoming routing updates\n"
- "Filter outgoing routing updates\n")
-{
- enum distribute_type type;
-
- /* Check of distribute list type. */
- if (strncmp (argv[1], "i", 1) == 0)
- type = DISTRIBUTE_V6_IN;
- else if (strncmp (argv[1], "o", 1) == 0)
- type = DISTRIBUTE_V6_OUT;
- else
- {
- vty_out (vty, "distribute list direction must be [in|out]%s",
- VTY_NEWLINE);
- return CMD_WARNING;
- }
-
- /* Get interface name corresponding distribute list. */
- distribute_list_prefix_set (NULL, type, argv[0]);
-
- return CMD_SUCCESS;
-}
-
-ALIAS (ipv6_distribute_list_prefix_all,
- ipv6_as_v4_distribute_list_prefix_all_cmd,
- "distribute-list prefix WORD (in|out)",
- "Filter networks in routing updates\n"
- "Filter prefixes in routing updates\n"
- "Name of an IP prefix-list\n"
- "Filter incoming routing updates\n"
- "Filter outgoing routing updates\n")
-
-DEFUN (no_distribute_list_prefix_all,
- no_distribute_list_prefix_all_cmd,
- "no distribute-list prefix WORD (in|out)",
- NO_STR
- "Filter networks in routing updates\n"
- "Filter prefixes in routing updates\n"
- "Name of an IP prefix-list\n"
- "Filter incoming routing updates\n"
- "Filter outgoing routing updates\n")
-{
- int ret;
- enum distribute_type type;
-
- /* Check of distribute list type. */
- if (strncmp (argv[1], "i", 1) == 0)
- type = DISTRIBUTE_V4_IN;
- else if (strncmp (argv[1], "o", 1) == 0)
- type = DISTRIBUTE_V4_OUT;
- else
- {
- vty_out (vty, "distribute list direction must be [in|out]%s",
- VTY_NEWLINE);
- return CMD_WARNING;
- }
-
- ret = distribute_list_prefix_unset (NULL, type, argv[0]);
- if (! ret)
- {
- vty_out (vty, "distribute list doesn't exist%s", VTY_NEWLINE);
- return CMD_WARNING;
- }
- return CMD_SUCCESS;
-}
-
-DEFUN (no_ipv6_distribute_list_prefix_all,
- no_ipv6_distribute_list_prefix_all_cmd,
- "no ipv6 distribute-list prefix WORD (in|out)",
- NO_STR
- "Filter networks in routing updates\n"
- "Filter prefixes in routing updates\n"
- "Name of an IP prefix-list\n"
- "Filter incoming routing updates\n"
- "Filter outgoing routing updates\n")
-{
- int ret;
- enum distribute_type type;
-
- /* Check of distribute list type. */
- if (strncmp (argv[1], "i", 1) == 0)
- type = DISTRIBUTE_V6_IN;
- else if (strncmp (argv[1], "o", 1) == 0)
- type = DISTRIBUTE_V6_OUT;
- else
- {
- vty_out (vty, "distribute list direction must be [in|out]%s",
- VTY_NEWLINE);
- return CMD_WARNING;
- }
-
- ret = distribute_list_prefix_unset (NULL, type, argv[0]);
- if (! ret)
- {
- vty_out (vty, "distribute list doesn't exist%s", VTY_NEWLINE);
- return CMD_WARNING;
- }
- return CMD_SUCCESS;
-}
-
-ALIAS (no_ipv6_distribute_list_prefix_all,
- no_ipv6_as_v4_distribute_list_prefix_all_cmd,
- "no distribute-list prefix WORD (in|out)",
- NO_STR
- "Filter networks in routing updates\n"
- "Filter prefixes in routing updates\n"
- "Name of an IP prefix-list\n"
- "Filter incoming routing updates\n"
- "Filter outgoing routing updates\n")
-
-DEFUN (distribute_list_prefix, distribute_list_prefix_cmd,
- "distribute-list prefix WORD (in|out) WORD",
- "Filter networks in routing updates\n"
- "Filter prefixes in routing updates\n"
- "Name of an IP prefix-list\n"
- "Filter incoming routing updates\n"
- "Filter outgoing routing updates\n"
- "Interface name\n")
-{
- enum distribute_type type;
-
- /* Check of distribute list type. */
- if (strncmp (argv[1], "i", 1) == 0)
- type = DISTRIBUTE_V4_IN;
- else if (strncmp (argv[1], "o", 1) == 0)
- type = DISTRIBUTE_V4_OUT;
- else
- {
- vty_out (vty, "distribute list direction must be [in|out]%s",
- VTY_NEWLINE);
- return CMD_WARNING;
- }
-
- /* Get interface name corresponding distribute list. */
- distribute_list_prefix_set (argv[2], type, argv[0]);
-
- return CMD_SUCCESS;
-}
-
-DEFUN (ipv6_distribute_list_prefix,
- ipv6_distribute_list_prefix_cmd,
- "ipv6 distribute-list prefix WORD (in|out) WORD",
- "Filter networks in routing updates\n"
- "Filter prefixes in routing updates\n"
- "Name of an IP prefix-list\n"
- "Filter incoming routing updates\n"
- "Filter outgoing routing updates\n"
- "Interface name\n")
-{
- enum distribute_type type;
-
- /* Check of distribute list type. */
- if (strncmp (argv[1], "i", 1) == 0)
- type = DISTRIBUTE_V6_IN;
- else if (strncmp (argv[1], "o", 1) == 0)
- type = DISTRIBUTE_V6_OUT;
- else
- {
- vty_out (vty, "distribute list direction must be [in|out]%s",
- VTY_NEWLINE);
- return CMD_WARNING;
- }
+ enum distribute_type type = argv[idx_disttype]->arg[0] == 'i' ? distin : distout;
+ /* Set appropriate function call */
+ int (*distfn)(const char *, enum distribute_type, const char *) = prefix ?
+ &distribute_list_prefix_unset : &distribute_list_unset;
+
+ /* if interface is present, get name */
+ const char *ifname = NULL;
+ if (argv[argc - 1]->type == VARIABLE_TKN)
+ ifname = argv[argc - 1]->arg;
/* Get interface name corresponding distribute list. */
- distribute_list_prefix_set (argv[2], type, argv[0]);
-
- return CMD_SUCCESS;
-}
-
-ALIAS (ipv6_distribute_list_prefix,
- ipv6_as_v4_distribute_list_prefix_cmd,
- "distribute-list prefix WORD (in|out) WORD",
- "Filter networks in routing updates\n"
- "Filter prefixes in routing updates\n"
- "Name of an IP prefix-list\n"
- "Filter incoming routing updates\n"
- "Filter outgoing routing updates\n"
- "Interface name\n")
-
-DEFUN (no_distribute_list_prefix, no_distribute_list_prefix_cmd,
- "no distribute-list prefix WORD (in|out) WORD",
- NO_STR
- "Filter networks in routing updates\n"
- "Filter prefixes in routing updates\n"
- "Name of an IP prefix-list\n"
- "Filter incoming routing updates\n"
- "Filter outgoing routing updates\n"
- "Interface name\n")
-{
- int ret;
- enum distribute_type type;
+ int ret = distfn (ifname, type, argv[2 + prefix]->arg);
- /* Check of distribute list type. */
- if (strncmp (argv[1], "i", 1) == 0)
- type = DISTRIBUTE_V4_IN;
- else if (strncmp (argv[1], "o", 1) == 0)
- type = DISTRIBUTE_V4_OUT;
- else
- {
- vty_out (vty, "distribute list direction must be [in|out]%s",
- VTY_NEWLINE);
- return CMD_WARNING;
- }
-
- ret = distribute_list_prefix_unset (argv[2], type, argv[0]);
if (! ret)
{
vty_out (vty, "distribute list doesn't exist%s", VTY_NEWLINE);
@@ -781,52 +352,6 @@ DEFUN (no_distribute_list_prefix, no_distribute_list_prefix_cmd,
return CMD_SUCCESS;
}
-DEFUN (no_ipv6_distribute_list_prefix,
- no_ipv6_distribute_list_prefix_cmd,
- "no ipv6 distribute-list prefix WORD (in|out) WORD",
- NO_STR
- "Filter networks in routing updates\n"
- "Filter prefixes in routing updates\n"
- "Name of an IP prefix-list\n"
- "Filter incoming routing updates\n"
- "Filter outgoing routing updates\n"
- "Interface name\n")
-{
- int ret;
- enum distribute_type type;
-
- /* Check of distribute list type. */
- if (strncmp (argv[1], "i", 1) == 0)
- type = DISTRIBUTE_V6_IN;
- else if (strncmp (argv[1], "o", 1) == 0)
- type = DISTRIBUTE_V6_OUT;
- else
- {
- vty_out (vty, "distribute list direction must be [in|out]%s",
- VTY_NEWLINE);
- return CMD_WARNING;
- }
-
- ret = distribute_list_prefix_unset (argv[2], type, argv[0]);
- if (! ret)
- {
- vty_out (vty, "distribute list doesn't exist%s", VTY_NEWLINE);
- return CMD_WARNING;
- }
- return CMD_SUCCESS;
-}
-
-ALIAS (no_ipv6_distribute_list_prefix,
- no_ipv6_as_v4_distribute_list_prefix_cmd,
- "no distribute-list prefix WORD (in|out) WORD",
- NO_STR
- "Filter networks in routing updates\n"
- "Filter prefixes in routing updates\n"
- "Name of an IP prefix-list\n"
- "Filter incoming routing updates\n"
- "Filter outgoing routing updates\n"
- "Interface name\n")
-
static int
distribute_print (struct vty *vty, char *tab[], int is_prefix,
enum distribute_type type, int has_print)
@@ -851,7 +376,7 @@ config_show_distribute (struct vty *vty)
/* Output filter configuration. */
dist = distribute_lookup (NULL);
- vty_out(vty, " Outgoing update filter list for all interface is");
+ vty_out (vty, " Outgoing update filter list for all interface is");
has_print = 0;
if (dist)
{
@@ -874,8 +399,8 @@ config_show_distribute (struct vty *vty)
{
dist = mp->data;
if (dist->ifname)
- {
- vty_out (vty, " %s filtered by", dist->ifname);
+ {
+ vty_out (vty, " %s filtered by", dist->ifname);
has_print = 0;
has_print = distribute_print(vty, dist->list, 0,
DISTRIBUTE_V4_OUT, has_print);
@@ -886,16 +411,16 @@ config_show_distribute (struct vty *vty)
has_print = distribute_print(vty, dist->prefix, 1,
DISTRIBUTE_V6_OUT, has_print);
if (has_print)
- vty_out (vty, "%s", VTY_NEWLINE);
+ vty_out (vty, "%s", VTY_NEWLINE);
else
vty_out(vty, " nothing%s", VTY_NEWLINE);
- }
+ }
}
/* Input filter configuration. */
dist = distribute_lookup (NULL);
- vty_out(vty, " Incoming update filter list for all interface is");
+ vty_out (vty, " Incoming update filter list for all interface is");
has_print = 0;
if (dist)
{
@@ -917,9 +442,9 @@ config_show_distribute (struct vty *vty)
for (mp = disthash->index[i]; mp; mp = mp->next)
{
dist = mp->data;
- if (dist->ifname)
- {
- vty_out (vty, " %s filtered by", dist->ifname);
+ if (dist->ifname)
+ {
+ vty_out (vty, " %s filtered by", dist->ifname);
has_print = 0;
has_print = distribute_print(vty, dist->list, 0,
DISTRIBUTE_V4_IN, has_print);
@@ -930,10 +455,10 @@ config_show_distribute (struct vty *vty)
has_print = distribute_print(vty, dist->prefix, 1,
DISTRIBUTE_V6_IN, has_print);
if (has_print)
- vty_out (vty, "%s", VTY_NEWLINE);
+ vty_out (vty, "%s", VTY_NEWLINE);
else
vty_out(vty, " nothing%s", VTY_NEWLINE);
- }
+ }
}
return 0;
}
@@ -997,39 +522,24 @@ distribute_list_init (int node)
{
disthash = hash_create (distribute_hash_make,
(int (*) (const void *, const void *)) distribute_cmp);
- /* install v4 */
- if (node == RIP_NODE) {
- install_element (node, &distribute_list_all_cmd);
- install_element (node, &no_distribute_list_all_cmd);
- install_element (node, &distribute_list_cmd);
- install_element (node, &no_distribute_list_cmd);
- install_element (node, &distribute_list_prefix_all_cmd);
- install_element (node, &no_distribute_list_prefix_all_cmd);
- install_element (node, &distribute_list_prefix_cmd);
- install_element (node, &no_distribute_list_prefix_cmd);
- }
+
+ install_element (node, &distribute_list_cmd);
+ install_element (node, &no_distribute_list_cmd);
/* install v6 */
if (node == RIPNG_NODE) {
- install_element (node, &ipv6_distribute_list_all_cmd);
- install_element (node, &no_ipv6_distribute_list_all_cmd);
install_element (node, &ipv6_distribute_list_cmd);
- install_element (node, &no_ipv6_distribute_list_cmd);
- install_element (node, &ipv6_distribute_list_prefix_all_cmd);
- install_element (node, &no_ipv6_distribute_list_prefix_all_cmd);
- install_element (node, &ipv6_distribute_list_prefix_cmd);
- install_element (node, &no_ipv6_distribute_list_prefix_cmd);
}
- /* install v4 syntax command for v6 only protocols. */
- if (node == RIPNG_NODE) {
- install_element (node, &ipv6_as_v4_distribute_list_all_cmd);
- install_element (node, &no_ipv6_as_v4_distribute_list_all_cmd);
- install_element (node, &ipv6_as_v4_distribute_list_cmd);
- install_element (node, &no_ipv6_as_v4_distribute_list_cmd);
- install_element (node, &ipv6_as_v4_distribute_list_prefix_all_cmd);
- install_element (node, &no_ipv6_as_v4_distribute_list_prefix_all_cmd);
- install_element (node, &ipv6_as_v4_distribute_list_prefix_cmd);
- install_element (node, &no_ipv6_as_v4_distribute_list_prefix_cmd);
- }
+ /* TODO: install v4 syntax command for v6 only protocols. */
+ /* if (node == RIPNG_NODE) {
+ * install_element (node, &ipv6_as_v4_distribute_list_all_cmd);
+ * install_element (node, &no_ipv6_as_v4_distribute_list_all_cmd);
+ * install_element (node, &ipv6_as_v4_distribute_list_cmd);
+ * install_element (node, &no_ipv6_as_v4_distribute_list_cmd);
+ * install_element (node, &ipv6_as_v4_distribute_list_prefix_all_cmd);
+ * install_element (node, &no_ipv6_as_v4_distribute_list_prefix_all_cmd);
+ * install_element (node, &ipv6_as_v4_distribute_list_prefix_cmd);
+ * install_element (node, &no_ipv6_as_v4_distribute_list_prefix_cmd);
+ }*/
}
diff --git a/lib/filter.c b/lib/filter.c
index e9ba715c92..501b28f2da 100644
--- a/lib/filter.c
+++ b/lib/filter.c
@@ -704,7 +704,7 @@ filter_set_cisco (struct vty *vty, const char *name_str, const char *type_str,
/* Standard access-list */
DEFUN (access_list_standard,
access_list_standard_cmd,
- "access-list (<1-99>|<1300-1999>) (deny|permit) A.B.C.D A.B.C.D",
+ "access-list <(1-99)|(1300-1999)> <deny|permit> A.B.C.D A.B.C.D",
"Add an access list entry\n"
"IP standard access list\n"
"IP standard access list (expanded range)\n"
@@ -713,13 +713,17 @@ DEFUN (access_list_standard,
"Address to match\n"
"Wildcard bits\n")
{
- return filter_set_cisco (vty, argv[0], argv[1], argv[2], argv[3],
+ int idx_acl = 1;
+ int idx_permit_deny = 2;
+ int idx_ipv4 = 3;
+ int idx_ipv4_2 = 4;
+ return filter_set_cisco (vty, argv[idx_acl]->arg, argv[idx_permit_deny]->arg, argv[idx_ipv4]->arg, argv[idx_ipv4_2]->arg,
NULL, NULL, 0, 1);
}
DEFUN (access_list_standard_nomask,
access_list_standard_nomask_cmd,
- "access-list (<1-99>|<1300-1999>) (deny|permit) A.B.C.D",
+ "access-list <(1-99)|(1300-1999)> <deny|permit> A.B.C.D",
"Add an access list entry\n"
"IP standard access list\n"
"IP standard access list (expanded range)\n"
@@ -727,13 +731,16 @@ DEFUN (access_list_standard_nomask,
"Specify packets to forward\n"
"Address to match\n")
{
- return filter_set_cisco (vty, argv[0], argv[1], argv[2], "0.0.0.0",
+ int idx_acl = 1;
+ int idx_permit_deny = 2;
+ int idx_ipv4 = 3;
+ return filter_set_cisco (vty, argv[idx_acl]->arg, argv[idx_permit_deny]->arg, argv[idx_ipv4]->arg, "0.0.0.0",
NULL, NULL, 0, 1);
}
DEFUN (access_list_standard_host,
access_list_standard_host_cmd,
- "access-list (<1-99>|<1300-1999>) (deny|permit) host A.B.C.D",
+ "access-list <(1-99)|(1300-1999)> <deny|permit> host A.B.C.D",
"Add an access list entry\n"
"IP standard access list\n"
"IP standard access list (expanded range)\n"
@@ -742,13 +749,16 @@ DEFUN (access_list_standard_host,
"A single host address\n"
"Address to match\n")
{
- return filter_set_cisco (vty, argv[0], argv[1], argv[2], "0.0.0.0",
+ int idx_acl = 1;
+ int idx_permit_deny = 2;
+ int idx_ipv4 = 4;
+ return filter_set_cisco (vty, argv[idx_acl]->arg, argv[idx_permit_deny]->arg, argv[idx_ipv4]->arg, "0.0.0.0",
NULL, NULL, 0, 1);
}
DEFUN (access_list_standard_any,
access_list_standard_any_cmd,
- "access-list (<1-99>|<1300-1999>) (deny|permit) any",
+ "access-list <(1-99)|(1300-1999)> <deny|permit> any",
"Add an access list entry\n"
"IP standard access list\n"
"IP standard access list (expanded range)\n"
@@ -756,13 +766,15 @@ DEFUN (access_list_standard_any,
"Specify packets to forward\n"
"Any source host\n")
{
- return filter_set_cisco (vty, argv[0], argv[1], "0.0.0.0",
+ int idx_acl = 1;
+ int idx_permit_deny = 2;
+ return filter_set_cisco (vty, argv[idx_acl]->arg, argv[idx_permit_deny]->arg, "0.0.0.0",
"255.255.255.255", NULL, NULL, 0, 1);
}
DEFUN (no_access_list_standard,
no_access_list_standard_cmd,
- "no access-list (<1-99>|<1300-1999>) (deny|permit) A.B.C.D A.B.C.D",
+ "no access-list <(1-99)|(1300-1999)> <deny|permit> A.B.C.D A.B.C.D",
NO_STR
"Add an access list entry\n"
"IP standard access list\n"
@@ -772,13 +784,17 @@ DEFUN (no_access_list_standard,
"Address to match\n"
"Wildcard bits\n")
{
- return filter_set_cisco (vty, argv[0], argv[1], argv[2], argv[3],
+ int idx_acl = 2;
+ int idx_permit_deny = 3;
+ int idx_ipv4 = 4;
+ int idx_ipv4_2 = 5;
+ return filter_set_cisco (vty, argv[idx_acl]->arg, argv[idx_permit_deny]->arg, argv[idx_ipv4]->arg, argv[idx_ipv4_2]->arg,
NULL, NULL, 0, 0);
}
DEFUN (no_access_list_standard_nomask,
no_access_list_standard_nomask_cmd,
- "no access-list (<1-99>|<1300-1999>) (deny|permit) A.B.C.D",
+ "no access-list <(1-99)|(1300-1999)> <deny|permit> A.B.C.D",
NO_STR
"Add an access list entry\n"
"IP standard access list\n"
@@ -787,13 +803,16 @@ DEFUN (no_access_list_standard_nomask,
"Specify packets to forward\n"
"Address to match\n")
{
- return filter_set_cisco (vty, argv[0], argv[1], argv[2], "0.0.0.0",
+ int idx_acl = 2;
+ int idx_permit_deny = 3;
+ int idx_ipv4 = 4;
+ return filter_set_cisco (vty, argv[idx_acl]->arg, argv[idx_permit_deny]->arg, argv[idx_ipv4]->arg, "0.0.0.0",
NULL, NULL, 0, 0);
}
DEFUN (no_access_list_standard_host,
no_access_list_standard_host_cmd,
- "no access-list (<1-99>|<1300-1999>) (deny|permit) host A.B.C.D",
+ "no access-list <(1-99)|(1300-1999)> <deny|permit> host A.B.C.D",
NO_STR
"Add an access list entry\n"
"IP standard access list\n"
@@ -803,13 +822,16 @@ DEFUN (no_access_list_standard_host,
"A single host address\n"
"Address to match\n")
{
- return filter_set_cisco (vty, argv[0], argv[1], argv[2], "0.0.0.0",
+ int idx_acl = 2;
+ int idx_permit_deny = 3;
+ int idx_ipv4 = 5;
+ return filter_set_cisco (vty, argv[idx_acl]->arg, argv[idx_permit_deny]->arg, argv[idx_ipv4]->arg, "0.0.0.0",
NULL, NULL, 0, 0);
}
DEFUN (no_access_list_standard_any,
no_access_list_standard_any_cmd,
- "no access-list (<1-99>|<1300-1999>) (deny|permit) any",
+ "no access-list <(1-99)|(1300-1999)> <deny|permit> any",
NO_STR
"Add an access list entry\n"
"IP standard access list\n"
@@ -818,14 +840,16 @@ DEFUN (no_access_list_standard_any,
"Specify packets to forward\n"
"Any source host\n")
{
- return filter_set_cisco (vty, argv[0], argv[1], "0.0.0.0",
+ int idx_acl = 2;
+ int idx_permit_deny = 3;
+ return filter_set_cisco (vty, argv[idx_acl]->arg, argv[idx_permit_deny]->arg, "0.0.0.0",
"255.255.255.255", NULL, NULL, 0, 0);
}
/* Extended access-list */
DEFUN (access_list_extended,
access_list_extended_cmd,
- "access-list (<100-199>|<2000-2699>) (deny|permit) ip A.B.C.D A.B.C.D A.B.C.D A.B.C.D",
+ "access-list <(100-199)|(2000-2699)> <deny|permit> ip A.B.C.D A.B.C.D A.B.C.D A.B.C.D",
"Add an access list entry\n"
"IP extended access list\n"
"IP extended access list (expanded range)\n"
@@ -837,13 +861,19 @@ DEFUN (access_list_extended,
"Destination address\n"
"Destination Wildcard bits\n")
{
- return filter_set_cisco (vty, argv[0], argv[1], argv[2],
- argv[3], argv[4], argv[5], 1 ,1);
+ int idx_acl = 1;
+ int idx_permit_deny = 2;
+ int idx_ipv4 = 4;
+ int idx_ipv4_2 = 5;
+ int idx_ipv4_3 = 6;
+ int idx_ipv4_4 = 7;
+ return filter_set_cisco (vty, argv[idx_acl]->arg, argv[idx_permit_deny]->arg, argv[idx_ipv4]->arg,
+ argv[idx_ipv4_2]->arg, argv[idx_ipv4_3]->arg, argv[idx_ipv4_4]->arg, 1 ,1);
}
DEFUN (access_list_extended_mask_any,
access_list_extended_mask_any_cmd,
- "access-list (<100-199>|<2000-2699>) (deny|permit) ip A.B.C.D A.B.C.D any",
+ "access-list <(100-199)|(2000-2699)> <deny|permit> ip A.B.C.D A.B.C.D any",
"Add an access list entry\n"
"IP extended access list\n"
"IP extended access list (expanded range)\n"
@@ -854,14 +884,18 @@ DEFUN (access_list_extended_mask_any,
"Source wildcard bits\n"
"Any destination host\n")
{
- return filter_set_cisco (vty, argv[0], argv[1], argv[2],
- argv[3], "0.0.0.0",
+ int idx_acl = 1;
+ int idx_permit_deny = 2;
+ int idx_ipv4 = 4;
+ int idx_ipv4_2 = 5;
+ return filter_set_cisco (vty, argv[idx_acl]->arg, argv[idx_permit_deny]->arg, argv[idx_ipv4]->arg,
+ argv[idx_ipv4_2]->arg, "0.0.0.0",
"255.255.255.255", 1, 1);
}
DEFUN (access_list_extended_any_mask,
access_list_extended_any_mask_cmd,
- "access-list (<100-199>|<2000-2699>) (deny|permit) ip any A.B.C.D A.B.C.D",
+ "access-list <(100-199)|(2000-2699)> <deny|permit> ip any A.B.C.D A.B.C.D",
"Add an access list entry\n"
"IP extended access list\n"
"IP extended access list (expanded range)\n"
@@ -872,14 +906,18 @@ DEFUN (access_list_extended_any_mask,
"Destination address\n"
"Destination Wildcard bits\n")
{
- return filter_set_cisco (vty, argv[0], argv[1], "0.0.0.0",
- "255.255.255.255", argv[2],
- argv[3], 1, 1);
+ int idx_acl = 1;
+ int idx_permit_deny = 2;
+ int idx_ipv4 = 5;
+ int idx_ipv4_2 = 6;
+ return filter_set_cisco (vty, argv[idx_acl]->arg, argv[idx_permit_deny]->arg, "0.0.0.0",
+ "255.255.255.255", argv[idx_ipv4]->arg,
+ argv[idx_ipv4_2]->arg, 1, 1);
}
DEFUN (access_list_extended_any_any,
access_list_extended_any_any_cmd,
- "access-list (<100-199>|<2000-2699>) (deny|permit) ip any any",
+ "access-list <(100-199)|(2000-2699)> <deny|permit> ip any any",
"Add an access list entry\n"
"IP extended access list\n"
"IP extended access list (expanded range)\n"
@@ -889,14 +927,16 @@ DEFUN (access_list_extended_any_any,
"Any source host\n"
"Any destination host\n")
{
- return filter_set_cisco (vty, argv[0], argv[1], "0.0.0.0",
+ int idx_acl = 1;
+ int idx_permit_deny = 2;
+ return filter_set_cisco (vty, argv[idx_acl]->arg, argv[idx_permit_deny]->arg, "0.0.0.0",
"255.255.255.255", "0.0.0.0",
"255.255.255.255", 1, 1);
}
DEFUN (access_list_extended_mask_host,
access_list_extended_mask_host_cmd,
- "access-list (<100-199>|<2000-2699>) (deny|permit) ip A.B.C.D A.B.C.D host A.B.C.D",
+ "access-list <(100-199)|(2000-2699)> <deny|permit> ip A.B.C.D A.B.C.D host A.B.C.D",
"Add an access list entry\n"
"IP extended access list\n"
"IP extended access list (expanded range)\n"
@@ -908,14 +948,19 @@ DEFUN (access_list_extended_mask_host,
"A single destination host\n"
"Destination address\n")
{
- return filter_set_cisco (vty, argv[0], argv[1], argv[2],
- argv[3], argv[4],
+ int idx_acl = 1;
+ int idx_permit_deny = 2;
+ int idx_ipv4 = 4;
+ int idx_ipv4_2 = 5;
+ int idx_ipv4_3 = 7;
+ return filter_set_cisco (vty, argv[idx_acl]->arg, argv[idx_permit_deny]->arg, argv[idx_ipv4]->arg,
+ argv[idx_ipv4_2]->arg, argv[idx_ipv4_3]->arg,
"0.0.0.0", 1, 1);
}
DEFUN (access_list_extended_host_mask,
access_list_extended_host_mask_cmd,
- "access-list (<100-199>|<2000-2699>) (deny|permit) ip host A.B.C.D A.B.C.D A.B.C.D",
+ "access-list <(100-199)|(2000-2699)> <deny|permit> ip host A.B.C.D A.B.C.D A.B.C.D",
"Add an access list entry\n"
"IP extended access list\n"
"IP extended access list (expanded range)\n"
@@ -927,14 +972,19 @@ DEFUN (access_list_extended_host_mask,
"Destination address\n"
"Destination Wildcard bits\n")
{
- return filter_set_cisco (vty, argv[0], argv[1], argv[2],
- "0.0.0.0", argv[3],
- argv[4], 1, 1);
+ int idx_acl = 1;
+ int idx_permit_deny = 2;
+ int idx_ipv4 = 5;
+ int idx_ipv4_2 = 6;
+ int idx_ipv4_3 = 7;
+ return filter_set_cisco (vty, argv[idx_acl]->arg, argv[idx_permit_deny]->arg, argv[idx_ipv4]->arg,
+ "0.0.0.0", argv[idx_ipv4_2]->arg,
+ argv[idx_ipv4_3]->arg, 1, 1);
}
DEFUN (access_list_extended_host_host,
access_list_extended_host_host_cmd,
- "access-list (<100-199>|<2000-2699>) (deny|permit) ip host A.B.C.D host A.B.C.D",
+ "access-list <(100-199)|(2000-2699)> <deny|permit> ip host A.B.C.D host A.B.C.D",
"Add an access list entry\n"
"IP extended access list\n"
"IP extended access list (expanded range)\n"
@@ -946,14 +996,18 @@ DEFUN (access_list_extended_host_host,
"A single destination host\n"
"Destination address\n")
{
- return filter_set_cisco (vty, argv[0], argv[1], argv[2],
- "0.0.0.0", argv[3],
+ int idx_acl = 1;
+ int idx_permit_deny = 2;
+ int idx_ipv4 = 5;
+ int idx_ipv4_2 = 7;
+ return filter_set_cisco (vty, argv[idx_acl]->arg, argv[idx_permit_deny]->arg, argv[idx_ipv4]->arg,
+ "0.0.0.0", argv[idx_ipv4_2]->arg,
"0.0.0.0", 1, 1);
}
DEFUN (access_list_extended_any_host,
access_list_extended_any_host_cmd,
- "access-list (<100-199>|<2000-2699>) (deny|permit) ip any host A.B.C.D",
+ "access-list <(100-199)|(2000-2699)> <deny|permit> ip any host A.B.C.D",
"Add an access list entry\n"
"IP extended access list\n"
"IP extended access list (expanded range)\n"
@@ -964,14 +1018,17 @@ DEFUN (access_list_extended_any_host,
"A single destination host\n"
"Destination address\n")
{
- return filter_set_cisco (vty, argv[0], argv[1], "0.0.0.0",
- "255.255.255.255", argv[2],
+ int idx_acl = 1;
+ int idx_permit_deny = 2;
+ int idx_ipv4 = 6;
+ return filter_set_cisco (vty, argv[idx_acl]->arg, argv[idx_permit_deny]->arg, "0.0.0.0",
+ "255.255.255.255", argv[idx_ipv4]->arg,
"0.0.0.0", 1, 1);
}
DEFUN (access_list_extended_host_any,
access_list_extended_host_any_cmd,
- "access-list (<100-199>|<2000-2699>) (deny|permit) ip host A.B.C.D any",
+ "access-list <(100-199)|(2000-2699)> <deny|permit> ip host A.B.C.D any",
"Add an access list entry\n"
"IP extended access list\n"
"IP extended access list (expanded range)\n"
@@ -982,14 +1039,17 @@ DEFUN (access_list_extended_host_any,
"Source address\n"
"Any destination host\n")
{
- return filter_set_cisco (vty, argv[0], argv[1], argv[2],
+ int idx_acl = 1;
+ int idx_permit_deny = 2;
+ int idx_ipv4 = 5;
+ return filter_set_cisco (vty, argv[idx_acl]->arg, argv[idx_permit_deny]->arg, argv[idx_ipv4]->arg,
"0.0.0.0", "0.0.0.0",
"255.255.255.255", 1, 1);
}
DEFUN (no_access_list_extended,
no_access_list_extended_cmd,
- "no access-list (<100-199>|<2000-2699>) (deny|permit) ip A.B.C.D A.B.C.D A.B.C.D A.B.C.D",
+ "no access-list <(100-199)|(2000-2699)> <deny|permit> ip A.B.C.D A.B.C.D A.B.C.D A.B.C.D",
NO_STR
"Add an access list entry\n"
"IP extended access list\n"
@@ -1002,13 +1062,19 @@ DEFUN (no_access_list_extended,
"Destination address\n"
"Destination Wildcard bits\n")
{
- return filter_set_cisco (vty, argv[0], argv[1], argv[2],
- argv[3], argv[4], argv[5], 1, 0);
+ int idx_acl = 2;
+ int idx_permit_deny = 3;
+ int idx_ipv4 = 5;
+ int idx_ipv4_2 = 6;
+ int idx_ipv4_3 = 7;
+ int idx_ipv4_4 = 8;
+ return filter_set_cisco (vty, argv[idx_acl]->arg, argv[idx_permit_deny]->arg, argv[idx_ipv4]->arg,
+ argv[idx_ipv4_2]->arg, argv[idx_ipv4_3]->arg, argv[idx_ipv4_4]->arg, 1, 0);
}
DEFUN (no_access_list_extended_mask_any,
no_access_list_extended_mask_any_cmd,
- "no access-list (<100-199>|<2000-2699>) (deny|permit) ip A.B.C.D A.B.C.D any",
+ "no access-list <(100-199)|(2000-2699)> <deny|permit> ip A.B.C.D A.B.C.D any",
NO_STR
"Add an access list entry\n"
"IP extended access list\n"
@@ -1020,14 +1086,18 @@ DEFUN (no_access_list_extended_mask_any,
"Source wildcard bits\n"
"Any destination host\n")
{
- return filter_set_cisco (vty, argv[0], argv[1], argv[2],
- argv[3], "0.0.0.0",
+ int idx_acl = 2;
+ int idx_permit_deny = 3;
+ int idx_ipv4 = 5;
+ int idx_ipv4_2 = 6;
+ return filter_set_cisco (vty, argv[idx_acl]->arg, argv[idx_permit_deny]->arg, argv[idx_ipv4]->arg,
+ argv[idx_ipv4_2]->arg, "0.0.0.0",
"255.255.255.255", 1, 0);
}
DEFUN (no_access_list_extended_any_mask,
no_access_list_extended_any_mask_cmd,
- "no access-list (<100-199>|<2000-2699>) (deny|permit) ip any A.B.C.D A.B.C.D",
+ "no access-list <(100-199)|(2000-2699)> <deny|permit> ip any A.B.C.D A.B.C.D",
NO_STR
"Add an access list entry\n"
"IP extended access list\n"
@@ -1039,14 +1109,18 @@ DEFUN (no_access_list_extended_any_mask,
"Destination address\n"
"Destination Wildcard bits\n")
{
- return filter_set_cisco (vty, argv[0], argv[1], "0.0.0.0",
- "255.255.255.255", argv[2],
- argv[3], 1, 0);
+ int idx_acl = 2;
+ int idx_permit_deny = 3;
+ int idx_ipv4 = 6;
+ int idx_ipv4_2 = 7;
+ return filter_set_cisco (vty, argv[idx_acl]->arg, argv[idx_permit_deny]->arg, "0.0.0.0",
+ "255.255.255.255", argv[idx_ipv4]->arg,
+ argv[idx_ipv4_2]->arg, 1, 0);
}
DEFUN (no_access_list_extended_any_any,
no_access_list_extended_any_any_cmd,
- "no access-list (<100-199>|<2000-2699>) (deny|permit) ip any any",
+ "no access-list <(100-199)|(2000-2699)> <deny|permit> ip any any",
NO_STR
"Add an access list entry\n"
"IP extended access list\n"
@@ -1057,14 +1131,16 @@ DEFUN (no_access_list_extended_any_any,
"Any source host\n"
"Any destination host\n")
{
- return filter_set_cisco (vty, argv[0], argv[1], "0.0.0.0",
+ int idx_acl = 2;
+ int idx_permit_deny = 3;
+ return filter_set_cisco (vty, argv[idx_acl]->arg, argv[idx_permit_deny]->arg, "0.0.0.0",
"255.255.255.255", "0.0.0.0",
"255.255.255.255", 1, 0);
}
DEFUN (no_access_list_extended_mask_host,
no_access_list_extended_mask_host_cmd,
- "no access-list (<100-199>|<2000-2699>) (deny|permit) ip A.B.C.D A.B.C.D host A.B.C.D",
+ "no access-list <(100-199)|(2000-2699)> <deny|permit> ip A.B.C.D A.B.C.D host A.B.C.D",
NO_STR
"Add an access list entry\n"
"IP extended access list\n"
@@ -1077,14 +1153,19 @@ DEFUN (no_access_list_extended_mask_host,
"A single destination host\n"
"Destination address\n")
{
- return filter_set_cisco (vty, argv[0], argv[1], argv[2],
- argv[3], argv[4],
+ int idx_acl = 2;
+ int idx_permit_deny = 3;
+ int idx_ipv4 = 5;
+ int idx_ipv4_2 = 6;
+ int idx_ipv4_3 = 8;
+ return filter_set_cisco (vty, argv[idx_acl]->arg, argv[idx_permit_deny]->arg, argv[idx_ipv4]->arg,
+ argv[idx_ipv4_2]->arg, argv[idx_ipv4_3]->arg,
"0.0.0.0", 1, 0);
}
DEFUN (no_access_list_extended_host_mask,
no_access_list_extended_host_mask_cmd,
- "no access-list (<100-199>|<2000-2699>) (deny|permit) ip host A.B.C.D A.B.C.D A.B.C.D",
+ "no access-list <(100-199)|(2000-2699)> <deny|permit> ip host A.B.C.D A.B.C.D A.B.C.D",
NO_STR
"Add an access list entry\n"
"IP extended access list\n"
@@ -1097,14 +1178,19 @@ DEFUN (no_access_list_extended_host_mask,
"Destination address\n"
"Destination Wildcard bits\n")
{
- return filter_set_cisco (vty, argv[0], argv[1], argv[2],
- "0.0.0.0", argv[3],
- argv[4], 1, 0);
+ int idx_acl = 2;
+ int idx_permit_deny = 3;
+ int idx_ipv4 = 6;
+ int idx_ipv4_2 = 7;
+ int idx_ipv4_3 = 8;
+ return filter_set_cisco (vty, argv[idx_acl]->arg, argv[idx_permit_deny]->arg, argv[idx_ipv4]->arg,
+ "0.0.0.0", argv[idx_ipv4_2]->arg,
+ argv[idx_ipv4_3]->arg, 1, 0);
}
DEFUN (no_access_list_extended_host_host,
no_access_list_extended_host_host_cmd,
- "no access-list (<100-199>|<2000-2699>) (deny|permit) ip host A.B.C.D host A.B.C.D",
+ "no access-list <(100-199)|(2000-2699)> <deny|permit> ip host A.B.C.D host A.B.C.D",
NO_STR
"Add an access list entry\n"
"IP extended access list\n"
@@ -1117,14 +1203,18 @@ DEFUN (no_access_list_extended_host_host,
"A single destination host\n"
"Destination address\n")
{
- return filter_set_cisco (vty, argv[0], argv[1], argv[2],
- "0.0.0.0", argv[3],
+ int idx_acl = 2;
+ int idx_permit_deny = 3;
+ int idx_ipv4 = 6;
+ int idx_ipv4_2 = 8;
+ return filter_set_cisco (vty, argv[idx_acl]->arg, argv[idx_permit_deny]->arg, argv[idx_ipv4]->arg,
+ "0.0.0.0", argv[idx_ipv4_2]->arg,
"0.0.0.0", 1, 0);
}
DEFUN (no_access_list_extended_any_host,
no_access_list_extended_any_host_cmd,
- "no access-list (<100-199>|<2000-2699>) (deny|permit) ip any host A.B.C.D",
+ "no access-list <(100-199)|(2000-2699)> <deny|permit> ip any host A.B.C.D",
NO_STR
"Add an access list entry\n"
"IP extended access list\n"
@@ -1136,14 +1226,17 @@ DEFUN (no_access_list_extended_any_host,
"A single destination host\n"
"Destination address\n")
{
- return filter_set_cisco (vty, argv[0], argv[1], "0.0.0.0",
- "255.255.255.255", argv[2],
+ int idx_acl = 2;
+ int idx_permit_deny = 3;
+ int idx_ipv4 = 7;
+ return filter_set_cisco (vty, argv[idx_acl]->arg, argv[idx_permit_deny]->arg, "0.0.0.0",
+ "255.255.255.255", argv[idx_ipv4]->arg,
"0.0.0.0", 1, 0);
}
DEFUN (no_access_list_extended_host_any,
no_access_list_extended_host_any_cmd,
- "no access-list (<100-199>|<2000-2699>) (deny|permit) ip host A.B.C.D any",
+ "no access-list <(100-199)|(2000-2699)> <deny|permit> ip host A.B.C.D any",
NO_STR
"Add an access list entry\n"
"IP extended access list\n"
@@ -1155,7 +1248,10 @@ DEFUN (no_access_list_extended_host_any,
"Source address\n"
"Any destination host\n")
{
- return filter_set_cisco (vty, argv[0], argv[1], argv[2],
+ int idx_acl = 2;
+ int idx_permit_deny = 3;
+ int idx_ipv4 = 6;
+ return filter_set_cisco (vty, argv[idx_acl]->arg, argv[idx_permit_deny]->arg, argv[idx_ipv4]->arg,
"0.0.0.0", "0.0.0.0",
"255.255.255.255", 1, 0);
}
@@ -1244,19 +1340,22 @@ filter_set_zebra (struct vty *vty, const char *name_str, const char *type_str,
/* Zebra access-list */
DEFUN (access_list,
access_list_cmd,
- "access-list WORD (deny|permit) A.B.C.D/M",
+ "access-list WORD <deny|permit> A.B.C.D/M",
"Add an access list entry\n"
"IP zebra access-list name\n"
"Specify packets to reject\n"
"Specify packets to forward\n"
"Prefix to match. e.g. 10.0.0.0/8\n")
{
- return filter_set_zebra (vty, argv[0], argv[1], AFI_IP, argv[2], 0, 1);
+ int idx_word = 1;
+ int idx_permit_deny = 2;
+ int idx_ipv4_prefixlen = 3;
+ return filter_set_zebra (vty, argv[idx_word]->arg, argv[idx_permit_deny]->arg, AFI_IP, argv[idx_ipv4_prefixlen]->arg, 0, 1);
}
DEFUN (access_list_exact,
access_list_exact_cmd,
- "access-list WORD (deny|permit) A.B.C.D/M exact-match",
+ "access-list WORD <deny|permit> A.B.C.D/M exact-match",
"Add an access list entry\n"
"IP zebra access-list name\n"
"Specify packets to reject\n"
@@ -1264,24 +1363,29 @@ DEFUN (access_list_exact,
"Prefix to match. e.g. 10.0.0.0/8\n"
"Exact match of the prefixes\n")
{
- return filter_set_zebra (vty, argv[0], argv[1], AFI_IP, argv[2], 1, 1);
+ int idx_word = 1;
+ int idx_permit_deny = 2;
+ int idx_ipv4_prefixlen = 3;
+ return filter_set_zebra (vty, argv[idx_word]->arg, argv[idx_permit_deny]->arg, AFI_IP, argv[idx_ipv4_prefixlen]->arg, 1, 1);
}
DEFUN (access_list_any,
access_list_any_cmd,
- "access-list WORD (deny|permit) any",
+ "access-list WORD <deny|permit> any",
"Add an access list entry\n"
"IP zebra access-list name\n"
"Specify packets to reject\n"
"Specify packets to forward\n"
"Prefix to match. e.g. 10.0.0.0/8\n")
{
- return filter_set_zebra (vty, argv[0], argv[1], AFI_IP, "0.0.0.0/0", 0, 1);
+ int idx_word = 1;
+ int idx_permit_deny = 2;
+ return filter_set_zebra (vty, argv[idx_word]->arg, argv[idx_permit_deny]->arg, AFI_IP, "0.0.0.0/0", 0, 1);
}
DEFUN (no_access_list,
no_access_list_cmd,
- "no access-list WORD (deny|permit) A.B.C.D/M",
+ "no access-list WORD <deny|permit> A.B.C.D/M",
NO_STR
"Add an access list entry\n"
"IP zebra access-list name\n"
@@ -1289,12 +1393,15 @@ DEFUN (no_access_list,
"Specify packets to forward\n"
"Prefix to match. e.g. 10.0.0.0/8\n")
{
- return filter_set_zebra (vty, argv[0], argv[1], AFI_IP, argv[2], 0, 0);
+ int idx_word = 2;
+ int idx_permit_deny = 3;
+ int idx_ipv4_prefixlen = 4;
+ return filter_set_zebra (vty, argv[idx_word]->arg, argv[idx_permit_deny]->arg, AFI_IP, argv[idx_ipv4_prefixlen]->arg, 0, 0);
}
DEFUN (no_access_list_exact,
no_access_list_exact_cmd,
- "no access-list WORD (deny|permit) A.B.C.D/M exact-match",
+ "no access-list WORD <deny|permit> A.B.C.D/M exact-match",
NO_STR
"Add an access list entry\n"
"IP zebra access-list name\n"
@@ -1303,12 +1410,15 @@ DEFUN (no_access_list_exact,
"Prefix to match. e.g. 10.0.0.0/8\n"
"Exact match of the prefixes\n")
{
- return filter_set_zebra (vty, argv[0], argv[1], AFI_IP, argv[2], 1, 0);
+ int idx_word = 2;
+ int idx_permit_deny = 3;
+ int idx_ipv4_prefixlen = 4;
+ return filter_set_zebra (vty, argv[idx_word]->arg, argv[idx_permit_deny]->arg, AFI_IP, argv[idx_ipv4_prefixlen]->arg, 1, 0);
}
DEFUN (no_access_list_any,
no_access_list_any_cmd,
- "no access-list WORD (deny|permit) any",
+ "no access-list WORD <deny|permit> any",
NO_STR
"Add an access list entry\n"
"IP zebra access-list name\n"
@@ -1316,12 +1426,14 @@ DEFUN (no_access_list_any,
"Specify packets to forward\n"
"Prefix to match. e.g. 10.0.0.0/8\n")
{
- return filter_set_zebra (vty, argv[0], argv[1], AFI_IP, "0.0.0.0/0", 0, 0);
+ int idx_word = 2;
+ int idx_permit_deny = 3;
+ return filter_set_zebra (vty, argv[idx_word]->arg, argv[idx_permit_deny]->arg, AFI_IP, "0.0.0.0/0", 0, 0);
}
DEFUN (no_access_list_all,
no_access_list_all_cmd,
- "no access-list (<1-99>|<100-199>|<1300-1999>|<2000-2699>|WORD)",
+ "no access-list <(1-99)|(100-199)|(1300-1999)|(2000-2699)|WORD>",
NO_STR
"Add an access list entry\n"
"IP standard access list\n"
@@ -1330,14 +1442,15 @@ DEFUN (no_access_list_all,
"IP extended access list (expanded range)\n"
"IP zebra access-list name\n")
{
+ int idx_acl = 2;
struct access_list *access;
struct access_master *master;
/* Looking up access_list. */
- access = access_list_lookup (AFI_IP, argv[0]);
+ access = access_list_lookup (AFI_IP, argv[idx_acl]->arg);
if (access == NULL)
{
- vty_out (vty, "%% access-list %s doesn't exist%s", argv[0],
+ vty_out (vty, "%% access-list %s doesn't exist%s", argv[idx_acl]->arg,
VTY_NEWLINE);
return CMD_WARNING;
}
@@ -1357,7 +1470,7 @@ DEFUN (no_access_list_all,
DEFUN (access_list_remark,
access_list_remark_cmd,
- "access-list (<1-99>|<100-199>|<1300-1999>|<2000-2699>|WORD) remark .LINE",
+ "access-list <(1-99)|(100-199)|(1300-1999)|(2000-2699)|WORD> remark LINE...",
"Add an access list entry\n"
"IP standard access list\n"
"IP extended access list\n"
@@ -1367,23 +1480,25 @@ DEFUN (access_list_remark,
"Access list entry comment\n"
"Comment up to 100 characters\n")
{
+ int idx_acl = 1;
+ int idx_remark = 3;
struct access_list *access;
- access = access_list_get (AFI_IP, argv[0]);
+ access = access_list_get (AFI_IP, argv[idx_acl]->arg);
if (access->remark)
{
XFREE (MTYPE_TMP, access->remark);
access->remark = NULL;
}
- access->remark = argv_concat(argv, argc, 1);
+ access->remark = argv_concat(argv, argc, idx_remark);
return CMD_SUCCESS;
}
DEFUN (no_access_list_remark,
no_access_list_remark_cmd,
- "no access-list (<1-99>|<100-199>|<1300-1999>|<2000-2699>|WORD) remark",
+ "no access-list <(1-99)|(100-199)|(1300-1999)|(2000-2699)|WORD> remark",
NO_STR
"Add an access list entry\n"
"IP standard access list\n"
@@ -1393,12 +1508,14 @@ DEFUN (no_access_list_remark,
"IP zebra access-list\n"
"Access list entry comment\n")
{
- return vty_access_list_remark_unset (vty, AFI_IP, argv[0]);
+ int idx_acl = 2;
+ return vty_access_list_remark_unset (vty, AFI_IP, argv[idx_acl]->arg);
}
-
-ALIAS (no_access_list_remark,
- no_access_list_remark_arg_cmd,
- "no access-list (<1-99>|<100-199>|<1300-1999>|<2000-2699>|WORD) remark .LINE",
+
+/* ALIAS_FIXME */
+DEFUN (no_access_list_remark_comment,
+ no_access_list_remark_comment_cmd,
+ "no access-list <(1-99)|(100-199)|(1300-1999)|(2000-2699)|WORD> remark LINE...",
NO_STR
"Add an access list entry\n"
"IP standard access list\n"
@@ -1408,11 +1525,15 @@ ALIAS (no_access_list_remark,
"IP zebra access-list\n"
"Access list entry comment\n"
"Comment up to 100 characters\n")
+{
+ return no_access_list_remark (self, vty, argc, argv);
+}
+
#ifdef HAVE_IPV6
DEFUN (ipv6_access_list,
ipv6_access_list_cmd,
- "ipv6 access-list WORD (deny|permit) X:X::X:X/M",
+ "ipv6 access-list WORD <deny|permit> X:X::X:X/M",
IPV6_STR
"Add an access list entry\n"
"IPv6 zebra access-list\n"
@@ -1420,12 +1541,15 @@ DEFUN (ipv6_access_list,
"Specify packets to forward\n"
"Prefix to match. e.g. 3ffe:506::/32\n")
{
- return filter_set_zebra (vty, argv[0], argv[1], AFI_IP6, argv[2], 0, 1);
+ int idx_word = 2;
+ int idx_permit_deny = 3;
+ int idx_ipv6_prefixlen = 4;
+ return filter_set_zebra (vty, argv[idx_word]->arg, argv[idx_permit_deny]->arg, AFI_IP6, argv[idx_ipv6_prefixlen]->arg, 0, 1);
}
DEFUN (ipv6_access_list_exact,
ipv6_access_list_exact_cmd,
- "ipv6 access-list WORD (deny|permit) X:X::X:X/M exact-match",
+ "ipv6 access-list WORD <deny|permit> X:X::X:X/M exact-match",
IPV6_STR
"Add an access list entry\n"
"IPv6 zebra access-list\n"
@@ -1434,12 +1558,15 @@ DEFUN (ipv6_access_list_exact,
"Prefix to match. e.g. 3ffe:506::/32\n"
"Exact match of the prefixes\n")
{
- return filter_set_zebra (vty, argv[0], argv[1], AFI_IP6, argv[2], 1, 1);
+ int idx_word = 2;
+ int idx_permit_deny = 3;
+ int idx_ipv6_prefixlen = 4;
+ return filter_set_zebra (vty, argv[idx_word]->arg, argv[idx_permit_deny]->arg, AFI_IP6, argv[idx_ipv6_prefixlen]->arg, 1, 1);
}
DEFUN (ipv6_access_list_any,
ipv6_access_list_any_cmd,
- "ipv6 access-list WORD (deny|permit) any",
+ "ipv6 access-list WORD <deny|permit> any",
IPV6_STR
"Add an access list entry\n"
"IPv6 zebra access-list\n"
@@ -1447,12 +1574,14 @@ DEFUN (ipv6_access_list_any,
"Specify packets to forward\n"
"Any prefixi to match\n")
{
- return filter_set_zebra (vty, argv[0], argv[1], AFI_IP6, "::/0", 0, 1);
+ int idx_word = 2;
+ int idx_permit_deny = 3;
+ return filter_set_zebra (vty, argv[idx_word]->arg, argv[idx_permit_deny]->arg, AFI_IP6, "::/0", 0, 1);
}
DEFUN (no_ipv6_access_list,
no_ipv6_access_list_cmd,
- "no ipv6 access-list WORD (deny|permit) X:X::X:X/M",
+ "no ipv6 access-list WORD <deny|permit> X:X::X:X/M",
NO_STR
IPV6_STR
"Add an access list entry\n"
@@ -1461,12 +1590,15 @@ DEFUN (no_ipv6_access_list,
"Specify packets to forward\n"
"Prefix to match. e.g. 3ffe:506::/32\n")
{
- return filter_set_zebra (vty, argv[0], argv[1], AFI_IP6, argv[2], 0, 0);
+ int idx_word = 3;
+ int idx_permit_deny = 4;
+ int idx_ipv6_prefixlen = 5;
+ return filter_set_zebra (vty, argv[idx_word]->arg, argv[idx_permit_deny]->arg, AFI_IP6, argv[idx_ipv6_prefixlen]->arg, 0, 0);
}
DEFUN (no_ipv6_access_list_exact,
no_ipv6_access_list_exact_cmd,
- "no ipv6 access-list WORD (deny|permit) X:X::X:X/M exact-match",
+ "no ipv6 access-list WORD <deny|permit> X:X::X:X/M exact-match",
NO_STR
IPV6_STR
"Add an access list entry\n"
@@ -1476,12 +1608,15 @@ DEFUN (no_ipv6_access_list_exact,
"Prefix to match. e.g. 3ffe:506::/32\n"
"Exact match of the prefixes\n")
{
- return filter_set_zebra (vty, argv[0], argv[1], AFI_IP6, argv[2], 1, 0);
+ int idx_word = 3;
+ int idx_permit_deny = 4;
+ int idx_ipv6_prefixlen = 5;
+ return filter_set_zebra (vty, argv[idx_word]->arg, argv[idx_permit_deny]->arg, AFI_IP6, argv[idx_ipv6_prefixlen]->arg, 1, 0);
}
DEFUN (no_ipv6_access_list_any,
no_ipv6_access_list_any_cmd,
- "no ipv6 access-list WORD (deny|permit) any",
+ "no ipv6 access-list WORD <deny|permit> any",
NO_STR
IPV6_STR
"Add an access list entry\n"
@@ -1490,7 +1625,9 @@ DEFUN (no_ipv6_access_list_any,
"Specify packets to forward\n"
"Any prefixi to match\n")
{
- return filter_set_zebra (vty, argv[0], argv[1], AFI_IP6, "::/0", 0, 0);
+ int idx_word = 3;
+ int idx_permit_deny = 4;
+ return filter_set_zebra (vty, argv[idx_word]->arg, argv[idx_permit_deny]->arg, AFI_IP6, "::/0", 0, 0);
}
@@ -1502,14 +1639,15 @@ DEFUN (no_ipv6_access_list_all,
"Add an access list entry\n"
"IPv6 zebra access-list\n")
{
+ int idx_word = 3;
struct access_list *access;
struct access_master *master;
/* Looking up access_list. */
- access = access_list_lookup (AFI_IP6, argv[0]);
+ access = access_list_lookup (AFI_IP6, argv[idx_word]->arg);
if (access == NULL)
{
- vty_out (vty, "%% access-list %s doesn't exist%s", argv[0],
+ vty_out (vty, "%% access-list %s doesn't exist%s", argv[idx_word]->arg,
VTY_NEWLINE);
return CMD_WARNING;
}
@@ -1529,23 +1667,25 @@ DEFUN (no_ipv6_access_list_all,
DEFUN (ipv6_access_list_remark,
ipv6_access_list_remark_cmd,
- "ipv6 access-list WORD remark .LINE",
+ "ipv6 access-list WORD remark LINE...",
IPV6_STR
"Add an access list entry\n"
"IPv6 zebra access-list\n"
"Access list entry comment\n"
"Comment up to 100 characters\n")
{
+ int idx_word = 2;
+ int idx_line = 4;
struct access_list *access;
- access = access_list_get (AFI_IP6, argv[0]);
+ access = access_list_get (AFI_IP6, argv[idx_word]->arg);
if (access->remark)
{
XFREE (MTYPE_TMP, access->remark);
access->remark = NULL;
}
- access->remark = argv_concat(argv, argc, 1);
+ access->remark = argv_concat(argv, argc, idx_line);
return CMD_SUCCESS;
}
@@ -1559,18 +1699,24 @@ DEFUN (no_ipv6_access_list_remark,
"IPv6 zebra access-list\n"
"Access list entry comment\n")
{
- return vty_access_list_remark_unset (vty, AFI_IP6, argv[0]);
+ int idx_word = 3;
+ return vty_access_list_remark_unset (vty, AFI_IP6, argv[idx_word]->arg);
}
-
-ALIAS (no_ipv6_access_list_remark,
- no_ipv6_access_list_remark_arg_cmd,
- "no ipv6 access-list WORD remark .LINE",
+
+/* ALIAS_FIXME */
+DEFUN (no_ipv6_access_list_remark_comment,
+ no_ipv6_access_list_remark_comment_cmd,
+ "no ipv6 access-list WORD remark LINE...",
NO_STR
IPV6_STR
"Add an access list entry\n"
"IPv6 zebra access-list\n"
"Access list entry comment\n"
"Comment up to 100 characters\n")
+{
+ return no_ipv6_access_list_remark (self, vty, argc, argv);
+}
+
#endif /* HAVE_IPV6 */
void config_write_access_zebra (struct vty *, struct filter *);
@@ -1695,7 +1841,7 @@ DEFUN (show_ip_access_list,
DEFUN (show_ip_access_list_name,
show_ip_access_list_name_cmd,
- "show ip access-list (<1-99>|<100-199>|<1300-1999>|<2000-2699>|WORD)",
+ "show ip access-list <(1-99)|(100-199)|(1300-1999)|(2000-2699)|WORD>",
SHOW_STR
IP_STR
"List IP access lists\n"
@@ -1705,7 +1851,8 @@ DEFUN (show_ip_access_list_name,
"IP extended access list (expanded range)\n"
"IP zebra access-list\n")
{
- return filter_show (vty, argv[0], AFI_IP);
+ int idx_acl = 3;
+ return filter_show (vty, argv[idx_acl]->arg, AFI_IP);
}
#ifdef HAVE_IPV6
@@ -1727,7 +1874,8 @@ DEFUN (show_ipv6_access_list_name,
"List IPv6 access lists\n"
"IPv6 zebra access-list\n")
{
- return filter_show (vty, argv[0], AFI_IP6);
+ int idx_word = 3;
+ return filter_show (vty, argv[idx_word]->arg, AFI_IP6);
}
#endif /* HAVE_IPV6 */
@@ -1958,7 +2106,7 @@ access_list_init_ipv4 (void)
install_element (CONFIG_NODE, &access_list_remark_cmd);
install_element (CONFIG_NODE, &no_access_list_all_cmd);
install_element (CONFIG_NODE, &no_access_list_remark_cmd);
- install_element (CONFIG_NODE, &no_access_list_remark_arg_cmd);
+ install_element (CONFIG_NODE, &no_access_list_remark_comment_cmd);
}
#ifdef HAVE_IPV6
@@ -2022,7 +2170,7 @@ access_list_init_ipv6 (void)
install_element (CONFIG_NODE, &no_ipv6_access_list_all_cmd);
install_element (CONFIG_NODE, &ipv6_access_list_remark_cmd);
install_element (CONFIG_NODE, &no_ipv6_access_list_remark_cmd);
- install_element (CONFIG_NODE, &no_ipv6_access_list_remark_arg_cmd);
+ install_element (CONFIG_NODE, &no_ipv6_access_list_remark_comment_cmd);
}
#endif /* HAVE_IPV6 */
diff --git a/lib/grammar_sandbox.c b/lib/grammar_sandbox.c
new file mode 100644
index 0000000000..c4ae2d7d77
--- /dev/null
+++ b/lib/grammar_sandbox.c
@@ -0,0 +1,386 @@
+/*
+ * Testing shim and API examples for the new CLI backend.
+ *
+ * This unit defines a number of commands in the old engine that can
+ * be used to test and interact with the new engine.
+ *
+ * This shim should be removed upon integration. It is currently hooked in
+ * vtysh/vtysh.c. It has no header, vtysh.c merely includes this entire unit
+ * since it clutters up the makefiles less and this is only a temporary shim.
+ *
+ * --
+ * Copyright (C) 2016 Cumulus Networks, Inc.
+ *
+ * This file is part of GNU Zebra.
+ *
+ * GNU Zebra is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2, or (at your option) any
+ * later version.
+ *
+ * GNU Zebra is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GNU Zebra; see the file COPYING. If not, write to the Free
+ * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ */
+
+#include "command.h"
+#include "graph.h"
+#include "command_parse.h"
+#include "command_match.h"
+
+#define GRAMMAR_STR "CLI grammar sandbox\n"
+
+/** headers **/
+void
+grammar_sandbox_init (void);
+void
+pretty_print_graph (struct graph_node *, int);
+void
+init_cmdgraph (struct graph **);
+vector
+completions_to_vec (struct list *);
+int
+compare_completions (const void *, const void *);
+
+/** shim interface commands **/
+struct graph *nodegraph;
+
+DEFUN (grammar_test,
+ grammar_test_cmd,
+ "grammar parse .COMMAND",
+ GRAMMAR_STR
+ "command to pass to new parser\n")
+{
+ int idx_command = 2;
+ // make a string from tokenized command line
+ char *command = argv_concat (argv, argc, idx_command);
+
+ // create cmd_element for parser
+ struct cmd_element *cmd = XCALLOC (MTYPE_CMD_TOKENS, sizeof (struct cmd_element));
+ cmd->string = command;
+ cmd->doc = NULL;
+ cmd->func = NULL;
+ cmd->tokens = vector_init (VECTOR_MIN_SIZE);
+
+ // parse the command and install it into the command graph
+ command_parse_format (nodegraph, cmd);
+
+ return CMD_SUCCESS;
+}
+
+DEFUN (grammar_test_complete,
+ grammar_test_complete_cmd,
+ "grammar complete .COMMAND",
+ GRAMMAR_STR
+ "attempt to complete input on DFA\n"
+ "command to complete")
+{
+ int idx_command = 2;
+ char *cmdstr = argv_concat (argv, argc, idx_command);
+ vector command = cmd_make_strvec (cmdstr);
+
+ // generate completions of user input
+ struct list *completions;
+ enum matcher_rv result = command_complete (nodegraph, command, &completions);
+
+ // print completions or relevant error message
+ if (!MATCHER_ERROR(result))
+ {
+ vector comps = completions_to_vec (completions);
+ struct cmd_token_t *tkn;
+
+ // calculate length of longest tkn->text in completions
+ unsigned int width = 0, i = 0;
+ for (i = 0; i < vector_active (comps); i++) {
+ tkn = vector_slot (comps, i);
+ unsigned int len = strlen (tkn->text);
+ width = len > width ? len : width;
+ }
+
+ // print completions
+ for (i = 0; i < vector_active (comps); i++) {
+ tkn = vector_slot (comps, i);
+ fprintf (stdout, " %-*s %s%s", width, tkn->text, tkn->desc, "\n");
+ }
+
+ for (i = 0; i < vector_active (comps); i++)
+ del_cmd_token ((struct cmd_token_t *) vector_slot (comps, i));
+ vector_free (comps);
+ }
+ else
+ fprintf (stdout, "%% No match%s", "\n");
+
+ // free resources
+ list_delete (completions);
+ cmd_free_strvec (command);
+ free (cmdstr);
+
+ return CMD_SUCCESS;
+}
+
+DEFUN (grammar_test_match,
+ grammar_test_match_cmd,
+ "grammar match .COMMAND",
+ GRAMMAR_STR
+ "attempt to match input on DFA\n"
+ "command to match")
+{
+ int idx_command = 2;
+ if (argv[0][0] == '#')
+ return CMD_SUCCESS;
+
+ char *cmdstr = argv_concat(argv, argc, idx_command);
+ vector command = cmd_make_strvec (cmdstr);
+
+ struct list *argvv = NULL;
+ struct cmd_element *element = NULL;
+ enum matcher_rv result = command_match (nodegraph, command, &argvv, &element);
+
+ // print completions or relevant error message
+ if (element)
+ {
+ fprintf (stdout, "Matched: %s%s", element->string, "\n");
+ struct listnode *ln;
+ struct cmd_token_t *token;
+ for (ALL_LIST_ELEMENTS_RO(argvv,ln,token))
+ fprintf (stdout, "%s -- %s%s", token->text, token->arg, "\n");
+
+ fprintf (stdout, "func: %p%s", element->func, "\n");
+
+ list_delete (argvv);
+ del_cmd_element (element);
+ }
+ else {
+ assert(MATCHER_ERROR(result));
+ switch (result) {
+ case MATCHER_NO_MATCH:
+ fprintf (stdout, "%% Unknown command%s", "\n");
+ break;
+ case MATCHER_INCOMPLETE:
+ fprintf (stdout, "%% Incomplete command%s", "\n");
+ break;
+ case MATCHER_AMBIGUOUS:
+ fprintf (stdout, "%% Ambiguous command%s", "\n");
+ break;
+ default:
+ fprintf (stdout, "%% Unknown error%s", "\n");
+ break;
+ }
+ }
+
+ // free resources
+ cmd_free_strvec (command);
+ free (cmdstr);
+
+ return CMD_SUCCESS;
+}
+
+/**
+ * Testing shim to test docstrings
+ */
+DEFUN (grammar_test_doc,
+ grammar_test_doc_cmd,
+ "grammar test docstring",
+ GRAMMAR_STR
+ "Test function for docstring\n"
+ "Command end\n")
+{
+ // create cmd_element with docstring
+ struct cmd_element *cmd = XCALLOC (MTYPE_CMD_TOKENS, sizeof (struct cmd_element));
+ cmd->string = XSTRDUP (MTYPE_CMD_TOKENS, "test docstring <example|selector follow> (1-255) end VARIABLE [OPTION|set lol] . VARARG");
+ cmd->doc = XSTRDUP (MTYPE_CMD_TOKENS,
+ "Test stuff\n"
+ "docstring thing\n"
+ "first example\n"
+ "second example\n"
+ "follow\n"
+ "random range\n"
+ "end thingy\n"
+ "variable\n"
+ "optional variable\n"
+ "optional set\n"
+ "optional lol\n"
+ "vararg!\n");
+ cmd->func = NULL;
+ cmd->tokens = vector_init (VECTOR_MIN_SIZE);
+
+ // parse element
+ command_parse_format (nodegraph, cmd);
+
+ return CMD_SUCCESS;
+}
+
+/**
+ * Debugging command to print command graph
+ */
+DEFUN (grammar_test_show,
+ grammar_test_show_cmd,
+ "grammar show graph",
+ GRAMMAR_STR
+ "print current accumulated DFA\n")
+{
+ if (!nodegraph)
+ zlog_info("nodegraph uninitialized");
+ else
+ pretty_print_graph (vector_slot (nodegraph->nodes, 0), 0);
+ return CMD_SUCCESS;
+}
+
+DEFUN (grammar_init_graph,
+ grammar_init_graph_cmd,
+ "grammar init graph",
+ GRAMMAR_STR
+ "(re)initialize graph\n")
+{
+ graph_delete_graph (nodegraph);
+ init_cmdgraph (&nodegraph);
+ return CMD_SUCCESS;
+}
+
+/* this is called in vtysh.c to set up the testing shim */
+void grammar_sandbox_init() {
+ init_cmdgraph (&nodegraph);
+
+ // install all enable elements
+ install_element (ENABLE_NODE, &grammar_test_cmd);
+ install_element (ENABLE_NODE, &grammar_test_show_cmd);
+ install_element (ENABLE_NODE, &grammar_test_match_cmd);
+ install_element (ENABLE_NODE, &grammar_test_complete_cmd);
+ install_element (ENABLE_NODE, &grammar_test_doc_cmd);
+ install_element (ENABLE_NODE, &grammar_init_graph_cmd);
+}
+
+
+/**
+ * Pretty-prints a graph, assuming it is a tree.
+ *
+ * @param start the node to take as the root
+ * @param level indent level for recursive calls, always pass 0
+ */
+void
+pretty_print_graph (struct graph_node *start, int level)
+{
+ // print this node
+ struct cmd_token_t *tok = start->data;
+ fprintf (stdout, "%s[%d] ", tok->text, tok->type);
+
+ int numto = vector_active (start->to);
+ if (numto)
+ {
+ if (numto > 1)
+ fprintf (stdout, "\n");
+ for (unsigned int i = 0; i < vector_active (start->to); i++)
+ {
+ struct graph_node *adj = vector_slot (start->to, i);
+ // if we're listing multiple children, indent!
+ if (numto > 1)
+ for (int j = 0; j < level+1; j++)
+ fprintf (stdout, " ");
+ // if this node is a vararg, just print *
+ if (adj == start)
+ fprintf (stdout, "*");
+ else
+ pretty_print_graph (adj, numto > 1 ? level+1 : level);
+ }
+ }
+ else
+ fprintf(stdout, "\n");
+}
+
+/** stuff that should go in command.c + command.h */
+void
+init_cmdgraph (struct graph **graph)
+{
+ // initialize graph, add start noe
+ *graph = graph_new ();
+ struct cmd_token_t *token = new_cmd_token (START_TKN, NULL, NULL);
+ graph_new_node (*graph, token, (void (*)(void *)) &del_cmd_token);
+ fprintf (stdout, "initialized graph\n");
+}
+
+int
+compare_completions (const void *fst, const void *snd)
+{
+ struct cmd_token_t *first = *(struct cmd_token_t **) fst,
+ *secnd = *(struct cmd_token_t **) snd;
+ return strcmp (first->text, secnd->text);
+}
+
+vector
+completions_to_vec (struct list *completions)
+{
+ vector comps = vector_init (VECTOR_MIN_SIZE);
+
+ struct listnode *ln;
+ struct cmd_token_t *token;
+ unsigned int i, exists;
+ for (ALL_LIST_ELEMENTS_RO(completions,ln,token))
+ {
+ // linear search for token in completions vector
+ exists = 0;
+ for (i = 0; i < vector_active (comps) && !exists; i++)
+ {
+ struct cmd_token_t *curr = vector_slot (comps, i);
+ exists = !strcmp (curr->text, token->text) &&
+ !strcmp (curr->desc, token->desc);
+ }
+
+ if (!exists)
+ vector_set (comps, copy_cmd_token (token));
+ }
+
+ // sort completions
+ qsort (comps->index,
+ vector_active (comps),
+ sizeof (void *),
+ &compare_completions);
+
+ return comps;
+}
+
+struct cmd_token_t *
+new_cmd_token (enum cmd_token_type_t type, char *text, char *desc)
+{
+ struct cmd_token_t *token = XMALLOC (MTYPE_CMD_TOKENS, sizeof (struct cmd_token_t));
+ token->type = type;
+ token->text = text;
+ token->desc = desc;
+ token->arg = NULL;
+
+ return token;
+}
+
+void
+del_cmd_token (struct cmd_token_t *token)
+{
+ if (!token) return;
+
+ if (token->text)
+ XFREE (MTYPE_CMD_TOKENS, token->text);
+ if (token->desc)
+ XFREE (MTYPE_CMD_TOKENS, token->desc);
+ if (token->arg)
+ XFREE (MTYPE_CMD_TOKENS, token->arg);
+
+ XFREE (MTYPE_CMD_TOKENS, token);
+}
+
+struct cmd_token_t *
+copy_cmd_token (struct cmd_token_t *token)
+{
+ struct cmd_token_t *copy = new_cmd_token (token->type, NULL, NULL);
+ copy->value = token->value;
+ copy->max = token->max;
+ copy->min = token->min;
+ copy->text = token->text ? XSTRDUP (MTYPE_CMD_TOKENS, token->text) : NULL;
+ copy->desc = token->desc ? XSTRDUP (MTYPE_CMD_TOKENS, token->desc) : NULL;
+ copy->arg = token->arg ? XSTRDUP (MTYPE_CMD_TOKENS, token->arg) : NULL;
+
+ return copy;
+}
diff --git a/lib/grammar_sandbox.h b/lib/grammar_sandbox.h
new file mode 100644
index 0000000000..6e61ce1b46
--- /dev/null
+++ b/lib/grammar_sandbox.h
@@ -0,0 +1,65 @@
+#ifndef _GRAMMAR_SANDBOX_H
+#define _GRAMMAR_SANDBOX_H
+
+/**
+ * Houses functionality for testing shim as well as code that should go into
+ * command.h and command.c during integration.
+ */
+#include "memory.h"
+
+#define CMD_CR_TEXT "<cr>"
+
+void
+grammar_sandbox_init (void);
+
+/**
+ * Types for tokens.
+ *
+ * The type determines what kind of data the token can match (in the
+ * matching use case) or hold (in the argv use case).
+ */
+enum cmd_token_type_t
+{
+ WORD_TKN, // words
+ NUMBER_TKN, // integral numbers
+ VARIABLE_TKN, // almost anything
+ RANGE_TKN, // integer range
+ IPV4_TKN, // IPV4 addresses
+ IPV4_PREFIX_TKN, // IPV4 network prefixes
+ IPV6_TKN, // IPV6 prefixes
+ IPV6_PREFIX_TKN, // IPV6 network prefixes
+
+ /* plumbing types */
+ SELECTOR_TKN, // marks beginning of selector
+ OPTION_TKN, // marks beginning of option
+ NUL_TKN, // dummy token
+ START_TKN, // first token in line
+ END_TKN, // last token in line
+};
+
+/**
+ * Token struct.
+ */
+struct cmd_token_t
+{
+ enum cmd_token_type_t type; // token type
+
+ char *text; // token text
+ char *desc; // token description
+
+ long long value; // for numeric types
+ long long min, max; // for ranges
+
+ char *arg; // user input that matches this token
+};
+
+struct cmd_token_t *
+new_cmd_token (enum cmd_token_type_t, char *, char *);
+
+void
+del_cmd_token (struct cmd_token_t *);
+
+struct cmd_token_t *
+copy_cmd_token (struct cmd_token_t *);
+
+#endif /* _GRAMMAR_SANDBOX_H */
diff --git a/lib/graph.c b/lib/graph.c
new file mode 100644
index 0000000000..891ecc33c0
--- /dev/null
+++ b/lib/graph.c
@@ -0,0 +1,138 @@
+/*
+ * Graph data structure.
+ *
+ * --
+ * Copyright (C) 2016 Cumulus Networks, Inc.
+ *
+ * This file is part of GNU Zebra.
+ *
+ * GNU Zebra is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2, or (at your option) any
+ * later version.
+ *
+ * GNU Zebra is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GNU Zebra; see the file COPYING. If not, write to the Free
+ * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ */
+#include <zebra.h>
+#include "graph.h"
+#include "memory.h"
+
+DEFINE_MTYPE_STATIC(LIB, GRAPH, "Graph")
+DEFINE_MTYPE_STATIC(LIB, GRAPH_NODE, "Graph Node")
+struct graph *
+graph_new ()
+{
+ struct graph *graph = XCALLOC (MTYPE_GRAPH, sizeof(struct graph));
+ graph->nodes = vector_init (VECTOR_MIN_SIZE);
+
+ return graph;
+}
+
+struct graph_node *
+graph_new_node (struct graph *graph, void *data, void (*del) (void*))
+{
+ struct graph_node *node =
+ XCALLOC(MTYPE_GRAPH_NODE, sizeof(struct graph_node));
+
+ node->from = vector_init (VECTOR_MIN_SIZE);
+ node->to = vector_init (VECTOR_MIN_SIZE);
+ node->data = data;
+ node->del = del;
+
+ vector_set (graph->nodes, node);
+
+ return node;
+}
+
+static void
+vector_remove (vector v, unsigned int ix)
+{
+ vector_unset (v, ix);
+ if (ix == vector_active (v)) return;
+ for (; ix < vector_active (v) - 1; ix++)
+ v->index[ix] = v->index[ix+1];
+ v->active--;
+}
+
+void
+graph_delete_node (struct graph *graph, struct graph_node *node)
+{
+ if (!node) return;
+
+ // an adjacent node
+ struct graph_node *adj;
+
+ // remove all edges from other nodes to us
+ vector edges = vector_copy (node->from);
+ for (unsigned int i = 0; i < vector_active (edges); i++)
+ {
+ adj = vector_slot (edges, i);
+ graph_remove_edge (adj, node);
+ }
+ vector_free (edges);
+
+ // remove all edges from us to other nodes
+ edges = vector_copy (node->to);
+ for (unsigned int i = 0; i < vector_active (edges); i++)
+ {
+ adj = vector_slot (edges, i);
+ graph_remove_edge (node, adj);
+ }
+ vector_free (edges);
+
+ // if there is a deletion callback, call it
+ if (node->del && node->data)
+ (*node->del) (node->data);
+
+ // free adjacency lists
+ vector_free (node->to);
+ vector_free (node->from);
+
+ // remove node from graph->nodes
+ for (unsigned int i = 0; i < vector_active (graph->nodes); i++)
+ if (vector_slot (graph->nodes, i) == node)
+ vector_remove (graph->nodes, i);
+
+ // free the node itself
+ XFREE (MTYPE_GRAPH_NODE, node);
+}
+
+struct graph_node *
+graph_add_edge (struct graph_node *from, struct graph_node *to)
+{
+ vector_set (from->to, to);
+ vector_set (to->from, from);
+ return to;
+}
+
+void
+graph_remove_edge (struct graph_node *from, struct graph_node *to)
+{
+ // remove from from to->from
+ for (unsigned int i = 0; i < vector_active (to->from); i++)
+ if (vector_slot (to->from, i) == from)
+ vector_remove (to->from, i);
+ // remove to from from->to
+ for (unsigned int i = 0; i < vector_active (from->to); i++)
+ if (vector_slot (from->to, i) == to)
+ vector_remove (from->to, i);
+}
+
+void
+graph_delete_graph (struct graph *graph)
+{
+ // delete each node in the graph
+ for (unsigned int i = 0; i < vector_active (graph->nodes); i++)
+ graph_delete_node (graph, vector_slot (graph->nodes, i));
+
+ vector_free (graph->nodes);
+ XFREE (MTYPE_GRAPH, graph);
+}
diff --git a/lib/graph.h b/lib/graph.h
new file mode 100644
index 0000000000..8d8aa3823b
--- /dev/null
+++ b/lib/graph.h
@@ -0,0 +1,101 @@
+/*
+ * Graph data structure.
+ *
+ * --
+ * Copyright (C) 2016 Cumulus Networks, Inc.
+ *
+ * This file is part of GNU Zebra.
+ *
+ * GNU Zebra is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2, or (at your option) any
+ * later version.
+ *
+ * GNU Zebra is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GNU Zebra; see the file COPYING. If not, write to the Free
+ * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ */
+
+#ifndef _ZEBRA_COMMAND_GRAPH_H
+#define _ZEBRA_COMMAND_GRAPH_H
+
+#include "vector.h"
+
+struct graph
+{
+ vector nodes;
+};
+
+struct graph_node
+{
+ vector from; // nodes which have edges to this node
+ vector to; // nodes which this node has edges to
+
+ void *data; // node data
+ void (*del) (void *data); // deletion callback
+};
+
+struct graph *
+graph_new (void);
+
+/**
+ * Creates a new node.
+ *
+ * @struct graph the graph this node exists in
+ * @param[in] data this node's data
+ * @param[in] del data deletion callback
+ * @return the new node
+ */
+struct graph_node *
+graph_new_node (struct graph *graph, void *data, void (*del) (void*));
+
+/**
+ * Deletes a node.
+ *
+ * Before deletion, this function removes all edges to and from this node from
+ * any neighbor nodes.
+ *
+ * If *data and *del are non-null, the following call is made:
+ * (*node->del) (node->data);
+ *
+ * @param[in] graph the graph this node belongs to
+ * @param[out] node pointer to node to delete
+ */
+void
+graph_delete_node (struct graph *graph, struct graph_node *node);
+
+/**
+ * Makes a directed edge between two nodes.
+ *
+ * @param[in] from
+ * @param[in] to
+ * @return to
+ */
+struct graph_node *
+graph_add_edge (struct graph_node *from, struct graph_node *to);
+
+/**
+ * Removes a directed edge between two nodes.
+ *
+ * @param[in] from
+ * @param[in] to
+ */
+void
+graph_remove_edge (struct graph_node *from, struct graph_node *to);
+
+/**
+ * Deletes a graph.
+ * Calls graph_delete_node on each node before freeing the graph struct itself.
+ *
+ * @param graph the graph to delete
+ */
+void
+graph_delete_graph (struct graph *graph);
+
+#endif /* _ZEBRA_COMMAND_GRAPH_H */
diff --git a/lib/if.c b/lib/if.c
index 6ae8500291..6235884e5d 100644
--- a/lib/if.c
+++ b/lib/if.c
@@ -677,25 +677,23 @@ if_dump_all (void)
if_dump (p);
}
-DEFUN (interface_desc,
+DEFUN (interface_desc,
interface_desc_cmd,
- "description .LINE",
+ "description LINE...",
"Interface specific description\n"
"Characters describing this interface\n")
{
+ int idx_line = 1;
VTY_DECLVAR_CONTEXT (interface, ifp);
- if (argc == 0)
- return CMD_SUCCESS;
-
if (ifp->desc)
XFREE (MTYPE_TMP, ifp->desc);
- ifp->desc = argv_concat(argv, argc, 0);
+ ifp->desc = argv_concat(argv, argc, idx_line);
return CMD_SUCCESS;
}
-DEFUN (no_interface_desc,
+DEFUN (no_interface_desc,
no_interface_desc_cmd,
"no description",
NO_STR
@@ -754,36 +752,42 @@ if_sunwzebra_get (const char *name, size_t nlen, vrf_id_t vrf_id)
DEFUN (interface,
interface_cmd,
- "interface IFNAME",
+ "interface IFNAME [vrf NAME]",
"Select an interface to configure\n"
- "Interface's name\n")
+ "Interface's name\n"
+ VRF_CMD_HELP_STR)
{
+ int idx_ifname = 1;
+ int idx_vrf = 3;
+ const char *ifname = argv[idx_ifname]->arg;
+ const char *vrfname = (argc > 2) ? argv[idx_vrf]->arg : NULL;
+
struct interface *ifp;
size_t sl;
vrf_id_t vrf_id = VRF_DEFAULT;
- if ((sl = strlen(argv[0])) > INTERFACE_NAMSIZ)
+ if ((sl = strlen(ifname)) > INTERFACE_NAMSIZ)
{
vty_out (vty, "%% Interface name %s is invalid: length exceeds "
"%d characters%s",
- argv[0], INTERFACE_NAMSIZ, VTY_NEWLINE);
+ ifname, INTERFACE_NAMSIZ, VTY_NEWLINE);
return CMD_WARNING;
}
/*Pending: need proper vrf name based lookup/(possible creation of VRF)
Imagine forward reference of a vrf by name in this interface config */
- if (argc > 1)
- VRF_GET_ID (vrf_id, argv[1]);
+ if (vrfname)
+ VRF_GET_ID (vrf_id, vrfname);
#ifdef SUNOS_5
- ifp = if_sunwzebra_get (argv[0], sl, vrf_id);
+ ifp = if_sunwzebra_get (ifname, sl, vrf_id);
#else
- ifp = if_get_by_name_len_vrf (argv[0], sl, vrf_id, 1);
+ ifp = if_get_by_name_len_vrf (ifname, sl, vrf_id, 1);
#endif /* SUNOS_5 */
if (!ifp)
{
- vty_out (vty, "%% interface %s not in %s%s", argv[0], argv[1], VTY_NEWLINE);
+ vty_out (vty, "%% interface %s not in %s%s", ifname, vrfname, VTY_NEWLINE);
return CMD_WARNING;
}
VTY_PUSH_CONTEXT_COMPAT (INTERFACE_NODE, ifp);
@@ -791,32 +795,29 @@ DEFUN (interface,
return CMD_SUCCESS;
}
-ALIAS (interface,
- interface_vrf_cmd,
- "interface IFNAME " VRF_CMD_STR,
- "Select an interface to configure\n"
- "Interface's name\n"
- VRF_CMD_HELP_STR)
-
DEFUN_NOSH (no_interface,
no_interface_cmd,
- "no interface IFNAME",
+ "no interface IFNAME [vrf NAME]",
NO_STR
"Delete a pseudo interface's configuration\n"
- "Interface's name\n")
+ "Interface's name\n"
+ VRF_CMD_HELP_STR)
{
+ const char *ifname = argv[2]->arg;
+ const char *vrfname = (argc > 3) ? argv[3]->arg : NULL;
+
// deleting interface
struct interface *ifp;
vrf_id_t vrf_id = VRF_DEFAULT;
- if (argc > 1)
- VRF_GET_ID (vrf_id, argv[1]);
+ if (argc > 3)
+ VRF_GET_ID (vrf_id, vrfname);
- ifp = if_lookup_by_name_vrf (argv[0], vrf_id);
+ ifp = if_lookup_by_name_vrf (ifname, vrf_id);
if (ifp == NULL)
{
- vty_out (vty, "%% Interface %s does not exist%s", argv[0], VTY_NEWLINE);
+ vty_out (vty, "%% Interface %s does not exist%s", ifname, VTY_NEWLINE);
return CMD_WARNING;
}
@@ -832,32 +833,27 @@ DEFUN_NOSH (no_interface,
return CMD_SUCCESS;
}
-ALIAS (no_interface,
- no_interface_vrf_cmd,
- "no interface IFNAME " VRF_CMD_STR,
- NO_STR
- "Delete a pseudo interface's configuration\n"
- "Interface's name\n"
- VRF_CMD_HELP_STR)
-
DEFUN (vrf,
vrf_cmd,
"vrf NAME",
"Select a VRF to configure\n"
"VRF's name\n")
{
+ int idx_name = 1;
+ const char *vrfname = argv[idx_name]->arg;
+
struct vrf *vrfp;
size_t sl;
- if ((sl = strlen(argv[0])) > VRF_NAMSIZ)
+ if ((sl = strlen(vrfname)) > VRF_NAMSIZ)
{
vty_out (vty, "%% VRF name %s is invalid: length exceeds "
"%d characters%s",
- argv[0], VRF_NAMSIZ, VTY_NEWLINE);
+ vrfname, VRF_NAMSIZ, VTY_NEWLINE);
return CMD_WARNING;
}
- vrfp = vrf_get (VRF_UNKNOWN, argv[0]);
+ vrfp = vrf_get (VRF_UNKNOWN, vrfname);
VTY_PUSH_CONTEXT_COMPAT (VRF_NODE, vrfp);
@@ -871,13 +867,15 @@ DEFUN_NOSH (no_vrf,
"Delete a pseudo VRF's configuration\n"
"VRF's name\n")
{
+ const char *vrfname = argv[2]->arg;
+
struct vrf *vrfp;
- vrfp = vrf_list_lookup_by_name (argv[0]);
+ vrfp = vrf_list_lookup_by_name (vrfname);;
if (vrfp == NULL)
{
- vty_out (vty, "%% VRF %s does not exist%s", argv[0], VTY_NEWLINE);
+ vty_out (vty, "%% VRF %s does not exist%s", vrfname, VTY_NEWLINE);
return CMD_WARNING;
}
@@ -897,10 +895,12 @@ DEFUN_NOSH (no_vrf,
/* For debug purpose. */
DEFUN (show_address,
show_address_cmd,
- "show address",
+ "show address [vrf NAME]",
SHOW_STR
- "address\n")
+ "address\n"
+ VRF_CMD_HELP_STR)
{
+ int idx_vrf = 3;
struct listnode *node;
struct listnode *node2;
struct interface *ifp;
@@ -908,8 +908,8 @@ DEFUN (show_address,
struct prefix *p;
vrf_id_t vrf_id = VRF_DEFAULT;
- if (argc > 0)
- VRF_GET_ID (vrf_id, argv[0]);
+ if (argc > 2)
+ VRF_GET_ID (vrf_id, argv[idx_vrf]->arg);
for (ALL_LIST_ELEMENTS_RO (vrf_iflist (vrf_id), node, ifp))
{
@@ -925,16 +925,9 @@ DEFUN (show_address,
return CMD_SUCCESS;
}
-ALIAS (show_address,
- show_address_vrf_cmd,
- "show address " VRF_CMD_STR,
- SHOW_STR
- "address\n"
- VRF_CMD_HELP_STR)
-
DEFUN (show_address_vrf_all,
show_address_vrf_all_cmd,
- "show address " VRF_ALL_CMD_STR,
+ "show address vrf all",
SHOW_STR
"address\n"
VRF_ALL_CMD_HELP_STR)
diff --git a/lib/if_rmap.c b/lib/if_rmap.c
index 736f2e237d..2afb08c7ca 100644
--- a/lib/if_rmap.c
+++ b/lib/if_rmap.c
@@ -211,18 +211,21 @@ if_rmap_unset (const char *ifname, enum if_rmap_type type,
DEFUN (if_rmap,
if_rmap_cmd,
- "route-map RMAP_NAME (in|out) IFNAME",
+ "route-map RMAP_NAME <in|out> IFNAME",
"Route map set\n"
"Route map name\n"
"Route map set for input filtering\n"
"Route map set for output filtering\n"
"Route map interface name\n")
{
+ int idx_rmap_name = 1;
+ int idx_in_out = 2;
+ int idx_ifname = 3;
enum if_rmap_type type;
- if (strncmp (argv[1], "i", 1) == 0)
+ if (strncmp (argv[idx_in_out]->text, "in", 1) == 0)
type = IF_RMAP_IN;
- else if (strncmp (argv[1], "o", 1) == 0)
+ else if (strncmp (argv[idx_in_out]->text, "out", 1) == 0)
type = IF_RMAP_OUT;
else
{
@@ -230,23 +233,14 @@ DEFUN (if_rmap,
return CMD_WARNING;
}
- if_rmap_set (argv[2], type, argv[0]);
+ if_rmap_set (argv[idx_ifname]->arg, type, argv[idx_rmap_name]->arg);
return CMD_SUCCESS;
-}
-
-ALIAS (if_rmap,
- if_ipv6_rmap_cmd,
- "route-map RMAP_NAME (in|out) IFNAME",
- "Route map set\n"
- "Route map name\n"
- "Route map set for input filtering\n"
- "Route map set for output filtering\n"
- "Route map interface name\n")
+}
DEFUN (no_if_rmap,
no_if_rmap_cmd,
- "no route-map ROUTEMAP_NAME (in|out) IFNAME",
+ "no route-map ROUTEMAP_NAME <in|out> IFNAME",
NO_STR
"Route map unset\n"
"Route map name\n"
@@ -254,12 +248,15 @@ DEFUN (no_if_rmap,
"Route map for output filtering\n"
"Route map interface name\n")
{
+ int idx_routemap_name = 2;
+ int idx_in_out = 3;
+ int idx_ifname = 4;
int ret;
enum if_rmap_type type;
- if (strncmp (argv[1], "i", 1) == 0)
+ if (strncmp (argv[idx_in_out]->arg, "i", 1) == 0)
type = IF_RMAP_IN;
- else if (strncmp (argv[1], "o", 1) == 0)
+ else if (strncmp (argv[idx_in_out]->arg, "o", 1) == 0)
type = IF_RMAP_OUT;
else
{
@@ -267,24 +264,15 @@ DEFUN (no_if_rmap,
return CMD_WARNING;
}
- ret = if_rmap_unset (argv[2], type, argv[0]);
+ ret = if_rmap_unset (argv[idx_ifname]->arg, type, argv[idx_routemap_name]->arg);
if (! ret)
{
vty_out (vty, "route-map doesn't exist%s", VTY_NEWLINE);
return CMD_WARNING;
}
return CMD_SUCCESS;
-}
+}
-ALIAS (no_if_rmap,
- no_if_ipv6_rmap_cmd,
- "no route-map ROUTEMAP_NAME (in|out) IFNAME",
- NO_STR
- "Route map unset\n"
- "Route map name\n"
- "Route map for input filtering\n"
- "Route map for output filtering\n"
- "Route map interface name\n")
/* Configuration write function. */
int
@@ -333,8 +321,6 @@ if_rmap_init (int node)
{
ifrmaphash = hash_create (if_rmap_hash_make, if_rmap_hash_cmp);
if (node == RIPNG_NODE) {
- install_element (RIPNG_NODE, &if_ipv6_rmap_cmd);
- install_element (RIPNG_NODE, &no_if_ipv6_rmap_cmd);
} else if (node == RIP_NODE) {
install_element (RIP_NODE, &if_rmap_cmd);
install_element (RIP_NODE, &no_if_rmap_cmd);
diff --git a/lib/json.c b/lib/json.c
index ca30c60984..966d24f005 100644
--- a/lib/json.c
+++ b/lib/json.c
@@ -21,6 +21,7 @@
#include <zebra.h>
+#include "command.h"
#include "lib/json.h"
/*
@@ -29,12 +30,12 @@
* what.
*/
int
-use_json (const int argc, const char *argv[])
+use_json (const int argc, struct cmd_token *argv[])
{
if (argc == 0)
return 0;
- if (argv[argc-1] && strcmp(argv[argc-1], "json") == 0)
+ if (argv[argc-1]->arg && strcmp(argv[argc-1]->arg, "json") == 0)
return 1;
return 0;
diff --git a/lib/json.h b/lib/json.h
index b217df0a7b..0ceffd4e8e 100644
--- a/lib/json.h
+++ b/lib/json.h
@@ -34,7 +34,7 @@
#define json_object_to_json_string_ext(A, B) json_object_to_json_string (A)
#endif
-extern int use_json(const int argc, const char *argv[]);
+extern int use_json(const int argc, struct cmd_token *argv[]);
extern void json_object_string_add(struct json_object* obj, const char *key,
const char *s);
extern void json_object_int_add(struct json_object* obj, const char *key,
diff --git a/lib/keychain.c b/lib/keychain.c
index c090956487..f8a3ffc012 100644
--- a/lib/keychain.c
+++ b/lib/keychain.c
@@ -247,9 +247,10 @@ DEFUN (key_chain,
"Key-chain management\n"
"Key-chain name\n")
{
+ int idx_word = 2;
struct keychain *keychain;
- keychain = keychain_get (argv[0]);
+ keychain = keychain_get (argv[idx_word]->arg);
VTY_PUSH_CONTEXT_COMPAT (KEYCHAIN_NODE, keychain);
return CMD_SUCCESS;
@@ -263,13 +264,14 @@ DEFUN (no_key_chain,
"Key-chain management\n"
"Key-chain name\n")
{
+ int idx_word = 3;
struct keychain *keychain;
- keychain = keychain_lookup (argv[0]);
+ keychain = keychain_lookup (argv[idx_word]->arg);
if (! keychain)
{
- vty_out (vty, "Can't find keychain %s%s", argv[0], VTY_NEWLINE);
+ vty_out (vty, "Can't find keychain %s%s", argv[idx_word]->arg, VTY_NEWLINE);
return CMD_WARNING;
}
@@ -280,33 +282,35 @@ DEFUN (no_key_chain,
DEFUN (key,
key_cmd,
- "key <0-2147483647>",
+ "key (0-2147483647)",
"Configure a key\n"
"Key identifier number\n")
{
+ int idx_number = 1;
VTY_DECLVAR_CONTEXT (keychain, keychain);
struct key *key;
u_int32_t index;
- VTY_GET_INTEGER ("key identifier", index, argv[0]);
+ VTY_GET_INTEGER ("key identifier", index, argv[idx_number]->arg);
key = key_get (keychain, index);
VTY_PUSH_CONTEXT_SUB (KEYCHAIN_KEY_NODE, key);
-
+
return CMD_SUCCESS;
}
DEFUN (no_key,
no_key_cmd,
- "no key <0-2147483647>",
+ "no key (0-2147483647)",
NO_STR
"Delete a key\n"
"Key identifier number\n")
{
+ int idx_number = 2;
VTY_DECLVAR_CONTEXT (keychain, keychain);
struct key *key;
u_int32_t index;
-
- VTY_GET_INTEGER ("key identifier", index, argv[0]);
+
+ VTY_GET_INTEGER ("key identifier", index, argv[idx_number]->arg);
key = key_lookup (keychain, index);
if (! key)
{
@@ -327,11 +331,12 @@ DEFUN (key_string,
"Set key string\n"
"The key\n")
{
+ int idx_line = 1;
VTY_DECLVAR_CONTEXT_SUB (key, key);
if (key->string)
XFREE(MTYPE_KEY, key->string);
- key->string = XSTRDUP(MTYPE_KEY, argv[0]);
+ key->string = XSTRDUP(MTYPE_KEY, argv[idx_line]->arg);
return CMD_SUCCESS;
}
@@ -541,7 +546,7 @@ key_lifetime_infinite_set (struct vty *vty, struct key_range *krange,
DEFUN (accept_lifetime_day_month_day_month,
accept_lifetime_day_month_day_month_cmd,
- "accept-lifetime HH:MM:SS <1-31> MONTH <1993-2035> HH:MM:SS <1-31> MONTH <1993-2035>",
+ "accept-lifetime HH:MM:SS (1-31) MONTH (1993-2035) HH:MM:SS (1-31) MONTH (1993-2035)",
"Set accept lifetime of the key\n"
"Time to start\n"
"Day of th month to start\n"
@@ -552,15 +557,23 @@ DEFUN (accept_lifetime_day_month_day_month,
"Month of the year to expire\n"
"Year to expire\n")
{
+ int idx_hhmmss = 1;
+ int idx_number = 2;
+ int idx_month = 3;
+ int idx_number_2 = 4;
+ int idx_hhmmss_2 = 5;
+ int idx_number_3 = 6;
+ int idx_month_2 = 7;
+ int idx_number_4 = 8;
VTY_DECLVAR_CONTEXT_SUB (key, key);
- return key_lifetime_set (vty, &key->accept, argv[0], argv[1], argv[2],
- argv[3], argv[4], argv[5], argv[6], argv[7]);
+ return key_lifetime_set (vty, &key->accept, argv[idx_hhmmss]->arg, argv[idx_number]->arg, argv[idx_month]->arg,
+ argv[idx_number_2]->arg, argv[idx_hhmmss_2]->arg, argv[idx_number_3]->arg, argv[idx_month_2]->arg, argv[idx_number_4]->arg);
}
DEFUN (accept_lifetime_day_month_month_day,
accept_lifetime_day_month_month_day_cmd,
- "accept-lifetime HH:MM:SS <1-31> MONTH <1993-2035> HH:MM:SS MONTH <1-31> <1993-2035>",
+ "accept-lifetime HH:MM:SS (1-31) MONTH (1993-2035) HH:MM:SS MONTH (1-31) (1993-2035)",
"Set accept lifetime of the key\n"
"Time to start\n"
"Day of th month to start\n"
@@ -571,15 +584,23 @@ DEFUN (accept_lifetime_day_month_month_day,
"Day of th month to expire\n"
"Year to expire\n")
{
+ int idx_hhmmss = 1;
+ int idx_number = 2;
+ int idx_month = 3;
+ int idx_number_2 = 4;
+ int idx_hhmmss_2 = 5;
+ int idx_month_2 = 6;
+ int idx_number_3 = 7;
+ int idx_number_4 = 8;
VTY_DECLVAR_CONTEXT_SUB (key, key);
- return key_lifetime_set (vty, &key->accept, argv[0], argv[1], argv[2],
- argv[3], argv[4], argv[6], argv[5], argv[7]);
+ return key_lifetime_set (vty, &key->accept, argv[idx_hhmmss]->arg, argv[idx_number]->arg, argv[idx_month]->arg,
+ argv[idx_number_2]->arg, argv[idx_hhmmss_2]->arg, argv[idx_number_3]->arg, argv[idx_month_2]->arg, argv[idx_number_4]->arg);
}
DEFUN (accept_lifetime_month_day_day_month,
accept_lifetime_month_day_day_month_cmd,
- "accept-lifetime HH:MM:SS MONTH <1-31> <1993-2035> HH:MM:SS <1-31> MONTH <1993-2035>",
+ "accept-lifetime HH:MM:SS MONTH (1-31) (1993-2035) HH:MM:SS (1-31) MONTH (1993-2035)",
"Set accept lifetime of the key\n"
"Time to start\n"
"Month of the year to start\n"
@@ -590,15 +611,23 @@ DEFUN (accept_lifetime_month_day_day_month,
"Month of the year to expire\n"
"Year to expire\n")
{
+ int idx_hhmmss = 1;
+ int idx_month = 2;
+ int idx_number = 3;
+ int idx_number_2 = 4;
+ int idx_hhmmss_2 = 5;
+ int idx_number_3 = 6;
+ int idx_month_2 = 7;
+ int idx_number_4 = 8;
VTY_DECLVAR_CONTEXT_SUB (key, key);
- return key_lifetime_set (vty, &key->accept, argv[0], argv[2], argv[1],
- argv[3], argv[4], argv[5], argv[6], argv[7]);
+ return key_lifetime_set (vty, &key->accept, argv[idx_hhmmss]->arg, argv[idx_number]->arg, argv[idx_month]->arg,
+ argv[idx_number_2]->arg, argv[idx_hhmmss_2]->arg, argv[idx_number_3]->arg, argv[idx_month_2]->arg, argv[idx_number_4]->arg);
}
DEFUN (accept_lifetime_month_day_month_day,
accept_lifetime_month_day_month_day_cmd,
- "accept-lifetime HH:MM:SS MONTH <1-31> <1993-2035> HH:MM:SS MONTH <1-31> <1993-2035>",
+ "accept-lifetime HH:MM:SS MONTH (1-31) (1993-2035) HH:MM:SS MONTH (1-31) (1993-2035)",
"Set accept lifetime of the key\n"
"Time to start\n"
"Month of the year to start\n"
@@ -609,15 +638,23 @@ DEFUN (accept_lifetime_month_day_month_day,
"Day of th month to expire\n"
"Year to expire\n")
{
+ int idx_hhmmss = 1;
+ int idx_month = 2;
+ int idx_number = 3;
+ int idx_number_2 = 4;
+ int idx_hhmmss_2 = 5;
+ int idx_month_2 = 6;
+ int idx_number_3 = 7;
+ int idx_number_4 = 8;
VTY_DECLVAR_CONTEXT_SUB (key, key);
- return key_lifetime_set (vty, &key->accept, argv[0], argv[2], argv[1],
- argv[3], argv[4], argv[6], argv[5], argv[7]);
+ return key_lifetime_set (vty, &key->accept, argv[idx_hhmmss]->arg, argv[idx_number]->arg, argv[idx_month]->arg,
+ argv[idx_number_2]->arg, argv[idx_hhmmss_2]->arg, argv[idx_number_3]->arg, argv[idx_month_2]->arg, argv[idx_number_4]->arg);
}
DEFUN (accept_lifetime_infinite_day_month,
accept_lifetime_infinite_day_month_cmd,
- "accept-lifetime HH:MM:SS <1-31> MONTH <1993-2035> infinite",
+ "accept-lifetime HH:MM:SS (1-31) MONTH (1993-2035) infinite",
"Set accept lifetime of the key\n"
"Time to start\n"
"Day of th month to start\n"
@@ -625,15 +662,19 @@ DEFUN (accept_lifetime_infinite_day_month,
"Year to start\n"
"Never expires")
{
+ int idx_hhmmss = 1;
+ int idx_number = 2;
+ int idx_month = 3;
+ int idx_number_2 = 4;
VTY_DECLVAR_CONTEXT_SUB (key, key);
- return key_lifetime_infinite_set (vty, &key->accept, argv[0], argv[1],
- argv[2], argv[3]);
+ return key_lifetime_infinite_set (vty, &key->accept, argv[idx_hhmmss]->arg, argv[idx_number]->arg,
+ argv[idx_month]->arg, argv[idx_number_2]->arg);
}
DEFUN (accept_lifetime_infinite_month_day,
accept_lifetime_infinite_month_day_cmd,
- "accept-lifetime HH:MM:SS MONTH <1-31> <1993-2035> infinite",
+ "accept-lifetime HH:MM:SS MONTH (1-31) (1993-2035) infinite",
"Set accept lifetime of the key\n"
"Time to start\n"
"Month of the year to start\n"
@@ -641,15 +682,19 @@ DEFUN (accept_lifetime_infinite_month_day,
"Year to start\n"
"Never expires")
{
+ int idx_hhmmss = 1;
+ int idx_month = 2;
+ int idx_number = 3;
+ int idx_number_2 = 4;
VTY_DECLVAR_CONTEXT_SUB (key, key);
- return key_lifetime_infinite_set (vty, &key->accept, argv[0], argv[2],
- argv[1], argv[3]);
+ return key_lifetime_infinite_set (vty, &key->accept, argv[idx_hhmmss]->arg, argv[idx_number]->arg,
+ argv[idx_month]->arg, argv[idx_number_2]->arg);
}
DEFUN (accept_lifetime_duration_day_month,
accept_lifetime_duration_day_month_cmd,
- "accept-lifetime HH:MM:SS <1-31> MONTH <1993-2035> duration <1-2147483646>",
+ "accept-lifetime HH:MM:SS (1-31) MONTH (1993-2035) duration (1-2147483646)",
"Set accept lifetime of the key\n"
"Time to start\n"
"Day of th month to start\n"
@@ -658,15 +703,20 @@ DEFUN (accept_lifetime_duration_day_month,
"Duration of the key\n"
"Duration seconds\n")
{
+ int idx_hhmmss = 1;
+ int idx_number = 2;
+ int idx_month = 3;
+ int idx_number_2 = 4;
+ int idx_number_3 = 6;
VTY_DECLVAR_CONTEXT_SUB (key, key);
- return key_lifetime_duration_set (vty, &key->accept, argv[0], argv[1],
- argv[2], argv[3], argv[4]);
+ return key_lifetime_duration_set (vty, &key->accept, argv[idx_hhmmss]->arg, argv[idx_number]->arg,
+ argv[idx_month]->arg, argv[idx_number_2]->arg, argv[idx_number_3]->arg);
}
DEFUN (accept_lifetime_duration_month_day,
accept_lifetime_duration_month_day_cmd,
- "accept-lifetime HH:MM:SS MONTH <1-31> <1993-2035> duration <1-2147483646>",
+ "accept-lifetime HH:MM:SS MONTH (1-31) (1993-2035) duration (1-2147483646)",
"Set accept lifetime of the key\n"
"Time to start\n"
"Month of the year to start\n"
@@ -675,15 +725,20 @@ DEFUN (accept_lifetime_duration_month_day,
"Duration of the key\n"
"Duration seconds\n")
{
+ int idx_hhmmss = 1;
+ int idx_month = 2;
+ int idx_number = 3;
+ int idx_number_2 = 4;
+ int idx_number_3 = 6;
VTY_DECLVAR_CONTEXT_SUB (key, key);
- return key_lifetime_duration_set (vty, &key->accept, argv[0], argv[2],
- argv[1], argv[3], argv[4]);
+ return key_lifetime_duration_set (vty, &key->accept, argv[idx_hhmmss]->arg, argv[idx_number]->arg,
+ argv[idx_month]->arg, argv[idx_number_2]->arg, argv[idx_number_3]->arg);
}
DEFUN (send_lifetime_day_month_day_month,
send_lifetime_day_month_day_month_cmd,
- "send-lifetime HH:MM:SS <1-31> MONTH <1993-2035> HH:MM:SS <1-31> MONTH <1993-2035>",
+ "send-lifetime HH:MM:SS (1-31) MONTH (1993-2035) HH:MM:SS (1-31) MONTH (1993-2035)",
"Set send lifetime of the key\n"
"Time to start\n"
"Day of th month to start\n"
@@ -694,15 +749,23 @@ DEFUN (send_lifetime_day_month_day_month,
"Month of the year to expire\n"
"Year to expire\n")
{
+ int idx_hhmmss = 1;
+ int idx_number = 2;
+ int idx_month = 3;
+ int idx_number_2 = 4;
+ int idx_hhmmss_2 = 5;
+ int idx_number_3 = 6;
+ int idx_month_2 = 7;
+ int idx_number_4 = 8;
VTY_DECLVAR_CONTEXT_SUB (key, key);
- return key_lifetime_set (vty, &key->send, argv[0], argv[1], argv[2], argv[3],
- argv[4], argv[5], argv[6], argv[7]);
+ return key_lifetime_set (vty, &key->send, argv[idx_hhmmss]->arg, argv[idx_number]->arg, argv[idx_month]->arg, argv[idx_number_2]->arg,
+ argv[idx_hhmmss_2]->arg, argv[idx_number_3]->arg, argv[idx_month_2]->arg, argv[idx_number_4]->arg);
}
DEFUN (send_lifetime_day_month_month_day,
send_lifetime_day_month_month_day_cmd,
- "send-lifetime HH:MM:SS <1-31> MONTH <1993-2035> HH:MM:SS MONTH <1-31> <1993-2035>",
+ "send-lifetime HH:MM:SS (1-31) MONTH (1993-2035) HH:MM:SS MONTH (1-31) (1993-2035)",
"Set send lifetime of the key\n"
"Time to start\n"
"Day of th month to start\n"
@@ -713,15 +776,23 @@ DEFUN (send_lifetime_day_month_month_day,
"Day of th month to expire\n"
"Year to expire\n")
{
+ int idx_hhmmss = 1;
+ int idx_number = 2;
+ int idx_month = 3;
+ int idx_number_2 = 4;
+ int idx_hhmmss_2 = 5;
+ int idx_month_2 = 6;
+ int idx_number_3 = 7;
+ int idx_number_4 = 8;
VTY_DECLVAR_CONTEXT_SUB (key, key);
- return key_lifetime_set (vty, &key->send, argv[0], argv[1], argv[2], argv[3],
- argv[4], argv[6], argv[5], argv[7]);
+ return key_lifetime_set (vty, &key->send, argv[idx_hhmmss]->arg, argv[idx_number]->arg, argv[idx_month]->arg, argv[idx_number_2]->arg,
+ argv[idx_hhmmss_2]->arg, argv[idx_number_3]->arg, argv[idx_month_2]->arg, argv[idx_number_4]->arg);
}
DEFUN (send_lifetime_month_day_day_month,
send_lifetime_month_day_day_month_cmd,
- "send-lifetime HH:MM:SS MONTH <1-31> <1993-2035> HH:MM:SS <1-31> MONTH <1993-2035>",
+ "send-lifetime HH:MM:SS MONTH (1-31) (1993-2035) HH:MM:SS (1-31) MONTH (1993-2035)",
"Set send lifetime of the key\n"
"Time to start\n"
"Month of the year to start\n"
@@ -732,15 +803,23 @@ DEFUN (send_lifetime_month_day_day_month,
"Month of the year to expire\n"
"Year to expire\n")
{
+ int idx_hhmmss = 1;
+ int idx_month = 2;
+ int idx_number = 3;
+ int idx_number_2 = 4;
+ int idx_hhmmss_2 = 5;
+ int idx_number_3 = 6;
+ int idx_month_2 = 7;
+ int idx_number_4 = 8;
VTY_DECLVAR_CONTEXT_SUB (key, key);
- return key_lifetime_set (vty, &key->send, argv[0], argv[2], argv[1], argv[3],
- argv[4], argv[5], argv[6], argv[7]);
+ return key_lifetime_set (vty, &key->send, argv[idx_hhmmss]->arg, argv[idx_number]->arg, argv[idx_month]->arg, argv[idx_number_2]->arg,
+ argv[idx_hhmmss_2]->arg, argv[idx_number_3]->arg, argv[idx_month_2]->arg, argv[idx_number_4]->arg);
}
DEFUN (send_lifetime_month_day_month_day,
send_lifetime_month_day_month_day_cmd,
- "send-lifetime HH:MM:SS MONTH <1-31> <1993-2035> HH:MM:SS MONTH <1-31> <1993-2035>",
+ "send-lifetime HH:MM:SS MONTH (1-31) (1993-2035) HH:MM:SS MONTH (1-31) (1993-2035)",
"Set send lifetime of the key\n"
"Time to start\n"
"Month of the year to start\n"
@@ -751,15 +830,23 @@ DEFUN (send_lifetime_month_day_month_day,
"Day of th month to expire\n"
"Year to expire\n")
{
+ int idx_hhmmss = 1;
+ int idx_month = 2;
+ int idx_number = 3;
+ int idx_number_2 = 4;
+ int idx_hhmmss_2 = 5;
+ int idx_month_2 = 6;
+ int idx_number_3 = 7;
+ int idx_number_4 = 8;
VTY_DECLVAR_CONTEXT_SUB (key, key);
- return key_lifetime_set (vty, &key->send, argv[0], argv[2], argv[1], argv[3],
- argv[4], argv[6], argv[5], argv[7]);
+ return key_lifetime_set (vty, &key->send, argv[idx_hhmmss]->arg, argv[idx_number]->arg, argv[idx_month]->arg, argv[idx_number_2]->arg,
+ argv[idx_hhmmss_2]->arg, argv[idx_number_3]->arg, argv[idx_month_2]->arg, argv[idx_number_4]->arg);
}
DEFUN (send_lifetime_infinite_day_month,
send_lifetime_infinite_day_month_cmd,
- "send-lifetime HH:MM:SS <1-31> MONTH <1993-2035> infinite",
+ "send-lifetime HH:MM:SS (1-31) MONTH (1993-2035) infinite",
"Set send lifetime of the key\n"
"Time to start\n"
"Day of th month to start\n"
@@ -767,15 +854,19 @@ DEFUN (send_lifetime_infinite_day_month,
"Year to start\n"
"Never expires")
{
+ int idx_hhmmss = 1;
+ int idx_number = 2;
+ int idx_month = 3;
+ int idx_number_2 = 4;
VTY_DECLVAR_CONTEXT_SUB (key, key);
- return key_lifetime_infinite_set (vty, &key->send, argv[0], argv[1], argv[2],
- argv[3]);
+ return key_lifetime_infinite_set (vty, &key->send, argv[idx_hhmmss]->arg, argv[idx_number]->arg, argv[idx_month]->arg,
+ argv[idx_number_2]->arg);
}
DEFUN (send_lifetime_infinite_month_day,
send_lifetime_infinite_month_day_cmd,
- "send-lifetime HH:MM:SS MONTH <1-31> <1993-2035> infinite",
+ "send-lifetime HH:MM:SS MONTH (1-31) (1993-2035) infinite",
"Set send lifetime of the key\n"
"Time to start\n"
"Month of the year to start\n"
@@ -783,15 +874,19 @@ DEFUN (send_lifetime_infinite_month_day,
"Year to start\n"
"Never expires")
{
+ int idx_hhmmss = 1;
+ int idx_month = 2;
+ int idx_number = 3;
+ int idx_number_2 = 4;
VTY_DECLVAR_CONTEXT_SUB (key, key);
- return key_lifetime_infinite_set (vty, &key->send, argv[0], argv[2], argv[1],
- argv[3]);
+ return key_lifetime_infinite_set (vty, &key->send, argv[idx_hhmmss]->arg, argv[idx_number]->arg, argv[idx_month]->arg,
+ argv[idx_number_2]->arg);
}
DEFUN (send_lifetime_duration_day_month,
send_lifetime_duration_day_month_cmd,
- "send-lifetime HH:MM:SS <1-31> MONTH <1993-2035> duration <1-2147483646>",
+ "send-lifetime HH:MM:SS (1-31) MONTH (1993-2035) duration (1-2147483646)",
"Set send lifetime of the key\n"
"Time to start\n"
"Day of th month to start\n"
@@ -800,15 +895,20 @@ DEFUN (send_lifetime_duration_day_month,
"Duration of the key\n"
"Duration seconds\n")
{
+ int idx_hhmmss = 1;
+ int idx_number = 2;
+ int idx_month = 3;
+ int idx_number_2 = 4;
+ int idx_number_3 = 6;
VTY_DECLVAR_CONTEXT_SUB (key, key);
- return key_lifetime_duration_set (vty, &key->send, argv[0], argv[1], argv[2],
- argv[3], argv[4]);
+ return key_lifetime_duration_set (vty, &key->send, argv[idx_hhmmss]->arg, argv[idx_number]->arg, argv[idx_month]->arg,
+ argv[idx_number_2]->arg, argv[idx_number_3]->arg);
}
DEFUN (send_lifetime_duration_month_day,
send_lifetime_duration_month_day_cmd,
- "send-lifetime HH:MM:SS MONTH <1-31> <1993-2035> duration <1-2147483646>",
+ "send-lifetime HH:MM:SS MONTH (1-31) (1993-2035) duration (1-2147483646)",
"Set send lifetime of the key\n"
"Time to start\n"
"Month of the year to start\n"
@@ -817,10 +917,15 @@ DEFUN (send_lifetime_duration_month_day,
"Duration of the key\n"
"Duration seconds\n")
{
+ int idx_hhmmss = 1;
+ int idx_month = 2;
+ int idx_number = 3;
+ int idx_number_2 = 4;
+ int idx_number_3 = 6;
VTY_DECLVAR_CONTEXT_SUB (key, key);
- return key_lifetime_duration_set (vty, &key->send, argv[0], argv[2], argv[1],
- argv[3], argv[4]);
+ return key_lifetime_duration_set (vty, &key->send, argv[idx_hhmmss]->arg, argv[idx_number]->arg, argv[idx_month]->arg,
+ argv[idx_number_2]->arg, argv[idx_number_3]->arg);
}
static struct cmd_node keychain_node =
diff --git a/lib/log.h b/lib/log.h
index d71b85df1a..cd4cd1495a 100644
--- a/lib/log.h
+++ b/lib/log.h
@@ -204,8 +204,6 @@ struct timestamp_control {
/* Defines for use in command construction: */
-#define LOG_LEVELS "(emergencies|alerts|critical|errors|warnings|notifications|informational|debugging)"
-
#define LOG_LEVEL_DESC \
"System is unusable\n" \
"Immediate action needed\n" \
@@ -216,8 +214,6 @@ struct timestamp_control {
"Informational messages\n" \
"Debugging messages\n"
-#define LOG_FACILITIES "(kern|user|mail|daemon|auth|syslog|lpr|news|uucp|cron|local0|local1|local2|local3|local4|local5|local6|local7)"
-
#define LOG_FACILITY_DESC \
"Kernel\n" \
"User process\n" \
diff --git a/lib/ns.c b/lib/ns.c
index 556350ed17..d8db1e45a1 100644
--- a/lib/ns.c
+++ b/lib/ns.c
@@ -551,20 +551,22 @@ ns_netns_pathname (struct vty *vty, const char *name)
DEFUN (ns_netns,
ns_netns_cmd,
- "logical-router <1-65535> ns NAME",
+ "logical-router (1-65535) ns NAME",
"Enable a logical-router\n"
"Specify the logical-router indentifier\n"
"The Name Space\n"
"The file name in " NS_RUN_DIR ", or a full pathname\n")
{
+ int idx_number = 1;
+ int idx_name = 3;
ns_id_t ns_id = NS_DEFAULT;
struct ns *ns = NULL;
- char *pathname = ns_netns_pathname (vty, argv[1]);
+ char *pathname = ns_netns_pathname (vty, argv[idx_name]->arg);
if (!pathname)
return CMD_WARNING;
- VTY_GET_INTEGER ("NS ID", ns_id, argv[0]);
+ VTY_GET_INTEGER ("NS ID", ns_id, argv[idx_number]->arg);
ns = ns_get (ns_id);
if (ns->name && strcmp (ns->name, pathname) != 0)
@@ -589,21 +591,23 @@ DEFUN (ns_netns,
DEFUN (no_ns_netns,
no_ns_netns_cmd,
- "no logical-router <1-65535> ns NAME",
+ "no logical-router (1-65535) ns NAME",
NO_STR
"Enable a Logical-Router\n"
"Specify the Logical-Router identifier\n"
"The Name Space\n"
"The file name in " NS_RUN_DIR ", or a full pathname\n")
{
+ int idx_number = 2;
+ int idx_name = 4;
ns_id_t ns_id = NS_DEFAULT;
struct ns *ns = NULL;
- char *pathname = ns_netns_pathname (vty, argv[1]);
+ char *pathname = ns_netns_pathname (vty, argv[idx_name]->arg);
if (!pathname)
return CMD_WARNING;
- VTY_GET_INTEGER ("NS ID", ns_id, argv[0]);
+ VTY_GET_INTEGER ("NS ID", ns_id, argv[idx_number]->arg);
ns = ns_lookup (ns_id);
if (!ns)
diff --git a/lib/plist.c b/lib/plist.c
index 2b93d880f6..a854ad52b3 100644
--- a/lib/plist.c
+++ b/lib/plist.c
@@ -20,7 +20,6 @@
*/
#include <zebra.h>
-#include "lib/json.h"
#include "prefix.h"
#include "command.h"
@@ -31,6 +30,7 @@
#include "stream.h"
#include "log.h"
#include "routemap.h"
+#include "lib/json.h"
#include "plist_int.h"
@@ -1420,7 +1420,7 @@ vty_clear_prefix_list (struct vty *vty, afi_t afi, const char *name,
DEFUN (ip_prefix_list,
ip_prefix_list_cmd,
- "ip prefix-list WORD (deny|permit) (A.B.C.D/M|any)",
+ "ip prefix-list WORD <deny|permit> <A.B.C.D/M|any>",
IP_STR
PREFIX_LIST_STR
"Name of a prefix list\n"
@@ -1429,13 +1429,16 @@ DEFUN (ip_prefix_list,
"IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
"Any prefix match. Same as \"0.0.0.0/0 le 32\"\n")
{
- return vty_prefix_list_install (vty, AFI_IP, argv[0], NULL,
- argv[1], argv[2], NULL, NULL);
+ int idx_word = 2;
+ int idx_permit_deny = 3;
+ int idx_ipv4_any = 4;
+ return vty_prefix_list_install (vty, AFI_IP, argv[idx_word]->arg, NULL,
+ argv[idx_permit_deny]->arg, argv[idx_ipv4_any]->arg, NULL, NULL);
}
DEFUN (ip_prefix_list_ge,
ip_prefix_list_ge_cmd,
- "ip prefix-list WORD (deny|permit) A.B.C.D/M ge <0-32>",
+ "ip prefix-list WORD <deny|permit> A.B.C.D/M ge (0-32)",
IP_STR
PREFIX_LIST_STR
"Name of a prefix list\n"
@@ -1445,13 +1448,17 @@ DEFUN (ip_prefix_list_ge,
"Minimum prefix length to be matched\n"
"Minimum prefix length\n")
{
- return vty_prefix_list_install (vty, AFI_IP, argv[0], NULL, argv[1],
- argv[2], argv[3], NULL);
+ int idx_word = 2;
+ int idx_permit_deny = 3;
+ int idx_ipv4_prefixlen = 4;
+ int idx_number = 6;
+ return vty_prefix_list_install (vty, AFI_IP, argv[idx_word]->arg, NULL, argv[idx_permit_deny]->arg,
+ argv[idx_ipv4_prefixlen]->arg, argv[idx_number]->arg, NULL);
}
DEFUN (ip_prefix_list_ge_le,
ip_prefix_list_ge_le_cmd,
- "ip prefix-list WORD (deny|permit) A.B.C.D/M ge <0-32> le <0-32>",
+ "ip prefix-list WORD <deny|permit> A.B.C.D/M ge (0-32) le (0-32)",
IP_STR
PREFIX_LIST_STR
"Name of a prefix list\n"
@@ -1463,13 +1470,18 @@ DEFUN (ip_prefix_list_ge_le,
"Maximum prefix length to be matched\n"
"Maximum prefix length\n")
{
- return vty_prefix_list_install (vty, AFI_IP, argv[0], NULL, argv[1],
- argv[2], argv[3], argv[4]);
+ int idx_word = 2;
+ int idx_permit_deny = 3;
+ int idx_ipv4_prefixlen = 4;
+ int idx_number = 6;
+ int idx_number_2 = 8;
+ return vty_prefix_list_install (vty, AFI_IP, argv[idx_word]->arg, NULL, argv[idx_permit_deny]->arg,
+ argv[idx_ipv4_prefixlen]->arg, argv[idx_number]->arg, argv[idx_number_2]->arg);
}
DEFUN (ip_prefix_list_le,
ip_prefix_list_le_cmd,
- "ip prefix-list WORD (deny|permit) A.B.C.D/M le <0-32>",
+ "ip prefix-list WORD <deny|permit> A.B.C.D/M le (0-32)",
IP_STR
PREFIX_LIST_STR
"Name of a prefix list\n"
@@ -1479,13 +1491,17 @@ DEFUN (ip_prefix_list_le,
"Maximum prefix length to be matched\n"
"Maximum prefix length\n")
{
- return vty_prefix_list_install (vty, AFI_IP, argv[0], NULL, argv[1],
- argv[2], NULL, argv[3]);
+ int idx_word = 2;
+ int idx_permit_deny = 3;
+ int idx_ipv4_prefixlen = 4;
+ int idx_number = 6;
+ return vty_prefix_list_install (vty, AFI_IP, argv[idx_word]->arg, NULL, argv[idx_permit_deny]->arg,
+ argv[idx_ipv4_prefixlen]->arg, NULL, argv[idx_number]->arg);
}
DEFUN (ip_prefix_list_le_ge,
ip_prefix_list_le_ge_cmd,
- "ip prefix-list WORD (deny|permit) A.B.C.D/M le <0-32> ge <0-32>",
+ "ip prefix-list WORD <deny|permit> A.B.C.D/M le (0-32) ge (0-32)",
IP_STR
PREFIX_LIST_STR
"Name of a prefix list\n"
@@ -1497,13 +1513,18 @@ DEFUN (ip_prefix_list_le_ge,
"Minimum prefix length to be matched\n"
"Minimum prefix length\n")
{
- return vty_prefix_list_install (vty, AFI_IP, argv[0], NULL, argv[1],
- argv[2], argv[4], argv[3]);
+ int idx_word = 2;
+ int idx_permit_deny = 3;
+ int idx_ipv4_prefixlen = 4;
+ int idx_number = 6;
+ int idx_number_2 = 8;
+ return vty_prefix_list_install (vty, AFI_IP, argv[idx_word]->arg, NULL, argv[idx_permit_deny]->arg,
+ argv[idx_ipv4_prefixlen]->arg, argv[idx_number_2]->arg, argv[idx_number]->arg);
}
DEFUN (ip_prefix_list_seq,
ip_prefix_list_seq_cmd,
- "ip prefix-list WORD seq <1-4294967295> (deny|permit) (A.B.C.D/M|any)",
+ "ip prefix-list WORD seq (1-4294967295) <deny|permit> <A.B.C.D/M|any>",
IP_STR
PREFIX_LIST_STR
"Name of a prefix list\n"
@@ -1514,13 +1535,17 @@ DEFUN (ip_prefix_list_seq,
"IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
"Any prefix match. Same as \"0.0.0.0/0 le 32\"\n")
{
- return vty_prefix_list_install (vty, AFI_IP, argv[0], argv[1], argv[2],
- argv[3], NULL, NULL);
+ int idx_word = 2;
+ int idx_number = 4;
+ int idx_permit_deny = 5;
+ int idx_ipv4_any = 6;
+ return vty_prefix_list_install (vty, AFI_IP, argv[idx_word]->arg, argv[idx_number]->arg, argv[idx_permit_deny]->arg,
+ argv[idx_ipv4_any]->arg, NULL, NULL);
}
DEFUN (ip_prefix_list_seq_ge,
ip_prefix_list_seq_ge_cmd,
- "ip prefix-list WORD seq <1-4294967295> (deny|permit) A.B.C.D/M ge <0-32>",
+ "ip prefix-list WORD seq (1-4294967295) <deny|permit> A.B.C.D/M ge (0-32)",
IP_STR
PREFIX_LIST_STR
"Name of a prefix list\n"
@@ -1532,13 +1557,18 @@ DEFUN (ip_prefix_list_seq_ge,
"Minimum prefix length to be matched\n"
"Minimum prefix length\n")
{
- return vty_prefix_list_install (vty, AFI_IP, argv[0], argv[1], argv[2],
- argv[3], argv[4], NULL);
+ int idx_word = 2;
+ int idx_number = 4;
+ int idx_permit_deny = 5;
+ int idx_ipv4_prefixlen = 6;
+ int idx_number_2 = 8;
+ return vty_prefix_list_install (vty, AFI_IP, argv[idx_word]->arg, argv[idx_number]->arg, argv[idx_permit_deny]->arg,
+ argv[idx_ipv4_prefixlen]->arg, argv[idx_number_2]->arg, NULL);
}
DEFUN (ip_prefix_list_seq_ge_le,
ip_prefix_list_seq_ge_le_cmd,
- "ip prefix-list WORD seq <1-4294967295> (deny|permit) A.B.C.D/M ge <0-32> le <0-32>",
+ "ip prefix-list WORD seq (1-4294967295) <deny|permit> A.B.C.D/M ge (0-32) le (0-32)",
IP_STR
PREFIX_LIST_STR
"Name of a prefix list\n"
@@ -1552,13 +1582,19 @@ DEFUN (ip_prefix_list_seq_ge_le,
"Maximum prefix length to be matched\n"
"Maximum prefix length\n")
{
- return vty_prefix_list_install (vty, AFI_IP, argv[0], argv[1], argv[2],
- argv[3], argv[4], argv[5]);
+ int idx_word = 2;
+ int idx_number = 4;
+ int idx_permit_deny = 5;
+ int idx_ipv4_prefixlen = 6;
+ int idx_number_2 = 8;
+ int idx_number_3 = 10;
+ return vty_prefix_list_install (vty, AFI_IP, argv[idx_word]->arg, argv[idx_number]->arg, argv[idx_permit_deny]->arg,
+ argv[idx_ipv4_prefixlen]->arg, argv[idx_number_2]->arg, argv[idx_number_3]->arg);
}
DEFUN (ip_prefix_list_seq_le,
ip_prefix_list_seq_le_cmd,
- "ip prefix-list WORD seq <1-4294967295> (deny|permit) A.B.C.D/M le <0-32>",
+ "ip prefix-list WORD seq (1-4294967295) <deny|permit> A.B.C.D/M le (0-32)",
IP_STR
PREFIX_LIST_STR
"Name of a prefix list\n"
@@ -1570,13 +1606,18 @@ DEFUN (ip_prefix_list_seq_le,
"Maximum prefix length to be matched\n"
"Maximum prefix length\n")
{
- return vty_prefix_list_install (vty, AFI_IP, argv[0], argv[1], argv[2],
- argv[3], NULL, argv[4]);
+ int idx_word = 2;
+ int idx_number = 4;
+ int idx_permit_deny = 5;
+ int idx_ipv4_prefixlen = 6;
+ int idx_number_2 = 8;
+ return vty_prefix_list_install (vty, AFI_IP, argv[idx_word]->arg, argv[idx_number]->arg, argv[idx_permit_deny]->arg,
+ argv[idx_ipv4_prefixlen]->arg, NULL, argv[idx_number_2]->arg);
}
DEFUN (ip_prefix_list_seq_le_ge,
ip_prefix_list_seq_le_ge_cmd,
- "ip prefix-list WORD seq <1-4294967295> (deny|permit) A.B.C.D/M le <0-32> ge <0-32>",
+ "ip prefix-list WORD seq (1-4294967295) <deny|permit> A.B.C.D/M le (0-32) ge (0-32)",
IP_STR
PREFIX_LIST_STR
"Name of a prefix list\n"
@@ -1590,8 +1631,14 @@ DEFUN (ip_prefix_list_seq_le_ge,
"Minimum prefix length to be matched\n"
"Minimum prefix length\n")
{
- return vty_prefix_list_install (vty, AFI_IP, argv[0], argv[1], argv[2],
- argv[3], argv[5], argv[4]);
+ int idx_word = 2;
+ int idx_number = 4;
+ int idx_permit_deny = 5;
+ int idx_ipv4_prefixlen = 6;
+ int idx_number_2 = 8;
+ int idx_number_3 = 10;
+ return vty_prefix_list_install (vty, AFI_IP, argv[idx_word]->arg, argv[idx_number]->arg, argv[idx_permit_deny]->arg,
+ argv[idx_ipv4_prefixlen]->arg, argv[idx_number_3]->arg, argv[idx_number_2]->arg);
}
DEFUN (no_ip_prefix_list,
@@ -1602,13 +1649,14 @@ DEFUN (no_ip_prefix_list,
PREFIX_LIST_STR
"Name of a prefix list\n")
{
- return vty_prefix_list_uninstall (vty, AFI_IP, argv[0], NULL, NULL,
+ int idx_word = 3;
+ return vty_prefix_list_uninstall (vty, AFI_IP, argv[idx_word]->arg, NULL, NULL,
NULL, NULL, NULL);
}
DEFUN (no_ip_prefix_list_prefix,
no_ip_prefix_list_prefix_cmd,
- "no ip prefix-list WORD (deny|permit) (A.B.C.D/M|any)",
+ "no ip prefix-list WORD <deny|permit> <A.B.C.D/M|any>",
NO_STR
IP_STR
PREFIX_LIST_STR
@@ -1618,13 +1666,16 @@ DEFUN (no_ip_prefix_list_prefix,
"IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
"Any prefix match. Same as \"0.0.0.0/0 le 32\"\n")
{
- return vty_prefix_list_uninstall (vty, AFI_IP, argv[0], NULL, argv[1],
- argv[2], NULL, NULL);
+ int idx_word = 3;
+ int idx_permit_deny = 4;
+ int idx_ipv4_any = 5;
+ return vty_prefix_list_uninstall (vty, AFI_IP, argv[idx_word]->arg, NULL, argv[idx_permit_deny]->arg,
+ argv[idx_ipv4_any]->arg, NULL, NULL);
}
DEFUN (no_ip_prefix_list_ge,
no_ip_prefix_list_ge_cmd,
- "no ip prefix-list WORD (deny|permit) A.B.C.D/M ge <0-32>",
+ "no ip prefix-list WORD <deny|permit> A.B.C.D/M ge (0-32)",
NO_STR
IP_STR
PREFIX_LIST_STR
@@ -1635,13 +1686,17 @@ DEFUN (no_ip_prefix_list_ge,
"Minimum prefix length to be matched\n"
"Minimum prefix length\n")
{
- return vty_prefix_list_uninstall (vty, AFI_IP, argv[0], NULL, argv[1],
- argv[2], argv[3], NULL);
+ int idx_word = 3;
+ int idx_permit_deny = 4;
+ int idx_ipv4_prefixlen = 5;
+ int idx_number = 7;
+ return vty_prefix_list_uninstall (vty, AFI_IP, argv[idx_word]->arg, NULL, argv[idx_permit_deny]->arg,
+ argv[idx_ipv4_prefixlen]->arg, argv[idx_number]->arg, NULL);
}
DEFUN (no_ip_prefix_list_ge_le,
no_ip_prefix_list_ge_le_cmd,
- "no ip prefix-list WORD (deny|permit) A.B.C.D/M ge <0-32> le <0-32>",
+ "no ip prefix-list WORD <deny|permit> A.B.C.D/M ge (0-32) le (0-32)",
NO_STR
IP_STR
PREFIX_LIST_STR
@@ -1654,13 +1709,18 @@ DEFUN (no_ip_prefix_list_ge_le,
"Maximum prefix length to be matched\n"
"Maximum prefix length\n")
{
- return vty_prefix_list_uninstall (vty, AFI_IP, argv[0], NULL, argv[1],
- argv[2], argv[3], argv[4]);
+ int idx_word = 3;
+ int idx_permit_deny = 4;
+ int idx_ipv4_prefixlen = 5;
+ int idx_number = 7;
+ int idx_number_2 = 9;
+ return vty_prefix_list_uninstall (vty, AFI_IP, argv[idx_word]->arg, NULL, argv[idx_permit_deny]->arg,
+ argv[idx_ipv4_prefixlen]->arg, argv[idx_number]->arg, argv[idx_number_2]->arg);
}
DEFUN (no_ip_prefix_list_le,
no_ip_prefix_list_le_cmd,
- "no ip prefix-list WORD (deny|permit) A.B.C.D/M le <0-32>",
+ "no ip prefix-list WORD <deny|permit> A.B.C.D/M le (0-32)",
NO_STR
IP_STR
PREFIX_LIST_STR
@@ -1671,13 +1731,17 @@ DEFUN (no_ip_prefix_list_le,
"Maximum prefix length to be matched\n"
"Maximum prefix length\n")
{
- return vty_prefix_list_uninstall (vty, AFI_IP, argv[0], NULL, argv[1],
- argv[2], NULL, argv[3]);
+ int idx_word = 3;
+ int idx_permit_deny = 4;
+ int idx_ipv4_prefixlen = 5;
+ int idx_number = 7;
+ return vty_prefix_list_uninstall (vty, AFI_IP, argv[idx_word]->arg, NULL, argv[idx_permit_deny]->arg,
+ argv[idx_ipv4_prefixlen]->arg, NULL, argv[idx_number]->arg);
}
DEFUN (no_ip_prefix_list_le_ge,
no_ip_prefix_list_le_ge_cmd,
- "no ip prefix-list WORD (deny|permit) A.B.C.D/M le <0-32> ge <0-32>",
+ "no ip prefix-list WORD <deny|permit> A.B.C.D/M le (0-32) ge (0-32)",
NO_STR
IP_STR
PREFIX_LIST_STR
@@ -1690,13 +1754,18 @@ DEFUN (no_ip_prefix_list_le_ge,
"Minimum prefix length to be matched\n"
"Minimum prefix length\n")
{
- return vty_prefix_list_uninstall (vty, AFI_IP, argv[0], NULL, argv[1],
- argv[2], argv[4], argv[3]);
+ int idx_word = 3;
+ int idx_permit_deny = 4;
+ int idx_ipv4_prefixlen = 5;
+ int idx_number = 7;
+ int idx_number_2 = 9;
+ return vty_prefix_list_uninstall (vty, AFI_IP, argv[idx_word]->arg, NULL, argv[idx_permit_deny]->arg,
+ argv[idx_ipv4_prefixlen]->arg, argv[idx_number_2]->arg, argv[idx_number]->arg);
}
DEFUN (no_ip_prefix_list_seq,
no_ip_prefix_list_seq_cmd,
- "no ip prefix-list WORD seq <1-4294967295> (deny|permit) (A.B.C.D/M|any)",
+ "no ip prefix-list WORD seq (1-4294967295) <deny|permit> <A.B.C.D/M|any>",
NO_STR
IP_STR
PREFIX_LIST_STR
@@ -1708,13 +1777,17 @@ DEFUN (no_ip_prefix_list_seq,
"IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
"Any prefix match. Same as \"0.0.0.0/0 le 32\"\n")
{
- return vty_prefix_list_uninstall (vty, AFI_IP, argv[0], argv[1], argv[2],
- argv[3], NULL, NULL);
+ int idx_word = 3;
+ int idx_number = 5;
+ int idx_permit_deny = 6;
+ int idx_ipv4_any = 7;
+ return vty_prefix_list_uninstall (vty, AFI_IP, argv[idx_word]->arg, argv[idx_number]->arg, argv[idx_permit_deny]->arg,
+ argv[idx_ipv4_any]->arg, NULL, NULL);
}
DEFUN (no_ip_prefix_list_seq_ge,
no_ip_prefix_list_seq_ge_cmd,
- "no ip prefix-list WORD seq <1-4294967295> (deny|permit) A.B.C.D/M ge <0-32>",
+ "no ip prefix-list WORD seq (1-4294967295) <deny|permit> A.B.C.D/M ge (0-32)",
NO_STR
IP_STR
PREFIX_LIST_STR
@@ -1727,13 +1800,18 @@ DEFUN (no_ip_prefix_list_seq_ge,
"Minimum prefix length to be matched\n"
"Minimum prefix length\n")
{
- return vty_prefix_list_uninstall (vty, AFI_IP, argv[0], argv[1], argv[2],
- argv[3], argv[4], NULL);
+ int idx_word = 3;
+ int idx_number = 5;
+ int idx_permit_deny = 6;
+ int idx_ipv4_prefixlen = 7;
+ int idx_number_2 = 9;
+ return vty_prefix_list_uninstall (vty, AFI_IP, argv[idx_word]->arg, argv[idx_number]->arg, argv[idx_permit_deny]->arg,
+ argv[idx_ipv4_prefixlen]->arg, argv[idx_number_2]->arg, NULL);
}
DEFUN (no_ip_prefix_list_seq_ge_le,
no_ip_prefix_list_seq_ge_le_cmd,
- "no ip prefix-list WORD seq <1-4294967295> (deny|permit) A.B.C.D/M ge <0-32> le <0-32>",
+ "no ip prefix-list WORD seq (1-4294967295) <deny|permit> A.B.C.D/M ge (0-32) le (0-32)",
NO_STR
IP_STR
PREFIX_LIST_STR
@@ -1748,13 +1826,19 @@ DEFUN (no_ip_prefix_list_seq_ge_le,
"Maximum prefix length to be matched\n"
"Maximum prefix length\n")
{
- return vty_prefix_list_uninstall (vty, AFI_IP, argv[0], argv[1], argv[2],
- argv[3], argv[4], argv[5]);
+ int idx_word = 3;
+ int idx_number = 5;
+ int idx_permit_deny = 6;
+ int idx_ipv4_prefixlen = 7;
+ int idx_number_2 = 9;
+ int idx_number_3 = 11;
+ return vty_prefix_list_uninstall (vty, AFI_IP, argv[idx_word]->arg, argv[idx_number]->arg, argv[idx_permit_deny]->arg,
+ argv[idx_ipv4_prefixlen]->arg, argv[idx_number_2]->arg, argv[idx_number_3]->arg);
}
DEFUN (no_ip_prefix_list_seq_le,
no_ip_prefix_list_seq_le_cmd,
- "no ip prefix-list WORD seq <1-4294967295> (deny|permit) A.B.C.D/M le <0-32>",
+ "no ip prefix-list WORD seq (1-4294967295) <deny|permit> A.B.C.D/M le (0-32)",
NO_STR
IP_STR
PREFIX_LIST_STR
@@ -1767,13 +1851,18 @@ DEFUN (no_ip_prefix_list_seq_le,
"Maximum prefix length to be matched\n"
"Maximum prefix length\n")
{
- return vty_prefix_list_uninstall (vty, AFI_IP, argv[0], argv[1], argv[2],
- argv[3], NULL, argv[4]);
+ int idx_word = 3;
+ int idx_number = 5;
+ int idx_permit_deny = 6;
+ int idx_ipv4_prefixlen = 7;
+ int idx_number_2 = 9;
+ return vty_prefix_list_uninstall (vty, AFI_IP, argv[idx_word]->arg, argv[idx_number]->arg, argv[idx_permit_deny]->arg,
+ argv[idx_ipv4_prefixlen]->arg, NULL, argv[idx_number_2]->arg);
}
DEFUN (no_ip_prefix_list_seq_le_ge,
no_ip_prefix_list_seq_le_ge_cmd,
- "no ip prefix-list WORD seq <1-4294967295> (deny|permit) A.B.C.D/M le <0-32> ge <0-32>",
+ "no ip prefix-list WORD seq (1-4294967295) <deny|permit> A.B.C.D/M le (0-32) ge (0-32)",
NO_STR
IP_STR
PREFIX_LIST_STR
@@ -1788,8 +1877,14 @@ DEFUN (no_ip_prefix_list_seq_le_ge,
"Minimum prefix length to be matched\n"
"Minimum prefix length\n")
{
- return vty_prefix_list_uninstall (vty, AFI_IP, argv[0], argv[1], argv[2],
- argv[3], argv[5], argv[4]);
+ int idx_word = 3;
+ int idx_number = 5;
+ int idx_permit_deny = 6;
+ int idx_ipv4_prefixlen = 7;
+ int idx_number_2 = 9;
+ int idx_number_3 = 11;
+ return vty_prefix_list_uninstall (vty, AFI_IP, argv[idx_word]->arg, argv[idx_number]->arg, argv[idx_permit_deny]->arg,
+ argv[idx_ipv4_prefixlen]->arg, argv[idx_number_3]->arg, argv[idx_number_2]->arg);
}
DEFUN (ip_prefix_list_sequence_number,
@@ -1817,26 +1912,28 @@ DEFUN (no_ip_prefix_list_sequence_number,
DEFUN (ip_prefix_list_description,
ip_prefix_list_description_cmd,
- "ip prefix-list WORD description .LINE",
+ "ip prefix-list WORD description LINE...",
IP_STR
PREFIX_LIST_STR
"Name of a prefix list\n"
"Prefix-list specific description\n"
"Up to 80 characters describing this prefix-list\n")
{
+ int idx_word = 2;
+ int idx_line = 4;
struct prefix_list *plist;
- plist = prefix_list_get (AFI_IP, 0, argv[0]);
+ plist = prefix_list_get (AFI_IP, 0, argv[idx_word]->arg);
if (plist->desc)
{
XFREE (MTYPE_TMP, plist->desc);
plist->desc = NULL;
}
- plist->desc = argv_concat(argv, argc, 1);
+ plist->desc = argv_concat(argv, argc, idx_line);
return CMD_SUCCESS;
-}
+}
DEFUN (no_ip_prefix_list_description,
no_ip_prefix_list_description_cmd,
@@ -1847,18 +1944,23 @@ DEFUN (no_ip_prefix_list_description,
"Name of a prefix list\n"
"Prefix-list specific description\n")
{
- return vty_prefix_list_desc_unset (vty, AFI_IP, argv[0]);
+ int idx_word = 3;
+ return vty_prefix_list_desc_unset (vty, AFI_IP, argv[idx_word]->arg);
}
-ALIAS (no_ip_prefix_list_description,
- no_ip_prefix_list_description_arg_cmd,
- "no ip prefix-list WORD description .LINE",
+/* ALIAS_FIXME */
+DEFUN (no_ip_prefix_list_description_comment,
+ no_ip_prefix_list_description_comment_cmd,
+ "no ip prefix-list WORD description LINE...",
NO_STR
IP_STR
PREFIX_LIST_STR
"Name of a prefix list\n"
"Prefix-list specific description\n"
"Up to 80 characters describing this prefix-list\n")
+{
+ return no_ip_prefix_list_description (self, vty, argc, argv);
+}
DEFUN (show_ip_prefix_list,
show_ip_prefix_list_cmd,
@@ -1878,12 +1980,13 @@ DEFUN (show_ip_prefix_list_name,
PREFIX_LIST_STR
"Name of a prefix list\n")
{
- return vty_show_prefix_list (vty, AFI_IP, argv[0], NULL, normal_display);
+ int idx_word = 3;
+ return vty_show_prefix_list (vty, AFI_IP, argv[idx_word]->arg, NULL, normal_display);
}
DEFUN (show_ip_prefix_list_name_seq,
show_ip_prefix_list_name_seq_cmd,
- "show ip prefix-list WORD seq <1-4294967295>",
+ "show ip prefix-list WORD seq (1-4294967295)",
SHOW_STR
IP_STR
PREFIX_LIST_STR
@@ -1891,7 +1994,9 @@ DEFUN (show_ip_prefix_list_name_seq,
"sequence number of an entry\n"
"Sequence number\n")
{
- return vty_show_prefix_list (vty, AFI_IP, argv[0], argv[1], sequential_display);
+ int idx_word = 3;
+ int idx_number = 5;
+ return vty_show_prefix_list (vty, AFI_IP, argv[idx_word]->arg, argv[idx_number]->arg, sequential_display);
}
DEFUN (show_ip_prefix_list_prefix,
@@ -1903,7 +2008,9 @@ DEFUN (show_ip_prefix_list_prefix,
"Name of a prefix list\n"
"IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
{
- return vty_show_prefix_list_prefix (vty, AFI_IP, argv[0], argv[1], normal_display);
+ int idx_word = 3;
+ int idx_ipv4_prefixlen = 4;
+ return vty_show_prefix_list_prefix (vty, AFI_IP, argv[idx_word]->arg, argv[idx_ipv4_prefixlen]->arg, normal_display);
}
DEFUN (show_ip_prefix_list_prefix_longer,
@@ -1916,7 +2023,9 @@ DEFUN (show_ip_prefix_list_prefix_longer,
"IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
"Lookup longer prefix\n")
{
- return vty_show_prefix_list_prefix (vty, AFI_IP, argv[0], argv[1], longer_display);
+ int idx_word = 3;
+ int idx_ipv4_prefixlen = 4;
+ return vty_show_prefix_list_prefix (vty, AFI_IP, argv[idx_word]->arg, argv[idx_ipv4_prefixlen]->arg, longer_display);
}
DEFUN (show_ip_prefix_list_prefix_first_match,
@@ -1929,7 +2038,9 @@ DEFUN (show_ip_prefix_list_prefix_first_match,
"IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
"First matched prefix\n")
{
- return vty_show_prefix_list_prefix (vty, AFI_IP, argv[0], argv[1], first_match_display);
+ int idx_word = 3;
+ int idx_ipv4_prefixlen = 4;
+ return vty_show_prefix_list_prefix (vty, AFI_IP, argv[idx_word]->arg, argv[idx_ipv4_prefixlen]->arg, first_match_display);
}
DEFUN (show_ip_prefix_list_summary,
@@ -1952,7 +2063,8 @@ DEFUN (show_ip_prefix_list_summary_name,
"Summary of prefix lists\n"
"Name of a prefix list\n")
{
- return vty_show_prefix_list (vty, AFI_IP, argv[0], NULL, summary_display);
+ int idx_word = 4;
+ return vty_show_prefix_list (vty, AFI_IP, argv[idx_word]->arg, NULL, summary_display);
}
@@ -1976,7 +2088,8 @@ DEFUN (show_ip_prefix_list_detail_name,
"Detail of prefix lists\n"
"Name of a prefix list\n")
{
- return vty_show_prefix_list (vty, AFI_IP, argv[0], NULL, detail_display);
+ int idx_word = 4;
+ return vty_show_prefix_list (vty, AFI_IP, argv[idx_word]->arg, NULL, detail_display);
}
DEFUN (clear_ip_prefix_list,
@@ -1997,7 +2110,8 @@ DEFUN (clear_ip_prefix_list_name,
PREFIX_LIST_STR
"Name of a prefix list\n")
{
- return vty_clear_prefix_list (vty, AFI_IP, argv[0], NULL);
+ int idx_word = 3;
+ return vty_clear_prefix_list (vty, AFI_IP, argv[idx_word]->arg, NULL);
}
DEFUN (clear_ip_prefix_list_name_prefix,
@@ -2009,13 +2123,15 @@ DEFUN (clear_ip_prefix_list_name_prefix,
"Name of a prefix list\n"
"IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
{
- return vty_clear_prefix_list (vty, AFI_IP, argv[0], argv[1]);
+ int idx_word = 3;
+ int idx_ipv4_prefixlen = 4;
+ return vty_clear_prefix_list (vty, AFI_IP, argv[idx_word]->arg, argv[idx_ipv4_prefixlen]->arg);
}
#ifdef HAVE_IPV6
DEFUN (ipv6_prefix_list,
ipv6_prefix_list_cmd,
- "ipv6 prefix-list WORD (deny|permit) (X:X::X:X/M|any)",
+ "ipv6 prefix-list WORD <deny|permit> <X:X::X:X/M|any>",
IPV6_STR
PREFIX_LIST_STR
"Name of a prefix list\n"
@@ -2024,13 +2140,16 @@ DEFUN (ipv6_prefix_list,
"IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
"Any prefix match. Same as \"::0/0 le 128\"\n")
{
- return vty_prefix_list_install (vty, AFI_IP6, argv[0], NULL,
- argv[1], argv[2], NULL, NULL);
+ int idx_word = 2;
+ int idx_permit_deny = 3;
+ int idx_ipv6_any = 4;
+ return vty_prefix_list_install (vty, AFI_IP6, argv[idx_word]->arg, NULL,
+ argv[idx_permit_deny]->arg, argv[idx_ipv6_any]->arg, NULL, NULL);
}
DEFUN (ipv6_prefix_list_ge,
ipv6_prefix_list_ge_cmd,
- "ipv6 prefix-list WORD (deny|permit) X:X::X:X/M ge <0-128>",
+ "ipv6 prefix-list WORD <deny|permit> X:X::X:X/M ge (0-128)",
IPV6_STR
PREFIX_LIST_STR
"Name of a prefix list\n"
@@ -2040,13 +2159,17 @@ DEFUN (ipv6_prefix_list_ge,
"Minimum prefix length to be matched\n"
"Minimum prefix length\n")
{
- return vty_prefix_list_install (vty, AFI_IP6, argv[0], NULL, argv[1],
- argv[2], argv[3], NULL);
+ int idx_word = 2;
+ int idx_permit_deny = 3;
+ int idx_ipv6_prefixlen = 4;
+ int idx_number = 6;
+ return vty_prefix_list_install (vty, AFI_IP6, argv[idx_word]->arg, NULL, argv[idx_permit_deny]->arg,
+ argv[idx_ipv6_prefixlen]->arg, argv[idx_number]->arg, NULL);
}
DEFUN (ipv6_prefix_list_ge_le,
ipv6_prefix_list_ge_le_cmd,
- "ipv6 prefix-list WORD (deny|permit) X:X::X:X/M ge <0-128> le <0-128>",
+ "ipv6 prefix-list WORD <deny|permit> X:X::X:X/M ge (0-128) le (0-128)",
IPV6_STR
PREFIX_LIST_STR
"Name of a prefix list\n"
@@ -2059,13 +2182,18 @@ DEFUN (ipv6_prefix_list_ge_le,
"Maximum prefix length\n")
{
- return vty_prefix_list_install (vty, AFI_IP6, argv[0], NULL, argv[1],
- argv[2], argv[3], argv[4]);
+ int idx_word = 2;
+ int idx_permit_deny = 3;
+ int idx_ipv6_prefixlen = 4;
+ int idx_number = 6;
+ int idx_number_2 = 8;
+ return vty_prefix_list_install (vty, AFI_IP6, argv[idx_word]->arg, NULL, argv[idx_permit_deny]->arg,
+ argv[idx_ipv6_prefixlen]->arg, argv[idx_number]->arg, argv[idx_number_2]->arg);
}
DEFUN (ipv6_prefix_list_le,
ipv6_prefix_list_le_cmd,
- "ipv6 prefix-list WORD (deny|permit) X:X::X:X/M le <0-128>",
+ "ipv6 prefix-list WORD <deny|permit> X:X::X:X/M le (0-128)",
IPV6_STR
PREFIX_LIST_STR
"Name of a prefix list\n"
@@ -2075,13 +2203,17 @@ DEFUN (ipv6_prefix_list_le,
"Maximum prefix length to be matched\n"
"Maximum prefix length\n")
{
- return vty_prefix_list_install (vty, AFI_IP6, argv[0], NULL, argv[1],
- argv[2], NULL, argv[3]);
+ int idx_word = 2;
+ int idx_permit_deny = 3;
+ int idx_ipv6_prefixlen = 4;
+ int idx_number = 6;
+ return vty_prefix_list_install (vty, AFI_IP6, argv[idx_word]->arg, NULL, argv[idx_permit_deny]->arg,
+ argv[idx_ipv6_prefixlen]->arg, NULL, argv[idx_number]->arg);
}
DEFUN (ipv6_prefix_list_le_ge,
ipv6_prefix_list_le_ge_cmd,
- "ipv6 prefix-list WORD (deny|permit) X:X::X:X/M le <0-128> ge <0-128>",
+ "ipv6 prefix-list WORD <deny|permit> X:X::X:X/M le (0-128) ge (0-128)",
IPV6_STR
PREFIX_LIST_STR
"Name of a prefix list\n"
@@ -2093,13 +2225,18 @@ DEFUN (ipv6_prefix_list_le_ge,
"Minimum prefix length to be matched\n"
"Minimum prefix length\n")
{
- return vty_prefix_list_install (vty, AFI_IP6, argv[0], NULL, argv[1],
- argv[2], argv[4], argv[3]);
+ int idx_word = 2;
+ int idx_permit_deny = 3;
+ int idx_ipv6_prefixlen = 4;
+ int idx_number = 6;
+ int idx_number_2 = 8;
+ return vty_prefix_list_install (vty, AFI_IP6, argv[idx_word]->arg, NULL, argv[idx_permit_deny]->arg,
+ argv[idx_ipv6_prefixlen]->arg, argv[idx_number_2]->arg, argv[idx_number]->arg);
}
DEFUN (ipv6_prefix_list_seq,
ipv6_prefix_list_seq_cmd,
- "ipv6 prefix-list WORD seq <1-4294967295> (deny|permit) (X:X::X:X/M|any)",
+ "ipv6 prefix-list WORD seq (1-4294967295) <deny|permit> <X:X::X:X/M|any>",
IPV6_STR
PREFIX_LIST_STR
"Name of a prefix list\n"
@@ -2110,13 +2247,17 @@ DEFUN (ipv6_prefix_list_seq,
"IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
"Any prefix match. Same as \"::0/0 le 128\"\n")
{
- return vty_prefix_list_install (vty, AFI_IP6, argv[0], argv[1], argv[2],
- argv[3], NULL, NULL);
+ int idx_word = 2;
+ int idx_number = 4;
+ int idx_permit_deny = 5;
+ int idx_ipv6_any = 6;
+ return vty_prefix_list_install (vty, AFI_IP6, argv[idx_word]->arg, argv[idx_number]->arg, argv[idx_permit_deny]->arg,
+ argv[idx_ipv6_any]->arg, NULL, NULL);
}
DEFUN (ipv6_prefix_list_seq_ge,
ipv6_prefix_list_seq_ge_cmd,
- "ipv6 prefix-list WORD seq <1-4294967295> (deny|permit) X:X::X:X/M ge <0-128>",
+ "ipv6 prefix-list WORD seq (1-4294967295) <deny|permit> X:X::X:X/M ge (0-128)",
IPV6_STR
PREFIX_LIST_STR
"Name of a prefix list\n"
@@ -2128,13 +2269,18 @@ DEFUN (ipv6_prefix_list_seq_ge,
"Minimum prefix length to be matched\n"
"Minimum prefix length\n")
{
- return vty_prefix_list_install (vty, AFI_IP6, argv[0], argv[1], argv[2],
- argv[3], argv[4], NULL);
+ int idx_word = 2;
+ int idx_number = 4;
+ int idx_permit_deny = 5;
+ int idx_ipv6_prefixlen = 6;
+ int idx_number_2 = 8;
+ return vty_prefix_list_install (vty, AFI_IP6, argv[idx_word]->arg, argv[idx_number]->arg, argv[idx_permit_deny]->arg,
+ argv[idx_ipv6_prefixlen]->arg, argv[idx_number_2]->arg, NULL);
}
DEFUN (ipv6_prefix_list_seq_ge_le,
ipv6_prefix_list_seq_ge_le_cmd,
- "ipv6 prefix-list WORD seq <1-4294967295> (deny|permit) X:X::X:X/M ge <0-128> le <0-128>",
+ "ipv6 prefix-list WORD seq (1-4294967295) <deny|permit> X:X::X:X/M ge (0-128) le (0-128)",
IPV6_STR
PREFIX_LIST_STR
"Name of a prefix list\n"
@@ -2148,13 +2294,19 @@ DEFUN (ipv6_prefix_list_seq_ge_le,
"Maximum prefix length to be matched\n"
"Maximum prefix length\n")
{
- return vty_prefix_list_install (vty, AFI_IP6, argv[0], argv[1], argv[2],
- argv[3], argv[4], argv[5]);
+ int idx_word = 2;
+ int idx_number = 4;
+ int idx_permit_deny = 5;
+ int idx_ipv6_prefixlen = 6;
+ int idx_number_2 = 8;
+ int idx_number_3 = 10;
+ return vty_prefix_list_install (vty, AFI_IP6, argv[idx_word]->arg, argv[idx_number]->arg, argv[idx_permit_deny]->arg,
+ argv[idx_ipv6_prefixlen]->arg, argv[idx_number_2]->arg, argv[idx_number_3]->arg);
}
DEFUN (ipv6_prefix_list_seq_le,
ipv6_prefix_list_seq_le_cmd,
- "ipv6 prefix-list WORD seq <1-4294967295> (deny|permit) X:X::X:X/M le <0-128>",
+ "ipv6 prefix-list WORD seq (1-4294967295) <deny|permit> X:X::X:X/M le (0-128)",
IPV6_STR
PREFIX_LIST_STR
"Name of a prefix list\n"
@@ -2166,13 +2318,18 @@ DEFUN (ipv6_prefix_list_seq_le,
"Maximum prefix length to be matched\n"
"Maximum prefix length\n")
{
- return vty_prefix_list_install (vty, AFI_IP6, argv[0], argv[1], argv[2],
- argv[3], NULL, argv[4]);
+ int idx_word = 2;
+ int idx_number = 4;
+ int idx_permit_deny = 5;
+ int idx_ipv6_prefixlen = 6;
+ int idx_number_2 = 8;
+ return vty_prefix_list_install (vty, AFI_IP6, argv[idx_word]->arg, argv[idx_number]->arg, argv[idx_permit_deny]->arg,
+ argv[idx_ipv6_prefixlen]->arg, NULL, argv[idx_number_2]->arg);
}
DEFUN (ipv6_prefix_list_seq_le_ge,
ipv6_prefix_list_seq_le_ge_cmd,
- "ipv6 prefix-list WORD seq <1-4294967295> (deny|permit) X:X::X:X/M le <0-128> ge <0-128>",
+ "ipv6 prefix-list WORD seq (1-4294967295) <deny|permit> X:X::X:X/M le (0-128) ge (0-128)",
IPV6_STR
PREFIX_LIST_STR
"Name of a prefix list\n"
@@ -2186,8 +2343,14 @@ DEFUN (ipv6_prefix_list_seq_le_ge,
"Minimum prefix length to be matched\n"
"Minimum prefix length\n")
{
- return vty_prefix_list_install (vty, AFI_IP6, argv[0], argv[1], argv[2],
- argv[3], argv[5], argv[4]);
+ int idx_word = 2;
+ int idx_number = 4;
+ int idx_permit_deny = 5;
+ int idx_ipv6_prefixlen = 6;
+ int idx_number_2 = 8;
+ int idx_number_3 = 10;
+ return vty_prefix_list_install (vty, AFI_IP6, argv[idx_word]->arg, argv[idx_number]->arg, argv[idx_permit_deny]->arg,
+ argv[idx_ipv6_prefixlen]->arg, argv[idx_number_3]->arg, argv[idx_number_2]->arg);
}
DEFUN (no_ipv6_prefix_list,
@@ -2198,13 +2361,14 @@ DEFUN (no_ipv6_prefix_list,
PREFIX_LIST_STR
"Name of a prefix list\n")
{
- return vty_prefix_list_uninstall (vty, AFI_IP6, argv[0], NULL, NULL,
+ int idx_word = 3;
+ return vty_prefix_list_uninstall (vty, AFI_IP6, argv[idx_word]->arg, NULL, NULL,
NULL, NULL, NULL);
}
DEFUN (no_ipv6_prefix_list_prefix,
no_ipv6_prefix_list_prefix_cmd,
- "no ipv6 prefix-list WORD (deny|permit) (X:X::X:X/M|any)",
+ "no ipv6 prefix-list WORD <deny|permit> <X:X::X:X/M|any>",
NO_STR
IPV6_STR
PREFIX_LIST_STR
@@ -2214,13 +2378,16 @@ DEFUN (no_ipv6_prefix_list_prefix,
"IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
"Any prefix match. Same as \"::0/0 le 128\"\n")
{
- return vty_prefix_list_uninstall (vty, AFI_IP6, argv[0], NULL, argv[1],
- argv[2], NULL, NULL);
+ int idx_word = 3;
+ int idx_permit_deny = 4;
+ int idx_ipv6_any = 5;
+ return vty_prefix_list_uninstall (vty, AFI_IP6, argv[idx_word]->arg, NULL, argv[idx_permit_deny]->arg,
+ argv[idx_ipv6_any]->arg, NULL, NULL);
}
DEFUN (no_ipv6_prefix_list_ge,
no_ipv6_prefix_list_ge_cmd,
- "no ipv6 prefix-list WORD (deny|permit) X:X::X:X/M ge <0-128>",
+ "no ipv6 prefix-list WORD <deny|permit> X:X::X:X/M ge (0-128)",
NO_STR
IPV6_STR
PREFIX_LIST_STR
@@ -2231,13 +2398,17 @@ DEFUN (no_ipv6_prefix_list_ge,
"Minimum prefix length to be matched\n"
"Minimum prefix length\n")
{
- return vty_prefix_list_uninstall (vty, AFI_IP6, argv[0], NULL, argv[1],
- argv[2], argv[3], NULL);
+ int idx_word = 3;
+ int idx_permit_deny = 4;
+ int idx_ipv6_prefixlen = 5;
+ int idx_number = 7;
+ return vty_prefix_list_uninstall (vty, AFI_IP6, argv[idx_word]->arg, NULL, argv[idx_permit_deny]->arg,
+ argv[idx_ipv6_prefixlen]->arg, argv[idx_number]->arg, NULL);
}
DEFUN (no_ipv6_prefix_list_ge_le,
no_ipv6_prefix_list_ge_le_cmd,
- "no ipv6 prefix-list WORD (deny|permit) X:X::X:X/M ge <0-128> le <0-128>",
+ "no ipv6 prefix-list WORD <deny|permit> X:X::X:X/M ge (0-128) le (0-128)",
NO_STR
IPV6_STR
PREFIX_LIST_STR
@@ -2250,13 +2421,18 @@ DEFUN (no_ipv6_prefix_list_ge_le,
"Maximum prefix length to be matched\n"
"Maximum prefix length\n")
{
- return vty_prefix_list_uninstall (vty, AFI_IP6, argv[0], NULL, argv[1],
- argv[2], argv[3], argv[4]);
+ int idx_word = 3;
+ int idx_permit_deny = 4;
+ int idx_ipv6_prefixlen = 5;
+ int idx_number = 7;
+ int idx_number_2 = 9;
+ return vty_prefix_list_uninstall (vty, AFI_IP6, argv[idx_word]->arg, NULL, argv[idx_permit_deny]->arg,
+ argv[idx_ipv6_prefixlen]->arg, argv[idx_number]->arg, argv[idx_number_2]->arg);
}
DEFUN (no_ipv6_prefix_list_le,
no_ipv6_prefix_list_le_cmd,
- "no ipv6 prefix-list WORD (deny|permit) X:X::X:X/M le <0-128>",
+ "no ipv6 prefix-list WORD <deny|permit> X:X::X:X/M le (0-128)",
NO_STR
IPV6_STR
PREFIX_LIST_STR
@@ -2267,13 +2443,17 @@ DEFUN (no_ipv6_prefix_list_le,
"Maximum prefix length to be matched\n"
"Maximum prefix length\n")
{
- return vty_prefix_list_uninstall (vty, AFI_IP6, argv[0], NULL, argv[1],
- argv[2], NULL, argv[3]);
+ int idx_word = 3;
+ int idx_permit_deny = 4;
+ int idx_ipv6_prefixlen = 5;
+ int idx_number = 7;
+ return vty_prefix_list_uninstall (vty, AFI_IP6, argv[idx_word]->arg, NULL, argv[idx_permit_deny]->arg,
+ argv[idx_ipv6_prefixlen]->arg, NULL, argv[idx_number]->arg);
}
DEFUN (no_ipv6_prefix_list_le_ge,
no_ipv6_prefix_list_le_ge_cmd,
- "no ipv6 prefix-list WORD (deny|permit) X:X::X:X/M le <0-128> ge <0-128>",
+ "no ipv6 prefix-list WORD <deny|permit> X:X::X:X/M le (0-128) ge (0-128)",
NO_STR
IPV6_STR
PREFIX_LIST_STR
@@ -2286,13 +2466,18 @@ DEFUN (no_ipv6_prefix_list_le_ge,
"Minimum prefix length to be matched\n"
"Minimum prefix length\n")
{
- return vty_prefix_list_uninstall (vty, AFI_IP6, argv[0], NULL, argv[1],
- argv[2], argv[4], argv[3]);
+ int idx_word = 3;
+ int idx_permit_deny = 4;
+ int idx_ipv6_prefixlen = 5;
+ int idx_number = 7;
+ int idx_number_2 = 9;
+ return vty_prefix_list_uninstall (vty, AFI_IP6, argv[idx_word]->arg, NULL, argv[idx_permit_deny]->arg,
+ argv[idx_ipv6_prefixlen]->arg, argv[idx_number_2]->arg, argv[idx_number]->arg);
}
DEFUN (no_ipv6_prefix_list_seq,
no_ipv6_prefix_list_seq_cmd,
- "no ipv6 prefix-list WORD seq <1-4294967295> (deny|permit) (X:X::X:X/M|any)",
+ "no ipv6 prefix-list WORD seq (1-4294967295) <deny|permit> <X:X::X:X/M|any>",
NO_STR
IPV6_STR
PREFIX_LIST_STR
@@ -2304,13 +2489,17 @@ DEFUN (no_ipv6_prefix_list_seq,
"IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
"Any prefix match. Same as \"::0/0 le 128\"\n")
{
- return vty_prefix_list_uninstall (vty, AFI_IP6, argv[0], argv[1], argv[2],
- argv[3], NULL, NULL);
+ int idx_word = 3;
+ int idx_number = 5;
+ int idx_permit_deny = 6;
+ int idx_ipv6_any = 7;
+ return vty_prefix_list_uninstall (vty, AFI_IP6, argv[idx_word]->arg, argv[idx_number]->arg, argv[idx_permit_deny]->arg,
+ argv[idx_ipv6_any]->arg, NULL, NULL);
}
DEFUN (no_ipv6_prefix_list_seq_ge,
no_ipv6_prefix_list_seq_ge_cmd,
- "no ipv6 prefix-list WORD seq <1-4294967295> (deny|permit) X:X::X:X/M ge <0-128>",
+ "no ipv6 prefix-list WORD seq (1-4294967295) <deny|permit> X:X::X:X/M ge (0-128)",
NO_STR
IPV6_STR
PREFIX_LIST_STR
@@ -2323,13 +2512,18 @@ DEFUN (no_ipv6_prefix_list_seq_ge,
"Minimum prefix length to be matched\n"
"Minimum prefix length\n")
{
- return vty_prefix_list_uninstall (vty, AFI_IP6, argv[0], argv[1], argv[2],
- argv[3], argv[4], NULL);
+ int idx_word = 3;
+ int idx_number = 5;
+ int idx_permit_deny = 6;
+ int idx_ipv6_prefixlen = 7;
+ int idx_number_2 = 9;
+ return vty_prefix_list_uninstall (vty, AFI_IP6, argv[idx_word]->arg, argv[idx_number]->arg, argv[idx_permit_deny]->arg,
+ argv[idx_ipv6_prefixlen]->arg, argv[idx_number_2]->arg, NULL);
}
DEFUN (no_ipv6_prefix_list_seq_ge_le,
no_ipv6_prefix_list_seq_ge_le_cmd,
- "no ipv6 prefix-list WORD seq <1-4294967295> (deny|permit) X:X::X:X/M ge <0-128> le <0-128>",
+ "no ipv6 prefix-list WORD seq (1-4294967295) <deny|permit> X:X::X:X/M ge (0-128) le (0-128)",
NO_STR
IPV6_STR
PREFIX_LIST_STR
@@ -2344,13 +2538,19 @@ DEFUN (no_ipv6_prefix_list_seq_ge_le,
"Maximum prefix length to be matched\n"
"Maximum prefix length\n")
{
- return vty_prefix_list_uninstall (vty, AFI_IP6, argv[0], argv[1], argv[2],
- argv[3], argv[4], argv[5]);
+ int idx_word = 3;
+ int idx_number = 5;
+ int idx_permit_deny = 6;
+ int idx_ipv6_prefixlen = 7;
+ int idx_number_2 = 9;
+ int idx_number_3 = 11;
+ return vty_prefix_list_uninstall (vty, AFI_IP6, argv[idx_word]->arg, argv[idx_number]->arg, argv[idx_permit_deny]->arg,
+ argv[idx_ipv6_prefixlen]->arg, argv[idx_number_2]->arg, argv[idx_number_3]->arg);
}
DEFUN (no_ipv6_prefix_list_seq_le,
no_ipv6_prefix_list_seq_le_cmd,
- "no ipv6 prefix-list WORD seq <1-4294967295> (deny|permit) X:X::X:X/M le <0-128>",
+ "no ipv6 prefix-list WORD seq (1-4294967295) <deny|permit> X:X::X:X/M le (0-128)",
NO_STR
IPV6_STR
PREFIX_LIST_STR
@@ -2363,13 +2563,18 @@ DEFUN (no_ipv6_prefix_list_seq_le,
"Maximum prefix length to be matched\n"
"Maximum prefix length\n")
{
- return vty_prefix_list_uninstall (vty, AFI_IP6, argv[0], argv[1], argv[2],
- argv[3], NULL, argv[4]);
+ int idx_word = 3;
+ int idx_number = 5;
+ int idx_permit_deny = 6;
+ int idx_ipv6_prefixlen = 7;
+ int idx_number_2 = 9;
+ return vty_prefix_list_uninstall (vty, AFI_IP6, argv[idx_word]->arg, argv[idx_number]->arg, argv[idx_permit_deny]->arg,
+ argv[idx_ipv6_prefixlen]->arg, NULL, argv[idx_number_2]->arg);
}
DEFUN (no_ipv6_prefix_list_seq_le_ge,
no_ipv6_prefix_list_seq_le_ge_cmd,
- "no ipv6 prefix-list WORD seq <1-4294967295> (deny|permit) X:X::X:X/M le <0-128> ge <0-128>",
+ "no ipv6 prefix-list WORD seq (1-4294967295) <deny|permit> X:X::X:X/M le (0-128) ge (0-128)",
NO_STR
IPV6_STR
PREFIX_LIST_STR
@@ -2384,8 +2589,14 @@ DEFUN (no_ipv6_prefix_list_seq_le_ge,
"Minimum prefix length to be matched\n"
"Minimum prefix length\n")
{
- return vty_prefix_list_uninstall (vty, AFI_IP6, argv[0], argv[1], argv[2],
- argv[3], argv[5], argv[4]);
+ int idx_word = 3;
+ int idx_number = 5;
+ int idx_permit_deny = 6;
+ int idx_ipv6_prefixlen = 7;
+ int idx_number_2 = 9;
+ int idx_number_3 = 11;
+ return vty_prefix_list_uninstall (vty, AFI_IP6, argv[idx_word]->arg, argv[idx_number]->arg, argv[idx_permit_deny]->arg,
+ argv[idx_ipv6_prefixlen]->arg, argv[idx_number_3]->arg, argv[idx_number_2]->arg);
}
DEFUN (ipv6_prefix_list_sequence_number,
@@ -2413,26 +2624,28 @@ DEFUN (no_ipv6_prefix_list_sequence_number,
DEFUN (ipv6_prefix_list_description,
ipv6_prefix_list_description_cmd,
- "ipv6 prefix-list WORD description .LINE",
+ "ipv6 prefix-list WORD description LINE...",
IPV6_STR
PREFIX_LIST_STR
"Name of a prefix list\n"
"Prefix-list specific description\n"
"Up to 80 characters describing this prefix-list\n")
{
+ int idx_word = 2;
+ int iddx_line = 4;
struct prefix_list *plist;
- plist = prefix_list_get (AFI_IP6, 0, argv[0]);
+ plist = prefix_list_get (AFI_IP6, 0, argv[idx_word]->arg);
if (plist->desc)
{
XFREE (MTYPE_TMP, plist->desc);
plist->desc = NULL;
}
- plist->desc = argv_concat(argv, argc, 1);
+ plist->desc = argv_concat(argv, argc, iddx_line);
return CMD_SUCCESS;
-}
+}
DEFUN (no_ipv6_prefix_list_description,
no_ipv6_prefix_list_description_cmd,
@@ -2443,18 +2656,24 @@ DEFUN (no_ipv6_prefix_list_description,
"Name of a prefix list\n"
"Prefix-list specific description\n")
{
- return vty_prefix_list_desc_unset (vty, AFI_IP6, argv[0]);
+ int idx_word = 3;
+ return vty_prefix_list_desc_unset (vty, AFI_IP6, argv[idx_word]->arg);
}
-ALIAS (no_ipv6_prefix_list_description,
- no_ipv6_prefix_list_description_arg_cmd,
- "no ipv6 prefix-list WORD description .LINE",
+/* ALIAS_FIXME */
+DEFUN (no_ipv6_prefix_list_description_comment,
+ no_ipv6_prefix_list_description_comment_cmd,
+ "no ipv6 prefix-list WORD description LINE...",
NO_STR
IPV6_STR
PREFIX_LIST_STR
"Name of a prefix list\n"
"Prefix-list specific description\n"
"Up to 80 characters describing this prefix-list\n")
+{
+ return no_ipv6_prefix_list_description_comment (self, vty, argc, argv);
+}
+
DEFUN (show_ipv6_prefix_list,
show_ipv6_prefix_list_cmd,
@@ -2474,12 +2693,13 @@ DEFUN (show_ipv6_prefix_list_name,
PREFIX_LIST_STR
"Name of a prefix list\n")
{
- return vty_show_prefix_list (vty, AFI_IP6, argv[0], NULL, normal_display);
+ int idx_word = 3;
+ return vty_show_prefix_list (vty, AFI_IP6, argv[idx_word]->arg, NULL, normal_display);
}
DEFUN (show_ipv6_prefix_list_name_seq,
show_ipv6_prefix_list_name_seq_cmd,
- "show ipv6 prefix-list WORD seq <1-4294967295>",
+ "show ipv6 prefix-list WORD seq (1-4294967295)",
SHOW_STR
IPV6_STR
PREFIX_LIST_STR
@@ -2487,7 +2707,9 @@ DEFUN (show_ipv6_prefix_list_name_seq,
"sequence number of an entry\n"
"Sequence number\n")
{
- return vty_show_prefix_list (vty, AFI_IP6, argv[0], argv[1], sequential_display);
+ int idx_word = 3;
+ int idx_number = 5;
+ return vty_show_prefix_list (vty, AFI_IP6, argv[idx_word]->arg, argv[idx_number]->arg, sequential_display);
}
DEFUN (show_ipv6_prefix_list_prefix,
@@ -2499,7 +2721,9 @@ DEFUN (show_ipv6_prefix_list_prefix,
"Name of a prefix list\n"
"IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
{
- return vty_show_prefix_list_prefix (vty, AFI_IP6, argv[0], argv[1], normal_display);
+ int idx_word = 3;
+ int idx_ipv6_prefixlen = 4;
+ return vty_show_prefix_list_prefix (vty, AFI_IP6, argv[idx_word]->arg, argv[idx_ipv6_prefixlen]->arg, normal_display);
}
DEFUN (show_ipv6_prefix_list_prefix_longer,
@@ -2512,7 +2736,9 @@ DEFUN (show_ipv6_prefix_list_prefix_longer,
"IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
"Lookup longer prefix\n")
{
- return vty_show_prefix_list_prefix (vty, AFI_IP6, argv[0], argv[1], longer_display);
+ int idx_word = 3;
+ int idx_ipv6_prefixlen = 4;
+ return vty_show_prefix_list_prefix (vty, AFI_IP6, argv[idx_word]->arg, argv[idx_ipv6_prefixlen]->arg, longer_display);
}
DEFUN (show_ipv6_prefix_list_prefix_first_match,
@@ -2525,7 +2751,9 @@ DEFUN (show_ipv6_prefix_list_prefix_first_match,
"IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
"First matched prefix\n")
{
- return vty_show_prefix_list_prefix (vty, AFI_IP6, argv[0], argv[1], first_match_display);
+ int idx_word = 3;
+ int idx_ipv6_prefixlen = 4;
+ return vty_show_prefix_list_prefix (vty, AFI_IP6, argv[idx_word]->arg, argv[idx_ipv6_prefixlen]->arg, first_match_display);
}
DEFUN (show_ipv6_prefix_list_summary,
@@ -2548,7 +2776,8 @@ DEFUN (show_ipv6_prefix_list_summary_name,
"Summary of prefix lists\n"
"Name of a prefix list\n")
{
- return vty_show_prefix_list (vty, AFI_IP6, argv[0], NULL, summary_display);
+ int idx_word = 4;
+ return vty_show_prefix_list (vty, AFI_IP6, argv[idx_word]->arg, NULL, summary_display);
}
DEFUN (show_ipv6_prefix_list_detail,
@@ -2571,7 +2800,8 @@ DEFUN (show_ipv6_prefix_list_detail_name,
"Detail of prefix lists\n"
"Name of a prefix list\n")
{
- return vty_show_prefix_list (vty, AFI_IP6, argv[0], NULL, detail_display);
+ int idx_word = 4;
+ return vty_show_prefix_list (vty, AFI_IP6, argv[idx_word]->arg, NULL, detail_display);
}
DEFUN (clear_ipv6_prefix_list,
@@ -2592,7 +2822,8 @@ DEFUN (clear_ipv6_prefix_list_name,
PREFIX_LIST_STR
"Name of a prefix list\n")
{
- return vty_clear_prefix_list (vty, AFI_IP6, argv[0], NULL);
+ int idx_word = 3;
+ return vty_clear_prefix_list (vty, AFI_IP6, argv[idx_word]->arg, NULL);
}
DEFUN (clear_ipv6_prefix_list_name_prefix,
@@ -2604,7 +2835,9 @@ DEFUN (clear_ipv6_prefix_list_name_prefix,
"Name of a prefix list\n"
"IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
{
- return vty_clear_prefix_list (vty, AFI_IP6, argv[0], argv[1]);
+ int idx_word = 3;
+ int idx_ipv6_prefixlen = 4;
+ return vty_clear_prefix_list (vty, AFI_IP6, argv[idx_word]->arg, argv[idx_ipv6_prefixlen]->arg);
}
#endif /* HAVE_IPV6 */
@@ -2960,7 +3193,7 @@ prefix_list_init_ipv4 (void)
install_element (CONFIG_NODE, &ip_prefix_list_description_cmd);
install_element (CONFIG_NODE, &no_ip_prefix_list_description_cmd);
- install_element (CONFIG_NODE, &no_ip_prefix_list_description_arg_cmd);
+ install_element (CONFIG_NODE, &no_ip_prefix_list_description_comment_cmd);
install_element (CONFIG_NODE, &ip_prefix_list_sequence_number_cmd);
install_element (CONFIG_NODE, &no_ip_prefix_list_sequence_number_cmd);
@@ -3026,7 +3259,7 @@ prefix_list_init_ipv6 (void)
install_element (CONFIG_NODE, &ipv6_prefix_list_description_cmd);
install_element (CONFIG_NODE, &no_ipv6_prefix_list_description_cmd);
- install_element (CONFIG_NODE, &no_ipv6_prefix_list_description_arg_cmd);
+ install_element (CONFIG_NODE, &no_ipv6_prefix_list_description_comment_cmd);
install_element (CONFIG_NODE, &ipv6_prefix_list_sequence_number_cmd);
install_element (CONFIG_NODE, &no_ipv6_prefix_list_sequence_number_cmd);
diff --git a/lib/route_types.txt b/lib/route_types.txt
index 54572450b5..56e8c14567 100644
--- a/lib/route_types.txt
+++ b/lib/route_types.txt
@@ -48,7 +48,7 @@ ZEBRA_ROUTE_STATIC, static, zebra, 'S', 1, 1, "static"
ZEBRA_ROUTE_RIP, rip, ripd, 'R', 1, 0, "RIP"
ZEBRA_ROUTE_RIPNG, ripng, ripngd, 'R', 0, 1, "RIPng"
ZEBRA_ROUTE_OSPF, ospf, ospfd, 'O', 1, 0, "OSPF"
-ZEBRA_ROUTE_OSPF6, ospf6, ospf6d, 'O', 0, 1, "OSPFv6"
+ZEBRA_ROUTE_OSPF6, ospf6, ospf6d, 'O', 0, 1, "OSPFv3"
ZEBRA_ROUTE_ISIS, isis, isisd, 'I', 1, 1, "IS-IS"
ZEBRA_ROUTE_BGP, bgp, bgpd, 'B', 1, 1, "BGP"
ZEBRA_ROUTE_PIM, pim, pimd, 'P', 1, 0, "PIM"
diff --git a/lib/routemap.c b/lib/routemap.c
index eec36d3717..a4a8a2bb23 100644
--- a/lib/routemap.c
+++ b/lib/routemap.c
@@ -24,9 +24,9 @@ Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
#include "memory.h"
#include "vector.h"
#include "prefix.h"
+#include "vty.h"
#include "routemap.h"
#include "command.h"
-#include "vty.h"
#include "log.h"
#include "hash.h"
@@ -47,6 +47,594 @@ static vector route_match_vec;
/* Vector for route set rules. */
static vector route_set_vec;
+struct route_map_match_set_hooks
+{
+ /* match interface */
+ int (*match_interface) (struct vty *vty,
+ struct route_map_index *index,
+ const char *command,
+ const char *arg,
+ route_map_event_t type);
+
+ /* no match interface */
+ int (*no_match_interface) (struct vty *vty,
+ struct route_map_index *index,
+ const char *command,
+ const char *arg,
+ route_map_event_t type);
+
+ /* match ip address */
+ int (*match_ip_address) (struct vty *vty,
+ struct route_map_index *index,
+ const char *command,
+ const char *arg,
+ route_map_event_t type);
+
+ /* no match ip address */
+ int (*no_match_ip_address) (struct vty *vty,
+ struct route_map_index *index,
+ const char *command,
+ const char *arg,
+ route_map_event_t type);
+
+ /* match ip address prefix list */
+ int (*match_ip_address_prefix_list) (struct vty *vty,
+ struct route_map_index *index,
+ const char *command,
+ const char *arg,
+ route_map_event_t type);
+
+ /* no match ip address prefix list */
+ int (*no_match_ip_address_prefix_list) (struct vty *vty,
+ struct route_map_index *index,
+ const char *command,
+ const char *arg,
+ route_map_event_t type);
+
+ /* match ip next hop */
+ int (*match_ip_next_hop) (struct vty *vty,
+ struct route_map_index *index,
+ const char *command,
+ const char *arg,
+ route_map_event_t type);
+
+ /* no match ip next hop */
+ int (*no_match_ip_next_hop) (struct vty *vty,
+ struct route_map_index *index,
+ const char *command,
+ const char *arg,
+ route_map_event_t type);
+
+ /* match ip next hop prefix list */
+ int (*match_ip_next_hop_prefix_list) (struct vty *vty,
+ struct route_map_index *index,
+ const char *command,
+ const char *arg,
+ route_map_event_t type);
+
+ /* no match ip next hop prefix list */
+ int (*no_match_ip_next_hop_prefix_list) (struct vty *vty,
+ struct route_map_index *index,
+ const char *command,
+ const char *arg,
+ route_map_event_t type);
+
+ /* match ipv6 address */
+ int (*match_ipv6_address) (struct vty *vty,
+ struct route_map_index *index,
+ const char *command,
+ const char *arg,
+ route_map_event_t type);
+
+ /* no match ipv6 address */
+ int (*no_match_ipv6_address) (struct vty *vty,
+ struct route_map_index *index,
+ const char *command,
+ const char *arg,
+ route_map_event_t type);
+
+
+ /* match ipv6 address prefix list */
+ int (*match_ipv6_address_prefix_list) (struct vty *vty,
+ struct route_map_index *index,
+ const char *command,
+ const char *arg,
+ route_map_event_t type);
+
+ /* no match ipv6 address prefix list */
+ int (*no_match_ipv6_address_prefix_list) (struct vty *vty,
+ struct route_map_index *index,
+ const char *command,
+ const char *arg,
+ route_map_event_t type);
+
+ /* match metric */
+ int (*match_metric) (struct vty *vty,
+ struct route_map_index *index,
+ const char *command,
+ const char *arg,
+ route_map_event_t type);
+
+ /* no match metric */
+ int (*no_match_metric) (struct vty *vty,
+ struct route_map_index *index,
+ const char *command,
+ const char *arg,
+ route_map_event_t type);
+
+ /* match tag */
+ int (*match_tag) (struct vty *vty,
+ struct route_map_index *index,
+ const char *command,
+ const char *arg,
+ route_map_event_t type);
+
+ /* no match tag */
+ int (*no_match_tag) (struct vty *vty,
+ struct route_map_index *index,
+ const char *command,
+ const char *arg,
+ route_map_event_t type);
+
+ /* set ip nexthop */
+ int (*set_ip_nexthop) (struct vty *vty,
+ struct route_map_index *index,
+ const char *command,
+ const char *arg);
+
+ /* no set ip nexthop */
+ int (*no_set_ip_nexthop) (struct vty *vty,
+ struct route_map_index *index,
+ const char *command,
+ const char *arg);
+
+ /* set ipv6 nexthop local */
+ int (*set_ipv6_nexthop_local) (struct vty *vty,
+ struct route_map_index *index,
+ const char *command,
+ const char *arg);
+
+ /* no set ipv6 nexthop local */
+ int (*no_set_ipv6_nexthop_local) (struct vty *vty,
+ struct route_map_index *index,
+ const char *command,
+ const char *arg);
+
+ /* set metric */
+ int (*set_metric) (struct vty *vty,
+ struct route_map_index *index,
+ const char *command,
+ const char *arg);
+
+ /* no set metric */
+ int (*no_set_metric) (struct vty *vty,
+ struct route_map_index *index,
+ const char *command,
+ const char *arg);
+
+ /* set tag */
+ int (*set_tag) (struct vty *vty,
+ struct route_map_index *index,
+ const char *command,
+ const char *arg);
+
+ /* no set tag */
+ int (*no_set_tag) (struct vty *vty,
+ struct route_map_index *index,
+ const char *command,
+ const char *arg);
+
+};
+
+struct route_map_match_set_hooks rmap_match_set_hook;
+
+/* match interface */
+void
+route_map_match_interface_hook (int (*func) (struct vty *vty,
+ struct route_map_index *index,
+ const char *command,
+ const char *arg,
+ route_map_event_t type))
+{
+ rmap_match_set_hook.match_interface = func;
+}
+
+/* no match interface */
+void
+route_map_no_match_interface_hook (int (*func) (struct vty *vty,
+ struct route_map_index *index,
+ const char *command,
+ const char *arg,
+ route_map_event_t type))
+{
+ rmap_match_set_hook.no_match_interface = func;
+}
+
+/* match ip address */
+void
+route_map_match_ip_address_hook (int (*func) (struct vty *vty,
+ struct route_map_index *index,
+ const char *command,
+ const char *arg,
+ route_map_event_t type))
+{
+ rmap_match_set_hook.match_ip_address = func;
+}
+
+/* no match ip address */
+void
+route_map_no_match_ip_address_hook (int (*func) (struct vty *vty,
+ struct route_map_index *index,
+ const char *command,
+ const char *arg,
+ route_map_event_t type))
+{
+ rmap_match_set_hook.no_match_ip_address = func;
+}
+
+/* match ip address prefix list */
+void
+route_map_match_ip_address_prefix_list_hook (int (*func) (struct vty *vty,
+ struct route_map_index *index,
+ const char *command,
+ const char *arg,
+ route_map_event_t type))
+{
+ rmap_match_set_hook.match_ip_address_prefix_list = func;
+}
+
+/* no match ip address prefix list */
+void
+route_map_no_match_ip_address_prefix_list_hook (int (*func) (struct vty *vty,
+ struct route_map_index *index,
+ const char *command,
+ const char *arg,
+ route_map_event_t type))
+{
+ rmap_match_set_hook.no_match_ip_address_prefix_list = func;
+}
+
+/* match ip next hop */
+void
+route_map_match_ip_next_hop_hook (int (*func) (struct vty *vty,
+ struct route_map_index *index,
+ const char *command,
+ const char *arg,
+ route_map_event_t type))
+{
+ rmap_match_set_hook.match_ip_next_hop = func;
+}
+
+/* no match ip next hop */
+void
+route_map_no_match_ip_next_hop_hook (int (*func) (struct vty *vty,
+ struct route_map_index *index,
+ const char *command,
+ const char *arg,
+ route_map_event_t type))
+{
+ rmap_match_set_hook.no_match_ip_next_hop = func;
+}
+
+/* match ip next hop prefix list */
+void
+route_map_match_ip_next_hop_prefix_list_hook (int (*func) (struct vty *vty,
+ struct route_map_index *index,
+ const char *command,
+ const char *arg,
+ route_map_event_t type))
+{
+ rmap_match_set_hook.match_ip_next_hop_prefix_list = func;
+}
+
+/* no match ip next hop prefix list */
+void
+route_map_no_match_ip_next_hop_prefix_list_hook (int (*func) (struct vty *vty,
+ struct route_map_index *index,
+ const char *command,
+ const char *arg,
+ route_map_event_t type))
+{
+ rmap_match_set_hook.no_match_ip_next_hop_prefix_list = func;
+}
+
+/* match ipv6 address */
+void
+route_map_match_ipv6_address_hook (int (*func) (struct vty *vty,
+ struct route_map_index *index,
+ const char *command,
+ const char *arg,
+ route_map_event_t type))
+{
+ rmap_match_set_hook.match_ipv6_address = func;
+}
+
+/* no match ipv6 address */
+void
+route_map_no_match_ipv6_address_hook (int (*func) (struct vty *vty,
+ struct route_map_index *index,
+ const char *command,
+ const char *arg,
+ route_map_event_t type))
+{
+ rmap_match_set_hook.no_match_ipv6_address = func;
+}
+
+
+/* match ipv6 address prefix list */
+void
+route_map_match_ipv6_address_prefix_list_hook (int (*func) (struct vty *vty,
+ struct route_map_index *index,
+ const char *command,
+ const char *arg,
+ route_map_event_t type))
+{
+ rmap_match_set_hook.match_ipv6_address_prefix_list = func;
+}
+
+/* no match ipv6 address prefix list */
+void
+route_map_no_match_ipv6_address_prefix_list_hook (int (*func) (struct vty *vty,
+ struct route_map_index *index,
+ const char *command,
+ const char *arg,
+ route_map_event_t type))
+{
+ rmap_match_set_hook.no_match_ipv6_address_prefix_list = func;
+}
+
+/* match metric */
+void
+route_map_match_metric_hook (int (*func) (struct vty *vty,
+ struct route_map_index *index,
+ const char *command,
+ const char *arg,
+ route_map_event_t type))
+{
+ rmap_match_set_hook.match_metric = func;
+}
+
+/* no match metric */
+void
+route_map_no_match_metric_hook (int (*func) (struct vty *vty,
+ struct route_map_index *index,
+ const char *command,
+ const char *arg,
+ route_map_event_t type))
+{
+ rmap_match_set_hook.no_match_metric = func;
+}
+
+/* match tag */
+void
+route_map_match_tag_hook (int (*func) (struct vty *vty,
+ struct route_map_index *index,
+ const char *command,
+ const char *arg,
+ route_map_event_t type))
+{
+ rmap_match_set_hook.match_tag = func;
+}
+
+/* no match tag */
+void
+route_map_no_match_tag_hook (int (*func) (struct vty *vty,
+ struct route_map_index *index,
+ const char *command,
+ const char *arg,
+ route_map_event_t type))
+{
+ rmap_match_set_hook.no_match_tag = func;
+}
+
+/* set ip nexthop */
+void
+route_map_set_ip_nexthop_hook (int (*func) (struct vty *vty,
+ struct route_map_index *index,
+ const char *command,
+ const char *arg))
+{
+ rmap_match_set_hook.set_ip_nexthop = func;
+}
+
+/* no set ip nexthop */
+void
+route_map_no_set_ip_nexthop_hook (int (*func) (struct vty *vty,
+ struct route_map_index *index,
+ const char *command,
+ const char *arg))
+{
+ rmap_match_set_hook.no_set_ip_nexthop = func;
+}
+
+/* set ipv6 nexthop local */
+void
+route_map_set_ipv6_nexthop_local_hook (int (*func) (struct vty *vty,
+ struct route_map_index *index,
+ const char *command,
+ const char *arg))
+{
+ rmap_match_set_hook.set_ipv6_nexthop_local = func;
+}
+
+/* no set ipv6 nexthop local */
+void
+route_map_no_set_ipv6_nexthop_local_hook (int (*func) (struct vty *vty,
+ struct route_map_index *index,
+ const char *command,
+ const char *arg))
+{
+ rmap_match_set_hook.no_set_ipv6_nexthop_local = func;
+}
+
+/* set metric */
+void
+route_map_set_metric_hook (int (*func) (struct vty *vty,
+ struct route_map_index *index,
+ const char *command,
+ const char *arg))
+{
+ rmap_match_set_hook.set_metric = func;
+}
+
+/* no set metric */
+void
+route_map_no_set_metric_hook (int (*func) (struct vty *vty,
+ struct route_map_index *index,
+ const char *command,
+ const char *arg))
+{
+ rmap_match_set_hook.no_set_metric = func;
+}
+
+/* set tag */
+void
+route_map_set_tag_hook (int (*func) (struct vty *vty,
+ struct route_map_index *index,
+ const char *command,
+ const char *arg))
+{
+ rmap_match_set_hook.set_tag = func;
+}
+
+/* no set tag */
+void
+route_map_no_set_tag_hook (int (*func) (struct vty *vty,
+ struct route_map_index *index,
+ const char *command,
+ const char *arg))
+{
+ rmap_match_set_hook.no_set_tag = func;
+}
+
+int
+generic_match_add (struct vty *vty, struct route_map_index *index,
+ const char *command, const char *arg,
+ route_map_event_t type)
+{
+ int ret;
+
+ ret = route_map_add_match (index, command, arg);
+ if (ret)
+ {
+ switch (ret)
+ {
+ case RMAP_RULE_MISSING:
+ vty_out (vty, "%% Can't find rule.%s", VTY_NEWLINE);
+ return CMD_WARNING;
+ case RMAP_COMPILE_ERROR:
+ vty_out (vty, "%% Argument is malformed.%s", VTY_NEWLINE);
+ return CMD_WARNING;
+ }
+ }
+
+ if (type != RMAP_EVENT_MATCH_ADDED)
+ {
+ route_map_upd8_dependency (type, arg, index->map->name);
+ }
+ return CMD_SUCCESS;
+}
+
+int
+generic_match_delete (struct vty *vty, struct route_map_index *index,
+ const char *command, const char *arg,
+ route_map_event_t type)
+{
+ int ret;
+ char *dep_name = NULL;
+ const char *tmpstr;
+ char *rmap_name = NULL;
+
+ if (type != RMAP_EVENT_MATCH_DELETED)
+ {
+ /* ignore the mundane, the types without any dependency */
+ if (arg == NULL)
+ {
+ if ((tmpstr = route_map_get_match_arg(index, command)) != NULL)
+ dep_name = XSTRDUP(MTYPE_ROUTE_MAP_RULE, tmpstr);
+ }
+ else
+ {
+ dep_name = XSTRDUP(MTYPE_ROUTE_MAP_RULE, arg);
+ }
+ rmap_name = XSTRDUP(MTYPE_ROUTE_MAP_NAME, index->map->name);
+ }
+
+ ret = route_map_delete_match (index, command, dep_name);
+ if (ret)
+ {
+ switch (ret)
+ {
+ case RMAP_RULE_MISSING:
+ vty_out (vty, "%% BGP Can't find rule.%s", VTY_NEWLINE);
+ break;
+ case RMAP_COMPILE_ERROR:
+ vty_out (vty, "%% BGP Argument is malformed.%s", VTY_NEWLINE);
+ break;
+ }
+ if (dep_name)
+ XFREE(MTYPE_ROUTE_MAP_RULE, dep_name);
+ if (rmap_name)
+ XFREE(MTYPE_ROUTE_MAP_NAME, rmap_name);
+ return CMD_WARNING;
+ }
+
+ if (type != RMAP_EVENT_MATCH_DELETED && dep_name)
+ route_map_upd8_dependency(type, dep_name, rmap_name);
+
+ if (dep_name)
+ XFREE(MTYPE_ROUTE_MAP_RULE, dep_name);
+ if (rmap_name)
+ XFREE(MTYPE_ROUTE_MAP_NAME, rmap_name);
+
+ return CMD_SUCCESS;
+}
+
+int
+generic_set_add (struct vty *vty, struct route_map_index *index,
+ const char *command, const char *arg)
+{
+ int ret;
+
+ ret = route_map_add_set (index, command, arg);
+ if (ret)
+ {
+ switch (ret)
+ {
+ case RMAP_RULE_MISSING:
+ vty_out (vty, "%% Can't find rule.%s", VTY_NEWLINE);
+ return CMD_WARNING;
+ case RMAP_COMPILE_ERROR:
+ vty_out (vty, "%% Argument is malformed.%s", VTY_NEWLINE);
+ return CMD_WARNING;
+ }
+ }
+ return CMD_SUCCESS;
+}
+
+int
+generic_set_delete (struct vty *vty, struct route_map_index *index,
+ const char *command, const char *arg)
+{
+ int ret;
+
+ ret = route_map_delete_set (index, command, arg);
+ if (ret)
+ {
+ switch (ret)
+ {
+ case RMAP_RULE_MISSING:
+ vty_out (vty, "%% Can't find rule.%s", VTY_NEWLINE);
+ return CMD_WARNING;
+ case RMAP_COMPILE_ERROR:
+ vty_out (vty, "%% Argument is malformed.%s", VTY_NEWLINE);
+ return CMD_WARNING;
+ }
+ }
+ return CMD_SUCCESS;
+}
+
+
/* Route map rule. This rule has both `match' rule and `set' rule. */
struct route_map_rule
{
@@ -1386,49 +1974,578 @@ route_map_notify_dependencies (const char *affected_name, route_map_event_t even
XFREE (MTYPE_ROUTE_MAP_NAME, name);
}
+
/* VTY related functions. */
-DEFUN (route_map,
- route_map_cmd,
- "route-map WORD (deny|permit) <1-65535>",
- "Create route-map or enter route-map command mode\n"
- "Route map tag\n"
- "Route map denies set operations\n"
- "Route map permits set operations\n"
- "Sequence to insert to/delete from existing route-map entry\n")
+DEFUN (match_interface,
+ match_interface_cmd,
+ "match interface WORD",
+ MATCH_STR
+ "match first hop interface of route\n"
+ "Interface name\n")
+{
+ int idx_word = 2;
+ VTY_DECLVAR_CONTEXT (route_map_index, index);
+
+ if (rmap_match_set_hook.match_interface)
+ return rmap_match_set_hook.match_interface (vty, index, "interface", argv[idx_word]->arg, RMAP_EVENT_MATCH_ADDED);
+ return CMD_SUCCESS;
+}
+
+DEFUN (no_match_interface,
+ no_match_interface_cmd,
+ "no match interface [INTERFACE]",
+ NO_STR
+ MATCH_STR
+ "Match first hop interface of route\n"
+ "Interface name\n")
{
- int permit;
- unsigned long pref;
- struct route_map *map;
- struct route_map_index *index;
- char *endptr = NULL;
+ char *iface = (argc == 4) ? argv[3]->arg : NULL;
+ VTY_DECLVAR_CONTEXT (route_map_index, index);
- /* Permit check. */
- if (strncmp (argv[1], "permit", strlen (argv[1])) == 0)
- permit = RMAP_PERMIT;
- else if (strncmp (argv[1], "deny", strlen (argv[1])) == 0)
- permit = RMAP_DENY;
- else
+ if (rmap_match_set_hook.no_match_interface)
+ return rmap_match_set_hook.no_match_interface (vty, index, "interface", iface, RMAP_EVENT_MATCH_DELETED);
+ return CMD_SUCCESS;
+}
+
+
+DEFUN (match_ip_address,
+ match_ip_address_cmd,
+ "match ip address <(1-199)|(1300-2699)|WORD>",
+ MATCH_STR
+ IP_STR
+ "Match address of route\n"
+ "IP access-list number\n"
+ "IP access-list number (expanded range)\n"
+ "IP Access-list name\n")
+{
+ int idx_acl = 3;
+ VTY_DECLVAR_CONTEXT (route_map_index, index);
+
+ if (rmap_match_set_hook.match_ip_address)
+ return rmap_match_set_hook.match_ip_address (vty, index, "ip address", argv[idx_acl]->arg,
+ RMAP_EVENT_FILTER_ADDED);
+ return CMD_SUCCESS;
+}
+
+
+DEFUN (no_match_ip_address,
+ no_match_ip_address_cmd,
+ "no match ip address [<(1-199)|(1300-2699)|WORD>]",
+ NO_STR
+ MATCH_STR
+ IP_STR
+ "Match address of route\n"
+ "IP access-list number\n"
+ "IP access-list number (expanded range)\n"
+ "IP Access-list name\n")
+{
+ int idx_word = 4;
+ VTY_DECLVAR_CONTEXT (route_map_index, index);
+
+ if (rmap_match_set_hook.no_match_ip_address)
{
- vty_out (vty, "the third field must be [permit|deny]%s", VTY_NEWLINE);
+ if (argc <= idx_word)
+ return rmap_match_set_hook.no_match_ip_address (vty, index, "ip address", NULL,
+ RMAP_EVENT_FILTER_DELETED);
+ return rmap_match_set_hook.no_match_ip_address (vty, index, "ip address", argv[idx_word]->arg,
+ RMAP_EVENT_FILTER_DELETED);
+ }
+ return CMD_SUCCESS;
+}
+
+
+DEFUN (match_ip_address_prefix_list,
+ match_ip_address_prefix_list_cmd,
+ "match ip address prefix-list WORD",
+ MATCH_STR
+ IP_STR
+ "Match address of route\n"
+ "Match entries of prefix-lists\n"
+ "IP prefix-list name\n")
+{
+ int idx_word = 4;
+ VTY_DECLVAR_CONTEXT (route_map_index, index);
+
+ if (rmap_match_set_hook.match_ip_address_prefix_list)
+ return rmap_match_set_hook.match_ip_address_prefix_list (vty, index, "ip address prefix-list",
+ argv[idx_word]->arg, RMAP_EVENT_PLIST_ADDED);
+ return CMD_SUCCESS;
+}
+
+
+DEFUN (no_match_ip_address_prefix_list,
+ no_match_ip_address_prefix_list_cmd,
+ "no match ip address prefix-list [WORD]",
+ NO_STR
+ MATCH_STR
+ IP_STR
+ "Match address of route\n"
+ "Match entries of prefix-lists\n"
+ "IP prefix-list name\n")
+{
+ int idx_word = 5;
+ VTY_DECLVAR_CONTEXT (route_map_index, index);
+
+ if (rmap_match_set_hook.no_match_ip_address_prefix_list)
+ {
+ if (argc <= idx_word)
+ return rmap_match_set_hook.no_match_ip_address_prefix_list (vty, index, "ip address prefix-list",
+ NULL, RMAP_EVENT_PLIST_DELETED);
+ return rmap_match_set_hook.no_match_ip_address_prefix_list(vty, index, "ip address prefix-list",
+ argv[idx_word]->arg, RMAP_EVENT_PLIST_DELETED);
+ }
+ return CMD_SUCCESS;
+}
+
+
+DEFUN (match_ip_next_hop,
+ match_ip_next_hop_cmd,
+ "match ip next-hop <(1-199)|(1300-2699)|WORD>",
+ MATCH_STR
+ IP_STR
+ "Match next-hop address of route\n"
+ "IP access-list number\n"
+ "IP access-list number (expanded range)\n"
+ "IP Access-list name\n")
+{
+ int idx_acl = 3;
+ VTY_DECLVAR_CONTEXT (route_map_index, index);
+
+ if (rmap_match_set_hook.match_ip_next_hop)
+ return rmap_match_set_hook.match_ip_next_hop (vty, index, "ip next-hop", argv[idx_acl]->arg,
+ RMAP_EVENT_FILTER_ADDED);
+ return CMD_SUCCESS;
+}
+
+
+DEFUN (no_match_ip_next_hop,
+ no_match_ip_next_hop_cmd,
+ "no match ip next-hop [<(1-199)|(1300-2699)|WORD>]",
+ NO_STR
+ MATCH_STR
+ IP_STR
+ "Match next-hop address of route\n"
+ "IP access-list number\n"
+ "IP access-list number (expanded range)\n"
+ "IP Access-list name\n")
+{
+ int idx_word = 4;
+ VTY_DECLVAR_CONTEXT (route_map_index, index);
+
+ if (rmap_match_set_hook.no_match_ip_next_hop)
+ {
+ if (argc <= idx_word)
+ return rmap_match_set_hook.no_match_ip_next_hop (vty, index, "ip next-hop", NULL,
+ RMAP_EVENT_FILTER_DELETED);
+ return rmap_match_set_hook.no_match_ip_next_hop (vty, index, "ip next-hop", argv[idx_word]->arg,
+ RMAP_EVENT_FILTER_DELETED);
+ }
+ return CMD_SUCCESS;
+}
+
+
+DEFUN (match_ip_next_hop_prefix_list,
+ match_ip_next_hop_prefix_list_cmd,
+ "match ip next-hop prefix-list WORD",
+ MATCH_STR
+ IP_STR
+ "Match next-hop address of route\n"
+ "Match entries of prefix-lists\n"
+ "IP prefix-list name\n")
+{
+ int idx_word = 4;
+ VTY_DECLVAR_CONTEXT (route_map_index, index);
+
+ if (rmap_match_set_hook.match_ip_next_hop_prefix_list)
+ return rmap_match_set_hook.match_ip_next_hop_prefix_list (vty, index, "ip next-hop prefix-list",
+ argv[idx_word]->arg, RMAP_EVENT_PLIST_ADDED);
+ return CMD_SUCCESS;
+}
+
+DEFUN (no_match_ip_next_hop_prefix_list,
+ no_match_ip_next_hop_prefix_list_cmd,
+ "no match ip next-hop prefix-list [WORD]",
+ NO_STR
+ MATCH_STR
+ IP_STR
+ "Match next-hop address of route\n"
+ "Match entries of prefix-lists\n"
+ "IP prefix-list name\n")
+{
+ int idx_word = 5;
+ VTY_DECLVAR_CONTEXT (route_map_index, index);
+
+ if (rmap_match_set_hook.no_match_ip_next_hop)
+ {
+ if (argc <= idx_word)
+ return rmap_match_set_hook.no_match_ip_next_hop (vty, index, "ip next-hop prefix-list",
+ NULL, RMAP_EVENT_PLIST_DELETED);
+ return rmap_match_set_hook.no_match_ip_next_hop (vty, index, "ip next-hop prefix-list",
+ argv[idx_word]->arg, RMAP_EVENT_PLIST_DELETED);
+ }
+ return CMD_SUCCESS;
+}
+
+
+DEFUN (match_ipv6_address,
+ match_ipv6_address_cmd,
+ "match ipv6 address WORD",
+ MATCH_STR
+ IPV6_STR
+ "Match IPv6 address of route\n"
+ "IPv6 access-list name\n")
+{
+ int idx_word = 3;
+ VTY_DECLVAR_CONTEXT (route_map_index, index);
+
+ if (rmap_match_set_hook.match_ipv6_address)
+ return rmap_match_set_hook.match_ipv6_address (vty, index, "ipv6 address", argv[idx_word]->arg,
+ RMAP_EVENT_FILTER_ADDED);
+ return CMD_SUCCESS;
+}
+
+DEFUN (no_match_ipv6_address,
+ no_match_ipv6_address_cmd,
+ "no match ipv6 address WORD",
+ NO_STR
+ MATCH_STR
+ IPV6_STR
+ "Match IPv6 address of route\n"
+ "IPv6 access-list name\n")
+{
+ int idx_word = 4;
+ VTY_DECLVAR_CONTEXT (route_map_index, index);
+
+ if (rmap_match_set_hook.no_match_ipv6_address)
+ return rmap_match_set_hook.no_match_ipv6_address (vty, index, "ipv6 address", argv[idx_word]->arg,
+ RMAP_EVENT_FILTER_DELETED);
+ return CMD_SUCCESS;
+}
+
+
+DEFUN (match_ipv6_address_prefix_list,
+ match_ipv6_address_prefix_list_cmd,
+ "match ipv6 address prefix-list WORD",
+ MATCH_STR
+ IPV6_STR
+ "Match address of route\n"
+ "Match entries of prefix-lists\n"
+ "IP prefix-list name\n")
+{
+ int idx_word = 4;
+ VTY_DECLVAR_CONTEXT (route_map_index, index);
+
+ if (rmap_match_set_hook.match_ipv6_address_prefix_list)
+ return rmap_match_set_hook.match_ipv6_address_prefix_list (vty, index, "ipv6 address prefix-list",
+ argv[idx_word]->arg, RMAP_EVENT_PLIST_ADDED);
+ return CMD_SUCCESS;
+}
+
+DEFUN (no_match_ipv6_address_prefix_list,
+ no_match_ipv6_address_prefix_list_cmd,
+ "no match ipv6 address prefix-list WORD",
+ NO_STR
+ MATCH_STR
+ IPV6_STR
+ "Match address of route\n"
+ "Match entries of prefix-lists\n"
+ "IP prefix-list name\n")
+{
+ int idx_word = 5;
+ VTY_DECLVAR_CONTEXT (route_map_index, index);
+
+ if (rmap_match_set_hook.no_match_ipv6_address_prefix_list)
+ return rmap_match_set_hook.no_match_ipv6_address_prefix_list(vty, index, "ipv6 address prefix-list",
+ argv[idx_word]->arg, RMAP_EVENT_PLIST_DELETED);
+ return CMD_SUCCESS;
+}
+
+
+DEFUN (match_metric,
+ match_metric_cmd,
+ "match metric (0-4294967295)",
+ MATCH_STR
+ "Match metric of route\n"
+ "Metric value\n")
+{
+ int idx_number = 2;
+ VTY_DECLVAR_CONTEXT (route_map_index, index);
+
+ if (rmap_match_set_hook.match_metric)
+ return rmap_match_set_hook.match_metric(vty, index, "metric", argv[idx_number]->arg,
+ RMAP_EVENT_MATCH_ADDED);
+ return CMD_SUCCESS;
+}
+
+
+DEFUN (no_match_metric,
+ no_match_metric_cmd,
+ "no match metric [(0-4294967295)]",
+ NO_STR
+ MATCH_STR
+ "Match metric of route\n"
+ "Metric value\n")
+{
+ int idx_number = 3;
+ VTY_DECLVAR_CONTEXT (route_map_index, index);
+
+ if (rmap_match_set_hook.no_match_metric)
+ {
+ if (argc <= idx_number)
+ return rmap_match_set_hook.no_match_metric (vty, index, "metric",
+ NULL, RMAP_EVENT_MATCH_DELETED);
+ return rmap_match_set_hook.no_match_metric(vty, index, "metric",
+ argv[idx_number]->arg,
+ RMAP_EVENT_MATCH_DELETED);
+ }
+ return CMD_SUCCESS;
+}
+
+
+DEFUN (match_tag,
+ match_tag_cmd,
+ "match tag (1-4294967295)",
+ MATCH_STR
+ "Match tag of route\n"
+ "Tag value\n")
+{
+ int idx_number = 2;
+ VTY_DECLVAR_CONTEXT (route_map_index, index);
+
+ if (rmap_match_set_hook.match_tag)
+ return rmap_match_set_hook.match_tag(vty, index, "tag", argv[idx_number]->arg,
+ RMAP_EVENT_MATCH_ADDED);
+ return CMD_SUCCESS;
+}
+
+
+DEFUN (no_match_tag,
+ no_match_tag_cmd,
+ "no match tag [(1-4294967295)]",
+ NO_STR
+ MATCH_STR
+ "Match tag of route\n"
+ "Tag value\n")
+{
+ VTY_DECLVAR_CONTEXT (route_map_index, index);
+
+ if (rmap_match_set_hook.no_match_tag)
+ return rmap_match_set_hook.no_match_tag (vty, index, "tag", argv[3]->arg,
+ RMAP_EVENT_MATCH_DELETED);
+ return CMD_SUCCESS;
+}
+
+
+DEFUN (set_ip_nexthop,
+ set_ip_nexthop_cmd,
+ "set ip next-hop A.B.C.D",
+ SET_STR
+ IP_STR
+ "Next hop address\n"
+ "IP address of next hop\n")
+{
+ int idx_ipv4 = 3;
+ union sockunion su;
+ int ret;
+ VTY_DECLVAR_CONTEXT (route_map_index, index);
+
+ ret = str2sockunion (argv[idx_ipv4]->arg, &su);
+ if (ret < 0)
+ {
+ vty_out (vty, "%% Malformed nexthop address%s", VTY_NEWLINE);
+ return CMD_WARNING;
+ }
+ if (su.sin.sin_addr.s_addr == 0 ||
+ IPV4_CLASS_DE(su.sin.sin_addr.s_addr))
+ {
+ vty_out (vty, "%% nexthop address cannot be 0.0.0.0, multicast "
+ "or reserved%s", VTY_NEWLINE);
return CMD_WARNING;
}
- /* Preference check. */
- pref = strtoul (argv[2], &endptr, 10);
- if (pref == ULONG_MAX || *endptr != '\0')
+ if (rmap_match_set_hook.set_ip_nexthop)
+ return rmap_match_set_hook.set_ip_nexthop(vty, index, "ip next-hop", argv[idx_ipv4]->arg);
+ return CMD_SUCCESS;
+}
+
+
+DEFUN (no_set_ip_nexthop,
+ no_set_ip_nexthop_cmd,
+ "no set ip next-hop [<peer-address|A.B.C.D>]",
+ NO_STR
+ SET_STR
+ "Next hop address\n"
+ "Use peer address (for BGP only)\n"
+ "IP address of next hop\n")
+{
+ int idx_peer = 4;
+ VTY_DECLVAR_CONTEXT (route_map_index, index);
+
+ if (rmap_match_set_hook.no_set_ip_nexthop)
{
- vty_out (vty, "the fourth field must be positive integer%s",
- VTY_NEWLINE);
+ if (argc <= idx_peer)
+ return rmap_match_set_hook.no_set_ip_nexthop (vty, index, "ip next-hop", NULL);
+ return rmap_match_set_hook.no_set_ip_nexthop (vty, index, "ip next-hop", argv[idx_peer]->arg);
+ }
+ return CMD_SUCCESS;
+}
+
+
+DEFUN (set_ipv6_nexthop_local,
+ set_ipv6_nexthop_local_cmd,
+ "set ipv6 next-hop local X:X::X:X",
+ SET_STR
+ IPV6_STR
+ "IPv6 next-hop address\n"
+ "IPv6 local address\n"
+ "IPv6 address of next hop\n")
+{
+ int idx_ipv6 = 4;
+ struct in6_addr addr;
+ int ret;
+ VTY_DECLVAR_CONTEXT (route_map_index, index);
+
+ ret = inet_pton (AF_INET6, argv[idx_ipv6]->arg, &addr);
+ if (!ret)
+ {
+ vty_out (vty, "%% Malformed nexthop address%s", VTY_NEWLINE);
return CMD_WARNING;
}
- if (pref == 0 || pref > 65535)
+ if (!IN6_IS_ADDR_LINKLOCAL(&addr))
{
- vty_out (vty, "the fourth field must be <1-65535>%s", VTY_NEWLINE);
+ vty_out (vty, "%% Invalid link-local nexthop address%s", VTY_NEWLINE);
return CMD_WARNING;
}
+ if (rmap_match_set_hook.set_ipv6_nexthop_local)
+ return rmap_match_set_hook.set_ipv6_nexthop_local (vty, index, "ipv6 next-hop local", argv[idx_ipv6]->arg);
+ return CMD_SUCCESS;
+}
+
+
+DEFUN (no_set_ipv6_nexthop_local,
+ no_set_ipv6_nexthop_local_cmd,
+ "no set ipv6 next-hop local [X:X::X:X]",
+ NO_STR
+ SET_STR
+ IPV6_STR
+ "IPv6 next-hop address\n"
+ "IPv6 local address\n"
+ "IPv6 address of next hop\n")
+{
+ int idx_ipv6 = 5;
+ VTY_DECLVAR_CONTEXT (route_map_index, index);
+
+ if (rmap_match_set_hook.no_set_ipv6_nexthop_local)
+ {
+ if (argc <= idx_ipv6)
+ return rmap_match_set_hook.no_set_ipv6_nexthop_local (vty, index, "ipv6 next-hop local", NULL);
+ return rmap_match_set_hook.no_set_ipv6_nexthop_local (vty, index, "ipv6 next-hop local", argv[5]->arg);
+ }
+ return CMD_SUCCESS;
+}
+
+DEFUN (set_metric,
+ set_metric_cmd,
+ "set metric <(0-4294967295)|rtt|+rtt|-rtt|+metric|-metric>",
+ SET_STR
+ "Metric value for destination routing protocol\n"
+ "Metric value\n"
+ "Assign round trip time\n"
+ "Add round trip time\n"
+ "Subtract round trip time\n"
+ "Add metric\n"
+ "Subtract metric\n")
+{
+ int idx_number = 2;
+ VTY_DECLVAR_CONTEXT (route_map_index, index);
+
+ if (rmap_match_set_hook.set_metric)
+ return rmap_match_set_hook.set_metric (vty, index, "metric", argv[idx_number]->arg);
+ return CMD_SUCCESS;
+}
+
+
+DEFUN (no_set_metric,
+ no_set_metric_cmd,
+ "no set metric [(0-4294967295)]",
+ NO_STR
+ SET_STR
+ "Metric value for destination routing protocol\n"
+ "Metric value\n")
+{
+ int idx_number = 3;
+ VTY_DECLVAR_CONTEXT (route_map_index, index);
+
+ if (rmap_match_set_hook.no_set_metric)
+ {
+ if (argc <= idx_number)
+ return rmap_match_set_hook.no_set_metric (vty, index, "metric", NULL);
+ return rmap_match_set_hook.no_set_metric (vty, index, "metric", argv[idx_number]->arg);
+ }
+ return CMD_SUCCESS;
+}
+
+
+DEFUN (set_tag,
+ set_tag_cmd,
+ "set tag (1-4294967295)",
+ SET_STR
+ "Tag value for routing protocol\n"
+ "Tag value\n")
+{
+ VTY_DECLVAR_CONTEXT (route_map_index, index);
+
+ int idx_number = 2;
+ if (rmap_match_set_hook.set_tag)
+ return rmap_match_set_hook.set_tag (vty, index, "tag", argv[idx_number]->arg);
+ return CMD_SUCCESS;
+}
+
+
+DEFUN (no_set_tag,
+ no_set_tag_cmd,
+ "no set tag [(1-4294967295)]",
+ NO_STR
+ SET_STR
+ "Tag value for routing protocol\n"
+ "Tag value\n")
+{
+ VTY_DECLVAR_CONTEXT (route_map_index, index);
+
+ int idx_number = 3;
+ if (rmap_match_set_hook.no_set_tag)
+ {
+ if (argc <= idx_number)
+ return rmap_match_set_hook.no_set_tag (vty, index, "tag", NULL);
+ return rmap_match_set_hook.no_set_tag (vty, index, "tag", argv[idx_number]->arg);
+ }
+ return CMD_SUCCESS;
+}
+
+
+
+DEFUN (route_map,
+ route_map_cmd,
+ "route-map WORD <deny|permit> (1-65535)",
+ "Create route-map or enter route-map command mode\n"
+ "Route map tag\n"
+ "Route map denies set operations\n"
+ "Route map permits set operations\n"
+ "Sequence to insert to/delete from existing route-map entry\n")
+{
+ int idx_word = 1;
+ int idx_permit_deny = 2;
+ int idx_number = 3;
+ struct route_map *map;
+ struct route_map_index *index;
+ char *endptr = NULL;
+ int permit = argv[idx_permit_deny]->arg[0] == 'p' ? RMAP_PERMIT : RMAP_DENY;
+ unsigned long pref = strtoul (argv[idx_number]->arg, &endptr, 10);
+ const char *mapname = argv[idx_word]->arg;
+
/* Get route map. */
- map = route_map_get (argv[0]);
+ map = route_map_get (mapname);
index = route_map_index_get (map, permit, pref);
VTY_PUSH_CONTEXT_COMPAT (RMAP_NODE, index);
@@ -1442,13 +2559,14 @@ DEFUN (no_route_map_all,
"Create route-map or enter route-map command mode\n"
"Route map tag\n")
{
+ int idx_word = 2;
+ const char *mapname = argv[idx_word]->arg;
struct route_map *map;
- map = route_map_lookup_by_name (argv[0]);
+ map = route_map_lookup_by_name (mapname);
if (map == NULL)
{
- vty_out (vty, "%% Could not find route-map %s%s",
- argv[0], VTY_NEWLINE);
+ vty_out (vty, "%% Could not find route-map %s%s", mapname, VTY_NEWLINE);
return CMD_WARNING;
}
@@ -1459,7 +2577,7 @@ DEFUN (no_route_map_all,
DEFUN (no_route_map,
no_route_map_cmd,
- "no route-map WORD (deny|permit) <1-65535>",
+ "no route-map WORD <deny|permit> (1-65535)",
NO_STR
"Create route-map or enter route-map command mode\n"
"Route map tag\n"
@@ -1467,43 +2585,22 @@ DEFUN (no_route_map,
"Route map permits set operations\n"
"Sequence to insert to/delete from existing route-map entry\n")
{
- int permit;
- unsigned long pref;
+ int idx_word = 2;
+ int idx_permit_deny = 3;
+ int idx_number = 4;
struct route_map *map;
struct route_map_index *index;
char *endptr = NULL;
-
- /* Permit check. */
- if (strncmp (argv[1], "permit", strlen (argv[1])) == 0)
- permit = RMAP_PERMIT;
- else if (strncmp (argv[1], "deny", strlen (argv[1])) == 0)
- permit = RMAP_DENY;
- else
- {
- vty_out (vty, "the third field must be [permit|deny]%s", VTY_NEWLINE);
- return CMD_WARNING;
- }
-
- /* Preference. */
- pref = strtoul (argv[2], &endptr, 10);
- if (pref == ULONG_MAX || *endptr != '\0')
- {
- vty_out (vty, "the fourth field must be positive integer%s",
- VTY_NEWLINE);
- return CMD_WARNING;
- }
- if (pref == 0 || pref > 65535)
- {
- vty_out (vty, "the fourth field must be <1-65535>%s", VTY_NEWLINE);
- return CMD_WARNING;
- }
+ int permit = argv[idx_permit_deny]->arg[0] == 'p' ? RMAP_PERMIT : RMAP_DENY;
+ const char *prefstr = argv[idx_number]->arg;
+ const char *mapname = argv[idx_word]->arg;
+ unsigned long pref = strtoul (prefstr, &endptr, 10);
/* Existence check. */
- map = route_map_lookup_by_name (argv[0]);
+ map = route_map_lookup_by_name (mapname);
if (map == NULL)
{
- vty_out (vty, "%% Could not find route-map %s%s",
- argv[0], VTY_NEWLINE);
+ vty_out (vty, "%% Could not find route-map %s%s", mapname, VTY_NEWLINE);
return CMD_WARNING;
}
@@ -1512,7 +2609,7 @@ DEFUN (no_route_map,
if (index == NULL)
{
vty_out (vty, "%% Could not find route-map entry %s %s%s",
- argv[0], argv[2], VTY_NEWLINE);
+ mapname, prefstr, VTY_NEWLINE);
return CMD_WARNING;
}
@@ -1556,7 +2653,7 @@ DEFUN (no_rmap_onmatch_next,
"Next clause\n")
{
struct route_map_index *index = VTY_GET_CONTEXT (route_map_index);
-
+
if (index)
index->exitpolicy = RMAP_EXIT;
@@ -1565,11 +2662,16 @@ DEFUN (no_rmap_onmatch_next,
DEFUN (rmap_onmatch_goto,
rmap_onmatch_goto_cmd,
- "on-match goto <1-65535>",
+ "on-match goto (1-65535)",
"Exit policy on matches\n"
"Goto Clause number\n"
"Number\n")
{
+ int idx_number = 2;
+ char *num = NULL;
+ num = argv[idx_number]->arg;
+
+
struct route_map_index *index = VTY_GET_CONTEXT (route_map_index);
int d = 0;
@@ -1583,16 +2685,15 @@ DEFUN (rmap_onmatch_goto,
return CMD_WARNING;
}
- if (argc == 1 && argv[0])
- VTY_GET_INTEGER_RANGE("route-map index", d, argv[0], 1, 65535);
+ if (num)
+ VTY_GET_INTEGER_RANGE("route-map index", d, num, 1, 65535);
else
d = index->pref + 1;
if (d <= index->pref)
{
/* Can't allow you to do that, Dave */
- vty_out (vty, "can't jump backwards in route-maps%s",
- VTY_NEWLINE);
+ vty_out (vty, "can't jump backwards in route-maps%s", VTY_NEWLINE);
return CMD_WARNING;
}
else
@@ -1619,31 +2720,28 @@ DEFUN (no_rmap_onmatch_goto,
return CMD_SUCCESS;
}
-/* Cisco/GNU Zebra compatible ALIASes for on-match next */
-ALIAS (rmap_onmatch_goto,
+/* Cisco/GNU Zebra compatibility aliases */
+/* ALIAS_FIXME */
+DEFUN (rmap_continue,
rmap_continue_cmd,
- "continue",
- "Continue on a different entry within the route-map\n")
-
-ALIAS (no_rmap_onmatch_goto,
- no_rmap_continue_cmd,
- "no continue",
- NO_STR
- "Continue on a different entry within the route-map\n")
-
-/* GNU Zebra compatible */
-ALIAS (rmap_onmatch_goto,
- rmap_continue_seq_cmd,
- "continue <1-65535>",
+ "continue (1-65535)",
"Continue on a different entry within the route-map\n"
"Route-map entry sequence number\n")
+{
+ return rmap_onmatch_goto (self, vty, argc, argv);
+}
-ALIAS (no_rmap_onmatch_goto,
- no_rmap_continue_seq,
- "no continue <1-65535>",
+/* ALIAS_FIXME */
+DEFUN (no_rmap_continue,
+ no_rmap_continue_cmd,
+ "no continue [(1-65535)]",
NO_STR
"Continue on a different entry within the route-map\n"
"Route-map entry sequence number\n")
+{
+ return no_rmap_onmatch_goto (self, vty, argc, argv);
+}
+
DEFUN (rmap_show_name,
rmap_show_name_cmd,
@@ -1652,25 +2750,20 @@ DEFUN (rmap_show_name,
"route-map information\n"
"route-map name\n")
{
- const char *name = NULL;
- if (argc)
- name = argv[0];
- return vty_show_route_map (vty, name);
+ int idx_word = 2;
+ const char *name = (argc == 3) ? argv[idx_word]->arg : NULL;
+ return vty_show_route_map (vty, name);
}
-ALIAS (rmap_onmatch_goto,
- rmap_continue_index_cmd,
- "continue <1-65535>",
- "Exit policy on matches\n"
- "Goto Clause number\n")
-
DEFUN (rmap_call,
rmap_call_cmd,
"call WORD",
"Jump to another Route-Map after match+set\n"
"Target route-map name\n")
{
+ int idx_word = 1;
struct route_map_index *index = VTY_GET_CONTEXT (route_map_index);
+ const char *rmap = argv[idx_word]->arg;
if (index)
{
@@ -1681,7 +2774,7 @@ DEFUN (rmap_call,
index->map->name);
XFREE (MTYPE_ROUTE_MAP_NAME, index->nextrm);
}
- index->nextrm = XSTRDUP (MTYPE_ROUTE_MAP_NAME, argv[0]);
+ index->nextrm = XSTRDUP (MTYPE_ROUTE_MAP_NAME, rmap);
}
/* Execute event hook. */
@@ -1713,17 +2806,18 @@ DEFUN (no_rmap_call,
DEFUN (rmap_description,
rmap_description_cmd,
- "description .LINE",
+ "description LINE...",
"Route-map comment\n"
"Comment describing this route-map rule\n")
{
+ int idx_line = 1;
struct route_map_index *index = VTY_GET_CONTEXT (route_map_index);
if (index)
{
if (index->description)
XFREE (MTYPE_TMP, index->description);
- index->description = argv_concat (argv, argc, 0);
+ index->description = argv_concat (argv, argc, idx_line);
}
return CMD_SUCCESS;
}
@@ -1876,11 +2970,10 @@ route_map_init (void)
install_element (RMAP_NODE, &no_rmap_onmatch_next_cmd);
install_element (RMAP_NODE, &rmap_onmatch_goto_cmd);
install_element (RMAP_NODE, &no_rmap_onmatch_goto_cmd);
-
- /* Install the continue stuff (ALIAS of on-match). */
install_element (RMAP_NODE, &rmap_continue_cmd);
install_element (RMAP_NODE, &no_rmap_continue_cmd);
- install_element (RMAP_NODE, &rmap_continue_index_cmd);
+
+ /* Install the continue stuff (ALIAS of on-match). */
/* Install the call stuff. */
install_element (RMAP_NODE, &rmap_call_cmd);
@@ -1892,4 +2985,44 @@ route_map_init (void)
/* Install show command */
install_element (ENABLE_NODE, &rmap_show_name_cmd);
+
+ install_element (RMAP_NODE, &match_interface_cmd);
+ install_element (RMAP_NODE, &no_match_interface_cmd);
+
+ install_element (RMAP_NODE, &match_ip_address_cmd);
+ install_element (RMAP_NODE, &no_match_ip_address_cmd);
+
+ install_element (RMAP_NODE, &match_ip_address_prefix_list_cmd);
+ install_element (RMAP_NODE, &no_match_ip_address_prefix_list_cmd);
+
+ install_element (RMAP_NODE, &match_ip_next_hop_cmd);
+ install_element (RMAP_NODE, &no_match_ip_next_hop_cmd);
+
+ install_element (RMAP_NODE, &match_ip_next_hop_prefix_list_cmd);
+ install_element (RMAP_NODE, &no_match_ip_next_hop_prefix_list_cmd);
+
+ install_element (RMAP_NODE, &match_ipv6_address_cmd);
+ install_element (RMAP_NODE, &no_match_ipv6_address_cmd);
+
+ install_element (RMAP_NODE, &match_ipv6_address_prefix_list_cmd);
+ install_element (RMAP_NODE, &no_match_ipv6_address_prefix_list_cmd);
+
+ install_element (RMAP_NODE, &match_metric_cmd);
+ install_element (RMAP_NODE, &no_match_metric_cmd);
+
+ install_element (RMAP_NODE, &match_tag_cmd);
+ install_element (RMAP_NODE, &no_match_tag_cmd);
+
+ install_element (RMAP_NODE, &set_ip_nexthop_cmd);
+ install_element (RMAP_NODE, &no_set_ip_nexthop_cmd);
+
+ install_element (RMAP_NODE, &set_ipv6_nexthop_local_cmd);
+ install_element (RMAP_NODE, &no_set_ipv6_nexthop_local_cmd);
+
+ install_element (RMAP_NODE, &set_metric_cmd);
+ install_element (RMAP_NODE, &no_set_metric_cmd);
+
+ install_element (RMAP_NODE, &set_tag_cmd);
+ install_element (RMAP_NODE, &no_set_tag_cmd);
+
}
diff --git a/lib/routemap.h b/lib/routemap.h
index b5cdd27277..b52f7289b0 100644
--- a/lib/routemap.h
+++ b/lib/routemap.h
@@ -25,6 +25,8 @@
#include "prefix.h"
#include "memory.h"
#include "qobj.h"
+#include "vty.h"
+
DECLARE_MTYPE(ROUTE_MAP_NAME)
DECLARE_MTYPE(ROUTE_MAP_RULE)
DECLARE_MTYPE(ROUTE_MAP_COMPILED)
@@ -234,6 +236,172 @@ extern void route_map_upd8_dependency (route_map_event_t type, const char *arg,
extern void route_map_notify_dependencies (const char *affected_name,
route_map_event_t event);
+extern int generic_match_add (struct vty *vty,
+ struct route_map_index *index,
+ const char *command,
+ const char *arg,
+ route_map_event_t type);
+
+extern int generic_match_delete (struct vty *vty,
+ struct route_map_index *index,
+ const char *command,
+ const char *arg,
+ route_map_event_t type);
+extern int generic_set_add (struct vty *vty, struct route_map_index *index,
+ const char *command, const char *arg);
+extern int generic_set_delete (struct vty *vty, struct route_map_index *index,
+ const char *command, const char *arg);
+
+
+/* match interface */
+extern void route_map_match_interface_hook (int (*func) (struct vty *vty,
+ struct route_map_index *index,
+ const char *command,
+ const char *arg,
+ route_map_event_t type));
+/* no match interface */
+extern void route_map_no_match_interface_hook (int (*func) (struct vty *vty,
+ struct route_map_index *index,
+ const char *command,
+ const char *arg,
+ route_map_event_t type));
+/* match ip address */
+extern void route_map_match_ip_address_hook (int (*func) (struct vty *vty,
+ struct route_map_index *index,
+ const char *command,
+ const char *arg,
+ route_map_event_t type));
+/* no match ip address */
+extern void route_map_no_match_ip_address_hook (int (*func) (struct vty *vty,
+ struct route_map_index *index,
+ const char *command,
+ const char *arg,
+ route_map_event_t type));
+/* match ip address prefix list */
+extern void route_map_match_ip_address_prefix_list_hook (int (*func) (struct vty *vty,
+ struct route_map_index *index,
+ const char *command,
+ const char *arg,
+ route_map_event_t type));
+/* no match ip address prefix list */
+extern void route_map_no_match_ip_address_prefix_list_hook (int (*func) (struct vty *vty,
+ struct route_map_index *index,
+ const char *command,
+ const char *arg,
+ route_map_event_t type));
+/* match ip next hop */
+extern void route_map_match_ip_next_hop_hook (int (*func) (struct vty *vty,
+ struct route_map_index *index,
+ const char *command,
+ const char *arg,
+ route_map_event_t type));
+/* no match ip next hop */
+extern void route_map_no_match_ip_next_hop_hook (int (*func) (struct vty *vty,
+ struct route_map_index *index,
+ const char *command,
+ const char *arg,
+ route_map_event_t type));
+/* match ip next hop prefix list */
+extern void route_map_match_ip_next_hop_prefix_list_hook (int (*func) (struct vty *vty,
+ struct route_map_index *index,
+ const char *command,
+ const char *arg,
+ route_map_event_t type));
+/* no match ip next hop prefix list */
+extern void route_map_no_match_ip_next_hop_prefix_list_hook (int (*func) (struct vty *vty,
+ struct route_map_index *index,
+ const char *command,
+ const char *arg,
+ route_map_event_t type));
+/* match ipv6 address */
+extern void route_map_match_ipv6_address_hook (int (*func) (struct vty *vty,
+ struct route_map_index *index,
+ const char *command,
+ const char *arg,
+ route_map_event_t type));
+/* no match ipv6 address */
+extern void route_map_no_match_ipv6_address_hook (int (*func) (struct vty *vty,
+ struct route_map_index *index,
+ const char *command,
+ const char *arg,
+ route_map_event_t type));
+/* match ipv6 address prefix list */
+extern void route_map_match_ipv6_address_prefix_list_hook (int (*func) (struct vty *vty,
+ struct route_map_index *index,
+ const char *command,
+ const char *arg,
+ route_map_event_t type));
+/* no match ipv6 address prefix list */
+extern void route_map_no_match_ipv6_address_prefix_list_hook (int (*func) (struct vty *vty,
+ struct route_map_index *index,
+ const char *command,
+ const char *arg,
+ route_map_event_t type));
+/* match metric */
+extern void route_map_match_metric_hook (int (*func) (struct vty *vty,
+ struct route_map_index *index,
+ const char *command,
+ const char *arg,
+ route_map_event_t type));
+/* no match metric */
+extern void route_map_no_match_metric_hook (int (*func) (struct vty *vty,
+ struct route_map_index *index,
+ const char *command,
+ const char *arg,
+ route_map_event_t type));
+/* match tag */
+extern void route_map_match_tag_hook (int (*func) (struct vty *vty,
+ struct route_map_index *index,
+ const char *command,
+ const char *arg,
+ route_map_event_t type));
+/* no match tag */
+extern void route_map_no_match_tag_hook (int (*func) (struct vty *vty,
+ struct route_map_index *index,
+ const char *command,
+ const char *arg,
+ route_map_event_t type));
+/* set ip nexthop */
+extern void route_map_set_ip_nexthop_hook (int (*func) (struct vty *vty,
+ struct route_map_index *index,
+ const char *command,
+ const char *arg));
+/* no set ip nexthop */
+extern void route_map_no_set_ip_nexthop_hook (int (*func) (struct vty *vty,
+ struct route_map_index *index,
+ const char *command,
+ const char *arg));
+/* set ipv6 nexthop local */
+extern void route_map_set_ipv6_nexthop_local_hook (int (*func) (struct vty *vty,
+ struct route_map_index *index,
+ const char *command,
+ const char *arg));
+/* no set ipv6 nexthop local */
+extern void route_map_no_set_ipv6_nexthop_local_hook (int (*func) (struct vty *vty,
+ struct route_map_index *index,
+ const char *command,
+ const char *arg));
+/* set metric */
+extern void route_map_set_metric_hook (int (*func) (struct vty *vty,
+ struct route_map_index *index,
+ const char *command,
+ const char *arg));
+/* no set metric */
+extern void route_map_no_set_metric_hook (int (*func) (struct vty *vty,
+ struct route_map_index *index,
+ const char *command,
+ const char *arg));
+/* set tag */
+extern void route_map_set_tag_hook (int (*func) (struct vty *vty,
+ struct route_map_index *index,
+ const char *command,
+ const char *arg));
+/* no set tag */
+extern void route_map_no_set_tag_hook (int (*func) (struct vty *vty,
+ struct route_map_index *index,
+ const char *command,
+ const char *arg));
+
extern void *route_map_rule_tag_compile (const char *arg);
extern void route_map_rule_tag_free (void *rule);
diff --git a/lib/smux.c b/lib/smux.c
index 5012e8d95e..82bf64f1c8 100644
--- a/lib/smux.c
+++ b/lib/smux.c
@@ -1370,7 +1370,8 @@ DEFUN (smux_peer,
"SNMP MUX peer settings\n"
"Object ID used in SMUX peering\n")
{
- if (smux_peer_oid (vty, argv[0], NULL) == 0)
+ int idx_oid = 2;
+ if (smux_peer_oid (vty, argv[idx_oid]->arg, NULL) == 0)
{
smux_start();
return CMD_SUCCESS;
@@ -1387,7 +1388,8 @@ DEFUN (smux_peer_password,
"SMUX peering object ID\n"
"SMUX peering password\n")
{
- if (smux_peer_oid (vty, argv[0], argv[1]) == 0)
+ int idx_oid = 2;
+ if (smux_peer_oid (vty, argv[idx_oid]->arg, argv[3]->rg) == 0)
{
smux_start();
return CMD_SUCCESS;
@@ -1398,32 +1400,17 @@ DEFUN (smux_peer_password,
DEFUN (no_smux_peer,
no_smux_peer_cmd,
- "no smux peer",
+ "no smux peer [OID [PASSWORD]]",
NO_STR
"SNMP MUX protocol settings\n"
- "SNMP MUX peer settings\n")
+ "SNMP MUX peer settings\n"
+ "SMUX peering object ID\n"
+ "SMUX peering password\n")
{
smux_stop();
return smux_peer_default ();
}
-ALIAS (no_smux_peer,
- no_smux_peer_oid_cmd,
- "no smux peer OID",
- NO_STR
- "SNMP MUX protocol settings\n"
- "SNMP MUX peer settings\n"
- "SMUX peering object ID\n")
-
-ALIAS (no_smux_peer,
- no_smux_peer_oid_password_cmd,
- "no smux peer OID PASSWORD",
- NO_STR
- "SNMP MUX protocol settings\n"
- "SNMP MUX peer settings\n"
- "SMUX peering object ID\n"
- "SMUX peering password\n")
-
static int
config_write_smux (struct vty *vty)
{
diff --git a/lib/str.c b/lib/str.c
index 16f759c074..cfdb6e024e 100644
--- a/lib/str.c
+++ b/lib/str.c
@@ -133,3 +133,11 @@ strndup (const char *s, size_t maxlen)
return (char *) memcpy (new, s, len);
}
#endif
+
+extern int
+strmatch (const char *str1, const char *str2)
+{
+ if (!strcmp(str1, str2))
+ return 1;
+ return 0;
+}
diff --git a/lib/str.h b/lib/str.h
index 7b83fe1cb1..dc8e7e5d67 100644
--- a/lib/str.h
+++ b/lib/str.h
@@ -29,5 +29,7 @@ extern size_t strnlen(const char *s, size_t maxlen);
extern char * strndup (const char *, size_t);
#endif
+extern int strmatch (const char *, const char *);
+
#endif /* _ZEBRA_STR_H */
diff --git a/lib/thread.c b/lib/thread.c
index 26be17585e..5dc296f2cc 100644
--- a/lib/thread.c
+++ b/lib/thread.c
@@ -278,7 +278,7 @@ cpu_record_print(struct vty *vty, thread_type filter)
vty_out(vty, "%21s %18s %18s%s",
"", "CPU (user+system):", "Real (wall-clock):", VTY_NEWLINE);
#endif
- vty_out(vty, " Runtime(ms) Invoked Avg uSec Max uSecs");
+ vty_out(vty, "Runtime(ms) Invoked Avg uSec Max uSecs");
#ifdef HAVE_RUSAGE
vty_out(vty, " Avg uSec Max uSecs");
#endif
@@ -299,15 +299,16 @@ DEFUN (show_thread_cpu,
"Thread CPU usage\n"
"Display filter (rwtexb)\n")
{
+ int idx_filter = 3;
int i = 0;
thread_type filter = (thread_type) -1U;
- if (argc > 0)
+ if (argc > 3)
{
filter = 0;
- while (argv[0][i] != '\0')
+ while (argv[idx_filter]->arg[i] != '\0')
{
- switch ( argv[0][i] )
+ switch ( argv[idx_filter]->arg[i] )
{
case 'r':
case 'R':
@@ -342,7 +343,7 @@ DEFUN (show_thread_cpu,
{
vty_out(vty, "Invalid filter \"%s\" specified,"
" must contain at least one of 'RWTEXB'%s",
- argv[0], VTY_NEWLINE);
+ argv[idx_filter]->arg, VTY_NEWLINE);
return CMD_WARNING;
}
}
@@ -381,15 +382,16 @@ DEFUN (clear_thread_cpu,
"Thread CPU usage\n"
"Display filter (rwtexb)\n")
{
+ int idx_filter = 3;
int i = 0;
thread_type filter = (thread_type) -1U;
- if (argc > 0)
+ if (argc > 3)
{
filter = 0;
- while (argv[0][i] != '\0')
+ while (argv[idx_filter]->arg[i] != '\0')
{
- switch ( argv[0][i] )
+ switch ( argv[idx_filter]->arg[i] )
{
case 'r':
case 'R':
@@ -424,7 +426,7 @@ DEFUN (clear_thread_cpu,
{
vty_out(vty, "Invalid filter \"%s\" specified,"
" must contain at least one of 'RWTEXB'%s",
- argv[0], VTY_NEWLINE);
+ argv[idx_filter]->arg, VTY_NEWLINE);
return CMD_WARNING;
}
}
diff --git a/lib/vrf.h b/lib/vrf.h
index 127b7082e9..f1fbad9ff5 100644
--- a/lib/vrf.h
+++ b/lib/vrf.h
@@ -51,11 +51,7 @@ enum {
/*
* The command strings
*/
-
-#define VRF_CMD_STR "vrf NAME"
#define VRF_CMD_HELP_STR "Specify the VRF\nThe VRF name\n"
-
-#define VRF_ALL_CMD_STR "vrf all"
#define VRF_ALL_CMD_HELP_STR "Specify the VRF\nAll VRFs\n"
/*
diff --git a/lib/vty.c b/lib/vty.c
index 171aca1739..78bf0e720d 100644
--- a/lib/vty.c
+++ b/lib/vty.c
@@ -17,7 +17,7 @@
* You should have received a copy of the GNU General Public License
* along with GNU Zebra; see the file COPYING. If not, write to the Free
* Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
+ * 02111-1307, USA.
*/
#include <zebra.h>
@@ -45,7 +45,7 @@ DEFINE_MTYPE_STATIC(LIB, VTY_OUT_BUF, "VTY output buffer")
DEFINE_MTYPE_STATIC(LIB, VTY_HIST, "VTY history")
/* Vty events */
-enum event
+enum event
{
VTY_SERV,
VTY_READ,
@@ -118,37 +118,37 @@ vty_out (struct vty *vty, const char *format, ...)
/* Initial buffer is not enough. */
if (len < 0 || len >= size)
- {
- while (1)
- {
- if (len > -1)
- size = len + 1;
- else
- size = size * 2;
-
- p = XREALLOC (MTYPE_VTY_OUT_BUF, p, size);
- if (! p)
- return -1;
-
- va_start (args, format);
- len = vsnprintf (p, size, format, args);
- va_end (args);
-
- if (len > -1 && len < size)
- break;
- }
- }
+ {
+ while (1)
+ {
+ if (len > -1)
+ size = len + 1;
+ else
+ size = size * 2;
+
+ p = XREALLOC (MTYPE_VTY_OUT_BUF, p, size);
+ if (! p)
+ return -1;
+
+ va_start (args, format);
+ len = vsnprintf (p, size, format, args);
+ va_end (args);
+
+ if (len > -1 && len < size)
+ break;
+ }
+ }
/* When initial buffer is enough to store all output. */
if (! p)
- p = buf;
+ p = buf;
/* Pointer p must point out buffer. */
buffer_put (vty->obuf, (u_char *) p, len);
/* If p is not different with buf, it is allocated buffer. */
if (p != buf)
- XFREE (MTYPE_VTY_OUT_BUF, p);
+ XFREE (MTYPE_VTY_OUT_BUF, p);
}
return len;
@@ -156,7 +156,7 @@ vty_out (struct vty *vty, const char *format, ...)
static int
vty_log_out (struct vty *vty, const char *level, const char *proto_str,
- const char *format, struct timestamp_control *ctl, va_list va)
+ const char *format, struct timestamp_control *ctl, va_list va)
{
int ret;
int len;
@@ -190,13 +190,13 @@ vty_log_out (struct vty *vty, const char *level, const char *proto_str,
if (write(vty->wfd, buf, len) < 0)
{
if (ERRNO_IO_RETRY(errno))
- /* Kernel buffer is full, probably too much debugging output, so just
- drop the data and ignore. */
- return -1;
+ /* Kernel buffer is full, probably too much debugging output, so just
+ drop the data and ignore. */
+ return -1;
/* Fatal I/O error. */
vty->monitor = 0; /* disable monitoring to avoid infinite recursion */
zlog_warn("%s: write failed to vty client fd %d, closing: %s",
- __func__, vty->fd, safe_strerror(errno));
+ __func__, vty->fd, safe_strerror(errno));
buffer_reset(vty->obuf);
/* cannot call vty_close, because a parent routine may still try
to access the vty struct */
@@ -212,7 +212,7 @@ void
vty_time_print (struct vty *vty, int cr)
{
char buf[QUAGGA_TIMESTAMP_LEN];
-
+
if (quagga_timestamp(0, buf, sizeof(buf)) == 0)
{
zlog (NULL, LOG_INFO, "quagga_timestamp error");
@@ -237,20 +237,20 @@ vty_hello (struct vty *vty)
f = fopen (host.motdfile, "r");
if (f)
- {
- while (fgets (buf, sizeof (buf), f))
- {
- char *s;
- /* work backwards to ignore trailling isspace() */
- for (s = buf + strlen (buf); (s > buf) && isspace ((int)*(s - 1));
- s--);
- *s = '\0';
- vty_out (vty, "%s%s", buf, VTY_NEWLINE);
- }
- fclose (f);
- }
+ {
+ while (fgets (buf, sizeof (buf), f))
+ {
+ char *s;
+ /* work backwards to ignore trailling isspace() */
+ for (s = buf + strlen (buf); (s > buf) && isspace ((int)*(s - 1));
+ s--);
+ *s = '\0';
+ vty_out (vty, "%s%s", buf, VTY_NEWLINE);
+ }
+ fclose (f);
+ }
else
- vty_out (vty, "MOTD file not found%s", VTY_NEWLINE);
+ vty_out (vty, "MOTD file not found%s", VTY_NEWLINE);
}
else if (host.motd)
vty_out (vty, "%s", host.motd);
@@ -267,10 +267,10 @@ vty_prompt (struct vty *vty)
{
hostname = host.name;
if (!hostname)
- {
- uname (&names);
- hostname = names.nodename;
- }
+ {
+ uname (&names);
+ hostname = names.nodename;
+ }
vty_out (vty, cmd_prompt (vty->node), hostname);
}
}
@@ -323,7 +323,7 @@ vty_new ()
{
struct vty *new = XCALLOC (MTYPE_VTY, sizeof (struct vty));
- new->obuf = buffer_new(0); /* Use default buffer size. */
+ 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;
@@ -344,19 +344,19 @@ vty_auth (struct vty *vty, char *buf)
{
case AUTH_NODE:
if (host.encrypt)
- passwd = host.password_encrypt;
+ passwd = host.password_encrypt;
else
- passwd = host.password;
+ passwd = host.password;
if (host.advanced)
- next_node = host.enable ? VIEW_NODE : ENABLE_NODE;
+ next_node = host.enable ? VIEW_NODE : ENABLE_NODE;
else
- next_node = VIEW_NODE;
+ next_node = VIEW_NODE;
break;
case AUTH_ENABLE_NODE:
if (host.encrypt)
- passwd = host.enable_encrypt;
+ passwd = host.enable_encrypt;
else
- passwd = host.enable;
+ passwd = host.enable;
next_node = ENABLE_NODE;
break;
}
@@ -364,9 +364,9 @@ vty_auth (struct vty *vty, char *buf)
if (passwd)
{
if (host.encrypt)
- fail = strcmp (crypt(buf, passwd), passwd);
+ fail = strcmp (crypt(buf, passwd), passwd);
else
- fail = strcmp (buf, passwd);
+ fail = strcmp (buf, passwd);
}
else
fail = 1;
@@ -374,26 +374,26 @@ vty_auth (struct vty *vty, char *buf)
if (! fail)
{
vty->fail = 0;
- vty->node = next_node; /* Success ! */
+ vty->node = next_node; /* Success ! */
}
else
{
vty->fail++;
if (vty->fail >= 3)
- {
- if (vty->node == AUTH_NODE)
- {
- vty_out (vty, "%% Bad passwords, too many failures!%s", VTY_NEWLINE);
- vty->status = VTY_CLOSE;
- }
- else
- {
- /* AUTH_ENABLE_NODE */
- vty->fail = 0;
- vty_out (vty, "%% Bad enable passwords, too many failures!%s", VTY_NEWLINE);
+ {
+ if (vty->node == AUTH_NODE)
+ {
+ vty_out (vty, "%% Bad passwords, too many failures!%s", VTY_NEWLINE);
+ vty->status = VTY_CLOSE;
+ }
+ else
+ {
+ /* AUTH_ENABLE_NODE */
+ vty->fail = 0;
+ vty_out (vty, "%% Bad enable passwords, too many failures!%s", VTY_NEWLINE);
vty->status = VTY_CLOSE;
- }
- }
+ }
+ }
}
}
@@ -420,7 +420,7 @@ vty_command (struct vty *vty, char *buf)
if (cp != NULL && *cp != '\0')
{
unsigned i;
- char vty_str[VTY_BUFSIZ];
+ char vty_str[VTY_BUFSIZ];
char prompt_str[VTY_BUFSIZ];
/* format the base vty info */
@@ -462,14 +462,14 @@ vty_command (struct vty *vty, char *buf)
protocolname = zlog_proto_names[zlog_default->protocol];
else
protocolname = zlog_proto_names[ZLOG_NONE];
-
+
#ifdef CONSUMED_TIME_CHECK
GETRUSAGE(&after);
if ((realtime = thread_consumed_time(&after, &before, &cputime)) >
- CONSUMED_TIME_CHECK)
+ CONSUMED_TIME_CHECK)
/* Warn about CPU hog that must be fixed. */
zlog_warn("SLOW COMMAND: command took %lums (cpu time %lums): %s",
- realtime/1000, cputime/1000, buf);
+ realtime/1000, cputime/1000, buf);
}
#endif /* CONSUMED_TIME_CHECK */
@@ -477,18 +477,18 @@ vty_command (struct vty *vty, char *buf)
switch (ret)
{
case CMD_WARNING:
- if (vty->type == VTY_FILE)
- vty_out (vty, "Warning...%s", VTY_NEWLINE);
- break;
+ if (vty->type == VTY_FILE)
+ vty_out (vty, "Warning...%s", VTY_NEWLINE);
+ break;
case CMD_ERR_AMBIGUOUS:
- vty_out (vty, "%% Ambiguous command.%s", VTY_NEWLINE);
- break;
+ vty_out (vty, "%% Ambiguous command.%s", VTY_NEWLINE);
+ break;
case CMD_ERR_NO_MATCH:
- vty_out (vty, "%% [%s] Unknown command: %s%s", protocolname, buf, VTY_NEWLINE);
- break;
+ vty_out (vty, "%% [%s] Unknown command: %s%s", protocolname, buf, VTY_NEWLINE);
+ break;
case CMD_ERR_INCOMPLETE:
- vty_out (vty, "%% Command incomplete.%s", VTY_NEWLINE);
- break;
+ vty_out (vty, "%% Command incomplete.%s", VTY_NEWLINE);
+ break;
}
cmd_free_strvec (vline);
@@ -686,7 +686,7 @@ vty_forward_word (struct vty *vty)
{
while (vty->cp != vty->length && vty->buf[vty->cp] != ' ')
vty_forward_char (vty);
-
+
while (vty->cp != vty->length && vty->buf[vty->cp] == ' ')
vty_forward_char (vty);
}
@@ -792,14 +792,14 @@ vty_delete_char (struct vty *vty)
}
if (vty->cp == vty->length)
- return; /* completion need here? */
+ return; /* completion need here? */
size = vty->length - vty->cp;
vty->length--;
memmove (&vty->buf[vty->cp], &vty->buf[vty->cp + 1], size - 1);
vty->buf[vty->length] = '\0';
-
+
if (vty->node == AUTH_NODE || vty->node == AUTH_ENABLE_NODE)
return;
@@ -829,7 +829,7 @@ vty_kill_line (struct vty *vty)
int size;
size = vty->length - vty->cp;
-
+
if (size == 0)
return;
@@ -924,7 +924,7 @@ vty_complete_command (struct vty *vty)
vector_set (vline, NULL);
matched = cmd_complete_command_lib (vline, vty, &ret, 1);
-
+
cmd_free_strvec (vline);
vty_out (vty, "%s", VTY_NEWLINE);
@@ -959,12 +959,12 @@ vty_complete_command (struct vty *vty)
break;
case CMD_COMPLETE_LIST_MATCH:
for (i = 0; matched[i] != NULL; i++)
- {
- if (i != 0 && ((i % 6) == 0))
- vty_out (vty, "%s", VTY_NEWLINE);
- vty_out (vty, "%-10s ", matched[i]);
- XFREE (MTYPE_TMP, matched[i]);
- }
+ {
+ if (i != 0 && ((i % 6) == 0))
+ vty_out (vty, "%s", VTY_NEWLINE);
+ vty_out (vty, "%-10s ", matched[i]);
+ XFREE (MTYPE_TMP, matched[i]);
+ }
vty_out (vty, "%s", VTY_NEWLINE);
vty_prompt (vty);
@@ -983,13 +983,13 @@ vty_complete_command (struct vty *vty)
static void
vty_describe_fold (struct vty *vty, int cmd_width,
- unsigned int desc_width, struct cmd_token *token)
+ unsigned int desc_width, struct cmd_token *token)
{
char *buf;
const char *cmd, *p;
int pos;
- cmd = token->cmd[0] == '.' ? token->cmd + 1 : token->cmd;
+ cmd = token->text;
if (desc_width <= 0)
{
@@ -1038,7 +1038,7 @@ vty_describe_command (struct vty *vty)
vline = vector_init (1);
vector_set (vline, NULL);
}
- else
+ else
if (isspace ((int) vty->buf[vty->length - 1]))
vector_set (vline, NULL);
@@ -1057,24 +1057,22 @@ vty_describe_command (struct vty *vty)
vty_out (vty, "%% There is no matched command.%s", VTY_NEWLINE);
goto out;
break;
- }
+ }
/* Get width of command string. */
width = 0;
for (i = 0; i < vector_active (describe); i++)
if ((token = vector_slot (describe, i)) != NULL)
{
- unsigned int len;
+ unsigned int len;
- if (token->cmd[0] == '\0')
- continue;
+ if (token->text[0] == '\0')
+ continue;
- len = strlen (token->cmd);
- if (token->cmd[0] == '.')
- len--;
+ len = strlen (token->text);
- if (width < len)
- width = len;
+ if (width < len)
+ width = len;
}
/* Get width of description string. */
@@ -1084,45 +1082,45 @@ vty_describe_command (struct vty *vty)
for (i = 0; i < vector_active (describe); i++)
if ((token = vector_slot (describe, i)) != NULL)
{
- if (token->cmd[0] == '\0')
- continue;
-
- if (strcmp (token->cmd, command_cr) == 0)
- {
- token_cr = token;
- continue;
- }
-
- if (!token->desc)
- vty_out (vty, " %-s%s",
- token->cmd[0] == '.' ? token->cmd + 1 : token->cmd,
- VTY_NEWLINE);
- else if (desc_width >= strlen (token->desc))
- vty_out (vty, " %-*s %s%s", width,
- token->cmd[0] == '.' ? token->cmd + 1 : token->cmd,
- token->desc, VTY_NEWLINE);
- else
- vty_describe_fold (vty, width, desc_width, token);
+ if (token->text[0] == '\0')
+ continue;
+
+ if (strcmp (token->text, CMD_CR_TEXT) == 0)
+ {
+ token_cr = token;
+ continue;
+ }
+
+ if (!token->desc)
+ vty_out (vty, " %-s%s",
+ token->text,
+ VTY_NEWLINE);
+ else if (desc_width >= strlen (token->desc))
+ vty_out (vty, " %-*s %s%s", width,
+ token->text,
+ token->desc, VTY_NEWLINE);
+ else
+ vty_describe_fold (vty, width, desc_width, token);
#if 0
- vty_out (vty, " %-*s %s%s", width
- desc->cmd[0] == '.' ? desc->cmd + 1 : desc->cmd,
- desc->str ? desc->str : "", VTY_NEWLINE);
+ vty_out (vty, " %-*s %s%s", width
+ desc->cmd[0] == '.' ? desc->cmd + 1 : desc->cmd,
+ desc->str ? desc->str : "", VTY_NEWLINE);
#endif /* 0 */
}
if ((token = token_cr))
{
if (!token->desc)
- vty_out (vty, " %-s%s",
- token->cmd[0] == '.' ? token->cmd + 1 : token->cmd,
- VTY_NEWLINE);
+ vty_out (vty, " %-s%s",
+ token->text,
+ VTY_NEWLINE);
else if (desc_width >= strlen (token->desc))
- vty_out (vty, " %-*s %s%s", width,
- token->cmd[0] == '.' ? token->cmd + 1 : token->cmd,
- token->desc, VTY_NEWLINE);
+ vty_out (vty, " %-*s %s%s", width,
+ token->text,
+ token->desc, VTY_NEWLINE);
else
- vty_describe_fold (vty, width, desc_width, token);
+ vty_describe_fold (vty, width, desc_width, token);
}
out:
@@ -1233,41 +1231,41 @@ vty_telnet_option (struct vty *vty, unsigned char *buf, int nbytes)
for (i = 0; i < nbytes; i++)
{
switch (buf[i])
- {
- case IAC:
- vty_out (vty, "IAC ");
- break;
- case WILL:
- vty_out (vty, "WILL ");
- break;
- case WONT:
- vty_out (vty, "WONT ");
- break;
- case DO:
- vty_out (vty, "DO ");
- break;
- case DONT:
- vty_out (vty, "DONT ");
- break;
- case SB:
- vty_out (vty, "SB ");
- break;
- case SE:
- vty_out (vty, "SE ");
- break;
- case TELOPT_ECHO:
- vty_out (vty, "TELOPT_ECHO %s", VTY_NEWLINE);
- break;
- case TELOPT_SGA:
- vty_out (vty, "TELOPT_SGA %s", VTY_NEWLINE);
- break;
- case TELOPT_NAWS:
- vty_out (vty, "TELOPT_NAWS %s", VTY_NEWLINE);
- break;
- default:
- vty_out (vty, "%x ", buf[i]);
- break;
- }
+ {
+ case IAC:
+ vty_out (vty, "IAC ");
+ break;
+ case WILL:
+ vty_out (vty, "WILL ");
+ break;
+ case WONT:
+ vty_out (vty, "WONT ");
+ break;
+ case DO:
+ vty_out (vty, "DO ");
+ break;
+ case DONT:
+ vty_out (vty, "DONT ");
+ break;
+ case SB:
+ vty_out (vty, "SB ");
+ break;
+ case SE:
+ vty_out (vty, "SE ");
+ break;
+ case TELOPT_ECHO:
+ vty_out (vty, "TELOPT_ECHO %s", VTY_NEWLINE);
+ break;
+ case TELOPT_SGA:
+ vty_out (vty, "TELOPT_SGA %s", VTY_NEWLINE);
+ break;
+ case TELOPT_NAWS:
+ vty_out (vty, "TELOPT_NAWS %s", VTY_NEWLINE);
+ break;
+ default:
+ vty_out (vty, "%x ", buf[i]);
+ break;
+ }
}
vty_out (vty, "%s", VTY_NEWLINE);
@@ -1280,42 +1278,42 @@ vty_telnet_option (struct vty *vty, unsigned char *buf, int nbytes)
vty->iac_sb_in_progress = 1;
return 0;
break;
- case SE:
+ case SE:
{
- if (!vty->iac_sb_in_progress)
- return 0;
-
- if ((vty->sb_len == 0) || (vty->sb_buf[0] == '\0'))
- {
- vty->iac_sb_in_progress = 0;
- return 0;
- }
- switch (vty->sb_buf[0])
- {
- case TELOPT_NAWS:
- if (vty->sb_len != TELNET_NAWS_SB_LEN)
- zlog_warn("RFC 1073 violation detected: telnet NAWS option "
- "should send %d characters, but we received %lu",
- TELNET_NAWS_SB_LEN, (u_long)vty->sb_len);
- else if (sizeof(vty->sb_buf) < TELNET_NAWS_SB_LEN)
- zlog_err("Bug detected: sizeof(vty->sb_buf) %lu < %d, "
- "too small to handle the telnet NAWS option",
- (u_long)sizeof(vty->sb_buf), TELNET_NAWS_SB_LEN);
- else
- {
- vty->width = ((vty->sb_buf[1] << 8)|vty->sb_buf[2]);
- vty->height = ((vty->sb_buf[3] << 8)|vty->sb_buf[4]);
+ if (!vty->iac_sb_in_progress)
+ return 0;
+
+ if ((vty->sb_len == 0) || (vty->sb_buf[0] == '\0'))
+ {
+ vty->iac_sb_in_progress = 0;
+ return 0;
+ }
+ switch (vty->sb_buf[0])
+ {
+ case TELOPT_NAWS:
+ if (vty->sb_len != TELNET_NAWS_SB_LEN)
+ zlog_warn("RFC 1073 violation detected: telnet NAWS option "
+ "should send %d characters, but we received %lu",
+ TELNET_NAWS_SB_LEN, (u_long)vty->sb_len);
+ else if (sizeof(vty->sb_buf) < TELNET_NAWS_SB_LEN)
+ zlog_err("Bug detected: sizeof(vty->sb_buf) %lu < %d, "
+ "too small to handle the telnet NAWS option",
+ (u_long)sizeof(vty->sb_buf), TELNET_NAWS_SB_LEN);
+ else
+ {
+ vty->width = ((vty->sb_buf[1] << 8)|vty->sb_buf[2]);
+ vty->height = ((vty->sb_buf[3] << 8)|vty->sb_buf[4]);
#ifdef TELNET_OPTION_DEBUG
- vty_out(vty, "TELNET NAWS window size negotiation completed: "
- "width %d, height %d%s",
- vty->width, vty->height, VTY_NEWLINE);
+ vty_out(vty, "TELNET NAWS window size negotiation completed: "
+ "width %d, height %d%s",
+ vty->width, vty->height, VTY_NEWLINE);
#endif
- }
- break;
- }
- vty->iac_sb_in_progress = 0;
- return 0;
- break;
+ }
+ break;
+ }
+ vty->iac_sb_in_progress = 0;
+ return 0;
+ break;
}
default:
break;
@@ -1340,7 +1338,7 @@ vty_execute (struct vty *vty)
default:
ret = vty_command (vty, vty->buf);
if (vty->type == VTY_TERM)
- vty_hist_add (vty);
+ vty_hist_add (vty);
break;
}
@@ -1410,187 +1408,187 @@ vty_read (struct thread *thread)
if ((nbytes = read (vty->fd, buf, VTY_READ_BUFSIZ)) <= 0)
{
if (nbytes < 0)
- {
- if (ERRNO_IO_RETRY(errno))
- {
- vty_event (VTY_READ, vty_sock, vty);
- return 0;
- }
- vty->monitor = 0; /* disable monitoring to avoid infinite recursion */
- zlog_warn("%s: read error on vty client fd %d, closing: %s",
- __func__, vty->fd, safe_strerror(errno));
+ {
+ if (ERRNO_IO_RETRY(errno))
+ {
+ vty_event (VTY_READ, vty_sock, vty);
+ return 0;
+ }
+ vty->monitor = 0; /* disable monitoring to avoid infinite recursion */
+ zlog_warn("%s: read error on vty client fd %d, closing: %s",
+ __func__, vty->fd, safe_strerror(errno));
buffer_reset(vty->obuf);
- }
+ }
vty->status = VTY_CLOSE;
}
- for (i = 0; i < nbytes; i++)
+ for (i = 0; i < nbytes; i++)
{
if (buf[i] == IAC)
- {
- if (!vty->iac)
- {
- vty->iac = 1;
- continue;
- }
- else
- {
- vty->iac = 0;
- }
- }
-
+ {
+ if (!vty->iac)
+ {
+ vty->iac = 1;
+ continue;
+ }
+ else
+ {
+ vty->iac = 0;
+ }
+ }
+
if (vty->iac_sb_in_progress && !vty->iac)
- {
- if (vty->sb_len < sizeof(vty->sb_buf))
- vty->sb_buf[vty->sb_len] = buf[i];
- vty->sb_len++;
- continue;
- }
+ {
+ if (vty->sb_len < sizeof(vty->sb_buf))
+ vty->sb_buf[vty->sb_len] = buf[i];
+ vty->sb_len++;
+ continue;
+ }
if (vty->iac)
- {
- /* In case of telnet command */
- int ret = 0;
- ret = vty_telnet_option (vty, buf + i, nbytes - i);
- vty->iac = 0;
- i += ret;
- continue;
- }
-
+ {
+ /* In case of telnet command */
+ int ret = 0;
+ ret = vty_telnet_option (vty, buf + i, nbytes - i);
+ vty->iac = 0;
+ i += ret;
+ continue;
+ }
+
if (vty->status == VTY_MORE)
- {
- switch (buf[i])
- {
- case CONTROL('C'):
- case 'q':
- case 'Q':
- vty_buffer_reset (vty);
- break;
+ {
+ switch (buf[i])
+ {
+ case CONTROL('C'):
+ case 'q':
+ case 'Q':
+ vty_buffer_reset (vty);
+ break;
#if 0 /* More line does not work for "show ip bgp". */
- case '\n':
- case '\r':
- vty->status = VTY_MORELINE;
- break;
+ case '\n':
+ case '\r':
+ vty->status = VTY_MORELINE;
+ break;
#endif
- default:
- break;
- }
- continue;
- }
+ default:
+ break;
+ }
+ continue;
+ }
/* Escape character. */
if (vty->escape == VTY_ESCAPE)
- {
- vty_escape_map (buf[i], vty);
- continue;
- }
+ {
+ vty_escape_map (buf[i], vty);
+ continue;
+ }
/* Pre-escape status. */
if (vty->escape == VTY_PRE_ESCAPE)
- {
- switch (buf[i])
- {
- case '[':
- vty->escape = VTY_ESCAPE;
- break;
- case 'b':
- vty_backward_word (vty);
- vty->escape = VTY_NORMAL;
- break;
- case 'f':
- vty_forward_word (vty);
- vty->escape = VTY_NORMAL;
- break;
- case 'd':
- vty_forward_kill_word (vty);
- vty->escape = VTY_NORMAL;
- break;
- case CONTROL('H'):
- case 0x7f:
- vty_backward_kill_word (vty);
- vty->escape = VTY_NORMAL;
- break;
- default:
- vty->escape = VTY_NORMAL;
- break;
- }
- continue;
- }
+ {
+ switch (buf[i])
+ {
+ case '[':
+ vty->escape = VTY_ESCAPE;
+ break;
+ case 'b':
+ vty_backward_word (vty);
+ vty->escape = VTY_NORMAL;
+ break;
+ case 'f':
+ vty_forward_word (vty);
+ vty->escape = VTY_NORMAL;
+ break;
+ case 'd':
+ vty_forward_kill_word (vty);
+ vty->escape = VTY_NORMAL;
+ break;
+ case CONTROL('H'):
+ case 0x7f:
+ vty_backward_kill_word (vty);
+ vty->escape = VTY_NORMAL;
+ break;
+ default:
+ vty->escape = VTY_NORMAL;
+ break;
+ }
+ continue;
+ }
switch (buf[i])
- {
- case CONTROL('A'):
- vty_beginning_of_line (vty);
- break;
- case CONTROL('B'):
- vty_backward_char (vty);
- break;
- case CONTROL('C'):
- vty_stop_input (vty);
- break;
- case CONTROL('D'):
- vty_delete_char (vty);
- break;
- case CONTROL('E'):
- vty_end_of_line (vty);
- break;
- case CONTROL('F'):
- vty_forward_char (vty);
- break;
- case CONTROL('H'):
- case 0x7f:
- vty_delete_backward_char (vty);
- break;
- case CONTROL('K'):
- vty_kill_line (vty);
- break;
- case CONTROL('N'):
- vty_next_line (vty);
- break;
- case CONTROL('P'):
- vty_previous_line (vty);
- break;
- case CONTROL('T'):
- vty_transpose_chars (vty);
- break;
- case CONTROL('U'):
- vty_kill_line_from_beginning (vty);
- break;
- case CONTROL('W'):
- vty_backward_kill_word (vty);
- break;
- case CONTROL('Z'):
- vty_end_config (vty);
- break;
- case '\n':
- case '\r':
- vty_out (vty, "%s", VTY_NEWLINE);
- vty_execute (vty);
- break;
- case '\t':
- vty_complete_command (vty);
- break;
- case '?':
- if (vty->node == AUTH_NODE || vty->node == AUTH_ENABLE_NODE)
- vty_self_insert (vty, buf[i]);
- else
- vty_describe_command (vty);
- break;
- case '\033':
- if (i + 1 < nbytes && buf[i + 1] == '[')
- {
- vty->escape = VTY_ESCAPE;
- i++;
- }
- else
- vty->escape = VTY_PRE_ESCAPE;
- break;
- default:
- if (buf[i] > 31 && buf[i] < 127)
- vty_self_insert (vty, buf[i]);
- break;
- }
+ {
+ case CONTROL('A'):
+ vty_beginning_of_line (vty);
+ break;
+ case CONTROL('B'):
+ vty_backward_char (vty);
+ break;
+ case CONTROL('C'):
+ vty_stop_input (vty);
+ break;
+ case CONTROL('D'):
+ vty_delete_char (vty);
+ break;
+ case CONTROL('E'):
+ vty_end_of_line (vty);
+ break;
+ case CONTROL('F'):
+ vty_forward_char (vty);
+ break;
+ case CONTROL('H'):
+ case 0x7f:
+ vty_delete_backward_char (vty);
+ break;
+ case CONTROL('K'):
+ vty_kill_line (vty);
+ break;
+ case CONTROL('N'):
+ vty_next_line (vty);
+ break;
+ case CONTROL('P'):
+ vty_previous_line (vty);
+ break;
+ case CONTROL('T'):
+ vty_transpose_chars (vty);
+ break;
+ case CONTROL('U'):
+ vty_kill_line_from_beginning (vty);
+ break;
+ case CONTROL('W'):
+ vty_backward_kill_word (vty);
+ break;
+ case CONTROL('Z'):
+ vty_end_config (vty);
+ break;
+ case '\n':
+ case '\r':
+ vty_out (vty, "%s", VTY_NEWLINE);
+ vty_execute (vty);
+ break;
+ case '\t':
+ vty_complete_command (vty);
+ break;
+ case '?':
+ if (vty->node == AUTH_NODE || vty->node == AUTH_ENABLE_NODE)
+ vty_self_insert (vty, buf[i]);
+ else
+ vty_describe_command (vty);
+ break;
+ case '\033':
+ if (i + 1 < nbytes && buf[i + 1] == '[')
+ {
+ vty->escape = VTY_ESCAPE;
+ i++;
+ }
+ else
+ vty->escape = VTY_PRE_ESCAPE;
+ break;
+ default:
+ if (buf[i] > 31 && buf[i] < 127)
+ vty_self_insert (vty, buf[i]);
+ break;
+ }
}
/* Check status. */
@@ -1630,36 +1628,36 @@ vty_flush (struct thread *thread)
flushrc = buffer_flush_available(vty->obuf, vty_sock);
else if (vty->status == VTY_MORELINE)
flushrc = buffer_flush_window(vty->obuf, vty_sock, vty->width,
- 1, erase, 0);
+ 1, erase, 0);
else
flushrc = buffer_flush_window(vty->obuf, vty_sock, vty->width,
- vty->lines >= 0 ? vty->lines :
- vty->height,
- erase, 0);
+ vty->lines >= 0 ? vty->lines :
+ vty->height,
+ erase, 0);
switch (flushrc)
{
case BUFFER_ERROR:
vty->monitor = 0; /* disable monitoring to avoid infinite recursion */
zlog_warn("buffer_flush failed on vty client fd %d, closing",
- vty->fd);
+ vty->fd);
buffer_reset(vty->obuf);
vty_close(vty);
return 0;
case BUFFER_EMPTY:
if (vty->status == VTY_CLOSE)
- vty_close (vty);
+ vty_close (vty);
else
- {
- vty->status = VTY_NORMAL;
- if (vty->lines == 0)
- vty_event (VTY_READ, vty_sock, vty);
- }
+ {
+ vty->status = VTY_NORMAL;
+ if (vty->lines == 0)
+ vty_event (VTY_READ, vty_sock, vty);
+ }
break;
case BUFFER_PENDING:
/* There is more data waiting to be written. */
vty->status = VTY_MORE;
if (vty->lines == 0)
- vty_event (VTY_WRITE, vty_sock, vty);
+ vty_event (VTY_WRITE, vty_sock, vty);
break;
}
@@ -1712,9 +1710,9 @@ vty_create (int vty_sock, union sockunion *su)
if (no_password_check)
{
if (host.advanced)
- vty->node = ENABLE_NODE;
+ vty->node = ENABLE_NODE;
else
- vty->node = VIEW_NODE;
+ vty->node = VIEW_NODE;
}
if (host.lines >= 0)
vty->lines = host.lines;
@@ -1723,12 +1721,12 @@ vty_create (int vty_sock, union sockunion *su)
{
/* Vty is not available if password isn't set. */
if (host.password == NULL && host.password_encrypt == NULL)
- {
- vty_out (vty, "Vty password is not set.%s", VTY_NEWLINE);
- vty->status = VTY_CLOSE;
- vty_close (vty);
- return NULL;
- }
+ {
+ vty_out (vty, "Vty password is not set.%s", VTY_NEWLINE);
+ vty->status = VTY_CLOSE;
+ vty_close (vty);
+ return NULL;
+ }
}
/* Say hello to the world. */
@@ -1848,17 +1846,17 @@ vty_accept (struct thread *thread)
if (p.family == AF_INET && vty_accesslist_name)
{
if ((acl = access_list_lookup (AFI_IP, vty_accesslist_name)) &&
- (access_list_apply (acl, &p) == FILTER_DENY))
- {
- zlog (NULL, LOG_INFO, "Vty connection refused from %s",
- sockunion2str (&su, buf, SU_ADDRSTRLEN));
- close (vty_sock);
-
- /* continue accepting connections */
- vty_event (VTY_SERV, accept_sock, NULL);
-
- return 0;
- }
+ (access_list_apply (acl, &p) == FILTER_DENY))
+ {
+ zlog (NULL, LOG_INFO, "Vty connection refused from %s",
+ sockunion2str (&su, buf, SU_ADDRSTRLEN));
+ close (vty_sock);
+
+ /* continue accepting connections */
+ vty_event (VTY_SERV, accept_sock, NULL);
+
+ return 0;
+ }
}
#ifdef HAVE_IPV6
@@ -1866,29 +1864,29 @@ vty_accept (struct thread *thread)
if (p.family == AF_INET6 && vty_ipv6_accesslist_name)
{
if ((acl = access_list_lookup (AFI_IP6, vty_ipv6_accesslist_name)) &&
- (access_list_apply (acl, &p) == FILTER_DENY))
- {
- zlog (NULL, LOG_INFO, "Vty connection refused from %s",
- sockunion2str (&su, buf, SU_ADDRSTRLEN));
- close (vty_sock);
-
- /* continue accepting connections */
- vty_event (VTY_SERV, accept_sock, NULL);
-
- return 0;
- }
+ (access_list_apply (acl, &p) == FILTER_DENY))
+ {
+ zlog (NULL, LOG_INFO, "Vty connection refused from %s",
+ sockunion2str (&su, buf, SU_ADDRSTRLEN));
+ close (vty_sock);
+
+ /* continue accepting connections */
+ vty_event (VTY_SERV, accept_sock, NULL);
+
+ return 0;
+ }
}
#endif /* HAVE_IPV6 */
-
+
on = 1;
- ret = setsockopt (vty_sock, IPPROTO_TCP, TCP_NODELAY,
- (char *) &on, sizeof (on));
+ ret = setsockopt (vty_sock, IPPROTO_TCP, TCP_NODELAY,
+ (char *) &on, sizeof (on));
if (ret < 0)
- zlog (NULL, LOG_INFO, "can't set sockopt to vty_sock : %s",
- safe_strerror (errno));
+ zlog (NULL, LOG_INFO, "can't set sockopt to vty_sock : %s",
+ safe_strerror (errno));
zlog (NULL, LOG_INFO, "Vty connection from %s",
- sockunion2str (&su, buf, SU_ADDRSTRLEN));
+ sockunion2str (&su, buf, SU_ADDRSTRLEN));
vty_create (vty_sock, &su);
@@ -1927,14 +1925,14 @@ vty_serv_sock_addrinfo (const char *hostname, unsigned short port)
{
if (ainfo->ai_family != AF_INET
#ifdef HAVE_IPV6
- && ainfo->ai_family != AF_INET6
+ && ainfo->ai_family != AF_INET6
#endif /* HAVE_IPV6 */
- )
- continue;
+ )
+ continue;
sock = socket (ainfo->ai_family, ainfo->ai_socktype, ainfo->ai_protocol);
if (sock < 0)
- continue;
+ continue;
sockopt_v6only (ainfo->ai_family, sock);
sockopt_reuseaddr (sock);
@@ -1942,17 +1940,17 @@ vty_serv_sock_addrinfo (const char *hostname, unsigned short port)
ret = bind (sock, ainfo->ai_addr, ainfo->ai_addrlen);
if (ret < 0)
- {
- close (sock); /* Avoid sd leak. */
- continue;
- }
+ {
+ close (sock); /* Avoid sd leak. */
+ continue;
+ }
ret = listen (sock, 3);
- if (ret < 0)
- {
- close (sock); /* Avoid sd leak. */
- continue;
- }
+ if (ret < 0)
+ {
+ close (sock); /* Avoid sd leak. */
+ continue;
+ }
vty_event (VTY_SERV, sock, NULL);
}
@@ -1983,7 +1981,7 @@ vty_serv_sock_family (const char* addr, unsigned short port, int family)
case AF_INET6:
naddr=&su.sin6.sin6_addr;
break;
-#endif
+#endif
}
if(naddr)
@@ -1991,11 +1989,11 @@ vty_serv_sock_family (const char* addr, unsigned short port, int family)
{
case -1:
zlog_err("bad address %s",addr);
- naddr=NULL;
- break;
+ naddr=NULL;
+ break;
case 0:
zlog_err("error translating address %s: %s",addr,safe_strerror(errno));
- naddr=NULL;
+ naddr=NULL;
}
/* Make new socket. */
@@ -2012,16 +2010,16 @@ vty_serv_sock_family (const char* addr, unsigned short port, int family)
if (ret < 0)
{
zlog_warn("can't bind socket");
- close (accept_sock); /* Avoid sd leak. */
+ close (accept_sock); /* Avoid sd leak. */
return;
}
/* Listen socket under queue 3. */
ret = listen (accept_sock, 3);
- if (ret < 0)
+ if (ret < 0)
{
zlog (NULL, LOG_WARNING, "can't listen socket");
- close (accept_sock); /* Avoid sd leak. */
+ close (accept_sock); /* Avoid sd leak. */
return;
}
@@ -2043,7 +2041,7 @@ vty_serv_un (const char *path)
struct sockaddr_un serv;
mode_t old_mask;
struct zprivs_ids_t ids;
-
+
/* First of all, unlink existing socket */
unlink (path);
@@ -2072,7 +2070,7 @@ vty_serv_un (const char *path)
if (ret < 0)
{
zlog_err("Cannot bind path %s: %s", path, safe_strerror(errno));
- close (sock); /* Avoid sd leak. */
+ close (sock); /* Avoid sd leak. */
return;
}
@@ -2080,14 +2078,14 @@ vty_serv_un (const char *path)
if (ret < 0)
{
zlog_err("listen(fd %d) failed: %s", sock, safe_strerror(errno));
- close (sock); /* Avoid sd leak. */
+ close (sock); /* Avoid sd leak. */
return;
}
umask (old_mask);
zprivs_get_ids(&ids);
-
+
if (ids.gid_vty > 0)
{
/* set group of socket */
@@ -2111,7 +2109,7 @@ vtysh_accept (struct thread *thread)
int client_len;
struct sockaddr_un client;
struct vty *vty;
-
+
accept_sock = THREAD_FD (thread);
vty_event (VTYSH_SERV, accept_sock, NULL);
@@ -2120,7 +2118,7 @@ vtysh_accept (struct thread *thread)
client_len = sizeof (struct sockaddr_un);
sock = accept (accept_sock, (struct sockaddr *) &client,
- (socklen_t *) &client_len);
+ (socklen_t *) &client_len);
if (sock < 0)
{
@@ -2135,7 +2133,7 @@ vtysh_accept (struct thread *thread)
close (sock);
return -1;
}
-
+
#ifdef VTYSH_DEBUG
printf ("VTY shell accept\n");
#endif /* VTYSH_DEBUG */
@@ -2190,16 +2188,16 @@ vtysh_read (struct thread *thread)
if ((nbytes = read (sock, buf, VTY_READ_BUFSIZ)) <= 0)
{
if (nbytes < 0)
- {
- if (ERRNO_IO_RETRY(errno))
- {
- vty_event (VTYSH_READ, sock, vty);
- return 0;
- }
- vty->monitor = 0; /* disable monitoring to avoid infinite recursion */
- zlog_warn("%s: read failed on vtysh client fd %d, closing: %s",
- __func__, sock, safe_strerror(errno));
- }
+ {
+ if (ERRNO_IO_RETRY(errno))
+ {
+ vty_event (VTYSH_READ, sock, vty);
+ return 0;
+ }
+ vty->monitor = 0; /* disable monitoring to avoid infinite recursion */
+ zlog_warn("%s: read failed on vtysh client fd %d, closing: %s",
+ __func__, sock, safe_strerror(errno));
+ }
buffer_reset(vty->obuf);
vty_close (vty);
#ifdef VTYSH_DEBUG
@@ -2217,25 +2215,25 @@ vtysh_read (struct thread *thread)
vty_ensure(vty, vty->length+1);
vty->buf[vty->length++] = *p;
if (*p == '\0')
- {
- /* Pass this line to parser. */
- ret = vty_execute (vty);
- /* Note that vty_execute clears the command buffer and resets
- vty->length to 0. */
+ {
+ /* Pass this line to parser. */
+ ret = vty_execute (vty);
+ /* Note that vty_execute clears the command buffer and resets
+ vty->length to 0. */
- /* Return result. */
+ /* Return result. */
#ifdef VTYSH_DEBUG
- printf ("result: %d\n", ret);
- printf ("vtysh node: %d\n", vty->node);
+ printf ("result: %d\n", ret);
+ printf ("vtysh node: %d\n", vty->node);
#endif /* VTYSH_DEBUG */
- header[3] = ret;
- buffer_put(vty->obuf, header, 4);
+ header[3] = ret;
+ buffer_put(vty->obuf, header, 4);
- if (!vty->t_write && (vtysh_flush(vty) < 0))
- /* Try to flush results; exit if a write error occurs. */
- return 0;
- }
+ if (!vty->t_write && (vtysh_flush(vty) < 0))
+ /* Try to flush results; exit if a write error occurs. */
+ return 0;
+ }
}
vty_event (VTYSH_READ, sock, vty);
@@ -2364,26 +2362,31 @@ vty_read_file (FILE *confp)
vty->fd = STDIN_FILENO;
vty->type = VTY_FILE;
vty->node = CONFIG_NODE;
-
+
/* Execute configuration file */
ret = config_from_file (vty, confp, &line_num);
/* Flush any previous errors before printing messages below */
buffer_flush_all (vty->obuf, vty->fd);
- if ( !((ret == CMD_SUCCESS) || (ret == CMD_ERR_NOTHING_TODO)) )
+ if ( !((ret == CMD_SUCCESS) || (ret == CMD_ERR_NOTHING_TODO)) )
{
+ const char *message = NULL;
switch (ret)
{
case CMD_ERR_AMBIGUOUS:
- fprintf (stderr, "*** Error reading config: Ambiguous command.\n");
+ message = "*** Error reading config: Ambiguous command.";
break;
case CMD_ERR_NO_MATCH:
- fprintf (stderr, "*** Error reading config: There is no such command.\n");
+ message = "*** Error reading config: There is no such command.";
break;
}
- fprintf (stderr, "*** Error occured processing line %u, below:\n%s\n",
- line_num, vty->error_buf);
+ fprintf (stderr, "%s\n", message);
+ zlog_err ("%s", message);
+ fprintf (stderr, "*** Error occurred processing line %u, below:\n%s\n",
+ line_num, vty->error_buf);
+ zlog_err ("*** Error occurred processing line %u, below:\n%s",
+ line_num, vty->error_buf);
}
vty_close (vty);
@@ -2398,7 +2401,7 @@ vty_use_backup_config (char *fullpath)
int tmp, sav;
int c;
char buffer[512];
-
+
fullpath_sav = malloc (strlen (fullpath) + strlen (CONF_BACKUP_EXT) + 1);
strcpy (fullpath_sav, fullpath);
strcat (fullpath_sav, CONF_BACKUP_EXT);
@@ -2410,7 +2413,7 @@ vty_use_backup_config (char *fullpath)
fullpath_tmp = malloc (strlen (fullpath) + 8);
sprintf (fullpath_tmp, "%s.XXXXXX", fullpath);
-
+
/* Open file to configuration write. */
tmp = mkstemp (fullpath_tmp);
if (tmp < 0)
@@ -2428,21 +2431,21 @@ vty_use_backup_config (char *fullpath)
free (fullpath_tmp);
return NULL;
}
-
+
while((c = read (sav, buffer, 512)) > 0)
{
if (write (tmp, buffer, c) <= 0)
- {
- free (fullpath_sav);
- free (fullpath_tmp);
- close (sav);
- close (tmp);
- return NULL;
- }
+ {
+ free (fullpath_sav);
+ free (fullpath_tmp);
+ close (sav);
+ close (tmp);
+ return NULL;
+ }
}
close (sav);
close (tmp);
-
+
if (chmod(fullpath_tmp, CONFIGFILE_MASK) != 0)
{
unlink (fullpath_tmp);
@@ -2450,12 +2453,12 @@ vty_use_backup_config (char *fullpath)
free (fullpath_tmp);
return NULL;
}
-
+
if (link (fullpath_tmp, fullpath) == 0)
ret = fopen (fullpath, "r");
unlink (fullpath_tmp);
-
+
free (fullpath_sav);
free (fullpath_tmp);
return ret;
@@ -2477,12 +2480,12 @@ vty_read_config (char *config_file,
if (! IS_DIRECTORY_SEP (config_file[0]))
{
if (getcwd (cwd, MAXPATHLEN) == NULL)
- {
- fprintf (stderr, "Failure to determine Current Working Directory %d!\n", errno);
- exit (1);
- }
- tmp = XMALLOC (MTYPE_TMP,
- strlen (cwd) + strlen (config_file) + 2);
+ {
+ fprintf (stderr, "Failure to determine Current Working Directory %d!\n", errno);
+ exit (1);
+ }
+ tmp = XMALLOC (MTYPE_TMP,
+ strlen (cwd) + strlen (config_file) + 2);
sprintf (tmp, "%s/%s", cwd, config_file);
fullpath = tmp;
}
@@ -2495,14 +2498,14 @@ vty_read_config (char *config_file,
{
fprintf (stderr, "%s: failed to open configuration file %s: %s\n",
__func__, fullpath, safe_strerror (errno));
-
+
confp = vty_use_backup_config (fullpath);
if (confp)
fprintf (stderr, "WARNING: using backup configuration file!\n");
else
{
- fprintf (stderr, "can't open configuration file [%s]\n",
- config_file);
+ fprintf (stderr, "can't open configuration file [%s]\n",
+ config_file);
exit(1);
}
}
@@ -2534,7 +2537,7 @@ vty_read_config (char *config_file,
{
ret = stat (integrate_default, &conf_stat);
if (ret >= 0)
- goto tmp_free_and_out;
+ goto tmp_free_and_out;
}
#endif /* VTYSH */
confp = fopen (config_default_dir, "r");
@@ -2542,7 +2545,7 @@ vty_read_config (char *config_file,
{
fprintf (stderr, "%s: failed to open configuration file %s: %s\n",
__func__, config_default_dir, safe_strerror (errno));
-
+
confp = vty_use_backup_config (config_default_dir);
if (confp)
{
@@ -2552,10 +2555,10 @@ vty_read_config (char *config_file,
else
{
fprintf (stderr, "can't open configuration file [%s]\n",
- config_default_dir);
- goto tmp_free_and_out;
+ config_default_dir);
+ goto tmp_free_and_out;
}
- }
+ }
else
fullpath = config_default_dir;
}
@@ -2574,23 +2577,23 @@ tmp_free_and_out:
/* Small utility function which output log to the VTY. */
void
vty_log (const char *level, const char *proto_str,
- const char *format, struct timestamp_control *ctl, va_list va)
+ const char *format, struct timestamp_control *ctl, va_list va)
{
unsigned int i;
struct vty *vty;
-
+
if (!vtyvec)
return;
for (i = 0; i < vector_active (vtyvec); i++)
if ((vty = vector_slot (vtyvec, i)) != NULL)
if (vty->monitor)
- {
- va_list ac;
- va_copy(ac, va);
- vty_log_out (vty, level, proto_str, format, ctl, ac);
- va_end(ac);
- }
+ {
+ va_list ac;
+ va_copy(ac, va);
+ vty_log_out (vty, level, proto_str, format, ctl, ac);
+ va_end(ac);
+ }
}
/* Async-signal-safe version of vty_log for fixed strings. */
@@ -2604,7 +2607,7 @@ vty_log_fixed (char *buf, size_t len)
/* vty may not have been initialised */
if (!vtyvec)
return;
-
+
iov[0].iov_base = buf;
iov[0].iov_len = len;
iov[1].iov_base = crlf;
@@ -2614,13 +2617,13 @@ vty_log_fixed (char *buf, size_t len)
{
struct vty *vty;
if (((vty = vector_slot (vtyvec, i)) != NULL) && vty->monitor)
- /* N.B. We don't care about the return code, since process is
- most likely just about to die anyway. */
- if (writev(vty->wfd, iov, 2) == -1)
- {
- fprintf(stderr, "Failure to writev: %d\n", errno);
- exit(-1);
- }
+ /* N.B. We don't care about the return code, since process is
+ most likely just about to die anyway. */
+ if (writev(vty->wfd, iov, 2) == -1)
+ {
+ fprintf(stderr, "Failure to writev: %d\n", errno);
+ exit(-1);
+ }
}
}
@@ -2687,28 +2690,28 @@ vty_event (enum event event, int sock, struct vty *vty)
/* Time out treatment. */
if (vty->v_timeout)
- {
- if (vty->t_timeout)
- thread_cancel (vty->t_timeout);
- vty->t_timeout =
- thread_add_timer (vty_master, vty_timeout, vty, vty->v_timeout);
- }
+ {
+ if (vty->t_timeout)
+ thread_cancel (vty->t_timeout);
+ vty->t_timeout =
+ thread_add_timer (vty_master, vty_timeout, vty, vty->v_timeout);
+ }
break;
case VTY_WRITE:
if (! vty->t_write)
- vty->t_write = thread_add_write (vty_master, vty_flush, vty, sock);
+ vty->t_write = thread_add_write (vty_master, vty_flush, vty, sock);
break;
case VTY_TIMEOUT_RESET:
if (vty->t_timeout)
- {
- thread_cancel (vty->t_timeout);
- vty->t_timeout = NULL;
- }
+ {
+ thread_cancel (vty->t_timeout);
+ vty->t_timeout = NULL;
+ }
if (vty->v_timeout)
- {
- vty->t_timeout =
- thread_add_timer (vty_master, vty_timeout, vty, vty->v_timeout);
- }
+ {
+ vty->t_timeout =
+ thread_add_timer (vty_master, vty_timeout, vty, vty->v_timeout);
+ }
break;
}
}
@@ -2724,8 +2727,8 @@ DEFUN (config_who,
for (i = 0; i < vector_active (vtyvec); i++)
if ((v = vector_slot (vtyvec, i)) != NULL)
vty_out (vty, "%svty[%d] connected from %s.%s",
- v->config ? "*" : " ",
- i, v->address, VTY_NEWLINE);
+ v->config ? "*" : " ",
+ i, v->address, VTY_NEWLINE);
return CMD_SUCCESS;
}
@@ -2766,21 +2769,24 @@ exec_timeout (struct vty *vty, const char *min_str, const char *sec_str)
DEFUN (exec_timeout_min,
exec_timeout_min_cmd,
- "exec-timeout <0-35791>",
+ "exec-timeout (0-35791)",
"Set timeout value\n"
"Timeout value in minutes\n")
{
- return exec_timeout (vty, argv[0], NULL);
+ int idx_number = 1;
+ return exec_timeout (vty, argv[idx_number]->arg, NULL);
}
DEFUN (exec_timeout_sec,
exec_timeout_sec_cmd,
- "exec-timeout <0-35791> <0-2147483>",
+ "exec-timeout (0-35791) (0-2147483)",
"Set the EXEC timeout\n"
"Timeout in minutes\n"
"Timeout in seconds\n")
{
- return exec_timeout (vty, argv[0], argv[1]);
+ int idx_number = 1;
+ int idx_number_2 = 2;
+ return exec_timeout (vty, argv[idx_number]->arg, argv[idx_number_2]->arg);
}
DEFUN (no_exec_timeout,
@@ -2799,10 +2805,11 @@ DEFUN (vty_access_class,
"Filter connections based on an IP access list\n"
"IP access list\n")
{
+ int idx_word = 1;
if (vty_accesslist_name)
XFREE(MTYPE_VTY, vty_accesslist_name);
- vty_accesslist_name = XSTRDUP(MTYPE_VTY, argv[0]);
+ vty_accesslist_name = XSTRDUP(MTYPE_VTY, argv[idx_word]->arg);
return CMD_SUCCESS;
}
@@ -2815,10 +2822,12 @@ DEFUN (no_vty_access_class,
"Filter connections based on an IP access list\n"
"IP access list\n")
{
- if (! vty_accesslist_name || (argc && strcmp(vty_accesslist_name, argv[0])))
+ int idx_word = 2;
+ const char *accesslist = (argc == 3) ? argv[idx_word]->arg : NULL;
+ if (! vty_accesslist_name || (argc == 3 && strcmp(vty_accesslist_name, accesslist)))
{
vty_out (vty, "Access-class is not currently applied to vty%s",
- VTY_NEWLINE);
+ VTY_NEWLINE);
return CMD_WARNING;
}
@@ -2838,10 +2847,11 @@ DEFUN (vty_ipv6_access_class,
"Filter connections based on an IP access list\n"
"IPv6 access list\n")
{
+ int idx_word = 2;
if (vty_ipv6_accesslist_name)
XFREE(MTYPE_VTY, vty_ipv6_accesslist_name);
- vty_ipv6_accesslist_name = XSTRDUP(MTYPE_VTY, argv[0]);
+ vty_ipv6_accesslist_name = XSTRDUP(MTYPE_VTY, argv[idx_word]->arg);
return CMD_SUCCESS;
}
@@ -2855,11 +2865,14 @@ DEFUN (no_vty_ipv6_access_class,
"Filter connections based on an IP access list\n"
"IPv6 access list\n")
{
+ int idx_word = 3;
+ const char *accesslist = (argc == 4) ? argv[idx_word]->arg : NULL;
+
if (! vty_ipv6_accesslist_name ||
- (argc && strcmp(vty_ipv6_accesslist_name, argv[0])))
+ (argc == 4 && strcmp(vty_ipv6_accesslist_name, accesslist)))
{
vty_out (vty, "IPv6 access-class is not currently applied to vty%s",
- VTY_NEWLINE);
+ VTY_NEWLINE);
return CMD_WARNING;
}
@@ -2933,12 +2946,16 @@ DEFUN (terminal_no_monitor,
return CMD_SUCCESS;
}
-ALIAS (terminal_no_monitor,
+DEFUN (no_terminal_monitor,
no_terminal_monitor_cmd,
"no terminal monitor",
NO_STR
"Set terminal line parameters\n"
"Copy debug output to the current terminal line\n")
+{
+ return terminal_no_monitor (self, vty, argc, argv);
+}
+
DEFUN (show_history,
show_history_cmd,
@@ -2951,13 +2968,13 @@ DEFUN (show_history,
for (index = vty->hindex + 1; index != vty->hindex;)
{
if (index == VTY_MAXHIST)
- {
- index = 0;
- continue;
- }
+ {
+ index = 0;
+ continue;
+ }
if (vty->hist[index] != NULL)
- vty_out (vty, " %s%s", vty->hist[index], VTY_NEWLINE);
+ vty_out (vty, " %s%s", vty->hist[index], VTY_NEWLINE);
index++;
}
@@ -2984,17 +3001,17 @@ vty_config_write (struct vty *vty)
if (vty_accesslist_name)
vty_out (vty, " access-class %s%s",
- vty_accesslist_name, VTY_NEWLINE);
+ vty_accesslist_name, VTY_NEWLINE);
if (vty_ipv6_accesslist_name)
vty_out (vty, " ipv6 access-class %s%s",
- vty_ipv6_accesslist_name, VTY_NEWLINE);
+ vty_ipv6_accesslist_name, VTY_NEWLINE);
/* exec-timeout */
if (vty_timeout_val != VTY_TIMEOUT_DEFAULT)
- vty_out (vty, " exec-timeout %ld %ld%s",
- vty_timeout_val / 60,
- vty_timeout_val % 60, VTY_NEWLINE);
+ vty_out (vty, " exec-timeout %ld %ld%s",
+ vty_timeout_val / 60,
+ vty_timeout_val % 60, VTY_NEWLINE);
/* login */
if (no_password_check)
@@ -3002,7 +3019,7 @@ vty_config_write (struct vty *vty)
if (do_log_commands)
vty_out (vty, "log commands%s", VTY_NEWLINE);
-
+
vty_out (vty, "!%s", VTY_NEWLINE);
return CMD_SUCCESS;
@@ -3026,16 +3043,16 @@ vty_reset ()
for (i = 0; i < vector_active (vtyvec); i++)
if ((vty = vector_slot (vtyvec, i)) != NULL)
{
- buffer_reset (vty->obuf);
- vty->status = VTY_CLOSE;
- vty_close (vty);
+ buffer_reset (vty->obuf);
+ vty->status = VTY_CLOSE;
+ vty_close (vty);
}
for (i = 0; i < vector_active (Vvty_serv_thread); i++)
if ((vty_serv_thread = vector_slot (Vvty_serv_thread, i)) != NULL)
{
- thread_cancel (vty_serv_thread);
- vector_slot (Vvty_serv_thread, i) = NULL;
+ thread_cancel (vty_serv_thread);
+ vector_slot (Vvty_serv_thread, i) = NULL;
close (i);
}
@@ -3070,15 +3087,15 @@ vty_save_cwd (void)
* Hence not worrying about it too much.
*/
if (!chdir (SYSCONFDIR))
- {
- fprintf(stderr, "Failure to chdir to %s, errno: %d\n", SYSCONFDIR, errno);
- exit(-1);
- }
+ {
+ fprintf(stderr, "Failure to chdir to %s, errno: %d\n", SYSCONFDIR, errno);
+ exit(-1);
+ }
if (getcwd (cwd, MAXPATHLEN) == NULL)
- {
- fprintf(stderr, "Failure to getcwd, errno: %d\n", errno);
- exit(-1);
- }
+ {
+ fprintf(stderr, "Failure to getcwd, errno: %d\n", errno);
+ exit(-1);
+ }
}
vty_cwd = XMALLOC (MTYPE_TMP, strlen (cwd) + 1);