]>
Commit | Line | Data |
---|---|---|
718e3744 | 1 | /* Virtual terminal [aka TeletYpe] interface routine |
2 | Copyright (C) 1997 Kunihiro Ishiguro | |
3 | ||
4 | This file is part of GNU Zebra. | |
5 | ||
6 | GNU Zebra is free software; you can redistribute it and/or modify it | |
7 | under the terms of the GNU General Public License as published by the | |
8 | Free Software Foundation; either version 2, or (at your option) any | |
9 | later version. | |
10 | ||
11 | GNU Zebra is distributed in the hope that it will be useful, but | |
12 | WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 | General Public License for more details. | |
15 | ||
16 | You should have received a copy of the GNU General Public License | |
17 | along with GNU Zebra; see the file COPYING. If not, write to the Free | |
18 | Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA | |
19 | 02111-1307, USA. */ | |
20 | ||
21 | #ifndef _ZEBRA_VTY_H | |
22 | #define _ZEBRA_VTY_H | |
23 | ||
b21b19c5 | 24 | #include "thread.h" |
1ed72e0b | 25 | #include "log.h" |
d227617a | 26 | #include "sockunion.h" |
b21b19c5 | 27 | |
718e3744 | 28 | #define VTY_BUFSIZ 512 |
29 | #define VTY_MAXHIST 20 | |
30 | ||
31 | /* VTY struct. */ | |
32 | struct vty | |
33 | { | |
34 | /* File descripter of this vty. */ | |
35 | int fd; | |
36 | ||
37 | /* Is this vty connect to file or not */ | |
38 | enum {VTY_TERM, VTY_FILE, VTY_SHELL, VTY_SHELL_SERV} type; | |
39 | ||
40 | /* Node status of this vty */ | |
41 | int node; | |
42 | ||
718e3744 | 43 | /* Failure count */ |
44 | int fail; | |
45 | ||
46 | /* Output buffer. */ | |
47 | struct buffer *obuf; | |
48 | ||
49 | /* Command input buffer */ | |
50 | char *buf; | |
51 | ||
5689fe5f DW |
52 | /* Command input error buffer */ |
53 | char *error_buf; | |
54 | ||
718e3744 | 55 | /* Command cursor point */ |
56 | int cp; | |
57 | ||
58 | /* Command length */ | |
59 | int length; | |
60 | ||
61 | /* Command max length. */ | |
62 | int max; | |
63 | ||
64 | /* Histry of command */ | |
65 | char *hist[VTY_MAXHIST]; | |
66 | ||
67 | /* History lookup current point */ | |
68 | int hp; | |
69 | ||
70 | /* History insert end point */ | |
71 | int hindex; | |
72 | ||
73 | /* For current referencing point of interface, route-map, | |
74 | access-list etc... */ | |
75 | void *index; | |
76 | ||
77 | /* For multiple level index treatment such as key chain and key. */ | |
78 | void *index_sub; | |
79 | ||
80 | /* For escape character. */ | |
81 | unsigned char escape; | |
82 | ||
83 | /* Current vty status. */ | |
5a646650 | 84 | enum {VTY_NORMAL, VTY_CLOSE, VTY_MORE, VTY_MORELINE} status; |
718e3744 | 85 | |
9fc7ebf1 | 86 | /* IAC handling: was the last character received the |
87 | IAC (interpret-as-command) escape character (and therefore the next | |
88 | character will be the command code)? Refer to Telnet RFC 854. */ | |
718e3744 | 89 | unsigned char iac; |
90 | ||
9fc7ebf1 | 91 | /* IAC SB (option subnegotiation) handling */ |
718e3744 | 92 | unsigned char iac_sb_in_progress; |
9fc7ebf1 | 93 | /* At the moment, we care only about the NAWS (window size) negotiation, |
94 | and that requires just a 5-character buffer (RFC 1073): | |
95 | <NAWS char> <16-bit width> <16-bit height> */ | |
96 | #define TELNET_NAWS_SB_LEN 5 | |
97 | unsigned char sb_buf[TELNET_NAWS_SB_LEN]; | |
98 | /* How many subnegotiation characters have we received? We just drop | |
99 | those that do not fit in the buffer. */ | |
100 | size_t sb_len; | |
718e3744 | 101 | |
102 | /* Window width/height. */ | |
103 | int width; | |
104 | int height; | |
105 | ||
718e3744 | 106 | /* Configure lines. */ |
107 | int lines; | |
108 | ||
718e3744 | 109 | /* Terminal monitor. */ |
110 | int monitor; | |
111 | ||
112 | /* In configure mode. */ | |
113 | int config; | |
114 | ||
115 | /* Read and write thread. */ | |
116 | struct thread *t_read; | |
117 | struct thread *t_write; | |
118 | ||
119 | /* Timeout seconds and thread. */ | |
120 | unsigned long v_timeout; | |
121 | struct thread *t_timeout; | |
d227617a JBD |
122 | |
123 | /* What address is this vty comming from. */ | |
124 | char address[SU_ADDRSTRLEN]; | |
718e3744 | 125 | }; |
126 | ||
127 | /* Integrated configuration file. */ | |
e8f2984c | 128 | #define INTEGRATE_DEFAULT_CONFIG "Quagga.conf" |
718e3744 | 129 | |
130 | /* Small macro to determine newline is newline only or linefeed needed. */ | |
131 | #define VTY_NEWLINE ((vty->type == VTY_TERM) ? "\r\n" : "\n") | |
132 | ||
133 | /* Default time out value */ | |
134 | #define VTY_TIMEOUT_DEFAULT 600 | |
135 | ||
136 | /* Vty read buffer size. */ | |
137 | #define VTY_READ_BUFSIZ 512 | |
138 | ||
139 | /* Directory separator. */ | |
140 | #ifndef DIRECTORY_SEP | |
141 | #define DIRECTORY_SEP '/' | |
142 | #endif /* DIRECTORY_SEP */ | |
143 | ||
144 | #ifndef IS_DIRECTORY_SEP | |
145 | #define IS_DIRECTORY_SEP(c) ((c) == DIRECTORY_SEP) | |
146 | #endif | |
147 | ||
148 | /* GCC have printf type attribute check. */ | |
149 | #ifdef __GNUC__ | |
150 | #define PRINTF_ATTRIBUTE(a,b) __attribute__ ((__format__ (__printf__, a, b))) | |
151 | #else | |
152 | #define PRINTF_ATTRIBUTE(a,b) | |
153 | #endif /* __GNUC__ */ | |
154 | ||
7798b632 AC |
155 | /* Utility macros to convert VTY argument to unsigned long */ |
156 | #define VTY_GET_ULONG(NAME,V,STR) \ | |
d4f0960c | 157 | do { \ |
42d49865 | 158 | char *endptr = NULL; \ |
664711c1 | 159 | errno = 0; \ |
42d49865 | 160 | (V) = strtoul ((STR), &endptr, 10); \ |
664711c1 | 161 | if (*(STR) == '-' || *endptr != '\0' || errno) \ |
42d49865 | 162 | { \ |
718e3744 | 163 | vty_out (vty, "%% Invalid %s value%s", NAME, VTY_NEWLINE); \ |
42d49865 | 164 | return CMD_WARNING; \ |
165 | } \ | |
d4f0960c | 166 | } while (0) |
718e3744 | 167 | |
8fe8a7f6 DS |
168 | /* Utility macros to convert VTY argument to unsigned long long */ |
169 | #define VTY_GET_ULL(NAME,V,STR) \ | |
170 | do { \ | |
171 | char *endptr = NULL; \ | |
172 | errno = 0; \ | |
173 | (V) = strtoull ((STR), &endptr, 10); \ | |
174 | if (*(STR) == '-' || *endptr != '\0' || errno) \ | |
175 | { \ | |
176 | vty_out (vty, "%% Invalid %s value%s", NAME, VTY_NEWLINE); \ | |
177 | return CMD_WARNING; \ | |
178 | } \ | |
179 | } while (0) | |
180 | ||
7798b632 AC |
181 | /* |
182 | * The logic below ((TMPL) <= ((MIN) && (TMPL) != (MIN)) is | |
183 | * done to circumvent the compiler complaining about | |
184 | * comparing unsigned numbers against zero, if MIN is zero. | |
185 | * NB: The compiler isn't smart enough to supress the warning | |
186 | * if you write (MIN) != 0 && tmpl < (MIN). | |
187 | */ | |
188 | #define VTY_GET_INTEGER_RANGE_HEART(NAME,TMPL,STR,MIN,MAX) \ | |
189 | do { \ | |
190 | VTY_GET_ULONG(NAME, (TMPL), STR); \ | |
191 | if ( ((TMPL) <= (MIN) && (TMPL) != (MIN)) || (TMPL) > (MAX) ) \ | |
192 | { \ | |
193 | vty_out (vty, "%% Invalid %s value%s", NAME, VTY_NEWLINE);\ | |
194 | return CMD_WARNING; \ | |
195 | } \ | |
196 | } while (0) | |
197 | ||
198 | #define VTY_GET_INTEGER_RANGE(NAME,V,STR,MIN,MAX) \ | |
199 | do { \ | |
200 | unsigned long tmpl; \ | |
201 | VTY_GET_INTEGER_RANGE_HEART(NAME,tmpl,STR,MIN,MAX); \ | |
202 | (V) = tmpl; \ | |
203 | } while (0) | |
204 | ||
205 | #define VTY_CHECK_INTEGER_RANGE(NAME,STR,MIN,MAX) \ | |
206 | do { \ | |
207 | unsigned long tmpl; \ | |
208 | VTY_GET_INTEGER_RANGE_HEART(NAME,tmpl,STR,MIN,MAX); \ | |
d4f0960c | 209 | } while (0) |
718e3744 | 210 | |
7798b632 AC |
211 | #define VTY_GET_INTEGER(NAME,V,STR) \ |
212 | VTY_GET_INTEGER_RANGE(NAME,V,STR,0U,UINT32_MAX) | |
42d49865 | 213 | |
8cc4198f | 214 | #define VTY_GET_IPV4_ADDRESS(NAME,V,STR) \ |
d4f0960c | 215 | do { \ |
8cc4198f | 216 | int retv; \ |
217 | retv = inet_aton ((STR), &(V)); \ | |
218 | if (!retv) \ | |
219 | { \ | |
220 | vty_out (vty, "%% Invalid %s value%s", NAME, VTY_NEWLINE); \ | |
221 | return CMD_WARNING; \ | |
222 | } \ | |
d4f0960c | 223 | } while (0) |
8cc4198f | 224 | |
225 | #define VTY_GET_IPV4_PREFIX(NAME,V,STR) \ | |
d4f0960c | 226 | do { \ |
8cc4198f | 227 | int retv; \ |
228 | retv = str2prefix_ipv4 ((STR), &(V)); \ | |
229 | if (retv <= 0) \ | |
230 | { \ | |
231 | vty_out (vty, "%% Invalid %s value%s", NAME, VTY_NEWLINE); \ | |
232 | return CMD_WARNING; \ | |
233 | } \ | |
d4f0960c | 234 | } while (0) |
8cc4198f | 235 | |
718e3744 | 236 | /* Exported variables */ |
237 | extern char integrate_default[]; | |
238 | ||
239 | /* Prototypes. */ | |
8cc4198f | 240 | extern void vty_init (struct thread_master *); |
241 | extern void vty_init_vtysh (void); | |
228da428 | 242 | extern void vty_terminate (void); |
8cc4198f | 243 | extern void vty_reset (void); |
244 | extern struct vty *vty_new (void); | |
245 | extern int vty_out (struct vty *, const char *, ...) PRINTF_ATTRIBUTE(2, 3); | |
246 | extern void vty_read_config (char *, char *); | |
247 | extern void vty_time_print (struct vty *, int); | |
248 | extern void vty_serv_sock (const char *, unsigned short, const char *); | |
249 | extern void vty_close (struct vty *); | |
250 | extern char *vty_get_cwd (void); | |
251 | extern void vty_log (const char *level, const char *proto, | |
1ed72e0b | 252 | const char *fmt, struct timestamp_control *, va_list); |
8cc4198f | 253 | extern int vty_config_lock (struct vty *); |
254 | extern int vty_config_unlock (struct vty *); | |
255 | extern int vty_shell (struct vty *); | |
256 | extern int vty_shell_serv (struct vty *); | |
257 | extern void vty_hello (struct vty *); | |
718e3744 | 258 | |
274a4a44 | 259 | /* Send a fixed-size message to all vty terminal monitors; this should be |
260 | an async-signal-safe function. */ | |
24873f0c | 261 | extern void vty_log_fixed (char *buf, size_t len); |
274a4a44 | 262 | |
718e3744 | 263 | #endif /* _ZEBRA_VTY_H */ |