]> git.proxmox.com Git - mirror_frr.git/blob - vtysh/vtysh.c
vtysh: Remove unused variable
[mirror_frr.git] / vtysh / vtysh.c
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 along
17 * with this program; see the file COPYING; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21 #include <zebra.h>
22
23 #include <sys/un.h>
24 #include <setjmp.h>
25 #include <sys/wait.h>
26 #include <sys/resource.h>
27 #include <sys/stat.h>
28
29 #include <readline/readline.h>
30 #include <readline/history.h>
31
32 #include <dirent.h>
33 #include <stdio.h>
34 #include <string.h>
35
36 #include "linklist.h"
37 #include "command.h"
38 #include "memory.h"
39 #include "filter.h"
40 #include "vtysh/vtysh.h"
41 #include "log.h"
42 #include "bgpd/bgp_vty.h"
43 #include "ns.h"
44 #include "vrf.h"
45 #include "libfrr.h"
46 #include "command_graph.h"
47 #include "frrstr.h"
48
49 DEFINE_MTYPE_STATIC(MVTYSH, VTYSH_CMD, "Vtysh cmd copy")
50
51 /* Struct VTY. */
52 struct vty *vty;
53
54 /* VTY shell pager name. */
55 char *vtysh_pager_name = NULL;
56
57 /* VTY shell client structure */
58 struct vtysh_client {
59 int fd;
60 const char *name;
61 int flag;
62 char path[MAXPATHLEN];
63 struct vtysh_client *next;
64 };
65
66 /* Some utility functions for working on vtysh-specific vty tasks */
67
68 static FILE *vty_open_pager(struct vty *vty)
69 {
70 if (vty->is_paged)
71 return vty->of;
72
73 if (!vtysh_pager_name)
74 return NULL;
75
76 vty->of_saved = vty->of;
77 vty->of = popen(vtysh_pager_name, "w");
78 if (vty->of == NULL) {
79 vty->of = vty->of_saved;
80 perror("popen");
81 exit(1);
82 }
83
84 vty->is_paged = true;
85
86 return vty->of;
87 }
88
89 static int vty_close_pager(struct vty *vty)
90 {
91 if (!vty->is_paged)
92 return 0;
93
94 fflush(vty->of);
95 if (pclose(vty->of) == -1) {
96 perror("pclose");
97 exit(1);
98 }
99
100 vty->of = vty->of_saved;
101 vty->is_paged = false;
102
103 return 0;
104 }
105
106 void vtysh_pager_init(void)
107 {
108 char *pager_defined;
109
110 pager_defined = getenv("VTYSH_PAGER");
111
112 if (pager_defined)
113 vtysh_pager_name = strdup(pager_defined);
114 else
115 vtysh_pager_name = strdup(VTYSH_PAGER);
116 }
117
118 /* --- */
119
120 struct vtysh_client vtysh_client[] = {
121 {.fd = -1, .name = "zebra", .flag = VTYSH_ZEBRA, .next = NULL},
122 {.fd = -1, .name = "ripd", .flag = VTYSH_RIPD, .next = NULL},
123 {.fd = -1, .name = "ripngd", .flag = VTYSH_RIPNGD, .next = NULL},
124 {.fd = -1, .name = "ospfd", .flag = VTYSH_OSPFD, .next = NULL},
125 {.fd = -1, .name = "ospf6d", .flag = VTYSH_OSPF6D, .next = NULL},
126 {.fd = -1, .name = "ldpd", .flag = VTYSH_LDPD, .next = NULL},
127 {.fd = -1, .name = "bgpd", .flag = VTYSH_BGPD, .next = NULL},
128 {.fd = -1, .name = "isisd", .flag = VTYSH_ISISD, .next = NULL},
129 {.fd = -1, .name = "pimd", .flag = VTYSH_PIMD, .next = NULL},
130 {.fd = -1, .name = "nhrpd", .flag = VTYSH_NHRPD, .next = NULL},
131 {.fd = -1, .name = "eigrpd", .flag = VTYSH_EIGRPD, .next = NULL},
132 {.fd = -1, .name = "babeld", .flag = VTYSH_BABELD, .next = NULL},
133 {.fd = -1, .name = "sharpd", .flag = VTYSH_SHARPD, .next = NULL},
134 {.fd = -1, .name = "watchfrr", .flag = VTYSH_WATCHFRR, .next = NULL},
135 {.fd = -1, .name = "pbrd", .flag = VTYSH_PBRD, .next = NULL},
136 };
137
138 enum vtysh_write_integrated vtysh_write_integrated =
139 WRITE_INTEGRATED_UNSPECIFIED;
140
141 static int vtysh_reconnect(struct vtysh_client *vclient);
142
143 static void vclient_close(struct vtysh_client *vclient)
144 {
145 if (vclient->fd >= 0) {
146 vty_out(vty,
147 "Warning: closing connection to %s because of an I/O error!\n",
148 vclient->name);
149 close(vclient->fd);
150 /* indicate as candidate for reconnect */
151 vclient->fd = VTYSH_WAS_ACTIVE;
152 }
153 }
154
155 /*
156 * Send a CLI command to a client and read the response.
157 *
158 * Output will be printed to vty->of. If you want to suppress output, set that
159 * to NULL.
160 *
161 * vclient
162 * the client to send the command to
163 *
164 * line
165 * the command to send
166 *
167 * callback
168 * if non-null, this will be called with each line of output received from
169 * the client passed in the second parameter
170 *
171 * cbarg
172 * optional first argument to pass to callback
173 *
174 * Returns:
175 * a status code
176 */
177 static int vtysh_client_run(struct vtysh_client *vclient, const char *line,
178 void (*callback)(void *, const char *), void *cbarg)
179 {
180 int ret;
181 char stackbuf[4096];
182 char *buf = stackbuf;
183 size_t bufsz = sizeof(stackbuf);
184 char *bufvalid, *end = NULL;
185 char terminator[3] = {0, 0, 0};
186
187 /* vclinet was previously active, try to reconnect */
188 if (vclient->fd == VTYSH_WAS_ACTIVE) {
189 ret = vtysh_reconnect(vclient);
190 if (ret < 0)
191 goto out_err;
192 }
193
194 if (vclient->fd < 0)
195 return CMD_SUCCESS;
196
197 ret = write(vclient->fd, line, strlen(line) + 1);
198 if (ret <= 0) {
199 /* close connection and try to reconnect */
200 vclient_close(vclient);
201 ret = vtysh_reconnect(vclient);
202 if (ret < 0)
203 goto out_err;
204 /* retry line */
205 ret = write(vclient->fd, line, strlen(line) + 1);
206 if (ret <= 0)
207 goto out_err;
208 }
209
210 bufvalid = buf;
211 do {
212 ssize_t nread =
213 read(vclient->fd, bufvalid, buf + bufsz - bufvalid - 1);
214
215 if (nread < 0 && (errno == EINTR || errno == EAGAIN))
216 continue;
217
218 if (nread <= 0) {
219 vty_out(vty, "vtysh: error reading from %s: %s (%d)",
220 vclient->name, safe_strerror(errno), errno);
221 goto out_err;
222 }
223
224 bufvalid += nread;
225
226 /* Null terminate so we may pass this to *printf later. */
227 bufvalid[0] = '\0';
228
229 /*
230 * We expect string output from daemons, so instead of looking
231 * for the full 3 null bytes of the terminator, we check for
232 * just one instead and assume it is the first byte of the
233 * terminator. The presence of the full terminator is checked
234 * later.
235 */
236 if (bufvalid - buf >= 4)
237 end = memmem(bufvalid - 4, 4, "\0", 1);
238
239 /*
240 * calculate # bytes we have, up to & not including the
241 * terminator if present
242 */
243 size_t textlen = (end ? end : bufvalid) - buf;
244 bool b = false;
245
246 /* feed line processing callback if present */
247 while (callback && bufvalid > buf && (end > buf || !end)) {
248 textlen = (end ? end : bufvalid) - buf;
249 char *eol = memchr(buf, '\n', textlen);
250 if (eol)
251 /* line break */
252 *eol++ = '\0';
253 else if (end == buf)
254 /*
255 * no line break, end of input, no text left
256 * before end; nothing to write
257 */
258 b = true;
259 else if (end)
260 /* no nl, end of input, but some text left */
261 eol = end;
262 else if (bufvalid == buf + bufsz - 1) {
263 /*
264 * no nl, no end of input, no buffer space;
265 * realloc
266 */
267 char *new;
268
269 bufsz *= 2;
270 if (buf == stackbuf) {
271 new = XMALLOC(MTYPE_TMP, bufsz);
272 memcpy(new, stackbuf, sizeof(stackbuf));
273 } else
274 new = XREALLOC(MTYPE_TMP, buf, bufsz);
275
276 bufvalid = bufvalid - buf + new;
277 buf = new;
278 /* if end != NULL, we won't be reading more
279 * data... */
280 assert(end == NULL);
281 b = true;
282 } else
283 b = true;
284
285 if (b)
286 break;
287
288 /* eol is at line end now, either \n => \0 or \0\0\0 */
289 assert(eol && eol <= bufvalid);
290
291 if (vty->of)
292 vty_out(vty, "%s\n", buf);
293
294 callback(cbarg, buf);
295
296 /* shift back data and adjust bufvalid */
297 memmove(buf, eol, bufvalid - eol);
298 bufvalid -= eol - buf;
299 if (end)
300 end -= eol - buf;
301 }
302
303 /* else if no callback, dump raw */
304 if (!callback) {
305 if (vty->of)
306 vty_out(vty, "%s", buf);
307 memmove(buf, buf + textlen, bufvalid - buf - textlen);
308 bufvalid -= textlen;
309 if (end)
310 end -= textlen;
311
312 /*
313 * ----------------------------------------------------
314 * At this point `buf` should be in one of two states:
315 * - Empty (i.e. buf == bufvalid)
316 * - Contains up to 4 bytes of the terminator
317 * ----------------------------------------------------
318 */
319 assert(((buf == bufvalid)
320 || (bufvalid - buf <= 4 && buf[0] == 0x00)));
321 }
322
323 /* if we have the terminator, break */
324 if (end && bufvalid - buf == 4) {
325 assert(!memcmp(buf, terminator, 3));
326 ret = buf[3];
327 break;
328 }
329
330 } while (true);
331 goto out;
332
333 out_err:
334 vclient_close(vclient);
335 ret = CMD_SUCCESS;
336 out:
337 if (buf != stackbuf)
338 XFREE(MTYPE_TMP, buf);
339 return ret;
340 }
341
342 static int vtysh_client_run_all(struct vtysh_client *head_client,
343 const char *line, int continue_on_err,
344 void (*callback)(void *, const char *),
345 void *cbarg)
346 {
347 struct vtysh_client *client;
348 int rc, rc_all = CMD_SUCCESS;
349 int correct_instance = 0, wrong_instance = 0;
350
351 for (client = head_client; client; client = client->next) {
352 rc = vtysh_client_run(client, line, callback, cbarg);
353 if (rc == CMD_NOT_MY_INSTANCE) {
354 wrong_instance++;
355 continue;
356 }
357 if (client->fd > 0)
358 correct_instance++;
359 if (rc != CMD_SUCCESS) {
360 if (!continue_on_err)
361 return rc;
362 rc_all = rc;
363 }
364 }
365 if (wrong_instance && !correct_instance) {
366 vty_out(vty,
367 "%% [%s]: command ignored as it targets an instance that is not running\n",
368 head_client->name);
369 rc_all = CMD_WARNING_CONFIG_FAILED;
370 }
371 return rc_all;
372 }
373
374 /*
375 * Execute command against all daemons.
376 *
377 * head_client
378 * where to start walking in the daemon list
379 *
380 * line
381 * the specific command to execute
382 *
383 * Returns:
384 * a status code
385 */
386 static int vtysh_client_execute(struct vtysh_client *head_client,
387 const char *line)
388 {
389 return vtysh_client_run_all(head_client, line, 0, NULL, NULL);
390 }
391
392 /*
393 * Retrieve all running config from daemons and parse it with the vtysh config
394 * parser. Returned output is not displayed to the user.
395 *
396 * head_client
397 * where to start walking in the daemon list
398 *
399 * line
400 * the specific command to execute
401 */
402 static void vtysh_client_config(struct vtysh_client *head_client, char *line)
403 {
404 /* watchfrr currently doesn't load any config, and has some hardcoded
405 * settings that show up in "show run". skip it here (for now at
406 * least) so we don't get that mangled up in config-write.
407 */
408 if (head_client->flag == VTYSH_WATCHFRR)
409 return;
410
411 /* suppress output to user */
412 vty->of_saved = vty->of;
413 vty->of = NULL;
414 vtysh_client_run_all(head_client, line, 1, vtysh_config_parse_line,
415 NULL);
416 vty->of = vty->of_saved;
417 }
418
419 /* Command execution over the vty interface. */
420 static int vtysh_execute_func(const char *line, int pager)
421 {
422 int ret, cmd_stat;
423 unsigned int i;
424 vector vline;
425 const struct cmd_element *cmd;
426 int tried = 0;
427 int saved_ret, saved_node;
428
429 /* Split readline string up into the vector. */
430 vline = cmd_make_strvec(line);
431
432 if (vline == NULL)
433 return CMD_SUCCESS;
434
435 if (user_mode) {
436 if (strncmp("en", vector_slot(vline, 0), 2) == 0) {
437 cmd_free_strvec(vline);
438 vty_out(vty, "%% Command not allowed: enable\n");
439 return CMD_WARNING;
440 }
441 }
442
443 saved_ret = ret = cmd_execute(vty, line, &cmd, 1);
444 saved_node = vty->node;
445
446 /*
447 * If command doesn't succeeded in current node, try to walk up in node
448 * tree. Changing vty->node is enough to try it just out without actual
449 * walkup in the vtysh.
450 */
451 while (ret != CMD_SUCCESS && ret != CMD_SUCCESS_DAEMON
452 && ret != CMD_WARNING && ret != CMD_WARNING_CONFIG_FAILED
453 && vty->node > CONFIG_NODE) {
454 vty->node = node_parent(vty->node);
455 ret = cmd_execute(vty, line, &cmd, 1);
456 tried++;
457 }
458
459 vty->node = saved_node;
460
461 /*
462 * If command succeeded in any other node than current (tried > 0) we
463 * have to move into node in the vtysh where it succeeded.
464 */
465 if (ret == CMD_SUCCESS || ret == CMD_SUCCESS_DAEMON
466 || ret == CMD_WARNING) {
467 if ((saved_node == BGP_VPNV4_NODE
468 || saved_node == BGP_VPNV6_NODE
469 || saved_node == BGP_IPV4_NODE
470 || saved_node == BGP_IPV6_NODE
471 || saved_node == BGP_FLOWSPECV4_NODE
472 || saved_node == BGP_FLOWSPECV6_NODE
473 || saved_node == BGP_IPV4M_NODE
474 || saved_node == BGP_IPV4L_NODE
475 || saved_node == BGP_IPV6L_NODE
476 || saved_node == BGP_IPV6M_NODE
477 || saved_node == BGP_EVPN_NODE
478 || saved_node == LDP_IPV4_NODE
479 || saved_node == LDP_IPV6_NODE)
480 && (tried == 1)) {
481 vtysh_execute("exit-address-family");
482 } else if ((saved_node == BGP_EVPN_VNI_NODE) && (tried == 1)) {
483 vtysh_execute("exit-vni");
484 } else if (saved_node == BGP_VRF_POLICY_NODE && (tried == 1)) {
485 vtysh_execute("exit-vrf-policy");
486 } else if ((saved_node == BGP_VNC_DEFAULTS_NODE
487 || saved_node == BGP_VNC_NVE_GROUP_NODE
488 || saved_node == BGP_VNC_L2_GROUP_NODE)
489 && (tried == 1)) {
490 vtysh_execute("exit-vnc");
491 } else if (saved_node == VRF_NODE && (tried == 1)) {
492 vtysh_execute("exit-vrf");
493 } else if ((saved_node == KEYCHAIN_KEY_NODE
494 || saved_node == LDP_PSEUDOWIRE_NODE
495 || saved_node == LDP_IPV4_IFACE_NODE
496 || saved_node == LDP_IPV6_IFACE_NODE)
497 && (tried == 1)) {
498 vtysh_execute("exit");
499 } else if (tried) {
500 vtysh_execute("end");
501 vtysh_execute("configure terminal");
502 }
503 }
504 /*
505 * If command didn't succeed in any node, continue with return value
506 * from first try.
507 */
508 else if (tried) {
509 ret = saved_ret;
510 }
511
512 cmd_free_strvec(vline);
513
514 cmd_stat = ret;
515 switch (ret) {
516 case CMD_WARNING:
517 case CMD_WARNING_CONFIG_FAILED:
518 if (vty->type == VTY_FILE)
519 vty_out(vty, "Warning...\n");
520 break;
521 case CMD_ERR_AMBIGUOUS:
522 vty_out(vty, "%% Ambiguous command: %s\n", line);
523 break;
524 case CMD_ERR_NO_MATCH:
525 vty_out(vty, "%% Unknown command: %s\n", line);
526 break;
527 case CMD_ERR_INCOMPLETE:
528 vty_out(vty, "%% Command incomplete: %s\n", line);
529 break;
530 case CMD_SUCCESS_DAEMON: {
531 /*
532 * FIXME: Don't open pager for exit commands. popen() causes
533 * problems if exited from vtysh at all. This hack shouldn't
534 * cause any problem but is really ugly.
535 */
536 if (pager && strncmp(line, "exit", 4))
537 vty_open_pager(vty);
538
539 if (!strcmp(cmd->string, "configure terminal")) {
540 for (i = 0; i < array_size(vtysh_client); i++) {
541 cmd_stat = vtysh_client_execute(
542 &vtysh_client[i], line);
543 if (cmd_stat == CMD_WARNING)
544 break;
545 }
546
547 if (cmd_stat) {
548 line = "end";
549 vline = cmd_make_strvec(line);
550
551
552 if (vline == NULL) {
553 if (vty->is_paged)
554 vty_close_pager(vty);
555 return CMD_SUCCESS;
556 }
557
558 ret = cmd_execute_command(vline, vty, &cmd, 1);
559 cmd_free_strvec(vline);
560 if (ret != CMD_SUCCESS_DAEMON)
561 break;
562 } else if (cmd->func) {
563 (*cmd->func)(cmd, vty, 0, NULL);
564 break;
565 }
566 }
567
568 cmd_stat = CMD_SUCCESS;
569 struct vtysh_client *vc;
570 for (i = 0; i < array_size(vtysh_client); i++) {
571 if (cmd->daemon & vtysh_client[i].flag) {
572 if (vtysh_client[i].fd < 0
573 && (cmd->daemon == vtysh_client[i].flag)) {
574 for (vc = &vtysh_client[i]; vc;
575 vc = vc->next)
576 if (vc->fd < 0)
577 vtysh_reconnect(vc);
578 }
579 if (vtysh_client[i].fd < 0
580 && (cmd->daemon == vtysh_client[i].flag)) {
581 bool any_inst = false;
582 for (vc = &vtysh_client[i]; vc;
583 vc = vc->next)
584 any_inst = any_inst
585 || (vc->fd > 0);
586 if (!any_inst) {
587 fprintf(stderr,
588 "%s is not running\n",
589 vtysh_client[i].name);
590 continue;
591 }
592 }
593 cmd_stat = vtysh_client_execute(
594 &vtysh_client[i], line);
595 if (cmd_stat != CMD_SUCCESS)
596 break;
597 }
598 }
599 if (cmd_stat != CMD_SUCCESS)
600 break;
601
602 if (cmd->func)
603 (*cmd->func)(cmd, vty, 0, NULL);
604 }
605 }
606 if (vty->is_paged)
607 vty_close_pager(vty);
608
609 return cmd_stat;
610 }
611
612 int vtysh_execute_no_pager(const char *line)
613 {
614 return vtysh_execute_func(line, 0);
615 }
616
617 int vtysh_execute(const char *line)
618 {
619 return vtysh_execute_func(line, 1);
620 }
621
622 static char *trim(char *s)
623 {
624 size_t size;
625 char *end;
626
627 size = strlen(s);
628
629 if (!size)
630 return s;
631
632 end = s + size - 1;
633 while (end >= s && isspace((int)*end))
634 end--;
635 *(end + 1) = '\0';
636
637 while (*s && isspace((int)*s))
638 s++;
639
640 return s;
641 }
642
643 int vtysh_mark_file(const char *filename)
644 {
645 struct vty *vty;
646 FILE *confp = NULL;
647 int ret;
648 vector vline;
649 int tried = 0;
650 const struct cmd_element *cmd;
651 int saved_ret, prev_node;
652 int lineno = 0;
653 char *vty_buf_copy = NULL;
654 char *vty_buf_trimmed = NULL;
655
656 if (strncmp("-", filename, 1) == 0)
657 confp = stdin;
658 else
659 confp = fopen(filename, "r");
660
661 if (confp == NULL) {
662 fprintf(stderr, "%% Can't open config file %s due to '%s'.\n",
663 filename, safe_strerror(errno));
664 return (CMD_ERR_NO_FILE);
665 }
666
667 vty = vty_new();
668 vty->wfd = STDERR_FILENO;
669 vty->type = VTY_TERM;
670 vty->node = CONFIG_NODE;
671
672 vtysh_execute_no_pager("enable");
673 vtysh_execute_no_pager("configure terminal");
674 vty_buf_copy = XCALLOC(MTYPE_VTYSH_CMD, VTY_BUFSIZ);
675
676 while (fgets(vty->buf, VTY_BUFSIZ, confp)) {
677 lineno++;
678 tried = 0;
679 strcpy(vty_buf_copy, vty->buf);
680 vty_buf_trimmed = trim(vty_buf_copy);
681
682 switch (vty->node) {
683 case LDP_IPV4_IFACE_NODE:
684 if (strncmp(vty_buf_copy, " ", 3)) {
685 vty_out(vty, " end\n");
686 vty->node = LDP_IPV4_NODE;
687 }
688 break;
689 case LDP_IPV6_IFACE_NODE:
690 if (strncmp(vty_buf_copy, " ", 3)) {
691 vty_out(vty, " end\n");
692 vty->node = LDP_IPV6_NODE;
693 }
694 break;
695 case LDP_PSEUDOWIRE_NODE:
696 if (strncmp(vty_buf_copy, " ", 2)) {
697 vty_out(vty, " end\n");
698 vty->node = LDP_L2VPN_NODE;
699 }
700 break;
701 default:
702 break;
703 }
704
705 if (vty_buf_trimmed[0] == '!' || vty_buf_trimmed[0] == '#') {
706 vty_out(vty, "%s", vty->buf);
707 continue;
708 }
709
710 /* Split readline string up into the vector. */
711 vline = cmd_make_strvec(vty->buf);
712
713 if (vline == NULL) {
714 vty_out(vty, "%s", vty->buf);
715 continue;
716 }
717
718 /*
719 * Ignore the "end" lines, we will generate these where
720 * appropriate
721 */
722 if (strlen(vty_buf_trimmed) == 3
723 && strncmp("end", vty_buf_trimmed, 3) == 0) {
724 cmd_free_strvec(vline);
725 continue;
726 }
727
728 prev_node = vty->node;
729 saved_ret = ret = cmd_execute_command_strict(vline, vty, &cmd);
730
731 /*
732 * If command doesn't succeeded in current node, try to walk up
733 * in node tree. Changing vty->node is enough to try it just
734 * out without actual walkup in the vtysh.
735 */
736 while (ret != CMD_SUCCESS && ret != CMD_SUCCESS_DAEMON
737 && ret != CMD_WARNING && ret != CMD_WARNING_CONFIG_FAILED
738 && vty->node > CONFIG_NODE) {
739 vty->node = node_parent(vty->node);
740 ret = cmd_execute_command_strict(vline, vty, &cmd);
741 tried++;
742 }
743
744 /*
745 * If command succeeded in any other node than current (tried >
746 * 0) we have to move into node in the vtysh where it
747 * succeeded.
748 */
749 if (ret == CMD_SUCCESS || ret == CMD_SUCCESS_DAEMON
750 || ret == CMD_WARNING) {
751 if ((prev_node == BGP_VPNV4_NODE
752 || prev_node == BGP_VPNV6_NODE
753 || prev_node == BGP_IPV4_NODE
754 || prev_node == BGP_IPV6_NODE
755 || prev_node == BGP_FLOWSPECV4_NODE
756 || prev_node == BGP_FLOWSPECV6_NODE
757 || prev_node == BGP_IPV4L_NODE
758 || prev_node == BGP_IPV6L_NODE
759 || prev_node == BGP_IPV4M_NODE
760 || prev_node == BGP_IPV6M_NODE
761 || prev_node == BGP_EVPN_NODE)
762 && (tried == 1)) {
763 vty_out(vty, "exit-address-family\n");
764 } else if ((prev_node == BGP_EVPN_VNI_NODE)
765 && (tried == 1)) {
766 vty_out(vty, "exit-vni\n");
767 } else if ((prev_node == KEYCHAIN_KEY_NODE)
768 && (tried == 1)) {
769 vty_out(vty, "exit\n");
770 } else if (tried) {
771 vty_out(vty, "end\n");
772 }
773 }
774 /*
775 * If command didn't succeed in any node, continue with return
776 * value from first try.
777 */
778 else if (tried) {
779 ret = saved_ret;
780 vty->node = prev_node;
781 }
782
783 cmd_free_strvec(vline);
784 switch (ret) {
785 case CMD_WARNING:
786 case CMD_WARNING_CONFIG_FAILED:
787 if (vty->type == VTY_FILE)
788 fprintf(stderr, "line %d: Warning...: %s\n",
789 lineno, vty->buf);
790 fclose(confp);
791 vty_close(vty);
792 XFREE(MTYPE_VTYSH_CMD, vty_buf_copy);
793 return ret;
794 case CMD_ERR_AMBIGUOUS:
795 fprintf(stderr, "line %d: %% Ambiguous command: %s\n",
796 lineno, vty->buf);
797 fclose(confp);
798 vty_close(vty);
799 XFREE(MTYPE_VTYSH_CMD, vty_buf_copy);
800 return CMD_ERR_AMBIGUOUS;
801 case CMD_ERR_NO_MATCH:
802 fprintf(stderr, "line %d: %% Unknown command: %s\n",
803 lineno, vty->buf);
804 fclose(confp);
805 vty_close(vty);
806 XFREE(MTYPE_VTYSH_CMD, vty_buf_copy);
807 return CMD_ERR_NO_MATCH;
808 case CMD_ERR_INCOMPLETE:
809 fprintf(stderr, "line %d: %% Command incomplete: %s\n",
810 lineno, vty->buf);
811 fclose(confp);
812 vty_close(vty);
813 XFREE(MTYPE_VTYSH_CMD, vty_buf_copy);
814 return CMD_ERR_INCOMPLETE;
815 case CMD_SUCCESS:
816 vty_out(vty, "%s", vty->buf);
817 break;
818 case CMD_SUCCESS_DAEMON: {
819 int cmd_stat;
820
821 vty_out(vty, "%s", vty->buf);
822 cmd_stat = vtysh_client_execute(&vtysh_client[0],
823 vty->buf);
824 if (cmd_stat != CMD_SUCCESS)
825 break;
826
827 if (cmd->func)
828 (*cmd->func)(cmd, vty, 0, NULL);
829 }
830 }
831 }
832 /* This is the end */
833 vty_out(vty, "\nend\n");
834 vty_close(vty);
835 XFREE(MTYPE_VTYSH_CMD, vty_buf_copy);
836
837 if (confp != stdin)
838 fclose(confp);
839
840 return (0);
841 }
842
843 /* Configration make from file. */
844 int vtysh_config_from_file(struct vty *vty, FILE *fp)
845 {
846 int ret;
847 const struct cmd_element *cmd;
848 int lineno = 0;
849 /* once we have an error, we remember & return that */
850 int retcode = CMD_SUCCESS;
851
852 while (fgets(vty->buf, VTY_BUFSIZ, fp)) {
853 lineno++;
854
855 ret = command_config_read_one_line(vty, &cmd, 1);
856
857 switch (ret) {
858 case CMD_WARNING:
859 case CMD_WARNING_CONFIG_FAILED:
860 if (vty->type == VTY_FILE)
861 fprintf(stderr, "line %d: Warning[%d]...: %s\n",
862 lineno, vty->node, vty->buf);
863 retcode = ret;
864
865 break;
866 case CMD_ERR_AMBIGUOUS:
867 fprintf(stderr,
868 "line %d: %% Ambiguous command[%d]: %s\n",
869 lineno, vty->node, vty->buf);
870 retcode = CMD_ERR_AMBIGUOUS;
871 break;
872 case CMD_ERR_NO_MATCH:
873 fprintf(stderr, "line %d: %% Unknown command[%d]: %s",
874 lineno, vty->node, vty->buf);
875 retcode = CMD_ERR_NO_MATCH;
876 break;
877 case CMD_ERR_INCOMPLETE:
878 fprintf(stderr,
879 "line %d: %% Command incomplete[%d]: %s\n",
880 lineno, vty->node, vty->buf);
881 retcode = CMD_ERR_INCOMPLETE;
882 break;
883 case CMD_SUCCESS_DAEMON: {
884 unsigned int i;
885 int cmd_stat = CMD_SUCCESS;
886
887 for (i = 0; i < array_size(vtysh_client); i++) {
888 if (cmd->daemon & vtysh_client[i].flag) {
889 cmd_stat = vtysh_client_execute(
890 &vtysh_client[i], vty->buf);
891 /*
892 * CMD_WARNING - Can mean that the
893 * command was parsed successfully but
894 * it was already entered in a few
895 * spots. As such if we receive a
896 * CMD_WARNING from a daemon we
897 * shouldn't stop talking to the other
898 * daemons for the particular command.
899 */
900 if (cmd_stat != CMD_SUCCESS
901 && cmd_stat != CMD_WARNING) {
902 fprintf(stderr,
903 "line %d: Failure to communicate[%d] to %s, line: %s\n",
904 lineno, cmd_stat,
905 vtysh_client[i].name,
906 vty->buf);
907 retcode = cmd_stat;
908 break;
909 }
910 }
911 }
912 if (cmd_stat != CMD_SUCCESS)
913 break;
914
915 if (cmd->func)
916 (*cmd->func)(cmd, vty, 0, NULL);
917 }
918 }
919 }
920
921 return (retcode);
922 }
923
924 /*
925 * Function processes cli commands terminated with '?' character when entered
926 * through either 'vtysh' or 'vtysh -c' interfaces.
927 */
928 static int vtysh_process_questionmark(const char *input, int input_len)
929 {
930 int ret, width = 0;
931 unsigned int i;
932 vector vline, describe;
933 struct cmd_token *token;
934
935 if (!input)
936 return 1;
937
938 vline = cmd_make_strvec(input);
939
940 /* In case of '> ?'. */
941 if (vline == NULL) {
942 vline = vector_init(1);
943 vector_set(vline, NULL);
944 } else if (input_len && isspace((int)input[input_len - 1]))
945 vector_set(vline, NULL);
946
947 describe = cmd_describe_command(vline, vty, &ret);
948
949 /* Ambiguous and no match error. */
950 switch (ret) {
951 case CMD_ERR_AMBIGUOUS:
952 cmd_free_strvec(vline);
953 vector_free(describe);
954 vty_out(vty, "%% Ambiguous command.\n");
955 rl_on_new_line();
956 return 0;
957 break;
958 case CMD_ERR_NO_MATCH:
959 cmd_free_strvec(vline);
960 if (describe)
961 vector_free(describe);
962 vty_out(vty, "%% There is no matched command.\n");
963 rl_on_new_line();
964 return 0;
965 break;
966 }
967
968 /* Get width of command string. */
969 width = 0;
970 for (i = 0; i < vector_active(describe); i++)
971 if ((token = vector_slot(describe, i)) != NULL) {
972 if (token->text[0] == '\0')
973 continue;
974
975 int len = strlen(token->text);
976
977 if (width < len)
978 width = len;
979 }
980
981 for (i = 0; i < vector_active(describe); i++)
982 if ((token = vector_slot(describe, i)) != NULL) {
983 if (!token->desc)
984 vty_out(vty, " %-s\n", token->text);
985 else
986 vty_out(vty, " %-*s %s\n", width, token->text,
987 token->desc);
988
989 if (IS_VARYING_TOKEN(token->type)) {
990 const char *ref = vector_slot(
991 vline, vector_active(vline) - 1);
992
993 vector varcomps = vector_init(VECTOR_MIN_SIZE);
994 cmd_variable_complete(token, ref, varcomps);
995
996 if (vector_active(varcomps) > 0) {
997 int rows, cols;
998 rl_get_screen_size(&rows, &cols);
999
1000 char *ac = cmd_variable_comp2str(
1001 varcomps, cols);
1002 vty_out(vty, "%s\n", ac);
1003 XFREE(MTYPE_TMP, ac);
1004 }
1005
1006 vector_free(varcomps);
1007 }
1008 }
1009
1010 cmd_free_strvec(vline);
1011 vector_free(describe);
1012
1013 return 0;
1014 }
1015
1016 /*
1017 * Entry point for user commands terminated with '?' character and typed through
1018 * the usual vtysh's stdin interface. This is the function being registered with
1019 * readline() api's.
1020 */
1021 static int vtysh_rl_describe(int a, int b)
1022 {
1023 int ret;
1024
1025 vty_out(vty, "\n");
1026
1027 ret = vtysh_process_questionmark(rl_line_buffer, rl_end);
1028 rl_on_new_line();
1029
1030 return ret;
1031 }
1032
1033 /*
1034 * Function in charged of processing vtysh instructions terminating with '?'
1035 * character and received through the 'vtysh -c' interface. If user's
1036 * instruction is well-formatted, we will call the same processing routine
1037 * utilized by the traditional vtysh's stdin interface.
1038 */
1039 int vtysh_execute_command_questionmark(char *input)
1040 {
1041 int input_len, qmark_count = 0;
1042 const char *str;
1043
1044 if (!(input && *input))
1045 return 1;
1046
1047 /* Finding out question_mark count and strlen */
1048 for (str = input; *str; ++str) {
1049 if (*str == '?')
1050 qmark_count++;
1051 }
1052 input_len = str - input;
1053
1054 /*
1055 * Verify that user's input terminates in '?' and that patterns such as
1056 * 'cmd ? subcmd ?' are prevented.
1057 */
1058 if (qmark_count != 1 || input[input_len - 1] != '?')
1059 return 1;
1060
1061 /*
1062 * Questionmark-processing function is not expecting to receive '?'
1063 * character in input string.
1064 */
1065 input[input_len - 1] = '\0';
1066
1067 return vtysh_process_questionmark(input, input_len - 1);
1068 }
1069
1070 /* Result of cmd_complete_command() call will be stored here
1071 * and used in new_completion() in order to put the space in
1072 * correct places only. */
1073 int complete_status;
1074
1075 static char *command_generator(const char *text, int state)
1076 {
1077 vector vline;
1078 static char **matched = NULL;
1079 static int index = 0;
1080
1081 /* First call. */
1082 if (!state) {
1083 index = 0;
1084
1085 if (vty->node == AUTH_NODE || vty->node == AUTH_ENABLE_NODE)
1086 return NULL;
1087
1088 vline = cmd_make_strvec(rl_line_buffer);
1089 if (vline == NULL)
1090 return NULL;
1091
1092 if (rl_end && isspace((int)rl_line_buffer[rl_end - 1]))
1093 vector_set(vline, NULL);
1094
1095 matched = cmd_complete_command(vline, vty, &complete_status);
1096 cmd_free_strvec(vline);
1097 }
1098
1099 if (matched && matched[index])
1100 /*
1101 * this is free()'d by readline, but we leak 1 count of
1102 * MTYPE_COMPLETION
1103 */
1104 return matched[index++];
1105
1106 XFREE(MTYPE_TMP, matched);
1107 matched = NULL;
1108
1109 return NULL;
1110 }
1111
1112 static char **new_completion(char *text, int start, int end)
1113 {
1114 char **matches;
1115
1116 matches = rl_completion_matches(text, command_generator);
1117
1118 if (matches) {
1119 rl_point = rl_end;
1120 if (complete_status != CMD_COMPLETE_FULL_MATCH)
1121 /* only append a space on full match */
1122 rl_completion_append_character = '\0';
1123 }
1124
1125 return matches;
1126 }
1127
1128 /* Vty node structures. */
1129 static struct cmd_node bgp_node = {
1130 BGP_NODE, "%s(config-router)# ",
1131 };
1132
1133 static struct cmd_node rip_node = {
1134 RIP_NODE, "%s(config-router)# ",
1135 };
1136
1137 static struct cmd_node isis_node = {
1138 ISIS_NODE, "%s(config-router)# ",
1139 };
1140
1141 static struct cmd_node interface_node = {
1142 INTERFACE_NODE, "%s(config-if)# ",
1143 };
1144
1145 static struct cmd_node pw_node = {
1146 PW_NODE, "%s(config-pw)# ",
1147 };
1148
1149 static struct cmd_node logicalrouter_node = {
1150 LOGICALROUTER_NODE, "%s(config-logical-router)# ",
1151 };
1152
1153 static struct cmd_node vrf_node = {
1154 VRF_NODE, "%s(config-vrf)# ",
1155 };
1156
1157 static struct cmd_node nh_group_node = {
1158 NH_GROUP_NODE,
1159 "%s(config-nh-group)# ",
1160 };
1161
1162 static struct cmd_node rmap_node = {RMAP_NODE, "%s(config-route-map)# "};
1163
1164 static struct cmd_node pbr_map_node = {PBRMAP_NODE, "%s(config-pbr-map)# "};
1165
1166 static struct cmd_node zebra_node = {ZEBRA_NODE, "%s(config-router)# "};
1167
1168 static struct cmd_node bgp_vpnv4_node = {BGP_VPNV4_NODE,
1169 "%s(config-router-af)# "};
1170
1171 static struct cmd_node bgp_vpnv6_node = {BGP_VPNV6_NODE,
1172 "%s(config-router-af)# "};
1173
1174 static struct cmd_node bgp_flowspecv4_node = {BGP_FLOWSPECV4_NODE,
1175 "%s(config-router-af)# "};
1176
1177 static struct cmd_node bgp_flowspecv6_node = {BGP_FLOWSPECV6_NODE,
1178 "%s(config-router-af)# "};
1179
1180 static struct cmd_node bgp_ipv4_node = {BGP_IPV4_NODE,
1181 "%s(config-router-af)# "};
1182
1183 static struct cmd_node bgp_ipv4m_node = {BGP_IPV4M_NODE,
1184 "%s(config-router-af)# "};
1185
1186 static struct cmd_node bgp_ipv4l_node = {BGP_IPV4L_NODE,
1187 "%s(config-router-af)# "};
1188
1189 static struct cmd_node bgp_ipv6_node = {BGP_IPV6_NODE,
1190 "%s(config-router-af)# "};
1191
1192 static struct cmd_node bgp_ipv6m_node = {BGP_IPV6M_NODE,
1193 "%s(config-router-af)# "};
1194
1195 static struct cmd_node bgp_evpn_node = {BGP_EVPN_NODE,
1196 "%s(config-router-af)# "};
1197
1198 static struct cmd_node bgp_evpn_vni_node = {BGP_EVPN_VNI_NODE,
1199 "%s(config-router-af-vni)# "};
1200
1201 static struct cmd_node bgp_ipv6l_node = {BGP_IPV6L_NODE,
1202 "%s(config-router-af)# "};
1203
1204 static struct cmd_node bgp_vnc_defaults_node = {
1205 BGP_VNC_DEFAULTS_NODE, "%s(config-router-vnc-defaults)# "};
1206
1207 static struct cmd_node bgp_vnc_nve_group_node = {
1208 BGP_VNC_NVE_GROUP_NODE, "%s(config-router-vnc-nve-group)# "};
1209
1210 static struct cmd_node bgp_vrf_policy_node = {BGP_VRF_POLICY_NODE,
1211 "%s(config-router-vrf-policy)# "};
1212
1213 static struct cmd_node bgp_vnc_l2_group_node = {
1214 BGP_VNC_L2_GROUP_NODE, "%s(config-router-vnc-l2-group)# "};
1215
1216 static struct cmd_node ospf_node = {OSPF_NODE, "%s(config-router)# "};
1217
1218 static struct cmd_node eigrp_node = {EIGRP_NODE, "%s(config-router)# "};
1219
1220 static struct cmd_node babel_node = {BABEL_NODE, "%s(config-router)# "};
1221
1222 static struct cmd_node ripng_node = {RIPNG_NODE, "%s(config-router)# "};
1223
1224 static struct cmd_node ospf6_node = {OSPF6_NODE, "%s(config-ospf6)# "};
1225
1226 static struct cmd_node ldp_node = {LDP_NODE, "%s(config-ldp)# "};
1227
1228 static struct cmd_node ldp_ipv4_node = {LDP_IPV4_NODE, "%s(config-ldp-af)# "};
1229
1230 static struct cmd_node ldp_ipv6_node = {LDP_IPV6_NODE, "%s(config-ldp-af)# "};
1231
1232 static struct cmd_node ldp_ipv4_iface_node = {LDP_IPV4_IFACE_NODE,
1233 "%s(config-ldp-af-if)# "};
1234
1235 static struct cmd_node ldp_ipv6_iface_node = {LDP_IPV6_IFACE_NODE,
1236 "%s(config-ldp-af-if)# "};
1237
1238 static struct cmd_node ldp_l2vpn_node = {LDP_L2VPN_NODE, "%s(config-l2vpn)# "};
1239
1240 static struct cmd_node ldp_pseudowire_node = {LDP_PSEUDOWIRE_NODE,
1241 "%s(config-l2vpn-pw)# "};
1242
1243 static struct cmd_node keychain_node = {KEYCHAIN_NODE, "%s(config-keychain)# "};
1244
1245 static struct cmd_node keychain_key_node = {KEYCHAIN_KEY_NODE,
1246 "%s(config-keychain-key)# "};
1247
1248 struct cmd_node link_params_node = {
1249 LINK_PARAMS_NODE, "%s(config-link-params)# ",
1250 };
1251
1252 #if defined(HAVE_RPKI)
1253 static struct cmd_node rpki_node = {RPKI_NODE, "%s(config-rpki)# ", 1};
1254 #endif
1255
1256 /* Defined in lib/vty.c */
1257 extern struct cmd_node vty_node;
1258
1259 /* When '^Z' is received from vty, move down to the enable mode. */
1260 static int vtysh_end(void)
1261 {
1262 switch (vty->node) {
1263 case VIEW_NODE:
1264 case ENABLE_NODE:
1265 /* Nothing to do. */
1266 break;
1267 default:
1268 vty->node = ENABLE_NODE;
1269 break;
1270 }
1271 return CMD_SUCCESS;
1272 }
1273
1274 DEFUNSH(VTYSH_REALLYALL, vtysh_end_all, vtysh_end_all_cmd, "end",
1275 "End current mode and change to enable mode\n")
1276 {
1277 return vtysh_end();
1278 }
1279
1280 DEFUNSH(VTYSH_BGPD, router_bgp, router_bgp_cmd,
1281 "router bgp [(1-4294967295) [<view|vrf> WORD]]",
1282 ROUTER_STR BGP_STR AS_STR
1283 "BGP view\nBGP VRF\n"
1284 "View/VRF name\n")
1285 {
1286 vty->node = BGP_NODE;
1287 return CMD_SUCCESS;
1288 }
1289
1290 DEFUNSH(VTYSH_BGPD, address_family_vpnv4, address_family_vpnv4_cmd,
1291 "address-family vpnv4 [unicast]",
1292 "Enter Address Family command mode\n"
1293 "Address Family\n"
1294 "Address Family modifier\n")
1295 {
1296 vty->node = BGP_VPNV4_NODE;
1297 return CMD_SUCCESS;
1298 }
1299
1300 DEFUNSH(VTYSH_BGPD, address_family_vpnv6, address_family_vpnv6_cmd,
1301 "address-family vpnv6 [unicast]",
1302 "Enter Address Family command mode\n"
1303 "Address Family\n"
1304 "Address Family modifier\n")
1305 {
1306 vty->node = BGP_VPNV6_NODE;
1307 return CMD_SUCCESS;
1308 }
1309
1310 DEFUNSH(VTYSH_BGPD, address_family_ipv4, address_family_ipv4_cmd,
1311 "address-family ipv4 [unicast]",
1312 "Enter Address Family command mode\n"
1313 "Address Family\n"
1314 "Address Family Modifier\n")
1315 {
1316 vty->node = BGP_IPV4_NODE;
1317 return CMD_SUCCESS;
1318 }
1319
1320 DEFUNSH(VTYSH_BGPD, address_family_flowspecv4, address_family_flowspecv4_cmd,
1321 "address-family ipv4 flowspec",
1322 "Enter Address Family command mode\n"
1323 "Address Family\n"
1324 "Address Family Modifier\n")
1325 {
1326 vty->node = BGP_FLOWSPECV4_NODE;
1327 return CMD_SUCCESS;
1328 }
1329
1330 DEFUNSH(VTYSH_BGPD, address_family_flowspecv6, address_family_flowspecv6_cmd,
1331 "address-family ipv6 flowspec",
1332 "Enter Address Family command mode\n"
1333 "Address Family\n"
1334 "Address Family Modifier\n")
1335 {
1336 vty->node = BGP_FLOWSPECV6_NODE;
1337 return CMD_SUCCESS;
1338 }
1339
1340 DEFUNSH(VTYSH_BGPD, address_family_ipv4_multicast,
1341 address_family_ipv4_multicast_cmd, "address-family ipv4 multicast",
1342 "Enter Address Family command mode\n"
1343 "Address Family\n"
1344 "Address Family modifier\n")
1345 {
1346 vty->node = BGP_IPV4M_NODE;
1347 return CMD_SUCCESS;
1348 }
1349
1350 DEFUNSH(VTYSH_BGPD, address_family_ipv4_vpn, address_family_ipv4_vpn_cmd,
1351 "address-family ipv4 vpn",
1352 "Enter Address Family command mode\n"
1353 "Address Family\n"
1354 "Address Family modifier\n")
1355 {
1356 vty->node = BGP_VPNV4_NODE;
1357 return CMD_SUCCESS;
1358 }
1359
1360 DEFUNSH(VTYSH_BGPD, address_family_ipv4_labeled_unicast,
1361 address_family_ipv4_labeled_unicast_cmd,
1362 "address-family ipv4 labeled-unicast",
1363 "Enter Address Family command mode\n"
1364 "Address Family\n"
1365 "Address Family modifier\n")
1366 {
1367 vty->node = BGP_IPV4L_NODE;
1368 return CMD_SUCCESS;
1369 }
1370
1371 DEFUNSH(VTYSH_BGPD, address_family_ipv6, address_family_ipv6_cmd,
1372 "address-family ipv6 [unicast]",
1373 "Enter Address Family command mode\n"
1374 "Address Family\n"
1375 "Address Family modifier\n")
1376 {
1377 vty->node = BGP_IPV6_NODE;
1378 return CMD_SUCCESS;
1379 }
1380
1381 DEFUNSH(VTYSH_BGPD, address_family_ipv6_multicast,
1382 address_family_ipv6_multicast_cmd, "address-family ipv6 multicast",
1383 "Enter Address Family command mode\n"
1384 "Address Family\n"
1385 "Address Family modifier\n")
1386 {
1387 vty->node = BGP_IPV6M_NODE;
1388 return CMD_SUCCESS;
1389 }
1390
1391 DEFUNSH(VTYSH_BGPD, address_family_ipv6_vpn, address_family_ipv6_vpn_cmd,
1392 "address-family ipv6 vpn",
1393 "Enter Address Family command mode\n"
1394 "Address Family\n"
1395 "Address Family modifier\n")
1396 {
1397 vty->node = BGP_VPNV6_NODE;
1398 return CMD_SUCCESS;
1399 }
1400
1401 DEFUNSH(VTYSH_BGPD, address_family_ipv6_labeled_unicast,
1402 address_family_ipv6_labeled_unicast_cmd,
1403 "address-family ipv6 labeled-unicast",
1404 "Enter Address Family command mode\n"
1405 "Address Family\n"
1406 "Address Family modifier\n")
1407 {
1408 vty->node = BGP_IPV6L_NODE;
1409 return CMD_SUCCESS;
1410 }
1411
1412 #if defined(HAVE_RPKI)
1413 DEFUNSH(VTYSH_BGPD,
1414 rpki,
1415 rpki_cmd,
1416 "rpki",
1417 "Enable rpki and enter rpki configuration mode\n")
1418 {
1419 vty->node = RPKI_NODE;
1420 return CMD_SUCCESS;
1421 }
1422
1423 DEFUNSH(VTYSH_BGPD,
1424 rpki_exit,
1425 rpki_exit_cmd,
1426 "exit",
1427 "Exit current mode and down to previous mode\n")
1428 {
1429 vty->node = CONFIG_NODE;
1430 return CMD_SUCCESS;
1431 }
1432
1433 DEFUNSH(VTYSH_BGPD,
1434 rpki_quit,
1435 rpki_quit_cmd,
1436 "quit",
1437 "Exit current mode and down to previous mode\n")
1438 {
1439 return rpki_exit(self, vty, argc, argv);
1440 }
1441 #endif
1442
1443 DEFUNSH(VTYSH_BGPD, address_family_evpn, address_family_evpn_cmd,
1444 "address-family <l2vpn evpn>",
1445 "Enter Address Family command mode\n"
1446 "Address Family\n"
1447 "Address Family modifier\n")
1448 {
1449 vty->node = BGP_EVPN_NODE;
1450 return CMD_SUCCESS;
1451 }
1452
1453 #if defined(HAVE_CUMULUS)
1454 DEFUNSH_HIDDEN(VTYSH_BGPD, address_family_evpn2, address_family_evpn2_cmd,
1455 "address-family evpn",
1456 "Enter Address Family command mode\n"
1457 "EVPN Address family\n")
1458 {
1459 vty->node = BGP_EVPN_NODE;
1460 return CMD_SUCCESS;
1461 }
1462 #endif
1463
1464 DEFUNSH(VTYSH_BGPD, bgp_evpn_vni, bgp_evpn_vni_cmd, "vni (1-16777215)",
1465 "VXLAN Network Identifier\n"
1466 "VNI number\n")
1467 {
1468 vty->node = BGP_EVPN_VNI_NODE;
1469 return CMD_SUCCESS;
1470 }
1471
1472 #if defined(ENABLE_BGP_VNC)
1473 DEFUNSH(VTYSH_BGPD, vnc_defaults, vnc_defaults_cmd, "vnc defaults",
1474 "VNC/RFP related configuration\n"
1475 "Configure default NVE group\n")
1476 {
1477 vty->node = BGP_VNC_DEFAULTS_NODE;
1478 return CMD_SUCCESS;
1479 }
1480
1481 DEFUNSH(VTYSH_BGPD, vnc_nve_group, vnc_nve_group_cmd, "vnc nve-group NAME",
1482 "VNC/RFP related configuration\n"
1483 "Configure a NVE group\n"
1484 "Group name\n")
1485 {
1486 vty->node = BGP_VNC_NVE_GROUP_NODE;
1487 return CMD_SUCCESS;
1488 }
1489
1490 DEFUNSH(VTYSH_BGPD, vnc_vrf_policy, vnc_vrf_policy_cmd, "vrf-policy NAME",
1491 "Configure a VRF policy group\n"
1492 "Group name\n")
1493 {
1494 vty->node = BGP_VRF_POLICY_NODE;
1495 return CMD_SUCCESS;
1496 }
1497
1498 DEFUNSH(VTYSH_BGPD, vnc_l2_group, vnc_l2_group_cmd, "vnc l2-group NAME",
1499 "VNC/RFP related configuration\n"
1500 "Configure a L2 group\n"
1501 "Group name\n")
1502 {
1503 vty->node = BGP_VNC_L2_GROUP_NODE;
1504 return CMD_SUCCESS;
1505 }
1506 #endif
1507
1508 DEFUNSH(VTYSH_RIPD, key_chain, key_chain_cmd, "key chain WORD",
1509 "Authentication key management\n"
1510 "Key-chain management\n"
1511 "Key-chain name\n")
1512 {
1513 vty->node = KEYCHAIN_NODE;
1514 return CMD_SUCCESS;
1515 }
1516
1517 DEFUNSH(VTYSH_RIPD, key, key_cmd, "key (0-2147483647)",
1518 "Configure a key\n"
1519 "Key identifier number\n")
1520 {
1521 vty->node = KEYCHAIN_KEY_NODE;
1522 return CMD_SUCCESS;
1523 }
1524
1525 DEFUNSH(VTYSH_RIPD, router_rip, router_rip_cmd, "router rip",
1526 ROUTER_STR "RIP\n")
1527 {
1528 vty->node = RIP_NODE;
1529 return CMD_SUCCESS;
1530 }
1531
1532 DEFUNSH(VTYSH_RIPNGD, router_ripng, router_ripng_cmd, "router ripng",
1533 ROUTER_STR "RIPng\n")
1534 {
1535 vty->node = RIPNG_NODE;
1536 return CMD_SUCCESS;
1537 }
1538
1539 DEFUNSH(VTYSH_OSPFD, router_ospf, router_ospf_cmd,
1540 "router ospf [(1-65535)] [vrf NAME]",
1541 "Enable a routing process\n"
1542 "Start OSPF configuration\n"
1543 "Instance ID\n"
1544 VRF_CMD_HELP_STR)
1545 {
1546 vty->node = OSPF_NODE;
1547 return CMD_SUCCESS;
1548 }
1549
1550 DEFUNSH(VTYSH_EIGRPD, router_eigrp, router_eigrp_cmd, "router eigrp (1-65535)",
1551 "Enable a routing process\n"
1552 "Start EIGRP configuration\n"
1553 "AS number to use\n")
1554 {
1555 vty->node = EIGRP_NODE;
1556 return CMD_SUCCESS;
1557 }
1558
1559 DEFUNSH(VTYSH_BABELD, router_babel, router_babel_cmd, "router babel",
1560 "Enable a routing process\n"
1561 "Make Babel instance command\n")
1562 {
1563 vty->node = BABEL_NODE;
1564 return CMD_SUCCESS;
1565 }
1566
1567 DEFUNSH(VTYSH_OSPF6D, router_ospf6, router_ospf6_cmd, "router ospf6",
1568 ROUTER_STR OSPF6_STR)
1569 {
1570 vty->node = OSPF6_NODE;
1571 return CMD_SUCCESS;
1572 }
1573
1574 #if defined(HAVE_LDPD)
1575 DEFUNSH(VTYSH_LDPD, ldp_mpls_ldp, ldp_mpls_ldp_cmd, "mpls ldp",
1576 "Global MPLS configuration subcommands\n"
1577 "Label Distribution Protocol\n")
1578 {
1579 vty->node = LDP_NODE;
1580 return CMD_SUCCESS;
1581 }
1582
1583 DEFUNSH(VTYSH_LDPD, ldp_address_family_ipv4, ldp_address_family_ipv4_cmd,
1584 "address-family ipv4",
1585 "Configure Address Family and its parameters\n"
1586 "IPv4\n")
1587 {
1588 vty->node = LDP_IPV4_NODE;
1589 return CMD_SUCCESS;
1590 }
1591
1592 DEFUNSH(VTYSH_LDPD, ldp_address_family_ipv6, ldp_address_family_ipv6_cmd,
1593 "address-family ipv6",
1594 "Configure Address Family and its parameters\n"
1595 "IPv6\n")
1596 {
1597 vty->node = LDP_IPV6_NODE;
1598 return CMD_SUCCESS;
1599 }
1600
1601 DEFUNSH(VTYSH_LDPD, ldp_exit_address_family, ldp_exit_address_family_cmd,
1602 "exit-address-family", "Exit from Address Family configuration mode\n")
1603 {
1604 if (vty->node == LDP_IPV4_NODE || vty->node == LDP_IPV6_NODE)
1605 vty->node = LDP_NODE;
1606 return CMD_SUCCESS;
1607 }
1608
1609 DEFUNSH(VTYSH_LDPD, ldp_interface_ifname, ldp_interface_ifname_cmd,
1610 "interface IFNAME",
1611 "Enable LDP on an interface and enter interface submode\n"
1612 "Interface's name\n")
1613 {
1614 switch (vty->node) {
1615 case LDP_IPV4_NODE:
1616 vty->node = LDP_IPV4_IFACE_NODE;
1617 break;
1618 case LDP_IPV6_NODE:
1619 vty->node = LDP_IPV6_IFACE_NODE;
1620 break;
1621 default:
1622 break;
1623 }
1624
1625 return CMD_SUCCESS;
1626 }
1627
1628 DEFUNSH(VTYSH_LDPD, ldp_l2vpn_word_type_vpls, ldp_l2vpn_word_type_vpls_cmd,
1629 "l2vpn WORD type vpls",
1630 "Configure l2vpn commands\n"
1631 "L2VPN name\n"
1632 "L2VPN type\n"
1633 "Virtual Private LAN Service\n")
1634 {
1635 vty->node = LDP_L2VPN_NODE;
1636 return CMD_SUCCESS;
1637 }
1638
1639 DEFUNSH(VTYSH_LDPD, ldp_member_pseudowire_ifname,
1640 ldp_member_pseudowire_ifname_cmd, "member pseudowire IFNAME",
1641 "L2VPN member configuration\n"
1642 "Pseudowire interface\n"
1643 "Interface's name\n")
1644 {
1645 vty->node = LDP_PSEUDOWIRE_NODE;
1646 return CMD_SUCCESS;
1647 }
1648 #endif
1649
1650 DEFUNSH(VTYSH_ISISD, router_isis, router_isis_cmd, "router isis WORD",
1651 ROUTER_STR
1652 "ISO IS-IS\n"
1653 "ISO Routing area tag\n")
1654 {
1655 vty->node = ISIS_NODE;
1656 return CMD_SUCCESS;
1657 }
1658
1659 DEFUNSH(VTYSH_RMAP, vtysh_route_map, vtysh_route_map_cmd,
1660 "route-map WORD <deny|permit> (1-65535)",
1661 "Create route-map or enter route-map command mode\n"
1662 "Route map tag\n"
1663 "Route map denies set operations\n"
1664 "Route map permits set operations\n"
1665 "Sequence to insert to/delete from existing route-map entry\n")
1666 {
1667 vty->node = RMAP_NODE;
1668 return CMD_SUCCESS;
1669 }
1670
1671 DEFUNSH(VTYSH_PBRD, vtysh_pbr_map, vtysh_pbr_map_cmd,
1672 "pbr-map NAME seq (1-700)",
1673 "Create pbr-map or enter pbr-map command mode\n"
1674 "The name of the PBR MAP\n"
1675 "Sequence to insert to/delete from existing pbr-map entry\n"
1676 "Sequence number\n")
1677 {
1678 vty->node = PBRMAP_NODE;
1679 return CMD_SUCCESS;
1680 }
1681
1682 DEFSH(VTYSH_PBRD, vtysh_no_pbr_map_cmd, "no pbr-map WORD [seq (1-700)]",
1683 NO_STR
1684 "Delete pbr-map\n"
1685 "The name of the PBR MAP\n"
1686 "Sequence to delete from existing pbr-map entry\n"
1687 "Sequence number\n")
1688
1689 DEFUNSH(VTYSH_ALL, vtysh_line_vty, vtysh_line_vty_cmd, "line vty",
1690 "Configure a terminal line\n"
1691 "Virtual terminal\n")
1692 {
1693 vty->node = VTY_NODE;
1694 return CMD_SUCCESS;
1695 }
1696
1697 DEFUNSH(VTYSH_REALLYALL, vtysh_enable, vtysh_enable_cmd, "enable",
1698 "Turn on privileged mode command\n")
1699 {
1700 vty->node = ENABLE_NODE;
1701 return CMD_SUCCESS;
1702 }
1703
1704 DEFUNSH(VTYSH_REALLYALL, vtysh_disable, vtysh_disable_cmd, "disable",
1705 "Turn off privileged mode command\n")
1706 {
1707 if (vty->node == ENABLE_NODE)
1708 vty->node = VIEW_NODE;
1709 return CMD_SUCCESS;
1710 }
1711
1712 DEFUNSH(VTYSH_REALLYALL, vtysh_config_terminal, vtysh_config_terminal_cmd,
1713 "configure terminal",
1714 "Configuration from vty interface\n"
1715 "Configuration terminal\n")
1716 {
1717 vty->node = CONFIG_NODE;
1718 return CMD_SUCCESS;
1719 }
1720
1721 static int vtysh_exit(struct vty *vty)
1722 {
1723 switch (vty->node) {
1724 case VIEW_NODE:
1725 case ENABLE_NODE:
1726 exit(0);
1727 break;
1728 case CONFIG_NODE:
1729 vty->node = ENABLE_NODE;
1730 break;
1731 case INTERFACE_NODE:
1732 case PW_NODE:
1733 case LOGICALROUTER_NODE:
1734 case VRF_NODE:
1735 case NH_GROUP_NODE:
1736 case ZEBRA_NODE:
1737 case BGP_NODE:
1738 case RIP_NODE:
1739 case RIPNG_NODE:
1740 case OSPF_NODE:
1741 case OSPF6_NODE:
1742 case EIGRP_NODE:
1743 case BABEL_NODE:
1744 case LDP_NODE:
1745 case LDP_L2VPN_NODE:
1746 case ISIS_NODE:
1747 case RMAP_NODE:
1748 case PBRMAP_NODE:
1749 case VTY_NODE:
1750 case KEYCHAIN_NODE:
1751 vtysh_execute("end");
1752 vtysh_execute("configure terminal");
1753 vty->node = CONFIG_NODE;
1754 break;
1755 case BGP_VPNV4_NODE:
1756 case BGP_VPNV6_NODE:
1757 case BGP_IPV4_NODE:
1758 case BGP_IPV4M_NODE:
1759 case BGP_IPV4L_NODE:
1760 case BGP_IPV6_NODE:
1761 case BGP_IPV6M_NODE:
1762 case BGP_IPV6L_NODE:
1763 case BGP_FLOWSPECV4_NODE:
1764 case BGP_FLOWSPECV6_NODE:
1765 case BGP_VRF_POLICY_NODE:
1766 case BGP_EVPN_NODE:
1767 case BGP_VNC_DEFAULTS_NODE:
1768 case BGP_VNC_NVE_GROUP_NODE:
1769 case BGP_VNC_L2_GROUP_NODE:
1770 vty->node = BGP_NODE;
1771 break;
1772 case BGP_EVPN_VNI_NODE:
1773 vty->node = BGP_EVPN_NODE;
1774 break;
1775 case LDP_IPV4_NODE:
1776 case LDP_IPV6_NODE:
1777 vty->node = LDP_NODE;
1778 break;
1779 case LDP_IPV4_IFACE_NODE:
1780 vty->node = LDP_IPV4_NODE;
1781 break;
1782 case LDP_IPV6_IFACE_NODE:
1783 vty->node = LDP_IPV6_NODE;
1784 break;
1785 case LDP_PSEUDOWIRE_NODE:
1786 vty->node = LDP_L2VPN_NODE;
1787 break;
1788 case KEYCHAIN_KEY_NODE:
1789 vty->node = KEYCHAIN_NODE;
1790 break;
1791 case LINK_PARAMS_NODE:
1792 vty->node = INTERFACE_NODE;
1793 break;
1794 default:
1795 break;
1796 }
1797 return CMD_SUCCESS;
1798 }
1799
1800 DEFUNSH(VTYSH_REALLYALL, vtysh_exit_all, vtysh_exit_all_cmd, "exit",
1801 "Exit current mode and down to previous mode\n")
1802 {
1803 return vtysh_exit(vty);
1804 }
1805
1806 DEFUNSH(VTYSH_ALL, vtysh_quit_all, vtysh_quit_all_cmd, "quit",
1807 "Exit current mode and down to previous mode\n")
1808 {
1809 return vtysh_exit_all(self, vty, argc, argv);
1810 }
1811
1812 DEFUNSH(VTYSH_BGPD, exit_address_family, exit_address_family_cmd,
1813 "exit-address-family", "Exit from Address Family configuration mode\n")
1814 {
1815 if (vty->node == BGP_IPV4_NODE || vty->node == BGP_IPV4M_NODE
1816 || vty->node == BGP_IPV4L_NODE || vty->node == BGP_VPNV4_NODE
1817 || vty->node == BGP_VPNV6_NODE || vty->node == BGP_IPV6_NODE
1818 || vty->node == BGP_IPV6L_NODE || vty->node == BGP_IPV6M_NODE
1819 || vty->node == BGP_EVPN_NODE
1820 || vty->node == BGP_FLOWSPECV4_NODE
1821 || vty->node == BGP_FLOWSPECV6_NODE)
1822 vty->node = BGP_NODE;
1823 return CMD_SUCCESS;
1824 }
1825
1826 DEFUNSH(VTYSH_BGPD, exit_vni, exit_vni_cmd, "exit-vni", "Exit from VNI mode\n")
1827 {
1828 if (vty->node == BGP_EVPN_VNI_NODE)
1829 vty->node = BGP_EVPN_NODE;
1830 return CMD_SUCCESS;
1831 }
1832
1833 DEFUNSH(VTYSH_BGPD, exit_vnc_config, exit_vnc_config_cmd, "exit-vnc",
1834 "Exit from VNC configuration mode\n")
1835 {
1836 if (vty->node == BGP_VNC_DEFAULTS_NODE
1837 || vty->node == BGP_VNC_NVE_GROUP_NODE
1838 || vty->node == BGP_VNC_L2_GROUP_NODE)
1839 vty->node = BGP_NODE;
1840 return CMD_SUCCESS;
1841 }
1842
1843 DEFUNSH(VTYSH_PIMD|VTYSH_ZEBRA, exit_vrf_config, exit_vrf_config_cmd, "exit-vrf",
1844 "Exit from VRF configuration mode\n")
1845 {
1846 if (vty->node == VRF_NODE)
1847 vty->node = CONFIG_NODE;
1848 return CMD_SUCCESS;
1849 }
1850
1851 DEFUNSH(VTYSH_BGPD, exit_vrf_policy, exit_vrf_policy_cmd, "exit-vrf-policy",
1852 "Exit from VRF policy configuration mode\n")
1853 {
1854 if (vty->node == BGP_VRF_POLICY_NODE)
1855 vty->node = BGP_NODE;
1856 return CMD_SUCCESS;
1857 }
1858
1859 DEFUNSH(VTYSH_RIPD, vtysh_exit_ripd, vtysh_exit_ripd_cmd, "exit",
1860 "Exit current mode and down to previous mode\n")
1861 {
1862 return vtysh_exit(vty);
1863 }
1864
1865 DEFUNSH(VTYSH_RIPD, vtysh_quit_ripd, vtysh_quit_ripd_cmd, "quit",
1866 "Exit current mode and down to previous mode\n")
1867 {
1868 return vtysh_exit_ripd(self, vty, argc, argv);
1869 }
1870
1871 DEFUNSH(VTYSH_RIPNGD, vtysh_exit_ripngd, vtysh_exit_ripngd_cmd, "exit",
1872 "Exit current mode and down to previous mode\n")
1873 {
1874 return vtysh_exit(vty);
1875 }
1876
1877 DEFUNSH(VTYSH_RIPNGD, vtysh_quit_ripngd, vtysh_quit_ripngd_cmd, "quit",
1878 "Exit current mode and down to previous mode\n")
1879 {
1880 return vtysh_exit_ripngd(self, vty, argc, argv);
1881 }
1882
1883 DEFUNSH(VTYSH_RMAP, vtysh_exit_rmap, vtysh_exit_rmap_cmd, "exit",
1884 "Exit current mode and down to previous mode\n")
1885 {
1886 return vtysh_exit(vty);
1887 }
1888
1889 DEFUNSH(VTYSH_RMAP, vtysh_quit_rmap, vtysh_quit_rmap_cmd, "quit",
1890 "Exit current mode and down to previous mode\n")
1891 {
1892 return vtysh_exit_rmap(self, vty, argc, argv);
1893 }
1894
1895 DEFUNSH(VTYSH_PBRD, vtysh_exit_pbr_map, vtysh_exit_pbr_map_cmd, "exit",
1896 "Exit current mode and down to previous mode\n")
1897 {
1898 return vtysh_exit(vty);
1899 }
1900
1901 DEFUNSH(VTYSH_PBRD, vtysh_quit_pbr_map, vtysh_quit_pbr_map_cmd, "quit",
1902 "Exit current mode and down to previous mode\n")
1903 {
1904 return vtysh_exit_rmap(self, vty, argc, argv);
1905 }
1906
1907 DEFUNSH(VTYSH_BGPD, vtysh_exit_bgpd, vtysh_exit_bgpd_cmd, "exit",
1908 "Exit current mode and down to previous mode\n")
1909 {
1910 return vtysh_exit(vty);
1911 }
1912
1913 DEFUNSH(VTYSH_BGPD, vtysh_quit_bgpd, vtysh_quit_bgpd_cmd, "quit",
1914 "Exit current mode and down to previous mode\n")
1915 {
1916 return vtysh_exit_bgpd(self, vty, argc, argv);
1917 }
1918
1919 DEFUNSH(VTYSH_OSPFD, vtysh_exit_ospfd, vtysh_exit_ospfd_cmd, "exit",
1920 "Exit current mode and down to previous mode\n")
1921 {
1922 return vtysh_exit(vty);
1923 }
1924
1925 DEFUNSH(VTYSH_OSPFD, vtysh_quit_ospfd, vtysh_quit_ospfd_cmd, "quit",
1926 "Exit current mode and down to previous mode\n")
1927 {
1928 return vtysh_exit_ospfd(self, vty, argc, argv);
1929 }
1930
1931 DEFUNSH(VTYSH_EIGRPD, vtysh_exit_eigrpd, vtysh_exit_eigrpd_cmd, "exit",
1932 "Exit current mode and down to previous mode\n")
1933 {
1934 return vtysh_exit(vty);
1935 }
1936
1937 DEFUNSH(VTYSH_EIGRPD, vtysh_quit_eigrpd, vtysh_quit_eigrpd_cmd, "quit",
1938 "Exit current mode and down to previous mode\n")
1939 {
1940 return vtysh_exit(vty);
1941 }
1942
1943 DEFUNSH(VTYSH_EIGRPD, vtysh_exit_babeld, vtysh_exit_babeld_cmd, "exit",
1944 "Exit current mode and down to previous mode\n")
1945 {
1946 return vtysh_exit(vty);
1947 }
1948
1949 DEFUNSH(VTYSH_BABELD, vtysh_quit_babeld, vtysh_quit_babeld_cmd, "quit",
1950 "Exit current mode and down to previous mode\n")
1951 {
1952 return vtysh_exit(vty);
1953 }
1954
1955 DEFUNSH(VTYSH_OSPF6D, vtysh_exit_ospf6d, vtysh_exit_ospf6d_cmd, "exit",
1956 "Exit current mode and down to previous mode\n")
1957 {
1958 return vtysh_exit(vty);
1959 }
1960
1961 DEFUNSH(VTYSH_OSPF6D, vtysh_quit_ospf6d, vtysh_quit_ospf6d_cmd, "quit",
1962 "Exit current mode and down to previous mode\n")
1963 {
1964 return vtysh_exit_ospf6d(self, vty, argc, argv);
1965 }
1966
1967 #if defined(HAVE_LDPD)
1968 DEFUNSH(VTYSH_LDPD, vtysh_exit_ldpd, vtysh_exit_ldpd_cmd, "exit",
1969 "Exit current mode and down to previous mode\n")
1970 {
1971 return vtysh_exit(vty);
1972 }
1973
1974 ALIAS(vtysh_exit_ldpd, vtysh_quit_ldpd_cmd, "quit",
1975 "Exit current mode and down to previous mode\n")
1976 #endif
1977
1978 DEFUNSH(VTYSH_ISISD, vtysh_exit_isisd, vtysh_exit_isisd_cmd, "exit",
1979 "Exit current mode and down to previous mode\n")
1980 {
1981 return vtysh_exit(vty);
1982 }
1983
1984 DEFUNSH(VTYSH_ISISD, vtysh_quit_isisd, vtysh_quit_isisd_cmd, "quit",
1985 "Exit current mode and down to previous mode\n")
1986 {
1987 return vtysh_exit_isisd(self, vty, argc, argv);
1988 }
1989
1990 DEFUNSH(VTYSH_ALL, vtysh_exit_line_vty, vtysh_exit_line_vty_cmd, "exit",
1991 "Exit current mode and down to previous mode\n")
1992 {
1993 return vtysh_exit(vty);
1994 }
1995
1996 DEFUNSH(VTYSH_ALL, vtysh_quit_line_vty, vtysh_quit_line_vty_cmd, "quit",
1997 "Exit current mode and down to previous mode\n")
1998 {
1999 return vtysh_exit_line_vty(self, vty, argc, argv);
2000 }
2001
2002 DEFUNSH(VTYSH_INTERFACE, vtysh_interface, vtysh_interface_cmd,
2003 "interface IFNAME [vrf NAME]",
2004 "Select an interface to configure\n"
2005 "Interface's name\n" VRF_CMD_HELP_STR)
2006 {
2007 vty->node = INTERFACE_NODE;
2008 return CMD_SUCCESS;
2009 }
2010
2011 DEFUNSH(VTYSH_ZEBRA, vtysh_pseudowire, vtysh_pseudowire_cmd,
2012 "pseudowire IFNAME",
2013 "Static pseudowire configuration\n"
2014 "Pseudowire name\n")
2015 {
2016 vty->node = PW_NODE;
2017 return CMD_SUCCESS;
2018 }
2019
2020 /* TODO Implement "no interface command in isisd. */
2021 DEFSH(VTYSH_ZEBRA | VTYSH_RIPD | VTYSH_RIPNGD | VTYSH_OSPFD | VTYSH_OSPF6D
2022 | VTYSH_EIGRPD,
2023 vtysh_no_interface_cmd, "no interface IFNAME", NO_STR
2024 "Delete a pseudo interface's configuration\n"
2025 "Interface's name\n")
2026
2027 DEFSH(VTYSH_ZEBRA, vtysh_no_interface_vrf_cmd, "no interface IFNAME vrf NAME",
2028 NO_STR
2029 "Delete a pseudo interface's configuration\n"
2030 "Interface's name\n" VRF_CMD_HELP_STR)
2031
2032 DEFUNSH(VTYSH_ZEBRA, vtysh_logicalrouter, vtysh_logicalrouter_cmd,
2033 "logical-router (1-65535) ns NAME",
2034 "Enable a logical-router\n"
2035 "Specify the logical-router indentifier\n"
2036 "The Name Space\n"
2037 "The file name in " NS_RUN_DIR ", or a full pathname\n")
2038 {
2039 vty->node = LOGICALROUTER_NODE;
2040 return CMD_SUCCESS;
2041 }
2042
2043 DEFSH(VTYSH_ZEBRA, vtysh_no_logicalrouter_cmd,
2044 "no logical-router (1-65535) ns NAME", NO_STR
2045 "Enable a Logical-Router\n"
2046 "Specify the Logical-Router identifier\n"
2047 "The Name Space\n"
2048 "The file name in " NS_RUN_DIR ", or a full pathname\n")
2049
2050 DEFUNSH(VTYSH_PBRD, vtysh_nexthop_group, vtysh_nexthop_group_cmd,
2051 "nexthop-group NAME",
2052 "Nexthop Group configuration\n"
2053 "Name of the Nexthop Group\n")
2054 {
2055 vty->node = NH_GROUP_NODE;
2056 return CMD_SUCCESS;
2057 }
2058
2059 DEFSH(VTYSH_PBRD, vtysh_no_nexthop_group_cmd, "no nexthop-group NAME",
2060 NO_STR
2061 "Nexthop Group Configuration\n"
2062 "Name of the Nexthop Group\n")
2063
2064 DEFUNSH(VTYSH_VRF, vtysh_vrf, vtysh_vrf_cmd, "vrf NAME",
2065 "Select a VRF to configure\n"
2066 "VRF's name\n")
2067 {
2068 vty->node = VRF_NODE;
2069 return CMD_SUCCESS;
2070 }
2071
2072 DEFSH(VTYSH_ZEBRA, vtysh_no_vrf_cmd, "no vrf NAME", NO_STR
2073 "Delete a pseudo vrf's configuration\n"
2074 "VRF's name\n")
2075
2076 DEFUNSH(VTYSH_NS, vtysh_exit_logicalrouter,
2077 vtysh_exit_logicalrouter_cmd, "exit",
2078 "Exit current mode and down to previous mode\n")
2079 {
2080 return vtysh_exit(vty);
2081 }
2082
2083 DEFUNSH(VTYSH_NS, vtysh_quit_logicalrouter,
2084 vtysh_quit_logicalrouter_cmd, "quit",
2085 "Exit current mode and down to previous mode\n")
2086 {
2087 return vtysh_exit_logicalrouter(self, vty, argc, argv);
2088 }
2089
2090 DEFUNSH(VTYSH_VRF, vtysh_exit_vrf, vtysh_exit_vrf_cmd, "exit",
2091 "Exit current mode and down to previous mode\n")
2092 {
2093 return vtysh_exit(vty);
2094 }
2095
2096 DEFUNSH(VTYSH_VRF, vtysh_quit_vrf, vtysh_quit_vrf_cmd, "quit",
2097 "Exit current mode and down to previous mode\n")
2098 {
2099 return vtysh_exit_vrf(self, vty, argc, argv);
2100 }
2101
2102 DEFUNSH(VTYSH_PBRD, vtysh_exit_nexthop_group, vtysh_exit_nexthop_group_cmd,
2103 "exit", "Exit current mode and down to previous mode\n")
2104 {
2105 return vtysh_exit(vty);
2106 }
2107
2108 DEFUNSH(VTYSH_VRF, vtysh_quit_nexthop_group, vtysh_quit_nexthop_group_cmd,
2109 "quit", "Exit current mode and down to previous mode\n")
2110 {
2111 return vtysh_exit_nexthop_group(self, vty, argc, argv);
2112 }
2113
2114 /*
2115 * TODO Implement interface description commands in ripngd, ospf6d
2116 * and isisd.
2117 */
2118 DEFSH(VTYSH_ZEBRA | VTYSH_RIPD | VTYSH_OSPFD | VTYSH_EIGRPD,
2119 vtysh_interface_desc_cmd, "description LINE...",
2120 "Interface specific description\n"
2121 "Characters describing this interface\n")
2122
2123 DEFSH(VTYSH_ZEBRA | VTYSH_RIPD | VTYSH_OSPFD | VTYSH_EIGRPD,
2124 vtysh_no_interface_desc_cmd, "no description",
2125 NO_STR "Interface specific description\n")
2126
2127 DEFUNSH(VTYSH_INTERFACE, vtysh_exit_interface, vtysh_exit_interface_cmd, "exit",
2128 "Exit current mode and down to previous mode\n")
2129 {
2130 return vtysh_exit(vty);
2131 }
2132
2133 DEFUNSH(VTYSH_INTERFACE, vtysh_quit_interface, vtysh_quit_interface_cmd, "quit",
2134 "Exit current mode and down to previous mode\n")
2135 {
2136 return vtysh_exit_interface(self, vty, argc, argv);
2137 }
2138
2139 DEFUN (vtysh_show_poll,
2140 vtysh_show_poll_cmd,
2141 "show thread poll",
2142 SHOW_STR
2143 "Thread information\n"
2144 "Thread Poll Information\n")
2145 {
2146 unsigned int i;
2147 int ret = CMD_SUCCESS;
2148 char line[100];
2149
2150 snprintf(line, sizeof(line), "do show thread poll\n");
2151 for (i = 0; i < array_size(vtysh_client); i++)
2152 if (vtysh_client[i].fd >= 0) {
2153 vty_out(vty, "Thread statistics for %s:\n",
2154 vtysh_client[i].name);
2155 ret = vtysh_client_execute(&vtysh_client[i], line);
2156 vty_out(vty, "\n");
2157 }
2158 return ret;
2159 }
2160
2161 DEFUN (vtysh_show_thread,
2162 vtysh_show_thread_cmd,
2163 "show thread cpu [FILTER]",
2164 SHOW_STR
2165 "Thread information\n"
2166 "Thread CPU usage\n"
2167 "Display filter (rwtexb)\n")
2168 {
2169 unsigned int i;
2170 int idx = 0;
2171 int ret = CMD_SUCCESS;
2172 char line[100];
2173
2174 const char *filter =
2175 argv_find(argv, argc, "FILTER", &idx) ? argv[idx]->arg : "";
2176
2177 snprintf(line, sizeof(line), "do show thread cpu %s\n", filter);
2178 for (i = 0; i < array_size(vtysh_client); i++)
2179 if (vtysh_client[i].fd >= 0) {
2180 vty_out(vty, "Thread statistics for %s:\n",
2181 vtysh_client[i].name);
2182 ret = vtysh_client_execute(&vtysh_client[i], line);
2183 vty_out(vty, "\n");
2184 }
2185 return ret;
2186 }
2187
2188 DEFUN (vtysh_show_work_queues,
2189 vtysh_show_work_queues_cmd,
2190 "show work-queues",
2191 SHOW_STR
2192 "Work Queue information\n")
2193 {
2194 unsigned int i;
2195 int ret = CMD_SUCCESS;
2196 char line[] = "do show work-queues\n";
2197
2198 for (i = 0; i < array_size(vtysh_client); i++)
2199 if (vtysh_client[i].fd >= 0) {
2200 vty_out(vty, "Work queue statistics for %s:\n",
2201 vtysh_client[i].name);
2202 ret = vtysh_client_execute(&vtysh_client[i], line);
2203 vty_out(vty, "\n");
2204 }
2205
2206 return ret;
2207 }
2208
2209 DEFUN (vtysh_show_work_queues_daemon,
2210 vtysh_show_work_queues_daemon_cmd,
2211 "show work-queues <zebra|ripd|ripngd|ospfd|ospf6d|bgpd|isisd|pbrd>",
2212 SHOW_STR
2213 "Work Queue information\n"
2214 "For the zebra daemon\n"
2215 "For the rip daemon\n"
2216 "For the ripng daemon\n"
2217 "For the ospf daemon\n"
2218 "For the ospfv6 daemon\n"
2219 "For the bgp daemon\n"
2220 "For the isis daemon\n"
2221 "For the pbr daemon\n")
2222 {
2223 int idx_protocol = 2;
2224 unsigned int i;
2225 int ret = CMD_SUCCESS;
2226
2227 for (i = 0; i < array_size(vtysh_client); i++) {
2228 if (strmatch(vtysh_client[i].name, argv[idx_protocol]->text))
2229 break;
2230 }
2231
2232 ret = vtysh_client_execute(&vtysh_client[i], "show work-queues\n");
2233
2234 return ret;
2235 }
2236
2237 DEFUNSH(VTYSH_ZEBRA, vtysh_link_params, vtysh_link_params_cmd, "link-params",
2238 LINK_PARAMS_STR)
2239 {
2240 vty->node = LINK_PARAMS_NODE;
2241 return CMD_SUCCESS;
2242 }
2243
2244 DEFUNSH(VTYSH_ZEBRA, exit_link_params, exit_link_params_cmd, "exit-link-params",
2245 "Exit from Link Params configuration node\n")
2246 {
2247 if (vty->node == LINK_PARAMS_NODE)
2248 vty->node = INTERFACE_NODE;
2249 return CMD_SUCCESS;
2250 }
2251
2252 static int show_per_daemon(const char *line, const char *headline)
2253 {
2254 unsigned int i;
2255 int ret = CMD_SUCCESS;
2256
2257 for (i = 0; i < array_size(vtysh_client); i++)
2258 if (vtysh_client[i].fd >= 0) {
2259 vty_out(vty, headline, vtysh_client[i].name);
2260 ret = vtysh_client_execute(&vtysh_client[i], line);
2261 vty_out(vty, "\n");
2262 }
2263
2264 return ret;
2265 }
2266
2267 DEFUNSH_HIDDEN (0x00,
2268 vtysh_debug_all,
2269 vtysh_debug_all_cmd,
2270 "[no] debug all",
2271 NO_STR
2272 DEBUG_STR
2273 "Toggle all debugs on or off\n")
2274 {
2275 return CMD_SUCCESS;
2276 }
2277
2278 DEFUN (vtysh_show_debugging,
2279 vtysh_show_debugging_cmd,
2280 "show debugging",
2281 SHOW_STR
2282 DEBUG_STR)
2283 {
2284 return show_per_daemon("do show debugging\n", "");
2285 }
2286
2287 DEFUN (vtysh_show_debugging_hashtable,
2288 vtysh_show_debugging_hashtable_cmd,
2289 "show debugging hashtable [statistics]",
2290 SHOW_STR
2291 DEBUG_STR
2292 "Statistics about hash tables\n"
2293 "Statistics about hash tables\n")
2294 {
2295 vty_out(vty, "\n");
2296 vty_out(vty,
2297 "Load factor (LF) - average number of elements across all buckets\n");
2298 vty_out(vty,
2299 "Full load factor (FLF) - average number of elements across full buckets\n\n");
2300 vty_out(vty,
2301 "Standard deviation (SD) is calculated for both the LF and FLF\n");
2302 vty_out(vty,
2303 "and indicates the typical deviation of bucket chain length\n");
2304 vty_out(vty, "from the value in the corresponding load factor.\n\n");
2305
2306 return show_per_daemon("do show debugging hashtable\n",
2307 "Hashtable statistics for %s:\n");
2308 }
2309
2310 /* Memory */
2311 DEFUN (vtysh_show_memory,
2312 vtysh_show_memory_cmd,
2313 "show memory",
2314 SHOW_STR
2315 "Memory statistics\n")
2316 {
2317 return show_per_daemon("do show memory\n", "Memory statistics for %s:\n");
2318 }
2319
2320 DEFUN (vtysh_show_modules,
2321 vtysh_show_modules_cmd,
2322 "show modules",
2323 SHOW_STR
2324 "Loaded modules\n")
2325 {
2326 return show_per_daemon("do show modules\n",
2327 "Module information for %s:\n");
2328 }
2329
2330 /* Logging commands. */
2331 DEFUN (vtysh_show_logging,
2332 vtysh_show_logging_cmd,
2333 "show logging",
2334 SHOW_STR
2335 "Show current logging configuration\n")
2336 {
2337 return show_per_daemon("do show logging\n",
2338 "Logging configuration for %s:\n");
2339 }
2340
2341 DEFUNSH(VTYSH_ALL, vtysh_log_stdout, vtysh_log_stdout_cmd, "log stdout",
2342 "Logging control\n"
2343 "Set stdout logging level\n")
2344 {
2345 return CMD_SUCCESS;
2346 }
2347
2348 DEFUNSH(VTYSH_ALL, vtysh_log_stdout_level, vtysh_log_stdout_level_cmd,
2349 "log stdout <emergencies|alerts|critical|errors|warnings|notifications|informational|debugging>",
2350 "Logging control\n"
2351 "Set stdout logging level\n" LOG_LEVEL_DESC)
2352 {
2353 return CMD_SUCCESS;
2354 }
2355
2356 DEFUNSH(VTYSH_ALL, no_vtysh_log_stdout, no_vtysh_log_stdout_cmd,
2357 "no log stdout [LEVEL]", NO_STR
2358 "Logging control\n"
2359 "Cancel logging to stdout\n"
2360 "Logging level\n")
2361 {
2362 return CMD_SUCCESS;
2363 }
2364
2365 DEFUNSH(VTYSH_ALL, vtysh_log_file, vtysh_log_file_cmd, "log file FILENAME",
2366 "Logging control\n"
2367 "Logging to file\n"
2368 "Logging filename\n")
2369 {
2370 return CMD_SUCCESS;
2371 }
2372
2373 DEFUNSH(VTYSH_ALL, vtysh_log_file_level, vtysh_log_file_level_cmd,
2374 "log file FILENAME <emergencies|alerts|critical|errors|warnings|notifications|informational|debugging>",
2375 "Logging control\n"
2376 "Logging to file\n"
2377 "Logging filename\n" LOG_LEVEL_DESC)
2378 {
2379 return CMD_SUCCESS;
2380 }
2381
2382 DEFUNSH(VTYSH_ALL, no_vtysh_log_file, no_vtysh_log_file_cmd,
2383 "no log file [FILENAME [LEVEL]]", NO_STR
2384 "Logging control\n"
2385 "Cancel logging to file\n"
2386 "Logging file name\n"
2387 "Logging level\n")
2388 {
2389 return CMD_SUCCESS;
2390 }
2391
2392 DEFUNSH(VTYSH_ALL, vtysh_log_monitor, vtysh_log_monitor_cmd,
2393 "log monitor [<emergencies|alerts|critical|errors|warnings|notifications|informational|debugging>]",
2394 "Logging control\n"
2395 "Set terminal line (monitor) logging level\n" LOG_LEVEL_DESC)
2396 {
2397 return CMD_SUCCESS;
2398 }
2399
2400 DEFUNSH(VTYSH_ALL, no_vtysh_log_monitor, no_vtysh_log_monitor_cmd,
2401 "no log monitor [LEVEL]", NO_STR
2402 "Logging control\n"
2403 "Disable terminal line (monitor) logging\n"
2404 "Logging level\n")
2405 {
2406 return CMD_SUCCESS;
2407 }
2408
2409 DEFUNSH(VTYSH_ALL, vtysh_log_syslog, vtysh_log_syslog_cmd,
2410 "log syslog [<emergencies|alerts|critical|errors|warnings|notifications|informational|debugging>]",
2411 "Logging control\n"
2412 "Set syslog logging level\n" LOG_LEVEL_DESC)
2413 {
2414 return CMD_SUCCESS;
2415 }
2416
2417 DEFUNSH(VTYSH_ALL, no_vtysh_log_syslog, no_vtysh_log_syslog_cmd,
2418 "no log syslog [<emergencies|alerts|critical|errors|warnings|notifications|informational|debugging>]",
2419 NO_STR
2420 "Logging control\n"
2421 "Cancel logging to syslog\n"
2422 LOG_LEVEL_DESC)
2423 {
2424 return CMD_SUCCESS;
2425 }
2426
2427 DEFUNSH(VTYSH_ALL, vtysh_log_facility, vtysh_log_facility_cmd,
2428 "log facility <kern|user|mail|daemon|auth|syslog|lpr|news|uucp|cron|local0|local1|local2|local3|local4|local5|local6|local7>",
2429 "Logging control\n"
2430 "Facility parameter for syslog messages\n" LOG_FACILITY_DESC)
2431 {
2432 return CMD_SUCCESS;
2433 }
2434
2435 DEFUNSH(VTYSH_ALL, no_vtysh_log_facility, no_vtysh_log_facility_cmd,
2436 "no log facility [FACILITY]", NO_STR
2437 "Logging control\n"
2438 "Reset syslog facility to default (daemon)\n"
2439 "Syslog facility\n")
2440 {
2441 return CMD_SUCCESS;
2442 }
2443
2444 DEFUNSH(VTYSH_ALL, vtysh_log_record_priority, vtysh_log_record_priority_cmd,
2445 "log record-priority",
2446 "Logging control\n"
2447 "Log the priority of the message within the message\n")
2448 {
2449 return CMD_SUCCESS;
2450 }
2451
2452 DEFUNSH(VTYSH_ALL, no_vtysh_log_record_priority,
2453 no_vtysh_log_record_priority_cmd, "no log record-priority", NO_STR
2454 "Logging control\n"
2455 "Do not log the priority of the message within the message\n")
2456 {
2457 return CMD_SUCCESS;
2458 }
2459
2460 DEFUNSH(VTYSH_ALL, vtysh_log_timestamp_precision,
2461 vtysh_log_timestamp_precision_cmd, "log timestamp precision (0-6)",
2462 "Logging control\n"
2463 "Timestamp configuration\n"
2464 "Set the timestamp precision\n"
2465 "Number of subsecond digits\n")
2466 {
2467 return CMD_SUCCESS;
2468 }
2469
2470 DEFUNSH(VTYSH_ALL, no_vtysh_log_timestamp_precision,
2471 no_vtysh_log_timestamp_precision_cmd, "no log timestamp precision",
2472 NO_STR
2473 "Logging control\n"
2474 "Timestamp configuration\n"
2475 "Reset the timestamp precision to the default value of 0\n")
2476 {
2477 return CMD_SUCCESS;
2478 }
2479
2480 DEFUNSH(VTYSH_ALL, vtysh_service_password_encrypt,
2481 vtysh_service_password_encrypt_cmd, "service password-encryption",
2482 "Set up miscellaneous service\n"
2483 "Enable encrypted passwords\n")
2484 {
2485 return CMD_SUCCESS;
2486 }
2487
2488 DEFUNSH(VTYSH_ALL, no_vtysh_service_password_encrypt,
2489 no_vtysh_service_password_encrypt_cmd, "no service password-encryption",
2490 NO_STR
2491 "Set up miscellaneous service\n"
2492 "Enable encrypted passwords\n")
2493 {
2494 return CMD_SUCCESS;
2495 }
2496
2497 DEFUNSH(VTYSH_ALL, vtysh_config_password, vtysh_password_cmd,
2498 "password [(8-8)] LINE",
2499 "Modify the terminal connection password\n"
2500 "Specifies a HIDDEN password will follow\n"
2501 "The password string\n")
2502 {
2503 return CMD_SUCCESS;
2504 }
2505
2506 DEFUNSH(VTYSH_ALL, no_vtysh_config_password, no_vtysh_password_cmd,
2507 "no password", NO_STR
2508 "Modify the terminal connection password\n")
2509 {
2510 vty_out(vty, NO_PASSWD_CMD_WARNING);
2511
2512 return CMD_SUCCESS;
2513 }
2514
2515 DEFUNSH(VTYSH_ALL, vtysh_config_enable_password, vtysh_enable_password_cmd,
2516 "enable password [(8-8)] LINE",
2517 "Modify enable password parameters\n"
2518 "Assign the privileged level password\n"
2519 "Specifies a HIDDEN password will follow\n"
2520 "The 'enable' password string\n")
2521 {
2522 return CMD_SUCCESS;
2523 }
2524
2525 DEFUNSH(VTYSH_ALL, no_vtysh_config_enable_password,
2526 no_vtysh_enable_password_cmd, "no enable password", NO_STR
2527 "Modify enable password parameters\n"
2528 "Assign the privileged level password\n")
2529 {
2530 vty_out(vty, NO_PASSWD_CMD_WARNING);
2531
2532 return CMD_SUCCESS;
2533 }
2534
2535 DEFUN (vtysh_write_terminal,
2536 vtysh_write_terminal_cmd,
2537 "write terminal [<zebra|ripd|ripngd|ospfd|ospf6d|ldpd|bgpd|isisd|pimd>]",
2538 "Write running configuration to memory, network, or terminal\n"
2539 "Write to terminal\n"
2540 "For the zebra daemon\n"
2541 "For the rip daemon\n"
2542 "For the ripng daemon\n"
2543 "For the ospf daemon\n"
2544 "For the ospfv6 daemon\n"
2545 "For the ldpd daemon\n"
2546 "For the bgp daemon\n"
2547 "For the isis daemon\n"
2548 "For the pim daemon\n")
2549 {
2550 unsigned int i;
2551 char line[] = "do write terminal\n";
2552
2553 vty_out(vty, "Building configuration...\n");
2554 vty_out(vty, "\nCurrent configuration:\n");
2555 vty_out(vty, "!\n");
2556
2557 for (i = 0; i < array_size(vtysh_client); i++)
2558 if ((argc < 3)
2559 || (strmatch(vtysh_client[i].name, argv[2]->text)))
2560 vtysh_client_config(&vtysh_client[i], line);
2561
2562 /* Integrate vtysh specific configuration. */
2563 vty_open_pager(vty);
2564 vtysh_config_write();
2565 vtysh_config_dump();
2566 vty_close_pager(vty);
2567 vty_out(vty, "end\n");
2568
2569 return CMD_SUCCESS;
2570 }
2571
2572 DEFUN (vtysh_show_running_config,
2573 vtysh_show_running_config_cmd,
2574 "show running-config [<zebra|ripd|ripngd|ospfd|ospf6d|ldpd|bgpd|isisd|pimd>]",
2575 SHOW_STR
2576 "Current operating configuration\n"
2577 "For the zebra daemon\n"
2578 "For the rip daemon\n"
2579 "For the ripng daemon\n"
2580 "For the ospf daemon\n"
2581 "For the ospfv6 daemon\n"
2582 "For the ldp daemon\n"
2583 "For the bgp daemon\n"
2584 "For the isis daemon\n"
2585 "For the pim daemon\n")
2586 {
2587 return vtysh_write_terminal(self, vty, argc, argv);
2588 }
2589
2590 DEFUN (vtysh_integrated_config,
2591 vtysh_integrated_config_cmd,
2592 "service integrated-vtysh-config",
2593 "Set up miscellaneous service\n"
2594 "Write configuration into integrated file\n")
2595 {
2596 vtysh_write_integrated = WRITE_INTEGRATED_YES;
2597 return CMD_SUCCESS;
2598 }
2599
2600 DEFUN (no_vtysh_integrated_config,
2601 no_vtysh_integrated_config_cmd,
2602 "no service integrated-vtysh-config",
2603 NO_STR
2604 "Set up miscellaneous service\n"
2605 "Write configuration into integrated file\n")
2606 {
2607 vtysh_write_integrated = WRITE_INTEGRATED_NO;
2608 return CMD_SUCCESS;
2609 }
2610
2611 static void backup_config_file(const char *fbackup)
2612 {
2613 char *integrate_sav = NULL;
2614
2615 integrate_sav = malloc(strlen(fbackup) + strlen(CONF_BACKUP_EXT) + 1);
2616 strcpy(integrate_sav, fbackup);
2617 strcat(integrate_sav, CONF_BACKUP_EXT);
2618
2619 /* Move current configuration file to backup config file. */
2620 if (unlink(integrate_sav) != 0) {
2621 vty_out(vty, "Warning: %s unlink failed\n", integrate_sav);
2622 }
2623 if (rename(fbackup, integrate_sav) != 0) {
2624 vty_out(vty, "Error renaming %s to %s\n", fbackup,
2625 integrate_sav);
2626 }
2627 free(integrate_sav);
2628 }
2629
2630 int vtysh_write_config_integrated(void)
2631 {
2632 unsigned int i;
2633 char line[] = "do write terminal\n";
2634 FILE *fp;
2635 int fd;
2636 #ifdef FRR_USER
2637 struct passwd *pwentry;
2638 #endif
2639 #ifdef FRR_GROUP
2640 struct group *grentry;
2641 #endif
2642 uid_t uid = -1;
2643 gid_t gid = -1;
2644 struct stat st;
2645 int err = 0;
2646
2647 vty_out(vty, "Building Configuration...\n");
2648
2649 backup_config_file(frr_config);
2650 fp = fopen(frr_config, "w");
2651 if (fp == NULL) {
2652 vty_out(vty,
2653 "%% Error: failed to open configuration file %s: %s\n",
2654 frr_config, safe_strerror(errno));
2655 return CMD_WARNING_CONFIG_FAILED;
2656 }
2657 fd = fileno(fp);
2658
2659 for (i = 0; i < array_size(vtysh_client); i++)
2660 vtysh_client_config(&vtysh_client[i], line);
2661
2662 vtysh_config_write();
2663 vty->of_saved = vty->of;
2664 vty->of = fp;
2665 vtysh_config_dump();
2666 vty->of = vty->of_saved;
2667
2668 if (fchmod(fd, CONFIGFILE_MASK) != 0) {
2669 printf("%% Warning: can't chmod configuration file %s: %s\n",
2670 frr_config, safe_strerror(errno));
2671 err++;
2672 }
2673
2674 #ifdef FRR_USER
2675 pwentry = getpwnam(FRR_USER);
2676 if (pwentry)
2677 uid = pwentry->pw_uid;
2678 else {
2679 printf("%% Warning: could not look up user \"%s\"\n", FRR_USER);
2680 err++;
2681 }
2682 #endif
2683 #ifdef FRR_GROUP
2684 grentry = getgrnam(FRR_GROUP);
2685 if (grentry)
2686 gid = grentry->gr_gid;
2687 else {
2688 printf("%% Warning: could not look up group \"%s\"\n",
2689 FRR_GROUP);
2690 err++;
2691 }
2692 #endif
2693
2694 if (!fstat(fd, &st)) {
2695 if (st.st_uid == uid)
2696 uid = -1;
2697 if (st.st_gid == gid)
2698 gid = -1;
2699 if ((uid != (uid_t)-1 || gid != (gid_t)-1)
2700 && fchown(fd, uid, gid)) {
2701 printf("%% Warning: can't chown configuration file %s: %s\n",
2702 frr_config, safe_strerror(errno));
2703 err++;
2704 }
2705 } else {
2706 printf("%% Warning: stat() failed on %s: %s\n", frr_config,
2707 safe_strerror(errno));
2708 err++;
2709 }
2710
2711 fclose(fp);
2712
2713 printf("Integrated configuration saved to %s\n", frr_config);
2714 if (err)
2715 return CMD_WARNING;
2716
2717 printf("[OK]\n");
2718 return CMD_SUCCESS;
2719 }
2720
2721 static bool want_config_integrated(void)
2722 {
2723 struct stat s;
2724
2725 switch (vtysh_write_integrated) {
2726 case WRITE_INTEGRATED_UNSPECIFIED:
2727 if (stat(frr_config, &s) && errno == ENOENT)
2728 return false;
2729 return true;
2730 case WRITE_INTEGRATED_NO:
2731 return false;
2732 case WRITE_INTEGRATED_YES:
2733 return true;
2734 }
2735 return true;
2736 }
2737
2738 DEFUN (vtysh_write_memory,
2739 vtysh_write_memory_cmd,
2740 "write [<memory|file>]",
2741 "Write running configuration to memory, network, or terminal\n"
2742 "Write configuration to the file (same as write file)\n"
2743 "Write configuration to the file (same as write memory)\n")
2744 {
2745 int ret = CMD_SUCCESS;
2746 char line[] = "do write memory\n";
2747 unsigned int i;
2748
2749 vty_out(vty, "Note: this version of vtysh never writes vtysh.conf\n");
2750
2751 /* If integrated frr.conf explicitely set. */
2752 if (want_config_integrated()) {
2753 ret = CMD_WARNING_CONFIG_FAILED;
2754
2755 /* first attempt to use watchfrr if it's available */
2756 bool used_watchfrr = false;
2757
2758 for (i = 0; i < array_size(vtysh_client); i++)
2759 if (vtysh_client[i].flag == VTYSH_WATCHFRR)
2760 break;
2761 if (i < array_size(vtysh_client) && vtysh_client[i].fd != -1) {
2762 used_watchfrr = true;
2763 ret = vtysh_client_execute(&vtysh_client[i],
2764 "do write integrated");
2765 }
2766
2767 /*
2768 * If we didn't use watchfrr, fallback to writing the config
2769 * ourselves
2770 */
2771 if (!used_watchfrr) {
2772 printf("\nWarning: attempting direct configuration write without "
2773 "watchfrr.\nFile permissions and ownership may be "
2774 "incorrect, or write may fail.\n\n");
2775 ret = vtysh_write_config_integrated();
2776 }
2777 return ret;
2778 }
2779
2780 vty_out(vty, "Building Configuration...\n");
2781
2782 for (i = 0; i < array_size(vtysh_client); i++)
2783 ret = vtysh_client_execute(&vtysh_client[i], line);
2784
2785 return ret;
2786 }
2787
2788 DEFUN (vtysh_copy_running_config,
2789 vtysh_copy_running_config_cmd,
2790 "copy running-config startup-config",
2791 "Copy from one file to another\n"
2792 "Copy from current system configuration\n"
2793 "Copy to startup configuration\n")
2794 {
2795 return vtysh_write_memory(self, vty, argc, argv);
2796 }
2797
2798 DEFUN (vtysh_terminal_length,
2799 vtysh_terminal_length_cmd,
2800 "terminal length (0-512)",
2801 "Set terminal line parameters\n"
2802 "Set number of lines on a screen\n"
2803 "Number of lines on screen (0 for no pausing)\n")
2804 {
2805 int idx_number = 2;
2806 int lines;
2807 char *endptr = NULL;
2808 char default_pager[10];
2809
2810 lines = strtol(argv[idx_number]->arg, &endptr, 10);
2811 if (lines < 0 || lines > 512 || *endptr != '\0') {
2812 vty_out(vty, "length is malformed\n");
2813 return CMD_WARNING;
2814 }
2815
2816 if (vtysh_pager_name) {
2817 free(vtysh_pager_name);
2818 vtysh_pager_name = NULL;
2819 }
2820
2821 if (lines != 0) {
2822 snprintf(default_pager, 10, "more -%i", lines);
2823 vtysh_pager_name = strdup(default_pager);
2824 }
2825
2826 return CMD_SUCCESS;
2827 }
2828
2829 DEFUN (vtysh_terminal_no_length,
2830 vtysh_terminal_no_length_cmd,
2831 "terminal no length",
2832 "Set terminal line parameters\n"
2833 NO_STR
2834 "Set number of lines on a screen\n")
2835 {
2836 if (vtysh_pager_name) {
2837 free(vtysh_pager_name);
2838 vtysh_pager_name = NULL;
2839 }
2840
2841 vtysh_pager_init();
2842 return CMD_SUCCESS;
2843 }
2844
2845 DEFUN (vtysh_show_daemons,
2846 vtysh_show_daemons_cmd,
2847 "show daemons",
2848 SHOW_STR
2849 "Show list of running daemons\n")
2850 {
2851 unsigned int i;
2852
2853 for (i = 0; i < array_size(vtysh_client); i++)
2854 if (vtysh_client[i].fd >= 0)
2855 vty_out(vty, " %s", vtysh_client[i].name);
2856 vty_out(vty, "\n");
2857
2858 return CMD_SUCCESS;
2859 }
2860
2861 /* Execute command in child process. */
2862 static void execute_command(const char *command, int argc, const char *arg1,
2863 const char *arg2)
2864 {
2865 pid_t pid;
2866 int status;
2867
2868 /* Call fork(). */
2869 pid = fork();
2870
2871 if (pid < 0) {
2872 /* Failure of fork(). */
2873 fprintf(stderr, "Can't fork: %s\n", safe_strerror(errno));
2874 exit(1);
2875 } else if (pid == 0) {
2876 /* This is child process. */
2877 switch (argc) {
2878 case 0:
2879 execlp(command, command, (const char *)NULL);
2880 break;
2881 case 1:
2882 execlp(command, command, arg1, (const char *)NULL);
2883 break;
2884 case 2:
2885 execlp(command, command, arg1, arg2,
2886 (const char *)NULL);
2887 break;
2888 }
2889
2890 /* When execlp suceed, this part is not executed. */
2891 fprintf(stderr, "Can't execute %s: %s\n", command,
2892 safe_strerror(errno));
2893 exit(1);
2894 } else {
2895 /* This is parent. */
2896 execute_flag = 1;
2897 wait4(pid, &status, 0, NULL);
2898 execute_flag = 0;
2899 }
2900 }
2901
2902 DEFUN (vtysh_ping,
2903 vtysh_ping_cmd,
2904 "ping WORD",
2905 "Send echo messages\n"
2906 "Ping destination address or hostname\n")
2907 {
2908 int idx = 1;
2909
2910 argv_find(argv, argc, "WORD", &idx);
2911 execute_command("ping", 1, argv[idx]->arg, NULL);
2912 return CMD_SUCCESS;
2913 }
2914
2915 ALIAS(vtysh_ping, vtysh_ping_ip_cmd, "ping ip WORD",
2916 "Send echo messages\n"
2917 "IP echo\n"
2918 "Ping destination address or hostname\n")
2919
2920 DEFUN (vtysh_traceroute,
2921 vtysh_traceroute_cmd,
2922 "traceroute WORD",
2923 "Trace route to destination\n"
2924 "Trace route to destination address or hostname\n")
2925 {
2926 int idx = 1;
2927
2928 argv_find(argv, argc, "WORD", &idx);
2929 execute_command("traceroute", 1, argv[idx]->arg, NULL);
2930 return CMD_SUCCESS;
2931 }
2932
2933 ALIAS(vtysh_traceroute, vtysh_traceroute_ip_cmd, "traceroute ip WORD",
2934 "Trace route to destination\n"
2935 "IP trace\n"
2936 "Trace route to destination address or hostname\n")
2937
2938 DEFUN (vtysh_mtrace,
2939 vtysh_mtrace_cmd,
2940 "mtrace WORD [WORD]",
2941 "Multicast trace route to multicast source\n"
2942 "Multicast trace route to multicast source address\n"
2943 "Multicast trace route for multicast group address\n")
2944 {
2945 if (argc == 2)
2946 execute_command("mtracebis", 1, argv[1]->arg, NULL);
2947 else
2948 execute_command("mtracebis", 2, argv[1]->arg, argv[2]->arg);
2949 return CMD_SUCCESS;
2950 }
2951
2952 DEFUN (vtysh_ping6,
2953 vtysh_ping6_cmd,
2954 "ping ipv6 WORD",
2955 "Send echo messages\n"
2956 "IPv6 echo\n"
2957 "Ping destination address or hostname\n")
2958 {
2959 execute_command("ping6", 1, argv[2]->arg, NULL);
2960 return CMD_SUCCESS;
2961 }
2962
2963 DEFUN (vtysh_traceroute6,
2964 vtysh_traceroute6_cmd,
2965 "traceroute ipv6 WORD",
2966 "Trace route to destination\n"
2967 "IPv6 trace\n"
2968 "Trace route to destination address or hostname\n")
2969 {
2970 execute_command("traceroute6", 1, argv[2]->arg, NULL);
2971 return CMD_SUCCESS;
2972 }
2973
2974 #if defined(HAVE_SHELL_ACCESS)
2975 DEFUN (vtysh_telnet,
2976 vtysh_telnet_cmd,
2977 "telnet WORD",
2978 "Open a telnet connection\n"
2979 "IP address or hostname of a remote system\n")
2980 {
2981 execute_command("telnet", 1, argv[1]->arg, NULL);
2982 return CMD_SUCCESS;
2983 }
2984
2985 DEFUN (vtysh_telnet_port,
2986 vtysh_telnet_port_cmd,
2987 "telnet WORD PORT",
2988 "Open a telnet connection\n"
2989 "IP address or hostname of a remote system\n"
2990 "TCP Port number\n")
2991 {
2992 execute_command("telnet", 2, argv[1]->arg, argv[2]->arg);
2993 return CMD_SUCCESS;
2994 }
2995
2996 DEFUN (vtysh_ssh,
2997 vtysh_ssh_cmd,
2998 "ssh WORD",
2999 "Open an ssh connection\n"
3000 "[user@]host\n")
3001 {
3002 execute_command("ssh", 1, argv[1]->arg, NULL);
3003 return CMD_SUCCESS;
3004 }
3005
3006 DEFUN (vtysh_start_shell,
3007 vtysh_start_shell_cmd,
3008 "start-shell",
3009 "Start UNIX shell\n")
3010 {
3011 execute_command("sh", 0, NULL, NULL);
3012 return CMD_SUCCESS;
3013 }
3014
3015 DEFUN (vtysh_start_bash,
3016 vtysh_start_bash_cmd,
3017 "start-shell bash",
3018 "Start UNIX shell\n"
3019 "Start bash\n")
3020 {
3021 execute_command("bash", 0, NULL, NULL);
3022 return CMD_SUCCESS;
3023 }
3024
3025 DEFUN (vtysh_start_zsh,
3026 vtysh_start_zsh_cmd,
3027 "start-shell zsh",
3028 "Start UNIX shell\n"
3029 "Start Z shell\n")
3030 {
3031 execute_command("zsh", 0, NULL, NULL);
3032 return CMD_SUCCESS;
3033 }
3034 #endif
3035
3036 DEFUN (config_list,
3037 config_list_cmd,
3038 "list [permutations]",
3039 "Print command list\n"
3040 "Print all possible command permutations\n")
3041 {
3042 return cmd_list_cmds(vty, argc == 2);
3043 }
3044
3045 DEFUN (vtysh_output_file,
3046 vtysh_output_file_cmd,
3047 "output file FILE",
3048 "Direct vtysh output to file\n"
3049 "Direct vtysh output to file\n"
3050 "Path to dump output to\n")
3051 {
3052 const char *path = argv[argc - 1]->arg;
3053 vty->of = fopen(path, "a");
3054 if (!vty->of) {
3055 vty_out(vty, "Failed to open file '%s': %s\n", path,
3056 safe_strerror(errno));
3057 vty->of = stdout;
3058 }
3059 return CMD_SUCCESS;
3060 }
3061
3062 DEFUN (no_vtysh_output_file,
3063 no_vtysh_output_file_cmd,
3064 "no output file [FILE]",
3065 NO_STR
3066 "Direct vtysh output to file\n"
3067 "Direct vtysh output to file\n"
3068 "Path to dump output to\n")
3069 {
3070 if (vty->of != stdout) {
3071 fclose(vty->of);
3072 vty->of = stdout;
3073 }
3074 return CMD_SUCCESS;
3075 }
3076
3077 DEFUN(find,
3078 find_cmd,
3079 "find COMMAND...",
3080 "Find CLI command containing text\n"
3081 "Text to search for\n")
3082 {
3083 char *text = argv_concat(argv, argc, 1);
3084 const struct cmd_node *node;
3085 const struct cmd_element *cli;
3086 vector clis;
3087
3088 for (unsigned int i = 0; i < vector_active(cmdvec); i++) {
3089 node = vector_slot(cmdvec, i);
3090 if (!node)
3091 continue;
3092 clis = node->cmd_vector;
3093 for (unsigned int j = 0; j < vector_active(clis); j++) {
3094 cli = vector_slot(clis, j);
3095 if (strcasestr(cli->string, text))
3096 vty_out(vty, " (%s) %s\n",
3097 node_names[node->node], cli->string);
3098 }
3099 }
3100
3101 XFREE(MTYPE_TMP, text);
3102
3103 return CMD_SUCCESS;
3104 }
3105
3106 DEFUN_HIDDEN(show_cli_graph_vtysh,
3107 show_cli_graph_vtysh_cmd,
3108 "show cli graph",
3109 SHOW_STR
3110 "CLI reflection\n"
3111 "Dump current command space as DOT graph\n")
3112 {
3113 struct cmd_node *cn = vector_slot(cmdvec, vty->node);
3114 char *dot = cmd_graph_dump_dot(cn->cmdgraph);
3115
3116 vty_out(vty, "%s\n", dot);
3117 XFREE(MTYPE_TMP, dot);
3118 return CMD_SUCCESS;
3119 }
3120
3121 static void vtysh_install_default(enum node_type node)
3122 {
3123 install_element(node, &config_list_cmd);
3124 install_element(node, &find_cmd);
3125 install_element(node, &show_cli_graph_vtysh_cmd);
3126 install_element(node, &vtysh_output_file_cmd);
3127 install_element(node, &no_vtysh_output_file_cmd);
3128 }
3129
3130 /* Making connection to protocol daemon. */
3131 static int vtysh_connect(struct vtysh_client *vclient)
3132 {
3133 int ret;
3134 int sock, len;
3135 struct sockaddr_un addr;
3136 struct stat s_stat;
3137 const char *path;
3138
3139 if (!vclient->path[0])
3140 snprintf(vclient->path, sizeof(vclient->path), "%s/%s.vty",
3141 vtydir, vclient->name);
3142 path = vclient->path;
3143
3144 /* Stat socket to see if we have permission to access it. */
3145 ret = stat(path, &s_stat);
3146 if (ret < 0 && errno != ENOENT) {
3147 fprintf(stderr, "vtysh_connect(%s): stat = %s\n", path,
3148 safe_strerror(errno));
3149 exit(1);
3150 }
3151
3152 if (ret >= 0) {
3153 if (!S_ISSOCK(s_stat.st_mode)) {
3154 fprintf(stderr, "vtysh_connect(%s): Not a socket\n",
3155 path);
3156 exit(1);
3157 }
3158 }
3159
3160 sock = socket(AF_UNIX, SOCK_STREAM, 0);
3161 if (sock < 0) {
3162 #ifdef DEBUG
3163 fprintf(stderr, "vtysh_connect(%s): socket = %s\n", path,
3164 safe_strerror(errno));
3165 #endif /* DEBUG */
3166 return -1;
3167 }
3168
3169 memset(&addr, 0, sizeof(struct sockaddr_un));
3170 addr.sun_family = AF_UNIX;
3171 strlcpy(addr.sun_path, path, sizeof(addr.sun_path));
3172 #ifdef HAVE_STRUCT_SOCKADDR_UN_SUN_LEN
3173 len = addr.sun_len = SUN_LEN(&addr);
3174 #else
3175 len = sizeof(addr.sun_family) + strlen(addr.sun_path);
3176 #endif /* HAVE_STRUCT_SOCKADDR_UN_SUN_LEN */
3177
3178 ret = connect(sock, (struct sockaddr *)&addr, len);
3179 if (ret < 0) {
3180 #ifdef DEBUG
3181 fprintf(stderr, "vtysh_connect(%s): connect = %s\n", path,
3182 safe_strerror(errno));
3183 #endif /* DEBUG */
3184 close(sock);
3185 return -1;
3186 }
3187 vclient->fd = sock;
3188
3189 return 0;
3190 }
3191
3192 static int vtysh_reconnect(struct vtysh_client *vclient)
3193 {
3194 int ret;
3195
3196 fprintf(stderr, "Warning: connecting to %s...", vclient->name);
3197 ret = vtysh_connect(vclient);
3198 if (ret < 0) {
3199 fprintf(stderr, "failed!\n");
3200 return ret;
3201 }
3202 fprintf(stderr, "success!\n");
3203 if (vtysh_client_execute(vclient, "enable") < 0)
3204 return -1;
3205 return vtysh_execute_no_pager("end");
3206 }
3207
3208 /* Return true if str ends with suffix, else return false */
3209 static int ends_with(const char *str, const char *suffix)
3210 {
3211 if (!str || !suffix)
3212 return 0;
3213 size_t lenstr = strlen(str);
3214 size_t lensuffix = strlen(suffix);
3215 if (lensuffix > lenstr)
3216 return 0;
3217 return strncmp(str + lenstr - lensuffix, suffix, lensuffix) == 0;
3218 }
3219
3220 static void vtysh_client_sorted_insert(struct vtysh_client *head_client,
3221 struct vtysh_client *client)
3222 {
3223 struct vtysh_client *prev_node, *current_node;
3224
3225 prev_node = head_client;
3226 current_node = head_client->next;
3227 while (current_node) {
3228 if (strcmp(current_node->path, client->path) > 0)
3229 break;
3230
3231 prev_node = current_node;
3232 current_node = current_node->next;
3233 }
3234 client->next = current_node;
3235 prev_node->next = client;
3236 }
3237
3238 #define MAXIMUM_INSTANCES 10
3239
3240 static void vtysh_update_all_insances(struct vtysh_client *head_client)
3241 {
3242 struct vtysh_client *client;
3243 DIR *dir;
3244 struct dirent *file;
3245 int n = 0;
3246
3247 if (head_client->flag != VTYSH_OSPFD)
3248 return;
3249
3250 /* ls vty_sock_dir and look for all files ending in .vty */
3251 dir = opendir(vtydir);
3252 if (dir) {
3253 while ((file = readdir(dir)) != NULL) {
3254 if (begins_with(file->d_name, "ospfd-")
3255 && ends_with(file->d_name, ".vty")) {
3256 if (n == MAXIMUM_INSTANCES) {
3257 fprintf(stderr,
3258 "Parsing %s, client limit(%d) reached!\n",
3259 vtydir, n);
3260 break;
3261 }
3262 client = (struct vtysh_client *)malloc(
3263 sizeof(struct vtysh_client));
3264 client->fd = -1;
3265 client->name = "ospfd";
3266 client->flag = VTYSH_OSPFD;
3267 snprintf(client->path, sizeof(client->path),
3268 "%s/%s", vtydir, file->d_name);
3269 client->next = NULL;
3270 vtysh_client_sorted_insert(head_client, client);
3271 n++;
3272 }
3273 }
3274 closedir(dir);
3275 }
3276 }
3277
3278 static int vtysh_connect_all_instances(struct vtysh_client *head_client)
3279 {
3280 struct vtysh_client *client;
3281 int rc = 0;
3282
3283 vtysh_update_all_insances(head_client);
3284
3285 client = head_client->next;
3286 while (client) {
3287 if (vtysh_connect(client) == 0)
3288 rc++;
3289 client = client->next;
3290 }
3291
3292 return rc;
3293 }
3294
3295 int vtysh_connect_all(const char *daemon_name)
3296 {
3297 unsigned int i;
3298 int rc = 0;
3299 int matches = 0;
3300
3301 for (i = 0; i < array_size(vtysh_client); i++) {
3302 if (!daemon_name
3303 || !strcmp(daemon_name, vtysh_client[i].name)) {
3304 matches++;
3305 if (vtysh_connect(&vtysh_client[i]) == 0)
3306 rc++;
3307
3308 rc += vtysh_connect_all_instances(&vtysh_client[i]);
3309 }
3310 }
3311 if (!matches)
3312 fprintf(stderr, "Error: no daemons match name %s!\n",
3313 daemon_name);
3314 return rc;
3315 }
3316
3317 /* To disable readline's filename completion. */
3318 static char *vtysh_completion_entry_function(const char *ignore,
3319 int invoking_key)
3320 {
3321 return NULL;
3322 }
3323
3324 void vtysh_readline_init(void)
3325 {
3326 /* readline related settings. */
3327 rl_initialize();
3328 rl_bind_key('?', (rl_command_func_t *)vtysh_rl_describe);
3329 rl_completion_entry_function = vtysh_completion_entry_function;
3330 rl_attempted_completion_function =
3331 (rl_completion_func_t *)new_completion;
3332 }
3333
3334 char *vtysh_prompt(void)
3335 {
3336 static char buf[100];
3337
3338 snprintf(buf, sizeof buf, cmd_prompt(vty->node), cmd_hostname_get());
3339 return buf;
3340 }
3341
3342 static void vtysh_ac_line(void *arg, const char *line)
3343 {
3344 vector comps = arg;
3345 size_t i;
3346 for (i = 0; i < vector_active(comps); i++)
3347 if (!strcmp(line, (char *)vector_slot(comps, i)))
3348 return;
3349 vector_set(comps, XSTRDUP(MTYPE_COMPLETION, line));
3350 }
3351
3352 static void vtysh_autocomplete(vector comps, struct cmd_token *token)
3353 {
3354 char accmd[256];
3355 size_t i;
3356
3357 snprintf(accmd, sizeof(accmd), "autocomplete %d %s %s", token->type,
3358 token->text, token->varname ? token->varname : "-");
3359
3360 vty->of_saved = vty->of;
3361 vty->of = NULL;
3362 for (i = 0; i < array_size(vtysh_client); i++)
3363 vtysh_client_run_all(&vtysh_client[i], accmd, 1, vtysh_ac_line,
3364 comps);
3365 vty->of = vty->of_saved;
3366 }
3367
3368 static const struct cmd_variable_handler vtysh_var_handler[] = {
3369 {/* match all */
3370 .tokenname = NULL,
3371 .varname = NULL,
3372 .completions = vtysh_autocomplete},
3373 {.completions = NULL}};
3374
3375 void vtysh_uninit()
3376 {
3377 if (vty->of != stdout)
3378 fclose(vty->of);
3379 }
3380
3381 void vtysh_init_vty(void)
3382 {
3383 /* Make vty structure. */
3384 vty = vty_new();
3385 vty->type = VTY_SHELL;
3386 vty->node = VIEW_NODE;
3387
3388 /* set default output */
3389 vty->of = stdout;
3390
3391 /* Initialize commands. */
3392 cmd_init(0);
3393 cmd_variable_handler_register(vtysh_var_handler);
3394
3395 /* Install nodes. */
3396 install_node(&bgp_node, NULL);
3397 install_node(&rip_node, NULL);
3398 install_node(&interface_node, NULL);
3399 install_node(&pw_node, NULL);
3400 install_node(&link_params_node, NULL);
3401 install_node(&logicalrouter_node, NULL);
3402 install_node(&vrf_node, NULL);
3403 install_node(&nh_group_node, NULL);
3404 install_node(&rmap_node, NULL);
3405 install_node(&pbr_map_node, NULL);
3406 install_node(&zebra_node, NULL);
3407 install_node(&bgp_vpnv4_node, NULL);
3408 install_node(&bgp_vpnv6_node, NULL);
3409 install_node(&bgp_flowspecv4_node, NULL);
3410 install_node(&bgp_flowspecv6_node, NULL);
3411 install_node(&bgp_ipv4_node, NULL);
3412 install_node(&bgp_ipv4m_node, NULL);
3413 install_node(&bgp_ipv4l_node, NULL);
3414 install_node(&bgp_ipv6_node, NULL);
3415 install_node(&bgp_ipv6m_node, NULL);
3416 install_node(&bgp_ipv6l_node, NULL);
3417 install_node(&bgp_vrf_policy_node, NULL);
3418 install_node(&bgp_evpn_node, NULL);
3419 install_node(&bgp_evpn_vni_node, NULL);
3420 install_node(&bgp_vnc_defaults_node, NULL);
3421 install_node(&bgp_vnc_nve_group_node, NULL);
3422 install_node(&bgp_vnc_l2_group_node, NULL);
3423 install_node(&ospf_node, NULL);
3424 install_node(&eigrp_node, NULL);
3425 install_node(&babel_node, NULL);
3426 install_node(&ripng_node, NULL);
3427 install_node(&ospf6_node, NULL);
3428 install_node(&ldp_node, NULL);
3429 install_node(&ldp_ipv4_node, NULL);
3430 install_node(&ldp_ipv6_node, NULL);
3431 install_node(&ldp_ipv4_iface_node, NULL);
3432 install_node(&ldp_ipv6_iface_node, NULL);
3433 install_node(&ldp_l2vpn_node, NULL);
3434 install_node(&ldp_pseudowire_node, NULL);
3435 install_node(&keychain_node, NULL);
3436 install_node(&keychain_key_node, NULL);
3437 install_node(&isis_node, NULL);
3438 install_node(&vty_node, NULL);
3439 #if defined(HAVE_RPKI)
3440 install_node(&rpki_node, NULL);
3441 #endif
3442
3443 struct cmd_node *node;
3444 for (unsigned int i = 0; i < vector_active(cmdvec); i++) {
3445 node = vector_slot(cmdvec, i);
3446 if (!node || node->node == VIEW_NODE)
3447 continue;
3448 vtysh_install_default(node->node);
3449 }
3450
3451 install_element(VIEW_NODE, &vtysh_enable_cmd);
3452 install_element(ENABLE_NODE, &vtysh_config_terminal_cmd);
3453 install_element(ENABLE_NODE, &vtysh_disable_cmd);
3454
3455 /* "exit" command. */
3456 install_element(VIEW_NODE, &vtysh_exit_all_cmd);
3457 install_element(CONFIG_NODE, &vtysh_exit_all_cmd);
3458 install_element(VIEW_NODE, &vtysh_quit_all_cmd);
3459 install_element(CONFIG_NODE, &vtysh_quit_all_cmd);
3460 install_element(RIP_NODE, &vtysh_exit_ripd_cmd);
3461 install_element(RIP_NODE, &vtysh_quit_ripd_cmd);
3462 install_element(RIPNG_NODE, &vtysh_exit_ripngd_cmd);
3463 install_element(RIPNG_NODE, &vtysh_quit_ripngd_cmd);
3464 install_element(OSPF_NODE, &vtysh_exit_ospfd_cmd);
3465 install_element(OSPF_NODE, &vtysh_quit_ospfd_cmd);
3466 install_element(EIGRP_NODE, &vtysh_exit_eigrpd_cmd);
3467 install_element(EIGRP_NODE, &vtysh_quit_eigrpd_cmd);
3468 install_element(BABEL_NODE, &vtysh_exit_babeld_cmd);
3469 install_element(BABEL_NODE, &vtysh_quit_babeld_cmd);
3470 install_element(OSPF6_NODE, &vtysh_exit_ospf6d_cmd);
3471 install_element(OSPF6_NODE, &vtysh_quit_ospf6d_cmd);
3472 #if defined(HAVE_LDPD)
3473 install_element(LDP_NODE, &vtysh_exit_ldpd_cmd);
3474 install_element(LDP_NODE, &vtysh_quit_ldpd_cmd);
3475 install_element(LDP_IPV4_NODE, &vtysh_exit_ldpd_cmd);
3476 install_element(LDP_IPV4_NODE, &vtysh_quit_ldpd_cmd);
3477 install_element(LDP_IPV4_NODE, &ldp_exit_address_family_cmd);
3478 install_element(LDP_IPV6_NODE, &vtysh_exit_ldpd_cmd);
3479 install_element(LDP_IPV6_NODE, &vtysh_quit_ldpd_cmd);
3480 install_element(LDP_IPV6_NODE, &ldp_exit_address_family_cmd);
3481 install_element(LDP_IPV4_IFACE_NODE, &vtysh_exit_ldpd_cmd);
3482 install_element(LDP_IPV4_IFACE_NODE, &vtysh_quit_ldpd_cmd);
3483 install_element(LDP_IPV6_IFACE_NODE, &vtysh_exit_ldpd_cmd);
3484 install_element(LDP_IPV6_IFACE_NODE, &vtysh_quit_ldpd_cmd);
3485 install_element(LDP_L2VPN_NODE, &vtysh_exit_ldpd_cmd);
3486 install_element(LDP_L2VPN_NODE, &vtysh_quit_ldpd_cmd);
3487 install_element(LDP_PSEUDOWIRE_NODE, &vtysh_exit_ldpd_cmd);
3488 install_element(LDP_PSEUDOWIRE_NODE, &vtysh_quit_ldpd_cmd);
3489 #endif
3490 install_element(BGP_NODE, &vtysh_exit_bgpd_cmd);
3491 install_element(BGP_NODE, &vtysh_quit_bgpd_cmd);
3492 install_element(BGP_VPNV4_NODE, &vtysh_exit_bgpd_cmd);
3493 install_element(BGP_VPNV4_NODE, &vtysh_quit_bgpd_cmd);
3494 install_element(BGP_VPNV6_NODE, &vtysh_exit_bgpd_cmd);
3495 install_element(BGP_VPNV6_NODE, &vtysh_quit_bgpd_cmd);
3496 install_element(BGP_FLOWSPECV4_NODE, &vtysh_exit_bgpd_cmd);
3497 install_element(BGP_FLOWSPECV4_NODE, &vtysh_quit_bgpd_cmd);
3498 install_element(BGP_FLOWSPECV6_NODE, &vtysh_exit_bgpd_cmd);
3499 install_element(BGP_FLOWSPECV6_NODE, &vtysh_quit_bgpd_cmd);
3500 install_element(BGP_IPV4_NODE, &vtysh_exit_bgpd_cmd);
3501 install_element(BGP_IPV4_NODE, &vtysh_quit_bgpd_cmd);
3502 install_element(BGP_IPV4M_NODE, &vtysh_exit_bgpd_cmd);
3503 install_element(BGP_IPV4M_NODE, &vtysh_quit_bgpd_cmd);
3504 install_element(BGP_IPV4L_NODE, &vtysh_exit_bgpd_cmd);
3505 install_element(BGP_IPV4L_NODE, &vtysh_quit_bgpd_cmd);
3506 install_element(BGP_IPV6_NODE, &vtysh_exit_bgpd_cmd);
3507 install_element(BGP_IPV6_NODE, &vtysh_quit_bgpd_cmd);
3508 install_element(BGP_IPV6M_NODE, &vtysh_exit_bgpd_cmd);
3509 install_element(BGP_IPV6M_NODE, &vtysh_quit_bgpd_cmd);
3510 install_element(BGP_EVPN_NODE, &vtysh_quit_bgpd_cmd);
3511 install_element(BGP_EVPN_NODE, &vtysh_exit_bgpd_cmd);
3512 install_element(BGP_EVPN_VNI_NODE, &vtysh_exit_bgpd_cmd);
3513 install_element(BGP_EVPN_VNI_NODE, &vtysh_quit_bgpd_cmd);
3514 install_element(BGP_IPV6L_NODE, &vtysh_exit_bgpd_cmd);
3515 install_element(BGP_IPV6L_NODE, &vtysh_quit_bgpd_cmd);
3516 #if defined(ENABLE_BGP_VNC)
3517 install_element(BGP_VRF_POLICY_NODE, &vtysh_exit_bgpd_cmd);
3518 install_element(BGP_VRF_POLICY_NODE, &vtysh_quit_bgpd_cmd);
3519 install_element(BGP_VNC_DEFAULTS_NODE, &vtysh_exit_bgpd_cmd);
3520 install_element(BGP_VNC_DEFAULTS_NODE, &vtysh_quit_bgpd_cmd);
3521 install_element(BGP_VNC_NVE_GROUP_NODE, &vtysh_exit_bgpd_cmd);
3522 install_element(BGP_VNC_NVE_GROUP_NODE, &vtysh_quit_bgpd_cmd);
3523 install_element(BGP_VNC_L2_GROUP_NODE, &vtysh_exit_bgpd_cmd);
3524 install_element(BGP_VNC_L2_GROUP_NODE, &vtysh_quit_bgpd_cmd);
3525 #endif
3526 install_element(ISIS_NODE, &vtysh_exit_isisd_cmd);
3527 install_element(ISIS_NODE, &vtysh_quit_isisd_cmd);
3528 install_element(KEYCHAIN_NODE, &vtysh_exit_ripd_cmd);
3529 install_element(KEYCHAIN_NODE, &vtysh_quit_ripd_cmd);
3530 install_element(KEYCHAIN_KEY_NODE, &vtysh_exit_ripd_cmd);
3531 install_element(KEYCHAIN_KEY_NODE, &vtysh_quit_ripd_cmd);
3532 install_element(RMAP_NODE, &vtysh_exit_rmap_cmd);
3533 install_element(RMAP_NODE, &vtysh_quit_rmap_cmd);
3534 install_element(PBRMAP_NODE, &vtysh_exit_pbr_map_cmd);
3535 install_element(PBRMAP_NODE, &vtysh_quit_pbr_map_cmd);
3536 install_element(VTY_NODE, &vtysh_exit_line_vty_cmd);
3537 install_element(VTY_NODE, &vtysh_quit_line_vty_cmd);
3538
3539 /* "end" command. */
3540 install_element(CONFIG_NODE, &vtysh_end_all_cmd);
3541 install_element(ENABLE_NODE, &vtysh_end_all_cmd);
3542 install_element(RIP_NODE, &vtysh_end_all_cmd);
3543 install_element(RIPNG_NODE, &vtysh_end_all_cmd);
3544 install_element(OSPF_NODE, &vtysh_end_all_cmd);
3545 install_element(EIGRP_NODE, &vtysh_end_all_cmd);
3546 install_element(BABEL_NODE, &vtysh_end_all_cmd);
3547 install_element(OSPF6_NODE, &vtysh_end_all_cmd);
3548 install_element(LDP_NODE, &vtysh_end_all_cmd);
3549 install_element(LDP_IPV4_NODE, &vtysh_end_all_cmd);
3550 install_element(LDP_IPV6_NODE, &vtysh_end_all_cmd);
3551 install_element(LDP_IPV4_IFACE_NODE, &vtysh_end_all_cmd);
3552 install_element(LDP_IPV6_IFACE_NODE, &vtysh_end_all_cmd);
3553 install_element(LDP_L2VPN_NODE, &vtysh_end_all_cmd);
3554 install_element(LDP_PSEUDOWIRE_NODE, &vtysh_end_all_cmd);
3555 install_element(BGP_NODE, &vtysh_end_all_cmd);
3556 install_element(BGP_IPV4_NODE, &vtysh_end_all_cmd);
3557 install_element(BGP_IPV4M_NODE, &vtysh_end_all_cmd);
3558 install_element(BGP_IPV4L_NODE, &vtysh_end_all_cmd);
3559 install_element(BGP_VPNV4_NODE, &vtysh_end_all_cmd);
3560 install_element(BGP_VPNV6_NODE, &vtysh_end_all_cmd);
3561 install_element(BGP_FLOWSPECV4_NODE, &vtysh_end_all_cmd);
3562 install_element(BGP_FLOWSPECV6_NODE, &vtysh_end_all_cmd);
3563 install_element(BGP_IPV6_NODE, &vtysh_end_all_cmd);
3564 install_element(BGP_IPV6M_NODE, &vtysh_end_all_cmd);
3565 install_element(BGP_IPV6L_NODE, &vtysh_end_all_cmd);
3566 install_element(BGP_VRF_POLICY_NODE, &vtysh_end_all_cmd);
3567 install_element(BGP_EVPN_NODE, &vtysh_end_all_cmd);
3568 install_element(BGP_EVPN_VNI_NODE, &vtysh_end_all_cmd);
3569 install_element(BGP_VNC_DEFAULTS_NODE, &vtysh_end_all_cmd);
3570 install_element(BGP_VNC_NVE_GROUP_NODE, &vtysh_end_all_cmd);
3571 install_element(BGP_VNC_L2_GROUP_NODE, &vtysh_end_all_cmd);
3572 install_element(ISIS_NODE, &vtysh_end_all_cmd);
3573 install_element(KEYCHAIN_NODE, &vtysh_end_all_cmd);
3574 install_element(KEYCHAIN_KEY_NODE, &vtysh_end_all_cmd);
3575 install_element(RMAP_NODE, &vtysh_end_all_cmd);
3576 install_element(PBRMAP_NODE, &vtysh_end_all_cmd);
3577 install_element(VTY_NODE, &vtysh_end_all_cmd);
3578
3579 install_element(INTERFACE_NODE, &vtysh_interface_desc_cmd);
3580 install_element(INTERFACE_NODE, &vtysh_no_interface_desc_cmd);
3581 install_element(INTERFACE_NODE, &vtysh_end_all_cmd);
3582 install_element(INTERFACE_NODE, &vtysh_exit_interface_cmd);
3583 install_element(LINK_PARAMS_NODE, &exit_link_params_cmd);
3584 install_element(LINK_PARAMS_NODE, &vtysh_end_all_cmd);
3585 install_element(LINK_PARAMS_NODE, &vtysh_exit_interface_cmd);
3586 install_element(INTERFACE_NODE, &vtysh_quit_interface_cmd);
3587
3588 install_element(PW_NODE, &vtysh_end_all_cmd);
3589 install_element(PW_NODE, &vtysh_exit_interface_cmd);
3590 install_element(PW_NODE, &vtysh_quit_interface_cmd);
3591
3592 install_element(LOGICALROUTER_NODE, &vtysh_end_all_cmd);
3593
3594 install_element(CONFIG_NODE, &vtysh_logicalrouter_cmd);
3595 install_element(CONFIG_NODE, &vtysh_no_logicalrouter_cmd);
3596 install_element(LOGICALROUTER_NODE, &vtysh_exit_logicalrouter_cmd);
3597 install_element(LOGICALROUTER_NODE, &vtysh_quit_logicalrouter_cmd);
3598
3599 install_element(CONFIG_NODE, &vtysh_nexthop_group_cmd);
3600 install_element(NH_GROUP_NODE, &vtysh_end_all_cmd);
3601 install_element(NH_GROUP_NODE, &vtysh_exit_nexthop_group_cmd);
3602 install_element(NH_GROUP_NODE, &vtysh_quit_nexthop_group_cmd);
3603
3604 install_element(VRF_NODE, &vtysh_end_all_cmd);
3605 install_element(VRF_NODE, &vtysh_exit_vrf_cmd);
3606 install_element(VRF_NODE, &vtysh_quit_vrf_cmd);
3607
3608 install_element(CONFIG_NODE, &router_eigrp_cmd);
3609 install_element(CONFIG_NODE, &router_babel_cmd);
3610 install_element(CONFIG_NODE, &router_rip_cmd);
3611 install_element(CONFIG_NODE, &router_ripng_cmd);
3612 install_element(CONFIG_NODE, &router_ospf_cmd);
3613 install_element(CONFIG_NODE, &router_ospf6_cmd);
3614 #if defined(HAVE_LDPD)
3615 install_element(CONFIG_NODE, &ldp_mpls_ldp_cmd);
3616 install_element(LDP_NODE, &ldp_address_family_ipv4_cmd);
3617 install_element(LDP_NODE, &ldp_address_family_ipv6_cmd);
3618 install_element(LDP_IPV4_NODE, &ldp_interface_ifname_cmd);
3619 install_element(LDP_IPV6_NODE, &ldp_interface_ifname_cmd);
3620 install_element(CONFIG_NODE, &ldp_l2vpn_word_type_vpls_cmd);
3621 install_element(LDP_L2VPN_NODE, &ldp_member_pseudowire_ifname_cmd);
3622 #endif
3623 install_element(CONFIG_NODE, &router_isis_cmd);
3624 install_element(CONFIG_NODE, &router_bgp_cmd);
3625 install_element(BGP_NODE, &address_family_vpnv4_cmd);
3626 install_element(BGP_NODE, &address_family_vpnv6_cmd);
3627 #if defined(ENABLE_BGP_VNC)
3628 install_element(BGP_NODE, &vnc_vrf_policy_cmd);
3629 install_element(BGP_NODE, &vnc_defaults_cmd);
3630 install_element(BGP_NODE, &vnc_nve_group_cmd);
3631 install_element(BGP_NODE, &vnc_l2_group_cmd);
3632 #endif
3633 install_element(BGP_NODE, &address_family_ipv4_cmd);
3634 install_element(BGP_NODE, &address_family_ipv4_multicast_cmd);
3635 install_element(BGP_NODE, &address_family_ipv4_vpn_cmd);
3636 install_element(BGP_NODE, &address_family_ipv4_labeled_unicast_cmd);
3637 install_element(BGP_NODE, &address_family_ipv6_cmd);
3638 install_element(BGP_NODE, &address_family_ipv6_multicast_cmd);
3639 install_element(BGP_NODE, &address_family_ipv6_vpn_cmd);
3640 install_element(BGP_NODE, &address_family_ipv6_labeled_unicast_cmd);
3641 install_element(BGP_NODE, &address_family_evpn_cmd);
3642 install_element(BGP_NODE, &address_family_flowspecv4_cmd);
3643 install_element(BGP_NODE, &address_family_flowspecv6_cmd);
3644 #if defined(HAVE_CUMULUS)
3645 install_element(BGP_NODE, &address_family_evpn2_cmd);
3646 #endif
3647 install_element(BGP_VPNV4_NODE, &exit_address_family_cmd);
3648 install_element(BGP_VPNV6_NODE, &exit_address_family_cmd);
3649 install_element(BGP_IPV4_NODE, &exit_address_family_cmd);
3650 install_element(BGP_IPV4M_NODE, &exit_address_family_cmd);
3651 install_element(BGP_IPV4L_NODE, &exit_address_family_cmd);
3652 install_element(BGP_IPV6_NODE, &exit_address_family_cmd);
3653 install_element(BGP_IPV6M_NODE, &exit_address_family_cmd);
3654 install_element(BGP_EVPN_NODE, &exit_address_family_cmd);
3655 install_element(BGP_IPV6L_NODE, &exit_address_family_cmd);
3656 install_element(BGP_FLOWSPECV4_NODE, &exit_address_family_cmd);
3657 install_element(BGP_FLOWSPECV6_NODE, &exit_address_family_cmd);
3658
3659 #if defined(HAVE_RPKI)
3660 install_element(CONFIG_NODE, &rpki_cmd);
3661 install_element(RPKI_NODE, &rpki_exit_cmd);
3662 install_element(RPKI_NODE, &rpki_quit_cmd);
3663 install_element(RPKI_NODE, &vtysh_end_all_cmd);
3664 #endif
3665
3666 /* EVPN commands */
3667 install_element(BGP_EVPN_NODE, &bgp_evpn_vni_cmd);
3668 install_element(BGP_EVPN_VNI_NODE, &exit_vni_cmd);
3669
3670 install_element(BGP_VRF_POLICY_NODE, &exit_vrf_policy_cmd);
3671 install_element(BGP_VNC_DEFAULTS_NODE, &exit_vnc_config_cmd);
3672 install_element(BGP_VNC_NVE_GROUP_NODE, &exit_vnc_config_cmd);
3673 install_element(BGP_VNC_L2_GROUP_NODE, &exit_vnc_config_cmd);
3674
3675 install_element(CONFIG_NODE, &key_chain_cmd);
3676 install_element(CONFIG_NODE, &vtysh_route_map_cmd);
3677 install_element(CONFIG_NODE, &vtysh_pbr_map_cmd);
3678 install_element(CONFIG_NODE, &vtysh_no_pbr_map_cmd);
3679 install_element(CONFIG_NODE, &vtysh_line_vty_cmd);
3680 install_element(KEYCHAIN_NODE, &key_cmd);
3681 install_element(KEYCHAIN_NODE, &key_chain_cmd);
3682 install_element(KEYCHAIN_KEY_NODE, &key_chain_cmd);
3683 install_element(CONFIG_NODE, &vtysh_interface_cmd);
3684 install_element(CONFIG_NODE, &vtysh_no_interface_cmd);
3685 install_element(CONFIG_NODE, &vtysh_no_interface_vrf_cmd);
3686 install_element(CONFIG_NODE, &vtysh_pseudowire_cmd);
3687 install_element(INTERFACE_NODE, &vtysh_link_params_cmd);
3688 install_element(ENABLE_NODE, &vtysh_show_running_config_cmd);
3689 install_element(ENABLE_NODE, &vtysh_copy_running_config_cmd);
3690
3691 install_element(VRF_NODE, &exit_vrf_config_cmd);
3692
3693 install_element(CONFIG_NODE, &vtysh_vrf_cmd);
3694 install_element(CONFIG_NODE, &vtysh_no_vrf_cmd);
3695 install_element(CONFIG_NODE, &vtysh_no_nexthop_group_cmd);
3696
3697 /* "write terminal" command. */
3698 install_element(ENABLE_NODE, &vtysh_write_terminal_cmd);
3699
3700 install_element(CONFIG_NODE, &vtysh_integrated_config_cmd);
3701 install_element(CONFIG_NODE, &no_vtysh_integrated_config_cmd);
3702
3703 /* "write memory" command. */
3704 install_element(ENABLE_NODE, &vtysh_write_memory_cmd);
3705
3706 install_element(VIEW_NODE, &vtysh_terminal_length_cmd);
3707 install_element(VIEW_NODE, &vtysh_terminal_no_length_cmd);
3708 install_element(VIEW_NODE, &vtysh_show_daemons_cmd);
3709
3710 install_element(VIEW_NODE, &vtysh_ping_cmd);
3711 install_element(VIEW_NODE, &vtysh_ping_ip_cmd);
3712 install_element(VIEW_NODE, &vtysh_traceroute_cmd);
3713 install_element(VIEW_NODE, &vtysh_traceroute_ip_cmd);
3714 install_element(VIEW_NODE, &vtysh_mtrace_cmd);
3715 install_element(VIEW_NODE, &vtysh_ping6_cmd);
3716 install_element(VIEW_NODE, &vtysh_traceroute6_cmd);
3717 #if defined(HAVE_SHELL_ACCESS)
3718 install_element(VIEW_NODE, &vtysh_telnet_cmd);
3719 install_element(VIEW_NODE, &vtysh_telnet_port_cmd);
3720 install_element(VIEW_NODE, &vtysh_ssh_cmd);
3721 #endif
3722 #if defined(HAVE_SHELL_ACCESS)
3723 install_element(ENABLE_NODE, &vtysh_start_shell_cmd);
3724 install_element(ENABLE_NODE, &vtysh_start_bash_cmd);
3725 install_element(ENABLE_NODE, &vtysh_start_zsh_cmd);
3726 #endif
3727
3728 /* debugging */
3729 install_element(VIEW_NODE, &vtysh_show_debugging_cmd);
3730 install_element(VIEW_NODE, &vtysh_show_debugging_hashtable_cmd);
3731 install_element(ENABLE_NODE, &vtysh_debug_all_cmd);
3732 install_element(CONFIG_NODE, &vtysh_debug_all_cmd);
3733
3734 /* misc lib show commands */
3735 install_element(VIEW_NODE, &vtysh_show_memory_cmd);
3736 install_element(VIEW_NODE, &vtysh_show_modules_cmd);
3737 install_element(VIEW_NODE, &vtysh_show_work_queues_cmd);
3738 install_element(VIEW_NODE, &vtysh_show_work_queues_daemon_cmd);
3739 install_element(VIEW_NODE, &vtysh_show_thread_cmd);
3740 install_element(VIEW_NODE, &vtysh_show_poll_cmd);
3741
3742 /* Logging */
3743 install_element(VIEW_NODE, &vtysh_show_logging_cmd);
3744 install_element(CONFIG_NODE, &vtysh_log_stdout_cmd);
3745 install_element(CONFIG_NODE, &vtysh_log_stdout_level_cmd);
3746 install_element(CONFIG_NODE, &no_vtysh_log_stdout_cmd);
3747 install_element(CONFIG_NODE, &vtysh_log_file_cmd);
3748 install_element(CONFIG_NODE, &vtysh_log_file_level_cmd);
3749 install_element(CONFIG_NODE, &no_vtysh_log_file_cmd);
3750 install_element(CONFIG_NODE, &vtysh_log_monitor_cmd);
3751 install_element(CONFIG_NODE, &no_vtysh_log_monitor_cmd);
3752 install_element(CONFIG_NODE, &vtysh_log_syslog_cmd);
3753 install_element(CONFIG_NODE, &no_vtysh_log_syslog_cmd);
3754 install_element(CONFIG_NODE, &vtysh_log_facility_cmd);
3755 install_element(CONFIG_NODE, &no_vtysh_log_facility_cmd);
3756 install_element(CONFIG_NODE, &vtysh_log_record_priority_cmd);
3757 install_element(CONFIG_NODE, &no_vtysh_log_record_priority_cmd);
3758 install_element(CONFIG_NODE, &vtysh_log_timestamp_precision_cmd);
3759 install_element(CONFIG_NODE, &no_vtysh_log_timestamp_precision_cmd);
3760
3761 install_element(CONFIG_NODE, &vtysh_service_password_encrypt_cmd);
3762 install_element(CONFIG_NODE, &no_vtysh_service_password_encrypt_cmd);
3763
3764 install_element(CONFIG_NODE, &vtysh_password_cmd);
3765 install_element(CONFIG_NODE, &no_vtysh_password_cmd);
3766 install_element(CONFIG_NODE, &vtysh_enable_password_cmd);
3767 install_element(CONFIG_NODE, &no_vtysh_enable_password_cmd);
3768 }