]>
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" |
25 | ||
718e3744 | 26 | #define VTY_BUFSIZ 512 |
27 | #define VTY_MAXHIST 20 | |
28 | ||
29 | /* VTY struct. */ | |
30 | struct vty | |
31 | { | |
32 | /* File descripter of this vty. */ | |
33 | int fd; | |
34 | ||
35 | /* Is this vty connect to file or not */ | |
36 | enum {VTY_TERM, VTY_FILE, VTY_SHELL, VTY_SHELL_SERV} type; | |
37 | ||
38 | /* Node status of this vty */ | |
39 | int node; | |
40 | ||
41 | /* What address is this vty comming from. */ | |
42 | char *address; | |
43 | ||
718e3744 | 44 | /* Failure count */ |
45 | int fail; | |
46 | ||
47 | /* Output buffer. */ | |
48 | struct buffer *obuf; | |
49 | ||
50 | /* Command input buffer */ | |
51 | char *buf; | |
52 | ||
53 | /* Command cursor point */ | |
54 | int cp; | |
55 | ||
56 | /* Command length */ | |
57 | int length; | |
58 | ||
59 | /* Command max length. */ | |
60 | int max; | |
61 | ||
62 | /* Histry of command */ | |
63 | char *hist[VTY_MAXHIST]; | |
64 | ||
65 | /* History lookup current point */ | |
66 | int hp; | |
67 | ||
68 | /* History insert end point */ | |
69 | int hindex; | |
70 | ||
71 | /* For current referencing point of interface, route-map, | |
72 | access-list etc... */ | |
73 | void *index; | |
74 | ||
75 | /* For multiple level index treatment such as key chain and key. */ | |
76 | void *index_sub; | |
77 | ||
78 | /* For escape character. */ | |
79 | unsigned char escape; | |
80 | ||
81 | /* Current vty status. */ | |
5a646650 | 82 | enum {VTY_NORMAL, VTY_CLOSE, VTY_MORE, VTY_MORELINE} status; |
718e3744 | 83 | |
84 | /* IAC handling */ | |
85 | unsigned char iac; | |
86 | ||
87 | /* IAC SB handling */ | |
88 | unsigned char iac_sb_in_progress; | |
89 | struct buffer *sb_buffer; | |
90 | ||
91 | /* Window width/height. */ | |
92 | int width; | |
93 | int height; | |
94 | ||
718e3744 | 95 | /* Configure lines. */ |
96 | int lines; | |
97 | ||
718e3744 | 98 | /* Terminal monitor. */ |
99 | int monitor; | |
100 | ||
101 | /* In configure mode. */ | |
102 | int config; | |
103 | ||
104 | /* Read and write thread. */ | |
105 | struct thread *t_read; | |
106 | struct thread *t_write; | |
107 | ||
108 | /* Timeout seconds and thread. */ | |
109 | unsigned long v_timeout; | |
110 | struct thread *t_timeout; | |
718e3744 | 111 | }; |
112 | ||
113 | /* Integrated configuration file. */ | |
e8f2984c | 114 | #define INTEGRATE_DEFAULT_CONFIG "Quagga.conf" |
718e3744 | 115 | |
116 | /* Small macro to determine newline is newline only or linefeed needed. */ | |
117 | #define VTY_NEWLINE ((vty->type == VTY_TERM) ? "\r\n" : "\n") | |
118 | ||
119 | /* Default time out value */ | |
120 | #define VTY_TIMEOUT_DEFAULT 600 | |
121 | ||
122 | /* Vty read buffer size. */ | |
123 | #define VTY_READ_BUFSIZ 512 | |
124 | ||
125 | /* Directory separator. */ | |
126 | #ifndef DIRECTORY_SEP | |
127 | #define DIRECTORY_SEP '/' | |
128 | #endif /* DIRECTORY_SEP */ | |
129 | ||
130 | #ifndef IS_DIRECTORY_SEP | |
131 | #define IS_DIRECTORY_SEP(c) ((c) == DIRECTORY_SEP) | |
132 | #endif | |
133 | ||
134 | /* GCC have printf type attribute check. */ | |
135 | #ifdef __GNUC__ | |
136 | #define PRINTF_ATTRIBUTE(a,b) __attribute__ ((__format__ (__printf__, a, b))) | |
137 | #else | |
138 | #define PRINTF_ATTRIBUTE(a,b) | |
139 | #endif /* __GNUC__ */ | |
140 | ||
42d49865 | 141 | /* Utility macros to convert VTY argument to unsigned long or integer. */ |
142 | #define VTY_GET_LONG(NAME,V,STR) \ | |
143 | { \ | |
144 | char *endptr = NULL; \ | |
145 | (V) = strtoul ((STR), &endptr, 10); \ | |
146 | if (*endptr != '\0' || (V) == ULONG_MAX) \ | |
147 | { \ | |
718e3744 | 148 | vty_out (vty, "%% Invalid %s value%s", NAME, VTY_NEWLINE); \ |
42d49865 | 149 | return CMD_WARNING; \ |
150 | } \ | |
718e3744 | 151 | } |
152 | ||
42d49865 | 153 | #define VTY_GET_INTEGER_RANGE(NAME,V,STR,MIN,MAX) \ |
154 | { \ | |
155 | unsigned long tmpl; \ | |
156 | VTY_GET_LONG(NAME, tmpl, STR) \ | |
157 | if ( tmpl < (MIN) || tmpl > (MAX)) \ | |
158 | { \ | |
718e3744 | 159 | vty_out (vty, "%% Invalid %s value%s", NAME, VTY_NEWLINE); \ |
42d49865 | 160 | return CMD_WARNING; \ |
161 | } \ | |
162 | (V) = tmpl; \ | |
718e3744 | 163 | } |
164 | ||
42d49865 | 165 | #define VTY_GET_INTEGER(NAME,V,STR) \ |
166 | VTY_GET_INTEGER_RANGE(NAME,V,STR,0U,UINT32_MAX) | |
167 | ||
718e3744 | 168 | /* Exported variables */ |
169 | extern char integrate_default[]; | |
170 | ||
171 | /* Prototypes. */ | |
b21b19c5 | 172 | void vty_init (struct thread_master *); |
718e3744 | 173 | void vty_init_vtysh (void); |
174 | void vty_reset (void); | |
175 | void vty_finish (void); | |
176 | struct vty *vty_new (void); | |
177 | int vty_out (struct vty *, const char *, ...) PRINTF_ATTRIBUTE(2, 3); | |
320ec10a | 178 | void vty_read_config (char *, char *); |
718e3744 | 179 | void vty_time_print (struct vty *, int); |
6ad96ea1 | 180 | void vty_serv_sock (const char *, unsigned short, const char *); |
718e3744 | 181 | void vty_close (struct vty *); |
182 | char *vty_get_cwd (void); | |
183 | void vty_log (const char *, const char *, va_list); | |
184 | int vty_config_lock (struct vty *); | |
185 | int vty_config_unlock (struct vty *); | |
186 | int vty_shell (struct vty *); | |
187 | int vty_shell_serv (struct vty *); | |
188 | void vty_hello (struct vty *); | |
189 | ||
190 | #endif /* _ZEBRA_VTY_H */ |