libosmovty UNKNOWN
Osmocom VTY library
Loading...
Searching...
No Matches
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)
#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
static void vty_clear_buf (struct vty *vty)
struct vtyvty_new (void)
 Allocate a new vty interface structure.
static void vty_auth (struct vty *vty)
void vty_flush (struct vty *vty)
void vty_close (struct vty *vty)
 Close a given vty interface.
int vty_shell (struct vty *vty)
 Return if this VTY is a shell or not.
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.
int vty_out_newline (struct vty *vty)
 print a newline on the given VTY
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).
void * vty_current_index (struct vty *vty)
 return the current index of a given VTY
int vty_current_node (struct vty *vty)
 return the current node of a given VTY
int vty_config_lock (struct vty *vty)
 Lock the configuration to a given VTY.
int vty_config_unlock (struct vty *vty)
 Unlock the configuration from a given VTY.
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.
int vty_read_config_filep (FILE *confp, void *priv)
 Read up VTY configuration from a file stream.
struct vtyvty_create (int vty_sock, void *priv)
 Create new vty structure.
 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.
 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.
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.
int vty_read_config_file (const char *file_name, void *priv)
 Read the configuration file using the VTY code.

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)
Value:
((X) - '@')

Referenced by vty_read().

◆ MAXPATHLEN

#define MAXPATHLEN   4096

◆ SYSCONFDIR

#define SYSCONFDIR   "/usr/local/etc"

Referenced by vty_save_cwd().

◆ VTY_BIND_ADDR_DEFAULT

#define VTY_BIND_ADDR_DEFAULT   "127.0.0.1"

◆ VTY_ESCAPE

#define VTY_ESCAPE   2

Referenced by vty_read().

◆ VTY_NORMAL

#define VTY_NORMAL   0

◆ VTY_PRE_ESCAPE

#define VTY_PRE_ESCAPE   1

Referenced by vty_read().

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, CMD_SUCCESS, and NO_STR.

◆ DEFUN() [4/10]

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

References CMD_SUCCESS, NO_STR, 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, vty::monitor, and NO_STR.

◆ 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()

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()

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()

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()

void vty_beginning_of_line ( struct vty * vty)
static

◆ vty_buffer_reset()

void vty_buffer_reset ( struct vty * vty)
static

◆ vty_clear_buf()

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()

void vty_clear_screen ( struct vty * vty)
static

◆ vty_command()

◆ vty_complete_command()

◆ vty_config_write()

int vty_config_write ( struct vty * vty)
static

◆ vty_delete_backward_char()

void vty_delete_backward_char ( struct vty * vty)
static

◆ vty_delete_char()

◆ vty_describe_command()

◆ vty_describe_fold()

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()

void vty_do_window_size ( struct vty * vty)
static

References vty_out().

Referenced by vty_create().

◆ vty_dont_linemode()

void vty_dont_linemode ( struct vty * vty)
static

References vty_out().

Referenced by vty_create().

◆ vty_down_level()

void vty_down_level ( struct vty * vty)
static

◆ vty_end_config()

void vty_end_config ( struct vty * vty)
static

◆ vty_end_of_line()

void vty_end_of_line ( struct vty * vty)
static

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

Referenced by vty_read().

◆ vty_ensure()

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

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

Referenced by vty_self_insert(), and vty_self_insert_overwrite().

◆ vty_escape_map()

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

◆ vty_event()

void vty_event ( enum event event,
int sock,
struct vty * vty )

◆ vty_execute()

◆ vty_forward_char()

void vty_forward_char ( struct vty * vty)
static

◆ vty_forward_kill_word()

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()

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()

void vty_hist_add ( struct vty * vty)
static

◆ vty_history_print()

void vty_history_print ( struct vty * vty)
static

◆ vty_insert_word_overwrite()

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

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

Referenced by vty_complete_command().

◆ vty_kill_line()

void vty_kill_line ( struct vty * vty)
static

◆ vty_kill_line_from_beginning()

void vty_kill_line_from_beginning ( struct vty * vty)
static

◆ vty_next_line()

void vty_next_line ( struct vty * vty)
static

◆ vty_out()

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

◆ vty_previous_line()

void vty_previous_line ( struct vty * vty)
static

◆ vty_prompt()

◆ vty_redraw_line()

void vty_redraw_line ( struct vty * vty)
static

◆ vty_save_cwd()

void vty_save_cwd ( void )
static

References MAXPATHLEN, SYSCONFDIR, tall_vty_ctx, and vty_cwd.

Referenced by vty_init().

◆ vty_self_insert()

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

◆ vty_self_insert_overwrite()

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

◆ vty_stop_input()

void vty_stop_input ( struct vty * vty)
static

◆ vty_telnet_option()

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

◆ vty_transpose_chars()

void vty_transpose_chars ( struct vty * vty)
static

◆ vty_will_echo()

void vty_will_echo ( struct vty * vty)
static

References vty_out().

Referenced by vty_create().

◆ vty_will_suppress_go_ahead()

void vty_will_suppress_go_ahead ( struct vty * vty)
static

References vty_out().

Referenced by vty_create().

◆ vty_write()

Variable Documentation

◆ password_check

int password_check
static

◆ 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().