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
29 /* Host configuration variable */
32 /* Host name of this router. */
35 /* Password for vty interface. */
37 char *password_encrypt
;
43 /* System wide terminal lines. */
55 /* config file name of this host */
58 /* Flags for services */
62 /* Banner configuration. */
66 /* There are some command levels which called from command node. */
69 AUTH_NODE
, /* Authentication mode of vty interface. */
70 VIEW_NODE
, /* View node. Default mode of vty interface. */
71 AUTH_ENABLE_NODE
, /* Authentication mode for change enable. */
72 ENABLE_NODE
, /* Enable node. */
73 CONFIG_NODE
, /* Config node. Default mode of config file. */
74 DEBUG_NODE
, /* Debug node. */
75 AAA_NODE
, /* AAA node. */
76 KEYCHAIN_NODE
, /* Key-chain node. */
77 KEYCHAIN_KEY_NODE
, /* Key-chain key node. */
78 INTERFACE_NODE
, /* Interface mode node. */
79 ZEBRA_NODE
, /* zebra connection node. */
80 TABLE_NODE
, /* rtm_table selection node. */
81 RIP_NODE
, /* RIP protocol mode node. */
82 RIPNG_NODE
, /* RIPng protocol mode node. */
83 BGP_NODE
, /* BGP protocol mode which includes BGP4+ */
84 BGP_VPNV4_NODE
, /* BGP MPLS-VPN PE exchange. */
85 BGP_IPV4_NODE
, /* BGP IPv4 unicast address family. */
86 BGP_IPV4M_NODE
, /* BGP IPv4 multicast address family. */
87 BGP_IPV6_NODE
, /* BGP IPv6 address family */
88 OSPF_NODE
, /* OSPF protocol mode */
89 OSPF6_NODE
, /* OSPF protocol for IPv6 mode */
90 MASC_NODE
, /* MASC for multicast. */
91 IRDP_NODE
, /* ICMP Router Discovery Protocol mode. */
92 IP_NODE
, /* Static ip route node. */
93 ACCESS_NODE
, /* Access list node. */
94 PREFIX_NODE
, /* Prefix list node. */
95 ACCESS_IPV6_NODE
, /* Access list node. */
96 PREFIX_IPV6_NODE
, /* Prefix list node. */
97 AS_LIST_NODE
, /* AS list node. */
98 COMMUNITY_LIST_NODE
, /* Community list node. */
99 RMAP_NODE
, /* Route map node. */
100 SMUX_NODE
, /* SNMP configuration node. */
101 DUMP_NODE
, /* Packet dump node. */
102 FORWARDING_NODE
, /* IP forwarding node. */
103 VTY_NODE
/* Vty node. */
106 /* Node which has some commands and prompt string and configuration
107 function pointer . */
113 /* Prompt character at vty interface. */
116 /* Is this node's configuration goes to vtysh ? */
119 /* Node's configuration write function */
120 int (*func
) (struct vty
*);
122 /* Vector of this node's command list. */
126 /* Structure of command element. */
129 char *string
; /* Command specification by string. */
130 int (*func
) (struct cmd_element
*, struct vty
*, int, char **);
131 char *doc
; /* Documentation of this command. */
132 int daemon
; /* Daemon to which this command belong. */
133 vector strvec
; /* Pointing out each description vector. */
134 int cmdsize
; /* Command index count. */
135 char *config
; /* Configuration string */
136 vector subconfig
; /* Sub configuration string */
139 /* Command description structure. */
142 char *cmd
; /* Command string. */
143 char *str
; /* Command's description. */
146 /* Return value of the commands. */
147 #define CMD_SUCCESS 0
148 #define CMD_WARNING 1
149 #define CMD_ERR_NO_MATCH 2
150 #define CMD_ERR_AMBIGUOUS 3
151 #define CMD_ERR_INCOMPLETE 4
152 #define CMD_ERR_EXEED_ARGC_MAX 5
153 #define CMD_ERR_NOTHING_TODO 6
154 #define CMD_COMPLETE_FULL_MATCH 7
155 #define CMD_COMPLETE_MATCH 8
156 #define CMD_COMPLETE_LIST_MATCH 9
157 #define CMD_SUCCESS_DAEMON 10
159 /* Argc max counts. */
160 #define CMD_ARGC_MAX 25
162 /* Turn off these macros when uisng cpp with extract.pl */
163 #ifndef VTYSH_EXTRACT_PL
165 /* DEFUN for vty command interafce. Little bit hacky ;-). */
166 #define DEFUN(funcname, cmdname, cmdstr, helpstr) \
167 int funcname (struct cmd_element *, struct vty *, int, char **); \
168 struct cmd_element cmdname = \
175 (struct cmd_element *self, struct vty *vty, int argc, char **argv)
177 /* DEFUN_NOSH for commands that vtysh should ignore */
178 #define DEFUN_NOSH(funcname, cmdname, cmdstr, helpstr) \
179 DEFUN(funcname, cmdname, cmdstr, helpstr)
181 /* DEFSH for vtysh. */
182 #define DEFSH(daemon, cmdname, cmdstr, helpstr) \
183 struct cmd_element cmdname = \
192 #define DEFUNSH(daemon, funcname, cmdname, cmdstr, helpstr) \
193 int funcname (struct cmd_element *, struct vty *, int, char **); \
194 struct cmd_element cmdname = \
202 (struct cmd_element *self, struct vty *vty, int argc, char **argv)
204 /* ALIAS macro which define existing command's alias. */
205 #define ALIAS(funcname, cmdname, cmdstr, helpstr) \
206 struct cmd_element cmdname = \
213 #endif /* VTYSH_EXTRACT_PL */
216 #define CMD_OPTION(S) ((S[0]) == '[')
217 #define CMD_VARIABLE(S) (((S[0]) >= 'A' && (S[0]) <= 'Z') || ((S[0]) == '<'))
218 #define CMD_VARARG(S) ((S[0]) == '.')
219 #define CMD_RANGE(S) ((S[0] == '<'))
221 #define CMD_IPV4(S) ((strcmp ((S), "A.B.C.D") == 0))
222 #define CMD_IPV4_PREFIX(S) ((strcmp ((S), "A.B.C.D/M") == 0))
223 #define CMD_IPV6(S) ((strcmp ((S), "X:X::X:X") == 0))
224 #define CMD_IPV6_PREFIX(S) ((strcmp ((S), "X:X::X:X/M") == 0))
226 /* Common descriptions. */
227 #define SHOW_STR "Show running system information\n"
228 #define IP_STR "IP information\n"
229 #define IPV6_STR "IPv6 information\n"
230 #define NO_STR "Negate a command or set its defaults\n"
231 #define CLEAR_STR "Reset functions\n"
232 #define RIP_STR "RIP information\n"
233 #define BGP_STR "BGP information\n"
234 #define OSPF_STR "OSPF information\n"
235 #define NEIGHBOR_STR "Specify neighbor router\n"
236 #define DEBUG_STR "Debugging functions (see also 'undebug')\n"
237 #define UNDEBUG_STR "Disable debugging functions (see also 'debug')\n"
238 #define ROUTER_STR "Enable a routing process\n"
239 #define AS_STR "AS number\n"
240 #define MBGP_STR "MBGP information\n"
241 #define MATCH_STR "Match values from routing table\n"
242 #define SET_STR "Set values in destination routing protocol\n"
243 #define OUT_STR "Filter outgoing routing updates\n"
244 #define IN_STR "Filter incoming routing updates\n"
245 #define V4NOTATION_STR "specify by IPv4 address notation(e.g. 0.0.0.0)\n"
246 #define OSPF6_NUMBER_STR "Specify by number\n"
247 #define INTERFACE_STR "Interface infomation\n"
248 #define IFNAME_STR "Interface name(e.g. ep0)\n"
249 #define IP6_STR "IPv6 Information\n"
250 #define OSPF6_STR "Open Shortest Path First (OSPF) for IPv6\n"
251 #define OSPF6_ROUTER_STR "Enable a routing process\n"
252 #define OSPF6_INSTANCE_STR "<1-65535> Instance ID\n"
253 #define SECONDS_STR "<1-65535> Seconds\n"
254 #define ROUTE_STR "Routing Table\n"
255 #define PREFIX_LIST_STR "Build a prefix list\n"
256 #define OSPF6_DUMP_TYPE_LIST \
257 "(neighbor|interface|area|lsa|zebra|config|dbex|spf|route|lsdb|redistribute|hook|asbr|prefix|abr)"
259 #define CONF_BACKUP_EXT ".sav"
261 /* IPv4 only machine should not accept IPv6 address for peer's IP
262 address. So we replace VTY command string like below. */
264 #define NEIGHBOR_CMD "neighbor (A.B.C.D|X:X::X:X) "
265 #define NO_NEIGHBOR_CMD "no neighbor (A.B.C.D|X:X::X:X) "
266 #define NEIGHBOR_ADDR_STR "Neighbor address\nIPv6 address\n"
267 #define NEIGHBOR_CMD2 "neighbor (A.B.C.D|X:X::X:X|WORD) "
268 #define NO_NEIGHBOR_CMD2 "no neighbor (A.B.C.D|X:X::X:X|WORD) "
269 #define NEIGHBOR_ADDR_STR2 "Neighbor address\nNeighbor IPv6 address\nNeighbor tag\n"
271 #define NEIGHBOR_CMD "neighbor A.B.C.D "
272 #define NO_NEIGHBOR_CMD "no neighbor A.B.C.D "
273 #define NEIGHBOR_ADDR_STR "Neighbor address\n"
274 #define NEIGHBOR_CMD2 "neighbor (A.B.C.D|WORD) "
275 #define NO_NEIGHBOR_CMD2 "no neighbor (A.B.C.D|WORD) "
276 #define NEIGHBOR_ADDR_STR2 "Neighbor address\nNeighbor tag\n"
277 #endif /* HAVE_IPV6 */
280 void install_node (struct cmd_node
*, int (*) (struct vty
*));
281 void install_default (enum node_type
);
282 void install_element (enum node_type
, struct cmd_element
*);
285 char *argv_concat (char **, int, int);
286 vector
cmd_make_strvec (char *);
287 void cmd_free_strvec (vector
);
288 vector
cmd_describe_command ();
289 char **cmd_complete_command ();
290 char *cmd_prompt (enum node_type
);
291 int config_from_file (struct vty
*, FILE *);
292 int cmd_execute_command (vector
, struct vty
*, struct cmd_element
**);
293 int cmd_execute_command_strict (vector
, struct vty
*, struct cmd_element
**);
294 void config_replace_string (struct cmd_element
*, char *, ...);
297 /* Export typical functions. */
298 extern struct cmd_element config_end_cmd
;
299 extern struct cmd_element config_exit_cmd
;
300 extern struct cmd_element config_quit_cmd
;
301 extern struct cmd_element config_help_cmd
;
302 extern struct cmd_element config_list_cmd
;
303 int config_exit (struct cmd_element
*, struct vty
*, int, char **);
304 int config_help (struct cmd_element
*, struct vty
*, int, char **);
305 char *host_config_file ();
306 void host_config_set (char *);
308 #endif /* _ZEBRA_COMMAND_H */