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