Loading...
Searching...
No Matches
vty.h
Go to the documentation of this file.
#pragma once
#include <stdio.h>
#include <stdarg.h>
#include <stdbool.h>
#include <time.h>
#include <osmocom/core/linuxlist.h>
#include <osmocom/core/defs.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
/* Number of application / library specific VTY attributes */
#define VTY_CMD_USR_ATTR_NUM 32
/* Flag characters reserved for global VTY attributes */
#define VTY_CMD_ATTR_FLAGS_RESERVED \
{ '.', '!', '@', '^' }
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;
struct llist_head parent_nodes;
char *indent;
bool expert_mode;
};
/* 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)
OSMO_DEPRECATED("Implicit parent node tracking has replaced the use of this callback. This callback is"
" no longer called, ever, and can be left NULL.");
int (*config_is_consistent)(struct vty *vty);
const char * usr_attr_desc[VTY_CMD_USR_ATTR_NUM];
char usr_attr_letters[VTY_CMD_USR_ATTR_NUM];
};
/* Prototypes. */
void vty_init(struct vty_app_info *app_info);
int vty_read_config_file(const char *file_name, void *priv);
int vty_read_config_filep(FILE *confp, 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);
bool vty_is_active(struct vty *vty);
int vty_out (struct vty *, const char *, ...) VTY_PRINTF_ATTRIBUTE(2, 3);
int vty_out_va(struct vty *vty, const char *format, va_list ap);
int vty_out_newline(struct vty *);
int vty_out_uptime(struct vty *vty, const struct timespec *starttime);
int vty_read(struct vty *vty);
//void vty_time_print (struct vty *, int);
void vty_close (struct vty *);
void vty_flush(struct vty *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);
/* Return IP address passed to the 'line vty'/'bind' command, or "127.0.0.1" */
const char *vty_get_bind_addr(void);
int vty_get_bind_port(int default_port);
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;
};
defs.h
node
struct cmd_node * node
Definition command.c:3584
starttime
static struct timespec starttime
Definition command.c:76
OSMO_DEPRECATED
#define OSMO_DEPRECATED(text)
vty_go_parent
int vty_go_parent(struct vty *vty)
Definition command.c:2489
vty_config_lock
int vty_config_lock(struct vty *)
Lock the configuration to a given VTY.
Definition vty.c:384
vty_type
vty_type
Definition vty.h:52
vty_new
struct vty * vty_new(void)
Allocate a new vty interface structure.
Definition vty.c:121
vty_reset
void vty_reset(void)
Reset all VTY status.
Definition vty.c:1789
VTY_MAXHIST
#define VTY_MAXHIST
Definition vty.h:30
vty_shell_serv
int vty_shell_serv(struct vty *)
Definition vty.c:1834
VTY_NEWLINE
#define VTY_NEWLINE
Definition vty.h:161
VTY_CMD_USR_ATTR_NUM
#define VTY_CMD_USR_ATTR_NUM
Definition vty.h:33
vty_read_config_filep
int vty_read_config_filep(FILE *confp, void *priv)
Read up VTY configuration from a file stream.
Definition vty.c:1519
VTY_PRINTF_ATTRIBUTE
#define VTY_PRINTF_ATTRIBUTE(a, b)
Definition vty.h:19
vty_out_uptime
int vty_out_uptime(struct vty *vty, const struct timespec *starttime)
calculates the time difference of a give timespec to the current time and prints in a human readable ...
Definition vty.c:350
cfg_description_cmd
struct cmd_element cfg_description_cmd
vty_init_vtysh
void vty_init_vtysh(void)
Definition vty.c:1839
vty_read
int vty_read(struct vty *vty)
Read data via vty socket.
Definition vty.c:1323
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:1916
vty_log
void vty_log(const char *level, const char *proto, const char *fmt, va_list)
vty_current_node
int vty_current_node(struct vty *vty)
return the current node of a given VTY
Definition vty.c:373
vty_shell
int vty_shell(struct vty *)
Return if this VTY is a shell or not.
Definition vty.c:266
vty_get_cwd
char * vty_get_cwd(void)
Definition vty.c:1829
vty_newline
static const char * vty_newline(struct vty *vty)
Definition vty.h:163
vty_is_active
bool vty_is_active(struct vty *vty)
Definition telnet_interface.c:219
vty_close
void vty_close(struct vty *)
Close a given vty interface.
Definition vty.c:223
vty_hello
void vty_hello(struct vty *)
Definition vty.c:407
vty_get_bind_port
int vty_get_bind_port(int default_port)
Returns configured port passed to the 'line vty'/'bind' command or default_port.
Definition vty.c:1689
vty_flush
void vty_flush(struct vty *vty)
Definition vty.c:216
vty_get_bind_addr
const char * vty_get_bind_addr(void)
Definition vty.c:1682
vty_config_unlock
int vty_config_unlock(struct vty *)
Unlock the configuration from a given VTY.
Definition vty.c:397
vty_out_newline
int vty_out_newline(struct vty *)
print a newline on the given VTY
Definition vty.c:340
vty_create
struct vty * vty_create(int vty_sock, void *priv)
Create new vty structure.
Definition vty.c:1563
cfg_no_description_cmd
struct cmd_element cfg_no_description_cmd
vty_out_va
int int vty_out_va(struct vty *vty, const char *format, va_list ap)
Definition vty.c:271
vty_current_index
void * vty_current_index(struct vty *)
return the current index of a given VTY
Definition vty.c:367
vty_out
int vty_out(struct vty *, const char *,...) VTY_PRINTF_ATTRIBUTE(2
vty_init
void vty_init(struct vty_app_info *app_info)
Initialize VTY layer.
Definition vty.c:1848
signal_vty
signal_vty
signal handling
Definition vty.h:239
tall_vty_ctx
void * tall_vty_ctx
Definition vty.c:113
VTY_FILE
@ VTY_FILE
Definition vty.h:54
VTY_SHELL
@ VTY_SHELL
Definition vty.h:55
VTY_SHELL_SERV
@ VTY_SHELL_SERV
Definition vty.h:56
VTY_TERM
@ VTY_TERM
Definition vty.h:53
VTY_WRITE
@ VTY_WRITE
Definition vty.h:42
VTY_SERV
@ VTY_SERV
Definition vty.h:40
VTY_READ
@ VTY_READ
Definition vty.h:41
VTY_CLOSED
@ VTY_CLOSED
Definition vty.h:43
VTY_TIMEOUT_RESET
@ VTY_TIMEOUT_RESET
Definition vty.h:44
S_VTY_EVENT
@ S_VTY_EVENT
Definition vty.h:240
linuxlist.h
buffer
Definition buffer.c:39
cmd_element
Structure of a command element.
Definition command.h:175
llist_head
vty_app_info
Information an application registers with the VTY.
Definition vty.h:169
vty_app_info::config_is_consistent
int(* config_is_consistent)(struct vty *vty)
Check if the config is consistent before write.
Definition vty.h:190
vty_app_info::version
const char * version
version string of the application
Definition vty.h:173
vty_app_info::name
const char * name
name of the application
Definition vty.h:171
vty_app_info::usr_attr_letters
char usr_attr_letters[VTY_CMD_USR_ATTR_NUM]
Flag letters of the application specific VTY attributes (optional).
Definition vty.h:194
vty_app_info::copyright
const char * copyright
copyright string of the application
Definition vty.h:175
vty_app_info::usr_attr_desc
const char * usr_attr_desc[VTY_CMD_USR_ATTR_NUM]
Description of the application specific VTY attributes (optional).
Definition vty.h:192
vty_app_info::go_parent_cb
int(* go_parent_cb)(struct vty *vty)
Call-back for taking actions upon exiting a node.
Definition vty.h:183
vty_app_info::tall_ctx
void * tall_ctx
talloc context
Definition vty.h:177
vty_app_info::is_config_node
int(* is_config_node)(struct vty *vty, int node) OSMO_DEPRECATED("Implicit parent node tracking has replaced the use of this callback. This callback is" " no longer called
OBSOLETED: Implicit parent node tracking has replaced the use of this callback.
Definition vty.h:186
vty_signal_data
Definition vty.h:243
vty_signal_data::event
enum event event
Definition vty.h:244
vty_signal_data::vty
struct vty * vty
Definition vty.h:246
vty_signal_data::sock
int sock
Definition vty.h:245
vty
Internal representation of a single VTY.
Definition vty.h:60
vty::obuf
struct buffer * obuf
Output buffer.
Definition vty.h:80
vty::fail
int fail
Failure count.
Definition vty.h:77
vty::config
int config
In configure mode.
Definition vty.h:147
vty::priv
void * priv
private data, specified by creator
Definition vty.h:65
vty::length
int length
Command length.
Definition vty.h:89
vty::index_sub
void * index_sub
For multiple level index treatment such as key chain and key.
Definition vty.h:108
vty::status
enum vty::@2 status
Current vty status.
vty::hist
char * hist[VTY_MAXHIST]
Histry of command.
Definition vty.h:95
vty::width
int width
Window width.
Definition vty.h:137
vty::escape
unsigned char escape
For escape character.
Definition vty.h:111
vty::parent_nodes
struct llist_head parent_nodes
List of parent nodes, last item is the outermost parent.
Definition vty.h:150
vty::indent
char * indent
When reading from a config file, these are the indenting characters expected for children of the curr...
Definition vty.h:154
vty::hp
int hp
History lookup current point.
Definition vty.h:98
vty::file
FILE * file
underlying file (if any)
Definition vty.h:62
vty::iac
unsigned char iac
IAC handling.
Definition vty.h:121
vty::height
int height
Widnow height.
Definition vty.h:139
vty::sb_len
size_t sb_len
How many subnegotiation characters have we received?
Definition vty.h:134
vty::index
void * index
For current referencing point of interface, route-map, access-list etc...
Definition vty.h:105
vty::sb_buf
unsigned char sb_buf[TELNET_NAWS_SB_LEN]
sub-negotiation buffer
Definition vty.h:130
vty::node
int node
Node status of this vty.
Definition vty.h:74
vty::buf
char * buf
Command input buffer.
Definition vty.h:83
vty::expert_mode
bool expert_mode
Whether the expert mode is enabled.
Definition vty.h:157
vty::cp
int cp
Command cursor point.
Definition vty.h:86
vty::VTY_MORELINE
@ VTY_MORELINE
Definition vty.h:114
vty::VTY_NORMAL
@ VTY_NORMAL
Definition vty.h:114
vty::VTY_MORE
@ VTY_MORE
Definition vty.h:114
vty::VTY_CLOSE
@ VTY_CLOSE
Definition vty.h:114
vty::monitor
int monitor
Definition vty.h:144
vty::max
int max
Command max length.
Definition vty.h:92
vty::type
enum vty_type type
Is this vty connect to file or not.
Definition vty.h:71
vty::fd
int fd
File descripter of this vty.
Definition vty.h:68
vty::hindex
int hindex
History insert end point.
Definition vty.h:101
vty::lines
int lines
Configure lines.
Definition vty.h:142
vty::iac_sb_in_progress
unsigned char iac_sb_in_progress
IAC SB (option subnegotiation) handling.
Definition vty.h:124
TELNET_NAWS_SB_LEN
#define TELNET_NAWS_SB_LEN
Definition vty.h:128