libosmovty 1.9.0.196-9975
Osmocom VTY library
vty.c File Reference
#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include <ctype.h>
#include <termios.h>
#include <sys/utsname.h>
#include <sys/param.h>
#include <arpa/telnet.h>
#include <osmocom/vty/vty.h>
#include <osmocom/vty/command.h>
#include <osmocom/vty/buffer.h>
#include <osmocom/core/talloc.h>
#include <osmocom/core/timer.h>
#include <osmocom/core/utils.h>

Macros

#define MAXPATHLEN   4096
 
#define SYSCONFDIR   "/usr/local/etc"
 
#define VTY_BIND_ADDR_DEFAULT   "127.0.0.1"
 
#define CONTROL(X)   ((X) - '@')
 
#define VTY_NORMAL   0
 
#define VTY_PRE_ESCAPE   1
 
#define VTY_ESCAPE   2
 

Functions

void vty_event (enum event event, int sock, struct vty *vty)
 callback from core VTY code about VTY related events More...
 
static void vty_clear_buf (struct vty *vty)
 
struct vtyvty_new (void)
 Allocate a new vty interface structure. More...
 
static void vty_auth (struct vty *vty)
 
void vty_flush (struct vty *vty)
 
void vty_close (struct vty *vty)
 Close a given vty interface. More...
 
int vty_shell (struct vty *vty)
 Return if this VTY is a shell or not. More...
 
int vty_out_va (struct vty *vty, const char *format, va_list ap)
 
int vty_out (struct vty *vty, const char *format,...)
 VTY standard output function. More...
 
int vty_out_newline (struct vty *vty)
 print a newline on the given VTY More...
 
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 format (days, hours, minutes, seconds). More...
 
void * vty_current_index (struct vty *vty)
 return the current index of a given VTY More...
 
int vty_current_node (struct vty *vty)
 return the current node of a given VTY More...
 
int vty_config_lock (struct vty *vty)
 Lock the configuration to a given VTY. More...
 
int vty_config_unlock (struct vty *vty)
 Unlock the configuration from a given VTY. More...
 
void vty_hello (struct vty *vty)
 
static void vty_prompt (struct vty *vty)
 
static int vty_command (struct vty *vty)
 
static void vty_write (struct vty *vty, const char *buf, size_t nbytes)
 
static void vty_ensure (struct vty *vty, int length)
 
static void vty_self_insert (struct vty *vty, char c)
 
static void vty_self_insert_overwrite (struct vty *vty, char c)
 
static void vty_insert_word_overwrite (struct vty *vty, char *str)
 
static void vty_forward_char (struct vty *vty)
 
static void vty_backward_char (struct vty *vty)
 
static void vty_beginning_of_line (struct vty *vty)
 
static void vty_end_of_line (struct vty *vty)
 
static void vty_hist_add (struct vty *vty)
 
static int vty_telnet_option (struct vty *vty, unsigned char *buf, int nbytes)
 
static int vty_execute (struct vty *vty)
 
static void vty_will_echo (struct vty *vty)
 
static void vty_will_suppress_go_ahead (struct vty *vty)
 
static void vty_dont_linemode (struct vty *vty)
 
static void vty_do_window_size (struct vty *vty)
 
static void vty_kill_line_from_beginning (struct vty *)
 
static void vty_redraw_line (struct vty *)
 
static void vty_history_print (struct vty *vty)
 
static void vty_next_line (struct vty *vty)
 
static void vty_previous_line (struct vty *vty)
 
static void vty_forward_word (struct vty *vty)
 
static void vty_backward_pure_word (struct vty *vty)
 
static void vty_backward_word (struct vty *vty)
 
static void vty_down_level (struct vty *vty)
 
static void vty_clear_screen (struct vty *vty)
 
static void vty_end_config (struct vty *vty)
 
static void vty_delete_char (struct vty *vty)
 
static void vty_delete_backward_char (struct vty *vty)
 
static void vty_kill_line (struct vty *vty)
 
static void vty_forward_kill_word (struct vty *vty)
 
static void vty_backward_kill_word (struct vty *vty)
 
static void vty_transpose_chars (struct vty *vty)
 
static void vty_complete_command (struct vty *vty)
 
static void vty_describe_fold (struct vty *vty, int cmd_width, unsigned int desc_width, struct desc *desc)
 
static void vty_describe_command (struct vty *vty)
 
static void vty_stop_input (struct vty *vty)
 
static void vty_escape_map (unsigned char c, struct vty *vty)
 
static void vty_buffer_reset (struct vty *vty)
 
int vty_read (struct vty *vty)
 Read data via vty socket. More...
 
int vty_read_config_filep (FILE *confp, void *priv)
 Read up VTY configuration from a file stream. More...
 
struct vtyvty_create (int vty_sock, void *priv)
 Create new vty structure. More...
 
 DEFUN (config_who, config_who_cmd, "who", "Display who is on vty\n")
 
 DEFUN (line_vty, line_vty_cmd, "line vty", "Configure a terminal line\n" "Virtual terminal\n")
 
 DEFUN (vty_login, vty_login_cmd, "login", "Enable password checking\n")
 
 DEFUN (no_vty_login, no_vty_login_cmd, "no login", NO_STR "Enable password checking\n")
 
 DEFUN (vty_bind, vty_bind_cmd, "bind A.B.C.D [<0-65535>]", "Accept VTY telnet connections on local interface\n" "Local interface IP address (default: " VTY_BIND_ADDR_DEFAULT ")\n" "Local TCP port number\n")
 
const char * vty_get_bind_addr (void)
 
int vty_get_bind_port (int default_port)
 Returns configured port passed to the 'line vty'/'bind' command or default_port. More...
 
 DEFUN (service_advanced_vty, service_advanced_vty_cmd, "service advanced-vty", "Set up miscellaneous service\n" "Enable advanced mode vty interface\n")
 
 DEFUN (no_service_advanced_vty, no_service_advanced_vty_cmd, "no service advanced-vty", NO_STR "Set up miscellaneous service\n" "Enable advanced mode vty interface\n")
 
 DEFUN (terminal_monitor, terminal_monitor_cmd, "terminal monitor", "Set terminal line parameters\n" "Copy debug output to the current terminal line\n")
 
 DEFUN (terminal_no_monitor, terminal_no_monitor_cmd, "terminal no monitor", "Set terminal line parameters\n" NO_STR "Copy debug output to the current terminal line\n")
 
 DEFUN (show_history, show_history_cmd, "show history", SHOW_STR "Display the session command history\n")
 
static int vty_config_write (struct vty *vty)
 
void vty_reset (void)
 Reset all VTY status. More...
 
static void vty_save_cwd (void)
 
char * vty_get_cwd (void)
 
int vty_shell_serv (struct vty *vty)
 
void vty_init_vtysh (void)
 
void vty_init (struct vty_app_info *app_info)
 Initialize VTY layer. More...
 
int vty_read_config_file (const char *file_name, void *priv)
 Read the configuration file using the VTY code. More...
 

Variables

struct host host
 
static vector vtyvec
 
vector Vvty_serv_thread
 
char * vty_cwd = NULL
 
static const char * vty_bind_addr = NULL
 
static int vty_bind_port = -1
 
static int vty_config
 
static int password_check
 
void * tall_vty_ctx
 
static const char telnet_backward_char = 0x08
 
static const char telnet_space_char = ' '
 
static const char telnet_escape_char = 0x1B
 
struct cmd_node vty_node
 

Macro Definition Documentation

◆ CONTROL

#define CONTROL (   X)    ((X) - '@')

◆ MAXPATHLEN

#define MAXPATHLEN   4096

◆ SYSCONFDIR

#define SYSCONFDIR   "/usr/local/etc"

◆ VTY_BIND_ADDR_DEFAULT

#define VTY_BIND_ADDR_DEFAULT   "127.0.0.1"

◆ VTY_ESCAPE

#define VTY_ESCAPE   2

◆ VTY_NORMAL

#define VTY_NORMAL   0

◆ VTY_PRE_ESCAPE

#define VTY_PRE_ESCAPE   1

Function Documentation

◆ DEFUN() [1/10]

DEFUN ( config_who  ,
config_who_cmd  ,
"who"  ,
"Display who is on vty\n  
)

◆ DEFUN() [2/10]

DEFUN ( line_vty  ,
line_vty_cmd  ,
"line vty ,
"Configure a terminal line\n" "Virtual terminal\n  
)

References CMD_SUCCESS, vty::node, and VTY_NODE.

◆ DEFUN() [3/10]

DEFUN ( no_service_advanced_vty  ,
no_service_advanced_vty_cmd  ,
"no service advanced-vty ,
NO_STR "Set up miscellaneous service\n" "Enable advanced mode vty interface\n  
)

References host::advanced, and CMD_SUCCESS.

◆ DEFUN() [4/10]

DEFUN ( no_vty_login  ,
no_vty_login_cmd  ,
"no login"  ,
NO_STR "Enable password checking\n  
)

References CMD_SUCCESS, and password_check.

◆ DEFUN() [5/10]

DEFUN ( service_advanced_vty  ,
service_advanced_vty_cmd  ,
"service advanced-vty ,
"Set up miscellaneous service\n" "Enable advanced mode vty interface\n  
)

References host::advanced, and CMD_SUCCESS.

◆ DEFUN() [6/10]

DEFUN ( show_history  ,
show_history_cmd  ,
"show history"  ,
SHOW_STR "Display the session command history\n  
)

◆ DEFUN() [7/10]

DEFUN ( terminal_monitor  ,
terminal_monitor_cmd  ,
"terminal monitor"  ,
"Set terminal line parameters\n" "Copy debug output to the current terminal line\n  
)

References CMD_SUCCESS, and vty::monitor.

◆ DEFUN() [8/10]

DEFUN ( terminal_no_monitor  ,
terminal_no_monitor_cmd  ,
"terminal no monitor"  ,
"Set terminal line parameters\n" NO_STR "Copy debug output to the current terminal line\n  
)

References CMD_SUCCESS, and vty::monitor.

◆ DEFUN() [9/10]

DEFUN ( vty_bind  ,
vty_bind_cmd  ,
"bind A.B.C.D "  [< 0-65535 >],
"Accept VTY telnet connections on local interface\n" "Local interface IP address (default: " VTY_BIND_ADDR_DEFAULT ")\n" "Local TCP port number\n  
)

◆ DEFUN() [10/10]

DEFUN ( vty_login  ,
vty_login_cmd  ,
"login"  ,
"Enable password checking\n  
)

References CMD_SUCCESS, and password_check.

◆ vty_auth()

◆ vty_backward_char()

◆ vty_backward_kill_word()

static void vty_backward_kill_word ( struct vty vty)
static

References vty::buf, vty::cp, and vty_delete_backward_char().

Referenced by vty_read().

◆ vty_backward_pure_word()

static void vty_backward_pure_word ( struct vty vty)
static

References vty::buf, vty::cp, and vty_backward_char().

Referenced by vty_complete_command().

◆ vty_backward_word()

static void vty_backward_word ( struct vty vty)
static

References vty::buf, vty::cp, and vty_backward_char().

Referenced by vty_read().

◆ vty_beginning_of_line()

static void vty_beginning_of_line ( struct vty vty)
static

◆ vty_buffer_reset()

static void vty_buffer_reset ( struct vty vty)
static

◆ vty_clear_buf()

static void vty_clear_buf ( struct vty vty)
static

References vty::buf, and vty::max.

Referenced by vty_create(), vty_execute(), and vty_stop_input().

◆ vty_clear_screen()

static void vty_clear_screen ( struct vty vty)
static

◆ vty_command()

◆ vty_complete_command()

◆ vty_config_write()

static int vty_config_write ( struct vty vty)
static

◆ vty_delete_backward_char()

static void vty_delete_backward_char ( struct vty vty)
static

◆ vty_delete_char()

◆ vty_describe_command()

◆ vty_describe_fold()

static void vty_describe_fold ( struct vty vty,
int  cmd_width,
unsigned int  desc_width,
struct desc desc 
)
static

References desc::cmd, desc::str, VTY_NEWLINE, and vty_out().

Referenced by vty_describe_command().

◆ vty_do_window_size()

static void vty_do_window_size ( struct vty vty)
static

References vty_out().

Referenced by vty_create().

◆ vty_dont_linemode()

static void vty_dont_linemode ( struct vty vty)
static

References vty_out().

Referenced by vty_create().

◆ vty_down_level()

static void vty_down_level ( struct vty vty)
static

◆ vty_end_config()

static void vty_end_config ( struct vty vty)
static

◆ vty_end_of_line()

static void vty_end_of_line ( struct vty vty)
static

References vty::cp, vty::length, and vty_forward_char().

Referenced by vty_read().

◆ vty_ensure()

static void vty_ensure ( struct vty vty,
int  length 
)
static

References vty::buf, length, and vty::max.

Referenced by vty_self_insert(), and vty_self_insert_overwrite().

◆ vty_escape_map()

static void vty_escape_map ( unsigned char  c,
struct vty vty 
)
static

◆ vty_event()

◆ vty_execute()

◆ vty_forward_char()

static void vty_forward_char ( struct vty vty)
static

◆ vty_forward_kill_word()

static void vty_forward_kill_word ( struct vty vty)
static

References vty::buf, vty::cp, vty::length, and vty_delete_char().

Referenced by vty_read().

◆ vty_forward_word()

static void vty_forward_word ( struct vty vty)
static

References vty::buf, vty::cp, vty::length, and vty_forward_char().

Referenced by vty_read().

◆ vty_hist_add()

static void vty_hist_add ( struct vty vty)
static

◆ vty_history_print()

static void vty_history_print ( struct vty vty)
static

◆ vty_insert_word_overwrite()

static void vty_insert_word_overwrite ( struct vty vty,
char *  str 
)
static

◆ vty_kill_line()

static void vty_kill_line ( struct vty vty)
static

◆ vty_kill_line_from_beginning()

static void vty_kill_line_from_beginning ( struct vty vty)
static

◆ vty_next_line()

static void vty_next_line ( struct vty vty)
static

◆ vty_out()

int vty_out ( struct vty vty,
const char *  format,
  ... 
)

◆ vty_previous_line()

static void vty_previous_line ( struct vty vty)
static

◆ vty_prompt()

◆ vty_redraw_line()

static void vty_redraw_line ( struct vty vty)
static

◆ vty_save_cwd()

static void vty_save_cwd ( void  )
static

References c, MAXPATHLEN, SYSCONFDIR, tall_vty_ctx, and vty_cwd.

Referenced by vty_init().

◆ vty_self_insert()

static void vty_self_insert ( struct vty vty,
char  c 
)
static

◆ vty_self_insert_overwrite()

static void vty_self_insert_overwrite ( struct vty vty,
char  c 
)
static

◆ vty_stop_input()

static void vty_stop_input ( struct vty vty)
static

◆ vty_telnet_option()

static int vty_telnet_option ( struct vty vty,
unsigned char *  buf,
int  nbytes 
)
static

◆ vty_transpose_chars()

static void vty_transpose_chars ( struct vty vty)
static

◆ vty_will_echo()

static void vty_will_echo ( struct vty vty)
static

References vty_out().

Referenced by vty_create().

◆ vty_will_suppress_go_ahead()

static void vty_will_suppress_go_ahead ( struct vty vty)
static

References vty_out().

Referenced by vty_create().

◆ vty_write()

static void vty_write ( struct vty vty,
const char *  buf,
size_t  nbytes 
)
static

Variable Documentation

◆ password_check

int password_check
static

Referenced by DEFUN(), vty_config_write(), and vty_create().

◆ telnet_backward_char

const char telnet_backward_char = 0x08
static

◆ telnet_escape_char

const char telnet_escape_char = 0x1B
static

Referenced by vty_clear_screen().

◆ telnet_space_char

const char telnet_space_char = ' '
static

Referenced by vty_delete_char(), and vty_kill_line().

◆ vty_bind_addr

const char* vty_bind_addr = NULL
static

◆ vty_bind_port

int vty_bind_port = -1
static

◆ vty_config

int vty_config
static

◆ vty_cwd

char* vty_cwd = NULL

Referenced by vty_get_cwd(), and vty_save_cwd().

◆ vty_node

struct cmd_node vty_node
Initial value:
= {
"%s(config-line)# ",
1,
}
@ VTY_NODE
Vty node.
Definition: command.h:84

Referenced by vty_init().

◆ vtyvec

◆ Vvty_serv_thread

vector Vvty_serv_thread

Referenced by vty_reset().