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 buffer_put (vty
->obuf
, (u_char
*) p
, len
);
148 /* If p is not different with buf, it is allocated buffer. */
150 XFREE (MTYPE_VTY_OUT_BUF
, p
);
157 vty_log_out (struct vty
*vty
, const char *level
, const char *proto_str
,
158 const char *format
, struct timestamp_control
*ctl
, va_list va
)
164 if (!ctl
->already_rendered
)
166 ctl
->len
= quagga_timestamp(ctl
->precision
, ctl
->buf
, sizeof(ctl
->buf
));
167 ctl
->already_rendered
= 1;
169 if (ctl
->len
+1 >= sizeof(buf
))
171 memcpy(buf
, ctl
->buf
, len
= ctl
->len
);
176 ret
= snprintf(buf
+len
, sizeof(buf
)-len
, "%s: %s: ", level
, proto_str
);
178 ret
= snprintf(buf
+len
, sizeof(buf
)-len
, "%s: ", proto_str
);
179 if ((ret
< 0) || ((size_t)(len
+= ret
) >= sizeof(buf
)))
182 if (((ret
= vsnprintf(buf
+len
, sizeof(buf
)-len
, format
, va
)) < 0) ||
183 ((size_t)((len
+= ret
)+2) > sizeof(buf
)))
189 if (write(vty
->wfd
, buf
, len
) < 0)
191 if (ERRNO_IO_RETRY(errno
))
192 /* Kernel buffer is full, probably too much debugging output, so just
193 drop the data and ignore. */
195 /* Fatal I/O error. */
196 vty
->monitor
= 0; /* disable monitoring to avoid infinite recursion */
197 zlog_warn("%s: write failed to vty client fd %d, closing: %s",
198 __func__
, vty
->fd
, safe_strerror(errno
));
199 buffer_reset(vty
->obuf
);
200 /* cannot call vty_close, because a parent routine may still try
201 to access the vty struct */
202 vty
->status
= VTY_CLOSE
;
203 shutdown(vty
->fd
, SHUT_RDWR
);
209 /* Output current time to the vty. */
211 vty_time_print (struct vty
*vty
, int cr
)
213 char buf
[QUAGGA_TIMESTAMP_LEN
];
215 if (quagga_timestamp(0, buf
, sizeof(buf
)) == 0)
217 zlog_info("quagga_timestamp error");
221 vty_out (vty
, "%s\n", buf
);
223 vty_out (vty
, "%s ", buf
);
228 /* Say hello to vty interface. */
230 vty_hello (struct vty
*vty
)
237 f
= fopen (host
.motdfile
, "r");
240 while (fgets (buf
, sizeof (buf
), f
))
243 /* work backwards to ignore trailling isspace() */
244 for (s
= buf
+ strlen (buf
); (s
> buf
) && isspace ((int)*(s
- 1));
247 vty_out (vty
, "%s%s", buf
, VTY_NEWLINE
);
252 vty_out (vty
, "MOTD file not found%s", VTY_NEWLINE
);
255 vty_out (vty
, "%s", host
.motd
);
258 /* Put out prompt and wait input from user. */
260 vty_prompt (struct vty
*vty
)
262 struct utsname names
;
265 if (vty
->type
== VTY_TERM
)
267 hostname
= host
.name
;
271 hostname
= names
.nodename
;
273 vty_out (vty
, cmd_prompt (vty
->node
), hostname
);
277 /* Send WILL TELOPT_ECHO to remote server. */
279 vty_will_echo (struct vty
*vty
)
281 unsigned char cmd
[] = { IAC
, WILL
, TELOPT_ECHO
, '\0' };
282 vty_out (vty
, "%s", cmd
);
285 /* Make suppress Go-Ahead telnet option. */
287 vty_will_suppress_go_ahead (struct vty
*vty
)
289 unsigned char cmd
[] = { IAC
, WILL
, TELOPT_SGA
, '\0' };
290 vty_out (vty
, "%s", cmd
);
293 /* Make don't use linemode over telnet. */
295 vty_dont_linemode (struct vty
*vty
)
297 unsigned char cmd
[] = { IAC
, DONT
, TELOPT_LINEMODE
, '\0' };
298 vty_out (vty
, "%s", cmd
);
301 /* Use window size. */
303 vty_do_window_size (struct vty
*vty
)
305 unsigned char cmd
[] = { IAC
, DO
, TELOPT_NAWS
, '\0' };
306 vty_out (vty
, "%s", cmd
);
309 #if 0 /* Currently not used. */
310 /* Make don't use lflow vty interface. */
312 vty_dont_lflow_ahead (struct vty
*vty
)
314 unsigned char cmd
[] = { IAC
, DONT
, TELOPT_LFLOW
, '\0' };
315 vty_out (vty
, "%s", cmd
);
319 /* Allocate new vty struct. */
323 struct vty
*new = XCALLOC (MTYPE_VTY
, sizeof (struct vty
));
325 new->obuf
= buffer_new(0); /* Use default buffer size. */
326 new->buf
= XCALLOC (MTYPE_VTY
, VTY_BUFSIZ
);
327 new->error_buf
= XCALLOC (MTYPE_VTY
, VTY_BUFSIZ
);
328 new->max
= VTY_BUFSIZ
;
333 /* Authentication of vty */
335 vty_auth (struct vty
*vty
, char *buf
)
338 enum node_type next_node
= 0;
340 char *crypt (const char *, const char *);
346 passwd
= host
.password_encrypt
;
348 passwd
= host
.password
;
350 next_node
= host
.enable
? VIEW_NODE
: ENABLE_NODE
;
352 next_node
= VIEW_NODE
;
354 case AUTH_ENABLE_NODE
:
356 passwd
= host
.enable_encrypt
;
358 passwd
= host
.enable
;
359 next_node
= ENABLE_NODE
;
366 fail
= strcmp (crypt(buf
, passwd
), passwd
);
368 fail
= strcmp (buf
, passwd
);
376 vty
->node
= next_node
; /* Success ! */
383 if (vty
->node
== AUTH_NODE
)
385 vty_out (vty
, "%% Bad passwords, too many failures!%s", VTY_NEWLINE
);
386 vty
->status
= VTY_CLOSE
;
390 /* AUTH_ENABLE_NODE */
392 vty_out (vty
, "%% Bad enable passwords, too many failures!%s", VTY_NEWLINE
);
393 vty
->status
= VTY_CLOSE
;
399 /* Command execution over the vty interface. */
401 vty_command (struct vty
*vty
, char *buf
)
405 const char *protocolname
;
409 * Log non empty command lines
415 /* Skip white spaces. */
416 while (isspace ((int) *cp
) && *cp
!= '\0')
419 if (cp
!= NULL
&& *cp
!= '\0')
422 char vty_str
[VTY_BUFSIZ
];
423 char prompt_str
[VTY_BUFSIZ
];
425 /* format the base vty info */
426 snprintf(vty_str
, sizeof(vty_str
), "vty[??]@%s", vty
->address
);
428 for (i
= 0; i
< vector_active (vtyvec
); i
++)
429 if (vty
== vector_slot (vtyvec
, i
))
431 snprintf(vty_str
, sizeof(vty_str
), "vty[%d]@%s",
436 /* format the prompt */
437 snprintf(prompt_str
, sizeof(prompt_str
), cmd_prompt (vty
->node
), vty_str
);
439 /* now log the command */
440 zlog_err("%s%s", prompt_str
, buf
);
442 /* Split readline string up into the vector */
443 vline
= cmd_make_strvec (buf
);
448 #ifdef CONSUMED_TIME_CHECK
452 unsigned long realtime
, cputime
;
455 #endif /* CONSUMED_TIME_CHECK */
457 ret
= cmd_execute_command (vline
, vty
, NULL
, 0);
459 /* Get the name of the protocol if any */
460 protocolname
= frr_protoname
;
462 #ifdef CONSUMED_TIME_CHECK
464 if ((realtime
= thread_consumed_time(&after
, &before
, &cputime
)) >
466 /* Warn about CPU hog that must be fixed. */
467 zlog_warn("SLOW COMMAND: command took %lums (cpu time %lums): %s",
468 realtime
/1000, cputime
/1000, buf
);
470 #endif /* CONSUMED_TIME_CHECK */
472 if (ret
!= CMD_SUCCESS
)
476 if (vty
->type
== VTY_FILE
)
477 vty_out (vty
, "Warning...%s", VTY_NEWLINE
);
479 case CMD_ERR_AMBIGUOUS
:
480 vty_out (vty
, "%% Ambiguous command.%s", VTY_NEWLINE
);
482 case CMD_ERR_NO_MATCH
:
483 vty_out (vty
, "%% [%s] Unknown command: %s%s", protocolname
, buf
, VTY_NEWLINE
);
485 case CMD_ERR_INCOMPLETE
:
486 vty_out (vty
, "%% Command incomplete.%s", VTY_NEWLINE
);
489 cmd_free_strvec (vline
);
494 static const char telnet_backward_char
= 0x08;
495 static const char telnet_space_char
= ' ';
497 /* Basic function to write buffer to vty. */
499 vty_write (struct vty
*vty
, const char *buf
, size_t nbytes
)
501 if ((vty
->node
== AUTH_NODE
) || (vty
->node
== AUTH_ENABLE_NODE
))
504 /* Should we do buffering here ? And make vty_flush (vty) ? */
505 buffer_put (vty
->obuf
, buf
, nbytes
);
508 /* Basic function to insert character into vty. */
510 vty_self_insert (struct vty
*vty
, char c
)
515 if (vty
->length
+ 1 >= VTY_BUFSIZ
)
518 length
= vty
->length
- vty
->cp
;
519 memmove (&vty
->buf
[vty
->cp
+ 1], &vty
->buf
[vty
->cp
], length
);
520 vty
->buf
[vty
->cp
] = c
;
522 vty_write (vty
, &vty
->buf
[vty
->cp
], length
+ 1);
523 for (i
= 0; i
< length
; i
++)
524 vty_write (vty
, &telnet_backward_char
, 1);
529 vty
->buf
[vty
->length
] = '\0';
532 /* Self insert character 'c' in overwrite mode. */
534 vty_self_insert_overwrite (struct vty
*vty
, char c
)
536 if (vty
->cp
== vty
->length
)
538 vty_self_insert (vty
, c
);
542 vty
->buf
[vty
->cp
++] = c
;
543 vty_write (vty
, &c
, 1);
547 * Insert a string into vty->buf at the current cursor position.
549 * If the resultant string would be larger than VTY_BUFSIZ it is
553 vty_insert_word_overwrite (struct vty
*vty
, char *str
)
555 if (vty
->cp
== VTY_BUFSIZ
)
558 size_t nwrite
= MIN ((int) strlen (str
), VTY_BUFSIZ
- vty
->cp
- 1);
559 memcpy (&vty
->buf
[vty
->cp
], str
, nwrite
);
561 vty
->length
= MAX (vty
->cp
, vty
->length
);
562 vty
->buf
[vty
->length
] = '\0';
563 vty_write (vty
, str
, nwrite
);
566 /* Forward character. */
568 vty_forward_char (struct vty
*vty
)
570 if (vty
->cp
< vty
->length
)
572 vty_write (vty
, &vty
->buf
[vty
->cp
], 1);
577 /* Backward character. */
579 vty_backward_char (struct vty
*vty
)
584 vty_write (vty
, &telnet_backward_char
, 1);
588 /* Move to the beginning of the line. */
590 vty_beginning_of_line (struct vty
*vty
)
593 vty_backward_char (vty
);
596 /* Move to the end of the line. */
598 vty_end_of_line (struct vty
*vty
)
600 while (vty
->cp
< vty
->length
)
601 vty_forward_char (vty
);
604 static void vty_kill_line_from_beginning (struct vty
*);
605 static void vty_redraw_line (struct vty
*);
607 /* Print command line history. This function is called from
608 vty_next_line and vty_previous_line. */
610 vty_history_print (struct vty
*vty
)
614 vty_kill_line_from_beginning (vty
);
616 /* Get previous line from history buffer */
617 length
= strlen (vty
->hist
[vty
->hp
]);
618 memcpy (vty
->buf
, vty
->hist
[vty
->hp
], length
);
619 vty
->cp
= vty
->length
= length
;
620 vty
->buf
[vty
->length
] = '\0';
622 /* Redraw current line */
623 vty_redraw_line (vty
);
626 /* Show next command line history. */
628 vty_next_line (struct vty
*vty
)
632 if (vty
->hp
== vty
->hindex
)
635 /* Try is there history exist or not. */
637 if (try_index
== (VTY_MAXHIST
- 1))
642 /* If there is not history return. */
643 if (vty
->hist
[try_index
] == NULL
)
648 vty_history_print (vty
);
651 /* Show previous command line history. */
653 vty_previous_line (struct vty
*vty
)
659 try_index
= VTY_MAXHIST
- 1;
663 if (vty
->hist
[try_index
] == NULL
)
668 vty_history_print (vty
);
671 /* This function redraw all of the command line character. */
673 vty_redraw_line (struct vty
*vty
)
675 vty_write (vty
, vty
->buf
, vty
->length
);
676 vty
->cp
= vty
->length
;
681 vty_forward_word (struct vty
*vty
)
683 while (vty
->cp
!= vty
->length
&& vty
->buf
[vty
->cp
] != ' ')
684 vty_forward_char (vty
);
686 while (vty
->cp
!= vty
->length
&& vty
->buf
[vty
->cp
] == ' ')
687 vty_forward_char (vty
);
690 /* Backward word without skipping training space. */
692 vty_backward_pure_word (struct vty
*vty
)
694 while (vty
->cp
> 0 && vty
->buf
[vty
->cp
- 1] != ' ')
695 vty_backward_char (vty
);
700 vty_backward_word (struct vty
*vty
)
702 while (vty
->cp
> 0 && vty
->buf
[vty
->cp
- 1] == ' ')
703 vty_backward_char (vty
);
705 while (vty
->cp
> 0 && vty
->buf
[vty
->cp
- 1] != ' ')
706 vty_backward_char (vty
);
709 /* When '^D' is typed at the beginning of the line we move to the down
712 vty_down_level (struct vty
*vty
)
714 vty_out (vty
, "%s", VTY_NEWLINE
);
720 /* When '^Z' is received from vty, move down to the enable mode. */
722 vty_end_config (struct vty
*vty
)
724 vty_out (vty
, "%s", VTY_NEWLINE
);
741 case BGP_VRF_POLICY_NODE
:
742 case BGP_VNC_DEFAULTS_NODE
:
743 case BGP_VNC_NVE_GROUP_NODE
:
744 case BGP_VNC_L2_GROUP_NODE
:
758 case LDP_IPV4_IFACE_NODE
:
759 case LDP_IPV6_IFACE_NODE
:
761 case LDP_PSEUDOWIRE_NODE
:
764 case KEYCHAIN_KEY_NODE
:
768 vty_config_unlock (vty
);
769 vty
->node
= ENABLE_NODE
;
772 /* Unknown node, we have to ignore it. */
780 /* Delete a charcter at the current point. */
782 vty_delete_char (struct vty
*vty
)
787 if (vty
->length
== 0)
789 vty_down_level (vty
);
793 if (vty
->cp
== vty
->length
)
794 return; /* completion need here? */
796 size
= vty
->length
- vty
->cp
;
799 memmove (&vty
->buf
[vty
->cp
], &vty
->buf
[vty
->cp
+ 1], size
- 1);
800 vty
->buf
[vty
->length
] = '\0';
802 if (vty
->node
== AUTH_NODE
|| vty
->node
== AUTH_ENABLE_NODE
)
805 vty_write (vty
, &vty
->buf
[vty
->cp
], size
- 1);
806 vty_write (vty
, &telnet_space_char
, 1);
808 for (i
= 0; i
< size
; i
++)
809 vty_write (vty
, &telnet_backward_char
, 1);
812 /* Delete a character before the point. */
814 vty_delete_backward_char (struct vty
*vty
)
819 vty_backward_char (vty
);
820 vty_delete_char (vty
);
823 /* Kill rest of line from current point. */
825 vty_kill_line (struct vty
*vty
)
830 size
= vty
->length
- vty
->cp
;
835 for (i
= 0; i
< size
; i
++)
836 vty_write (vty
, &telnet_space_char
, 1);
837 for (i
= 0; i
< size
; i
++)
838 vty_write (vty
, &telnet_backward_char
, 1);
840 memset (&vty
->buf
[vty
->cp
], 0, size
);
841 vty
->length
= vty
->cp
;
844 /* Kill line from the beginning. */
846 vty_kill_line_from_beginning (struct vty
*vty
)
848 vty_beginning_of_line (vty
);
852 /* Delete a word before the point. */
854 vty_forward_kill_word (struct vty
*vty
)
856 while (vty
->cp
!= vty
->length
&& vty
->buf
[vty
->cp
] == ' ')
857 vty_delete_char (vty
);
858 while (vty
->cp
!= vty
->length
&& vty
->buf
[vty
->cp
] != ' ')
859 vty_delete_char (vty
);
862 /* Delete a word before the point. */
864 vty_backward_kill_word (struct vty
*vty
)
866 while (vty
->cp
> 0 && vty
->buf
[vty
->cp
- 1] == ' ')
867 vty_delete_backward_char (vty
);
868 while (vty
->cp
> 0 && vty
->buf
[vty
->cp
- 1] != ' ')
869 vty_delete_backward_char (vty
);
872 /* Transpose chars before or at the point. */
874 vty_transpose_chars (struct vty
*vty
)
878 /* If length is short or point is near by the beginning of line then
880 if (vty
->length
< 2 || vty
->cp
< 1)
883 /* In case of point is located at the end of the line. */
884 if (vty
->cp
== vty
->length
)
886 c1
= vty
->buf
[vty
->cp
- 1];
887 c2
= vty
->buf
[vty
->cp
- 2];
889 vty_backward_char (vty
);
890 vty_backward_char (vty
);
891 vty_self_insert_overwrite (vty
, c1
);
892 vty_self_insert_overwrite (vty
, c2
);
896 c1
= vty
->buf
[vty
->cp
];
897 c2
= vty
->buf
[vty
->cp
- 1];
899 vty_backward_char (vty
);
900 vty_self_insert_overwrite (vty
, c1
);
901 vty_self_insert_overwrite (vty
, c2
);
905 /* Do completion at vty interface. */
907 vty_complete_command (struct vty
*vty
)
911 char **matched
= NULL
;
914 if (vty
->node
== AUTH_NODE
|| vty
->node
== AUTH_ENABLE_NODE
)
917 vline
= cmd_make_strvec (vty
->buf
);
921 /* In case of 'help \t'. */
922 if (isspace ((int) vty
->buf
[vty
->length
- 1]))
923 vector_set (vline
, NULL
);
925 matched
= cmd_complete_command (vline
, vty
, &ret
);
927 cmd_free_strvec (vline
);
929 vty_out (vty
, "%s", VTY_NEWLINE
);
932 case CMD_ERR_AMBIGUOUS
:
933 vty_out (vty
, "%% Ambiguous command.%s", VTY_NEWLINE
);
935 vty_redraw_line (vty
);
937 case CMD_ERR_NO_MATCH
:
938 /* vty_out (vty, "%% There is no matched command.%s", VTY_NEWLINE); */
940 vty_redraw_line (vty
);
942 case CMD_COMPLETE_FULL_MATCH
:
945 /* 2016-11-28 equinox -- need to debug, SEGV here */
946 vty_out (vty
, "%% CLI BUG: FULL_MATCH with NULL str%s", VTY_NEWLINE
);
948 vty_redraw_line (vty
);
952 vty_redraw_line (vty
);
953 vty_backward_pure_word (vty
);
954 vty_insert_word_overwrite (vty
, matched
[0]);
955 vty_self_insert (vty
, ' ');
956 XFREE (MTYPE_COMPLETION
, matched
[0]);
958 case CMD_COMPLETE_MATCH
:
960 vty_redraw_line (vty
);
961 vty_backward_pure_word (vty
);
962 vty_insert_word_overwrite (vty
, matched
[0]);
963 XFREE (MTYPE_COMPLETION
, matched
[0]);
965 case CMD_COMPLETE_LIST_MATCH
:
966 for (i
= 0; matched
[i
] != NULL
; i
++)
968 if (i
!= 0 && ((i
% 6) == 0))
969 vty_out (vty
, "%s", VTY_NEWLINE
);
970 vty_out (vty
, "%-10s ", matched
[i
]);
971 XFREE (MTYPE_COMPLETION
, matched
[i
]);
973 vty_out (vty
, "%s", VTY_NEWLINE
);
976 vty_redraw_line (vty
);
978 case CMD_ERR_NOTHING_TODO
:
980 vty_redraw_line (vty
);
986 XFREE (MTYPE_TMP
, matched
);
990 vty_describe_fold (struct vty
*vty
, int cmd_width
,
991 unsigned int desc_width
, struct cmd_token
*token
)
1001 vty_out (vty
, " %-*s %s%s", cmd_width
, cmd
, token
->desc
, VTY_NEWLINE
);
1005 buf
= XCALLOC (MTYPE_TMP
, strlen (token
->desc
) + 1);
1007 for (p
= token
->desc
; strlen (p
) > desc_width
; p
+= pos
+ 1)
1009 for (pos
= desc_width
; pos
> 0; pos
--)
1010 if (*(p
+ pos
) == ' ')
1016 strncpy (buf
, p
, pos
);
1018 vty_out (vty
, " %-*s %s%s", cmd_width
, cmd
, buf
, VTY_NEWLINE
);
1023 vty_out (vty
, " %-*s %s%s", cmd_width
, cmd
, p
, VTY_NEWLINE
);
1025 XFREE (MTYPE_TMP
, buf
);
1028 /* Describe matched command function. */
1030 vty_describe_command (struct vty
*vty
)
1035 unsigned int i
, width
, desc_width
;
1036 struct cmd_token
*token
, *token_cr
= NULL
;
1038 vline
= cmd_make_strvec (vty
->buf
);
1040 /* In case of '> ?'. */
1043 vline
= vector_init (1);
1044 vector_set (vline
, NULL
);
1047 if (isspace ((int) vty
->buf
[vty
->length
- 1]))
1048 vector_set (vline
, NULL
);
1050 describe
= cmd_describe_command (vline
, vty
, &ret
);
1052 vty_out (vty
, "%s", VTY_NEWLINE
);
1054 /* Ambiguous error. */
1057 case CMD_ERR_AMBIGUOUS
:
1058 vty_out (vty
, "%% Ambiguous command.%s", VTY_NEWLINE
);
1061 case CMD_ERR_NO_MATCH
:
1062 vty_out (vty
, "%% There is no matched command.%s", VTY_NEWLINE
);
1067 /* Get width of command string. */
1069 for (i
= 0; i
< vector_active (describe
); i
++)
1070 if ((token
= vector_slot (describe
, i
)) != NULL
)
1074 if (token
->text
[0] == '\0')
1077 len
= strlen (token
->text
);
1083 /* Get width of description string. */
1084 desc_width
= vty
->width
- (width
+ 6);
1086 /* Print out description. */
1087 for (i
= 0; i
< vector_active (describe
); i
++)
1088 if ((token
= vector_slot (describe
, i
)) != NULL
)
1090 if (token
->text
[0] == '\0')
1093 if (strcmp (token
->text
, CMD_CR_TEXT
) == 0)
1100 vty_out (vty
, " %-s%s",
1103 else if (desc_width
>= strlen (token
->desc
))
1104 vty_out (vty
, " %-*s %s%s", width
,
1106 token
->desc
, VTY_NEWLINE
);
1108 vty_describe_fold (vty
, width
, desc_width
, token
);
1110 if (IS_VARYING_TOKEN(token
->type
))
1112 const char *ref
= vector_slot(vline
, vector_active(vline
) - 1);
1114 vector varcomps
= vector_init (VECTOR_MIN_SIZE
);
1115 cmd_variable_complete (token
, ref
, varcomps
);
1117 if (vector_active(varcomps
) > 0)
1120 for (size_t j
= 0; j
< vector_active (varcomps
); j
++)
1122 char *item
= vector_slot (varcomps
, j
);
1123 vty_out(vty
, " %s", item
);
1124 XFREE(MTYPE_COMPLETION
, item
);
1126 vty_out(vty
, "%s", VTY_NEWLINE
);
1128 vector_free(varcomps
);
1131 vty_out (vty
, " %-*s %s%s", width
1132 desc
->cmd
[0] == '.' ? desc
->cmd
+ 1 : desc
->cmd
,
1133 desc
->str
? desc
->str
: "", VTY_NEWLINE
);
1137 if ((token
= token_cr
))
1140 vty_out (vty
, " %-s%s",
1143 else if (desc_width
>= strlen (token
->desc
))
1144 vty_out (vty
, " %-*s %s%s", width
,
1146 token
->desc
, VTY_NEWLINE
);
1148 vty_describe_fold (vty
, width
, desc_width
, token
);
1152 cmd_free_strvec (vline
);
1154 vector_free (describe
);
1157 vty_redraw_line (vty
);
1161 vty_clear_buf (struct vty
*vty
)
1163 memset (vty
->buf
, 0, vty
->max
);
1166 /* ^C stop current input and do not add command line to the history. */
1168 vty_stop_input (struct vty
*vty
)
1170 vty
->cp
= vty
->length
= 0;
1171 vty_clear_buf (vty
);
1172 vty_out (vty
, "%s", VTY_NEWLINE
);
1178 /* Nothing to do. */
1181 case INTERFACE_NODE
:
1193 case LDP_IPV4_IFACE_NODE
:
1194 case LDP_IPV6_IFACE_NODE
:
1195 case LDP_L2VPN_NODE
:
1196 case LDP_PSEUDOWIRE_NODE
:
1199 case KEYCHAIN_KEY_NODE
:
1203 vty_config_unlock (vty
);
1204 vty
->node
= ENABLE_NODE
;
1207 /* Unknown node, we have to ignore it. */
1212 /* Set history pointer to the latest one. */
1213 vty
->hp
= vty
->hindex
;
1216 /* Add current command line to the history buffer. */
1218 vty_hist_add (struct vty
*vty
)
1222 if (vty
->length
== 0)
1225 index
= vty
->hindex
? vty
->hindex
- 1 : VTY_MAXHIST
- 1;
1227 /* Ignore the same string as previous one. */
1228 if (vty
->hist
[index
])
1229 if (strcmp (vty
->buf
, vty
->hist
[index
]) == 0)
1231 vty
->hp
= vty
->hindex
;
1235 /* Insert history entry. */
1236 if (vty
->hist
[vty
->hindex
])
1237 XFREE (MTYPE_VTY_HIST
, vty
->hist
[vty
->hindex
]);
1238 vty
->hist
[vty
->hindex
] = XSTRDUP (MTYPE_VTY_HIST
, vty
->buf
);
1240 /* History index rotation. */
1242 if (vty
->hindex
== VTY_MAXHIST
)
1245 vty
->hp
= vty
->hindex
;
1248 /* #define TELNET_OPTION_DEBUG */
1250 /* Get telnet window size. */
1252 vty_telnet_option (struct vty
*vty
, unsigned char *buf
, int nbytes
)
1254 #ifdef TELNET_OPTION_DEBUG
1257 for (i
= 0; i
< nbytes
; i
++)
1262 vty_out (vty
, "IAC ");
1265 vty_out (vty
, "WILL ");
1268 vty_out (vty
, "WONT ");
1271 vty_out (vty
, "DO ");
1274 vty_out (vty
, "DONT ");
1277 vty_out (vty
, "SB ");
1280 vty_out (vty
, "SE ");
1283 vty_out (vty
, "TELOPT_ECHO %s", VTY_NEWLINE
);
1286 vty_out (vty
, "TELOPT_SGA %s", VTY_NEWLINE
);
1289 vty_out (vty
, "TELOPT_NAWS %s", VTY_NEWLINE
);
1292 vty_out (vty
, "%x ", buf
[i
]);
1296 vty_out (vty
, "%s", VTY_NEWLINE
);
1298 #endif /* TELNET_OPTION_DEBUG */
1304 vty
->iac_sb_in_progress
= 1;
1309 if (!vty
->iac_sb_in_progress
)
1312 if ((vty
->sb_len
== 0) || (vty
->sb_buf
[0] == '\0'))
1314 vty
->iac_sb_in_progress
= 0;
1317 switch (vty
->sb_buf
[0])
1320 if (vty
->sb_len
!= TELNET_NAWS_SB_LEN
)
1321 zlog_warn("RFC 1073 violation detected: telnet NAWS option "
1322 "should send %d characters, but we received %lu",
1323 TELNET_NAWS_SB_LEN
, (u_long
)vty
->sb_len
);
1324 else if (sizeof(vty
->sb_buf
) < TELNET_NAWS_SB_LEN
)
1325 zlog_err("Bug detected: sizeof(vty->sb_buf) %lu < %d, "
1326 "too small to handle the telnet NAWS option",
1327 (u_long
)sizeof(vty
->sb_buf
), TELNET_NAWS_SB_LEN
);
1330 vty
->width
= ((vty
->sb_buf
[1] << 8)|vty
->sb_buf
[2]);
1331 vty
->height
= ((vty
->sb_buf
[3] << 8)|vty
->sb_buf
[4]);
1332 #ifdef TELNET_OPTION_DEBUG
1333 vty_out(vty
, "TELNET NAWS window size negotiation completed: "
1334 "width %d, height %d%s",
1335 vty
->width
, vty
->height
, VTY_NEWLINE
);
1340 vty
->iac_sb_in_progress
= 0;
1350 /* Execute current command line. */
1352 vty_execute (struct vty
*vty
)
1361 case AUTH_ENABLE_NODE
:
1362 vty_auth (vty
, vty
->buf
);
1365 ret
= vty_command (vty
, vty
->buf
);
1366 if (vty
->type
== VTY_TERM
)
1371 /* Clear command line buffer. */
1372 vty
->cp
= vty
->length
= 0;
1373 vty_clear_buf (vty
);
1375 if (vty
->status
!= VTY_CLOSE
)
1381 #define CONTROL(X) ((X) - '@')
1382 #define VTY_NORMAL 0
1383 #define VTY_PRE_ESCAPE 1
1384 #define VTY_ESCAPE 2
1386 /* Escape character command map. */
1388 vty_escape_map (unsigned char c
, struct vty
*vty
)
1393 vty_previous_line (vty
);
1396 vty_next_line (vty
);
1399 vty_forward_char (vty
);
1402 vty_backward_char (vty
);
1408 /* Go back to normal mode. */
1409 vty
->escape
= VTY_NORMAL
;
1412 /* Quit print out to the buffer. */
1414 vty_buffer_reset (struct vty
*vty
)
1416 buffer_reset (vty
->obuf
);
1418 vty_redraw_line (vty
);
1421 /* Read data via vty socket. */
1423 vty_read (struct thread
*thread
)
1427 unsigned char buf
[VTY_READ_BUFSIZ
];
1429 int vty_sock
= THREAD_FD (thread
);
1430 struct vty
*vty
= THREAD_ARG (thread
);
1433 /* Read raw data from socket */
1434 if ((nbytes
= read (vty
->fd
, buf
, VTY_READ_BUFSIZ
)) <= 0)
1438 if (ERRNO_IO_RETRY(errno
))
1440 vty_event (VTY_READ
, vty_sock
, vty
);
1443 vty
->monitor
= 0; /* disable monitoring to avoid infinite recursion */
1444 zlog_warn("%s: read error on vty client fd %d, closing: %s",
1445 __func__
, vty
->fd
, safe_strerror(errno
));
1446 buffer_reset(vty
->obuf
);
1448 vty
->status
= VTY_CLOSE
;
1451 for (i
= 0; i
< nbytes
; i
++)
1466 if (vty
->iac_sb_in_progress
&& !vty
->iac
)
1468 if (vty
->sb_len
< sizeof(vty
->sb_buf
))
1469 vty
->sb_buf
[vty
->sb_len
] = buf
[i
];
1476 /* In case of telnet command */
1478 ret
= vty_telnet_option (vty
, buf
+ i
, nbytes
- i
);
1485 if (vty
->status
== VTY_MORE
)
1492 vty_buffer_reset (vty
);
1494 #if 0 /* More line does not work for "show ip bgp". */
1497 vty
->status
= VTY_MORELINE
;
1506 /* Escape character. */
1507 if (vty
->escape
== VTY_ESCAPE
)
1509 vty_escape_map (buf
[i
], vty
);
1513 /* Pre-escape status. */
1514 if (vty
->escape
== VTY_PRE_ESCAPE
)
1519 vty
->escape
= VTY_ESCAPE
;
1522 vty_backward_word (vty
);
1523 vty
->escape
= VTY_NORMAL
;
1526 vty_forward_word (vty
);
1527 vty
->escape
= VTY_NORMAL
;
1530 vty_forward_kill_word (vty
);
1531 vty
->escape
= VTY_NORMAL
;
1535 vty_backward_kill_word (vty
);
1536 vty
->escape
= VTY_NORMAL
;
1539 vty
->escape
= VTY_NORMAL
;
1548 vty_beginning_of_line (vty
);
1551 vty_backward_char (vty
);
1554 vty_stop_input (vty
);
1557 vty_delete_char (vty
);
1560 vty_end_of_line (vty
);
1563 vty_forward_char (vty
);
1567 vty_delete_backward_char (vty
);
1570 vty_kill_line (vty
);
1573 vty_next_line (vty
);
1576 vty_previous_line (vty
);
1579 vty_transpose_chars (vty
);
1582 vty_kill_line_from_beginning (vty
);
1585 vty_backward_kill_word (vty
);
1588 vty_end_config (vty
);
1592 vty_out (vty
, "%s", VTY_NEWLINE
);
1596 vty_complete_command (vty
);
1599 if (vty
->node
== AUTH_NODE
|| vty
->node
== AUTH_ENABLE_NODE
)
1600 vty_self_insert (vty
, buf
[i
]);
1602 vty_describe_command (vty
);
1605 if (i
+ 1 < nbytes
&& buf
[i
+ 1] == '[')
1607 vty
->escape
= VTY_ESCAPE
;
1611 vty
->escape
= VTY_PRE_ESCAPE
;
1614 if (buf
[i
] > 31 && buf
[i
] < 127)
1615 vty_self_insert (vty
, buf
[i
]);
1621 if (vty
->status
== VTY_CLOSE
)
1625 vty_event (VTY_WRITE
, vty
->wfd
, vty
);
1626 vty_event (VTY_READ
, vty_sock
, vty
);
1631 /* Flush buffer to the vty. */
1633 vty_flush (struct thread
*thread
)
1636 buffer_status_t flushrc
;
1637 int vty_sock
= THREAD_FD (thread
);
1638 struct vty
*vty
= THREAD_ARG (thread
);
1640 vty
->t_write
= NULL
;
1642 /* Tempolary disable read thread. */
1643 if ((vty
->lines
== 0) && vty
->t_read
)
1645 thread_cancel (vty
->t_read
);
1649 /* Function execution continue. */
1650 erase
= ((vty
->status
== VTY_MORE
|| vty
->status
== VTY_MORELINE
));
1652 /* N.B. if width is 0, that means we don't know the window size. */
1653 if ((vty
->lines
== 0) || (vty
->width
== 0) || (vty
->height
== 0))
1654 flushrc
= buffer_flush_available(vty
->obuf
, vty_sock
);
1655 else if (vty
->status
== VTY_MORELINE
)
1656 flushrc
= buffer_flush_window(vty
->obuf
, vty_sock
, vty
->width
,
1659 flushrc
= buffer_flush_window(vty
->obuf
, vty_sock
, vty
->width
,
1660 vty
->lines
>= 0 ? vty
->lines
:
1666 vty
->monitor
= 0; /* disable monitoring to avoid infinite recursion */
1667 zlog_warn("buffer_flush failed on vty client fd %d, closing",
1669 buffer_reset(vty
->obuf
);
1673 if (vty
->status
== VTY_CLOSE
)
1677 vty
->status
= VTY_NORMAL
;
1678 if (vty
->lines
== 0)
1679 vty_event (VTY_READ
, vty_sock
, vty
);
1682 case BUFFER_PENDING
:
1683 /* There is more data waiting to be written. */
1684 vty
->status
= VTY_MORE
;
1685 if (vty
->lines
== 0)
1686 vty_event (VTY_WRITE
, vty_sock
, vty
);
1693 /* allocate and initialise vty */
1695 vty_new_init (int vty_sock
)
1701 vty
->wfd
= vty_sock
;
1702 vty
->type
= VTY_TERM
;
1703 vty
->node
= AUTH_NODE
;
1706 vty_clear_buf (vty
);
1708 memset (vty
->hist
, 0, sizeof (vty
->hist
));
1711 vector_set_index (vtyvec
, vty_sock
, vty
);
1712 vty
->status
= VTY_NORMAL
;
1715 vty
->iac_sb_in_progress
= 0;
1721 /* Create new vty structure. */
1723 vty_create (int vty_sock
, union sockunion
*su
)
1725 char buf
[SU_ADDRSTRLEN
];
1728 sockunion2str(su
, buf
, SU_ADDRSTRLEN
);
1730 /* Allocate new vty structure and set up default values. */
1731 vty
= vty_new_init (vty_sock
);
1733 /* configurable parameters not part of basic init */
1734 vty
->v_timeout
= vty_timeout_val
;
1735 strcpy (vty
->address
, buf
);
1736 if (no_password_check
)
1739 vty
->node
= ENABLE_NODE
;
1741 vty
->node
= VIEW_NODE
;
1743 if (host
.lines
>= 0)
1744 vty
->lines
= host
.lines
;
1746 if (! no_password_check
)
1748 /* Vty is not available if password isn't set. */
1749 if (host
.password
== NULL
&& host
.password_encrypt
== NULL
)
1751 vty_out (vty
, "Vty password is not set.%s", VTY_NEWLINE
);
1752 vty
->status
= VTY_CLOSE
;
1758 /* Say hello to the world. */
1760 if (! no_password_check
)
1761 vty_out (vty
, "%sUser Access Verification%s%s", VTY_NEWLINE
, VTY_NEWLINE
, VTY_NEWLINE
);
1763 /* Setting up terminal. */
1764 vty_will_echo (vty
);
1765 vty_will_suppress_go_ahead (vty
);
1767 vty_dont_linemode (vty
);
1768 vty_do_window_size (vty
);
1769 /* vty_dont_lflow_ahead (vty); */
1773 /* Add read/write thread. */
1774 vty_event (VTY_WRITE
, vty_sock
, vty
);
1775 vty_event (VTY_READ
, vty_sock
, vty
);
1780 /* create vty for stdio */
1781 static struct termios stdio_orig_termios
;
1782 static struct vty
*stdio_vty
= NULL
;
1783 static void (*stdio_vty_atclose
)(void);
1786 vty_stdio_reset (void)
1790 tcsetattr (0, TCSANOW
, &stdio_orig_termios
);
1793 if (stdio_vty_atclose
)
1794 stdio_vty_atclose ();
1795 stdio_vty_atclose
= NULL
;
1800 vty_stdio (void (*atclose
)())
1803 struct termios termios
;
1805 /* refuse creating two vtys on stdio */
1809 vty
= stdio_vty
= vty_new_init (0);
1810 stdio_vty_atclose
= atclose
;
1813 /* always have stdio vty in a known _unchangeable_ state, don't want config
1814 * to have any effect here to make sure scripting this works as intended */
1815 vty
->node
= ENABLE_NODE
;
1817 strcpy (vty
->address
, "console");
1819 if (!tcgetattr (0, &stdio_orig_termios
))
1821 termios
= stdio_orig_termios
;
1822 termios
.c_iflag
&= ~(IGNBRK
| BRKINT
| PARMRK
| ISTRIP
1823 | INLCR
| IGNCR
| ICRNL
| IXON
);
1824 termios
.c_oflag
&= ~OPOST
;
1825 termios
.c_lflag
&= ~(ECHO
| ECHONL
| ICANON
| ISIG
| IEXTEN
);
1826 termios
.c_cflag
&= ~(CSIZE
| PARENB
);
1827 termios
.c_cflag
|= CS8
;
1828 tcsetattr (0, TCSANOW
, &termios
);
1833 /* Add read/write thread. */
1834 vty_event (VTY_WRITE
, 1, vty
);
1835 vty_event (VTY_READ
, 0, vty
);
1840 /* Accept connection from the network. */
1842 vty_accept (struct thread
*thread
)
1850 struct access_list
*acl
= NULL
;
1851 char buf
[SU_ADDRSTRLEN
];
1853 accept_sock
= THREAD_FD (thread
);
1855 /* We continue hearing vty socket. */
1856 vty_event (VTY_SERV
, accept_sock
, NULL
);
1858 memset (&su
, 0, sizeof (union sockunion
));
1860 /* We can handle IPv4 or IPv6 socket. */
1861 vty_sock
= sockunion_accept (accept_sock
, &su
);
1864 zlog_warn ("can't accept vty socket : %s", safe_strerror (errno
));
1867 set_nonblocking(vty_sock
);
1868 set_cloexec(vty_sock
);
1870 sockunion2hostprefix (&su
, &p
);
1872 /* VTY's accesslist apply. */
1873 if (p
.family
== AF_INET
&& vty_accesslist_name
)
1875 if ((acl
= access_list_lookup (AFI_IP
, vty_accesslist_name
)) &&
1876 (access_list_apply (acl
, &p
) == FILTER_DENY
))
1878 zlog_info ("Vty connection refused from %s",
1879 sockunion2str (&su
, buf
, SU_ADDRSTRLEN
));
1882 /* continue accepting connections */
1883 vty_event (VTY_SERV
, accept_sock
, NULL
);
1889 /* VTY's ipv6 accesslist apply. */
1890 if (p
.family
== AF_INET6
&& vty_ipv6_accesslist_name
)
1892 if ((acl
= access_list_lookup (AFI_IP6
, vty_ipv6_accesslist_name
)) &&
1893 (access_list_apply (acl
, &p
) == FILTER_DENY
))
1895 zlog_info ("Vty connection refused from %s",
1896 sockunion2str (&su
, buf
, SU_ADDRSTRLEN
));
1899 /* continue accepting connections */
1900 vty_event (VTY_SERV
, accept_sock
, NULL
);
1907 ret
= setsockopt (vty_sock
, IPPROTO_TCP
, TCP_NODELAY
,
1908 (char *) &on
, sizeof (on
));
1910 zlog_info ("can't set sockopt to vty_sock : %s",
1911 safe_strerror (errno
));
1913 zlog_info ("Vty connection from %s",
1914 sockunion2str (&su
, buf
, SU_ADDRSTRLEN
));
1916 vty_create (vty_sock
, &su
);
1922 vty_serv_sock_addrinfo (const char *hostname
, unsigned short port
)
1925 struct addrinfo req
;
1926 struct addrinfo
*ainfo
;
1927 struct addrinfo
*ainfo_save
;
1929 char port_str
[BUFSIZ
];
1931 memset (&req
, 0, sizeof (struct addrinfo
));
1932 req
.ai_flags
= AI_PASSIVE
;
1933 req
.ai_family
= AF_UNSPEC
;
1934 req
.ai_socktype
= SOCK_STREAM
;
1935 sprintf (port_str
, "%d", port
);
1936 port_str
[sizeof (port_str
) - 1] = '\0';
1938 ret
= getaddrinfo (hostname
, port_str
, &req
, &ainfo
);
1942 fprintf (stderr
, "getaddrinfo failed: %s\n", gai_strerror (ret
));
1950 if (ainfo
->ai_family
!= AF_INET
1951 && ainfo
->ai_family
!= AF_INET6
1955 sock
= socket (ainfo
->ai_family
, ainfo
->ai_socktype
, ainfo
->ai_protocol
);
1959 sockopt_v6only (ainfo
->ai_family
, sock
);
1960 sockopt_reuseaddr (sock
);
1961 sockopt_reuseport (sock
);
1964 ret
= bind (sock
, ainfo
->ai_addr
, ainfo
->ai_addrlen
);
1967 close (sock
); /* Avoid sd leak. */
1971 ret
= listen (sock
, 3);
1974 close (sock
); /* Avoid sd leak. */
1978 vty_event (VTY_SERV
, sock
, NULL
);
1980 while ((ainfo
= ainfo
->ai_next
) != NULL
);
1982 freeaddrinfo (ainfo_save
);
1986 /* For sockaddr_un. */
1989 /* VTY shell UNIX domain socket. */
1991 vty_serv_un (const char *path
)
1995 struct sockaddr_un serv
;
1997 struct zprivs_ids_t ids
;
1999 /* First of all, unlink existing socket */
2003 old_mask
= umask (0007);
2005 /* Make UNIX domain socket. */
2006 sock
= socket (AF_UNIX
, SOCK_STREAM
, 0);
2009 zlog_err("Cannot create unix stream socket: %s", safe_strerror(errno
));
2013 /* Make server socket. */
2014 memset (&serv
, 0, sizeof (struct sockaddr_un
));
2015 serv
.sun_family
= AF_UNIX
;
2016 strlcpy (serv
.sun_path
, path
, sizeof (serv
.sun_path
));
2017 #ifdef HAVE_STRUCT_SOCKADDR_UN_SUN_LEN
2018 len
= serv
.sun_len
= SUN_LEN(&serv
);
2020 len
= sizeof (serv
.sun_family
) + strlen (serv
.sun_path
);
2021 #endif /* HAVE_STRUCT_SOCKADDR_UN_SUN_LEN */
2025 ret
= bind (sock
, (struct sockaddr
*) &serv
, len
);
2028 zlog_err("Cannot bind path %s: %s", path
, safe_strerror(errno
));
2029 close (sock
); /* Avoid sd leak. */
2033 ret
= listen (sock
, 5);
2036 zlog_err("listen(fd %d) failed: %s", sock
, safe_strerror(errno
));
2037 close (sock
); /* Avoid sd leak. */
2043 zprivs_get_ids(&ids
);
2045 /* Hack: ids.gid_vty is actually a uint, but we stored -1 in it
2046 earlier for the case when we don't need to chown the file
2047 type casting it here to make a compare */
2048 if ((int)ids
.gid_vty
> 0)
2050 /* set group of socket */
2051 if ( chown (path
, -1, ids
.gid_vty
) )
2053 zlog_err ("vty_serv_un: could chown socket, %s",
2054 safe_strerror (errno
) );
2058 vty_event (VTYSH_SERV
, sock
, NULL
);
2061 /* #define VTYSH_DEBUG 1 */
2064 vtysh_accept (struct thread
*thread
)
2069 struct sockaddr_un client
;
2072 accept_sock
= THREAD_FD (thread
);
2074 vty_event (VTYSH_SERV
, accept_sock
, NULL
);
2076 memset (&client
, 0, sizeof (struct sockaddr_un
));
2077 client_len
= sizeof (struct sockaddr_un
);
2079 sock
= accept (accept_sock
, (struct sockaddr
*) &client
,
2080 (socklen_t
*) &client_len
);
2084 zlog_warn ("can't accept vty socket : %s", safe_strerror (errno
));
2088 if (set_nonblocking(sock
) < 0)
2090 zlog_warn ("vtysh_accept: could not set vty socket %d to non-blocking,"
2091 " %s, closing", sock
, safe_strerror (errno
));
2098 printf ("VTY shell accept\n");
2099 #endif /* VTYSH_DEBUG */
2104 vty
->type
= VTY_SHELL_SERV
;
2105 vty
->node
= VIEW_NODE
;
2107 vty_event (VTYSH_READ
, sock
, vty
);
2113 vtysh_flush(struct vty
*vty
)
2115 switch (buffer_flush_available(vty
->obuf
, vty
->wfd
))
2117 case BUFFER_PENDING
:
2118 vty_event(VTYSH_WRITE
, vty
->wfd
, vty
);
2121 vty
->monitor
= 0; /* disable monitoring to avoid infinite recursion */
2122 zlog_warn("%s: write error to fd %d, closing", __func__
, vty
->fd
);
2123 buffer_reset(vty
->obuf
);
2134 vtysh_read (struct thread
*thread
)
2140 unsigned char buf
[VTY_READ_BUFSIZ
];
2142 u_char header
[4] = {0, 0, 0, 0};
2144 sock
= THREAD_FD (thread
);
2145 vty
= THREAD_ARG (thread
);
2148 if ((nbytes
= read (sock
, buf
, VTY_READ_BUFSIZ
)) <= 0)
2152 if (ERRNO_IO_RETRY(errno
))
2154 vty_event (VTYSH_READ
, sock
, vty
);
2157 vty
->monitor
= 0; /* disable monitoring to avoid infinite recursion */
2158 zlog_warn("%s: read failed on vtysh client fd %d, closing: %s",
2159 __func__
, sock
, safe_strerror(errno
));
2161 buffer_reset(vty
->obuf
);
2164 printf ("close vtysh\n");
2165 #endif /* VTYSH_DEBUG */
2170 printf ("line: %.*s\n", nbytes
, buf
);
2171 #endif /* VTYSH_DEBUG */
2173 if (vty
->length
+ nbytes
>= VTY_BUFSIZ
)
2175 /* Clear command line buffer. */
2176 vty
->cp
= vty
->length
= 0;
2177 vty_clear_buf (vty
);
2178 vty_out (vty
, "%% Command is too long.%s", VTY_NEWLINE
);
2182 for (p
= buf
; p
< buf
+nbytes
; p
++)
2184 vty
->buf
[vty
->length
++] = *p
;
2187 /* Pass this line to parser. */
2188 ret
= vty_execute (vty
);
2189 /* Note that vty_execute clears the command buffer and resets
2190 vty->length to 0. */
2192 /* Return result. */
2194 printf ("result: %d\n", ret
);
2195 printf ("vtysh node: %d\n", vty
->node
);
2196 #endif /* VTYSH_DEBUG */
2198 /* hack for asynchronous "write integrated"
2199 * - other commands in "buf" will be ditched
2200 * - input during pending config-write is "unsupported" */
2201 if (ret
== CMD_SUSPEND
)
2204 /* warning: watchquagga hardcodes this result write */
2206 buffer_put(vty
->obuf
, header
, 4);
2208 if (!vty
->t_write
&& (vtysh_flush(vty
) < 0))
2209 /* Try to flush results; exit if a write error occurs. */
2215 if (vty
->status
== VTY_CLOSE
)
2218 vty_event (VTYSH_READ
, sock
, vty
);
2224 vtysh_write (struct thread
*thread
)
2226 struct vty
*vty
= THREAD_ARG (thread
);
2228 vty
->t_write
= NULL
;
2235 /* Determine address family to bind. */
2237 vty_serv_sock (const char *addr
, unsigned short port
, const char *path
)
2239 /* If port is set to 0, do not listen on TCP/IP at all! */
2241 vty_serv_sock_addrinfo (addr
, port
);
2248 /* Close vty interface. Warning: call this only from functions that
2249 will be careful not to access the vty afterwards (since it has
2250 now been freed). This is safest from top-level functions (called
2251 directly by the thread dispatcher). */
2253 vty_close (struct vty
*vty
)
2256 bool was_stdio
= false;
2258 /* Cancel threads.*/
2260 thread_cancel (vty
->t_read
);
2262 thread_cancel (vty
->t_write
);
2264 thread_cancel (vty
->t_timeout
);
2267 buffer_flush_all (vty
->obuf
, vty
->wfd
);
2269 /* Free input buffer. */
2270 buffer_free (vty
->obuf
);
2272 /* Free command history. */
2273 for (i
= 0; i
< VTY_MAXHIST
; i
++)
2275 XFREE (MTYPE_VTY_HIST
, vty
->hist
[i
]);
2278 vector_unset (vtyvec
, vty
->fd
);
2280 if (vty
->wfd
> 0 && vty
->type
== VTY_FILE
)
2287 if (vty
->wfd
> 0 && vty
->wfd
!= vty
->fd
)
2294 XFREE (MTYPE_VTY
, vty
->buf
);
2297 XFREE (MTYPE_VTY
, vty
->error_buf
);
2299 /* Check configure. */
2300 vty_config_unlock (vty
);
2303 XFREE (MTYPE_VTY
, vty
);
2309 /* When time out occur output message then close connection. */
2311 vty_timeout (struct thread
*thread
)
2315 vty
= THREAD_ARG (thread
);
2316 vty
->t_timeout
= NULL
;
2320 buffer_reset (vty
->obuf
);
2321 vty_out (vty
, "%sVty connection is timed out.%s", VTY_NEWLINE
, VTY_NEWLINE
);
2323 /* Close connection. */
2324 vty
->status
= VTY_CLOSE
;
2330 /* Read up configuration file from file_name. */
2332 vty_read_file (FILE *confp
)
2336 unsigned int line_num
= 0;
2339 vty
->wfd
= dup(STDERR_FILENO
); /* vty_close() will close this */
2342 /* Fine, we couldn't make a new fd. vty_close doesn't close stdout. */
2343 vty
->wfd
= STDOUT_FILENO
;
2345 vty
->fd
= STDIN_FILENO
;
2346 vty
->type
= VTY_FILE
;
2347 vty
->node
= CONFIG_NODE
;
2349 /* Execute configuration file */
2350 ret
= config_from_file (vty
, confp
, &line_num
);
2352 /* Flush any previous errors before printing messages below */
2353 buffer_flush_all (vty
->obuf
, vty
->fd
);
2355 if ( !((ret
== CMD_SUCCESS
) || (ret
== CMD_ERR_NOTHING_TODO
)) )
2357 const char *message
= NULL
;
2360 case CMD_ERR_AMBIGUOUS
:
2361 message
= "*** Error reading config: Ambiguous command.";
2363 case CMD_ERR_NO_MATCH
:
2364 message
= "*** Error reading config: There is no such command.";
2367 fprintf (stderr
, "%s\n", message
);
2368 zlog_err ("%s", message
);
2369 fprintf (stderr
, "*** Error occurred processing line %u, below:\n%s\n",
2370 line_num
, vty
->error_buf
);
2371 zlog_err ("*** Error occurred processing line %u, below:\n%s",
2372 line_num
, vty
->error_buf
);
2379 vty_use_backup_config (const char *fullpath
)
2381 char *fullpath_sav
, *fullpath_tmp
;
2387 fullpath_sav
= malloc (strlen (fullpath
) + strlen (CONF_BACKUP_EXT
) + 1);
2388 strcpy (fullpath_sav
, fullpath
);
2389 strcat (fullpath_sav
, CONF_BACKUP_EXT
);
2391 sav
= open (fullpath_sav
, O_RDONLY
);
2394 free (fullpath_sav
);
2398 fullpath_tmp
= malloc (strlen (fullpath
) + 8);
2399 sprintf (fullpath_tmp
, "%s.XXXXXX", fullpath
);
2401 /* Open file to configuration write. */
2402 tmp
= mkstemp (fullpath_tmp
);
2406 if (fchmod (tmp
, CONFIGFILE_MASK
) != 0)
2409 while((c
= read (sav
, buffer
, 512)) > 0)
2411 if (write (tmp
, buffer
, c
) <= 0)
2417 if (rename (fullpath_tmp
, fullpath
) == 0)
2418 ret
= fopen (fullpath
, "r");
2420 unlink (fullpath_tmp
);
2426 unlink (fullpath_tmp
);
2431 free (fullpath_sav
);
2432 free (fullpath_tmp
);
2436 /* Read up configuration file from file_name. */
2438 vty_read_config (const char *config_file
,
2439 char *config_default_dir
)
2441 char cwd
[MAXPATHLEN
];
2443 const char *fullpath
;
2446 /* If -f flag specified. */
2447 if (config_file
!= NULL
)
2449 if (! IS_DIRECTORY_SEP (config_file
[0]))
2451 if (getcwd (cwd
, MAXPATHLEN
) == NULL
)
2453 fprintf (stderr
, "Failure to determine Current Working Directory %d!\n", errno
);
2456 tmp
= XMALLOC (MTYPE_TMP
,
2457 strlen (cwd
) + strlen (config_file
) + 2);
2458 sprintf (tmp
, "%s/%s", cwd
, config_file
);
2462 fullpath
= config_file
;
2464 confp
= fopen (fullpath
, "r");
2468 fprintf (stderr
, "%s: failed to open configuration file %s: %s\n",
2469 __func__
, fullpath
, safe_strerror (errno
));
2471 confp
= vty_use_backup_config (fullpath
);
2473 fprintf (stderr
, "WARNING: using backup configuration file!\n");
2476 fprintf (stderr
, "can't open configuration file [%s]\n",
2485 host_config_set (config_default_dir
);
2489 struct stat conf_stat
;
2491 /* !!!!PLEASE LEAVE!!!!
2492 * This is NEEDED for use with vtysh -b, or else you can get
2493 * a real configuration food fight with a lot garbage in the
2494 * merged configuration file it creates coming from the per
2495 * daemon configuration files. This also allows the daemons
2496 * to start if there default configuration file is not
2497 * present or ignore them, as needed when using vtysh -b to
2498 * configure the daemons at boot - MAG
2501 /* Stat for vtysh Zebra.conf, if found startup and wait for
2502 * boot configuration
2505 if ( strstr(config_default_dir
, "vtysh") == NULL
)
2507 ret
= stat (integrate_default
, &conf_stat
);
2509 goto tmp_free_and_out
;
2512 confp
= fopen (config_default_dir
, "r");
2515 fprintf (stderr
, "%s: failed to open configuration file %s: %s\n",
2516 __func__
, config_default_dir
, safe_strerror (errno
));
2518 confp
= vty_use_backup_config (config_default_dir
);
2521 fprintf (stderr
, "WARNING: using backup configuration file!\n");
2522 fullpath
= config_default_dir
;
2526 fprintf (stderr
, "can't open configuration file [%s]\n",
2527 config_default_dir
);
2528 goto tmp_free_and_out
;
2532 fullpath
= config_default_dir
;
2535 vty_read_file (confp
);
2539 host_config_set (fullpath
);
2543 XFREE (MTYPE_TMP
, tmp
);
2546 /* Small utility function which output log to the VTY. */
2548 vty_log (const char *level
, const char *proto_str
,
2549 const char *format
, struct timestamp_control
*ctl
, va_list va
)
2557 for (i
= 0; i
< vector_active (vtyvec
); i
++)
2558 if ((vty
= vector_slot (vtyvec
, i
)) != NULL
)
2563 vty_log_out (vty
, level
, proto_str
, format
, ctl
, ac
);
2568 /* Async-signal-safe version of vty_log for fixed strings. */
2570 vty_log_fixed (char *buf
, size_t len
)
2573 struct iovec iov
[2];
2574 char crlf
[4] = "\r\n";
2576 /* vty may not have been initialised */
2580 iov
[0].iov_base
= buf
;
2581 iov
[0].iov_len
= len
;
2582 iov
[1].iov_base
= crlf
;
2585 for (i
= 0; i
< vector_active (vtyvec
); i
++)
2588 if (((vty
= vector_slot (vtyvec
, i
)) != NULL
) && vty
->monitor
)
2589 /* N.B. We don't care about the return code, since process is
2590 most likely just about to die anyway. */
2591 if (writev(vty
->wfd
, iov
, 2) == -1)
2593 fprintf(stderr
, "Failure to writev: %d\n", errno
);
2600 vty_config_lock (struct vty
*vty
)
2602 if (vty_config_is_lockless
)
2604 if (vty_config
== 0)
2613 vty_config_unlock (struct vty
*vty
)
2615 if (vty_config_is_lockless
)
2617 if (vty_config
== 1 && vty
->config
== 1)
2626 vty_config_lockless (void)
2628 vty_config_is_lockless
= 1;
2631 /* Master of the threads. */
2632 static struct thread_master
*vty_master
;
2635 vty_event (enum event event
, int sock
, struct vty
*vty
)
2637 struct thread
*vty_serv_thread
= NULL
;
2642 vty_serv_thread
= thread_add_read(vty_master
, vty_accept
, vty
, sock
, NULL
);
2643 vector_set_index (Vvty_serv_thread
, sock
, vty_serv_thread
);
2647 vty_serv_thread
= thread_add_read(vty_master
, vtysh_accept
, vty
, sock
, NULL
);
2648 vector_set_index (Vvty_serv_thread
, sock
, vty_serv_thread
);
2652 thread_add_read(vty_master
, vtysh_read
, vty
, sock
, &vty
->t_read
);
2655 vty
->t_write
= NULL
;
2656 thread_add_write(vty_master
, vtysh_write
, vty
, sock
, &vty
->t_write
);
2661 thread_add_read(vty_master
, vty_read
, vty
, sock
, &vty
->t_read
);
2663 /* Time out treatment. */
2667 thread_cancel (vty
->t_timeout
);
2668 vty
->t_timeout
= NULL
;
2669 thread_add_timer(vty_master
, vty_timeout
, vty
, vty
->v_timeout
,
2674 thread_add_write(vty_master
, vty_flush
, vty
, sock
, &vty
->t_write
);
2676 case VTY_TIMEOUT_RESET
:
2679 thread_cancel (vty
->t_timeout
);
2680 vty
->t_timeout
= NULL
;
2684 vty
->t_timeout
= NULL
;
2685 thread_add_timer(vty_master
, vty_timeout
, vty
, vty
->v_timeout
,
2692 DEFUN_NOSH (config_who
,
2695 "Display who is on vty\n")
2700 for (i
= 0; i
< vector_active (vtyvec
); i
++)
2701 if ((v
= vector_slot (vtyvec
, i
)) != NULL
)
2702 vty_out (vty
, "%svty[%d] connected from %s.%s",
2703 v
->config
? "*" : " ",
2704 i
, v
->address
, VTY_NEWLINE
);
2708 /* Move to vty configuration mode. */
2709 DEFUN_NOSH (line_vty
,
2712 "Configure a terminal line\n"
2713 "Virtual terminal\n")
2715 vty
->node
= VTY_NODE
;
2719 /* Set time out value. */
2721 exec_timeout (struct vty
*vty
, const char *min_str
, const char *sec_str
)
2723 unsigned long timeout
= 0;
2725 /* min_str and sec_str are already checked by parser. So it must be
2726 all digit string. */
2729 timeout
= strtol (min_str
, NULL
, 10);
2733 timeout
+= strtol (sec_str
, NULL
, 10);
2735 vty_timeout_val
= timeout
;
2736 vty
->v_timeout
= timeout
;
2737 vty_event (VTY_TIMEOUT_RESET
, 0, vty
);
2743 DEFUN (exec_timeout_min
,
2744 exec_timeout_min_cmd
,
2745 "exec-timeout (0-35791)",
2746 "Set timeout value\n"
2747 "Timeout value in minutes\n")
2750 return exec_timeout (vty
, argv
[idx_number
]->arg
, NULL
);
2753 DEFUN (exec_timeout_sec
,
2754 exec_timeout_sec_cmd
,
2755 "exec-timeout (0-35791) (0-2147483)",
2756 "Set the EXEC timeout\n"
2757 "Timeout in minutes\n"
2758 "Timeout in seconds\n")
2761 int idx_number_2
= 2;
2762 return exec_timeout (vty
, argv
[idx_number
]->arg
, argv
[idx_number_2
]->arg
);
2765 DEFUN (no_exec_timeout
,
2766 no_exec_timeout_cmd
,
2769 "Set the EXEC timeout\n")
2771 return exec_timeout (vty
, NULL
, NULL
);
2774 /* Set vty access class. */
2775 DEFUN (vty_access_class
,
2776 vty_access_class_cmd
,
2777 "access-class WORD",
2778 "Filter connections based on an IP access list\n"
2782 if (vty_accesslist_name
)
2783 XFREE(MTYPE_VTY
, vty_accesslist_name
);
2785 vty_accesslist_name
= XSTRDUP(MTYPE_VTY
, argv
[idx_word
]->arg
);
2790 /* Clear vty access class. */
2791 DEFUN (no_vty_access_class
,
2792 no_vty_access_class_cmd
,
2793 "no access-class [WORD]",
2795 "Filter connections based on an IP access list\n"
2799 const char *accesslist
= (argc
== 3) ? argv
[idx_word
]->arg
: NULL
;
2800 if (! vty_accesslist_name
|| (argc
== 3 && strcmp(vty_accesslist_name
, accesslist
)))
2802 vty_out (vty
, "Access-class is not currently applied to vty%s",
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%s",
2851 XFREE(MTYPE_VTY
, vty_ipv6_accesslist_name
);
2853 vty_ipv6_accesslist_name
= NULL
;
2862 "Enable password checking\n")
2864 no_password_check
= 0;
2868 DEFUN (no_vty_login
,
2872 "Enable password checking\n")
2874 no_password_check
= 1;
2878 DEFUN (service_advanced_vty
,
2879 service_advanced_vty_cmd
,
2880 "service advanced-vty",
2881 "Set up miscellaneous service\n"
2882 "Enable advanced mode vty interface\n")
2888 DEFUN (no_service_advanced_vty
,
2889 no_service_advanced_vty_cmd
,
2890 "no service advanced-vty",
2892 "Set up miscellaneous service\n"
2893 "Enable advanced mode vty interface\n")
2899 DEFUN_NOSH (terminal_monitor
,
2900 terminal_monitor_cmd
,
2902 "Set terminal line parameters\n"
2903 "Copy debug output to the current terminal line\n")
2909 DEFUN_NOSH (terminal_no_monitor
,
2910 terminal_no_monitor_cmd
,
2911 "terminal no monitor",
2912 "Set terminal line parameters\n"
2914 "Copy debug output to the current terminal line\n")
2920 DEFUN_NOSH (no_terminal_monitor
,
2921 no_terminal_monitor_cmd
,
2922 "no terminal monitor",
2924 "Set terminal line parameters\n"
2925 "Copy debug output to the current terminal line\n")
2927 return terminal_no_monitor (self
, vty
, argc
, argv
);
2931 DEFUN_NOSH (show_history
,
2935 "Display the session command history\n")
2939 for (index
= vty
->hindex
+ 1; index
!= vty
->hindex
;)
2941 if (index
== VTY_MAXHIST
)
2947 if (vty
->hist
[index
] != NULL
)
2948 vty_out (vty
, " %s%s", vty
->hist
[index
], VTY_NEWLINE
);
2957 DEFUN (log_commands
,
2961 "Log all commands (can't be unset without restart)\n")
2963 do_log_commands
= 1;
2967 /* Display current configuration. */
2969 vty_config_write (struct vty
*vty
)
2971 vty_out (vty
, "line vty%s", VTY_NEWLINE
);
2973 if (vty_accesslist_name
)
2974 vty_out (vty
, " access-class %s%s",
2975 vty_accesslist_name
, VTY_NEWLINE
);
2977 if (vty_ipv6_accesslist_name
)
2978 vty_out (vty
, " ipv6 access-class %s%s",
2979 vty_ipv6_accesslist_name
, VTY_NEWLINE
);
2982 if (vty_timeout_val
!= VTY_TIMEOUT_DEFAULT
)
2983 vty_out (vty
, " exec-timeout %ld %ld%s",
2984 vty_timeout_val
/ 60,
2985 vty_timeout_val
% 60, VTY_NEWLINE
);
2988 if (no_password_check
)
2989 vty_out (vty
, " no login%s", VTY_NEWLINE
);
2991 if (do_log_commands
)
2992 vty_out (vty
, "log commands%s", VTY_NEWLINE
);
2994 vty_out (vty
, "!%s", VTY_NEWLINE
);
2999 struct cmd_node vty_node
=
3002 "%s(config-line)# ",
3006 /* Reset all VTY status. */
3012 struct thread
*vty_serv_thread
;
3014 for (i
= 0; i
< vector_active (vtyvec
); i
++)
3015 if ((vty
= vector_slot (vtyvec
, i
)) != NULL
)
3017 buffer_reset (vty
->obuf
);
3018 vty
->status
= VTY_CLOSE
;
3022 for (i
= 0; i
< vector_active (Vvty_serv_thread
); i
++)
3023 if ((vty_serv_thread
= vector_slot (Vvty_serv_thread
, i
)) != NULL
)
3025 thread_cancel (vty_serv_thread
);
3026 vector_slot (Vvty_serv_thread
, i
) = NULL
;
3030 vty_timeout_val
= VTY_TIMEOUT_DEFAULT
;
3032 if (vty_accesslist_name
)
3034 XFREE(MTYPE_VTY
, vty_accesslist_name
);
3035 vty_accesslist_name
= NULL
;
3038 if (vty_ipv6_accesslist_name
)
3040 XFREE(MTYPE_VTY
, vty_ipv6_accesslist_name
);
3041 vty_ipv6_accesslist_name
= NULL
;
3048 char cwd
[MAXPATHLEN
];
3051 c
= getcwd (cwd
, MAXPATHLEN
);
3056 * At this point if these go wrong, more than likely
3057 * the whole world is coming down around us
3058 * Hence not worrying about it too much.
3060 if (!chdir (SYSCONFDIR
))
3062 fprintf(stderr
, "Failure to chdir to %s, errno: %d\n", SYSCONFDIR
, errno
);
3065 if (getcwd (cwd
, MAXPATHLEN
) == NULL
)
3067 fprintf(stderr
, "Failure to getcwd, errno: %d\n", errno
);
3072 vty_cwd
= XMALLOC (MTYPE_TMP
, strlen (cwd
) + 1);
3073 strcpy (vty_cwd
, cwd
);
3083 vty_shell (struct vty
*vty
)
3085 return vty
->type
== VTY_SHELL
? 1 : 0;
3089 vty_shell_serv (struct vty
*vty
)
3091 return vty
->type
== VTY_SHELL_SERV
? 1 : 0;
3097 vtyvec
= vector_init (VECTOR_MIN_SIZE
);
3100 /* Install vty's own commands like `who' command. */
3102 vty_init (struct thread_master
*master_thread
)
3104 /* For further configuration read, preserve current directory. */
3107 vtyvec
= vector_init (VECTOR_MIN_SIZE
);
3109 vty_master
= master_thread
;
3111 atexit (vty_stdio_reset
);
3113 /* Initilize server thread vector. */
3114 Vvty_serv_thread
= vector_init (VECTOR_MIN_SIZE
);
3116 /* Install bgp top node. */
3117 install_node (&vty_node
, vty_config_write
);
3119 install_element (VIEW_NODE
, &config_who_cmd
);
3120 install_element (VIEW_NODE
, &show_history_cmd
);
3121 install_element (CONFIG_NODE
, &line_vty_cmd
);
3122 install_element (CONFIG_NODE
, &service_advanced_vty_cmd
);
3123 install_element (CONFIG_NODE
, &no_service_advanced_vty_cmd
);
3124 install_element (CONFIG_NODE
, &show_history_cmd
);
3125 install_element (CONFIG_NODE
, &log_commands_cmd
);
3126 install_element (ENABLE_NODE
, &terminal_monitor_cmd
);
3127 install_element (ENABLE_NODE
, &terminal_no_monitor_cmd
);
3128 install_element (ENABLE_NODE
, &no_terminal_monitor_cmd
);
3130 install_default (VTY_NODE
);
3131 install_element (VTY_NODE
, &exec_timeout_min_cmd
);
3132 install_element (VTY_NODE
, &exec_timeout_sec_cmd
);
3133 install_element (VTY_NODE
, &no_exec_timeout_cmd
);
3134 install_element (VTY_NODE
, &vty_access_class_cmd
);
3135 install_element (VTY_NODE
, &no_vty_access_class_cmd
);
3136 install_element (VTY_NODE
, &vty_login_cmd
);
3137 install_element (VTY_NODE
, &no_vty_login_cmd
);
3138 install_element (VTY_NODE
, &vty_ipv6_access_class_cmd
);
3139 install_element (VTY_NODE
, &no_vty_ipv6_access_class_cmd
);
3143 vty_terminate (void)
3146 XFREE (MTYPE_TMP
, vty_cwd
);
3148 if (vtyvec
&& Vvty_serv_thread
)
3151 vector_free (vtyvec
);
3152 vector_free (Vvty_serv_thread
);
3154 Vvty_serv_thread
= NULL
;