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 static void vtysh_pager_envdef(bool fallback
)
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
= "fabricd", .flag
= VTYSH_FABRICD
, .next
= NULL
},
136 {.fd
= -1, .name
= "watchfrr", .flag
= VTYSH_WATCHFRR
, .next
= NULL
},
137 {.fd
= -1, .name
= "pbrd", .flag
= VTYSH_PBRD
, .next
= NULL
},
138 {.fd
= -1, .name
= "staticd", .flag
= VTYSH_STATICD
, .next
= NULL
},
139 {.fd
= -1, .name
= "bfdd", .flag
= VTYSH_BFDD
, .next
= NULL
},
140 {.fd
= -1, .name
= "vrrpd", .flag
= VTYSH_VRRPD
, .next
= NULL
},
143 /* Searches for client by name, returns index */
144 static int vtysh_client_lookup(const char *name
)
148 for (unsigned int i
= 0; i
< array_size(vtysh_client
); i
++) {
149 if (strmatch(vtysh_client
[i
].name
, name
)) {
158 enum vtysh_write_integrated vtysh_write_integrated
=
159 WRITE_INTEGRATED_UNSPECIFIED
;
161 static int vtysh_reconnect(struct vtysh_client
*vclient
);
163 static void vclient_close(struct vtysh_client
*vclient
)
165 if (vclient
->fd
>= 0) {
167 "Warning: closing connection to %s because of an I/O error!\n",
170 /* indicate as candidate for reconnect */
171 vclient
->fd
= VTYSH_WAS_ACTIVE
;
176 * Send a CLI command to a client and read the response.
178 * Output will be printed to vty->of. If you want to suppress output, set that
182 * the client to send the command to
185 * the command to send
188 * if non-null, this will be called with each line of output received from
189 * the client passed in the second parameter
192 * optional first argument to pass to callback
197 static int vtysh_client_run(struct vtysh_client
*vclient
, const char *line
,
198 void (*callback
)(void *, const char *), void *cbarg
)
202 char *buf
= stackbuf
;
203 size_t bufsz
= sizeof(stackbuf
);
204 char *bufvalid
, *end
= NULL
;
205 char terminator
[3] = {0, 0, 0};
207 /* vclinet was previously active, try to reconnect */
208 if (vclient
->fd
== VTYSH_WAS_ACTIVE
) {
209 ret
= vtysh_reconnect(vclient
);
217 ret
= write(vclient
->fd
, line
, strlen(line
) + 1);
219 /* close connection and try to reconnect */
220 vclient_close(vclient
);
221 ret
= vtysh_reconnect(vclient
);
225 ret
= write(vclient
->fd
, line
, strlen(line
) + 1);
233 read(vclient
->fd
, bufvalid
, buf
+ bufsz
- bufvalid
- 1);
235 if (nread
< 0 && (errno
== EINTR
|| errno
== EAGAIN
))
239 vty_out(vty
, "vtysh: error reading from %s: %s (%d)",
240 vclient
->name
, safe_strerror(errno
), errno
);
246 /* Null terminate so we may pass this to *printf later. */
250 * We expect string output from daemons, so instead of looking
251 * for the full 3 null bytes of the terminator, we check for
252 * just one instead and assume it is the first byte of the
253 * terminator. The presence of the full terminator is checked
256 if (bufvalid
- buf
>= 4)
257 end
= memmem(bufvalid
- 4, 4, "\0", 1);
260 * calculate # bytes we have, up to & not including the
261 * terminator if present
263 size_t textlen
= (end
? end
: bufvalid
) - buf
;
266 /* feed line processing callback if present */
267 while (callback
&& bufvalid
> buf
&& (end
> buf
|| !end
)) {
268 textlen
= (end
? end
: bufvalid
) - buf
;
269 char *eol
= memchr(buf
, '\n', textlen
);
275 * no line break, end of input, no text left
276 * before end; nothing to write
280 /* no nl, end of input, but some text left */
282 else if (bufvalid
== buf
+ bufsz
- 1) {
284 * no nl, no end of input, no buffer space;
290 if (buf
== stackbuf
) {
291 new = XMALLOC(MTYPE_TMP
, bufsz
);
292 memcpy(new, stackbuf
, sizeof(stackbuf
));
294 new = XREALLOC(MTYPE_TMP
, buf
, bufsz
);
296 bufvalid
= bufvalid
- buf
+ new;
298 /* if end != NULL, we won't be reading more
308 /* eol is at line end now, either \n => \0 or \0\0\0 */
309 assert(eol
&& eol
<= bufvalid
);
312 vty_out(vty
, "%s\n", buf
);
314 callback(cbarg
, buf
);
316 /* shift back data and adjust bufvalid */
317 memmove(buf
, eol
, bufvalid
- eol
);
318 bufvalid
-= eol
- buf
;
323 /* else if no callback, dump raw */
326 vty_out(vty
, "%s", buf
);
327 memmove(buf
, buf
+ textlen
, bufvalid
- buf
- textlen
);
333 * ----------------------------------------------------
334 * At this point `buf` should be in one of two states:
335 * - Empty (i.e. buf == bufvalid)
336 * - Contains up to 4 bytes of the terminator
337 * ----------------------------------------------------
339 assert(((buf
== bufvalid
)
340 || (bufvalid
- buf
<= 4 && buf
[0] == 0x00)));
343 /* if we have the terminator, break */
344 if (end
&& bufvalid
- buf
== 4) {
345 assert(!memcmp(buf
, terminator
, 3));
354 vclient_close(vclient
);
358 XFREE(MTYPE_TMP
, buf
);
362 static int vtysh_client_run_all(struct vtysh_client
*head_client
,
363 const char *line
, int continue_on_err
,
364 void (*callback
)(void *, const char *),
367 struct vtysh_client
*client
;
368 int rc
, rc_all
= CMD_SUCCESS
;
369 int correct_instance
= 0, wrong_instance
= 0;
371 for (client
= head_client
; client
; client
= client
->next
) {
372 rc
= vtysh_client_run(client
, line
, callback
, cbarg
);
373 if (rc
== CMD_NOT_MY_INSTANCE
) {
379 if (rc
!= CMD_SUCCESS
) {
380 if (!continue_on_err
)
385 if (wrong_instance
&& !correct_instance
) {
387 "%% [%s]: command ignored as it targets an instance that is not running\n",
389 rc_all
= CMD_WARNING_CONFIG_FAILED
;
395 * Execute command against all daemons.
398 * where to start walking in the daemon list
401 * the specific command to execute
406 static int vtysh_client_execute(struct vtysh_client
*head_client
,
409 return vtysh_client_run_all(head_client
, line
, 0, NULL
, NULL
);
412 /* Execute by name */
413 static int vtysh_client_execute_name(const char *name
, const char *line
)
415 int ret
= CMD_SUCCESS
;
418 idx_client
= vtysh_client_lookup(name
);
419 if (idx_client
!= -1)
420 ret
= vtysh_client_execute(&vtysh_client
[idx_client
], line
);
422 vty_out(vty
, "Client not found\n");
430 * Retrieve all running config from daemons and parse it with the vtysh config
431 * parser. Returned output is not displayed to the user.
434 * where to start walking in the daemon list
437 * the specific command to execute
439 static void vtysh_client_config(struct vtysh_client
*head_client
, char *line
)
441 /* watchfrr currently doesn't load any config, and has some hardcoded
442 * settings that show up in "show run". skip it here (for now at
443 * least) so we don't get that mangled up in config-write.
445 if (head_client
->flag
== VTYSH_WATCHFRR
)
448 /* suppress output to user */
449 vty
->of_saved
= vty
->of
;
451 vtysh_client_run_all(head_client
, line
, 1, vtysh_config_parse_line
,
453 vty
->of
= vty
->of_saved
;
456 /* Command execution over the vty interface. */
457 static int vtysh_execute_func(const char *line
, int pager
)
462 const struct cmd_element
*cmd
;
464 int saved_ret
, saved_node
;
466 /* Split readline string up into the vector. */
467 vline
= cmd_make_strvec(line
);
473 if (strncmp("en", vector_slot(vline
, 0), 2) == 0) {
474 cmd_free_strvec(vline
);
475 vty_out(vty
, "%% Command not allowed: enable\n");
480 saved_ret
= ret
= cmd_execute(vty
, line
, &cmd
, 1);
481 saved_node
= vty
->node
;
484 * If command doesn't succeeded in current node, try to walk up in node
485 * tree. Changing vty->node is enough to try it just out without actual
486 * walkup in the vtysh.
488 while (ret
!= CMD_SUCCESS
&& ret
!= CMD_SUCCESS_DAEMON
489 && ret
!= CMD_WARNING
&& ret
!= CMD_WARNING_CONFIG_FAILED
490 && vty
->node
> CONFIG_NODE
) {
491 vty
->node
= node_parent(vty
->node
);
492 ret
= cmd_execute(vty
, line
, &cmd
, 1);
496 vty
->node
= saved_node
;
499 * If command succeeded in any other node than current (tried > 0) we
500 * have to move into node in the vtysh where it succeeded.
502 if (ret
== CMD_SUCCESS
|| ret
== CMD_SUCCESS_DAEMON
503 || ret
== CMD_WARNING
) {
504 if ((saved_node
== BGP_VPNV4_NODE
505 || saved_node
== BGP_VPNV6_NODE
506 || saved_node
== BGP_IPV4_NODE
507 || saved_node
== BGP_IPV6_NODE
508 || saved_node
== BGP_FLOWSPECV4_NODE
509 || saved_node
== BGP_FLOWSPECV6_NODE
510 || saved_node
== BGP_IPV4M_NODE
511 || saved_node
== BGP_IPV4L_NODE
512 || saved_node
== BGP_IPV6L_NODE
513 || saved_node
== BGP_IPV6M_NODE
514 || saved_node
== BGP_EVPN_NODE
515 || saved_node
== LDP_IPV4_NODE
516 || saved_node
== LDP_IPV6_NODE
)
518 vtysh_execute("exit-address-family");
519 } else if ((saved_node
== BGP_EVPN_VNI_NODE
) && (tried
== 1)) {
520 vtysh_execute("exit-vni");
521 } else if (saved_node
== BGP_VRF_POLICY_NODE
&& (tried
== 1)) {
522 vtysh_execute("exit-vrf-policy");
523 } else if ((saved_node
== BGP_VNC_DEFAULTS_NODE
524 || saved_node
== BGP_VNC_NVE_GROUP_NODE
525 || saved_node
== BGP_VNC_L2_GROUP_NODE
)
527 vtysh_execute("exit-vnc");
528 } else if (saved_node
== VRF_NODE
&& (tried
== 1)) {
529 vtysh_execute("exit-vrf");
530 } else if ((saved_node
== KEYCHAIN_KEY_NODE
531 || saved_node
== LDP_PSEUDOWIRE_NODE
532 || saved_node
== LDP_IPV4_IFACE_NODE
533 || saved_node
== LDP_IPV6_IFACE_NODE
)
535 vtysh_execute("exit");
537 vtysh_execute("end");
538 vtysh_execute("configure");
542 * If command didn't succeed in any node, continue with return value
549 cmd_free_strvec(vline
);
554 case CMD_WARNING_CONFIG_FAILED
:
555 if (vty
->type
== VTY_FILE
)
556 vty_out(vty
, "Warning...\n");
558 case CMD_ERR_AMBIGUOUS
:
559 vty_out(vty
, "%% Ambiguous command: %s\n", line
);
561 case CMD_ERR_NO_MATCH
:
562 vty_out(vty
, "%% Unknown command: %s\n", line
);
564 case CMD_ERR_INCOMPLETE
:
565 vty_out(vty
, "%% Command incomplete: %s\n", line
);
567 case CMD_SUCCESS_DAEMON
: {
569 * FIXME: Don't open pager for exit commands. popen() causes
570 * problems if exited from vtysh at all. This hack shouldn't
571 * cause any problem but is really ugly.
573 if (pager
&& strncmp(line
, "exit", 4))
576 if (!strcmp(cmd
->string
, "configure")) {
577 for (i
= 0; i
< array_size(vtysh_client
); i
++) {
578 cmd_stat
= vtysh_client_execute(
579 &vtysh_client
[i
], line
);
580 if (cmd_stat
== CMD_WARNING
)
586 vline
= cmd_make_strvec(line
);
591 vty_close_pager(vty
);
595 ret
= cmd_execute_command(vline
, vty
, &cmd
, 1);
596 cmd_free_strvec(vline
);
597 if (ret
!= CMD_SUCCESS_DAEMON
)
599 } else if (cmd
->func
) {
600 (*cmd
->func
)(cmd
, vty
, 0, NULL
);
605 cmd_stat
= CMD_SUCCESS
;
606 struct vtysh_client
*vc
;
607 for (i
= 0; i
< array_size(vtysh_client
); i
++) {
608 if (cmd
->daemon
& vtysh_client
[i
].flag
) {
609 if (vtysh_client
[i
].fd
< 0
610 && (cmd
->daemon
== vtysh_client
[i
].flag
)) {
611 for (vc
= &vtysh_client
[i
]; vc
;
613 if (vc
->fd
== VTYSH_WAS_ACTIVE
)
616 if (vtysh_client
[i
].fd
< 0
617 && (cmd
->daemon
== vtysh_client
[i
].flag
)) {
618 bool any_inst
= false;
619 for (vc
= &vtysh_client
[i
]; vc
;
625 "%s is not running\n",
626 vtysh_client
[i
].name
);
630 cmd_stat
= vtysh_client_execute(
631 &vtysh_client
[i
], line
);
632 if (cmd_stat
!= CMD_SUCCESS
)
636 if (cmd_stat
!= CMD_SUCCESS
)
640 (*cmd
->func
)(cmd
, vty
, 0, NULL
);
644 vty_close_pager(vty
);
649 int vtysh_execute_no_pager(const char *line
)
651 return vtysh_execute_func(line
, 0);
654 int vtysh_execute(const char *line
)
656 return vtysh_execute_func(line
, 1);
659 static char *trim(char *s
)
670 while (end
>= s
&& isspace((int)*end
))
674 while (*s
&& isspace((int)*s
))
680 int vtysh_mark_file(const char *filename
)
687 const struct cmd_element
*cmd
;
688 int saved_ret
, prev_node
;
690 char *vty_buf_copy
= NULL
;
691 char *vty_buf_trimmed
= NULL
;
693 if (strncmp("-", filename
, 1) == 0)
696 confp
= fopen(filename
, "r");
699 fprintf(stderr
, "%% Can't open config file %s due to '%s'.\n",
700 filename
, safe_strerror(errno
));
701 return (CMD_ERR_NO_FILE
);
705 vty
->wfd
= STDERR_FILENO
;
706 vty
->type
= VTY_TERM
;
707 vty
->node
= CONFIG_NODE
;
709 vtysh_execute_no_pager("enable");
710 vtysh_execute_no_pager("configure");
711 vty_buf_copy
= XCALLOC(MTYPE_VTYSH_CMD
, VTY_BUFSIZ
);
713 while (fgets(vty
->buf
, VTY_BUFSIZ
, confp
)) {
716 strlcpy(vty_buf_copy
, vty
->buf
, VTY_BUFSIZ
);
717 vty_buf_trimmed
= trim(vty_buf_copy
);
720 case LDP_IPV4_IFACE_NODE
:
721 if (strncmp(vty_buf_copy
, " ", 3)) {
722 vty_out(vty
, " end\n");
723 vty
->node
= LDP_IPV4_NODE
;
726 case LDP_IPV6_IFACE_NODE
:
727 if (strncmp(vty_buf_copy
, " ", 3)) {
728 vty_out(vty
, " end\n");
729 vty
->node
= LDP_IPV6_NODE
;
732 case LDP_PSEUDOWIRE_NODE
:
733 if (strncmp(vty_buf_copy
, " ", 2)) {
734 vty_out(vty
, " end\n");
735 vty
->node
= LDP_L2VPN_NODE
;
742 if (vty_buf_trimmed
[0] == '!' || vty_buf_trimmed
[0] == '#') {
743 vty_out(vty
, "%s", vty
->buf
);
747 /* Split readline string up into the vector. */
748 vline
= cmd_make_strvec(vty
->buf
);
751 vty_out(vty
, "%s", vty
->buf
);
756 * Ignore the "end" lines, we will generate these where
759 if (strlen(vty_buf_trimmed
) == 3
760 && strncmp("end", vty_buf_trimmed
, 3) == 0) {
761 cmd_free_strvec(vline
);
765 prev_node
= vty
->node
;
766 saved_ret
= ret
= cmd_execute_command_strict(vline
, vty
, &cmd
);
769 * If command doesn't succeeded in current node, try to walk up
770 * in node tree. Changing vty->node is enough to try it just
771 * out without actual walkup in the vtysh.
773 while (ret
!= CMD_SUCCESS
&& ret
!= CMD_SUCCESS_DAEMON
774 && ret
!= CMD_WARNING
&& ret
!= CMD_WARNING_CONFIG_FAILED
775 && vty
->node
> CONFIG_NODE
) {
776 vty
->node
= node_parent(vty
->node
);
777 ret
= cmd_execute_command_strict(vline
, vty
, &cmd
);
782 * If command succeeded in any other node than current (tried >
783 * 0) we have to move into node in the vtysh where it
786 if (ret
== CMD_SUCCESS
|| ret
== CMD_SUCCESS_DAEMON
787 || ret
== CMD_WARNING
) {
788 if ((prev_node
== BGP_VPNV4_NODE
789 || prev_node
== BGP_VPNV6_NODE
790 || prev_node
== BGP_IPV4_NODE
791 || prev_node
== BGP_IPV6_NODE
792 || prev_node
== BGP_FLOWSPECV4_NODE
793 || prev_node
== BGP_FLOWSPECV6_NODE
794 || prev_node
== BGP_IPV4L_NODE
795 || prev_node
== BGP_IPV6L_NODE
796 || prev_node
== BGP_IPV4M_NODE
797 || prev_node
== BGP_IPV6M_NODE
798 || prev_node
== BGP_EVPN_NODE
)
800 vty_out(vty
, "exit-address-family\n");
801 } else if ((prev_node
== BGP_EVPN_VNI_NODE
)
803 vty_out(vty
, "exit-vni\n");
804 } else if ((prev_node
== KEYCHAIN_KEY_NODE
)
806 vty_out(vty
, "exit\n");
808 vty_out(vty
, "end\n");
812 * If command didn't succeed in any node, continue with return
813 * value from first try.
817 vty
->node
= prev_node
;
820 cmd_free_strvec(vline
);
823 case CMD_WARNING_CONFIG_FAILED
:
824 if (vty
->type
== VTY_FILE
)
825 fprintf(stderr
, "line %d: Warning...: %s\n",
829 XFREE(MTYPE_VTYSH_CMD
, vty_buf_copy
);
831 case CMD_ERR_AMBIGUOUS
:
832 fprintf(stderr
, "line %d: %% Ambiguous command: %s\n",
836 XFREE(MTYPE_VTYSH_CMD
, vty_buf_copy
);
837 return CMD_ERR_AMBIGUOUS
;
838 case CMD_ERR_NO_MATCH
:
839 fprintf(stderr
, "line %d: %% Unknown command: %s\n",
843 XFREE(MTYPE_VTYSH_CMD
, vty_buf_copy
);
844 return CMD_ERR_NO_MATCH
;
845 case CMD_ERR_INCOMPLETE
:
846 fprintf(stderr
, "line %d: %% Command incomplete: %s\n",
850 XFREE(MTYPE_VTYSH_CMD
, vty_buf_copy
);
851 return CMD_ERR_INCOMPLETE
;
853 vty_out(vty
, "%s", vty
->buf
);
855 case CMD_SUCCESS_DAEMON
: {
858 vty_out(vty
, "%s", vty
->buf
);
859 cmd_stat
= vtysh_client_execute(&vtysh_client
[0],
861 if (cmd_stat
!= CMD_SUCCESS
)
865 (*cmd
->func
)(cmd
, vty
, 0, NULL
);
869 /* This is the end */
870 vty_out(vty
, "\nend\n");
872 XFREE(MTYPE_VTYSH_CMD
, vty_buf_copy
);
880 /* Configration make from file. */
881 int vtysh_config_from_file(struct vty
*vty
, FILE *fp
)
884 const struct cmd_element
*cmd
;
886 /* once we have an error, we remember & return that */
887 int retcode
= CMD_SUCCESS
;
889 while (fgets(vty
->buf
, VTY_BUFSIZ
, fp
)) {
892 ret
= command_config_read_one_line(vty
, &cmd
, lineno
, 1);
896 case CMD_WARNING_CONFIG_FAILED
:
897 if (vty
->type
== VTY_FILE
)
898 fprintf(stderr
, "line %d: Warning[%d]...: %s\n",
899 lineno
, vty
->node
, vty
->buf
);
903 case CMD_ERR_AMBIGUOUS
:
905 "line %d: %% Ambiguous command[%d]: %s\n",
906 lineno
, vty
->node
, vty
->buf
);
907 retcode
= CMD_ERR_AMBIGUOUS
;
909 case CMD_ERR_NO_MATCH
:
910 fprintf(stderr
, "line %d: %% Unknown command[%d]: %s",
911 lineno
, vty
->node
, vty
->buf
);
912 retcode
= CMD_ERR_NO_MATCH
;
914 case CMD_ERR_INCOMPLETE
:
916 "line %d: %% Command incomplete[%d]: %s\n",
917 lineno
, vty
->node
, vty
->buf
);
918 retcode
= CMD_ERR_INCOMPLETE
;
920 case CMD_SUCCESS_DAEMON
: {
922 int cmd_stat
= CMD_SUCCESS
;
924 for (i
= 0; i
< array_size(vtysh_client
); i
++) {
925 if (cmd
->daemon
& vtysh_client
[i
].flag
) {
926 cmd_stat
= vtysh_client_execute(
927 &vtysh_client
[i
], vty
->buf
);
929 * CMD_WARNING - Can mean that the
930 * command was parsed successfully but
931 * it was already entered in a few
932 * spots. As such if we receive a
933 * CMD_WARNING from a daemon we
934 * shouldn't stop talking to the other
935 * daemons for the particular command.
937 if (cmd_stat
!= CMD_SUCCESS
938 && cmd_stat
!= CMD_WARNING
) {
940 "line %d: Failure to communicate[%d] to %s, line: %s\n",
942 vtysh_client
[i
].name
,
949 if (cmd_stat
!= CMD_SUCCESS
)
953 (*cmd
->func
)(cmd
, vty
, 0, NULL
);
962 * Function processes cli commands terminated with '?' character when entered
963 * through either 'vtysh' or 'vtysh -c' interfaces.
965 static int vtysh_process_questionmark(const char *input
, int input_len
)
969 vector vline
, describe
;
970 struct cmd_token
*token
;
975 vline
= cmd_make_strvec(input
);
977 /* In case of '> ?'. */
979 vline
= vector_init(1);
980 vector_set(vline
, NULL
);
981 } else if (input_len
&& isspace((int)input
[input_len
- 1]))
982 vector_set(vline
, NULL
);
984 describe
= cmd_describe_command(vline
, vty
, &ret
);
986 /* Ambiguous and no match error. */
988 case CMD_ERR_AMBIGUOUS
:
989 cmd_free_strvec(vline
);
990 vector_free(describe
);
991 vty_out(vty
, "%% Ambiguous command.\n");
995 case CMD_ERR_NO_MATCH
:
996 cmd_free_strvec(vline
);
998 vector_free(describe
);
999 vty_out(vty
, "%% There is no matched command.\n");
1005 /* Get width of command string. */
1007 for (i
= 0; i
< vector_active(describe
); i
++)
1008 if ((token
= vector_slot(describe
, i
)) != NULL
) {
1009 if (token
->text
[0] == '\0')
1012 int len
= strlen(token
->text
);
1018 for (i
= 0; i
< vector_active(describe
); i
++)
1019 if ((token
= vector_slot(describe
, i
)) != NULL
) {
1021 vty_out(vty
, " %-s\n", token
->text
);
1023 vty_out(vty
, " %-*s %s\n", width
, token
->text
,
1026 if (IS_VARYING_TOKEN(token
->type
)) {
1027 const char *ref
= vector_slot(
1028 vline
, vector_active(vline
) - 1);
1030 vector varcomps
= vector_init(VECTOR_MIN_SIZE
);
1031 cmd_variable_complete(token
, ref
, varcomps
);
1033 if (vector_active(varcomps
) > 0) {
1035 rl_get_screen_size(&rows
, &cols
);
1037 char *ac
= cmd_variable_comp2str(
1039 vty_out(vty
, "%s\n", ac
);
1040 XFREE(MTYPE_TMP
, ac
);
1043 vector_free(varcomps
);
1047 cmd_free_strvec(vline
);
1048 vector_free(describe
);
1054 * Entry point for user commands terminated with '?' character and typed through
1055 * the usual vtysh's stdin interface. This is the function being registered with
1058 static int vtysh_rl_describe(int a
, int b
)
1064 ret
= vtysh_process_questionmark(rl_line_buffer
, rl_end
);
1071 * Function in charged of processing vtysh instructions terminating with '?'
1072 * character and received through the 'vtysh -c' interface. If user's
1073 * instruction is well-formatted, we will call the same processing routine
1074 * utilized by the traditional vtysh's stdin interface.
1076 int vtysh_execute_command_questionmark(char *input
)
1078 int input_len
, qmark_count
= 0;
1081 if (!(input
&& *input
))
1084 /* Finding out question_mark count and strlen */
1085 for (str
= input
; *str
; ++str
) {
1089 input_len
= str
- input
;
1092 * Verify that user's input terminates in '?' and that patterns such as
1093 * 'cmd ? subcmd ?' are prevented.
1095 if (qmark_count
!= 1 || input
[input_len
- 1] != '?')
1099 * Questionmark-processing function is not expecting to receive '?'
1100 * character in input string.
1102 input
[input_len
- 1] = '\0';
1104 return vtysh_process_questionmark(input
, input_len
- 1);
1107 /* Result of cmd_complete_command() call will be stored here
1108 * and used in new_completion() in order to put the space in
1109 * correct places only. */
1110 int complete_status
;
1112 static char *command_generator(const char *text
, int state
)
1115 static char **matched
= NULL
;
1116 static int index
= 0;
1122 if (vty
->node
== AUTH_NODE
|| vty
->node
== AUTH_ENABLE_NODE
)
1125 vline
= cmd_make_strvec(rl_line_buffer
);
1129 if (rl_end
&& isspace((int)rl_line_buffer
[rl_end
- 1]))
1130 vector_set(vline
, NULL
);
1132 matched
= cmd_complete_command(vline
, vty
, &complete_status
);
1133 cmd_free_strvec(vline
);
1136 if (matched
&& matched
[index
])
1138 * this is free()'d by readline, but we leak 1 count of
1141 return matched
[index
++];
1143 XFREE(MTYPE_TMP
, matched
);
1149 static char **new_completion(const char *text
, int start
, int end
)
1153 matches
= rl_completion_matches(text
, command_generator
);
1157 if (complete_status
!= CMD_COMPLETE_FULL_MATCH
)
1158 /* only append a space on full match */
1159 rl_completion_append_character
= '\0';
1165 /* Vty node structures. */
1166 static struct cmd_node bgp_node
= {
1167 BGP_NODE
, "%s(config-router)# ",
1170 static struct cmd_node rip_node
= {
1171 RIP_NODE
, "%s(config-router)# ",
1174 static struct cmd_node isis_node
= {
1175 ISIS_NODE
, "%s(config-router)# ",
1178 static struct cmd_node openfabric_node
= {
1179 OPENFABRIC_NODE
, "%s(config-router)# ",
1182 static struct cmd_node interface_node
= {
1183 INTERFACE_NODE
, "%s(config-if)# ",
1186 static struct cmd_node pw_node
= {
1187 PW_NODE
, "%s(config-pw)# ",
1190 static struct cmd_node logicalrouter_node
= {
1191 LOGICALROUTER_NODE
, "%s(config-logical-router)# ",
1194 static struct cmd_node vrf_node
= {
1195 VRF_NODE
, "%s(config-vrf)# ",
1198 static struct cmd_node nh_group_node
= {
1200 "%s(config-nh-group)# ",
1203 static struct cmd_node rmap_node
= {RMAP_NODE
, "%s(config-route-map)# "};
1205 static struct cmd_node pbr_map_node
= {PBRMAP_NODE
, "%s(config-pbr-map)# "};
1207 static struct cmd_node zebra_node
= {ZEBRA_NODE
, "%s(config-router)# "};
1209 static struct cmd_node bgp_vpnv4_node
= {BGP_VPNV4_NODE
,
1210 "%s(config-router-af)# "};
1212 static struct cmd_node bgp_vpnv6_node
= {BGP_VPNV6_NODE
,
1213 "%s(config-router-af)# "};
1215 static struct cmd_node bgp_flowspecv4_node
= {BGP_FLOWSPECV4_NODE
,
1216 "%s(config-router-af)# "};
1218 static struct cmd_node bgp_flowspecv6_node
= {BGP_FLOWSPECV6_NODE
,
1219 "%s(config-router-af)# "};
1221 static struct cmd_node bgp_ipv4_node
= {BGP_IPV4_NODE
,
1222 "%s(config-router-af)# "};
1224 static struct cmd_node bgp_ipv4m_node
= {BGP_IPV4M_NODE
,
1225 "%s(config-router-af)# "};
1227 static struct cmd_node bgp_ipv4l_node
= {BGP_IPV4L_NODE
,
1228 "%s(config-router-af)# "};
1230 static struct cmd_node bgp_ipv6_node
= {BGP_IPV6_NODE
,
1231 "%s(config-router-af)# "};
1233 static struct cmd_node bgp_ipv6m_node
= {BGP_IPV6M_NODE
,
1234 "%s(config-router-af)# "};
1236 static struct cmd_node bgp_evpn_node
= {BGP_EVPN_NODE
,
1237 "%s(config-router-af)# "};
1239 static struct cmd_node bgp_evpn_vni_node
= {BGP_EVPN_VNI_NODE
,
1240 "%s(config-router-af-vni)# "};
1242 static struct cmd_node bgp_ipv6l_node
= {BGP_IPV6L_NODE
,
1243 "%s(config-router-af)# "};
1245 static struct cmd_node bgp_vnc_defaults_node
= {
1246 BGP_VNC_DEFAULTS_NODE
, "%s(config-router-vnc-defaults)# "};
1248 static struct cmd_node bgp_vnc_nve_group_node
= {
1249 BGP_VNC_NVE_GROUP_NODE
, "%s(config-router-vnc-nve-group)# "};
1251 static struct cmd_node bgp_vrf_policy_node
= {BGP_VRF_POLICY_NODE
,
1252 "%s(config-router-vrf-policy)# "};
1254 static struct cmd_node bgp_vnc_l2_group_node
= {
1255 BGP_VNC_L2_GROUP_NODE
, "%s(config-router-vnc-l2-group)# "};
1257 static struct cmd_node ospf_node
= {OSPF_NODE
, "%s(config-router)# "};
1259 static struct cmd_node eigrp_node
= {EIGRP_NODE
, "%s(config-router)# "};
1261 static struct cmd_node babel_node
= {BABEL_NODE
, "%s(config-router)# "};
1263 static struct cmd_node ripng_node
= {RIPNG_NODE
, "%s(config-router)# "};
1265 static struct cmd_node ospf6_node
= {OSPF6_NODE
, "%s(config-ospf6)# "};
1267 static struct cmd_node ldp_node
= {LDP_NODE
, "%s(config-ldp)# "};
1269 static struct cmd_node ldp_ipv4_node
= {LDP_IPV4_NODE
, "%s(config-ldp-af)# "};
1271 static struct cmd_node ldp_ipv6_node
= {LDP_IPV6_NODE
, "%s(config-ldp-af)# "};
1273 static struct cmd_node ldp_ipv4_iface_node
= {LDP_IPV4_IFACE_NODE
,
1274 "%s(config-ldp-af-if)# "};
1276 static struct cmd_node ldp_ipv6_iface_node
= {LDP_IPV6_IFACE_NODE
,
1277 "%s(config-ldp-af-if)# "};
1279 static struct cmd_node ldp_l2vpn_node
= {LDP_L2VPN_NODE
, "%s(config-l2vpn)# "};
1281 static struct cmd_node ldp_pseudowire_node
= {LDP_PSEUDOWIRE_NODE
,
1282 "%s(config-l2vpn-pw)# "};
1284 static struct cmd_node keychain_node
= {KEYCHAIN_NODE
, "%s(config-keychain)# "};
1286 static struct cmd_node keychain_key_node
= {KEYCHAIN_KEY_NODE
,
1287 "%s(config-keychain-key)# "};
1289 struct cmd_node link_params_node
= {
1290 LINK_PARAMS_NODE
, "%s(config-link-params)# ",
1293 static struct cmd_node rpki_node
= {RPKI_NODE
, "%s(config-rpki)# ", 1};
1296 static struct cmd_node bfd_node
= {
1301 static struct cmd_node bfd_peer_node
= {
1303 "%s(config-bfd-peer)# ",
1305 #endif /* HAVE_BFDD */
1307 /* Defined in lib/vty.c */
1308 extern struct cmd_node vty_node
;
1310 /* When '^Z' is received from vty, move down to the enable mode. */
1311 static int vtysh_end(void)
1313 switch (vty
->node
) {
1316 /* Nothing to do. */
1319 vty
->node
= ENABLE_NODE
;
1325 DEFUNSH(VTYSH_REALLYALL
, vtysh_end_all
, vtysh_end_all_cmd
, "end",
1326 "End current mode and change to enable mode\n")
1331 DEFUNSH(VTYSH_BGPD
, router_bgp
, router_bgp_cmd
,
1332 "router bgp [(1-4294967295) [<view|vrf> WORD]]",
1333 ROUTER_STR BGP_STR AS_STR
1334 "BGP view\nBGP VRF\n"
1337 vty
->node
= BGP_NODE
;
1341 #ifdef KEEP_OLD_VPN_COMMANDS
1342 DEFUNSH(VTYSH_BGPD
, address_family_vpnv4
, address_family_vpnv4_cmd
,
1343 "address-family vpnv4 [unicast]",
1344 "Enter Address Family command mode\n"
1346 "Address Family modifier\n")
1348 vty
->node
= BGP_VPNV4_NODE
;
1352 DEFUNSH(VTYSH_BGPD
, address_family_vpnv6
, address_family_vpnv6_cmd
,
1353 "address-family vpnv6 [unicast]",
1354 "Enter Address Family command mode\n"
1356 "Address Family modifier\n")
1358 vty
->node
= BGP_VPNV6_NODE
;
1361 #endif /* KEEP_OLD_VPN_COMMANDS */
1363 DEFUNSH(VTYSH_BGPD
, address_family_ipv4
, address_family_ipv4_cmd
,
1364 "address-family ipv4 [unicast]",
1365 "Enter Address Family command mode\n"
1367 "Address Family Modifier\n")
1369 vty
->node
= BGP_IPV4_NODE
;
1373 DEFUNSH(VTYSH_BGPD
, address_family_flowspecv4
, address_family_flowspecv4_cmd
,
1374 "address-family ipv4 flowspec",
1375 "Enter Address Family command mode\n"
1377 "Address Family Modifier\n")
1379 vty
->node
= BGP_FLOWSPECV4_NODE
;
1383 DEFUNSH(VTYSH_BGPD
, address_family_flowspecv6
, address_family_flowspecv6_cmd
,
1384 "address-family ipv6 flowspec",
1385 "Enter Address Family command mode\n"
1387 "Address Family Modifier\n")
1389 vty
->node
= BGP_FLOWSPECV6_NODE
;
1393 DEFUNSH(VTYSH_BGPD
, address_family_ipv4_multicast
,
1394 address_family_ipv4_multicast_cmd
, "address-family ipv4 multicast",
1395 "Enter Address Family command mode\n"
1397 "Address Family modifier\n")
1399 vty
->node
= BGP_IPV4M_NODE
;
1403 DEFUNSH(VTYSH_BGPD
, address_family_ipv4_vpn
, address_family_ipv4_vpn_cmd
,
1404 "address-family ipv4 vpn",
1405 "Enter Address Family command mode\n"
1407 "Address Family modifier\n")
1409 vty
->node
= BGP_VPNV4_NODE
;
1413 DEFUNSH(VTYSH_BGPD
, address_family_ipv4_labeled_unicast
,
1414 address_family_ipv4_labeled_unicast_cmd
,
1415 "address-family ipv4 labeled-unicast",
1416 "Enter Address Family command mode\n"
1418 "Address Family modifier\n")
1420 vty
->node
= BGP_IPV4L_NODE
;
1424 DEFUNSH(VTYSH_BGPD
, address_family_ipv6
, address_family_ipv6_cmd
,
1425 "address-family ipv6 [unicast]",
1426 "Enter Address Family command mode\n"
1428 "Address Family modifier\n")
1430 vty
->node
= BGP_IPV6_NODE
;
1434 DEFUNSH(VTYSH_BGPD
, address_family_ipv6_multicast
,
1435 address_family_ipv6_multicast_cmd
, "address-family ipv6 multicast",
1436 "Enter Address Family command mode\n"
1438 "Address Family modifier\n")
1440 vty
->node
= BGP_IPV6M_NODE
;
1444 DEFUNSH(VTYSH_BGPD
, address_family_ipv6_vpn
, address_family_ipv6_vpn_cmd
,
1445 "address-family ipv6 vpn",
1446 "Enter Address Family command mode\n"
1448 "Address Family modifier\n")
1450 vty
->node
= BGP_VPNV6_NODE
;
1454 DEFUNSH(VTYSH_BGPD
, address_family_ipv6_labeled_unicast
,
1455 address_family_ipv6_labeled_unicast_cmd
,
1456 "address-family ipv6 labeled-unicast",
1457 "Enter Address Family command mode\n"
1459 "Address Family modifier\n")
1461 vty
->node
= BGP_IPV6L_NODE
;
1469 "Enable rpki and enter rpki configuration mode\n")
1471 vty
->node
= RPKI_NODE
;
1475 DEFUNSH(VTYSH_BGPD
, address_family_evpn
, address_family_evpn_cmd
,
1476 "address-family <l2vpn evpn>",
1477 "Enter Address Family command mode\n"
1479 "Address Family modifier\n")
1481 vty
->node
= BGP_EVPN_NODE
;
1485 #if defined(HAVE_CUMULUS)
1486 DEFUNSH_HIDDEN(VTYSH_BGPD
, address_family_evpn2
, address_family_evpn2_cmd
,
1487 "address-family evpn",
1488 "Enter Address Family command mode\n"
1489 "EVPN Address family\n")
1491 vty
->node
= BGP_EVPN_NODE
;
1496 DEFUNSH(VTYSH_BGPD
, bgp_evpn_vni
, bgp_evpn_vni_cmd
, "vni " CMD_VNI_RANGE
,
1497 "VXLAN Network Identifier\n"
1500 vty
->node
= BGP_EVPN_VNI_NODE
;
1504 #if defined(ENABLE_BGP_VNC)
1505 DEFUNSH(VTYSH_BGPD
, vnc_defaults
, vnc_defaults_cmd
, "vnc defaults",
1506 "VNC/RFP related configuration\n"
1507 "Configure default NVE group\n")
1509 vty
->node
= BGP_VNC_DEFAULTS_NODE
;
1513 DEFUNSH(VTYSH_BGPD
, vnc_nve_group
, vnc_nve_group_cmd
, "vnc nve-group NAME",
1514 "VNC/RFP related configuration\n"
1515 "Configure a NVE group\n"
1518 vty
->node
= BGP_VNC_NVE_GROUP_NODE
;
1522 DEFUNSH(VTYSH_BGPD
, vnc_vrf_policy
, vnc_vrf_policy_cmd
, "vrf-policy NAME",
1523 "Configure a VRF policy group\n"
1526 vty
->node
= BGP_VRF_POLICY_NODE
;
1530 DEFUNSH(VTYSH_BGPD
, vnc_l2_group
, vnc_l2_group_cmd
, "vnc l2-group NAME",
1531 "VNC/RFP related configuration\n"
1532 "Configure a L2 group\n"
1535 vty
->node
= BGP_VNC_L2_GROUP_NODE
;
1540 DEFUNSH(VTYSH_KEYS
, key_chain
, key_chain_cmd
, "key chain WORD",
1541 "Authentication key management\n"
1542 "Key-chain management\n"
1545 vty
->node
= KEYCHAIN_NODE
;
1549 DEFUNSH(VTYSH_KEYS
, key
, key_cmd
, "key (0-2147483647)",
1551 "Key identifier number\n")
1553 vty
->node
= KEYCHAIN_KEY_NODE
;
1557 DEFUNSH(VTYSH_RIPD
, router_rip
, router_rip_cmd
, "router rip [vrf NAME]",
1558 ROUTER_STR
"RIP\n" VRF_CMD_HELP_STR
)
1560 vty
->node
= RIP_NODE
;
1564 DEFUNSH(VTYSH_RIPNGD
, router_ripng
, router_ripng_cmd
, "router ripng [vrf NAME]",
1565 ROUTER_STR
"RIPng\n" VRF_CMD_HELP_STR
)
1567 vty
->node
= RIPNG_NODE
;
1571 DEFUNSH(VTYSH_OSPFD
, router_ospf
, router_ospf_cmd
,
1572 "router ospf [(1-65535)] [vrf NAME]",
1573 "Enable a routing process\n"
1574 "Start OSPF configuration\n"
1578 vty
->node
= OSPF_NODE
;
1582 DEFUNSH(VTYSH_EIGRPD
, router_eigrp
, router_eigrp_cmd
, "router eigrp (1-65535)",
1583 "Enable a routing process\n"
1584 "Start EIGRP configuration\n"
1585 "AS number to use\n")
1587 vty
->node
= EIGRP_NODE
;
1591 DEFUNSH(VTYSH_BABELD
, router_babel
, router_babel_cmd
, "router babel",
1592 "Enable a routing process\n"
1593 "Make Babel instance command\n")
1595 vty
->node
= BABEL_NODE
;
1599 DEFUNSH(VTYSH_OSPF6D
, router_ospf6
, router_ospf6_cmd
, "router ospf6",
1600 ROUTER_STR OSPF6_STR
)
1602 vty
->node
= OSPF6_NODE
;
1606 #if defined(HAVE_LDPD)
1607 DEFUNSH(VTYSH_LDPD
, ldp_mpls_ldp
, ldp_mpls_ldp_cmd
, "mpls ldp",
1608 "Global MPLS configuration subcommands\n"
1609 "Label Distribution Protocol\n")
1611 vty
->node
= LDP_NODE
;
1615 DEFUNSH(VTYSH_LDPD
, ldp_address_family_ipv4
, ldp_address_family_ipv4_cmd
,
1616 "address-family ipv4",
1617 "Configure Address Family and its parameters\n"
1620 vty
->node
= LDP_IPV4_NODE
;
1624 DEFUNSH(VTYSH_LDPD
, ldp_address_family_ipv6
, ldp_address_family_ipv6_cmd
,
1625 "address-family ipv6",
1626 "Configure Address Family and its parameters\n"
1629 vty
->node
= LDP_IPV6_NODE
;
1633 DEFUNSH(VTYSH_LDPD
, ldp_exit_address_family
, ldp_exit_address_family_cmd
,
1634 "exit-address-family", "Exit from Address Family configuration mode\n")
1636 if (vty
->node
== LDP_IPV4_NODE
|| vty
->node
== LDP_IPV6_NODE
)
1637 vty
->node
= LDP_NODE
;
1641 DEFUNSH(VTYSH_LDPD
, ldp_interface_ifname
, ldp_interface_ifname_cmd
,
1643 "Enable LDP on an interface and enter interface submode\n"
1644 "Interface's name\n")
1646 switch (vty
->node
) {
1648 vty
->node
= LDP_IPV4_IFACE_NODE
;
1651 vty
->node
= LDP_IPV6_IFACE_NODE
;
1660 DEFUNSH(VTYSH_LDPD
, ldp_l2vpn_word_type_vpls
, ldp_l2vpn_word_type_vpls_cmd
,
1661 "l2vpn WORD type vpls",
1662 "Configure l2vpn commands\n"
1665 "Virtual Private LAN Service\n")
1667 vty
->node
= LDP_L2VPN_NODE
;
1671 DEFUNSH(VTYSH_LDPD
, ldp_member_pseudowire_ifname
,
1672 ldp_member_pseudowire_ifname_cmd
, "member pseudowire IFNAME",
1673 "L2VPN member configuration\n"
1674 "Pseudowire interface\n"
1675 "Interface's name\n")
1677 vty
->node
= LDP_PSEUDOWIRE_NODE
;
1682 DEFUNSH(VTYSH_ISISD
, router_isis
, router_isis_cmd
, "router isis WORD",
1685 "ISO Routing area tag\n")
1687 vty
->node
= ISIS_NODE
;
1691 DEFUNSH(VTYSH_FABRICD
, router_openfabric
, router_openfabric_cmd
, "router openfabric WORD",
1693 "OpenFabric routing protocol\n"
1694 "ISO Routing area tag\n")
1696 vty
->node
= OPENFABRIC_NODE
;
1700 DEFUNSH(VTYSH_RMAP
, vtysh_route_map
, vtysh_route_map_cmd
,
1701 "route-map WORD <deny|permit> (1-65535)",
1702 "Create route-map or enter route-map command mode\n"
1704 "Route map denies set operations\n"
1705 "Route map permits set operations\n"
1706 "Sequence to insert to/delete from existing route-map entry\n")
1708 vty
->node
= RMAP_NODE
;
1712 DEFUNSH(VTYSH_PBRD
, vtysh_pbr_map
, vtysh_pbr_map_cmd
,
1713 "pbr-map PBRMAP seq (1-700)",
1714 "Create pbr-map or enter pbr-map command mode\n"
1715 "The name of the PBR MAP\n"
1716 "Sequence to insert to/delete from existing pbr-map entry\n"
1717 "Sequence number\n")
1719 vty
->node
= PBRMAP_NODE
;
1724 DEFUNSH(VTYSH_BFDD
, bfd_enter
, bfd_enter_cmd
, "bfd", "Configure BFD peers\n")
1726 vty
->node
= BFD_NODE
;
1730 DEFUNSH(VTYSH_BFDD
, bfd_peer_enter
, bfd_peer_enter_cmd
,
1731 "peer <A.B.C.D|X:X::X:X> [{multihop|local-address <A.B.C.D|X:X::X:X>|interface IFNAME|vrf NAME}]",
1733 "IPv4 peer address\n"
1734 "IPv6 peer address\n"
1735 "Configure multihop\n"
1736 "Configure local address\n"
1737 "IPv4 local address\n"
1738 "IPv6 local address\n"
1740 "Configure interface name to use\n"
1742 "Configure VRF name\n")
1744 vty
->node
= BFD_PEER_NODE
;
1747 #endif /* HAVE_BFDD */
1749 DEFSH(VTYSH_PBRD
, vtysh_no_pbr_map_cmd
, "no pbr-map PBRMAP [seq (1-700)]",
1752 "The name of the PBR MAP\n"
1753 "Sequence to delete from existing pbr-map entry\n"
1754 "Sequence number\n")
1756 DEFUNSH(VTYSH_ALL
, vtysh_line_vty
, vtysh_line_vty_cmd
, "line vty",
1757 "Configure a terminal line\n"
1758 "Virtual terminal\n")
1760 vty
->node
= VTY_NODE
;
1764 DEFUNSH(VTYSH_REALLYALL
, vtysh_enable
, vtysh_enable_cmd
, "enable",
1765 "Turn on privileged mode command\n")
1767 vty
->node
= ENABLE_NODE
;
1771 DEFUNSH(VTYSH_REALLYALL
, vtysh_disable
, vtysh_disable_cmd
, "disable",
1772 "Turn off privileged mode command\n")
1774 if (vty
->node
== ENABLE_NODE
)
1775 vty
->node
= VIEW_NODE
;
1779 DEFUNSH(VTYSH_REALLYALL
, vtysh_config_terminal
, vtysh_config_terminal_cmd
,
1780 "configure [terminal]",
1781 "Configuration from vty interface\n"
1782 "Configuration terminal\n")
1784 vty
->node
= CONFIG_NODE
;
1788 static int vtysh_exit(struct vty
*vty
)
1790 switch (vty
->node
) {
1796 vty
->node
= ENABLE_NODE
;
1798 case INTERFACE_NODE
:
1800 case LOGICALROUTER_NODE
:
1812 case LDP_L2VPN_NODE
:
1814 case OPENFABRIC_NODE
:
1821 vtysh_execute("end");
1822 vtysh_execute("configure");
1823 vty
->node
= CONFIG_NODE
;
1825 case BGP_VPNV4_NODE
:
1826 case BGP_VPNV6_NODE
:
1828 case BGP_IPV4M_NODE
:
1829 case BGP_IPV4L_NODE
:
1831 case BGP_IPV6M_NODE
:
1832 case BGP_IPV6L_NODE
:
1833 case BGP_FLOWSPECV4_NODE
:
1834 case BGP_FLOWSPECV6_NODE
:
1835 case BGP_VRF_POLICY_NODE
:
1837 case BGP_VNC_DEFAULTS_NODE
:
1838 case BGP_VNC_NVE_GROUP_NODE
:
1839 case BGP_VNC_L2_GROUP_NODE
:
1840 vty
->node
= BGP_NODE
;
1842 case BGP_EVPN_VNI_NODE
:
1843 vty
->node
= BGP_EVPN_NODE
;
1847 vty
->node
= LDP_NODE
;
1849 case LDP_IPV4_IFACE_NODE
:
1850 vty
->node
= LDP_IPV4_NODE
;
1852 case LDP_IPV6_IFACE_NODE
:
1853 vty
->node
= LDP_IPV6_NODE
;
1855 case LDP_PSEUDOWIRE_NODE
:
1856 vty
->node
= LDP_L2VPN_NODE
;
1858 case KEYCHAIN_KEY_NODE
:
1859 vty
->node
= KEYCHAIN_NODE
;
1861 case LINK_PARAMS_NODE
:
1862 vty
->node
= INTERFACE_NODE
;
1865 vty
->node
= BFD_NODE
;
1873 DEFUNSH(VTYSH_REALLYALL
, vtysh_exit_all
, vtysh_exit_all_cmd
, "exit",
1874 "Exit current mode and down to previous mode\n")
1876 return vtysh_exit(vty
);
1879 DEFUNSH(VTYSH_ALL
, vtysh_quit_all
, vtysh_quit_all_cmd
, "quit",
1880 "Exit current mode and down to previous mode\n")
1882 return vtysh_exit_all(self
, vty
, argc
, argv
);
1885 DEFUNSH(VTYSH_BGPD
, exit_address_family
, exit_address_family_cmd
,
1886 "exit-address-family", "Exit from Address Family configuration mode\n")
1888 if (vty
->node
== BGP_IPV4_NODE
|| vty
->node
== BGP_IPV4M_NODE
1889 || vty
->node
== BGP_IPV4L_NODE
|| vty
->node
== BGP_VPNV4_NODE
1890 || vty
->node
== BGP_VPNV6_NODE
|| vty
->node
== BGP_IPV6_NODE
1891 || vty
->node
== BGP_IPV6L_NODE
|| vty
->node
== BGP_IPV6M_NODE
1892 || vty
->node
== BGP_EVPN_NODE
1893 || vty
->node
== BGP_FLOWSPECV4_NODE
1894 || vty
->node
== BGP_FLOWSPECV6_NODE
)
1895 vty
->node
= BGP_NODE
;
1899 DEFUNSH(VTYSH_BGPD
, exit_vni
, exit_vni_cmd
, "exit-vni", "Exit from VNI mode\n")
1901 if (vty
->node
== BGP_EVPN_VNI_NODE
)
1902 vty
->node
= BGP_EVPN_NODE
;
1906 DEFUNSH(VTYSH_BGPD
, exit_vnc_config
, exit_vnc_config_cmd
, "exit-vnc",
1907 "Exit from VNC configuration mode\n")
1909 if (vty
->node
== BGP_VNC_DEFAULTS_NODE
1910 || vty
->node
== BGP_VNC_NVE_GROUP_NODE
1911 || vty
->node
== BGP_VNC_L2_GROUP_NODE
)
1912 vty
->node
= BGP_NODE
;
1917 DEFUNSH(VTYSH_BGPD
, rpki_exit
, rpki_exit_cmd
, "exit",
1918 "Exit current mode and down to previous mode\n")
1924 DEFUNSH(VTYSH_BGPD
, rpki_quit
, rpki_quit_cmd
, "quit",
1925 "Exit current mode and down to previous mode\n")
1927 return rpki_exit(self
, vty
, argc
, argv
);
1930 DEFUNSH(VTYSH_PIMD
|VTYSH_ZEBRA
, exit_vrf_config
, exit_vrf_config_cmd
, "exit-vrf",
1931 "Exit from VRF configuration mode\n")
1933 if (vty
->node
== VRF_NODE
)
1934 vty
->node
= CONFIG_NODE
;
1938 DEFUNSH(VTYSH_BGPD
, exit_vrf_policy
, exit_vrf_policy_cmd
, "exit-vrf-policy",
1939 "Exit from VRF policy configuration mode\n")
1941 if (vty
->node
== BGP_VRF_POLICY_NODE
)
1942 vty
->node
= BGP_NODE
;
1946 DEFUNSH(VTYSH_RIPD
, vtysh_exit_ripd
, vtysh_exit_ripd_cmd
, "exit",
1947 "Exit current mode and down to previous mode\n")
1949 return vtysh_exit(vty
);
1952 DEFUNSH(VTYSH_RIPD
, vtysh_quit_ripd
, vtysh_quit_ripd_cmd
, "quit",
1953 "Exit current mode and down to previous mode\n")
1955 return vtysh_exit_ripd(self
, vty
, argc
, argv
);
1958 DEFUNSH(VTYSH_RIPNGD
, vtysh_exit_ripngd
, vtysh_exit_ripngd_cmd
, "exit",
1959 "Exit current mode and down to previous mode\n")
1961 return vtysh_exit(vty
);
1964 DEFUNSH(VTYSH_RIPNGD
, vtysh_quit_ripngd
, vtysh_quit_ripngd_cmd
, "quit",
1965 "Exit current mode and down to previous mode\n")
1967 return vtysh_exit_ripngd(self
, vty
, argc
, argv
);
1970 DEFUNSH(VTYSH_RMAP
, vtysh_exit_rmap
, vtysh_exit_rmap_cmd
, "exit",
1971 "Exit current mode and down to previous mode\n")
1973 return vtysh_exit(vty
);
1976 DEFUNSH(VTYSH_RMAP
, vtysh_quit_rmap
, vtysh_quit_rmap_cmd
, "quit",
1977 "Exit current mode and down to previous mode\n")
1979 return vtysh_exit_rmap(self
, vty
, argc
, argv
);
1982 DEFUNSH(VTYSH_PBRD
, vtysh_exit_pbr_map
, vtysh_exit_pbr_map_cmd
, "exit",
1983 "Exit current mode and down to previous mode\n")
1985 return vtysh_exit(vty
);
1988 DEFUNSH(VTYSH_PBRD
, vtysh_quit_pbr_map
, vtysh_quit_pbr_map_cmd
, "quit",
1989 "Exit current mode and down to previous mode\n")
1991 return vtysh_exit_rmap(self
, vty
, argc
, argv
);
1994 DEFUNSH(VTYSH_BGPD
, vtysh_exit_bgpd
, vtysh_exit_bgpd_cmd
, "exit",
1995 "Exit current mode and down to previous mode\n")
1997 return vtysh_exit(vty
);
2000 DEFUNSH(VTYSH_BGPD
, vtysh_quit_bgpd
, vtysh_quit_bgpd_cmd
, "quit",
2001 "Exit current mode and down to previous mode\n")
2003 return vtysh_exit_bgpd(self
, vty
, argc
, argv
);
2006 DEFUNSH(VTYSH_OSPFD
, vtysh_exit_ospfd
, vtysh_exit_ospfd_cmd
, "exit",
2007 "Exit current mode and down to previous mode\n")
2009 return vtysh_exit(vty
);
2012 DEFUNSH(VTYSH_OSPFD
, vtysh_quit_ospfd
, vtysh_quit_ospfd_cmd
, "quit",
2013 "Exit current mode and down to previous mode\n")
2015 return vtysh_exit_ospfd(self
, vty
, argc
, argv
);
2018 DEFUNSH(VTYSH_EIGRPD
, vtysh_exit_eigrpd
, vtysh_exit_eigrpd_cmd
, "exit",
2019 "Exit current mode and down to previous mode\n")
2021 return vtysh_exit(vty
);
2024 DEFUNSH(VTYSH_EIGRPD
, vtysh_quit_eigrpd
, vtysh_quit_eigrpd_cmd
, "quit",
2025 "Exit current mode and down to previous mode\n")
2027 return vtysh_exit(vty
);
2030 DEFUNSH(VTYSH_EIGRPD
, vtysh_exit_babeld
, vtysh_exit_babeld_cmd
, "exit",
2031 "Exit current mode and down to previous mode\n")
2033 return vtysh_exit(vty
);
2036 DEFUNSH(VTYSH_BABELD
, vtysh_quit_babeld
, vtysh_quit_babeld_cmd
, "quit",
2037 "Exit current mode and down to previous mode\n")
2039 return vtysh_exit(vty
);
2042 DEFUNSH(VTYSH_OSPF6D
, vtysh_exit_ospf6d
, vtysh_exit_ospf6d_cmd
, "exit",
2043 "Exit current mode and down to previous mode\n")
2045 return vtysh_exit(vty
);
2048 DEFUNSH(VTYSH_OSPF6D
, vtysh_quit_ospf6d
, vtysh_quit_ospf6d_cmd
, "quit",
2049 "Exit current mode and down to previous mode\n")
2051 return vtysh_exit_ospf6d(self
, vty
, argc
, argv
);
2054 #if defined(HAVE_LDPD)
2055 DEFUNSH(VTYSH_LDPD
, vtysh_exit_ldpd
, vtysh_exit_ldpd_cmd
, "exit",
2056 "Exit current mode and down to previous mode\n")
2058 return vtysh_exit(vty
);
2061 ALIAS(vtysh_exit_ldpd
, vtysh_quit_ldpd_cmd
, "quit",
2062 "Exit current mode and down to previous mode\n")
2065 DEFUNSH(VTYSH_ISISD
, vtysh_exit_isisd
, vtysh_exit_isisd_cmd
, "exit",
2066 "Exit current mode and down to previous mode\n")
2068 return vtysh_exit(vty
);
2071 DEFUNSH(VTYSH_ISISD
, vtysh_quit_isisd
, vtysh_quit_isisd_cmd
, "quit",
2072 "Exit current mode and down to previous mode\n")
2074 return vtysh_exit_isisd(self
, vty
, argc
, argv
);
2078 DEFUNSH(VTYSH_BFDD
, vtysh_exit_bfdd
, vtysh_exit_bfdd_cmd
, "exit",
2079 "Exit current mode and down to previous mode\n")
2081 return vtysh_exit(vty
);
2084 ALIAS(vtysh_exit_bfdd
, vtysh_quit_bfdd_cmd
, "quit",
2085 "Exit current mode and down to previous mode\n")
2088 DEFUNSH(VTYSH_FABRICD
, vtysh_exit_fabricd
, vtysh_exit_fabricd_cmd
, "exit",
2089 "Exit current mode and down to previous mode\n")
2091 return vtysh_exit(vty
);
2094 DEFUNSH(VTYSH_FABRICD
, vtysh_quit_fabricd
, vtysh_quit_fabricd_cmd
, "quit",
2095 "Exit current mode and down to previous mode\n")
2097 return vtysh_exit_fabricd(self
, vty
, argc
, argv
);
2100 DEFUNSH(VTYSH_ALL
, vtysh_exit_line_vty
, vtysh_exit_line_vty_cmd
, "exit",
2101 "Exit current mode and down to previous mode\n")
2103 return vtysh_exit(vty
);
2106 DEFUNSH(VTYSH_ALL
, vtysh_quit_line_vty
, vtysh_quit_line_vty_cmd
, "quit",
2107 "Exit current mode and down to previous mode\n")
2109 return vtysh_exit_line_vty(self
, vty
, argc
, argv
);
2112 DEFUNSH(VTYSH_INTERFACE
, vtysh_interface
, vtysh_interface_cmd
,
2113 "interface IFNAME [vrf NAME]",
2114 "Select an interface to configure\n"
2115 "Interface's name\n" VRF_CMD_HELP_STR
)
2117 vty
->node
= INTERFACE_NODE
;
2121 DEFUNSH(VTYSH_ZEBRA
, vtysh_pseudowire
, vtysh_pseudowire_cmd
,
2122 "pseudowire IFNAME",
2123 "Static pseudowire configuration\n"
2124 "Pseudowire name\n")
2126 vty
->node
= PW_NODE
;
2130 DEFUNSH(VTYSH_ZEBRA
, vtysh_logicalrouter
, vtysh_logicalrouter_cmd
,
2131 "logical-router (1-65535) ns NAME",
2132 "Enable a logical-router\n"
2133 "Specify the logical-router indentifier\n"
2135 "The file name in " NS_RUN_DIR
", or a full pathname\n")
2137 vty
->node
= LOGICALROUTER_NODE
;
2141 DEFSH(VTYSH_ZEBRA
, vtysh_no_logicalrouter_cmd
,
2142 "no logical-router (1-65535) ns NAME", NO_STR
2143 "Enable a Logical-Router\n"
2144 "Specify the Logical-Router identifier\n"
2146 "The file name in " NS_RUN_DIR
", or a full pathname\n")
2148 DEFUNSH(VTYSH_PBRD
| VTYSH_SHARPD
, vtysh_nexthop_group
, vtysh_nexthop_group_cmd
,
2149 "nexthop-group NHGNAME",
2150 "Nexthop Group configuration\n"
2151 "Name of the Nexthop Group\n")
2153 vty
->node
= NH_GROUP_NODE
;
2157 DEFSH(VTYSH_PBRD
| VTYSH_SHARPD
, vtysh_no_nexthop_group_cmd
,
2158 "no nexthop-group NHGNAME",
2160 "Nexthop Group Configuration\n"
2161 "Name of the Nexthop Group\n")
2163 DEFUNSH(VTYSH_VRF
, vtysh_vrf
, vtysh_vrf_cmd
, "vrf NAME",
2164 "Select a VRF to configure\n"
2167 vty
->node
= VRF_NODE
;
2171 DEFSH(VTYSH_ZEBRA
, vtysh_vrf_netns_cmd
,
2173 "Attach VRF to a Namespace\n"
2174 "The file name in " NS_RUN_DIR
", or a full pathname\n")
2176 DEFSH(VTYSH_ZEBRA
, vtysh_no_vrf_netns_cmd
,
2179 "Detach VRF from a Namespace\n"
2180 "The file name in " NS_RUN_DIR
", or a full pathname\n")
2182 DEFUNSH(VTYSH_NS
, vtysh_exit_logicalrouter
,
2183 vtysh_exit_logicalrouter_cmd
, "exit",
2184 "Exit current mode and down to previous mode\n")
2186 return vtysh_exit(vty
);
2189 DEFUNSH(VTYSH_NS
, vtysh_quit_logicalrouter
,
2190 vtysh_quit_logicalrouter_cmd
, "quit",
2191 "Exit current mode and down to previous mode\n")
2193 return vtysh_exit_logicalrouter(self
, vty
, argc
, argv
);
2196 DEFUNSH(VTYSH_VRF
, vtysh_exit_vrf
, vtysh_exit_vrf_cmd
, "exit",
2197 "Exit current mode and down to previous mode\n")
2199 return vtysh_exit(vty
);
2202 DEFUNSH(VTYSH_VRF
, vtysh_quit_vrf
, vtysh_quit_vrf_cmd
, "quit",
2203 "Exit current mode and down to previous mode\n")
2205 return vtysh_exit_vrf(self
, vty
, argc
, argv
);
2208 DEFUNSH(VTYSH_PBRD
| VTYSH_SHARPD
, vtysh_exit_nexthop_group
, vtysh_exit_nexthop_group_cmd
,
2209 "exit", "Exit current mode and down to previous mode\n")
2211 return vtysh_exit(vty
);
2214 DEFUNSH(VTYSH_VRF
, vtysh_quit_nexthop_group
, vtysh_quit_nexthop_group_cmd
,
2215 "quit", "Exit current mode and down to previous mode\n")
2217 return vtysh_exit_nexthop_group(self
, vty
, argc
, argv
);
2220 DEFUNSH(VTYSH_INTERFACE
, vtysh_exit_interface
, vtysh_exit_interface_cmd
, "exit",
2221 "Exit current mode and down to previous mode\n")
2223 return vtysh_exit(vty
);
2226 DEFUNSH(VTYSH_INTERFACE
, vtysh_quit_interface
, vtysh_quit_interface_cmd
, "quit",
2227 "Exit current mode and down to previous mode\n")
2229 return vtysh_exit_interface(self
, vty
, argc
, argv
);
2232 DEFUN (vtysh_show_poll
,
2233 vtysh_show_poll_cmd
,
2236 "Thread information\n"
2237 "Thread Poll Information\n")
2240 int ret
= CMD_SUCCESS
;
2243 snprintf(line
, sizeof(line
), "do show thread poll\n");
2244 for (i
= 0; i
< array_size(vtysh_client
); i
++)
2245 if (vtysh_client
[i
].fd
>= 0) {
2246 vty_out(vty
, "Thread statistics for %s:\n",
2247 vtysh_client
[i
].name
);
2248 ret
= vtysh_client_execute(&vtysh_client
[i
], line
);
2254 DEFUN (vtysh_show_thread
,
2255 vtysh_show_thread_cmd
,
2256 "show thread cpu [FILTER]",
2258 "Thread information\n"
2259 "Thread CPU usage\n"
2260 "Display filter (rwtexb)\n")
2264 int ret
= CMD_SUCCESS
;
2267 const char *filter
=
2268 argv_find(argv
, argc
, "FILTER", &idx
) ? argv
[idx
]->arg
: "";
2270 snprintf(line
, sizeof(line
), "do show thread cpu %s\n", filter
);
2271 for (i
= 0; i
< array_size(vtysh_client
); i
++)
2272 if (vtysh_client
[i
].fd
>= 0) {
2273 vty_out(vty
, "Thread statistics for %s:\n",
2274 vtysh_client
[i
].name
);
2275 ret
= vtysh_client_execute(&vtysh_client
[i
], line
);
2281 DEFUN (vtysh_show_work_queues
,
2282 vtysh_show_work_queues_cmd
,
2285 "Work Queue information\n")
2288 int ret
= CMD_SUCCESS
;
2289 char line
[] = "do show work-queues\n";
2291 for (i
= 0; i
< array_size(vtysh_client
); i
++)
2292 if (vtysh_client
[i
].fd
>= 0) {
2293 vty_out(vty
, "Work queue statistics for %s:\n",
2294 vtysh_client
[i
].name
);
2295 ret
= vtysh_client_execute(&vtysh_client
[i
], line
);
2302 DEFUN (vtysh_show_work_queues_daemon
,
2303 vtysh_show_work_queues_daemon_cmd
,
2304 "show work-queues " DAEMONS_LIST
,
2306 "Work Queue information\n"
2309 int idx_protocol
= 2;
2311 return vtysh_client_execute_name(argv
[idx_protocol
]->text
,
2312 "show work-queues\n");
2315 DEFUNSH(VTYSH_ZEBRA
, vtysh_link_params
, vtysh_link_params_cmd
, "link-params",
2318 vty
->node
= LINK_PARAMS_NODE
;
2322 DEFUNSH(VTYSH_ZEBRA
, exit_link_params
, exit_link_params_cmd
, "exit-link-params",
2323 "Exit from Link Params configuration node\n")
2325 if (vty
->node
== LINK_PARAMS_NODE
)
2326 vty
->node
= INTERFACE_NODE
;
2330 static int show_per_daemon(const char *line
, const char *headline
)
2333 int ret
= CMD_SUCCESS
;
2335 for (i
= 0; i
< array_size(vtysh_client
); i
++)
2336 if (vtysh_client
[i
].fd
>= 0) {
2337 vty_out(vty
, headline
, vtysh_client
[i
].name
);
2338 ret
= vtysh_client_execute(&vtysh_client
[i
], line
);
2345 DEFUNSH_HIDDEN (0x00,
2347 vtysh_debug_all_cmd
,
2351 "Toggle all debugs on or off\n")
2356 DEFUN (vtysh_show_debugging
,
2357 vtysh_show_debugging_cmd
,
2362 return show_per_daemon("do show debugging\n", "");
2365 DEFUN (vtysh_show_debugging_hashtable
,
2366 vtysh_show_debugging_hashtable_cmd
,
2367 "show debugging hashtable [statistics]",
2370 "Statistics about hash tables\n"
2371 "Statistics about hash tables\n")
2375 "Load factor (LF) - average number of elements across all buckets\n");
2377 "Full load factor (FLF) - average number of elements across full buckets\n\n");
2379 "Standard deviation (SD) is calculated for both the LF and FLF\n");
2381 "and indicates the typical deviation of bucket chain length\n");
2382 vty_out(vty
, "from the value in the corresponding load factor.\n\n");
2384 return show_per_daemon("do show debugging hashtable\n",
2385 "Hashtable statistics for %s:\n");
2388 DEFUN (vtysh_show_error_code
,
2389 vtysh_show_error_code_cmd
,
2390 "show error <(1-4294967296)|all> [json]",
2392 "Information on errors\n"
2393 "Error code to get info about\n"
2394 "Information on all errors\n"
2397 char *fcmd
= argv_concat(argv
, argc
, 0);
2401 snprintf(cmd
, sizeof(cmd
), "do %s", fcmd
);
2403 /* FIXME: Needs to determine which daemon to send to via code ranges */
2404 rv
= show_per_daemon(cmd
, "");
2406 XFREE(MTYPE_TMP
, fcmd
);
2411 DEFUN (vtysh_show_memory
,
2412 vtysh_show_memory_cmd
,
2415 "Memory statistics\n")
2417 return show_per_daemon("do show memory\n", "Memory statistics for %s:\n");
2420 DEFUN (vtysh_show_modules
,
2421 vtysh_show_modules_cmd
,
2426 return show_per_daemon("do show modules\n",
2427 "Module information for %s:\n");
2430 /* Logging commands. */
2431 DEFUN (vtysh_show_logging
,
2432 vtysh_show_logging_cmd
,
2435 "Show current logging configuration\n")
2437 return show_per_daemon("do show logging\n",
2438 "Logging configuration for %s:\n");
2441 DEFUNSH(VTYSH_ALL
, vtysh_log_stdout
, vtysh_log_stdout_cmd
, "log stdout",
2443 "Set stdout logging level\n")
2448 DEFUNSH(VTYSH_ALL
, vtysh_log_stdout_level
, vtysh_log_stdout_level_cmd
,
2449 "log stdout <emergencies|alerts|critical|errors|warnings|notifications|informational|debugging>",
2451 "Set stdout logging level\n" LOG_LEVEL_DESC
)
2456 DEFUNSH(VTYSH_ALL
, no_vtysh_log_stdout
, no_vtysh_log_stdout_cmd
,
2457 "no log stdout [LEVEL]", NO_STR
2459 "Cancel logging to stdout\n"
2465 DEFUNSH(VTYSH_ALL
, vtysh_log_file
, vtysh_log_file_cmd
, "log file FILENAME",
2468 "Logging filename\n")
2473 DEFUNSH(VTYSH_ALL
, vtysh_log_file_level
, vtysh_log_file_level_cmd
,
2474 "log file FILENAME <emergencies|alerts|critical|errors|warnings|notifications|informational|debugging>",
2477 "Logging filename\n" LOG_LEVEL_DESC
)
2482 DEFUNSH(VTYSH_ALL
, no_vtysh_log_file
, no_vtysh_log_file_cmd
,
2483 "no log file [FILENAME [LEVEL]]", NO_STR
2485 "Cancel logging to file\n"
2486 "Logging file name\n"
2492 DEFUNSH(VTYSH_ALL
, vtysh_log_monitor
, vtysh_log_monitor_cmd
,
2493 "log monitor [<emergencies|alerts|critical|errors|warnings|notifications|informational|debugging>]",
2495 "Set terminal line (monitor) logging level\n" LOG_LEVEL_DESC
)
2500 DEFUNSH(VTYSH_ALL
, no_vtysh_log_monitor
, no_vtysh_log_monitor_cmd
,
2501 "no log monitor [LEVEL]", NO_STR
2503 "Disable terminal line (monitor) logging\n"
2509 DEFUNSH(VTYSH_ALL
, vtysh_log_syslog
, vtysh_log_syslog_cmd
,
2510 "log syslog [<emergencies|alerts|critical|errors|warnings|notifications|informational|debugging>]",
2512 "Set syslog logging level\n" LOG_LEVEL_DESC
)
2517 DEFUNSH(VTYSH_ALL
, no_vtysh_log_syslog
, no_vtysh_log_syslog_cmd
,
2518 "no log syslog [<emergencies|alerts|critical|errors|warnings|notifications|informational|debugging>]",
2521 "Cancel logging to syslog\n"
2527 DEFUNSH(VTYSH_ALL
, vtysh_log_facility
, vtysh_log_facility_cmd
,
2528 "log facility <kern|user|mail|daemon|auth|syslog|lpr|news|uucp|cron|local0|local1|local2|local3|local4|local5|local6|local7>",
2530 "Facility parameter for syslog messages\n" LOG_FACILITY_DESC
)
2535 DEFUNSH(VTYSH_ALL
, no_vtysh_log_facility
, no_vtysh_log_facility_cmd
,
2536 "no log facility [FACILITY]", NO_STR
2538 "Reset syslog facility to default (daemon)\n"
2539 "Syslog facility\n")
2544 DEFUNSH(VTYSH_ALL
, vtysh_log_record_priority
, vtysh_log_record_priority_cmd
,
2545 "log record-priority",
2547 "Log the priority of the message within the message\n")
2552 DEFUNSH(VTYSH_ALL
, no_vtysh_log_record_priority
,
2553 no_vtysh_log_record_priority_cmd
, "no log record-priority", NO_STR
2555 "Do not log the priority of the message within the message\n")
2560 DEFUNSH(VTYSH_ALL
, vtysh_log_timestamp_precision
,
2561 vtysh_log_timestamp_precision_cmd
, "log timestamp precision (0-6)",
2563 "Timestamp configuration\n"
2564 "Set the timestamp precision\n"
2565 "Number of subsecond digits\n")
2570 DEFUNSH(VTYSH_ALL
, vtysh_debug_memstats
,
2571 vtysh_debug_memstats_cmd
, "[no] debug memstats-at-exit",
2574 "Print memory statistics at exit\n")
2579 DEFUNSH(VTYSH_ALL
, no_vtysh_log_timestamp_precision
,
2580 no_vtysh_log_timestamp_precision_cmd
, "no log timestamp precision",
2583 "Timestamp configuration\n"
2584 "Reset the timestamp precision to the default value of 0\n")
2589 DEFUNSH(VTYSH_ALL
, vtysh_service_password_encrypt
,
2590 vtysh_service_password_encrypt_cmd
, "service password-encryption",
2591 "Set up miscellaneous service\n"
2592 "Enable encrypted passwords\n")
2597 DEFUNSH(VTYSH_ALL
, no_vtysh_service_password_encrypt
,
2598 no_vtysh_service_password_encrypt_cmd
, "no service password-encryption",
2600 "Set up miscellaneous service\n"
2601 "Enable encrypted passwords\n")
2606 DEFUNSH(VTYSH_ALL
, vtysh_config_password
, vtysh_password_cmd
,
2607 "password [(8-8)] LINE",
2608 "Modify the terminal connection password\n"
2609 "Specifies a HIDDEN password will follow\n"
2610 "The password string\n")
2615 DEFUNSH(VTYSH_ALL
, no_vtysh_config_password
, no_vtysh_password_cmd
,
2616 "no password", NO_STR
2617 "Modify the terminal connection password\n")
2619 vty_out(vty
, NO_PASSWD_CMD_WARNING
);
2624 DEFUNSH(VTYSH_ALL
, vtysh_config_enable_password
, vtysh_enable_password_cmd
,
2625 "enable password [(8-8)] LINE",
2626 "Modify enable password parameters\n"
2627 "Assign the privileged level password\n"
2628 "Specifies a HIDDEN password will follow\n"
2629 "The 'enable' password string\n")
2634 DEFUNSH(VTYSH_ALL
, no_vtysh_config_enable_password
,
2635 no_vtysh_enable_password_cmd
, "no enable password", NO_STR
2636 "Modify enable password parameters\n"
2637 "Assign the privileged level password\n")
2639 vty_out(vty
, NO_PASSWD_CMD_WARNING
);
2644 DEFUN (vtysh_write_terminal
,
2645 vtysh_write_terminal_cmd
,
2646 "write terminal ["DAEMONS_LIST
"]",
2647 "Write running configuration to memory, network, or terminal\n"
2648 "Write to terminal\n"
2652 char line
[] = "do write terminal\n";
2654 vty_out(vty
, "Building configuration...\n");
2655 vty_out(vty
, "\nCurrent configuration:\n");
2656 vty_out(vty
, "!\n");
2658 for (i
= 0; i
< array_size(vtysh_client
); i
++)
2660 || (strmatch(vtysh_client
[i
].name
, argv
[2]->text
)))
2661 vtysh_client_config(&vtysh_client
[i
], line
);
2663 /* Integrate vtysh specific configuration. */
2664 vty_open_pager(vty
);
2665 vtysh_config_write();
2666 vtysh_config_dump();
2667 vty_close_pager(vty
);
2668 vty_out(vty
, "end\n");
2673 DEFUN (vtysh_show_running_config
,
2674 vtysh_show_running_config_cmd
,
2675 "show running-config ["DAEMONS_LIST
"]",
2677 "Current operating configuration\n"
2680 return vtysh_write_terminal(self
, vty
, argc
, argv
);
2683 DEFUN (vtysh_integrated_config
,
2684 vtysh_integrated_config_cmd
,
2685 "service integrated-vtysh-config",
2686 "Set up miscellaneous service\n"
2687 "Write configuration into integrated file\n")
2689 vtysh_write_integrated
= WRITE_INTEGRATED_YES
;
2693 DEFUN (no_vtysh_integrated_config
,
2694 no_vtysh_integrated_config_cmd
,
2695 "no service integrated-vtysh-config",
2697 "Set up miscellaneous service\n"
2698 "Write configuration into integrated file\n")
2700 vtysh_write_integrated
= WRITE_INTEGRATED_NO
;
2704 static void backup_config_file(const char *fbackup
)
2706 char *integrate_sav
= NULL
;
2708 size_t integrate_sav_sz
= strlen(fbackup
) + strlen(CONF_BACKUP_EXT
) + 1;
2709 integrate_sav
= malloc(integrate_sav_sz
);
2710 strlcpy(integrate_sav
, fbackup
, integrate_sav_sz
);
2711 strlcat(integrate_sav
, CONF_BACKUP_EXT
, integrate_sav_sz
);
2713 /* Move current configuration file to backup config file. */
2714 if (unlink(integrate_sav
) != 0) {
2715 vty_out(vty
, "Warning: %s unlink failed\n", integrate_sav
);
2717 if (rename(fbackup
, integrate_sav
) != 0) {
2718 vty_out(vty
, "Error renaming %s to %s\n", fbackup
,
2721 free(integrate_sav
);
2724 int vtysh_write_config_integrated(void)
2727 char line
[] = "do write terminal\n";
2731 struct passwd
*pwentry
;
2734 struct group
*grentry
;
2741 vty_out(vty
, "Building Configuration...\n");
2743 backup_config_file(frr_config
);
2744 fp
= fopen(frr_config
, "w");
2747 "%% Error: failed to open configuration file %s: %s\n",
2748 frr_config
, safe_strerror(errno
));
2749 return CMD_WARNING_CONFIG_FAILED
;
2753 for (i
= 0; i
< array_size(vtysh_client
); i
++)
2754 vtysh_client_config(&vtysh_client
[i
], line
);
2756 vtysh_config_write();
2757 vty
->of_saved
= vty
->of
;
2759 vtysh_config_dump();
2760 vty
->of
= vty
->of_saved
;
2762 if (fchmod(fd
, CONFIGFILE_MASK
) != 0) {
2763 printf("%% Warning: can't chmod configuration file %s: %s\n",
2764 frr_config
, safe_strerror(errno
));
2769 pwentry
= getpwnam(FRR_USER
);
2771 uid
= pwentry
->pw_uid
;
2773 printf("%% Warning: could not look up user \"%s\"\n", FRR_USER
);
2778 grentry
= getgrnam(FRR_GROUP
);
2780 gid
= grentry
->gr_gid
;
2782 printf("%% Warning: could not look up group \"%s\"\n",
2788 if (!fstat(fd
, &st
)) {
2789 if (st
.st_uid
== uid
)
2791 if (st
.st_gid
== gid
)
2793 if ((uid
!= (uid_t
)-1 || gid
!= (gid_t
)-1)
2794 && fchown(fd
, uid
, gid
)) {
2795 printf("%% Warning: can't chown configuration file %s: %s\n",
2796 frr_config
, safe_strerror(errno
));
2800 printf("%% Warning: stat() failed on %s: %s\n", frr_config
,
2801 safe_strerror(errno
));
2807 printf("Integrated configuration saved to %s\n", frr_config
);
2815 static bool want_config_integrated(void)
2819 switch (vtysh_write_integrated
) {
2820 case WRITE_INTEGRATED_UNSPECIFIED
:
2821 if (stat(frr_config
, &s
) && errno
== ENOENT
)
2824 case WRITE_INTEGRATED_NO
:
2826 case WRITE_INTEGRATED_YES
:
2832 DEFUN (vtysh_write_memory
,
2833 vtysh_write_memory_cmd
,
2834 "write [<memory|file>]",
2835 "Write running configuration to memory, network, or terminal\n"
2836 "Write configuration to the file (same as write file)\n"
2837 "Write configuration to the file (same as write memory)\n")
2839 int ret
= CMD_SUCCESS
;
2840 char line
[] = "do write memory\n";
2843 vty_out(vty
, "Note: this version of vtysh never writes vtysh.conf\n");
2845 /* If integrated frr.conf explicitely set. */
2846 if (want_config_integrated()) {
2847 ret
= CMD_WARNING_CONFIG_FAILED
;
2849 /* first attempt to use watchfrr if it's available */
2850 bool used_watchfrr
= false;
2852 for (i
= 0; i
< array_size(vtysh_client
); i
++)
2853 if (vtysh_client
[i
].flag
== VTYSH_WATCHFRR
)
2855 if (i
< array_size(vtysh_client
) && vtysh_client
[i
].fd
!= -1) {
2856 used_watchfrr
= true;
2857 ret
= vtysh_client_execute(&vtysh_client
[i
],
2858 "do write integrated");
2862 * If we didn't use watchfrr, fallback to writing the config
2865 if (!used_watchfrr
) {
2866 printf("\nWarning: attempting direct configuration write without "
2867 "watchfrr.\nFile permissions and ownership may be "
2868 "incorrect, or write may fail.\n\n");
2869 ret
= vtysh_write_config_integrated();
2874 vty_out(vty
, "Building Configuration...\n");
2876 for (i
= 0; i
< array_size(vtysh_client
); i
++)
2877 ret
= vtysh_client_execute(&vtysh_client
[i
], line
);
2882 DEFUN (vtysh_copy_running_config
,
2883 vtysh_copy_running_config_cmd
,
2884 "copy running-config startup-config",
2885 "Copy from one file to another\n"
2886 "Copy from current system configuration\n"
2887 "Copy to startup configuration\n")
2889 return vtysh_write_memory(self
, vty
, argc
, argv
);
2892 DEFUN (vtysh_terminal_paginate
,
2893 vtysh_terminal_paginate_cmd
,
2894 "[no] terminal paginate",
2896 "Set terminal line parameters\n"
2897 "Use pager for output scrolling\n")
2899 free(vtysh_pager_name
);
2900 vtysh_pager_name
= NULL
;
2902 if (strcmp(argv
[0]->text
, "no"))
2903 vtysh_pager_envdef(true);
2907 DEFUN (vtysh_terminal_length
,
2908 vtysh_terminal_length_cmd
,
2909 "[no] terminal length (0-4294967295)",
2911 "Set terminal line parameters\n"
2912 "Set number of lines on a screen\n"
2913 "Number of lines on screen (0 for no pausing, nonzero to use pager)\n")
2916 unsigned long lines
;
2918 free(vtysh_pager_name
);
2919 vtysh_pager_name
= NULL
;
2921 if (!strcmp(argv
[0]->text
, "no") || !strcmp(argv
[1]->text
, "no")) {
2922 /* "terminal no length" = use VTYSH_PAGER */
2923 vtysh_pager_envdef(true);
2927 lines
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
2930 "%% The \"terminal length\" command is deprecated and its value is ignored.\n"
2931 "%% Please use \"terminal paginate\" instead with OS TTY length handling.\n");
2932 vtysh_pager_envdef(true);
2938 ALIAS_DEPRECATED(vtysh_terminal_length
,
2939 vtysh_terminal_no_length_cmd
,
2940 "terminal no length",
2941 "Set terminal line parameters\n"
2943 "Set number of lines on a screen\n")
2945 DEFUN (vtysh_show_daemons
,
2946 vtysh_show_daemons_cmd
,
2949 "Show list of running daemons\n")
2953 for (i
= 0; i
< array_size(vtysh_client
); i
++)
2954 if (vtysh_client
[i
].fd
>= 0)
2955 vty_out(vty
, " %s", vtysh_client
[i
].name
);
2961 /* Execute command in child process. */
2962 static void execute_command(const char *command
, int argc
, const char *arg1
,
2972 /* Failure of fork(). */
2973 fprintf(stderr
, "Can't fork: %s\n", safe_strerror(errno
));
2975 } else if (pid
== 0) {
2976 /* This is child process. */
2979 execlp(command
, command
, (const char *)NULL
);
2982 execlp(command
, command
, arg1
, (const char *)NULL
);
2985 execlp(command
, command
, arg1
, arg2
,
2986 (const char *)NULL
);
2990 /* When execlp suceed, this part is not executed. */
2991 fprintf(stderr
, "Can't execute %s: %s\n", command
,
2992 safe_strerror(errno
));
2995 /* This is parent. */
2997 wait4(pid
, &status
, 0, NULL
);
3005 "Send echo messages\n"
3006 "Ping destination address or hostname\n")
3010 argv_find(argv
, argc
, "WORD", &idx
);
3011 execute_command("ping", 1, argv
[idx
]->arg
, NULL
);
3015 ALIAS(vtysh_ping
, vtysh_ping_ip_cmd
, "ping ip WORD",
3016 "Send echo messages\n"
3018 "Ping destination address or hostname\n")
3020 DEFUN (vtysh_traceroute
,
3021 vtysh_traceroute_cmd
,
3023 "Trace route to destination\n"
3024 "Trace route to destination address or hostname\n")
3028 argv_find(argv
, argc
, "WORD", &idx
);
3029 execute_command("traceroute", 1, argv
[idx
]->arg
, NULL
);
3033 ALIAS(vtysh_traceroute
, vtysh_traceroute_ip_cmd
, "traceroute ip WORD",
3034 "Trace route to destination\n"
3036 "Trace route to destination address or hostname\n")
3038 DEFUN (vtysh_mtrace
,
3040 "mtrace WORD [WORD]",
3041 "Multicast trace route to multicast source\n"
3042 "Multicast trace route to multicast source address\n"
3043 "Multicast trace route for multicast group address\n")
3046 execute_command("mtracebis", 1, argv
[1]->arg
, NULL
);
3048 execute_command("mtracebis", 2, argv
[1]->arg
, argv
[2]->arg
);
3055 "Send echo messages\n"
3057 "Ping destination address or hostname\n")
3059 execute_command("ping6", 1, argv
[2]->arg
, NULL
);
3063 DEFUN (vtysh_traceroute6
,
3064 vtysh_traceroute6_cmd
,
3065 "traceroute ipv6 WORD",
3066 "Trace route to destination\n"
3068 "Trace route to destination address or hostname\n")
3070 execute_command("traceroute6", 1, argv
[2]->arg
, NULL
);
3074 #if defined(HAVE_SHELL_ACCESS)
3075 DEFUN (vtysh_telnet
,
3078 "Open a telnet connection\n"
3079 "IP address or hostname of a remote system\n")
3081 execute_command("telnet", 1, argv
[1]->arg
, NULL
);
3085 DEFUN (vtysh_telnet_port
,
3086 vtysh_telnet_port_cmd
,
3088 "Open a telnet connection\n"
3089 "IP address or hostname of a remote system\n"
3090 "TCP Port number\n")
3092 execute_command("telnet", 2, argv
[1]->arg
, argv
[2]->arg
);
3099 "Open an ssh connection\n"
3102 execute_command("ssh", 1, argv
[1]->arg
, NULL
);
3106 DEFUN (vtysh_start_shell
,
3107 vtysh_start_shell_cmd
,
3109 "Start UNIX shell\n")
3111 execute_command("sh", 0, NULL
, NULL
);
3115 DEFUN (vtysh_start_bash
,
3116 vtysh_start_bash_cmd
,
3118 "Start UNIX shell\n"
3121 execute_command("bash", 0, NULL
, NULL
);
3125 DEFUN (vtysh_start_zsh
,
3126 vtysh_start_zsh_cmd
,
3128 "Start UNIX shell\n"
3131 execute_command("zsh", 0, NULL
, NULL
);
3138 "list [permutations]",
3139 "Print command list\n"
3140 "Print all possible command permutations\n")
3142 return cmd_list_cmds(vty
, argc
== 2);
3145 DEFUN (vtysh_output_file
,
3146 vtysh_output_file_cmd
,
3148 "Direct vtysh output to file\n"
3149 "Direct vtysh output to file\n"
3150 "Path to dump output to\n")
3152 const char *path
= argv
[argc
- 1]->arg
;
3153 vty
->of
= fopen(path
, "a");
3155 vty_out(vty
, "Failed to open file '%s': %s\n", path
,
3156 safe_strerror(errno
));
3162 DEFUN (no_vtysh_output_file
,
3163 no_vtysh_output_file_cmd
,
3164 "no output file [FILE]",
3166 "Direct vtysh output to file\n"
3167 "Direct vtysh output to file\n"
3168 "Path to dump output to\n")
3170 if (vty
->of
!= stdout
) {
3180 "Find CLI command containing text\n"
3181 "Text to search for\n")
3183 char *text
= argv_concat(argv
, argc
, 1);
3184 const struct cmd_node
*node
;
3185 const struct cmd_element
*cli
;
3188 for (unsigned int i
= 0; i
< vector_active(cmdvec
); i
++) {
3189 node
= vector_slot(cmdvec
, i
);
3192 clis
= node
->cmd_vector
;
3193 for (unsigned int j
= 0; j
< vector_active(clis
); j
++) {
3194 cli
= vector_slot(clis
, j
);
3195 if (strcasestr(cli
->string
, text
))
3196 vty_out(vty
, " (%s) %s\n",
3197 node_names
[node
->node
], cli
->string
);
3201 XFREE(MTYPE_TMP
, text
);
3206 DEFUN_HIDDEN(show_cli_graph_vtysh
,
3207 show_cli_graph_vtysh_cmd
,
3211 "Dump current command space as DOT graph\n")
3213 struct cmd_node
*cn
= vector_slot(cmdvec
, vty
->node
);
3214 char *dot
= cmd_graph_dump_dot(cn
->cmdgraph
);
3216 vty_out(vty
, "%s\n", dot
);
3217 XFREE(MTYPE_TMP
, dot
);
3221 static void vtysh_install_default(enum node_type node
)
3223 install_element(node
, &config_list_cmd
);
3224 install_element(node
, &find_cmd
);
3225 install_element(node
, &show_cli_graph_vtysh_cmd
);
3226 install_element(node
, &vtysh_output_file_cmd
);
3227 install_element(node
, &no_vtysh_output_file_cmd
);
3230 /* Making connection to protocol daemon. */
3231 static int vtysh_connect(struct vtysh_client
*vclient
)
3235 struct sockaddr_un addr
;
3239 if (!vclient
->path
[0])
3240 snprintf(vclient
->path
, sizeof(vclient
->path
), "%s/%s.vty",
3241 vtydir
, vclient
->name
);
3242 path
= vclient
->path
;
3244 /* Stat socket to see if we have permission to access it. */
3245 ret
= stat(path
, &s_stat
);
3246 if (ret
< 0 && errno
!= ENOENT
) {
3247 fprintf(stderr
, "vtysh_connect(%s): stat = %s\n", path
,
3248 safe_strerror(errno
));
3253 if (!S_ISSOCK(s_stat
.st_mode
)) {
3254 fprintf(stderr
, "vtysh_connect(%s): Not a socket\n",
3260 sock
= socket(AF_UNIX
, SOCK_STREAM
, 0);
3263 fprintf(stderr
, "vtysh_connect(%s): socket = %s\n", path
,
3264 safe_strerror(errno
));
3269 memset(&addr
, 0, sizeof(struct sockaddr_un
));
3270 addr
.sun_family
= AF_UNIX
;
3271 strlcpy(addr
.sun_path
, path
, sizeof(addr
.sun_path
));
3272 #ifdef HAVE_STRUCT_SOCKADDR_UN_SUN_LEN
3273 len
= addr
.sun_len
= SUN_LEN(&addr
);
3275 len
= sizeof(addr
.sun_family
) + strlen(addr
.sun_path
);
3276 #endif /* HAVE_STRUCT_SOCKADDR_UN_SUN_LEN */
3278 ret
= connect(sock
, (struct sockaddr
*)&addr
, len
);
3281 fprintf(stderr
, "vtysh_connect(%s): connect = %s\n", path
,
3282 safe_strerror(errno
));
3292 static int vtysh_reconnect(struct vtysh_client
*vclient
)
3296 fprintf(stderr
, "Warning: connecting to %s...", vclient
->name
);
3297 ret
= vtysh_connect(vclient
);
3299 fprintf(stderr
, "failed!\n");
3302 fprintf(stderr
, "success!\n");
3303 if (vtysh_client_execute(vclient
, "enable") < 0)
3305 return vtysh_execute_no_pager("end");
3308 /* Return true if str ends with suffix, else return false */
3309 static int ends_with(const char *str
, const char *suffix
)
3311 if (!str
|| !suffix
)
3313 size_t lenstr
= strlen(str
);
3314 size_t lensuffix
= strlen(suffix
);
3315 if (lensuffix
> lenstr
)
3317 return strncmp(str
+ lenstr
- lensuffix
, suffix
, lensuffix
) == 0;
3320 static void vtysh_client_sorted_insert(struct vtysh_client
*head_client
,
3321 struct vtysh_client
*client
)
3323 struct vtysh_client
*prev_node
, *current_node
;
3325 prev_node
= head_client
;
3326 current_node
= head_client
->next
;
3327 while (current_node
) {
3328 if (strcmp(current_node
->path
, client
->path
) > 0)
3331 prev_node
= current_node
;
3332 current_node
= current_node
->next
;
3334 client
->next
= current_node
;
3335 prev_node
->next
= client
;
3338 #define MAXIMUM_INSTANCES 10
3340 static void vtysh_update_all_instances(struct vtysh_client
*head_client
)
3342 struct vtysh_client
*client
;
3344 struct dirent
*file
;
3347 if (head_client
->flag
!= VTYSH_OSPFD
)
3350 /* ls vty_sock_dir and look for all files ending in .vty */
3351 dir
= opendir(vtydir
);
3353 while ((file
= readdir(dir
)) != NULL
) {
3354 if (frrstr_startswith(file
->d_name
, "ospfd-")
3355 && ends_with(file
->d_name
, ".vty")) {
3356 if (n
== MAXIMUM_INSTANCES
) {
3358 "Parsing %s, client limit(%d) reached!\n",
3362 client
= (struct vtysh_client
*)malloc(
3363 sizeof(struct vtysh_client
));
3365 client
->name
= "ospfd";
3366 client
->flag
= VTYSH_OSPFD
;
3367 snprintf(client
->path
, sizeof(client
->path
),
3368 "%s/%s", vtydir
, file
->d_name
);
3369 client
->next
= NULL
;
3370 vtysh_client_sorted_insert(head_client
, client
);
3378 static int vtysh_connect_all_instances(struct vtysh_client
*head_client
)
3380 struct vtysh_client
*client
;
3383 vtysh_update_all_instances(head_client
);
3385 client
= head_client
->next
;
3387 if (vtysh_connect(client
) == 0)
3389 client
= client
->next
;
3395 int vtysh_connect_all(const char *daemon_name
)
3401 for (i
= 0; i
< array_size(vtysh_client
); i
++) {
3403 || !strcmp(daemon_name
, vtysh_client
[i
].name
)) {
3405 if (vtysh_connect(&vtysh_client
[i
]) == 0)
3408 rc
+= vtysh_connect_all_instances(&vtysh_client
[i
]);
3412 fprintf(stderr
, "Error: no daemons match name %s!\n",
3417 /* To disable readline's filename completion. */
3418 static char *vtysh_completion_entry_function(const char *ignore
,
3424 void vtysh_readline_init(void)
3426 /* readline related settings. */
3428 rl_bind_key('?', (rl_command_func_t
*)vtysh_rl_describe
);
3429 rl_completion_entry_function
= vtysh_completion_entry_function
;
3430 rl_attempted_completion_function
= new_completion
;
3433 char *vtysh_prompt(void)
3435 static char buf
[512];
3437 snprintf(buf
, sizeof buf
, cmd_prompt(vty
->node
), cmd_hostname_get());
3441 static void vtysh_ac_line(void *arg
, const char *line
)
3445 for (i
= 0; i
< vector_active(comps
); i
++)
3446 if (!strcmp(line
, (char *)vector_slot(comps
, i
)))
3448 vector_set(comps
, XSTRDUP(MTYPE_COMPLETION
, line
));
3451 static void vtysh_autocomplete(vector comps
, struct cmd_token
*token
)
3456 snprintf(accmd
, sizeof(accmd
), "autocomplete %d %s %s", token
->type
,
3457 token
->text
, token
->varname
? token
->varname
: "-");
3459 vty
->of_saved
= vty
->of
;
3461 for (i
= 0; i
< array_size(vtysh_client
); i
++)
3462 vtysh_client_run_all(&vtysh_client
[i
], accmd
, 1, vtysh_ac_line
,
3464 vty
->of
= vty
->of_saved
;
3467 static const struct cmd_variable_handler vtysh_var_handler
[] = {
3471 .completions
= vtysh_autocomplete
},
3472 {.completions
= NULL
}};
3474 void vtysh_uninit(void)
3476 if (vty
->of
!= stdout
)
3480 void vtysh_init_vty(void)
3482 /* Make vty structure. */
3484 vty
->type
= VTY_SHELL
;
3485 vty
->node
= VIEW_NODE
;
3487 /* set default output */
3489 vtysh_pager_envdef(false);
3491 /* Initialize commands. */
3493 cmd_variable_handler_register(vtysh_var_handler
);
3495 /* Install nodes. */
3496 install_node(&bgp_node
, NULL
);
3497 install_node(&rip_node
, NULL
);
3498 install_node(&interface_node
, NULL
);
3499 install_node(&pw_node
, NULL
);
3500 install_node(&link_params_node
, NULL
);
3501 install_node(&logicalrouter_node
, NULL
);
3502 install_node(&vrf_node
, NULL
);
3503 install_node(&nh_group_node
, NULL
);
3504 install_node(&rmap_node
, NULL
);
3505 install_node(&pbr_map_node
, NULL
);
3506 install_node(&zebra_node
, NULL
);
3507 install_node(&bgp_vpnv4_node
, NULL
);
3508 install_node(&bgp_vpnv6_node
, NULL
);
3509 install_node(&bgp_flowspecv4_node
, NULL
);
3510 install_node(&bgp_flowspecv6_node
, NULL
);
3511 install_node(&bgp_ipv4_node
, NULL
);
3512 install_node(&bgp_ipv4m_node
, NULL
);
3513 install_node(&bgp_ipv4l_node
, NULL
);
3514 install_node(&bgp_ipv6_node
, NULL
);
3515 install_node(&bgp_ipv6m_node
, NULL
);
3516 install_node(&bgp_ipv6l_node
, NULL
);
3517 install_node(&bgp_vrf_policy_node
, NULL
);
3518 install_node(&bgp_evpn_node
, NULL
);
3519 install_node(&bgp_evpn_vni_node
, NULL
);
3520 install_node(&bgp_vnc_defaults_node
, NULL
);
3521 install_node(&bgp_vnc_nve_group_node
, NULL
);
3522 install_node(&bgp_vnc_l2_group_node
, NULL
);
3523 install_node(&ospf_node
, NULL
);
3524 install_node(&eigrp_node
, NULL
);
3525 install_node(&babel_node
, NULL
);
3526 install_node(&ripng_node
, NULL
);
3527 install_node(&ospf6_node
, NULL
);
3528 install_node(&ldp_node
, NULL
);
3529 install_node(&ldp_ipv4_node
, NULL
);
3530 install_node(&ldp_ipv6_node
, NULL
);
3531 install_node(&ldp_ipv4_iface_node
, NULL
);
3532 install_node(&ldp_ipv6_iface_node
, NULL
);
3533 install_node(&ldp_l2vpn_node
, NULL
);
3534 install_node(&ldp_pseudowire_node
, NULL
);
3535 install_node(&keychain_node
, NULL
);
3536 install_node(&keychain_key_node
, NULL
);
3537 install_node(&isis_node
, NULL
);
3538 install_node(&openfabric_node
, NULL
);
3539 install_node(&vty_node
, NULL
);
3540 install_node(&rpki_node
, NULL
);
3542 install_node(&bfd_node
, NULL
);
3543 install_node(&bfd_peer_node
, NULL
);
3544 #endif /* HAVE_BFDD */
3546 struct cmd_node
*node
;
3547 for (unsigned int i
= 0; i
< vector_active(cmdvec
); i
++) {
3548 node
= vector_slot(cmdvec
, i
);
3549 if (!node
|| node
->node
== VIEW_NODE
)
3551 vtysh_install_default(node
->node
);
3554 install_element(VIEW_NODE
, &vtysh_enable_cmd
);
3555 install_element(ENABLE_NODE
, &vtysh_config_terminal_cmd
);
3556 install_element(ENABLE_NODE
, &vtysh_disable_cmd
);
3558 /* "exit" command. */
3559 install_element(VIEW_NODE
, &vtysh_exit_all_cmd
);
3560 install_element(CONFIG_NODE
, &vtysh_exit_all_cmd
);
3561 install_element(VIEW_NODE
, &vtysh_quit_all_cmd
);
3562 install_element(CONFIG_NODE
, &vtysh_quit_all_cmd
);
3563 install_element(RIP_NODE
, &vtysh_exit_ripd_cmd
);
3564 install_element(RIP_NODE
, &vtysh_quit_ripd_cmd
);
3565 install_element(RIPNG_NODE
, &vtysh_exit_ripngd_cmd
);
3566 install_element(RIPNG_NODE
, &vtysh_quit_ripngd_cmd
);
3567 install_element(OSPF_NODE
, &vtysh_exit_ospfd_cmd
);
3568 install_element(OSPF_NODE
, &vtysh_quit_ospfd_cmd
);
3569 install_element(EIGRP_NODE
, &vtysh_exit_eigrpd_cmd
);
3570 install_element(EIGRP_NODE
, &vtysh_quit_eigrpd_cmd
);
3571 install_element(BABEL_NODE
, &vtysh_exit_babeld_cmd
);
3572 install_element(BABEL_NODE
, &vtysh_quit_babeld_cmd
);
3573 install_element(OSPF6_NODE
, &vtysh_exit_ospf6d_cmd
);
3574 install_element(OSPF6_NODE
, &vtysh_quit_ospf6d_cmd
);
3575 #if defined(HAVE_LDPD)
3576 install_element(LDP_NODE
, &vtysh_exit_ldpd_cmd
);
3577 install_element(LDP_NODE
, &vtysh_quit_ldpd_cmd
);
3578 install_element(LDP_IPV4_NODE
, &vtysh_exit_ldpd_cmd
);
3579 install_element(LDP_IPV4_NODE
, &vtysh_quit_ldpd_cmd
);
3580 install_element(LDP_IPV4_NODE
, &ldp_exit_address_family_cmd
);
3581 install_element(LDP_IPV6_NODE
, &vtysh_exit_ldpd_cmd
);
3582 install_element(LDP_IPV6_NODE
, &vtysh_quit_ldpd_cmd
);
3583 install_element(LDP_IPV6_NODE
, &ldp_exit_address_family_cmd
);
3584 install_element(LDP_IPV4_IFACE_NODE
, &vtysh_exit_ldpd_cmd
);
3585 install_element(LDP_IPV4_IFACE_NODE
, &vtysh_quit_ldpd_cmd
);
3586 install_element(LDP_IPV6_IFACE_NODE
, &vtysh_exit_ldpd_cmd
);
3587 install_element(LDP_IPV6_IFACE_NODE
, &vtysh_quit_ldpd_cmd
);
3588 install_element(LDP_L2VPN_NODE
, &vtysh_exit_ldpd_cmd
);
3589 install_element(LDP_L2VPN_NODE
, &vtysh_quit_ldpd_cmd
);
3590 install_element(LDP_PSEUDOWIRE_NODE
, &vtysh_exit_ldpd_cmd
);
3591 install_element(LDP_PSEUDOWIRE_NODE
, &vtysh_quit_ldpd_cmd
);
3593 install_element(BGP_NODE
, &vtysh_exit_bgpd_cmd
);
3594 install_element(BGP_NODE
, &vtysh_quit_bgpd_cmd
);
3595 install_element(BGP_VPNV4_NODE
, &vtysh_exit_bgpd_cmd
);
3596 install_element(BGP_VPNV4_NODE
, &vtysh_quit_bgpd_cmd
);
3597 install_element(BGP_VPNV6_NODE
, &vtysh_exit_bgpd_cmd
);
3598 install_element(BGP_VPNV6_NODE
, &vtysh_quit_bgpd_cmd
);
3599 install_element(BGP_FLOWSPECV4_NODE
, &vtysh_exit_bgpd_cmd
);
3600 install_element(BGP_FLOWSPECV4_NODE
, &vtysh_quit_bgpd_cmd
);
3601 install_element(BGP_FLOWSPECV6_NODE
, &vtysh_exit_bgpd_cmd
);
3602 install_element(BGP_FLOWSPECV6_NODE
, &vtysh_quit_bgpd_cmd
);
3603 install_element(BGP_IPV4_NODE
, &vtysh_exit_bgpd_cmd
);
3604 install_element(BGP_IPV4_NODE
, &vtysh_quit_bgpd_cmd
);
3605 install_element(BGP_IPV4M_NODE
, &vtysh_exit_bgpd_cmd
);
3606 install_element(BGP_IPV4M_NODE
, &vtysh_quit_bgpd_cmd
);
3607 install_element(BGP_IPV4L_NODE
, &vtysh_exit_bgpd_cmd
);
3608 install_element(BGP_IPV4L_NODE
, &vtysh_quit_bgpd_cmd
);
3609 install_element(BGP_IPV6_NODE
, &vtysh_exit_bgpd_cmd
);
3610 install_element(BGP_IPV6_NODE
, &vtysh_quit_bgpd_cmd
);
3611 install_element(BGP_IPV6M_NODE
, &vtysh_exit_bgpd_cmd
);
3612 install_element(BGP_IPV6M_NODE
, &vtysh_quit_bgpd_cmd
);
3613 install_element(BGP_EVPN_NODE
, &vtysh_quit_bgpd_cmd
);
3614 install_element(BGP_EVPN_NODE
, &vtysh_exit_bgpd_cmd
);
3615 install_element(BGP_EVPN_VNI_NODE
, &vtysh_exit_bgpd_cmd
);
3616 install_element(BGP_EVPN_VNI_NODE
, &vtysh_quit_bgpd_cmd
);
3617 install_element(BGP_IPV6L_NODE
, &vtysh_exit_bgpd_cmd
);
3618 install_element(BGP_IPV6L_NODE
, &vtysh_quit_bgpd_cmd
);
3619 #if defined(ENABLE_BGP_VNC)
3620 install_element(BGP_VRF_POLICY_NODE
, &vtysh_exit_bgpd_cmd
);
3621 install_element(BGP_VRF_POLICY_NODE
, &vtysh_quit_bgpd_cmd
);
3622 install_element(BGP_VNC_DEFAULTS_NODE
, &vtysh_exit_bgpd_cmd
);
3623 install_element(BGP_VNC_DEFAULTS_NODE
, &vtysh_quit_bgpd_cmd
);
3624 install_element(BGP_VNC_NVE_GROUP_NODE
, &vtysh_exit_bgpd_cmd
);
3625 install_element(BGP_VNC_NVE_GROUP_NODE
, &vtysh_quit_bgpd_cmd
);
3626 install_element(BGP_VNC_L2_GROUP_NODE
, &vtysh_exit_bgpd_cmd
);
3627 install_element(BGP_VNC_L2_GROUP_NODE
, &vtysh_quit_bgpd_cmd
);
3629 install_element(ISIS_NODE
, &vtysh_exit_isisd_cmd
);
3630 install_element(ISIS_NODE
, &vtysh_quit_isisd_cmd
);
3631 install_element(OPENFABRIC_NODE
, &vtysh_exit_fabricd_cmd
);
3632 install_element(OPENFABRIC_NODE
, &vtysh_quit_fabricd_cmd
);
3633 install_element(KEYCHAIN_NODE
, &vtysh_exit_ripd_cmd
);
3634 install_element(KEYCHAIN_NODE
, &vtysh_quit_ripd_cmd
);
3635 install_element(KEYCHAIN_KEY_NODE
, &vtysh_exit_ripd_cmd
);
3636 install_element(KEYCHAIN_KEY_NODE
, &vtysh_quit_ripd_cmd
);
3637 install_element(RMAP_NODE
, &vtysh_exit_rmap_cmd
);
3638 install_element(RMAP_NODE
, &vtysh_quit_rmap_cmd
);
3639 install_element(PBRMAP_NODE
, &vtysh_exit_pbr_map_cmd
);
3640 install_element(PBRMAP_NODE
, &vtysh_quit_pbr_map_cmd
);
3643 install_element(CONFIG_NODE
, &bfd_enter_cmd
);
3644 install_element(BFD_NODE
, &bfd_peer_enter_cmd
);
3646 /* Exit/quit node. */
3647 install_element(BFD_NODE
, &vtysh_exit_bfdd_cmd
);
3648 install_element(BFD_NODE
, &vtysh_quit_bfdd_cmd
);
3649 install_element(BFD_PEER_NODE
, &vtysh_exit_bfdd_cmd
);
3650 install_element(BFD_PEER_NODE
, &vtysh_quit_bfdd_cmd
);
3653 install_element(BFD_NODE
, &vtysh_end_all_cmd
);
3654 install_element(BFD_PEER_NODE
, &vtysh_end_all_cmd
);
3655 #endif /* HAVE_BFDD */
3656 install_element(VTY_NODE
, &vtysh_exit_line_vty_cmd
);
3657 install_element(VTY_NODE
, &vtysh_quit_line_vty_cmd
);
3659 /* "end" command. */
3660 install_element(CONFIG_NODE
, &vtysh_end_all_cmd
);
3661 install_element(ENABLE_NODE
, &vtysh_end_all_cmd
);
3662 install_element(RIP_NODE
, &vtysh_end_all_cmd
);
3663 install_element(RIPNG_NODE
, &vtysh_end_all_cmd
);
3664 install_element(OSPF_NODE
, &vtysh_end_all_cmd
);
3665 install_element(EIGRP_NODE
, &vtysh_end_all_cmd
);
3666 install_element(BABEL_NODE
, &vtysh_end_all_cmd
);
3667 install_element(OSPF6_NODE
, &vtysh_end_all_cmd
);
3668 install_element(LDP_NODE
, &vtysh_end_all_cmd
);
3669 install_element(LDP_IPV4_NODE
, &vtysh_end_all_cmd
);
3670 install_element(LDP_IPV6_NODE
, &vtysh_end_all_cmd
);
3671 install_element(LDP_IPV4_IFACE_NODE
, &vtysh_end_all_cmd
);
3672 install_element(LDP_IPV6_IFACE_NODE
, &vtysh_end_all_cmd
);
3673 install_element(LDP_L2VPN_NODE
, &vtysh_end_all_cmd
);
3674 install_element(LDP_PSEUDOWIRE_NODE
, &vtysh_end_all_cmd
);
3675 install_element(BGP_NODE
, &vtysh_end_all_cmd
);
3676 install_element(BGP_IPV4_NODE
, &vtysh_end_all_cmd
);
3677 install_element(BGP_IPV4M_NODE
, &vtysh_end_all_cmd
);
3678 install_element(BGP_IPV4L_NODE
, &vtysh_end_all_cmd
);
3679 install_element(BGP_VPNV4_NODE
, &vtysh_end_all_cmd
);
3680 install_element(BGP_VPNV6_NODE
, &vtysh_end_all_cmd
);
3681 install_element(BGP_FLOWSPECV4_NODE
, &vtysh_end_all_cmd
);
3682 install_element(BGP_FLOWSPECV6_NODE
, &vtysh_end_all_cmd
);
3683 install_element(BGP_IPV6_NODE
, &vtysh_end_all_cmd
);
3684 install_element(BGP_IPV6M_NODE
, &vtysh_end_all_cmd
);
3685 install_element(BGP_IPV6L_NODE
, &vtysh_end_all_cmd
);
3686 install_element(BGP_VRF_POLICY_NODE
, &vtysh_end_all_cmd
);
3687 install_element(BGP_EVPN_NODE
, &vtysh_end_all_cmd
);
3688 install_element(BGP_EVPN_VNI_NODE
, &vtysh_end_all_cmd
);
3689 install_element(BGP_VNC_DEFAULTS_NODE
, &vtysh_end_all_cmd
);
3690 install_element(BGP_VNC_NVE_GROUP_NODE
, &vtysh_end_all_cmd
);
3691 install_element(BGP_VNC_L2_GROUP_NODE
, &vtysh_end_all_cmd
);
3692 install_element(ISIS_NODE
, &vtysh_end_all_cmd
);
3693 install_element(OPENFABRIC_NODE
, &vtysh_end_all_cmd
);
3694 install_element(KEYCHAIN_NODE
, &vtysh_end_all_cmd
);
3695 install_element(KEYCHAIN_KEY_NODE
, &vtysh_end_all_cmd
);
3696 install_element(RMAP_NODE
, &vtysh_end_all_cmd
);
3697 install_element(PBRMAP_NODE
, &vtysh_end_all_cmd
);
3698 install_element(VTY_NODE
, &vtysh_end_all_cmd
);
3700 install_element(INTERFACE_NODE
, &vtysh_end_all_cmd
);
3701 install_element(INTERFACE_NODE
, &vtysh_exit_interface_cmd
);
3702 install_element(LINK_PARAMS_NODE
, &exit_link_params_cmd
);
3703 install_element(LINK_PARAMS_NODE
, &vtysh_end_all_cmd
);
3704 install_element(LINK_PARAMS_NODE
, &vtysh_exit_interface_cmd
);
3705 install_element(INTERFACE_NODE
, &vtysh_quit_interface_cmd
);
3707 install_element(PW_NODE
, &vtysh_end_all_cmd
);
3708 install_element(PW_NODE
, &vtysh_exit_interface_cmd
);
3709 install_element(PW_NODE
, &vtysh_quit_interface_cmd
);
3711 install_element(LOGICALROUTER_NODE
, &vtysh_end_all_cmd
);
3713 install_element(CONFIG_NODE
, &vtysh_logicalrouter_cmd
);
3714 install_element(CONFIG_NODE
, &vtysh_no_logicalrouter_cmd
);
3715 install_element(LOGICALROUTER_NODE
, &vtysh_exit_logicalrouter_cmd
);
3716 install_element(LOGICALROUTER_NODE
, &vtysh_quit_logicalrouter_cmd
);
3718 install_element(CONFIG_NODE
, &vtysh_nexthop_group_cmd
);
3719 install_element(NH_GROUP_NODE
, &vtysh_end_all_cmd
);
3720 install_element(NH_GROUP_NODE
, &vtysh_exit_nexthop_group_cmd
);
3721 install_element(NH_GROUP_NODE
, &vtysh_quit_nexthop_group_cmd
);
3723 install_element(VRF_NODE
, &vtysh_end_all_cmd
);
3724 install_element(VRF_NODE
, &vtysh_exit_vrf_cmd
);
3725 install_element(VRF_NODE
, &vtysh_quit_vrf_cmd
);
3727 install_element(CONFIG_NODE
, &router_eigrp_cmd
);
3728 install_element(CONFIG_NODE
, &router_babel_cmd
);
3729 install_element(CONFIG_NODE
, &router_rip_cmd
);
3730 install_element(CONFIG_NODE
, &router_ripng_cmd
);
3731 install_element(CONFIG_NODE
, &router_ospf_cmd
);
3732 install_element(CONFIG_NODE
, &router_ospf6_cmd
);
3733 #if defined(HAVE_LDPD)
3734 install_element(CONFIG_NODE
, &ldp_mpls_ldp_cmd
);
3735 install_element(LDP_NODE
, &ldp_address_family_ipv4_cmd
);
3736 install_element(LDP_NODE
, &ldp_address_family_ipv6_cmd
);
3737 install_element(LDP_IPV4_NODE
, &ldp_interface_ifname_cmd
);
3738 install_element(LDP_IPV6_NODE
, &ldp_interface_ifname_cmd
);
3739 install_element(CONFIG_NODE
, &ldp_l2vpn_word_type_vpls_cmd
);
3740 install_element(LDP_L2VPN_NODE
, &ldp_member_pseudowire_ifname_cmd
);
3742 install_element(CONFIG_NODE
, &router_isis_cmd
);
3743 install_element(CONFIG_NODE
, &router_openfabric_cmd
);
3744 install_element(CONFIG_NODE
, &router_bgp_cmd
);
3745 #ifdef KEEP_OLD_VPN_COMMANDS
3746 install_element(BGP_NODE
, &address_family_vpnv4_cmd
);
3747 install_element(BGP_NODE
, &address_family_vpnv6_cmd
);
3748 #endif /* KEEP_OLD_VPN_COMMANDS */
3749 #if defined(ENABLE_BGP_VNC)
3750 install_element(BGP_NODE
, &vnc_vrf_policy_cmd
);
3751 install_element(BGP_NODE
, &vnc_defaults_cmd
);
3752 install_element(BGP_NODE
, &vnc_nve_group_cmd
);
3753 install_element(BGP_NODE
, &vnc_l2_group_cmd
);
3755 install_element(BGP_NODE
, &address_family_ipv4_cmd
);
3756 install_element(BGP_NODE
, &address_family_ipv4_multicast_cmd
);
3757 install_element(BGP_NODE
, &address_family_ipv4_vpn_cmd
);
3758 install_element(BGP_NODE
, &address_family_ipv4_labeled_unicast_cmd
);
3759 install_element(BGP_NODE
, &address_family_ipv6_cmd
);
3760 install_element(BGP_NODE
, &address_family_ipv6_multicast_cmd
);
3761 install_element(BGP_NODE
, &address_family_ipv6_vpn_cmd
);
3762 install_element(BGP_NODE
, &address_family_ipv6_labeled_unicast_cmd
);
3763 install_element(BGP_NODE
, &address_family_evpn_cmd
);
3764 install_element(BGP_NODE
, &address_family_flowspecv4_cmd
);
3765 install_element(BGP_NODE
, &address_family_flowspecv6_cmd
);
3766 #if defined(HAVE_CUMULUS)
3767 install_element(BGP_NODE
, &address_family_evpn2_cmd
);
3769 install_element(BGP_VPNV4_NODE
, &exit_address_family_cmd
);
3770 install_element(BGP_VPNV6_NODE
, &exit_address_family_cmd
);
3771 install_element(BGP_IPV4_NODE
, &exit_address_family_cmd
);
3772 install_element(BGP_IPV4M_NODE
, &exit_address_family_cmd
);
3773 install_element(BGP_IPV4L_NODE
, &exit_address_family_cmd
);
3774 install_element(BGP_IPV6_NODE
, &exit_address_family_cmd
);
3775 install_element(BGP_IPV6M_NODE
, &exit_address_family_cmd
);
3776 install_element(BGP_EVPN_NODE
, &exit_address_family_cmd
);
3777 install_element(BGP_IPV6L_NODE
, &exit_address_family_cmd
);
3778 install_element(BGP_FLOWSPECV4_NODE
, &exit_address_family_cmd
);
3779 install_element(BGP_FLOWSPECV6_NODE
, &exit_address_family_cmd
);
3781 install_element(CONFIG_NODE
, &rpki_cmd
);
3782 install_element(RPKI_NODE
, &rpki_exit_cmd
);
3783 install_element(RPKI_NODE
, &rpki_quit_cmd
);
3784 install_element(RPKI_NODE
, &vtysh_end_all_cmd
);
3787 install_element(BGP_EVPN_NODE
, &bgp_evpn_vni_cmd
);
3788 install_element(BGP_EVPN_VNI_NODE
, &exit_vni_cmd
);
3790 install_element(BGP_VRF_POLICY_NODE
, &exit_vrf_policy_cmd
);
3791 install_element(BGP_VNC_DEFAULTS_NODE
, &exit_vnc_config_cmd
);
3792 install_element(BGP_VNC_NVE_GROUP_NODE
, &exit_vnc_config_cmd
);
3793 install_element(BGP_VNC_L2_GROUP_NODE
, &exit_vnc_config_cmd
);
3795 install_element(CONFIG_NODE
, &key_chain_cmd
);
3796 install_element(CONFIG_NODE
, &vtysh_route_map_cmd
);
3797 install_element(CONFIG_NODE
, &vtysh_pbr_map_cmd
);
3798 install_element(CONFIG_NODE
, &vtysh_no_pbr_map_cmd
);
3799 install_element(CONFIG_NODE
, &vtysh_line_vty_cmd
);
3800 install_element(KEYCHAIN_NODE
, &key_cmd
);
3801 install_element(KEYCHAIN_NODE
, &key_chain_cmd
);
3802 install_element(KEYCHAIN_KEY_NODE
, &key_chain_cmd
);
3803 install_element(CONFIG_NODE
, &vtysh_interface_cmd
);
3804 install_element(CONFIG_NODE
, &vtysh_pseudowire_cmd
);
3805 install_element(INTERFACE_NODE
, &vtysh_link_params_cmd
);
3806 install_element(ENABLE_NODE
, &vtysh_show_running_config_cmd
);
3807 install_element(ENABLE_NODE
, &vtysh_copy_running_config_cmd
);
3809 install_element(CONFIG_NODE
, &vtysh_vrf_cmd
);
3810 install_element(VRF_NODE
, &vtysh_vrf_netns_cmd
);
3811 install_element(VRF_NODE
, &vtysh_no_vrf_netns_cmd
);
3812 install_element(VRF_NODE
, &exit_vrf_config_cmd
);
3814 install_element(CONFIG_NODE
, &vtysh_no_nexthop_group_cmd
);
3816 /* "write terminal" command. */
3817 install_element(ENABLE_NODE
, &vtysh_write_terminal_cmd
);
3819 install_element(CONFIG_NODE
, &vtysh_integrated_config_cmd
);
3820 install_element(CONFIG_NODE
, &no_vtysh_integrated_config_cmd
);
3822 /* "write memory" command. */
3823 install_element(ENABLE_NODE
, &vtysh_write_memory_cmd
);
3825 install_element(CONFIG_NODE
, &vtysh_terminal_paginate_cmd
);
3826 install_element(VIEW_NODE
, &vtysh_terminal_paginate_cmd
);
3827 install_element(VIEW_NODE
, &vtysh_terminal_length_cmd
);
3828 install_element(VIEW_NODE
, &vtysh_terminal_no_length_cmd
);
3829 install_element(VIEW_NODE
, &vtysh_show_daemons_cmd
);
3831 install_element(VIEW_NODE
, &vtysh_ping_cmd
);
3832 install_element(VIEW_NODE
, &vtysh_ping_ip_cmd
);
3833 install_element(VIEW_NODE
, &vtysh_traceroute_cmd
);
3834 install_element(VIEW_NODE
, &vtysh_traceroute_ip_cmd
);
3835 install_element(VIEW_NODE
, &vtysh_mtrace_cmd
);
3836 install_element(VIEW_NODE
, &vtysh_ping6_cmd
);
3837 install_element(VIEW_NODE
, &vtysh_traceroute6_cmd
);
3838 #if defined(HAVE_SHELL_ACCESS)
3839 install_element(VIEW_NODE
, &vtysh_telnet_cmd
);
3840 install_element(VIEW_NODE
, &vtysh_telnet_port_cmd
);
3841 install_element(VIEW_NODE
, &vtysh_ssh_cmd
);
3843 #if defined(HAVE_SHELL_ACCESS)
3844 install_element(ENABLE_NODE
, &vtysh_start_shell_cmd
);
3845 install_element(ENABLE_NODE
, &vtysh_start_bash_cmd
);
3846 install_element(ENABLE_NODE
, &vtysh_start_zsh_cmd
);
3850 install_element(VIEW_NODE
, &vtysh_show_debugging_cmd
);
3851 install_element(VIEW_NODE
, &vtysh_show_error_code_cmd
);
3852 install_element(VIEW_NODE
, &vtysh_show_debugging_hashtable_cmd
);
3853 install_element(ENABLE_NODE
, &vtysh_debug_all_cmd
);
3854 install_element(CONFIG_NODE
, &vtysh_debug_all_cmd
);
3855 install_element(ENABLE_NODE
, &vtysh_debug_memstats_cmd
);
3856 install_element(CONFIG_NODE
, &vtysh_debug_memstats_cmd
);
3858 /* misc lib show commands */
3859 install_element(VIEW_NODE
, &vtysh_show_memory_cmd
);
3860 install_element(VIEW_NODE
, &vtysh_show_modules_cmd
);
3861 install_element(VIEW_NODE
, &vtysh_show_work_queues_cmd
);
3862 install_element(VIEW_NODE
, &vtysh_show_work_queues_daemon_cmd
);
3863 install_element(VIEW_NODE
, &vtysh_show_thread_cmd
);
3864 install_element(VIEW_NODE
, &vtysh_show_poll_cmd
);
3867 install_element(VIEW_NODE
, &vtysh_show_logging_cmd
);
3868 install_element(CONFIG_NODE
, &vtysh_log_stdout_cmd
);
3869 install_element(CONFIG_NODE
, &vtysh_log_stdout_level_cmd
);
3870 install_element(CONFIG_NODE
, &no_vtysh_log_stdout_cmd
);
3871 install_element(CONFIG_NODE
, &vtysh_log_file_cmd
);
3872 install_element(CONFIG_NODE
, &vtysh_log_file_level_cmd
);
3873 install_element(CONFIG_NODE
, &no_vtysh_log_file_cmd
);
3874 install_element(CONFIG_NODE
, &vtysh_log_monitor_cmd
);
3875 install_element(CONFIG_NODE
, &no_vtysh_log_monitor_cmd
);
3876 install_element(CONFIG_NODE
, &vtysh_log_syslog_cmd
);
3877 install_element(CONFIG_NODE
, &no_vtysh_log_syslog_cmd
);
3878 install_element(CONFIG_NODE
, &vtysh_log_facility_cmd
);
3879 install_element(CONFIG_NODE
, &no_vtysh_log_facility_cmd
);
3880 install_element(CONFIG_NODE
, &vtysh_log_record_priority_cmd
);
3881 install_element(CONFIG_NODE
, &no_vtysh_log_record_priority_cmd
);
3882 install_element(CONFIG_NODE
, &vtysh_log_timestamp_precision_cmd
);
3883 install_element(CONFIG_NODE
, &no_vtysh_log_timestamp_precision_cmd
);
3885 install_element(CONFIG_NODE
, &vtysh_service_password_encrypt_cmd
);
3886 install_element(CONFIG_NODE
, &no_vtysh_service_password_encrypt_cmd
);
3888 install_element(CONFIG_NODE
, &vtysh_password_cmd
);
3889 install_element(CONFIG_NODE
, &no_vtysh_password_cmd
);
3890 install_element(CONFIG_NODE
, &vtysh_enable_password_cmd
);
3891 install_element(CONFIG_NODE
, &no_vtysh_enable_password_cmd
);