1 /* Virtual terminal interface shell.
2 * Copyright (C) 2000 Kunihiro Ishiguro
4 * This file is part of GNU Zebra.
6 * GNU Zebra is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2, or (at your option) any
11 * GNU Zebra is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; see the file COPYING; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26 #include <sys/resource.h>
29 #include <readline/readline.h>
30 #include <readline/history.h>
40 #include "vtysh/vtysh.h"
42 #include "bgpd/bgp_vty.h"
47 DEFINE_MTYPE_STATIC(MVTYSH
, VTYSH_CMD
, "Vtysh cmd copy")
52 /* VTY shell pager name. */
53 char *vtysh_pager_name
= NULL
;
55 /* VTY shell client structure. */
60 char path
[MAXPATHLEN
];
61 struct vtysh_client
*next
;
64 struct vtysh_client vtysh_client
[] = {
65 {.fd
= -1, .name
= "zebra", .flag
= VTYSH_ZEBRA
, .next
= NULL
},
66 {.fd
= -1, .name
= "ripd", .flag
= VTYSH_RIPD
, .next
= NULL
},
67 {.fd
= -1, .name
= "ripngd", .flag
= VTYSH_RIPNGD
, .next
= NULL
},
68 {.fd
= -1, .name
= "ospfd", .flag
= VTYSH_OSPFD
, .next
= NULL
},
69 {.fd
= -1, .name
= "ospf6d", .flag
= VTYSH_OSPF6D
, .next
= NULL
},
70 {.fd
= -1, .name
= "ldpd", .flag
= VTYSH_LDPD
, .next
= NULL
},
71 {.fd
= -1, .name
= "bgpd", .flag
= VTYSH_BGPD
, .next
= NULL
},
72 {.fd
= -1, .name
= "isisd", .flag
= VTYSH_ISISD
, .next
= NULL
},
73 {.fd
= -1, .name
= "pimd", .flag
= VTYSH_PIMD
, .next
= NULL
},
74 {.fd
= -1, .name
= "nhrpd", .flag
= VTYSH_NHRPD
, .next
= NULL
},
75 {.fd
= -1, .name
= "eigrpd", .flag
= VTYSH_EIGRPD
, .next
= NULL
},
76 {.fd
= -1, .name
= "babeld", .flag
= VTYSH_BABELD
, .next
= NULL
},
77 {.fd
= -1, .name
= "watchfrr", .flag
= VTYSH_WATCHFRR
, .next
= NULL
},
80 enum vtysh_write_integrated vtysh_write_integrated
=
81 WRITE_INTEGRATED_UNSPECIFIED
;
83 static void vclient_close(struct vtysh_client
*vclient
)
85 if (vclient
->fd
>= 0) {
87 "Warning: closing connection to %s because of an I/O error!\n",
94 /* Return true if str begins with prefix, else return false */
95 static int begins_with(const char *str
, const char *prefix
)
99 size_t lenstr
= strlen(str
);
100 size_t lenprefix
= strlen(prefix
);
101 if (lenprefix
> lenstr
)
103 return strncmp(str
, prefix
, lenprefix
) == 0;
106 static int vtysh_client_run(struct vtysh_client
*vclient
, const char *line
,
107 FILE *fp
, void (*callback
)(void *, const char *),
112 char *buf
= stackbuf
;
113 size_t bufsz
= sizeof(stackbuf
);
114 char *bufvalid
, *end
= NULL
;
115 char terminator
[3] = {0, 0, 0};
120 ret
= write(vclient
->fd
, line
, strlen(line
) + 1);
127 read(vclient
->fd
, bufvalid
, buf
+ bufsz
- bufvalid
);
129 if (nread
< 0 && (errno
== EINTR
|| errno
== EAGAIN
))
133 fprintf(stderr
, "vtysh: error reading from %s: %s (%d)",
134 vclient
->name
, safe_strerror(errno
), errno
);
140 end
= memmem(buf
, bufvalid
- buf
, terminator
,
142 if (end
+ sizeof(terminator
) + 1 > bufvalid
)
143 /* found \0\0\0 but return code hasn't been read yet */
146 ret
= end
[sizeof(terminator
)];
148 while (bufvalid
> buf
&& (end
> buf
|| !end
)) {
149 size_t textlen
= (end
? end
: bufvalid
) - buf
;
150 char *eol
= memchr(buf
, '\n', textlen
);
155 /* no line break, end of input, no text left
157 * => don't insert an empty line at the end */
160 /* no line break, end of input, but some text
164 /* continue reading */
167 /* eol is at a line end now, either \n => \0 or \0\0\0
169 assert(eol
&& eol
<= bufvalid
);
176 callback(cbarg
, buf
);
182 memmove(buf
, eol
, bufvalid
- eol
);
183 bufvalid
-= eol
- buf
;
188 if (bufvalid
== buf
+ bufsz
) {
191 if (buf
== stackbuf
) {
192 new = XMALLOC(MTYPE_TMP
, bufsz
);
193 memcpy(new, stackbuf
, sizeof(stackbuf
));
195 new = XREALLOC(MTYPE_TMP
, buf
, bufsz
);
197 bufvalid
= bufvalid
- buf
+ new;
199 /* if end != NULL, we won't be reading more data... */
206 vclient_close(vclient
);
210 XFREE(MTYPE_TMP
, buf
);
214 static int vtysh_client_run_all(struct vtysh_client
*head_client
,
215 const char *line
, int continue_on_err
, FILE *fp
,
216 void (*callback
)(void *, const char *),
219 struct vtysh_client
*client
;
220 int rc
, rc_all
= CMD_SUCCESS
;
221 int correct_instance
= 0, wrong_instance
= 0;
223 for (client
= head_client
; client
; client
= client
->next
) {
224 rc
= vtysh_client_run(client
, line
, fp
, callback
, cbarg
);
225 if (rc
== CMD_NOT_MY_INSTANCE
) {
231 if (rc
!= CMD_SUCCESS
) {
232 if (!continue_on_err
)
237 if (wrong_instance
&& !correct_instance
&& fp
) {
239 "%% [%s]: command ignored as it targets an instance that is not running\n",
241 rc_all
= CMD_WARNING_CONFIG_FAILED
;
246 static int vtysh_client_execute(struct vtysh_client
*head_client
,
247 const char *line
, FILE *fp
)
249 return vtysh_client_run_all(head_client
, line
, 0, fp
, NULL
, NULL
);
252 static void vtysh_client_config(struct vtysh_client
*head_client
, char *line
)
254 /* watchfrr currently doesn't load any config, and has some hardcoded
255 * settings that show up in "show run". skip it here (for now at
256 * least) so we don't get that mangled up in config-write.
258 if (head_client
->flag
== VTYSH_WATCHFRR
)
261 vtysh_client_run_all(head_client
, line
, 1, NULL
,
262 vtysh_config_parse_line
, NULL
);
265 void vtysh_pager_init(void)
269 pager_defined
= getenv("VTYSH_PAGER");
272 vtysh_pager_name
= strdup(pager_defined
);
274 vtysh_pager_name
= strdup(VTYSH_PAGER
);
277 /* Command execution over the vty interface. */
278 static int vtysh_execute_func(const char *line
, int pager
)
283 const struct cmd_element
*cmd
;
287 int saved_ret
, saved_node
;
289 /* Split readline string up into the vector. */
290 vline
= cmd_make_strvec(line
);
295 saved_ret
= ret
= cmd_execute_command(vline
, vty
, &cmd
, 1);
296 saved_node
= vty
->node
;
298 /* If command doesn't succeeded in current node, try to walk up in node
300 * Changing vty->node is enough to try it just out without actual walkup
303 while (ret
!= CMD_SUCCESS
&& ret
!= CMD_SUCCESS_DAEMON
304 && ret
!= CMD_WARNING
&& ret
!= CMD_WARNING_CONFIG_FAILED
305 && vty
->node
> CONFIG_NODE
) {
306 vty
->node
= node_parent(vty
->node
);
307 ret
= cmd_execute_command(vline
, vty
, &cmd
, 1);
311 vty
->node
= saved_node
;
313 /* If command succeeded in any other node than current (tried > 0) we
315 * to move into node in the vtysh where it succeeded. */
316 if (ret
== CMD_SUCCESS
|| ret
== CMD_SUCCESS_DAEMON
317 || ret
== CMD_WARNING
) {
318 if ((saved_node
== BGP_VPNV4_NODE
319 || saved_node
== BGP_VPNV6_NODE
320 || saved_node
== BGP_IPV4_NODE
321 || saved_node
== BGP_IPV6_NODE
322 || saved_node
== BGP_IPV4M_NODE
323 || saved_node
== BGP_IPV4L_NODE
324 || saved_node
== BGP_IPV6L_NODE
325 || saved_node
== BGP_IPV6M_NODE
326 || saved_node
== BGP_EVPN_NODE
327 || saved_node
== LDP_IPV4_NODE
328 || saved_node
== LDP_IPV6_NODE
)
330 vtysh_execute("exit-address-family");
331 } else if ((saved_node
== BGP_EVPN_VNI_NODE
) && (tried
== 1)) {
332 vtysh_execute("exit-vni");
333 } else if (saved_node
== BGP_VRF_POLICY_NODE
&& (tried
== 1)) {
334 vtysh_execute("exit-vrf-policy");
335 } else if ((saved_node
== BGP_VNC_DEFAULTS_NODE
336 || saved_node
== BGP_VNC_NVE_GROUP_NODE
337 || saved_node
== BGP_VNC_L2_GROUP_NODE
)
339 vtysh_execute("exit-vnc");
340 } else if ((saved_node
== KEYCHAIN_KEY_NODE
341 || saved_node
== LDP_PSEUDOWIRE_NODE
342 || saved_node
== LDP_IPV4_IFACE_NODE
343 || saved_node
== LDP_IPV6_IFACE_NODE
)
345 vtysh_execute("exit");
347 vtysh_execute("end");
348 vtysh_execute("configure terminal");
351 /* If command didn't succeed in any node, continue with return value
358 cmd_free_strvec(vline
);
363 case CMD_WARNING_CONFIG_FAILED
:
364 if (vty
->type
== VTY_FILE
)
365 fprintf(stdout
, "Warning...\n");
367 case CMD_ERR_AMBIGUOUS
:
368 fprintf(stdout
, "%% Ambiguous command.\n");
370 case CMD_ERR_NO_MATCH
:
371 fprintf(stdout
, "%% Unknown command.\n");
373 case CMD_ERR_INCOMPLETE
:
374 fprintf(stdout
, "%% Command incomplete.\n");
376 case CMD_SUCCESS_DAEMON
: {
377 /* FIXME: Don't open pager for exit commands. popen() causes
379 * if exited from vtysh at all. This hack shouldn't cause any
381 * but is really ugly. */
382 if (pager
&& vtysh_pager_name
383 && (strncmp(line
, "exit", 4) != 0)) {
384 fp
= popen(vtysh_pager_name
, "w");
386 perror("popen failed for pager");
393 if (!strcmp(cmd
->string
, "configure terminal")) {
394 for (i
= 0; i
< array_size(vtysh_client
); i
++) {
395 cmd_stat
= vtysh_client_execute(
396 &vtysh_client
[i
], line
, fp
);
397 if (cmd_stat
== CMD_WARNING
)
403 vline
= cmd_make_strvec(line
);
406 if (pager
&& vtysh_pager_name
&& fp
408 if (pclose(fp
) == -1) {
409 perror("pclose failed for pager");
416 ret
= cmd_execute_command(vline
, vty
, &cmd
, 1);
417 cmd_free_strvec(vline
);
418 if (ret
!= CMD_SUCCESS_DAEMON
)
420 } else if (cmd
->func
) {
421 (*cmd
->func
)(cmd
, vty
, 0, NULL
);
426 cmd_stat
= CMD_SUCCESS
;
427 struct vtysh_client
*vc
;
428 for (i
= 0; i
< array_size(vtysh_client
); i
++) {
429 if (cmd
->daemon
& vtysh_client
[i
].flag
) {
430 if (vtysh_client
[i
].fd
< 0
431 && (cmd
->daemon
== vtysh_client
[i
].flag
)) {
432 bool any_inst
= false;
433 for (vc
= &vtysh_client
[i
]; vc
;
439 "%s is not running\n",
440 vtysh_client
[i
].name
);
444 cmd_stat
= vtysh_client_execute(
445 &vtysh_client
[i
], line
, fp
);
446 if (cmd_stat
!= CMD_SUCCESS
)
450 if (cmd_stat
!= CMD_SUCCESS
)
454 (*cmd
->func
)(cmd
, vty
, 0, NULL
);
457 if (pager
&& vtysh_pager_name
&& fp
&& closepager
) {
458 if (pclose(fp
) == -1) {
459 perror("pclose failed for pager");
466 int vtysh_execute_no_pager(const char *line
)
468 return vtysh_execute_func(line
, 0);
471 int vtysh_execute(const char *line
)
473 return vtysh_execute_func(line
, 1);
476 static char *trim(char *s
)
487 while (end
>= s
&& isspace(*end
))
491 while (*s
&& isspace(*s
))
497 int vtysh_mark_file(const char *filename
)
504 const struct cmd_element
*cmd
;
505 int saved_ret
, prev_node
;
507 char *vty_buf_copy
= NULL
;
508 char *vty_buf_trimmed
= NULL
;
510 if (strncmp("-", filename
, 1) == 0)
513 confp
= fopen(filename
, "r");
516 fprintf(stderr
, "%% Can't open config file %s due to '%s'.\n",
517 filename
, safe_strerror(errno
));
518 return (CMD_ERR_NO_FILE
);
522 vty
->fd
= 0; /* stdout */
523 vty
->type
= VTY_TERM
;
524 vty
->node
= CONFIG_NODE
;
526 vtysh_execute_no_pager("enable");
527 vtysh_execute_no_pager("configure terminal");
528 vty_buf_copy
= XCALLOC(MTYPE_VTYSH_CMD
, VTY_BUFSIZ
);
530 while (fgets(vty
->buf
, VTY_BUFSIZ
, confp
)) {
533 strcpy(vty_buf_copy
, vty
->buf
);
534 vty_buf_trimmed
= trim(vty_buf_copy
);
537 case LDP_IPV4_IFACE_NODE
:
538 if (strncmp(vty_buf_copy
, " ", 3)) {
539 fprintf(stdout
, " end\n");
540 vty
->node
= LDP_IPV4_NODE
;
543 case LDP_IPV6_IFACE_NODE
:
544 if (strncmp(vty_buf_copy
, " ", 3)) {
545 fprintf(stdout
, " end\n");
546 vty
->node
= LDP_IPV6_NODE
;
549 case LDP_PSEUDOWIRE_NODE
:
550 if (strncmp(vty_buf_copy
, " ", 2)) {
551 fprintf(stdout
, " end\n");
552 vty
->node
= LDP_L2VPN_NODE
;
559 if (vty_buf_trimmed
[0] == '!' || vty_buf_trimmed
[0] == '#') {
560 fprintf(stdout
, "%s", vty
->buf
);
564 /* Split readline string up into the vector. */
565 vline
= cmd_make_strvec(vty
->buf
);
568 fprintf(stdout
, "%s", vty
->buf
);
572 /* Ignore the "end" lines, we will generate these where
574 if (strlen(vty_buf_trimmed
) == 3
575 && strncmp("end", vty_buf_trimmed
, 3) == 0) {
579 prev_node
= vty
->node
;
580 saved_ret
= ret
= cmd_execute_command_strict(vline
, vty
, &cmd
);
582 /* If command doesn't succeeded in current node, try to walk up
584 * Changing vty->node is enough to try it just out without
587 while (ret
!= CMD_SUCCESS
&& ret
!= CMD_SUCCESS_DAEMON
588 && ret
!= CMD_WARNING
&& ret
!= CMD_WARNING_CONFIG_FAILED
589 && vty
->node
> CONFIG_NODE
) {
590 vty
->node
= node_parent(vty
->node
);
591 ret
= cmd_execute_command_strict(vline
, vty
, &cmd
);
595 /* If command succeeded in any other node than current (tried >
597 * to move into node in the vtysh where it succeeded. */
598 if (ret
== CMD_SUCCESS
|| ret
== CMD_SUCCESS_DAEMON
599 || ret
== CMD_WARNING
) {
600 if ((prev_node
== BGP_VPNV4_NODE
601 || prev_node
== BGP_VPNV6_NODE
602 || prev_node
== BGP_IPV4_NODE
603 || prev_node
== BGP_IPV6_NODE
604 || prev_node
== BGP_IPV4L_NODE
605 || prev_node
== BGP_IPV6L_NODE
606 || prev_node
== BGP_IPV4M_NODE
607 || prev_node
== BGP_IPV6M_NODE
608 || prev_node
== BGP_EVPN_NODE
)
610 fprintf(stdout
, "exit-address-family\n");
611 } else if ((prev_node
== BGP_EVPN_VNI_NODE
)
613 fprintf(stdout
, "exit-vni\n");
614 } else if ((prev_node
== KEYCHAIN_KEY_NODE
)
616 fprintf(stdout
, "exit\n");
618 fprintf(stdout
, "end\n");
621 /* If command didn't succeed in any node, continue with return
626 vty
->node
= prev_node
;
629 cmd_free_strvec(vline
);
632 case CMD_WARNING_CONFIG_FAILED
:
633 if (vty
->type
== VTY_FILE
)
634 fprintf(stderr
, "line %d: Warning...: %s\n",
638 XFREE(MTYPE_VTYSH_CMD
, vty_buf_copy
);
640 case CMD_ERR_AMBIGUOUS
:
641 fprintf(stderr
, "line %d: %% Ambiguous command: %s\n",
645 XFREE(MTYPE_VTYSH_CMD
, vty_buf_copy
);
646 return CMD_ERR_AMBIGUOUS
;
647 case CMD_ERR_NO_MATCH
:
648 fprintf(stderr
, "line %d: %% Unknown command: %s\n",
652 XFREE(MTYPE_VTYSH_CMD
, vty_buf_copy
);
653 return CMD_ERR_NO_MATCH
;
654 case CMD_ERR_INCOMPLETE
:
655 fprintf(stderr
, "line %d: %% Command incomplete: %s\n",
659 XFREE(MTYPE_VTYSH_CMD
, vty_buf_copy
);
660 return CMD_ERR_INCOMPLETE
;
662 fprintf(stdout
, "%s", vty
->buf
);
664 case CMD_SUCCESS_DAEMON
: {
666 int cmd_stat
= CMD_SUCCESS
;
668 fprintf(stdout
, "%s", vty
->buf
);
669 for (i
= 0; i
< array_size(vtysh_client
); i
++) {
670 if (cmd
->daemon
& vtysh_client
[i
].flag
) {
671 cmd_stat
= vtysh_client_execute(
672 &vtysh_client
[i
], vty
->buf
,
674 if (cmd_stat
!= CMD_SUCCESS
)
678 if (cmd_stat
!= CMD_SUCCESS
)
682 (*cmd
->func
)(cmd
, vty
, 0, NULL
);
686 /* This is the end */
687 fprintf(stdout
, "\nend\n");
689 XFREE(MTYPE_VTYSH_CMD
, vty_buf_copy
);
697 /* Configration make from file. */
698 int vtysh_config_from_file(struct vty
*vty
, FILE *fp
)
701 const struct cmd_element
*cmd
;
703 int retcode
= CMD_SUCCESS
;
705 while (fgets(vty
->buf
, VTY_BUFSIZ
, fp
)) {
708 ret
= command_config_read_one_line(vty
, &cmd
, 1);
712 case CMD_WARNING_CONFIG_FAILED
:
713 if (vty
->type
== VTY_FILE
)
714 fprintf(stderr
, "line %d: Warning[%d]...: %s\n",
715 lineno
, vty
->node
, vty
->buf
);
716 retcode
= ret
; /* once we have an error, we remember &
719 case CMD_ERR_AMBIGUOUS
:
721 "line %d: %% Ambiguous command[%d]: %s\n",
722 lineno
, vty
->node
, vty
->buf
);
723 retcode
= CMD_ERR_AMBIGUOUS
; /* once we have an error,
727 case CMD_ERR_NO_MATCH
:
728 fprintf(stderr
, "line %d: %% Unknown command[%d]: %s",
729 lineno
, vty
->node
, vty
->buf
);
731 CMD_ERR_NO_MATCH
; /* once we have an error, we
732 remember & return that */
734 case CMD_ERR_INCOMPLETE
:
736 "line %d: %% Command incomplete[%d]: %s\n",
737 lineno
, vty
->node
, vty
->buf
);
738 retcode
= CMD_ERR_INCOMPLETE
; /* once we have an error,
742 case CMD_SUCCESS_DAEMON
: {
744 int cmd_stat
= CMD_SUCCESS
;
746 for (i
= 0; i
< array_size(vtysh_client
); i
++) {
747 if (cmd
->daemon
& vtysh_client
[i
].flag
) {
748 cmd_stat
= vtysh_client_execute(
749 &vtysh_client
[i
], vty
->buf
,
752 * CMD_WARNING - Can mean that the
754 * parsed successfully but it was
756 * in a few spots. As such if we
758 * CMD_WARNING from a daemon we
760 * talking to the other daemons for the
764 if (cmd_stat
!= CMD_SUCCESS
765 && cmd_stat
!= CMD_WARNING
) {
767 "line %d: Failure to communicate[%d] to %s, line: %s\n",
769 vtysh_client
[i
].name
,
776 if (cmd_stat
!= CMD_SUCCESS
)
780 (*cmd
->func
)(cmd
, vty
, 0, NULL
);
788 /* We don't care about the point of the cursor when '?' is typed. */
789 static int vtysh_rl_describe(void)
796 struct cmd_token
*token
;
798 vline
= cmd_make_strvec(rl_line_buffer
);
800 /* In case of '> ?'. */
802 vline
= vector_init(1);
803 vector_set(vline
, NULL
);
804 } else if (rl_end
&& isspace((int)rl_line_buffer
[rl_end
- 1]))
805 vector_set(vline
, NULL
);
807 describe
= cmd_describe_command(vline
, vty
, &ret
);
809 fprintf(stdout
, "\n");
811 /* Ambiguous and no match error. */
813 case CMD_ERR_AMBIGUOUS
:
814 cmd_free_strvec(vline
);
815 fprintf(stdout
, "%% Ambiguous command.\n");
819 case CMD_ERR_NO_MATCH
:
820 cmd_free_strvec(vline
);
821 fprintf(stdout
, "%% There is no matched command.\n");
827 /* Get width of command string. */
829 for (i
= 0; i
< vector_active(describe
); i
++)
830 if ((token
= vector_slot(describe
, i
)) != NULL
) {
831 if (token
->text
[0] == '\0')
834 int len
= strlen(token
->text
);
840 for (i
= 0; i
< vector_active(describe
); i
++)
841 if ((token
= vector_slot(describe
, i
)) != NULL
) {
843 fprintf(stdout
, " %-s\n", token
->text
);
845 fprintf(stdout
, " %-*s %s\n", width
,
846 token
->text
, token
->desc
);
848 if (IS_VARYING_TOKEN(token
->type
)) {
849 const char *ref
= vector_slot(
850 vline
, vector_active(vline
) - 1);
852 vector varcomps
= vector_init(VECTOR_MIN_SIZE
);
853 cmd_variable_complete(token
, ref
, varcomps
);
855 if (vector_active(varcomps
) > 0) {
857 rl_get_screen_size(&rows
, &cols
);
859 char *ac
= cmd_variable_comp2str(
861 fprintf(stdout
, "%s\n", ac
);
862 XFREE(MTYPE_TMP
, ac
);
865 vector_free(varcomps
);
869 cmd_free_strvec(vline
);
870 vector_free(describe
);
877 /* Result of cmd_complete_command() call will be stored here
878 * and used in new_completion() in order to put the space in
879 * correct places only. */
882 static char *command_generator(const char *text
, int state
)
885 static char **matched
= NULL
;
886 static int index
= 0;
892 if (vty
->node
== AUTH_NODE
|| vty
->node
== AUTH_ENABLE_NODE
)
895 vline
= cmd_make_strvec(rl_line_buffer
);
899 if (rl_end
&& isspace((int)rl_line_buffer
[rl_end
- 1]))
900 vector_set(vline
, NULL
);
902 matched
= cmd_complete_command(vline
, vty
, &complete_status
);
903 cmd_free_strvec(vline
);
906 if (matched
&& matched
[index
])
907 /* this is free()'d by readline, but we leak 1 count of
908 * MTYPE_COMPLETION */
909 return matched
[index
++];
911 XFREE(MTYPE_TMP
, matched
);
917 static char **new_completion(char *text
, int start
, int end
)
921 matches
= rl_completion_matches(text
, command_generator
);
925 if (complete_status
!= CMD_COMPLETE_FULL_MATCH
)
926 /* only append a space on full match */
927 rl_completion_append_character
= '\0';
933 /* Vty node structures. */
934 static struct cmd_node bgp_node
= {
935 BGP_NODE
, "%s(config-router)# ",
938 static struct cmd_node rip_node
= {
939 RIP_NODE
, "%s(config-router)# ",
942 static struct cmd_node isis_node
= {
943 ISIS_NODE
, "%s(config-router)# ",
946 static struct cmd_node interface_node
= {
947 INTERFACE_NODE
, "%s(config-if)# ",
950 static struct cmd_node pw_node
= {
951 PW_NODE
, "%s(config-pw)# ",
954 static struct cmd_node ns_node
= {
955 NS_NODE
, "%s(config-logical-router)# ",
958 static struct cmd_node vrf_node
= {
959 VRF_NODE
, "%s(config-vrf)# ",
962 static struct cmd_node rmap_node
= {RMAP_NODE
, "%s(config-route-map)# "};
964 static struct cmd_node zebra_node
= {ZEBRA_NODE
, "%s(config-router)# "};
966 static struct cmd_node bgp_vpnv4_node
= {BGP_VPNV4_NODE
,
967 "%s(config-router-af)# "};
969 static struct cmd_node bgp_vpnv6_node
= {BGP_VPNV6_NODE
,
970 "%s(config-router-af)# "};
972 static struct cmd_node bgp_ipv4_node
= {BGP_IPV4_NODE
,
973 "%s(config-router-af)# "};
975 static struct cmd_node bgp_ipv4m_node
= {BGP_IPV4M_NODE
,
976 "%s(config-router-af)# "};
978 static struct cmd_node bgp_ipv4l_node
= {BGP_IPV4L_NODE
,
979 "%s(config-router-af)# "};
981 static struct cmd_node bgp_ipv6_node
= {BGP_IPV6_NODE
,
982 "%s(config-router-af)# "};
984 static struct cmd_node bgp_ipv6m_node
= {BGP_IPV6M_NODE
,
985 "%s(config-router-af)# "};
987 static struct cmd_node bgp_evpn_node
= {BGP_EVPN_NODE
,
988 "%s(config-router-af)# "};
990 static struct cmd_node bgp_evpn_vni_node
= {BGP_EVPN_VNI_NODE
,
991 "%s(config-router-af-vni)# "};
993 static struct cmd_node bgp_ipv6l_node
= {BGP_IPV6L_NODE
,
994 "%s(config-router-af)# "};
996 static struct cmd_node bgp_vnc_defaults_node
= {
997 BGP_VNC_DEFAULTS_NODE
, "%s(config-router-vnc-defaults)# "};
999 static struct cmd_node bgp_vnc_nve_group_node
= {
1000 BGP_VNC_NVE_GROUP_NODE
, "%s(config-router-vnc-nve-group)# "};
1002 static struct cmd_node bgp_vrf_policy_node
= {BGP_VRF_POLICY_NODE
,
1003 "%s(config-router-vrf-policy)# "};
1005 static struct cmd_node bgp_vnc_l2_group_node
= {
1006 BGP_VNC_L2_GROUP_NODE
, "%s(config-router-vnc-l2-group)# "};
1008 static struct cmd_node ospf_node
= {OSPF_NODE
, "%s(config-router)# "};
1010 static struct cmd_node eigrp_node
= {EIGRP_NODE
, "%s(config-router)# "};
1012 static struct cmd_node babel_node
= {BABEL_NODE
, "%s(config-router)# "};
1014 static struct cmd_node ripng_node
= {RIPNG_NODE
, "%s(config-router)# "};
1016 static struct cmd_node ospf6_node
= {OSPF6_NODE
, "%s(config-ospf6)# "};
1018 static struct cmd_node ldp_node
= {LDP_NODE
, "%s(config-ldp)# "};
1020 static struct cmd_node ldp_ipv4_node
= {LDP_IPV4_NODE
, "%s(config-ldp-af)# "};
1022 static struct cmd_node ldp_ipv6_node
= {LDP_IPV6_NODE
, "%s(config-ldp-af)# "};
1024 static struct cmd_node ldp_ipv4_iface_node
= {LDP_IPV4_IFACE_NODE
,
1025 "%s(config-ldp-af-if)# "};
1027 static struct cmd_node ldp_ipv6_iface_node
= {LDP_IPV6_IFACE_NODE
,
1028 "%s(config-ldp-af-if)# "};
1030 static struct cmd_node ldp_l2vpn_node
= {LDP_L2VPN_NODE
, "%s(config-l2vpn)# "};
1032 static struct cmd_node ldp_pseudowire_node
= {LDP_PSEUDOWIRE_NODE
,
1033 "%s(config-l2vpn-pw)# "};
1035 static struct cmd_node keychain_node
= {KEYCHAIN_NODE
, "%s(config-keychain)# "};
1037 static struct cmd_node keychain_key_node
= {KEYCHAIN_KEY_NODE
,
1038 "%s(config-keychain-key)# "};
1040 struct cmd_node link_params_node
= {
1041 LINK_PARAMS_NODE
, "%s(config-link-params)# ",
1044 /* Defined in lib/vty.c */
1045 extern struct cmd_node vty_node
;
1047 /* When '^Z' is received from vty, move down to the enable mode. */
1048 static int vtysh_end(void)
1050 switch (vty
->node
) {
1053 /* Nothing to do. */
1056 vty
->node
= ENABLE_NODE
;
1062 DEFUNSH(VTYSH_REALLYALL
, vtysh_end_all
, vtysh_end_all_cmd
, "end",
1063 "End current mode and change to enable mode\n")
1068 DEFUNSH(VTYSH_BGPD
, router_bgp
, router_bgp_cmd
,
1069 "router bgp [(1-4294967295) [<view|vrf> WORD]]",
1070 ROUTER_STR BGP_STR AS_STR
1071 "BGP view\nBGP VRF\n"
1074 vty
->node
= BGP_NODE
;
1078 DEFUNSH(VTYSH_BGPD
, address_family_vpnv4
, address_family_vpnv4_cmd
,
1079 "address-family vpnv4 [unicast]",
1080 "Enter Address Family command mode\n"
1082 "Address Family modifier\n")
1084 vty
->node
= BGP_VPNV4_NODE
;
1088 DEFUNSH(VTYSH_BGPD
, address_family_vpnv6
, address_family_vpnv6_cmd
,
1089 "address-family vpnv6 [unicast]",
1090 "Enter Address Family command mode\n"
1092 "Address Family modifier\n")
1094 vty
->node
= BGP_VPNV6_NODE
;
1098 DEFUNSH(VTYSH_BGPD
, address_family_ipv4
, address_family_ipv4_cmd
,
1099 "address-family ipv4 [unicast]",
1100 "Enter Address Family command mode\n"
1102 "Address Family Modifier\n")
1104 vty
->node
= BGP_IPV4_NODE
;
1108 DEFUNSH(VTYSH_BGPD
, address_family_ipv4_multicast
,
1109 address_family_ipv4_multicast_cmd
, "address-family ipv4 multicast",
1110 "Enter Address Family command mode\n"
1112 "Address Family modifier\n")
1114 vty
->node
= BGP_IPV4M_NODE
;
1118 DEFUNSH(VTYSH_BGPD
, address_family_ipv4_vpn
, address_family_ipv4_vpn_cmd
,
1119 "address-family ipv4 vpn",
1120 "Enter Address Family command mode\n"
1122 "Address Family modifier\n")
1124 vty
->node
= BGP_VPNV4_NODE
;
1128 DEFUNSH(VTYSH_BGPD
, address_family_ipv4_labeled_unicast
,
1129 address_family_ipv4_labeled_unicast_cmd
,
1130 "address-family ipv4 labeled-unicast",
1131 "Enter Address Family command mode\n"
1133 "Address Family modifier\n")
1135 vty
->node
= BGP_IPV4L_NODE
;
1139 DEFUNSH(VTYSH_BGPD
, address_family_ipv6
, address_family_ipv6_cmd
,
1140 "address-family ipv6 [unicast]",
1141 "Enter Address Family command mode\n"
1143 "Address Family modifier\n")
1145 vty
->node
= BGP_IPV6_NODE
;
1149 DEFUNSH(VTYSH_BGPD
, address_family_ipv6_multicast
,
1150 address_family_ipv6_multicast_cmd
, "address-family ipv6 multicast",
1151 "Enter Address Family command mode\n"
1153 "Address Family modifier\n")
1155 vty
->node
= BGP_IPV6M_NODE
;
1159 DEFUNSH(VTYSH_BGPD
, address_family_ipv6_vpn
, address_family_ipv6_vpn_cmd
,
1160 "address-family ipv6 vpn",
1161 "Enter Address Family command mode\n"
1163 "Address Family modifier\n")
1165 vty
->node
= BGP_VPNV6_NODE
;
1169 DEFUNSH(VTYSH_BGPD
, address_family_ipv6_labeled_unicast
,
1170 address_family_ipv6_labeled_unicast_cmd
,
1171 "address-family ipv6 labeled-unicast",
1172 "Enter Address Family command mode\n"
1174 "Address Family modifier\n")
1176 vty
->node
= BGP_IPV6L_NODE
;
1180 DEFUNSH(VTYSH_BGPD
, address_family_evpn
, address_family_evpn_cmd
,
1181 "address-family <l2vpn evpn>",
1182 "Enter Address Family command mode\n"
1184 "Address Family modifier\n")
1186 vty
->node
= BGP_EVPN_NODE
;
1190 #if defined(HAVE_CUMULUS)
1191 DEFUNSH_HIDDEN(VTYSH_BGPD
, address_family_evpn2
, address_family_evpn2_cmd
,
1192 "address-family evpn",
1193 "Enter Address Family command mode\n"
1194 "EVPN Address family\n")
1196 vty
->node
= BGP_EVPN_NODE
;
1201 DEFUNSH(VTYSH_BGPD
, bgp_evpn_vni
, bgp_evpn_vni_cmd
, "vni (1-16777215)",
1202 "VXLAN Network Identifier\n"
1205 vty
->node
= BGP_EVPN_VNI_NODE
;
1209 #if defined(ENABLE_BGP_VNC)
1210 DEFUNSH(VTYSH_BGPD
, vnc_defaults
, vnc_defaults_cmd
, "vnc defaults",
1211 "VNC/RFP related configuration\n"
1212 "Configure default NVE group\n")
1214 vty
->node
= BGP_VNC_DEFAULTS_NODE
;
1218 DEFUNSH(VTYSH_BGPD
, vnc_nve_group
, vnc_nve_group_cmd
, "vnc nve-group NAME",
1219 "VNC/RFP related configuration\n"
1220 "Configure a NVE group\n"
1223 vty
->node
= BGP_VNC_NVE_GROUP_NODE
;
1227 DEFUNSH(VTYSH_BGPD
, vnc_vrf_policy
, vnc_vrf_policy_cmd
, "vrf-policy NAME",
1228 "Configure a VRF policy group\n"
1231 vty
->node
= BGP_VRF_POLICY_NODE
;
1235 DEFUNSH(VTYSH_BGPD
, vnc_l2_group
, vnc_l2_group_cmd
, "vnc l2-group NAME",
1236 "VNC/RFP related configuration\n"
1237 "Configure a L2 group\n"
1240 vty
->node
= BGP_VNC_L2_GROUP_NODE
;
1245 DEFUNSH(VTYSH_RIPD
, key_chain
, key_chain_cmd
, "key chain WORD",
1246 "Authentication key management\n"
1247 "Key-chain management\n"
1250 vty
->node
= KEYCHAIN_NODE
;
1254 DEFUNSH(VTYSH_RIPD
, key
, key_cmd
, "key (0-2147483647)",
1256 "Key identifier number\n")
1258 vty
->node
= KEYCHAIN_KEY_NODE
;
1262 DEFUNSH(VTYSH_RIPD
, router_rip
, router_rip_cmd
, "router rip",
1265 vty
->node
= RIP_NODE
;
1269 DEFUNSH(VTYSH_RIPNGD
, router_ripng
, router_ripng_cmd
, "router ripng",
1270 ROUTER_STR
"RIPng\n")
1272 vty
->node
= RIPNG_NODE
;
1276 DEFUNSH(VTYSH_OSPFD
, router_ospf
, router_ospf_cmd
,
1277 "router ospf [(1-65535)] [vrf NAME]",
1278 "Enable a routing process\n"
1279 "Start OSPF configuration\n"
1283 vty
->node
= OSPF_NODE
;
1287 DEFUNSH(VTYSH_EIGRPD
, router_eigrp
, router_eigrp_cmd
, "router eigrp (1-65535)",
1288 "Enable a routing process\n"
1289 "Start EIGRP configuration\n"
1290 "AS number to use\n")
1292 vty
->node
= EIGRP_NODE
;
1296 DEFUNSH(VTYSH_BABELD
, router_babel
, router_babel_cmd
, "router babel",
1297 "Enable a routing process\n"
1298 "Make Babel instance command\n")
1300 vty
->node
= BABEL_NODE
;
1304 DEFUNSH(VTYSH_OSPF6D
, router_ospf6
, router_ospf6_cmd
, "router ospf6",
1305 ROUTER_STR OSPF6_STR
)
1307 vty
->node
= OSPF6_NODE
;
1311 #if defined(HAVE_LDPD)
1312 DEFUNSH(VTYSH_LDPD
, ldp_mpls_ldp
, ldp_mpls_ldp_cmd
, "mpls ldp",
1313 "Global MPLS configuration subcommands\n"
1314 "Label Distribution Protocol\n")
1316 vty
->node
= LDP_NODE
;
1320 DEFUNSH(VTYSH_LDPD
, ldp_address_family_ipv4
, ldp_address_family_ipv4_cmd
,
1321 "address-family ipv4",
1322 "Configure Address Family and its parameters\n"
1325 vty
->node
= LDP_IPV4_NODE
;
1329 DEFUNSH(VTYSH_LDPD
, ldp_address_family_ipv6
, ldp_address_family_ipv6_cmd
,
1330 "address-family ipv6",
1331 "Configure Address Family and its parameters\n"
1334 vty
->node
= LDP_IPV6_NODE
;
1338 DEFUNSH(VTYSH_LDPD
, ldp_exit_address_family
, ldp_exit_address_family_cmd
,
1339 "exit-address-family", "Exit from Address Family configuration mode\n")
1341 if (vty
->node
== LDP_IPV4_NODE
|| vty
->node
== LDP_IPV6_NODE
)
1342 vty
->node
= LDP_NODE
;
1346 DEFUNSH(VTYSH_LDPD
, ldp_interface_ifname
, ldp_interface_ifname_cmd
,
1348 "Enable LDP on an interface and enter interface submode\n"
1349 "Interface's name\n")
1351 switch (vty
->node
) {
1353 vty
->node
= LDP_IPV4_IFACE_NODE
;
1356 vty
->node
= LDP_IPV6_IFACE_NODE
;
1365 DEFUNSH(VTYSH_LDPD
, ldp_l2vpn_word_type_vpls
, ldp_l2vpn_word_type_vpls_cmd
,
1366 "l2vpn WORD type vpls",
1367 "Configure l2vpn commands\n"
1370 "Virtual Private LAN Service\n")
1372 vty
->node
= LDP_L2VPN_NODE
;
1376 DEFUNSH(VTYSH_LDPD
, ldp_member_pseudowire_ifname
,
1377 ldp_member_pseudowire_ifname_cmd
, "member pseudowire IFNAME",
1378 "L2VPN member configuration\n"
1379 "Pseudowire interface\n"
1380 "Interface's name\n")
1382 vty
->node
= LDP_PSEUDOWIRE_NODE
;
1387 DEFUNSH(VTYSH_ISISD
, router_isis
, router_isis_cmd
, "router isis WORD",
1390 "ISO Routing area tag")
1392 vty
->node
= ISIS_NODE
;
1396 DEFUNSH(VTYSH_RMAP
, vtysh_route_map
, vtysh_route_map_cmd
,
1397 "route-map WORD <deny|permit> (1-65535)",
1398 "Create route-map or enter route-map command mode\n"
1400 "Route map denies set operations\n"
1401 "Route map permits set operations\n"
1402 "Sequence to insert to/delete from existing route-map entry\n")
1404 vty
->node
= RMAP_NODE
;
1408 DEFUNSH(VTYSH_ALL
, vtysh_line_vty
, vtysh_line_vty_cmd
, "line vty",
1409 "Configure a terminal line\n"
1410 "Virtual terminal\n")
1412 vty
->node
= VTY_NODE
;
1416 DEFUNSH(VTYSH_REALLYALL
, vtysh_enable
, vtysh_enable_cmd
, "enable",
1417 "Turn on privileged mode command\n")
1419 vty
->node
= ENABLE_NODE
;
1423 DEFUNSH(VTYSH_REALLYALL
, vtysh_disable
, vtysh_disable_cmd
, "disable",
1424 "Turn off privileged mode command\n")
1426 if (vty
->node
== ENABLE_NODE
)
1427 vty
->node
= VIEW_NODE
;
1431 DEFUNSH(VTYSH_REALLYALL
, vtysh_config_terminal
, vtysh_config_terminal_cmd
,
1432 "configure terminal",
1433 "Configuration from vty interface\n"
1434 "Configuration terminal\n")
1436 vty
->node
= CONFIG_NODE
;
1440 static int vtysh_exit(struct vty
*vty
)
1442 switch (vty
->node
) {
1448 vty
->node
= ENABLE_NODE
;
1450 case INTERFACE_NODE
:
1463 case LDP_L2VPN_NODE
:
1469 vtysh_execute("end");
1470 vtysh_execute("configure terminal");
1471 vty
->node
= CONFIG_NODE
;
1473 case BGP_VPNV4_NODE
:
1474 case BGP_VPNV6_NODE
:
1476 case BGP_IPV4M_NODE
:
1477 case BGP_IPV4L_NODE
:
1479 case BGP_IPV6M_NODE
:
1480 case BGP_IPV6L_NODE
:
1481 case BGP_VRF_POLICY_NODE
:
1483 case BGP_VNC_DEFAULTS_NODE
:
1484 case BGP_VNC_NVE_GROUP_NODE
:
1485 case BGP_VNC_L2_GROUP_NODE
:
1486 vty
->node
= BGP_NODE
;
1488 case BGP_EVPN_VNI_NODE
:
1489 vty
->node
= BGP_EVPN_NODE
;
1493 vty
->node
= LDP_NODE
;
1495 case LDP_IPV4_IFACE_NODE
:
1496 vty
->node
= LDP_IPV4_NODE
;
1498 case LDP_IPV6_IFACE_NODE
:
1499 vty
->node
= LDP_IPV6_NODE
;
1501 case LDP_PSEUDOWIRE_NODE
:
1502 vty
->node
= LDP_L2VPN_NODE
;
1504 case KEYCHAIN_KEY_NODE
:
1505 vty
->node
= KEYCHAIN_NODE
;
1507 case LINK_PARAMS_NODE
:
1508 vty
->node
= INTERFACE_NODE
;
1516 DEFUNSH(VTYSH_REALLYALL
, vtysh_exit_all
, vtysh_exit_all_cmd
, "exit",
1517 "Exit current mode and down to previous mode\n")
1519 return vtysh_exit(vty
);
1522 DEFUNSH(VTYSH_ALL
, vtysh_quit_all
, vtysh_quit_all_cmd
, "quit",
1523 "Exit current mode and down to previous mode\n")
1525 return vtysh_exit_all(self
, vty
, argc
, argv
);
1528 DEFUNSH(VTYSH_BGPD
, exit_address_family
, exit_address_family_cmd
,
1529 "exit-address-family", "Exit from Address Family configuration mode\n")
1531 if (vty
->node
== BGP_IPV4_NODE
|| vty
->node
== BGP_IPV4M_NODE
1532 || vty
->node
== BGP_IPV4L_NODE
|| vty
->node
== BGP_VPNV4_NODE
1533 || vty
->node
== BGP_VPNV6_NODE
|| vty
->node
== BGP_IPV6_NODE
1534 || vty
->node
== BGP_IPV6L_NODE
|| vty
->node
== BGP_IPV6M_NODE
1535 || vty
->node
== BGP_EVPN_NODE
)
1536 vty
->node
= BGP_NODE
;
1540 DEFUNSH(VTYSH_BGPD
, exit_vni
, exit_vni_cmd
, "exit-vni", "Exit from VNI mode\n")
1542 if (vty
->node
== BGP_EVPN_VNI_NODE
)
1543 vty
->node
= BGP_EVPN_NODE
;
1547 DEFUNSH(VTYSH_BGPD
, exit_vnc_config
, exit_vnc_config_cmd
, "exit-vnc",
1548 "Exit from VNC configuration mode\n")
1550 if (vty
->node
== BGP_VNC_DEFAULTS_NODE
1551 || vty
->node
== BGP_VNC_NVE_GROUP_NODE
1552 || vty
->node
== BGP_VNC_L2_GROUP_NODE
)
1553 vty
->node
= BGP_NODE
;
1557 DEFUNSH(VTYSH_BGPD
, exit_vrf_policy
, exit_vrf_policy_cmd
, "exit-vrf-policy",
1558 "Exit from VRF configuration mode\n")
1560 if (vty
->node
== BGP_VRF_POLICY_NODE
)
1561 vty
->node
= BGP_NODE
;
1565 DEFUNSH(VTYSH_RIPD
, vtysh_exit_ripd
, vtysh_exit_ripd_cmd
, "exit",
1566 "Exit current mode and down to previous mode\n")
1568 return vtysh_exit(vty
);
1571 DEFUNSH(VTYSH_RIPD
, vtysh_quit_ripd
, vtysh_quit_ripd_cmd
, "quit",
1572 "Exit current mode and down to previous mode\n")
1574 return vtysh_exit_ripd(self
, vty
, argc
, argv
);
1577 DEFUNSH(VTYSH_RIPNGD
, vtysh_exit_ripngd
, vtysh_exit_ripngd_cmd
, "exit",
1578 "Exit current mode and down to previous mode\n")
1580 return vtysh_exit(vty
);
1583 DEFUNSH(VTYSH_RIPNGD
, vtysh_quit_ripngd
, vtysh_quit_ripngd_cmd
, "quit",
1584 "Exit current mode and down to previous mode\n")
1586 return vtysh_exit_ripngd(self
, vty
, argc
, argv
);
1589 DEFUNSH(VTYSH_RMAP
, vtysh_exit_rmap
, vtysh_exit_rmap_cmd
, "exit",
1590 "Exit current mode and down to previous mode\n")
1592 return vtysh_exit(vty
);
1595 DEFUNSH(VTYSH_RMAP
, vtysh_quit_rmap
, vtysh_quit_rmap_cmd
, "quit",
1596 "Exit current mode and down to previous mode\n")
1598 return vtysh_exit_rmap(self
, vty
, argc
, argv
);
1601 DEFUNSH(VTYSH_BGPD
, vtysh_exit_bgpd
, vtysh_exit_bgpd_cmd
, "exit",
1602 "Exit current mode and down to previous mode\n")
1604 return vtysh_exit(vty
);
1607 DEFUNSH(VTYSH_BGPD
, vtysh_quit_bgpd
, vtysh_quit_bgpd_cmd
, "quit",
1608 "Exit current mode and down to previous mode\n")
1610 return vtysh_exit_bgpd(self
, vty
, argc
, argv
);
1613 DEFUNSH(VTYSH_OSPFD
, vtysh_exit_ospfd
, vtysh_exit_ospfd_cmd
, "exit",
1614 "Exit current mode and down to previous mode\n")
1616 return vtysh_exit(vty
);
1619 DEFUNSH(VTYSH_OSPFD
, vtysh_quit_ospfd
, vtysh_quit_ospfd_cmd
, "quit",
1620 "Exit current mode and down to previous mode\n")
1622 return vtysh_exit_ospfd(self
, vty
, argc
, argv
);
1625 DEFUNSH(VTYSH_EIGRPD
, vtysh_exit_eigrpd
, vtysh_exit_eigrpd_cmd
, "exit",
1626 "Exit current mode and down to previous mode\n")
1628 return vtysh_exit(vty
);
1631 DEFUNSH(VTYSH_EIGRPD
, vtysh_quit_eigrpd
, vtysh_quit_eigrpd_cmd
, "quit",
1632 "Exit current mode and down to previous mode\n")
1634 return vtysh_exit(vty
);
1637 DEFUNSH(VTYSH_EIGRPD
, vtysh_exit_babeld
, vtysh_exit_babeld_cmd
, "exit",
1638 "Exit current mode and down to previous mode\n")
1640 return vtysh_exit(vty
);
1643 DEFUNSH(VTYSH_BABELD
, vtysh_quit_babeld
, vtysh_quit_babeld_cmd
, "quit",
1644 "Exit current mode and down to previous mode\n")
1646 return vtysh_exit(vty
);
1649 DEFUNSH(VTYSH_OSPF6D
, vtysh_exit_ospf6d
, vtysh_exit_ospf6d_cmd
, "exit",
1650 "Exit current mode and down to previous mode\n")
1652 return vtysh_exit(vty
);
1655 DEFUNSH(VTYSH_OSPF6D
, vtysh_quit_ospf6d
, vtysh_quit_ospf6d_cmd
, "quit",
1656 "Exit current mode and down to previous mode\n")
1658 return vtysh_exit_ospf6d(self
, vty
, argc
, argv
);
1661 #if defined(HAVE_LDPD)
1662 DEFUNSH(VTYSH_LDPD
, vtysh_exit_ldpd
, vtysh_exit_ldpd_cmd
, "exit",
1663 "Exit current mode and down to previous mode\n")
1665 return vtysh_exit(vty
);
1668 ALIAS(vtysh_exit_ldpd
, vtysh_quit_ldpd_cmd
, "quit",
1669 "Exit current mode and down to previous mode\n")
1672 DEFUNSH(VTYSH_ISISD
, vtysh_exit_isisd
, vtysh_exit_isisd_cmd
, "exit",
1673 "Exit current mode and down to previous mode\n")
1675 return vtysh_exit(vty
);
1678 DEFUNSH(VTYSH_ISISD
, vtysh_quit_isisd
, vtysh_quit_isisd_cmd
, "quit",
1679 "Exit current mode and down to previous mode\n")
1681 return vtysh_exit_isisd(self
, vty
, argc
, argv
);
1684 DEFUNSH(VTYSH_ALL
, vtysh_exit_line_vty
, vtysh_exit_line_vty_cmd
, "exit",
1685 "Exit current mode and down to previous mode\n")
1687 return vtysh_exit(vty
);
1690 DEFUNSH(VTYSH_ALL
, vtysh_quit_line_vty
, vtysh_quit_line_vty_cmd
, "quit",
1691 "Exit current mode and down to previous mode\n")
1693 return vtysh_exit_line_vty(self
, vty
, argc
, argv
);
1696 DEFUNSH(VTYSH_INTERFACE
, vtysh_interface
, vtysh_interface_cmd
,
1697 "interface IFNAME [vrf NAME]",
1698 "Select an interface to configure\n"
1699 "Interface's name\n" VRF_CMD_HELP_STR
)
1701 vty
->node
= INTERFACE_NODE
;
1705 DEFUNSH(VTYSH_ZEBRA
, vtysh_pseudowire
, vtysh_pseudowire_cmd
,
1706 "pseudowire IFNAME",
1707 "Static pseudowire configuration\n"
1708 "Pseudowire name\n")
1710 vty
->node
= PW_NODE
;
1714 /* TODO Implement "no interface command in isisd. */
1715 DEFSH(VTYSH_ZEBRA
| VTYSH_RIPD
| VTYSH_RIPNGD
| VTYSH_OSPFD
| VTYSH_OSPF6D
1717 vtysh_no_interface_cmd
, "no interface IFNAME", NO_STR
1718 "Delete a pseudo interface's configuration\n"
1719 "Interface's name\n")
1721 DEFSH(VTYSH_ZEBRA
, vtysh_no_interface_vrf_cmd
, "no interface IFNAME vrf NAME",
1723 "Delete a pseudo interface's configuration\n"
1724 "Interface's name\n" VRF_CMD_HELP_STR
)
1726 DEFUNSH(VTYSH_NS
, vtysh_ns
, vtysh_ns_cmd
, "logical-router (1-65535) ns NAME",
1727 "Enable a logical-router\n"
1728 "Specify the logical-router indentifier\n"
1730 "The file name in " NS_RUN_DIR
", or a full pathname\n")
1732 vty
->node
= NS_NODE
;
1736 DEFUNSH(VTYSH_VRF
, vtysh_vrf
, vtysh_vrf_cmd
, "vrf NAME",
1737 "Select a VRF to configure\n"
1740 vty
->node
= VRF_NODE
;
1744 DEFSH(VTYSH_ZEBRA
, vtysh_no_vrf_cmd
, "no vrf NAME", NO_STR
1745 "Delete a pseudo vrf's configuration\n"
1748 DEFUNSH(VTYSH_NS
, vtysh_exit_ns
, vtysh_exit_ns_cmd
, "exit",
1749 "Exit current mode and down to previous mode\n")
1751 return vtysh_exit(vty
);
1754 DEFUNSH(VTYSH_NS
, vtysh_quit_ns
, vtysh_quit_ns_cmd
, "quit",
1755 "Exit current mode and down to previous mode\n")
1757 return vtysh_exit_ns(self
, vty
, argc
, argv
);
1760 DEFUNSH(VTYSH_VRF
, vtysh_exit_vrf
, vtysh_exit_vrf_cmd
, "exit",
1761 "Exit current mode and down to previous mode\n")
1763 return vtysh_exit(vty
);
1766 DEFUNSH(VTYSH_VRF
, vtysh_quit_vrf
, vtysh_quit_vrf_cmd
, "quit",
1767 "Exit current mode and down to previous mode\n")
1769 return vtysh_exit_vrf(self
, vty
, argc
, argv
);
1772 /* TODO Implement interface description commands in ripngd, ospf6d
1774 DEFSH(VTYSH_ZEBRA
| VTYSH_RIPD
| VTYSH_OSPFD
| VTYSH_EIGRPD
,
1775 vtysh_interface_desc_cmd
, "description LINE...",
1776 "Interface specific description\n"
1777 "Characters describing this interface\n")
1779 DEFSH(VTYSH_ZEBRA
| VTYSH_RIPD
| VTYSH_OSPFD
| VTYSH_EIGRPD
,
1780 vtysh_no_interface_desc_cmd
, "no description",
1781 NO_STR
"Interface specific description\n")
1783 DEFUNSH(VTYSH_INTERFACE
, vtysh_exit_interface
, vtysh_exit_interface_cmd
, "exit",
1784 "Exit current mode and down to previous mode\n")
1786 return vtysh_exit(vty
);
1789 DEFUNSH(VTYSH_INTERFACE
, vtysh_quit_interface
, vtysh_quit_interface_cmd
, "quit",
1790 "Exit current mode and down to previous mode\n")
1792 return vtysh_exit_interface(self
, vty
, argc
, argv
);
1795 DEFUN (vtysh_show_thread
,
1796 vtysh_show_thread_cmd
,
1797 "show thread cpu [FILTER]",
1799 "Thread information\n"
1800 "Thread CPU usage\n"
1801 "Display filter (rwtexb)\n")
1805 int ret
= CMD_SUCCESS
;
1808 const char *filter
=
1809 argv_find(argv
, argc
, "FILTER", &idx
) ? argv
[idx
]->arg
: "";
1811 snprintf(line
, sizeof(line
), "do show thread cpu %s\n", filter
);
1812 for (i
= 0; i
< array_size(vtysh_client
); i
++)
1813 if (vtysh_client
[i
].fd
>= 0) {
1814 fprintf(stdout
, "Thread statistics for %s:\n",
1815 vtysh_client
[i
].name
);
1816 ret
= vtysh_client_execute(&vtysh_client
[i
], line
,
1818 fprintf(stdout
, "\n");
1823 DEFUN (vtysh_show_work_queues
,
1824 vtysh_show_work_queues_cmd
,
1827 "Work Queue information\n")
1830 int ret
= CMD_SUCCESS
;
1831 char line
[] = "do show work-queues\n";
1833 for (i
= 0; i
< array_size(vtysh_client
); i
++)
1834 if (vtysh_client
[i
].fd
>= 0) {
1835 fprintf(stdout
, "Work queue statistics for %s:\n",
1836 vtysh_client
[i
].name
);
1837 ret
= vtysh_client_execute(&vtysh_client
[i
], line
,
1839 fprintf(stdout
, "\n");
1845 DEFUN (vtysh_show_work_queues_daemon
,
1846 vtysh_show_work_queues_daemon_cmd
,
1847 "show work-queues <zebra|ripd|ripngd|ospfd|ospf6d|bgpd|isisd>",
1849 "Work Queue information\n"
1850 "For the zebra daemon\n"
1851 "For the rip daemon\n"
1852 "For the ripng daemon\n"
1853 "For the ospf daemon\n"
1854 "For the ospfv6 daemon\n"
1855 "For the bgp daemon\n"
1856 "For the isis daemon\n")
1858 int idx_protocol
= 2;
1860 int ret
= CMD_SUCCESS
;
1862 for (i
= 0; i
< array_size(vtysh_client
); i
++) {
1863 if (strmatch(vtysh_client
[i
].name
, argv
[idx_protocol
]->text
))
1867 ret
= vtysh_client_execute(&vtysh_client
[i
], "show work-queues\n",
1873 DEFUNSH(VTYSH_ZEBRA
, vtysh_link_params
, vtysh_link_params_cmd
, "link-params",
1876 vty
->node
= LINK_PARAMS_NODE
;
1880 DEFUNSH(VTYSH_ZEBRA
, exit_link_params
, exit_link_params_cmd
, "exit-link-params",
1881 "Exit from Link Params configuration node\n")
1883 if (vty
->node
== LINK_PARAMS_NODE
)
1884 vty
->node
= INTERFACE_NODE
;
1888 static int show_per_daemon(const char *line
, const char *headline
)
1891 int ret
= CMD_SUCCESS
;
1893 for (i
= 0; i
< array_size(vtysh_client
); i
++)
1894 if (vtysh_client
[i
].fd
>= 0) {
1895 fprintf(stdout
, headline
, vtysh_client
[i
].name
);
1896 ret
= vtysh_client_execute(&vtysh_client
[i
], line
,
1898 fprintf(stdout
, "\n");
1904 DEFUN (vtysh_show_debugging
,
1905 vtysh_show_debugging_cmd
,
1910 return show_per_daemon("do show debugging\n",
1914 DEFUN (vtysh_show_debugging_hashtable
,
1915 vtysh_show_debugging_hashtable_cmd
,
1916 "show debugging hashtable [statistics]",
1919 "Statistics about hash tables\n"
1920 "Statistics about hash tables\n")
1922 fprintf(stdout
, "\n");
1924 "Load factor (LF) - average number of elements across all buckets\n");
1926 "Full load factor (FLF) - average number of elements across full buckets\n\n");
1928 "Standard deviation (SD) is calculated for both the LF and FLF\n");
1930 "and indicates the typical deviation of bucket chain length\n");
1931 fprintf(stdout
, "from the value in the corresponding load factor.\n\n");
1933 return show_per_daemon("do show debugging hashtable\n",
1934 "Hashtable statistics for %s:\n");
1938 DEFUN (vtysh_show_memory
,
1939 vtysh_show_memory_cmd
,
1942 "Memory statistics\n")
1944 return show_per_daemon("show memory\n",
1945 "Memory statistics for %s:\n");
1948 DEFUN (vtysh_show_modules
,
1949 vtysh_show_modules_cmd
,
1954 return show_per_daemon("show modules\n",
1955 "Module information for %s:\n");
1958 /* Logging commands. */
1959 DEFUN (vtysh_show_logging
,
1960 vtysh_show_logging_cmd
,
1963 "Show current logging configuration\n")
1965 return show_per_daemon("do show logging\n",
1966 "Logging configuration for %s:\n");
1969 DEFUNSH(VTYSH_ALL
, vtysh_log_stdout
, vtysh_log_stdout_cmd
, "log stdout",
1971 "Set stdout logging level\n")
1976 DEFUNSH(VTYSH_ALL
, vtysh_log_stdout_level
, vtysh_log_stdout_level_cmd
,
1977 "log stdout <emergencies|alerts|critical|errors|warnings|notifications|informational|debugging>",
1979 "Set stdout logging level\n" LOG_LEVEL_DESC
)
1984 DEFUNSH(VTYSH_ALL
, no_vtysh_log_stdout
, no_vtysh_log_stdout_cmd
,
1985 "no log stdout [LEVEL]", NO_STR
1987 "Cancel logging to stdout\n"
1993 DEFUNSH(VTYSH_ALL
, vtysh_log_file
, vtysh_log_file_cmd
, "log file FILENAME",
1996 "Logging filename\n")
2001 DEFUNSH(VTYSH_ALL
, vtysh_log_file_level
, vtysh_log_file_level_cmd
,
2002 "log file FILENAME <emergencies|alerts|critical|errors|warnings|notifications|informational|debugging>",
2005 "Logging filename\n" LOG_LEVEL_DESC
)
2010 DEFUNSH(VTYSH_ALL
, no_vtysh_log_file
, no_vtysh_log_file_cmd
,
2011 "no log file [FILENAME [LEVEL]]", NO_STR
2013 "Cancel logging to file\n"
2014 "Logging file name\n"
2020 DEFUNSH(VTYSH_ALL
, vtysh_log_monitor
, vtysh_log_monitor_cmd
,
2021 "log monitor [<emergencies|alerts|critical|errors|warnings|notifications|informational|debugging>]",
2023 "Set terminal line (monitor) logging level\n" LOG_LEVEL_DESC
)
2028 DEFUNSH(VTYSH_ALL
, no_vtysh_log_monitor
, no_vtysh_log_monitor_cmd
,
2029 "no log monitor [LEVEL]", NO_STR
2031 "Disable terminal line (monitor) logging\n"
2037 DEFUNSH(VTYSH_ALL
, vtysh_log_syslog
, vtysh_log_syslog_cmd
,
2038 "log syslog [<emergencies|alerts|critical|errors|warnings|notifications|informational|debugging>]",
2040 "Set syslog logging level\n" LOG_LEVEL_DESC
)
2045 DEFUNSH(VTYSH_ALL
, no_vtysh_log_syslog
, no_vtysh_log_syslog_cmd
,
2046 "no log syslog [LEVEL]", NO_STR
2048 "Cancel logging to syslog\n"
2054 DEFUNSH(VTYSH_ALL
, vtysh_log_facility
, vtysh_log_facility_cmd
,
2055 "log facility <kern|user|mail|daemon|auth|syslog|lpr|news|uucp|cron|local0|local1|local2|local3|local4|local5|local6|local7>",
2057 "Facility parameter for syslog messages\n" LOG_FACILITY_DESC
)
2063 DEFUNSH(VTYSH_ALL
, no_vtysh_log_facility
, no_vtysh_log_facility_cmd
,
2064 "no log facility [FACILITY]", NO_STR
2066 "Reset syslog facility to default (daemon)\n"
2067 "Syslog facility\n")
2074 VTYSH_ALL
, vtysh_log_trap
, vtysh_log_trap_cmd
,
2075 "log trap <emergencies|alerts|critical|errors|warnings|notifications|informational|debugging>",
2077 "(Deprecated) Set logging level and default for all destinations\n" LOG_LEVEL_DESC
)
2083 DEFUNSH_DEPRECATED(VTYSH_ALL
, no_vtysh_log_trap
, no_vtysh_log_trap_cmd
,
2084 "no log trap [LEVEL]", NO_STR
2086 "Permit all logging information\n"
2092 DEFUNSH(VTYSH_ALL
, vtysh_log_record_priority
, vtysh_log_record_priority_cmd
,
2093 "log record-priority",
2095 "Log the priority of the message within the message\n")
2100 DEFUNSH(VTYSH_ALL
, no_vtysh_log_record_priority
,
2101 no_vtysh_log_record_priority_cmd
, "no log record-priority", NO_STR
2103 "Do not log the priority of the message within the message\n")
2108 DEFUNSH(VTYSH_ALL
, vtysh_log_timestamp_precision
,
2109 vtysh_log_timestamp_precision_cmd
, "log timestamp precision (0-6)",
2111 "Timestamp configuration\n"
2112 "Set the timestamp precision\n"
2113 "Number of subsecond digits\n")
2118 DEFUNSH(VTYSH_ALL
, no_vtysh_log_timestamp_precision
,
2119 no_vtysh_log_timestamp_precision_cmd
, "no log timestamp precision",
2122 "Timestamp configuration\n"
2123 "Reset the timestamp precision to the default value of 0\n")
2128 DEFUNSH(VTYSH_ALL
, vtysh_service_password_encrypt
,
2129 vtysh_service_password_encrypt_cmd
, "service password-encryption",
2130 "Set up miscellaneous service\n"
2131 "Enable encrypted passwords\n")
2136 DEFUNSH(VTYSH_ALL
, no_vtysh_service_password_encrypt
,
2137 no_vtysh_service_password_encrypt_cmd
, "no service password-encryption",
2139 "Set up miscellaneous service\n"
2140 "Enable encrypted passwords\n")
2145 DEFUNSH(VTYSH_ALL
, vtysh_config_password
, vtysh_password_cmd
,
2146 "password [(8-8)] LINE",
2147 "Assign the terminal connection password\n"
2148 "Specifies a HIDDEN password will follow\n"
2149 "The password string\n")
2154 DEFUNSH(VTYSH_ALL
, vtysh_config_enable_password
, vtysh_enable_password_cmd
,
2155 "enable password [(8-8)] LINE",
2156 "Modify enable password parameters\n"
2157 "Assign the privileged level password\n"
2158 "Specifies a HIDDEN password will follow\n"
2159 "The 'enable' password string\n")
2164 DEFUNSH(VTYSH_ALL
, no_vtysh_config_enable_password
,
2165 no_vtysh_enable_password_cmd
, "no enable password", NO_STR
2166 "Modify enable password parameters\n"
2167 "Assign the privileged level password\n")
2172 DEFUN (vtysh_write_terminal
,
2173 vtysh_write_terminal_cmd
,
2174 "write terminal [<zebra|ripd|ripngd|ospfd|ospf6d|ldpd|bgpd|isisd|pimd>]",
2175 "Write running configuration to memory, network, or terminal\n"
2176 "Write to terminal\n"
2177 "For the zebra daemon\n"
2178 "For the rip daemon\n"
2179 "For the ripng daemon\n"
2180 "For the ospf daemon\n"
2181 "For the ospfv6 daemon\n"
2182 "For the ldpd daemon\n"
2183 "For the bgp daemon\n"
2184 "For the isis daemon\n"
2185 "For the pim daemon\n")
2188 char line
[] = "do write terminal\n";
2191 if (vtysh_pager_name
) {
2192 fp
= popen(vtysh_pager_name
, "w");
2200 vty_out(vty
, "Building configuration...\n");
2201 vty_out(vty
, "\nCurrent configuration:\n");
2202 vty_out(vty
, "!\n");
2204 for (i
= 0; i
< array_size(vtysh_client
); i
++)
2206 || (strmatch(vtysh_client
[i
].name
, argv
[2]->text
)))
2207 vtysh_client_config(&vtysh_client
[i
], line
);
2209 /* Integrate vtysh specific configuration. */
2210 vtysh_config_write();
2212 vtysh_config_dump(fp
);
2214 if (vtysh_pager_name
&& fp
) {
2216 if (pclose(fp
) == -1) {
2223 vty_out(vty
, "end\n");
2227 DEFUN (vtysh_show_running_config
,
2228 vtysh_show_running_config_cmd
,
2229 "show running-config [<zebra|ripd|ripngd|ospfd|ospf6d|ldpd|bgpd|isisd|pimd>]",
2231 "Current operating configuration\n"
2232 "For the zebra daemon\n"
2233 "For the rip daemon\n"
2234 "For the ripng daemon\n"
2235 "For the ospf daemon\n"
2236 "For the ospfv6 daemon\n"
2237 "For the ldp daemon\n"
2238 "For the bgp daemon\n"
2239 "For the isis daemon\n"
2240 "For the pim daemon\n")
2242 return vtysh_write_terminal(self
, vty
, argc
, argv
);
2245 DEFUN (vtysh_integrated_config
,
2246 vtysh_integrated_config_cmd
,
2247 "service integrated-vtysh-config",
2248 "Set up miscellaneous service\n"
2249 "Write configuration into integrated file\n")
2251 vtysh_write_integrated
= WRITE_INTEGRATED_YES
;
2255 DEFUN (no_vtysh_integrated_config
,
2256 no_vtysh_integrated_config_cmd
,
2257 "no service integrated-vtysh-config",
2259 "Set up miscellaneous service\n"
2260 "Write configuration into integrated file\n")
2262 vtysh_write_integrated
= WRITE_INTEGRATED_NO
;
2266 static void backup_config_file(const char *fbackup
)
2268 char *integrate_sav
= NULL
;
2270 integrate_sav
= malloc(strlen(fbackup
) + strlen(CONF_BACKUP_EXT
) + 1);
2271 strcpy(integrate_sav
, fbackup
);
2272 strcat(integrate_sav
, CONF_BACKUP_EXT
);
2274 /* Move current configuration file to backup config file. */
2275 unlink(integrate_sav
);
2276 rename(fbackup
, integrate_sav
);
2277 free(integrate_sav
);
2280 int vtysh_write_config_integrated(void)
2283 char line
[] = "do write terminal\n";
2286 struct passwd
*pwentry
;
2287 struct group
*grentry
;
2293 fprintf(stdout
, "Building Configuration...\n");
2295 backup_config_file(frr_config
);
2296 fp
= fopen(frr_config
, "w");
2299 "%% Error: failed to open configuration file %s: %s\n",
2300 frr_config
, safe_strerror(errno
));
2301 return CMD_WARNING_CONFIG_FAILED
;
2305 for (i
= 0; i
< array_size(vtysh_client
); i
++)
2306 vtysh_client_config(&vtysh_client
[i
], line
);
2308 vtysh_config_write();
2309 vtysh_config_dump(fp
);
2311 if (fchmod(fd
, CONFIGFILE_MASK
) != 0) {
2312 printf("%% Warning: can't chmod configuration file %s: %s\n",
2313 frr_config
, safe_strerror(errno
));
2318 pwentry
= getpwnam(FRR_USER
);
2320 uid
= pwentry
->pw_uid
;
2322 printf("%% Warning: could not look up user \"%s\"\n", FRR_USER
);
2327 grentry
= getgrnam(FRR_GROUP
);
2329 gid
= grentry
->gr_gid
;
2331 printf("%% Warning: could not look up group \"%s\"\n",
2337 if (!fstat(fd
, &st
)) {
2338 if (st
.st_uid
== uid
)
2340 if (st
.st_gid
== gid
)
2342 if ((uid
!= (uid_t
)-1 || gid
!= (gid_t
)-1)
2343 && fchown(fd
, uid
, gid
)) {
2344 printf("%% Warning: can't chown configuration file %s: %s\n",
2345 frr_config
, safe_strerror(errno
));
2349 printf("%% Warning: stat() failed on %s: %s\n", frr_config
,
2350 safe_strerror(errno
));
2356 printf("Integrated configuration saved to %s\n", frr_config
);
2364 static bool want_config_integrated(void)
2368 switch (vtysh_write_integrated
) {
2369 case WRITE_INTEGRATED_UNSPECIFIED
:
2370 if (stat(frr_config
, &s
) && errno
== ENOENT
)
2373 case WRITE_INTEGRATED_NO
:
2375 case WRITE_INTEGRATED_YES
:
2381 DEFUN (vtysh_write_memory
,
2382 vtysh_write_memory_cmd
,
2383 "write [<memory|file>]",
2384 "Write running configuration to memory, network, or terminal\n"
2385 "Write configuration to the file (same as write file)\n"
2386 "Write configuration to the file (same as write memory)\n")
2388 int ret
= CMD_SUCCESS
;
2389 char line
[] = "do write memory\n";
2393 "Note: this version of vtysh never writes vtysh.conf\n");
2395 /* If integrated frr.conf explicitely set. */
2396 if (want_config_integrated()) {
2397 ret
= CMD_WARNING_CONFIG_FAILED
;
2398 for (i
= 0; i
< array_size(vtysh_client
); i
++)
2399 if (vtysh_client
[i
].flag
== VTYSH_WATCHFRR
)
2401 if (i
< array_size(vtysh_client
) && vtysh_client
[i
].fd
!= -1)
2402 ret
= vtysh_client_execute(&vtysh_client
[i
],
2403 "do write integrated",
2406 if (ret
!= CMD_SUCCESS
) {
2407 printf("\nWarning: attempting direct configuration write without "
2408 "watchfrr.\nFile permissions and ownership may be "
2409 "incorrect, or write may fail.\n\n");
2410 ret
= vtysh_write_config_integrated();
2415 fprintf(stdout
, "Building Configuration...\n");
2417 for (i
= 0; i
< array_size(vtysh_client
); i
++)
2418 ret
= vtysh_client_execute(&vtysh_client
[i
], line
, stdout
);
2423 DEFUN (vtysh_copy_running_config
,
2424 vtysh_copy_running_config_cmd
,
2425 "copy running-config startup-config",
2426 "Copy from one file to another\n"
2427 "Copy from current system configuration\n"
2428 "Copy to startup configuration\n")
2430 return vtysh_write_memory(self
, vty
, argc
, argv
);
2433 DEFUN (vtysh_terminal_length
,
2434 vtysh_terminal_length_cmd
,
2435 "terminal length (0-512)",
2436 "Set terminal line parameters\n"
2437 "Set number of lines on a screen\n"
2438 "Number of lines on screen (0 for no pausing)\n")
2442 char *endptr
= NULL
;
2443 char default_pager
[10];
2445 lines
= strtol(argv
[idx_number
]->arg
, &endptr
, 10);
2446 if (lines
< 0 || lines
> 512 || *endptr
!= '\0') {
2447 vty_out(vty
, "length is malformed\n");
2451 if (vtysh_pager_name
) {
2452 free(vtysh_pager_name
);
2453 vtysh_pager_name
= NULL
;
2457 snprintf(default_pager
, 10, "more -%i", lines
);
2458 vtysh_pager_name
= strdup(default_pager
);
2464 DEFUN (vtysh_terminal_no_length
,
2465 vtysh_terminal_no_length_cmd
,
2466 "terminal no length",
2467 "Set terminal line parameters\n"
2469 "Set number of lines on a screen\n")
2471 if (vtysh_pager_name
) {
2472 free(vtysh_pager_name
);
2473 vtysh_pager_name
= NULL
;
2480 DEFUN (vtysh_show_daemons
,
2481 vtysh_show_daemons_cmd
,
2484 "Show list of running daemons\n")
2488 for (i
= 0; i
< array_size(vtysh_client
); i
++)
2489 if (vtysh_client
[i
].fd
>= 0)
2490 vty_out(vty
, " %s", vtysh_client
[i
].name
);
2496 /* Execute command in child process. */
2497 static void execute_command(const char *command
, int argc
,
2498 const char *arg1
, const char *arg2
)
2507 /* Failure of fork(). */
2508 fprintf(stderr
, "Can't fork: %s\n", safe_strerror(errno
));
2510 } else if (pid
== 0) {
2511 /* This is child process. */
2514 execlp(command
, command
, (const char *)NULL
);
2517 execlp(command
, command
, arg1
, (const char *)NULL
);
2520 execlp(command
, command
, arg1
, arg2
,
2521 (const char *)NULL
);
2525 /* When execlp suceed, this part is not executed. */
2526 fprintf(stderr
, "Can't execute %s: %s\n", command
,
2527 safe_strerror(errno
));
2530 /* This is parent. */
2532 wait4(pid
, &status
, 0, NULL
);
2540 "Send echo messages\n"
2541 "Ping destination address or hostname\n")
2545 argv_find(argv
, argc
, "WORD", &idx
);
2546 execute_command("ping", 1, argv
[idx
]->arg
, NULL
);
2550 ALIAS(vtysh_ping
, vtysh_ping_ip_cmd
, "ping ip WORD",
2551 "Send echo messages\n"
2553 "Ping destination address or hostname\n")
2555 DEFUN (vtysh_traceroute
,
2556 vtysh_traceroute_cmd
,
2558 "Trace route to destination\n"
2559 "Trace route to destination address or hostname\n")
2563 argv_find(argv
, argc
, "WORD", &idx
);
2564 execute_command("traceroute", 1, argv
[idx
]->arg
, NULL
);
2568 ALIAS(vtysh_traceroute
, vtysh_traceroute_ip_cmd
, "traceroute ip WORD",
2569 "Trace route to destination\n"
2571 "Trace route to destination address or hostname\n")
2576 "Send echo messages\n"
2578 "Ping destination address or hostname\n")
2580 execute_command("ping6", 1, argv
[2]->arg
, NULL
);
2584 DEFUN (vtysh_traceroute6
,
2585 vtysh_traceroute6_cmd
,
2586 "traceroute ipv6 WORD",
2587 "Trace route to destination\n"
2589 "Trace route to destination address or hostname\n")
2591 execute_command("traceroute6", 1, argv
[2]->arg
, NULL
);
2595 #if defined(HAVE_SHELL_ACCESS)
2596 DEFUN (vtysh_telnet
,
2599 "Open a telnet connection\n"
2600 "IP address or hostname of a remote system\n")
2602 execute_command("telnet", 1, argv
[1]->arg
, NULL
);
2606 DEFUN (vtysh_telnet_port
,
2607 vtysh_telnet_port_cmd
,
2609 "Open a telnet connection\n"
2610 "IP address or hostname of a remote system\n"
2611 "TCP Port number\n")
2613 execute_command("telnet", 2, argv
[1]->arg
, argv
[2]->arg
);
2620 "Open an ssh connection\n"
2623 execute_command("ssh", 1, argv
[1]->arg
, NULL
);
2627 DEFUN (vtysh_start_shell
,
2628 vtysh_start_shell_cmd
,
2630 "Start UNIX shell\n")
2632 execute_command("sh", 0, NULL
, NULL
);
2636 DEFUN (vtysh_start_bash
,
2637 vtysh_start_bash_cmd
,
2639 "Start UNIX shell\n"
2642 execute_command("bash", 0, NULL
, NULL
);
2646 DEFUN (vtysh_start_zsh
,
2647 vtysh_start_zsh_cmd
,
2649 "Start UNIX shell\n"
2652 execute_command("zsh", 0, NULL
, NULL
);
2659 "list [permutations]",
2660 "Print command list\n"
2661 "Print all possible command permutations\n")
2663 return cmd_list_cmds(vty
, argc
== 2);
2669 "Find CLI command containing text\n"
2670 "Text to search for\n")
2672 char *text
= argv_concat(argv
, argc
, 1);
2673 const struct cmd_node
*node
;
2674 const struct cmd_element
*cli
;
2677 for (unsigned int i
= 0; i
< vector_active(cmdvec
); i
++) {
2678 node
= vector_slot(cmdvec
, i
);
2681 clis
= node
->cmd_vector
;
2682 for (unsigned int j
= 0; j
< vector_active(clis
); j
++) {
2683 cli
= vector_slot(clis
, j
);
2684 if (strcasestr(cli
->string
, text
))
2685 fprintf(stdout
, " (%s) %s\n",
2686 node_names
[node
->node
], cli
->string
);
2690 XFREE(MTYPE_TMP
, text
);
2695 static void vtysh_install_default(enum node_type node
)
2697 install_element(node
, &config_list_cmd
);
2698 install_element(node
, &find_cmd
);
2701 /* Making connection to protocol daemon. */
2702 static int vtysh_connect(struct vtysh_client
*vclient
)
2706 struct sockaddr_un addr
;
2710 if (!vclient
->path
[0])
2711 snprintf(vclient
->path
, sizeof(vclient
->path
), "%s/%s.vty",
2712 vtydir
, vclient
->name
);
2713 path
= vclient
->path
;
2715 /* Stat socket to see if we have permission to access it. */
2716 ret
= stat(path
, &s_stat
);
2717 if (ret
< 0 && errno
!= ENOENT
) {
2718 fprintf(stderr
, "vtysh_connect(%s): stat = %s\n", path
,
2719 safe_strerror(errno
));
2724 if (!S_ISSOCK(s_stat
.st_mode
)) {
2725 fprintf(stderr
, "vtysh_connect(%s): Not a socket\n",
2731 sock
= socket(AF_UNIX
, SOCK_STREAM
, 0);
2734 fprintf(stderr
, "vtysh_connect(%s): socket = %s\n", path
,
2735 safe_strerror(errno
));
2740 memset(&addr
, 0, sizeof(struct sockaddr_un
));
2741 addr
.sun_family
= AF_UNIX
;
2742 strlcpy(addr
.sun_path
, path
, sizeof(addr
.sun_path
));
2743 #ifdef HAVE_STRUCT_SOCKADDR_UN_SUN_LEN
2744 len
= addr
.sun_len
= SUN_LEN(&addr
);
2746 len
= sizeof(addr
.sun_family
) + strlen(addr
.sun_path
);
2747 #endif /* HAVE_STRUCT_SOCKADDR_UN_SUN_LEN */
2749 ret
= connect(sock
, (struct sockaddr
*)&addr
, len
);
2752 fprintf(stderr
, "vtysh_connect(%s): connect = %s\n", path
,
2753 safe_strerror(errno
));
2763 /* Return true if str ends with suffix, else return false */
2764 static int ends_with(const char *str
, const char *suffix
)
2766 if (!str
|| !suffix
)
2768 size_t lenstr
= strlen(str
);
2769 size_t lensuffix
= strlen(suffix
);
2770 if (lensuffix
> lenstr
)
2772 return strncmp(str
+ lenstr
- lensuffix
, suffix
, lensuffix
) == 0;
2775 static void vtysh_client_sorted_insert(struct vtysh_client
*head_client
,
2776 struct vtysh_client
*client
)
2778 struct vtysh_client
*prev_node
, *current_node
;
2780 prev_node
= head_client
;
2781 current_node
= head_client
->next
;
2782 while (current_node
) {
2783 if (strcmp(current_node
->path
, client
->path
) > 0)
2786 prev_node
= current_node
;
2787 current_node
= current_node
->next
;
2789 client
->next
= current_node
;
2790 prev_node
->next
= client
;
2793 #define MAXIMUM_INSTANCES 10
2795 static void vtysh_update_all_insances(struct vtysh_client
*head_client
)
2797 struct vtysh_client
*client
;
2799 struct dirent
*file
;
2802 if (head_client
->flag
!= VTYSH_OSPFD
)
2805 /* ls vty_sock_dir and look for all files ending in .vty */
2806 dir
= opendir(vtydir
);
2808 while ((file
= readdir(dir
)) != NULL
) {
2809 if (begins_with(file
->d_name
, "ospfd-")
2810 && ends_with(file
->d_name
, ".vty")) {
2811 if (n
== MAXIMUM_INSTANCES
) {
2813 "Parsing %s, client limit(%d) reached!\n",
2817 client
= (struct vtysh_client
*)malloc(
2818 sizeof(struct vtysh_client
));
2820 client
->name
= "ospfd";
2821 client
->flag
= VTYSH_OSPFD
;
2822 snprintf(client
->path
, sizeof(client
->path
),
2823 "%s/%s", vtydir
, file
->d_name
);
2824 client
->next
= NULL
;
2825 vtysh_client_sorted_insert(head_client
, client
);
2833 static int vtysh_connect_all_instances(struct vtysh_client
*head_client
)
2835 struct vtysh_client
*client
;
2838 vtysh_update_all_insances(head_client
);
2840 client
= head_client
->next
;
2842 if (vtysh_connect(client
) == 0)
2844 client
= client
->next
;
2850 int vtysh_connect_all(const char *daemon_name
)
2856 for (i
= 0; i
< array_size(vtysh_client
); i
++) {
2858 || !strcmp(daemon_name
, vtysh_client
[i
].name
)) {
2860 if (vtysh_connect(&vtysh_client
[i
]) == 0)
2863 rc
+= vtysh_connect_all_instances(&vtysh_client
[i
]);
2867 fprintf(stderr
, "Error: no daemons match name %s!\n",
2872 /* To disable readline's filename completion. */
2873 static char *vtysh_completion_entry_function(const char *ignore
,
2879 void vtysh_readline_init(void)
2881 /* readline related settings. */
2883 rl_bind_key('?', (rl_command_func_t
*)vtysh_rl_describe
);
2884 rl_completion_entry_function
= vtysh_completion_entry_function
;
2885 rl_attempted_completion_function
=
2886 (rl_completion_func_t
*)new_completion
;
2889 char *vtysh_prompt(void)
2891 static char buf
[100];
2893 snprintf(buf
, sizeof buf
, cmd_prompt(vty
->node
), cmd_hostname_get());
2897 static void vtysh_ac_line(void *arg
, const char *line
)
2901 for (i
= 0; i
< vector_active(comps
); i
++)
2902 if (!strcmp(line
, (char *)vector_slot(comps
, i
)))
2904 vector_set(comps
, XSTRDUP(MTYPE_COMPLETION
, line
));
2907 static void vtysh_autocomplete(vector comps
, struct cmd_token
*token
)
2912 snprintf(accmd
, sizeof(accmd
), "autocomplete %d %s %s", token
->type
,
2913 token
->text
, token
->varname
? token
->varname
: "-");
2915 for (i
= 0; i
< array_size(vtysh_client
); i
++)
2916 vtysh_client_run_all(&vtysh_client
[i
], accmd
, 1, NULL
,
2917 vtysh_ac_line
, comps
);
2920 static const struct cmd_variable_handler vtysh_var_handler
[] = {
2924 .completions
= vtysh_autocomplete
},
2925 {.completions
= NULL
}};
2927 void vtysh_init_vty(void)
2929 /* Make vty structure. */
2931 vty
->type
= VTY_SHELL
;
2932 vty
->node
= VIEW_NODE
;
2934 /* Initialize commands. */
2936 cmd_variable_handler_register(vtysh_var_handler
);
2938 /* Install nodes. */
2939 install_node(&bgp_node
, NULL
);
2940 install_node(&rip_node
, NULL
);
2941 install_node(&interface_node
, NULL
);
2942 install_node(&pw_node
, NULL
);
2943 install_node(&link_params_node
, NULL
);
2944 install_node(&ns_node
, NULL
);
2945 install_node(&vrf_node
, NULL
);
2946 install_node(&rmap_node
, NULL
);
2947 install_node(&zebra_node
, NULL
);
2948 install_node(&bgp_vpnv4_node
, NULL
);
2949 install_node(&bgp_vpnv6_node
, NULL
);
2950 install_node(&bgp_ipv4_node
, NULL
);
2951 install_node(&bgp_ipv4m_node
, NULL
);
2952 install_node(&bgp_ipv4l_node
, NULL
);
2953 install_node(&bgp_ipv6_node
, NULL
);
2954 install_node(&bgp_ipv6m_node
, NULL
);
2955 install_node(&bgp_ipv6l_node
, NULL
);
2956 install_node(&bgp_vrf_policy_node
, NULL
);
2957 install_node(&bgp_evpn_node
, NULL
);
2958 install_node(&bgp_evpn_vni_node
, NULL
);
2959 install_node(&bgp_vnc_defaults_node
, NULL
);
2960 install_node(&bgp_vnc_nve_group_node
, NULL
);
2961 install_node(&bgp_vnc_l2_group_node
, NULL
);
2962 install_node(&ospf_node
, NULL
);
2963 install_node(&eigrp_node
, NULL
);
2964 install_node(&babel_node
, NULL
);
2965 install_node(&ripng_node
, NULL
);
2966 install_node(&ospf6_node
, NULL
);
2967 install_node(&ldp_node
, NULL
);
2968 install_node(&ldp_ipv4_node
, NULL
);
2969 install_node(&ldp_ipv6_node
, NULL
);
2970 install_node(&ldp_ipv4_iface_node
, NULL
);
2971 install_node(&ldp_ipv6_iface_node
, NULL
);
2972 install_node(&ldp_l2vpn_node
, NULL
);
2973 install_node(&ldp_pseudowire_node
, NULL
);
2974 install_node(&keychain_node
, NULL
);
2975 install_node(&keychain_key_node
, NULL
);
2976 install_node(&isis_node
, NULL
);
2977 install_node(&vty_node
, NULL
);
2979 struct cmd_node
*node
;
2980 for (unsigned int i
= 0; i
< vector_active(cmdvec
); i
++) {
2981 node
= vector_slot(cmdvec
, i
);
2982 if (!node
|| node
->node
== VIEW_NODE
)
2984 vtysh_install_default(node
->node
);
2987 install_element(VIEW_NODE
, &vtysh_enable_cmd
);
2988 install_element(ENABLE_NODE
, &vtysh_config_terminal_cmd
);
2989 install_element(ENABLE_NODE
, &vtysh_disable_cmd
);
2991 /* "exit" command. */
2992 install_element(VIEW_NODE
, &vtysh_exit_all_cmd
);
2993 install_element(CONFIG_NODE
, &vtysh_exit_all_cmd
);
2994 install_element(VIEW_NODE
, &vtysh_quit_all_cmd
);
2995 install_element(CONFIG_NODE
, &vtysh_quit_all_cmd
);
2996 install_element(RIP_NODE
, &vtysh_exit_ripd_cmd
);
2997 install_element(RIP_NODE
, &vtysh_quit_ripd_cmd
);
2998 install_element(RIPNG_NODE
, &vtysh_exit_ripngd_cmd
);
2999 install_element(RIPNG_NODE
, &vtysh_quit_ripngd_cmd
);
3000 install_element(OSPF_NODE
, &vtysh_exit_ospfd_cmd
);
3001 install_element(OSPF_NODE
, &vtysh_quit_ospfd_cmd
);
3002 install_element(EIGRP_NODE
, &vtysh_exit_eigrpd_cmd
);
3003 install_element(EIGRP_NODE
, &vtysh_quit_eigrpd_cmd
);
3004 install_element(BABEL_NODE
, &vtysh_exit_babeld_cmd
);
3005 install_element(BABEL_NODE
, &vtysh_quit_babeld_cmd
);
3006 install_element(OSPF6_NODE
, &vtysh_exit_ospf6d_cmd
);
3007 install_element(OSPF6_NODE
, &vtysh_quit_ospf6d_cmd
);
3008 #if defined(HAVE_LDPD)
3009 install_element(LDP_NODE
, &vtysh_exit_ldpd_cmd
);
3010 install_element(LDP_NODE
, &vtysh_quit_ldpd_cmd
);
3011 install_element(LDP_IPV4_NODE
, &vtysh_exit_ldpd_cmd
);
3012 install_element(LDP_IPV4_NODE
, &vtysh_quit_ldpd_cmd
);
3013 install_element(LDP_IPV4_NODE
, &ldp_exit_address_family_cmd
);
3014 install_element(LDP_IPV6_NODE
, &vtysh_exit_ldpd_cmd
);
3015 install_element(LDP_IPV6_NODE
, &vtysh_quit_ldpd_cmd
);
3016 install_element(LDP_IPV6_NODE
, &ldp_exit_address_family_cmd
);
3017 install_element(LDP_IPV4_IFACE_NODE
, &vtysh_exit_ldpd_cmd
);
3018 install_element(LDP_IPV4_IFACE_NODE
, &vtysh_quit_ldpd_cmd
);
3019 install_element(LDP_IPV6_IFACE_NODE
, &vtysh_exit_ldpd_cmd
);
3020 install_element(LDP_IPV6_IFACE_NODE
, &vtysh_quit_ldpd_cmd
);
3021 install_element(LDP_L2VPN_NODE
, &vtysh_exit_ldpd_cmd
);
3022 install_element(LDP_L2VPN_NODE
, &vtysh_quit_ldpd_cmd
);
3023 install_element(LDP_PSEUDOWIRE_NODE
, &vtysh_exit_ldpd_cmd
);
3024 install_element(LDP_PSEUDOWIRE_NODE
, &vtysh_quit_ldpd_cmd
);
3026 install_element(BGP_NODE
, &vtysh_exit_bgpd_cmd
);
3027 install_element(BGP_NODE
, &vtysh_quit_bgpd_cmd
);
3028 install_element(BGP_VPNV4_NODE
, &vtysh_exit_bgpd_cmd
);
3029 install_element(BGP_VPNV4_NODE
, &vtysh_quit_bgpd_cmd
);
3030 install_element(BGP_VPNV6_NODE
, &vtysh_exit_bgpd_cmd
);
3031 install_element(BGP_VPNV6_NODE
, &vtysh_quit_bgpd_cmd
);
3032 install_element(BGP_IPV4_NODE
, &vtysh_exit_bgpd_cmd
);
3033 install_element(BGP_IPV4_NODE
, &vtysh_quit_bgpd_cmd
);
3034 install_element(BGP_IPV4M_NODE
, &vtysh_exit_bgpd_cmd
);
3035 install_element(BGP_IPV4M_NODE
, &vtysh_quit_bgpd_cmd
);
3036 install_element(BGP_IPV4L_NODE
, &vtysh_exit_bgpd_cmd
);
3037 install_element(BGP_IPV4L_NODE
, &vtysh_quit_bgpd_cmd
);
3038 install_element(BGP_IPV6_NODE
, &vtysh_exit_bgpd_cmd
);
3039 install_element(BGP_IPV6_NODE
, &vtysh_quit_bgpd_cmd
);
3040 install_element(BGP_IPV6M_NODE
, &vtysh_exit_bgpd_cmd
);
3041 install_element(BGP_IPV6M_NODE
, &vtysh_quit_bgpd_cmd
);
3042 install_element(BGP_EVPN_NODE
, &vtysh_quit_bgpd_cmd
);
3043 install_element(BGP_EVPN_NODE
, &vtysh_exit_bgpd_cmd
);
3044 install_element(BGP_EVPN_VNI_NODE
, &vtysh_exit_bgpd_cmd
);
3045 install_element(BGP_EVPN_VNI_NODE
, &vtysh_quit_bgpd_cmd
);
3046 install_element(BGP_IPV6L_NODE
, &vtysh_exit_bgpd_cmd
);
3047 install_element(BGP_IPV6L_NODE
, &vtysh_quit_bgpd_cmd
);
3048 #if defined(ENABLE_BGP_VNC)
3049 install_element(BGP_VRF_POLICY_NODE
, &vtysh_exit_bgpd_cmd
);
3050 install_element(BGP_VRF_POLICY_NODE
, &vtysh_quit_bgpd_cmd
);
3051 install_element(BGP_VNC_DEFAULTS_NODE
, &vtysh_exit_bgpd_cmd
);
3052 install_element(BGP_VNC_DEFAULTS_NODE
, &vtysh_quit_bgpd_cmd
);
3053 install_element(BGP_VNC_NVE_GROUP_NODE
, &vtysh_exit_bgpd_cmd
);
3054 install_element(BGP_VNC_NVE_GROUP_NODE
, &vtysh_quit_bgpd_cmd
);
3055 install_element(BGP_VNC_L2_GROUP_NODE
, &vtysh_exit_bgpd_cmd
);
3056 install_element(BGP_VNC_L2_GROUP_NODE
, &vtysh_quit_bgpd_cmd
);
3058 install_element(ISIS_NODE
, &vtysh_exit_isisd_cmd
);
3059 install_element(ISIS_NODE
, &vtysh_quit_isisd_cmd
);
3060 install_element(KEYCHAIN_NODE
, &vtysh_exit_ripd_cmd
);
3061 install_element(KEYCHAIN_NODE
, &vtysh_quit_ripd_cmd
);
3062 install_element(KEYCHAIN_KEY_NODE
, &vtysh_exit_ripd_cmd
);
3063 install_element(KEYCHAIN_KEY_NODE
, &vtysh_quit_ripd_cmd
);
3064 install_element(RMAP_NODE
, &vtysh_exit_rmap_cmd
);
3065 install_element(RMAP_NODE
, &vtysh_quit_rmap_cmd
);
3066 install_element(VTY_NODE
, &vtysh_exit_line_vty_cmd
);
3067 install_element(VTY_NODE
, &vtysh_quit_line_vty_cmd
);
3069 /* "end" command. */
3070 install_element(CONFIG_NODE
, &vtysh_end_all_cmd
);
3071 install_element(ENABLE_NODE
, &vtysh_end_all_cmd
);
3072 install_element(RIP_NODE
, &vtysh_end_all_cmd
);
3073 install_element(RIPNG_NODE
, &vtysh_end_all_cmd
);
3074 install_element(OSPF_NODE
, &vtysh_end_all_cmd
);
3075 install_element(EIGRP_NODE
, &vtysh_end_all_cmd
);
3076 install_element(BABEL_NODE
, &vtysh_end_all_cmd
);
3077 install_element(OSPF6_NODE
, &vtysh_end_all_cmd
);
3078 install_element(LDP_NODE
, &vtysh_end_all_cmd
);
3079 install_element(LDP_IPV4_NODE
, &vtysh_end_all_cmd
);
3080 install_element(LDP_IPV6_NODE
, &vtysh_end_all_cmd
);
3081 install_element(LDP_IPV4_IFACE_NODE
, &vtysh_end_all_cmd
);
3082 install_element(LDP_IPV6_IFACE_NODE
, &vtysh_end_all_cmd
);
3083 install_element(LDP_L2VPN_NODE
, &vtysh_end_all_cmd
);
3084 install_element(LDP_PSEUDOWIRE_NODE
, &vtysh_end_all_cmd
);
3085 install_element(BGP_NODE
, &vtysh_end_all_cmd
);
3086 install_element(BGP_IPV4_NODE
, &vtysh_end_all_cmd
);
3087 install_element(BGP_IPV4M_NODE
, &vtysh_end_all_cmd
);
3088 install_element(BGP_IPV4L_NODE
, &vtysh_end_all_cmd
);
3089 install_element(BGP_VPNV4_NODE
, &vtysh_end_all_cmd
);
3090 install_element(BGP_VPNV6_NODE
, &vtysh_end_all_cmd
);
3091 install_element(BGP_IPV6_NODE
, &vtysh_end_all_cmd
);
3092 install_element(BGP_IPV6M_NODE
, &vtysh_end_all_cmd
);
3093 install_element(BGP_IPV6L_NODE
, &vtysh_end_all_cmd
);
3094 install_element(BGP_VRF_POLICY_NODE
, &vtysh_end_all_cmd
);
3095 install_element(BGP_EVPN_NODE
, &vtysh_end_all_cmd
);
3096 install_element(BGP_EVPN_VNI_NODE
, &vtysh_end_all_cmd
);
3097 install_element(BGP_VNC_DEFAULTS_NODE
, &vtysh_end_all_cmd
);
3098 install_element(BGP_VNC_NVE_GROUP_NODE
, &vtysh_end_all_cmd
);
3099 install_element(BGP_VNC_L2_GROUP_NODE
, &vtysh_end_all_cmd
);
3100 install_element(ISIS_NODE
, &vtysh_end_all_cmd
);
3101 install_element(KEYCHAIN_NODE
, &vtysh_end_all_cmd
);
3102 install_element(KEYCHAIN_KEY_NODE
, &vtysh_end_all_cmd
);
3103 install_element(RMAP_NODE
, &vtysh_end_all_cmd
);
3104 install_element(VTY_NODE
, &vtysh_end_all_cmd
);
3106 install_element(INTERFACE_NODE
, &vtysh_interface_desc_cmd
);
3107 install_element(INTERFACE_NODE
, &vtysh_no_interface_desc_cmd
);
3108 install_element(INTERFACE_NODE
, &vtysh_end_all_cmd
);
3109 install_element(INTERFACE_NODE
, &vtysh_exit_interface_cmd
);
3110 install_element(LINK_PARAMS_NODE
, &exit_link_params_cmd
);
3111 install_element(LINK_PARAMS_NODE
, &vtysh_end_all_cmd
);
3112 install_element(LINK_PARAMS_NODE
, &vtysh_exit_interface_cmd
);
3113 install_element(INTERFACE_NODE
, &vtysh_quit_interface_cmd
);
3115 install_element(PW_NODE
, &vtysh_end_all_cmd
);
3116 install_element(PW_NODE
, &vtysh_exit_interface_cmd
);
3117 install_element(PW_NODE
, &vtysh_quit_interface_cmd
);
3119 install_element(NS_NODE
, &vtysh_end_all_cmd
);
3121 install_element(CONFIG_NODE
, &vtysh_ns_cmd
);
3122 install_element(NS_NODE
, &vtysh_exit_ns_cmd
);
3123 install_element(NS_NODE
, &vtysh_quit_ns_cmd
);
3125 install_element(VRF_NODE
, &vtysh_end_all_cmd
);
3126 install_element(VRF_NODE
, &vtysh_exit_vrf_cmd
);
3127 install_element(VRF_NODE
, &vtysh_quit_vrf_cmd
);
3129 install_element(CONFIG_NODE
, &router_eigrp_cmd
);
3130 install_element(CONFIG_NODE
, &router_babel_cmd
);
3131 install_element(CONFIG_NODE
, &router_rip_cmd
);
3132 install_element(CONFIG_NODE
, &router_ripng_cmd
);
3133 install_element(CONFIG_NODE
, &router_ospf_cmd
);
3134 install_element(CONFIG_NODE
, &router_ospf6_cmd
);
3135 #if defined(HAVE_LDPD)
3136 install_element(CONFIG_NODE
, &ldp_mpls_ldp_cmd
);
3137 install_element(LDP_NODE
, &ldp_address_family_ipv4_cmd
);
3138 install_element(LDP_NODE
, &ldp_address_family_ipv6_cmd
);
3139 install_element(LDP_IPV4_NODE
, &ldp_interface_ifname_cmd
);
3140 install_element(LDP_IPV6_NODE
, &ldp_interface_ifname_cmd
);
3141 install_element(CONFIG_NODE
, &ldp_l2vpn_word_type_vpls_cmd
);
3142 install_element(LDP_L2VPN_NODE
, &ldp_member_pseudowire_ifname_cmd
);
3144 install_element(CONFIG_NODE
, &router_isis_cmd
);
3145 install_element(CONFIG_NODE
, &router_bgp_cmd
);
3146 install_element(BGP_NODE
, &address_family_vpnv4_cmd
);
3147 install_element(BGP_NODE
, &address_family_vpnv6_cmd
);
3148 #if defined(ENABLE_BGP_VNC)
3149 install_element(BGP_NODE
, &vnc_vrf_policy_cmd
);
3150 install_element(BGP_NODE
, &vnc_defaults_cmd
);
3151 install_element(BGP_NODE
, &vnc_nve_group_cmd
);
3152 install_element(BGP_NODE
, &vnc_l2_group_cmd
);
3154 install_element(BGP_NODE
, &address_family_ipv4_cmd
);
3155 install_element(BGP_NODE
, &address_family_ipv4_multicast_cmd
);
3156 install_element(BGP_NODE
, &address_family_ipv4_vpn_cmd
);
3157 install_element(BGP_NODE
, &address_family_ipv4_labeled_unicast_cmd
);
3158 install_element(BGP_NODE
, &address_family_ipv6_cmd
);
3159 install_element(BGP_NODE
, &address_family_ipv6_multicast_cmd
);
3160 install_element(BGP_NODE
, &address_family_ipv6_vpn_cmd
);
3161 install_element(BGP_NODE
, &address_family_ipv6_labeled_unicast_cmd
);
3162 install_element(BGP_NODE
, &address_family_evpn_cmd
);
3163 #if defined(HAVE_CUMULUS)
3164 install_element(BGP_NODE
, &address_family_evpn2_cmd
);
3166 install_element(BGP_VPNV4_NODE
, &exit_address_family_cmd
);
3167 install_element(BGP_VPNV6_NODE
, &exit_address_family_cmd
);
3168 install_element(BGP_IPV4_NODE
, &exit_address_family_cmd
);
3169 install_element(BGP_IPV4M_NODE
, &exit_address_family_cmd
);
3170 install_element(BGP_IPV4L_NODE
, &exit_address_family_cmd
);
3171 install_element(BGP_IPV6_NODE
, &exit_address_family_cmd
);
3172 install_element(BGP_IPV6M_NODE
, &exit_address_family_cmd
);
3173 install_element(BGP_EVPN_NODE
, &exit_address_family_cmd
);
3174 install_element(BGP_IPV6L_NODE
, &exit_address_family_cmd
);
3177 install_element(BGP_EVPN_NODE
, &bgp_evpn_vni_cmd
);
3178 install_element(BGP_EVPN_VNI_NODE
, &exit_vni_cmd
);
3180 install_element(BGP_VRF_POLICY_NODE
, &exit_vrf_policy_cmd
);
3181 install_element(BGP_VNC_DEFAULTS_NODE
, &exit_vnc_config_cmd
);
3182 install_element(BGP_VNC_NVE_GROUP_NODE
, &exit_vnc_config_cmd
);
3183 install_element(BGP_VNC_L2_GROUP_NODE
, &exit_vnc_config_cmd
);
3185 install_element(CONFIG_NODE
, &key_chain_cmd
);
3186 install_element(CONFIG_NODE
, &vtysh_route_map_cmd
);
3187 install_element(CONFIG_NODE
, &vtysh_line_vty_cmd
);
3188 install_element(KEYCHAIN_NODE
, &key_cmd
);
3189 install_element(KEYCHAIN_NODE
, &key_chain_cmd
);
3190 install_element(KEYCHAIN_KEY_NODE
, &key_chain_cmd
);
3191 install_element(CONFIG_NODE
, &vtysh_interface_cmd
);
3192 install_element(CONFIG_NODE
, &vtysh_no_interface_cmd
);
3193 install_element(CONFIG_NODE
, &vtysh_no_interface_vrf_cmd
);
3194 install_element(CONFIG_NODE
, &vtysh_pseudowire_cmd
);
3195 install_element(INTERFACE_NODE
, &vtysh_link_params_cmd
);
3196 install_element(ENABLE_NODE
, &vtysh_show_running_config_cmd
);
3197 install_element(ENABLE_NODE
, &vtysh_copy_running_config_cmd
);
3199 install_element(CONFIG_NODE
, &vtysh_vrf_cmd
);
3200 install_element(CONFIG_NODE
, &vtysh_no_vrf_cmd
);
3202 /* "write terminal" command. */
3203 install_element(ENABLE_NODE
, &vtysh_write_terminal_cmd
);
3205 install_element(CONFIG_NODE
, &vtysh_integrated_config_cmd
);
3206 install_element(CONFIG_NODE
, &no_vtysh_integrated_config_cmd
);
3208 /* "write memory" command. */
3209 install_element(ENABLE_NODE
, &vtysh_write_memory_cmd
);
3211 install_element(VIEW_NODE
, &vtysh_terminal_length_cmd
);
3212 install_element(VIEW_NODE
, &vtysh_terminal_no_length_cmd
);
3213 install_element(VIEW_NODE
, &vtysh_show_daemons_cmd
);
3215 install_element(VIEW_NODE
, &vtysh_ping_cmd
);
3216 install_element(VIEW_NODE
, &vtysh_ping_ip_cmd
);
3217 install_element(VIEW_NODE
, &vtysh_traceroute_cmd
);
3218 install_element(VIEW_NODE
, &vtysh_traceroute_ip_cmd
);
3219 install_element(VIEW_NODE
, &vtysh_ping6_cmd
);
3220 install_element(VIEW_NODE
, &vtysh_traceroute6_cmd
);
3221 #if defined(HAVE_SHELL_ACCESS)
3222 install_element(VIEW_NODE
, &vtysh_telnet_cmd
);
3223 install_element(VIEW_NODE
, &vtysh_telnet_port_cmd
);
3224 install_element(VIEW_NODE
, &vtysh_ssh_cmd
);
3226 #if defined(HAVE_SHELL_ACCESS)
3227 install_element(ENABLE_NODE
, &vtysh_start_shell_cmd
);
3228 install_element(ENABLE_NODE
, &vtysh_start_bash_cmd
);
3229 install_element(ENABLE_NODE
, &vtysh_start_zsh_cmd
);
3232 install_element(VIEW_NODE
, &vtysh_show_debugging_cmd
);
3233 install_element(VIEW_NODE
, &vtysh_show_debugging_hashtable_cmd
);
3234 install_element(VIEW_NODE
, &vtysh_show_memory_cmd
);
3235 install_element(VIEW_NODE
, &vtysh_show_modules_cmd
);
3237 install_element(VIEW_NODE
, &vtysh_show_work_queues_cmd
);
3238 install_element(VIEW_NODE
, &vtysh_show_work_queues_daemon_cmd
);
3240 install_element(VIEW_NODE
, &vtysh_show_thread_cmd
);
3243 install_element(VIEW_NODE
, &vtysh_show_logging_cmd
);
3244 install_element(CONFIG_NODE
, &vtysh_log_stdout_cmd
);
3245 install_element(CONFIG_NODE
, &vtysh_log_stdout_level_cmd
);
3246 install_element(CONFIG_NODE
, &no_vtysh_log_stdout_cmd
);
3247 install_element(CONFIG_NODE
, &vtysh_log_file_cmd
);
3248 install_element(CONFIG_NODE
, &vtysh_log_file_level_cmd
);
3249 install_element(CONFIG_NODE
, &no_vtysh_log_file_cmd
);
3250 install_element(CONFIG_NODE
, &vtysh_log_monitor_cmd
);
3251 install_element(CONFIG_NODE
, &no_vtysh_log_monitor_cmd
);
3252 install_element(CONFIG_NODE
, &vtysh_log_syslog_cmd
);
3253 install_element(CONFIG_NODE
, &no_vtysh_log_syslog_cmd
);
3254 install_element(CONFIG_NODE
, &vtysh_log_trap_cmd
);
3255 install_element(CONFIG_NODE
, &no_vtysh_log_trap_cmd
);
3256 install_element(CONFIG_NODE
, &vtysh_log_facility_cmd
);
3257 install_element(CONFIG_NODE
, &no_vtysh_log_facility_cmd
);
3258 install_element(CONFIG_NODE
, &vtysh_log_record_priority_cmd
);
3259 install_element(CONFIG_NODE
, &no_vtysh_log_record_priority_cmd
);
3260 install_element(CONFIG_NODE
, &vtysh_log_timestamp_precision_cmd
);
3261 install_element(CONFIG_NODE
, &no_vtysh_log_timestamp_precision_cmd
);
3263 install_element(CONFIG_NODE
, &vtysh_service_password_encrypt_cmd
);
3264 install_element(CONFIG_NODE
, &no_vtysh_service_password_encrypt_cmd
);
3266 install_element(CONFIG_NODE
, &vtysh_password_cmd
);
3267 install_element(CONFIG_NODE
, &vtysh_enable_password_cmd
);
3268 install_element(CONFIG_NODE
, &no_vtysh_enable_password_cmd
);