Annotation of embedaddon/quagga/lib/vty.h, revision 1.1.1.3
1.1 misho 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:
24: #include "thread.h"
25: #include "log.h"
1.1.1.3 ! misho 26: #include "sockunion.h"
1.1 misho 27:
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:
43: /* Failure count */
44: int fail;
45:
46: /* Output buffer. */
47: struct buffer *obuf;
48:
49: /* Command input buffer */
50: char *buf;
51:
52: /* Command cursor point */
53: int cp;
54:
55: /* Command length */
56: int length;
57:
58: /* Command max length. */
59: int max;
60:
61: /* Histry of command */
62: char *hist[VTY_MAXHIST];
63:
64: /* History lookup current point */
65: int hp;
66:
67: /* History insert end point */
68: int hindex;
69:
70: /* For current referencing point of interface, route-map,
71: access-list etc... */
72: void *index;
73:
74: /* For multiple level index treatment such as key chain and key. */
75: void *index_sub;
76:
77: /* For escape character. */
78: unsigned char escape;
79:
80: /* Current vty status. */
81: enum {VTY_NORMAL, VTY_CLOSE, VTY_MORE, VTY_MORELINE} status;
82:
83: /* IAC handling: was the last character received the
84: IAC (interpret-as-command) escape character (and therefore the next
85: character will be the command code)? Refer to Telnet RFC 854. */
86: unsigned char iac;
87:
88: /* IAC SB (option subnegotiation) handling */
89: unsigned char iac_sb_in_progress;
90: /* At the moment, we care only about the NAWS (window size) negotiation,
91: and that requires just a 5-character buffer (RFC 1073):
92: <NAWS char> <16-bit width> <16-bit height> */
93: #define TELNET_NAWS_SB_LEN 5
94: unsigned char sb_buf[TELNET_NAWS_SB_LEN];
95: /* How many subnegotiation characters have we received? We just drop
96: those that do not fit in the buffer. */
97: size_t sb_len;
98:
99: /* Window width/height. */
100: int width;
101: int height;
102:
103: /* Configure lines. */
104: int lines;
105:
106: /* Terminal monitor. */
107: int monitor;
108:
109: /* In configure mode. */
110: int config;
111:
112: /* Read and write thread. */
113: struct thread *t_read;
114: struct thread *t_write;
115:
116: /* Timeout seconds and thread. */
117: unsigned long v_timeout;
118: struct thread *t_timeout;
1.1.1.3 ! misho 119:
! 120: /* What address is this vty comming from. */
! 121: char address[SU_ADDRSTRLEN];
1.1 misho 122: };
123:
124: /* Integrated configuration file. */
125: #define INTEGRATE_DEFAULT_CONFIG "Quagga.conf"
126:
127: /* Small macro to determine newline is newline only or linefeed needed. */
128: #define VTY_NEWLINE ((vty->type == VTY_TERM) ? "\r\n" : "\n")
129:
130: /* Default time out value */
131: #define VTY_TIMEOUT_DEFAULT 600
132:
133: /* Vty read buffer size. */
134: #define VTY_READ_BUFSIZ 512
135:
136: /* Directory separator. */
137: #ifndef DIRECTORY_SEP
138: #define DIRECTORY_SEP '/'
139: #endif /* DIRECTORY_SEP */
140:
141: #ifndef IS_DIRECTORY_SEP
142: #define IS_DIRECTORY_SEP(c) ((c) == DIRECTORY_SEP)
143: #endif
144:
145: /* GCC have printf type attribute check. */
146: #ifdef __GNUC__
147: #define PRINTF_ATTRIBUTE(a,b) __attribute__ ((__format__ (__printf__, a, b)))
148: #else
149: #define PRINTF_ATTRIBUTE(a,b)
150: #endif /* __GNUC__ */
151:
1.1.1.3 ! misho 152: /* Utility macros to convert VTY argument to unsigned long */
! 153: #define VTY_GET_ULONG(NAME,V,STR) \
1.1 misho 154: do { \
155: char *endptr = NULL; \
1.1.1.2 misho 156: errno = 0; \
1.1 misho 157: (V) = strtoul ((STR), &endptr, 10); \
1.1.1.2 misho 158: if (*(STR) == '-' || *endptr != '\0' || errno) \
1.1 misho 159: { \
160: vty_out (vty, "%% Invalid %s value%s", NAME, VTY_NEWLINE); \
161: return CMD_WARNING; \
162: } \
163: } while (0)
164:
1.1.1.3 ! misho 165: /*
! 166: * The logic below ((TMPL) <= ((MIN) && (TMPL) != (MIN)) is
! 167: * done to circumvent the compiler complaining about
! 168: * comparing unsigned numbers against zero, if MIN is zero.
! 169: * NB: The compiler isn't smart enough to supress the warning
! 170: * if you write (MIN) != 0 && tmpl < (MIN).
! 171: */
! 172: #define VTY_GET_INTEGER_RANGE_HEART(NAME,TMPL,STR,MIN,MAX) \
! 173: do { \
! 174: VTY_GET_ULONG(NAME, (TMPL), STR); \
! 175: if ( ((TMPL) <= (MIN) && (TMPL) != (MIN)) || (TMPL) > (MAX) ) \
! 176: { \
! 177: vty_out (vty, "%% Invalid %s value%s", NAME, VTY_NEWLINE);\
! 178: return CMD_WARNING; \
! 179: } \
! 180: } while (0)
! 181:
! 182: #define VTY_GET_INTEGER_RANGE(NAME,V,STR,MIN,MAX) \
! 183: do { \
! 184: unsigned long tmpl; \
! 185: VTY_GET_INTEGER_RANGE_HEART(NAME,tmpl,STR,MIN,MAX); \
! 186: (V) = tmpl; \
! 187: } while (0)
! 188:
! 189: #define VTY_CHECK_INTEGER_RANGE(NAME,STR,MIN,MAX) \
! 190: do { \
! 191: unsigned long tmpl; \
! 192: VTY_GET_INTEGER_RANGE_HEART(NAME,tmpl,STR,MIN,MAX); \
1.1 misho 193: } while (0)
194:
1.1.1.3 ! misho 195: #define VTY_GET_INTEGER(NAME,V,STR) \
! 196: VTY_GET_INTEGER_RANGE(NAME,V,STR,0U,UINT32_MAX)
1.1 misho 197:
198: #define VTY_GET_IPV4_ADDRESS(NAME,V,STR) \
199: do { \
200: int retv; \
201: retv = inet_aton ((STR), &(V)); \
202: if (!retv) \
203: { \
204: vty_out (vty, "%% Invalid %s value%s", NAME, VTY_NEWLINE); \
205: return CMD_WARNING; \
206: } \
207: } while (0)
208:
209: #define VTY_GET_IPV4_PREFIX(NAME,V,STR) \
210: do { \
211: int retv; \
212: retv = str2prefix_ipv4 ((STR), &(V)); \
213: if (retv <= 0) \
214: { \
215: vty_out (vty, "%% Invalid %s value%s", NAME, VTY_NEWLINE); \
216: return CMD_WARNING; \
217: } \
218: } while (0)
219:
220: /* Exported variables */
221: extern char integrate_default[];
222:
223: /* Prototypes. */
224: extern void vty_init (struct thread_master *);
225: extern void vty_init_vtysh (void);
226: extern void vty_terminate (void);
227: extern void vty_reset (void);
228: extern struct vty *vty_new (void);
229: extern int vty_out (struct vty *, const char *, ...) PRINTF_ATTRIBUTE(2, 3);
230: extern void vty_read_config (char *, char *);
231: extern void vty_time_print (struct vty *, int);
232: extern void vty_serv_sock (const char *, unsigned short, const char *);
233: extern void vty_close (struct vty *);
234: extern char *vty_get_cwd (void);
235: extern void vty_log (const char *level, const char *proto,
236: const char *fmt, struct timestamp_control *, va_list);
237: extern int vty_config_lock (struct vty *);
238: extern int vty_config_unlock (struct vty *);
239: extern int vty_shell (struct vty *);
240: extern int vty_shell_serv (struct vty *);
241: extern void vty_hello (struct vty *);
242:
243: /* Send a fixed-size message to all vty terminal monitors; this should be
244: an async-signal-safe function. */
245: extern void vty_log_fixed (const char *buf, size_t len);
246:
247: #endif /* _ZEBRA_VTY_H */
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>