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