2 * Zebra configuration command interface routine
3 * Copyright (C) 1997, 98 Kunihiro Ishiguro
5 * This file is part of GNU Zebra.
7 * GNU Zebra is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published
9 * by the Free Software Foundation; either version 2, or (at your
10 * option) any later version.
12 * GNU Zebra is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with GNU Zebra; see the file COPYING. If not, write to the
19 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
23 #ifndef _ZEBRA_COMMAND_H
24 #define _ZEBRA_COMMAND_H
28 #include "lib/route_types.h"
34 /* for test-commands.c */
37 /* Host configuration variable */
40 /* Host name of this router. */
43 /* Password for vty interface. */
45 char *password_encrypt
;
51 /* System wide terminal lines. */
57 /* config file name of this host */
60 /* Flags for services */
64 /* Banner configuration. */
69 /* There are some command levels which called from command node. */
72 AUTH_NODE
, /* Authentication mode of vty interface. */
73 VIEW_NODE
, /* View node. Default mode of vty interface. */
74 AUTH_ENABLE_NODE
, /* Authentication mode for change enable. */
75 ENABLE_NODE
, /* Enable node. */
76 CONFIG_NODE
, /* Config node. Default mode of config file. */
77 SERVICE_NODE
, /* Service node. */
78 DEBUG_NODE
, /* Debug node. */
79 VRF_DEBUG_NODE
, /* Vrf Debug node. */
80 DEBUG_VNC_NODE
, /* Debug VNC node. */
81 AAA_NODE
, /* AAA node. */
82 KEYCHAIN_NODE
, /* Key-chain node. */
83 KEYCHAIN_KEY_NODE
, /* Key-chain key node. */
84 NS_NODE
, /* Logical-Router node. */
85 VRF_NODE
, /* VRF mode node. */
86 INTERFACE_NODE
, /* Interface mode node. */
87 ZEBRA_NODE
, /* zebra connection node. */
88 TABLE_NODE
, /* rtm_table selection node. */
89 RIP_NODE
, /* RIP protocol mode node. */
90 RIPNG_NODE
, /* RIPng protocol mode node. */
91 BGP_NODE
, /* BGP protocol mode which includes BGP4+ */
92 BGP_VPNV4_NODE
, /* BGP MPLS-VPN PE exchange. */
93 BGP_VPNV6_NODE
, /* BGP MPLS-VPN PE exchange. */
94 BGP_IPV4_NODE
, /* BGP IPv4 unicast address family. */
95 BGP_IPV4M_NODE
, /* BGP IPv4 multicast address family. */
96 BGP_IPV6_NODE
, /* BGP IPv6 address family */
97 BGP_IPV6M_NODE
, /* BGP IPv6 multicast address family. */
98 BGP_ENCAP_NODE
, /* BGP ENCAP SAFI */
99 BGP_ENCAPV6_NODE
, /* BGP ENCAP SAFI */
100 BGP_VNC_DEFAULTS_NODE
, /* BGP VNC nve defaults */
101 BGP_VNC_NVE_GROUP_NODE
, /* BGP VNC nve group */
102 BGP_VNC_L2_GROUP_NODE
, /* BGP VNC L2 group */
103 RFP_DEFAULTS_NODE
, /* RFP defaults node */
104 OSPF_NODE
, /* OSPF protocol mode */
105 OSPF6_NODE
, /* OSPF protocol for IPv6 mode */
106 LDP_NODE
, /* LDP protocol mode */
107 LDP_IPV4_NODE
, /* LDP IPv4 address family */
108 LDP_IPV6_NODE
, /* LDP IPv6 address family */
109 LDP_IPV4_IFACE_NODE
, /* LDP IPv4 Interface */
110 LDP_IPV6_IFACE_NODE
, /* LDP IPv6 Interface */
111 LDP_L2VPN_NODE
, /* LDP L2VPN node */
112 LDP_PSEUDOWIRE_NODE
, /* LDP Pseudowire node */
113 ISIS_NODE
, /* ISIS protocol mode */
114 PIM_NODE
, /* PIM protocol mode */
115 MASC_NODE
, /* MASC for multicast. */
116 IRDP_NODE
, /* ICMP Router Discovery Protocol mode. */
117 IP_NODE
, /* Static ip route node. */
118 ACCESS_NODE
, /* Access list node. */
119 PREFIX_NODE
, /* Prefix list node. */
120 ACCESS_IPV6_NODE
, /* Access list node. */
121 PREFIX_IPV6_NODE
, /* Prefix list node. */
122 AS_LIST_NODE
, /* AS list node. */
123 COMMUNITY_LIST_NODE
, /* Community list node. */
124 RMAP_NODE
, /* Route map node. */
125 SMUX_NODE
, /* SNMP configuration node. */
126 DUMP_NODE
, /* Packet dump node. */
127 FORWARDING_NODE
, /* IP forwarding node. */
128 PROTOCOL_NODE
, /* protocol filtering node */
129 MPLS_NODE
, /* MPLS config node */
130 VTY_NODE
, /* Vty node. */
131 LINK_PARAMS_NODE
, /* Link-parameters node */
134 /* Node which has some commands and prompt string and configuration
135 function pointer . */
141 /* Prompt character at vty interface. */
144 /* Is this node's configuration goes to vtysh ? */
147 /* Node's configuration write function */
148 int (*func
) (struct vty
*);
150 /* Node's command graph */
151 struct graph
*cmdgraph
;
153 /* Vector of this node's command list. */
160 * The type determines what kind of data the token can match (in the
161 * matching use case) or hold (in the argv use case).
166 VARIABLE_TKN
, // almost anything
167 RANGE_TKN
, // integer range
168 IPV4_TKN
, // IPV4 addresses
169 IPV4_PREFIX_TKN
, // IPV4 network prefixes
170 IPV6_TKN
, // IPV6 prefixes
171 IPV6_PREFIX_TKN
, // IPV6 network prefixes
174 SELECTOR_TKN
, // marks beginning of selector
175 OPTION_TKN
, // marks beginning of option
176 NUL_TKN
, // dummy token
177 START_TKN
, // first token in line
178 END_TKN
, // last token in line
186 enum cmd_token_type type
; // token type
188 char *text
; // token text
189 char *desc
; // token description
191 long long min
, max
; // for ranges
193 char *arg
; // user input that matches this token
198 CMD_ATTR_DEPRECATED
= 1,
202 /* Structure of command element. */
205 const char *string
; /* Command specification by string. */
206 const char *doc
; /* Documentation of this command. */
207 int daemon
; /* Daemon to which this command belong. */
208 u_char attr
; /* Command attributes */
210 /* handler function for command */
211 int (*func
) (struct cmd_element
*, struct vty
*, int, struct cmd_token
*[]);
214 /* Return value of the commands. */
215 #define CMD_SUCCESS 0
216 #define CMD_WARNING 1
217 #define CMD_ERR_NO_MATCH 2
218 #define CMD_ERR_AMBIGUOUS 3
219 #define CMD_ERR_INCOMPLETE 4
220 #define CMD_ERR_EXEED_ARGC_MAX 5
221 #define CMD_ERR_NOTHING_TODO 6
222 #define CMD_COMPLETE_FULL_MATCH 7
223 #define CMD_COMPLETE_MATCH 8
224 #define CMD_COMPLETE_LIST_MATCH 9
225 #define CMD_SUCCESS_DAEMON 10
226 #define CMD_ERR_NO_FILE 11
228 /* Argc max counts. */
229 #define CMD_ARGC_MAX 25
231 /* Turn off these macros when uisng cpp with extract.pl */
232 #ifndef VTYSH_EXTRACT_PL
234 /* helper defines for end-user DEFUN* macros */
235 #define DEFUN_CMD_ELEMENT(funcname, cmdname, cmdstr, helpstr, attrs, dnum) \
236 struct cmd_element cmdname = \
245 #define DEFUN_CMD_FUNC_DECL(funcname) \
246 static int funcname (struct cmd_element *, struct vty *, int, struct cmd_token *[]);
248 #define DEFUN_CMD_FUNC_TEXT(funcname) \
249 static int funcname \
250 (struct cmd_element *self __attribute__ ((unused)), \
251 struct vty *vty __attribute__ ((unused)), \
252 int argc __attribute__ ((unused)), \
253 struct cmd_token *argv[] __attribute__ ((unused)) )
255 #define DEFUN(funcname, cmdname, cmdstr, helpstr) \
256 DEFUN_CMD_FUNC_DECL(funcname) \
257 DEFUN_CMD_ELEMENT(funcname, cmdname, cmdstr, helpstr, 0, 0) \
258 DEFUN_CMD_FUNC_TEXT(funcname)
260 #define DEFUN_ATTR(funcname, cmdname, cmdstr, helpstr, attr) \
261 DEFUN_CMD_FUNC_DECL(funcname) \
262 DEFUN_CMD_ELEMENT(funcname, cmdname, cmdstr, helpstr, attr, 0) \
263 DEFUN_CMD_FUNC_TEXT(funcname)
265 #define DEFUN_HIDDEN(funcname, cmdname, cmdstr, helpstr) \
266 DEFUN_ATTR (funcname, cmdname, cmdstr, helpstr, CMD_ATTR_HIDDEN)
268 #define DEFUN_DEPRECATED(funcname, cmdname, cmdstr, helpstr) \
269 DEFUN_ATTR (funcname, cmdname, cmdstr, helpstr, CMD_ATTR_DEPRECATED) \
271 /* DEFUN_NOSH for commands that vtysh should ignore */
272 #define DEFUN_NOSH(funcname, cmdname, cmdstr, helpstr) \
273 DEFUN(funcname, cmdname, cmdstr, helpstr)
275 /* DEFSH for vtysh. */
276 #define DEFSH(daemon, cmdname, cmdstr, helpstr) \
277 DEFUN_CMD_ELEMENT(NULL, cmdname, cmdstr, helpstr, 0, daemon) \
279 #define DEFSH_HIDDEN(daemon, cmdname, cmdstr, helpstr) \
280 DEFUN_CMD_ELEMENT(NULL, cmdname, cmdstr, helpstr, CMD_ATTR_HIDDEN, daemon) \
283 #define DEFUNSH(daemon, funcname, cmdname, cmdstr, helpstr) \
284 DEFUN_CMD_FUNC_DECL(funcname) \
285 DEFUN_CMD_ELEMENT(funcname, cmdname, cmdstr, helpstr, 0, daemon) \
286 DEFUN_CMD_FUNC_TEXT(funcname)
288 /* DEFUN + DEFSH with attributes */
289 #define DEFUNSH_ATTR(daemon, funcname, cmdname, cmdstr, helpstr, attr) \
290 DEFUN_CMD_FUNC_DECL(funcname) \
291 DEFUN_CMD_ELEMENT(funcname, cmdname, cmdstr, helpstr, attr, daemon) \
292 DEFUN_CMD_FUNC_TEXT(funcname)
294 #define DEFUNSH_HIDDEN(daemon, funcname, cmdname, cmdstr, helpstr) \
295 DEFUNSH_ATTR (daemon, funcname, cmdname, cmdstr, helpstr, CMD_ATTR_HIDDEN)
297 #define DEFUNSH_DEPRECATED(daemon, funcname, cmdname, cmdstr, helpstr) \
298 DEFUNSH_ATTR (daemon, funcname, cmdname, cmdstr, helpstr, CMD_ATTR_DEPRECATED)
300 /* ALIAS macro which define existing command's alias. */
301 #define ALIAS(funcname, cmdname, cmdstr, helpstr) \
302 DEFUN_CMD_ELEMENT(funcname, cmdname, cmdstr, helpstr, 0, 0)
304 #define ALIAS_ATTR(funcname, cmdname, cmdstr, helpstr, attr) \
305 DEFUN_CMD_ELEMENT(funcname, cmdname, cmdstr, helpstr, attr, 0)
307 #define ALIAS_HIDDEN(funcname, cmdname, cmdstr, helpstr) \
308 DEFUN_CMD_ELEMENT(funcname, cmdname, cmdstr, helpstr, CMD_ATTR_HIDDEN, 0)
310 #define ALIAS_DEPRECATED(funcname, cmdname, cmdstr, helpstr) \
311 DEFUN_CMD_ELEMENT(funcname, cmdname, cmdstr, helpstr, CMD_ATTR_DEPRECATED, 0)
313 #define ALIAS_SH(daemon, funcname, cmdname, cmdstr, helpstr) \
314 DEFUN_CMD_ELEMENT(funcname, cmdname, cmdstr, helpstr, 0, daemon)
316 #define ALIAS_SH_HIDDEN(daemon, funcname, cmdname, cmdstr, helpstr) \
317 DEFUN_CMD_ELEMENT(funcname, cmdname, cmdstr, helpstr, CMD_ATTR_HIDDEN, daemon)
319 #define ALIAS_SH_DEPRECATED(daemon, funcname, cmdname, cmdstr, helpstr) \
320 DEFUN_CMD_ELEMENT(funcname, cmdname, cmdstr, helpstr, CMD_ATTR_DEPRECATED, daemon)
322 #endif /* VTYSH_EXTRACT_PL */
327 * Sometimes #defines create maximum values that
328 * need to have strings created from them that
329 * allow the parser to match against them.
330 * These macros allow that.
332 #define CMD_CREATE_STR(s) CMD_CREATE_STR_HELPER(s)
333 #define CMD_CREATE_STR_HELPER(s) #s
335 /* Common descriptions. */
336 #define SHOW_STR "Show running system information\n"
337 #define IP_STR "IP information\n"
338 #define IPV6_STR "IPv6 information\n"
339 #define NO_STR "Negate a command or set its defaults\n"
340 #define REDIST_STR "Redistribute information from another routing protocol\n"
341 #define CLEAR_STR "Reset functions\n"
342 #define RIP_STR "RIP information\n"
343 #define BGP_STR "BGP information\n"
344 #define BGP_SOFT_STR "Soft reconfig inbound and outbound updates\n"
345 #define BGP_SOFT_IN_STR "Send route-refresh unless using 'soft-reconfiguration inbound'\n"
346 #define BGP_SOFT_OUT_STR "Resend all outbound updates\n"
347 #define BGP_SOFT_RSCLIENT_RIB_STR "Soft reconfig for rsclient RIB\n"
348 #define OSPF_STR "OSPF information\n"
349 #define NEIGHBOR_STR "Specify neighbor router\n"
350 #define DEBUG_STR "Debugging functions (see also 'undebug')\n"
351 #define UNDEBUG_STR "Disable debugging functions (see also 'debug')\n"
352 #define ROUTER_STR "Enable a routing process\n"
353 #define AS_STR "AS number\n"
354 #define MBGP_STR "MBGP information\n"
355 #define MATCH_STR "Match values from routing table\n"
356 #define SET_STR "Set values in destination routing protocol\n"
357 #define OUT_STR "Filter outgoing routing updates\n"
358 #define IN_STR "Filter incoming routing updates\n"
359 #define V4NOTATION_STR "specify by IPv4 address notation(e.g. 0.0.0.0)\n"
360 #define OSPF6_NUMBER_STR "Specify by number\n"
361 #define INTERFACE_STR "Interface infomation\n"
362 #define IFNAME_STR "Interface name(e.g. ep0)\n"
363 #define IP6_STR "IPv6 Information\n"
364 #define OSPF6_STR "Open Shortest Path First (OSPF) for IPv6\n"
365 #define OSPF6_ROUTER_STR "Enable a routing process\n"
366 #define OSPF6_INSTANCE_STR "(1-65535) Instance ID\n"
367 #define SECONDS_STR "(1-65535) Seconds\n"
368 #define ROUTE_STR "Routing Table\n"
369 #define PREFIX_LIST_STR "Build a prefix list\n"
370 #define OSPF6_DUMP_TYPE_LIST \
371 "<neighbor|interface|area|lsa|zebra|config|dbex|spf|route|lsdb|redistribute|hook|asbr|prefix|abr>"
372 #define ISIS_STR "IS-IS information\n"
373 #define AREA_TAG_STR "[area tag]\n"
374 #define COMMUNITY_AANN_STR "Community number where AA and NN are (0-65535)\n"
375 #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"
376 #define MPLS_TE_STR "MPLS-TE specific commands\n"
377 #define LINK_PARAMS_STR "Configure interface link parameters\n"
378 #define OSPF_RI_STR "OSPF Router Information specific commands\n"
379 #define PCE_STR "PCE Router Information specific commands\n"
380 #define MPLS_STR "MPLS information\n"
382 #define CONF_BACKUP_EXT ".sav"
384 /* IPv4 only machine should not accept IPv6 address for peer's IP
385 address. So we replace VTY command string like below. */
387 #define NEIGHBOR_ADDR_STR "Neighbor address\nIPv6 address\n"
388 #define NEIGHBOR_ADDR_STR2 "Neighbor address\nNeighbor IPv6 address\nInterface name or neighbor tag\n"
389 #define NEIGHBOR_ADDR_STR3 "Neighbor address\nIPv6 address\nInterface name\n"
391 #define NEIGHBOR_ADDR_STR "Neighbor address\n"
392 #define NEIGHBOR_ADDR_STR2 "Neighbor address\nNeighbor tag\n"
393 #endif /* HAVE_IPV6 */
395 /* Dynamic neighbor (listen range) configuration */
397 #define LISTEN_RANGE_ADDR_STR "Neighbor address\nNeighbor IPv6 address\n"
399 #define LISTEN_RANGE_ADDR_STR "Neighbor address\n"
400 #endif /* HAVE_IPV6 */
403 extern void install_node (struct cmd_node
*, int (*) (struct vty
*));
404 extern void install_default (enum node_type
);
405 extern void install_element (enum node_type
, struct cmd_element
*);
407 /* Concatenates argv[shift] through argv[argc-1] into a single NUL-terminated
408 string with a space between each element (allocated using
409 XMALLOC(MTYPE_TMP)). Returns NULL if shift >= argc. */
410 extern char *argv_concat (struct cmd_token
**argv
, int argc
, int shift
);
412 extern vector
cmd_make_strvec (const char *);
413 extern void cmd_free_strvec (vector
);
414 extern char *cmd_concat_strvec (vector
);
415 extern vector
cmd_describe_command (vector
, struct vty
*, int *status
);
416 extern char **cmd_complete_command (vector
, struct vty
*, int *status
);
417 extern char **cmd_complete_command_lib (vector
, struct vty
*, int *status
, int islib
);
418 extern const char *cmd_prompt (enum node_type
);
419 extern int command_config_read_one_line (struct vty
*vty
, struct cmd_element
**, int use_config_node
);
420 extern int config_from_file (struct vty
*, FILE *, unsigned int *line_num
);
421 extern enum node_type
node_parent (enum node_type
);
422 extern int cmd_execute_command (vector
, struct vty
*, struct cmd_element
**, int);
423 extern int cmd_execute_command_strict (vector
, struct vty
*, struct cmd_element
**);
424 extern void cmd_init (int);
425 extern void cmd_terminate (void);
427 /* memory management for cmd_element */
429 del_cmd_element(struct cmd_element
*);
431 copy_cmd_element(struct cmd_element
*cmd
);
433 /* memory management for cmd_token */
435 new_cmd_token (enum cmd_token_type
, char *, char *);
437 del_cmd_token (struct cmd_token
*);
439 copy_cmd_token (struct cmd_token
*);
441 /* Export typical functions. */
442 extern struct cmd_element config_end_cmd
;
443 extern struct cmd_element config_exit_cmd
;
444 extern struct cmd_element config_quit_cmd
;
445 extern struct cmd_element config_help_cmd
;
446 extern struct cmd_element config_list_cmd
;
447 extern char *host_config_file (void);
448 extern void host_config_set (const char *);
450 extern void print_version (const char *);
452 extern int cmd_banner_motd_file (const char *);
454 /* struct host global, ick */
455 extern struct host host
;
457 /* text for <cr> command */
458 #define CMD_CR_TEXT "<cr>"
460 #endif /* _ZEBRA_COMMAND_H */