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 && vty
->node
> CONFIG_NODE
) {
496 vty
->node
= node_parent(vty
->node
);
497 ret
= cmd_execute(vty
, line
, &cmd
, 1);
501 vty
->node
= saved_node
;
504 * If command succeeded in any other node than current (tried > 0) we
505 * have to move into node in the vtysh where it succeeded.
507 if (ret
== CMD_SUCCESS
|| ret
== CMD_SUCCESS_DAEMON
508 || ret
== CMD_WARNING
) {
509 if ((saved_node
== BGP_VPNV4_NODE
510 || saved_node
== BGP_VPNV6_NODE
511 || saved_node
== BGP_IPV4_NODE
512 || saved_node
== BGP_IPV6_NODE
513 || saved_node
== BGP_FLOWSPECV4_NODE
514 || saved_node
== BGP_FLOWSPECV6_NODE
515 || saved_node
== BGP_IPV4M_NODE
516 || saved_node
== BGP_IPV4L_NODE
517 || saved_node
== BGP_IPV6L_NODE
518 || saved_node
== BGP_IPV6M_NODE
519 || saved_node
== BGP_EVPN_NODE
520 || saved_node
== LDP_IPV4_NODE
521 || saved_node
== LDP_IPV6_NODE
)
523 vtysh_execute("exit-address-family");
524 } else if ((saved_node
== BGP_EVPN_VNI_NODE
) && (tried
== 1)) {
525 vtysh_execute("exit-vni");
526 } else if (saved_node
== BGP_VRF_POLICY_NODE
&& (tried
== 1)) {
527 vtysh_execute("exit-vrf-policy");
528 } else if ((saved_node
== BGP_VNC_DEFAULTS_NODE
529 || saved_node
== BGP_VNC_NVE_GROUP_NODE
530 || saved_node
== BGP_VNC_L2_GROUP_NODE
)
532 vtysh_execute("exit-vnc");
533 } else if (saved_node
== VRF_NODE
&& (tried
== 1)) {
534 vtysh_execute("exit-vrf");
535 } else if ((saved_node
== KEYCHAIN_KEY_NODE
536 || saved_node
== LDP_PSEUDOWIRE_NODE
537 || saved_node
== LDP_IPV4_IFACE_NODE
538 || saved_node
== LDP_IPV6_IFACE_NODE
)
540 vtysh_execute("exit");
542 vtysh_execute("end");
543 vtysh_execute("configure");
547 * If command didn't succeed in any node, continue with return value
554 cmd_free_strvec(vline
);
559 case CMD_WARNING_CONFIG_FAILED
:
560 if (vty
->type
== VTY_FILE
)
561 vty_out(vty
, "Warning...\n");
563 case CMD_ERR_AMBIGUOUS
:
564 vty_out(vty
, "%% Ambiguous command: %s\n", line
);
566 case CMD_ERR_NO_MATCH
:
567 vty_out(vty
, "%% Unknown command: %s\n", line
);
569 case CMD_ERR_INCOMPLETE
:
570 vty_out(vty
, "%% Command incomplete: %s\n", line
);
572 case CMD_SUCCESS_DAEMON
: {
574 * FIXME: Don't open pager for exit commands. popen() causes
575 * problems if exited from vtysh at all. This hack shouldn't
576 * cause any problem but is really ugly.
578 if (pager
&& strncmp(line
, "exit", 4))
581 if (!strcmp(cmd
->string
, "configure")) {
582 for (i
= 0; i
< array_size(vtysh_client
); i
++) {
583 cmd_stat
= vtysh_client_execute(
584 &vtysh_client
[i
], line
);
585 if (cmd_stat
== CMD_WARNING
)
591 vline
= cmd_make_strvec(line
);
596 vty_close_pager(vty
);
600 ret
= cmd_execute_command(vline
, vty
, &cmd
, 1);
601 cmd_free_strvec(vline
);
602 if (ret
!= CMD_SUCCESS_DAEMON
)
604 } else if (cmd
->func
) {
605 (*cmd
->func
)(cmd
, vty
, 0, NULL
);
610 cmd_stat
= CMD_SUCCESS
;
611 struct vtysh_client
*vc
;
612 for (i
= 0; i
< array_size(vtysh_client
); i
++) {
613 if (cmd
->daemon
& vtysh_client
[i
].flag
) {
614 if (vtysh_client
[i
].fd
< 0
615 && (cmd
->daemon
== vtysh_client
[i
].flag
)) {
616 for (vc
= &vtysh_client
[i
]; vc
;
618 if (vc
->fd
== VTYSH_WAS_ACTIVE
)
621 if (vtysh_client
[i
].fd
< 0
622 && (cmd
->daemon
== vtysh_client
[i
].flag
)) {
623 bool any_inst
= false;
624 for (vc
= &vtysh_client
[i
]; vc
;
630 "%s is not running\n",
631 vtysh_client
[i
].name
);
635 cmd_stat
= vtysh_client_execute(
636 &vtysh_client
[i
], line
);
637 if (cmd_stat
!= CMD_SUCCESS
)
641 if (cmd_stat
!= CMD_SUCCESS
)
645 (*cmd
->func
)(cmd
, vty
, 0, NULL
);
649 vty_close_pager(vty
);
654 int vtysh_execute_no_pager(const char *line
)
656 return vtysh_execute_func(line
, 0);
659 int vtysh_execute(const char *line
)
661 return vtysh_execute_func(line
, 1);
664 static char *trim(char *s
)
675 while (end
>= s
&& isspace((unsigned char)*end
))
679 while (*s
&& isspace((unsigned char)*s
))
685 int vtysh_mark_file(const char *filename
)
692 const struct cmd_element
*cmd
;
693 int saved_ret
, prev_node
;
695 char *vty_buf_copy
= NULL
;
696 char *vty_buf_trimmed
= NULL
;
698 if (strncmp("-", filename
, 1) == 0)
701 confp
= fopen(filename
, "r");
704 fprintf(stderr
, "%% Can't open config file %s due to '%s'.\n",
705 filename
, safe_strerror(errno
));
706 return (CMD_ERR_NO_FILE
);
710 vty
->wfd
= STDERR_FILENO
;
711 vty
->type
= VTY_TERM
;
712 vty
->node
= CONFIG_NODE
;
714 vtysh_execute_no_pager("enable");
715 vtysh_execute_no_pager("configure");
716 vty_buf_copy
= XCALLOC(MTYPE_VTYSH_CMD
, VTY_BUFSIZ
);
718 while (fgets(vty
->buf
, VTY_BUFSIZ
, confp
)) {
721 strlcpy(vty_buf_copy
, vty
->buf
, VTY_BUFSIZ
);
722 vty_buf_trimmed
= trim(vty_buf_copy
);
725 case LDP_IPV4_IFACE_NODE
:
726 if (strncmp(vty_buf_copy
, " ", 3)) {
727 vty_out(vty
, " end\n");
728 vty
->node
= LDP_IPV4_NODE
;
731 case LDP_IPV6_IFACE_NODE
:
732 if (strncmp(vty_buf_copy
, " ", 3)) {
733 vty_out(vty
, " end\n");
734 vty
->node
= LDP_IPV6_NODE
;
737 case LDP_PSEUDOWIRE_NODE
:
738 if (strncmp(vty_buf_copy
, " ", 2)) {
739 vty_out(vty
, " end\n");
740 vty
->node
= LDP_L2VPN_NODE
;
747 if (vty_buf_trimmed
[0] == '!' || vty_buf_trimmed
[0] == '#') {
748 vty_out(vty
, "%s", vty
->buf
);
752 /* Split readline string up into the vector. */
753 vline
= cmd_make_strvec(vty
->buf
);
756 vty_out(vty
, "%s", vty
->buf
);
761 * Ignore the "end" lines, we will generate these where
764 if (strlen(vty_buf_trimmed
) == 3
765 && strncmp("end", vty_buf_trimmed
, 3) == 0) {
766 cmd_free_strvec(vline
);
770 prev_node
= vty
->node
;
771 saved_ret
= ret
= cmd_execute_command_strict(vline
, vty
, &cmd
);
774 * If command doesn't succeeded in current node, try to walk up
775 * in node tree. Changing vty->node is enough to try it just
776 * out without actual walkup in the vtysh.
778 while (ret
!= CMD_SUCCESS
&& ret
!= CMD_SUCCESS_DAEMON
779 && ret
!= CMD_WARNING
&& ret
!= CMD_WARNING_CONFIG_FAILED
780 && vty
->node
> CONFIG_NODE
) {
781 vty
->node
= node_parent(vty
->node
);
782 ret
= cmd_execute_command_strict(vline
, vty
, &cmd
);
787 * If command succeeded in any other node than current (tried >
788 * 0) we have to move into node in the vtysh where it
791 if (ret
== CMD_SUCCESS
|| ret
== CMD_SUCCESS_DAEMON
792 || ret
== CMD_WARNING
) {
793 if ((prev_node
== BGP_VPNV4_NODE
794 || prev_node
== BGP_VPNV6_NODE
795 || prev_node
== BGP_IPV4_NODE
796 || prev_node
== BGP_IPV6_NODE
797 || prev_node
== BGP_FLOWSPECV4_NODE
798 || prev_node
== BGP_FLOWSPECV6_NODE
799 || prev_node
== BGP_IPV4L_NODE
800 || prev_node
== BGP_IPV6L_NODE
801 || prev_node
== BGP_IPV4M_NODE
802 || prev_node
== BGP_IPV6M_NODE
803 || prev_node
== BGP_EVPN_NODE
)
805 vty_out(vty
, "exit-address-family\n");
806 } else if ((prev_node
== BGP_EVPN_VNI_NODE
)
808 vty_out(vty
, "exit-vni\n");
809 } else if ((prev_node
== KEYCHAIN_KEY_NODE
)
811 vty_out(vty
, "exit\n");
813 vty_out(vty
, "end\n");
817 * If command didn't succeed in any node, continue with return
818 * value from first try.
822 vty
->node
= prev_node
;
825 cmd_free_strvec(vline
);
828 case CMD_WARNING_CONFIG_FAILED
:
829 if (vty
->type
== VTY_FILE
)
830 fprintf(stderr
, "line %d: Warning...: %s\n",
834 XFREE(MTYPE_VTYSH_CMD
, vty_buf_copy
);
836 case CMD_ERR_AMBIGUOUS
:
837 fprintf(stderr
, "line %d: %% Ambiguous command: %s\n",
841 XFREE(MTYPE_VTYSH_CMD
, vty_buf_copy
);
842 return CMD_ERR_AMBIGUOUS
;
843 case CMD_ERR_NO_MATCH
:
844 fprintf(stderr
, "line %d: %% Unknown command: %s\n",
848 XFREE(MTYPE_VTYSH_CMD
, vty_buf_copy
);
849 return CMD_ERR_NO_MATCH
;
850 case CMD_ERR_INCOMPLETE
:
851 fprintf(stderr
, "line %d: %% Command incomplete: %s\n",
855 XFREE(MTYPE_VTYSH_CMD
, vty_buf_copy
);
856 return CMD_ERR_INCOMPLETE
;
858 vty_out(vty
, "%s", vty
->buf
);
859 if (strmatch(vty_buf_trimmed
, "exit-vrf"))
860 vty_out(vty
, "end\n");
862 case CMD_SUCCESS_DAEMON
: {
865 vty_out(vty
, "%s", vty
->buf
);
866 if (strmatch(vty_buf_trimmed
, "exit-vrf"))
867 vty_out(vty
, "end\n");
868 cmd_stat
= vtysh_client_execute(&vtysh_client
[0],
870 if (cmd_stat
!= CMD_SUCCESS
)
874 (*cmd
->func
)(cmd
, vty
, 0, NULL
);
878 /* This is the end */
879 vty_out(vty
, "\nend\n");
881 XFREE(MTYPE_VTYSH_CMD
, vty_buf_copy
);
889 /* Configration make from file. */
890 int vtysh_config_from_file(struct vty
*vty
, FILE *fp
)
893 const struct cmd_element
*cmd
;
895 /* once we have an error, we remember & return that */
896 int retcode
= CMD_SUCCESS
;
898 while (fgets(vty
->buf
, VTY_BUFSIZ
, fp
)) {
901 ret
= command_config_read_one_line(vty
, &cmd
, lineno
, 1);
905 case CMD_WARNING_CONFIG_FAILED
:
906 if (vty
->type
== VTY_FILE
)
907 fprintf(stderr
, "line %d: Warning[%d]...: %s\n",
908 lineno
, vty
->node
, vty
->buf
);
912 case CMD_ERR_AMBIGUOUS
:
914 "line %d: %% Ambiguous command[%d]: %s\n",
915 lineno
, vty
->node
, vty
->buf
);
916 retcode
= CMD_ERR_AMBIGUOUS
;
918 case CMD_ERR_NO_MATCH
:
919 fprintf(stderr
, "line %d: %% Unknown command[%d]: %s",
920 lineno
, vty
->node
, vty
->buf
);
921 retcode
= CMD_ERR_NO_MATCH
;
923 case CMD_ERR_INCOMPLETE
:
925 "line %d: %% Command incomplete[%d]: %s\n",
926 lineno
, vty
->node
, vty
->buf
);
927 retcode
= CMD_ERR_INCOMPLETE
;
929 case CMD_SUCCESS_DAEMON
: {
931 int cmd_stat
= CMD_SUCCESS
;
933 for (i
= 0; i
< array_size(vtysh_client
); i
++) {
934 if (cmd
->daemon
& vtysh_client
[i
].flag
) {
935 cmd_stat
= vtysh_client_execute(
936 &vtysh_client
[i
], vty
->buf
);
938 * CMD_WARNING - Can mean that the
939 * command was parsed successfully but
940 * it was already entered in a few
941 * spots. As such if we receive a
942 * CMD_WARNING from a daemon we
943 * shouldn't stop talking to the other
944 * daemons for the particular command.
946 if (cmd_stat
!= CMD_SUCCESS
947 && cmd_stat
!= CMD_WARNING
) {
949 "line %d: Failure to communicate[%d] to %s, line: %s\n",
951 vtysh_client
[i
].name
,
958 if (cmd_stat
!= CMD_SUCCESS
)
962 (*cmd
->func
)(cmd
, vty
, 0, NULL
);
971 * Function processes cli commands terminated with '?' character when entered
972 * through either 'vtysh' or 'vtysh -c' interfaces.
974 static int vtysh_process_questionmark(const char *input
, int input_len
)
978 vector vline
, describe
;
979 struct cmd_token
*token
;
984 vline
= cmd_make_strvec(input
);
986 /* In case of '> ?'. */
988 vline
= vector_init(1);
989 vector_set(vline
, NULL
);
990 } else if (input_len
&& isspace((unsigned char)input
[input_len
- 1]))
991 vector_set(vline
, NULL
);
993 describe
= cmd_describe_command(vline
, vty
, &ret
);
995 /* Ambiguous and no match error. */
997 case CMD_ERR_AMBIGUOUS
:
998 cmd_free_strvec(vline
);
999 vector_free(describe
);
1000 vty_out(vty
, "%% Ambiguous command.\n");
1004 case CMD_ERR_NO_MATCH
:
1005 cmd_free_strvec(vline
);
1007 vector_free(describe
);
1008 vty_out(vty
, "%% There is no matched command.\n");
1014 /* Get width of command string. */
1016 for (i
= 0; i
< vector_active(describe
); i
++)
1017 if ((token
= vector_slot(describe
, i
)) != NULL
) {
1018 if (token
->text
[0] == '\0')
1021 int len
= strlen(token
->text
);
1027 for (i
= 0; i
< vector_active(describe
); i
++)
1028 if ((token
= vector_slot(describe
, i
)) != NULL
) {
1030 vty_out(vty
, " %-s\n", token
->text
);
1032 vty_out(vty
, " %-*s %s\n", width
, token
->text
,
1035 if (IS_VARYING_TOKEN(token
->type
)) {
1036 const char *ref
= vector_slot(
1037 vline
, vector_active(vline
) - 1);
1039 vector varcomps
= vector_init(VECTOR_MIN_SIZE
);
1040 cmd_variable_complete(token
, ref
, varcomps
);
1042 if (vector_active(varcomps
) > 0) {
1044 rl_get_screen_size(&rows
, &cols
);
1046 char *ac
= cmd_variable_comp2str(
1048 vty_out(vty
, "%s\n", ac
);
1049 XFREE(MTYPE_TMP
, ac
);
1052 vector_free(varcomps
);
1056 cmd_free_strvec(vline
);
1057 vector_free(describe
);
1063 * Entry point for user commands terminated with '?' character and typed through
1064 * the usual vtysh's stdin interface. This is the function being registered with
1067 static int vtysh_rl_describe(int a
, int b
)
1073 ret
= vtysh_process_questionmark(rl_line_buffer
, rl_end
);
1080 * Function in charged of processing vtysh instructions terminating with '?'
1081 * character and received through the 'vtysh -c' interface. If user's
1082 * instruction is well-formatted, we will call the same processing routine
1083 * utilized by the traditional vtysh's stdin interface.
1085 int vtysh_execute_command_questionmark(char *input
)
1087 int input_len
, qmark_count
= 0;
1090 if (!(input
&& *input
))
1093 /* Finding out question_mark count and strlen */
1094 for (str
= input
; *str
; ++str
) {
1098 input_len
= str
- input
;
1101 * Verify that user's input terminates in '?' and that patterns such as
1102 * 'cmd ? subcmd ?' are prevented.
1104 if (qmark_count
!= 1 || input
[input_len
- 1] != '?')
1108 * Questionmark-processing function is not expecting to receive '?'
1109 * character in input string.
1111 input
[input_len
- 1] = '\0';
1113 return vtysh_process_questionmark(input
, input_len
- 1);
1116 /* Result of cmd_complete_command() call will be stored here
1117 * and used in new_completion() in order to put the space in
1118 * correct places only. */
1119 int complete_status
;
1121 static char *command_generator(const char *text
, int state
)
1124 static char **matched
= NULL
;
1125 static int index
= 0;
1131 if (vty
->node
== AUTH_NODE
|| vty
->node
== AUTH_ENABLE_NODE
)
1134 vline
= cmd_make_strvec(rl_line_buffer
);
1139 isspace((unsigned char)rl_line_buffer
[rl_end
- 1]))
1140 vector_set(vline
, NULL
);
1142 matched
= cmd_complete_command(vline
, vty
, &complete_status
);
1143 cmd_free_strvec(vline
);
1146 if (matched
&& matched
[index
])
1148 * this is free()'d by readline, but we leak 1 count of
1151 return matched
[index
++];
1153 XFREE(MTYPE_TMP
, matched
);
1159 static char **new_completion(const char *text
, int start
, int end
)
1163 matches
= rl_completion_matches(text
, command_generator
);
1167 if (complete_status
!= CMD_COMPLETE_FULL_MATCH
)
1168 /* only append a space on full match */
1169 rl_completion_append_character
= '\0';
1175 /* Vty node structures. */
1176 static struct cmd_node bgp_node
= {
1177 BGP_NODE
, "%s(config-router)# ",
1180 static struct cmd_node rip_node
= {
1181 RIP_NODE
, "%s(config-router)# ",
1184 static struct cmd_node isis_node
= {
1185 ISIS_NODE
, "%s(config-router)# ",
1188 static struct cmd_node openfabric_node
= {
1189 OPENFABRIC_NODE
, "%s(config-router)# ",
1192 static struct cmd_node interface_node
= {
1193 INTERFACE_NODE
, "%s(config-if)# ",
1196 static struct cmd_node pw_node
= {
1197 PW_NODE
, "%s(config-pw)# ",
1200 static struct cmd_node vrf_node
= {
1201 VRF_NODE
, "%s(config-vrf)# ",
1204 static struct cmd_node nh_group_node
= {
1206 "%s(config-nh-group)# ",
1209 static struct cmd_node rmap_node
= {RMAP_NODE
, "%s(config-route-map)# "};
1211 static struct cmd_node pbr_map_node
= {PBRMAP_NODE
, "%s(config-pbr-map)# "};
1213 static struct cmd_node zebra_node
= {ZEBRA_NODE
, "%s(config-router)# "};
1215 static struct cmd_node bgp_vpnv4_node
= {BGP_VPNV4_NODE
,
1216 "%s(config-router-af)# "};
1218 static struct cmd_node bgp_vpnv6_node
= {BGP_VPNV6_NODE
,
1219 "%s(config-router-af)# "};
1221 static struct cmd_node bgp_flowspecv4_node
= {BGP_FLOWSPECV4_NODE
,
1222 "%s(config-router-af)# "};
1224 static struct cmd_node bgp_flowspecv6_node
= {BGP_FLOWSPECV6_NODE
,
1225 "%s(config-router-af)# "};
1227 static struct cmd_node bgp_ipv4_node
= {BGP_IPV4_NODE
,
1228 "%s(config-router-af)# "};
1230 static struct cmd_node bgp_ipv4m_node
= {BGP_IPV4M_NODE
,
1231 "%s(config-router-af)# "};
1233 static struct cmd_node bgp_ipv4l_node
= {BGP_IPV4L_NODE
,
1234 "%s(config-router-af)# "};
1236 static struct cmd_node bgp_ipv6_node
= {BGP_IPV6_NODE
,
1237 "%s(config-router-af)# "};
1239 static struct cmd_node bgp_ipv6m_node
= {BGP_IPV6M_NODE
,
1240 "%s(config-router-af)# "};
1242 static struct cmd_node bgp_evpn_node
= {BGP_EVPN_NODE
,
1243 "%s(config-router-af)# "};
1245 static struct cmd_node bgp_evpn_vni_node
= {BGP_EVPN_VNI_NODE
,
1246 "%s(config-router-af-vni)# "};
1248 static struct cmd_node bgp_ipv6l_node
= {BGP_IPV6L_NODE
,
1249 "%s(config-router-af)# "};
1251 static struct cmd_node bgp_vnc_defaults_node
= {
1252 BGP_VNC_DEFAULTS_NODE
, "%s(config-router-vnc-defaults)# "};
1254 static struct cmd_node bgp_vnc_nve_group_node
= {
1255 BGP_VNC_NVE_GROUP_NODE
, "%s(config-router-vnc-nve-group)# "};
1257 static struct cmd_node bgp_vrf_policy_node
= {BGP_VRF_POLICY_NODE
,
1258 "%s(config-router-vrf-policy)# "};
1260 static struct cmd_node bgp_vnc_l2_group_node
= {
1261 BGP_VNC_L2_GROUP_NODE
, "%s(config-router-vnc-l2-group)# "};
1263 static struct cmd_node bmp_node
= {BMP_NODE
, "%s(config-bgp-bmp)# "};
1265 static struct cmd_node ospf_node
= {OSPF_NODE
, "%s(config-router)# "};
1267 static struct cmd_node eigrp_node
= {EIGRP_NODE
, "%s(config-router)# "};
1269 static struct cmd_node babel_node
= {BABEL_NODE
, "%s(config-router)# "};
1271 static struct cmd_node ripng_node
= {RIPNG_NODE
, "%s(config-router)# "};
1273 static struct cmd_node ospf6_node
= {OSPF6_NODE
, "%s(config-ospf6)# "};
1275 static struct cmd_node ldp_node
= {LDP_NODE
, "%s(config-ldp)# "};
1277 static struct cmd_node ldp_ipv4_node
= {LDP_IPV4_NODE
, "%s(config-ldp-af)# "};
1279 static struct cmd_node ldp_ipv6_node
= {LDP_IPV6_NODE
, "%s(config-ldp-af)# "};
1281 static struct cmd_node ldp_ipv4_iface_node
= {LDP_IPV4_IFACE_NODE
,
1282 "%s(config-ldp-af-if)# "};
1284 static struct cmd_node ldp_ipv6_iface_node
= {LDP_IPV6_IFACE_NODE
,
1285 "%s(config-ldp-af-if)# "};
1287 static struct cmd_node ldp_l2vpn_node
= {LDP_L2VPN_NODE
, "%s(config-l2vpn)# "};
1289 static struct cmd_node ldp_pseudowire_node
= {LDP_PSEUDOWIRE_NODE
,
1290 "%s(config-l2vpn-pw)# "};
1292 static struct cmd_node keychain_node
= {KEYCHAIN_NODE
, "%s(config-keychain)# "};
1294 static struct cmd_node keychain_key_node
= {KEYCHAIN_KEY_NODE
,
1295 "%s(config-keychain-key)# "};
1297 struct cmd_node link_params_node
= {
1298 LINK_PARAMS_NODE
, "%s(config-link-params)# ",
1301 static struct cmd_node rpki_node
= {RPKI_NODE
, "%s(config-rpki)# ", 1};
1304 static struct cmd_node bfd_node
= {
1309 static struct cmd_node bfd_peer_node
= {
1311 "%s(config-bfd-peer)# ",
1313 #endif /* HAVE_BFDD */
1315 /* Defined in lib/vty.c */
1316 extern struct cmd_node vty_node
;
1318 /* When '^Z' is received from vty, move down to the enable mode. */
1319 static int vtysh_end(void)
1321 switch (vty
->node
) {
1324 /* Nothing to do. */
1327 vty
->node
= ENABLE_NODE
;
1333 DEFUNSH(VTYSH_REALLYALL
, vtysh_end_all
, vtysh_end_all_cmd
, "end",
1334 "End current mode and change to enable mode\n")
1339 DEFUNSH(VTYSH_BGPD
, router_bgp
, router_bgp_cmd
,
1340 "router bgp [(1-4294967295)$instasn [<view|vrf> WORD]]",
1341 ROUTER_STR BGP_STR AS_STR
1342 "BGP view\nBGP VRF\n"
1345 vty
->node
= BGP_NODE
;
1349 #ifdef KEEP_OLD_VPN_COMMANDS
1350 DEFUNSH(VTYSH_BGPD
, address_family_vpnv4
, address_family_vpnv4_cmd
,
1351 "address-family vpnv4 [unicast]",
1352 "Enter Address Family command mode\n"
1354 "Address Family modifier\n")
1356 vty
->node
= BGP_VPNV4_NODE
;
1360 DEFUNSH(VTYSH_BGPD
, address_family_vpnv6
, address_family_vpnv6_cmd
,
1361 "address-family vpnv6 [unicast]",
1362 "Enter Address Family command mode\n"
1364 "Address Family modifier\n")
1366 vty
->node
= BGP_VPNV6_NODE
;
1369 #endif /* KEEP_OLD_VPN_COMMANDS */
1371 DEFUNSH(VTYSH_BGPD
, address_family_ipv4
, address_family_ipv4_cmd
,
1372 "address-family ipv4 [unicast]",
1373 "Enter Address Family command mode\n"
1375 "Address Family Modifier\n")
1377 vty
->node
= BGP_IPV4_NODE
;
1381 DEFUNSH(VTYSH_BGPD
, address_family_flowspecv4
, address_family_flowspecv4_cmd
,
1382 "address-family ipv4 flowspec",
1383 "Enter Address Family command mode\n"
1385 "Address Family Modifier\n")
1387 vty
->node
= BGP_FLOWSPECV4_NODE
;
1391 DEFUNSH(VTYSH_BGPD
, address_family_flowspecv6
, address_family_flowspecv6_cmd
,
1392 "address-family ipv6 flowspec",
1393 "Enter Address Family command mode\n"
1395 "Address Family Modifier\n")
1397 vty
->node
= BGP_FLOWSPECV6_NODE
;
1401 DEFUNSH(VTYSH_BGPD
, address_family_ipv4_multicast
,
1402 address_family_ipv4_multicast_cmd
, "address-family ipv4 multicast",
1403 "Enter Address Family command mode\n"
1405 "Address Family modifier\n")
1407 vty
->node
= BGP_IPV4M_NODE
;
1411 DEFUNSH(VTYSH_BGPD
, address_family_ipv4_vpn
, address_family_ipv4_vpn_cmd
,
1412 "address-family ipv4 vpn",
1413 "Enter Address Family command mode\n"
1415 "Address Family modifier\n")
1417 vty
->node
= BGP_VPNV4_NODE
;
1421 DEFUNSH(VTYSH_BGPD
, address_family_ipv4_labeled_unicast
,
1422 address_family_ipv4_labeled_unicast_cmd
,
1423 "address-family ipv4 labeled-unicast",
1424 "Enter Address Family command mode\n"
1426 "Address Family modifier\n")
1428 vty
->node
= BGP_IPV4L_NODE
;
1432 DEFUNSH(VTYSH_BGPD
, address_family_ipv6
, address_family_ipv6_cmd
,
1433 "address-family ipv6 [unicast]",
1434 "Enter Address Family command mode\n"
1436 "Address Family modifier\n")
1438 vty
->node
= BGP_IPV6_NODE
;
1442 DEFUNSH(VTYSH_BGPD
, address_family_ipv6_multicast
,
1443 address_family_ipv6_multicast_cmd
, "address-family ipv6 multicast",
1444 "Enter Address Family command mode\n"
1446 "Address Family modifier\n")
1448 vty
->node
= BGP_IPV6M_NODE
;
1452 DEFUNSH(VTYSH_BGPD
, address_family_ipv6_vpn
, address_family_ipv6_vpn_cmd
,
1453 "address-family ipv6 vpn",
1454 "Enter Address Family command mode\n"
1456 "Address Family modifier\n")
1458 vty
->node
= BGP_VPNV6_NODE
;
1462 DEFUNSH(VTYSH_BGPD
, address_family_ipv6_labeled_unicast
,
1463 address_family_ipv6_labeled_unicast_cmd
,
1464 "address-family ipv6 labeled-unicast",
1465 "Enter Address Family command mode\n"
1467 "Address Family modifier\n")
1469 vty
->node
= BGP_IPV6L_NODE
;
1477 "Enable rpki and enter rpki configuration mode\n")
1479 vty
->node
= RPKI_NODE
;
1486 "bmp targets BMPTARGETS",
1487 "BGP Monitoring Protocol\n"
1488 "Create BMP target group\n"
1489 "Name of the BMP target group\n")
1491 vty
->node
= BMP_NODE
;
1495 DEFUNSH(VTYSH_BGPD
, address_family_evpn
, address_family_evpn_cmd
,
1496 "address-family <l2vpn evpn>",
1497 "Enter Address Family command mode\n"
1499 "Address Family modifier\n")
1501 vty
->node
= BGP_EVPN_NODE
;
1505 #if defined(HAVE_CUMULUS)
1506 DEFUNSH_HIDDEN(VTYSH_BGPD
, address_family_evpn2
, address_family_evpn2_cmd
,
1507 "address-family evpn",
1508 "Enter Address Family command mode\n"
1509 "EVPN Address family\n")
1511 vty
->node
= BGP_EVPN_NODE
;
1516 DEFUNSH(VTYSH_BGPD
, bgp_evpn_vni
, bgp_evpn_vni_cmd
, "vni " CMD_VNI_RANGE
,
1517 "VXLAN Network Identifier\n"
1520 vty
->node
= BGP_EVPN_VNI_NODE
;
1524 #if defined(ENABLE_BGP_VNC)
1525 DEFUNSH(VTYSH_BGPD
, vnc_defaults
, vnc_defaults_cmd
, "vnc defaults",
1526 "VNC/RFP related configuration\n"
1527 "Configure default NVE group\n")
1529 vty
->node
= BGP_VNC_DEFAULTS_NODE
;
1533 DEFUNSH(VTYSH_BGPD
, vnc_nve_group
, vnc_nve_group_cmd
, "vnc nve-group NAME",
1534 "VNC/RFP related configuration\n"
1535 "Configure a NVE group\n"
1538 vty
->node
= BGP_VNC_NVE_GROUP_NODE
;
1542 DEFUNSH(VTYSH_BGPD
, vnc_vrf_policy
, vnc_vrf_policy_cmd
, "vrf-policy NAME",
1543 "Configure a VRF policy group\n"
1546 vty
->node
= BGP_VRF_POLICY_NODE
;
1550 DEFUNSH(VTYSH_BGPD
, vnc_l2_group
, vnc_l2_group_cmd
, "vnc l2-group NAME",
1551 "VNC/RFP related configuration\n"
1552 "Configure a L2 group\n"
1555 vty
->node
= BGP_VNC_L2_GROUP_NODE
;
1560 DEFUNSH(VTYSH_KEYS
, key_chain
, key_chain_cmd
, "key chain WORD",
1561 "Authentication key management\n"
1562 "Key-chain management\n"
1565 vty
->node
= KEYCHAIN_NODE
;
1569 DEFUNSH(VTYSH_KEYS
, key
, key_cmd
, "key (0-2147483647)",
1571 "Key identifier number\n")
1573 vty
->node
= KEYCHAIN_KEY_NODE
;
1577 DEFUNSH(VTYSH_RIPD
, router_rip
, router_rip_cmd
, "router rip [vrf NAME]",
1578 ROUTER_STR
"RIP\n" VRF_CMD_HELP_STR
)
1580 vty
->node
= RIP_NODE
;
1584 DEFUNSH(VTYSH_RIPNGD
, router_ripng
, router_ripng_cmd
, "router ripng [vrf NAME]",
1585 ROUTER_STR
"RIPng\n" VRF_CMD_HELP_STR
)
1587 vty
->node
= RIPNG_NODE
;
1591 DEFUNSH(VTYSH_OSPFD
, router_ospf
, router_ospf_cmd
,
1592 "router ospf [(1-65535)] [vrf NAME]",
1593 "Enable a routing process\n"
1594 "Start OSPF configuration\n"
1598 vty
->node
= OSPF_NODE
;
1602 DEFUNSH(VTYSH_EIGRPD
, router_eigrp
, router_eigrp_cmd
, "router eigrp (1-65535) [vrf NAME]",
1603 "Enable a routing process\n"
1604 "Start EIGRP configuration\n"
1605 "AS number to use\n"
1608 vty
->node
= EIGRP_NODE
;
1612 DEFUNSH(VTYSH_BABELD
, router_babel
, router_babel_cmd
, "router babel",
1613 "Enable a routing process\n"
1614 "Make Babel instance command\n")
1616 vty
->node
= BABEL_NODE
;
1620 DEFUNSH(VTYSH_OSPF6D
, router_ospf6
, router_ospf6_cmd
, "router ospf6",
1621 ROUTER_STR OSPF6_STR
)
1623 vty
->node
= OSPF6_NODE
;
1627 #if defined(HAVE_LDPD)
1628 DEFUNSH(VTYSH_LDPD
, ldp_mpls_ldp
, ldp_mpls_ldp_cmd
, "mpls ldp",
1629 "Global MPLS configuration subcommands\n"
1630 "Label Distribution Protocol\n")
1632 vty
->node
= LDP_NODE
;
1636 DEFUNSH(VTYSH_LDPD
, ldp_address_family_ipv4
, ldp_address_family_ipv4_cmd
,
1637 "address-family ipv4",
1638 "Configure Address Family and its parameters\n"
1641 vty
->node
= LDP_IPV4_NODE
;
1645 DEFUNSH(VTYSH_LDPD
, ldp_address_family_ipv6
, ldp_address_family_ipv6_cmd
,
1646 "address-family ipv6",
1647 "Configure Address Family and its parameters\n"
1650 vty
->node
= LDP_IPV6_NODE
;
1654 DEFUNSH(VTYSH_LDPD
, ldp_exit_address_family
, ldp_exit_address_family_cmd
,
1655 "exit-address-family", "Exit from Address Family configuration mode\n")
1657 if (vty
->node
== LDP_IPV4_NODE
|| vty
->node
== LDP_IPV6_NODE
)
1658 vty
->node
= LDP_NODE
;
1662 DEFUNSH(VTYSH_LDPD
, ldp_interface_ifname
, ldp_interface_ifname_cmd
,
1664 "Enable LDP on an interface and enter interface submode\n"
1665 "Interface's name\n")
1667 switch (vty
->node
) {
1669 vty
->node
= LDP_IPV4_IFACE_NODE
;
1672 vty
->node
= LDP_IPV6_IFACE_NODE
;
1681 DEFUNSH(VTYSH_LDPD
, ldp_l2vpn_word_type_vpls
, ldp_l2vpn_word_type_vpls_cmd
,
1682 "l2vpn WORD type vpls",
1683 "Configure l2vpn commands\n"
1686 "Virtual Private LAN Service\n")
1688 vty
->node
= LDP_L2VPN_NODE
;
1692 DEFUNSH(VTYSH_LDPD
, ldp_member_pseudowire_ifname
,
1693 ldp_member_pseudowire_ifname_cmd
, "member pseudowire IFNAME",
1694 "L2VPN member configuration\n"
1695 "Pseudowire interface\n"
1696 "Interface's name\n")
1698 vty
->node
= LDP_PSEUDOWIRE_NODE
;
1703 DEFUNSH(VTYSH_ISISD
, router_isis
, router_isis_cmd
, "router isis WORD",
1706 "ISO Routing area tag\n")
1708 vty
->node
= ISIS_NODE
;
1712 DEFUNSH(VTYSH_FABRICD
, router_openfabric
, router_openfabric_cmd
, "router openfabric WORD",
1714 "OpenFabric routing protocol\n"
1715 "ISO Routing area tag\n")
1717 vty
->node
= OPENFABRIC_NODE
;
1721 DEFUNSH(VTYSH_RMAP
, vtysh_route_map
, vtysh_route_map_cmd
,
1722 "route-map WORD <deny|permit> (1-65535)",
1723 "Create route-map or enter route-map command mode\n"
1725 "Route map denies set operations\n"
1726 "Route map permits set operations\n"
1727 "Sequence to insert to/delete from existing route-map entry\n")
1729 vty
->node
= RMAP_NODE
;
1733 DEFUNSH(VTYSH_PBRD
, vtysh_pbr_map
, vtysh_pbr_map_cmd
,
1734 "pbr-map PBRMAP seq (1-700)",
1735 "Create pbr-map or enter pbr-map command mode\n"
1736 "The name of the PBR MAP\n"
1737 "Sequence to insert to/delete from existing pbr-map entry\n"
1738 "Sequence number\n")
1740 vty
->node
= PBRMAP_NODE
;
1745 DEFUNSH(VTYSH_BFDD
, bfd_enter
, bfd_enter_cmd
, "bfd", "Configure BFD peers\n")
1747 vty
->node
= BFD_NODE
;
1751 DEFUNSH(VTYSH_BFDD
, bfd_peer_enter
, bfd_peer_enter_cmd
,
1752 "peer <A.B.C.D|X:X::X:X> [{multihop|local-address <A.B.C.D|X:X::X:X>|interface IFNAME|vrf NAME}]",
1754 "IPv4 peer address\n"
1755 "IPv6 peer address\n"
1756 "Configure multihop\n"
1757 "Configure local address\n"
1758 "IPv4 local address\n"
1759 "IPv6 local address\n"
1761 "Configure interface name to use\n"
1763 "Configure VRF name\n")
1765 vty
->node
= BFD_PEER_NODE
;
1768 #endif /* HAVE_BFDD */
1770 DEFSH(VTYSH_PBRD
, vtysh_no_pbr_map_cmd
, "no pbr-map PBRMAP [seq (1-700)]",
1773 "The name of the PBR MAP\n"
1774 "Sequence to delete from existing pbr-map entry\n"
1775 "Sequence number\n")
1777 DEFUNSH(VTYSH_ALL
, vtysh_line_vty
, vtysh_line_vty_cmd
, "line vty",
1778 "Configure a terminal line\n"
1779 "Virtual terminal\n")
1781 vty
->node
= VTY_NODE
;
1785 DEFUNSH(VTYSH_REALLYALL
, vtysh_enable
, vtysh_enable_cmd
, "enable",
1786 "Turn on privileged mode command\n")
1788 vty
->node
= ENABLE_NODE
;
1792 DEFUNSH(VTYSH_REALLYALL
, vtysh_disable
, vtysh_disable_cmd
, "disable",
1793 "Turn off privileged mode command\n")
1795 if (vty
->node
== ENABLE_NODE
)
1796 vty
->node
= VIEW_NODE
;
1800 DEFUNSH(VTYSH_REALLYALL
, vtysh_config_terminal
, vtysh_config_terminal_cmd
,
1801 "configure [terminal]",
1802 "Configuration from vty interface\n"
1803 "Configuration terminal\n")
1805 vty
->node
= CONFIG_NODE
;
1809 static int vtysh_exit(struct vty
*vty
)
1811 switch (vty
->node
) {
1817 vty
->node
= ENABLE_NODE
;
1819 case INTERFACE_NODE
:
1832 case LDP_L2VPN_NODE
:
1834 case OPENFABRIC_NODE
:
1841 vtysh_execute("end");
1842 vtysh_execute("configure");
1843 vty
->node
= CONFIG_NODE
;
1845 case BGP_VPNV4_NODE
:
1846 case BGP_VPNV6_NODE
:
1848 case BGP_IPV4M_NODE
:
1849 case BGP_IPV4L_NODE
:
1851 case BGP_IPV6M_NODE
:
1852 case BGP_IPV6L_NODE
:
1853 case BGP_FLOWSPECV4_NODE
:
1854 case BGP_FLOWSPECV6_NODE
:
1855 case BGP_VRF_POLICY_NODE
:
1857 case BGP_VNC_DEFAULTS_NODE
:
1858 case BGP_VNC_NVE_GROUP_NODE
:
1859 case BGP_VNC_L2_GROUP_NODE
:
1861 vty
->node
= BGP_NODE
;
1863 case BGP_EVPN_VNI_NODE
:
1864 vty
->node
= BGP_EVPN_NODE
;
1868 vty
->node
= LDP_NODE
;
1870 case LDP_IPV4_IFACE_NODE
:
1871 vty
->node
= LDP_IPV4_NODE
;
1873 case LDP_IPV6_IFACE_NODE
:
1874 vty
->node
= LDP_IPV6_NODE
;
1876 case LDP_PSEUDOWIRE_NODE
:
1877 vty
->node
= LDP_L2VPN_NODE
;
1879 case KEYCHAIN_KEY_NODE
:
1880 vty
->node
= KEYCHAIN_NODE
;
1882 case LINK_PARAMS_NODE
:
1883 vty
->node
= INTERFACE_NODE
;
1886 vty
->node
= BFD_NODE
;
1894 DEFUNSH(VTYSH_REALLYALL
, vtysh_exit_all
, vtysh_exit_all_cmd
, "exit",
1895 "Exit current mode and down to previous mode\n")
1897 return vtysh_exit(vty
);
1900 DEFUNSH(VTYSH_ALL
, vtysh_quit_all
, vtysh_quit_all_cmd
, "quit",
1901 "Exit current mode and down to previous mode\n")
1903 return vtysh_exit_all(self
, vty
, argc
, argv
);
1906 DEFUNSH(VTYSH_BGPD
, exit_address_family
, exit_address_family_cmd
,
1907 "exit-address-family", "Exit from Address Family configuration mode\n")
1909 if (vty
->node
== BGP_IPV4_NODE
|| vty
->node
== BGP_IPV4M_NODE
1910 || vty
->node
== BGP_IPV4L_NODE
|| vty
->node
== BGP_VPNV4_NODE
1911 || vty
->node
== BGP_VPNV6_NODE
|| vty
->node
== BGP_IPV6_NODE
1912 || vty
->node
== BGP_IPV6L_NODE
|| vty
->node
== BGP_IPV6M_NODE
1913 || vty
->node
== BGP_EVPN_NODE
1914 || vty
->node
== BGP_FLOWSPECV4_NODE
1915 || vty
->node
== BGP_FLOWSPECV6_NODE
)
1916 vty
->node
= BGP_NODE
;
1920 DEFUNSH(VTYSH_BGPD
, exit_vni
, exit_vni_cmd
, "exit-vni", "Exit from VNI mode\n")
1922 if (vty
->node
== BGP_EVPN_VNI_NODE
)
1923 vty
->node
= BGP_EVPN_NODE
;
1927 DEFUNSH(VTYSH_BGPD
, exit_vnc_config
, exit_vnc_config_cmd
, "exit-vnc",
1928 "Exit from VNC configuration mode\n")
1930 if (vty
->node
== BGP_VNC_DEFAULTS_NODE
1931 || vty
->node
== BGP_VNC_NVE_GROUP_NODE
1932 || vty
->node
== BGP_VNC_L2_GROUP_NODE
)
1933 vty
->node
= BGP_NODE
;
1938 DEFUNSH(VTYSH_BGPD
, rpki_exit
, rpki_exit_cmd
, "exit",
1939 "Exit current mode and down to previous mode\n")
1945 DEFUNSH(VTYSH_BGPD
, rpki_quit
, rpki_quit_cmd
, "quit",
1946 "Exit current mode and down to previous mode\n")
1948 return rpki_exit(self
, vty
, argc
, argv
);
1951 DEFUNSH(VTYSH_BGPD
, bmp_exit
, bmp_exit_cmd
, "exit",
1952 "Exit current mode and down to previous mode\n")
1958 DEFUNSH(VTYSH_BGPD
, bmp_quit
, bmp_quit_cmd
, "quit",
1959 "Exit current mode and down to previous mode\n")
1961 return bmp_exit(self
, vty
, argc
, argv
);
1964 DEFUNSH(VTYSH_VRF
, exit_vrf_config
, exit_vrf_config_cmd
, "exit-vrf",
1965 "Exit from VRF configuration mode\n")
1967 if (vty
->node
== VRF_NODE
)
1968 vty
->node
= CONFIG_NODE
;
1972 DEFUNSH(VTYSH_BGPD
, exit_vrf_policy
, exit_vrf_policy_cmd
, "exit-vrf-policy",
1973 "Exit from VRF policy configuration mode\n")
1975 if (vty
->node
== BGP_VRF_POLICY_NODE
)
1976 vty
->node
= BGP_NODE
;
1980 DEFUNSH(VTYSH_RIPD
, vtysh_exit_ripd
, vtysh_exit_ripd_cmd
, "exit",
1981 "Exit current mode and down to previous mode\n")
1983 return vtysh_exit(vty
);
1986 DEFUNSH(VTYSH_RIPD
, vtysh_quit_ripd
, vtysh_quit_ripd_cmd
, "quit",
1987 "Exit current mode and down to previous mode\n")
1989 return vtysh_exit_ripd(self
, vty
, argc
, argv
);
1992 DEFUNSH(VTYSH_RIPNGD
, vtysh_exit_ripngd
, vtysh_exit_ripngd_cmd
, "exit",
1993 "Exit current mode and down to previous mode\n")
1995 return vtysh_exit(vty
);
1998 DEFUNSH(VTYSH_RIPNGD
, vtysh_quit_ripngd
, vtysh_quit_ripngd_cmd
, "quit",
1999 "Exit current mode and down to previous mode\n")
2001 return vtysh_exit_ripngd(self
, vty
, argc
, argv
);
2004 DEFUNSH(VTYSH_RMAP
, vtysh_exit_rmap
, vtysh_exit_rmap_cmd
, "exit",
2005 "Exit current mode and down to previous mode\n")
2007 return vtysh_exit(vty
);
2010 DEFUNSH(VTYSH_RMAP
, vtysh_quit_rmap
, vtysh_quit_rmap_cmd
, "quit",
2011 "Exit current mode and down to previous mode\n")
2013 return vtysh_exit_rmap(self
, vty
, argc
, argv
);
2016 DEFUNSH(VTYSH_PBRD
, vtysh_exit_pbr_map
, vtysh_exit_pbr_map_cmd
, "exit",
2017 "Exit current mode and down to previous mode\n")
2019 return vtysh_exit(vty
);
2022 DEFUNSH(VTYSH_PBRD
, vtysh_quit_pbr_map
, vtysh_quit_pbr_map_cmd
, "quit",
2023 "Exit current mode and down to previous mode\n")
2025 return vtysh_exit_rmap(self
, vty
, argc
, argv
);
2028 DEFUNSH(VTYSH_BGPD
, vtysh_exit_bgpd
, vtysh_exit_bgpd_cmd
, "exit",
2029 "Exit current mode and down to previous mode\n")
2031 return vtysh_exit(vty
);
2034 DEFUNSH(VTYSH_BGPD
, vtysh_quit_bgpd
, vtysh_quit_bgpd_cmd
, "quit",
2035 "Exit current mode and down to previous mode\n")
2037 return vtysh_exit_bgpd(self
, vty
, argc
, argv
);
2040 DEFUNSH(VTYSH_OSPFD
, vtysh_exit_ospfd
, vtysh_exit_ospfd_cmd
, "exit",
2041 "Exit current mode and down to previous mode\n")
2043 return vtysh_exit(vty
);
2046 DEFUNSH(VTYSH_OSPFD
, vtysh_quit_ospfd
, vtysh_quit_ospfd_cmd
, "quit",
2047 "Exit current mode and down to previous mode\n")
2049 return vtysh_exit_ospfd(self
, vty
, argc
, argv
);
2052 DEFUNSH(VTYSH_EIGRPD
, vtysh_exit_eigrpd
, vtysh_exit_eigrpd_cmd
, "exit",
2053 "Exit current mode and down to previous mode\n")
2055 return vtysh_exit(vty
);
2058 DEFUNSH(VTYSH_EIGRPD
, vtysh_quit_eigrpd
, vtysh_quit_eigrpd_cmd
, "quit",
2059 "Exit current mode and down to previous mode\n")
2061 return vtysh_exit(vty
);
2064 DEFUNSH(VTYSH_EIGRPD
, vtysh_exit_babeld
, vtysh_exit_babeld_cmd
, "exit",
2065 "Exit current mode and down to previous mode\n")
2067 return vtysh_exit(vty
);
2070 DEFUNSH(VTYSH_BABELD
, vtysh_quit_babeld
, vtysh_quit_babeld_cmd
, "quit",
2071 "Exit current mode and down to previous mode\n")
2073 return vtysh_exit(vty
);
2076 DEFUNSH(VTYSH_OSPF6D
, vtysh_exit_ospf6d
, vtysh_exit_ospf6d_cmd
, "exit",
2077 "Exit current mode and down to previous mode\n")
2079 return vtysh_exit(vty
);
2082 DEFUNSH(VTYSH_OSPF6D
, vtysh_quit_ospf6d
, vtysh_quit_ospf6d_cmd
, "quit",
2083 "Exit current mode and down to previous mode\n")
2085 return vtysh_exit_ospf6d(self
, vty
, argc
, argv
);
2088 #if defined(HAVE_LDPD)
2089 DEFUNSH(VTYSH_LDPD
, vtysh_exit_ldpd
, vtysh_exit_ldpd_cmd
, "exit",
2090 "Exit current mode and down to previous mode\n")
2092 return vtysh_exit(vty
);
2095 ALIAS(vtysh_exit_ldpd
, vtysh_quit_ldpd_cmd
, "quit",
2096 "Exit current mode and down to previous mode\n")
2099 DEFUNSH(VTYSH_ISISD
, vtysh_exit_isisd
, vtysh_exit_isisd_cmd
, "exit",
2100 "Exit current mode and down to previous mode\n")
2102 return vtysh_exit(vty
);
2105 DEFUNSH(VTYSH_ISISD
, vtysh_quit_isisd
, vtysh_quit_isisd_cmd
, "quit",
2106 "Exit current mode and down to previous mode\n")
2108 return vtysh_exit_isisd(self
, vty
, argc
, argv
);
2112 DEFUNSH(VTYSH_BFDD
, vtysh_exit_bfdd
, vtysh_exit_bfdd_cmd
, "exit",
2113 "Exit current mode and down to previous mode\n")
2115 return vtysh_exit(vty
);
2118 ALIAS(vtysh_exit_bfdd
, vtysh_quit_bfdd_cmd
, "quit",
2119 "Exit current mode and down to previous mode\n")
2122 DEFUNSH(VTYSH_FABRICD
, vtysh_exit_fabricd
, vtysh_exit_fabricd_cmd
, "exit",
2123 "Exit current mode and down to previous mode\n")
2125 return vtysh_exit(vty
);
2128 DEFUNSH(VTYSH_FABRICD
, vtysh_quit_fabricd
, vtysh_quit_fabricd_cmd
, "quit",
2129 "Exit current mode and down to previous mode\n")
2131 return vtysh_exit_fabricd(self
, vty
, argc
, argv
);
2134 DEFUNSH(VTYSH_ALL
, vtysh_exit_line_vty
, vtysh_exit_line_vty_cmd
, "exit",
2135 "Exit current mode and down to previous mode\n")
2137 return vtysh_exit(vty
);
2140 DEFUNSH(VTYSH_ALL
, vtysh_quit_line_vty
, vtysh_quit_line_vty_cmd
, "quit",
2141 "Exit current mode and down to previous mode\n")
2143 return vtysh_exit_line_vty(self
, vty
, argc
, argv
);
2146 DEFUNSH(VTYSH_INTERFACE
, vtysh_interface
, vtysh_interface_cmd
,
2147 "interface IFNAME [vrf NAME]",
2148 "Select an interface to configure\n"
2149 "Interface's name\n" VRF_CMD_HELP_STR
)
2151 vty
->node
= INTERFACE_NODE
;
2155 DEFUNSH(VTYSH_ZEBRA
, vtysh_pseudowire
, vtysh_pseudowire_cmd
,
2156 "pseudowire IFNAME",
2157 "Static pseudowire configuration\n"
2158 "Pseudowire name\n")
2160 vty
->node
= PW_NODE
;
2164 DEFUNSH(VTYSH_PBRD
| VTYSH_SHARPD
, vtysh_nexthop_group
, vtysh_nexthop_group_cmd
,
2165 "nexthop-group NHGNAME",
2166 "Nexthop Group configuration\n"
2167 "Name of the Nexthop Group\n")
2169 vty
->node
= NH_GROUP_NODE
;
2173 DEFSH(VTYSH_PBRD
| VTYSH_SHARPD
, vtysh_no_nexthop_group_cmd
,
2174 "no nexthop-group NHGNAME",
2176 "Nexthop Group Configuration\n"
2177 "Name of the Nexthop Group\n")
2179 DEFUNSH(VTYSH_VRF
, vtysh_vrf
, vtysh_vrf_cmd
, "vrf NAME",
2180 "Select a VRF to configure\n"
2183 vty
->node
= VRF_NODE
;
2187 DEFSH(VTYSH_ZEBRA
, vtysh_vrf_netns_cmd
,
2189 "Attach VRF to a Namespace\n"
2190 "The file name in " NS_RUN_DIR
", or a full pathname\n")
2192 DEFSH(VTYSH_ZEBRA
, vtysh_no_vrf_netns_cmd
,
2195 "Detach VRF from a Namespace\n"
2196 "The file name in " NS_RUN_DIR
", or a full pathname\n")
2198 DEFUNSH(VTYSH_VRF
, vtysh_exit_vrf
, vtysh_exit_vrf_cmd
, "exit",
2199 "Exit current mode and down to previous mode\n")
2201 return vtysh_exit(vty
);
2204 DEFUNSH(VTYSH_VRF
, vtysh_quit_vrf
, vtysh_quit_vrf_cmd
, "quit",
2205 "Exit current mode and down to previous mode\n")
2207 return vtysh_exit_vrf(self
, vty
, argc
, argv
);
2210 DEFUNSH(VTYSH_PBRD
| VTYSH_SHARPD
, vtysh_exit_nexthop_group
, vtysh_exit_nexthop_group_cmd
,
2211 "exit", "Exit current mode and down to previous mode\n")
2213 return vtysh_exit(vty
);
2216 DEFUNSH(VTYSH_PBRD
| VTYSH_SHARPD
, vtysh_quit_nexthop_group
, vtysh_quit_nexthop_group_cmd
,
2217 "quit", "Exit current mode and down to previous mode\n")
2219 return vtysh_exit_nexthop_group(self
, vty
, argc
, argv
);
2222 DEFUNSH(VTYSH_INTERFACE
, vtysh_exit_interface
, vtysh_exit_interface_cmd
, "exit",
2223 "Exit current mode and down to previous mode\n")
2225 return vtysh_exit(vty
);
2228 DEFUNSH(VTYSH_INTERFACE
, vtysh_quit_interface
, vtysh_quit_interface_cmd
, "quit",
2229 "Exit current mode and down to previous mode\n")
2231 return vtysh_exit_interface(self
, vty
, argc
, argv
);
2234 DEFUN (vtysh_show_poll
,
2235 vtysh_show_poll_cmd
,
2238 "Thread information\n"
2239 "Thread Poll Information\n")
2242 int ret
= CMD_SUCCESS
;
2245 snprintf(line
, sizeof(line
), "do show thread poll\n");
2246 for (i
= 0; i
< array_size(vtysh_client
); i
++)
2247 if (vtysh_client
[i
].fd
>= 0) {
2248 vty_out(vty
, "Thread statistics for %s:\n",
2249 vtysh_client
[i
].name
);
2250 ret
= vtysh_client_execute(&vtysh_client
[i
], line
);
2256 DEFUN (vtysh_show_thread
,
2257 vtysh_show_thread_cmd
,
2258 "show thread cpu [FILTER]",
2260 "Thread information\n"
2261 "Thread CPU usage\n"
2262 "Display filter (rwtexb)\n")
2266 int ret
= CMD_SUCCESS
;
2269 const char *filter
=
2270 argv_find(argv
, argc
, "FILTER", &idx
) ? argv
[idx
]->arg
: "";
2272 snprintf(line
, sizeof(line
), "do show thread cpu %s\n", filter
);
2273 for (i
= 0; i
< array_size(vtysh_client
); i
++)
2274 if (vtysh_client
[i
].fd
>= 0) {
2275 vty_out(vty
, "Thread statistics for %s:\n",
2276 vtysh_client
[i
].name
);
2277 ret
= vtysh_client_execute(&vtysh_client
[i
], line
);
2283 DEFUN (vtysh_show_work_queues
,
2284 vtysh_show_work_queues_cmd
,
2287 "Work Queue information\n")
2290 int ret
= CMD_SUCCESS
;
2291 char line
[] = "do show work-queues\n";
2293 for (i
= 0; i
< array_size(vtysh_client
); i
++)
2294 if (vtysh_client
[i
].fd
>= 0) {
2295 vty_out(vty
, "Work queue statistics for %s:\n",
2296 vtysh_client
[i
].name
);
2297 ret
= vtysh_client_execute(&vtysh_client
[i
], line
);
2304 DEFUN (vtysh_show_work_queues_daemon
,
2305 vtysh_show_work_queues_daemon_cmd
,
2306 "show work-queues " DAEMONS_LIST
,
2308 "Work Queue information\n"
2311 int idx_protocol
= 2;
2313 return vtysh_client_execute_name(argv
[idx_protocol
]->text
,
2314 "show work-queues\n");
2317 DEFUNSH(VTYSH_ZEBRA
, vtysh_link_params
, vtysh_link_params_cmd
, "link-params",
2320 vty
->node
= LINK_PARAMS_NODE
;
2324 DEFUNSH(VTYSH_ZEBRA
, exit_link_params
, exit_link_params_cmd
, "exit-link-params",
2325 "Exit from Link Params configuration node\n")
2327 if (vty
->node
== LINK_PARAMS_NODE
)
2328 vty
->node
= INTERFACE_NODE
;
2332 static int show_per_daemon(const char *line
, const char *headline
)
2335 int ret
= CMD_SUCCESS
;
2337 for (i
= 0; i
< array_size(vtysh_client
); i
++)
2338 if (vtysh_client
[i
].fd
>= 0) {
2339 vty_out(vty
, headline
, vtysh_client
[i
].name
);
2340 ret
= vtysh_client_execute(&vtysh_client
[i
], line
);
2347 DEFUNSH_HIDDEN (0x00,
2349 vtysh_debug_all_cmd
,
2353 "Toggle all debugs on or off\n")
2358 DEFUN (vtysh_show_debugging
,
2359 vtysh_show_debugging_cmd
,
2364 return show_per_daemon("do show debugging\n", "");
2367 DEFUN (vtysh_show_debugging_hashtable
,
2368 vtysh_show_debugging_hashtable_cmd
,
2369 "show debugging hashtable [statistics]",
2372 "Statistics about hash tables\n"
2373 "Statistics about hash tables\n")
2377 "Load factor (LF) - average number of elements across all buckets\n");
2379 "Full load factor (FLF) - average number of elements across full buckets\n\n");
2381 "Standard deviation (SD) is calculated for both the LF and FLF\n");
2383 "and indicates the typical deviation of bucket chain length\n");
2384 vty_out(vty
, "from the value in the corresponding load factor.\n\n");
2386 return show_per_daemon("do show debugging hashtable\n",
2387 "Hashtable statistics for %s:\n");
2390 DEFUN (vtysh_show_error_code
,
2391 vtysh_show_error_code_cmd
,
2392 "show error <(1-4294967296)|all> [json]",
2394 "Information on errors\n"
2395 "Error code to get info about\n"
2396 "Information on all errors\n"
2401 if (!strmatch(argv
[2]->text
, "all"))
2402 arg
= strtoul(argv
[2]->arg
, NULL
, 10);
2404 /* If it's not a shared code, send it to all the daemons */
2405 if (arg
< LIB_FERR_START
|| arg
> LIB_FERR_END
) {
2406 char *fcmd
= argv_concat(argv
, argc
, 0);
2409 snprintf(cmd
, sizeof(cmd
), "do %s", fcmd
);
2410 show_per_daemon(cmd
, "");
2411 XFREE(MTYPE_TMP
, fcmd
);
2412 /* Otherwise, print it ourselves to avoid duplication */
2414 bool json
= strmatch(argv
[argc
- 1]->text
, "json");
2416 if (!strmatch(argv
[2]->text
, "all"))
2417 arg
= strtoul(argv
[2]->arg
, NULL
, 10);
2419 log_ref_display(vty
, arg
, json
);
2426 DEFUN (show_yang_operational_data
,
2427 show_yang_operational_data_cmd
,
2428 "show yang operational-data XPATH$xpath\
2430 format <json$json|xml$xml>\
2431 |translate WORD$translator_family\
2434 "YANG information\n"
2435 "Show YANG operational data\n"
2436 "XPath expression specifying the YANG data path\n"
2437 "Set the output format\n"
2438 "JavaScript Object Notation\n"
2439 "Extensible Markup Language\n"
2440 "Translate operational data\n"
2441 "YANG module translator\n"
2444 int idx_protocol
= argc
- 1;
2445 char *fcmd
= argv_concat(argv
, argc
- 1, 0);
2446 int ret
= vtysh_client_execute_name(argv
[idx_protocol
]->text
, fcmd
);
2447 XFREE(MTYPE_TMP
, fcmd
);
2451 DEFUNSH(VTYSH_ALL
, debug_nb
,
2453 "[no] debug northbound\
2455 callbacks$cbs [{configuration$cbs_cfg|state$cbs_state|rpc$cbs_rpc}]\
2456 |notifications$notifications\
2461 "Northbound debugging\n"
2473 DEFUN (vtysh_show_memory
,
2474 vtysh_show_memory_cmd
,
2477 "Memory statistics\n")
2479 return show_per_daemon("do show memory\n", "Memory statistics for %s:\n");
2482 DEFUN (vtysh_show_modules
,
2483 vtysh_show_modules_cmd
,
2488 return show_per_daemon("do show modules\n",
2489 "Module information for %s:\n");
2492 /* Logging commands. */
2493 DEFUN (vtysh_show_logging
,
2494 vtysh_show_logging_cmd
,
2497 "Show current logging configuration\n")
2499 return show_per_daemon("do show logging\n",
2500 "Logging configuration for %s:\n");
2503 DEFUNSH(VTYSH_ALL
, vtysh_log_stdout
, vtysh_log_stdout_cmd
, "log stdout",
2505 "Set stdout logging level\n")
2510 DEFUNSH(VTYSH_ALL
, vtysh_log_stdout_level
, vtysh_log_stdout_level_cmd
,
2511 "log stdout <emergencies|alerts|critical|errors|warnings|notifications|informational|debugging>",
2513 "Set stdout logging level\n" LOG_LEVEL_DESC
)
2518 DEFUNSH(VTYSH_ALL
, no_vtysh_log_stdout
, no_vtysh_log_stdout_cmd
,
2519 "no log stdout [LEVEL]", NO_STR
2521 "Cancel logging to stdout\n"
2527 DEFUNSH(VTYSH_ALL
, vtysh_log_file
, vtysh_log_file_cmd
, "log file FILENAME",
2530 "Logging filename\n")
2535 DEFUNSH(VTYSH_ALL
, vtysh_log_file_level
, vtysh_log_file_level_cmd
,
2536 "log file FILENAME <emergencies|alerts|critical|errors|warnings|notifications|informational|debugging>",
2539 "Logging filename\n" LOG_LEVEL_DESC
)
2544 DEFUNSH(VTYSH_ALL
, no_vtysh_log_file
, no_vtysh_log_file_cmd
,
2545 "no log file [FILENAME [LEVEL]]", NO_STR
2547 "Cancel logging to file\n"
2548 "Logging file name\n"
2554 DEFUNSH(VTYSH_ALL
, vtysh_log_monitor
, vtysh_log_monitor_cmd
,
2555 "log monitor [<emergencies|alerts|critical|errors|warnings|notifications|informational|debugging>]",
2557 "Set terminal line (monitor) logging level\n" LOG_LEVEL_DESC
)
2562 DEFUNSH(VTYSH_ALL
, no_vtysh_log_monitor
, no_vtysh_log_monitor_cmd
,
2563 "no log monitor [LEVEL]", NO_STR
2565 "Disable terminal line (monitor) logging\n"
2571 DEFUNSH(VTYSH_ALL
, vtysh_log_syslog
, vtysh_log_syslog_cmd
,
2572 "log syslog [<emergencies|alerts|critical|errors|warnings|notifications|informational|debugging>]",
2574 "Set syslog logging level\n" LOG_LEVEL_DESC
)
2579 DEFUNSH(VTYSH_ALL
, no_vtysh_log_syslog
, no_vtysh_log_syslog_cmd
,
2580 "no log syslog [<emergencies|alerts|critical|errors|warnings|notifications|informational|debugging>]",
2583 "Cancel logging to syslog\n"
2589 DEFUNSH(VTYSH_ALL
, vtysh_log_facility
, vtysh_log_facility_cmd
,
2590 "log facility <kern|user|mail|daemon|auth|syslog|lpr|news|uucp|cron|local0|local1|local2|local3|local4|local5|local6|local7>",
2592 "Facility parameter for syslog messages\n" LOG_FACILITY_DESC
)
2597 DEFUNSH(VTYSH_ALL
, no_vtysh_log_facility
, no_vtysh_log_facility_cmd
,
2598 "no log facility [<kern|user|mail|daemon|auth|syslog|lpr|news|uucp|cron|local0|local1|local2|local3|local4|local5|local6|local7>]",
2601 "Reset syslog facility to default (daemon)\n"
2607 DEFUNSH(VTYSH_ALL
, vtysh_log_record_priority
, vtysh_log_record_priority_cmd
,
2608 "log record-priority",
2610 "Log the priority of the message within the message\n")
2615 DEFUNSH(VTYSH_ALL
, no_vtysh_log_record_priority
,
2616 no_vtysh_log_record_priority_cmd
, "no log record-priority", NO_STR
2618 "Do not log the priority of the message within the message\n")
2623 DEFUNSH(VTYSH_ALL
, vtysh_log_timestamp_precision
,
2624 vtysh_log_timestamp_precision_cmd
, "log timestamp precision (0-6)",
2626 "Timestamp configuration\n"
2627 "Set the timestamp precision\n"
2628 "Number of subsecond digits\n")
2633 DEFUNSH(VTYSH_ALL
, vtysh_debug_memstats
,
2634 vtysh_debug_memstats_cmd
, "[no] debug memstats-at-exit",
2637 "Print memory statistics at exit\n")
2642 DEFUNSH(VTYSH_ALL
, no_vtysh_log_timestamp_precision
,
2643 no_vtysh_log_timestamp_precision_cmd
, "no log timestamp precision",
2646 "Timestamp configuration\n"
2647 "Reset the timestamp precision to the default value of 0\n")
2652 DEFUNSH(VTYSH_ALL
, vtysh_service_password_encrypt
,
2653 vtysh_service_password_encrypt_cmd
, "service password-encryption",
2654 "Set up miscellaneous service\n"
2655 "Enable encrypted passwords\n")
2660 DEFUNSH(VTYSH_ALL
, no_vtysh_service_password_encrypt
,
2661 no_vtysh_service_password_encrypt_cmd
, "no service password-encryption",
2663 "Set up miscellaneous service\n"
2664 "Enable encrypted passwords\n")
2669 DEFUNSH(VTYSH_ALL
, vtysh_config_password
, vtysh_password_cmd
,
2670 "password [(8-8)] LINE",
2671 "Modify the terminal connection password\n"
2672 "Specifies a HIDDEN password will follow\n"
2673 "The password string\n")
2678 DEFUNSH(VTYSH_ALL
, no_vtysh_config_password
, no_vtysh_password_cmd
,
2679 "no password", NO_STR
2680 "Modify the terminal connection password\n")
2682 vty_out(vty
, NO_PASSWD_CMD_WARNING
);
2687 DEFUNSH(VTYSH_ALL
, vtysh_config_enable_password
, vtysh_enable_password_cmd
,
2688 "enable password [(8-8)] LINE",
2689 "Modify enable password parameters\n"
2690 "Assign the privileged level password\n"
2691 "Specifies a HIDDEN password will follow\n"
2692 "The 'enable' password string\n")
2697 DEFUNSH(VTYSH_ALL
, no_vtysh_config_enable_password
,
2698 no_vtysh_enable_password_cmd
, "no enable password", NO_STR
2699 "Modify enable password parameters\n"
2700 "Assign the privileged level password\n")
2702 vty_out(vty
, NO_PASSWD_CMD_WARNING
);
2708 DEFUN (vtysh_log_filter
,
2709 vtysh_log_filter_cmd
,
2710 "[no] log-filter WORD ["DAEMONS_LIST
"]",
2713 "String to filter by\n"
2716 char *filter
= NULL
;
2717 char *daemon
= NULL
;
2724 char line
[ZLOG_FILTER_LENGTH_MAX
+ 20];
2726 found
= argv_find(argv
, argc
, "no", &idx
);
2728 len
= snprintf(line
, sizeof(line
), "no log-filter");
2731 len
= snprintf(line
, sizeof(line
), "log-filter");
2736 found
= argv_find(argv
, argc
, "WORD", &idx
);
2738 vty_out(vty
, "%% No filter string given\n");
2741 filter
= argv
[idx
]->arg
;
2743 if (strnlen(filter
, ZLOG_FILTER_LENGTH_MAX
+ 1)
2744 > ZLOG_FILTER_LENGTH_MAX
) {
2745 vty_out(vty
, "%% Filter is too long\n");
2749 len
= snprintf(line
+ total_len
, sizeof(line
) - total_len
, " %s\n",
2752 if ((len
< 0) || (size_t)(total_len
+ len
) > sizeof(line
)) {
2753 vty_out(vty
, "%% Error buffering filter to daemons\n");
2754 return CMD_ERR_INCOMPLETE
;
2757 if (argc
>= (daemon_idx
+ 1))
2758 daemon
= argv
[daemon_idx
]->text
;
2760 if (daemon
!= NULL
) {
2761 vty_out(vty
, "Applying log filter change to %s:\n", daemon
);
2762 return vtysh_client_execute_name(daemon
, line
);
2764 return show_per_daemon(line
,
2765 "Applying log filter change to %s:\n");
2768 /* Clear log filters */
2769 DEFUN (vtysh_log_filter_clear
,
2770 vtysh_log_filter_clear_cmd
,
2771 "log-filter clear ["DAEMONS_LIST
"]",
2776 char *daemon
= NULL
;
2779 char line
[] = "clear log-filter\n";
2781 if (argc
>= (daemon_idx
+ 1))
2782 daemon
= argv
[daemon_idx
]->text
;
2784 if (daemon
!= NULL
) {
2785 vty_out(vty
, "Clearing all filters applied to %s:\n", daemon
);
2786 return vtysh_client_execute_name(daemon
, line
);
2788 return show_per_daemon(line
,
2789 "Clearing all filters applied to %s:\n");
2792 /* Show log filter */
2793 DEFUN (vtysh_show_log_filter
,
2794 vtysh_show_log_filter_cmd
,
2799 char line
[] = "do show log-filter\n";
2801 return show_per_daemon(line
, "Log filters applied to %s:\n");
2804 DEFUN (vtysh_write_terminal
,
2805 vtysh_write_terminal_cmd
,
2806 "write terminal ["DAEMONS_LIST
"]",
2807 "Write running configuration to memory, network, or terminal\n"
2808 "Write to terminal\n"
2812 char line
[] = "do write terminal\n";
2814 vty_out(vty
, "Building configuration...\n");
2815 vty_out(vty
, "\nCurrent configuration:\n");
2816 vty_out(vty
, "!\n");
2818 for (i
= 0; i
< array_size(vtysh_client
); i
++)
2820 || (strmatch(vtysh_client
[i
].name
, argv
[2]->text
)))
2821 vtysh_client_config(&vtysh_client
[i
], line
);
2823 /* Integrate vtysh specific configuration. */
2824 vty_open_pager(vty
);
2825 vtysh_config_write();
2826 vtysh_config_dump();
2827 vty_close_pager(vty
);
2828 vty_out(vty
, "end\n");
2833 DEFUN (vtysh_show_running_config
,
2834 vtysh_show_running_config_cmd
,
2835 "show running-config ["DAEMONS_LIST
"]",
2837 "Current operating configuration\n"
2840 return vtysh_write_terminal(self
, vty
, argc
, argv
);
2843 DEFUN (vtysh_integrated_config
,
2844 vtysh_integrated_config_cmd
,
2845 "service integrated-vtysh-config",
2846 "Set up miscellaneous service\n"
2847 "Write configuration into integrated file\n")
2849 vtysh_write_integrated
= WRITE_INTEGRATED_YES
;
2853 DEFUN (no_vtysh_integrated_config
,
2854 no_vtysh_integrated_config_cmd
,
2855 "no service integrated-vtysh-config",
2857 "Set up miscellaneous service\n"
2858 "Write configuration into integrated file\n")
2860 vtysh_write_integrated
= WRITE_INTEGRATED_NO
;
2864 static void backup_config_file(const char *fbackup
)
2866 char *integrate_sav
= NULL
;
2868 size_t integrate_sav_sz
= strlen(fbackup
) + strlen(CONF_BACKUP_EXT
) + 1;
2869 integrate_sav
= malloc(integrate_sav_sz
);
2870 strlcpy(integrate_sav
, fbackup
, integrate_sav_sz
);
2871 strlcat(integrate_sav
, CONF_BACKUP_EXT
, integrate_sav_sz
);
2873 /* Move current configuration file to backup config file. */
2874 if (unlink(integrate_sav
) != 0) {
2875 vty_out(vty
, "Warning: %s unlink failed\n", integrate_sav
);
2877 if (rename(fbackup
, integrate_sav
) != 0) {
2878 vty_out(vty
, "Error renaming %s to %s\n", fbackup
,
2881 free(integrate_sav
);
2884 int vtysh_write_config_integrated(void)
2887 char line
[] = "do write terminal\n";
2891 struct passwd
*pwentry
;
2894 struct group
*grentry
;
2901 vty_out(vty
, "Building Configuration...\n");
2903 backup_config_file(frr_config
);
2904 fp
= fopen(frr_config
, "w");
2907 "%% Error: failed to open configuration file %s: %s\n",
2908 frr_config
, safe_strerror(errno
));
2909 return CMD_WARNING_CONFIG_FAILED
;
2913 for (i
= 0; i
< array_size(vtysh_client
); i
++)
2914 vtysh_client_config(&vtysh_client
[i
], line
);
2916 vtysh_config_write();
2917 vty
->of_saved
= vty
->of
;
2919 vtysh_config_dump();
2920 vty
->of
= vty
->of_saved
;
2922 if (fchmod(fd
, CONFIGFILE_MASK
) != 0) {
2923 printf("%% Warning: can't chmod configuration file %s: %s\n",
2924 frr_config
, safe_strerror(errno
));
2929 pwentry
= getpwnam(FRR_USER
);
2931 uid
= pwentry
->pw_uid
;
2933 printf("%% Warning: could not look up user \"%s\"\n", FRR_USER
);
2938 grentry
= getgrnam(FRR_GROUP
);
2940 gid
= grentry
->gr_gid
;
2942 printf("%% Warning: could not look up group \"%s\"\n",
2948 if (!fstat(fd
, &st
)) {
2949 if (st
.st_uid
== uid
)
2951 if (st
.st_gid
== gid
)
2953 if ((uid
!= (uid_t
)-1 || gid
!= (gid_t
)-1)
2954 && fchown(fd
, uid
, gid
)) {
2955 printf("%% Warning: can't chown configuration file %s: %s\n",
2956 frr_config
, safe_strerror(errno
));
2960 printf("%% Warning: stat() failed on %s: %s\n", frr_config
,
2961 safe_strerror(errno
));
2967 printf("Integrated configuration saved to %s\n", frr_config
);
2975 static bool want_config_integrated(void)
2979 switch (vtysh_write_integrated
) {
2980 case WRITE_INTEGRATED_UNSPECIFIED
:
2981 if (stat(frr_config
, &s
) && errno
== ENOENT
)
2984 case WRITE_INTEGRATED_NO
:
2986 case WRITE_INTEGRATED_YES
:
2992 DEFUN (vtysh_write_memory
,
2993 vtysh_write_memory_cmd
,
2994 "write [<memory|file>]",
2995 "Write running configuration to memory, network, or terminal\n"
2996 "Write configuration to the file (same as write file)\n"
2997 "Write configuration to the file (same as write memory)\n")
2999 int ret
= CMD_SUCCESS
;
3000 char line
[] = "do write memory\n";
3003 vty_out(vty
, "Note: this version of vtysh never writes vtysh.conf\n");
3005 /* If integrated frr.conf explicitely set. */
3006 if (want_config_integrated()) {
3007 ret
= CMD_WARNING_CONFIG_FAILED
;
3009 /* first attempt to use watchfrr if it's available */
3010 bool used_watchfrr
= false;
3012 for (i
= 0; i
< array_size(vtysh_client
); i
++)
3013 if (vtysh_client
[i
].flag
== VTYSH_WATCHFRR
)
3015 if (i
< array_size(vtysh_client
) && vtysh_client
[i
].fd
!= -1) {
3016 used_watchfrr
= true;
3017 ret
= vtysh_client_execute(&vtysh_client
[i
],
3018 "do write integrated");
3022 * If we didn't use watchfrr, fallback to writing the config
3025 if (!used_watchfrr
) {
3026 printf("\nWarning: attempting direct configuration write without "
3027 "watchfrr.\nFile permissions and ownership may be "
3028 "incorrect, or write may fail.\n\n");
3029 ret
= vtysh_write_config_integrated();
3034 vty_out(vty
, "Building Configuration...\n");
3036 for (i
= 0; i
< array_size(vtysh_client
); i
++)
3037 ret
= vtysh_client_execute(&vtysh_client
[i
], line
);
3042 DEFUN (vtysh_copy_running_config
,
3043 vtysh_copy_running_config_cmd
,
3044 "copy running-config startup-config",
3045 "Copy from one file to another\n"
3046 "Copy from current system configuration\n"
3047 "Copy to startup configuration\n")
3049 return vtysh_write_memory(self
, vty
, argc
, argv
);
3052 DEFUN (vtysh_terminal_paginate
,
3053 vtysh_terminal_paginate_cmd
,
3054 "[no] terminal paginate",
3056 "Set terminal line parameters\n"
3057 "Use pager for output scrolling\n")
3059 free(vtysh_pager_name
);
3060 vtysh_pager_name
= NULL
;
3062 if (strcmp(argv
[0]->text
, "no"))
3063 vtysh_pager_envdef(true);
3067 DEFUN (vtysh_terminal_length
,
3068 vtysh_terminal_length_cmd
,
3069 "[no] terminal length (0-4294967295)",
3071 "Set terminal line parameters\n"
3072 "Set number of lines on a screen\n"
3073 "Number of lines on screen (0 for no pausing, nonzero to use pager)\n")
3076 unsigned long lines
;
3078 free(vtysh_pager_name
);
3079 vtysh_pager_name
= NULL
;
3081 if (!strcmp(argv
[0]->text
, "no") || !strcmp(argv
[1]->text
, "no")) {
3082 /* "terminal no length" = use VTYSH_PAGER */
3083 vtysh_pager_envdef(true);
3087 lines
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
3090 "%% The \"terminal length\" command is deprecated and its value is ignored.\n"
3091 "%% Please use \"terminal paginate\" instead with OS TTY length handling.\n");
3092 vtysh_pager_envdef(true);
3098 ALIAS_DEPRECATED(vtysh_terminal_length
,
3099 vtysh_terminal_no_length_cmd
,
3100 "terminal no length",
3101 "Set terminal line parameters\n"
3103 "Set number of lines on a screen\n")
3105 DEFUN (vtysh_show_daemons
,
3106 vtysh_show_daemons_cmd
,
3109 "Show list of running daemons\n")
3113 for (i
= 0; i
< array_size(vtysh_client
); i
++)
3114 if (vtysh_client
[i
].fd
>= 0)
3115 vty_out(vty
, " %s", vtysh_client
[i
].name
);
3121 /* Execute command in child process. */
3122 static void execute_command(const char *command
, int argc
, const char *arg1
,
3132 /* Failure of fork(). */
3133 fprintf(stderr
, "Can't fork: %s\n", safe_strerror(errno
));
3135 } else if (pid
== 0) {
3136 /* This is child process. */
3139 execlp(command
, command
, (const char *)NULL
);
3142 execlp(command
, command
, arg1
, (const char *)NULL
);
3145 execlp(command
, command
, arg1
, arg2
,
3146 (const char *)NULL
);
3150 /* When execlp suceed, this part is not executed. */
3151 fprintf(stderr
, "Can't execute %s: %s\n", command
,
3152 safe_strerror(errno
));
3155 /* This is parent. */
3157 wait4(pid
, &status
, 0, NULL
);
3165 "Send echo messages\n"
3166 "Ping destination address or hostname\n")
3170 argv_find(argv
, argc
, "WORD", &idx
);
3171 execute_command("ping", 1, argv
[idx
]->arg
, NULL
);
3175 ALIAS(vtysh_ping
, vtysh_ping_ip_cmd
, "ping ip WORD",
3176 "Send echo messages\n"
3178 "Ping destination address or hostname\n")
3180 DEFUN (vtysh_traceroute
,
3181 vtysh_traceroute_cmd
,
3183 "Trace route to destination\n"
3184 "Trace route to destination address or hostname\n")
3188 argv_find(argv
, argc
, "WORD", &idx
);
3189 execute_command("traceroute", 1, argv
[idx
]->arg
, NULL
);
3193 ALIAS(vtysh_traceroute
, vtysh_traceroute_ip_cmd
, "traceroute ip WORD",
3194 "Trace route to destination\n"
3196 "Trace route to destination address or hostname\n")
3198 DEFUN (vtysh_mtrace
,
3200 "mtrace WORD [WORD]",
3201 "Multicast trace route to multicast source\n"
3202 "Multicast trace route to multicast source address\n"
3203 "Multicast trace route for multicast group address\n")
3206 execute_command("mtracebis", 1, argv
[1]->arg
, NULL
);
3208 execute_command("mtracebis", 2, argv
[1]->arg
, argv
[2]->arg
);
3215 "Send echo messages\n"
3217 "Ping destination address or hostname\n")
3219 execute_command("ping6", 1, argv
[2]->arg
, NULL
);
3223 DEFUN (vtysh_traceroute6
,
3224 vtysh_traceroute6_cmd
,
3225 "traceroute ipv6 WORD",
3226 "Trace route to destination\n"
3228 "Trace route to destination address or hostname\n")
3230 execute_command("traceroute6", 1, argv
[2]->arg
, NULL
);
3234 #if defined(HAVE_SHELL_ACCESS)
3235 DEFUN (vtysh_telnet
,
3238 "Open a telnet connection\n"
3239 "IP address or hostname of a remote system\n")
3241 execute_command("telnet", 1, argv
[1]->arg
, NULL
);
3245 DEFUN (vtysh_telnet_port
,
3246 vtysh_telnet_port_cmd
,
3248 "Open a telnet connection\n"
3249 "IP address or hostname of a remote system\n"
3250 "TCP Port number\n")
3252 execute_command("telnet", 2, argv
[1]->arg
, argv
[2]->arg
);
3259 "Open an ssh connection\n"
3262 execute_command("ssh", 1, argv
[1]->arg
, NULL
);
3266 DEFUN (vtysh_start_shell
,
3267 vtysh_start_shell_cmd
,
3269 "Start UNIX shell\n")
3271 execute_command("sh", 0, NULL
, NULL
);
3275 DEFUN (vtysh_start_bash
,
3276 vtysh_start_bash_cmd
,
3278 "Start UNIX shell\n"
3281 execute_command("bash", 0, NULL
, NULL
);
3285 DEFUN (vtysh_start_zsh
,
3286 vtysh_start_zsh_cmd
,
3288 "Start UNIX shell\n"
3291 execute_command("zsh", 0, NULL
, NULL
);
3298 "list [permutations]",
3299 "Print command list\n"
3300 "Print all possible command permutations\n")
3302 return cmd_list_cmds(vty
, argc
== 2);
3305 DEFUN (vtysh_output_file
,
3306 vtysh_output_file_cmd
,
3308 "Direct vtysh output to file\n"
3309 "Direct vtysh output to file\n"
3310 "Path to dump output to\n")
3312 const char *path
= argv
[argc
- 1]->arg
;
3313 vty
->of
= fopen(path
, "a");
3315 vty_out(vty
, "Failed to open file '%s': %s\n", path
,
3316 safe_strerror(errno
));
3322 DEFUN (no_vtysh_output_file
,
3323 no_vtysh_output_file_cmd
,
3324 "no output file [FILE]",
3326 "Direct vtysh output to file\n"
3327 "Direct vtysh output to file\n"
3328 "Path to dump output to\n")
3330 if (vty
->of
!= stdout
) {
3340 "Find CLI command matching a regular expression\n"
3341 "Search pattern (POSIX regex)\n")
3343 char *pattern
= argv
[1]->arg
;
3344 const struct cmd_node
*node
;
3345 const struct cmd_element
*cli
;
3350 int cr
= regcomp(&exp
, pattern
, REG_NOSUB
| REG_EXTENDED
);
3355 vty_out(vty
, "%% Invalid \\{...\\} expression\n");
3358 vty_out(vty
, "%% Bad repetition operator\n");
3361 vty_out(vty
, "%% Regex syntax error\n");
3364 vty_out(vty
, "%% Invalid collating element\n");
3367 vty_out(vty
, "%% Invalid character class name\n");
3371 "%% Regex ended with escape character (\\)\n");
3375 "%% Invalid number in \\digit construction\n");
3378 vty_out(vty
, "%% Unbalanced square brackets\n");
3381 vty_out(vty
, "%% Unbalanced parentheses\n");
3384 vty_out(vty
, "%% Unbalanced braces\n");
3388 "%% Invalid endpoint in range expression\n");
3391 vty_out(vty
, "%% Failed to compile (out of memory)\n");
3399 for (unsigned int i
= 0; i
< vector_active(cmdvec
); i
++) {
3400 node
= vector_slot(cmdvec
, i
);
3403 clis
= node
->cmd_vector
;
3404 for (unsigned int j
= 0; j
< vector_active(clis
); j
++) {
3405 cli
= vector_slot(clis
, j
);
3407 if (regexec(&exp
, cli
->string
, 0, NULL
, 0) == 0)
3408 vty_out(vty
, " (%s) %s\n",
3409 node_names
[node
->node
], cli
->string
);
3418 DEFUN_HIDDEN(show_cli_graph_vtysh
,
3419 show_cli_graph_vtysh_cmd
,
3423 "Dump current command space as DOT graph\n")
3425 struct cmd_node
*cn
= vector_slot(cmdvec
, vty
->node
);
3426 char *dot
= cmd_graph_dump_dot(cn
->cmdgraph
);
3428 vty_out(vty
, "%s\n", dot
);
3429 XFREE(MTYPE_TMP
, dot
);
3433 static void vtysh_install_default(enum node_type node
)
3435 install_element(node
, &config_list_cmd
);
3436 install_element(node
, &find_cmd
);
3437 install_element(node
, &show_cli_graph_vtysh_cmd
);
3438 install_element(node
, &vtysh_output_file_cmd
);
3439 install_element(node
, &no_vtysh_output_file_cmd
);
3442 /* Making connection to protocol daemon. */
3443 static int vtysh_connect(struct vtysh_client
*vclient
)
3447 struct sockaddr_un addr
;
3451 if (!vclient
->path
[0])
3452 snprintf(vclient
->path
, sizeof(vclient
->path
), "%s/%s.vty",
3453 vtydir
, vclient
->name
);
3454 path
= vclient
->path
;
3456 /* Stat socket to see if we have permission to access it. */
3457 ret
= stat(path
, &s_stat
);
3458 if (ret
< 0 && errno
!= ENOENT
) {
3459 fprintf(stderr
, "vtysh_connect(%s): stat = %s\n", path
,
3460 safe_strerror(errno
));
3465 if (!S_ISSOCK(s_stat
.st_mode
)) {
3466 fprintf(stderr
, "vtysh_connect(%s): Not a socket\n",
3472 sock
= socket(AF_UNIX
, SOCK_STREAM
, 0);
3475 fprintf(stderr
, "vtysh_connect(%s): socket = %s\n", path
,
3476 safe_strerror(errno
));
3481 memset(&addr
, 0, sizeof(struct sockaddr_un
));
3482 addr
.sun_family
= AF_UNIX
;
3483 strlcpy(addr
.sun_path
, path
, sizeof(addr
.sun_path
));
3484 #ifdef HAVE_STRUCT_SOCKADDR_UN_SUN_LEN
3485 len
= addr
.sun_len
= SUN_LEN(&addr
);
3487 len
= sizeof(addr
.sun_family
) + strlen(addr
.sun_path
);
3488 #endif /* HAVE_STRUCT_SOCKADDR_UN_SUN_LEN */
3490 ret
= connect(sock
, (struct sockaddr
*)&addr
, len
);
3493 fprintf(stderr
, "vtysh_connect(%s): connect = %s\n", path
,
3494 safe_strerror(errno
));
3504 static int vtysh_reconnect(struct vtysh_client
*vclient
)
3508 fprintf(stderr
, "Warning: connecting to %s...", vclient
->name
);
3509 ret
= vtysh_connect(vclient
);
3511 fprintf(stderr
, "failed!\n");
3514 fprintf(stderr
, "success!\n");
3515 if (vtysh_client_execute(vclient
, "enable") < 0)
3517 return vtysh_execute_no_pager("end");
3520 /* Return true if str ends with suffix, else return false */
3521 static int ends_with(const char *str
, const char *suffix
)
3523 if (!str
|| !suffix
)
3525 size_t lenstr
= strlen(str
);
3526 size_t lensuffix
= strlen(suffix
);
3527 if (lensuffix
> lenstr
)
3529 return strncmp(str
+ lenstr
- lensuffix
, suffix
, lensuffix
) == 0;
3532 static void vtysh_client_sorted_insert(struct vtysh_client
*head_client
,
3533 struct vtysh_client
*client
)
3535 struct vtysh_client
*prev_node
, *current_node
;
3537 prev_node
= head_client
;
3538 current_node
= head_client
->next
;
3539 while (current_node
) {
3540 if (strcmp(current_node
->path
, client
->path
) > 0)
3543 prev_node
= current_node
;
3544 current_node
= current_node
->next
;
3546 client
->next
= current_node
;
3547 prev_node
->next
= client
;
3550 #define MAXIMUM_INSTANCES 10
3552 static void vtysh_update_all_instances(struct vtysh_client
*head_client
)
3554 struct vtysh_client
*client
;
3556 struct dirent
*file
;
3559 if (head_client
->flag
!= VTYSH_OSPFD
)
3562 /* ls vty_sock_dir and look for all files ending in .vty */
3563 dir
= opendir(vtydir
);
3565 while ((file
= readdir(dir
)) != NULL
) {
3566 if (frrstr_startswith(file
->d_name
, "ospfd-")
3567 && ends_with(file
->d_name
, ".vty")) {
3568 if (n
== MAXIMUM_INSTANCES
) {
3570 "Parsing %s, client limit(%d) reached!\n",
3574 client
= (struct vtysh_client
*)malloc(
3575 sizeof(struct vtysh_client
));
3577 client
->name
= "ospfd";
3578 client
->flag
= VTYSH_OSPFD
;
3579 snprintf(client
->path
, sizeof(client
->path
),
3580 "%s/%s", vtydir
, file
->d_name
);
3581 client
->next
= NULL
;
3582 vtysh_client_sorted_insert(head_client
, client
);
3590 static int vtysh_connect_all_instances(struct vtysh_client
*head_client
)
3592 struct vtysh_client
*client
;
3595 vtysh_update_all_instances(head_client
);
3597 client
= head_client
->next
;
3599 if (vtysh_connect(client
) == 0)
3601 client
= client
->next
;
3607 int vtysh_connect_all(const char *daemon_name
)
3613 for (i
= 0; i
< array_size(vtysh_client
); i
++) {
3615 || !strcmp(daemon_name
, vtysh_client
[i
].name
)) {
3617 if (vtysh_connect(&vtysh_client
[i
]) == 0)
3620 rc
+= vtysh_connect_all_instances(&vtysh_client
[i
]);
3624 fprintf(stderr
, "Error: no daemons match name %s!\n",
3629 /* To disable readline's filename completion. */
3630 static char *vtysh_completion_entry_function(const char *ignore
,
3636 void vtysh_readline_init(void)
3638 /* readline related settings. */
3640 rl_bind_key('?', (rl_command_func_t
*)vtysh_rl_describe
);
3641 rl_completion_entry_function
= vtysh_completion_entry_function
;
3642 rl_attempted_completion_function
= new_completion
;
3645 char *vtysh_prompt(void)
3647 static char buf
[512];
3649 snprintf(buf
, sizeof buf
, cmd_prompt(vty
->node
), cmd_hostname_get());
3653 static void vtysh_ac_line(void *arg
, const char *line
)
3657 for (i
= 0; i
< vector_active(comps
); i
++)
3658 if (!strcmp(line
, (char *)vector_slot(comps
, i
)))
3660 vector_set(comps
, XSTRDUP(MTYPE_COMPLETION
, line
));
3663 static void vtysh_autocomplete(vector comps
, struct cmd_token
*token
)
3668 snprintf(accmd
, sizeof(accmd
), "autocomplete %d %s %s", token
->type
,
3669 token
->text
, token
->varname
? token
->varname
: "-");
3671 vty
->of_saved
= vty
->of
;
3673 for (i
= 0; i
< array_size(vtysh_client
); i
++)
3674 vtysh_client_run_all(&vtysh_client
[i
], accmd
, 1, vtysh_ac_line
,
3676 vty
->of
= vty
->of_saved
;
3679 static const struct cmd_variable_handler vtysh_var_handler
[] = {
3683 .completions
= vtysh_autocomplete
},
3684 {.completions
= NULL
}};
3686 void vtysh_uninit(void)
3688 if (vty
->of
!= stdout
)
3692 void vtysh_init_vty(void)
3694 /* Make vty structure. */
3696 vty
->type
= VTY_SHELL
;
3697 vty
->node
= VIEW_NODE
;
3699 /* set default output */
3701 vtysh_pager_envdef(false);
3703 /* Initialize commands. */
3705 cmd_variable_handler_register(vtysh_var_handler
);
3707 /* Install nodes. */
3708 install_node(&bgp_node
, NULL
);
3709 install_node(&rip_node
, NULL
);
3710 install_node(&interface_node
, NULL
);
3711 install_node(&pw_node
, NULL
);
3712 install_node(&link_params_node
, NULL
);
3713 install_node(&vrf_node
, NULL
);
3714 install_node(&nh_group_node
, NULL
);
3715 install_node(&rmap_node
, NULL
);
3716 install_node(&pbr_map_node
, NULL
);
3717 install_node(&zebra_node
, NULL
);
3718 install_node(&bgp_vpnv4_node
, NULL
);
3719 install_node(&bgp_vpnv6_node
, NULL
);
3720 install_node(&bgp_flowspecv4_node
, NULL
);
3721 install_node(&bgp_flowspecv6_node
, NULL
);
3722 install_node(&bgp_ipv4_node
, NULL
);
3723 install_node(&bgp_ipv4m_node
, NULL
);
3724 install_node(&bgp_ipv4l_node
, NULL
);
3725 install_node(&bgp_ipv6_node
, NULL
);
3726 install_node(&bgp_ipv6m_node
, NULL
);
3727 install_node(&bgp_ipv6l_node
, NULL
);
3728 install_node(&bgp_vrf_policy_node
, NULL
);
3729 install_node(&bgp_evpn_node
, NULL
);
3730 install_node(&bgp_evpn_vni_node
, NULL
);
3731 install_node(&bgp_vnc_defaults_node
, NULL
);
3732 install_node(&bgp_vnc_nve_group_node
, NULL
);
3733 install_node(&bgp_vnc_l2_group_node
, NULL
);
3734 install_node(&ospf_node
, NULL
);
3735 install_node(&eigrp_node
, NULL
);
3736 install_node(&babel_node
, NULL
);
3737 install_node(&ripng_node
, NULL
);
3738 install_node(&ospf6_node
, NULL
);
3739 install_node(&ldp_node
, NULL
);
3740 install_node(&ldp_ipv4_node
, NULL
);
3741 install_node(&ldp_ipv6_node
, NULL
);
3742 install_node(&ldp_ipv4_iface_node
, NULL
);
3743 install_node(&ldp_ipv6_iface_node
, NULL
);
3744 install_node(&ldp_l2vpn_node
, NULL
);
3745 install_node(&ldp_pseudowire_node
, NULL
);
3746 install_node(&keychain_node
, NULL
);
3747 install_node(&keychain_key_node
, NULL
);
3748 install_node(&isis_node
, NULL
);
3749 install_node(&openfabric_node
, NULL
);
3750 install_node(&vty_node
, NULL
);
3751 install_node(&rpki_node
, NULL
);
3752 install_node(&bmp_node
, NULL
);
3754 install_node(&bfd_node
, NULL
);
3755 install_node(&bfd_peer_node
, NULL
);
3756 #endif /* HAVE_BFDD */
3758 struct cmd_node
*node
;
3759 for (unsigned int i
= 0; i
< vector_active(cmdvec
); i
++) {
3760 node
= vector_slot(cmdvec
, i
);
3761 if (!node
|| node
->node
== VIEW_NODE
)
3763 vtysh_install_default(node
->node
);
3766 install_element(VIEW_NODE
, &vtysh_enable_cmd
);
3767 install_element(ENABLE_NODE
, &vtysh_config_terminal_cmd
);
3768 install_element(ENABLE_NODE
, &vtysh_disable_cmd
);
3770 /* "exit" command. */
3771 install_element(VIEW_NODE
, &vtysh_exit_all_cmd
);
3772 install_element(CONFIG_NODE
, &vtysh_exit_all_cmd
);
3773 install_element(VIEW_NODE
, &vtysh_quit_all_cmd
);
3774 install_element(CONFIG_NODE
, &vtysh_quit_all_cmd
);
3775 install_element(RIP_NODE
, &vtysh_exit_ripd_cmd
);
3776 install_element(RIP_NODE
, &vtysh_quit_ripd_cmd
);
3777 install_element(RIPNG_NODE
, &vtysh_exit_ripngd_cmd
);
3778 install_element(RIPNG_NODE
, &vtysh_quit_ripngd_cmd
);
3779 install_element(OSPF_NODE
, &vtysh_exit_ospfd_cmd
);
3780 install_element(OSPF_NODE
, &vtysh_quit_ospfd_cmd
);
3781 install_element(EIGRP_NODE
, &vtysh_exit_eigrpd_cmd
);
3782 install_element(EIGRP_NODE
, &vtysh_quit_eigrpd_cmd
);
3783 install_element(BABEL_NODE
, &vtysh_exit_babeld_cmd
);
3784 install_element(BABEL_NODE
, &vtysh_quit_babeld_cmd
);
3785 install_element(OSPF6_NODE
, &vtysh_exit_ospf6d_cmd
);
3786 install_element(OSPF6_NODE
, &vtysh_quit_ospf6d_cmd
);
3787 #if defined(HAVE_LDPD)
3788 install_element(LDP_NODE
, &vtysh_exit_ldpd_cmd
);
3789 install_element(LDP_NODE
, &vtysh_quit_ldpd_cmd
);
3790 install_element(LDP_IPV4_NODE
, &vtysh_exit_ldpd_cmd
);
3791 install_element(LDP_IPV4_NODE
, &vtysh_quit_ldpd_cmd
);
3792 install_element(LDP_IPV4_NODE
, &ldp_exit_address_family_cmd
);
3793 install_element(LDP_IPV6_NODE
, &vtysh_exit_ldpd_cmd
);
3794 install_element(LDP_IPV6_NODE
, &vtysh_quit_ldpd_cmd
);
3795 install_element(LDP_IPV6_NODE
, &ldp_exit_address_family_cmd
);
3796 install_element(LDP_IPV4_IFACE_NODE
, &vtysh_exit_ldpd_cmd
);
3797 install_element(LDP_IPV4_IFACE_NODE
, &vtysh_quit_ldpd_cmd
);
3798 install_element(LDP_IPV6_IFACE_NODE
, &vtysh_exit_ldpd_cmd
);
3799 install_element(LDP_IPV6_IFACE_NODE
, &vtysh_quit_ldpd_cmd
);
3800 install_element(LDP_L2VPN_NODE
, &vtysh_exit_ldpd_cmd
);
3801 install_element(LDP_L2VPN_NODE
, &vtysh_quit_ldpd_cmd
);
3802 install_element(LDP_PSEUDOWIRE_NODE
, &vtysh_exit_ldpd_cmd
);
3803 install_element(LDP_PSEUDOWIRE_NODE
, &vtysh_quit_ldpd_cmd
);
3805 install_element(BGP_NODE
, &vtysh_exit_bgpd_cmd
);
3806 install_element(BGP_NODE
, &vtysh_quit_bgpd_cmd
);
3807 install_element(BGP_VPNV4_NODE
, &vtysh_exit_bgpd_cmd
);
3808 install_element(BGP_VPNV4_NODE
, &vtysh_quit_bgpd_cmd
);
3809 install_element(BGP_VPNV6_NODE
, &vtysh_exit_bgpd_cmd
);
3810 install_element(BGP_VPNV6_NODE
, &vtysh_quit_bgpd_cmd
);
3811 install_element(BGP_FLOWSPECV4_NODE
, &vtysh_exit_bgpd_cmd
);
3812 install_element(BGP_FLOWSPECV4_NODE
, &vtysh_quit_bgpd_cmd
);
3813 install_element(BGP_FLOWSPECV6_NODE
, &vtysh_exit_bgpd_cmd
);
3814 install_element(BGP_FLOWSPECV6_NODE
, &vtysh_quit_bgpd_cmd
);
3815 install_element(BGP_IPV4_NODE
, &vtysh_exit_bgpd_cmd
);
3816 install_element(BGP_IPV4_NODE
, &vtysh_quit_bgpd_cmd
);
3817 install_element(BGP_IPV4M_NODE
, &vtysh_exit_bgpd_cmd
);
3818 install_element(BGP_IPV4M_NODE
, &vtysh_quit_bgpd_cmd
);
3819 install_element(BGP_IPV4L_NODE
, &vtysh_exit_bgpd_cmd
);
3820 install_element(BGP_IPV4L_NODE
, &vtysh_quit_bgpd_cmd
);
3821 install_element(BGP_IPV6_NODE
, &vtysh_exit_bgpd_cmd
);
3822 install_element(BGP_IPV6_NODE
, &vtysh_quit_bgpd_cmd
);
3823 install_element(BGP_IPV6M_NODE
, &vtysh_exit_bgpd_cmd
);
3824 install_element(BGP_IPV6M_NODE
, &vtysh_quit_bgpd_cmd
);
3825 install_element(BGP_EVPN_NODE
, &vtysh_quit_bgpd_cmd
);
3826 install_element(BGP_EVPN_NODE
, &vtysh_exit_bgpd_cmd
);
3827 install_element(BGP_EVPN_VNI_NODE
, &vtysh_exit_bgpd_cmd
);
3828 install_element(BGP_EVPN_VNI_NODE
, &vtysh_quit_bgpd_cmd
);
3829 install_element(BGP_IPV6L_NODE
, &vtysh_exit_bgpd_cmd
);
3830 install_element(BGP_IPV6L_NODE
, &vtysh_quit_bgpd_cmd
);
3831 #if defined(ENABLE_BGP_VNC)
3832 install_element(BGP_VRF_POLICY_NODE
, &vtysh_exit_bgpd_cmd
);
3833 install_element(BGP_VRF_POLICY_NODE
, &vtysh_quit_bgpd_cmd
);
3834 install_element(BGP_VNC_DEFAULTS_NODE
, &vtysh_exit_bgpd_cmd
);
3835 install_element(BGP_VNC_DEFAULTS_NODE
, &vtysh_quit_bgpd_cmd
);
3836 install_element(BGP_VNC_NVE_GROUP_NODE
, &vtysh_exit_bgpd_cmd
);
3837 install_element(BGP_VNC_NVE_GROUP_NODE
, &vtysh_quit_bgpd_cmd
);
3838 install_element(BGP_VNC_L2_GROUP_NODE
, &vtysh_exit_bgpd_cmd
);
3839 install_element(BGP_VNC_L2_GROUP_NODE
, &vtysh_quit_bgpd_cmd
);
3841 install_element(ISIS_NODE
, &vtysh_exit_isisd_cmd
);
3842 install_element(ISIS_NODE
, &vtysh_quit_isisd_cmd
);
3843 install_element(OPENFABRIC_NODE
, &vtysh_exit_fabricd_cmd
);
3844 install_element(OPENFABRIC_NODE
, &vtysh_quit_fabricd_cmd
);
3845 install_element(KEYCHAIN_NODE
, &vtysh_exit_ripd_cmd
);
3846 install_element(KEYCHAIN_NODE
, &vtysh_quit_ripd_cmd
);
3847 install_element(KEYCHAIN_KEY_NODE
, &vtysh_exit_ripd_cmd
);
3848 install_element(KEYCHAIN_KEY_NODE
, &vtysh_quit_ripd_cmd
);
3849 install_element(RMAP_NODE
, &vtysh_exit_rmap_cmd
);
3850 install_element(RMAP_NODE
, &vtysh_quit_rmap_cmd
);
3851 install_element(PBRMAP_NODE
, &vtysh_exit_pbr_map_cmd
);
3852 install_element(PBRMAP_NODE
, &vtysh_quit_pbr_map_cmd
);
3855 install_element(CONFIG_NODE
, &bfd_enter_cmd
);
3856 install_element(BFD_NODE
, &bfd_peer_enter_cmd
);
3858 /* Exit/quit node. */
3859 install_element(BFD_NODE
, &vtysh_exit_bfdd_cmd
);
3860 install_element(BFD_NODE
, &vtysh_quit_bfdd_cmd
);
3861 install_element(BFD_PEER_NODE
, &vtysh_exit_bfdd_cmd
);
3862 install_element(BFD_PEER_NODE
, &vtysh_quit_bfdd_cmd
);
3865 install_element(BFD_NODE
, &vtysh_end_all_cmd
);
3866 install_element(BFD_PEER_NODE
, &vtysh_end_all_cmd
);
3867 #endif /* HAVE_BFDD */
3868 install_element(VTY_NODE
, &vtysh_exit_line_vty_cmd
);
3869 install_element(VTY_NODE
, &vtysh_quit_line_vty_cmd
);
3871 /* "end" command. */
3872 install_element(CONFIG_NODE
, &vtysh_end_all_cmd
);
3873 install_element(ENABLE_NODE
, &vtysh_end_all_cmd
);
3874 install_element(RIP_NODE
, &vtysh_end_all_cmd
);
3875 install_element(RIPNG_NODE
, &vtysh_end_all_cmd
);
3876 install_element(OSPF_NODE
, &vtysh_end_all_cmd
);
3877 install_element(EIGRP_NODE
, &vtysh_end_all_cmd
);
3878 install_element(BABEL_NODE
, &vtysh_end_all_cmd
);
3879 install_element(OSPF6_NODE
, &vtysh_end_all_cmd
);
3880 install_element(LDP_NODE
, &vtysh_end_all_cmd
);
3881 install_element(LDP_IPV4_NODE
, &vtysh_end_all_cmd
);
3882 install_element(LDP_IPV6_NODE
, &vtysh_end_all_cmd
);
3883 install_element(LDP_IPV4_IFACE_NODE
, &vtysh_end_all_cmd
);
3884 install_element(LDP_IPV6_IFACE_NODE
, &vtysh_end_all_cmd
);
3885 install_element(LDP_L2VPN_NODE
, &vtysh_end_all_cmd
);
3886 install_element(LDP_PSEUDOWIRE_NODE
, &vtysh_end_all_cmd
);
3887 install_element(BGP_NODE
, &vtysh_end_all_cmd
);
3888 install_element(BGP_IPV4_NODE
, &vtysh_end_all_cmd
);
3889 install_element(BGP_IPV4M_NODE
, &vtysh_end_all_cmd
);
3890 install_element(BGP_IPV4L_NODE
, &vtysh_end_all_cmd
);
3891 install_element(BGP_VPNV4_NODE
, &vtysh_end_all_cmd
);
3892 install_element(BGP_VPNV6_NODE
, &vtysh_end_all_cmd
);
3893 install_element(BGP_FLOWSPECV4_NODE
, &vtysh_end_all_cmd
);
3894 install_element(BGP_FLOWSPECV6_NODE
, &vtysh_end_all_cmd
);
3895 install_element(BGP_IPV6_NODE
, &vtysh_end_all_cmd
);
3896 install_element(BGP_IPV6M_NODE
, &vtysh_end_all_cmd
);
3897 install_element(BGP_IPV6L_NODE
, &vtysh_end_all_cmd
);
3898 install_element(BGP_VRF_POLICY_NODE
, &vtysh_end_all_cmd
);
3899 install_element(BGP_EVPN_NODE
, &vtysh_end_all_cmd
);
3900 install_element(BGP_EVPN_VNI_NODE
, &vtysh_end_all_cmd
);
3901 install_element(BGP_VNC_DEFAULTS_NODE
, &vtysh_end_all_cmd
);
3902 install_element(BGP_VNC_NVE_GROUP_NODE
, &vtysh_end_all_cmd
);
3903 install_element(BGP_VNC_L2_GROUP_NODE
, &vtysh_end_all_cmd
);
3904 install_element(ISIS_NODE
, &vtysh_end_all_cmd
);
3905 install_element(OPENFABRIC_NODE
, &vtysh_end_all_cmd
);
3906 install_element(KEYCHAIN_NODE
, &vtysh_end_all_cmd
);
3907 install_element(KEYCHAIN_KEY_NODE
, &vtysh_end_all_cmd
);
3908 install_element(RMAP_NODE
, &vtysh_end_all_cmd
);
3909 install_element(PBRMAP_NODE
, &vtysh_end_all_cmd
);
3910 install_element(VTY_NODE
, &vtysh_end_all_cmd
);
3912 install_element(INTERFACE_NODE
, &vtysh_end_all_cmd
);
3913 install_element(INTERFACE_NODE
, &vtysh_exit_interface_cmd
);
3914 install_element(LINK_PARAMS_NODE
, &exit_link_params_cmd
);
3915 install_element(LINK_PARAMS_NODE
, &vtysh_end_all_cmd
);
3916 install_element(LINK_PARAMS_NODE
, &vtysh_exit_interface_cmd
);
3917 install_element(INTERFACE_NODE
, &vtysh_quit_interface_cmd
);
3919 install_element(PW_NODE
, &vtysh_end_all_cmd
);
3920 install_element(PW_NODE
, &vtysh_exit_interface_cmd
);
3921 install_element(PW_NODE
, &vtysh_quit_interface_cmd
);
3923 install_element(CONFIG_NODE
, &vtysh_nexthop_group_cmd
);
3924 install_element(NH_GROUP_NODE
, &vtysh_end_all_cmd
);
3925 install_element(NH_GROUP_NODE
, &vtysh_exit_nexthop_group_cmd
);
3926 install_element(NH_GROUP_NODE
, &vtysh_quit_nexthop_group_cmd
);
3928 install_element(VRF_NODE
, &vtysh_end_all_cmd
);
3929 install_element(VRF_NODE
, &vtysh_exit_vrf_cmd
);
3930 install_element(VRF_NODE
, &vtysh_quit_vrf_cmd
);
3932 install_element(CONFIG_NODE
, &router_eigrp_cmd
);
3933 install_element(CONFIG_NODE
, &router_babel_cmd
);
3934 install_element(CONFIG_NODE
, &router_rip_cmd
);
3935 install_element(CONFIG_NODE
, &router_ripng_cmd
);
3936 install_element(CONFIG_NODE
, &router_ospf_cmd
);
3937 install_element(CONFIG_NODE
, &router_ospf6_cmd
);
3938 #if defined(HAVE_LDPD)
3939 install_element(CONFIG_NODE
, &ldp_mpls_ldp_cmd
);
3940 install_element(LDP_NODE
, &ldp_address_family_ipv4_cmd
);
3941 install_element(LDP_NODE
, &ldp_address_family_ipv6_cmd
);
3942 install_element(LDP_IPV4_NODE
, &ldp_interface_ifname_cmd
);
3943 install_element(LDP_IPV6_NODE
, &ldp_interface_ifname_cmd
);
3944 install_element(CONFIG_NODE
, &ldp_l2vpn_word_type_vpls_cmd
);
3945 install_element(LDP_L2VPN_NODE
, &ldp_member_pseudowire_ifname_cmd
);
3947 install_element(CONFIG_NODE
, &router_isis_cmd
);
3948 install_element(CONFIG_NODE
, &router_openfabric_cmd
);
3949 install_element(CONFIG_NODE
, &router_bgp_cmd
);
3950 #ifdef KEEP_OLD_VPN_COMMANDS
3951 install_element(BGP_NODE
, &address_family_vpnv4_cmd
);
3952 install_element(BGP_NODE
, &address_family_vpnv6_cmd
);
3953 #endif /* KEEP_OLD_VPN_COMMANDS */
3954 #if defined(ENABLE_BGP_VNC)
3955 install_element(BGP_NODE
, &vnc_vrf_policy_cmd
);
3956 install_element(BGP_NODE
, &vnc_defaults_cmd
);
3957 install_element(BGP_NODE
, &vnc_nve_group_cmd
);
3958 install_element(BGP_NODE
, &vnc_l2_group_cmd
);
3960 install_element(BGP_NODE
, &address_family_ipv4_cmd
);
3961 install_element(BGP_NODE
, &address_family_ipv4_multicast_cmd
);
3962 install_element(BGP_NODE
, &address_family_ipv4_vpn_cmd
);
3963 install_element(BGP_NODE
, &address_family_ipv4_labeled_unicast_cmd
);
3964 install_element(BGP_NODE
, &address_family_ipv6_cmd
);
3965 install_element(BGP_NODE
, &address_family_ipv6_multicast_cmd
);
3966 install_element(BGP_NODE
, &address_family_ipv6_vpn_cmd
);
3967 install_element(BGP_NODE
, &address_family_ipv6_labeled_unicast_cmd
);
3968 install_element(BGP_NODE
, &address_family_evpn_cmd
);
3969 install_element(BGP_NODE
, &address_family_flowspecv4_cmd
);
3970 install_element(BGP_NODE
, &address_family_flowspecv6_cmd
);
3971 #if defined(HAVE_CUMULUS)
3972 install_element(BGP_NODE
, &address_family_evpn2_cmd
);
3974 install_element(BGP_VPNV4_NODE
, &exit_address_family_cmd
);
3975 install_element(BGP_VPNV6_NODE
, &exit_address_family_cmd
);
3976 install_element(BGP_IPV4_NODE
, &exit_address_family_cmd
);
3977 install_element(BGP_IPV4M_NODE
, &exit_address_family_cmd
);
3978 install_element(BGP_IPV4L_NODE
, &exit_address_family_cmd
);
3979 install_element(BGP_IPV6_NODE
, &exit_address_family_cmd
);
3980 install_element(BGP_IPV6M_NODE
, &exit_address_family_cmd
);
3981 install_element(BGP_EVPN_NODE
, &exit_address_family_cmd
);
3982 install_element(BGP_IPV6L_NODE
, &exit_address_family_cmd
);
3983 install_element(BGP_FLOWSPECV4_NODE
, &exit_address_family_cmd
);
3984 install_element(BGP_FLOWSPECV6_NODE
, &exit_address_family_cmd
);
3986 install_element(BGP_NODE
, &bmp_targets_cmd
);
3987 install_element(BMP_NODE
, &bmp_exit_cmd
);
3988 install_element(BMP_NODE
, &bmp_quit_cmd
);
3989 install_element(BMP_NODE
, &vtysh_end_all_cmd
);
3991 install_element(CONFIG_NODE
, &rpki_cmd
);
3992 install_element(RPKI_NODE
, &rpki_exit_cmd
);
3993 install_element(RPKI_NODE
, &rpki_quit_cmd
);
3994 install_element(RPKI_NODE
, &vtysh_end_all_cmd
);
3997 install_element(BGP_EVPN_NODE
, &bgp_evpn_vni_cmd
);
3998 install_element(BGP_EVPN_VNI_NODE
, &exit_vni_cmd
);
4000 install_element(BGP_VRF_POLICY_NODE
, &exit_vrf_policy_cmd
);
4001 install_element(BGP_VNC_DEFAULTS_NODE
, &exit_vnc_config_cmd
);
4002 install_element(BGP_VNC_NVE_GROUP_NODE
, &exit_vnc_config_cmd
);
4003 install_element(BGP_VNC_L2_GROUP_NODE
, &exit_vnc_config_cmd
);
4005 install_element(CONFIG_NODE
, &key_chain_cmd
);
4006 install_element(CONFIG_NODE
, &vtysh_route_map_cmd
);
4007 install_element(CONFIG_NODE
, &vtysh_pbr_map_cmd
);
4008 install_element(CONFIG_NODE
, &vtysh_no_pbr_map_cmd
);
4009 install_element(CONFIG_NODE
, &vtysh_line_vty_cmd
);
4010 install_element(KEYCHAIN_NODE
, &key_cmd
);
4011 install_element(KEYCHAIN_NODE
, &key_chain_cmd
);
4012 install_element(KEYCHAIN_KEY_NODE
, &key_chain_cmd
);
4013 install_element(CONFIG_NODE
, &vtysh_interface_cmd
);
4014 install_element(CONFIG_NODE
, &vtysh_pseudowire_cmd
);
4015 install_element(INTERFACE_NODE
, &vtysh_link_params_cmd
);
4016 install_element(ENABLE_NODE
, &vtysh_show_running_config_cmd
);
4017 install_element(ENABLE_NODE
, &vtysh_copy_running_config_cmd
);
4019 install_element(CONFIG_NODE
, &vtysh_vrf_cmd
);
4020 install_element(VRF_NODE
, &vtysh_vrf_netns_cmd
);
4021 install_element(VRF_NODE
, &vtysh_no_vrf_netns_cmd
);
4022 install_element(VRF_NODE
, &exit_vrf_config_cmd
);
4024 install_element(CONFIG_NODE
, &vtysh_no_nexthop_group_cmd
);
4026 /* "write terminal" command. */
4027 install_element(ENABLE_NODE
, &vtysh_write_terminal_cmd
);
4029 install_element(CONFIG_NODE
, &vtysh_integrated_config_cmd
);
4030 install_element(CONFIG_NODE
, &no_vtysh_integrated_config_cmd
);
4032 /* "write memory" command. */
4033 install_element(ENABLE_NODE
, &vtysh_write_memory_cmd
);
4035 install_element(CONFIG_NODE
, &vtysh_terminal_paginate_cmd
);
4036 install_element(VIEW_NODE
, &vtysh_terminal_paginate_cmd
);
4037 install_element(VIEW_NODE
, &vtysh_terminal_length_cmd
);
4038 install_element(VIEW_NODE
, &vtysh_terminal_no_length_cmd
);
4039 install_element(VIEW_NODE
, &vtysh_show_daemons_cmd
);
4041 install_element(VIEW_NODE
, &vtysh_ping_cmd
);
4042 install_element(VIEW_NODE
, &vtysh_ping_ip_cmd
);
4043 install_element(VIEW_NODE
, &vtysh_traceroute_cmd
);
4044 install_element(VIEW_NODE
, &vtysh_traceroute_ip_cmd
);
4045 install_element(VIEW_NODE
, &vtysh_mtrace_cmd
);
4046 install_element(VIEW_NODE
, &vtysh_ping6_cmd
);
4047 install_element(VIEW_NODE
, &vtysh_traceroute6_cmd
);
4048 #if defined(HAVE_SHELL_ACCESS)
4049 install_element(VIEW_NODE
, &vtysh_telnet_cmd
);
4050 install_element(VIEW_NODE
, &vtysh_telnet_port_cmd
);
4051 install_element(VIEW_NODE
, &vtysh_ssh_cmd
);
4053 #if defined(HAVE_SHELL_ACCESS)
4054 install_element(ENABLE_NODE
, &vtysh_start_shell_cmd
);
4055 install_element(ENABLE_NODE
, &vtysh_start_bash_cmd
);
4056 install_element(ENABLE_NODE
, &vtysh_start_zsh_cmd
);
4060 install_element(VIEW_NODE
, &vtysh_show_debugging_cmd
);
4061 install_element(VIEW_NODE
, &vtysh_show_error_code_cmd
);
4062 install_element(VIEW_NODE
, &vtysh_show_debugging_hashtable_cmd
);
4063 install_element(ENABLE_NODE
, &vtysh_debug_all_cmd
);
4064 install_element(CONFIG_NODE
, &vtysh_debug_all_cmd
);
4065 install_element(ENABLE_NODE
, &vtysh_debug_memstats_cmd
);
4066 install_element(CONFIG_NODE
, &vtysh_debug_memstats_cmd
);
4069 install_element(VIEW_NODE
, &show_yang_operational_data_cmd
);
4070 install_element(ENABLE_NODE
, &debug_nb_cmd
);
4071 install_element(CONFIG_NODE
, &debug_nb_cmd
);
4073 /* misc lib show commands */
4074 install_element(VIEW_NODE
, &vtysh_show_memory_cmd
);
4075 install_element(VIEW_NODE
, &vtysh_show_modules_cmd
);
4076 install_element(VIEW_NODE
, &vtysh_show_work_queues_cmd
);
4077 install_element(VIEW_NODE
, &vtysh_show_work_queues_daemon_cmd
);
4078 install_element(VIEW_NODE
, &vtysh_show_thread_cmd
);
4079 install_element(VIEW_NODE
, &vtysh_show_poll_cmd
);
4082 install_element(VIEW_NODE
, &vtysh_show_logging_cmd
);
4083 install_element(VIEW_NODE
, &vtysh_show_log_filter_cmd
);
4084 install_element(CONFIG_NODE
, &vtysh_log_filter_cmd
);
4085 install_element(CONFIG_NODE
, &vtysh_log_filter_clear_cmd
);
4086 install_element(CONFIG_NODE
, &vtysh_log_stdout_cmd
);
4087 install_element(CONFIG_NODE
, &vtysh_log_stdout_level_cmd
);
4088 install_element(CONFIG_NODE
, &no_vtysh_log_stdout_cmd
);
4089 install_element(CONFIG_NODE
, &vtysh_log_file_cmd
);
4090 install_element(CONFIG_NODE
, &vtysh_log_file_level_cmd
);
4091 install_element(CONFIG_NODE
, &no_vtysh_log_file_cmd
);
4092 install_element(CONFIG_NODE
, &vtysh_log_monitor_cmd
);
4093 install_element(CONFIG_NODE
, &no_vtysh_log_monitor_cmd
);
4094 install_element(CONFIG_NODE
, &vtysh_log_syslog_cmd
);
4095 install_element(CONFIG_NODE
, &no_vtysh_log_syslog_cmd
);
4096 install_element(CONFIG_NODE
, &vtysh_log_facility_cmd
);
4097 install_element(CONFIG_NODE
, &no_vtysh_log_facility_cmd
);
4098 install_element(CONFIG_NODE
, &vtysh_log_record_priority_cmd
);
4099 install_element(CONFIG_NODE
, &no_vtysh_log_record_priority_cmd
);
4100 install_element(CONFIG_NODE
, &vtysh_log_timestamp_precision_cmd
);
4101 install_element(CONFIG_NODE
, &no_vtysh_log_timestamp_precision_cmd
);
4103 install_element(CONFIG_NODE
, &vtysh_service_password_encrypt_cmd
);
4104 install_element(CONFIG_NODE
, &no_vtysh_service_password_encrypt_cmd
);
4106 install_element(CONFIG_NODE
, &vtysh_password_cmd
);
4107 install_element(CONFIG_NODE
, &no_vtysh_password_cmd
);
4108 install_element(CONFIG_NODE
, &vtysh_enable_password_cmd
);
4109 install_element(CONFIG_NODE
, &no_vtysh_enable_password_cmd
);