path: root/src/vty
AgeCommit message (Collapse)AuthorFilesLines
2020-05-18enable vty xml dumping to stdoutNeels Hofmeyr1-25/+60
Allow dumping the VTY XML reference (for generating manuals) to a normal FILE* stream instead of a vty output buffer. We currently generate the VTY reference by starting the client program, connecting to the VTY telnet and dumping the reference. That is weirdly convoluted, especially since there has to be a valid config file that successfully starts up a minimal set of external links before the reference can be generated. IMO we should have dumped the XML reference to stdout from the start, and never to a VTY session. With this patch, it is trivial to generate the XML VTY reference by a commandline switch. The client program will set up the entire VTY, and immediately after parsing the cmdline options but before parsing a config file, just dumps the reference and doesn't even start establishing local ports. That would allow generating the XML reference on the fly during the build process of the manuals, without the need of a docker container or somesuch. A first implementation of such a commandline switch is `osmo-bsc -X`, added in I316efedb2c1652791434ecf14a1e261367cd2fb7 This patch jumps through a bit of a hoop to still allow dumping to a VTY buffer without code dup, to still allow dumping the XML reference through telnet VTY, until all our programs have implemented an -X switch (TM). Change-Id: Ic74bbdb6dc5ea05f03c791cc70184861e39cd492
2020-05-09stats: Support regular stats flushAlexander Chemeris1-0/+26
Reliable monitoring requires regular flush of all stat values, even if they have not changed. Otherwise (1) the monitoring app has to maintain state and (2) can go out of sync if it's restarted while the app is still running. Change-Id: I04f1e7bdf0d6f20e4f15571e94191de61c47ddad
2020-05-09stats: Move cfg_stats_interval_cmd() function.Alexander Chemeris1-18/+17
cfg_stats_interval_cmd() function was (probably mistakenly) inserted between cfg_stats_reporter_statsd_cmd() and cfg_no_stats_reporter_statsd_cmd() function which makes no sense. Move it below the cfg_no_stats_reporter_log_cmd() to follow the order of the osmo_stats_vty_add_cmds() function calls. Change-Id: I1ecec7025e95cf5ffc21ae3b1c75cf6da8c58de2
2020-02-06tdef_vty: do not enforce enum 'node_type' in osmo_tdef_vty_groups_init()Vadim Yanitskiy1-3/+3
Some osmo-* applications may need to use their own VTY node as a parent for the timer configuration commands. Therefore it makes more sense to use 'unsigned int' instead of 'enum node_type'. Let's also clarify that osmo_tdef_vty_groups_init() accepts parent node for configuration commands only: 'parent_node' -> 'parent_cfg_node'. Change-Id: Ifb4c406c85d76a25fc53fc235484599aa87dc77c
2020-01-03logging_vty.c: Avoid acquiring log tgt lock in logging level cmd when not neededPau Espin Pedrol1-4/+4
Change-Id: Ia6780221174070cee408625e24513f2c11cc9dfc
2020-01-02Bump version: → Espin Pedrol1-1/+1
Change-Id: I5698bfe45467a8b0e44549105aaf27b8da500de8
2019-11-30libosmovty: simplify condition checking vty->fd in vty_close()Vadim Yanitskiy1-2/+2
On POSIX systems, standard I/O streams - stdin, stdout, and stderr, always have default file descriptors 0, 1, and 2 respectively. Change-Id: Ied35d142af0ba0f5ad78975b8f22c35b32d6ff71
2019-11-30libosmovty: properly initialize vty->fd in vty_new()Vadim Yanitskiy1-0/+1
Since we're using talloc_zero(), vty->fd is initialized with 0, which corresponds to stdin. Let's set an invalid value to prevent potential bugs like the one fixed by the recent change [1]. [1] Icdeaea67a06da3a2f07b252e455629559ecc1829 Change-Id: Iec15649781317a23e13d2c2840a8f672050f76c1
2019-11-24vty: track parent nodes also for telnet sessionsNeels Hofmeyr1-30/+24
Keep track of parent nodes and go back hierarchically, not only for .cfg file reading, but also for telnet VTY sessions. A long time ago cfg file parsing was made strictly hierarchical: node exits go back to parent nodes exactly as they were entered. However, live telnet VTY sessions still lacked this and depended on the go_parent_cb(). From this commit on, implementing a go_parent_cb() is completely optional. The go_parent_cb() no longer has the task to determine the correct parent node, neither for cfg files (as already the case before this patch) nor for telnet VTY sessions (added by this patch). Instead, a go_parent_cb() implementation can merely take actions it requires on node exits, for example applying some config when leaving a specific node. The node value that is returned by the go_parent_cb() and the vty->node and vty->index values that might be set are completely ignored; instead the implicit parent node tracking determines the parent and node object. As a side effect, the is_config_node() callback is no longer needed, since the VTY now always implicitly knows when to exit back to the CONFIG_NODE. For example, osmo_ss7_is_config_node() could now be dropped, and the osmo_ss7_vty_go_parent() could be shortened by five switch cases, does no longer need to set vty->node nor vty->index and could thus be shortened to: int osmo_ss7_vty_go_parent(struct vty *vty) { struct osmo_ss7_asp *asp; struct osmo_xua_server *oxs; switch (vty->node) { case L_CS7_ASP_NODE: asp = vty->index; /* If no local addr was set */ if (!asp->cfg.local.host_cnt) { asp->cfg.local.host[0] = NULL; asp->cfg.local.host_cnt = 1; } osmo_ss7_asp_restart(asp); break; case L_CS7_XUA_NODE: oxs = vty->index; /* If no local addr was set, or erased after _create(): */ if (!oxs->cfg.local.host_cnt) osmo_ss7_xua_server_set_local_host(oxs, NULL); if (osmo_ss7_xua_server_bind(oxs) < 0) vty_out(vty, "%% Unable to bind xUA server to IP(s)%s", VTY_NEWLINE); break; } return 0; } Before parent tracking, every program was required to write a go_parent_cb() which has to return every node's parent node, basically a switch() statement that manually traces the way back out of child nodes. If the go_parent_cb() has errors, we may wildly jump around the node tree: a common error is to jump right out to the top config node with one exit, even though we were N levels deep. This kind of error has been eliminated for cfg files long ago, but still exists for telnet VTY sessions, which this patch fixes. This came up when I was adding multi-level config nodes to osmo-hlr to support Distributed GSM / remote MS lookup: the config file worked fine, while vty node tests failed to exit to the correct nodes. Change-Id: I2b32b4fe20732728db6e9cdac7e484d96ab86dc5
2019-11-21logging/vty: fix: do not close stderr in vty_close()Vadim Yanitskiy1-1/+1
Since Icdeaea67a06da3a2f07b252e455629559ecc1829, we use stderr for printing warnings while parsing the VTY configuration files. Make sure we do not close() stderr. Otherwise stderr logging gets broken. Change-Id: I6ecc85555d102f5911d50ed5ac54933c766fa84d Fixes: Icdeaea67a06da3a2f07b252e455629559ecc1829
2019-11-21logging/vty: fix vty_read_file(): do not write warnings to stdinVadim Yanitskiy1-1/+5
Setting vty->fd to 0 is a bad idea, which may cause the process to write() warnings to its own _stdin_ (yes, it's possible). For example, when a configuration file contains deprecated logging commands. Let's use stderr by default. Change-Id: Icdeaea67a06da3a2f07b252e455629559ecc1829
2019-11-21logging/vty: fix: actually ignore deprecated logging commandsVadim Yanitskiy1-1/+1
We shall not prevent programs from starting if their configuration files contain deprecated 'logging level ...' commands. Just print a warning and return CMD_SUCCESS instead of CMD_WARNING. While writing a unit test, another funny bug has been uncovered. Parsing of a deprecated command indeed triggers a deprecation warning, originated from libosmovty's log_deprecated_func(). This function simply calls vty_out(), but... Since the invocation of the vty_out() happens _before_ the VTY is initialized, the process is actually writing that warning to its own stdin! Most likely, because we use talloc_zero() to allocate a new instance of struct 'vty'. As a side effect, the evil warning magically appears in the output of 'make check', breaking the test statistics. Let's work around this bug for now by redirecting stdin to /dev/null. Change-Id: Ia934581410cd41594791d4e14ee74c16abe1009a Fixes: Ic9c1b566ec4a459f03e6319cf369691903cf9d00
2019-11-21logging/vty: use LOG_LEVEL_ARGS in logging_vty_add_deprecated_subsys()Vadim Yanitskiy1-2/+1
Change-Id: I862c3cce0147ee8cf4013501132584ea09c58b53
2019-11-20logging/vty: do not print deprecated logging commands to stdoutVadim Yanitskiy1-1/+0
Yes, we don't really need to poison stdout, as some osmo-* binaries (like osmo-gapk) may want to use it for non-logging purposes. This printf() call looks like a debugging leftover. Change-Id: Ida35865b1c0bb3d3567918f8e89c6551c6b34103
2019-10-28vty: Return error if cmd returns CMD_WARNING while reading cfg filePau Espin Pedrol1-2/+1
Otherwise bad configurations can easily sneak in and produce unexpected behavior. Change-Id: Ic9c1b566ec4a459f03e6319cf369691903cf9d00
2019-10-11vty: Fix go_parent_cb not called for indented nodes at end of cfg filePau Espin Pedrol1-0/+4
Without this patch, for instance in this cfg file below, go_parent_cb is not called for nodes such as "listen" and "cs7": """ line vty no login cs7 instance 0 xua rkm routing-key-allocation dynamic-permitted listen m3ua 2905 accept-asp-connections dynamic-permitted local-ip """ Related: OS#3608 Change-Id: Ia6d88c0e63d94ba99e950da6efbc4c1871070012
2019-10-09logging: Introduce mutex API to manage log_target in multi-thread envsPau Espin Pedrol1-88/+113
log_enable_multithread() enables use of locks inside the implementation. Lock use is disabled by default, this way only multi-thread processes need to enable it and suffer related complexity/performance penalties. Locks are required around osmo_log_target_list and items inside it, since targets can be used, modified and deleted by different threads concurrently (for instance, user writing "logging disable" in VTY while another thread is willing to write into that target). Multithread apps and libraries aiming at being used in multithread apps should update their code to use the locks introduced here when containing code iterating over osmo_log_target_list explictly or implicitly by obtaining a log_target (eg. osmo_log_vty2tgt()). Related: OS#4088 Change-Id: Id7711893b34263baacac6caf4d489467053131bb
2019-10-07vty: Optionally Set/replace cfg file during cmd 'write file'Pau Espin Pedrol1-2/+6
This way if the process is started with no file associated (eg. no -c param and default cfg path doesn't exist), config can be later saved into a file by passing the parameter. Otherwise, until now this message was displayed: Can't save to configuration file, using vtysh. Related: OS#4024 Change-Id: I38edcf902a08b6bd0ebb9aa6fc1a7041421af525
2019-10-07tdef: Introduce min_val and max_val fieldsPau Espin Pedrol1-7/+28
This is useful for timers expected to have a range of valid or expected values. Validation is done at runtime when timer values are set by the app or by the user through the VTY. Related: OS#4190 Change-Id: I4661ac41c29a009a1d5fc57d87aaee6041c7d1b2
2019-09-02MAXPATHLEN set if not definedRuben Undheim2-0/+10
Change-Id: I1dce8ace228814b5a7246a00b31309ab9461d266
2019-08-30fix: vty crash by logging during VTY_CLOSED event handlingNeels Hofmeyr1-3/+3
When a VTY closes, dispatch the VTY_CLOSED signal before tearing down the VTY buffer and fd. In particular this fixes: - a crash during telnet_close_client(), invoked by the VTY_CLOSED event, which logs to DLGLOBAL and uses vty->obuf that, so far, vty_close() had already unallocated earlier (OS#4164). - the logging about closing a telnet session so far logged: DLGLOBAL INFO Closing telnet connection r=NULL<->l=NULL By dispatching the VTY_CLOSED event while the fd is still valid, we instead get the actual connection IP address and port being closed: DLGLOBAL INFO Closing telnet connection r=<->l= Related: OS#4164 Change-Id: I1d235cbfbfb9aaf411316642c7bcfac12106df44
2019-08-20vty: Register logp cmd next to logging commandsPau Espin Pedrol1-2/+3
This way it's easier by osmo_verify_transcript_vty.py to skip and avoid breaking existent test in osmo-hlr. Fixes: d0b3b9edac978c91bf84aa2537aa24426685b1fb Change-Id: Iab9423661e4f4eefca2e3d02b60a43f913ed92a3
2019-08-13add vty logp command to echo on all log targetsNeels Hofmeyr1-0/+41
When reading SUT logs resulting from TTCN3 runs, it can be hard to figure out which log section corresponds to which test code. Add a 'logp' command on VIEW and ENABLE nodes that simply echos an arbitrary message on log output, useful to set markers / explanations from the TTCN3 code, which then appear in all log outputs and can make it trivial to figure out which log section is interesting. logging_vty_test# logp lglobal notice This is the log message DLGLOBAL NOTICE This is the log message From TTCN3, could be used like this, e.g. in BSC_Tests.ttcn: private function f_logp(charstring log_msg) runs on MSC_ConnHdlr { // log on TTCN3 log output log(log_msg); // log in stderr log f_vty_transceive(BSCVTY, "logp lglobal notice " & log_msg); } ... f_logp("f_probe_for_handover(" & log_label & "): Ending the test: Handover Failure stops the procedure."); Change-Id: Ife5dc8999174c74e0d133729284fe526d6eaf8d9
2019-08-06Bump version: → Espin Pedrol1-1/+1
Change-Id: I05dd1f2725e05f856f1d27c9201a0005de101b8f
2019-08-02Get rid of osmo_str_tolower() use inside libosmocore codePau Espin Pedrol1-11/+13
There's no real good reason for using that function (static buffer) instead of osmo_str_tolower_buf(local buffer), so let's use the later. In any case, we get rid of TLS variables in those places, which is a performance improvement. It will also allow later shrinking of those buffers if we decide to define maximum logging category and level name length. Change-Id: I2e99de1142020e4d80ef0a094e4e751f7903f5f9
2019-07-30vty/vty.c: the command buffer can be accessed directlyVadim Yanitskiy1-7/+7
Change-Id: Ic6d7d68e9a559a6fb5bd6eaf6eccceae51e7ed39
2019-07-30vty/vty.c: fix vty_read(): prevent further heap-buffer overrunVadim Yanitskiy1-0/+2
After reading data from the socket, assigned to a given VTY, we need to '\0'-terminate the received string. Otherwise, further access to that string, stored in a heap buffer vty->buf, would lead to a heap overrun. == How to reproduce? $ python -c "print 'A' * 512" | telnet $HOST $PORT ==21264==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x6190000211e0 at pc 0x000000435d2f bp 0x7ffc06c7add0 sp 0x7ffc06c7a578 READ of size 1025 at 0x6190000211e0 thread T0 #0 0x435d2e in __interceptor_strlen (/usr/local/bin/osmo-msc+0x435d2e) #1 0x7fb95bfa5624 in talloc_strdup (/usr/lib/x86_64-linux-gnu/libtalloc.so.2+0x6624) #2 0x7fb95c1be2bc in vty_hist_add /opt/osmocom/libosmocore/src/vty/vty.c:578 #3 0x7fb95c1be2bc in vty_execute /opt/osmocom/libosmocore/src/vty/vty.c:703 #4 0x7fb95c1be2bc in vty_read /opt/osmocom/libosmocore/src/vty/vty.c:1425 #5 0x7fb95c1bfd78 in client_data /opt/osmocom/libosmocore/src/vty/telnet_interface.c:157 #6 0x7fb95b90bd33 in osmo_fd_disp_fds /opt/osmocom/libosmocore/src/select.c:223 #7 0x7fb95b90bd33 in osmo_select_main /opt/osmocom/libosmocore/src/select.c:263 #8 0x5006cc in main /opt/osmocom/osmo-msc/src/osmo-msc/msc_main.c:723:3 #9 0x7fb959935f44 in __libc_start_main /build/eglibc-xkFqqE/eglibc-2.19/csu/libc-start.c:287 #10 0x4226fb in _start (/usr/local/bin/osmo-msc+0x4226fb) == Why exactly 512? Because the initial size of the heap buffer is 512 (see VTY_BUFSIZ). Later on it can be realloc()ated, so X > 512 should also work. Found using AddressSanitizer and Radamsa [1] fuzzer. [1] https://gitlab.com/akihe/radamsa Change-Id: I82f774ad18d0e555eb8f3590a519946d9c583c78
2019-07-30vty/telnet_interface.c: log connection accept() / close() eventsVadim Yanitskiy1-0/+12
Unfortunately, osmo_sock_get_name_buf() fails in telnet_close_client(): DLGLOBAL INFO telnet_interface.c:130 Closing telnet connection <error-in-getsockname> because getsockname(), getpeername(), and even close() fail with: "Bad file descriptor". This looks like a bug of the existing code. Change-Id: I77b31abfa159d2f269deaa5a08d94b7bbba7d23c
2019-07-30vty/logging_vty.c: fix writing of 'print category-hex'Vadim Yanitskiy1-0/+2
Change-Id: I33837f0fac1afe83596fa600916abc05ecb8c356
2019-07-27vty/telnet_interface.c: avoid unneeded initializationVadim Yanitskiy1-1/+1
Unconditional initialization follows the structure definition, so there is no need to do it twice. This prevents compiler from warning about potential errors. Change-Id: If9fd2826f132dfa203dda62940d93dbdfcfd92ac
2019-07-27vty/telnet_interface.c: use DLGLOBAL logging sub-systemVadim Yanitskiy1-2/+2
Change-Id: I1564f4714a33d36792e4982deb8f19d1b740dc0c
2019-07-25stats_vty: Add verb to sentence for show asciidoc countersDaniel Willmann1-1/+1
Change-Id: Ib444383d2074ddb89b3fe5bbf198bcbfabd7057f
2019-06-25vty: Simplify char escaping in asciidoc outputPau Espin Pedrol1-9/+4
Change-Id: I7df6858bb98abffc1d5bf420f991ae5854b24638
2019-06-19vty: Remove trailing whitespace in output from show asciidocPau Espin Pedrol1-2/+2
Change-Id: Ifb3115c7488fbcf082cc9b92abc25cf7c46064e0
2019-06-14vty: command.c: Fix: single-choice optional args are no longer passed ↵Pau Espin Pedrol1-5/+14
incomplete to vty func For instance, take command "single0 [one]": If user executes "single0 on", VTY func will receive argv[0]="one" instead of argv[0]="on". Related: OS#4045 Change-Id: I5f4e2d16c62a2d22717989c6acc77450957168cb
2019-06-14vty: command.c: Fix: multi-choice args are no longer passed incomplete to ↵Pau Espin Pedrol1-7/+44
vty func For instance, take command "multi0 (one|two|three)": If user executes "multi0 tw", VTY func will receive argv[0]="two" instead of argv[0]="tw". Fixes: OS#4045 Change-Id: I91b6621ac3d87fda5412a9b415e7bfb4736c8a9a
2019-06-14vty: command.c: Get rid of big indentation blockPau Espin Pedrol1-30/+30
This block will become bigger in forthcoming commits. Change-Id: Ibc1494014b1e77ce10950f7268a44d2d2091a6f2
2019-06-14command.c: Improve return check condition in cmd_execut_command_real()Pau Espin Pedrol1-2/+2
Check against MAX argc is changed to == since it cannot be incremented twice without passing the check. Change-Id: Ia330e475989fda863bedcc3cbf94deaf8dd83037
2019-06-12vty: command.c: Get rid of huge indentation blockPau Espin Pedrol1-91/+94
Huge conditional block inside for loop is negated in this patch together with a "continue" keyword, similar to what was already done recently in 4742526645d6137dd90ef369f0415afdb91736dc. Change-Id: I803c4ed38e9ab09bf929528c75a60e6f65da3928
2019-06-12cosmetic: vty: command.c: Use upper case for enum match_type value namesPau Espin Pedrol1-101/+101
Makes code easier to follow because enum values no longer look like variables. Change-Id: Ib6e9592c5962d047869a280c10f9b557fae6f435
2019-06-11vty: command.c: Fix is_cmd_ambiguous() returning always 0Pau Espin Pedrol1-5/+5
inner block defined variable "enum match_type ret" was being masking outter block variable "int ret = 0". The ret variable was being given non zero values only inside the inner block, so that change was done on the inner variable and not the outer one, which is returned. Fixes: 5314c513f23688462d7f7937e5ae5e0d5cd4548e Change-Id: Iec87d7db49a096d07e38ff8a060b923a52bfd6ba
2019-06-11vty: command.c: Get rid of huge indentation blockPau Espin Pedrol1-84/+87
Huge conditional block inside foor loop is negated in this patch together with a "continue" keyword. Change-Id: I9715734ed276f002fdc8c3b9742531ad36b2ef9e
2019-06-01vty/command.c: cosmetic: add missing curly bracketsVadim Yanitskiy1-2/+4
Otherwise it's a bit hard to read the code. Change-Id: I807ec71cfb67976251be844cdb2d2776b1837438
2019-05-27tdef: Fix license: GPLv2+ instead of AGPLv3+Harald Welte1-4/+5
libosmo{core,gsm,vty} code is GPLv2+. The tdef code originated in osmo-msc.git and was moved here without changing the license. That was a mistake, it always was meant to be under GPLv2-or-later after moving to libosmocore.git. Copyright is with sysmocom, so I as the managing director can approve the license change. Change-Id: Ie483ff6f6ea0a56c477649677b4b163c49df11d7
2019-05-07Bump version: → Espin Pedrol1-1/+1
Change-Id: I351411ca5913c8b40f23287ec7c9ebfe11bd2bb0
2019-05-03add vty_is_active()Neels Hofmeyr1-0/+10
For async callbacks it is useful to determine whether a given VTY pointer is still valid. For example, in osmo-msc, a silent call can be triggered by VTY, which causes a Paging. The paging_cb then writes to the VTY console that the silent call has succeeded. Unless the telnet vty session has already ended, in which case osmo-msc crashes; e.g. from an osmo_interact_vty.py command invocation. With this function, osmo-msc can ask whether the vty pointer passed to the paging callback is still active, and skip vty_out() if not. Change-Id: I42cf2af47283dd42c101faae0fac293c3a68d599
2019-04-11add osmo_str_startswith()Neels Hofmeyr1-11/+1
Move from a static implementation in tdef_vty.c to utils.c, I also want to use this in osmo-msc. The point is that the telnet VTY allows unambiguous partly matches of keyword args. For example, if I have a command definition of: compare (apples|oranges) then it is perfectly legal as for the vty parser to write only compare app One could expect the VTY to then pass the unambiguous match of "apples" to the parsing function, but that is not the case. Hence a VTY function implementation is faced with parsing a keyword of "app" instead of the expected "apples". This is actually a very widespread bug in our VTY implementations, which assume that exactly one full keyword will always be found. I am now writing new commands in a way that are able to manage only the starts of keywords. Arguably, strstr(a, b) == a does the same thing, but it searches the entire string unnecessarily. Change-Id: Ib2ffb0e9a870dd52e081c7e66d8818057d159513
2019-04-11vty/talloc_ctx_vty.c: use REG_NOSUB flag of regcomp()Vadim Yanitskiy1-1/+1
We don't need to know position of matches: just yes or no. This change would save some computation power. Change-Id: Id55ffe64cc1a35dd83f61dbb0f9828aa676696f9
2019-04-11vty/talloc_ctx_vty.c: allocate walk_cb_params on stack, not heapVadim Yanitskiy1-43/+15
There is no need to allocate struct 'walk_cb_params' dynamically. Change-Id: I96f25f1ddb36b19b12055deaeeb6f58e59180e72
2019-03-21select: Rename BSC_FD_* constants to OSMO_FD_*Harald Welte1-8/+8
The naming of these constants dates back to when the code was private within OpenBSC. Everything else was renamed (bsc_fd -> osmo_fd) at the time, but somehow the BSC_FD_* defines have been missed at the time. Keep compatibility #defines around, but allow us to migrate the applications to a less confusing naming meanwhile. Change-Id: Ifae33ed61a7cf0ae54ad487399e7dd2489986436