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_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
= zlog_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
);
742 case BGP_ENCAPV6_NODE
:
743 case BGP_VRF_POLICY_NODE
:
744 case BGP_VNC_DEFAULTS_NODE
:
745 case BGP_VNC_NVE_GROUP_NODE
:
746 case BGP_VNC_L2_GROUP_NODE
:
760 case LDP_IPV4_IFACE_NODE
:
761 case LDP_IPV6_IFACE_NODE
:
763 case LDP_PSEUDOWIRE_NODE
:
766 case KEYCHAIN_KEY_NODE
:
770 vty_config_unlock (vty
);
771 vty
->node
= ENABLE_NODE
;
774 /* Unknown node, we have to ignore it. */
782 /* Delete a charcter at the current point. */
784 vty_delete_char (struct vty
*vty
)
789 if (vty
->length
== 0)
791 vty_down_level (vty
);
795 if (vty
->cp
== vty
->length
)
796 return; /* completion need here? */
798 size
= vty
->length
- vty
->cp
;
801 memmove (&vty
->buf
[vty
->cp
], &vty
->buf
[vty
->cp
+ 1], size
- 1);
802 vty
->buf
[vty
->length
] = '\0';
804 if (vty
->node
== AUTH_NODE
|| vty
->node
== AUTH_ENABLE_NODE
)
807 vty_write (vty
, &vty
->buf
[vty
->cp
], size
- 1);
808 vty_write (vty
, &telnet_space_char
, 1);
810 for (i
= 0; i
< size
; i
++)
811 vty_write (vty
, &telnet_backward_char
, 1);
814 /* Delete a character before the point. */
816 vty_delete_backward_char (struct vty
*vty
)
821 vty_backward_char (vty
);
822 vty_delete_char (vty
);
825 /* Kill rest of line from current point. */
827 vty_kill_line (struct vty
*vty
)
832 size
= vty
->length
- vty
->cp
;
837 for (i
= 0; i
< size
; i
++)
838 vty_write (vty
, &telnet_space_char
, 1);
839 for (i
= 0; i
< size
; i
++)
840 vty_write (vty
, &telnet_backward_char
, 1);
842 memset (&vty
->buf
[vty
->cp
], 0, size
);
843 vty
->length
= vty
->cp
;
846 /* Kill line from the beginning. */
848 vty_kill_line_from_beginning (struct vty
*vty
)
850 vty_beginning_of_line (vty
);
854 /* Delete a word before the point. */
856 vty_forward_kill_word (struct vty
*vty
)
858 while (vty
->cp
!= vty
->length
&& vty
->buf
[vty
->cp
] == ' ')
859 vty_delete_char (vty
);
860 while (vty
->cp
!= vty
->length
&& vty
->buf
[vty
->cp
] != ' ')
861 vty_delete_char (vty
);
864 /* Delete a word before the point. */
866 vty_backward_kill_word (struct vty
*vty
)
868 while (vty
->cp
> 0 && vty
->buf
[vty
->cp
- 1] == ' ')
869 vty_delete_backward_char (vty
);
870 while (vty
->cp
> 0 && vty
->buf
[vty
->cp
- 1] != ' ')
871 vty_delete_backward_char (vty
);
874 /* Transpose chars before or at the point. */
876 vty_transpose_chars (struct vty
*vty
)
880 /* If length is short or point is near by the beginning of line then
882 if (vty
->length
< 2 || vty
->cp
< 1)
885 /* In case of point is located at the end of the line. */
886 if (vty
->cp
== vty
->length
)
888 c1
= vty
->buf
[vty
->cp
- 1];
889 c2
= vty
->buf
[vty
->cp
- 2];
891 vty_backward_char (vty
);
892 vty_backward_char (vty
);
893 vty_self_insert_overwrite (vty
, c1
);
894 vty_self_insert_overwrite (vty
, c2
);
898 c1
= vty
->buf
[vty
->cp
];
899 c2
= vty
->buf
[vty
->cp
- 1];
901 vty_backward_char (vty
);
902 vty_self_insert_overwrite (vty
, c1
);
903 vty_self_insert_overwrite (vty
, c2
);
907 /* Do completion at vty interface. */
909 vty_complete_command (struct vty
*vty
)
913 char **matched
= NULL
;
916 if (vty
->node
== AUTH_NODE
|| vty
->node
== AUTH_ENABLE_NODE
)
919 vline
= cmd_make_strvec (vty
->buf
);
923 /* In case of 'help \t'. */
924 if (isspace ((int) vty
->buf
[vty
->length
- 1]))
925 vector_set (vline
, NULL
);
927 matched
= cmd_complete_command (vline
, vty
, &ret
);
929 cmd_free_strvec (vline
);
931 vty_out (vty
, "%s", VTY_NEWLINE
);
934 case CMD_ERR_AMBIGUOUS
:
935 vty_out (vty
, "%% Ambiguous command.%s", VTY_NEWLINE
);
937 vty_redraw_line (vty
);
939 case CMD_ERR_NO_MATCH
:
940 /* vty_out (vty, "%% There is no matched command.%s", VTY_NEWLINE); */
942 vty_redraw_line (vty
);
944 case CMD_COMPLETE_FULL_MATCH
:
947 /* 2016-11-28 equinox -- need to debug, SEGV here */
948 vty_out (vty
, "%% CLI BUG: FULL_MATCH with NULL str%s", VTY_NEWLINE
);
950 vty_redraw_line (vty
);
954 vty_redraw_line (vty
);
955 vty_backward_pure_word (vty
);
956 vty_insert_word_overwrite (vty
, matched
[0]);
957 vty_self_insert (vty
, ' ');
958 XFREE (MTYPE_TMP
, matched
[0]);
960 case CMD_COMPLETE_MATCH
:
962 vty_redraw_line (vty
);
963 vty_backward_pure_word (vty
);
964 vty_insert_word_overwrite (vty
, matched
[0]);
965 XFREE (MTYPE_TMP
, matched
[0]);
967 case CMD_COMPLETE_LIST_MATCH
:
968 for (i
= 0; matched
[i
] != NULL
; i
++)
970 if (i
!= 0 && ((i
% 6) == 0))
971 vty_out (vty
, "%s", VTY_NEWLINE
);
972 vty_out (vty
, "%-10s ", matched
[i
]);
973 XFREE (MTYPE_TMP
, matched
[i
]);
975 vty_out (vty
, "%s", VTY_NEWLINE
);
978 vty_redraw_line (vty
);
980 case CMD_ERR_NOTHING_TODO
:
982 vty_redraw_line (vty
);
988 XFREE (MTYPE_TMP
, matched
);
992 vty_describe_fold (struct vty
*vty
, int cmd_width
,
993 unsigned int desc_width
, struct cmd_token
*token
)
1001 if (desc_width
<= 0)
1003 vty_out (vty
, " %-*s %s%s", cmd_width
, cmd
, token
->desc
, VTY_NEWLINE
);
1007 buf
= XCALLOC (MTYPE_TMP
, strlen (token
->desc
) + 1);
1009 for (p
= token
->desc
; strlen (p
) > desc_width
; p
+= pos
+ 1)
1011 for (pos
= desc_width
; pos
> 0; pos
--)
1012 if (*(p
+ pos
) == ' ')
1018 strncpy (buf
, p
, pos
);
1020 vty_out (vty
, " %-*s %s%s", cmd_width
, cmd
, buf
, VTY_NEWLINE
);
1025 vty_out (vty
, " %-*s %s%s", cmd_width
, cmd
, p
, VTY_NEWLINE
);
1027 XFREE (MTYPE_TMP
, buf
);
1030 /* Describe matched command function. */
1032 vty_describe_command (struct vty
*vty
)
1037 unsigned int i
, width
, desc_width
;
1038 struct cmd_token
*token
, *token_cr
= NULL
;
1040 vline
= cmd_make_strvec (vty
->buf
);
1042 /* In case of '> ?'. */
1045 vline
= vector_init (1);
1046 vector_set (vline
, NULL
);
1049 if (isspace ((int) vty
->buf
[vty
->length
- 1]))
1050 vector_set (vline
, NULL
);
1052 describe
= cmd_describe_command (vline
, vty
, &ret
);
1054 vty_out (vty
, "%s", VTY_NEWLINE
);
1056 /* Ambiguous error. */
1059 case CMD_ERR_AMBIGUOUS
:
1060 vty_out (vty
, "%% Ambiguous command.%s", VTY_NEWLINE
);
1063 case CMD_ERR_NO_MATCH
:
1064 vty_out (vty
, "%% There is no matched command.%s", VTY_NEWLINE
);
1069 /* Get width of command string. */
1071 for (i
= 0; i
< vector_active (describe
); i
++)
1072 if ((token
= vector_slot (describe
, i
)) != NULL
)
1076 if (token
->text
[0] == '\0')
1079 len
= strlen (token
->text
);
1085 /* Get width of description string. */
1086 desc_width
= vty
->width
- (width
+ 6);
1088 /* Print out description. */
1089 for (i
= 0; i
< vector_active (describe
); i
++)
1090 if ((token
= vector_slot (describe
, i
)) != NULL
)
1092 if (token
->text
[0] == '\0')
1095 if (strcmp (token
->text
, CMD_CR_TEXT
) == 0)
1102 vty_out (vty
, " %-s%s",
1105 else if (desc_width
>= strlen (token
->desc
))
1106 vty_out (vty
, " %-*s %s%s", width
,
1108 token
->desc
, VTY_NEWLINE
);
1110 vty_describe_fold (vty
, width
, desc_width
, token
);
1113 vty_out (vty
, " %-*s %s%s", width
1114 desc
->cmd
[0] == '.' ? desc
->cmd
+ 1 : desc
->cmd
,
1115 desc
->str
? desc
->str
: "", VTY_NEWLINE
);
1119 if ((token
= token_cr
))
1122 vty_out (vty
, " %-s%s",
1125 else if (desc_width
>= strlen (token
->desc
))
1126 vty_out (vty
, " %-*s %s%s", width
,
1128 token
->desc
, VTY_NEWLINE
);
1130 vty_describe_fold (vty
, width
, desc_width
, token
);
1134 cmd_free_strvec (vline
);
1136 vector_free (describe
);
1139 vty_redraw_line (vty
);
1143 vty_clear_buf (struct vty
*vty
)
1145 memset (vty
->buf
, 0, vty
->max
);
1148 /* ^C stop current input and do not add command line to the history. */
1150 vty_stop_input (struct vty
*vty
)
1152 vty
->cp
= vty
->length
= 0;
1153 vty_clear_buf (vty
);
1154 vty_out (vty
, "%s", VTY_NEWLINE
);
1160 /* Nothing to do. */
1163 case INTERFACE_NODE
:
1175 case LDP_IPV4_IFACE_NODE
:
1176 case LDP_IPV6_IFACE_NODE
:
1177 case LDP_L2VPN_NODE
:
1178 case LDP_PSEUDOWIRE_NODE
:
1181 case KEYCHAIN_KEY_NODE
:
1185 vty_config_unlock (vty
);
1186 vty
->node
= ENABLE_NODE
;
1189 /* Unknown node, we have to ignore it. */
1194 /* Set history pointer to the latest one. */
1195 vty
->hp
= vty
->hindex
;
1198 /* Add current command line to the history buffer. */
1200 vty_hist_add (struct vty
*vty
)
1204 if (vty
->length
== 0)
1207 index
= vty
->hindex
? vty
->hindex
- 1 : VTY_MAXHIST
- 1;
1209 /* Ignore the same string as previous one. */
1210 if (vty
->hist
[index
])
1211 if (strcmp (vty
->buf
, vty
->hist
[index
]) == 0)
1213 vty
->hp
= vty
->hindex
;
1217 /* Insert history entry. */
1218 if (vty
->hist
[vty
->hindex
])
1219 XFREE (MTYPE_VTY_HIST
, vty
->hist
[vty
->hindex
]);
1220 vty
->hist
[vty
->hindex
] = XSTRDUP (MTYPE_VTY_HIST
, vty
->buf
);
1222 /* History index rotation. */
1224 if (vty
->hindex
== VTY_MAXHIST
)
1227 vty
->hp
= vty
->hindex
;
1230 /* #define TELNET_OPTION_DEBUG */
1232 /* Get telnet window size. */
1234 vty_telnet_option (struct vty
*vty
, unsigned char *buf
, int nbytes
)
1236 #ifdef TELNET_OPTION_DEBUG
1239 for (i
= 0; i
< nbytes
; i
++)
1244 vty_out (vty
, "IAC ");
1247 vty_out (vty
, "WILL ");
1250 vty_out (vty
, "WONT ");
1253 vty_out (vty
, "DO ");
1256 vty_out (vty
, "DONT ");
1259 vty_out (vty
, "SB ");
1262 vty_out (vty
, "SE ");
1265 vty_out (vty
, "TELOPT_ECHO %s", VTY_NEWLINE
);
1268 vty_out (vty
, "TELOPT_SGA %s", VTY_NEWLINE
);
1271 vty_out (vty
, "TELOPT_NAWS %s", VTY_NEWLINE
);
1274 vty_out (vty
, "%x ", buf
[i
]);
1278 vty_out (vty
, "%s", VTY_NEWLINE
);
1280 #endif /* TELNET_OPTION_DEBUG */
1286 vty
->iac_sb_in_progress
= 1;
1291 if (!vty
->iac_sb_in_progress
)
1294 if ((vty
->sb_len
== 0) || (vty
->sb_buf
[0] == '\0'))
1296 vty
->iac_sb_in_progress
= 0;
1299 switch (vty
->sb_buf
[0])
1302 if (vty
->sb_len
!= TELNET_NAWS_SB_LEN
)
1303 zlog_warn("RFC 1073 violation detected: telnet NAWS option "
1304 "should send %d characters, but we received %lu",
1305 TELNET_NAWS_SB_LEN
, (u_long
)vty
->sb_len
);
1306 else if (sizeof(vty
->sb_buf
) < TELNET_NAWS_SB_LEN
)
1307 zlog_err("Bug detected: sizeof(vty->sb_buf) %lu < %d, "
1308 "too small to handle the telnet NAWS option",
1309 (u_long
)sizeof(vty
->sb_buf
), TELNET_NAWS_SB_LEN
);
1312 vty
->width
= ((vty
->sb_buf
[1] << 8)|vty
->sb_buf
[2]);
1313 vty
->height
= ((vty
->sb_buf
[3] << 8)|vty
->sb_buf
[4]);
1314 #ifdef TELNET_OPTION_DEBUG
1315 vty_out(vty
, "TELNET NAWS window size negotiation completed: "
1316 "width %d, height %d%s",
1317 vty
->width
, vty
->height
, VTY_NEWLINE
);
1322 vty
->iac_sb_in_progress
= 0;
1332 /* Execute current command line. */
1334 vty_execute (struct vty
*vty
)
1343 case AUTH_ENABLE_NODE
:
1344 vty_auth (vty
, vty
->buf
);
1347 ret
= vty_command (vty
, vty
->buf
);
1348 if (vty
->type
== VTY_TERM
)
1353 /* Clear command line buffer. */
1354 vty
->cp
= vty
->length
= 0;
1355 vty_clear_buf (vty
);
1357 if (vty
->status
!= VTY_CLOSE
)
1363 #define CONTROL(X) ((X) - '@')
1364 #define VTY_NORMAL 0
1365 #define VTY_PRE_ESCAPE 1
1366 #define VTY_ESCAPE 2
1368 /* Escape character command map. */
1370 vty_escape_map (unsigned char c
, struct vty
*vty
)
1375 vty_previous_line (vty
);
1378 vty_next_line (vty
);
1381 vty_forward_char (vty
);
1384 vty_backward_char (vty
);
1390 /* Go back to normal mode. */
1391 vty
->escape
= VTY_NORMAL
;
1394 /* Quit print out to the buffer. */
1396 vty_buffer_reset (struct vty
*vty
)
1398 buffer_reset (vty
->obuf
);
1400 vty_redraw_line (vty
);
1403 /* Read data via vty socket. */
1405 vty_read (struct thread
*thread
)
1409 unsigned char buf
[VTY_READ_BUFSIZ
];
1411 int vty_sock
= THREAD_FD (thread
);
1412 struct vty
*vty
= THREAD_ARG (thread
);
1415 /* Read raw data from socket */
1416 if ((nbytes
= read (vty
->fd
, buf
, VTY_READ_BUFSIZ
)) <= 0)
1420 if (ERRNO_IO_RETRY(errno
))
1422 vty_event (VTY_READ
, vty_sock
, vty
);
1425 vty
->monitor
= 0; /* disable monitoring to avoid infinite recursion */
1426 zlog_warn("%s: read error on vty client fd %d, closing: %s",
1427 __func__
, vty
->fd
, safe_strerror(errno
));
1428 buffer_reset(vty
->obuf
);
1430 vty
->status
= VTY_CLOSE
;
1433 for (i
= 0; i
< nbytes
; i
++)
1448 if (vty
->iac_sb_in_progress
&& !vty
->iac
)
1450 if (vty
->sb_len
< sizeof(vty
->sb_buf
))
1451 vty
->sb_buf
[vty
->sb_len
] = buf
[i
];
1458 /* In case of telnet command */
1460 ret
= vty_telnet_option (vty
, buf
+ i
, nbytes
- i
);
1467 if (vty
->status
== VTY_MORE
)
1474 vty_buffer_reset (vty
);
1476 #if 0 /* More line does not work for "show ip bgp". */
1479 vty
->status
= VTY_MORELINE
;
1488 /* Escape character. */
1489 if (vty
->escape
== VTY_ESCAPE
)
1491 vty_escape_map (buf
[i
], vty
);
1495 /* Pre-escape status. */
1496 if (vty
->escape
== VTY_PRE_ESCAPE
)
1501 vty
->escape
= VTY_ESCAPE
;
1504 vty_backward_word (vty
);
1505 vty
->escape
= VTY_NORMAL
;
1508 vty_forward_word (vty
);
1509 vty
->escape
= VTY_NORMAL
;
1512 vty_forward_kill_word (vty
);
1513 vty
->escape
= VTY_NORMAL
;
1517 vty_backward_kill_word (vty
);
1518 vty
->escape
= VTY_NORMAL
;
1521 vty
->escape
= VTY_NORMAL
;
1530 vty_beginning_of_line (vty
);
1533 vty_backward_char (vty
);
1536 vty_stop_input (vty
);
1539 vty_delete_char (vty
);
1542 vty_end_of_line (vty
);
1545 vty_forward_char (vty
);
1549 vty_delete_backward_char (vty
);
1552 vty_kill_line (vty
);
1555 vty_next_line (vty
);
1558 vty_previous_line (vty
);
1561 vty_transpose_chars (vty
);
1564 vty_kill_line_from_beginning (vty
);
1567 vty_backward_kill_word (vty
);
1570 vty_end_config (vty
);
1574 vty_out (vty
, "%s", VTY_NEWLINE
);
1578 vty_complete_command (vty
);
1581 if (vty
->node
== AUTH_NODE
|| vty
->node
== AUTH_ENABLE_NODE
)
1582 vty_self_insert (vty
, buf
[i
]);
1584 vty_describe_command (vty
);
1587 if (i
+ 1 < nbytes
&& buf
[i
+ 1] == '[')
1589 vty
->escape
= VTY_ESCAPE
;
1593 vty
->escape
= VTY_PRE_ESCAPE
;
1596 if (buf
[i
] > 31 && buf
[i
] < 127)
1597 vty_self_insert (vty
, buf
[i
]);
1603 if (vty
->status
== VTY_CLOSE
)
1607 vty_event (VTY_WRITE
, vty
->wfd
, vty
);
1608 vty_event (VTY_READ
, vty_sock
, vty
);
1613 /* Flush buffer to the vty. */
1615 vty_flush (struct thread
*thread
)
1618 buffer_status_t flushrc
;
1619 int vty_sock
= THREAD_FD (thread
);
1620 struct vty
*vty
= THREAD_ARG (thread
);
1622 vty
->t_write
= NULL
;
1624 /* Tempolary disable read thread. */
1625 if ((vty
->lines
== 0) && vty
->t_read
)
1627 thread_cancel (vty
->t_read
);
1631 /* Function execution continue. */
1632 erase
= ((vty
->status
== VTY_MORE
|| vty
->status
== VTY_MORELINE
));
1634 /* N.B. if width is 0, that means we don't know the window size. */
1635 if ((vty
->lines
== 0) || (vty
->width
== 0) || (vty
->height
== 0))
1636 flushrc
= buffer_flush_available(vty
->obuf
, vty_sock
);
1637 else if (vty
->status
== VTY_MORELINE
)
1638 flushrc
= buffer_flush_window(vty
->obuf
, vty_sock
, vty
->width
,
1641 flushrc
= buffer_flush_window(vty
->obuf
, vty_sock
, vty
->width
,
1642 vty
->lines
>= 0 ? vty
->lines
:
1648 vty
->monitor
= 0; /* disable monitoring to avoid infinite recursion */
1649 zlog_warn("buffer_flush failed on vty client fd %d, closing",
1651 buffer_reset(vty
->obuf
);
1655 if (vty
->status
== VTY_CLOSE
)
1659 vty
->status
= VTY_NORMAL
;
1660 if (vty
->lines
== 0)
1661 vty_event (VTY_READ
, vty_sock
, vty
);
1664 case BUFFER_PENDING
:
1665 /* There is more data waiting to be written. */
1666 vty
->status
= VTY_MORE
;
1667 if (vty
->lines
== 0)
1668 vty_event (VTY_WRITE
, vty_sock
, vty
);
1675 /* allocate and initialise vty */
1677 vty_new_init (int vty_sock
)
1683 vty
->wfd
= vty_sock
;
1684 vty
->type
= VTY_TERM
;
1685 vty
->node
= AUTH_NODE
;
1688 vty_clear_buf (vty
);
1690 memset (vty
->hist
, 0, sizeof (vty
->hist
));
1693 vector_set_index (vtyvec
, vty_sock
, vty
);
1694 vty
->status
= VTY_NORMAL
;
1697 vty
->iac_sb_in_progress
= 0;
1703 /* Create new vty structure. */
1705 vty_create (int vty_sock
, union sockunion
*su
)
1707 char buf
[SU_ADDRSTRLEN
];
1710 sockunion2str(su
, buf
, SU_ADDRSTRLEN
);
1712 /* Allocate new vty structure and set up default values. */
1713 vty
= vty_new_init (vty_sock
);
1715 /* configurable parameters not part of basic init */
1716 vty
->v_timeout
= vty_timeout_val
;
1717 strcpy (vty
->address
, buf
);
1718 if (no_password_check
)
1721 vty
->node
= ENABLE_NODE
;
1723 vty
->node
= VIEW_NODE
;
1725 if (host
.lines
>= 0)
1726 vty
->lines
= host
.lines
;
1728 if (! no_password_check
)
1730 /* Vty is not available if password isn't set. */
1731 if (host
.password
== NULL
&& host
.password_encrypt
== NULL
)
1733 vty_out (vty
, "Vty password is not set.%s", VTY_NEWLINE
);
1734 vty
->status
= VTY_CLOSE
;
1740 /* Say hello to the world. */
1742 if (! no_password_check
)
1743 vty_out (vty
, "%sUser Access Verification%s%s", VTY_NEWLINE
, VTY_NEWLINE
, VTY_NEWLINE
);
1745 /* Setting up terminal. */
1746 vty_will_echo (vty
);
1747 vty_will_suppress_go_ahead (vty
);
1749 vty_dont_linemode (vty
);
1750 vty_do_window_size (vty
);
1751 /* vty_dont_lflow_ahead (vty); */
1755 /* Add read/write thread. */
1756 vty_event (VTY_WRITE
, vty_sock
, vty
);
1757 vty_event (VTY_READ
, vty_sock
, vty
);
1762 /* create vty for stdio */
1763 static struct termios stdio_orig_termios
;
1764 static struct vty
*stdio_vty
= NULL
;
1765 static void (*stdio_vty_atclose
)(void);
1768 vty_stdio_reset (void)
1772 tcsetattr (0, TCSANOW
, &stdio_orig_termios
);
1775 if (stdio_vty_atclose
)
1776 stdio_vty_atclose ();
1777 stdio_vty_atclose
= NULL
;
1782 vty_stdio (void (*atclose
)())
1785 struct termios termios
;
1787 /* refuse creating two vtys on stdio */
1791 vty
= stdio_vty
= vty_new_init (0);
1792 stdio_vty_atclose
= atclose
;
1795 /* always have stdio vty in a known _unchangeable_ state, don't want config
1796 * to have any effect here to make sure scripting this works as intended */
1797 vty
->node
= ENABLE_NODE
;
1799 strcpy (vty
->address
, "console");
1801 if (!tcgetattr (0, &stdio_orig_termios
))
1803 termios
= stdio_orig_termios
;
1804 termios
.c_iflag
&= ~(IGNBRK
| BRKINT
| PARMRK
| ISTRIP
1805 | INLCR
| IGNCR
| ICRNL
| IXON
);
1806 termios
.c_oflag
&= ~OPOST
;
1807 termios
.c_lflag
&= ~(ECHO
| ECHONL
| ICANON
| ISIG
| IEXTEN
);
1808 termios
.c_cflag
&= ~(CSIZE
| PARENB
);
1809 termios
.c_cflag
|= CS8
;
1810 tcsetattr (0, TCSANOW
, &termios
);
1815 /* Add read/write thread. */
1816 vty_event (VTY_WRITE
, 1, vty
);
1817 vty_event (VTY_READ
, 0, vty
);
1822 /* Accept connection from the network. */
1824 vty_accept (struct thread
*thread
)
1832 struct access_list
*acl
= NULL
;
1833 char buf
[SU_ADDRSTRLEN
];
1835 accept_sock
= THREAD_FD (thread
);
1837 /* We continue hearing vty socket. */
1838 vty_event (VTY_SERV
, accept_sock
, NULL
);
1840 memset (&su
, 0, sizeof (union sockunion
));
1842 /* We can handle IPv4 or IPv6 socket. */
1843 vty_sock
= sockunion_accept (accept_sock
, &su
);
1846 zlog_warn ("can't accept vty socket : %s", safe_strerror (errno
));
1849 set_nonblocking(vty_sock
);
1850 set_cloexec(vty_sock
);
1852 sockunion2hostprefix (&su
, &p
);
1854 /* VTY's accesslist apply. */
1855 if (p
.family
== AF_INET
&& vty_accesslist_name
)
1857 if ((acl
= access_list_lookup (AFI_IP
, vty_accesslist_name
)) &&
1858 (access_list_apply (acl
, &p
) == FILTER_DENY
))
1860 zlog_info ("Vty connection refused from %s",
1861 sockunion2str (&su
, buf
, SU_ADDRSTRLEN
));
1864 /* continue accepting connections */
1865 vty_event (VTY_SERV
, accept_sock
, NULL
);
1871 /* VTY's ipv6 accesslist apply. */
1872 if (p
.family
== AF_INET6
&& vty_ipv6_accesslist_name
)
1874 if ((acl
= access_list_lookup (AFI_IP6
, vty_ipv6_accesslist_name
)) &&
1875 (access_list_apply (acl
, &p
) == FILTER_DENY
))
1877 zlog_info ("Vty connection refused from %s",
1878 sockunion2str (&su
, buf
, SU_ADDRSTRLEN
));
1881 /* continue accepting connections */
1882 vty_event (VTY_SERV
, accept_sock
, NULL
);
1889 ret
= setsockopt (vty_sock
, IPPROTO_TCP
, TCP_NODELAY
,
1890 (char *) &on
, sizeof (on
));
1892 zlog_info ("can't set sockopt to vty_sock : %s",
1893 safe_strerror (errno
));
1895 zlog_info ("Vty connection from %s",
1896 sockunion2str (&su
, buf
, SU_ADDRSTRLEN
));
1898 vty_create (vty_sock
, &su
);
1904 vty_serv_sock_addrinfo (const char *hostname
, unsigned short port
)
1907 struct addrinfo req
;
1908 struct addrinfo
*ainfo
;
1909 struct addrinfo
*ainfo_save
;
1911 char port_str
[BUFSIZ
];
1913 memset (&req
, 0, sizeof (struct addrinfo
));
1914 req
.ai_flags
= AI_PASSIVE
;
1915 req
.ai_family
= AF_UNSPEC
;
1916 req
.ai_socktype
= SOCK_STREAM
;
1917 sprintf (port_str
, "%d", port
);
1918 port_str
[sizeof (port_str
) - 1] = '\0';
1920 ret
= getaddrinfo (hostname
, port_str
, &req
, &ainfo
);
1924 fprintf (stderr
, "getaddrinfo failed: %s\n", gai_strerror (ret
));
1932 if (ainfo
->ai_family
!= AF_INET
1933 && ainfo
->ai_family
!= AF_INET6
1937 sock
= socket (ainfo
->ai_family
, ainfo
->ai_socktype
, ainfo
->ai_protocol
);
1941 sockopt_v6only (ainfo
->ai_family
, sock
);
1942 sockopt_reuseaddr (sock
);
1943 sockopt_reuseport (sock
);
1946 ret
= bind (sock
, ainfo
->ai_addr
, ainfo
->ai_addrlen
);
1949 close (sock
); /* Avoid sd leak. */
1953 ret
= listen (sock
, 3);
1956 close (sock
); /* Avoid sd leak. */
1960 vty_event (VTY_SERV
, sock
, NULL
);
1962 while ((ainfo
= ainfo
->ai_next
) != NULL
);
1964 freeaddrinfo (ainfo_save
);
1968 /* For sockaddr_un. */
1971 /* VTY shell UNIX domain socket. */
1973 vty_serv_un (const char *path
)
1977 struct sockaddr_un serv
;
1979 struct zprivs_ids_t ids
;
1981 /* First of all, unlink existing socket */
1985 old_mask
= umask (0007);
1987 /* Make UNIX domain socket. */
1988 sock
= socket (AF_UNIX
, SOCK_STREAM
, 0);
1991 zlog_err("Cannot create unix stream socket: %s", safe_strerror(errno
));
1995 /* Make server socket. */
1996 memset (&serv
, 0, sizeof (struct sockaddr_un
));
1997 serv
.sun_family
= AF_UNIX
;
1998 strlcpy (serv
.sun_path
, path
, sizeof (serv
.sun_path
));
1999 #ifdef HAVE_STRUCT_SOCKADDR_UN_SUN_LEN
2000 len
= serv
.sun_len
= SUN_LEN(&serv
);
2002 len
= sizeof (serv
.sun_family
) + strlen (serv
.sun_path
);
2003 #endif /* HAVE_STRUCT_SOCKADDR_UN_SUN_LEN */
2007 ret
= bind (sock
, (struct sockaddr
*) &serv
, len
);
2010 zlog_err("Cannot bind path %s: %s", path
, safe_strerror(errno
));
2011 close (sock
); /* Avoid sd leak. */
2015 ret
= listen (sock
, 5);
2018 zlog_err("listen(fd %d) failed: %s", sock
, safe_strerror(errno
));
2019 close (sock
); /* Avoid sd leak. */
2025 zprivs_get_ids(&ids
);
2027 /* Hack: ids.gid_vty is actually a uint, but we stored -1 in it
2028 earlier for the case when we don't need to chown the file
2029 type casting it here to make a compare */
2030 if ((int)ids
.gid_vty
> 0)
2032 /* set group of socket */
2033 if ( chown (path
, -1, ids
.gid_vty
) )
2035 zlog_err ("vty_serv_un: could chown socket, %s",
2036 safe_strerror (errno
) );
2040 vty_event (VTYSH_SERV
, sock
, NULL
);
2043 /* #define VTYSH_DEBUG 1 */
2046 vtysh_accept (struct thread
*thread
)
2051 struct sockaddr_un client
;
2054 accept_sock
= THREAD_FD (thread
);
2056 vty_event (VTYSH_SERV
, accept_sock
, NULL
);
2058 memset (&client
, 0, sizeof (struct sockaddr_un
));
2059 client_len
= sizeof (struct sockaddr_un
);
2061 sock
= accept (accept_sock
, (struct sockaddr
*) &client
,
2062 (socklen_t
*) &client_len
);
2066 zlog_warn ("can't accept vty socket : %s", safe_strerror (errno
));
2070 if (set_nonblocking(sock
) < 0)
2072 zlog_warn ("vtysh_accept: could not set vty socket %d to non-blocking,"
2073 " %s, closing", sock
, safe_strerror (errno
));
2080 printf ("VTY shell accept\n");
2081 #endif /* VTYSH_DEBUG */
2086 vty
->type
= VTY_SHELL_SERV
;
2087 vty
->node
= VIEW_NODE
;
2089 vty_event (VTYSH_READ
, sock
, vty
);
2095 vtysh_flush(struct vty
*vty
)
2097 switch (buffer_flush_available(vty
->obuf
, vty
->wfd
))
2099 case BUFFER_PENDING
:
2100 vty_event(VTYSH_WRITE
, vty
->wfd
, vty
);
2103 vty
->monitor
= 0; /* disable monitoring to avoid infinite recursion */
2104 zlog_warn("%s: write error to fd %d, closing", __func__
, vty
->fd
);
2105 buffer_reset(vty
->obuf
);
2116 vtysh_read (struct thread
*thread
)
2122 unsigned char buf
[VTY_READ_BUFSIZ
];
2124 u_char header
[4] = {0, 0, 0, 0};
2126 sock
= THREAD_FD (thread
);
2127 vty
= THREAD_ARG (thread
);
2130 if ((nbytes
= read (sock
, buf
, VTY_READ_BUFSIZ
)) <= 0)
2134 if (ERRNO_IO_RETRY(errno
))
2136 vty_event (VTYSH_READ
, sock
, vty
);
2139 vty
->monitor
= 0; /* disable monitoring to avoid infinite recursion */
2140 zlog_warn("%s: read failed on vtysh client fd %d, closing: %s",
2141 __func__
, sock
, safe_strerror(errno
));
2143 buffer_reset(vty
->obuf
);
2146 printf ("close vtysh\n");
2147 #endif /* VTYSH_DEBUG */
2152 printf ("line: %.*s\n", nbytes
, buf
);
2153 #endif /* VTYSH_DEBUG */
2155 if (vty
->length
+ nbytes
>= VTY_BUFSIZ
)
2157 /* Clear command line buffer. */
2158 vty
->cp
= vty
->length
= 0;
2159 vty_clear_buf (vty
);
2160 vty_out (vty
, "%% Command is too long.%s", VTY_NEWLINE
);
2164 for (p
= buf
; p
< buf
+nbytes
; p
++)
2166 vty
->buf
[vty
->length
++] = *p
;
2169 /* Pass this line to parser. */
2170 ret
= vty_execute (vty
);
2171 /* Note that vty_execute clears the command buffer and resets
2172 vty->length to 0. */
2174 /* Return result. */
2176 printf ("result: %d\n", ret
);
2177 printf ("vtysh node: %d\n", vty
->node
);
2178 #endif /* VTYSH_DEBUG */
2180 /* hack for asynchronous "write integrated"
2181 * - other commands in "buf" will be ditched
2182 * - input during pending config-write is "unsupported" */
2183 if (ret
== CMD_SUSPEND
)
2186 /* warning: watchquagga hardcodes this result write */
2188 buffer_put(vty
->obuf
, header
, 4);
2190 if (!vty
->t_write
&& (vtysh_flush(vty
) < 0))
2191 /* Try to flush results; exit if a write error occurs. */
2197 vty_event (VTYSH_READ
, sock
, vty
);
2203 vtysh_write (struct thread
*thread
)
2205 struct vty
*vty
= THREAD_ARG (thread
);
2207 vty
->t_write
= NULL
;
2214 /* Determine address family to bind. */
2216 vty_serv_sock (const char *addr
, unsigned short port
, const char *path
)
2218 /* If port is set to 0, do not listen on TCP/IP at all! */
2220 vty_serv_sock_addrinfo (addr
, port
);
2227 /* Close vty interface. Warning: call this only from functions that
2228 will be careful not to access the vty afterwards (since it has
2229 now been freed). This is safest from top-level functions (called
2230 directly by the thread dispatcher). */
2232 vty_close (struct vty
*vty
)
2235 bool was_stdio
= false;
2237 /* Cancel threads.*/
2239 thread_cancel (vty
->t_read
);
2241 thread_cancel (vty
->t_write
);
2243 thread_cancel (vty
->t_timeout
);
2246 buffer_flush_all (vty
->obuf
, vty
->wfd
);
2248 /* Free input buffer. */
2249 buffer_free (vty
->obuf
);
2251 /* Free command history. */
2252 for (i
= 0; i
< VTY_MAXHIST
; i
++)
2254 XFREE (MTYPE_VTY_HIST
, vty
->hist
[i
]);
2257 vector_unset (vtyvec
, vty
->fd
);
2259 if (vty
->wfd
> 0 && vty
->type
== VTY_FILE
)
2266 if (vty
->wfd
> 0 && vty
->wfd
!= vty
->fd
)
2273 XFREE (MTYPE_VTY
, vty
->buf
);
2276 XFREE (MTYPE_VTY
, vty
->error_buf
);
2278 /* Check configure. */
2279 vty_config_unlock (vty
);
2282 XFREE (MTYPE_VTY
, vty
);
2288 /* When time out occur output message then close connection. */
2290 vty_timeout (struct thread
*thread
)
2294 vty
= THREAD_ARG (thread
);
2295 vty
->t_timeout
= NULL
;
2299 buffer_reset (vty
->obuf
);
2300 vty_out (vty
, "%sVty connection is timed out.%s", VTY_NEWLINE
, VTY_NEWLINE
);
2302 /* Close connection. */
2303 vty
->status
= VTY_CLOSE
;
2309 /* Read up configuration file from file_name. */
2311 vty_read_file (FILE *confp
)
2315 unsigned int line_num
= 0;
2318 vty
->wfd
= dup(STDERR_FILENO
); /* vty_close() will close this */
2321 /* Fine, we couldn't make a new fd. vty_close doesn't close stdout. */
2322 vty
->wfd
= STDOUT_FILENO
;
2324 vty
->fd
= STDIN_FILENO
;
2325 vty
->type
= VTY_FILE
;
2326 vty
->node
= CONFIG_NODE
;
2328 /* Execute configuration file */
2329 ret
= config_from_file (vty
, confp
, &line_num
);
2331 /* Flush any previous errors before printing messages below */
2332 buffer_flush_all (vty
->obuf
, vty
->fd
);
2334 if ( !((ret
== CMD_SUCCESS
) || (ret
== CMD_ERR_NOTHING_TODO
)) )
2336 const char *message
= NULL
;
2339 case CMD_ERR_AMBIGUOUS
:
2340 message
= "*** Error reading config: Ambiguous command.";
2342 case CMD_ERR_NO_MATCH
:
2343 message
= "*** Error reading config: There is no such command.";
2346 fprintf (stderr
, "%s\n", message
);
2347 zlog_err ("%s", message
);
2348 fprintf (stderr
, "*** Error occurred processing line %u, below:\n%s\n",
2349 line_num
, vty
->error_buf
);
2350 zlog_err ("*** Error occurred processing line %u, below:\n%s",
2351 line_num
, vty
->error_buf
);
2358 vty_use_backup_config (const char *fullpath
)
2360 char *fullpath_sav
, *fullpath_tmp
;
2366 fullpath_sav
= malloc (strlen (fullpath
) + strlen (CONF_BACKUP_EXT
) + 1);
2367 strcpy (fullpath_sav
, fullpath
);
2368 strcat (fullpath_sav
, CONF_BACKUP_EXT
);
2370 sav
= open (fullpath_sav
, O_RDONLY
);
2373 free (fullpath_sav
);
2377 fullpath_tmp
= malloc (strlen (fullpath
) + 8);
2378 sprintf (fullpath_tmp
, "%s.XXXXXX", fullpath
);
2380 /* Open file to configuration write. */
2381 tmp
= mkstemp (fullpath_tmp
);
2385 if (fchmod (tmp
, CONFIGFILE_MASK
) != 0)
2388 while((c
= read (sav
, buffer
, 512)) > 0)
2390 if (write (tmp
, buffer
, c
) <= 0)
2396 if (rename (fullpath_tmp
, fullpath
) == 0)
2397 ret
= fopen (fullpath
, "r");
2399 unlink (fullpath_tmp
);
2405 unlink (fullpath_tmp
);
2410 free (fullpath_sav
);
2411 free (fullpath_tmp
);
2415 /* Read up configuration file from file_name. */
2417 vty_read_config (const char *config_file
,
2418 char *config_default_dir
)
2420 char cwd
[MAXPATHLEN
];
2422 const char *fullpath
;
2425 /* If -f flag specified. */
2426 if (config_file
!= NULL
)
2428 if (! IS_DIRECTORY_SEP (config_file
[0]))
2430 if (getcwd (cwd
, MAXPATHLEN
) == NULL
)
2432 fprintf (stderr
, "Failure to determine Current Working Directory %d!\n", errno
);
2435 tmp
= XMALLOC (MTYPE_TMP
,
2436 strlen (cwd
) + strlen (config_file
) + 2);
2437 sprintf (tmp
, "%s/%s", cwd
, config_file
);
2441 fullpath
= config_file
;
2443 confp
= fopen (fullpath
, "r");
2447 fprintf (stderr
, "%s: failed to open configuration file %s: %s\n",
2448 __func__
, fullpath
, safe_strerror (errno
));
2450 confp
= vty_use_backup_config (fullpath
);
2452 fprintf (stderr
, "WARNING: using backup configuration file!\n");
2455 fprintf (stderr
, "can't open configuration file [%s]\n",
2464 host_config_set (config_default_dir
);
2468 struct stat conf_stat
;
2470 /* !!!!PLEASE LEAVE!!!!
2471 * This is NEEDED for use with vtysh -b, or else you can get
2472 * a real configuration food fight with a lot garbage in the
2473 * merged configuration file it creates coming from the per
2474 * daemon configuration files. This also allows the daemons
2475 * to start if there default configuration file is not
2476 * present or ignore them, as needed when using vtysh -b to
2477 * configure the daemons at boot - MAG
2480 /* Stat for vtysh Zebra.conf, if found startup and wait for
2481 * boot configuration
2484 if ( strstr(config_default_dir
, "vtysh") == NULL
)
2486 ret
= stat (integrate_default
, &conf_stat
);
2488 goto tmp_free_and_out
;
2491 confp
= fopen (config_default_dir
, "r");
2494 fprintf (stderr
, "%s: failed to open configuration file %s: %s\n",
2495 __func__
, config_default_dir
, safe_strerror (errno
));
2497 confp
= vty_use_backup_config (config_default_dir
);
2500 fprintf (stderr
, "WARNING: using backup configuration file!\n");
2501 fullpath
= config_default_dir
;
2505 fprintf (stderr
, "can't open configuration file [%s]\n",
2506 config_default_dir
);
2507 goto tmp_free_and_out
;
2511 fullpath
= config_default_dir
;
2514 vty_read_file (confp
);
2518 host_config_set (fullpath
);
2522 XFREE (MTYPE_TMP
, tmp
);
2525 /* Small utility function which output log to the VTY. */
2527 vty_log (const char *level
, const char *proto_str
,
2528 const char *format
, struct timestamp_control
*ctl
, va_list va
)
2536 for (i
= 0; i
< vector_active (vtyvec
); i
++)
2537 if ((vty
= vector_slot (vtyvec
, i
)) != NULL
)
2542 vty_log_out (vty
, level
, proto_str
, format
, ctl
, ac
);
2547 /* Async-signal-safe version of vty_log for fixed strings. */
2549 vty_log_fixed (char *buf
, size_t len
)
2552 struct iovec iov
[2];
2553 char crlf
[4] = "\r\n";
2555 /* vty may not have been initialised */
2559 iov
[0].iov_base
= buf
;
2560 iov
[0].iov_len
= len
;
2561 iov
[1].iov_base
= crlf
;
2564 for (i
= 0; i
< vector_active (vtyvec
); i
++)
2567 if (((vty
= vector_slot (vtyvec
, i
)) != NULL
) && vty
->monitor
)
2568 /* N.B. We don't care about the return code, since process is
2569 most likely just about to die anyway. */
2570 if (writev(vty
->wfd
, iov
, 2) == -1)
2572 fprintf(stderr
, "Failure to writev: %d\n", errno
);
2579 vty_config_lock (struct vty
*vty
)
2581 if (vty_config_is_lockless
)
2583 if (vty_config
== 0)
2592 vty_config_unlock (struct vty
*vty
)
2594 if (vty_config_is_lockless
)
2596 if (vty_config
== 1 && vty
->config
== 1)
2605 vty_config_lockless (void)
2607 vty_config_is_lockless
= 1;
2610 /* Master of the threads. */
2611 static struct thread_master
*vty_master
;
2614 vty_event (enum event event
, int sock
, struct vty
*vty
)
2616 struct thread
*vty_serv_thread
;
2621 vty_serv_thread
= thread_add_read (vty_master
, vty_accept
, vty
, sock
);
2622 vector_set_index (Vvty_serv_thread
, sock
, vty_serv_thread
);
2626 vty_serv_thread
= thread_add_read (vty_master
, vtysh_accept
, vty
, sock
);
2627 vector_set_index (Vvty_serv_thread
, sock
, vty_serv_thread
);
2630 vty
->t_read
= thread_add_read (vty_master
, vtysh_read
, vty
, sock
);
2633 vty
->t_write
= thread_add_write (vty_master
, vtysh_write
, vty
, sock
);
2637 vty
->t_read
= thread_add_read (vty_master
, vty_read
, vty
, sock
);
2639 /* Time out treatment. */
2643 thread_cancel (vty
->t_timeout
);
2645 thread_add_timer (vty_master
, vty_timeout
, vty
, vty
->v_timeout
);
2650 vty
->t_write
= thread_add_write (vty_master
, vty_flush
, vty
, sock
);
2652 case VTY_TIMEOUT_RESET
:
2655 thread_cancel (vty
->t_timeout
);
2656 vty
->t_timeout
= NULL
;
2661 thread_add_timer (vty_master
, vty_timeout
, vty
, vty
->v_timeout
);
2667 DEFUN_NOSH (config_who
,
2670 "Display who is on vty\n")
2675 for (i
= 0; i
< vector_active (vtyvec
); i
++)
2676 if ((v
= vector_slot (vtyvec
, i
)) != NULL
)
2677 vty_out (vty
, "%svty[%d] connected from %s.%s",
2678 v
->config
? "*" : " ",
2679 i
, v
->address
, VTY_NEWLINE
);
2683 /* Move to vty configuration mode. */
2684 DEFUN_NOSH (line_vty
,
2687 "Configure a terminal line\n"
2688 "Virtual terminal\n")
2690 vty
->node
= VTY_NODE
;
2694 /* Set time out value. */
2696 exec_timeout (struct vty
*vty
, const char *min_str
, const char *sec_str
)
2698 unsigned long timeout
= 0;
2700 /* min_str and sec_str are already checked by parser. So it must be
2701 all digit string. */
2704 timeout
= strtol (min_str
, NULL
, 10);
2708 timeout
+= strtol (sec_str
, NULL
, 10);
2710 vty_timeout_val
= timeout
;
2711 vty
->v_timeout
= timeout
;
2712 vty_event (VTY_TIMEOUT_RESET
, 0, vty
);
2718 DEFUN (exec_timeout_min
,
2719 exec_timeout_min_cmd
,
2720 "exec-timeout (0-35791)",
2721 "Set timeout value\n"
2722 "Timeout value in minutes\n")
2725 return exec_timeout (vty
, argv
[idx_number
]->arg
, NULL
);
2728 DEFUN (exec_timeout_sec
,
2729 exec_timeout_sec_cmd
,
2730 "exec-timeout (0-35791) (0-2147483)",
2731 "Set the EXEC timeout\n"
2732 "Timeout in minutes\n"
2733 "Timeout in seconds\n")
2736 int idx_number_2
= 2;
2737 return exec_timeout (vty
, argv
[idx_number
]->arg
, argv
[idx_number_2
]->arg
);
2740 DEFUN (no_exec_timeout
,
2741 no_exec_timeout_cmd
,
2744 "Set the EXEC timeout\n")
2746 return exec_timeout (vty
, NULL
, NULL
);
2749 /* Set vty access class. */
2750 DEFUN (vty_access_class
,
2751 vty_access_class_cmd
,
2752 "access-class WORD",
2753 "Filter connections based on an IP access list\n"
2757 if (vty_accesslist_name
)
2758 XFREE(MTYPE_VTY
, vty_accesslist_name
);
2760 vty_accesslist_name
= XSTRDUP(MTYPE_VTY
, argv
[idx_word
]->arg
);
2765 /* Clear vty access class. */
2766 DEFUN (no_vty_access_class
,
2767 no_vty_access_class_cmd
,
2768 "no access-class [WORD]",
2770 "Filter connections based on an IP access list\n"
2774 const char *accesslist
= (argc
== 3) ? argv
[idx_word
]->arg
: NULL
;
2775 if (! vty_accesslist_name
|| (argc
== 3 && strcmp(vty_accesslist_name
, accesslist
)))
2777 vty_out (vty
, "Access-class is not currently applied to vty%s",
2782 XFREE(MTYPE_VTY
, vty_accesslist_name
);
2784 vty_accesslist_name
= NULL
;
2789 /* Set vty access class. */
2790 DEFUN (vty_ipv6_access_class
,
2791 vty_ipv6_access_class_cmd
,
2792 "ipv6 access-class WORD",
2794 "Filter connections based on an IP access list\n"
2795 "IPv6 access list\n")
2798 if (vty_ipv6_accesslist_name
)
2799 XFREE(MTYPE_VTY
, vty_ipv6_accesslist_name
);
2801 vty_ipv6_accesslist_name
= XSTRDUP(MTYPE_VTY
, argv
[idx_word
]->arg
);
2806 /* Clear vty access class. */
2807 DEFUN (no_vty_ipv6_access_class
,
2808 no_vty_ipv6_access_class_cmd
,
2809 "no ipv6 access-class [WORD]",
2812 "Filter connections based on an IP access list\n"
2813 "IPv6 access list\n")
2816 const char *accesslist
= (argc
== 4) ? argv
[idx_word
]->arg
: NULL
;
2818 if (! vty_ipv6_accesslist_name
||
2819 (argc
== 4 && strcmp(vty_ipv6_accesslist_name
, accesslist
)))
2821 vty_out (vty
, "IPv6 access-class is not currently applied to vty%s",
2826 XFREE(MTYPE_VTY
, vty_ipv6_accesslist_name
);
2828 vty_ipv6_accesslist_name
= NULL
;
2837 "Enable password checking\n")
2839 no_password_check
= 0;
2843 DEFUN (no_vty_login
,
2847 "Enable password checking\n")
2849 no_password_check
= 1;
2853 DEFUN (service_advanced_vty
,
2854 service_advanced_vty_cmd
,
2855 "service advanced-vty",
2856 "Set up miscellaneous service\n"
2857 "Enable advanced mode vty interface\n")
2863 DEFUN (no_service_advanced_vty
,
2864 no_service_advanced_vty_cmd
,
2865 "no service advanced-vty",
2867 "Set up miscellaneous service\n"
2868 "Enable advanced mode vty interface\n")
2874 DEFUN_NOSH (terminal_monitor
,
2875 terminal_monitor_cmd
,
2877 "Set terminal line parameters\n"
2878 "Copy debug output to the current terminal line\n")
2884 DEFUN_NOSH (terminal_no_monitor
,
2885 terminal_no_monitor_cmd
,
2886 "terminal no monitor",
2887 "Set terminal line parameters\n"
2889 "Copy debug output to the current terminal line\n")
2895 DEFUN_NOSH (no_terminal_monitor
,
2896 no_terminal_monitor_cmd
,
2897 "no terminal monitor",
2899 "Set terminal line parameters\n"
2900 "Copy debug output to the current terminal line\n")
2902 return terminal_no_monitor (self
, vty
, argc
, argv
);
2906 DEFUN_NOSH (show_history
,
2910 "Display the session command history\n")
2914 for (index
= vty
->hindex
+ 1; index
!= vty
->hindex
;)
2916 if (index
== VTY_MAXHIST
)
2922 if (vty
->hist
[index
] != NULL
)
2923 vty_out (vty
, " %s%s", vty
->hist
[index
], VTY_NEWLINE
);
2932 DEFUN (log_commands
,
2936 "Log all commands (can't be unset without restart)\n")
2938 do_log_commands
= 1;
2942 /* Display current configuration. */
2944 vty_config_write (struct vty
*vty
)
2946 vty_out (vty
, "line vty%s", VTY_NEWLINE
);
2948 if (vty_accesslist_name
)
2949 vty_out (vty
, " access-class %s%s",
2950 vty_accesslist_name
, VTY_NEWLINE
);
2952 if (vty_ipv6_accesslist_name
)
2953 vty_out (vty
, " ipv6 access-class %s%s",
2954 vty_ipv6_accesslist_name
, VTY_NEWLINE
);
2957 if (vty_timeout_val
!= VTY_TIMEOUT_DEFAULT
)
2958 vty_out (vty
, " exec-timeout %ld %ld%s",
2959 vty_timeout_val
/ 60,
2960 vty_timeout_val
% 60, VTY_NEWLINE
);
2963 if (no_password_check
)
2964 vty_out (vty
, " no login%s", VTY_NEWLINE
);
2966 if (do_log_commands
)
2967 vty_out (vty
, "log commands%s", VTY_NEWLINE
);
2969 vty_out (vty
, "!%s", VTY_NEWLINE
);
2974 struct cmd_node vty_node
=
2977 "%s(config-line)# ",
2981 /* Reset all VTY status. */
2987 struct thread
*vty_serv_thread
;
2989 for (i
= 0; i
< vector_active (vtyvec
); i
++)
2990 if ((vty
= vector_slot (vtyvec
, i
)) != NULL
)
2992 buffer_reset (vty
->obuf
);
2993 vty
->status
= VTY_CLOSE
;
2997 for (i
= 0; i
< vector_active (Vvty_serv_thread
); i
++)
2998 if ((vty_serv_thread
= vector_slot (Vvty_serv_thread
, i
)) != NULL
)
3000 thread_cancel (vty_serv_thread
);
3001 vector_slot (Vvty_serv_thread
, i
) = NULL
;
3005 vty_timeout_val
= VTY_TIMEOUT_DEFAULT
;
3007 if (vty_accesslist_name
)
3009 XFREE(MTYPE_VTY
, vty_accesslist_name
);
3010 vty_accesslist_name
= NULL
;
3013 if (vty_ipv6_accesslist_name
)
3015 XFREE(MTYPE_VTY
, vty_ipv6_accesslist_name
);
3016 vty_ipv6_accesslist_name
= NULL
;
3023 char cwd
[MAXPATHLEN
];
3026 c
= getcwd (cwd
, MAXPATHLEN
);
3031 * At this point if these go wrong, more than likely
3032 * the whole world is coming down around us
3033 * Hence not worrying about it too much.
3035 if (!chdir (SYSCONFDIR
))
3037 fprintf(stderr
, "Failure to chdir to %s, errno: %d\n", SYSCONFDIR
, errno
);
3040 if (getcwd (cwd
, MAXPATHLEN
) == NULL
)
3042 fprintf(stderr
, "Failure to getcwd, errno: %d\n", errno
);
3047 vty_cwd
= XMALLOC (MTYPE_TMP
, strlen (cwd
) + 1);
3048 strcpy (vty_cwd
, cwd
);
3058 vty_shell (struct vty
*vty
)
3060 return vty
->type
== VTY_SHELL
? 1 : 0;
3064 vty_shell_serv (struct vty
*vty
)
3066 return vty
->type
== VTY_SHELL_SERV
? 1 : 0;
3072 vtyvec
= vector_init (VECTOR_MIN_SIZE
);
3075 /* Install vty's own commands like `who' command. */
3077 vty_init (struct thread_master
*master_thread
)
3079 /* For further configuration read, preserve current directory. */
3082 vtyvec
= vector_init (VECTOR_MIN_SIZE
);
3084 vty_master
= master_thread
;
3086 atexit (vty_stdio_reset
);
3088 /* Initilize server thread vector. */
3089 Vvty_serv_thread
= vector_init (VECTOR_MIN_SIZE
);
3091 /* Install bgp top node. */
3092 install_node (&vty_node
, vty_config_write
);
3094 install_element (VIEW_NODE
, &config_who_cmd
);
3095 install_element (VIEW_NODE
, &show_history_cmd
);
3096 install_element (CONFIG_NODE
, &line_vty_cmd
);
3097 install_element (CONFIG_NODE
, &service_advanced_vty_cmd
);
3098 install_element (CONFIG_NODE
, &no_service_advanced_vty_cmd
);
3099 install_element (CONFIG_NODE
, &show_history_cmd
);
3100 install_element (CONFIG_NODE
, &log_commands_cmd
);
3101 install_element (ENABLE_NODE
, &terminal_monitor_cmd
);
3102 install_element (ENABLE_NODE
, &terminal_no_monitor_cmd
);
3103 install_element (ENABLE_NODE
, &no_terminal_monitor_cmd
);
3105 install_default (VTY_NODE
);
3106 install_element (VTY_NODE
, &exec_timeout_min_cmd
);
3107 install_element (VTY_NODE
, &exec_timeout_sec_cmd
);
3108 install_element (VTY_NODE
, &no_exec_timeout_cmd
);
3109 install_element (VTY_NODE
, &vty_access_class_cmd
);
3110 install_element (VTY_NODE
, &no_vty_access_class_cmd
);
3111 install_element (VTY_NODE
, &vty_login_cmd
);
3112 install_element (VTY_NODE
, &no_vty_login_cmd
);
3113 install_element (VTY_NODE
, &vty_ipv6_access_class_cmd
);
3114 install_element (VTY_NODE
, &no_vty_ipv6_access_class_cmd
);
3118 vty_terminate (void)
3121 XFREE (MTYPE_TMP
, vty_cwd
);
3123 if (vtyvec
&& Vvty_serv_thread
)
3126 vector_free (vtyvec
);
3127 vector_free (Vvty_serv_thread
);
3129 Vvty_serv_thread
= NULL
;
3133 /* Utility functions to get arguments from commands generated
3134 by the xml2cli.pl script. */
3136 vty_get_arg_value (struct vty_arg
*args
[], const char *arg
)
3140 if (strcmp ((*args
)->name
, arg
) == 0)
3141 return (*args
)->value
;
3148 vty_get_arg (struct vty_arg
*args
[], const char *arg
)
3152 if (strcmp ((*args
)->name
, arg
) == 0)