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