libosmovty 1.10.0.64-ff3d
Osmocom VTY library
|
#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 vty * | vty_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 vty * | vty_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 |
#define CONTROL | ( | X | ) | ((X) - '@') |
#define MAXPATHLEN 4096 |
#define SYSCONFDIR "/usr/local/etc" |
#define VTY_BIND_ADDR_DEFAULT "127.0.0.1" |
#define VTY_ESCAPE 2 |
#define VTY_NORMAL 0 |
#define VTY_PRE_ESCAPE 1 |
DEFUN | ( | config_who | , |
config_who_cmd | , | ||
"who" | , | ||
"Display who is on vty\n" | |||
) |
References CMD_SUCCESS, vty::config, vector_active, vector_slot, VTY_NEWLINE, vty_out(), and vtyvec.
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 | ( | 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 | ( | no_vty_login | , |
no_vty_login_cmd | , | ||
"no login" | , | ||
NO_STR "Enable password checking\n" | |||
) |
References CMD_SUCCESS, and password_check.
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 | ( | show_history | , |
show_history_cmd | , | ||
"show history" | , | ||
SHOW_STR "Display the session command history\n" | |||
) |
References CMD_SUCCESS, vty::hindex, vty::hist, vty::index, VTY_MAXHIST, VTY_NEWLINE, and vty_out().
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 | ( | 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 | ( | 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" | |||
) |
References argc, argv, CMD_SUCCESS, tall_vty_ctx, vty_bind_addr, and vty_bind_port.
DEFUN | ( | vty_login | , |
vty_login_cmd | , | ||
"login" | , | ||
"Enable password checking\n" | |||
) |
References CMD_SUCCESS, and password_check.
|
static |
References host::advanced, AUTH_ENABLE_NODE, AUTH_NODE, vty::buf, host::enable, host::enable_encrypt, ENABLE_NODE, host::encrypt, vty::fail, vty::node, host::password, host::password_encrypt, vty::status, VIEW_NODE, vty::VTY_CLOSE, VTY_NEWLINE, and vty_out().
Referenced by vty_execute().
|
static |
References vty::cp, telnet_backward_char, and vty_write().
Referenced by vty_backward_pure_word(), vty_backward_word(), vty_beginning_of_line(), vty_delete_backward_char(), vty_escape_map(), vty_read(), and vty_transpose_chars().
|
static |
References vty::buf, vty::cp, and vty_delete_backward_char().
Referenced by vty_read().
|
static |
References vty::buf, vty::cp, and vty_backward_char().
Referenced by vty_complete_command().
|
static |
References vty::buf, vty::cp, and vty_backward_char().
Referenced by vty_read().
|
static |
References vty::cp, and vty_backward_char().
Referenced by vty_kill_line_from_beginning(), and vty_read().
|
static |
References buffer_reset(), vty::obuf, vty_prompt(), and vty_redraw_line().
Referenced by vty_read().
|
static |
References vty::buf, and vty::max.
Referenced by vty_create(), vty_execute(), and vty_stop_input().
|
static |
References telnet_escape_char, vty_out(), vty_prompt(), and vty_redraw_line().
Referenced by vty_read().
|
static |
References vty::buf, CMD_ERR_AMBIGUOUS, CMD_ERR_INCOMPLETE, CMD_ERR_NO_MATCH, cmd_execute_command(), cmd_free_strvec(), cmd_make_strvec(), CMD_SUCCESS, CMD_WARNING, vty::type, VTY_FILE, VTY_NEWLINE, and vty_out().
Referenced by vty_execute().
|
static |
References AUTH_ENABLE_NODE, AUTH_NODE, vty::buf, cmd_complete_command(), CMD_COMPLETE_FULL_MATCH, CMD_COMPLETE_LIST_MATCH, CMD_COMPLETE_MATCH, CMD_ERR_AMBIGUOUS, CMD_ERR_NO_MATCH, CMD_ERR_NOTHING_TODO, cmd_free_strvec(), cmd_make_strvec(), vty::length, vty::node, vector_only_index_free(), vector_set(), vty_backward_pure_word(), vty_insert_word_overwrite(), VTY_NEWLINE, vty_out(), vty_prompt(), vty_redraw_line(), and vty_self_insert().
Referenced by vty_read().
|
static |
References CMD_SUCCESS, password_check, vty_bind_addr, VTY_BIND_ADDR_DEFAULT, vty_bind_port, VTY_NEWLINE, and vty_out().
Referenced by vty_init().
|
static |
References vty::cp, vty_backward_char(), and vty_delete_char().
Referenced by vty_backward_kill_word(), and vty_read().
|
static |
References AUTH_ENABLE_NODE, AUTH_NODE, vty::buf, vty::cp, vty::length, vty::node, telnet_backward_char, telnet_space_char, vty_down_level(), and vty_write().
Referenced by vty_delete_backward_char(), vty_forward_kill_word(), and vty_read().
|
static |
References vty::buf, desc::cmd, cmd_describe_command(), CMD_ERR_AMBIGUOUS, CMD_ERR_NO_MATCH, cmd_free_strvec(), cmd_make_strvec(), len(), vty::length, desc::str, vector_active, vector_free(), vector_init(), vector_set(), vector_slot, vty_describe_fold(), VTY_NEWLINE, vty_out(), vty_prompt(), vty_redraw_line(), and vty::width.
Referenced by vty_read().
|
static |
References desc::cmd, desc::str, VTY_NEWLINE, and vty_out().
Referenced by vty_describe_command().
|
static |
References vty_out().
Referenced by vty_create().
|
static |
References vty_out().
Referenced by vty_create().
|
static |
References config_exit_cmd, CONFIG_NODE, vty::cp, cmd_element::func, vty::node, vty, vty_go_parent(), VTY_NEWLINE, vty_out(), and vty_prompt().
Referenced by vty_delete_char().
|
static |
References CFG_LOG_NODE, CONFIG_NODE, vty::cp, ENABLE_NODE, vty::node, VIEW_NODE, vty_config_unlock(), VTY_NEWLINE, VTY_NODE, vty_out(), and vty_prompt().
Referenced by vty_read().
|
static |
References vty::cp, vty::length, and vty_forward_char().
Referenced by vty_read().
|
static |
References vty::buf, length, and vty::max.
Referenced by vty_self_insert(), and vty_self_insert_overwrite().
|
static |
References c, vty::escape, vty_backward_char(), vty_forward_char(), vty_next_line(), VTY_NORMAL, and vty_previous_line().
Referenced by vty_read().
callback from core VTY code about VTY related events
References vty_signal_data::event, telnet_connection::fd, OSMO_FD_READ, OSMO_FD_WRITE, osmo_signal_dispatch(), vty::priv, S_VTY_EVENT, vty_signal_data::sock, SS_L_VTY, telnet_close_client(), vty::type, vty_signal_data::vty, vty, VTY_CLOSED, VTY_READ, VTY_TERM, VTY_WRITE, and osmo_fd::when.
Referenced by vty_close(), vty_create(), vty_out_va(), and vty_read().
|
static |
References AUTH_ENABLE_NODE, AUTH_NODE, CMD_SUCCESS, vty::cp, vty::length, vty::node, vty::status, vty::type, vty_auth(), vty_clear_buf(), vty_command(), vty_hist_add(), vty_prompt(), and VTY_TERM.
Referenced by vty_read().
|
static |
References vty::buf, vty::cp, vty::length, and vty_write().
Referenced by vty_end_of_line(), vty_escape_map(), vty_forward_word(), and vty_read().
|
static |
References vty::buf, vty::cp, vty::length, and vty_delete_char().
Referenced by vty_read().
|
static |
References vty::buf, vty::cp, vty::length, and vty_forward_char().
Referenced by vty_read().
|
static |
References vty::buf, vty::hindex, vty::hist, vty::hp, vty::length, and VTY_MAXHIST.
Referenced by vty_execute().
|
static |
References vty::buf, vty::cp, vty::hist, vty::hp, length, vty::length, vty_kill_line_from_beginning(), and vty_redraw_line().
Referenced by vty_next_line(), and vty_previous_line().
|
static |
References vty::buf, vty::cp, len(), vty::length, and vty_write().
Referenced by vty_complete_command().
|
static |
References vty::buf, vty::cp, vty::length, telnet_backward_char, telnet_space_char, and vty_write().
Referenced by vty_kill_line_from_beginning(), and vty_read().
|
static |
References vty_beginning_of_line(), and vty_kill_line().
Referenced by vty_history_print(), and vty_read().
|
static |
References vty::hindex, vty::hist, vty::hp, vty_history_print(), and VTY_MAXHIST.
Referenced by vty_escape_map(), and vty_read().
int vty_out | ( | struct vty * | vty, |
const char * | format, | ||
... | |||
) |
VTY standard output function.
[in] | vty | VTY to which we should print |
[in] | format | variable-length format string |
References vty_out_va().
Referenced by DEFUN(), vty_auth(), vty_clear_screen(), vty_command(), vty_complete_command(), vty_config_write(), vty_create(), vty_describe_command(), vty_describe_fold(), vty_do_window_size(), vty_dont_linemode(), vty_down_level(), vty_end_config(), vty_hello(), vty_out_uptime(), vty_prompt(), vty_read(), vty_stop_input(), vty_telnet_option(), vty_will_echo(), and vty_will_suppress_go_ahead().
|
static |
References vty::hist, vty::hp, vty_history_print(), and VTY_MAXHIST.
Referenced by vty_escape_map(), and vty_read().
|
static |
References host::app_info, cmd_prompt(), vty_app_info::name, vty::node, vty::type, vty_out(), and VTY_TERM.
Referenced by vty_buffer_reset(), vty_clear_screen(), vty_complete_command(), vty_create(), vty_describe_command(), vty_down_level(), vty_end_config(), vty_execute(), and vty_stop_input().
|
static |
References vty::buf, vty::cp, vty::length, and vty_write().
Referenced by vty_buffer_reset(), vty_clear_screen(), vty_complete_command(), vty_describe_command(), and vty_history_print().
|
static |
References c, MAXPATHLEN, SYSCONFDIR, tall_vty_ctx, and vty_cwd.
Referenced by vty_init().
|
static |
References vty::buf, c, vty::cp, length, vty::length, telnet_backward_char, vty_ensure(), and vty_write().
Referenced by vty_complete_command(), and vty_read().
|
static |
References AUTH_ENABLE_NODE, AUTH_NODE, vty::buf, c, vty::cp, vty::length, vty::node, vty_ensure(), and vty_write().
Referenced by vty_transpose_chars().
|
static |
References vty::cp, vty::hindex, vty::hp, vty::length, vty_clear_buf(), VTY_NEWLINE, vty_out(), and vty_prompt().
Referenced by vty_read().
|
static |
References vty::height, vty::iac_sb_in_progress, vty::sb_buf, vty::sb_len, TELNET_NAWS_SB_LEN, VTY_NEWLINE, vty_out(), and vty::width.
Referenced by vty_read().
|
static |
References vty::buf, vty::cp, vty::length, vty_backward_char(), and vty_self_insert_overwrite().
Referenced by vty_read().
|
static |
References vty_out().
Referenced by vty_create().
|
static |
References vty_out().
Referenced by vty_create().
|
static |
References AUTH_ENABLE_NODE, AUTH_NODE, buffer_put(), vty::node, and vty::obuf.
Referenced by vty_backward_char(), vty_delete_char(), vty_forward_char(), vty_insert_word_overwrite(), vty_kill_line(), vty_redraw_line(), vty_self_insert(), and vty_self_insert_overwrite().
|
static |
Referenced by DEFUN(), vty_config_write(), and vty_create().
|
static |
Referenced by vty_backward_char(), vty_delete_char(), vty_kill_line(), and vty_self_insert().
|
static |
Referenced by vty_clear_screen().
|
static |
Referenced by vty_delete_char(), and vty_kill_line().
|
static |
Referenced by DEFUN(), vty_config_write(), and vty_get_bind_addr().
|
static |
Referenced by DEFUN(), vty_config_write(), and vty_get_bind_port().
|
static |
Referenced by vty_config_lock(), and vty_config_unlock().
char* vty_cwd = NULL |
Referenced by vty_get_cwd(), and vty_save_cwd().
struct cmd_node vty_node |
Referenced by vty_init().
|
static |
Referenced by DEFUN(), vty_close(), vty_create(), vty_init(), vty_init_vtysh(), and vty_reset().
vector Vvty_serv_thread |
Referenced by vty_reset().