]>
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 along
17 * with this program; see the file COPYING; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26 #include "sockunion.h"
29 #define VTY_BUFSIZ 4096
30 #define VTY_MAXHIST 20
35 /* File descripter of this vty. */
38 /* output FD, to support stdin/stdout combination */
41 /* Is this vty connect to file or not */
42 enum {VTY_TERM
, VTY_FILE
, VTY_SHELL
, VTY_SHELL_SERV
} type
;
44 /* Node status of this vty */
53 /* Command input buffer */
56 /* Command input error buffer */
59 /* Command cursor point */
65 /* Command max length. */
68 /* Histry of command */
69 char *hist
[VTY_MAXHIST
];
71 /* History lookup current point */
74 /* History insert end point */
77 /* qobj object ID (replacement for "index") */
80 /* qobj second-level object ID (replacement for "index_sub") */
81 uint64_t qobj_index_sub
;
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 static inline void vty_push_context(struct vty
*vty
,
131 int node
, uint64_t id
)
134 vty
->qobj_index
= id
;
137 /* note: VTY_PUSH_CONTEXT(..., NULL) doesn't work, since it will try to
138 * dereference "NULL->qobj_node.nid" */
139 #define VTY_PUSH_CONTEXT(nodeval, ptr) \
140 vty_push_context(vty, nodeval, QOBJ_ID_0SAFE(ptr))
141 #define VTY_PUSH_CONTEXT_NULL(nodeval) \
142 vty_push_context(vty, nodeval, 0ULL)
143 #define VTY_PUSH_CONTEXT_SUB(nodeval, ptr) do { \
144 vty->node = nodeval; \
145 /* qobj_index stays untouched */ \
146 vty->qobj_index_sub = QOBJ_ID_0SAFE(ptr); \
149 /* can return NULL if context is invalid! */
150 #define VTY_GET_CONTEXT(structname) \
151 QOBJ_GET_TYPESAFE(vty->qobj_index, structname)
152 #define VTY_GET_CONTEXT_SUB(structname) \
153 QOBJ_GET_TYPESAFE(vty->qobj_index_sub, structname)
155 /* will return if ptr is NULL. */
156 #define VTY_CHECK_CONTEXT(ptr) \
158 vty_out (vty, "Current configuration object was deleted " \
159 "by another process.%s", VTYNL); \
160 return CMD_WARNING; \
163 /* struct structname *ptr = <context>; ptr will never be NULL. */
164 #define VTY_DECLVAR_CONTEXT(structname, ptr) \
165 struct structname *ptr = VTY_GET_CONTEXT(structname); \
166 VTY_CHECK_CONTEXT(ptr);
167 #define VTY_DECLVAR_CONTEXT_SUB(structname, ptr) \
168 struct structname *ptr = VTY_GET_CONTEXT_SUB(structname); \
169 VTY_CHECK_CONTEXT(ptr);
179 /* Integrated configuration file. */
180 #define INTEGRATE_DEFAULT_CONFIG "frr.conf"
182 /* Small macro to determine newline is newline only or linefeed needed. */
183 #define VTYNL ((vty->type == VTY_TERM) ? "\r\n" : "\n")
185 /* for compatibility */
186 #define VTY_NEWLINE VTYNL
187 #define VTY_GET_INTEGER(desc,v,str) {(v)=strtoul ((str), NULL, 10);}
188 #define VTY_GET_INTEGER_RANGE(desc,v,str,min,max) {(v)=strtoul ((str), NULL, 10);}
190 /* Default time out value */
191 #define VTY_TIMEOUT_DEFAULT 600
193 /* Vty read buffer size. */
194 #define VTY_READ_BUFSIZ 512
196 /* Directory separator. */
197 #ifndef DIRECTORY_SEP
198 #define DIRECTORY_SEP '/'
199 #endif /* DIRECTORY_SEP */
201 #ifndef IS_DIRECTORY_SEP
202 #define IS_DIRECTORY_SEP(c) ((c) == DIRECTORY_SEP)
205 /* Exported variables */
206 extern char integrate_default
[];
209 extern void vty_init (struct thread_master
*);
210 extern void vty_init_vtysh (void);
211 extern void vty_terminate (void);
212 extern void vty_reset (void);
213 extern struct vty
*vty_new (void);
214 extern struct vty
*vty_stdio (void (*atclose
)(void));
215 extern int vty_out (struct vty
*, const char *, ...) PRINTF_ATTRIBUTE(2, 3);
216 extern int vty_outln (struct vty
*, const char *, ...) PRINTF_ATTRIBUTE(2, 3);
217 extern void vty_read_config (const char *, char *);
218 extern void vty_time_print (struct vty
*, int);
219 extern void vty_serv_sock (const char *, unsigned short, const char *);
220 extern void vty_close (struct vty
*);
221 extern char *vty_get_cwd (void);
222 extern void vty_log (const char *level
, const char *proto
,
223 const char *fmt
, struct timestamp_control
*, va_list);
224 extern int vty_config_lock (struct vty
*);
225 extern int vty_config_unlock (struct vty
*);
226 extern void vty_config_lockless (void);
227 extern int vty_shell (struct vty
*);
228 extern int vty_shell_serv (struct vty
*);
229 extern void vty_hello (struct vty
*);
231 /* Send a fixed-size message to all vty terminal monitors; this should be
232 an async-signal-safe function. */
233 extern void vty_log_fixed (char *buf
, size_t len
);
235 #endif /* _ZEBRA_VTY_H */