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