vty.h
Go to the documentation of this file.
#pragma once
#include <stdio.h>
#include <stdarg.h>
/* GCC have printf type attribute check. */
#ifdef __GNUC__
#define VTY_PRINTF_ATTRIBUTE(a,b) __attribute__ ((__format__ (__printf__, a, b)))
#else
#define VTY_PRINTF_ATTRIBUTE(a,b)
#endif /* __GNUC__ */
/* Does the I/O error indicate that the operation should be retried later? */
#define ERRNO_IO_RETRY(EN) \
(((EN) == EAGAIN) || ((EN) == EWOULDBLOCK) || ((EN) == EINTR))
/* Vty read buffer size. */
#define VTY_READ_BUFSIZ 512
#define VTY_BUFSIZ 512
#define VTY_MAXHIST 20
enum event {
VTY_SERV,
VTY_READ,
VTY_WRITE,
VTY_CLOSED,
VTY_TIMEOUT_RESET,
#ifdef VTYSH
VTYSH_SERV,
VTYSH_READ,
VTYSH_WRITE
#endif /* VTYSH */
};
enum vty_type {
VTY_TERM,
VTY_FILE,
VTY_SHELL,
VTY_SHELL_SERV
};
struct vty {
FILE *file;
void *priv;
int fd;
enum vty_type type;
int node;
int fail;
struct buffer *obuf;
char *buf;
int cp;
int length;
int max;
char *hist[VTY_MAXHIST];
int hp;
int hindex;
void *index;
void *index_sub;
unsigned char escape;
enum { VTY_NORMAL, VTY_CLOSE, VTY_MORE, VTY_MORELINE } status;
unsigned char iac;
unsigned char iac_sb_in_progress;
/* At the moment, we care only about the NAWS (window size) negotiation,
* and that requires just a 5-character buffer (RFC 1073):
* <NAWS char> <16-bit width> <16-bit height> */
#define TELNET_NAWS_SB_LEN 5
unsigned char sb_buf[TELNET_NAWS_SB_LEN];
size_t sb_len;
int width;
int height;
int lines;
int monitor;
int config;
};
/* Small macro to determine newline is newline only or linefeed needed. */
#define VTY_NEWLINE ((vty->type == VTY_TERM) ? "\r\n" : "\n")
static inline const char *vty_newline(struct vty *vty)
{
return VTY_NEWLINE;
}
struct vty_app_info {
const char *name;
const char *version;
const char *copyright;
void *tall_ctx;
int (*go_parent_cb)(struct vty *vty);
int (*is_config_node)(struct vty *vty, int node);
int (*config_is_consistent)(struct vty *vty);
};
/* Prototypes. */
void vty_init(struct vty_app_info *app_info);
int vty_read_config_file(const char *file_name, void *priv);
void vty_init_vtysh (void);
void vty_reset (void);
struct vty *vty_new (void);
struct vty *vty_create (int vty_sock, void *priv);
int vty_out (struct vty *, const char *, ...) VTY_PRINTF_ATTRIBUTE(2, 3);
int vty_out_newline(struct vty *);
int vty_read(struct vty *vty);
//void vty_time_print (struct vty *, int);
void vty_close (struct vty *);
char *vty_get_cwd (void);
void vty_log (const char *level, const char *proto, const char *fmt, va_list);
int vty_config_lock (struct vty *);
int vty_config_unlock (struct vty *);
int vty_shell (struct vty *);
int vty_shell_serv (struct vty *);
void vty_hello (struct vty *);
void *vty_current_index(struct vty *);
int vty_current_node(struct vty *vty);
int vty_go_parent(struct vty *vty);
extern void *tall_vty_ctx;
extern struct cmd_element cfg_description_cmd;
extern struct cmd_element cfg_no_description_cmd;
enum signal_vty {
S_VTY_EVENT,
};
struct vty_signal_data {
enum event event;
int sock;
struct vty *vty;
};
vty::length
int length
Command length.
Definition: vty.h:79
vty_app_info::tall_ctx
void * tall_ctx
talloc context
Definition: vty.h:157
vty_app_info::name
const char * name
name of the application
Definition: vty.h:151
vty::lines
int lines
Configure lines.
Definition: vty.h:132
vty::file
FILE * file
underlying file (if any)
Definition: vty.h:52
vty::sb_len
size_t sb_len
How many subnegotiation characters have we received?
Definition: vty.h:124
vty_read
int vty_read(struct vty *vty)
Read data via vty socket.
Definition: vty.c:1260
vty::sb_buf
unsigned char sb_buf[TELNET_NAWS_SB_LEN]
sub-negotiation buffer
Definition: vty.h:120
vty_config_unlock
int vty_config_unlock(struct vty *)
Unlock the configuration from a given VTY.
Definition: vty.c:330
vty_config_lock
int vty_config_lock(struct vty *)
Lock the configuration to a given VTY.
Definition: vty.c:317
vty::hindex
int hindex
History insert end point.
Definition: vty.h:91
vty
Definition: vty.h:50
vty_signal_data
Definition: vty.h:202
vty::height
int height
Widnow height.
Definition: vty.h:129
vty_close
void vty_close(struct vty *)
Close a given vty interface.
Definition: vty.c:184
vty::max
int max
Command max length.
Definition: vty.h:82
vty::width
int width
Window width.
Definition: vty.h:127
vty::type
enum vty_type type
Is this vty connect to file or not.
Definition: vty.h:61
vty_app_info::copyright
const char * copyright
copyright string of the application
Definition: vty.h:155
vty::hist
char * hist[VTY_MAXHIST]
Histry of command.
Definition: vty.h:85
vty::buf
char * buf
Command input buffer.
Definition: vty.h:73
vty::escape
unsigned char escape
For escape character.
Definition: vty.h:101
vty_out
int vty_out(struct vty *vty, const char *format,...)
VTY standard output function.
Definition: vty.c:235
vty::fail
int fail
Failure count.
Definition: vty.h:67
vty_current_index
void * vty_current_index(struct vty *)
return the current index of a given VTY
Definition: vty.c:300
vty::node
int node
Node status of this vty.
Definition: vty.h:64
vty::config
int config
In configure mode.
Definition: vty.h:137
vty_reset
void vty_reset(void)
Reset all VTY status.
Definition: vty.c:1669
vty_read_config_file
int vty_read_config_file(const char *file_name, void *priv)
Read the configuration file using the VTY code.
Definition: vty.c:1766
vty::iac
unsigned char iac
IAC handling.
Definition: vty.h:111
vty_app_info::version
const char * version
version string of the application
Definition: vty.h:153
vty::fd
int fd
File descripter of this vty.
Definition: vty.h:58
vty_current_node
int vty_current_node(struct vty *vty)
return the current node of a given VTY
Definition: vty.c:306
vty::priv
void * priv
private data, specified by creator
Definition: vty.h:55
vty::status
enum vty::@1 status
Current vty status.
vty::obuf
struct buffer * obuf
Output buffer.
Definition: vty.h:70
vty_shell
int vty_shell(struct vty *)
Return if this VTY is a shell or not.
Definition: vty.c:225
cmd_element
Structure of a command element.
Definition: command.h:126
vty_out_newline
int int vty_out_newline(struct vty *)
print a newline on the given VTY
Definition: vty.c:292
vty_init
void vty_init(struct vty_app_info *app_info)
Initialize VTY layer.
Definition: vty.c:1730
buffer
Definition: buffer.c:36
event
event
VTY events.
Definition: vty.h:29
vty::hp
int hp
History lookup current point.
Definition: vty.h:88
vty_create
struct vty * vty_create(int vty_sock, void *priv)
Create new vty structure.
Definition: vty.c:1481
vty::index_sub
void * index_sub
For multiple level index treatment such as key chain and key.
Definition: vty.h:98
vty::cp
int cp
Command cursor point.
Definition: vty.h:76
signal_vty
signal_vty
Definition: vty.h:198
vty::iac_sb_in_progress
unsigned char iac_sb_in_progress
IAC SB (option subnegotiation) handling.
Definition: vty.h:114
vty_new
struct vty * vty_new(void)
Allocate a new vty interface structure.
Definition: vty.c:91
vty_app_info
Definition: vty.h:149
vty::index
void * index
For current referencing point of interface, route-map, access-list etc...
Definition: vty.h:95