]>
Commit | Line | Data |
---|---|---|
718e3744 | 1 | /* Virtual terminal interface shell. |
2 | * Copyright (C) 2000 Kunihiro Ishiguro | |
3 | * | |
4 | * This file is part of GNU Zebra. | |
5 | * | |
6 | * GNU Zebra is free software; you can redistribute it and/or modify it | |
7 | * under the terms of the GNU General Public License as published by the | |
8 | * Free Software Foundation; either version 2, or (at your option) any | |
9 | * later version. | |
10 | * | |
11 | * GNU Zebra is distributed in the hope that it will be useful, but | |
12 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 | * General Public License for more details. | |
15 | * | |
16 | * You should have received a copy of the GNU General Public License | |
17 | * along with GNU Zebra; see the file COPYING. If not, write to the Free | |
18 | * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA | |
19 | * 02111-1307, USA. | |
20 | */ | |
21 | ||
22 | #include <zebra.h> | |
23 | ||
24 | #include <sys/un.h> | |
25 | #include <setjmp.h> | |
26 | #include <sys/wait.h> | |
27 | #include <sys/resource.h> | |
28 | #include <sys/stat.h> | |
29 | ||
30 | #include <readline/readline.h> | |
31 | #include <readline/history.h> | |
32 | ||
7c8ff89e DS |
33 | #include <dirent.h> |
34 | #include <stdio.h> | |
35 | #include <string.h> | |
36 | ||
4201dd11 | 37 | #include "linklist.h" |
718e3744 | 38 | #include "command.h" |
39 | #include "memory.h" | |
039f3a34 | 40 | #include "filter.h" |
718e3744 | 41 | #include "vtysh/vtysh.h" |
6099b3b5 | 42 | #include "log.h" |
320da874 | 43 | #include "bgpd/bgp_vty.h" |
13460c44 | 44 | #include "ns.h" |
cd2a8a42 | 45 | #include "vrf.h" |
718e3744 | 46 | |
4a1ab8e4 DL |
47 | DEFINE_MTYPE_STATIC(MVTYSH, VTYSH_CMD, "Vtysh cmd copy") |
48 | ||
718e3744 | 49 | /* Struct VTY. */ |
50 | struct vty *vty; | |
51 | ||
52 | /* VTY shell pager name. */ | |
53 | char *vtysh_pager_name = NULL; | |
54 | ||
55 | /* VTY shell client structure. */ | |
56 | struct vtysh_client | |
57 | { | |
58 | int fd; | |
c0e8c16f | 59 | const char *name; |
b1aa147d | 60 | int flag; |
c0e8c16f | 61 | const char *path; |
7c8ff89e DS |
62 | struct vtysh_client *next; |
63 | }; | |
64 | ||
65 | struct vtysh_client vtysh_client[] = | |
66 | { | |
67 | { .fd = -1, .name = "zebra", .flag = VTYSH_ZEBRA, .path = ZEBRA_VTYSH_PATH, .next = NULL}, | |
68 | { .fd = -1, .name = "ripd", .flag = VTYSH_RIPD, .path = RIP_VTYSH_PATH, .next = NULL}, | |
69 | { .fd = -1, .name = "ripngd", .flag = VTYSH_RIPNGD, .path = RIPNG_VTYSH_PATH, .next = NULL}, | |
70 | { .fd = -1, .name = "ospfd", .flag = VTYSH_OSPFD, .path = OSPF_VTYSH_PATH, .next = NULL}, | |
71 | { .fd = -1, .name = "ospf6d", .flag = VTYSH_OSPF6D, .path = OSPF6_VTYSH_PATH, .next = NULL}, | |
4fcbf6e2 | 72 | { .fd = -1, .name = "ldpd", .flag = VTYSH_LDPD, .path = LDP_VTYSH_PATH, .next = NULL}, |
7c8ff89e DS |
73 | { .fd = -1, .name = "bgpd", .flag = VTYSH_BGPD, .path = BGP_VTYSH_PATH, .next = NULL}, |
74 | { .fd = -1, .name = "isisd", .flag = VTYSH_ISISD, .path = ISIS_VTYSH_PATH, .next = NULL}, | |
12e41d03 | 75 | { .fd = -1, .name = "pimd", .flag = VTYSH_PIMD, .path = PIM_VTYSH_PATH, .next = NULL}, |
4a96e944 | 76 | { .fd = -1, .name = "watchquagga", .flag = VTYSH_WATCHQUAGGA, .path = WATCHQUAGGA_VTYSH_PATH, .next = NULL}, |
b1aa147d | 77 | }; |
78 | ||
039eaca3 | 79 | enum vtysh_write_integrated vtysh_write_integrated = WRITE_INTEGRATED_UNSPECIFIED; |
e7168df4 | 80 | |
274a4a44 | 81 | static void |
718e3744 | 82 | vclient_close (struct vtysh_client *vclient) |
83 | { | |
b1aa147d | 84 | if (vclient->fd >= 0) |
85 | { | |
86 | fprintf(stderr, | |
87 | "Warning: closing connection to %s because of an I/O error!\n", | |
88 | vclient->name); | |
89 | close (vclient->fd); | |
90 | vclient->fd = -1; | |
91 | } | |
718e3744 | 92 | } |
93 | ||
f35a5350 DW |
94 | /* Return true if str begins with prefix, else return false */ |
95 | static int | |
96 | begins_with(const char *str, const char *prefix) | |
97 | { | |
98 | if (!str || !prefix) | |
99 | return 0; | |
100 | size_t lenstr = strlen(str); | |
101 | size_t lenprefix = strlen(prefix); | |
102 | if (lenprefix > lenstr) | |
103 | return 0; | |
104 | return strncmp(str, prefix, lenprefix) == 0; | |
105 | } | |
106 | ||
7526a182 DL |
107 | /* NB: multiplexed function: |
108 | * if fp == NULL, this calls vtysh_config_parse_line | |
109 | * if fp != NULL, this prints lines to fp | |
110 | */ | |
274a4a44 | 111 | static int |
7526a182 | 112 | vtysh_client_run (struct vtysh_client *vclient, const char *line, FILE *fp) |
718e3744 | 113 | { |
114 | int ret; | |
7526a182 DL |
115 | char stackbuf[4096]; |
116 | char *buf = stackbuf; | |
117 | size_t bufsz = sizeof(stackbuf); | |
118 | char *bufvalid, *end = NULL; | |
119 | char terminator[3] = {0, 0, 0}; | |
718e3744 | 120 | |
121 | if (vclient->fd < 0) | |
122 | return CMD_SUCCESS; | |
123 | ||
124 | ret = write (vclient->fd, line, strlen (line) + 1); | |
125 | if (ret <= 0) | |
7526a182 | 126 | goto out_err; |
7c8ff89e | 127 | |
7526a182 DL |
128 | bufvalid = buf; |
129 | do | |
7c8ff89e | 130 | { |
7526a182 DL |
131 | ssize_t nread = read (vclient->fd, bufvalid, buf + bufsz - bufvalid); |
132 | ||
133 | if (nread < 0 && (errno == EINTR || errno == EAGAIN)) | |
134 | continue; | |
135 | ||
136 | if (nread <= 0) | |
137 | { | |
138 | fprintf (stderr, "vtysh: error reading from %s: %s (%d)", | |
139 | vclient->name, safe_strerror(errno), errno); | |
140 | goto out_err; | |
141 | } | |
142 | ||
143 | bufvalid += nread; | |
144 | ||
145 | end = memmem (buf, bufvalid - buf, terminator, sizeof(terminator)); | |
146 | if (end + sizeof(terminator) + 1 > bufvalid) | |
147 | /* found \0\0\0 but return code hasn't been read yet */ | |
148 | end = NULL; | |
149 | if (end) | |
150 | ret = end[sizeof(terminator)]; | |
151 | ||
152 | while (bufvalid > buf && (end > buf || !end)) | |
153 | { | |
154 | size_t textlen = (end ? end : bufvalid) - buf; | |
155 | char *eol = memchr (buf, '\n', textlen); | |
156 | if (eol) | |
157 | /* line break */ | |
158 | *eol++ = '\0'; | |
159 | else if (end == buf) | |
160 | /* no line break, end of input, no text left before end | |
161 | * => don't insert an empty line at the end */ | |
162 | break; | |
163 | else if (end) | |
164 | /* no line break, end of input, but some text left */ | |
165 | eol = end; | |
166 | else | |
167 | /* continue reading */ | |
168 | break; | |
718e3744 | 169 | |
7526a182 DL |
170 | /* eol is at a line end now, either \n => \0 or \0\0\0 */ |
171 | assert(eol && eol <= bufvalid); | |
718e3744 | 172 | |
7526a182 | 173 | if (fp) |
2852de1c | 174 | { |
7526a182 DL |
175 | fputs (buf, fp); |
176 | fputc ('\n', fp); | |
2852de1c | 177 | } |
178 | else | |
7526a182 DL |
179 | vtysh_config_parse_line (buf); |
180 | ||
181 | if (eol == end) | |
182 | /* \n\0\0\0 */ | |
183 | break; | |
184 | ||
185 | memmove (buf, eol, bufvalid - eol); | |
186 | bufvalid -= eol - buf; | |
2d35a720 DL |
187 | if (end) |
188 | end -= eol - buf; | |
7526a182 DL |
189 | } |
190 | ||
191 | if (bufvalid == buf + bufsz) | |
192 | { | |
193 | char *new; | |
194 | bufsz *= 2; | |
195 | if (buf == stackbuf) | |
2852de1c | 196 | { |
7526a182 DL |
197 | new = XMALLOC (MTYPE_TMP, bufsz); |
198 | memcpy (new, stackbuf, sizeof(stackbuf)); | |
2852de1c | 199 | } |
7526a182 DL |
200 | else |
201 | new = XREALLOC (MTYPE_TMP, buf, bufsz); | |
2852de1c | 202 | |
7526a182 DL |
203 | bufvalid = bufvalid - buf + new; |
204 | buf = new; | |
205 | /* if end != NULL, we won't be reading more data... */ | |
206 | assert (end == NULL); | |
207 | } | |
718e3744 | 208 | } |
7526a182 DL |
209 | while (!end); |
210 | goto out; | |
211 | ||
212 | out_err: | |
213 | vclient_close (vclient); | |
214 | ret = CMD_SUCCESS; | |
215 | out: | |
216 | if (buf != stackbuf) | |
217 | XFREE (MTYPE_TMP, buf); | |
218 | return ret; | |
718e3744 | 219 | } |
220 | ||
7c8ff89e | 221 | static int |
7526a182 DL |
222 | vtysh_client_run_all (struct vtysh_client *head_client, const char *line, |
223 | int continue_on_err, FILE *fp) | |
7c8ff89e DS |
224 | { |
225 | struct vtysh_client *client; | |
7526a182 | 226 | int rc, rc_all = CMD_SUCCESS; |
7c8ff89e | 227 | |
7526a182 | 228 | for (client = head_client; client; client = client->next) |
7c8ff89e | 229 | { |
7526a182 | 230 | rc = vtysh_client_run(client, line, fp); |
7c8ff89e | 231 | if (rc != CMD_SUCCESS) |
7526a182 DL |
232 | { |
233 | if (!continue_on_err) | |
234 | return rc; | |
235 | rc_all = rc; | |
236 | } | |
7c8ff89e | 237 | } |
7526a182 DL |
238 | return rc_all; |
239 | } | |
240 | ||
241 | static int | |
242 | vtysh_client_execute (struct vtysh_client *head_client, const char *line, | |
243 | FILE *fp) | |
244 | { | |
245 | return vtysh_client_run_all (head_client, line, 0, fp); | |
246 | } | |
247 | ||
248 | static void | |
249 | vtysh_client_config (struct vtysh_client *head_client, char *line) | |
250 | { | |
251 | vtysh_client_run_all (head_client, line, 1, NULL); | |
7c8ff89e DS |
252 | } |
253 | ||
718e3744 | 254 | void |
b1aa147d | 255 | vtysh_pager_init (void) |
718e3744 | 256 | { |
5a9c53de | 257 | char *pager_defined; |
258 | ||
259 | pager_defined = getenv ("VTYSH_PAGER"); | |
260 | ||
261 | if (pager_defined) | |
262 | vtysh_pager_name = strdup (pager_defined); | |
263 | else | |
34553cc3 | 264 | vtysh_pager_name = strdup ("more"); |
718e3744 | 265 | } |
266 | ||
267 | /* Command execution over the vty interface. */ | |
57fb9748 | 268 | static int |
dda09522 | 269 | vtysh_execute_func (const char *line, int pager) |
718e3744 | 270 | { |
2c4d48bc | 271 | int ret, cmd_stat; |
b1aa147d | 272 | u_int i; |
718e3744 | 273 | vector vline; |
17aca20b | 274 | const struct cmd_element *cmd; |
718e3744 | 275 | FILE *fp = NULL; |
13bfca7a | 276 | int closepager = 0; |
277 | int tried = 0; | |
278 | int saved_ret, saved_node; | |
718e3744 | 279 | |
95e735b5 | 280 | /* Split readline string up into the vector. */ |
718e3744 | 281 | vline = cmd_make_strvec (line); |
282 | ||
283 | if (vline == NULL) | |
57fb9748 | 284 | return CMD_SUCCESS; |
718e3744 | 285 | |
13bfca7a | 286 | saved_ret = ret = cmd_execute_command (vline, vty, &cmd, 1); |
287 | saved_node = vty->node; | |
288 | ||
289 | /* If command doesn't succeeded in current node, try to walk up in node tree. | |
290 | * Changing vty->node is enough to try it just out without actual walkup in | |
291 | * the vtysh. */ | |
292 | while (ret != CMD_SUCCESS && ret != CMD_SUCCESS_DAEMON && ret != CMD_WARNING | |
293 | && vty->node > CONFIG_NODE) | |
294 | { | |
295 | vty->node = node_parent(vty->node); | |
296 | ret = cmd_execute_command (vline, vty, &cmd, 1); | |
297 | tried++; | |
298 | } | |
299 | ||
300 | vty->node = saved_node; | |
301 | ||
302 | /* If command succeeded in any other node than current (tried > 0) we have | |
303 | * to move into node in the vtysh where it succeeded. */ | |
304 | if (ret == CMD_SUCCESS || ret == CMD_SUCCESS_DAEMON || ret == CMD_WARNING) | |
305 | { | |
bb86c601 | 306 | if ((saved_node == BGP_VPNV4_NODE || saved_node == BGP_VPNV6_NODE |
8b1fb8be | 307 | || saved_node == BGP_ENCAP_NODE || saved_node == BGP_ENCAPV6_NODE |
8ecd3266 | 308 | || saved_node == BGP_IPV4_NODE |
57b5b7ed | 309 | || saved_node == BGP_IPV6_NODE || saved_node == BGP_IPV4M_NODE |
310 | || saved_node == BGP_IPV6M_NODE) | |
13bfca7a | 311 | && (tried == 1)) |
312 | { | |
313 | vtysh_execute("exit-address-family"); | |
314 | } | |
65efcfce LB |
315 | else if ((saved_node == BGP_VNC_DEFAULTS_NODE |
316 | || saved_node == BGP_VNC_NVE_GROUP_NODE | |
317 | || saved_node == BGP_VNC_L2_GROUP_NODE) && (tried == 1)) | |
318 | { | |
319 | vtysh_execute("exit-vnc"); | |
320 | } | |
13bfca7a | 321 | else if ((saved_node == KEYCHAIN_KEY_NODE) && (tried == 1)) |
322 | { | |
323 | vtysh_execute("exit"); | |
324 | } | |
325 | else if (tried) | |
326 | { | |
327 | vtysh_execute ("end"); | |
328 | vtysh_execute ("configure terminal"); | |
329 | } | |
330 | } | |
331 | /* If command didn't succeed in any node, continue with return value from | |
332 | * first try. */ | |
333 | else if (tried) | |
334 | { | |
335 | ret = saved_ret; | |
336 | } | |
718e3744 | 337 | |
338 | cmd_free_strvec (vline); | |
339 | ||
2c4d48bc | 340 | cmd_stat = ret; |
718e3744 | 341 | switch (ret) |
342 | { | |
343 | case CMD_WARNING: | |
344 | if (vty->type == VTY_FILE) | |
4fc01e67 | 345 | fprintf (stdout,"Warning...\n"); |
718e3744 | 346 | break; |
347 | case CMD_ERR_AMBIGUOUS: | |
4fc01e67 | 348 | fprintf (stdout,"%% Ambiguous command.\n"); |
718e3744 | 349 | break; |
350 | case CMD_ERR_NO_MATCH: | |
4fc01e67 | 351 | fprintf (stdout,"%% Unknown command.\n"); |
718e3744 | 352 | break; |
353 | case CMD_ERR_INCOMPLETE: | |
4fc01e67 | 354 | fprintf (stdout,"%% Command incomplete.\n"); |
718e3744 | 355 | break; |
356 | case CMD_SUCCESS_DAEMON: | |
357 | { | |
97b7db2d | 358 | /* FIXME: Don't open pager for exit commands. popen() causes problems |
359 | * if exited from vtysh at all. This hack shouldn't cause any problem | |
360 | * but is really ugly. */ | |
361 | if (pager && vtysh_pager_name && (strncmp(line, "exit", 4) != 0)) | |
718e3744 | 362 | { |
4fc01e67 | 363 | fp = popen (vtysh_pager_name, "w"); |
718e3744 | 364 | if (fp == NULL) |
365 | { | |
a805cc2d | 366 | perror ("popen failed for pager"); |
367 | fp = stdout; | |
718e3744 | 368 | } |
a805cc2d | 369 | else |
370 | closepager=1; | |
718e3744 | 371 | } |
372 | else | |
373 | fp = stdout; | |
374 | ||
375 | if (! strcmp(cmd->string,"configure terminal")) | |
376 | { | |
837d16cc | 377 | for (i = 0; i < array_size(vtysh_client); i++) |
b1aa147d | 378 | { |
379 | cmd_stat = vtysh_client_execute(&vtysh_client[i], line, fp); | |
380 | if (cmd_stat == CMD_WARNING) | |
381 | break; | |
382 | } | |
383 | ||
718e3744 | 384 | if (cmd_stat) |
385 | { | |
b094d260 | 386 | line = "end"; |
387 | vline = cmd_make_strvec (line); | |
718e3744 | 388 | |
b094d260 | 389 | if (vline == NULL) |
718e3744 | 390 | { |
a805cc2d | 391 | if (pager && vtysh_pager_name && fp && closepager) |
718e3744 | 392 | { |
393 | if (pclose (fp) == -1) | |
394 | { | |
a805cc2d | 395 | perror ("pclose failed for pager"); |
718e3744 | 396 | } |
397 | fp = NULL; | |
398 | } | |
57fb9748 | 399 | return CMD_SUCCESS; |
718e3744 | 400 | } |
401 | ||
87d683b0 | 402 | ret = cmd_execute_command (vline, vty, &cmd, 1); |
b094d260 | 403 | cmd_free_strvec (vline); |
404 | if (ret != CMD_SUCCESS_DAEMON) | |
405 | break; | |
718e3744 | 406 | } |
407 | else | |
408 | if (cmd->func) | |
409 | { | |
410 | (*cmd->func) (cmd, vty, 0, NULL); | |
411 | break; | |
b094d260 | 412 | } |
718e3744 | 413 | } |
414 | ||
b1aa147d | 415 | cmd_stat = CMD_SUCCESS; |
837d16cc | 416 | for (i = 0; i < array_size(vtysh_client); i++) |
b1aa147d | 417 | { |
418 | if (cmd->daemon & vtysh_client[i].flag) | |
419 | { | |
420 | cmd_stat = vtysh_client_execute(&vtysh_client[i], line, fp); | |
421 | if (cmd_stat != CMD_SUCCESS) | |
422 | break; | |
423 | } | |
424 | } | |
425 | if (cmd_stat != CMD_SUCCESS) | |
426 | break; | |
427 | ||
718e3744 | 428 | if (cmd->func) |
429 | (*cmd->func) (cmd, vty, 0, NULL); | |
430 | } | |
431 | } | |
a805cc2d | 432 | if (pager && vtysh_pager_name && fp && closepager) |
718e3744 | 433 | { |
434 | if (pclose (fp) == -1) | |
435 | { | |
a805cc2d | 436 | perror ("pclose failed for pager"); |
718e3744 | 437 | } |
438 | fp = NULL; | |
439 | } | |
57fb9748 | 440 | return cmd_stat; |
718e3744 | 441 | } |
442 | ||
57fb9748 | 443 | int |
dda09522 | 444 | vtysh_execute_no_pager (const char *line) |
718e3744 | 445 | { |
57fb9748 | 446 | return vtysh_execute_func (line, 0); |
718e3744 | 447 | } |
448 | ||
57fb9748 | 449 | int |
dda09522 | 450 | vtysh_execute (const char *line) |
718e3744 | 451 | { |
57fb9748 | 452 | return vtysh_execute_func (line, 1); |
718e3744 | 453 | } |
454 | ||
a5b89524 DW |
455 | static char * |
456 | trim (char *s) | |
457 | { | |
458 | size_t size; | |
459 | char *end; | |
460 | ||
461 | size = strlen(s); | |
462 | ||
463 | if (!size) | |
464 | return s; | |
465 | ||
466 | end = s + size - 1; | |
467 | while (end >= s && isspace(*end)) | |
468 | end--; | |
469 | *(end + 1) = '\0'; | |
470 | ||
471 | while (*s && isspace(*s)) | |
472 | s++; | |
473 | ||
474 | return s; | |
475 | } | |
476 | ||
0846286b | 477 | int |
c0e8c16f | 478 | vtysh_mark_file (const char *filename) |
0846286b DS |
479 | { |
480 | struct vty *vty; | |
481 | FILE *confp = NULL; | |
482 | int ret; | |
483 | vector vline; | |
484 | int tried = 0; | |
17aca20b | 485 | const struct cmd_element *cmd; |
0846286b DS |
486 | int saved_ret, prev_node; |
487 | int lineno = 0; | |
a5b89524 DW |
488 | char *vty_buf_copy = NULL; |
489 | char *vty_buf_trimmed = NULL; | |
0846286b DS |
490 | |
491 | if (strncmp("-", filename, 1) == 0) | |
492 | confp = stdin; | |
493 | else | |
494 | confp = fopen (filename, "r"); | |
495 | ||
496 | if (confp == NULL) | |
1db63918 DS |
497 | { |
498 | fprintf (stderr, "%% Can't open config file %s due to '%s'.\n", | |
499 | filename, safe_strerror (errno)); | |
500 | return (CMD_ERR_NO_FILE); | |
501 | } | |
0846286b DS |
502 | |
503 | vty = vty_new (); | |
504 | vty->fd = 0; /* stdout */ | |
505 | vty->type = VTY_TERM; | |
506 | vty->node = CONFIG_NODE; | |
507 | ||
508 | vtysh_execute_no_pager ("enable"); | |
509 | vtysh_execute_no_pager ("configure terminal"); | |
4a1ab8e4 | 510 | vty_buf_copy = XCALLOC (MTYPE_VTYSH_CMD, VTY_BUFSIZ); |
0846286b DS |
511 | |
512 | while (fgets (vty->buf, VTY_BUFSIZ, confp)) | |
513 | { | |
514 | lineno++; | |
515 | tried = 0; | |
a5b89524 DW |
516 | strcpy(vty_buf_copy, vty->buf); |
517 | vty_buf_trimmed = trim(vty_buf_copy); | |
0846286b | 518 | |
a5b89524 | 519 | if (vty_buf_trimmed[0] == '!' || vty_buf_trimmed[0] == '#') |
0846286b DS |
520 | { |
521 | fprintf(stdout, "%s", vty->buf); | |
522 | continue; | |
523 | } | |
524 | ||
525 | /* Split readline string up into the vector. */ | |
526 | vline = cmd_make_strvec (vty->buf); | |
527 | ||
528 | if (vline == NULL) | |
529 | { | |
530 | fprintf(stdout, "%s", vty->buf); | |
531 | continue; | |
532 | } | |
533 | ||
a5b89524 DW |
534 | /* Ignore the "end" lines, we will generate these where appropriate */ |
535 | if (strlen(vty_buf_trimmed) == 3 && strncmp("end", vty_buf_trimmed, 3) == 0) | |
536 | { | |
537 | continue; | |
538 | } | |
539 | ||
0846286b DS |
540 | prev_node = vty->node; |
541 | saved_ret = ret = cmd_execute_command_strict (vline, vty, &cmd); | |
542 | ||
543 | /* If command doesn't succeeded in current node, try to walk up in node tree. | |
544 | * Changing vty->node is enough to try it just out without actual walkup in | |
545 | * the vtysh. */ | |
546 | while (ret != CMD_SUCCESS && ret != CMD_SUCCESS_DAEMON && ret != CMD_WARNING | |
547 | && vty->node > CONFIG_NODE) | |
548 | { | |
549 | vty->node = node_parent(vty->node); | |
550 | ret = cmd_execute_command_strict (vline, vty, &cmd); | |
551 | tried++; | |
552 | } | |
553 | ||
554 | /* If command succeeded in any other node than current (tried > 0) we have | |
555 | * to move into node in the vtysh where it succeeded. */ | |
556 | if (ret == CMD_SUCCESS || ret == CMD_SUCCESS_DAEMON || ret == CMD_WARNING) | |
557 | { | |
558 | if ((prev_node == BGP_VPNV4_NODE || prev_node == BGP_IPV4_NODE | |
559 | || prev_node == BGP_IPV6_NODE || prev_node == BGP_IPV4M_NODE | |
6407da5a | 560 | || prev_node == BGP_IPV6M_NODE || prev_node == BGP_VPNV6_NODE) |
0846286b DS |
561 | && (tried == 1)) |
562 | { | |
563 | fprintf(stdout, "exit-address-family\n"); | |
564 | } | |
565 | else if ((prev_node == KEYCHAIN_KEY_NODE) && (tried == 1)) | |
566 | { | |
567 | fprintf(stdout, "exit\n"); | |
568 | } | |
569 | else if (tried) | |
570 | { | |
571 | fprintf(stdout, "end\n"); | |
572 | } | |
573 | } | |
574 | /* If command didn't succeed in any node, continue with return value from | |
575 | * first try. */ | |
576 | else if (tried) | |
577 | { | |
578 | ret = saved_ret; | |
579 | vty->node = prev_node; | |
580 | } | |
581 | ||
582 | cmd_free_strvec (vline); | |
583 | switch (ret) | |
584 | { | |
585 | case CMD_WARNING: | |
586 | if (vty->type == VTY_FILE) | |
587 | fprintf (stderr,"line %d: Warning...: %s\n", lineno, vty->buf); | |
588 | fclose(confp); | |
589 | vty_close(vty); | |
4a1ab8e4 | 590 | XFREE(MTYPE_VTYSH_CMD, vty_buf_copy); |
1db63918 | 591 | return CMD_WARNING; |
0846286b DS |
592 | case CMD_ERR_AMBIGUOUS: |
593 | fprintf (stderr,"line %d: %% Ambiguous command: %s\n", lineno, vty->buf); | |
594 | fclose(confp); | |
595 | vty_close(vty); | |
4a1ab8e4 | 596 | XFREE(MTYPE_VTYSH_CMD, vty_buf_copy); |
1db63918 | 597 | return CMD_ERR_AMBIGUOUS; |
0846286b DS |
598 | case CMD_ERR_NO_MATCH: |
599 | fprintf (stderr,"line %d: %% Unknown command: %s\n", lineno, vty->buf); | |
600 | fclose(confp); | |
601 | vty_close(vty); | |
4a1ab8e4 | 602 | XFREE(MTYPE_VTYSH_CMD, vty_buf_copy); |
1db63918 | 603 | return CMD_ERR_NO_MATCH; |
0846286b DS |
604 | case CMD_ERR_INCOMPLETE: |
605 | fprintf (stderr,"line %d: %% Command incomplete: %s\n", lineno, vty->buf); | |
606 | fclose(confp); | |
607 | vty_close(vty); | |
4a1ab8e4 | 608 | XFREE(MTYPE_VTYSH_CMD, vty_buf_copy); |
1db63918 | 609 | return CMD_ERR_INCOMPLETE; |
0846286b DS |
610 | case CMD_SUCCESS: |
611 | fprintf(stdout, "%s", vty->buf); | |
612 | break; | |
613 | case CMD_SUCCESS_DAEMON: | |
614 | { | |
615 | u_int i; | |
616 | int cmd_stat = CMD_SUCCESS; | |
617 | ||
618 | fprintf(stdout, "%s", vty->buf); | |
619 | for (i = 0; i < array_size(vtysh_client); i++) | |
620 | { | |
621 | if (cmd->daemon & vtysh_client[i].flag) | |
622 | { | |
623 | cmd_stat = vtysh_client_execute (&vtysh_client[i], | |
624 | vty->buf, stdout); | |
625 | if (cmd_stat != CMD_SUCCESS) | |
626 | break; | |
627 | } | |
628 | } | |
629 | if (cmd_stat != CMD_SUCCESS) | |
630 | break; | |
631 | ||
632 | if (cmd->func) | |
633 | (*cmd->func) (cmd, vty, 0, NULL); | |
634 | } | |
635 | } | |
636 | } | |
637 | /* This is the end */ | |
638 | fprintf(stdout, "end\n"); | |
639 | vty_close(vty); | |
4a1ab8e4 | 640 | XFREE(MTYPE_VTYSH_CMD, vty_buf_copy); |
0846286b DS |
641 | |
642 | if (confp != stdin) | |
643 | fclose(confp); | |
644 | ||
645 | return (0); | |
646 | } | |
647 | ||
718e3744 | 648 | /* Configration make from file. */ |
3221dca8 | 649 | int |
718e3744 | 650 | vtysh_config_from_file (struct vty *vty, FILE *fp) |
651 | { | |
652 | int ret; | |
17aca20b | 653 | const struct cmd_element *cmd; |
9117f21e | 654 | int lineno = 0; |
3221dca8 | 655 | int retcode = CMD_SUCCESS; |
718e3744 | 656 | |
657 | while (fgets (vty->buf, VTY_BUFSIZ, fp)) | |
658 | { | |
9117f21e | 659 | lineno++; |
718e3744 | 660 | |
bed578b8 | 661 | ret = command_config_read_one_line (vty, &cmd, 1); |
718e3744 | 662 | |
663 | switch (ret) | |
664 | { | |
665 | case CMD_WARNING: | |
666 | if (vty->type == VTY_FILE) | |
1db63918 DS |
667 | fprintf (stderr,"line %d: Warning[%d]...: %s\n", lineno, vty->node, vty->buf); |
668 | retcode = CMD_WARNING; /* once we have an error, we remember & return that */ | |
718e3744 | 669 | break; |
670 | case CMD_ERR_AMBIGUOUS: | |
1db63918 DS |
671 | fprintf (stderr,"line %d: %% Ambiguous command[%d]: %s\n", lineno, vty->node, vty->buf); |
672 | retcode = CMD_ERR_AMBIGUOUS; /* once we have an error, we remember & return that */ | |
718e3744 | 673 | break; |
674 | case CMD_ERR_NO_MATCH: | |
1db63918 DS |
675 | fprintf (stderr,"line %d: %% Unknown command[%d]: %s", lineno, vty->node, vty->buf); |
676 | retcode = CMD_ERR_NO_MATCH; /* once we have an error, we remember & return that */ | |
718e3744 | 677 | break; |
678 | case CMD_ERR_INCOMPLETE: | |
1db63918 DS |
679 | fprintf (stderr,"line %d: %% Command incomplete[%d]: %s\n", lineno, vty->node, vty->buf); |
680 | retcode = CMD_ERR_INCOMPLETE; /* once we have an error, we remember & return that */ | |
718e3744 | 681 | break; |
682 | case CMD_SUCCESS_DAEMON: | |
683 | { | |
b1aa147d | 684 | u_int i; |
685 | int cmd_stat = CMD_SUCCESS; | |
686 | ||
837d16cc | 687 | for (i = 0; i < array_size(vtysh_client); i++) |
b1aa147d | 688 | { |
44316fef | 689 | if (cmd->daemon & vtysh_client[i].flag) |
b1aa147d | 690 | { |
691 | cmd_stat = vtysh_client_execute (&vtysh_client[i], | |
692 | vty->buf, stdout); | |
279c6956 DS |
693 | /* |
694 | * CMD_WARNING - Can mean that the command was | |
695 | * parsed successfully but it was already entered | |
696 | * in a few spots. As such if we receive a | |
697 | * CMD_WARNING from a daemon we shouldn't stop | |
698 | * talking to the other daemons for the particular | |
699 | * command. | |
700 | */ | |
701 | if (cmd_stat != CMD_SUCCESS && cmd_stat != CMD_WARNING) | |
1db63918 DS |
702 | { |
703 | fprintf (stderr, "line %d: Failure to communicate[%d] to %s, line: %s\n", | |
704 | lineno, cmd_stat, vtysh_client[i].name, vty->buf); | |
705 | break; | |
706 | } | |
b1aa147d | 707 | } |
708 | } | |
709 | if (cmd_stat != CMD_SUCCESS) | |
710 | break; | |
711 | ||
718e3744 | 712 | if (cmd->func) |
713 | (*cmd->func) (cmd, vty, 0, NULL); | |
714 | } | |
715 | } | |
716 | } | |
3221dca8 DS |
717 | |
718 | return (retcode); | |
718e3744 | 719 | } |
720 | ||
721 | /* We don't care about the point of the cursor when '?' is typed. */ | |
4201dd11 | 722 | static int |
b1aa147d | 723 | vtysh_rl_describe (void) |
718e3744 | 724 | { |
725 | int ret; | |
dda09522 | 726 | unsigned int i; |
718e3744 | 727 | vector vline; |
728 | vector describe; | |
729 | int width; | |
cd40b329 | 730 | struct cmd_token *token; |
718e3744 | 731 | |
732 | vline = cmd_make_strvec (rl_line_buffer); | |
733 | ||
734 | /* In case of '> ?'. */ | |
735 | if (vline == NULL) | |
736 | { | |
737 | vline = vector_init (1); | |
9f7d541a | 738 | vector_set (vline, NULL); |
718e3744 | 739 | } |
740 | else | |
741 | if (rl_end && isspace ((int) rl_line_buffer[rl_end - 1])) | |
9f7d541a | 742 | vector_set (vline, NULL); |
718e3744 | 743 | |
744 | describe = cmd_describe_command (vline, vty, &ret); | |
745 | ||
4fc01e67 | 746 | fprintf (stdout,"\n"); |
718e3744 | 747 | |
748 | /* Ambiguous and no match error. */ | |
749 | switch (ret) | |
750 | { | |
751 | case CMD_ERR_AMBIGUOUS: | |
752 | cmd_free_strvec (vline); | |
4fc01e67 | 753 | fprintf (stdout,"%% Ambiguous command.\n"); |
718e3744 | 754 | rl_on_new_line (); |
755 | return 0; | |
756 | break; | |
757 | case CMD_ERR_NO_MATCH: | |
758 | cmd_free_strvec (vline); | |
4fc01e67 | 759 | fprintf (stdout,"%% There is no matched command.\n"); |
718e3744 | 760 | rl_on_new_line (); |
761 | return 0; | |
762 | break; | |
763 | } | |
764 | ||
765 | /* Get width of command string. */ | |
766 | width = 0; | |
55468c86 | 767 | for (i = 0; i < vector_active (describe); i++) |
cd40b329 | 768 | if ((token = vector_slot (describe, i)) != NULL) |
718e3744 | 769 | { |
c3f24f06 QY |
770 | if (token->text[0] == '\0') |
771 | continue; | |
718e3744 | 772 | |
c3f24f06 | 773 | int len = strlen (token->text); |
718e3744 | 774 | |
c3f24f06 QY |
775 | if (width < len) |
776 | width = len; | |
718e3744 | 777 | } |
778 | ||
55468c86 | 779 | for (i = 0; i < vector_active (describe); i++) |
cd40b329 | 780 | if ((token = vector_slot (describe, i)) != NULL) |
718e3744 | 781 | { |
cd40b329 | 782 | if (! token->desc) |
4fc01e67 | 783 | fprintf (stdout," %-s\n", |
c3f24f06 | 784 | token->text); |
718e3744 | 785 | else |
4fc01e67 | 786 | fprintf (stdout," %-*s %s\n", |
b094d260 | 787 | width, |
c3f24f06 | 788 | token->text, |
cd40b329 | 789 | token->desc); |
718e3744 | 790 | } |
791 | ||
792 | cmd_free_strvec (vline); | |
793 | vector_free (describe); | |
794 | ||
795 | rl_on_new_line(); | |
796 | ||
797 | return 0; | |
798 | } | |
799 | ||
95e735b5 | 800 | /* Result of cmd_complete_command() call will be stored here |
801 | * and used in new_completion() in order to put the space in | |
802 | * correct places only. */ | |
718e3744 | 803 | int complete_status; |
804 | ||
274a4a44 | 805 | static char * |
dfc0d9ba | 806 | command_generator (const char *text, int state) |
718e3744 | 807 | { |
808 | vector vline; | |
809 | static char **matched = NULL; | |
810 | static int index = 0; | |
811 | ||
812 | /* First call. */ | |
813 | if (! state) | |
814 | { | |
815 | index = 0; | |
816 | ||
817 | if (vty->node == AUTH_NODE || vty->node == AUTH_ENABLE_NODE) | |
818 | return NULL; | |
819 | ||
820 | vline = cmd_make_strvec (rl_line_buffer); | |
821 | if (vline == NULL) | |
822 | return NULL; | |
823 | ||
824 | if (rl_end && isspace ((int) rl_line_buffer[rl_end - 1])) | |
9f7d541a | 825 | vector_set (vline, NULL); |
718e3744 | 826 | |
039dc612 QY |
827 | if (matched) |
828 | XFREE (MTYPE_TMP, matched); | |
718e3744 | 829 | matched = cmd_complete_command (vline, vty, &complete_status); |
039dc612 | 830 | cmd_free_strvec (vline); |
718e3744 | 831 | } |
832 | ||
833 | if (matched && matched[index]) | |
834 | return matched[index++]; | |
835 | ||
836 | return NULL; | |
837 | } | |
838 | ||
274a4a44 | 839 | static char ** |
718e3744 | 840 | new_completion (char *text, int start, int end) |
841 | { | |
842 | char **matches; | |
843 | ||
dfc0d9ba | 844 | matches = rl_completion_matches (text, command_generator); |
718e3744 | 845 | |
846 | if (matches) | |
847 | { | |
848 | rl_point = rl_end; | |
67e7a212 CF |
849 | if (complete_status != CMD_COMPLETE_FULL_MATCH) |
850 | /* only append a space on full match */ | |
851 | rl_completion_append_character = '\0'; | |
718e3744 | 852 | } |
853 | ||
854 | return matches; | |
855 | } | |
856 | ||
95e735b5 | 857 | /* Vty node structures. */ |
7fc626de | 858 | static struct cmd_node bgp_node = |
718e3744 | 859 | { |
860 | BGP_NODE, | |
861 | "%s(config-router)# ", | |
862 | }; | |
863 | ||
7fc626de | 864 | static struct cmd_node rip_node = |
718e3744 | 865 | { |
866 | RIP_NODE, | |
867 | "%s(config-router)# ", | |
868 | }; | |
869 | ||
7fc626de | 870 | static struct cmd_node isis_node = |
c25e458a | 871 | { |
872 | ISIS_NODE, | |
873 | "%s(config-router)# ", | |
c25e458a | 874 | }; |
875 | ||
7fc626de | 876 | static struct cmd_node interface_node = |
718e3744 | 877 | { |
878 | INTERFACE_NODE, | |
879 | "%s(config-if)# ", | |
880 | }; | |
881 | ||
13460c44 FL |
882 | static struct cmd_node ns_node = |
883 | { | |
884 | NS_NODE, | |
885 | "%s(config-logical-router)# ", | |
886 | }; | |
887 | ||
e9d94ea7 DS |
888 | static struct cmd_node vrf_node = |
889 | { | |
890 | VRF_NODE, | |
891 | "%s(config-vrf)# ", | |
892 | }; | |
893 | ||
7fc626de | 894 | static struct cmd_node rmap_node = |
95e735b5 | 895 | { |
896 | RMAP_NODE, | |
897 | "%s(config-route-map)# " | |
898 | }; | |
899 | ||
7fc626de | 900 | static struct cmd_node zebra_node = |
95e735b5 | 901 | { |
902 | ZEBRA_NODE, | |
903 | "%s(config-router)# " | |
904 | }; | |
905 | ||
7fc626de | 906 | static struct cmd_node bgp_vpnv4_node = |
95e735b5 | 907 | { |
908 | BGP_VPNV4_NODE, | |
909 | "%s(config-router-af)# " | |
910 | }; | |
911 | ||
8ecd3266 | 912 | static struct cmd_node bgp_vpnv6_node = |
913 | { | |
914 | BGP_VPNV6_NODE, | |
915 | "%s(config-router-af)# " | |
916 | }; | |
917 | ||
8b1fb8be LB |
918 | static struct cmd_node bgp_encap_node = |
919 | { | |
920 | BGP_ENCAP_NODE, | |
921 | "%s(config-router-af)# " | |
922 | }; | |
923 | ||
924 | static struct cmd_node bgp_encapv6_node = | |
925 | { | |
926 | BGP_ENCAPV6_NODE, | |
927 | "%s(config-router-af)# " | |
928 | }; | |
929 | ||
7fc626de | 930 | static struct cmd_node bgp_ipv4_node = |
95e735b5 | 931 | { |
932 | BGP_IPV4_NODE, | |
933 | "%s(config-router-af)# " | |
934 | }; | |
935 | ||
7fc626de | 936 | static struct cmd_node bgp_ipv4m_node = |
95e735b5 | 937 | { |
938 | BGP_IPV4M_NODE, | |
939 | "%s(config-router-af)# " | |
940 | }; | |
941 | ||
7fc626de | 942 | static struct cmd_node bgp_ipv6_node = |
95e735b5 | 943 | { |
944 | BGP_IPV6_NODE, | |
945 | "%s(config-router-af)# " | |
946 | }; | |
947 | ||
7fc626de | 948 | static struct cmd_node bgp_ipv6m_node = |
57b5b7ed | 949 | { |
950 | BGP_IPV6M_NODE, | |
951 | "%s(config-router-af)# " | |
952 | }; | |
953 | ||
65efcfce LB |
954 | static struct cmd_node bgp_vnc_defaults_node = |
955 | { | |
956 | BGP_VNC_DEFAULTS_NODE, | |
957 | "%s(config-router-vnc-defaults)# " | |
958 | }; | |
959 | ||
960 | static struct cmd_node bgp_vnc_nve_group_node = | |
961 | { | |
962 | BGP_VNC_NVE_GROUP_NODE, | |
963 | "%s(config-router-vnc-nve-group)# " | |
964 | }; | |
965 | ||
966 | static struct cmd_node bgp_vnc_l2_group_node = | |
967 | { | |
968 | BGP_VNC_L2_GROUP_NODE, | |
969 | "%s(config-router-vnc-l2-group)# " | |
970 | }; | |
971 | ||
7fc626de | 972 | static struct cmd_node ospf_node = |
95e735b5 | 973 | { |
974 | OSPF_NODE, | |
975 | "%s(config-router)# " | |
976 | }; | |
977 | ||
7fc626de | 978 | static struct cmd_node ripng_node = |
95e735b5 | 979 | { |
980 | RIPNG_NODE, | |
981 | "%s(config-router)# " | |
982 | }; | |
983 | ||
7fc626de | 984 | static struct cmd_node ospf6_node = |
95e735b5 | 985 | { |
986 | OSPF6_NODE, | |
987 | "%s(config-ospf6)# " | |
988 | }; | |
989 | ||
4fcbf6e2 RW |
990 | static struct cmd_node ldp_node = |
991 | { | |
992 | LDP_NODE, | |
993 | "%s(config-ldp)# " | |
994 | }; | |
995 | ||
996 | static struct cmd_node ldp_ipv4_node = | |
997 | { | |
998 | LDP_IPV4_NODE, | |
999 | "%s(config-ldp-af)# " | |
1000 | }; | |
1001 | ||
1002 | static struct cmd_node ldp_ipv6_node = | |
1003 | { | |
1004 | LDP_IPV6_NODE, | |
1005 | "%s(config-ldp-af)# " | |
1006 | }; | |
1007 | ||
1008 | static struct cmd_node ldp_ipv4_iface_node = | |
1009 | { | |
1010 | LDP_IPV4_IFACE_NODE, | |
1011 | "%s(config-ldp-af-if)# " | |
1012 | }; | |
1013 | ||
1014 | static struct cmd_node ldp_ipv6_iface_node = | |
1015 | { | |
1016 | LDP_IPV6_IFACE_NODE, | |
1017 | "%s(config-ldp-af-if)# " | |
1018 | }; | |
1019 | ||
1020 | static struct cmd_node ldp_l2vpn_node = | |
1021 | { | |
1022 | LDP_L2VPN_NODE, | |
1023 | "%s(config-l2vpn)# " | |
1024 | }; | |
1025 | ||
1026 | static struct cmd_node ldp_pseudowire_node = | |
1027 | { | |
1028 | LDP_PSEUDOWIRE_NODE, | |
1029 | "%s(config-l2vpn-pw)# " | |
1030 | }; | |
1031 | ||
7fc626de | 1032 | static struct cmd_node keychain_node = |
95e735b5 | 1033 | { |
1034 | KEYCHAIN_NODE, | |
1035 | "%s(config-keychain)# " | |
1036 | }; | |
1037 | ||
7fc626de | 1038 | static struct cmd_node keychain_key_node = |
95e735b5 | 1039 | { |
1040 | KEYCHAIN_KEY_NODE, | |
1041 | "%s(config-keychain-key)# " | |
1042 | }; | |
1043 | ||
16f1b9ee OD |
1044 | struct cmd_node link_params_node = |
1045 | { | |
1046 | LINK_PARAMS_NODE, | |
1047 | "%s(config-link-params)# ", | |
1048 | }; | |
1049 | ||
e7168df4 | 1050 | /* Defined in lib/vty.c */ |
1051 | extern struct cmd_node vty_node; | |
1052 | ||
95e735b5 | 1053 | /* When '^Z' is received from vty, move down to the enable mode. */ |
4201dd11 | 1054 | static int |
b1aa147d | 1055 | vtysh_end (void) |
95e735b5 | 1056 | { |
1057 | switch (vty->node) | |
1058 | { | |
1059 | case VIEW_NODE: | |
1060 | case ENABLE_NODE: | |
1061 | /* Nothing to do. */ | |
1062 | break; | |
1063 | default: | |
1064 | vty->node = ENABLE_NODE; | |
1065 | break; | |
1066 | } | |
1067 | return CMD_SUCCESS; | |
1068 | } | |
1069 | ||
4a96e944 | 1070 | DEFUNSH (VTYSH_REALLYALL, |
95e735b5 | 1071 | vtysh_end_all, |
1072 | vtysh_end_all_cmd, | |
1073 | "end", | |
e7168df4 | 1074 | "End current mode and change to enable mode\n") |
95e735b5 | 1075 | { |
4289546d | 1076 | return vtysh_end (); |
95e735b5 | 1077 | } |
1078 | ||
718e3744 | 1079 | DEFUNSH (VTYSH_BGPD, |
1080 | router_bgp, | |
1081 | router_bgp_cmd, | |
a98d33ab | 1082 | "router bgp [(1-4294967295) [<view|vrf> WORD]]", |
718e3744 | 1083 | ROUTER_STR |
1084 | BGP_STR | |
a98d33ab QY |
1085 | AS_STR |
1086 | "BGP view\nBGP VRF\n" | |
1087 | "View/VRF name\n") | |
718e3744 | 1088 | { |
1089 | vty->node = BGP_NODE; | |
1090 | return CMD_SUCCESS; | |
1091 | } | |
1092 | ||
1093 | DEFUNSH (VTYSH_BGPD, | |
1094 | address_family_vpnv4, | |
1095 | address_family_vpnv4_cmd, | |
843d75b1 | 1096 | "address-family vpnv4 [unicast]", |
718e3744 | 1097 | "Enter Address Family command mode\n" |
843d75b1 | 1098 | "Address Family\n" |
718e3744 | 1099 | "Address Family Modifier\n") |
1100 | { | |
1101 | vty->node = BGP_VPNV4_NODE; | |
1102 | return CMD_SUCCESS; | |
1103 | } | |
1104 | ||
8ecd3266 | 1105 | DEFUNSH (VTYSH_BGPD, |
1106 | address_family_vpnv6, | |
1107 | address_family_vpnv6_cmd, | |
843d75b1 | 1108 | "address-family vpnv6 [unicast]", |
8ecd3266 | 1109 | "Enter Address Family command mode\n" |
843d75b1 | 1110 | "Address Family\n" |
8ecd3266 | 1111 | "Address Family Modifier\n") |
1112 | { | |
1113 | vty->node = BGP_VPNV6_NODE; | |
1114 | return CMD_SUCCESS; | |
1115 | } | |
1116 | ||
8b1fb8be LB |
1117 | DEFUNSH (VTYSH_BGPD, |
1118 | address_family_encapv4, | |
1119 | address_family_encapv4_cmd, | |
4c4ff4c1 | 1120 | "address-family <encap|encapv4>", |
8b1fb8be | 1121 | "Enter Address Family command mode\n" |
4c4ff4c1 | 1122 | "Address Family\n" |
843d75b1 | 1123 | "Address Family\n") |
8b1fb8be LB |
1124 | { |
1125 | vty->node = BGP_ENCAP_NODE; | |
1126 | return CMD_SUCCESS; | |
1127 | } | |
1128 | ||
1129 | DEFUNSH (VTYSH_BGPD, | |
1130 | address_family_encapv6, | |
1131 | address_family_encapv6_cmd, | |
1132 | "address-family encapv6", | |
1133 | "Enter Address Family command mode\n" | |
843d75b1 | 1134 | "Address Family\n") |
8b1fb8be LB |
1135 | { |
1136 | vty->node = BGP_ENCAPV6_NODE; | |
1137 | return CMD_SUCCESS; | |
1138 | } | |
1139 | ||
718e3744 | 1140 | DEFUNSH (VTYSH_BGPD, |
1141 | address_family_ipv4_unicast, | |
1142 | address_family_ipv4_unicast_cmd, | |
1143 | "address-family ipv4 unicast", | |
1144 | "Enter Address Family command mode\n" | |
843d75b1 | 1145 | "Address Family\n" |
718e3744 | 1146 | "Address Family Modifier\n") |
1147 | { | |
1148 | vty->node = BGP_IPV4_NODE; | |
1149 | return CMD_SUCCESS; | |
1150 | } | |
1151 | ||
1152 | DEFUNSH (VTYSH_BGPD, | |
1153 | address_family_ipv4_multicast, | |
1154 | address_family_ipv4_multicast_cmd, | |
1155 | "address-family ipv4 multicast", | |
1156 | "Enter Address Family command mode\n" | |
843d75b1 | 1157 | "Address Family\n" |
718e3744 | 1158 | "Address Family Modifier\n") |
1159 | { | |
1160 | vty->node = BGP_IPV4M_NODE; | |
1161 | return CMD_SUCCESS; | |
1162 | } | |
1163 | ||
1164 | DEFUNSH (VTYSH_BGPD, | |
1165 | address_family_ipv6, | |
1166 | address_family_ipv6_cmd, | |
843d75b1 | 1167 | "address-family ipv6 [unicast]", |
718e3744 | 1168 | "Enter Address Family command mode\n" |
843d75b1 | 1169 | "Address Family\n" |
718e3744 | 1170 | "Address Family Modifier\n") |
1171 | { | |
1172 | vty->node = BGP_IPV6_NODE; | |
1173 | return CMD_SUCCESS; | |
1174 | } | |
1175 | ||
57b5b7ed | 1176 | DEFUNSH (VTYSH_BGPD, |
1177 | address_family_ipv6_multicast, | |
1178 | address_family_ipv6_multicast_cmd, | |
1179 | "address-family ipv6 multicast", | |
1180 | "Enter Address Family command mode\n" | |
843d75b1 | 1181 | "Address Family\n" |
57b5b7ed | 1182 | "Address Family Modifier\n") |
1183 | { | |
1184 | vty->node = BGP_IPV6M_NODE; | |
1185 | return CMD_SUCCESS; | |
1186 | } | |
1187 | ||
87ab4aec | 1188 | #if defined (ENABLE_BGP_VNC) |
65efcfce LB |
1189 | DEFUNSH (VTYSH_BGPD, |
1190 | vnc_defaults, | |
1191 | vnc_defaults_cmd, | |
1192 | "vnc defaults", | |
1193 | "VNC/RFP related configuration\n" | |
1194 | "Configure default NVE group\n") | |
1195 | { | |
1196 | vty->node = BGP_VNC_DEFAULTS_NODE; | |
1197 | return CMD_SUCCESS; | |
1198 | } | |
1199 | ||
1200 | DEFUNSH (VTYSH_BGPD, | |
1201 | vnc_nve_group, | |
1202 | vnc_nve_group_cmd, | |
1203 | "vnc nve-group NAME", | |
1204 | "VNC/RFP related configuration\n" | |
1205 | "Configure a NVE group\n" | |
1206 | "Group name\n") | |
1207 | { | |
1208 | vty->node = BGP_VNC_NVE_GROUP_NODE; | |
1209 | return CMD_SUCCESS; | |
1210 | } | |
1211 | ||
1212 | DEFUNSH (VTYSH_BGPD, | |
1213 | vnc_l2_group, | |
1214 | vnc_l2_group_cmd, | |
1215 | "vnc l2-group NAME", | |
1216 | "VNC/RFP related configuration\n" | |
1217 | "Configure a L2 group\n" | |
1218 | "Group name\n") | |
1219 | { | |
1220 | vty->node = BGP_VNC_L2_GROUP_NODE; | |
1221 | return CMD_SUCCESS; | |
1222 | } | |
87ab4aec | 1223 | #endif |
65efcfce | 1224 | |
718e3744 | 1225 | DEFUNSH (VTYSH_RIPD, |
1226 | key_chain, | |
1227 | key_chain_cmd, | |
1228 | "key chain WORD", | |
1229 | "Authentication key management\n" | |
1230 | "Key-chain management\n" | |
1231 | "Key-chain name\n") | |
1232 | { | |
1233 | vty->node = KEYCHAIN_NODE; | |
1234 | return CMD_SUCCESS; | |
1235 | } | |
1236 | ||
1237 | DEFUNSH (VTYSH_RIPD, | |
1238 | key, | |
1239 | key_cmd, | |
a98d33ab | 1240 | "key (0-2147483647)", |
718e3744 | 1241 | "Configure a key\n" |
1242 | "Key identifier number\n") | |
1243 | { | |
1244 | vty->node = KEYCHAIN_KEY_NODE; | |
1245 | return CMD_SUCCESS; | |
1246 | } | |
1247 | ||
1248 | DEFUNSH (VTYSH_RIPD, | |
1249 | router_rip, | |
1250 | router_rip_cmd, | |
1251 | "router rip", | |
1252 | ROUTER_STR | |
1253 | "RIP") | |
1254 | { | |
1255 | vty->node = RIP_NODE; | |
1256 | return CMD_SUCCESS; | |
1257 | } | |
1258 | ||
1259 | DEFUNSH (VTYSH_RIPNGD, | |
1260 | router_ripng, | |
1261 | router_ripng_cmd, | |
1262 | "router ripng", | |
1263 | ROUTER_STR | |
1264 | "RIPng") | |
1265 | { | |
1266 | vty->node = RIPNG_NODE; | |
1267 | return CMD_SUCCESS; | |
1268 | } | |
1269 | ||
1270 | DEFUNSH (VTYSH_OSPFD, | |
1271 | router_ospf, | |
1272 | router_ospf_cmd, | |
a98d33ab | 1273 | "router ospf [(1-65535)]", |
718e3744 | 1274 | "Enable a routing process\n" |
a98d33ab QY |
1275 | "Start OSPF configuration\n" |
1276 | "Instance ID\n") | |
718e3744 | 1277 | { |
1278 | vty->node = OSPF_NODE; | |
1279 | return CMD_SUCCESS; | |
1280 | } | |
1281 | ||
1282 | DEFUNSH (VTYSH_OSPF6D, | |
1283 | router_ospf6, | |
1284 | router_ospf6_cmd, | |
1285 | "router ospf6", | |
16cedbb0 | 1286 | ROUTER_STR |
718e3744 | 1287 | OSPF6_STR) |
1288 | { | |
1289 | vty->node = OSPF6_NODE; | |
1290 | return CMD_SUCCESS; | |
1291 | } | |
1292 | ||
87ab4aec | 1293 | #if defined (HAVE_LDPD) |
4fcbf6e2 RW |
1294 | DEFUNSH (VTYSH_LDPD, |
1295 | ldp_mpls_ldp, | |
1296 | ldp_mpls_ldp_cmd, | |
1297 | "mpls ldp", | |
1298 | "Global MPLS configuration subcommands\n" | |
1299 | "Label Distribution Protocol\n") | |
1300 | { | |
1301 | vty->node = LDP_NODE; | |
1302 | return CMD_SUCCESS; | |
1303 | } | |
1304 | ||
1305 | DEFUNSH (VTYSH_LDPD, | |
1306 | ldp_address_family_ipv4, | |
1307 | ldp_address_family_ipv4_cmd, | |
1308 | "address-family ipv4", | |
1309 | "Configure Address Family and its parameters\n" | |
1310 | "IPv4\n") | |
1311 | { | |
1312 | vty->node = LDP_IPV4_NODE; | |
1313 | return CMD_SUCCESS; | |
1314 | } | |
1315 | ||
1316 | DEFUNSH (VTYSH_LDPD, | |
1317 | ldp_address_family_ipv6, | |
1318 | ldp_address_family_ipv6_cmd, | |
1319 | "address-family ipv6", | |
1320 | "Configure Address Family and its parameters\n" | |
1321 | "IPv6\n") | |
1322 | { | |
1323 | vty->node = LDP_IPV6_NODE; | |
1324 | return CMD_SUCCESS; | |
1325 | } | |
1326 | ||
1327 | DEFUNSH (VTYSH_LDPD, | |
1328 | ldp_interface_ifname, | |
1329 | ldp_interface_ifname_cmd, | |
1330 | "interface IFNAME", | |
1331 | "Enable LDP on an interface and enter interface submode\n" | |
1332 | "Interface's name\n") | |
1333 | { | |
1334 | switch (vty->node) | |
1335 | { | |
1336 | case LDP_IPV4_NODE: | |
1337 | vty->node = LDP_IPV4_IFACE_NODE; | |
1338 | break; | |
1339 | case LDP_IPV6_NODE: | |
1340 | vty->node = LDP_IPV6_IFACE_NODE; | |
1341 | break; | |
1342 | default: | |
1343 | break; | |
1344 | } | |
1345 | ||
1346 | return CMD_SUCCESS; | |
1347 | } | |
1348 | ||
1349 | DEFUNSH (VTYSH_LDPD, | |
1350 | ldp_l2vpn_word_type_vpls, | |
1351 | ldp_l2vpn_word_type_vpls_cmd, | |
1352 | "l2vpn WORD type vpls", | |
1353 | "Configure l2vpn commands\n" | |
1354 | "L2VPN name\n" | |
1355 | "L2VPN type\n" | |
1356 | "Virtual Private LAN Service\n") | |
1357 | { | |
1358 | vty->node = LDP_L2VPN_NODE; | |
1359 | return CMD_SUCCESS; | |
1360 | } | |
1361 | ||
1362 | DEFUNSH (VTYSH_LDPD, | |
1363 | ldp_member_pseudowire_ifname, | |
1364 | ldp_member_pseudowire_ifname_cmd, | |
1365 | "member pseudowire IFNAME", | |
1366 | "L2VPN member configuration\n" | |
1367 | "Pseudowire interface\n" | |
1368 | "Interface's name\n") | |
1369 | { | |
1370 | vty->node = LDP_PSEUDOWIRE_NODE; | |
1371 | return CMD_SUCCESS; | |
1372 | } | |
87ab4aec | 1373 | #endif |
4fcbf6e2 | 1374 | |
c25e458a | 1375 | DEFUNSH (VTYSH_ISISD, |
b094d260 | 1376 | router_isis, |
1377 | router_isis_cmd, | |
1378 | "router isis WORD", | |
1379 | ROUTER_STR | |
1380 | "ISO IS-IS\n" | |
1381 | "ISO Routing area tag") | |
c25e458a | 1382 | { |
1383 | vty->node = ISIS_NODE; | |
1384 | return CMD_SUCCESS; | |
1385 | } | |
1386 | ||
718e3744 | 1387 | DEFUNSH (VTYSH_RMAP, |
1388 | route_map, | |
1389 | route_map_cmd, | |
a98d33ab | 1390 | "route-map WORD <deny|permit> (1-65535)", |
718e3744 | 1391 | "Create route-map or enter route-map command mode\n" |
1392 | "Route map tag\n" | |
1393 | "Route map denies set operations\n" | |
1394 | "Route map permits set operations\n" | |
1395 | "Sequence to insert to/delete from existing route-map entry\n") | |
1396 | { | |
1397 | vty->node = RMAP_NODE; | |
1398 | return CMD_SUCCESS; | |
1399 | } | |
1400 | ||
e7168df4 | 1401 | DEFUNSH (VTYSH_ALL, |
1402 | vtysh_line_vty, | |
1403 | vtysh_line_vty_cmd, | |
1404 | "line vty", | |
1405 | "Configure a terminal line\n" | |
1406 | "Virtual terminal\n") | |
1407 | { | |
1408 | vty->node = VTY_NODE; | |
1409 | return CMD_SUCCESS; | |
1410 | } | |
1411 | ||
4a96e944 DL |
1412 | DEFUNSH (VTYSH_REALLYALL, |
1413 | vtysh_enable, | |
718e3744 | 1414 | vtysh_enable_cmd, |
1415 | "enable", | |
1416 | "Turn on privileged mode command\n") | |
1417 | { | |
1418 | vty->node = ENABLE_NODE; | |
1419 | return CMD_SUCCESS; | |
1420 | } | |
1421 | ||
4a96e944 DL |
1422 | DEFUNSH (VTYSH_REALLYALL, |
1423 | vtysh_disable, | |
718e3744 | 1424 | vtysh_disable_cmd, |
1425 | "disable", | |
1426 | "Turn off privileged mode command\n") | |
1427 | { | |
1428 | if (vty->node == ENABLE_NODE) | |
1429 | vty->node = VIEW_NODE; | |
1430 | return CMD_SUCCESS; | |
1431 | } | |
1432 | ||
4a96e944 | 1433 | DEFUNSH (VTYSH_REALLYALL, |
718e3744 | 1434 | vtysh_config_terminal, |
1435 | vtysh_config_terminal_cmd, | |
1436 | "configure terminal", | |
1437 | "Configuration from vty interface\n" | |
1438 | "Configuration terminal\n") | |
1439 | { | |
1440 | vty->node = CONFIG_NODE; | |
1441 | return CMD_SUCCESS; | |
1442 | } | |
1443 | ||
274a4a44 | 1444 | static int |
718e3744 | 1445 | vtysh_exit (struct vty *vty) |
1446 | { | |
1447 | switch (vty->node) | |
1448 | { | |
1449 | case VIEW_NODE: | |
1450 | case ENABLE_NODE: | |
1451 | exit (0); | |
1452 | break; | |
1453 | case CONFIG_NODE: | |
1454 | vty->node = ENABLE_NODE; | |
1455 | break; | |
1456 | case INTERFACE_NODE: | |
13460c44 | 1457 | case NS_NODE: |
e9d94ea7 | 1458 | case VRF_NODE: |
718e3744 | 1459 | case ZEBRA_NODE: |
1460 | case BGP_NODE: | |
1461 | case RIP_NODE: | |
1462 | case RIPNG_NODE: | |
1463 | case OSPF_NODE: | |
1464 | case OSPF6_NODE: | |
4fcbf6e2 RW |
1465 | case LDP_NODE: |
1466 | case LDP_L2VPN_NODE: | |
c25e458a | 1467 | case ISIS_NODE: |
718e3744 | 1468 | case MASC_NODE: |
1469 | case RMAP_NODE: | |
1470 | case VTY_NODE: | |
1471 | case KEYCHAIN_NODE: | |
2a56df97 | 1472 | vtysh_execute("end"); |
1473 | vtysh_execute("configure terminal"); | |
718e3744 | 1474 | vty->node = CONFIG_NODE; |
1475 | break; | |
1476 | case BGP_VPNV4_NODE: | |
8ecd3266 | 1477 | case BGP_VPNV6_NODE: |
8b1fb8be LB |
1478 | case BGP_ENCAP_NODE: |
1479 | case BGP_ENCAPV6_NODE: | |
718e3744 | 1480 | case BGP_IPV4_NODE: |
1481 | case BGP_IPV4M_NODE: | |
1482 | case BGP_IPV6_NODE: | |
57b5b7ed | 1483 | case BGP_IPV6M_NODE: |
65efcfce LB |
1484 | case BGP_VNC_DEFAULTS_NODE: |
1485 | case BGP_VNC_NVE_GROUP_NODE: | |
1486 | case BGP_VNC_L2_GROUP_NODE: | |
718e3744 | 1487 | vty->node = BGP_NODE; |
1488 | break; | |
4fcbf6e2 RW |
1489 | case LDP_IPV4_NODE: |
1490 | case LDP_IPV6_NODE: | |
1491 | vty->node = LDP_NODE; | |
1492 | break; | |
1493 | case LDP_IPV4_IFACE_NODE: | |
1494 | vty->node = LDP_IPV4_NODE; | |
1495 | break; | |
1496 | case LDP_IPV6_IFACE_NODE: | |
1497 | vty->node = LDP_IPV6_NODE; | |
1498 | break; | |
1499 | case LDP_PSEUDOWIRE_NODE: | |
1500 | vty->node = LDP_L2VPN_NODE; | |
1501 | break; | |
718e3744 | 1502 | case KEYCHAIN_KEY_NODE: |
1503 | vty->node = KEYCHAIN_NODE; | |
1504 | break; | |
16f1b9ee OD |
1505 | case LINK_PARAMS_NODE: |
1506 | vty->node = INTERFACE_NODE; | |
1507 | break; | |
718e3744 | 1508 | default: |
1509 | break; | |
1510 | } | |
1511 | return CMD_SUCCESS; | |
1512 | } | |
1513 | ||
4a96e944 | 1514 | DEFUNSH (VTYSH_REALLYALL, |
718e3744 | 1515 | vtysh_exit_all, |
1516 | vtysh_exit_all_cmd, | |
1517 | "exit", | |
1518 | "Exit current mode and down to previous mode\n") | |
1519 | { | |
1520 | return vtysh_exit (vty); | |
1521 | } | |
1522 | ||
a98d33ab QY |
1523 | DEFUNSH (VTYSH_ALL, |
1524 | vtysh_quit_all, | |
1525 | vtysh_quit_all_cmd, | |
1526 | "quit", | |
1527 | "Exit current mode and down to previous mode\n") | |
1528 | { | |
1529 | return vtysh_exit_all (self, vty, argc, argv); | |
1530 | } | |
718e3744 | 1531 | |
1532 | DEFUNSH (VTYSH_BGPD, | |
1533 | exit_address_family, | |
1534 | exit_address_family_cmd, | |
1535 | "exit-address-family", | |
1536 | "Exit from Address Family configuration mode\n") | |
1537 | { | |
1538 | if (vty->node == BGP_IPV4_NODE | |
1539 | || vty->node == BGP_IPV4M_NODE | |
1540 | || vty->node == BGP_VPNV4_NODE | |
8ecd3266 | 1541 | || vty->node == BGP_VPNV6_NODE |
8b1fb8be LB |
1542 | || vty->node == BGP_ENCAP_NODE |
1543 | || vty->node == BGP_ENCAPV6_NODE | |
57b5b7ed | 1544 | || vty->node == BGP_IPV6_NODE |
1545 | || vty->node == BGP_IPV6M_NODE) | |
718e3744 | 1546 | vty->node = BGP_NODE; |
1547 | return CMD_SUCCESS; | |
1548 | } | |
1549 | ||
65efcfce LB |
1550 | DEFUNSH (VTYSH_BGPD, |
1551 | exit_vnc_config, | |
1552 | exit_vnc_config_cmd, | |
1553 | "exit-vnc", | |
1554 | "Exit from VNC configuration mode\n") | |
1555 | { | |
1556 | if (vty->node == BGP_VNC_DEFAULTS_NODE | |
1557 | || vty->node == BGP_VNC_NVE_GROUP_NODE | |
1558 | || vty->node == BGP_VNC_L2_GROUP_NODE) | |
1559 | vty->node = BGP_NODE; | |
1560 | return CMD_SUCCESS; | |
1561 | } | |
1562 | ||
718e3744 | 1563 | DEFUNSH (VTYSH_ZEBRA, |
1564 | vtysh_exit_zebra, | |
1565 | vtysh_exit_zebra_cmd, | |
1566 | "exit", | |
1567 | "Exit current mode and down to previous mode\n") | |
1568 | { | |
1569 | return vtysh_exit (vty); | |
1570 | } | |
1571 | ||
a98d33ab QY |
1572 | DEFUNSH (VTYSH_ZEBRA, |
1573 | vtysh_quit_zebra, | |
1574 | vtysh_quit_zebra_cmd, | |
1575 | "quit", | |
1576 | "Exit current mode and down to previous mode\n") | |
1577 | { | |
1578 | return vtysh_exit_zebra (self, vty, argc, argv); | |
1579 | } | |
718e3744 | 1580 | |
1581 | DEFUNSH (VTYSH_RIPD, | |
1582 | vtysh_exit_ripd, | |
1583 | vtysh_exit_ripd_cmd, | |
1584 | "exit", | |
1585 | "Exit current mode and down to previous mode\n") | |
1586 | { | |
1587 | return vtysh_exit (vty); | |
1588 | } | |
1589 | ||
a98d33ab QY |
1590 | DEFUNSH (VTYSH_RIPD, |
1591 | vtysh_quit_ripd, | |
1592 | vtysh_quit_ripd_cmd, | |
1593 | "quit", | |
1594 | "Exit current mode and down to previous mode\n") | |
1595 | { | |
1596 | return vtysh_exit_ripd (self, vty, argc, argv); | |
1597 | } | |
718e3744 | 1598 | |
68980084 | 1599 | DEFUNSH (VTYSH_RIPNGD, |
b094d260 | 1600 | vtysh_exit_ripngd, |
1601 | vtysh_exit_ripngd_cmd, | |
1602 | "exit", | |
1603 | "Exit current mode and down to previous mode\n") | |
68980084 | 1604 | { |
1605 | return vtysh_exit (vty); | |
1606 | } | |
1607 | ||
a98d33ab QY |
1608 | DEFUNSH (VTYSH_RIPNGD, |
1609 | vtysh_quit_ripngd, | |
1610 | vtysh_quit_ripngd_cmd, | |
1611 | "quit", | |
1612 | "Exit current mode and down to previous mode\n") | |
1613 | { | |
1614 | return vtysh_exit_ripngd (self, vty, argc, argv); | |
1615 | } | |
68980084 | 1616 | |
718e3744 | 1617 | DEFUNSH (VTYSH_RMAP, |
1618 | vtysh_exit_rmap, | |
1619 | vtysh_exit_rmap_cmd, | |
1620 | "exit", | |
1621 | "Exit current mode and down to previous mode\n") | |
1622 | { | |
1623 | return vtysh_exit (vty); | |
1624 | } | |
1625 | ||
a98d33ab QY |
1626 | DEFUNSH (VTYSH_RMAP, |
1627 | vtysh_quit_rmap, | |
1628 | vtysh_quit_rmap_cmd, | |
1629 | "quit", | |
1630 | "Exit current mode and down to previous mode\n") | |
1631 | { | |
1632 | return vtysh_exit_rmap (self, vty, argc, argv); | |
1633 | } | |
718e3744 | 1634 | |
1635 | DEFUNSH (VTYSH_BGPD, | |
1636 | vtysh_exit_bgpd, | |
1637 | vtysh_exit_bgpd_cmd, | |
1638 | "exit", | |
1639 | "Exit current mode and down to previous mode\n") | |
1640 | { | |
1641 | return vtysh_exit (vty); | |
1642 | } | |
1643 | ||
a98d33ab QY |
1644 | DEFUNSH (VTYSH_BGPD, |
1645 | vtysh_quit_bgpd, | |
1646 | vtysh_quit_bgpd_cmd, | |
1647 | "quit", | |
1648 | "Exit current mode and down to previous mode\n") | |
1649 | { | |
1650 | return vtysh_exit_bgpd (self, vty, argc, argv); | |
1651 | } | |
718e3744 | 1652 | |
1653 | DEFUNSH (VTYSH_OSPFD, | |
1654 | vtysh_exit_ospfd, | |
1655 | vtysh_exit_ospfd_cmd, | |
1656 | "exit", | |
1657 | "Exit current mode and down to previous mode\n") | |
1658 | { | |
1659 | return vtysh_exit (vty); | |
1660 | } | |
1661 | ||
a98d33ab QY |
1662 | DEFUNSH (VTYSH_OSPFD, |
1663 | vtysh_quit_ospfd, | |
1664 | vtysh_quit_ospfd_cmd, | |
1665 | "quit", | |
1666 | "Exit current mode and down to previous mode\n") | |
1667 | { | |
1668 | return vtysh_exit_ospfd (self, vty, argc, argv); | |
1669 | } | |
718e3744 | 1670 | |
68980084 | 1671 | DEFUNSH (VTYSH_OSPF6D, |
b094d260 | 1672 | vtysh_exit_ospf6d, |
1673 | vtysh_exit_ospf6d_cmd, | |
1674 | "exit", | |
1675 | "Exit current mode and down to previous mode\n") | |
68980084 | 1676 | { |
1677 | return vtysh_exit (vty); | |
1678 | } | |
1679 | ||
a98d33ab QY |
1680 | DEFUNSH (VTYSH_OSPF6D, |
1681 | vtysh_quit_ospf6d, | |
1682 | vtysh_quit_ospf6d_cmd, | |
1683 | "quit", | |
1684 | "Exit current mode and down to previous mode\n") | |
1685 | { | |
1686 | return vtysh_exit_ospf6d (self, vty, argc, argv); | |
1687 | } | |
68980084 | 1688 | |
87ab4aec | 1689 | #if defined (HAVE_LDPD) |
4fcbf6e2 RW |
1690 | DEFUNSH (VTYSH_LDPD, |
1691 | vtysh_exit_ldpd, | |
1692 | vtysh_exit_ldpd_cmd, | |
1693 | "exit", | |
1694 | "Exit current mode and down to previous mode\n") | |
1695 | { | |
1696 | return vtysh_exit (vty); | |
1697 | } | |
1698 | ||
1699 | ALIAS (vtysh_exit_ldpd, | |
1700 | vtysh_quit_ldpd_cmd, | |
1701 | "quit", | |
1702 | "Exit current mode and down to previous mode\n") | |
87ab4aec | 1703 | #endif |
4fcbf6e2 | 1704 | |
c25e458a | 1705 | DEFUNSH (VTYSH_ISISD, |
b094d260 | 1706 | vtysh_exit_isisd, |
1707 | vtysh_exit_isisd_cmd, | |
1708 | "exit", | |
1709 | "Exit current mode and down to previous mode\n") | |
c25e458a | 1710 | { |
1711 | return vtysh_exit (vty); | |
1712 | } | |
1713 | ||
a98d33ab QY |
1714 | DEFUNSH (VTYSH_ISISD, |
1715 | vtysh_quit_isisd, | |
1716 | vtysh_quit_isisd_cmd, | |
1717 | "quit", | |
1718 | "Exit current mode and down to previous mode\n") | |
1719 | { | |
1720 | return vtysh_exit_isisd (self, vty, argc, argv); | |
1721 | } | |
c25e458a | 1722 | |
e7168df4 | 1723 | DEFUNSH (VTYSH_ALL, |
1724 | vtysh_exit_line_vty, | |
1725 | vtysh_exit_line_vty_cmd, | |
1726 | "exit", | |
1727 | "Exit current mode and down to previous mode\n") | |
1728 | { | |
1729 | return vtysh_exit (vty); | |
1730 | } | |
1731 | ||
a98d33ab QY |
1732 | DEFUNSH (VTYSH_ALL, |
1733 | vtysh_quit_line_vty, | |
1734 | vtysh_quit_line_vty_cmd, | |
1735 | "quit", | |
1736 | "Exit current mode and down to previous mode\n") | |
1737 | { | |
1738 | return vtysh_exit_line_vty (self, vty, argc, argv); | |
1739 | } | |
e7168df4 | 1740 | |
95e735b5 | 1741 | DEFUNSH (VTYSH_INTERFACE, |
718e3744 | 1742 | vtysh_interface, |
1743 | vtysh_interface_cmd, | |
a98d33ab | 1744 | "interface IFNAME [vrf NAME]", |
718e3744 | 1745 | "Select an interface to configure\n" |
a98d33ab QY |
1746 | "Interface's name\n" |
1747 | VRF_CMD_HELP_STR) | |
718e3744 | 1748 | { |
1749 | vty->node = INTERFACE_NODE; | |
1750 | return CMD_SUCCESS; | |
1751 | } | |
1752 | ||
95e735b5 | 1753 | /* TODO Implement "no interface command in isisd. */ |
4fcbf6e2 | 1754 | DEFSH (VTYSH_ZEBRA|VTYSH_RIPD|VTYSH_RIPNGD|VTYSH_OSPFD|VTYSH_OSPF6D|VTYSH_LDPD, |
32d2463c | 1755 | vtysh_no_interface_cmd, |
1756 | "no interface IFNAME", | |
1757 | NO_STR | |
1758 | "Delete a pseudo interface's configuration\n" | |
1759 | "Interface's name\n") | |
1760 | ||
cd2a8a42 FL |
1761 | DEFSH (VTYSH_ZEBRA, |
1762 | vtysh_no_interface_vrf_cmd, | |
199d90a1 | 1763 | "no interface IFNAME vrf NAME", |
cd2a8a42 FL |
1764 | NO_STR |
1765 | "Delete a pseudo interface's configuration\n" | |
1766 | "Interface's name\n" | |
1767 | VRF_CMD_HELP_STR) | |
1768 | ||
13460c44 FL |
1769 | DEFUNSH (VTYSH_NS, |
1770 | vtysh_ns, | |
1771 | vtysh_ns_cmd, | |
a98d33ab | 1772 | "logical-router (1-65535) ns NAME", |
13460c44 FL |
1773 | "Enable a logical-router\n" |
1774 | "Specify the logical-router indentifier\n" | |
1775 | "The Name Space\n" | |
1776 | "The file name in " NS_RUN_DIR ", or a full pathname\n") | |
1777 | { | |
1778 | vty->node = NS_NODE; | |
1779 | return CMD_SUCCESS; | |
1780 | } | |
1781 | ||
e9d94ea7 DS |
1782 | DEFUNSH (VTYSH_VRF, |
1783 | vtysh_vrf, | |
1784 | vtysh_vrf_cmd, | |
1785 | "vrf NAME", | |
1786 | "Select a VRF to configure\n" | |
1787 | "VRF's name\n") | |
1788 | { | |
1789 | vty->node = VRF_NODE; | |
1790 | return CMD_SUCCESS; | |
1791 | } | |
1792 | ||
1793 | DEFSH (VTYSH_ZEBRA, | |
1794 | vtysh_no_vrf_cmd, | |
1795 | "no vrf NAME", | |
1796 | NO_STR | |
1797 | "Delete a pseudo vrf's configuration\n" | |
1798 | "VRF's name\n") | |
1799 | ||
13460c44 FL |
1800 | DEFUNSH (VTYSH_NS, |
1801 | vtysh_exit_ns, | |
1802 | vtysh_exit_ns_cmd, | |
1803 | "exit", | |
1804 | "Exit current mode and down to previous mode\n") | |
1805 | { | |
1806 | return vtysh_exit (vty); | |
1807 | } | |
1808 | ||
a98d33ab QY |
1809 | DEFUNSH (VTYSH_NS, |
1810 | vtysh_quit_ns, | |
1811 | vtysh_quit_ns_cmd, | |
1812 | "quit", | |
1813 | "Exit current mode and down to previous mode\n") | |
1814 | { | |
030204c7 | 1815 | return vtysh_exit_ns(self, vty, argc, argv); |
a98d33ab | 1816 | } |
13460c44 | 1817 | |
e9d94ea7 DS |
1818 | DEFUNSH (VTYSH_VRF, |
1819 | vtysh_exit_vrf, | |
1820 | vtysh_exit_vrf_cmd, | |
1821 | "exit", | |
1822 | "Exit current mode and down to previous mode\n") | |
1823 | { | |
1824 | return vtysh_exit (vty); | |
1825 | } | |
1826 | ||
a98d33ab QY |
1827 | DEFUNSH (VTYSH_VRF, |
1828 | vtysh_quit_vrf, | |
1829 | vtysh_quit_vrf_cmd, | |
1830 | "quit", | |
1831 | "Exit current mode and down to previous mode\n") | |
1832 | { | |
1833 | return vtysh_exit_vrf (self, vty, argc, argv); | |
1834 | } | |
e9d94ea7 | 1835 | |
95e735b5 | 1836 | /* TODO Implement interface description commands in ripngd, ospf6d |
1837 | * and isisd. */ | |
4fcbf6e2 | 1838 | DEFSH (VTYSH_ZEBRA|VTYSH_RIPD|VTYSH_OSPFD|VTYSH_LDPD, |
338a9916 | 1839 | interface_desc_cmd, |
e961923c | 1840 | "description LINE...", |
338a9916 | 1841 | "Interface specific description\n" |
1842 | "Characters describing this interface\n") | |
464dc8da | 1843 | |
1844 | DEFSH (VTYSH_ZEBRA|VTYSH_RIPD|VTYSH_OSPFD, | |
1845 | no_interface_desc_cmd, | |
1846 | "no description", | |
1847 | NO_STR | |
1848 | "Interface specific description\n") | |
338a9916 | 1849 | |
95e735b5 | 1850 | DEFUNSH (VTYSH_INTERFACE, |
718e3744 | 1851 | vtysh_exit_interface, |
1852 | vtysh_exit_interface_cmd, | |
1853 | "exit", | |
1854 | "Exit current mode and down to previous mode\n") | |
1855 | { | |
1856 | return vtysh_exit (vty); | |
1857 | } | |
1858 | ||
a98d33ab QY |
1859 | DEFUNSH (VTYSH_INTERFACE, |
1860 | vtysh_quit_interface, | |
1861 | vtysh_quit_interface_cmd, | |
1862 | "quit", | |
1863 | "Exit current mode and down to previous mode\n") | |
1864 | { | |
1865 | return vtysh_exit_interface (self, vty, argc, argv); | |
1866 | } | |
718e3744 | 1867 | |
0f69b58c DS |
1868 | DEFUN (vtysh_show_thread, |
1869 | vtysh_show_thread_cmd, | |
1870 | "show thread cpu [FILTER]", | |
1871 | SHOW_STR | |
1872 | "Thread information\n" | |
1873 | "Thread CPU usage\n" | |
1874 | "Display filter (rwtexb)\n") | |
1875 | { | |
abddf075 | 1876 | int idx_filter = 3; |
0f69b58c DS |
1877 | unsigned int i; |
1878 | int ret = CMD_SUCCESS; | |
1879 | char line[100]; | |
1880 | ||
bfbc035b | 1881 | sprintf(line, "show thread cpu %s\n", (argc == 4) ? argv[idx_filter]->arg : ""); |
0f69b58c DS |
1882 | for (i = 0; i < array_size(vtysh_client); i++) |
1883 | if ( vtysh_client[i].fd >= 0 ) | |
1884 | { | |
1885 | fprintf (stdout, "Thread statistics for %s:\n", | |
1886 | vtysh_client[i].name); | |
1887 | ret = vtysh_client_execute (&vtysh_client[i], line, stdout); | |
1888 | fprintf (stdout,"\n"); | |
1889 | } | |
1890 | return ret; | |
1891 | } | |
1892 | ||
1893 | DEFUN (vtysh_show_work_queues, | |
1894 | vtysh_show_work_queues_cmd, | |
1895 | "show work-queues", | |
1896 | SHOW_STR | |
1897 | "Work Queue information\n") | |
1898 | { | |
1899 | unsigned int i; | |
1900 | int ret = CMD_SUCCESS; | |
1901 | char line[] = "show work-queues\n"; | |
1902 | ||
1903 | for (i = 0; i < array_size(vtysh_client); i++) | |
1904 | if ( vtysh_client[i].fd >= 0 ) | |
1905 | { | |
1906 | fprintf (stdout, "Work queue statistics for %s:\n", | |
1907 | vtysh_client[i].name); | |
1908 | ret = vtysh_client_execute (&vtysh_client[i], line, stdout); | |
1909 | fprintf (stdout,"\n"); | |
1910 | } | |
1911 | ||
1912 | return ret; | |
1913 | } | |
1914 | ||
b47b0a84 DS |
1915 | DEFUN (vtysh_show_work_queues_daemon, |
1916 | vtysh_show_work_queues_daemon_cmd, | |
6147e2c6 | 1917 | "show work-queues <zebra|ripd|ripngd|ospfd|ospf6d|bgpd|isisd>", |
b47b0a84 DS |
1918 | SHOW_STR |
1919 | "Work Queue information\n" | |
1920 | "For the zebra daemon\n" | |
1921 | "For the rip daemon\n" | |
1922 | "For the ripng daemon\n" | |
1923 | "For the ospf daemon\n" | |
1924 | "For the ospfv6 daemon\n" | |
1925 | "For the bgp daemon\n" | |
1926 | "For the isis daemon\n") | |
1927 | { | |
bfbc035b | 1928 | int idx_protocol = 2; |
b47b0a84 DS |
1929 | unsigned int i; |
1930 | int ret = CMD_SUCCESS; | |
1931 | ||
1932 | for (i = 0; i < array_size(vtysh_client); i++) | |
1933 | { | |
bfbc035b | 1934 | if (begins_with(vtysh_client[i].name, argv[idx_protocol]->arg)) |
b47b0a84 DS |
1935 | break; |
1936 | } | |
1937 | ||
1938 | ret = vtysh_client_execute(&vtysh_client[i], "show work-queues\n", stdout); | |
1939 | ||
1940 | return ret; | |
1941 | } | |
1942 | ||
16f1b9ee OD |
1943 | DEFUNSH (VTYSH_ZEBRA, |
1944 | vtysh_link_params, | |
1945 | vtysh_link_params_cmd, | |
1946 | "link-params", | |
1947 | LINK_PARAMS_STR | |
1948 | ) | |
1949 | { | |
1950 | vty->node = LINK_PARAMS_NODE; | |
1951 | return CMD_SUCCESS; | |
1952 | } | |
1953 | ||
03f99d9a DS |
1954 | DEFUNSH (VTYSH_ZEBRA, |
1955 | exit_link_params, | |
1956 | exit_link_params_cmd, | |
1957 | "exit-link-params", | |
1958 | "Exit from Link Params configuration node\n") | |
1959 | { | |
1960 | if (vty->node == LINK_PARAMS_NODE) | |
1961 | vty->node = INTERFACE_NODE; | |
1962 | return CMD_SUCCESS; | |
1963 | } | |
1964 | ||
362b4031 PJ |
1965 | /* Memory */ |
1966 | DEFUN (vtysh_show_memory, | |
1967 | vtysh_show_memory_cmd, | |
1968 | "show memory", | |
1969 | SHOW_STR | |
1970 | "Memory statistics\n") | |
1971 | { | |
1972 | unsigned int i; | |
1973 | int ret = CMD_SUCCESS; | |
1974 | char line[] = "show memory\n"; | |
1975 | ||
837d16cc | 1976 | for (i = 0; i < array_size(vtysh_client); i++) |
362b4031 PJ |
1977 | if ( vtysh_client[i].fd >= 0 ) |
1978 | { | |
1979 | fprintf (stdout, "Memory statistics for %s:\n", | |
1980 | vtysh_client[i].name); | |
1981 | ret = vtysh_client_execute (&vtysh_client[i], line, stdout); | |
1982 | fprintf (stdout,"\n"); | |
1983 | } | |
1984 | ||
1985 | return ret; | |
1986 | } | |
1987 | ||
95e735b5 | 1988 | /* Logging commands. */ |
dbf7d13d PJ |
1989 | DEFUN (vtysh_show_logging, |
1990 | vtysh_show_logging_cmd, | |
1991 | "show logging", | |
1992 | SHOW_STR | |
1993 | "Show current logging configuration\n") | |
1994 | { | |
1995 | unsigned int i; | |
1996 | int ret = CMD_SUCCESS; | |
1997 | char line[] = "show logging\n"; | |
1998 | ||
837d16cc | 1999 | for (i = 0; i < array_size(vtysh_client); i++) |
4150f33e PJ |
2000 | if ( vtysh_client[i].fd >= 0 ) |
2001 | { | |
2002 | fprintf (stdout,"Logging configuration for %s:\n", | |
2003 | vtysh_client[i].name); | |
2004 | ret = vtysh_client_execute (&vtysh_client[i], line, stdout); | |
2005 | fprintf (stdout,"\n"); | |
2006 | } | |
2007 | ||
dbf7d13d PJ |
2008 | return ret; |
2009 | } | |
2010 | ||
95e735b5 | 2011 | DEFUNSH (VTYSH_ALL, |
2012 | vtysh_log_stdout, | |
2013 | vtysh_log_stdout_cmd, | |
2014 | "log stdout", | |
2015 | "Logging control\n" | |
274a4a44 | 2016 | "Set stdout logging level\n") |
2017 | { | |
2018 | return CMD_SUCCESS; | |
2019 | } | |
2020 | ||
2021 | DEFUNSH (VTYSH_ALL, | |
2022 | vtysh_log_stdout_level, | |
2023 | vtysh_log_stdout_level_cmd, | |
199d90a1 | 2024 | "log stdout <emergencies|alerts|critical|errors|warnings|notifications|informational|debugging>", |
274a4a44 | 2025 | "Logging control\n" |
2026 | "Set stdout logging level\n" | |
2027 | LOG_LEVEL_DESC) | |
95e735b5 | 2028 | { |
2029 | return CMD_SUCCESS; | |
2030 | } | |
2031 | ||
2032 | DEFUNSH (VTYSH_ALL, | |
2033 | no_vtysh_log_stdout, | |
2034 | no_vtysh_log_stdout_cmd, | |
274a4a44 | 2035 | "no log stdout [LEVEL]", |
95e735b5 | 2036 | NO_STR |
2037 | "Logging control\n" | |
274a4a44 | 2038 | "Cancel logging to stdout\n" |
2039 | "Logging level\n") | |
95e735b5 | 2040 | { |
2041 | return CMD_SUCCESS; | |
2042 | } | |
2043 | ||
2044 | DEFUNSH (VTYSH_ALL, | |
2045 | vtysh_log_file, | |
2046 | vtysh_log_file_cmd, | |
2047 | "log file FILENAME", | |
2048 | "Logging control\n" | |
2049 | "Logging to file\n" | |
2050 | "Logging filename\n") | |
2051 | { | |
2052 | return CMD_SUCCESS; | |
2053 | } | |
2054 | ||
274a4a44 | 2055 | DEFUNSH (VTYSH_ALL, |
2056 | vtysh_log_file_level, | |
2057 | vtysh_log_file_level_cmd, | |
199d90a1 | 2058 | "log file FILENAME <emergencies|alerts|critical|errors|warnings|notifications|informational|debugging>", |
274a4a44 | 2059 | "Logging control\n" |
2060 | "Logging to file\n" | |
2061 | "Logging filename\n" | |
2062 | LOG_LEVEL_DESC) | |
2063 | { | |
2064 | return CMD_SUCCESS; | |
2065 | } | |
2066 | ||
95e735b5 | 2067 | DEFUNSH (VTYSH_ALL, |
2068 | no_vtysh_log_file, | |
2069 | no_vtysh_log_file_cmd, | |
a98d33ab | 2070 | "no log file [FILENAME [LEVEL]]", |
95e735b5 | 2071 | NO_STR |
2072 | "Logging control\n" | |
2073 | "Cancel logging to file\n" | |
a98d33ab QY |
2074 | "Logging file name\n" |
2075 | "Logging level\n") | |
95e735b5 | 2076 | { |
2077 | return CMD_SUCCESS; | |
2078 | } | |
2079 | ||
274a4a44 | 2080 | DEFUNSH (VTYSH_ALL, |
2081 | vtysh_log_monitor, | |
2082 | vtysh_log_monitor_cmd, | |
e83a9414 | 2083 | "log monitor [<emergencies|alerts|critical|errors|warnings|notifications|informational|debugging>]", |
274a4a44 | 2084 | "Logging control\n" |
2085 | "Set terminal line (monitor) logging level\n" | |
a98d33ab | 2086 | LOG_LEVEL_DESC) |
274a4a44 | 2087 | { |
2088 | return CMD_SUCCESS; | |
2089 | } | |
2090 | ||
2091 | DEFUNSH (VTYSH_ALL, | |
2092 | no_vtysh_log_monitor, | |
2093 | no_vtysh_log_monitor_cmd, | |
2094 | "no log monitor [LEVEL]", | |
2095 | NO_STR | |
2096 | "Logging control\n" | |
2097 | "Disable terminal line (monitor) logging\n" | |
2098 | "Logging level\n") | |
2099 | { | |
2100 | return CMD_SUCCESS; | |
2101 | } | |
2102 | ||
95e735b5 | 2103 | DEFUNSH (VTYSH_ALL, |
2104 | vtysh_log_syslog, | |
2105 | vtysh_log_syslog_cmd, | |
199d90a1 | 2106 | "log syslog <emergencies|alerts|critical|errors|warnings|notifications|informational|debugging>", |
274a4a44 | 2107 | "Logging control\n" |
2108 | "Set syslog logging level\n" | |
a98d33ab | 2109 | LOG_LEVEL_DESC) |
95e735b5 | 2110 | { |
2111 | return CMD_SUCCESS; | |
2112 | } | |
2113 | ||
2114 | DEFUNSH (VTYSH_ALL, | |
2115 | no_vtysh_log_syslog, | |
2116 | no_vtysh_log_syslog_cmd, | |
274a4a44 | 2117 | "no log syslog [LEVEL]", |
95e735b5 | 2118 | NO_STR |
2119 | "Logging control\n" | |
274a4a44 | 2120 | "Cancel logging to syslog\n" |
2121 | "Logging level\n") | |
95e735b5 | 2122 | { |
2123 | return CMD_SUCCESS; | |
2124 | } | |
2125 | ||
2126 | DEFUNSH (VTYSH_ALL, | |
274a4a44 | 2127 | vtysh_log_facility, |
2128 | vtysh_log_facility_cmd, | |
199d90a1 | 2129 | "log facility <kern|user|mail|daemon|auth|syslog|lpr|news|uucp|cron|local0|local1|local2|local3|local4|local5|local6|local7>", |
95e735b5 | 2130 | "Logging control\n" |
274a4a44 | 2131 | "Facility parameter for syslog messages\n" |
2132 | LOG_FACILITY_DESC) | |
2133 | ||
95e735b5 | 2134 | { |
2135 | return CMD_SUCCESS; | |
2136 | } | |
2137 | ||
2138 | DEFUNSH (VTYSH_ALL, | |
274a4a44 | 2139 | no_vtysh_log_facility, |
2140 | no_vtysh_log_facility_cmd, | |
2141 | "no log facility [FACILITY]", | |
95e735b5 | 2142 | NO_STR |
2143 | "Logging control\n" | |
274a4a44 | 2144 | "Reset syslog facility to default (daemon)\n" |
2145 | "Syslog facility\n") | |
2146 | ||
2147 | { | |
2148 | return CMD_SUCCESS; | |
2149 | } | |
2150 | ||
2151 | DEFUNSH_DEPRECATED (VTYSH_ALL, | |
2152 | vtysh_log_trap, | |
2153 | vtysh_log_trap_cmd, | |
199d90a1 | 2154 | "log trap <emergencies|alerts|critical|errors|warnings|notifications|informational|debugging>", |
274a4a44 | 2155 | "Logging control\n" |
2156 | "(Deprecated) Set logging level and default for all destinations\n" | |
2157 | LOG_LEVEL_DESC) | |
2158 | ||
2159 | { | |
2160 | return CMD_SUCCESS; | |
2161 | } | |
2162 | ||
2163 | DEFUNSH_DEPRECATED (VTYSH_ALL, | |
2164 | no_vtysh_log_trap, | |
2165 | no_vtysh_log_trap_cmd, | |
2166 | "no log trap [LEVEL]", | |
2167 | NO_STR | |
2168 | "Logging control\n" | |
2169 | "Permit all logging information\n" | |
2170 | "Logging level\n") | |
95e735b5 | 2171 | { |
2172 | return CMD_SUCCESS; | |
2173 | } | |
2174 | ||
2175 | DEFUNSH (VTYSH_ALL, | |
2176 | vtysh_log_record_priority, | |
2177 | vtysh_log_record_priority_cmd, | |
2178 | "log record-priority", | |
2179 | "Logging control\n" | |
2180 | "Log the priority of the message within the message\n") | |
2181 | { | |
2182 | return CMD_SUCCESS; | |
2183 | } | |
2184 | ||
2185 | DEFUNSH (VTYSH_ALL, | |
2186 | no_vtysh_log_record_priority, | |
2187 | no_vtysh_log_record_priority_cmd, | |
2188 | "no log record-priority", | |
2189 | NO_STR | |
2190 | "Logging control\n" | |
2191 | "Do not log the priority of the message within the message\n") | |
2192 | { | |
2193 | return CMD_SUCCESS; | |
2194 | } | |
2195 | ||
c749b722 AS |
2196 | DEFUNSH (VTYSH_ALL, |
2197 | vtysh_log_timestamp_precision, | |
2198 | vtysh_log_timestamp_precision_cmd, | |
a98d33ab | 2199 | "log timestamp precision (0-6)", |
c749b722 AS |
2200 | "Logging control\n" |
2201 | "Timestamp configuration\n" | |
2202 | "Set the timestamp precision\n" | |
2203 | "Number of subsecond digits\n") | |
2204 | { | |
2205 | return CMD_SUCCESS; | |
2206 | } | |
2207 | ||
2208 | DEFUNSH (VTYSH_ALL, | |
2209 | no_vtysh_log_timestamp_precision, | |
2210 | no_vtysh_log_timestamp_precision_cmd, | |
2211 | "no log timestamp precision", | |
2212 | NO_STR | |
2213 | "Logging control\n" | |
2214 | "Timestamp configuration\n" | |
2215 | "Reset the timestamp precision to the default value of 0\n") | |
2216 | { | |
2217 | return CMD_SUCCESS; | |
2218 | } | |
2219 | ||
e7168df4 | 2220 | DEFUNSH (VTYSH_ALL, |
2221 | vtysh_service_password_encrypt, | |
2222 | vtysh_service_password_encrypt_cmd, | |
2223 | "service password-encryption", | |
2224 | "Set up miscellaneous service\n" | |
2225 | "Enable encrypted passwords\n") | |
2226 | { | |
2227 | return CMD_SUCCESS; | |
2228 | } | |
2229 | ||
2230 | DEFUNSH (VTYSH_ALL, | |
2231 | no_vtysh_service_password_encrypt, | |
2232 | no_vtysh_service_password_encrypt_cmd, | |
2233 | "no service password-encryption", | |
2234 | NO_STR | |
2235 | "Set up miscellaneous service\n" | |
2236 | "Enable encrypted passwords\n") | |
2237 | { | |
2238 | return CMD_SUCCESS; | |
2239 | } | |
2240 | ||
2241 | DEFUNSH (VTYSH_ALL, | |
2242 | vtysh_config_password, | |
2243 | vtysh_password_cmd, | |
a98d33ab | 2244 | "password (8-8) WORD", |
e7168df4 | 2245 | "Assign the terminal connection password\n" |
2246 | "Specifies a HIDDEN password will follow\n" | |
2247 | "dummy string \n" | |
2248 | "The HIDDEN line password string\n") | |
2249 | { | |
2250 | return CMD_SUCCESS; | |
2251 | } | |
2252 | ||
2253 | DEFUNSH (VTYSH_ALL, | |
2254 | vtysh_password_text, | |
2255 | vtysh_password_text_cmd, | |
2256 | "password LINE", | |
2257 | "Assign the terminal connection password\n" | |
2258 | "The UNENCRYPTED (cleartext) line password\n") | |
2259 | { | |
2260 | return CMD_SUCCESS; | |
2261 | } | |
2262 | ||
2263 | DEFUNSH (VTYSH_ALL, | |
2264 | vtysh_config_enable_password, | |
2265 | vtysh_enable_password_cmd, | |
a98d33ab | 2266 | "enable password (8-8) WORD", |
e7168df4 | 2267 | "Modify enable password parameters\n" |
2268 | "Assign the privileged level password\n" | |
2269 | "Specifies a HIDDEN password will follow\n" | |
e7168df4 | 2270 | "The HIDDEN 'enable' password string\n") |
2271 | { | |
2272 | return CMD_SUCCESS; | |
2273 | } | |
2274 | ||
2275 | DEFUNSH (VTYSH_ALL, | |
2276 | vtysh_enable_password_text, | |
2277 | vtysh_enable_password_text_cmd, | |
2278 | "enable password LINE", | |
2279 | "Modify enable password parameters\n" | |
2280 | "Assign the privileged level password\n" | |
2281 | "The UNENCRYPTED (cleartext) 'enable' password\n") | |
2282 | { | |
2283 | return CMD_SUCCESS; | |
2284 | } | |
2285 | ||
2286 | DEFUNSH (VTYSH_ALL, | |
2287 | no_vtysh_config_enable_password, | |
2288 | no_vtysh_enable_password_cmd, | |
2289 | "no enable password", | |
2290 | NO_STR | |
2291 | "Modify enable password parameters\n" | |
2292 | "Assign the privileged level password\n") | |
2293 | { | |
2294 | return CMD_SUCCESS; | |
2295 | } | |
2296 | ||
718e3744 | 2297 | DEFUN (vtysh_write_terminal, |
2298 | vtysh_write_terminal_cmd, | |
e52702f2 | 2299 | "write terminal [<zebra|ripd|ripngd|ospfd|ospf6d|ldpd|bgpd|isisd|pimd>]", |
718e3744 | 2300 | "Write running configuration to memory, network, or terminal\n" |
066242b5 QY |
2301 | "Write to terminal\n" |
2302 | "For the zebra daemon\n" | |
2303 | "For the rip daemon\n" | |
2304 | "For the ripng daemon\n" | |
2305 | "For the ospf daemon\n" | |
2306 | "For the ospfv6 daemon\n" | |
16cedbb0 | 2307 | "For the ldpd daemon\n" |
066242b5 QY |
2308 | "For the bgp daemon\n" |
2309 | "For the isis daemon\n" | |
2310 | "For the pim daemon\n") | |
718e3744 | 2311 | { |
066242b5 QY |
2312 | u_int i; |
2313 | char line[] = "write terminal\n"; | |
718e3744 | 2314 | FILE *fp = NULL; |
2315 | ||
2316 | if (vtysh_pager_name) | |
2317 | { | |
4fc01e67 | 2318 | fp = popen (vtysh_pager_name, "w"); |
718e3744 | 2319 | if (fp == NULL) |
066242b5 QY |
2320 | { |
2321 | perror ("popen"); | |
2322 | exit (1); | |
2323 | } | |
718e3744 | 2324 | } |
2325 | else | |
2326 | fp = stdout; | |
2327 | ||
2328 | vty_out (vty, "Building configuration...%s", VTY_NEWLINE); | |
2329 | vty_out (vty, "%sCurrent configuration:%s", VTY_NEWLINE, | |
066242b5 | 2330 | VTY_NEWLINE); |
e7168df4 | 2331 | vty_out (vty, "!%s", VTY_NEWLINE); |
718e3744 | 2332 | |
066242b5 QY |
2333 | for (i = 0; i < array_size(vtysh_client); i++) |
2334 | if ((argc < 3 ) || (strmatch (vtysh_client[i].name, argv[2]->text))) | |
2335 | vtysh_client_config (&vtysh_client[i], line); | |
2336 | ||
e7168df4 | 2337 | /* Integrate vtysh specific configuration. */ |
2338 | vtysh_config_write (); | |
2339 | ||
718e3744 | 2340 | vtysh_config_dump (fp); |
2341 | ||
2342 | if (vtysh_pager_name && fp) | |
2343 | { | |
2344 | fflush (fp); | |
2345 | if (pclose (fp) == -1) | |
066242b5 QY |
2346 | { |
2347 | perror ("pclose"); | |
2348 | exit (1); | |
2349 | } | |
718e3744 | 2350 | fp = NULL; |
2351 | } | |
2352 | ||
6e79f8bb | 2353 | vty_out (vty, "end%s", VTY_NEWLINE); |
718e3744 | 2354 | return CMD_SUCCESS; |
2355 | } | |
2356 | ||
a98d33ab QY |
2357 | DEFUN (vtysh_show_running_config, |
2358 | vtysh_show_running_config_cmd, | |
e52702f2 | 2359 | "show running-config [<zebra|ripd|ripngd|ospfd|ospf6d|ldpd|bgpd|isisd|pimd>]", |
a98d33ab QY |
2360 | SHOW_STR |
2361 | "Current operating configuration\n" | |
c006e89e DS |
2362 | "For the zebra daemon\n" |
2363 | "For the rip daemon\n" | |
2364 | "For the ripng daemon\n" | |
2365 | "For the ospf daemon\n" | |
2366 | "For the ospfv6 daemon\n" | |
4fcbf6e2 | 2367 | "For the ldp daemon\n" |
c006e89e | 2368 | "For the bgp daemon\n" |
0fab7646 DS |
2369 | "For the isis daemon\n" |
2370 | "For the pim daemon\n") | |
c006e89e | 2371 | { |
a98d33ab | 2372 | return vtysh_write_terminal (self, vty, argc, argv); |
c006e89e DS |
2373 | } |
2374 | ||
e7168df4 | 2375 | DEFUN (vtysh_integrated_config, |
2376 | vtysh_integrated_config_cmd, | |
2377 | "service integrated-vtysh-config", | |
2378 | "Set up miscellaneous service\n" | |
2379 | "Write configuration into integrated file\n") | |
4fc01e67 | 2380 | { |
039eaca3 | 2381 | vtysh_write_integrated = WRITE_INTEGRATED_YES; |
e7168df4 | 2382 | return CMD_SUCCESS; |
4fc01e67 | 2383 | } |
2384 | ||
e7168df4 | 2385 | DEFUN (no_vtysh_integrated_config, |
2386 | no_vtysh_integrated_config_cmd, | |
2387 | "no service integrated-vtysh-config", | |
2388 | NO_STR | |
2389 | "Set up miscellaneous service\n" | |
2390 | "Write configuration into integrated file\n") | |
4fc01e67 | 2391 | { |
039eaca3 | 2392 | vtysh_write_integrated = WRITE_INTEGRATED_NO; |
e7168df4 | 2393 | return CMD_SUCCESS; |
4fc01e67 | 2394 | } |
2395 | ||
a7222276 DS |
2396 | static void |
2397 | backup_config_file (const char *fbackup) | |
718e3744 | 2398 | { |
718e3744 | 2399 | char *integrate_sav = NULL; |
2400 | ||
a7222276 | 2401 | integrate_sav = malloc (strlen (fbackup) + |
95e735b5 | 2402 | strlen (CONF_BACKUP_EXT) + 1); |
a7222276 | 2403 | strcpy (integrate_sav, fbackup); |
718e3744 | 2404 | strcat (integrate_sav, CONF_BACKUP_EXT); |
2405 | ||
95e735b5 | 2406 | /* Move current configuration file to backup config file. */ |
718e3744 | 2407 | unlink (integrate_sav); |
a7222276 | 2408 | rename (fbackup, integrate_sav); |
95e735b5 | 2409 | free (integrate_sav); |
a7222276 DS |
2410 | } |
2411 | ||
a68f8616 DL |
2412 | int |
2413 | vtysh_write_config_integrated(void) | |
a7222276 DS |
2414 | { |
2415 | u_int i; | |
2416 | char line[] = "write terminal\n"; | |
cb947ba3 | 2417 | FILE *fp; |
367988ee DL |
2418 | int fd; |
2419 | struct passwd *pwentry; | |
2420 | struct group *grentry; | |
2421 | uid_t uid = -1; | |
2422 | gid_t gid = -1; | |
2423 | struct stat st; | |
2424 | int err = 0; | |
a7222276 DS |
2425 | |
2426 | fprintf (stdout,"Building Configuration...\n"); | |
2427 | ||
cb947ba3 DL |
2428 | backup_config_file(quagga_config); |
2429 | fp = fopen (quagga_config, "w"); | |
718e3744 | 2430 | if (fp == NULL) |
2431 | { | |
c10c5926 | 2432 | fprintf (stdout,"%% Error: failed to open configuration file %s: %s\n", |
cb947ba3 | 2433 | quagga_config, safe_strerror(errno)); |
c10c5926 | 2434 | return CMD_WARNING; |
a7222276 | 2435 | } |
367988ee | 2436 | fd = fileno (fp); |
a7222276 | 2437 | |
837d16cc | 2438 | for (i = 0; i < array_size(vtysh_client); i++) |
c0e8c16f | 2439 | vtysh_client_config (&vtysh_client[i], line); |
718e3744 | 2440 | |
f64e741e | 2441 | vtysh_config_write (); |
718e3744 | 2442 | vtysh_config_dump (fp); |
2443 | ||
367988ee DL |
2444 | if (fchmod (fd, CONFIGFILE_MASK) != 0) |
2445 | { | |
2446 | printf ("%% Warning: can't chmod configuration file %s: %s\n", | |
2447 | quagga_config, safe_strerror(errno)); | |
2448 | err++; | |
2449 | } | |
718e3744 | 2450 | |
367988ee DL |
2451 | pwentry = getpwnam (QUAGGA_USER); |
2452 | if (pwentry) | |
2453 | uid = pwentry->pw_uid; | |
2454 | else | |
aa593d5e | 2455 | { |
367988ee DL |
2456 | printf ("%% Warning: could not look up user \"%s\"\n", QUAGGA_USER); |
2457 | err++; | |
aa593d5e | 2458 | } |
2459 | ||
367988ee DL |
2460 | grentry = getgrnam (QUAGGA_GROUP); |
2461 | if (grentry) | |
2462 | gid = grentry->gr_gid; | |
2463 | else | |
a7222276 | 2464 | { |
367988ee DL |
2465 | printf ("%% Warning: could not look up group \"%s\"\n", QUAGGA_GROUP); |
2466 | err++; | |
a7222276 | 2467 | } |
4fc01e67 | 2468 | |
367988ee DL |
2469 | if (!fstat (fd, &st)) |
2470 | { | |
2471 | if (st.st_uid == uid) | |
2472 | uid = -1; | |
2473 | if (st.st_gid == gid) | |
2474 | gid = -1; | |
2475 | if ((uid != (uid_t)-1 || gid != (gid_t)-1) && fchown (fd, uid, gid)) | |
2476 | { | |
2477 | printf ("%% Warning: can't chown configuration file %s: %s\n", | |
2478 | quagga_config, safe_strerror(errno)); | |
2479 | err++; | |
2480 | } | |
2481 | } | |
2482 | else | |
2483 | { | |
2484 | printf ("%% Warning: stat() failed on %s: %s\n", | |
2485 | quagga_config, safe_strerror(errno)); | |
2486 | err++; | |
2487 | } | |
2488 | ||
2489 | fclose (fp); | |
4fc01e67 | 2490 | |
c10c5926 | 2491 | printf ("Integrated configuration saved to %s\n", quagga_config); |
367988ee DL |
2492 | if (err) |
2493 | return CMD_WARNING; | |
4fc01e67 | 2494 | |
c10c5926 | 2495 | printf ("[OK]\n"); |
718e3744 | 2496 | return CMD_SUCCESS; |
2497 | } | |
2498 | ||
a68f8616 | 2499 | static bool want_config_integrated(void) |
039eaca3 CF |
2500 | { |
2501 | struct stat s; | |
2502 | ||
2503 | switch (vtysh_write_integrated) | |
2504 | { | |
2505 | case WRITE_INTEGRATED_UNSPECIFIED: | |
cb947ba3 | 2506 | if (stat(quagga_config, &s) && errno == ENOENT) |
039eaca3 CF |
2507 | return false; |
2508 | return true; | |
2509 | case WRITE_INTEGRATED_NO: | |
2510 | return false; | |
2511 | case WRITE_INTEGRATED_YES: | |
2512 | return true; | |
2513 | } | |
3d3c3cbd | 2514 | return true; |
039eaca3 CF |
2515 | } |
2516 | ||
4fc01e67 | 2517 | DEFUN (vtysh_write_memory, |
2518 | vtysh_write_memory_cmd, | |
a98d33ab | 2519 | "write [<memory|file>]", |
4fc01e67 | 2520 | "Write running configuration to memory, network, or terminal\n" |
a98d33ab QY |
2521 | "Write configuration to the file (same as write file)\n" |
2522 | "Write configuration to the file (same as write memory)\n") | |
4fc01e67 | 2523 | { |
dfc0d9ba | 2524 | int ret = CMD_SUCCESS; |
4fc01e67 | 2525 | char line[] = "write memory\n"; |
b1aa147d | 2526 | u_int i; |
a7222276 | 2527 | |
cb947ba3 | 2528 | fprintf (stdout, "Note: this version of vtysh never writes vtysh.conf\n"); |
a7222276 | 2529 | |
e7168df4 | 2530 | /* If integrated Quagga.conf explicitely set. */ |
a68f8616 | 2531 | if (want_config_integrated()) |
a7222276 | 2532 | { |
e10ca9b6 DL |
2533 | ret = CMD_WARNING; |
2534 | for (i = 0; i < array_size(vtysh_client); i++) | |
2535 | if (vtysh_client[i].flag == VTYSH_WATCHQUAGGA) | |
2536 | break; | |
2537 | if (i < array_size(vtysh_client) && vtysh_client[i].fd != -1) | |
2538 | ret = vtysh_client_execute (&vtysh_client[i], "write integrated", stdout); | |
2539 | ||
2540 | if (ret != CMD_SUCCESS) | |
2541 | { | |
c10c5926 | 2542 | printf("\nWarning: attempting direct configuration write without " |
e10ca9b6 | 2543 | "watchquagga.\nFile permissions and ownership may be " |
c10c5926 | 2544 | "incorrect, or write may fail.\n\n"); |
e10ca9b6 DL |
2545 | ret = vtysh_write_config_integrated(); |
2546 | } | |
2547 | return ret; | |
a7222276 DS |
2548 | } |
2549 | ||
4fc01e67 | 2550 | fprintf (stdout,"Building Configuration...\n"); |
a7222276 | 2551 | |
837d16cc | 2552 | for (i = 0; i < array_size(vtysh_client); i++) |
b1aa147d | 2553 | ret = vtysh_client_execute (&vtysh_client[i], line, stdout); |
4fc01e67 | 2554 | |
dfc0d9ba | 2555 | return ret; |
4fc01e67 | 2556 | } |
2557 | ||
a98d33ab QY |
2558 | DEFUN (vtysh_copy_running_config, |
2559 | vtysh_copy_running_config_cmd, | |
2560 | "copy running-config startup-config", | |
718e3744 | 2561 | "Copy from one file to another\n" |
2562 | "Copy from current system configuration\n" | |
2563 | "Copy to startup configuration\n") | |
a98d33ab QY |
2564 | { |
2565 | return vtysh_write_memory (self, vty, argc, argv); | |
2566 | } | |
718e3744 | 2567 | |
34553cc3 | 2568 | DEFUN (vtysh_terminal_length, |
2569 | vtysh_terminal_length_cmd, | |
6147e2c6 | 2570 | "terminal length (0-512)", |
34553cc3 | 2571 | "Set terminal line parameters\n" |
2572 | "Set number of lines on a screen\n" | |
2573 | "Number of lines on screen (0 for no pausing)\n") | |
2574 | { | |
bfbc035b | 2575 | int idx_number = 2; |
34553cc3 | 2576 | int lines; |
2577 | char *endptr = NULL; | |
2578 | char default_pager[10]; | |
2579 | ||
bfbc035b | 2580 | lines = strtol (argv[idx_number]->arg, &endptr, 10); |
34553cc3 | 2581 | if (lines < 0 || lines > 512 || *endptr != '\0') |
2582 | { | |
2583 | vty_out (vty, "length is malformed%s", VTY_NEWLINE); | |
2584 | return CMD_WARNING; | |
2585 | } | |
2586 | ||
2587 | if (vtysh_pager_name) | |
2588 | { | |
2589 | free (vtysh_pager_name); | |
2590 | vtysh_pager_name = NULL; | |
2591 | } | |
2592 | ||
2593 | if (lines != 0) | |
2594 | { | |
2595 | snprintf(default_pager, 10, "more -%i", lines); | |
2596 | vtysh_pager_name = strdup (default_pager); | |
2597 | } | |
2598 | ||
2599 | return CMD_SUCCESS; | |
2600 | } | |
2601 | ||
2602 | DEFUN (vtysh_terminal_no_length, | |
2603 | vtysh_terminal_no_length_cmd, | |
2604 | "terminal no length", | |
2605 | "Set terminal line parameters\n" | |
2606 | NO_STR | |
2607 | "Set number of lines on a screen\n") | |
2608 | { | |
2609 | if (vtysh_pager_name) | |
2610 | { | |
2611 | free (vtysh_pager_name); | |
2612 | vtysh_pager_name = NULL; | |
2613 | } | |
2614 | ||
2615 | vtysh_pager_init(); | |
2616 | return CMD_SUCCESS; | |
2617 | } | |
2618 | ||
f2799e69 | 2619 | DEFUN (vtysh_show_daemons, |
2620 | vtysh_show_daemons_cmd, | |
2621 | "show daemons", | |
e7168df4 | 2622 | SHOW_STR |
2623 | "Show list of running daemons\n") | |
2624 | { | |
b1aa147d | 2625 | u_int i; |
2626 | ||
837d16cc | 2627 | for (i = 0; i < array_size(vtysh_client); i++) |
b1aa147d | 2628 | if ( vtysh_client[i].fd >= 0 ) |
2629 | vty_out(vty, " %s", vtysh_client[i].name); | |
e7168df4 | 2630 | vty_out(vty, "%s", VTY_NEWLINE); |
2631 | ||
2632 | return CMD_SUCCESS; | |
2633 | } | |
2634 | ||
718e3744 | 2635 | /* Execute command in child process. */ |
c0e8c16f | 2636 | static void |
bfbc035b | 2637 | execute_command (const char *command, int argc, struct cmd_token *arg1, |
5862ff52 | 2638 | const char *arg2) |
718e3744 | 2639 | { |
718e3744 | 2640 | pid_t pid; |
2641 | int status; | |
2642 | ||
2643 | /* Call fork(). */ | |
2644 | pid = fork (); | |
2645 | ||
2646 | if (pid < 0) | |
2647 | { | |
2648 | /* Failure of fork(). */ | |
6099b3b5 | 2649 | fprintf (stderr, "Can't fork: %s\n", safe_strerror (errno)); |
718e3744 | 2650 | exit (1); |
2651 | } | |
2652 | else if (pid == 0) | |
2653 | { | |
2654 | /* This is child process. */ | |
2655 | switch (argc) | |
2656 | { | |
2657 | case 0: | |
c0e8c16f | 2658 | execlp (command, command, (const char *)NULL); |
718e3744 | 2659 | break; |
2660 | case 1: | |
c0e8c16f | 2661 | execlp (command, command, arg1, (const char *)NULL); |
718e3744 | 2662 | break; |
2663 | case 2: | |
c0e8c16f | 2664 | execlp (command, command, arg1, arg2, (const char *)NULL); |
718e3744 | 2665 | break; |
2666 | } | |
2667 | ||
2668 | /* When execlp suceed, this part is not executed. */ | |
6099b3b5 | 2669 | fprintf (stderr, "Can't execute %s: %s\n", command, safe_strerror (errno)); |
718e3744 | 2670 | exit (1); |
2671 | } | |
2672 | else | |
2673 | { | |
2674 | /* This is parent. */ | |
2675 | execute_flag = 1; | |
c0e8c16f | 2676 | wait4 (pid, &status, 0, NULL); |
718e3744 | 2677 | execute_flag = 0; |
2678 | } | |
718e3744 | 2679 | } |
2680 | ||
2681 | DEFUN (vtysh_ping, | |
2682 | vtysh_ping_cmd, | |
2683 | "ping WORD", | |
4eeccf18 | 2684 | "Send echo messages\n" |
718e3744 | 2685 | "Ping destination address or hostname\n") |
2686 | { | |
2687 | execute_command ("ping", 1, argv[0], NULL); | |
2688 | return CMD_SUCCESS; | |
2689 | } | |
2690 | ||
4eeccf18 | 2691 | ALIAS (vtysh_ping, |
2692 | vtysh_ping_ip_cmd, | |
2693 | "ping ip WORD", | |
2694 | "Send echo messages\n" | |
2695 | "IP echo\n" | |
2696 | "Ping destination address or hostname\n") | |
2697 | ||
718e3744 | 2698 | DEFUN (vtysh_traceroute, |
2699 | vtysh_traceroute_cmd, | |
2700 | "traceroute WORD", | |
2701 | "Trace route to destination\n" | |
2702 | "Trace route to destination address or hostname\n") | |
2703 | { | |
2704 | execute_command ("traceroute", 1, argv[0], NULL); | |
2705 | return CMD_SUCCESS; | |
2706 | } | |
2707 | ||
4eeccf18 | 2708 | ALIAS (vtysh_traceroute, |
2709 | vtysh_traceroute_ip_cmd, | |
2710 | "traceroute ip WORD", | |
2711 | "Trace route to destination\n" | |
2712 | "IP trace\n" | |
2713 | "Trace route to destination address or hostname\n") | |
2714 | ||
4eeccf18 | 2715 | DEFUN (vtysh_ping6, |
2716 | vtysh_ping6_cmd, | |
2717 | "ping ipv6 WORD", | |
2718 | "Send echo messages\n" | |
2719 | "IPv6 echo\n" | |
2720 | "Ping destination address or hostname\n") | |
2721 | { | |
2722 | execute_command ("ping6", 1, argv[0], NULL); | |
2723 | return CMD_SUCCESS; | |
2724 | } | |
2725 | ||
2726 | DEFUN (vtysh_traceroute6, | |
2727 | vtysh_traceroute6_cmd, | |
2728 | "traceroute ipv6 WORD", | |
2729 | "Trace route to destination\n" | |
2730 | "IPv6 trace\n" | |
2731 | "Trace route to destination address or hostname\n") | |
2732 | { | |
2733 | execute_command ("traceroute6", 1, argv[0], NULL); | |
2734 | return CMD_SUCCESS; | |
2735 | } | |
4eeccf18 | 2736 | |
576b6b5d | 2737 | #if defined(HAVE_SHELL_ACCESS) |
718e3744 | 2738 | DEFUN (vtysh_telnet, |
2739 | vtysh_telnet_cmd, | |
2740 | "telnet WORD", | |
2741 | "Open a telnet connection\n" | |
2742 | "IP address or hostname of a remote system\n") | |
2743 | { | |
2744 | execute_command ("telnet", 1, argv[0], NULL); | |
2745 | return CMD_SUCCESS; | |
2746 | } | |
2747 | ||
2748 | DEFUN (vtysh_telnet_port, | |
2749 | vtysh_telnet_port_cmd, | |
2750 | "telnet WORD PORT", | |
2751 | "Open a telnet connection\n" | |
2752 | "IP address or hostname of a remote system\n" | |
2753 | "TCP Port number\n") | |
2754 | { | |
2755 | execute_command ("telnet", 2, argv[0], argv[1]); | |
2756 | return CMD_SUCCESS; | |
2757 | } | |
2758 | ||
5087df56 | 2759 | DEFUN (vtysh_ssh, |
2760 | vtysh_ssh_cmd, | |
2761 | "ssh WORD", | |
2762 | "Open an ssh connection\n" | |
2763 | "[user@]host\n") | |
2764 | { | |
2765 | execute_command ("ssh", 1, argv[0], NULL); | |
2766 | return CMD_SUCCESS; | |
2767 | } | |
2768 | ||
718e3744 | 2769 | DEFUN (vtysh_start_shell, |
2770 | vtysh_start_shell_cmd, | |
2771 | "start-shell", | |
2772 | "Start UNIX shell\n") | |
2773 | { | |
2774 | execute_command ("sh", 0, NULL, NULL); | |
2775 | return CMD_SUCCESS; | |
2776 | } | |
2777 | ||
2778 | DEFUN (vtysh_start_bash, | |
2779 | vtysh_start_bash_cmd, | |
2780 | "start-shell bash", | |
2781 | "Start UNIX shell\n" | |
2782 | "Start bash\n") | |
2783 | { | |
2784 | execute_command ("bash", 0, NULL, NULL); | |
2785 | return CMD_SUCCESS; | |
2786 | } | |
2787 | ||
2788 | DEFUN (vtysh_start_zsh, | |
2789 | vtysh_start_zsh_cmd, | |
2790 | "start-shell zsh", | |
2791 | "Start UNIX shell\n" | |
2792 | "Start Z shell\n") | |
2793 | { | |
2794 | execute_command ("zsh", 0, NULL, NULL); | |
2795 | return CMD_SUCCESS; | |
2796 | } | |
576b6b5d | 2797 | #endif |
b094d260 | 2798 | |
274a4a44 | 2799 | static void |
718e3744 | 2800 | vtysh_install_default (enum node_type node) |
2801 | { | |
2802 | install_element (node, &config_list_cmd); | |
2803 | } | |
2804 | ||
2805 | /* Making connection to protocol daemon. */ | |
274a4a44 | 2806 | static int |
b1aa147d | 2807 | vtysh_connect (struct vtysh_client *vclient) |
718e3744 | 2808 | { |
2809 | int ret; | |
2810 | int sock, len; | |
2811 | struct sockaddr_un addr; | |
2812 | struct stat s_stat; | |
718e3744 | 2813 | |
718e3744 | 2814 | /* Stat socket to see if we have permission to access it. */ |
b1aa147d | 2815 | ret = stat (vclient->path, &s_stat); |
718e3744 | 2816 | if (ret < 0 && errno != ENOENT) |
2817 | { | |
2818 | fprintf (stderr, "vtysh_connect(%s): stat = %s\n", | |
b1aa147d | 2819 | vclient->path, safe_strerror(errno)); |
718e3744 | 2820 | exit(1); |
2821 | } | |
2822 | ||
2823 | if (ret >= 0) | |
2824 | { | |
2825 | if (! S_ISSOCK(s_stat.st_mode)) | |
2826 | { | |
2827 | fprintf (stderr, "vtysh_connect(%s): Not a socket\n", | |
b1aa147d | 2828 | vclient->path); |
718e3744 | 2829 | exit (1); |
2830 | } | |
2831 | ||
718e3744 | 2832 | } |
2833 | ||
2834 | sock = socket (AF_UNIX, SOCK_STREAM, 0); | |
2835 | if (sock < 0) | |
2836 | { | |
2837 | #ifdef DEBUG | |
b1aa147d | 2838 | fprintf(stderr, "vtysh_connect(%s): socket = %s\n", vclient->path, |
6099b3b5 | 2839 | safe_strerror(errno)); |
718e3744 | 2840 | #endif /* DEBUG */ |
2841 | return -1; | |
2842 | } | |
2843 | ||
2844 | memset (&addr, 0, sizeof (struct sockaddr_un)); | |
2845 | addr.sun_family = AF_UNIX; | |
b1aa147d | 2846 | strncpy (addr.sun_path, vclient->path, strlen (vclient->path)); |
6f0e3f6e | 2847 | #ifdef HAVE_STRUCT_SOCKADDR_UN_SUN_LEN |
718e3744 | 2848 | len = addr.sun_len = SUN_LEN(&addr); |
2849 | #else | |
2850 | len = sizeof (addr.sun_family) + strlen (addr.sun_path); | |
6f0e3f6e | 2851 | #endif /* HAVE_STRUCT_SOCKADDR_UN_SUN_LEN */ |
718e3744 | 2852 | |
2853 | ret = connect (sock, (struct sockaddr *) &addr, len); | |
2854 | if (ret < 0) | |
2855 | { | |
2856 | #ifdef DEBUG | |
b1aa147d | 2857 | fprintf(stderr, "vtysh_connect(%s): connect = %s\n", vclient->path, |
6099b3b5 | 2858 | safe_strerror(errno)); |
718e3744 | 2859 | #endif /* DEBUG */ |
2860 | close (sock); | |
2861 | return -1; | |
2862 | } | |
2863 | vclient->fd = sock; | |
2864 | ||
2865 | return 0; | |
2866 | } | |
2867 | ||
7c8ff89e DS |
2868 | /* Return true if str ends with suffix, else return false */ |
2869 | static int | |
2870 | ends_with(const char *str, const char *suffix) | |
2871 | { | |
2872 | if (!str || !suffix) | |
2873 | return 0; | |
2874 | size_t lenstr = strlen(str); | |
2875 | size_t lensuffix = strlen(suffix); | |
2876 | if (lensuffix > lenstr) | |
2877 | return 0; | |
2878 | return strncmp(str + lenstr - lensuffix, suffix, lensuffix) == 0; | |
2879 | } | |
2880 | ||
2881 | static void | |
2882 | vtysh_client_sorted_insert (struct vtysh_client *head_client, | |
2883 | struct vtysh_client *client) | |
2884 | { | |
2885 | struct vtysh_client *prev_node, *current_node; | |
2886 | ||
2887 | prev_node = head_client; | |
2888 | current_node = head_client->next; | |
2889 | while (current_node) | |
2890 | { | |
2891 | if (strcmp(current_node->path, client->path) > 0) | |
2892 | break; | |
2893 | ||
2894 | prev_node = current_node; | |
2895 | current_node = current_node->next; | |
2896 | } | |
2897 | client->next = current_node; | |
2898 | prev_node->next = client; | |
2899 | } | |
2900 | ||
2901 | #define MAXIMUM_INSTANCES 10 | |
2902 | ||
2903 | static void | |
2904 | vtysh_update_all_insances(struct vtysh_client * head_client) | |
2905 | { | |
2906 | struct vtysh_client *client; | |
c0e8c16f | 2907 | char *ptr; |
7c8ff89e DS |
2908 | DIR *dir; |
2909 | struct dirent *file; | |
2910 | int n = 0; | |
2911 | ||
2912 | if (head_client->flag != VTYSH_OSPFD) return; | |
2913 | ||
2914 | /* ls /var/run/quagga/ and look for all files ending in .vty */ | |
2915 | dir = opendir("/var/run/quagga/"); | |
2916 | if (dir) | |
2917 | { | |
2918 | while ((file = readdir(dir)) != NULL) | |
2919 | { | |
2920 | if (begins_with(file->d_name, "ospfd-") && ends_with(file->d_name, ".vty")) | |
2921 | { | |
2922 | if (n == MAXIMUM_INSTANCES) | |
2923 | { | |
2924 | fprintf(stderr, | |
2925 | "Parsing /var/run/quagga/, client limit(%d) reached!\n", n); | |
2926 | break; | |
2927 | } | |
2928 | client = (struct vtysh_client *) malloc(sizeof(struct vtysh_client)); | |
2929 | client->fd = -1; | |
c0e8c16f | 2930 | client->name = "ospfd"; |
7c8ff89e | 2931 | client->flag = VTYSH_OSPFD; |
c0e8c16f DS |
2932 | ptr = (char *) malloc(100); |
2933 | sprintf(ptr, "/var/run/quagga/%s", file->d_name); | |
2934 | client->path = (const char *)ptr; | |
7c8ff89e DS |
2935 | client->next = NULL; |
2936 | vtysh_client_sorted_insert(head_client, client); | |
2937 | n++; | |
2938 | } | |
2939 | } | |
2940 | closedir(dir); | |
2941 | } | |
2942 | } | |
2943 | ||
4201dd11 | 2944 | static int |
7c8ff89e DS |
2945 | vtysh_connect_all_instances (struct vtysh_client *head_client) |
2946 | { | |
2947 | struct vtysh_client *client; | |
2948 | int rc = 0; | |
2949 | ||
2950 | vtysh_update_all_insances(head_client); | |
2951 | ||
2952 | client = head_client->next; | |
2953 | while (client) | |
2954 | { | |
2955 | if (vtysh_connect(client) == 0) | |
2956 | rc++; | |
2957 | client = client->next; | |
2958 | } | |
2959 | ||
2960 | return rc; | |
2961 | } | |
2962 | ||
f366ad31 AS |
2963 | int |
2964 | vtysh_connect_all(const char *daemon_name) | |
718e3744 | 2965 | { |
b1aa147d | 2966 | u_int i; |
f366ad31 AS |
2967 | int rc = 0; |
2968 | int matches = 0; | |
b1aa147d | 2969 | |
837d16cc | 2970 | for (i = 0; i < array_size(vtysh_client); i++) |
b1aa147d | 2971 | { |
f366ad31 AS |
2972 | if (!daemon_name || !strcmp(daemon_name, vtysh_client[i].name)) |
2973 | { | |
2974 | matches++; | |
2975 | if (vtysh_connect(&vtysh_client[i]) == 0) | |
2976 | rc++; | |
7c8ff89e DS |
2977 | |
2978 | rc += vtysh_connect_all_instances(&vtysh_client[i]); | |
2979 | } | |
b1aa147d | 2980 | } |
f366ad31 AS |
2981 | if (!matches) |
2982 | fprintf(stderr, "Error: no daemons match name %s!\n", daemon_name); | |
2983 | return rc; | |
718e3744 | 2984 | } |
2985 | ||
95e735b5 | 2986 | /* To disable readline's filename completion. */ |
274a4a44 | 2987 | static char * |
dfc0d9ba | 2988 | vtysh_completion_entry_function (const char *ignore, int invoking_key) |
718e3744 | 2989 | { |
dfc0d9ba | 2990 | return NULL; |
718e3744 | 2991 | } |
2992 | ||
2993 | void | |
b1aa147d | 2994 | vtysh_readline_init (void) |
718e3744 | 2995 | { |
2996 | /* readline related settings. */ | |
a7c36d85 | 2997 | rl_initialize (); |
66d2ead7 | 2998 | rl_bind_key ('?', (rl_command_func_t *) vtysh_rl_describe); |
68980084 | 2999 | rl_completion_entry_function = vtysh_completion_entry_function; |
66d2ead7 | 3000 | rl_attempted_completion_function = (rl_completion_func_t *)new_completion; |
718e3744 | 3001 | } |
3002 | ||
3003 | char * | |
b1aa147d | 3004 | vtysh_prompt (void) |
718e3744 | 3005 | { |
f366ad31 | 3006 | static struct utsname names; |
718e3744 | 3007 | static char buf[100]; |
3008 | const char*hostname; | |
3009 | extern struct host host; | |
3010 | ||
3011 | hostname = host.name; | |
3012 | ||
3013 | if (!hostname) | |
3014 | { | |
f366ad31 AS |
3015 | if (!names.nodename[0]) |
3016 | uname (&names); | |
718e3744 | 3017 | hostname = names.nodename; |
3018 | } | |
3019 | ||
3020 | snprintf (buf, sizeof buf, cmd_prompt (vty->node), hostname); | |
3021 | ||
3022 | return buf; | |
3023 | } | |
3024 | ||
3025 | void | |
b1aa147d | 3026 | vtysh_init_vty (void) |
718e3744 | 3027 | { |
3028 | /* Make vty structure. */ | |
3029 | vty = vty_new (); | |
3030 | vty->type = VTY_SHELL; | |
3031 | vty->node = VIEW_NODE; | |
3032 | ||
3033 | /* Initialize commands. */ | |
3034 | cmd_init (0); | |
3035 | ||
3036 | /* Install nodes. */ | |
3037 | install_node (&bgp_node, NULL); | |
3038 | install_node (&rip_node, NULL); | |
3039 | install_node (&interface_node, NULL); | |
16f1b9ee | 3040 | install_node (&link_params_node, NULL); |
13460c44 | 3041 | install_node (&ns_node, NULL); |
e9d94ea7 | 3042 | install_node (&vrf_node, NULL); |
718e3744 | 3043 | install_node (&rmap_node, NULL); |
3044 | install_node (&zebra_node, NULL); | |
3045 | install_node (&bgp_vpnv4_node, NULL); | |
8ecd3266 | 3046 | install_node (&bgp_vpnv6_node, NULL); |
8b1fb8be LB |
3047 | install_node (&bgp_encap_node, NULL); |
3048 | install_node (&bgp_encapv6_node, NULL); | |
718e3744 | 3049 | install_node (&bgp_ipv4_node, NULL); |
3050 | install_node (&bgp_ipv4m_node, NULL); | |
718e3744 | 3051 | install_node (&bgp_ipv6_node, NULL); |
57b5b7ed | 3052 | install_node (&bgp_ipv6m_node, NULL); |
65efcfce LB |
3053 | install_node (&bgp_vnc_defaults_node, NULL); |
3054 | install_node (&bgp_vnc_nve_group_node, NULL); | |
3055 | install_node (&bgp_vnc_l2_group_node, NULL); | |
718e3744 | 3056 | install_node (&ospf_node, NULL); |
718e3744 | 3057 | install_node (&ripng_node, NULL); |
3058 | install_node (&ospf6_node, NULL); | |
4fcbf6e2 RW |
3059 | install_node (&ldp_node, NULL); |
3060 | install_node (&ldp_ipv4_node, NULL); | |
3061 | install_node (&ldp_ipv6_node, NULL); | |
3062 | install_node (&ldp_ipv4_iface_node, NULL); | |
3063 | install_node (&ldp_ipv6_iface_node, NULL); | |
3064 | install_node (&ldp_l2vpn_node, NULL); | |
3065 | install_node (&ldp_pseudowire_node, NULL); | |
718e3744 | 3066 | install_node (&keychain_node, NULL); |
3067 | install_node (&keychain_key_node, NULL); | |
c25e458a | 3068 | install_node (&isis_node, NULL); |
e7168df4 | 3069 | install_node (&vty_node, NULL); |
718e3744 | 3070 | |
3071 | vtysh_install_default (VIEW_NODE); | |
718e3744 | 3072 | vtysh_install_default (CONFIG_NODE); |
3073 | vtysh_install_default (BGP_NODE); | |
3074 | vtysh_install_default (RIP_NODE); | |
3075 | vtysh_install_default (INTERFACE_NODE); | |
16f1b9ee | 3076 | vtysh_install_default (LINK_PARAMS_NODE); |
13460c44 | 3077 | vtysh_install_default (NS_NODE); |
e9d94ea7 | 3078 | vtysh_install_default (VRF_NODE); |
718e3744 | 3079 | vtysh_install_default (RMAP_NODE); |
3080 | vtysh_install_default (ZEBRA_NODE); | |
3081 | vtysh_install_default (BGP_VPNV4_NODE); | |
8ecd3266 | 3082 | vtysh_install_default (BGP_VPNV6_NODE); |
8b1fb8be LB |
3083 | vtysh_install_default (BGP_ENCAP_NODE); |
3084 | vtysh_install_default (BGP_ENCAPV6_NODE); | |
718e3744 | 3085 | vtysh_install_default (BGP_IPV4_NODE); |
3086 | vtysh_install_default (BGP_IPV4M_NODE); | |
3087 | vtysh_install_default (BGP_IPV6_NODE); | |
57b5b7ed | 3088 | vtysh_install_default (BGP_IPV6M_NODE); |
87ab4aec | 3089 | #if ENABLE_BGP_VNC |
65efcfce LB |
3090 | vtysh_install_default (BGP_VNC_DEFAULTS_NODE); |
3091 | vtysh_install_default (BGP_VNC_NVE_GROUP_NODE); | |
3092 | vtysh_install_default (BGP_VNC_L2_GROUP_NODE); | |
87ab4aec | 3093 | #endif |
718e3744 | 3094 | vtysh_install_default (OSPF_NODE); |
3095 | vtysh_install_default (RIPNG_NODE); | |
3096 | vtysh_install_default (OSPF6_NODE); | |
4fcbf6e2 RW |
3097 | vtysh_install_default (LDP_NODE); |
3098 | vtysh_install_default (LDP_IPV4_NODE); | |
3099 | vtysh_install_default (LDP_IPV6_NODE); | |
3100 | vtysh_install_default (LDP_IPV4_IFACE_NODE); | |
3101 | vtysh_install_default (LDP_IPV6_IFACE_NODE); | |
3102 | vtysh_install_default (LDP_L2VPN_NODE); | |
3103 | vtysh_install_default (LDP_PSEUDOWIRE_NODE); | |
c25e458a | 3104 | vtysh_install_default (ISIS_NODE); |
718e3744 | 3105 | vtysh_install_default (KEYCHAIN_NODE); |
3106 | vtysh_install_default (KEYCHAIN_KEY_NODE); | |
e7168df4 | 3107 | vtysh_install_default (VTY_NODE); |
718e3744 | 3108 | |
3109 | install_element (VIEW_NODE, &vtysh_enable_cmd); | |
3110 | install_element (ENABLE_NODE, &vtysh_config_terminal_cmd); | |
3111 | install_element (ENABLE_NODE, &vtysh_disable_cmd); | |
3112 | ||
3113 | /* "exit" command. */ | |
3114 | install_element (VIEW_NODE, &vtysh_exit_all_cmd); | |
718e3744 | 3115 | install_element (CONFIG_NODE, &vtysh_exit_all_cmd); |
3116 | /* install_element (CONFIG_NODE, &vtysh_quit_all_cmd); */ | |
718e3744 | 3117 | install_element (RIP_NODE, &vtysh_exit_ripd_cmd); |
3118 | install_element (RIP_NODE, &vtysh_quit_ripd_cmd); | |
68980084 | 3119 | install_element (RIPNG_NODE, &vtysh_exit_ripngd_cmd); |
3120 | install_element (RIPNG_NODE, &vtysh_quit_ripngd_cmd); | |
718e3744 | 3121 | install_element (OSPF_NODE, &vtysh_exit_ospfd_cmd); |
3122 | install_element (OSPF_NODE, &vtysh_quit_ospfd_cmd); | |
68980084 | 3123 | install_element (OSPF6_NODE, &vtysh_exit_ospf6d_cmd); |
3124 | install_element (OSPF6_NODE, &vtysh_quit_ospf6d_cmd); | |
87ab4aec | 3125 | #if defined (HAVE_LDPD) |
4fcbf6e2 RW |
3126 | install_element (LDP_NODE, &vtysh_exit_ldpd_cmd); |
3127 | install_element (LDP_NODE, &vtysh_quit_ldpd_cmd); | |
3128 | install_element (LDP_IPV4_NODE, &vtysh_exit_ldpd_cmd); | |
3129 | install_element (LDP_IPV4_NODE, &vtysh_quit_ldpd_cmd); | |
3130 | install_element (LDP_IPV6_NODE, &vtysh_exit_ldpd_cmd); | |
3131 | install_element (LDP_IPV6_NODE, &vtysh_quit_ldpd_cmd); | |
3132 | install_element (LDP_IPV4_IFACE_NODE, &vtysh_exit_ldpd_cmd); | |
3133 | install_element (LDP_IPV4_IFACE_NODE, &vtysh_quit_ldpd_cmd); | |
3134 | install_element (LDP_IPV6_IFACE_NODE, &vtysh_exit_ldpd_cmd); | |
3135 | install_element (LDP_IPV6_IFACE_NODE, &vtysh_quit_ldpd_cmd); | |
3136 | install_element (LDP_L2VPN_NODE, &vtysh_exit_ldpd_cmd); | |
3137 | install_element (LDP_L2VPN_NODE, &vtysh_quit_ldpd_cmd); | |
3138 | install_element (LDP_PSEUDOWIRE_NODE, &vtysh_exit_ldpd_cmd); | |
3139 | install_element (LDP_PSEUDOWIRE_NODE, &vtysh_quit_ldpd_cmd); | |
87ab4aec | 3140 | #endif |
718e3744 | 3141 | install_element (BGP_NODE, &vtysh_exit_bgpd_cmd); |
3142 | install_element (BGP_NODE, &vtysh_quit_bgpd_cmd); | |
3143 | install_element (BGP_VPNV4_NODE, &vtysh_exit_bgpd_cmd); | |
3144 | install_element (BGP_VPNV4_NODE, &vtysh_quit_bgpd_cmd); | |
8ecd3266 | 3145 | install_element (BGP_VPNV6_NODE, &vtysh_exit_bgpd_cmd); |
3146 | install_element (BGP_VPNV6_NODE, &vtysh_quit_bgpd_cmd); | |
8b1fb8be LB |
3147 | install_element (BGP_ENCAP_NODE, &vtysh_exit_bgpd_cmd); |
3148 | install_element (BGP_ENCAP_NODE, &vtysh_quit_bgpd_cmd); | |
3149 | install_element (BGP_ENCAPV6_NODE, &vtysh_exit_bgpd_cmd); | |
3150 | install_element (BGP_ENCAPV6_NODE, &vtysh_quit_bgpd_cmd); | |
718e3744 | 3151 | install_element (BGP_IPV4_NODE, &vtysh_exit_bgpd_cmd); |
3152 | install_element (BGP_IPV4_NODE, &vtysh_quit_bgpd_cmd); | |
3153 | install_element (BGP_IPV4M_NODE, &vtysh_exit_bgpd_cmd); | |
3154 | install_element (BGP_IPV4M_NODE, &vtysh_quit_bgpd_cmd); | |
3155 | install_element (BGP_IPV6_NODE, &vtysh_exit_bgpd_cmd); | |
3156 | install_element (BGP_IPV6_NODE, &vtysh_quit_bgpd_cmd); | |
57b5b7ed | 3157 | install_element (BGP_IPV6M_NODE, &vtysh_exit_bgpd_cmd); |
3158 | install_element (BGP_IPV6M_NODE, &vtysh_quit_bgpd_cmd); | |
87ab4aec | 3159 | #if defined (ENABLE_BGP_VNC) |
65efcfce LB |
3160 | install_element (BGP_VNC_DEFAULTS_NODE, &vtysh_exit_bgpd_cmd); |
3161 | install_element (BGP_VNC_DEFAULTS_NODE, &vtysh_quit_bgpd_cmd); | |
3162 | install_element (BGP_VNC_NVE_GROUP_NODE, &vtysh_exit_bgpd_cmd); | |
3163 | install_element (BGP_VNC_NVE_GROUP_NODE, &vtysh_quit_bgpd_cmd); | |
3164 | install_element (BGP_VNC_L2_GROUP_NODE, &vtysh_exit_bgpd_cmd); | |
3165 | install_element (BGP_VNC_L2_GROUP_NODE, &vtysh_quit_bgpd_cmd); | |
87ab4aec | 3166 | #endif |
c25e458a | 3167 | install_element (ISIS_NODE, &vtysh_exit_isisd_cmd); |
3168 | install_element (ISIS_NODE, &vtysh_quit_isisd_cmd); | |
718e3744 | 3169 | install_element (KEYCHAIN_NODE, &vtysh_exit_ripd_cmd); |
3170 | install_element (KEYCHAIN_NODE, &vtysh_quit_ripd_cmd); | |
3171 | install_element (KEYCHAIN_KEY_NODE, &vtysh_exit_ripd_cmd); | |
3172 | install_element (KEYCHAIN_KEY_NODE, &vtysh_quit_ripd_cmd); | |
3173 | install_element (RMAP_NODE, &vtysh_exit_rmap_cmd); | |
3174 | install_element (RMAP_NODE, &vtysh_quit_rmap_cmd); | |
e7168df4 | 3175 | install_element (VTY_NODE, &vtysh_exit_line_vty_cmd); |
3176 | install_element (VTY_NODE, &vtysh_quit_line_vty_cmd); | |
718e3744 | 3177 | |
3178 | /* "end" command. */ | |
3179 | install_element (CONFIG_NODE, &vtysh_end_all_cmd); | |
3180 | install_element (ENABLE_NODE, &vtysh_end_all_cmd); | |
3181 | install_element (RIP_NODE, &vtysh_end_all_cmd); | |
3182 | install_element (RIPNG_NODE, &vtysh_end_all_cmd); | |
3183 | install_element (OSPF_NODE, &vtysh_end_all_cmd); | |
3184 | install_element (OSPF6_NODE, &vtysh_end_all_cmd); | |
4fcbf6e2 RW |
3185 | install_element (LDP_NODE, &vtysh_end_all_cmd); |
3186 | install_element (LDP_IPV4_NODE, &vtysh_end_all_cmd); | |
3187 | install_element (LDP_IPV6_NODE, &vtysh_end_all_cmd); | |
3188 | install_element (LDP_IPV4_IFACE_NODE, &vtysh_end_all_cmd); | |
3189 | install_element (LDP_IPV6_IFACE_NODE, &vtysh_end_all_cmd); | |
3190 | install_element (LDP_L2VPN_NODE, &vtysh_end_all_cmd); | |
3191 | install_element (LDP_PSEUDOWIRE_NODE, &vtysh_end_all_cmd); | |
718e3744 | 3192 | install_element (BGP_NODE, &vtysh_end_all_cmd); |
3193 | install_element (BGP_IPV4_NODE, &vtysh_end_all_cmd); | |
3194 | install_element (BGP_IPV4M_NODE, &vtysh_end_all_cmd); | |
3195 | install_element (BGP_VPNV4_NODE, &vtysh_end_all_cmd); | |
8ecd3266 | 3196 | install_element (BGP_VPNV6_NODE, &vtysh_end_all_cmd); |
8b1fb8be LB |
3197 | install_element (BGP_ENCAP_NODE, &vtysh_end_all_cmd); |
3198 | install_element (BGP_ENCAPV6_NODE, &vtysh_end_all_cmd); | |
718e3744 | 3199 | install_element (BGP_IPV6_NODE, &vtysh_end_all_cmd); |
57b5b7ed | 3200 | install_element (BGP_IPV6M_NODE, &vtysh_end_all_cmd); |
65efcfce LB |
3201 | install_element (BGP_VNC_DEFAULTS_NODE, &vtysh_end_all_cmd); |
3202 | install_element (BGP_VNC_NVE_GROUP_NODE, &vtysh_end_all_cmd); | |
3203 | install_element (BGP_VNC_L2_GROUP_NODE, &vtysh_end_all_cmd); | |
c25e458a | 3204 | install_element (ISIS_NODE, &vtysh_end_all_cmd); |
718e3744 | 3205 | install_element (KEYCHAIN_NODE, &vtysh_end_all_cmd); |
3206 | install_element (KEYCHAIN_KEY_NODE, &vtysh_end_all_cmd); | |
3207 | install_element (RMAP_NODE, &vtysh_end_all_cmd); | |
e7168df4 | 3208 | install_element (VTY_NODE, &vtysh_end_all_cmd); |
718e3744 | 3209 | |
338a9916 | 3210 | install_element (INTERFACE_NODE, &interface_desc_cmd); |
464dc8da | 3211 | install_element (INTERFACE_NODE, &no_interface_desc_cmd); |
718e3744 | 3212 | install_element (INTERFACE_NODE, &vtysh_end_all_cmd); |
3213 | install_element (INTERFACE_NODE, &vtysh_exit_interface_cmd); | |
03f99d9a | 3214 | install_element (LINK_PARAMS_NODE, &exit_link_params_cmd); |
16f1b9ee OD |
3215 | install_element (LINK_PARAMS_NODE, &vtysh_end_all_cmd); |
3216 | install_element (LINK_PARAMS_NODE, &vtysh_exit_interface_cmd); | |
718e3744 | 3217 | install_element (INTERFACE_NODE, &vtysh_quit_interface_cmd); |
e9d94ea7 | 3218 | |
13460c44 FL |
3219 | install_element (NS_NODE, &vtysh_end_all_cmd); |
3220 | install_element (NS_NODE, &vtysh_exit_ns_cmd); | |
3221 | install_element (NS_NODE, &vtysh_quit_ns_cmd); | |
3222 | ||
e9d94ea7 DS |
3223 | install_element (VRF_NODE, &vtysh_end_all_cmd); |
3224 | install_element (VRF_NODE, &vtysh_exit_vrf_cmd); | |
3225 | install_element (VRF_NODE, &vtysh_quit_vrf_cmd); | |
3226 | ||
718e3744 | 3227 | install_element (CONFIG_NODE, &router_rip_cmd); |
718e3744 | 3228 | install_element (CONFIG_NODE, &router_ripng_cmd); |
718e3744 | 3229 | install_element (CONFIG_NODE, &router_ospf_cmd); |
718e3744 | 3230 | install_element (CONFIG_NODE, &router_ospf6_cmd); |
87ab4aec | 3231 | #if defined (HAVE_LDPD) |
4fcbf6e2 RW |
3232 | install_element (CONFIG_NODE, &ldp_mpls_ldp_cmd); |
3233 | install_element (LDP_NODE, &ldp_address_family_ipv4_cmd); | |
3234 | install_element (LDP_NODE, &ldp_address_family_ipv6_cmd); | |
3235 | install_element (LDP_IPV4_NODE, &ldp_interface_ifname_cmd); | |
3236 | install_element (LDP_IPV6_NODE, &ldp_interface_ifname_cmd); | |
3237 | install_element (CONFIG_NODE, &ldp_l2vpn_word_type_vpls_cmd); | |
3238 | install_element (LDP_L2VPN_NODE, &ldp_member_pseudowire_ifname_cmd); | |
87ab4aec | 3239 | #endif |
c25e458a | 3240 | install_element (CONFIG_NODE, &router_isis_cmd); |
718e3744 | 3241 | install_element (CONFIG_NODE, &router_bgp_cmd); |
3242 | install_element (BGP_NODE, &address_family_vpnv4_cmd); | |
8ecd3266 | 3243 | install_element (BGP_NODE, &address_family_vpnv6_cmd); |
4c4ff4c1 | 3244 | install_element (BGP_NODE, &address_family_encapv4_cmd); |
8b1fb8be | 3245 | install_element (BGP_NODE, &address_family_encapv6_cmd); |
87ab4aec | 3246 | #if defined(ENABLE_BGP_VNC) |
65efcfce LB |
3247 | install_element (BGP_NODE, &vnc_defaults_cmd); |
3248 | install_element (BGP_NODE, &vnc_nve_group_cmd); | |
87ab4aec | 3249 | #endif |
718e3744 | 3250 | install_element (BGP_NODE, &address_family_ipv4_unicast_cmd); |
3251 | install_element (BGP_NODE, &address_family_ipv4_multicast_cmd); | |
718e3744 | 3252 | install_element (BGP_NODE, &address_family_ipv6_cmd); |
01a2af45 | 3253 | install_element (BGP_NODE, &address_family_ipv6_multicast_cmd); |
718e3744 | 3254 | install_element (BGP_VPNV4_NODE, &exit_address_family_cmd); |
8ecd3266 | 3255 | install_element (BGP_VPNV6_NODE, &exit_address_family_cmd); |
8b1fb8be LB |
3256 | install_element (BGP_ENCAP_NODE, &exit_address_family_cmd); |
3257 | install_element (BGP_ENCAPV6_NODE, &exit_address_family_cmd); | |
718e3744 | 3258 | install_element (BGP_IPV4_NODE, &exit_address_family_cmd); |
3259 | install_element (BGP_IPV4M_NODE, &exit_address_family_cmd); | |
3260 | install_element (BGP_IPV6_NODE, &exit_address_family_cmd); | |
57b5b7ed | 3261 | install_element (BGP_IPV6M_NODE, &exit_address_family_cmd); |
65efcfce LB |
3262 | |
3263 | install_element (BGP_VNC_DEFAULTS_NODE, &exit_vnc_config_cmd); | |
3264 | install_element (BGP_VNC_NVE_GROUP_NODE, &exit_vnc_config_cmd); | |
3265 | install_element (BGP_VNC_L2_GROUP_NODE, &exit_vnc_config_cmd); | |
3266 | ||
718e3744 | 3267 | install_element (CONFIG_NODE, &key_chain_cmd); |
3268 | install_element (CONFIG_NODE, &route_map_cmd); | |
e7168df4 | 3269 | install_element (CONFIG_NODE, &vtysh_line_vty_cmd); |
718e3744 | 3270 | install_element (KEYCHAIN_NODE, &key_cmd); |
3271 | install_element (KEYCHAIN_NODE, &key_chain_cmd); | |
3272 | install_element (KEYCHAIN_KEY_NODE, &key_chain_cmd); | |
3273 | install_element (CONFIG_NODE, &vtysh_interface_cmd); | |
32d2463c | 3274 | install_element (CONFIG_NODE, &vtysh_no_interface_cmd); |
cd2a8a42 | 3275 | install_element (CONFIG_NODE, &vtysh_no_interface_vrf_cmd); |
16f1b9ee | 3276 | install_element (INTERFACE_NODE, &vtysh_link_params_cmd); |
718e3744 | 3277 | install_element (ENABLE_NODE, &vtysh_show_running_config_cmd); |
a98d33ab | 3278 | install_element (ENABLE_NODE, &vtysh_copy_running_config_cmd); |
718e3744 | 3279 | |
e9d94ea7 DS |
3280 | install_element (CONFIG_NODE, &vtysh_vrf_cmd); |
3281 | install_element (CONFIG_NODE, &vtysh_no_vrf_cmd); | |
3282 | ||
95e735b5 | 3283 | /* "write terminal" command. */ |
718e3744 | 3284 | install_element (ENABLE_NODE, &vtysh_write_terminal_cmd); |
b47b0a84 | 3285 | |
e7168df4 | 3286 | install_element (CONFIG_NODE, &vtysh_integrated_config_cmd); |
3287 | install_element (CONFIG_NODE, &no_vtysh_integrated_config_cmd); | |
718e3744 | 3288 | |
95e735b5 | 3289 | /* "write memory" command. */ |
718e3744 | 3290 | install_element (ENABLE_NODE, &vtysh_write_memory_cmd); |
718e3744 | 3291 | |
34553cc3 | 3292 | install_element (VIEW_NODE, &vtysh_terminal_length_cmd); |
34553cc3 | 3293 | install_element (VIEW_NODE, &vtysh_terminal_no_length_cmd); |
f2799e69 | 3294 | install_element (VIEW_NODE, &vtysh_show_daemons_cmd); |
34553cc3 | 3295 | |
718e3744 | 3296 | install_element (VIEW_NODE, &vtysh_ping_cmd); |
4eeccf18 | 3297 | install_element (VIEW_NODE, &vtysh_ping_ip_cmd); |
718e3744 | 3298 | install_element (VIEW_NODE, &vtysh_traceroute_cmd); |
4eeccf18 | 3299 | install_element (VIEW_NODE, &vtysh_traceroute_ip_cmd); |
4eeccf18 | 3300 | install_element (VIEW_NODE, &vtysh_ping6_cmd); |
3301 | install_element (VIEW_NODE, &vtysh_traceroute6_cmd); | |
576b6b5d | 3302 | #if defined(HAVE_SHELL_ACCESS) |
718e3744 | 3303 | install_element (VIEW_NODE, &vtysh_telnet_cmd); |
3304 | install_element (VIEW_NODE, &vtysh_telnet_port_cmd); | |
5087df56 | 3305 | install_element (VIEW_NODE, &vtysh_ssh_cmd); |
4eeccf18 | 3306 | #endif |
576b6b5d | 3307 | #if defined(HAVE_SHELL_ACCESS) |
718e3744 | 3308 | install_element (ENABLE_NODE, &vtysh_start_shell_cmd); |
3309 | install_element (ENABLE_NODE, &vtysh_start_bash_cmd); | |
3310 | install_element (ENABLE_NODE, &vtysh_start_zsh_cmd); | |
576b6b5d DS |
3311 | #endif |
3312 | ||
362b4031 | 3313 | install_element (VIEW_NODE, &vtysh_show_memory_cmd); |
362b4031 | 3314 | |
0f69b58c | 3315 | install_element (VIEW_NODE, &vtysh_show_work_queues_cmd); |
b47b0a84 | 3316 | install_element (VIEW_NODE, &vtysh_show_work_queues_daemon_cmd); |
0f69b58c DS |
3317 | |
3318 | install_element (VIEW_NODE, &vtysh_show_thread_cmd); | |
0f69b58c | 3319 | |
dbf7d13d | 3320 | /* Logging */ |
dbf7d13d | 3321 | install_element (VIEW_NODE, &vtysh_show_logging_cmd); |
718e3744 | 3322 | install_element (CONFIG_NODE, &vtysh_log_stdout_cmd); |
274a4a44 | 3323 | install_element (CONFIG_NODE, &vtysh_log_stdout_level_cmd); |
718e3744 | 3324 | install_element (CONFIG_NODE, &no_vtysh_log_stdout_cmd); |
3325 | install_element (CONFIG_NODE, &vtysh_log_file_cmd); | |
274a4a44 | 3326 | install_element (CONFIG_NODE, &vtysh_log_file_level_cmd); |
718e3744 | 3327 | install_element (CONFIG_NODE, &no_vtysh_log_file_cmd); |
274a4a44 | 3328 | install_element (CONFIG_NODE, &vtysh_log_monitor_cmd); |
274a4a44 | 3329 | install_element (CONFIG_NODE, &no_vtysh_log_monitor_cmd); |
718e3744 | 3330 | install_element (CONFIG_NODE, &vtysh_log_syslog_cmd); |
3331 | install_element (CONFIG_NODE, &no_vtysh_log_syslog_cmd); | |
3332 | install_element (CONFIG_NODE, &vtysh_log_trap_cmd); | |
3333 | install_element (CONFIG_NODE, &no_vtysh_log_trap_cmd); | |
274a4a44 | 3334 | install_element (CONFIG_NODE, &vtysh_log_facility_cmd); |
3335 | install_element (CONFIG_NODE, &no_vtysh_log_facility_cmd); | |
718e3744 | 3336 | install_element (CONFIG_NODE, &vtysh_log_record_priority_cmd); |
3337 | install_element (CONFIG_NODE, &no_vtysh_log_record_priority_cmd); | |
c749b722 AS |
3338 | install_element (CONFIG_NODE, &vtysh_log_timestamp_precision_cmd); |
3339 | install_element (CONFIG_NODE, &no_vtysh_log_timestamp_precision_cmd); | |
e7168df4 | 3340 | |
3341 | install_element (CONFIG_NODE, &vtysh_service_password_encrypt_cmd); | |
3342 | install_element (CONFIG_NODE, &no_vtysh_service_password_encrypt_cmd); | |
3343 | ||
3344 | install_element (CONFIG_NODE, &vtysh_password_cmd); | |
3345 | install_element (CONFIG_NODE, &vtysh_password_text_cmd); | |
3346 | install_element (CONFIG_NODE, &vtysh_enable_password_cmd); | |
3347 | install_element (CONFIG_NODE, &vtysh_enable_password_text_cmd); | |
3348 | install_element (CONFIG_NODE, &no_vtysh_enable_password_cmd); | |
718e3744 | 3349 | } |