aboutsummaryrefslogtreecommitdiffstats
path: root/src/vlib/unix/cli.c
AgeCommit message (Collapse)AuthorFilesLines
2019-09-17vlib: fix cli process stack overflowAloys Augustin1-1/+1
Some cli processes, including bringing up an i40e interface with dpdk, consume more than the currently available stack space. Type: fix Fixes: VPP-1774 Signed-off-by: Aloys Augustin <aloaugus@cisco.com> Change-Id: I86ceb9e6e07523d5e0f760b5922467f09a8d4006
2019-09-16vlib: cli support ctrl-w to erase left wordHiroki Shirokura1-0/+47
Type: fix Signed-off-by: Hiroki Shirokura <slank.dev@gmail.com> Change-Id: I3ae7dc3858d0353764d629d6a9eff2bdab5f8768
2019-08-09stats: create /run/vpp before stat socket bind()YohanPipereau1-1/+1
When VPP tries to bind to stats.sock it will complain about non-existing /run/vpp directory. /run/vpp is created before cli socket operations are performed. The same should be done for stat socket. Ticket: VPP-1708 Type: fix Change-Id: I53d70939c8125d04a365ac51a6cbf8926dc52adf Signed-off-by: YohanPipereau <ypiperea@cisco.com> Signed-off-by: Ole Troan <ot@cisco.com>
2019-07-10vlib: Replace timer in CLI with an event processChris Luke1-16/+140
The CLI code, when it accepts a socket connection, ran a timer for each session that would ensure the CLI session was started should the TELNET negotiation stage fail to complete. It has since transpired that this is unsafe; the timer is capable of firing in critical sections, during a spinlock, and since we peform non-trivial things in the handler it can cause a deadlock. This was reported recently in VPP-1711 but a search of history suggests this may also be (one of) the causes in VPP-1413. This change replaces that method with an event-driven process. The process is created when the first socket connection is accepted. When new connections are created the process is sent an event to register the new session in a list. That event process has a loop that evaluates the list of oustanding sessions and if a deadline expires, their session is started if it has not been already, and then removed from the list. If we have pending sessions then the loop waits on a timer or an event; if there are no sessions it waits on events only. Type: fix Ticket: VPP-1711 Change-Id: I8c6093b7d0fc1bea0eb790032ed282a0ca169194 Signed-off-by: Chris Luke <chrisy@flirble.org> Signed-off-by: Dave Barach <dave@barachs.net>
2019-05-17Fix 'terminal history off' crasherChris Luke1-7/+14
- 'set terminal history off' or '... limit 0' has an incorrect terminal condition and tries to vec_delete one-too-many times causing a crash. - Changing >= to > fixes this. - In any case, a single vec_delete is more efficient, so do that instead. Change-Id: Ia0db63b6c5c7891d75b302e793b4e4985dd86ebb Signed-off-by: Chris Luke <chrisy@flirble.org>
2019-03-28Typos. A bunch of typos I've been collecting.Paul Vinciguerra1-2/+2
Change-Id: I53ab8d17914e6563110354e4052109ac02bf8f3b Signed-off-by: Paul Vinciguerra <pvinci@vinciconsulting.com>
2018-10-23c11 safe string handling supportDave Barach1-2/+2
Change-Id: Ied34720ca5a6e6e717eea4e86003e854031b6eab Signed-off-by: Dave Barach <dave@barachs.net>
2018-09-07Silence warning over ignored return value (CID 187932)Chris Luke1-2/+2
- We deliberately ignore the return value. Change-Id: If467911b019e7336cf9dc6d4c95c2cd53a5af33f Signed-off-by: Chris Luke <chrisy@flirble.org>
2018-09-06Fix Telnet option processing issueChris Luke1-1/+8
- A check for the length of the buffer should have used the provided 'len' variable, not 'vec_len' since the buffer pointer may be within a vector, but not the start of one. 'vec_len' reports 0 in that case, causing premature exit from the options processing loop and a wait for further input before it checks the next option. - Also add TCP_NODELAY to CLI sockets to disable Nagle on TCP connections for a possible improvement in interactive response. Change-Id: Ie1f53c003ca7d66bed51f437d298183215bad38c Signed-off-by: Chris Luke <chrisy@flirble.org>
2018-07-12Fix debug CLI node recycling bugsDave Barach1-5/+26
When creating a new - as opposed to recycled - debug CLI process node, perform a proper barrier sync and node runtime update. Otherwise, the graph replicas diverge for some period of time. That's not immediately fatal, but it's not a good idea, either. When renaming a debug cli process node, fix all of the name-vector replicas before freeing the [one-and-only] name vector. This fixes the so-called stats segment node runtime scraper crash, which tripped over a replicated dangling reference to the recently-freed debug CLI node name. Change-Id: Ieffabd9f003139e534b9d79b88370439907930e5 Signed-off-by: Dave Barach <dbarach@cisco.com>
2018-06-30cli: Validate cli_file_index on quit commandSteve Shin1-0/+4
VPP crash happens with 'vppctl quit quit' command. The 2nd quit command tries to access the file index which is already freed by the first quit. This can be avoided to validate cli_file_index. Change-Id: I880514c93523db2a727d7510c97950582cd6a6c8 Signed-off-by: Steve Shin <jonshin@cisco.com>
2018-06-10cli: Disable XON/XOFF in the ttyChris Luke1-0/+4
- CLI history forward-search is bound to ^S which is common, but that is also the tty's default control byte to pause output. So we disable XON/XOFF in the tty so that we can use ^S. Change-Id: I61717c77a11733d64eed7f8119677e7cd2e20029 Signed-off-by: Chris Luke <chrisy@flirble.org>
2018-06-10cli: Fix reverse-line-wrap in terminals (VPP-1295)Chris Luke1-86/+195
- Terminals do not reverse-line-wrap when the cursor is at the left edge and \b tries to make it go left. - Instead, we have to track the cursor position if we need to emit \b's and if we are at the left edge emit an ANSI sequence to relocate the cursor. Previously we usually simply calculated the new cursor position after a bunch of output had completed. - Further trickiness is required since most xterm-like terminals also defer moving the cursor to the next line when at the right edge[1], and then if they receive a \b move the cursor back one character too many. - This requires intricate reworking of everywhere that \b is emitted by the CLI code during command line editing. [1] Bash counters this issue by tracking the cursor position as output is generated and forcing the cursor to the next line (by emitting a space followed by \r) if it gets to this phantom cursor position); here we effectively do that but only if the user tries to go left when in this state. Change-Id: I7c1d7c0e24c53111a5810cebb504ccfdac743086 Signed-off-by: Chris Luke <chrisy@flirble.org>
2018-06-10cli: Fix off-by-one in the pagerChris Luke1-2/+2
- The last line in the pager buffer was sometimes missed when using space/pg-dn; simple off-by-one error. Change-Id: Id4e5f7cf0e5db4f719f87b9069d75427bc66d3f7 Signed-off-by: Chris Luke <chrisy@flirble.org>
2018-03-16cli: make q work againFlorin Coras1-0/+8
After the addition of "qos" cli, "quit" command is not the only match for "q". Therefore, add a separate "q" cli to avoid ambiguity. Change-Id: I84f6ddce14ef7d5fa7089537cb62adfecea0e501 Signed-off-by: Florin Coras <fcoras@cisco.com>
2018-02-06vlib: epoll on worker threadsDamjan Marion1-1/+50
This patch teaches worer threads to sleep and to be waken up by kernel if there is activity on file desctiptors assigned to that thread. It also adds counters to epoll file descriptors and new debug cli 'show unix file'. Change-Id: Iaf67869f4aa88ff5b0a08982e1c08474013107c4 Signed-off-by: Damjan Marion <damarion@cisco.com>
2018-01-30VPP-899: Run VPP under SELinuxBilly McFall1-4/+20
Add an SELinux profile such that VPP can run under SELinux on RPM based platforms. The SELinux Policy is currently only implemented for RPM packages, specifically, Fedora, CentOS and RHEL. Doxygen User Documentation has been included (selinux_doc.md). Once some discussion on file locations has completed (see vpp-devlist), updates to the Debug CLI documentation will also need to be updated. Additional changes: Patch Set 2: - Rework selinux_doc.md such that each line is only 80 characters instead of each sentence on a line. Made additonal minor chnages to the text. - Update vHost Debug CLI documentation to reflex new socket location. Cleaned up some text from when I originally wrote it, to better reflex proper use. - Update exec Debug CLI documentation to be more inline with suggested helptext, added text regarding recommended script file location. - For Debian builds, create the /var/log/vpp/ directory. I don't use Debian very much, so please pay extra attention to build-data/platforms.mk and build-root/deb/debian/.gitignore. - Per discussion on VPP call, changed the default log location to /var/log/vpp/vpp.log. - Changed the socket location for vHost in AutoConfig to /var/run/vpp/. Patch Set 3: - Update selinux_doc.md based on comments. Change-Id: I400520dc33f1ca51012d09ef8fe5a7b7b96c631e Signed-off-by: Billy McFall <bmcfall@redhat.com>
2017-12-06fix bug in pagerNeale Ranns1-2/+3
the format statement can return NULL before the pager has pages. Change-Id: Ibabfd107e64fc9ab0eb142c28c155506f0d25828 Signed-off-by: Neale Ranns <nranns@cisco.com>
2017-11-13Instead of a min term size, use a default (VPP-1061)Chris Luke1-16/+21
- In the bug report, Docker was sometimes giving shells a 0,0 terminal size. The minimum-term-size logic meant that VPP assumed the terminal had 1 row. The pager functioned, but of course overwrote the one line with its own prompt. - Instead of a minimum size, always use a default size when the either terminal dimension is 0. Change-Id: Iee5a465f0e4cbb618ef2222b40a52994aefa54bf Signed-off-by: Chris Luke <chrisy@flirble.org>
2017-10-03Repair vlib API socket serverDave Barach1-1/+1
- Teach vpp_api_test to send/receive API messages over sockets - Add memfd-based shared memory - Add api messages to create memfd-based shared memory segments - vpp_api_test supports both socket and shared memory segment connections - vpp_api_test pivot from socket to shared memory API messaging - add socket client support to libvlibclient.so - dead client reaper sends ping messages, container-friendly - dead client reaper falls back to kill (<pid>, 0) live checking if e.g. a python app goes silent for tens of seconds - handle ping messages in python client support code - teach show api ring about pairwise shared-memory segments - fix ip probing of already resolved destinations (VPP-998) We'll need this work to implement proper host-stack client isolation Change-Id: Ic23b65f75c854d0393d9a2e9d6b122a9551be769 Signed-off-by: Dave Barach <dave@barachs.net> Signed-off-by: Dave Wallace <dwallacelf@gmail.com> Signed-off-by: Florin Coras <fcoras@cisco.com>
2017-09-22Fix vpp "unix interactive" when running under emacs + gdbDave Barach1-3/+8
In this specific corner-case setup, ioctl (0, TIOCGWINSZ) returns window height = 0 and width = 0. Rather than declaring the terminal to be non-interactive, set the window size parameters to 80 x 24. Change-Id: If66f5f0883f1940518ec1c6e26228c9bb6f32852 Signed-off-by: Dave Barach <dave@barachs.net>
2017-09-21vppctl,cli: Improve non-interactive vppctl (VPP-944)Chris Luke1-51/+308
Short version: Make vppctl behave as expected when run from scripts, or without a controlling terminal, and especially when using it with VPP commands on its command line ("non-interactively"). In particular, prevent the welcome banner and VPP CLI prompt from being sent by VPP when being used in these ways. vppctl ------ - Improve vppctl's detection of non-interactive sessions. - Pass non-interactiveness in the terminal type telnet option as a value distinct from "dumb" (which means non-ANSI capable.) - Make tty setup handling more robust. - Only send non-interactive command once we've sent the terminal type, to ensure correct event sequence; we need the VPP cli session to be in line-by-line mode. - Ignore stdin when it looks something like /dev/null. - Skip NUL bytes received from VPP. VPP CLI ------- - Detect "non-interactive" terminal types and set session parameters accordingly. - Add an "interactive" flag that controls whether the welcome banner and CLI prompt are sent. - Detect if telnet options processing switched us into line mode and act accordingly for the rest of the current input buffer. This was causing the command string to be echoed by the CLI editor code. - For non-interactive sessions, send a NUL byte after the input buffer has been processed. This is because vppctl depends on seeing traffic before it will try to close the session; a command with no output would cause it to hang. NUL bytes are ignored by all decent terminals, but we have vppctl strip them out anyway. - Prevent certain commands from running in non-interactive sessions since they manipulate interactive-related features. - For interactive sessions, quench the prompt that prints on VPP shutdown. - Detect and handle socket errors in the CLI; sessions were leaking. - Pevent SIGPIPE from ever being raised; handle EPIPE instead. We don't need VPP to die just because a socket closed just before we try to write to it! - Add a command to dump a list of current CLI sessions; mostly this was to detect session leakage, but it may have some general utility. Change-Id: Ia147da013317180882c1d967b18eefb8519a55fb Signed-off-by: Chris Luke <chrisy@flirble.org>
2017-09-20CLI: fix segfault when browsing an empty historyYoann Desmouceaux1-3/+1
When one starts VPP, types a command, presses up rather than enter, then types a new command, unix_cli_line_process_one() segfaults. This is due to cf->cursor not being reset upon pressing up if the history is empty. Change-Id: Ie503f20a9cb551e735abb8b0f4feb8c0006d2b61 Signed-off-by: Yoann Desmouceaux <ydesmouc@cisco.com>
2017-09-18Fixes for issues Coverity has reported (VPP-972)Chris Luke1-0/+30
177117: fstat() returns -1 on error; the code is checking for any positive value instead 175142: final return could never be reached; simple refactoring 175235,175236: Warning suppressed with an explicit cast to (void) 174817: Final return couldn't be reached; is is_in_order is 0 then 'rv' is already returned above 172095,172093: If is_is_set does not get set to 1, then return 0 has already been invoked 174405: Re-kill this (nothing sets rv) 171136: Looks like a cmd line flag to set test_bytes was missing; added it, and refactored the argc/argv processing to avoid two other potential segv's 176813: Add range checking for term width/height. First stab at a reasonable range is 1-512 for both. 175350: Fix implicit casting in shift operation 174272: Not a c+p error; try using a coverity annotation to ignore it 174273,175320: Annotated FORWARD_NULL Change-Id: I58d0f860fc2209f59f8d1b6b344d631b8d429ace Signed-off-by: Chris Luke <chrisy@flirble.org>
2017-09-14clib_socket: add sendmsg / recvmsg with ancillary data supportDamjan Marion1-2/+2
Change-Id: Ie18580e05ec12291e7026f21ad874e088a712c8e Signed-off-by: Damjan Marion <damarion@cisco.com>
2017-09-09move unix_file_* code to vppinfraDamjan Marion1-39/+46
This will allow us to use this code in client libraries without vlib. Change-Id: I8557b752496841ba588aa36b6082cbe2cd1867fe Signed-off-by: Damjan Marion <damarion@cisco.com>
2017-08-24Make VPP runtime directory configurableDamjan Marion1-8/+12
New startup config command: unix { runtime-dir /run/vpp } Also, adds recursive mkdir funtion for use in deifferent places like cli-config socket path and dpdk hugepage directory path. Change-Id: I1446ceab9c220c25804e73a743a3ebb383450124 Signed-off-by: Damjan Marion <damarion@cisco.com>
2017-07-06unix: mkdir VPP_RUN_DIR before opening a socket in itChris Luke1-0/+11
Change https://gerrit.fd.io/r/#/c/7230/ added a Unix domain CLI socket in the default startup.conf; however unless you had previously run VPP with the DPDK plugin enabled the directory that it is created in. /run/vpp, would not exist and startup would fail. This directory is typically hosted in a tmpfs ramdisk and is thus ephemeral. This patch adds a function that attempts to mkdir VPP_RUN_DIR and uses it in both the DPDK plugin and the CLI code if the CLI socket is to be created in that directory. Change-Id: Ibbf925819099dce2b5eb0fa238b9edca1036d6fd Signed-off-by: Chris Luke <chrisy@flirble.org>
2017-06-21Add option to create clib_socket with group write permissionsDamjan Marion1-1/+4
Also allow group write as default for CLI socket connections. Change-Id: I6af1f277f70581358cd9241bf0f5cb0752fe250f Signed-off-by: Damjan Marion <damarion@cisco.com>
2017-06-06vlib: add screen-256color CLI terminal typeDamjan Marion1-0/+1
Change-Id: Ia78e69e5e8ed18020314aef321b94ac37037799b Signed-off-by: Damjan Marion <damarion@cisco.com>
2017-05-23Add TAB-based auto-completion to the CLIYoann Desmouceaux1-0/+153
Hitting tab: - in the middle of a uniquely defined subcommand will expand the subcommand - in the middle of a non-uniquely defined (or empty) subcommand will display all possible subcommands, and possibly expand to the lowest common prefix Change-Id: Ib858eefdb0353cd2c3aad472799d15cd537455a0 Signed-off-by: Yoann Desmouceaux <ydesmouc@cisco.com>
2017-02-22VPP-635: CLI Memory leak with invalid parameterBilly McFall1-6/+16
In the CLI parsing, below is a common pattern: /* Get a line of input. */ if (!unformat_user (input, unformat_line_input, line_input)) return 0; while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) { if (unformat (line_input, "x")) x = 1; : else return clib_error_return (0, "unknown input `%U'", format_unformat_error, line_input); } unformat_free (line_input); The 'else' returns if an unknown string is encountered. There a memory leak because the 'unformat_free(line_input)' is not called. There is a large number of instances of this pattern. Replaced the previous pattern with: /* Get a line of input. */ if (!unformat_user (input, unformat_line_input, line_input)) return 0; while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) { if (unformat (line_input, "x")) x = 1; : else { error = clib_error_return (0, "unknown input `%U'", format_unformat_error, line_input); goto done: } } /* ...Remaining code... */ done: unformat_free (line_input); return error; } In multiple files, 'unformat_free (line_input);' was never called, so there was a memory leak whether an invalid string was entered or not. Also, there were multiple instance where: error = clib_error_return (0, "unknown input `%U'", format_unformat_error, line_input); used 'input' as the last parameter instead of 'line_input'. The result is that output did not contain the substring in error, instead just an empty string. Fixed all of those as well. There are a lot of file, and very mind numbing work, so tried to keep it to a pattern to avoid mistakes. Change-Id: I8902f0c32a47dd7fb3bb3471a89818571702f1d2 Signed-off-by: Billy McFall <bmcfall@redhat.com> Signed-off-by: Dave Barach <dave@barachs.net>
2016-12-28Reorganize source tree to use single autotools instanceDamjan Marion1-0/+2989
Change-Id: I7b51f88292e057c6443b12224486f2d0c9f8ae23 Signed-off-by: Damjan Marion <damarion@cisco.com>