libosmovty
0.6.3
Osmocom VTY library
Main Page
Modules
Data Structures
Files
File List
Globals
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
#ifndef _ZEBRA_COMMAND_H
24
#define _ZEBRA_COMMAND_H
25
26
#include <stdio.h>
27
#include <sys/types.h>
28
#include "vector.h"
29
36
struct
host
{
38
char
*
name
;
39
41
char
*
password
;
42
char
*password_encrypt;
43
45
char
*
enable
;
46
char
*enable_encrypt;
47
49
int
lines
;
50
52
char
*
logfile
;
53
55
char
*
config
;
56
58
int
advanced
;
59
int
encrypt;
60
62
const
char
*
motd
;
63
char
*motdfile;
64
66
const
struct
vty_app_info
*
app_info
;
67
};
68
70
enum
node_type
{
71
AUTH_NODE
,
72
VIEW_NODE
,
73
AUTH_ENABLE_NODE
,
74
ENABLE_NODE
,
75
CONFIG_NODE
,
76
SERVICE_NODE
,
77
DEBUG_NODE
,
78
CFG_LOG_NODE
,
80
VTY_NODE
,
82
L_E1INP_NODE
,
83
L_IPA_NODE
,
84
L_NS_NODE
,
85
L_BSSGP_NODE
,
87
_LAST_OSMOVTY_NODE
88
};
89
90
#include "
vty.h
"
91
94
struct
cmd_node
{
96
enum
node_type
node
;
97
99
const
char
*
prompt
;
100
102
int
vtysh
;
103
105
int (*
func
) (
struct
vty
*);
106
108
vector
cmd_vector
;
109
};
110
111
enum
{
112
CMD_ATTR_DEPRECATED = 1,
113
CMD_ATTR_HIDDEN,
114
};
115
117
struct
cmd_element
{
118
const
char
*
string
;
119
int (*func) (
struct
cmd_element
*,
struct
vty
*, int,
const
char
*[]);
120
const
char
*
doc
;
121
int
daemon
;
122
vector
strvec
;
123
unsigned
int
cmdsize
;
124
char
*
config
;
125
vector
subconfig
;
126
u_char
attr
;
127
};
128
130
struct
desc
{
131
const
char
*
cmd
;
132
const
char
*
str
;
133
};
134
136
#define CMD_SUCCESS 0
137
#define CMD_WARNING 1
138
#define CMD_ERR_NO_MATCH 2
139
#define CMD_ERR_AMBIGUOUS 3
140
#define CMD_ERR_INCOMPLETE 4
141
#define CMD_ERR_EXEED_ARGC_MAX 5
142
#define CMD_ERR_NOTHING_TODO 6
143
#define CMD_COMPLETE_FULL_MATCH 7
144
#define CMD_COMPLETE_MATCH 8
145
#define CMD_COMPLETE_LIST_MATCH 9
146
#define CMD_SUCCESS_DAEMON 10
147
148
/* Argc max counts. */
149
#define CMD_ARGC_MAX 256
150
151
/* Turn off these macros when uisng cpp with extract.pl */
152
#ifndef VTYSH_EXTRACT_PL
153
154
/* helper defines for end-user DEFUN* macros */
155
#define DEFUN_CMD_ELEMENT(funcname, cmdname, cmdstr, helpstr, attrs, dnum) \
156
static struct cmd_element cmdname = \
157
{ \
158
.string = cmdstr, \
159
.func = funcname, \
160
.doc = helpstr, \
161
.attr = attrs, \
162
.daemon = dnum, \
163
};
164
165
/* global (non static) cmd_element */
166
#define gDEFUN_CMD_ELEMENT(funcname, cmdname, cmdstr, helpstr, attrs, dnum) \
167
struct cmd_element cmdname = \
168
{ \
169
.string = cmdstr, \
170
.func = funcname, \
171
.doc = helpstr, \
172
.attr = attrs, \
173
.daemon = dnum, \
174
};
175
176
#define DEFUN_CMD_FUNC_DECL(funcname) \
177
static int funcname (struct cmd_element *, struct vty *, int, const char *[]); \
178
179
#define DEFUN_CMD_FUNC_TEXT(funcname) \
180
static int funcname \
181
(struct cmd_element *self, struct vty *vty, int argc, const char *argv[])
182
189
#define DEFUN(funcname, cmdname, cmdstr, helpstr) \
190
DEFUN_CMD_FUNC_DECL(funcname) \
191
DEFUN_CMD_ELEMENT(funcname, cmdname, cmdstr, helpstr, 0, 0) \
192
DEFUN_CMD_FUNC_TEXT(funcname)
193
200
#define gDEFUN(funcname, cmdname, cmdstr, helpstr) \
201
DEFUN_CMD_FUNC_DECL(funcname) \
202
gDEFUN_CMD_ELEMENT(funcname, cmdname, cmdstr, helpstr, 0, 0) \
203
DEFUN_CMD_FUNC_TEXT(funcname)
204
205
#define DEFUN_ATTR(funcname, cmdname, cmdstr, helpstr, attr) \
206
DEFUN_CMD_FUNC_DECL(funcname) \
207
DEFUN_CMD_ELEMENT(funcname, cmdname, cmdstr, helpstr, attr, 0) \
208
DEFUN_CMD_FUNC_TEXT(funcname)
209
210
#define DEFUN_HIDDEN(funcname, cmdname, cmdstr, helpstr) \
211
DEFUN_ATTR (funcname, cmdname, cmdstr, helpstr, CMD_ATTR_HIDDEN)
212
213
#define DEFUN_DEPRECATED(funcname, cmdname, cmdstr, helpstr) \
214
DEFUN_ATTR (funcname, cmdname, cmdstr, helpstr, CMD_ATTR_DEPRECATED) \
215
216
/* DEFUN_NOSH for commands that vtysh should ignore */
217
#define DEFUN_NOSH(funcname, cmdname, cmdstr, helpstr) \
218
DEFUN(funcname, cmdname, cmdstr, helpstr)
219
220
/* DEFSH for vtysh. */
221
#define DEFSH(daemon, cmdname, cmdstr, helpstr) \
222
DEFUN_CMD_ELEMENT(NULL, cmdname, cmdstr, helpstr, 0, daemon) \
223
224
/* DEFUN + DEFSH */
225
#define DEFUNSH(daemon, funcname, cmdname, cmdstr, helpstr) \
226
DEFUN_CMD_FUNC_DECL(funcname) \
227
DEFUN_CMD_ELEMENT(funcname, cmdname, cmdstr, helpstr, 0, daemon) \
228
DEFUN_CMD_FUNC_TEXT(funcname)
229
230
/* DEFUN + DEFSH with attributes */
231
#define DEFUNSH_ATTR(daemon, funcname, cmdname, cmdstr, helpstr, attr) \
232
DEFUN_CMD_FUNC_DECL(funcname) \
233
DEFUN_CMD_ELEMENT(funcname, cmdname, cmdstr, helpstr, attr, daemon) \
234
DEFUN_CMD_FUNC_TEXT(funcname)
235
236
#define DEFUNSH_HIDDEN(daemon, funcname, cmdname, cmdstr, helpstr) \
237
DEFUNSH_ATTR (daemon, funcname, cmdname, cmdstr, helpstr, CMD_ATTR_HIDDEN)
238
239
#define DEFUNSH_DEPRECATED(daemon, funcname, cmdname, cmdstr, helpstr) \
240
DEFUNSH_ATTR (daemon, funcname, cmdname, cmdstr, helpstr, CMD_ATTR_DEPRECATED)
241
242
/* ALIAS macro which define existing command's alias. */
243
#define ALIAS(funcname, cmdname, cmdstr, helpstr) \
244
DEFUN_CMD_ELEMENT(funcname, cmdname, cmdstr, helpstr, 0, 0)
245
246
/* global (non static) cmd_element */
247
#define gALIAS(funcname, cmdname, cmdstr, helpstr) \
248
gDEFUN_CMD_ELEMENT(funcname, cmdname, cmdstr, helpstr, 0, 0)
249
250
#define ALIAS_ATTR(funcname, cmdname, cmdstr, helpstr, attr) \
251
DEFUN_CMD_ELEMENT(funcname, cmdname, cmdstr, helpstr, attr, 0)
252
253
#define ALIAS_HIDDEN(funcname, cmdname, cmdstr, helpstr) \
254
DEFUN_CMD_ELEMENT(funcname, cmdname, cmdstr, helpstr, CMD_ATTR_HIDDEN, 0)
255
256
#define ALIAS_DEPRECATED(funcname, cmdname, cmdstr, helpstr) \
257
DEFUN_CMD_ELEMENT(funcname, cmdname, cmdstr, helpstr, CMD_ATTR_DEPRECATED, 0)
258
259
#define ALIAS_SH(daemon, funcname, cmdname, cmdstr, helpstr) \
260
DEFUN_CMD_ELEMENT(funcname, cmdname, cmdstr, helpstr, 0, daemon)
261
262
#define ALIAS_SH_HIDDEN(daemon, funcname, cmdname, cmdstr, helpstr) \
263
DEFUN_CMD_ELEMENT(funcname, cmdname, cmdstr, helpstr, CMD_ATTR_HIDDEN, daemon)
264
265
#define ALIAS_SH_DEPRECATED(daemon, funcname, cmdname, cmdstr, helpstr) \
266
DEFUN_CMD_ELEMENT(funcname, cmdname, cmdstr, helpstr, CMD_ATTR_DEPRECATED, daemon)
267
268
#endif
/* VTYSH_EXTRACT_PL */
269
270
/* Some macroes */
271
#define CMD_OPTION(S) ((S[0]) == '[')
272
#define CMD_VARIABLE(S) (((S[0]) >= 'A' && (S[0]) <= 'Z') || ((S[0]) == '<'))
273
#define CMD_VARARG(S) ((S[0]) == '.')
274
#define CMD_RANGE(S) ((S[0] == '<'))
275
276
#define CMD_IPV4(S) ((strcmp ((S), "A.B.C.D") == 0))
277
#define CMD_IPV4_PREFIX(S) ((strcmp ((S), "A.B.C.D/M") == 0))
278
#define CMD_IPV6(S) ((strcmp ((S), "X:X::X:X") == 0))
279
#define CMD_IPV6_PREFIX(S) ((strcmp ((S), "X:X::X:X/M") == 0))
280
281
/* Common descriptions. */
282
#define SHOW_STR "Show running system information\n"
283
#define IP_STR "IP information\n"
284
#define IPV6_STR "IPv6 information\n"
285
#define NO_STR "Negate a command or set its defaults\n"
286
#define CLEAR_STR "Reset functions\n"
287
#define RIP_STR "RIP information\n"
288
#define BGP_STR "BGP information\n"
289
#define OSPF_STR "OSPF information\n"
290
#define NEIGHBOR_STR "Specify neighbor router\n"
291
#define DEBUG_STR "Debugging functions (see also 'undebug')\n"
292
#define UNDEBUG_STR "Disable debugging functions (see also 'debug')\n"
293
#define ROUTER_STR "Enable a routing process\n"
294
#define AS_STR "AS number\n"
295
#define MBGP_STR "MBGP information\n"
296
#define MATCH_STR "Match values from routing table\n"
297
#define SET_STR "Set values in destination routing protocol\n"
298
#define OUT_STR "Filter outgoing routing updates\n"
299
#define IN_STR "Filter incoming routing updates\n"
300
#define V4NOTATION_STR "specify by IPv4 address notation(e.g. 0.0.0.0)\n"
301
#define OSPF6_NUMBER_STR "Specify by number\n"
302
#define INTERFACE_STR "Interface infomation\n"
303
#define IFNAME_STR "Interface name(e.g. ep0)\n"
304
#define IP6_STR "IPv6 Information\n"
305
#define OSPF6_STR "Open Shortest Path First (OSPF) for IPv6\n"
306
#define OSPF6_ROUTER_STR "Enable a routing process\n"
307
#define OSPF6_INSTANCE_STR "<1-65535> Instance ID\n"
308
#define SECONDS_STR "<1-65535> Seconds\n"
309
#define ROUTE_STR "Routing Table\n"
310
#define PREFIX_LIST_STR "Build a prefix list\n"
311
#define OSPF6_DUMP_TYPE_LIST \
312
"(neighbor|interface|area|lsa|zebra|config|dbex|spf|route|lsdb|redistribute|hook|asbr|prefix|abr)"
313
#define ISIS_STR "IS-IS information\n"
314
#define AREA_TAG_STR "[area tag]\n"
315
316
#define CONF_BACKUP_EXT ".sav"
317
318
/* IPv4 only machine should not accept IPv6 address for peer's IP
319
address. So we replace VTY command string like below. */
320
#ifdef HAVE_IPV6
321
#define NEIGHBOR_CMD "neighbor (A.B.C.D|X:X::X:X) "
322
#define NO_NEIGHBOR_CMD "no neighbor (A.B.C.D|X:X::X:X) "
323
#define NEIGHBOR_ADDR_STR "Neighbor address\nIPv6 address\n"
324
#define NEIGHBOR_CMD2 "neighbor (A.B.C.D|X:X::X:X|WORD) "
325
#define NO_NEIGHBOR_CMD2 "no neighbor (A.B.C.D|X:X::X:X|WORD) "
326
#define NEIGHBOR_ADDR_STR2 "Neighbor address\nNeighbor IPv6 address\nNeighbor tag\n"
327
#else
328
#define NEIGHBOR_CMD "neighbor A.B.C.D "
329
#define NO_NEIGHBOR_CMD "no neighbor A.B.C.D "
330
#define NEIGHBOR_ADDR_STR "Neighbor address\n"
331
#define NEIGHBOR_CMD2 "neighbor (A.B.C.D|WORD) "
332
#define NO_NEIGHBOR_CMD2 "no neighbor (A.B.C.D|WORD) "
333
#define NEIGHBOR_ADDR_STR2 "Neighbor address\nNeighbor tag\n"
334
#endif
/* HAVE_IPV6 */
335
336
/* Prototypes. */
337
void
install_node
(
struct
cmd_node
*,
int
(*)(
struct
vty
*));
338
void
install_default(
enum
node_type
);
339
void
install_element
(
enum
node_type
,
struct
cmd_element
*);
340
void
install_element_ve(
struct
cmd_element
*cmd);
341
void
sort_node
(
void
);
342
343
/* Concatenates argv[shift] through argv[argc-1] into a single NUL-terminated
344
string with a space between each element (allocated using
345
XMALLOC(MTYPE_TMP)). Returns NULL if shift >= argc. */
346
char
*argv_concat(
const
char
**argv,
int
argc,
int
shift);
347
348
vector
cmd_make_strvec
(
const
char
*);
349
void
cmd_free_strvec
(
vector
);
350
vector
cmd_describe_command();
351
char
**cmd_complete_command();
352
const
char
*
cmd_prompt
(
enum
node_type
);
353
int
config_from_file(
struct
vty
*, FILE *);
354
enum
node_type
node_parent(
enum
node_type
);
355
int
cmd_execute_command(
vector
,
struct
vty
*,
struct
cmd_element
**,
int
);
356
int
cmd_execute_command_strict(
vector
,
struct
vty
*,
struct
cmd_element
**);
357
void
config_replace_string(
struct
cmd_element
*,
char
*, ...);
358
void
cmd_init(
int
);
359
360
/* Export typical functions. */
361
extern
struct
cmd_element
config_exit_cmd;
362
extern
struct
cmd_element
config_help_cmd;
363
extern
struct
cmd_element
config_list_cmd;
364
extern
struct
cmd_element
config_end_cmd;
365
char
*host_config_file();
366
void
host_config_set(
const
char
*);
367
368
/* This is called from main when a daemon is invoked with -v or --version. */
369
void
print_version
(
int
print_copyright);
370
371
extern
void
*tall_vty_cmd_ctx;
372
374
#endif
/* _ZEBRA_COMMAND_H */
include
osmocom
vty
command.h
Generated on Fri Aug 23 2013 20:51:44 for libosmovty by
1.8.1.2