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