]>
git.proxmox.com Git - mirror_frr.git/blob - lib/vty.h
1 /* Virtual terminal [aka TeletYpe] interface routine
2 Copyright (C) 1997 Kunihiro Ishiguro
4 This file is part of GNU Zebra.
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
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.
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
26 #include "sockunion.h"
28 #define VTY_BUFSIZ 512
29 #define VTY_MAXHIST 20
34 /* File descripter of this vty. */
37 /* output FD, to support stdin/stdout combination */
40 /* Is this vty connect to file or not */
41 enum {VTY_TERM
, VTY_FILE
, VTY_SHELL
, VTY_SHELL_SERV
} type
;
43 /* Node status of this vty */
52 /* Command input buffer */
55 /* Command input error buffer */
58 /* Command cursor point */
64 /* Command max length. */
67 /* Histry of command */
68 char *hist
[VTY_MAXHIST
];
70 /* History lookup current point */
73 /* History insert end point */
76 /* For current referencing point of interface, route-map,
80 /* For multiple level index treatment such as key chain and key. */
83 /* For escape character. */
86 /* Current vty status. */
87 enum {VTY_NORMAL
, VTY_CLOSE
, VTY_MORE
, VTY_MORELINE
} status
;
89 /* IAC handling: was the last character received the
90 IAC (interpret-as-command) escape character (and therefore the next
91 character will be the command code)? Refer to Telnet RFC 854. */
94 /* IAC SB (option subnegotiation) handling */
95 unsigned char iac_sb_in_progress
;
96 /* At the moment, we care only about the NAWS (window size) negotiation,
97 and that requires just a 5-character buffer (RFC 1073):
98 <NAWS char> <16-bit width> <16-bit height> */
99 #define TELNET_NAWS_SB_LEN 5
100 unsigned char sb_buf
[TELNET_NAWS_SB_LEN
];
101 /* How many subnegotiation characters have we received? We just drop
102 those that do not fit in the buffer. */
105 /* Window width/height. */
109 /* Configure lines. */
112 /* Terminal monitor. */
115 /* In configure mode. */
118 /* Read and write thread. */
119 struct thread
*t_read
;
120 struct thread
*t_write
;
122 /* Timeout seconds and thread. */
123 unsigned long v_timeout
;
124 struct thread
*t_timeout
;
126 /* What address is this vty comming from. */
127 char address
[SU_ADDRSTRLEN
];
130 /* Integrated configuration file. */
131 #define INTEGRATE_DEFAULT_CONFIG "Quagga.conf"
133 /* Small macro to determine newline is newline only or linefeed needed. */
134 #define VTY_NEWLINE ((vty->type == VTY_TERM) ? "\r\n" : "\n")
136 /* Default time out value */
137 #define VTY_TIMEOUT_DEFAULT 600
139 /* Vty read buffer size. */
140 #define VTY_READ_BUFSIZ 512
142 /* Directory separator. */
143 #ifndef DIRECTORY_SEP
144 #define DIRECTORY_SEP '/'
145 #endif /* DIRECTORY_SEP */
147 #ifndef IS_DIRECTORY_SEP
148 #define IS_DIRECTORY_SEP(c) ((c) == DIRECTORY_SEP)
151 /* GCC have printf type attribute check. */
153 #define PRINTF_ATTRIBUTE(a,b) __attribute__ ((__format__ (__printf__, a, b)))
155 #define PRINTF_ATTRIBUTE(a,b)
156 #endif /* __GNUC__ */
158 /* Utility macros to convert VTY argument to unsigned long */
159 #define VTY_GET_ULONG(NAME,V,STR) \
161 char *endptr = NULL; \
163 (V) = strtoul ((STR), &endptr, 10); \
166 vty_out (vty, "%% Invalid %s value (dash)%s", NAME, VTY_NEWLINE); \
167 return CMD_WARNING; \
169 if (*endptr != '\0') \
171 vty_out (vty, "%% Invalid %s value (%s)%s", NAME, endptr, VTY_NEWLINE); \
172 return CMD_WARNING; \
176 vty_out (vty, "%% Invalid %s value (error %d)%s", NAME, errno, VTY_NEWLINE); \
177 return CMD_WARNING; \
181 /* Utility macros to convert VTY argument to unsigned long long */
182 #define VTY_GET_ULL(NAME,V,STR) \
184 char *endptr = NULL; \
186 (V) = strtoull ((STR), &endptr, 10); \
189 vty_out (vty, "%% Invalid %s value (dash)%s", NAME, VTY_NEWLINE); \
190 return CMD_WARNING; \
192 if (*endptr != '\0') \
194 vty_out (vty, "%% Invalid %s value (%s)%s", NAME, endptr, VTY_NEWLINE); \
195 return CMD_WARNING; \
199 vty_out (vty, "%% Invalid %s value (error %d)%s", NAME, errno, VTY_NEWLINE); \
200 return CMD_WARNING; \
205 * The logic below ((TMPL) <= ((MIN) && (TMPL) != (MIN)) is
206 * done to circumvent the compiler complaining about
207 * comparing unsigned numbers against zero, if MIN is zero.
208 * NB: The compiler isn't smart enough to supress the warning
209 * if you write (MIN) != 0 && tmpl < (MIN).
211 #define VTY_GET_INTEGER_RANGE_HEART(NAME,TMPL,STR,MIN,MAX) \
213 VTY_GET_ULONG(NAME, (TMPL), STR); \
214 if ( ((TMPL) <= (MIN) && (TMPL) != (MIN)) || (TMPL) > (MAX) ) \
216 vty_out (vty, "%% Invalid %s value%s", NAME, VTY_NEWLINE);\
217 return CMD_WARNING; \
221 #define VTY_GET_INTEGER_RANGE(NAME,V,STR,MIN,MAX) \
223 unsigned long tmpl; \
224 VTY_GET_INTEGER_RANGE_HEART(NAME,tmpl,STR,MIN,MAX); \
228 #define VTY_CHECK_INTEGER_RANGE(NAME,STR,MIN,MAX) \
230 unsigned long tmpl; \
231 VTY_GET_INTEGER_RANGE_HEART(NAME,tmpl,STR,MIN,MAX); \
234 #define VTY_GET_INTEGER(NAME,V,STR) \
235 VTY_GET_INTEGER_RANGE(NAME,V,STR,0U,UINT32_MAX)
237 #define VTY_GET_IPV4_ADDRESS(NAME,V,STR) \
240 retv = inet_aton ((STR), &(V)); \
243 vty_out (vty, "%% Invalid %s value%s", NAME, VTY_NEWLINE); \
244 return CMD_WARNING; \
248 #define VTY_GET_IPV4_PREFIX(NAME,V,STR) \
251 retv = str2prefix_ipv4 ((STR), &(V)); \
254 vty_out (vty, "%% Invalid %s value%s", NAME, VTY_NEWLINE); \
255 return CMD_WARNING; \
259 #define VTY_WARN_EXPERIMENTAL() \
261 vty_out (vty, "%% WARNING: this command is experimental. Both its name and" \
262 " parameters may%s%% change in a future version of Quagga," \
263 " possibly breaking your configuration!%s", \
264 VTY_NEWLINE, VTY_NEWLINE); \
267 /* Exported variables */
268 extern char integrate_default
[];
271 extern void vty_init (struct thread_master
*);
272 extern void vty_init_vtysh (void);
273 extern void vty_terminate (void);
274 extern void vty_reset (void);
275 extern struct vty
*vty_new (void);
276 extern struct vty
*vty_stdio (void (*atclose
)(void));
277 extern int vty_out (struct vty
*, const char *, ...) PRINTF_ATTRIBUTE(2, 3);
278 extern void vty_read_config (char *, char *);
279 extern void vty_time_print (struct vty
*, int);
280 extern void vty_serv_sock (const char *, unsigned short, const char *);
281 extern void vty_close (struct vty
*);
282 extern char *vty_get_cwd (void);
283 extern void vty_log (const char *level
, const char *proto
,
284 const char *fmt
, struct timestamp_control
*, va_list);
285 extern int vty_config_lock (struct vty
*);
286 extern int vty_config_unlock (struct vty
*);
287 extern int vty_shell (struct vty
*);
288 extern int vty_shell_serv (struct vty
*);
289 extern void vty_hello (struct vty
*);
291 /* Send a fixed-size message to all vty terminal monitors; this should be
292 an async-signal-safe function. */
293 extern void vty_log_fixed (char *buf
, size_t len
);
295 #endif /* _ZEBRA_VTY_H */