1 /* Virtual terminal interface shell.
2 * Copyright (C) 2000 Kunihiro Ishiguro
4 * This file is part of GNU Zebra.
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
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.
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
26 #include <sys/resource.h>
29 #include <readline/readline.h>
30 #include <readline/history.h>
40 #include "vtysh/vtysh.h"
42 #include "bgpd/bgp_vty.h"
46 #include "command_graph.h"
50 DEFINE_MTYPE_STATIC(MVTYSH
, VTYSH_CMD
, "Vtysh cmd copy")
55 /* VTY shell pager name. */
56 char *vtysh_pager_name
= NULL
;
58 /* VTY shell client structure */
63 char path
[MAXPATHLEN
];
64 struct vtysh_client
*next
;
67 /* Some utility functions for working on vtysh-specific vty tasks */
69 static FILE *vty_open_pager(struct vty
*vty
)
74 if (!vtysh_pager_name
)
77 vty
->of_saved
= vty
->of
;
78 vty
->of
= popen(vtysh_pager_name
, "w");
79 if (vty
->of
== NULL
) {
80 vty
->of
= vty
->of_saved
;
90 static int vty_close_pager(struct vty
*vty
)
96 if (pclose(vty
->of
) == -1) {
101 vty
->of
= vty
->of_saved
;
102 vty
->is_paged
= false;
107 void vtysh_pager_init(void)
111 pager_defined
= getenv("VTYSH_PAGER");
114 vtysh_pager_name
= strdup(pager_defined
);
116 vtysh_pager_name
= strdup(VTYSH_PAGER
);
121 struct vtysh_client vtysh_client
[] = {
122 {.fd
= -1, .name
= "zebra", .flag
= VTYSH_ZEBRA
, .next
= NULL
},
123 {.fd
= -1, .name
= "ripd", .flag
= VTYSH_RIPD
, .next
= NULL
},
124 {.fd
= -1, .name
= "ripngd", .flag
= VTYSH_RIPNGD
, .next
= NULL
},
125 {.fd
= -1, .name
= "ospfd", .flag
= VTYSH_OSPFD
, .next
= NULL
},
126 {.fd
= -1, .name
= "ospf6d", .flag
= VTYSH_OSPF6D
, .next
= NULL
},
127 {.fd
= -1, .name
= "ldpd", .flag
= VTYSH_LDPD
, .next
= NULL
},
128 {.fd
= -1, .name
= "bgpd", .flag
= VTYSH_BGPD
, .next
= NULL
},
129 {.fd
= -1, .name
= "isisd", .flag
= VTYSH_ISISD
, .next
= NULL
},
130 {.fd
= -1, .name
= "pimd", .flag
= VTYSH_PIMD
, .next
= NULL
},
131 {.fd
= -1, .name
= "nhrpd", .flag
= VTYSH_NHRPD
, .next
= NULL
},
132 {.fd
= -1, .name
= "eigrpd", .flag
= VTYSH_EIGRPD
, .next
= NULL
},
133 {.fd
= -1, .name
= "babeld", .flag
= VTYSH_BABELD
, .next
= NULL
},
134 {.fd
= -1, .name
= "sharpd", .flag
= VTYSH_SHARPD
, .next
= NULL
},
135 {.fd
= -1, .name
= "watchfrr", .flag
= VTYSH_WATCHFRR
, .next
= NULL
},
136 {.fd
= -1, .name
= "pbrd", .flag
= VTYSH_PBRD
, .next
= NULL
},
137 {.fd
= -1, .name
= "staticd", .flag
= VTYSH_STATICD
, .next
= NULL
},
138 {.fd
= -1, .name
= "bfdd", .flag
= VTYSH_BFDD
, .next
= NULL
},
141 enum vtysh_write_integrated vtysh_write_integrated
=
142 WRITE_INTEGRATED_UNSPECIFIED
;
144 static int vtysh_reconnect(struct vtysh_client
*vclient
);
146 static void vclient_close(struct vtysh_client
*vclient
)
148 if (vclient
->fd
>= 0) {
150 "Warning: closing connection to %s because of an I/O error!\n",
153 /* indicate as candidate for reconnect */
154 vclient
->fd
= VTYSH_WAS_ACTIVE
;
159 * Send a CLI command to a client and read the response.
161 * Output will be printed to vty->of. If you want to suppress output, set that
165 * the client to send the command to
168 * the command to send
171 * if non-null, this will be called with each line of output received from
172 * the client passed in the second parameter
175 * optional first argument to pass to callback
180 static int vtysh_client_run(struct vtysh_client
*vclient
, const char *line
,
181 void (*callback
)(void *, const char *), void *cbarg
)
185 char *buf
= stackbuf
;
186 size_t bufsz
= sizeof(stackbuf
);
187 char *bufvalid
, *end
= NULL
;
188 char terminator
[3] = {0, 0, 0};
190 /* vclinet was previously active, try to reconnect */
191 if (vclient
->fd
== VTYSH_WAS_ACTIVE
) {
192 ret
= vtysh_reconnect(vclient
);
200 ret
= write(vclient
->fd
, line
, strlen(line
) + 1);
202 /* close connection and try to reconnect */
203 vclient_close(vclient
);
204 ret
= vtysh_reconnect(vclient
);
208 ret
= write(vclient
->fd
, line
, strlen(line
) + 1);
216 read(vclient
->fd
, bufvalid
, buf
+ bufsz
- bufvalid
- 1);
218 if (nread
< 0 && (errno
== EINTR
|| errno
== EAGAIN
))
222 vty_out(vty
, "vtysh: error reading from %s: %s (%d)",
223 vclient
->name
, safe_strerror(errno
), errno
);
229 /* Null terminate so we may pass this to *printf later. */
233 * We expect string output from daemons, so instead of looking
234 * for the full 3 null bytes of the terminator, we check for
235 * just one instead and assume it is the first byte of the
236 * terminator. The presence of the full terminator is checked
239 if (bufvalid
- buf
>= 4)
240 end
= memmem(bufvalid
- 4, 4, "\0", 1);
243 * calculate # bytes we have, up to & not including the
244 * terminator if present
246 size_t textlen
= (end
? end
: bufvalid
) - buf
;
249 /* feed line processing callback if present */
250 while (callback
&& bufvalid
> buf
&& (end
> buf
|| !end
)) {
251 textlen
= (end
? end
: bufvalid
) - buf
;
252 char *eol
= memchr(buf
, '\n', textlen
);
258 * no line break, end of input, no text left
259 * before end; nothing to write
263 /* no nl, end of input, but some text left */
265 else if (bufvalid
== buf
+ bufsz
- 1) {
267 * no nl, no end of input, no buffer space;
273 if (buf
== stackbuf
) {
274 new = XMALLOC(MTYPE_TMP
, bufsz
);
275 memcpy(new, stackbuf
, sizeof(stackbuf
));
277 new = XREALLOC(MTYPE_TMP
, buf
, bufsz
);
279 bufvalid
= bufvalid
- buf
+ new;
281 /* if end != NULL, we won't be reading more
291 /* eol is at line end now, either \n => \0 or \0\0\0 */
292 assert(eol
&& eol
<= bufvalid
);
295 vty_out(vty
, "%s\n", buf
);
297 callback(cbarg
, buf
);
299 /* shift back data and adjust bufvalid */
300 memmove(buf
, eol
, bufvalid
- eol
);
301 bufvalid
-= eol
- buf
;
306 /* else if no callback, dump raw */
309 vty_out(vty
, "%s", buf
);
310 memmove(buf
, buf
+ textlen
, bufvalid
- buf
- textlen
);
316 * ----------------------------------------------------
317 * At this point `buf` should be in one of two states:
318 * - Empty (i.e. buf == bufvalid)
319 * - Contains up to 4 bytes of the terminator
320 * ----------------------------------------------------
322 assert(((buf
== bufvalid
)
323 || (bufvalid
- buf
<= 4 && buf
[0] == 0x00)));
326 /* if we have the terminator, break */
327 if (end
&& bufvalid
- buf
== 4) {
328 assert(!memcmp(buf
, terminator
, 3));
337 vclient_close(vclient
);
341 XFREE(MTYPE_TMP
, buf
);
345 static int vtysh_client_run_all(struct vtysh_client
*head_client
,
346 const char *line
, int continue_on_err
,
347 void (*callback
)(void *, const char *),
350 struct vtysh_client
*client
;
351 int rc
, rc_all
= CMD_SUCCESS
;
352 int correct_instance
= 0, wrong_instance
= 0;
354 for (client
= head_client
; client
; client
= client
->next
) {
355 rc
= vtysh_client_run(client
, line
, callback
, cbarg
);
356 if (rc
== CMD_NOT_MY_INSTANCE
) {
362 if (rc
!= CMD_SUCCESS
) {
363 if (!continue_on_err
)
368 if (wrong_instance
&& !correct_instance
) {
370 "%% [%s]: command ignored as it targets an instance that is not running\n",
372 rc_all
= CMD_WARNING_CONFIG_FAILED
;
378 * Execute command against all daemons.
381 * where to start walking in the daemon list
384 * the specific command to execute
389 static int vtysh_client_execute(struct vtysh_client
*head_client
,
392 return vtysh_client_run_all(head_client
, line
, 0, NULL
, NULL
);
396 * Retrieve all running config from daemons and parse it with the vtysh config
397 * parser. Returned output is not displayed to the user.
400 * where to start walking in the daemon list
403 * the specific command to execute
405 static void vtysh_client_config(struct vtysh_client
*head_client
, char *line
)
407 /* watchfrr currently doesn't load any config, and has some hardcoded
408 * settings that show up in "show run". skip it here (for now at
409 * least) so we don't get that mangled up in config-write.
411 if (head_client
->flag
== VTYSH_WATCHFRR
)
414 /* suppress output to user */
415 vty
->of_saved
= vty
->of
;
417 vtysh_client_run_all(head_client
, line
, 1, vtysh_config_parse_line
,
419 vty
->of
= vty
->of_saved
;
422 /* Command execution over the vty interface. */
423 static int vtysh_execute_func(const char *line
, int pager
)
428 const struct cmd_element
*cmd
;
430 int saved_ret
, saved_node
;
432 /* Split readline string up into the vector. */
433 vline
= cmd_make_strvec(line
);
439 if (strncmp("en", vector_slot(vline
, 0), 2) == 0) {
440 cmd_free_strvec(vline
);
441 vty_out(vty
, "%% Command not allowed: enable\n");
446 saved_ret
= ret
= cmd_execute(vty
, line
, &cmd
, 1);
447 saved_node
= vty
->node
;
450 * If command doesn't succeeded in current node, try to walk up in node
451 * tree. Changing vty->node is enough to try it just out without actual
452 * walkup in the vtysh.
454 while (ret
!= CMD_SUCCESS
&& ret
!= CMD_SUCCESS_DAEMON
455 && ret
!= CMD_WARNING
&& ret
!= CMD_WARNING_CONFIG_FAILED
456 && vty
->node
> CONFIG_NODE
) {
457 vty
->node
= node_parent(vty
->node
);
458 ret
= cmd_execute(vty
, line
, &cmd
, 1);
462 vty
->node
= saved_node
;
465 * If command succeeded in any other node than current (tried > 0) we
466 * have to move into node in the vtysh where it succeeded.
468 if (ret
== CMD_SUCCESS
|| ret
== CMD_SUCCESS_DAEMON
469 || ret
== CMD_WARNING
) {
470 if ((saved_node
== BGP_VPNV4_NODE
471 || saved_node
== BGP_VPNV6_NODE
472 || saved_node
== BGP_IPV4_NODE
473 || saved_node
== BGP_IPV6_NODE
474 || saved_node
== BGP_FLOWSPECV4_NODE
475 || saved_node
== BGP_FLOWSPECV6_NODE
476 || saved_node
== BGP_IPV4M_NODE
477 || saved_node
== BGP_IPV4L_NODE
478 || saved_node
== BGP_IPV6L_NODE
479 || saved_node
== BGP_IPV6M_NODE
480 || saved_node
== BGP_EVPN_NODE
481 || saved_node
== LDP_IPV4_NODE
482 || saved_node
== LDP_IPV6_NODE
)
484 vtysh_execute("exit-address-family");
485 } else if ((saved_node
== BGP_EVPN_VNI_NODE
) && (tried
== 1)) {
486 vtysh_execute("exit-vni");
487 } else if (saved_node
== BGP_VRF_POLICY_NODE
&& (tried
== 1)) {
488 vtysh_execute("exit-vrf-policy");
489 } else if ((saved_node
== BGP_VNC_DEFAULTS_NODE
490 || saved_node
== BGP_VNC_NVE_GROUP_NODE
491 || saved_node
== BGP_VNC_L2_GROUP_NODE
)
493 vtysh_execute("exit-vnc");
494 } else if (saved_node
== VRF_NODE
&& (tried
== 1)) {
495 vtysh_execute("exit-vrf");
496 } else if ((saved_node
== KEYCHAIN_KEY_NODE
497 || saved_node
== LDP_PSEUDOWIRE_NODE
498 || saved_node
== LDP_IPV4_IFACE_NODE
499 || saved_node
== LDP_IPV6_IFACE_NODE
)
501 vtysh_execute("exit");
503 vtysh_execute("end");
504 vtysh_execute("configure terminal");
508 * If command didn't succeed in any node, continue with return value
515 cmd_free_strvec(vline
);
520 case CMD_WARNING_CONFIG_FAILED
:
521 if (vty
->type
== VTY_FILE
)
522 vty_out(vty
, "Warning...\n");
524 case CMD_ERR_AMBIGUOUS
:
525 vty_out(vty
, "%% Ambiguous command: %s\n", line
);
527 case CMD_ERR_NO_MATCH
:
528 vty_out(vty
, "%% Unknown command: %s\n", line
);
530 case CMD_ERR_INCOMPLETE
:
531 vty_out(vty
, "%% Command incomplete: %s\n", line
);
533 case CMD_SUCCESS_DAEMON
: {
535 * FIXME: Don't open pager for exit commands. popen() causes
536 * problems if exited from vtysh at all. This hack shouldn't
537 * cause any problem but is really ugly.
539 if (pager
&& strncmp(line
, "exit", 4))
542 if (!strcmp(cmd
->string
, "configure terminal")) {
543 for (i
= 0; i
< array_size(vtysh_client
); i
++) {
544 cmd_stat
= vtysh_client_execute(
545 &vtysh_client
[i
], line
);
546 if (cmd_stat
== CMD_WARNING
)
552 vline
= cmd_make_strvec(line
);
557 vty_close_pager(vty
);
561 ret
= cmd_execute_command(vline
, vty
, &cmd
, 1);
562 cmd_free_strvec(vline
);
563 if (ret
!= CMD_SUCCESS_DAEMON
)
565 } else if (cmd
->func
) {
566 (*cmd
->func
)(cmd
, vty
, 0, NULL
);
571 cmd_stat
= CMD_SUCCESS
;
572 struct vtysh_client
*vc
;
573 for (i
= 0; i
< array_size(vtysh_client
); i
++) {
574 if (cmd
->daemon
& vtysh_client
[i
].flag
) {
575 if (vtysh_client
[i
].fd
< 0
576 && (cmd
->daemon
== vtysh_client
[i
].flag
)) {
577 for (vc
= &vtysh_client
[i
]; vc
;
582 if (vtysh_client
[i
].fd
< 0
583 && (cmd
->daemon
== vtysh_client
[i
].flag
)) {
584 bool any_inst
= false;
585 for (vc
= &vtysh_client
[i
]; vc
;
591 "%s is not running\n",
592 vtysh_client
[i
].name
);
596 cmd_stat
= vtysh_client_execute(
597 &vtysh_client
[i
], line
);
598 if (cmd_stat
!= CMD_SUCCESS
)
602 if (cmd_stat
!= CMD_SUCCESS
)
606 (*cmd
->func
)(cmd
, vty
, 0, NULL
);
610 vty_close_pager(vty
);
615 int vtysh_execute_no_pager(const char *line
)
617 return vtysh_execute_func(line
, 0);
620 int vtysh_execute(const char *line
)
622 return vtysh_execute_func(line
, 1);
625 static char *trim(char *s
)
636 while (end
>= s
&& isspace((int)*end
))
640 while (*s
&& isspace((int)*s
))
646 int vtysh_mark_file(const char *filename
)
653 const struct cmd_element
*cmd
;
654 int saved_ret
, prev_node
;
656 char *vty_buf_copy
= NULL
;
657 char *vty_buf_trimmed
= NULL
;
659 if (strncmp("-", filename
, 1) == 0)
662 confp
= fopen(filename
, "r");
665 fprintf(stderr
, "%% Can't open config file %s due to '%s'.\n",
666 filename
, safe_strerror(errno
));
667 return (CMD_ERR_NO_FILE
);
671 vty
->wfd
= STDERR_FILENO
;
672 vty
->type
= VTY_TERM
;
673 vty
->node
= CONFIG_NODE
;
675 vtysh_execute_no_pager("enable");
676 vtysh_execute_no_pager("configure terminal");
677 vty_buf_copy
= XCALLOC(MTYPE_VTYSH_CMD
, VTY_BUFSIZ
);
679 while (fgets(vty
->buf
, VTY_BUFSIZ
, confp
)) {
682 strcpy(vty_buf_copy
, vty
->buf
);
683 vty_buf_trimmed
= trim(vty_buf_copy
);
686 case LDP_IPV4_IFACE_NODE
:
687 if (strncmp(vty_buf_copy
, " ", 3)) {
688 vty_out(vty
, " end\n");
689 vty
->node
= LDP_IPV4_NODE
;
692 case LDP_IPV6_IFACE_NODE
:
693 if (strncmp(vty_buf_copy
, " ", 3)) {
694 vty_out(vty
, " end\n");
695 vty
->node
= LDP_IPV6_NODE
;
698 case LDP_PSEUDOWIRE_NODE
:
699 if (strncmp(vty_buf_copy
, " ", 2)) {
700 vty_out(vty
, " end\n");
701 vty
->node
= LDP_L2VPN_NODE
;
708 if (vty_buf_trimmed
[0] == '!' || vty_buf_trimmed
[0] == '#') {
709 vty_out(vty
, "%s", vty
->buf
);
713 /* Split readline string up into the vector. */
714 vline
= cmd_make_strvec(vty
->buf
);
717 vty_out(vty
, "%s", vty
->buf
);
722 * Ignore the "end" lines, we will generate these where
725 if (strlen(vty_buf_trimmed
) == 3
726 && strncmp("end", vty_buf_trimmed
, 3) == 0) {
727 cmd_free_strvec(vline
);
731 prev_node
= vty
->node
;
732 saved_ret
= ret
= cmd_execute_command_strict(vline
, vty
, &cmd
);
735 * If command doesn't succeeded in current node, try to walk up
736 * in node tree. Changing vty->node is enough to try it just
737 * out without actual walkup in the vtysh.
739 while (ret
!= CMD_SUCCESS
&& ret
!= CMD_SUCCESS_DAEMON
740 && ret
!= CMD_WARNING
&& ret
!= CMD_WARNING_CONFIG_FAILED
741 && vty
->node
> CONFIG_NODE
) {
742 vty
->node
= node_parent(vty
->node
);
743 ret
= cmd_execute_command_strict(vline
, vty
, &cmd
);
748 * If command succeeded in any other node than current (tried >
749 * 0) we have to move into node in the vtysh where it
752 if (ret
== CMD_SUCCESS
|| ret
== CMD_SUCCESS_DAEMON
753 || ret
== CMD_WARNING
) {
754 if ((prev_node
== BGP_VPNV4_NODE
755 || prev_node
== BGP_VPNV6_NODE
756 || prev_node
== BGP_IPV4_NODE
757 || prev_node
== BGP_IPV6_NODE
758 || prev_node
== BGP_FLOWSPECV4_NODE
759 || prev_node
== BGP_FLOWSPECV6_NODE
760 || prev_node
== BGP_IPV4L_NODE
761 || prev_node
== BGP_IPV6L_NODE
762 || prev_node
== BGP_IPV4M_NODE
763 || prev_node
== BGP_IPV6M_NODE
764 || prev_node
== BGP_EVPN_NODE
)
766 vty_out(vty
, "exit-address-family\n");
767 } else if ((prev_node
== BGP_EVPN_VNI_NODE
)
769 vty_out(vty
, "exit-vni\n");
770 } else if ((prev_node
== KEYCHAIN_KEY_NODE
)
772 vty_out(vty
, "exit\n");
774 vty_out(vty
, "end\n");
778 * If command didn't succeed in any node, continue with return
779 * value from first try.
783 vty
->node
= prev_node
;
786 cmd_free_strvec(vline
);
789 case CMD_WARNING_CONFIG_FAILED
:
790 if (vty
->type
== VTY_FILE
)
791 fprintf(stderr
, "line %d: Warning...: %s\n",
795 XFREE(MTYPE_VTYSH_CMD
, vty_buf_copy
);
797 case CMD_ERR_AMBIGUOUS
:
798 fprintf(stderr
, "line %d: %% Ambiguous command: %s\n",
802 XFREE(MTYPE_VTYSH_CMD
, vty_buf_copy
);
803 return CMD_ERR_AMBIGUOUS
;
804 case CMD_ERR_NO_MATCH
:
805 fprintf(stderr
, "line %d: %% Unknown command: %s\n",
809 XFREE(MTYPE_VTYSH_CMD
, vty_buf_copy
);
810 return CMD_ERR_NO_MATCH
;
811 case CMD_ERR_INCOMPLETE
:
812 fprintf(stderr
, "line %d: %% Command incomplete: %s\n",
816 XFREE(MTYPE_VTYSH_CMD
, vty_buf_copy
);
817 return CMD_ERR_INCOMPLETE
;
819 vty_out(vty
, "%s", vty
->buf
);
821 case CMD_SUCCESS_DAEMON
: {
824 vty_out(vty
, "%s", vty
->buf
);
825 cmd_stat
= vtysh_client_execute(&vtysh_client
[0],
827 if (cmd_stat
!= CMD_SUCCESS
)
831 (*cmd
->func
)(cmd
, vty
, 0, NULL
);
835 /* This is the end */
836 vty_out(vty
, "\nend\n");
838 XFREE(MTYPE_VTYSH_CMD
, vty_buf_copy
);
846 /* Configration make from file. */
847 int vtysh_config_from_file(struct vty
*vty
, FILE *fp
)
850 const struct cmd_element
*cmd
;
852 /* once we have an error, we remember & return that */
853 int retcode
= CMD_SUCCESS
;
855 while (fgets(vty
->buf
, VTY_BUFSIZ
, fp
)) {
858 ret
= command_config_read_one_line(vty
, &cmd
, 1);
862 case CMD_WARNING_CONFIG_FAILED
:
863 if (vty
->type
== VTY_FILE
)
864 fprintf(stderr
, "line %d: Warning[%d]...: %s\n",
865 lineno
, vty
->node
, vty
->buf
);
869 case CMD_ERR_AMBIGUOUS
:
871 "line %d: %% Ambiguous command[%d]: %s\n",
872 lineno
, vty
->node
, vty
->buf
);
873 retcode
= CMD_ERR_AMBIGUOUS
;
875 case CMD_ERR_NO_MATCH
:
876 fprintf(stderr
, "line %d: %% Unknown command[%d]: %s",
877 lineno
, vty
->node
, vty
->buf
);
878 retcode
= CMD_ERR_NO_MATCH
;
880 case CMD_ERR_INCOMPLETE
:
882 "line %d: %% Command incomplete[%d]: %s\n",
883 lineno
, vty
->node
, vty
->buf
);
884 retcode
= CMD_ERR_INCOMPLETE
;
886 case CMD_SUCCESS_DAEMON
: {
888 int cmd_stat
= CMD_SUCCESS
;
890 for (i
= 0; i
< array_size(vtysh_client
); i
++) {
891 if (cmd
->daemon
& vtysh_client
[i
].flag
) {
892 cmd_stat
= vtysh_client_execute(
893 &vtysh_client
[i
], vty
->buf
);
895 * CMD_WARNING - Can mean that the
896 * command was parsed successfully but
897 * it was already entered in a few
898 * spots. As such if we receive a
899 * CMD_WARNING from a daemon we
900 * shouldn't stop talking to the other
901 * daemons for the particular command.
903 if (cmd_stat
!= CMD_SUCCESS
904 && cmd_stat
!= CMD_WARNING
) {
906 "line %d: Failure to communicate[%d] to %s, line: %s\n",
908 vtysh_client
[i
].name
,
915 if (cmd_stat
!= CMD_SUCCESS
)
919 (*cmd
->func
)(cmd
, vty
, 0, NULL
);
928 * Function processes cli commands terminated with '?' character when entered
929 * through either 'vtysh' or 'vtysh -c' interfaces.
931 static int vtysh_process_questionmark(const char *input
, int input_len
)
935 vector vline
, describe
;
936 struct cmd_token
*token
;
941 vline
= cmd_make_strvec(input
);
943 /* In case of '> ?'. */
945 vline
= vector_init(1);
946 vector_set(vline
, NULL
);
947 } else if (input_len
&& isspace((int)input
[input_len
- 1]))
948 vector_set(vline
, NULL
);
950 describe
= cmd_describe_command(vline
, vty
, &ret
);
952 /* Ambiguous and no match error. */
954 case CMD_ERR_AMBIGUOUS
:
955 cmd_free_strvec(vline
);
956 vector_free(describe
);
957 vty_out(vty
, "%% Ambiguous command.\n");
961 case CMD_ERR_NO_MATCH
:
962 cmd_free_strvec(vline
);
964 vector_free(describe
);
965 vty_out(vty
, "%% There is no matched command.\n");
971 /* Get width of command string. */
973 for (i
= 0; i
< vector_active(describe
); i
++)
974 if ((token
= vector_slot(describe
, i
)) != NULL
) {
975 if (token
->text
[0] == '\0')
978 int len
= strlen(token
->text
);
984 for (i
= 0; i
< vector_active(describe
); i
++)
985 if ((token
= vector_slot(describe
, i
)) != NULL
) {
987 vty_out(vty
, " %-s\n", token
->text
);
989 vty_out(vty
, " %-*s %s\n", width
, token
->text
,
992 if (IS_VARYING_TOKEN(token
->type
)) {
993 const char *ref
= vector_slot(
994 vline
, vector_active(vline
) - 1);
996 vector varcomps
= vector_init(VECTOR_MIN_SIZE
);
997 cmd_variable_complete(token
, ref
, varcomps
);
999 if (vector_active(varcomps
) > 0) {
1001 rl_get_screen_size(&rows
, &cols
);
1003 char *ac
= cmd_variable_comp2str(
1005 vty_out(vty
, "%s\n", ac
);
1006 XFREE(MTYPE_TMP
, ac
);
1009 vector_free(varcomps
);
1013 cmd_free_strvec(vline
);
1014 vector_free(describe
);
1020 * Entry point for user commands terminated with '?' character and typed through
1021 * the usual vtysh's stdin interface. This is the function being registered with
1024 static int vtysh_rl_describe(int a
, int b
)
1030 ret
= vtysh_process_questionmark(rl_line_buffer
, rl_end
);
1037 * Function in charged of processing vtysh instructions terminating with '?'
1038 * character and received through the 'vtysh -c' interface. If user's
1039 * instruction is well-formatted, we will call the same processing routine
1040 * utilized by the traditional vtysh's stdin interface.
1042 int vtysh_execute_command_questionmark(char *input
)
1044 int input_len
, qmark_count
= 0;
1047 if (!(input
&& *input
))
1050 /* Finding out question_mark count and strlen */
1051 for (str
= input
; *str
; ++str
) {
1055 input_len
= str
- input
;
1058 * Verify that user's input terminates in '?' and that patterns such as
1059 * 'cmd ? subcmd ?' are prevented.
1061 if (qmark_count
!= 1 || input
[input_len
- 1] != '?')
1065 * Questionmark-processing function is not expecting to receive '?'
1066 * character in input string.
1068 input
[input_len
- 1] = '\0';
1070 return vtysh_process_questionmark(input
, input_len
- 1);
1073 /* Result of cmd_complete_command() call will be stored here
1074 * and used in new_completion() in order to put the space in
1075 * correct places only. */
1076 int complete_status
;
1078 static char *command_generator(const char *text
, int state
)
1081 static char **matched
= NULL
;
1082 static int index
= 0;
1088 if (vty
->node
== AUTH_NODE
|| vty
->node
== AUTH_ENABLE_NODE
)
1091 vline
= cmd_make_strvec(rl_line_buffer
);
1095 if (rl_end
&& isspace((int)rl_line_buffer
[rl_end
- 1]))
1096 vector_set(vline
, NULL
);
1098 matched
= cmd_complete_command(vline
, vty
, &complete_status
);
1099 cmd_free_strvec(vline
);
1102 if (matched
&& matched
[index
])
1104 * this is free()'d by readline, but we leak 1 count of
1107 return matched
[index
++];
1109 XFREE(MTYPE_TMP
, matched
);
1115 static char **new_completion(char *text
, int start
, int end
)
1119 matches
= rl_completion_matches(text
, command_generator
);
1123 if (complete_status
!= CMD_COMPLETE_FULL_MATCH
)
1124 /* only append a space on full match */
1125 rl_completion_append_character
= '\0';
1131 /* Vty node structures. */
1132 static struct cmd_node bgp_node
= {
1133 BGP_NODE
, "%s(config-router)# ",
1136 static struct cmd_node rip_node
= {
1137 RIP_NODE
, "%s(config-router)# ",
1140 static struct cmd_node isis_node
= {
1141 ISIS_NODE
, "%s(config-router)# ",
1144 static struct cmd_node interface_node
= {
1145 INTERFACE_NODE
, "%s(config-if)# ",
1148 static struct cmd_node pw_node
= {
1149 PW_NODE
, "%s(config-pw)# ",
1152 static struct cmd_node logicalrouter_node
= {
1153 LOGICALROUTER_NODE
, "%s(config-logical-router)# ",
1156 static struct cmd_node vrf_node
= {
1157 VRF_NODE
, "%s(config-vrf)# ",
1160 static struct cmd_node nh_group_node
= {
1162 "%s(config-nh-group)# ",
1165 static struct cmd_node rmap_node
= {RMAP_NODE
, "%s(config-route-map)# "};
1167 static struct cmd_node pbr_map_node
= {PBRMAP_NODE
, "%s(config-pbr-map)# "};
1169 static struct cmd_node zebra_node
= {ZEBRA_NODE
, "%s(config-router)# "};
1171 static struct cmd_node bgp_vpnv4_node
= {BGP_VPNV4_NODE
,
1172 "%s(config-router-af)# "};
1174 static struct cmd_node bgp_vpnv6_node
= {BGP_VPNV6_NODE
,
1175 "%s(config-router-af)# "};
1177 static struct cmd_node bgp_flowspecv4_node
= {BGP_FLOWSPECV4_NODE
,
1178 "%s(config-router-af)# "};
1180 static struct cmd_node bgp_flowspecv6_node
= {BGP_FLOWSPECV6_NODE
,
1181 "%s(config-router-af)# "};
1183 static struct cmd_node bgp_ipv4_node
= {BGP_IPV4_NODE
,
1184 "%s(config-router-af)# "};
1186 static struct cmd_node bgp_ipv4m_node
= {BGP_IPV4M_NODE
,
1187 "%s(config-router-af)# "};
1189 static struct cmd_node bgp_ipv4l_node
= {BGP_IPV4L_NODE
,
1190 "%s(config-router-af)# "};
1192 static struct cmd_node bgp_ipv6_node
= {BGP_IPV6_NODE
,
1193 "%s(config-router-af)# "};
1195 static struct cmd_node bgp_ipv6m_node
= {BGP_IPV6M_NODE
,
1196 "%s(config-router-af)# "};
1198 static struct cmd_node bgp_evpn_node
= {BGP_EVPN_NODE
,
1199 "%s(config-router-af)# "};
1201 static struct cmd_node bgp_evpn_vni_node
= {BGP_EVPN_VNI_NODE
,
1202 "%s(config-router-af-vni)# "};
1204 static struct cmd_node bgp_ipv6l_node
= {BGP_IPV6L_NODE
,
1205 "%s(config-router-af)# "};
1207 static struct cmd_node bgp_vnc_defaults_node
= {
1208 BGP_VNC_DEFAULTS_NODE
, "%s(config-router-vnc-defaults)# "};
1210 static struct cmd_node bgp_vnc_nve_group_node
= {
1211 BGP_VNC_NVE_GROUP_NODE
, "%s(config-router-vnc-nve-group)# "};
1213 static struct cmd_node bgp_vrf_policy_node
= {BGP_VRF_POLICY_NODE
,
1214 "%s(config-router-vrf-policy)# "};
1216 static struct cmd_node bgp_vnc_l2_group_node
= {
1217 BGP_VNC_L2_GROUP_NODE
, "%s(config-router-vnc-l2-group)# "};
1219 static struct cmd_node ospf_node
= {OSPF_NODE
, "%s(config-router)# "};
1221 static struct cmd_node eigrp_node
= {EIGRP_NODE
, "%s(config-router)# "};
1223 static struct cmd_node babel_node
= {BABEL_NODE
, "%s(config-router)# "};
1225 static struct cmd_node ripng_node
= {RIPNG_NODE
, "%s(config-router)# "};
1227 static struct cmd_node ospf6_node
= {OSPF6_NODE
, "%s(config-ospf6)# "};
1229 static struct cmd_node ldp_node
= {LDP_NODE
, "%s(config-ldp)# "};
1231 static struct cmd_node ldp_ipv4_node
= {LDP_IPV4_NODE
, "%s(config-ldp-af)# "};
1233 static struct cmd_node ldp_ipv6_node
= {LDP_IPV6_NODE
, "%s(config-ldp-af)# "};
1235 static struct cmd_node ldp_ipv4_iface_node
= {LDP_IPV4_IFACE_NODE
,
1236 "%s(config-ldp-af-if)# "};
1238 static struct cmd_node ldp_ipv6_iface_node
= {LDP_IPV6_IFACE_NODE
,
1239 "%s(config-ldp-af-if)# "};
1241 static struct cmd_node ldp_l2vpn_node
= {LDP_L2VPN_NODE
, "%s(config-l2vpn)# "};
1243 static struct cmd_node ldp_pseudowire_node
= {LDP_PSEUDOWIRE_NODE
,
1244 "%s(config-l2vpn-pw)# "};
1246 static struct cmd_node keychain_node
= {KEYCHAIN_NODE
, "%s(config-keychain)# "};
1248 static struct cmd_node keychain_key_node
= {KEYCHAIN_KEY_NODE
,
1249 "%s(config-keychain-key)# "};
1251 struct cmd_node link_params_node
= {
1252 LINK_PARAMS_NODE
, "%s(config-link-params)# ",
1255 #if defined(HAVE_RPKI)
1256 static struct cmd_node rpki_node
= {RPKI_NODE
, "%s(config-rpki)# ", 1};
1260 static struct cmd_node bfd_node
= {
1265 static struct cmd_node bfd_peer_node
= {
1267 "%s(config-bfd-peer)# ",
1269 #endif /* HAVE_BFDD */
1271 /* Defined in lib/vty.c */
1272 extern struct cmd_node vty_node
;
1274 /* When '^Z' is received from vty, move down to the enable mode. */
1275 static int vtysh_end(void)
1277 switch (vty
->node
) {
1280 /* Nothing to do. */
1283 vty
->node
= ENABLE_NODE
;
1289 DEFUNSH(VTYSH_REALLYALL
, vtysh_end_all
, vtysh_end_all_cmd
, "end",
1290 "End current mode and change to enable mode\n")
1295 DEFUNSH(VTYSH_BGPD
, router_bgp
, router_bgp_cmd
,
1296 "router bgp [(1-4294967295) [<view|vrf> WORD]]",
1297 ROUTER_STR BGP_STR AS_STR
1298 "BGP view\nBGP VRF\n"
1301 vty
->node
= BGP_NODE
;
1305 DEFUNSH(VTYSH_BGPD
, address_family_vpnv4
, address_family_vpnv4_cmd
,
1306 "address-family vpnv4 [unicast]",
1307 "Enter Address Family command mode\n"
1309 "Address Family modifier\n")
1311 vty
->node
= BGP_VPNV4_NODE
;
1315 DEFUNSH(VTYSH_BGPD
, address_family_vpnv6
, address_family_vpnv6_cmd
,
1316 "address-family vpnv6 [unicast]",
1317 "Enter Address Family command mode\n"
1319 "Address Family modifier\n")
1321 vty
->node
= BGP_VPNV6_NODE
;
1325 DEFUNSH(VTYSH_BGPD
, address_family_ipv4
, address_family_ipv4_cmd
,
1326 "address-family ipv4 [unicast]",
1327 "Enter Address Family command mode\n"
1329 "Address Family Modifier\n")
1331 vty
->node
= BGP_IPV4_NODE
;
1335 DEFUNSH(VTYSH_BGPD
, address_family_flowspecv4
, address_family_flowspecv4_cmd
,
1336 "address-family ipv4 flowspec",
1337 "Enter Address Family command mode\n"
1339 "Address Family Modifier\n")
1341 vty
->node
= BGP_FLOWSPECV4_NODE
;
1345 DEFUNSH(VTYSH_BGPD
, address_family_flowspecv6
, address_family_flowspecv6_cmd
,
1346 "address-family ipv6 flowspec",
1347 "Enter Address Family command mode\n"
1349 "Address Family Modifier\n")
1351 vty
->node
= BGP_FLOWSPECV6_NODE
;
1355 DEFUNSH(VTYSH_BGPD
, address_family_ipv4_multicast
,
1356 address_family_ipv4_multicast_cmd
, "address-family ipv4 multicast",
1357 "Enter Address Family command mode\n"
1359 "Address Family modifier\n")
1361 vty
->node
= BGP_IPV4M_NODE
;
1365 DEFUNSH(VTYSH_BGPD
, address_family_ipv4_vpn
, address_family_ipv4_vpn_cmd
,
1366 "address-family ipv4 vpn",
1367 "Enter Address Family command mode\n"
1369 "Address Family modifier\n")
1371 vty
->node
= BGP_VPNV4_NODE
;
1375 DEFUNSH(VTYSH_BGPD
, address_family_ipv4_labeled_unicast
,
1376 address_family_ipv4_labeled_unicast_cmd
,
1377 "address-family ipv4 labeled-unicast",
1378 "Enter Address Family command mode\n"
1380 "Address Family modifier\n")
1382 vty
->node
= BGP_IPV4L_NODE
;
1386 DEFUNSH(VTYSH_BGPD
, address_family_ipv6
, address_family_ipv6_cmd
,
1387 "address-family ipv6 [unicast]",
1388 "Enter Address Family command mode\n"
1390 "Address Family modifier\n")
1392 vty
->node
= BGP_IPV6_NODE
;
1396 DEFUNSH(VTYSH_BGPD
, address_family_ipv6_multicast
,
1397 address_family_ipv6_multicast_cmd
, "address-family ipv6 multicast",
1398 "Enter Address Family command mode\n"
1400 "Address Family modifier\n")
1402 vty
->node
= BGP_IPV6M_NODE
;
1406 DEFUNSH(VTYSH_BGPD
, address_family_ipv6_vpn
, address_family_ipv6_vpn_cmd
,
1407 "address-family ipv6 vpn",
1408 "Enter Address Family command mode\n"
1410 "Address Family modifier\n")
1412 vty
->node
= BGP_VPNV6_NODE
;
1416 DEFUNSH(VTYSH_BGPD
, address_family_ipv6_labeled_unicast
,
1417 address_family_ipv6_labeled_unicast_cmd
,
1418 "address-family ipv6 labeled-unicast",
1419 "Enter Address Family command mode\n"
1421 "Address Family modifier\n")
1423 vty
->node
= BGP_IPV6L_NODE
;
1427 #if defined(HAVE_RPKI)
1432 "Enable rpki and enter rpki configuration mode\n")
1434 vty
->node
= RPKI_NODE
;
1442 "Exit current mode and down to previous mode\n")
1444 vty
->node
= CONFIG_NODE
;
1452 "Exit current mode and down to previous mode\n")
1454 return rpki_exit(self
, vty
, argc
, argv
);
1458 DEFUNSH(VTYSH_BGPD
, address_family_evpn
, address_family_evpn_cmd
,
1459 "address-family <l2vpn evpn>",
1460 "Enter Address Family command mode\n"
1462 "Address Family modifier\n")
1464 vty
->node
= BGP_EVPN_NODE
;
1468 #if defined(HAVE_CUMULUS)
1469 DEFUNSH_HIDDEN(VTYSH_BGPD
, address_family_evpn2
, address_family_evpn2_cmd
,
1470 "address-family evpn",
1471 "Enter Address Family command mode\n"
1472 "EVPN Address family\n")
1474 vty
->node
= BGP_EVPN_NODE
;
1479 DEFUNSH(VTYSH_BGPD
, bgp_evpn_vni
, bgp_evpn_vni_cmd
, "vni (1-16777215)",
1480 "VXLAN Network Identifier\n"
1483 vty
->node
= BGP_EVPN_VNI_NODE
;
1487 #if defined(ENABLE_BGP_VNC)
1488 DEFUNSH(VTYSH_BGPD
, vnc_defaults
, vnc_defaults_cmd
, "vnc defaults",
1489 "VNC/RFP related configuration\n"
1490 "Configure default NVE group\n")
1492 vty
->node
= BGP_VNC_DEFAULTS_NODE
;
1496 DEFUNSH(VTYSH_BGPD
, vnc_nve_group
, vnc_nve_group_cmd
, "vnc nve-group NAME",
1497 "VNC/RFP related configuration\n"
1498 "Configure a NVE group\n"
1501 vty
->node
= BGP_VNC_NVE_GROUP_NODE
;
1505 DEFUNSH(VTYSH_BGPD
, vnc_vrf_policy
, vnc_vrf_policy_cmd
, "vrf-policy NAME",
1506 "Configure a VRF policy group\n"
1509 vty
->node
= BGP_VRF_POLICY_NODE
;
1513 DEFUNSH(VTYSH_BGPD
, vnc_l2_group
, vnc_l2_group_cmd
, "vnc l2-group NAME",
1514 "VNC/RFP related configuration\n"
1515 "Configure a L2 group\n"
1518 vty
->node
= BGP_VNC_L2_GROUP_NODE
;
1523 DEFUNSH(VTYSH_RIPD
, key_chain
, key_chain_cmd
, "key chain WORD",
1524 "Authentication key management\n"
1525 "Key-chain management\n"
1528 vty
->node
= KEYCHAIN_NODE
;
1532 DEFUNSH(VTYSH_RIPD
, key
, key_cmd
, "key (0-2147483647)",
1534 "Key identifier number\n")
1536 vty
->node
= KEYCHAIN_KEY_NODE
;
1540 DEFUNSH(VTYSH_RIPD
, router_rip
, router_rip_cmd
, "router rip",
1543 vty
->node
= RIP_NODE
;
1547 DEFUNSH(VTYSH_RIPNGD
, router_ripng
, router_ripng_cmd
, "router ripng",
1548 ROUTER_STR
"RIPng\n")
1550 vty
->node
= RIPNG_NODE
;
1554 DEFUNSH(VTYSH_OSPFD
, router_ospf
, router_ospf_cmd
,
1555 "router ospf [(1-65535)] [vrf NAME]",
1556 "Enable a routing process\n"
1557 "Start OSPF configuration\n"
1561 vty
->node
= OSPF_NODE
;
1565 DEFUNSH(VTYSH_EIGRPD
, router_eigrp
, router_eigrp_cmd
, "router eigrp (1-65535)",
1566 "Enable a routing process\n"
1567 "Start EIGRP configuration\n"
1568 "AS number to use\n")
1570 vty
->node
= EIGRP_NODE
;
1574 DEFUNSH(VTYSH_BABELD
, router_babel
, router_babel_cmd
, "router babel",
1575 "Enable a routing process\n"
1576 "Make Babel instance command\n")
1578 vty
->node
= BABEL_NODE
;
1582 DEFUNSH(VTYSH_OSPF6D
, router_ospf6
, router_ospf6_cmd
, "router ospf6",
1583 ROUTER_STR OSPF6_STR
)
1585 vty
->node
= OSPF6_NODE
;
1589 #if defined(HAVE_LDPD)
1590 DEFUNSH(VTYSH_LDPD
, ldp_mpls_ldp
, ldp_mpls_ldp_cmd
, "mpls ldp",
1591 "Global MPLS configuration subcommands\n"
1592 "Label Distribution Protocol\n")
1594 vty
->node
= LDP_NODE
;
1598 DEFUNSH(VTYSH_LDPD
, ldp_address_family_ipv4
, ldp_address_family_ipv4_cmd
,
1599 "address-family ipv4",
1600 "Configure Address Family and its parameters\n"
1603 vty
->node
= LDP_IPV4_NODE
;
1607 DEFUNSH(VTYSH_LDPD
, ldp_address_family_ipv6
, ldp_address_family_ipv6_cmd
,
1608 "address-family ipv6",
1609 "Configure Address Family and its parameters\n"
1612 vty
->node
= LDP_IPV6_NODE
;
1616 DEFUNSH(VTYSH_LDPD
, ldp_exit_address_family
, ldp_exit_address_family_cmd
,
1617 "exit-address-family", "Exit from Address Family configuration mode\n")
1619 if (vty
->node
== LDP_IPV4_NODE
|| vty
->node
== LDP_IPV6_NODE
)
1620 vty
->node
= LDP_NODE
;
1624 DEFUNSH(VTYSH_LDPD
, ldp_interface_ifname
, ldp_interface_ifname_cmd
,
1626 "Enable LDP on an interface and enter interface submode\n"
1627 "Interface's name\n")
1629 switch (vty
->node
) {
1631 vty
->node
= LDP_IPV4_IFACE_NODE
;
1634 vty
->node
= LDP_IPV6_IFACE_NODE
;
1643 DEFUNSH(VTYSH_LDPD
, ldp_l2vpn_word_type_vpls
, ldp_l2vpn_word_type_vpls_cmd
,
1644 "l2vpn WORD type vpls",
1645 "Configure l2vpn commands\n"
1648 "Virtual Private LAN Service\n")
1650 vty
->node
= LDP_L2VPN_NODE
;
1654 DEFUNSH(VTYSH_LDPD
, ldp_member_pseudowire_ifname
,
1655 ldp_member_pseudowire_ifname_cmd
, "member pseudowire IFNAME",
1656 "L2VPN member configuration\n"
1657 "Pseudowire interface\n"
1658 "Interface's name\n")
1660 vty
->node
= LDP_PSEUDOWIRE_NODE
;
1665 DEFUNSH(VTYSH_ISISD
, router_isis
, router_isis_cmd
, "router isis WORD",
1668 "ISO Routing area tag\n")
1670 vty
->node
= ISIS_NODE
;
1674 DEFUNSH(VTYSH_RMAP
, vtysh_route_map
, vtysh_route_map_cmd
,
1675 "route-map WORD <deny|permit> (1-65535)",
1676 "Create route-map or enter route-map command mode\n"
1678 "Route map denies set operations\n"
1679 "Route map permits set operations\n"
1680 "Sequence to insert to/delete from existing route-map entry\n")
1682 vty
->node
= RMAP_NODE
;
1686 DEFUNSH(VTYSH_PBRD
, vtysh_pbr_map
, vtysh_pbr_map_cmd
,
1687 "pbr-map NAME seq (1-700)",
1688 "Create pbr-map or enter pbr-map command mode\n"
1689 "The name of the PBR MAP\n"
1690 "Sequence to insert to/delete from existing pbr-map entry\n"
1691 "Sequence number\n")
1693 vty
->node
= PBRMAP_NODE
;
1698 DEFUNSH(VTYSH_BFDD
, bfd_enter
, bfd_enter_cmd
, "bfd", "Configure BFD peers\n")
1700 vty
->node
= BFD_NODE
;
1704 DEFUNSH(VTYSH_BFDD
, bfd_peer_enter
, bfd_peer_enter_cmd
,
1705 "peer <A.B.C.D|X:X::X:X> [{multihop|local-address <A.B.C.D|X:X::X:X>|interface IFNAME|vrf NAME}]",
1707 "IPv4 peer address\n"
1708 "IPv6 peer address\n"
1709 "Configure multihop\n"
1710 "Configure local address\n"
1711 "IPv4 local address\n"
1712 "IPv6 local address\n"
1714 "Configure interface name to use\n"
1716 "Configure VRF name\n")
1718 vty
->node
= BFD_PEER_NODE
;
1721 #endif /* HAVE_BFDD */
1723 DEFSH(VTYSH_PBRD
, vtysh_no_pbr_map_cmd
, "no pbr-map WORD [seq (1-700)]",
1726 "The name of the PBR MAP\n"
1727 "Sequence to delete from existing pbr-map entry\n"
1728 "Sequence number\n")
1730 DEFUNSH(VTYSH_ALL
, vtysh_line_vty
, vtysh_line_vty_cmd
, "line vty",
1731 "Configure a terminal line\n"
1732 "Virtual terminal\n")
1734 vty
->node
= VTY_NODE
;
1738 DEFUNSH(VTYSH_REALLYALL
, vtysh_enable
, vtysh_enable_cmd
, "enable",
1739 "Turn on privileged mode command\n")
1741 vty
->node
= ENABLE_NODE
;
1745 DEFUNSH(VTYSH_REALLYALL
, vtysh_disable
, vtysh_disable_cmd
, "disable",
1746 "Turn off privileged mode command\n")
1748 if (vty
->node
== ENABLE_NODE
)
1749 vty
->node
= VIEW_NODE
;
1753 DEFUNSH(VTYSH_REALLYALL
, vtysh_config_terminal
, vtysh_config_terminal_cmd
,
1754 "configure terminal",
1755 "Configuration from vty interface\n"
1756 "Configuration terminal\n")
1758 vty
->node
= CONFIG_NODE
;
1762 static int vtysh_exit(struct vty
*vty
)
1764 switch (vty
->node
) {
1770 vty
->node
= ENABLE_NODE
;
1772 case INTERFACE_NODE
:
1774 case LOGICALROUTER_NODE
:
1786 case LDP_L2VPN_NODE
:
1793 vtysh_execute("end");
1794 vtysh_execute("configure terminal");
1795 vty
->node
= CONFIG_NODE
;
1797 case BGP_VPNV4_NODE
:
1798 case BGP_VPNV6_NODE
:
1800 case BGP_IPV4M_NODE
:
1801 case BGP_IPV4L_NODE
:
1803 case BGP_IPV6M_NODE
:
1804 case BGP_IPV6L_NODE
:
1805 case BGP_FLOWSPECV4_NODE
:
1806 case BGP_FLOWSPECV6_NODE
:
1807 case BGP_VRF_POLICY_NODE
:
1809 case BGP_VNC_DEFAULTS_NODE
:
1810 case BGP_VNC_NVE_GROUP_NODE
:
1811 case BGP_VNC_L2_GROUP_NODE
:
1812 vty
->node
= BGP_NODE
;
1814 case BGP_EVPN_VNI_NODE
:
1815 vty
->node
= BGP_EVPN_NODE
;
1819 vty
->node
= LDP_NODE
;
1821 case LDP_IPV4_IFACE_NODE
:
1822 vty
->node
= LDP_IPV4_NODE
;
1824 case LDP_IPV6_IFACE_NODE
:
1825 vty
->node
= LDP_IPV6_NODE
;
1827 case LDP_PSEUDOWIRE_NODE
:
1828 vty
->node
= LDP_L2VPN_NODE
;
1830 case KEYCHAIN_KEY_NODE
:
1831 vty
->node
= KEYCHAIN_NODE
;
1833 case LINK_PARAMS_NODE
:
1834 vty
->node
= INTERFACE_NODE
;
1837 vty
->node
= BFD_NODE
;
1845 DEFUNSH(VTYSH_REALLYALL
, vtysh_exit_all
, vtysh_exit_all_cmd
, "exit",
1846 "Exit current mode and down to previous mode\n")
1848 return vtysh_exit(vty
);
1851 DEFUNSH(VTYSH_ALL
, vtysh_quit_all
, vtysh_quit_all_cmd
, "quit",
1852 "Exit current mode and down to previous mode\n")
1854 return vtysh_exit_all(self
, vty
, argc
, argv
);
1857 DEFUNSH(VTYSH_BGPD
, exit_address_family
, exit_address_family_cmd
,
1858 "exit-address-family", "Exit from Address Family configuration mode\n")
1860 if (vty
->node
== BGP_IPV4_NODE
|| vty
->node
== BGP_IPV4M_NODE
1861 || vty
->node
== BGP_IPV4L_NODE
|| vty
->node
== BGP_VPNV4_NODE
1862 || vty
->node
== BGP_VPNV6_NODE
|| vty
->node
== BGP_IPV6_NODE
1863 || vty
->node
== BGP_IPV6L_NODE
|| vty
->node
== BGP_IPV6M_NODE
1864 || vty
->node
== BGP_EVPN_NODE
1865 || vty
->node
== BGP_FLOWSPECV4_NODE
1866 || vty
->node
== BGP_FLOWSPECV6_NODE
)
1867 vty
->node
= BGP_NODE
;
1871 DEFUNSH(VTYSH_BGPD
, exit_vni
, exit_vni_cmd
, "exit-vni", "Exit from VNI mode\n")
1873 if (vty
->node
== BGP_EVPN_VNI_NODE
)
1874 vty
->node
= BGP_EVPN_NODE
;
1878 DEFUNSH(VTYSH_BGPD
, exit_vnc_config
, exit_vnc_config_cmd
, "exit-vnc",
1879 "Exit from VNC configuration mode\n")
1881 if (vty
->node
== BGP_VNC_DEFAULTS_NODE
1882 || vty
->node
== BGP_VNC_NVE_GROUP_NODE
1883 || vty
->node
== BGP_VNC_L2_GROUP_NODE
)
1884 vty
->node
= BGP_NODE
;
1888 DEFUNSH(VTYSH_PIMD
|VTYSH_ZEBRA
, exit_vrf_config
, exit_vrf_config_cmd
, "exit-vrf",
1889 "Exit from VRF configuration mode\n")
1891 if (vty
->node
== VRF_NODE
)
1892 vty
->node
= CONFIG_NODE
;
1896 DEFUNSH(VTYSH_BGPD
, exit_vrf_policy
, exit_vrf_policy_cmd
, "exit-vrf-policy",
1897 "Exit from VRF policy configuration mode\n")
1899 if (vty
->node
== BGP_VRF_POLICY_NODE
)
1900 vty
->node
= BGP_NODE
;
1904 DEFUNSH(VTYSH_RIPD
, vtysh_exit_ripd
, vtysh_exit_ripd_cmd
, "exit",
1905 "Exit current mode and down to previous mode\n")
1907 return vtysh_exit(vty
);
1910 DEFUNSH(VTYSH_RIPD
, vtysh_quit_ripd
, vtysh_quit_ripd_cmd
, "quit",
1911 "Exit current mode and down to previous mode\n")
1913 return vtysh_exit_ripd(self
, vty
, argc
, argv
);
1916 DEFUNSH(VTYSH_RIPNGD
, vtysh_exit_ripngd
, vtysh_exit_ripngd_cmd
, "exit",
1917 "Exit current mode and down to previous mode\n")
1919 return vtysh_exit(vty
);
1922 DEFUNSH(VTYSH_RIPNGD
, vtysh_quit_ripngd
, vtysh_quit_ripngd_cmd
, "quit",
1923 "Exit current mode and down to previous mode\n")
1925 return vtysh_exit_ripngd(self
, vty
, argc
, argv
);
1928 DEFUNSH(VTYSH_RMAP
, vtysh_exit_rmap
, vtysh_exit_rmap_cmd
, "exit",
1929 "Exit current mode and down to previous mode\n")
1931 return vtysh_exit(vty
);
1934 DEFUNSH(VTYSH_RMAP
, vtysh_quit_rmap
, vtysh_quit_rmap_cmd
, "quit",
1935 "Exit current mode and down to previous mode\n")
1937 return vtysh_exit_rmap(self
, vty
, argc
, argv
);
1940 DEFUNSH(VTYSH_PBRD
, vtysh_exit_pbr_map
, vtysh_exit_pbr_map_cmd
, "exit",
1941 "Exit current mode and down to previous mode\n")
1943 return vtysh_exit(vty
);
1946 DEFUNSH(VTYSH_PBRD
, vtysh_quit_pbr_map
, vtysh_quit_pbr_map_cmd
, "quit",
1947 "Exit current mode and down to previous mode\n")
1949 return vtysh_exit_rmap(self
, vty
, argc
, argv
);
1952 DEFUNSH(VTYSH_BGPD
, vtysh_exit_bgpd
, vtysh_exit_bgpd_cmd
, "exit",
1953 "Exit current mode and down to previous mode\n")
1955 return vtysh_exit(vty
);
1958 DEFUNSH(VTYSH_BGPD
, vtysh_quit_bgpd
, vtysh_quit_bgpd_cmd
, "quit",
1959 "Exit current mode and down to previous mode\n")
1961 return vtysh_exit_bgpd(self
, vty
, argc
, argv
);
1964 DEFUNSH(VTYSH_OSPFD
, vtysh_exit_ospfd
, vtysh_exit_ospfd_cmd
, "exit",
1965 "Exit current mode and down to previous mode\n")
1967 return vtysh_exit(vty
);
1970 DEFUNSH(VTYSH_OSPFD
, vtysh_quit_ospfd
, vtysh_quit_ospfd_cmd
, "quit",
1971 "Exit current mode and down to previous mode\n")
1973 return vtysh_exit_ospfd(self
, vty
, argc
, argv
);
1976 DEFUNSH(VTYSH_EIGRPD
, vtysh_exit_eigrpd
, vtysh_exit_eigrpd_cmd
, "exit",
1977 "Exit current mode and down to previous mode\n")
1979 return vtysh_exit(vty
);
1982 DEFUNSH(VTYSH_EIGRPD
, vtysh_quit_eigrpd
, vtysh_quit_eigrpd_cmd
, "quit",
1983 "Exit current mode and down to previous mode\n")
1985 return vtysh_exit(vty
);
1988 DEFUNSH(VTYSH_EIGRPD
, vtysh_exit_babeld
, vtysh_exit_babeld_cmd
, "exit",
1989 "Exit current mode and down to previous mode\n")
1991 return vtysh_exit(vty
);
1994 DEFUNSH(VTYSH_BABELD
, vtysh_quit_babeld
, vtysh_quit_babeld_cmd
, "quit",
1995 "Exit current mode and down to previous mode\n")
1997 return vtysh_exit(vty
);
2000 DEFUNSH(VTYSH_OSPF6D
, vtysh_exit_ospf6d
, vtysh_exit_ospf6d_cmd
, "exit",
2001 "Exit current mode and down to previous mode\n")
2003 return vtysh_exit(vty
);
2006 DEFUNSH(VTYSH_OSPF6D
, vtysh_quit_ospf6d
, vtysh_quit_ospf6d_cmd
, "quit",
2007 "Exit current mode and down to previous mode\n")
2009 return vtysh_exit_ospf6d(self
, vty
, argc
, argv
);
2012 #if defined(HAVE_LDPD)
2013 DEFUNSH(VTYSH_LDPD
, vtysh_exit_ldpd
, vtysh_exit_ldpd_cmd
, "exit",
2014 "Exit current mode and down to previous mode\n")
2016 return vtysh_exit(vty
);
2019 ALIAS(vtysh_exit_ldpd
, vtysh_quit_ldpd_cmd
, "quit",
2020 "Exit current mode and down to previous mode\n")
2023 DEFUNSH(VTYSH_ISISD
, vtysh_exit_isisd
, vtysh_exit_isisd_cmd
, "exit",
2024 "Exit current mode and down to previous mode\n")
2026 return vtysh_exit(vty
);
2029 DEFUNSH(VTYSH_ISISD
, vtysh_quit_isisd
, vtysh_quit_isisd_cmd
, "quit",
2030 "Exit current mode and down to previous mode\n")
2032 return vtysh_exit_isisd(self
, vty
, argc
, argv
);
2036 DEFUNSH(VTYSH_BFDD
, vtysh_exit_bfdd
, vtysh_exit_bfdd_cmd
, "exit",
2037 "Exit current mode and down to previous mode\n")
2039 return vtysh_exit(vty
);
2042 ALIAS(vtysh_exit_bfdd
, vtysh_quit_bfdd_cmd
, "quit",
2043 "Exit current mode and down to previous mode\n")
2046 DEFUNSH(VTYSH_ALL
, vtysh_exit_line_vty
, vtysh_exit_line_vty_cmd
, "exit",
2047 "Exit current mode and down to previous mode\n")
2049 return vtysh_exit(vty
);
2052 DEFUNSH(VTYSH_ALL
, vtysh_quit_line_vty
, vtysh_quit_line_vty_cmd
, "quit",
2053 "Exit current mode and down to previous mode\n")
2055 return vtysh_exit_line_vty(self
, vty
, argc
, argv
);
2058 DEFUNSH(VTYSH_INTERFACE
, vtysh_interface
, vtysh_interface_cmd
,
2059 "interface IFNAME [vrf NAME]",
2060 "Select an interface to configure\n"
2061 "Interface's name\n" VRF_CMD_HELP_STR
)
2063 vty
->node
= INTERFACE_NODE
;
2067 DEFUNSH(VTYSH_ZEBRA
, vtysh_pseudowire
, vtysh_pseudowire_cmd
,
2068 "pseudowire IFNAME",
2069 "Static pseudowire configuration\n"
2070 "Pseudowire name\n")
2072 vty
->node
= PW_NODE
;
2076 DEFUNSH(VTYSH_ZEBRA
, vtysh_logicalrouter
, vtysh_logicalrouter_cmd
,
2077 "logical-router (1-65535) ns NAME",
2078 "Enable a logical-router\n"
2079 "Specify the logical-router indentifier\n"
2081 "The file name in " NS_RUN_DIR
", or a full pathname\n")
2083 vty
->node
= LOGICALROUTER_NODE
;
2087 DEFSH(VTYSH_ZEBRA
, vtysh_no_logicalrouter_cmd
,
2088 "no logical-router (1-65535) ns NAME", NO_STR
2089 "Enable a Logical-Router\n"
2090 "Specify the Logical-Router identifier\n"
2092 "The file name in " NS_RUN_DIR
", or a full pathname\n")
2094 DEFUNSH(VTYSH_PBRD
, vtysh_nexthop_group
, vtysh_nexthop_group_cmd
,
2095 "nexthop-group NAME",
2096 "Nexthop Group configuration\n"
2097 "Name of the Nexthop Group\n")
2099 vty
->node
= NH_GROUP_NODE
;
2103 DEFSH(VTYSH_PBRD
, vtysh_no_nexthop_group_cmd
, "no nexthop-group NAME",
2105 "Nexthop Group Configuration\n"
2106 "Name of the Nexthop Group\n")
2108 DEFUNSH(VTYSH_VRF
, vtysh_vrf
, vtysh_vrf_cmd
, "vrf NAME",
2109 "Select a VRF to configure\n"
2112 vty
->node
= VRF_NODE
;
2116 DEFSH(VTYSH_ZEBRA
, vtysh_vrf_netns_cmd
,
2118 "Attach VRF to a Namespace\n"
2119 "The file name in " NS_RUN_DIR
", or a full pathname\n")
2121 DEFSH(VTYSH_ZEBRA
, vtysh_no_vrf_netns_cmd
,
2124 "Detach VRF from a Namespace\n"
2125 "The file name in " NS_RUN_DIR
", or a full pathname\n")
2127 DEFUNSH(VTYSH_NS
, vtysh_exit_logicalrouter
,
2128 vtysh_exit_logicalrouter_cmd
, "exit",
2129 "Exit current mode and down to previous mode\n")
2131 return vtysh_exit(vty
);
2134 DEFUNSH(VTYSH_NS
, vtysh_quit_logicalrouter
,
2135 vtysh_quit_logicalrouter_cmd
, "quit",
2136 "Exit current mode and down to previous mode\n")
2138 return vtysh_exit_logicalrouter(self
, vty
, argc
, argv
);
2141 DEFUNSH(VTYSH_VRF
, vtysh_exit_vrf
, vtysh_exit_vrf_cmd
, "exit",
2142 "Exit current mode and down to previous mode\n")
2144 return vtysh_exit(vty
);
2147 DEFUNSH(VTYSH_VRF
, vtysh_quit_vrf
, vtysh_quit_vrf_cmd
, "quit",
2148 "Exit current mode and down to previous mode\n")
2150 return vtysh_exit_vrf(self
, vty
, argc
, argv
);
2153 DEFUNSH(VTYSH_PBRD
, vtysh_exit_nexthop_group
, vtysh_exit_nexthop_group_cmd
,
2154 "exit", "Exit current mode and down to previous mode\n")
2156 return vtysh_exit(vty
);
2159 DEFUNSH(VTYSH_VRF
, vtysh_quit_nexthop_group
, vtysh_quit_nexthop_group_cmd
,
2160 "quit", "Exit current mode and down to previous mode\n")
2162 return vtysh_exit_nexthop_group(self
, vty
, argc
, argv
);
2165 DEFUNSH(VTYSH_INTERFACE
, vtysh_exit_interface
, vtysh_exit_interface_cmd
, "exit",
2166 "Exit current mode and down to previous mode\n")
2168 return vtysh_exit(vty
);
2171 DEFUNSH(VTYSH_INTERFACE
, vtysh_quit_interface
, vtysh_quit_interface_cmd
, "quit",
2172 "Exit current mode and down to previous mode\n")
2174 return vtysh_exit_interface(self
, vty
, argc
, argv
);
2177 DEFUN (vtysh_show_poll
,
2178 vtysh_show_poll_cmd
,
2181 "Thread information\n"
2182 "Thread Poll Information\n")
2185 int ret
= CMD_SUCCESS
;
2188 snprintf(line
, sizeof(line
), "do show thread poll\n");
2189 for (i
= 0; i
< array_size(vtysh_client
); i
++)
2190 if (vtysh_client
[i
].fd
>= 0) {
2191 vty_out(vty
, "Thread statistics for %s:\n",
2192 vtysh_client
[i
].name
);
2193 ret
= vtysh_client_execute(&vtysh_client
[i
], line
);
2199 DEFUN (vtysh_show_thread
,
2200 vtysh_show_thread_cmd
,
2201 "show thread cpu [FILTER]",
2203 "Thread information\n"
2204 "Thread CPU usage\n"
2205 "Display filter (rwtexb)\n")
2209 int ret
= CMD_SUCCESS
;
2212 const char *filter
=
2213 argv_find(argv
, argc
, "FILTER", &idx
) ? argv
[idx
]->arg
: "";
2215 snprintf(line
, sizeof(line
), "do show thread cpu %s\n", filter
);
2216 for (i
= 0; i
< array_size(vtysh_client
); i
++)
2217 if (vtysh_client
[i
].fd
>= 0) {
2218 vty_out(vty
, "Thread statistics for %s:\n",
2219 vtysh_client
[i
].name
);
2220 ret
= vtysh_client_execute(&vtysh_client
[i
], line
);
2226 DEFUN (vtysh_show_work_queues
,
2227 vtysh_show_work_queues_cmd
,
2230 "Work Queue information\n")
2233 int ret
= CMD_SUCCESS
;
2234 char line
[] = "do show work-queues\n";
2236 for (i
= 0; i
< array_size(vtysh_client
); i
++)
2237 if (vtysh_client
[i
].fd
>= 0) {
2238 vty_out(vty
, "Work queue statistics for %s:\n",
2239 vtysh_client
[i
].name
);
2240 ret
= vtysh_client_execute(&vtysh_client
[i
], line
);
2247 DEFUN (vtysh_show_work_queues_daemon
,
2248 vtysh_show_work_queues_daemon_cmd
,
2249 "show work-queues <zebra|ripd|ripngd|ospfd|ospf6d|bgpd|isisd|pbrd>",
2251 "Work Queue information\n"
2252 "For the zebra daemon\n"
2253 "For the rip daemon\n"
2254 "For the ripng daemon\n"
2255 "For the ospf daemon\n"
2256 "For the ospfv6 daemon\n"
2257 "For the bgp daemon\n"
2258 "For the isis daemon\n"
2259 "For the pbr daemon\n")
2261 int idx_protocol
= 2;
2263 int ret
= CMD_SUCCESS
;
2265 for (i
= 0; i
< array_size(vtysh_client
); i
++) {
2266 if (strmatch(vtysh_client
[i
].name
, argv
[idx_protocol
]->text
))
2270 ret
= vtysh_client_execute(&vtysh_client
[i
], "show work-queues\n");
2275 DEFUNSH(VTYSH_ZEBRA
, vtysh_link_params
, vtysh_link_params_cmd
, "link-params",
2278 vty
->node
= LINK_PARAMS_NODE
;
2282 DEFUNSH(VTYSH_ZEBRA
, exit_link_params
, exit_link_params_cmd
, "exit-link-params",
2283 "Exit from Link Params configuration node\n")
2285 if (vty
->node
== LINK_PARAMS_NODE
)
2286 vty
->node
= INTERFACE_NODE
;
2290 static int show_per_daemon(const char *line
, const char *headline
)
2293 int ret
= CMD_SUCCESS
;
2295 for (i
= 0; i
< array_size(vtysh_client
); i
++)
2296 if (vtysh_client
[i
].fd
>= 0) {
2297 vty_out(vty
, headline
, vtysh_client
[i
].name
);
2298 ret
= vtysh_client_execute(&vtysh_client
[i
], line
);
2305 DEFUNSH_HIDDEN (0x00,
2307 vtysh_debug_all_cmd
,
2311 "Toggle all debugs on or off\n")
2316 DEFUN (vtysh_show_debugging
,
2317 vtysh_show_debugging_cmd
,
2322 return show_per_daemon("do show debugging\n", "");
2325 DEFUN (vtysh_show_debugging_hashtable
,
2326 vtysh_show_debugging_hashtable_cmd
,
2327 "show debugging hashtable [statistics]",
2330 "Statistics about hash tables\n"
2331 "Statistics about hash tables\n")
2335 "Load factor (LF) - average number of elements across all buckets\n");
2337 "Full load factor (FLF) - average number of elements across full buckets\n\n");
2339 "Standard deviation (SD) is calculated for both the LF and FLF\n");
2341 "and indicates the typical deviation of bucket chain length\n");
2342 vty_out(vty
, "from the value in the corresponding load factor.\n\n");
2344 return show_per_daemon("do show debugging hashtable\n",
2345 "Hashtable statistics for %s:\n");
2348 DEFUN (vtysh_show_error_code
,
2349 vtysh_show_error_code_cmd
,
2350 "show error <(1-4294967296)|all> [json]",
2352 "Information on errors\n"
2353 "Error code to get info about\n"
2354 "Information on all errors\n"
2357 char *fcmd
= argv_concat(argv
, argc
, 0);
2361 snprintf(cmd
, sizeof(cmd
), "do %s", fcmd
);
2363 /* FIXME: Needs to determine which daemon to send to via code ranges */
2364 rv
= show_per_daemon(cmd
, "");
2366 XFREE(MTYPE_TMP
, fcmd
);
2371 DEFUN (vtysh_show_memory
,
2372 vtysh_show_memory_cmd
,
2375 "Memory statistics\n")
2377 return show_per_daemon("do show memory\n", "Memory statistics for %s:\n");
2380 DEFUN (vtysh_show_modules
,
2381 vtysh_show_modules_cmd
,
2386 return show_per_daemon("do show modules\n",
2387 "Module information for %s:\n");
2390 /* Logging commands. */
2391 DEFUN (vtysh_show_logging
,
2392 vtysh_show_logging_cmd
,
2395 "Show current logging configuration\n")
2397 return show_per_daemon("do show logging\n",
2398 "Logging configuration for %s:\n");
2401 DEFUNSH(VTYSH_ALL
, vtysh_log_stdout
, vtysh_log_stdout_cmd
, "log stdout",
2403 "Set stdout logging level\n")
2408 DEFUNSH(VTYSH_ALL
, vtysh_log_stdout_level
, vtysh_log_stdout_level_cmd
,
2409 "log stdout <emergencies|alerts|critical|errors|warnings|notifications|informational|debugging>",
2411 "Set stdout logging level\n" LOG_LEVEL_DESC
)
2416 DEFUNSH(VTYSH_ALL
, no_vtysh_log_stdout
, no_vtysh_log_stdout_cmd
,
2417 "no log stdout [LEVEL]", NO_STR
2419 "Cancel logging to stdout\n"
2425 DEFUNSH(VTYSH_ALL
, vtysh_log_file
, vtysh_log_file_cmd
, "log file FILENAME",
2428 "Logging filename\n")
2433 DEFUNSH(VTYSH_ALL
, vtysh_log_file_level
, vtysh_log_file_level_cmd
,
2434 "log file FILENAME <emergencies|alerts|critical|errors|warnings|notifications|informational|debugging>",
2437 "Logging filename\n" LOG_LEVEL_DESC
)
2442 DEFUNSH(VTYSH_ALL
, no_vtysh_log_file
, no_vtysh_log_file_cmd
,
2443 "no log file [FILENAME [LEVEL]]", NO_STR
2445 "Cancel logging to file\n"
2446 "Logging file name\n"
2452 DEFUNSH(VTYSH_ALL
, vtysh_log_monitor
, vtysh_log_monitor_cmd
,
2453 "log monitor [<emergencies|alerts|critical|errors|warnings|notifications|informational|debugging>]",
2455 "Set terminal line (monitor) logging level\n" LOG_LEVEL_DESC
)
2460 DEFUNSH(VTYSH_ALL
, no_vtysh_log_monitor
, no_vtysh_log_monitor_cmd
,
2461 "no log monitor [LEVEL]", NO_STR
2463 "Disable terminal line (monitor) logging\n"
2469 DEFUNSH(VTYSH_ALL
, vtysh_log_syslog
, vtysh_log_syslog_cmd
,
2470 "log syslog [<emergencies|alerts|critical|errors|warnings|notifications|informational|debugging>]",
2472 "Set syslog logging level\n" LOG_LEVEL_DESC
)
2477 DEFUNSH(VTYSH_ALL
, no_vtysh_log_syslog
, no_vtysh_log_syslog_cmd
,
2478 "no log syslog [<emergencies|alerts|critical|errors|warnings|notifications|informational|debugging>]",
2481 "Cancel logging to syslog\n"
2487 DEFUNSH(VTYSH_ALL
, vtysh_log_facility
, vtysh_log_facility_cmd
,
2488 "log facility <kern|user|mail|daemon|auth|syslog|lpr|news|uucp|cron|local0|local1|local2|local3|local4|local5|local6|local7>",
2490 "Facility parameter for syslog messages\n" LOG_FACILITY_DESC
)
2495 DEFUNSH(VTYSH_ALL
, no_vtysh_log_facility
, no_vtysh_log_facility_cmd
,
2496 "no log facility [FACILITY]", NO_STR
2498 "Reset syslog facility to default (daemon)\n"
2499 "Syslog facility\n")
2504 DEFUNSH(VTYSH_ALL
, vtysh_log_record_priority
, vtysh_log_record_priority_cmd
,
2505 "log record-priority",
2507 "Log the priority of the message within the message\n")
2512 DEFUNSH(VTYSH_ALL
, no_vtysh_log_record_priority
,
2513 no_vtysh_log_record_priority_cmd
, "no log record-priority", NO_STR
2515 "Do not log the priority of the message within the message\n")
2520 DEFUNSH(VTYSH_ALL
, vtysh_log_timestamp_precision
,
2521 vtysh_log_timestamp_precision_cmd
, "log timestamp precision (0-6)",
2523 "Timestamp configuration\n"
2524 "Set the timestamp precision\n"
2525 "Number of subsecond digits\n")
2530 DEFUNSH(VTYSH_ALL
, no_vtysh_log_timestamp_precision
,
2531 no_vtysh_log_timestamp_precision_cmd
, "no log timestamp precision",
2534 "Timestamp configuration\n"
2535 "Reset the timestamp precision to the default value of 0\n")
2540 DEFUNSH(VTYSH_ALL
, vtysh_service_password_encrypt
,
2541 vtysh_service_password_encrypt_cmd
, "service password-encryption",
2542 "Set up miscellaneous service\n"
2543 "Enable encrypted passwords\n")
2548 DEFUNSH(VTYSH_ALL
, no_vtysh_service_password_encrypt
,
2549 no_vtysh_service_password_encrypt_cmd
, "no service password-encryption",
2551 "Set up miscellaneous service\n"
2552 "Enable encrypted passwords\n")
2557 DEFUNSH(VTYSH_ALL
, vtysh_config_password
, vtysh_password_cmd
,
2558 "password [(8-8)] LINE",
2559 "Modify the terminal connection password\n"
2560 "Specifies a HIDDEN password will follow\n"
2561 "The password string\n")
2566 DEFUNSH(VTYSH_ALL
, no_vtysh_config_password
, no_vtysh_password_cmd
,
2567 "no password", NO_STR
2568 "Modify the terminal connection password\n")
2570 vty_out(vty
, NO_PASSWD_CMD_WARNING
);
2575 DEFUNSH(VTYSH_ALL
, vtysh_config_enable_password
, vtysh_enable_password_cmd
,
2576 "enable password [(8-8)] LINE",
2577 "Modify enable password parameters\n"
2578 "Assign the privileged level password\n"
2579 "Specifies a HIDDEN password will follow\n"
2580 "The 'enable' password string\n")
2585 DEFUNSH(VTYSH_ALL
, no_vtysh_config_enable_password
,
2586 no_vtysh_enable_password_cmd
, "no enable password", NO_STR
2587 "Modify enable password parameters\n"
2588 "Assign the privileged level password\n")
2590 vty_out(vty
, NO_PASSWD_CMD_WARNING
);
2595 DEFUN (vtysh_write_terminal
,
2596 vtysh_write_terminal_cmd
,
2597 "write terminal [<zebra|ripd|ripngd|ospfd|ospf6d|ldpd|bgpd|isisd|pimd>]",
2598 "Write running configuration to memory, network, or terminal\n"
2599 "Write to terminal\n"
2600 "For the zebra daemon\n"
2601 "For the rip daemon\n"
2602 "For the ripng daemon\n"
2603 "For the ospf daemon\n"
2604 "For the ospfv6 daemon\n"
2605 "For the ldpd daemon\n"
2606 "For the bgp daemon\n"
2607 "For the isis daemon\n"
2608 "For the pim daemon\n")
2611 char line
[] = "do write terminal\n";
2613 vty_out(vty
, "Building configuration...\n");
2614 vty_out(vty
, "\nCurrent configuration:\n");
2615 vty_out(vty
, "!\n");
2617 for (i
= 0; i
< array_size(vtysh_client
); i
++)
2619 || (strmatch(vtysh_client
[i
].name
, argv
[2]->text
)))
2620 vtysh_client_config(&vtysh_client
[i
], line
);
2622 /* Integrate vtysh specific configuration. */
2623 vty_open_pager(vty
);
2624 vtysh_config_write();
2625 vtysh_config_dump();
2626 vty_close_pager(vty
);
2627 vty_out(vty
, "end\n");
2632 DEFUN (vtysh_show_running_config
,
2633 vtysh_show_running_config_cmd
,
2634 "show running-config [<zebra|ripd|ripngd|ospfd|ospf6d|ldpd|bgpd|isisd|pimd>]",
2636 "Current operating configuration\n"
2637 "For the zebra daemon\n"
2638 "For the rip daemon\n"
2639 "For the ripng daemon\n"
2640 "For the ospf daemon\n"
2641 "For the ospfv6 daemon\n"
2642 "For the ldp daemon\n"
2643 "For the bgp daemon\n"
2644 "For the isis daemon\n"
2645 "For the pim daemon\n")
2647 return vtysh_write_terminal(self
, vty
, argc
, argv
);
2650 DEFUN (vtysh_integrated_config
,
2651 vtysh_integrated_config_cmd
,
2652 "service integrated-vtysh-config",
2653 "Set up miscellaneous service\n"
2654 "Write configuration into integrated file\n")
2656 vtysh_write_integrated
= WRITE_INTEGRATED_YES
;
2660 DEFUN (no_vtysh_integrated_config
,
2661 no_vtysh_integrated_config_cmd
,
2662 "no service integrated-vtysh-config",
2664 "Set up miscellaneous service\n"
2665 "Write configuration into integrated file\n")
2667 vtysh_write_integrated
= WRITE_INTEGRATED_NO
;
2671 static void backup_config_file(const char *fbackup
)
2673 char *integrate_sav
= NULL
;
2675 integrate_sav
= malloc(strlen(fbackup
) + strlen(CONF_BACKUP_EXT
) + 1);
2676 strcpy(integrate_sav
, fbackup
);
2677 strcat(integrate_sav
, CONF_BACKUP_EXT
);
2679 /* Move current configuration file to backup config file. */
2680 if (unlink(integrate_sav
) != 0) {
2681 vty_out(vty
, "Warning: %s unlink failed\n", integrate_sav
);
2683 if (rename(fbackup
, integrate_sav
) != 0) {
2684 vty_out(vty
, "Error renaming %s to %s\n", fbackup
,
2687 free(integrate_sav
);
2690 int vtysh_write_config_integrated(void)
2693 char line
[] = "do write terminal\n";
2697 struct passwd
*pwentry
;
2700 struct group
*grentry
;
2707 vty_out(vty
, "Building Configuration...\n");
2709 backup_config_file(frr_config
);
2710 fp
= fopen(frr_config
, "w");
2713 "%% Error: failed to open configuration file %s: %s\n",
2714 frr_config
, safe_strerror(errno
));
2715 return CMD_WARNING_CONFIG_FAILED
;
2719 for (i
= 0; i
< array_size(vtysh_client
); i
++)
2720 vtysh_client_config(&vtysh_client
[i
], line
);
2722 vtysh_config_write();
2723 vty
->of_saved
= vty
->of
;
2725 vtysh_config_dump();
2726 vty
->of
= vty
->of_saved
;
2728 if (fchmod(fd
, CONFIGFILE_MASK
) != 0) {
2729 printf("%% Warning: can't chmod configuration file %s: %s\n",
2730 frr_config
, safe_strerror(errno
));
2735 pwentry
= getpwnam(FRR_USER
);
2737 uid
= pwentry
->pw_uid
;
2739 printf("%% Warning: could not look up user \"%s\"\n", FRR_USER
);
2744 grentry
= getgrnam(FRR_GROUP
);
2746 gid
= grentry
->gr_gid
;
2748 printf("%% Warning: could not look up group \"%s\"\n",
2754 if (!fstat(fd
, &st
)) {
2755 if (st
.st_uid
== uid
)
2757 if (st
.st_gid
== gid
)
2759 if ((uid
!= (uid_t
)-1 || gid
!= (gid_t
)-1)
2760 && fchown(fd
, uid
, gid
)) {
2761 printf("%% Warning: can't chown configuration file %s: %s\n",
2762 frr_config
, safe_strerror(errno
));
2766 printf("%% Warning: stat() failed on %s: %s\n", frr_config
,
2767 safe_strerror(errno
));
2773 printf("Integrated configuration saved to %s\n", frr_config
);
2781 static bool want_config_integrated(void)
2785 switch (vtysh_write_integrated
) {
2786 case WRITE_INTEGRATED_UNSPECIFIED
:
2787 if (stat(frr_config
, &s
) && errno
== ENOENT
)
2790 case WRITE_INTEGRATED_NO
:
2792 case WRITE_INTEGRATED_YES
:
2798 DEFUN (vtysh_write_memory
,
2799 vtysh_write_memory_cmd
,
2800 "write [<memory|file>]",
2801 "Write running configuration to memory, network, or terminal\n"
2802 "Write configuration to the file (same as write file)\n"
2803 "Write configuration to the file (same as write memory)\n")
2805 int ret
= CMD_SUCCESS
;
2806 char line
[] = "do write memory\n";
2809 vty_out(vty
, "Note: this version of vtysh never writes vtysh.conf\n");
2811 /* If integrated frr.conf explicitely set. */
2812 if (want_config_integrated()) {
2813 ret
= CMD_WARNING_CONFIG_FAILED
;
2815 /* first attempt to use watchfrr if it's available */
2816 bool used_watchfrr
= false;
2818 for (i
= 0; i
< array_size(vtysh_client
); i
++)
2819 if (vtysh_client
[i
].flag
== VTYSH_WATCHFRR
)
2821 if (i
< array_size(vtysh_client
) && vtysh_client
[i
].fd
!= -1) {
2822 used_watchfrr
= true;
2823 ret
= vtysh_client_execute(&vtysh_client
[i
],
2824 "do write integrated");
2828 * If we didn't use watchfrr, fallback to writing the config
2831 if (!used_watchfrr
) {
2832 printf("\nWarning: attempting direct configuration write without "
2833 "watchfrr.\nFile permissions and ownership may be "
2834 "incorrect, or write may fail.\n\n");
2835 ret
= vtysh_write_config_integrated();
2840 vty_out(vty
, "Building Configuration...\n");
2842 for (i
= 0; i
< array_size(vtysh_client
); i
++)
2843 ret
= vtysh_client_execute(&vtysh_client
[i
], line
);
2848 DEFUN (vtysh_copy_running_config
,
2849 vtysh_copy_running_config_cmd
,
2850 "copy running-config startup-config",
2851 "Copy from one file to another\n"
2852 "Copy from current system configuration\n"
2853 "Copy to startup configuration\n")
2855 return vtysh_write_memory(self
, vty
, argc
, argv
);
2858 DEFUN (vtysh_terminal_length
,
2859 vtysh_terminal_length_cmd
,
2860 "terminal length (0-512)",
2861 "Set terminal line parameters\n"
2862 "Set number of lines on a screen\n"
2863 "Number of lines on screen (0 for no pausing)\n")
2867 char *endptr
= NULL
;
2868 char default_pager
[10];
2870 lines
= strtol(argv
[idx_number
]->arg
, &endptr
, 10);
2871 if (lines
< 0 || lines
> 512 || *endptr
!= '\0') {
2872 vty_out(vty
, "length is malformed\n");
2876 if (vtysh_pager_name
) {
2877 free(vtysh_pager_name
);
2878 vtysh_pager_name
= NULL
;
2882 snprintf(default_pager
, 10, "more -%i", lines
);
2883 vtysh_pager_name
= strdup(default_pager
);
2889 DEFUN (vtysh_terminal_no_length
,
2890 vtysh_terminal_no_length_cmd
,
2891 "terminal no length",
2892 "Set terminal line parameters\n"
2894 "Set number of lines on a screen\n")
2896 if (vtysh_pager_name
) {
2897 free(vtysh_pager_name
);
2898 vtysh_pager_name
= NULL
;
2905 DEFUN (vtysh_show_daemons
,
2906 vtysh_show_daemons_cmd
,
2909 "Show list of running daemons\n")
2913 for (i
= 0; i
< array_size(vtysh_client
); i
++)
2914 if (vtysh_client
[i
].fd
>= 0)
2915 vty_out(vty
, " %s", vtysh_client
[i
].name
);
2921 /* Execute command in child process. */
2922 static void execute_command(const char *command
, int argc
, const char *arg1
,
2932 /* Failure of fork(). */
2933 fprintf(stderr
, "Can't fork: %s\n", safe_strerror(errno
));
2935 } else if (pid
== 0) {
2936 /* This is child process. */
2939 execlp(command
, command
, (const char *)NULL
);
2942 execlp(command
, command
, arg1
, (const char *)NULL
);
2945 execlp(command
, command
, arg1
, arg2
,
2946 (const char *)NULL
);
2950 /* When execlp suceed, this part is not executed. */
2951 fprintf(stderr
, "Can't execute %s: %s\n", command
,
2952 safe_strerror(errno
));
2955 /* This is parent. */
2957 wait4(pid
, &status
, 0, NULL
);
2965 "Send echo messages\n"
2966 "Ping destination address or hostname\n")
2970 argv_find(argv
, argc
, "WORD", &idx
);
2971 execute_command("ping", 1, argv
[idx
]->arg
, NULL
);
2975 ALIAS(vtysh_ping
, vtysh_ping_ip_cmd
, "ping ip WORD",
2976 "Send echo messages\n"
2978 "Ping destination address or hostname\n")
2980 DEFUN (vtysh_traceroute
,
2981 vtysh_traceroute_cmd
,
2983 "Trace route to destination\n"
2984 "Trace route to destination address or hostname\n")
2988 argv_find(argv
, argc
, "WORD", &idx
);
2989 execute_command("traceroute", 1, argv
[idx
]->arg
, NULL
);
2993 ALIAS(vtysh_traceroute
, vtysh_traceroute_ip_cmd
, "traceroute ip WORD",
2994 "Trace route to destination\n"
2996 "Trace route to destination address or hostname\n")
2998 DEFUN (vtysh_mtrace
,
3000 "mtrace WORD [WORD]",
3001 "Multicast trace route to multicast source\n"
3002 "Multicast trace route to multicast source address\n"
3003 "Multicast trace route for multicast group address\n")
3006 execute_command("mtracebis", 1, argv
[1]->arg
, NULL
);
3008 execute_command("mtracebis", 2, argv
[1]->arg
, argv
[2]->arg
);
3015 "Send echo messages\n"
3017 "Ping destination address or hostname\n")
3019 execute_command("ping6", 1, argv
[2]->arg
, NULL
);
3023 DEFUN (vtysh_traceroute6
,
3024 vtysh_traceroute6_cmd
,
3025 "traceroute ipv6 WORD",
3026 "Trace route to destination\n"
3028 "Trace route to destination address or hostname\n")
3030 execute_command("traceroute6", 1, argv
[2]->arg
, NULL
);
3034 #if defined(HAVE_SHELL_ACCESS)
3035 DEFUN (vtysh_telnet
,
3038 "Open a telnet connection\n"
3039 "IP address or hostname of a remote system\n")
3041 execute_command("telnet", 1, argv
[1]->arg
, NULL
);
3045 DEFUN (vtysh_telnet_port
,
3046 vtysh_telnet_port_cmd
,
3048 "Open a telnet connection\n"
3049 "IP address or hostname of a remote system\n"
3050 "TCP Port number\n")
3052 execute_command("telnet", 2, argv
[1]->arg
, argv
[2]->arg
);
3059 "Open an ssh connection\n"
3062 execute_command("ssh", 1, argv
[1]->arg
, NULL
);
3066 DEFUN (vtysh_start_shell
,
3067 vtysh_start_shell_cmd
,
3069 "Start UNIX shell\n")
3071 execute_command("sh", 0, NULL
, NULL
);
3075 DEFUN (vtysh_start_bash
,
3076 vtysh_start_bash_cmd
,
3078 "Start UNIX shell\n"
3081 execute_command("bash", 0, NULL
, NULL
);
3085 DEFUN (vtysh_start_zsh
,
3086 vtysh_start_zsh_cmd
,
3088 "Start UNIX shell\n"
3091 execute_command("zsh", 0, NULL
, NULL
);
3098 "list [permutations]",
3099 "Print command list\n"
3100 "Print all possible command permutations\n")
3102 return cmd_list_cmds(vty
, argc
== 2);
3105 DEFUN (vtysh_output_file
,
3106 vtysh_output_file_cmd
,
3108 "Direct vtysh output to file\n"
3109 "Direct vtysh output to file\n"
3110 "Path to dump output to\n")
3112 const char *path
= argv
[argc
- 1]->arg
;
3113 vty
->of
= fopen(path
, "a");
3115 vty_out(vty
, "Failed to open file '%s': %s\n", path
,
3116 safe_strerror(errno
));
3122 DEFUN (no_vtysh_output_file
,
3123 no_vtysh_output_file_cmd
,
3124 "no output file [FILE]",
3126 "Direct vtysh output to file\n"
3127 "Direct vtysh output to file\n"
3128 "Path to dump output to\n")
3130 if (vty
->of
!= stdout
) {
3140 "Find CLI command containing text\n"
3141 "Text to search for\n")
3143 char *text
= argv_concat(argv
, argc
, 1);
3144 const struct cmd_node
*node
;
3145 const struct cmd_element
*cli
;
3148 for (unsigned int i
= 0; i
< vector_active(cmdvec
); i
++) {
3149 node
= vector_slot(cmdvec
, i
);
3152 clis
= node
->cmd_vector
;
3153 for (unsigned int j
= 0; j
< vector_active(clis
); j
++) {
3154 cli
= vector_slot(clis
, j
);
3155 if (strcasestr(cli
->string
, text
))
3156 vty_out(vty
, " (%s) %s\n",
3157 node_names
[node
->node
], cli
->string
);
3161 XFREE(MTYPE_TMP
, text
);
3166 DEFUN_HIDDEN(show_cli_graph_vtysh
,
3167 show_cli_graph_vtysh_cmd
,
3171 "Dump current command space as DOT graph\n")
3173 struct cmd_node
*cn
= vector_slot(cmdvec
, vty
->node
);
3174 char *dot
= cmd_graph_dump_dot(cn
->cmdgraph
);
3176 vty_out(vty
, "%s\n", dot
);
3177 XFREE(MTYPE_TMP
, dot
);
3181 static void vtysh_install_default(enum node_type node
)
3183 install_element(node
, &config_list_cmd
);
3184 install_element(node
, &find_cmd
);
3185 install_element(node
, &show_cli_graph_vtysh_cmd
);
3186 install_element(node
, &vtysh_output_file_cmd
);
3187 install_element(node
, &no_vtysh_output_file_cmd
);
3190 /* Making connection to protocol daemon. */
3191 static int vtysh_connect(struct vtysh_client
*vclient
)
3195 struct sockaddr_un addr
;
3199 if (!vclient
->path
[0])
3200 snprintf(vclient
->path
, sizeof(vclient
->path
), "%s/%s.vty",
3201 vtydir
, vclient
->name
);
3202 path
= vclient
->path
;
3204 /* Stat socket to see if we have permission to access it. */
3205 ret
= stat(path
, &s_stat
);
3206 if (ret
< 0 && errno
!= ENOENT
) {
3207 fprintf(stderr
, "vtysh_connect(%s): stat = %s\n", path
,
3208 safe_strerror(errno
));
3213 if (!S_ISSOCK(s_stat
.st_mode
)) {
3214 fprintf(stderr
, "vtysh_connect(%s): Not a socket\n",
3220 sock
= socket(AF_UNIX
, SOCK_STREAM
, 0);
3223 fprintf(stderr
, "vtysh_connect(%s): socket = %s\n", path
,
3224 safe_strerror(errno
));
3229 memset(&addr
, 0, sizeof(struct sockaddr_un
));
3230 addr
.sun_family
= AF_UNIX
;
3231 strlcpy(addr
.sun_path
, path
, sizeof(addr
.sun_path
));
3232 #ifdef HAVE_STRUCT_SOCKADDR_UN_SUN_LEN
3233 len
= addr
.sun_len
= SUN_LEN(&addr
);
3235 len
= sizeof(addr
.sun_family
) + strlen(addr
.sun_path
);
3236 #endif /* HAVE_STRUCT_SOCKADDR_UN_SUN_LEN */
3238 ret
= connect(sock
, (struct sockaddr
*)&addr
, len
);
3241 fprintf(stderr
, "vtysh_connect(%s): connect = %s\n", path
,
3242 safe_strerror(errno
));
3252 static int vtysh_reconnect(struct vtysh_client
*vclient
)
3256 fprintf(stderr
, "Warning: connecting to %s...", vclient
->name
);
3257 ret
= vtysh_connect(vclient
);
3259 fprintf(stderr
, "failed!\n");
3262 fprintf(stderr
, "success!\n");
3263 if (vtysh_client_execute(vclient
, "enable") < 0)
3265 return vtysh_execute_no_pager("end");
3268 /* Return true if str ends with suffix, else return false */
3269 static int ends_with(const char *str
, const char *suffix
)
3271 if (!str
|| !suffix
)
3273 size_t lenstr
= strlen(str
);
3274 size_t lensuffix
= strlen(suffix
);
3275 if (lensuffix
> lenstr
)
3277 return strncmp(str
+ lenstr
- lensuffix
, suffix
, lensuffix
) == 0;
3280 static void vtysh_client_sorted_insert(struct vtysh_client
*head_client
,
3281 struct vtysh_client
*client
)
3283 struct vtysh_client
*prev_node
, *current_node
;
3285 prev_node
= head_client
;
3286 current_node
= head_client
->next
;
3287 while (current_node
) {
3288 if (strcmp(current_node
->path
, client
->path
) > 0)
3291 prev_node
= current_node
;
3292 current_node
= current_node
->next
;
3294 client
->next
= current_node
;
3295 prev_node
->next
= client
;
3298 #define MAXIMUM_INSTANCES 10
3300 static void vtysh_update_all_insances(struct vtysh_client
*head_client
)
3302 struct vtysh_client
*client
;
3304 struct dirent
*file
;
3307 if (head_client
->flag
!= VTYSH_OSPFD
)
3310 /* ls vty_sock_dir and look for all files ending in .vty */
3311 dir
= opendir(vtydir
);
3313 while ((file
= readdir(dir
)) != NULL
) {
3314 if (begins_with(file
->d_name
, "ospfd-")
3315 && ends_with(file
->d_name
, ".vty")) {
3316 if (n
== MAXIMUM_INSTANCES
) {
3318 "Parsing %s, client limit(%d) reached!\n",
3322 client
= (struct vtysh_client
*)malloc(
3323 sizeof(struct vtysh_client
));
3325 client
->name
= "ospfd";
3326 client
->flag
= VTYSH_OSPFD
;
3327 snprintf(client
->path
, sizeof(client
->path
),
3328 "%s/%s", vtydir
, file
->d_name
);
3329 client
->next
= NULL
;
3330 vtysh_client_sorted_insert(head_client
, client
);
3338 static int vtysh_connect_all_instances(struct vtysh_client
*head_client
)
3340 struct vtysh_client
*client
;
3343 vtysh_update_all_insances(head_client
);
3345 client
= head_client
->next
;
3347 if (vtysh_connect(client
) == 0)
3349 client
= client
->next
;
3355 int vtysh_connect_all(const char *daemon_name
)
3361 for (i
= 0; i
< array_size(vtysh_client
); i
++) {
3363 || !strcmp(daemon_name
, vtysh_client
[i
].name
)) {
3365 if (vtysh_connect(&vtysh_client
[i
]) == 0)
3368 rc
+= vtysh_connect_all_instances(&vtysh_client
[i
]);
3372 fprintf(stderr
, "Error: no daemons match name %s!\n",
3377 /* To disable readline's filename completion. */
3378 static char *vtysh_completion_entry_function(const char *ignore
,
3384 void vtysh_readline_init(void)
3386 /* readline related settings. */
3388 rl_bind_key('?', (rl_command_func_t
*)vtysh_rl_describe
);
3389 rl_completion_entry_function
= vtysh_completion_entry_function
;
3390 rl_attempted_completion_function
=
3391 (rl_completion_func_t
*)new_completion
;
3394 char *vtysh_prompt(void)
3396 static char buf
[100];
3398 snprintf(buf
, sizeof buf
, cmd_prompt(vty
->node
), cmd_hostname_get());
3402 static void vtysh_ac_line(void *arg
, const char *line
)
3406 for (i
= 0; i
< vector_active(comps
); i
++)
3407 if (!strcmp(line
, (char *)vector_slot(comps
, i
)))
3409 vector_set(comps
, XSTRDUP(MTYPE_COMPLETION
, line
));
3412 static void vtysh_autocomplete(vector comps
, struct cmd_token
*token
)
3417 snprintf(accmd
, sizeof(accmd
), "autocomplete %d %s %s", token
->type
,
3418 token
->text
, token
->varname
? token
->varname
: "-");
3420 vty
->of_saved
= vty
->of
;
3422 for (i
= 0; i
< array_size(vtysh_client
); i
++)
3423 vtysh_client_run_all(&vtysh_client
[i
], accmd
, 1, vtysh_ac_line
,
3425 vty
->of
= vty
->of_saved
;
3428 static const struct cmd_variable_handler vtysh_var_handler
[] = {
3432 .completions
= vtysh_autocomplete
},
3433 {.completions
= NULL
}};
3437 if (vty
->of
!= stdout
)
3441 void vtysh_init_vty(void)
3443 /* Make vty structure. */
3445 vty
->type
= VTY_SHELL
;
3446 vty
->node
= VIEW_NODE
;
3448 /* set default output */
3451 /* Initialize commands. */
3453 cmd_variable_handler_register(vtysh_var_handler
);
3455 /* Install nodes. */
3456 install_node(&bgp_node
, NULL
);
3457 install_node(&rip_node
, NULL
);
3458 install_node(&interface_node
, NULL
);
3459 install_node(&pw_node
, NULL
);
3460 install_node(&link_params_node
, NULL
);
3461 install_node(&logicalrouter_node
, NULL
);
3462 install_node(&vrf_node
, NULL
);
3463 install_node(&nh_group_node
, NULL
);
3464 install_node(&rmap_node
, NULL
);
3465 install_node(&pbr_map_node
, NULL
);
3466 install_node(&zebra_node
, NULL
);
3467 install_node(&bgp_vpnv4_node
, NULL
);
3468 install_node(&bgp_vpnv6_node
, NULL
);
3469 install_node(&bgp_flowspecv4_node
, NULL
);
3470 install_node(&bgp_flowspecv6_node
, NULL
);
3471 install_node(&bgp_ipv4_node
, NULL
);
3472 install_node(&bgp_ipv4m_node
, NULL
);
3473 install_node(&bgp_ipv4l_node
, NULL
);
3474 install_node(&bgp_ipv6_node
, NULL
);
3475 install_node(&bgp_ipv6m_node
, NULL
);
3476 install_node(&bgp_ipv6l_node
, NULL
);
3477 install_node(&bgp_vrf_policy_node
, NULL
);
3478 install_node(&bgp_evpn_node
, NULL
);
3479 install_node(&bgp_evpn_vni_node
, NULL
);
3480 install_node(&bgp_vnc_defaults_node
, NULL
);
3481 install_node(&bgp_vnc_nve_group_node
, NULL
);
3482 install_node(&bgp_vnc_l2_group_node
, NULL
);
3483 install_node(&ospf_node
, NULL
);
3484 install_node(&eigrp_node
, NULL
);
3485 install_node(&babel_node
, NULL
);
3486 install_node(&ripng_node
, NULL
);
3487 install_node(&ospf6_node
, NULL
);
3488 install_node(&ldp_node
, NULL
);
3489 install_node(&ldp_ipv4_node
, NULL
);
3490 install_node(&ldp_ipv6_node
, NULL
);
3491 install_node(&ldp_ipv4_iface_node
, NULL
);
3492 install_node(&ldp_ipv6_iface_node
, NULL
);
3493 install_node(&ldp_l2vpn_node
, NULL
);
3494 install_node(&ldp_pseudowire_node
, NULL
);
3495 install_node(&keychain_node
, NULL
);
3496 install_node(&keychain_key_node
, NULL
);
3497 install_node(&isis_node
, NULL
);
3498 install_node(&vty_node
, NULL
);
3499 #if defined(HAVE_RPKI)
3500 install_node(&rpki_node
, NULL
);
3503 install_node(&bfd_node
, NULL
);
3504 install_node(&bfd_peer_node
, NULL
);
3505 #endif /* HAVE_BFDD */
3507 struct cmd_node
*node
;
3508 for (unsigned int i
= 0; i
< vector_active(cmdvec
); i
++) {
3509 node
= vector_slot(cmdvec
, i
);
3510 if (!node
|| node
->node
== VIEW_NODE
)
3512 vtysh_install_default(node
->node
);
3515 install_element(VIEW_NODE
, &vtysh_enable_cmd
);
3516 install_element(ENABLE_NODE
, &vtysh_config_terminal_cmd
);
3517 install_element(ENABLE_NODE
, &vtysh_disable_cmd
);
3519 /* "exit" command. */
3520 install_element(VIEW_NODE
, &vtysh_exit_all_cmd
);
3521 install_element(CONFIG_NODE
, &vtysh_exit_all_cmd
);
3522 install_element(VIEW_NODE
, &vtysh_quit_all_cmd
);
3523 install_element(CONFIG_NODE
, &vtysh_quit_all_cmd
);
3524 install_element(RIP_NODE
, &vtysh_exit_ripd_cmd
);
3525 install_element(RIP_NODE
, &vtysh_quit_ripd_cmd
);
3526 install_element(RIPNG_NODE
, &vtysh_exit_ripngd_cmd
);
3527 install_element(RIPNG_NODE
, &vtysh_quit_ripngd_cmd
);
3528 install_element(OSPF_NODE
, &vtysh_exit_ospfd_cmd
);
3529 install_element(OSPF_NODE
, &vtysh_quit_ospfd_cmd
);
3530 install_element(EIGRP_NODE
, &vtysh_exit_eigrpd_cmd
);
3531 install_element(EIGRP_NODE
, &vtysh_quit_eigrpd_cmd
);
3532 install_element(BABEL_NODE
, &vtysh_exit_babeld_cmd
);
3533 install_element(BABEL_NODE
, &vtysh_quit_babeld_cmd
);
3534 install_element(OSPF6_NODE
, &vtysh_exit_ospf6d_cmd
);
3535 install_element(OSPF6_NODE
, &vtysh_quit_ospf6d_cmd
);
3536 #if defined(HAVE_LDPD)
3537 install_element(LDP_NODE
, &vtysh_exit_ldpd_cmd
);
3538 install_element(LDP_NODE
, &vtysh_quit_ldpd_cmd
);
3539 install_element(LDP_IPV4_NODE
, &vtysh_exit_ldpd_cmd
);
3540 install_element(LDP_IPV4_NODE
, &vtysh_quit_ldpd_cmd
);
3541 install_element(LDP_IPV4_NODE
, &ldp_exit_address_family_cmd
);
3542 install_element(LDP_IPV6_NODE
, &vtysh_exit_ldpd_cmd
);
3543 install_element(LDP_IPV6_NODE
, &vtysh_quit_ldpd_cmd
);
3544 install_element(LDP_IPV6_NODE
, &ldp_exit_address_family_cmd
);
3545 install_element(LDP_IPV4_IFACE_NODE
, &vtysh_exit_ldpd_cmd
);
3546 install_element(LDP_IPV4_IFACE_NODE
, &vtysh_quit_ldpd_cmd
);
3547 install_element(LDP_IPV6_IFACE_NODE
, &vtysh_exit_ldpd_cmd
);
3548 install_element(LDP_IPV6_IFACE_NODE
, &vtysh_quit_ldpd_cmd
);
3549 install_element(LDP_L2VPN_NODE
, &vtysh_exit_ldpd_cmd
);
3550 install_element(LDP_L2VPN_NODE
, &vtysh_quit_ldpd_cmd
);
3551 install_element(LDP_PSEUDOWIRE_NODE
, &vtysh_exit_ldpd_cmd
);
3552 install_element(LDP_PSEUDOWIRE_NODE
, &vtysh_quit_ldpd_cmd
);
3554 install_element(BGP_NODE
, &vtysh_exit_bgpd_cmd
);
3555 install_element(BGP_NODE
, &vtysh_quit_bgpd_cmd
);
3556 install_element(BGP_VPNV4_NODE
, &vtysh_exit_bgpd_cmd
);
3557 install_element(BGP_VPNV4_NODE
, &vtysh_quit_bgpd_cmd
);
3558 install_element(BGP_VPNV6_NODE
, &vtysh_exit_bgpd_cmd
);
3559 install_element(BGP_VPNV6_NODE
, &vtysh_quit_bgpd_cmd
);
3560 install_element(BGP_FLOWSPECV4_NODE
, &vtysh_exit_bgpd_cmd
);
3561 install_element(BGP_FLOWSPECV4_NODE
, &vtysh_quit_bgpd_cmd
);
3562 install_element(BGP_FLOWSPECV6_NODE
, &vtysh_exit_bgpd_cmd
);
3563 install_element(BGP_FLOWSPECV6_NODE
, &vtysh_quit_bgpd_cmd
);
3564 install_element(BGP_IPV4_NODE
, &vtysh_exit_bgpd_cmd
);
3565 install_element(BGP_IPV4_NODE
, &vtysh_quit_bgpd_cmd
);
3566 install_element(BGP_IPV4M_NODE
, &vtysh_exit_bgpd_cmd
);
3567 install_element(BGP_IPV4M_NODE
, &vtysh_quit_bgpd_cmd
);
3568 install_element(BGP_IPV4L_NODE
, &vtysh_exit_bgpd_cmd
);
3569 install_element(BGP_IPV4L_NODE
, &vtysh_quit_bgpd_cmd
);
3570 install_element(BGP_IPV6_NODE
, &vtysh_exit_bgpd_cmd
);
3571 install_element(BGP_IPV6_NODE
, &vtysh_quit_bgpd_cmd
);
3572 install_element(BGP_IPV6M_NODE
, &vtysh_exit_bgpd_cmd
);
3573 install_element(BGP_IPV6M_NODE
, &vtysh_quit_bgpd_cmd
);
3574 install_element(BGP_EVPN_NODE
, &vtysh_quit_bgpd_cmd
);
3575 install_element(BGP_EVPN_NODE
, &vtysh_exit_bgpd_cmd
);
3576 install_element(BGP_EVPN_VNI_NODE
, &vtysh_exit_bgpd_cmd
);
3577 install_element(BGP_EVPN_VNI_NODE
, &vtysh_quit_bgpd_cmd
);
3578 install_element(BGP_IPV6L_NODE
, &vtysh_exit_bgpd_cmd
);
3579 install_element(BGP_IPV6L_NODE
, &vtysh_quit_bgpd_cmd
);
3580 #if defined(ENABLE_BGP_VNC)
3581 install_element(BGP_VRF_POLICY_NODE
, &vtysh_exit_bgpd_cmd
);
3582 install_element(BGP_VRF_POLICY_NODE
, &vtysh_quit_bgpd_cmd
);
3583 install_element(BGP_VNC_DEFAULTS_NODE
, &vtysh_exit_bgpd_cmd
);
3584 install_element(BGP_VNC_DEFAULTS_NODE
, &vtysh_quit_bgpd_cmd
);
3585 install_element(BGP_VNC_NVE_GROUP_NODE
, &vtysh_exit_bgpd_cmd
);
3586 install_element(BGP_VNC_NVE_GROUP_NODE
, &vtysh_quit_bgpd_cmd
);
3587 install_element(BGP_VNC_L2_GROUP_NODE
, &vtysh_exit_bgpd_cmd
);
3588 install_element(BGP_VNC_L2_GROUP_NODE
, &vtysh_quit_bgpd_cmd
);
3590 install_element(ISIS_NODE
, &vtysh_exit_isisd_cmd
);
3591 install_element(ISIS_NODE
, &vtysh_quit_isisd_cmd
);
3592 install_element(KEYCHAIN_NODE
, &vtysh_exit_ripd_cmd
);
3593 install_element(KEYCHAIN_NODE
, &vtysh_quit_ripd_cmd
);
3594 install_element(KEYCHAIN_KEY_NODE
, &vtysh_exit_ripd_cmd
);
3595 install_element(KEYCHAIN_KEY_NODE
, &vtysh_quit_ripd_cmd
);
3596 install_element(RMAP_NODE
, &vtysh_exit_rmap_cmd
);
3597 install_element(RMAP_NODE
, &vtysh_quit_rmap_cmd
);
3598 install_element(PBRMAP_NODE
, &vtysh_exit_pbr_map_cmd
);
3599 install_element(PBRMAP_NODE
, &vtysh_quit_pbr_map_cmd
);
3602 install_element(CONFIG_NODE
, &bfd_enter_cmd
);
3603 install_element(BFD_NODE
, &bfd_peer_enter_cmd
);
3605 /* Exit/quit node. */
3606 install_element(BFD_NODE
, &vtysh_exit_bfdd_cmd
);
3607 install_element(BFD_NODE
, &vtysh_quit_bfdd_cmd
);
3608 install_element(BFD_PEER_NODE
, &vtysh_exit_bfdd_cmd
);
3609 install_element(BFD_PEER_NODE
, &vtysh_quit_bfdd_cmd
);
3612 install_element(BFD_NODE
, &vtysh_end_all_cmd
);
3613 install_element(BFD_PEER_NODE
, &vtysh_end_all_cmd
);
3614 #endif /* HAVE_BFDD */
3615 install_element(VTY_NODE
, &vtysh_exit_line_vty_cmd
);
3616 install_element(VTY_NODE
, &vtysh_quit_line_vty_cmd
);
3618 /* "end" command. */
3619 install_element(CONFIG_NODE
, &vtysh_end_all_cmd
);
3620 install_element(ENABLE_NODE
, &vtysh_end_all_cmd
);
3621 install_element(RIP_NODE
, &vtysh_end_all_cmd
);
3622 install_element(RIPNG_NODE
, &vtysh_end_all_cmd
);
3623 install_element(OSPF_NODE
, &vtysh_end_all_cmd
);
3624 install_element(EIGRP_NODE
, &vtysh_end_all_cmd
);
3625 install_element(BABEL_NODE
, &vtysh_end_all_cmd
);
3626 install_element(OSPF6_NODE
, &vtysh_end_all_cmd
);
3627 install_element(LDP_NODE
, &vtysh_end_all_cmd
);
3628 install_element(LDP_IPV4_NODE
, &vtysh_end_all_cmd
);
3629 install_element(LDP_IPV6_NODE
, &vtysh_end_all_cmd
);
3630 install_element(LDP_IPV4_IFACE_NODE
, &vtysh_end_all_cmd
);
3631 install_element(LDP_IPV6_IFACE_NODE
, &vtysh_end_all_cmd
);
3632 install_element(LDP_L2VPN_NODE
, &vtysh_end_all_cmd
);
3633 install_element(LDP_PSEUDOWIRE_NODE
, &vtysh_end_all_cmd
);
3634 install_element(BGP_NODE
, &vtysh_end_all_cmd
);
3635 install_element(BGP_IPV4_NODE
, &vtysh_end_all_cmd
);
3636 install_element(BGP_IPV4M_NODE
, &vtysh_end_all_cmd
);
3637 install_element(BGP_IPV4L_NODE
, &vtysh_end_all_cmd
);
3638 install_element(BGP_VPNV4_NODE
, &vtysh_end_all_cmd
);
3639 install_element(BGP_VPNV6_NODE
, &vtysh_end_all_cmd
);
3640 install_element(BGP_FLOWSPECV4_NODE
, &vtysh_end_all_cmd
);
3641 install_element(BGP_FLOWSPECV6_NODE
, &vtysh_end_all_cmd
);
3642 install_element(BGP_IPV6_NODE
, &vtysh_end_all_cmd
);
3643 install_element(BGP_IPV6M_NODE
, &vtysh_end_all_cmd
);
3644 install_element(BGP_IPV6L_NODE
, &vtysh_end_all_cmd
);
3645 install_element(BGP_VRF_POLICY_NODE
, &vtysh_end_all_cmd
);
3646 install_element(BGP_EVPN_NODE
, &vtysh_end_all_cmd
);
3647 install_element(BGP_EVPN_VNI_NODE
, &vtysh_end_all_cmd
);
3648 install_element(BGP_VNC_DEFAULTS_NODE
, &vtysh_end_all_cmd
);
3649 install_element(BGP_VNC_NVE_GROUP_NODE
, &vtysh_end_all_cmd
);
3650 install_element(BGP_VNC_L2_GROUP_NODE
, &vtysh_end_all_cmd
);
3651 install_element(ISIS_NODE
, &vtysh_end_all_cmd
);
3652 install_element(KEYCHAIN_NODE
, &vtysh_end_all_cmd
);
3653 install_element(KEYCHAIN_KEY_NODE
, &vtysh_end_all_cmd
);
3654 install_element(RMAP_NODE
, &vtysh_end_all_cmd
);
3655 install_element(PBRMAP_NODE
, &vtysh_end_all_cmd
);
3656 install_element(VTY_NODE
, &vtysh_end_all_cmd
);
3658 install_element(INTERFACE_NODE
, &vtysh_end_all_cmd
);
3659 install_element(INTERFACE_NODE
, &vtysh_exit_interface_cmd
);
3660 install_element(LINK_PARAMS_NODE
, &exit_link_params_cmd
);
3661 install_element(LINK_PARAMS_NODE
, &vtysh_end_all_cmd
);
3662 install_element(LINK_PARAMS_NODE
, &vtysh_exit_interface_cmd
);
3663 install_element(INTERFACE_NODE
, &vtysh_quit_interface_cmd
);
3665 install_element(PW_NODE
, &vtysh_end_all_cmd
);
3666 install_element(PW_NODE
, &vtysh_exit_interface_cmd
);
3667 install_element(PW_NODE
, &vtysh_quit_interface_cmd
);
3669 install_element(LOGICALROUTER_NODE
, &vtysh_end_all_cmd
);
3671 install_element(CONFIG_NODE
, &vtysh_logicalrouter_cmd
);
3672 install_element(CONFIG_NODE
, &vtysh_no_logicalrouter_cmd
);
3673 install_element(LOGICALROUTER_NODE
, &vtysh_exit_logicalrouter_cmd
);
3674 install_element(LOGICALROUTER_NODE
, &vtysh_quit_logicalrouter_cmd
);
3676 install_element(CONFIG_NODE
, &vtysh_nexthop_group_cmd
);
3677 install_element(NH_GROUP_NODE
, &vtysh_end_all_cmd
);
3678 install_element(NH_GROUP_NODE
, &vtysh_exit_nexthop_group_cmd
);
3679 install_element(NH_GROUP_NODE
, &vtysh_quit_nexthop_group_cmd
);
3681 install_element(VRF_NODE
, &vtysh_end_all_cmd
);
3682 install_element(VRF_NODE
, &vtysh_exit_vrf_cmd
);
3683 install_element(VRF_NODE
, &vtysh_quit_vrf_cmd
);
3685 install_element(CONFIG_NODE
, &router_eigrp_cmd
);
3686 install_element(CONFIG_NODE
, &router_babel_cmd
);
3687 install_element(CONFIG_NODE
, &router_rip_cmd
);
3688 install_element(CONFIG_NODE
, &router_ripng_cmd
);
3689 install_element(CONFIG_NODE
, &router_ospf_cmd
);
3690 install_element(CONFIG_NODE
, &router_ospf6_cmd
);
3691 #if defined(HAVE_LDPD)
3692 install_element(CONFIG_NODE
, &ldp_mpls_ldp_cmd
);
3693 install_element(LDP_NODE
, &ldp_address_family_ipv4_cmd
);
3694 install_element(LDP_NODE
, &ldp_address_family_ipv6_cmd
);
3695 install_element(LDP_IPV4_NODE
, &ldp_interface_ifname_cmd
);
3696 install_element(LDP_IPV6_NODE
, &ldp_interface_ifname_cmd
);
3697 install_element(CONFIG_NODE
, &ldp_l2vpn_word_type_vpls_cmd
);
3698 install_element(LDP_L2VPN_NODE
, &ldp_member_pseudowire_ifname_cmd
);
3700 install_element(CONFIG_NODE
, &router_isis_cmd
);
3701 install_element(CONFIG_NODE
, &router_bgp_cmd
);
3702 install_element(BGP_NODE
, &address_family_vpnv4_cmd
);
3703 install_element(BGP_NODE
, &address_family_vpnv6_cmd
);
3704 #if defined(ENABLE_BGP_VNC)
3705 install_element(BGP_NODE
, &vnc_vrf_policy_cmd
);
3706 install_element(BGP_NODE
, &vnc_defaults_cmd
);
3707 install_element(BGP_NODE
, &vnc_nve_group_cmd
);
3708 install_element(BGP_NODE
, &vnc_l2_group_cmd
);
3710 install_element(BGP_NODE
, &address_family_ipv4_cmd
);
3711 install_element(BGP_NODE
, &address_family_ipv4_multicast_cmd
);
3712 install_element(BGP_NODE
, &address_family_ipv4_vpn_cmd
);
3713 install_element(BGP_NODE
, &address_family_ipv4_labeled_unicast_cmd
);
3714 install_element(BGP_NODE
, &address_family_ipv6_cmd
);
3715 install_element(BGP_NODE
, &address_family_ipv6_multicast_cmd
);
3716 install_element(BGP_NODE
, &address_family_ipv6_vpn_cmd
);
3717 install_element(BGP_NODE
, &address_family_ipv6_labeled_unicast_cmd
);
3718 install_element(BGP_NODE
, &address_family_evpn_cmd
);
3719 install_element(BGP_NODE
, &address_family_flowspecv4_cmd
);
3720 install_element(BGP_NODE
, &address_family_flowspecv6_cmd
);
3721 #if defined(HAVE_CUMULUS)
3722 install_element(BGP_NODE
, &address_family_evpn2_cmd
);
3724 install_element(BGP_VPNV4_NODE
, &exit_address_family_cmd
);
3725 install_element(BGP_VPNV6_NODE
, &exit_address_family_cmd
);
3726 install_element(BGP_IPV4_NODE
, &exit_address_family_cmd
);
3727 install_element(BGP_IPV4M_NODE
, &exit_address_family_cmd
);
3728 install_element(BGP_IPV4L_NODE
, &exit_address_family_cmd
);
3729 install_element(BGP_IPV6_NODE
, &exit_address_family_cmd
);
3730 install_element(BGP_IPV6M_NODE
, &exit_address_family_cmd
);
3731 install_element(BGP_EVPN_NODE
, &exit_address_family_cmd
);
3732 install_element(BGP_IPV6L_NODE
, &exit_address_family_cmd
);
3733 install_element(BGP_FLOWSPECV4_NODE
, &exit_address_family_cmd
);
3734 install_element(BGP_FLOWSPECV6_NODE
, &exit_address_family_cmd
);
3736 #if defined(HAVE_RPKI)
3737 install_element(CONFIG_NODE
, &rpki_cmd
);
3738 install_element(RPKI_NODE
, &rpki_exit_cmd
);
3739 install_element(RPKI_NODE
, &rpki_quit_cmd
);
3740 install_element(RPKI_NODE
, &vtysh_end_all_cmd
);
3744 install_element(BGP_EVPN_NODE
, &bgp_evpn_vni_cmd
);
3745 install_element(BGP_EVPN_VNI_NODE
, &exit_vni_cmd
);
3747 install_element(BGP_VRF_POLICY_NODE
, &exit_vrf_policy_cmd
);
3748 install_element(BGP_VNC_DEFAULTS_NODE
, &exit_vnc_config_cmd
);
3749 install_element(BGP_VNC_NVE_GROUP_NODE
, &exit_vnc_config_cmd
);
3750 install_element(BGP_VNC_L2_GROUP_NODE
, &exit_vnc_config_cmd
);
3752 install_element(CONFIG_NODE
, &key_chain_cmd
);
3753 install_element(CONFIG_NODE
, &vtysh_route_map_cmd
);
3754 install_element(CONFIG_NODE
, &vtysh_pbr_map_cmd
);
3755 install_element(CONFIG_NODE
, &vtysh_no_pbr_map_cmd
);
3756 install_element(CONFIG_NODE
, &vtysh_line_vty_cmd
);
3757 install_element(KEYCHAIN_NODE
, &key_cmd
);
3758 install_element(KEYCHAIN_NODE
, &key_chain_cmd
);
3759 install_element(KEYCHAIN_KEY_NODE
, &key_chain_cmd
);
3760 install_element(CONFIG_NODE
, &vtysh_interface_cmd
);
3761 install_element(CONFIG_NODE
, &vtysh_pseudowire_cmd
);
3762 install_element(INTERFACE_NODE
, &vtysh_link_params_cmd
);
3763 install_element(ENABLE_NODE
, &vtysh_show_running_config_cmd
);
3764 install_element(ENABLE_NODE
, &vtysh_copy_running_config_cmd
);
3766 install_element(CONFIG_NODE
, &vtysh_vrf_cmd
);
3767 install_element(VRF_NODE
, &vtysh_vrf_netns_cmd
);
3768 install_element(VRF_NODE
, &vtysh_no_vrf_netns_cmd
);
3769 install_element(VRF_NODE
, &exit_vrf_config_cmd
);
3771 install_element(CONFIG_NODE
, &vtysh_no_nexthop_group_cmd
);
3773 /* "write terminal" command. */
3774 install_element(ENABLE_NODE
, &vtysh_write_terminal_cmd
);
3776 install_element(CONFIG_NODE
, &vtysh_integrated_config_cmd
);
3777 install_element(CONFIG_NODE
, &no_vtysh_integrated_config_cmd
);
3779 /* "write memory" command. */
3780 install_element(ENABLE_NODE
, &vtysh_write_memory_cmd
);
3782 install_element(VIEW_NODE
, &vtysh_terminal_length_cmd
);
3783 install_element(VIEW_NODE
, &vtysh_terminal_no_length_cmd
);
3784 install_element(VIEW_NODE
, &vtysh_show_daemons_cmd
);
3786 install_element(VIEW_NODE
, &vtysh_ping_cmd
);
3787 install_element(VIEW_NODE
, &vtysh_ping_ip_cmd
);
3788 install_element(VIEW_NODE
, &vtysh_traceroute_cmd
);
3789 install_element(VIEW_NODE
, &vtysh_traceroute_ip_cmd
);
3790 install_element(VIEW_NODE
, &vtysh_mtrace_cmd
);
3791 install_element(VIEW_NODE
, &vtysh_ping6_cmd
);
3792 install_element(VIEW_NODE
, &vtysh_traceroute6_cmd
);
3793 #if defined(HAVE_SHELL_ACCESS)
3794 install_element(VIEW_NODE
, &vtysh_telnet_cmd
);
3795 install_element(VIEW_NODE
, &vtysh_telnet_port_cmd
);
3796 install_element(VIEW_NODE
, &vtysh_ssh_cmd
);
3798 #if defined(HAVE_SHELL_ACCESS)
3799 install_element(ENABLE_NODE
, &vtysh_start_shell_cmd
);
3800 install_element(ENABLE_NODE
, &vtysh_start_bash_cmd
);
3801 install_element(ENABLE_NODE
, &vtysh_start_zsh_cmd
);
3805 install_element(VIEW_NODE
, &vtysh_show_debugging_cmd
);
3806 install_element(VIEW_NODE
, &vtysh_show_error_code_cmd
);
3807 install_element(VIEW_NODE
, &vtysh_show_debugging_hashtable_cmd
);
3808 install_element(ENABLE_NODE
, &vtysh_debug_all_cmd
);
3809 install_element(CONFIG_NODE
, &vtysh_debug_all_cmd
);
3811 /* misc lib show commands */
3812 install_element(VIEW_NODE
, &vtysh_show_memory_cmd
);
3813 install_element(VIEW_NODE
, &vtysh_show_modules_cmd
);
3814 install_element(VIEW_NODE
, &vtysh_show_work_queues_cmd
);
3815 install_element(VIEW_NODE
, &vtysh_show_work_queues_daemon_cmd
);
3816 install_element(VIEW_NODE
, &vtysh_show_thread_cmd
);
3817 install_element(VIEW_NODE
, &vtysh_show_poll_cmd
);
3820 install_element(VIEW_NODE
, &vtysh_show_logging_cmd
);
3821 install_element(CONFIG_NODE
, &vtysh_log_stdout_cmd
);
3822 install_element(CONFIG_NODE
, &vtysh_log_stdout_level_cmd
);
3823 install_element(CONFIG_NODE
, &no_vtysh_log_stdout_cmd
);
3824 install_element(CONFIG_NODE
, &vtysh_log_file_cmd
);
3825 install_element(CONFIG_NODE
, &vtysh_log_file_level_cmd
);
3826 install_element(CONFIG_NODE
, &no_vtysh_log_file_cmd
);
3827 install_element(CONFIG_NODE
, &vtysh_log_monitor_cmd
);
3828 install_element(CONFIG_NODE
, &no_vtysh_log_monitor_cmd
);
3829 install_element(CONFIG_NODE
, &vtysh_log_syslog_cmd
);
3830 install_element(CONFIG_NODE
, &no_vtysh_log_syslog_cmd
);
3831 install_element(CONFIG_NODE
, &vtysh_log_facility_cmd
);
3832 install_element(CONFIG_NODE
, &no_vtysh_log_facility_cmd
);
3833 install_element(CONFIG_NODE
, &vtysh_log_record_priority_cmd
);
3834 install_element(CONFIG_NODE
, &no_vtysh_log_record_priority_cmd
);
3835 install_element(CONFIG_NODE
, &vtysh_log_timestamp_precision_cmd
);
3836 install_element(CONFIG_NODE
, &no_vtysh_log_timestamp_precision_cmd
);
3838 install_element(CONFIG_NODE
, &vtysh_service_password_encrypt_cmd
);
3839 install_element(CONFIG_NODE
, &no_vtysh_service_password_encrypt_cmd
);
3841 install_element(CONFIG_NODE
, &vtysh_password_cmd
);
3842 install_element(CONFIG_NODE
, &no_vtysh_password_cmd
);
3843 install_element(CONFIG_NODE
, &vtysh_enable_password_cmd
);
3844 install_element(CONFIG_NODE
, &no_vtysh_enable_password_cmd
);