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;
96 vty_out_variadic (struct vty
*vty
, const char *format
, va_list args
)
105 vprintf (format
, args
);
108 /* Try to write to initial buffer. */
110 len
= vsnprintf (buf
, sizeof(buf
), format
, cp
);
113 /* Initial buffer is not enough. */
114 if (len
< 0 || len
>= size
)
123 p
= XREALLOC (MTYPE_VTY_OUT_BUF
, p
, size
);
128 len
= vsnprintf (p
, size
, format
, cp
);
131 if (len
> -1 && len
< size
)
136 /* When initial buffer is enough to store all output. */
140 /* Pointer p must point out buffer. */
141 buffer_put (vty
->obuf
, (u_char
*) p
, len
);
143 /* If p is not different with buf, it is allocated buffer. */
145 XFREE (MTYPE_VTY_OUT_BUF
, p
);
150 /* VTY standard output function. */
152 vty_out (struct vty
*vty
, const char *format
, ...)
157 va_start (args
, format
);
158 len
= vty_out_variadic (vty
, format
, args
);
165 vty_outln (struct vty
*vty
, const char *format
, ...)
170 va_start (args
, format
);
171 len
= vty_out_variadic (vty
, format
, args
);
174 return len
+ vty_out (vty
, "%s", VTYNL
);
178 vty_log_out (struct vty
*vty
, const char *level
, const char *proto_str
,
179 const char *format
, struct timestamp_control
*ctl
, va_list va
)
185 if (!ctl
->already_rendered
)
187 ctl
->len
= quagga_timestamp(ctl
->precision
, ctl
->buf
, sizeof(ctl
->buf
));
188 ctl
->already_rendered
= 1;
190 if (ctl
->len
+1 >= sizeof(buf
))
192 memcpy(buf
, ctl
->buf
, len
= ctl
->len
);
197 ret
= snprintf(buf
+len
, sizeof(buf
)-len
, "%s: %s: ", level
, proto_str
);
199 ret
= snprintf(buf
+len
, sizeof(buf
)-len
, "%s: ", proto_str
);
200 if ((ret
< 0) || ((size_t)(len
+= ret
) >= sizeof(buf
)))
203 if (((ret
= vsnprintf(buf
+len
, sizeof(buf
)-len
, format
, va
)) < 0) ||
204 ((size_t)((len
+= ret
)+2) > sizeof(buf
)))
210 if (write(vty
->wfd
, buf
, len
) < 0)
212 if (ERRNO_IO_RETRY(errno
))
213 /* Kernel buffer is full, probably too much debugging output, so just
214 drop the data and ignore. */
216 /* Fatal I/O error. */
217 vty
->monitor
= 0; /* disable monitoring to avoid infinite recursion */
218 zlog_warn("%s: write failed to vty client fd %d, closing: %s",
219 __func__
, vty
->fd
, safe_strerror(errno
));
220 buffer_reset(vty
->obuf
);
221 /* cannot call vty_close, because a parent routine may still try
222 to access the vty struct */
223 vty
->status
= VTY_CLOSE
;
224 shutdown(vty
->fd
, SHUT_RDWR
);
230 /* Output current time to the vty. */
232 vty_time_print (struct vty
*vty
, int cr
)
234 char buf
[QUAGGA_TIMESTAMP_LEN
];
236 if (quagga_timestamp(0, buf
, sizeof(buf
)) == 0)
238 zlog_info("quagga_timestamp error");
242 vty_out (vty
, "%s\n", buf
);
244 vty_out (vty
, "%s ", buf
);
249 /* Say hello to vty interface. */
251 vty_hello (struct vty
*vty
)
258 f
= fopen (host
.motdfile
, "r");
261 while (fgets (buf
, sizeof (buf
), f
))
264 /* work backwards to ignore trailling isspace() */
265 for (s
= buf
+ strlen (buf
); (s
> buf
) && isspace ((int)*(s
- 1));
268 vty_outln (vty
, "%s", buf
);
273 vty_outln (vty
, "MOTD file not found");
276 vty_out (vty
, "%s", host
.motd
);
279 /* Put out prompt and wait input from user. */
281 vty_prompt (struct vty
*vty
)
283 struct utsname names
;
286 if (vty
->type
== VTY_TERM
)
288 hostname
= host
.name
;
292 hostname
= names
.nodename
;
294 vty_out (vty
, cmd_prompt (vty
->node
), hostname
);
298 /* Send WILL TELOPT_ECHO to remote server. */
300 vty_will_echo (struct vty
*vty
)
302 unsigned char cmd
[] = { IAC
, WILL
, TELOPT_ECHO
, '\0' };
303 vty_out (vty
, "%s", cmd
);
306 /* Make suppress Go-Ahead telnet option. */
308 vty_will_suppress_go_ahead (struct vty
*vty
)
310 unsigned char cmd
[] = { IAC
, WILL
, TELOPT_SGA
, '\0' };
311 vty_out (vty
, "%s", cmd
);
314 /* Make don't use linemode over telnet. */
316 vty_dont_linemode (struct vty
*vty
)
318 unsigned char cmd
[] = { IAC
, DONT
, TELOPT_LINEMODE
, '\0' };
319 vty_out (vty
, "%s", cmd
);
322 /* Use window size. */
324 vty_do_window_size (struct vty
*vty
)
326 unsigned char cmd
[] = { IAC
, DO
, TELOPT_NAWS
, '\0' };
327 vty_out (vty
, "%s", cmd
);
330 #if 0 /* Currently not used. */
331 /* Make don't use lflow vty interface. */
333 vty_dont_lflow_ahead (struct vty
*vty
)
335 unsigned char cmd
[] = { IAC
, DONT
, TELOPT_LFLOW
, '\0' };
336 vty_out (vty
, "%s", cmd
);
340 /* Allocate new vty struct. */
344 struct vty
*new = XCALLOC (MTYPE_VTY
, sizeof (struct vty
));
346 new->obuf
= buffer_new(0); /* Use default buffer size. */
347 new->buf
= XCALLOC (MTYPE_VTY
, VTY_BUFSIZ
);
348 new->error_buf
= XCALLOC (MTYPE_VTY
, VTY_BUFSIZ
);
349 new->max
= VTY_BUFSIZ
;
354 /* Authentication of vty */
356 vty_auth (struct vty
*vty
, char *buf
)
359 enum node_type next_node
= 0;
361 char *crypt (const char *, const char *);
367 passwd
= host
.password_encrypt
;
369 passwd
= host
.password
;
371 next_node
= host
.enable
? VIEW_NODE
: ENABLE_NODE
;
373 next_node
= VIEW_NODE
;
375 case AUTH_ENABLE_NODE
:
377 passwd
= host
.enable_encrypt
;
379 passwd
= host
.enable
;
380 next_node
= ENABLE_NODE
;
387 fail
= strcmp (crypt(buf
, passwd
), passwd
);
389 fail
= strcmp (buf
, passwd
);
397 vty
->node
= next_node
; /* Success ! */
404 if (vty
->node
== AUTH_NODE
)
406 vty_outln (vty
, "%% Bad passwords, too many failures!");
407 vty
->status
= VTY_CLOSE
;
411 /* AUTH_ENABLE_NODE */
413 vty_outln (vty
, "%% Bad enable passwords, too many failures!");
414 vty
->status
= VTY_CLOSE
;
420 /* Command execution over the vty interface. */
422 vty_command (struct vty
*vty
, char *buf
)
426 const char *protocolname
;
430 * Log non empty command lines
436 /* Skip white spaces. */
437 while (isspace ((int) *cp
) && *cp
!= '\0')
440 if (cp
!= NULL
&& *cp
!= '\0')
443 char vty_str
[VTY_BUFSIZ
];
444 char prompt_str
[VTY_BUFSIZ
];
446 /* format the base vty info */
447 snprintf(vty_str
, sizeof(vty_str
), "vty[??]@%s", vty
->address
);
449 for (i
= 0; i
< vector_active (vtyvec
); i
++)
450 if (vty
== vector_slot (vtyvec
, i
))
452 snprintf(vty_str
, sizeof(vty_str
), "vty[%d]@%s",
457 /* format the prompt */
458 snprintf(prompt_str
, sizeof(prompt_str
), cmd_prompt (vty
->node
), vty_str
);
460 /* now log the command */
461 zlog_err("%s%s", prompt_str
, buf
);
463 /* Split readline string up into the vector */
464 vline
= cmd_make_strvec (buf
);
469 #ifdef CONSUMED_TIME_CHECK
473 unsigned long realtime
, cputime
;
476 #endif /* CONSUMED_TIME_CHECK */
478 ret
= cmd_execute_command (vline
, vty
, NULL
, 0);
480 /* Get the name of the protocol if any */
481 protocolname
= frr_protoname
;
483 #ifdef CONSUMED_TIME_CHECK
485 if ((realtime
= thread_consumed_time(&after
, &before
, &cputime
)) >
487 /* Warn about CPU hog that must be fixed. */
488 zlog_warn("SLOW COMMAND: command took %lums (cpu time %lums): %s",
489 realtime
/1000, cputime
/1000, buf
);
491 #endif /* CONSUMED_TIME_CHECK */
493 if (ret
!= CMD_SUCCESS
)
497 if (vty
->type
== VTY_FILE
)
498 vty_outln (vty
, "Warning...");
500 case CMD_ERR_AMBIGUOUS
:
501 vty_outln (vty
, "%% Ambiguous command.");
503 case CMD_ERR_NO_MATCH
:
504 vty_outln (vty
, "%% [%s] Unknown command: %s", protocolname
, buf
);
506 case CMD_ERR_INCOMPLETE
:
507 vty_outln (vty
, "%% Command incomplete.");
510 cmd_free_strvec (vline
);
515 static const char telnet_backward_char
= 0x08;
516 static const char telnet_space_char
= ' ';
518 /* Basic function to write buffer to vty. */
520 vty_write (struct vty
*vty
, const char *buf
, size_t nbytes
)
522 if ((vty
->node
== AUTH_NODE
) || (vty
->node
== AUTH_ENABLE_NODE
))
525 /* Should we do buffering here ? And make vty_flush (vty) ? */
526 buffer_put (vty
->obuf
, buf
, nbytes
);
529 /* Basic function to insert character into vty. */
531 vty_self_insert (struct vty
*vty
, char c
)
536 if (vty
->length
+ 1 >= VTY_BUFSIZ
)
539 length
= vty
->length
- vty
->cp
;
540 memmove (&vty
->buf
[vty
->cp
+ 1], &vty
->buf
[vty
->cp
], length
);
541 vty
->buf
[vty
->cp
] = c
;
543 vty_write (vty
, &vty
->buf
[vty
->cp
], length
+ 1);
544 for (i
= 0; i
< length
; i
++)
545 vty_write (vty
, &telnet_backward_char
, 1);
550 vty
->buf
[vty
->length
] = '\0';
553 /* Self insert character 'c' in overwrite mode. */
555 vty_self_insert_overwrite (struct vty
*vty
, char c
)
557 if (vty
->cp
== vty
->length
)
559 vty_self_insert (vty
, c
);
563 vty
->buf
[vty
->cp
++] = c
;
564 vty_write (vty
, &c
, 1);
568 * Insert a string into vty->buf at the current cursor position.
570 * If the resultant string would be larger than VTY_BUFSIZ it is
574 vty_insert_word_overwrite (struct vty
*vty
, char *str
)
576 if (vty
->cp
== VTY_BUFSIZ
)
579 size_t nwrite
= MIN ((int) strlen (str
), VTY_BUFSIZ
- vty
->cp
- 1);
580 memcpy (&vty
->buf
[vty
->cp
], str
, nwrite
);
582 vty
->length
= MAX (vty
->cp
, vty
->length
);
583 vty
->buf
[vty
->length
] = '\0';
584 vty_write (vty
, str
, nwrite
);
587 /* Forward character. */
589 vty_forward_char (struct vty
*vty
)
591 if (vty
->cp
< vty
->length
)
593 vty_write (vty
, &vty
->buf
[vty
->cp
], 1);
598 /* Backward character. */
600 vty_backward_char (struct vty
*vty
)
605 vty_write (vty
, &telnet_backward_char
, 1);
609 /* Move to the beginning of the line. */
611 vty_beginning_of_line (struct vty
*vty
)
614 vty_backward_char (vty
);
617 /* Move to the end of the line. */
619 vty_end_of_line (struct vty
*vty
)
621 while (vty
->cp
< vty
->length
)
622 vty_forward_char (vty
);
625 static void vty_kill_line_from_beginning (struct vty
*);
626 static void vty_redraw_line (struct vty
*);
628 /* Print command line history. This function is called from
629 vty_next_line and vty_previous_line. */
631 vty_history_print (struct vty
*vty
)
635 vty_kill_line_from_beginning (vty
);
637 /* Get previous line from history buffer */
638 length
= strlen (vty
->hist
[vty
->hp
]);
639 memcpy (vty
->buf
, vty
->hist
[vty
->hp
], length
);
640 vty
->cp
= vty
->length
= length
;
641 vty
->buf
[vty
->length
] = '\0';
643 /* Redraw current line */
644 vty_redraw_line (vty
);
647 /* Show next command line history. */
649 vty_next_line (struct vty
*vty
)
653 if (vty
->hp
== vty
->hindex
)
656 /* Try is there history exist or not. */
658 if (try_index
== (VTY_MAXHIST
- 1))
663 /* If there is not history return. */
664 if (vty
->hist
[try_index
] == NULL
)
669 vty_history_print (vty
);
672 /* Show previous command line history. */
674 vty_previous_line (struct vty
*vty
)
680 try_index
= VTY_MAXHIST
- 1;
684 if (vty
->hist
[try_index
] == NULL
)
689 vty_history_print (vty
);
692 /* This function redraw all of the command line character. */
694 vty_redraw_line (struct vty
*vty
)
696 vty_write (vty
, vty
->buf
, vty
->length
);
697 vty
->cp
= vty
->length
;
702 vty_forward_word (struct vty
*vty
)
704 while (vty
->cp
!= vty
->length
&& vty
->buf
[vty
->cp
] != ' ')
705 vty_forward_char (vty
);
707 while (vty
->cp
!= vty
->length
&& vty
->buf
[vty
->cp
] == ' ')
708 vty_forward_char (vty
);
711 /* Backward word without skipping training space. */
713 vty_backward_pure_word (struct vty
*vty
)
715 while (vty
->cp
> 0 && vty
->buf
[vty
->cp
- 1] != ' ')
716 vty_backward_char (vty
);
721 vty_backward_word (struct vty
*vty
)
723 while (vty
->cp
> 0 && vty
->buf
[vty
->cp
- 1] == ' ')
724 vty_backward_char (vty
);
726 while (vty
->cp
> 0 && vty
->buf
[vty
->cp
- 1] != ' ')
727 vty_backward_char (vty
);
730 /* When '^D' is typed at the beginning of the line we move to the down
733 vty_down_level (struct vty
*vty
)
735 vty_out (vty
, VTYNL
);
741 /* When '^Z' is received from vty, move down to the enable mode. */
743 vty_end_config (struct vty
*vty
)
745 vty_out (vty
, VTYNL
);
762 case BGP_VRF_POLICY_NODE
:
763 case BGP_VNC_DEFAULTS_NODE
:
764 case BGP_VNC_NVE_GROUP_NODE
:
765 case BGP_VNC_L2_GROUP_NODE
:
779 case LDP_IPV4_IFACE_NODE
:
780 case LDP_IPV6_IFACE_NODE
:
782 case LDP_PSEUDOWIRE_NODE
:
785 case KEYCHAIN_KEY_NODE
:
789 vty_config_unlock (vty
);
790 vty
->node
= ENABLE_NODE
;
793 /* Unknown node, we have to ignore it. */
801 /* Delete a charcter at the current point. */
803 vty_delete_char (struct vty
*vty
)
808 if (vty
->length
== 0)
810 vty_down_level (vty
);
814 if (vty
->cp
== vty
->length
)
815 return; /* completion need here? */
817 size
= vty
->length
- vty
->cp
;
820 memmove (&vty
->buf
[vty
->cp
], &vty
->buf
[vty
->cp
+ 1], size
- 1);
821 vty
->buf
[vty
->length
] = '\0';
823 if (vty
->node
== AUTH_NODE
|| vty
->node
== AUTH_ENABLE_NODE
)
826 vty_write (vty
, &vty
->buf
[vty
->cp
], size
- 1);
827 vty_write (vty
, &telnet_space_char
, 1);
829 for (i
= 0; i
< size
; i
++)
830 vty_write (vty
, &telnet_backward_char
, 1);
833 /* Delete a character before the point. */
835 vty_delete_backward_char (struct vty
*vty
)
840 vty_backward_char (vty
);
841 vty_delete_char (vty
);
844 /* Kill rest of line from current point. */
846 vty_kill_line (struct vty
*vty
)
851 size
= vty
->length
- vty
->cp
;
856 for (i
= 0; i
< size
; i
++)
857 vty_write (vty
, &telnet_space_char
, 1);
858 for (i
= 0; i
< size
; i
++)
859 vty_write (vty
, &telnet_backward_char
, 1);
861 memset (&vty
->buf
[vty
->cp
], 0, size
);
862 vty
->length
= vty
->cp
;
865 /* Kill line from the beginning. */
867 vty_kill_line_from_beginning (struct vty
*vty
)
869 vty_beginning_of_line (vty
);
873 /* Delete a word before the point. */
875 vty_forward_kill_word (struct vty
*vty
)
877 while (vty
->cp
!= vty
->length
&& vty
->buf
[vty
->cp
] == ' ')
878 vty_delete_char (vty
);
879 while (vty
->cp
!= vty
->length
&& vty
->buf
[vty
->cp
] != ' ')
880 vty_delete_char (vty
);
883 /* Delete a word before the point. */
885 vty_backward_kill_word (struct vty
*vty
)
887 while (vty
->cp
> 0 && vty
->buf
[vty
->cp
- 1] == ' ')
888 vty_delete_backward_char (vty
);
889 while (vty
->cp
> 0 && vty
->buf
[vty
->cp
- 1] != ' ')
890 vty_delete_backward_char (vty
);
893 /* Transpose chars before or at the point. */
895 vty_transpose_chars (struct vty
*vty
)
899 /* If length is short or point is near by the beginning of line then
901 if (vty
->length
< 2 || vty
->cp
< 1)
904 /* In case of point is located at the end of the line. */
905 if (vty
->cp
== vty
->length
)
907 c1
= vty
->buf
[vty
->cp
- 1];
908 c2
= vty
->buf
[vty
->cp
- 2];
910 vty_backward_char (vty
);
911 vty_backward_char (vty
);
912 vty_self_insert_overwrite (vty
, c1
);
913 vty_self_insert_overwrite (vty
, c2
);
917 c1
= vty
->buf
[vty
->cp
];
918 c2
= vty
->buf
[vty
->cp
- 1];
920 vty_backward_char (vty
);
921 vty_self_insert_overwrite (vty
, c1
);
922 vty_self_insert_overwrite (vty
, c2
);
926 /* Do completion at vty interface. */
928 vty_complete_command (struct vty
*vty
)
932 char **matched
= NULL
;
935 if (vty
->node
== AUTH_NODE
|| vty
->node
== AUTH_ENABLE_NODE
)
938 vline
= cmd_make_strvec (vty
->buf
);
942 /* In case of 'help \t'. */
943 if (isspace ((int) vty
->buf
[vty
->length
- 1]))
944 vector_set (vline
, NULL
);
946 matched
= cmd_complete_command (vline
, vty
, &ret
);
948 cmd_free_strvec (vline
);
950 vty_out (vty
, VTYNL
);
953 case CMD_ERR_AMBIGUOUS
:
954 vty_outln (vty
, "%% Ambiguous command.");
956 vty_redraw_line (vty
);
958 case CMD_ERR_NO_MATCH
:
959 /* vty_out (vty, "%% There is no matched command.%s", VTYNL); */
961 vty_redraw_line (vty
);
963 case CMD_COMPLETE_FULL_MATCH
:
966 /* 2016-11-28 equinox -- need to debug, SEGV here */
967 vty_outln (vty
, "%% CLI BUG: FULL_MATCH with NULL str");
969 vty_redraw_line (vty
);
973 vty_redraw_line (vty
);
974 vty_backward_pure_word (vty
);
975 vty_insert_word_overwrite (vty
, matched
[0]);
976 vty_self_insert (vty
, ' ');
977 XFREE (MTYPE_COMPLETION
, matched
[0]);
979 case CMD_COMPLETE_MATCH
:
981 vty_redraw_line (vty
);
982 vty_backward_pure_word (vty
);
983 vty_insert_word_overwrite (vty
, matched
[0]);
984 XFREE (MTYPE_COMPLETION
, matched
[0]);
986 case CMD_COMPLETE_LIST_MATCH
:
987 for (i
= 0; matched
[i
] != NULL
; i
++)
989 if (i
!= 0 && ((i
% 6) == 0))
990 vty_out (vty
, VTYNL
);
991 vty_out (vty
, "%-10s ", matched
[i
]);
992 XFREE (MTYPE_COMPLETION
, matched
[i
]);
994 vty_out (vty
, VTYNL
);
997 vty_redraw_line (vty
);
999 case CMD_ERR_NOTHING_TODO
:
1001 vty_redraw_line (vty
);
1007 XFREE (MTYPE_TMP
, matched
);
1011 vty_describe_fold (struct vty
*vty
, int cmd_width
,
1012 unsigned int desc_width
, struct cmd_token
*token
)
1015 const char *cmd
, *p
;
1020 if (desc_width
<= 0)
1022 vty_outln (vty
, " %-*s %s", cmd_width
, cmd
, token
->desc
);
1026 buf
= XCALLOC (MTYPE_TMP
, strlen (token
->desc
) + 1);
1028 for (p
= token
->desc
; strlen (p
) > desc_width
; p
+= pos
+ 1)
1030 for (pos
= desc_width
; pos
> 0; pos
--)
1031 if (*(p
+ pos
) == ' ')
1037 strncpy (buf
, p
, pos
);
1039 vty_outln (vty
, " %-*s %s", cmd_width
, cmd
, buf
);
1044 vty_outln (vty
, " %-*s %s", cmd_width
, cmd
, p
);
1046 XFREE (MTYPE_TMP
, buf
);
1049 /* Describe matched command function. */
1051 vty_describe_command (struct vty
*vty
)
1056 unsigned int i
, width
, desc_width
;
1057 struct cmd_token
*token
, *token_cr
= NULL
;
1059 vline
= cmd_make_strvec (vty
->buf
);
1061 /* In case of '> ?'. */
1064 vline
= vector_init (1);
1065 vector_set (vline
, NULL
);
1068 if (isspace ((int) vty
->buf
[vty
->length
- 1]))
1069 vector_set (vline
, NULL
);
1071 describe
= cmd_describe_command (vline
, vty
, &ret
);
1073 vty_out (vty
, VTYNL
);
1075 /* Ambiguous error. */
1078 case CMD_ERR_AMBIGUOUS
:
1079 vty_outln (vty
, "%% Ambiguous command.");
1082 case CMD_ERR_NO_MATCH
:
1083 vty_outln (vty
, "%% There is no matched command.");
1088 /* Get width of command string. */
1090 for (i
= 0; i
< vector_active (describe
); i
++)
1091 if ((token
= vector_slot (describe
, i
)) != NULL
)
1095 if (token
->text
[0] == '\0')
1098 len
= strlen (token
->text
);
1104 /* Get width of description string. */
1105 desc_width
= vty
->width
- (width
+ 6);
1107 /* Print out description. */
1108 for (i
= 0; i
< vector_active (describe
); i
++)
1109 if ((token
= vector_slot (describe
, i
)) != NULL
)
1111 if (token
->text
[0] == '\0')
1114 if (strcmp (token
->text
, CMD_CR_TEXT
) == 0)
1121 vty_outln (vty
, " %-s",
1123 else if (desc_width
>= strlen (token
->desc
))
1124 vty_outln (vty
, " %-*s %s", width
,
1128 vty_describe_fold (vty
, width
, desc_width
, token
);
1130 if (IS_VARYING_TOKEN(token
->type
))
1132 const char *ref
= vector_slot(vline
, vector_active(vline
) - 1);
1134 vector varcomps
= vector_init (VECTOR_MIN_SIZE
);
1135 cmd_variable_complete (token
, ref
, varcomps
);
1137 if (vector_active(varcomps
) > 0)
1140 for (size_t j
= 0; j
< vector_active (varcomps
); j
++)
1142 char *item
= vector_slot (varcomps
, j
);
1143 vty_out(vty
, " %s", item
);
1144 XFREE(MTYPE_COMPLETION
, item
);
1146 vty_out (vty
, VTYNL
);
1148 vector_free(varcomps
);
1151 vty_out (vty
, " %-*s %s%s", width
1152 desc
->cmd
[0] == '.' ? desc
->cmd
+ 1 : desc
->cmd
,
1153 desc
->str
? desc
->str
: "", VTYNL
);
1157 if ((token
= token_cr
))
1160 vty_outln (vty
, " %-s",
1162 else if (desc_width
>= strlen (token
->desc
))
1163 vty_outln (vty
, " %-*s %s", width
,
1167 vty_describe_fold (vty
, width
, desc_width
, token
);
1171 cmd_free_strvec (vline
);
1173 vector_free (describe
);
1176 vty_redraw_line (vty
);
1180 vty_clear_buf (struct vty
*vty
)
1182 memset (vty
->buf
, 0, vty
->max
);
1185 /* ^C stop current input and do not add command line to the history. */
1187 vty_stop_input (struct vty
*vty
)
1189 vty
->cp
= vty
->length
= 0;
1190 vty_clear_buf (vty
);
1191 vty_out (vty
, VTYNL
);
1197 /* Nothing to do. */
1200 case INTERFACE_NODE
:
1212 case LDP_IPV4_IFACE_NODE
:
1213 case LDP_IPV6_IFACE_NODE
:
1214 case LDP_L2VPN_NODE
:
1215 case LDP_PSEUDOWIRE_NODE
:
1218 case KEYCHAIN_KEY_NODE
:
1222 vty_config_unlock (vty
);
1223 vty
->node
= ENABLE_NODE
;
1226 /* Unknown node, we have to ignore it. */
1231 /* Set history pointer to the latest one. */
1232 vty
->hp
= vty
->hindex
;
1235 /* Add current command line to the history buffer. */
1237 vty_hist_add (struct vty
*vty
)
1241 if (vty
->length
== 0)
1244 index
= vty
->hindex
? vty
->hindex
- 1 : VTY_MAXHIST
- 1;
1246 /* Ignore the same string as previous one. */
1247 if (vty
->hist
[index
])
1248 if (strcmp (vty
->buf
, vty
->hist
[index
]) == 0)
1250 vty
->hp
= vty
->hindex
;
1254 /* Insert history entry. */
1255 if (vty
->hist
[vty
->hindex
])
1256 XFREE (MTYPE_VTY_HIST
, vty
->hist
[vty
->hindex
]);
1257 vty
->hist
[vty
->hindex
] = XSTRDUP (MTYPE_VTY_HIST
, vty
->buf
);
1259 /* History index rotation. */
1261 if (vty
->hindex
== VTY_MAXHIST
)
1264 vty
->hp
= vty
->hindex
;
1267 /* #define TELNET_OPTION_DEBUG */
1269 /* Get telnet window size. */
1271 vty_telnet_option (struct vty
*vty
, unsigned char *buf
, int nbytes
)
1273 #ifdef TELNET_OPTION_DEBUG
1276 for (i
= 0; i
< nbytes
; i
++)
1281 vty_out (vty
, "IAC ");
1284 vty_out (vty
, "WILL ");
1287 vty_out (vty
, "WONT ");
1290 vty_out (vty
, "DO ");
1293 vty_out (vty
, "DONT ");
1296 vty_out (vty
, "SB ");
1299 vty_out (vty
, "SE ");
1302 vty_outln (vty
, "TELOPT_ECHO ");
1305 vty_outln (vty
, "TELOPT_SGA ");
1308 vty_outln (vty
, "TELOPT_NAWS ");
1311 vty_out (vty
, "%x ", buf
[i
]);
1315 vty_out (vty
, VTYNL
);
1317 #endif /* TELNET_OPTION_DEBUG */
1323 vty
->iac_sb_in_progress
= 1;
1328 if (!vty
->iac_sb_in_progress
)
1331 if ((vty
->sb_len
== 0) || (vty
->sb_buf
[0] == '\0'))
1333 vty
->iac_sb_in_progress
= 0;
1336 switch (vty
->sb_buf
[0])
1339 if (vty
->sb_len
!= TELNET_NAWS_SB_LEN
)
1340 zlog_warn("RFC 1073 violation detected: telnet NAWS option "
1341 "should send %d characters, but we received %lu",
1342 TELNET_NAWS_SB_LEN
, (u_long
)vty
->sb_len
);
1343 else if (sizeof(vty
->sb_buf
) < TELNET_NAWS_SB_LEN
)
1344 zlog_err("Bug detected: sizeof(vty->sb_buf) %lu < %d, "
1345 "too small to handle the telnet NAWS option",
1346 (u_long
)sizeof(vty
->sb_buf
), TELNET_NAWS_SB_LEN
);
1349 vty
->width
= ((vty
->sb_buf
[1] << 8)|vty
->sb_buf
[2]);
1350 vty
->height
= ((vty
->sb_buf
[3] << 8)|vty
->sb_buf
[4]);
1351 #ifdef TELNET_OPTION_DEBUG
1352 vty_outln (vty
, "TELNET NAWS window size negotiation completed: "
1353 "width %d, height %d",
1354 vty
->width
, vty
->height
);
1359 vty
->iac_sb_in_progress
= 0;
1369 /* Execute current command line. */
1371 vty_execute (struct vty
*vty
)
1380 case AUTH_ENABLE_NODE
:
1381 vty_auth (vty
, vty
->buf
);
1384 ret
= vty_command (vty
, vty
->buf
);
1385 if (vty
->type
== VTY_TERM
)
1390 /* Clear command line buffer. */
1391 vty
->cp
= vty
->length
= 0;
1392 vty_clear_buf (vty
);
1394 if (vty
->status
!= VTY_CLOSE
)
1400 #define CONTROL(X) ((X) - '@')
1401 #define VTY_NORMAL 0
1402 #define VTY_PRE_ESCAPE 1
1403 #define VTY_ESCAPE 2
1405 /* Escape character command map. */
1407 vty_escape_map (unsigned char c
, struct vty
*vty
)
1412 vty_previous_line (vty
);
1415 vty_next_line (vty
);
1418 vty_forward_char (vty
);
1421 vty_backward_char (vty
);
1427 /* Go back to normal mode. */
1428 vty
->escape
= VTY_NORMAL
;
1431 /* Quit print out to the buffer. */
1433 vty_buffer_reset (struct vty
*vty
)
1435 buffer_reset (vty
->obuf
);
1437 vty_redraw_line (vty
);
1440 /* Read data via vty socket. */
1442 vty_read (struct thread
*thread
)
1446 unsigned char buf
[VTY_READ_BUFSIZ
];
1448 int vty_sock
= THREAD_FD (thread
);
1449 struct vty
*vty
= THREAD_ARG (thread
);
1452 /* Read raw data from socket */
1453 if ((nbytes
= read (vty
->fd
, buf
, VTY_READ_BUFSIZ
)) <= 0)
1457 if (ERRNO_IO_RETRY(errno
))
1459 vty_event (VTY_READ
, vty_sock
, vty
);
1462 vty
->monitor
= 0; /* disable monitoring to avoid infinite recursion */
1463 zlog_warn("%s: read error on vty client fd %d, closing: %s",
1464 __func__
, vty
->fd
, safe_strerror(errno
));
1465 buffer_reset(vty
->obuf
);
1467 vty
->status
= VTY_CLOSE
;
1470 for (i
= 0; i
< nbytes
; i
++)
1485 if (vty
->iac_sb_in_progress
&& !vty
->iac
)
1487 if (vty
->sb_len
< sizeof(vty
->sb_buf
))
1488 vty
->sb_buf
[vty
->sb_len
] = buf
[i
];
1495 /* In case of telnet command */
1497 ret
= vty_telnet_option (vty
, buf
+ i
, nbytes
- i
);
1504 if (vty
->status
== VTY_MORE
)
1511 vty_buffer_reset (vty
);
1513 #if 0 /* More line does not work for "show ip bgp". */
1516 vty
->status
= VTY_MORELINE
;
1525 /* Escape character. */
1526 if (vty
->escape
== VTY_ESCAPE
)
1528 vty_escape_map (buf
[i
], vty
);
1532 /* Pre-escape status. */
1533 if (vty
->escape
== VTY_PRE_ESCAPE
)
1538 vty
->escape
= VTY_ESCAPE
;
1541 vty_backward_word (vty
);
1542 vty
->escape
= VTY_NORMAL
;
1545 vty_forward_word (vty
);
1546 vty
->escape
= VTY_NORMAL
;
1549 vty_forward_kill_word (vty
);
1550 vty
->escape
= VTY_NORMAL
;
1554 vty_backward_kill_word (vty
);
1555 vty
->escape
= VTY_NORMAL
;
1558 vty
->escape
= VTY_NORMAL
;
1567 vty_beginning_of_line (vty
);
1570 vty_backward_char (vty
);
1573 vty_stop_input (vty
);
1576 vty_delete_char (vty
);
1579 vty_end_of_line (vty
);
1582 vty_forward_char (vty
);
1586 vty_delete_backward_char (vty
);
1589 vty_kill_line (vty
);
1592 vty_next_line (vty
);
1595 vty_previous_line (vty
);
1598 vty_transpose_chars (vty
);
1601 vty_kill_line_from_beginning (vty
);
1604 vty_backward_kill_word (vty
);
1607 vty_end_config (vty
);
1611 vty_out (vty
, VTYNL
);
1615 vty_complete_command (vty
);
1618 if (vty
->node
== AUTH_NODE
|| vty
->node
== AUTH_ENABLE_NODE
)
1619 vty_self_insert (vty
, buf
[i
]);
1621 vty_describe_command (vty
);
1624 if (i
+ 1 < nbytes
&& buf
[i
+ 1] == '[')
1626 vty
->escape
= VTY_ESCAPE
;
1630 vty
->escape
= VTY_PRE_ESCAPE
;
1633 if (buf
[i
] > 31 && buf
[i
] < 127)
1634 vty_self_insert (vty
, buf
[i
]);
1640 if (vty
->status
== VTY_CLOSE
)
1644 vty_event (VTY_WRITE
, vty
->wfd
, vty
);
1645 vty_event (VTY_READ
, vty_sock
, vty
);
1650 /* Flush buffer to the vty. */
1652 vty_flush (struct thread
*thread
)
1655 buffer_status_t flushrc
;
1656 int vty_sock
= THREAD_FD (thread
);
1657 struct vty
*vty
= THREAD_ARG (thread
);
1659 vty
->t_write
= NULL
;
1661 /* Tempolary disable read thread. */
1662 if ((vty
->lines
== 0) && vty
->t_read
)
1664 thread_cancel (vty
->t_read
);
1668 /* Function execution continue. */
1669 erase
= ((vty
->status
== VTY_MORE
|| vty
->status
== VTY_MORELINE
));
1671 /* N.B. if width is 0, that means we don't know the window size. */
1672 if ((vty
->lines
== 0) || (vty
->width
== 0) || (vty
->height
== 0))
1673 flushrc
= buffer_flush_available(vty
->obuf
, vty_sock
);
1674 else if (vty
->status
== VTY_MORELINE
)
1675 flushrc
= buffer_flush_window(vty
->obuf
, vty_sock
, vty
->width
,
1678 flushrc
= buffer_flush_window(vty
->obuf
, vty_sock
, vty
->width
,
1679 vty
->lines
>= 0 ? vty
->lines
:
1685 vty
->monitor
= 0; /* disable monitoring to avoid infinite recursion */
1686 zlog_warn("buffer_flush failed on vty client fd %d, closing",
1688 buffer_reset(vty
->obuf
);
1692 if (vty
->status
== VTY_CLOSE
)
1696 vty
->status
= VTY_NORMAL
;
1697 if (vty
->lines
== 0)
1698 vty_event (VTY_READ
, vty_sock
, vty
);
1701 case BUFFER_PENDING
:
1702 /* There is more data waiting to be written. */
1703 vty
->status
= VTY_MORE
;
1704 if (vty
->lines
== 0)
1705 vty_event (VTY_WRITE
, vty_sock
, vty
);
1712 /* allocate and initialise vty */
1714 vty_new_init (int vty_sock
)
1720 vty
->wfd
= vty_sock
;
1721 vty
->type
= VTY_TERM
;
1722 vty
->node
= AUTH_NODE
;
1725 vty_clear_buf (vty
);
1727 memset (vty
->hist
, 0, sizeof (vty
->hist
));
1730 vector_set_index (vtyvec
, vty_sock
, vty
);
1731 vty
->status
= VTY_NORMAL
;
1734 vty
->iac_sb_in_progress
= 0;
1740 /* Create new vty structure. */
1742 vty_create (int vty_sock
, union sockunion
*su
)
1744 char buf
[SU_ADDRSTRLEN
];
1747 sockunion2str(su
, buf
, SU_ADDRSTRLEN
);
1749 /* Allocate new vty structure and set up default values. */
1750 vty
= vty_new_init (vty_sock
);
1752 /* configurable parameters not part of basic init */
1753 vty
->v_timeout
= vty_timeout_val
;
1754 strcpy (vty
->address
, buf
);
1755 if (no_password_check
)
1758 vty
->node
= ENABLE_NODE
;
1760 vty
->node
= VIEW_NODE
;
1762 if (host
.lines
>= 0)
1763 vty
->lines
= host
.lines
;
1765 if (! no_password_check
)
1767 /* Vty is not available if password isn't set. */
1768 if (host
.password
== NULL
&& host
.password_encrypt
== NULL
)
1770 vty_outln (vty
, "Vty password is not set.");
1771 vty
->status
= VTY_CLOSE
;
1777 /* Say hello to the world. */
1779 if (! no_password_check
)
1780 vty_outln (vty
, "%sUser Access Verification%s", VTYNL
,
1783 /* Setting up terminal. */
1784 vty_will_echo (vty
);
1785 vty_will_suppress_go_ahead (vty
);
1787 vty_dont_linemode (vty
);
1788 vty_do_window_size (vty
);
1789 /* vty_dont_lflow_ahead (vty); */
1793 /* Add read/write thread. */
1794 vty_event (VTY_WRITE
, vty_sock
, vty
);
1795 vty_event (VTY_READ
, vty_sock
, vty
);
1800 /* create vty for stdio */
1801 static struct termios stdio_orig_termios
;
1802 static struct vty
*stdio_vty
= NULL
;
1803 static void (*stdio_vty_atclose
)(void);
1806 vty_stdio_reset (void)
1810 tcsetattr (0, TCSANOW
, &stdio_orig_termios
);
1813 if (stdio_vty_atclose
)
1814 stdio_vty_atclose ();
1815 stdio_vty_atclose
= NULL
;
1820 vty_stdio (void (*atclose
)())
1823 struct termios termios
;
1825 /* refuse creating two vtys on stdio */
1829 vty
= stdio_vty
= vty_new_init (0);
1830 stdio_vty_atclose
= atclose
;
1833 /* always have stdio vty in a known _unchangeable_ state, don't want config
1834 * to have any effect here to make sure scripting this works as intended */
1835 vty
->node
= ENABLE_NODE
;
1837 strcpy (vty
->address
, "console");
1839 if (!tcgetattr (0, &stdio_orig_termios
))
1841 termios
= stdio_orig_termios
;
1842 termios
.c_iflag
&= ~(IGNBRK
| BRKINT
| PARMRK
| ISTRIP
1843 | INLCR
| IGNCR
| ICRNL
| IXON
);
1844 termios
.c_oflag
&= ~OPOST
;
1845 termios
.c_lflag
&= ~(ECHO
| ECHONL
| ICANON
| ISIG
| IEXTEN
);
1846 termios
.c_cflag
&= ~(CSIZE
| PARENB
);
1847 termios
.c_cflag
|= CS8
;
1848 tcsetattr (0, TCSANOW
, &termios
);
1853 /* Add read/write thread. */
1854 vty_event (VTY_WRITE
, 1, vty
);
1855 vty_event (VTY_READ
, 0, vty
);
1860 /* Accept connection from the network. */
1862 vty_accept (struct thread
*thread
)
1870 struct access_list
*acl
= NULL
;
1871 char buf
[SU_ADDRSTRLEN
];
1873 accept_sock
= THREAD_FD (thread
);
1875 /* We continue hearing vty socket. */
1876 vty_event (VTY_SERV
, accept_sock
, NULL
);
1878 memset (&su
, 0, sizeof (union sockunion
));
1880 /* We can handle IPv4 or IPv6 socket. */
1881 vty_sock
= sockunion_accept (accept_sock
, &su
);
1884 zlog_warn ("can't accept vty socket : %s", safe_strerror (errno
));
1887 set_nonblocking(vty_sock
);
1888 set_cloexec(vty_sock
);
1890 sockunion2hostprefix (&su
, &p
);
1892 /* VTY's accesslist apply. */
1893 if (p
.family
== AF_INET
&& vty_accesslist_name
)
1895 if ((acl
= access_list_lookup (AFI_IP
, vty_accesslist_name
)) &&
1896 (access_list_apply (acl
, &p
) == FILTER_DENY
))
1898 zlog_info ("Vty connection refused from %s",
1899 sockunion2str (&su
, buf
, SU_ADDRSTRLEN
));
1902 /* continue accepting connections */
1903 vty_event (VTY_SERV
, accept_sock
, NULL
);
1909 /* VTY's ipv6 accesslist apply. */
1910 if (p
.family
== AF_INET6
&& vty_ipv6_accesslist_name
)
1912 if ((acl
= access_list_lookup (AFI_IP6
, vty_ipv6_accesslist_name
)) &&
1913 (access_list_apply (acl
, &p
) == FILTER_DENY
))
1915 zlog_info ("Vty connection refused from %s",
1916 sockunion2str (&su
, buf
, SU_ADDRSTRLEN
));
1919 /* continue accepting connections */
1920 vty_event (VTY_SERV
, accept_sock
, NULL
);
1927 ret
= setsockopt (vty_sock
, IPPROTO_TCP
, TCP_NODELAY
,
1928 (char *) &on
, sizeof (on
));
1930 zlog_info ("can't set sockopt to vty_sock : %s",
1931 safe_strerror (errno
));
1933 zlog_info ("Vty connection from %s",
1934 sockunion2str (&su
, buf
, SU_ADDRSTRLEN
));
1936 vty_create (vty_sock
, &su
);
1942 vty_serv_sock_addrinfo (const char *hostname
, unsigned short port
)
1945 struct addrinfo req
;
1946 struct addrinfo
*ainfo
;
1947 struct addrinfo
*ainfo_save
;
1949 char port_str
[BUFSIZ
];
1951 memset (&req
, 0, sizeof (struct addrinfo
));
1952 req
.ai_flags
= AI_PASSIVE
;
1953 req
.ai_family
= AF_UNSPEC
;
1954 req
.ai_socktype
= SOCK_STREAM
;
1955 sprintf (port_str
, "%d", port
);
1956 port_str
[sizeof (port_str
) - 1] = '\0';
1958 ret
= getaddrinfo (hostname
, port_str
, &req
, &ainfo
);
1962 fprintf (stderr
, "getaddrinfo failed: %s\n", gai_strerror (ret
));
1970 if (ainfo
->ai_family
!= AF_INET
1971 && ainfo
->ai_family
!= AF_INET6
1975 sock
= socket (ainfo
->ai_family
, ainfo
->ai_socktype
, ainfo
->ai_protocol
);
1979 sockopt_v6only (ainfo
->ai_family
, sock
);
1980 sockopt_reuseaddr (sock
);
1981 sockopt_reuseport (sock
);
1984 ret
= bind (sock
, ainfo
->ai_addr
, ainfo
->ai_addrlen
);
1987 close (sock
); /* Avoid sd leak. */
1991 ret
= listen (sock
, 3);
1994 close (sock
); /* Avoid sd leak. */
1998 vty_event (VTY_SERV
, sock
, NULL
);
2000 while ((ainfo
= ainfo
->ai_next
) != NULL
);
2002 freeaddrinfo (ainfo_save
);
2006 /* For sockaddr_un. */
2009 /* VTY shell UNIX domain socket. */
2011 vty_serv_un (const char *path
)
2015 struct sockaddr_un serv
;
2017 struct zprivs_ids_t ids
;
2019 /* First of all, unlink existing socket */
2023 old_mask
= umask (0007);
2025 /* Make UNIX domain socket. */
2026 sock
= socket (AF_UNIX
, SOCK_STREAM
, 0);
2029 zlog_err("Cannot create unix stream socket: %s", safe_strerror(errno
));
2033 /* Make server socket. */
2034 memset (&serv
, 0, sizeof (struct sockaddr_un
));
2035 serv
.sun_family
= AF_UNIX
;
2036 strlcpy (serv
.sun_path
, path
, sizeof (serv
.sun_path
));
2037 #ifdef HAVE_STRUCT_SOCKADDR_UN_SUN_LEN
2038 len
= serv
.sun_len
= SUN_LEN(&serv
);
2040 len
= sizeof (serv
.sun_family
) + strlen (serv
.sun_path
);
2041 #endif /* HAVE_STRUCT_SOCKADDR_UN_SUN_LEN */
2045 ret
= bind (sock
, (struct sockaddr
*) &serv
, len
);
2048 zlog_err("Cannot bind path %s: %s", path
, safe_strerror(errno
));
2049 close (sock
); /* Avoid sd leak. */
2053 ret
= listen (sock
, 5);
2056 zlog_err("listen(fd %d) failed: %s", sock
, safe_strerror(errno
));
2057 close (sock
); /* Avoid sd leak. */
2063 zprivs_get_ids(&ids
);
2065 /* Hack: ids.gid_vty is actually a uint, but we stored -1 in it
2066 earlier for the case when we don't need to chown the file
2067 type casting it here to make a compare */
2068 if ((int)ids
.gid_vty
> 0)
2070 /* set group of socket */
2071 if ( chown (path
, -1, ids
.gid_vty
) )
2073 zlog_err ("vty_serv_un: could chown socket, %s",
2074 safe_strerror (errno
) );
2078 vty_event (VTYSH_SERV
, sock
, NULL
);
2081 /* #define VTYSH_DEBUG 1 */
2084 vtysh_accept (struct thread
*thread
)
2089 struct sockaddr_un client
;
2092 accept_sock
= THREAD_FD (thread
);
2094 vty_event (VTYSH_SERV
, accept_sock
, NULL
);
2096 memset (&client
, 0, sizeof (struct sockaddr_un
));
2097 client_len
= sizeof (struct sockaddr_un
);
2099 sock
= accept (accept_sock
, (struct sockaddr
*) &client
,
2100 (socklen_t
*) &client_len
);
2104 zlog_warn ("can't accept vty socket : %s", safe_strerror (errno
));
2108 if (set_nonblocking(sock
) < 0)
2110 zlog_warn ("vtysh_accept: could not set vty socket %d to non-blocking,"
2111 " %s, closing", sock
, safe_strerror (errno
));
2118 printf ("VTY shell accept\n");
2119 #endif /* VTYSH_DEBUG */
2124 vty
->type
= VTY_SHELL_SERV
;
2125 vty
->node
= VIEW_NODE
;
2127 vty_event (VTYSH_READ
, sock
, vty
);
2133 vtysh_flush(struct vty
*vty
)
2135 switch (buffer_flush_available(vty
->obuf
, vty
->wfd
))
2137 case BUFFER_PENDING
:
2138 vty_event(VTYSH_WRITE
, vty
->wfd
, vty
);
2141 vty
->monitor
= 0; /* disable monitoring to avoid infinite recursion */
2142 zlog_warn("%s: write error to fd %d, closing", __func__
, vty
->fd
);
2143 buffer_reset(vty
->obuf
);
2154 vtysh_read (struct thread
*thread
)
2160 unsigned char buf
[VTY_READ_BUFSIZ
];
2162 u_char header
[4] = {0, 0, 0, 0};
2164 sock
= THREAD_FD (thread
);
2165 vty
= THREAD_ARG (thread
);
2168 if ((nbytes
= read (sock
, buf
, VTY_READ_BUFSIZ
)) <= 0)
2172 if (ERRNO_IO_RETRY(errno
))
2174 vty_event (VTYSH_READ
, sock
, vty
);
2177 vty
->monitor
= 0; /* disable monitoring to avoid infinite recursion */
2178 zlog_warn("%s: read failed on vtysh client fd %d, closing: %s",
2179 __func__
, sock
, safe_strerror(errno
));
2181 buffer_reset(vty
->obuf
);
2184 printf ("close vtysh\n");
2185 #endif /* VTYSH_DEBUG */
2190 printf ("line: %.*s\n", nbytes
, buf
);
2191 #endif /* VTYSH_DEBUG */
2193 if (vty
->length
+ nbytes
>= VTY_BUFSIZ
)
2195 /* Clear command line buffer. */
2196 vty
->cp
= vty
->length
= 0;
2197 vty_clear_buf (vty
);
2198 vty_outln (vty
, "%% Command is too long.");
2202 for (p
= buf
; p
< buf
+nbytes
; p
++)
2204 vty
->buf
[vty
->length
++] = *p
;
2207 /* Pass this line to parser. */
2208 ret
= vty_execute (vty
);
2209 /* Note that vty_execute clears the command buffer and resets
2210 vty->length to 0. */
2212 /* Return result. */
2214 printf ("result: %d\n", ret
);
2215 printf ("vtysh node: %d\n", vty
->node
);
2216 #endif /* VTYSH_DEBUG */
2218 /* hack for asynchronous "write integrated"
2219 * - other commands in "buf" will be ditched
2220 * - input during pending config-write is "unsupported" */
2221 if (ret
== CMD_SUSPEND
)
2224 /* warning: watchfrr hardcodes this result write */
2226 buffer_put(vty
->obuf
, header
, 4);
2228 if (!vty
->t_write
&& (vtysh_flush(vty
) < 0))
2229 /* Try to flush results; exit if a write error occurs. */
2235 if (vty
->status
== VTY_CLOSE
)
2238 vty_event (VTYSH_READ
, sock
, vty
);
2244 vtysh_write (struct thread
*thread
)
2246 struct vty
*vty
= THREAD_ARG (thread
);
2248 vty
->t_write
= NULL
;
2255 /* Determine address family to bind. */
2257 vty_serv_sock (const char *addr
, unsigned short port
, const char *path
)
2259 /* If port is set to 0, do not listen on TCP/IP at all! */
2261 vty_serv_sock_addrinfo (addr
, port
);
2268 /* Close vty interface. Warning: call this only from functions that
2269 will be careful not to access the vty afterwards (since it has
2270 now been freed). This is safest from top-level functions (called
2271 directly by the thread dispatcher). */
2273 vty_close (struct vty
*vty
)
2276 bool was_stdio
= false;
2278 /* Cancel threads.*/
2280 thread_cancel (vty
->t_read
);
2282 thread_cancel (vty
->t_write
);
2284 thread_cancel (vty
->t_timeout
);
2287 buffer_flush_all (vty
->obuf
, vty
->wfd
);
2289 /* Free input buffer. */
2290 buffer_free (vty
->obuf
);
2292 /* Free command history. */
2293 for (i
= 0; i
< VTY_MAXHIST
; i
++)
2295 XFREE (MTYPE_VTY_HIST
, vty
->hist
[i
]);
2298 vector_unset (vtyvec
, vty
->fd
);
2300 if (vty
->wfd
> 0 && vty
->type
== VTY_FILE
)
2307 if (vty
->wfd
> 0 && vty
->wfd
!= vty
->fd
)
2314 XFREE (MTYPE_VTY
, vty
->buf
);
2317 XFREE (MTYPE_VTY
, vty
->error_buf
);
2319 /* Check configure. */
2320 vty_config_unlock (vty
);
2323 XFREE (MTYPE_VTY
, vty
);
2329 /* When time out occur output message then close connection. */
2331 vty_timeout (struct thread
*thread
)
2335 vty
= THREAD_ARG (thread
);
2336 vty
->t_timeout
= NULL
;
2340 buffer_reset (vty
->obuf
);
2341 vty_outln (vty
, "%sVty connection is timed out.", VTYNL
);
2343 /* Close connection. */
2344 vty
->status
= VTY_CLOSE
;
2350 /* Read up configuration file from file_name. */
2352 vty_read_file (FILE *confp
)
2356 unsigned int line_num
= 0;
2359 vty
->wfd
= dup(STDERR_FILENO
); /* vty_close() will close this */
2362 /* Fine, we couldn't make a new fd. vty_close doesn't close stdout. */
2363 vty
->wfd
= STDOUT_FILENO
;
2365 vty
->fd
= STDIN_FILENO
;
2366 vty
->type
= VTY_FILE
;
2367 vty
->node
= CONFIG_NODE
;
2369 /* Execute configuration file */
2370 ret
= config_from_file (vty
, confp
, &line_num
);
2372 /* Flush any previous errors before printing messages below */
2373 buffer_flush_all (vty
->obuf
, vty
->fd
);
2375 if ( !((ret
== CMD_SUCCESS
) || (ret
== CMD_ERR_NOTHING_TODO
)) )
2377 const char *message
= NULL
;
2380 case CMD_ERR_AMBIGUOUS
:
2381 message
= "*** Error reading config: Ambiguous command.";
2383 case CMD_ERR_NO_MATCH
:
2384 message
= "*** Error reading config: There is no such command.";
2387 fprintf (stderr
, "%s\n", message
);
2388 zlog_err ("%s", message
);
2389 fprintf (stderr
, "*** Error occurred processing line %u, below:\n%s\n",
2390 line_num
, vty
->error_buf
);
2391 zlog_err ("*** Error occurred processing line %u, below:\n%s",
2392 line_num
, vty
->error_buf
);
2399 vty_use_backup_config (const char *fullpath
)
2401 char *fullpath_sav
, *fullpath_tmp
;
2407 fullpath_sav
= malloc (strlen (fullpath
) + strlen (CONF_BACKUP_EXT
) + 1);
2408 strcpy (fullpath_sav
, fullpath
);
2409 strcat (fullpath_sav
, CONF_BACKUP_EXT
);
2411 sav
= open (fullpath_sav
, O_RDONLY
);
2414 free (fullpath_sav
);
2418 fullpath_tmp
= malloc (strlen (fullpath
) + 8);
2419 sprintf (fullpath_tmp
, "%s.XXXXXX", fullpath
);
2421 /* Open file to configuration write. */
2422 tmp
= mkstemp (fullpath_tmp
);
2426 if (fchmod (tmp
, CONFIGFILE_MASK
) != 0)
2429 while((c
= read (sav
, buffer
, 512)) > 0)
2431 if (write (tmp
, buffer
, c
) <= 0)
2437 if (rename (fullpath_tmp
, fullpath
) == 0)
2438 ret
= fopen (fullpath
, "r");
2440 unlink (fullpath_tmp
);
2446 unlink (fullpath_tmp
);
2451 free (fullpath_sav
);
2452 free (fullpath_tmp
);
2456 /* Read up configuration file from file_name. */
2458 vty_read_config (const char *config_file
,
2459 char *config_default_dir
)
2461 char cwd
[MAXPATHLEN
];
2463 const char *fullpath
;
2466 /* If -f flag specified. */
2467 if (config_file
!= NULL
)
2469 if (! IS_DIRECTORY_SEP (config_file
[0]))
2471 if (getcwd (cwd
, MAXPATHLEN
) == NULL
)
2473 fprintf (stderr
, "Failure to determine Current Working Directory %d!\n", errno
);
2476 tmp
= XMALLOC (MTYPE_TMP
,
2477 strlen (cwd
) + strlen (config_file
) + 2);
2478 sprintf (tmp
, "%s/%s", cwd
, config_file
);
2482 fullpath
= config_file
;
2484 confp
= fopen (fullpath
, "r");
2488 fprintf (stderr
, "%s: failed to open configuration file %s: %s\n",
2489 __func__
, fullpath
, safe_strerror (errno
));
2491 confp
= vty_use_backup_config (fullpath
);
2493 fprintf (stderr
, "WARNING: using backup configuration file!\n");
2496 fprintf (stderr
, "can't open configuration file [%s]\n",
2505 host_config_set (config_default_dir
);
2509 struct stat conf_stat
;
2511 /* !!!!PLEASE LEAVE!!!!
2512 * This is NEEDED for use with vtysh -b, or else you can get
2513 * a real configuration food fight with a lot garbage in the
2514 * merged configuration file it creates coming from the per
2515 * daemon configuration files. This also allows the daemons
2516 * to start if there default configuration file is not
2517 * present or ignore them, as needed when using vtysh -b to
2518 * configure the daemons at boot - MAG
2521 /* Stat for vtysh Zebra.conf, if found startup and wait for
2522 * boot configuration
2525 if ( strstr(config_default_dir
, "vtysh") == NULL
)
2527 ret
= stat (integrate_default
, &conf_stat
);
2529 goto tmp_free_and_out
;
2532 confp
= fopen (config_default_dir
, "r");
2535 fprintf (stderr
, "%s: failed to open configuration file %s: %s\n",
2536 __func__
, config_default_dir
, safe_strerror (errno
));
2538 confp
= vty_use_backup_config (config_default_dir
);
2541 fprintf (stderr
, "WARNING: using backup configuration file!\n");
2542 fullpath
= config_default_dir
;
2546 fprintf (stderr
, "can't open configuration file [%s]\n",
2547 config_default_dir
);
2548 goto tmp_free_and_out
;
2552 fullpath
= config_default_dir
;
2555 vty_read_file (confp
);
2559 host_config_set (fullpath
);
2563 XFREE (MTYPE_TMP
, tmp
);
2566 /* Small utility function which output log to the VTY. */
2568 vty_log (const char *level
, const char *proto_str
,
2569 const char *format
, struct timestamp_control
*ctl
, va_list va
)
2577 for (i
= 0; i
< vector_active (vtyvec
); i
++)
2578 if ((vty
= vector_slot (vtyvec
, i
)) != NULL
)
2583 vty_log_out (vty
, level
, proto_str
, format
, ctl
, ac
);
2588 /* Async-signal-safe version of vty_log for fixed strings. */
2590 vty_log_fixed (char *buf
, size_t len
)
2593 struct iovec iov
[2];
2594 char crlf
[4] = "\r\n";
2596 /* vty may not have been initialised */
2600 iov
[0].iov_base
= buf
;
2601 iov
[0].iov_len
= len
;
2602 iov
[1].iov_base
= crlf
;
2605 for (i
= 0; i
< vector_active (vtyvec
); i
++)
2608 if (((vty
= vector_slot (vtyvec
, i
)) != NULL
) && vty
->monitor
)
2609 /* N.B. We don't care about the return code, since process is
2610 most likely just about to die anyway. */
2611 if (writev(vty
->wfd
, iov
, 2) == -1)
2613 fprintf(stderr
, "Failure to writev: %d\n", errno
);
2620 vty_config_lock (struct vty
*vty
)
2622 if (vty_config_is_lockless
)
2624 if (vty_config
== 0)
2633 vty_config_unlock (struct vty
*vty
)
2635 if (vty_config_is_lockless
)
2637 if (vty_config
== 1 && vty
->config
== 1)
2646 vty_config_lockless (void)
2648 vty_config_is_lockless
= 1;
2651 /* Master of the threads. */
2652 static struct thread_master
*vty_master
;
2655 vty_event (enum event event
, int sock
, struct vty
*vty
)
2657 struct thread
*vty_serv_thread
= NULL
;
2662 vty_serv_thread
= thread_add_read(vty_master
, vty_accept
, vty
, sock
, NULL
);
2663 vector_set_index (Vvty_serv_thread
, sock
, vty_serv_thread
);
2667 vty_serv_thread
= thread_add_read(vty_master
, vtysh_accept
, vty
, sock
, NULL
);
2668 vector_set_index (Vvty_serv_thread
, sock
, vty_serv_thread
);
2672 thread_add_read(vty_master
, vtysh_read
, vty
, sock
, &vty
->t_read
);
2675 vty
->t_write
= NULL
;
2676 thread_add_write(vty_master
, vtysh_write
, vty
, sock
, &vty
->t_write
);
2681 thread_add_read(vty_master
, vty_read
, vty
, sock
, &vty
->t_read
);
2683 /* Time out treatment. */
2687 thread_cancel (vty
->t_timeout
);
2688 vty
->t_timeout
= NULL
;
2689 thread_add_timer(vty_master
, vty_timeout
, vty
, vty
->v_timeout
,
2694 thread_add_write(vty_master
, vty_flush
, vty
, sock
, &vty
->t_write
);
2696 case VTY_TIMEOUT_RESET
:
2699 thread_cancel (vty
->t_timeout
);
2700 vty
->t_timeout
= NULL
;
2704 vty
->t_timeout
= NULL
;
2705 thread_add_timer(vty_master
, vty_timeout
, vty
, vty
->v_timeout
,
2712 DEFUN_NOSH (config_who
,
2715 "Display who is on vty\n")
2720 for (i
= 0; i
< vector_active (vtyvec
); i
++)
2721 if ((v
= vector_slot (vtyvec
, i
)) != NULL
)
2722 vty_out (vty
, "%svty[%d] connected from %s.%s",
2723 v
->config
? "*" : " ",
2724 i
, v
->address
, VTYNL
);
2728 /* Move to vty configuration mode. */
2729 DEFUN_NOSH (line_vty
,
2732 "Configure a terminal line\n"
2733 "Virtual terminal\n")
2735 vty
->node
= VTY_NODE
;
2739 /* Set time out value. */
2741 exec_timeout (struct vty
*vty
, const char *min_str
, const char *sec_str
)
2743 unsigned long timeout
= 0;
2745 /* min_str and sec_str are already checked by parser. So it must be
2746 all digit string. */
2749 timeout
= strtol (min_str
, NULL
, 10);
2753 timeout
+= strtol (sec_str
, NULL
, 10);
2755 vty_timeout_val
= timeout
;
2756 vty
->v_timeout
= timeout
;
2757 vty_event (VTY_TIMEOUT_RESET
, 0, vty
);
2763 DEFUN (exec_timeout_min
,
2764 exec_timeout_min_cmd
,
2765 "exec-timeout (0-35791)",
2766 "Set timeout value\n"
2767 "Timeout value in minutes\n")
2770 return exec_timeout (vty
, argv
[idx_number
]->arg
, NULL
);
2773 DEFUN (exec_timeout_sec
,
2774 exec_timeout_sec_cmd
,
2775 "exec-timeout (0-35791) (0-2147483)",
2776 "Set the EXEC timeout\n"
2777 "Timeout in minutes\n"
2778 "Timeout in seconds\n")
2781 int idx_number_2
= 2;
2782 return exec_timeout (vty
, argv
[idx_number
]->arg
, argv
[idx_number_2
]->arg
);
2785 DEFUN (no_exec_timeout
,
2786 no_exec_timeout_cmd
,
2789 "Set the EXEC timeout\n")
2791 return exec_timeout (vty
, NULL
, NULL
);
2794 /* Set vty access class. */
2795 DEFUN (vty_access_class
,
2796 vty_access_class_cmd
,
2797 "access-class WORD",
2798 "Filter connections based on an IP access list\n"
2802 if (vty_accesslist_name
)
2803 XFREE(MTYPE_VTY
, vty_accesslist_name
);
2805 vty_accesslist_name
= XSTRDUP(MTYPE_VTY
, argv
[idx_word
]->arg
);
2810 /* Clear vty access class. */
2811 DEFUN (no_vty_access_class
,
2812 no_vty_access_class_cmd
,
2813 "no access-class [WORD]",
2815 "Filter connections based on an IP access list\n"
2819 const char *accesslist
= (argc
== 3) ? argv
[idx_word
]->arg
: NULL
;
2820 if (! vty_accesslist_name
|| (argc
== 3 && strcmp(vty_accesslist_name
, accesslist
)))
2822 vty_outln (vty
,"Access-class is not currently applied to vty");
2826 XFREE(MTYPE_VTY
, vty_accesslist_name
);
2828 vty_accesslist_name
= NULL
;
2833 /* Set vty access class. */
2834 DEFUN (vty_ipv6_access_class
,
2835 vty_ipv6_access_class_cmd
,
2836 "ipv6 access-class WORD",
2838 "Filter connections based on an IP access list\n"
2839 "IPv6 access list\n")
2842 if (vty_ipv6_accesslist_name
)
2843 XFREE(MTYPE_VTY
, vty_ipv6_accesslist_name
);
2845 vty_ipv6_accesslist_name
= XSTRDUP(MTYPE_VTY
, argv
[idx_word
]->arg
);
2850 /* Clear vty access class. */
2851 DEFUN (no_vty_ipv6_access_class
,
2852 no_vty_ipv6_access_class_cmd
,
2853 "no ipv6 access-class [WORD]",
2856 "Filter connections based on an IP access list\n"
2857 "IPv6 access list\n")
2860 const char *accesslist
= (argc
== 4) ? argv
[idx_word
]->arg
: NULL
;
2862 if (! vty_ipv6_accesslist_name
||
2863 (argc
== 4 && strcmp(vty_ipv6_accesslist_name
, accesslist
)))
2865 vty_outln (vty
,"IPv6 access-class is not currently applied to vty");
2869 XFREE(MTYPE_VTY
, vty_ipv6_accesslist_name
);
2871 vty_ipv6_accesslist_name
= NULL
;
2880 "Enable password checking\n")
2882 no_password_check
= 0;
2886 DEFUN (no_vty_login
,
2890 "Enable password checking\n")
2892 no_password_check
= 1;
2896 DEFUN (service_advanced_vty
,
2897 service_advanced_vty_cmd
,
2898 "service advanced-vty",
2899 "Set up miscellaneous service\n"
2900 "Enable advanced mode vty interface\n")
2906 DEFUN (no_service_advanced_vty
,
2907 no_service_advanced_vty_cmd
,
2908 "no service advanced-vty",
2910 "Set up miscellaneous service\n"
2911 "Enable advanced mode vty interface\n")
2917 DEFUN_NOSH (terminal_monitor
,
2918 terminal_monitor_cmd
,
2920 "Set terminal line parameters\n"
2921 "Copy debug output to the current terminal line\n")
2927 DEFUN_NOSH (terminal_no_monitor
,
2928 terminal_no_monitor_cmd
,
2929 "terminal no monitor",
2930 "Set terminal line parameters\n"
2932 "Copy debug output to the current terminal line\n")
2938 DEFUN_NOSH (no_terminal_monitor
,
2939 no_terminal_monitor_cmd
,
2940 "no terminal monitor",
2942 "Set terminal line parameters\n"
2943 "Copy debug output to the current terminal line\n")
2945 return terminal_no_monitor (self
, vty
, argc
, argv
);
2949 DEFUN_NOSH (show_history
,
2953 "Display the session command history\n")
2957 for (index
= vty
->hindex
+ 1; index
!= vty
->hindex
;)
2959 if (index
== VTY_MAXHIST
)
2965 if (vty
->hist
[index
] != NULL
)
2966 vty_out (vty
, " %s%s", vty
->hist
[index
], VTYNL
);
2975 DEFUN (log_commands
,
2979 "Log all commands (can't be unset without restart)\n")
2981 do_log_commands
= 1;
2985 /* Display current configuration. */
2987 vty_config_write (struct vty
*vty
)
2989 vty_outln (vty
, "line vty");
2991 if (vty_accesslist_name
)
2992 vty_outln (vty
, " access-class %s",
2993 vty_accesslist_name
);
2995 if (vty_ipv6_accesslist_name
)
2996 vty_outln (vty
, " ipv6 access-class %s",
2997 vty_ipv6_accesslist_name
);
3000 if (vty_timeout_val
!= VTY_TIMEOUT_DEFAULT
)
3001 vty_outln (vty
, " exec-timeout %ld %ld",
3002 vty_timeout_val
/ 60,
3003 vty_timeout_val
% 60);
3006 if (no_password_check
)
3007 vty_outln (vty
, " no login");
3009 if (do_log_commands
)
3010 vty_outln (vty
, "log commands");
3012 vty_outln (vty
, "!");
3017 struct cmd_node vty_node
=
3020 "%s(config-line)# ",
3024 /* Reset all VTY status. */
3030 struct thread
*vty_serv_thread
;
3032 for (i
= 0; i
< vector_active (vtyvec
); i
++)
3033 if ((vty
= vector_slot (vtyvec
, i
)) != NULL
)
3035 buffer_reset (vty
->obuf
);
3036 vty
->status
= VTY_CLOSE
;
3040 for (i
= 0; i
< vector_active (Vvty_serv_thread
); i
++)
3041 if ((vty_serv_thread
= vector_slot (Vvty_serv_thread
, i
)) != NULL
)
3043 thread_cancel (vty_serv_thread
);
3044 vector_slot (Vvty_serv_thread
, i
) = NULL
;
3048 vty_timeout_val
= VTY_TIMEOUT_DEFAULT
;
3050 if (vty_accesslist_name
)
3052 XFREE(MTYPE_VTY
, vty_accesslist_name
);
3053 vty_accesslist_name
= NULL
;
3056 if (vty_ipv6_accesslist_name
)
3058 XFREE(MTYPE_VTY
, vty_ipv6_accesslist_name
);
3059 vty_ipv6_accesslist_name
= NULL
;
3066 char cwd
[MAXPATHLEN
];
3069 c
= getcwd (cwd
, MAXPATHLEN
);
3074 * At this point if these go wrong, more than likely
3075 * the whole world is coming down around us
3076 * Hence not worrying about it too much.
3078 if (!chdir (SYSCONFDIR
))
3080 fprintf(stderr
, "Failure to chdir to %s, errno: %d\n", SYSCONFDIR
, errno
);
3083 if (getcwd (cwd
, MAXPATHLEN
) == NULL
)
3085 fprintf(stderr
, "Failure to getcwd, errno: %d\n", errno
);
3090 vty_cwd
= XMALLOC (MTYPE_TMP
, strlen (cwd
) + 1);
3091 strcpy (vty_cwd
, cwd
);
3101 vty_shell (struct vty
*vty
)
3103 return vty
->type
== VTY_SHELL
? 1 : 0;
3107 vty_shell_serv (struct vty
*vty
)
3109 return vty
->type
== VTY_SHELL_SERV
? 1 : 0;
3115 vtyvec
= vector_init (VECTOR_MIN_SIZE
);
3118 /* Install vty's own commands like `who' command. */
3120 vty_init (struct thread_master
*master_thread
)
3122 /* For further configuration read, preserve current directory. */
3125 vtyvec
= vector_init (VECTOR_MIN_SIZE
);
3127 vty_master
= master_thread
;
3129 atexit (vty_stdio_reset
);
3131 /* Initilize server thread vector. */
3132 Vvty_serv_thread
= vector_init (VECTOR_MIN_SIZE
);
3134 /* Install bgp top node. */
3135 install_node (&vty_node
, vty_config_write
);
3137 install_element (VIEW_NODE
, &config_who_cmd
);
3138 install_element (VIEW_NODE
, &show_history_cmd
);
3139 install_element (CONFIG_NODE
, &line_vty_cmd
);
3140 install_element (CONFIG_NODE
, &service_advanced_vty_cmd
);
3141 install_element (CONFIG_NODE
, &no_service_advanced_vty_cmd
);
3142 install_element (CONFIG_NODE
, &show_history_cmd
);
3143 install_element (CONFIG_NODE
, &log_commands_cmd
);
3144 install_element (ENABLE_NODE
, &terminal_monitor_cmd
);
3145 install_element (ENABLE_NODE
, &terminal_no_monitor_cmd
);
3146 install_element (ENABLE_NODE
, &no_terminal_monitor_cmd
);
3148 install_default (VTY_NODE
);
3149 install_element (VTY_NODE
, &exec_timeout_min_cmd
);
3150 install_element (VTY_NODE
, &exec_timeout_sec_cmd
);
3151 install_element (VTY_NODE
, &no_exec_timeout_cmd
);
3152 install_element (VTY_NODE
, &vty_access_class_cmd
);
3153 install_element (VTY_NODE
, &no_vty_access_class_cmd
);
3154 install_element (VTY_NODE
, &vty_login_cmd
);
3155 install_element (VTY_NODE
, &no_vty_login_cmd
);
3156 install_element (VTY_NODE
, &vty_ipv6_access_class_cmd
);
3157 install_element (VTY_NODE
, &no_vty_ipv6_access_class_cmd
);
3161 vty_terminate (void)
3164 XFREE (MTYPE_TMP
, vty_cwd
);
3166 if (vtyvec
&& Vvty_serv_thread
)
3169 vector_free (vtyvec
);
3170 vector_free (Vvty_serv_thread
);
3172 Vvty_serv_thread
= NULL
;