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
18 * along with GNU Zebra; see the file COPYING. If not, write to the Free
19 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
28 #include <lib/version.h>
30 #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 (NULL
, LOG_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(NULL
, LOG_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 */
461 protocolname
= zlog_proto_names
[zlog_default
->protocol
];
463 protocolname
= zlog_proto_names
[ZLOG_NONE
];
465 #ifdef CONSUMED_TIME_CHECK
467 if ((realtime
= thread_consumed_time(&after
, &before
, &cputime
)) >
469 /* Warn about CPU hog that must be fixed. */
470 zlog_warn("SLOW COMMAND: command took %lums (cpu time %lums): %s",
471 realtime
/1000, cputime
/1000, buf
);
473 #endif /* CONSUMED_TIME_CHECK */
475 if (ret
!= CMD_SUCCESS
)
479 if (vty
->type
== VTY_FILE
)
480 vty_out (vty
, "Warning...%s", VTY_NEWLINE
);
482 case CMD_ERR_AMBIGUOUS
:
483 vty_out (vty
, "%% Ambiguous command.%s", VTY_NEWLINE
);
485 case CMD_ERR_NO_MATCH
:
486 vty_out (vty
, "%% [%s] Unknown command: %s%s", protocolname
, buf
, VTY_NEWLINE
);
488 case CMD_ERR_INCOMPLETE
:
489 vty_out (vty
, "%% Command incomplete.%s", VTY_NEWLINE
);
492 cmd_free_strvec (vline
);
497 static const char telnet_backward_char
= 0x08;
498 static const char telnet_space_char
= ' ';
500 /* Basic function to write buffer to vty. */
502 vty_write (struct vty
*vty
, const char *buf
, size_t nbytes
)
504 if ((vty
->node
== AUTH_NODE
) || (vty
->node
== AUTH_ENABLE_NODE
))
507 /* Should we do buffering here ? And make vty_flush (vty) ? */
508 buffer_put (vty
->obuf
, buf
, nbytes
);
511 /* Basic function to insert character into vty. */
513 vty_self_insert (struct vty
*vty
, char c
)
518 if (vty
->length
+ 1 >= VTY_BUFSIZ
)
521 length
= vty
->length
- vty
->cp
;
522 memmove (&vty
->buf
[vty
->cp
+ 1], &vty
->buf
[vty
->cp
], length
);
523 vty
->buf
[vty
->cp
] = c
;
525 vty_write (vty
, &vty
->buf
[vty
->cp
], length
+ 1);
526 for (i
= 0; i
< length
; i
++)
527 vty_write (vty
, &telnet_backward_char
, 1);
532 vty
->buf
[vty
->length
] = '\0';
535 /* Self insert character 'c' in overwrite mode. */
537 vty_self_insert_overwrite (struct vty
*vty
, char c
)
539 if (vty
->cp
== vty
->length
)
541 vty_self_insert (vty
, c
);
545 vty
->buf
[vty
->cp
++] = c
;
546 vty_write (vty
, &c
, 1);
550 * Insert a string into vty->buf at the current cursor position.
552 * If the resultant string would be larger than VTY_BUFSIZ it is
556 vty_insert_word_overwrite (struct vty
*vty
, char *str
)
558 if (vty
->cp
== VTY_BUFSIZ
)
561 size_t nwrite
= MIN ((int) strlen (str
), VTY_BUFSIZ
- vty
->cp
- 1);
562 memcpy (&vty
->buf
[vty
->cp
], str
, nwrite
);
564 vty
->length
= MAX (vty
->cp
, vty
->length
);
565 vty
->buf
[vty
->length
] = '\0';
566 vty_write (vty
, str
, nwrite
);
569 /* Forward character. */
571 vty_forward_char (struct vty
*vty
)
573 if (vty
->cp
< vty
->length
)
575 vty_write (vty
, &vty
->buf
[vty
->cp
], 1);
580 /* Backward character. */
582 vty_backward_char (struct vty
*vty
)
587 vty_write (vty
, &telnet_backward_char
, 1);
591 /* Move to the beginning of the line. */
593 vty_beginning_of_line (struct vty
*vty
)
596 vty_backward_char (vty
);
599 /* Move to the end of the line. */
601 vty_end_of_line (struct vty
*vty
)
603 while (vty
->cp
< vty
->length
)
604 vty_forward_char (vty
);
607 static void vty_kill_line_from_beginning (struct vty
*);
608 static void vty_redraw_line (struct vty
*);
610 /* Print command line history. This function is called from
611 vty_next_line and vty_previous_line. */
613 vty_history_print (struct vty
*vty
)
617 vty_kill_line_from_beginning (vty
);
619 /* Get previous line from history buffer */
620 length
= strlen (vty
->hist
[vty
->hp
]);
621 memcpy (vty
->buf
, vty
->hist
[vty
->hp
], length
);
622 vty
->cp
= vty
->length
= length
;
623 vty
->buf
[vty
->length
] = '\0';
625 /* Redraw current line */
626 vty_redraw_line (vty
);
629 /* Show next command line history. */
631 vty_next_line (struct vty
*vty
)
635 if (vty
->hp
== vty
->hindex
)
638 /* Try is there history exist or not. */
640 if (try_index
== (VTY_MAXHIST
- 1))
645 /* If there is not history return. */
646 if (vty
->hist
[try_index
] == NULL
)
651 vty_history_print (vty
);
654 /* Show previous command line history. */
656 vty_previous_line (struct vty
*vty
)
662 try_index
= VTY_MAXHIST
- 1;
666 if (vty
->hist
[try_index
] == NULL
)
671 vty_history_print (vty
);
674 /* This function redraw all of the command line character. */
676 vty_redraw_line (struct vty
*vty
)
678 vty_write (vty
, vty
->buf
, vty
->length
);
679 vty
->cp
= vty
->length
;
684 vty_forward_word (struct vty
*vty
)
686 while (vty
->cp
!= vty
->length
&& vty
->buf
[vty
->cp
] != ' ')
687 vty_forward_char (vty
);
689 while (vty
->cp
!= vty
->length
&& vty
->buf
[vty
->cp
] == ' ')
690 vty_forward_char (vty
);
693 /* Backward word without skipping training space. */
695 vty_backward_pure_word (struct vty
*vty
)
697 while (vty
->cp
> 0 && vty
->buf
[vty
->cp
- 1] != ' ')
698 vty_backward_char (vty
);
703 vty_backward_word (struct vty
*vty
)
705 while (vty
->cp
> 0 && vty
->buf
[vty
->cp
- 1] == ' ')
706 vty_backward_char (vty
);
708 while (vty
->cp
> 0 && vty
->buf
[vty
->cp
- 1] != ' ')
709 vty_backward_char (vty
);
712 /* When '^D' is typed at the beginning of the line we move to the down
715 vty_down_level (struct vty
*vty
)
717 vty_out (vty
, "%s", VTY_NEWLINE
);
723 /* When '^Z' is received from vty, move down to the enable mode. */
725 vty_end_config (struct vty
*vty
)
727 vty_out (vty
, "%s", VTY_NEWLINE
);
744 case BGP_ENCAPV6_NODE
:
745 case BGP_VRF_POLICY_NODE
:
746 case BGP_VNC_DEFAULTS_NODE
:
747 case BGP_VNC_NVE_GROUP_NODE
:
748 case BGP_VNC_L2_GROUP_NODE
:
759 case LDP_IPV4_IFACE_NODE
:
760 case LDP_IPV6_IFACE_NODE
:
762 case LDP_PSEUDOWIRE_NODE
:
765 case KEYCHAIN_KEY_NODE
:
769 vty_config_unlock (vty
);
770 vty
->node
= ENABLE_NODE
;
773 /* Unknown node, we have to ignore it. */
781 /* Delete a charcter at the current point. */
783 vty_delete_char (struct vty
*vty
)
788 if (vty
->length
== 0)
790 vty_down_level (vty
);
794 if (vty
->cp
== vty
->length
)
795 return; /* completion need here? */
797 size
= vty
->length
- vty
->cp
;
800 memmove (&vty
->buf
[vty
->cp
], &vty
->buf
[vty
->cp
+ 1], size
- 1);
801 vty
->buf
[vty
->length
] = '\0';
803 if (vty
->node
== AUTH_NODE
|| vty
->node
== AUTH_ENABLE_NODE
)
806 vty_write (vty
, &vty
->buf
[vty
->cp
], size
- 1);
807 vty_write (vty
, &telnet_space_char
, 1);
809 for (i
= 0; i
< size
; i
++)
810 vty_write (vty
, &telnet_backward_char
, 1);
813 /* Delete a character before the point. */
815 vty_delete_backward_char (struct vty
*vty
)
820 vty_backward_char (vty
);
821 vty_delete_char (vty
);
824 /* Kill rest of line from current point. */
826 vty_kill_line (struct vty
*vty
)
831 size
= vty
->length
- vty
->cp
;
836 for (i
= 0; i
< size
; i
++)
837 vty_write (vty
, &telnet_space_char
, 1);
838 for (i
= 0; i
< size
; i
++)
839 vty_write (vty
, &telnet_backward_char
, 1);
841 memset (&vty
->buf
[vty
->cp
], 0, size
);
842 vty
->length
= vty
->cp
;
845 /* Kill line from the beginning. */
847 vty_kill_line_from_beginning (struct vty
*vty
)
849 vty_beginning_of_line (vty
);
853 /* Delete a word before the point. */
855 vty_forward_kill_word (struct vty
*vty
)
857 while (vty
->cp
!= vty
->length
&& vty
->buf
[vty
->cp
] == ' ')
858 vty_delete_char (vty
);
859 while (vty
->cp
!= vty
->length
&& vty
->buf
[vty
->cp
] != ' ')
860 vty_delete_char (vty
);
863 /* Delete a word before the point. */
865 vty_backward_kill_word (struct vty
*vty
)
867 while (vty
->cp
> 0 && vty
->buf
[vty
->cp
- 1] == ' ')
868 vty_delete_backward_char (vty
);
869 while (vty
->cp
> 0 && vty
->buf
[vty
->cp
- 1] != ' ')
870 vty_delete_backward_char (vty
);
873 /* Transpose chars before or at the point. */
875 vty_transpose_chars (struct vty
*vty
)
879 /* If length is short or point is near by the beginning of line then
881 if (vty
->length
< 2 || vty
->cp
< 1)
884 /* In case of point is located at the end of the line. */
885 if (vty
->cp
== vty
->length
)
887 c1
= vty
->buf
[vty
->cp
- 1];
888 c2
= vty
->buf
[vty
->cp
- 2];
890 vty_backward_char (vty
);
891 vty_backward_char (vty
);
892 vty_self_insert_overwrite (vty
, c1
);
893 vty_self_insert_overwrite (vty
, c2
);
897 c1
= vty
->buf
[vty
->cp
];
898 c2
= vty
->buf
[vty
->cp
- 1];
900 vty_backward_char (vty
);
901 vty_self_insert_overwrite (vty
, c1
);
902 vty_self_insert_overwrite (vty
, c2
);
906 /* Do completion at vty interface. */
908 vty_complete_command (struct vty
*vty
)
912 char **matched
= NULL
;
915 if (vty
->node
== AUTH_NODE
|| vty
->node
== AUTH_ENABLE_NODE
)
918 vline
= cmd_make_strvec (vty
->buf
);
922 /* In case of 'help \t'. */
923 if (isspace ((int) vty
->buf
[vty
->length
- 1]))
924 vector_set (vline
, NULL
);
926 matched
= cmd_complete_command (vline
, vty
, &ret
);
928 cmd_free_strvec (vline
);
930 vty_out (vty
, "%s", VTY_NEWLINE
);
933 case CMD_ERR_AMBIGUOUS
:
934 vty_out (vty
, "%% Ambiguous command.%s", VTY_NEWLINE
);
936 vty_redraw_line (vty
);
938 case CMD_ERR_NO_MATCH
:
939 /* vty_out (vty, "%% There is no matched command.%s", VTY_NEWLINE); */
941 vty_redraw_line (vty
);
943 case CMD_COMPLETE_FULL_MATCH
:
946 /* 2016-11-28 equinox -- need to debug, SEGV here */
947 vty_out (vty
, "%% CLI BUG: FULL_MATCH with NULL str%s", VTY_NEWLINE
);
949 vty_redraw_line (vty
);
953 vty_redraw_line (vty
);
954 vty_backward_pure_word (vty
);
955 vty_insert_word_overwrite (vty
, matched
[0]);
956 vty_self_insert (vty
, ' ');
957 XFREE (MTYPE_TMP
, matched
[0]);
959 case CMD_COMPLETE_MATCH
:
961 vty_redraw_line (vty
);
962 vty_backward_pure_word (vty
);
963 vty_insert_word_overwrite (vty
, matched
[0]);
964 XFREE (MTYPE_TMP
, matched
[0]);
966 case CMD_COMPLETE_LIST_MATCH
:
967 for (i
= 0; matched
[i
] != NULL
; i
++)
969 if (i
!= 0 && ((i
% 6) == 0))
970 vty_out (vty
, "%s", VTY_NEWLINE
);
971 vty_out (vty
, "%-10s ", matched
[i
]);
972 XFREE (MTYPE_TMP
, matched
[i
]);
974 vty_out (vty
, "%s", VTY_NEWLINE
);
977 vty_redraw_line (vty
);
979 case CMD_ERR_NOTHING_TODO
:
981 vty_redraw_line (vty
);
987 XFREE (MTYPE_TMP
, matched
);
991 vty_describe_fold (struct vty
*vty
, int cmd_width
,
992 unsigned int desc_width
, struct cmd_token
*token
)
1000 if (desc_width
<= 0)
1002 vty_out (vty
, " %-*s %s%s", cmd_width
, cmd
, token
->desc
, VTY_NEWLINE
);
1006 buf
= XCALLOC (MTYPE_TMP
, strlen (token
->desc
) + 1);
1008 for (p
= token
->desc
; strlen (p
) > desc_width
; p
+= pos
+ 1)
1010 for (pos
= desc_width
; pos
> 0; pos
--)
1011 if (*(p
+ pos
) == ' ')
1017 strncpy (buf
, p
, pos
);
1019 vty_out (vty
, " %-*s %s%s", cmd_width
, cmd
, buf
, VTY_NEWLINE
);
1024 vty_out (vty
, " %-*s %s%s", cmd_width
, cmd
, p
, VTY_NEWLINE
);
1026 XFREE (MTYPE_TMP
, buf
);
1029 /* Describe matched command function. */
1031 vty_describe_command (struct vty
*vty
)
1036 unsigned int i
, width
, desc_width
;
1037 struct cmd_token
*token
, *token_cr
= NULL
;
1039 vline
= cmd_make_strvec (vty
->buf
);
1041 /* In case of '> ?'. */
1044 vline
= vector_init (1);
1045 vector_set (vline
, NULL
);
1048 if (isspace ((int) vty
->buf
[vty
->length
- 1]))
1049 vector_set (vline
, NULL
);
1051 describe
= cmd_describe_command (vline
, vty
, &ret
);
1053 vty_out (vty
, "%s", VTY_NEWLINE
);
1055 /* Ambiguous error. */
1058 case CMD_ERR_AMBIGUOUS
:
1059 vty_out (vty
, "%% Ambiguous command.%s", VTY_NEWLINE
);
1062 case CMD_ERR_NO_MATCH
:
1063 vty_out (vty
, "%% There is no matched command.%s", VTY_NEWLINE
);
1068 /* Get width of command string. */
1070 for (i
= 0; i
< vector_active (describe
); i
++)
1071 if ((token
= vector_slot (describe
, i
)) != NULL
)
1075 if (token
->text
[0] == '\0')
1078 len
= strlen (token
->text
);
1084 /* Get width of description string. */
1085 desc_width
= vty
->width
- (width
+ 6);
1087 /* Print out description. */
1088 for (i
= 0; i
< vector_active (describe
); i
++)
1089 if ((token
= vector_slot (describe
, i
)) != NULL
)
1091 if (token
->text
[0] == '\0')
1094 if (strcmp (token
->text
, CMD_CR_TEXT
) == 0)
1101 vty_out (vty
, " %-s%s",
1104 else if (desc_width
>= strlen (token
->desc
))
1105 vty_out (vty
, " %-*s %s%s", width
,
1107 token
->desc
, VTY_NEWLINE
);
1109 vty_describe_fold (vty
, width
, desc_width
, token
);
1112 vty_out (vty
, " %-*s %s%s", width
1113 desc
->cmd
[0] == '.' ? desc
->cmd
+ 1 : desc
->cmd
,
1114 desc
->str
? desc
->str
: "", VTY_NEWLINE
);
1118 if ((token
= token_cr
))
1121 vty_out (vty
, " %-s%s",
1124 else if (desc_width
>= strlen (token
->desc
))
1125 vty_out (vty
, " %-*s %s%s", width
,
1127 token
->desc
, VTY_NEWLINE
);
1129 vty_describe_fold (vty
, width
, desc_width
, token
);
1133 cmd_free_strvec (vline
);
1135 vector_free (describe
);
1138 vty_redraw_line (vty
);
1142 vty_clear_buf (struct vty
*vty
)
1144 memset (vty
->buf
, 0, vty
->max
);
1147 /* ^C stop current input and do not add command line to the history. */
1149 vty_stop_input (struct vty
*vty
)
1151 vty
->cp
= vty
->length
= 0;
1152 vty_clear_buf (vty
);
1153 vty_out (vty
, "%s", VTY_NEWLINE
);
1159 /* Nothing to do. */
1162 case INTERFACE_NODE
:
1173 case LDP_IPV4_IFACE_NODE
:
1174 case LDP_IPV6_IFACE_NODE
:
1175 case LDP_L2VPN_NODE
:
1176 case LDP_PSEUDOWIRE_NODE
:
1179 case KEYCHAIN_KEY_NODE
:
1183 vty_config_unlock (vty
);
1184 vty
->node
= ENABLE_NODE
;
1187 /* Unknown node, we have to ignore it. */
1192 /* Set history pointer to the latest one. */
1193 vty
->hp
= vty
->hindex
;
1196 /* Add current command line to the history buffer. */
1198 vty_hist_add (struct vty
*vty
)
1202 if (vty
->length
== 0)
1205 index
= vty
->hindex
? vty
->hindex
- 1 : VTY_MAXHIST
- 1;
1207 /* Ignore the same string as previous one. */
1208 if (vty
->hist
[index
])
1209 if (strcmp (vty
->buf
, vty
->hist
[index
]) == 0)
1211 vty
->hp
= vty
->hindex
;
1215 /* Insert history entry. */
1216 if (vty
->hist
[vty
->hindex
])
1217 XFREE (MTYPE_VTY_HIST
, vty
->hist
[vty
->hindex
]);
1218 vty
->hist
[vty
->hindex
] = XSTRDUP (MTYPE_VTY_HIST
, vty
->buf
);
1220 /* History index rotation. */
1222 if (vty
->hindex
== VTY_MAXHIST
)
1225 vty
->hp
= vty
->hindex
;
1228 /* #define TELNET_OPTION_DEBUG */
1230 /* Get telnet window size. */
1232 vty_telnet_option (struct vty
*vty
, unsigned char *buf
, int nbytes
)
1234 #ifdef TELNET_OPTION_DEBUG
1237 for (i
= 0; i
< nbytes
; i
++)
1242 vty_out (vty
, "IAC ");
1245 vty_out (vty
, "WILL ");
1248 vty_out (vty
, "WONT ");
1251 vty_out (vty
, "DO ");
1254 vty_out (vty
, "DONT ");
1257 vty_out (vty
, "SB ");
1260 vty_out (vty
, "SE ");
1263 vty_out (vty
, "TELOPT_ECHO %s", VTY_NEWLINE
);
1266 vty_out (vty
, "TELOPT_SGA %s", VTY_NEWLINE
);
1269 vty_out (vty
, "TELOPT_NAWS %s", VTY_NEWLINE
);
1272 vty_out (vty
, "%x ", buf
[i
]);
1276 vty_out (vty
, "%s", VTY_NEWLINE
);
1278 #endif /* TELNET_OPTION_DEBUG */
1284 vty
->iac_sb_in_progress
= 1;
1289 if (!vty
->iac_sb_in_progress
)
1292 if ((vty
->sb_len
== 0) || (vty
->sb_buf
[0] == '\0'))
1294 vty
->iac_sb_in_progress
= 0;
1297 switch (vty
->sb_buf
[0])
1300 if (vty
->sb_len
!= TELNET_NAWS_SB_LEN
)
1301 zlog_warn("RFC 1073 violation detected: telnet NAWS option "
1302 "should send %d characters, but we received %lu",
1303 TELNET_NAWS_SB_LEN
, (u_long
)vty
->sb_len
);
1304 else if (sizeof(vty
->sb_buf
) < TELNET_NAWS_SB_LEN
)
1305 zlog_err("Bug detected: sizeof(vty->sb_buf) %lu < %d, "
1306 "too small to handle the telnet NAWS option",
1307 (u_long
)sizeof(vty
->sb_buf
), TELNET_NAWS_SB_LEN
);
1310 vty
->width
= ((vty
->sb_buf
[1] << 8)|vty
->sb_buf
[2]);
1311 vty
->height
= ((vty
->sb_buf
[3] << 8)|vty
->sb_buf
[4]);
1312 #ifdef TELNET_OPTION_DEBUG
1313 vty_out(vty
, "TELNET NAWS window size negotiation completed: "
1314 "width %d, height %d%s",
1315 vty
->width
, vty
->height
, VTY_NEWLINE
);
1320 vty
->iac_sb_in_progress
= 0;
1330 /* Execute current command line. */
1332 vty_execute (struct vty
*vty
)
1341 case AUTH_ENABLE_NODE
:
1342 vty_auth (vty
, vty
->buf
);
1345 ret
= vty_command (vty
, vty
->buf
);
1346 if (vty
->type
== VTY_TERM
)
1351 /* Clear command line buffer. */
1352 vty
->cp
= vty
->length
= 0;
1353 vty_clear_buf (vty
);
1355 if (vty
->status
!= VTY_CLOSE
)
1361 #define CONTROL(X) ((X) - '@')
1362 #define VTY_NORMAL 0
1363 #define VTY_PRE_ESCAPE 1
1364 #define VTY_ESCAPE 2
1366 /* Escape character command map. */
1368 vty_escape_map (unsigned char c
, struct vty
*vty
)
1373 vty_previous_line (vty
);
1376 vty_next_line (vty
);
1379 vty_forward_char (vty
);
1382 vty_backward_char (vty
);
1388 /* Go back to normal mode. */
1389 vty
->escape
= VTY_NORMAL
;
1392 /* Quit print out to the buffer. */
1394 vty_buffer_reset (struct vty
*vty
)
1396 buffer_reset (vty
->obuf
);
1398 vty_redraw_line (vty
);
1401 /* Read data via vty socket. */
1403 vty_read (struct thread
*thread
)
1407 unsigned char buf
[VTY_READ_BUFSIZ
];
1409 int vty_sock
= THREAD_FD (thread
);
1410 struct vty
*vty
= THREAD_ARG (thread
);
1413 /* Read raw data from socket */
1414 if ((nbytes
= read (vty
->fd
, buf
, VTY_READ_BUFSIZ
)) <= 0)
1418 if (ERRNO_IO_RETRY(errno
))
1420 vty_event (VTY_READ
, vty_sock
, vty
);
1423 vty
->monitor
= 0; /* disable monitoring to avoid infinite recursion */
1424 zlog_warn("%s: read error on vty client fd %d, closing: %s",
1425 __func__
, vty
->fd
, safe_strerror(errno
));
1426 buffer_reset(vty
->obuf
);
1428 vty
->status
= VTY_CLOSE
;
1431 for (i
= 0; i
< nbytes
; i
++)
1446 if (vty
->iac_sb_in_progress
&& !vty
->iac
)
1448 if (vty
->sb_len
< sizeof(vty
->sb_buf
))
1449 vty
->sb_buf
[vty
->sb_len
] = buf
[i
];
1456 /* In case of telnet command */
1458 ret
= vty_telnet_option (vty
, buf
+ i
, nbytes
- i
);
1465 if (vty
->status
== VTY_MORE
)
1472 vty_buffer_reset (vty
);
1474 #if 0 /* More line does not work for "show ip bgp". */
1477 vty
->status
= VTY_MORELINE
;
1486 /* Escape character. */
1487 if (vty
->escape
== VTY_ESCAPE
)
1489 vty_escape_map (buf
[i
], vty
);
1493 /* Pre-escape status. */
1494 if (vty
->escape
== VTY_PRE_ESCAPE
)
1499 vty
->escape
= VTY_ESCAPE
;
1502 vty_backward_word (vty
);
1503 vty
->escape
= VTY_NORMAL
;
1506 vty_forward_word (vty
);
1507 vty
->escape
= VTY_NORMAL
;
1510 vty_forward_kill_word (vty
);
1511 vty
->escape
= VTY_NORMAL
;
1515 vty_backward_kill_word (vty
);
1516 vty
->escape
= VTY_NORMAL
;
1519 vty
->escape
= VTY_NORMAL
;
1528 vty_beginning_of_line (vty
);
1531 vty_backward_char (vty
);
1534 vty_stop_input (vty
);
1537 vty_delete_char (vty
);
1540 vty_end_of_line (vty
);
1543 vty_forward_char (vty
);
1547 vty_delete_backward_char (vty
);
1550 vty_kill_line (vty
);
1553 vty_next_line (vty
);
1556 vty_previous_line (vty
);
1559 vty_transpose_chars (vty
);
1562 vty_kill_line_from_beginning (vty
);
1565 vty_backward_kill_word (vty
);
1568 vty_end_config (vty
);
1572 vty_out (vty
, "%s", VTY_NEWLINE
);
1576 vty_complete_command (vty
);
1579 if (vty
->node
== AUTH_NODE
|| vty
->node
== AUTH_ENABLE_NODE
)
1580 vty_self_insert (vty
, buf
[i
]);
1582 vty_describe_command (vty
);
1585 if (i
+ 1 < nbytes
&& buf
[i
+ 1] == '[')
1587 vty
->escape
= VTY_ESCAPE
;
1591 vty
->escape
= VTY_PRE_ESCAPE
;
1594 if (buf
[i
] > 31 && buf
[i
] < 127)
1595 vty_self_insert (vty
, buf
[i
]);
1601 if (vty
->status
== VTY_CLOSE
)
1605 vty_event (VTY_WRITE
, vty
->wfd
, vty
);
1606 vty_event (VTY_READ
, vty_sock
, vty
);
1611 /* Flush buffer to the vty. */
1613 vty_flush (struct thread
*thread
)
1616 buffer_status_t flushrc
;
1617 int vty_sock
= THREAD_FD (thread
);
1618 struct vty
*vty
= THREAD_ARG (thread
);
1620 vty
->t_write
= NULL
;
1622 /* Tempolary disable read thread. */
1623 if ((vty
->lines
== 0) && vty
->t_read
)
1625 thread_cancel (vty
->t_read
);
1629 /* Function execution continue. */
1630 erase
= ((vty
->status
== VTY_MORE
|| vty
->status
== VTY_MORELINE
));
1632 /* N.B. if width is 0, that means we don't know the window size. */
1633 if ((vty
->lines
== 0) || (vty
->width
== 0) || (vty
->height
== 0))
1634 flushrc
= buffer_flush_available(vty
->obuf
, vty_sock
);
1635 else if (vty
->status
== VTY_MORELINE
)
1636 flushrc
= buffer_flush_window(vty
->obuf
, vty_sock
, vty
->width
,
1639 flushrc
= buffer_flush_window(vty
->obuf
, vty_sock
, vty
->width
,
1640 vty
->lines
>= 0 ? vty
->lines
:
1646 vty
->monitor
= 0; /* disable monitoring to avoid infinite recursion */
1647 zlog_warn("buffer_flush failed on vty client fd %d, closing",
1649 buffer_reset(vty
->obuf
);
1653 if (vty
->status
== VTY_CLOSE
)
1657 vty
->status
= VTY_NORMAL
;
1658 if (vty
->lines
== 0)
1659 vty_event (VTY_READ
, vty_sock
, vty
);
1662 case BUFFER_PENDING
:
1663 /* There is more data waiting to be written. */
1664 vty
->status
= VTY_MORE
;
1665 if (vty
->lines
== 0)
1666 vty_event (VTY_WRITE
, vty_sock
, vty
);
1673 /* allocate and initialise vty */
1675 vty_new_init (int vty_sock
)
1681 vty
->wfd
= vty_sock
;
1682 vty
->type
= VTY_TERM
;
1683 vty
->node
= AUTH_NODE
;
1686 vty_clear_buf (vty
);
1688 memset (vty
->hist
, 0, sizeof (vty
->hist
));
1691 vector_set_index (vtyvec
, vty_sock
, vty
);
1692 vty
->status
= VTY_NORMAL
;
1695 vty
->iac_sb_in_progress
= 0;
1701 /* Create new vty structure. */
1703 vty_create (int vty_sock
, union sockunion
*su
)
1705 char buf
[SU_ADDRSTRLEN
];
1708 sockunion2str(su
, buf
, SU_ADDRSTRLEN
);
1710 /* Allocate new vty structure and set up default values. */
1711 vty
= vty_new_init (vty_sock
);
1713 /* configurable parameters not part of basic init */
1714 vty
->v_timeout
= vty_timeout_val
;
1715 strcpy (vty
->address
, buf
);
1716 if (no_password_check
)
1719 vty
->node
= ENABLE_NODE
;
1721 vty
->node
= VIEW_NODE
;
1723 if (host
.lines
>= 0)
1724 vty
->lines
= host
.lines
;
1726 if (! no_password_check
)
1728 /* Vty is not available if password isn't set. */
1729 if (host
.password
== NULL
&& host
.password_encrypt
== NULL
)
1731 vty_out (vty
, "Vty password is not set.%s", VTY_NEWLINE
);
1732 vty
->status
= VTY_CLOSE
;
1738 /* Say hello to the world. */
1740 if (! no_password_check
)
1741 vty_out (vty
, "%sUser Access Verification%s%s", VTY_NEWLINE
, VTY_NEWLINE
, VTY_NEWLINE
);
1743 /* Setting up terminal. */
1744 vty_will_echo (vty
);
1745 vty_will_suppress_go_ahead (vty
);
1747 vty_dont_linemode (vty
);
1748 vty_do_window_size (vty
);
1749 /* vty_dont_lflow_ahead (vty); */
1753 /* Add read/write thread. */
1754 vty_event (VTY_WRITE
, vty_sock
, vty
);
1755 vty_event (VTY_READ
, vty_sock
, vty
);
1760 /* create vty for stdio */
1761 static struct termios stdio_orig_termios
;
1762 static struct vty
*stdio_vty
= NULL
;
1763 static void (*stdio_vty_atclose
)(void);
1766 vty_stdio_reset (void)
1770 tcsetattr (0, TCSANOW
, &stdio_orig_termios
);
1773 if (stdio_vty_atclose
)
1774 stdio_vty_atclose ();
1775 stdio_vty_atclose
= NULL
;
1780 vty_stdio (void (*atclose
)())
1783 struct termios termios
;
1785 /* refuse creating two vtys on stdio */
1789 vty
= stdio_vty
= vty_new_init (0);
1790 stdio_vty_atclose
= atclose
;
1793 /* always have stdio vty in a known _unchangeable_ state, don't want config
1794 * to have any effect here to make sure scripting this works as intended */
1795 vty
->node
= ENABLE_NODE
;
1797 strcpy (vty
->address
, "console");
1799 if (!tcgetattr (0, &stdio_orig_termios
))
1801 termios
= stdio_orig_termios
;
1802 termios
.c_iflag
&= ~(IGNBRK
| BRKINT
| PARMRK
| ISTRIP
1803 | INLCR
| IGNCR
| ICRNL
| IXON
);
1804 termios
.c_oflag
&= ~OPOST
;
1805 termios
.c_lflag
&= ~(ECHO
| ECHONL
| ICANON
| ISIG
| IEXTEN
);
1806 termios
.c_cflag
&= ~(CSIZE
| PARENB
);
1807 termios
.c_cflag
|= CS8
;
1808 tcsetattr (0, TCSANOW
, &termios
);
1813 /* Add read/write thread. */
1814 vty_event (VTY_WRITE
, 1, vty
);
1815 vty_event (VTY_READ
, 0, vty
);
1820 /* Accept connection from the network. */
1822 vty_accept (struct thread
*thread
)
1830 struct access_list
*acl
= NULL
;
1831 char buf
[SU_ADDRSTRLEN
];
1833 accept_sock
= THREAD_FD (thread
);
1835 /* We continue hearing vty socket. */
1836 vty_event (VTY_SERV
, accept_sock
, NULL
);
1838 memset (&su
, 0, sizeof (union sockunion
));
1840 /* We can handle IPv4 or IPv6 socket. */
1841 vty_sock
= sockunion_accept (accept_sock
, &su
);
1844 zlog_warn ("can't accept vty socket : %s", safe_strerror (errno
));
1847 set_nonblocking(vty_sock
);
1848 set_cloexec(vty_sock
);
1850 sockunion2hostprefix (&su
, &p
);
1852 /* VTY's accesslist apply. */
1853 if (p
.family
== AF_INET
&& vty_accesslist_name
)
1855 if ((acl
= access_list_lookup (AFI_IP
, vty_accesslist_name
)) &&
1856 (access_list_apply (acl
, &p
) == FILTER_DENY
))
1858 zlog (NULL
, LOG_INFO
, "Vty connection refused from %s",
1859 sockunion2str (&su
, buf
, SU_ADDRSTRLEN
));
1862 /* continue accepting connections */
1863 vty_event (VTY_SERV
, accept_sock
, NULL
);
1869 /* VTY's ipv6 accesslist apply. */
1870 if (p
.family
== AF_INET6
&& vty_ipv6_accesslist_name
)
1872 if ((acl
= access_list_lookup (AFI_IP6
, vty_ipv6_accesslist_name
)) &&
1873 (access_list_apply (acl
, &p
) == FILTER_DENY
))
1875 zlog (NULL
, LOG_INFO
, "Vty connection refused from %s",
1876 sockunion2str (&su
, buf
, SU_ADDRSTRLEN
));
1879 /* continue accepting connections */
1880 vty_event (VTY_SERV
, accept_sock
, NULL
);
1887 ret
= setsockopt (vty_sock
, IPPROTO_TCP
, TCP_NODELAY
,
1888 (char *) &on
, sizeof (on
));
1890 zlog (NULL
, LOG_INFO
, "can't set sockopt to vty_sock : %s",
1891 safe_strerror (errno
));
1893 zlog (NULL
, LOG_INFO
, "Vty connection from %s",
1894 sockunion2str (&su
, buf
, SU_ADDRSTRLEN
));
1896 vty_create (vty_sock
, &su
);
1902 vty_serv_sock_addrinfo (const char *hostname
, unsigned short port
)
1905 struct addrinfo req
;
1906 struct addrinfo
*ainfo
;
1907 struct addrinfo
*ainfo_save
;
1909 char port_str
[BUFSIZ
];
1911 memset (&req
, 0, sizeof (struct addrinfo
));
1912 req
.ai_flags
= AI_PASSIVE
;
1913 req
.ai_family
= AF_UNSPEC
;
1914 req
.ai_socktype
= SOCK_STREAM
;
1915 sprintf (port_str
, "%d", port
);
1916 port_str
[sizeof (port_str
) - 1] = '\0';
1918 ret
= getaddrinfo (hostname
, port_str
, &req
, &ainfo
);
1922 fprintf (stderr
, "getaddrinfo failed: %s\n", gai_strerror (ret
));
1930 if (ainfo
->ai_family
!= AF_INET
1931 && ainfo
->ai_family
!= AF_INET6
1935 sock
= socket (ainfo
->ai_family
, ainfo
->ai_socktype
, ainfo
->ai_protocol
);
1939 sockopt_v6only (ainfo
->ai_family
, sock
);
1940 sockopt_reuseaddr (sock
);
1941 sockopt_reuseport (sock
);
1944 ret
= bind (sock
, ainfo
->ai_addr
, ainfo
->ai_addrlen
);
1947 close (sock
); /* Avoid sd leak. */
1951 ret
= listen (sock
, 3);
1954 close (sock
); /* Avoid sd leak. */
1958 vty_event (VTY_SERV
, sock
, NULL
);
1960 while ((ainfo
= ainfo
->ai_next
) != NULL
);
1962 freeaddrinfo (ainfo_save
);
1966 /* For sockaddr_un. */
1969 /* VTY shell UNIX domain socket. */
1971 vty_serv_un (const char *path
)
1975 struct sockaddr_un serv
;
1977 struct zprivs_ids_t ids
;
1979 /* First of all, unlink existing socket */
1983 old_mask
= umask (0007);
1985 /* Make UNIX domain socket. */
1986 sock
= socket (AF_UNIX
, SOCK_STREAM
, 0);
1989 zlog_err("Cannot create unix stream socket: %s", safe_strerror(errno
));
1993 /* Make server socket. */
1994 memset (&serv
, 0, sizeof (struct sockaddr_un
));
1995 serv
.sun_family
= AF_UNIX
;
1996 strncpy (serv
.sun_path
, path
, strlen (path
));
1997 #ifdef HAVE_STRUCT_SOCKADDR_UN_SUN_LEN
1998 len
= serv
.sun_len
= SUN_LEN(&serv
);
2000 len
= sizeof (serv
.sun_family
) + strlen (serv
.sun_path
);
2001 #endif /* HAVE_STRUCT_SOCKADDR_UN_SUN_LEN */
2005 ret
= bind (sock
, (struct sockaddr
*) &serv
, len
);
2008 zlog_err("Cannot bind path %s: %s", path
, safe_strerror(errno
));
2009 close (sock
); /* Avoid sd leak. */
2013 ret
= listen (sock
, 5);
2016 zlog_err("listen(fd %d) failed: %s", sock
, safe_strerror(errno
));
2017 close (sock
); /* Avoid sd leak. */
2023 zprivs_get_ids(&ids
);
2025 /* Hack: ids.gid_vty is actually a uint, but we stored -1 in it
2026 earlier for the case when we don't need to chown the file
2027 type casting it here to make a compare */
2028 if ((int)ids
.gid_vty
> 0)
2030 /* set group of socket */
2031 if ( chown (path
, -1, ids
.gid_vty
) )
2033 zlog_err ("vty_serv_un: could chown socket, %s",
2034 safe_strerror (errno
) );
2038 vty_event (VTYSH_SERV
, sock
, NULL
);
2041 /* #define VTYSH_DEBUG 1 */
2044 vtysh_accept (struct thread
*thread
)
2049 struct sockaddr_un client
;
2052 accept_sock
= THREAD_FD (thread
);
2054 vty_event (VTYSH_SERV
, accept_sock
, NULL
);
2056 memset (&client
, 0, sizeof (struct sockaddr_un
));
2057 client_len
= sizeof (struct sockaddr_un
);
2059 sock
= accept (accept_sock
, (struct sockaddr
*) &client
,
2060 (socklen_t
*) &client_len
);
2064 zlog_warn ("can't accept vty socket : %s", safe_strerror (errno
));
2068 if (set_nonblocking(sock
) < 0)
2070 zlog_warn ("vtysh_accept: could not set vty socket %d to non-blocking,"
2071 " %s, closing", sock
, safe_strerror (errno
));
2078 printf ("VTY shell accept\n");
2079 #endif /* VTYSH_DEBUG */
2084 vty
->type
= VTY_SHELL_SERV
;
2085 vty
->node
= VIEW_NODE
;
2087 vty_event (VTYSH_READ
, sock
, vty
);
2093 vtysh_flush(struct vty
*vty
)
2095 switch (buffer_flush_available(vty
->obuf
, vty
->wfd
))
2097 case BUFFER_PENDING
:
2098 vty_event(VTYSH_WRITE
, vty
->wfd
, vty
);
2101 vty
->monitor
= 0; /* disable monitoring to avoid infinite recursion */
2102 zlog_warn("%s: write error to fd %d, closing", __func__
, vty
->fd
);
2103 buffer_reset(vty
->obuf
);
2114 vtysh_read (struct thread
*thread
)
2120 unsigned char buf
[VTY_READ_BUFSIZ
];
2122 u_char header
[4] = {0, 0, 0, 0};
2124 sock
= THREAD_FD (thread
);
2125 vty
= THREAD_ARG (thread
);
2128 if ((nbytes
= read (sock
, buf
, VTY_READ_BUFSIZ
)) <= 0)
2132 if (ERRNO_IO_RETRY(errno
))
2134 vty_event (VTYSH_READ
, sock
, vty
);
2137 vty
->monitor
= 0; /* disable monitoring to avoid infinite recursion */
2138 zlog_warn("%s: read failed on vtysh client fd %d, closing: %s",
2139 __func__
, sock
, safe_strerror(errno
));
2141 buffer_reset(vty
->obuf
);
2144 printf ("close vtysh\n");
2145 #endif /* VTYSH_DEBUG */
2150 printf ("line: %.*s\n", nbytes
, buf
);
2151 #endif /* VTYSH_DEBUG */
2153 if (vty
->length
+ nbytes
>= VTY_BUFSIZ
)
2155 /* Clear command line buffer. */
2156 vty
->cp
= vty
->length
= 0;
2157 vty_clear_buf (vty
);
2158 vty_out (vty
, "%% Command is too long.%s", VTY_NEWLINE
);
2162 for (p
= buf
; p
< buf
+nbytes
; p
++)
2164 vty
->buf
[vty
->length
++] = *p
;
2167 /* Pass this line to parser. */
2168 ret
= vty_execute (vty
);
2169 /* Note that vty_execute clears the command buffer and resets
2170 vty->length to 0. */
2172 /* Return result. */
2174 printf ("result: %d\n", ret
);
2175 printf ("vtysh node: %d\n", vty
->node
);
2176 #endif /* VTYSH_DEBUG */
2178 /* hack for asynchronous "write integrated"
2179 * - other commands in "buf" will be ditched
2180 * - input during pending config-write is "unsupported" */
2181 if (ret
== CMD_SUSPEND
)
2184 /* warning: watchquagga hardcodes this result write */
2186 buffer_put(vty
->obuf
, header
, 4);
2188 if (!vty
->t_write
&& (vtysh_flush(vty
) < 0))
2189 /* Try to flush results; exit if a write error occurs. */
2195 vty_event (VTYSH_READ
, sock
, vty
);
2201 vtysh_write (struct thread
*thread
)
2203 struct vty
*vty
= THREAD_ARG (thread
);
2205 vty
->t_write
= NULL
;
2212 /* Determine address family to bind. */
2214 vty_serv_sock (const char *addr
, unsigned short port
, const char *path
)
2216 /* If port is set to 0, do not listen on TCP/IP at all! */
2218 vty_serv_sock_addrinfo (addr
, port
);
2225 /* Close vty interface. Warning: call this only from functions that
2226 will be careful not to access the vty afterwards (since it has
2227 now been freed). This is safest from top-level functions (called
2228 directly by the thread dispatcher). */
2230 vty_close (struct vty
*vty
)
2233 bool was_stdio
= false;
2235 /* Cancel threads.*/
2237 thread_cancel (vty
->t_read
);
2239 thread_cancel (vty
->t_write
);
2241 thread_cancel (vty
->t_timeout
);
2244 buffer_flush_all (vty
->obuf
, vty
->wfd
);
2246 /* Free input buffer. */
2247 buffer_free (vty
->obuf
);
2249 /* Free command history. */
2250 for (i
= 0; i
< VTY_MAXHIST
; i
++)
2252 XFREE (MTYPE_VTY_HIST
, vty
->hist
[i
]);
2255 vector_unset (vtyvec
, vty
->fd
);
2264 XFREE (MTYPE_VTY
, vty
->buf
);
2267 XFREE (MTYPE_VTY
, vty
->error_buf
);
2269 /* Check configure. */
2270 vty_config_unlock (vty
);
2273 XFREE (MTYPE_VTY
, vty
);
2279 /* When time out occur output message then close connection. */
2281 vty_timeout (struct thread
*thread
)
2285 vty
= THREAD_ARG (thread
);
2286 vty
->t_timeout
= NULL
;
2290 buffer_reset (vty
->obuf
);
2291 vty_out (vty
, "%sVty connection is timed out.%s", VTY_NEWLINE
, VTY_NEWLINE
);
2293 /* Close connection. */
2294 vty
->status
= VTY_CLOSE
;
2300 /* Read up configuration file from file_name. */
2302 vty_read_file (FILE *confp
)
2306 unsigned int line_num
= 0;
2309 vty
->wfd
= dup(STDERR_FILENO
); /* vty_close() will close this */
2312 /* Fine, we couldn't make a new fd. vty_close doesn't close stdout. */
2313 vty
->wfd
= STDOUT_FILENO
;
2315 vty
->fd
= STDIN_FILENO
;
2316 vty
->type
= VTY_FILE
;
2317 vty
->node
= CONFIG_NODE
;
2319 /* Execute configuration file */
2320 ret
= config_from_file (vty
, confp
, &line_num
);
2322 /* Flush any previous errors before printing messages below */
2323 buffer_flush_all (vty
->obuf
, vty
->fd
);
2325 if ( !((ret
== CMD_SUCCESS
) || (ret
== CMD_ERR_NOTHING_TODO
)) )
2327 const char *message
= NULL
;
2330 case CMD_ERR_AMBIGUOUS
:
2331 message
= "*** Error reading config: Ambiguous command.";
2333 case CMD_ERR_NO_MATCH
:
2334 message
= "*** Error reading config: There is no such command.";
2337 fprintf (stderr
, "%s\n", message
);
2338 zlog_err ("%s", message
);
2339 fprintf (stderr
, "*** Error occurred processing line %u, below:\n%s\n",
2340 line_num
, vty
->error_buf
);
2341 zlog_err ("*** Error occurred processing line %u, below:\n%s",
2342 line_num
, vty
->error_buf
);
2349 vty_use_backup_config (char *fullpath
)
2351 char *fullpath_sav
, *fullpath_tmp
;
2358 fullpath_sav
= malloc (strlen (fullpath
) + strlen (CONF_BACKUP_EXT
) + 1);
2359 strcpy (fullpath_sav
, fullpath
);
2360 strcat (fullpath_sav
, CONF_BACKUP_EXT
);
2361 if (stat (fullpath_sav
, &buf
) == -1)
2363 free (fullpath_sav
);
2367 fullpath_tmp
= malloc (strlen (fullpath
) + 8);
2368 sprintf (fullpath_tmp
, "%s.XXXXXX", fullpath
);
2370 /* Open file to configuration write. */
2371 tmp
= mkstemp (fullpath_tmp
);
2374 free (fullpath_sav
);
2375 free (fullpath_tmp
);
2379 sav
= open (fullpath_sav
, O_RDONLY
);
2382 unlink (fullpath_tmp
);
2383 free (fullpath_sav
);
2384 free (fullpath_tmp
);
2388 while((c
= read (sav
, buffer
, 512)) > 0)
2390 if (write (tmp
, buffer
, c
) <= 0)
2392 free (fullpath_sav
);
2393 free (fullpath_tmp
);
2402 if (chmod(fullpath_tmp
, CONFIGFILE_MASK
) != 0)
2404 unlink (fullpath_tmp
);
2405 free (fullpath_sav
);
2406 free (fullpath_tmp
);
2410 if (link (fullpath_tmp
, fullpath
) == 0)
2411 ret
= fopen (fullpath
, "r");
2413 unlink (fullpath_tmp
);
2415 free (fullpath_sav
);
2416 free (fullpath_tmp
);
2420 /* Read up configuration file from file_name. */
2422 vty_read_config (char *config_file
,
2423 char *config_default_dir
)
2425 char cwd
[MAXPATHLEN
];
2430 /* If -f flag specified. */
2431 if (config_file
!= NULL
)
2433 if (! IS_DIRECTORY_SEP (config_file
[0]))
2435 if (getcwd (cwd
, MAXPATHLEN
) == NULL
)
2437 fprintf (stderr
, "Failure to determine Current Working Directory %d!\n", errno
);
2440 tmp
= XMALLOC (MTYPE_TMP
,
2441 strlen (cwd
) + strlen (config_file
) + 2);
2442 sprintf (tmp
, "%s/%s", cwd
, config_file
);
2446 fullpath
= config_file
;
2448 confp
= fopen (fullpath
, "r");
2452 fprintf (stderr
, "%s: failed to open configuration file %s: %s\n",
2453 __func__
, fullpath
, safe_strerror (errno
));
2455 confp
= vty_use_backup_config (fullpath
);
2457 fprintf (stderr
, "WARNING: using backup configuration file!\n");
2460 fprintf (stderr
, "can't open configuration file [%s]\n",
2469 host_config_set (config_default_dir
);
2473 struct stat conf_stat
;
2475 /* !!!!PLEASE LEAVE!!!!
2476 * This is NEEDED for use with vtysh -b, or else you can get
2477 * a real configuration food fight with a lot garbage in the
2478 * merged configuration file it creates coming from the per
2479 * daemon configuration files. This also allows the daemons
2480 * to start if there default configuration file is not
2481 * present or ignore them, as needed when using vtysh -b to
2482 * configure the daemons at boot - MAG
2485 /* Stat for vtysh Zebra.conf, if found startup and wait for
2486 * boot configuration
2489 if ( strstr(config_default_dir
, "vtysh") == NULL
)
2491 ret
= stat (integrate_default
, &conf_stat
);
2493 goto tmp_free_and_out
;
2496 confp
= fopen (config_default_dir
, "r");
2499 fprintf (stderr
, "%s: failed to open configuration file %s: %s\n",
2500 __func__
, config_default_dir
, safe_strerror (errno
));
2502 confp
= vty_use_backup_config (config_default_dir
);
2505 fprintf (stderr
, "WARNING: using backup configuration file!\n");
2506 fullpath
= config_default_dir
;
2510 fprintf (stderr
, "can't open configuration file [%s]\n",
2511 config_default_dir
);
2512 goto tmp_free_and_out
;
2516 fullpath
= config_default_dir
;
2519 vty_read_file (confp
);
2523 host_config_set (fullpath
);
2527 XFREE (MTYPE_TMP
, fullpath
);
2530 /* Small utility function which output log to the VTY. */
2532 vty_log (const char *level
, const char *proto_str
,
2533 const char *format
, struct timestamp_control
*ctl
, va_list va
)
2541 for (i
= 0; i
< vector_active (vtyvec
); i
++)
2542 if ((vty
= vector_slot (vtyvec
, i
)) != NULL
)
2547 vty_log_out (vty
, level
, proto_str
, format
, ctl
, ac
);
2552 /* Async-signal-safe version of vty_log for fixed strings. */
2554 vty_log_fixed (char *buf
, size_t len
)
2557 struct iovec iov
[2];
2558 char crlf
[4] = "\r\n";
2560 /* vty may not have been initialised */
2564 iov
[0].iov_base
= buf
;
2565 iov
[0].iov_len
= len
;
2566 iov
[1].iov_base
= crlf
;
2569 for (i
= 0; i
< vector_active (vtyvec
); i
++)
2572 if (((vty
= vector_slot (vtyvec
, i
)) != NULL
) && vty
->monitor
)
2573 /* N.B. We don't care about the return code, since process is
2574 most likely just about to die anyway. */
2575 if (writev(vty
->wfd
, iov
, 2) == -1)
2577 fprintf(stderr
, "Failure to writev: %d\n", errno
);
2584 vty_config_lock (struct vty
*vty
)
2586 if (vty_config_is_lockless
)
2588 if (vty_config
== 0)
2597 vty_config_unlock (struct vty
*vty
)
2599 if (vty_config_is_lockless
)
2601 if (vty_config
== 1 && vty
->config
== 1)
2610 vty_config_lockless (void)
2612 vty_config_is_lockless
= 1;
2615 /* Master of the threads. */
2616 static struct thread_master
*vty_master
;
2619 vty_event (enum event event
, int sock
, struct vty
*vty
)
2621 struct thread
*vty_serv_thread
;
2626 vty_serv_thread
= thread_add_read (vty_master
, vty_accept
, vty
, sock
);
2627 vector_set_index (Vvty_serv_thread
, sock
, vty_serv_thread
);
2631 vty_serv_thread
= thread_add_read (vty_master
, vtysh_accept
, vty
, sock
);
2632 vector_set_index (Vvty_serv_thread
, sock
, vty_serv_thread
);
2635 vty
->t_read
= thread_add_read (vty_master
, vtysh_read
, vty
, sock
);
2638 vty
->t_write
= thread_add_write (vty_master
, vtysh_write
, vty
, sock
);
2642 vty
->t_read
= thread_add_read (vty_master
, vty_read
, vty
, sock
);
2644 /* Time out treatment. */
2648 thread_cancel (vty
->t_timeout
);
2650 thread_add_timer (vty_master
, vty_timeout
, vty
, vty
->v_timeout
);
2655 vty
->t_write
= thread_add_write (vty_master
, vty_flush
, vty
, sock
);
2657 case VTY_TIMEOUT_RESET
:
2660 thread_cancel (vty
->t_timeout
);
2661 vty
->t_timeout
= NULL
;
2666 thread_add_timer (vty_master
, vty_timeout
, vty
, vty
->v_timeout
);
2675 "Display who is on vty\n")
2680 for (i
= 0; i
< vector_active (vtyvec
); i
++)
2681 if ((v
= vector_slot (vtyvec
, i
)) != NULL
)
2682 vty_out (vty
, "%svty[%d] connected from %s.%s",
2683 v
->config
? "*" : " ",
2684 i
, v
->address
, VTY_NEWLINE
);
2688 /* Move to vty configuration mode. */
2692 "Configure a terminal line\n"
2693 "Virtual terminal\n")
2695 vty
->node
= VTY_NODE
;
2699 /* Set time out value. */
2701 exec_timeout (struct vty
*vty
, const char *min_str
, const char *sec_str
)
2703 unsigned long timeout
= 0;
2705 /* min_str and sec_str are already checked by parser. So it must be
2706 all digit string. */
2709 timeout
= strtol (min_str
, NULL
, 10);
2713 timeout
+= strtol (sec_str
, NULL
, 10);
2715 vty_timeout_val
= timeout
;
2716 vty
->v_timeout
= timeout
;
2717 vty_event (VTY_TIMEOUT_RESET
, 0, vty
);
2723 DEFUN (exec_timeout_min
,
2724 exec_timeout_min_cmd
,
2725 "exec-timeout (0-35791)",
2726 "Set timeout value\n"
2727 "Timeout value in minutes\n")
2730 return exec_timeout (vty
, argv
[idx_number
]->arg
, NULL
);
2733 DEFUN (exec_timeout_sec
,
2734 exec_timeout_sec_cmd
,
2735 "exec-timeout (0-35791) (0-2147483)",
2736 "Set the EXEC timeout\n"
2737 "Timeout in minutes\n"
2738 "Timeout in seconds\n")
2741 int idx_number_2
= 2;
2742 return exec_timeout (vty
, argv
[idx_number
]->arg
, argv
[idx_number_2
]->arg
);
2745 DEFUN (no_exec_timeout
,
2746 no_exec_timeout_cmd
,
2749 "Set the EXEC timeout\n")
2751 return exec_timeout (vty
, NULL
, NULL
);
2754 /* Set vty access class. */
2755 DEFUN (vty_access_class
,
2756 vty_access_class_cmd
,
2757 "access-class WORD",
2758 "Filter connections based on an IP access list\n"
2762 if (vty_accesslist_name
)
2763 XFREE(MTYPE_VTY
, vty_accesslist_name
);
2765 vty_accesslist_name
= XSTRDUP(MTYPE_VTY
, argv
[idx_word
]->arg
);
2770 /* Clear vty access class. */
2771 DEFUN (no_vty_access_class
,
2772 no_vty_access_class_cmd
,
2773 "no access-class [WORD]",
2775 "Filter connections based on an IP access list\n"
2779 const char *accesslist
= (argc
== 3) ? argv
[idx_word
]->arg
: NULL
;
2780 if (! vty_accesslist_name
|| (argc
== 3 && strcmp(vty_accesslist_name
, accesslist
)))
2782 vty_out (vty
, "Access-class is not currently applied to vty%s",
2787 XFREE(MTYPE_VTY
, vty_accesslist_name
);
2789 vty_accesslist_name
= NULL
;
2794 /* Set vty access class. */
2795 DEFUN (vty_ipv6_access_class
,
2796 vty_ipv6_access_class_cmd
,
2797 "ipv6 access-class WORD",
2799 "Filter connections based on an IP access list\n"
2800 "IPv6 access list\n")
2803 if (vty_ipv6_accesslist_name
)
2804 XFREE(MTYPE_VTY
, vty_ipv6_accesslist_name
);
2806 vty_ipv6_accesslist_name
= XSTRDUP(MTYPE_VTY
, argv
[idx_word
]->arg
);
2811 /* Clear vty access class. */
2812 DEFUN (no_vty_ipv6_access_class
,
2813 no_vty_ipv6_access_class_cmd
,
2814 "no ipv6 access-class [WORD]",
2817 "Filter connections based on an IP access list\n"
2818 "IPv6 access list\n")
2821 const char *accesslist
= (argc
== 4) ? argv
[idx_word
]->arg
: NULL
;
2823 if (! vty_ipv6_accesslist_name
||
2824 (argc
== 4 && strcmp(vty_ipv6_accesslist_name
, accesslist
)))
2826 vty_out (vty
, "IPv6 access-class is not currently applied to vty%s",
2831 XFREE(MTYPE_VTY
, vty_ipv6_accesslist_name
);
2833 vty_ipv6_accesslist_name
= NULL
;
2842 "Enable password checking\n")
2844 no_password_check
= 0;
2848 DEFUN (no_vty_login
,
2852 "Enable password checking\n")
2854 no_password_check
= 1;
2858 DEFUN (service_advanced_vty
,
2859 service_advanced_vty_cmd
,
2860 "service advanced-vty",
2861 "Set up miscellaneous service\n"
2862 "Enable advanced mode vty interface\n")
2868 DEFUN (no_service_advanced_vty
,
2869 no_service_advanced_vty_cmd
,
2870 "no service advanced-vty",
2872 "Set up miscellaneous service\n"
2873 "Enable advanced mode vty interface\n")
2879 DEFUN (terminal_monitor
,
2880 terminal_monitor_cmd
,
2882 "Set terminal line parameters\n"
2883 "Copy debug output to the current terminal line\n")
2889 DEFUN (terminal_no_monitor
,
2890 terminal_no_monitor_cmd
,
2891 "terminal no monitor",
2892 "Set terminal line parameters\n"
2894 "Copy debug output to the current terminal line\n")
2900 DEFUN (no_terminal_monitor
,
2901 no_terminal_monitor_cmd
,
2902 "no terminal monitor",
2904 "Set terminal line parameters\n"
2905 "Copy debug output to the current terminal line\n")
2907 return terminal_no_monitor (self
, vty
, argc
, argv
);
2911 DEFUN (show_history
,
2915 "Display the session command history\n")
2919 for (index
= vty
->hindex
+ 1; index
!= vty
->hindex
;)
2921 if (index
== VTY_MAXHIST
)
2927 if (vty
->hist
[index
] != NULL
)
2928 vty_out (vty
, " %s%s", vty
->hist
[index
], VTY_NEWLINE
);
2937 DEFUN (log_commands
,
2941 "Log all commands (can't be unset without restart)\n")
2943 do_log_commands
= 1;
2947 /* Display current configuration. */
2949 vty_config_write (struct vty
*vty
)
2951 vty_out (vty
, "line vty%s", VTY_NEWLINE
);
2953 if (vty_accesslist_name
)
2954 vty_out (vty
, " access-class %s%s",
2955 vty_accesslist_name
, VTY_NEWLINE
);
2957 if (vty_ipv6_accesslist_name
)
2958 vty_out (vty
, " ipv6 access-class %s%s",
2959 vty_ipv6_accesslist_name
, VTY_NEWLINE
);
2962 if (vty_timeout_val
!= VTY_TIMEOUT_DEFAULT
)
2963 vty_out (vty
, " exec-timeout %ld %ld%s",
2964 vty_timeout_val
/ 60,
2965 vty_timeout_val
% 60, VTY_NEWLINE
);
2968 if (no_password_check
)
2969 vty_out (vty
, " no login%s", VTY_NEWLINE
);
2971 if (do_log_commands
)
2972 vty_out (vty
, "log commands%s", VTY_NEWLINE
);
2974 vty_out (vty
, "!%s", VTY_NEWLINE
);
2979 struct cmd_node vty_node
=
2982 "%s(config-line)# ",
2986 /* Reset all VTY status. */
2992 struct thread
*vty_serv_thread
;
2994 for (i
= 0; i
< vector_active (vtyvec
); i
++)
2995 if ((vty
= vector_slot (vtyvec
, i
)) != NULL
)
2997 buffer_reset (vty
->obuf
);
2998 vty
->status
= VTY_CLOSE
;
3002 for (i
= 0; i
< vector_active (Vvty_serv_thread
); i
++)
3003 if ((vty_serv_thread
= vector_slot (Vvty_serv_thread
, i
)) != NULL
)
3005 thread_cancel (vty_serv_thread
);
3006 vector_slot (Vvty_serv_thread
, i
) = NULL
;
3010 vty_timeout_val
= VTY_TIMEOUT_DEFAULT
;
3012 if (vty_accesslist_name
)
3014 XFREE(MTYPE_VTY
, vty_accesslist_name
);
3015 vty_accesslist_name
= NULL
;
3018 if (vty_ipv6_accesslist_name
)
3020 XFREE(MTYPE_VTY
, vty_ipv6_accesslist_name
);
3021 vty_ipv6_accesslist_name
= NULL
;
3028 char cwd
[MAXPATHLEN
];
3031 c
= getcwd (cwd
, MAXPATHLEN
);
3036 * At this point if these go wrong, more than likely
3037 * the whole world is coming down around us
3038 * Hence not worrying about it too much.
3040 if (!chdir (SYSCONFDIR
))
3042 fprintf(stderr
, "Failure to chdir to %s, errno: %d\n", SYSCONFDIR
, errno
);
3045 if (getcwd (cwd
, MAXPATHLEN
) == NULL
)
3047 fprintf(stderr
, "Failure to getcwd, errno: %d\n", errno
);
3052 vty_cwd
= XMALLOC (MTYPE_TMP
, strlen (cwd
) + 1);
3053 strcpy (vty_cwd
, cwd
);
3063 vty_shell (struct vty
*vty
)
3065 return vty
->type
== VTY_SHELL
? 1 : 0;
3069 vty_shell_serv (struct vty
*vty
)
3071 return vty
->type
== VTY_SHELL_SERV
? 1 : 0;
3077 vtyvec
= vector_init (VECTOR_MIN_SIZE
);
3080 /* Install vty's own commands like `who' command. */
3082 vty_init (struct thread_master
*master_thread
)
3084 /* For further configuration read, preserve current directory. */
3087 vtyvec
= vector_init (VECTOR_MIN_SIZE
);
3089 vty_master
= master_thread
;
3091 atexit (vty_stdio_reset
);
3093 /* Initilize server thread vector. */
3094 Vvty_serv_thread
= vector_init (VECTOR_MIN_SIZE
);
3096 /* Install bgp top node. */
3097 install_node (&vty_node
, vty_config_write
);
3099 install_element (VIEW_NODE
, &config_who_cmd
);
3100 install_element (VIEW_NODE
, &show_history_cmd
);
3101 install_element (CONFIG_NODE
, &line_vty_cmd
);
3102 install_element (CONFIG_NODE
, &service_advanced_vty_cmd
);
3103 install_element (CONFIG_NODE
, &no_service_advanced_vty_cmd
);
3104 install_element (CONFIG_NODE
, &show_history_cmd
);
3105 install_element (CONFIG_NODE
, &log_commands_cmd
);
3106 install_element (ENABLE_NODE
, &terminal_monitor_cmd
);
3107 install_element (ENABLE_NODE
, &terminal_no_monitor_cmd
);
3108 install_element (ENABLE_NODE
, &no_terminal_monitor_cmd
);
3110 install_default (VTY_NODE
);
3111 install_element (VTY_NODE
, &exec_timeout_min_cmd
);
3112 install_element (VTY_NODE
, &exec_timeout_sec_cmd
);
3113 install_element (VTY_NODE
, &no_exec_timeout_cmd
);
3114 install_element (VTY_NODE
, &vty_access_class_cmd
);
3115 install_element (VTY_NODE
, &no_vty_access_class_cmd
);
3116 install_element (VTY_NODE
, &vty_login_cmd
);
3117 install_element (VTY_NODE
, &no_vty_login_cmd
);
3118 install_element (VTY_NODE
, &vty_ipv6_access_class_cmd
);
3119 install_element (VTY_NODE
, &no_vty_ipv6_access_class_cmd
);
3123 vty_terminate (void)
3126 XFREE (MTYPE_TMP
, vty_cwd
);
3128 if (vtyvec
&& Vvty_serv_thread
)
3131 vector_free (vtyvec
);
3132 vector_free (Vvty_serv_thread
);
3136 /* Utility functions to get arguments from commands generated
3137 by the xml2cli.pl script. */
3139 vty_get_arg_value (struct vty_arg
*args
[], const char *arg
)
3143 if (strcmp ((*args
)->name
, arg
) == 0)
3144 return (*args
)->value
;
3151 vty_get_arg (struct vty_arg
*args
[], const char *arg
)
3155 if (strcmp ((*args
)->name
, arg
) == 0)