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 /* readline carries some ancient definitions around */
30 #pragma GCC diagnostic push
31 #pragma GCC diagnostic ignored "-Wstrict-prototypes"
32 #include <readline/readline.h>
33 #include <readline/history.h>
34 #pragma GCC diagnostic pop
45 #include "vtysh/vtysh.h"
46 #include "vtysh/vtysh_daemons.h"
50 #include "command_graph.h"
54 #include "bgpd/bgp_vty.h"
56 DEFINE_MTYPE_STATIC(MVTYSH
, VTYSH_CMD
, "Vtysh cmd copy");
61 /* VTY shell pager name. */
62 char *vtysh_pager_name
= NULL
;
64 /* VTY should add timestamp */
65 bool vtysh_add_timestamp
;
67 /* VTY shell client structure */
72 char path
[MAXPATHLEN
];
73 struct vtysh_client
*next
;
75 struct thread
*log_reader
;
80 static bool stderr_tty
;
81 static bool stderr_stdout_same
;
83 /* Some utility functions for working on vtysh-specific vty tasks */
85 static FILE *vty_open_pager(struct vty
*vty
)
90 if (!vtysh_pager_name
)
93 vty
->of_saved
= vty
->of
;
94 vty
->of
= popen(vtysh_pager_name
, "w");
95 if (vty
->of
== NULL
) {
96 vty
->of
= vty
->of_saved
;
101 vty
->is_paged
= true;
106 static int vty_close_pager(struct vty
*vty
)
112 if (pclose(vty
->of
) == -1) {
117 vty
->of
= vty
->of_saved
;
118 vty
->is_paged
= false;
123 static void vtysh_pager_envdef(bool fallback
)
127 pager_defined
= getenv("VTYSH_PAGER");
130 vtysh_pager_name
= strdup(pager_defined
);
132 vtysh_pager_name
= strdup(VTYSH_PAGER
);
137 struct vtysh_client vtysh_client
[] = {
138 {.name
= "zebra", .flag
= VTYSH_ZEBRA
},
139 {.name
= "ripd", .flag
= VTYSH_RIPD
},
140 {.name
= "ripngd", .flag
= VTYSH_RIPNGD
},
141 {.name
= "ospfd", .flag
= VTYSH_OSPFD
},
142 {.name
= "ospf6d", .flag
= VTYSH_OSPF6D
},
143 {.name
= "ldpd", .flag
= VTYSH_LDPD
},
144 {.name
= "bgpd", .flag
= VTYSH_BGPD
},
145 {.name
= "isisd", .flag
= VTYSH_ISISD
},
146 {.name
= "pimd", .flag
= VTYSH_PIMD
},
147 {.name
= "nhrpd", .flag
= VTYSH_NHRPD
},
148 {.name
= "eigrpd", .flag
= VTYSH_EIGRPD
},
149 {.name
= "babeld", .flag
= VTYSH_BABELD
},
150 {.name
= "sharpd", .flag
= VTYSH_SHARPD
},
151 {.name
= "fabricd", .flag
= VTYSH_FABRICD
},
152 {.name
= "watchfrr", .flag
= VTYSH_WATCHFRR
},
153 {.name
= "pbrd", .flag
= VTYSH_PBRD
},
154 {.name
= "staticd", .flag
= VTYSH_STATICD
},
155 {.name
= "bfdd", .flag
= VTYSH_BFDD
},
156 {.name
= "vrrpd", .flag
= VTYSH_VRRPD
},
157 {.name
= "pathd", .flag
= VTYSH_PATHD
},
158 {.name
= "pim6d", .flag
= VTYSH_PIM6D
},
161 /* Searches for client by name, returns index */
162 static int vtysh_client_lookup(const char *name
)
166 for (unsigned int i
= 0; i
< array_size(vtysh_client
); i
++) {
167 if (strmatch(vtysh_client
[i
].name
, name
)) {
176 enum vtysh_write_integrated vtysh_write_integrated
=
177 WRITE_INTEGRATED_UNSPECIFIED
;
179 static int vtysh_reconnect(struct vtysh_client
*vclient
);
181 static void vclient_close(struct vtysh_client
*vclient
)
183 if (vclient
->fd
>= 0) {
186 "Warning: closing connection to %s because of an I/O error!\n",
189 /* indicate as candidate for reconnect */
190 vclient
->fd
= VTYSH_WAS_ACTIVE
;
194 static ssize_t
vtysh_client_receive(struct vtysh_client
*vclient
, char *buf
,
195 size_t bufsz
, int *pass_fd
)
197 struct iovec iov
[1] = {
204 uint8_t buf
[CMSG_SPACE(sizeof(int))];
205 struct cmsghdr align
;
209 .msg_iovlen
= array_size(iov
),
210 .msg_control
= u
.buf
,
211 .msg_controllen
= sizeof(u
.buf
),
213 struct cmsghdr
*cmh
= CMSG_FIRSTHDR(&mh
);
216 cmh
->cmsg_level
= SOL_SOCKET
;
217 cmh
->cmsg_type
= SCM_RIGHTS
;
218 cmh
->cmsg_len
= CMSG_LEN(sizeof(int));
219 memset(CMSG_DATA(cmh
), -1, sizeof(int));
222 ret
= recvmsg(vclient
->fd
, &mh
, 0);
223 if (ret
>= 0 || (errno
!= EINTR
&& errno
!= EAGAIN
))
227 if (cmh
->cmsg_len
== CMSG_LEN(sizeof(int))) {
230 memcpy(&fd
, CMSG_DATA(cmh
), sizeof(int));
242 * Send a CLI command to a client and read the response.
244 * Output will be printed to vty->of. If you want to suppress output, set that
248 * the client to send the command to
251 * the command to send
254 * if non-null, this will be called with each line of output received from
255 * the client passed in the second parameter
258 * optional first argument to pass to callback
263 static int vtysh_client_run(struct vtysh_client
*vclient
, const char *line
,
264 void (*callback
)(void *, const char *), void *cbarg
,
269 char *buf
= stackbuf
;
270 size_t bufsz
= sizeof(stackbuf
);
271 char *bufvalid
, *end
= NULL
;
272 char terminator
[3] = {0, 0, 0};
274 /* vclinet was previously active, try to reconnect */
275 if (vclient
->fd
== VTYSH_WAS_ACTIVE
) {
276 ret
= vtysh_reconnect(vclient
);
284 ret
= write(vclient
->fd
, line
, strlen(line
) + 1);
286 /* close connection and try to reconnect */
287 vclient_close(vclient
);
288 ret
= vtysh_reconnect(vclient
);
292 ret
= write(vclient
->fd
, line
, strlen(line
) + 1);
301 nread
= vtysh_client_receive(
302 vclient
, bufvalid
, buf
+ bufsz
- bufvalid
- 1, pass_fd
);
304 if (nread
< 0 && (errno
== EINTR
|| errno
== EAGAIN
))
310 "vtysh: error reading from %s: %s (%d)",
311 vclient
->name
, safe_strerror(errno
),
318 /* Null terminate so we may pass this to *printf later. */
322 * We expect string output from daemons, so instead of looking
323 * for the full 3 null bytes of the terminator, we check for
324 * just one instead and assume it is the first byte of the
325 * terminator. The presence of the full terminator is checked
328 if (bufvalid
- buf
>= 4)
329 end
= memmem(bufvalid
- 4, 4, "\0", 1);
332 * calculate # bytes we have, up to & not including the
333 * terminator if present
335 size_t textlen
= (end
? end
: bufvalid
) - buf
;
338 /* feed line processing callback if present */
339 while (callback
&& bufvalid
> buf
&& (end
> buf
|| !end
)) {
340 textlen
= (end
? end
: bufvalid
) - buf
;
341 char *eol
= memchr(buf
, '\n', textlen
);
347 * no line break, end of input, no text left
348 * before end; nothing to write
352 /* no nl, end of input, but some text left */
354 else if (bufvalid
== buf
+ bufsz
- 1) {
356 * no nl, no end of input, no buffer space;
362 if (buf
== stackbuf
) {
363 new = XMALLOC(MTYPE_TMP
, bufsz
);
364 memcpy(new, stackbuf
, sizeof(stackbuf
));
366 new = XREALLOC(MTYPE_TMP
, buf
, bufsz
);
368 bufvalid
= bufvalid
- buf
+ new;
370 /* if end != NULL, we won't be reading more
380 /* eol is at line end now, either \n => \0 or \0\0\0 */
381 assert(eol
&& eol
<= bufvalid
);
384 vty_out(vty
, "%s\n", buf
);
386 callback(cbarg
, buf
);
388 /* shift back data and adjust bufvalid */
389 memmove(buf
, eol
, bufvalid
- eol
);
390 bufvalid
-= eol
- buf
;
395 /* else if no callback, dump raw */
398 vty_out(vty
, "%s", buf
);
399 memmove(buf
, buf
+ textlen
, bufvalid
- buf
- textlen
);
405 * ----------------------------------------------------
406 * At this point `buf` should be in one of two states:
407 * - Empty (i.e. buf == bufvalid)
408 * - Contains up to 4 bytes of the terminator
409 * ----------------------------------------------------
411 assert(((buf
== bufvalid
)
412 || (bufvalid
- buf
<= 4 && buf
[0] == 0x00)));
415 /* if we have the terminator, break */
416 if (end
&& bufvalid
- buf
== 4) {
417 assert(!memcmp(buf
, terminator
, 3));
426 vclient_close(vclient
);
430 XFREE(MTYPE_TMP
, buf
);
434 static int vtysh_client_run_all(struct vtysh_client
*head_client
,
435 const char *line
, int continue_on_err
,
436 void (*callback
)(void *, const char *),
439 struct vtysh_client
*client
;
440 int rc
, rc_all
= CMD_SUCCESS
;
441 int correct_instance
= 0, wrong_instance
= 0;
443 for (client
= head_client
; client
; client
= client
->next
) {
444 rc
= vtysh_client_run(client
, line
, callback
, cbarg
, NULL
);
445 if (rc
== CMD_NOT_MY_INSTANCE
) {
451 if (rc
!= CMD_SUCCESS
) {
452 if (!continue_on_err
)
457 if (wrong_instance
&& !correct_instance
&& vty
->of
) {
459 "%% [%s]: command ignored as it targets an instance that is not running\n",
461 rc_all
= CMD_WARNING_CONFIG_FAILED
;
467 * Execute command against all daemons.
470 * where to start walking in the daemon list
473 * the specific command to execute
478 static int vtysh_client_execute(struct vtysh_client
*head_client
,
481 return vtysh_client_run_all(head_client
, line
, 0, NULL
, NULL
);
484 /* Execute by name */
485 static int vtysh_client_execute_name(const char *name
, const char *line
)
487 int ret
= CMD_SUCCESS
;
490 idx_client
= vtysh_client_lookup(name
);
491 if (idx_client
!= -1)
492 ret
= vtysh_client_execute(&vtysh_client
[idx_client
], line
);
494 vty_out(vty
, "Client not found\n");
502 * Retrieve all running config from daemons and parse it with the vtysh config
503 * parser. Returned output is not displayed to the user.
506 * where to start walking in the daemon list
509 * the specific command to execute
511 static void vtysh_client_config(struct vtysh_client
*head_client
, char *line
)
513 /* watchfrr currently doesn't load any config, and has some hardcoded
514 * settings that show up in "show run". skip it here (for now at
515 * least) so we don't get that mangled up in config-write.
517 if (head_client
->flag
== VTYSH_WATCHFRR
)
520 /* suppress output to user */
521 vty
->of_saved
= vty
->of
;
523 vtysh_client_run_all(head_client
, line
, 1, vtysh_config_parse_line
,
525 vty
->of
= vty
->of_saved
;
528 /* Command execution over the vty interface. */
529 static int vtysh_execute_func(const char *line
, int pager
)
534 const struct cmd_element
*cmd
;
536 int saved_ret
, saved_node
;
538 /* Split readline string up into the vector. */
539 vline
= cmd_make_strvec(line
);
544 if (vtysh_add_timestamp
&& strncmp(line
, "exit", 4)) {
547 (void)frr_timestamp(3, ts
, sizeof(ts
));
548 vty_out(vty
, "%% %s\n\n", ts
);
551 saved_ret
= ret
= cmd_execute(vty
, line
, &cmd
, 1);
552 saved_node
= vty
->node
;
555 * If command doesn't succeeded in current node, try to walk up in node
556 * tree. Changing vty->node is enough to try it just out without actual
557 * walkup in the vtysh.
559 while (ret
!= CMD_SUCCESS
&& ret
!= CMD_SUCCESS_DAEMON
560 && ret
!= CMD_WARNING
&& ret
!= CMD_WARNING_CONFIG_FAILED
561 && ret
!= CMD_ERR_AMBIGUOUS
&& ret
!= CMD_ERR_INCOMPLETE
562 && vty
->node
> CONFIG_NODE
) {
563 vty
->node
= node_parent(vty
->node
);
564 ret
= cmd_execute(vty
, line
, &cmd
, 1);
568 vty
->node
= saved_node
;
571 * If command succeeded in any other node than current (tried > 0) we
572 * have to move into node in the vtysh where it succeeded.
574 if (ret
== CMD_SUCCESS
|| ret
== CMD_SUCCESS_DAEMON
575 || ret
== CMD_WARNING
) {
577 vtysh_execute("exit");
580 * If command didn't succeed in any node, continue with return value
587 cmd_free_strvec(vline
);
592 case CMD_WARNING_CONFIG_FAILED
:
593 if (vty
->type
== VTY_FILE
)
594 vty_out(vty
, "Warning...\n");
596 case CMD_ERR_AMBIGUOUS
:
597 vty_out(vty
, "%% Ambiguous command: %s\n", line
);
599 case CMD_ERR_NO_MATCH
:
600 vty_out(vty
, "%% Unknown command: %s\n", line
);
602 case CMD_ERR_INCOMPLETE
:
603 vty_out(vty
, "%% Command incomplete: %s\n", line
);
605 case CMD_SUCCESS_DAEMON
: {
607 * FIXME: Don't open pager for exit commands. popen() causes
608 * problems if exited from vtysh at all. This hack shouldn't
609 * cause any problem but is really ugly.
611 if (pager
&& strncmp(line
, "exit", 4))
614 if (!strcmp(cmd
->string
, "configure")) {
615 for (i
= 0; i
< array_size(vtysh_client
); i
++) {
616 cmd_stat
= vtysh_client_execute(
617 &vtysh_client
[i
], line
);
618 if (cmd_stat
== CMD_WARNING
)
624 vline
= cmd_make_strvec(line
);
629 vty_close_pager(vty
);
633 ret
= cmd_execute_command(vline
, vty
, &cmd
, 1);
634 cmd_free_strvec(vline
);
635 if (ret
!= CMD_SUCCESS_DAEMON
)
637 } else if (cmd
->func
) {
638 (*cmd
->func
)(cmd
, vty
, 0, NULL
);
643 cmd_stat
= CMD_SUCCESS
;
644 struct vtysh_client
*vc
;
645 for (i
= 0; i
< array_size(vtysh_client
); i
++) {
646 if (cmd
->daemon
& vtysh_client
[i
].flag
) {
647 if (vtysh_client
[i
].fd
< 0
648 && (cmd
->daemon
== vtysh_client
[i
].flag
)) {
649 for (vc
= &vtysh_client
[i
]; vc
;
651 if (vc
->fd
== VTYSH_WAS_ACTIVE
)
654 if (vtysh_client
[i
].fd
< 0
655 && (cmd
->daemon
== vtysh_client
[i
].flag
)) {
656 bool any_inst
= false;
657 for (vc
= &vtysh_client
[i
]; vc
;
663 "%s is not running\n",
664 vtysh_client
[i
].name
);
665 cmd_stat
= CMD_ERR_NO_DAEMON
;
669 cmd_stat
= vtysh_client_execute(
670 &vtysh_client
[i
], line
);
671 if (cmd_stat
!= CMD_SUCCESS
)
675 if (cmd_stat
!= CMD_SUCCESS
&& cmd_stat
!= CMD_ERR_NO_DAEMON
)
679 (*cmd
->func
)(cmd
, vty
, 0, NULL
);
683 vty_close_pager(vty
);
688 int vtysh_execute_no_pager(const char *line
)
690 return vtysh_execute_func(line
, 0);
693 int vtysh_execute(const char *line
)
695 return vtysh_execute_func(line
, 1);
698 static char *trim(char *s
)
709 while (end
>= s
&& isspace((unsigned char)*end
))
713 while (*s
&& isspace((unsigned char)*s
))
719 int vtysh_mark_file(const char *filename
)
726 const struct cmd_element
*cmd
;
727 int saved_ret
, prev_node
;
729 char *vty_buf_copy
= NULL
;
730 char *vty_buf_trimmed
= NULL
;
732 if (strncmp("-", filename
, 1) == 0)
735 confp
= fopen(filename
, "r");
738 fprintf(stderr
, "%% Can't open config file %s due to '%s'.\n",
739 filename
, safe_strerror(errno
));
740 return CMD_ERR_NO_FILE
;
744 vty
->wfd
= STDOUT_FILENO
;
745 vty
->type
= VTY_TERM
;
746 vty
->node
= CONFIG_NODE
;
748 vtysh_execute_no_pager("enable");
749 vtysh_execute_no_pager("configure");
750 vty_buf_copy
= XCALLOC(MTYPE_VTYSH_CMD
, VTY_BUFSIZ
);
752 while (fgets(vty
->buf
, VTY_BUFSIZ
, confp
)) {
755 strlcpy(vty_buf_copy
, vty
->buf
, VTY_BUFSIZ
);
756 vty_buf_trimmed
= trim(vty_buf_copy
);
758 if (vty_buf_trimmed
[0] == '!' || vty_buf_trimmed
[0] == '#') {
759 vty_out(vty
, "%s", vty
->buf
);
763 /* Split readline string up into the vector. */
764 vline
= cmd_make_strvec(vty
->buf
);
767 vty_out(vty
, "%s", vty
->buf
);
772 * Ignore the "end" lines, we will generate these where
775 if (strlen(vty_buf_trimmed
) == 3
776 && strncmp("end", vty_buf_trimmed
, 3) == 0) {
777 cmd_free_strvec(vline
);
781 prev_node
= vty
->node
;
782 saved_ret
= ret
= cmd_execute_command_strict(vline
, vty
, &cmd
);
785 * If command doesn't succeeded in current node, try to walk up
786 * in node tree. Changing vty->node is enough to try it just
787 * out without actual walkup in the vtysh.
789 while (ret
!= CMD_SUCCESS
&& ret
!= CMD_SUCCESS_DAEMON
790 && ret
!= CMD_WARNING
&& ret
!= CMD_WARNING_CONFIG_FAILED
791 && ret
!= CMD_ERR_AMBIGUOUS
&& ret
!= CMD_ERR_INCOMPLETE
792 && vty
->node
> CONFIG_NODE
) {
793 vty
->node
= node_parent(vty
->node
);
794 ret
= cmd_execute_command_strict(vline
, vty
, &cmd
);
799 * If command succeeded in any other node than current (tried >
800 * 0) we have to move into node in the vtysh where it
803 if (ret
== CMD_SUCCESS
|| ret
== CMD_SUCCESS_DAEMON
804 || ret
== CMD_WARNING
) {
806 vty_out(vty
, "exit\n");
809 * If command didn't succeed in any node, continue with return
810 * value from first try.
814 vty
->node
= prev_node
;
817 cmd_free_strvec(vline
);
820 case CMD_WARNING_CONFIG_FAILED
:
821 if (vty
->type
== VTY_FILE
)
822 fprintf(stderr
, "line %d: Warning...: %s\n",
826 XFREE(MTYPE_VTYSH_CMD
, vty_buf_copy
);
828 case CMD_ERR_AMBIGUOUS
:
829 fprintf(stderr
, "line %d: %% Ambiguous command: %s\n",
833 XFREE(MTYPE_VTYSH_CMD
, vty_buf_copy
);
834 return CMD_ERR_AMBIGUOUS
;
835 case CMD_ERR_NO_MATCH
:
836 fprintf(stderr
, "line %d: %% Unknown command: %s\n",
840 XFREE(MTYPE_VTYSH_CMD
, vty_buf_copy
);
841 return CMD_ERR_NO_MATCH
;
842 case CMD_ERR_INCOMPLETE
:
843 fprintf(stderr
, "line %d: %% Command incomplete: %s\n",
847 XFREE(MTYPE_VTYSH_CMD
, vty_buf_copy
);
848 return CMD_ERR_INCOMPLETE
;
850 vty_out(vty
, "%s", vty
->buf
);
851 if (strmatch(vty_buf_trimmed
, "exit-vrf"))
852 vty_out(vty
, "end\n");
854 case CMD_SUCCESS_DAEMON
: {
857 vty_out(vty
, "%s", vty
->buf
);
858 if (strmatch(vty_buf_trimmed
, "exit-vrf"))
859 vty_out(vty
, "end\n");
860 cmd_stat
= vtysh_client_execute(&vtysh_client
[0],
862 if (cmd_stat
!= CMD_SUCCESS
)
866 (*cmd
->func
)(cmd
, vty
, 0, NULL
);
870 /* This is the end */
871 vty_out(vty
, "\nend\n");
873 XFREE(MTYPE_VTYSH_CMD
, vty_buf_copy
);
881 /* Configuration make from file. */
882 int vtysh_config_from_file(struct vty
*vty
, FILE *fp
)
885 const struct cmd_element
*cmd
;
887 /* once we have an error, we remember & return that */
888 int retcode
= CMD_SUCCESS
;
889 char *vty_buf_copy
= XCALLOC(MTYPE_VTYSH_CMD
, VTY_BUFSIZ
);
890 char *vty_buf_trimmed
= NULL
;
892 while (fgets(vty
->buf
, VTY_BUFSIZ
, fp
)) {
895 strlcpy(vty_buf_copy
, vty
->buf
, VTY_BUFSIZ
);
896 vty_buf_trimmed
= trim(vty_buf_copy
);
899 * Ignore the "end" lines, we will generate these where
900 * appropriate, otherwise we never execute
901 * XFRR_end_configuration, and start/end markers do not work.
903 if (strmatch(vty_buf_trimmed
, "end"))
906 ret
= command_config_read_one_line(vty
, &cmd
, lineno
, 1);
910 case CMD_WARNING_CONFIG_FAILED
:
911 if (vty
->type
== VTY_FILE
)
912 fprintf(stderr
, "line %d: Warning[%d]...: %s\n",
913 lineno
, vty
->node
, vty
->buf
);
917 case CMD_ERR_AMBIGUOUS
:
919 "line %d: %% Ambiguous command[%d]: %s\n",
920 lineno
, vty
->node
, vty
->buf
);
921 retcode
= CMD_ERR_AMBIGUOUS
;
923 case CMD_ERR_NO_MATCH
:
924 fprintf(stderr
, "line %d: %% Unknown command[%d]: %s",
925 lineno
, vty
->node
, vty
->buf
);
926 retcode
= CMD_ERR_NO_MATCH
;
928 case CMD_ERR_INCOMPLETE
:
930 "line %d: %% Command incomplete[%d]: %s\n",
931 lineno
, vty
->node
, vty
->buf
);
932 retcode
= CMD_ERR_INCOMPLETE
;
934 case CMD_SUCCESS_DAEMON
: {
936 int cmd_stat
= CMD_SUCCESS
;
938 for (i
= 0; i
< array_size(vtysh_client
); i
++) {
939 if (cmd
->daemon
& vtysh_client
[i
].flag
) {
940 cmd_stat
= vtysh_client_execute(
941 &vtysh_client
[i
], vty
->buf
);
943 * CMD_WARNING - Can mean that the
944 * command was parsed successfully but
945 * it was already entered in a few
946 * spots. As such if we receive a
947 * CMD_WARNING from a daemon we
948 * shouldn't stop talking to the other
949 * daemons for the particular command.
951 if (cmd_stat
!= CMD_SUCCESS
952 && cmd_stat
!= CMD_WARNING
) {
954 "line %d: Failure to communicate[%d] to %s, line: %s\n",
956 vtysh_client
[i
].name
,
963 if (cmd_stat
!= CMD_SUCCESS
)
967 (*cmd
->func
)(cmd
, vty
, 0, NULL
);
972 XFREE(MTYPE_VTYSH_CMD
, vty_buf_copy
);
978 * Function processes cli commands terminated with '?' character when entered
979 * through either 'vtysh' or 'vtysh -c' interfaces.
981 static int vtysh_process_questionmark(const char *input
, int input_len
)
985 vector vline
, describe
;
986 struct cmd_token
*token
;
991 vline
= cmd_make_strvec(input
);
993 /* In case of '> ?'. */
995 vline
= vector_init(1);
996 vector_set(vline
, NULL
);
997 } else if (input_len
&& isspace((unsigned char)input
[input_len
- 1]))
998 vector_set(vline
, NULL
);
1000 describe
= cmd_describe_command(vline
, vty
, &ret
);
1002 /* Ambiguous and no match error. */
1004 case CMD_ERR_AMBIGUOUS
:
1005 cmd_free_strvec(vline
);
1006 vector_free(describe
);
1007 vty_out(vty
, "%% Ambiguous command.\n");
1010 case CMD_ERR_NO_MATCH
:
1011 cmd_free_strvec(vline
);
1013 vector_free(describe
);
1014 vty_out(vty
, "%% There is no matched command.\n");
1019 /* Get width of command string. */
1021 for (i
= 0; i
< vector_active(describe
); i
++)
1022 if ((token
= vector_slot(describe
, i
)) != NULL
) {
1023 if (token
->text
[0] == '\0')
1026 int len
= strlen(token
->text
);
1032 for (i
= 0; i
< vector_active(describe
); i
++)
1033 if ((token
= vector_slot(describe
, i
)) != NULL
) {
1035 vty_out(vty
, " %-s\n", token
->text
);
1037 vty_out(vty
, " %-*s %s\n", width
, token
->text
,
1040 if (IS_VARYING_TOKEN(token
->type
)) {
1041 const char *ref
= vector_slot(
1042 vline
, vector_active(vline
) - 1);
1044 vector varcomps
= vector_init(VECTOR_MIN_SIZE
);
1045 cmd_variable_complete(token
, ref
, varcomps
);
1047 if (vector_active(varcomps
) > 0) {
1049 rl_get_screen_size(&rows
, &cols
);
1051 char *ac
= cmd_variable_comp2str(
1053 vty_out(vty
, "%s\n", ac
);
1054 XFREE(MTYPE_TMP
, ac
);
1057 vector_free(varcomps
);
1061 cmd_free_strvec(vline
);
1062 vector_free(describe
);
1068 * Entry point for user commands terminated with '?' character and typed through
1069 * the usual vtysh's stdin interface. This is the function being registered with
1072 static int vtysh_rl_describe(int a
, int b
)
1078 ret
= vtysh_process_questionmark(rl_line_buffer
, rl_end
);
1085 * Function in charged of processing vtysh instructions terminating with '?'
1086 * character and received through the 'vtysh -c' interface. If user's
1087 * instruction is well-formatted, we will call the same processing routine
1088 * utilized by the traditional vtysh's stdin interface.
1090 int vtysh_execute_command_questionmark(char *input
)
1092 int input_len
, qmark_count
= 0;
1095 if (!(input
&& *input
))
1098 /* Finding out question_mark count and strlen */
1099 for (str
= input
; *str
; ++str
) {
1103 input_len
= str
- input
;
1106 * Verify that user's input terminates in '?' and that patterns such as
1107 * 'cmd ? subcmd ?' are prevented.
1109 if (qmark_count
!= 1 || input
[input_len
- 1] != '?')
1113 * Questionmark-processing function is not expecting to receive '?'
1114 * character in input string.
1116 input
[input_len
- 1] = '\0';
1118 return vtysh_process_questionmark(input
, input_len
- 1);
1121 /* Result of cmd_complete_command() call will be stored here
1122 * and used in new_completion() in order to put the space in
1123 * correct places only. */
1124 int complete_status
;
1126 static char *command_generator(const char *text
, int state
)
1129 static char **matched
= NULL
;
1130 static int index
= 0;
1136 if (vty
->node
== AUTH_NODE
|| vty
->node
== AUTH_ENABLE_NODE
)
1139 vline
= cmd_make_strvec(rl_line_buffer
);
1144 isspace((unsigned char)rl_line_buffer
[rl_end
- 1]))
1145 vector_set(vline
, NULL
);
1147 matched
= cmd_complete_command(vline
, vty
, &complete_status
);
1148 cmd_free_strvec(vline
);
1151 if (matched
&& matched
[index
]) {
1152 XCOUNTFREE(MTYPE_COMPLETION
, matched
[index
]);
1153 return matched
[index
++];
1156 XFREE(MTYPE_TMP
, matched
);
1161 static char **new_completion(const char *text
, int start
, int end
)
1165 matches
= rl_completion_matches(text
, command_generator
);
1169 if (complete_status
!= CMD_COMPLETE_FULL_MATCH
)
1170 /* only append a space on full match */
1171 rl_completion_append_character
= '\0';
1177 /* Vty node structures. */
1179 static struct cmd_node bgp_node
= {
1182 .parent_node
= CONFIG_NODE
,
1183 .prompt
= "%s(config-router)# ",
1185 #endif /* HAVE_BGPD */
1187 static struct cmd_node rip_node
= {
1190 .parent_node
= CONFIG_NODE
,
1191 .prompt
= "%s(config-router)# ",
1195 static struct cmd_node isis_node
= {
1198 .parent_node
= CONFIG_NODE
,
1199 .prompt
= "%s(config-router)# ",
1201 #endif /* HAVE_ISISD */
1204 static struct cmd_node openfabric_node
= {
1205 .name
= "openfabric",
1206 .node
= OPENFABRIC_NODE
,
1207 .parent_node
= CONFIG_NODE
,
1208 .prompt
= "%s(config-router)# ",
1210 #endif /* HAVE_FABRICD */
1212 static struct cmd_node interface_node
= {
1213 .name
= "interface",
1214 .node
= INTERFACE_NODE
,
1215 .parent_node
= CONFIG_NODE
,
1216 .prompt
= "%s(config-if)# ",
1219 static struct cmd_node pw_node
= {
1222 .parent_node
= CONFIG_NODE
,
1223 .prompt
= "%s(config-pw)# ",
1226 static struct cmd_node segment_routing_node
= {
1227 .name
= "segment-routing",
1228 .node
= SEGMENT_ROUTING_NODE
,
1229 .parent_node
= CONFIG_NODE
,
1230 .prompt
= "%s(config-sr)# ",
1233 #if defined(HAVE_PATHD)
1234 static struct cmd_node sr_traffic_eng_node
= {
1235 .name
= "sr traffic-eng",
1236 .node
= SR_TRAFFIC_ENG_NODE
,
1237 .parent_node
= SEGMENT_ROUTING_NODE
,
1238 .prompt
= "%s(config-sr-te)# ",
1241 static struct cmd_node srte_segment_list_node
= {
1242 .name
= "srte segment-list",
1243 .node
= SR_SEGMENT_LIST_NODE
,
1244 .parent_node
= SR_TRAFFIC_ENG_NODE
,
1245 .prompt
= "%s(config-sr-te-segment-list)# ",
1248 static struct cmd_node srte_policy_node
= {
1249 .name
= "srte policy",
1250 .node
= SR_POLICY_NODE
,
1251 .parent_node
= SR_TRAFFIC_ENG_NODE
,
1252 .prompt
= "%s(config-sr-te-policy)# ",
1255 static struct cmd_node srte_candidate_dyn_node
= {
1256 .name
= "srte candidate-dyn",
1257 .node
= SR_CANDIDATE_DYN_NODE
,
1258 .parent_node
= SR_POLICY_NODE
,
1259 .prompt
= "%s(config-sr-te-candidate)# ",
1262 static struct cmd_node pcep_node
= {
1263 .name
= "srte pcep",
1265 .parent_node
= SR_TRAFFIC_ENG_NODE
,
1266 .prompt
= "%s(config-sr-te-pcep)# "
1269 static struct cmd_node pcep_pcc_node
= {
1270 .name
= "srte pcep pcc",
1271 .node
= PCEP_PCC_NODE
,
1272 .parent_node
= PCEP_NODE
,
1273 .prompt
= "%s(config-sr-te-pcep-pcc)# ",
1276 static struct cmd_node pcep_pce_node
= {
1277 .name
= "srte pcep pce-peer",
1278 .node
= PCEP_PCE_NODE
,
1279 .parent_node
= PCEP_NODE
,
1280 .prompt
= "%s(config-sr-te-pcep-pce-peer)# ",
1283 static struct cmd_node pcep_pce_config_node
= {
1284 .name
= "srte pcep pce-config",
1285 .node
= PCEP_PCE_CONFIG_NODE
,
1286 .parent_node
= PCEP_NODE
,
1287 .prompt
= "%s(pcep-sr-te-pcep-pce-config)# ",
1289 #endif /* HAVE_PATHD */
1291 static struct cmd_node vrf_node
= {
1294 .parent_node
= CONFIG_NODE
,
1295 .prompt
= "%s(config-vrf)# ",
1298 static struct cmd_node nh_group_node
= {
1299 .name
= "nexthop-group",
1300 .node
= NH_GROUP_NODE
,
1301 .parent_node
= CONFIG_NODE
,
1302 .prompt
= "%s(config-nh-group)# ",
1305 static struct cmd_node rmap_node
= {
1308 .parent_node
= CONFIG_NODE
,
1309 .prompt
= "%s(config-route-map)# ",
1312 static struct cmd_node srv6_node
= {
1315 .parent_node
= SEGMENT_ROUTING_NODE
,
1316 .prompt
= "%s(config-srv6)# ",
1319 static struct cmd_node srv6_locs_node
= {
1320 .name
= "srv6-locators",
1321 .node
= SRV6_LOCS_NODE
,
1322 .parent_node
= SRV6_NODE
,
1323 .prompt
= "%s(config-srv6-locators)# ",
1326 static struct cmd_node srv6_loc_node
= {
1327 .name
= "srv6-locator",
1328 .node
= SRV6_LOC_NODE
,
1329 .parent_node
= SRV6_LOCS_NODE
,
1330 .prompt
= "%s(config-srv6-locator)# ",
1334 static struct cmd_node pbr_map_node
= {
1336 .node
= PBRMAP_NODE
,
1337 .parent_node
= CONFIG_NODE
,
1338 .prompt
= "%s(config-pbr-map)# ",
1340 #endif /* HAVE_PBRD */
1342 static struct cmd_node zebra_node
= {
1345 .parent_node
= CONFIG_NODE
,
1346 .prompt
= "%s(config-router)# ",
1350 static struct cmd_node bgp_vpnv4_node
= {
1351 .name
= "bgp vpnv4",
1352 .node
= BGP_VPNV4_NODE
,
1353 .parent_node
= BGP_NODE
,
1354 .prompt
= "%s(config-router-af)# ",
1358 static struct cmd_node bgp_vpnv6_node
= {
1359 .name
= "bgp vpnv6",
1360 .node
= BGP_VPNV6_NODE
,
1361 .parent_node
= BGP_NODE
,
1362 .prompt
= "%s(config-router-af)# ",
1366 static struct cmd_node bgp_flowspecv4_node
= {
1367 .name
= "bgp ipv4 flowspec",
1368 .node
= BGP_FLOWSPECV4_NODE
,
1369 .parent_node
= BGP_NODE
,
1370 .prompt
= "%s(config-router-af)# ",
1374 static struct cmd_node bgp_flowspecv6_node
= {
1375 .name
= "bgp ipv6 flowspec",
1376 .node
= BGP_FLOWSPECV6_NODE
,
1377 .parent_node
= BGP_NODE
,
1378 .prompt
= "%s(config-router-af)# ",
1382 static struct cmd_node bgp_ipv4_node
= {
1383 .name
= "bgp ipv4 unicast",
1384 .node
= BGP_IPV4_NODE
,
1385 .parent_node
= BGP_NODE
,
1386 .prompt
= "%s(config-router-af)# ",
1390 static struct cmd_node bgp_ipv4m_node
= {
1391 .name
= "bgp ipv4 multicast",
1392 .node
= BGP_IPV4M_NODE
,
1393 .parent_node
= BGP_NODE
,
1394 .prompt
= "%s(config-router-af)# ",
1398 static struct cmd_node bgp_ipv4l_node
= {
1399 .name
= "bgp ipv4 labeled unicast",
1400 .node
= BGP_IPV4L_NODE
,
1401 .parent_node
= BGP_NODE
,
1402 .prompt
= "%s(config-router-af)# ",
1406 static struct cmd_node bgp_ipv6_node
= {
1408 .node
= BGP_IPV6_NODE
,
1409 .parent_node
= BGP_NODE
,
1410 .prompt
= "%s(config-router-af)# ",
1414 static struct cmd_node bgp_ipv6m_node
= {
1415 .name
= "bgp ipv6 multicast",
1416 .node
= BGP_IPV6M_NODE
,
1417 .parent_node
= BGP_NODE
,
1418 .prompt
= "%s(config-router-af)# ",
1422 static struct cmd_node bgp_evpn_node
= {
1424 .node
= BGP_EVPN_NODE
,
1425 .parent_node
= BGP_NODE
,
1426 .prompt
= "%s(config-router-af)# ",
1430 static struct cmd_node bgp_evpn_vni_node
= {
1431 .name
= "bgp evpn vni",
1432 .node
= BGP_EVPN_VNI_NODE
,
1433 .parent_node
= BGP_EVPN_NODE
,
1434 .prompt
= "%s(config-router-af-vni)# ",
1437 static struct cmd_node bgp_ipv6l_node
= {
1438 .name
= "bgp ipv6 labeled unicast",
1439 .node
= BGP_IPV6L_NODE
,
1440 .parent_node
= BGP_NODE
,
1441 .prompt
= "%s(config-router-af)# ",
1445 #ifdef ENABLE_BGP_VNC
1446 static struct cmd_node bgp_vnc_defaults_node
= {
1447 .name
= "bgp vnc defaults",
1448 .node
= BGP_VNC_DEFAULTS_NODE
,
1449 .parent_node
= BGP_NODE
,
1450 .prompt
= "%s(config-router-vnc-defaults)# ",
1453 static struct cmd_node bgp_vnc_nve_group_node
= {
1454 .name
= "bgp vnc nve",
1455 .node
= BGP_VNC_NVE_GROUP_NODE
,
1456 .parent_node
= BGP_NODE
,
1457 .prompt
= "%s(config-router-vnc-nve-group)# ",
1460 static struct cmd_node bgp_vrf_policy_node
= {
1461 .name
= "bgp vrf policy",
1462 .node
= BGP_VRF_POLICY_NODE
,
1463 .parent_node
= BGP_NODE
,
1464 .prompt
= "%s(config-router-vrf-policy)# ",
1467 static struct cmd_node bgp_vnc_l2_group_node
= {
1468 .name
= "bgp vnc l2",
1469 .node
= BGP_VNC_L2_GROUP_NODE
,
1470 .parent_node
= BGP_NODE
,
1471 .prompt
= "%s(config-router-vnc-l2-group)# ",
1473 #endif /* ENABLE_BGP_VNC */
1475 static struct cmd_node bmp_node
= {
1478 .parent_node
= BGP_NODE
,
1479 .prompt
= "%s(config-bgp-bmp)# "
1482 static struct cmd_node bgp_srv6_node
= {
1484 .node
= BGP_SRV6_NODE
,
1485 .parent_node
= BGP_NODE
,
1486 .prompt
= "%s(config-router-srv6)# ",
1488 #endif /* HAVE_BGPD */
1491 static struct cmd_node ospf_node
= {
1494 .parent_node
= CONFIG_NODE
,
1495 .prompt
= "%s(config-router)# ",
1497 #endif /* HAVE_OSPFD */
1500 static struct cmd_node eigrp_node
= {
1503 .parent_node
= CONFIG_NODE
,
1504 .prompt
= "%s(config-router)# ",
1506 #endif /* HAVE_EIGRPD */
1509 static struct cmd_node babel_node
= {
1512 .parent_node
= CONFIG_NODE
,
1513 .prompt
= "%s(config-router)# ",
1515 #endif /* HAVE_BABELD */
1517 static struct cmd_node ripng_node
= {
1520 .parent_node
= CONFIG_NODE
,
1521 .prompt
= "%s(config-router)# ",
1525 static struct cmd_node ospf6_node
= {
1528 .parent_node
= CONFIG_NODE
,
1529 .prompt
= "%s(config-ospf6)# ",
1531 #endif /* HAVE_OSPF6D */
1534 static struct cmd_node ldp_node
= {
1537 .parent_node
= CONFIG_NODE
,
1538 .prompt
= "%s(config-ldp)# ",
1541 static struct cmd_node ldp_ipv4_node
= {
1543 .node
= LDP_IPV4_NODE
,
1544 .parent_node
= LDP_NODE
,
1545 .prompt
= "%s(config-ldp-af)# ",
1548 static struct cmd_node ldp_ipv6_node
= {
1550 .node
= LDP_IPV6_NODE
,
1551 .parent_node
= LDP_NODE
,
1552 .prompt
= "%s(config-ldp-af)# ",
1555 static struct cmd_node ldp_ipv4_iface_node
= {
1556 .name
= "ldp ipv4 interface",
1557 .node
= LDP_IPV4_IFACE_NODE
,
1558 .parent_node
= LDP_IPV4_NODE
,
1559 .prompt
= "%s(config-ldp-af-if)# ",
1562 static struct cmd_node ldp_ipv6_iface_node
= {
1563 .name
= "ldp ipv6 interface",
1564 .node
= LDP_IPV6_IFACE_NODE
,
1565 .parent_node
= LDP_IPV6_NODE
,
1566 .prompt
= "%s(config-ldp-af-if)# ",
1569 static struct cmd_node ldp_l2vpn_node
= {
1570 .name
= "ldp l2vpn",
1571 .node
= LDP_L2VPN_NODE
,
1572 .parent_node
= CONFIG_NODE
,
1573 .prompt
= "%s(config-l2vpn)# ",
1576 static struct cmd_node ldp_pseudowire_node
= {
1578 .node
= LDP_PSEUDOWIRE_NODE
,
1579 .parent_node
= LDP_L2VPN_NODE
,
1580 .prompt
= "%s(config-l2vpn-pw)# ",
1582 #endif /* HAVE_LDPD */
1584 static struct cmd_node keychain_node
= {
1586 .node
= KEYCHAIN_NODE
,
1587 .parent_node
= CONFIG_NODE
,
1588 .prompt
= "%s(config-keychain)# ",
1591 static struct cmd_node keychain_key_node
= {
1592 .name
= "keychain key",
1593 .node
= KEYCHAIN_KEY_NODE
,
1594 .parent_node
= KEYCHAIN_NODE
,
1595 .prompt
= "%s(config-keychain-key)# ",
1598 struct cmd_node link_params_node
= {
1599 .name
= "link-params",
1600 .node
= LINK_PARAMS_NODE
,
1601 .parent_node
= INTERFACE_NODE
,
1602 .prompt
= "%s(config-link-params)# ",
1607 static struct cmd_node rpki_node
= {
1610 .parent_node
= CONFIG_NODE
,
1611 .prompt
= "%s(config-rpki)# ",
1613 #endif /* HAVE_BGPD */
1616 static struct cmd_node bfd_node
= {
1619 .parent_node
= CONFIG_NODE
,
1620 .prompt
= "%s(config-bfd)# ",
1623 static struct cmd_node bfd_peer_node
= {
1625 .node
= BFD_PEER_NODE
,
1626 .parent_node
= BFD_NODE
,
1627 .prompt
= "%s(config-bfd-peer)# ",
1630 static struct cmd_node bfd_profile_node
= {
1631 .name
= "bfd profile",
1632 .node
= BFD_PROFILE_NODE
,
1633 .parent_node
= BFD_NODE
,
1634 .prompt
= "%s(config-bfd-profile)# ",
1636 #endif /* HAVE_BFDD */
1638 /* Defined in lib/vty.c */
1639 extern struct cmd_node vty_node
;
1641 /* When '^Z' is received from vty, move down to the enable mode. */
1642 static int vtysh_end(void)
1644 switch (vty
->node
) {
1647 /* Nothing to do. */
1650 vty
->node
= ENABLE_NODE
;
1656 #include "vtysh/vtysh_clippy.c"
1658 DEFUNSH(VTYSH_REALLYALL
, vtysh_end_all
, vtysh_end_all_cmd
, "end",
1659 "End current mode and change to enable mode\n")
1664 DEFUNSH(VTYSH_ZEBRA
, srv6
, srv6_cmd
,
1666 "Segment-Routing SRv6 configuration\n")
1668 vty
->node
= SRV6_NODE
;
1672 DEFUNSH(VTYSH_ZEBRA
, srv6_locators
, srv6_locators_cmd
,
1674 "Segment-Routing SRv6 locators configuration\n")
1676 vty
->node
= SRV6_LOCS_NODE
;
1680 DEFUNSH(VTYSH_ZEBRA
, srv6_locator
, srv6_locator_cmd
,
1682 "Segment Routing SRv6 locator\n"
1683 "Specify locator-name\n")
1685 vty
->node
= SRV6_LOC_NODE
;
1690 DEFUNSH(VTYSH_BGPD
, router_bgp
, router_bgp_cmd
,
1691 "router bgp [(1-4294967295) [<view|vrf> VIEWVRFNAME]]",
1692 ROUTER_STR BGP_STR AS_STR
1693 "BGP view\nBGP VRF\n"
1696 vty
->node
= BGP_NODE
;
1700 #ifdef KEEP_OLD_VPN_COMMANDS
1701 DEFUNSH(VTYSH_BGPD
, address_family_vpnv4
, address_family_vpnv4_cmd
,
1702 "address-family vpnv4 [unicast]",
1703 "Enter Address Family command mode\n"
1705 BGP_AF_MODIFIER_STR
)
1707 vty
->node
= BGP_VPNV4_NODE
;
1711 DEFUNSH(VTYSH_BGPD
, address_family_vpnv6
, address_family_vpnv6_cmd
,
1712 "address-family vpnv6 [unicast]",
1713 "Enter Address Family command mode\n"
1715 BGP_AF_MODIFIER_STR
)
1717 vty
->node
= BGP_VPNV6_NODE
;
1720 #endif /* KEEP_OLD_VPN_COMMANDS */
1722 DEFUNSH(VTYSH_BGPD
, address_family_ipv4
, address_family_ipv4_cmd
,
1723 "address-family ipv4 [unicast]",
1724 "Enter Address Family command mode\n"
1726 BGP_AF_MODIFIER_STR
)
1728 vty
->node
= BGP_IPV4_NODE
;
1732 DEFUNSH(VTYSH_BGPD
, address_family_flowspecv4
, address_family_flowspecv4_cmd
,
1733 "address-family ipv4 flowspec",
1734 "Enter Address Family command mode\n"
1736 BGP_AF_MODIFIER_STR
)
1738 vty
->node
= BGP_FLOWSPECV4_NODE
;
1742 DEFUNSH(VTYSH_BGPD
, address_family_flowspecv6
, address_family_flowspecv6_cmd
,
1743 "address-family ipv6 flowspec",
1744 "Enter Address Family command mode\n"
1746 BGP_AF_MODIFIER_STR
)
1748 vty
->node
= BGP_FLOWSPECV6_NODE
;
1752 DEFUNSH(VTYSH_BGPD
, address_family_ipv4_multicast
,
1753 address_family_ipv4_multicast_cmd
, "address-family ipv4 multicast",
1754 "Enter Address Family command mode\n"
1756 BGP_AF_MODIFIER_STR
)
1758 vty
->node
= BGP_IPV4M_NODE
;
1762 DEFUNSH(VTYSH_BGPD
, address_family_ipv4_vpn
, address_family_ipv4_vpn_cmd
,
1763 "address-family ipv4 vpn",
1764 "Enter Address Family command mode\n"
1766 BGP_AF_MODIFIER_STR
)
1768 vty
->node
= BGP_VPNV4_NODE
;
1772 DEFUNSH(VTYSH_BGPD
, address_family_ipv4_labeled_unicast
,
1773 address_family_ipv4_labeled_unicast_cmd
,
1774 "address-family ipv4 labeled-unicast",
1775 "Enter Address Family command mode\n"
1777 BGP_AF_MODIFIER_STR
)
1779 vty
->node
= BGP_IPV4L_NODE
;
1783 DEFUNSH(VTYSH_BGPD
, address_family_ipv6
, address_family_ipv6_cmd
,
1784 "address-family ipv6 [unicast]",
1785 "Enter Address Family command mode\n"
1787 BGP_AF_MODIFIER_STR
)
1789 vty
->node
= BGP_IPV6_NODE
;
1793 DEFUNSH(VTYSH_BGPD
, address_family_ipv6_multicast
,
1794 address_family_ipv6_multicast_cmd
, "address-family ipv6 multicast",
1795 "Enter Address Family command mode\n"
1797 BGP_AF_MODIFIER_STR
)
1799 vty
->node
= BGP_IPV6M_NODE
;
1803 DEFUNSH(VTYSH_BGPD
, address_family_ipv6_vpn
, address_family_ipv6_vpn_cmd
,
1804 "address-family ipv6 vpn",
1805 "Enter Address Family command mode\n"
1807 BGP_AF_MODIFIER_STR
)
1809 vty
->node
= BGP_VPNV6_NODE
;
1813 DEFUNSH(VTYSH_BGPD
, address_family_ipv6_labeled_unicast
,
1814 address_family_ipv6_labeled_unicast_cmd
,
1815 "address-family ipv6 labeled-unicast",
1816 "Enter Address Family command mode\n"
1818 BGP_AF_MODIFIER_STR
)
1820 vty
->node
= BGP_IPV6L_NODE
;
1828 "Enable rpki and enter rpki configuration mode\n")
1830 vty
->node
= RPKI_NODE
;
1837 "bmp targets BMPTARGETS",
1838 "BGP Monitoring Protocol\n"
1839 "Create BMP target group\n"
1840 "Name of the BMP target group\n")
1842 vty
->node
= BMP_NODE
;
1849 "segment-routing srv6",
1850 "Segment-Routing configuration\n"
1851 "Segment-Routing SRv6 configuration\n")
1853 vty
->node
= BGP_SRV6_NODE
;
1861 "exit Segment-Routing SRv6 configuration\n")
1863 if (vty
->node
== BGP_SRV6_NODE
)
1864 vty
->node
= BGP_NODE
;
1872 "quit Segment-Routing SRv6 configuration\n")
1874 if (vty
->node
== BGP_SRV6_NODE
)
1875 vty
->node
= BGP_NODE
;
1879 DEFUNSH(VTYSH_BGPD
, address_family_evpn
, address_family_evpn_cmd
,
1880 "address-family <l2vpn evpn>",
1881 "Enter Address Family command mode\n"
1883 BGP_AF_MODIFIER_STR
)
1885 vty
->node
= BGP_EVPN_NODE
;
1889 DEFUNSH(VTYSH_BGPD
, bgp_evpn_vni
, bgp_evpn_vni_cmd
, "vni " CMD_VNI_RANGE
,
1890 "VXLAN Network Identifier\n"
1893 vty
->node
= BGP_EVPN_VNI_NODE
;
1897 #if defined(ENABLE_BGP_VNC)
1898 DEFUNSH(VTYSH_BGPD
, vnc_defaults
, vnc_defaults_cmd
, "vnc defaults",
1899 "VNC/RFP related configuration\n"
1900 "Configure default NVE group\n")
1902 vty
->node
= BGP_VNC_DEFAULTS_NODE
;
1906 DEFUNSH(VTYSH_BGPD
, vnc_nve_group
, vnc_nve_group_cmd
, "vnc nve-group NAME",
1907 "VNC/RFP related configuration\n"
1908 "Configure a NVE group\n"
1911 vty
->node
= BGP_VNC_NVE_GROUP_NODE
;
1915 DEFUNSH(VTYSH_BGPD
, vnc_vrf_policy
, vnc_vrf_policy_cmd
, "vrf-policy NAME",
1916 "Configure a VRF policy group\n"
1919 vty
->node
= BGP_VRF_POLICY_NODE
;
1923 DEFUNSH(VTYSH_BGPD
, vnc_l2_group
, vnc_l2_group_cmd
, "vnc l2-group NAME",
1924 "VNC/RFP related configuration\n"
1925 "Configure a L2 group\n"
1928 vty
->node
= BGP_VNC_L2_GROUP_NODE
;
1932 DEFUNSH(VTYSH_BGPD
, exit_vnc_config
, exit_vnc_config_cmd
, "exit-vnc",
1933 "Exit from VNC configuration mode\n")
1935 if (vty
->node
== BGP_VNC_DEFAULTS_NODE
1936 || vty
->node
== BGP_VNC_NVE_GROUP_NODE
1937 || vty
->node
== BGP_VNC_L2_GROUP_NODE
)
1938 vty
->node
= BGP_NODE
;
1942 DEFUNSH(VTYSH_BGPD
, exit_vrf_policy
, exit_vrf_policy_cmd
, "exit-vrf-policy",
1943 "Exit from VRF policy configuration mode\n")
1945 if (vty
->node
== BGP_VRF_POLICY_NODE
)
1946 vty
->node
= BGP_NODE
;
1950 #endif /* HAVE_BGPD */
1952 DEFUNSH(VTYSH_KEYS
, key_chain
, key_chain_cmd
, "key chain WORD",
1953 "Authentication key management\n"
1954 "Key-chain management\n"
1957 vty
->node
= KEYCHAIN_NODE
;
1961 DEFUNSH(VTYSH_KEYS
, key
, key_cmd
, "key (0-2147483647)",
1963 "Key identifier number\n")
1965 vty
->node
= KEYCHAIN_KEY_NODE
;
1970 DEFUNSH(VTYSH_RIPD
, router_rip
, router_rip_cmd
, "router rip [vrf NAME]",
1971 ROUTER_STR
"RIP\n" VRF_CMD_HELP_STR
)
1973 vty
->node
= RIP_NODE
;
1976 #endif /* HAVE_RIPD */
1979 DEFUNSH(VTYSH_RIPNGD
, router_ripng
, router_ripng_cmd
, "router ripng [vrf NAME]",
1980 ROUTER_STR
"RIPng\n" VRF_CMD_HELP_STR
)
1982 vty
->node
= RIPNG_NODE
;
1985 #endif /* HAVE_RIPNGD */
1988 DEFUNSH(VTYSH_OSPFD
, router_ospf
, router_ospf_cmd
,
1989 "router ospf [(1-65535)] [vrf NAME]",
1990 "Enable a routing process\n"
1991 "Start OSPF configuration\n"
1995 vty
->node
= OSPF_NODE
;
1998 #endif /* HAVE_OSPFD */
2001 DEFUNSH(VTYSH_EIGRPD
, router_eigrp
, router_eigrp_cmd
, "router eigrp (1-65535) [vrf NAME]",
2002 "Enable a routing process\n"
2003 "Start EIGRP configuration\n"
2004 "AS number to use\n"
2007 vty
->node
= EIGRP_NODE
;
2010 #endif /* HAVE_EIGRPD */
2013 DEFUNSH(VTYSH_BABELD
, router_babel
, router_babel_cmd
, "router babel",
2014 "Enable a routing process\n"
2015 "Make Babel instance command\n")
2017 vty
->node
= BABEL_NODE
;
2020 #endif /* HAVE_BABELD */
2023 DEFUNSH(VTYSH_OSPF6D
, router_ospf6
, router_ospf6_cmd
, "router ospf6 [vrf NAME]",
2024 ROUTER_STR OSPF6_STR VRF_CMD_HELP_STR
)
2026 vty
->node
= OSPF6_NODE
;
2031 #if defined(HAVE_LDPD)
2032 DEFUNSH(VTYSH_LDPD
, ldp_mpls_ldp
, ldp_mpls_ldp_cmd
, "mpls ldp",
2033 "Global MPLS configuration subcommands\n"
2034 "Label Distribution Protocol\n")
2036 vty
->node
= LDP_NODE
;
2040 DEFUNSH(VTYSH_LDPD
, ldp_address_family_ipv4
, ldp_address_family_ipv4_cmd
,
2041 "address-family ipv4",
2042 "Configure Address Family and its parameters\n"
2045 vty
->node
= LDP_IPV4_NODE
;
2049 DEFUNSH(VTYSH_LDPD
, ldp_address_family_ipv6
, ldp_address_family_ipv6_cmd
,
2050 "address-family ipv6",
2051 "Configure Address Family and its parameters\n"
2054 vty
->node
= LDP_IPV6_NODE
;
2058 DEFUNSH(VTYSH_LDPD
, ldp_exit_address_family
, ldp_exit_address_family_cmd
,
2059 "exit-address-family", "Exit from Address Family configuration mode\n")
2061 if (vty
->node
== LDP_IPV4_NODE
|| vty
->node
== LDP_IPV6_NODE
)
2062 vty
->node
= LDP_NODE
;
2066 DEFUNSH(VTYSH_LDPD
, ldp_interface_ifname
, ldp_interface_ifname_cmd
,
2068 "Enable LDP on an interface and enter interface submode\n"
2069 "Interface's name\n")
2071 switch (vty
->node
) {
2073 vty
->node
= LDP_IPV4_IFACE_NODE
;
2076 vty
->node
= LDP_IPV6_IFACE_NODE
;
2085 DEFUNSH(VTYSH_LDPD
, ldp_l2vpn_word_type_vpls
, ldp_l2vpn_word_type_vpls_cmd
,
2086 "l2vpn WORD type vpls",
2087 "Configure l2vpn commands\n"
2090 "Virtual Private LAN Service\n")
2092 vty
->node
= LDP_L2VPN_NODE
;
2096 DEFUNSH(VTYSH_LDPD
, ldp_member_pseudowire_ifname
,
2097 ldp_member_pseudowire_ifname_cmd
, "member pseudowire IFNAME",
2098 "L2VPN member configuration\n"
2099 "Pseudowire interface\n"
2100 "Interface's name\n")
2102 vty
->node
= LDP_PSEUDOWIRE_NODE
;
2108 DEFUNSH(VTYSH_ISISD
, router_isis
, router_isis_cmd
,
2109 "router isis WORD [vrf NAME]",
2112 "ISO Routing area tag\n" VRF_CMD_HELP_STR
)
2114 vty
->node
= ISIS_NODE
;
2117 #endif /* HAVE_ISISD */
2120 DEFUNSH(VTYSH_FABRICD
, router_openfabric
, router_openfabric_cmd
, "router openfabric WORD",
2122 "OpenFabric routing protocol\n"
2123 "ISO Routing area tag\n")
2125 vty
->node
= OPENFABRIC_NODE
;
2128 #endif /* HAVE_FABRICD */
2130 DEFUNSH(VTYSH_SR
, segment_routing
, segment_routing_cmd
,
2132 "Configure segment routing\n")
2134 vty
->node
= SEGMENT_ROUTING_NODE
;
2138 #if defined (HAVE_PATHD)
2139 DEFUNSH(VTYSH_PATHD
, sr_traffic_eng
, sr_traffic_eng_cmd
,
2141 "Configure SR traffic engineering\n")
2143 vty
->node
= SR_TRAFFIC_ENG_NODE
;
2147 DEFUNSH(VTYSH_PATHD
, srte_segment_list
, srte_segment_list_cmd
,
2148 "segment-list WORD$name",
2150 "Segment List Name\n")
2152 vty
->node
= SR_SEGMENT_LIST_NODE
;
2156 DEFUNSH(VTYSH_PATHD
, srte_policy
, srte_policy_cmd
,
2157 "policy color (0-4294967295) endpoint <A.B.C.D|X:X::X:X>",
2158 "Segment Routing Policy\n"
2160 "SR Policy color value\n"
2161 "SR Policy endpoint\n"
2162 "SR Policy endpoint IPv4 address\n"
2163 "SR Policy endpoint IPv6 address\n")
2165 vty
->node
= SR_POLICY_NODE
;
2169 DEFUNSH(VTYSH_PATHD
, srte_policy_candidate_dyn_path
,
2170 srte_policy_candidate_dyn_path_cmd
,
2171 "candidate-path preference (0-4294967295) name WORD dynamic",
2172 "Segment Routing Policy Candidate Path\n"
2173 "Segment Routing Policy Candidate Path Preference\n"
2174 "Administrative Preference\n"
2175 "Segment Routing Policy Candidate Path Name\n"
2179 vty
->node
= SR_CANDIDATE_DYN_NODE
;
2183 DEFUNSH(VTYSH_PATHD
, pcep
, pcep_cmd
,
2185 "Configure SR pcep\n")
2187 vty
->node
= PCEP_NODE
;
2191 DEFUNSH(VTYSH_PATHD
, pcep_cli_pcc
, pcep_cli_pcc_cmd
,
2193 "PCC configuration\n")
2195 vty
->node
= PCEP_PCC_NODE
;
2199 DEFUNSH(VTYSH_PATHD
, pcep_cli_pce
, pcep_cli_pce_cmd
,
2201 "PCE configuration\n"
2204 vty
->node
= PCEP_PCE_NODE
;
2208 DEFUNSH(VTYSH_PATHD
, pcep_cli_pcep_pce_config
, pcep_cli_pcep_pce_config_cmd
,
2210 "PCEP peer Configuration Group\n"
2211 "PCEP peer Configuration Group name\n")
2213 vty
->node
= PCEP_PCE_CONFIG_NODE
;
2217 #endif /* HAVE_PATHD */
2219 /* max value is EXT_ADMIN_GROUP_MAX_POSITIONS - 1 */
2220 DEFUNSH(VTYSH_AFFMAP
, affinity_map
, vtysh_affinity_map_cmd
,
2221 "affinity-map NAME bit-position (0-1023)",
2222 "Affinity map configuration\n"
2223 "Affinity attribute name\n"
2224 "Bit position for affinity attribute value\n"
2230 /* max value is EXT_ADMIN_GROUP_MAX_POSITIONS - 1 */
2231 DEFUNSH(VTYSH_AFFMAP
, no_affinity_map
, vtysh_no_affinity_map_cmd
,
2232 "no affinity-map NAME$name [bit-position (0-1023)$position]",
2234 "Affinity map configuration\n"
2235 "Affinity attribute name\n"
2236 "Bit position for affinity attribute value\n"
2242 DEFUNSH(VTYSH_RMAP
, vtysh_route_map
, vtysh_route_map_cmd
,
2243 "route-map RMAP_NAME <deny|permit> (1-65535)",
2244 "Create route-map or enter route-map command mode\n"
2246 "Route map denies set operations\n"
2247 "Route map permits set operations\n"
2248 "Sequence to insert to/delete from existing route-map entry\n")
2250 vty
->node
= RMAP_NODE
;
2255 DEFUNSH(VTYSH_PBRD
, vtysh_pbr_map
, vtysh_pbr_map_cmd
,
2256 "pbr-map PBRMAP seq (1-700)",
2257 "Create pbr-map or enter pbr-map command mode\n"
2258 "The name of the PBR MAP\n"
2259 "Sequence to insert to/delete from existing pbr-map entry\n"
2260 "Sequence number\n")
2262 vty
->node
= PBRMAP_NODE
;
2266 DEFSH(VTYSH_PBRD
, vtysh_no_pbr_map_cmd
, "no pbr-map PBRMAP [seq (1-700)]",
2269 "The name of the PBR MAP\n"
2270 "Sequence to delete from existing pbr-map entry\n"
2271 "Sequence number\n")
2272 #endif /* HAVE_PBRD */
2275 DEFUNSH(VTYSH_BFDD
, bfd_enter
, bfd_enter_cmd
, "bfd", "Configure BFD peers\n")
2277 vty
->node
= BFD_NODE
;
2281 DEFUNSH(VTYSH_BFDD
, bfd_peer_enter
, bfd_peer_enter_cmd
,
2282 "peer <A.B.C.D|X:X::X:X> [{multihop|local-address <A.B.C.D|X:X::X:X>|interface IFNAME|vrf NAME}]",
2284 "IPv4 peer address\n"
2285 "IPv6 peer address\n"
2286 "Configure multihop\n"
2287 "Configure local address\n"
2288 "IPv4 local address\n"
2289 "IPv6 local address\n"
2291 "Configure interface name to use\n"
2293 "Configure VRF name\n")
2295 vty
->node
= BFD_PEER_NODE
;
2299 DEFUNSH(VTYSH_BFDD
, bfd_profile_enter
, bfd_profile_enter_cmd
,
2302 BFD_PROFILE_NAME_STR
)
2304 vty
->node
= BFD_PROFILE_NODE
;
2307 #endif /* HAVE_BFDD */
2309 DEFUNSH(VTYSH_ALL
, vtysh_line_vty
, vtysh_line_vty_cmd
, "line vty",
2310 "Configure a terminal line\n"
2311 "Virtual terminal\n")
2313 vty
->node
= VTY_NODE
;
2317 DEFUNSH(VTYSH_REALLYALL
, vtysh_enable
, vtysh_enable_cmd
, "enable",
2318 "Turn on privileged mode command\n")
2320 vty
->node
= ENABLE_NODE
;
2324 DEFUNSH(VTYSH_REALLYALL
, vtysh_disable
, vtysh_disable_cmd
, "disable",
2325 "Turn off privileged mode command\n")
2327 if (vty
->node
== ENABLE_NODE
)
2328 vty
->node
= VIEW_NODE
;
2332 DEFUNSH(VTYSH_REALLYALL
, vtysh_config_terminal
, vtysh_config_terminal_cmd
,
2333 "configure [terminal]",
2334 "Configuration from vty interface\n"
2335 "Configuration terminal\n")
2337 vty
->node
= CONFIG_NODE
;
2341 static int vtysh_exit(struct vty
*vty
)
2343 struct cmd_node
*cnode
= vector_lookup(cmdvec
, vty
->node
);
2345 if (vty
->node
== VIEW_NODE
|| vty
->node
== ENABLE_NODE
)
2347 if (cnode
->node_exit
)
2348 cnode
->node_exit(vty
);
2349 if (cnode
->parent_node
)
2350 vty
->node
= cnode
->parent_node
;
2352 if (vty
->node
== CONFIG_NODE
) {
2353 /* resync in case one of the daemons is somewhere else */
2354 vtysh_execute("end");
2355 vtysh_execute("configure");
2360 DEFUNSH(VTYSH_REALLYALL
, vtysh_exit_all
, vtysh_exit_all_cmd
, "exit",
2361 "Exit current mode and down to previous mode\n")
2363 return vtysh_exit(vty
);
2366 DEFUNSH(VTYSH_REALLYALL
, vtysh_quit_all
, vtysh_quit_all_cmd
, "quit",
2367 "Exit current mode and down to previous mode\n")
2369 return vtysh_exit_all(self
, vty
, argc
, argv
);
2373 DEFUNSH(VTYSH_BGPD
, exit_address_family
, exit_address_family_cmd
,
2374 "exit-address-family", "Exit from Address Family configuration mode\n")
2376 if (vty
->node
== BGP_IPV4_NODE
|| vty
->node
== BGP_IPV4M_NODE
2377 || vty
->node
== BGP_IPV4L_NODE
|| vty
->node
== BGP_VPNV4_NODE
2378 || vty
->node
== BGP_VPNV6_NODE
|| vty
->node
== BGP_IPV6_NODE
2379 || vty
->node
== BGP_IPV6L_NODE
|| vty
->node
== BGP_IPV6M_NODE
2380 || vty
->node
== BGP_EVPN_NODE
2381 || vty
->node
== BGP_FLOWSPECV4_NODE
2382 || vty
->node
== BGP_FLOWSPECV6_NODE
)
2383 vty
->node
= BGP_NODE
;
2387 DEFUNSH(VTYSH_BGPD
, exit_vni
, exit_vni_cmd
, "exit-vni", "Exit from VNI mode\n")
2389 if (vty
->node
== BGP_EVPN_VNI_NODE
)
2390 vty
->node
= BGP_EVPN_NODE
;
2394 DEFUNSH(VTYSH_BGPD
, rpki_exit
, rpki_exit_cmd
, "exit",
2395 "Exit current mode and down to previous mode\n")
2401 DEFUNSH(VTYSH_BGPD
, rpki_quit
, rpki_quit_cmd
, "quit",
2402 "Exit current mode and down to previous mode\n")
2404 return rpki_exit(self
, vty
, argc
, argv
);
2407 DEFUNSH(VTYSH_BGPD
, bmp_exit
, bmp_exit_cmd
, "exit",
2408 "Exit current mode and down to previous mode\n")
2414 DEFUNSH(VTYSH_BGPD
, bmp_quit
, bmp_quit_cmd
, "quit",
2415 "Exit current mode and down to previous mode\n")
2417 return bmp_exit(self
, vty
, argc
, argv
);
2419 #endif /* HAVE_BGPD */
2421 DEFUNSH(VTYSH_VRF
, exit_vrf_config
, exit_vrf_config_cmd
, "exit-vrf",
2422 "Exit from VRF configuration mode\n")
2424 if (vty
->node
== VRF_NODE
)
2425 vty
->node
= CONFIG_NODE
;
2429 DEFUNSH(VTYSH_ZEBRA
, exit_srv6_config
, exit_srv6_config_cmd
, "exit",
2430 "Exit from SRv6 configuration mode\n")
2432 if (vty
->node
== SRV6_NODE
)
2433 vty
->node
= SEGMENT_ROUTING_NODE
;
2437 DEFUNSH(VTYSH_ZEBRA
, exit_srv6_locs_config
, exit_srv6_locs_config_cmd
, "exit",
2438 "Exit from SRv6-locator configuration mode\n")
2440 if (vty
->node
== SRV6_LOCS_NODE
)
2441 vty
->node
= SRV6_NODE
;
2445 DEFUNSH(VTYSH_ZEBRA
, exit_srv6_loc_config
, exit_srv6_loc_config_cmd
, "exit",
2446 "Exit from SRv6-locators configuration mode\n")
2448 if (vty
->node
== SRV6_LOC_NODE
)
2449 vty
->node
= SRV6_LOCS_NODE
;
2454 DEFUNSH(VTYSH_RIPD
, vtysh_exit_ripd
, vtysh_exit_ripd_cmd
, "exit",
2455 "Exit current mode and down to previous mode\n")
2457 return vtysh_exit(vty
);
2460 DEFUNSH(VTYSH_RIPD
, vtysh_quit_ripd
, vtysh_quit_ripd_cmd
, "quit",
2461 "Exit current mode and down to previous mode\n")
2463 return vtysh_exit_ripd(self
, vty
, argc
, argv
);
2465 #endif /* HAVE_RIPD */
2468 DEFUNSH(VTYSH_RIPNGD
, vtysh_exit_ripngd
, vtysh_exit_ripngd_cmd
, "exit",
2469 "Exit current mode and down to previous mode\n")
2471 return vtysh_exit(vty
);
2474 DEFUNSH(VTYSH_RIPNGD
, vtysh_quit_ripngd
, vtysh_quit_ripngd_cmd
, "quit",
2475 "Exit current mode and down to previous mode\n")
2477 return vtysh_exit_ripngd(self
, vty
, argc
, argv
);
2479 #endif /* HAVE_RIPNGD */
2481 DEFUNSH(VTYSH_RMAP
, vtysh_exit_rmap
, vtysh_exit_rmap_cmd
, "exit",
2482 "Exit current mode and down to previous mode\n")
2484 return vtysh_exit(vty
);
2487 DEFUNSH(VTYSH_RMAP
, vtysh_quit_rmap
, vtysh_quit_rmap_cmd
, "quit",
2488 "Exit current mode and down to previous mode\n")
2490 return vtysh_exit_rmap(self
, vty
, argc
, argv
);
2494 DEFUNSH(VTYSH_PBRD
, vtysh_exit_pbr_map
, vtysh_exit_pbr_map_cmd
, "exit",
2495 "Exit current mode and down to previous mode\n")
2497 return vtysh_exit(vty
);
2500 DEFUNSH(VTYSH_PBRD
, vtysh_quit_pbr_map
, vtysh_quit_pbr_map_cmd
, "quit",
2501 "Exit current mode and down to previous mode\n")
2503 return vtysh_exit_rmap(self
, vty
, argc
, argv
);
2505 #endif /* HAVE_PBRD */
2508 DEFUNSH(VTYSH_BGPD
, vtysh_exit_bgpd
, vtysh_exit_bgpd_cmd
, "exit",
2509 "Exit current mode and down to previous mode\n")
2511 return vtysh_exit(vty
);
2514 DEFUNSH(VTYSH_BGPD
, vtysh_quit_bgpd
, vtysh_quit_bgpd_cmd
, "quit",
2515 "Exit current mode and down to previous mode\n")
2517 return vtysh_exit_bgpd(self
, vty
, argc
, argv
);
2519 #endif /* HAVE_BGPD */
2522 DEFUNSH(VTYSH_OSPFD
, vtysh_exit_ospfd
, vtysh_exit_ospfd_cmd
, "exit",
2523 "Exit current mode and down to previous mode\n")
2525 return vtysh_exit(vty
);
2528 DEFUNSH(VTYSH_OSPFD
, vtysh_quit_ospfd
, vtysh_quit_ospfd_cmd
, "quit",
2529 "Exit current mode and down to previous mode\n")
2531 return vtysh_exit_ospfd(self
, vty
, argc
, argv
);
2533 #endif /* HAVE_OSPFD */
2536 DEFUNSH(VTYSH_EIGRPD
, vtysh_exit_eigrpd
, vtysh_exit_eigrpd_cmd
, "exit",
2537 "Exit current mode and down to previous mode\n")
2539 return vtysh_exit(vty
);
2542 DEFUNSH(VTYSH_EIGRPD
, vtysh_quit_eigrpd
, vtysh_quit_eigrpd_cmd
, "quit",
2543 "Exit current mode and down to previous mode\n")
2545 return vtysh_exit(vty
);
2547 #endif /* HAVE_EIGRPD */
2550 DEFUNSH(VTYSH_BABELD
, vtysh_exit_babeld
, vtysh_exit_babeld_cmd
, "exit",
2551 "Exit current mode and down to previous mode\n")
2553 return vtysh_exit(vty
);
2556 DEFUNSH(VTYSH_BABELD
, vtysh_quit_babeld
, vtysh_quit_babeld_cmd
, "quit",
2557 "Exit current mode and down to previous mode\n")
2559 return vtysh_exit(vty
);
2561 #endif /* HAVE_BABELD */
2564 DEFUNSH(VTYSH_OSPF6D
, vtysh_exit_ospf6d
, vtysh_exit_ospf6d_cmd
, "exit",
2565 "Exit current mode and down to previous mode\n")
2567 return vtysh_exit(vty
);
2570 DEFUNSH(VTYSH_OSPF6D
, vtysh_quit_ospf6d
, vtysh_quit_ospf6d_cmd
, "quit",
2571 "Exit current mode and down to previous mode\n")
2573 return vtysh_exit_ospf6d(self
, vty
, argc
, argv
);
2575 #endif /* HAVE_OSPF6D */
2577 #if defined(HAVE_LDPD)
2578 DEFUNSH(VTYSH_LDPD
, vtysh_exit_ldpd
, vtysh_exit_ldpd_cmd
, "exit",
2579 "Exit current mode and down to previous mode\n")
2581 return vtysh_exit(vty
);
2584 ALIAS(vtysh_exit_ldpd
, vtysh_quit_ldpd_cmd
, "quit",
2585 "Exit current mode and down to previous mode\n")
2589 DEFUNSH(VTYSH_ISISD
, vtysh_exit_isisd
, vtysh_exit_isisd_cmd
, "exit",
2590 "Exit current mode and down to previous mode\n")
2592 return vtysh_exit(vty
);
2595 DEFUNSH(VTYSH_ISISD
, vtysh_quit_isisd
, vtysh_quit_isisd_cmd
, "quit",
2596 "Exit current mode and down to previous mode\n")
2598 return vtysh_exit_isisd(self
, vty
, argc
, argv
);
2600 #endif /* HAVE_ISISD */
2603 DEFUNSH(VTYSH_BFDD
, vtysh_exit_bfdd
, vtysh_exit_bfdd_cmd
, "exit",
2604 "Exit current mode and down to previous mode\n")
2606 return vtysh_exit(vty
);
2609 ALIAS(vtysh_exit_bfdd
, vtysh_quit_bfdd_cmd
, "quit",
2610 "Exit current mode and down to previous mode\n")
2614 DEFUNSH(VTYSH_FABRICD
, vtysh_exit_fabricd
, vtysh_exit_fabricd_cmd
, "exit",
2615 "Exit current mode and down to previous mode\n")
2617 return vtysh_exit(vty
);
2620 DEFUNSH(VTYSH_FABRICD
, vtysh_quit_fabricd
, vtysh_quit_fabricd_cmd
, "quit",
2621 "Exit current mode and down to previous mode\n")
2623 return vtysh_exit_fabricd(self
, vty
, argc
, argv
);
2625 #endif /* HAVE_FABRICD */
2627 DEFUNSH(VTYSH_KEYS
, vtysh_exit_keys
, vtysh_exit_keys_cmd
, "exit",
2628 "Exit current mode and down to previous mode\n")
2630 return vtysh_exit(vty
);
2633 DEFUNSH(VTYSH_KEYS
, vtysh_quit_keys
, vtysh_quit_keys_cmd
, "quit",
2634 "Exit current mode and down to previous mode\n")
2636 return vtysh_exit_keys(self
, vty
, argc
, argv
);
2639 DEFUNSH(VTYSH_SR
, vtysh_exit_sr
, vtysh_exit_sr_cmd
, "exit",
2640 "Exit current mode and down to previous mode\n")
2642 return vtysh_exit(vty
);
2645 DEFUNSH(VTYSH_SR
, vtysh_quit_sr
, vtysh_quit_sr_cmd
, "quit",
2646 "Exit current mode and down to previous mode\n")
2648 return vtysh_exit(vty
);
2651 #if defined(HAVE_PATHD)
2652 DEFUNSH(VTYSH_PATHD
, vtysh_exit_pathd
, vtysh_exit_pathd_cmd
, "exit",
2653 "Exit current mode and down to previous mode\n")
2655 return vtysh_exit(vty
);
2658 DEFUNSH(VTYSH_PATHD
, vtysh_quit_pathd
, vtysh_quit_pathd_cmd
, "quit",
2659 "Exit current mode and down to previous mode\n")
2661 return vtysh_exit_pathd(self
, vty
, argc
, argv
);
2663 #endif /* HAVE_PATHD */
2665 DEFUNSH(VTYSH_ALL
, vtysh_exit_line_vty
, vtysh_exit_line_vty_cmd
, "exit",
2666 "Exit current mode and down to previous mode\n")
2668 return vtysh_exit(vty
);
2671 DEFUNSH(VTYSH_ALL
, vtysh_quit_line_vty
, vtysh_quit_line_vty_cmd
, "quit",
2672 "Exit current mode and down to previous mode\n")
2674 return vtysh_exit_line_vty(self
, vty
, argc
, argv
);
2677 DEFUNSH(VTYSH_INTERFACE
, vtysh_interface
, vtysh_interface_cmd
,
2678 "interface IFNAME [vrf NAME]",
2679 "Select an interface to configure\n"
2680 "Interface's name\n" VRF_CMD_HELP_STR
)
2682 vty
->node
= INTERFACE_NODE
;
2686 DEFUNSH(VTYSH_ZEBRA
, vtysh_pseudowire
, vtysh_pseudowire_cmd
,
2687 "pseudowire IFNAME",
2688 "Static pseudowire configuration\n"
2689 "Pseudowire name\n")
2691 vty
->node
= PW_NODE
;
2695 DEFUNSH(VTYSH_NH_GROUP
,
2696 vtysh_nexthop_group
, vtysh_nexthop_group_cmd
,
2697 "nexthop-group NHGNAME",
2698 "Nexthop Group configuration\n"
2699 "Name of the Nexthop Group\n")
2701 vty
->node
= NH_GROUP_NODE
;
2705 DEFSH(VTYSH_NH_GROUP
, vtysh_no_nexthop_group_cmd
,
2706 "no nexthop-group NHGNAME",
2708 "Nexthop Group Configuration\n"
2709 "Name of the Nexthop Group\n")
2711 DEFUNSH(VTYSH_VRF
, vtysh_vrf
, vtysh_vrf_cmd
, "vrf NAME",
2712 "Select a VRF to configure\n"
2715 vty
->node
= VRF_NODE
;
2719 DEFUNSH(VTYSH_VRF
, vtysh_exit_vrf
, vtysh_exit_vrf_cmd
, "exit",
2720 "Exit current mode and down to previous mode\n")
2722 return vtysh_exit(vty
);
2725 DEFUNSH(VTYSH_VRF
, vtysh_quit_vrf
, vtysh_quit_vrf_cmd
, "quit",
2726 "Exit current mode and down to previous mode\n")
2728 return vtysh_exit_vrf(self
, vty
, argc
, argv
);
2731 DEFUNSH(VTYSH_NH_GROUP
,
2732 vtysh_exit_nexthop_group
, vtysh_exit_nexthop_group_cmd
,
2733 "exit", "Exit current mode and down to previous mode\n")
2735 return vtysh_exit(vty
);
2738 DEFUNSH(VTYSH_NH_GROUP
,
2739 vtysh_quit_nexthop_group
, vtysh_quit_nexthop_group_cmd
,
2740 "quit", "Exit current mode and down to previous mode\n")
2742 return vtysh_exit_nexthop_group(self
, vty
, argc
, argv
);
2745 DEFUNSH(VTYSH_INTERFACE
, vtysh_exit_interface
, vtysh_exit_interface_cmd
, "exit",
2746 "Exit current mode and down to previous mode\n")
2748 return vtysh_exit(vty
);
2751 DEFUNSH(VTYSH_INTERFACE
, vtysh_quit_interface
, vtysh_quit_interface_cmd
, "quit",
2752 "Exit current mode and down to previous mode\n")
2754 return vtysh_exit_interface(self
, vty
, argc
, argv
);
2757 DEFUNSH(VTYSH_ZEBRA
, vtysh_exit_pseudowire
, vtysh_exit_pseudowire_cmd
, "exit",
2758 "Exit current mode and down to previous mode\n")
2760 return vtysh_exit(vty
);
2763 DEFUNSH(VTYSH_ZEBRA
, vtysh_quit_pseudowire
, vtysh_quit_pseudowire_cmd
, "quit",
2764 "Exit current mode and down to previous mode\n")
2766 return vtysh_exit_pseudowire(self
, vty
, argc
, argv
);
2769 static char *do_prepend(struct vty
*vty
, struct cmd_token
**argv
, int argc
)
2771 const char *argstr
[argc
+ 1];
2774 if (vty
->node
!= VIEW_NODE
) {
2779 for (i
= 0; i
< argc
; i
++)
2780 argstr
[i
+ off
] = argv
[i
]->arg
;
2782 return frrstr_join(argstr
, argc
+ off
, " ");
2785 #pragma GCC diagnostic push
2786 #pragma GCC diagnostic ignored "-Wformat-nonliteral"
2787 /* 'headline' is a format string with a %s for the daemon name
2789 * Also for some reason GCC emits the warning on the end of the function
2790 * (optimization maybe?) rather than on the vty_out line, so this pragma
2791 * wraps the entire function rather than just the vty_out line.
2794 static int show_per_daemon(struct vty
*vty
, struct cmd_token
**argv
, int argc
,
2795 const char *headline
)
2798 int ret
= CMD_SUCCESS
;
2799 char *line
= do_prepend(vty
, argv
, argc
);
2801 for (i
= 0; i
< array_size(vtysh_client
); i
++)
2802 if (vtysh_client
[i
].fd
>= 0 || vtysh_client
[i
].next
) {
2803 vty_out(vty
, headline
, vtysh_client
[i
].name
);
2804 ret
= vtysh_client_execute(&vtysh_client
[i
], line
);
2808 XFREE(MTYPE_TMP
, line
);
2812 #pragma GCC diagnostic pop
2814 static int show_one_daemon(struct vty
*vty
, struct cmd_token
**argv
, int argc
,
2818 char *line
= do_prepend(vty
, argv
, argc
);
2820 ret
= vtysh_client_execute_name(name
, line
);
2822 XFREE(MTYPE_TMP
, line
);
2827 DEFUN (vtysh_show_thread_timer
,
2828 vtysh_show_thread_timer_cmd
,
2829 "show thread timers",
2831 "Thread information\n"
2832 "Show all timers and how long they have in the system\n")
2834 return show_per_daemon(vty
, argv
, argc
, "Thread timers for %s:\n");
2837 DEFUN (vtysh_show_poll
,
2838 vtysh_show_poll_cmd
,
2841 "Thread information\n"
2842 "Thread Poll Information\n")
2844 return show_per_daemon(vty
, argv
, argc
, "Thread statistics for %s:\n");
2847 DEFUN (vtysh_show_thread
,
2848 vtysh_show_thread_cmd
,
2849 "show thread cpu [FILTER]",
2851 "Thread information\n"
2852 "Thread CPU usage\n"
2853 "Display filter (rwtexb)\n")
2855 return show_per_daemon(vty
, argv
, argc
, "Thread statistics for %s:\n");
2858 DEFUN (vtysh_show_work_queues
,
2859 vtysh_show_work_queues_cmd
,
2862 "Work Queue information\n")
2864 return show_per_daemon(vty
, argv
, argc
,
2865 "Work queue statistics for %s:\n");
2868 DEFUN (vtysh_show_work_queues_daemon
,
2869 vtysh_show_work_queues_daemon_cmd
,
2870 "show work-queues " DAEMONS_LIST
,
2872 "Work Queue information\n"
2875 return show_one_daemon(vty
, argv
, argc
- 1, argv
[argc
- 1]->text
);
2878 DEFUNSH(VTYSH_ZEBRA
, vtysh_link_params
, vtysh_link_params_cmd
, "link-params",
2881 vty
->node
= LINK_PARAMS_NODE
;
2885 DEFUNSH(VTYSH_ZEBRA
, exit_link_params
, exit_link_params_cmd
, "exit-link-params",
2886 "Exit from Link Params configuration node\n")
2888 if (vty
->node
== LINK_PARAMS_NODE
)
2889 vty
->node
= INTERFACE_NODE
;
2893 DEFUNSH(VTYSH_ZEBRA
, vtysh_exit_link_params
, vtysh_exit_link_params_cmd
, "exit",
2894 "Exit current mode and down to previous mode\n")
2896 if (vty
->node
== LINK_PARAMS_NODE
)
2897 vty
->node
= INTERFACE_NODE
;
2901 DEFUNSH(VTYSH_ZEBRA
, vtysh_quit_link_params
, vtysh_quit_link_params_cmd
, "quit",
2902 "Exit current mode and down to previous mode\n")
2904 return vtysh_exit_link_params(self
, vty
, argc
, argv
);
2907 DEFUNSH_HIDDEN (0x00,
2909 vtysh_debug_all_cmd
,
2913 "Toggle all debugs on or off\n")
2918 DEFUN (vtysh_show_debugging
,
2919 vtysh_show_debugging_cmd
,
2924 return show_per_daemon(vty
, argv
, argc
, "");
2927 DEFUN (vtysh_show_debugging_hashtable
,
2928 vtysh_show_debugging_hashtable_cmd
,
2929 "show debugging hashtable [statistics]",
2932 "Statistics about hash tables\n"
2933 "Statistics about hash tables\n")
2935 bool stats
= strmatch(argv
[argc
- 1]->text
, "statistics");
2939 "Load factor (LF) - average number of elements across all buckets\n");
2941 "Full load factor (FLF) - average number of elements across full buckets\n\n");
2943 "Standard deviation (SD) is calculated for both the LF and FLF\n");
2945 "and indicates the typical deviation of bucket chain length\n");
2946 vty_out(vty
, "from the value in the corresponding load factor.\n\n");
2948 return show_per_daemon(vty
, argv
, stats
? argc
- 1 : argc
,
2949 "Hashtable statistics for %s:\n");
2952 DEFUN (vtysh_show_error_code
,
2953 vtysh_show_error_code_cmd
,
2954 "show error <(1-4294967296)|all> [json]",
2956 "Information on errors\n"
2957 "Error code to get info about\n"
2958 "Information on all errors\n"
2963 if (!strmatch(argv
[2]->text
, "all"))
2964 arg
= strtoul(argv
[2]->arg
, NULL
, 10);
2966 /* If it's not a shared code, send it to all the daemons */
2967 if (arg
< LIB_FERR_START
|| arg
> LIB_FERR_END
) {
2968 show_per_daemon(vty
, argv
, argc
, "");
2969 /* Otherwise, print it ourselves to avoid duplication */
2971 bool json
= strmatch(argv
[argc
- 1]->text
, "json");
2973 if (!strmatch(argv
[2]->text
, "all"))
2974 arg
= strtoul(argv
[2]->arg
, NULL
, 10);
2976 log_ref_display(vty
, arg
, json
);
2983 DEFUN_HIDDEN (show_config_running
,
2984 show_config_running_cmd
,
2985 "show configuration running\
2986 [<json|xml> [translate WORD]]\
2987 [with-defaults] " DAEMONS_LIST
,
2989 "Configuration information\n"
2990 "Running configuration\n"
2991 "Change output format to JSON\n"
2992 "Change output format to XML\n"
2993 "Translate output\n"
2994 "YANG module translator\n"
2995 "Show default values\n"
2998 return show_one_daemon(vty
, argv
, argc
- 1, argv
[argc
- 1]->text
);
3001 DEFUN (show_yang_operational_data
,
3002 show_yang_operational_data_cmd
,
3003 "show yang operational-data XPATH\
3010 "YANG information\n"
3011 "Show YANG operational data\n"
3012 "XPath expression specifying the YANG data path\n"
3013 "Set the output format\n"
3014 "JavaScript Object Notation\n"
3015 "Extensible Markup Language\n"
3016 "Translate operational data\n"
3017 "YANG module translator\n"
3018 "Merge configuration data\n"
3021 return show_one_daemon(vty
, argv
, argc
- 1, argv
[argc
- 1]->text
);
3024 DEFUN(show_yang_module
, show_yang_module_cmd
,
3025 "show yang module [module-translator WORD] " DAEMONS_LIST
,
3027 "YANG information\n"
3028 "Show loaded modules\n"
3029 "YANG module translator\n"
3030 "YANG module translator\n" DAEMONS_STR
)
3032 return show_one_daemon(vty
, argv
, argc
- 1, argv
[argc
- 1]->text
);
3035 DEFUN(show_yang_module_detail
, show_yang_module_detail_cmd
,
3037 [module-translator WORD]\
3038 WORD <compiled|summary|tree|yang|yin> " DAEMONS_LIST
,
3040 "YANG information\n"
3041 "Show loaded modules\n"
3042 "YANG module translator\n"
3043 "YANG module translator\n"
3045 "Display compiled module in YANG format\n"
3046 "Display summary information about the module\n"
3047 "Display module in the tree (RFC 8340) format\n"
3048 "Display module in the YANG format\n"
3049 "Display module in the YIN format\n" DAEMONS_STR
)
3051 return show_one_daemon(vty
, argv
, argc
- 1, argv
[argc
- 1]->text
);
3055 DEFUNSH(VTYSH_ALL
, debug_nb
,
3057 "[no] debug northbound\
3059 callbacks [{configuration|state|rpc}]\
3066 "Northbound debugging\n"
3073 "libyang debugging\n")
3078 DEFUN (vtysh_show_history
,
3079 vtysh_show_history_cmd
,
3082 "The list of commands stored in history\n")
3084 HIST_ENTRY
**hlist
= history_list();
3088 vty_out(vty
, "%s\n", hlist
[i
]->line
);
3095 DEFUN (vtysh_show_memory
,
3096 vtysh_show_memory_cmd
,
3097 "show memory [" DAEMONS_LIST
"]",
3099 "Memory statistics\n"
3103 return show_one_daemon(vty
, argv
, argc
- 1,
3104 argv
[argc
- 1]->text
);
3106 return show_per_daemon(vty
, argv
, argc
, "Memory statistics for %s:\n");
3109 DEFUN (vtysh_show_modules
,
3110 vtysh_show_modules_cmd
,
3115 return show_per_daemon(vty
, argv
, argc
, "Module information for %s:\n");
3118 /* Logging commands. */
3119 DEFUN (vtysh_show_logging
,
3120 vtysh_show_logging_cmd
,
3123 "Show current logging configuration\n")
3125 return show_per_daemon(vty
, argv
, argc
,
3126 "Logging configuration for %s:\n");
3129 DEFUNSH(VTYSH_ALL
, vtysh_debug_memstats
,
3130 vtysh_debug_memstats_cmd
, "[no] debug memstats-at-exit",
3133 "Print memory statistics at exit\n")
3138 DEFUN(vtysh_debug_uid_backtrace
,
3139 vtysh_debug_uid_backtrace_cmd
,
3140 "[no] debug unique-id UID backtrace",
3143 "Options per individual log message, by unique ID\n"
3144 "Log message unique ID (XXXXX-XXXXX)\n"
3145 "Add backtrace to log when message is printed\n")
3147 unsigned int i
, ok
= 0;
3148 int err
= CMD_SUCCESS
, ret
;
3152 if (!strcmp(argv
[0]->text
, "no")) {
3154 snprintfrr(line
, sizeof(line
),
3155 "no debug unique-id %s backtrace", uid
);
3158 snprintfrr(line
, sizeof(line
), "debug unique-id %s backtrace",
3162 for (i
= 0; i
< array_size(vtysh_client
); i
++)
3163 if (vtysh_client
[i
].fd
>= 0 || vtysh_client
[i
].next
) {
3164 ret
= vtysh_client_execute(&vtysh_client
[i
], line
);
3169 case CMD_ERR_NOTHING_TODO
:
3170 /* ignore this daemon
3172 * note this doesn't need to handle instances
3173 * of the same daemon individually because
3174 * the same daemon will have the same UIDs
3178 if (err
== CMD_SUCCESS
)
3184 if (err
== CMD_SUCCESS
&& !ok
) {
3185 vty_out(vty
, "%% no running daemon recognizes unique-ID %s\n",
3192 DEFUNSH(VTYSH_ALL
, vtysh_allow_reserved_ranges
, vtysh_allow_reserved_ranges_cmd
,
3193 "allow-reserved-ranges",
3194 "Allow using IPv4 (Class E) reserved IP space\n")
3199 DEFUNSH(VTYSH_ALL
, no_vtysh_allow_reserved_ranges
,
3200 no_vtysh_allow_reserved_ranges_cmd
, "no allow-reserved-ranges",
3201 NO_STR
"Allow using IPv4 (Class E) reserved IP space\n")
3206 DEFUNSH(VTYSH_ALL
, vtysh_service_password_encrypt
,
3207 vtysh_service_password_encrypt_cmd
, "service password-encryption",
3208 "Set up miscellaneous service\n"
3209 "Enable encrypted passwords\n")
3214 DEFUNSH(VTYSH_ALL
, no_vtysh_service_password_encrypt
,
3215 no_vtysh_service_password_encrypt_cmd
, "no service password-encryption",
3217 "Set up miscellaneous service\n"
3218 "Enable encrypted passwords\n")
3223 DEFUNSH(VTYSH_ALL
, vtysh_config_password
, vtysh_password_cmd
,
3224 "password [(8-8)] LINE",
3225 "Modify the terminal connection password\n"
3226 "Specifies a HIDDEN password will follow\n"
3227 "The password string\n")
3232 DEFUNSH(VTYSH_ALL
, no_vtysh_config_password
, no_vtysh_password_cmd
,
3233 "no password", NO_STR
3234 "Modify the terminal connection password\n")
3236 vty_out(vty
, NO_PASSWD_CMD_WARNING
);
3241 DEFUNSH(VTYSH_ALL
, vtysh_config_enable_password
, vtysh_enable_password_cmd
,
3242 "enable password [(8-8)] LINE",
3243 "Modify enable password parameters\n"
3244 "Assign the privileged level password\n"
3245 "Specifies a HIDDEN password will follow\n"
3246 "The 'enable' password string\n")
3251 DEFUNSH(VTYSH_ALL
, no_vtysh_config_enable_password
,
3252 no_vtysh_enable_password_cmd
, "no enable password", NO_STR
3253 "Modify enable password parameters\n"
3254 "Assign the privileged level password\n")
3256 vty_out(vty
, NO_PASSWD_CMD_WARNING
);
3261 DEFUN (vtysh_write_terminal
,
3262 vtysh_write_terminal_cmd
,
3263 "write terminal ["DAEMONS_LIST
"] [no-header]",
3264 "Write running configuration to memory, network, or terminal\n"
3265 "Write to terminal\n"
3267 "Skip \"Building configuration...\" header\n")
3270 char line
[] = "do write terminal";
3272 if (!strcmp(argv
[argc
- 1]->arg
, "no-header"))
3275 vty_out(vty
, "Building configuration...\n");
3276 vty_out(vty
, "\nCurrent configuration:\n");
3277 vty_out(vty
, "!\n");
3280 for (i
= 0; i
< array_size(vtysh_client
); i
++)
3282 || (strmatch(vtysh_client
[i
].name
, argv
[2]->text
)))
3283 vtysh_client_config(&vtysh_client
[i
], line
);
3285 /* Integrate vtysh specific configuration. */
3286 vty_open_pager(vty
);
3287 vtysh_config_write();
3288 vtysh_config_dump();
3289 vty_close_pager(vty
);
3290 vty_out(vty
, "end\n");
3295 DEFUN (vtysh_show_running_config
,
3296 vtysh_show_running_config_cmd
,
3297 "show running-config ["DAEMONS_LIST
"] [no-header]",
3299 "Current operating configuration\n"
3301 "Skip \"Building configuration...\" header\n")
3303 return vtysh_write_terminal(self
, vty
, argc
, argv
);
3306 DEFUN (vtysh_integrated_config
,
3307 vtysh_integrated_config_cmd
,
3308 "service integrated-vtysh-config",
3309 "Set up miscellaneous service\n"
3310 "Write configuration into integrated file\n")
3312 vtysh_write_integrated
= WRITE_INTEGRATED_YES
;
3316 DEFUN (no_vtysh_integrated_config
,
3317 no_vtysh_integrated_config_cmd
,
3318 "no service integrated-vtysh-config",
3320 "Set up miscellaneous service\n"
3321 "Write configuration into integrated file\n")
3323 vtysh_write_integrated
= WRITE_INTEGRATED_NO
;
3327 static void backup_config_file(const char *fbackup
)
3329 char *integrate_sav
= NULL
;
3331 size_t integrate_sav_sz
= strlen(fbackup
) + strlen(CONF_BACKUP_EXT
) + 1;
3332 integrate_sav
= malloc(integrate_sav_sz
);
3333 strlcpy(integrate_sav
, fbackup
, integrate_sav_sz
);
3334 strlcat(integrate_sav
, CONF_BACKUP_EXT
, integrate_sav_sz
);
3336 /* Move current configuration file to backup config file. */
3337 if (unlink(integrate_sav
) != 0 && errno
!= ENOENT
)
3338 vty_out(vty
, "Unlink failed for %s: %s\n", integrate_sav
,
3340 if (rename(fbackup
, integrate_sav
) != 0 && errno
!= ENOENT
)
3341 vty_out(vty
, "Error renaming %s to %s: %s\n", fbackup
,
3342 integrate_sav
, strerror(errno
));
3343 free(integrate_sav
);
3346 int vtysh_write_config_integrated(void)
3349 char line
[] = "do write terminal";
3353 struct passwd
*pwentry
;
3356 struct group
*grentry
;
3363 vty_out(vty
, "Building Configuration...\n");
3365 backup_config_file(frr_config
);
3366 fp
= fopen(frr_config
, "w");
3369 "%% Error: failed to open configuration file %s: %s\n",
3370 frr_config
, safe_strerror(errno
));
3371 return CMD_WARNING_CONFIG_FAILED
;
3375 for (i
= 0; i
< array_size(vtysh_client
); i
++)
3376 vtysh_client_config(&vtysh_client
[i
], line
);
3378 vtysh_config_write();
3379 vty
->of_saved
= vty
->of
;
3381 vtysh_config_dump();
3382 vty
->of
= vty
->of_saved
;
3384 if (fchmod(fd
, CONFIGFILE_MASK
) != 0) {
3385 printf("%% Warning: can't chmod configuration file %s: %s\n",
3386 frr_config
, safe_strerror(errno
));
3391 pwentry
= getpwnam(FRR_USER
);
3393 uid
= pwentry
->pw_uid
;
3395 printf("%% Warning: could not look up user \"%s\"\n", FRR_USER
);
3400 grentry
= getgrnam(FRR_GROUP
);
3402 gid
= grentry
->gr_gid
;
3404 printf("%% Warning: could not look up group \"%s\"\n",
3410 if (!fstat(fd
, &st
)) {
3411 if (st
.st_uid
== uid
)
3413 if (st
.st_gid
== gid
)
3415 if ((uid
!= (uid_t
)-1 || gid
!= (gid_t
)-1)
3416 && fchown(fd
, uid
, gid
)) {
3417 printf("%% Warning: can't chown configuration file %s: %s\n",
3418 frr_config
, safe_strerror(errno
));
3422 printf("%% Warning: stat() failed on %s: %s\n", frr_config
,
3423 safe_strerror(errno
));
3427 if (fflush(fp
) != 0) {
3428 printf("%% Warning: fflush() failed on %s: %s\n", frr_config
,
3429 safe_strerror(errno
));
3433 if (fsync(fd
) < 0) {
3434 printf("%% Warning: fsync() failed on %s: %s\n", frr_config
,
3435 safe_strerror(errno
));
3441 printf("Integrated configuration saved to %s\n", frr_config
);
3449 DEFUN_HIDDEN(start_config
, start_config_cmd
, "XFRR_start_configuration",
3450 "The Beginning of Configuration\n")
3453 char line
[] = "XFRR_start_configuration";
3455 for (i
= 0; i
< array_size(vtysh_client
); i
++)
3456 vtysh_client_execute(&vtysh_client
[i
], line
);
3461 DEFUN_HIDDEN(end_config
, end_config_cmd
, "XFRR_end_configuration",
3462 "The End of Configuration\n")
3465 char line
[] = "XFRR_end_configuration";
3467 for (i
= 0; i
< array_size(vtysh_client
); i
++)
3468 vtysh_client_execute(&vtysh_client
[i
], line
);
3473 static bool want_config_integrated(void)
3477 switch (vtysh_write_integrated
) {
3478 case WRITE_INTEGRATED_UNSPECIFIED
:
3479 if (stat(frr_config
, &s
) && errno
== ENOENT
)
3482 case WRITE_INTEGRATED_NO
:
3484 case WRITE_INTEGRATED_YES
:
3490 DEFUN (vtysh_write_memory
,
3491 vtysh_write_memory_cmd
,
3492 "write [<memory|file>]",
3493 "Write running configuration to memory, network, or terminal\n"
3494 "Write configuration to the file (same as write file)\n"
3495 "Write configuration to the file (same as write memory)\n")
3497 int ret
= CMD_SUCCESS
;
3498 char line
[] = "do write memory";
3501 vty_out(vty
, "Note: this version of vtysh never writes vtysh.conf\n");
3503 /* If integrated frr.conf explicitly set. */
3504 if (want_config_integrated()) {
3505 ret
= CMD_WARNING_CONFIG_FAILED
;
3507 /* first attempt to use watchfrr if it's available */
3508 bool used_watchfrr
= false;
3510 for (i
= 0; i
< array_size(vtysh_client
); i
++)
3511 if (vtysh_client
[i
].flag
== VTYSH_WATCHFRR
)
3513 if (i
< array_size(vtysh_client
) && vtysh_client
[i
].fd
!= -1) {
3514 used_watchfrr
= true;
3515 ret
= vtysh_client_execute(&vtysh_client
[i
],
3516 "do write integrated");
3520 * If we didn't use watchfrr, fallback to writing the config
3523 if (!used_watchfrr
) {
3524 printf("\nWarning: attempting direct configuration write without watchfrr.\nFile permissions and ownership may be incorrect, or write may fail.\n\n");
3525 ret
= vtysh_write_config_integrated();
3530 vty_out(vty
, "Building Configuration...\n");
3532 for (i
= 0; i
< array_size(vtysh_client
); i
++)
3533 ret
= vtysh_client_execute(&vtysh_client
[i
], line
);
3538 DEFUN (vtysh_copy_running_config
,
3539 vtysh_copy_running_config_cmd
,
3540 "copy running-config startup-config",
3541 "Copy from one file to another\n"
3542 "Copy from current system configuration\n"
3543 "Copy to startup configuration\n")
3545 return vtysh_write_memory(self
, vty
, argc
, argv
);
3548 DEFUN (vtysh_copy_to_running
,
3549 vtysh_copy_to_running_cmd
,
3550 "copy FILENAME running-config",
3551 "Apply a configuration file\n"
3552 "Configuration file to read\n"
3553 "Apply to current configuration\n")
3556 const char *fname
= argv
[1]->arg
;
3558 ret
= vtysh_read_config(fname
, true);
3560 /* Return to enable mode - the 'read_config' api leaves us up a level */
3561 vtysh_execute_no_pager("enable");
3566 DEFUN (vtysh_terminal_paginate
,
3567 vtysh_terminal_paginate_cmd
,
3568 "[no] terminal paginate",
3570 "Set terminal line parameters\n"
3571 "Use pager for output scrolling\n")
3573 free(vtysh_pager_name
);
3574 vtysh_pager_name
= NULL
;
3576 if (strcmp(argv
[0]->text
, "no"))
3577 vtysh_pager_envdef(true);
3581 DEFUN (vtysh_terminal_length
,
3582 vtysh_terminal_length_cmd
,
3583 "[no] terminal length (0-4294967295)",
3585 "Set terminal line parameters\n"
3586 "Set number of lines on a screen\n"
3587 "Number of lines on screen (0 for no pausing, nonzero to use pager)\n")
3590 unsigned long lines
;
3592 free(vtysh_pager_name
);
3593 vtysh_pager_name
= NULL
;
3595 if (!strcmp(argv
[0]->text
, "no") || !strcmp(argv
[1]->text
, "no")) {
3596 /* "terminal no length" = use VTYSH_PAGER */
3597 vtysh_pager_envdef(true);
3601 lines
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
3604 "%% The \"terminal length\" command is deprecated and its value is ignored.\n"
3605 "%% Please use \"terminal paginate\" instead with OS TTY length handling.\n");
3606 vtysh_pager_envdef(true);
3612 ALIAS_DEPRECATED(vtysh_terminal_length
,
3613 vtysh_terminal_no_length_cmd
,
3614 "terminal no length",
3615 "Set terminal line parameters\n"
3617 "Set number of lines on a screen\n")
3619 DEFUN (vtysh_show_daemons
,
3620 vtysh_show_daemons_cmd
,
3623 "Show list of running daemons\n")
3627 for (i
= 0; i
< array_size(vtysh_client
); i
++)
3628 if (vtysh_client
[i
].fd
>= 0)
3629 vty_out(vty
, " %s", vtysh_client
[i
].name
);
3635 struct visual_prio
{
3636 /* 4 characters for nice alignment */
3639 int c256_background
;
3643 /* clang-format off */
3644 struct visual_prio visual_prios
[] = {
3646 .label
= "\e[31;1mEMRG",
3647 .c256_background
= 53,
3648 .c256_formatarg
= 225,
3651 .label
= "\e[31;1mALRT",
3652 .c256_background
= 53,
3653 .c256_formatarg
= 225,
3656 .label
= "\e[31;1mCRIT",
3657 .c256_background
= 53,
3658 .c256_formatarg
= 225,
3661 .label
= "\e[38;5;202mERR!",
3662 .c256_background
= 52,
3663 .c256_formatarg
= 224,
3666 .label
= "\e[38;5;222mWARN",
3667 .c256_background
= 58,
3668 .c256_formatarg
= 230,
3672 .c256_background
= 234,
3673 .c256_formatarg
= 195,
3676 .label
= "\e[38;5;192mINFO",
3677 .c256_background
= 236,
3678 .c256_formatarg
= 195,
3681 .label
= "\e[38;5;116mDEBG",
3682 .c256_background
= 238,
3683 .c256_formatarg
= 195,
3686 /* clang-format on */
3688 static void vtysh_log_print(struct vtysh_client
*vclient
,
3689 struct zlog_live_hdr
*hdr
, const char *text
)
3691 size_t textlen
= hdr
->textlen
, textpos
= 0;
3692 time_t ts
= hdr
->ts_sec
;
3693 struct visual_prio
*vis
;
3697 if (hdr
->prio
>= array_size(visual_prios
))
3698 vis
= &visual_prios
[LOG_CRIT
];
3700 vis
= &visual_prios
[hdr
->prio
];
3702 localtime_r(&ts
, &tm
);
3703 strftime(ts_buf
, sizeof(ts_buf
), "%Y-%m-%d %H:%M:%S", &tm
);
3706 const char *label
= vis
->label
+ strlen(vis
->label
) - 4;
3708 fprintf(stderr
, "%s.%03u [%s] %s: %.*s\n", ts_buf
,
3709 hdr
->ts_nsec
/ 1000000U, label
, vclient
->name
,
3710 (int)textlen
, text
);
3715 "\e[48;5;%dm\e[38;5;247m%s.%03u [%s\e[38;5;247m] \e[38;5;255m%s\e[38;5;247m: \e[38;5;251m",
3716 vis
->c256_background
, ts_buf
, hdr
->ts_nsec
/ 1000000U,
3717 vis
->label
, vclient
->name
);
3719 for (size_t fmtpos
= 0; fmtpos
< hdr
->n_argpos
; fmtpos
++) {
3720 struct fmt_outpos
*fmt
= &hdr
->argpos
[fmtpos
];
3722 if (fmt
->off_start
< textpos
|| fmt
->off_end
< fmt
->off_start
||
3723 fmt
->off_end
> textlen
)
3726 while (fmt
->off_end
> fmt
->off_start
&&
3727 text
[fmt
->off_end
- 1] == ' ')
3730 fprintf(stderr
, "%.*s\e[38;5;%dm%.*s\e[38;5;251m",
3731 (int)(fmt
->off_start
- textpos
), text
+ textpos
,
3732 vis
->c256_formatarg
,
3733 (int)(fmt
->off_end
- fmt
->off_start
),
3734 text
+ fmt
->off_start
);
3735 textpos
= fmt
->off_end
;
3737 fprintf(stderr
, "%.*s\033[K\033[m\n", (int)(textlen
- textpos
),
3741 static void vtysh_log_read(struct thread
*thread
)
3743 struct vtysh_client
*vclient
= THREAD_ARG(thread
);
3745 struct zlog_live_hdr hdr
;
3751 thread_add_read(master
, vtysh_log_read
, vclient
, vclient
->log_fd
,
3752 &vclient
->log_reader
);
3754 ret
= recv(vclient
->log_fd
, &buf
, sizeof(buf
), 0);
3756 if (ret
< 0 && ERRNO_IO_RETRY(errno
))
3759 if (stderr_stdout_same
) {
3760 #ifdef HAVE_RL_CLEAR_VISIBLE_LINE
3761 rl_clear_visible_line();
3771 buf
.text
[0] = '\0'; /* coverity */
3774 snprintfrr(buf
.text
, sizeof(buf
.text
),
3775 "log monitor connection error: %m");
3778 buf
.text
, sizeof(buf
.text
),
3779 "log monitor connection closed unexpectedly");
3780 buf
.hdr
.textlen
= strlen(buf
.text
);
3782 THREAD_OFF(vclient
->log_reader
);
3783 close(vclient
->log_fd
);
3784 vclient
->log_fd
= -1;
3786 clock_gettime(CLOCK_REALTIME
, &ts
);
3787 buf
.hdr
.ts_sec
= ts
.tv_sec
;
3788 buf
.hdr
.ts_nsec
= ts
.tv_nsec
;
3789 buf
.hdr
.prio
= LOG_ERR
;
3791 buf
.hdr
.texthdrlen
= 0;
3792 buf
.hdr
.n_argpos
= 0;
3794 int32_t lost_msgs
= buf
.hdr
.lost_msgs
- vclient
->lost_msgs
;
3796 if (lost_msgs
> 0) {
3797 vclient
->lost_msgs
= buf
.hdr
.lost_msgs
;
3799 "%d log messages from %s lost (vtysh reading too slowly)\n",
3800 lost_msgs
, vclient
->name
);
3804 text
= buf
.text
+ sizeof(buf
.hdr
.argpos
[0]) * buf
.hdr
.n_argpos
;
3805 vtysh_log_print(vclient
, &buf
.hdr
, text
);
3807 if (stderr_stdout_same
)
3808 rl_forced_update_display();
3814 /* clippy/clidef can't process the DEFPY below without some value for this */
3815 #define DAEMONS_LIST "daemon"
3818 DEFPY (vtysh_terminal_monitor
,
3819 vtysh_terminal_monitor_cmd
,
3820 "terminal monitor ["DAEMONS_LIST
"]$daemon",
3821 "Set terminal line parameters\n"
3822 "Receive log messages to active VTY session\n"
3825 static const char line
[] = "terminal monitor";
3826 int ret_all
= CMD_SUCCESS
, ret
, fd
;
3829 for (i
= 0; i
< array_size(vtysh_client
); i
++) {
3830 struct vtysh_client
*vclient
= &vtysh_client
[i
];
3832 if (daemon
&& strcmp(vclient
->name
, daemon
))
3835 for (; vclient
; vclient
= vclient
->next
) {
3836 if (vclient
->log_fd
!= -1) {
3837 vty_out(vty
, "%% %s: already monitoring logs\n",
3844 ret
= vtysh_client_run(vclient
, line
, NULL
, NULL
, &fd
);
3846 set_nonblocking(fd
);
3847 vclient
->log_fd
= fd
;
3848 thread_add_read(master
, vtysh_log_read
, vclient
,
3850 &vclient
->log_reader
);
3852 if (ret
!= CMD_SUCCESS
) {
3853 vty_out(vty
, "%% failed to enable logs on %s\n",
3855 ret_all
= CMD_WARNING
;
3861 if (!ok
&& ret_all
== CMD_SUCCESS
) {
3863 "%% command had no effect, relevant daemons not connected?\n");
3864 ret_all
= CMD_WARNING
;
3869 DEFPY (no_vtysh_terminal_monitor
,
3870 no_vtysh_terminal_monitor_cmd
,
3871 "no terminal monitor ["DAEMONS_LIST
"]$daemon",
3873 "Set terminal line parameters\n"
3874 "Receive log messages to active VTY session\n"
3877 static const char line
[] = "no terminal monitor";
3878 int ret_all
= CMD_SUCCESS
, ret
;
3881 for (i
= 0; i
< array_size(vtysh_client
); i
++) {
3882 struct vtysh_client
*vclient
= &vtysh_client
[i
];
3884 if (daemon
&& strcmp(vclient
->name
, daemon
))
3887 for (; vclient
; vclient
= vclient
->next
) {
3888 /* run this even if log_fd == -1, in case something
3891 ret
= vtysh_client_run(vclient
, line
, NULL
, NULL
, NULL
);
3892 if (ret
!= CMD_SUCCESS
) {
3894 "%% failed to disable logs on %s\n",
3896 ret_all
= CMD_WARNING
;
3900 /* with this being a datagram socket, we can't expect
3901 * a close notification...
3903 if (vclient
->log_fd
!= -1) {
3904 THREAD_OFF(vclient
->log_reader
);
3906 close(vclient
->log_fd
);
3907 vclient
->log_fd
= -1;
3912 if (!ok
&& ret_all
== CMD_SUCCESS
) {
3914 "%% command had no effect, relevant daemons not connected?\n");
3915 ret_all
= CMD_WARNING
;
3921 /* Execute command in child process. */
3922 static void execute_command(const char *command
, int argc
, const char *arg1
,
3932 /* Failure of fork(). */
3933 fprintf(stderr
, "Can't fork: %s\n", safe_strerror(errno
));
3935 } else if (pid
== 0) {
3936 /* This is child process. */
3939 execlp(command
, command
, (const char *)NULL
);
3942 execlp(command
, command
, arg1
, (const char *)NULL
);
3945 execlp(command
, command
, arg1
, arg2
,
3946 (const char *)NULL
);
3950 /* When execlp suceed, this part is not executed. */
3951 fprintf(stderr
, "Can't execute %s: %s\n", command
,
3952 safe_strerror(errno
));
3955 /* This is parent. */
3957 wait4(pid
, &status
, 0, NULL
);
3965 "Send echo messages\n"
3966 "Ping destination address or hostname\n")
3970 argv_find(argv
, argc
, "WORD", &idx
);
3971 execute_command("ping", 1, argv
[idx
]->arg
, NULL
);
3975 DEFUN(vtysh_motd
, vtysh_motd_cmd
, "show motd", SHOW_STR
"Show motd\n")
3981 ALIAS(vtysh_ping
, vtysh_ping_ip_cmd
, "ping ip WORD",
3982 "Send echo messages\n"
3984 "Ping destination address or hostname\n")
3986 DEFUN (vtysh_traceroute
,
3987 vtysh_traceroute_cmd
,
3989 "Trace route to destination\n"
3990 "Trace route to destination address or hostname\n")
3994 argv_find(argv
, argc
, "WORD", &idx
);
3995 execute_command("traceroute", 1, argv
[idx
]->arg
, NULL
);
3999 ALIAS(vtysh_traceroute
, vtysh_traceroute_ip_cmd
, "traceroute ip WORD",
4000 "Trace route to destination\n"
4002 "Trace route to destination address or hostname\n")
4004 DEFUN (vtysh_mtrace
,
4006 "mtrace WORD [WORD]",
4007 "Multicast trace route to multicast source\n"
4008 "Multicast trace route to multicast source address\n"
4009 "Multicast trace route for multicast group address\n")
4012 execute_command("mtracebis", 1, argv
[1]->arg
, NULL
);
4014 execute_command("mtracebis", 2, argv
[1]->arg
, argv
[2]->arg
);
4021 "Send echo messages\n"
4023 "Ping destination address or hostname\n")
4025 execute_command("ping6", 1, argv
[2]->arg
, NULL
);
4029 DEFUN (vtysh_traceroute6
,
4030 vtysh_traceroute6_cmd
,
4031 "traceroute ipv6 WORD",
4032 "Trace route to destination\n"
4034 "Trace route to destination address or hostname\n")
4036 execute_command("traceroute6", 1, argv
[2]->arg
, NULL
);
4040 #if CONFDATE > 20240201
4041 CPP_NOTICE("Remove HAVE_SHELL_ACCESS and it's documentation");
4043 #if defined(HAVE_SHELL_ACCESS)
4044 DEFUN (vtysh_telnet
,
4047 "Open a telnet connection\n"
4048 "IP address or hostname of a remote system\n")
4050 execute_command("telnet", 1, argv
[1]->arg
, NULL
);
4054 DEFUN (vtysh_telnet_port
,
4055 vtysh_telnet_port_cmd
,
4057 "Open a telnet connection\n"
4058 "IP address or hostname of a remote system\n"
4059 "TCP Port number\n")
4061 execute_command("telnet", 2, argv
[1]->arg
, argv
[2]->arg
);
4068 "Open an ssh connection\n"
4071 execute_command("ssh", 1, argv
[1]->arg
, NULL
);
4075 DEFUN (vtysh_start_shell
,
4076 vtysh_start_shell_cmd
,
4078 "Start UNIX shell\n")
4080 execute_command("sh", 0, NULL
, NULL
);
4084 DEFUN (vtysh_start_bash
,
4085 vtysh_start_bash_cmd
,
4087 "Start UNIX shell\n"
4090 execute_command("bash", 0, NULL
, NULL
);
4094 DEFUN (vtysh_start_zsh
,
4095 vtysh_start_zsh_cmd
,
4097 "Start UNIX shell\n"
4100 execute_command("zsh", 0, NULL
, NULL
);
4107 "list [permutations]",
4108 "Print command list\n"
4109 "Print all possible command permutations\n")
4111 return cmd_list_cmds(vty
, argc
== 2);
4114 DEFUN (vtysh_output_file
,
4115 vtysh_output_file_cmd
,
4117 "Direct vtysh output to file\n"
4118 "Direct vtysh output to file\n"
4119 "Path to dump output to\n")
4121 const char *path
= argv
[argc
- 1]->arg
;
4122 vty
->of
= fopen(path
, "a");
4124 vty_out(vty
, "Failed to open file '%s': %s\n", path
,
4125 safe_strerror(errno
));
4131 DEFUN (no_vtysh_output_file
,
4132 no_vtysh_output_file_cmd
,
4133 "no output file [FILE]",
4135 "Direct vtysh output to file\n"
4136 "Direct vtysh output to file\n"
4137 "Path to dump output to\n")
4139 if (vty
->of
!= stdout
) {
4149 "Find CLI command matching a regular expression\n"
4150 "Search pattern (POSIX regex)\n")
4152 return cmd_find_cmds(vty
, argv
, argc
);
4155 DEFUN_HIDDEN(show_cli_graph_vtysh
,
4156 show_cli_graph_vtysh_cmd
,
4160 "Dump current command space as DOT graph\n")
4162 struct cmd_node
*cn
= vector_slot(cmdvec
, vty
->node
);
4163 char *dot
= cmd_graph_dump_dot(cn
->cmdgraph
);
4165 vty_out(vty
, "%s\n", dot
);
4166 XFREE(MTYPE_TMP
, dot
);
4170 static void vtysh_install_default(enum node_type node
)
4172 _install_element(node
, &config_list_cmd
);
4173 _install_element(node
, &find_cmd
);
4174 _install_element(node
, &show_cli_graph_vtysh_cmd
);
4175 _install_element(node
, &vtysh_output_file_cmd
);
4176 _install_element(node
, &no_vtysh_output_file_cmd
);
4179 /* Making connection to protocol daemon. */
4180 static int vtysh_connect(struct vtysh_client
*vclient
)
4184 struct sockaddr_un addr
;
4188 if (!vclient
->path
[0])
4189 snprintf(vclient
->path
, sizeof(vclient
->path
), "%s/%s.vty",
4190 vtydir
, vclient
->name
);
4191 path
= vclient
->path
;
4193 /* Stat socket to see if we have permission to access it. */
4194 ret
= stat(path
, &s_stat
);
4195 if (ret
< 0 && errno
!= ENOENT
) {
4196 fprintf(stderr
, "vtysh_connect(%s): stat = %s\n", path
,
4197 safe_strerror(errno
));
4202 if (!S_ISSOCK(s_stat
.st_mode
)) {
4203 fprintf(stderr
, "vtysh_connect(%s): Not a socket\n",
4209 sock
= socket(AF_UNIX
, SOCK_STREAM
, 0);
4212 fprintf(stderr
, "vtysh_connect(%s): socket = %s\n", path
,
4213 safe_strerror(errno
));
4218 memset(&addr
, 0, sizeof(addr
));
4219 addr
.sun_family
= AF_UNIX
;
4220 strlcpy(addr
.sun_path
, path
, sizeof(addr
.sun_path
));
4221 #ifdef HAVE_STRUCT_SOCKADDR_UN_SUN_LEN
4222 len
= addr
.sun_len
= SUN_LEN(&addr
);
4224 len
= sizeof(addr
.sun_family
) + strlen(addr
.sun_path
);
4225 #endif /* HAVE_STRUCT_SOCKADDR_UN_SUN_LEN */
4227 ret
= connect(sock
, (struct sockaddr
*)&addr
, len
);
4230 fprintf(stderr
, "vtysh_connect(%s): connect = %s\n", path
,
4231 safe_strerror(errno
));
4241 static int vtysh_reconnect(struct vtysh_client
*vclient
)
4245 fprintf(stderr
, "Warning: connecting to %s...", vclient
->name
);
4246 ret
= vtysh_connect(vclient
);
4248 fprintf(stderr
, "failed!\n");
4251 fprintf(stderr
, "success!\n");
4252 if (vtysh_client_execute(vclient
, "enable") < 0)
4254 return vtysh_execute_no_pager("end");
4257 /* Return true if str ends with suffix, else return false */
4258 static int ends_with(const char *str
, const char *suffix
)
4260 if (!str
|| !suffix
)
4262 size_t lenstr
= strlen(str
);
4263 size_t lensuffix
= strlen(suffix
);
4264 if (lensuffix
> lenstr
)
4266 return strncmp(str
+ lenstr
- lensuffix
, suffix
, lensuffix
) == 0;
4269 static void vtysh_client_sorted_insert(struct vtysh_client
*head_client
,
4270 struct vtysh_client
*client
)
4272 struct vtysh_client
*prev_node
, *current_node
;
4274 prev_node
= head_client
;
4275 current_node
= head_client
->next
;
4276 while (current_node
) {
4277 if (strcmp(current_node
->path
, client
->path
) > 0)
4280 prev_node
= current_node
;
4281 current_node
= current_node
->next
;
4283 client
->next
= current_node
;
4284 prev_node
->next
= client
;
4287 #define MAXIMUM_INSTANCES 10
4289 static void vtysh_update_all_instances(struct vtysh_client
*head_client
)
4291 struct vtysh_client
*client
;
4293 struct dirent
*file
;
4296 if (head_client
->flag
!= VTYSH_OSPFD
)
4299 /* ls vty_sock_dir and look for all files ending in .vty */
4300 dir
= opendir(vtydir
);
4302 while ((file
= readdir(dir
)) != NULL
) {
4303 if (frrstr_startswith(file
->d_name
, "ospfd-")
4304 && ends_with(file
->d_name
, ".vty")) {
4305 if (n
== MAXIMUM_INSTANCES
) {
4307 "Parsing %s, client limit(%d) reached!\n",
4311 client
= (struct vtysh_client
*)malloc(
4312 sizeof(struct vtysh_client
));
4314 client
->name
= "ospfd";
4315 client
->flag
= VTYSH_OSPFD
;
4316 snprintf(client
->path
, sizeof(client
->path
),
4317 "%s/%s", vtydir
, file
->d_name
);
4318 client
->next
= NULL
;
4319 vtysh_client_sorted_insert(head_client
, client
);
4327 static int vtysh_connect_all_instances(struct vtysh_client
*head_client
)
4329 struct vtysh_client
*client
;
4332 vtysh_update_all_instances(head_client
);
4334 client
= head_client
->next
;
4336 if (vtysh_connect(client
) == 0)
4338 client
= client
->next
;
4344 int vtysh_connect_all(const char *daemon_name
)
4350 for (i
= 0; i
< array_size(vtysh_client
); i
++) {
4352 || !strcmp(daemon_name
, vtysh_client
[i
].name
)) {
4354 if (vtysh_connect(&vtysh_client
[i
]) == 0)
4357 rc
+= vtysh_connect_all_instances(&vtysh_client
[i
]);
4361 fprintf(stderr
, "Error: no daemons match name %s!\n",
4366 /* To disable readline's filename completion. */
4367 static char *vtysh_completion_entry_function(const char *ignore
,
4373 void vtysh_readline_init(void)
4375 /* readline related settings. */
4376 char *disable_bracketed_paste
=
4377 XSTRDUP(MTYPE_TMP
, "set enable-bracketed-paste off");
4380 rl_parse_and_bind(disable_bracketed_paste
);
4381 rl_bind_key('?', (rl_command_func_t
*)vtysh_rl_describe
);
4382 rl_completion_entry_function
= vtysh_completion_entry_function
;
4383 rl_attempted_completion_function
= new_completion
;
4385 XFREE(MTYPE_TMP
, disable_bracketed_paste
);
4388 char *vtysh_prompt(void)
4390 static char buf
[512];
4392 #pragma GCC diagnostic push
4393 #pragma GCC diagnostic ignored "-Wformat-nonliteral"
4394 /* prompt formatting has a %s in the cmd_node prompt string. */
4395 snprintf(buf
, sizeof(buf
), cmd_prompt(vty
->node
), cmd_hostname_get());
4396 #pragma GCC diagnostic pop
4400 static void vtysh_ac_line(void *arg
, const char *line
)
4404 for (i
= 0; i
< vector_active(comps
); i
++)
4405 if (!strcmp(line
, (char *)vector_slot(comps
, i
)))
4407 vector_set(comps
, XSTRDUP(MTYPE_COMPLETION
, line
));
4410 static void vtysh_autocomplete(vector comps
, struct cmd_token
*token
)
4415 snprintf(accmd
, sizeof(accmd
), "autocomplete %d %s %s", token
->type
,
4416 token
->text
, token
->varname
? token
->varname
: "-");
4418 vty
->of_saved
= vty
->of
;
4420 for (i
= 0; i
< array_size(vtysh_client
); i
++)
4421 vtysh_client_run_all(&vtysh_client
[i
], accmd
, 1, vtysh_ac_line
,
4423 vty
->of
= vty
->of_saved
;
4426 static const struct cmd_variable_handler vtysh_var_handler
[] = {
4430 .completions
= vtysh_autocomplete
},
4431 {.completions
= NULL
}};
4433 void vtysh_uninit(void)
4435 if (vty
->of
!= stdout
)
4439 void vtysh_init_vty(void)
4441 struct stat st_out
, st_err
;
4443 cmd_defer_tree(true);
4445 for (size_t i
= 0; i
< array_size(vtysh_client
); i
++) {
4446 vtysh_client
[i
].fd
= -1;
4447 vtysh_client
[i
].log_fd
= -1;
4450 stderr_tty
= isatty(STDERR_FILENO
);
4452 if (fstat(STDOUT_FILENO
, &st_out
) || fstat(STDERR_FILENO
, &st_err
) ||
4453 (st_out
.st_dev
== st_err
.st_dev
&& st_out
.st_ino
== st_err
.st_ino
))
4454 stderr_stdout_same
= true;
4456 /* Make vty structure. */
4458 vty
->type
= VTY_SHELL
;
4459 vty
->node
= VIEW_NODE
;
4461 /* set default output */
4463 vtysh_pager_envdef(false);
4465 /* Initialize commands. */
4467 cmd_variable_handler_register(vtysh_var_handler
);
4471 install_node(&bgp_node
);
4472 install_element(CONFIG_NODE
, &router_bgp_cmd
);
4473 install_element(BGP_NODE
, &vtysh_exit_bgpd_cmd
);
4474 install_element(BGP_NODE
, &vtysh_quit_bgpd_cmd
);
4475 install_element(BGP_NODE
, &vtysh_end_all_cmd
);
4477 install_node(&bgp_vpnv4_node
);
4478 install_element(BGP_NODE
, &address_family_ipv4_vpn_cmd
);
4479 #ifdef KEEP_OLD_VPN_COMMANDS
4480 install_element(BGP_NODE
, &address_family_vpnv4_cmd
);
4481 #endif /* KEEP_OLD_VPN_COMMANDS */
4482 install_element(BGP_VPNV4_NODE
, &vtysh_exit_bgpd_cmd
);
4483 install_element(BGP_VPNV4_NODE
, &vtysh_quit_bgpd_cmd
);
4484 install_element(BGP_VPNV4_NODE
, &vtysh_end_all_cmd
);
4485 install_element(BGP_VPNV4_NODE
, &exit_address_family_cmd
);
4487 install_node(&bgp_vpnv6_node
);
4488 install_element(BGP_NODE
, &address_family_ipv6_vpn_cmd
);
4489 #ifdef KEEP_OLD_VPN_COMMANDS
4490 install_element(BGP_NODE
, &address_family_vpnv6_cmd
);
4491 #endif /* KEEP_OLD_VPN_COMMANDS */
4492 install_element(BGP_VPNV6_NODE
, &vtysh_exit_bgpd_cmd
);
4493 install_element(BGP_VPNV6_NODE
, &vtysh_quit_bgpd_cmd
);
4494 install_element(BGP_VPNV6_NODE
, &vtysh_end_all_cmd
);
4495 install_element(BGP_VPNV6_NODE
, &exit_address_family_cmd
);
4497 install_node(&bgp_flowspecv4_node
);
4498 install_element(BGP_NODE
, &address_family_flowspecv4_cmd
);
4499 install_element(BGP_FLOWSPECV4_NODE
, &vtysh_exit_bgpd_cmd
);
4500 install_element(BGP_FLOWSPECV4_NODE
, &vtysh_quit_bgpd_cmd
);
4501 install_element(BGP_FLOWSPECV4_NODE
, &vtysh_end_all_cmd
);
4502 install_element(BGP_FLOWSPECV4_NODE
, &exit_address_family_cmd
);
4504 install_node(&bgp_flowspecv6_node
);
4505 install_element(BGP_NODE
, &address_family_flowspecv6_cmd
);
4506 install_element(BGP_FLOWSPECV6_NODE
, &vtysh_exit_bgpd_cmd
);
4507 install_element(BGP_FLOWSPECV6_NODE
, &vtysh_quit_bgpd_cmd
);
4508 install_element(BGP_FLOWSPECV6_NODE
, &vtysh_end_all_cmd
);
4509 install_element(BGP_FLOWSPECV6_NODE
, &exit_address_family_cmd
);
4511 install_node(&bgp_ipv4_node
);
4512 install_element(BGP_NODE
, &address_family_ipv4_cmd
);
4513 install_element(BGP_IPV4_NODE
, &vtysh_exit_bgpd_cmd
);
4514 install_element(BGP_IPV4_NODE
, &vtysh_quit_bgpd_cmd
);
4515 install_element(BGP_IPV4_NODE
, &vtysh_end_all_cmd
);
4516 install_element(BGP_IPV4_NODE
, &exit_address_family_cmd
);
4518 install_node(&bgp_ipv4m_node
);
4519 install_element(BGP_NODE
, &address_family_ipv4_multicast_cmd
);
4520 install_element(BGP_IPV4M_NODE
, &vtysh_exit_bgpd_cmd
);
4521 install_element(BGP_IPV4M_NODE
, &vtysh_quit_bgpd_cmd
);
4522 install_element(BGP_IPV4M_NODE
, &vtysh_end_all_cmd
);
4523 install_element(BGP_IPV4M_NODE
, &exit_address_family_cmd
);
4525 install_node(&bgp_ipv4l_node
);
4526 install_element(BGP_NODE
, &address_family_ipv4_labeled_unicast_cmd
);
4527 install_element(BGP_IPV4L_NODE
, &vtysh_exit_bgpd_cmd
);
4528 install_element(BGP_IPV4L_NODE
, &vtysh_quit_bgpd_cmd
);
4529 install_element(BGP_IPV4L_NODE
, &vtysh_end_all_cmd
);
4530 install_element(BGP_IPV4L_NODE
, &exit_address_family_cmd
);
4532 install_node(&bgp_ipv6_node
);
4533 install_element(BGP_NODE
, &address_family_ipv6_cmd
);
4534 install_element(BGP_IPV6_NODE
, &vtysh_exit_bgpd_cmd
);
4535 install_element(BGP_IPV6_NODE
, &vtysh_quit_bgpd_cmd
);
4536 install_element(BGP_IPV6_NODE
, &vtysh_end_all_cmd
);
4537 install_element(BGP_IPV6_NODE
, &exit_address_family_cmd
);
4539 install_node(&bgp_ipv6m_node
);
4540 install_element(BGP_NODE
, &address_family_ipv6_multicast_cmd
);
4541 install_element(BGP_IPV6M_NODE
, &vtysh_exit_bgpd_cmd
);
4542 install_element(BGP_IPV6M_NODE
, &vtysh_quit_bgpd_cmd
);
4543 install_element(BGP_IPV6M_NODE
, &vtysh_end_all_cmd
);
4544 install_element(BGP_IPV6M_NODE
, &exit_address_family_cmd
);
4546 install_node(&bgp_ipv6l_node
);
4547 install_element(BGP_NODE
, &address_family_ipv6_labeled_unicast_cmd
);
4548 install_element(BGP_IPV6L_NODE
, &vtysh_exit_bgpd_cmd
);
4549 install_element(BGP_IPV6L_NODE
, &vtysh_quit_bgpd_cmd
);
4550 install_element(BGP_IPV6L_NODE
, &vtysh_end_all_cmd
);
4551 install_element(BGP_IPV6L_NODE
, &exit_address_family_cmd
);
4553 #if defined(ENABLE_BGP_VNC)
4554 install_node(&bgp_vrf_policy_node
);
4555 install_element(BGP_NODE
, &vnc_vrf_policy_cmd
);
4556 install_element(BGP_VRF_POLICY_NODE
, &vtysh_exit_bgpd_cmd
);
4557 install_element(BGP_VRF_POLICY_NODE
, &vtysh_quit_bgpd_cmd
);
4558 install_element(BGP_VRF_POLICY_NODE
, &vtysh_end_all_cmd
);
4559 install_element(BGP_VRF_POLICY_NODE
, &exit_vrf_policy_cmd
);
4561 install_node(&bgp_vnc_defaults_node
);
4562 install_element(BGP_NODE
, &vnc_defaults_cmd
);
4563 install_element(BGP_VNC_DEFAULTS_NODE
, &vtysh_exit_bgpd_cmd
);
4564 install_element(BGP_VNC_DEFAULTS_NODE
, &vtysh_quit_bgpd_cmd
);
4565 install_element(BGP_VNC_DEFAULTS_NODE
, &vtysh_end_all_cmd
);
4566 install_element(BGP_VNC_DEFAULTS_NODE
, &exit_vnc_config_cmd
);
4568 install_node(&bgp_vnc_nve_group_node
);
4569 install_element(BGP_NODE
, &vnc_nve_group_cmd
);
4570 install_element(BGP_VNC_NVE_GROUP_NODE
, &vtysh_exit_bgpd_cmd
);
4571 install_element(BGP_VNC_NVE_GROUP_NODE
, &vtysh_quit_bgpd_cmd
);
4572 install_element(BGP_VNC_NVE_GROUP_NODE
, &vtysh_end_all_cmd
);
4573 install_element(BGP_VNC_NVE_GROUP_NODE
, &exit_vnc_config_cmd
);
4575 install_node(&bgp_vnc_l2_group_node
);
4576 install_element(BGP_NODE
, &vnc_l2_group_cmd
);
4577 install_element(BGP_VNC_L2_GROUP_NODE
, &vtysh_exit_bgpd_cmd
);
4578 install_element(BGP_VNC_L2_GROUP_NODE
, &vtysh_quit_bgpd_cmd
);
4579 install_element(BGP_VNC_L2_GROUP_NODE
, &vtysh_end_all_cmd
);
4580 install_element(BGP_VNC_L2_GROUP_NODE
, &exit_vnc_config_cmd
);
4583 install_node(&bgp_evpn_node
);
4584 install_element(BGP_NODE
, &address_family_evpn_cmd
);
4585 install_element(BGP_EVPN_NODE
, &vtysh_quit_bgpd_cmd
);
4586 install_element(BGP_EVPN_NODE
, &vtysh_exit_bgpd_cmd
);
4587 install_element(BGP_EVPN_NODE
, &vtysh_end_all_cmd
);
4588 install_element(BGP_EVPN_NODE
, &exit_address_family_cmd
);
4590 install_node(&bgp_evpn_vni_node
);
4591 install_element(BGP_EVPN_NODE
, &bgp_evpn_vni_cmd
);
4592 install_element(BGP_EVPN_VNI_NODE
, &vtysh_exit_bgpd_cmd
);
4593 install_element(BGP_EVPN_VNI_NODE
, &vtysh_quit_bgpd_cmd
);
4594 install_element(BGP_EVPN_VNI_NODE
, &vtysh_end_all_cmd
);
4595 install_element(BGP_EVPN_VNI_NODE
, &exit_vni_cmd
);
4597 install_node(&rpki_node
);
4598 install_element(CONFIG_NODE
, &rpki_cmd
);
4599 install_element(RPKI_NODE
, &rpki_exit_cmd
);
4600 install_element(RPKI_NODE
, &rpki_quit_cmd
);
4601 install_element(RPKI_NODE
, &vtysh_end_all_cmd
);
4603 install_node(&bmp_node
);
4604 install_element(BGP_NODE
, &bmp_targets_cmd
);
4605 install_element(BMP_NODE
, &bmp_exit_cmd
);
4606 install_element(BMP_NODE
, &bmp_quit_cmd
);
4607 install_element(BMP_NODE
, &vtysh_end_all_cmd
);
4609 install_node(&bgp_srv6_node
);
4610 install_element(BGP_NODE
, &bgp_srv6_cmd
);
4611 install_element(BGP_SRV6_NODE
, &exit_bgp_srv6_cmd
);
4612 install_element(BGP_SRV6_NODE
, &quit_bgp_srv6_cmd
);
4613 install_element(BGP_SRV6_NODE
, &vtysh_end_all_cmd
);
4614 #endif /* HAVE_BGPD */
4617 install_node(&rip_node
);
4619 install_element(CONFIG_NODE
, &router_rip_cmd
);
4620 install_element(RIP_NODE
, &vtysh_exit_ripd_cmd
);
4621 install_element(RIP_NODE
, &vtysh_quit_ripd_cmd
);
4622 install_element(RIP_NODE
, &vtysh_end_all_cmd
);
4623 #endif /* HAVE_RIPD */
4626 install_node(&ripng_node
);
4628 install_element(CONFIG_NODE
, &router_ripng_cmd
);
4629 install_element(RIPNG_NODE
, &vtysh_exit_ripngd_cmd
);
4630 install_element(RIPNG_NODE
, &vtysh_quit_ripngd_cmd
);
4631 install_element(RIPNG_NODE
, &vtysh_end_all_cmd
);
4632 #endif /* HAVE_RIPNGD */
4636 install_node(&ospf_node
);
4637 install_element(CONFIG_NODE
, &router_ospf_cmd
);
4638 install_element(OSPF_NODE
, &vtysh_exit_ospfd_cmd
);
4639 install_element(OSPF_NODE
, &vtysh_quit_ospfd_cmd
);
4640 install_element(OSPF_NODE
, &vtysh_end_all_cmd
);
4641 #endif /* HAVE_OSPFD */
4645 install_node(&ospf6_node
);
4646 install_element(CONFIG_NODE
, &router_ospf6_cmd
);
4647 install_element(OSPF6_NODE
, &vtysh_exit_ospf6d_cmd
);
4648 install_element(OSPF6_NODE
, &vtysh_quit_ospf6d_cmd
);
4649 install_element(OSPF6_NODE
, &vtysh_end_all_cmd
);
4650 #endif /* HAVE_OSPF6D */
4653 #if defined(HAVE_LDPD)
4654 install_node(&ldp_node
);
4655 install_element(CONFIG_NODE
, &ldp_mpls_ldp_cmd
);
4656 install_element(LDP_NODE
, &vtysh_exit_ldpd_cmd
);
4657 install_element(LDP_NODE
, &vtysh_quit_ldpd_cmd
);
4658 install_element(LDP_NODE
, &vtysh_end_all_cmd
);
4660 install_node(&ldp_ipv4_node
);
4661 install_element(LDP_NODE
, &ldp_address_family_ipv4_cmd
);
4662 install_element(LDP_IPV4_NODE
, &vtysh_exit_ldpd_cmd
);
4663 install_element(LDP_IPV4_NODE
, &vtysh_quit_ldpd_cmd
);
4664 install_element(LDP_IPV4_NODE
, &ldp_exit_address_family_cmd
);
4665 install_element(LDP_IPV4_NODE
, &vtysh_end_all_cmd
);
4667 install_node(&ldp_ipv6_node
);
4668 install_element(LDP_NODE
, &ldp_address_family_ipv6_cmd
);
4669 install_element(LDP_IPV6_NODE
, &vtysh_exit_ldpd_cmd
);
4670 install_element(LDP_IPV6_NODE
, &vtysh_quit_ldpd_cmd
);
4671 install_element(LDP_IPV6_NODE
, &ldp_exit_address_family_cmd
);
4672 install_element(LDP_IPV6_NODE
, &vtysh_end_all_cmd
);
4674 install_node(&ldp_ipv4_iface_node
);
4675 install_element(LDP_IPV4_NODE
, &ldp_interface_ifname_cmd
);
4676 install_element(LDP_IPV4_IFACE_NODE
, &vtysh_exit_ldpd_cmd
);
4677 install_element(LDP_IPV4_IFACE_NODE
, &vtysh_quit_ldpd_cmd
);
4678 install_element(LDP_IPV4_IFACE_NODE
, &vtysh_end_all_cmd
);
4680 install_node(&ldp_ipv6_iface_node
);
4681 install_element(LDP_IPV6_NODE
, &ldp_interface_ifname_cmd
);
4682 install_element(LDP_IPV6_IFACE_NODE
, &vtysh_exit_ldpd_cmd
);
4683 install_element(LDP_IPV6_IFACE_NODE
, &vtysh_quit_ldpd_cmd
);
4684 install_element(LDP_IPV6_IFACE_NODE
, &vtysh_end_all_cmd
);
4686 install_node(&ldp_l2vpn_node
);
4687 install_element(CONFIG_NODE
, &ldp_l2vpn_word_type_vpls_cmd
);
4688 install_element(LDP_L2VPN_NODE
, &vtysh_exit_ldpd_cmd
);
4689 install_element(LDP_L2VPN_NODE
, &vtysh_quit_ldpd_cmd
);
4690 install_element(LDP_L2VPN_NODE
, &vtysh_end_all_cmd
);
4692 install_node(&ldp_pseudowire_node
);
4693 install_element(LDP_L2VPN_NODE
, &ldp_member_pseudowire_ifname_cmd
);
4694 install_element(LDP_PSEUDOWIRE_NODE
, &vtysh_exit_ldpd_cmd
);
4695 install_element(LDP_PSEUDOWIRE_NODE
, &vtysh_quit_ldpd_cmd
);
4696 install_element(LDP_PSEUDOWIRE_NODE
, &vtysh_end_all_cmd
);
4701 install_node(&eigrp_node
);
4702 install_element(CONFIG_NODE
, &router_eigrp_cmd
);
4703 install_element(EIGRP_NODE
, &vtysh_exit_eigrpd_cmd
);
4704 install_element(EIGRP_NODE
, &vtysh_quit_eigrpd_cmd
);
4705 install_element(EIGRP_NODE
, &vtysh_end_all_cmd
);
4706 #endif /* HAVE_EIGRPD */
4710 install_node(&babel_node
);
4711 install_element(CONFIG_NODE
, &router_babel_cmd
);
4712 install_element(BABEL_NODE
, &vtysh_exit_babeld_cmd
);
4713 install_element(BABEL_NODE
, &vtysh_quit_babeld_cmd
);
4714 install_element(BABEL_NODE
, &vtysh_end_all_cmd
);
4715 #endif /* HAVE_BABELD */
4719 install_node(&isis_node
);
4720 install_element(CONFIG_NODE
, &router_isis_cmd
);
4721 install_element(ISIS_NODE
, &vtysh_exit_isisd_cmd
);
4722 install_element(ISIS_NODE
, &vtysh_quit_isisd_cmd
);
4723 install_element(ISIS_NODE
, &vtysh_end_all_cmd
);
4724 #endif /* HAVE_ISISD */
4728 install_node(&openfabric_node
);
4729 install_element(CONFIG_NODE
, &router_openfabric_cmd
);
4730 install_element(OPENFABRIC_NODE
, &vtysh_exit_fabricd_cmd
);
4731 install_element(OPENFABRIC_NODE
, &vtysh_quit_fabricd_cmd
);
4732 install_element(OPENFABRIC_NODE
, &vtysh_end_all_cmd
);
4733 #endif /* HAVE_FABRICD */
4737 install_node(&pbr_map_node
);
4738 install_element(CONFIG_NODE
, &vtysh_pbr_map_cmd
);
4739 install_element(CONFIG_NODE
, &vtysh_no_pbr_map_cmd
);
4740 install_element(PBRMAP_NODE
, &vtysh_exit_pbr_map_cmd
);
4741 install_element(PBRMAP_NODE
, &vtysh_quit_pbr_map_cmd
);
4742 install_element(PBRMAP_NODE
, &vtysh_end_all_cmd
);
4743 #endif /* HAVE_PBRD */
4747 install_node(&bfd_node
);
4748 install_element(CONFIG_NODE
, &bfd_enter_cmd
);
4749 install_element(BFD_NODE
, &vtysh_exit_bfdd_cmd
);
4750 install_element(BFD_NODE
, &vtysh_quit_bfdd_cmd
);
4751 install_element(BFD_NODE
, &vtysh_end_all_cmd
);
4753 install_node(&bfd_peer_node
);
4754 install_element(BFD_NODE
, &bfd_peer_enter_cmd
);
4755 install_element(BFD_PEER_NODE
, &vtysh_exit_bfdd_cmd
);
4756 install_element(BFD_PEER_NODE
, &vtysh_quit_bfdd_cmd
);
4757 install_element(BFD_PEER_NODE
, &vtysh_end_all_cmd
);
4759 install_node(&bfd_profile_node
);
4760 install_element(BFD_NODE
, &bfd_profile_enter_cmd
);
4761 install_element(BFD_PROFILE_NODE
, &vtysh_exit_bfdd_cmd
);
4762 install_element(BFD_PROFILE_NODE
, &vtysh_quit_bfdd_cmd
);
4763 install_element(BFD_PROFILE_NODE
, &vtysh_end_all_cmd
);
4764 #endif /* HAVE_BFDD */
4766 install_node(&segment_routing_node
);
4767 install_element(CONFIG_NODE
, &segment_routing_cmd
);
4768 install_element(SEGMENT_ROUTING_NODE
, &vtysh_exit_sr_cmd
);
4769 install_element(SEGMENT_ROUTING_NODE
, &vtysh_quit_sr_cmd
);
4770 install_element(SEGMENT_ROUTING_NODE
, &vtysh_end_all_cmd
);
4772 #if defined(HAVE_PATHD)
4773 install_node(&sr_traffic_eng_node
);
4774 install_node(&srte_segment_list_node
);
4775 install_node(&srte_policy_node
);
4776 install_node(&srte_candidate_dyn_node
);
4778 install_element(SR_TRAFFIC_ENG_NODE
, &vtysh_exit_pathd_cmd
);
4779 install_element(SR_TRAFFIC_ENG_NODE
, &vtysh_quit_pathd_cmd
);
4780 install_element(SR_SEGMENT_LIST_NODE
, &vtysh_exit_pathd_cmd
);
4781 install_element(SR_SEGMENT_LIST_NODE
, &vtysh_quit_pathd_cmd
);
4782 install_element(SR_POLICY_NODE
, &vtysh_exit_pathd_cmd
);
4783 install_element(SR_POLICY_NODE
, &vtysh_quit_pathd_cmd
);
4784 install_element(SR_CANDIDATE_DYN_NODE
, &vtysh_exit_pathd_cmd
);
4785 install_element(SR_CANDIDATE_DYN_NODE
, &vtysh_quit_pathd_cmd
);
4788 install_element(SR_TRAFFIC_ENG_NODE
, &vtysh_end_all_cmd
);
4789 install_element(SR_SEGMENT_LIST_NODE
, &vtysh_end_all_cmd
);
4790 install_element(SR_POLICY_NODE
, &vtysh_end_all_cmd
);
4791 install_element(SR_CANDIDATE_DYN_NODE
, &vtysh_end_all_cmd
);
4793 install_element(SEGMENT_ROUTING_NODE
, &sr_traffic_eng_cmd
);
4794 install_element(SR_TRAFFIC_ENG_NODE
, &srte_segment_list_cmd
);
4795 install_element(SR_TRAFFIC_ENG_NODE
, &srte_policy_cmd
);
4796 install_element(SR_POLICY_NODE
, &srte_policy_candidate_dyn_path_cmd
);
4798 install_node(&pcep_node
);
4799 install_node(&pcep_pcc_node
);
4800 install_node(&pcep_pce_node
);
4801 install_node(&pcep_pce_config_node
);
4803 install_element(PCEP_NODE
, &vtysh_exit_pathd_cmd
);
4804 install_element(PCEP_NODE
, &vtysh_quit_pathd_cmd
);
4805 install_element(PCEP_PCC_NODE
, &vtysh_exit_pathd_cmd
);
4806 install_element(PCEP_PCC_NODE
, &vtysh_quit_pathd_cmd
);
4807 install_element(PCEP_PCE_NODE
, &vtysh_exit_pathd_cmd
);
4808 install_element(PCEP_PCE_NODE
, &vtysh_quit_pathd_cmd
);
4809 install_element(PCEP_PCE_CONFIG_NODE
, &vtysh_exit_pathd_cmd
);
4810 install_element(PCEP_PCE_CONFIG_NODE
, &vtysh_quit_pathd_cmd
);
4812 install_element(PCEP_NODE
, &vtysh_end_all_cmd
);
4813 install_element(PCEP_PCC_NODE
, &vtysh_end_all_cmd
);
4814 install_element(PCEP_PCE_NODE
, &vtysh_end_all_cmd
);
4815 install_element(PCEP_PCE_CONFIG_NODE
, &vtysh_end_all_cmd
);
4817 install_element(SR_TRAFFIC_ENG_NODE
, &pcep_cmd
);
4818 install_element(PCEP_NODE
, &pcep_cli_pcc_cmd
);
4819 install_element(PCEP_NODE
, &pcep_cli_pcep_pce_config_cmd
);
4820 install_element(PCEP_NODE
, &pcep_cli_pce_cmd
);
4822 #endif /* HAVE_PATHD */
4825 install_node(&keychain_node
);
4826 install_element(CONFIG_NODE
, &key_chain_cmd
);
4827 install_element(KEYCHAIN_NODE
, &key_chain_cmd
);
4828 install_element(KEYCHAIN_NODE
, &vtysh_exit_keys_cmd
);
4829 install_element(KEYCHAIN_NODE
, &vtysh_quit_keys_cmd
);
4830 install_element(KEYCHAIN_NODE
, &vtysh_end_all_cmd
);
4832 install_node(&keychain_key_node
);
4833 install_element(KEYCHAIN_NODE
, &key_cmd
);
4834 install_element(KEYCHAIN_KEY_NODE
, &key_chain_cmd
);
4835 install_element(KEYCHAIN_KEY_NODE
, &vtysh_exit_keys_cmd
);
4836 install_element(KEYCHAIN_KEY_NODE
, &vtysh_quit_keys_cmd
);
4837 install_element(KEYCHAIN_KEY_NODE
, &vtysh_end_all_cmd
);
4840 install_node(&nh_group_node
);
4841 install_element(CONFIG_NODE
, &vtysh_nexthop_group_cmd
);
4842 install_element(CONFIG_NODE
, &vtysh_no_nexthop_group_cmd
);
4843 install_element(NH_GROUP_NODE
, &vtysh_end_all_cmd
);
4844 install_element(NH_GROUP_NODE
, &vtysh_exit_nexthop_group_cmd
);
4845 install_element(NH_GROUP_NODE
, &vtysh_quit_nexthop_group_cmd
);
4848 install_node(&zebra_node
);
4850 install_node(&interface_node
);
4851 install_element(CONFIG_NODE
, &vtysh_interface_cmd
);
4852 install_element(INTERFACE_NODE
, &vtysh_end_all_cmd
);
4853 install_element(INTERFACE_NODE
, &vtysh_exit_interface_cmd
);
4854 install_element(INTERFACE_NODE
, &vtysh_quit_interface_cmd
);
4856 install_node(&link_params_node
);
4857 install_element(INTERFACE_NODE
, &vtysh_link_params_cmd
);
4858 install_element(LINK_PARAMS_NODE
, &exit_link_params_cmd
);
4859 install_element(LINK_PARAMS_NODE
, &vtysh_end_all_cmd
);
4860 install_element(LINK_PARAMS_NODE
, &vtysh_exit_link_params_cmd
);
4861 install_element(LINK_PARAMS_NODE
, &vtysh_quit_link_params_cmd
);
4863 install_node(&pw_node
);
4864 install_element(CONFIG_NODE
, &vtysh_pseudowire_cmd
);
4865 install_element(PW_NODE
, &vtysh_end_all_cmd
);
4866 install_element(PW_NODE
, &vtysh_exit_pseudowire_cmd
);
4867 install_element(PW_NODE
, &vtysh_quit_pseudowire_cmd
);
4869 install_node(&vrf_node
);
4870 install_element(CONFIG_NODE
, &vtysh_vrf_cmd
);
4871 install_element(VRF_NODE
, &exit_vrf_config_cmd
);
4872 install_element(VRF_NODE
, &vtysh_end_all_cmd
);
4873 install_element(VRF_NODE
, &vtysh_exit_vrf_cmd
);
4874 install_element(VRF_NODE
, &vtysh_quit_vrf_cmd
);
4876 install_element(CONFIG_NODE
, &vtysh_affinity_map_cmd
);
4877 install_element(CONFIG_NODE
, &vtysh_no_affinity_map_cmd
);
4879 install_node(&rmap_node
);
4880 install_element(CONFIG_NODE
, &vtysh_route_map_cmd
);
4881 install_element(RMAP_NODE
, &vtysh_exit_rmap_cmd
);
4882 install_element(RMAP_NODE
, &vtysh_quit_rmap_cmd
);
4883 install_element(RMAP_NODE
, &vtysh_end_all_cmd
);
4885 install_node(&vty_node
);
4886 install_element(CONFIG_NODE
, &vtysh_line_vty_cmd
);
4887 install_element(VTY_NODE
, &vtysh_exit_line_vty_cmd
);
4888 install_element(VTY_NODE
, &vtysh_quit_line_vty_cmd
);
4889 install_element(VTY_NODE
, &vtysh_end_all_cmd
);
4892 struct cmd_node
*node
;
4893 for (unsigned int i
= 0; i
< vector_active(cmdvec
); i
++) {
4894 node
= vector_slot(cmdvec
, i
);
4895 if (!node
|| node
->node
== VIEW_NODE
)
4897 vtysh_install_default(node
->node
);
4903 install_element(VIEW_NODE
, &vtysh_enable_cmd
);
4904 install_element(ENABLE_NODE
, &vtysh_config_terminal_cmd
);
4905 install_element(ENABLE_NODE
, &vtysh_disable_cmd
);
4907 /* "exit" command. */
4908 install_element(VIEW_NODE
, &vtysh_exit_all_cmd
);
4909 install_element(CONFIG_NODE
, &vtysh_exit_all_cmd
);
4910 install_element(VIEW_NODE
, &vtysh_quit_all_cmd
);
4911 install_element(CONFIG_NODE
, &vtysh_quit_all_cmd
);
4913 /* "end" command. */
4914 install_element(CONFIG_NODE
, &vtysh_end_all_cmd
);
4915 install_element(ENABLE_NODE
, &vtysh_end_all_cmd
);
4917 /* SRv6 Data-plane */
4918 install_node(&srv6_node
);
4919 install_element(SEGMENT_ROUTING_NODE
, &srv6_cmd
);
4920 install_element(SRV6_NODE
, &srv6_locators_cmd
);
4921 install_element(SRV6_NODE
, &exit_srv6_config_cmd
);
4922 install_element(SRV6_NODE
, &vtysh_end_all_cmd
);
4924 install_node(&srv6_locs_node
);
4925 install_element(SRV6_LOCS_NODE
, &srv6_locator_cmd
);
4926 install_element(SRV6_LOCS_NODE
, &exit_srv6_locs_config_cmd
);
4927 install_element(SRV6_LOCS_NODE
, &vtysh_end_all_cmd
);
4929 install_node(&srv6_loc_node
);
4930 install_element(SRV6_LOC_NODE
, &exit_srv6_loc_config_cmd
);
4931 install_element(SRV6_LOC_NODE
, &vtysh_end_all_cmd
);
4933 install_element(ENABLE_NODE
, &vtysh_show_running_config_cmd
);
4934 install_element(ENABLE_NODE
, &vtysh_copy_running_config_cmd
);
4935 install_element(ENABLE_NODE
, &vtysh_copy_to_running_cmd
);
4937 /* "write terminal" command. */
4938 install_element(ENABLE_NODE
, &vtysh_write_terminal_cmd
);
4940 install_element(CONFIG_NODE
, &vtysh_integrated_config_cmd
);
4941 install_element(CONFIG_NODE
, &no_vtysh_integrated_config_cmd
);
4943 /* "write memory" command. */
4944 install_element(ENABLE_NODE
, &vtysh_write_memory_cmd
);
4946 install_element(CONFIG_NODE
, &start_config_cmd
);
4947 install_element(CONFIG_NODE
, &end_config_cmd
);
4949 install_element(CONFIG_NODE
, &vtysh_terminal_paginate_cmd
);
4950 install_element(VIEW_NODE
, &vtysh_terminal_paginate_cmd
);
4951 install_element(VIEW_NODE
, &vtysh_terminal_length_cmd
);
4952 install_element(VIEW_NODE
, &vtysh_terminal_no_length_cmd
);
4953 install_element(VIEW_NODE
, &vtysh_show_daemons_cmd
);
4955 install_element(VIEW_NODE
, &vtysh_terminal_monitor_cmd
);
4956 install_element(VIEW_NODE
, &no_vtysh_terminal_monitor_cmd
);
4958 install_element(VIEW_NODE
, &vtysh_ping_cmd
);
4959 install_element(VIEW_NODE
, &vtysh_motd_cmd
);
4960 install_element(VIEW_NODE
, &vtysh_ping_ip_cmd
);
4961 install_element(VIEW_NODE
, &vtysh_traceroute_cmd
);
4962 install_element(VIEW_NODE
, &vtysh_traceroute_ip_cmd
);
4963 install_element(VIEW_NODE
, &vtysh_mtrace_cmd
);
4964 install_element(VIEW_NODE
, &vtysh_ping6_cmd
);
4965 install_element(VIEW_NODE
, &vtysh_traceroute6_cmd
);
4966 #if defined(HAVE_SHELL_ACCESS)
4967 install_element(VIEW_NODE
, &vtysh_telnet_cmd
);
4968 install_element(VIEW_NODE
, &vtysh_telnet_port_cmd
);
4969 install_element(VIEW_NODE
, &vtysh_ssh_cmd
);
4971 #if defined(HAVE_SHELL_ACCESS)
4972 install_element(ENABLE_NODE
, &vtysh_start_shell_cmd
);
4973 install_element(ENABLE_NODE
, &vtysh_start_bash_cmd
);
4974 install_element(ENABLE_NODE
, &vtysh_start_zsh_cmd
);
4978 install_element(VIEW_NODE
, &vtysh_show_error_code_cmd
);
4979 install_element(ENABLE_NODE
, &vtysh_show_debugging_cmd
);
4980 install_element(ENABLE_NODE
, &vtysh_show_debugging_hashtable_cmd
);
4981 install_element(ENABLE_NODE
, &vtysh_debug_all_cmd
);
4982 install_element(CONFIG_NODE
, &vtysh_debug_all_cmd
);
4983 install_element(ENABLE_NODE
, &vtysh_debug_memstats_cmd
);
4984 install_element(CONFIG_NODE
, &vtysh_debug_memstats_cmd
);
4985 install_element(ENABLE_NODE
, &vtysh_debug_uid_backtrace_cmd
);
4986 install_element(CONFIG_NODE
, &vtysh_debug_uid_backtrace_cmd
);
4989 install_element(ENABLE_NODE
, &show_config_running_cmd
);
4990 install_element(ENABLE_NODE
, &show_yang_operational_data_cmd
);
4991 install_element(ENABLE_NODE
, &show_yang_module_cmd
);
4992 install_element(ENABLE_NODE
, &show_yang_module_detail_cmd
);
4993 install_element(ENABLE_NODE
, &debug_nb_cmd
);
4994 install_element(CONFIG_NODE
, &debug_nb_cmd
);
4996 /* misc lib show commands */
4997 install_element(VIEW_NODE
, &vtysh_show_history_cmd
);
4998 install_element(VIEW_NODE
, &vtysh_show_memory_cmd
);
4999 install_element(VIEW_NODE
, &vtysh_show_modules_cmd
);
5000 install_element(VIEW_NODE
, &vtysh_show_work_queues_cmd
);
5001 install_element(VIEW_NODE
, &vtysh_show_work_queues_daemon_cmd
);
5002 install_element(VIEW_NODE
, &vtysh_show_thread_cmd
);
5003 install_element(VIEW_NODE
, &vtysh_show_poll_cmd
);
5004 install_element(VIEW_NODE
, &vtysh_show_thread_timer_cmd
);
5007 install_element(VIEW_NODE
, &vtysh_show_logging_cmd
);
5009 install_element(CONFIG_NODE
, &vtysh_service_password_encrypt_cmd
);
5010 install_element(CONFIG_NODE
, &no_vtysh_service_password_encrypt_cmd
);
5012 install_element(CONFIG_NODE
, &vtysh_allow_reserved_ranges_cmd
);
5013 install_element(CONFIG_NODE
, &no_vtysh_allow_reserved_ranges_cmd
);
5015 install_element(CONFIG_NODE
, &vtysh_password_cmd
);
5016 install_element(CONFIG_NODE
, &no_vtysh_password_cmd
);
5017 install_element(CONFIG_NODE
, &vtysh_enable_password_cmd
);
5018 install_element(CONFIG_NODE
, &no_vtysh_enable_password_cmd
);