]> git.proxmox.com Git - mirror_frr.git/blame - lib/command.h
bgpd: Vestigialize `show ip bgp`, this time for real
[mirror_frr.git] / lib / command.h
CommitLineData
718e3744 1/*
2 * Zebra configuration command interface routine
3 * Copyright (C) 1997, 98 Kunihiro Ishiguro
4 *
5 * This file is part of GNU Zebra.
6 *
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.
d0bfb22c 11 *
718e3744 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.
16 *
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.
21 */
22
23#ifndef _ZEBRA_COMMAND_H
24#define _ZEBRA_COMMAND_H
25
26#include "vector.h"
27#include "vty.h"
9c42a6eb 28#include "lib/route_types.h"
d0bfb22c 29#include "graph.h"
4a1ab8e4 30#include "memory.h"
274f29b2 31#include "hash.h"
4a1ab8e4
DL
32
33DECLARE_MTYPE(HOST)
34
35/* for test-commands.c */
36DECLARE_MTYPE(STRVEC)
718e3744 37
38/* Host configuration variable */
39struct host
40{
41 /* Host name of this router. */
42 char *name;
43
44 /* Password for vty interface. */
45 char *password;
46 char *password_encrypt;
47
48 /* Enable password */
49 char *enable;
50 char *enable_encrypt;
51
52 /* System wide terminal lines. */
53 int lines;
54
55 /* Log filename. */
56 char *logfile;
57
718e3744 58 /* config file name of this host */
59 char *config;
60
61 /* Flags for services */
62 int advanced;
63 int encrypt;
64
65 /* Banner configuration. */
8c328f11 66 const char *motd;
3b0c5d9a 67 char *motdfile;
718e3744 68};
69
70/* There are some command levels which called from command node. */
d0bfb22c 71enum node_type
718e3744 72{
d0bfb22c 73 AUTH_NODE, /* Authentication mode of vty interface. */
d0bfb22c
QY
74 VIEW_NODE, /* View node. Default mode of vty interface. */
75 AUTH_ENABLE_NODE, /* Authentication mode for change enable. */
76 ENABLE_NODE, /* Enable node. */
77 CONFIG_NODE, /* Config node. Default mode of config file. */
78 SERVICE_NODE, /* Service node. */
79 DEBUG_NODE, /* Debug node. */
19dc275e 80 VRF_DEBUG_NODE, /* Vrf Debug node. */
65efcfce 81 DEBUG_VNC_NODE, /* Debug VNC node. */
d0bfb22c
QY
82 AAA_NODE, /* AAA node. */
83 KEYCHAIN_NODE, /* Key-chain node. */
84 KEYCHAIN_KEY_NODE, /* Key-chain key node. */
844ec28c 85 NS_NODE, /* Logical-Router node. */
d0bfb22c
QY
86 VRF_NODE, /* VRF mode node. */
87 INTERFACE_NODE, /* Interface mode node. */
88 ZEBRA_NODE, /* zebra connection node. */
89 TABLE_NODE, /* rtm_table selection node. */
90 RIP_NODE, /* RIP protocol mode node. */
91 RIPNG_NODE, /* RIPng protocol mode node. */
92 BGP_NODE, /* BGP protocol mode which includes BGP4+ */
93 BGP_VPNV4_NODE, /* BGP MPLS-VPN PE exchange. */
94 BGP_VPNV6_NODE, /* BGP MPLS-VPN PE exchange. */
95 BGP_IPV4_NODE, /* BGP IPv4 unicast address family. */
96 BGP_IPV4M_NODE, /* BGP IPv4 multicast address family. */
97 BGP_IPV6_NODE, /* BGP IPv6 address family */
98 BGP_IPV6M_NODE, /* BGP IPv6 multicast address family. */
99 BGP_ENCAP_NODE, /* BGP ENCAP SAFI */
100 BGP_ENCAPV6_NODE, /* BGP ENCAP SAFI */
65efcfce
LB
101 BGP_VNC_DEFAULTS_NODE, /* BGP VNC nve defaults */
102 BGP_VNC_NVE_GROUP_NODE, /* BGP VNC nve group */
103 BGP_VNC_L2_GROUP_NODE, /* BGP VNC L2 group */
104 RFP_DEFAULTS_NODE, /* RFP defaults node */
d0bfb22c
QY
105 OSPF_NODE, /* OSPF protocol mode */
106 OSPF6_NODE, /* OSPF protocol for IPv6 mode */
eac6e3f0
RW
107 LDP_NODE, /* LDP protocol mode */
108 LDP_IPV4_NODE, /* LDP IPv4 address family */
109 LDP_IPV6_NODE, /* LDP IPv6 address family */
110 LDP_IPV4_IFACE_NODE, /* LDP IPv4 Interface */
111 LDP_IPV6_IFACE_NODE, /* LDP IPv6 Interface */
112 LDP_L2VPN_NODE, /* LDP L2VPN node */
113 LDP_PSEUDOWIRE_NODE, /* LDP Pseudowire node */
d0bfb22c
QY
114 ISIS_NODE, /* ISIS protocol mode */
115 PIM_NODE, /* PIM protocol mode */
116 MASC_NODE, /* MASC for multicast. */
117 IRDP_NODE, /* ICMP Router Discovery Protocol mode. */
118 IP_NODE, /* Static ip route node. */
119 ACCESS_NODE, /* Access list node. */
120 PREFIX_NODE, /* Prefix list node. */
121 ACCESS_IPV6_NODE, /* Access list node. */
122 PREFIX_IPV6_NODE, /* Prefix list node. */
123 AS_LIST_NODE, /* AS list node. */
124 COMMUNITY_LIST_NODE, /* Community list node. */
125 RMAP_NODE, /* Route map node. */
126 SMUX_NODE, /* SNMP configuration node. */
127 DUMP_NODE, /* Packet dump node. */
128 FORWARDING_NODE, /* IP forwarding node. */
7514fb77 129 PROTOCOL_NODE, /* protocol filtering node */
7758e3f3 130 MPLS_NODE, /* MPLS config node */
d0bfb22c 131 VTY_NODE, /* Vty node. */
844ec28c 132 LINK_PARAMS_NODE, /* Link-parameters node */
718e3744 133};
134
135/* Node which has some commands and prompt string and configuration
136 function pointer . */
d0bfb22c 137struct cmd_node
718e3744 138{
139 /* Node index. */
d0bfb22c 140 enum node_type node;
718e3744 141
142 /* Prompt character at vty interface. */
d0bfb22c 143 const char *prompt;
718e3744 144
145 /* Is this node's configuration goes to vtysh ? */
146 int vtysh;
d0bfb22c 147
718e3744 148 /* Node's configuration write function */
149 int (*func) (struct vty *);
150
d0bfb22c
QY
151 /* Node's command graph */
152 struct graph *cmdgraph;
153
718e3744 154 /* Vector of this node's command list. */
d0bfb22c 155 vector cmd_vector;
274f29b2
PJ
156
157 /* Hashed index of command node list, for de-dupping primarily */
158 struct hash *cmd_hash;
718e3744 159};
160
d0bfb22c
QY
161/**
162 * Types for tokens.
163 *
164 * The type determines what kind of data the token can match (in the
165 * matching use case) or hold (in the argv use case).
166 */
167enum cmd_token_type
406d6716 168{
d0bfb22c 169 WORD_TKN, // words
d0bfb22c
QY
170 VARIABLE_TKN, // almost anything
171 RANGE_TKN, // integer range
172 IPV4_TKN, // IPV4 addresses
173 IPV4_PREFIX_TKN, // IPV4 network prefixes
174 IPV6_TKN, // IPV6 prefixes
175 IPV6_PREFIX_TKN, // IPV6 network prefixes
176
177 /* plumbing types */
178 SELECTOR_TKN, // marks beginning of selector
179 OPTION_TKN, // marks beginning of option
180 NUL_TKN, // dummy token
181 START_TKN, // first token in line
182 END_TKN, // last token in line
406d6716 183};
184
d0bfb22c
QY
185/**
186 * Token struct.
187 */
188struct cmd_token
718e3744 189{
d0bfb22c 190 enum cmd_token_type type; // token type
718e3744 191
d0bfb22c
QY
192 char *text; // token text
193 char *desc; // token description
cd40b329 194
d0bfb22c
QY
195 long long min, max; // for ranges
196
197 char *arg; // user input that matches this token
cd40b329
CF
198};
199
d0bfb22c 200enum
c117e027 201{
d0bfb22c
QY
202 CMD_ATTR_DEPRECATED = 1,
203 CMD_ATTR_HIDDEN,
c117e027
DL
204};
205
d0bfb22c
QY
206/* Structure of command element. */
207struct cmd_element
718e3744 208{
d0bfb22c
QY
209 const char *string; /* Command specification by string. */
210 const char *doc; /* Documentation of this command. */
211 int daemon; /* Daemon to which this command belong. */
212 u_char attr; /* Command attributes */
cd40b329 213
d0bfb22c
QY
214 /* handler function for command */
215 int (*func) (struct cmd_element *, struct vty *, int, struct cmd_token *[]);
718e3744 216};
217
218/* Return value of the commands. */
219#define CMD_SUCCESS 0
220#define CMD_WARNING 1
221#define CMD_ERR_NO_MATCH 2
222#define CMD_ERR_AMBIGUOUS 3
223#define CMD_ERR_INCOMPLETE 4
224#define CMD_ERR_EXEED_ARGC_MAX 5
225#define CMD_ERR_NOTHING_TODO 6
226#define CMD_COMPLETE_FULL_MATCH 7
227#define CMD_COMPLETE_MATCH 8
228#define CMD_COMPLETE_LIST_MATCH 9
229#define CMD_SUCCESS_DAEMON 10
1db63918 230#define CMD_ERR_NO_FILE 11
718e3744 231
232/* Argc max counts. */
233#define CMD_ARGC_MAX 25
234
235/* Turn off these macros when uisng cpp with extract.pl */
d0bfb22c 236#ifndef VTYSH_EXTRACT_PL
718e3744 237
406d6716 238/* helper defines for end-user DEFUN* macros */
239#define DEFUN_CMD_ELEMENT(funcname, cmdname, cmdstr, helpstr, attrs, dnum) \
718e3744 240 struct cmd_element cmdname = \
241 { \
9035efaa 242 .string = cmdstr, \
243 .func = funcname, \
406d6716 244 .doc = helpstr, \
245 .attr = attrs, \
246 .daemon = dnum, \
247 };
248
249#define DEFUN_CMD_FUNC_DECL(funcname) \
d0bfb22c 250 static int funcname (struct cmd_element *, struct vty *, int, struct cmd_token *[]);
406d6716 251
252#define DEFUN_CMD_FUNC_TEXT(funcname) \
274a4a44 253 static int funcname \
6cf0cf0c
PJ
254 (struct cmd_element *self __attribute__ ((unused)), \
255 struct vty *vty __attribute__ ((unused)), \
256 int argc __attribute__ ((unused)), \
d0bfb22c 257 struct cmd_token *argv[] __attribute__ ((unused)) )
406d6716 258
406d6716 259#define DEFUN(funcname, cmdname, cmdstr, helpstr) \
260 DEFUN_CMD_FUNC_DECL(funcname) \
261 DEFUN_CMD_ELEMENT(funcname, cmdname, cmdstr, helpstr, 0, 0) \
262 DEFUN_CMD_FUNC_TEXT(funcname)
263
264#define DEFUN_ATTR(funcname, cmdname, cmdstr, helpstr, attr) \
265 DEFUN_CMD_FUNC_DECL(funcname) \
266 DEFUN_CMD_ELEMENT(funcname, cmdname, cmdstr, helpstr, attr, 0) \
267 DEFUN_CMD_FUNC_TEXT(funcname)
268
269#define DEFUN_HIDDEN(funcname, cmdname, cmdstr, helpstr) \
270 DEFUN_ATTR (funcname, cmdname, cmdstr, helpstr, CMD_ATTR_HIDDEN)
271
272#define DEFUN_DEPRECATED(funcname, cmdname, cmdstr, helpstr) \
2557aed1 273 DEFUN_ATTR (funcname, cmdname, cmdstr, helpstr, CMD_ATTR_DEPRECATED) \
718e3744 274
275/* DEFUN_NOSH for commands that vtysh should ignore */
276#define DEFUN_NOSH(funcname, cmdname, cmdstr, helpstr) \
277 DEFUN(funcname, cmdname, cmdstr, helpstr)
278
279/* DEFSH for vtysh. */
280#define DEFSH(daemon, cmdname, cmdstr, helpstr) \
406d6716 281 DEFUN_CMD_ELEMENT(NULL, cmdname, cmdstr, helpstr, 0, daemon) \
718e3744 282
abaaab4e
DW
283#define DEFSH_HIDDEN(daemon, cmdname, cmdstr, helpstr) \
284 DEFUN_CMD_ELEMENT(NULL, cmdname, cmdstr, helpstr, CMD_ATTR_HIDDEN, daemon) \
285
718e3744 286/* DEFUN + DEFSH */
287#define DEFUNSH(daemon, funcname, cmdname, cmdstr, helpstr) \
406d6716 288 DEFUN_CMD_FUNC_DECL(funcname) \
289 DEFUN_CMD_ELEMENT(funcname, cmdname, cmdstr, helpstr, 0, daemon) \
290 DEFUN_CMD_FUNC_TEXT(funcname)
718e3744 291
274a4a44 292/* DEFUN + DEFSH with attributes */
293#define DEFUNSH_ATTR(daemon, funcname, cmdname, cmdstr, helpstr, attr) \
294 DEFUN_CMD_FUNC_DECL(funcname) \
295 DEFUN_CMD_ELEMENT(funcname, cmdname, cmdstr, helpstr, attr, daemon) \
296 DEFUN_CMD_FUNC_TEXT(funcname)
297
298#define DEFUNSH_HIDDEN(daemon, funcname, cmdname, cmdstr, helpstr) \
299 DEFUNSH_ATTR (daemon, funcname, cmdname, cmdstr, helpstr, CMD_ATTR_HIDDEN)
300
301#define DEFUNSH_DEPRECATED(daemon, funcname, cmdname, cmdstr, helpstr) \
302 DEFUNSH_ATTR (daemon, funcname, cmdname, cmdstr, helpstr, CMD_ATTR_DEPRECATED)
303
718e3744 304/* ALIAS macro which define existing command's alias. */
305#define ALIAS(funcname, cmdname, cmdstr, helpstr) \
406d6716 306 DEFUN_CMD_ELEMENT(funcname, cmdname, cmdstr, helpstr, 0, 0)
307
308#define ALIAS_ATTR(funcname, cmdname, cmdstr, helpstr, attr) \
274a4a44 309 DEFUN_CMD_ELEMENT(funcname, cmdname, cmdstr, helpstr, attr, 0)
406d6716 310
311#define ALIAS_HIDDEN(funcname, cmdname, cmdstr, helpstr) \
312 DEFUN_CMD_ELEMENT(funcname, cmdname, cmdstr, helpstr, CMD_ATTR_HIDDEN, 0)
313
314#define ALIAS_DEPRECATED(funcname, cmdname, cmdstr, helpstr) \
315 DEFUN_CMD_ELEMENT(funcname, cmdname, cmdstr, helpstr, CMD_ATTR_DEPRECATED, 0)
718e3744 316
274a4a44 317#define ALIAS_SH(daemon, funcname, cmdname, cmdstr, helpstr) \
318 DEFUN_CMD_ELEMENT(funcname, cmdname, cmdstr, helpstr, 0, daemon)
319
320#define ALIAS_SH_HIDDEN(daemon, funcname, cmdname, cmdstr, helpstr) \
321 DEFUN_CMD_ELEMENT(funcname, cmdname, cmdstr, helpstr, CMD_ATTR_HIDDEN, daemon)
322
323#define ALIAS_SH_DEPRECATED(daemon, funcname, cmdname, cmdstr, helpstr) \
324 DEFUN_CMD_ELEMENT(funcname, cmdname, cmdstr, helpstr, CMD_ATTR_DEPRECATED, daemon)
325
718e3744 326#endif /* VTYSH_EXTRACT_PL */
327
328/* Some macroes */
ba6d273b
DS
329
330/*
331 * Sometimes #defines create maximum values that
332 * need to have strings created from them that
333 * allow the parser to match against them.
334 * These macros allow that.
335 */
336#define CMD_CREATE_STR(s) CMD_CREATE_STR_HELPER(s)
337#define CMD_CREATE_STR_HELPER(s) #s
ba6d273b 338
718e3744 339/* Common descriptions. */
340#define SHOW_STR "Show running system information\n"
341#define IP_STR "IP information\n"
342#define IPV6_STR "IPv6 information\n"
343#define NO_STR "Negate a command or set its defaults\n"
9c42a6eb 344#define REDIST_STR "Redistribute information from another routing protocol\n"
718e3744 345#define CLEAR_STR "Reset functions\n"
346#define RIP_STR "RIP information\n"
347#define BGP_STR "BGP information\n"
e0bce756
DS
348#define BGP_SOFT_STR "Soft reconfig inbound and outbound updates\n"
349#define BGP_SOFT_IN_STR "Send route-refresh unless using 'soft-reconfiguration inbound'\n"
350#define BGP_SOFT_OUT_STR "Resend all outbound updates\n"
351#define BGP_SOFT_RSCLIENT_RIB_STR "Soft reconfig for rsclient RIB\n"
718e3744 352#define OSPF_STR "OSPF information\n"
353#define NEIGHBOR_STR "Specify neighbor router\n"
354#define DEBUG_STR "Debugging functions (see also 'undebug')\n"
355#define UNDEBUG_STR "Disable debugging functions (see also 'debug')\n"
356#define ROUTER_STR "Enable a routing process\n"
357#define AS_STR "AS number\n"
358#define MBGP_STR "MBGP information\n"
359#define MATCH_STR "Match values from routing table\n"
360#define SET_STR "Set values in destination routing protocol\n"
361#define OUT_STR "Filter outgoing routing updates\n"
362#define IN_STR "Filter incoming routing updates\n"
363#define V4NOTATION_STR "specify by IPv4 address notation(e.g. 0.0.0.0)\n"
364#define OSPF6_NUMBER_STR "Specify by number\n"
365#define INTERFACE_STR "Interface infomation\n"
366#define IFNAME_STR "Interface name(e.g. ep0)\n"
367#define IP6_STR "IPv6 Information\n"
368#define OSPF6_STR "Open Shortest Path First (OSPF) for IPv6\n"
369#define OSPF6_ROUTER_STR "Enable a routing process\n"
d0bfb22c
QY
370#define OSPF6_INSTANCE_STR "(1-65535) Instance ID\n"
371#define SECONDS_STR "(1-65535) Seconds\n"
718e3744 372#define ROUTE_STR "Routing Table\n"
373#define PREFIX_LIST_STR "Build a prefix list\n"
374#define OSPF6_DUMP_TYPE_LIST \
d0bfb22c 375"<neighbor|interface|area|lsa|zebra|config|dbex|spf|route|lsdb|redistribute|hook|asbr|prefix|abr>"
9e867fe6 376#define ISIS_STR "IS-IS information\n"
377#define AREA_TAG_STR "[area tag]\n"
d0bfb22c
QY
378#define COMMUNITY_AANN_STR "Community number where AA and NN are (0-65535)\n"
379#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"
16f1b9ee
OD
380#define MPLS_TE_STR "MPLS-TE specific commands\n"
381#define LINK_PARAMS_STR "Configure interface link parameters\n"
382#define OSPF_RI_STR "OSPF Router Information specific commands\n"
383#define PCE_STR "PCE Router Information specific commands\n"
7758e3f3 384#define MPLS_STR "MPLS information\n"
718e3744 385
386#define CONF_BACKUP_EXT ".sav"
387
388/* IPv4 only machine should not accept IPv6 address for peer's IP
389 address. So we replace VTY command string like below. */
390#ifdef HAVE_IPV6
718e3744 391#define NEIGHBOR_ADDR_STR "Neighbor address\nIPv6 address\n"
a80beece
DS
392#define NEIGHBOR_ADDR_STR2 "Neighbor address\nNeighbor IPv6 address\nInterface name or neighbor tag\n"
393#define NEIGHBOR_ADDR_STR3 "Neighbor address\nIPv6 address\nInterface name\n"
718e3744 394#else
718e3744 395#define NEIGHBOR_ADDR_STR "Neighbor address\n"
718e3744 396#define NEIGHBOR_ADDR_STR2 "Neighbor address\nNeighbor tag\n"
397#endif /* HAVE_IPV6 */
398
f14e6fdb
DS
399/* Dynamic neighbor (listen range) configuration */
400#ifdef HAVE_IPV6
f14e6fdb
DS
401#define LISTEN_RANGE_ADDR_STR "Neighbor address\nNeighbor IPv6 address\n"
402#else
f14e6fdb
DS
403#define LISTEN_RANGE_ADDR_STR "Neighbor address\n"
404#endif /* HAVE_IPV6 */
405
718e3744 406/* Prototypes. */
8cc4198f 407extern void install_node (struct cmd_node *, int (*) (struct vty *));
408extern void install_default (enum node_type);
409extern void install_element (enum node_type, struct cmd_element *);
718e3744 410
f6834d4c 411/* Concatenates argv[shift] through argv[argc-1] into a single NUL-terminated
412 string with a space between each element (allocated using
413 XMALLOC(MTYPE_TMP)). Returns NULL if shift >= argc. */
d0bfb22c 414extern char *argv_concat (struct cmd_token **argv, int argc, int shift);
ae19d7dd 415extern int argv_find (struct cmd_token **argv, int argc, const char *text, int *index);
8cc4198f 416
417extern vector cmd_make_strvec (const char *);
418extern void cmd_free_strvec (vector);
42debbb4 419extern char *cmd_concat_strvec (vector);
8cc4198f 420extern vector cmd_describe_command (vector, struct vty *, int *status);
421extern char **cmd_complete_command (vector, struct vty *, int *status);
cde9f101 422extern char **cmd_complete_command_lib (vector, struct vty *, int *status, int islib);
8cc4198f 423extern const char *cmd_prompt (enum node_type);
bed578b8 424extern int command_config_read_one_line (struct vty *vty, struct cmd_element **, int use_config_node);
13fbc82d 425extern int config_from_file (struct vty *, FILE *, unsigned int *line_num);
8cc4198f 426extern enum node_type node_parent (enum node_type);
427extern int cmd_execute_command (vector, struct vty *, struct cmd_element **, int);
428extern int cmd_execute_command_strict (vector, struct vty *, struct cmd_element **);
8cc4198f 429extern void cmd_init (int);
228da428 430extern void cmd_terminate (void);
718e3744 431
de9d7e4f
QY
432/* memory management for cmd_element */
433void
1eb5e8dc 434del_cmd_element(struct cmd_element *);
de9d7e4f
QY
435struct cmd_element *
436copy_cmd_element(struct cmd_element *cmd);
437
d0bfb22c
QY
438/* memory management for cmd_token */
439struct cmd_token *
440new_cmd_token (enum cmd_token_type, char *, char *);
441void
442del_cmd_token (struct cmd_token *);
443struct cmd_token *
444copy_cmd_token (struct cmd_token *);
445
718e3744 446/* Export typical functions. */
447extern struct cmd_element config_end_cmd;
448extern struct cmd_element config_exit_cmd;
449extern struct cmd_element config_quit_cmd;
450extern struct cmd_element config_help_cmd;
451extern struct cmd_element config_list_cmd;
57387fb2 452extern const char *host_config_get (void);
c0e8c16f 453extern void host_config_set (const char *);
6590f2c3 454
8cc4198f 455extern void print_version (const char *);
86228fde 456
7cfc61d3
DS
457extern int cmd_banner_motd_file (const char *);
458
86228fde 459/* struct host global, ick */
d0bfb22c
QY
460extern struct host host;
461
462/* text for <cr> command */
463#define CMD_CR_TEXT "<cr>"
228da428 464
718e3744 465#endif /* _ZEBRA_COMMAND_H */