1 /* Virtual terminal interface shell.
2 * Copyright (C) 2000 Kunihiro Ishiguro
4 * This file is part of GNU Zebra.
6 * GNU Zebra is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2, or (at your option) any
11 * GNU Zebra is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; see the file COPYING; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26 #include <sys/resource.h>
29 #include <readline/readline.h>
30 #include <readline/history.h>
40 #include "vtysh/vtysh.h"
42 #include "bgpd/bgp_vty.h"
46 #include "command_graph.h"
50 DEFINE_MTYPE_STATIC(MVTYSH
, VTYSH_CMD
, "Vtysh cmd copy")
55 /* VTY shell pager name. */
56 char *vtysh_pager_name
= NULL
;
58 /* VTY shell client structure */
63 char path
[MAXPATHLEN
];
64 struct vtysh_client
*next
;
67 /* Some utility functions for working on vtysh-specific vty tasks */
69 static FILE *vty_open_pager(struct vty
*vty
)
74 if (!vtysh_pager_name
)
77 vty
->of_saved
= vty
->of
;
78 vty
->of
= popen(vtysh_pager_name
, "w");
79 if (vty
->of
== NULL
) {
80 vty
->of
= vty
->of_saved
;
90 static int vty_close_pager(struct vty
*vty
)
96 if (pclose(vty
->of
) == -1) {
101 vty
->of
= vty
->of_saved
;
102 vty
->is_paged
= false;
107 static void vtysh_pager_envdef(bool fallback
)
111 pager_defined
= getenv("VTYSH_PAGER");
114 vtysh_pager_name
= strdup(pager_defined
);
116 vtysh_pager_name
= strdup(VTYSH_PAGER
);
121 struct vtysh_client vtysh_client
[] = {
122 {.fd
= -1, .name
= "zebra", .flag
= VTYSH_ZEBRA
, .next
= NULL
},
123 {.fd
= -1, .name
= "ripd", .flag
= VTYSH_RIPD
, .next
= NULL
},
124 {.fd
= -1, .name
= "ripngd", .flag
= VTYSH_RIPNGD
, .next
= NULL
},
125 {.fd
= -1, .name
= "ospfd", .flag
= VTYSH_OSPFD
, .next
= NULL
},
126 {.fd
= -1, .name
= "ospf6d", .flag
= VTYSH_OSPF6D
, .next
= NULL
},
127 {.fd
= -1, .name
= "ldpd", .flag
= VTYSH_LDPD
, .next
= NULL
},
128 {.fd
= -1, .name
= "bgpd", .flag
= VTYSH_BGPD
, .next
= NULL
},
129 {.fd
= -1, .name
= "isisd", .flag
= VTYSH_ISISD
, .next
= NULL
},
130 {.fd
= -1, .name
= "pimd", .flag
= VTYSH_PIMD
, .next
= NULL
},
131 {.fd
= -1, .name
= "nhrpd", .flag
= VTYSH_NHRPD
, .next
= NULL
},
132 {.fd
= -1, .name
= "eigrpd", .flag
= VTYSH_EIGRPD
, .next
= NULL
},
133 {.fd
= -1, .name
= "babeld", .flag
= VTYSH_BABELD
, .next
= NULL
},
134 {.fd
= -1, .name
= "sharpd", .flag
= VTYSH_SHARPD
, .next
= NULL
},
135 {.fd
= -1, .name
= "fabricd", .flag
= VTYSH_FABRICD
, .next
= NULL
},
136 {.fd
= -1, .name
= "watchfrr", .flag
= VTYSH_WATCHFRR
, .next
= NULL
},
137 {.fd
= -1, .name
= "pbrd", .flag
= VTYSH_PBRD
, .next
= NULL
},
138 {.fd
= -1, .name
= "staticd", .flag
= VTYSH_STATICD
, .next
= NULL
},
139 {.fd
= -1, .name
= "bfdd", .flag
= VTYSH_BFDD
, .next
= NULL
},
140 {.fd
= -1, .name
= "vrrpd", .flag
= VTYSH_VRRPD
, .next
= NULL
},
143 enum vtysh_write_integrated vtysh_write_integrated
=
144 WRITE_INTEGRATED_UNSPECIFIED
;
146 static int vtysh_reconnect(struct vtysh_client
*vclient
);
148 static void vclient_close(struct vtysh_client
*vclient
)
150 if (vclient
->fd
>= 0) {
152 "Warning: closing connection to %s because of an I/O error!\n",
155 /* indicate as candidate for reconnect */
156 vclient
->fd
= VTYSH_WAS_ACTIVE
;
161 * Send a CLI command to a client and read the response.
163 * Output will be printed to vty->of. If you want to suppress output, set that
167 * the client to send the command to
170 * the command to send
173 * if non-null, this will be called with each line of output received from
174 * the client passed in the second parameter
177 * optional first argument to pass to callback
182 static int vtysh_client_run(struct vtysh_client
*vclient
, const char *line
,
183 void (*callback
)(void *, const char *), void *cbarg
)
187 char *buf
= stackbuf
;
188 size_t bufsz
= sizeof(stackbuf
);
189 char *bufvalid
, *end
= NULL
;
190 char terminator
[3] = {0, 0, 0};
192 /* vclinet was previously active, try to reconnect */
193 if (vclient
->fd
== VTYSH_WAS_ACTIVE
) {
194 ret
= vtysh_reconnect(vclient
);
202 ret
= write(vclient
->fd
, line
, strlen(line
) + 1);
204 /* close connection and try to reconnect */
205 vclient_close(vclient
);
206 ret
= vtysh_reconnect(vclient
);
210 ret
= write(vclient
->fd
, line
, strlen(line
) + 1);
218 read(vclient
->fd
, bufvalid
, buf
+ bufsz
- bufvalid
- 1);
220 if (nread
< 0 && (errno
== EINTR
|| errno
== EAGAIN
))
224 vty_out(vty
, "vtysh: error reading from %s: %s (%d)",
225 vclient
->name
, safe_strerror(errno
), errno
);
231 /* Null terminate so we may pass this to *printf later. */
235 * We expect string output from daemons, so instead of looking
236 * for the full 3 null bytes of the terminator, we check for
237 * just one instead and assume it is the first byte of the
238 * terminator. The presence of the full terminator is checked
241 if (bufvalid
- buf
>= 4)
242 end
= memmem(bufvalid
- 4, 4, "\0", 1);
245 * calculate # bytes we have, up to & not including the
246 * terminator if present
248 size_t textlen
= (end
? end
: bufvalid
) - buf
;
251 /* feed line processing callback if present */
252 while (callback
&& bufvalid
> buf
&& (end
> buf
|| !end
)) {
253 textlen
= (end
? end
: bufvalid
) - buf
;
254 char *eol
= memchr(buf
, '\n', textlen
);
260 * no line break, end of input, no text left
261 * before end; nothing to write
265 /* no nl, end of input, but some text left */
267 else if (bufvalid
== buf
+ bufsz
- 1) {
269 * no nl, no end of input, no buffer space;
275 if (buf
== stackbuf
) {
276 new = XMALLOC(MTYPE_TMP
, bufsz
);
277 memcpy(new, stackbuf
, sizeof(stackbuf
));
279 new = XREALLOC(MTYPE_TMP
, buf
, bufsz
);
281 bufvalid
= bufvalid
- buf
+ new;
283 /* if end != NULL, we won't be reading more
293 /* eol is at line end now, either \n => \0 or \0\0\0 */
294 assert(eol
&& eol
<= bufvalid
);
297 vty_out(vty
, "%s\n", buf
);
299 callback(cbarg
, buf
);
301 /* shift back data and adjust bufvalid */
302 memmove(buf
, eol
, bufvalid
- eol
);
303 bufvalid
-= eol
- buf
;
308 /* else if no callback, dump raw */
311 vty_out(vty
, "%s", buf
);
312 memmove(buf
, buf
+ textlen
, bufvalid
- buf
- textlen
);
318 * ----------------------------------------------------
319 * At this point `buf` should be in one of two states:
320 * - Empty (i.e. buf == bufvalid)
321 * - Contains up to 4 bytes of the terminator
322 * ----------------------------------------------------
324 assert(((buf
== bufvalid
)
325 || (bufvalid
- buf
<= 4 && buf
[0] == 0x00)));
328 /* if we have the terminator, break */
329 if (end
&& bufvalid
- buf
== 4) {
330 assert(!memcmp(buf
, terminator
, 3));
339 vclient_close(vclient
);
343 XFREE(MTYPE_TMP
, buf
);
347 static int vtysh_client_run_all(struct vtysh_client
*head_client
,
348 const char *line
, int continue_on_err
,
349 void (*callback
)(void *, const char *),
352 struct vtysh_client
*client
;
353 int rc
, rc_all
= CMD_SUCCESS
;
354 int correct_instance
= 0, wrong_instance
= 0;
356 for (client
= head_client
; client
; client
= client
->next
) {
357 rc
= vtysh_client_run(client
, line
, callback
, cbarg
);
358 if (rc
== CMD_NOT_MY_INSTANCE
) {
364 if (rc
!= CMD_SUCCESS
) {
365 if (!continue_on_err
)
370 if (wrong_instance
&& !correct_instance
) {
372 "%% [%s]: command ignored as it targets an instance that is not running\n",
374 rc_all
= CMD_WARNING_CONFIG_FAILED
;
380 * Execute command against all daemons.
383 * where to start walking in the daemon list
386 * the specific command to execute
391 static int vtysh_client_execute(struct vtysh_client
*head_client
,
394 return vtysh_client_run_all(head_client
, line
, 0, NULL
, NULL
);
398 * Retrieve all running config from daemons and parse it with the vtysh config
399 * parser. Returned output is not displayed to the user.
402 * where to start walking in the daemon list
405 * the specific command to execute
407 static void vtysh_client_config(struct vtysh_client
*head_client
, char *line
)
409 /* watchfrr currently doesn't load any config, and has some hardcoded
410 * settings that show up in "show run". skip it here (for now at
411 * least) so we don't get that mangled up in config-write.
413 if (head_client
->flag
== VTYSH_WATCHFRR
)
416 /* suppress output to user */
417 vty
->of_saved
= vty
->of
;
419 vtysh_client_run_all(head_client
, line
, 1, vtysh_config_parse_line
,
421 vty
->of
= vty
->of_saved
;
424 /* Command execution over the vty interface. */
425 static int vtysh_execute_func(const char *line
, int pager
)
430 const struct cmd_element
*cmd
;
432 int saved_ret
, saved_node
;
434 /* Split readline string up into the vector. */
435 vline
= cmd_make_strvec(line
);
441 if (strncmp("en", vector_slot(vline
, 0), 2) == 0) {
442 cmd_free_strvec(vline
);
443 vty_out(vty
, "%% Command not allowed: enable\n");
448 saved_ret
= ret
= cmd_execute(vty
, line
, &cmd
, 1);
449 saved_node
= vty
->node
;
452 * If command doesn't succeeded in current node, try to walk up in node
453 * tree. Changing vty->node is enough to try it just out without actual
454 * walkup in the vtysh.
456 while (ret
!= CMD_SUCCESS
&& ret
!= CMD_SUCCESS_DAEMON
457 && ret
!= CMD_WARNING
&& ret
!= CMD_WARNING_CONFIG_FAILED
458 && vty
->node
> CONFIG_NODE
) {
459 vty
->node
= node_parent(vty
->node
);
460 ret
= cmd_execute(vty
, line
, &cmd
, 1);
464 vty
->node
= saved_node
;
467 * If command succeeded in any other node than current (tried > 0) we
468 * have to move into node in the vtysh where it succeeded.
470 if (ret
== CMD_SUCCESS
|| ret
== CMD_SUCCESS_DAEMON
471 || ret
== CMD_WARNING
) {
472 if ((saved_node
== BGP_VPNV4_NODE
473 || saved_node
== BGP_VPNV6_NODE
474 || saved_node
== BGP_IPV4_NODE
475 || saved_node
== BGP_IPV6_NODE
476 || saved_node
== BGP_FLOWSPECV4_NODE
477 || saved_node
== BGP_FLOWSPECV6_NODE
478 || saved_node
== BGP_IPV4M_NODE
479 || saved_node
== BGP_IPV4L_NODE
480 || saved_node
== BGP_IPV6L_NODE
481 || saved_node
== BGP_IPV6M_NODE
482 || saved_node
== BGP_EVPN_NODE
483 || saved_node
== LDP_IPV4_NODE
484 || saved_node
== LDP_IPV6_NODE
)
486 vtysh_execute("exit-address-family");
487 } else if ((saved_node
== BGP_EVPN_VNI_NODE
) && (tried
== 1)) {
488 vtysh_execute("exit-vni");
489 } else if (saved_node
== BGP_VRF_POLICY_NODE
&& (tried
== 1)) {
490 vtysh_execute("exit-vrf-policy");
491 } else if ((saved_node
== BGP_VNC_DEFAULTS_NODE
492 || saved_node
== BGP_VNC_NVE_GROUP_NODE
493 || saved_node
== BGP_VNC_L2_GROUP_NODE
)
495 vtysh_execute("exit-vnc");
496 } else if (saved_node
== VRF_NODE
&& (tried
== 1)) {
497 vtysh_execute("exit-vrf");
498 } else if ((saved_node
== KEYCHAIN_KEY_NODE
499 || saved_node
== LDP_PSEUDOWIRE_NODE
500 || saved_node
== LDP_IPV4_IFACE_NODE
501 || saved_node
== LDP_IPV6_IFACE_NODE
)
503 vtysh_execute("exit");
505 vtysh_execute("end");
506 vtysh_execute("configure");
510 * If command didn't succeed in any node, continue with return value
517 cmd_free_strvec(vline
);
522 case CMD_WARNING_CONFIG_FAILED
:
523 if (vty
->type
== VTY_FILE
)
524 vty_out(vty
, "Warning...\n");
526 case CMD_ERR_AMBIGUOUS
:
527 vty_out(vty
, "%% Ambiguous command: %s\n", line
);
529 case CMD_ERR_NO_MATCH
:
530 vty_out(vty
, "%% Unknown command: %s\n", line
);
532 case CMD_ERR_INCOMPLETE
:
533 vty_out(vty
, "%% Command incomplete: %s\n", line
);
535 case CMD_SUCCESS_DAEMON
: {
537 * FIXME: Don't open pager for exit commands. popen() causes
538 * problems if exited from vtysh at all. This hack shouldn't
539 * cause any problem but is really ugly.
541 if (pager
&& strncmp(line
, "exit", 4))
544 if (!strcmp(cmd
->string
, "configure")) {
545 for (i
= 0; i
< array_size(vtysh_client
); i
++) {
546 cmd_stat
= vtysh_client_execute(
547 &vtysh_client
[i
], line
);
548 if (cmd_stat
== CMD_WARNING
)
554 vline
= cmd_make_strvec(line
);
559 vty_close_pager(vty
);
563 ret
= cmd_execute_command(vline
, vty
, &cmd
, 1);
564 cmd_free_strvec(vline
);
565 if (ret
!= CMD_SUCCESS_DAEMON
)
567 } else if (cmd
->func
) {
568 (*cmd
->func
)(cmd
, vty
, 0, NULL
);
573 cmd_stat
= CMD_SUCCESS
;
574 struct vtysh_client
*vc
;
575 for (i
= 0; i
< array_size(vtysh_client
); i
++) {
576 if (cmd
->daemon
& vtysh_client
[i
].flag
) {
577 if (vtysh_client
[i
].fd
< 0
578 && (cmd
->daemon
== vtysh_client
[i
].flag
)) {
579 for (vc
= &vtysh_client
[i
]; vc
;
581 if (vc
->fd
== VTYSH_WAS_ACTIVE
)
584 if (vtysh_client
[i
].fd
< 0
585 && (cmd
->daemon
== vtysh_client
[i
].flag
)) {
586 bool any_inst
= false;
587 for (vc
= &vtysh_client
[i
]; vc
;
593 "%s is not running\n",
594 vtysh_client
[i
].name
);
598 cmd_stat
= vtysh_client_execute(
599 &vtysh_client
[i
], line
);
600 if (cmd_stat
!= CMD_SUCCESS
)
604 if (cmd_stat
!= CMD_SUCCESS
)
608 (*cmd
->func
)(cmd
, vty
, 0, NULL
);
612 vty_close_pager(vty
);
617 int vtysh_execute_no_pager(const char *line
)
619 return vtysh_execute_func(line
, 0);
622 int vtysh_execute(const char *line
)
624 return vtysh_execute_func(line
, 1);
627 static char *trim(char *s
)
638 while (end
>= s
&& isspace((int)*end
))
642 while (*s
&& isspace((int)*s
))
648 int vtysh_mark_file(const char *filename
)
655 const struct cmd_element
*cmd
;
656 int saved_ret
, prev_node
;
658 char *vty_buf_copy
= NULL
;
659 char *vty_buf_trimmed
= NULL
;
661 if (strncmp("-", filename
, 1) == 0)
664 confp
= fopen(filename
, "r");
667 fprintf(stderr
, "%% Can't open config file %s due to '%s'.\n",
668 filename
, safe_strerror(errno
));
669 return (CMD_ERR_NO_FILE
);
673 vty
->wfd
= STDERR_FILENO
;
674 vty
->type
= VTY_TERM
;
675 vty
->node
= CONFIG_NODE
;
677 vtysh_execute_no_pager("enable");
678 vtysh_execute_no_pager("configure");
679 vty_buf_copy
= XCALLOC(MTYPE_VTYSH_CMD
, VTY_BUFSIZ
);
681 while (fgets(vty
->buf
, VTY_BUFSIZ
, confp
)) {
684 strcpy(vty_buf_copy
, vty
->buf
);
685 vty_buf_trimmed
= trim(vty_buf_copy
);
688 case LDP_IPV4_IFACE_NODE
:
689 if (strncmp(vty_buf_copy
, " ", 3)) {
690 vty_out(vty
, " end\n");
691 vty
->node
= LDP_IPV4_NODE
;
694 case LDP_IPV6_IFACE_NODE
:
695 if (strncmp(vty_buf_copy
, " ", 3)) {
696 vty_out(vty
, " end\n");
697 vty
->node
= LDP_IPV6_NODE
;
700 case LDP_PSEUDOWIRE_NODE
:
701 if (strncmp(vty_buf_copy
, " ", 2)) {
702 vty_out(vty
, " end\n");
703 vty
->node
= LDP_L2VPN_NODE
;
710 if (vty_buf_trimmed
[0] == '!' || vty_buf_trimmed
[0] == '#') {
711 vty_out(vty
, "%s", vty
->buf
);
715 /* Split readline string up into the vector. */
716 vline
= cmd_make_strvec(vty
->buf
);
719 vty_out(vty
, "%s", vty
->buf
);
724 * Ignore the "end" lines, we will generate these where
727 if (strlen(vty_buf_trimmed
) == 3
728 && strncmp("end", vty_buf_trimmed
, 3) == 0) {
729 cmd_free_strvec(vline
);
733 prev_node
= vty
->node
;
734 saved_ret
= ret
= cmd_execute_command_strict(vline
, vty
, &cmd
);
737 * If command doesn't succeeded in current node, try to walk up
738 * in node tree. Changing vty->node is enough to try it just
739 * out without actual walkup in the vtysh.
741 while (ret
!= CMD_SUCCESS
&& ret
!= CMD_SUCCESS_DAEMON
742 && ret
!= CMD_WARNING
&& ret
!= CMD_WARNING_CONFIG_FAILED
743 && vty
->node
> CONFIG_NODE
) {
744 vty
->node
= node_parent(vty
->node
);
745 ret
= cmd_execute_command_strict(vline
, vty
, &cmd
);
750 * If command succeeded in any other node than current (tried >
751 * 0) we have to move into node in the vtysh where it
754 if (ret
== CMD_SUCCESS
|| ret
== CMD_SUCCESS_DAEMON
755 || ret
== CMD_WARNING
) {
756 if ((prev_node
== BGP_VPNV4_NODE
757 || prev_node
== BGP_VPNV6_NODE
758 || prev_node
== BGP_IPV4_NODE
759 || prev_node
== BGP_IPV6_NODE
760 || prev_node
== BGP_FLOWSPECV4_NODE
761 || prev_node
== BGP_FLOWSPECV6_NODE
762 || prev_node
== BGP_IPV4L_NODE
763 || prev_node
== BGP_IPV6L_NODE
764 || prev_node
== BGP_IPV4M_NODE
765 || prev_node
== BGP_IPV6M_NODE
766 || prev_node
== BGP_EVPN_NODE
)
768 vty_out(vty
, "exit-address-family\n");
769 } else if ((prev_node
== BGP_EVPN_VNI_NODE
)
771 vty_out(vty
, "exit-vni\n");
772 } else if ((prev_node
== KEYCHAIN_KEY_NODE
)
774 vty_out(vty
, "exit\n");
776 vty_out(vty
, "end\n");
780 * If command didn't succeed in any node, continue with return
781 * value from first try.
785 vty
->node
= prev_node
;
788 cmd_free_strvec(vline
);
791 case CMD_WARNING_CONFIG_FAILED
:
792 if (vty
->type
== VTY_FILE
)
793 fprintf(stderr
, "line %d: Warning...: %s\n",
797 XFREE(MTYPE_VTYSH_CMD
, vty_buf_copy
);
799 case CMD_ERR_AMBIGUOUS
:
800 fprintf(stderr
, "line %d: %% Ambiguous command: %s\n",
804 XFREE(MTYPE_VTYSH_CMD
, vty_buf_copy
);
805 return CMD_ERR_AMBIGUOUS
;
806 case CMD_ERR_NO_MATCH
:
807 fprintf(stderr
, "line %d: %% Unknown command: %s\n",
811 XFREE(MTYPE_VTYSH_CMD
, vty_buf_copy
);
812 return CMD_ERR_NO_MATCH
;
813 case CMD_ERR_INCOMPLETE
:
814 fprintf(stderr
, "line %d: %% Command incomplete: %s\n",
818 XFREE(MTYPE_VTYSH_CMD
, vty_buf_copy
);
819 return CMD_ERR_INCOMPLETE
;
821 vty_out(vty
, "%s", vty
->buf
);
823 case CMD_SUCCESS_DAEMON
: {
826 vty_out(vty
, "%s", vty
->buf
);
827 cmd_stat
= vtysh_client_execute(&vtysh_client
[0],
829 if (cmd_stat
!= CMD_SUCCESS
)
833 (*cmd
->func
)(cmd
, vty
, 0, NULL
);
837 /* This is the end */
838 vty_out(vty
, "\nend\n");
840 XFREE(MTYPE_VTYSH_CMD
, vty_buf_copy
);
848 /* Configration make from file. */
849 int vtysh_config_from_file(struct vty
*vty
, FILE *fp
)
852 const struct cmd_element
*cmd
;
854 /* once we have an error, we remember & return that */
855 int retcode
= CMD_SUCCESS
;
857 while (fgets(vty
->buf
, VTY_BUFSIZ
, fp
)) {
860 ret
= command_config_read_one_line(vty
, &cmd
, lineno
, 1);
864 case CMD_WARNING_CONFIG_FAILED
:
865 if (vty
->type
== VTY_FILE
)
866 fprintf(stderr
, "line %d: Warning[%d]...: %s\n",
867 lineno
, vty
->node
, vty
->buf
);
871 case CMD_ERR_AMBIGUOUS
:
873 "line %d: %% Ambiguous command[%d]: %s\n",
874 lineno
, vty
->node
, vty
->buf
);
875 retcode
= CMD_ERR_AMBIGUOUS
;
877 case CMD_ERR_NO_MATCH
:
878 fprintf(stderr
, "line %d: %% Unknown command[%d]: %s",
879 lineno
, vty
->node
, vty
->buf
);
880 retcode
= CMD_ERR_NO_MATCH
;
882 case CMD_ERR_INCOMPLETE
:
884 "line %d: %% Command incomplete[%d]: %s\n",
885 lineno
, vty
->node
, vty
->buf
);
886 retcode
= CMD_ERR_INCOMPLETE
;
888 case CMD_SUCCESS_DAEMON
: {
890 int cmd_stat
= CMD_SUCCESS
;
892 for (i
= 0; i
< array_size(vtysh_client
); i
++) {
893 if (cmd
->daemon
& vtysh_client
[i
].flag
) {
894 cmd_stat
= vtysh_client_execute(
895 &vtysh_client
[i
], vty
->buf
);
897 * CMD_WARNING - Can mean that the
898 * command was parsed successfully but
899 * it was already entered in a few
900 * spots. As such if we receive a
901 * CMD_WARNING from a daemon we
902 * shouldn't stop talking to the other
903 * daemons for the particular command.
905 if (cmd_stat
!= CMD_SUCCESS
906 && cmd_stat
!= CMD_WARNING
) {
908 "line %d: Failure to communicate[%d] to %s, line: %s\n",
910 vtysh_client
[i
].name
,
917 if (cmd_stat
!= CMD_SUCCESS
)
921 (*cmd
->func
)(cmd
, vty
, 0, NULL
);
930 * Function processes cli commands terminated with '?' character when entered
931 * through either 'vtysh' or 'vtysh -c' interfaces.
933 static int vtysh_process_questionmark(const char *input
, int input_len
)
937 vector vline
, describe
;
938 struct cmd_token
*token
;
943 vline
= cmd_make_strvec(input
);
945 /* In case of '> ?'. */
947 vline
= vector_init(1);
948 vector_set(vline
, NULL
);
949 } else if (input_len
&& isspace((int)input
[input_len
- 1]))
950 vector_set(vline
, NULL
);
952 describe
= cmd_describe_command(vline
, vty
, &ret
);
954 /* Ambiguous and no match error. */
956 case CMD_ERR_AMBIGUOUS
:
957 cmd_free_strvec(vline
);
958 vector_free(describe
);
959 vty_out(vty
, "%% Ambiguous command.\n");
963 case CMD_ERR_NO_MATCH
:
964 cmd_free_strvec(vline
);
966 vector_free(describe
);
967 vty_out(vty
, "%% There is no matched command.\n");
973 /* Get width of command string. */
975 for (i
= 0; i
< vector_active(describe
); i
++)
976 if ((token
= vector_slot(describe
, i
)) != NULL
) {
977 if (token
->text
[0] == '\0')
980 int len
= strlen(token
->text
);
986 for (i
= 0; i
< vector_active(describe
); i
++)
987 if ((token
= vector_slot(describe
, i
)) != NULL
) {
989 vty_out(vty
, " %-s\n", token
->text
);
991 vty_out(vty
, " %-*s %s\n", width
, token
->text
,
994 if (IS_VARYING_TOKEN(token
->type
)) {
995 const char *ref
= vector_slot(
996 vline
, vector_active(vline
) - 1);
998 vector varcomps
= vector_init(VECTOR_MIN_SIZE
);
999 cmd_variable_complete(token
, ref
, varcomps
);
1001 if (vector_active(varcomps
) > 0) {
1003 rl_get_screen_size(&rows
, &cols
);
1005 char *ac
= cmd_variable_comp2str(
1007 vty_out(vty
, "%s\n", ac
);
1008 XFREE(MTYPE_TMP
, ac
);
1011 vector_free(varcomps
);
1015 cmd_free_strvec(vline
);
1016 vector_free(describe
);
1022 * Entry point for user commands terminated with '?' character and typed through
1023 * the usual vtysh's stdin interface. This is the function being registered with
1026 static int vtysh_rl_describe(int a
, int b
)
1032 ret
= vtysh_process_questionmark(rl_line_buffer
, rl_end
);
1039 * Function in charged of processing vtysh instructions terminating with '?'
1040 * character and received through the 'vtysh -c' interface. If user's
1041 * instruction is well-formatted, we will call the same processing routine
1042 * utilized by the traditional vtysh's stdin interface.
1044 int vtysh_execute_command_questionmark(char *input
)
1046 int input_len
, qmark_count
= 0;
1049 if (!(input
&& *input
))
1052 /* Finding out question_mark count and strlen */
1053 for (str
= input
; *str
; ++str
) {
1057 input_len
= str
- input
;
1060 * Verify that user's input terminates in '?' and that patterns such as
1061 * 'cmd ? subcmd ?' are prevented.
1063 if (qmark_count
!= 1 || input
[input_len
- 1] != '?')
1067 * Questionmark-processing function is not expecting to receive '?'
1068 * character in input string.
1070 input
[input_len
- 1] = '\0';
1072 return vtysh_process_questionmark(input
, input_len
- 1);
1075 /* Result of cmd_complete_command() call will be stored here
1076 * and used in new_completion() in order to put the space in
1077 * correct places only. */
1078 int complete_status
;
1080 static char *command_generator(const char *text
, int state
)
1083 static char **matched
= NULL
;
1084 static int index
= 0;
1090 if (vty
->node
== AUTH_NODE
|| vty
->node
== AUTH_ENABLE_NODE
)
1093 vline
= cmd_make_strvec(rl_line_buffer
);
1097 if (rl_end
&& isspace((int)rl_line_buffer
[rl_end
- 1]))
1098 vector_set(vline
, NULL
);
1100 matched
= cmd_complete_command(vline
, vty
, &complete_status
);
1101 cmd_free_strvec(vline
);
1104 if (matched
&& matched
[index
])
1106 * this is free()'d by readline, but we leak 1 count of
1109 return matched
[index
++];
1111 XFREE(MTYPE_TMP
, matched
);
1117 static char **new_completion(const char *text
, int start
, int end
)
1121 matches
= rl_completion_matches(text
, command_generator
);
1125 if (complete_status
!= CMD_COMPLETE_FULL_MATCH
)
1126 /* only append a space on full match */
1127 rl_completion_append_character
= '\0';
1133 /* Vty node structures. */
1134 static struct cmd_node bgp_node
= {
1135 BGP_NODE
, "%s(config-router)# ",
1138 static struct cmd_node rip_node
= {
1139 RIP_NODE
, "%s(config-router)# ",
1142 static struct cmd_node isis_node
= {
1143 ISIS_NODE
, "%s(config-router)# ",
1146 static struct cmd_node openfabric_node
= {
1147 OPENFABRIC_NODE
, "%s(config-router)# ",
1150 static struct cmd_node interface_node
= {
1151 INTERFACE_NODE
, "%s(config-if)# ",
1154 static struct cmd_node pw_node
= {
1155 PW_NODE
, "%s(config-pw)# ",
1158 static struct cmd_node logicalrouter_node
= {
1159 LOGICALROUTER_NODE
, "%s(config-logical-router)# ",
1162 static struct cmd_node vrf_node
= {
1163 VRF_NODE
, "%s(config-vrf)# ",
1166 static struct cmd_node nh_group_node
= {
1168 "%s(config-nh-group)# ",
1171 static struct cmd_node rmap_node
= {RMAP_NODE
, "%s(config-route-map)# "};
1173 static struct cmd_node pbr_map_node
= {PBRMAP_NODE
, "%s(config-pbr-map)# "};
1175 static struct cmd_node zebra_node
= {ZEBRA_NODE
, "%s(config-router)# "};
1177 static struct cmd_node bgp_vpnv4_node
= {BGP_VPNV4_NODE
,
1178 "%s(config-router-af)# "};
1180 static struct cmd_node bgp_vpnv6_node
= {BGP_VPNV6_NODE
,
1181 "%s(config-router-af)# "};
1183 static struct cmd_node bgp_flowspecv4_node
= {BGP_FLOWSPECV4_NODE
,
1184 "%s(config-router-af)# "};
1186 static struct cmd_node bgp_flowspecv6_node
= {BGP_FLOWSPECV6_NODE
,
1187 "%s(config-router-af)# "};
1189 static struct cmd_node bgp_ipv4_node
= {BGP_IPV4_NODE
,
1190 "%s(config-router-af)# "};
1192 static struct cmd_node bgp_ipv4m_node
= {BGP_IPV4M_NODE
,
1193 "%s(config-router-af)# "};
1195 static struct cmd_node bgp_ipv4l_node
= {BGP_IPV4L_NODE
,
1196 "%s(config-router-af)# "};
1198 static struct cmd_node bgp_ipv6_node
= {BGP_IPV6_NODE
,
1199 "%s(config-router-af)# "};
1201 static struct cmd_node bgp_ipv6m_node
= {BGP_IPV6M_NODE
,
1202 "%s(config-router-af)# "};
1204 static struct cmd_node bgp_evpn_node
= {BGP_EVPN_NODE
,
1205 "%s(config-router-af)# "};
1207 static struct cmd_node bgp_evpn_vni_node
= {BGP_EVPN_VNI_NODE
,
1208 "%s(config-router-af-vni)# "};
1210 static struct cmd_node bgp_ipv6l_node
= {BGP_IPV6L_NODE
,
1211 "%s(config-router-af)# "};
1213 static struct cmd_node bgp_vnc_defaults_node
= {
1214 BGP_VNC_DEFAULTS_NODE
, "%s(config-router-vnc-defaults)# "};
1216 static struct cmd_node bgp_vnc_nve_group_node
= {
1217 BGP_VNC_NVE_GROUP_NODE
, "%s(config-router-vnc-nve-group)# "};
1219 static struct cmd_node bgp_vrf_policy_node
= {BGP_VRF_POLICY_NODE
,
1220 "%s(config-router-vrf-policy)# "};
1222 static struct cmd_node bgp_vnc_l2_group_node
= {
1223 BGP_VNC_L2_GROUP_NODE
, "%s(config-router-vnc-l2-group)# "};
1225 static struct cmd_node ospf_node
= {OSPF_NODE
, "%s(config-router)# "};
1227 static struct cmd_node eigrp_node
= {EIGRP_NODE
, "%s(config-router)# "};
1229 static struct cmd_node babel_node
= {BABEL_NODE
, "%s(config-router)# "};
1231 static struct cmd_node ripng_node
= {RIPNG_NODE
, "%s(config-router)# "};
1233 static struct cmd_node ospf6_node
= {OSPF6_NODE
, "%s(config-ospf6)# "};
1235 static struct cmd_node ldp_node
= {LDP_NODE
, "%s(config-ldp)# "};
1237 static struct cmd_node ldp_ipv4_node
= {LDP_IPV4_NODE
, "%s(config-ldp-af)# "};
1239 static struct cmd_node ldp_ipv6_node
= {LDP_IPV6_NODE
, "%s(config-ldp-af)# "};
1241 static struct cmd_node ldp_ipv4_iface_node
= {LDP_IPV4_IFACE_NODE
,
1242 "%s(config-ldp-af-if)# "};
1244 static struct cmd_node ldp_ipv6_iface_node
= {LDP_IPV6_IFACE_NODE
,
1245 "%s(config-ldp-af-if)# "};
1247 static struct cmd_node ldp_l2vpn_node
= {LDP_L2VPN_NODE
, "%s(config-l2vpn)# "};
1249 static struct cmd_node ldp_pseudowire_node
= {LDP_PSEUDOWIRE_NODE
,
1250 "%s(config-l2vpn-pw)# "};
1252 static struct cmd_node keychain_node
= {KEYCHAIN_NODE
, "%s(config-keychain)# "};
1254 static struct cmd_node keychain_key_node
= {KEYCHAIN_KEY_NODE
,
1255 "%s(config-keychain-key)# "};
1257 struct cmd_node link_params_node
= {
1258 LINK_PARAMS_NODE
, "%s(config-link-params)# ",
1261 static struct cmd_node rpki_node
= {RPKI_NODE
, "%s(config-rpki)# ", 1};
1264 static struct cmd_node bfd_node
= {
1269 static struct cmd_node bfd_peer_node
= {
1271 "%s(config-bfd-peer)# ",
1273 #endif /* HAVE_BFDD */
1275 /* Defined in lib/vty.c */
1276 extern struct cmd_node vty_node
;
1278 /* When '^Z' is received from vty, move down to the enable mode. */
1279 static int vtysh_end(void)
1281 switch (vty
->node
) {
1284 /* Nothing to do. */
1287 vty
->node
= ENABLE_NODE
;
1293 DEFUNSH(VTYSH_REALLYALL
, vtysh_end_all
, vtysh_end_all_cmd
, "end",
1294 "End current mode and change to enable mode\n")
1299 DEFUNSH(VTYSH_BGPD
, router_bgp
, router_bgp_cmd
,
1300 "router bgp [(1-4294967295) [<view|vrf> WORD]]",
1301 ROUTER_STR BGP_STR AS_STR
1302 "BGP view\nBGP VRF\n"
1305 vty
->node
= BGP_NODE
;
1309 #ifdef KEEP_OLD_VPN_COMMANDS
1310 DEFUNSH(VTYSH_BGPD
, address_family_vpnv4
, address_family_vpnv4_cmd
,
1311 "address-family vpnv4 [unicast]",
1312 "Enter Address Family command mode\n"
1314 "Address Family modifier\n")
1316 vty
->node
= BGP_VPNV4_NODE
;
1320 DEFUNSH(VTYSH_BGPD
, address_family_vpnv6
, address_family_vpnv6_cmd
,
1321 "address-family vpnv6 [unicast]",
1322 "Enter Address Family command mode\n"
1324 "Address Family modifier\n")
1326 vty
->node
= BGP_VPNV6_NODE
;
1329 #endif /* KEEP_OLD_VPN_COMMANDS */
1331 DEFUNSH(VTYSH_BGPD
, address_family_ipv4
, address_family_ipv4_cmd
,
1332 "address-family ipv4 [unicast]",
1333 "Enter Address Family command mode\n"
1335 "Address Family Modifier\n")
1337 vty
->node
= BGP_IPV4_NODE
;
1341 DEFUNSH(VTYSH_BGPD
, address_family_flowspecv4
, address_family_flowspecv4_cmd
,
1342 "address-family ipv4 flowspec",
1343 "Enter Address Family command mode\n"
1345 "Address Family Modifier\n")
1347 vty
->node
= BGP_FLOWSPECV4_NODE
;
1351 DEFUNSH(VTYSH_BGPD
, address_family_flowspecv6
, address_family_flowspecv6_cmd
,
1352 "address-family ipv6 flowspec",
1353 "Enter Address Family command mode\n"
1355 "Address Family Modifier\n")
1357 vty
->node
= BGP_FLOWSPECV6_NODE
;
1361 DEFUNSH(VTYSH_BGPD
, address_family_ipv4_multicast
,
1362 address_family_ipv4_multicast_cmd
, "address-family ipv4 multicast",
1363 "Enter Address Family command mode\n"
1365 "Address Family modifier\n")
1367 vty
->node
= BGP_IPV4M_NODE
;
1371 DEFUNSH(VTYSH_BGPD
, address_family_ipv4_vpn
, address_family_ipv4_vpn_cmd
,
1372 "address-family ipv4 vpn",
1373 "Enter Address Family command mode\n"
1375 "Address Family modifier\n")
1377 vty
->node
= BGP_VPNV4_NODE
;
1381 DEFUNSH(VTYSH_BGPD
, address_family_ipv4_labeled_unicast
,
1382 address_family_ipv4_labeled_unicast_cmd
,
1383 "address-family ipv4 labeled-unicast",
1384 "Enter Address Family command mode\n"
1386 "Address Family modifier\n")
1388 vty
->node
= BGP_IPV4L_NODE
;
1392 DEFUNSH(VTYSH_BGPD
, address_family_ipv6
, address_family_ipv6_cmd
,
1393 "address-family ipv6 [unicast]",
1394 "Enter Address Family command mode\n"
1396 "Address Family modifier\n")
1398 vty
->node
= BGP_IPV6_NODE
;
1402 DEFUNSH(VTYSH_BGPD
, address_family_ipv6_multicast
,
1403 address_family_ipv6_multicast_cmd
, "address-family ipv6 multicast",
1404 "Enter Address Family command mode\n"
1406 "Address Family modifier\n")
1408 vty
->node
= BGP_IPV6M_NODE
;
1412 DEFUNSH(VTYSH_BGPD
, address_family_ipv6_vpn
, address_family_ipv6_vpn_cmd
,
1413 "address-family ipv6 vpn",
1414 "Enter Address Family command mode\n"
1416 "Address Family modifier\n")
1418 vty
->node
= BGP_VPNV6_NODE
;
1422 DEFUNSH(VTYSH_BGPD
, address_family_ipv6_labeled_unicast
,
1423 address_family_ipv6_labeled_unicast_cmd
,
1424 "address-family ipv6 labeled-unicast",
1425 "Enter Address Family command mode\n"
1427 "Address Family modifier\n")
1429 vty
->node
= BGP_IPV6L_NODE
;
1437 "Enable rpki and enter rpki configuration mode\n")
1439 vty
->node
= RPKI_NODE
;
1443 DEFUNSH(VTYSH_BGPD
, address_family_evpn
, address_family_evpn_cmd
,
1444 "address-family <l2vpn evpn>",
1445 "Enter Address Family command mode\n"
1447 "Address Family modifier\n")
1449 vty
->node
= BGP_EVPN_NODE
;
1453 #if defined(HAVE_CUMULUS)
1454 DEFUNSH_HIDDEN(VTYSH_BGPD
, address_family_evpn2
, address_family_evpn2_cmd
,
1455 "address-family evpn",
1456 "Enter Address Family command mode\n"
1457 "EVPN Address family\n")
1459 vty
->node
= BGP_EVPN_NODE
;
1464 DEFUNSH(VTYSH_BGPD
, bgp_evpn_vni
, bgp_evpn_vni_cmd
, "vni " CMD_VNI_RANGE
,
1465 "VXLAN Network Identifier\n"
1468 vty
->node
= BGP_EVPN_VNI_NODE
;
1472 #if defined(ENABLE_BGP_VNC)
1473 DEFUNSH(VTYSH_BGPD
, vnc_defaults
, vnc_defaults_cmd
, "vnc defaults",
1474 "VNC/RFP related configuration\n"
1475 "Configure default NVE group\n")
1477 vty
->node
= BGP_VNC_DEFAULTS_NODE
;
1481 DEFUNSH(VTYSH_BGPD
, vnc_nve_group
, vnc_nve_group_cmd
, "vnc nve-group NAME",
1482 "VNC/RFP related configuration\n"
1483 "Configure a NVE group\n"
1486 vty
->node
= BGP_VNC_NVE_GROUP_NODE
;
1490 DEFUNSH(VTYSH_BGPD
, vnc_vrf_policy
, vnc_vrf_policy_cmd
, "vrf-policy NAME",
1491 "Configure a VRF policy group\n"
1494 vty
->node
= BGP_VRF_POLICY_NODE
;
1498 DEFUNSH(VTYSH_BGPD
, vnc_l2_group
, vnc_l2_group_cmd
, "vnc l2-group NAME",
1499 "VNC/RFP related configuration\n"
1500 "Configure a L2 group\n"
1503 vty
->node
= BGP_VNC_L2_GROUP_NODE
;
1508 DEFUNSH(VTYSH_KEYS
, key_chain
, key_chain_cmd
, "key chain WORD",
1509 "Authentication key management\n"
1510 "Key-chain management\n"
1513 vty
->node
= KEYCHAIN_NODE
;
1517 DEFUNSH(VTYSH_KEYS
, key
, key_cmd
, "key (0-2147483647)",
1519 "Key identifier number\n")
1521 vty
->node
= KEYCHAIN_KEY_NODE
;
1525 DEFUNSH(VTYSH_RIPD
, router_rip
, router_rip_cmd
, "router rip [vrf NAME]",
1526 ROUTER_STR
"RIP\n" VRF_CMD_HELP_STR
)
1528 vty
->node
= RIP_NODE
;
1532 DEFUNSH(VTYSH_RIPNGD
, router_ripng
, router_ripng_cmd
, "router ripng [vrf NAME]",
1533 ROUTER_STR
"RIPng\n" VRF_CMD_HELP_STR
)
1535 vty
->node
= RIPNG_NODE
;
1539 DEFUNSH(VTYSH_OSPFD
, router_ospf
, router_ospf_cmd
,
1540 "router ospf [(1-65535)] [vrf NAME]",
1541 "Enable a routing process\n"
1542 "Start OSPF configuration\n"
1546 vty
->node
= OSPF_NODE
;
1550 DEFUNSH(VTYSH_EIGRPD
, router_eigrp
, router_eigrp_cmd
, "router eigrp (1-65535)",
1551 "Enable a routing process\n"
1552 "Start EIGRP configuration\n"
1553 "AS number to use\n")
1555 vty
->node
= EIGRP_NODE
;
1559 DEFUNSH(VTYSH_BABELD
, router_babel
, router_babel_cmd
, "router babel",
1560 "Enable a routing process\n"
1561 "Make Babel instance command\n")
1563 vty
->node
= BABEL_NODE
;
1567 DEFUNSH(VTYSH_OSPF6D
, router_ospf6
, router_ospf6_cmd
, "router ospf6",
1568 ROUTER_STR OSPF6_STR
)
1570 vty
->node
= OSPF6_NODE
;
1574 #if defined(HAVE_LDPD)
1575 DEFUNSH(VTYSH_LDPD
, ldp_mpls_ldp
, ldp_mpls_ldp_cmd
, "mpls ldp",
1576 "Global MPLS configuration subcommands\n"
1577 "Label Distribution Protocol\n")
1579 vty
->node
= LDP_NODE
;
1583 DEFUNSH(VTYSH_LDPD
, ldp_address_family_ipv4
, ldp_address_family_ipv4_cmd
,
1584 "address-family ipv4",
1585 "Configure Address Family and its parameters\n"
1588 vty
->node
= LDP_IPV4_NODE
;
1592 DEFUNSH(VTYSH_LDPD
, ldp_address_family_ipv6
, ldp_address_family_ipv6_cmd
,
1593 "address-family ipv6",
1594 "Configure Address Family and its parameters\n"
1597 vty
->node
= LDP_IPV6_NODE
;
1601 DEFUNSH(VTYSH_LDPD
, ldp_exit_address_family
, ldp_exit_address_family_cmd
,
1602 "exit-address-family", "Exit from Address Family configuration mode\n")
1604 if (vty
->node
== LDP_IPV4_NODE
|| vty
->node
== LDP_IPV6_NODE
)
1605 vty
->node
= LDP_NODE
;
1609 DEFUNSH(VTYSH_LDPD
, ldp_interface_ifname
, ldp_interface_ifname_cmd
,
1611 "Enable LDP on an interface and enter interface submode\n"
1612 "Interface's name\n")
1614 switch (vty
->node
) {
1616 vty
->node
= LDP_IPV4_IFACE_NODE
;
1619 vty
->node
= LDP_IPV6_IFACE_NODE
;
1628 DEFUNSH(VTYSH_LDPD
, ldp_l2vpn_word_type_vpls
, ldp_l2vpn_word_type_vpls_cmd
,
1629 "l2vpn WORD type vpls",
1630 "Configure l2vpn commands\n"
1633 "Virtual Private LAN Service\n")
1635 vty
->node
= LDP_L2VPN_NODE
;
1639 DEFUNSH(VTYSH_LDPD
, ldp_member_pseudowire_ifname
,
1640 ldp_member_pseudowire_ifname_cmd
, "member pseudowire IFNAME",
1641 "L2VPN member configuration\n"
1642 "Pseudowire interface\n"
1643 "Interface's name\n")
1645 vty
->node
= LDP_PSEUDOWIRE_NODE
;
1650 DEFUNSH(VTYSH_ISISD
, router_isis
, router_isis_cmd
, "router isis WORD",
1653 "ISO Routing area tag\n")
1655 vty
->node
= ISIS_NODE
;
1659 DEFUNSH(VTYSH_FABRICD
, router_openfabric
, router_openfabric_cmd
, "router openfabric WORD",
1661 "OpenFabric routing protocol\n"
1662 "ISO Routing area tag\n")
1664 vty
->node
= OPENFABRIC_NODE
;
1668 DEFUNSH(VTYSH_RMAP
, vtysh_route_map
, vtysh_route_map_cmd
,
1669 "route-map WORD <deny|permit> (1-65535)",
1670 "Create route-map or enter route-map command mode\n"
1672 "Route map denies set operations\n"
1673 "Route map permits set operations\n"
1674 "Sequence to insert to/delete from existing route-map entry\n")
1676 vty
->node
= RMAP_NODE
;
1680 DEFUNSH(VTYSH_PBRD
, vtysh_pbr_map
, vtysh_pbr_map_cmd
,
1681 "pbr-map NAME seq (1-700)",
1682 "Create pbr-map or enter pbr-map command mode\n"
1683 "The name of the PBR MAP\n"
1684 "Sequence to insert to/delete from existing pbr-map entry\n"
1685 "Sequence number\n")
1687 vty
->node
= PBRMAP_NODE
;
1692 DEFUNSH(VTYSH_BFDD
, bfd_enter
, bfd_enter_cmd
, "bfd", "Configure BFD peers\n")
1694 vty
->node
= BFD_NODE
;
1698 DEFUNSH(VTYSH_BFDD
, bfd_peer_enter
, bfd_peer_enter_cmd
,
1699 "peer <A.B.C.D|X:X::X:X> [{multihop|local-address <A.B.C.D|X:X::X:X>|interface IFNAME|vrf NAME}]",
1701 "IPv4 peer address\n"
1702 "IPv6 peer address\n"
1703 "Configure multihop\n"
1704 "Configure local address\n"
1705 "IPv4 local address\n"
1706 "IPv6 local address\n"
1708 "Configure interface name to use\n"
1710 "Configure VRF name\n")
1712 vty
->node
= BFD_PEER_NODE
;
1715 #endif /* HAVE_BFDD */
1717 DEFSH(VTYSH_PBRD
, vtysh_no_pbr_map_cmd
, "no pbr-map WORD [seq (1-700)]",
1720 "The name of the PBR MAP\n"
1721 "Sequence to delete from existing pbr-map entry\n"
1722 "Sequence number\n")
1724 DEFUNSH(VTYSH_ALL
, vtysh_line_vty
, vtysh_line_vty_cmd
, "line vty",
1725 "Configure a terminal line\n"
1726 "Virtual terminal\n")
1728 vty
->node
= VTY_NODE
;
1732 DEFUNSH(VTYSH_REALLYALL
, vtysh_enable
, vtysh_enable_cmd
, "enable",
1733 "Turn on privileged mode command\n")
1735 vty
->node
= ENABLE_NODE
;
1739 DEFUNSH(VTYSH_REALLYALL
, vtysh_disable
, vtysh_disable_cmd
, "disable",
1740 "Turn off privileged mode command\n")
1742 if (vty
->node
== ENABLE_NODE
)
1743 vty
->node
= VIEW_NODE
;
1747 DEFUNSH(VTYSH_REALLYALL
, vtysh_config_terminal
, vtysh_config_terminal_cmd
,
1748 "configure [terminal]",
1749 "Configuration from vty interface\n"
1750 "Configuration terminal\n")
1752 vty
->node
= CONFIG_NODE
;
1756 static int vtysh_exit(struct vty
*vty
)
1758 switch (vty
->node
) {
1764 vty
->node
= ENABLE_NODE
;
1766 case INTERFACE_NODE
:
1768 case LOGICALROUTER_NODE
:
1780 case LDP_L2VPN_NODE
:
1782 case OPENFABRIC_NODE
:
1789 vtysh_execute("end");
1790 vtysh_execute("configure");
1791 vty
->node
= CONFIG_NODE
;
1793 case BGP_VPNV4_NODE
:
1794 case BGP_VPNV6_NODE
:
1796 case BGP_IPV4M_NODE
:
1797 case BGP_IPV4L_NODE
:
1799 case BGP_IPV6M_NODE
:
1800 case BGP_IPV6L_NODE
:
1801 case BGP_FLOWSPECV4_NODE
:
1802 case BGP_FLOWSPECV6_NODE
:
1803 case BGP_VRF_POLICY_NODE
:
1805 case BGP_VNC_DEFAULTS_NODE
:
1806 case BGP_VNC_NVE_GROUP_NODE
:
1807 case BGP_VNC_L2_GROUP_NODE
:
1808 vty
->node
= BGP_NODE
;
1810 case BGP_EVPN_VNI_NODE
:
1811 vty
->node
= BGP_EVPN_NODE
;
1815 vty
->node
= LDP_NODE
;
1817 case LDP_IPV4_IFACE_NODE
:
1818 vty
->node
= LDP_IPV4_NODE
;
1820 case LDP_IPV6_IFACE_NODE
:
1821 vty
->node
= LDP_IPV6_NODE
;
1823 case LDP_PSEUDOWIRE_NODE
:
1824 vty
->node
= LDP_L2VPN_NODE
;
1826 case KEYCHAIN_KEY_NODE
:
1827 vty
->node
= KEYCHAIN_NODE
;
1829 case LINK_PARAMS_NODE
:
1830 vty
->node
= INTERFACE_NODE
;
1833 vty
->node
= BFD_NODE
;
1841 DEFUNSH(VTYSH_REALLYALL
, vtysh_exit_all
, vtysh_exit_all_cmd
, "exit",
1842 "Exit current mode and down to previous mode\n")
1844 return vtysh_exit(vty
);
1847 DEFUNSH(VTYSH_ALL
, vtysh_quit_all
, vtysh_quit_all_cmd
, "quit",
1848 "Exit current mode and down to previous mode\n")
1850 return vtysh_exit_all(self
, vty
, argc
, argv
);
1853 DEFUNSH(VTYSH_BGPD
, exit_address_family
, exit_address_family_cmd
,
1854 "exit-address-family", "Exit from Address Family configuration mode\n")
1856 if (vty
->node
== BGP_IPV4_NODE
|| vty
->node
== BGP_IPV4M_NODE
1857 || vty
->node
== BGP_IPV4L_NODE
|| vty
->node
== BGP_VPNV4_NODE
1858 || vty
->node
== BGP_VPNV6_NODE
|| vty
->node
== BGP_IPV6_NODE
1859 || vty
->node
== BGP_IPV6L_NODE
|| vty
->node
== BGP_IPV6M_NODE
1860 || vty
->node
== BGP_EVPN_NODE
1861 || vty
->node
== BGP_FLOWSPECV4_NODE
1862 || vty
->node
== BGP_FLOWSPECV6_NODE
)
1863 vty
->node
= BGP_NODE
;
1867 DEFUNSH(VTYSH_BGPD
, exit_vni
, exit_vni_cmd
, "exit-vni", "Exit from VNI mode\n")
1869 if (vty
->node
== BGP_EVPN_VNI_NODE
)
1870 vty
->node
= BGP_EVPN_NODE
;
1874 DEFUNSH(VTYSH_BGPD
, exit_vnc_config
, exit_vnc_config_cmd
, "exit-vnc",
1875 "Exit from VNC configuration mode\n")
1877 if (vty
->node
== BGP_VNC_DEFAULTS_NODE
1878 || vty
->node
== BGP_VNC_NVE_GROUP_NODE
1879 || vty
->node
== BGP_VNC_L2_GROUP_NODE
)
1880 vty
->node
= BGP_NODE
;
1885 DEFUNSH(VTYSH_BGPD
, rpki_exit
, rpki_exit_cmd
, "exit",
1886 "Exit current mode and down to previous mode\n")
1892 DEFUNSH(VTYSH_BGPD
, rpki_quit
, rpki_quit_cmd
, "quit",
1893 "Exit current mode and down to previous mode\n")
1895 return rpki_exit(self
, vty
, argc
, argv
);
1898 DEFUNSH(VTYSH_PIMD
|VTYSH_ZEBRA
, exit_vrf_config
, exit_vrf_config_cmd
, "exit-vrf",
1899 "Exit from VRF configuration mode\n")
1901 if (vty
->node
== VRF_NODE
)
1902 vty
->node
= CONFIG_NODE
;
1906 DEFUNSH(VTYSH_BGPD
, exit_vrf_policy
, exit_vrf_policy_cmd
, "exit-vrf-policy",
1907 "Exit from VRF policy configuration mode\n")
1909 if (vty
->node
== BGP_VRF_POLICY_NODE
)
1910 vty
->node
= BGP_NODE
;
1914 DEFUNSH(VTYSH_RIPD
, vtysh_exit_ripd
, vtysh_exit_ripd_cmd
, "exit",
1915 "Exit current mode and down to previous mode\n")
1917 return vtysh_exit(vty
);
1920 DEFUNSH(VTYSH_RIPD
, vtysh_quit_ripd
, vtysh_quit_ripd_cmd
, "quit",
1921 "Exit current mode and down to previous mode\n")
1923 return vtysh_exit_ripd(self
, vty
, argc
, argv
);
1926 DEFUNSH(VTYSH_RIPNGD
, vtysh_exit_ripngd
, vtysh_exit_ripngd_cmd
, "exit",
1927 "Exit current mode and down to previous mode\n")
1929 return vtysh_exit(vty
);
1932 DEFUNSH(VTYSH_RIPNGD
, vtysh_quit_ripngd
, vtysh_quit_ripngd_cmd
, "quit",
1933 "Exit current mode and down to previous mode\n")
1935 return vtysh_exit_ripngd(self
, vty
, argc
, argv
);
1938 DEFUNSH(VTYSH_RMAP
, vtysh_exit_rmap
, vtysh_exit_rmap_cmd
, "exit",
1939 "Exit current mode and down to previous mode\n")
1941 return vtysh_exit(vty
);
1944 DEFUNSH(VTYSH_RMAP
, vtysh_quit_rmap
, vtysh_quit_rmap_cmd
, "quit",
1945 "Exit current mode and down to previous mode\n")
1947 return vtysh_exit_rmap(self
, vty
, argc
, argv
);
1950 DEFUNSH(VTYSH_PBRD
, vtysh_exit_pbr_map
, vtysh_exit_pbr_map_cmd
, "exit",
1951 "Exit current mode and down to previous mode\n")
1953 return vtysh_exit(vty
);
1956 DEFUNSH(VTYSH_PBRD
, vtysh_quit_pbr_map
, vtysh_quit_pbr_map_cmd
, "quit",
1957 "Exit current mode and down to previous mode\n")
1959 return vtysh_exit_rmap(self
, vty
, argc
, argv
);
1962 DEFUNSH(VTYSH_BGPD
, vtysh_exit_bgpd
, vtysh_exit_bgpd_cmd
, "exit",
1963 "Exit current mode and down to previous mode\n")
1965 return vtysh_exit(vty
);
1968 DEFUNSH(VTYSH_BGPD
, vtysh_quit_bgpd
, vtysh_quit_bgpd_cmd
, "quit",
1969 "Exit current mode and down to previous mode\n")
1971 return vtysh_exit_bgpd(self
, vty
, argc
, argv
);
1974 DEFUNSH(VTYSH_OSPFD
, vtysh_exit_ospfd
, vtysh_exit_ospfd_cmd
, "exit",
1975 "Exit current mode and down to previous mode\n")
1977 return vtysh_exit(vty
);
1980 DEFUNSH(VTYSH_OSPFD
, vtysh_quit_ospfd
, vtysh_quit_ospfd_cmd
, "quit",
1981 "Exit current mode and down to previous mode\n")
1983 return vtysh_exit_ospfd(self
, vty
, argc
, argv
);
1986 DEFUNSH(VTYSH_EIGRPD
, vtysh_exit_eigrpd
, vtysh_exit_eigrpd_cmd
, "exit",
1987 "Exit current mode and down to previous mode\n")
1989 return vtysh_exit(vty
);
1992 DEFUNSH(VTYSH_EIGRPD
, vtysh_quit_eigrpd
, vtysh_quit_eigrpd_cmd
, "quit",
1993 "Exit current mode and down to previous mode\n")
1995 return vtysh_exit(vty
);
1998 DEFUNSH(VTYSH_EIGRPD
, vtysh_exit_babeld
, vtysh_exit_babeld_cmd
, "exit",
1999 "Exit current mode and down to previous mode\n")
2001 return vtysh_exit(vty
);
2004 DEFUNSH(VTYSH_BABELD
, vtysh_quit_babeld
, vtysh_quit_babeld_cmd
, "quit",
2005 "Exit current mode and down to previous mode\n")
2007 return vtysh_exit(vty
);
2010 DEFUNSH(VTYSH_OSPF6D
, vtysh_exit_ospf6d
, vtysh_exit_ospf6d_cmd
, "exit",
2011 "Exit current mode and down to previous mode\n")
2013 return vtysh_exit(vty
);
2016 DEFUNSH(VTYSH_OSPF6D
, vtysh_quit_ospf6d
, vtysh_quit_ospf6d_cmd
, "quit",
2017 "Exit current mode and down to previous mode\n")
2019 return vtysh_exit_ospf6d(self
, vty
, argc
, argv
);
2022 #if defined(HAVE_LDPD)
2023 DEFUNSH(VTYSH_LDPD
, vtysh_exit_ldpd
, vtysh_exit_ldpd_cmd
, "exit",
2024 "Exit current mode and down to previous mode\n")
2026 return vtysh_exit(vty
);
2029 ALIAS(vtysh_exit_ldpd
, vtysh_quit_ldpd_cmd
, "quit",
2030 "Exit current mode and down to previous mode\n")
2033 DEFUNSH(VTYSH_ISISD
, vtysh_exit_isisd
, vtysh_exit_isisd_cmd
, "exit",
2034 "Exit current mode and down to previous mode\n")
2036 return vtysh_exit(vty
);
2039 DEFUNSH(VTYSH_ISISD
, vtysh_quit_isisd
, vtysh_quit_isisd_cmd
, "quit",
2040 "Exit current mode and down to previous mode\n")
2042 return vtysh_exit_isisd(self
, vty
, argc
, argv
);
2046 DEFUNSH(VTYSH_BFDD
, vtysh_exit_bfdd
, vtysh_exit_bfdd_cmd
, "exit",
2047 "Exit current mode and down to previous mode\n")
2049 return vtysh_exit(vty
);
2052 ALIAS(vtysh_exit_bfdd
, vtysh_quit_bfdd_cmd
, "quit",
2053 "Exit current mode and down to previous mode\n")
2056 DEFUNSH(VTYSH_FABRICD
, vtysh_exit_fabricd
, vtysh_exit_fabricd_cmd
, "exit",
2057 "Exit current mode and down to previous mode\n")
2059 return vtysh_exit(vty
);
2062 DEFUNSH(VTYSH_FABRICD
, vtysh_quit_fabricd
, vtysh_quit_fabricd_cmd
, "quit",
2063 "Exit current mode and down to previous mode\n")
2065 return vtysh_exit_fabricd(self
, vty
, argc
, argv
);
2068 DEFUNSH(VTYSH_ALL
, vtysh_exit_line_vty
, vtysh_exit_line_vty_cmd
, "exit",
2069 "Exit current mode and down to previous mode\n")
2071 return vtysh_exit(vty
);
2074 DEFUNSH(VTYSH_ALL
, vtysh_quit_line_vty
, vtysh_quit_line_vty_cmd
, "quit",
2075 "Exit current mode and down to previous mode\n")
2077 return vtysh_exit_line_vty(self
, vty
, argc
, argv
);
2080 DEFUNSH(VTYSH_INTERFACE
, vtysh_interface
, vtysh_interface_cmd
,
2081 "interface IFNAME [vrf NAME]",
2082 "Select an interface to configure\n"
2083 "Interface's name\n" VRF_CMD_HELP_STR
)
2085 vty
->node
= INTERFACE_NODE
;
2089 DEFUNSH(VTYSH_ZEBRA
, vtysh_pseudowire
, vtysh_pseudowire_cmd
,
2090 "pseudowire IFNAME",
2091 "Static pseudowire configuration\n"
2092 "Pseudowire name\n")
2094 vty
->node
= PW_NODE
;
2098 DEFUNSH(VTYSH_ZEBRA
, vtysh_logicalrouter
, vtysh_logicalrouter_cmd
,
2099 "logical-router (1-65535) ns NAME",
2100 "Enable a logical-router\n"
2101 "Specify the logical-router indentifier\n"
2103 "The file name in " NS_RUN_DIR
", or a full pathname\n")
2105 vty
->node
= LOGICALROUTER_NODE
;
2109 DEFSH(VTYSH_ZEBRA
, vtysh_no_logicalrouter_cmd
,
2110 "no logical-router (1-65535) ns NAME", NO_STR
2111 "Enable a Logical-Router\n"
2112 "Specify the Logical-Router identifier\n"
2114 "The file name in " NS_RUN_DIR
", or a full pathname\n")
2116 DEFUNSH(VTYSH_PBRD
| VTYSH_SHARPD
, vtysh_nexthop_group
, vtysh_nexthop_group_cmd
,
2117 "nexthop-group NAME",
2118 "Nexthop Group configuration\n"
2119 "Name of the Nexthop Group\n")
2121 vty
->node
= NH_GROUP_NODE
;
2125 DEFSH(VTYSH_PBRD
| VTYSH_SHARPD
, vtysh_no_nexthop_group_cmd
,
2126 "no nexthop-group NAME",
2128 "Nexthop Group Configuration\n"
2129 "Name of the Nexthop Group\n")
2131 DEFUNSH(VTYSH_VRF
, vtysh_vrf
, vtysh_vrf_cmd
, "vrf NAME",
2132 "Select a VRF to configure\n"
2135 vty
->node
= VRF_NODE
;
2139 DEFSH(VTYSH_ZEBRA
, vtysh_vrf_netns_cmd
,
2141 "Attach VRF to a Namespace\n"
2142 "The file name in " NS_RUN_DIR
", or a full pathname\n")
2144 DEFSH(VTYSH_ZEBRA
, vtysh_no_vrf_netns_cmd
,
2147 "Detach VRF from a Namespace\n"
2148 "The file name in " NS_RUN_DIR
", or a full pathname\n")
2150 DEFUNSH(VTYSH_NS
, vtysh_exit_logicalrouter
,
2151 vtysh_exit_logicalrouter_cmd
, "exit",
2152 "Exit current mode and down to previous mode\n")
2154 return vtysh_exit(vty
);
2157 DEFUNSH(VTYSH_NS
, vtysh_quit_logicalrouter
,
2158 vtysh_quit_logicalrouter_cmd
, "quit",
2159 "Exit current mode and down to previous mode\n")
2161 return vtysh_exit_logicalrouter(self
, vty
, argc
, argv
);
2164 DEFUNSH(VTYSH_VRF
, vtysh_exit_vrf
, vtysh_exit_vrf_cmd
, "exit",
2165 "Exit current mode and down to previous mode\n")
2167 return vtysh_exit(vty
);
2170 DEFUNSH(VTYSH_VRF
, vtysh_quit_vrf
, vtysh_quit_vrf_cmd
, "quit",
2171 "Exit current mode and down to previous mode\n")
2173 return vtysh_exit_vrf(self
, vty
, argc
, argv
);
2176 DEFUNSH(VTYSH_PBRD
| VTYSH_SHARPD
, vtysh_exit_nexthop_group
, vtysh_exit_nexthop_group_cmd
,
2177 "exit", "Exit current mode and down to previous mode\n")
2179 return vtysh_exit(vty
);
2182 DEFUNSH(VTYSH_VRF
, vtysh_quit_nexthop_group
, vtysh_quit_nexthop_group_cmd
,
2183 "quit", "Exit current mode and down to previous mode\n")
2185 return vtysh_exit_nexthop_group(self
, vty
, argc
, argv
);
2188 DEFUNSH(VTYSH_INTERFACE
, vtysh_exit_interface
, vtysh_exit_interface_cmd
, "exit",
2189 "Exit current mode and down to previous mode\n")
2191 return vtysh_exit(vty
);
2194 DEFUNSH(VTYSH_INTERFACE
, vtysh_quit_interface
, vtysh_quit_interface_cmd
, "quit",
2195 "Exit current mode and down to previous mode\n")
2197 return vtysh_exit_interface(self
, vty
, argc
, argv
);
2200 DEFUN (vtysh_show_poll
,
2201 vtysh_show_poll_cmd
,
2204 "Thread information\n"
2205 "Thread Poll Information\n")
2208 int ret
= CMD_SUCCESS
;
2211 snprintf(line
, sizeof(line
), "do show thread poll\n");
2212 for (i
= 0; i
< array_size(vtysh_client
); i
++)
2213 if (vtysh_client
[i
].fd
>= 0) {
2214 vty_out(vty
, "Thread statistics for %s:\n",
2215 vtysh_client
[i
].name
);
2216 ret
= vtysh_client_execute(&vtysh_client
[i
], line
);
2222 DEFUN (vtysh_show_thread
,
2223 vtysh_show_thread_cmd
,
2224 "show thread cpu [FILTER]",
2226 "Thread information\n"
2227 "Thread CPU usage\n"
2228 "Display filter (rwtexb)\n")
2232 int ret
= CMD_SUCCESS
;
2235 const char *filter
=
2236 argv_find(argv
, argc
, "FILTER", &idx
) ? argv
[idx
]->arg
: "";
2238 snprintf(line
, sizeof(line
), "do show thread cpu %s\n", filter
);
2239 for (i
= 0; i
< array_size(vtysh_client
); i
++)
2240 if (vtysh_client
[i
].fd
>= 0) {
2241 vty_out(vty
, "Thread statistics for %s:\n",
2242 vtysh_client
[i
].name
);
2243 ret
= vtysh_client_execute(&vtysh_client
[i
], line
);
2249 DEFUN (vtysh_show_work_queues
,
2250 vtysh_show_work_queues_cmd
,
2253 "Work Queue information\n")
2256 int ret
= CMD_SUCCESS
;
2257 char line
[] = "do show work-queues\n";
2259 for (i
= 0; i
< array_size(vtysh_client
); i
++)
2260 if (vtysh_client
[i
].fd
>= 0) {
2261 vty_out(vty
, "Work queue statistics for %s:\n",
2262 vtysh_client
[i
].name
);
2263 ret
= vtysh_client_execute(&vtysh_client
[i
], line
);
2270 DEFUN (vtysh_show_work_queues_daemon
,
2271 vtysh_show_work_queues_daemon_cmd
,
2272 "show work-queues <zebra|ripd|ripngd|ospfd|ospf6d|bgpd|isisd|pbrd|fabricd|pimd|staticd>",
2274 "Work Queue information\n"
2275 "For the zebra daemon\n"
2276 "For the rip daemon\n"
2277 "For the ripng daemon\n"
2278 "For the ospf daemon\n"
2279 "For the ospfv6 daemon\n"
2280 "For the bgp daemon\n"
2281 "For the isis daemon\n"
2282 "For the pbr daemon\n"
2283 "For the fabricd daemon\n"
2284 "For the pim daemon\n"
2285 "For the static daemon\n")
2287 int idx_protocol
= 2;
2289 int ret
= CMD_SUCCESS
;
2291 for (i
= 0; i
< array_size(vtysh_client
); i
++) {
2292 if (strmatch(vtysh_client
[i
].name
, argv
[idx_protocol
]->text
))
2296 ret
= vtysh_client_execute(&vtysh_client
[i
], "show work-queues\n");
2301 DEFUNSH(VTYSH_ZEBRA
, vtysh_link_params
, vtysh_link_params_cmd
, "link-params",
2304 vty
->node
= LINK_PARAMS_NODE
;
2308 DEFUNSH(VTYSH_ZEBRA
, exit_link_params
, exit_link_params_cmd
, "exit-link-params",
2309 "Exit from Link Params configuration node\n")
2311 if (vty
->node
== LINK_PARAMS_NODE
)
2312 vty
->node
= INTERFACE_NODE
;
2316 static int show_per_daemon(const char *line
, const char *headline
)
2319 int ret
= CMD_SUCCESS
;
2321 for (i
= 0; i
< array_size(vtysh_client
); i
++)
2322 if (vtysh_client
[i
].fd
>= 0) {
2323 vty_out(vty
, headline
, vtysh_client
[i
].name
);
2324 ret
= vtysh_client_execute(&vtysh_client
[i
], line
);
2331 DEFUNSH_HIDDEN (0x00,
2333 vtysh_debug_all_cmd
,
2337 "Toggle all debugs on or off\n")
2342 DEFUN (vtysh_show_debugging
,
2343 vtysh_show_debugging_cmd
,
2348 return show_per_daemon("do show debugging\n", "");
2351 DEFUN (vtysh_show_debugging_hashtable
,
2352 vtysh_show_debugging_hashtable_cmd
,
2353 "show debugging hashtable [statistics]",
2356 "Statistics about hash tables\n"
2357 "Statistics about hash tables\n")
2361 "Load factor (LF) - average number of elements across all buckets\n");
2363 "Full load factor (FLF) - average number of elements across full buckets\n\n");
2365 "Standard deviation (SD) is calculated for both the LF and FLF\n");
2367 "and indicates the typical deviation of bucket chain length\n");
2368 vty_out(vty
, "from the value in the corresponding load factor.\n\n");
2370 return show_per_daemon("do show debugging hashtable\n",
2371 "Hashtable statistics for %s:\n");
2374 DEFUN (vtysh_show_error_code
,
2375 vtysh_show_error_code_cmd
,
2376 "show error <(1-4294967296)|all> [json]",
2378 "Information on errors\n"
2379 "Error code to get info about\n"
2380 "Information on all errors\n"
2383 char *fcmd
= argv_concat(argv
, argc
, 0);
2387 snprintf(cmd
, sizeof(cmd
), "do %s", fcmd
);
2389 /* FIXME: Needs to determine which daemon to send to via code ranges */
2390 rv
= show_per_daemon(cmd
, "");
2392 XFREE(MTYPE_TMP
, fcmd
);
2397 DEFUN (vtysh_show_memory
,
2398 vtysh_show_memory_cmd
,
2401 "Memory statistics\n")
2403 return show_per_daemon("do show memory\n", "Memory statistics for %s:\n");
2406 DEFUN (vtysh_show_modules
,
2407 vtysh_show_modules_cmd
,
2412 return show_per_daemon("do show modules\n",
2413 "Module information for %s:\n");
2416 /* Logging commands. */
2417 DEFUN (vtysh_show_logging
,
2418 vtysh_show_logging_cmd
,
2421 "Show current logging configuration\n")
2423 return show_per_daemon("do show logging\n",
2424 "Logging configuration for %s:\n");
2427 DEFUNSH(VTYSH_ALL
, vtysh_log_stdout
, vtysh_log_stdout_cmd
, "log stdout",
2429 "Set stdout logging level\n")
2434 DEFUNSH(VTYSH_ALL
, vtysh_log_stdout_level
, vtysh_log_stdout_level_cmd
,
2435 "log stdout <emergencies|alerts|critical|errors|warnings|notifications|informational|debugging>",
2437 "Set stdout logging level\n" LOG_LEVEL_DESC
)
2442 DEFUNSH(VTYSH_ALL
, no_vtysh_log_stdout
, no_vtysh_log_stdout_cmd
,
2443 "no log stdout [LEVEL]", NO_STR
2445 "Cancel logging to stdout\n"
2451 DEFUNSH(VTYSH_ALL
, vtysh_log_file
, vtysh_log_file_cmd
, "log file FILENAME",
2454 "Logging filename\n")
2459 DEFUNSH(VTYSH_ALL
, vtysh_log_file_level
, vtysh_log_file_level_cmd
,
2460 "log file FILENAME <emergencies|alerts|critical|errors|warnings|notifications|informational|debugging>",
2463 "Logging filename\n" LOG_LEVEL_DESC
)
2468 DEFUNSH(VTYSH_ALL
, no_vtysh_log_file
, no_vtysh_log_file_cmd
,
2469 "no log file [FILENAME [LEVEL]]", NO_STR
2471 "Cancel logging to file\n"
2472 "Logging file name\n"
2478 DEFUNSH(VTYSH_ALL
, vtysh_log_monitor
, vtysh_log_monitor_cmd
,
2479 "log monitor [<emergencies|alerts|critical|errors|warnings|notifications|informational|debugging>]",
2481 "Set terminal line (monitor) logging level\n" LOG_LEVEL_DESC
)
2486 DEFUNSH(VTYSH_ALL
, no_vtysh_log_monitor
, no_vtysh_log_monitor_cmd
,
2487 "no log monitor [LEVEL]", NO_STR
2489 "Disable terminal line (monitor) logging\n"
2495 DEFUNSH(VTYSH_ALL
, vtysh_log_syslog
, vtysh_log_syslog_cmd
,
2496 "log syslog [<emergencies|alerts|critical|errors|warnings|notifications|informational|debugging>]",
2498 "Set syslog logging level\n" LOG_LEVEL_DESC
)
2503 DEFUNSH(VTYSH_ALL
, no_vtysh_log_syslog
, no_vtysh_log_syslog_cmd
,
2504 "no log syslog [<emergencies|alerts|critical|errors|warnings|notifications|informational|debugging>]",
2507 "Cancel logging to syslog\n"
2513 DEFUNSH(VTYSH_ALL
, vtysh_log_facility
, vtysh_log_facility_cmd
,
2514 "log facility <kern|user|mail|daemon|auth|syslog|lpr|news|uucp|cron|local0|local1|local2|local3|local4|local5|local6|local7>",
2516 "Facility parameter for syslog messages\n" LOG_FACILITY_DESC
)
2521 DEFUNSH(VTYSH_ALL
, no_vtysh_log_facility
, no_vtysh_log_facility_cmd
,
2522 "no log facility [FACILITY]", NO_STR
2524 "Reset syslog facility to default (daemon)\n"
2525 "Syslog facility\n")
2530 DEFUNSH(VTYSH_ALL
, vtysh_log_record_priority
, vtysh_log_record_priority_cmd
,
2531 "log record-priority",
2533 "Log the priority of the message within the message\n")
2538 DEFUNSH(VTYSH_ALL
, no_vtysh_log_record_priority
,
2539 no_vtysh_log_record_priority_cmd
, "no log record-priority", NO_STR
2541 "Do not log the priority of the message within the message\n")
2546 DEFUNSH(VTYSH_ALL
, vtysh_log_timestamp_precision
,
2547 vtysh_log_timestamp_precision_cmd
, "log timestamp precision (0-6)",
2549 "Timestamp configuration\n"
2550 "Set the timestamp precision\n"
2551 "Number of subsecond digits\n")
2556 DEFUNSH(VTYSH_ALL
, no_vtysh_log_timestamp_precision
,
2557 no_vtysh_log_timestamp_precision_cmd
, "no log timestamp precision",
2560 "Timestamp configuration\n"
2561 "Reset the timestamp precision to the default value of 0\n")
2566 DEFUNSH(VTYSH_ALL
, vtysh_service_password_encrypt
,
2567 vtysh_service_password_encrypt_cmd
, "service password-encryption",
2568 "Set up miscellaneous service\n"
2569 "Enable encrypted passwords\n")
2574 DEFUNSH(VTYSH_ALL
, no_vtysh_service_password_encrypt
,
2575 no_vtysh_service_password_encrypt_cmd
, "no service password-encryption",
2577 "Set up miscellaneous service\n"
2578 "Enable encrypted passwords\n")
2583 DEFUNSH(VTYSH_ALL
, vtysh_config_password
, vtysh_password_cmd
,
2584 "password [(8-8)] LINE",
2585 "Modify the terminal connection password\n"
2586 "Specifies a HIDDEN password will follow\n"
2587 "The password string\n")
2592 DEFUNSH(VTYSH_ALL
, no_vtysh_config_password
, no_vtysh_password_cmd
,
2593 "no password", NO_STR
2594 "Modify the terminal connection password\n")
2596 vty_out(vty
, NO_PASSWD_CMD_WARNING
);
2601 DEFUNSH(VTYSH_ALL
, vtysh_config_enable_password
, vtysh_enable_password_cmd
,
2602 "enable password [(8-8)] LINE",
2603 "Modify enable password parameters\n"
2604 "Assign the privileged level password\n"
2605 "Specifies a HIDDEN password will follow\n"
2606 "The 'enable' password string\n")
2611 DEFUNSH(VTYSH_ALL
, no_vtysh_config_enable_password
,
2612 no_vtysh_enable_password_cmd
, "no enable password", NO_STR
2613 "Modify enable password parameters\n"
2614 "Assign the privileged level password\n")
2616 vty_out(vty
, NO_PASSWD_CMD_WARNING
);
2621 DEFUN (vtysh_write_terminal
,
2622 vtysh_write_terminal_cmd
,
2623 "write terminal [<zebra|ripd|ripngd|ospfd|ospf6d|ldpd|bgpd|isisd|fabricd|pimd|staticd>]",
2624 "Write running configuration to memory, network, or terminal\n"
2625 "Write to terminal\n"
2626 "For the zebra daemon\n"
2627 "For the rip daemon\n"
2628 "For the ripng daemon\n"
2629 "For the ospf daemon\n"
2630 "For the ospfv6 daemon\n"
2631 "For the ldpd daemon\n"
2632 "For the bgp daemon\n"
2633 "For the isis daemon\n"
2634 "For the fabricd daemon\n"
2635 "For the pim daemon\n"
2636 "For the static daemon\n")
2639 char line
[] = "do write terminal\n";
2641 vty_out(vty
, "Building configuration...\n");
2642 vty_out(vty
, "\nCurrent configuration:\n");
2643 vty_out(vty
, "!\n");
2645 for (i
= 0; i
< array_size(vtysh_client
); i
++)
2647 || (strmatch(vtysh_client
[i
].name
, argv
[2]->text
)))
2648 vtysh_client_config(&vtysh_client
[i
], line
);
2650 /* Integrate vtysh specific configuration. */
2651 vty_open_pager(vty
);
2652 vtysh_config_write();
2653 vtysh_config_dump();
2654 vty_close_pager(vty
);
2655 vty_out(vty
, "end\n");
2660 DEFUN (vtysh_show_running_config
,
2661 vtysh_show_running_config_cmd
,
2662 "show running-config [<zebra|ripd|ripngd|ospfd|ospf6d|ldpd|bgpd|isisd|fabricd|pimd|staticd>]",
2664 "Current operating configuration\n"
2665 "For the zebra daemon\n"
2666 "For the rip daemon\n"
2667 "For the ripng daemon\n"
2668 "For the ospf daemon\n"
2669 "For the ospfv6 daemon\n"
2670 "For the ldp daemon\n"
2671 "For the bgp daemon\n"
2672 "For the isis daemon\n"
2673 "For the fabricd daemon\n"
2674 "For the pim daemon\n"
2675 "For the static daemon\n")
2677 return vtysh_write_terminal(self
, vty
, argc
, argv
);
2680 DEFUN (vtysh_integrated_config
,
2681 vtysh_integrated_config_cmd
,
2682 "service integrated-vtysh-config",
2683 "Set up miscellaneous service\n"
2684 "Write configuration into integrated file\n")
2686 vtysh_write_integrated
= WRITE_INTEGRATED_YES
;
2690 DEFUN (no_vtysh_integrated_config
,
2691 no_vtysh_integrated_config_cmd
,
2692 "no service integrated-vtysh-config",
2694 "Set up miscellaneous service\n"
2695 "Write configuration into integrated file\n")
2697 vtysh_write_integrated
= WRITE_INTEGRATED_NO
;
2701 static void backup_config_file(const char *fbackup
)
2703 char *integrate_sav
= NULL
;
2705 integrate_sav
= malloc(strlen(fbackup
) + strlen(CONF_BACKUP_EXT
) + 1);
2706 strcpy(integrate_sav
, fbackup
);
2707 strcat(integrate_sav
, CONF_BACKUP_EXT
);
2709 /* Move current configuration file to backup config file. */
2710 if (unlink(integrate_sav
) != 0) {
2711 vty_out(vty
, "Warning: %s unlink failed\n", integrate_sav
);
2713 if (rename(fbackup
, integrate_sav
) != 0) {
2714 vty_out(vty
, "Error renaming %s to %s\n", fbackup
,
2717 free(integrate_sav
);
2720 int vtysh_write_config_integrated(void)
2723 char line
[] = "do write terminal\n";
2727 struct passwd
*pwentry
;
2730 struct group
*grentry
;
2737 vty_out(vty
, "Building Configuration...\n");
2739 backup_config_file(frr_config
);
2740 fp
= fopen(frr_config
, "w");
2743 "%% Error: failed to open configuration file %s: %s\n",
2744 frr_config
, safe_strerror(errno
));
2745 return CMD_WARNING_CONFIG_FAILED
;
2749 for (i
= 0; i
< array_size(vtysh_client
); i
++)
2750 vtysh_client_config(&vtysh_client
[i
], line
);
2752 vtysh_config_write();
2753 vty
->of_saved
= vty
->of
;
2755 vtysh_config_dump();
2756 vty
->of
= vty
->of_saved
;
2758 if (fchmod(fd
, CONFIGFILE_MASK
) != 0) {
2759 printf("%% Warning: can't chmod configuration file %s: %s\n",
2760 frr_config
, safe_strerror(errno
));
2765 pwentry
= getpwnam(FRR_USER
);
2767 uid
= pwentry
->pw_uid
;
2769 printf("%% Warning: could not look up user \"%s\"\n", FRR_USER
);
2774 grentry
= getgrnam(FRR_GROUP
);
2776 gid
= grentry
->gr_gid
;
2778 printf("%% Warning: could not look up group \"%s\"\n",
2784 if (!fstat(fd
, &st
)) {
2785 if (st
.st_uid
== uid
)
2787 if (st
.st_gid
== gid
)
2789 if ((uid
!= (uid_t
)-1 || gid
!= (gid_t
)-1)
2790 && fchown(fd
, uid
, gid
)) {
2791 printf("%% Warning: can't chown configuration file %s: %s\n",
2792 frr_config
, safe_strerror(errno
));
2796 printf("%% Warning: stat() failed on %s: %s\n", frr_config
,
2797 safe_strerror(errno
));
2803 printf("Integrated configuration saved to %s\n", frr_config
);
2811 static bool want_config_integrated(void)
2815 switch (vtysh_write_integrated
) {
2816 case WRITE_INTEGRATED_UNSPECIFIED
:
2817 if (stat(frr_config
, &s
) && errno
== ENOENT
)
2820 case WRITE_INTEGRATED_NO
:
2822 case WRITE_INTEGRATED_YES
:
2828 DEFUN (vtysh_write_memory
,
2829 vtysh_write_memory_cmd
,
2830 "write [<memory|file>]",
2831 "Write running configuration to memory, network, or terminal\n"
2832 "Write configuration to the file (same as write file)\n"
2833 "Write configuration to the file (same as write memory)\n")
2835 int ret
= CMD_SUCCESS
;
2836 char line
[] = "do write memory\n";
2839 vty_out(vty
, "Note: this version of vtysh never writes vtysh.conf\n");
2841 /* If integrated frr.conf explicitely set. */
2842 if (want_config_integrated()) {
2843 ret
= CMD_WARNING_CONFIG_FAILED
;
2845 /* first attempt to use watchfrr if it's available */
2846 bool used_watchfrr
= false;
2848 for (i
= 0; i
< array_size(vtysh_client
); i
++)
2849 if (vtysh_client
[i
].flag
== VTYSH_WATCHFRR
)
2851 if (i
< array_size(vtysh_client
) && vtysh_client
[i
].fd
!= -1) {
2852 used_watchfrr
= true;
2853 ret
= vtysh_client_execute(&vtysh_client
[i
],
2854 "do write integrated");
2858 * If we didn't use watchfrr, fallback to writing the config
2861 if (!used_watchfrr
) {
2862 printf("\nWarning: attempting direct configuration write without "
2863 "watchfrr.\nFile permissions and ownership may be "
2864 "incorrect, or write may fail.\n\n");
2865 ret
= vtysh_write_config_integrated();
2870 vty_out(vty
, "Building Configuration...\n");
2872 for (i
= 0; i
< array_size(vtysh_client
); i
++)
2873 ret
= vtysh_client_execute(&vtysh_client
[i
], line
);
2878 DEFUN (vtysh_copy_running_config
,
2879 vtysh_copy_running_config_cmd
,
2880 "copy running-config startup-config",
2881 "Copy from one file to another\n"
2882 "Copy from current system configuration\n"
2883 "Copy to startup configuration\n")
2885 return vtysh_write_memory(self
, vty
, argc
, argv
);
2888 DEFUN (vtysh_terminal_paginate
,
2889 vtysh_terminal_paginate_cmd
,
2890 "[no] terminal paginate",
2892 "Set terminal line parameters\n"
2893 "Use pager for output scrolling\n")
2895 free(vtysh_pager_name
);
2896 vtysh_pager_name
= NULL
;
2898 if (strcmp(argv
[0]->text
, "no"))
2899 vtysh_pager_envdef(true);
2903 DEFUN (vtysh_terminal_length
,
2904 vtysh_terminal_length_cmd
,
2905 "[no] terminal length (0-4294967295)",
2907 "Set terminal line parameters\n"
2908 "Set number of lines on a screen\n"
2909 "Number of lines on screen (0 for no pausing, nonzero to use pager)\n")
2912 unsigned long lines
;
2914 free(vtysh_pager_name
);
2915 vtysh_pager_name
= NULL
;
2917 if (!strcmp(argv
[0]->text
, "no") || !strcmp(argv
[1]->text
, "no")) {
2918 /* "terminal no length" = use VTYSH_PAGER */
2919 vtysh_pager_envdef(true);
2923 lines
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
2926 "%% The \"terminal length\" command is deprecated and its value is ignored.\n"
2927 "%% Please use \"terminal paginate\" instead with OS TTY length handling.\n");
2928 vtysh_pager_envdef(true);
2934 ALIAS_DEPRECATED(vtysh_terminal_length
,
2935 vtysh_terminal_no_length_cmd
,
2936 "terminal no length",
2937 "Set terminal line parameters\n"
2939 "Set number of lines on a screen\n")
2941 DEFUN (vtysh_show_daemons
,
2942 vtysh_show_daemons_cmd
,
2945 "Show list of running daemons\n")
2949 for (i
= 0; i
< array_size(vtysh_client
); i
++)
2950 if (vtysh_client
[i
].fd
>= 0)
2951 vty_out(vty
, " %s", vtysh_client
[i
].name
);
2957 /* Execute command in child process. */
2958 static void execute_command(const char *command
, int argc
, const char *arg1
,
2968 /* Failure of fork(). */
2969 fprintf(stderr
, "Can't fork: %s\n", safe_strerror(errno
));
2971 } else if (pid
== 0) {
2972 /* This is child process. */
2975 execlp(command
, command
, (const char *)NULL
);
2978 execlp(command
, command
, arg1
, (const char *)NULL
);
2981 execlp(command
, command
, arg1
, arg2
,
2982 (const char *)NULL
);
2986 /* When execlp suceed, this part is not executed. */
2987 fprintf(stderr
, "Can't execute %s: %s\n", command
,
2988 safe_strerror(errno
));
2991 /* This is parent. */
2993 wait4(pid
, &status
, 0, NULL
);
3001 "Send echo messages\n"
3002 "Ping destination address or hostname\n")
3006 argv_find(argv
, argc
, "WORD", &idx
);
3007 execute_command("ping", 1, argv
[idx
]->arg
, NULL
);
3011 ALIAS(vtysh_ping
, vtysh_ping_ip_cmd
, "ping ip WORD",
3012 "Send echo messages\n"
3014 "Ping destination address or hostname\n")
3016 DEFUN (vtysh_traceroute
,
3017 vtysh_traceroute_cmd
,
3019 "Trace route to destination\n"
3020 "Trace route to destination address or hostname\n")
3024 argv_find(argv
, argc
, "WORD", &idx
);
3025 execute_command("traceroute", 1, argv
[idx
]->arg
, NULL
);
3029 ALIAS(vtysh_traceroute
, vtysh_traceroute_ip_cmd
, "traceroute ip WORD",
3030 "Trace route to destination\n"
3032 "Trace route to destination address or hostname\n")
3034 DEFUN (vtysh_mtrace
,
3036 "mtrace WORD [WORD]",
3037 "Multicast trace route to multicast source\n"
3038 "Multicast trace route to multicast source address\n"
3039 "Multicast trace route for multicast group address\n")
3042 execute_command("mtracebis", 1, argv
[1]->arg
, NULL
);
3044 execute_command("mtracebis", 2, argv
[1]->arg
, argv
[2]->arg
);
3051 "Send echo messages\n"
3053 "Ping destination address or hostname\n")
3055 execute_command("ping6", 1, argv
[2]->arg
, NULL
);
3059 DEFUN (vtysh_traceroute6
,
3060 vtysh_traceroute6_cmd
,
3061 "traceroute ipv6 WORD",
3062 "Trace route to destination\n"
3064 "Trace route to destination address or hostname\n")
3066 execute_command("traceroute6", 1, argv
[2]->arg
, NULL
);
3070 #if defined(HAVE_SHELL_ACCESS)
3071 DEFUN (vtysh_telnet
,
3074 "Open a telnet connection\n"
3075 "IP address or hostname of a remote system\n")
3077 execute_command("telnet", 1, argv
[1]->arg
, NULL
);
3081 DEFUN (vtysh_telnet_port
,
3082 vtysh_telnet_port_cmd
,
3084 "Open a telnet connection\n"
3085 "IP address or hostname of a remote system\n"
3086 "TCP Port number\n")
3088 execute_command("telnet", 2, argv
[1]->arg
, argv
[2]->arg
);
3095 "Open an ssh connection\n"
3098 execute_command("ssh", 1, argv
[1]->arg
, NULL
);
3102 DEFUN (vtysh_start_shell
,
3103 vtysh_start_shell_cmd
,
3105 "Start UNIX shell\n")
3107 execute_command("sh", 0, NULL
, NULL
);
3111 DEFUN (vtysh_start_bash
,
3112 vtysh_start_bash_cmd
,
3114 "Start UNIX shell\n"
3117 execute_command("bash", 0, NULL
, NULL
);
3121 DEFUN (vtysh_start_zsh
,
3122 vtysh_start_zsh_cmd
,
3124 "Start UNIX shell\n"
3127 execute_command("zsh", 0, NULL
, NULL
);
3134 "list [permutations]",
3135 "Print command list\n"
3136 "Print all possible command permutations\n")
3138 return cmd_list_cmds(vty
, argc
== 2);
3141 DEFUN (vtysh_output_file
,
3142 vtysh_output_file_cmd
,
3144 "Direct vtysh output to file\n"
3145 "Direct vtysh output to file\n"
3146 "Path to dump output to\n")
3148 const char *path
= argv
[argc
- 1]->arg
;
3149 vty
->of
= fopen(path
, "a");
3151 vty_out(vty
, "Failed to open file '%s': %s\n", path
,
3152 safe_strerror(errno
));
3158 DEFUN (no_vtysh_output_file
,
3159 no_vtysh_output_file_cmd
,
3160 "no output file [FILE]",
3162 "Direct vtysh output to file\n"
3163 "Direct vtysh output to file\n"
3164 "Path to dump output to\n")
3166 if (vty
->of
!= stdout
) {
3176 "Find CLI command containing text\n"
3177 "Text to search for\n")
3179 char *text
= argv_concat(argv
, argc
, 1);
3180 const struct cmd_node
*node
;
3181 const struct cmd_element
*cli
;
3184 for (unsigned int i
= 0; i
< vector_active(cmdvec
); i
++) {
3185 node
= vector_slot(cmdvec
, i
);
3188 clis
= node
->cmd_vector
;
3189 for (unsigned int j
= 0; j
< vector_active(clis
); j
++) {
3190 cli
= vector_slot(clis
, j
);
3191 if (strcasestr(cli
->string
, text
))
3192 vty_out(vty
, " (%s) %s\n",
3193 node_names
[node
->node
], cli
->string
);
3197 XFREE(MTYPE_TMP
, text
);
3202 DEFUN_HIDDEN(show_cli_graph_vtysh
,
3203 show_cli_graph_vtysh_cmd
,
3207 "Dump current command space as DOT graph\n")
3209 struct cmd_node
*cn
= vector_slot(cmdvec
, vty
->node
);
3210 char *dot
= cmd_graph_dump_dot(cn
->cmdgraph
);
3212 vty_out(vty
, "%s\n", dot
);
3213 XFREE(MTYPE_TMP
, dot
);
3217 static void vtysh_install_default(enum node_type node
)
3219 install_element(node
, &config_list_cmd
);
3220 install_element(node
, &find_cmd
);
3221 install_element(node
, &show_cli_graph_vtysh_cmd
);
3222 install_element(node
, &vtysh_output_file_cmd
);
3223 install_element(node
, &no_vtysh_output_file_cmd
);
3226 /* Making connection to protocol daemon. */
3227 static int vtysh_connect(struct vtysh_client
*vclient
)
3231 struct sockaddr_un addr
;
3235 if (!vclient
->path
[0])
3236 snprintf(vclient
->path
, sizeof(vclient
->path
), "%s/%s.vty",
3237 vtydir
, vclient
->name
);
3238 path
= vclient
->path
;
3240 /* Stat socket to see if we have permission to access it. */
3241 ret
= stat(path
, &s_stat
);
3242 if (ret
< 0 && errno
!= ENOENT
) {
3243 fprintf(stderr
, "vtysh_connect(%s): stat = %s\n", path
,
3244 safe_strerror(errno
));
3249 if (!S_ISSOCK(s_stat
.st_mode
)) {
3250 fprintf(stderr
, "vtysh_connect(%s): Not a socket\n",
3256 sock
= socket(AF_UNIX
, SOCK_STREAM
, 0);
3259 fprintf(stderr
, "vtysh_connect(%s): socket = %s\n", path
,
3260 safe_strerror(errno
));
3265 memset(&addr
, 0, sizeof(struct sockaddr_un
));
3266 addr
.sun_family
= AF_UNIX
;
3267 strlcpy(addr
.sun_path
, path
, sizeof(addr
.sun_path
));
3268 #ifdef HAVE_STRUCT_SOCKADDR_UN_SUN_LEN
3269 len
= addr
.sun_len
= SUN_LEN(&addr
);
3271 len
= sizeof(addr
.sun_family
) + strlen(addr
.sun_path
);
3272 #endif /* HAVE_STRUCT_SOCKADDR_UN_SUN_LEN */
3274 ret
= connect(sock
, (struct sockaddr
*)&addr
, len
);
3277 fprintf(stderr
, "vtysh_connect(%s): connect = %s\n", path
,
3278 safe_strerror(errno
));
3288 static int vtysh_reconnect(struct vtysh_client
*vclient
)
3292 fprintf(stderr
, "Warning: connecting to %s...", vclient
->name
);
3293 ret
= vtysh_connect(vclient
);
3295 fprintf(stderr
, "failed!\n");
3298 fprintf(stderr
, "success!\n");
3299 if (vtysh_client_execute(vclient
, "enable") < 0)
3301 return vtysh_execute_no_pager("end");
3304 /* Return true if str ends with suffix, else return false */
3305 static int ends_with(const char *str
, const char *suffix
)
3307 if (!str
|| !suffix
)
3309 size_t lenstr
= strlen(str
);
3310 size_t lensuffix
= strlen(suffix
);
3311 if (lensuffix
> lenstr
)
3313 return strncmp(str
+ lenstr
- lensuffix
, suffix
, lensuffix
) == 0;
3316 static void vtysh_client_sorted_insert(struct vtysh_client
*head_client
,
3317 struct vtysh_client
*client
)
3319 struct vtysh_client
*prev_node
, *current_node
;
3321 prev_node
= head_client
;
3322 current_node
= head_client
->next
;
3323 while (current_node
) {
3324 if (strcmp(current_node
->path
, client
->path
) > 0)
3327 prev_node
= current_node
;
3328 current_node
= current_node
->next
;
3330 client
->next
= current_node
;
3331 prev_node
->next
= client
;
3334 #define MAXIMUM_INSTANCES 10
3336 static void vtysh_update_all_instances(struct vtysh_client
*head_client
)
3338 struct vtysh_client
*client
;
3340 struct dirent
*file
;
3343 if (head_client
->flag
!= VTYSH_OSPFD
)
3346 /* ls vty_sock_dir and look for all files ending in .vty */
3347 dir
= opendir(vtydir
);
3349 while ((file
= readdir(dir
)) != NULL
) {
3350 if (begins_with(file
->d_name
, "ospfd-")
3351 && ends_with(file
->d_name
, ".vty")) {
3352 if (n
== MAXIMUM_INSTANCES
) {
3354 "Parsing %s, client limit(%d) reached!\n",
3358 client
= (struct vtysh_client
*)malloc(
3359 sizeof(struct vtysh_client
));
3361 client
->name
= "ospfd";
3362 client
->flag
= VTYSH_OSPFD
;
3363 snprintf(client
->path
, sizeof(client
->path
),
3364 "%s/%s", vtydir
, file
->d_name
);
3365 client
->next
= NULL
;
3366 vtysh_client_sorted_insert(head_client
, client
);
3374 static int vtysh_connect_all_instances(struct vtysh_client
*head_client
)
3376 struct vtysh_client
*client
;
3379 vtysh_update_all_instances(head_client
);
3381 client
= head_client
->next
;
3383 if (vtysh_connect(client
) == 0)
3385 client
= client
->next
;
3391 int vtysh_connect_all(const char *daemon_name
)
3397 for (i
= 0; i
< array_size(vtysh_client
); i
++) {
3399 || !strcmp(daemon_name
, vtysh_client
[i
].name
)) {
3401 if (vtysh_connect(&vtysh_client
[i
]) == 0)
3404 rc
+= vtysh_connect_all_instances(&vtysh_client
[i
]);
3408 fprintf(stderr
, "Error: no daemons match name %s!\n",
3413 /* To disable readline's filename completion. */
3414 static char *vtysh_completion_entry_function(const char *ignore
,
3420 void vtysh_readline_init(void)
3422 /* readline related settings. */
3424 rl_bind_key('?', (rl_command_func_t
*)vtysh_rl_describe
);
3425 rl_completion_entry_function
= vtysh_completion_entry_function
;
3426 rl_attempted_completion_function
= new_completion
;
3429 char *vtysh_prompt(void)
3431 static char buf
[100];
3433 snprintf(buf
, sizeof buf
, cmd_prompt(vty
->node
), cmd_hostname_get());
3437 static void vtysh_ac_line(void *arg
, const char *line
)
3441 for (i
= 0; i
< vector_active(comps
); i
++)
3442 if (!strcmp(line
, (char *)vector_slot(comps
, i
)))
3444 vector_set(comps
, XSTRDUP(MTYPE_COMPLETION
, line
));
3447 static void vtysh_autocomplete(vector comps
, struct cmd_token
*token
)
3452 snprintf(accmd
, sizeof(accmd
), "autocomplete %d %s %s", token
->type
,
3453 token
->text
, token
->varname
? token
->varname
: "-");
3455 vty
->of_saved
= vty
->of
;
3457 for (i
= 0; i
< array_size(vtysh_client
); i
++)
3458 vtysh_client_run_all(&vtysh_client
[i
], accmd
, 1, vtysh_ac_line
,
3460 vty
->of
= vty
->of_saved
;
3463 static const struct cmd_variable_handler vtysh_var_handler
[] = {
3467 .completions
= vtysh_autocomplete
},
3468 {.completions
= NULL
}};
3470 void vtysh_uninit(void)
3472 if (vty
->of
!= stdout
)
3476 void vtysh_init_vty(void)
3478 /* Make vty structure. */
3480 vty
->type
= VTY_SHELL
;
3481 vty
->node
= VIEW_NODE
;
3483 /* set default output */
3485 vtysh_pager_envdef(false);
3487 /* Initialize commands. */
3489 cmd_variable_handler_register(vtysh_var_handler
);
3491 /* Install nodes. */
3492 install_node(&bgp_node
, NULL
);
3493 install_node(&rip_node
, NULL
);
3494 install_node(&interface_node
, NULL
);
3495 install_node(&pw_node
, NULL
);
3496 install_node(&link_params_node
, NULL
);
3497 install_node(&logicalrouter_node
, NULL
);
3498 install_node(&vrf_node
, NULL
);
3499 install_node(&nh_group_node
, NULL
);
3500 install_node(&rmap_node
, NULL
);
3501 install_node(&pbr_map_node
, NULL
);
3502 install_node(&zebra_node
, NULL
);
3503 install_node(&bgp_vpnv4_node
, NULL
);
3504 install_node(&bgp_vpnv6_node
, NULL
);
3505 install_node(&bgp_flowspecv4_node
, NULL
);
3506 install_node(&bgp_flowspecv6_node
, NULL
);
3507 install_node(&bgp_ipv4_node
, NULL
);
3508 install_node(&bgp_ipv4m_node
, NULL
);
3509 install_node(&bgp_ipv4l_node
, NULL
);
3510 install_node(&bgp_ipv6_node
, NULL
);
3511 install_node(&bgp_ipv6m_node
, NULL
);
3512 install_node(&bgp_ipv6l_node
, NULL
);
3513 install_node(&bgp_vrf_policy_node
, NULL
);
3514 install_node(&bgp_evpn_node
, NULL
);
3515 install_node(&bgp_evpn_vni_node
, NULL
);
3516 install_node(&bgp_vnc_defaults_node
, NULL
);
3517 install_node(&bgp_vnc_nve_group_node
, NULL
);
3518 install_node(&bgp_vnc_l2_group_node
, NULL
);
3519 install_node(&ospf_node
, NULL
);
3520 install_node(&eigrp_node
, NULL
);
3521 install_node(&babel_node
, NULL
);
3522 install_node(&ripng_node
, NULL
);
3523 install_node(&ospf6_node
, NULL
);
3524 install_node(&ldp_node
, NULL
);
3525 install_node(&ldp_ipv4_node
, NULL
);
3526 install_node(&ldp_ipv6_node
, NULL
);
3527 install_node(&ldp_ipv4_iface_node
, NULL
);
3528 install_node(&ldp_ipv6_iface_node
, NULL
);
3529 install_node(&ldp_l2vpn_node
, NULL
);
3530 install_node(&ldp_pseudowire_node
, NULL
);
3531 install_node(&keychain_node
, NULL
);
3532 install_node(&keychain_key_node
, NULL
);
3533 install_node(&isis_node
, NULL
);
3534 install_node(&openfabric_node
, NULL
);
3535 install_node(&vty_node
, NULL
);
3536 install_node(&rpki_node
, NULL
);
3538 install_node(&bfd_node
, NULL
);
3539 install_node(&bfd_peer_node
, NULL
);
3540 #endif /* HAVE_BFDD */
3542 struct cmd_node
*node
;
3543 for (unsigned int i
= 0; i
< vector_active(cmdvec
); i
++) {
3544 node
= vector_slot(cmdvec
, i
);
3545 if (!node
|| node
->node
== VIEW_NODE
)
3547 vtysh_install_default(node
->node
);
3550 install_element(VIEW_NODE
, &vtysh_enable_cmd
);
3551 install_element(ENABLE_NODE
, &vtysh_config_terminal_cmd
);
3552 install_element(ENABLE_NODE
, &vtysh_disable_cmd
);
3554 /* "exit" command. */
3555 install_element(VIEW_NODE
, &vtysh_exit_all_cmd
);
3556 install_element(CONFIG_NODE
, &vtysh_exit_all_cmd
);
3557 install_element(VIEW_NODE
, &vtysh_quit_all_cmd
);
3558 install_element(CONFIG_NODE
, &vtysh_quit_all_cmd
);
3559 install_element(RIP_NODE
, &vtysh_exit_ripd_cmd
);
3560 install_element(RIP_NODE
, &vtysh_quit_ripd_cmd
);
3561 install_element(RIPNG_NODE
, &vtysh_exit_ripngd_cmd
);
3562 install_element(RIPNG_NODE
, &vtysh_quit_ripngd_cmd
);
3563 install_element(OSPF_NODE
, &vtysh_exit_ospfd_cmd
);
3564 install_element(OSPF_NODE
, &vtysh_quit_ospfd_cmd
);
3565 install_element(EIGRP_NODE
, &vtysh_exit_eigrpd_cmd
);
3566 install_element(EIGRP_NODE
, &vtysh_quit_eigrpd_cmd
);
3567 install_element(BABEL_NODE
, &vtysh_exit_babeld_cmd
);
3568 install_element(BABEL_NODE
, &vtysh_quit_babeld_cmd
);
3569 install_element(OSPF6_NODE
, &vtysh_exit_ospf6d_cmd
);
3570 install_element(OSPF6_NODE
, &vtysh_quit_ospf6d_cmd
);
3571 #if defined(HAVE_LDPD)
3572 install_element(LDP_NODE
, &vtysh_exit_ldpd_cmd
);
3573 install_element(LDP_NODE
, &vtysh_quit_ldpd_cmd
);
3574 install_element(LDP_IPV4_NODE
, &vtysh_exit_ldpd_cmd
);
3575 install_element(LDP_IPV4_NODE
, &vtysh_quit_ldpd_cmd
);
3576 install_element(LDP_IPV4_NODE
, &ldp_exit_address_family_cmd
);
3577 install_element(LDP_IPV6_NODE
, &vtysh_exit_ldpd_cmd
);
3578 install_element(LDP_IPV6_NODE
, &vtysh_quit_ldpd_cmd
);
3579 install_element(LDP_IPV6_NODE
, &ldp_exit_address_family_cmd
);
3580 install_element(LDP_IPV4_IFACE_NODE
, &vtysh_exit_ldpd_cmd
);
3581 install_element(LDP_IPV4_IFACE_NODE
, &vtysh_quit_ldpd_cmd
);
3582 install_element(LDP_IPV6_IFACE_NODE
, &vtysh_exit_ldpd_cmd
);
3583 install_element(LDP_IPV6_IFACE_NODE
, &vtysh_quit_ldpd_cmd
);
3584 install_element(LDP_L2VPN_NODE
, &vtysh_exit_ldpd_cmd
);
3585 install_element(LDP_L2VPN_NODE
, &vtysh_quit_ldpd_cmd
);
3586 install_element(LDP_PSEUDOWIRE_NODE
, &vtysh_exit_ldpd_cmd
);
3587 install_element(LDP_PSEUDOWIRE_NODE
, &vtysh_quit_ldpd_cmd
);
3589 install_element(BGP_NODE
, &vtysh_exit_bgpd_cmd
);
3590 install_element(BGP_NODE
, &vtysh_quit_bgpd_cmd
);
3591 install_element(BGP_VPNV4_NODE
, &vtysh_exit_bgpd_cmd
);
3592 install_element(BGP_VPNV4_NODE
, &vtysh_quit_bgpd_cmd
);
3593 install_element(BGP_VPNV6_NODE
, &vtysh_exit_bgpd_cmd
);
3594 install_element(BGP_VPNV6_NODE
, &vtysh_quit_bgpd_cmd
);
3595 install_element(BGP_FLOWSPECV4_NODE
, &vtysh_exit_bgpd_cmd
);
3596 install_element(BGP_FLOWSPECV4_NODE
, &vtysh_quit_bgpd_cmd
);
3597 install_element(BGP_FLOWSPECV6_NODE
, &vtysh_exit_bgpd_cmd
);
3598 install_element(BGP_FLOWSPECV6_NODE
, &vtysh_quit_bgpd_cmd
);
3599 install_element(BGP_IPV4_NODE
, &vtysh_exit_bgpd_cmd
);
3600 install_element(BGP_IPV4_NODE
, &vtysh_quit_bgpd_cmd
);
3601 install_element(BGP_IPV4M_NODE
, &vtysh_exit_bgpd_cmd
);
3602 install_element(BGP_IPV4M_NODE
, &vtysh_quit_bgpd_cmd
);
3603 install_element(BGP_IPV4L_NODE
, &vtysh_exit_bgpd_cmd
);
3604 install_element(BGP_IPV4L_NODE
, &vtysh_quit_bgpd_cmd
);
3605 install_element(BGP_IPV6_NODE
, &vtysh_exit_bgpd_cmd
);
3606 install_element(BGP_IPV6_NODE
, &vtysh_quit_bgpd_cmd
);
3607 install_element(BGP_IPV6M_NODE
, &vtysh_exit_bgpd_cmd
);
3608 install_element(BGP_IPV6M_NODE
, &vtysh_quit_bgpd_cmd
);
3609 install_element(BGP_EVPN_NODE
, &vtysh_quit_bgpd_cmd
);
3610 install_element(BGP_EVPN_NODE
, &vtysh_exit_bgpd_cmd
);
3611 install_element(BGP_EVPN_VNI_NODE
, &vtysh_exit_bgpd_cmd
);
3612 install_element(BGP_EVPN_VNI_NODE
, &vtysh_quit_bgpd_cmd
);
3613 install_element(BGP_IPV6L_NODE
, &vtysh_exit_bgpd_cmd
);
3614 install_element(BGP_IPV6L_NODE
, &vtysh_quit_bgpd_cmd
);
3615 #if defined(ENABLE_BGP_VNC)
3616 install_element(BGP_VRF_POLICY_NODE
, &vtysh_exit_bgpd_cmd
);
3617 install_element(BGP_VRF_POLICY_NODE
, &vtysh_quit_bgpd_cmd
);
3618 install_element(BGP_VNC_DEFAULTS_NODE
, &vtysh_exit_bgpd_cmd
);
3619 install_element(BGP_VNC_DEFAULTS_NODE
, &vtysh_quit_bgpd_cmd
);
3620 install_element(BGP_VNC_NVE_GROUP_NODE
, &vtysh_exit_bgpd_cmd
);
3621 install_element(BGP_VNC_NVE_GROUP_NODE
, &vtysh_quit_bgpd_cmd
);
3622 install_element(BGP_VNC_L2_GROUP_NODE
, &vtysh_exit_bgpd_cmd
);
3623 install_element(BGP_VNC_L2_GROUP_NODE
, &vtysh_quit_bgpd_cmd
);
3625 install_element(ISIS_NODE
, &vtysh_exit_isisd_cmd
);
3626 install_element(ISIS_NODE
, &vtysh_quit_isisd_cmd
);
3627 install_element(OPENFABRIC_NODE
, &vtysh_exit_fabricd_cmd
);
3628 install_element(OPENFABRIC_NODE
, &vtysh_quit_fabricd_cmd
);
3629 install_element(KEYCHAIN_NODE
, &vtysh_exit_ripd_cmd
);
3630 install_element(KEYCHAIN_NODE
, &vtysh_quit_ripd_cmd
);
3631 install_element(KEYCHAIN_KEY_NODE
, &vtysh_exit_ripd_cmd
);
3632 install_element(KEYCHAIN_KEY_NODE
, &vtysh_quit_ripd_cmd
);
3633 install_element(RMAP_NODE
, &vtysh_exit_rmap_cmd
);
3634 install_element(RMAP_NODE
, &vtysh_quit_rmap_cmd
);
3635 install_element(PBRMAP_NODE
, &vtysh_exit_pbr_map_cmd
);
3636 install_element(PBRMAP_NODE
, &vtysh_quit_pbr_map_cmd
);
3639 install_element(CONFIG_NODE
, &bfd_enter_cmd
);
3640 install_element(BFD_NODE
, &bfd_peer_enter_cmd
);
3642 /* Exit/quit node. */
3643 install_element(BFD_NODE
, &vtysh_exit_bfdd_cmd
);
3644 install_element(BFD_NODE
, &vtysh_quit_bfdd_cmd
);
3645 install_element(BFD_PEER_NODE
, &vtysh_exit_bfdd_cmd
);
3646 install_element(BFD_PEER_NODE
, &vtysh_quit_bfdd_cmd
);
3649 install_element(BFD_NODE
, &vtysh_end_all_cmd
);
3650 install_element(BFD_PEER_NODE
, &vtysh_end_all_cmd
);
3651 #endif /* HAVE_BFDD */
3652 install_element(VTY_NODE
, &vtysh_exit_line_vty_cmd
);
3653 install_element(VTY_NODE
, &vtysh_quit_line_vty_cmd
);
3655 /* "end" command. */
3656 install_element(CONFIG_NODE
, &vtysh_end_all_cmd
);
3657 install_element(ENABLE_NODE
, &vtysh_end_all_cmd
);
3658 install_element(RIP_NODE
, &vtysh_end_all_cmd
);
3659 install_element(RIPNG_NODE
, &vtysh_end_all_cmd
);
3660 install_element(OSPF_NODE
, &vtysh_end_all_cmd
);
3661 install_element(EIGRP_NODE
, &vtysh_end_all_cmd
);
3662 install_element(BABEL_NODE
, &vtysh_end_all_cmd
);
3663 install_element(OSPF6_NODE
, &vtysh_end_all_cmd
);
3664 install_element(LDP_NODE
, &vtysh_end_all_cmd
);
3665 install_element(LDP_IPV4_NODE
, &vtysh_end_all_cmd
);
3666 install_element(LDP_IPV6_NODE
, &vtysh_end_all_cmd
);
3667 install_element(LDP_IPV4_IFACE_NODE
, &vtysh_end_all_cmd
);
3668 install_element(LDP_IPV6_IFACE_NODE
, &vtysh_end_all_cmd
);
3669 install_element(LDP_L2VPN_NODE
, &vtysh_end_all_cmd
);
3670 install_element(LDP_PSEUDOWIRE_NODE
, &vtysh_end_all_cmd
);
3671 install_element(BGP_NODE
, &vtysh_end_all_cmd
);
3672 install_element(BGP_IPV4_NODE
, &vtysh_end_all_cmd
);
3673 install_element(BGP_IPV4M_NODE
, &vtysh_end_all_cmd
);
3674 install_element(BGP_IPV4L_NODE
, &vtysh_end_all_cmd
);
3675 install_element(BGP_VPNV4_NODE
, &vtysh_end_all_cmd
);
3676 install_element(BGP_VPNV6_NODE
, &vtysh_end_all_cmd
);
3677 install_element(BGP_FLOWSPECV4_NODE
, &vtysh_end_all_cmd
);
3678 install_element(BGP_FLOWSPECV6_NODE
, &vtysh_end_all_cmd
);
3679 install_element(BGP_IPV6_NODE
, &vtysh_end_all_cmd
);
3680 install_element(BGP_IPV6M_NODE
, &vtysh_end_all_cmd
);
3681 install_element(BGP_IPV6L_NODE
, &vtysh_end_all_cmd
);
3682 install_element(BGP_VRF_POLICY_NODE
, &vtysh_end_all_cmd
);
3683 install_element(BGP_EVPN_NODE
, &vtysh_end_all_cmd
);
3684 install_element(BGP_EVPN_VNI_NODE
, &vtysh_end_all_cmd
);
3685 install_element(BGP_VNC_DEFAULTS_NODE
, &vtysh_end_all_cmd
);
3686 install_element(BGP_VNC_NVE_GROUP_NODE
, &vtysh_end_all_cmd
);
3687 install_element(BGP_VNC_L2_GROUP_NODE
, &vtysh_end_all_cmd
);
3688 install_element(ISIS_NODE
, &vtysh_end_all_cmd
);
3689 install_element(OPENFABRIC_NODE
, &vtysh_end_all_cmd
);
3690 install_element(KEYCHAIN_NODE
, &vtysh_end_all_cmd
);
3691 install_element(KEYCHAIN_KEY_NODE
, &vtysh_end_all_cmd
);
3692 install_element(RMAP_NODE
, &vtysh_end_all_cmd
);
3693 install_element(PBRMAP_NODE
, &vtysh_end_all_cmd
);
3694 install_element(VTY_NODE
, &vtysh_end_all_cmd
);
3696 install_element(INTERFACE_NODE
, &vtysh_end_all_cmd
);
3697 install_element(INTERFACE_NODE
, &vtysh_exit_interface_cmd
);
3698 install_element(LINK_PARAMS_NODE
, &exit_link_params_cmd
);
3699 install_element(LINK_PARAMS_NODE
, &vtysh_end_all_cmd
);
3700 install_element(LINK_PARAMS_NODE
, &vtysh_exit_interface_cmd
);
3701 install_element(INTERFACE_NODE
, &vtysh_quit_interface_cmd
);
3703 install_element(PW_NODE
, &vtysh_end_all_cmd
);
3704 install_element(PW_NODE
, &vtysh_exit_interface_cmd
);
3705 install_element(PW_NODE
, &vtysh_quit_interface_cmd
);
3707 install_element(LOGICALROUTER_NODE
, &vtysh_end_all_cmd
);
3709 install_element(CONFIG_NODE
, &vtysh_logicalrouter_cmd
);
3710 install_element(CONFIG_NODE
, &vtysh_no_logicalrouter_cmd
);
3711 install_element(LOGICALROUTER_NODE
, &vtysh_exit_logicalrouter_cmd
);
3712 install_element(LOGICALROUTER_NODE
, &vtysh_quit_logicalrouter_cmd
);
3714 install_element(CONFIG_NODE
, &vtysh_nexthop_group_cmd
);
3715 install_element(NH_GROUP_NODE
, &vtysh_end_all_cmd
);
3716 install_element(NH_GROUP_NODE
, &vtysh_exit_nexthop_group_cmd
);
3717 install_element(NH_GROUP_NODE
, &vtysh_quit_nexthop_group_cmd
);
3719 install_element(VRF_NODE
, &vtysh_end_all_cmd
);
3720 install_element(VRF_NODE
, &vtysh_exit_vrf_cmd
);
3721 install_element(VRF_NODE
, &vtysh_quit_vrf_cmd
);
3723 install_element(CONFIG_NODE
, &router_eigrp_cmd
);
3724 install_element(CONFIG_NODE
, &router_babel_cmd
);
3725 install_element(CONFIG_NODE
, &router_rip_cmd
);
3726 install_element(CONFIG_NODE
, &router_ripng_cmd
);
3727 install_element(CONFIG_NODE
, &router_ospf_cmd
);
3728 install_element(CONFIG_NODE
, &router_ospf6_cmd
);
3729 #if defined(HAVE_LDPD)
3730 install_element(CONFIG_NODE
, &ldp_mpls_ldp_cmd
);
3731 install_element(LDP_NODE
, &ldp_address_family_ipv4_cmd
);
3732 install_element(LDP_NODE
, &ldp_address_family_ipv6_cmd
);
3733 install_element(LDP_IPV4_NODE
, &ldp_interface_ifname_cmd
);
3734 install_element(LDP_IPV6_NODE
, &ldp_interface_ifname_cmd
);
3735 install_element(CONFIG_NODE
, &ldp_l2vpn_word_type_vpls_cmd
);
3736 install_element(LDP_L2VPN_NODE
, &ldp_member_pseudowire_ifname_cmd
);
3738 install_element(CONFIG_NODE
, &router_isis_cmd
);
3739 install_element(CONFIG_NODE
, &router_openfabric_cmd
);
3740 install_element(CONFIG_NODE
, &router_bgp_cmd
);
3741 #ifdef KEEP_OLD_VPN_COMMANDS
3742 install_element(BGP_NODE
, &address_family_vpnv4_cmd
);
3743 install_element(BGP_NODE
, &address_family_vpnv6_cmd
);
3744 #endif /* KEEP_OLD_VPN_COMMANDS */
3745 #if defined(ENABLE_BGP_VNC)
3746 install_element(BGP_NODE
, &vnc_vrf_policy_cmd
);
3747 install_element(BGP_NODE
, &vnc_defaults_cmd
);
3748 install_element(BGP_NODE
, &vnc_nve_group_cmd
);
3749 install_element(BGP_NODE
, &vnc_l2_group_cmd
);
3751 install_element(BGP_NODE
, &address_family_ipv4_cmd
);
3752 install_element(BGP_NODE
, &address_family_ipv4_multicast_cmd
);
3753 install_element(BGP_NODE
, &address_family_ipv4_vpn_cmd
);
3754 install_element(BGP_NODE
, &address_family_ipv4_labeled_unicast_cmd
);
3755 install_element(BGP_NODE
, &address_family_ipv6_cmd
);
3756 install_element(BGP_NODE
, &address_family_ipv6_multicast_cmd
);
3757 install_element(BGP_NODE
, &address_family_ipv6_vpn_cmd
);
3758 install_element(BGP_NODE
, &address_family_ipv6_labeled_unicast_cmd
);
3759 install_element(BGP_NODE
, &address_family_evpn_cmd
);
3760 install_element(BGP_NODE
, &address_family_flowspecv4_cmd
);
3761 install_element(BGP_NODE
, &address_family_flowspecv6_cmd
);
3762 #if defined(HAVE_CUMULUS)
3763 install_element(BGP_NODE
, &address_family_evpn2_cmd
);
3765 install_element(BGP_VPNV4_NODE
, &exit_address_family_cmd
);
3766 install_element(BGP_VPNV6_NODE
, &exit_address_family_cmd
);
3767 install_element(BGP_IPV4_NODE
, &exit_address_family_cmd
);
3768 install_element(BGP_IPV4M_NODE
, &exit_address_family_cmd
);
3769 install_element(BGP_IPV4L_NODE
, &exit_address_family_cmd
);
3770 install_element(BGP_IPV6_NODE
, &exit_address_family_cmd
);
3771 install_element(BGP_IPV6M_NODE
, &exit_address_family_cmd
);
3772 install_element(BGP_EVPN_NODE
, &exit_address_family_cmd
);
3773 install_element(BGP_IPV6L_NODE
, &exit_address_family_cmd
);
3774 install_element(BGP_FLOWSPECV4_NODE
, &exit_address_family_cmd
);
3775 install_element(BGP_FLOWSPECV6_NODE
, &exit_address_family_cmd
);
3777 install_element(CONFIG_NODE
, &rpki_cmd
);
3778 install_element(RPKI_NODE
, &rpki_exit_cmd
);
3779 install_element(RPKI_NODE
, &rpki_quit_cmd
);
3780 install_element(RPKI_NODE
, &vtysh_end_all_cmd
);
3783 install_element(BGP_EVPN_NODE
, &bgp_evpn_vni_cmd
);
3784 install_element(BGP_EVPN_VNI_NODE
, &exit_vni_cmd
);
3786 install_element(BGP_VRF_POLICY_NODE
, &exit_vrf_policy_cmd
);
3787 install_element(BGP_VNC_DEFAULTS_NODE
, &exit_vnc_config_cmd
);
3788 install_element(BGP_VNC_NVE_GROUP_NODE
, &exit_vnc_config_cmd
);
3789 install_element(BGP_VNC_L2_GROUP_NODE
, &exit_vnc_config_cmd
);
3791 install_element(CONFIG_NODE
, &key_chain_cmd
);
3792 install_element(CONFIG_NODE
, &vtysh_route_map_cmd
);
3793 install_element(CONFIG_NODE
, &vtysh_pbr_map_cmd
);
3794 install_element(CONFIG_NODE
, &vtysh_no_pbr_map_cmd
);
3795 install_element(CONFIG_NODE
, &vtysh_line_vty_cmd
);
3796 install_element(KEYCHAIN_NODE
, &key_cmd
);
3797 install_element(KEYCHAIN_NODE
, &key_chain_cmd
);
3798 install_element(KEYCHAIN_KEY_NODE
, &key_chain_cmd
);
3799 install_element(CONFIG_NODE
, &vtysh_interface_cmd
);
3800 install_element(CONFIG_NODE
, &vtysh_pseudowire_cmd
);
3801 install_element(INTERFACE_NODE
, &vtysh_link_params_cmd
);
3802 install_element(ENABLE_NODE
, &vtysh_show_running_config_cmd
);
3803 install_element(ENABLE_NODE
, &vtysh_copy_running_config_cmd
);
3805 install_element(CONFIG_NODE
, &vtysh_vrf_cmd
);
3806 install_element(VRF_NODE
, &vtysh_vrf_netns_cmd
);
3807 install_element(VRF_NODE
, &vtysh_no_vrf_netns_cmd
);
3808 install_element(VRF_NODE
, &exit_vrf_config_cmd
);
3810 install_element(CONFIG_NODE
, &vtysh_no_nexthop_group_cmd
);
3812 /* "write terminal" command. */
3813 install_element(ENABLE_NODE
, &vtysh_write_terminal_cmd
);
3815 install_element(CONFIG_NODE
, &vtysh_integrated_config_cmd
);
3816 install_element(CONFIG_NODE
, &no_vtysh_integrated_config_cmd
);
3818 /* "write memory" command. */
3819 install_element(ENABLE_NODE
, &vtysh_write_memory_cmd
);
3821 install_element(CONFIG_NODE
, &vtysh_terminal_paginate_cmd
);
3822 install_element(VIEW_NODE
, &vtysh_terminal_paginate_cmd
);
3823 install_element(VIEW_NODE
, &vtysh_terminal_length_cmd
);
3824 install_element(VIEW_NODE
, &vtysh_terminal_no_length_cmd
);
3825 install_element(VIEW_NODE
, &vtysh_show_daemons_cmd
);
3827 install_element(VIEW_NODE
, &vtysh_ping_cmd
);
3828 install_element(VIEW_NODE
, &vtysh_ping_ip_cmd
);
3829 install_element(VIEW_NODE
, &vtysh_traceroute_cmd
);
3830 install_element(VIEW_NODE
, &vtysh_traceroute_ip_cmd
);
3831 install_element(VIEW_NODE
, &vtysh_mtrace_cmd
);
3832 install_element(VIEW_NODE
, &vtysh_ping6_cmd
);
3833 install_element(VIEW_NODE
, &vtysh_traceroute6_cmd
);
3834 #if defined(HAVE_SHELL_ACCESS)
3835 install_element(VIEW_NODE
, &vtysh_telnet_cmd
);
3836 install_element(VIEW_NODE
, &vtysh_telnet_port_cmd
);
3837 install_element(VIEW_NODE
, &vtysh_ssh_cmd
);
3839 #if defined(HAVE_SHELL_ACCESS)
3840 install_element(ENABLE_NODE
, &vtysh_start_shell_cmd
);
3841 install_element(ENABLE_NODE
, &vtysh_start_bash_cmd
);
3842 install_element(ENABLE_NODE
, &vtysh_start_zsh_cmd
);
3846 install_element(VIEW_NODE
, &vtysh_show_debugging_cmd
);
3847 install_element(VIEW_NODE
, &vtysh_show_error_code_cmd
);
3848 install_element(VIEW_NODE
, &vtysh_show_debugging_hashtable_cmd
);
3849 install_element(ENABLE_NODE
, &vtysh_debug_all_cmd
);
3850 install_element(CONFIG_NODE
, &vtysh_debug_all_cmd
);
3852 /* misc lib show commands */
3853 install_element(VIEW_NODE
, &vtysh_show_memory_cmd
);
3854 install_element(VIEW_NODE
, &vtysh_show_modules_cmd
);
3855 install_element(VIEW_NODE
, &vtysh_show_work_queues_cmd
);
3856 install_element(VIEW_NODE
, &vtysh_show_work_queues_daemon_cmd
);
3857 install_element(VIEW_NODE
, &vtysh_show_thread_cmd
);
3858 install_element(VIEW_NODE
, &vtysh_show_poll_cmd
);
3861 install_element(VIEW_NODE
, &vtysh_show_logging_cmd
);
3862 install_element(CONFIG_NODE
, &vtysh_log_stdout_cmd
);
3863 install_element(CONFIG_NODE
, &vtysh_log_stdout_level_cmd
);
3864 install_element(CONFIG_NODE
, &no_vtysh_log_stdout_cmd
);
3865 install_element(CONFIG_NODE
, &vtysh_log_file_cmd
);
3866 install_element(CONFIG_NODE
, &vtysh_log_file_level_cmd
);
3867 install_element(CONFIG_NODE
, &no_vtysh_log_file_cmd
);
3868 install_element(CONFIG_NODE
, &vtysh_log_monitor_cmd
);
3869 install_element(CONFIG_NODE
, &no_vtysh_log_monitor_cmd
);
3870 install_element(CONFIG_NODE
, &vtysh_log_syslog_cmd
);
3871 install_element(CONFIG_NODE
, &no_vtysh_log_syslog_cmd
);
3872 install_element(CONFIG_NODE
, &vtysh_log_facility_cmd
);
3873 install_element(CONFIG_NODE
, &no_vtysh_log_facility_cmd
);
3874 install_element(CONFIG_NODE
, &vtysh_log_record_priority_cmd
);
3875 install_element(CONFIG_NODE
, &no_vtysh_log_record_priority_cmd
);
3876 install_element(CONFIG_NODE
, &vtysh_log_timestamp_precision_cmd
);
3877 install_element(CONFIG_NODE
, &no_vtysh_log_timestamp_precision_cmd
);
3879 install_element(CONFIG_NODE
, &vtysh_service_password_encrypt_cmd
);
3880 install_element(CONFIG_NODE
, &no_vtysh_service_password_encrypt_cmd
);
3882 install_element(CONFIG_NODE
, &vtysh_password_cmd
);
3883 install_element(CONFIG_NODE
, &no_vtysh_password_cmd
);
3884 install_element(CONFIG_NODE
, &vtysh_enable_password_cmd
);
3885 install_element(CONFIG_NODE
, &no_vtysh_enable_password_cmd
);