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);
533 /* Self insert character 'c' in overwrite mode. */
535 vty_self_insert_overwrite (struct vty
*vty
, char c
)
537 if (vty
->cp
== vty
->length
)
539 vty_self_insert (vty
, c
);
543 vty
->buf
[vty
->cp
++] = c
;
544 vty_write (vty
, &c
, 1);
548 * Insert a string into vty->buf at the current cursor position.
550 * If the resultant string would be larger than VTY_BUFSIZ it is
554 vty_insert_word_overwrite (struct vty
*vty
, char *str
)
556 size_t nwrite
= MIN ((int) strlen (str
), VTY_BUFSIZ
- vty
->cp
);
557 vty_write (vty
, str
, nwrite
);
558 strncpy (&vty
->buf
[vty
->cp
], str
, nwrite
);
560 vty
->length
= vty
->cp
;
563 /* Forward character. */
565 vty_forward_char (struct vty
*vty
)
567 if (vty
->cp
< vty
->length
)
569 vty_write (vty
, &vty
->buf
[vty
->cp
], 1);
574 /* Backward character. */
576 vty_backward_char (struct vty
*vty
)
581 vty_write (vty
, &telnet_backward_char
, 1);
585 /* Move to the beginning of the line. */
587 vty_beginning_of_line (struct vty
*vty
)
590 vty_backward_char (vty
);
593 /* Move to the end of the line. */
595 vty_end_of_line (struct vty
*vty
)
597 while (vty
->cp
< vty
->length
)
598 vty_forward_char (vty
);
601 static void vty_kill_line_from_beginning (struct vty
*);
602 static void vty_redraw_line (struct vty
*);
604 /* Print command line history. This function is called from
605 vty_next_line and vty_previous_line. */
607 vty_history_print (struct vty
*vty
)
611 vty_kill_line_from_beginning (vty
);
613 /* Get previous line from history buffer */
614 length
= strlen (vty
->hist
[vty
->hp
]);
615 memcpy (vty
->buf
, vty
->hist
[vty
->hp
], length
);
616 vty
->cp
= vty
->length
= length
;
618 /* Redraw current line */
619 vty_redraw_line (vty
);
622 /* Show next command line history. */
624 vty_next_line (struct vty
*vty
)
628 if (vty
->hp
== vty
->hindex
)
631 /* Try is there history exist or not. */
633 if (try_index
== (VTY_MAXHIST
- 1))
638 /* If there is not history return. */
639 if (vty
->hist
[try_index
] == NULL
)
644 vty_history_print (vty
);
647 /* Show previous command line history. */
649 vty_previous_line (struct vty
*vty
)
655 try_index
= VTY_MAXHIST
- 1;
659 if (vty
->hist
[try_index
] == NULL
)
664 vty_history_print (vty
);
667 /* This function redraw all of the command line character. */
669 vty_redraw_line (struct vty
*vty
)
671 vty_write (vty
, vty
->buf
, vty
->length
);
672 vty
->cp
= vty
->length
;
677 vty_forward_word (struct vty
*vty
)
679 while (vty
->cp
!= vty
->length
&& vty
->buf
[vty
->cp
] != ' ')
680 vty_forward_char (vty
);
682 while (vty
->cp
!= vty
->length
&& vty
->buf
[vty
->cp
] == ' ')
683 vty_forward_char (vty
);
686 /* Backward word without skipping training space. */
688 vty_backward_pure_word (struct vty
*vty
)
690 while (vty
->cp
> 0 && vty
->buf
[vty
->cp
- 1] != ' ')
691 vty_backward_char (vty
);
696 vty_backward_word (struct vty
*vty
)
698 while (vty
->cp
> 0 && vty
->buf
[vty
->cp
- 1] == ' ')
699 vty_backward_char (vty
);
701 while (vty
->cp
> 0 && vty
->buf
[vty
->cp
- 1] != ' ')
702 vty_backward_char (vty
);
705 /* When '^D' is typed at the beginning of the line we move to the down
708 vty_down_level (struct vty
*vty
)
710 vty_out (vty
, "%s", VTY_NEWLINE
);
716 /* When '^Z' is received from vty, move down to the enable mode. */
718 vty_end_config (struct vty
*vty
)
720 vty_out (vty
, "%s", VTY_NEWLINE
);
737 case BGP_ENCAPV6_NODE
:
738 case BGP_VNC_DEFAULTS_NODE
:
739 case BGP_VNC_NVE_GROUP_NODE
:
740 case BGP_VNC_L2_GROUP_NODE
:
751 case LDP_IPV4_IFACE_NODE
:
752 case LDP_IPV6_IFACE_NODE
:
754 case LDP_PSEUDOWIRE_NODE
:
757 case KEYCHAIN_KEY_NODE
:
761 vty_config_unlock (vty
);
762 vty
->node
= ENABLE_NODE
;
765 /* Unknown node, we have to ignore it. */
773 /* Delete a charcter at the current point. */
775 vty_delete_char (struct vty
*vty
)
780 if (vty
->length
== 0)
782 vty_down_level (vty
);
786 if (vty
->cp
== vty
->length
)
787 return; /* completion need here? */
789 size
= vty
->length
- vty
->cp
;
792 memmove (&vty
->buf
[vty
->cp
], &vty
->buf
[vty
->cp
+ 1], size
- 1);
793 vty
->buf
[vty
->length
] = '\0';
795 if (vty
->node
== AUTH_NODE
|| vty
->node
== AUTH_ENABLE_NODE
)
798 vty_write (vty
, &vty
->buf
[vty
->cp
], size
- 1);
799 vty_write (vty
, &telnet_space_char
, 1);
801 for (i
= 0; i
< size
; i
++)
802 vty_write (vty
, &telnet_backward_char
, 1);
805 /* Delete a character before the point. */
807 vty_delete_backward_char (struct vty
*vty
)
812 vty_backward_char (vty
);
813 vty_delete_char (vty
);
816 /* Kill rest of line from current point. */
818 vty_kill_line (struct vty
*vty
)
823 size
= vty
->length
- vty
->cp
;
828 for (i
= 0; i
< size
; i
++)
829 vty_write (vty
, &telnet_space_char
, 1);
830 for (i
= 0; i
< size
; i
++)
831 vty_write (vty
, &telnet_backward_char
, 1);
833 memset (&vty
->buf
[vty
->cp
], 0, size
);
834 vty
->length
= vty
->cp
;
837 /* Kill line from the beginning. */
839 vty_kill_line_from_beginning (struct vty
*vty
)
841 vty_beginning_of_line (vty
);
845 /* Delete a word before the point. */
847 vty_forward_kill_word (struct vty
*vty
)
849 while (vty
->cp
!= vty
->length
&& vty
->buf
[vty
->cp
] == ' ')
850 vty_delete_char (vty
);
851 while (vty
->cp
!= vty
->length
&& vty
->buf
[vty
->cp
] != ' ')
852 vty_delete_char (vty
);
855 /* Delete a word before the point. */
857 vty_backward_kill_word (struct vty
*vty
)
859 while (vty
->cp
> 0 && vty
->buf
[vty
->cp
- 1] == ' ')
860 vty_delete_backward_char (vty
);
861 while (vty
->cp
> 0 && vty
->buf
[vty
->cp
- 1] != ' ')
862 vty_delete_backward_char (vty
);
865 /* Transpose chars before or at the point. */
867 vty_transpose_chars (struct vty
*vty
)
871 /* If length is short or point is near by the beginning of line then
873 if (vty
->length
< 2 || vty
->cp
< 1)
876 /* In case of point is located at the end of the line. */
877 if (vty
->cp
== vty
->length
)
879 c1
= vty
->buf
[vty
->cp
- 1];
880 c2
= vty
->buf
[vty
->cp
- 2];
882 vty_backward_char (vty
);
883 vty_backward_char (vty
);
884 vty_self_insert_overwrite (vty
, c1
);
885 vty_self_insert_overwrite (vty
, c2
);
889 c1
= vty
->buf
[vty
->cp
];
890 c2
= vty
->buf
[vty
->cp
- 1];
892 vty_backward_char (vty
);
893 vty_self_insert_overwrite (vty
, c1
);
894 vty_self_insert_overwrite (vty
, c2
);
898 /* Do completion at vty interface. */
900 vty_complete_command (struct vty
*vty
)
904 char **matched
= NULL
;
907 if (vty
->node
== AUTH_NODE
|| vty
->node
== AUTH_ENABLE_NODE
)
910 vline
= cmd_make_strvec (vty
->buf
);
914 /* In case of 'help \t'. */
915 if (isspace ((int) vty
->buf
[vty
->length
- 1]))
916 vector_set (vline
, NULL
);
918 matched
= cmd_complete_command (vline
, vty
, &ret
);
920 cmd_free_strvec (vline
);
922 vty_out (vty
, "%s", VTY_NEWLINE
);
925 case CMD_ERR_AMBIGUOUS
:
926 vty_out (vty
, "%% Ambiguous command.%s", VTY_NEWLINE
);
928 vty_redraw_line (vty
);
930 case CMD_ERR_NO_MATCH
:
931 /* vty_out (vty, "%% There is no matched command.%s", VTY_NEWLINE); */
933 vty_redraw_line (vty
);
935 case CMD_COMPLETE_FULL_MATCH
:
938 /* 2016-11-28 equinox -- need to debug, SEGV here */
939 vty_out (vty
, "%% CLI BUG: FULL_MATCH with NULL str%s", VTY_NEWLINE
);
941 vty_redraw_line (vty
);
945 vty_redraw_line (vty
);
946 vty_backward_pure_word (vty
);
947 vty_insert_word_overwrite (vty
, matched
[0]);
948 vty_self_insert (vty
, ' ');
949 XFREE (MTYPE_TMP
, matched
[0]);
951 case CMD_COMPLETE_MATCH
:
953 vty_redraw_line (vty
);
954 vty_backward_pure_word (vty
);
955 vty_insert_word_overwrite (vty
, matched
[0]);
956 XFREE (MTYPE_TMP
, matched
[0]);
957 vector_only_index_free (matched
);
960 case CMD_COMPLETE_LIST_MATCH
:
961 for (i
= 0; matched
[i
] != NULL
; i
++)
963 if (i
!= 0 && ((i
% 6) == 0))
964 vty_out (vty
, "%s", VTY_NEWLINE
);
965 vty_out (vty
, "%-10s ", matched
[i
]);
966 XFREE (MTYPE_TMP
, matched
[i
]);
968 vty_out (vty
, "%s", VTY_NEWLINE
);
971 vty_redraw_line (vty
);
973 case CMD_ERR_NOTHING_TODO
:
975 vty_redraw_line (vty
);
981 vector_only_index_free (matched
);
985 vty_describe_fold (struct vty
*vty
, int cmd_width
,
986 unsigned int desc_width
, struct cmd_token
*token
)
996 vty_out (vty
, " %-*s %s%s", cmd_width
, cmd
, token
->desc
, VTY_NEWLINE
);
1000 buf
= XCALLOC (MTYPE_TMP
, strlen (token
->desc
) + 1);
1002 for (p
= token
->desc
; strlen (p
) > desc_width
; p
+= pos
+ 1)
1004 for (pos
= desc_width
; pos
> 0; pos
--)
1005 if (*(p
+ pos
) == ' ')
1011 strncpy (buf
, p
, pos
);
1013 vty_out (vty
, " %-*s %s%s", cmd_width
, cmd
, buf
, VTY_NEWLINE
);
1018 vty_out (vty
, " %-*s %s%s", cmd_width
, cmd
, p
, VTY_NEWLINE
);
1020 XFREE (MTYPE_TMP
, buf
);
1023 /* Describe matched command function. */
1025 vty_describe_command (struct vty
*vty
)
1030 unsigned int i
, width
, desc_width
;
1031 struct cmd_token
*token
, *token_cr
= NULL
;
1033 vline
= cmd_make_strvec (vty
->buf
);
1035 /* In case of '> ?'. */
1038 vline
= vector_init (1);
1039 vector_set (vline
, NULL
);
1042 if (isspace ((int) vty
->buf
[vty
->length
- 1]))
1043 vector_set (vline
, NULL
);
1045 describe
= cmd_describe_command (vline
, vty
, &ret
);
1047 vty_out (vty
, "%s", VTY_NEWLINE
);
1049 /* Ambiguous error. */
1052 case CMD_ERR_AMBIGUOUS
:
1053 vty_out (vty
, "%% Ambiguous command.%s", VTY_NEWLINE
);
1056 case CMD_ERR_NO_MATCH
:
1057 vty_out (vty
, "%% There is no matched command.%s", VTY_NEWLINE
);
1062 /* Get width of command string. */
1064 for (i
= 0; i
< vector_active (describe
); i
++)
1065 if ((token
= vector_slot (describe
, i
)) != NULL
)
1069 if (token
->text
[0] == '\0')
1072 len
= strlen (token
->text
);
1078 /* Get width of description string. */
1079 desc_width
= vty
->width
- (width
+ 6);
1081 /* Print out description. */
1082 for (i
= 0; i
< vector_active (describe
); i
++)
1083 if ((token
= vector_slot (describe
, i
)) != NULL
)
1085 if (token
->text
[0] == '\0')
1088 if (strcmp (token
->text
, CMD_CR_TEXT
) == 0)
1095 vty_out (vty
, " %-s%s",
1098 else if (desc_width
>= strlen (token
->desc
))
1099 vty_out (vty
, " %-*s %s%s", width
,
1101 token
->desc
, VTY_NEWLINE
);
1103 vty_describe_fold (vty
, width
, desc_width
, token
);
1106 vty_out (vty
, " %-*s %s%s", width
1107 desc
->cmd
[0] == '.' ? desc
->cmd
+ 1 : desc
->cmd
,
1108 desc
->str
? desc
->str
: "", VTY_NEWLINE
);
1112 if ((token
= token_cr
))
1115 vty_out (vty
, " %-s%s",
1118 else if (desc_width
>= strlen (token
->desc
))
1119 vty_out (vty
, " %-*s %s%s", width
,
1121 token
->desc
, VTY_NEWLINE
);
1123 vty_describe_fold (vty
, width
, desc_width
, token
);
1127 cmd_free_strvec (vline
);
1129 vector_free (describe
);
1132 vty_redraw_line (vty
);
1136 vty_clear_buf (struct vty
*vty
)
1138 memset (vty
->buf
, 0, vty
->max
);
1141 /* ^C stop current input and do not add command line to the history. */
1143 vty_stop_input (struct vty
*vty
)
1145 vty
->cp
= vty
->length
= 0;
1146 vty_clear_buf (vty
);
1147 vty_out (vty
, "%s", VTY_NEWLINE
);
1153 /* Nothing to do. */
1156 case INTERFACE_NODE
:
1167 case LDP_IPV4_IFACE_NODE
:
1168 case LDP_IPV6_IFACE_NODE
:
1169 case LDP_L2VPN_NODE
:
1170 case LDP_PSEUDOWIRE_NODE
:
1173 case KEYCHAIN_KEY_NODE
:
1177 vty_config_unlock (vty
);
1178 vty
->node
= ENABLE_NODE
;
1181 /* Unknown node, we have to ignore it. */
1186 /* Set history pointer to the latest one. */
1187 vty
->hp
= vty
->hindex
;
1190 /* Add current command line to the history buffer. */
1192 vty_hist_add (struct vty
*vty
)
1196 if (vty
->length
== 0)
1199 index
= vty
->hindex
? vty
->hindex
- 1 : VTY_MAXHIST
- 1;
1201 /* Ignore the same string as previous one. */
1202 if (vty
->hist
[index
])
1203 if (strcmp (vty
->buf
, vty
->hist
[index
]) == 0)
1205 vty
->hp
= vty
->hindex
;
1209 /* Insert history entry. */
1210 if (vty
->hist
[vty
->hindex
])
1211 XFREE (MTYPE_VTY_HIST
, vty
->hist
[vty
->hindex
]);
1212 vty
->hist
[vty
->hindex
] = XSTRDUP (MTYPE_VTY_HIST
, vty
->buf
);
1214 /* History index rotation. */
1216 if (vty
->hindex
== VTY_MAXHIST
)
1219 vty
->hp
= vty
->hindex
;
1222 /* #define TELNET_OPTION_DEBUG */
1224 /* Get telnet window size. */
1226 vty_telnet_option (struct vty
*vty
, unsigned char *buf
, int nbytes
)
1228 #ifdef TELNET_OPTION_DEBUG
1231 for (i
= 0; i
< nbytes
; i
++)
1236 vty_out (vty
, "IAC ");
1239 vty_out (vty
, "WILL ");
1242 vty_out (vty
, "WONT ");
1245 vty_out (vty
, "DO ");
1248 vty_out (vty
, "DONT ");
1251 vty_out (vty
, "SB ");
1254 vty_out (vty
, "SE ");
1257 vty_out (vty
, "TELOPT_ECHO %s", VTY_NEWLINE
);
1260 vty_out (vty
, "TELOPT_SGA %s", VTY_NEWLINE
);
1263 vty_out (vty
, "TELOPT_NAWS %s", VTY_NEWLINE
);
1266 vty_out (vty
, "%x ", buf
[i
]);
1270 vty_out (vty
, "%s", VTY_NEWLINE
);
1272 #endif /* TELNET_OPTION_DEBUG */
1278 vty
->iac_sb_in_progress
= 1;
1283 if (!vty
->iac_sb_in_progress
)
1286 if ((vty
->sb_len
== 0) || (vty
->sb_buf
[0] == '\0'))
1288 vty
->iac_sb_in_progress
= 0;
1291 switch (vty
->sb_buf
[0])
1294 if (vty
->sb_len
!= TELNET_NAWS_SB_LEN
)
1295 zlog_warn("RFC 1073 violation detected: telnet NAWS option "
1296 "should send %d characters, but we received %lu",
1297 TELNET_NAWS_SB_LEN
, (u_long
)vty
->sb_len
);
1298 else if (sizeof(vty
->sb_buf
) < TELNET_NAWS_SB_LEN
)
1299 zlog_err("Bug detected: sizeof(vty->sb_buf) %lu < %d, "
1300 "too small to handle the telnet NAWS option",
1301 (u_long
)sizeof(vty
->sb_buf
), TELNET_NAWS_SB_LEN
);
1304 vty
->width
= ((vty
->sb_buf
[1] << 8)|vty
->sb_buf
[2]);
1305 vty
->height
= ((vty
->sb_buf
[3] << 8)|vty
->sb_buf
[4]);
1306 #ifdef TELNET_OPTION_DEBUG
1307 vty_out(vty
, "TELNET NAWS window size negotiation completed: "
1308 "width %d, height %d%s",
1309 vty
->width
, vty
->height
, VTY_NEWLINE
);
1314 vty
->iac_sb_in_progress
= 0;
1324 /* Execute current command line. */
1326 vty_execute (struct vty
*vty
)
1335 case AUTH_ENABLE_NODE
:
1336 vty_auth (vty
, vty
->buf
);
1339 ret
= vty_command (vty
, vty
->buf
);
1340 if (vty
->type
== VTY_TERM
)
1345 /* Clear command line buffer. */
1346 vty
->cp
= vty
->length
= 0;
1347 vty_clear_buf (vty
);
1349 if (vty
->status
!= VTY_CLOSE
)
1355 #define CONTROL(X) ((X) - '@')
1356 #define VTY_NORMAL 0
1357 #define VTY_PRE_ESCAPE 1
1358 #define VTY_ESCAPE 2
1360 /* Escape character command map. */
1362 vty_escape_map (unsigned char c
, struct vty
*vty
)
1367 vty_previous_line (vty
);
1370 vty_next_line (vty
);
1373 vty_forward_char (vty
);
1376 vty_backward_char (vty
);
1382 /* Go back to normal mode. */
1383 vty
->escape
= VTY_NORMAL
;
1386 /* Quit print out to the buffer. */
1388 vty_buffer_reset (struct vty
*vty
)
1390 buffer_reset (vty
->obuf
);
1392 vty_redraw_line (vty
);
1395 /* Read data via vty socket. */
1397 vty_read (struct thread
*thread
)
1401 unsigned char buf
[VTY_READ_BUFSIZ
];
1403 int vty_sock
= THREAD_FD (thread
);
1404 struct vty
*vty
= THREAD_ARG (thread
);
1407 /* Read raw data from socket */
1408 if ((nbytes
= read (vty
->fd
, buf
, VTY_READ_BUFSIZ
)) <= 0)
1412 if (ERRNO_IO_RETRY(errno
))
1414 vty_event (VTY_READ
, vty_sock
, vty
);
1417 vty
->monitor
= 0; /* disable monitoring to avoid infinite recursion */
1418 zlog_warn("%s: read error on vty client fd %d, closing: %s",
1419 __func__
, vty
->fd
, safe_strerror(errno
));
1420 buffer_reset(vty
->obuf
);
1422 vty
->status
= VTY_CLOSE
;
1425 for (i
= 0; i
< nbytes
; i
++)
1440 if (vty
->iac_sb_in_progress
&& !vty
->iac
)
1442 if (vty
->sb_len
< sizeof(vty
->sb_buf
))
1443 vty
->sb_buf
[vty
->sb_len
] = buf
[i
];
1450 /* In case of telnet command */
1452 ret
= vty_telnet_option (vty
, buf
+ i
, nbytes
- i
);
1459 if (vty
->status
== VTY_MORE
)
1466 vty_buffer_reset (vty
);
1468 #if 0 /* More line does not work for "show ip bgp". */
1471 vty
->status
= VTY_MORELINE
;
1480 /* Escape character. */
1481 if (vty
->escape
== VTY_ESCAPE
)
1483 vty_escape_map (buf
[i
], vty
);
1487 /* Pre-escape status. */
1488 if (vty
->escape
== VTY_PRE_ESCAPE
)
1493 vty
->escape
= VTY_ESCAPE
;
1496 vty_backward_word (vty
);
1497 vty
->escape
= VTY_NORMAL
;
1500 vty_forward_word (vty
);
1501 vty
->escape
= VTY_NORMAL
;
1504 vty_forward_kill_word (vty
);
1505 vty
->escape
= VTY_NORMAL
;
1509 vty_backward_kill_word (vty
);
1510 vty
->escape
= VTY_NORMAL
;
1513 vty
->escape
= VTY_NORMAL
;
1522 vty_beginning_of_line (vty
);
1525 vty_backward_char (vty
);
1528 vty_stop_input (vty
);
1531 vty_delete_char (vty
);
1534 vty_end_of_line (vty
);
1537 vty_forward_char (vty
);
1541 vty_delete_backward_char (vty
);
1544 vty_kill_line (vty
);
1547 vty_next_line (vty
);
1550 vty_previous_line (vty
);
1553 vty_transpose_chars (vty
);
1556 vty_kill_line_from_beginning (vty
);
1559 vty_backward_kill_word (vty
);
1562 vty_end_config (vty
);
1566 vty_out (vty
, "%s", VTY_NEWLINE
);
1570 vty_complete_command (vty
);
1573 if (vty
->node
== AUTH_NODE
|| vty
->node
== AUTH_ENABLE_NODE
)
1574 vty_self_insert (vty
, buf
[i
]);
1576 vty_describe_command (vty
);
1579 if (i
+ 1 < nbytes
&& buf
[i
+ 1] == '[')
1581 vty
->escape
= VTY_ESCAPE
;
1585 vty
->escape
= VTY_PRE_ESCAPE
;
1588 if (buf
[i
] > 31 && buf
[i
] < 127)
1589 vty_self_insert (vty
, buf
[i
]);
1595 if (vty
->status
== VTY_CLOSE
)
1599 vty_event (VTY_WRITE
, vty
->wfd
, vty
);
1600 vty_event (VTY_READ
, vty_sock
, vty
);
1605 /* Flush buffer to the vty. */
1607 vty_flush (struct thread
*thread
)
1610 buffer_status_t flushrc
;
1611 int vty_sock
= THREAD_FD (thread
);
1612 struct vty
*vty
= THREAD_ARG (thread
);
1614 vty
->t_write
= NULL
;
1616 /* Tempolary disable read thread. */
1617 if ((vty
->lines
== 0) && vty
->t_read
)
1619 thread_cancel (vty
->t_read
);
1623 /* Function execution continue. */
1624 erase
= ((vty
->status
== VTY_MORE
|| vty
->status
== VTY_MORELINE
));
1626 /* N.B. if width is 0, that means we don't know the window size. */
1627 if ((vty
->lines
== 0) || (vty
->width
== 0) || (vty
->height
== 0))
1628 flushrc
= buffer_flush_available(vty
->obuf
, vty_sock
);
1629 else if (vty
->status
== VTY_MORELINE
)
1630 flushrc
= buffer_flush_window(vty
->obuf
, vty_sock
, vty
->width
,
1633 flushrc
= buffer_flush_window(vty
->obuf
, vty_sock
, vty
->width
,
1634 vty
->lines
>= 0 ? vty
->lines
:
1640 vty
->monitor
= 0; /* disable monitoring to avoid infinite recursion */
1641 zlog_warn("buffer_flush failed on vty client fd %d, closing",
1643 buffer_reset(vty
->obuf
);
1647 if (vty
->status
== VTY_CLOSE
)
1651 vty
->status
= VTY_NORMAL
;
1652 if (vty
->lines
== 0)
1653 vty_event (VTY_READ
, vty_sock
, vty
);
1656 case BUFFER_PENDING
:
1657 /* There is more data waiting to be written. */
1658 vty
->status
= VTY_MORE
;
1659 if (vty
->lines
== 0)
1660 vty_event (VTY_WRITE
, vty_sock
, vty
);
1667 /* allocate and initialise vty */
1669 vty_new_init (int vty_sock
)
1675 vty
->wfd
= vty_sock
;
1676 vty
->type
= VTY_TERM
;
1677 vty
->node
= AUTH_NODE
;
1680 vty_clear_buf (vty
);
1682 memset (vty
->hist
, 0, sizeof (vty
->hist
));
1685 vector_set_index (vtyvec
, vty_sock
, vty
);
1686 vty
->status
= VTY_NORMAL
;
1689 vty
->iac_sb_in_progress
= 0;
1695 /* Create new vty structure. */
1697 vty_create (int vty_sock
, union sockunion
*su
)
1699 char buf
[SU_ADDRSTRLEN
];
1702 sockunion2str(su
, buf
, SU_ADDRSTRLEN
);
1704 /* Allocate new vty structure and set up default values. */
1705 vty
= vty_new_init (vty_sock
);
1707 /* configurable parameters not part of basic init */
1708 vty
->v_timeout
= vty_timeout_val
;
1709 strcpy (vty
->address
, buf
);
1710 if (no_password_check
)
1713 vty
->node
= ENABLE_NODE
;
1715 vty
->node
= VIEW_NODE
;
1717 if (host
.lines
>= 0)
1718 vty
->lines
= host
.lines
;
1720 if (! no_password_check
)
1722 /* Vty is not available if password isn't set. */
1723 if (host
.password
== NULL
&& host
.password_encrypt
== NULL
)
1725 vty_out (vty
, "Vty password is not set.%s", VTY_NEWLINE
);
1726 vty
->status
= VTY_CLOSE
;
1732 /* Say hello to the world. */
1734 if (! no_password_check
)
1735 vty_out (vty
, "%sUser Access Verification%s%s", VTY_NEWLINE
, VTY_NEWLINE
, VTY_NEWLINE
);
1737 /* Setting up terminal. */
1738 vty_will_echo (vty
);
1739 vty_will_suppress_go_ahead (vty
);
1741 vty_dont_linemode (vty
);
1742 vty_do_window_size (vty
);
1743 /* vty_dont_lflow_ahead (vty); */
1747 /* Add read/write thread. */
1748 vty_event (VTY_WRITE
, vty_sock
, vty
);
1749 vty_event (VTY_READ
, vty_sock
, vty
);
1754 /* create vty for stdio */
1755 static struct termios stdio_orig_termios
;
1756 static struct vty
*stdio_vty
= NULL
;
1757 static void (*stdio_vty_atclose
)(void);
1760 vty_stdio_reset (void)
1764 tcsetattr (0, TCSANOW
, &stdio_orig_termios
);
1767 if (stdio_vty_atclose
)
1768 stdio_vty_atclose ();
1769 stdio_vty_atclose
= NULL
;
1774 vty_stdio (void (*atclose
)())
1777 struct termios termios
;
1779 /* refuse creating two vtys on stdio */
1783 vty
= stdio_vty
= vty_new_init (0);
1784 stdio_vty_atclose
= atclose
;
1787 /* always have stdio vty in a known _unchangeable_ state, don't want config
1788 * to have any effect here to make sure scripting this works as intended */
1789 vty
->node
= ENABLE_NODE
;
1791 strcpy (vty
->address
, "console");
1793 if (!tcgetattr (0, &stdio_orig_termios
))
1795 termios
= stdio_orig_termios
;
1796 termios
.c_iflag
&= ~(IGNBRK
| BRKINT
| PARMRK
| ISTRIP
1797 | INLCR
| IGNCR
| ICRNL
| IXON
);
1798 termios
.c_oflag
&= ~OPOST
;
1799 termios
.c_lflag
&= ~(ECHO
| ECHONL
| ICANON
| ISIG
| IEXTEN
);
1800 termios
.c_cflag
&= ~(CSIZE
| PARENB
);
1801 termios
.c_cflag
|= CS8
;
1802 tcsetattr (0, TCSANOW
, &termios
);
1807 /* Add read/write thread. */
1808 vty_event (VTY_WRITE
, 1, vty
);
1809 vty_event (VTY_READ
, 0, vty
);
1814 /* Accept connection from the network. */
1816 vty_accept (struct thread
*thread
)
1824 struct access_list
*acl
= NULL
;
1825 char buf
[SU_ADDRSTRLEN
];
1827 accept_sock
= THREAD_FD (thread
);
1829 /* We continue hearing vty socket. */
1830 vty_event (VTY_SERV
, accept_sock
, NULL
);
1832 memset (&su
, 0, sizeof (union sockunion
));
1834 /* We can handle IPv4 or IPv6 socket. */
1835 vty_sock
= sockunion_accept (accept_sock
, &su
);
1838 zlog_warn ("can't accept vty socket : %s", safe_strerror (errno
));
1841 set_nonblocking(vty_sock
);
1842 set_cloexec(vty_sock
);
1844 sockunion2hostprefix (&su
, &p
);
1846 /* VTY's accesslist apply. */
1847 if (p
.family
== AF_INET
&& vty_accesslist_name
)
1849 if ((acl
= access_list_lookup (AFI_IP
, vty_accesslist_name
)) &&
1850 (access_list_apply (acl
, &p
) == FILTER_DENY
))
1852 zlog (NULL
, LOG_INFO
, "Vty connection refused from %s",
1853 sockunion2str (&su
, buf
, SU_ADDRSTRLEN
));
1856 /* continue accepting connections */
1857 vty_event (VTY_SERV
, accept_sock
, NULL
);
1863 /* VTY's ipv6 accesslist apply. */
1864 if (p
.family
== AF_INET6
&& vty_ipv6_accesslist_name
)
1866 if ((acl
= access_list_lookup (AFI_IP6
, vty_ipv6_accesslist_name
)) &&
1867 (access_list_apply (acl
, &p
) == FILTER_DENY
))
1869 zlog (NULL
, LOG_INFO
, "Vty connection refused from %s",
1870 sockunion2str (&su
, buf
, SU_ADDRSTRLEN
));
1873 /* continue accepting connections */
1874 vty_event (VTY_SERV
, accept_sock
, NULL
);
1881 ret
= setsockopt (vty_sock
, IPPROTO_TCP
, TCP_NODELAY
,
1882 (char *) &on
, sizeof (on
));
1884 zlog (NULL
, LOG_INFO
, "can't set sockopt to vty_sock : %s",
1885 safe_strerror (errno
));
1887 zlog (NULL
, LOG_INFO
, "Vty connection from %s",
1888 sockunion2str (&su
, buf
, SU_ADDRSTRLEN
));
1890 vty_create (vty_sock
, &su
);
1896 vty_serv_sock_addrinfo (const char *hostname
, unsigned short port
)
1899 struct addrinfo req
;
1900 struct addrinfo
*ainfo
;
1901 struct addrinfo
*ainfo_save
;
1903 char port_str
[BUFSIZ
];
1905 memset (&req
, 0, sizeof (struct addrinfo
));
1906 req
.ai_flags
= AI_PASSIVE
;
1907 req
.ai_family
= AF_UNSPEC
;
1908 req
.ai_socktype
= SOCK_STREAM
;
1909 sprintf (port_str
, "%d", port
);
1910 port_str
[sizeof (port_str
) - 1] = '\0';
1912 ret
= getaddrinfo (hostname
, port_str
, &req
, &ainfo
);
1916 fprintf (stderr
, "getaddrinfo failed: %s\n", gai_strerror (ret
));
1924 if (ainfo
->ai_family
!= AF_INET
1925 && ainfo
->ai_family
!= AF_INET6
1929 sock
= socket (ainfo
->ai_family
, ainfo
->ai_socktype
, ainfo
->ai_protocol
);
1933 sockopt_v6only (ainfo
->ai_family
, sock
);
1934 sockopt_reuseaddr (sock
);
1935 sockopt_reuseport (sock
);
1938 ret
= bind (sock
, ainfo
->ai_addr
, ainfo
->ai_addrlen
);
1941 close (sock
); /* Avoid sd leak. */
1945 ret
= listen (sock
, 3);
1948 close (sock
); /* Avoid sd leak. */
1952 vty_event (VTY_SERV
, sock
, NULL
);
1954 while ((ainfo
= ainfo
->ai_next
) != NULL
);
1956 freeaddrinfo (ainfo_save
);
1960 /* For sockaddr_un. */
1963 /* VTY shell UNIX domain socket. */
1965 vty_serv_un (const char *path
)
1969 struct sockaddr_un serv
;
1971 struct zprivs_ids_t ids
;
1973 /* First of all, unlink existing socket */
1977 old_mask
= umask (0007);
1979 /* Make UNIX domain socket. */
1980 sock
= socket (AF_UNIX
, SOCK_STREAM
, 0);
1983 zlog_err("Cannot create unix stream socket: %s", safe_strerror(errno
));
1987 /* Make server socket. */
1988 memset (&serv
, 0, sizeof (struct sockaddr_un
));
1989 serv
.sun_family
= AF_UNIX
;
1990 strncpy (serv
.sun_path
, path
, strlen (path
));
1991 #ifdef HAVE_STRUCT_SOCKADDR_UN_SUN_LEN
1992 len
= serv
.sun_len
= SUN_LEN(&serv
);
1994 len
= sizeof (serv
.sun_family
) + strlen (serv
.sun_path
);
1995 #endif /* HAVE_STRUCT_SOCKADDR_UN_SUN_LEN */
1999 ret
= bind (sock
, (struct sockaddr
*) &serv
, len
);
2002 zlog_err("Cannot bind path %s: %s", path
, safe_strerror(errno
));
2003 close (sock
); /* Avoid sd leak. */
2007 ret
= listen (sock
, 5);
2010 zlog_err("listen(fd %d) failed: %s", sock
, safe_strerror(errno
));
2011 close (sock
); /* Avoid sd leak. */
2017 zprivs_get_ids(&ids
);
2019 if (ids
.gid_vty
> 0)
2021 /* set group of socket */
2022 if ( chown (path
, -1, ids
.gid_vty
) )
2024 zlog_err ("vty_serv_un: could chown socket, %s",
2025 safe_strerror (errno
) );
2029 vty_event (VTYSH_SERV
, sock
, NULL
);
2032 /* #define VTYSH_DEBUG 1 */
2035 vtysh_accept (struct thread
*thread
)
2040 struct sockaddr_un client
;
2043 accept_sock
= THREAD_FD (thread
);
2045 vty_event (VTYSH_SERV
, accept_sock
, NULL
);
2047 memset (&client
, 0, sizeof (struct sockaddr_un
));
2048 client_len
= sizeof (struct sockaddr_un
);
2050 sock
= accept (accept_sock
, (struct sockaddr
*) &client
,
2051 (socklen_t
*) &client_len
);
2055 zlog_warn ("can't accept vty socket : %s", safe_strerror (errno
));
2059 if (set_nonblocking(sock
) < 0)
2061 zlog_warn ("vtysh_accept: could not set vty socket %d to non-blocking,"
2062 " %s, closing", sock
, safe_strerror (errno
));
2069 printf ("VTY shell accept\n");
2070 #endif /* VTYSH_DEBUG */
2075 vty
->type
= VTY_SHELL_SERV
;
2076 vty
->node
= VIEW_NODE
;
2078 vty_event (VTYSH_READ
, sock
, vty
);
2084 vtysh_flush(struct vty
*vty
)
2086 switch (buffer_flush_available(vty
->obuf
, vty
->wfd
))
2088 case BUFFER_PENDING
:
2089 vty_event(VTYSH_WRITE
, vty
->wfd
, vty
);
2092 vty
->monitor
= 0; /* disable monitoring to avoid infinite recursion */
2093 zlog_warn("%s: write error to fd %d, closing", __func__
, vty
->fd
);
2094 buffer_reset(vty
->obuf
);
2105 vtysh_read (struct thread
*thread
)
2111 unsigned char buf
[VTY_READ_BUFSIZ
];
2113 u_char header
[4] = {0, 0, 0, 0};
2115 sock
= THREAD_FD (thread
);
2116 vty
= THREAD_ARG (thread
);
2119 if ((nbytes
= read (sock
, buf
, VTY_READ_BUFSIZ
)) <= 0)
2123 if (ERRNO_IO_RETRY(errno
))
2125 vty_event (VTYSH_READ
, sock
, vty
);
2128 vty
->monitor
= 0; /* disable monitoring to avoid infinite recursion */
2129 zlog_warn("%s: read failed on vtysh client fd %d, closing: %s",
2130 __func__
, sock
, safe_strerror(errno
));
2132 buffer_reset(vty
->obuf
);
2135 printf ("close vtysh\n");
2136 #endif /* VTYSH_DEBUG */
2141 printf ("line: %.*s\n", nbytes
, buf
);
2142 #endif /* VTYSH_DEBUG */
2144 if (vty
->length
+ nbytes
> VTY_BUFSIZ
)
2146 /* Clear command line buffer. */
2147 vty
->cp
= vty
->length
= 0;
2148 vty_clear_buf (vty
);
2149 vty_out (vty
, "%% Command is too long.%s", VTY_NEWLINE
);
2153 for (p
= buf
; p
< buf
+nbytes
; p
++)
2155 vty
->buf
[vty
->length
++] = *p
;
2158 /* Pass this line to parser. */
2159 ret
= vty_execute (vty
);
2160 /* Note that vty_execute clears the command buffer and resets
2161 vty->length to 0. */
2163 /* Return result. */
2165 printf ("result: %d\n", ret
);
2166 printf ("vtysh node: %d\n", vty
->node
);
2167 #endif /* VTYSH_DEBUG */
2169 /* hack for asynchronous "write integrated"
2170 * - other commands in "buf" will be ditched
2171 * - input during pending config-write is "unsupported" */
2172 if (ret
== CMD_SUSPEND
)
2175 /* warning: watchquagga hardcodes this result write */
2177 buffer_put(vty
->obuf
, header
, 4);
2179 if (!vty
->t_write
&& (vtysh_flush(vty
) < 0))
2180 /* Try to flush results; exit if a write error occurs. */
2186 vty_event (VTYSH_READ
, sock
, vty
);
2192 vtysh_write (struct thread
*thread
)
2194 struct vty
*vty
= THREAD_ARG (thread
);
2196 vty
->t_write
= NULL
;
2203 /* Determine address family to bind. */
2205 vty_serv_sock (const char *addr
, unsigned short port
, const char *path
)
2207 /* If port is set to 0, do not listen on TCP/IP at all! */
2209 vty_serv_sock_addrinfo (addr
, port
);
2216 /* Close vty interface. Warning: call this only from functions that
2217 will be careful not to access the vty afterwards (since it has
2218 now been freed). This is safest from top-level functions (called
2219 directly by the thread dispatcher). */
2221 vty_close (struct vty
*vty
)
2225 /* Cancel threads.*/
2227 thread_cancel (vty
->t_read
);
2229 thread_cancel (vty
->t_write
);
2231 thread_cancel (vty
->t_timeout
);
2234 buffer_flush_all (vty
->obuf
, vty
->wfd
);
2236 /* Free input buffer. */
2237 buffer_free (vty
->obuf
);
2239 /* Free command history. */
2240 for (i
= 0; i
< VTY_MAXHIST
; i
++)
2242 XFREE (MTYPE_VTY_HIST
, vty
->hist
[i
]);
2245 vector_unset (vtyvec
, vty
->fd
);
2254 XFREE (MTYPE_VTY
, vty
->buf
);
2257 XFREE (MTYPE_VTY
, vty
->error_buf
);
2259 /* Check configure. */
2260 vty_config_unlock (vty
);
2263 XFREE (MTYPE_VTY
, vty
);
2266 /* When time out occur output message then close connection. */
2268 vty_timeout (struct thread
*thread
)
2272 vty
= THREAD_ARG (thread
);
2273 vty
->t_timeout
= NULL
;
2277 buffer_reset (vty
->obuf
);
2278 vty_out (vty
, "%sVty connection is timed out.%s", VTY_NEWLINE
, VTY_NEWLINE
);
2280 /* Close connection. */
2281 vty
->status
= VTY_CLOSE
;
2287 /* Read up configuration file from file_name. */
2289 vty_read_file (FILE *confp
)
2293 unsigned int line_num
= 0;
2296 vty
->wfd
= dup(STDERR_FILENO
); /* vty_close() will close this */
2299 /* Fine, we couldn't make a new fd. vty_close doesn't close stdout. */
2300 vty
->wfd
= STDOUT_FILENO
;
2302 vty
->fd
= STDIN_FILENO
;
2303 vty
->type
= VTY_FILE
;
2304 vty
->node
= CONFIG_NODE
;
2306 /* Execute configuration file */
2307 ret
= config_from_file (vty
, confp
, &line_num
);
2309 /* Flush any previous errors before printing messages below */
2310 buffer_flush_all (vty
->obuf
, vty
->fd
);
2312 if ( !((ret
== CMD_SUCCESS
) || (ret
== CMD_ERR_NOTHING_TODO
)) )
2314 const char *message
= NULL
;
2317 case CMD_ERR_AMBIGUOUS
:
2318 message
= "*** Error reading config: Ambiguous command.";
2320 case CMD_ERR_NO_MATCH
:
2321 message
= "*** Error reading config: There is no such command.";
2324 fprintf (stderr
, "%s\n", message
);
2325 zlog_err ("%s", message
);
2326 fprintf (stderr
, "*** Error occurred processing line %u, below:\n%s\n",
2327 line_num
, vty
->error_buf
);
2328 zlog_err ("*** Error occurred processing line %u, below:\n%s",
2329 line_num
, vty
->error_buf
);
2336 vty_use_backup_config (char *fullpath
)
2338 char *fullpath_sav
, *fullpath_tmp
;
2345 fullpath_sav
= malloc (strlen (fullpath
) + strlen (CONF_BACKUP_EXT
) + 1);
2346 strcpy (fullpath_sav
, fullpath
);
2347 strcat (fullpath_sav
, CONF_BACKUP_EXT
);
2348 if (stat (fullpath_sav
, &buf
) == -1)
2350 free (fullpath_sav
);
2354 fullpath_tmp
= malloc (strlen (fullpath
) + 8);
2355 sprintf (fullpath_tmp
, "%s.XXXXXX", fullpath
);
2357 /* Open file to configuration write. */
2358 tmp
= mkstemp (fullpath_tmp
);
2361 free (fullpath_sav
);
2362 free (fullpath_tmp
);
2366 sav
= open (fullpath_sav
, O_RDONLY
);
2369 unlink (fullpath_tmp
);
2370 free (fullpath_sav
);
2371 free (fullpath_tmp
);
2375 while((c
= read (sav
, buffer
, 512)) > 0)
2377 if (write (tmp
, buffer
, c
) <= 0)
2379 free (fullpath_sav
);
2380 free (fullpath_tmp
);
2389 if (chmod(fullpath_tmp
, CONFIGFILE_MASK
) != 0)
2391 unlink (fullpath_tmp
);
2392 free (fullpath_sav
);
2393 free (fullpath_tmp
);
2397 if (link (fullpath_tmp
, fullpath
) == 0)
2398 ret
= fopen (fullpath
, "r");
2400 unlink (fullpath_tmp
);
2402 free (fullpath_sav
);
2403 free (fullpath_tmp
);
2407 /* Read up configuration file from file_name. */
2409 vty_read_config (char *config_file
,
2410 char *config_default_dir
)
2412 char cwd
[MAXPATHLEN
];
2417 /* If -f flag specified. */
2418 if (config_file
!= NULL
)
2420 if (! IS_DIRECTORY_SEP (config_file
[0]))
2422 if (getcwd (cwd
, MAXPATHLEN
) == NULL
)
2424 fprintf (stderr
, "Failure to determine Current Working Directory %d!\n", errno
);
2427 tmp
= XMALLOC (MTYPE_TMP
,
2428 strlen (cwd
) + strlen (config_file
) + 2);
2429 sprintf (tmp
, "%s/%s", cwd
, config_file
);
2433 fullpath
= config_file
;
2435 confp
= fopen (fullpath
, "r");
2439 fprintf (stderr
, "%s: failed to open configuration file %s: %s\n",
2440 __func__
, fullpath
, safe_strerror (errno
));
2442 confp
= vty_use_backup_config (fullpath
);
2444 fprintf (stderr
, "WARNING: using backup configuration file!\n");
2447 fprintf (stderr
, "can't open configuration file [%s]\n",
2456 host_config_set (config_default_dir
);
2460 struct stat conf_stat
;
2462 /* !!!!PLEASE LEAVE!!!!
2463 * This is NEEDED for use with vtysh -b, or else you can get
2464 * a real configuration food fight with a lot garbage in the
2465 * merged configuration file it creates coming from the per
2466 * daemon configuration files. This also allows the daemons
2467 * to start if there default configuration file is not
2468 * present or ignore them, as needed when using vtysh -b to
2469 * configure the daemons at boot - MAG
2472 /* Stat for vtysh Zebra.conf, if found startup and wait for
2473 * boot configuration
2476 if ( strstr(config_default_dir
, "vtysh") == NULL
)
2478 ret
= stat (integrate_default
, &conf_stat
);
2480 goto tmp_free_and_out
;
2483 confp
= fopen (config_default_dir
, "r");
2486 fprintf (stderr
, "%s: failed to open configuration file %s: %s\n",
2487 __func__
, config_default_dir
, safe_strerror (errno
));
2489 confp
= vty_use_backup_config (config_default_dir
);
2492 fprintf (stderr
, "WARNING: using backup configuration file!\n");
2493 fullpath
= config_default_dir
;
2497 fprintf (stderr
, "can't open configuration file [%s]\n",
2498 config_default_dir
);
2499 goto tmp_free_and_out
;
2503 fullpath
= config_default_dir
;
2506 vty_read_file (confp
);
2510 host_config_set (fullpath
);
2514 XFREE (MTYPE_TMP
, fullpath
);
2517 /* Small utility function which output log to the VTY. */
2519 vty_log (const char *level
, const char *proto_str
,
2520 const char *format
, struct timestamp_control
*ctl
, va_list va
)
2528 for (i
= 0; i
< vector_active (vtyvec
); i
++)
2529 if ((vty
= vector_slot (vtyvec
, i
)) != NULL
)
2534 vty_log_out (vty
, level
, proto_str
, format
, ctl
, ac
);
2539 /* Async-signal-safe version of vty_log for fixed strings. */
2541 vty_log_fixed (char *buf
, size_t len
)
2544 struct iovec iov
[2];
2545 char crlf
[4] = "\r\n";
2547 /* vty may not have been initialised */
2551 iov
[0].iov_base
= buf
;
2552 iov
[0].iov_len
= len
;
2553 iov
[1].iov_base
= crlf
;
2556 for (i
= 0; i
< vector_active (vtyvec
); i
++)
2559 if (((vty
= vector_slot (vtyvec
, i
)) != NULL
) && vty
->monitor
)
2560 /* N.B. We don't care about the return code, since process is
2561 most likely just about to die anyway. */
2562 if (writev(vty
->wfd
, iov
, 2) == -1)
2564 fprintf(stderr
, "Failure to writev: %d\n", errno
);
2571 vty_config_lock (struct vty
*vty
)
2573 if (vty_config_is_lockless
)
2575 if (vty_config
== 0)
2584 vty_config_unlock (struct vty
*vty
)
2586 if (vty_config_is_lockless
)
2588 if (vty_config
== 1 && vty
->config
== 1)
2597 vty_config_lockless (void)
2599 vty_config_is_lockless
= 1;
2602 /* Master of the threads. */
2603 static struct thread_master
*vty_master
;
2606 vty_event (enum event event
, int sock
, struct vty
*vty
)
2608 struct thread
*vty_serv_thread
;
2613 vty_serv_thread
= thread_add_read (vty_master
, vty_accept
, vty
, sock
);
2614 vector_set_index (Vvty_serv_thread
, sock
, vty_serv_thread
);
2618 vty_serv_thread
= thread_add_read (vty_master
, vtysh_accept
, vty
, sock
);
2619 vector_set_index (Vvty_serv_thread
, sock
, vty_serv_thread
);
2622 vty
->t_read
= thread_add_read (vty_master
, vtysh_read
, vty
, sock
);
2625 vty
->t_write
= thread_add_write (vty_master
, vtysh_write
, vty
, sock
);
2629 vty
->t_read
= thread_add_read (vty_master
, vty_read
, vty
, sock
);
2631 /* Time out treatment. */
2635 thread_cancel (vty
->t_timeout
);
2637 thread_add_timer (vty_master
, vty_timeout
, vty
, vty
->v_timeout
);
2642 vty
->t_write
= thread_add_write (vty_master
, vty_flush
, vty
, sock
);
2644 case VTY_TIMEOUT_RESET
:
2647 thread_cancel (vty
->t_timeout
);
2648 vty
->t_timeout
= NULL
;
2653 thread_add_timer (vty_master
, vty_timeout
, vty
, vty
->v_timeout
);
2662 "Display who is on vty\n")
2667 for (i
= 0; i
< vector_active (vtyvec
); i
++)
2668 if ((v
= vector_slot (vtyvec
, i
)) != NULL
)
2669 vty_out (vty
, "%svty[%d] connected from %s.%s",
2670 v
->config
? "*" : " ",
2671 i
, v
->address
, VTY_NEWLINE
);
2675 /* Move to vty configuration mode. */
2679 "Configure a terminal line\n"
2680 "Virtual terminal\n")
2682 vty
->node
= VTY_NODE
;
2686 /* Set time out value. */
2688 exec_timeout (struct vty
*vty
, const char *min_str
, const char *sec_str
)
2690 unsigned long timeout
= 0;
2692 /* min_str and sec_str are already checked by parser. So it must be
2693 all digit string. */
2696 timeout
= strtol (min_str
, NULL
, 10);
2700 timeout
+= strtol (sec_str
, NULL
, 10);
2702 vty_timeout_val
= timeout
;
2703 vty
->v_timeout
= timeout
;
2704 vty_event (VTY_TIMEOUT_RESET
, 0, vty
);
2710 DEFUN (exec_timeout_min
,
2711 exec_timeout_min_cmd
,
2712 "exec-timeout (0-35791)",
2713 "Set timeout value\n"
2714 "Timeout value in minutes\n")
2717 return exec_timeout (vty
, argv
[idx_number
]->arg
, NULL
);
2720 DEFUN (exec_timeout_sec
,
2721 exec_timeout_sec_cmd
,
2722 "exec-timeout (0-35791) (0-2147483)",
2723 "Set the EXEC timeout\n"
2724 "Timeout in minutes\n"
2725 "Timeout in seconds\n")
2728 int idx_number_2
= 2;
2729 return exec_timeout (vty
, argv
[idx_number
]->arg
, argv
[idx_number_2
]->arg
);
2732 DEFUN (no_exec_timeout
,
2733 no_exec_timeout_cmd
,
2736 "Set the EXEC timeout\n")
2738 return exec_timeout (vty
, NULL
, NULL
);
2741 /* Set vty access class. */
2742 DEFUN (vty_access_class
,
2743 vty_access_class_cmd
,
2744 "access-class WORD",
2745 "Filter connections based on an IP access list\n"
2749 if (vty_accesslist_name
)
2750 XFREE(MTYPE_VTY
, vty_accesslist_name
);
2752 vty_accesslist_name
= XSTRDUP(MTYPE_VTY
, argv
[idx_word
]->arg
);
2757 /* Clear vty access class. */
2758 DEFUN (no_vty_access_class
,
2759 no_vty_access_class_cmd
,
2760 "no access-class [WORD]",
2762 "Filter connections based on an IP access list\n"
2766 const char *accesslist
= (argc
== 3) ? argv
[idx_word
]->arg
: NULL
;
2767 if (! vty_accesslist_name
|| (argc
== 3 && strcmp(vty_accesslist_name
, accesslist
)))
2769 vty_out (vty
, "Access-class is not currently applied to vty%s",
2774 XFREE(MTYPE_VTY
, vty_accesslist_name
);
2776 vty_accesslist_name
= NULL
;
2781 /* Set vty access class. */
2782 DEFUN (vty_ipv6_access_class
,
2783 vty_ipv6_access_class_cmd
,
2784 "ipv6 access-class WORD",
2786 "Filter connections based on an IP access list\n"
2787 "IPv6 access list\n")
2790 if (vty_ipv6_accesslist_name
)
2791 XFREE(MTYPE_VTY
, vty_ipv6_accesslist_name
);
2793 vty_ipv6_accesslist_name
= XSTRDUP(MTYPE_VTY
, argv
[idx_word
]->arg
);
2798 /* Clear vty access class. */
2799 DEFUN (no_vty_ipv6_access_class
,
2800 no_vty_ipv6_access_class_cmd
,
2801 "no ipv6 access-class [WORD]",
2804 "Filter connections based on an IP access list\n"
2805 "IPv6 access list\n")
2808 const char *accesslist
= (argc
== 4) ? argv
[idx_word
]->arg
: NULL
;
2810 if (! vty_ipv6_accesslist_name
||
2811 (argc
== 4 && strcmp(vty_ipv6_accesslist_name
, accesslist
)))
2813 vty_out (vty
, "IPv6 access-class is not currently applied to vty%s",
2818 XFREE(MTYPE_VTY
, vty_ipv6_accesslist_name
);
2820 vty_ipv6_accesslist_name
= NULL
;
2829 "Enable password checking\n")
2831 no_password_check
= 0;
2835 DEFUN (no_vty_login
,
2839 "Enable password checking\n")
2841 no_password_check
= 1;
2845 DEFUN (service_advanced_vty
,
2846 service_advanced_vty_cmd
,
2847 "service advanced-vty",
2848 "Set up miscellaneous service\n"
2849 "Enable advanced mode vty interface\n")
2855 DEFUN (no_service_advanced_vty
,
2856 no_service_advanced_vty_cmd
,
2857 "no service advanced-vty",
2859 "Set up miscellaneous service\n"
2860 "Enable advanced mode vty interface\n")
2866 DEFUN (terminal_monitor
,
2867 terminal_monitor_cmd
,
2869 "Set terminal line parameters\n"
2870 "Copy debug output to the current terminal line\n")
2876 DEFUN (terminal_no_monitor
,
2877 terminal_no_monitor_cmd
,
2878 "terminal no monitor",
2879 "Set terminal line parameters\n"
2881 "Copy debug output to the current terminal line\n")
2887 DEFUN (no_terminal_monitor
,
2888 no_terminal_monitor_cmd
,
2889 "no terminal monitor",
2891 "Set terminal line parameters\n"
2892 "Copy debug output to the current terminal line\n")
2894 return terminal_no_monitor (self
, vty
, argc
, argv
);
2898 DEFUN (show_history
,
2902 "Display the session command history\n")
2906 for (index
= vty
->hindex
+ 1; index
!= vty
->hindex
;)
2908 if (index
== VTY_MAXHIST
)
2914 if (vty
->hist
[index
] != NULL
)
2915 vty_out (vty
, " %s%s", vty
->hist
[index
], VTY_NEWLINE
);
2924 DEFUN (log_commands
,
2928 "Log all commands (can't be unset without restart)\n")
2930 do_log_commands
= 1;
2934 /* Display current configuration. */
2936 vty_config_write (struct vty
*vty
)
2938 vty_out (vty
, "line vty%s", VTY_NEWLINE
);
2940 if (vty_accesslist_name
)
2941 vty_out (vty
, " access-class %s%s",
2942 vty_accesslist_name
, VTY_NEWLINE
);
2944 if (vty_ipv6_accesslist_name
)
2945 vty_out (vty
, " ipv6 access-class %s%s",
2946 vty_ipv6_accesslist_name
, VTY_NEWLINE
);
2949 if (vty_timeout_val
!= VTY_TIMEOUT_DEFAULT
)
2950 vty_out (vty
, " exec-timeout %ld %ld%s",
2951 vty_timeout_val
/ 60,
2952 vty_timeout_val
% 60, VTY_NEWLINE
);
2955 if (no_password_check
)
2956 vty_out (vty
, " no login%s", VTY_NEWLINE
);
2958 if (do_log_commands
)
2959 vty_out (vty
, "log commands%s", VTY_NEWLINE
);
2961 vty_out (vty
, "!%s", VTY_NEWLINE
);
2966 struct cmd_node vty_node
=
2969 "%s(config-line)# ",
2973 /* Reset all VTY status. */
2979 struct thread
*vty_serv_thread
;
2981 for (i
= 0; i
< vector_active (vtyvec
); i
++)
2982 if ((vty
= vector_slot (vtyvec
, i
)) != NULL
)
2984 buffer_reset (vty
->obuf
);
2985 vty
->status
= VTY_CLOSE
;
2989 for (i
= 0; i
< vector_active (Vvty_serv_thread
); i
++)
2990 if ((vty_serv_thread
= vector_slot (Vvty_serv_thread
, i
)) != NULL
)
2992 thread_cancel (vty_serv_thread
);
2993 vector_slot (Vvty_serv_thread
, i
) = NULL
;
2997 vty_timeout_val
= VTY_TIMEOUT_DEFAULT
;
2999 if (vty_accesslist_name
)
3001 XFREE(MTYPE_VTY
, vty_accesslist_name
);
3002 vty_accesslist_name
= NULL
;
3005 if (vty_ipv6_accesslist_name
)
3007 XFREE(MTYPE_VTY
, vty_ipv6_accesslist_name
);
3008 vty_ipv6_accesslist_name
= NULL
;
3015 char cwd
[MAXPATHLEN
];
3018 c
= getcwd (cwd
, MAXPATHLEN
);
3023 * At this point if these go wrong, more than likely
3024 * the whole world is coming down around us
3025 * Hence not worrying about it too much.
3027 if (!chdir (SYSCONFDIR
))
3029 fprintf(stderr
, "Failure to chdir to %s, errno: %d\n", SYSCONFDIR
, errno
);
3032 if (getcwd (cwd
, MAXPATHLEN
) == NULL
)
3034 fprintf(stderr
, "Failure to getcwd, errno: %d\n", errno
);
3039 vty_cwd
= XMALLOC (MTYPE_TMP
, strlen (cwd
) + 1);
3040 strcpy (vty_cwd
, cwd
);
3050 vty_shell (struct vty
*vty
)
3052 return vty
->type
== VTY_SHELL
? 1 : 0;
3056 vty_shell_serv (struct vty
*vty
)
3058 return vty
->type
== VTY_SHELL_SERV
? 1 : 0;
3064 vtyvec
= vector_init (VECTOR_MIN_SIZE
);
3067 /* Install vty's own commands like `who' command. */
3069 vty_init (struct thread_master
*master_thread
)
3071 /* For further configuration read, preserve current directory. */
3074 vtyvec
= vector_init (VECTOR_MIN_SIZE
);
3076 vty_master
= master_thread
;
3078 atexit (vty_stdio_reset
);
3080 /* Initilize server thread vector. */
3081 Vvty_serv_thread
= vector_init (VECTOR_MIN_SIZE
);
3083 /* Install bgp top node. */
3084 install_node (&vty_node
, vty_config_write
);
3086 install_element (VIEW_NODE
, &config_who_cmd
);
3087 install_element (VIEW_NODE
, &show_history_cmd
);
3088 install_element (CONFIG_NODE
, &line_vty_cmd
);
3089 install_element (CONFIG_NODE
, &service_advanced_vty_cmd
);
3090 install_element (CONFIG_NODE
, &no_service_advanced_vty_cmd
);
3091 install_element (CONFIG_NODE
, &show_history_cmd
);
3092 install_element (CONFIG_NODE
, &log_commands_cmd
);
3093 install_element (ENABLE_NODE
, &terminal_monitor_cmd
);
3094 install_element (ENABLE_NODE
, &terminal_no_monitor_cmd
);
3095 install_element (ENABLE_NODE
, &no_terminal_monitor_cmd
);
3097 install_default (VTY_NODE
);
3098 install_element (VTY_NODE
, &exec_timeout_min_cmd
);
3099 install_element (VTY_NODE
, &exec_timeout_sec_cmd
);
3100 install_element (VTY_NODE
, &no_exec_timeout_cmd
);
3101 install_element (VTY_NODE
, &vty_access_class_cmd
);
3102 install_element (VTY_NODE
, &no_vty_access_class_cmd
);
3103 install_element (VTY_NODE
, &vty_login_cmd
);
3104 install_element (VTY_NODE
, &no_vty_login_cmd
);
3105 install_element (VTY_NODE
, &vty_ipv6_access_class_cmd
);
3106 install_element (VTY_NODE
, &no_vty_ipv6_access_class_cmd
);
3110 vty_terminate (void)
3113 XFREE (MTYPE_TMP
, vty_cwd
);
3115 if (vtyvec
&& Vvty_serv_thread
)
3118 vector_free (vtyvec
);
3119 vector_free (Vvty_serv_thread
);
3123 /* Utility functions to get arguments from commands generated
3124 by the xml2cli.pl script. */
3126 vty_get_arg_value (struct vty_arg
*args
[], const char *arg
)
3130 if (strcmp ((*args
)->name
, arg
) == 0)
3131 return (*args
)->value
;
3138 vty_get_arg (struct vty_arg
*args
[], const char *arg
)
3142 if (strcmp ((*args
)->name
, arg
) == 0)