2 * Virtual terminal [aka TeletYpe] interface routine.
3 * Copyright (C) 1997, 98 Kunihiro Ishiguro
5 * This file is part of GNU Zebra.
7 * GNU Zebra is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2, or (at your option) any
12 * GNU Zebra is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; see the file COPYING; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
27 #include <lib/version.h>
29 #include "sockunion.h"
39 #include <arpa/telnet.h>
42 DEFINE_MTYPE_STATIC(LIB
, VTY
, "VTY")
43 DEFINE_MTYPE_STATIC(LIB
, VTY_OUT_BUF
, "VTY output buffer")
44 DEFINE_MTYPE_STATIC(LIB
, VTY_HIST
, "VTY history")
59 static void vty_event(enum event
, int, struct vty
*);
61 /* Extern host structure from command.c */
62 extern struct host host
;
64 /* Vector which store each vty structure. */
67 /* Vty timeout value. */
68 static unsigned long vty_timeout_val
= VTY_TIMEOUT_DEFAULT
;
70 /* Vty access-class command */
71 static char *vty_accesslist_name
= NULL
;
73 /* Vty access-calss for IPv6. */
74 static char *vty_ipv6_accesslist_name
= NULL
;
76 /* VTY server thread. */
77 static vector Vvty_serv_thread
;
79 /* Current directory. */
83 static int vty_config
;
84 static int vty_config_is_lockless
= 0;
86 /* Login password check. */
87 static int no_password_check
= 0;
89 /* Integrated configuration file path */
90 char integrate_default
[] = SYSCONFDIR INTEGRATE_DEFAULT_CONFIG
;
92 static int do_log_commands
= 0;
94 /* VTY standard output function. */
95 int vty_out(struct vty
*vty
, const char *format
, ...)
103 if (vty_shell(vty
)) {
104 va_start(args
, format
);
105 vprintf(format
, args
);
108 /* Try to write to initial buffer. */
109 va_start(args
, format
);
110 len
= vsnprintf(buf
, sizeof(buf
), format
, args
);
113 /* Initial buffer is not enough. */
114 if (len
< 0 || len
>= size
) {
121 p
= XREALLOC(MTYPE_VTY_OUT_BUF
, p
, size
);
125 va_start(args
, format
);
126 len
= vsnprintf(p
, size
, format
, args
);
129 if (len
> -1 && len
< size
)
134 /* When initial buffer is enough to store all output. */
138 /* Pointer p must point out buffer. */
139 if (vty
->type
!= VTY_TERM
)
140 buffer_put(vty
->obuf
, (u_char
*)p
, len
);
142 buffer_put_crlf(vty
->obuf
, (u_char
*)p
, len
);
144 /* If p is not different with buf, it is allocated buffer. */
146 XFREE(MTYPE_VTY_OUT_BUF
, p
);
152 static int vty_log_out(struct vty
*vty
, const char *level
,
153 const char *proto_str
, const char *format
,
154 struct timestamp_control
*ctl
, va_list va
)
160 if (!ctl
->already_rendered
) {
161 ctl
->len
= quagga_timestamp(ctl
->precision
, ctl
->buf
,
163 ctl
->already_rendered
= 1;
165 if (ctl
->len
+ 1 >= sizeof(buf
))
167 memcpy(buf
, ctl
->buf
, len
= ctl
->len
);
172 ret
= snprintf(buf
+ len
, sizeof(buf
) - len
, "%s: %s: ", level
,
175 ret
= snprintf(buf
+ len
, sizeof(buf
) - len
, "%s: ", proto_str
);
176 if ((ret
< 0) || ((size_t)(len
+= ret
) >= sizeof(buf
)))
179 if (((ret
= vsnprintf(buf
+ len
, sizeof(buf
) - len
, format
, va
)) < 0)
180 || ((size_t)((len
+= ret
) + 2) > sizeof(buf
)))
186 if (write(vty
->wfd
, buf
, len
) < 0) {
187 if (ERRNO_IO_RETRY(errno
))
188 /* Kernel buffer is full, probably too much debugging
190 drop the data and ignore. */
192 /* Fatal I/O error. */
194 0; /* disable monitoring to avoid infinite recursion */
195 zlog_warn("%s: write failed to vty client fd %d, closing: %s",
196 __func__
, vty
->fd
, safe_strerror(errno
));
197 buffer_reset(vty
->obuf
);
198 /* cannot call vty_close, because a parent routine may still try
199 to access the vty struct */
200 vty
->status
= VTY_CLOSE
;
201 shutdown(vty
->fd
, SHUT_RDWR
);
207 /* Output current time to the vty. */
208 void vty_time_print(struct vty
*vty
, int cr
)
210 char buf
[QUAGGA_TIMESTAMP_LEN
];
212 if (quagga_timestamp(0, buf
, sizeof(buf
)) == 0) {
213 zlog_info("quagga_timestamp error");
217 vty_out(vty
, "%s\n", buf
);
219 vty_out(vty
, "%s ", buf
);
224 /* Say hello to vty interface. */
225 void vty_hello(struct vty
*vty
)
231 f
= fopen(host
.motdfile
, "r");
233 while (fgets(buf
, sizeof(buf
), f
)) {
235 /* work backwards to ignore trailling isspace()
237 for (s
= buf
+ strlen(buf
);
238 (s
> buf
) && isspace((int)*(s
- 1)); s
--)
241 vty_out(vty
, "%s\n", buf
);
245 vty_out(vty
, "MOTD file not found\n");
246 } else if (host
.motd
)
247 vty_out(vty
, "%s", host
.motd
);
250 /* Put out prompt and wait input from user. */
251 static void vty_prompt(struct vty
*vty
)
253 struct utsname names
;
254 const char *hostname
;
256 if (vty
->type
== VTY_TERM
) {
257 hostname
= host
.name
;
260 hostname
= names
.nodename
;
262 vty_out(vty
, cmd_prompt(vty
->node
), hostname
);
266 /* Send WILL TELOPT_ECHO to remote server. */
267 static void vty_will_echo(struct vty
*vty
)
269 unsigned char cmd
[] = {IAC
, WILL
, TELOPT_ECHO
, '\0'};
270 vty_out(vty
, "%s", cmd
);
273 /* Make suppress Go-Ahead telnet option. */
274 static void vty_will_suppress_go_ahead(struct vty
*vty
)
276 unsigned char cmd
[] = {IAC
, WILL
, TELOPT_SGA
, '\0'};
277 vty_out(vty
, "%s", cmd
);
280 /* Make don't use linemode over telnet. */
281 static void vty_dont_linemode(struct vty
*vty
)
283 unsigned char cmd
[] = {IAC
, DONT
, TELOPT_LINEMODE
, '\0'};
284 vty_out(vty
, "%s", cmd
);
287 /* Use window size. */
288 static void vty_do_window_size(struct vty
*vty
)
290 unsigned char cmd
[] = {IAC
, DO
, TELOPT_NAWS
, '\0'};
291 vty_out(vty
, "%s", cmd
);
294 #if 0 /* Currently not used. */
295 /* Make don't use lflow vty interface. */
297 vty_dont_lflow_ahead (struct vty
*vty
)
299 unsigned char cmd
[] = { IAC
, DONT
, TELOPT_LFLOW
, '\0' };
300 vty_out (vty
, "%s", cmd
);
304 /* Allocate new vty struct. */
305 struct vty
*vty_new()
307 struct vty
*new = XCALLOC(MTYPE_VTY
, sizeof(struct vty
));
309 new->fd
= new->wfd
= -1;
310 new->obuf
= buffer_new(0); /* Use default buffer size. */
311 new->buf
= XCALLOC(MTYPE_VTY
, VTY_BUFSIZ
);
312 new->error_buf
= XCALLOC(MTYPE_VTY
, VTY_BUFSIZ
);
313 new->max
= VTY_BUFSIZ
;
318 /* Authentication of vty */
319 static void vty_auth(struct vty
*vty
, char *buf
)
322 enum node_type next_node
= 0;
324 char *crypt(const char *, const char *);
329 passwd
= host
.password_encrypt
;
331 passwd
= host
.password
;
333 next_node
= host
.enable
? VIEW_NODE
: ENABLE_NODE
;
335 next_node
= VIEW_NODE
;
337 case AUTH_ENABLE_NODE
:
339 passwd
= host
.enable_encrypt
;
341 passwd
= host
.enable
;
342 next_node
= ENABLE_NODE
;
348 fail
= strcmp(crypt(buf
, passwd
), passwd
);
350 fail
= strcmp(buf
, passwd
);
356 vty
->node
= next_node
; /* Success ! */
359 if (vty
->fail
>= 3) {
360 if (vty
->node
== AUTH_NODE
) {
362 "%% Bad passwords, too many failures!\n");
363 vty
->status
= VTY_CLOSE
;
365 /* AUTH_ENABLE_NODE */
368 "%% Bad enable passwords, too many failures!\n");
369 vty
->status
= VTY_CLOSE
;
375 /* Command execution over the vty interface. */
376 static int vty_command(struct vty
*vty
, char *buf
)
380 const char *protocolname
;
384 * Log non empty command lines
389 /* Skip white spaces. */
390 while (isspace((int)*cp
) && *cp
!= '\0')
393 if (cp
!= NULL
&& *cp
!= '\0') {
395 char vty_str
[VTY_BUFSIZ
];
396 char prompt_str
[VTY_BUFSIZ
];
398 /* format the base vty info */
399 snprintf(vty_str
, sizeof(vty_str
), "vty[??]@%s", vty
->address
);
401 for (i
= 0; i
< vector_active(vtyvec
); i
++)
402 if (vty
== vector_slot(vtyvec
, i
)) {
403 snprintf(vty_str
, sizeof(vty_str
),
404 "vty[%d]@%s", i
, vty
->address
);
408 /* format the prompt */
409 snprintf(prompt_str
, sizeof(prompt_str
), cmd_prompt(vty
->node
),
412 /* now log the command */
413 zlog_err("%s%s", prompt_str
, buf
);
415 /* Split readline string up into the vector */
416 vline
= cmd_make_strvec(buf
);
421 #ifdef CONSUMED_TIME_CHECK
425 unsigned long realtime
, cputime
;
428 #endif /* CONSUMED_TIME_CHECK */
430 ret
= cmd_execute_command(vline
, vty
, NULL
, 0);
432 /* Get the name of the protocol if any */
433 protocolname
= frr_protoname
;
435 #ifdef CONSUMED_TIME_CHECK
437 if ((realtime
= thread_consumed_time(&after
, &before
, &cputime
))
438 > CONSUMED_TIME_CHECK
)
439 /* Warn about CPU hog that must be fixed. */
441 "SLOW COMMAND: command took %lums (cpu time %lums): %s",
442 realtime
/ 1000, cputime
/ 1000, buf
);
444 #endif /* CONSUMED_TIME_CHECK */
446 if (ret
!= CMD_SUCCESS
)
449 if (vty
->type
== VTY_FILE
)
450 vty_out(vty
, "Warning...\n");
452 case CMD_ERR_AMBIGUOUS
:
453 vty_out(vty
, "%% Ambiguous command.\n");
455 case CMD_ERR_NO_MATCH
:
456 vty_out(vty
, "%% [%s] Unknown command: %s\n",
459 case CMD_ERR_INCOMPLETE
:
460 vty_out(vty
, "%% Command incomplete.\n");
463 cmd_free_strvec(vline
);
468 static const char telnet_backward_char
= 0x08;
469 static const char telnet_space_char
= ' ';
471 /* Basic function to write buffer to vty. */
472 static void vty_write(struct vty
*vty
, const char *buf
, size_t nbytes
)
474 if ((vty
->node
== AUTH_NODE
) || (vty
->node
== AUTH_ENABLE_NODE
))
477 /* Should we do buffering here ? And make vty_flush (vty) ? */
478 buffer_put(vty
->obuf
, buf
, nbytes
);
481 /* Basic function to insert character into vty. */
482 static void vty_self_insert(struct vty
*vty
, char c
)
487 if (vty
->length
+ 1 >= VTY_BUFSIZ
)
490 length
= vty
->length
- vty
->cp
;
491 memmove(&vty
->buf
[vty
->cp
+ 1], &vty
->buf
[vty
->cp
], length
);
492 vty
->buf
[vty
->cp
] = c
;
494 vty_write(vty
, &vty
->buf
[vty
->cp
], length
+ 1);
495 for (i
= 0; i
< length
; i
++)
496 vty_write(vty
, &telnet_backward_char
, 1);
501 vty
->buf
[vty
->length
] = '\0';
504 /* Self insert character 'c' in overwrite mode. */
505 static void vty_self_insert_overwrite(struct vty
*vty
, char c
)
507 if (vty
->cp
== vty
->length
) {
508 vty_self_insert(vty
, c
);
512 vty
->buf
[vty
->cp
++] = c
;
513 vty_write(vty
, &c
, 1);
517 * Insert a string into vty->buf at the current cursor position.
519 * If the resultant string would be larger than VTY_BUFSIZ it is
522 static void vty_insert_word_overwrite(struct vty
*vty
, char *str
)
524 if (vty
->cp
== VTY_BUFSIZ
)
527 size_t nwrite
= MIN((int)strlen(str
), VTY_BUFSIZ
- vty
->cp
- 1);
528 memcpy(&vty
->buf
[vty
->cp
], str
, nwrite
);
530 vty
->length
= MAX(vty
->cp
, vty
->length
);
531 vty
->buf
[vty
->length
] = '\0';
532 vty_write(vty
, str
, nwrite
);
535 /* Forward character. */
536 static void vty_forward_char(struct vty
*vty
)
538 if (vty
->cp
< vty
->length
) {
539 vty_write(vty
, &vty
->buf
[vty
->cp
], 1);
544 /* Backward character. */
545 static void vty_backward_char(struct vty
*vty
)
549 vty_write(vty
, &telnet_backward_char
, 1);
553 /* Move to the beginning of the line. */
554 static void vty_beginning_of_line(struct vty
*vty
)
557 vty_backward_char(vty
);
560 /* Move to the end of the line. */
561 static void vty_end_of_line(struct vty
*vty
)
563 while (vty
->cp
< vty
->length
)
564 vty_forward_char(vty
);
567 static void vty_kill_line_from_beginning(struct vty
*);
568 static void vty_redraw_line(struct vty
*);
570 /* Print command line history. This function is called from
571 vty_next_line and vty_previous_line. */
572 static void vty_history_print(struct vty
*vty
)
576 vty_kill_line_from_beginning(vty
);
578 /* Get previous line from history buffer */
579 length
= strlen(vty
->hist
[vty
->hp
]);
580 memcpy(vty
->buf
, vty
->hist
[vty
->hp
], length
);
581 vty
->cp
= vty
->length
= length
;
582 vty
->buf
[vty
->length
] = '\0';
584 /* Redraw current line */
585 vty_redraw_line(vty
);
588 /* Show next command line history. */
589 static void vty_next_line(struct vty
*vty
)
593 if (vty
->hp
== vty
->hindex
)
596 /* Try is there history exist or not. */
598 if (try_index
== (VTY_MAXHIST
- 1))
603 /* If there is not history return. */
604 if (vty
->hist
[try_index
] == NULL
)
609 vty_history_print(vty
);
612 /* Show previous command line history. */
613 static void vty_previous_line(struct vty
*vty
)
619 try_index
= VTY_MAXHIST
- 1;
623 if (vty
->hist
[try_index
] == NULL
)
628 vty_history_print(vty
);
631 /* This function redraw all of the command line character. */
632 static void vty_redraw_line(struct vty
*vty
)
634 vty_write(vty
, vty
->buf
, vty
->length
);
635 vty
->cp
= vty
->length
;
639 static void vty_forward_word(struct vty
*vty
)
641 while (vty
->cp
!= vty
->length
&& vty
->buf
[vty
->cp
] != ' ')
642 vty_forward_char(vty
);
644 while (vty
->cp
!= vty
->length
&& vty
->buf
[vty
->cp
] == ' ')
645 vty_forward_char(vty
);
648 /* Backward word without skipping training space. */
649 static void vty_backward_pure_word(struct vty
*vty
)
651 while (vty
->cp
> 0 && vty
->buf
[vty
->cp
- 1] != ' ')
652 vty_backward_char(vty
);
656 static void vty_backward_word(struct vty
*vty
)
658 while (vty
->cp
> 0 && vty
->buf
[vty
->cp
- 1] == ' ')
659 vty_backward_char(vty
);
661 while (vty
->cp
> 0 && vty
->buf
[vty
->cp
- 1] != ' ')
662 vty_backward_char(vty
);
665 /* When '^D' is typed at the beginning of the line we move to the down
667 static void vty_down_level(struct vty
*vty
)
675 /* When '^Z' is received from vty, move down to the enable mode. */
676 static void vty_end_config(struct vty
*vty
)
695 case BGP_VRF_POLICY_NODE
:
696 case BGP_VNC_DEFAULTS_NODE
:
697 case BGP_VNC_NVE_GROUP_NODE
:
698 case BGP_VNC_L2_GROUP_NODE
:
712 case LDP_IPV4_IFACE_NODE
:
713 case LDP_IPV6_IFACE_NODE
:
715 case LDP_PSEUDOWIRE_NODE
:
718 case KEYCHAIN_KEY_NODE
:
722 case BGP_EVPN_VNI_NODE
:
723 vty_config_unlock(vty
);
724 vty
->node
= ENABLE_NODE
;
727 /* Unknown node, we have to ignore it. */
735 /* Delete a charcter at the current point. */
736 static void vty_delete_char(struct vty
*vty
)
741 if (vty
->length
== 0) {
746 if (vty
->cp
== vty
->length
)
747 return; /* completion need here? */
749 size
= vty
->length
- vty
->cp
;
752 memmove(&vty
->buf
[vty
->cp
], &vty
->buf
[vty
->cp
+ 1], size
- 1);
753 vty
->buf
[vty
->length
] = '\0';
755 if (vty
->node
== AUTH_NODE
|| vty
->node
== AUTH_ENABLE_NODE
)
758 vty_write(vty
, &vty
->buf
[vty
->cp
], size
- 1);
759 vty_write(vty
, &telnet_space_char
, 1);
761 for (i
= 0; i
< size
; i
++)
762 vty_write(vty
, &telnet_backward_char
, 1);
765 /* Delete a character before the point. */
766 static void vty_delete_backward_char(struct vty
*vty
)
771 vty_backward_char(vty
);
772 vty_delete_char(vty
);
775 /* Kill rest of line from current point. */
776 static void vty_kill_line(struct vty
*vty
)
781 size
= vty
->length
- vty
->cp
;
786 for (i
= 0; i
< size
; i
++)
787 vty_write(vty
, &telnet_space_char
, 1);
788 for (i
= 0; i
< size
; i
++)
789 vty_write(vty
, &telnet_backward_char
, 1);
791 memset(&vty
->buf
[vty
->cp
], 0, size
);
792 vty
->length
= vty
->cp
;
795 /* Kill line from the beginning. */
796 static void vty_kill_line_from_beginning(struct vty
*vty
)
798 vty_beginning_of_line(vty
);
802 /* Delete a word before the point. */
803 static void vty_forward_kill_word(struct vty
*vty
)
805 while (vty
->cp
!= vty
->length
&& vty
->buf
[vty
->cp
] == ' ')
806 vty_delete_char(vty
);
807 while (vty
->cp
!= vty
->length
&& vty
->buf
[vty
->cp
] != ' ')
808 vty_delete_char(vty
);
811 /* Delete a word before the point. */
812 static void vty_backward_kill_word(struct vty
*vty
)
814 while (vty
->cp
> 0 && vty
->buf
[vty
->cp
- 1] == ' ')
815 vty_delete_backward_char(vty
);
816 while (vty
->cp
> 0 && vty
->buf
[vty
->cp
- 1] != ' ')
817 vty_delete_backward_char(vty
);
820 /* Transpose chars before or at the point. */
821 static void vty_transpose_chars(struct vty
*vty
)
825 /* If length is short or point is near by the beginning of line then
827 if (vty
->length
< 2 || vty
->cp
< 1)
830 /* In case of point is located at the end of the line. */
831 if (vty
->cp
== vty
->length
) {
832 c1
= vty
->buf
[vty
->cp
- 1];
833 c2
= vty
->buf
[vty
->cp
- 2];
835 vty_backward_char(vty
);
836 vty_backward_char(vty
);
837 vty_self_insert_overwrite(vty
, c1
);
838 vty_self_insert_overwrite(vty
, c2
);
840 c1
= vty
->buf
[vty
->cp
];
841 c2
= vty
->buf
[vty
->cp
- 1];
843 vty_backward_char(vty
);
844 vty_self_insert_overwrite(vty
, c1
);
845 vty_self_insert_overwrite(vty
, c2
);
849 /* Do completion at vty interface. */
850 static void vty_complete_command(struct vty
*vty
)
854 char **matched
= NULL
;
857 if (vty
->node
== AUTH_NODE
|| vty
->node
== AUTH_ENABLE_NODE
)
860 vline
= cmd_make_strvec(vty
->buf
);
864 /* In case of 'help \t'. */
865 if (isspace((int)vty
->buf
[vty
->length
- 1]))
866 vector_set(vline
, NULL
);
868 matched
= cmd_complete_command(vline
, vty
, &ret
);
870 cmd_free_strvec(vline
);
874 case CMD_ERR_AMBIGUOUS
:
875 vty_out(vty
, "%% Ambiguous command.\n");
877 vty_redraw_line(vty
);
879 case CMD_ERR_NO_MATCH
:
880 /* vty_out (vty, "%% There is no matched command.\n"); */
882 vty_redraw_line(vty
);
884 case CMD_COMPLETE_FULL_MATCH
:
886 /* 2016-11-28 equinox -- need to debug, SEGV here */
887 vty_out(vty
, "%% CLI BUG: FULL_MATCH with NULL str\n");
889 vty_redraw_line(vty
);
893 vty_redraw_line(vty
);
894 vty_backward_pure_word(vty
);
895 vty_insert_word_overwrite(vty
, matched
[0]);
896 vty_self_insert(vty
, ' ');
897 XFREE(MTYPE_COMPLETION
, matched
[0]);
899 case CMD_COMPLETE_MATCH
:
901 vty_redraw_line(vty
);
902 vty_backward_pure_word(vty
);
903 vty_insert_word_overwrite(vty
, matched
[0]);
904 XFREE(MTYPE_COMPLETION
, matched
[0]);
906 case CMD_COMPLETE_LIST_MATCH
:
907 for (i
= 0; matched
[i
] != NULL
; i
++) {
908 if (i
!= 0 && ((i
% 6) == 0))
910 vty_out(vty
, "%-10s ", matched
[i
]);
911 XFREE(MTYPE_COMPLETION
, matched
[i
]);
916 vty_redraw_line(vty
);
918 case CMD_ERR_NOTHING_TODO
:
920 vty_redraw_line(vty
);
926 XFREE(MTYPE_TMP
, matched
);
929 static void vty_describe_fold(struct vty
*vty
, int cmd_width
,
930 unsigned int desc_width
, struct cmd_token
*token
)
938 if (desc_width
<= 0) {
939 vty_out(vty
, " %-*s %s\n", cmd_width
, cmd
, token
->desc
);
943 buf
= XCALLOC(MTYPE_TMP
, strlen(token
->desc
) + 1);
945 for (p
= token
->desc
; strlen(p
) > desc_width
; p
+= pos
+ 1) {
946 for (pos
= desc_width
; pos
> 0; pos
--)
947 if (*(p
+ pos
) == ' ')
953 strncpy(buf
, p
, pos
);
955 vty_out(vty
, " %-*s %s\n", cmd_width
, cmd
, buf
);
960 vty_out(vty
, " %-*s %s\n", cmd_width
, cmd
, p
);
962 XFREE(MTYPE_TMP
, buf
);
965 /* Describe matched command function. */
966 static void vty_describe_command(struct vty
*vty
)
971 unsigned int i
, width
, desc_width
;
972 struct cmd_token
*token
, *token_cr
= NULL
;
974 vline
= cmd_make_strvec(vty
->buf
);
976 /* In case of '> ?'. */
978 vline
= vector_init(1);
979 vector_set(vline
, NULL
);
980 } else if (isspace((int)vty
->buf
[vty
->length
- 1]))
981 vector_set(vline
, NULL
);
983 describe
= cmd_describe_command(vline
, vty
, &ret
);
987 /* Ambiguous error. */
989 case CMD_ERR_AMBIGUOUS
:
990 vty_out(vty
, "%% Ambiguous command.\n");
993 case CMD_ERR_NO_MATCH
:
994 vty_out(vty
, "%% There is no matched command.\n");
999 /* Get width of command string. */
1001 for (i
= 0; i
< vector_active(describe
); i
++)
1002 if ((token
= vector_slot(describe
, i
)) != NULL
) {
1005 if (token
->text
[0] == '\0')
1008 len
= strlen(token
->text
);
1014 /* Get width of description string. */
1015 desc_width
= vty
->width
- (width
+ 6);
1017 /* Print out description. */
1018 for (i
= 0; i
< vector_active(describe
); i
++)
1019 if ((token
= vector_slot(describe
, i
)) != NULL
) {
1020 if (token
->text
[0] == '\0')
1023 if (strcmp(token
->text
, CMD_CR_TEXT
) == 0) {
1029 vty_out(vty
, " %-s\n", token
->text
);
1030 else if (desc_width
>= strlen(token
->desc
))
1031 vty_out(vty
, " %-*s %s\n", width
, token
->text
,
1034 vty_describe_fold(vty
, width
, desc_width
,
1037 if (IS_VARYING_TOKEN(token
->type
)) {
1038 const char *ref
= vector_slot(
1039 vline
, vector_active(vline
) - 1);
1041 vector varcomps
= vector_init(VECTOR_MIN_SIZE
);
1042 cmd_variable_complete(token
, ref
, varcomps
);
1044 if (vector_active(varcomps
) > 0) {
1045 char *ac
= cmd_variable_comp2str(
1046 varcomps
, vty
->width
);
1047 vty_out(vty
, "%s\n", ac
);
1048 XFREE(MTYPE_TMP
, ac
);
1051 vector_free(varcomps
);
1054 vty_out (vty
, " %-*s %s\n", width
1055 desc
->cmd
[0] == '.' ? desc
->cmd
+ 1 : desc
->cmd
,
1056 desc
->str
? desc
->str
: "");
1060 if ((token
= token_cr
)) {
1062 vty_out(vty
, " %-s\n", token
->text
);
1063 else if (desc_width
>= strlen(token
->desc
))
1064 vty_out(vty
, " %-*s %s\n", width
, token
->text
,
1067 vty_describe_fold(vty
, width
, desc_width
, token
);
1071 cmd_free_strvec(vline
);
1073 vector_free(describe
);
1076 vty_redraw_line(vty
);
1079 static void vty_clear_buf(struct vty
*vty
)
1081 memset(vty
->buf
, 0, vty
->max
);
1084 /* ^C stop current input and do not add command line to the history. */
1085 static void vty_stop_input(struct vty
*vty
)
1087 vty
->cp
= vty
->length
= 0;
1091 switch (vty
->node
) {
1094 /* Nothing to do. */
1097 case INTERFACE_NODE
:
1110 case LDP_IPV4_IFACE_NODE
:
1111 case LDP_IPV6_IFACE_NODE
:
1112 case LDP_L2VPN_NODE
:
1113 case LDP_PSEUDOWIRE_NODE
:
1116 case KEYCHAIN_KEY_NODE
:
1120 vty_config_unlock(vty
);
1121 vty
->node
= ENABLE_NODE
;
1124 /* Unknown node, we have to ignore it. */
1129 /* Set history pointer to the latest one. */
1130 vty
->hp
= vty
->hindex
;
1133 /* Add current command line to the history buffer. */
1134 static void vty_hist_add(struct vty
*vty
)
1138 if (vty
->length
== 0)
1141 index
= vty
->hindex
? vty
->hindex
- 1 : VTY_MAXHIST
- 1;
1143 /* Ignore the same string as previous one. */
1144 if (vty
->hist
[index
])
1145 if (strcmp(vty
->buf
, vty
->hist
[index
]) == 0) {
1146 vty
->hp
= vty
->hindex
;
1150 /* Insert history entry. */
1151 if (vty
->hist
[vty
->hindex
])
1152 XFREE(MTYPE_VTY_HIST
, vty
->hist
[vty
->hindex
]);
1153 vty
->hist
[vty
->hindex
] = XSTRDUP(MTYPE_VTY_HIST
, vty
->buf
);
1155 /* History index rotation. */
1157 if (vty
->hindex
== VTY_MAXHIST
)
1160 vty
->hp
= vty
->hindex
;
1163 /* #define TELNET_OPTION_DEBUG */
1165 /* Get telnet window size. */
1166 static int vty_telnet_option(struct vty
*vty
, unsigned char *buf
, int nbytes
)
1168 #ifdef TELNET_OPTION_DEBUG
1171 for (i
= 0; i
< nbytes
; i
++) {
1174 vty_out(vty
, "IAC ");
1177 vty_out(vty
, "WILL ");
1180 vty_out(vty
, "WONT ");
1183 vty_out(vty
, "DO ");
1186 vty_out(vty
, "DONT ");
1189 vty_out(vty
, "SB ");
1192 vty_out(vty
, "SE ");
1195 vty_out(vty
, "TELOPT_ECHO \n");
1198 vty_out(vty
, "TELOPT_SGA \n");
1201 vty_out(vty
, "TELOPT_NAWS \n");
1204 vty_out(vty
, "%x ", buf
[i
]);
1210 #endif /* TELNET_OPTION_DEBUG */
1215 vty
->iac_sb_in_progress
= 1;
1219 if (!vty
->iac_sb_in_progress
)
1222 if ((vty
->sb_len
== 0) || (vty
->sb_buf
[0] == '\0')) {
1223 vty
->iac_sb_in_progress
= 0;
1226 switch (vty
->sb_buf
[0]) {
1228 if (vty
->sb_len
!= TELNET_NAWS_SB_LEN
)
1230 "RFC 1073 violation detected: telnet NAWS option "
1231 "should send %d characters, but we received %lu",
1233 (u_long
)vty
->sb_len
);
1234 else if (sizeof(vty
->sb_buf
) < TELNET_NAWS_SB_LEN
)
1236 "Bug detected: sizeof(vty->sb_buf) %lu < %d, "
1237 "too small to handle the telnet NAWS option",
1238 (u_long
)sizeof(vty
->sb_buf
),
1239 TELNET_NAWS_SB_LEN
);
1241 vty
->width
= ((vty
->sb_buf
[1] << 8)
1243 vty
->height
= ((vty
->sb_buf
[3] << 8)
1245 #ifdef TELNET_OPTION_DEBUG
1247 "TELNET NAWS window size negotiation completed: "
1248 "width %d, height %d\n",
1249 vty
->width
, vty
->height
);
1254 vty
->iac_sb_in_progress
= 0;
1264 /* Execute current command line. */
1265 static int vty_execute(struct vty
*vty
)
1271 switch (vty
->node
) {
1273 case AUTH_ENABLE_NODE
:
1274 vty_auth(vty
, vty
->buf
);
1277 ret
= vty_command(vty
, vty
->buf
);
1278 if (vty
->type
== VTY_TERM
)
1283 /* Clear command line buffer. */
1284 vty
->cp
= vty
->length
= 0;
1287 if (vty
->status
!= VTY_CLOSE
)
1293 #define CONTROL(X) ((X) - '@')
1294 #define VTY_NORMAL 0
1295 #define VTY_PRE_ESCAPE 1
1296 #define VTY_ESCAPE 2
1298 /* Escape character command map. */
1299 static void vty_escape_map(unsigned char c
, struct vty
*vty
)
1303 vty_previous_line(vty
);
1309 vty_forward_char(vty
);
1312 vty_backward_char(vty
);
1318 /* Go back to normal mode. */
1319 vty
->escape
= VTY_NORMAL
;
1322 /* Quit print out to the buffer. */
1323 static void vty_buffer_reset(struct vty
*vty
)
1325 buffer_reset(vty
->obuf
);
1327 vty_redraw_line(vty
);
1330 /* Read data via vty socket. */
1331 static int vty_read(struct thread
*thread
)
1335 unsigned char buf
[VTY_READ_BUFSIZ
];
1337 int vty_sock
= THREAD_FD(thread
);
1338 struct vty
*vty
= THREAD_ARG(thread
);
1341 /* Read raw data from socket */
1342 if ((nbytes
= read(vty
->fd
, buf
, VTY_READ_BUFSIZ
)) <= 0) {
1344 if (ERRNO_IO_RETRY(errno
)) {
1345 vty_event(VTY_READ
, vty_sock
, vty
);
1348 vty
->monitor
= 0; /* disable monitoring to avoid
1349 infinite recursion */
1351 "%s: read error on vty client fd %d, closing: %s",
1352 __func__
, vty
->fd
, safe_strerror(errno
));
1353 buffer_reset(vty
->obuf
);
1355 vty
->status
= VTY_CLOSE
;
1358 for (i
= 0; i
< nbytes
; i
++) {
1359 if (buf
[i
] == IAC
) {
1368 if (vty
->iac_sb_in_progress
&& !vty
->iac
) {
1369 if (vty
->sb_len
< sizeof(vty
->sb_buf
))
1370 vty
->sb_buf
[vty
->sb_len
] = buf
[i
];
1376 /* In case of telnet command */
1378 ret
= vty_telnet_option(vty
, buf
+ i
, nbytes
- i
);
1385 if (vty
->status
== VTY_MORE
) {
1390 vty_buffer_reset(vty
);
1392 #if 0 /* More line does not work for "show ip bgp". */
1395 vty
->status
= VTY_MORELINE
;
1404 /* Escape character. */
1405 if (vty
->escape
== VTY_ESCAPE
) {
1406 vty_escape_map(buf
[i
], vty
);
1410 /* Pre-escape status. */
1411 if (vty
->escape
== VTY_PRE_ESCAPE
) {
1414 vty
->escape
= VTY_ESCAPE
;
1417 vty_backward_word(vty
);
1418 vty
->escape
= VTY_NORMAL
;
1421 vty_forward_word(vty
);
1422 vty
->escape
= VTY_NORMAL
;
1425 vty_forward_kill_word(vty
);
1426 vty
->escape
= VTY_NORMAL
;
1430 vty_backward_kill_word(vty
);
1431 vty
->escape
= VTY_NORMAL
;
1434 vty
->escape
= VTY_NORMAL
;
1442 vty_beginning_of_line(vty
);
1445 vty_backward_char(vty
);
1448 vty_stop_input(vty
);
1451 vty_delete_char(vty
);
1454 vty_end_of_line(vty
);
1457 vty_forward_char(vty
);
1461 vty_delete_backward_char(vty
);
1470 vty_previous_line(vty
);
1473 vty_transpose_chars(vty
);
1476 vty_kill_line_from_beginning(vty
);
1479 vty_backward_kill_word(vty
);
1482 vty_end_config(vty
);
1490 vty_complete_command(vty
);
1493 if (vty
->node
== AUTH_NODE
1494 || vty
->node
== AUTH_ENABLE_NODE
)
1495 vty_self_insert(vty
, buf
[i
]);
1497 vty_describe_command(vty
);
1500 if (i
+ 1 < nbytes
&& buf
[i
+ 1] == '[') {
1501 vty
->escape
= VTY_ESCAPE
;
1504 vty
->escape
= VTY_PRE_ESCAPE
;
1507 if (buf
[i
] > 31 && buf
[i
] < 127)
1508 vty_self_insert(vty
, buf
[i
]);
1514 if (vty
->status
== VTY_CLOSE
)
1517 vty_event(VTY_WRITE
, vty
->wfd
, vty
);
1518 vty_event(VTY_READ
, vty_sock
, vty
);
1523 /* Flush buffer to the vty. */
1524 static int vty_flush(struct thread
*thread
)
1527 buffer_status_t flushrc
;
1528 int vty_sock
= THREAD_FD(thread
);
1529 struct vty
*vty
= THREAD_ARG(thread
);
1531 vty
->t_write
= NULL
;
1533 /* Tempolary disable read thread. */
1534 if ((vty
->lines
== 0) && vty
->t_read
) {
1535 thread_cancel(vty
->t_read
);
1539 /* Function execution continue. */
1540 erase
= ((vty
->status
== VTY_MORE
|| vty
->status
== VTY_MORELINE
));
1542 /* N.B. if width is 0, that means we don't know the window size. */
1543 if ((vty
->lines
== 0) || (vty
->width
== 0) || (vty
->height
== 0))
1544 flushrc
= buffer_flush_available(vty
->obuf
, vty_sock
);
1545 else if (vty
->status
== VTY_MORELINE
)
1546 flushrc
= buffer_flush_window(vty
->obuf
, vty_sock
, vty
->width
,
1549 flushrc
= buffer_flush_window(
1550 vty
->obuf
, vty_sock
, vty
->width
,
1551 vty
->lines
>= 0 ? vty
->lines
: vty
->height
, erase
, 0);
1555 0; /* disable monitoring to avoid infinite recursion */
1556 zlog_warn("buffer_flush failed on vty client fd %d, closing",
1558 buffer_reset(vty
->obuf
);
1562 if (vty
->status
== VTY_CLOSE
)
1565 vty
->status
= VTY_NORMAL
;
1566 if (vty
->lines
== 0)
1567 vty_event(VTY_READ
, vty_sock
, vty
);
1570 case BUFFER_PENDING
:
1571 /* There is more data waiting to be written. */
1572 vty
->status
= VTY_MORE
;
1573 if (vty
->lines
== 0)
1574 vty_event(VTY_WRITE
, vty_sock
, vty
);
1581 /* allocate and initialise vty */
1582 static struct vty
*vty_new_init(int vty_sock
)
1588 vty
->wfd
= vty_sock
;
1589 vty
->type
= VTY_TERM
;
1590 vty
->node
= AUTH_NODE
;
1595 memset(vty
->hist
, 0, sizeof(vty
->hist
));
1598 vector_set_index(vtyvec
, vty_sock
, vty
);
1599 vty
->status
= VTY_NORMAL
;
1602 vty
->iac_sb_in_progress
= 0;
1608 /* Create new vty structure. */
1609 static struct vty
*vty_create(int vty_sock
, union sockunion
*su
)
1611 char buf
[SU_ADDRSTRLEN
];
1614 sockunion2str(su
, buf
, SU_ADDRSTRLEN
);
1616 /* Allocate new vty structure and set up default values. */
1617 vty
= vty_new_init(vty_sock
);
1619 /* configurable parameters not part of basic init */
1620 vty
->v_timeout
= vty_timeout_val
;
1621 strcpy(vty
->address
, buf
);
1622 if (no_password_check
) {
1624 vty
->node
= ENABLE_NODE
;
1626 vty
->node
= VIEW_NODE
;
1628 if (host
.lines
>= 0)
1629 vty
->lines
= host
.lines
;
1631 if (!no_password_check
) {
1632 /* Vty is not available if password isn't set. */
1633 if (host
.password
== NULL
&& host
.password_encrypt
== NULL
) {
1634 vty_out(vty
, "Vty password is not set.\n");
1635 vty
->status
= VTY_CLOSE
;
1641 /* Say hello to the world. */
1643 if (!no_password_check
)
1644 vty_out(vty
, "\nUser Access Verification\n\n");
1646 /* Setting up terminal. */
1648 vty_will_suppress_go_ahead(vty
);
1650 vty_dont_linemode(vty
);
1651 vty_do_window_size(vty
);
1652 /* vty_dont_lflow_ahead (vty); */
1656 /* Add read/write thread. */
1657 vty_event(VTY_WRITE
, vty_sock
, vty
);
1658 vty_event(VTY_READ
, vty_sock
, vty
);
1663 /* create vty for stdio */
1664 static struct termios stdio_orig_termios
;
1665 static struct vty
*stdio_vty
= NULL
;
1666 static bool stdio_termios
= false;
1667 static void (*stdio_vty_atclose
)(int isexit
);
1669 static void vty_stdio_reset(int isexit
)
1673 tcsetattr(0, TCSANOW
, &stdio_orig_termios
);
1674 stdio_termios
= false;
1678 if (stdio_vty_atclose
)
1679 stdio_vty_atclose(isexit
);
1680 stdio_vty_atclose
= NULL
;
1684 static void vty_stdio_atexit(void)
1689 void vty_stdio_suspend(void)
1694 if (stdio_vty
->t_write
)
1695 thread_cancel(stdio_vty
->t_write
);
1696 if (stdio_vty
->t_read
)
1697 thread_cancel(stdio_vty
->t_read
);
1698 if (stdio_vty
->t_timeout
)
1699 thread_cancel(stdio_vty
->t_timeout
);
1702 tcsetattr(0, TCSANOW
, &stdio_orig_termios
);
1703 stdio_termios
= false;
1706 void vty_stdio_resume(void)
1711 if (!tcgetattr(0, &stdio_orig_termios
)) {
1712 struct termios termios
;
1714 termios
= stdio_orig_termios
;
1715 termios
.c_iflag
&= ~(IGNBRK
| BRKINT
| PARMRK
| ISTRIP
| INLCR
1716 | IGNCR
| ICRNL
| IXON
);
1717 termios
.c_oflag
&= ~OPOST
;
1718 termios
.c_lflag
&= ~(ECHO
| ECHONL
| ICANON
| IEXTEN
);
1719 termios
.c_cflag
&= ~(CSIZE
| PARENB
);
1720 termios
.c_cflag
|= CS8
;
1721 tcsetattr(0, TCSANOW
, &termios
);
1722 stdio_termios
= true;
1725 vty_prompt(stdio_vty
);
1727 /* Add read/write thread. */
1728 vty_event(VTY_WRITE
, 1, stdio_vty
);
1729 vty_event(VTY_READ
, 0, stdio_vty
);
1732 void vty_stdio_close(void)
1736 vty_close(stdio_vty
);
1739 struct vty
*vty_stdio(void (*atclose
)(int isexit
))
1743 /* refuse creating two vtys on stdio */
1747 vty
= stdio_vty
= vty_new_init(0);
1748 stdio_vty_atclose
= atclose
;
1751 /* always have stdio vty in a known _unchangeable_ state, don't want
1753 * to have any effect here to make sure scripting this works as intended
1755 vty
->node
= ENABLE_NODE
;
1757 strcpy(vty
->address
, "console");
1763 /* Accept connection from the network. */
1764 static int vty_accept(struct thread
*thread
)
1772 struct access_list
*acl
= NULL
;
1773 char buf
[SU_ADDRSTRLEN
];
1775 accept_sock
= THREAD_FD(thread
);
1777 /* We continue hearing vty socket. */
1778 vty_event(VTY_SERV
, accept_sock
, NULL
);
1780 memset(&su
, 0, sizeof(union sockunion
));
1782 /* We can handle IPv4 or IPv6 socket. */
1783 vty_sock
= sockunion_accept(accept_sock
, &su
);
1785 zlog_warn("can't accept vty socket : %s", safe_strerror(errno
));
1788 set_nonblocking(vty_sock
);
1789 set_cloexec(vty_sock
);
1791 sockunion2hostprefix(&su
, &p
);
1793 /* VTY's accesslist apply. */
1794 if (p
.family
== AF_INET
&& vty_accesslist_name
) {
1795 if ((acl
= access_list_lookup(AFI_IP
, vty_accesslist_name
))
1796 && (access_list_apply(acl
, &p
) == FILTER_DENY
)) {
1797 zlog_info("Vty connection refused from %s",
1798 sockunion2str(&su
, buf
, SU_ADDRSTRLEN
));
1801 /* continue accepting connections */
1802 vty_event(VTY_SERV
, accept_sock
, NULL
);
1808 /* VTY's ipv6 accesslist apply. */
1809 if (p
.family
== AF_INET6
&& vty_ipv6_accesslist_name
) {
1810 if ((acl
= access_list_lookup(AFI_IP6
,
1811 vty_ipv6_accesslist_name
))
1812 && (access_list_apply(acl
, &p
) == FILTER_DENY
)) {
1813 zlog_info("Vty connection refused from %s",
1814 sockunion2str(&su
, buf
, SU_ADDRSTRLEN
));
1817 /* continue accepting connections */
1818 vty_event(VTY_SERV
, accept_sock
, NULL
);
1825 ret
= setsockopt(vty_sock
, IPPROTO_TCP
, TCP_NODELAY
, (char *)&on
,
1828 zlog_info("can't set sockopt to vty_sock : %s",
1829 safe_strerror(errno
));
1831 zlog_info("Vty connection from %s",
1832 sockunion2str(&su
, buf
, SU_ADDRSTRLEN
));
1834 vty_create(vty_sock
, &su
);
1839 static void vty_serv_sock_addrinfo(const char *hostname
, unsigned short port
)
1842 struct addrinfo req
;
1843 struct addrinfo
*ainfo
;
1844 struct addrinfo
*ainfo_save
;
1846 char port_str
[BUFSIZ
];
1848 memset(&req
, 0, sizeof(struct addrinfo
));
1849 req
.ai_flags
= AI_PASSIVE
;
1850 req
.ai_family
= AF_UNSPEC
;
1851 req
.ai_socktype
= SOCK_STREAM
;
1852 sprintf(port_str
, "%d", port
);
1853 port_str
[sizeof(port_str
) - 1] = '\0';
1855 ret
= getaddrinfo(hostname
, port_str
, &req
, &ainfo
);
1858 zlog_err("getaddrinfo failed: %s", gai_strerror(ret
));
1865 if (ainfo
->ai_family
!= AF_INET
&& ainfo
->ai_family
!= AF_INET6
)
1868 sock
= socket(ainfo
->ai_family
, ainfo
->ai_socktype
,
1869 ainfo
->ai_protocol
);
1873 sockopt_v6only(ainfo
->ai_family
, sock
);
1874 sockopt_reuseaddr(sock
);
1875 sockopt_reuseport(sock
);
1878 ret
= bind(sock
, ainfo
->ai_addr
, ainfo
->ai_addrlen
);
1880 close(sock
); /* Avoid sd leak. */
1884 ret
= listen(sock
, 3);
1886 close(sock
); /* Avoid sd leak. */
1890 vty_event(VTY_SERV
, sock
, NULL
);
1891 } while ((ainfo
= ainfo
->ai_next
) != NULL
);
1893 freeaddrinfo(ainfo_save
);
1897 /* For sockaddr_un. */
1900 /* VTY shell UNIX domain socket. */
1901 static void vty_serv_un(const char *path
)
1905 struct sockaddr_un serv
;
1907 struct zprivs_ids_t ids
;
1909 /* First of all, unlink existing socket */
1913 old_mask
= umask(0007);
1915 /* Make UNIX domain socket. */
1916 sock
= socket(AF_UNIX
, SOCK_STREAM
, 0);
1918 zlog_err("Cannot create unix stream socket: %s",
1919 safe_strerror(errno
));
1923 /* Make server socket. */
1924 memset(&serv
, 0, sizeof(struct sockaddr_un
));
1925 serv
.sun_family
= AF_UNIX
;
1926 strlcpy(serv
.sun_path
, path
, sizeof(serv
.sun_path
));
1927 #ifdef HAVE_STRUCT_SOCKADDR_UN_SUN_LEN
1928 len
= serv
.sun_len
= SUN_LEN(&serv
);
1930 len
= sizeof(serv
.sun_family
) + strlen(serv
.sun_path
);
1931 #endif /* HAVE_STRUCT_SOCKADDR_UN_SUN_LEN */
1935 ret
= bind(sock
, (struct sockaddr
*)&serv
, len
);
1937 zlog_err("Cannot bind path %s: %s", path
, safe_strerror(errno
));
1938 close(sock
); /* Avoid sd leak. */
1942 ret
= listen(sock
, 5);
1944 zlog_err("listen(fd %d) failed: %s", sock
,
1945 safe_strerror(errno
));
1946 close(sock
); /* Avoid sd leak. */
1952 zprivs_get_ids(&ids
);
1954 /* Hack: ids.gid_vty is actually a uint, but we stored -1 in it
1955 earlier for the case when we don't need to chown the file
1956 type casting it here to make a compare */
1957 if ((int)ids
.gid_vty
> 0) {
1958 /* set group of socket */
1959 if (chown(path
, -1, ids
.gid_vty
)) {
1960 zlog_err("vty_serv_un: could chown socket, %s",
1961 safe_strerror(errno
));
1965 vty_event(VTYSH_SERV
, sock
, NULL
);
1968 /* #define VTYSH_DEBUG 1 */
1970 static int vtysh_accept(struct thread
*thread
)
1975 struct sockaddr_un client
;
1978 accept_sock
= THREAD_FD(thread
);
1980 vty_event(VTYSH_SERV
, accept_sock
, NULL
);
1982 memset(&client
, 0, sizeof(struct sockaddr_un
));
1983 client_len
= sizeof(struct sockaddr_un
);
1985 sock
= accept(accept_sock
, (struct sockaddr
*)&client
,
1986 (socklen_t
*)&client_len
);
1989 zlog_warn("can't accept vty socket : %s", safe_strerror(errno
));
1993 if (set_nonblocking(sock
) < 0) {
1995 "vtysh_accept: could not set vty socket %d to non-blocking,"
1997 sock
, safe_strerror(errno
));
2004 printf("VTY shell accept\n");
2005 #endif /* VTYSH_DEBUG */
2010 vty
->type
= VTY_SHELL_SERV
;
2011 vty
->node
= VIEW_NODE
;
2013 vty_event(VTYSH_READ
, sock
, vty
);
2018 static int vtysh_flush(struct vty
*vty
)
2020 switch (buffer_flush_available(vty
->obuf
, vty
->wfd
)) {
2021 case BUFFER_PENDING
:
2022 vty_event(VTYSH_WRITE
, vty
->wfd
, vty
);
2026 0; /* disable monitoring to avoid infinite recursion */
2027 zlog_warn("%s: write error to fd %d, closing", __func__
,
2029 buffer_reset(vty
->obuf
);
2039 static int vtysh_read(struct thread
*thread
)
2045 unsigned char buf
[VTY_READ_BUFSIZ
];
2047 u_char header
[4] = {0, 0, 0, 0};
2049 sock
= THREAD_FD(thread
);
2050 vty
= THREAD_ARG(thread
);
2053 if ((nbytes
= read(sock
, buf
, VTY_READ_BUFSIZ
)) <= 0) {
2055 if (ERRNO_IO_RETRY(errno
)) {
2056 vty_event(VTYSH_READ
, sock
, vty
);
2059 vty
->monitor
= 0; /* disable monitoring to avoid
2060 infinite recursion */
2062 "%s: read failed on vtysh client fd %d, closing: %s",
2063 __func__
, sock
, safe_strerror(errno
));
2065 buffer_reset(vty
->obuf
);
2068 printf("close vtysh\n");
2069 #endif /* VTYSH_DEBUG */
2074 printf("line: %.*s\n", nbytes
, buf
);
2075 #endif /* VTYSH_DEBUG */
2077 if (vty
->length
+ nbytes
>= VTY_BUFSIZ
) {
2078 /* Clear command line buffer. */
2079 vty
->cp
= vty
->length
= 0;
2081 vty_out(vty
, "%% Command is too long.\n");
2083 for (p
= buf
; p
< buf
+ nbytes
; p
++) {
2084 vty
->buf
[vty
->length
++] = *p
;
2086 /* Pass this line to parser. */
2087 ret
= vty_execute(vty
);
2088 /* Note that vty_execute clears the command buffer and resets
2089 vty->length to 0. */
2091 /* Return result. */
2093 printf("result: %d\n", ret
);
2094 printf("vtysh node: %d\n", vty
->node
);
2095 #endif /* VTYSH_DEBUG */
2097 /* hack for asynchronous "write integrated"
2098 * - other commands in "buf" will be ditched
2099 * - input during pending config-write is
2101 if (ret
== CMD_SUSPEND
)
2104 /* warning: watchfrr hardcodes this result write
2107 buffer_put(vty
->obuf
, header
, 4);
2109 if (!vty
->t_write
&& (vtysh_flush(vty
) < 0))
2110 /* Try to flush results; exit if a write
2117 if (vty
->status
== VTY_CLOSE
)
2120 vty_event(VTYSH_READ
, sock
, vty
);
2125 static int vtysh_write(struct thread
*thread
)
2127 struct vty
*vty
= THREAD_ARG(thread
);
2129 vty
->t_write
= NULL
;
2136 /* Determine address family to bind. */
2137 void vty_serv_sock(const char *addr
, unsigned short port
, const char *path
)
2139 /* If port is set to 0, do not listen on TCP/IP at all! */
2141 vty_serv_sock_addrinfo(addr
, port
);
2148 /* Close vty interface. Warning: call this only from functions that
2149 will be careful not to access the vty afterwards (since it has
2150 now been freed). This is safest from top-level functions (called
2151 directly by the thread dispatcher). */
2152 void vty_close(struct vty
*vty
)
2155 bool was_stdio
= false;
2157 /* Cancel threads.*/
2159 thread_cancel(vty
->t_read
);
2161 thread_cancel(vty
->t_write
);
2163 thread_cancel(vty
->t_timeout
);
2166 buffer_flush_all(vty
->obuf
, vty
->wfd
);
2168 /* Free input buffer. */
2169 buffer_free(vty
->obuf
);
2171 /* Free command history. */
2172 for (i
= 0; i
< VTY_MAXHIST
; i
++)
2174 XFREE(MTYPE_VTY_HIST
, vty
->hist
[i
]);
2178 vector_unset(vtyvec
, vty
->fd
);
2180 if (vty
->wfd
> 0 && vty
->type
== VTY_FILE
)
2184 * note check is for fd > STDERR_FILENO, not fd != -1.
2185 * We never close stdin/stdout/stderr here, because we may be
2186 * running in foreground mode with logging to stdout. Also,
2187 * additionally, we'd need to replace these fds with /dev/null. */
2188 if (vty
->wfd
> STDERR_FILENO
&& vty
->wfd
!= vty
->fd
)
2190 if (vty
->fd
> STDERR_FILENO
) {
2196 XFREE(MTYPE_VTY
, vty
->buf
);
2199 XFREE(MTYPE_VTY
, vty
->error_buf
);
2201 /* Check configure. */
2202 vty_config_unlock(vty
);
2205 XFREE(MTYPE_VTY
, vty
);
2211 /* When time out occur output message then close connection. */
2212 static int vty_timeout(struct thread
*thread
)
2216 vty
= THREAD_ARG(thread
);
2217 vty
->t_timeout
= NULL
;
2221 buffer_reset(vty
->obuf
);
2222 vty_out(vty
, "\nVty connection is timed out.\n");
2224 /* Close connection. */
2225 vty
->status
= VTY_CLOSE
;
2231 /* Read up configuration file from file_name. */
2232 static void vty_read_file(FILE *confp
)
2236 unsigned int line_num
= 0;
2239 /* vty_close won't close stderr; if some config command prints
2240 * something it'll end up there. (not ideal; it'd be beter if output
2241 * from a file-load went to logging instead. Also note that if this
2242 * function is called after daemonizing, stderr will be /dev/null.)
2244 * vty->fd will be -1 from vty_new()
2246 vty
->wfd
= STDERR_FILENO
;
2247 vty
->type
= VTY_FILE
;
2248 vty
->node
= CONFIG_NODE
;
2250 /* Execute configuration file */
2251 ret
= config_from_file(vty
, confp
, &line_num
);
2253 /* Flush any previous errors before printing messages below */
2254 buffer_flush_all(vty
->obuf
, vty
->wfd
);
2256 if (!((ret
== CMD_SUCCESS
) || (ret
== CMD_ERR_NOTHING_TODO
))) {
2257 const char *message
= NULL
;
2261 case CMD_ERR_AMBIGUOUS
:
2262 message
= "Ambiguous command";
2264 case CMD_ERR_NO_MATCH
:
2265 message
= "No such command";
2269 nl
= strchr(vty
->error_buf
, '\n');
2272 zlog_err("ERROR: %s on config line %u: %s",
2273 message
, line_num
, vty
->error_buf
);
2279 static FILE *vty_use_backup_config(const char *fullpath
)
2281 char *fullpath_sav
, *fullpath_tmp
;
2287 fullpath_sav
= malloc(strlen(fullpath
) + strlen(CONF_BACKUP_EXT
) + 1);
2288 strcpy(fullpath_sav
, fullpath
);
2289 strcat(fullpath_sav
, CONF_BACKUP_EXT
);
2291 sav
= open(fullpath_sav
, O_RDONLY
);
2297 fullpath_tmp
= malloc(strlen(fullpath
) + 8);
2298 sprintf(fullpath_tmp
, "%s.XXXXXX", fullpath
);
2300 /* Open file to configuration write. */
2301 tmp
= mkstemp(fullpath_tmp
);
2305 if (fchmod(tmp
, CONFIGFILE_MASK
) != 0)
2308 while ((c
= read(sav
, buffer
, 512)) > 0) {
2309 if (write(tmp
, buffer
, c
) <= 0)
2315 if (rename(fullpath_tmp
, fullpath
) == 0)
2316 ret
= fopen(fullpath
, "r");
2318 unlink(fullpath_tmp
);
2323 unlink(fullpath_tmp
);
2333 /* Read up configuration file from file_name. */
2334 void vty_read_config(const char *config_file
, char *config_default_dir
)
2336 char cwd
[MAXPATHLEN
];
2338 const char *fullpath
;
2341 /* If -f flag specified. */
2342 if (config_file
!= NULL
) {
2343 if (!IS_DIRECTORY_SEP(config_file
[0])) {
2344 if (getcwd(cwd
, MAXPATHLEN
) == NULL
) {
2345 zlog_err("Failure to determine Current Working Directory %d!",
2349 tmp
= XMALLOC(MTYPE_TMP
,
2350 strlen(cwd
) + strlen(config_file
) + 2);
2351 sprintf(tmp
, "%s/%s", cwd
, config_file
);
2354 fullpath
= config_file
;
2356 confp
= fopen(fullpath
, "r");
2358 if (confp
== NULL
) {
2359 zlog_err("%s: failed to open configuration file %s: %s",
2360 __func__
, fullpath
, safe_strerror(errno
));
2362 confp
= vty_use_backup_config(fullpath
);
2364 zlog_warn("WARNING: using backup configuration file!");
2366 zlog_err("can't open configuration file [%s]",
2373 host_config_set(config_default_dir
);
2377 struct stat conf_stat
;
2379 /* !!!!PLEASE LEAVE!!!!
2380 * This is NEEDED for use with vtysh -b, or else you can get
2381 * a real configuration food fight with a lot garbage in the
2382 * merged configuration file it creates coming from the per
2383 * daemon configuration files. This also allows the daemons
2384 * to start if there default configuration file is not
2385 * present or ignore them, as needed when using vtysh -b to
2386 * configure the daemons at boot - MAG
2389 /* Stat for vtysh Zebra.conf, if found startup and wait for
2390 * boot configuration
2393 if (strstr(config_default_dir
, "vtysh") == NULL
) {
2394 ret
= stat(integrate_default
, &conf_stat
);
2396 goto tmp_free_and_out
;
2399 confp
= fopen(config_default_dir
, "r");
2400 if (confp
== NULL
) {
2401 zlog_err("%s: failed to open configuration file %s: %s",
2402 __func__
, config_default_dir
,
2403 safe_strerror(errno
));
2405 confp
= vty_use_backup_config(config_default_dir
);
2407 zlog_warn("WARNING: using backup configuration file!");
2408 fullpath
= config_default_dir
;
2410 zlog_err("can't open configuration file [%s]",
2411 config_default_dir
);
2412 goto tmp_free_and_out
;
2415 fullpath
= config_default_dir
;
2418 vty_read_file(confp
);
2422 host_config_set(fullpath
);
2426 XFREE(MTYPE_TMP
, tmp
);
2429 /* Small utility function which output log to the VTY. */
2430 void vty_log(const char *level
, const char *proto_str
, const char *format
,
2431 struct timestamp_control
*ctl
, va_list va
)
2439 for (i
= 0; i
< vector_active(vtyvec
); i
++)
2440 if ((vty
= vector_slot(vtyvec
, i
)) != NULL
)
2444 vty_log_out(vty
, level
, proto_str
, format
, ctl
,
2450 /* Async-signal-safe version of vty_log for fixed strings. */
2451 void vty_log_fixed(char *buf
, size_t len
)
2454 struct iovec iov
[2];
2455 char crlf
[4] = "\r\n";
2457 /* vty may not have been initialised */
2461 iov
[0].iov_base
= buf
;
2462 iov
[0].iov_len
= len
;
2463 iov
[1].iov_base
= crlf
;
2466 for (i
= 0; i
< vector_active(vtyvec
); i
++) {
2468 if (((vty
= vector_slot(vtyvec
, i
)) != NULL
) && vty
->monitor
)
2469 /* N.B. We don't care about the return code, since
2471 most likely just about to die anyway. */
2472 if (writev(vty
->wfd
, iov
, 2) == -1) {
2473 fprintf(stderr
, "Failure to writev: %d\n",
2480 int vty_config_lock(struct vty
*vty
)
2482 if (vty_config_is_lockless
)
2484 if (vty_config
== 0) {
2491 int vty_config_unlock(struct vty
*vty
)
2493 if (vty_config_is_lockless
)
2495 if (vty_config
== 1 && vty
->config
== 1) {
2502 void vty_config_lockless(void)
2504 vty_config_is_lockless
= 1;
2507 /* Master of the threads. */
2508 static struct thread_master
*vty_master
;
2510 static void vty_event(enum event event
, int sock
, struct vty
*vty
)
2512 struct thread
*vty_serv_thread
= NULL
;
2516 vty_serv_thread
= thread_add_read(vty_master
, vty_accept
, vty
,
2518 vector_set_index(Vvty_serv_thread
, sock
, vty_serv_thread
);
2522 vty_serv_thread
= thread_add_read(vty_master
, vtysh_accept
, vty
,
2524 vector_set_index(Vvty_serv_thread
, sock
, vty_serv_thread
);
2528 thread_add_read(vty_master
, vtysh_read
, vty
, sock
,
2532 vty
->t_write
= NULL
;
2533 thread_add_write(vty_master
, vtysh_write
, vty
, sock
,
2539 thread_add_read(vty_master
, vty_read
, vty
, sock
, &vty
->t_read
);
2541 /* Time out treatment. */
2542 if (vty
->v_timeout
) {
2544 thread_cancel(vty
->t_timeout
);
2545 vty
->t_timeout
= NULL
;
2546 thread_add_timer(vty_master
, vty_timeout
, vty
,
2547 vty
->v_timeout
, &vty
->t_timeout
);
2551 thread_add_write(vty_master
, vty_flush
, vty
, sock
,
2554 case VTY_TIMEOUT_RESET
:
2555 if (vty
->t_timeout
) {
2556 thread_cancel(vty
->t_timeout
);
2557 vty
->t_timeout
= NULL
;
2559 if (vty
->v_timeout
) {
2560 vty
->t_timeout
= NULL
;
2561 thread_add_timer(vty_master
, vty_timeout
, vty
,
2562 vty
->v_timeout
, &vty
->t_timeout
);
2568 DEFUN_NOSH (config_who
,
2571 "Display who is on vty\n")
2576 for (i
= 0; i
< vector_active(vtyvec
); i
++)
2577 if ((v
= vector_slot(vtyvec
, i
)) != NULL
)
2578 vty_out(vty
, "%svty[%d] connected from %s.\n",
2579 v
->config
? "*" : " ", i
, v
->address
);
2583 /* Move to vty configuration mode. */
2584 DEFUN_NOSH (line_vty
,
2587 "Configure a terminal line\n"
2588 "Virtual terminal\n")
2590 vty
->node
= VTY_NODE
;
2594 /* Set time out value. */
2595 static int exec_timeout(struct vty
*vty
, const char *min_str
,
2596 const char *sec_str
)
2598 unsigned long timeout
= 0;
2600 /* min_str and sec_str are already checked by parser. So it must be
2601 all digit string. */
2603 timeout
= strtol(min_str
, NULL
, 10);
2607 timeout
+= strtol(sec_str
, NULL
, 10);
2609 vty_timeout_val
= timeout
;
2610 vty
->v_timeout
= timeout
;
2611 vty_event(VTY_TIMEOUT_RESET
, 0, vty
);
2617 DEFUN (exec_timeout_min
,
2618 exec_timeout_min_cmd
,
2619 "exec-timeout (0-35791)",
2620 "Set timeout value\n"
2621 "Timeout value in minutes\n")
2624 return exec_timeout(vty
, argv
[idx_number
]->arg
, NULL
);
2627 DEFUN (exec_timeout_sec
,
2628 exec_timeout_sec_cmd
,
2629 "exec-timeout (0-35791) (0-2147483)",
2630 "Set the EXEC timeout\n"
2631 "Timeout in minutes\n"
2632 "Timeout in seconds\n")
2635 int idx_number_2
= 2;
2636 return exec_timeout(vty
, argv
[idx_number
]->arg
,
2637 argv
[idx_number_2
]->arg
);
2640 DEFUN (no_exec_timeout
,
2641 no_exec_timeout_cmd
,
2644 "Set the EXEC timeout\n")
2646 return exec_timeout(vty
, NULL
, NULL
);
2649 /* Set vty access class. */
2650 DEFUN (vty_access_class
,
2651 vty_access_class_cmd
,
2652 "access-class WORD",
2653 "Filter connections based on an IP access list\n"
2657 if (vty_accesslist_name
)
2658 XFREE(MTYPE_VTY
, vty_accesslist_name
);
2660 vty_accesslist_name
= XSTRDUP(MTYPE_VTY
, argv
[idx_word
]->arg
);
2665 /* Clear vty access class. */
2666 DEFUN (no_vty_access_class
,
2667 no_vty_access_class_cmd
,
2668 "no access-class [WORD]",
2670 "Filter connections based on an IP access list\n"
2674 const char *accesslist
= (argc
== 3) ? argv
[idx_word
]->arg
: NULL
;
2675 if (!vty_accesslist_name
2676 || (argc
== 3 && strcmp(vty_accesslist_name
, accesslist
))) {
2677 vty_out(vty
, "Access-class is not currently applied to vty\n");
2678 return CMD_WARNING_CONFIG_FAILED
;
2681 XFREE(MTYPE_VTY
, vty_accesslist_name
);
2683 vty_accesslist_name
= NULL
;
2688 /* Set vty access class. */
2689 DEFUN (vty_ipv6_access_class
,
2690 vty_ipv6_access_class_cmd
,
2691 "ipv6 access-class WORD",
2693 "Filter connections based on an IP access list\n"
2694 "IPv6 access list\n")
2697 if (vty_ipv6_accesslist_name
)
2698 XFREE(MTYPE_VTY
, vty_ipv6_accesslist_name
);
2700 vty_ipv6_accesslist_name
= XSTRDUP(MTYPE_VTY
, argv
[idx_word
]->arg
);
2705 /* Clear vty access class. */
2706 DEFUN (no_vty_ipv6_access_class
,
2707 no_vty_ipv6_access_class_cmd
,
2708 "no ipv6 access-class [WORD]",
2711 "Filter connections based on an IP access list\n"
2712 "IPv6 access list\n")
2715 const char *accesslist
= (argc
== 4) ? argv
[idx_word
]->arg
: NULL
;
2717 if (!vty_ipv6_accesslist_name
2718 || (argc
== 4 && strcmp(vty_ipv6_accesslist_name
, accesslist
))) {
2720 "IPv6 access-class is not currently applied to vty\n");
2721 return CMD_WARNING_CONFIG_FAILED
;
2724 XFREE(MTYPE_VTY
, vty_ipv6_accesslist_name
);
2726 vty_ipv6_accesslist_name
= NULL
;
2735 "Enable password checking\n")
2737 no_password_check
= 0;
2741 DEFUN (no_vty_login
,
2745 "Enable password checking\n")
2747 no_password_check
= 1;
2751 DEFUN (service_advanced_vty
,
2752 service_advanced_vty_cmd
,
2753 "service advanced-vty",
2754 "Set up miscellaneous service\n"
2755 "Enable advanced mode vty interface\n")
2761 DEFUN (no_service_advanced_vty
,
2762 no_service_advanced_vty_cmd
,
2763 "no service advanced-vty",
2765 "Set up miscellaneous service\n"
2766 "Enable advanced mode vty interface\n")
2772 DEFUN_NOSH (terminal_monitor
,
2773 terminal_monitor_cmd
,
2775 "Set terminal line parameters\n"
2776 "Copy debug output to the current terminal line\n")
2782 DEFUN_NOSH (terminal_no_monitor
,
2783 terminal_no_monitor_cmd
,
2784 "terminal no monitor",
2785 "Set terminal line parameters\n"
2787 "Copy debug output to the current terminal line\n")
2793 DEFUN_NOSH (no_terminal_monitor
,
2794 no_terminal_monitor_cmd
,
2795 "no terminal monitor",
2797 "Set terminal line parameters\n"
2798 "Copy debug output to the current terminal line\n")
2800 return terminal_no_monitor(self
, vty
, argc
, argv
);
2804 DEFUN_NOSH (show_history
,
2808 "Display the session command history\n")
2812 for (index
= vty
->hindex
+ 1; index
!= vty
->hindex
;) {
2813 if (index
== VTY_MAXHIST
) {
2818 if (vty
->hist
[index
] != NULL
)
2819 vty_out(vty
, " %s\n", vty
->hist
[index
]);
2828 DEFUN (log_commands
,
2832 "Log all commands (can't be unset without restart)\n")
2834 do_log_commands
= 1;
2838 /* Display current configuration. */
2839 static int vty_config_write(struct vty
*vty
)
2841 vty_out(vty
, "line vty\n");
2843 if (vty_accesslist_name
)
2844 vty_out(vty
, " access-class %s\n", vty_accesslist_name
);
2846 if (vty_ipv6_accesslist_name
)
2847 vty_out(vty
, " ipv6 access-class %s\n",
2848 vty_ipv6_accesslist_name
);
2851 if (vty_timeout_val
!= VTY_TIMEOUT_DEFAULT
)
2852 vty_out(vty
, " exec-timeout %ld %ld\n", vty_timeout_val
/ 60,
2853 vty_timeout_val
% 60);
2856 if (no_password_check
)
2857 vty_out(vty
, " no login\n");
2859 if (do_log_commands
)
2860 vty_out(vty
, "log commands\n");
2862 vty_out(vty
, "!\n");
2867 struct cmd_node vty_node
= {
2868 VTY_NODE
, "%s(config-line)# ", 1,
2871 /* Reset all VTY status. */
2876 struct thread
*vty_serv_thread
;
2878 for (i
= 0; i
< vector_active(vtyvec
); i
++)
2879 if ((vty
= vector_slot(vtyvec
, i
)) != NULL
) {
2880 buffer_reset(vty
->obuf
);
2881 vty
->status
= VTY_CLOSE
;
2885 for (i
= 0; i
< vector_active(Vvty_serv_thread
); i
++)
2886 if ((vty_serv_thread
= vector_slot(Vvty_serv_thread
, i
))
2888 thread_cancel(vty_serv_thread
);
2889 vector_slot(Vvty_serv_thread
, i
) = NULL
;
2893 vty_timeout_val
= VTY_TIMEOUT_DEFAULT
;
2895 if (vty_accesslist_name
) {
2896 XFREE(MTYPE_VTY
, vty_accesslist_name
);
2897 vty_accesslist_name
= NULL
;
2900 if (vty_ipv6_accesslist_name
) {
2901 XFREE(MTYPE_VTY
, vty_ipv6_accesslist_name
);
2902 vty_ipv6_accesslist_name
= NULL
;
2906 static void vty_save_cwd(void)
2908 char cwd
[MAXPATHLEN
];
2911 c
= getcwd(cwd
, MAXPATHLEN
);
2915 * At this point if these go wrong, more than likely
2916 * the whole world is coming down around us
2917 * Hence not worrying about it too much.
2919 if (!chdir(SYSCONFDIR
)) {
2920 zlog_err("Failure to chdir to %s, errno: %d",
2924 if (getcwd(cwd
, MAXPATHLEN
) == NULL
) {
2925 zlog_err("Failure to getcwd, errno: %d",
2931 vty_cwd
= XMALLOC(MTYPE_TMP
, strlen(cwd
) + 1);
2932 strcpy(vty_cwd
, cwd
);
2940 int vty_shell(struct vty
*vty
)
2942 return vty
->type
== VTY_SHELL
? 1 : 0;
2945 int vty_shell_serv(struct vty
*vty
)
2947 return vty
->type
== VTY_SHELL_SERV
? 1 : 0;
2950 void vty_init_vtysh()
2952 vtyvec
= vector_init(VECTOR_MIN_SIZE
);
2955 /* Install vty's own commands like `who' command. */
2956 void vty_init(struct thread_master
*master_thread
)
2958 /* For further configuration read, preserve current directory. */
2961 vtyvec
= vector_init(VECTOR_MIN_SIZE
);
2963 vty_master
= master_thread
;
2965 atexit(vty_stdio_atexit
);
2967 /* Initilize server thread vector. */
2968 Vvty_serv_thread
= vector_init(VECTOR_MIN_SIZE
);
2970 /* Install bgp top node. */
2971 install_node(&vty_node
, vty_config_write
);
2973 install_element(VIEW_NODE
, &config_who_cmd
);
2974 install_element(VIEW_NODE
, &show_history_cmd
);
2975 install_element(CONFIG_NODE
, &line_vty_cmd
);
2976 install_element(CONFIG_NODE
, &service_advanced_vty_cmd
);
2977 install_element(CONFIG_NODE
, &no_service_advanced_vty_cmd
);
2978 install_element(CONFIG_NODE
, &show_history_cmd
);
2979 install_element(CONFIG_NODE
, &log_commands_cmd
);
2980 install_element(ENABLE_NODE
, &terminal_monitor_cmd
);
2981 install_element(ENABLE_NODE
, &terminal_no_monitor_cmd
);
2982 install_element(ENABLE_NODE
, &no_terminal_monitor_cmd
);
2984 install_default(VTY_NODE
);
2985 install_element(VTY_NODE
, &exec_timeout_min_cmd
);
2986 install_element(VTY_NODE
, &exec_timeout_sec_cmd
);
2987 install_element(VTY_NODE
, &no_exec_timeout_cmd
);
2988 install_element(VTY_NODE
, &vty_access_class_cmd
);
2989 install_element(VTY_NODE
, &no_vty_access_class_cmd
);
2990 install_element(VTY_NODE
, &vty_login_cmd
);
2991 install_element(VTY_NODE
, &no_vty_login_cmd
);
2992 install_element(VTY_NODE
, &vty_ipv6_access_class_cmd
);
2993 install_element(VTY_NODE
, &no_vty_ipv6_access_class_cmd
);
2996 void vty_terminate(void)
2999 XFREE(MTYPE_TMP
, vty_cwd
);
3001 if (vtyvec
&& Vvty_serv_thread
) {
3003 vector_free(vtyvec
);
3004 vector_free(Vvty_serv_thread
);
3006 Vvty_serv_thread
= NULL
;