libosmovty  0.9.6.311-c977
Osmocom VTY library
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
vty.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <stdio.h>
4 #include <stdarg.h>
5 
10 /* GCC have printf type attribute check. */
11 #ifdef __GNUC__
12 #define VTY_PRINTF_ATTRIBUTE(a,b) __attribute__ ((__format__ (__printf__, a, b)))
13 #else
14 #define VTY_PRINTF_ATTRIBUTE(a,b)
15 #endif /* __GNUC__ */
16 
17 /* Does the I/O error indicate that the operation should be retried later? */
18 #define ERRNO_IO_RETRY(EN) \
19  (((EN) == EAGAIN) || ((EN) == EWOULDBLOCK) || ((EN) == EINTR))
20 
21 /* Vty read buffer size. */
22 #define VTY_READ_BUFSIZ 512
23 
24 #define VTY_BUFSIZ 512
25 #define VTY_MAXHIST 20
26 
28 enum event {
34 #ifdef VTYSH
35  VTYSH_SERV,
36  VTYSH_READ,
37  VTYSH_WRITE
38 #endif /* VTYSH */
39 };
40 
41 enum vty_type {
46 };
47 
49 struct vty {
51  FILE *file;
52 
54  void *priv;
55 
57  int fd;
58 
60  enum vty_type type;
61 
63  int node;
64 
66  int fail;
67 
69  struct buffer *obuf;
70 
72  char *buf;
73 
75  int cp;
76 
78  int length;
79 
81  int max;
82 
84  char *hist[VTY_MAXHIST];
85 
87  int hp;
88 
90  int hindex;
91 
94  void *index;
95 
97  void *index_sub;
98 
100  unsigned char escape;
101 
104 
110  unsigned char iac;
111 
113  unsigned char iac_sb_in_progress;
114  /* At the moment, we care only about the NAWS (window size) negotiation,
115  * and that requires just a 5-character buffer (RFC 1073):
116  * <NAWS char> <16-bit width> <16-bit height> */
117 #define TELNET_NAWS_SB_LEN 5
118 
119  unsigned char sb_buf[TELNET_NAWS_SB_LEN];
123  size_t sb_len;
124 
126  int width;
128  int height;
129 
131  int lines;
132 
133  int monitor;
134 
136  int config;
137 };
138 
139 /* Small macro to determine newline is newline only or linefeed needed. */
140 #define VTY_NEWLINE ((vty->type == VTY_TERM) ? "\r\n" : "\n")
141 
142 static inline const char *vty_newline(struct vty *vty)
143 {
144  return VTY_NEWLINE;
145 }
146 
148 struct vty_app_info {
150  const char *name;
152  const char *version;
154  const char *copyright;
156  void *tall_ctx;
158  int (*go_parent_cb)(struct vty *vty);
160  int (*is_config_node)(struct vty *vty, int node);
162  int (*config_is_consistent)(struct vty *vty);
163 };
164 
165 /* Prototypes. */
166 void vty_init(struct vty_app_info *app_info);
167 int vty_read_config_file(const char *file_name, void *priv);
168 void vty_init_vtysh (void);
169 void vty_reset (void);
170 struct vty *vty_new (void);
171 struct vty *vty_create (int vty_sock, void *priv);
172 int vty_out (struct vty *, const char *, ...) VTY_PRINTF_ATTRIBUTE(2, 3);
173 int vty_out_newline(struct vty *);
174 int vty_read(struct vty *vty);
175 //void vty_time_print (struct vty *, int);
176 void vty_close (struct vty *);
177 char *vty_get_cwd (void);
178 void vty_log (const char *level, const char *proto, const char *fmt, va_list);
179 int vty_config_lock (struct vty *);
180 int vty_config_unlock (struct vty *);
181 int vty_shell (struct vty *);
182 int vty_shell_serv (struct vty *);
183 void vty_hello (struct vty *);
184 void *vty_current_index(struct vty *);
185 int vty_current_node(struct vty *vty);
186 int vty_go_parent(struct vty *vty);
187 
188 /* Return IP address passed to the 'line vty'/'bind' command, or "127.0.0.1" */
189 const char *vty_get_bind_addr(void);
190 
191 extern void *tall_vty_ctx;
192 
193 extern struct cmd_element cfg_description_cmd;
194 extern struct cmd_element cfg_no_description_cmd;
195 
196 
202 };
203 
205  enum event event;
206  int sock;
207  struct vty *vty;
208 };
209 
void vty_init_vtysh(void)
Definition: vty.c:1755
Definition: vty.h:31
Definition: vty.h:103
int vty_shell_serv(struct vty *)
Definition: vty.c:1750
int length
Command length.
Definition: vty.h:78
enum event event
Definition: vty.h:205
Definition: vty.h:45
void * tall_ctx
talloc context
Definition: vty.h:156
struct cmd_element cfg_description_cmd
const char * name
name of the application
Definition: vty.h:150
int lines
Configure lines.
Definition: vty.h:131
FILE * file
underlying file (if any)
Definition: vty.h:51
size_t sb_len
How many subnegotiation characters have we received?
Definition: vty.h:123
int vty_read(struct vty *vty)
Read data via vty socket.
Definition: vty.c:1275
unsigned char sb_buf[TELNET_NAWS_SB_LEN]
sub-negotiation buffer
Definition: vty.h:119
int vty_config_unlock(struct vty *)
Unlock the configuration from a given VTY.
Definition: vty.c:345
int vty_config_lock(struct vty *)
Lock the configuration to a given VTY.
Definition: vty.c:332
int hindex
History insert end point.
Definition: vty.h:90
Internal representation of a single VTY.
Definition: vty.h:49
Definition: vty.h:204
int(* is_config_node)(struct vty *vty, int node)
call-back to determine if node is config node
Definition: vty.h:160
int height
Widnow height.
Definition: vty.h:128
void vty_log(const char *level, const char *proto, const char *fmt, va_list)
Definition: vty.h:201
void vty_close(struct vty *)
Close a given vty interface.
Definition: vty.c:199
int max
Command max length.
Definition: vty.h:81
int width
Window width.
Definition: vty.h:126
enum vty_type type
Is this vty connect to file or not.
Definition: vty.h:60
Definition: vty.h:30
int(* go_parent_cb)(struct vty *vty)
call-back for returning to parent n ode
Definition: vty.h:158
const char * copyright
copyright string of the application
Definition: vty.h:154
char * hist[VTY_MAXHIST]
Histry of command.
Definition: vty.h:84
char * buf
Command input buffer.
Definition: vty.h:72
int vty_out(struct vty *, const char *,...) VTY_PRINTF_ATTRIBUTE(2
unsigned char escape
For escape character.
Definition: vty.h:100
#define VTY_NEWLINE
Definition: vty.h:140
#define VTY_PRINTF_ATTRIBUTE(a, b)
Definition: vty.h:14
struct cmd_node * node
Definition: command.c:2644
Definition: vty.h:44
int sock
Definition: vty.h:206
int fail
Failure count.
Definition: vty.h:66
void * vty_current_index(struct vty *)
return the current index of a given VTY
Definition: vty.c:315
Definition: vty.h:103
int node
Node status of this vty.
Definition: vty.h:63
int config
In configure mode.
Definition: vty.h:136
void vty_reset(void)
Reset all VTY status.
Definition: vty.c:1705
int vty_read_config_file(const char *file_name, void *priv)
Read the configuration file using the VTY code.
Definition: vty.c:1803
unsigned char iac
IAC handling.
Definition: vty.h:110
const char * version
version string of the application
Definition: vty.h:152
int fd
File descripter of this vty.
Definition: vty.h:57
static const char * vty_newline(struct vty *vty)
Definition: vty.h:142
void * tall_vty_ctx
Definition: vty.c:98
int vty_current_node(struct vty *vty)
return the current node of a given VTY
Definition: vty.c:321
void * priv
private data, specified by creator
Definition: vty.h:54
enum vty::@1 status
Current vty status.
struct cmd_element cfg_no_description_cmd
struct buffer * obuf
Output buffer.
Definition: vty.h:69
int(* config_is_consistent)(struct vty *vty)
Check if the config is consistent before write.
Definition: vty.h:162
int vty_shell(struct vty *)
Return if this VTY is a shell or not.
Definition: vty.c:240
Structure of a command element.
Definition: command.h:134
int int vty_out_newline(struct vty *)
print a newline on the given VTY
Definition: vty.c:307
void vty_init(struct vty_app_info *app_info)
Initialize VTY layer.
Definition: vty.c:1766
Definition: vty.h:33
Definition: vty.h:103
#define TELNET_NAWS_SB_LEN
Definition: vty.h:117
Definition: buffer.c:37
struct vty * vty
Definition: vty.h:207
Definition: vty.h:103
Definition: vty.h:42
Definition: vty.h:43
int hp
History lookup current point.
Definition: vty.h:87
int monitor
Definition: vty.h:133
struct vty * vty_create(int vty_sock, void *priv)
Create new vty structure.
Definition: vty.c:1496
char * vty_get_cwd(void)
Definition: vty.c:1745
void * index_sub
For multiple level index treatment such as key chain and key.
Definition: vty.h:97
int cp
Command cursor point.
Definition: vty.h:75
void vty_hello(struct vty *)
Definition: vty.c:355
signal_vty
signal handling
Definition: vty.h:200
Definition: vty.h:29
unsigned char iac_sb_in_progress
IAC SB (option subnegotiation) handling.
Definition: vty.h:113
struct vty * vty_new(void)
Allocate a new vty interface structure.
Definition: vty.c:106
Information an application registers with the VTY.
Definition: vty.h:148
vty_type
Definition: vty.h:41
#define VTY_MAXHIST
Definition: vty.h:25
Definition: vty.h:32
int vty_go_parent(struct vty *vty)
Definition: command.c:1965
const char * vty_get_bind_addr(void)
Definition: vty.c:1613
void * index
For current referencing point of interface, route-map, access-list etc...
Definition: vty.h:94