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>
39 #include "vtysh/vtysh.h"
41 #include "bgpd/bgp_vty.h"
46 /* VTY shell pager name. */
47 char *vtysh_pager_name
= NULL
;
49 /* VTY shell client structure. */
56 struct vtysh_client
*next
;
59 struct vtysh_client vtysh_client
[] =
61 { .fd
= -1, .name
= "zebra", .flag
= VTYSH_ZEBRA
, .path
= ZEBRA_VTYSH_PATH
, .next
= NULL
},
62 { .fd
= -1, .name
= "ripd", .flag
= VTYSH_RIPD
, .path
= RIP_VTYSH_PATH
, .next
= NULL
},
63 { .fd
= -1, .name
= "ripngd", .flag
= VTYSH_RIPNGD
, .path
= RIPNG_VTYSH_PATH
, .next
= NULL
},
64 { .fd
= -1, .name
= "ospfd", .flag
= VTYSH_OSPFD
, .path
= OSPF_VTYSH_PATH
, .next
= NULL
},
65 { .fd
= -1, .name
= "ospf6d", .flag
= VTYSH_OSPF6D
, .path
= OSPF6_VTYSH_PATH
, .next
= NULL
},
66 { .fd
= -1, .name
= "bgpd", .flag
= VTYSH_BGPD
, .path
= BGP_VTYSH_PATH
, .next
= NULL
},
67 { .fd
= -1, .name
= "isisd", .flag
= VTYSH_ISISD
, .path
= ISIS_VTYSH_PATH
, .next
= NULL
},
68 { .fd
= -1, .name
= "babeld", .flag
= VTYSH_BABELD
, .path
= BABEL_VTYSH_PATH
, .next
= NULL
},
72 * Compiler is warning about prototypes not being declared.
73 * The DEFUNSH and DEFUN macro's are messing with the
74 * compiler I believe. This is just to make it happy.
77 int vtysh_rl_describe(void);
78 void vtysh_exit_ripd_only(void);
79 int vtysh_connect_all_instances(struct vtysh_client
*);
82 /* We need direct access to ripd to implement vtysh_exit_ripd_only. */
83 static struct vtysh_client
*ripd_client
= NULL
;
86 /* Using integrated config from Quagga.conf. Default is no. */
87 int vtysh_writeconfig_integrated
= 0;
89 extern char config_default
[];
92 vclient_close (struct vtysh_client
*vclient
)
97 "Warning: closing connection to %s because of an I/O error!\n",
104 /* Following filled with debug code to trace a problematic condition
105 * under load - it SHOULD handle it. */
106 #define ERR_WHERE_STRING "vtysh(): vtysh_client_config(): "
108 vtysh_client_config_one (struct vtysh_client
*vclient
, char *line
)
123 ret
= write (vclient
->fd
, line
, strlen (line
) + 1);
126 vclient_close (vclient
);
130 /* Allow enough room for buffer to read more than a few pages from socket. */
131 bufsz
= 5 * getpagesize() + 1;
132 buf
= XMALLOC(MTYPE_TMP
, bufsz
);
133 memset(buf
, 0, bufsz
);
138 if (pbuf
>= ((buf
+ bufsz
) -1))
140 fprintf (stderr
, ERR_WHERE_STRING \
141 "warning - pbuf beyond buffer end.\n");
145 readln
= (buf
+ bufsz
) - pbuf
- 1;
146 nbytes
= read (vclient
->fd
, pbuf
, readln
);
154 fprintf(stderr
, ERR_WHERE_STRING
"(%u)", errno
);
157 if (errno
== EAGAIN
|| errno
== EIO
)
160 vclient_close (vclient
);
161 XFREE(MTYPE_TMP
, buf
);
170 if (pbuf
[i
] == '\0' && pbuf
[i
+ 1] == '\0' && pbuf
[i
+ 2] == '\0')
178 /* See if a line exists in buffer, if so parse and consume it, and
179 * reset read position. */
180 if ((eoln
= strrchr(buf
, '\n')) == NULL
)
183 if (eoln
>= ((buf
+ bufsz
) - 1))
185 fprintf (stderr
, ERR_WHERE_STRING \
186 "warning - eoln beyond buffer end.\n");
188 vtysh_config_parse(buf
);
191 left
= (size_t)(buf
+ bufsz
- eoln
);
192 memmove(buf
, eoln
, left
);
194 pbuf
= buf
+ strlen(buf
);
197 /* Parse anything left in the buffer. */
199 vtysh_config_parse (buf
);
201 XFREE(MTYPE_TMP
, buf
);
206 vtysh_client_config (struct vtysh_client
*head_client
, char *line
)
208 struct vtysh_client
*client
;
211 rc
= vtysh_client_config_one(head_client
, line
);
212 if (rc
!= CMD_SUCCESS
)
215 client
= head_client
->next
;
218 rc
= vtysh_client_config_one(client
, line
);
219 if (rc
!= CMD_SUCCESS
)
221 client
= client
->next
;
227 vtysh_client_execute_one (struct vtysh_client
*vclient
, const char *line
, FILE *fp
)
238 ret
= write (vclient
->fd
, line
, strlen (line
) + 1);
241 vclient_close (vclient
);
247 nbytes
= read (vclient
->fd
, buf
, sizeof(buf
)-1);
249 if (nbytes
<= 0 && errno
!= EINTR
)
251 vclient_close (vclient
);
257 if ((numnulls
== 3) && (nbytes
== 1))
264 /* check for trailling \0\0\0<ret code>,
265 * even if split across reads
266 * (see lib/vty.c::vtysh_read)
276 while (i
< nbytes
&& numnulls
< 3)
278 if (buf
[i
++] == '\0')
284 /* got 3 or more trailing NULs? */
285 if ((numnulls
>= 3) && (i
< nbytes
))
286 return (buf
[nbytes
-1]);
292 vtysh_client_execute (struct vtysh_client
*head_client
, const char *line
, FILE *fp
)
294 struct vtysh_client
*client
;
297 rc
= vtysh_client_execute_one(head_client
, line
, fp
);
298 if (rc
!= CMD_SUCCESS
)
301 client
= head_client
->next
;
304 rc
= vtysh_client_execute_one(client
, line
, fp
);
305 if (rc
!= CMD_SUCCESS
)
307 client
= client
->next
;
313 vtysh_exit_ripd_only (void)
316 vtysh_client_execute (ripd_client
, "exit", stdout
);
321 vtysh_pager_init (void)
325 pager_defined
= getenv ("VTYSH_PAGER");
328 vtysh_pager_name
= strdup (pager_defined
);
330 vtysh_pager_name
= strdup ("more");
333 /* Command execution over the vty interface. */
335 vtysh_execute_func (const char *line
, int pager
)
340 struct cmd_element
*cmd
;
344 int saved_ret
, saved_node
;
346 /* Split readline string up into the vector. */
347 vline
= cmd_make_strvec (line
);
352 saved_ret
= ret
= cmd_execute_command (vline
, vty
, &cmd
, 1);
353 saved_node
= vty
->node
;
355 /* If command doesn't succeeded in current node, try to walk up in node tree.
356 * Changing vty->node is enough to try it just out without actual walkup in
358 while (ret
!= CMD_SUCCESS
&& ret
!= CMD_SUCCESS_DAEMON
&& ret
!= CMD_WARNING
359 && vty
->node
> CONFIG_NODE
)
361 vty
->node
= node_parent(vty
->node
);
362 ret
= cmd_execute_command (vline
, vty
, &cmd
, 1);
366 vty
->node
= saved_node
;
368 /* If command succeeded in any other node than current (tried > 0) we have
369 * to move into node in the vtysh where it succeeded. */
370 if (ret
== CMD_SUCCESS
|| ret
== CMD_SUCCESS_DAEMON
|| ret
== CMD_WARNING
)
372 if ((saved_node
== BGP_VPNV4_NODE
|| saved_node
== BGP_IPV4_NODE
373 || saved_node
== BGP_IPV6_NODE
|| saved_node
== BGP_IPV4M_NODE
374 || saved_node
== BGP_IPV6M_NODE
)
377 vtysh_execute("exit-address-family");
379 else if ((saved_node
== KEYCHAIN_KEY_NODE
) && (tried
== 1))
381 vtysh_execute("exit");
385 vtysh_execute ("end");
386 vtysh_execute ("configure terminal");
389 /* If command didn't succeed in any node, continue with return value from
396 cmd_free_strvec (vline
);
402 if (vty
->type
== VTY_FILE
)
403 fprintf (stdout
,"Warning...\n");
405 case CMD_ERR_AMBIGUOUS
:
406 fprintf (stdout
,"%% Ambiguous command.\n");
408 case CMD_ERR_NO_MATCH
:
409 fprintf (stdout
,"%% Unknown command.\n");
411 case CMD_ERR_INCOMPLETE
:
412 fprintf (stdout
,"%% Command incomplete.\n");
414 case CMD_SUCCESS_DAEMON
:
416 /* FIXME: Don't open pager for exit commands. popen() causes problems
417 * if exited from vtysh at all. This hack shouldn't cause any problem
418 * but is really ugly. */
419 if (pager
&& vtysh_pager_name
&& (strncmp(line
, "exit", 4) != 0))
421 fp
= popen (vtysh_pager_name
, "w");
424 perror ("popen failed for pager");
433 if (! strcmp(cmd
->string
,"configure terminal"))
435 for (i
= 0; i
< array_size(vtysh_client
); i
++)
437 cmd_stat
= vtysh_client_execute(&vtysh_client
[i
], line
, fp
);
438 if (cmd_stat
== CMD_WARNING
)
445 vline
= cmd_make_strvec (line
);
449 if (pager
&& vtysh_pager_name
&& fp
&& closepager
)
451 if (pclose (fp
) == -1)
453 perror ("pclose failed for pager");
460 ret
= cmd_execute_command (vline
, vty
, &cmd
, 1);
461 cmd_free_strvec (vline
);
462 if (ret
!= CMD_SUCCESS_DAEMON
)
468 (*cmd
->func
) (cmd
, vty
, 0, NULL
);
473 cmd_stat
= CMD_SUCCESS
;
474 for (i
= 0; i
< array_size(vtysh_client
); i
++)
476 if (cmd
->daemon
& vtysh_client
[i
].flag
)
478 cmd_stat
= vtysh_client_execute(&vtysh_client
[i
], line
, fp
);
479 if (cmd_stat
!= CMD_SUCCESS
)
483 if (cmd_stat
!= CMD_SUCCESS
)
487 (*cmd
->func
) (cmd
, vty
, 0, NULL
);
490 if (pager
&& vtysh_pager_name
&& fp
&& closepager
)
492 if (pclose (fp
) == -1)
494 perror ("pclose failed for pager");
502 vtysh_execute_no_pager (const char *line
)
504 return vtysh_execute_func (line
, 0);
508 vtysh_execute (const char *line
)
510 return vtysh_execute_func (line
, 1);
514 vtysh_mark_file (const char *filename
)
521 struct cmd_element
*cmd
;
522 int saved_ret
, prev_node
;
525 if (strncmp("-", filename
, 1) == 0)
528 confp
= fopen (filename
, "r");
534 vty
->fd
= 0; /* stdout */
535 vty
->type
= VTY_TERM
;
536 vty
->node
= CONFIG_NODE
;
538 vtysh_execute_no_pager ("enable");
539 vtysh_execute_no_pager ("configure terminal");
541 while (fgets (vty
->buf
, VTY_BUFSIZ
, confp
))
546 if (vty
->buf
[0] == '!' || vty
->buf
[1] == '#')
548 fprintf(stdout
, "%s", vty
->buf
);
552 /* Split readline string up into the vector. */
553 vline
= cmd_make_strvec (vty
->buf
);
557 fprintf(stdout
, "%s", vty
->buf
);
561 prev_node
= vty
->node
;
562 saved_ret
= ret
= cmd_execute_command_strict (vline
, vty
, &cmd
);
564 /* If command doesn't succeeded in current node, try to walk up in node tree.
565 * Changing vty->node is enough to try it just out without actual walkup in
567 while (ret
!= CMD_SUCCESS
&& ret
!= CMD_SUCCESS_DAEMON
&& ret
!= CMD_WARNING
568 && vty
->node
> CONFIG_NODE
)
570 vty
->node
= node_parent(vty
->node
);
571 ret
= cmd_execute_command_strict (vline
, vty
, &cmd
);
575 /* If command succeeded in any other node than current (tried > 0) we have
576 * to move into node in the vtysh where it succeeded. */
577 if (ret
== CMD_SUCCESS
|| ret
== CMD_SUCCESS_DAEMON
|| ret
== CMD_WARNING
)
579 if ((prev_node
== BGP_VPNV4_NODE
|| prev_node
== BGP_IPV4_NODE
580 || prev_node
== BGP_IPV6_NODE
|| prev_node
== BGP_IPV4M_NODE
581 || prev_node
== BGP_IPV6M_NODE
)
584 fprintf(stdout
, "exit-address-family\n");
586 else if ((prev_node
== KEYCHAIN_KEY_NODE
) && (tried
== 1))
588 fprintf(stdout
, "exit\n");
592 fprintf(stdout
, "end\n");
595 /* If command didn't succeed in any node, continue with return value from
600 vty
->node
= prev_node
;
603 cmd_free_strvec (vline
);
607 if (vty
->type
== VTY_FILE
)
608 fprintf (stderr
,"line %d: Warning...: %s\n", lineno
, vty
->buf
);
612 case CMD_ERR_AMBIGUOUS
:
613 fprintf (stderr
,"line %d: %% Ambiguous command: %s\n", lineno
, vty
->buf
);
617 case CMD_ERR_NO_MATCH
:
618 fprintf (stderr
,"line %d: %% Unknown command: %s\n", lineno
, vty
->buf
);
622 case CMD_ERR_INCOMPLETE
:
623 fprintf (stderr
,"line %d: %% Command incomplete: %s\n", lineno
, vty
->buf
);
628 fprintf(stdout
, "%s", vty
->buf
);
630 case CMD_SUCCESS_DAEMON
:
633 int cmd_stat
= CMD_SUCCESS
;
635 fprintf(stdout
, "%s", vty
->buf
);
636 for (i
= 0; i
< array_size(vtysh_client
); i
++)
638 if (cmd
->daemon
& vtysh_client
[i
].flag
)
640 cmd_stat
= vtysh_client_execute (&vtysh_client
[i
],
642 if (cmd_stat
!= CMD_SUCCESS
)
646 if (cmd_stat
!= CMD_SUCCESS
)
650 (*cmd
->func
) (cmd
, vty
, 0, NULL
);
654 /* This is the end */
655 fprintf(stdout
, "end\n");
664 /* Configration make from file. */
666 vtysh_config_from_file (struct vty
*vty
, FILE *fp
)
670 struct cmd_element
*cmd
;
671 int save_node
= CONFIG_NODE
;
673 while (fgets (vty
->buf
, VTY_BUFSIZ
, fp
))
675 if (vty
->buf
[0] == '!' || vty
->buf
[1] == '#')
678 vline
= cmd_make_strvec (vty
->buf
);
680 /* In case of comment line. */
684 /* Execute configuration command : this is strict match. */
685 ret
= cmd_execute_command_strict (vline
, vty
, &cmd
);
687 /* Try again with setting node to CONFIG_NODE. */
688 if (ret
!= CMD_SUCCESS
689 && ret
!= CMD_SUCCESS_DAEMON
690 && ret
!= CMD_WARNING
)
692 if (vty
->node
== KEYCHAIN_KEY_NODE
)
694 vty
->node
= KEYCHAIN_NODE
;
695 vtysh_exit_ripd_only ();
696 ret
= cmd_execute_command_strict (vline
, vty
, &cmd
);
698 if (ret
!= CMD_SUCCESS
699 && ret
!= CMD_SUCCESS_DAEMON
700 && ret
!= CMD_WARNING
)
702 vtysh_exit_ripd_only ();
703 vty
->node
= CONFIG_NODE
;
704 ret
= cmd_execute_command_strict (vline
, vty
, &cmd
);
709 save_node
= vty
->node
;
710 vtysh_execute ("end");
711 vtysh_execute ("configure terminal");
712 vty
->node
= CONFIG_NODE
;
713 ret
= cmd_execute_command_strict (vline
, vty
, &cmd
);
714 if ((ret
!= CMD_SUCCESS
) &&
715 (ret
!= CMD_SUCCESS_DAEMON
) &&
716 (ret
!= CMD_WARNING
))
717 vty
->node
= save_node
;
721 cmd_free_strvec (vline
);
726 if (vty
->type
== VTY_FILE
)
727 fprintf (stdout
,"Warning...\n");
729 case CMD_ERR_AMBIGUOUS
:
730 fprintf (stdout
,"%% Ambiguous command: %s\n", vty
->buf
);
732 case CMD_ERR_NO_MATCH
:
733 fprintf (stdout
,"%% Unknown command: %s", vty
->buf
);
735 case CMD_ERR_INCOMPLETE
:
736 fprintf (stdout
,"%% Command incomplete: %s\n", vty
->buf
);
738 case CMD_SUCCESS_DAEMON
:
741 int cmd_stat
= CMD_SUCCESS
;
743 for (i
= 0; i
< array_size(vtysh_client
); i
++)
745 if (cmd
->daemon
& vtysh_client
[i
].flag
)
747 cmd_stat
= vtysh_client_execute (&vtysh_client
[i
],
749 if (cmd_stat
!= CMD_SUCCESS
)
753 if (cmd_stat
!= CMD_SUCCESS
)
757 (*cmd
->func
) (cmd
, vty
, 0, NULL
);
764 /* We don't care about the point of the cursor when '?' is typed. */
766 vtysh_rl_describe (void)
773 struct cmd_token
*token
;
775 vline
= cmd_make_strvec (rl_line_buffer
);
777 /* In case of '> ?'. */
780 vline
= vector_init (1);
781 vector_set (vline
, '\0');
784 if (rl_end
&& isspace ((int) rl_line_buffer
[rl_end
- 1]))
785 vector_set (vline
, '\0');
787 describe
= cmd_describe_command (vline
, vty
, &ret
);
789 fprintf (stdout
,"\n");
791 /* Ambiguous and no match error. */
794 case CMD_ERR_AMBIGUOUS
:
795 cmd_free_strvec (vline
);
796 fprintf (stdout
,"%% Ambiguous command.\n");
800 case CMD_ERR_NO_MATCH
:
801 cmd_free_strvec (vline
);
802 fprintf (stdout
,"%% There is no matched command.\n");
808 /* Get width of command string. */
810 for (i
= 0; i
< vector_active (describe
); i
++)
811 if ((token
= vector_slot (describe
, i
)) != NULL
)
815 if (token
->cmd
[0] == '\0')
818 len
= strlen (token
->cmd
);
819 if (token
->cmd
[0] == '.')
826 for (i
= 0; i
< vector_active (describe
); i
++)
827 if ((token
= vector_slot (describe
, i
)) != NULL
)
829 if (token
->cmd
[0] == '\0')
833 fprintf (stdout
," %-s\n",
834 token
->cmd
[0] == '.' ? token
->cmd
+ 1 : token
->cmd
);
836 fprintf (stdout
," %-*s %s\n",
838 token
->cmd
[0] == '.' ? token
->cmd
+ 1 : token
->cmd
,
842 cmd_free_strvec (vline
);
843 vector_free (describe
);
850 /* Result of cmd_complete_command() call will be stored here
851 * and used in new_completion() in order to put the space in
852 * correct places only. */
856 command_generator (const char *text
, int state
)
859 static char **matched
= NULL
;
860 static int index
= 0;
867 if (vty
->node
== AUTH_NODE
|| vty
->node
== AUTH_ENABLE_NODE
)
870 vline
= cmd_make_strvec (rl_line_buffer
);
874 if (rl_end
&& isspace ((int) rl_line_buffer
[rl_end
- 1]))
875 vector_set (vline
, '\0');
877 matched
= cmd_complete_command (vline
, vty
, &complete_status
);
880 if (matched
&& matched
[index
])
881 return matched
[index
++];
887 new_completion (char *text
, int start
, int end
)
891 matches
= rl_completion_matches (text
, command_generator
);
896 if (complete_status
!= CMD_COMPLETE_FULL_MATCH
)
897 /* only append a space on full match */
898 rl_completion_append_character
= '\0';
905 /* This function is not actually being used. */
907 vtysh_completion (char *text
, int start
, int end
)
911 char **matched
= NULL
;
913 if (vty
->node
== AUTH_NODE
|| vty
->node
== AUTH_ENABLE_NODE
)
916 vline
= cmd_make_strvec (rl_line_buffer
);
920 /* In case of 'help \t'. */
921 if (rl_end
&& isspace ((int) rl_line_buffer
[rl_end
- 1]))
922 vector_set (vline
, '\0');
924 matched
= cmd_complete_command (vline
, vty
, &ret
);
926 cmd_free_strvec (vline
);
928 return (char **) matched
;
932 /* Vty node structures. */
933 static struct cmd_node bgp_node
=
936 "%s(config-router)# ",
939 static struct cmd_node rip_node
=
942 "%s(config-router)# ",
945 static struct cmd_node isis_node
=
948 "%s(config-router)# ",
951 static struct cmd_node interface_node
=
957 static struct cmd_node rmap_node
=
960 "%s(config-route-map)# "
963 static struct cmd_node zebra_node
=
966 "%s(config-router)# "
969 static struct cmd_node bgp_vpnv4_node
=
972 "%s(config-router-af)# "
975 static struct cmd_node bgp_ipv4_node
=
978 "%s(config-router-af)# "
981 static struct cmd_node bgp_ipv4m_node
=
984 "%s(config-router-af)# "
987 static struct cmd_node bgp_ipv6_node
=
990 "%s(config-router-af)# "
993 static struct cmd_node bgp_ipv6m_node
=
996 "%s(config-router-af)# "
999 static struct cmd_node ospf_node
=
1002 "%s(config-router)# "
1005 static struct cmd_node ripng_node
=
1008 "%s(config-router)# "
1011 static struct cmd_node ospf6_node
=
1014 "%s(config-ospf6)# "
1017 static struct cmd_node babel_node
=
1020 "%s(config-babel)# "
1023 static struct cmd_node keychain_node
=
1026 "%s(config-keychain)# "
1029 static struct cmd_node keychain_key_node
=
1032 "%s(config-keychain-key)# "
1035 /* Defined in lib/vty.c */
1036 extern struct cmd_node vty_node
;
1038 /* When '^Z' is received from vty, move down to the enable mode. */
1046 /* Nothing to do. */
1049 vty
->node
= ENABLE_NODE
;
1059 "End current mode and change to enable mode\n")
1061 return vtysh_end ();
1064 DEFUNSH (VTYSH_BGPD
,
1067 "router bgp " CMD_AS_RANGE
,
1072 vty
->node
= BGP_NODE
;
1076 ALIAS_SH (VTYSH_BGPD
,
1078 router_bgp_view_cmd
,
1079 "router bgp " CMD_AS_RANGE
" view WORD",
1086 DEFUNSH (VTYSH_BGPD
,
1087 address_family_vpnv4
,
1088 address_family_vpnv4_cmd
,
1089 "address-family vpnv4",
1090 "Enter Address Family command mode\n"
1093 vty
->node
= BGP_VPNV4_NODE
;
1097 DEFUNSH (VTYSH_BGPD
,
1098 address_family_vpnv4_unicast
,
1099 address_family_vpnv4_unicast_cmd
,
1100 "address-family vpnv4 unicast",
1101 "Enter Address Family command mode\n"
1103 "Address Family Modifier\n")
1105 vty
->node
= BGP_VPNV4_NODE
;
1109 DEFUNSH (VTYSH_BGPD
,
1110 address_family_ipv4_unicast
,
1111 address_family_ipv4_unicast_cmd
,
1112 "address-family ipv4 unicast",
1113 "Enter Address Family command mode\n"
1115 "Address Family Modifier\n")
1117 vty
->node
= BGP_IPV4_NODE
;
1121 DEFUNSH (VTYSH_BGPD
,
1122 address_family_ipv4_multicast
,
1123 address_family_ipv4_multicast_cmd
,
1124 "address-family ipv4 multicast",
1125 "Enter Address Family command mode\n"
1127 "Address Family Modifier\n")
1129 vty
->node
= BGP_IPV4M_NODE
;
1133 DEFUNSH (VTYSH_BGPD
,
1134 address_family_ipv6
,
1135 address_family_ipv6_cmd
,
1136 "address-family ipv6",
1137 "Enter Address Family command mode\n"
1140 vty
->node
= BGP_IPV6_NODE
;
1144 DEFUNSH (VTYSH_BGPD
,
1145 address_family_ipv6_unicast
,
1146 address_family_ipv6_unicast_cmd
,
1147 "address-family ipv6 unicast",
1148 "Enter Address Family command mode\n"
1150 "Address Family Modifier\n")
1152 vty
->node
= BGP_IPV6_NODE
;
1156 DEFUNSH (VTYSH_BGPD
,
1157 address_family_ipv6_multicast
,
1158 address_family_ipv6_multicast_cmd
,
1159 "address-family ipv6 multicast",
1160 "Enter Address Family command mode\n"
1162 "Address Family Modifier\n")
1164 vty
->node
= BGP_IPV6M_NODE
;
1168 DEFUNSH (VTYSH_RIPD
,
1172 "Authentication key management\n"
1173 "Key-chain management\n"
1176 vty
->node
= KEYCHAIN_NODE
;
1180 DEFUNSH (VTYSH_RIPD
,
1183 "key <0-2147483647>",
1185 "Key identifier number\n")
1187 vty
->node
= KEYCHAIN_KEY_NODE
;
1191 DEFUNSH (VTYSH_RIPD
,
1198 vty
->node
= RIP_NODE
;
1202 DEFUNSH (VTYSH_RIPNGD
,
1209 vty
->node
= RIPNG_NODE
;
1213 DEFUNSH (VTYSH_OSPFD
,
1217 "Enable a routing process\n"
1218 "Start OSPF configuration\n")
1220 vty
->node
= OSPF_NODE
;
1224 ALIAS_SH (VTYSH_OSPFD
,
1226 router_ospf_instance_cmd
,
1227 "router ospf <1-65535>",
1228 "Enable a routing process\n"
1229 "Start OSPF configuration\n"
1232 DEFUNSH (VTYSH_OSPF6D
,
1239 vty
->node
= OSPF6_NODE
;
1243 DEFUNSH (VTYSH_BABELD
,
1250 vty
->node
= BABEL_NODE
;
1254 DEFUNSH (VTYSH_ISISD
,
1260 "ISO Routing area tag")
1262 vty
->node
= ISIS_NODE
;
1266 DEFUNSH (VTYSH_RMAP
,
1269 "route-map WORD (deny|permit) <1-65535>",
1270 "Create route-map or enter route-map command mode\n"
1272 "Route map denies set operations\n"
1273 "Route map permits set operations\n"
1274 "Sequence to insert to/delete from existing route-map entry\n")
1276 vty
->node
= RMAP_NODE
;
1284 "Configure a terminal line\n"
1285 "Virtual terminal\n")
1287 vty
->node
= VTY_NODE
;
1295 "Turn on privileged mode command\n")
1297 vty
->node
= ENABLE_NODE
;
1305 "Turn off privileged mode command\n")
1307 if (vty
->node
== ENABLE_NODE
)
1308 vty
->node
= VIEW_NODE
;
1313 vtysh_config_terminal
,
1314 vtysh_config_terminal_cmd
,
1315 "configure terminal",
1316 "Configuration from vty interface\n"
1317 "Configuration terminal\n")
1319 vty
->node
= CONFIG_NODE
;
1324 vtysh_exit (struct vty
*vty
)
1333 vty
->node
= ENABLE_NODE
;
1335 case INTERFACE_NODE
:
1348 vtysh_execute("end");
1349 vtysh_execute("configure terminal");
1350 vty
->node
= CONFIG_NODE
;
1352 case BGP_VPNV4_NODE
:
1354 case BGP_IPV4M_NODE
:
1356 case BGP_IPV6M_NODE
:
1357 vty
->node
= BGP_NODE
;
1359 case KEYCHAIN_KEY_NODE
:
1360 vty
->node
= KEYCHAIN_NODE
;
1372 "Exit current mode and down to previous mode\n")
1374 return vtysh_exit (vty
);
1377 ALIAS (vtysh_exit_all
,
1380 "Exit current mode and down to previous mode\n")
1382 DEFUNSH (VTYSH_BGPD
,
1383 exit_address_family
,
1384 exit_address_family_cmd
,
1385 "exit-address-family",
1386 "Exit from Address Family configuration mode\n")
1388 if (vty
->node
== BGP_IPV4_NODE
1389 || vty
->node
== BGP_IPV4M_NODE
1390 || vty
->node
== BGP_VPNV4_NODE
1391 || vty
->node
== BGP_IPV6_NODE
1392 || vty
->node
== BGP_IPV6M_NODE
)
1393 vty
->node
= BGP_NODE
;
1397 DEFUNSH (VTYSH_ZEBRA
,
1399 vtysh_exit_zebra_cmd
,
1401 "Exit current mode and down to previous mode\n")
1403 return vtysh_exit (vty
);
1406 ALIAS (vtysh_exit_zebra
,
1407 vtysh_quit_zebra_cmd
,
1409 "Exit current mode and down to previous mode\n")
1411 DEFUNSH (VTYSH_RIPD
,
1413 vtysh_exit_ripd_cmd
,
1415 "Exit current mode and down to previous mode\n")
1417 return vtysh_exit (vty
);
1420 ALIAS (vtysh_exit_ripd
,
1421 vtysh_quit_ripd_cmd
,
1423 "Exit current mode and down to previous mode\n")
1425 DEFUNSH (VTYSH_RIPNGD
,
1427 vtysh_exit_ripngd_cmd
,
1429 "Exit current mode and down to previous mode\n")
1431 return vtysh_exit (vty
);
1434 ALIAS (vtysh_exit_ripngd
,
1435 vtysh_quit_ripngd_cmd
,
1437 "Exit current mode and down to previous mode\n")
1439 DEFUNSH (VTYSH_RMAP
,
1441 vtysh_exit_rmap_cmd
,
1443 "Exit current mode and down to previous mode\n")
1445 return vtysh_exit (vty
);
1448 ALIAS (vtysh_exit_rmap
,
1449 vtysh_quit_rmap_cmd
,
1451 "Exit current mode and down to previous mode\n")
1453 DEFUNSH (VTYSH_BGPD
,
1455 vtysh_exit_bgpd_cmd
,
1457 "Exit current mode and down to previous mode\n")
1459 return vtysh_exit (vty
);
1462 ALIAS (vtysh_exit_bgpd
,
1463 vtysh_quit_bgpd_cmd
,
1465 "Exit current mode and down to previous mode\n")
1467 DEFUNSH (VTYSH_OSPFD
,
1469 vtysh_exit_ospfd_cmd
,
1471 "Exit current mode and down to previous mode\n")
1473 return vtysh_exit (vty
);
1476 ALIAS (vtysh_exit_ospfd
,
1477 vtysh_quit_ospfd_cmd
,
1479 "Exit current mode and down to previous mode\n")
1481 DEFUNSH (VTYSH_OSPF6D
,
1483 vtysh_exit_ospf6d_cmd
,
1485 "Exit current mode and down to previous mode\n")
1487 return vtysh_exit (vty
);
1490 ALIAS (vtysh_exit_ospf6d
,
1491 vtysh_quit_ospf6d_cmd
,
1493 "Exit current mode and down to previous mode\n")
1495 DEFUNSH (VTYSH_ISISD
,
1497 vtysh_exit_isisd_cmd
,
1499 "Exit current mode and down to previous mode\n")
1501 return vtysh_exit (vty
);
1504 ALIAS (vtysh_exit_isisd
,
1505 vtysh_quit_isisd_cmd
,
1507 "Exit current mode and down to previous mode\n")
1510 vtysh_exit_line_vty
,
1511 vtysh_exit_line_vty_cmd
,
1513 "Exit current mode and down to previous mode\n")
1515 return vtysh_exit (vty
);
1518 ALIAS (vtysh_exit_line_vty
,
1519 vtysh_quit_line_vty_cmd
,
1521 "Exit current mode and down to previous mode\n")
1523 DEFUNSH (VTYSH_INTERFACE
,
1525 vtysh_interface_cmd
,
1527 "Select an interface to configure\n"
1528 "Interface's name\n")
1530 vty
->node
= INTERFACE_NODE
;
1534 /* TODO Implement "no interface command in isisd. */
1535 DEFSH (VTYSH_ZEBRA
|VTYSH_RIPD
|VTYSH_RIPNGD
|VTYSH_OSPFD
|VTYSH_OSPF6D
,
1536 vtysh_no_interface_cmd
,
1537 "no interface IFNAME",
1539 "Delete a pseudo interface's configuration\n"
1540 "Interface's name\n")
1542 /* TODO Implement interface description commands in ripngd, ospf6d
1544 DEFSH (VTYSH_ZEBRA
|VTYSH_RIPD
|VTYSH_OSPFD
,
1546 "description .LINE",
1547 "Interface specific description\n"
1548 "Characters describing this interface\n")
1550 DEFSH (VTYSH_ZEBRA
|VTYSH_RIPD
|VTYSH_OSPFD
,
1551 no_interface_desc_cmd
,
1554 "Interface specific description\n")
1556 DEFUNSH (VTYSH_INTERFACE
,
1557 vtysh_exit_interface
,
1558 vtysh_exit_interface_cmd
,
1560 "Exit current mode and down to previous mode\n")
1562 return vtysh_exit (vty
);
1565 ALIAS (vtysh_exit_interface
,
1566 vtysh_quit_interface_cmd
,
1568 "Exit current mode and down to previous mode\n")
1571 DEFUN (vtysh_show_memory
,
1572 vtysh_show_memory_cmd
,
1575 "Memory statistics\n")
1578 int ret
= CMD_SUCCESS
;
1579 char line
[] = "show memory\n";
1581 for (i
= 0; i
< array_size(vtysh_client
); i
++)
1582 if ( vtysh_client
[i
].fd
>= 0 )
1584 fprintf (stdout
, "Memory statistics for %s:\n",
1585 vtysh_client
[i
].name
);
1586 ret
= vtysh_client_execute (&vtysh_client
[i
], line
, stdout
);
1587 fprintf (stdout
,"\n");
1593 /* Logging commands. */
1594 DEFUN (vtysh_show_logging
,
1595 vtysh_show_logging_cmd
,
1598 "Show current logging configuration\n")
1601 int ret
= CMD_SUCCESS
;
1602 char line
[] = "show logging\n";
1604 for (i
= 0; i
< array_size(vtysh_client
); i
++)
1605 if ( vtysh_client
[i
].fd
>= 0 )
1607 fprintf (stdout
,"Logging configuration for %s:\n",
1608 vtysh_client
[i
].name
);
1609 ret
= vtysh_client_execute (&vtysh_client
[i
], line
, stdout
);
1610 fprintf (stdout
,"\n");
1618 vtysh_log_stdout_cmd
,
1621 "Set stdout logging level\n")
1627 vtysh_log_stdout_level
,
1628 vtysh_log_stdout_level_cmd
,
1629 "log stdout "LOG_LEVELS
,
1631 "Set stdout logging level\n"
1638 no_vtysh_log_stdout
,
1639 no_vtysh_log_stdout_cmd
,
1640 "no log stdout [LEVEL]",
1643 "Cancel logging to stdout\n"
1652 "log file FILENAME",
1655 "Logging filename\n")
1661 vtysh_log_file_level
,
1662 vtysh_log_file_level_cmd
,
1663 "log file FILENAME "LOG_LEVELS
,
1666 "Logging filename\n"
1674 no_vtysh_log_file_cmd
,
1675 "no log file [FILENAME]",
1678 "Cancel logging to file\n"
1679 "Logging file name\n")
1684 ALIAS_SH (VTYSH_ALL
,
1686 no_vtysh_log_file_level_cmd
,
1687 "no log file FILENAME LEVEL",
1690 "Cancel logging to file\n"
1691 "Logging file name\n"
1696 vtysh_log_monitor_cmd
,
1699 "Set terminal line (monitor) logging level\n")
1705 vtysh_log_monitor_level
,
1706 vtysh_log_monitor_level_cmd
,
1707 "log monitor "LOG_LEVELS
,
1709 "Set terminal line (monitor) logging level\n"
1716 no_vtysh_log_monitor
,
1717 no_vtysh_log_monitor_cmd
,
1718 "no log monitor [LEVEL]",
1721 "Disable terminal line (monitor) logging\n"
1729 vtysh_log_syslog_cmd
,
1732 "Set syslog logging level\n")
1738 vtysh_log_syslog_level
,
1739 vtysh_log_syslog_level_cmd
,
1740 "log syslog "LOG_LEVELS
,
1742 "Set syslog logging level\n"
1749 no_vtysh_log_syslog
,
1750 no_vtysh_log_syslog_cmd
,
1751 "no log syslog [LEVEL]",
1754 "Cancel logging to syslog\n"
1762 vtysh_log_facility_cmd
,
1763 "log facility "LOG_FACILITIES
,
1765 "Facility parameter for syslog messages\n"
1773 no_vtysh_log_facility
,
1774 no_vtysh_log_facility_cmd
,
1775 "no log facility [FACILITY]",
1778 "Reset syslog facility to default (daemon)\n"
1779 "Syslog facility\n")
1785 DEFUNSH_DEPRECATED (VTYSH_ALL
,
1788 "log trap "LOG_LEVELS
,
1790 "(Deprecated) Set logging level and default for all destinations\n"
1797 DEFUNSH_DEPRECATED (VTYSH_ALL
,
1799 no_vtysh_log_trap_cmd
,
1800 "no log trap [LEVEL]",
1803 "Permit all logging information\n"
1810 vtysh_log_record_priority
,
1811 vtysh_log_record_priority_cmd
,
1812 "log record-priority",
1814 "Log the priority of the message within the message\n")
1820 no_vtysh_log_record_priority
,
1821 no_vtysh_log_record_priority_cmd
,
1822 "no log record-priority",
1825 "Do not log the priority of the message within the message\n")
1831 vtysh_log_timestamp_precision
,
1832 vtysh_log_timestamp_precision_cmd
,
1833 "log timestamp precision <0-6>",
1835 "Timestamp configuration\n"
1836 "Set the timestamp precision\n"
1837 "Number of subsecond digits\n")
1843 no_vtysh_log_timestamp_precision
,
1844 no_vtysh_log_timestamp_precision_cmd
,
1845 "no log timestamp precision",
1848 "Timestamp configuration\n"
1849 "Reset the timestamp precision to the default value of 0\n")
1855 vtysh_service_password_encrypt
,
1856 vtysh_service_password_encrypt_cmd
,
1857 "service password-encryption",
1858 "Set up miscellaneous service\n"
1859 "Enable encrypted passwords\n")
1865 no_vtysh_service_password_encrypt
,
1866 no_vtysh_service_password_encrypt_cmd
,
1867 "no service password-encryption",
1869 "Set up miscellaneous service\n"
1870 "Enable encrypted passwords\n")
1876 vtysh_config_password
,
1878 "password (8|) WORD",
1879 "Assign the terminal connection password\n"
1880 "Specifies a HIDDEN password will follow\n"
1882 "The HIDDEN line password string\n")
1888 vtysh_password_text
,
1889 vtysh_password_text_cmd
,
1891 "Assign the terminal connection password\n"
1892 "The UNENCRYPTED (cleartext) line password\n")
1898 vtysh_config_enable_password
,
1899 vtysh_enable_password_cmd
,
1900 "enable password (8|) WORD",
1901 "Modify enable password parameters\n"
1902 "Assign the privileged level password\n"
1903 "Specifies a HIDDEN password will follow\n"
1905 "The HIDDEN 'enable' password string\n")
1911 vtysh_enable_password_text
,
1912 vtysh_enable_password_text_cmd
,
1913 "enable password LINE",
1914 "Modify enable password parameters\n"
1915 "Assign the privileged level password\n"
1916 "The UNENCRYPTED (cleartext) 'enable' password\n")
1922 no_vtysh_config_enable_password
,
1923 no_vtysh_enable_password_cmd
,
1924 "no enable password",
1926 "Modify enable password parameters\n"
1927 "Assign the privileged level password\n")
1932 DEFUN (vtysh_write_terminal
,
1933 vtysh_write_terminal_cmd
,
1935 "Write running configuration to memory, network, or terminal\n"
1936 "Write to terminal\n")
1939 char line
[] = "write terminal\n";
1942 if (vtysh_pager_name
)
1944 fp
= popen (vtysh_pager_name
, "w");
1954 vty_out (vty
, "Building configuration...%s", VTY_NEWLINE
);
1955 vty_out (vty
, "%sCurrent configuration:%s", VTY_NEWLINE
,
1957 vty_out (vty
, "!%s", VTY_NEWLINE
);
1959 for (i
= 0; i
< array_size(vtysh_client
); i
++)
1960 vtysh_client_config (&vtysh_client
[i
], line
);
1962 /* Integrate vtysh specific configuration. */
1963 vtysh_config_write ();
1965 vtysh_config_dump (fp
);
1967 if (vtysh_pager_name
&& fp
)
1970 if (pclose (fp
) == -1)
1978 vty_out (vty
, "end%s", VTY_NEWLINE
);
1983 DEFUN (vtysh_integrated_config
,
1984 vtysh_integrated_config_cmd
,
1985 "service integrated-vtysh-config",
1986 "Set up miscellaneous service\n"
1987 "Write configuration into integrated file\n")
1989 vtysh_writeconfig_integrated
= 1;
1993 DEFUN (no_vtysh_integrated_config
,
1994 no_vtysh_integrated_config_cmd
,
1995 "no service integrated-vtysh-config",
1997 "Set up miscellaneous service\n"
1998 "Write configuration into integrated file\n")
2000 vtysh_writeconfig_integrated
= 0;
2005 write_config_integrated(void)
2008 char line
[] = "write terminal\n";
2010 char *integrate_sav
= NULL
;
2012 integrate_sav
= malloc (strlen (integrate_default
) +
2013 strlen (CONF_BACKUP_EXT
) + 1);
2014 strcpy (integrate_sav
, integrate_default
);
2015 strcat (integrate_sav
, CONF_BACKUP_EXT
);
2017 fprintf (stdout
,"Building Configuration...\n");
2019 /* Move current configuration file to backup config file. */
2020 unlink (integrate_sav
);
2021 rename (integrate_default
, integrate_sav
);
2022 free (integrate_sav
);
2024 fp
= fopen (integrate_default
, "w");
2027 fprintf (stdout
,"%% Can't open configuration file %s.\n",
2032 for (i
= 0; i
< array_size(vtysh_client
); i
++)
2033 vtysh_client_config (&vtysh_client
[i
], line
);
2035 vtysh_config_dump (fp
);
2039 if (chmod (integrate_default
, CONFIGFILE_MASK
) != 0)
2041 fprintf (stdout
,"%% Can't chmod configuration file %s: %s (%d)\n",
2042 integrate_default
, safe_strerror(errno
), errno
);
2046 fprintf(stdout
,"Integrated configuration saved to %s\n",integrate_default
);
2048 fprintf (stdout
,"[OK]\n");
2053 DEFUN (vtysh_write_memory
,
2054 vtysh_write_memory_cmd
,
2056 "Write running configuration to memory, network, or terminal\n"
2057 "Write configuration to the file (same as write file)\n")
2059 int ret
= CMD_SUCCESS
;
2060 char line
[] = "write memory\n";
2063 /* If integrated Quagga.conf explicitely set. */
2064 if (vtysh_writeconfig_integrated
)
2065 return write_config_integrated();
2067 fprintf (stdout
,"Building Configuration...\n");
2069 for (i
= 0; i
< array_size(vtysh_client
); i
++)
2070 ret
= vtysh_client_execute (&vtysh_client
[i
], line
, stdout
);
2072 fprintf (stdout
,"[OK]\n");
2077 ALIAS (vtysh_write_memory
,
2078 vtysh_copy_runningconfig_startupconfig_cmd
,
2079 "copy running-config startup-config",
2080 "Copy from one file to another\n"
2081 "Copy from current system configuration\n"
2082 "Copy to startup configuration\n")
2084 ALIAS (vtysh_write_memory
,
2085 vtysh_write_file_cmd
,
2087 "Write running configuration to memory, network, or terminal\n"
2088 "Write configuration to the file (same as write memory)\n")
2090 ALIAS (vtysh_write_memory
,
2093 "Write running configuration to memory, network, or terminal\n")
2095 ALIAS (vtysh_write_terminal
,
2096 vtysh_show_running_config_cmd
,
2097 "show running-config",
2099 "Current operating configuration\n")
2101 DEFUN (vtysh_terminal_length
,
2102 vtysh_terminal_length_cmd
,
2103 "terminal length <0-512>",
2104 "Set terminal line parameters\n"
2105 "Set number of lines on a screen\n"
2106 "Number of lines on screen (0 for no pausing)\n")
2109 char *endptr
= NULL
;
2110 char default_pager
[10];
2112 lines
= strtol (argv
[0], &endptr
, 10);
2113 if (lines
< 0 || lines
> 512 || *endptr
!= '\0')
2115 vty_out (vty
, "length is malformed%s", VTY_NEWLINE
);
2119 if (vtysh_pager_name
)
2121 free (vtysh_pager_name
);
2122 vtysh_pager_name
= NULL
;
2127 snprintf(default_pager
, 10, "more -%i", lines
);
2128 vtysh_pager_name
= strdup (default_pager
);
2134 DEFUN (vtysh_terminal_no_length
,
2135 vtysh_terminal_no_length_cmd
,
2136 "terminal no length",
2137 "Set terminal line parameters\n"
2139 "Set number of lines on a screen\n")
2141 if (vtysh_pager_name
)
2143 free (vtysh_pager_name
);
2144 vtysh_pager_name
= NULL
;
2151 DEFUN (vtysh_show_daemons
,
2152 vtysh_show_daemons_cmd
,
2155 "Show list of running daemons\n")
2159 for (i
= 0; i
< array_size(vtysh_client
); i
++)
2160 if ( vtysh_client
[i
].fd
>= 0 )
2161 vty_out(vty
, " %s", vtysh_client
[i
].name
);
2162 vty_out(vty
, "%s", VTY_NEWLINE
);
2167 /* Execute command in child process. */
2169 execute_command (const char *command
, int argc
, const char *arg1
,
2180 /* Failure of fork(). */
2181 fprintf (stderr
, "Can't fork: %s\n", safe_strerror (errno
));
2186 /* This is child process. */
2190 execlp (command
, command
, (const char *)NULL
);
2193 execlp (command
, command
, arg1
, (const char *)NULL
);
2196 execlp (command
, command
, arg1
, arg2
, (const char *)NULL
);
2200 /* When execlp suceed, this part is not executed. */
2201 fprintf (stderr
, "Can't execute %s: %s\n", command
, safe_strerror (errno
));
2206 /* This is parent. */
2208 wait4 (pid
, &status
, 0, NULL
);
2216 "Send echo messages\n"
2217 "Ping destination address or hostname\n")
2219 execute_command ("ping", 1, argv
[0], NULL
);
2226 "Send echo messages\n"
2228 "Ping destination address or hostname\n")
2230 DEFUN (vtysh_traceroute
,
2231 vtysh_traceroute_cmd
,
2233 "Trace route to destination\n"
2234 "Trace route to destination address or hostname\n")
2236 execute_command ("traceroute", 1, argv
[0], NULL
);
2240 ALIAS (vtysh_traceroute
,
2241 vtysh_traceroute_ip_cmd
,
2242 "traceroute ip WORD",
2243 "Trace route to destination\n"
2245 "Trace route to destination address or hostname\n")
2251 "Send echo messages\n"
2253 "Ping destination address or hostname\n")
2255 execute_command ("ping6", 1, argv
[0], NULL
);
2259 DEFUN (vtysh_traceroute6
,
2260 vtysh_traceroute6_cmd
,
2261 "traceroute ipv6 WORD",
2262 "Trace route to destination\n"
2264 "Trace route to destination address or hostname\n")
2266 execute_command ("traceroute6", 1, argv
[0], NULL
);
2271 DEFUN (vtysh_telnet
,
2274 "Open a telnet connection\n"
2275 "IP address or hostname of a remote system\n")
2277 execute_command ("telnet", 1, argv
[0], NULL
);
2281 DEFUN (vtysh_telnet_port
,
2282 vtysh_telnet_port_cmd
,
2284 "Open a telnet connection\n"
2285 "IP address or hostname of a remote system\n"
2286 "TCP Port number\n")
2288 execute_command ("telnet", 2, argv
[0], argv
[1]);
2295 "Open an ssh connection\n"
2298 execute_command ("ssh", 1, argv
[0], NULL
);
2302 DEFUN (vtysh_start_shell
,
2303 vtysh_start_shell_cmd
,
2305 "Start UNIX shell\n")
2307 execute_command ("sh", 0, NULL
, NULL
);
2311 DEFUN (vtysh_start_bash
,
2312 vtysh_start_bash_cmd
,
2314 "Start UNIX shell\n"
2317 execute_command ("bash", 0, NULL
, NULL
);
2321 DEFUN (vtysh_start_zsh
,
2322 vtysh_start_zsh_cmd
,
2324 "Start UNIX shell\n"
2327 execute_command ("zsh", 0, NULL
, NULL
);
2332 vtysh_install_default (enum node_type node
)
2334 install_element (node
, &config_list_cmd
);
2337 /* Making connection to protocol daemon. */
2339 vtysh_connect (struct vtysh_client
*vclient
)
2343 struct sockaddr_un addr
;
2346 /* Stat socket to see if we have permission to access it. */
2347 ret
= stat (vclient
->path
, &s_stat
);
2348 if (ret
< 0 && errno
!= ENOENT
)
2350 fprintf (stderr
, "vtysh_connect(%s): stat = %s\n",
2351 vclient
->path
, safe_strerror(errno
));
2357 if (! S_ISSOCK(s_stat
.st_mode
))
2359 fprintf (stderr
, "vtysh_connect(%s): Not a socket\n",
2366 sock
= socket (AF_UNIX
, SOCK_STREAM
, 0);
2370 fprintf(stderr
, "vtysh_connect(%s): socket = %s\n", vclient
->path
,
2371 safe_strerror(errno
));
2376 memset (&addr
, 0, sizeof (struct sockaddr_un
));
2377 addr
.sun_family
= AF_UNIX
;
2378 strncpy (addr
.sun_path
, vclient
->path
, strlen (vclient
->path
));
2379 #ifdef HAVE_STRUCT_SOCKADDR_UN_SUN_LEN
2380 len
= addr
.sun_len
= SUN_LEN(&addr
);
2382 len
= sizeof (addr
.sun_family
) + strlen (addr
.sun_path
);
2383 #endif /* HAVE_STRUCT_SOCKADDR_UN_SUN_LEN */
2385 ret
= connect (sock
, (struct sockaddr
*) &addr
, len
);
2389 fprintf(stderr
, "vtysh_connect(%s): connect = %s\n", vclient
->path
,
2390 safe_strerror(errno
));
2400 /* Return true if str begins with prefix, else return false */
2402 begins_with(const char *str
, const char *prefix
)
2404 if (!str
|| !prefix
)
2406 size_t lenstr
= strlen(str
);
2407 size_t lenprefix
= strlen(prefix
);
2408 if (lenprefix
> lenstr
)
2410 return strncmp(str
, prefix
, lenprefix
) == 0;
2413 /* Return true if str ends with suffix, else return false */
2415 ends_with(const char *str
, const char *suffix
)
2417 if (!str
|| !suffix
)
2419 size_t lenstr
= strlen(str
);
2420 size_t lensuffix
= strlen(suffix
);
2421 if (lensuffix
> lenstr
)
2423 return strncmp(str
+ lenstr
- lensuffix
, suffix
, lensuffix
) == 0;
2427 vtysh_client_sorted_insert (struct vtysh_client
*head_client
,
2428 struct vtysh_client
*client
)
2430 struct vtysh_client
*prev_node
, *current_node
;
2432 prev_node
= head_client
;
2433 current_node
= head_client
->next
;
2434 while (current_node
)
2436 if (strcmp(current_node
->path
, client
->path
) > 0)
2439 prev_node
= current_node
;
2440 current_node
= current_node
->next
;
2442 client
->next
= current_node
;
2443 prev_node
->next
= client
;
2446 #define MAXIMUM_INSTANCES 10
2449 vtysh_update_all_insances(struct vtysh_client
* head_client
)
2451 struct vtysh_client
*client
;
2454 struct dirent
*file
;
2457 if (head_client
->flag
!= VTYSH_OSPFD
) return;
2459 /* ls /var/run/quagga/ and look for all files ending in .vty */
2460 dir
= opendir("/var/run/quagga/");
2463 while ((file
= readdir(dir
)) != NULL
)
2465 if (begins_with(file
->d_name
, "ospfd-") && ends_with(file
->d_name
, ".vty"))
2467 if (n
== MAXIMUM_INSTANCES
)
2470 "Parsing /var/run/quagga/, client limit(%d) reached!\n", n
);
2473 client
= (struct vtysh_client
*) malloc(sizeof(struct vtysh_client
));
2475 client
->name
= "ospfd";
2476 client
->flag
= VTYSH_OSPFD
;
2477 ptr
= (char *) malloc(100);
2478 sprintf(ptr
, "/var/run/quagga/%s", file
->d_name
);
2479 client
->path
= (const char *)ptr
;
2480 client
->next
= NULL
;
2481 vtysh_client_sorted_insert(head_client
, client
);
2490 vtysh_connect_all_instances (struct vtysh_client
*head_client
)
2492 struct vtysh_client
*client
;
2495 vtysh_update_all_insances(head_client
);
2497 client
= head_client
->next
;
2500 if (vtysh_connect(client
) == 0)
2502 client
= client
->next
;
2509 vtysh_connect_all(const char *daemon_name
)
2515 for (i
= 0; i
< array_size(vtysh_client
); i
++)
2517 if (!daemon_name
|| !strcmp(daemon_name
, vtysh_client
[i
].name
))
2520 if (vtysh_connect(&vtysh_client
[i
]) == 0)
2522 /* We need direct access to ripd in vtysh_exit_ripd_only. */
2523 if (vtysh_client
[i
].flag
== VTYSH_RIPD
)
2524 ripd_client
= &vtysh_client
[i
];
2526 rc
+= vtysh_connect_all_instances(&vtysh_client
[i
]);
2530 fprintf(stderr
, "Error: no daemons match name %s!\n", daemon_name
);
2534 /* To disable readline's filename completion. */
2536 vtysh_completion_entry_function (const char *ignore
, int invoking_key
)
2542 vtysh_readline_init (void)
2544 /* readline related settings. */
2545 rl_bind_key ('?', (rl_command_func_t
*) vtysh_rl_describe
);
2546 rl_completion_entry_function
= vtysh_completion_entry_function
;
2547 rl_attempted_completion_function
= (rl_completion_func_t
*)new_completion
;
2553 static struct utsname names
;
2554 static char buf
[100];
2555 const char*hostname
;
2556 extern struct host host
;
2558 hostname
= host
.name
;
2562 if (!names
.nodename
[0])
2564 hostname
= names
.nodename
;
2567 snprintf (buf
, sizeof buf
, cmd_prompt (vty
->node
), hostname
);
2573 vtysh_init_vty (void)
2575 /* Make vty structure. */
2577 vty
->type
= VTY_SHELL
;
2578 vty
->node
= VIEW_NODE
;
2580 /* Initialize commands. */
2583 /* Install nodes. */
2584 install_node (&bgp_node
, NULL
);
2585 install_node (&rip_node
, NULL
);
2586 install_node (&interface_node
, NULL
);
2587 install_node (&rmap_node
, NULL
);
2588 install_node (&zebra_node
, NULL
);
2589 install_node (&bgp_vpnv4_node
, NULL
);
2590 install_node (&bgp_ipv4_node
, NULL
);
2591 install_node (&bgp_ipv4m_node
, NULL
);
2592 /* #ifdef HAVE_IPV6 */
2593 install_node (&bgp_ipv6_node
, NULL
);
2594 install_node (&bgp_ipv6m_node
, NULL
);
2596 install_node (&ospf_node
, NULL
);
2597 /* #ifdef HAVE_IPV6 */
2598 install_node (&ripng_node
, NULL
);
2599 install_node (&ospf6_node
, NULL
);
2601 install_node (&babel_node
, NULL
);
2602 install_node (&keychain_node
, NULL
);
2603 install_node (&keychain_key_node
, NULL
);
2604 install_node (&isis_node
, NULL
);
2605 install_node (&vty_node
, NULL
);
2607 vtysh_install_default (VIEW_NODE
);
2608 vtysh_install_default (ENABLE_NODE
);
2609 vtysh_install_default (CONFIG_NODE
);
2610 vtysh_install_default (BGP_NODE
);
2611 vtysh_install_default (RIP_NODE
);
2612 vtysh_install_default (INTERFACE_NODE
);
2613 vtysh_install_default (RMAP_NODE
);
2614 vtysh_install_default (ZEBRA_NODE
);
2615 vtysh_install_default (BGP_VPNV4_NODE
);
2616 vtysh_install_default (BGP_IPV4_NODE
);
2617 vtysh_install_default (BGP_IPV4M_NODE
);
2618 vtysh_install_default (BGP_IPV6_NODE
);
2619 vtysh_install_default (BGP_IPV6M_NODE
);
2620 vtysh_install_default (OSPF_NODE
);
2621 vtysh_install_default (RIPNG_NODE
);
2622 vtysh_install_default (OSPF6_NODE
);
2623 vtysh_install_default (BABEL_NODE
);
2624 vtysh_install_default (ISIS_NODE
);
2625 vtysh_install_default (KEYCHAIN_NODE
);
2626 vtysh_install_default (KEYCHAIN_KEY_NODE
);
2627 vtysh_install_default (VTY_NODE
);
2629 install_element (VIEW_NODE
, &vtysh_enable_cmd
);
2630 install_element (ENABLE_NODE
, &vtysh_config_terminal_cmd
);
2631 install_element (ENABLE_NODE
, &vtysh_disable_cmd
);
2633 /* "exit" command. */
2634 install_element (VIEW_NODE
, &vtysh_exit_all_cmd
);
2635 install_element (VIEW_NODE
, &vtysh_quit_all_cmd
);
2636 install_element (CONFIG_NODE
, &vtysh_exit_all_cmd
);
2637 /* install_element (CONFIG_NODE, &vtysh_quit_all_cmd); */
2638 install_element (ENABLE_NODE
, &vtysh_exit_all_cmd
);
2639 install_element (ENABLE_NODE
, &vtysh_quit_all_cmd
);
2640 install_element (RIP_NODE
, &vtysh_exit_ripd_cmd
);
2641 install_element (RIP_NODE
, &vtysh_quit_ripd_cmd
);
2642 install_element (RIPNG_NODE
, &vtysh_exit_ripngd_cmd
);
2643 install_element (RIPNG_NODE
, &vtysh_quit_ripngd_cmd
);
2644 install_element (OSPF_NODE
, &vtysh_exit_ospfd_cmd
);
2645 install_element (OSPF_NODE
, &vtysh_quit_ospfd_cmd
);
2646 install_element (OSPF6_NODE
, &vtysh_exit_ospf6d_cmd
);
2647 install_element (OSPF6_NODE
, &vtysh_quit_ospf6d_cmd
);
2648 install_element (BGP_NODE
, &vtysh_exit_bgpd_cmd
);
2649 install_element (BGP_NODE
, &vtysh_quit_bgpd_cmd
);
2650 install_element (BGP_VPNV4_NODE
, &vtysh_exit_bgpd_cmd
);
2651 install_element (BGP_VPNV4_NODE
, &vtysh_quit_bgpd_cmd
);
2652 install_element (BGP_IPV4_NODE
, &vtysh_exit_bgpd_cmd
);
2653 install_element (BGP_IPV4_NODE
, &vtysh_quit_bgpd_cmd
);
2654 install_element (BGP_IPV4M_NODE
, &vtysh_exit_bgpd_cmd
);
2655 install_element (BGP_IPV4M_NODE
, &vtysh_quit_bgpd_cmd
);
2656 install_element (BGP_IPV6_NODE
, &vtysh_exit_bgpd_cmd
);
2657 install_element (BGP_IPV6_NODE
, &vtysh_quit_bgpd_cmd
);
2658 install_element (BGP_IPV6M_NODE
, &vtysh_exit_bgpd_cmd
);
2659 install_element (BGP_IPV6M_NODE
, &vtysh_quit_bgpd_cmd
);
2660 install_element (ISIS_NODE
, &vtysh_exit_isisd_cmd
);
2661 install_element (ISIS_NODE
, &vtysh_quit_isisd_cmd
);
2662 install_element (KEYCHAIN_NODE
, &vtysh_exit_ripd_cmd
);
2663 install_element (KEYCHAIN_NODE
, &vtysh_quit_ripd_cmd
);
2664 install_element (KEYCHAIN_KEY_NODE
, &vtysh_exit_ripd_cmd
);
2665 install_element (KEYCHAIN_KEY_NODE
, &vtysh_quit_ripd_cmd
);
2666 install_element (RMAP_NODE
, &vtysh_exit_rmap_cmd
);
2667 install_element (RMAP_NODE
, &vtysh_quit_rmap_cmd
);
2668 install_element (VTY_NODE
, &vtysh_exit_line_vty_cmd
);
2669 install_element (VTY_NODE
, &vtysh_quit_line_vty_cmd
);
2671 /* "end" command. */
2672 install_element (CONFIG_NODE
, &vtysh_end_all_cmd
);
2673 install_element (ENABLE_NODE
, &vtysh_end_all_cmd
);
2674 install_element (RIP_NODE
, &vtysh_end_all_cmd
);
2675 install_element (RIPNG_NODE
, &vtysh_end_all_cmd
);
2676 install_element (OSPF_NODE
, &vtysh_end_all_cmd
);
2677 install_element (OSPF6_NODE
, &vtysh_end_all_cmd
);
2678 install_element (BABEL_NODE
, &vtysh_end_all_cmd
);
2679 install_element (BGP_NODE
, &vtysh_end_all_cmd
);
2680 install_element (BGP_IPV4_NODE
, &vtysh_end_all_cmd
);
2681 install_element (BGP_IPV4M_NODE
, &vtysh_end_all_cmd
);
2682 install_element (BGP_VPNV4_NODE
, &vtysh_end_all_cmd
);
2683 install_element (BGP_IPV6_NODE
, &vtysh_end_all_cmd
);
2684 install_element (BGP_IPV6M_NODE
, &vtysh_end_all_cmd
);
2685 install_element (ISIS_NODE
, &vtysh_end_all_cmd
);
2686 install_element (KEYCHAIN_NODE
, &vtysh_end_all_cmd
);
2687 install_element (KEYCHAIN_KEY_NODE
, &vtysh_end_all_cmd
);
2688 install_element (RMAP_NODE
, &vtysh_end_all_cmd
);
2689 install_element (VTY_NODE
, &vtysh_end_all_cmd
);
2691 install_element (INTERFACE_NODE
, &interface_desc_cmd
);
2692 install_element (INTERFACE_NODE
, &no_interface_desc_cmd
);
2693 install_element (INTERFACE_NODE
, &vtysh_end_all_cmd
);
2694 install_element (INTERFACE_NODE
, &vtysh_exit_interface_cmd
);
2695 install_element (INTERFACE_NODE
, &vtysh_quit_interface_cmd
);
2696 install_element (CONFIG_NODE
, &router_rip_cmd
);
2698 install_element (CONFIG_NODE
, &router_ripng_cmd
);
2700 install_element (CONFIG_NODE
, &router_ospf_cmd
);
2701 install_element (CONFIG_NODE
, &router_ospf_instance_cmd
);
2703 install_element (CONFIG_NODE
, &router_ospf6_cmd
);
2705 install_element (CONFIG_NODE
, &router_babel_cmd
);
2706 install_element (CONFIG_NODE
, &router_isis_cmd
);
2707 install_element (CONFIG_NODE
, &router_bgp_cmd
);
2708 install_element (CONFIG_NODE
, &router_bgp_view_cmd
);
2709 install_element (BGP_NODE
, &address_family_vpnv4_cmd
);
2710 install_element (BGP_NODE
, &address_family_vpnv4_unicast_cmd
);
2711 install_element (BGP_NODE
, &address_family_ipv4_unicast_cmd
);
2712 install_element (BGP_NODE
, &address_family_ipv4_multicast_cmd
);
2714 install_element (BGP_NODE
, &address_family_ipv6_cmd
);
2715 install_element (BGP_NODE
, &address_family_ipv6_unicast_cmd
);
2716 install_element (BGP_NODE
, &address_family_ipv6_multicast_cmd
);
2718 install_element (BGP_VPNV4_NODE
, &exit_address_family_cmd
);
2719 install_element (BGP_IPV4_NODE
, &exit_address_family_cmd
);
2720 install_element (BGP_IPV4M_NODE
, &exit_address_family_cmd
);
2721 install_element (BGP_IPV6_NODE
, &exit_address_family_cmd
);
2722 install_element (BGP_IPV6M_NODE
, &exit_address_family_cmd
);
2723 install_element (CONFIG_NODE
, &key_chain_cmd
);
2724 install_element (CONFIG_NODE
, &route_map_cmd
);
2725 install_element (CONFIG_NODE
, &vtysh_line_vty_cmd
);
2726 install_element (KEYCHAIN_NODE
, &key_cmd
);
2727 install_element (KEYCHAIN_NODE
, &key_chain_cmd
);
2728 install_element (KEYCHAIN_KEY_NODE
, &key_chain_cmd
);
2729 install_element (CONFIG_NODE
, &vtysh_interface_cmd
);
2730 install_element (CONFIG_NODE
, &vtysh_no_interface_cmd
);
2731 install_element (ENABLE_NODE
, &vtysh_show_running_config_cmd
);
2732 install_element (ENABLE_NODE
, &vtysh_copy_runningconfig_startupconfig_cmd
);
2733 install_element (ENABLE_NODE
, &vtysh_write_file_cmd
);
2734 install_element (ENABLE_NODE
, &vtysh_write_cmd
);
2736 /* "write terminal" command. */
2737 install_element (ENABLE_NODE
, &vtysh_write_terminal_cmd
);
2739 install_element (CONFIG_NODE
, &vtysh_integrated_config_cmd
);
2740 install_element (CONFIG_NODE
, &no_vtysh_integrated_config_cmd
);
2742 /* "write memory" command. */
2743 install_element (ENABLE_NODE
, &vtysh_write_memory_cmd
);
2745 install_element (VIEW_NODE
, &vtysh_terminal_length_cmd
);
2746 install_element (ENABLE_NODE
, &vtysh_terminal_length_cmd
);
2747 install_element (VIEW_NODE
, &vtysh_terminal_no_length_cmd
);
2748 install_element (ENABLE_NODE
, &vtysh_terminal_no_length_cmd
);
2749 install_element (VIEW_NODE
, &vtysh_show_daemons_cmd
);
2750 install_element (ENABLE_NODE
, &vtysh_show_daemons_cmd
);
2752 install_element (VIEW_NODE
, &vtysh_ping_cmd
);
2753 install_element (VIEW_NODE
, &vtysh_ping_ip_cmd
);
2754 install_element (VIEW_NODE
, &vtysh_traceroute_cmd
);
2755 install_element (VIEW_NODE
, &vtysh_traceroute_ip_cmd
);
2757 install_element (VIEW_NODE
, &vtysh_ping6_cmd
);
2758 install_element (VIEW_NODE
, &vtysh_traceroute6_cmd
);
2760 install_element (VIEW_NODE
, &vtysh_telnet_cmd
);
2761 install_element (VIEW_NODE
, &vtysh_telnet_port_cmd
);
2762 install_element (VIEW_NODE
, &vtysh_ssh_cmd
);
2763 install_element (ENABLE_NODE
, &vtysh_ping_cmd
);
2764 install_element (ENABLE_NODE
, &vtysh_ping_ip_cmd
);
2765 install_element (ENABLE_NODE
, &vtysh_traceroute_cmd
);
2766 install_element (ENABLE_NODE
, &vtysh_traceroute_ip_cmd
);
2768 install_element (ENABLE_NODE
, &vtysh_ping6_cmd
);
2769 install_element (ENABLE_NODE
, &vtysh_traceroute6_cmd
);
2771 install_element (ENABLE_NODE
, &vtysh_telnet_cmd
);
2772 install_element (ENABLE_NODE
, &vtysh_telnet_port_cmd
);
2773 install_element (ENABLE_NODE
, &vtysh_ssh_cmd
);
2774 install_element (ENABLE_NODE
, &vtysh_start_shell_cmd
);
2775 install_element (ENABLE_NODE
, &vtysh_start_bash_cmd
);
2776 install_element (ENABLE_NODE
, &vtysh_start_zsh_cmd
);
2778 install_element (VIEW_NODE
, &vtysh_show_memory_cmd
);
2779 install_element (ENABLE_NODE
, &vtysh_show_memory_cmd
);
2782 install_element (ENABLE_NODE
, &vtysh_show_logging_cmd
);
2783 install_element (VIEW_NODE
, &vtysh_show_logging_cmd
);
2784 install_element (CONFIG_NODE
, &vtysh_log_stdout_cmd
);
2785 install_element (CONFIG_NODE
, &vtysh_log_stdout_level_cmd
);
2786 install_element (CONFIG_NODE
, &no_vtysh_log_stdout_cmd
);
2787 install_element (CONFIG_NODE
, &vtysh_log_file_cmd
);
2788 install_element (CONFIG_NODE
, &vtysh_log_file_level_cmd
);
2789 install_element (CONFIG_NODE
, &no_vtysh_log_file_cmd
);
2790 install_element (CONFIG_NODE
, &no_vtysh_log_file_level_cmd
);
2791 install_element (CONFIG_NODE
, &vtysh_log_monitor_cmd
);
2792 install_element (CONFIG_NODE
, &vtysh_log_monitor_level_cmd
);
2793 install_element (CONFIG_NODE
, &no_vtysh_log_monitor_cmd
);
2794 install_element (CONFIG_NODE
, &vtysh_log_syslog_cmd
);
2795 install_element (CONFIG_NODE
, &vtysh_log_syslog_level_cmd
);
2796 install_element (CONFIG_NODE
, &no_vtysh_log_syslog_cmd
);
2797 install_element (CONFIG_NODE
, &vtysh_log_trap_cmd
);
2798 install_element (CONFIG_NODE
, &no_vtysh_log_trap_cmd
);
2799 install_element (CONFIG_NODE
, &vtysh_log_facility_cmd
);
2800 install_element (CONFIG_NODE
, &no_vtysh_log_facility_cmd
);
2801 install_element (CONFIG_NODE
, &vtysh_log_record_priority_cmd
);
2802 install_element (CONFIG_NODE
, &no_vtysh_log_record_priority_cmd
);
2803 install_element (CONFIG_NODE
, &vtysh_log_timestamp_precision_cmd
);
2804 install_element (CONFIG_NODE
, &no_vtysh_log_timestamp_precision_cmd
);
2806 install_element (CONFIG_NODE
, &vtysh_service_password_encrypt_cmd
);
2807 install_element (CONFIG_NODE
, &no_vtysh_service_password_encrypt_cmd
);
2809 install_element (CONFIG_NODE
, &vtysh_password_cmd
);
2810 install_element (CONFIG_NODE
, &vtysh_password_text_cmd
);
2811 install_element (CONFIG_NODE
, &vtysh_enable_password_cmd
);
2812 install_element (CONFIG_NODE
, &vtysh_enable_password_text_cmd
);
2813 install_element (CONFIG_NODE
, &no_vtysh_enable_password_cmd
);