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