libosmovty  UNKNOWN
Osmocom VTY library
command.h
Go to the documentation of this file.
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.
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 #pragma once
24 
25 #include <stdio.h>
26 #include <sys/types.h>
27 #include "vector.h"
28 
35 struct host {
37  char *name;
38 
40  char *password;
41  char *password_encrypt;
42 
44  char *enable;
45  char *enable_encrypt;
46 
48  int lines;
49 
51  char *logfile;
52 
54  char *config;
55 
57  int advanced;
58  int encrypt;
59 
61  const char *motd;
62  char *motdfile;
63 
65  const struct vty_app_info *app_info;
66 };
67 
69 enum node_type {
87  /*
88  * When adding new nodes to the libosmocore project, these nodes can be
89  * used to avoid ABI changes for unrelated projects.
90  */
96  _LAST_OSMOVTY_NODE
97 };
98 
99 #include "vty.h"
100 
103 struct cmd_node {
105  int node;
106 
108  const char *prompt;
109 
111  int vtysh;
112 
114  int (*func) (struct vty *);
115 
118 };
119 
120 enum {
121  CMD_ATTR_DEPRECATED = 1,
122  CMD_ATTR_HIDDEN,
123 };
124 
126 struct cmd_element {
127  const char *string;
128  int (*func) (struct cmd_element *, struct vty *, int, const char *[]);
129  const char *doc;
130  int daemon;
132  unsigned int cmdsize;
133  char *config;
135  unsigned char attr;
136 };
137 
139 struct desc {
140  const char *cmd;
141  const char *str;
142 };
143 
145 #define CMD_SUCCESS 0
146 #define CMD_WARNING 1
147 #define CMD_ERR_NO_MATCH 2
148 #define CMD_ERR_AMBIGUOUS 3
149 #define CMD_ERR_INCOMPLETE 4
150 #define CMD_ERR_EXEED_ARGC_MAX 5
151 #define CMD_ERR_NOTHING_TODO 6
152 #define CMD_COMPLETE_FULL_MATCH 7
153 #define CMD_COMPLETE_MATCH 8
154 #define CMD_COMPLETE_LIST_MATCH 9
155 #define CMD_SUCCESS_DAEMON 10
156 
157 /* Argc max counts. */
158 #define CMD_ARGC_MAX 256
159 
160 /* Turn off these macros when uisng cpp with extract.pl */
161 #ifndef VTYSH_EXTRACT_PL
162 
163 /* helper defines for end-user DEFUN* macros */
164 #define DEFUN_CMD_ELEMENT(funcname, cmdname, cmdstr, helpstr, attrs, dnum) \
165  static struct cmd_element cmdname = \
166  { \
167  .string = cmdstr, \
168  .func = funcname, \
169  .doc = helpstr, \
170  .attr = attrs, \
171  .daemon = dnum, \
172  };
173 
174 /* global (non static) cmd_element */
175 #define gDEFUN_CMD_ELEMENT(funcname, cmdname, cmdstr, helpstr, attrs, dnum) \
176  struct cmd_element cmdname = \
177  { \
178  .string = cmdstr, \
179  .func = funcname, \
180  .doc = helpstr, \
181  .attr = attrs, \
182  .daemon = dnum, \
183  };
184 
185 #define DEFUN_CMD_FUNC_DECL(funcname) \
186  static int funcname (struct cmd_element *, struct vty *, int, const char *[]); \
187 
188 #define DEFUN_CMD_FUNC_TEXT(funcname) \
189  static int funcname \
190  (struct cmd_element *self, struct vty *vty, int argc, const char *argv[])
191 
198 #define DEFUN(funcname, cmdname, cmdstr, helpstr) \
199  DEFUN_CMD_FUNC_DECL(funcname) \
200  DEFUN_CMD_ELEMENT(funcname, cmdname, cmdstr, helpstr, 0, 0) \
201  DEFUN_CMD_FUNC_TEXT(funcname)
202 
209 #define gDEFUN(funcname, cmdname, cmdstr, helpstr) \
210  DEFUN_CMD_FUNC_DECL(funcname) \
211  gDEFUN_CMD_ELEMENT(funcname, cmdname, cmdstr, helpstr, 0, 0) \
212  DEFUN_CMD_FUNC_TEXT(funcname)
213 
214 #define DEFUN_ATTR(funcname, cmdname, cmdstr, helpstr, attr) \
215  DEFUN_CMD_FUNC_DECL(funcname) \
216  DEFUN_CMD_ELEMENT(funcname, cmdname, cmdstr, helpstr, attr, 0) \
217  DEFUN_CMD_FUNC_TEXT(funcname)
218 
219 #define DEFUN_HIDDEN(funcname, cmdname, cmdstr, helpstr) \
220  DEFUN_ATTR (funcname, cmdname, cmdstr, helpstr, CMD_ATTR_HIDDEN)
221 
222 #define DEFUN_DEPRECATED(funcname, cmdname, cmdstr, helpstr) \
223  DEFUN_ATTR (funcname, cmdname, cmdstr, helpstr, CMD_ATTR_DEPRECATED) \
224 
225 /* DEFUN_NOSH for commands that vtysh should ignore */
226 #define DEFUN_NOSH(funcname, cmdname, cmdstr, helpstr) \
227  DEFUN(funcname, cmdname, cmdstr, helpstr)
228 
229 /* DEFSH for vtysh. */
230 #define DEFSH(daemon, cmdname, cmdstr, helpstr) \
231  DEFUN_CMD_ELEMENT(NULL, cmdname, cmdstr, helpstr, 0, daemon) \
232 
233 /* DEFUN + DEFSH */
234 #define DEFUNSH(daemon, funcname, cmdname, cmdstr, helpstr) \
235  DEFUN_CMD_FUNC_DECL(funcname) \
236  DEFUN_CMD_ELEMENT(funcname, cmdname, cmdstr, helpstr, 0, daemon) \
237  DEFUN_CMD_FUNC_TEXT(funcname)
238 
239 /* DEFUN + DEFSH with attributes */
240 #define DEFUNSH_ATTR(daemon, funcname, cmdname, cmdstr, helpstr, attr) \
241  DEFUN_CMD_FUNC_DECL(funcname) \
242  DEFUN_CMD_ELEMENT(funcname, cmdname, cmdstr, helpstr, attr, daemon) \
243  DEFUN_CMD_FUNC_TEXT(funcname)
244 
245 #define DEFUNSH_HIDDEN(daemon, funcname, cmdname, cmdstr, helpstr) \
246  DEFUNSH_ATTR (daemon, funcname, cmdname, cmdstr, helpstr, CMD_ATTR_HIDDEN)
247 
248 #define DEFUNSH_DEPRECATED(daemon, funcname, cmdname, cmdstr, helpstr) \
249  DEFUNSH_ATTR (daemon, funcname, cmdname, cmdstr, helpstr, CMD_ATTR_DEPRECATED)
250 
251 /* ALIAS macro which define existing command's alias. */
252 #define ALIAS(funcname, cmdname, cmdstr, helpstr) \
253  DEFUN_CMD_ELEMENT(funcname, cmdname, cmdstr, helpstr, 0, 0)
254 
255 /* global (non static) cmd_element */
256 #define gALIAS(funcname, cmdname, cmdstr, helpstr) \
257  gDEFUN_CMD_ELEMENT(funcname, cmdname, cmdstr, helpstr, 0, 0)
258 
259 #define ALIAS_ATTR(funcname, cmdname, cmdstr, helpstr, attr) \
260  DEFUN_CMD_ELEMENT(funcname, cmdname, cmdstr, helpstr, attr, 0)
261 
262 #define ALIAS_HIDDEN(funcname, cmdname, cmdstr, helpstr) \
263  DEFUN_CMD_ELEMENT(funcname, cmdname, cmdstr, helpstr, CMD_ATTR_HIDDEN, 0)
264 
265 #define ALIAS_DEPRECATED(funcname, cmdname, cmdstr, helpstr) \
266  DEFUN_CMD_ELEMENT(funcname, cmdname, cmdstr, helpstr, CMD_ATTR_DEPRECATED, 0)
267 
268 #define ALIAS_SH(daemon, funcname, cmdname, cmdstr, helpstr) \
269  DEFUN_CMD_ELEMENT(funcname, cmdname, cmdstr, helpstr, 0, daemon)
270 
271 #define ALIAS_SH_HIDDEN(daemon, funcname, cmdname, cmdstr, helpstr) \
272  DEFUN_CMD_ELEMENT(funcname, cmdname, cmdstr, helpstr, CMD_ATTR_HIDDEN, daemon)
273 
274 #define ALIAS_SH_DEPRECATED(daemon, funcname, cmdname, cmdstr, helpstr) \
275  DEFUN_CMD_ELEMENT(funcname, cmdname, cmdstr, helpstr, CMD_ATTR_DEPRECATED, daemon)
276 
277 #endif /* VTYSH_EXTRACT_PL */
278 
279 /* Some macroes */
280 #define CMD_OPTION(S) ((S[0]) == '[')
281 #define CMD_VARIABLE(S) (((S[0]) >= 'A' && (S[0]) <= 'Z') || ((S[0]) == '<'))
282 #define CMD_VARARG(S) ((S[0]) == '.')
283 #define CMD_RANGE(S) ((S[0] == '<'))
284 
285 #define CMD_IPV4(S) ((strcmp ((S), "A.B.C.D") == 0))
286 #define CMD_IPV4_PREFIX(S) ((strcmp ((S), "A.B.C.D/M") == 0))
287 #define CMD_IPV6(S) ((strcmp ((S), "X:X::X:X") == 0))
288 #define CMD_IPV6_PREFIX(S) ((strcmp ((S), "X:X::X:X/M") == 0))
289 
290 /* Common descriptions. */
291 #define SHOW_STR "Show running system information\n"
292 #define IP_STR "IP information\n"
293 #define IPV6_STR "IPv6 information\n"
294 #define NO_STR "Negate a command or set its defaults\n"
295 #define CLEAR_STR "Reset functions\n"
296 #define RIP_STR "RIP information\n"
297 #define BGP_STR "BGP information\n"
298 #define OSPF_STR "OSPF information\n"
299 #define NEIGHBOR_STR "Specify neighbor router\n"
300 #define DEBUG_STR "Debugging functions (see also 'undebug')\n"
301 #define UNDEBUG_STR "Disable debugging functions (see also 'debug')\n"
302 #define ROUTER_STR "Enable a routing process\n"
303 #define AS_STR "AS number\n"
304 #define MBGP_STR "MBGP information\n"
305 #define MATCH_STR "Match values from routing table\n"
306 #define SET_STR "Set values in destination routing protocol\n"
307 #define OUT_STR "Filter outgoing routing updates\n"
308 #define IN_STR "Filter incoming routing updates\n"
309 #define V4NOTATION_STR "specify by IPv4 address notation(e.g. 0.0.0.0)\n"
310 #define OSPF6_NUMBER_STR "Specify by number\n"
311 #define INTERFACE_STR "Interface infomation\n"
312 #define IFNAME_STR "Interface name(e.g. ep0)\n"
313 #define IP6_STR "IPv6 Information\n"
314 #define OSPF6_STR "Open Shortest Path First (OSPF) for IPv6\n"
315 #define OSPF6_ROUTER_STR "Enable a routing process\n"
316 #define OSPF6_INSTANCE_STR "<1-65535> Instance ID\n"
317 #define SECONDS_STR "<1-65535> Seconds\n"
318 #define ROUTE_STR "Routing Table\n"
319 #define PREFIX_LIST_STR "Build a prefix list\n"
320 #define OSPF6_DUMP_TYPE_LIST \
321 "(neighbor|interface|area|lsa|zebra|config|dbex|spf|route|lsdb|redistribute|hook|asbr|prefix|abr)"
322 #define ISIS_STR "IS-IS information\n"
323 #define AREA_TAG_STR "[area tag]\n"
324 
325 #define CONF_BACKUP_EXT ".sav"
326 
327 /* IPv4 only machine should not accept IPv6 address for peer's IP
328  address. So we replace VTY command string like below. */
329 #ifdef HAVE_IPV6
330 #define NEIGHBOR_CMD "neighbor (A.B.C.D|X:X::X:X) "
331 #define NO_NEIGHBOR_CMD "no neighbor (A.B.C.D|X:X::X:X) "
332 #define NEIGHBOR_ADDR_STR "Neighbor address\nIPv6 address\n"
333 #define NEIGHBOR_CMD2 "neighbor (A.B.C.D|X:X::X:X|WORD) "
334 #define NO_NEIGHBOR_CMD2 "no neighbor (A.B.C.D|X:X::X:X|WORD) "
335 #define NEIGHBOR_ADDR_STR2 "Neighbor address\nNeighbor IPv6 address\nNeighbor tag\n"
336 #else
337 #define NEIGHBOR_CMD "neighbor A.B.C.D "
338 #define NO_NEIGHBOR_CMD "no neighbor A.B.C.D "
339 #define NEIGHBOR_ADDR_STR "Neighbor address\n"
340 #define NEIGHBOR_CMD2 "neighbor (A.B.C.D|WORD) "
341 #define NO_NEIGHBOR_CMD2 "no neighbor (A.B.C.D|WORD) "
342 #define NEIGHBOR_ADDR_STR2 "Neighbor address\nNeighbor tag\n"
343 #endif /* HAVE_IPV6 */
344 
345 /* Prototypes. */
346 void install_node(struct cmd_node *, int (*)(struct vty *));
347 void install_default(int node_type);
348 void install_element(int node_type, struct cmd_element *);
349 void install_element_ve(struct cmd_element *cmd);
350 void sort_node(void);
351 
352 /* This is similar to install_default() but it also creates
353  * 'exit' and 'end' commands.
354  */
355 void vty_install_default(int node_type);
356 
357 /* Concatenates argv[shift] through argv[argc-1] into a single NUL-terminated
358  string with a space between each element (allocated using
359  XMALLOC(MTYPE_TMP)). Returns NULL if shift >= argc. */
360 char *argv_concat(const char **argv, int argc, int shift);
361 
362 vector cmd_make_strvec(const char *);
363 void cmd_free_strvec(vector);
364 vector cmd_describe_command();
365 char **cmd_complete_command();
366 const char *cmd_prompt(enum node_type);
367 int config_from_file(struct vty *, FILE *);
368 enum node_type node_parent(enum node_type);
369 int cmd_execute_command(vector, struct vty *, struct cmd_element **, int);
370 int cmd_execute_command_strict(vector, struct vty *, struct cmd_element **);
371 void config_replace_string(struct cmd_element *, char *, ...);
372 void cmd_init(int);
373 
374 /* Export typical functions. */
375 extern struct cmd_element config_exit_cmd;
376 extern struct cmd_element config_help_cmd;
377 extern struct cmd_element config_list_cmd;
378 extern struct cmd_element config_end_cmd;
379 char *host_config_file();
380 void host_config_set(const char *);
381 
382 /* This is called from main when a daemon is invoked with -v or --version. */
383 void print_version(int print_copyright);
384 
385 extern void *tall_vty_cmd_ctx;
386 
int advanced
Flags for services.
Definition: command.h:57
const char * prompt
Prompt character at vty interface.
Definition: command.h:108
Reserved for later extensions.
Definition: command.h:94
const char * string
Command specification by string.
Definition: command.h:127
const char * cmd
Command string.
Definition: command.h:140
int daemon
Daemon to which this command belong.
Definition: command.h:130
const char * doc
Documentation of this command.
Definition: command.h:129
Definition: vty.h:50
vector cmd_make_strvec(const char *)
Definition: command.c:194
NS node in libosmo-gb.
Definition: command.h:84
char * config
Configuration string.
Definition: command.h:133
const struct vty_app_info * app_info
VTY application information.
Definition: command.h:65
char * password
Password for vty interface.
Definition: command.h:40
E1 line in libosmo-abis.
Definition: command.h:82
Configure the logging.
Definition: command.h:77
Reserved for later extensions.
Definition: command.h:91
IPA proxying commands in libosmo-abis.
Definition: command.h:83
Vty node.
Definition: command.h:80
void install_element(int node_type, struct cmd_element *)
Install a command into a node.
Definition: command.c:551
char * config
config file name of this host
Definition: command.h:54
Command description structure.
Definition: command.h:139
const char * cmd_prompt(enum node_type)
Return prompt character of specified node.
Definition: command.c:400
Host configuration variable.
Definition: command.h:35
Configure the statistics.
Definition: command.h:78
Config node. Default mode of config file.
Definition: command.h:74
void sort_node(void)
Sort each node&#39;s command element according to command string.
Definition: command.c:162
node_type
There are some command levels which called from command node.
Definition: command.h:69
Node which has some commands and prompt string and configuration function pointer ...
Definition: command.h:103
void install_node(struct cmd_node *, int(*)(struct vty *))
Install top node of command vector.
Definition: command.c:125
void cmd_free_strvec(vector)
Free allocated string vector.
Definition: command.c:242
Authentication mode of vty interface.
Definition: command.h:70
View node. Default mode of vty interface.
Definition: command.h:71
vector strvec
Pointing out each description vector.
Definition: command.h:131
int lines
System wide terminal lines.
Definition: command.h:48
char * logfile
Log filename.
Definition: command.h:51
int vtysh
Is this node&#39;s configuration goes to vtysh ?
Definition: command.h:111
const char * motd
Banner configuration.
Definition: command.h:61
vector cmd_vector
Vector of this node&#39;s command list.
Definition: command.h:117
Service node.
Definition: command.h:75
Reserved for later extensions.
Definition: command.h:93
char * enable
Enable password.
Definition: command.h:44
Structure of a command element.
Definition: command.h:126
unsigned char attr
Command attributes.
Definition: command.h:135
char * name
Host name of this router.
Definition: command.h:37
int node
Node index.
Definition: command.h:105
vector subconfig
Sub configuration string.
Definition: command.h:134
unsigned int cmdsize
Command index count.
Definition: command.h:132
void print_version(int print_copyright)
print the version (and optionally copyright) information
Definition: command.c:92
const char * str
Command&#39;s description.
Definition: command.h:141
Enable node.
Definition: command.h:73
Authentication mode for change enable.
Definition: command.h:72
Definition: vty.h:149
Reserved for later extensions.
Definition: command.h:92
BSSGP node in libosmo-gb.
Definition: command.h:85
Debug node.
Definition: command.h:76
Definition: vector.h:26