blob: 32a347fca2f6e3e1a5fdf2aa6c5d10b6134194d4 [file] [log] [blame]
paul718e3742002-12-13 20:15:29 +00001/*
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.
11 *
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"
28
29/* Host configuration variable */
30struct host
31{
32 /* Host name of this router. */
33 char *name;
34
35 /* Password for vty interface. */
36 char *password;
37 char *password_encrypt;
38
39 /* Enable password */
40 char *enable;
41 char *enable_encrypt;
42
43 /* System wide terminal lines. */
44 int lines;
45
46 /* Log filename. */
47 char *logfile;
48
49 /* Log stdout. */
50 u_char log_stdout;
51
52 /* Log syslog. */
53 u_char log_syslog;
54
55 /* config file name of this host */
56 char *config;
57
58 /* Flags for services */
59 int advanced;
60 int encrypt;
61
62 /* Banner configuration. */
63 char *motd;
64};
65
66/* There are some command levels which called from command node. */
67enum node_type
68{
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 */
jardin9e867fe2003-12-23 08:56:18 +000090 ISIS_NODE, /* ISIS protocol mode */
paul718e3742002-12-13 20:15:29 +000091 MASC_NODE, /* MASC for multicast. */
92 IRDP_NODE, /* ICMP Router Discovery Protocol mode. */
93 IP_NODE, /* Static ip route node. */
94 ACCESS_NODE, /* Access list node. */
95 PREFIX_NODE, /* Prefix list node. */
96 ACCESS_IPV6_NODE, /* Access list node. */
97 PREFIX_IPV6_NODE, /* Prefix list node. */
98 AS_LIST_NODE, /* AS list node. */
99 COMMUNITY_LIST_NODE, /* Community list node. */
100 RMAP_NODE, /* Route map node. */
101 SMUX_NODE, /* SNMP configuration node. */
102 DUMP_NODE, /* Packet dump node. */
103 FORWARDING_NODE, /* IP forwarding node. */
104 VTY_NODE /* Vty node. */
105};
106
107/* Node which has some commands and prompt string and configuration
108 function pointer . */
109struct cmd_node
110{
111 /* Node index. */
112 enum node_type node;
113
114 /* Prompt character at vty interface. */
115 char *prompt;
116
117 /* Is this node's configuration goes to vtysh ? */
118 int vtysh;
119
120 /* Node's configuration write function */
121 int (*func) (struct vty *);
122
123 /* Vector of this node's command list. */
124 vector cmd_vector;
125};
126
127/* Structure of command element. */
128struct cmd_element
129{
130 char *string; /* Command specification by string. */
131 int (*func) (struct cmd_element *, struct vty *, int, char **);
132 char *doc; /* Documentation of this command. */
133 int daemon; /* Daemon to which this command belong. */
134 vector strvec; /* Pointing out each description vector. */
135 int cmdsize; /* Command index count. */
136 char *config; /* Configuration string */
137 vector subconfig; /* Sub configuration string */
138};
139
140/* Command description structure. */
141struct desc
142{
143 char *cmd; /* Command string. */
144 char *str; /* Command's description. */
145};
146
147/* Return value of the commands. */
148#define CMD_SUCCESS 0
149#define CMD_WARNING 1
150#define CMD_ERR_NO_MATCH 2
151#define CMD_ERR_AMBIGUOUS 3
152#define CMD_ERR_INCOMPLETE 4
153#define CMD_ERR_EXEED_ARGC_MAX 5
154#define CMD_ERR_NOTHING_TODO 6
155#define CMD_COMPLETE_FULL_MATCH 7
156#define CMD_COMPLETE_MATCH 8
157#define CMD_COMPLETE_LIST_MATCH 9
158#define CMD_SUCCESS_DAEMON 10
159
160/* Argc max counts. */
161#define CMD_ARGC_MAX 25
162
163/* Turn off these macros when uisng cpp with extract.pl */
164#ifndef VTYSH_EXTRACT_PL
165
166/* DEFUN for vty command interafce. Little bit hacky ;-). */
167#define DEFUN(funcname, cmdname, cmdstr, helpstr) \
168 int funcname (struct cmd_element *, struct vty *, int, char **); \
169 struct cmd_element cmdname = \
170 { \
171 cmdstr, \
172 funcname, \
173 helpstr \
174 }; \
175 int funcname \
176 (struct cmd_element *self, struct vty *vty, int argc, char **argv)
177
178/* DEFUN_NOSH for commands that vtysh should ignore */
179#define DEFUN_NOSH(funcname, cmdname, cmdstr, helpstr) \
180 DEFUN(funcname, cmdname, cmdstr, helpstr)
181
182/* DEFSH for vtysh. */
183#define DEFSH(daemon, cmdname, cmdstr, helpstr) \
184 struct cmd_element cmdname = \
185 { \
186 cmdstr, \
187 NULL, \
188 helpstr, \
189 daemon \
190 }; \
191
192/* DEFUN + DEFSH */
193#define DEFUNSH(daemon, funcname, cmdname, cmdstr, helpstr) \
194 int funcname (struct cmd_element *, struct vty *, int, char **); \
195 struct cmd_element cmdname = \
196 { \
197 cmdstr, \
198 funcname, \
199 helpstr, \
200 daemon \
201 }; \
202 int funcname \
203 (struct cmd_element *self, struct vty *vty, int argc, char **argv)
204
205/* ALIAS macro which define existing command's alias. */
206#define ALIAS(funcname, cmdname, cmdstr, helpstr) \
207 struct cmd_element cmdname = \
208 { \
209 cmdstr, \
210 funcname, \
211 helpstr \
212 };
213
214#endif /* VTYSH_EXTRACT_PL */
215
216/* Some macroes */
217#define CMD_OPTION(S) ((S[0]) == '[')
218#define CMD_VARIABLE(S) (((S[0]) >= 'A' && (S[0]) <= 'Z') || ((S[0]) == '<'))
219#define CMD_VARARG(S) ((S[0]) == '.')
220#define CMD_RANGE(S) ((S[0] == '<'))
221
222#define CMD_IPV4(S) ((strcmp ((S), "A.B.C.D") == 0))
223#define CMD_IPV4_PREFIX(S) ((strcmp ((S), "A.B.C.D/M") == 0))
224#define CMD_IPV6(S) ((strcmp ((S), "X:X::X:X") == 0))
225#define CMD_IPV6_PREFIX(S) ((strcmp ((S), "X:X::X:X/M") == 0))
226
227/* Common descriptions. */
228#define SHOW_STR "Show running system information\n"
229#define IP_STR "IP information\n"
230#define IPV6_STR "IPv6 information\n"
231#define NO_STR "Negate a command or set its defaults\n"
232#define CLEAR_STR "Reset functions\n"
233#define RIP_STR "RIP information\n"
234#define BGP_STR "BGP information\n"
235#define OSPF_STR "OSPF information\n"
236#define NEIGHBOR_STR "Specify neighbor router\n"
237#define DEBUG_STR "Debugging functions (see also 'undebug')\n"
238#define UNDEBUG_STR "Disable debugging functions (see also 'debug')\n"
239#define ROUTER_STR "Enable a routing process\n"
240#define AS_STR "AS number\n"
241#define MBGP_STR "MBGP information\n"
242#define MATCH_STR "Match values from routing table\n"
243#define SET_STR "Set values in destination routing protocol\n"
244#define OUT_STR "Filter outgoing routing updates\n"
245#define IN_STR "Filter incoming routing updates\n"
246#define V4NOTATION_STR "specify by IPv4 address notation(e.g. 0.0.0.0)\n"
247#define OSPF6_NUMBER_STR "Specify by number\n"
248#define INTERFACE_STR "Interface infomation\n"
249#define IFNAME_STR "Interface name(e.g. ep0)\n"
250#define IP6_STR "IPv6 Information\n"
251#define OSPF6_STR "Open Shortest Path First (OSPF) for IPv6\n"
252#define OSPF6_ROUTER_STR "Enable a routing process\n"
253#define OSPF6_INSTANCE_STR "<1-65535> Instance ID\n"
254#define SECONDS_STR "<1-65535> Seconds\n"
255#define ROUTE_STR "Routing Table\n"
256#define PREFIX_LIST_STR "Build a prefix list\n"
257#define OSPF6_DUMP_TYPE_LIST \
258"(neighbor|interface|area|lsa|zebra|config|dbex|spf|route|lsdb|redistribute|hook|asbr|prefix|abr)"
jardin9e867fe2003-12-23 08:56:18 +0000259#define ISIS_STR "IS-IS information\n"
260#define AREA_TAG_STR "[area tag]\n"
paul718e3742002-12-13 20:15:29 +0000261
262#define CONF_BACKUP_EXT ".sav"
263
264/* IPv4 only machine should not accept IPv6 address for peer's IP
265 address. So we replace VTY command string like below. */
266#ifdef HAVE_IPV6
267#define NEIGHBOR_CMD "neighbor (A.B.C.D|X:X::X:X) "
268#define NO_NEIGHBOR_CMD "no neighbor (A.B.C.D|X:X::X:X) "
269#define NEIGHBOR_ADDR_STR "Neighbor address\nIPv6 address\n"
270#define NEIGHBOR_CMD2 "neighbor (A.B.C.D|X:X::X:X|WORD) "
271#define NO_NEIGHBOR_CMD2 "no neighbor (A.B.C.D|X:X::X:X|WORD) "
272#define NEIGHBOR_ADDR_STR2 "Neighbor address\nNeighbor IPv6 address\nNeighbor tag\n"
273#else
274#define NEIGHBOR_CMD "neighbor A.B.C.D "
275#define NO_NEIGHBOR_CMD "no neighbor A.B.C.D "
276#define NEIGHBOR_ADDR_STR "Neighbor address\n"
277#define NEIGHBOR_CMD2 "neighbor (A.B.C.D|WORD) "
278#define NO_NEIGHBOR_CMD2 "no neighbor (A.B.C.D|WORD) "
279#define NEIGHBOR_ADDR_STR2 "Neighbor address\nNeighbor tag\n"
280#endif /* HAVE_IPV6 */
281
282/* Prototypes. */
283void install_node (struct cmd_node *, int (*) (struct vty *));
284void install_default (enum node_type);
285void install_element (enum node_type, struct cmd_element *);
286void sort_node ();
287
288char *argv_concat (char **, int, int);
289vector cmd_make_strvec (char *);
290void cmd_free_strvec (vector);
291vector cmd_describe_command ();
292char **cmd_complete_command ();
293char *cmd_prompt (enum node_type);
294int config_from_file (struct vty *, FILE *);
295int cmd_execute_command (vector, struct vty *, struct cmd_element **);
296int cmd_execute_command_strict (vector, struct vty *, struct cmd_element **);
297void config_replace_string (struct cmd_element *, char *, ...);
298void cmd_init (int);
299
300/* Export typical functions. */
301extern struct cmd_element config_end_cmd;
302extern struct cmd_element config_exit_cmd;
303extern struct cmd_element config_quit_cmd;
304extern struct cmd_element config_help_cmd;
305extern struct cmd_element config_list_cmd;
306int config_exit (struct cmd_element *, struct vty *, int, char **);
307int config_help (struct cmd_element *, struct vty *, int, char **);
308char *host_config_file ();
309void host_config_set (char *);
310
311#endif /* _ZEBRA_COMMAND_H */