diff options
Diffstat (limited to 'lib/command.h')
| -rw-r--r-- | lib/command.h | 112 |
1 files changed, 36 insertions, 76 deletions
diff --git a/lib/command.h b/lib/command.h index 55d7d30c48..d0c9f0eaf9 100644 --- a/lib/command.h +++ b/lib/command.h @@ -14,10 +14,9 @@ * 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. + * You should have received a copy of the GNU General Public License along + * with this program; see the file COPYING; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ #ifndef _ZEBRA_COMMAND_H @@ -29,9 +28,10 @@ #include "graph.h" #include "memory.h" #include "hash.h" +#include "command_graph.h" DECLARE_MTYPE(HOST) -DECLARE_MTYPE(CMD_ARG) +DECLARE_MTYPE(COMPLETION) /* for test-commands.c */ DECLARE_MTYPE(STRVEC) @@ -68,7 +68,7 @@ struct host { char *motdfile; }; -/* There are some command levels which called from command node. */ +/* List of CLI nodes. Please remember to update the name array in command.c. */ enum node_type { AUTH_NODE, /* Authentication mode of vty interface. */ VIEW_NODE, /* View node. Default mode of vty interface. */ @@ -89,13 +89,17 @@ enum node_type { TABLE_NODE, /* rtm_table selection node. */ RIP_NODE, /* RIP protocol mode node. */ RIPNG_NODE, /* RIPng protocol mode node. */ + BABEL_NODE, /* BABEL protocol mode node. */ + EIGRP_NODE, /* EIGRP 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_IPV4L_NODE, /* BGP IPv4 labeled unicast address family. */ BGP_IPV6_NODE, /* BGP IPv6 address family */ BGP_IPV6M_NODE, /* BGP IPv6 multicast address family. */ + BGP_IPV6L_NODE, /* BGP IPv6 labeled unicast address family. */ BGP_VRF_POLICY_NODE, /* BGP VRF policy */ BGP_VNC_DEFAULTS_NODE, /* BGP VNC nve defaults */ BGP_VNC_NVE_GROUP_NODE, /* BGP VNC nve group */ @@ -131,8 +135,13 @@ enum node_type { PW_NODE, /* Pseudowire config node */ VTY_NODE, /* Vty node. */ LINK_PARAMS_NODE, /* Link-parameters node */ + BGP_EVPN_VNI_NODE, /* BGP EVPN VNI */ + NODE_TYPE_MAX, /* maximum */ }; +extern vector cmdvec; +extern const char *node_names[]; + /* Node which has some commands and prompt string and configuration function pointer . */ struct cmd_node { @@ -158,65 +167,6 @@ struct cmd_node { struct hash *cmd_hash; }; -/** - * 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 { - 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 */ - FORK_TKN, // marks subgraph beginning - JOIN_TKN, // marks subgraph end - START_TKN, // first token in line - END_TKN, // last token in line - - SPECIAL_TKN = FORK_TKN, -}; - -/* Command attributes */ -enum { CMD_ATTR_NORMAL, - CMD_ATTR_DEPRECATED, - CMD_ATTR_HIDDEN, -}; - -/* Comamand token struct. */ -struct cmd_token { - enum cmd_token_type type; // token type - u_char attr; // token attributes - bool allowrepeat; // matcher allowed to match token repetively? - uint32_t refcnt; - - char *text; // token text - char *desc; // token description - long long min, max; // for ranges - char *arg; // user input that matches this token - - struct graph_node *forkjoin; // paired FORK/JOIN for JOIN/FORK -}; - -/* Structure of command element. */ -struct cmd_element { - 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 */ - - /* handler function for command */ - int (*func)(const struct cmd_element *, struct vty *, int, - struct cmd_token *[]); - - const char *name; /* symbol name for debugging */ -}; - /* Return value of the commands. */ #define CMD_SUCCESS 0 #define CMD_WARNING 1 @@ -231,6 +181,8 @@ struct cmd_element { #define CMD_SUCCESS_DAEMON 10 #define CMD_ERR_NO_FILE 11 #define CMD_SUSPEND 12 +#define CMD_WARNING_CONFIG_FAILED 13 +#define CMD_NOT_MY_INSTANCE 14 /* Argc max counts. */ #define CMD_ARGC_MAX 25 @@ -260,6 +212,10 @@ struct cmd_element { int argc __attribute__((unused)), \ struct cmd_token *argv[] __attribute__((unused))) +#define DEFPY(funcname, cmdname, cmdstr, helpstr) \ + DEFUN_CMD_ELEMENT(funcname, cmdname, cmdstr, helpstr, 0, 0) \ + funcdecl_##funcname + #define DEFUN(funcname, cmdname, cmdstr, helpstr) \ DEFUN_CMD_FUNC_DECL(funcname) \ DEFUN_CMD_ELEMENT(funcname, cmdname, cmdstr, helpstr, 0, 0) \ @@ -334,6 +290,9 @@ struct cmd_element { DEFUN_CMD_ELEMENT(funcname, cmdname, cmdstr, helpstr, \ CMD_ATTR_DEPRECATED, daemon) +#else /* VTYSH_EXTRACT_PL */ +#define DEFPY(funcname, cmdname, cmdstr, helpstr) \ + DEFUN(funcname, cmdname, cmdstr, helpstr) #endif /* VTYSH_EXTRACT_PL */ /* Some macroes */ @@ -346,6 +305,7 @@ struct cmd_element { */ #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" @@ -355,6 +315,7 @@ struct cmd_element { #define REDIST_STR "Redistribute information from another routing protocol\n" #define CLEAR_STR "Reset functions\n" #define RIP_STR "RIP information\n" +#define EIGRP_STR "EIGRP information\n" #define BGP_STR "BGP information\n" #define BGP_SOFT_STR "Soft reconfig inbound and outbound updates\n" #define BGP_SOFT_IN_STR "Send route-refresh unless using 'soft-reconfiguration inbound'\n" @@ -441,16 +402,7 @@ extern int cmd_hostname_set(const char *hostname); /* NOT safe for general use; call this only if DEV_BUILD! */ extern void grammar_sandbox_init(void); -/* memory management for cmd_token */ -extern struct cmd_token *new_cmd_token(enum cmd_token_type, u_char attr, - const char *text, const char *desc); -extern void del_cmd_token(struct cmd_token *); -extern struct cmd_token *copy_cmd_token(struct cmd_token *); - extern vector completions_to_vec(struct list *completions); -extern void cmd_merge_graphs(struct graph *old, struct graph *new, - int direction); -extern void command_parse_format(struct graph *graph, struct cmd_element *cmd); /* Export typical functions. */ extern const char *host_config_get(void); @@ -463,7 +415,15 @@ extern int cmd_banner_motd_file(const char *); /* struct host global, ick */ extern struct host host; -/* text for <cr> command */ -#define CMD_CR_TEXT "<cr>" +struct cmd_variable_handler { + const char *tokenname, *varname; + void (*completions)(vector out, struct cmd_token *token); +}; + +extern void cmd_variable_complete(struct cmd_token *token, const char *arg, + vector comps); +extern void +cmd_variable_handler_register(const struct cmd_variable_handler *cvh); +extern char *cmd_variable_comp2str(vector comps, unsigned short cols); #endif /* _ZEBRA_COMMAND_H */ |
