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")
60 static void vty_event (enum event
, int, struct vty
*);
62 /* Extern host structure from command.c */
63 extern struct host host
;
65 /* Vector which store each vty structure. */
68 /* Vty timeout value. */
69 static unsigned long vty_timeout_val
= VTY_TIMEOUT_DEFAULT
;
71 /* Vty access-class command */
72 static char *vty_accesslist_name
= NULL
;
74 /* Vty access-calss for IPv6. */
75 static char *vty_ipv6_accesslist_name
= NULL
;
77 /* VTY server thread. */
78 static vector Vvty_serv_thread
;
80 /* Current directory. */
84 static int vty_config
;
85 static int vty_config_is_lockless
= 0;
87 /* Login password check. */
88 static int no_password_check
= 0;
90 /* Integrated configuration file path */
91 char integrate_default
[] = SYSCONFDIR INTEGRATE_DEFAULT_CONFIG
;
93 static int do_log_commands
= 0;
95 /* VTY standard output function. */
97 vty_out (struct vty
*vty
, const char *format
, ...)
107 va_start (args
, format
);
108 vprintf (format
, args
);
113 /* Try to write to initial buffer. */
114 va_start (args
, format
);
115 len
= vsnprintf (buf
, sizeof(buf
), format
, args
);
118 /* Initial buffer is not enough. */
119 if (len
< 0 || len
>= size
)
128 p
= XREALLOC (MTYPE_VTY_OUT_BUF
, p
, size
);
132 va_start (args
, format
);
133 len
= vsnprintf (p
, size
, format
, args
);
136 if (len
> -1 && len
< size
)
141 /* When initial buffer is enough to store all output. */
145 /* Pointer p must point out buffer. */
146 if (vty
->type
!= VTY_TERM
)
147 buffer_put (vty
->obuf
, (u_char
*) p
, len
);
149 buffer_put_crlf (vty
->obuf
, (u_char
*) p
, len
);
151 /* If p is not different with buf, it is allocated buffer. */
153 XFREE (MTYPE_VTY_OUT_BUF
, p
);
160 vty_log_out (struct vty
*vty
, const char *level
, const char *proto_str
,
161 const char *format
, struct timestamp_control
*ctl
, va_list va
)
167 if (!ctl
->already_rendered
)
169 ctl
->len
= quagga_timestamp(ctl
->precision
, ctl
->buf
, sizeof(ctl
->buf
));
170 ctl
->already_rendered
= 1;
172 if (ctl
->len
+1 >= sizeof(buf
))
174 memcpy(buf
, ctl
->buf
, len
= ctl
->len
);
179 ret
= snprintf(buf
+len
, sizeof(buf
)-len
, "%s: %s: ", level
, proto_str
);
181 ret
= snprintf(buf
+len
, sizeof(buf
)-len
, "%s: ", proto_str
);
182 if ((ret
< 0) || ((size_t)(len
+= ret
) >= sizeof(buf
)))
185 if (((ret
= vsnprintf(buf
+len
, sizeof(buf
)-len
, format
, va
)) < 0) ||
186 ((size_t)((len
+= ret
)+2) > sizeof(buf
)))
192 if (write(vty
->wfd
, buf
, len
) < 0)
194 if (ERRNO_IO_RETRY(errno
))
195 /* Kernel buffer is full, probably too much debugging output, so just
196 drop the data and ignore. */
198 /* Fatal I/O error. */
199 vty
->monitor
= 0; /* disable monitoring to avoid infinite recursion */
200 zlog_warn("%s: write failed to vty client fd %d, closing: %s",
201 __func__
, vty
->fd
, safe_strerror(errno
));
202 buffer_reset(vty
->obuf
);
203 /* cannot call vty_close, because a parent routine may still try
204 to access the vty struct */
205 vty
->status
= VTY_CLOSE
;
206 shutdown(vty
->fd
, SHUT_RDWR
);
212 /* Output current time to the vty. */
214 vty_time_print (struct vty
*vty
, int cr
)
216 char buf
[QUAGGA_TIMESTAMP_LEN
];
218 if (quagga_timestamp(0, buf
, sizeof(buf
)) == 0)
220 zlog_info("quagga_timestamp error");
224 vty_out (vty
, "%s\n", buf
);
226 vty_out (vty
, "%s ", buf
);
231 /* Say hello to vty interface. */
233 vty_hello (struct vty
*vty
)
240 f
= fopen (host
.motdfile
, "r");
243 while (fgets (buf
, sizeof (buf
), f
))
246 /* work backwards to ignore trailling isspace() */
247 for (s
= buf
+ strlen (buf
); (s
> buf
) && isspace ((int)*(s
- 1));
250 vty_out (vty
, "%s\n", buf
);
255 vty_out (vty
, "MOTD file not found\n");
258 vty_out (vty
, "%s", host
.motd
);
261 /* Put out prompt and wait input from user. */
263 vty_prompt (struct vty
*vty
)
265 struct utsname names
;
268 if (vty
->type
== VTY_TERM
)
270 hostname
= host
.name
;
274 hostname
= names
.nodename
;
276 vty_out (vty
, cmd_prompt (vty
->node
), hostname
);
280 /* Send WILL TELOPT_ECHO to remote server. */
282 vty_will_echo (struct vty
*vty
)
284 unsigned char cmd
[] = { IAC
, WILL
, TELOPT_ECHO
, '\0' };
285 vty_out (vty
, "%s", cmd
);
288 /* Make suppress Go-Ahead telnet option. */
290 vty_will_suppress_go_ahead (struct vty
*vty
)
292 unsigned char cmd
[] = { IAC
, WILL
, TELOPT_SGA
, '\0' };
293 vty_out (vty
, "%s", cmd
);
296 /* Make don't use linemode over telnet. */
298 vty_dont_linemode (struct vty
*vty
)
300 unsigned char cmd
[] = { IAC
, DONT
, TELOPT_LINEMODE
, '\0' };
301 vty_out (vty
, "%s", cmd
);
304 /* Use window size. */
306 vty_do_window_size (struct vty
*vty
)
308 unsigned char cmd
[] = { IAC
, DO
, TELOPT_NAWS
, '\0' };
309 vty_out (vty
, "%s", cmd
);
312 #if 0 /* Currently not used. */
313 /* Make don't use lflow vty interface. */
315 vty_dont_lflow_ahead (struct vty
*vty
)
317 unsigned char cmd
[] = { IAC
, DONT
, TELOPT_LFLOW
, '\0' };
318 vty_out (vty
, "%s", cmd
);
322 /* Allocate new vty struct. */
326 struct vty
*new = XCALLOC (MTYPE_VTY
, sizeof (struct vty
));
328 new->obuf
= buffer_new(0); /* Use default buffer size. */
329 new->buf
= XCALLOC (MTYPE_VTY
, VTY_BUFSIZ
);
330 new->error_buf
= XCALLOC (MTYPE_VTY
, VTY_BUFSIZ
);
331 new->max
= VTY_BUFSIZ
;
336 /* Authentication of vty */
338 vty_auth (struct vty
*vty
, char *buf
)
341 enum node_type next_node
= 0;
343 char *crypt (const char *, const char *);
349 passwd
= host
.password_encrypt
;
351 passwd
= host
.password
;
353 next_node
= host
.enable
? VIEW_NODE
: ENABLE_NODE
;
355 next_node
= VIEW_NODE
;
357 case AUTH_ENABLE_NODE
:
359 passwd
= host
.enable_encrypt
;
361 passwd
= host
.enable
;
362 next_node
= ENABLE_NODE
;
369 fail
= strcmp (crypt(buf
, passwd
), passwd
);
371 fail
= strcmp (buf
, passwd
);
379 vty
->node
= next_node
; /* Success ! */
386 if (vty
->node
== AUTH_NODE
)
388 vty_out (vty
, "%% Bad passwords, too many failures!\n");
389 vty
->status
= VTY_CLOSE
;
393 /* AUTH_ENABLE_NODE */
395 vty_out (vty
, "%% Bad enable passwords, too many failures!\n");
396 vty
->status
= VTY_CLOSE
;
402 /* Command execution over the vty interface. */
404 vty_command (struct vty
*vty
, char *buf
)
408 const char *protocolname
;
412 * Log non empty command lines
418 /* Skip white spaces. */
419 while (isspace ((int) *cp
) && *cp
!= '\0')
422 if (cp
!= NULL
&& *cp
!= '\0')
425 char vty_str
[VTY_BUFSIZ
];
426 char prompt_str
[VTY_BUFSIZ
];
428 /* format the base vty info */
429 snprintf(vty_str
, sizeof(vty_str
), "vty[??]@%s", vty
->address
);
431 for (i
= 0; i
< vector_active (vtyvec
); i
++)
432 if (vty
== vector_slot (vtyvec
, i
))
434 snprintf(vty_str
, sizeof(vty_str
), "vty[%d]@%s",
439 /* format the prompt */
440 snprintf(prompt_str
, sizeof(prompt_str
), cmd_prompt (vty
->node
), vty_str
);
442 /* now log the command */
443 zlog_err("%s%s", prompt_str
, buf
);
445 /* Split readline string up into the vector */
446 vline
= cmd_make_strvec (buf
);
451 #ifdef CONSUMED_TIME_CHECK
455 unsigned long realtime
, cputime
;
458 #endif /* CONSUMED_TIME_CHECK */
460 ret
= cmd_execute_command (vline
, vty
, NULL
, 0);
462 /* Get the name of the protocol if any */
463 protocolname
= frr_protoname
;
465 #ifdef CONSUMED_TIME_CHECK
467 if ((realtime
= thread_consumed_time(&after
, &before
, &cputime
)) >
469 /* Warn about CPU hog that must be fixed. */
470 zlog_warn("SLOW COMMAND: command took %lums (cpu time %lums): %s",
471 realtime
/1000, cputime
/1000, buf
);
473 #endif /* CONSUMED_TIME_CHECK */
475 if (ret
!= CMD_SUCCESS
)
479 if (vty
->type
== VTY_FILE
)
480 vty_out (vty
, "Warning...\n");
482 case CMD_ERR_AMBIGUOUS
:
483 vty_out (vty
, "%% Ambiguous command.\n");
485 case CMD_ERR_NO_MATCH
:
486 vty_out (vty
, "%% [%s] Unknown command: %s\n", protocolname
, buf
);
488 case CMD_ERR_INCOMPLETE
:
489 vty_out (vty
, "%% Command incomplete.\n");
492 cmd_free_strvec (vline
);
497 static const char telnet_backward_char
= 0x08;
498 static const char telnet_space_char
= ' ';
500 /* Basic function to write buffer to vty. */
502 vty_write (struct vty
*vty
, const char *buf
, size_t nbytes
)
504 if ((vty
->node
== AUTH_NODE
) || (vty
->node
== AUTH_ENABLE_NODE
))
507 /* Should we do buffering here ? And make vty_flush (vty) ? */
508 buffer_put (vty
->obuf
, buf
, nbytes
);
511 /* Basic function to insert character into vty. */
513 vty_self_insert (struct vty
*vty
, char c
)
518 if (vty
->length
+ 1 >= VTY_BUFSIZ
)
521 length
= vty
->length
- vty
->cp
;
522 memmove (&vty
->buf
[vty
->cp
+ 1], &vty
->buf
[vty
->cp
], length
);
523 vty
->buf
[vty
->cp
] = c
;
525 vty_write (vty
, &vty
->buf
[vty
->cp
], length
+ 1);
526 for (i
= 0; i
< length
; i
++)
527 vty_write (vty
, &telnet_backward_char
, 1);
532 vty
->buf
[vty
->length
] = '\0';
535 /* Self insert character 'c' in overwrite mode. */
537 vty_self_insert_overwrite (struct vty
*vty
, char c
)
539 if (vty
->cp
== vty
->length
)
541 vty_self_insert (vty
, c
);
545 vty
->buf
[vty
->cp
++] = c
;
546 vty_write (vty
, &c
, 1);
550 * Insert a string into vty->buf at the current cursor position.
552 * If the resultant string would be larger than VTY_BUFSIZ it is
556 vty_insert_word_overwrite (struct vty
*vty
, char *str
)
558 if (vty
->cp
== VTY_BUFSIZ
)
561 size_t nwrite
= MIN ((int) strlen (str
), VTY_BUFSIZ
- vty
->cp
- 1);
562 memcpy (&vty
->buf
[vty
->cp
], str
, nwrite
);
564 vty
->length
= MAX (vty
->cp
, vty
->length
);
565 vty
->buf
[vty
->length
] = '\0';
566 vty_write (vty
, str
, nwrite
);
569 /* Forward character. */
571 vty_forward_char (struct vty
*vty
)
573 if (vty
->cp
< vty
->length
)
575 vty_write (vty
, &vty
->buf
[vty
->cp
], 1);
580 /* Backward character. */
582 vty_backward_char (struct vty
*vty
)
587 vty_write (vty
, &telnet_backward_char
, 1);
591 /* Move to the beginning of the line. */
593 vty_beginning_of_line (struct vty
*vty
)
596 vty_backward_char (vty
);
599 /* Move to the end of the line. */
601 vty_end_of_line (struct vty
*vty
)
603 while (vty
->cp
< vty
->length
)
604 vty_forward_char (vty
);
607 static void vty_kill_line_from_beginning (struct vty
*);
608 static void vty_redraw_line (struct vty
*);
610 /* Print command line history. This function is called from
611 vty_next_line and vty_previous_line. */
613 vty_history_print (struct vty
*vty
)
617 vty_kill_line_from_beginning (vty
);
619 /* Get previous line from history buffer */
620 length
= strlen (vty
->hist
[vty
->hp
]);
621 memcpy (vty
->buf
, vty
->hist
[vty
->hp
], length
);
622 vty
->cp
= vty
->length
= length
;
623 vty
->buf
[vty
->length
] = '\0';
625 /* Redraw current line */
626 vty_redraw_line (vty
);
629 /* Show next command line history. */
631 vty_next_line (struct vty
*vty
)
635 if (vty
->hp
== vty
->hindex
)
638 /* Try is there history exist or not. */
640 if (try_index
== (VTY_MAXHIST
- 1))
645 /* If there is not history return. */
646 if (vty
->hist
[try_index
] == NULL
)
651 vty_history_print (vty
);
654 /* Show previous command line history. */
656 vty_previous_line (struct vty
*vty
)
662 try_index
= VTY_MAXHIST
- 1;
666 if (vty
->hist
[try_index
] == NULL
)
671 vty_history_print (vty
);
674 /* This function redraw all of the command line character. */
676 vty_redraw_line (struct vty
*vty
)
678 vty_write (vty
, vty
->buf
, vty
->length
);
679 vty
->cp
= vty
->length
;
684 vty_forward_word (struct vty
*vty
)
686 while (vty
->cp
!= vty
->length
&& vty
->buf
[vty
->cp
] != ' ')
687 vty_forward_char (vty
);
689 while (vty
->cp
!= vty
->length
&& vty
->buf
[vty
->cp
] == ' ')
690 vty_forward_char (vty
);
693 /* Backward word without skipping training space. */
695 vty_backward_pure_word (struct vty
*vty
)
697 while (vty
->cp
> 0 && vty
->buf
[vty
->cp
- 1] != ' ')
698 vty_backward_char (vty
);
703 vty_backward_word (struct vty
*vty
)
705 while (vty
->cp
> 0 && vty
->buf
[vty
->cp
- 1] == ' ')
706 vty_backward_char (vty
);
708 while (vty
->cp
> 0 && vty
->buf
[vty
->cp
- 1] != ' ')
709 vty_backward_char (vty
);
712 /* When '^D' is typed at the beginning of the line we move to the down
715 vty_down_level (struct vty
*vty
)
723 /* When '^Z' is received from vty, move down to the enable mode. */
725 vty_end_config (struct vty
*vty
)
744 case BGP_VRF_POLICY_NODE
:
745 case BGP_VNC_DEFAULTS_NODE
:
746 case BGP_VNC_NVE_GROUP_NODE
:
747 case BGP_VNC_L2_GROUP_NODE
:
761 case LDP_IPV4_IFACE_NODE
:
762 case LDP_IPV6_IFACE_NODE
:
764 case LDP_PSEUDOWIRE_NODE
:
767 case KEYCHAIN_KEY_NODE
:
771 vty_config_unlock (vty
);
772 vty
->node
= ENABLE_NODE
;
775 /* Unknown node, we have to ignore it. */
783 /* Delete a charcter at the current point. */
785 vty_delete_char (struct vty
*vty
)
790 if (vty
->length
== 0)
792 vty_down_level (vty
);
796 if (vty
->cp
== vty
->length
)
797 return; /* completion need here? */
799 size
= vty
->length
- vty
->cp
;
802 memmove (&vty
->buf
[vty
->cp
], &vty
->buf
[vty
->cp
+ 1], size
- 1);
803 vty
->buf
[vty
->length
] = '\0';
805 if (vty
->node
== AUTH_NODE
|| vty
->node
== AUTH_ENABLE_NODE
)
808 vty_write (vty
, &vty
->buf
[vty
->cp
], size
- 1);
809 vty_write (vty
, &telnet_space_char
, 1);
811 for (i
= 0; i
< size
; i
++)
812 vty_write (vty
, &telnet_backward_char
, 1);
815 /* Delete a character before the point. */
817 vty_delete_backward_char (struct vty
*vty
)
822 vty_backward_char (vty
);
823 vty_delete_char (vty
);
826 /* Kill rest of line from current point. */
828 vty_kill_line (struct vty
*vty
)
833 size
= vty
->length
- vty
->cp
;
838 for (i
= 0; i
< size
; i
++)
839 vty_write (vty
, &telnet_space_char
, 1);
840 for (i
= 0; i
< size
; i
++)
841 vty_write (vty
, &telnet_backward_char
, 1);
843 memset (&vty
->buf
[vty
->cp
], 0, size
);
844 vty
->length
= vty
->cp
;
847 /* Kill line from the beginning. */
849 vty_kill_line_from_beginning (struct vty
*vty
)
851 vty_beginning_of_line (vty
);
855 /* Delete a word before the point. */
857 vty_forward_kill_word (struct vty
*vty
)
859 while (vty
->cp
!= vty
->length
&& vty
->buf
[vty
->cp
] == ' ')
860 vty_delete_char (vty
);
861 while (vty
->cp
!= vty
->length
&& vty
->buf
[vty
->cp
] != ' ')
862 vty_delete_char (vty
);
865 /* Delete a word before the point. */
867 vty_backward_kill_word (struct vty
*vty
)
869 while (vty
->cp
> 0 && vty
->buf
[vty
->cp
- 1] == ' ')
870 vty_delete_backward_char (vty
);
871 while (vty
->cp
> 0 && vty
->buf
[vty
->cp
- 1] != ' ')
872 vty_delete_backward_char (vty
);
875 /* Transpose chars before or at the point. */
877 vty_transpose_chars (struct vty
*vty
)
881 /* If length is short or point is near by the beginning of line then
883 if (vty
->length
< 2 || vty
->cp
< 1)
886 /* In case of point is located at the end of the line. */
887 if (vty
->cp
== vty
->length
)
889 c1
= vty
->buf
[vty
->cp
- 1];
890 c2
= vty
->buf
[vty
->cp
- 2];
892 vty_backward_char (vty
);
893 vty_backward_char (vty
);
894 vty_self_insert_overwrite (vty
, c1
);
895 vty_self_insert_overwrite (vty
, c2
);
899 c1
= vty
->buf
[vty
->cp
];
900 c2
= vty
->buf
[vty
->cp
- 1];
902 vty_backward_char (vty
);
903 vty_self_insert_overwrite (vty
, c1
);
904 vty_self_insert_overwrite (vty
, c2
);
908 /* Do completion at vty interface. */
910 vty_complete_command (struct vty
*vty
)
914 char **matched
= NULL
;
917 if (vty
->node
== AUTH_NODE
|| vty
->node
== AUTH_ENABLE_NODE
)
920 vline
= cmd_make_strvec (vty
->buf
);
924 /* In case of 'help \t'. */
925 if (isspace ((int) vty
->buf
[vty
->length
- 1]))
926 vector_set (vline
, NULL
);
928 matched
= cmd_complete_command (vline
, vty
, &ret
);
930 cmd_free_strvec (vline
);
935 case CMD_ERR_AMBIGUOUS
:
936 vty_out (vty
, "%% Ambiguous command.\n");
938 vty_redraw_line (vty
);
940 case CMD_ERR_NO_MATCH
:
941 /* vty_out (vty, "%% There is no matched command.\n"); */
943 vty_redraw_line (vty
);
945 case CMD_COMPLETE_FULL_MATCH
:
948 /* 2016-11-28 equinox -- need to debug, SEGV here */
949 vty_out (vty
, "%% CLI BUG: FULL_MATCH with NULL str\n");
951 vty_redraw_line (vty
);
955 vty_redraw_line (vty
);
956 vty_backward_pure_word (vty
);
957 vty_insert_word_overwrite (vty
, matched
[0]);
958 vty_self_insert (vty
, ' ');
959 XFREE (MTYPE_COMPLETION
, matched
[0]);
961 case CMD_COMPLETE_MATCH
:
963 vty_redraw_line (vty
);
964 vty_backward_pure_word (vty
);
965 vty_insert_word_overwrite (vty
, matched
[0]);
966 XFREE (MTYPE_COMPLETION
, matched
[0]);
968 case CMD_COMPLETE_LIST_MATCH
:
969 for (i
= 0; matched
[i
] != NULL
; i
++)
971 if (i
!= 0 && ((i
% 6) == 0))
973 vty_out (vty
, "%-10s ", matched
[i
]);
974 XFREE (MTYPE_COMPLETION
, matched
[i
]);
979 vty_redraw_line (vty
);
981 case CMD_ERR_NOTHING_TODO
:
983 vty_redraw_line (vty
);
989 XFREE (MTYPE_TMP
, matched
);
993 vty_describe_fold (struct vty
*vty
, int cmd_width
,
994 unsigned int desc_width
, struct cmd_token
*token
)
1002 if (desc_width
<= 0)
1004 vty_out (vty
, " %-*s %s\n", cmd_width
, cmd
, token
->desc
);
1008 buf
= XCALLOC (MTYPE_TMP
, strlen (token
->desc
) + 1);
1010 for (p
= token
->desc
; strlen (p
) > desc_width
; p
+= pos
+ 1)
1012 for (pos
= desc_width
; pos
> 0; pos
--)
1013 if (*(p
+ pos
) == ' ')
1019 strncpy (buf
, p
, pos
);
1021 vty_out (vty
, " %-*s %s\n", cmd_width
, cmd
, buf
);
1026 vty_out (vty
, " %-*s %s\n", cmd_width
, cmd
, p
);
1028 XFREE (MTYPE_TMP
, buf
);
1031 /* Describe matched command function. */
1033 vty_describe_command (struct vty
*vty
)
1038 unsigned int i
, width
, desc_width
;
1039 struct cmd_token
*token
, *token_cr
= NULL
;
1041 vline
= cmd_make_strvec (vty
->buf
);
1043 /* In case of '> ?'. */
1046 vline
= vector_init (1);
1047 vector_set (vline
, NULL
);
1050 if (isspace ((int) vty
->buf
[vty
->length
- 1]))
1051 vector_set (vline
, NULL
);
1053 describe
= cmd_describe_command (vline
, vty
, &ret
);
1055 vty_out (vty
, "\n");
1057 /* Ambiguous error. */
1060 case CMD_ERR_AMBIGUOUS
:
1061 vty_out (vty
, "%% Ambiguous command.\n");
1064 case CMD_ERR_NO_MATCH
:
1065 vty_out (vty
, "%% There is no matched command.\n");
1070 /* Get width of command string. */
1072 for (i
= 0; i
< vector_active (describe
); i
++)
1073 if ((token
= vector_slot (describe
, i
)) != NULL
)
1077 if (token
->text
[0] == '\0')
1080 len
= strlen (token
->text
);
1086 /* Get width of description string. */
1087 desc_width
= vty
->width
- (width
+ 6);
1089 /* Print out description. */
1090 for (i
= 0; i
< vector_active (describe
); i
++)
1091 if ((token
= vector_slot (describe
, i
)) != NULL
)
1093 if (token
->text
[0] == '\0')
1096 if (strcmp (token
->text
, CMD_CR_TEXT
) == 0)
1103 vty_out (vty
, " %-s\n",
1105 else if (desc_width
>= strlen (token
->desc
))
1106 vty_out (vty
, " %-*s %s\n", width
,
1110 vty_describe_fold (vty
, width
, desc_width
, token
);
1112 if (IS_VARYING_TOKEN(token
->type
))
1114 const char *ref
= vector_slot(vline
, vector_active(vline
) - 1);
1116 vector varcomps
= vector_init (VECTOR_MIN_SIZE
);
1117 cmd_variable_complete (token
, ref
, varcomps
);
1119 if (vector_active(varcomps
) > 0)
1122 for (size_t j
= 0; j
< vector_active (varcomps
); j
++)
1124 char *item
= vector_slot (varcomps
, j
);
1125 vty_out(vty
, " %s", item
);
1126 XFREE(MTYPE_COMPLETION
, item
);
1128 vty_out (vty
, "\n");
1130 vector_free(varcomps
);
1133 vty_out (vty
, " %-*s %s\n", width
1134 desc
->cmd
[0] == '.' ? desc
->cmd
+ 1 : desc
->cmd
,
1135 desc
->str
? desc
->str
: "");
1139 if ((token
= token_cr
))
1142 vty_out (vty
, " %-s\n",
1144 else if (desc_width
>= strlen (token
->desc
))
1145 vty_out (vty
, " %-*s %s\n", width
,
1149 vty_describe_fold (vty
, width
, desc_width
, token
);
1153 cmd_free_strvec (vline
);
1155 vector_free (describe
);
1158 vty_redraw_line (vty
);
1162 vty_clear_buf (struct vty
*vty
)
1164 memset (vty
->buf
, 0, vty
->max
);
1167 /* ^C stop current input and do not add command line to the history. */
1169 vty_stop_input (struct vty
*vty
)
1171 vty
->cp
= vty
->length
= 0;
1172 vty_clear_buf (vty
);
1173 vty_out (vty
, "\n");
1179 /* Nothing to do. */
1182 case INTERFACE_NODE
:
1194 case LDP_IPV4_IFACE_NODE
:
1195 case LDP_IPV6_IFACE_NODE
:
1196 case LDP_L2VPN_NODE
:
1197 case LDP_PSEUDOWIRE_NODE
:
1200 case KEYCHAIN_KEY_NODE
:
1204 vty_config_unlock (vty
);
1205 vty
->node
= ENABLE_NODE
;
1208 /* Unknown node, we have to ignore it. */
1213 /* Set history pointer to the latest one. */
1214 vty
->hp
= vty
->hindex
;
1217 /* Add current command line to the history buffer. */
1219 vty_hist_add (struct vty
*vty
)
1223 if (vty
->length
== 0)
1226 index
= vty
->hindex
? vty
->hindex
- 1 : VTY_MAXHIST
- 1;
1228 /* Ignore the same string as previous one. */
1229 if (vty
->hist
[index
])
1230 if (strcmp (vty
->buf
, vty
->hist
[index
]) == 0)
1232 vty
->hp
= vty
->hindex
;
1236 /* Insert history entry. */
1237 if (vty
->hist
[vty
->hindex
])
1238 XFREE (MTYPE_VTY_HIST
, vty
->hist
[vty
->hindex
]);
1239 vty
->hist
[vty
->hindex
] = XSTRDUP (MTYPE_VTY_HIST
, vty
->buf
);
1241 /* History index rotation. */
1243 if (vty
->hindex
== VTY_MAXHIST
)
1246 vty
->hp
= vty
->hindex
;
1249 /* #define TELNET_OPTION_DEBUG */
1251 /* Get telnet window size. */
1253 vty_telnet_option (struct vty
*vty
, unsigned char *buf
, int nbytes
)
1255 #ifdef TELNET_OPTION_DEBUG
1258 for (i
= 0; i
< nbytes
; i
++)
1263 vty_out (vty
, "IAC ");
1266 vty_out (vty
, "WILL ");
1269 vty_out (vty
, "WONT ");
1272 vty_out (vty
, "DO ");
1275 vty_out (vty
, "DONT ");
1278 vty_out (vty
, "SB ");
1281 vty_out (vty
, "SE ");
1284 vty_out (vty
, "TELOPT_ECHO \n");
1287 vty_out (vty
, "TELOPT_SGA \n");
1290 vty_out (vty
, "TELOPT_NAWS \n");
1293 vty_out (vty
, "%x ", buf
[i
]);
1297 vty_out (vty
, "\n");
1299 #endif /* TELNET_OPTION_DEBUG */
1305 vty
->iac_sb_in_progress
= 1;
1310 if (!vty
->iac_sb_in_progress
)
1313 if ((vty
->sb_len
== 0) || (vty
->sb_buf
[0] == '\0'))
1315 vty
->iac_sb_in_progress
= 0;
1318 switch (vty
->sb_buf
[0])
1321 if (vty
->sb_len
!= TELNET_NAWS_SB_LEN
)
1322 zlog_warn("RFC 1073 violation detected: telnet NAWS option "
1323 "should send %d characters, but we received %lu",
1324 TELNET_NAWS_SB_LEN
, (u_long
)vty
->sb_len
);
1325 else if (sizeof(vty
->sb_buf
) < TELNET_NAWS_SB_LEN
)
1326 zlog_err("Bug detected: sizeof(vty->sb_buf) %lu < %d, "
1327 "too small to handle the telnet NAWS option",
1328 (u_long
)sizeof(vty
->sb_buf
), TELNET_NAWS_SB_LEN
);
1331 vty
->width
= ((vty
->sb_buf
[1] << 8)|vty
->sb_buf
[2]);
1332 vty
->height
= ((vty
->sb_buf
[3] << 8)|vty
->sb_buf
[4]);
1333 #ifdef TELNET_OPTION_DEBUG
1334 vty_out (vty
, "TELNET NAWS window size negotiation completed: "
1335 "width %d, height %d\n",
1336 vty
->width
, vty
->height
);
1341 vty
->iac_sb_in_progress
= 0;
1351 /* Execute current command line. */
1353 vty_execute (struct vty
*vty
)
1362 case AUTH_ENABLE_NODE
:
1363 vty_auth (vty
, vty
->buf
);
1366 ret
= vty_command (vty
, vty
->buf
);
1367 if (vty
->type
== VTY_TERM
)
1372 /* Clear command line buffer. */
1373 vty
->cp
= vty
->length
= 0;
1374 vty_clear_buf (vty
);
1376 if (vty
->status
!= VTY_CLOSE
)
1382 #define CONTROL(X) ((X) - '@')
1383 #define VTY_NORMAL 0
1384 #define VTY_PRE_ESCAPE 1
1385 #define VTY_ESCAPE 2
1387 /* Escape character command map. */
1389 vty_escape_map (unsigned char c
, struct vty
*vty
)
1394 vty_previous_line (vty
);
1397 vty_next_line (vty
);
1400 vty_forward_char (vty
);
1403 vty_backward_char (vty
);
1409 /* Go back to normal mode. */
1410 vty
->escape
= VTY_NORMAL
;
1413 /* Quit print out to the buffer. */
1415 vty_buffer_reset (struct vty
*vty
)
1417 buffer_reset (vty
->obuf
);
1419 vty_redraw_line (vty
);
1422 /* Read data via vty socket. */
1424 vty_read (struct thread
*thread
)
1428 unsigned char buf
[VTY_READ_BUFSIZ
];
1430 int vty_sock
= THREAD_FD (thread
);
1431 struct vty
*vty
= THREAD_ARG (thread
);
1434 /* Read raw data from socket */
1435 if ((nbytes
= read (vty
->fd
, buf
, VTY_READ_BUFSIZ
)) <= 0)
1439 if (ERRNO_IO_RETRY(errno
))
1441 vty_event (VTY_READ
, vty_sock
, vty
);
1444 vty
->monitor
= 0; /* disable monitoring to avoid infinite recursion */
1445 zlog_warn("%s: read error on vty client fd %d, closing: %s",
1446 __func__
, vty
->fd
, safe_strerror(errno
));
1447 buffer_reset(vty
->obuf
);
1449 vty
->status
= VTY_CLOSE
;
1452 for (i
= 0; i
< nbytes
; i
++)
1467 if (vty
->iac_sb_in_progress
&& !vty
->iac
)
1469 if (vty
->sb_len
< sizeof(vty
->sb_buf
))
1470 vty
->sb_buf
[vty
->sb_len
] = buf
[i
];
1477 /* In case of telnet command */
1479 ret
= vty_telnet_option (vty
, buf
+ i
, nbytes
- i
);
1486 if (vty
->status
== VTY_MORE
)
1493 vty_buffer_reset (vty
);
1495 #if 0 /* More line does not work for "show ip bgp". */
1498 vty
->status
= VTY_MORELINE
;
1507 /* Escape character. */
1508 if (vty
->escape
== VTY_ESCAPE
)
1510 vty_escape_map (buf
[i
], vty
);
1514 /* Pre-escape status. */
1515 if (vty
->escape
== VTY_PRE_ESCAPE
)
1520 vty
->escape
= VTY_ESCAPE
;
1523 vty_backward_word (vty
);
1524 vty
->escape
= VTY_NORMAL
;
1527 vty_forward_word (vty
);
1528 vty
->escape
= VTY_NORMAL
;
1531 vty_forward_kill_word (vty
);
1532 vty
->escape
= VTY_NORMAL
;
1536 vty_backward_kill_word (vty
);
1537 vty
->escape
= VTY_NORMAL
;
1540 vty
->escape
= VTY_NORMAL
;
1549 vty_beginning_of_line (vty
);
1552 vty_backward_char (vty
);
1555 vty_stop_input (vty
);
1558 vty_delete_char (vty
);
1561 vty_end_of_line (vty
);
1564 vty_forward_char (vty
);
1568 vty_delete_backward_char (vty
);
1571 vty_kill_line (vty
);
1574 vty_next_line (vty
);
1577 vty_previous_line (vty
);
1580 vty_transpose_chars (vty
);
1583 vty_kill_line_from_beginning (vty
);
1586 vty_backward_kill_word (vty
);
1589 vty_end_config (vty
);
1593 vty_out (vty
, "\n");
1597 vty_complete_command (vty
);
1600 if (vty
->node
== AUTH_NODE
|| vty
->node
== AUTH_ENABLE_NODE
)
1601 vty_self_insert (vty
, buf
[i
]);
1603 vty_describe_command (vty
);
1606 if (i
+ 1 < nbytes
&& buf
[i
+ 1] == '[')
1608 vty
->escape
= VTY_ESCAPE
;
1612 vty
->escape
= VTY_PRE_ESCAPE
;
1615 if (buf
[i
] > 31 && buf
[i
] < 127)
1616 vty_self_insert (vty
, buf
[i
]);
1622 if (vty
->status
== VTY_CLOSE
)
1626 vty_event (VTY_WRITE
, vty
->wfd
, vty
);
1627 vty_event (VTY_READ
, vty_sock
, vty
);
1632 /* Flush buffer to the vty. */
1634 vty_flush (struct thread
*thread
)
1637 buffer_status_t flushrc
;
1638 int vty_sock
= THREAD_FD (thread
);
1639 struct vty
*vty
= THREAD_ARG (thread
);
1641 vty
->t_write
= NULL
;
1643 /* Tempolary disable read thread. */
1644 if ((vty
->lines
== 0) && vty
->t_read
)
1646 thread_cancel (vty
->t_read
);
1650 /* Function execution continue. */
1651 erase
= ((vty
->status
== VTY_MORE
|| vty
->status
== VTY_MORELINE
));
1653 /* N.B. if width is 0, that means we don't know the window size. */
1654 if ((vty
->lines
== 0) || (vty
->width
== 0) || (vty
->height
== 0))
1655 flushrc
= buffer_flush_available(vty
->obuf
, vty_sock
);
1656 else if (vty
->status
== VTY_MORELINE
)
1657 flushrc
= buffer_flush_window(vty
->obuf
, vty_sock
, vty
->width
,
1660 flushrc
= buffer_flush_window(vty
->obuf
, vty_sock
, vty
->width
,
1661 vty
->lines
>= 0 ? vty
->lines
:
1667 vty
->monitor
= 0; /* disable monitoring to avoid infinite recursion */
1668 zlog_warn("buffer_flush failed on vty client fd %d, closing",
1670 buffer_reset(vty
->obuf
);
1674 if (vty
->status
== VTY_CLOSE
)
1678 vty
->status
= VTY_NORMAL
;
1679 if (vty
->lines
== 0)
1680 vty_event (VTY_READ
, vty_sock
, vty
);
1683 case BUFFER_PENDING
:
1684 /* There is more data waiting to be written. */
1685 vty
->status
= VTY_MORE
;
1686 if (vty
->lines
== 0)
1687 vty_event (VTY_WRITE
, vty_sock
, vty
);
1694 /* allocate and initialise vty */
1696 vty_new_init (int vty_sock
)
1702 vty
->wfd
= vty_sock
;
1703 vty
->type
= VTY_TERM
;
1704 vty
->node
= AUTH_NODE
;
1707 vty_clear_buf (vty
);
1709 memset (vty
->hist
, 0, sizeof (vty
->hist
));
1712 vector_set_index (vtyvec
, vty_sock
, vty
);
1713 vty
->status
= VTY_NORMAL
;
1716 vty
->iac_sb_in_progress
= 0;
1722 /* Create new vty structure. */
1724 vty_create (int vty_sock
, union sockunion
*su
)
1726 char buf
[SU_ADDRSTRLEN
];
1729 sockunion2str(su
, buf
, SU_ADDRSTRLEN
);
1731 /* Allocate new vty structure and set up default values. */
1732 vty
= vty_new_init (vty_sock
);
1734 /* configurable parameters not part of basic init */
1735 vty
->v_timeout
= vty_timeout_val
;
1736 strcpy (vty
->address
, buf
);
1737 if (no_password_check
)
1740 vty
->node
= ENABLE_NODE
;
1742 vty
->node
= VIEW_NODE
;
1744 if (host
.lines
>= 0)
1745 vty
->lines
= host
.lines
;
1747 if (! no_password_check
)
1749 /* Vty is not available if password isn't set. */
1750 if (host
.password
== NULL
&& host
.password_encrypt
== NULL
)
1752 vty_out (vty
, "Vty password is not set.\n");
1753 vty
->status
= VTY_CLOSE
;
1759 /* Say hello to the world. */
1761 if (! no_password_check
)
1762 vty_out (vty
, "\nUser Access Verification\n\n");
1764 /* Setting up terminal. */
1765 vty_will_echo (vty
);
1766 vty_will_suppress_go_ahead (vty
);
1768 vty_dont_linemode (vty
);
1769 vty_do_window_size (vty
);
1770 /* vty_dont_lflow_ahead (vty); */
1774 /* Add read/write thread. */
1775 vty_event (VTY_WRITE
, vty_sock
, vty
);
1776 vty_event (VTY_READ
, vty_sock
, vty
);
1781 /* create vty for stdio */
1782 static struct termios stdio_orig_termios
;
1783 static struct vty
*stdio_vty
= NULL
;
1784 static void (*stdio_vty_atclose
)(void);
1787 vty_stdio_reset (void)
1791 tcsetattr (0, TCSANOW
, &stdio_orig_termios
);
1794 if (stdio_vty_atclose
)
1795 stdio_vty_atclose ();
1796 stdio_vty_atclose
= NULL
;
1801 vty_stdio (void (*atclose
)())
1804 struct termios termios
;
1806 /* refuse creating two vtys on stdio */
1810 vty
= stdio_vty
= vty_new_init (0);
1811 stdio_vty_atclose
= atclose
;
1814 /* always have stdio vty in a known _unchangeable_ state, don't want config
1815 * to have any effect here to make sure scripting this works as intended */
1816 vty
->node
= ENABLE_NODE
;
1818 strcpy (vty
->address
, "console");
1820 if (!tcgetattr (0, &stdio_orig_termios
))
1822 termios
= stdio_orig_termios
;
1823 termios
.c_iflag
&= ~(IGNBRK
| BRKINT
| PARMRK
| ISTRIP
1824 | INLCR
| IGNCR
| ICRNL
| IXON
);
1825 termios
.c_oflag
&= ~OPOST
;
1826 termios
.c_lflag
&= ~(ECHO
| ECHONL
| ICANON
| ISIG
| IEXTEN
);
1827 termios
.c_cflag
&= ~(CSIZE
| PARENB
);
1828 termios
.c_cflag
|= CS8
;
1829 tcsetattr (0, TCSANOW
, &termios
);
1834 /* Add read/write thread. */
1835 vty_event (VTY_WRITE
, 1, vty
);
1836 vty_event (VTY_READ
, 0, vty
);
1841 /* Accept connection from the network. */
1843 vty_accept (struct thread
*thread
)
1851 struct access_list
*acl
= NULL
;
1852 char buf
[SU_ADDRSTRLEN
];
1854 accept_sock
= THREAD_FD (thread
);
1856 /* We continue hearing vty socket. */
1857 vty_event (VTY_SERV
, accept_sock
, NULL
);
1859 memset (&su
, 0, sizeof (union sockunion
));
1861 /* We can handle IPv4 or IPv6 socket. */
1862 vty_sock
= sockunion_accept (accept_sock
, &su
);
1865 zlog_warn ("can't accept vty socket : %s", safe_strerror (errno
));
1868 set_nonblocking(vty_sock
);
1869 set_cloexec(vty_sock
);
1871 sockunion2hostprefix (&su
, &p
);
1873 /* VTY's accesslist apply. */
1874 if (p
.family
== AF_INET
&& vty_accesslist_name
)
1876 if ((acl
= access_list_lookup (AFI_IP
, vty_accesslist_name
)) &&
1877 (access_list_apply (acl
, &p
) == FILTER_DENY
))
1879 zlog_info ("Vty connection refused from %s",
1880 sockunion2str (&su
, buf
, SU_ADDRSTRLEN
));
1883 /* continue accepting connections */
1884 vty_event (VTY_SERV
, accept_sock
, NULL
);
1890 /* VTY's ipv6 accesslist apply. */
1891 if (p
.family
== AF_INET6
&& vty_ipv6_accesslist_name
)
1893 if ((acl
= access_list_lookup (AFI_IP6
, vty_ipv6_accesslist_name
)) &&
1894 (access_list_apply (acl
, &p
) == FILTER_DENY
))
1896 zlog_info ("Vty connection refused from %s",
1897 sockunion2str (&su
, buf
, SU_ADDRSTRLEN
));
1900 /* continue accepting connections */
1901 vty_event (VTY_SERV
, accept_sock
, NULL
);
1908 ret
= setsockopt (vty_sock
, IPPROTO_TCP
, TCP_NODELAY
,
1909 (char *) &on
, sizeof (on
));
1911 zlog_info ("can't set sockopt to vty_sock : %s",
1912 safe_strerror (errno
));
1914 zlog_info ("Vty connection from %s",
1915 sockunion2str (&su
, buf
, SU_ADDRSTRLEN
));
1917 vty_create (vty_sock
, &su
);
1923 vty_serv_sock_addrinfo (const char *hostname
, unsigned short port
)
1926 struct addrinfo req
;
1927 struct addrinfo
*ainfo
;
1928 struct addrinfo
*ainfo_save
;
1930 char port_str
[BUFSIZ
];
1932 memset (&req
, 0, sizeof (struct addrinfo
));
1933 req
.ai_flags
= AI_PASSIVE
;
1934 req
.ai_family
= AF_UNSPEC
;
1935 req
.ai_socktype
= SOCK_STREAM
;
1936 sprintf (port_str
, "%d", port
);
1937 port_str
[sizeof (port_str
) - 1] = '\0';
1939 ret
= getaddrinfo (hostname
, port_str
, &req
, &ainfo
);
1943 fprintf (stderr
, "getaddrinfo failed: %s\n", gai_strerror (ret
));
1951 if (ainfo
->ai_family
!= AF_INET
1952 && ainfo
->ai_family
!= AF_INET6
1956 sock
= socket (ainfo
->ai_family
, ainfo
->ai_socktype
, ainfo
->ai_protocol
);
1960 sockopt_v6only (ainfo
->ai_family
, sock
);
1961 sockopt_reuseaddr (sock
);
1962 sockopt_reuseport (sock
);
1965 ret
= bind (sock
, ainfo
->ai_addr
, ainfo
->ai_addrlen
);
1968 close (sock
); /* Avoid sd leak. */
1972 ret
= listen (sock
, 3);
1975 close (sock
); /* Avoid sd leak. */
1979 vty_event (VTY_SERV
, sock
, NULL
);
1981 while ((ainfo
= ainfo
->ai_next
) != NULL
);
1983 freeaddrinfo (ainfo_save
);
1987 /* For sockaddr_un. */
1990 /* VTY shell UNIX domain socket. */
1992 vty_serv_un (const char *path
)
1996 struct sockaddr_un serv
;
1998 struct zprivs_ids_t ids
;
2000 /* First of all, unlink existing socket */
2004 old_mask
= umask (0007);
2006 /* Make UNIX domain socket. */
2007 sock
= socket (AF_UNIX
, SOCK_STREAM
, 0);
2010 zlog_err("Cannot create unix stream socket: %s", safe_strerror(errno
));
2014 /* Make server socket. */
2015 memset (&serv
, 0, sizeof (struct sockaddr_un
));
2016 serv
.sun_family
= AF_UNIX
;
2017 strlcpy (serv
.sun_path
, path
, sizeof (serv
.sun_path
));
2018 #ifdef HAVE_STRUCT_SOCKADDR_UN_SUN_LEN
2019 len
= serv
.sun_len
= SUN_LEN(&serv
);
2021 len
= sizeof (serv
.sun_family
) + strlen (serv
.sun_path
);
2022 #endif /* HAVE_STRUCT_SOCKADDR_UN_SUN_LEN */
2026 ret
= bind (sock
, (struct sockaddr
*) &serv
, len
);
2029 zlog_err("Cannot bind path %s: %s", path
, safe_strerror(errno
));
2030 close (sock
); /* Avoid sd leak. */
2034 ret
= listen (sock
, 5);
2037 zlog_err("listen(fd %d) failed: %s", sock
, safe_strerror(errno
));
2038 close (sock
); /* Avoid sd leak. */
2044 zprivs_get_ids(&ids
);
2046 /* Hack: ids.gid_vty is actually a uint, but we stored -1 in it
2047 earlier for the case when we don't need to chown the file
2048 type casting it here to make a compare */
2049 if ((int)ids
.gid_vty
> 0)
2051 /* set group of socket */
2052 if ( chown (path
, -1, ids
.gid_vty
) )
2054 zlog_err ("vty_serv_un: could chown socket, %s",
2055 safe_strerror (errno
) );
2059 vty_event (VTYSH_SERV
, sock
, NULL
);
2062 /* #define VTYSH_DEBUG 1 */
2065 vtysh_accept (struct thread
*thread
)
2070 struct sockaddr_un client
;
2073 accept_sock
= THREAD_FD (thread
);
2075 vty_event (VTYSH_SERV
, accept_sock
, NULL
);
2077 memset (&client
, 0, sizeof (struct sockaddr_un
));
2078 client_len
= sizeof (struct sockaddr_un
);
2080 sock
= accept (accept_sock
, (struct sockaddr
*) &client
,
2081 (socklen_t
*) &client_len
);
2085 zlog_warn ("can't accept vty socket : %s", safe_strerror (errno
));
2089 if (set_nonblocking(sock
) < 0)
2091 zlog_warn ("vtysh_accept: could not set vty socket %d to non-blocking,"
2092 " %s, closing", sock
, safe_strerror (errno
));
2099 printf ("VTY shell accept\n");
2100 #endif /* VTYSH_DEBUG */
2105 vty
->type
= VTY_SHELL_SERV
;
2106 vty
->node
= VIEW_NODE
;
2108 vty_event (VTYSH_READ
, sock
, vty
);
2114 vtysh_flush(struct vty
*vty
)
2116 switch (buffer_flush_available(vty
->obuf
, vty
->wfd
))
2118 case BUFFER_PENDING
:
2119 vty_event(VTYSH_WRITE
, vty
->wfd
, vty
);
2122 vty
->monitor
= 0; /* disable monitoring to avoid infinite recursion */
2123 zlog_warn("%s: write error to fd %d, closing", __func__
, vty
->fd
);
2124 buffer_reset(vty
->obuf
);
2135 vtysh_read (struct thread
*thread
)
2141 unsigned char buf
[VTY_READ_BUFSIZ
];
2143 u_char header
[4] = {0, 0, 0, 0};
2145 sock
= THREAD_FD (thread
);
2146 vty
= THREAD_ARG (thread
);
2149 if ((nbytes
= read (sock
, buf
, VTY_READ_BUFSIZ
)) <= 0)
2153 if (ERRNO_IO_RETRY(errno
))
2155 vty_event (VTYSH_READ
, sock
, vty
);
2158 vty
->monitor
= 0; /* disable monitoring to avoid infinite recursion */
2159 zlog_warn("%s: read failed on vtysh client fd %d, closing: %s",
2160 __func__
, sock
, safe_strerror(errno
));
2162 buffer_reset(vty
->obuf
);
2165 printf ("close vtysh\n");
2166 #endif /* VTYSH_DEBUG */
2171 printf ("line: %.*s\n", nbytes
, buf
);
2172 #endif /* VTYSH_DEBUG */
2174 if (vty
->length
+ nbytes
>= VTY_BUFSIZ
)
2176 /* Clear command line buffer. */
2177 vty
->cp
= vty
->length
= 0;
2178 vty_clear_buf (vty
);
2179 vty_out (vty
, "%% Command is too long.\n");
2183 for (p
= buf
; p
< buf
+nbytes
; p
++)
2185 vty
->buf
[vty
->length
++] = *p
;
2188 /* Pass this line to parser. */
2189 ret
= vty_execute (vty
);
2190 /* Note that vty_execute clears the command buffer and resets
2191 vty->length to 0. */
2193 /* Return result. */
2195 printf ("result: %d\n", ret
);
2196 printf ("vtysh node: %d\n", vty
->node
);
2197 #endif /* VTYSH_DEBUG */
2199 /* hack for asynchronous "write integrated"
2200 * - other commands in "buf" will be ditched
2201 * - input during pending config-write is "unsupported" */
2202 if (ret
== CMD_SUSPEND
)
2205 /* warning: watchfrr hardcodes this result write */
2207 buffer_put(vty
->obuf
, header
, 4);
2209 if (!vty
->t_write
&& (vtysh_flush(vty
) < 0))
2210 /* Try to flush results; exit if a write error occurs. */
2216 if (vty
->status
== VTY_CLOSE
)
2219 vty_event (VTYSH_READ
, sock
, vty
);
2225 vtysh_write (struct thread
*thread
)
2227 struct vty
*vty
= THREAD_ARG (thread
);
2229 vty
->t_write
= NULL
;
2236 /* Determine address family to bind. */
2238 vty_serv_sock (const char *addr
, unsigned short port
, const char *path
)
2240 /* If port is set to 0, do not listen on TCP/IP at all! */
2242 vty_serv_sock_addrinfo (addr
, port
);
2249 /* Close vty interface. Warning: call this only from functions that
2250 will be careful not to access the vty afterwards (since it has
2251 now been freed). This is safest from top-level functions (called
2252 directly by the thread dispatcher). */
2254 vty_close (struct vty
*vty
)
2257 bool was_stdio
= false;
2259 /* Cancel threads.*/
2261 thread_cancel (vty
->t_read
);
2263 thread_cancel (vty
->t_write
);
2265 thread_cancel (vty
->t_timeout
);
2268 buffer_flush_all (vty
->obuf
, vty
->wfd
);
2270 /* Free input buffer. */
2271 buffer_free (vty
->obuf
);
2273 /* Free command history. */
2274 for (i
= 0; i
< VTY_MAXHIST
; i
++)
2276 XFREE (MTYPE_VTY_HIST
, vty
->hist
[i
]);
2279 vector_unset (vtyvec
, vty
->fd
);
2281 if (vty
->wfd
> 0 && vty
->type
== VTY_FILE
)
2288 if (vty
->wfd
> 0 && vty
->wfd
!= vty
->fd
)
2295 XFREE (MTYPE_VTY
, vty
->buf
);
2298 XFREE (MTYPE_VTY
, vty
->error_buf
);
2300 /* Check configure. */
2301 vty_config_unlock (vty
);
2304 XFREE (MTYPE_VTY
, vty
);
2310 /* When time out occur output message then close connection. */
2312 vty_timeout (struct thread
*thread
)
2316 vty
= THREAD_ARG (thread
);
2317 vty
->t_timeout
= NULL
;
2321 buffer_reset (vty
->obuf
);
2322 vty_out (vty
, "\nVty connection is timed out.\n");
2324 /* Close connection. */
2325 vty
->status
= VTY_CLOSE
;
2331 /* Read up configuration file from file_name. */
2333 vty_read_file (FILE *confp
)
2337 unsigned int line_num
= 0;
2340 vty
->wfd
= dup(STDERR_FILENO
); /* vty_close() will close this */
2343 /* Fine, we couldn't make a new fd. vty_close doesn't close stdout. */
2344 vty
->wfd
= STDOUT_FILENO
;
2346 vty
->fd
= STDIN_FILENO
;
2347 vty
->type
= VTY_FILE
;
2348 vty
->node
= CONFIG_NODE
;
2350 /* Execute configuration file */
2351 ret
= config_from_file (vty
, confp
, &line_num
);
2353 /* Flush any previous errors before printing messages below */
2354 buffer_flush_all (vty
->obuf
, vty
->fd
);
2356 if ( !((ret
== CMD_SUCCESS
) || (ret
== CMD_ERR_NOTHING_TODO
)) )
2358 const char *message
= NULL
;
2361 case CMD_ERR_AMBIGUOUS
:
2362 message
= "*** Error reading config: Ambiguous command.";
2364 case CMD_ERR_NO_MATCH
:
2365 message
= "*** Error reading config: There is no such command.";
2368 fprintf (stderr
, "%s\n", message
);
2369 zlog_err ("%s", message
);
2370 fprintf (stderr
, "*** Error occurred processing line %u, below:\n%s\n",
2371 line_num
, vty
->error_buf
);
2372 zlog_err ("*** Error occurred processing line %u, below:\n%s",
2373 line_num
, vty
->error_buf
);
2380 vty_use_backup_config (const char *fullpath
)
2382 char *fullpath_sav
, *fullpath_tmp
;
2388 fullpath_sav
= malloc (strlen (fullpath
) + strlen (CONF_BACKUP_EXT
) + 1);
2389 strcpy (fullpath_sav
, fullpath
);
2390 strcat (fullpath_sav
, CONF_BACKUP_EXT
);
2392 sav
= open (fullpath_sav
, O_RDONLY
);
2395 free (fullpath_sav
);
2399 fullpath_tmp
= malloc (strlen (fullpath
) + 8);
2400 sprintf (fullpath_tmp
, "%s.XXXXXX", fullpath
);
2402 /* Open file to configuration write. */
2403 tmp
= mkstemp (fullpath_tmp
);
2407 if (fchmod (tmp
, CONFIGFILE_MASK
) != 0)
2410 while((c
= read (sav
, buffer
, 512)) > 0)
2412 if (write (tmp
, buffer
, c
) <= 0)
2418 if (rename (fullpath_tmp
, fullpath
) == 0)
2419 ret
= fopen (fullpath
, "r");
2421 unlink (fullpath_tmp
);
2427 unlink (fullpath_tmp
);
2432 free (fullpath_sav
);
2433 free (fullpath_tmp
);
2437 /* Read up configuration file from file_name. */
2439 vty_read_config (const char *config_file
,
2440 char *config_default_dir
)
2442 char cwd
[MAXPATHLEN
];
2444 const char *fullpath
;
2447 /* If -f flag specified. */
2448 if (config_file
!= NULL
)
2450 if (! IS_DIRECTORY_SEP (config_file
[0]))
2452 if (getcwd (cwd
, MAXPATHLEN
) == NULL
)
2454 fprintf (stderr
, "Failure to determine Current Working Directory %d!\n", errno
);
2457 tmp
= XMALLOC (MTYPE_TMP
,
2458 strlen (cwd
) + strlen (config_file
) + 2);
2459 sprintf (tmp
, "%s/%s", cwd
, config_file
);
2463 fullpath
= config_file
;
2465 confp
= fopen (fullpath
, "r");
2469 fprintf (stderr
, "%s: failed to open configuration file %s: %s\n",
2470 __func__
, fullpath
, safe_strerror (errno
));
2472 confp
= vty_use_backup_config (fullpath
);
2474 fprintf (stderr
, "WARNING: using backup configuration file!\n");
2477 fprintf (stderr
, "can't open configuration file [%s]\n",
2486 host_config_set (config_default_dir
);
2490 struct stat conf_stat
;
2492 /* !!!!PLEASE LEAVE!!!!
2493 * This is NEEDED for use with vtysh -b, or else you can get
2494 * a real configuration food fight with a lot garbage in the
2495 * merged configuration file it creates coming from the per
2496 * daemon configuration files. This also allows the daemons
2497 * to start if there default configuration file is not
2498 * present or ignore them, as needed when using vtysh -b to
2499 * configure the daemons at boot - MAG
2502 /* Stat for vtysh Zebra.conf, if found startup and wait for
2503 * boot configuration
2506 if ( strstr(config_default_dir
, "vtysh") == NULL
)
2508 ret
= stat (integrate_default
, &conf_stat
);
2510 goto tmp_free_and_out
;
2513 confp
= fopen (config_default_dir
, "r");
2516 fprintf (stderr
, "%s: failed to open configuration file %s: %s\n",
2517 __func__
, config_default_dir
, safe_strerror (errno
));
2519 confp
= vty_use_backup_config (config_default_dir
);
2522 fprintf (stderr
, "WARNING: using backup configuration file!\n");
2523 fullpath
= config_default_dir
;
2527 fprintf (stderr
, "can't open configuration file [%s]\n",
2528 config_default_dir
);
2529 goto tmp_free_and_out
;
2533 fullpath
= config_default_dir
;
2536 vty_read_file (confp
);
2540 host_config_set (fullpath
);
2544 XFREE (MTYPE_TMP
, tmp
);
2547 /* Small utility function which output log to the VTY. */
2549 vty_log (const char *level
, const char *proto_str
,
2550 const char *format
, struct timestamp_control
*ctl
, va_list va
)
2558 for (i
= 0; i
< vector_active (vtyvec
); i
++)
2559 if ((vty
= vector_slot (vtyvec
, i
)) != NULL
)
2564 vty_log_out (vty
, level
, proto_str
, format
, ctl
, ac
);
2569 /* Async-signal-safe version of vty_log for fixed strings. */
2571 vty_log_fixed (char *buf
, size_t len
)
2574 struct iovec iov
[2];
2575 char crlf
[4] = "\r\n";
2577 /* vty may not have been initialised */
2581 iov
[0].iov_base
= buf
;
2582 iov
[0].iov_len
= len
;
2583 iov
[1].iov_base
= crlf
;
2586 for (i
= 0; i
< vector_active (vtyvec
); i
++)
2589 if (((vty
= vector_slot (vtyvec
, i
)) != NULL
) && vty
->monitor
)
2590 /* N.B. We don't care about the return code, since process is
2591 most likely just about to die anyway. */
2592 if (writev(vty
->wfd
, iov
, 2) == -1)
2594 fprintf(stderr
, "Failure to writev: %d\n", errno
);
2601 vty_config_lock (struct vty
*vty
)
2603 if (vty_config_is_lockless
)
2605 if (vty_config
== 0)
2614 vty_config_unlock (struct vty
*vty
)
2616 if (vty_config_is_lockless
)
2618 if (vty_config
== 1 && vty
->config
== 1)
2627 vty_config_lockless (void)
2629 vty_config_is_lockless
= 1;
2632 /* Master of the threads. */
2633 static struct thread_master
*vty_master
;
2636 vty_event (enum event event
, int sock
, struct vty
*vty
)
2638 struct thread
*vty_serv_thread
= NULL
;
2643 vty_serv_thread
= thread_add_read(vty_master
, vty_accept
, vty
, sock
, NULL
);
2644 vector_set_index (Vvty_serv_thread
, sock
, vty_serv_thread
);
2648 vty_serv_thread
= thread_add_read(vty_master
, vtysh_accept
, vty
, sock
, NULL
);
2649 vector_set_index (Vvty_serv_thread
, sock
, vty_serv_thread
);
2653 thread_add_read(vty_master
, vtysh_read
, vty
, sock
, &vty
->t_read
);
2656 vty
->t_write
= NULL
;
2657 thread_add_write(vty_master
, vtysh_write
, vty
, sock
, &vty
->t_write
);
2662 thread_add_read(vty_master
, vty_read
, vty
, sock
, &vty
->t_read
);
2664 /* Time out treatment. */
2668 thread_cancel (vty
->t_timeout
);
2669 vty
->t_timeout
= NULL
;
2670 thread_add_timer(vty_master
, vty_timeout
, vty
, vty
->v_timeout
,
2675 thread_add_write(vty_master
, vty_flush
, vty
, sock
, &vty
->t_write
);
2677 case VTY_TIMEOUT_RESET
:
2680 thread_cancel (vty
->t_timeout
);
2681 vty
->t_timeout
= NULL
;
2685 vty
->t_timeout
= NULL
;
2686 thread_add_timer(vty_master
, vty_timeout
, vty
, vty
->v_timeout
,
2693 DEFUN_NOSH (config_who
,
2696 "Display who is on vty\n")
2701 for (i
= 0; i
< vector_active (vtyvec
); i
++)
2702 if ((v
= vector_slot (vtyvec
, i
)) != NULL
)
2703 vty_out (vty
, "%svty[%d] connected from %s.\n",
2704 v
->config
? "*" : " ",
2709 /* Move to vty configuration mode. */
2710 DEFUN_NOSH (line_vty
,
2713 "Configure a terminal line\n"
2714 "Virtual terminal\n")
2716 vty
->node
= VTY_NODE
;
2720 /* Set time out value. */
2722 exec_timeout (struct vty
*vty
, const char *min_str
, const char *sec_str
)
2724 unsigned long timeout
= 0;
2726 /* min_str and sec_str are already checked by parser. So it must be
2727 all digit string. */
2730 timeout
= strtol (min_str
, NULL
, 10);
2734 timeout
+= strtol (sec_str
, NULL
, 10);
2736 vty_timeout_val
= timeout
;
2737 vty
->v_timeout
= timeout
;
2738 vty_event (VTY_TIMEOUT_RESET
, 0, vty
);
2744 DEFUN (exec_timeout_min
,
2745 exec_timeout_min_cmd
,
2746 "exec-timeout (0-35791)",
2747 "Set timeout value\n"
2748 "Timeout value in minutes\n")
2751 return exec_timeout (vty
, argv
[idx_number
]->arg
, NULL
);
2754 DEFUN (exec_timeout_sec
,
2755 exec_timeout_sec_cmd
,
2756 "exec-timeout (0-35791) (0-2147483)",
2757 "Set the EXEC timeout\n"
2758 "Timeout in minutes\n"
2759 "Timeout in seconds\n")
2762 int idx_number_2
= 2;
2763 return exec_timeout (vty
, argv
[idx_number
]->arg
, argv
[idx_number_2
]->arg
);
2766 DEFUN (no_exec_timeout
,
2767 no_exec_timeout_cmd
,
2770 "Set the EXEC timeout\n")
2772 return exec_timeout (vty
, NULL
, NULL
);
2775 /* Set vty access class. */
2776 DEFUN (vty_access_class
,
2777 vty_access_class_cmd
,
2778 "access-class WORD",
2779 "Filter connections based on an IP access list\n"
2783 if (vty_accesslist_name
)
2784 XFREE(MTYPE_VTY
, vty_accesslist_name
);
2786 vty_accesslist_name
= XSTRDUP(MTYPE_VTY
, argv
[idx_word
]->arg
);
2791 /* Clear vty access class. */
2792 DEFUN (no_vty_access_class
,
2793 no_vty_access_class_cmd
,
2794 "no access-class [WORD]",
2796 "Filter connections based on an IP access list\n"
2800 const char *accesslist
= (argc
== 3) ? argv
[idx_word
]->arg
: NULL
;
2801 if (! vty_accesslist_name
|| (argc
== 3 && strcmp(vty_accesslist_name
, accesslist
)))
2803 vty_out (vty
,"Access-class is not currently applied to vty\n");
2804 return CMD_WARNING_CONFIG_FAILED
;
2807 XFREE(MTYPE_VTY
, vty_accesslist_name
);
2809 vty_accesslist_name
= NULL
;
2814 /* Set vty access class. */
2815 DEFUN (vty_ipv6_access_class
,
2816 vty_ipv6_access_class_cmd
,
2817 "ipv6 access-class WORD",
2819 "Filter connections based on an IP access list\n"
2820 "IPv6 access list\n")
2823 if (vty_ipv6_accesslist_name
)
2824 XFREE(MTYPE_VTY
, vty_ipv6_accesslist_name
);
2826 vty_ipv6_accesslist_name
= XSTRDUP(MTYPE_VTY
, argv
[idx_word
]->arg
);
2831 /* Clear vty access class. */
2832 DEFUN (no_vty_ipv6_access_class
,
2833 no_vty_ipv6_access_class_cmd
,
2834 "no ipv6 access-class [WORD]",
2837 "Filter connections based on an IP access list\n"
2838 "IPv6 access list\n")
2841 const char *accesslist
= (argc
== 4) ? argv
[idx_word
]->arg
: NULL
;
2843 if (! vty_ipv6_accesslist_name
||
2844 (argc
== 4 && strcmp(vty_ipv6_accesslist_name
, accesslist
)))
2846 vty_out (vty
,"IPv6 access-class is not currently applied to vty\n");
2847 return CMD_WARNING_CONFIG_FAILED
;
2850 XFREE(MTYPE_VTY
, vty_ipv6_accesslist_name
);
2852 vty_ipv6_accesslist_name
= NULL
;
2861 "Enable password checking\n")
2863 no_password_check
= 0;
2867 DEFUN (no_vty_login
,
2871 "Enable password checking\n")
2873 no_password_check
= 1;
2877 DEFUN (service_advanced_vty
,
2878 service_advanced_vty_cmd
,
2879 "service advanced-vty",
2880 "Set up miscellaneous service\n"
2881 "Enable advanced mode vty interface\n")
2887 DEFUN (no_service_advanced_vty
,
2888 no_service_advanced_vty_cmd
,
2889 "no service advanced-vty",
2891 "Set up miscellaneous service\n"
2892 "Enable advanced mode vty interface\n")
2898 DEFUN_NOSH (terminal_monitor
,
2899 terminal_monitor_cmd
,
2901 "Set terminal line parameters\n"
2902 "Copy debug output to the current terminal line\n")
2908 DEFUN_NOSH (terminal_no_monitor
,
2909 terminal_no_monitor_cmd
,
2910 "terminal no monitor",
2911 "Set terminal line parameters\n"
2913 "Copy debug output to the current terminal line\n")
2919 DEFUN_NOSH (no_terminal_monitor
,
2920 no_terminal_monitor_cmd
,
2921 "no terminal monitor",
2923 "Set terminal line parameters\n"
2924 "Copy debug output to the current terminal line\n")
2926 return terminal_no_monitor (self
, vty
, argc
, argv
);
2930 DEFUN_NOSH (show_history
,
2934 "Display the session command history\n")
2938 for (index
= vty
->hindex
+ 1; index
!= vty
->hindex
;)
2940 if (index
== VTY_MAXHIST
)
2946 if (vty
->hist
[index
] != NULL
)
2947 vty_out (vty
, " %s\n", vty
->hist
[index
]);
2956 DEFUN (log_commands
,
2960 "Log all commands (can't be unset without restart)\n")
2962 do_log_commands
= 1;
2966 /* Display current configuration. */
2968 vty_config_write (struct vty
*vty
)
2970 vty_out (vty
, "line vty\n");
2972 if (vty_accesslist_name
)
2973 vty_out (vty
, " access-class %s\n",
2974 vty_accesslist_name
);
2976 if (vty_ipv6_accesslist_name
)
2977 vty_out (vty
, " ipv6 access-class %s\n",
2978 vty_ipv6_accesslist_name
);
2981 if (vty_timeout_val
!= VTY_TIMEOUT_DEFAULT
)
2982 vty_out (vty
, " exec-timeout %ld %ld\n",
2983 vty_timeout_val
/ 60,
2984 vty_timeout_val
% 60);
2987 if (no_password_check
)
2988 vty_out (vty
, " no login\n");
2990 if (do_log_commands
)
2991 vty_out (vty
, "log commands\n");
2993 vty_out (vty
, "!\n");
2998 struct cmd_node vty_node
=
3001 "%s(config-line)# ",
3005 /* Reset all VTY status. */
3011 struct thread
*vty_serv_thread
;
3013 for (i
= 0; i
< vector_active (vtyvec
); i
++)
3014 if ((vty
= vector_slot (vtyvec
, i
)) != NULL
)
3016 buffer_reset (vty
->obuf
);
3017 vty
->status
= VTY_CLOSE
;
3021 for (i
= 0; i
< vector_active (Vvty_serv_thread
); i
++)
3022 if ((vty_serv_thread
= vector_slot (Vvty_serv_thread
, i
)) != NULL
)
3024 thread_cancel (vty_serv_thread
);
3025 vector_slot (Vvty_serv_thread
, i
) = NULL
;
3029 vty_timeout_val
= VTY_TIMEOUT_DEFAULT
;
3031 if (vty_accesslist_name
)
3033 XFREE(MTYPE_VTY
, vty_accesslist_name
);
3034 vty_accesslist_name
= NULL
;
3037 if (vty_ipv6_accesslist_name
)
3039 XFREE(MTYPE_VTY
, vty_ipv6_accesslist_name
);
3040 vty_ipv6_accesslist_name
= NULL
;
3047 char cwd
[MAXPATHLEN
];
3050 c
= getcwd (cwd
, MAXPATHLEN
);
3055 * At this point if these go wrong, more than likely
3056 * the whole world is coming down around us
3057 * Hence not worrying about it too much.
3059 if (!chdir (SYSCONFDIR
))
3061 fprintf(stderr
, "Failure to chdir to %s, errno: %d\n", SYSCONFDIR
, errno
);
3064 if (getcwd (cwd
, MAXPATHLEN
) == NULL
)
3066 fprintf(stderr
, "Failure to getcwd, errno: %d\n", errno
);
3071 vty_cwd
= XMALLOC (MTYPE_TMP
, strlen (cwd
) + 1);
3072 strcpy (vty_cwd
, cwd
);
3082 vty_shell (struct vty
*vty
)
3084 return vty
->type
== VTY_SHELL
? 1 : 0;
3088 vty_shell_serv (struct vty
*vty
)
3090 return vty
->type
== VTY_SHELL_SERV
? 1 : 0;
3096 vtyvec
= vector_init (VECTOR_MIN_SIZE
);
3099 /* Install vty's own commands like `who' command. */
3101 vty_init (struct thread_master
*master_thread
)
3103 /* For further configuration read, preserve current directory. */
3106 vtyvec
= vector_init (VECTOR_MIN_SIZE
);
3108 vty_master
= master_thread
;
3110 atexit (vty_stdio_reset
);
3112 /* Initilize server thread vector. */
3113 Vvty_serv_thread
= vector_init (VECTOR_MIN_SIZE
);
3115 /* Install bgp top node. */
3116 install_node (&vty_node
, vty_config_write
);
3118 install_element (VIEW_NODE
, &config_who_cmd
);
3119 install_element (VIEW_NODE
, &show_history_cmd
);
3120 install_element (CONFIG_NODE
, &line_vty_cmd
);
3121 install_element (CONFIG_NODE
, &service_advanced_vty_cmd
);
3122 install_element (CONFIG_NODE
, &no_service_advanced_vty_cmd
);
3123 install_element (CONFIG_NODE
, &show_history_cmd
);
3124 install_element (CONFIG_NODE
, &log_commands_cmd
);
3125 install_element (ENABLE_NODE
, &terminal_monitor_cmd
);
3126 install_element (ENABLE_NODE
, &terminal_no_monitor_cmd
);
3127 install_element (ENABLE_NODE
, &no_terminal_monitor_cmd
);
3129 install_default (VTY_NODE
);
3130 install_element (VTY_NODE
, &exec_timeout_min_cmd
);
3131 install_element (VTY_NODE
, &exec_timeout_sec_cmd
);
3132 install_element (VTY_NODE
, &no_exec_timeout_cmd
);
3133 install_element (VTY_NODE
, &vty_access_class_cmd
);
3134 install_element (VTY_NODE
, &no_vty_access_class_cmd
);
3135 install_element (VTY_NODE
, &vty_login_cmd
);
3136 install_element (VTY_NODE
, &no_vty_login_cmd
);
3137 install_element (VTY_NODE
, &vty_ipv6_access_class_cmd
);
3138 install_element (VTY_NODE
, &no_vty_ipv6_access_class_cmd
);
3142 vty_terminate (void)
3145 XFREE (MTYPE_TMP
, vty_cwd
);
3147 if (vtyvec
&& Vvty_serv_thread
)
3150 vector_free (vtyvec
);
3151 vector_free (Vvty_serv_thread
);
3153 Vvty_serv_thread
= NULL
;