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
17 * along with GNU Zebra; see the file COPYING. If not, write to the Free
18 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
27 #include <sys/resource.h>
30 #include <readline/readline.h>
31 #include <readline/history.h>
41 #include "vtysh/vtysh.h"
43 #include "bgpd/bgp_vty.h"
48 DEFINE_MTYPE_STATIC(MVTYSH
, VTYSH_CMD
, "Vtysh cmd copy")
53 /* VTY shell pager name. */
54 char *vtysh_pager_name
= NULL
;
56 /* VTY shell client structure. */
62 char path
[MAXPATHLEN
];
63 struct vtysh_client
*next
;
66 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
= "watchfrr", .flag
= VTYSH_WATCHFRR
, .next
= NULL
},
82 enum vtysh_write_integrated vtysh_write_integrated
= WRITE_INTEGRATED_UNSPECIFIED
;
85 vclient_close (struct vtysh_client
*vclient
)
90 "Warning: closing connection to %s because of an I/O error!\n",
97 /* Return true if str begins with prefix, else return false */
99 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 /* NB: multiplexed function:
111 * if fp == NULL, this calls vtysh_config_parse_line
112 * if fp != NULL, this prints lines to fp
115 vtysh_client_run (struct vtysh_client
*vclient
, const char *line
, FILE *fp
)
119 char *buf
= stackbuf
;
120 size_t bufsz
= sizeof(stackbuf
);
121 char *bufvalid
, *end
= NULL
;
122 char terminator
[3] = {0, 0, 0};
127 ret
= write (vclient
->fd
, line
, strlen (line
) + 1);
134 ssize_t nread
= read (vclient
->fd
, bufvalid
, buf
+ bufsz
- bufvalid
);
136 if (nread
< 0 && (errno
== EINTR
|| errno
== EAGAIN
))
141 fprintf (stderr
, "vtysh: error reading from %s: %s (%d)",
142 vclient
->name
, safe_strerror(errno
), errno
);
148 end
= memmem (buf
, bufvalid
- buf
, terminator
, sizeof(terminator
));
149 if (end
+ sizeof(terminator
) + 1 > bufvalid
)
150 /* found \0\0\0 but return code hasn't been read yet */
153 ret
= end
[sizeof(terminator
)];
155 while (bufvalid
> buf
&& (end
> buf
|| !end
))
157 size_t textlen
= (end
? end
: bufvalid
) - buf
;
158 char *eol
= memchr (buf
, '\n', textlen
);
163 /* no line break, end of input, no text left before end
164 * => don't insert an empty line at the end */
167 /* no line break, end of input, but some text left */
170 /* continue reading */
173 /* eol is at a line end now, either \n => \0 or \0\0\0 */
174 assert(eol
&& eol
<= bufvalid
);
182 vtysh_config_parse_line (buf
);
188 memmove (buf
, eol
, bufvalid
- eol
);
189 bufvalid
-= eol
- buf
;
194 if (bufvalid
== buf
+ bufsz
)
200 new = XMALLOC (MTYPE_TMP
, bufsz
);
201 memcpy (new, stackbuf
, sizeof(stackbuf
));
204 new = XREALLOC (MTYPE_TMP
, buf
, bufsz
);
206 bufvalid
= bufvalid
- buf
+ new;
208 /* if end != NULL, we won't be reading more data... */
209 assert (end
== NULL
);
216 vclient_close (vclient
);
220 XFREE (MTYPE_TMP
, buf
);
225 vtysh_client_run_all (struct vtysh_client
*head_client
, const char *line
,
226 int continue_on_err
, FILE *fp
)
228 struct vtysh_client
*client
;
229 int rc
, rc_all
= CMD_SUCCESS
;
231 for (client
= head_client
; client
; client
= client
->next
)
233 rc
= vtysh_client_run(client
, line
, fp
);
234 if (rc
!= CMD_SUCCESS
)
236 if (!continue_on_err
)
245 vtysh_client_execute (struct vtysh_client
*head_client
, const char *line
,
248 return vtysh_client_run_all (head_client
, line
, 0, fp
);
252 vtysh_client_config (struct vtysh_client
*head_client
, char *line
)
254 vtysh_client_run_all (head_client
, line
, 1, NULL
);
258 vtysh_pager_init (void)
262 pager_defined
= getenv ("VTYSH_PAGER");
265 vtysh_pager_name
= strdup (pager_defined
);
267 vtysh_pager_name
= strdup ("more");
270 /* Command execution over the vty interface. */
272 vtysh_execute_func (const char *line
, int pager
)
277 const struct cmd_element
*cmd
;
281 int saved_ret
, saved_node
;
283 /* Split readline string up into the vector. */
284 vline
= cmd_make_strvec (line
);
289 saved_ret
= ret
= cmd_execute_command (vline
, vty
, &cmd
, 1);
290 saved_node
= vty
->node
;
292 /* If command doesn't succeeded in current node, try to walk up in node tree.
293 * Changing vty->node is enough to try it just out without actual walkup in
295 while (ret
!= CMD_SUCCESS
&& ret
!= CMD_SUCCESS_DAEMON
&& ret
!= CMD_WARNING
296 && vty
->node
> CONFIG_NODE
)
298 vty
->node
= node_parent(vty
->node
);
299 ret
= cmd_execute_command (vline
, vty
, &cmd
, 1);
303 vty
->node
= saved_node
;
305 /* If command succeeded in any other node than current (tried > 0) we have
306 * to move into node in the vtysh where it succeeded. */
307 if (ret
== CMD_SUCCESS
|| ret
== CMD_SUCCESS_DAEMON
|| ret
== CMD_WARNING
)
309 if ((saved_node
== BGP_VPNV4_NODE
|| saved_node
== BGP_VPNV6_NODE
310 || saved_node
== BGP_ENCAP_NODE
|| saved_node
== BGP_ENCAPV6_NODE
311 || saved_node
== BGP_IPV4_NODE
312 || saved_node
== BGP_IPV6_NODE
|| saved_node
== BGP_IPV4M_NODE
313 || saved_node
== BGP_IPV6M_NODE
|| saved_node
== BGP_EVPN_NODE
)
316 vtysh_execute("exit-address-family");
318 else if (saved_node
== BGP_VRF_POLICY_NODE
&& (tried
== 1))
320 vtysh_execute("exit-vrf-policy");
322 else if ((saved_node
== BGP_VNC_DEFAULTS_NODE
323 || saved_node
== BGP_VNC_NVE_GROUP_NODE
324 || saved_node
== BGP_VNC_L2_GROUP_NODE
) && (tried
== 1))
326 vtysh_execute("exit-vnc");
328 else if ((saved_node
== KEYCHAIN_KEY_NODE
) && (tried
== 1))
330 vtysh_execute("exit");
334 vtysh_execute ("end");
335 vtysh_execute ("configure terminal");
338 /* If command didn't succeed in any node, continue with return value from
345 cmd_free_strvec (vline
);
351 if (vty
->type
== VTY_FILE
)
352 fprintf (stdout
,"Warning...\n");
354 case CMD_ERR_AMBIGUOUS
:
355 fprintf (stdout
,"%% Ambiguous command.\n");
357 case CMD_ERR_NO_MATCH
:
358 fprintf (stdout
,"%% Unknown command.\n");
360 case CMD_ERR_INCOMPLETE
:
361 fprintf (stdout
,"%% Command incomplete.\n");
363 case CMD_SUCCESS_DAEMON
:
365 /* FIXME: Don't open pager for exit commands. popen() causes problems
366 * if exited from vtysh at all. This hack shouldn't cause any problem
367 * but is really ugly. */
368 if (pager
&& vtysh_pager_name
&& (strncmp(line
, "exit", 4) != 0))
370 fp
= popen (vtysh_pager_name
, "w");
373 perror ("popen failed for pager");
382 if (! strcmp(cmd
->string
,"configure terminal"))
384 for (i
= 0; i
< array_size(vtysh_client
); i
++)
386 cmd_stat
= vtysh_client_execute(&vtysh_client
[i
], line
, fp
);
387 if (cmd_stat
== CMD_WARNING
)
394 vline
= cmd_make_strvec (line
);
398 if (pager
&& vtysh_pager_name
&& fp
&& closepager
)
400 if (pclose (fp
) == -1)
402 perror ("pclose failed for pager");
409 ret
= cmd_execute_command (vline
, vty
, &cmd
, 1);
410 cmd_free_strvec (vline
);
411 if (ret
!= CMD_SUCCESS_DAEMON
)
417 (*cmd
->func
) (cmd
, vty
, 0, NULL
);
422 cmd_stat
= CMD_SUCCESS
;
423 for (i
= 0; i
< array_size(vtysh_client
); i
++)
425 if (cmd
->daemon
& vtysh_client
[i
].flag
)
427 cmd_stat
= vtysh_client_execute(&vtysh_client
[i
], line
, fp
);
428 if (cmd_stat
!= CMD_SUCCESS
)
432 if (cmd_stat
!= CMD_SUCCESS
)
436 (*cmd
->func
) (cmd
, vty
, 0, NULL
);
439 if (pager
&& vtysh_pager_name
&& fp
&& closepager
)
441 if (pclose (fp
) == -1)
443 perror ("pclose failed for pager");
451 vtysh_execute_no_pager (const char *line
)
453 return vtysh_execute_func (line
, 0);
457 vtysh_execute (const char *line
)
459 return vtysh_execute_func (line
, 1);
474 while (end
>= s
&& isspace(*end
))
478 while (*s
&& isspace(*s
))
485 vtysh_mark_file (const char *filename
)
492 const struct cmd_element
*cmd
;
493 int saved_ret
, prev_node
;
495 char *vty_buf_copy
= NULL
;
496 char *vty_buf_trimmed
= NULL
;
498 if (strncmp("-", filename
, 1) == 0)
501 confp
= fopen (filename
, "r");
505 fprintf (stderr
, "%% Can't open config file %s due to '%s'.\n",
506 filename
, safe_strerror (errno
));
507 return (CMD_ERR_NO_FILE
);
511 vty
->fd
= 0; /* stdout */
512 vty
->type
= VTY_TERM
;
513 vty
->node
= CONFIG_NODE
;
515 vtysh_execute_no_pager ("enable");
516 vtysh_execute_no_pager ("configure terminal");
517 vty_buf_copy
= XCALLOC (MTYPE_VTYSH_CMD
, VTY_BUFSIZ
);
519 while (fgets (vty
->buf
, VTY_BUFSIZ
, confp
))
523 strcpy(vty_buf_copy
, vty
->buf
);
524 vty_buf_trimmed
= trim(vty_buf_copy
);
526 if (vty_buf_trimmed
[0] == '!' || vty_buf_trimmed
[0] == '#')
528 fprintf(stdout
, "%s", vty
->buf
);
532 /* Split readline string up into the vector. */
533 vline
= cmd_make_strvec (vty
->buf
);
537 fprintf(stdout
, "%s", vty
->buf
);
541 /* Ignore the "end" lines, we will generate these where appropriate */
542 if (strlen(vty_buf_trimmed
) == 3 && strncmp("end", vty_buf_trimmed
, 3) == 0)
547 prev_node
= vty
->node
;
548 saved_ret
= ret
= cmd_execute_command_strict (vline
, vty
, &cmd
);
550 /* If command doesn't succeeded in current node, try to walk up in node tree.
551 * Changing vty->node is enough to try it just out without actual walkup in
553 while (ret
!= CMD_SUCCESS
&& ret
!= CMD_SUCCESS_DAEMON
&& ret
!= CMD_WARNING
554 && vty
->node
> CONFIG_NODE
)
556 vty
->node
= node_parent(vty
->node
);
557 ret
= cmd_execute_command_strict (vline
, vty
, &cmd
);
561 /* If command succeeded in any other node than current (tried > 0) we have
562 * to move into node in the vtysh where it succeeded. */
563 if (ret
== CMD_SUCCESS
|| ret
== CMD_SUCCESS_DAEMON
|| ret
== CMD_WARNING
)
565 if ((prev_node
== BGP_VPNV4_NODE
|| prev_node
== BGP_IPV4_NODE
566 || prev_node
== BGP_IPV6_NODE
|| prev_node
== BGP_IPV4M_NODE
567 || prev_node
== BGP_IPV6M_NODE
|| prev_node
== BGP_VPNV6_NODE
568 || prev_node
== BGP_EVPN_NODE
)
571 fprintf(stdout
, "exit-address-family\n");
573 else if ((prev_node
== KEYCHAIN_KEY_NODE
) && (tried
== 1))
575 fprintf(stdout
, "exit\n");
579 fprintf(stdout
, "end\n");
582 /* If command didn't succeed in any node, continue with return value from
587 vty
->node
= prev_node
;
590 cmd_free_strvec (vline
);
594 if (vty
->type
== VTY_FILE
)
595 fprintf (stderr
,"line %d: Warning...: %s\n", lineno
, vty
->buf
);
598 XFREE(MTYPE_VTYSH_CMD
, vty_buf_copy
);
600 case CMD_ERR_AMBIGUOUS
:
601 fprintf (stderr
,"line %d: %% Ambiguous command: %s\n", lineno
, vty
->buf
);
604 XFREE(MTYPE_VTYSH_CMD
, vty_buf_copy
);
605 return CMD_ERR_AMBIGUOUS
;
606 case CMD_ERR_NO_MATCH
:
607 fprintf (stderr
,"line %d: %% Unknown command: %s\n", lineno
, vty
->buf
);
610 XFREE(MTYPE_VTYSH_CMD
, vty_buf_copy
);
611 return CMD_ERR_NO_MATCH
;
612 case CMD_ERR_INCOMPLETE
:
613 fprintf (stderr
,"line %d: %% Command incomplete: %s\n", lineno
, vty
->buf
);
616 XFREE(MTYPE_VTYSH_CMD
, vty_buf_copy
);
617 return CMD_ERR_INCOMPLETE
;
619 fprintf(stdout
, "%s", vty
->buf
);
621 case CMD_SUCCESS_DAEMON
:
624 int cmd_stat
= CMD_SUCCESS
;
626 fprintf(stdout
, "%s", vty
->buf
);
627 for (i
= 0; i
< array_size(vtysh_client
); i
++)
629 if (cmd
->daemon
& vtysh_client
[i
].flag
)
631 cmd_stat
= vtysh_client_execute (&vtysh_client
[i
],
633 if (cmd_stat
!= CMD_SUCCESS
)
637 if (cmd_stat
!= CMD_SUCCESS
)
641 (*cmd
->func
) (cmd
, vty
, 0, NULL
);
645 /* This is the end */
646 fprintf(stdout
, "end\n");
648 XFREE(MTYPE_VTYSH_CMD
, vty_buf_copy
);
656 /* Configration make from file. */
658 vtysh_config_from_file (struct vty
*vty
, FILE *fp
)
661 const struct cmd_element
*cmd
;
663 int retcode
= CMD_SUCCESS
;
665 while (fgets (vty
->buf
, VTY_BUFSIZ
, fp
))
669 ret
= command_config_read_one_line (vty
, &cmd
, 1);
674 if (vty
->type
== VTY_FILE
)
675 fprintf (stderr
,"line %d: Warning[%d]...: %s\n", lineno
, vty
->node
, vty
->buf
);
676 retcode
= CMD_WARNING
; /* once we have an error, we remember & return that */
678 case CMD_ERR_AMBIGUOUS
:
679 fprintf (stderr
,"line %d: %% Ambiguous command[%d]: %s\n", lineno
, vty
->node
, vty
->buf
);
680 retcode
= CMD_ERR_AMBIGUOUS
; /* once we have an error, we remember & return that */
682 case CMD_ERR_NO_MATCH
:
683 fprintf (stderr
,"line %d: %% Unknown command[%d]: %s", lineno
, vty
->node
, vty
->buf
);
684 retcode
= CMD_ERR_NO_MATCH
; /* once we have an error, we remember & return that */
686 case CMD_ERR_INCOMPLETE
:
687 fprintf (stderr
,"line %d: %% Command incomplete[%d]: %s\n", lineno
, vty
->node
, vty
->buf
);
688 retcode
= CMD_ERR_INCOMPLETE
; /* once we have an error, we remember & return that */
690 case CMD_SUCCESS_DAEMON
:
693 int cmd_stat
= CMD_SUCCESS
;
695 for (i
= 0; i
< array_size(vtysh_client
); i
++)
697 if (cmd
->daemon
& vtysh_client
[i
].flag
)
699 cmd_stat
= vtysh_client_execute (&vtysh_client
[i
],
702 * CMD_WARNING - Can mean that the command was
703 * parsed successfully but it was already entered
704 * in a few spots. As such if we receive a
705 * CMD_WARNING from a daemon we shouldn't stop
706 * talking to the other daemons for the particular
709 if (cmd_stat
!= CMD_SUCCESS
&& cmd_stat
!= CMD_WARNING
)
711 fprintf (stderr
, "line %d: Failure to communicate[%d] to %s, line: %s\n",
712 lineno
, cmd_stat
, vtysh_client
[i
].name
, vty
->buf
);
717 if (cmd_stat
!= CMD_SUCCESS
)
721 (*cmd
->func
) (cmd
, vty
, 0, NULL
);
729 /* We don't care about the point of the cursor when '?' is typed. */
731 vtysh_rl_describe (void)
738 struct cmd_token
*token
;
740 vline
= cmd_make_strvec (rl_line_buffer
);
742 /* In case of '> ?'. */
745 vline
= vector_init (1);
746 vector_set (vline
, NULL
);
749 if (rl_end
&& isspace ((int) rl_line_buffer
[rl_end
- 1]))
750 vector_set (vline
, NULL
);
752 describe
= cmd_describe_command (vline
, vty
, &ret
);
754 fprintf (stdout
,"\n");
756 /* Ambiguous and no match error. */
759 case CMD_ERR_AMBIGUOUS
:
760 cmd_free_strvec (vline
);
761 fprintf (stdout
,"%% Ambiguous command.\n");
765 case CMD_ERR_NO_MATCH
:
766 cmd_free_strvec (vline
);
767 fprintf (stdout
,"%% There is no matched command.\n");
773 /* Get width of command string. */
775 for (i
= 0; i
< vector_active (describe
); i
++)
776 if ((token
= vector_slot (describe
, i
)) != NULL
)
778 if (token
->text
[0] == '\0')
781 int len
= strlen (token
->text
);
787 for (i
= 0; i
< vector_active (describe
); i
++)
788 if ((token
= vector_slot (describe
, i
)) != NULL
)
791 fprintf (stdout
," %-s\n",
794 fprintf (stdout
," %-*s %s\n",
800 cmd_free_strvec (vline
);
801 vector_free (describe
);
808 /* Result of cmd_complete_command() call will be stored here
809 * and used in new_completion() in order to put the space in
810 * correct places only. */
814 command_generator (const char *text
, int state
)
817 static char **matched
= NULL
;
818 static int index
= 0;
825 if (vty
->node
== AUTH_NODE
|| vty
->node
== AUTH_ENABLE_NODE
)
828 vline
= cmd_make_strvec (rl_line_buffer
);
832 if (rl_end
&& isspace ((int) rl_line_buffer
[rl_end
- 1]))
833 vector_set (vline
, NULL
);
835 matched
= cmd_complete_command (vline
, vty
, &complete_status
);
836 cmd_free_strvec (vline
);
839 if (matched
&& matched
[index
])
840 return matched
[index
++];
842 XFREE (MTYPE_TMP
, matched
);
849 new_completion (char *text
, int start
, int end
)
853 matches
= rl_completion_matches (text
, command_generator
);
858 if (complete_status
!= CMD_COMPLETE_FULL_MATCH
)
859 /* only append a space on full match */
860 rl_completion_append_character
= '\0';
866 /* Vty node structures. */
867 static struct cmd_node bgp_node
=
870 "%s(config-router)# ",
873 static struct cmd_node rip_node
=
876 "%s(config-router)# ",
879 static struct cmd_node isis_node
=
882 "%s(config-router)# ",
885 static struct cmd_node interface_node
=
891 static struct cmd_node ns_node
=
894 "%s(config-logical-router)# ",
897 static struct cmd_node vrf_node
=
903 static struct cmd_node rmap_node
=
906 "%s(config-route-map)# "
909 static struct cmd_node zebra_node
=
912 "%s(config-router)# "
915 static struct cmd_node bgp_vpnv4_node
=
918 "%s(config-router-af)# "
921 static struct cmd_node bgp_vpnv6_node
=
924 "%s(config-router-af)# "
927 static struct cmd_node bgp_encap_node
=
930 "%s(config-router-af)# "
933 static struct cmd_node bgp_encapv6_node
=
936 "%s(config-router-af)# "
939 static struct cmd_node bgp_ipv4_node
=
942 "%s(config-router-af)# "
945 static struct cmd_node bgp_ipv4m_node
=
948 "%s(config-router-af)# "
951 static struct cmd_node bgp_ipv6_node
=
954 "%s(config-router-af)# "
957 static struct cmd_node bgp_ipv6m_node
=
960 "%s(config-router-af)# "
963 static struct cmd_node bgp_evpn_node
=
966 "%s(config-router-af)# "
969 static struct cmd_node bgp_vnc_defaults_node
=
971 BGP_VNC_DEFAULTS_NODE
,
972 "%s(config-router-vnc-defaults)# "
975 static struct cmd_node bgp_vnc_nve_group_node
=
977 BGP_VNC_NVE_GROUP_NODE
,
978 "%s(config-router-vnc-nve-group)# "
981 static struct cmd_node bgp_vrf_policy_node
= {
983 "%s(config-router-vrf-policy)# "
986 static struct cmd_node bgp_vnc_l2_group_node
=
988 BGP_VNC_L2_GROUP_NODE
,
989 "%s(config-router-vnc-l2-group)# "
992 static struct cmd_node ospf_node
=
995 "%s(config-router)# "
998 static struct cmd_node eigrp_node
=
1001 "%s(config-router)# "
1004 static struct cmd_node ripng_node
=
1007 "%s(config-router)# "
1010 static struct cmd_node ospf6_node
=
1013 "%s(config-ospf6)# "
1016 static struct cmd_node ldp_node
=
1022 static struct cmd_node ldp_ipv4_node
=
1025 "%s(config-ldp-af)# "
1028 static struct cmd_node ldp_ipv6_node
=
1031 "%s(config-ldp-af)# "
1034 static struct cmd_node ldp_ipv4_iface_node
=
1036 LDP_IPV4_IFACE_NODE
,
1037 "%s(config-ldp-af-if)# "
1040 static struct cmd_node ldp_ipv6_iface_node
=
1042 LDP_IPV6_IFACE_NODE
,
1043 "%s(config-ldp-af-if)# "
1046 static struct cmd_node ldp_l2vpn_node
=
1049 "%s(config-l2vpn)# "
1052 static struct cmd_node ldp_pseudowire_node
=
1054 LDP_PSEUDOWIRE_NODE
,
1055 "%s(config-l2vpn-pw)# "
1058 static struct cmd_node keychain_node
=
1061 "%s(config-keychain)# "
1064 static struct cmd_node keychain_key_node
=
1067 "%s(config-keychain-key)# "
1070 struct cmd_node link_params_node
=
1073 "%s(config-link-params)# ",
1076 /* Defined in lib/vty.c */
1077 extern struct cmd_node vty_node
;
1079 /* When '^Z' is received from vty, move down to the enable mode. */
1087 /* Nothing to do. */
1090 vty
->node
= ENABLE_NODE
;
1096 DEFUNSH (VTYSH_REALLYALL
,
1100 "End current mode and change to enable mode\n")
1102 return vtysh_end ();
1105 DEFUNSH (VTYSH_BGPD
,
1108 "router bgp [(1-4294967295) [<view|vrf> WORD]]",
1112 "BGP view\nBGP VRF\n"
1115 vty
->node
= BGP_NODE
;
1119 DEFUNSH (VTYSH_BGPD
,
1120 address_family_vpnv4
,
1121 address_family_vpnv4_cmd
,
1122 "address-family vpnv4 [unicast]",
1123 "Enter Address Family command mode\n"
1125 "Address Family Modifier\n")
1127 vty
->node
= BGP_VPNV4_NODE
;
1131 DEFUNSH (VTYSH_BGPD
,
1132 address_family_vpnv6
,
1133 address_family_vpnv6_cmd
,
1134 "address-family vpnv6 [unicast]",
1135 "Enter Address Family command mode\n"
1137 "Address Family Modifier\n")
1139 vty
->node
= BGP_VPNV6_NODE
;
1143 DEFUNSH (VTYSH_BGPD
,
1144 address_family_encapv4
,
1145 address_family_encapv4_cmd
,
1146 "address-family <encap|encapv4>",
1147 "Enter Address Family command mode\n"
1151 vty
->node
= BGP_ENCAP_NODE
;
1155 DEFUNSH (VTYSH_BGPD
,
1156 address_family_encapv6
,
1157 address_family_encapv6_cmd
,
1158 "address-family encapv6",
1159 "Enter Address Family command mode\n"
1162 vty
->node
= BGP_ENCAPV6_NODE
;
1166 DEFUNSH (VTYSH_BGPD
,
1167 address_family_ipv4_unicast
,
1168 address_family_ipv4_unicast_cmd
,
1169 "address-family ipv4 [<unicast|multicast|vpn|encap>]",
1170 "Enter Address Family command mode\n"
1172 "Address Family Modifier\n"
1173 "Address Family Modifier\n"
1174 "Address Family Modifier\n"
1175 "Address Family Modifier\n")
1179 if (argv_find (argv
, argc
, "multicast", &idx
))
1180 vty
->node
= BGP_IPV4M_NODE
;
1182 else if (argv_find (argv
, argc
, "encap", &idx
))
1183 vty
->node
= BGP_ENCAP_NODE
;
1185 else if (argv_find (argv
, argc
, "vpn", &idx
))
1186 vty
->node
= BGP_VPNV4_NODE
;
1189 vty
->node
= BGP_IPV4_NODE
;
1194 DEFUNSH (VTYSH_BGPD
,
1195 address_family_ipv6
,
1196 address_family_ipv6_cmd
,
1197 "address-family ipv6 [<unicast|multicast|vpn|encap>]",
1198 "Enter Address Family command mode\n"
1200 "Address Family Modifier\n"
1201 "Address Family Modifier\n"
1202 "Address Family Modifier\n"
1203 "Address Family Modifier\n")
1207 if (argv_find (argv
, argc
, "multicast", &idx
))
1208 vty
->node
= BGP_IPV6M_NODE
;
1210 else if (argv_find (argv
, argc
, "encap", &idx
))
1211 vty
->node
= BGP_ENCAPV6_NODE
;
1213 else if (argv_find (argv
, argc
, "vpn", &idx
))
1214 vty
->node
= BGP_VPNV6_NODE
;
1217 vty
->node
= BGP_IPV6_NODE
;
1222 DEFUNSH (VTYSH_BGPD
,
1223 address_family_evpn
,
1224 address_family_evpn_cmd
,
1225 "address-family <l2vpn evpn>",
1226 "Enter Address Family command mode\n"
1227 "EVPN Address family\n"
1228 "Layer2 VPN Address family\n"
1229 "Ethernet Virtual Private Network Subsequent Address Family\n")
1231 vty
->node
= BGP_EVPN_NODE
;
1235 #if defined (ENABLE_BGP_VNC)
1236 DEFUNSH (VTYSH_BGPD
,
1240 "VNC/RFP related configuration\n"
1241 "Configure default NVE group\n")
1243 vty
->node
= BGP_VNC_DEFAULTS_NODE
;
1247 DEFUNSH (VTYSH_BGPD
,
1250 "vnc nve-group NAME",
1251 "VNC/RFP related configuration\n"
1252 "Configure a NVE group\n"
1255 vty
->node
= BGP_VNC_NVE_GROUP_NODE
;
1259 DEFUNSH (VTYSH_BGPD
,
1263 "Configure a VRF policy group\n"
1266 vty
->node
= BGP_VRF_POLICY_NODE
;
1270 DEFUNSH (VTYSH_BGPD
,
1273 "vnc l2-group NAME",
1274 "VNC/RFP related configuration\n"
1275 "Configure a L2 group\n"
1278 vty
->node
= BGP_VNC_L2_GROUP_NODE
;
1283 DEFUNSH (VTYSH_RIPD
,
1287 "Authentication key management\n"
1288 "Key-chain management\n"
1291 vty
->node
= KEYCHAIN_NODE
;
1295 DEFUNSH (VTYSH_RIPD
,
1298 "key (0-2147483647)",
1300 "Key identifier number\n")
1302 vty
->node
= KEYCHAIN_KEY_NODE
;
1306 DEFUNSH (VTYSH_RIPD
,
1313 vty
->node
= RIP_NODE
;
1317 DEFUNSH (VTYSH_RIPNGD
,
1324 vty
->node
= RIPNG_NODE
;
1328 DEFUNSH (VTYSH_OSPFD
,
1331 "router ospf [(1-65535)]",
1332 "Enable a routing process\n"
1333 "Start OSPF configuration\n"
1336 vty
->node
= OSPF_NODE
;
1340 DEFUNSH (VTYSH_EIGRPD
,
1343 "router eigrp (1-65535)",
1344 "Enable a routing process\n"
1345 "Start EIGRP configuration\n"
1346 "AS number to use\n")
1348 vty
->node
= EIGRP_NODE
;
1352 DEFUNSH (VTYSH_OSPF6D
,
1359 vty
->node
= OSPF6_NODE
;
1363 #if defined (HAVE_LDPD)
1364 DEFUNSH (VTYSH_LDPD
,
1368 "Global MPLS configuration subcommands\n"
1369 "Label Distribution Protocol\n")
1371 vty
->node
= LDP_NODE
;
1375 DEFUNSH (VTYSH_LDPD
,
1376 ldp_address_family_ipv4
,
1377 ldp_address_family_ipv4_cmd
,
1378 "address-family ipv4",
1379 "Configure Address Family and its parameters\n"
1382 vty
->node
= LDP_IPV4_NODE
;
1386 DEFUNSH (VTYSH_LDPD
,
1387 ldp_address_family_ipv6
,
1388 ldp_address_family_ipv6_cmd
,
1389 "address-family ipv6",
1390 "Configure Address Family and its parameters\n"
1393 vty
->node
= LDP_IPV6_NODE
;
1397 DEFUNSH (VTYSH_LDPD
,
1398 ldp_interface_ifname
,
1399 ldp_interface_ifname_cmd
,
1401 "Enable LDP on an interface and enter interface submode\n"
1402 "Interface's name\n")
1407 vty
->node
= LDP_IPV4_IFACE_NODE
;
1410 vty
->node
= LDP_IPV6_IFACE_NODE
;
1419 DEFUNSH (VTYSH_LDPD
,
1420 ldp_l2vpn_word_type_vpls
,
1421 ldp_l2vpn_word_type_vpls_cmd
,
1422 "l2vpn WORD type vpls",
1423 "Configure l2vpn commands\n"
1426 "Virtual Private LAN Service\n")
1428 vty
->node
= LDP_L2VPN_NODE
;
1432 DEFUNSH (VTYSH_LDPD
,
1433 ldp_member_pseudowire_ifname
,
1434 ldp_member_pseudowire_ifname_cmd
,
1435 "member pseudowire IFNAME",
1436 "L2VPN member configuration\n"
1437 "Pseudowire interface\n"
1438 "Interface's name\n")
1440 vty
->node
= LDP_PSEUDOWIRE_NODE
;
1445 DEFUNSH (VTYSH_ISISD
,
1451 "ISO Routing area tag")
1453 vty
->node
= ISIS_NODE
;
1457 DEFUNSH (VTYSH_RMAP
,
1459 vtysh_route_map_cmd
,
1460 "route-map WORD <deny|permit> (1-65535)",
1461 "Create route-map or enter route-map command mode\n"
1463 "Route map denies set operations\n"
1464 "Route map permits set operations\n"
1465 "Sequence to insert to/delete from existing route-map entry\n")
1467 vty
->node
= RMAP_NODE
;
1475 "Configure a terminal line\n"
1476 "Virtual terminal\n")
1478 vty
->node
= VTY_NODE
;
1482 DEFUNSH (VTYSH_REALLYALL
,
1486 "Turn on privileged mode command\n")
1488 vty
->node
= ENABLE_NODE
;
1492 DEFUNSH (VTYSH_REALLYALL
,
1496 "Turn off privileged mode command\n")
1498 if (vty
->node
== ENABLE_NODE
)
1499 vty
->node
= VIEW_NODE
;
1503 DEFUNSH (VTYSH_REALLYALL
,
1504 vtysh_config_terminal
,
1505 vtysh_config_terminal_cmd
,
1506 "configure terminal",
1507 "Configuration from vty interface\n"
1508 "Configuration terminal\n")
1510 vty
->node
= CONFIG_NODE
;
1515 vtysh_exit (struct vty
*vty
)
1524 vty
->node
= ENABLE_NODE
;
1526 case INTERFACE_NODE
:
1537 case LDP_L2VPN_NODE
:
1543 vtysh_execute("end");
1544 vtysh_execute("configure terminal");
1545 vty
->node
= CONFIG_NODE
;
1547 case BGP_VPNV4_NODE
:
1548 case BGP_VPNV6_NODE
:
1549 case BGP_ENCAP_NODE
:
1550 case BGP_ENCAPV6_NODE
:
1552 case BGP_IPV4M_NODE
:
1554 case BGP_IPV6M_NODE
:
1555 case BGP_VRF_POLICY_NODE
:
1557 case BGP_VNC_DEFAULTS_NODE
:
1558 case BGP_VNC_NVE_GROUP_NODE
:
1559 case BGP_VNC_L2_GROUP_NODE
:
1560 vty
->node
= BGP_NODE
;
1564 vty
->node
= LDP_NODE
;
1566 case LDP_IPV4_IFACE_NODE
:
1567 vty
->node
= LDP_IPV4_NODE
;
1569 case LDP_IPV6_IFACE_NODE
:
1570 vty
->node
= LDP_IPV6_NODE
;
1572 case LDP_PSEUDOWIRE_NODE
:
1573 vty
->node
= LDP_L2VPN_NODE
;
1575 case KEYCHAIN_KEY_NODE
:
1576 vty
->node
= KEYCHAIN_NODE
;
1578 case LINK_PARAMS_NODE
:
1579 vty
->node
= INTERFACE_NODE
;
1587 DEFUNSH (VTYSH_REALLYALL
,
1591 "Exit current mode and down to previous mode\n")
1593 return vtysh_exit (vty
);
1600 "Exit current mode and down to previous mode\n")
1602 return vtysh_exit_all (self
, vty
, argc
, argv
);
1605 DEFUNSH (VTYSH_BGPD
,
1606 exit_address_family
,
1607 exit_address_family_cmd
,
1608 "exit-address-family",
1609 "Exit from Address Family configuration mode\n")
1611 if (vty
->node
== BGP_IPV4_NODE
1612 || vty
->node
== BGP_IPV4M_NODE
1613 || vty
->node
== BGP_VPNV4_NODE
1614 || vty
->node
== BGP_VPNV6_NODE
1615 || vty
->node
== BGP_ENCAP_NODE
1616 || vty
->node
== BGP_ENCAPV6_NODE
1617 || vty
->node
== BGP_IPV6_NODE
1618 || vty
->node
== BGP_IPV6M_NODE
)
1619 vty
->node
= BGP_NODE
;
1623 DEFUNSH (VTYSH_BGPD
,
1625 exit_vnc_config_cmd
,
1627 "Exit from VNC configuration mode\n")
1629 if (vty
->node
== BGP_VNC_DEFAULTS_NODE
1630 || vty
->node
== BGP_VNC_NVE_GROUP_NODE
1631 || vty
->node
== BGP_VNC_L2_GROUP_NODE
)
1632 vty
->node
= BGP_NODE
;
1636 DEFUNSH (VTYSH_BGPD
,
1638 exit_vrf_policy_cmd
,
1640 "Exit from VRF configuration mode\n")
1642 if (vty
->node
== BGP_VRF_POLICY_NODE
)
1643 vty
->node
= BGP_NODE
;
1647 DEFUNSH (VTYSH_RIPD
,
1649 vtysh_exit_ripd_cmd
,
1651 "Exit current mode and down to previous mode\n")
1653 return vtysh_exit (vty
);
1656 DEFUNSH (VTYSH_RIPD
,
1658 vtysh_quit_ripd_cmd
,
1660 "Exit current mode and down to previous mode\n")
1662 return vtysh_exit_ripd (self
, vty
, argc
, argv
);
1665 DEFUNSH (VTYSH_RIPNGD
,
1667 vtysh_exit_ripngd_cmd
,
1669 "Exit current mode and down to previous mode\n")
1671 return vtysh_exit (vty
);
1674 DEFUNSH (VTYSH_RIPNGD
,
1676 vtysh_quit_ripngd_cmd
,
1678 "Exit current mode and down to previous mode\n")
1680 return vtysh_exit_ripngd (self
, vty
, argc
, argv
);
1683 DEFUNSH (VTYSH_RMAP
,
1685 vtysh_exit_rmap_cmd
,
1687 "Exit current mode and down to previous mode\n")
1689 return vtysh_exit (vty
);
1692 DEFUNSH (VTYSH_RMAP
,
1694 vtysh_quit_rmap_cmd
,
1696 "Exit current mode and down to previous mode\n")
1698 return vtysh_exit_rmap (self
, vty
, argc
, argv
);
1701 DEFUNSH (VTYSH_BGPD
,
1703 vtysh_exit_bgpd_cmd
,
1705 "Exit current mode and down to previous mode\n")
1707 return vtysh_exit (vty
);
1710 DEFUNSH (VTYSH_BGPD
,
1712 vtysh_quit_bgpd_cmd
,
1714 "Exit current mode and down to previous mode\n")
1716 return vtysh_exit_bgpd (self
, vty
, argc
, argv
);
1719 DEFUNSH (VTYSH_OSPFD
,
1721 vtysh_exit_ospfd_cmd
,
1723 "Exit current mode and down to previous mode\n")
1725 return vtysh_exit (vty
);
1728 DEFUNSH (VTYSH_OSPFD
,
1730 vtysh_quit_ospfd_cmd
,
1732 "Exit current mode and down to previous mode\n")
1734 return vtysh_exit_ospfd (self
, vty
, argc
, argv
);
1737 DEFUNSH (VTYSH_EIGRPD
,
1739 vtysh_exit_eigrpd_cmd
,
1741 "Exit current mode and down to previous mode\n")
1743 return vtysh_exit (vty
);
1746 DEFUNSH (VTYSH_EIGRPD
,
1748 vtysh_quit_eigrpd_cmd
,
1750 "Exit current mode and down to previous mode\n")
1752 return vtysh_exit (vty
);
1755 DEFUNSH (VTYSH_OSPF6D
,
1757 vtysh_exit_ospf6d_cmd
,
1759 "Exit current mode and down to previous mode\n")
1761 return vtysh_exit (vty
);
1764 DEFUNSH (VTYSH_OSPF6D
,
1766 vtysh_quit_ospf6d_cmd
,
1768 "Exit current mode and down to previous mode\n")
1770 return vtysh_exit_ospf6d (self
, vty
, argc
, argv
);
1773 #if defined (HAVE_LDPD)
1774 DEFUNSH (VTYSH_LDPD
,
1776 vtysh_exit_ldpd_cmd
,
1778 "Exit current mode and down to previous mode\n")
1780 return vtysh_exit (vty
);
1783 ALIAS (vtysh_exit_ldpd
,
1784 vtysh_quit_ldpd_cmd
,
1786 "Exit current mode and down to previous mode\n")
1789 DEFUNSH (VTYSH_ISISD
,
1791 vtysh_exit_isisd_cmd
,
1793 "Exit current mode and down to previous mode\n")
1795 return vtysh_exit (vty
);
1798 DEFUNSH (VTYSH_ISISD
,
1800 vtysh_quit_isisd_cmd
,
1802 "Exit current mode and down to previous mode\n")
1804 return vtysh_exit_isisd (self
, vty
, argc
, argv
);
1808 vtysh_exit_line_vty
,
1809 vtysh_exit_line_vty_cmd
,
1811 "Exit current mode and down to previous mode\n")
1813 return vtysh_exit (vty
);
1817 vtysh_quit_line_vty
,
1818 vtysh_quit_line_vty_cmd
,
1820 "Exit current mode and down to previous mode\n")
1822 return vtysh_exit_line_vty (self
, vty
, argc
, argv
);
1825 DEFUNSH (VTYSH_INTERFACE
,
1827 vtysh_interface_cmd
,
1828 "interface IFNAME [vrf NAME]",
1829 "Select an interface to configure\n"
1830 "Interface's name\n"
1833 vty
->node
= INTERFACE_NODE
;
1837 /* TODO Implement "no interface command in isisd. */
1838 DEFSH (VTYSH_ZEBRA
|VTYSH_RIPD
|VTYSH_RIPNGD
|VTYSH_OSPFD
|VTYSH_OSPF6D
|VTYSH_EIGRPD
,
1839 vtysh_no_interface_cmd
,
1840 "no interface IFNAME",
1842 "Delete a pseudo interface's configuration\n"
1843 "Interface's name\n")
1846 vtysh_no_interface_vrf_cmd
,
1847 "no interface IFNAME vrf NAME",
1849 "Delete a pseudo interface's configuration\n"
1850 "Interface's name\n"
1856 "logical-router (1-65535) ns NAME",
1857 "Enable a logical-router\n"
1858 "Specify the logical-router indentifier\n"
1860 "The file name in " NS_RUN_DIR
", or a full pathname\n")
1862 vty
->node
= NS_NODE
;
1870 "Select a VRF to configure\n"
1873 vty
->node
= VRF_NODE
;
1881 "Delete a pseudo vrf's configuration\n"
1888 "Exit current mode and down to previous mode\n")
1890 return vtysh_exit (vty
);
1897 "Exit current mode and down to previous mode\n")
1899 return vtysh_exit_ns(self
, vty
, argc
, argv
);
1906 "Exit current mode and down to previous mode\n")
1908 return vtysh_exit (vty
);
1915 "Exit current mode and down to previous mode\n")
1917 return vtysh_exit_vrf (self
, vty
, argc
, argv
);
1920 /* TODO Implement interface description commands in ripngd, ospf6d
1922 DEFSH (VTYSH_ZEBRA
|VTYSH_RIPD
|VTYSH_OSPFD
|VTYSH_EIGRPD
,
1923 vtysh_interface_desc_cmd
,
1924 "description LINE...",
1925 "Interface specific description\n"
1926 "Characters describing this interface\n")
1928 DEFSH (VTYSH_ZEBRA
|VTYSH_RIPD
|VTYSH_OSPFD
|VTYSH_EIGRPD
,
1929 vtysh_no_interface_desc_cmd
,
1932 "Interface specific description\n")
1934 DEFUNSH (VTYSH_INTERFACE
,
1935 vtysh_exit_interface
,
1936 vtysh_exit_interface_cmd
,
1938 "Exit current mode and down to previous mode\n")
1940 return vtysh_exit (vty
);
1943 DEFUNSH (VTYSH_INTERFACE
,
1944 vtysh_quit_interface
,
1945 vtysh_quit_interface_cmd
,
1947 "Exit current mode and down to previous mode\n")
1949 return vtysh_exit_interface (self
, vty
, argc
, argv
);
1952 DEFUN (vtysh_show_thread
,
1953 vtysh_show_thread_cmd
,
1954 "show thread cpu [FILTER]",
1956 "Thread information\n"
1957 "Thread CPU usage\n"
1958 "Display filter (rwtexb)\n")
1962 int ret
= CMD_SUCCESS
;
1965 sprintf(line
, "show thread cpu %s\n", (argc
== 4) ? argv
[idx_filter
]->arg
: "");
1966 for (i
= 0; i
< array_size(vtysh_client
); i
++)
1967 if ( vtysh_client
[i
].fd
>= 0 )
1969 fprintf (stdout
, "Thread statistics for %s:\n",
1970 vtysh_client
[i
].name
);
1971 ret
= vtysh_client_execute (&vtysh_client
[i
], line
, stdout
);
1972 fprintf (stdout
,"\n");
1977 DEFUN (vtysh_show_work_queues
,
1978 vtysh_show_work_queues_cmd
,
1981 "Work Queue information\n")
1984 int ret
= CMD_SUCCESS
;
1985 char line
[] = "show work-queues\n";
1987 for (i
= 0; i
< array_size(vtysh_client
); i
++)
1988 if ( vtysh_client
[i
].fd
>= 0 )
1990 fprintf (stdout
, "Work queue statistics for %s:\n",
1991 vtysh_client
[i
].name
);
1992 ret
= vtysh_client_execute (&vtysh_client
[i
], line
, stdout
);
1993 fprintf (stdout
,"\n");
1999 DEFUN (vtysh_show_work_queues_daemon
,
2000 vtysh_show_work_queues_daemon_cmd
,
2001 "show work-queues <zebra|ripd|ripngd|ospfd|ospf6d|bgpd|isisd>",
2003 "Work Queue information\n"
2004 "For the zebra daemon\n"
2005 "For the rip daemon\n"
2006 "For the ripng daemon\n"
2007 "For the ospf daemon\n"
2008 "For the ospfv6 daemon\n"
2009 "For the bgp daemon\n"
2010 "For the isis daemon\n")
2012 int idx_protocol
= 2;
2014 int ret
= CMD_SUCCESS
;
2016 for (i
= 0; i
< array_size(vtysh_client
); i
++)
2018 if (strmatch(vtysh_client
[i
].name
, argv
[idx_protocol
]->text
))
2022 ret
= vtysh_client_execute(&vtysh_client
[i
], "show work-queues\n", stdout
);
2027 DEFUNSH (VTYSH_ZEBRA
,
2029 vtysh_link_params_cmd
,
2034 vty
->node
= LINK_PARAMS_NODE
;
2038 DEFUNSH (VTYSH_ZEBRA
,
2040 exit_link_params_cmd
,
2042 "Exit from Link Params configuration node\n")
2044 if (vty
->node
== LINK_PARAMS_NODE
)
2045 vty
->node
= INTERFACE_NODE
;
2050 show_per_daemon (const char *line
, const char *headline
)
2053 int ret
= CMD_SUCCESS
;
2055 for (i
= 0; i
< array_size(vtysh_client
); i
++)
2056 if ( vtysh_client
[i
].fd
>= 0 )
2058 fprintf (stdout
, headline
,
2059 vtysh_client
[i
].name
);
2060 ret
= vtysh_client_execute (&vtysh_client
[i
], line
, stdout
);
2061 fprintf (stdout
,"\n");
2068 DEFUN (vtysh_show_memory
,
2069 vtysh_show_memory_cmd
,
2072 "Memory statistics\n")
2074 return show_per_daemon ("show memory\n", "Memory statistics for %s:\n");
2077 DEFUN (vtysh_show_modules
,
2078 vtysh_show_modules_cmd
,
2083 return show_per_daemon ("show modules\n", "Module information for %s:\n");
2086 /* Logging commands. */
2087 DEFUN (vtysh_show_logging
,
2088 vtysh_show_logging_cmd
,
2091 "Show current logging configuration\n")
2094 int ret
= CMD_SUCCESS
;
2095 char line
[] = "show logging\n";
2097 for (i
= 0; i
< array_size(vtysh_client
); i
++)
2098 if ( vtysh_client
[i
].fd
>= 0 )
2100 fprintf (stdout
,"Logging configuration for %s:\n",
2101 vtysh_client
[i
].name
);
2102 ret
= vtysh_client_execute (&vtysh_client
[i
], line
, stdout
);
2103 fprintf (stdout
,"\n");
2111 vtysh_log_stdout_cmd
,
2114 "Set stdout logging level\n")
2120 vtysh_log_stdout_level
,
2121 vtysh_log_stdout_level_cmd
,
2122 "log stdout <emergencies|alerts|critical|errors|warnings|notifications|informational|debugging>",
2124 "Set stdout logging level\n"
2131 no_vtysh_log_stdout
,
2132 no_vtysh_log_stdout_cmd
,
2133 "no log stdout [LEVEL]",
2136 "Cancel logging to stdout\n"
2145 "log file FILENAME",
2148 "Logging filename\n")
2154 vtysh_log_file_level
,
2155 vtysh_log_file_level_cmd
,
2156 "log file FILENAME <emergencies|alerts|critical|errors|warnings|notifications|informational|debugging>",
2159 "Logging filename\n"
2167 no_vtysh_log_file_cmd
,
2168 "no log file [FILENAME [LEVEL]]",
2171 "Cancel logging to file\n"
2172 "Logging file name\n"
2180 vtysh_log_monitor_cmd
,
2181 "log monitor [<emergencies|alerts|critical|errors|warnings|notifications|informational|debugging>]",
2183 "Set terminal line (monitor) logging level\n"
2190 no_vtysh_log_monitor
,
2191 no_vtysh_log_monitor_cmd
,
2192 "no log monitor [LEVEL]",
2195 "Disable terminal line (monitor) logging\n"
2203 vtysh_log_syslog_cmd
,
2204 "log syslog [<emergencies|alerts|critical|errors|warnings|notifications|informational|debugging>]",
2206 "Set syslog logging level\n"
2213 no_vtysh_log_syslog
,
2214 no_vtysh_log_syslog_cmd
,
2215 "no log syslog [LEVEL]",
2218 "Cancel logging to syslog\n"
2226 vtysh_log_facility_cmd
,
2227 "log facility <kern|user|mail|daemon|auth|syslog|lpr|news|uucp|cron|local0|local1|local2|local3|local4|local5|local6|local7>",
2229 "Facility parameter for syslog messages\n"
2237 no_vtysh_log_facility
,
2238 no_vtysh_log_facility_cmd
,
2239 "no log facility [FACILITY]",
2242 "Reset syslog facility to default (daemon)\n"
2243 "Syslog facility\n")
2249 DEFUNSH_DEPRECATED (VTYSH_ALL
,
2252 "log trap <emergencies|alerts|critical|errors|warnings|notifications|informational|debugging>",
2254 "(Deprecated) Set logging level and default for all destinations\n"
2261 DEFUNSH_DEPRECATED (VTYSH_ALL
,
2263 no_vtysh_log_trap_cmd
,
2264 "no log trap [LEVEL]",
2267 "Permit all logging information\n"
2274 vtysh_log_record_priority
,
2275 vtysh_log_record_priority_cmd
,
2276 "log record-priority",
2278 "Log the priority of the message within the message\n")
2284 no_vtysh_log_record_priority
,
2285 no_vtysh_log_record_priority_cmd
,
2286 "no log record-priority",
2289 "Do not log the priority of the message within the message\n")
2295 vtysh_log_timestamp_precision
,
2296 vtysh_log_timestamp_precision_cmd
,
2297 "log timestamp precision (0-6)",
2299 "Timestamp configuration\n"
2300 "Set the timestamp precision\n"
2301 "Number of subsecond digits\n")
2307 no_vtysh_log_timestamp_precision
,
2308 no_vtysh_log_timestamp_precision_cmd
,
2309 "no log timestamp precision",
2312 "Timestamp configuration\n"
2313 "Reset the timestamp precision to the default value of 0\n")
2319 vtysh_service_password_encrypt
,
2320 vtysh_service_password_encrypt_cmd
,
2321 "service password-encryption",
2322 "Set up miscellaneous service\n"
2323 "Enable encrypted passwords\n")
2329 no_vtysh_service_password_encrypt
,
2330 no_vtysh_service_password_encrypt_cmd
,
2331 "no service password-encryption",
2333 "Set up miscellaneous service\n"
2334 "Enable encrypted passwords\n")
2340 vtysh_config_password
,
2342 "password (8-8) WORD",
2343 "Assign the terminal connection password\n"
2344 "Specifies a HIDDEN password will follow\n"
2346 "The HIDDEN line password string\n")
2352 vtysh_password_text
,
2353 vtysh_password_text_cmd
,
2355 "Assign the terminal connection password\n"
2356 "The UNENCRYPTED (cleartext) line password\n")
2362 vtysh_config_enable_password
,
2363 vtysh_enable_password_cmd
,
2364 "enable password (8-8) WORD",
2365 "Modify enable password parameters\n"
2366 "Assign the privileged level password\n"
2367 "Specifies a HIDDEN password will follow\n"
2368 "The HIDDEN 'enable' password string\n")
2374 vtysh_enable_password_text
,
2375 vtysh_enable_password_text_cmd
,
2376 "enable password LINE",
2377 "Modify enable password parameters\n"
2378 "Assign the privileged level password\n"
2379 "The UNENCRYPTED (cleartext) 'enable' password\n")
2385 no_vtysh_config_enable_password
,
2386 no_vtysh_enable_password_cmd
,
2387 "no enable password",
2389 "Modify enable password parameters\n"
2390 "Assign the privileged level password\n")
2395 DEFUN (vtysh_write_terminal
,
2396 vtysh_write_terminal_cmd
,
2397 "write terminal [<zebra|ripd|ripngd|ospfd|ospf6d|ldpd|bgpd|isisd|pimd>]",
2398 "Write running configuration to memory, network, or terminal\n"
2399 "Write to terminal\n"
2400 "For the zebra daemon\n"
2401 "For the rip daemon\n"
2402 "For the ripng daemon\n"
2403 "For the ospf daemon\n"
2404 "For the ospfv6 daemon\n"
2405 "For the ldpd daemon\n"
2406 "For the bgp daemon\n"
2407 "For the isis daemon\n"
2408 "For the pim daemon\n")
2411 char line
[] = "write terminal\n";
2414 if (vtysh_pager_name
)
2416 fp
= popen (vtysh_pager_name
, "w");
2426 vty_out (vty
, "Building configuration...%s", VTY_NEWLINE
);
2427 vty_out (vty
, "%sCurrent configuration:%s", VTY_NEWLINE
,
2429 vty_out (vty
, "!%s", VTY_NEWLINE
);
2431 for (i
= 0; i
< array_size(vtysh_client
); i
++)
2432 if ((argc
< 3 ) || (strmatch (vtysh_client
[i
].name
, argv
[2]->text
)))
2433 vtysh_client_config (&vtysh_client
[i
], line
);
2435 /* Integrate vtysh specific configuration. */
2436 vtysh_config_write ();
2438 vtysh_config_dump (fp
);
2440 if (vtysh_pager_name
&& fp
)
2443 if (pclose (fp
) == -1)
2451 vty_out (vty
, "end%s", VTY_NEWLINE
);
2455 DEFUN (vtysh_show_running_config
,
2456 vtysh_show_running_config_cmd
,
2457 "show running-config [<zebra|ripd|ripngd|ospfd|ospf6d|ldpd|bgpd|isisd|pimd>]",
2459 "Current operating configuration\n"
2460 "For the zebra daemon\n"
2461 "For the rip daemon\n"
2462 "For the ripng daemon\n"
2463 "For the ospf daemon\n"
2464 "For the ospfv6 daemon\n"
2465 "For the ldp daemon\n"
2466 "For the bgp daemon\n"
2467 "For the isis daemon\n"
2468 "For the pim daemon\n")
2470 return vtysh_write_terminal (self
, vty
, argc
, argv
);
2473 DEFUN (vtysh_integrated_config
,
2474 vtysh_integrated_config_cmd
,
2475 "service integrated-vtysh-config",
2476 "Set up miscellaneous service\n"
2477 "Write configuration into integrated file\n")
2479 vtysh_write_integrated
= WRITE_INTEGRATED_YES
;
2483 DEFUN (no_vtysh_integrated_config
,
2484 no_vtysh_integrated_config_cmd
,
2485 "no service integrated-vtysh-config",
2487 "Set up miscellaneous service\n"
2488 "Write configuration into integrated file\n")
2490 vtysh_write_integrated
= WRITE_INTEGRATED_NO
;
2495 backup_config_file (const char *fbackup
)
2497 char *integrate_sav
= NULL
;
2499 integrate_sav
= malloc (strlen (fbackup
) +
2500 strlen (CONF_BACKUP_EXT
) + 1);
2501 strcpy (integrate_sav
, fbackup
);
2502 strcat (integrate_sav
, CONF_BACKUP_EXT
);
2504 /* Move current configuration file to backup config file. */
2505 unlink (integrate_sav
);
2506 rename (fbackup
, integrate_sav
);
2507 free (integrate_sav
);
2511 vtysh_write_config_integrated(void)
2514 char line
[] = "write terminal\n";
2517 struct passwd
*pwentry
;
2518 struct group
*grentry
;
2524 fprintf (stdout
,"Building Configuration...\n");
2526 backup_config_file(quagga_config
);
2527 fp
= fopen (quagga_config
, "w");
2530 fprintf (stdout
,"%% Error: failed to open configuration file %s: %s\n",
2531 quagga_config
, safe_strerror(errno
));
2536 for (i
= 0; i
< array_size(vtysh_client
); i
++)
2537 vtysh_client_config (&vtysh_client
[i
], line
);
2539 vtysh_config_write ();
2540 vtysh_config_dump (fp
);
2542 if (fchmod (fd
, CONFIGFILE_MASK
) != 0)
2544 printf ("%% Warning: can't chmod configuration file %s: %s\n",
2545 quagga_config
, safe_strerror(errno
));
2549 pwentry
= getpwnam (FRR_USER
);
2551 uid
= pwentry
->pw_uid
;
2554 printf ("%% Warning: could not look up user \"%s\"\n", FRR_USER
);
2558 grentry
= getgrnam (FRR_GROUP
);
2560 gid
= grentry
->gr_gid
;
2563 printf ("%% Warning: could not look up group \"%s\"\n", FRR_GROUP
);
2567 if (!fstat (fd
, &st
))
2569 if (st
.st_uid
== uid
)
2571 if (st
.st_gid
== gid
)
2573 if ((uid
!= (uid_t
)-1 || gid
!= (gid_t
)-1) && fchown (fd
, uid
, gid
))
2575 printf ("%% Warning: can't chown configuration file %s: %s\n",
2576 quagga_config
, safe_strerror(errno
));
2582 printf ("%% Warning: stat() failed on %s: %s\n",
2583 quagga_config
, safe_strerror(errno
));
2589 printf ("Integrated configuration saved to %s\n", quagga_config
);
2597 static bool want_config_integrated(void)
2601 switch (vtysh_write_integrated
)
2603 case WRITE_INTEGRATED_UNSPECIFIED
:
2604 if (stat(quagga_config
, &s
) && errno
== ENOENT
)
2607 case WRITE_INTEGRATED_NO
:
2609 case WRITE_INTEGRATED_YES
:
2615 DEFUN (vtysh_write_memory
,
2616 vtysh_write_memory_cmd
,
2617 "write [<memory|file>]",
2618 "Write running configuration to memory, network, or terminal\n"
2619 "Write configuration to the file (same as write file)\n"
2620 "Write configuration to the file (same as write memory)\n")
2622 int ret
= CMD_SUCCESS
;
2623 char line
[] = "write memory\n";
2626 fprintf (stdout
, "Note: this version of vtysh never writes vtysh.conf\n");
2628 /* If integrated frr.conf explicitely set. */
2629 if (want_config_integrated())
2632 for (i
= 0; i
< array_size(vtysh_client
); i
++)
2633 if (vtysh_client
[i
].flag
== VTYSH_WATCHFRR
)
2635 if (i
< array_size(vtysh_client
) && vtysh_client
[i
].fd
!= -1)
2636 ret
= vtysh_client_execute (&vtysh_client
[i
], "write integrated", stdout
);
2638 if (ret
!= CMD_SUCCESS
)
2640 printf("\nWarning: attempting direct configuration write without "
2641 "watchfrr.\nFile permissions and ownership may be "
2642 "incorrect, or write may fail.\n\n");
2643 ret
= vtysh_write_config_integrated();
2648 fprintf (stdout
,"Building Configuration...\n");
2650 for (i
= 0; i
< array_size(vtysh_client
); i
++)
2651 ret
= vtysh_client_execute (&vtysh_client
[i
], line
, stdout
);
2656 DEFUN (vtysh_copy_running_config
,
2657 vtysh_copy_running_config_cmd
,
2658 "copy running-config startup-config",
2659 "Copy from one file to another\n"
2660 "Copy from current system configuration\n"
2661 "Copy to startup configuration\n")
2663 return vtysh_write_memory (self
, vty
, argc
, argv
);
2666 DEFUN (vtysh_terminal_length
,
2667 vtysh_terminal_length_cmd
,
2668 "terminal length (0-512)",
2669 "Set terminal line parameters\n"
2670 "Set number of lines on a screen\n"
2671 "Number of lines on screen (0 for no pausing)\n")
2675 char *endptr
= NULL
;
2676 char default_pager
[10];
2678 lines
= strtol (argv
[idx_number
]->arg
, &endptr
, 10);
2679 if (lines
< 0 || lines
> 512 || *endptr
!= '\0')
2681 vty_out (vty
, "length is malformed%s", VTY_NEWLINE
);
2685 if (vtysh_pager_name
)
2687 free (vtysh_pager_name
);
2688 vtysh_pager_name
= NULL
;
2693 snprintf(default_pager
, 10, "more -%i", lines
);
2694 vtysh_pager_name
= strdup (default_pager
);
2700 DEFUN (vtysh_terminal_no_length
,
2701 vtysh_terminal_no_length_cmd
,
2702 "terminal no length",
2703 "Set terminal line parameters\n"
2705 "Set number of lines on a screen\n")
2707 if (vtysh_pager_name
)
2709 free (vtysh_pager_name
);
2710 vtysh_pager_name
= NULL
;
2717 DEFUN (vtysh_show_daemons
,
2718 vtysh_show_daemons_cmd
,
2721 "Show list of running daemons\n")
2725 for (i
= 0; i
< array_size(vtysh_client
); i
++)
2726 if ( vtysh_client
[i
].fd
>= 0 )
2727 vty_out(vty
, " %s", vtysh_client
[i
].name
);
2728 vty_out(vty
, "%s", VTY_NEWLINE
);
2733 /* Execute command in child process. */
2735 execute_command (const char *command
, int argc
, struct cmd_token
*arg1
,
2746 /* Failure of fork(). */
2747 fprintf (stderr
, "Can't fork: %s\n", safe_strerror (errno
));
2752 /* This is child process. */
2756 execlp (command
, command
, (const char *)NULL
);
2759 execlp (command
, command
, arg1
, (const char *)NULL
);
2762 execlp (command
, command
, arg1
, arg2
, (const char *)NULL
);
2766 /* When execlp suceed, this part is not executed. */
2767 fprintf (stderr
, "Can't execute %s: %s\n", command
, safe_strerror (errno
));
2772 /* This is parent. */
2774 wait4 (pid
, &status
, 0, NULL
);
2782 "Send echo messages\n"
2783 "Ping destination address or hostname\n")
2785 execute_command ("ping", 1, argv
[0], NULL
);
2792 "Send echo messages\n"
2794 "Ping destination address or hostname\n")
2796 DEFUN (vtysh_traceroute
,
2797 vtysh_traceroute_cmd
,
2799 "Trace route to destination\n"
2800 "Trace route to destination address or hostname\n")
2802 execute_command ("traceroute", 1, argv
[0], NULL
);
2806 ALIAS (vtysh_traceroute
,
2807 vtysh_traceroute_ip_cmd
,
2808 "traceroute ip WORD",
2809 "Trace route to destination\n"
2811 "Trace route to destination address or hostname\n")
2816 "Send echo messages\n"
2818 "Ping destination address or hostname\n")
2820 execute_command ("ping6", 1, argv
[0], NULL
);
2824 DEFUN (vtysh_traceroute6
,
2825 vtysh_traceroute6_cmd
,
2826 "traceroute ipv6 WORD",
2827 "Trace route to destination\n"
2829 "Trace route to destination address or hostname\n")
2831 execute_command ("traceroute6", 1, argv
[0], NULL
);
2835 #if defined(HAVE_SHELL_ACCESS)
2836 DEFUN (vtysh_telnet
,
2839 "Open a telnet connection\n"
2840 "IP address or hostname of a remote system\n")
2842 execute_command ("telnet", 1, argv
[0], NULL
);
2846 DEFUN (vtysh_telnet_port
,
2847 vtysh_telnet_port_cmd
,
2849 "Open a telnet connection\n"
2850 "IP address or hostname of a remote system\n"
2851 "TCP Port number\n")
2853 execute_command ("telnet", 2, argv
[0], argv
[1]);
2860 "Open an ssh connection\n"
2863 execute_command ("ssh", 1, argv
[0], NULL
);
2867 DEFUN (vtysh_start_shell
,
2868 vtysh_start_shell_cmd
,
2870 "Start UNIX shell\n")
2872 execute_command ("sh", 0, NULL
, NULL
);
2876 DEFUN (vtysh_start_bash
,
2877 vtysh_start_bash_cmd
,
2879 "Start UNIX shell\n"
2882 execute_command ("bash", 0, NULL
, NULL
);
2886 DEFUN (vtysh_start_zsh
,
2887 vtysh_start_zsh_cmd
,
2889 "Start UNIX shell\n"
2892 execute_command ("zsh", 0, NULL
, NULL
);
2899 "list [permutations]",
2900 "Print command list\n"
2901 "Print all possible command permutations\n")
2903 return cmd_list_cmds (vty
, argc
== 2);
2907 vtysh_install_default (enum node_type node
)
2909 install_element (node
, &config_list_cmd
);
2912 /* Making connection to protocol daemon. */
2914 vtysh_connect (struct vtysh_client
*vclient
)
2918 struct sockaddr_un addr
;
2922 if (!vclient
->path
[0])
2923 snprintf(vclient
->path
, sizeof(vclient
->path
), "%s/%s.vty",
2924 vty_sock_path
, vclient
->name
);
2925 path
= vclient
->path
;
2927 /* Stat socket to see if we have permission to access it. */
2928 ret
= stat (path
, &s_stat
);
2929 if (ret
< 0 && errno
!= ENOENT
)
2931 fprintf (stderr
, "vtysh_connect(%s): stat = %s\n",
2932 path
, safe_strerror(errno
));
2938 if (! S_ISSOCK(s_stat
.st_mode
))
2940 fprintf (stderr
, "vtysh_connect(%s): Not a socket\n",
2947 sock
= socket (AF_UNIX
, SOCK_STREAM
, 0);
2951 fprintf(stderr
, "vtysh_connect(%s): socket = %s\n", path
,
2952 safe_strerror(errno
));
2957 memset (&addr
, 0, sizeof (struct sockaddr_un
));
2958 addr
.sun_family
= AF_UNIX
;
2959 strlcpy (addr
.sun_path
, path
, sizeof (addr
.sun_path
));
2960 #ifdef HAVE_STRUCT_SOCKADDR_UN_SUN_LEN
2961 len
= addr
.sun_len
= SUN_LEN(&addr
);
2963 len
= sizeof (addr
.sun_family
) + strlen (addr
.sun_path
);
2964 #endif /* HAVE_STRUCT_SOCKADDR_UN_SUN_LEN */
2966 ret
= connect (sock
, (struct sockaddr
*) &addr
, len
);
2970 fprintf(stderr
, "vtysh_connect(%s): connect = %s\n", path
,
2971 safe_strerror(errno
));
2981 /* Return true if str ends with suffix, else return false */
2983 ends_with(const char *str
, const char *suffix
)
2985 if (!str
|| !suffix
)
2987 size_t lenstr
= strlen(str
);
2988 size_t lensuffix
= strlen(suffix
);
2989 if (lensuffix
> lenstr
)
2991 return strncmp(str
+ lenstr
- lensuffix
, suffix
, lensuffix
) == 0;
2995 vtysh_client_sorted_insert (struct vtysh_client
*head_client
,
2996 struct vtysh_client
*client
)
2998 struct vtysh_client
*prev_node
, *current_node
;
3000 prev_node
= head_client
;
3001 current_node
= head_client
->next
;
3002 while (current_node
)
3004 if (strcmp(current_node
->path
, client
->path
) > 0)
3007 prev_node
= current_node
;
3008 current_node
= current_node
->next
;
3010 client
->next
= current_node
;
3011 prev_node
->next
= client
;
3014 #define MAXIMUM_INSTANCES 10
3017 vtysh_update_all_insances(struct vtysh_client
* head_client
)
3019 struct vtysh_client
*client
;
3021 struct dirent
*file
;
3024 if (head_client
->flag
!= VTYSH_OSPFD
) return;
3026 /* ls vty_sock_dir and look for all files ending in .vty */
3027 dir
= opendir(vty_sock_path
);
3030 while ((file
= readdir(dir
)) != NULL
)
3032 if (begins_with(file
->d_name
, "ospfd-") && ends_with(file
->d_name
, ".vty"))
3034 if (n
== MAXIMUM_INSTANCES
)
3037 "Parsing %s, client limit(%d) reached!\n",
3041 client
= (struct vtysh_client
*) malloc(sizeof(struct vtysh_client
));
3043 client
->name
= "ospfd";
3044 client
->flag
= VTYSH_OSPFD
;
3045 snprintf(client
->path
, sizeof(client
->path
), "%s/%s",
3046 vty_sock_path
, file
->d_name
);
3047 client
->next
= NULL
;
3048 vtysh_client_sorted_insert(head_client
, client
);
3057 vtysh_connect_all_instances (struct vtysh_client
*head_client
)
3059 struct vtysh_client
*client
;
3062 vtysh_update_all_insances(head_client
);
3064 client
= head_client
->next
;
3067 if (vtysh_connect(client
) == 0)
3069 client
= client
->next
;
3076 vtysh_connect_all(const char *daemon_name
)
3082 for (i
= 0; i
< array_size(vtysh_client
); i
++)
3084 if (!daemon_name
|| !strcmp(daemon_name
, vtysh_client
[i
].name
))
3087 if (vtysh_connect(&vtysh_client
[i
]) == 0)
3090 rc
+= vtysh_connect_all_instances(&vtysh_client
[i
]);
3094 fprintf(stderr
, "Error: no daemons match name %s!\n", daemon_name
);
3098 /* To disable readline's filename completion. */
3100 vtysh_completion_entry_function (const char *ignore
, int invoking_key
)
3106 vtysh_readline_init (void)
3108 /* readline related settings. */
3110 rl_bind_key ('?', (rl_command_func_t
*) vtysh_rl_describe
);
3111 rl_completion_entry_function
= vtysh_completion_entry_function
;
3112 rl_attempted_completion_function
= (rl_completion_func_t
*)new_completion
;
3118 static struct utsname names
;
3119 static char buf
[100];
3120 const char*hostname
;
3121 extern struct host host
;
3123 hostname
= host
.name
;
3127 if (!names
.nodename
[0])
3129 hostname
= names
.nodename
;
3132 snprintf (buf
, sizeof buf
, cmd_prompt (vty
->node
), hostname
);
3138 vtysh_init_vty (void)
3140 /* Make vty structure. */
3142 vty
->type
= VTY_SHELL
;
3143 vty
->node
= VIEW_NODE
;
3145 /* Initialize commands. */
3148 /* Install nodes. */
3149 install_node (&bgp_node
, NULL
);
3150 install_node (&rip_node
, NULL
);
3151 install_node (&interface_node
, NULL
);
3152 install_node (&link_params_node
, NULL
);
3153 install_node (&ns_node
, NULL
);
3154 install_node (&vrf_node
, NULL
);
3155 install_node (&rmap_node
, NULL
);
3156 install_node (&zebra_node
, NULL
);
3157 install_node (&bgp_vpnv4_node
, NULL
);
3158 install_node (&bgp_vpnv6_node
, NULL
);
3159 install_node (&bgp_encap_node
, NULL
);
3160 install_node (&bgp_encapv6_node
, NULL
);
3161 install_node (&bgp_ipv4_node
, NULL
);
3162 install_node (&bgp_ipv4m_node
, NULL
);
3163 install_node (&bgp_ipv6_node
, NULL
);
3164 install_node (&bgp_ipv6m_node
, NULL
);
3165 install_node (&bgp_vrf_policy_node
, NULL
);
3166 install_node (&bgp_evpn_node
, NULL
);
3167 install_node (&bgp_vnc_defaults_node
, NULL
);
3168 install_node (&bgp_vnc_nve_group_node
, NULL
);
3169 install_node (&bgp_vnc_l2_group_node
, NULL
);
3170 install_node (&ospf_node
, NULL
);
3171 install_node (&eigrp_node
, NULL
);
3172 install_node (&ripng_node
, NULL
);
3173 install_node (&ospf6_node
, NULL
);
3174 install_node (&ldp_node
, NULL
);
3175 install_node (&ldp_ipv4_node
, NULL
);
3176 install_node (&ldp_ipv6_node
, NULL
);
3177 install_node (&ldp_ipv4_iface_node
, NULL
);
3178 install_node (&ldp_ipv6_iface_node
, NULL
);
3179 install_node (&ldp_l2vpn_node
, NULL
);
3180 install_node (&ldp_pseudowire_node
, NULL
);
3181 install_node (&keychain_node
, NULL
);
3182 install_node (&keychain_key_node
, NULL
);
3183 install_node (&isis_node
, NULL
);
3184 install_node (&vty_node
, NULL
);
3186 vtysh_install_default (VIEW_NODE
);
3187 vtysh_install_default (CONFIG_NODE
);
3188 vtysh_install_default (BGP_NODE
);
3189 vtysh_install_default (RIP_NODE
);
3190 vtysh_install_default (INTERFACE_NODE
);
3191 vtysh_install_default (LINK_PARAMS_NODE
);
3192 vtysh_install_default (NS_NODE
);
3193 vtysh_install_default (VRF_NODE
);
3194 vtysh_install_default (RMAP_NODE
);
3195 vtysh_install_default (ZEBRA_NODE
);
3196 vtysh_install_default (BGP_VPNV4_NODE
);
3197 vtysh_install_default (BGP_VPNV6_NODE
);
3198 vtysh_install_default (BGP_ENCAP_NODE
);
3199 vtysh_install_default (BGP_ENCAPV6_NODE
);
3200 vtysh_install_default (BGP_IPV4_NODE
);
3201 vtysh_install_default (BGP_IPV4M_NODE
);
3202 vtysh_install_default (BGP_IPV6_NODE
);
3203 vtysh_install_default (BGP_IPV6M_NODE
);
3204 vtysh_install_default (BGP_EVPN_NODE
);
3206 vtysh_install_default (BGP_VRF_POLICY_NODE
);
3207 vtysh_install_default (BGP_VNC_DEFAULTS_NODE
);
3208 vtysh_install_default (BGP_VNC_NVE_GROUP_NODE
);
3209 vtysh_install_default (BGP_VNC_L2_GROUP_NODE
);
3211 vtysh_install_default (OSPF_NODE
);
3212 vtysh_install_default (EIGRP_NODE
);
3213 vtysh_install_default (RIPNG_NODE
);
3214 vtysh_install_default (OSPF6_NODE
);
3215 vtysh_install_default (LDP_NODE
);
3216 vtysh_install_default (LDP_IPV4_NODE
);
3217 vtysh_install_default (LDP_IPV6_NODE
);
3218 vtysh_install_default (LDP_IPV4_IFACE_NODE
);
3219 vtysh_install_default (LDP_IPV6_IFACE_NODE
);
3220 vtysh_install_default (LDP_L2VPN_NODE
);
3221 vtysh_install_default (LDP_PSEUDOWIRE_NODE
);
3222 vtysh_install_default (ISIS_NODE
);
3223 vtysh_install_default (KEYCHAIN_NODE
);
3224 vtysh_install_default (KEYCHAIN_KEY_NODE
);
3225 vtysh_install_default (VTY_NODE
);
3227 install_element (VIEW_NODE
, &vtysh_enable_cmd
);
3228 install_element (ENABLE_NODE
, &vtysh_config_terminal_cmd
);
3229 install_element (ENABLE_NODE
, &vtysh_disable_cmd
);
3231 /* "exit" command. */
3232 install_element (VIEW_NODE
, &vtysh_exit_all_cmd
);
3233 install_element (CONFIG_NODE
, &vtysh_exit_all_cmd
);
3234 install_element (VIEW_NODE
, &vtysh_quit_all_cmd
);
3235 install_element (CONFIG_NODE
, &vtysh_quit_all_cmd
);
3236 install_element (RIP_NODE
, &vtysh_exit_ripd_cmd
);
3237 install_element (RIP_NODE
, &vtysh_quit_ripd_cmd
);
3238 install_element (RIPNG_NODE
, &vtysh_exit_ripngd_cmd
);
3239 install_element (RIPNG_NODE
, &vtysh_quit_ripngd_cmd
);
3240 install_element (OSPF_NODE
, &vtysh_exit_ospfd_cmd
);
3241 install_element (OSPF_NODE
, &vtysh_quit_ospfd_cmd
);
3242 install_element (EIGRP_NODE
, &vtysh_exit_eigrpd_cmd
);
3243 install_element (EIGRP_NODE
, &vtysh_quit_eigrpd_cmd
);
3244 install_element (OSPF6_NODE
, &vtysh_exit_ospf6d_cmd
);
3245 install_element (OSPF6_NODE
, &vtysh_quit_ospf6d_cmd
);
3246 #if defined (HAVE_LDPD)
3247 install_element (LDP_NODE
, &vtysh_exit_ldpd_cmd
);
3248 install_element (LDP_NODE
, &vtysh_quit_ldpd_cmd
);
3249 install_element (LDP_IPV4_NODE
, &vtysh_exit_ldpd_cmd
);
3250 install_element (LDP_IPV4_NODE
, &vtysh_quit_ldpd_cmd
);
3251 install_element (LDP_IPV6_NODE
, &vtysh_exit_ldpd_cmd
);
3252 install_element (LDP_IPV6_NODE
, &vtysh_quit_ldpd_cmd
);
3253 install_element (LDP_IPV4_IFACE_NODE
, &vtysh_exit_ldpd_cmd
);
3254 install_element (LDP_IPV4_IFACE_NODE
, &vtysh_quit_ldpd_cmd
);
3255 install_element (LDP_IPV6_IFACE_NODE
, &vtysh_exit_ldpd_cmd
);
3256 install_element (LDP_IPV6_IFACE_NODE
, &vtysh_quit_ldpd_cmd
);
3257 install_element (LDP_L2VPN_NODE
, &vtysh_exit_ldpd_cmd
);
3258 install_element (LDP_L2VPN_NODE
, &vtysh_quit_ldpd_cmd
);
3259 install_element (LDP_PSEUDOWIRE_NODE
, &vtysh_exit_ldpd_cmd
);
3260 install_element (LDP_PSEUDOWIRE_NODE
, &vtysh_quit_ldpd_cmd
);
3262 install_element (BGP_NODE
, &vtysh_exit_bgpd_cmd
);
3263 install_element (BGP_NODE
, &vtysh_quit_bgpd_cmd
);
3264 install_element (BGP_VPNV4_NODE
, &vtysh_exit_bgpd_cmd
);
3265 install_element (BGP_VPNV4_NODE
, &vtysh_quit_bgpd_cmd
);
3266 install_element (BGP_VPNV6_NODE
, &vtysh_exit_bgpd_cmd
);
3267 install_element (BGP_VPNV6_NODE
, &vtysh_quit_bgpd_cmd
);
3268 install_element (BGP_ENCAP_NODE
, &vtysh_exit_bgpd_cmd
);
3269 install_element (BGP_ENCAP_NODE
, &vtysh_quit_bgpd_cmd
);
3270 install_element (BGP_ENCAPV6_NODE
, &vtysh_exit_bgpd_cmd
);
3271 install_element (BGP_ENCAPV6_NODE
, &vtysh_quit_bgpd_cmd
);
3272 install_element (BGP_IPV4_NODE
, &vtysh_exit_bgpd_cmd
);
3273 install_element (BGP_IPV4_NODE
, &vtysh_quit_bgpd_cmd
);
3274 install_element (BGP_IPV4M_NODE
, &vtysh_exit_bgpd_cmd
);
3275 install_element (BGP_IPV4M_NODE
, &vtysh_quit_bgpd_cmd
);
3276 install_element (BGP_IPV6_NODE
, &vtysh_exit_bgpd_cmd
);
3277 install_element (BGP_IPV6_NODE
, &vtysh_quit_bgpd_cmd
);
3278 install_element (BGP_IPV6M_NODE
, &vtysh_exit_bgpd_cmd
);
3279 install_element (BGP_IPV6M_NODE
, &vtysh_quit_bgpd_cmd
);
3280 install_element (BGP_EVPN_NODE
, &vtysh_quit_bgpd_cmd
);
3281 #if defined (ENABLE_BGP_VNC)
3282 install_element (BGP_VRF_POLICY_NODE
, &vtysh_exit_bgpd_cmd
);
3283 install_element (BGP_VRF_POLICY_NODE
, &vtysh_quit_bgpd_cmd
);
3284 install_element (BGP_VNC_DEFAULTS_NODE
, &vtysh_exit_bgpd_cmd
);
3285 install_element (BGP_VNC_DEFAULTS_NODE
, &vtysh_quit_bgpd_cmd
);
3286 install_element (BGP_VNC_NVE_GROUP_NODE
, &vtysh_exit_bgpd_cmd
);
3287 install_element (BGP_VNC_NVE_GROUP_NODE
, &vtysh_quit_bgpd_cmd
);
3288 install_element (BGP_VNC_L2_GROUP_NODE
, &vtysh_exit_bgpd_cmd
);
3289 install_element (BGP_VNC_L2_GROUP_NODE
, &vtysh_quit_bgpd_cmd
);
3291 install_element (ISIS_NODE
, &vtysh_exit_isisd_cmd
);
3292 install_element (ISIS_NODE
, &vtysh_quit_isisd_cmd
);
3293 install_element (KEYCHAIN_NODE
, &vtysh_exit_ripd_cmd
);
3294 install_element (KEYCHAIN_NODE
, &vtysh_quit_ripd_cmd
);
3295 install_element (KEYCHAIN_KEY_NODE
, &vtysh_exit_ripd_cmd
);
3296 install_element (KEYCHAIN_KEY_NODE
, &vtysh_quit_ripd_cmd
);
3297 install_element (RMAP_NODE
, &vtysh_exit_rmap_cmd
);
3298 install_element (RMAP_NODE
, &vtysh_quit_rmap_cmd
);
3299 install_element (VTY_NODE
, &vtysh_exit_line_vty_cmd
);
3300 install_element (VTY_NODE
, &vtysh_quit_line_vty_cmd
);
3302 /* "end" command. */
3303 install_element (CONFIG_NODE
, &vtysh_end_all_cmd
);
3304 install_element (ENABLE_NODE
, &vtysh_end_all_cmd
);
3305 install_element (RIP_NODE
, &vtysh_end_all_cmd
);
3306 install_element (RIPNG_NODE
, &vtysh_end_all_cmd
);
3307 install_element (OSPF_NODE
, &vtysh_end_all_cmd
);
3308 install_element (EIGRP_NODE
, &vtysh_end_all_cmd
);
3309 install_element (OSPF6_NODE
, &vtysh_end_all_cmd
);
3310 install_element (LDP_NODE
, &vtysh_end_all_cmd
);
3311 install_element (LDP_IPV4_NODE
, &vtysh_end_all_cmd
);
3312 install_element (LDP_IPV6_NODE
, &vtysh_end_all_cmd
);
3313 install_element (LDP_IPV4_IFACE_NODE
, &vtysh_end_all_cmd
);
3314 install_element (LDP_IPV6_IFACE_NODE
, &vtysh_end_all_cmd
);
3315 install_element (LDP_L2VPN_NODE
, &vtysh_end_all_cmd
);
3316 install_element (LDP_PSEUDOWIRE_NODE
, &vtysh_end_all_cmd
);
3317 install_element (BGP_NODE
, &vtysh_end_all_cmd
);
3318 install_element (BGP_IPV4_NODE
, &vtysh_end_all_cmd
);
3319 install_element (BGP_IPV4M_NODE
, &vtysh_end_all_cmd
);
3320 install_element (BGP_VPNV4_NODE
, &vtysh_end_all_cmd
);
3321 install_element (BGP_VPNV6_NODE
, &vtysh_end_all_cmd
);
3322 install_element (BGP_ENCAP_NODE
, &vtysh_end_all_cmd
);
3323 install_element (BGP_ENCAPV6_NODE
, &vtysh_end_all_cmd
);
3324 install_element (BGP_IPV6_NODE
, &vtysh_end_all_cmd
);
3325 install_element (BGP_IPV6M_NODE
, &vtysh_end_all_cmd
);
3326 install_element (BGP_VRF_POLICY_NODE
, &vtysh_end_all_cmd
);
3327 install_element (BGP_EVPN_NODE
, &vtysh_end_all_cmd
);
3328 install_element (BGP_VNC_DEFAULTS_NODE
, &vtysh_end_all_cmd
);
3329 install_element (BGP_VNC_NVE_GROUP_NODE
, &vtysh_end_all_cmd
);
3330 install_element (BGP_VNC_L2_GROUP_NODE
, &vtysh_end_all_cmd
);
3331 install_element (ISIS_NODE
, &vtysh_end_all_cmd
);
3332 install_element (KEYCHAIN_NODE
, &vtysh_end_all_cmd
);
3333 install_element (KEYCHAIN_KEY_NODE
, &vtysh_end_all_cmd
);
3334 install_element (RMAP_NODE
, &vtysh_end_all_cmd
);
3335 install_element (VTY_NODE
, &vtysh_end_all_cmd
);
3337 install_element (INTERFACE_NODE
, &vtysh_interface_desc_cmd
);
3338 install_element (INTERFACE_NODE
, &vtysh_no_interface_desc_cmd
);
3339 install_element (INTERFACE_NODE
, &vtysh_end_all_cmd
);
3340 install_element (INTERFACE_NODE
, &vtysh_exit_interface_cmd
);
3341 install_element (LINK_PARAMS_NODE
, &exit_link_params_cmd
);
3342 install_element (LINK_PARAMS_NODE
, &vtysh_end_all_cmd
);
3343 install_element (LINK_PARAMS_NODE
, &vtysh_exit_interface_cmd
);
3344 install_element (INTERFACE_NODE
, &vtysh_quit_interface_cmd
);
3346 install_element (NS_NODE
, &vtysh_end_all_cmd
);
3348 install_element (CONFIG_NODE
, &vtysh_ns_cmd
);
3349 install_element (NS_NODE
, &vtysh_exit_ns_cmd
);
3350 install_element (NS_NODE
, &vtysh_quit_ns_cmd
);
3352 install_element (VRF_NODE
, &vtysh_end_all_cmd
);
3353 install_element (VRF_NODE
, &vtysh_exit_vrf_cmd
);
3354 install_element (VRF_NODE
, &vtysh_quit_vrf_cmd
);
3356 install_element (CONFIG_NODE
, &router_eigrp_cmd
);
3357 install_element (CONFIG_NODE
, &router_rip_cmd
);
3358 install_element (CONFIG_NODE
, &router_ripng_cmd
);
3359 install_element (CONFIG_NODE
, &router_ospf_cmd
);
3360 install_element (CONFIG_NODE
, &router_ospf6_cmd
);
3361 #if defined (HAVE_LDPD)
3362 install_element (CONFIG_NODE
, &ldp_mpls_ldp_cmd
);
3363 install_element (LDP_NODE
, &ldp_address_family_ipv4_cmd
);
3364 install_element (LDP_NODE
, &ldp_address_family_ipv6_cmd
);
3365 install_element (LDP_IPV4_NODE
, &ldp_interface_ifname_cmd
);
3366 install_element (LDP_IPV6_NODE
, &ldp_interface_ifname_cmd
);
3367 install_element (CONFIG_NODE
, &ldp_l2vpn_word_type_vpls_cmd
);
3368 install_element (LDP_L2VPN_NODE
, &ldp_member_pseudowire_ifname_cmd
);
3370 install_element (CONFIG_NODE
, &router_isis_cmd
);
3371 install_element (CONFIG_NODE
, &router_bgp_cmd
);
3372 install_element (BGP_NODE
, &address_family_vpnv4_cmd
);
3373 install_element (BGP_NODE
, &address_family_vpnv6_cmd
);
3374 install_element (BGP_NODE
, &address_family_encapv4_cmd
);
3375 install_element (BGP_NODE
, &address_family_encapv6_cmd
);
3376 #if defined(ENABLE_BGP_VNC)
3377 install_element (BGP_NODE
, &vnc_vrf_policy_cmd
);
3378 install_element (BGP_NODE
, &vnc_defaults_cmd
);
3379 install_element (BGP_NODE
, &vnc_nve_group_cmd
);
3380 install_element (BGP_NODE
, &vnc_l2_group_cmd
);
3382 install_element (BGP_NODE
, &address_family_ipv4_unicast_cmd
);
3383 install_element (BGP_NODE
, &address_family_ipv6_cmd
);
3384 install_element (BGP_NODE
, &address_family_evpn_cmd
);
3385 install_element (BGP_VPNV4_NODE
, &exit_address_family_cmd
);
3386 install_element (BGP_VPNV6_NODE
, &exit_address_family_cmd
);
3387 install_element (BGP_ENCAP_NODE
, &exit_address_family_cmd
);
3388 install_element (BGP_ENCAPV6_NODE
, &exit_address_family_cmd
);
3389 install_element (BGP_IPV4_NODE
, &exit_address_family_cmd
);
3390 install_element (BGP_IPV4M_NODE
, &exit_address_family_cmd
);
3391 install_element (BGP_IPV6_NODE
, &exit_address_family_cmd
);
3392 install_element (BGP_IPV6M_NODE
, &exit_address_family_cmd
);
3393 install_element (BGP_EVPN_NODE
, &exit_address_family_cmd
);
3395 install_element (BGP_VRF_POLICY_NODE
, &exit_vrf_policy_cmd
);
3396 install_element (BGP_VNC_DEFAULTS_NODE
, &exit_vnc_config_cmd
);
3397 install_element (BGP_VNC_NVE_GROUP_NODE
, &exit_vnc_config_cmd
);
3398 install_element (BGP_VNC_L2_GROUP_NODE
, &exit_vnc_config_cmd
);
3400 install_element (CONFIG_NODE
, &key_chain_cmd
);
3401 install_element (CONFIG_NODE
, &vtysh_route_map_cmd
);
3402 install_element (CONFIG_NODE
, &vtysh_line_vty_cmd
);
3403 install_element (KEYCHAIN_NODE
, &key_cmd
);
3404 install_element (KEYCHAIN_NODE
, &key_chain_cmd
);
3405 install_element (KEYCHAIN_KEY_NODE
, &key_chain_cmd
);
3406 install_element (CONFIG_NODE
, &vtysh_interface_cmd
);
3407 install_element (CONFIG_NODE
, &vtysh_no_interface_cmd
);
3408 install_element (CONFIG_NODE
, &vtysh_no_interface_vrf_cmd
);
3409 install_element (INTERFACE_NODE
, &vtysh_link_params_cmd
);
3410 install_element (ENABLE_NODE
, &vtysh_show_running_config_cmd
);
3411 install_element (ENABLE_NODE
, &vtysh_copy_running_config_cmd
);
3413 install_element (CONFIG_NODE
, &vtysh_vrf_cmd
);
3414 install_element (CONFIG_NODE
, &vtysh_no_vrf_cmd
);
3416 /* "write terminal" command. */
3417 install_element (ENABLE_NODE
, &vtysh_write_terminal_cmd
);
3419 install_element (CONFIG_NODE
, &vtysh_integrated_config_cmd
);
3420 install_element (CONFIG_NODE
, &no_vtysh_integrated_config_cmd
);
3422 /* "write memory" command. */
3423 install_element (ENABLE_NODE
, &vtysh_write_memory_cmd
);
3425 install_element (VIEW_NODE
, &vtysh_terminal_length_cmd
);
3426 install_element (VIEW_NODE
, &vtysh_terminal_no_length_cmd
);
3427 install_element (VIEW_NODE
, &vtysh_show_daemons_cmd
);
3429 install_element (VIEW_NODE
, &vtysh_ping_cmd
);
3430 install_element (VIEW_NODE
, &vtysh_ping_ip_cmd
);
3431 install_element (VIEW_NODE
, &vtysh_traceroute_cmd
);
3432 install_element (VIEW_NODE
, &vtysh_traceroute_ip_cmd
);
3433 install_element (VIEW_NODE
, &vtysh_ping6_cmd
);
3434 install_element (VIEW_NODE
, &vtysh_traceroute6_cmd
);
3435 #if defined(HAVE_SHELL_ACCESS)
3436 install_element (VIEW_NODE
, &vtysh_telnet_cmd
);
3437 install_element (VIEW_NODE
, &vtysh_telnet_port_cmd
);
3438 install_element (VIEW_NODE
, &vtysh_ssh_cmd
);
3440 #if defined(HAVE_SHELL_ACCESS)
3441 install_element (ENABLE_NODE
, &vtysh_start_shell_cmd
);
3442 install_element (ENABLE_NODE
, &vtysh_start_bash_cmd
);
3443 install_element (ENABLE_NODE
, &vtysh_start_zsh_cmd
);
3446 install_element (VIEW_NODE
, &vtysh_show_memory_cmd
);
3447 install_element (VIEW_NODE
, &vtysh_show_modules_cmd
);
3449 install_element (VIEW_NODE
, &vtysh_show_work_queues_cmd
);
3450 install_element (VIEW_NODE
, &vtysh_show_work_queues_daemon_cmd
);
3452 install_element (VIEW_NODE
, &vtysh_show_thread_cmd
);
3455 install_element (VIEW_NODE
, &vtysh_show_logging_cmd
);
3456 install_element (CONFIG_NODE
, &vtysh_log_stdout_cmd
);
3457 install_element (CONFIG_NODE
, &vtysh_log_stdout_level_cmd
);
3458 install_element (CONFIG_NODE
, &no_vtysh_log_stdout_cmd
);
3459 install_element (CONFIG_NODE
, &vtysh_log_file_cmd
);
3460 install_element (CONFIG_NODE
, &vtysh_log_file_level_cmd
);
3461 install_element (CONFIG_NODE
, &no_vtysh_log_file_cmd
);
3462 install_element (CONFIG_NODE
, &vtysh_log_monitor_cmd
);
3463 install_element (CONFIG_NODE
, &no_vtysh_log_monitor_cmd
);
3464 install_element (CONFIG_NODE
, &vtysh_log_syslog_cmd
);
3465 install_element (CONFIG_NODE
, &no_vtysh_log_syslog_cmd
);
3466 install_element (CONFIG_NODE
, &vtysh_log_trap_cmd
);
3467 install_element (CONFIG_NODE
, &no_vtysh_log_trap_cmd
);
3468 install_element (CONFIG_NODE
, &vtysh_log_facility_cmd
);
3469 install_element (CONFIG_NODE
, &no_vtysh_log_facility_cmd
);
3470 install_element (CONFIG_NODE
, &vtysh_log_record_priority_cmd
);
3471 install_element (CONFIG_NODE
, &no_vtysh_log_record_priority_cmd
);
3472 install_element (CONFIG_NODE
, &vtysh_log_timestamp_precision_cmd
);
3473 install_element (CONFIG_NODE
, &no_vtysh_log_timestamp_precision_cmd
);
3475 install_element (CONFIG_NODE
, &vtysh_service_password_encrypt_cmd
);
3476 install_element (CONFIG_NODE
, &no_vtysh_service_password_encrypt_cmd
);
3478 install_element (CONFIG_NODE
, &vtysh_password_cmd
);
3479 install_element (CONFIG_NODE
, &vtysh_password_text_cmd
);
3480 install_element (CONFIG_NODE
, &vtysh_enable_password_cmd
);
3481 install_element (CONFIG_NODE
, &vtysh_enable_password_text_cmd
);
3482 install_element (CONFIG_NODE
, &no_vtysh_enable_password_cmd
);