blob: c5c8c3b0b0df1bf4c825c405c147a5f10655361e [file] [log] [blame]
paul718e3742002-12-13 20:15:29 +00001/* Virtual terminal [aka TeletYpe] interface routine
2 Copyright (C) 1997 Kunihiro Ishiguro
3
4This file is part of GNU Zebra.
5
6GNU Zebra is free software; you can redistribute it and/or modify it
7under the terms of the GNU General Public License as published by the
8Free Software Foundation; either version 2, or (at your option) any
9later version.
10
11GNU Zebra is distributed in the hope that it will be useful, but
12WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with GNU Zebra; see the file COPYING. If not, write to the Free
18Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
1902111-1307, USA. */
20
21#ifndef _ZEBRA_VTY_H
22#define _ZEBRA_VTY_H
23
paulb21b19c2003-06-15 01:28:29 +000024#include "thread.h"
25
paul718e3742002-12-13 20:15:29 +000026#define VTY_BUFSIZ 512
27#define VTY_MAXHIST 20
28
29/* VTY struct. */
30struct 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
44 /* Privilege level of this vty. */
45 int privilege;
46
47 /* Failure count */
48 int fail;
49
50 /* Output buffer. */
51 struct buffer *obuf;
52
53 /* Command input buffer */
54 char *buf;
55
56 /* Command cursor point */
57 int cp;
58
59 /* Command length */
60 int length;
61
62 /* Command max length. */
63 int max;
64
65 /* Histry of command */
66 char *hist[VTY_MAXHIST];
67
68 /* History lookup current point */
69 int hp;
70
71 /* History insert end point */
72 int hindex;
73
74 /* For current referencing point of interface, route-map,
75 access-list etc... */
76 void *index;
77
78 /* For multiple level index treatment such as key chain and key. */
79 void *index_sub;
80
81 /* For escape character. */
82 unsigned char escape;
83
84 /* Current vty status. */
85 enum {VTY_NORMAL, VTY_CLOSE, VTY_MORE, VTY_MORELINE,
86 VTY_START, VTY_CONTINUE} status;
87
88 /* IAC handling */
89 unsigned char iac;
90
91 /* IAC SB handling */
92 unsigned char iac_sb_in_progress;
93 struct buffer *sb_buffer;
94
95 /* Window width/height. */
96 int width;
97 int height;
98
99 int scroll_one;
100
101 /* Configure lines. */
102 int lines;
103
104 /* Current executing function pointer. */
105 int (*func) (struct vty *, void *arg);
106
107 /* Terminal monitor. */
108 int monitor;
109
110 /* In configure mode. */
111 int config;
112
113 /* Read and write thread. */
114 struct thread *t_read;
115 struct thread *t_write;
116
117 /* Timeout seconds and thread. */
118 unsigned long v_timeout;
119 struct thread *t_timeout;
120
121 /* Thread output function. */
122 struct thread *t_output;
123
124 /* Output data pointer. */
125 int (*output_func) (struct vty *, int);
126 void (*output_clean) (struct vty *);
127 void *output_rn;
128 unsigned long output_count;
129 int output_type;
130 void *output_arg;
131};
132
133/* Integrated configuration file. */
paule8f29842003-08-12 13:08:31 +0000134#define INTEGRATE_DEFAULT_CONFIG "Quagga.conf"
paul718e3742002-12-13 20:15:29 +0000135
136/* Small macro to determine newline is newline only or linefeed needed. */
137#define VTY_NEWLINE ((vty->type == VTY_TERM) ? "\r\n" : "\n")
138
139/* Default time out value */
140#define VTY_TIMEOUT_DEFAULT 600
141
142/* Vty read buffer size. */
143#define VTY_READ_BUFSIZ 512
144
145/* Directory separator. */
146#ifndef DIRECTORY_SEP
147#define DIRECTORY_SEP '/'
148#endif /* DIRECTORY_SEP */
149
150#ifndef IS_DIRECTORY_SEP
151#define IS_DIRECTORY_SEP(c) ((c) == DIRECTORY_SEP)
152#endif
153
154/* GCC have printf type attribute check. */
155#ifdef __GNUC__
156#define PRINTF_ATTRIBUTE(a,b) __attribute__ ((__format__ (__printf__, a, b)))
157#else
158#define PRINTF_ATTRIBUTE(a,b)
159#endif /* __GNUC__ */
160
paul42d49862004-10-13 05:22:18 +0000161/* Utility macros to convert VTY argument to unsigned long or integer. */
162#define VTY_GET_LONG(NAME,V,STR) \
163{ \
164 char *endptr = NULL; \
165 (V) = strtoul ((STR), &endptr, 10); \
166 if (*endptr != '\0' || (V) == ULONG_MAX) \
167 { \
paul718e3742002-12-13 20:15:29 +0000168 vty_out (vty, "%% Invalid %s value%s", NAME, VTY_NEWLINE); \
paul42d49862004-10-13 05:22:18 +0000169 return CMD_WARNING; \
170 } \
paul718e3742002-12-13 20:15:29 +0000171}
172
paul42d49862004-10-13 05:22:18 +0000173#define VTY_GET_INTEGER_RANGE(NAME,V,STR,MIN,MAX) \
174{ \
175 unsigned long tmpl; \
176 VTY_GET_LONG(NAME, tmpl, STR) \
177 if ( tmpl < (MIN) || tmpl > (MAX)) \
178 { \
paul718e3742002-12-13 20:15:29 +0000179 vty_out (vty, "%% Invalid %s value%s", NAME, VTY_NEWLINE); \
paul42d49862004-10-13 05:22:18 +0000180 return CMD_WARNING; \
181 } \
182 (V) = tmpl; \
paul718e3742002-12-13 20:15:29 +0000183}
184
paul42d49862004-10-13 05:22:18 +0000185#define VTY_GET_INTEGER(NAME,V,STR) \
186 VTY_GET_INTEGER_RANGE(NAME,V,STR,0U,UINT32_MAX)
187
paul718e3742002-12-13 20:15:29 +0000188/* Exported variables */
189extern char integrate_default[];
190
191/* Prototypes. */
paulb21b19c2003-06-15 01:28:29 +0000192void vty_init (struct thread_master *);
paul718e3742002-12-13 20:15:29 +0000193void vty_init_vtysh (void);
194void vty_reset (void);
195void vty_finish (void);
196struct vty *vty_new (void);
197int vty_out (struct vty *, const char *, ...) PRINTF_ATTRIBUTE(2, 3);
hasso320ec102004-06-20 19:54:37 +0000198void vty_read_config (char *, char *);
paul718e3742002-12-13 20:15:29 +0000199void vty_time_print (struct vty *, int);
hasso6ad96ea2004-10-07 19:33:46 +0000200void vty_serv_sock (const char *, unsigned short, const char *);
paul718e3742002-12-13 20:15:29 +0000201void vty_close (struct vty *);
202char *vty_get_cwd (void);
203void vty_log (const char *, const char *, va_list);
204int vty_config_lock (struct vty *);
205int vty_config_unlock (struct vty *);
206int vty_shell (struct vty *);
207int vty_shell_serv (struct vty *);
208void vty_hello (struct vty *);
209
210#endif /* _ZEBRA_VTY_H */