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"
51 DEFINE_MTYPE_STATIC(MVTYSH
, VTYSH_CMD
, "Vtysh cmd copy")
56 /* VTY shell pager name. */
57 char *vtysh_pager_name
= NULL
;
59 /* VTY shell client structure */
64 char path
[MAXPATHLEN
];
65 struct vtysh_client
*next
;
68 /* Some utility functions for working on vtysh-specific vty tasks */
70 static FILE *vty_open_pager(struct vty
*vty
)
75 if (!vtysh_pager_name
)
78 vty
->of_saved
= vty
->of
;
79 vty
->of
= popen(vtysh_pager_name
, "w");
80 if (vty
->of
== NULL
) {
81 vty
->of
= vty
->of_saved
;
91 static int vty_close_pager(struct vty
*vty
)
97 if (pclose(vty
->of
) == -1) {
102 vty
->of
= vty
->of_saved
;
103 vty
->is_paged
= false;
108 static void vtysh_pager_envdef(bool fallback
)
112 pager_defined
= getenv("VTYSH_PAGER");
115 vtysh_pager_name
= strdup(pager_defined
);
117 vtysh_pager_name
= strdup(VTYSH_PAGER
);
122 struct vtysh_client vtysh_client
[] = {
123 {.fd
= -1, .name
= "zebra", .flag
= VTYSH_ZEBRA
, .next
= NULL
},
124 {.fd
= -1, .name
= "ripd", .flag
= VTYSH_RIPD
, .next
= NULL
},
125 {.fd
= -1, .name
= "ripngd", .flag
= VTYSH_RIPNGD
, .next
= NULL
},
126 {.fd
= -1, .name
= "ospfd", .flag
= VTYSH_OSPFD
, .next
= NULL
},
127 {.fd
= -1, .name
= "ospf6d", .flag
= VTYSH_OSPF6D
, .next
= NULL
},
128 {.fd
= -1, .name
= "ldpd", .flag
= VTYSH_LDPD
, .next
= NULL
},
129 {.fd
= -1, .name
= "bgpd", .flag
= VTYSH_BGPD
, .next
= NULL
},
130 {.fd
= -1, .name
= "isisd", .flag
= VTYSH_ISISD
, .next
= NULL
},
131 {.fd
= -1, .name
= "pimd", .flag
= VTYSH_PIMD
, .next
= NULL
},
132 {.fd
= -1, .name
= "nhrpd", .flag
= VTYSH_NHRPD
, .next
= NULL
},
133 {.fd
= -1, .name
= "eigrpd", .flag
= VTYSH_EIGRPD
, .next
= NULL
},
134 {.fd
= -1, .name
= "babeld", .flag
= VTYSH_BABELD
, .next
= NULL
},
135 {.fd
= -1, .name
= "sharpd", .flag
= VTYSH_SHARPD
, .next
= NULL
},
136 {.fd
= -1, .name
= "fabricd", .flag
= VTYSH_FABRICD
, .next
= NULL
},
137 {.fd
= -1, .name
= "watchfrr", .flag
= VTYSH_WATCHFRR
, .next
= NULL
},
138 {.fd
= -1, .name
= "pbrd", .flag
= VTYSH_PBRD
, .next
= NULL
},
139 {.fd
= -1, .name
= "staticd", .flag
= VTYSH_STATICD
, .next
= NULL
},
140 {.fd
= -1, .name
= "bfdd", .flag
= VTYSH_BFDD
, .next
= NULL
},
141 {.fd
= -1, .name
= "vrrpd", .flag
= VTYSH_VRRPD
, .next
= NULL
},
144 /* Searches for client by name, returns index */
145 static int vtysh_client_lookup(const char *name
)
149 for (unsigned int i
= 0; i
< array_size(vtysh_client
); i
++) {
150 if (strmatch(vtysh_client
[i
].name
, name
)) {
159 enum vtysh_write_integrated vtysh_write_integrated
=
160 WRITE_INTEGRATED_UNSPECIFIED
;
162 static int vtysh_reconnect(struct vtysh_client
*vclient
);
164 static void vclient_close(struct vtysh_client
*vclient
)
166 if (vclient
->fd
>= 0) {
169 "Warning: closing connection to %s because of an I/O error!\n",
172 /* indicate as candidate for reconnect */
173 vclient
->fd
= VTYSH_WAS_ACTIVE
;
178 * Send a CLI command to a client and read the response.
180 * Output will be printed to vty->of. If you want to suppress output, set that
184 * the client to send the command to
187 * the command to send
190 * if non-null, this will be called with each line of output received from
191 * the client passed in the second parameter
194 * optional first argument to pass to callback
199 static int vtysh_client_run(struct vtysh_client
*vclient
, const char *line
,
200 void (*callback
)(void *, const char *), void *cbarg
)
204 char *buf
= stackbuf
;
205 size_t bufsz
= sizeof(stackbuf
);
206 char *bufvalid
, *end
= NULL
;
207 char terminator
[3] = {0, 0, 0};
209 /* vclinet was previously active, try to reconnect */
210 if (vclient
->fd
== VTYSH_WAS_ACTIVE
) {
211 ret
= vtysh_reconnect(vclient
);
219 ret
= write(vclient
->fd
, line
, strlen(line
) + 1);
221 /* close connection and try to reconnect */
222 vclient_close(vclient
);
223 ret
= vtysh_reconnect(vclient
);
227 ret
= write(vclient
->fd
, line
, strlen(line
) + 1);
235 read(vclient
->fd
, bufvalid
, buf
+ bufsz
- bufvalid
- 1);
237 if (nread
< 0 && (errno
== EINTR
|| errno
== EAGAIN
))
243 "vtysh: error reading from %s: %s (%d)",
244 vclient
->name
, safe_strerror(errno
),
251 /* Null terminate so we may pass this to *printf later. */
255 * We expect string output from daemons, so instead of looking
256 * for the full 3 null bytes of the terminator, we check for
257 * just one instead and assume it is the first byte of the
258 * terminator. The presence of the full terminator is checked
261 if (bufvalid
- buf
>= 4)
262 end
= memmem(bufvalid
- 4, 4, "\0", 1);
265 * calculate # bytes we have, up to & not including the
266 * terminator if present
268 size_t textlen
= (end
? end
: bufvalid
) - buf
;
271 /* feed line processing callback if present */
272 while (callback
&& bufvalid
> buf
&& (end
> buf
|| !end
)) {
273 textlen
= (end
? end
: bufvalid
) - buf
;
274 char *eol
= memchr(buf
, '\n', textlen
);
280 * no line break, end of input, no text left
281 * before end; nothing to write
285 /* no nl, end of input, but some text left */
287 else if (bufvalid
== buf
+ bufsz
- 1) {
289 * no nl, no end of input, no buffer space;
295 if (buf
== stackbuf
) {
296 new = XMALLOC(MTYPE_TMP
, bufsz
);
297 memcpy(new, stackbuf
, sizeof(stackbuf
));
299 new = XREALLOC(MTYPE_TMP
, buf
, bufsz
);
301 bufvalid
= bufvalid
- buf
+ new;
303 /* if end != NULL, we won't be reading more
313 /* eol is at line end now, either \n => \0 or \0\0\0 */
314 assert(eol
&& eol
<= bufvalid
);
317 vty_out(vty
, "%s\n", buf
);
319 callback(cbarg
, buf
);
321 /* shift back data and adjust bufvalid */
322 memmove(buf
, eol
, bufvalid
- eol
);
323 bufvalid
-= eol
- buf
;
328 /* else if no callback, dump raw */
331 vty_out(vty
, "%s", buf
);
332 memmove(buf
, buf
+ textlen
, bufvalid
- buf
- textlen
);
338 * ----------------------------------------------------
339 * At this point `buf` should be in one of two states:
340 * - Empty (i.e. buf == bufvalid)
341 * - Contains up to 4 bytes of the terminator
342 * ----------------------------------------------------
344 assert(((buf
== bufvalid
)
345 || (bufvalid
- buf
<= 4 && buf
[0] == 0x00)));
348 /* if we have the terminator, break */
349 if (end
&& bufvalid
- buf
== 4) {
350 assert(!memcmp(buf
, terminator
, 3));
359 vclient_close(vclient
);
363 XFREE(MTYPE_TMP
, buf
);
367 static int vtysh_client_run_all(struct vtysh_client
*head_client
,
368 const char *line
, int continue_on_err
,
369 void (*callback
)(void *, const char *),
372 struct vtysh_client
*client
;
373 int rc
, rc_all
= CMD_SUCCESS
;
374 int correct_instance
= 0, wrong_instance
= 0;
376 for (client
= head_client
; client
; client
= client
->next
) {
377 rc
= vtysh_client_run(client
, line
, callback
, cbarg
);
378 if (rc
== CMD_NOT_MY_INSTANCE
) {
384 if (rc
!= CMD_SUCCESS
) {
385 if (!continue_on_err
)
390 if (wrong_instance
&& !correct_instance
&& vty
->of
) {
392 "%% [%s]: command ignored as it targets an instance that is not running\n",
394 rc_all
= CMD_WARNING_CONFIG_FAILED
;
400 * Execute command against all daemons.
403 * where to start walking in the daemon list
406 * the specific command to execute
411 static int vtysh_client_execute(struct vtysh_client
*head_client
,
414 return vtysh_client_run_all(head_client
, line
, 0, NULL
, NULL
);
417 /* Execute by name */
418 static int vtysh_client_execute_name(const char *name
, const char *line
)
420 int ret
= CMD_SUCCESS
;
423 idx_client
= vtysh_client_lookup(name
);
424 if (idx_client
!= -1)
425 ret
= vtysh_client_execute(&vtysh_client
[idx_client
], line
);
427 vty_out(vty
, "Client not found\n");
435 * Retrieve all running config from daemons and parse it with the vtysh config
436 * parser. Returned output is not displayed to the user.
439 * where to start walking in the daemon list
442 * the specific command to execute
444 static void vtysh_client_config(struct vtysh_client
*head_client
, char *line
)
446 /* watchfrr currently doesn't load any config, and has some hardcoded
447 * settings that show up in "show run". skip it here (for now at
448 * least) so we don't get that mangled up in config-write.
450 if (head_client
->flag
== VTYSH_WATCHFRR
)
453 /* suppress output to user */
454 vty
->of_saved
= vty
->of
;
456 vtysh_client_run_all(head_client
, line
, 1, vtysh_config_parse_line
,
458 vty
->of
= vty
->of_saved
;
461 /* Command execution over the vty interface. */
462 static int vtysh_execute_func(const char *line
, int pager
)
467 const struct cmd_element
*cmd
;
469 int saved_ret
, saved_node
;
471 /* Split readline string up into the vector. */
472 vline
= cmd_make_strvec(line
);
478 if (strncmp("en", vector_slot(vline
, 0), 2) == 0) {
479 cmd_free_strvec(vline
);
480 vty_out(vty
, "%% Command not allowed: enable\n");
485 saved_ret
= ret
= cmd_execute(vty
, line
, &cmd
, 1);
486 saved_node
= vty
->node
;
489 * If command doesn't succeeded in current node, try to walk up in node
490 * tree. Changing vty->node is enough to try it just out without actual
491 * walkup in the vtysh.
493 while (ret
!= CMD_SUCCESS
&& ret
!= CMD_SUCCESS_DAEMON
494 && ret
!= CMD_WARNING
&& ret
!= CMD_WARNING_CONFIG_FAILED
495 && ret
!= CMD_ERR_AMBIGUOUS
&& ret
!= CMD_ERR_INCOMPLETE
496 && vty
->node
> CONFIG_NODE
) {
497 vty
->node
= node_parent(vty
->node
);
498 ret
= cmd_execute(vty
, line
, &cmd
, 1);
502 vty
->node
= saved_node
;
505 * If command succeeded in any other node than current (tried > 0) we
506 * have to move into node in the vtysh where it succeeded.
508 if (ret
== CMD_SUCCESS
|| ret
== CMD_SUCCESS_DAEMON
509 || ret
== CMD_WARNING
) {
510 if ((saved_node
== BGP_VPNV4_NODE
511 || saved_node
== BGP_VPNV6_NODE
512 || saved_node
== BGP_IPV4_NODE
513 || saved_node
== BGP_IPV6_NODE
514 || saved_node
== BGP_FLOWSPECV4_NODE
515 || saved_node
== BGP_FLOWSPECV6_NODE
516 || saved_node
== BGP_IPV4M_NODE
517 || saved_node
== BGP_IPV4L_NODE
518 || saved_node
== BGP_IPV6L_NODE
519 || saved_node
== BGP_IPV6M_NODE
520 || saved_node
== BGP_EVPN_NODE
521 || saved_node
== LDP_IPV4_NODE
522 || saved_node
== LDP_IPV6_NODE
)
524 vtysh_execute("exit-address-family");
525 } else if ((saved_node
== BGP_EVPN_VNI_NODE
) && (tried
== 1)) {
526 vtysh_execute("exit-vni");
527 } else if (saved_node
== BGP_VRF_POLICY_NODE
&& (tried
== 1)) {
528 vtysh_execute("exit-vrf-policy");
529 } else if ((saved_node
== BGP_VNC_DEFAULTS_NODE
530 || saved_node
== BGP_VNC_NVE_GROUP_NODE
531 || saved_node
== BGP_VNC_L2_GROUP_NODE
)
533 vtysh_execute("exit-vnc");
534 } else if (saved_node
== VRF_NODE
&& (tried
== 1)) {
535 vtysh_execute("exit-vrf");
536 } else if ((saved_node
== KEYCHAIN_KEY_NODE
537 || saved_node
== LDP_PSEUDOWIRE_NODE
538 || saved_node
== LDP_IPV4_IFACE_NODE
539 || saved_node
== LDP_IPV6_IFACE_NODE
)
541 vtysh_execute("exit");
543 vtysh_execute("end");
544 vtysh_execute("configure");
548 * If command didn't succeed in any node, continue with return value
555 cmd_free_strvec(vline
);
560 case CMD_WARNING_CONFIG_FAILED
:
561 if (vty
->type
== VTY_FILE
)
562 vty_out(vty
, "Warning...\n");
564 case CMD_ERR_AMBIGUOUS
:
565 vty_out(vty
, "%% Ambiguous command: %s\n", line
);
567 case CMD_ERR_NO_MATCH
:
568 vty_out(vty
, "%% Unknown command: %s\n", line
);
570 case CMD_ERR_INCOMPLETE
:
571 vty_out(vty
, "%% Command incomplete: %s\n", line
);
573 case CMD_SUCCESS_DAEMON
: {
575 * FIXME: Don't open pager for exit commands. popen() causes
576 * problems if exited from vtysh at all. This hack shouldn't
577 * cause any problem but is really ugly.
579 if (pager
&& strncmp(line
, "exit", 4))
582 if (!strcmp(cmd
->string
, "configure")) {
583 for (i
= 0; i
< array_size(vtysh_client
); i
++) {
584 cmd_stat
= vtysh_client_execute(
585 &vtysh_client
[i
], line
);
586 if (cmd_stat
== CMD_WARNING
)
592 vline
= cmd_make_strvec(line
);
597 vty_close_pager(vty
);
601 ret
= cmd_execute_command(vline
, vty
, &cmd
, 1);
602 cmd_free_strvec(vline
);
603 if (ret
!= CMD_SUCCESS_DAEMON
)
605 } else if (cmd
->func
) {
606 (*cmd
->func
)(cmd
, vty
, 0, NULL
);
611 cmd_stat
= CMD_SUCCESS
;
612 struct vtysh_client
*vc
;
613 for (i
= 0; i
< array_size(vtysh_client
); i
++) {
614 if (cmd
->daemon
& vtysh_client
[i
].flag
) {
615 if (vtysh_client
[i
].fd
< 0
616 && (cmd
->daemon
== vtysh_client
[i
].flag
)) {
617 for (vc
= &vtysh_client
[i
]; vc
;
619 if (vc
->fd
== VTYSH_WAS_ACTIVE
)
622 if (vtysh_client
[i
].fd
< 0
623 && (cmd
->daemon
== vtysh_client
[i
].flag
)) {
624 bool any_inst
= false;
625 for (vc
= &vtysh_client
[i
]; vc
;
631 "%s is not running\n",
632 vtysh_client
[i
].name
);
636 cmd_stat
= vtysh_client_execute(
637 &vtysh_client
[i
], line
);
638 if (cmd_stat
!= CMD_SUCCESS
)
642 if (cmd_stat
!= CMD_SUCCESS
)
646 (*cmd
->func
)(cmd
, vty
, 0, NULL
);
650 vty_close_pager(vty
);
655 int vtysh_execute_no_pager(const char *line
)
657 return vtysh_execute_func(line
, 0);
660 int vtysh_execute(const char *line
)
662 return vtysh_execute_func(line
, 1);
665 static char *trim(char *s
)
676 while (end
>= s
&& isspace((unsigned char)*end
))
680 while (*s
&& isspace((unsigned char)*s
))
686 int vtysh_mark_file(const char *filename
)
693 const struct cmd_element
*cmd
;
694 int saved_ret
, prev_node
;
696 char *vty_buf_copy
= NULL
;
697 char *vty_buf_trimmed
= NULL
;
699 if (strncmp("-", filename
, 1) == 0)
702 confp
= fopen(filename
, "r");
705 fprintf(stderr
, "%% Can't open config file %s due to '%s'.\n",
706 filename
, safe_strerror(errno
));
707 return (CMD_ERR_NO_FILE
);
711 vty
->wfd
= STDERR_FILENO
;
712 vty
->type
= VTY_TERM
;
713 vty
->node
= CONFIG_NODE
;
715 vtysh_execute_no_pager("enable");
716 vtysh_execute_no_pager("configure");
717 vty_buf_copy
= XCALLOC(MTYPE_VTYSH_CMD
, VTY_BUFSIZ
);
719 while (fgets(vty
->buf
, VTY_BUFSIZ
, confp
)) {
722 strlcpy(vty_buf_copy
, vty
->buf
, VTY_BUFSIZ
);
723 vty_buf_trimmed
= trim(vty_buf_copy
);
726 case LDP_IPV4_IFACE_NODE
:
727 if (strncmp(vty_buf_copy
, " ", 3)) {
728 vty_out(vty
, " exit-ldp-if\n");
729 vty
->node
= LDP_IPV4_NODE
;
732 case LDP_IPV6_IFACE_NODE
:
733 if (strncmp(vty_buf_copy
, " ", 3)) {
734 vty_out(vty
, " exit-ldp-if\n");
735 vty
->node
= LDP_IPV6_NODE
;
738 case LDP_PSEUDOWIRE_NODE
:
739 if (strncmp(vty_buf_copy
, " ", 2)) {
740 vty_out(vty
, " exit\n");
741 vty
->node
= LDP_L2VPN_NODE
;
748 if (vty_buf_trimmed
[0] == '!' || vty_buf_trimmed
[0] == '#') {
749 vty_out(vty
, "%s", vty
->buf
);
753 /* Split readline string up into the vector. */
754 vline
= cmd_make_strvec(vty
->buf
);
757 vty_out(vty
, "%s", vty
->buf
);
762 * Ignore the "end" lines, we will generate these where
765 if (strlen(vty_buf_trimmed
) == 3
766 && strncmp("end", vty_buf_trimmed
, 3) == 0) {
767 cmd_free_strvec(vline
);
771 prev_node
= vty
->node
;
772 saved_ret
= ret
= cmd_execute_command_strict(vline
, vty
, &cmd
);
775 * If command doesn't succeeded in current node, try to walk up
776 * in node tree. Changing vty->node is enough to try it just
777 * out without actual walkup in the vtysh.
779 while (ret
!= CMD_SUCCESS
&& ret
!= CMD_SUCCESS_DAEMON
780 && ret
!= CMD_WARNING
&& ret
!= CMD_WARNING_CONFIG_FAILED
781 && ret
!= CMD_ERR_AMBIGUOUS
&& ret
!= CMD_ERR_INCOMPLETE
782 && vty
->node
> CONFIG_NODE
) {
783 vty
->node
= node_parent(vty
->node
);
784 ret
= cmd_execute_command_strict(vline
, vty
, &cmd
);
789 * If command succeeded in any other node than current (tried >
790 * 0) we have to move into node in the vtysh where it
793 if (ret
== CMD_SUCCESS
|| ret
== CMD_SUCCESS_DAEMON
794 || ret
== CMD_WARNING
) {
795 if ((prev_node
== BGP_VPNV4_NODE
796 || prev_node
== BGP_VPNV6_NODE
797 || prev_node
== BGP_IPV4_NODE
798 || prev_node
== BGP_IPV6_NODE
799 || prev_node
== BGP_FLOWSPECV4_NODE
800 || prev_node
== BGP_FLOWSPECV6_NODE
801 || prev_node
== BGP_IPV4L_NODE
802 || prev_node
== BGP_IPV6L_NODE
803 || prev_node
== BGP_IPV4M_NODE
804 || prev_node
== BGP_IPV6M_NODE
805 || prev_node
== BGP_EVPN_NODE
)
807 vty_out(vty
, "exit-address-family\n");
808 } else if ((prev_node
== BGP_EVPN_VNI_NODE
)
810 vty_out(vty
, "exit-vni\n");
811 } else if ((prev_node
== KEYCHAIN_KEY_NODE
)
813 vty_out(vty
, "exit\n");
815 vty_out(vty
, "end\n");
819 * If command didn't succeed in any node, continue with return
820 * value from first try.
824 vty
->node
= prev_node
;
827 cmd_free_strvec(vline
);
830 case CMD_WARNING_CONFIG_FAILED
:
831 if (vty
->type
== VTY_FILE
)
832 fprintf(stderr
, "line %d: Warning...: %s\n",
836 XFREE(MTYPE_VTYSH_CMD
, vty_buf_copy
);
838 case CMD_ERR_AMBIGUOUS
:
839 fprintf(stderr
, "line %d: %% Ambiguous command: %s\n",
843 XFREE(MTYPE_VTYSH_CMD
, vty_buf_copy
);
844 return CMD_ERR_AMBIGUOUS
;
845 case CMD_ERR_NO_MATCH
:
846 fprintf(stderr
, "line %d: %% Unknown command: %s\n",
850 XFREE(MTYPE_VTYSH_CMD
, vty_buf_copy
);
851 return CMD_ERR_NO_MATCH
;
852 case CMD_ERR_INCOMPLETE
:
853 fprintf(stderr
, "line %d: %% Command incomplete: %s\n",
857 XFREE(MTYPE_VTYSH_CMD
, vty_buf_copy
);
858 return CMD_ERR_INCOMPLETE
;
860 vty_out(vty
, "%s", vty
->buf
);
861 if (strmatch(vty_buf_trimmed
, "exit-vrf"))
862 vty_out(vty
, "end\n");
864 case CMD_SUCCESS_DAEMON
: {
867 vty_out(vty
, "%s", vty
->buf
);
868 if (strmatch(vty_buf_trimmed
, "exit-vrf"))
869 vty_out(vty
, "end\n");
870 cmd_stat
= vtysh_client_execute(&vtysh_client
[0],
872 if (cmd_stat
!= CMD_SUCCESS
)
876 (*cmd
->func
)(cmd
, vty
, 0, NULL
);
880 /* This is the end */
881 vty_out(vty
, "\nend\n");
883 XFREE(MTYPE_VTYSH_CMD
, vty_buf_copy
);
891 /* Configration make from file. */
892 int vtysh_config_from_file(struct vty
*vty
, FILE *fp
)
895 const struct cmd_element
*cmd
;
897 /* once we have an error, we remember & return that */
898 int retcode
= CMD_SUCCESS
;
900 while (fgets(vty
->buf
, VTY_BUFSIZ
, fp
)) {
903 ret
= command_config_read_one_line(vty
, &cmd
, lineno
, 1);
907 case CMD_WARNING_CONFIG_FAILED
:
908 if (vty
->type
== VTY_FILE
)
909 fprintf(stderr
, "line %d: Warning[%d]...: %s\n",
910 lineno
, vty
->node
, vty
->buf
);
914 case CMD_ERR_AMBIGUOUS
:
916 "line %d: %% Ambiguous command[%d]: %s\n",
917 lineno
, vty
->node
, vty
->buf
);
918 retcode
= CMD_ERR_AMBIGUOUS
;
920 case CMD_ERR_NO_MATCH
:
921 fprintf(stderr
, "line %d: %% Unknown command[%d]: %s",
922 lineno
, vty
->node
, vty
->buf
);
923 retcode
= CMD_ERR_NO_MATCH
;
925 case CMD_ERR_INCOMPLETE
:
927 "line %d: %% Command incomplete[%d]: %s\n",
928 lineno
, vty
->node
, vty
->buf
);
929 retcode
= CMD_ERR_INCOMPLETE
;
931 case CMD_SUCCESS_DAEMON
: {
933 int cmd_stat
= CMD_SUCCESS
;
935 for (i
= 0; i
< array_size(vtysh_client
); i
++) {
936 if (cmd
->daemon
& vtysh_client
[i
].flag
) {
937 cmd_stat
= vtysh_client_execute(
938 &vtysh_client
[i
], vty
->buf
);
940 * CMD_WARNING - Can mean that the
941 * command was parsed successfully but
942 * it was already entered in a few
943 * spots. As such if we receive a
944 * CMD_WARNING from a daemon we
945 * shouldn't stop talking to the other
946 * daemons for the particular command.
948 if (cmd_stat
!= CMD_SUCCESS
949 && cmd_stat
!= CMD_WARNING
) {
951 "line %d: Failure to communicate[%d] to %s, line: %s\n",
953 vtysh_client
[i
].name
,
960 if (cmd_stat
!= CMD_SUCCESS
)
964 (*cmd
->func
)(cmd
, vty
, 0, NULL
);
973 * Function processes cli commands terminated with '?' character when entered
974 * through either 'vtysh' or 'vtysh -c' interfaces.
976 static int vtysh_process_questionmark(const char *input
, int input_len
)
980 vector vline
, describe
;
981 struct cmd_token
*token
;
986 vline
= cmd_make_strvec(input
);
988 /* In case of '> ?'. */
990 vline
= vector_init(1);
991 vector_set(vline
, NULL
);
992 } else if (input_len
&& isspace((unsigned char)input
[input_len
- 1]))
993 vector_set(vline
, NULL
);
995 describe
= cmd_describe_command(vline
, vty
, &ret
);
997 /* Ambiguous and no match error. */
999 case CMD_ERR_AMBIGUOUS
:
1000 cmd_free_strvec(vline
);
1001 vector_free(describe
);
1002 vty_out(vty
, "%% Ambiguous command.\n");
1006 case CMD_ERR_NO_MATCH
:
1007 cmd_free_strvec(vline
);
1009 vector_free(describe
);
1010 vty_out(vty
, "%% There is no matched command.\n");
1016 /* Get width of command string. */
1018 for (i
= 0; i
< vector_active(describe
); i
++)
1019 if ((token
= vector_slot(describe
, i
)) != NULL
) {
1020 if (token
->text
[0] == '\0')
1023 int len
= strlen(token
->text
);
1029 for (i
= 0; i
< vector_active(describe
); i
++)
1030 if ((token
= vector_slot(describe
, i
)) != NULL
) {
1032 vty_out(vty
, " %-s\n", token
->text
);
1034 vty_out(vty
, " %-*s %s\n", width
, token
->text
,
1037 if (IS_VARYING_TOKEN(token
->type
)) {
1038 const char *ref
= vector_slot(
1039 vline
, vector_active(vline
) - 1);
1041 vector varcomps
= vector_init(VECTOR_MIN_SIZE
);
1042 cmd_variable_complete(token
, ref
, varcomps
);
1044 if (vector_active(varcomps
) > 0) {
1046 rl_get_screen_size(&rows
, &cols
);
1048 char *ac
= cmd_variable_comp2str(
1050 vty_out(vty
, "%s\n", ac
);
1051 XFREE(MTYPE_TMP
, ac
);
1054 vector_free(varcomps
);
1058 cmd_free_strvec(vline
);
1059 vector_free(describe
);
1065 * Entry point for user commands terminated with '?' character and typed through
1066 * the usual vtysh's stdin interface. This is the function being registered with
1069 static int vtysh_rl_describe(int a
, int b
)
1075 ret
= vtysh_process_questionmark(rl_line_buffer
, rl_end
);
1082 * Function in charged of processing vtysh instructions terminating with '?'
1083 * character and received through the 'vtysh -c' interface. If user's
1084 * instruction is well-formatted, we will call the same processing routine
1085 * utilized by the traditional vtysh's stdin interface.
1087 int vtysh_execute_command_questionmark(char *input
)
1089 int input_len
, qmark_count
= 0;
1092 if (!(input
&& *input
))
1095 /* Finding out question_mark count and strlen */
1096 for (str
= input
; *str
; ++str
) {
1100 input_len
= str
- input
;
1103 * Verify that user's input terminates in '?' and that patterns such as
1104 * 'cmd ? subcmd ?' are prevented.
1106 if (qmark_count
!= 1 || input
[input_len
- 1] != '?')
1110 * Questionmark-processing function is not expecting to receive '?'
1111 * character in input string.
1113 input
[input_len
- 1] = '\0';
1115 return vtysh_process_questionmark(input
, input_len
- 1);
1118 /* Result of cmd_complete_command() call will be stored here
1119 * and used in new_completion() in order to put the space in
1120 * correct places only. */
1121 int complete_status
;
1123 static char *command_generator(const char *text
, int state
)
1126 static char **matched
= NULL
;
1127 static int index
= 0;
1133 if (vty
->node
== AUTH_NODE
|| vty
->node
== AUTH_ENABLE_NODE
)
1136 vline
= cmd_make_strvec(rl_line_buffer
);
1141 isspace((unsigned char)rl_line_buffer
[rl_end
- 1]))
1142 vector_set(vline
, NULL
);
1144 matched
= cmd_complete_command(vline
, vty
, &complete_status
);
1145 cmd_free_strvec(vline
);
1148 if (matched
&& matched
[index
])
1150 * this is free()'d by readline, but we leak 1 count of
1153 return matched
[index
++];
1155 XFREE(MTYPE_TMP
, matched
);
1160 static char **new_completion(const char *text
, int start
, int end
)
1164 matches
= rl_completion_matches(text
, command_generator
);
1168 if (complete_status
!= CMD_COMPLETE_FULL_MATCH
)
1169 /* only append a space on full match */
1170 rl_completion_append_character
= '\0';
1176 /* Vty node structures. */
1177 static struct cmd_node bgp_node
= {
1178 BGP_NODE
, "%s(config-router)# ",
1181 static struct cmd_node rip_node
= {
1182 RIP_NODE
, "%s(config-router)# ",
1185 static struct cmd_node isis_node
= {
1186 ISIS_NODE
, "%s(config-router)# ",
1189 static struct cmd_node openfabric_node
= {
1190 OPENFABRIC_NODE
, "%s(config-router)# ",
1193 static struct cmd_node interface_node
= {
1194 INTERFACE_NODE
, "%s(config-if)# ",
1197 static struct cmd_node pw_node
= {
1198 PW_NODE
, "%s(config-pw)# ",
1201 static struct cmd_node vrf_node
= {
1202 VRF_NODE
, "%s(config-vrf)# ",
1205 static struct cmd_node nh_group_node
= {
1207 "%s(config-nh-group)# ",
1210 static struct cmd_node rmap_node
= {RMAP_NODE
, "%s(config-route-map)# "};
1212 static struct cmd_node pbr_map_node
= {PBRMAP_NODE
, "%s(config-pbr-map)# "};
1214 static struct cmd_node zebra_node
= {ZEBRA_NODE
, "%s(config-router)# "};
1216 static struct cmd_node bgp_vpnv4_node
= {BGP_VPNV4_NODE
,
1217 "%s(config-router-af)# "};
1219 static struct cmd_node bgp_vpnv6_node
= {BGP_VPNV6_NODE
,
1220 "%s(config-router-af)# "};
1222 static struct cmd_node bgp_flowspecv4_node
= {BGP_FLOWSPECV4_NODE
,
1223 "%s(config-router-af)# "};
1225 static struct cmd_node bgp_flowspecv6_node
= {BGP_FLOWSPECV6_NODE
,
1226 "%s(config-router-af)# "};
1228 static struct cmd_node bgp_ipv4_node
= {BGP_IPV4_NODE
,
1229 "%s(config-router-af)# "};
1231 static struct cmd_node bgp_ipv4m_node
= {BGP_IPV4M_NODE
,
1232 "%s(config-router-af)# "};
1234 static struct cmd_node bgp_ipv4l_node
= {BGP_IPV4L_NODE
,
1235 "%s(config-router-af)# "};
1237 static struct cmd_node bgp_ipv6_node
= {BGP_IPV6_NODE
,
1238 "%s(config-router-af)# "};
1240 static struct cmd_node bgp_ipv6m_node
= {BGP_IPV6M_NODE
,
1241 "%s(config-router-af)# "};
1243 static struct cmd_node bgp_evpn_node
= {BGP_EVPN_NODE
,
1244 "%s(config-router-af)# "};
1246 static struct cmd_node bgp_evpn_vni_node
= {BGP_EVPN_VNI_NODE
,
1247 "%s(config-router-af-vni)# "};
1249 static struct cmd_node bgp_ipv6l_node
= {BGP_IPV6L_NODE
,
1250 "%s(config-router-af)# "};
1252 static struct cmd_node bgp_vnc_defaults_node
= {
1253 BGP_VNC_DEFAULTS_NODE
, "%s(config-router-vnc-defaults)# "};
1255 static struct cmd_node bgp_vnc_nve_group_node
= {
1256 BGP_VNC_NVE_GROUP_NODE
, "%s(config-router-vnc-nve-group)# "};
1258 static struct cmd_node bgp_vrf_policy_node
= {BGP_VRF_POLICY_NODE
,
1259 "%s(config-router-vrf-policy)# "};
1261 static struct cmd_node bgp_vnc_l2_group_node
= {
1262 BGP_VNC_L2_GROUP_NODE
, "%s(config-router-vnc-l2-group)# "};
1264 static struct cmd_node bmp_node
= {BMP_NODE
, "%s(config-bgp-bmp)# "};
1266 static struct cmd_node ospf_node
= {OSPF_NODE
, "%s(config-router)# "};
1268 static struct cmd_node eigrp_node
= {EIGRP_NODE
, "%s(config-router)# "};
1270 static struct cmd_node babel_node
= {BABEL_NODE
, "%s(config-router)# "};
1272 static struct cmd_node ripng_node
= {RIPNG_NODE
, "%s(config-router)# "};
1274 static struct cmd_node ospf6_node
= {OSPF6_NODE
, "%s(config-ospf6)# "};
1276 static struct cmd_node ldp_node
= {LDP_NODE
, "%s(config-ldp)# "};
1278 static struct cmd_node ldp_ipv4_node
= {LDP_IPV4_NODE
, "%s(config-ldp-af)# "};
1280 static struct cmd_node ldp_ipv6_node
= {LDP_IPV6_NODE
, "%s(config-ldp-af)# "};
1282 static struct cmd_node ldp_ipv4_iface_node
= {LDP_IPV4_IFACE_NODE
,
1283 "%s(config-ldp-af-if)# "};
1285 static struct cmd_node ldp_ipv6_iface_node
= {LDP_IPV6_IFACE_NODE
,
1286 "%s(config-ldp-af-if)# "};
1288 static struct cmd_node ldp_l2vpn_node
= {LDP_L2VPN_NODE
, "%s(config-l2vpn)# "};
1290 static struct cmd_node ldp_pseudowire_node
= {LDP_PSEUDOWIRE_NODE
,
1291 "%s(config-l2vpn-pw)# "};
1293 static struct cmd_node keychain_node
= {KEYCHAIN_NODE
, "%s(config-keychain)# "};
1295 static struct cmd_node keychain_key_node
= {KEYCHAIN_KEY_NODE
,
1296 "%s(config-keychain-key)# "};
1298 struct cmd_node link_params_node
= {
1299 LINK_PARAMS_NODE
, "%s(config-link-params)# ",
1302 static struct cmd_node rpki_node
= {RPKI_NODE
, "%s(config-rpki)# ", 1};
1305 static struct cmd_node bfd_node
= {
1310 static struct cmd_node bfd_peer_node
= {
1312 "%s(config-bfd-peer)# ",
1314 #endif /* HAVE_BFDD */
1316 /* Defined in lib/vty.c */
1317 extern struct cmd_node vty_node
;
1319 /* When '^Z' is received from vty, move down to the enable mode. */
1320 static int vtysh_end(void)
1322 switch (vty
->node
) {
1325 /* Nothing to do. */
1328 vty
->node
= ENABLE_NODE
;
1334 DEFUNSH(VTYSH_REALLYALL
, vtysh_end_all
, vtysh_end_all_cmd
, "end",
1335 "End current mode and change to enable mode\n")
1340 DEFUNSH(VTYSH_BGPD
, router_bgp
, router_bgp_cmd
,
1341 "router bgp [(1-4294967295) [<view|vrf> WORD]]",
1342 ROUTER_STR BGP_STR AS_STR
1343 "BGP view\nBGP VRF\n"
1346 vty
->node
= BGP_NODE
;
1350 #ifdef KEEP_OLD_VPN_COMMANDS
1351 DEFUNSH(VTYSH_BGPD
, address_family_vpnv4
, address_family_vpnv4_cmd
,
1352 "address-family vpnv4 [unicast]",
1353 "Enter Address Family command mode\n"
1355 "Address Family modifier\n")
1357 vty
->node
= BGP_VPNV4_NODE
;
1361 DEFUNSH(VTYSH_BGPD
, address_family_vpnv6
, address_family_vpnv6_cmd
,
1362 "address-family vpnv6 [unicast]",
1363 "Enter Address Family command mode\n"
1365 "Address Family modifier\n")
1367 vty
->node
= BGP_VPNV6_NODE
;
1370 #endif /* KEEP_OLD_VPN_COMMANDS */
1372 DEFUNSH(VTYSH_BGPD
, address_family_ipv4
, address_family_ipv4_cmd
,
1373 "address-family ipv4 [unicast]",
1374 "Enter Address Family command mode\n"
1376 "Address Family Modifier\n")
1378 vty
->node
= BGP_IPV4_NODE
;
1382 DEFUNSH(VTYSH_BGPD
, address_family_flowspecv4
, address_family_flowspecv4_cmd
,
1383 "address-family ipv4 flowspec",
1384 "Enter Address Family command mode\n"
1386 "Address Family Modifier\n")
1388 vty
->node
= BGP_FLOWSPECV4_NODE
;
1392 DEFUNSH(VTYSH_BGPD
, address_family_flowspecv6
, address_family_flowspecv6_cmd
,
1393 "address-family ipv6 flowspec",
1394 "Enter Address Family command mode\n"
1396 "Address Family Modifier\n")
1398 vty
->node
= BGP_FLOWSPECV6_NODE
;
1402 DEFUNSH(VTYSH_BGPD
, address_family_ipv4_multicast
,
1403 address_family_ipv4_multicast_cmd
, "address-family ipv4 multicast",
1404 "Enter Address Family command mode\n"
1406 "Address Family modifier\n")
1408 vty
->node
= BGP_IPV4M_NODE
;
1412 DEFUNSH(VTYSH_BGPD
, address_family_ipv4_vpn
, address_family_ipv4_vpn_cmd
,
1413 "address-family ipv4 vpn",
1414 "Enter Address Family command mode\n"
1416 "Address Family modifier\n")
1418 vty
->node
= BGP_VPNV4_NODE
;
1422 DEFUNSH(VTYSH_BGPD
, address_family_ipv4_labeled_unicast
,
1423 address_family_ipv4_labeled_unicast_cmd
,
1424 "address-family ipv4 labeled-unicast",
1425 "Enter Address Family command mode\n"
1427 "Address Family modifier\n")
1429 vty
->node
= BGP_IPV4L_NODE
;
1433 DEFUNSH(VTYSH_BGPD
, address_family_ipv6
, address_family_ipv6_cmd
,
1434 "address-family ipv6 [unicast]",
1435 "Enter Address Family command mode\n"
1437 "Address Family modifier\n")
1439 vty
->node
= BGP_IPV6_NODE
;
1443 DEFUNSH(VTYSH_BGPD
, address_family_ipv6_multicast
,
1444 address_family_ipv6_multicast_cmd
, "address-family ipv6 multicast",
1445 "Enter Address Family command mode\n"
1447 "Address Family modifier\n")
1449 vty
->node
= BGP_IPV6M_NODE
;
1453 DEFUNSH(VTYSH_BGPD
, address_family_ipv6_vpn
, address_family_ipv6_vpn_cmd
,
1454 "address-family ipv6 vpn",
1455 "Enter Address Family command mode\n"
1457 "Address Family modifier\n")
1459 vty
->node
= BGP_VPNV6_NODE
;
1463 DEFUNSH(VTYSH_BGPD
, address_family_ipv6_labeled_unicast
,
1464 address_family_ipv6_labeled_unicast_cmd
,
1465 "address-family ipv6 labeled-unicast",
1466 "Enter Address Family command mode\n"
1468 "Address Family modifier\n")
1470 vty
->node
= BGP_IPV6L_NODE
;
1478 "Enable rpki and enter rpki configuration mode\n")
1480 vty
->node
= RPKI_NODE
;
1487 "bmp targets BMPTARGETS",
1488 "BGP Monitoring Protocol\n"
1489 "Create BMP target group\n"
1490 "Name of the BMP target group\n")
1492 vty
->node
= BMP_NODE
;
1496 DEFUNSH(VTYSH_BGPD
, address_family_evpn
, address_family_evpn_cmd
,
1497 "address-family <l2vpn evpn>",
1498 "Enter Address Family command mode\n"
1500 "Address Family modifier\n")
1502 vty
->node
= BGP_EVPN_NODE
;
1506 #if defined(HAVE_CUMULUS)
1507 DEFUNSH_HIDDEN(VTYSH_BGPD
, address_family_evpn2
, address_family_evpn2_cmd
,
1508 "address-family evpn",
1509 "Enter Address Family command mode\n"
1510 "EVPN Address family\n")
1512 vty
->node
= BGP_EVPN_NODE
;
1517 DEFUNSH(VTYSH_BGPD
, bgp_evpn_vni
, bgp_evpn_vni_cmd
, "vni " CMD_VNI_RANGE
,
1518 "VXLAN Network Identifier\n"
1521 vty
->node
= BGP_EVPN_VNI_NODE
;
1525 #if defined(ENABLE_BGP_VNC)
1526 DEFUNSH(VTYSH_BGPD
, vnc_defaults
, vnc_defaults_cmd
, "vnc defaults",
1527 "VNC/RFP related configuration\n"
1528 "Configure default NVE group\n")
1530 vty
->node
= BGP_VNC_DEFAULTS_NODE
;
1534 DEFUNSH(VTYSH_BGPD
, vnc_nve_group
, vnc_nve_group_cmd
, "vnc nve-group NAME",
1535 "VNC/RFP related configuration\n"
1536 "Configure a NVE group\n"
1539 vty
->node
= BGP_VNC_NVE_GROUP_NODE
;
1543 DEFUNSH(VTYSH_BGPD
, vnc_vrf_policy
, vnc_vrf_policy_cmd
, "vrf-policy NAME",
1544 "Configure a VRF policy group\n"
1547 vty
->node
= BGP_VRF_POLICY_NODE
;
1551 DEFUNSH(VTYSH_BGPD
, vnc_l2_group
, vnc_l2_group_cmd
, "vnc l2-group NAME",
1552 "VNC/RFP related configuration\n"
1553 "Configure a L2 group\n"
1556 vty
->node
= BGP_VNC_L2_GROUP_NODE
;
1561 DEFUNSH(VTYSH_KEYS
, key_chain
, key_chain_cmd
, "key chain WORD",
1562 "Authentication key management\n"
1563 "Key-chain management\n"
1566 vty
->node
= KEYCHAIN_NODE
;
1570 DEFUNSH(VTYSH_KEYS
, key
, key_cmd
, "key (0-2147483647)",
1572 "Key identifier number\n")
1574 vty
->node
= KEYCHAIN_KEY_NODE
;
1578 DEFUNSH(VTYSH_RIPD
, router_rip
, router_rip_cmd
, "router rip [vrf NAME]",
1579 ROUTER_STR
"RIP\n" VRF_CMD_HELP_STR
)
1581 vty
->node
= RIP_NODE
;
1585 DEFUNSH(VTYSH_RIPNGD
, router_ripng
, router_ripng_cmd
, "router ripng [vrf NAME]",
1586 ROUTER_STR
"RIPng\n" VRF_CMD_HELP_STR
)
1588 vty
->node
= RIPNG_NODE
;
1592 DEFUNSH(VTYSH_OSPFD
, router_ospf
, router_ospf_cmd
,
1593 "router ospf [(1-65535)] [vrf NAME]",
1594 "Enable a routing process\n"
1595 "Start OSPF configuration\n"
1599 vty
->node
= OSPF_NODE
;
1603 DEFUNSH(VTYSH_EIGRPD
, router_eigrp
, router_eigrp_cmd
, "router eigrp (1-65535) [vrf NAME]",
1604 "Enable a routing process\n"
1605 "Start EIGRP configuration\n"
1606 "AS number to use\n"
1609 vty
->node
= EIGRP_NODE
;
1613 DEFUNSH(VTYSH_BABELD
, router_babel
, router_babel_cmd
, "router babel",
1614 "Enable a routing process\n"
1615 "Make Babel instance command\n")
1617 vty
->node
= BABEL_NODE
;
1621 DEFUNSH(VTYSH_OSPF6D
, router_ospf6
, router_ospf6_cmd
, "router ospf6",
1622 ROUTER_STR OSPF6_STR
)
1624 vty
->node
= OSPF6_NODE
;
1628 #if defined(HAVE_LDPD)
1629 DEFUNSH(VTYSH_LDPD
, ldp_mpls_ldp
, ldp_mpls_ldp_cmd
, "mpls ldp",
1630 "Global MPLS configuration subcommands\n"
1631 "Label Distribution Protocol\n")
1633 vty
->node
= LDP_NODE
;
1637 DEFUNSH(VTYSH_LDPD
, ldp_address_family_ipv4
, ldp_address_family_ipv4_cmd
,
1638 "address-family ipv4",
1639 "Configure Address Family and its parameters\n"
1642 vty
->node
= LDP_IPV4_NODE
;
1646 DEFUNSH(VTYSH_LDPD
, ldp_address_family_ipv6
, ldp_address_family_ipv6_cmd
,
1647 "address-family ipv6",
1648 "Configure Address Family and its parameters\n"
1651 vty
->node
= LDP_IPV6_NODE
;
1655 DEFUNSH(VTYSH_LDPD
, ldp_exit_address_family
, ldp_exit_address_family_cmd
,
1656 "exit-address-family", "Exit from Address Family configuration mode\n")
1658 if (vty
->node
== LDP_IPV4_NODE
|| vty
->node
== LDP_IPV6_NODE
)
1659 vty
->node
= LDP_NODE
;
1663 DEFUNSH(VTYSH_LDPD
, ldp_interface_ifname
, ldp_interface_ifname_cmd
,
1665 "Enable LDP on an interface and enter interface submode\n"
1666 "Interface's name\n")
1668 switch (vty
->node
) {
1670 vty
->node
= LDP_IPV4_IFACE_NODE
;
1673 vty
->node
= LDP_IPV6_IFACE_NODE
;
1682 DEFUNSH(VTYSH_LDPD
, ldp_l2vpn_word_type_vpls
, ldp_l2vpn_word_type_vpls_cmd
,
1683 "l2vpn WORD type vpls",
1684 "Configure l2vpn commands\n"
1687 "Virtual Private LAN Service\n")
1689 vty
->node
= LDP_L2VPN_NODE
;
1693 DEFUNSH(VTYSH_LDPD
, ldp_member_pseudowire_ifname
,
1694 ldp_member_pseudowire_ifname_cmd
, "member pseudowire IFNAME",
1695 "L2VPN member configuration\n"
1696 "Pseudowire interface\n"
1697 "Interface's name\n")
1699 vty
->node
= LDP_PSEUDOWIRE_NODE
;
1704 DEFUNSH(VTYSH_ISISD
, router_isis
, router_isis_cmd
, "router isis WORD",
1707 "ISO Routing area tag\n")
1709 vty
->node
= ISIS_NODE
;
1713 DEFUNSH(VTYSH_FABRICD
, router_openfabric
, router_openfabric_cmd
, "router openfabric WORD",
1715 "OpenFabric routing protocol\n"
1716 "ISO Routing area tag\n")
1718 vty
->node
= OPENFABRIC_NODE
;
1722 DEFUNSH(VTYSH_RMAP
, vtysh_route_map
, vtysh_route_map_cmd
,
1723 "route-map WORD <deny|permit> (1-65535)",
1724 "Create route-map or enter route-map command mode\n"
1726 "Route map denies set operations\n"
1727 "Route map permits set operations\n"
1728 "Sequence to insert to/delete from existing route-map entry\n")
1730 vty
->node
= RMAP_NODE
;
1734 DEFUNSH(VTYSH_PBRD
, vtysh_pbr_map
, vtysh_pbr_map_cmd
,
1735 "pbr-map PBRMAP seq (1-700)",
1736 "Create pbr-map or enter pbr-map command mode\n"
1737 "The name of the PBR MAP\n"
1738 "Sequence to insert to/delete from existing pbr-map entry\n"
1739 "Sequence number\n")
1741 vty
->node
= PBRMAP_NODE
;
1746 DEFUNSH(VTYSH_BFDD
, bfd_enter
, bfd_enter_cmd
, "bfd", "Configure BFD peers\n")
1748 vty
->node
= BFD_NODE
;
1752 DEFUNSH(VTYSH_BFDD
, bfd_peer_enter
, bfd_peer_enter_cmd
,
1753 "peer <A.B.C.D|X:X::X:X> [{multihop|local-address <A.B.C.D|X:X::X:X>|interface IFNAME|vrf NAME}]",
1755 "IPv4 peer address\n"
1756 "IPv6 peer address\n"
1757 "Configure multihop\n"
1758 "Configure local address\n"
1759 "IPv4 local address\n"
1760 "IPv6 local address\n"
1762 "Configure interface name to use\n"
1764 "Configure VRF name\n")
1766 vty
->node
= BFD_PEER_NODE
;
1769 #endif /* HAVE_BFDD */
1771 DEFSH(VTYSH_PBRD
, vtysh_no_pbr_map_cmd
, "no pbr-map PBRMAP [seq (1-700)]",
1774 "The name of the PBR MAP\n"
1775 "Sequence to delete from existing pbr-map entry\n"
1776 "Sequence number\n")
1778 DEFUNSH(VTYSH_ALL
, vtysh_line_vty
, vtysh_line_vty_cmd
, "line vty",
1779 "Configure a terminal line\n"
1780 "Virtual terminal\n")
1782 vty
->node
= VTY_NODE
;
1786 DEFUNSH(VTYSH_REALLYALL
, vtysh_enable
, vtysh_enable_cmd
, "enable",
1787 "Turn on privileged mode command\n")
1789 vty
->node
= ENABLE_NODE
;
1793 DEFUNSH(VTYSH_REALLYALL
, vtysh_disable
, vtysh_disable_cmd
, "disable",
1794 "Turn off privileged mode command\n")
1796 if (vty
->node
== ENABLE_NODE
)
1797 vty
->node
= VIEW_NODE
;
1801 DEFUNSH(VTYSH_REALLYALL
, vtysh_config_terminal
, vtysh_config_terminal_cmd
,
1802 "configure [terminal]",
1803 "Configuration from vty interface\n"
1804 "Configuration terminal\n")
1806 vty
->node
= CONFIG_NODE
;
1810 static int vtysh_exit(struct vty
*vty
)
1812 switch (vty
->node
) {
1818 vty
->node
= ENABLE_NODE
;
1820 case INTERFACE_NODE
:
1833 case LDP_L2VPN_NODE
:
1835 case OPENFABRIC_NODE
:
1842 vtysh_execute("end");
1843 vtysh_execute("configure");
1844 vty
->node
= CONFIG_NODE
;
1846 case BGP_VPNV4_NODE
:
1847 case BGP_VPNV6_NODE
:
1849 case BGP_IPV4M_NODE
:
1850 case BGP_IPV4L_NODE
:
1852 case BGP_IPV6M_NODE
:
1853 case BGP_IPV6L_NODE
:
1854 case BGP_FLOWSPECV4_NODE
:
1855 case BGP_FLOWSPECV6_NODE
:
1856 case BGP_VRF_POLICY_NODE
:
1858 case BGP_VNC_DEFAULTS_NODE
:
1859 case BGP_VNC_NVE_GROUP_NODE
:
1860 case BGP_VNC_L2_GROUP_NODE
:
1862 vty
->node
= BGP_NODE
;
1864 case BGP_EVPN_VNI_NODE
:
1865 vty
->node
= BGP_EVPN_NODE
;
1869 vty
->node
= LDP_NODE
;
1871 case LDP_IPV4_IFACE_NODE
:
1872 vty
->node
= LDP_IPV4_NODE
;
1874 case LDP_IPV6_IFACE_NODE
:
1875 vty
->node
= LDP_IPV6_NODE
;
1877 case LDP_PSEUDOWIRE_NODE
:
1878 vty
->node
= LDP_L2VPN_NODE
;
1880 case KEYCHAIN_KEY_NODE
:
1881 vty
->node
= KEYCHAIN_NODE
;
1883 case LINK_PARAMS_NODE
:
1884 vty
->node
= INTERFACE_NODE
;
1887 vty
->node
= BFD_NODE
;
1895 DEFUNSH(VTYSH_REALLYALL
, vtysh_exit_all
, vtysh_exit_all_cmd
, "exit",
1896 "Exit current mode and down to previous mode\n")
1898 return vtysh_exit(vty
);
1901 DEFUNSH(VTYSH_ALL
, vtysh_quit_all
, vtysh_quit_all_cmd
, "quit",
1902 "Exit current mode and down to previous mode\n")
1904 return vtysh_exit_all(self
, vty
, argc
, argv
);
1907 DEFUNSH(VTYSH_BGPD
, exit_address_family
, exit_address_family_cmd
,
1908 "exit-address-family", "Exit from Address Family configuration mode\n")
1910 if (vty
->node
== BGP_IPV4_NODE
|| vty
->node
== BGP_IPV4M_NODE
1911 || vty
->node
== BGP_IPV4L_NODE
|| vty
->node
== BGP_VPNV4_NODE
1912 || vty
->node
== BGP_VPNV6_NODE
|| vty
->node
== BGP_IPV6_NODE
1913 || vty
->node
== BGP_IPV6L_NODE
|| vty
->node
== BGP_IPV6M_NODE
1914 || vty
->node
== BGP_EVPN_NODE
1915 || vty
->node
== BGP_FLOWSPECV4_NODE
1916 || vty
->node
== BGP_FLOWSPECV6_NODE
)
1917 vty
->node
= BGP_NODE
;
1921 DEFUNSH(VTYSH_BGPD
, exit_vni
, exit_vni_cmd
, "exit-vni", "Exit from VNI mode\n")
1923 if (vty
->node
== BGP_EVPN_VNI_NODE
)
1924 vty
->node
= BGP_EVPN_NODE
;
1928 DEFUNSH(VTYSH_BGPD
, exit_vnc_config
, exit_vnc_config_cmd
, "exit-vnc",
1929 "Exit from VNC configuration mode\n")
1931 if (vty
->node
== BGP_VNC_DEFAULTS_NODE
1932 || vty
->node
== BGP_VNC_NVE_GROUP_NODE
1933 || vty
->node
== BGP_VNC_L2_GROUP_NODE
)
1934 vty
->node
= BGP_NODE
;
1939 DEFUNSH(VTYSH_BGPD
, rpki_exit
, rpki_exit_cmd
, "exit",
1940 "Exit current mode and down to previous mode\n")
1946 DEFUNSH(VTYSH_BGPD
, rpki_quit
, rpki_quit_cmd
, "quit",
1947 "Exit current mode and down to previous mode\n")
1949 return rpki_exit(self
, vty
, argc
, argv
);
1952 DEFUNSH(VTYSH_BGPD
, bmp_exit
, bmp_exit_cmd
, "exit",
1953 "Exit current mode and down to previous mode\n")
1959 DEFUNSH(VTYSH_BGPD
, bmp_quit
, bmp_quit_cmd
, "quit",
1960 "Exit current mode and down to previous mode\n")
1962 return bmp_exit(self
, vty
, argc
, argv
);
1965 DEFUNSH(VTYSH_VRF
, exit_vrf_config
, exit_vrf_config_cmd
, "exit-vrf",
1966 "Exit from VRF configuration mode\n")
1968 if (vty
->node
== VRF_NODE
)
1969 vty
->node
= CONFIG_NODE
;
1973 DEFUNSH(VTYSH_BGPD
, exit_vrf_policy
, exit_vrf_policy_cmd
, "exit-vrf-policy",
1974 "Exit from VRF policy configuration mode\n")
1976 if (vty
->node
== BGP_VRF_POLICY_NODE
)
1977 vty
->node
= BGP_NODE
;
1981 DEFUNSH(VTYSH_RIPD
, vtysh_exit_ripd
, vtysh_exit_ripd_cmd
, "exit",
1982 "Exit current mode and down to previous mode\n")
1984 return vtysh_exit(vty
);
1987 DEFUNSH(VTYSH_RIPD
, vtysh_quit_ripd
, vtysh_quit_ripd_cmd
, "quit",
1988 "Exit current mode and down to previous mode\n")
1990 return vtysh_exit_ripd(self
, vty
, argc
, argv
);
1993 DEFUNSH(VTYSH_RIPNGD
, vtysh_exit_ripngd
, vtysh_exit_ripngd_cmd
, "exit",
1994 "Exit current mode and down to previous mode\n")
1996 return vtysh_exit(vty
);
1999 DEFUNSH(VTYSH_RIPNGD
, vtysh_quit_ripngd
, vtysh_quit_ripngd_cmd
, "quit",
2000 "Exit current mode and down to previous mode\n")
2002 return vtysh_exit_ripngd(self
, vty
, argc
, argv
);
2005 DEFUNSH(VTYSH_RMAP
, vtysh_exit_rmap
, vtysh_exit_rmap_cmd
, "exit",
2006 "Exit current mode and down to previous mode\n")
2008 return vtysh_exit(vty
);
2011 DEFUNSH(VTYSH_RMAP
, vtysh_quit_rmap
, vtysh_quit_rmap_cmd
, "quit",
2012 "Exit current mode and down to previous mode\n")
2014 return vtysh_exit_rmap(self
, vty
, argc
, argv
);
2017 DEFUNSH(VTYSH_PBRD
, vtysh_exit_pbr_map
, vtysh_exit_pbr_map_cmd
, "exit",
2018 "Exit current mode and down to previous mode\n")
2020 return vtysh_exit(vty
);
2023 DEFUNSH(VTYSH_PBRD
, vtysh_quit_pbr_map
, vtysh_quit_pbr_map_cmd
, "quit",
2024 "Exit current mode and down to previous mode\n")
2026 return vtysh_exit_rmap(self
, vty
, argc
, argv
);
2029 DEFUNSH(VTYSH_BGPD
, vtysh_exit_bgpd
, vtysh_exit_bgpd_cmd
, "exit",
2030 "Exit current mode and down to previous mode\n")
2032 return vtysh_exit(vty
);
2035 DEFUNSH(VTYSH_BGPD
, vtysh_quit_bgpd
, vtysh_quit_bgpd_cmd
, "quit",
2036 "Exit current mode and down to previous mode\n")
2038 return vtysh_exit_bgpd(self
, vty
, argc
, argv
);
2041 DEFUNSH(VTYSH_OSPFD
, vtysh_exit_ospfd
, vtysh_exit_ospfd_cmd
, "exit",
2042 "Exit current mode and down to previous mode\n")
2044 return vtysh_exit(vty
);
2047 DEFUNSH(VTYSH_OSPFD
, vtysh_quit_ospfd
, vtysh_quit_ospfd_cmd
, "quit",
2048 "Exit current mode and down to previous mode\n")
2050 return vtysh_exit_ospfd(self
, vty
, argc
, argv
);
2053 DEFUNSH(VTYSH_EIGRPD
, vtysh_exit_eigrpd
, vtysh_exit_eigrpd_cmd
, "exit",
2054 "Exit current mode and down to previous mode\n")
2056 return vtysh_exit(vty
);
2059 DEFUNSH(VTYSH_EIGRPD
, vtysh_quit_eigrpd
, vtysh_quit_eigrpd_cmd
, "quit",
2060 "Exit current mode and down to previous mode\n")
2062 return vtysh_exit(vty
);
2065 DEFUNSH(VTYSH_EIGRPD
, vtysh_exit_babeld
, vtysh_exit_babeld_cmd
, "exit",
2066 "Exit current mode and down to previous mode\n")
2068 return vtysh_exit(vty
);
2071 DEFUNSH(VTYSH_BABELD
, vtysh_quit_babeld
, vtysh_quit_babeld_cmd
, "quit",
2072 "Exit current mode and down to previous mode\n")
2074 return vtysh_exit(vty
);
2077 DEFUNSH(VTYSH_OSPF6D
, vtysh_exit_ospf6d
, vtysh_exit_ospf6d_cmd
, "exit",
2078 "Exit current mode and down to previous mode\n")
2080 return vtysh_exit(vty
);
2083 DEFUNSH(VTYSH_OSPF6D
, vtysh_quit_ospf6d
, vtysh_quit_ospf6d_cmd
, "quit",
2084 "Exit current mode and down to previous mode\n")
2086 return vtysh_exit_ospf6d(self
, vty
, argc
, argv
);
2089 #if defined(HAVE_LDPD)
2090 DEFUNSH(VTYSH_LDPD
, vtysh_exit_ldpd
, vtysh_exit_ldpd_cmd
, "exit",
2091 "Exit current mode and down to previous mode\n")
2093 return vtysh_exit(vty
);
2096 ALIAS(vtysh_exit_ldpd
, vtysh_quit_ldpd_cmd
, "quit",
2097 "Exit current mode and down to previous mode\n")
2100 DEFUNSH(VTYSH_ISISD
, vtysh_exit_isisd
, vtysh_exit_isisd_cmd
, "exit",
2101 "Exit current mode and down to previous mode\n")
2103 return vtysh_exit(vty
);
2106 DEFUNSH(VTYSH_ISISD
, vtysh_quit_isisd
, vtysh_quit_isisd_cmd
, "quit",
2107 "Exit current mode and down to previous mode\n")
2109 return vtysh_exit_isisd(self
, vty
, argc
, argv
);
2113 DEFUNSH(VTYSH_BFDD
, vtysh_exit_bfdd
, vtysh_exit_bfdd_cmd
, "exit",
2114 "Exit current mode and down to previous mode\n")
2116 return vtysh_exit(vty
);
2119 ALIAS(vtysh_exit_bfdd
, vtysh_quit_bfdd_cmd
, "quit",
2120 "Exit current mode and down to previous mode\n")
2123 DEFUNSH(VTYSH_FABRICD
, vtysh_exit_fabricd
, vtysh_exit_fabricd_cmd
, "exit",
2124 "Exit current mode and down to previous mode\n")
2126 return vtysh_exit(vty
);
2129 DEFUNSH(VTYSH_FABRICD
, vtysh_quit_fabricd
, vtysh_quit_fabricd_cmd
, "quit",
2130 "Exit current mode and down to previous mode\n")
2132 return vtysh_exit_fabricd(self
, vty
, argc
, argv
);
2135 DEFUNSH(VTYSH_ALL
, vtysh_exit_line_vty
, vtysh_exit_line_vty_cmd
, "exit",
2136 "Exit current mode and down to previous mode\n")
2138 return vtysh_exit(vty
);
2141 DEFUNSH(VTYSH_ALL
, vtysh_quit_line_vty
, vtysh_quit_line_vty_cmd
, "quit",
2142 "Exit current mode and down to previous mode\n")
2144 return vtysh_exit_line_vty(self
, vty
, argc
, argv
);
2147 DEFUNSH(VTYSH_INTERFACE
, vtysh_interface
, vtysh_interface_cmd
,
2148 "interface IFNAME [vrf NAME]",
2149 "Select an interface to configure\n"
2150 "Interface's name\n" VRF_CMD_HELP_STR
)
2152 vty
->node
= INTERFACE_NODE
;
2156 DEFUNSH(VTYSH_ZEBRA
, vtysh_pseudowire
, vtysh_pseudowire_cmd
,
2157 "pseudowire IFNAME",
2158 "Static pseudowire configuration\n"
2159 "Pseudowire name\n")
2161 vty
->node
= PW_NODE
;
2165 DEFUNSH(VTYSH_NH_GROUP
,
2166 vtysh_nexthop_group
, vtysh_nexthop_group_cmd
,
2167 "nexthop-group NHGNAME",
2168 "Nexthop Group configuration\n"
2169 "Name of the Nexthop Group\n")
2171 vty
->node
= NH_GROUP_NODE
;
2175 DEFSH(VTYSH_NH_GROUP
, vtysh_no_nexthop_group_cmd
,
2176 "no nexthop-group NHGNAME",
2178 "Nexthop Group Configuration\n"
2179 "Name of the Nexthop Group\n")
2181 DEFUNSH(VTYSH_VRF
, vtysh_vrf
, vtysh_vrf_cmd
, "vrf NAME",
2182 "Select a VRF to configure\n"
2185 vty
->node
= VRF_NODE
;
2189 DEFSH(VTYSH_ZEBRA
, vtysh_vrf_netns_cmd
,
2191 "Attach VRF to a Namespace\n"
2192 "The file name in " NS_RUN_DIR
", or a full pathname\n")
2194 DEFSH(VTYSH_ZEBRA
, vtysh_no_vrf_netns_cmd
,
2197 "Detach VRF from a Namespace\n"
2198 "The file name in " NS_RUN_DIR
", or a full pathname\n")
2200 DEFUNSH(VTYSH_VRF
, vtysh_exit_vrf
, vtysh_exit_vrf_cmd
, "exit",
2201 "Exit current mode and down to previous mode\n")
2203 return vtysh_exit(vty
);
2206 DEFUNSH(VTYSH_VRF
, vtysh_quit_vrf
, vtysh_quit_vrf_cmd
, "quit",
2207 "Exit current mode and down to previous mode\n")
2209 return vtysh_exit_vrf(self
, vty
, argc
, argv
);
2212 DEFUNSH(VTYSH_NH_GROUP
,
2213 vtysh_exit_nexthop_group
, vtysh_exit_nexthop_group_cmd
,
2214 "exit", "Exit current mode and down to previous mode\n")
2216 return vtysh_exit(vty
);
2219 DEFUNSH(VTYSH_NH_GROUP
,
2220 vtysh_quit_nexthop_group
, vtysh_quit_nexthop_group_cmd
,
2221 "quit", "Exit current mode and down to previous mode\n")
2223 return vtysh_exit_nexthop_group(self
, vty
, argc
, argv
);
2226 DEFUNSH(VTYSH_INTERFACE
, vtysh_exit_interface
, vtysh_exit_interface_cmd
, "exit",
2227 "Exit current mode and down to previous mode\n")
2229 return vtysh_exit(vty
);
2232 DEFUNSH(VTYSH_INTERFACE
, vtysh_quit_interface
, vtysh_quit_interface_cmd
, "quit",
2233 "Exit current mode and down to previous mode\n")
2235 return vtysh_exit_interface(self
, vty
, argc
, argv
);
2238 DEFUN (vtysh_show_poll
,
2239 vtysh_show_poll_cmd
,
2242 "Thread information\n"
2243 "Thread Poll Information\n")
2246 int ret
= CMD_SUCCESS
;
2249 snprintf(line
, sizeof(line
), "do show thread poll\n");
2250 for (i
= 0; i
< array_size(vtysh_client
); i
++)
2251 if (vtysh_client
[i
].fd
>= 0) {
2252 vty_out(vty
, "Thread statistics for %s:\n",
2253 vtysh_client
[i
].name
);
2254 ret
= vtysh_client_execute(&vtysh_client
[i
], line
);
2260 #ifndef EXCLUDE_CPU_TIME
2261 DEFUN (vtysh_show_thread
,
2262 vtysh_show_thread_cmd
,
2263 "show thread cpu [FILTER]",
2265 "Thread information\n"
2266 "Thread CPU usage\n"
2267 "Display filter (rwtexb)\n")
2271 int ret
= CMD_SUCCESS
;
2274 const char *filter
=
2275 argv_find(argv
, argc
, "FILTER", &idx
) ? argv
[idx
]->arg
: "";
2277 snprintf(line
, sizeof(line
), "do show thread cpu %s\n", filter
);
2278 for (i
= 0; i
< array_size(vtysh_client
); i
++)
2279 if (vtysh_client
[i
].fd
>= 0) {
2280 vty_out(vty
, "Thread statistics for %s:\n",
2281 vtysh_client
[i
].name
);
2282 ret
= vtysh_client_execute(&vtysh_client
[i
], line
);
2289 DEFUN (vtysh_show_work_queues
,
2290 vtysh_show_work_queues_cmd
,
2293 "Work Queue information\n")
2296 int ret
= CMD_SUCCESS
;
2297 char line
[] = "do show work-queues\n";
2299 for (i
= 0; i
< array_size(vtysh_client
); i
++)
2300 if (vtysh_client
[i
].fd
>= 0) {
2301 vty_out(vty
, "Work queue statistics for %s:\n",
2302 vtysh_client
[i
].name
);
2303 ret
= vtysh_client_execute(&vtysh_client
[i
], line
);
2310 DEFUN (vtysh_show_work_queues_daemon
,
2311 vtysh_show_work_queues_daemon_cmd
,
2312 "show work-queues " DAEMONS_LIST
,
2314 "Work Queue information\n"
2317 int idx_protocol
= 2;
2319 return vtysh_client_execute_name(argv
[idx_protocol
]->text
,
2320 "show work-queues\n");
2323 DEFUNSH(VTYSH_ZEBRA
, vtysh_link_params
, vtysh_link_params_cmd
, "link-params",
2326 vty
->node
= LINK_PARAMS_NODE
;
2330 DEFUNSH(VTYSH_ZEBRA
, exit_link_params
, exit_link_params_cmd
, "exit-link-params",
2331 "Exit from Link Params configuration node\n")
2333 if (vty
->node
== LINK_PARAMS_NODE
)
2334 vty
->node
= INTERFACE_NODE
;
2338 static int show_per_daemon(const char *line
, const char *headline
)
2341 int ret
= CMD_SUCCESS
;
2343 for (i
= 0; i
< array_size(vtysh_client
); i
++)
2344 if (vtysh_client
[i
].fd
>= 0) {
2345 vty_out(vty
, headline
, vtysh_client
[i
].name
);
2346 ret
= vtysh_client_execute(&vtysh_client
[i
], line
);
2353 DEFUNSH_HIDDEN (0x00,
2355 vtysh_debug_all_cmd
,
2359 "Toggle all debugs on or off\n")
2364 DEFUN (vtysh_show_debugging
,
2365 vtysh_show_debugging_cmd
,
2370 return show_per_daemon("do show debugging\n", "");
2373 DEFUN (vtysh_show_debugging_hashtable
,
2374 vtysh_show_debugging_hashtable_cmd
,
2375 "show debugging hashtable [statistics]",
2378 "Statistics about hash tables\n"
2379 "Statistics about hash tables\n")
2383 "Load factor (LF) - average number of elements across all buckets\n");
2385 "Full load factor (FLF) - average number of elements across full buckets\n\n");
2387 "Standard deviation (SD) is calculated for both the LF and FLF\n");
2389 "and indicates the typical deviation of bucket chain length\n");
2390 vty_out(vty
, "from the value in the corresponding load factor.\n\n");
2392 return show_per_daemon("do show debugging hashtable\n",
2393 "Hashtable statistics for %s:\n");
2396 DEFUN (vtysh_show_error_code
,
2397 vtysh_show_error_code_cmd
,
2398 "show error <(1-4294967296)|all> [json]",
2400 "Information on errors\n"
2401 "Error code to get info about\n"
2402 "Information on all errors\n"
2407 if (!strmatch(argv
[2]->text
, "all"))
2408 arg
= strtoul(argv
[2]->arg
, NULL
, 10);
2410 /* If it's not a shared code, send it to all the daemons */
2411 if (arg
< LIB_FERR_START
|| arg
> LIB_FERR_END
) {
2412 char *fcmd
= argv_concat(argv
, argc
, 0);
2415 snprintf(cmd
, sizeof(cmd
), "do %s", fcmd
);
2416 show_per_daemon(cmd
, "");
2417 XFREE(MTYPE_TMP
, fcmd
);
2418 /* Otherwise, print it ourselves to avoid duplication */
2420 bool json
= strmatch(argv
[argc
- 1]->text
, "json");
2422 if (!strmatch(argv
[2]->text
, "all"))
2423 arg
= strtoul(argv
[2]->arg
, NULL
, 10);
2425 log_ref_display(vty
, arg
, json
);
2432 DEFUN (show_yang_operational_data
,
2433 show_yang_operational_data_cmd
,
2434 "show yang operational-data XPATH\
2440 "YANG information\n"
2441 "Show YANG operational data\n"
2442 "XPath expression specifying the YANG data path\n"
2443 "Set the output format\n"
2444 "JavaScript Object Notation\n"
2445 "Extensible Markup Language\n"
2446 "Translate operational data\n"
2447 "YANG module translator\n"
2450 int idx_protocol
= argc
- 1;
2451 char *fcmd
= argv_concat(argv
, argc
- 1, 0);
2452 int ret
= vtysh_client_execute_name(argv
[idx_protocol
]->text
, fcmd
);
2453 XFREE(MTYPE_TMP
, fcmd
);
2457 DEFUNSH(VTYSH_ALL
, debug_nb
,
2459 "[no] debug northbound\
2461 callbacks [{configuration|state|rpc}]\
2468 "Northbound debugging\n"
2475 "libyang debugging\n")
2481 DEFUN (vtysh_show_memory
,
2482 vtysh_show_memory_cmd
,
2485 "Memory statistics\n")
2487 return show_per_daemon("do show memory\n", "Memory statistics for %s:\n");
2490 DEFUN (vtysh_show_modules
,
2491 vtysh_show_modules_cmd
,
2496 return show_per_daemon("do show modules\n",
2497 "Module information for %s:\n");
2500 /* Logging commands. */
2501 DEFUN (vtysh_show_logging
,
2502 vtysh_show_logging_cmd
,
2505 "Show current logging configuration\n")
2507 return show_per_daemon("do show logging\n",
2508 "Logging configuration for %s:\n");
2511 DEFUNSH(VTYSH_ALL
, vtysh_log_stdout
, vtysh_log_stdout_cmd
, "log stdout",
2513 "Set stdout logging level\n")
2518 DEFUNSH(VTYSH_ALL
, vtysh_log_stdout_level
, vtysh_log_stdout_level_cmd
,
2519 "log stdout <emergencies|alerts|critical|errors|warnings|notifications|informational|debugging>",
2521 "Set stdout logging level\n" LOG_LEVEL_DESC
)
2526 DEFUNSH(VTYSH_ALL
, no_vtysh_log_stdout
, no_vtysh_log_stdout_cmd
,
2527 "no log stdout [LEVEL]", NO_STR
2529 "Cancel logging to stdout\n"
2535 DEFUNSH(VTYSH_ALL
, vtysh_log_file
, vtysh_log_file_cmd
, "log file FILENAME",
2538 "Logging filename\n")
2543 DEFUNSH(VTYSH_ALL
, vtysh_log_file_level
, vtysh_log_file_level_cmd
,
2544 "log file FILENAME <emergencies|alerts|critical|errors|warnings|notifications|informational|debugging>",
2547 "Logging filename\n" LOG_LEVEL_DESC
)
2552 DEFUNSH(VTYSH_ALL
, no_vtysh_log_file
, no_vtysh_log_file_cmd
,
2553 "no log file [FILENAME [LEVEL]]", NO_STR
2555 "Cancel logging to file\n"
2556 "Logging file name\n"
2562 DEFUNSH(VTYSH_ALL
, vtysh_log_monitor
, vtysh_log_monitor_cmd
,
2563 "log monitor [<emergencies|alerts|critical|errors|warnings|notifications|informational|debugging>]",
2565 "Set terminal line (monitor) logging level\n" LOG_LEVEL_DESC
)
2570 DEFUNSH(VTYSH_ALL
, no_vtysh_log_monitor
, no_vtysh_log_monitor_cmd
,
2571 "no log monitor [LEVEL]", NO_STR
2573 "Disable terminal line (monitor) logging\n"
2579 DEFUNSH(VTYSH_ALL
, vtysh_log_syslog
, vtysh_log_syslog_cmd
,
2580 "log syslog [<emergencies|alerts|critical|errors|warnings|notifications|informational|debugging>]",
2582 "Set syslog logging level\n" LOG_LEVEL_DESC
)
2587 DEFUNSH(VTYSH_ALL
, no_vtysh_log_syslog
, no_vtysh_log_syslog_cmd
,
2588 "no log syslog [<emergencies|alerts|critical|errors|warnings|notifications|informational|debugging>]",
2591 "Cancel logging to syslog\n"
2597 DEFUNSH(VTYSH_ALL
, vtysh_log_facility
, vtysh_log_facility_cmd
,
2598 "log facility <kern|user|mail|daemon|auth|syslog|lpr|news|uucp|cron|local0|local1|local2|local3|local4|local5|local6|local7>",
2600 "Facility parameter for syslog messages\n" LOG_FACILITY_DESC
)
2605 DEFUNSH(VTYSH_ALL
, no_vtysh_log_facility
, no_vtysh_log_facility_cmd
,
2606 "no log facility [<kern|user|mail|daemon|auth|syslog|lpr|news|uucp|cron|local0|local1|local2|local3|local4|local5|local6|local7>]",
2609 "Reset syslog facility to default (daemon)\n"
2615 DEFUNSH(VTYSH_ALL
, vtysh_log_record_priority
, vtysh_log_record_priority_cmd
,
2616 "log record-priority",
2618 "Log the priority of the message within the message\n")
2623 DEFUNSH(VTYSH_ALL
, no_vtysh_log_record_priority
,
2624 no_vtysh_log_record_priority_cmd
, "no log record-priority", NO_STR
2626 "Do not log the priority of the message within the message\n")
2631 DEFUNSH(VTYSH_ALL
, vtysh_log_timestamp_precision
,
2632 vtysh_log_timestamp_precision_cmd
, "log timestamp precision (0-6)",
2634 "Timestamp configuration\n"
2635 "Set the timestamp precision\n"
2636 "Number of subsecond digits\n")
2641 DEFUNSH(VTYSH_ALL
, vtysh_debug_memstats
,
2642 vtysh_debug_memstats_cmd
, "[no] debug memstats-at-exit",
2645 "Print memory statistics at exit\n")
2650 DEFUNSH(VTYSH_ALL
, no_vtysh_log_timestamp_precision
,
2651 no_vtysh_log_timestamp_precision_cmd
, "no log timestamp precision",
2654 "Timestamp configuration\n"
2655 "Reset the timestamp precision to the default value of 0\n")
2660 DEFUNSH(VTYSH_ALL
, vtysh_service_password_encrypt
,
2661 vtysh_service_password_encrypt_cmd
, "service password-encryption",
2662 "Set up miscellaneous service\n"
2663 "Enable encrypted passwords\n")
2668 DEFUNSH(VTYSH_ALL
, no_vtysh_service_password_encrypt
,
2669 no_vtysh_service_password_encrypt_cmd
, "no service password-encryption",
2671 "Set up miscellaneous service\n"
2672 "Enable encrypted passwords\n")
2677 DEFUNSH(VTYSH_ALL
, vtysh_config_password
, vtysh_password_cmd
,
2678 "password [(8-8)] LINE",
2679 "Modify the terminal connection password\n"
2680 "Specifies a HIDDEN password will follow\n"
2681 "The password string\n")
2686 DEFUNSH(VTYSH_ALL
, no_vtysh_config_password
, no_vtysh_password_cmd
,
2687 "no password", NO_STR
2688 "Modify the terminal connection password\n")
2690 vty_out(vty
, NO_PASSWD_CMD_WARNING
);
2695 DEFUNSH(VTYSH_ALL
, vtysh_config_enable_password
, vtysh_enable_password_cmd
,
2696 "enable password [(8-8)] LINE",
2697 "Modify enable password parameters\n"
2698 "Assign the privileged level password\n"
2699 "Specifies a HIDDEN password will follow\n"
2700 "The 'enable' password string\n")
2705 DEFUNSH(VTYSH_ALL
, no_vtysh_config_enable_password
,
2706 no_vtysh_enable_password_cmd
, "no enable password", NO_STR
2707 "Modify enable password parameters\n"
2708 "Assign the privileged level password\n")
2710 vty_out(vty
, NO_PASSWD_CMD_WARNING
);
2716 DEFUN (vtysh_log_filter
,
2717 vtysh_log_filter_cmd
,
2718 "[no] log-filter WORD ["DAEMONS_LIST
"]",
2721 "String to filter by\n"
2724 char *filter
= NULL
;
2725 char *daemon
= NULL
;
2732 char line
[ZLOG_FILTER_LENGTH_MAX
+ 20];
2734 found
= argv_find(argv
, argc
, "no", &idx
);
2736 len
= snprintf(line
, sizeof(line
), "no log-filter");
2739 len
= snprintf(line
, sizeof(line
), "log-filter");
2744 found
= argv_find(argv
, argc
, "WORD", &idx
);
2746 vty_out(vty
, "%% No filter string given\n");
2749 filter
= argv
[idx
]->arg
;
2751 if (strnlen(filter
, ZLOG_FILTER_LENGTH_MAX
+ 1)
2752 > ZLOG_FILTER_LENGTH_MAX
) {
2753 vty_out(vty
, "%% Filter is too long\n");
2757 len
= snprintf(line
+ total_len
, sizeof(line
) - total_len
, " %s\n",
2760 if ((len
< 0) || (size_t)(total_len
+ len
) > sizeof(line
)) {
2761 vty_out(vty
, "%% Error buffering filter to daemons\n");
2762 return CMD_ERR_INCOMPLETE
;
2765 if (argc
>= (daemon_idx
+ 1))
2766 daemon
= argv
[daemon_idx
]->text
;
2768 if (daemon
!= NULL
) {
2769 vty_out(vty
, "Applying log filter change to %s:\n", daemon
);
2770 return vtysh_client_execute_name(daemon
, line
);
2772 return show_per_daemon(line
,
2773 "Applying log filter change to %s:\n");
2776 /* Clear log filters */
2777 DEFUN (vtysh_log_filter_clear
,
2778 vtysh_log_filter_clear_cmd
,
2779 "log-filter clear ["DAEMONS_LIST
"]",
2784 char *daemon
= NULL
;
2787 char line
[] = "clear log-filter\n";
2789 if (argc
>= (daemon_idx
+ 1))
2790 daemon
= argv
[daemon_idx
]->text
;
2792 if (daemon
!= NULL
) {
2793 vty_out(vty
, "Clearing all filters applied to %s:\n", daemon
);
2794 return vtysh_client_execute_name(daemon
, line
);
2796 return show_per_daemon(line
,
2797 "Clearing all filters applied to %s:\n");
2800 /* Show log filter */
2801 DEFUN (vtysh_show_log_filter
,
2802 vtysh_show_log_filter_cmd
,
2807 char line
[] = "do show log-filter\n";
2809 return show_per_daemon(line
, "Log filters applied to %s:\n");
2812 DEFUN (vtysh_write_terminal
,
2813 vtysh_write_terminal_cmd
,
2814 "write terminal ["DAEMONS_LIST
"]",
2815 "Write running configuration to memory, network, or terminal\n"
2816 "Write to terminal\n"
2820 char line
[] = "do write terminal\n";
2822 vty_out(vty
, "Building configuration...\n");
2823 vty_out(vty
, "\nCurrent configuration:\n");
2824 vty_out(vty
, "!\n");
2826 for (i
= 0; i
< array_size(vtysh_client
); i
++)
2828 || (strmatch(vtysh_client
[i
].name
, argv
[2]->text
)))
2829 vtysh_client_config(&vtysh_client
[i
], line
);
2831 /* Integrate vtysh specific configuration. */
2832 vty_open_pager(vty
);
2833 vtysh_config_write();
2834 vtysh_config_dump();
2835 vty_close_pager(vty
);
2836 vty_out(vty
, "end\n");
2841 DEFUN (vtysh_show_running_config
,
2842 vtysh_show_running_config_cmd
,
2843 "show running-config ["DAEMONS_LIST
"]",
2845 "Current operating configuration\n"
2848 return vtysh_write_terminal(self
, vty
, argc
, argv
);
2851 DEFUN (vtysh_integrated_config
,
2852 vtysh_integrated_config_cmd
,
2853 "service integrated-vtysh-config",
2854 "Set up miscellaneous service\n"
2855 "Write configuration into integrated file\n")
2857 vtysh_write_integrated
= WRITE_INTEGRATED_YES
;
2861 DEFUN (no_vtysh_integrated_config
,
2862 no_vtysh_integrated_config_cmd
,
2863 "no service integrated-vtysh-config",
2865 "Set up miscellaneous service\n"
2866 "Write configuration into integrated file\n")
2868 vtysh_write_integrated
= WRITE_INTEGRATED_NO
;
2872 static void backup_config_file(const char *fbackup
)
2874 char *integrate_sav
= NULL
;
2876 size_t integrate_sav_sz
= strlen(fbackup
) + strlen(CONF_BACKUP_EXT
) + 1;
2877 integrate_sav
= malloc(integrate_sav_sz
);
2878 strlcpy(integrate_sav
, fbackup
, integrate_sav_sz
);
2879 strlcat(integrate_sav
, CONF_BACKUP_EXT
, integrate_sav_sz
);
2881 /* Move current configuration file to backup config file. */
2882 if (unlink(integrate_sav
) != 0) {
2883 vty_out(vty
, "Warning: %s unlink failed\n", integrate_sav
);
2885 if (rename(fbackup
, integrate_sav
) != 0) {
2886 vty_out(vty
, "Error renaming %s to %s\n", fbackup
,
2889 free(integrate_sav
);
2892 int vtysh_write_config_integrated(void)
2895 char line
[] = "do write terminal\n";
2899 struct passwd
*pwentry
;
2902 struct group
*grentry
;
2909 vty_out(vty
, "Building Configuration...\n");
2911 backup_config_file(frr_config
);
2912 fp
= fopen(frr_config
, "w");
2915 "%% Error: failed to open configuration file %s: %s\n",
2916 frr_config
, safe_strerror(errno
));
2917 return CMD_WARNING_CONFIG_FAILED
;
2921 for (i
= 0; i
< array_size(vtysh_client
); i
++)
2922 vtysh_client_config(&vtysh_client
[i
], line
);
2924 vtysh_config_write();
2925 vty
->of_saved
= vty
->of
;
2927 vtysh_config_dump();
2928 vty
->of
= vty
->of_saved
;
2930 if (fchmod(fd
, CONFIGFILE_MASK
) != 0) {
2931 printf("%% Warning: can't chmod configuration file %s: %s\n",
2932 frr_config
, safe_strerror(errno
));
2937 pwentry
= getpwnam(FRR_USER
);
2939 uid
= pwentry
->pw_uid
;
2941 printf("%% Warning: could not look up user \"%s\"\n", FRR_USER
);
2946 grentry
= getgrnam(FRR_GROUP
);
2948 gid
= grentry
->gr_gid
;
2950 printf("%% Warning: could not look up group \"%s\"\n",
2956 if (!fstat(fd
, &st
)) {
2957 if (st
.st_uid
== uid
)
2959 if (st
.st_gid
== gid
)
2961 if ((uid
!= (uid_t
)-1 || gid
!= (gid_t
)-1)
2962 && fchown(fd
, uid
, gid
)) {
2963 printf("%% Warning: can't chown configuration file %s: %s\n",
2964 frr_config
, safe_strerror(errno
));
2968 printf("%% Warning: stat() failed on %s: %s\n", frr_config
,
2969 safe_strerror(errno
));
2975 printf("Integrated configuration saved to %s\n", frr_config
);
2983 static bool want_config_integrated(void)
2987 switch (vtysh_write_integrated
) {
2988 case WRITE_INTEGRATED_UNSPECIFIED
:
2989 if (stat(frr_config
, &s
) && errno
== ENOENT
)
2992 case WRITE_INTEGRATED_NO
:
2994 case WRITE_INTEGRATED_YES
:
3000 DEFUN (vtysh_write_memory
,
3001 vtysh_write_memory_cmd
,
3002 "write [<memory|file>]",
3003 "Write running configuration to memory, network, or terminal\n"
3004 "Write configuration to the file (same as write file)\n"
3005 "Write configuration to the file (same as write memory)\n")
3007 int ret
= CMD_SUCCESS
;
3008 char line
[] = "do write memory\n";
3011 vty_out(vty
, "Note: this version of vtysh never writes vtysh.conf\n");
3013 /* If integrated frr.conf explicitely set. */
3014 if (want_config_integrated()) {
3015 ret
= CMD_WARNING_CONFIG_FAILED
;
3017 /* first attempt to use watchfrr if it's available */
3018 bool used_watchfrr
= false;
3020 for (i
= 0; i
< array_size(vtysh_client
); i
++)
3021 if (vtysh_client
[i
].flag
== VTYSH_WATCHFRR
)
3023 if (i
< array_size(vtysh_client
) && vtysh_client
[i
].fd
!= -1) {
3024 used_watchfrr
= true;
3025 ret
= vtysh_client_execute(&vtysh_client
[i
],
3026 "do write integrated");
3030 * If we didn't use watchfrr, fallback to writing the config
3033 if (!used_watchfrr
) {
3034 printf("\nWarning: attempting direct configuration write without "
3035 "watchfrr.\nFile permissions and ownership may be "
3036 "incorrect, or write may fail.\n\n");
3037 ret
= vtysh_write_config_integrated();
3042 vty_out(vty
, "Building Configuration...\n");
3044 for (i
= 0; i
< array_size(vtysh_client
); i
++)
3045 ret
= vtysh_client_execute(&vtysh_client
[i
], line
);
3050 DEFUN (vtysh_copy_running_config
,
3051 vtysh_copy_running_config_cmd
,
3052 "copy running-config startup-config",
3053 "Copy from one file to another\n"
3054 "Copy from current system configuration\n"
3055 "Copy to startup configuration\n")
3057 return vtysh_write_memory(self
, vty
, argc
, argv
);
3060 DEFUN (vtysh_copy_to_running
,
3061 vtysh_copy_to_running_cmd
,
3062 "copy FILENAME running-config",
3063 "Apply a configuration file\n"
3064 "Configuration file to read\n"
3065 "Apply to current configuration\n")
3068 const char *fname
= argv
[1]->arg
;
3070 ret
= vtysh_read_config(fname
);
3072 /* Return to enable mode - the 'read_config' api leaves us up a level */
3073 vtysh_execute_no_pager("enable");
3078 DEFUN (vtysh_terminal_paginate
,
3079 vtysh_terminal_paginate_cmd
,
3080 "[no] terminal paginate",
3082 "Set terminal line parameters\n"
3083 "Use pager for output scrolling\n")
3085 free(vtysh_pager_name
);
3086 vtysh_pager_name
= NULL
;
3088 if (strcmp(argv
[0]->text
, "no"))
3089 vtysh_pager_envdef(true);
3093 DEFUN (vtysh_terminal_length
,
3094 vtysh_terminal_length_cmd
,
3095 "[no] terminal length (0-4294967295)",
3097 "Set terminal line parameters\n"
3098 "Set number of lines on a screen\n"
3099 "Number of lines on screen (0 for no pausing, nonzero to use pager)\n")
3102 unsigned long lines
;
3104 free(vtysh_pager_name
);
3105 vtysh_pager_name
= NULL
;
3107 if (!strcmp(argv
[0]->text
, "no") || !strcmp(argv
[1]->text
, "no")) {
3108 /* "terminal no length" = use VTYSH_PAGER */
3109 vtysh_pager_envdef(true);
3113 lines
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
3116 "%% The \"terminal length\" command is deprecated and its value is ignored.\n"
3117 "%% Please use \"terminal paginate\" instead with OS TTY length handling.\n");
3118 vtysh_pager_envdef(true);
3124 ALIAS_DEPRECATED(vtysh_terminal_length
,
3125 vtysh_terminal_no_length_cmd
,
3126 "terminal no length",
3127 "Set terminal line parameters\n"
3129 "Set number of lines on a screen\n")
3131 DEFUN (vtysh_show_daemons
,
3132 vtysh_show_daemons_cmd
,
3135 "Show list of running daemons\n")
3139 for (i
= 0; i
< array_size(vtysh_client
); i
++)
3140 if (vtysh_client
[i
].fd
>= 0)
3141 vty_out(vty
, " %s", vtysh_client
[i
].name
);
3147 /* Execute command in child process. */
3148 static void execute_command(const char *command
, int argc
, const char *arg1
,
3158 /* Failure of fork(). */
3159 fprintf(stderr
, "Can't fork: %s\n", safe_strerror(errno
));
3161 } else if (pid
== 0) {
3162 /* This is child process. */
3165 execlp(command
, command
, (const char *)NULL
);
3168 execlp(command
, command
, arg1
, (const char *)NULL
);
3171 execlp(command
, command
, arg1
, arg2
,
3172 (const char *)NULL
);
3176 /* When execlp suceed, this part is not executed. */
3177 fprintf(stderr
, "Can't execute %s: %s\n", command
,
3178 safe_strerror(errno
));
3181 /* This is parent. */
3183 wait4(pid
, &status
, 0, NULL
);
3191 "Send echo messages\n"
3192 "Ping destination address or hostname\n")
3196 argv_find(argv
, argc
, "WORD", &idx
);
3197 execute_command("ping", 1, argv
[idx
]->arg
, NULL
);
3201 ALIAS(vtysh_ping
, vtysh_ping_ip_cmd
, "ping ip WORD",
3202 "Send echo messages\n"
3204 "Ping destination address or hostname\n")
3206 DEFUN (vtysh_traceroute
,
3207 vtysh_traceroute_cmd
,
3209 "Trace route to destination\n"
3210 "Trace route to destination address or hostname\n")
3214 argv_find(argv
, argc
, "WORD", &idx
);
3215 execute_command("traceroute", 1, argv
[idx
]->arg
, NULL
);
3219 ALIAS(vtysh_traceroute
, vtysh_traceroute_ip_cmd
, "traceroute ip WORD",
3220 "Trace route to destination\n"
3222 "Trace route to destination address or hostname\n")
3224 DEFUN (vtysh_mtrace
,
3226 "mtrace WORD [WORD]",
3227 "Multicast trace route to multicast source\n"
3228 "Multicast trace route to multicast source address\n"
3229 "Multicast trace route for multicast group address\n")
3232 execute_command("mtracebis", 1, argv
[1]->arg
, NULL
);
3234 execute_command("mtracebis", 2, argv
[1]->arg
, argv
[2]->arg
);
3241 "Send echo messages\n"
3243 "Ping destination address or hostname\n")
3245 execute_command("ping6", 1, argv
[2]->arg
, NULL
);
3249 DEFUN (vtysh_traceroute6
,
3250 vtysh_traceroute6_cmd
,
3251 "traceroute ipv6 WORD",
3252 "Trace route to destination\n"
3254 "Trace route to destination address or hostname\n")
3256 execute_command("traceroute6", 1, argv
[2]->arg
, NULL
);
3260 #if defined(HAVE_SHELL_ACCESS)
3261 DEFUN (vtysh_telnet
,
3264 "Open a telnet connection\n"
3265 "IP address or hostname of a remote system\n")
3267 execute_command("telnet", 1, argv
[1]->arg
, NULL
);
3271 DEFUN (vtysh_telnet_port
,
3272 vtysh_telnet_port_cmd
,
3274 "Open a telnet connection\n"
3275 "IP address or hostname of a remote system\n"
3276 "TCP Port number\n")
3278 execute_command("telnet", 2, argv
[1]->arg
, argv
[2]->arg
);
3285 "Open an ssh connection\n"
3288 execute_command("ssh", 1, argv
[1]->arg
, NULL
);
3292 DEFUN (vtysh_start_shell
,
3293 vtysh_start_shell_cmd
,
3295 "Start UNIX shell\n")
3297 execute_command("sh", 0, NULL
, NULL
);
3301 DEFUN (vtysh_start_bash
,
3302 vtysh_start_bash_cmd
,
3304 "Start UNIX shell\n"
3307 execute_command("bash", 0, NULL
, NULL
);
3311 DEFUN (vtysh_start_zsh
,
3312 vtysh_start_zsh_cmd
,
3314 "Start UNIX shell\n"
3317 execute_command("zsh", 0, NULL
, NULL
);
3324 "list [permutations]",
3325 "Print command list\n"
3326 "Print all possible command permutations\n")
3328 return cmd_list_cmds(vty
, argc
== 2);
3331 DEFUN (vtysh_output_file
,
3332 vtysh_output_file_cmd
,
3334 "Direct vtysh output to file\n"
3335 "Direct vtysh output to file\n"
3336 "Path to dump output to\n")
3338 const char *path
= argv
[argc
- 1]->arg
;
3339 vty
->of
= fopen(path
, "a");
3341 vty_out(vty
, "Failed to open file '%s': %s\n", path
,
3342 safe_strerror(errno
));
3348 DEFUN (no_vtysh_output_file
,
3349 no_vtysh_output_file_cmd
,
3350 "no output file [FILE]",
3352 "Direct vtysh output to file\n"
3353 "Direct vtysh output to file\n"
3354 "Path to dump output to\n")
3356 if (vty
->of
!= stdout
) {
3366 "Find CLI command matching a regular expression\n"
3367 "Search pattern (POSIX regex)\n")
3369 char *pattern
= argv
[1]->arg
;
3370 const struct cmd_node
*node
;
3371 const struct cmd_element
*cli
;
3376 int cr
= regcomp(&exp
, pattern
, REG_NOSUB
| REG_EXTENDED
);
3381 vty_out(vty
, "%% Invalid \\{...\\} expression\n");
3384 vty_out(vty
, "%% Bad repetition operator\n");
3387 vty_out(vty
, "%% Regex syntax error\n");
3390 vty_out(vty
, "%% Invalid collating element\n");
3393 vty_out(vty
, "%% Invalid character class name\n");
3397 "%% Regex ended with escape character (\\)\n");
3401 "%% Invalid number in \\digit construction\n");
3404 vty_out(vty
, "%% Unbalanced square brackets\n");
3407 vty_out(vty
, "%% Unbalanced parentheses\n");
3410 vty_out(vty
, "%% Unbalanced braces\n");
3414 "%% Invalid endpoint in range expression\n");
3417 vty_out(vty
, "%% Failed to compile (out of memory)\n");
3425 for (unsigned int i
= 0; i
< vector_active(cmdvec
); i
++) {
3426 node
= vector_slot(cmdvec
, i
);
3429 clis
= node
->cmd_vector
;
3430 for (unsigned int j
= 0; j
< vector_active(clis
); j
++) {
3431 cli
= vector_slot(clis
, j
);
3433 if (regexec(&exp
, cli
->string
, 0, NULL
, 0) == 0)
3434 vty_out(vty
, " (%s) %s\n",
3435 node_names
[node
->node
], cli
->string
);
3444 DEFUN_HIDDEN(show_cli_graph_vtysh
,
3445 show_cli_graph_vtysh_cmd
,
3449 "Dump current command space as DOT graph\n")
3451 struct cmd_node
*cn
= vector_slot(cmdvec
, vty
->node
);
3452 char *dot
= cmd_graph_dump_dot(cn
->cmdgraph
);
3454 vty_out(vty
, "%s\n", dot
);
3455 XFREE(MTYPE_TMP
, dot
);
3459 static void vtysh_install_default(enum node_type node
)
3461 install_element(node
, &config_list_cmd
);
3462 install_element(node
, &find_cmd
);
3463 install_element(node
, &show_cli_graph_vtysh_cmd
);
3464 install_element(node
, &vtysh_output_file_cmd
);
3465 install_element(node
, &no_vtysh_output_file_cmd
);
3468 /* Making connection to protocol daemon. */
3469 static int vtysh_connect(struct vtysh_client
*vclient
)
3473 struct sockaddr_un addr
;
3477 if (!vclient
->path
[0])
3478 snprintf(vclient
->path
, sizeof(vclient
->path
), "%s/%s.vty",
3479 vtydir
, vclient
->name
);
3480 path
= vclient
->path
;
3482 /* Stat socket to see if we have permission to access it. */
3483 ret
= stat(path
, &s_stat
);
3484 if (ret
< 0 && errno
!= ENOENT
) {
3485 fprintf(stderr
, "vtysh_connect(%s): stat = %s\n", path
,
3486 safe_strerror(errno
));
3491 if (!S_ISSOCK(s_stat
.st_mode
)) {
3492 fprintf(stderr
, "vtysh_connect(%s): Not a socket\n",
3498 sock
= socket(AF_UNIX
, SOCK_STREAM
, 0);
3501 fprintf(stderr
, "vtysh_connect(%s): socket = %s\n", path
,
3502 safe_strerror(errno
));
3507 memset(&addr
, 0, sizeof(struct sockaddr_un
));
3508 addr
.sun_family
= AF_UNIX
;
3509 strlcpy(addr
.sun_path
, path
, sizeof(addr
.sun_path
));
3510 #ifdef HAVE_STRUCT_SOCKADDR_UN_SUN_LEN
3511 len
= addr
.sun_len
= SUN_LEN(&addr
);
3513 len
= sizeof(addr
.sun_family
) + strlen(addr
.sun_path
);
3514 #endif /* HAVE_STRUCT_SOCKADDR_UN_SUN_LEN */
3516 ret
= connect(sock
, (struct sockaddr
*)&addr
, len
);
3519 fprintf(stderr
, "vtysh_connect(%s): connect = %s\n", path
,
3520 safe_strerror(errno
));
3530 static int vtysh_reconnect(struct vtysh_client
*vclient
)
3534 fprintf(stderr
, "Warning: connecting to %s...", vclient
->name
);
3535 ret
= vtysh_connect(vclient
);
3537 fprintf(stderr
, "failed!\n");
3540 fprintf(stderr
, "success!\n");
3541 if (vtysh_client_execute(vclient
, "enable") < 0)
3543 return vtysh_execute_no_pager("end");
3546 /* Return true if str ends with suffix, else return false */
3547 static int ends_with(const char *str
, const char *suffix
)
3549 if (!str
|| !suffix
)
3551 size_t lenstr
= strlen(str
);
3552 size_t lensuffix
= strlen(suffix
);
3553 if (lensuffix
> lenstr
)
3555 return strncmp(str
+ lenstr
- lensuffix
, suffix
, lensuffix
) == 0;
3558 static void vtysh_client_sorted_insert(struct vtysh_client
*head_client
,
3559 struct vtysh_client
*client
)
3561 struct vtysh_client
*prev_node
, *current_node
;
3563 prev_node
= head_client
;
3564 current_node
= head_client
->next
;
3565 while (current_node
) {
3566 if (strcmp(current_node
->path
, client
->path
) > 0)
3569 prev_node
= current_node
;
3570 current_node
= current_node
->next
;
3572 client
->next
= current_node
;
3573 prev_node
->next
= client
;
3576 #define MAXIMUM_INSTANCES 10
3578 static void vtysh_update_all_instances(struct vtysh_client
*head_client
)
3580 struct vtysh_client
*client
;
3582 struct dirent
*file
;
3585 if (head_client
->flag
!= VTYSH_OSPFD
)
3588 /* ls vty_sock_dir and look for all files ending in .vty */
3589 dir
= opendir(vtydir
);
3591 while ((file
= readdir(dir
)) != NULL
) {
3592 if (frrstr_startswith(file
->d_name
, "ospfd-")
3593 && ends_with(file
->d_name
, ".vty")) {
3594 if (n
== MAXIMUM_INSTANCES
) {
3596 "Parsing %s, client limit(%d) reached!\n",
3600 client
= (struct vtysh_client
*)malloc(
3601 sizeof(struct vtysh_client
));
3603 client
->name
= "ospfd";
3604 client
->flag
= VTYSH_OSPFD
;
3605 snprintf(client
->path
, sizeof(client
->path
),
3606 "%s/%s", vtydir
, file
->d_name
);
3607 client
->next
= NULL
;
3608 vtysh_client_sorted_insert(head_client
, client
);
3616 static int vtysh_connect_all_instances(struct vtysh_client
*head_client
)
3618 struct vtysh_client
*client
;
3621 vtysh_update_all_instances(head_client
);
3623 client
= head_client
->next
;
3625 if (vtysh_connect(client
) == 0)
3627 client
= client
->next
;
3633 int vtysh_connect_all(const char *daemon_name
)
3639 for (i
= 0; i
< array_size(vtysh_client
); i
++) {
3641 || !strcmp(daemon_name
, vtysh_client
[i
].name
)) {
3643 if (vtysh_connect(&vtysh_client
[i
]) == 0)
3646 rc
+= vtysh_connect_all_instances(&vtysh_client
[i
]);
3650 fprintf(stderr
, "Error: no daemons match name %s!\n",
3655 /* To disable readline's filename completion. */
3656 static char *vtysh_completion_entry_function(const char *ignore
,
3662 void vtysh_readline_init(void)
3664 /* readline related settings. */
3666 rl_bind_key('?', (rl_command_func_t
*)vtysh_rl_describe
);
3667 rl_completion_entry_function
= vtysh_completion_entry_function
;
3668 rl_attempted_completion_function
= new_completion
;
3671 char *vtysh_prompt(void)
3673 static char buf
[512];
3675 snprintf(buf
, sizeof buf
, cmd_prompt(vty
->node
), cmd_hostname_get());
3679 static void vtysh_ac_line(void *arg
, const char *line
)
3683 for (i
= 0; i
< vector_active(comps
); i
++)
3684 if (!strcmp(line
, (char *)vector_slot(comps
, i
)))
3686 vector_set(comps
, XSTRDUP(MTYPE_COMPLETION
, line
));
3689 static void vtysh_autocomplete(vector comps
, struct cmd_token
*token
)
3694 snprintf(accmd
, sizeof(accmd
), "autocomplete %d %s %s", token
->type
,
3695 token
->text
, token
->varname
? token
->varname
: "-");
3697 vty
->of_saved
= vty
->of
;
3699 for (i
= 0; i
< array_size(vtysh_client
); i
++)
3700 vtysh_client_run_all(&vtysh_client
[i
], accmd
, 1, vtysh_ac_line
,
3702 vty
->of
= vty
->of_saved
;
3705 static const struct cmd_variable_handler vtysh_var_handler
[] = {
3709 .completions
= vtysh_autocomplete
},
3710 {.completions
= NULL
}};
3712 void vtysh_uninit(void)
3714 if (vty
->of
!= stdout
)
3718 void vtysh_init_vty(void)
3720 /* Make vty structure. */
3722 vty
->type
= VTY_SHELL
;
3723 vty
->node
= VIEW_NODE
;
3725 /* set default output */
3727 vtysh_pager_envdef(false);
3729 /* Initialize commands. */
3731 cmd_variable_handler_register(vtysh_var_handler
);
3733 /* Install nodes. */
3734 install_node(&bgp_node
, NULL
);
3735 install_node(&rip_node
, NULL
);
3736 install_node(&interface_node
, NULL
);
3737 install_node(&pw_node
, NULL
);
3738 install_node(&link_params_node
, NULL
);
3739 install_node(&vrf_node
, NULL
);
3740 install_node(&nh_group_node
, NULL
);
3741 install_node(&rmap_node
, NULL
);
3742 install_node(&pbr_map_node
, NULL
);
3743 install_node(&zebra_node
, NULL
);
3744 install_node(&bgp_vpnv4_node
, NULL
);
3745 install_node(&bgp_vpnv6_node
, NULL
);
3746 install_node(&bgp_flowspecv4_node
, NULL
);
3747 install_node(&bgp_flowspecv6_node
, NULL
);
3748 install_node(&bgp_ipv4_node
, NULL
);
3749 install_node(&bgp_ipv4m_node
, NULL
);
3750 install_node(&bgp_ipv4l_node
, NULL
);
3751 install_node(&bgp_ipv6_node
, NULL
);
3752 install_node(&bgp_ipv6m_node
, NULL
);
3753 install_node(&bgp_ipv6l_node
, NULL
);
3754 install_node(&bgp_vrf_policy_node
, NULL
);
3755 install_node(&bgp_evpn_node
, NULL
);
3756 install_node(&bgp_evpn_vni_node
, NULL
);
3757 install_node(&bgp_vnc_defaults_node
, NULL
);
3758 install_node(&bgp_vnc_nve_group_node
, NULL
);
3759 install_node(&bgp_vnc_l2_group_node
, NULL
);
3760 install_node(&ospf_node
, NULL
);
3761 install_node(&eigrp_node
, NULL
);
3762 install_node(&babel_node
, NULL
);
3763 install_node(&ripng_node
, NULL
);
3764 install_node(&ospf6_node
, NULL
);
3765 install_node(&ldp_node
, NULL
);
3766 install_node(&ldp_ipv4_node
, NULL
);
3767 install_node(&ldp_ipv6_node
, NULL
);
3768 install_node(&ldp_ipv4_iface_node
, NULL
);
3769 install_node(&ldp_ipv6_iface_node
, NULL
);
3770 install_node(&ldp_l2vpn_node
, NULL
);
3771 install_node(&ldp_pseudowire_node
, NULL
);
3772 install_node(&keychain_node
, NULL
);
3773 install_node(&keychain_key_node
, NULL
);
3774 install_node(&isis_node
, NULL
);
3775 install_node(&openfabric_node
, NULL
);
3776 install_node(&vty_node
, NULL
);
3777 install_node(&rpki_node
, NULL
);
3778 install_node(&bmp_node
, NULL
);
3780 install_node(&bfd_node
, NULL
);
3781 install_node(&bfd_peer_node
, NULL
);
3782 #endif /* HAVE_BFDD */
3784 struct cmd_node
*node
;
3785 for (unsigned int i
= 0; i
< vector_active(cmdvec
); i
++) {
3786 node
= vector_slot(cmdvec
, i
);
3787 if (!node
|| node
->node
== VIEW_NODE
)
3789 vtysh_install_default(node
->node
);
3792 install_element(VIEW_NODE
, &vtysh_enable_cmd
);
3793 install_element(ENABLE_NODE
, &vtysh_config_terminal_cmd
);
3794 install_element(ENABLE_NODE
, &vtysh_disable_cmd
);
3796 /* "exit" command. */
3797 install_element(VIEW_NODE
, &vtysh_exit_all_cmd
);
3798 install_element(CONFIG_NODE
, &vtysh_exit_all_cmd
);
3799 install_element(VIEW_NODE
, &vtysh_quit_all_cmd
);
3800 install_element(CONFIG_NODE
, &vtysh_quit_all_cmd
);
3801 install_element(RIP_NODE
, &vtysh_exit_ripd_cmd
);
3802 install_element(RIP_NODE
, &vtysh_quit_ripd_cmd
);
3803 install_element(RIPNG_NODE
, &vtysh_exit_ripngd_cmd
);
3804 install_element(RIPNG_NODE
, &vtysh_quit_ripngd_cmd
);
3805 install_element(OSPF_NODE
, &vtysh_exit_ospfd_cmd
);
3806 install_element(OSPF_NODE
, &vtysh_quit_ospfd_cmd
);
3807 install_element(EIGRP_NODE
, &vtysh_exit_eigrpd_cmd
);
3808 install_element(EIGRP_NODE
, &vtysh_quit_eigrpd_cmd
);
3809 install_element(BABEL_NODE
, &vtysh_exit_babeld_cmd
);
3810 install_element(BABEL_NODE
, &vtysh_quit_babeld_cmd
);
3811 install_element(OSPF6_NODE
, &vtysh_exit_ospf6d_cmd
);
3812 install_element(OSPF6_NODE
, &vtysh_quit_ospf6d_cmd
);
3813 #if defined(HAVE_LDPD)
3814 install_element(LDP_NODE
, &vtysh_exit_ldpd_cmd
);
3815 install_element(LDP_NODE
, &vtysh_quit_ldpd_cmd
);
3816 install_element(LDP_IPV4_NODE
, &vtysh_exit_ldpd_cmd
);
3817 install_element(LDP_IPV4_NODE
, &vtysh_quit_ldpd_cmd
);
3818 install_element(LDP_IPV4_NODE
, &ldp_exit_address_family_cmd
);
3819 install_element(LDP_IPV6_NODE
, &vtysh_exit_ldpd_cmd
);
3820 install_element(LDP_IPV6_NODE
, &vtysh_quit_ldpd_cmd
);
3821 install_element(LDP_IPV6_NODE
, &ldp_exit_address_family_cmd
);
3822 install_element(LDP_IPV4_IFACE_NODE
, &vtysh_exit_ldpd_cmd
);
3823 install_element(LDP_IPV4_IFACE_NODE
, &vtysh_quit_ldpd_cmd
);
3824 install_element(LDP_IPV6_IFACE_NODE
, &vtysh_exit_ldpd_cmd
);
3825 install_element(LDP_IPV6_IFACE_NODE
, &vtysh_quit_ldpd_cmd
);
3826 install_element(LDP_L2VPN_NODE
, &vtysh_exit_ldpd_cmd
);
3827 install_element(LDP_L2VPN_NODE
, &vtysh_quit_ldpd_cmd
);
3828 install_element(LDP_PSEUDOWIRE_NODE
, &vtysh_exit_ldpd_cmd
);
3829 install_element(LDP_PSEUDOWIRE_NODE
, &vtysh_quit_ldpd_cmd
);
3831 install_element(BGP_NODE
, &vtysh_exit_bgpd_cmd
);
3832 install_element(BGP_NODE
, &vtysh_quit_bgpd_cmd
);
3833 install_element(BGP_VPNV4_NODE
, &vtysh_exit_bgpd_cmd
);
3834 install_element(BGP_VPNV4_NODE
, &vtysh_quit_bgpd_cmd
);
3835 install_element(BGP_VPNV6_NODE
, &vtysh_exit_bgpd_cmd
);
3836 install_element(BGP_VPNV6_NODE
, &vtysh_quit_bgpd_cmd
);
3837 install_element(BGP_FLOWSPECV4_NODE
, &vtysh_exit_bgpd_cmd
);
3838 install_element(BGP_FLOWSPECV4_NODE
, &vtysh_quit_bgpd_cmd
);
3839 install_element(BGP_FLOWSPECV6_NODE
, &vtysh_exit_bgpd_cmd
);
3840 install_element(BGP_FLOWSPECV6_NODE
, &vtysh_quit_bgpd_cmd
);
3841 install_element(BGP_IPV4_NODE
, &vtysh_exit_bgpd_cmd
);
3842 install_element(BGP_IPV4_NODE
, &vtysh_quit_bgpd_cmd
);
3843 install_element(BGP_IPV4M_NODE
, &vtysh_exit_bgpd_cmd
);
3844 install_element(BGP_IPV4M_NODE
, &vtysh_quit_bgpd_cmd
);
3845 install_element(BGP_IPV4L_NODE
, &vtysh_exit_bgpd_cmd
);
3846 install_element(BGP_IPV4L_NODE
, &vtysh_quit_bgpd_cmd
);
3847 install_element(BGP_IPV6_NODE
, &vtysh_exit_bgpd_cmd
);
3848 install_element(BGP_IPV6_NODE
, &vtysh_quit_bgpd_cmd
);
3849 install_element(BGP_IPV6M_NODE
, &vtysh_exit_bgpd_cmd
);
3850 install_element(BGP_IPV6M_NODE
, &vtysh_quit_bgpd_cmd
);
3851 install_element(BGP_EVPN_NODE
, &vtysh_quit_bgpd_cmd
);
3852 install_element(BGP_EVPN_NODE
, &vtysh_exit_bgpd_cmd
);
3853 install_element(BGP_EVPN_VNI_NODE
, &vtysh_exit_bgpd_cmd
);
3854 install_element(BGP_EVPN_VNI_NODE
, &vtysh_quit_bgpd_cmd
);
3855 install_element(BGP_IPV6L_NODE
, &vtysh_exit_bgpd_cmd
);
3856 install_element(BGP_IPV6L_NODE
, &vtysh_quit_bgpd_cmd
);
3857 #if defined(ENABLE_BGP_VNC)
3858 install_element(BGP_VRF_POLICY_NODE
, &vtysh_exit_bgpd_cmd
);
3859 install_element(BGP_VRF_POLICY_NODE
, &vtysh_quit_bgpd_cmd
);
3860 install_element(BGP_VNC_DEFAULTS_NODE
, &vtysh_exit_bgpd_cmd
);
3861 install_element(BGP_VNC_DEFAULTS_NODE
, &vtysh_quit_bgpd_cmd
);
3862 install_element(BGP_VNC_NVE_GROUP_NODE
, &vtysh_exit_bgpd_cmd
);
3863 install_element(BGP_VNC_NVE_GROUP_NODE
, &vtysh_quit_bgpd_cmd
);
3864 install_element(BGP_VNC_L2_GROUP_NODE
, &vtysh_exit_bgpd_cmd
);
3865 install_element(BGP_VNC_L2_GROUP_NODE
, &vtysh_quit_bgpd_cmd
);
3867 install_element(ISIS_NODE
, &vtysh_exit_isisd_cmd
);
3868 install_element(ISIS_NODE
, &vtysh_quit_isisd_cmd
);
3869 install_element(OPENFABRIC_NODE
, &vtysh_exit_fabricd_cmd
);
3870 install_element(OPENFABRIC_NODE
, &vtysh_quit_fabricd_cmd
);
3871 install_element(KEYCHAIN_NODE
, &vtysh_exit_ripd_cmd
);
3872 install_element(KEYCHAIN_NODE
, &vtysh_quit_ripd_cmd
);
3873 install_element(KEYCHAIN_KEY_NODE
, &vtysh_exit_ripd_cmd
);
3874 install_element(KEYCHAIN_KEY_NODE
, &vtysh_quit_ripd_cmd
);
3875 install_element(RMAP_NODE
, &vtysh_exit_rmap_cmd
);
3876 install_element(RMAP_NODE
, &vtysh_quit_rmap_cmd
);
3877 install_element(PBRMAP_NODE
, &vtysh_exit_pbr_map_cmd
);
3878 install_element(PBRMAP_NODE
, &vtysh_quit_pbr_map_cmd
);
3881 install_element(CONFIG_NODE
, &bfd_enter_cmd
);
3882 install_element(BFD_NODE
, &bfd_peer_enter_cmd
);
3884 /* Exit/quit node. */
3885 install_element(BFD_NODE
, &vtysh_exit_bfdd_cmd
);
3886 install_element(BFD_NODE
, &vtysh_quit_bfdd_cmd
);
3887 install_element(BFD_PEER_NODE
, &vtysh_exit_bfdd_cmd
);
3888 install_element(BFD_PEER_NODE
, &vtysh_quit_bfdd_cmd
);
3891 install_element(BFD_NODE
, &vtysh_end_all_cmd
);
3892 install_element(BFD_PEER_NODE
, &vtysh_end_all_cmd
);
3893 #endif /* HAVE_BFDD */
3894 install_element(VTY_NODE
, &vtysh_exit_line_vty_cmd
);
3895 install_element(VTY_NODE
, &vtysh_quit_line_vty_cmd
);
3897 /* "end" command. */
3898 install_element(CONFIG_NODE
, &vtysh_end_all_cmd
);
3899 install_element(ENABLE_NODE
, &vtysh_end_all_cmd
);
3900 install_element(RIP_NODE
, &vtysh_end_all_cmd
);
3901 install_element(RIPNG_NODE
, &vtysh_end_all_cmd
);
3902 install_element(OSPF_NODE
, &vtysh_end_all_cmd
);
3903 install_element(EIGRP_NODE
, &vtysh_end_all_cmd
);
3904 install_element(BABEL_NODE
, &vtysh_end_all_cmd
);
3905 install_element(OSPF6_NODE
, &vtysh_end_all_cmd
);
3906 install_element(LDP_NODE
, &vtysh_end_all_cmd
);
3907 install_element(LDP_IPV4_NODE
, &vtysh_end_all_cmd
);
3908 install_element(LDP_IPV6_NODE
, &vtysh_end_all_cmd
);
3909 install_element(LDP_IPV4_IFACE_NODE
, &vtysh_end_all_cmd
);
3910 install_element(LDP_IPV6_IFACE_NODE
, &vtysh_end_all_cmd
);
3911 install_element(LDP_L2VPN_NODE
, &vtysh_end_all_cmd
);
3912 install_element(LDP_PSEUDOWIRE_NODE
, &vtysh_end_all_cmd
);
3913 install_element(BGP_NODE
, &vtysh_end_all_cmd
);
3914 install_element(BGP_IPV4_NODE
, &vtysh_end_all_cmd
);
3915 install_element(BGP_IPV4M_NODE
, &vtysh_end_all_cmd
);
3916 install_element(BGP_IPV4L_NODE
, &vtysh_end_all_cmd
);
3917 install_element(BGP_VPNV4_NODE
, &vtysh_end_all_cmd
);
3918 install_element(BGP_VPNV6_NODE
, &vtysh_end_all_cmd
);
3919 install_element(BGP_FLOWSPECV4_NODE
, &vtysh_end_all_cmd
);
3920 install_element(BGP_FLOWSPECV6_NODE
, &vtysh_end_all_cmd
);
3921 install_element(BGP_IPV6_NODE
, &vtysh_end_all_cmd
);
3922 install_element(BGP_IPV6M_NODE
, &vtysh_end_all_cmd
);
3923 install_element(BGP_IPV6L_NODE
, &vtysh_end_all_cmd
);
3924 install_element(BGP_VRF_POLICY_NODE
, &vtysh_end_all_cmd
);
3925 install_element(BGP_EVPN_NODE
, &vtysh_end_all_cmd
);
3926 install_element(BGP_EVPN_VNI_NODE
, &vtysh_end_all_cmd
);
3927 install_element(BGP_VNC_DEFAULTS_NODE
, &vtysh_end_all_cmd
);
3928 install_element(BGP_VNC_NVE_GROUP_NODE
, &vtysh_end_all_cmd
);
3929 install_element(BGP_VNC_L2_GROUP_NODE
, &vtysh_end_all_cmd
);
3930 install_element(ISIS_NODE
, &vtysh_end_all_cmd
);
3931 install_element(OPENFABRIC_NODE
, &vtysh_end_all_cmd
);
3932 install_element(KEYCHAIN_NODE
, &vtysh_end_all_cmd
);
3933 install_element(KEYCHAIN_KEY_NODE
, &vtysh_end_all_cmd
);
3934 install_element(RMAP_NODE
, &vtysh_end_all_cmd
);
3935 install_element(PBRMAP_NODE
, &vtysh_end_all_cmd
);
3936 install_element(VTY_NODE
, &vtysh_end_all_cmd
);
3938 install_element(INTERFACE_NODE
, &vtysh_end_all_cmd
);
3939 install_element(INTERFACE_NODE
, &vtysh_exit_interface_cmd
);
3940 install_element(LINK_PARAMS_NODE
, &exit_link_params_cmd
);
3941 install_element(LINK_PARAMS_NODE
, &vtysh_end_all_cmd
);
3942 install_element(LINK_PARAMS_NODE
, &vtysh_exit_interface_cmd
);
3943 install_element(INTERFACE_NODE
, &vtysh_quit_interface_cmd
);
3945 install_element(PW_NODE
, &vtysh_end_all_cmd
);
3946 install_element(PW_NODE
, &vtysh_exit_interface_cmd
);
3947 install_element(PW_NODE
, &vtysh_quit_interface_cmd
);
3949 install_element(CONFIG_NODE
, &vtysh_nexthop_group_cmd
);
3950 install_element(NH_GROUP_NODE
, &vtysh_end_all_cmd
);
3951 install_element(NH_GROUP_NODE
, &vtysh_exit_nexthop_group_cmd
);
3952 install_element(NH_GROUP_NODE
, &vtysh_quit_nexthop_group_cmd
);
3954 install_element(VRF_NODE
, &vtysh_end_all_cmd
);
3955 install_element(VRF_NODE
, &vtysh_exit_vrf_cmd
);
3956 install_element(VRF_NODE
, &vtysh_quit_vrf_cmd
);
3958 install_element(CONFIG_NODE
, &router_eigrp_cmd
);
3959 install_element(CONFIG_NODE
, &router_babel_cmd
);
3960 install_element(CONFIG_NODE
, &router_rip_cmd
);
3961 install_element(CONFIG_NODE
, &router_ripng_cmd
);
3962 install_element(CONFIG_NODE
, &router_ospf_cmd
);
3963 install_element(CONFIG_NODE
, &router_ospf6_cmd
);
3964 #if defined(HAVE_LDPD)
3965 install_element(CONFIG_NODE
, &ldp_mpls_ldp_cmd
);
3966 install_element(LDP_NODE
, &ldp_address_family_ipv4_cmd
);
3967 install_element(LDP_NODE
, &ldp_address_family_ipv6_cmd
);
3968 install_element(LDP_IPV4_NODE
, &ldp_interface_ifname_cmd
);
3969 install_element(LDP_IPV6_NODE
, &ldp_interface_ifname_cmd
);
3970 install_element(CONFIG_NODE
, &ldp_l2vpn_word_type_vpls_cmd
);
3971 install_element(LDP_L2VPN_NODE
, &ldp_member_pseudowire_ifname_cmd
);
3973 install_element(CONFIG_NODE
, &router_isis_cmd
);
3974 install_element(CONFIG_NODE
, &router_openfabric_cmd
);
3975 install_element(CONFIG_NODE
, &router_bgp_cmd
);
3976 #ifdef KEEP_OLD_VPN_COMMANDS
3977 install_element(BGP_NODE
, &address_family_vpnv4_cmd
);
3978 install_element(BGP_NODE
, &address_family_vpnv6_cmd
);
3979 #endif /* KEEP_OLD_VPN_COMMANDS */
3980 #if defined(ENABLE_BGP_VNC)
3981 install_element(BGP_NODE
, &vnc_vrf_policy_cmd
);
3982 install_element(BGP_NODE
, &vnc_defaults_cmd
);
3983 install_element(BGP_NODE
, &vnc_nve_group_cmd
);
3984 install_element(BGP_NODE
, &vnc_l2_group_cmd
);
3986 install_element(BGP_NODE
, &address_family_ipv4_cmd
);
3987 install_element(BGP_NODE
, &address_family_ipv4_multicast_cmd
);
3988 install_element(BGP_NODE
, &address_family_ipv4_vpn_cmd
);
3989 install_element(BGP_NODE
, &address_family_ipv4_labeled_unicast_cmd
);
3990 install_element(BGP_NODE
, &address_family_ipv6_cmd
);
3991 install_element(BGP_NODE
, &address_family_ipv6_multicast_cmd
);
3992 install_element(BGP_NODE
, &address_family_ipv6_vpn_cmd
);
3993 install_element(BGP_NODE
, &address_family_ipv6_labeled_unicast_cmd
);
3994 install_element(BGP_NODE
, &address_family_evpn_cmd
);
3995 install_element(BGP_NODE
, &address_family_flowspecv4_cmd
);
3996 install_element(BGP_NODE
, &address_family_flowspecv6_cmd
);
3997 #if defined(HAVE_CUMULUS)
3998 install_element(BGP_NODE
, &address_family_evpn2_cmd
);
4000 install_element(BGP_VPNV4_NODE
, &exit_address_family_cmd
);
4001 install_element(BGP_VPNV6_NODE
, &exit_address_family_cmd
);
4002 install_element(BGP_IPV4_NODE
, &exit_address_family_cmd
);
4003 install_element(BGP_IPV4M_NODE
, &exit_address_family_cmd
);
4004 install_element(BGP_IPV4L_NODE
, &exit_address_family_cmd
);
4005 install_element(BGP_IPV6_NODE
, &exit_address_family_cmd
);
4006 install_element(BGP_IPV6M_NODE
, &exit_address_family_cmd
);
4007 install_element(BGP_EVPN_NODE
, &exit_address_family_cmd
);
4008 install_element(BGP_IPV6L_NODE
, &exit_address_family_cmd
);
4009 install_element(BGP_FLOWSPECV4_NODE
, &exit_address_family_cmd
);
4010 install_element(BGP_FLOWSPECV6_NODE
, &exit_address_family_cmd
);
4012 install_element(BGP_NODE
, &bmp_targets_cmd
);
4013 install_element(BMP_NODE
, &bmp_exit_cmd
);
4014 install_element(BMP_NODE
, &bmp_quit_cmd
);
4015 install_element(BMP_NODE
, &vtysh_end_all_cmd
);
4017 install_element(CONFIG_NODE
, &rpki_cmd
);
4018 install_element(RPKI_NODE
, &rpki_exit_cmd
);
4019 install_element(RPKI_NODE
, &rpki_quit_cmd
);
4020 install_element(RPKI_NODE
, &vtysh_end_all_cmd
);
4023 install_element(BGP_EVPN_NODE
, &bgp_evpn_vni_cmd
);
4024 install_element(BGP_EVPN_VNI_NODE
, &exit_vni_cmd
);
4026 install_element(BGP_VRF_POLICY_NODE
, &exit_vrf_policy_cmd
);
4027 install_element(BGP_VNC_DEFAULTS_NODE
, &exit_vnc_config_cmd
);
4028 install_element(BGP_VNC_NVE_GROUP_NODE
, &exit_vnc_config_cmd
);
4029 install_element(BGP_VNC_L2_GROUP_NODE
, &exit_vnc_config_cmd
);
4031 install_element(CONFIG_NODE
, &key_chain_cmd
);
4032 install_element(CONFIG_NODE
, &vtysh_route_map_cmd
);
4033 install_element(CONFIG_NODE
, &vtysh_pbr_map_cmd
);
4034 install_element(CONFIG_NODE
, &vtysh_no_pbr_map_cmd
);
4035 install_element(CONFIG_NODE
, &vtysh_line_vty_cmd
);
4036 install_element(KEYCHAIN_NODE
, &key_cmd
);
4037 install_element(KEYCHAIN_NODE
, &key_chain_cmd
);
4038 install_element(KEYCHAIN_KEY_NODE
, &key_chain_cmd
);
4039 install_element(CONFIG_NODE
, &vtysh_interface_cmd
);
4040 install_element(CONFIG_NODE
, &vtysh_pseudowire_cmd
);
4041 install_element(INTERFACE_NODE
, &vtysh_link_params_cmd
);
4042 install_element(ENABLE_NODE
, &vtysh_show_running_config_cmd
);
4043 install_element(ENABLE_NODE
, &vtysh_copy_running_config_cmd
);
4044 install_element(ENABLE_NODE
, &vtysh_copy_to_running_cmd
);
4046 install_element(CONFIG_NODE
, &vtysh_vrf_cmd
);
4047 install_element(VRF_NODE
, &vtysh_vrf_netns_cmd
);
4048 install_element(VRF_NODE
, &vtysh_no_vrf_netns_cmd
);
4049 install_element(VRF_NODE
, &exit_vrf_config_cmd
);
4051 install_element(CONFIG_NODE
, &vtysh_no_nexthop_group_cmd
);
4053 /* "write terminal" command. */
4054 install_element(ENABLE_NODE
, &vtysh_write_terminal_cmd
);
4056 install_element(CONFIG_NODE
, &vtysh_integrated_config_cmd
);
4057 install_element(CONFIG_NODE
, &no_vtysh_integrated_config_cmd
);
4059 /* "write memory" command. */
4060 install_element(ENABLE_NODE
, &vtysh_write_memory_cmd
);
4062 install_element(CONFIG_NODE
, &vtysh_terminal_paginate_cmd
);
4063 install_element(VIEW_NODE
, &vtysh_terminal_paginate_cmd
);
4064 install_element(VIEW_NODE
, &vtysh_terminal_length_cmd
);
4065 install_element(VIEW_NODE
, &vtysh_terminal_no_length_cmd
);
4066 install_element(VIEW_NODE
, &vtysh_show_daemons_cmd
);
4068 install_element(VIEW_NODE
, &vtysh_ping_cmd
);
4069 install_element(VIEW_NODE
, &vtysh_ping_ip_cmd
);
4070 install_element(VIEW_NODE
, &vtysh_traceroute_cmd
);
4071 install_element(VIEW_NODE
, &vtysh_traceroute_ip_cmd
);
4072 install_element(VIEW_NODE
, &vtysh_mtrace_cmd
);
4073 install_element(VIEW_NODE
, &vtysh_ping6_cmd
);
4074 install_element(VIEW_NODE
, &vtysh_traceroute6_cmd
);
4075 #if defined(HAVE_SHELL_ACCESS)
4076 install_element(VIEW_NODE
, &vtysh_telnet_cmd
);
4077 install_element(VIEW_NODE
, &vtysh_telnet_port_cmd
);
4078 install_element(VIEW_NODE
, &vtysh_ssh_cmd
);
4080 #if defined(HAVE_SHELL_ACCESS)
4081 install_element(ENABLE_NODE
, &vtysh_start_shell_cmd
);
4082 install_element(ENABLE_NODE
, &vtysh_start_bash_cmd
);
4083 install_element(ENABLE_NODE
, &vtysh_start_zsh_cmd
);
4087 install_element(VIEW_NODE
, &vtysh_show_debugging_cmd
);
4088 install_element(VIEW_NODE
, &vtysh_show_error_code_cmd
);
4089 install_element(VIEW_NODE
, &vtysh_show_debugging_hashtable_cmd
);
4090 install_element(ENABLE_NODE
, &vtysh_debug_all_cmd
);
4091 install_element(CONFIG_NODE
, &vtysh_debug_all_cmd
);
4092 install_element(ENABLE_NODE
, &vtysh_debug_memstats_cmd
);
4093 install_element(CONFIG_NODE
, &vtysh_debug_memstats_cmd
);
4096 install_element(VIEW_NODE
, &show_yang_operational_data_cmd
);
4097 install_element(ENABLE_NODE
, &debug_nb_cmd
);
4098 install_element(CONFIG_NODE
, &debug_nb_cmd
);
4100 /* misc lib show commands */
4101 install_element(VIEW_NODE
, &vtysh_show_memory_cmd
);
4102 install_element(VIEW_NODE
, &vtysh_show_modules_cmd
);
4103 install_element(VIEW_NODE
, &vtysh_show_work_queues_cmd
);
4104 install_element(VIEW_NODE
, &vtysh_show_work_queues_daemon_cmd
);
4105 #ifndef EXCLUDE_CPU_TIME
4106 install_element(VIEW_NODE
, &vtysh_show_thread_cmd
);
4108 install_element(VIEW_NODE
, &vtysh_show_poll_cmd
);
4111 install_element(VIEW_NODE
, &vtysh_show_logging_cmd
);
4112 install_element(VIEW_NODE
, &vtysh_show_log_filter_cmd
);
4113 install_element(CONFIG_NODE
, &vtysh_log_filter_cmd
);
4114 install_element(CONFIG_NODE
, &vtysh_log_filter_clear_cmd
);
4115 install_element(CONFIG_NODE
, &vtysh_log_stdout_cmd
);
4116 install_element(CONFIG_NODE
, &vtysh_log_stdout_level_cmd
);
4117 install_element(CONFIG_NODE
, &no_vtysh_log_stdout_cmd
);
4118 install_element(CONFIG_NODE
, &vtysh_log_file_cmd
);
4119 install_element(CONFIG_NODE
, &vtysh_log_file_level_cmd
);
4120 install_element(CONFIG_NODE
, &no_vtysh_log_file_cmd
);
4121 install_element(CONFIG_NODE
, &vtysh_log_monitor_cmd
);
4122 install_element(CONFIG_NODE
, &no_vtysh_log_monitor_cmd
);
4123 install_element(CONFIG_NODE
, &vtysh_log_syslog_cmd
);
4124 install_element(CONFIG_NODE
, &no_vtysh_log_syslog_cmd
);
4125 install_element(CONFIG_NODE
, &vtysh_log_facility_cmd
);
4126 install_element(CONFIG_NODE
, &no_vtysh_log_facility_cmd
);
4127 install_element(CONFIG_NODE
, &vtysh_log_record_priority_cmd
);
4128 install_element(CONFIG_NODE
, &no_vtysh_log_record_priority_cmd
);
4129 install_element(CONFIG_NODE
, &vtysh_log_timestamp_precision_cmd
);
4130 install_element(CONFIG_NODE
, &no_vtysh_log_timestamp_precision_cmd
);
4132 install_element(CONFIG_NODE
, &vtysh_service_password_encrypt_cmd
);
4133 install_element(CONFIG_NODE
, &no_vtysh_service_password_encrypt_cmd
);
4135 install_element(CONFIG_NODE
, &vtysh_password_cmd
);
4136 install_element(CONFIG_NODE
, &no_vtysh_password_cmd
);
4137 install_element(CONFIG_NODE
, &vtysh_enable_password_cmd
);
4138 install_element(CONFIG_NODE
, &no_vtysh_enable_password_cmd
);