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")
49 /* Destination for vtysh output */
55 /* VTY shell pager name. */
56 char *vtysh_pager_name
= NULL
;
58 /* VTY shell client structure. */
63 char path
[MAXPATHLEN
];
64 struct vtysh_client
*next
;
67 struct vtysh_client vtysh_client
[] = {
68 {.fd
= -1, .name
= "zebra", .flag
= VTYSH_ZEBRA
, .next
= NULL
},
69 {.fd
= -1, .name
= "ripd", .flag
= VTYSH_RIPD
, .next
= NULL
},
70 {.fd
= -1, .name
= "ripngd", .flag
= VTYSH_RIPNGD
, .next
= NULL
},
71 {.fd
= -1, .name
= "ospfd", .flag
= VTYSH_OSPFD
, .next
= NULL
},
72 {.fd
= -1, .name
= "ospf6d", .flag
= VTYSH_OSPF6D
, .next
= NULL
},
73 {.fd
= -1, .name
= "ldpd", .flag
= VTYSH_LDPD
, .next
= NULL
},
74 {.fd
= -1, .name
= "bgpd", .flag
= VTYSH_BGPD
, .next
= NULL
},
75 {.fd
= -1, .name
= "isisd", .flag
= VTYSH_ISISD
, .next
= NULL
},
76 {.fd
= -1, .name
= "pimd", .flag
= VTYSH_PIMD
, .next
= NULL
},
77 {.fd
= -1, .name
= "nhrpd", .flag
= VTYSH_NHRPD
, .next
= NULL
},
78 {.fd
= -1, .name
= "eigrpd", .flag
= VTYSH_EIGRPD
, .next
= NULL
},
79 {.fd
= -1, .name
= "babeld", .flag
= VTYSH_BABELD
, .next
= NULL
},
80 {.fd
= -1, .name
= "sharpd", .flag
= VTYSH_SHARPD
, .next
= NULL
},
81 {.fd
= -1, .name
= "watchfrr", .flag
= VTYSH_WATCHFRR
, .next
= NULL
},
84 enum vtysh_write_integrated vtysh_write_integrated
=
85 WRITE_INTEGRATED_UNSPECIFIED
;
87 static void vclient_close(struct vtysh_client
*vclient
)
89 if (vclient
->fd
>= 0) {
91 "Warning: closing connection to %s because of an I/O error!\n",
98 /* Return true if str begins with prefix, else return false */
99 static int begins_with(const char *str
, const char *prefix
)
103 size_t lenstr
= strlen(str
);
104 size_t lenprefix
= strlen(prefix
);
105 if (lenprefix
> lenstr
)
107 return strncmp(str
, prefix
, lenprefix
) == 0;
110 static int vtysh_client_run(struct vtysh_client
*vclient
, const char *line
,
111 FILE *fp
, void (*callback
)(void *, const char *),
116 char *buf
= stackbuf
;
117 size_t bufsz
= sizeof(stackbuf
);
118 char *bufvalid
, *end
= NULL
;
119 char terminator
[3] = {0, 0, 0};
124 ret
= write(vclient
->fd
, line
, strlen(line
) + 1);
131 read(vclient
->fd
, bufvalid
, buf
+ bufsz
- bufvalid
);
133 if (nread
< 0 && (errno
== EINTR
|| errno
== EAGAIN
))
137 fprintf(stderr
, "vtysh: error reading from %s: %s (%d)",
138 vclient
->name
, safe_strerror(errno
), errno
);
144 if (bufvalid
- buf
>= 4)
145 end
= memmem(bufvalid
- 4, 4, terminator
,
148 if (end
&& end
+ sizeof(terminator
) + 1 > bufvalid
)
149 /* found \0\0\0 but return code hasn't been read yet */
152 ret
= end
[sizeof(terminator
)];
155 * calculate # bytes we have, up to & not including the
156 * terminator if present
158 size_t textlen
= (end
? end
: bufvalid
) - buf
;
160 /* feed line processing callback if present */
161 while (callback
&& bufvalid
> buf
&& (end
> buf
|| !end
)) {
162 textlen
= (end
? end
: bufvalid
) - buf
;
163 char *eol
= memchr(buf
, '\n', textlen
);
168 /* no line break, end of input, no text left
170 * => don't insert an empty line at the end */
173 /* no line break, end of input, but some text
177 /* continue reading */
180 /* eol is at line end now, either \n => \0 or \0\0\0 */
181 assert(eol
&& eol
<= bufvalid
);
188 callback(cbarg
, buf
);
194 memmove(buf
, eol
, bufvalid
- eol
);
195 bufvalid
-= eol
- buf
;
200 /* else if no callback, dump raw */
203 fwrite(buf
, 1, textlen
, fp
);
204 memmove(buf
, buf
+ textlen
, bufvalid
- buf
- textlen
);
208 if (bufvalid
== buf
+ bufsz
) {
211 if (buf
== stackbuf
) {
212 new = XMALLOC(MTYPE_TMP
, bufsz
);
213 memcpy(new, stackbuf
, sizeof(stackbuf
));
215 new = XREALLOC(MTYPE_TMP
, buf
, bufsz
);
217 bufvalid
= bufvalid
- buf
+ new;
219 /* if end != NULL, we won't be reading more data... */
226 vclient_close(vclient
);
230 XFREE(MTYPE_TMP
, buf
);
234 static int vtysh_client_run_all(struct vtysh_client
*head_client
,
235 const char *line
, int continue_on_err
, FILE *fp
,
236 void (*callback
)(void *, const char *),
239 struct vtysh_client
*client
;
240 int rc
, rc_all
= CMD_SUCCESS
;
241 int correct_instance
= 0, wrong_instance
= 0;
243 for (client
= head_client
; client
; client
= client
->next
) {
244 rc
= vtysh_client_run(client
, line
, fp
, callback
, cbarg
);
245 if (rc
== CMD_NOT_MY_INSTANCE
) {
251 if (rc
!= CMD_SUCCESS
) {
252 if (!continue_on_err
)
257 if (wrong_instance
&& !correct_instance
&& fp
) {
259 "%% [%s]: command ignored as it targets an instance that is not running\n",
261 rc_all
= CMD_WARNING_CONFIG_FAILED
;
266 static int vtysh_client_execute(struct vtysh_client
*head_client
,
267 const char *line
, FILE *fp
)
269 return vtysh_client_run_all(head_client
, line
, 0, fp
, NULL
, NULL
);
272 static void vtysh_client_config(struct vtysh_client
*head_client
, char *line
)
274 /* watchfrr currently doesn't load any config, and has some hardcoded
275 * settings that show up in "show run". skip it here (for now at
276 * least) so we don't get that mangled up in config-write.
278 if (head_client
->flag
== VTYSH_WATCHFRR
)
281 vtysh_client_run_all(head_client
, line
, 1, NULL
,
282 vtysh_config_parse_line
, NULL
);
285 void vtysh_pager_init(void)
289 pager_defined
= getenv("VTYSH_PAGER");
292 vtysh_pager_name
= strdup(pager_defined
);
294 vtysh_pager_name
= strdup(VTYSH_PAGER
);
297 /* Command execution over the vty interface. */
298 static int vtysh_execute_func(const char *line
, int pager
)
303 const struct cmd_element
*cmd
;
307 int saved_ret
, saved_node
;
309 /* Split readline string up into the vector. */
310 vline
= cmd_make_strvec(line
);
316 if (strncmp("en", vector_slot(vline
, 0), 2) == 0) {
317 fprintf(stdout
, "%% Command not allowed: enable\n");
322 saved_ret
= ret
= cmd_execute_command(vline
, vty
, &cmd
, 1);
323 saved_node
= vty
->node
;
325 /* If command doesn't succeeded in current node, try to walk up in node
327 * Changing vty->node is enough to try it just out without actual walkup
330 while (ret
!= CMD_SUCCESS
&& ret
!= CMD_SUCCESS_DAEMON
331 && ret
!= CMD_WARNING
&& ret
!= CMD_WARNING_CONFIG_FAILED
332 && vty
->node
> CONFIG_NODE
) {
333 vty
->node
= node_parent(vty
->node
);
334 ret
= cmd_execute_command(vline
, vty
, &cmd
, 1);
338 vty
->node
= saved_node
;
340 /* If command succeeded in any other node than current (tried > 0) we
342 * to move into node in the vtysh where it succeeded. */
343 if (ret
== CMD_SUCCESS
|| ret
== CMD_SUCCESS_DAEMON
344 || ret
== CMD_WARNING
) {
345 if ((saved_node
== BGP_VPNV4_NODE
346 || saved_node
== BGP_VPNV6_NODE
347 || saved_node
== BGP_IPV4_NODE
348 || saved_node
== BGP_IPV6_NODE
349 || saved_node
== BGP_IPV4M_NODE
350 || saved_node
== BGP_IPV4L_NODE
351 || saved_node
== BGP_IPV6L_NODE
352 || saved_node
== BGP_IPV6M_NODE
353 || saved_node
== BGP_EVPN_NODE
354 || saved_node
== LDP_IPV4_NODE
355 || saved_node
== LDP_IPV6_NODE
)
357 vtysh_execute("exit-address-family");
358 } else if ((saved_node
== BGP_EVPN_VNI_NODE
) && (tried
== 1)) {
359 vtysh_execute("exit-vni");
360 } else if (saved_node
== BGP_VRF_POLICY_NODE
&& (tried
== 1)) {
361 vtysh_execute("exit-vrf-policy");
362 } else if ((saved_node
== BGP_VNC_DEFAULTS_NODE
363 || saved_node
== BGP_VNC_NVE_GROUP_NODE
364 || saved_node
== BGP_VNC_L2_GROUP_NODE
)
366 vtysh_execute("exit-vnc");
367 } else if ((saved_node
== KEYCHAIN_KEY_NODE
368 || saved_node
== LDP_PSEUDOWIRE_NODE
369 || saved_node
== LDP_IPV4_IFACE_NODE
370 || saved_node
== LDP_IPV6_IFACE_NODE
)
372 vtysh_execute("exit");
374 vtysh_execute("end");
375 vtysh_execute("configure terminal");
378 /* If command didn't succeed in any node, continue with return value
385 cmd_free_strvec(vline
);
390 case CMD_WARNING_CONFIG_FAILED
:
391 if (vty
->type
== VTY_FILE
)
392 fprintf(stdout
, "Warning...\n");
394 case CMD_ERR_AMBIGUOUS
:
395 fprintf(stdout
, "%% Ambiguous command: %s\n", line
);
397 case CMD_ERR_NO_MATCH
:
398 fprintf(stdout
, "%% Unknown command: %s\n", line
);
400 case CMD_ERR_INCOMPLETE
:
401 fprintf(stdout
, "%% Command incomplete: %s\n", line
);
403 case CMD_SUCCESS_DAEMON
: {
405 * FIXME: Don't open pager for exit commands. popen() causes
406 * problems if exited from vtysh at all. This hack shouldn't
407 * cause any problem but is really ugly.
410 if (pager
&& vtysh_pager_name
&& outputfile
== stdout
411 && (strncmp(line
, "exit", 4) != 0)) {
412 fp
= popen(vtysh_pager_name
, "w");
414 perror("popen failed for pager");
420 if (!strcmp(cmd
->string
, "configure terminal")) {
421 for (i
= 0; i
< array_size(vtysh_client
); i
++) {
422 cmd_stat
= vtysh_client_execute(
423 &vtysh_client
[i
], line
, fp
);
424 if (cmd_stat
== CMD_WARNING
)
430 vline
= cmd_make_strvec(line
);
433 if (pager
&& vtysh_pager_name
&& fp
434 && fp
!= outputfile
&& closepager
) {
435 if (pclose(fp
) == -1) {
436 perror("pclose failed for pager");
443 ret
= cmd_execute_command(vline
, vty
, &cmd
, 1);
444 cmd_free_strvec(vline
);
445 if (ret
!= CMD_SUCCESS_DAEMON
)
447 } else if (cmd
->func
) {
448 (*cmd
->func
)(cmd
, vty
, 0, NULL
);
453 cmd_stat
= CMD_SUCCESS
;
454 struct vtysh_client
*vc
;
455 for (i
= 0; i
< array_size(vtysh_client
); i
++) {
456 if (cmd
->daemon
& vtysh_client
[i
].flag
) {
457 if (vtysh_client
[i
].fd
< 0
458 && (cmd
->daemon
== vtysh_client
[i
].flag
)) {
459 bool any_inst
= false;
460 for (vc
= &vtysh_client
[i
]; vc
;
466 "%s is not running\n",
467 vtysh_client
[i
].name
);
471 cmd_stat
= vtysh_client_execute(
472 &vtysh_client
[i
], line
, fp
);
473 if (cmd_stat
!= CMD_SUCCESS
)
477 if (cmd_stat
!= CMD_SUCCESS
)
481 (*cmd
->func
)(cmd
, vty
, 0, NULL
);
484 if (pager
&& vtysh_pager_name
&& fp
&& closepager
&& fp
!= outputfile
) {
485 if (pclose(fp
) == -1) {
486 perror("pclose failed for pager");
493 int vtysh_execute_no_pager(const char *line
)
495 return vtysh_execute_func(line
, 0);
498 int vtysh_execute(const char *line
)
500 return vtysh_execute_func(line
, 1);
503 static char *trim(char *s
)
514 while (end
>= s
&& isspace((int)*end
))
518 while (*s
&& isspace((int)*s
))
524 int vtysh_mark_file(const char *filename
)
531 const struct cmd_element
*cmd
;
532 int saved_ret
, prev_node
;
534 char *vty_buf_copy
= NULL
;
535 char *vty_buf_trimmed
= NULL
;
537 if (strncmp("-", filename
, 1) == 0)
540 confp
= fopen(filename
, "r");
543 fprintf(stderr
, "%% Can't open config file %s due to '%s'.\n",
544 filename
, safe_strerror(errno
));
545 return (CMD_ERR_NO_FILE
);
549 vty
->wfd
= STDERR_FILENO
;
550 vty
->type
= VTY_TERM
;
551 vty
->node
= CONFIG_NODE
;
553 vtysh_execute_no_pager("enable");
554 vtysh_execute_no_pager("configure terminal");
555 vty_buf_copy
= XCALLOC(MTYPE_VTYSH_CMD
, VTY_BUFSIZ
);
557 while (fgets(vty
->buf
, VTY_BUFSIZ
, confp
)) {
560 strcpy(vty_buf_copy
, vty
->buf
);
561 vty_buf_trimmed
= trim(vty_buf_copy
);
564 case LDP_IPV4_IFACE_NODE
:
565 if (strncmp(vty_buf_copy
, " ", 3)) {
566 fprintf(outputfile
, " end\n");
567 vty
->node
= LDP_IPV4_NODE
;
570 case LDP_IPV6_IFACE_NODE
:
571 if (strncmp(vty_buf_copy
, " ", 3)) {
572 fprintf(outputfile
, " end\n");
573 vty
->node
= LDP_IPV6_NODE
;
576 case LDP_PSEUDOWIRE_NODE
:
577 if (strncmp(vty_buf_copy
, " ", 2)) {
578 fprintf(outputfile
, " end\n");
579 vty
->node
= LDP_L2VPN_NODE
;
586 if (vty_buf_trimmed
[0] == '!' || vty_buf_trimmed
[0] == '#') {
587 fprintf(outputfile
, "%s", vty
->buf
);
591 /* Split readline string up into the vector. */
592 vline
= cmd_make_strvec(vty
->buf
);
595 fprintf(outputfile
, "%s", vty
->buf
);
599 /* Ignore the "end" lines, we will generate these where
601 if (strlen(vty_buf_trimmed
) == 3
602 && strncmp("end", vty_buf_trimmed
, 3) == 0) {
603 cmd_free_strvec(vline
);
607 prev_node
= vty
->node
;
608 saved_ret
= ret
= cmd_execute_command_strict(vline
, vty
, &cmd
);
610 /* If command doesn't succeeded in current node, try to walk up
612 * Changing vty->node is enough to try it just out without
615 while (ret
!= CMD_SUCCESS
&& ret
!= CMD_SUCCESS_DAEMON
616 && ret
!= CMD_WARNING
&& ret
!= CMD_WARNING_CONFIG_FAILED
617 && vty
->node
> CONFIG_NODE
) {
618 vty
->node
= node_parent(vty
->node
);
619 ret
= cmd_execute_command_strict(vline
, vty
, &cmd
);
623 /* If command succeeded in any other node than current (tried >
625 * to move into node in the vtysh where it succeeded. */
626 if (ret
== CMD_SUCCESS
|| ret
== CMD_SUCCESS_DAEMON
627 || ret
== CMD_WARNING
) {
628 if ((prev_node
== BGP_VPNV4_NODE
629 || prev_node
== BGP_VPNV6_NODE
630 || prev_node
== BGP_IPV4_NODE
631 || prev_node
== BGP_IPV6_NODE
632 || prev_node
== BGP_IPV4L_NODE
633 || prev_node
== BGP_IPV6L_NODE
634 || prev_node
== BGP_IPV4M_NODE
635 || prev_node
== BGP_IPV6M_NODE
636 || prev_node
== BGP_EVPN_NODE
)
638 fprintf(outputfile
, "exit-address-family\n");
639 } else if ((prev_node
== BGP_EVPN_VNI_NODE
)
641 fprintf(outputfile
, "exit-vni\n");
642 } else if ((prev_node
== KEYCHAIN_KEY_NODE
)
644 fprintf(outputfile
, "exit\n");
646 fprintf(outputfile
, "end\n");
649 /* If command didn't succeed in any node, continue with return
654 vty
->node
= prev_node
;
657 cmd_free_strvec(vline
);
660 case CMD_WARNING_CONFIG_FAILED
:
661 if (vty
->type
== VTY_FILE
)
662 fprintf(stderr
, "line %d: Warning...: %s\n",
666 XFREE(MTYPE_VTYSH_CMD
, vty_buf_copy
);
668 case CMD_ERR_AMBIGUOUS
:
669 fprintf(stderr
, "line %d: %% Ambiguous command: %s\n",
673 XFREE(MTYPE_VTYSH_CMD
, vty_buf_copy
);
674 return CMD_ERR_AMBIGUOUS
;
675 case CMD_ERR_NO_MATCH
:
676 fprintf(stderr
, "line %d: %% Unknown command: %s\n",
680 XFREE(MTYPE_VTYSH_CMD
, vty_buf_copy
);
681 return CMD_ERR_NO_MATCH
;
682 case CMD_ERR_INCOMPLETE
:
683 fprintf(stderr
, "line %d: %% Command incomplete: %s\n",
687 XFREE(MTYPE_VTYSH_CMD
, vty_buf_copy
);
688 return CMD_ERR_INCOMPLETE
;
690 fprintf(stdout
, "%s", vty
->buf
);
692 case CMD_SUCCESS_DAEMON
: {
694 int cmd_stat
= CMD_SUCCESS
;
696 fprintf(outputfile
, "%s", vty
->buf
);
697 for (i
= 0; i
< array_size(vtysh_client
); i
++) {
698 if (cmd
->daemon
& vtysh_client
[i
].flag
) {
699 cmd_stat
= vtysh_client_execute(
700 &vtysh_client
[i
], vty
->buf
,
702 if (cmd_stat
!= CMD_SUCCESS
)
706 if (cmd_stat
!= CMD_SUCCESS
)
710 (*cmd
->func
)(cmd
, vty
, 0, NULL
);
714 /* This is the end */
715 fprintf(outputfile
, "\nend\n");
717 XFREE(MTYPE_VTYSH_CMD
, vty_buf_copy
);
725 /* Configration make from file. */
726 int vtysh_config_from_file(struct vty
*vty
, FILE *fp
)
729 const struct cmd_element
*cmd
;
731 int retcode
= CMD_SUCCESS
;
733 while (fgets(vty
->buf
, VTY_BUFSIZ
, fp
)) {
736 ret
= command_config_read_one_line(vty
, &cmd
, 1);
740 case CMD_WARNING_CONFIG_FAILED
:
741 if (vty
->type
== VTY_FILE
)
742 fprintf(stderr
, "line %d: Warning[%d]...: %s\n",
743 lineno
, vty
->node
, vty
->buf
);
744 retcode
= ret
; /* once we have an error, we remember &
747 case CMD_ERR_AMBIGUOUS
:
749 "line %d: %% Ambiguous command[%d]: %s\n",
750 lineno
, vty
->node
, vty
->buf
);
751 retcode
= CMD_ERR_AMBIGUOUS
; /* once we have an error,
755 case CMD_ERR_NO_MATCH
:
756 fprintf(stderr
, "line %d: %% Unknown command[%d]: %s",
757 lineno
, vty
->node
, vty
->buf
);
758 retcode
= CMD_ERR_NO_MATCH
; /* once we have an error, we
759 remember & return that */
761 case CMD_ERR_INCOMPLETE
:
763 "line %d: %% Command incomplete[%d]: %s\n",
764 lineno
, vty
->node
, vty
->buf
);
765 retcode
= CMD_ERR_INCOMPLETE
; /* once we have an error,
769 case CMD_SUCCESS_DAEMON
: {
771 int cmd_stat
= CMD_SUCCESS
;
773 for (i
= 0; i
< array_size(vtysh_client
); i
++) {
774 if (cmd
->daemon
& vtysh_client
[i
].flag
) {
775 cmd_stat
= vtysh_client_execute(
776 &vtysh_client
[i
], vty
->buf
,
779 * CMD_WARNING - Can mean that the
781 * parsed successfully but it was
783 * in a few spots. As such if we
785 * CMD_WARNING from a daemon we
787 * talking to the other daemons for the
791 if (cmd_stat
!= CMD_SUCCESS
792 && cmd_stat
!= CMD_WARNING
) {
794 "line %d: Failure to communicate[%d] to %s, line: %s\n",
796 vtysh_client
[i
].name
,
803 if (cmd_stat
!= CMD_SUCCESS
)
807 (*cmd
->func
)(cmd
, vty
, 0, NULL
);
815 /* We don't care about the point of the cursor when '?' is typed. */
816 static int vtysh_rl_describe(void)
823 struct cmd_token
*token
;
825 vline
= cmd_make_strvec(rl_line_buffer
);
827 /* In case of '> ?'. */
829 vline
= vector_init(1);
830 vector_set(vline
, NULL
);
831 } else if (rl_end
&& isspace((int)rl_line_buffer
[rl_end
- 1]))
832 vector_set(vline
, NULL
);
834 fprintf(stdout
, "\n");
836 describe
= cmd_describe_command(vline
, vty
, &ret
);
838 /* Ambiguous and no match error. */
840 case CMD_ERR_AMBIGUOUS
:
841 cmd_free_strvec(vline
);
842 vector_free(describe
);
843 fprintf(stdout
, "%% Ambiguous command.\n");
847 case CMD_ERR_NO_MATCH
:
848 cmd_free_strvec(vline
);
850 vector_free(describe
);
851 fprintf(stdout
, "%% There is no matched command.\n");
857 /* Get width of command string. */
859 for (i
= 0; i
< vector_active(describe
); i
++)
860 if ((token
= vector_slot(describe
, i
)) != NULL
) {
861 if (token
->text
[0] == '\0')
864 int len
= strlen(token
->text
);
870 for (i
= 0; i
< vector_active(describe
); i
++)
871 if ((token
= vector_slot(describe
, i
)) != NULL
) {
873 fprintf(stdout
, " %-s\n", token
->text
);
875 fprintf(stdout
, " %-*s %s\n", width
,
876 token
->text
, token
->desc
);
878 if (IS_VARYING_TOKEN(token
->type
)) {
879 const char *ref
= vector_slot(
880 vline
, vector_active(vline
) - 1);
882 vector varcomps
= vector_init(VECTOR_MIN_SIZE
);
883 cmd_variable_complete(token
, ref
, varcomps
);
885 if (vector_active(varcomps
) > 0) {
887 rl_get_screen_size(&rows
, &cols
);
889 char *ac
= cmd_variable_comp2str(
891 fprintf(stdout
, "%s\n", ac
);
892 XFREE(MTYPE_TMP
, ac
);
895 vector_free(varcomps
);
899 cmd_free_strvec(vline
);
900 vector_free(describe
);
907 /* Result of cmd_complete_command() call will be stored here
908 * and used in new_completion() in order to put the space in
909 * correct places only. */
912 static char *command_generator(const char *text
, int state
)
915 static char **matched
= NULL
;
916 static int index
= 0;
922 if (vty
->node
== AUTH_NODE
|| vty
->node
== AUTH_ENABLE_NODE
)
925 vline
= cmd_make_strvec(rl_line_buffer
);
929 if (rl_end
&& isspace((int)rl_line_buffer
[rl_end
- 1]))
930 vector_set(vline
, NULL
);
932 matched
= cmd_complete_command(vline
, vty
, &complete_status
);
933 cmd_free_strvec(vline
);
936 if (matched
&& matched
[index
])
937 /* this is free()'d by readline, but we leak 1 count of
938 * MTYPE_COMPLETION */
939 return matched
[index
++];
941 XFREE(MTYPE_TMP
, matched
);
947 static char **new_completion(char *text
, int start
, int end
)
951 matches
= rl_completion_matches(text
, command_generator
);
955 if (complete_status
!= CMD_COMPLETE_FULL_MATCH
)
956 /* only append a space on full match */
957 rl_completion_append_character
= '\0';
963 /* Vty node structures. */
964 static struct cmd_node bgp_node
= {
965 BGP_NODE
, "%s(config-router)# ",
968 static struct cmd_node rip_node
= {
969 RIP_NODE
, "%s(config-router)# ",
972 static struct cmd_node isis_node
= {
973 ISIS_NODE
, "%s(config-router)# ",
976 static struct cmd_node interface_node
= {
977 INTERFACE_NODE
, "%s(config-if)# ",
980 static struct cmd_node pw_node
= {
981 PW_NODE
, "%s(config-pw)# ",
984 static struct cmd_node logicalrouter_node
= {
985 LOGICALROUTER_NODE
, "%s(config-logical-router)# ",
988 static struct cmd_node vrf_node
= {
989 VRF_NODE
, "%s(config-vrf)# ",
992 static struct cmd_node rmap_node
= {RMAP_NODE
, "%s(config-route-map)# "};
994 static struct cmd_node zebra_node
= {ZEBRA_NODE
, "%s(config-router)# "};
996 static struct cmd_node bgp_vpnv4_node
= {BGP_VPNV4_NODE
,
997 "%s(config-router-af)# "};
999 static struct cmd_node bgp_vpnv6_node
= {BGP_VPNV6_NODE
,
1000 "%s(config-router-af)# "};
1002 static struct cmd_node bgp_ipv4_node
= {BGP_IPV4_NODE
,
1003 "%s(config-router-af)# "};
1005 static struct cmd_node bgp_ipv4m_node
= {BGP_IPV4M_NODE
,
1006 "%s(config-router-af)# "};
1008 static struct cmd_node bgp_ipv4l_node
= {BGP_IPV4L_NODE
,
1009 "%s(config-router-af)# "};
1011 static struct cmd_node bgp_ipv6_node
= {BGP_IPV6_NODE
,
1012 "%s(config-router-af)# "};
1014 static struct cmd_node bgp_ipv6m_node
= {BGP_IPV6M_NODE
,
1015 "%s(config-router-af)# "};
1017 static struct cmd_node bgp_evpn_node
= {BGP_EVPN_NODE
,
1018 "%s(config-router-af)# "};
1020 static struct cmd_node bgp_evpn_vni_node
= {BGP_EVPN_VNI_NODE
,
1021 "%s(config-router-af-vni)# "};
1023 static struct cmd_node bgp_ipv6l_node
= {BGP_IPV6L_NODE
,
1024 "%s(config-router-af)# "};
1026 static struct cmd_node bgp_vnc_defaults_node
= {
1027 BGP_VNC_DEFAULTS_NODE
, "%s(config-router-vnc-defaults)# "};
1029 static struct cmd_node bgp_vnc_nve_group_node
= {
1030 BGP_VNC_NVE_GROUP_NODE
, "%s(config-router-vnc-nve-group)# "};
1032 static struct cmd_node bgp_vrf_policy_node
= {BGP_VRF_POLICY_NODE
,
1033 "%s(config-router-vrf-policy)# "};
1035 static struct cmd_node bgp_vnc_l2_group_node
= {
1036 BGP_VNC_L2_GROUP_NODE
, "%s(config-router-vnc-l2-group)# "};
1038 static struct cmd_node ospf_node
= {OSPF_NODE
, "%s(config-router)# "};
1040 static struct cmd_node eigrp_node
= {EIGRP_NODE
, "%s(config-router)# "};
1042 static struct cmd_node babel_node
= {BABEL_NODE
, "%s(config-router)# "};
1044 static struct cmd_node ripng_node
= {RIPNG_NODE
, "%s(config-router)# "};
1046 static struct cmd_node ospf6_node
= {OSPF6_NODE
, "%s(config-ospf6)# "};
1048 static struct cmd_node ldp_node
= {LDP_NODE
, "%s(config-ldp)# "};
1050 static struct cmd_node ldp_ipv4_node
= {LDP_IPV4_NODE
, "%s(config-ldp-af)# "};
1052 static struct cmd_node ldp_ipv6_node
= {LDP_IPV6_NODE
, "%s(config-ldp-af)# "};
1054 static struct cmd_node ldp_ipv4_iface_node
= {LDP_IPV4_IFACE_NODE
,
1055 "%s(config-ldp-af-if)# "};
1057 static struct cmd_node ldp_ipv6_iface_node
= {LDP_IPV6_IFACE_NODE
,
1058 "%s(config-ldp-af-if)# "};
1060 static struct cmd_node ldp_l2vpn_node
= {LDP_L2VPN_NODE
, "%s(config-l2vpn)# "};
1062 static struct cmd_node ldp_pseudowire_node
= {LDP_PSEUDOWIRE_NODE
,
1063 "%s(config-l2vpn-pw)# "};
1065 static struct cmd_node keychain_node
= {KEYCHAIN_NODE
, "%s(config-keychain)# "};
1067 static struct cmd_node keychain_key_node
= {KEYCHAIN_KEY_NODE
,
1068 "%s(config-keychain-key)# "};
1070 struct cmd_node link_params_node
= {
1071 LINK_PARAMS_NODE
, "%s(config-link-params)# ",
1074 #if defined(HAVE_RPKI)
1075 static struct cmd_node rpki_node
= {RPKI_NODE
, "%s(config-rpki)# ", 1};
1078 /* Defined in lib/vty.c */
1079 extern struct cmd_node vty_node
;
1081 /* When '^Z' is received from vty, move down to the enable mode. */
1082 static int vtysh_end(void)
1084 switch (vty
->node
) {
1087 /* Nothing to do. */
1090 vty
->node
= ENABLE_NODE
;
1096 DEFUNSH(VTYSH_REALLYALL
, vtysh_end_all
, vtysh_end_all_cmd
, "end",
1097 "End current mode and change to enable mode\n")
1102 DEFUNSH(VTYSH_BGPD
, router_bgp
, router_bgp_cmd
,
1103 "router bgp [(1-4294967295) [<view|vrf> WORD]]",
1104 ROUTER_STR BGP_STR AS_STR
1105 "BGP view\nBGP VRF\n"
1108 vty
->node
= BGP_NODE
;
1112 DEFUNSH(VTYSH_BGPD
, address_family_vpnv4
, address_family_vpnv4_cmd
,
1113 "address-family vpnv4 [unicast]",
1114 "Enter Address Family command mode\n"
1116 "Address Family modifier\n")
1118 vty
->node
= BGP_VPNV4_NODE
;
1122 DEFUNSH(VTYSH_BGPD
, address_family_vpnv6
, address_family_vpnv6_cmd
,
1123 "address-family vpnv6 [unicast]",
1124 "Enter Address Family command mode\n"
1126 "Address Family modifier\n")
1128 vty
->node
= BGP_VPNV6_NODE
;
1132 DEFUNSH(VTYSH_BGPD
, address_family_ipv4
, address_family_ipv4_cmd
,
1133 "address-family ipv4 [unicast]",
1134 "Enter Address Family command mode\n"
1136 "Address Family Modifier\n")
1138 vty
->node
= BGP_IPV4_NODE
;
1142 DEFUNSH(VTYSH_BGPD
, address_family_ipv4_multicast
,
1143 address_family_ipv4_multicast_cmd
, "address-family ipv4 multicast",
1144 "Enter Address Family command mode\n"
1146 "Address Family modifier\n")
1148 vty
->node
= BGP_IPV4M_NODE
;
1152 DEFUNSH(VTYSH_BGPD
, address_family_ipv4_vpn
, address_family_ipv4_vpn_cmd
,
1153 "address-family ipv4 vpn",
1154 "Enter Address Family command mode\n"
1156 "Address Family modifier\n")
1158 vty
->node
= BGP_VPNV4_NODE
;
1162 DEFUNSH(VTYSH_BGPD
, address_family_ipv4_labeled_unicast
,
1163 address_family_ipv4_labeled_unicast_cmd
,
1164 "address-family ipv4 labeled-unicast",
1165 "Enter Address Family command mode\n"
1167 "Address Family modifier\n")
1169 vty
->node
= BGP_IPV4L_NODE
;
1173 DEFUNSH(VTYSH_BGPD
, address_family_ipv6
, address_family_ipv6_cmd
,
1174 "address-family ipv6 [unicast]",
1175 "Enter Address Family command mode\n"
1177 "Address Family modifier\n")
1179 vty
->node
= BGP_IPV6_NODE
;
1183 DEFUNSH(VTYSH_BGPD
, address_family_ipv6_multicast
,
1184 address_family_ipv6_multicast_cmd
, "address-family ipv6 multicast",
1185 "Enter Address Family command mode\n"
1187 "Address Family modifier\n")
1189 vty
->node
= BGP_IPV6M_NODE
;
1193 DEFUNSH(VTYSH_BGPD
, address_family_ipv6_vpn
, address_family_ipv6_vpn_cmd
,
1194 "address-family ipv6 vpn",
1195 "Enter Address Family command mode\n"
1197 "Address Family modifier\n")
1199 vty
->node
= BGP_VPNV6_NODE
;
1203 DEFUNSH(VTYSH_BGPD
, address_family_ipv6_labeled_unicast
,
1204 address_family_ipv6_labeled_unicast_cmd
,
1205 "address-family ipv6 labeled-unicast",
1206 "Enter Address Family command mode\n"
1208 "Address Family modifier\n")
1210 vty
->node
= BGP_IPV6L_NODE
;
1214 #if defined(HAVE_RPKI)
1219 "Enable rpki and enter rpki configuration mode\n")
1221 vty
->node
= RPKI_NODE
;
1229 "Exit current mode and down to previous mode\n")
1231 vty
->node
= CONFIG_NODE
;
1239 "Exit current mode and down to previous mode\n")
1241 return rpki_exit(self
, vty
, argc
, argv
);
1245 DEFUNSH(VTYSH_BGPD
, address_family_evpn
, address_family_evpn_cmd
,
1246 "address-family <l2vpn evpn>",
1247 "Enter Address Family command mode\n"
1249 "Address Family modifier\n")
1251 vty
->node
= BGP_EVPN_NODE
;
1255 #if defined(HAVE_CUMULUS)
1256 DEFUNSH_HIDDEN(VTYSH_BGPD
, address_family_evpn2
, address_family_evpn2_cmd
,
1257 "address-family evpn",
1258 "Enter Address Family command mode\n"
1259 "EVPN Address family\n")
1261 vty
->node
= BGP_EVPN_NODE
;
1266 DEFUNSH(VTYSH_BGPD
, bgp_evpn_vni
, bgp_evpn_vni_cmd
, "vni (1-16777215)",
1267 "VXLAN Network Identifier\n"
1270 vty
->node
= BGP_EVPN_VNI_NODE
;
1274 #if defined(ENABLE_BGP_VNC)
1275 DEFUNSH(VTYSH_BGPD
, vnc_defaults
, vnc_defaults_cmd
, "vnc defaults",
1276 "VNC/RFP related configuration\n"
1277 "Configure default NVE group\n")
1279 vty
->node
= BGP_VNC_DEFAULTS_NODE
;
1283 DEFUNSH(VTYSH_BGPD
, vnc_nve_group
, vnc_nve_group_cmd
, "vnc nve-group NAME",
1284 "VNC/RFP related configuration\n"
1285 "Configure a NVE group\n"
1288 vty
->node
= BGP_VNC_NVE_GROUP_NODE
;
1292 DEFUNSH(VTYSH_BGPD
, vnc_vrf_policy
, vnc_vrf_policy_cmd
, "vrf-policy NAME",
1293 "Configure a VRF policy group\n"
1296 vty
->node
= BGP_VRF_POLICY_NODE
;
1300 DEFUNSH(VTYSH_BGPD
, vnc_l2_group
, vnc_l2_group_cmd
, "vnc l2-group NAME",
1301 "VNC/RFP related configuration\n"
1302 "Configure a L2 group\n"
1305 vty
->node
= BGP_VNC_L2_GROUP_NODE
;
1310 DEFUNSH(VTYSH_RIPD
, key_chain
, key_chain_cmd
, "key chain WORD",
1311 "Authentication key management\n"
1312 "Key-chain management\n"
1315 vty
->node
= KEYCHAIN_NODE
;
1319 DEFUNSH(VTYSH_RIPD
, key
, key_cmd
, "key (0-2147483647)",
1321 "Key identifier number\n")
1323 vty
->node
= KEYCHAIN_KEY_NODE
;
1327 DEFUNSH(VTYSH_RIPD
, router_rip
, router_rip_cmd
, "router rip",
1330 vty
->node
= RIP_NODE
;
1334 DEFUNSH(VTYSH_RIPNGD
, router_ripng
, router_ripng_cmd
, "router ripng",
1335 ROUTER_STR
"RIPng\n")
1337 vty
->node
= RIPNG_NODE
;
1341 DEFUNSH(VTYSH_OSPFD
, router_ospf
, router_ospf_cmd
,
1342 "router ospf [(1-65535)] [vrf NAME]",
1343 "Enable a routing process\n"
1344 "Start OSPF configuration\n"
1348 vty
->node
= OSPF_NODE
;
1352 DEFUNSH(VTYSH_EIGRPD
, router_eigrp
, router_eigrp_cmd
, "router eigrp (1-65535)",
1353 "Enable a routing process\n"
1354 "Start EIGRP configuration\n"
1355 "AS number to use\n")
1357 vty
->node
= EIGRP_NODE
;
1361 DEFUNSH(VTYSH_BABELD
, router_babel
, router_babel_cmd
, "router babel",
1362 "Enable a routing process\n"
1363 "Make Babel instance command\n")
1365 vty
->node
= BABEL_NODE
;
1369 DEFUNSH(VTYSH_OSPF6D
, router_ospf6
, router_ospf6_cmd
, "router ospf6",
1370 ROUTER_STR OSPF6_STR
)
1372 vty
->node
= OSPF6_NODE
;
1376 #if defined(HAVE_LDPD)
1377 DEFUNSH(VTYSH_LDPD
, ldp_mpls_ldp
, ldp_mpls_ldp_cmd
, "mpls ldp",
1378 "Global MPLS configuration subcommands\n"
1379 "Label Distribution Protocol\n")
1381 vty
->node
= LDP_NODE
;
1385 DEFUNSH(VTYSH_LDPD
, ldp_address_family_ipv4
, ldp_address_family_ipv4_cmd
,
1386 "address-family ipv4",
1387 "Configure Address Family and its parameters\n"
1390 vty
->node
= LDP_IPV4_NODE
;
1394 DEFUNSH(VTYSH_LDPD
, ldp_address_family_ipv6
, ldp_address_family_ipv6_cmd
,
1395 "address-family ipv6",
1396 "Configure Address Family and its parameters\n"
1399 vty
->node
= LDP_IPV6_NODE
;
1403 DEFUNSH(VTYSH_LDPD
, ldp_exit_address_family
, ldp_exit_address_family_cmd
,
1404 "exit-address-family", "Exit from Address Family configuration mode\n")
1406 if (vty
->node
== LDP_IPV4_NODE
|| vty
->node
== LDP_IPV6_NODE
)
1407 vty
->node
= LDP_NODE
;
1411 DEFUNSH(VTYSH_LDPD
, ldp_interface_ifname
, ldp_interface_ifname_cmd
,
1413 "Enable LDP on an interface and enter interface submode\n"
1414 "Interface's name\n")
1416 switch (vty
->node
) {
1418 vty
->node
= LDP_IPV4_IFACE_NODE
;
1421 vty
->node
= LDP_IPV6_IFACE_NODE
;
1430 DEFUNSH(VTYSH_LDPD
, ldp_l2vpn_word_type_vpls
, ldp_l2vpn_word_type_vpls_cmd
,
1431 "l2vpn WORD type vpls",
1432 "Configure l2vpn commands\n"
1435 "Virtual Private LAN Service\n")
1437 vty
->node
= LDP_L2VPN_NODE
;
1441 DEFUNSH(VTYSH_LDPD
, ldp_member_pseudowire_ifname
,
1442 ldp_member_pseudowire_ifname_cmd
, "member pseudowire IFNAME",
1443 "L2VPN member configuration\n"
1444 "Pseudowire interface\n"
1445 "Interface's name\n")
1447 vty
->node
= LDP_PSEUDOWIRE_NODE
;
1452 DEFUNSH(VTYSH_ISISD
, router_isis
, router_isis_cmd
, "router isis WORD",
1455 "ISO Routing area tag\n")
1457 vty
->node
= ISIS_NODE
;
1461 DEFUNSH(VTYSH_RMAP
, vtysh_route_map
, vtysh_route_map_cmd
,
1462 "route-map WORD <deny|permit> (1-65535)",
1463 "Create route-map or enter route-map command mode\n"
1465 "Route map denies set operations\n"
1466 "Route map permits set operations\n"
1467 "Sequence to insert to/delete from existing route-map entry\n")
1469 vty
->node
= RMAP_NODE
;
1473 DEFUNSH(VTYSH_ALL
, vtysh_line_vty
, vtysh_line_vty_cmd
, "line vty",
1474 "Configure a terminal line\n"
1475 "Virtual terminal\n")
1477 vty
->node
= VTY_NODE
;
1481 DEFUNSH(VTYSH_REALLYALL
, vtysh_enable
, vtysh_enable_cmd
, "enable",
1482 "Turn on privileged mode command\n")
1484 vty
->node
= ENABLE_NODE
;
1488 DEFUNSH(VTYSH_REALLYALL
, vtysh_disable
, vtysh_disable_cmd
, "disable",
1489 "Turn off privileged mode command\n")
1491 if (vty
->node
== ENABLE_NODE
)
1492 vty
->node
= VIEW_NODE
;
1496 DEFUNSH(VTYSH_REALLYALL
, vtysh_config_terminal
, vtysh_config_terminal_cmd
,
1497 "configure terminal",
1498 "Configuration from vty interface\n"
1499 "Configuration terminal\n")
1501 vty
->node
= CONFIG_NODE
;
1505 static int vtysh_exit(struct vty
*vty
)
1507 switch (vty
->node
) {
1513 vty
->node
= ENABLE_NODE
;
1515 case INTERFACE_NODE
:
1517 case LOGICALROUTER_NODE
:
1529 case LDP_L2VPN_NODE
:
1535 vtysh_execute("end");
1536 vtysh_execute("configure terminal");
1537 vty
->node
= CONFIG_NODE
;
1539 case BGP_VPNV4_NODE
:
1540 case BGP_VPNV6_NODE
:
1542 case BGP_IPV4M_NODE
:
1543 case BGP_IPV4L_NODE
:
1545 case BGP_IPV6M_NODE
:
1546 case BGP_IPV6L_NODE
:
1547 case BGP_VRF_POLICY_NODE
:
1549 case BGP_VNC_DEFAULTS_NODE
:
1550 case BGP_VNC_NVE_GROUP_NODE
:
1551 case BGP_VNC_L2_GROUP_NODE
:
1552 vty
->node
= BGP_NODE
;
1554 case BGP_EVPN_VNI_NODE
:
1555 vty
->node
= BGP_EVPN_NODE
;
1559 vty
->node
= LDP_NODE
;
1561 case LDP_IPV4_IFACE_NODE
:
1562 vty
->node
= LDP_IPV4_NODE
;
1564 case LDP_IPV6_IFACE_NODE
:
1565 vty
->node
= LDP_IPV6_NODE
;
1567 case LDP_PSEUDOWIRE_NODE
:
1568 vty
->node
= LDP_L2VPN_NODE
;
1570 case KEYCHAIN_KEY_NODE
:
1571 vty
->node
= KEYCHAIN_NODE
;
1573 case LINK_PARAMS_NODE
:
1574 vty
->node
= INTERFACE_NODE
;
1582 DEFUNSH(VTYSH_REALLYALL
, vtysh_exit_all
, vtysh_exit_all_cmd
, "exit",
1583 "Exit current mode and down to previous mode\n")
1585 return vtysh_exit(vty
);
1588 DEFUNSH(VTYSH_ALL
, vtysh_quit_all
, vtysh_quit_all_cmd
, "quit",
1589 "Exit current mode and down to previous mode\n")
1591 return vtysh_exit_all(self
, vty
, argc
, argv
);
1594 DEFUNSH(VTYSH_BGPD
, exit_address_family
, exit_address_family_cmd
,
1595 "exit-address-family", "Exit from Address Family configuration mode\n")
1597 if (vty
->node
== BGP_IPV4_NODE
|| vty
->node
== BGP_IPV4M_NODE
1598 || vty
->node
== BGP_IPV4L_NODE
|| vty
->node
== BGP_VPNV4_NODE
1599 || vty
->node
== BGP_VPNV6_NODE
|| vty
->node
== BGP_IPV6_NODE
1600 || vty
->node
== BGP_IPV6L_NODE
|| vty
->node
== BGP_IPV6M_NODE
1601 || vty
->node
== BGP_EVPN_NODE
)
1602 vty
->node
= BGP_NODE
;
1606 DEFUNSH(VTYSH_BGPD
, exit_vni
, exit_vni_cmd
, "exit-vni", "Exit from VNI mode\n")
1608 if (vty
->node
== BGP_EVPN_VNI_NODE
)
1609 vty
->node
= BGP_EVPN_NODE
;
1613 DEFUNSH(VTYSH_BGPD
, exit_vnc_config
, exit_vnc_config_cmd
, "exit-vnc",
1614 "Exit from VNC configuration mode\n")
1616 if (vty
->node
== BGP_VNC_DEFAULTS_NODE
1617 || vty
->node
== BGP_VNC_NVE_GROUP_NODE
1618 || vty
->node
== BGP_VNC_L2_GROUP_NODE
)
1619 vty
->node
= BGP_NODE
;
1623 DEFUNSH(VTYSH_BGPD
, exit_vrf_policy
, exit_vrf_policy_cmd
, "exit-vrf-policy",
1624 "Exit from VRF configuration mode\n")
1626 if (vty
->node
== BGP_VRF_POLICY_NODE
)
1627 vty
->node
= BGP_NODE
;
1631 DEFUNSH(VTYSH_RIPD
, vtysh_exit_ripd
, vtysh_exit_ripd_cmd
, "exit",
1632 "Exit current mode and down to previous mode\n")
1634 return vtysh_exit(vty
);
1637 DEFUNSH(VTYSH_RIPD
, vtysh_quit_ripd
, vtysh_quit_ripd_cmd
, "quit",
1638 "Exit current mode and down to previous mode\n")
1640 return vtysh_exit_ripd(self
, vty
, argc
, argv
);
1643 DEFUNSH(VTYSH_RIPNGD
, vtysh_exit_ripngd
, vtysh_exit_ripngd_cmd
, "exit",
1644 "Exit current mode and down to previous mode\n")
1646 return vtysh_exit(vty
);
1649 DEFUNSH(VTYSH_RIPNGD
, vtysh_quit_ripngd
, vtysh_quit_ripngd_cmd
, "quit",
1650 "Exit current mode and down to previous mode\n")
1652 return vtysh_exit_ripngd(self
, vty
, argc
, argv
);
1655 DEFUNSH(VTYSH_RMAP
, vtysh_exit_rmap
, vtysh_exit_rmap_cmd
, "exit",
1656 "Exit current mode and down to previous mode\n")
1658 return vtysh_exit(vty
);
1661 DEFUNSH(VTYSH_RMAP
, vtysh_quit_rmap
, vtysh_quit_rmap_cmd
, "quit",
1662 "Exit current mode and down to previous mode\n")
1664 return vtysh_exit_rmap(self
, vty
, argc
, argv
);
1667 DEFUNSH(VTYSH_BGPD
, vtysh_exit_bgpd
, vtysh_exit_bgpd_cmd
, "exit",
1668 "Exit current mode and down to previous mode\n")
1670 return vtysh_exit(vty
);
1673 DEFUNSH(VTYSH_BGPD
, vtysh_quit_bgpd
, vtysh_quit_bgpd_cmd
, "quit",
1674 "Exit current mode and down to previous mode\n")
1676 return vtysh_exit_bgpd(self
, vty
, argc
, argv
);
1679 DEFUNSH(VTYSH_OSPFD
, vtysh_exit_ospfd
, vtysh_exit_ospfd_cmd
, "exit",
1680 "Exit current mode and down to previous mode\n")
1682 return vtysh_exit(vty
);
1685 DEFUNSH(VTYSH_OSPFD
, vtysh_quit_ospfd
, vtysh_quit_ospfd_cmd
, "quit",
1686 "Exit current mode and down to previous mode\n")
1688 return vtysh_exit_ospfd(self
, vty
, argc
, argv
);
1691 DEFUNSH(VTYSH_EIGRPD
, vtysh_exit_eigrpd
, vtysh_exit_eigrpd_cmd
, "exit",
1692 "Exit current mode and down to previous mode\n")
1694 return vtysh_exit(vty
);
1697 DEFUNSH(VTYSH_EIGRPD
, vtysh_quit_eigrpd
, vtysh_quit_eigrpd_cmd
, "quit",
1698 "Exit current mode and down to previous mode\n")
1700 return vtysh_exit(vty
);
1703 DEFUNSH(VTYSH_EIGRPD
, vtysh_exit_babeld
, vtysh_exit_babeld_cmd
, "exit",
1704 "Exit current mode and down to previous mode\n")
1706 return vtysh_exit(vty
);
1709 DEFUNSH(VTYSH_BABELD
, vtysh_quit_babeld
, vtysh_quit_babeld_cmd
, "quit",
1710 "Exit current mode and down to previous mode\n")
1712 return vtysh_exit(vty
);
1715 DEFUNSH(VTYSH_OSPF6D
, vtysh_exit_ospf6d
, vtysh_exit_ospf6d_cmd
, "exit",
1716 "Exit current mode and down to previous mode\n")
1718 return vtysh_exit(vty
);
1721 DEFUNSH(VTYSH_OSPF6D
, vtysh_quit_ospf6d
, vtysh_quit_ospf6d_cmd
, "quit",
1722 "Exit current mode and down to previous mode\n")
1724 return vtysh_exit_ospf6d(self
, vty
, argc
, argv
);
1727 #if defined(HAVE_LDPD)
1728 DEFUNSH(VTYSH_LDPD
, vtysh_exit_ldpd
, vtysh_exit_ldpd_cmd
, "exit",
1729 "Exit current mode and down to previous mode\n")
1731 return vtysh_exit(vty
);
1734 ALIAS(vtysh_exit_ldpd
, vtysh_quit_ldpd_cmd
, "quit",
1735 "Exit current mode and down to previous mode\n")
1738 DEFUNSH(VTYSH_ISISD
, vtysh_exit_isisd
, vtysh_exit_isisd_cmd
, "exit",
1739 "Exit current mode and down to previous mode\n")
1741 return vtysh_exit(vty
);
1744 DEFUNSH(VTYSH_ISISD
, vtysh_quit_isisd
, vtysh_quit_isisd_cmd
, "quit",
1745 "Exit current mode and down to previous mode\n")
1747 return vtysh_exit_isisd(self
, vty
, argc
, argv
);
1750 DEFUNSH(VTYSH_ALL
, vtysh_exit_line_vty
, vtysh_exit_line_vty_cmd
, "exit",
1751 "Exit current mode and down to previous mode\n")
1753 return vtysh_exit(vty
);
1756 DEFUNSH(VTYSH_ALL
, vtysh_quit_line_vty
, vtysh_quit_line_vty_cmd
, "quit",
1757 "Exit current mode and down to previous mode\n")
1759 return vtysh_exit_line_vty(self
, vty
, argc
, argv
);
1762 DEFUNSH(VTYSH_INTERFACE
, vtysh_interface
, vtysh_interface_cmd
,
1763 "interface IFNAME [vrf NAME]",
1764 "Select an interface to configure\n"
1765 "Interface's name\n" VRF_CMD_HELP_STR
)
1767 vty
->node
= INTERFACE_NODE
;
1771 DEFUNSH(VTYSH_ZEBRA
, vtysh_pseudowire
, vtysh_pseudowire_cmd
,
1772 "pseudowire IFNAME",
1773 "Static pseudowire configuration\n"
1774 "Pseudowire name\n")
1776 vty
->node
= PW_NODE
;
1780 /* TODO Implement "no interface command in isisd. */
1781 DEFSH(VTYSH_ZEBRA
| VTYSH_RIPD
| VTYSH_RIPNGD
| VTYSH_OSPFD
| VTYSH_OSPF6D
1783 vtysh_no_interface_cmd
, "no interface IFNAME", NO_STR
1784 "Delete a pseudo interface's configuration\n"
1785 "Interface's name\n")
1787 DEFSH(VTYSH_ZEBRA
, vtysh_no_interface_vrf_cmd
, "no interface IFNAME vrf NAME",
1789 "Delete a pseudo interface's configuration\n"
1790 "Interface's name\n" VRF_CMD_HELP_STR
)
1792 DEFUNSH(VTYSH_ZEBRA
, vtysh_logicalrouter
, vtysh_logicalrouter_cmd
,
1793 "logical-router (1-65535) ns NAME",
1794 "Enable a logical-router\n"
1795 "Specify the logical-router indentifier\n"
1797 "The file name in " NS_RUN_DIR
", or a full pathname\n")
1799 vty
->node
= LOGICALROUTER_NODE
;
1803 DEFSH(VTYSH_ZEBRA
, vtysh_no_logicalrouter_cmd
,
1804 "no logical-router (1-65535) ns NAME", NO_STR
1805 "Enable a Logical-Router\n"
1806 "Specify the Logical-Router identifier\n"
1808 "The file name in " NS_RUN_DIR
", or a full pathname\n")
1810 DEFUNSH(VTYSH_VRF
, vtysh_vrf
, vtysh_vrf_cmd
, "vrf NAME",
1811 "Select a VRF to configure\n"
1814 vty
->node
= VRF_NODE
;
1818 DEFSH(VTYSH_ZEBRA
, vtysh_no_vrf_cmd
, "no vrf NAME", NO_STR
1819 "Delete a pseudo vrf's configuration\n"
1822 DEFUNSH(VTYSH_NS
, vtysh_exit_logicalrouter
,
1823 vtysh_exit_logicalrouter_cmd
, "exit",
1824 "Exit current mode and down to previous mode\n")
1826 return vtysh_exit(vty
);
1829 DEFUNSH(VTYSH_NS
, vtysh_quit_logicalrouter
,
1830 vtysh_quit_logicalrouter_cmd
, "quit",
1831 "Exit current mode and down to previous mode\n")
1833 return vtysh_exit_logicalrouter(self
, vty
, argc
, argv
);
1836 DEFUNSH(VTYSH_VRF
, vtysh_exit_vrf
, vtysh_exit_vrf_cmd
, "exit",
1837 "Exit current mode and down to previous mode\n")
1839 return vtysh_exit(vty
);
1842 DEFUNSH(VTYSH_VRF
, vtysh_quit_vrf
, vtysh_quit_vrf_cmd
, "quit",
1843 "Exit current mode and down to previous mode\n")
1845 return vtysh_exit_vrf(self
, vty
, argc
, argv
);
1848 /* TODO Implement interface description commands in ripngd, ospf6d
1850 DEFSH(VTYSH_ZEBRA
| VTYSH_RIPD
| VTYSH_OSPFD
| VTYSH_EIGRPD
,
1851 vtysh_interface_desc_cmd
, "description LINE...",
1852 "Interface specific description\n"
1853 "Characters describing this interface\n")
1855 DEFSH(VTYSH_ZEBRA
| VTYSH_RIPD
| VTYSH_OSPFD
| VTYSH_EIGRPD
,
1856 vtysh_no_interface_desc_cmd
, "no description",
1857 NO_STR
"Interface specific description\n")
1859 DEFUNSH(VTYSH_INTERFACE
, vtysh_exit_interface
, vtysh_exit_interface_cmd
, "exit",
1860 "Exit current mode and down to previous mode\n")
1862 return vtysh_exit(vty
);
1865 DEFUNSH(VTYSH_INTERFACE
, vtysh_quit_interface
, vtysh_quit_interface_cmd
, "quit",
1866 "Exit current mode and down to previous mode\n")
1868 return vtysh_exit_interface(self
, vty
, argc
, argv
);
1871 DEFUN (vtysh_show_thread
,
1872 vtysh_show_thread_cmd
,
1873 "show thread cpu [FILTER]",
1875 "Thread information\n"
1876 "Thread CPU usage\n"
1877 "Display filter (rwtexb)\n")
1881 int ret
= CMD_SUCCESS
;
1884 const char *filter
=
1885 argv_find(argv
, argc
, "FILTER", &idx
) ? argv
[idx
]->arg
: "";
1887 snprintf(line
, sizeof(line
), "do show thread cpu %s\n", filter
);
1888 for (i
= 0; i
< array_size(vtysh_client
); i
++)
1889 if (vtysh_client
[i
].fd
>= 0) {
1890 fprintf(stdout
, "Thread statistics for %s:\n",
1891 vtysh_client
[i
].name
);
1892 ret
= vtysh_client_execute(&vtysh_client
[i
], line
,
1894 fprintf(stdout
, "\n");
1899 DEFUN (vtysh_show_work_queues
,
1900 vtysh_show_work_queues_cmd
,
1903 "Work Queue information\n")
1906 int ret
= CMD_SUCCESS
;
1907 char line
[] = "do show work-queues\n";
1909 for (i
= 0; i
< array_size(vtysh_client
); i
++)
1910 if (vtysh_client
[i
].fd
>= 0) {
1911 fprintf(stdout
, "Work queue statistics for %s:\n",
1912 vtysh_client
[i
].name
);
1913 ret
= vtysh_client_execute(&vtysh_client
[i
], line
,
1915 fprintf(stdout
, "\n");
1921 DEFUN (vtysh_show_work_queues_daemon
,
1922 vtysh_show_work_queues_daemon_cmd
,
1923 "show work-queues <zebra|ripd|ripngd|ospfd|ospf6d|bgpd|isisd>",
1925 "Work Queue information\n"
1926 "For the zebra daemon\n"
1927 "For the rip daemon\n"
1928 "For the ripng daemon\n"
1929 "For the ospf daemon\n"
1930 "For the ospfv6 daemon\n"
1931 "For the bgp daemon\n"
1932 "For the isis daemon\n")
1934 int idx_protocol
= 2;
1936 int ret
= CMD_SUCCESS
;
1938 for (i
= 0; i
< array_size(vtysh_client
); i
++) {
1939 if (strmatch(vtysh_client
[i
].name
, argv
[idx_protocol
]->text
))
1943 ret
= vtysh_client_execute(&vtysh_client
[i
], "show work-queues\n",
1949 DEFUNSH(VTYSH_ZEBRA
, vtysh_link_params
, vtysh_link_params_cmd
, "link-params",
1952 vty
->node
= LINK_PARAMS_NODE
;
1956 DEFUNSH(VTYSH_ZEBRA
, exit_link_params
, exit_link_params_cmd
, "exit-link-params",
1957 "Exit from Link Params configuration node\n")
1959 if (vty
->node
== LINK_PARAMS_NODE
)
1960 vty
->node
= INTERFACE_NODE
;
1964 static int show_per_daemon(const char *line
, const char *headline
)
1967 int ret
= CMD_SUCCESS
;
1969 for (i
= 0; i
< array_size(vtysh_client
); i
++)
1970 if (vtysh_client
[i
].fd
>= 0) {
1971 fprintf(outputfile
, headline
, vtysh_client
[i
].name
);
1972 ret
= vtysh_client_execute(&vtysh_client
[i
], line
,
1974 fprintf(stdout
, "\n");
1980 DEFUNSH_HIDDEN (0x00,
1982 vtysh_debug_all_cmd
,
1986 "Toggle all debugs on or off\n")
1991 DEFUN (vtysh_show_debugging
,
1992 vtysh_show_debugging_cmd
,
1997 return show_per_daemon("do show debugging\n", "");
2000 DEFUN (vtysh_show_debugging_hashtable
,
2001 vtysh_show_debugging_hashtable_cmd
,
2002 "show debugging hashtable [statistics]",
2005 "Statistics about hash tables\n"
2006 "Statistics about hash tables\n")
2008 fprintf(stdout
, "\n");
2010 "Load factor (LF) - average number of elements across all buckets\n");
2012 "Full load factor (FLF) - average number of elements across full buckets\n\n");
2014 "Standard deviation (SD) is calculated for both the LF and FLF\n");
2016 "and indicates the typical deviation of bucket chain length\n");
2017 fprintf(stdout
, "from the value in the corresponding load factor.\n\n");
2019 return show_per_daemon("do show debugging hashtable\n",
2020 "Hashtable statistics for %s:\n");
2024 DEFUN (vtysh_show_memory
,
2025 vtysh_show_memory_cmd
,
2028 "Memory statistics\n")
2030 return show_per_daemon("show memory\n", "Memory statistics for %s:\n");
2033 DEFUN (vtysh_show_modules
,
2034 vtysh_show_modules_cmd
,
2039 return show_per_daemon("show modules\n",
2040 "Module information for %s:\n");
2043 /* Logging commands. */
2044 DEFUN (vtysh_show_logging
,
2045 vtysh_show_logging_cmd
,
2048 "Show current logging configuration\n")
2050 return show_per_daemon("do show logging\n",
2051 "Logging configuration for %s:\n");
2054 DEFUNSH(VTYSH_ALL
, vtysh_log_stdout
, vtysh_log_stdout_cmd
, "log stdout",
2056 "Set stdout logging level\n")
2061 DEFUNSH(VTYSH_ALL
, vtysh_log_stdout_level
, vtysh_log_stdout_level_cmd
,
2062 "log stdout <emergencies|alerts|critical|errors|warnings|notifications|informational|debugging>",
2064 "Set stdout logging level\n" LOG_LEVEL_DESC
)
2069 DEFUNSH(VTYSH_ALL
, no_vtysh_log_stdout
, no_vtysh_log_stdout_cmd
,
2070 "no log stdout [LEVEL]", NO_STR
2072 "Cancel logging to stdout\n"
2078 DEFUNSH(VTYSH_ALL
, vtysh_log_file
, vtysh_log_file_cmd
, "log file FILENAME",
2081 "Logging filename\n")
2086 DEFUNSH(VTYSH_ALL
, vtysh_log_file_level
, vtysh_log_file_level_cmd
,
2087 "log file FILENAME <emergencies|alerts|critical|errors|warnings|notifications|informational|debugging>",
2090 "Logging filename\n" LOG_LEVEL_DESC
)
2095 DEFUNSH(VTYSH_ALL
, no_vtysh_log_file
, no_vtysh_log_file_cmd
,
2096 "no log file [FILENAME [LEVEL]]", NO_STR
2098 "Cancel logging to file\n"
2099 "Logging file name\n"
2105 DEFUNSH(VTYSH_ALL
, vtysh_log_monitor
, vtysh_log_monitor_cmd
,
2106 "log monitor [<emergencies|alerts|critical|errors|warnings|notifications|informational|debugging>]",
2108 "Set terminal line (monitor) logging level\n" LOG_LEVEL_DESC
)
2113 DEFUNSH(VTYSH_ALL
, no_vtysh_log_monitor
, no_vtysh_log_monitor_cmd
,
2114 "no log monitor [LEVEL]", NO_STR
2116 "Disable terminal line (monitor) logging\n"
2122 DEFUNSH(VTYSH_ALL
, vtysh_log_syslog
, vtysh_log_syslog_cmd
,
2123 "log syslog [<emergencies|alerts|critical|errors|warnings|notifications|informational|debugging>]",
2125 "Set syslog logging level\n" LOG_LEVEL_DESC
)
2130 DEFUNSH(VTYSH_ALL
, no_vtysh_log_syslog
, no_vtysh_log_syslog_cmd
,
2131 "no log syslog [LEVEL]", NO_STR
2133 "Cancel logging to syslog\n"
2139 DEFUNSH(VTYSH_ALL
, vtysh_log_facility
, vtysh_log_facility_cmd
,
2140 "log facility <kern|user|mail|daemon|auth|syslog|lpr|news|uucp|cron|local0|local1|local2|local3|local4|local5|local6|local7>",
2142 "Facility parameter for syslog messages\n" LOG_FACILITY_DESC
)
2147 DEFUNSH(VTYSH_ALL
, no_vtysh_log_facility
, no_vtysh_log_facility_cmd
,
2148 "no log facility [FACILITY]", NO_STR
2150 "Reset syslog facility to default (daemon)\n"
2151 "Syslog facility\n")
2157 VTYSH_ALL
, vtysh_log_trap
, vtysh_log_trap_cmd
,
2158 "log trap <emergencies|alerts|critical|errors|warnings|notifications|informational|debugging>",
2160 "(Deprecated) Set logging level and default for all destinations\n" LOG_LEVEL_DESC
)
2165 DEFUNSH_DEPRECATED(VTYSH_ALL
, no_vtysh_log_trap
, no_vtysh_log_trap_cmd
,
2166 "no log trap [LEVEL]", NO_STR
2168 "Permit all logging information\n"
2174 DEFUNSH(VTYSH_ALL
, vtysh_log_record_priority
, vtysh_log_record_priority_cmd
,
2175 "log record-priority",
2177 "Log the priority of the message within the message\n")
2182 DEFUNSH(VTYSH_ALL
, no_vtysh_log_record_priority
,
2183 no_vtysh_log_record_priority_cmd
, "no log record-priority", NO_STR
2185 "Do not log the priority of the message within the message\n")
2190 DEFUNSH(VTYSH_ALL
, vtysh_log_timestamp_precision
,
2191 vtysh_log_timestamp_precision_cmd
, "log timestamp precision (0-6)",
2193 "Timestamp configuration\n"
2194 "Set the timestamp precision\n"
2195 "Number of subsecond digits\n")
2200 DEFUNSH(VTYSH_ALL
, no_vtysh_log_timestamp_precision
,
2201 no_vtysh_log_timestamp_precision_cmd
, "no log timestamp precision",
2204 "Timestamp configuration\n"
2205 "Reset the timestamp precision to the default value of 0\n")
2210 DEFUNSH(VTYSH_ALL
, vtysh_service_password_encrypt
,
2211 vtysh_service_password_encrypt_cmd
, "service password-encryption",
2212 "Set up miscellaneous service\n"
2213 "Enable encrypted passwords\n")
2218 DEFUNSH(VTYSH_ALL
, no_vtysh_service_password_encrypt
,
2219 no_vtysh_service_password_encrypt_cmd
, "no service password-encryption",
2221 "Set up miscellaneous service\n"
2222 "Enable encrypted passwords\n")
2227 DEFUNSH(VTYSH_ALL
, vtysh_config_password
, vtysh_password_cmd
,
2228 "password [(8-8)] LINE",
2229 "Assign the terminal connection password\n"
2230 "Specifies a HIDDEN password will follow\n"
2231 "The password string\n")
2236 DEFUNSH(VTYSH_ALL
, vtysh_config_enable_password
, vtysh_enable_password_cmd
,
2237 "enable password [(8-8)] LINE",
2238 "Modify enable password parameters\n"
2239 "Assign the privileged level password\n"
2240 "Specifies a HIDDEN password will follow\n"
2241 "The 'enable' password string\n")
2246 DEFUNSH(VTYSH_ALL
, no_vtysh_config_enable_password
,
2247 no_vtysh_enable_password_cmd
, "no enable password", NO_STR
2248 "Modify enable password parameters\n"
2249 "Assign the privileged level password\n")
2254 DEFUN (vtysh_write_terminal
,
2255 vtysh_write_terminal_cmd
,
2256 "write terminal [<zebra|ripd|ripngd|ospfd|ospf6d|ldpd|bgpd|isisd|pimd>]",
2257 "Write running configuration to memory, network, or terminal\n"
2258 "Write to terminal\n"
2259 "For the zebra daemon\n"
2260 "For the rip daemon\n"
2261 "For the ripng daemon\n"
2262 "For the ospf daemon\n"
2263 "For the ospfv6 daemon\n"
2264 "For the ldpd daemon\n"
2265 "For the bgp daemon\n"
2266 "For the isis daemon\n"
2267 "For the pim daemon\n")
2270 char line
[] = "do write terminal\n";
2271 FILE *fp
= outputfile
;
2273 if (fp
== stdout
&& vtysh_pager_name
) {
2274 fp
= popen(vtysh_pager_name
, "w");
2281 fprintf(outputfile
, "Building configuration...\n");
2282 fprintf(outputfile
, "\nCurrent configuration:\n");
2283 fprintf(outputfile
, "!\n");
2285 for (i
= 0; i
< array_size(vtysh_client
); i
++)
2287 || (strmatch(vtysh_client
[i
].name
, argv
[2]->text
)))
2288 vtysh_client_config(&vtysh_client
[i
], line
);
2290 /* Integrate vtysh specific configuration. */
2291 vtysh_config_write();
2293 vtysh_config_dump(fp
);
2295 if (vtysh_pager_name
&& fp
&& fp
!= outputfile
) {
2297 if (pclose(fp
) == -1) {
2304 fprintf(outputfile
, "end\n");
2308 DEFUN (vtysh_show_running_config
,
2309 vtysh_show_running_config_cmd
,
2310 "show running-config [<zebra|ripd|ripngd|ospfd|ospf6d|ldpd|bgpd|isisd|pimd>]",
2312 "Current operating configuration\n"
2313 "For the zebra daemon\n"
2314 "For the rip daemon\n"
2315 "For the ripng daemon\n"
2316 "For the ospf daemon\n"
2317 "For the ospfv6 daemon\n"
2318 "For the ldp daemon\n"
2319 "For the bgp daemon\n"
2320 "For the isis daemon\n"
2321 "For the pim daemon\n")
2323 return vtysh_write_terminal(self
, vty
, argc
, argv
);
2326 DEFUN (vtysh_integrated_config
,
2327 vtysh_integrated_config_cmd
,
2328 "service integrated-vtysh-config",
2329 "Set up miscellaneous service\n"
2330 "Write configuration into integrated file\n")
2332 vtysh_write_integrated
= WRITE_INTEGRATED_YES
;
2336 DEFUN (no_vtysh_integrated_config
,
2337 no_vtysh_integrated_config_cmd
,
2338 "no service integrated-vtysh-config",
2340 "Set up miscellaneous service\n"
2341 "Write configuration into integrated file\n")
2343 vtysh_write_integrated
= WRITE_INTEGRATED_NO
;
2347 static void backup_config_file(const char *fbackup
)
2349 char *integrate_sav
= NULL
;
2351 integrate_sav
= malloc(strlen(fbackup
) + strlen(CONF_BACKUP_EXT
) + 1);
2352 strcpy(integrate_sav
, fbackup
);
2353 strcat(integrate_sav
, CONF_BACKUP_EXT
);
2355 /* Move current configuration file to backup config file. */
2356 unlink(integrate_sav
);
2357 rename(fbackup
, integrate_sav
);
2358 free(integrate_sav
);
2361 int vtysh_write_config_integrated(void)
2364 char line
[] = "do write terminal\n";
2367 struct passwd
*pwentry
;
2368 struct group
*grentry
;
2374 fprintf(stdout
, "Building Configuration...\n");
2376 backup_config_file(frr_config
);
2377 fp
= fopen(frr_config
, "w");
2380 "%% Error: failed to open configuration file %s: %s\n",
2381 frr_config
, safe_strerror(errno
));
2382 return CMD_WARNING_CONFIG_FAILED
;
2386 for (i
= 0; i
< array_size(vtysh_client
); i
++)
2387 vtysh_client_config(&vtysh_client
[i
], line
);
2389 vtysh_config_write();
2390 vtysh_config_dump(fp
);
2392 if (fchmod(fd
, CONFIGFILE_MASK
) != 0) {
2393 printf("%% Warning: can't chmod configuration file %s: %s\n",
2394 frr_config
, safe_strerror(errno
));
2399 pwentry
= getpwnam(FRR_USER
);
2401 uid
= pwentry
->pw_uid
;
2403 printf("%% Warning: could not look up user \"%s\"\n", FRR_USER
);
2408 grentry
= getgrnam(FRR_GROUP
);
2410 gid
= grentry
->gr_gid
;
2412 printf("%% Warning: could not look up group \"%s\"\n",
2418 if (!fstat(fd
, &st
)) {
2419 if (st
.st_uid
== uid
)
2421 if (st
.st_gid
== gid
)
2423 if ((uid
!= (uid_t
)-1 || gid
!= (gid_t
)-1)
2424 && fchown(fd
, uid
, gid
)) {
2425 printf("%% Warning: can't chown configuration file %s: %s\n",
2426 frr_config
, safe_strerror(errno
));
2430 printf("%% Warning: stat() failed on %s: %s\n", frr_config
,
2431 safe_strerror(errno
));
2437 printf("Integrated configuration saved to %s\n", frr_config
);
2445 static bool want_config_integrated(void)
2449 switch (vtysh_write_integrated
) {
2450 case WRITE_INTEGRATED_UNSPECIFIED
:
2451 if (stat(frr_config
, &s
) && errno
== ENOENT
)
2454 case WRITE_INTEGRATED_NO
:
2456 case WRITE_INTEGRATED_YES
:
2462 DEFUN (vtysh_write_memory
,
2463 vtysh_write_memory_cmd
,
2464 "write [<memory|file>]",
2465 "Write running configuration to memory, network, or terminal\n"
2466 "Write configuration to the file (same as write file)\n"
2467 "Write configuration to the file (same as write memory)\n")
2469 int ret
= CMD_SUCCESS
;
2470 char line
[] = "do write memory\n";
2474 "Note: this version of vtysh never writes vtysh.conf\n");
2476 /* If integrated frr.conf explicitely set. */
2477 if (want_config_integrated()) {
2478 ret
= CMD_WARNING_CONFIG_FAILED
;
2479 for (i
= 0; i
< array_size(vtysh_client
); i
++)
2480 if (vtysh_client
[i
].flag
== VTYSH_WATCHFRR
)
2482 if (i
< array_size(vtysh_client
) && vtysh_client
[i
].fd
!= -1)
2483 ret
= vtysh_client_execute(&vtysh_client
[i
],
2484 "do write integrated",
2488 * If watchfrr returns CMD_WARNING_CONFIG_FAILED this means
2489 * that it could not write the config, but additionally
2490 * indicates that we should not try either
2492 if (ret
!= CMD_SUCCESS
&& ret
!= CMD_WARNING_CONFIG_FAILED
) {
2493 printf("\nWarning: attempting direct configuration write without "
2494 "watchfrr.\nFile permissions and ownership may be "
2495 "incorrect, or write may fail.\n\n");
2496 ret
= vtysh_write_config_integrated();
2501 fprintf(outputfile
, "Building Configuration...\n");
2503 for (i
= 0; i
< array_size(vtysh_client
); i
++)
2504 ret
= vtysh_client_execute(&vtysh_client
[i
], line
, outputfile
);
2509 DEFUN (vtysh_copy_running_config
,
2510 vtysh_copy_running_config_cmd
,
2511 "copy running-config startup-config",
2512 "Copy from one file to another\n"
2513 "Copy from current system configuration\n"
2514 "Copy to startup configuration\n")
2516 return vtysh_write_memory(self
, vty
, argc
, argv
);
2519 DEFUN (vtysh_terminal_length
,
2520 vtysh_terminal_length_cmd
,
2521 "terminal length (0-512)",
2522 "Set terminal line parameters\n"
2523 "Set number of lines on a screen\n"
2524 "Number of lines on screen (0 for no pausing)\n")
2528 char *endptr
= NULL
;
2529 char default_pager
[10];
2531 lines
= strtol(argv
[idx_number
]->arg
, &endptr
, 10);
2532 if (lines
< 0 || lines
> 512 || *endptr
!= '\0') {
2533 fprintf(outputfile
, "length is malformed\n");
2537 if (vtysh_pager_name
) {
2538 free(vtysh_pager_name
);
2539 vtysh_pager_name
= NULL
;
2543 snprintf(default_pager
, 10, "more -%i", lines
);
2544 vtysh_pager_name
= strdup(default_pager
);
2550 DEFUN (vtysh_terminal_no_length
,
2551 vtysh_terminal_no_length_cmd
,
2552 "terminal no length",
2553 "Set terminal line parameters\n"
2555 "Set number of lines on a screen\n")
2557 if (vtysh_pager_name
) {
2558 free(vtysh_pager_name
);
2559 vtysh_pager_name
= NULL
;
2566 DEFUN (vtysh_show_daemons
,
2567 vtysh_show_daemons_cmd
,
2570 "Show list of running daemons\n")
2574 for (i
= 0; i
< array_size(vtysh_client
); i
++)
2575 if (vtysh_client
[i
].fd
>= 0)
2576 fprintf(outputfile
, " %s", vtysh_client
[i
].name
);
2577 fprintf(outputfile
, "\n");
2582 /* Execute command in child process. */
2583 static void execute_command(const char *command
, int argc
, const char *arg1
,
2593 /* Failure of fork(). */
2594 fprintf(stderr
, "Can't fork: %s\n", safe_strerror(errno
));
2596 } else if (pid
== 0) {
2597 /* This is child process. */
2600 execlp(command
, command
, (const char *)NULL
);
2603 execlp(command
, command
, arg1
, (const char *)NULL
);
2606 execlp(command
, command
, arg1
, arg2
,
2607 (const char *)NULL
);
2611 /* When execlp suceed, this part is not executed. */
2612 fprintf(stderr
, "Can't execute %s: %s\n", command
,
2613 safe_strerror(errno
));
2616 /* This is parent. */
2618 wait4(pid
, &status
, 0, NULL
);
2626 "Send echo messages\n"
2627 "Ping destination address or hostname\n")
2631 argv_find(argv
, argc
, "WORD", &idx
);
2632 execute_command("ping", 1, argv
[idx
]->arg
, NULL
);
2636 ALIAS(vtysh_ping
, vtysh_ping_ip_cmd
, "ping ip WORD",
2637 "Send echo messages\n"
2639 "Ping destination address or hostname\n")
2641 DEFUN (vtysh_traceroute
,
2642 vtysh_traceroute_cmd
,
2644 "Trace route to destination\n"
2645 "Trace route to destination address or hostname\n")
2649 argv_find(argv
, argc
, "WORD", &idx
);
2650 execute_command("traceroute", 1, argv
[idx
]->arg
, NULL
);
2654 ALIAS(vtysh_traceroute
, vtysh_traceroute_ip_cmd
, "traceroute ip WORD",
2655 "Trace route to destination\n"
2657 "Trace route to destination address or hostname\n")
2659 DEFUN (vtysh_mtrace
,
2662 "Multicast trace route to multicast source\n"
2663 "Multicast trace route to multicast source address\n")
2667 argv_find(argv
, argc
, "WORD", &idx
);
2668 execute_command("mtracebis", 1, argv
[idx
]->arg
, NULL
);
2675 "Send echo messages\n"
2677 "Ping destination address or hostname\n")
2679 execute_command("ping6", 1, argv
[2]->arg
, NULL
);
2683 DEFUN (vtysh_traceroute6
,
2684 vtysh_traceroute6_cmd
,
2685 "traceroute ipv6 WORD",
2686 "Trace route to destination\n"
2688 "Trace route to destination address or hostname\n")
2690 execute_command("traceroute6", 1, argv
[2]->arg
, NULL
);
2694 #if defined(HAVE_SHELL_ACCESS)
2695 DEFUN (vtysh_telnet
,
2698 "Open a telnet connection\n"
2699 "IP address or hostname of a remote system\n")
2701 execute_command("telnet", 1, argv
[1]->arg
, NULL
);
2705 DEFUN (vtysh_telnet_port
,
2706 vtysh_telnet_port_cmd
,
2708 "Open a telnet connection\n"
2709 "IP address or hostname of a remote system\n"
2710 "TCP Port number\n")
2712 execute_command("telnet", 2, argv
[1]->arg
, argv
[2]->arg
);
2719 "Open an ssh connection\n"
2722 execute_command("ssh", 1, argv
[1]->arg
, NULL
);
2726 DEFUN (vtysh_start_shell
,
2727 vtysh_start_shell_cmd
,
2729 "Start UNIX shell\n")
2731 execute_command("sh", 0, NULL
, NULL
);
2735 DEFUN (vtysh_start_bash
,
2736 vtysh_start_bash_cmd
,
2738 "Start UNIX shell\n"
2741 execute_command("bash", 0, NULL
, NULL
);
2745 DEFUN (vtysh_start_zsh
,
2746 vtysh_start_zsh_cmd
,
2748 "Start UNIX shell\n"
2751 execute_command("zsh", 0, NULL
, NULL
);
2758 "list [permutations]",
2759 "Print command list\n"
2760 "Print all possible command permutations\n")
2762 return cmd_list_cmds(vty
, argc
== 2);
2765 DEFUN (vtysh_output_file
,
2766 vtysh_output_file_cmd
,
2768 "Direct vtysh output to file\n"
2769 "Direct vtysh output to file\n"
2770 "Path to dump output to\n")
2772 const char *path
= argv
[argc
- 1]->arg
;
2773 outputfile
= fopen(path
, "a");
2775 fprintf(stdout
, "Failed to open file '%s': %s\n", path
,
2776 safe_strerror(errno
));
2777 outputfile
= stdout
;
2782 DEFUN (no_vtysh_output_file
,
2783 no_vtysh_output_file_cmd
,
2784 "no output file [FILE]",
2786 "Direct vtysh output to file\n"
2787 "Direct vtysh output to file\n"
2788 "Path to dump output to\n")
2790 if (outputfile
!= stdout
) {
2792 outputfile
= stdout
;
2800 "Find CLI command containing text\n"
2801 "Text to search for\n")
2803 char *text
= argv_concat(argv
, argc
, 1);
2804 const struct cmd_node
*node
;
2805 const struct cmd_element
*cli
;
2808 for (unsigned int i
= 0; i
< vector_active(cmdvec
); i
++) {
2809 node
= vector_slot(cmdvec
, i
);
2812 clis
= node
->cmd_vector
;
2813 for (unsigned int j
= 0; j
< vector_active(clis
); j
++) {
2814 cli
= vector_slot(clis
, j
);
2815 if (strcasestr(cli
->string
, text
))
2816 fprintf(stdout
, " (%s) %s\n",
2817 node_names
[node
->node
], cli
->string
);
2821 XFREE(MTYPE_TMP
, text
);
2826 static void vtysh_install_default(enum node_type node
)
2828 install_element(node
, &config_list_cmd
);
2829 install_element(node
, &find_cmd
);
2830 install_element(node
, &vtysh_output_file_cmd
);
2831 install_element(node
, &no_vtysh_output_file_cmd
);
2834 /* Making connection to protocol daemon. */
2835 static int vtysh_connect(struct vtysh_client
*vclient
)
2839 struct sockaddr_un addr
;
2843 if (!vclient
->path
[0])
2844 snprintf(vclient
->path
, sizeof(vclient
->path
), "%s/%s.vty",
2845 vtydir
, vclient
->name
);
2846 path
= vclient
->path
;
2848 /* Stat socket to see if we have permission to access it. */
2849 ret
= stat(path
, &s_stat
);
2850 if (ret
< 0 && errno
!= ENOENT
) {
2851 fprintf(stderr
, "vtysh_connect(%s): stat = %s\n", path
,
2852 safe_strerror(errno
));
2857 if (!S_ISSOCK(s_stat
.st_mode
)) {
2858 fprintf(stderr
, "vtysh_connect(%s): Not a socket\n",
2864 sock
= socket(AF_UNIX
, SOCK_STREAM
, 0);
2867 fprintf(stderr
, "vtysh_connect(%s): socket = %s\n", path
,
2868 safe_strerror(errno
));
2873 memset(&addr
, 0, sizeof(struct sockaddr_un
));
2874 addr
.sun_family
= AF_UNIX
;
2875 strlcpy(addr
.sun_path
, path
, sizeof(addr
.sun_path
));
2876 #ifdef HAVE_STRUCT_SOCKADDR_UN_SUN_LEN
2877 len
= addr
.sun_len
= SUN_LEN(&addr
);
2879 len
= sizeof(addr
.sun_family
) + strlen(addr
.sun_path
);
2880 #endif /* HAVE_STRUCT_SOCKADDR_UN_SUN_LEN */
2882 ret
= connect(sock
, (struct sockaddr
*)&addr
, len
);
2885 fprintf(stderr
, "vtysh_connect(%s): connect = %s\n", path
,
2886 safe_strerror(errno
));
2896 /* Return true if str ends with suffix, else return false */
2897 static int ends_with(const char *str
, const char *suffix
)
2899 if (!str
|| !suffix
)
2901 size_t lenstr
= strlen(str
);
2902 size_t lensuffix
= strlen(suffix
);
2903 if (lensuffix
> lenstr
)
2905 return strncmp(str
+ lenstr
- lensuffix
, suffix
, lensuffix
) == 0;
2908 static void vtysh_client_sorted_insert(struct vtysh_client
*head_client
,
2909 struct vtysh_client
*client
)
2911 struct vtysh_client
*prev_node
, *current_node
;
2913 prev_node
= head_client
;
2914 current_node
= head_client
->next
;
2915 while (current_node
) {
2916 if (strcmp(current_node
->path
, client
->path
) > 0)
2919 prev_node
= current_node
;
2920 current_node
= current_node
->next
;
2922 client
->next
= current_node
;
2923 prev_node
->next
= client
;
2926 #define MAXIMUM_INSTANCES 10
2928 static void vtysh_update_all_insances(struct vtysh_client
*head_client
)
2930 struct vtysh_client
*client
;
2932 struct dirent
*file
;
2935 if (head_client
->flag
!= VTYSH_OSPFD
)
2938 /* ls vty_sock_dir and look for all files ending in .vty */
2939 dir
= opendir(vtydir
);
2941 while ((file
= readdir(dir
)) != NULL
) {
2942 if (begins_with(file
->d_name
, "ospfd-")
2943 && ends_with(file
->d_name
, ".vty")) {
2944 if (n
== MAXIMUM_INSTANCES
) {
2946 "Parsing %s, client limit(%d) reached!\n",
2950 client
= (struct vtysh_client
*)malloc(
2951 sizeof(struct vtysh_client
));
2953 client
->name
= "ospfd";
2954 client
->flag
= VTYSH_OSPFD
;
2955 snprintf(client
->path
, sizeof(client
->path
),
2956 "%s/%s", vtydir
, file
->d_name
);
2957 client
->next
= NULL
;
2958 vtysh_client_sorted_insert(head_client
, client
);
2966 static int vtysh_connect_all_instances(struct vtysh_client
*head_client
)
2968 struct vtysh_client
*client
;
2971 vtysh_update_all_insances(head_client
);
2973 client
= head_client
->next
;
2975 if (vtysh_connect(client
) == 0)
2977 client
= client
->next
;
2983 int vtysh_connect_all(const char *daemon_name
)
2989 for (i
= 0; i
< array_size(vtysh_client
); i
++) {
2991 || !strcmp(daemon_name
, vtysh_client
[i
].name
)) {
2993 if (vtysh_connect(&vtysh_client
[i
]) == 0)
2996 rc
+= vtysh_connect_all_instances(&vtysh_client
[i
]);
3000 fprintf(stderr
, "Error: no daemons match name %s!\n",
3005 /* To disable readline's filename completion. */
3006 static char *vtysh_completion_entry_function(const char *ignore
,
3012 void vtysh_readline_init(void)
3014 /* readline related settings. */
3016 rl_bind_key('?', (rl_command_func_t
*)vtysh_rl_describe
);
3017 rl_completion_entry_function
= vtysh_completion_entry_function
;
3018 rl_attempted_completion_function
=
3019 (rl_completion_func_t
*)new_completion
;
3022 char *vtysh_prompt(void)
3024 static char buf
[100];
3026 snprintf(buf
, sizeof buf
, cmd_prompt(vty
->node
), cmd_hostname_get());
3030 static void vtysh_ac_line(void *arg
, const char *line
)
3034 for (i
= 0; i
< vector_active(comps
); i
++)
3035 if (!strcmp(line
, (char *)vector_slot(comps
, i
)))
3037 vector_set(comps
, XSTRDUP(MTYPE_COMPLETION
, line
));
3040 static void vtysh_autocomplete(vector comps
, struct cmd_token
*token
)
3045 snprintf(accmd
, sizeof(accmd
), "autocomplete %d %s %s", token
->type
,
3046 token
->text
, token
->varname
? token
->varname
: "-");
3048 for (i
= 0; i
< array_size(vtysh_client
); i
++)
3049 vtysh_client_run_all(&vtysh_client
[i
], accmd
, 1, NULL
,
3050 vtysh_ac_line
, comps
);
3053 static const struct cmd_variable_handler vtysh_var_handler
[] = {
3057 .completions
= vtysh_autocomplete
},
3058 {.completions
= NULL
}};
3062 if (outputfile
!= stdout
)
3066 void vtysh_init_vty(void)
3068 /* Make vty structure. */
3070 vty
->type
= VTY_SHELL
;
3071 vty
->node
= VIEW_NODE
;
3073 /* set default output */
3074 outputfile
= stdout
;
3076 /* Initialize commands. */
3078 cmd_variable_handler_register(vtysh_var_handler
);
3080 /* Install nodes. */
3081 install_node(&bgp_node
, NULL
);
3082 install_node(&rip_node
, NULL
);
3083 install_node(&interface_node
, NULL
);
3084 install_node(&pw_node
, NULL
);
3085 install_node(&link_params_node
, NULL
);
3086 install_node(&logicalrouter_node
, NULL
);
3087 install_node(&vrf_node
, NULL
);
3088 install_node(&rmap_node
, NULL
);
3089 install_node(&zebra_node
, NULL
);
3090 install_node(&bgp_vpnv4_node
, NULL
);
3091 install_node(&bgp_vpnv6_node
, NULL
);
3092 install_node(&bgp_ipv4_node
, NULL
);
3093 install_node(&bgp_ipv4m_node
, NULL
);
3094 install_node(&bgp_ipv4l_node
, NULL
);
3095 install_node(&bgp_ipv6_node
, NULL
);
3096 install_node(&bgp_ipv6m_node
, NULL
);
3097 install_node(&bgp_ipv6l_node
, NULL
);
3098 install_node(&bgp_vrf_policy_node
, NULL
);
3099 install_node(&bgp_evpn_node
, NULL
);
3100 install_node(&bgp_evpn_vni_node
, NULL
);
3101 install_node(&bgp_vnc_defaults_node
, NULL
);
3102 install_node(&bgp_vnc_nve_group_node
, NULL
);
3103 install_node(&bgp_vnc_l2_group_node
, NULL
);
3104 install_node(&ospf_node
, NULL
);
3105 install_node(&eigrp_node
, NULL
);
3106 install_node(&babel_node
, NULL
);
3107 install_node(&ripng_node
, NULL
);
3108 install_node(&ospf6_node
, NULL
);
3109 install_node(&ldp_node
, NULL
);
3110 install_node(&ldp_ipv4_node
, NULL
);
3111 install_node(&ldp_ipv6_node
, NULL
);
3112 install_node(&ldp_ipv4_iface_node
, NULL
);
3113 install_node(&ldp_ipv6_iface_node
, NULL
);
3114 install_node(&ldp_l2vpn_node
, NULL
);
3115 install_node(&ldp_pseudowire_node
, NULL
);
3116 install_node(&keychain_node
, NULL
);
3117 install_node(&keychain_key_node
, NULL
);
3118 install_node(&isis_node
, NULL
);
3119 install_node(&vty_node
, NULL
);
3120 #if defined(HAVE_RPKI)
3121 install_node(&rpki_node
, NULL
);
3124 struct cmd_node
*node
;
3125 for (unsigned int i
= 0; i
< vector_active(cmdvec
); i
++) {
3126 node
= vector_slot(cmdvec
, i
);
3127 if (!node
|| node
->node
== VIEW_NODE
)
3129 vtysh_install_default(node
->node
);
3132 install_element(VIEW_NODE
, &vtysh_enable_cmd
);
3133 install_element(ENABLE_NODE
, &vtysh_config_terminal_cmd
);
3134 install_element(ENABLE_NODE
, &vtysh_disable_cmd
);
3136 /* "exit" command. */
3137 install_element(VIEW_NODE
, &vtysh_exit_all_cmd
);
3138 install_element(CONFIG_NODE
, &vtysh_exit_all_cmd
);
3139 install_element(VIEW_NODE
, &vtysh_quit_all_cmd
);
3140 install_element(CONFIG_NODE
, &vtysh_quit_all_cmd
);
3141 install_element(RIP_NODE
, &vtysh_exit_ripd_cmd
);
3142 install_element(RIP_NODE
, &vtysh_quit_ripd_cmd
);
3143 install_element(RIPNG_NODE
, &vtysh_exit_ripngd_cmd
);
3144 install_element(RIPNG_NODE
, &vtysh_quit_ripngd_cmd
);
3145 install_element(OSPF_NODE
, &vtysh_exit_ospfd_cmd
);
3146 install_element(OSPF_NODE
, &vtysh_quit_ospfd_cmd
);
3147 install_element(EIGRP_NODE
, &vtysh_exit_eigrpd_cmd
);
3148 install_element(EIGRP_NODE
, &vtysh_quit_eigrpd_cmd
);
3149 install_element(BABEL_NODE
, &vtysh_exit_babeld_cmd
);
3150 install_element(BABEL_NODE
, &vtysh_quit_babeld_cmd
);
3151 install_element(OSPF6_NODE
, &vtysh_exit_ospf6d_cmd
);
3152 install_element(OSPF6_NODE
, &vtysh_quit_ospf6d_cmd
);
3153 #if defined(HAVE_LDPD)
3154 install_element(LDP_NODE
, &vtysh_exit_ldpd_cmd
);
3155 install_element(LDP_NODE
, &vtysh_quit_ldpd_cmd
);
3156 install_element(LDP_IPV4_NODE
, &vtysh_exit_ldpd_cmd
);
3157 install_element(LDP_IPV4_NODE
, &vtysh_quit_ldpd_cmd
);
3158 install_element(LDP_IPV4_NODE
, &ldp_exit_address_family_cmd
);
3159 install_element(LDP_IPV6_NODE
, &vtysh_exit_ldpd_cmd
);
3160 install_element(LDP_IPV6_NODE
, &vtysh_quit_ldpd_cmd
);
3161 install_element(LDP_IPV6_NODE
, &ldp_exit_address_family_cmd
);
3162 install_element(LDP_IPV4_IFACE_NODE
, &vtysh_exit_ldpd_cmd
);
3163 install_element(LDP_IPV4_IFACE_NODE
, &vtysh_quit_ldpd_cmd
);
3164 install_element(LDP_IPV6_IFACE_NODE
, &vtysh_exit_ldpd_cmd
);
3165 install_element(LDP_IPV6_IFACE_NODE
, &vtysh_quit_ldpd_cmd
);
3166 install_element(LDP_L2VPN_NODE
, &vtysh_exit_ldpd_cmd
);
3167 install_element(LDP_L2VPN_NODE
, &vtysh_quit_ldpd_cmd
);
3168 install_element(LDP_PSEUDOWIRE_NODE
, &vtysh_exit_ldpd_cmd
);
3169 install_element(LDP_PSEUDOWIRE_NODE
, &vtysh_quit_ldpd_cmd
);
3171 install_element(BGP_NODE
, &vtysh_exit_bgpd_cmd
);
3172 install_element(BGP_NODE
, &vtysh_quit_bgpd_cmd
);
3173 install_element(BGP_VPNV4_NODE
, &vtysh_exit_bgpd_cmd
);
3174 install_element(BGP_VPNV4_NODE
, &vtysh_quit_bgpd_cmd
);
3175 install_element(BGP_VPNV6_NODE
, &vtysh_exit_bgpd_cmd
);
3176 install_element(BGP_VPNV6_NODE
, &vtysh_quit_bgpd_cmd
);
3177 install_element(BGP_IPV4_NODE
, &vtysh_exit_bgpd_cmd
);
3178 install_element(BGP_IPV4_NODE
, &vtysh_quit_bgpd_cmd
);
3179 install_element(BGP_IPV4M_NODE
, &vtysh_exit_bgpd_cmd
);
3180 install_element(BGP_IPV4M_NODE
, &vtysh_quit_bgpd_cmd
);
3181 install_element(BGP_IPV4L_NODE
, &vtysh_exit_bgpd_cmd
);
3182 install_element(BGP_IPV4L_NODE
, &vtysh_quit_bgpd_cmd
);
3183 install_element(BGP_IPV6_NODE
, &vtysh_exit_bgpd_cmd
);
3184 install_element(BGP_IPV6_NODE
, &vtysh_quit_bgpd_cmd
);
3185 install_element(BGP_IPV6M_NODE
, &vtysh_exit_bgpd_cmd
);
3186 install_element(BGP_IPV6M_NODE
, &vtysh_quit_bgpd_cmd
);
3187 install_element(BGP_EVPN_NODE
, &vtysh_quit_bgpd_cmd
);
3188 install_element(BGP_EVPN_NODE
, &vtysh_exit_bgpd_cmd
);
3189 install_element(BGP_EVPN_VNI_NODE
, &vtysh_exit_bgpd_cmd
);
3190 install_element(BGP_EVPN_VNI_NODE
, &vtysh_quit_bgpd_cmd
);
3191 install_element(BGP_IPV6L_NODE
, &vtysh_exit_bgpd_cmd
);
3192 install_element(BGP_IPV6L_NODE
, &vtysh_quit_bgpd_cmd
);
3193 #if defined(ENABLE_BGP_VNC)
3194 install_element(BGP_VRF_POLICY_NODE
, &vtysh_exit_bgpd_cmd
);
3195 install_element(BGP_VRF_POLICY_NODE
, &vtysh_quit_bgpd_cmd
);
3196 install_element(BGP_VNC_DEFAULTS_NODE
, &vtysh_exit_bgpd_cmd
);
3197 install_element(BGP_VNC_DEFAULTS_NODE
, &vtysh_quit_bgpd_cmd
);
3198 install_element(BGP_VNC_NVE_GROUP_NODE
, &vtysh_exit_bgpd_cmd
);
3199 install_element(BGP_VNC_NVE_GROUP_NODE
, &vtysh_quit_bgpd_cmd
);
3200 install_element(BGP_VNC_L2_GROUP_NODE
, &vtysh_exit_bgpd_cmd
);
3201 install_element(BGP_VNC_L2_GROUP_NODE
, &vtysh_quit_bgpd_cmd
);
3203 install_element(ISIS_NODE
, &vtysh_exit_isisd_cmd
);
3204 install_element(ISIS_NODE
, &vtysh_quit_isisd_cmd
);
3205 install_element(KEYCHAIN_NODE
, &vtysh_exit_ripd_cmd
);
3206 install_element(KEYCHAIN_NODE
, &vtysh_quit_ripd_cmd
);
3207 install_element(KEYCHAIN_KEY_NODE
, &vtysh_exit_ripd_cmd
);
3208 install_element(KEYCHAIN_KEY_NODE
, &vtysh_quit_ripd_cmd
);
3209 install_element(RMAP_NODE
, &vtysh_exit_rmap_cmd
);
3210 install_element(RMAP_NODE
, &vtysh_quit_rmap_cmd
);
3211 install_element(VTY_NODE
, &vtysh_exit_line_vty_cmd
);
3212 install_element(VTY_NODE
, &vtysh_quit_line_vty_cmd
);
3214 /* "end" command. */
3215 install_element(CONFIG_NODE
, &vtysh_end_all_cmd
);
3216 install_element(ENABLE_NODE
, &vtysh_end_all_cmd
);
3217 install_element(RIP_NODE
, &vtysh_end_all_cmd
);
3218 install_element(RIPNG_NODE
, &vtysh_end_all_cmd
);
3219 install_element(OSPF_NODE
, &vtysh_end_all_cmd
);
3220 install_element(EIGRP_NODE
, &vtysh_end_all_cmd
);
3221 install_element(BABEL_NODE
, &vtysh_end_all_cmd
);
3222 install_element(OSPF6_NODE
, &vtysh_end_all_cmd
);
3223 install_element(LDP_NODE
, &vtysh_end_all_cmd
);
3224 install_element(LDP_IPV4_NODE
, &vtysh_end_all_cmd
);
3225 install_element(LDP_IPV6_NODE
, &vtysh_end_all_cmd
);
3226 install_element(LDP_IPV4_IFACE_NODE
, &vtysh_end_all_cmd
);
3227 install_element(LDP_IPV6_IFACE_NODE
, &vtysh_end_all_cmd
);
3228 install_element(LDP_L2VPN_NODE
, &vtysh_end_all_cmd
);
3229 install_element(LDP_PSEUDOWIRE_NODE
, &vtysh_end_all_cmd
);
3230 install_element(BGP_NODE
, &vtysh_end_all_cmd
);
3231 install_element(BGP_IPV4_NODE
, &vtysh_end_all_cmd
);
3232 install_element(BGP_IPV4M_NODE
, &vtysh_end_all_cmd
);
3233 install_element(BGP_IPV4L_NODE
, &vtysh_end_all_cmd
);
3234 install_element(BGP_VPNV4_NODE
, &vtysh_end_all_cmd
);
3235 install_element(BGP_VPNV6_NODE
, &vtysh_end_all_cmd
);
3236 install_element(BGP_IPV6_NODE
, &vtysh_end_all_cmd
);
3237 install_element(BGP_IPV6M_NODE
, &vtysh_end_all_cmd
);
3238 install_element(BGP_IPV6L_NODE
, &vtysh_end_all_cmd
);
3239 install_element(BGP_VRF_POLICY_NODE
, &vtysh_end_all_cmd
);
3240 install_element(BGP_EVPN_NODE
, &vtysh_end_all_cmd
);
3241 install_element(BGP_EVPN_VNI_NODE
, &vtysh_end_all_cmd
);
3242 install_element(BGP_VNC_DEFAULTS_NODE
, &vtysh_end_all_cmd
);
3243 install_element(BGP_VNC_NVE_GROUP_NODE
, &vtysh_end_all_cmd
);
3244 install_element(BGP_VNC_L2_GROUP_NODE
, &vtysh_end_all_cmd
);
3245 install_element(ISIS_NODE
, &vtysh_end_all_cmd
);
3246 install_element(KEYCHAIN_NODE
, &vtysh_end_all_cmd
);
3247 install_element(KEYCHAIN_KEY_NODE
, &vtysh_end_all_cmd
);
3248 install_element(RMAP_NODE
, &vtysh_end_all_cmd
);
3249 install_element(VTY_NODE
, &vtysh_end_all_cmd
);
3251 install_element(INTERFACE_NODE
, &vtysh_interface_desc_cmd
);
3252 install_element(INTERFACE_NODE
, &vtysh_no_interface_desc_cmd
);
3253 install_element(INTERFACE_NODE
, &vtysh_end_all_cmd
);
3254 install_element(INTERFACE_NODE
, &vtysh_exit_interface_cmd
);
3255 install_element(LINK_PARAMS_NODE
, &exit_link_params_cmd
);
3256 install_element(LINK_PARAMS_NODE
, &vtysh_end_all_cmd
);
3257 install_element(LINK_PARAMS_NODE
, &vtysh_exit_interface_cmd
);
3258 install_element(INTERFACE_NODE
, &vtysh_quit_interface_cmd
);
3260 install_element(PW_NODE
, &vtysh_end_all_cmd
);
3261 install_element(PW_NODE
, &vtysh_exit_interface_cmd
);
3262 install_element(PW_NODE
, &vtysh_quit_interface_cmd
);
3264 install_element(LOGICALROUTER_NODE
, &vtysh_end_all_cmd
);
3266 install_element(CONFIG_NODE
, &vtysh_logicalrouter_cmd
);
3267 install_element(CONFIG_NODE
, &vtysh_no_logicalrouter_cmd
);
3268 install_element(LOGICALROUTER_NODE
, &vtysh_exit_logicalrouter_cmd
);
3269 install_element(LOGICALROUTER_NODE
, &vtysh_quit_logicalrouter_cmd
);
3271 install_element(VRF_NODE
, &vtysh_end_all_cmd
);
3272 install_element(VRF_NODE
, &vtysh_exit_vrf_cmd
);
3273 install_element(VRF_NODE
, &vtysh_quit_vrf_cmd
);
3275 install_element(CONFIG_NODE
, &router_eigrp_cmd
);
3276 install_element(CONFIG_NODE
, &router_babel_cmd
);
3277 install_element(CONFIG_NODE
, &router_rip_cmd
);
3278 install_element(CONFIG_NODE
, &router_ripng_cmd
);
3279 install_element(CONFIG_NODE
, &router_ospf_cmd
);
3280 install_element(CONFIG_NODE
, &router_ospf6_cmd
);
3281 #if defined(HAVE_LDPD)
3282 install_element(CONFIG_NODE
, &ldp_mpls_ldp_cmd
);
3283 install_element(LDP_NODE
, &ldp_address_family_ipv4_cmd
);
3284 install_element(LDP_NODE
, &ldp_address_family_ipv6_cmd
);
3285 install_element(LDP_IPV4_NODE
, &ldp_interface_ifname_cmd
);
3286 install_element(LDP_IPV6_NODE
, &ldp_interface_ifname_cmd
);
3287 install_element(CONFIG_NODE
, &ldp_l2vpn_word_type_vpls_cmd
);
3288 install_element(LDP_L2VPN_NODE
, &ldp_member_pseudowire_ifname_cmd
);
3290 install_element(CONFIG_NODE
, &router_isis_cmd
);
3291 install_element(CONFIG_NODE
, &router_bgp_cmd
);
3292 install_element(BGP_NODE
, &address_family_vpnv4_cmd
);
3293 install_element(BGP_NODE
, &address_family_vpnv6_cmd
);
3294 #if defined(ENABLE_BGP_VNC)
3295 install_element(BGP_NODE
, &vnc_vrf_policy_cmd
);
3296 install_element(BGP_NODE
, &vnc_defaults_cmd
);
3297 install_element(BGP_NODE
, &vnc_nve_group_cmd
);
3298 install_element(BGP_NODE
, &vnc_l2_group_cmd
);
3300 install_element(BGP_NODE
, &address_family_ipv4_cmd
);
3301 install_element(BGP_NODE
, &address_family_ipv4_multicast_cmd
);
3302 install_element(BGP_NODE
, &address_family_ipv4_vpn_cmd
);
3303 install_element(BGP_NODE
, &address_family_ipv4_labeled_unicast_cmd
);
3304 install_element(BGP_NODE
, &address_family_ipv6_cmd
);
3305 install_element(BGP_NODE
, &address_family_ipv6_multicast_cmd
);
3306 install_element(BGP_NODE
, &address_family_ipv6_vpn_cmd
);
3307 install_element(BGP_NODE
, &address_family_ipv6_labeled_unicast_cmd
);
3308 install_element(BGP_NODE
, &address_family_evpn_cmd
);
3309 #if defined(HAVE_CUMULUS)
3310 install_element(BGP_NODE
, &address_family_evpn2_cmd
);
3312 install_element(BGP_VPNV4_NODE
, &exit_address_family_cmd
);
3313 install_element(BGP_VPNV6_NODE
, &exit_address_family_cmd
);
3314 install_element(BGP_IPV4_NODE
, &exit_address_family_cmd
);
3315 install_element(BGP_IPV4M_NODE
, &exit_address_family_cmd
);
3316 install_element(BGP_IPV4L_NODE
, &exit_address_family_cmd
);
3317 install_element(BGP_IPV6_NODE
, &exit_address_family_cmd
);
3318 install_element(BGP_IPV6M_NODE
, &exit_address_family_cmd
);
3319 install_element(BGP_EVPN_NODE
, &exit_address_family_cmd
);
3320 install_element(BGP_IPV6L_NODE
, &exit_address_family_cmd
);
3322 #if defined(HAVE_RPKI)
3323 install_element(CONFIG_NODE
, &rpki_cmd
);
3324 install_element(RPKI_NODE
, &rpki_exit_cmd
);
3325 install_element(RPKI_NODE
, &rpki_quit_cmd
);
3326 install_element(RPKI_NODE
, &vtysh_end_all_cmd
);
3330 install_element(BGP_EVPN_NODE
, &bgp_evpn_vni_cmd
);
3331 install_element(BGP_EVPN_VNI_NODE
, &exit_vni_cmd
);
3333 install_element(BGP_VRF_POLICY_NODE
, &exit_vrf_policy_cmd
);
3334 install_element(BGP_VNC_DEFAULTS_NODE
, &exit_vnc_config_cmd
);
3335 install_element(BGP_VNC_NVE_GROUP_NODE
, &exit_vnc_config_cmd
);
3336 install_element(BGP_VNC_L2_GROUP_NODE
, &exit_vnc_config_cmd
);
3338 install_element(CONFIG_NODE
, &key_chain_cmd
);
3339 install_element(CONFIG_NODE
, &vtysh_route_map_cmd
);
3340 install_element(CONFIG_NODE
, &vtysh_line_vty_cmd
);
3341 install_element(KEYCHAIN_NODE
, &key_cmd
);
3342 install_element(KEYCHAIN_NODE
, &key_chain_cmd
);
3343 install_element(KEYCHAIN_KEY_NODE
, &key_chain_cmd
);
3344 install_element(CONFIG_NODE
, &vtysh_interface_cmd
);
3345 install_element(CONFIG_NODE
, &vtysh_no_interface_cmd
);
3346 install_element(CONFIG_NODE
, &vtysh_no_interface_vrf_cmd
);
3347 install_element(CONFIG_NODE
, &vtysh_pseudowire_cmd
);
3348 install_element(INTERFACE_NODE
, &vtysh_link_params_cmd
);
3349 install_element(ENABLE_NODE
, &vtysh_show_running_config_cmd
);
3350 install_element(ENABLE_NODE
, &vtysh_copy_running_config_cmd
);
3352 install_element(CONFIG_NODE
, &vtysh_vrf_cmd
);
3353 install_element(CONFIG_NODE
, &vtysh_no_vrf_cmd
);
3355 /* "write terminal" command. */
3356 install_element(ENABLE_NODE
, &vtysh_write_terminal_cmd
);
3358 install_element(CONFIG_NODE
, &vtysh_integrated_config_cmd
);
3359 install_element(CONFIG_NODE
, &no_vtysh_integrated_config_cmd
);
3361 /* "write memory" command. */
3362 install_element(ENABLE_NODE
, &vtysh_write_memory_cmd
);
3364 install_element(VIEW_NODE
, &vtysh_terminal_length_cmd
);
3365 install_element(VIEW_NODE
, &vtysh_terminal_no_length_cmd
);
3366 install_element(VIEW_NODE
, &vtysh_show_daemons_cmd
);
3368 install_element(VIEW_NODE
, &vtysh_ping_cmd
);
3369 install_element(VIEW_NODE
, &vtysh_ping_ip_cmd
);
3370 install_element(VIEW_NODE
, &vtysh_traceroute_cmd
);
3371 install_element(VIEW_NODE
, &vtysh_traceroute_ip_cmd
);
3372 install_element(VIEW_NODE
, &vtysh_mtrace_cmd
);
3373 install_element(VIEW_NODE
, &vtysh_ping6_cmd
);
3374 install_element(VIEW_NODE
, &vtysh_traceroute6_cmd
);
3375 #if defined(HAVE_SHELL_ACCESS)
3376 install_element(VIEW_NODE
, &vtysh_telnet_cmd
);
3377 install_element(VIEW_NODE
, &vtysh_telnet_port_cmd
);
3378 install_element(VIEW_NODE
, &vtysh_ssh_cmd
);
3380 #if defined(HAVE_SHELL_ACCESS)
3381 install_element(ENABLE_NODE
, &vtysh_start_shell_cmd
);
3382 install_element(ENABLE_NODE
, &vtysh_start_bash_cmd
);
3383 install_element(ENABLE_NODE
, &vtysh_start_zsh_cmd
);
3387 install_element(VIEW_NODE
, &vtysh_show_debugging_cmd
);
3388 install_element(VIEW_NODE
, &vtysh_show_debugging_hashtable_cmd
);
3389 install_element(VIEW_NODE
, &vtysh_debug_all_cmd
);
3390 install_element(CONFIG_NODE
, &vtysh_debug_all_cmd
);
3392 /* misc lib show commands */
3393 install_element(VIEW_NODE
, &vtysh_show_memory_cmd
);
3394 install_element(VIEW_NODE
, &vtysh_show_modules_cmd
);
3395 install_element(VIEW_NODE
, &vtysh_show_work_queues_cmd
);
3396 install_element(VIEW_NODE
, &vtysh_show_work_queues_daemon_cmd
);
3397 install_element(VIEW_NODE
, &vtysh_show_thread_cmd
);
3400 install_element(VIEW_NODE
, &vtysh_show_logging_cmd
);
3401 install_element(CONFIG_NODE
, &vtysh_log_stdout_cmd
);
3402 install_element(CONFIG_NODE
, &vtysh_log_stdout_level_cmd
);
3403 install_element(CONFIG_NODE
, &no_vtysh_log_stdout_cmd
);
3404 install_element(CONFIG_NODE
, &vtysh_log_file_cmd
);
3405 install_element(CONFIG_NODE
, &vtysh_log_file_level_cmd
);
3406 install_element(CONFIG_NODE
, &no_vtysh_log_file_cmd
);
3407 install_element(CONFIG_NODE
, &vtysh_log_monitor_cmd
);
3408 install_element(CONFIG_NODE
, &no_vtysh_log_monitor_cmd
);
3409 install_element(CONFIG_NODE
, &vtysh_log_syslog_cmd
);
3410 install_element(CONFIG_NODE
, &no_vtysh_log_syslog_cmd
);
3411 install_element(CONFIG_NODE
, &vtysh_log_trap_cmd
);
3412 install_element(CONFIG_NODE
, &no_vtysh_log_trap_cmd
);
3413 install_element(CONFIG_NODE
, &vtysh_log_facility_cmd
);
3414 install_element(CONFIG_NODE
, &no_vtysh_log_facility_cmd
);
3415 install_element(CONFIG_NODE
, &vtysh_log_record_priority_cmd
);
3416 install_element(CONFIG_NODE
, &no_vtysh_log_record_priority_cmd
);
3417 install_element(CONFIG_NODE
, &vtysh_log_timestamp_precision_cmd
);
3418 install_element(CONFIG_NODE
, &no_vtysh_log_timestamp_precision_cmd
);
3420 install_element(CONFIG_NODE
, &vtysh_service_password_encrypt_cmd
);
3421 install_element(CONFIG_NODE
, &no_vtysh_service_password_encrypt_cmd
);
3423 install_element(CONFIG_NODE
, &vtysh_password_cmd
);
3424 install_element(CONFIG_NODE
, &vtysh_enable_password_cmd
);
3425 install_element(CONFIG_NODE
, &no_vtysh_enable_password_cmd
);