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
) {
230 if (rc
!= CMD_SUCCESS
) {
231 if (!continue_on_err
)
236 if (wrong_instance
&& !correct_instance
&& fp
) {
238 "%% [%s]: command ignored as it targets an instance that is not running\n",
240 rc_all
= CMD_WARNING_CONFIG_FAILED
;
245 static int vtysh_client_execute(struct vtysh_client
*head_client
,
246 const char *line
, FILE *fp
)
248 return vtysh_client_run_all(head_client
, line
, 0, fp
, NULL
, NULL
);
251 static void vtysh_client_config(struct vtysh_client
*head_client
, char *line
)
253 /* watchfrr currently doesn't load any config, and has some hardcoded
254 * settings that show up in "show run". skip it here (for now at
255 * least) so we don't get that mangled up in config-write.
257 if (head_client
->flag
== VTYSH_WATCHFRR
)
260 vtysh_client_run_all(head_client
, line
, 1, NULL
,
261 vtysh_config_parse_line
, NULL
);
264 void vtysh_pager_init(void)
268 pager_defined
= getenv("VTYSH_PAGER");
271 vtysh_pager_name
= strdup(pager_defined
);
273 vtysh_pager_name
= strdup(VTYSH_PAGER
);
276 /* Command execution over the vty interface. */
277 static int vtysh_execute_func(const char *line
, int pager
)
282 const struct cmd_element
*cmd
;
286 int saved_ret
, saved_node
;
288 /* Split readline string up into the vector. */
289 vline
= cmd_make_strvec(line
);
294 saved_ret
= ret
= cmd_execute_command(vline
, vty
, &cmd
, 1);
295 saved_node
= vty
->node
;
297 /* If command doesn't succeeded in current node, try to walk up in node
299 * Changing vty->node is enough to try it just out without actual walkup
302 while (ret
!= CMD_SUCCESS
&& ret
!= CMD_SUCCESS_DAEMON
303 && ret
!= CMD_WARNING
&& ret
!= CMD_WARNING_CONFIG_FAILED
304 && vty
->node
> CONFIG_NODE
) {
305 vty
->node
= node_parent(vty
->node
);
306 ret
= cmd_execute_command(vline
, vty
, &cmd
, 1);
310 vty
->node
= saved_node
;
312 /* If command succeeded in any other node than current (tried > 0) we
314 * to move into node in the vtysh where it succeeded. */
315 if (ret
== CMD_SUCCESS
|| ret
== CMD_SUCCESS_DAEMON
316 || ret
== CMD_WARNING
) {
317 if ((saved_node
== BGP_VPNV4_NODE
318 || saved_node
== BGP_VPNV6_NODE
319 || saved_node
== BGP_IPV4_NODE
320 || saved_node
== BGP_IPV6_NODE
321 || saved_node
== BGP_IPV4M_NODE
322 || saved_node
== BGP_IPV4L_NODE
323 || saved_node
== BGP_IPV6L_NODE
324 || saved_node
== BGP_IPV6M_NODE
325 || saved_node
== BGP_EVPN_NODE
326 || saved_node
== LDP_IPV4_NODE
327 || saved_node
== LDP_IPV6_NODE
)
329 vtysh_execute("exit-address-family");
330 } else if ((saved_node
== BGP_EVPN_VNI_NODE
) && (tried
== 1)) {
331 vtysh_execute("exit-vni");
332 } else if (saved_node
== BGP_VRF_POLICY_NODE
&& (tried
== 1)) {
333 vtysh_execute("exit-vrf-policy");
334 } else if ((saved_node
== BGP_VNC_DEFAULTS_NODE
335 || saved_node
== BGP_VNC_NVE_GROUP_NODE
336 || saved_node
== BGP_VNC_L2_GROUP_NODE
)
338 vtysh_execute("exit-vnc");
339 } else if ((saved_node
== KEYCHAIN_KEY_NODE
340 || saved_node
== LDP_PSEUDOWIRE_NODE
341 || saved_node
== LDP_IPV4_IFACE_NODE
342 || saved_node
== LDP_IPV6_IFACE_NODE
)
344 vtysh_execute("exit");
346 vtysh_execute("end");
347 vtysh_execute("configure terminal");
350 /* If command didn't succeed in any node, continue with return value
357 cmd_free_strvec(vline
);
362 case CMD_WARNING_CONFIG_FAILED
:
363 if (vty
->type
== VTY_FILE
)
364 fprintf(stdout
, "Warning...\n");
366 case CMD_ERR_AMBIGUOUS
:
367 fprintf(stdout
, "%% Ambiguous command.\n");
369 case CMD_ERR_NO_MATCH
:
370 fprintf(stdout
, "%% Unknown command.\n");
372 case CMD_ERR_INCOMPLETE
:
373 fprintf(stdout
, "%% Command incomplete.\n");
375 case CMD_SUCCESS_DAEMON
: {
376 /* FIXME: Don't open pager for exit commands. popen() causes
378 * if exited from vtysh at all. This hack shouldn't cause any
380 * but is really ugly. */
381 if (pager
&& vtysh_pager_name
382 && (strncmp(line
, "exit", 4) != 0)) {
383 fp
= popen(vtysh_pager_name
, "w");
385 perror("popen failed for pager");
392 if (!strcmp(cmd
->string
, "configure terminal")) {
393 for (i
= 0; i
< array_size(vtysh_client
); i
++) {
394 cmd_stat
= vtysh_client_execute(
395 &vtysh_client
[i
], line
, fp
);
396 if (cmd_stat
== CMD_WARNING
)
402 vline
= cmd_make_strvec(line
);
405 if (pager
&& vtysh_pager_name
&& fp
407 if (pclose(fp
) == -1) {
408 perror("pclose failed for pager");
415 ret
= cmd_execute_command(vline
, vty
, &cmd
, 1);
416 cmd_free_strvec(vline
);
417 if (ret
!= CMD_SUCCESS_DAEMON
)
419 } else if (cmd
->func
) {
420 (*cmd
->func
)(cmd
, vty
, 0, NULL
);
425 cmd_stat
= CMD_SUCCESS
;
426 for (i
= 0; i
< array_size(vtysh_client
); i
++) {
427 if (cmd
->daemon
& vtysh_client
[i
].flag
) {
428 cmd_stat
= vtysh_client_execute(
429 &vtysh_client
[i
], line
, fp
);
430 if (cmd_stat
!= CMD_SUCCESS
)
434 if (cmd_stat
!= CMD_SUCCESS
)
438 (*cmd
->func
)(cmd
, vty
, 0, NULL
);
441 if (pager
&& vtysh_pager_name
&& fp
&& closepager
) {
442 if (pclose(fp
) == -1) {
443 perror("pclose failed for pager");
450 int vtysh_execute_no_pager(const char *line
)
452 return vtysh_execute_func(line
, 0);
455 int vtysh_execute(const char *line
)
457 return vtysh_execute_func(line
, 1);
460 static char *trim(char *s
)
471 while (end
>= s
&& isspace(*end
))
475 while (*s
&& isspace(*s
))
481 int vtysh_mark_file(const char *filename
)
488 const struct cmd_element
*cmd
;
489 int saved_ret
, prev_node
;
491 char *vty_buf_copy
= NULL
;
492 char *vty_buf_trimmed
= NULL
;
494 if (strncmp("-", filename
, 1) == 0)
497 confp
= fopen(filename
, "r");
500 fprintf(stderr
, "%% Can't open config file %s due to '%s'.\n",
501 filename
, safe_strerror(errno
));
502 return (CMD_ERR_NO_FILE
);
506 vty
->fd
= 0; /* stdout */
507 vty
->type
= VTY_TERM
;
508 vty
->node
= CONFIG_NODE
;
510 vtysh_execute_no_pager("enable");
511 vtysh_execute_no_pager("configure terminal");
512 vty_buf_copy
= XCALLOC(MTYPE_VTYSH_CMD
, VTY_BUFSIZ
);
514 while (fgets(vty
->buf
, VTY_BUFSIZ
, confp
)) {
517 strcpy(vty_buf_copy
, vty
->buf
);
518 vty_buf_trimmed
= trim(vty_buf_copy
);
521 case LDP_IPV4_IFACE_NODE
:
522 if (strncmp(vty_buf_copy
, " ", 3)) {
523 fprintf(stdout
, " end\n");
524 vty
->node
= LDP_IPV4_NODE
;
527 case LDP_IPV6_IFACE_NODE
:
528 if (strncmp(vty_buf_copy
, " ", 3)) {
529 fprintf(stdout
, " end\n");
530 vty
->node
= LDP_IPV6_NODE
;
533 case LDP_PSEUDOWIRE_NODE
:
534 if (strncmp(vty_buf_copy
, " ", 2)) {
535 fprintf(stdout
, " end\n");
536 vty
->node
= LDP_L2VPN_NODE
;
543 if (vty_buf_trimmed
[0] == '!' || vty_buf_trimmed
[0] == '#') {
544 fprintf(stdout
, "%s", vty
->buf
);
548 /* Split readline string up into the vector. */
549 vline
= cmd_make_strvec(vty
->buf
);
552 fprintf(stdout
, "%s", vty
->buf
);
556 /* Ignore the "end" lines, we will generate these where
558 if (strlen(vty_buf_trimmed
) == 3
559 && strncmp("end", vty_buf_trimmed
, 3) == 0) {
563 prev_node
= vty
->node
;
564 saved_ret
= ret
= cmd_execute_command_strict(vline
, vty
, &cmd
);
566 /* If command doesn't succeeded in current node, try to walk up
568 * Changing vty->node is enough to try it just out without
571 while (ret
!= CMD_SUCCESS
&& ret
!= CMD_SUCCESS_DAEMON
572 && ret
!= CMD_WARNING
&& ret
!= CMD_WARNING_CONFIG_FAILED
573 && vty
->node
> CONFIG_NODE
) {
574 vty
->node
= node_parent(vty
->node
);
575 ret
= cmd_execute_command_strict(vline
, vty
, &cmd
);
579 /* If command succeeded in any other node than current (tried >
581 * to move into node in the vtysh where it succeeded. */
582 if (ret
== CMD_SUCCESS
|| ret
== CMD_SUCCESS_DAEMON
583 || ret
== CMD_WARNING
) {
584 if ((prev_node
== BGP_VPNV4_NODE
585 || prev_node
== BGP_VPNV6_NODE
586 || prev_node
== BGP_IPV4_NODE
587 || prev_node
== BGP_IPV6_NODE
588 || prev_node
== BGP_IPV4L_NODE
589 || prev_node
== BGP_IPV6L_NODE
590 || prev_node
== BGP_IPV4M_NODE
591 || prev_node
== BGP_IPV6M_NODE
592 || prev_node
== BGP_EVPN_NODE
)
594 fprintf(stdout
, "exit-address-family\n");
595 } else if ((prev_node
== BGP_EVPN_VNI_NODE
)
597 fprintf(stdout
, "exit-vni\n");
598 } else if ((prev_node
== KEYCHAIN_KEY_NODE
)
600 fprintf(stdout
, "exit\n");
602 fprintf(stdout
, "end\n");
605 /* If command didn't succeed in any node, continue with return
610 vty
->node
= prev_node
;
613 cmd_free_strvec(vline
);
616 case CMD_WARNING_CONFIG_FAILED
:
617 if (vty
->type
== VTY_FILE
)
618 fprintf(stderr
, "line %d: Warning...: %s\n",
622 XFREE(MTYPE_VTYSH_CMD
, vty_buf_copy
);
624 case CMD_ERR_AMBIGUOUS
:
625 fprintf(stderr
, "line %d: %% Ambiguous command: %s\n",
629 XFREE(MTYPE_VTYSH_CMD
, vty_buf_copy
);
630 return CMD_ERR_AMBIGUOUS
;
631 case CMD_ERR_NO_MATCH
:
632 fprintf(stderr
, "line %d: %% Unknown command: %s\n",
636 XFREE(MTYPE_VTYSH_CMD
, vty_buf_copy
);
637 return CMD_ERR_NO_MATCH
;
638 case CMD_ERR_INCOMPLETE
:
639 fprintf(stderr
, "line %d: %% Command incomplete: %s\n",
643 XFREE(MTYPE_VTYSH_CMD
, vty_buf_copy
);
644 return CMD_ERR_INCOMPLETE
;
646 fprintf(stdout
, "%s", vty
->buf
);
648 case CMD_SUCCESS_DAEMON
: {
650 int cmd_stat
= CMD_SUCCESS
;
652 fprintf(stdout
, "%s", vty
->buf
);
653 for (i
= 0; i
< array_size(vtysh_client
); i
++) {
654 if (cmd
->daemon
& vtysh_client
[i
].flag
) {
655 cmd_stat
= vtysh_client_execute(
656 &vtysh_client
[i
], vty
->buf
,
658 if (cmd_stat
!= CMD_SUCCESS
)
662 if (cmd_stat
!= CMD_SUCCESS
)
666 (*cmd
->func
)(cmd
, vty
, 0, NULL
);
670 /* This is the end */
671 fprintf(stdout
, "\nend\n");
673 XFREE(MTYPE_VTYSH_CMD
, vty_buf_copy
);
681 /* Configration make from file. */
682 int vtysh_config_from_file(struct vty
*vty
, FILE *fp
)
685 const struct cmd_element
*cmd
;
687 int retcode
= CMD_SUCCESS
;
689 while (fgets(vty
->buf
, VTY_BUFSIZ
, fp
)) {
692 ret
= command_config_read_one_line(vty
, &cmd
, 1);
696 case CMD_WARNING_CONFIG_FAILED
:
697 if (vty
->type
== VTY_FILE
)
698 fprintf(stderr
, "line %d: Warning[%d]...: %s\n",
699 lineno
, vty
->node
, vty
->buf
);
700 retcode
= ret
; /* once we have an error, we remember &
703 case CMD_ERR_AMBIGUOUS
:
705 "line %d: %% Ambiguous command[%d]: %s\n",
706 lineno
, vty
->node
, vty
->buf
);
707 retcode
= CMD_ERR_AMBIGUOUS
; /* once we have an error,
711 case CMD_ERR_NO_MATCH
:
712 fprintf(stderr
, "line %d: %% Unknown command[%d]: %s",
713 lineno
, vty
->node
, vty
->buf
);
715 CMD_ERR_NO_MATCH
; /* once we have an error, we
716 remember & return that */
718 case CMD_ERR_INCOMPLETE
:
720 "line %d: %% Command incomplete[%d]: %s\n",
721 lineno
, vty
->node
, vty
->buf
);
722 retcode
= CMD_ERR_INCOMPLETE
; /* once we have an error,
726 case CMD_SUCCESS_DAEMON
: {
728 int cmd_stat
= CMD_SUCCESS
;
730 for (i
= 0; i
< array_size(vtysh_client
); i
++) {
731 if (cmd
->daemon
& vtysh_client
[i
].flag
) {
732 cmd_stat
= vtysh_client_execute(
733 &vtysh_client
[i
], vty
->buf
,
736 * CMD_WARNING - Can mean that the
738 * parsed successfully but it was
740 * in a few spots. As such if we
742 * CMD_WARNING from a daemon we
744 * talking to the other daemons for the
748 if (cmd_stat
!= CMD_SUCCESS
749 && cmd_stat
!= CMD_WARNING
) {
751 "line %d: Failure to communicate[%d] to %s, line: %s\n",
753 vtysh_client
[i
].name
,
760 if (cmd_stat
!= CMD_SUCCESS
)
764 (*cmd
->func
)(cmd
, vty
, 0, NULL
);
772 /* We don't care about the point of the cursor when '?' is typed. */
773 static int vtysh_rl_describe(void)
780 struct cmd_token
*token
;
782 vline
= cmd_make_strvec(rl_line_buffer
);
784 /* In case of '> ?'. */
786 vline
= vector_init(1);
787 vector_set(vline
, NULL
);
788 } else if (rl_end
&& isspace((int)rl_line_buffer
[rl_end
- 1]))
789 vector_set(vline
, NULL
);
791 describe
= cmd_describe_command(vline
, vty
, &ret
);
793 fprintf(stdout
, "\n");
795 /* Ambiguous and no match error. */
797 case CMD_ERR_AMBIGUOUS
:
798 cmd_free_strvec(vline
);
799 fprintf(stdout
, "%% Ambiguous command.\n");
803 case CMD_ERR_NO_MATCH
:
804 cmd_free_strvec(vline
);
805 fprintf(stdout
, "%% There is no matched command.\n");
811 /* Get width of command string. */
813 for (i
= 0; i
< vector_active(describe
); i
++)
814 if ((token
= vector_slot(describe
, i
)) != NULL
) {
815 if (token
->text
[0] == '\0')
818 int len
= strlen(token
->text
);
824 for (i
= 0; i
< vector_active(describe
); i
++)
825 if ((token
= vector_slot(describe
, i
)) != NULL
) {
827 fprintf(stdout
, " %-s\n", token
->text
);
829 fprintf(stdout
, " %-*s %s\n", width
,
830 token
->text
, token
->desc
);
832 if (IS_VARYING_TOKEN(token
->type
)) {
833 const char *ref
= vector_slot(
834 vline
, vector_active(vline
) - 1);
836 vector varcomps
= vector_init(VECTOR_MIN_SIZE
);
837 cmd_variable_complete(token
, ref
, varcomps
);
839 if (vector_active(varcomps
) > 0) {
841 rl_get_screen_size(&rows
, &cols
);
843 char *ac
= cmd_variable_comp2str(
845 fprintf(stdout
, "%s\n", ac
);
846 XFREE(MTYPE_TMP
, ac
);
849 vector_free(varcomps
);
853 cmd_free_strvec(vline
);
854 vector_free(describe
);
861 /* Result of cmd_complete_command() call will be stored here
862 * and used in new_completion() in order to put the space in
863 * correct places only. */
866 static char *command_generator(const char *text
, int state
)
869 static char **matched
= NULL
;
870 static int index
= 0;
876 if (vty
->node
== AUTH_NODE
|| vty
->node
== AUTH_ENABLE_NODE
)
879 vline
= cmd_make_strvec(rl_line_buffer
);
883 if (rl_end
&& isspace((int)rl_line_buffer
[rl_end
- 1]))
884 vector_set(vline
, NULL
);
886 matched
= cmd_complete_command(vline
, vty
, &complete_status
);
887 cmd_free_strvec(vline
);
890 if (matched
&& matched
[index
])
891 /* this is free()'d by readline, but we leak 1 count of
892 * MTYPE_COMPLETION */
893 return matched
[index
++];
895 XFREE(MTYPE_TMP
, matched
);
901 static char **new_completion(char *text
, int start
, int end
)
905 matches
= rl_completion_matches(text
, command_generator
);
909 if (complete_status
!= CMD_COMPLETE_FULL_MATCH
)
910 /* only append a space on full match */
911 rl_completion_append_character
= '\0';
917 /* Vty node structures. */
918 static struct cmd_node bgp_node
= {
919 BGP_NODE
, "%s(config-router)# ",
922 static struct cmd_node rip_node
= {
923 RIP_NODE
, "%s(config-router)# ",
926 static struct cmd_node isis_node
= {
927 ISIS_NODE
, "%s(config-router)# ",
930 static struct cmd_node interface_node
= {
931 INTERFACE_NODE
, "%s(config-if)# ",
934 static struct cmd_node pw_node
= {
935 PW_NODE
, "%s(config-pw)# ",
938 static struct cmd_node ns_node
= {
939 NS_NODE
, "%s(config-logical-router)# ",
942 static struct cmd_node vrf_node
= {
943 VRF_NODE
, "%s(config-vrf)# ",
946 static struct cmd_node rmap_node
= {RMAP_NODE
, "%s(config-route-map)# "};
948 static struct cmd_node zebra_node
= {ZEBRA_NODE
, "%s(config-router)# "};
950 static struct cmd_node bgp_vpnv4_node
= {BGP_VPNV4_NODE
,
951 "%s(config-router-af)# "};
953 static struct cmd_node bgp_vpnv6_node
= {BGP_VPNV6_NODE
,
954 "%s(config-router-af)# "};
956 static struct cmd_node bgp_ipv4_node
= {BGP_IPV4_NODE
,
957 "%s(config-router-af)# "};
959 static struct cmd_node bgp_ipv4m_node
= {BGP_IPV4M_NODE
,
960 "%s(config-router-af)# "};
962 static struct cmd_node bgp_ipv4l_node
= {BGP_IPV4L_NODE
,
963 "%s(config-router-af)# "};
965 static struct cmd_node bgp_ipv6_node
= {BGP_IPV6_NODE
,
966 "%s(config-router-af)# "};
968 static struct cmd_node bgp_ipv6m_node
= {BGP_IPV6M_NODE
,
969 "%s(config-router-af)# "};
971 static struct cmd_node bgp_evpn_node
= {BGP_EVPN_NODE
,
972 "%s(config-router-af)# "};
974 static struct cmd_node bgp_evpn_vni_node
= {BGP_EVPN_VNI_NODE
,
975 "%s(config-router-af-vni)# "};
977 static struct cmd_node bgp_ipv6l_node
= {BGP_IPV6L_NODE
,
978 "%s(config-router-af)# "};
980 static struct cmd_node bgp_vnc_defaults_node
= {
981 BGP_VNC_DEFAULTS_NODE
, "%s(config-router-vnc-defaults)# "};
983 static struct cmd_node bgp_vnc_nve_group_node
= {
984 BGP_VNC_NVE_GROUP_NODE
, "%s(config-router-vnc-nve-group)# "};
986 static struct cmd_node bgp_vrf_policy_node
= {BGP_VRF_POLICY_NODE
,
987 "%s(config-router-vrf-policy)# "};
989 static struct cmd_node bgp_vnc_l2_group_node
= {
990 BGP_VNC_L2_GROUP_NODE
, "%s(config-router-vnc-l2-group)# "};
992 static struct cmd_node ospf_node
= {OSPF_NODE
, "%s(config-router)# "};
994 static struct cmd_node eigrp_node
= {EIGRP_NODE
, "%s(config-router)# "};
996 static struct cmd_node babel_node
= {BABEL_NODE
, "%s(config-router)# "};
998 static struct cmd_node ripng_node
= {RIPNG_NODE
, "%s(config-router)# "};
1000 static struct cmd_node ospf6_node
= {OSPF6_NODE
, "%s(config-ospf6)# "};
1002 static struct cmd_node ldp_node
= {LDP_NODE
, "%s(config-ldp)# "};
1004 static struct cmd_node ldp_ipv4_node
= {LDP_IPV4_NODE
, "%s(config-ldp-af)# "};
1006 static struct cmd_node ldp_ipv6_node
= {LDP_IPV6_NODE
, "%s(config-ldp-af)# "};
1008 static struct cmd_node ldp_ipv4_iface_node
= {LDP_IPV4_IFACE_NODE
,
1009 "%s(config-ldp-af-if)# "};
1011 static struct cmd_node ldp_ipv6_iface_node
= {LDP_IPV6_IFACE_NODE
,
1012 "%s(config-ldp-af-if)# "};
1014 static struct cmd_node ldp_l2vpn_node
= {LDP_L2VPN_NODE
, "%s(config-l2vpn)# "};
1016 static struct cmd_node ldp_pseudowire_node
= {LDP_PSEUDOWIRE_NODE
,
1017 "%s(config-l2vpn-pw)# "};
1019 static struct cmd_node keychain_node
= {KEYCHAIN_NODE
, "%s(config-keychain)# "};
1021 static struct cmd_node keychain_key_node
= {KEYCHAIN_KEY_NODE
,
1022 "%s(config-keychain-key)# "};
1024 struct cmd_node link_params_node
= {
1025 LINK_PARAMS_NODE
, "%s(config-link-params)# ",
1028 /* Defined in lib/vty.c */
1029 extern struct cmd_node vty_node
;
1031 /* When '^Z' is received from vty, move down to the enable mode. */
1032 static int vtysh_end(void)
1034 switch (vty
->node
) {
1037 /* Nothing to do. */
1040 vty
->node
= ENABLE_NODE
;
1046 DEFUNSH(VTYSH_REALLYALL
, vtysh_end_all
, vtysh_end_all_cmd
, "end",
1047 "End current mode and change to enable mode\n")
1052 DEFUNSH(VTYSH_BGPD
, router_bgp
, router_bgp_cmd
,
1053 "router bgp [(1-4294967295) [<view|vrf> WORD]]",
1054 ROUTER_STR BGP_STR AS_STR
1055 "BGP view\nBGP VRF\n"
1058 vty
->node
= BGP_NODE
;
1062 DEFUNSH(VTYSH_BGPD
, address_family_vpnv4
, address_family_vpnv4_cmd
,
1063 "address-family vpnv4 [unicast]",
1064 "Enter Address Family command mode\n"
1066 "Address Family modifier\n")
1068 vty
->node
= BGP_VPNV4_NODE
;
1072 DEFUNSH(VTYSH_BGPD
, address_family_vpnv6
, address_family_vpnv6_cmd
,
1073 "address-family vpnv6 [unicast]",
1074 "Enter Address Family command mode\n"
1076 "Address Family modifier\n")
1078 vty
->node
= BGP_VPNV6_NODE
;
1082 DEFUNSH(VTYSH_BGPD
, address_family_ipv4
, address_family_ipv4_cmd
,
1083 "address-family ipv4 [unicast]",
1084 "Enter Address Family command mode\n"
1086 "Address Family Modifier\n")
1088 vty
->node
= BGP_IPV4_NODE
;
1092 DEFUNSH(VTYSH_BGPD
, address_family_ipv4_multicast
,
1093 address_family_ipv4_multicast_cmd
, "address-family ipv4 multicast",
1094 "Enter Address Family command mode\n"
1096 "Address Family modifier\n")
1098 vty
->node
= BGP_IPV4M_NODE
;
1102 DEFUNSH(VTYSH_BGPD
, address_family_ipv4_vpn
, address_family_ipv4_vpn_cmd
,
1103 "address-family ipv4 vpn",
1104 "Enter Address Family command mode\n"
1106 "Address Family modifier\n")
1108 vty
->node
= BGP_VPNV4_NODE
;
1112 DEFUNSH(VTYSH_BGPD
, address_family_ipv4_labeled_unicast
,
1113 address_family_ipv4_labeled_unicast_cmd
,
1114 "address-family ipv4 labeled-unicast",
1115 "Enter Address Family command mode\n"
1117 "Address Family modifier\n")
1119 vty
->node
= BGP_IPV4L_NODE
;
1123 DEFUNSH(VTYSH_BGPD
, address_family_ipv6
, address_family_ipv6_cmd
,
1124 "address-family ipv6 [unicast]",
1125 "Enter Address Family command mode\n"
1127 "Address Family modifier\n")
1129 vty
->node
= BGP_IPV6_NODE
;
1133 DEFUNSH(VTYSH_BGPD
, address_family_ipv6_multicast
,
1134 address_family_ipv6_multicast_cmd
, "address-family ipv6 multicast",
1135 "Enter Address Family command mode\n"
1137 "Address Family modifier\n")
1139 vty
->node
= BGP_IPV6M_NODE
;
1143 DEFUNSH(VTYSH_BGPD
, address_family_ipv6_vpn
, address_family_ipv6_vpn_cmd
,
1144 "address-family ipv6 vpn",
1145 "Enter Address Family command mode\n"
1147 "Address Family modifier\n")
1149 vty
->node
= BGP_VPNV6_NODE
;
1153 DEFUNSH(VTYSH_BGPD
, address_family_ipv6_labeled_unicast
,
1154 address_family_ipv6_labeled_unicast_cmd
,
1155 "address-family ipv6 labeled-unicast",
1156 "Enter Address Family command mode\n"
1158 "Address Family modifier\n")
1160 vty
->node
= BGP_IPV6L_NODE
;
1164 DEFUNSH(VTYSH_BGPD
, address_family_evpn
, address_family_evpn_cmd
,
1165 "address-family <l2vpn evpn>",
1166 "Enter Address Family command mode\n"
1168 "Address Family modifier\n")
1170 vty
->node
= BGP_EVPN_NODE
;
1174 #if defined(HAVE_CUMULUS)
1175 DEFUNSH_HIDDEN(VTYSH_BGPD
, address_family_evpn2
, address_family_evpn2_cmd
,
1176 "address-family evpn",
1177 "Enter Address Family command mode\n"
1178 "EVPN Address family\n")
1180 vty
->node
= BGP_EVPN_NODE
;
1185 DEFUNSH(VTYSH_BGPD
, bgp_evpn_vni
, bgp_evpn_vni_cmd
, "vni (1-16777215)",
1186 "VXLAN Network Identifier\n"
1189 vty
->node
= BGP_EVPN_VNI_NODE
;
1193 #if defined(ENABLE_BGP_VNC)
1194 DEFUNSH(VTYSH_BGPD
, vnc_defaults
, vnc_defaults_cmd
, "vnc defaults",
1195 "VNC/RFP related configuration\n"
1196 "Configure default NVE group\n")
1198 vty
->node
= BGP_VNC_DEFAULTS_NODE
;
1202 DEFUNSH(VTYSH_BGPD
, vnc_nve_group
, vnc_nve_group_cmd
, "vnc nve-group NAME",
1203 "VNC/RFP related configuration\n"
1204 "Configure a NVE group\n"
1207 vty
->node
= BGP_VNC_NVE_GROUP_NODE
;
1211 DEFUNSH(VTYSH_BGPD
, vnc_vrf_policy
, vnc_vrf_policy_cmd
, "vrf-policy NAME",
1212 "Configure a VRF policy group\n"
1215 vty
->node
= BGP_VRF_POLICY_NODE
;
1219 DEFUNSH(VTYSH_BGPD
, vnc_l2_group
, vnc_l2_group_cmd
, "vnc l2-group NAME",
1220 "VNC/RFP related configuration\n"
1221 "Configure a L2 group\n"
1224 vty
->node
= BGP_VNC_L2_GROUP_NODE
;
1229 DEFUNSH(VTYSH_RIPD
, key_chain
, key_chain_cmd
, "key chain WORD",
1230 "Authentication key management\n"
1231 "Key-chain management\n"
1234 vty
->node
= KEYCHAIN_NODE
;
1238 DEFUNSH(VTYSH_RIPD
, key
, key_cmd
, "key (0-2147483647)",
1240 "Key identifier number\n")
1242 vty
->node
= KEYCHAIN_KEY_NODE
;
1246 DEFUNSH(VTYSH_RIPD
, router_rip
, router_rip_cmd
, "router rip",
1249 vty
->node
= RIP_NODE
;
1253 DEFUNSH(VTYSH_RIPNGD
, router_ripng
, router_ripng_cmd
, "router ripng",
1254 ROUTER_STR
"RIPng\n")
1256 vty
->node
= RIPNG_NODE
;
1260 DEFUNSH(VTYSH_OSPFD
, router_ospf
, router_ospf_cmd
, "router ospf [(1-65535)]",
1261 "Enable a routing process\n"
1262 "Start OSPF configuration\n"
1265 vty
->node
= OSPF_NODE
;
1269 DEFUNSH(VTYSH_EIGRPD
, router_eigrp
, router_eigrp_cmd
, "router eigrp (1-65535)",
1270 "Enable a routing process\n"
1271 "Start EIGRP configuration\n"
1272 "AS number to use\n")
1274 vty
->node
= EIGRP_NODE
;
1278 DEFUNSH(VTYSH_BABELD
, router_babel
, router_babel_cmd
, "router babel",
1279 "Enable a routing process\n"
1280 "Make Babel instance command\n")
1282 vty
->node
= BABEL_NODE
;
1286 DEFUNSH(VTYSH_OSPF6D
, router_ospf6
, router_ospf6_cmd
, "router ospf6",
1287 ROUTER_STR OSPF6_STR
)
1289 vty
->node
= OSPF6_NODE
;
1293 #if defined(HAVE_LDPD)
1294 DEFUNSH(VTYSH_LDPD
, ldp_mpls_ldp
, ldp_mpls_ldp_cmd
, "mpls ldp",
1295 "Global MPLS configuration subcommands\n"
1296 "Label Distribution Protocol\n")
1298 vty
->node
= LDP_NODE
;
1302 DEFUNSH(VTYSH_LDPD
, ldp_address_family_ipv4
, ldp_address_family_ipv4_cmd
,
1303 "address-family ipv4",
1304 "Configure Address Family and its parameters\n"
1307 vty
->node
= LDP_IPV4_NODE
;
1311 DEFUNSH(VTYSH_LDPD
, ldp_address_family_ipv6
, ldp_address_family_ipv6_cmd
,
1312 "address-family ipv6",
1313 "Configure Address Family and its parameters\n"
1316 vty
->node
= LDP_IPV6_NODE
;
1320 DEFUNSH(VTYSH_LDPD
, ldp_exit_address_family
, ldp_exit_address_family_cmd
,
1321 "exit-address-family", "Exit from Address Family configuration mode\n")
1323 if (vty
->node
== LDP_IPV4_NODE
|| vty
->node
== LDP_IPV6_NODE
)
1324 vty
->node
= LDP_NODE
;
1328 DEFUNSH(VTYSH_LDPD
, ldp_interface_ifname
, ldp_interface_ifname_cmd
,
1330 "Enable LDP on an interface and enter interface submode\n"
1331 "Interface's name\n")
1333 switch (vty
->node
) {
1335 vty
->node
= LDP_IPV4_IFACE_NODE
;
1338 vty
->node
= LDP_IPV6_IFACE_NODE
;
1347 DEFUNSH(VTYSH_LDPD
, ldp_l2vpn_word_type_vpls
, ldp_l2vpn_word_type_vpls_cmd
,
1348 "l2vpn WORD type vpls",
1349 "Configure l2vpn commands\n"
1352 "Virtual Private LAN Service\n")
1354 vty
->node
= LDP_L2VPN_NODE
;
1358 DEFUNSH(VTYSH_LDPD
, ldp_member_pseudowire_ifname
,
1359 ldp_member_pseudowire_ifname_cmd
, "member pseudowire IFNAME",
1360 "L2VPN member configuration\n"
1361 "Pseudowire interface\n"
1362 "Interface's name\n")
1364 vty
->node
= LDP_PSEUDOWIRE_NODE
;
1369 DEFUNSH(VTYSH_ISISD
, router_isis
, router_isis_cmd
, "router isis WORD",
1372 "ISO Routing area tag")
1374 vty
->node
= ISIS_NODE
;
1378 DEFUNSH(VTYSH_RMAP
, vtysh_route_map
, vtysh_route_map_cmd
,
1379 "route-map WORD <deny|permit> (1-65535)",
1380 "Create route-map or enter route-map command mode\n"
1382 "Route map denies set operations\n"
1383 "Route map permits set operations\n"
1384 "Sequence to insert to/delete from existing route-map entry\n")
1386 vty
->node
= RMAP_NODE
;
1390 DEFUNSH(VTYSH_ALL
, vtysh_line_vty
, vtysh_line_vty_cmd
, "line vty",
1391 "Configure a terminal line\n"
1392 "Virtual terminal\n")
1394 vty
->node
= VTY_NODE
;
1398 DEFUNSH(VTYSH_REALLYALL
, vtysh_enable
, vtysh_enable_cmd
, "enable",
1399 "Turn on privileged mode command\n")
1401 vty
->node
= ENABLE_NODE
;
1405 DEFUNSH(VTYSH_REALLYALL
, vtysh_disable
, vtysh_disable_cmd
, "disable",
1406 "Turn off privileged mode command\n")
1408 if (vty
->node
== ENABLE_NODE
)
1409 vty
->node
= VIEW_NODE
;
1413 DEFUNSH(VTYSH_REALLYALL
, vtysh_config_terminal
, vtysh_config_terminal_cmd
,
1414 "configure terminal",
1415 "Configuration from vty interface\n"
1416 "Configuration terminal\n")
1418 vty
->node
= CONFIG_NODE
;
1422 static int vtysh_exit(struct vty
*vty
)
1424 switch (vty
->node
) {
1430 vty
->node
= ENABLE_NODE
;
1432 case INTERFACE_NODE
:
1445 case LDP_L2VPN_NODE
:
1451 vtysh_execute("end");
1452 vtysh_execute("configure terminal");
1453 vty
->node
= CONFIG_NODE
;
1455 case BGP_VPNV4_NODE
:
1456 case BGP_VPNV6_NODE
:
1458 case BGP_IPV4M_NODE
:
1459 case BGP_IPV4L_NODE
:
1461 case BGP_IPV6M_NODE
:
1462 case BGP_IPV6L_NODE
:
1463 case BGP_VRF_POLICY_NODE
:
1465 case BGP_VNC_DEFAULTS_NODE
:
1466 case BGP_VNC_NVE_GROUP_NODE
:
1467 case BGP_VNC_L2_GROUP_NODE
:
1468 vty
->node
= BGP_NODE
;
1470 case BGP_EVPN_VNI_NODE
:
1471 vty
->node
= BGP_EVPN_NODE
;
1475 vty
->node
= LDP_NODE
;
1477 case LDP_IPV4_IFACE_NODE
:
1478 vty
->node
= LDP_IPV4_NODE
;
1480 case LDP_IPV6_IFACE_NODE
:
1481 vty
->node
= LDP_IPV6_NODE
;
1483 case LDP_PSEUDOWIRE_NODE
:
1484 vty
->node
= LDP_L2VPN_NODE
;
1486 case KEYCHAIN_KEY_NODE
:
1487 vty
->node
= KEYCHAIN_NODE
;
1489 case LINK_PARAMS_NODE
:
1490 vty
->node
= INTERFACE_NODE
;
1498 DEFUNSH(VTYSH_REALLYALL
, vtysh_exit_all
, vtysh_exit_all_cmd
, "exit",
1499 "Exit current mode and down to previous mode\n")
1501 return vtysh_exit(vty
);
1504 DEFUNSH(VTYSH_ALL
, vtysh_quit_all
, vtysh_quit_all_cmd
, "quit",
1505 "Exit current mode and down to previous mode\n")
1507 return vtysh_exit_all(self
, vty
, argc
, argv
);
1510 DEFUNSH(VTYSH_BGPD
, exit_address_family
, exit_address_family_cmd
,
1511 "exit-address-family", "Exit from Address Family configuration mode\n")
1513 if (vty
->node
== BGP_IPV4_NODE
|| vty
->node
== BGP_IPV4M_NODE
1514 || vty
->node
== BGP_IPV4L_NODE
|| vty
->node
== BGP_VPNV4_NODE
1515 || vty
->node
== BGP_VPNV6_NODE
|| vty
->node
== BGP_IPV6_NODE
1516 || vty
->node
== BGP_IPV6L_NODE
|| vty
->node
== BGP_IPV6M_NODE
1517 || vty
->node
== BGP_EVPN_NODE
)
1518 vty
->node
= BGP_NODE
;
1522 DEFUNSH(VTYSH_BGPD
, exit_vni
, exit_vni_cmd
, "exit-vni", "Exit from VNI mode\n")
1524 if (vty
->node
== BGP_EVPN_VNI_NODE
)
1525 vty
->node
= BGP_EVPN_NODE
;
1529 DEFUNSH(VTYSH_BGPD
, exit_vnc_config
, exit_vnc_config_cmd
, "exit-vnc",
1530 "Exit from VNC configuration mode\n")
1532 if (vty
->node
== BGP_VNC_DEFAULTS_NODE
1533 || vty
->node
== BGP_VNC_NVE_GROUP_NODE
1534 || vty
->node
== BGP_VNC_L2_GROUP_NODE
)
1535 vty
->node
= BGP_NODE
;
1539 DEFUNSH(VTYSH_BGPD
, exit_vrf_policy
, exit_vrf_policy_cmd
, "exit-vrf-policy",
1540 "Exit from VRF configuration mode\n")
1542 if (vty
->node
== BGP_VRF_POLICY_NODE
)
1543 vty
->node
= BGP_NODE
;
1547 DEFUNSH(VTYSH_RIPD
, vtysh_exit_ripd
, vtysh_exit_ripd_cmd
, "exit",
1548 "Exit current mode and down to previous mode\n")
1550 return vtysh_exit(vty
);
1553 DEFUNSH(VTYSH_RIPD
, vtysh_quit_ripd
, vtysh_quit_ripd_cmd
, "quit",
1554 "Exit current mode and down to previous mode\n")
1556 return vtysh_exit_ripd(self
, vty
, argc
, argv
);
1559 DEFUNSH(VTYSH_RIPNGD
, vtysh_exit_ripngd
, vtysh_exit_ripngd_cmd
, "exit",
1560 "Exit current mode and down to previous mode\n")
1562 return vtysh_exit(vty
);
1565 DEFUNSH(VTYSH_RIPNGD
, vtysh_quit_ripngd
, vtysh_quit_ripngd_cmd
, "quit",
1566 "Exit current mode and down to previous mode\n")
1568 return vtysh_exit_ripngd(self
, vty
, argc
, argv
);
1571 DEFUNSH(VTYSH_RMAP
, vtysh_exit_rmap
, vtysh_exit_rmap_cmd
, "exit",
1572 "Exit current mode and down to previous mode\n")
1574 return vtysh_exit(vty
);
1577 DEFUNSH(VTYSH_RMAP
, vtysh_quit_rmap
, vtysh_quit_rmap_cmd
, "quit",
1578 "Exit current mode and down to previous mode\n")
1580 return vtysh_exit_rmap(self
, vty
, argc
, argv
);
1583 DEFUNSH(VTYSH_BGPD
, vtysh_exit_bgpd
, vtysh_exit_bgpd_cmd
, "exit",
1584 "Exit current mode and down to previous mode\n")
1586 return vtysh_exit(vty
);
1589 DEFUNSH(VTYSH_BGPD
, vtysh_quit_bgpd
, vtysh_quit_bgpd_cmd
, "quit",
1590 "Exit current mode and down to previous mode\n")
1592 return vtysh_exit_bgpd(self
, vty
, argc
, argv
);
1595 DEFUNSH(VTYSH_OSPFD
, vtysh_exit_ospfd
, vtysh_exit_ospfd_cmd
, "exit",
1596 "Exit current mode and down to previous mode\n")
1598 return vtysh_exit(vty
);
1601 DEFUNSH(VTYSH_OSPFD
, vtysh_quit_ospfd
, vtysh_quit_ospfd_cmd
, "quit",
1602 "Exit current mode and down to previous mode\n")
1604 return vtysh_exit_ospfd(self
, vty
, argc
, argv
);
1607 DEFUNSH(VTYSH_EIGRPD
, vtysh_exit_eigrpd
, vtysh_exit_eigrpd_cmd
, "exit",
1608 "Exit current mode and down to previous mode\n")
1610 return vtysh_exit(vty
);
1613 DEFUNSH(VTYSH_EIGRPD
, vtysh_quit_eigrpd
, vtysh_quit_eigrpd_cmd
, "quit",
1614 "Exit current mode and down to previous mode\n")
1616 return vtysh_exit(vty
);
1619 DEFUNSH(VTYSH_EIGRPD
, vtysh_exit_babeld
, vtysh_exit_babeld_cmd
, "exit",
1620 "Exit current mode and down to previous mode\n")
1622 return vtysh_exit(vty
);
1625 DEFUNSH(VTYSH_BABELD
, vtysh_quit_babeld
, vtysh_quit_babeld_cmd
, "quit",
1626 "Exit current mode and down to previous mode\n")
1628 return vtysh_exit(vty
);
1631 DEFUNSH(VTYSH_OSPF6D
, vtysh_exit_ospf6d
, vtysh_exit_ospf6d_cmd
, "exit",
1632 "Exit current mode and down to previous mode\n")
1634 return vtysh_exit(vty
);
1637 DEFUNSH(VTYSH_OSPF6D
, vtysh_quit_ospf6d
, vtysh_quit_ospf6d_cmd
, "quit",
1638 "Exit current mode and down to previous mode\n")
1640 return vtysh_exit_ospf6d(self
, vty
, argc
, argv
);
1643 #if defined(HAVE_LDPD)
1644 DEFUNSH(VTYSH_LDPD
, vtysh_exit_ldpd
, vtysh_exit_ldpd_cmd
, "exit",
1645 "Exit current mode and down to previous mode\n")
1647 return vtysh_exit(vty
);
1650 ALIAS(vtysh_exit_ldpd
, vtysh_quit_ldpd_cmd
, "quit",
1651 "Exit current mode and down to previous mode\n")
1654 DEFUNSH(VTYSH_ISISD
, vtysh_exit_isisd
, vtysh_exit_isisd_cmd
, "exit",
1655 "Exit current mode and down to previous mode\n")
1657 return vtysh_exit(vty
);
1660 DEFUNSH(VTYSH_ISISD
, vtysh_quit_isisd
, vtysh_quit_isisd_cmd
, "quit",
1661 "Exit current mode and down to previous mode\n")
1663 return vtysh_exit_isisd(self
, vty
, argc
, argv
);
1666 DEFUNSH(VTYSH_ALL
, vtysh_exit_line_vty
, vtysh_exit_line_vty_cmd
, "exit",
1667 "Exit current mode and down to previous mode\n")
1669 return vtysh_exit(vty
);
1672 DEFUNSH(VTYSH_ALL
, vtysh_quit_line_vty
, vtysh_quit_line_vty_cmd
, "quit",
1673 "Exit current mode and down to previous mode\n")
1675 return vtysh_exit_line_vty(self
, vty
, argc
, argv
);
1678 DEFUNSH(VTYSH_INTERFACE
, vtysh_interface
, vtysh_interface_cmd
,
1679 "interface IFNAME [vrf NAME]",
1680 "Select an interface to configure\n"
1681 "Interface's name\n" VRF_CMD_HELP_STR
)
1683 vty
->node
= INTERFACE_NODE
;
1687 DEFUNSH(VTYSH_ZEBRA
, vtysh_pseudowire
, vtysh_pseudowire_cmd
,
1688 "pseudowire IFNAME",
1689 "Static pseudowire configuration\n"
1690 "Pseudowire name\n")
1692 vty
->node
= PW_NODE
;
1696 /* TODO Implement "no interface command in isisd. */
1697 DEFSH(VTYSH_ZEBRA
| VTYSH_RIPD
| VTYSH_RIPNGD
| VTYSH_OSPFD
| VTYSH_OSPF6D
1699 vtysh_no_interface_cmd
, "no interface IFNAME", NO_STR
1700 "Delete a pseudo interface's configuration\n"
1701 "Interface's name\n")
1703 DEFSH(VTYSH_ZEBRA
, vtysh_no_interface_vrf_cmd
, "no interface IFNAME vrf NAME",
1705 "Delete a pseudo interface's configuration\n"
1706 "Interface's name\n" VRF_CMD_HELP_STR
)
1708 DEFUNSH(VTYSH_NS
, vtysh_ns
, vtysh_ns_cmd
, "logical-router (1-65535) ns NAME",
1709 "Enable a logical-router\n"
1710 "Specify the logical-router indentifier\n"
1712 "The file name in " NS_RUN_DIR
", or a full pathname\n")
1714 vty
->node
= NS_NODE
;
1718 DEFUNSH(VTYSH_VRF
, vtysh_vrf
, vtysh_vrf_cmd
, "vrf NAME",
1719 "Select a VRF to configure\n"
1722 vty
->node
= VRF_NODE
;
1726 DEFSH(VTYSH_ZEBRA
, vtysh_no_vrf_cmd
, "no vrf NAME", NO_STR
1727 "Delete a pseudo vrf's configuration\n"
1730 DEFUNSH(VTYSH_NS
, vtysh_exit_ns
, vtysh_exit_ns_cmd
, "exit",
1731 "Exit current mode and down to previous mode\n")
1733 return vtysh_exit(vty
);
1736 DEFUNSH(VTYSH_NS
, vtysh_quit_ns
, vtysh_quit_ns_cmd
, "quit",
1737 "Exit current mode and down to previous mode\n")
1739 return vtysh_exit_ns(self
, vty
, argc
, argv
);
1742 DEFUNSH(VTYSH_VRF
, vtysh_exit_vrf
, vtysh_exit_vrf_cmd
, "exit",
1743 "Exit current mode and down to previous mode\n")
1745 return vtysh_exit(vty
);
1748 DEFUNSH(VTYSH_VRF
, vtysh_quit_vrf
, vtysh_quit_vrf_cmd
, "quit",
1749 "Exit current mode and down to previous mode\n")
1751 return vtysh_exit_vrf(self
, vty
, argc
, argv
);
1754 /* TODO Implement interface description commands in ripngd, ospf6d
1756 DEFSH(VTYSH_ZEBRA
| VTYSH_RIPD
| VTYSH_OSPFD
| VTYSH_EIGRPD
,
1757 vtysh_interface_desc_cmd
, "description LINE...",
1758 "Interface specific description\n"
1759 "Characters describing this interface\n")
1761 DEFSH(VTYSH_ZEBRA
| VTYSH_RIPD
| VTYSH_OSPFD
| VTYSH_EIGRPD
,
1762 vtysh_no_interface_desc_cmd
, "no description",
1763 NO_STR
"Interface specific description\n")
1765 DEFUNSH(VTYSH_INTERFACE
, vtysh_exit_interface
, vtysh_exit_interface_cmd
, "exit",
1766 "Exit current mode and down to previous mode\n")
1768 return vtysh_exit(vty
);
1771 DEFUNSH(VTYSH_INTERFACE
, vtysh_quit_interface
, vtysh_quit_interface_cmd
, "quit",
1772 "Exit current mode and down to previous mode\n")
1774 return vtysh_exit_interface(self
, vty
, argc
, argv
);
1777 DEFUN (vtysh_show_thread
,
1778 vtysh_show_thread_cmd
,
1779 "show thread cpu [FILTER]",
1781 "Thread information\n"
1782 "Thread CPU usage\n"
1783 "Display filter (rwtexb)\n")
1787 int ret
= CMD_SUCCESS
;
1790 const char *filter
=
1791 argv_find(argv
, argc
, "FILTER", &idx
) ? argv
[idx
]->arg
: "";
1793 snprintf(line
, sizeof(line
), "do show thread cpu %s\n", filter
);
1794 for (i
= 0; i
< array_size(vtysh_client
); i
++)
1795 if (vtysh_client
[i
].fd
>= 0) {
1796 fprintf(stdout
, "Thread statistics for %s:\n",
1797 vtysh_client
[i
].name
);
1798 ret
= vtysh_client_execute(&vtysh_client
[i
], line
,
1800 fprintf(stdout
, "\n");
1805 DEFUN (vtysh_show_work_queues
,
1806 vtysh_show_work_queues_cmd
,
1809 "Work Queue information\n")
1812 int ret
= CMD_SUCCESS
;
1813 char line
[] = "do show work-queues\n";
1815 for (i
= 0; i
< array_size(vtysh_client
); i
++)
1816 if (vtysh_client
[i
].fd
>= 0) {
1817 fprintf(stdout
, "Work queue statistics for %s:\n",
1818 vtysh_client
[i
].name
);
1819 ret
= vtysh_client_execute(&vtysh_client
[i
], line
,
1821 fprintf(stdout
, "\n");
1827 DEFUN (vtysh_show_work_queues_daemon
,
1828 vtysh_show_work_queues_daemon_cmd
,
1829 "show work-queues <zebra|ripd|ripngd|ospfd|ospf6d|bgpd|isisd>",
1831 "Work Queue information\n"
1832 "For the zebra daemon\n"
1833 "For the rip daemon\n"
1834 "For the ripng daemon\n"
1835 "For the ospf daemon\n"
1836 "For the ospfv6 daemon\n"
1837 "For the bgp daemon\n"
1838 "For the isis daemon\n")
1840 int idx_protocol
= 2;
1842 int ret
= CMD_SUCCESS
;
1844 for (i
= 0; i
< array_size(vtysh_client
); i
++) {
1845 if (strmatch(vtysh_client
[i
].name
, argv
[idx_protocol
]->text
))
1849 ret
= vtysh_client_execute(&vtysh_client
[i
], "show work-queues\n",
1855 DEFUN (vtysh_show_hashtable
,
1856 vtysh_show_hashtable_cmd
,
1857 "show hashtable [statistics]",
1859 "Statistics about hash tables\n"
1860 "Statistics about hash tables\n")
1862 char cmd
[] = "do show hashtable statistics";
1864 int ret
= CMD_SUCCESS
;
1866 fprintf(stdout
, "\n");
1868 "Load factor (LF) - average number of elements across all buckets\n");
1870 "Full load factor (FLF) - average number of elements across full buckets\n\n");
1873 "Standard deviation (SD) is calculated for both the LF and FLF\n");
1875 "and indicates the typical deviation of bucket chain length\n");
1876 fprintf(stdout
, "from the value in the corresponding load factor.\n\n");
1878 for (i
= 0; i
< array_size(vtysh_client
); i
++)
1879 if (vtysh_client
[i
].fd
>= 0) {
1880 ret
= vtysh_client_execute(&vtysh_client
[i
], cmd
,
1882 fprintf(stdout
, "\n");
1887 DEFUNSH(VTYSH_ZEBRA
, vtysh_link_params
, vtysh_link_params_cmd
, "link-params",
1890 vty
->node
= LINK_PARAMS_NODE
;
1894 DEFUNSH(VTYSH_ZEBRA
, exit_link_params
, exit_link_params_cmd
, "exit-link-params",
1895 "Exit from Link Params configuration node\n")
1897 if (vty
->node
== LINK_PARAMS_NODE
)
1898 vty
->node
= INTERFACE_NODE
;
1902 static int show_per_daemon(const char *line
, const char *headline
)
1905 int ret
= CMD_SUCCESS
;
1907 for (i
= 0; i
< array_size(vtysh_client
); i
++)
1908 if (vtysh_client
[i
].fd
>= 0) {
1909 fprintf(stdout
, headline
, vtysh_client
[i
].name
);
1910 ret
= vtysh_client_execute(&vtysh_client
[i
], line
,
1912 fprintf(stdout
, "\n");
1918 DEFUN (vtysh_show_debugging
,
1919 vtysh_show_debugging_cmd
,
1924 return show_per_daemon("do show debugging\n",
1925 "Debugging Information for %s:\n");
1928 DEFUN (vtysh_show_debugging_hashtable
,
1929 vtysh_show_debugging_hashtable_cmd
,
1930 "show debugging hashtable [statistics]",
1933 "Statistics about hash tables\n"
1934 "Statistics about hash tables\n")
1936 return show_per_daemon("do show debugging hashtable\n",
1937 "Hashtable statistics for %s:\n");
1941 DEFUN (vtysh_show_memory
,
1942 vtysh_show_memory_cmd
,
1945 "Memory statistics\n")
1947 return show_per_daemon("show memory\n",
1948 "Memory statistics for %s:\n");
1951 DEFUN (vtysh_show_modules
,
1952 vtysh_show_modules_cmd
,
1957 return show_per_daemon("show modules\n",
1958 "Module information for %s:\n");
1961 /* Logging commands. */
1962 DEFUN (vtysh_show_logging
,
1963 vtysh_show_logging_cmd
,
1966 "Show current logging configuration\n")
1968 return show_per_daemon("do show logging\n",
1969 "Logging configuration for %s:\n");
1972 DEFUNSH(VTYSH_ALL
, vtysh_log_stdout
, vtysh_log_stdout_cmd
, "log stdout",
1974 "Set stdout logging level\n")
1979 DEFUNSH(VTYSH_ALL
, vtysh_log_stdout_level
, vtysh_log_stdout_level_cmd
,
1980 "log stdout <emergencies|alerts|critical|errors|warnings|notifications|informational|debugging>",
1982 "Set stdout logging level\n" LOG_LEVEL_DESC
)
1987 DEFUNSH(VTYSH_ALL
, no_vtysh_log_stdout
, no_vtysh_log_stdout_cmd
,
1988 "no log stdout [LEVEL]", NO_STR
1990 "Cancel logging to stdout\n"
1996 DEFUNSH(VTYSH_ALL
, vtysh_log_file
, vtysh_log_file_cmd
, "log file FILENAME",
1999 "Logging filename\n")
2004 DEFUNSH(VTYSH_ALL
, vtysh_log_file_level
, vtysh_log_file_level_cmd
,
2005 "log file FILENAME <emergencies|alerts|critical|errors|warnings|notifications|informational|debugging>",
2008 "Logging filename\n" LOG_LEVEL_DESC
)
2013 DEFUNSH(VTYSH_ALL
, no_vtysh_log_file
, no_vtysh_log_file_cmd
,
2014 "no log file [FILENAME [LEVEL]]", NO_STR
2016 "Cancel logging to file\n"
2017 "Logging file name\n"
2023 DEFUNSH(VTYSH_ALL
, vtysh_log_monitor
, vtysh_log_monitor_cmd
,
2024 "log monitor [<emergencies|alerts|critical|errors|warnings|notifications|informational|debugging>]",
2026 "Set terminal line (monitor) logging level\n" LOG_LEVEL_DESC
)
2031 DEFUNSH(VTYSH_ALL
, no_vtysh_log_monitor
, no_vtysh_log_monitor_cmd
,
2032 "no log monitor [LEVEL]", NO_STR
2034 "Disable terminal line (monitor) logging\n"
2040 DEFUNSH(VTYSH_ALL
, vtysh_log_syslog
, vtysh_log_syslog_cmd
,
2041 "log syslog [<emergencies|alerts|critical|errors|warnings|notifications|informational|debugging>]",
2043 "Set syslog logging level\n" LOG_LEVEL_DESC
)
2048 DEFUNSH(VTYSH_ALL
, no_vtysh_log_syslog
, no_vtysh_log_syslog_cmd
,
2049 "no log syslog [LEVEL]", NO_STR
2051 "Cancel logging to syslog\n"
2057 DEFUNSH(VTYSH_ALL
, vtysh_log_facility
, vtysh_log_facility_cmd
,
2058 "log facility <kern|user|mail|daemon|auth|syslog|lpr|news|uucp|cron|local0|local1|local2|local3|local4|local5|local6|local7>",
2060 "Facility parameter for syslog messages\n" LOG_FACILITY_DESC
)
2066 DEFUNSH(VTYSH_ALL
, no_vtysh_log_facility
, no_vtysh_log_facility_cmd
,
2067 "no log facility [FACILITY]", NO_STR
2069 "Reset syslog facility to default (daemon)\n"
2070 "Syslog facility\n")
2077 VTYSH_ALL
, vtysh_log_trap
, vtysh_log_trap_cmd
,
2078 "log trap <emergencies|alerts|critical|errors|warnings|notifications|informational|debugging>",
2080 "(Deprecated) Set logging level and default for all destinations\n" LOG_LEVEL_DESC
)
2086 DEFUNSH_DEPRECATED(VTYSH_ALL
, no_vtysh_log_trap
, no_vtysh_log_trap_cmd
,
2087 "no log trap [LEVEL]", NO_STR
2089 "Permit all logging information\n"
2095 DEFUNSH(VTYSH_ALL
, vtysh_log_record_priority
, vtysh_log_record_priority_cmd
,
2096 "log record-priority",
2098 "Log the priority of the message within the message\n")
2103 DEFUNSH(VTYSH_ALL
, no_vtysh_log_record_priority
,
2104 no_vtysh_log_record_priority_cmd
, "no log record-priority", NO_STR
2106 "Do not log the priority of the message within the message\n")
2111 DEFUNSH(VTYSH_ALL
, vtysh_log_timestamp_precision
,
2112 vtysh_log_timestamp_precision_cmd
, "log timestamp precision (0-6)",
2114 "Timestamp configuration\n"
2115 "Set the timestamp precision\n"
2116 "Number of subsecond digits\n")
2121 DEFUNSH(VTYSH_ALL
, no_vtysh_log_timestamp_precision
,
2122 no_vtysh_log_timestamp_precision_cmd
, "no log timestamp precision",
2125 "Timestamp configuration\n"
2126 "Reset the timestamp precision to the default value of 0\n")
2131 DEFUNSH(VTYSH_ALL
, vtysh_service_password_encrypt
,
2132 vtysh_service_password_encrypt_cmd
, "service password-encryption",
2133 "Set up miscellaneous service\n"
2134 "Enable encrypted passwords\n")
2139 DEFUNSH(VTYSH_ALL
, no_vtysh_service_password_encrypt
,
2140 no_vtysh_service_password_encrypt_cmd
, "no service password-encryption",
2142 "Set up miscellaneous service\n"
2143 "Enable encrypted passwords\n")
2148 DEFUNSH(VTYSH_ALL
, vtysh_config_password
, vtysh_password_cmd
,
2149 "password [(8-8)] LINE",
2150 "Assign the terminal connection password\n"
2151 "Specifies a HIDDEN password will follow\n"
2152 "The password string\n")
2157 DEFUNSH(VTYSH_ALL
, vtysh_config_enable_password
, vtysh_enable_password_cmd
,
2158 "enable password [(8-8)] LINE",
2159 "Modify enable password parameters\n"
2160 "Assign the privileged level password\n"
2161 "Specifies a HIDDEN password will follow\n"
2162 "The 'enable' password string\n")
2167 DEFUNSH(VTYSH_ALL
, no_vtysh_config_enable_password
,
2168 no_vtysh_enable_password_cmd
, "no enable password", NO_STR
2169 "Modify enable password parameters\n"
2170 "Assign the privileged level password\n")
2175 DEFUN (vtysh_write_terminal
,
2176 vtysh_write_terminal_cmd
,
2177 "write terminal [<zebra|ripd|ripngd|ospfd|ospf6d|ldpd|bgpd|isisd|pimd>]",
2178 "Write running configuration to memory, network, or terminal\n"
2179 "Write to terminal\n"
2180 "For the zebra daemon\n"
2181 "For the rip daemon\n"
2182 "For the ripng daemon\n"
2183 "For the ospf daemon\n"
2184 "For the ospfv6 daemon\n"
2185 "For the ldpd daemon\n"
2186 "For the bgp daemon\n"
2187 "For the isis daemon\n"
2188 "For the pim daemon\n")
2191 char line
[] = "do write terminal\n";
2194 if (vtysh_pager_name
) {
2195 fp
= popen(vtysh_pager_name
, "w");
2203 vty_out(vty
, "Building configuration...\n");
2204 vty_out(vty
, "\nCurrent configuration:\n");
2205 vty_out(vty
, "!\n");
2207 for (i
= 0; i
< array_size(vtysh_client
); i
++)
2209 || (strmatch(vtysh_client
[i
].name
, argv
[2]->text
)))
2210 vtysh_client_config(&vtysh_client
[i
], line
);
2212 /* Integrate vtysh specific configuration. */
2213 vtysh_config_write();
2215 vtysh_config_dump(fp
);
2217 if (vtysh_pager_name
&& fp
) {
2219 if (pclose(fp
) == -1) {
2226 vty_out(vty
, "end\n");
2230 DEFUN (vtysh_show_running_config
,
2231 vtysh_show_running_config_cmd
,
2232 "show running-config [<zebra|ripd|ripngd|ospfd|ospf6d|ldpd|bgpd|isisd|pimd>]",
2234 "Current operating configuration\n"
2235 "For the zebra daemon\n"
2236 "For the rip daemon\n"
2237 "For the ripng daemon\n"
2238 "For the ospf daemon\n"
2239 "For the ospfv6 daemon\n"
2240 "For the ldp daemon\n"
2241 "For the bgp daemon\n"
2242 "For the isis daemon\n"
2243 "For the pim daemon\n")
2245 return vtysh_write_terminal(self
, vty
, argc
, argv
);
2248 DEFUN (vtysh_integrated_config
,
2249 vtysh_integrated_config_cmd
,
2250 "service integrated-vtysh-config",
2251 "Set up miscellaneous service\n"
2252 "Write configuration into integrated file\n")
2254 vtysh_write_integrated
= WRITE_INTEGRATED_YES
;
2258 DEFUN (no_vtysh_integrated_config
,
2259 no_vtysh_integrated_config_cmd
,
2260 "no service integrated-vtysh-config",
2262 "Set up miscellaneous service\n"
2263 "Write configuration into integrated file\n")
2265 vtysh_write_integrated
= WRITE_INTEGRATED_NO
;
2269 static void backup_config_file(const char *fbackup
)
2271 char *integrate_sav
= NULL
;
2273 integrate_sav
= malloc(strlen(fbackup
) + strlen(CONF_BACKUP_EXT
) + 1);
2274 strcpy(integrate_sav
, fbackup
);
2275 strcat(integrate_sav
, CONF_BACKUP_EXT
);
2277 /* Move current configuration file to backup config file. */
2278 unlink(integrate_sav
);
2279 rename(fbackup
, integrate_sav
);
2280 free(integrate_sav
);
2283 int vtysh_write_config_integrated(void)
2286 char line
[] = "do write terminal\n";
2289 struct passwd
*pwentry
;
2290 struct group
*grentry
;
2296 fprintf(stdout
, "Building Configuration...\n");
2298 backup_config_file(quagga_config
);
2299 fp
= fopen(quagga_config
, "w");
2302 "%% Error: failed to open configuration file %s: %s\n",
2303 quagga_config
, safe_strerror(errno
));
2304 return CMD_WARNING_CONFIG_FAILED
;
2308 for (i
= 0; i
< array_size(vtysh_client
); i
++)
2309 vtysh_client_config(&vtysh_client
[i
], line
);
2311 vtysh_config_write();
2312 vtysh_config_dump(fp
);
2314 if (fchmod(fd
, CONFIGFILE_MASK
) != 0) {
2315 printf("%% Warning: can't chmod configuration file %s: %s\n",
2316 quagga_config
, safe_strerror(errno
));
2321 pwentry
= getpwnam(FRR_USER
);
2323 uid
= pwentry
->pw_uid
;
2325 printf("%% Warning: could not look up user \"%s\"\n", FRR_USER
);
2330 grentry
= getgrnam(FRR_GROUP
);
2332 gid
= grentry
->gr_gid
;
2334 printf("%% Warning: could not look up group \"%s\"\n",
2340 if (!fstat(fd
, &st
)) {
2341 if (st
.st_uid
== uid
)
2343 if (st
.st_gid
== gid
)
2345 if ((uid
!= (uid_t
)-1 || gid
!= (gid_t
)-1)
2346 && fchown(fd
, uid
, gid
)) {
2347 printf("%% Warning: can't chown configuration file %s: %s\n",
2348 quagga_config
, safe_strerror(errno
));
2352 printf("%% Warning: stat() failed on %s: %s\n", quagga_config
,
2353 safe_strerror(errno
));
2359 printf("Integrated configuration saved to %s\n", quagga_config
);
2367 static bool want_config_integrated(void)
2371 switch (vtysh_write_integrated
) {
2372 case WRITE_INTEGRATED_UNSPECIFIED
:
2373 if (stat(quagga_config
, &s
) && errno
== ENOENT
)
2376 case WRITE_INTEGRATED_NO
:
2378 case WRITE_INTEGRATED_YES
:
2384 DEFUN (vtysh_write_memory
,
2385 vtysh_write_memory_cmd
,
2386 "write [<memory|file>]",
2387 "Write running configuration to memory, network, or terminal\n"
2388 "Write configuration to the file (same as write file)\n"
2389 "Write configuration to the file (same as write memory)\n")
2391 int ret
= CMD_SUCCESS
;
2392 char line
[] = "do write memory\n";
2396 "Note: this version of vtysh never writes vtysh.conf\n");
2398 /* If integrated frr.conf explicitely set. */
2399 if (want_config_integrated()) {
2400 ret
= CMD_WARNING_CONFIG_FAILED
;
2401 for (i
= 0; i
< array_size(vtysh_client
); i
++)
2402 if (vtysh_client
[i
].flag
== VTYSH_WATCHFRR
)
2404 if (i
< array_size(vtysh_client
) && vtysh_client
[i
].fd
!= -1)
2405 ret
= vtysh_client_execute(&vtysh_client
[i
],
2406 "do write integrated",
2409 if (ret
!= CMD_SUCCESS
) {
2410 printf("\nWarning: attempting direct configuration write without "
2411 "watchfrr.\nFile permissions and ownership may be "
2412 "incorrect, or write may fail.\n\n");
2413 ret
= vtysh_write_config_integrated();
2418 fprintf(stdout
, "Building Configuration...\n");
2420 for (i
= 0; i
< array_size(vtysh_client
); i
++)
2421 ret
= vtysh_client_execute(&vtysh_client
[i
], line
, stdout
);
2426 DEFUN (vtysh_copy_running_config
,
2427 vtysh_copy_running_config_cmd
,
2428 "copy running-config startup-config",
2429 "Copy from one file to another\n"
2430 "Copy from current system configuration\n"
2431 "Copy to startup configuration\n")
2433 return vtysh_write_memory(self
, vty
, argc
, argv
);
2436 DEFUN (vtysh_terminal_length
,
2437 vtysh_terminal_length_cmd
,
2438 "terminal length (0-512)",
2439 "Set terminal line parameters\n"
2440 "Set number of lines on a screen\n"
2441 "Number of lines on screen (0 for no pausing)\n")
2445 char *endptr
= NULL
;
2446 char default_pager
[10];
2448 lines
= strtol(argv
[idx_number
]->arg
, &endptr
, 10);
2449 if (lines
< 0 || lines
> 512 || *endptr
!= '\0') {
2450 vty_out(vty
, "length is malformed\n");
2454 if (vtysh_pager_name
) {
2455 free(vtysh_pager_name
);
2456 vtysh_pager_name
= NULL
;
2460 snprintf(default_pager
, 10, "more -%i", lines
);
2461 vtysh_pager_name
= strdup(default_pager
);
2467 DEFUN (vtysh_terminal_no_length
,
2468 vtysh_terminal_no_length_cmd
,
2469 "terminal no length",
2470 "Set terminal line parameters\n"
2472 "Set number of lines on a screen\n")
2474 if (vtysh_pager_name
) {
2475 free(vtysh_pager_name
);
2476 vtysh_pager_name
= NULL
;
2483 DEFUN (vtysh_show_daemons
,
2484 vtysh_show_daemons_cmd
,
2487 "Show list of running daemons\n")
2491 for (i
= 0; i
< array_size(vtysh_client
); i
++)
2492 if (vtysh_client
[i
].fd
>= 0)
2493 vty_out(vty
, " %s", vtysh_client
[i
].name
);
2499 /* Execute command in child process. */
2500 static void execute_command(const char *command
, int argc
,
2501 const char *arg1
, const char *arg2
)
2510 /* Failure of fork(). */
2511 fprintf(stderr
, "Can't fork: %s\n", safe_strerror(errno
));
2513 } else if (pid
== 0) {
2514 /* This is child process. */
2517 execlp(command
, command
, (const char *)NULL
);
2520 execlp(command
, command
, arg1
, (const char *)NULL
);
2523 execlp(command
, command
, arg1
, arg2
,
2524 (const char *)NULL
);
2528 /* When execlp suceed, this part is not executed. */
2529 fprintf(stderr
, "Can't execute %s: %s\n", command
,
2530 safe_strerror(errno
));
2533 /* This is parent. */
2535 wait4(pid
, &status
, 0, NULL
);
2543 "Send echo messages\n"
2544 "Ping destination address or hostname\n")
2548 argv_find(argv
, argc
, "WORD", &idx
);
2549 execute_command("ping", 1, argv
[idx
]->arg
, NULL
);
2553 ALIAS(vtysh_ping
, vtysh_ping_ip_cmd
, "ping ip WORD",
2554 "Send echo messages\n"
2556 "Ping destination address or hostname\n")
2558 DEFUN (vtysh_traceroute
,
2559 vtysh_traceroute_cmd
,
2561 "Trace route to destination\n"
2562 "Trace route to destination address or hostname\n")
2566 argv_find(argv
, argc
, "WORD", &idx
);
2567 execute_command("traceroute", 1, argv
[idx
]->arg
, NULL
);
2571 ALIAS(vtysh_traceroute
, vtysh_traceroute_ip_cmd
, "traceroute ip WORD",
2572 "Trace route to destination\n"
2574 "Trace route to destination address or hostname\n")
2579 "Send echo messages\n"
2581 "Ping destination address or hostname\n")
2583 execute_command("ping6", 1, argv
[2]->arg
, NULL
);
2587 DEFUN (vtysh_traceroute6
,
2588 vtysh_traceroute6_cmd
,
2589 "traceroute ipv6 WORD",
2590 "Trace route to destination\n"
2592 "Trace route to destination address or hostname\n")
2594 execute_command("traceroute6", 1, argv
[2]->arg
, NULL
);
2598 #if defined(HAVE_SHELL_ACCESS)
2599 DEFUN (vtysh_telnet
,
2602 "Open a telnet connection\n"
2603 "IP address or hostname of a remote system\n")
2605 execute_command("telnet", 1, argv
[1]->arg
, NULL
);
2609 DEFUN (vtysh_telnet_port
,
2610 vtysh_telnet_port_cmd
,
2612 "Open a telnet connection\n"
2613 "IP address or hostname of a remote system\n"
2614 "TCP Port number\n")
2616 execute_command("telnet", 2, argv
[1]->arg
, argv
[2]->arg
);
2623 "Open an ssh connection\n"
2626 execute_command("ssh", 1, argv
[1]->arg
, NULL
);
2630 DEFUN (vtysh_start_shell
,
2631 vtysh_start_shell_cmd
,
2633 "Start UNIX shell\n")
2635 execute_command("sh", 0, NULL
, NULL
);
2639 DEFUN (vtysh_start_bash
,
2640 vtysh_start_bash_cmd
,
2642 "Start UNIX shell\n"
2645 execute_command("bash", 0, NULL
, NULL
);
2649 DEFUN (vtysh_start_zsh
,
2650 vtysh_start_zsh_cmd
,
2652 "Start UNIX shell\n"
2655 execute_command("zsh", 0, NULL
, NULL
);
2662 "list [permutations]",
2663 "Print command list\n"
2664 "Print all possible command permutations\n")
2666 return cmd_list_cmds(vty
, argc
== 2);
2672 "Find CLI command containing text\n"
2673 "Text to search for\n")
2675 char *text
= argv_concat(argv
, argc
, 1);
2676 const struct cmd_node
*node
;
2677 const struct cmd_element
*cli
;
2680 for (unsigned int i
= 0; i
< vector_active(cmdvec
); i
++) {
2681 node
= vector_slot(cmdvec
, i
);
2684 clis
= node
->cmd_vector
;
2685 for (unsigned int j
= 0; j
< vector_active(clis
); j
++) {
2686 cli
= vector_slot(clis
, j
);
2687 if (strcasestr(cli
->string
, text
))
2688 fprintf(stdout
, " (%s) %s\n",
2689 node_names
[node
->node
], cli
->string
);
2693 XFREE(MTYPE_TMP
, text
);
2698 static void vtysh_install_default(enum node_type node
)
2700 install_element(node
, &config_list_cmd
);
2701 install_element(node
, &find_cmd
);
2704 /* Making connection to protocol daemon. */
2705 static int vtysh_connect(struct vtysh_client
*vclient
)
2709 struct sockaddr_un addr
;
2713 if (!vclient
->path
[0])
2714 snprintf(vclient
->path
, sizeof(vclient
->path
), "%s/%s.vty",
2715 vty_sock_path
, vclient
->name
);
2716 path
= vclient
->path
;
2718 /* Stat socket to see if we have permission to access it. */
2719 ret
= stat(path
, &s_stat
);
2720 if (ret
< 0 && errno
!= ENOENT
) {
2721 fprintf(stderr
, "vtysh_connect(%s): stat = %s\n", path
,
2722 safe_strerror(errno
));
2727 if (!S_ISSOCK(s_stat
.st_mode
)) {
2728 fprintf(stderr
, "vtysh_connect(%s): Not a socket\n",
2734 sock
= socket(AF_UNIX
, SOCK_STREAM
, 0);
2737 fprintf(stderr
, "vtysh_connect(%s): socket = %s\n", path
,
2738 safe_strerror(errno
));
2743 memset(&addr
, 0, sizeof(struct sockaddr_un
));
2744 addr
.sun_family
= AF_UNIX
;
2745 strlcpy(addr
.sun_path
, path
, sizeof(addr
.sun_path
));
2746 #ifdef HAVE_STRUCT_SOCKADDR_UN_SUN_LEN
2747 len
= addr
.sun_len
= SUN_LEN(&addr
);
2749 len
= sizeof(addr
.sun_family
) + strlen(addr
.sun_path
);
2750 #endif /* HAVE_STRUCT_SOCKADDR_UN_SUN_LEN */
2752 ret
= connect(sock
, (struct sockaddr
*)&addr
, len
);
2755 fprintf(stderr
, "vtysh_connect(%s): connect = %s\n", path
,
2756 safe_strerror(errno
));
2766 /* Return true if str ends with suffix, else return false */
2767 static int ends_with(const char *str
, const char *suffix
)
2769 if (!str
|| !suffix
)
2771 size_t lenstr
= strlen(str
);
2772 size_t lensuffix
= strlen(suffix
);
2773 if (lensuffix
> lenstr
)
2775 return strncmp(str
+ lenstr
- lensuffix
, suffix
, lensuffix
) == 0;
2778 static void vtysh_client_sorted_insert(struct vtysh_client
*head_client
,
2779 struct vtysh_client
*client
)
2781 struct vtysh_client
*prev_node
, *current_node
;
2783 prev_node
= head_client
;
2784 current_node
= head_client
->next
;
2785 while (current_node
) {
2786 if (strcmp(current_node
->path
, client
->path
) > 0)
2789 prev_node
= current_node
;
2790 current_node
= current_node
->next
;
2792 client
->next
= current_node
;
2793 prev_node
->next
= client
;
2796 #define MAXIMUM_INSTANCES 10
2798 static void vtysh_update_all_insances(struct vtysh_client
*head_client
)
2800 struct vtysh_client
*client
;
2802 struct dirent
*file
;
2805 if (head_client
->flag
!= VTYSH_OSPFD
)
2808 /* ls vty_sock_dir and look for all files ending in .vty */
2809 dir
= opendir(vty_sock_path
);
2811 while ((file
= readdir(dir
)) != NULL
) {
2812 if (begins_with(file
->d_name
, "ospfd-")
2813 && ends_with(file
->d_name
, ".vty")) {
2814 if (n
== MAXIMUM_INSTANCES
) {
2816 "Parsing %s, client limit(%d) reached!\n",
2820 client
= (struct vtysh_client
*)malloc(
2821 sizeof(struct vtysh_client
));
2823 client
->name
= "ospfd";
2824 client
->flag
= VTYSH_OSPFD
;
2825 snprintf(client
->path
, sizeof(client
->path
),
2826 "%s/%s", vty_sock_path
, file
->d_name
);
2827 client
->next
= NULL
;
2828 vtysh_client_sorted_insert(head_client
, client
);
2836 static int vtysh_connect_all_instances(struct vtysh_client
*head_client
)
2838 struct vtysh_client
*client
;
2841 vtysh_update_all_insances(head_client
);
2843 client
= head_client
->next
;
2845 if (vtysh_connect(client
) == 0)
2847 client
= client
->next
;
2853 int vtysh_connect_all(const char *daemon_name
)
2859 for (i
= 0; i
< array_size(vtysh_client
); i
++) {
2861 || !strcmp(daemon_name
, vtysh_client
[i
].name
)) {
2863 if (vtysh_connect(&vtysh_client
[i
]) == 0)
2866 rc
+= vtysh_connect_all_instances(&vtysh_client
[i
]);
2870 fprintf(stderr
, "Error: no daemons match name %s!\n",
2875 /* To disable readline's filename completion. */
2876 static char *vtysh_completion_entry_function(const char *ignore
,
2882 void vtysh_readline_init(void)
2884 /* readline related settings. */
2886 rl_bind_key('?', (rl_command_func_t
*)vtysh_rl_describe
);
2887 rl_completion_entry_function
= vtysh_completion_entry_function
;
2888 rl_attempted_completion_function
=
2889 (rl_completion_func_t
*)new_completion
;
2892 char *vtysh_prompt(void)
2894 static struct utsname names
;
2895 static char buf
[100];
2896 const char *hostname
;
2897 extern struct host host
;
2899 hostname
= host
.name
;
2902 if (!names
.nodename
[0])
2904 hostname
= names
.nodename
;
2907 snprintf(buf
, sizeof buf
, cmd_prompt(vty
->node
), hostname
);
2912 static void vtysh_ac_line(void *arg
, const char *line
)
2916 for (i
= 0; i
< vector_active(comps
); i
++)
2917 if (!strcmp(line
, (char *)vector_slot(comps
, i
)))
2919 vector_set(comps
, XSTRDUP(MTYPE_COMPLETION
, line
));
2922 static void vtysh_autocomplete(vector comps
, struct cmd_token
*token
)
2927 snprintf(accmd
, sizeof(accmd
), "autocomplete %d %s %s", token
->type
,
2928 token
->text
, token
->varname
? token
->varname
: "-");
2930 for (i
= 0; i
< array_size(vtysh_client
); i
++)
2931 vtysh_client_run_all(&vtysh_client
[i
], accmd
, 1, NULL
,
2932 vtysh_ac_line
, comps
);
2935 static const struct cmd_variable_handler vtysh_var_handler
[] = {
2939 .completions
= vtysh_autocomplete
},
2940 {.completions
= NULL
}};
2942 void vtysh_init_vty(void)
2944 /* Make vty structure. */
2946 vty
->type
= VTY_SHELL
;
2947 vty
->node
= VIEW_NODE
;
2949 /* Initialize commands. */
2951 cmd_variable_handler_register(vtysh_var_handler
);
2953 /* Install nodes. */
2954 install_node(&bgp_node
, NULL
);
2955 install_node(&rip_node
, NULL
);
2956 install_node(&interface_node
, NULL
);
2957 install_node(&pw_node
, NULL
);
2958 install_node(&link_params_node
, NULL
);
2959 install_node(&ns_node
, NULL
);
2960 install_node(&vrf_node
, NULL
);
2961 install_node(&rmap_node
, NULL
);
2962 install_node(&zebra_node
, NULL
);
2963 install_node(&bgp_vpnv4_node
, NULL
);
2964 install_node(&bgp_vpnv6_node
, NULL
);
2965 install_node(&bgp_ipv4_node
, NULL
);
2966 install_node(&bgp_ipv4m_node
, NULL
);
2967 install_node(&bgp_ipv4l_node
, NULL
);
2968 install_node(&bgp_ipv6_node
, NULL
);
2969 install_node(&bgp_ipv6m_node
, NULL
);
2970 install_node(&bgp_ipv6l_node
, NULL
);
2971 install_node(&bgp_vrf_policy_node
, NULL
);
2972 install_node(&bgp_evpn_node
, NULL
);
2973 install_node(&bgp_evpn_vni_node
, NULL
);
2974 install_node(&bgp_vnc_defaults_node
, NULL
);
2975 install_node(&bgp_vnc_nve_group_node
, NULL
);
2976 install_node(&bgp_vnc_l2_group_node
, NULL
);
2977 install_node(&ospf_node
, NULL
);
2978 install_node(&eigrp_node
, NULL
);
2979 install_node(&babel_node
, NULL
);
2980 install_node(&ripng_node
, NULL
);
2981 install_node(&ospf6_node
, NULL
);
2982 install_node(&ldp_node
, NULL
);
2983 install_node(&ldp_ipv4_node
, NULL
);
2984 install_node(&ldp_ipv6_node
, NULL
);
2985 install_node(&ldp_ipv4_iface_node
, NULL
);
2986 install_node(&ldp_ipv6_iface_node
, NULL
);
2987 install_node(&ldp_l2vpn_node
, NULL
);
2988 install_node(&ldp_pseudowire_node
, NULL
);
2989 install_node(&keychain_node
, NULL
);
2990 install_node(&keychain_key_node
, NULL
);
2991 install_node(&isis_node
, NULL
);
2992 install_node(&vty_node
, NULL
);
2994 struct cmd_node
*node
;
2995 for (unsigned int i
= 0; i
< vector_active(cmdvec
); i
++) {
2996 node
= vector_slot(cmdvec
, i
);
2997 if (!node
|| node
->node
== VIEW_NODE
)
2999 vtysh_install_default(node
->node
);
3002 install_element(VIEW_NODE
, &vtysh_enable_cmd
);
3003 install_element(ENABLE_NODE
, &vtysh_config_terminal_cmd
);
3004 install_element(ENABLE_NODE
, &vtysh_disable_cmd
);
3006 /* "exit" command. */
3007 install_element(VIEW_NODE
, &vtysh_exit_all_cmd
);
3008 install_element(CONFIG_NODE
, &vtysh_exit_all_cmd
);
3009 install_element(VIEW_NODE
, &vtysh_quit_all_cmd
);
3010 install_element(CONFIG_NODE
, &vtysh_quit_all_cmd
);
3011 install_element(RIP_NODE
, &vtysh_exit_ripd_cmd
);
3012 install_element(RIP_NODE
, &vtysh_quit_ripd_cmd
);
3013 install_element(RIPNG_NODE
, &vtysh_exit_ripngd_cmd
);
3014 install_element(RIPNG_NODE
, &vtysh_quit_ripngd_cmd
);
3015 install_element(OSPF_NODE
, &vtysh_exit_ospfd_cmd
);
3016 install_element(OSPF_NODE
, &vtysh_quit_ospfd_cmd
);
3017 install_element(EIGRP_NODE
, &vtysh_exit_eigrpd_cmd
);
3018 install_element(EIGRP_NODE
, &vtysh_quit_eigrpd_cmd
);
3019 install_element(BABEL_NODE
, &vtysh_exit_babeld_cmd
);
3020 install_element(BABEL_NODE
, &vtysh_quit_babeld_cmd
);
3021 install_element(OSPF6_NODE
, &vtysh_exit_ospf6d_cmd
);
3022 install_element(OSPF6_NODE
, &vtysh_quit_ospf6d_cmd
);
3023 #if defined(HAVE_LDPD)
3024 install_element(LDP_NODE
, &vtysh_exit_ldpd_cmd
);
3025 install_element(LDP_NODE
, &vtysh_quit_ldpd_cmd
);
3026 install_element(LDP_IPV4_NODE
, &vtysh_exit_ldpd_cmd
);
3027 install_element(LDP_IPV4_NODE
, &vtysh_quit_ldpd_cmd
);
3028 install_element(LDP_IPV4_NODE
, &ldp_exit_address_family_cmd
);
3029 install_element(LDP_IPV6_NODE
, &vtysh_exit_ldpd_cmd
);
3030 install_element(LDP_IPV6_NODE
, &vtysh_quit_ldpd_cmd
);
3031 install_element(LDP_IPV6_NODE
, &ldp_exit_address_family_cmd
);
3032 install_element(LDP_IPV4_IFACE_NODE
, &vtysh_exit_ldpd_cmd
);
3033 install_element(LDP_IPV4_IFACE_NODE
, &vtysh_quit_ldpd_cmd
);
3034 install_element(LDP_IPV6_IFACE_NODE
, &vtysh_exit_ldpd_cmd
);
3035 install_element(LDP_IPV6_IFACE_NODE
, &vtysh_quit_ldpd_cmd
);
3036 install_element(LDP_L2VPN_NODE
, &vtysh_exit_ldpd_cmd
);
3037 install_element(LDP_L2VPN_NODE
, &vtysh_quit_ldpd_cmd
);
3038 install_element(LDP_PSEUDOWIRE_NODE
, &vtysh_exit_ldpd_cmd
);
3039 install_element(LDP_PSEUDOWIRE_NODE
, &vtysh_quit_ldpd_cmd
);
3041 install_element(BGP_NODE
, &vtysh_exit_bgpd_cmd
);
3042 install_element(BGP_NODE
, &vtysh_quit_bgpd_cmd
);
3043 install_element(BGP_VPNV4_NODE
, &vtysh_exit_bgpd_cmd
);
3044 install_element(BGP_VPNV4_NODE
, &vtysh_quit_bgpd_cmd
);
3045 install_element(BGP_VPNV6_NODE
, &vtysh_exit_bgpd_cmd
);
3046 install_element(BGP_VPNV6_NODE
, &vtysh_quit_bgpd_cmd
);
3047 install_element(BGP_IPV4_NODE
, &vtysh_exit_bgpd_cmd
);
3048 install_element(BGP_IPV4_NODE
, &vtysh_quit_bgpd_cmd
);
3049 install_element(BGP_IPV4M_NODE
, &vtysh_exit_bgpd_cmd
);
3050 install_element(BGP_IPV4M_NODE
, &vtysh_quit_bgpd_cmd
);
3051 install_element(BGP_IPV4L_NODE
, &vtysh_exit_bgpd_cmd
);
3052 install_element(BGP_IPV4L_NODE
, &vtysh_quit_bgpd_cmd
);
3053 install_element(BGP_IPV6_NODE
, &vtysh_exit_bgpd_cmd
);
3054 install_element(BGP_IPV6_NODE
, &vtysh_quit_bgpd_cmd
);
3055 install_element(BGP_IPV6M_NODE
, &vtysh_exit_bgpd_cmd
);
3056 install_element(BGP_IPV6M_NODE
, &vtysh_quit_bgpd_cmd
);
3057 install_element(BGP_EVPN_NODE
, &vtysh_quit_bgpd_cmd
);
3058 install_element(BGP_EVPN_NODE
, &vtysh_exit_bgpd_cmd
);
3059 install_element(BGP_EVPN_VNI_NODE
, &vtysh_exit_bgpd_cmd
);
3060 install_element(BGP_EVPN_VNI_NODE
, &vtysh_quit_bgpd_cmd
);
3061 install_element(BGP_IPV6L_NODE
, &vtysh_exit_bgpd_cmd
);
3062 install_element(BGP_IPV6L_NODE
, &vtysh_quit_bgpd_cmd
);
3063 #if defined(ENABLE_BGP_VNC)
3064 install_element(BGP_VRF_POLICY_NODE
, &vtysh_exit_bgpd_cmd
);
3065 install_element(BGP_VRF_POLICY_NODE
, &vtysh_quit_bgpd_cmd
);
3066 install_element(BGP_VNC_DEFAULTS_NODE
, &vtysh_exit_bgpd_cmd
);
3067 install_element(BGP_VNC_DEFAULTS_NODE
, &vtysh_quit_bgpd_cmd
);
3068 install_element(BGP_VNC_NVE_GROUP_NODE
, &vtysh_exit_bgpd_cmd
);
3069 install_element(BGP_VNC_NVE_GROUP_NODE
, &vtysh_quit_bgpd_cmd
);
3070 install_element(BGP_VNC_L2_GROUP_NODE
, &vtysh_exit_bgpd_cmd
);
3071 install_element(BGP_VNC_L2_GROUP_NODE
, &vtysh_quit_bgpd_cmd
);
3073 install_element(ISIS_NODE
, &vtysh_exit_isisd_cmd
);
3074 install_element(ISIS_NODE
, &vtysh_quit_isisd_cmd
);
3075 install_element(KEYCHAIN_NODE
, &vtysh_exit_ripd_cmd
);
3076 install_element(KEYCHAIN_NODE
, &vtysh_quit_ripd_cmd
);
3077 install_element(KEYCHAIN_KEY_NODE
, &vtysh_exit_ripd_cmd
);
3078 install_element(KEYCHAIN_KEY_NODE
, &vtysh_quit_ripd_cmd
);
3079 install_element(RMAP_NODE
, &vtysh_exit_rmap_cmd
);
3080 install_element(RMAP_NODE
, &vtysh_quit_rmap_cmd
);
3081 install_element(VTY_NODE
, &vtysh_exit_line_vty_cmd
);
3082 install_element(VTY_NODE
, &vtysh_quit_line_vty_cmd
);
3084 /* "end" command. */
3085 install_element(CONFIG_NODE
, &vtysh_end_all_cmd
);
3086 install_element(ENABLE_NODE
, &vtysh_end_all_cmd
);
3087 install_element(RIP_NODE
, &vtysh_end_all_cmd
);
3088 install_element(RIPNG_NODE
, &vtysh_end_all_cmd
);
3089 install_element(OSPF_NODE
, &vtysh_end_all_cmd
);
3090 install_element(EIGRP_NODE
, &vtysh_end_all_cmd
);
3091 install_element(BABEL_NODE
, &vtysh_end_all_cmd
);
3092 install_element(OSPF6_NODE
, &vtysh_end_all_cmd
);
3093 install_element(LDP_NODE
, &vtysh_end_all_cmd
);
3094 install_element(LDP_IPV4_NODE
, &vtysh_end_all_cmd
);
3095 install_element(LDP_IPV6_NODE
, &vtysh_end_all_cmd
);
3096 install_element(LDP_IPV4_IFACE_NODE
, &vtysh_end_all_cmd
);
3097 install_element(LDP_IPV6_IFACE_NODE
, &vtysh_end_all_cmd
);
3098 install_element(LDP_L2VPN_NODE
, &vtysh_end_all_cmd
);
3099 install_element(LDP_PSEUDOWIRE_NODE
, &vtysh_end_all_cmd
);
3100 install_element(BGP_NODE
, &vtysh_end_all_cmd
);
3101 install_element(BGP_IPV4_NODE
, &vtysh_end_all_cmd
);
3102 install_element(BGP_IPV4M_NODE
, &vtysh_end_all_cmd
);
3103 install_element(BGP_IPV4L_NODE
, &vtysh_end_all_cmd
);
3104 install_element(BGP_VPNV4_NODE
, &vtysh_end_all_cmd
);
3105 install_element(BGP_VPNV6_NODE
, &vtysh_end_all_cmd
);
3106 install_element(BGP_IPV6_NODE
, &vtysh_end_all_cmd
);
3107 install_element(BGP_IPV6M_NODE
, &vtysh_end_all_cmd
);
3108 install_element(BGP_IPV6L_NODE
, &vtysh_end_all_cmd
);
3109 install_element(BGP_VRF_POLICY_NODE
, &vtysh_end_all_cmd
);
3110 install_element(BGP_EVPN_NODE
, &vtysh_end_all_cmd
);
3111 install_element(BGP_EVPN_VNI_NODE
, &vtysh_end_all_cmd
);
3112 install_element(BGP_VNC_DEFAULTS_NODE
, &vtysh_end_all_cmd
);
3113 install_element(BGP_VNC_NVE_GROUP_NODE
, &vtysh_end_all_cmd
);
3114 install_element(BGP_VNC_L2_GROUP_NODE
, &vtysh_end_all_cmd
);
3115 install_element(ISIS_NODE
, &vtysh_end_all_cmd
);
3116 install_element(KEYCHAIN_NODE
, &vtysh_end_all_cmd
);
3117 install_element(KEYCHAIN_KEY_NODE
, &vtysh_end_all_cmd
);
3118 install_element(RMAP_NODE
, &vtysh_end_all_cmd
);
3119 install_element(VTY_NODE
, &vtysh_end_all_cmd
);
3121 install_element(INTERFACE_NODE
, &vtysh_interface_desc_cmd
);
3122 install_element(INTERFACE_NODE
, &vtysh_no_interface_desc_cmd
);
3123 install_element(INTERFACE_NODE
, &vtysh_end_all_cmd
);
3124 install_element(INTERFACE_NODE
, &vtysh_exit_interface_cmd
);
3125 install_element(LINK_PARAMS_NODE
, &exit_link_params_cmd
);
3126 install_element(LINK_PARAMS_NODE
, &vtysh_end_all_cmd
);
3127 install_element(LINK_PARAMS_NODE
, &vtysh_exit_interface_cmd
);
3128 install_element(INTERFACE_NODE
, &vtysh_quit_interface_cmd
);
3130 install_element(PW_NODE
, &vtysh_end_all_cmd
);
3131 install_element(PW_NODE
, &vtysh_exit_interface_cmd
);
3132 install_element(PW_NODE
, &vtysh_quit_interface_cmd
);
3134 install_element(NS_NODE
, &vtysh_end_all_cmd
);
3136 install_element(CONFIG_NODE
, &vtysh_ns_cmd
);
3137 install_element(NS_NODE
, &vtysh_exit_ns_cmd
);
3138 install_element(NS_NODE
, &vtysh_quit_ns_cmd
);
3140 install_element(VRF_NODE
, &vtysh_end_all_cmd
);
3141 install_element(VRF_NODE
, &vtysh_exit_vrf_cmd
);
3142 install_element(VRF_NODE
, &vtysh_quit_vrf_cmd
);
3144 install_element(CONFIG_NODE
, &router_eigrp_cmd
);
3145 install_element(CONFIG_NODE
, &router_babel_cmd
);
3146 install_element(CONFIG_NODE
, &router_rip_cmd
);
3147 install_element(CONFIG_NODE
, &router_ripng_cmd
);
3148 install_element(CONFIG_NODE
, &router_ospf_cmd
);
3149 install_element(CONFIG_NODE
, &router_ospf6_cmd
);
3150 #if defined(HAVE_LDPD)
3151 install_element(CONFIG_NODE
, &ldp_mpls_ldp_cmd
);
3152 install_element(LDP_NODE
, &ldp_address_family_ipv4_cmd
);
3153 install_element(LDP_NODE
, &ldp_address_family_ipv6_cmd
);
3154 install_element(LDP_IPV4_NODE
, &ldp_interface_ifname_cmd
);
3155 install_element(LDP_IPV6_NODE
, &ldp_interface_ifname_cmd
);
3156 install_element(CONFIG_NODE
, &ldp_l2vpn_word_type_vpls_cmd
);
3157 install_element(LDP_L2VPN_NODE
, &ldp_member_pseudowire_ifname_cmd
);
3159 install_element(CONFIG_NODE
, &router_isis_cmd
);
3160 install_element(CONFIG_NODE
, &router_bgp_cmd
);
3161 install_element(BGP_NODE
, &address_family_vpnv4_cmd
);
3162 install_element(BGP_NODE
, &address_family_vpnv6_cmd
);
3163 #if defined(ENABLE_BGP_VNC)
3164 install_element(BGP_NODE
, &vnc_vrf_policy_cmd
);
3165 install_element(BGP_NODE
, &vnc_defaults_cmd
);
3166 install_element(BGP_NODE
, &vnc_nve_group_cmd
);
3167 install_element(BGP_NODE
, &vnc_l2_group_cmd
);
3169 install_element(BGP_NODE
, &address_family_ipv4_cmd
);
3170 install_element(BGP_NODE
, &address_family_ipv4_multicast_cmd
);
3171 install_element(BGP_NODE
, &address_family_ipv4_vpn_cmd
);
3172 install_element(BGP_NODE
, &address_family_ipv4_labeled_unicast_cmd
);
3173 install_element(BGP_NODE
, &address_family_ipv6_cmd
);
3174 install_element(BGP_NODE
, &address_family_ipv6_multicast_cmd
);
3175 install_element(BGP_NODE
, &address_family_ipv6_vpn_cmd
);
3176 install_element(BGP_NODE
, &address_family_ipv6_labeled_unicast_cmd
);
3177 install_element(BGP_NODE
, &address_family_evpn_cmd
);
3178 #if defined(HAVE_CUMULUS)
3179 install_element(BGP_NODE
, &address_family_evpn2_cmd
);
3181 install_element(BGP_VPNV4_NODE
, &exit_address_family_cmd
);
3182 install_element(BGP_VPNV6_NODE
, &exit_address_family_cmd
);
3183 install_element(BGP_IPV4_NODE
, &exit_address_family_cmd
);
3184 install_element(BGP_IPV4M_NODE
, &exit_address_family_cmd
);
3185 install_element(BGP_IPV4L_NODE
, &exit_address_family_cmd
);
3186 install_element(BGP_IPV6_NODE
, &exit_address_family_cmd
);
3187 install_element(BGP_IPV6M_NODE
, &exit_address_family_cmd
);
3188 install_element(BGP_EVPN_NODE
, &exit_address_family_cmd
);
3189 install_element(BGP_IPV6L_NODE
, &exit_address_family_cmd
);
3192 install_element(BGP_EVPN_NODE
, &bgp_evpn_vni_cmd
);
3193 install_element(BGP_EVPN_VNI_NODE
, &exit_vni_cmd
);
3195 install_element(BGP_VRF_POLICY_NODE
, &exit_vrf_policy_cmd
);
3196 install_element(BGP_VNC_DEFAULTS_NODE
, &exit_vnc_config_cmd
);
3197 install_element(BGP_VNC_NVE_GROUP_NODE
, &exit_vnc_config_cmd
);
3198 install_element(BGP_VNC_L2_GROUP_NODE
, &exit_vnc_config_cmd
);
3200 install_element(CONFIG_NODE
, &key_chain_cmd
);
3201 install_element(CONFIG_NODE
, &vtysh_route_map_cmd
);
3202 install_element(CONFIG_NODE
, &vtysh_line_vty_cmd
);
3203 install_element(KEYCHAIN_NODE
, &key_cmd
);
3204 install_element(KEYCHAIN_NODE
, &key_chain_cmd
);
3205 install_element(KEYCHAIN_KEY_NODE
, &key_chain_cmd
);
3206 install_element(CONFIG_NODE
, &vtysh_interface_cmd
);
3207 install_element(CONFIG_NODE
, &vtysh_no_interface_cmd
);
3208 install_element(CONFIG_NODE
, &vtysh_no_interface_vrf_cmd
);
3209 install_element(CONFIG_NODE
, &vtysh_pseudowire_cmd
);
3210 install_element(INTERFACE_NODE
, &vtysh_link_params_cmd
);
3211 install_element(ENABLE_NODE
, &vtysh_show_running_config_cmd
);
3212 install_element(ENABLE_NODE
, &vtysh_copy_running_config_cmd
);
3214 install_element(CONFIG_NODE
, &vtysh_vrf_cmd
);
3215 install_element(CONFIG_NODE
, &vtysh_no_vrf_cmd
);
3217 /* "write terminal" command. */
3218 install_element(ENABLE_NODE
, &vtysh_write_terminal_cmd
);
3220 install_element(CONFIG_NODE
, &vtysh_integrated_config_cmd
);
3221 install_element(CONFIG_NODE
, &no_vtysh_integrated_config_cmd
);
3223 /* "write memory" command. */
3224 install_element(ENABLE_NODE
, &vtysh_write_memory_cmd
);
3226 install_element(VIEW_NODE
, &vtysh_terminal_length_cmd
);
3227 install_element(VIEW_NODE
, &vtysh_terminal_no_length_cmd
);
3228 install_element(VIEW_NODE
, &vtysh_show_daemons_cmd
);
3230 install_element(VIEW_NODE
, &vtysh_ping_cmd
);
3231 install_element(VIEW_NODE
, &vtysh_ping_ip_cmd
);
3232 install_element(VIEW_NODE
, &vtysh_traceroute_cmd
);
3233 install_element(VIEW_NODE
, &vtysh_traceroute_ip_cmd
);
3234 install_element(VIEW_NODE
, &vtysh_ping6_cmd
);
3235 install_element(VIEW_NODE
, &vtysh_traceroute6_cmd
);
3236 #if defined(HAVE_SHELL_ACCESS)
3237 install_element(VIEW_NODE
, &vtysh_telnet_cmd
);
3238 install_element(VIEW_NODE
, &vtysh_telnet_port_cmd
);
3239 install_element(VIEW_NODE
, &vtysh_ssh_cmd
);
3241 #if defined(HAVE_SHELL_ACCESS)
3242 install_element(ENABLE_NODE
, &vtysh_start_shell_cmd
);
3243 install_element(ENABLE_NODE
, &vtysh_start_bash_cmd
);
3244 install_element(ENABLE_NODE
, &vtysh_start_zsh_cmd
);
3247 install_element(VIEW_NODE
, &vtysh_show_debugging_cmd
);
3248 install_element(VIEW_NODE
, &vtysh_show_debugging_hashtable_cmd
);
3249 install_element(VIEW_NODE
, &vtysh_show_memory_cmd
);
3250 install_element(VIEW_NODE
, &vtysh_show_modules_cmd
);
3252 install_element(VIEW_NODE
, &vtysh_show_work_queues_cmd
);
3253 install_element(VIEW_NODE
, &vtysh_show_work_queues_daemon_cmd
);
3255 install_element(VIEW_NODE
, &vtysh_show_hashtable_cmd
);
3257 install_element(VIEW_NODE
, &vtysh_show_thread_cmd
);
3260 install_element(VIEW_NODE
, &vtysh_show_logging_cmd
);
3261 install_element(CONFIG_NODE
, &vtysh_log_stdout_cmd
);
3262 install_element(CONFIG_NODE
, &vtysh_log_stdout_level_cmd
);
3263 install_element(CONFIG_NODE
, &no_vtysh_log_stdout_cmd
);
3264 install_element(CONFIG_NODE
, &vtysh_log_file_cmd
);
3265 install_element(CONFIG_NODE
, &vtysh_log_file_level_cmd
);
3266 install_element(CONFIG_NODE
, &no_vtysh_log_file_cmd
);
3267 install_element(CONFIG_NODE
, &vtysh_log_monitor_cmd
);
3268 install_element(CONFIG_NODE
, &no_vtysh_log_monitor_cmd
);
3269 install_element(CONFIG_NODE
, &vtysh_log_syslog_cmd
);
3270 install_element(CONFIG_NODE
, &no_vtysh_log_syslog_cmd
);
3271 install_element(CONFIG_NODE
, &vtysh_log_trap_cmd
);
3272 install_element(CONFIG_NODE
, &no_vtysh_log_trap_cmd
);
3273 install_element(CONFIG_NODE
, &vtysh_log_facility_cmd
);
3274 install_element(CONFIG_NODE
, &no_vtysh_log_facility_cmd
);
3275 install_element(CONFIG_NODE
, &vtysh_log_record_priority_cmd
);
3276 install_element(CONFIG_NODE
, &no_vtysh_log_record_priority_cmd
);
3277 install_element(CONFIG_NODE
, &vtysh_log_timestamp_precision_cmd
);
3278 install_element(CONFIG_NODE
, &no_vtysh_log_timestamp_precision_cmd
);
3280 install_element(CONFIG_NODE
, &vtysh_service_password_encrypt_cmd
);
3281 install_element(CONFIG_NODE
, &no_vtysh_service_password_encrypt_cmd
);
3283 install_element(CONFIG_NODE
, &vtysh_password_cmd
);
3284 install_element(CONFIG_NODE
, &vtysh_enable_password_cmd
);
3285 install_element(CONFIG_NODE
, &no_vtysh_enable_password_cmd
);