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
;
222 for (client
= head_client
; client
; client
= client
->next
) {
223 rc
= vtysh_client_run(client
, line
, fp
, callback
, cbarg
);
224 if (rc
!= CMD_SUCCESS
) {
225 if (!continue_on_err
)
233 static int vtysh_client_execute(struct vtysh_client
*head_client
,
234 const char *line
, FILE *fp
)
236 return vtysh_client_run_all(head_client
, line
, 0, fp
, NULL
, NULL
);
239 static void vtysh_client_config(struct vtysh_client
*head_client
, char *line
)
241 vtysh_client_run_all(head_client
, line
, 1, NULL
,
242 vtysh_config_parse_line
, NULL
);
245 void vtysh_pager_init(void)
249 pager_defined
= getenv("VTYSH_PAGER");
252 vtysh_pager_name
= strdup(pager_defined
);
254 vtysh_pager_name
= strdup(VTYSH_PAGER
);
257 /* Command execution over the vty interface. */
258 static int vtysh_execute_func(const char *line
, int pager
)
263 const struct cmd_element
*cmd
;
267 int saved_ret
, saved_node
;
269 /* Split readline string up into the vector. */
270 vline
= cmd_make_strvec(line
);
275 saved_ret
= ret
= cmd_execute_command(vline
, vty
, &cmd
, 1);
276 saved_node
= vty
->node
;
278 /* If command doesn't succeeded in current node, try to walk up in node
280 * Changing vty->node is enough to try it just out without actual walkup
283 while (ret
!= CMD_SUCCESS
&& ret
!= CMD_SUCCESS_DAEMON
284 && ret
!= CMD_WARNING
&& ret
!= CMD_WARNING_CONFIG_FAILED
285 && vty
->node
> CONFIG_NODE
) {
286 vty
->node
= node_parent(vty
->node
);
287 ret
= cmd_execute_command(vline
, vty
, &cmd
, 1);
291 vty
->node
= saved_node
;
293 /* If command succeeded in any other node than current (tried > 0) we
295 * to move into node in the vtysh where it succeeded. */
296 if (ret
== CMD_SUCCESS
|| ret
== CMD_SUCCESS_DAEMON
297 || ret
== CMD_WARNING
) {
298 if ((saved_node
== BGP_VPNV4_NODE
299 || saved_node
== BGP_VPNV6_NODE
300 || saved_node
== BGP_IPV4_NODE
301 || saved_node
== BGP_IPV6_NODE
302 || saved_node
== BGP_IPV4M_NODE
303 || saved_node
== BGP_IPV4L_NODE
304 || saved_node
== BGP_IPV6L_NODE
305 || saved_node
== BGP_IPV6M_NODE
306 || saved_node
== BGP_EVPN_NODE
)
308 vtysh_execute("exit-address-family");
309 } else if ((saved_node
== BGP_EVPN_VNI_NODE
) && (tried
== 1)) {
310 vtysh_execute("exit-vni");
311 } else if (saved_node
== BGP_VRF_POLICY_NODE
&& (tried
== 1)) {
312 vtysh_execute("exit-vrf-policy");
313 } else if ((saved_node
== BGP_VNC_DEFAULTS_NODE
314 || saved_node
== BGP_VNC_NVE_GROUP_NODE
315 || saved_node
== BGP_VNC_L2_GROUP_NODE
)
317 vtysh_execute("exit-vnc");
318 } else if ((saved_node
== KEYCHAIN_KEY_NODE
319 || saved_node
== LDP_PSEUDOWIRE_NODE
320 || saved_node
== LDP_IPV4_IFACE_NODE
321 || saved_node
== LDP_IPV6_IFACE_NODE
)
323 vtysh_execute("exit");
325 vtysh_execute("end");
326 vtysh_execute("configure terminal");
329 /* If command didn't succeed in any node, continue with return value
336 cmd_free_strvec(vline
);
341 case CMD_WARNING_CONFIG_FAILED
:
342 if (vty
->type
== VTY_FILE
)
343 fprintf(stdout
, "Warning...\n");
345 case CMD_ERR_AMBIGUOUS
:
346 fprintf(stdout
, "%% Ambiguous command.\n");
348 case CMD_ERR_NO_MATCH
:
349 fprintf(stdout
, "%% Unknown command.\n");
351 case CMD_ERR_INCOMPLETE
:
352 fprintf(stdout
, "%% Command incomplete.\n");
354 case CMD_SUCCESS_DAEMON
: {
355 /* FIXME: Don't open pager for exit commands. popen() causes
357 * if exited from vtysh at all. This hack shouldn't cause any
359 * but is really ugly. */
360 if (pager
&& vtysh_pager_name
361 && (strncmp(line
, "exit", 4) != 0)) {
362 fp
= popen(vtysh_pager_name
, "w");
364 perror("popen failed for pager");
371 if (!strcmp(cmd
->string
, "configure terminal")) {
372 for (i
= 0; i
< array_size(vtysh_client
); i
++) {
373 cmd_stat
= vtysh_client_execute(
374 &vtysh_client
[i
], line
, fp
);
375 if (cmd_stat
== CMD_WARNING
)
381 vline
= cmd_make_strvec(line
);
384 if (pager
&& vtysh_pager_name
&& fp
386 if (pclose(fp
) == -1) {
387 perror("pclose failed for pager");
394 ret
= cmd_execute_command(vline
, vty
, &cmd
, 1);
395 cmd_free_strvec(vline
);
396 if (ret
!= CMD_SUCCESS_DAEMON
)
398 } else if (cmd
->func
) {
399 (*cmd
->func
)(cmd
, vty
, 0, NULL
);
404 cmd_stat
= CMD_SUCCESS
;
405 for (i
= 0; i
< array_size(vtysh_client
); i
++) {
406 if (cmd
->daemon
& vtysh_client
[i
].flag
) {
407 cmd_stat
= vtysh_client_execute(
408 &vtysh_client
[i
], line
, fp
);
409 if (cmd_stat
!= CMD_SUCCESS
)
413 if (cmd_stat
!= CMD_SUCCESS
)
417 (*cmd
->func
)(cmd
, vty
, 0, NULL
);
420 if (pager
&& vtysh_pager_name
&& fp
&& closepager
) {
421 if (pclose(fp
) == -1) {
422 perror("pclose failed for pager");
429 int vtysh_execute_no_pager(const char *line
)
431 return vtysh_execute_func(line
, 0);
434 int vtysh_execute(const char *line
)
436 return vtysh_execute_func(line
, 1);
439 static char *trim(char *s
)
450 while (end
>= s
&& isspace(*end
))
454 while (*s
&& isspace(*s
))
460 int vtysh_mark_file(const char *filename
)
467 const struct cmd_element
*cmd
;
468 int saved_ret
, prev_node
;
470 char *vty_buf_copy
= NULL
;
471 char *vty_buf_trimmed
= NULL
;
473 if (strncmp("-", filename
, 1) == 0)
476 confp
= fopen(filename
, "r");
479 fprintf(stderr
, "%% Can't open config file %s due to '%s'.\n",
480 filename
, safe_strerror(errno
));
481 return (CMD_ERR_NO_FILE
);
485 vty
->fd
= 0; /* stdout */
486 vty
->type
= VTY_TERM
;
487 vty
->node
= CONFIG_NODE
;
489 vtysh_execute_no_pager("enable");
490 vtysh_execute_no_pager("configure terminal");
491 vty_buf_copy
= XCALLOC(MTYPE_VTYSH_CMD
, VTY_BUFSIZ
);
493 while (fgets(vty
->buf
, VTY_BUFSIZ
, confp
)) {
496 strcpy(vty_buf_copy
, vty
->buf
);
497 vty_buf_trimmed
= trim(vty_buf_copy
);
499 if (vty_buf_trimmed
[0] == '!' || vty_buf_trimmed
[0] == '#') {
500 fprintf(stdout
, "%s", vty
->buf
);
504 /* Split readline string up into the vector. */
505 vline
= cmd_make_strvec(vty
->buf
);
508 fprintf(stdout
, "%s", vty
->buf
);
512 /* Ignore the "end" lines, we will generate these where
514 if (strlen(vty_buf_trimmed
) == 3
515 && strncmp("end", vty_buf_trimmed
, 3) == 0) {
519 prev_node
= vty
->node
;
520 saved_ret
= ret
= cmd_execute_command_strict(vline
, vty
, &cmd
);
522 /* If command doesn't succeeded in current node, try to walk up
524 * Changing vty->node is enough to try it just out without
527 while (ret
!= CMD_SUCCESS
&& ret
!= CMD_SUCCESS_DAEMON
528 && ret
!= CMD_WARNING
&& ret
!= CMD_WARNING_CONFIG_FAILED
529 && vty
->node
> CONFIG_NODE
) {
530 vty
->node
= node_parent(vty
->node
);
531 ret
= cmd_execute_command_strict(vline
, vty
, &cmd
);
535 /* If command succeeded in any other node than current (tried >
537 * to move into node in the vtysh where it succeeded. */
538 if (ret
== CMD_SUCCESS
|| ret
== CMD_SUCCESS_DAEMON
539 || ret
== CMD_WARNING
) {
540 if ((prev_node
== BGP_VPNV4_NODE
541 || prev_node
== BGP_VPNV6_NODE
542 || prev_node
== BGP_IPV4_NODE
543 || prev_node
== BGP_IPV6_NODE
544 || prev_node
== BGP_IPV4L_NODE
545 || prev_node
== BGP_IPV6L_NODE
546 || prev_node
== BGP_IPV4M_NODE
547 || prev_node
== BGP_IPV6M_NODE
548 || prev_node
== BGP_EVPN_NODE
)
550 fprintf(stdout
, "exit-address-family\n");
551 } else if ((prev_node
== BGP_EVPN_VNI_NODE
)
553 fprintf(stdout
, "exit-vni\n");
554 } else if ((prev_node
== KEYCHAIN_KEY_NODE
)
556 fprintf(stdout
, "exit\n");
558 fprintf(stdout
, "end\n");
561 /* If command didn't succeed in any node, continue with return
566 vty
->node
= prev_node
;
569 cmd_free_strvec(vline
);
572 case CMD_WARNING_CONFIG_FAILED
:
573 if (vty
->type
== VTY_FILE
)
574 fprintf(stderr
, "line %d: Warning...: %s\n",
578 XFREE(MTYPE_VTYSH_CMD
, vty_buf_copy
);
580 case CMD_ERR_AMBIGUOUS
:
581 fprintf(stderr
, "line %d: %% Ambiguous command: %s\n",
585 XFREE(MTYPE_VTYSH_CMD
, vty_buf_copy
);
586 return CMD_ERR_AMBIGUOUS
;
587 case CMD_ERR_NO_MATCH
:
588 fprintf(stderr
, "line %d: %% Unknown command: %s\n",
592 XFREE(MTYPE_VTYSH_CMD
, vty_buf_copy
);
593 return CMD_ERR_NO_MATCH
;
594 case CMD_ERR_INCOMPLETE
:
595 fprintf(stderr
, "line %d: %% Command incomplete: %s\n",
599 XFREE(MTYPE_VTYSH_CMD
, vty_buf_copy
);
600 return CMD_ERR_INCOMPLETE
;
602 fprintf(stdout
, "%s", vty
->buf
);
604 case CMD_SUCCESS_DAEMON
: {
606 int cmd_stat
= CMD_SUCCESS
;
608 fprintf(stdout
, "%s", vty
->buf
);
609 for (i
= 0; i
< array_size(vtysh_client
); i
++) {
610 if (cmd
->daemon
& vtysh_client
[i
].flag
) {
611 cmd_stat
= vtysh_client_execute(
612 &vtysh_client
[i
], vty
->buf
,
614 if (cmd_stat
!= CMD_SUCCESS
)
618 if (cmd_stat
!= CMD_SUCCESS
)
622 (*cmd
->func
)(cmd
, vty
, 0, NULL
);
626 /* This is the end */
627 fprintf(stdout
, "\nend\n");
629 XFREE(MTYPE_VTYSH_CMD
, vty_buf_copy
);
637 /* Configration make from file. */
638 int vtysh_config_from_file(struct vty
*vty
, FILE *fp
)
641 const struct cmd_element
*cmd
;
643 int retcode
= CMD_SUCCESS
;
645 while (fgets(vty
->buf
, VTY_BUFSIZ
, fp
)) {
648 ret
= command_config_read_one_line(vty
, &cmd
, 1);
652 case CMD_WARNING_CONFIG_FAILED
:
653 if (vty
->type
== VTY_FILE
)
654 fprintf(stderr
, "line %d: Warning[%d]...: %s\n",
655 lineno
, vty
->node
, vty
->buf
);
656 retcode
= ret
; /* once we have an error, we remember &
659 case CMD_ERR_AMBIGUOUS
:
661 "line %d: %% Ambiguous command[%d]: %s\n",
662 lineno
, vty
->node
, vty
->buf
);
663 retcode
= CMD_ERR_AMBIGUOUS
; /* once we have an error,
667 case CMD_ERR_NO_MATCH
:
668 fprintf(stderr
, "line %d: %% Unknown command[%d]: %s",
669 lineno
, vty
->node
, vty
->buf
);
671 CMD_ERR_NO_MATCH
; /* once we have an error, we
672 remember & return that */
674 case CMD_ERR_INCOMPLETE
:
676 "line %d: %% Command incomplete[%d]: %s\n",
677 lineno
, vty
->node
, vty
->buf
);
678 retcode
= CMD_ERR_INCOMPLETE
; /* once we have an error,
682 case CMD_SUCCESS_DAEMON
: {
684 int cmd_stat
= CMD_SUCCESS
;
686 for (i
= 0; i
< array_size(vtysh_client
); i
++) {
687 if (cmd
->daemon
& vtysh_client
[i
].flag
) {
688 cmd_stat
= vtysh_client_execute(
689 &vtysh_client
[i
], vty
->buf
,
692 * CMD_WARNING - Can mean that the
694 * parsed successfully but it was
696 * in a few spots. As such if we
698 * CMD_WARNING from a daemon we
700 * talking to the other daemons for the
704 if (cmd_stat
!= CMD_SUCCESS
705 && cmd_stat
!= CMD_WARNING
) {
707 "line %d: Failure to communicate[%d] to %s, line: %s\n",
709 vtysh_client
[i
].name
,
715 if (cmd_stat
!= CMD_SUCCESS
)
719 (*cmd
->func
)(cmd
, vty
, 0, NULL
);
727 /* We don't care about the point of the cursor when '?' is typed. */
728 static int vtysh_rl_describe(void)
735 struct cmd_token
*token
;
737 vline
= cmd_make_strvec(rl_line_buffer
);
739 /* In case of '> ?'. */
741 vline
= vector_init(1);
742 vector_set(vline
, NULL
);
743 } else if (rl_end
&& isspace((int)rl_line_buffer
[rl_end
- 1]))
744 vector_set(vline
, NULL
);
746 describe
= cmd_describe_command(vline
, vty
, &ret
);
748 fprintf(stdout
, "\n");
750 /* Ambiguous and no match error. */
752 case CMD_ERR_AMBIGUOUS
:
753 cmd_free_strvec(vline
);
754 fprintf(stdout
, "%% Ambiguous command.\n");
758 case CMD_ERR_NO_MATCH
:
759 cmd_free_strvec(vline
);
760 fprintf(stdout
, "%% There is no matched command.\n");
766 /* Get width of command string. */
768 for (i
= 0; i
< vector_active(describe
); i
++)
769 if ((token
= vector_slot(describe
, i
)) != NULL
) {
770 if (token
->text
[0] == '\0')
773 int len
= strlen(token
->text
);
779 for (i
= 0; i
< vector_active(describe
); i
++)
780 if ((token
= vector_slot(describe
, i
)) != NULL
) {
782 fprintf(stdout
, " %-s\n", token
->text
);
784 fprintf(stdout
, " %-*s %s\n", width
,
785 token
->text
, token
->desc
);
787 if (IS_VARYING_TOKEN(token
->type
)) {
788 const char *ref
= vector_slot(
789 vline
, vector_active(vline
) - 1);
791 vector varcomps
= vector_init(VECTOR_MIN_SIZE
);
792 cmd_variable_complete(token
, ref
, varcomps
);
794 if (vector_active(varcomps
) > 0) {
796 rl_get_screen_size(&rows
, &cols
);
798 char *ac
= cmd_variable_comp2str(
800 fprintf(stdout
, "%s\n", ac
);
801 XFREE(MTYPE_TMP
, ac
);
804 vector_free(varcomps
);
808 cmd_free_strvec(vline
);
809 vector_free(describe
);
816 /* Result of cmd_complete_command() call will be stored here
817 * and used in new_completion() in order to put the space in
818 * correct places only. */
821 static char *command_generator(const char *text
, int state
)
824 static char **matched
= NULL
;
825 static int index
= 0;
831 if (vty
->node
== AUTH_NODE
|| vty
->node
== AUTH_ENABLE_NODE
)
834 vline
= cmd_make_strvec(rl_line_buffer
);
838 if (rl_end
&& isspace((int)rl_line_buffer
[rl_end
- 1]))
839 vector_set(vline
, NULL
);
841 matched
= cmd_complete_command(vline
, vty
, &complete_status
);
842 cmd_free_strvec(vline
);
845 if (matched
&& matched
[index
])
846 /* this is free()'d by readline, but we leak 1 count of
847 * MTYPE_COMPLETION */
848 return matched
[index
++];
850 XFREE(MTYPE_TMP
, matched
);
856 static char **new_completion(char *text
, int start
, int end
)
860 matches
= rl_completion_matches(text
, command_generator
);
864 if (complete_status
!= CMD_COMPLETE_FULL_MATCH
)
865 /* only append a space on full match */
866 rl_completion_append_character
= '\0';
872 /* Vty node structures. */
873 static struct cmd_node bgp_node
= {
874 BGP_NODE
, "%s(config-router)# ",
877 static struct cmd_node rip_node
= {
878 RIP_NODE
, "%s(config-router)# ",
881 static struct cmd_node isis_node
= {
882 ISIS_NODE
, "%s(config-router)# ",
885 static struct cmd_node interface_node
= {
886 INTERFACE_NODE
, "%s(config-if)# ",
889 static struct cmd_node ns_node
= {
890 NS_NODE
, "%s(config-logical-router)# ",
893 static struct cmd_node vrf_node
= {
894 VRF_NODE
, "%s(config-vrf)# ",
897 static struct cmd_node rmap_node
= {RMAP_NODE
, "%s(config-route-map)# "};
899 static struct cmd_node zebra_node
= {ZEBRA_NODE
, "%s(config-router)# "};
901 static struct cmd_node bgp_vpnv4_node
= {BGP_VPNV4_NODE
,
902 "%s(config-router-af)# "};
904 static struct cmd_node bgp_vpnv6_node
= {BGP_VPNV6_NODE
,
905 "%s(config-router-af)# "};
907 static struct cmd_node bgp_ipv4_node
= {BGP_IPV4_NODE
,
908 "%s(config-router-af)# "};
910 static struct cmd_node bgp_ipv4m_node
= {BGP_IPV4M_NODE
,
911 "%s(config-router-af)# "};
913 static struct cmd_node bgp_ipv4l_node
= {BGP_IPV4L_NODE
,
914 "%s(config-router-af)# "};
916 static struct cmd_node bgp_ipv6_node
= {BGP_IPV6_NODE
,
917 "%s(config-router-af)# "};
919 static struct cmd_node bgp_ipv6m_node
= {BGP_IPV6M_NODE
,
920 "%s(config-router-af)# "};
922 static struct cmd_node bgp_evpn_node
= {BGP_EVPN_NODE
,
923 "%s(config-router-af)# "};
925 static struct cmd_node bgp_evpn_vni_node
= {BGP_EVPN_VNI_NODE
,
926 "%s(config-router-af-vni)# "};
928 static struct cmd_node bgp_ipv6l_node
= {BGP_IPV6L_NODE
,
929 "%s(config-router-af)# "};
931 static struct cmd_node bgp_vnc_defaults_node
= {
932 BGP_VNC_DEFAULTS_NODE
, "%s(config-router-vnc-defaults)# "};
934 static struct cmd_node bgp_vnc_nve_group_node
= {
935 BGP_VNC_NVE_GROUP_NODE
, "%s(config-router-vnc-nve-group)# "};
937 static struct cmd_node bgp_vrf_policy_node
= {BGP_VRF_POLICY_NODE
,
938 "%s(config-router-vrf-policy)# "};
940 static struct cmd_node bgp_vnc_l2_group_node
= {
941 BGP_VNC_L2_GROUP_NODE
, "%s(config-router-vnc-l2-group)# "};
943 static struct cmd_node ospf_node
= {OSPF_NODE
, "%s(config-router)# "};
945 static struct cmd_node eigrp_node
= {EIGRP_NODE
, "%s(config-router)# "};
947 static struct cmd_node babel_node
= {BABEL_NODE
, "%s(config-router)# "};
949 static struct cmd_node ripng_node
= {RIPNG_NODE
, "%s(config-router)# "};
951 static struct cmd_node ospf6_node
= {OSPF6_NODE
, "%s(config-ospf6)# "};
953 static struct cmd_node ldp_node
= {LDP_NODE
, "%s(config-ldp)# "};
955 static struct cmd_node ldp_ipv4_node
= {LDP_IPV4_NODE
, "%s(config-ldp-af)# "};
957 static struct cmd_node ldp_ipv6_node
= {LDP_IPV6_NODE
, "%s(config-ldp-af)# "};
959 static struct cmd_node ldp_ipv4_iface_node
= {LDP_IPV4_IFACE_NODE
,
960 "%s(config-ldp-af-if)# "};
962 static struct cmd_node ldp_ipv6_iface_node
= {LDP_IPV6_IFACE_NODE
,
963 "%s(config-ldp-af-if)# "};
965 static struct cmd_node ldp_l2vpn_node
= {LDP_L2VPN_NODE
, "%s(config-l2vpn)# "};
967 static struct cmd_node ldp_pseudowire_node
= {LDP_PSEUDOWIRE_NODE
,
968 "%s(config-l2vpn-pw)# "};
970 static struct cmd_node keychain_node
= {KEYCHAIN_NODE
, "%s(config-keychain)# "};
972 static struct cmd_node keychain_key_node
= {KEYCHAIN_KEY_NODE
,
973 "%s(config-keychain-key)# "};
975 struct cmd_node link_params_node
= {
976 LINK_PARAMS_NODE
, "%s(config-link-params)# ",
979 /* Defined in lib/vty.c */
980 extern struct cmd_node vty_node
;
982 /* When '^Z' is received from vty, move down to the enable mode. */
983 static int vtysh_end(void)
991 vty
->node
= ENABLE_NODE
;
997 DEFUNSH(VTYSH_REALLYALL
, vtysh_end_all
, vtysh_end_all_cmd
, "end",
998 "End current mode and change to enable mode\n")
1003 DEFUNSH(VTYSH_BGPD
, router_bgp
, router_bgp_cmd
,
1004 "router bgp [(1-4294967295) [<view|vrf> WORD]]",
1005 ROUTER_STR BGP_STR AS_STR
1006 "BGP view\nBGP VRF\n"
1009 vty
->node
= BGP_NODE
;
1013 DEFUNSH(VTYSH_BGPD
, address_family_vpnv4
, address_family_vpnv4_cmd
,
1014 "address-family vpnv4 [unicast]",
1015 "Enter Address Family command mode\n"
1017 "Address Family modifier\n")
1019 vty
->node
= BGP_VPNV4_NODE
;
1023 DEFUNSH(VTYSH_BGPD
, address_family_vpnv6
, address_family_vpnv6_cmd
,
1024 "address-family vpnv6 [unicast]",
1025 "Enter Address Family command mode\n"
1027 "Address Family modifier\n")
1029 vty
->node
= BGP_VPNV6_NODE
;
1033 DEFUNSH(VTYSH_BGPD
, address_family_ipv4
, address_family_ipv4_cmd
,
1034 "address-family ipv4 [unicast]",
1035 "Enter Address Family command mode\n"
1037 "Address Family Modifier\n")
1039 vty
->node
= BGP_IPV4_NODE
;
1043 DEFUNSH(VTYSH_BGPD
, address_family_ipv4_multicast
,
1044 address_family_ipv4_multicast_cmd
, "address-family ipv4 multicast",
1045 "Enter Address Family command mode\n"
1047 "Address Family modifier\n")
1049 vty
->node
= BGP_IPV4M_NODE
;
1053 DEFUNSH(VTYSH_BGPD
, address_family_ipv4_vpn
, address_family_ipv4_vpn_cmd
,
1054 "address-family ipv4 vpn",
1055 "Enter Address Family command mode\n"
1057 "Address Family modifier\n")
1059 vty
->node
= BGP_VPNV4_NODE
;
1063 DEFUNSH(VTYSH_BGPD
, address_family_ipv4_labeled_unicast
,
1064 address_family_ipv4_labeled_unicast_cmd
,
1065 "address-family ipv4 labeled-unicast",
1066 "Enter Address Family command mode\n"
1068 "Address Family modifier\n")
1070 vty
->node
= BGP_IPV4L_NODE
;
1074 DEFUNSH(VTYSH_BGPD
, address_family_ipv6
, address_family_ipv6_cmd
,
1075 "address-family ipv6 [unicast]",
1076 "Enter Address Family command mode\n"
1078 "Address Family modifier\n")
1080 vty
->node
= BGP_IPV6_NODE
;
1084 DEFUNSH(VTYSH_BGPD
, address_family_ipv6_multicast
,
1085 address_family_ipv6_multicast_cmd
, "address-family ipv6 multicast",
1086 "Enter Address Family command mode\n"
1088 "Address Family modifier\n")
1090 vty
->node
= BGP_IPV6M_NODE
;
1094 DEFUNSH(VTYSH_BGPD
, address_family_ipv6_vpn
, address_family_ipv6_vpn_cmd
,
1095 "address-family ipv6 vpn",
1096 "Enter Address Family command mode\n"
1098 "Address Family modifier\n")
1100 vty
->node
= BGP_VPNV6_NODE
;
1104 DEFUNSH(VTYSH_BGPD
, address_family_ipv6_labeled_unicast
,
1105 address_family_ipv6_labeled_unicast_cmd
,
1106 "address-family ipv6 labeled-unicast",
1107 "Enter Address Family command mode\n"
1109 "Address Family modifier\n")
1111 vty
->node
= BGP_IPV6L_NODE
;
1115 DEFUNSH(VTYSH_BGPD
, address_family_evpn
, address_family_evpn_cmd
,
1116 "address-family <l2vpn evpn>",
1117 "Enter Address Family command mode\n"
1119 "Address Family modifier\n")
1121 vty
->node
= BGP_EVPN_NODE
;
1125 #if defined(HAVE_CUMULUS)
1126 DEFUNSH(VTYSH_BGPD
, address_family_evpn2
, address_family_evpn2_cmd
,
1127 "address-family evpn",
1128 "Enter Address Family command mode\n"
1129 "EVPN Address family\n")
1131 vty
->node
= BGP_EVPN_NODE
;
1136 DEFUNSH(VTYSH_BGPD
, bgp_evpn_vni
, bgp_evpn_vni_cmd
, "vni (1-16777215)",
1137 "VXLAN Network Identifier\n"
1140 vty
->node
= BGP_EVPN_VNI_NODE
;
1144 #if defined(ENABLE_BGP_VNC)
1145 DEFUNSH(VTYSH_BGPD
, vnc_defaults
, vnc_defaults_cmd
, "vnc defaults",
1146 "VNC/RFP related configuration\n"
1147 "Configure default NVE group\n")
1149 vty
->node
= BGP_VNC_DEFAULTS_NODE
;
1153 DEFUNSH(VTYSH_BGPD
, vnc_nve_group
, vnc_nve_group_cmd
, "vnc nve-group NAME",
1154 "VNC/RFP related configuration\n"
1155 "Configure a NVE group\n"
1158 vty
->node
= BGP_VNC_NVE_GROUP_NODE
;
1162 DEFUNSH(VTYSH_BGPD
, vnc_vrf_policy
, vnc_vrf_policy_cmd
, "vrf-policy NAME",
1163 "Configure a VRF policy group\n"
1166 vty
->node
= BGP_VRF_POLICY_NODE
;
1170 DEFUNSH(VTYSH_BGPD
, vnc_l2_group
, vnc_l2_group_cmd
, "vnc l2-group NAME",
1171 "VNC/RFP related configuration\n"
1172 "Configure a L2 group\n"
1175 vty
->node
= BGP_VNC_L2_GROUP_NODE
;
1180 DEFUNSH(VTYSH_RIPD
, key_chain
, key_chain_cmd
, "key chain WORD",
1181 "Authentication key management\n"
1182 "Key-chain management\n"
1185 vty
->node
= KEYCHAIN_NODE
;
1189 DEFUNSH(VTYSH_RIPD
, key
, key_cmd
, "key (0-2147483647)",
1191 "Key identifier number\n")
1193 vty
->node
= KEYCHAIN_KEY_NODE
;
1197 DEFUNSH(VTYSH_RIPD
, router_rip
, router_rip_cmd
, "router rip",
1200 vty
->node
= RIP_NODE
;
1204 DEFUNSH(VTYSH_RIPNGD
, router_ripng
, router_ripng_cmd
, "router ripng",
1205 ROUTER_STR
"RIPng\n")
1207 vty
->node
= RIPNG_NODE
;
1211 DEFUNSH(VTYSH_OSPFD
, router_ospf
, router_ospf_cmd
, "router ospf [(1-65535)]",
1212 "Enable a routing process\n"
1213 "Start OSPF configuration\n"
1216 vty
->node
= OSPF_NODE
;
1220 DEFUNSH(VTYSH_EIGRPD
, router_eigrp
, router_eigrp_cmd
, "router eigrp (1-65535)",
1221 "Enable a routing process\n"
1222 "Start EIGRP configuration\n"
1223 "AS number to use\n")
1225 vty
->node
= EIGRP_NODE
;
1229 DEFUNSH(VTYSH_BABELD
, router_babel
, router_babel_cmd
, "router babel",
1230 "Enable a routing process\n"
1231 "Make Babel instance command\n")
1233 vty
->node
= BABEL_NODE
;
1237 DEFUNSH(VTYSH_OSPF6D
, router_ospf6
, router_ospf6_cmd
, "router ospf6",
1238 ROUTER_STR OSPF6_STR
)
1240 vty
->node
= OSPF6_NODE
;
1244 #if defined(HAVE_LDPD)
1245 DEFUNSH(VTYSH_LDPD
, ldp_mpls_ldp
, ldp_mpls_ldp_cmd
, "mpls ldp",
1246 "Global MPLS configuration subcommands\n"
1247 "Label Distribution Protocol\n")
1249 vty
->node
= LDP_NODE
;
1253 DEFUNSH(VTYSH_LDPD
, ldp_address_family_ipv4
, ldp_address_family_ipv4_cmd
,
1254 "address-family ipv4",
1255 "Configure Address Family and its parameters\n"
1258 vty
->node
= LDP_IPV4_NODE
;
1262 DEFUNSH(VTYSH_LDPD
, ldp_address_family_ipv6
, ldp_address_family_ipv6_cmd
,
1263 "address-family ipv6",
1264 "Configure Address Family and its parameters\n"
1267 vty
->node
= LDP_IPV6_NODE
;
1271 DEFUNSH(VTYSH_LDPD
, ldp_interface_ifname
, ldp_interface_ifname_cmd
,
1273 "Enable LDP on an interface and enter interface submode\n"
1274 "Interface's name\n")
1276 switch (vty
->node
) {
1278 vty
->node
= LDP_IPV4_IFACE_NODE
;
1281 vty
->node
= LDP_IPV6_IFACE_NODE
;
1290 DEFUNSH(VTYSH_LDPD
, ldp_l2vpn_word_type_vpls
, ldp_l2vpn_word_type_vpls_cmd
,
1291 "l2vpn WORD type vpls",
1292 "Configure l2vpn commands\n"
1295 "Virtual Private LAN Service\n")
1297 vty
->node
= LDP_L2VPN_NODE
;
1301 DEFUNSH(VTYSH_LDPD
, ldp_member_pseudowire_ifname
,
1302 ldp_member_pseudowire_ifname_cmd
, "member pseudowire IFNAME",
1303 "L2VPN member configuration\n"
1304 "Pseudowire interface\n"
1305 "Interface's name\n")
1307 vty
->node
= LDP_PSEUDOWIRE_NODE
;
1312 DEFUNSH(VTYSH_ISISD
, router_isis
, router_isis_cmd
, "router isis WORD",
1315 "ISO Routing area tag")
1317 vty
->node
= ISIS_NODE
;
1321 DEFUNSH(VTYSH_RMAP
, vtysh_route_map
, vtysh_route_map_cmd
,
1322 "route-map WORD <deny|permit> (1-65535)",
1323 "Create route-map or enter route-map command mode\n"
1325 "Route map denies set operations\n"
1326 "Route map permits set operations\n"
1327 "Sequence to insert to/delete from existing route-map entry\n")
1329 vty
->node
= RMAP_NODE
;
1333 DEFUNSH(VTYSH_ALL
, vtysh_line_vty
, vtysh_line_vty_cmd
, "line vty",
1334 "Configure a terminal line\n"
1335 "Virtual terminal\n")
1337 vty
->node
= VTY_NODE
;
1341 DEFUNSH(VTYSH_REALLYALL
, vtysh_enable
, vtysh_enable_cmd
, "enable",
1342 "Turn on privileged mode command\n")
1344 vty
->node
= ENABLE_NODE
;
1348 DEFUNSH(VTYSH_REALLYALL
, vtysh_disable
, vtysh_disable_cmd
, "disable",
1349 "Turn off privileged mode command\n")
1351 if (vty
->node
== ENABLE_NODE
)
1352 vty
->node
= VIEW_NODE
;
1356 DEFUNSH(VTYSH_REALLYALL
, vtysh_config_terminal
, vtysh_config_terminal_cmd
,
1357 "configure terminal",
1358 "Configuration from vty interface\n"
1359 "Configuration terminal\n")
1361 vty
->node
= CONFIG_NODE
;
1365 static int vtysh_exit(struct vty
*vty
)
1367 switch (vty
->node
) {
1373 vty
->node
= ENABLE_NODE
;
1375 case INTERFACE_NODE
:
1387 case LDP_L2VPN_NODE
:
1393 vtysh_execute("end");
1394 vtysh_execute("configure terminal");
1395 vty
->node
= CONFIG_NODE
;
1397 case BGP_VPNV4_NODE
:
1398 case BGP_VPNV6_NODE
:
1400 case BGP_IPV4M_NODE
:
1401 case BGP_IPV4L_NODE
:
1403 case BGP_IPV6M_NODE
:
1404 case BGP_IPV6L_NODE
:
1405 case BGP_VRF_POLICY_NODE
:
1407 case BGP_VNC_DEFAULTS_NODE
:
1408 case BGP_VNC_NVE_GROUP_NODE
:
1409 case BGP_VNC_L2_GROUP_NODE
:
1410 vty
->node
= BGP_NODE
;
1412 case BGP_EVPN_VNI_NODE
:
1413 vty
->node
= BGP_EVPN_NODE
;
1417 vty
->node
= LDP_NODE
;
1419 case LDP_IPV4_IFACE_NODE
:
1420 vty
->node
= LDP_IPV4_NODE
;
1422 case LDP_IPV6_IFACE_NODE
:
1423 vty
->node
= LDP_IPV6_NODE
;
1425 case LDP_PSEUDOWIRE_NODE
:
1426 vty
->node
= LDP_L2VPN_NODE
;
1428 case KEYCHAIN_KEY_NODE
:
1429 vty
->node
= KEYCHAIN_NODE
;
1431 case LINK_PARAMS_NODE
:
1432 vty
->node
= INTERFACE_NODE
;
1440 DEFUNSH(VTYSH_REALLYALL
, vtysh_exit_all
, vtysh_exit_all_cmd
, "exit",
1441 "Exit current mode and down to previous mode\n")
1443 return vtysh_exit(vty
);
1446 DEFUNSH(VTYSH_ALL
, vtysh_quit_all
, vtysh_quit_all_cmd
, "quit",
1447 "Exit current mode and down to previous mode\n")
1449 return vtysh_exit_all(self
, vty
, argc
, argv
);
1452 DEFUNSH(VTYSH_BGPD
, exit_address_family
, exit_address_family_cmd
,
1453 "exit-address-family", "Exit from Address Family configuration mode\n")
1455 if (vty
->node
== BGP_IPV4_NODE
|| vty
->node
== BGP_IPV4M_NODE
1456 || vty
->node
== BGP_IPV4L_NODE
|| vty
->node
== BGP_VPNV4_NODE
1457 || vty
->node
== BGP_VPNV6_NODE
|| vty
->node
== BGP_IPV6_NODE
1458 || vty
->node
== BGP_IPV6L_NODE
|| vty
->node
== BGP_IPV6M_NODE
1459 || vty
->node
== BGP_EVPN_NODE
)
1460 vty
->node
= BGP_NODE
;
1464 DEFUNSH(VTYSH_BGPD
, exit_vni
, exit_vni_cmd
, "exit-vni", "Exit from VNI mode\n")
1466 if (vty
->node
== BGP_EVPN_VNI_NODE
)
1467 vty
->node
= BGP_EVPN_NODE
;
1471 DEFUNSH(VTYSH_BGPD
, exit_vnc_config
, exit_vnc_config_cmd
, "exit-vnc",
1472 "Exit from VNC configuration mode\n")
1474 if (vty
->node
== BGP_VNC_DEFAULTS_NODE
1475 || vty
->node
== BGP_VNC_NVE_GROUP_NODE
1476 || vty
->node
== BGP_VNC_L2_GROUP_NODE
)
1477 vty
->node
= BGP_NODE
;
1481 DEFUNSH(VTYSH_BGPD
, exit_vrf_policy
, exit_vrf_policy_cmd
, "exit-vrf-policy",
1482 "Exit from VRF configuration mode\n")
1484 if (vty
->node
== BGP_VRF_POLICY_NODE
)
1485 vty
->node
= BGP_NODE
;
1489 DEFUNSH(VTYSH_RIPD
, vtysh_exit_ripd
, vtysh_exit_ripd_cmd
, "exit",
1490 "Exit current mode and down to previous mode\n")
1492 return vtysh_exit(vty
);
1495 DEFUNSH(VTYSH_RIPD
, vtysh_quit_ripd
, vtysh_quit_ripd_cmd
, "quit",
1496 "Exit current mode and down to previous mode\n")
1498 return vtysh_exit_ripd(self
, vty
, argc
, argv
);
1501 DEFUNSH(VTYSH_RIPNGD
, vtysh_exit_ripngd
, vtysh_exit_ripngd_cmd
, "exit",
1502 "Exit current mode and down to previous mode\n")
1504 return vtysh_exit(vty
);
1507 DEFUNSH(VTYSH_RIPNGD
, vtysh_quit_ripngd
, vtysh_quit_ripngd_cmd
, "quit",
1508 "Exit current mode and down to previous mode\n")
1510 return vtysh_exit_ripngd(self
, vty
, argc
, argv
);
1513 DEFUNSH(VTYSH_RMAP
, vtysh_exit_rmap
, vtysh_exit_rmap_cmd
, "exit",
1514 "Exit current mode and down to previous mode\n")
1516 return vtysh_exit(vty
);
1519 DEFUNSH(VTYSH_RMAP
, vtysh_quit_rmap
, vtysh_quit_rmap_cmd
, "quit",
1520 "Exit current mode and down to previous mode\n")
1522 return vtysh_exit_rmap(self
, vty
, argc
, argv
);
1525 DEFUNSH(VTYSH_BGPD
, vtysh_exit_bgpd
, vtysh_exit_bgpd_cmd
, "exit",
1526 "Exit current mode and down to previous mode\n")
1528 return vtysh_exit(vty
);
1531 DEFUNSH(VTYSH_BGPD
, vtysh_quit_bgpd
, vtysh_quit_bgpd_cmd
, "quit",
1532 "Exit current mode and down to previous mode\n")
1534 return vtysh_exit_bgpd(self
, vty
, argc
, argv
);
1537 DEFUNSH(VTYSH_OSPFD
, vtysh_exit_ospfd
, vtysh_exit_ospfd_cmd
, "exit",
1538 "Exit current mode and down to previous mode\n")
1540 return vtysh_exit(vty
);
1543 DEFUNSH(VTYSH_OSPFD
, vtysh_quit_ospfd
, vtysh_quit_ospfd_cmd
, "quit",
1544 "Exit current mode and down to previous mode\n")
1546 return vtysh_exit_ospfd(self
, vty
, argc
, argv
);
1549 DEFUNSH(VTYSH_EIGRPD
, vtysh_exit_eigrpd
, vtysh_exit_eigrpd_cmd
, "exit",
1550 "Exit current mode and down to previous mode\n")
1552 return vtysh_exit(vty
);
1555 DEFUNSH(VTYSH_EIGRPD
, vtysh_quit_eigrpd
, vtysh_quit_eigrpd_cmd
, "quit",
1556 "Exit current mode and down to previous mode\n")
1558 return vtysh_exit(vty
);
1561 DEFUNSH(VTYSH_EIGRPD
, vtysh_exit_babeld
, vtysh_exit_babeld_cmd
, "exit",
1562 "Exit current mode and down to previous mode\n")
1564 return vtysh_exit(vty
);
1567 DEFUNSH(VTYSH_BABELD
, vtysh_quit_babeld
, vtysh_quit_babeld_cmd
, "quit",
1568 "Exit current mode and down to previous mode\n")
1570 return vtysh_exit(vty
);
1573 DEFUNSH(VTYSH_OSPF6D
, vtysh_exit_ospf6d
, vtysh_exit_ospf6d_cmd
, "exit",
1574 "Exit current mode and down to previous mode\n")
1576 return vtysh_exit(vty
);
1579 DEFUNSH(VTYSH_OSPF6D
, vtysh_quit_ospf6d
, vtysh_quit_ospf6d_cmd
, "quit",
1580 "Exit current mode and down to previous mode\n")
1582 return vtysh_exit_ospf6d(self
, vty
, argc
, argv
);
1585 #if defined(HAVE_LDPD)
1586 DEFUNSH(VTYSH_LDPD
, vtysh_exit_ldpd
, vtysh_exit_ldpd_cmd
, "exit",
1587 "Exit current mode and down to previous mode\n")
1589 return vtysh_exit(vty
);
1592 ALIAS(vtysh_exit_ldpd
, vtysh_quit_ldpd_cmd
, "quit",
1593 "Exit current mode and down to previous mode\n")
1596 DEFUNSH(VTYSH_ISISD
, vtysh_exit_isisd
, vtysh_exit_isisd_cmd
, "exit",
1597 "Exit current mode and down to previous mode\n")
1599 return vtysh_exit(vty
);
1602 DEFUNSH(VTYSH_ISISD
, vtysh_quit_isisd
, vtysh_quit_isisd_cmd
, "quit",
1603 "Exit current mode and down to previous mode\n")
1605 return vtysh_exit_isisd(self
, vty
, argc
, argv
);
1608 DEFUNSH(VTYSH_ALL
, vtysh_exit_line_vty
, vtysh_exit_line_vty_cmd
, "exit",
1609 "Exit current mode and down to previous mode\n")
1611 return vtysh_exit(vty
);
1614 DEFUNSH(VTYSH_ALL
, vtysh_quit_line_vty
, vtysh_quit_line_vty_cmd
, "quit",
1615 "Exit current mode and down to previous mode\n")
1617 return vtysh_exit_line_vty(self
, vty
, argc
, argv
);
1620 DEFUNSH(VTYSH_INTERFACE
, vtysh_interface
, vtysh_interface_cmd
,
1621 "interface IFNAME [vrf NAME]",
1622 "Select an interface to configure\n"
1623 "Interface's name\n" VRF_CMD_HELP_STR
)
1625 vty
->node
= INTERFACE_NODE
;
1629 /* TODO Implement "no interface command in isisd. */
1630 DEFSH(VTYSH_ZEBRA
| VTYSH_RIPD
| VTYSH_RIPNGD
| VTYSH_OSPFD
| VTYSH_OSPF6D
1632 vtysh_no_interface_cmd
, "no interface IFNAME", NO_STR
1633 "Delete a pseudo interface's configuration\n"
1634 "Interface's name\n")
1636 DEFSH(VTYSH_ZEBRA
, vtysh_no_interface_vrf_cmd
, "no interface IFNAME vrf NAME",
1638 "Delete a pseudo interface's configuration\n"
1639 "Interface's name\n" VRF_CMD_HELP_STR
)
1641 DEFUNSH(VTYSH_NS
, vtysh_ns
, vtysh_ns_cmd
, "logical-router (1-65535) ns NAME",
1642 "Enable a logical-router\n"
1643 "Specify the logical-router indentifier\n"
1645 "The file name in " NS_RUN_DIR
", or a full pathname\n")
1647 vty
->node
= NS_NODE
;
1651 DEFUNSH(VTYSH_VRF
, vtysh_vrf
, vtysh_vrf_cmd
, "vrf NAME",
1652 "Select a VRF to configure\n"
1655 vty
->node
= VRF_NODE
;
1659 DEFSH(VTYSH_ZEBRA
, vtysh_no_vrf_cmd
, "no vrf NAME", NO_STR
1660 "Delete a pseudo vrf's configuration\n"
1663 DEFUNSH(VTYSH_NS
, vtysh_exit_ns
, vtysh_exit_ns_cmd
, "exit",
1664 "Exit current mode and down to previous mode\n")
1666 return vtysh_exit(vty
);
1669 DEFUNSH(VTYSH_NS
, vtysh_quit_ns
, vtysh_quit_ns_cmd
, "quit",
1670 "Exit current mode and down to previous mode\n")
1672 return vtysh_exit_ns(self
, vty
, argc
, argv
);
1675 DEFUNSH(VTYSH_VRF
, vtysh_exit_vrf
, vtysh_exit_vrf_cmd
, "exit",
1676 "Exit current mode and down to previous mode\n")
1678 return vtysh_exit(vty
);
1681 DEFUNSH(VTYSH_VRF
, vtysh_quit_vrf
, vtysh_quit_vrf_cmd
, "quit",
1682 "Exit current mode and down to previous mode\n")
1684 return vtysh_exit_vrf(self
, vty
, argc
, argv
);
1687 /* TODO Implement interface description commands in ripngd, ospf6d
1689 DEFSH(VTYSH_ZEBRA
| VTYSH_RIPD
| VTYSH_OSPFD
| VTYSH_EIGRPD
,
1690 vtysh_interface_desc_cmd
, "description LINE...",
1691 "Interface specific description\n"
1692 "Characters describing this interface\n")
1694 DEFSH(VTYSH_ZEBRA
| VTYSH_RIPD
| VTYSH_OSPFD
| VTYSH_EIGRPD
,
1695 vtysh_no_interface_desc_cmd
, "no description",
1696 NO_STR
"Interface specific description\n")
1698 DEFUNSH(VTYSH_INTERFACE
, vtysh_exit_interface
, vtysh_exit_interface_cmd
, "exit",
1699 "Exit current mode and down to previous mode\n")
1701 return vtysh_exit(vty
);
1704 DEFUNSH(VTYSH_INTERFACE
, vtysh_quit_interface
, vtysh_quit_interface_cmd
, "quit",
1705 "Exit current mode and down to previous mode\n")
1707 return vtysh_exit_interface(self
, vty
, argc
, argv
);
1710 DEFUN (vtysh_show_thread
,
1711 vtysh_show_thread_cmd
,
1712 "show thread cpu [FILTER]",
1714 "Thread information\n"
1715 "Thread CPU usage\n"
1716 "Display filter (rwtexb)\n")
1720 int ret
= CMD_SUCCESS
;
1723 const char *filter
=
1724 argv_find(argv
, argc
, "FILTER", &idx
) ? argv
[idx
]->arg
: "";
1726 snprintf(line
, sizeof(line
), "do show thread cpu %s\n", filter
);
1727 for (i
= 0; i
< array_size(vtysh_client
); i
++)
1728 if (vtysh_client
[i
].fd
>= 0) {
1729 fprintf(stdout
, "Thread statistics for %s:\n",
1730 vtysh_client
[i
].name
);
1731 ret
= vtysh_client_execute(&vtysh_client
[i
], line
,
1733 fprintf(stdout
, "\n");
1738 DEFUN (vtysh_show_work_queues
,
1739 vtysh_show_work_queues_cmd
,
1742 "Work Queue information\n")
1745 int ret
= CMD_SUCCESS
;
1746 char line
[] = "do show work-queues\n";
1748 for (i
= 0; i
< array_size(vtysh_client
); i
++)
1749 if (vtysh_client
[i
].fd
>= 0) {
1750 fprintf(stdout
, "Work queue statistics for %s:\n",
1751 vtysh_client
[i
].name
);
1752 ret
= vtysh_client_execute(&vtysh_client
[i
], line
,
1754 fprintf(stdout
, "\n");
1760 DEFUN (vtysh_show_work_queues_daemon
,
1761 vtysh_show_work_queues_daemon_cmd
,
1762 "show work-queues <zebra|ripd|ripngd|ospfd|ospf6d|bgpd|isisd>",
1764 "Work Queue information\n"
1765 "For the zebra daemon\n"
1766 "For the rip daemon\n"
1767 "For the ripng daemon\n"
1768 "For the ospf daemon\n"
1769 "For the ospfv6 daemon\n"
1770 "For the bgp daemon\n"
1771 "For the isis daemon\n")
1773 int idx_protocol
= 2;
1775 int ret
= CMD_SUCCESS
;
1777 for (i
= 0; i
< array_size(vtysh_client
); i
++) {
1778 if (strmatch(vtysh_client
[i
].name
, argv
[idx_protocol
]->text
))
1782 ret
= vtysh_client_execute(&vtysh_client
[i
], "show work-queues\n",
1788 DEFUN (vtysh_show_hashtable
,
1789 vtysh_show_hashtable_cmd
,
1790 "show hashtable [statistics]",
1792 "Statistics about hash tables\n"
1793 "Statistics about hash tables\n")
1795 char cmd
[] = "do show hashtable statistics";
1797 int ret
= CMD_SUCCESS
;
1799 fprintf(stdout
, "\n");
1801 "Load factor (LF) - average number of elements across all buckets\n");
1803 "Full load factor (FLF) - average number of elements across full buckets\n\n");
1806 "Standard deviation (SD) is calculated for both the LF and FLF\n");
1808 "and indicates the typical deviation of bucket chain length\n");
1809 fprintf(stdout
, "from the value in the corresponding load factor.\n\n");
1811 for (i
= 0; i
< array_size(vtysh_client
); i
++)
1812 if (vtysh_client
[i
].fd
>= 0) {
1813 ret
= vtysh_client_execute(&vtysh_client
[i
], cmd
,
1815 fprintf(stdout
, "\n");
1820 DEFUNSH(VTYSH_ZEBRA
, vtysh_link_params
, vtysh_link_params_cmd
, "link-params",
1823 vty
->node
= LINK_PARAMS_NODE
;
1827 DEFUNSH(VTYSH_ZEBRA
, exit_link_params
, exit_link_params_cmd
, "exit-link-params",
1828 "Exit from Link Params configuration node\n")
1830 if (vty
->node
== LINK_PARAMS_NODE
)
1831 vty
->node
= INTERFACE_NODE
;
1835 static int show_per_daemon(const char *line
, const char *headline
)
1838 int ret
= CMD_SUCCESS
;
1840 for (i
= 0; i
< array_size(vtysh_client
); i
++)
1841 if (vtysh_client
[i
].fd
>= 0) {
1842 fprintf(stdout
, headline
, vtysh_client
[i
].name
);
1843 ret
= vtysh_client_execute(&vtysh_client
[i
], line
,
1845 fprintf(stdout
, "\n");
1852 DEFUN (vtysh_show_memory
,
1853 vtysh_show_memory_cmd
,
1856 "Memory statistics\n")
1858 return show_per_daemon("show memory\n", "Memory statistics for %s:\n");
1861 DEFUN (vtysh_show_modules
,
1862 vtysh_show_modules_cmd
,
1867 return show_per_daemon("show modules\n",
1868 "Module information for %s:\n");
1871 /* Logging commands. */
1872 DEFUN (vtysh_show_logging
,
1873 vtysh_show_logging_cmd
,
1876 "Show current logging configuration\n")
1879 int ret
= CMD_SUCCESS
;
1880 char line
[] = "do show logging\n";
1882 for (i
= 0; i
< array_size(vtysh_client
); i
++)
1883 if (vtysh_client
[i
].fd
>= 0) {
1884 fprintf(stdout
, "Logging configuration for %s:\n",
1885 vtysh_client
[i
].name
);
1886 ret
= vtysh_client_execute(&vtysh_client
[i
], line
,
1888 fprintf(stdout
, "\n");
1894 DEFUNSH(VTYSH_ALL
, vtysh_log_stdout
, vtysh_log_stdout_cmd
, "log stdout",
1896 "Set stdout logging level\n")
1901 DEFUNSH(VTYSH_ALL
, vtysh_log_stdout_level
, vtysh_log_stdout_level_cmd
,
1902 "log stdout <emergencies|alerts|critical|errors|warnings|notifications|informational|debugging>",
1904 "Set stdout logging level\n" LOG_LEVEL_DESC
)
1909 DEFUNSH(VTYSH_ALL
, no_vtysh_log_stdout
, no_vtysh_log_stdout_cmd
,
1910 "no log stdout [LEVEL]", NO_STR
1912 "Cancel logging to stdout\n"
1918 DEFUNSH(VTYSH_ALL
, vtysh_log_file
, vtysh_log_file_cmd
, "log file FILENAME",
1921 "Logging filename\n")
1926 DEFUNSH(VTYSH_ALL
, vtysh_log_file_level
, vtysh_log_file_level_cmd
,
1927 "log file FILENAME <emergencies|alerts|critical|errors|warnings|notifications|informational|debugging>",
1930 "Logging filename\n" LOG_LEVEL_DESC
)
1935 DEFUNSH(VTYSH_ALL
, no_vtysh_log_file
, no_vtysh_log_file_cmd
,
1936 "no log file [FILENAME [LEVEL]]", NO_STR
1938 "Cancel logging to file\n"
1939 "Logging file name\n"
1945 DEFUNSH(VTYSH_ALL
, vtysh_log_monitor
, vtysh_log_monitor_cmd
,
1946 "log monitor [<emergencies|alerts|critical|errors|warnings|notifications|informational|debugging>]",
1948 "Set terminal line (monitor) logging level\n" LOG_LEVEL_DESC
)
1953 DEFUNSH(VTYSH_ALL
, no_vtysh_log_monitor
, no_vtysh_log_monitor_cmd
,
1954 "no log monitor [LEVEL]", NO_STR
1956 "Disable terminal line (monitor) logging\n"
1962 DEFUNSH(VTYSH_ALL
, vtysh_log_syslog
, vtysh_log_syslog_cmd
,
1963 "log syslog [<emergencies|alerts|critical|errors|warnings|notifications|informational|debugging>]",
1965 "Set syslog logging level\n" LOG_LEVEL_DESC
)
1970 DEFUNSH(VTYSH_ALL
, no_vtysh_log_syslog
, no_vtysh_log_syslog_cmd
,
1971 "no log syslog [LEVEL]", NO_STR
1973 "Cancel logging to syslog\n"
1979 DEFUNSH(VTYSH_ALL
, vtysh_log_facility
, vtysh_log_facility_cmd
,
1980 "log facility <kern|user|mail|daemon|auth|syslog|lpr|news|uucp|cron|local0|local1|local2|local3|local4|local5|local6|local7>",
1982 "Facility parameter for syslog messages\n" LOG_FACILITY_DESC
)
1988 DEFUNSH(VTYSH_ALL
, no_vtysh_log_facility
, no_vtysh_log_facility_cmd
,
1989 "no log facility [FACILITY]", NO_STR
1991 "Reset syslog facility to default (daemon)\n"
1992 "Syslog facility\n")
1999 VTYSH_ALL
, vtysh_log_trap
, vtysh_log_trap_cmd
,
2000 "log trap <emergencies|alerts|critical|errors|warnings|notifications|informational|debugging>",
2002 "(Deprecated) Set logging level and default for all destinations\n" LOG_LEVEL_DESC
)
2008 DEFUNSH_DEPRECATED(VTYSH_ALL
, no_vtysh_log_trap
, no_vtysh_log_trap_cmd
,
2009 "no log trap [LEVEL]", NO_STR
2011 "Permit all logging information\n"
2017 DEFUNSH(VTYSH_ALL
, vtysh_log_record_priority
, vtysh_log_record_priority_cmd
,
2018 "log record-priority",
2020 "Log the priority of the message within the message\n")
2025 DEFUNSH(VTYSH_ALL
, no_vtysh_log_record_priority
,
2026 no_vtysh_log_record_priority_cmd
, "no log record-priority", NO_STR
2028 "Do not log the priority of the message within the message\n")
2033 DEFUNSH(VTYSH_ALL
, vtysh_log_timestamp_precision
,
2034 vtysh_log_timestamp_precision_cmd
, "log timestamp precision (0-6)",
2036 "Timestamp configuration\n"
2037 "Set the timestamp precision\n"
2038 "Number of subsecond digits\n")
2043 DEFUNSH(VTYSH_ALL
, no_vtysh_log_timestamp_precision
,
2044 no_vtysh_log_timestamp_precision_cmd
, "no log timestamp precision",
2047 "Timestamp configuration\n"
2048 "Reset the timestamp precision to the default value of 0\n")
2053 DEFUNSH(VTYSH_ALL
, vtysh_service_password_encrypt
,
2054 vtysh_service_password_encrypt_cmd
, "service password-encryption",
2055 "Set up miscellaneous service\n"
2056 "Enable encrypted passwords\n")
2061 DEFUNSH(VTYSH_ALL
, no_vtysh_service_password_encrypt
,
2062 no_vtysh_service_password_encrypt_cmd
, "no service password-encryption",
2064 "Set up miscellaneous service\n"
2065 "Enable encrypted passwords\n")
2070 DEFUNSH(VTYSH_ALL
, vtysh_config_password
, vtysh_password_cmd
,
2071 "password [(8-8)] LINE",
2072 "Assign the terminal connection password\n"
2073 "Specifies a HIDDEN password will follow\n"
2074 "The password string\n")
2079 DEFUNSH(VTYSH_ALL
, vtysh_config_enable_password
, vtysh_enable_password_cmd
,
2080 "enable password [(8-8)] LINE",
2081 "Modify enable password parameters\n"
2082 "Assign the privileged level password\n"
2083 "Specifies a HIDDEN password will follow\n"
2084 "The 'enable' password string\n")
2089 DEFUNSH(VTYSH_ALL
, no_vtysh_config_enable_password
,
2090 no_vtysh_enable_password_cmd
, "no enable password", NO_STR
2091 "Modify enable password parameters\n"
2092 "Assign the privileged level password\n")
2097 DEFUN (vtysh_write_terminal
,
2098 vtysh_write_terminal_cmd
,
2099 "write terminal [<zebra|ripd|ripngd|ospfd|ospf6d|ldpd|bgpd|isisd|pimd>]",
2100 "Write running configuration to memory, network, or terminal\n"
2101 "Write to terminal\n"
2102 "For the zebra daemon\n"
2103 "For the rip daemon\n"
2104 "For the ripng daemon\n"
2105 "For the ospf daemon\n"
2106 "For the ospfv6 daemon\n"
2107 "For the ldpd daemon\n"
2108 "For the bgp daemon\n"
2109 "For the isis daemon\n"
2110 "For the pim daemon\n")
2113 char line
[] = "do write terminal\n";
2116 if (vtysh_pager_name
) {
2117 fp
= popen(vtysh_pager_name
, "w");
2125 vty_out(vty
, "Building configuration...\n");
2126 vty_out(vty
, "\nCurrent configuration:\n");
2127 vty_out(vty
, "!\n");
2129 for (i
= 0; i
< array_size(vtysh_client
); i
++)
2131 || (strmatch(vtysh_client
[i
].name
, argv
[2]->text
)))
2132 vtysh_client_config(&vtysh_client
[i
], line
);
2134 /* Integrate vtysh specific configuration. */
2135 vtysh_config_write();
2137 vtysh_config_dump(fp
);
2139 if (vtysh_pager_name
&& fp
) {
2141 if (pclose(fp
) == -1) {
2148 vty_out(vty
, "end\n");
2152 DEFUN (vtysh_show_running_config
,
2153 vtysh_show_running_config_cmd
,
2154 "show running-config [<zebra|ripd|ripngd|ospfd|ospf6d|ldpd|bgpd|isisd|pimd>]",
2156 "Current operating configuration\n"
2157 "For the zebra daemon\n"
2158 "For the rip daemon\n"
2159 "For the ripng daemon\n"
2160 "For the ospf daemon\n"
2161 "For the ospfv6 daemon\n"
2162 "For the ldp daemon\n"
2163 "For the bgp daemon\n"
2164 "For the isis daemon\n"
2165 "For the pim daemon\n")
2167 return vtysh_write_terminal(self
, vty
, argc
, argv
);
2170 DEFUN (vtysh_integrated_config
,
2171 vtysh_integrated_config_cmd
,
2172 "service integrated-vtysh-config",
2173 "Set up miscellaneous service\n"
2174 "Write configuration into integrated file\n")
2176 vtysh_write_integrated
= WRITE_INTEGRATED_YES
;
2180 DEFUN (no_vtysh_integrated_config
,
2181 no_vtysh_integrated_config_cmd
,
2182 "no service integrated-vtysh-config",
2184 "Set up miscellaneous service\n"
2185 "Write configuration into integrated file\n")
2187 vtysh_write_integrated
= WRITE_INTEGRATED_NO
;
2191 static void backup_config_file(const char *fbackup
)
2193 char *integrate_sav
= NULL
;
2195 integrate_sav
= malloc(strlen(fbackup
) + strlen(CONF_BACKUP_EXT
) + 1);
2196 strcpy(integrate_sav
, fbackup
);
2197 strcat(integrate_sav
, CONF_BACKUP_EXT
);
2199 /* Move current configuration file to backup config file. */
2200 unlink(integrate_sav
);
2201 rename(fbackup
, integrate_sav
);
2202 free(integrate_sav
);
2205 int vtysh_write_config_integrated(void)
2208 char line
[] = "do write terminal\n";
2211 struct passwd
*pwentry
;
2212 struct group
*grentry
;
2218 fprintf(stdout
, "Building Configuration...\n");
2220 backup_config_file(quagga_config
);
2221 fp
= fopen(quagga_config
, "w");
2224 "%% Error: failed to open configuration file %s: %s\n",
2225 quagga_config
, safe_strerror(errno
));
2226 return CMD_WARNING_CONFIG_FAILED
;
2230 for (i
= 0; i
< array_size(vtysh_client
); i
++)
2231 vtysh_client_config(&vtysh_client
[i
], line
);
2233 vtysh_config_write();
2234 vtysh_config_dump(fp
);
2236 if (fchmod(fd
, CONFIGFILE_MASK
) != 0) {
2237 printf("%% Warning: can't chmod configuration file %s: %s\n",
2238 quagga_config
, safe_strerror(errno
));
2243 pwentry
= getpwnam(FRR_USER
);
2245 uid
= pwentry
->pw_uid
;
2247 printf("%% Warning: could not look up user \"%s\"\n", FRR_USER
);
2252 grentry
= getgrnam(FRR_GROUP
);
2254 gid
= grentry
->gr_gid
;
2256 printf("%% Warning: could not look up group \"%s\"\n",
2262 if (!fstat(fd
, &st
)) {
2263 if (st
.st_uid
== uid
)
2265 if (st
.st_gid
== gid
)
2267 if ((uid
!= (uid_t
)-1 || gid
!= (gid_t
)-1)
2268 && fchown(fd
, uid
, gid
)) {
2269 printf("%% Warning: can't chown configuration file %s: %s\n",
2270 quagga_config
, safe_strerror(errno
));
2274 printf("%% Warning: stat() failed on %s: %s\n", quagga_config
,
2275 safe_strerror(errno
));
2281 printf("Integrated configuration saved to %s\n", quagga_config
);
2289 static bool want_config_integrated(void)
2293 switch (vtysh_write_integrated
) {
2294 case WRITE_INTEGRATED_UNSPECIFIED
:
2295 if (stat(quagga_config
, &s
) && errno
== ENOENT
)
2298 case WRITE_INTEGRATED_NO
:
2300 case WRITE_INTEGRATED_YES
:
2306 DEFUN (vtysh_write_memory
,
2307 vtysh_write_memory_cmd
,
2308 "write [<memory|file>]",
2309 "Write running configuration to memory, network, or terminal\n"
2310 "Write configuration to the file (same as write file)\n"
2311 "Write configuration to the file (same as write memory)\n")
2313 int ret
= CMD_SUCCESS
;
2314 char line
[] = "do write memory\n";
2318 "Note: this version of vtysh never writes vtysh.conf\n");
2320 /* If integrated frr.conf explicitely set. */
2321 if (want_config_integrated()) {
2322 ret
= CMD_WARNING_CONFIG_FAILED
;
2323 for (i
= 0; i
< array_size(vtysh_client
); i
++)
2324 if (vtysh_client
[i
].flag
== VTYSH_WATCHFRR
)
2326 if (i
< array_size(vtysh_client
) && vtysh_client
[i
].fd
!= -1)
2327 ret
= vtysh_client_execute(&vtysh_client
[i
],
2328 "do write integrated",
2331 if (ret
!= CMD_SUCCESS
) {
2332 printf("\nWarning: attempting direct configuration write without "
2333 "watchfrr.\nFile permissions and ownership may be "
2334 "incorrect, or write may fail.\n\n");
2335 ret
= vtysh_write_config_integrated();
2340 fprintf(stdout
, "Building Configuration...\n");
2342 for (i
= 0; i
< array_size(vtysh_client
); i
++)
2343 ret
= vtysh_client_execute(&vtysh_client
[i
], line
, stdout
);
2348 DEFUN (vtysh_copy_running_config
,
2349 vtysh_copy_running_config_cmd
,
2350 "copy running-config startup-config",
2351 "Copy from one file to another\n"
2352 "Copy from current system configuration\n"
2353 "Copy to startup configuration\n")
2355 return vtysh_write_memory(self
, vty
, argc
, argv
);
2358 DEFUN (vtysh_terminal_length
,
2359 vtysh_terminal_length_cmd
,
2360 "terminal length (0-512)",
2361 "Set terminal line parameters\n"
2362 "Set number of lines on a screen\n"
2363 "Number of lines on screen (0 for no pausing)\n")
2367 char *endptr
= NULL
;
2368 char default_pager
[10];
2370 lines
= strtol(argv
[idx_number
]->arg
, &endptr
, 10);
2371 if (lines
< 0 || lines
> 512 || *endptr
!= '\0') {
2372 vty_out(vty
, "length is malformed\n");
2376 if (vtysh_pager_name
) {
2377 free(vtysh_pager_name
);
2378 vtysh_pager_name
= NULL
;
2382 snprintf(default_pager
, 10, "more -%i", lines
);
2383 vtysh_pager_name
= strdup(default_pager
);
2389 DEFUN (vtysh_terminal_no_length
,
2390 vtysh_terminal_no_length_cmd
,
2391 "terminal no length",
2392 "Set terminal line parameters\n"
2394 "Set number of lines on a screen\n")
2396 if (vtysh_pager_name
) {
2397 free(vtysh_pager_name
);
2398 vtysh_pager_name
= NULL
;
2405 DEFUN (vtysh_show_daemons
,
2406 vtysh_show_daemons_cmd
,
2409 "Show list of running daemons\n")
2413 for (i
= 0; i
< array_size(vtysh_client
); i
++)
2414 if (vtysh_client
[i
].fd
>= 0)
2415 vty_out(vty
, " %s", vtysh_client
[i
].name
);
2421 /* Execute command in child process. */
2422 static void execute_command(const char *command
, int argc
,
2423 struct cmd_token
*arg1
, const char *arg2
)
2432 /* Failure of fork(). */
2433 fprintf(stderr
, "Can't fork: %s\n", safe_strerror(errno
));
2435 } else if (pid
== 0) {
2436 /* This is child process. */
2439 execlp(command
, command
, (const char *)NULL
);
2442 execlp(command
, command
, arg1
, (const char *)NULL
);
2445 execlp(command
, command
, arg1
, arg2
,
2446 (const char *)NULL
);
2450 /* When execlp suceed, this part is not executed. */
2451 fprintf(stderr
, "Can't execute %s: %s\n", command
,
2452 safe_strerror(errno
));
2455 /* This is parent. */
2457 wait4(pid
, &status
, 0, NULL
);
2465 "Send echo messages\n"
2466 "Ping destination address or hostname\n")
2468 execute_command("ping", 1, argv
[0], NULL
);
2472 ALIAS(vtysh_ping
, vtysh_ping_ip_cmd
, "ping ip WORD",
2473 "Send echo messages\n"
2475 "Ping destination address or hostname\n")
2477 DEFUN (vtysh_traceroute
,
2478 vtysh_traceroute_cmd
,
2480 "Trace route to destination\n"
2481 "Trace route to destination address or hostname\n")
2483 execute_command("traceroute", 1, argv
[0], NULL
);
2487 ALIAS(vtysh_traceroute
, vtysh_traceroute_ip_cmd
, "traceroute ip WORD",
2488 "Trace route to destination\n"
2490 "Trace route to destination address or hostname\n")
2495 "Send echo messages\n"
2497 "Ping destination address or hostname\n")
2499 execute_command("ping6", 1, argv
[0], NULL
);
2503 DEFUN (vtysh_traceroute6
,
2504 vtysh_traceroute6_cmd
,
2505 "traceroute ipv6 WORD",
2506 "Trace route to destination\n"
2508 "Trace route to destination address or hostname\n")
2510 execute_command("traceroute6", 1, argv
[0], NULL
);
2514 #if defined(HAVE_SHELL_ACCESS)
2515 DEFUN (vtysh_telnet
,
2518 "Open a telnet connection\n"
2519 "IP address or hostname of a remote system\n")
2521 execute_command("telnet", 1, argv
[0], NULL
);
2525 DEFUN (vtysh_telnet_port
,
2526 vtysh_telnet_port_cmd
,
2528 "Open a telnet connection\n"
2529 "IP address or hostname of a remote system\n"
2530 "TCP Port number\n")
2532 execute_command("telnet", 2, argv
[0], argv
[1]);
2539 "Open an ssh connection\n"
2542 execute_command("ssh", 1, argv
[0], NULL
);
2546 DEFUN (vtysh_start_shell
,
2547 vtysh_start_shell_cmd
,
2549 "Start UNIX shell\n")
2551 execute_command("sh", 0, NULL
, NULL
);
2555 DEFUN (vtysh_start_bash
,
2556 vtysh_start_bash_cmd
,
2558 "Start UNIX shell\n"
2561 execute_command("bash", 0, NULL
, NULL
);
2565 DEFUN (vtysh_start_zsh
,
2566 vtysh_start_zsh_cmd
,
2568 "Start UNIX shell\n"
2571 execute_command("zsh", 0, NULL
, NULL
);
2578 "list [permutations]",
2579 "Print command list\n"
2580 "Print all possible command permutations\n")
2582 return cmd_list_cmds(vty
, argc
== 2);
2585 static void vtysh_install_default(enum node_type node
)
2587 install_element(node
, &config_list_cmd
);
2590 /* Making connection to protocol daemon. */
2591 static int vtysh_connect(struct vtysh_client
*vclient
)
2595 struct sockaddr_un addr
;
2599 if (!vclient
->path
[0])
2600 snprintf(vclient
->path
, sizeof(vclient
->path
), "%s/%s.vty",
2601 vty_sock_path
, vclient
->name
);
2602 path
= vclient
->path
;
2604 /* Stat socket to see if we have permission to access it. */
2605 ret
= stat(path
, &s_stat
);
2606 if (ret
< 0 && errno
!= ENOENT
) {
2607 fprintf(stderr
, "vtysh_connect(%s): stat = %s\n", path
,
2608 safe_strerror(errno
));
2613 if (!S_ISSOCK(s_stat
.st_mode
)) {
2614 fprintf(stderr
, "vtysh_connect(%s): Not a socket\n",
2620 sock
= socket(AF_UNIX
, SOCK_STREAM
, 0);
2623 fprintf(stderr
, "vtysh_connect(%s): socket = %s\n", path
,
2624 safe_strerror(errno
));
2629 memset(&addr
, 0, sizeof(struct sockaddr_un
));
2630 addr
.sun_family
= AF_UNIX
;
2631 strlcpy(addr
.sun_path
, path
, sizeof(addr
.sun_path
));
2632 #ifdef HAVE_STRUCT_SOCKADDR_UN_SUN_LEN
2633 len
= addr
.sun_len
= SUN_LEN(&addr
);
2635 len
= sizeof(addr
.sun_family
) + strlen(addr
.sun_path
);
2636 #endif /* HAVE_STRUCT_SOCKADDR_UN_SUN_LEN */
2638 ret
= connect(sock
, (struct sockaddr
*)&addr
, len
);
2641 fprintf(stderr
, "vtysh_connect(%s): connect = %s\n", path
,
2642 safe_strerror(errno
));
2652 /* Return true if str ends with suffix, else return false */
2653 static int ends_with(const char *str
, const char *suffix
)
2655 if (!str
|| !suffix
)
2657 size_t lenstr
= strlen(str
);
2658 size_t lensuffix
= strlen(suffix
);
2659 if (lensuffix
> lenstr
)
2661 return strncmp(str
+ lenstr
- lensuffix
, suffix
, lensuffix
) == 0;
2664 static void vtysh_client_sorted_insert(struct vtysh_client
*head_client
,
2665 struct vtysh_client
*client
)
2667 struct vtysh_client
*prev_node
, *current_node
;
2669 prev_node
= head_client
;
2670 current_node
= head_client
->next
;
2671 while (current_node
) {
2672 if (strcmp(current_node
->path
, client
->path
) > 0)
2675 prev_node
= current_node
;
2676 current_node
= current_node
->next
;
2678 client
->next
= current_node
;
2679 prev_node
->next
= client
;
2682 #define MAXIMUM_INSTANCES 10
2684 static void vtysh_update_all_insances(struct vtysh_client
*head_client
)
2686 struct vtysh_client
*client
;
2688 struct dirent
*file
;
2691 if (head_client
->flag
!= VTYSH_OSPFD
)
2694 /* ls vty_sock_dir and look for all files ending in .vty */
2695 dir
= opendir(vty_sock_path
);
2697 while ((file
= readdir(dir
)) != NULL
) {
2698 if (begins_with(file
->d_name
, "ospfd-")
2699 && ends_with(file
->d_name
, ".vty")) {
2700 if (n
== MAXIMUM_INSTANCES
) {
2702 "Parsing %s, client limit(%d) reached!\n",
2706 client
= (struct vtysh_client
*)malloc(
2707 sizeof(struct vtysh_client
));
2709 client
->name
= "ospfd";
2710 client
->flag
= VTYSH_OSPFD
;
2711 snprintf(client
->path
, sizeof(client
->path
),
2712 "%s/%s", vty_sock_path
, file
->d_name
);
2713 client
->next
= NULL
;
2714 vtysh_client_sorted_insert(head_client
, client
);
2722 static int vtysh_connect_all_instances(struct vtysh_client
*head_client
)
2724 struct vtysh_client
*client
;
2727 vtysh_update_all_insances(head_client
);
2729 client
= head_client
->next
;
2731 if (vtysh_connect(client
) == 0)
2733 client
= client
->next
;
2739 int vtysh_connect_all(const char *daemon_name
)
2745 for (i
= 0; i
< array_size(vtysh_client
); i
++) {
2747 || !strcmp(daemon_name
, vtysh_client
[i
].name
)) {
2749 if (vtysh_connect(&vtysh_client
[i
]) == 0)
2752 rc
+= vtysh_connect_all_instances(&vtysh_client
[i
]);
2756 fprintf(stderr
, "Error: no daemons match name %s!\n",
2761 /* To disable readline's filename completion. */
2762 static char *vtysh_completion_entry_function(const char *ignore
,
2768 void vtysh_readline_init(void)
2770 /* readline related settings. */
2772 rl_bind_key('?', (rl_command_func_t
*)vtysh_rl_describe
);
2773 rl_completion_entry_function
= vtysh_completion_entry_function
;
2774 rl_attempted_completion_function
=
2775 (rl_completion_func_t
*)new_completion
;
2778 char *vtysh_prompt(void)
2780 static struct utsname names
;
2781 static char buf
[100];
2782 const char *hostname
;
2783 extern struct host host
;
2785 hostname
= host
.name
;
2788 if (!names
.nodename
[0])
2790 hostname
= names
.nodename
;
2793 snprintf(buf
, sizeof buf
, cmd_prompt(vty
->node
), hostname
);
2798 static void vtysh_ac_line(void *arg
, const char *line
)
2802 for (i
= 0; i
< vector_active(comps
); i
++)
2803 if (!strcmp(line
, (char *)vector_slot(comps
, i
)))
2805 vector_set(comps
, XSTRDUP(MTYPE_COMPLETION
, line
));
2808 static void vtysh_autocomplete(vector comps
, struct cmd_token
*token
)
2813 snprintf(accmd
, sizeof(accmd
), "autocomplete %d %s %s", token
->type
,
2814 token
->text
, token
->varname
? token
->varname
: "-");
2816 for (i
= 0; i
< array_size(vtysh_client
); i
++)
2817 vtysh_client_run_all(&vtysh_client
[i
], accmd
, 1, NULL
,
2818 vtysh_ac_line
, comps
);
2821 static const struct cmd_variable_handler vtysh_var_handler
[] = {
2825 .completions
= vtysh_autocomplete
},
2826 {.completions
= NULL
}};
2828 void vtysh_init_vty(void)
2830 /* Make vty structure. */
2832 vty
->type
= VTY_SHELL
;
2833 vty
->node
= VIEW_NODE
;
2835 /* Initialize commands. */
2837 cmd_variable_handler_register(vtysh_var_handler
);
2839 /* Install nodes. */
2840 install_node(&bgp_node
, NULL
);
2841 install_node(&rip_node
, NULL
);
2842 install_node(&interface_node
, NULL
);
2843 install_node(&link_params_node
, NULL
);
2844 install_node(&ns_node
, NULL
);
2845 install_node(&vrf_node
, NULL
);
2846 install_node(&rmap_node
, NULL
);
2847 install_node(&zebra_node
, NULL
);
2848 install_node(&bgp_vpnv4_node
, NULL
);
2849 install_node(&bgp_vpnv6_node
, NULL
);
2850 install_node(&bgp_ipv4_node
, NULL
);
2851 install_node(&bgp_ipv4m_node
, NULL
);
2852 install_node(&bgp_ipv4l_node
, NULL
);
2853 install_node(&bgp_ipv6_node
, NULL
);
2854 install_node(&bgp_ipv6m_node
, NULL
);
2855 install_node(&bgp_ipv6l_node
, NULL
);
2856 install_node(&bgp_vrf_policy_node
, NULL
);
2857 install_node(&bgp_evpn_node
, NULL
);
2858 install_node(&bgp_evpn_vni_node
, NULL
);
2859 install_node(&bgp_vnc_defaults_node
, NULL
);
2860 install_node(&bgp_vnc_nve_group_node
, NULL
);
2861 install_node(&bgp_vnc_l2_group_node
, NULL
);
2862 install_node(&ospf_node
, NULL
);
2863 install_node(&eigrp_node
, NULL
);
2864 install_node(&babel_node
, NULL
);
2865 install_node(&ripng_node
, NULL
);
2866 install_node(&ospf6_node
, NULL
);
2867 install_node(&ldp_node
, NULL
);
2868 install_node(&ldp_ipv4_node
, NULL
);
2869 install_node(&ldp_ipv6_node
, NULL
);
2870 install_node(&ldp_ipv4_iface_node
, NULL
);
2871 install_node(&ldp_ipv6_iface_node
, NULL
);
2872 install_node(&ldp_l2vpn_node
, NULL
);
2873 install_node(&ldp_pseudowire_node
, NULL
);
2874 install_node(&keychain_node
, NULL
);
2875 install_node(&keychain_key_node
, NULL
);
2876 install_node(&isis_node
, NULL
);
2877 install_node(&vty_node
, NULL
);
2879 vtysh_install_default(VIEW_NODE
);
2880 vtysh_install_default(CONFIG_NODE
);
2881 vtysh_install_default(BGP_NODE
);
2882 vtysh_install_default(RIP_NODE
);
2883 vtysh_install_default(INTERFACE_NODE
);
2884 vtysh_install_default(LINK_PARAMS_NODE
);
2885 vtysh_install_default(NS_NODE
);
2886 vtysh_install_default(VRF_NODE
);
2887 vtysh_install_default(RMAP_NODE
);
2888 vtysh_install_default(ZEBRA_NODE
);
2889 vtysh_install_default(BGP_VPNV4_NODE
);
2890 vtysh_install_default(BGP_VPNV6_NODE
);
2891 vtysh_install_default(BGP_IPV4_NODE
);
2892 vtysh_install_default(BGP_IPV4M_NODE
);
2893 vtysh_install_default(BGP_IPV4L_NODE
);
2894 vtysh_install_default(BGP_IPV6_NODE
);
2895 vtysh_install_default(BGP_IPV6M_NODE
);
2896 vtysh_install_default(BGP_EVPN_NODE
);
2897 vtysh_install_default(BGP_EVPN_VNI_NODE
);
2898 vtysh_install_default(BGP_IPV6L_NODE
);
2900 vtysh_install_default(BGP_VRF_POLICY_NODE
);
2901 vtysh_install_default(BGP_VNC_DEFAULTS_NODE
);
2902 vtysh_install_default(BGP_VNC_NVE_GROUP_NODE
);
2903 vtysh_install_default(BGP_VNC_L2_GROUP_NODE
);
2905 vtysh_install_default(OSPF_NODE
);
2906 vtysh_install_default(EIGRP_NODE
);
2907 vtysh_install_default(BABEL_NODE
);
2908 vtysh_install_default(RIPNG_NODE
);
2909 vtysh_install_default(OSPF6_NODE
);
2910 vtysh_install_default(LDP_NODE
);
2911 vtysh_install_default(LDP_IPV4_NODE
);
2912 vtysh_install_default(LDP_IPV6_NODE
);
2913 vtysh_install_default(LDP_IPV4_IFACE_NODE
);
2914 vtysh_install_default(LDP_IPV6_IFACE_NODE
);
2915 vtysh_install_default(LDP_L2VPN_NODE
);
2916 vtysh_install_default(LDP_PSEUDOWIRE_NODE
);
2917 vtysh_install_default(ISIS_NODE
);
2918 vtysh_install_default(KEYCHAIN_NODE
);
2919 vtysh_install_default(KEYCHAIN_KEY_NODE
);
2920 vtysh_install_default(VTY_NODE
);
2922 install_element(VIEW_NODE
, &vtysh_enable_cmd
);
2923 install_element(ENABLE_NODE
, &vtysh_config_terminal_cmd
);
2924 install_element(ENABLE_NODE
, &vtysh_disable_cmd
);
2926 /* "exit" command. */
2927 install_element(VIEW_NODE
, &vtysh_exit_all_cmd
);
2928 install_element(CONFIG_NODE
, &vtysh_exit_all_cmd
);
2929 install_element(VIEW_NODE
, &vtysh_quit_all_cmd
);
2930 install_element(CONFIG_NODE
, &vtysh_quit_all_cmd
);
2931 install_element(RIP_NODE
, &vtysh_exit_ripd_cmd
);
2932 install_element(RIP_NODE
, &vtysh_quit_ripd_cmd
);
2933 install_element(RIPNG_NODE
, &vtysh_exit_ripngd_cmd
);
2934 install_element(RIPNG_NODE
, &vtysh_quit_ripngd_cmd
);
2935 install_element(OSPF_NODE
, &vtysh_exit_ospfd_cmd
);
2936 install_element(OSPF_NODE
, &vtysh_quit_ospfd_cmd
);
2937 install_element(EIGRP_NODE
, &vtysh_exit_eigrpd_cmd
);
2938 install_element(EIGRP_NODE
, &vtysh_quit_eigrpd_cmd
);
2939 install_element(BABEL_NODE
, &vtysh_exit_babeld_cmd
);
2940 install_element(BABEL_NODE
, &vtysh_quit_babeld_cmd
);
2941 install_element(OSPF6_NODE
, &vtysh_exit_ospf6d_cmd
);
2942 install_element(OSPF6_NODE
, &vtysh_quit_ospf6d_cmd
);
2943 #if defined(HAVE_LDPD)
2944 install_element(LDP_NODE
, &vtysh_exit_ldpd_cmd
);
2945 install_element(LDP_NODE
, &vtysh_quit_ldpd_cmd
);
2946 install_element(LDP_IPV4_NODE
, &vtysh_exit_ldpd_cmd
);
2947 install_element(LDP_IPV4_NODE
, &vtysh_quit_ldpd_cmd
);
2948 install_element(LDP_IPV6_NODE
, &vtysh_exit_ldpd_cmd
);
2949 install_element(LDP_IPV6_NODE
, &vtysh_quit_ldpd_cmd
);
2950 install_element(LDP_IPV4_IFACE_NODE
, &vtysh_exit_ldpd_cmd
);
2951 install_element(LDP_IPV4_IFACE_NODE
, &vtysh_quit_ldpd_cmd
);
2952 install_element(LDP_IPV6_IFACE_NODE
, &vtysh_exit_ldpd_cmd
);
2953 install_element(LDP_IPV6_IFACE_NODE
, &vtysh_quit_ldpd_cmd
);
2954 install_element(LDP_L2VPN_NODE
, &vtysh_exit_ldpd_cmd
);
2955 install_element(LDP_L2VPN_NODE
, &vtysh_quit_ldpd_cmd
);
2956 install_element(LDP_PSEUDOWIRE_NODE
, &vtysh_exit_ldpd_cmd
);
2957 install_element(LDP_PSEUDOWIRE_NODE
, &vtysh_quit_ldpd_cmd
);
2959 install_element(BGP_NODE
, &vtysh_exit_bgpd_cmd
);
2960 install_element(BGP_NODE
, &vtysh_quit_bgpd_cmd
);
2961 install_element(BGP_VPNV4_NODE
, &vtysh_exit_bgpd_cmd
);
2962 install_element(BGP_VPNV4_NODE
, &vtysh_quit_bgpd_cmd
);
2963 install_element(BGP_VPNV6_NODE
, &vtysh_exit_bgpd_cmd
);
2964 install_element(BGP_VPNV6_NODE
, &vtysh_quit_bgpd_cmd
);
2965 install_element(BGP_IPV4_NODE
, &vtysh_exit_bgpd_cmd
);
2966 install_element(BGP_IPV4_NODE
, &vtysh_quit_bgpd_cmd
);
2967 install_element(BGP_IPV4M_NODE
, &vtysh_exit_bgpd_cmd
);
2968 install_element(BGP_IPV4M_NODE
, &vtysh_quit_bgpd_cmd
);
2969 install_element(BGP_IPV4L_NODE
, &vtysh_exit_bgpd_cmd
);
2970 install_element(BGP_IPV4L_NODE
, &vtysh_quit_bgpd_cmd
);
2971 install_element(BGP_IPV6_NODE
, &vtysh_exit_bgpd_cmd
);
2972 install_element(BGP_IPV6_NODE
, &vtysh_quit_bgpd_cmd
);
2973 install_element(BGP_IPV6M_NODE
, &vtysh_exit_bgpd_cmd
);
2974 install_element(BGP_IPV6M_NODE
, &vtysh_quit_bgpd_cmd
);
2975 install_element(BGP_EVPN_NODE
, &vtysh_quit_bgpd_cmd
);
2976 install_element(BGP_EVPN_NODE
, &vtysh_exit_bgpd_cmd
);
2977 install_element(BGP_EVPN_VNI_NODE
, &vtysh_exit_bgpd_cmd
);
2978 install_element(BGP_EVPN_VNI_NODE
, &vtysh_quit_bgpd_cmd
);
2979 install_element(BGP_IPV6L_NODE
, &vtysh_exit_bgpd_cmd
);
2980 install_element(BGP_IPV6L_NODE
, &vtysh_quit_bgpd_cmd
);
2981 #if defined(ENABLE_BGP_VNC)
2982 install_element(BGP_VRF_POLICY_NODE
, &vtysh_exit_bgpd_cmd
);
2983 install_element(BGP_VRF_POLICY_NODE
, &vtysh_quit_bgpd_cmd
);
2984 install_element(BGP_VNC_DEFAULTS_NODE
, &vtysh_exit_bgpd_cmd
);
2985 install_element(BGP_VNC_DEFAULTS_NODE
, &vtysh_quit_bgpd_cmd
);
2986 install_element(BGP_VNC_NVE_GROUP_NODE
, &vtysh_exit_bgpd_cmd
);
2987 install_element(BGP_VNC_NVE_GROUP_NODE
, &vtysh_quit_bgpd_cmd
);
2988 install_element(BGP_VNC_L2_GROUP_NODE
, &vtysh_exit_bgpd_cmd
);
2989 install_element(BGP_VNC_L2_GROUP_NODE
, &vtysh_quit_bgpd_cmd
);
2991 install_element(ISIS_NODE
, &vtysh_exit_isisd_cmd
);
2992 install_element(ISIS_NODE
, &vtysh_quit_isisd_cmd
);
2993 install_element(KEYCHAIN_NODE
, &vtysh_exit_ripd_cmd
);
2994 install_element(KEYCHAIN_NODE
, &vtysh_quit_ripd_cmd
);
2995 install_element(KEYCHAIN_KEY_NODE
, &vtysh_exit_ripd_cmd
);
2996 install_element(KEYCHAIN_KEY_NODE
, &vtysh_quit_ripd_cmd
);
2997 install_element(RMAP_NODE
, &vtysh_exit_rmap_cmd
);
2998 install_element(RMAP_NODE
, &vtysh_quit_rmap_cmd
);
2999 install_element(VTY_NODE
, &vtysh_exit_line_vty_cmd
);
3000 install_element(VTY_NODE
, &vtysh_quit_line_vty_cmd
);
3002 /* "end" command. */
3003 install_element(CONFIG_NODE
, &vtysh_end_all_cmd
);
3004 install_element(ENABLE_NODE
, &vtysh_end_all_cmd
);
3005 install_element(RIP_NODE
, &vtysh_end_all_cmd
);
3006 install_element(RIPNG_NODE
, &vtysh_end_all_cmd
);
3007 install_element(OSPF_NODE
, &vtysh_end_all_cmd
);
3008 install_element(EIGRP_NODE
, &vtysh_end_all_cmd
);
3009 install_element(BABEL_NODE
, &vtysh_end_all_cmd
);
3010 install_element(OSPF6_NODE
, &vtysh_end_all_cmd
);
3011 install_element(LDP_NODE
, &vtysh_end_all_cmd
);
3012 install_element(LDP_IPV4_NODE
, &vtysh_end_all_cmd
);
3013 install_element(LDP_IPV6_NODE
, &vtysh_end_all_cmd
);
3014 install_element(LDP_IPV4_IFACE_NODE
, &vtysh_end_all_cmd
);
3015 install_element(LDP_IPV6_IFACE_NODE
, &vtysh_end_all_cmd
);
3016 install_element(LDP_L2VPN_NODE
, &vtysh_end_all_cmd
);
3017 install_element(LDP_PSEUDOWIRE_NODE
, &vtysh_end_all_cmd
);
3018 install_element(BGP_NODE
, &vtysh_end_all_cmd
);
3019 install_element(BGP_IPV4_NODE
, &vtysh_end_all_cmd
);
3020 install_element(BGP_IPV4M_NODE
, &vtysh_end_all_cmd
);
3021 install_element(BGP_IPV4L_NODE
, &vtysh_end_all_cmd
);
3022 install_element(BGP_VPNV4_NODE
, &vtysh_end_all_cmd
);
3023 install_element(BGP_VPNV6_NODE
, &vtysh_end_all_cmd
);
3024 install_element(BGP_IPV6_NODE
, &vtysh_end_all_cmd
);
3025 install_element(BGP_IPV6M_NODE
, &vtysh_end_all_cmd
);
3026 install_element(BGP_IPV6L_NODE
, &vtysh_end_all_cmd
);
3027 install_element(BGP_VRF_POLICY_NODE
, &vtysh_end_all_cmd
);
3028 install_element(BGP_EVPN_NODE
, &vtysh_end_all_cmd
);
3029 install_element(BGP_EVPN_VNI_NODE
, &vtysh_end_all_cmd
);
3030 install_element(BGP_VNC_DEFAULTS_NODE
, &vtysh_end_all_cmd
);
3031 install_element(BGP_VNC_NVE_GROUP_NODE
, &vtysh_end_all_cmd
);
3032 install_element(BGP_VNC_L2_GROUP_NODE
, &vtysh_end_all_cmd
);
3033 install_element(ISIS_NODE
, &vtysh_end_all_cmd
);
3034 install_element(KEYCHAIN_NODE
, &vtysh_end_all_cmd
);
3035 install_element(KEYCHAIN_KEY_NODE
, &vtysh_end_all_cmd
);
3036 install_element(RMAP_NODE
, &vtysh_end_all_cmd
);
3037 install_element(VTY_NODE
, &vtysh_end_all_cmd
);
3039 install_element(INTERFACE_NODE
, &vtysh_interface_desc_cmd
);
3040 install_element(INTERFACE_NODE
, &vtysh_no_interface_desc_cmd
);
3041 install_element(INTERFACE_NODE
, &vtysh_end_all_cmd
);
3042 install_element(INTERFACE_NODE
, &vtysh_exit_interface_cmd
);
3043 install_element(LINK_PARAMS_NODE
, &exit_link_params_cmd
);
3044 install_element(LINK_PARAMS_NODE
, &vtysh_end_all_cmd
);
3045 install_element(LINK_PARAMS_NODE
, &vtysh_exit_interface_cmd
);
3046 install_element(INTERFACE_NODE
, &vtysh_quit_interface_cmd
);
3048 install_element(NS_NODE
, &vtysh_end_all_cmd
);
3050 install_element(CONFIG_NODE
, &vtysh_ns_cmd
);
3051 install_element(NS_NODE
, &vtysh_exit_ns_cmd
);
3052 install_element(NS_NODE
, &vtysh_quit_ns_cmd
);
3054 install_element(VRF_NODE
, &vtysh_end_all_cmd
);
3055 install_element(VRF_NODE
, &vtysh_exit_vrf_cmd
);
3056 install_element(VRF_NODE
, &vtysh_quit_vrf_cmd
);
3058 install_element(CONFIG_NODE
, &router_eigrp_cmd
);
3059 install_element(CONFIG_NODE
, &router_babel_cmd
);
3060 install_element(CONFIG_NODE
, &router_rip_cmd
);
3061 install_element(CONFIG_NODE
, &router_ripng_cmd
);
3062 install_element(CONFIG_NODE
, &router_ospf_cmd
);
3063 install_element(CONFIG_NODE
, &router_ospf6_cmd
);
3064 #if defined(HAVE_LDPD)
3065 install_element(CONFIG_NODE
, &ldp_mpls_ldp_cmd
);
3066 install_element(LDP_NODE
, &ldp_address_family_ipv4_cmd
);
3067 install_element(LDP_NODE
, &ldp_address_family_ipv6_cmd
);
3068 install_element(LDP_IPV4_NODE
, &ldp_interface_ifname_cmd
);
3069 install_element(LDP_IPV6_NODE
, &ldp_interface_ifname_cmd
);
3070 install_element(CONFIG_NODE
, &ldp_l2vpn_word_type_vpls_cmd
);
3071 install_element(LDP_L2VPN_NODE
, &ldp_member_pseudowire_ifname_cmd
);
3073 install_element(CONFIG_NODE
, &router_isis_cmd
);
3074 install_element(CONFIG_NODE
, &router_bgp_cmd
);
3075 install_element(BGP_NODE
, &address_family_vpnv4_cmd
);
3076 install_element(BGP_NODE
, &address_family_vpnv6_cmd
);
3077 #if defined(ENABLE_BGP_VNC)
3078 install_element(BGP_NODE
, &vnc_vrf_policy_cmd
);
3079 install_element(BGP_NODE
, &vnc_defaults_cmd
);
3080 install_element(BGP_NODE
, &vnc_nve_group_cmd
);
3081 install_element(BGP_NODE
, &vnc_l2_group_cmd
);
3083 install_element(BGP_NODE
, &address_family_ipv4_cmd
);
3084 install_element(BGP_NODE
, &address_family_ipv4_multicast_cmd
);
3085 install_element(BGP_NODE
, &address_family_ipv4_vpn_cmd
);
3086 install_element(BGP_NODE
, &address_family_ipv4_labeled_unicast_cmd
);
3087 install_element(BGP_NODE
, &address_family_ipv6_cmd
);
3088 install_element(BGP_NODE
, &address_family_ipv6_multicast_cmd
);
3089 install_element(BGP_NODE
, &address_family_ipv6_vpn_cmd
);
3090 install_element(BGP_NODE
, &address_family_ipv6_labeled_unicast_cmd
);
3091 install_element(BGP_NODE
, &address_family_evpn_cmd
);
3092 #if defined(HAVE_CUMULUS)
3093 install_element(BGP_NODE
, &address_family_evpn2_cmd
);
3095 install_element(BGP_VPNV4_NODE
, &exit_address_family_cmd
);
3096 install_element(BGP_VPNV6_NODE
, &exit_address_family_cmd
);
3097 install_element(BGP_IPV4_NODE
, &exit_address_family_cmd
);
3098 install_element(BGP_IPV4M_NODE
, &exit_address_family_cmd
);
3099 install_element(BGP_IPV4L_NODE
, &exit_address_family_cmd
);
3100 install_element(BGP_IPV6_NODE
, &exit_address_family_cmd
);
3101 install_element(BGP_IPV6M_NODE
, &exit_address_family_cmd
);
3102 install_element(BGP_EVPN_NODE
, &exit_address_family_cmd
);
3103 install_element(BGP_IPV6L_NODE
, &exit_address_family_cmd
);
3106 install_element(BGP_EVPN_NODE
, &bgp_evpn_vni_cmd
);
3107 install_element(BGP_EVPN_VNI_NODE
, &exit_vni_cmd
);
3109 install_element(BGP_VRF_POLICY_NODE
, &exit_vrf_policy_cmd
);
3110 install_element(BGP_VNC_DEFAULTS_NODE
, &exit_vnc_config_cmd
);
3111 install_element(BGP_VNC_NVE_GROUP_NODE
, &exit_vnc_config_cmd
);
3112 install_element(BGP_VNC_L2_GROUP_NODE
, &exit_vnc_config_cmd
);
3114 install_element(CONFIG_NODE
, &key_chain_cmd
);
3115 install_element(CONFIG_NODE
, &vtysh_route_map_cmd
);
3116 install_element(CONFIG_NODE
, &vtysh_line_vty_cmd
);
3117 install_element(KEYCHAIN_NODE
, &key_cmd
);
3118 install_element(KEYCHAIN_NODE
, &key_chain_cmd
);
3119 install_element(KEYCHAIN_KEY_NODE
, &key_chain_cmd
);
3120 install_element(CONFIG_NODE
, &vtysh_interface_cmd
);
3121 install_element(CONFIG_NODE
, &vtysh_no_interface_cmd
);
3122 install_element(CONFIG_NODE
, &vtysh_no_interface_vrf_cmd
);
3123 install_element(INTERFACE_NODE
, &vtysh_link_params_cmd
);
3124 install_element(ENABLE_NODE
, &vtysh_show_running_config_cmd
);
3125 install_element(ENABLE_NODE
, &vtysh_copy_running_config_cmd
);
3127 install_element(CONFIG_NODE
, &vtysh_vrf_cmd
);
3128 install_element(CONFIG_NODE
, &vtysh_no_vrf_cmd
);
3130 /* "write terminal" command. */
3131 install_element(ENABLE_NODE
, &vtysh_write_terminal_cmd
);
3133 install_element(CONFIG_NODE
, &vtysh_integrated_config_cmd
);
3134 install_element(CONFIG_NODE
, &no_vtysh_integrated_config_cmd
);
3136 /* "write memory" command. */
3137 install_element(ENABLE_NODE
, &vtysh_write_memory_cmd
);
3139 install_element(VIEW_NODE
, &vtysh_terminal_length_cmd
);
3140 install_element(VIEW_NODE
, &vtysh_terminal_no_length_cmd
);
3141 install_element(VIEW_NODE
, &vtysh_show_daemons_cmd
);
3143 install_element(VIEW_NODE
, &vtysh_ping_cmd
);
3144 install_element(VIEW_NODE
, &vtysh_ping_ip_cmd
);
3145 install_element(VIEW_NODE
, &vtysh_traceroute_cmd
);
3146 install_element(VIEW_NODE
, &vtysh_traceroute_ip_cmd
);
3147 install_element(VIEW_NODE
, &vtysh_ping6_cmd
);
3148 install_element(VIEW_NODE
, &vtysh_traceroute6_cmd
);
3149 #if defined(HAVE_SHELL_ACCESS)
3150 install_element(VIEW_NODE
, &vtysh_telnet_cmd
);
3151 install_element(VIEW_NODE
, &vtysh_telnet_port_cmd
);
3152 install_element(VIEW_NODE
, &vtysh_ssh_cmd
);
3154 #if defined(HAVE_SHELL_ACCESS)
3155 install_element(ENABLE_NODE
, &vtysh_start_shell_cmd
);
3156 install_element(ENABLE_NODE
, &vtysh_start_bash_cmd
);
3157 install_element(ENABLE_NODE
, &vtysh_start_zsh_cmd
);
3160 install_element(VIEW_NODE
, &vtysh_show_memory_cmd
);
3161 install_element(VIEW_NODE
, &vtysh_show_modules_cmd
);
3163 install_element(VIEW_NODE
, &vtysh_show_work_queues_cmd
);
3164 install_element(VIEW_NODE
, &vtysh_show_work_queues_daemon_cmd
);
3166 install_element(VIEW_NODE
, &vtysh_show_hashtable_cmd
);
3168 install_element(VIEW_NODE
, &vtysh_show_thread_cmd
);
3171 install_element(VIEW_NODE
, &vtysh_show_logging_cmd
);
3172 install_element(CONFIG_NODE
, &vtysh_log_stdout_cmd
);
3173 install_element(CONFIG_NODE
, &vtysh_log_stdout_level_cmd
);
3174 install_element(CONFIG_NODE
, &no_vtysh_log_stdout_cmd
);
3175 install_element(CONFIG_NODE
, &vtysh_log_file_cmd
);
3176 install_element(CONFIG_NODE
, &vtysh_log_file_level_cmd
);
3177 install_element(CONFIG_NODE
, &no_vtysh_log_file_cmd
);
3178 install_element(CONFIG_NODE
, &vtysh_log_monitor_cmd
);
3179 install_element(CONFIG_NODE
, &no_vtysh_log_monitor_cmd
);
3180 install_element(CONFIG_NODE
, &vtysh_log_syslog_cmd
);
3181 install_element(CONFIG_NODE
, &no_vtysh_log_syslog_cmd
);
3182 install_element(CONFIG_NODE
, &vtysh_log_trap_cmd
);
3183 install_element(CONFIG_NODE
, &no_vtysh_log_trap_cmd
);
3184 install_element(CONFIG_NODE
, &vtysh_log_facility_cmd
);
3185 install_element(CONFIG_NODE
, &no_vtysh_log_facility_cmd
);
3186 install_element(CONFIG_NODE
, &vtysh_log_record_priority_cmd
);
3187 install_element(CONFIG_NODE
, &no_vtysh_log_record_priority_cmd
);
3188 install_element(CONFIG_NODE
, &vtysh_log_timestamp_precision_cmd
);
3189 install_element(CONFIG_NODE
, &no_vtysh_log_timestamp_precision_cmd
);
3191 install_element(CONFIG_NODE
, &vtysh_service_password_encrypt_cmd
);
3192 install_element(CONFIG_NODE
, &no_vtysh_service_password_encrypt_cmd
);
3194 install_element(CONFIG_NODE
, &vtysh_password_cmd
);
3195 install_element(CONFIG_NODE
, &vtysh_enable_password_cmd
);
3196 install_element(CONFIG_NODE
, &no_vtysh_enable_password_cmd
);