FD.io VPP
v18.10-34-gcce845e
Vector Packet Processing
|
Unix stdin/socket command line interface. More...
Go to the source code of this file.
Data Structures | |
struct | unix_cli_banner_t |
A CLI banner line. More... | |
struct | unix_cli_pager_index_t |
Pager line index. More... | |
struct | unix_cli_file_t |
Unix CLI session. More... | |
struct | unix_cli_parse_actions_t |
Mapping of input buffer strings to action values. More... | |
struct | unix_cli_main_t |
CLI global state. More... | |
Macros | |
#define | ESC "\x1b" |
ANSI escape code. More... | |
#define | CSI ESC "[" |
ANSI Control Sequence Introducer. More... | |
#define | ANSI_CLEAR CSI "2J" CSI "1;1H" |
ANSI clear screen. More... | |
#define | ANSI_RESET CSI "0m" |
ANSI reset color settings. More... | |
#define | ANSI_BOLD CSI "1m" |
ANSI Start bold text. More... | |
#define | ANSI_DIM CSI "2m" |
ANSI Stop bold text. More... | |
#define | ANSI_DRED ANSI_DIM CSI "31m" |
ANSI Start dark red text. More... | |
#define | ANSI_BRED ANSI_BOLD CSI "31m" |
ANSI Start bright red text. More... | |
#define | ANSI_CLEARLINE CSI "2K" |
ANSI clear line cursor is on. More... | |
#define | ANSI_SCROLLDN CSI "1T" |
ANSI scroll screen down one line. More... | |
#define | ANSI_SAVECURSOR CSI "s" |
ANSI save cursor position. More... | |
#define | ANSI_RESTCURSOR CSI "u" |
ANSI restore cursor position if previously saved. More... | |
#define | UNIX_CLI_MAX_DEPTH_TELNET 24 |
Maximum depth into a byte stream from which to compile a Telnet protocol message. More... | |
#define | UNIX_CLI_MAX_TERMINAL_WIDTH 512 |
Maximum terminal width we will accept. More... | |
#define | UNIX_CLI_MAX_TERMINAL_HEIGHT 512 |
Maximum terminal height we will accept. More... | |
#define | UNIX_CLI_DEFAULT_TERMINAL_HEIGHT 24 |
Default terminal height. More... | |
#define | UNIX_CLI_DEFAULT_TERMINAL_WIDTH 80 |
Default terminal width. More... | |
#define | CTL(c) (u8[]){ (c) - '@', 0 } |
Given a capital ASCII letter character return a NUL terminated string with the control code for that letter. More... | |
#define | fl(x, y) ( (x) ? toupper((y)) : tolower((y)) ) |
Functions | |
static void | unix_cli_pager_reset (unix_cli_file_t *f) |
Resets the pager buffer and other data. More... | |
static void | unix_cli_file_free (unix_cli_file_t *f) |
Release storage used by a CLI session. More... | |
static unix_cli_parse_action_t | unix_cli_match_action (unix_cli_parse_actions_t *a, u8 *input, u32 ilen, i32 *matched) |
Search for a byte sequence in the action list. More... | |
static void | unix_cli_add_pending_output (clib_file_t *uf, unix_cli_file_t *cf, u8 *buffer, uword buffer_bytes) |
Add bytes to the output vector and then flagg the I/O system that bytes are available to be sent. More... | |
static void | unix_cli_del_pending_output (clib_file_t *uf, unix_cli_file_t *cf, uword n_bytes) |
Delete all bytes from the output vector and flag the I/O system that no more bytes are available to be sent. More... | |
static word | unix_vlib_findchr (u8 chr, u8 *str, word len) |
A bit like strchr with a buffer length limit. More... | |
static void | unix_vlib_cli_output_raw (unix_cli_file_t *cf, clib_file_t *uf, u8 *buffer, uword buffer_bytes) |
Send a buffer to the CLI stream if possible, enqueue it otherwise. More... | |
static void | unix_vlib_cli_output_cooked (unix_cli_file_t *cf, clib_file_t *uf, u8 *buffer, uword buffer_bytes) |
Process a buffer for CRLF handling before outputting it to the CLI. More... | |
static void | unix_vlib_cli_output_cursor_left (unix_cli_file_t *cf, clib_file_t *uf) |
Moves the terminal cursor one character to the left, with special handling when it reaches the left edge of the terminal window. More... | |
static void | unix_cli_cli_prompt (unix_cli_file_t *cf, clib_file_t *uf) |
Output the CLI prompt. More... | |
static void | unix_cli_pager_prompt (unix_cli_file_t *cf, clib_file_t *uf) |
Output a pager prompt and show number of buffered lines. More... | |
static void | unix_cli_pager_message (unix_cli_file_t *cf, clib_file_t *uf, char *message, char *postfix) |
Output a pager "skipping" message. More... | |
static void | unix_cli_pager_prompt_erase (unix_cli_file_t *cf, clib_file_t *uf) |
Erase the printed pager prompt. More... | |
static void | unix_cli_ansi_cursor (unix_cli_file_t *cf, clib_file_t *uf, u16 x, u16 y) |
Uses an ANSI escape sequence to move the cursor. More... | |
static void | unix_cli_pager_redraw (unix_cli_file_t *cf, clib_file_t *uf) |
Redraw the currently displayed page of text. More... | |
static void | unix_cli_pager_add_line (unix_cli_file_t *cf, u8 *line, word len_or_index) |
Process and add a line to the pager index. More... | |
static void | unix_cli_pager_reindex (unix_cli_file_t *cf) |
Reindex entire pager buffer. More... | |
static void | unix_vlib_cli_output (uword cli_file_index, u8 *buffer, uword buffer_bytes) |
VLIB CLI output function. More... | |
static u8 | unix_cli_terminal_type_ansi (u8 *term, uword len) |
Identify whether a terminal type is ANSI capable. More... | |
static u8 | unix_cli_terminal_type_noninteractive (u8 *term, uword len) |
Identify whether a terminal type is non-interactive. More... | |
static void | unix_cli_set_session_noninteractive (unix_cli_file_t *cf) |
Set a session to be non-interactive. More... | |
static void | unix_cli_file_welcome (unix_cli_main_t *cm, unix_cli_file_t *cf) |
Emit initial welcome banner and prompt on a connection. More... | |
static void | unix_cli_file_welcome_timer (any arg, f64 delay) |
A failsafe triggered on a timer to ensure we send the prompt to telnet sessions that fail to negotiate the terminal type. More... | |
static i32 | unix_cli_process_telnet (unix_main_t *um, unix_cli_file_t *cf, clib_file_t *uf, u8 *input_vector, uword len) |
A mostly no-op Telnet state machine. More... | |
static int | unix_cli_line_process_one (unix_cli_main_t *cm, unix_main_t *um, unix_cli_file_t *cf, clib_file_t *uf, u8 input, unix_cli_parse_action_t action) |
Process actionable input. More... | |
static int | unix_cli_line_edit (unix_cli_main_t *cm, unix_main_t *um, clib_file_main_t *fm, unix_cli_file_t *cf) |
Process input bytes on a stream to provide line editing and command history in the CLI. More... | |
static void | unix_cli_process_input (unix_cli_main_t *cm, uword cli_file_index) |
Process input to a CLI session. More... | |
static void | unix_cli_kill (unix_cli_main_t *cm, uword cli_file_index) |
Destroy a CLI session. More... | |
static uword | unix_cli_process (vlib_main_t *vm, vlib_node_runtime_t *rt, vlib_frame_t *f) |
Handle system events. More... | |
static clib_error_t * | unix_cli_write_ready (clib_file_t *uf) |
Called when a CLI session file descriptor can be written to without blocking. More... | |
static clib_error_t * | unix_cli_read_ready (clib_file_t *uf) |
Called when a CLI session file descriptor has data to be read. More... | |
static clib_error_t * | unix_cli_error_detected (clib_file_t *uf) |
Called when a CLI session file descriptor has an error condition. More... | |
static u32 | unix_cli_file_add (unix_cli_main_t *cm, char *name, int fd) |
Store a new CLI session. More... | |
static clib_error_t * | unix_cli_listen_read_ready (clib_file_t *uf) |
Telnet listening socket has a new connection. More... | |
static void | unix_cli_resize_interrupt (int signum) |
The system terminal has informed us that the window size has changed. More... | |
static clib_error_t * | unix_cli_config (vlib_main_t *vm, unformat_input_t *input) |
Handle configuration directives in the unix section. More... | |
static clib_error_t * | unix_cli_exit (vlib_main_t *vm) |
Called when VPP is shutting down, this restores the system terminal state if previously saved. More... | |
void | vlib_unix_cli_set_prompt (char *prompt) |
Set the CLI prompt. More... | |
static clib_error_t * | unix_cli_quit (vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd) |
CLI command to quit the terminal session. More... | |
static clib_error_t * | unix_cli_exec (vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd) |
CLI command to execute a VPP command script. More... | |
static clib_error_t * | unix_show_errors (vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd) |
CLI command to show various unix error statistics. More... | |
static clib_error_t * | unix_show_files (vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd) |
CLI command to show various unix error statistics. More... | |
static clib_error_t * | unix_cli_show_history (vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd) |
CLI command to show session command history. More... | |
static clib_error_t * | unix_cli_show_terminal (vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd) |
CLI command to show terminal status. More... | |
static clib_error_t * | unix_cli_show_cli_sessions (vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd) |
CLI command to display a list of CLI sessions. More... | |
static clib_error_t * | unix_cli_set_terminal_pager (vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd) |
CLI command to set terminal pager settings. More... | |
static clib_error_t * | unix_cli_set_terminal_history (vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd) |
CLI command to set terminal history settings. More... | |
static clib_error_t * | unix_cli_set_terminal_ansi (vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd) |
CLI command to set terminal ANSI settings. More... | |
static clib_error_t * | unix_cli_init (vlib_main_t *vm) |
Variables | |
static unix_cli_banner_t | unix_cli_banner [] |
Plain welcome banner. More... | |
static unix_cli_banner_t | unix_cli_banner_color [] |
ANSI color welcome banner. More... | |
static unix_cli_parse_actions_t | unix_cli_parse_strings [] |
Patterns to match on a CLI input stream. More... | |
static unix_cli_parse_actions_t | unix_cli_parse_pager [] |
Patterns to match when a CLI session is in the pager. More... | |
static unix_cli_main_t | unix_cli_main |
CLI global state. More... | |
static vlib_cli_command_t | unix_cli_quit_command |
(constructor) VLIB_CLI_COMMAND (unix_cli_quit_command) More... | |
static vlib_cli_command_t | unix_cli_q_command |
(constructor) VLIB_CLI_COMMAND (unix_cli_q_command) More... | |
static vlib_cli_command_t | cli_exec |
(constructor) VLIB_CLI_COMMAND (cli_exec) More... | |
static vlib_cli_command_t | cli_unix_show_errors |
(constructor) VLIB_CLI_COMMAND (cli_unix_show_errors) More... | |
static vlib_cli_command_t | cli_unix_show_files |
(constructor) VLIB_CLI_COMMAND (cli_unix_show_files) More... | |
static vlib_cli_command_t | cli_unix_cli_show_history |
(constructor) VLIB_CLI_COMMAND (cli_unix_cli_show_history) More... | |
static vlib_cli_command_t | cli_unix_cli_show_terminal |
(constructor) VLIB_CLI_COMMAND (cli_unix_cli_show_terminal) More... | |
static vlib_cli_command_t | cli_unix_cli_show_cli_sessions |
(constructor) VLIB_CLI_COMMAND (cli_unix_cli_show_cli_sessions) More... | |
static vlib_cli_command_t | cli_unix_cli_set_terminal_pager |
(constructor) VLIB_CLI_COMMAND (cli_unix_cli_set_terminal_pager) More... | |
static vlib_cli_command_t | cli_unix_cli_set_terminal_history |
(constructor) VLIB_CLI_COMMAND (cli_unix_cli_set_terminal_history) More... | |
static vlib_cli_command_t | cli_unix_cli_set_terminal_ansi |
(constructor) VLIB_CLI_COMMAND (cli_unix_cli_set_terminal_ansi) More... | |
Unix stdin/socket command line interface.
Provides a command line interface so humans can interact with VPP. This is predominantly a debugging and testing mechanism.
Definition in file cli.c.
#define ANSI_RESTCURSOR CSI "u" |
#define ANSI_SCROLLDN CSI "1T" |
#define fl | ( | x, | |
y | |||
) | ( (x) ? toupper((y)) : tolower((y)) ) |
#define UNIX_CLI_DEFAULT_TERMINAL_HEIGHT 24 |
#define UNIX_CLI_DEFAULT_TERMINAL_WIDTH 80 |
#define UNIX_CLI_MAX_DEPTH_TELNET 24 |
#define UNIX_CLI_MAX_TERMINAL_HEIGHT 512 |
#define UNIX_CLI_MAX_TERMINAL_WIDTH 512 |
CLI actions.
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
inlinestatic |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
Search for a byte sequence in the action list.
Searches the unix_cli_parse_actions_t list in a for a match with the bytes in input of maximum length ilen bytes. When a match is made *matched indicates how many bytes were matched. Returns a value from the enum unix_cli_parse_action_t to indicate whether no match was found, a partial match was found or a complete match was found and what action, if any, should be taken.
[in] | a | Actions list to search within. |
[in] | input | String fragment to search for. |
[in] | ilen | Length of the string in 'input'. |
[out] | matched | Pointer to an integer that will contain the number of bytes matched when a complete match is found. |
Definition at line 500 of file cli.c.
|
static |
Process and add a line to the pager index.
In normal operation this function will take the given character string found in line
and with length len_or_index
and iterates the over the contents, adding each line of text discovered within it to the pager index. Lines are identified by newlines ("<code>\\n</code>") and by strings longer than the width of the terminal.
If instead line
is NULL
then len_or_index
is taken to mean the index of an existing line in the pager buffer; this simply means that the input line does not need to be cloned since we alreayd have it. This is typical if we are reindexing the pager buffer.
cf | The CLI session whose pager we are adding to. |
line | The string of text to be indexed into the pager buffer. If line is NULL then the mode of operation changes slightly; see the description above. |
len_or_index | If line is a pointer to a string then this parameter indicates the length of that string; Otherwise this value provides the index in the pager buffer of an existing string to be indexed. |
Definition at line 915 of file cli.c.
|
static |
|
static |
|
static |
|
static |
|
static |
Reindex entire pager buffer.
Resets the current pager index and then re-adds the lines in the pager buffer to the index.
Additionally this function attempts to retain the current page start line offset by searching for the same top-of-screen line in the new index.
cf | The CLI session whose pager buffer should be reindexed. |
Definition at line 977 of file cli.c.
|
inlinestatic |
|
static |
|
static |
|
static |
A mostly no-op Telnet state machine.
Process Telnet command bytes in a way that ensures we're mostly transparent to the Telnet protocol. That is, it's mostly a no-op.
Definition at line 1271 of file cli.c.
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
Identify whether a terminal type is ANSI capable.
Compares the string given in term
with a list of terminal types known to support ANSI escape sequences.
This list contains, for example, xterm
, screen
and ansi
.
term | A string with a terminal type in it. |
len | The length of the string in term . |
1
if the terminal type is recognized as supporting ANSI terminal sequences; 0
otherwise. Definition at line 1138 of file cli.c.
Identify whether a terminal type is non-interactive.
Compares the string given in term
with a list of terminal types known to be non-interactive, as send by tools such as vppctl
.
This list contains, for example, vppctl
.
term | A string with a terminal type in it. |
len | The length of the string in term . |
1
if the terminal type is recognized as being non-interactive; 0
otherwise. Definition at line 1170 of file cli.c.
|
static |
|
static |
|
static |
VLIB CLI output function.
If the terminal has a pager configured then this function takes care of collating output into the pager buffer; ensuring only the first page is displayed and any lines in excess of the first page are buffered.
If the maximum number of index lines in the buffer is exceeded then the pager is cancelled and the contents of the current buffer are sent to the terminal.
If there is no pager configured then the output is sent directly to the terminal.
cli_file_index | Index of the CLI session where this output is directed. |
buffer | String of printabe bytes to be output. |
buffer_bytes | The number of bytes in buffer to be output. |
Definition at line 1050 of file cli.c.
|
static |
Process a buffer for CRLF handling before outputting it to the CLI.
cf | Unix CLI session of the desired stream to write to. |
uf | The Unix file structure of the desired stream to write to. |
buffer | Pointer to the buffer that needs to be written. |
buffer_bytes | The number of bytes from buffer to write. |
Definition at line 666 of file cli.c.
|
static |
Moves the terminal cursor one character to the left, with special handling when it reaches the left edge of the terminal window.
Ordinarily we can simply send a '' to move the cursor left, however most terminals will not reverse-wrap to the end of the previous line if the cursor is in the left-most column. To counter this we must check the cursor position + prompt length modulo terminal width and if available use some other means, such as ANSI terminal escape sequences, to move the cursor.
cf | Unix CLI session of the desired stream to write to. |
uf | The Unix file structure of the desired stream to write to. |
Definition at line 719 of file cli.c.
|
static |
Send a buffer to the CLI stream if possible, enqueue it otherwise.
Attempts to write given buffer to the file descriptor of the given Unix CLI session. If that session already has data in the output buffer or if the write attempt tells us to try again later then the given buffer is appended to the pending output buffer instead.
This is typically called only from unix_vlib_cli_output_cooked
since that is where CRLF handling occurs or from places where we explicitly do not want cooked handling.
cf | Unix CLI session of the desired stream to write to. |
uf | The Unix file structure of the desired stream to write to. |
buffer | Pointer to the buffer that needs to be written. |
buffer_bytes | The number of bytes from buffer to write. |
Definition at line 615 of file cli.c.
A bit like strchr with a buffer length limit.
Search a buffer for the first instance of a character up to the limit of the buffer length. If found then return the position of that character.
The key departure from strchr is that if the character is not found then return the buffer length.
chr | The byte value to search for. |
str | The buffer in which to search for the value. |
len | The depth into the buffer to search. |
chr
. If chr
is not found then len
instead. Definition at line 588 of file cli.c.
void vlib_unix_cli_set_prompt | ( | char * | prompt | ) |
|
static |
(constructor) VLIB_CLI_COMMAND (cli_exec)
|
static |
(constructor) VLIB_CLI_COMMAND (cli_unix_cli_set_terminal_ansi)
|
static |
(constructor) VLIB_CLI_COMMAND (cli_unix_cli_set_terminal_history)
|
static |
(constructor) VLIB_CLI_COMMAND (cli_unix_cli_set_terminal_pager)
|
static |
(constructor) VLIB_CLI_COMMAND (cli_unix_cli_show_cli_sessions)
|
static |
(constructor) VLIB_CLI_COMMAND (cli_unix_cli_show_history)
|
static |
(constructor) VLIB_CLI_COMMAND (cli_unix_cli_show_terminal)
|
static |
(constructor) VLIB_CLI_COMMAND (cli_unix_show_errors)
|
static |
(constructor) VLIB_CLI_COMMAND (cli_unix_show_files)
|
static |
|
static |
ANSI color welcome banner.
|
static |
|
static |
Patterns to match when a CLI session is in the pager.
|
static |
Patterns to match on a CLI input stream.
|
static |
(constructor) VLIB_CLI_COMMAND (unix_cli_q_command)
|
static |
(constructor) VLIB_CLI_COMMAND (unix_cli_quit_command)