summaryrefslogtreecommitdiffstats
path: root/tests/vty
Commit message (Collapse)AuthorAgeFilesLines
* logging/vty: fix: actually ignore deprecated logging commandsVadim Yanitskiy2019-11-213-0/+9
| | | | | | | | | | | | | | | | | | | | | | | 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
* vty: Return error if cmd returns CMD_WARNING while reading cfg filePau Espin Pedrol2019-10-283-0/+27
| | | | | | | Otherwise bad configurations can easily sneak in and produce unexpected behavior. Change-Id: Ic9c1b566ec4a459f03e6319cf369691903cf9d00
* vty: command.c: Fix: single-choice optional args are no longer passed ↵Pau Espin Pedrol2019-06-141-1/+1
| | | | | | | | | | | 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
* vty: command.c: Fix: multi-choice args are no longer passed incomplete to ↵Pau Espin Pedrol2019-06-141-6/+6
| | | | | | | | | | | 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
* vty: tests: Verify incomplete optional parameters are passed to vty funcsPau Espin Pedrol2019-06-142-0/+18
| | | | | | | | The test shows that in the case were "single0 on" is executed, VTY function should return complete "single0 one" but it doesn't. Related: OS#4045 Change-Id: Ib5b9dc07e2b280dc95011b3926afb1d490cadd81
* vty: command.c: Fix is_cmd_ambiguous() returning always 0Pau Espin Pedrol2019-06-111-3/+3
| | | | | | | | | | 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
* vty_transcript_test.vty: add choice auto-complete testsVadim Yanitskiy2019-06-061-0/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This patch is a result of discussion we had in [1]. The key idea is that libosmovty should properly auto-complete the commands containing choice, such as the following one: multi0 (one|two|three) [1] If9b0c0d031477ca87786aab5c269d00748e896c8 Right now, sending the following command: (osmo-foo-bar)# multi0 th would basically match the following vector: multi0 three however the resulting argv would be: ["multi0", "th"] Moreover, sending the following command: (osmo-foo-bar)# multi0 t would basically match the following vectors: multi0 two multi0 three because both start from 't', so the resulting argv would be: ["multi0", "t"] which is ambiguous! The expected output is: (osmo-foo-bar)# multi0 th ok argc=1 three (osmo-foo-bar)# multi0 t % Ambiguous command. This is going to be fixed in the follow up patches. Change-Id: I83c3aef813173952641035862c534ef16384780e
* vty: enable optional-multi-choice syntax: [(one|two)]Neels Hofmeyr2019-02-042-0/+24
| | | | | | | | | | | | | | | | | | | | | | | | | | Since very recently we sensibly handle commands like cmd ([one]|[two]|[three]) as optional multi-choice arguments. In addition, support the more obvious syntax of cmd [(one|two|three)] Internally, the tokens are mangled to [one] [two] and [three], which is how the rest of the code detects optional args, and makes sense in terms of UI: > cmd ? [one] [two] [three] (i.e. optional arguments are always shown in braces in '?' listings) Before this patch, commands defined with a syntax like [(one|two)], would lead to an assertion (shows as "multiple") during program startup. Change-Id: I952b3c00f97e2447f2308b0ec6f5f1714692b5b2
* vty: enable optional-multi-choice syntax: ([one]|[two])Neels Hofmeyr2019-02-041-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Add basic optional multi-choice argument support. The VTY detects optional arguments by square braces. > cmd ? [optional-arg] > cmd optional-arg ok > cmd ok However, within multi-choice args, these braces were so far not treated as optional: > list cmd2 ([one]|[two]|[three]) > cmd2 % Command incomplete In preparation for I952b3c00f97e2447f2308b0ec6f5f1714692b5b2 which will enable the more obvious syntax of cmd [(one|two)] for reasons of internal implementation, first support a syntax of cmd ([one]|[two]) The internal vty implementation always needs square braces around each option. There is currently no good way to prevent developers from defining braces inside multi-arguments, so it is easiest to allow and handle them: > list cmd2 ([one]|[two]|[three]) > cmd2 ok The VTY doesn't guard against a mix like cmd (one|[two]) With this patch, a multi-choice command is treated as optional iff the first element is in square brackets. The remaining elements' square brackets have no effect besides confusing the user. This is not explicitly checked against. In general, I would prefer to check all of these details, but the current VTY code with its endless code duplication and obscure string mangling just doesn't provide that luxury. There are numerous worse errors hidden in there. Change-Id: I9a8474bd89ddc2155c58bfca7bd038d586aaa60a
* add generic vty_transcript_test.c, vty_transcript_test.vtyNeels Hofmeyr2019-02-042-0/+283
| | | | | | | | I want to tweak general VTY features and need to cover with a transcript test to show the differences. Start by showing the current situation of optional and multi-choice arguments. Change-Id: I5a79c83fabd02aba6406b6e0d620969c4bd0cc1d
* vty: fix use-after-free and memleaks in is_cmd_ambiguous()Neels Hofmeyr2018-07-112-0/+81
| | | | | | | | | | | | | | | | | | | | | | | vty_test: add test against ambiguous cmd causing use-after-free and memory leaks. Add this test along with the fix, because the new test triggers the memory use-after-free and leaks, causing build failures. Add cmd_deopt_with_ctx() to allow passing a specific talloc ctx. is_cmd_ambiguous(): keep all cmd_deopt() allocations until the function exits. Add a comment explaining why. Before this, if a command matched an optional "[arg]" with square brackets, we would keep it in local var 'matched', but we would free the string it points to at the end of that loop iteration; upon encountering another match, we would attempt to strcmp against the freed 'matched'. Instead of adding hard-to-read and -verify free/alloc dances to keep the 'matched' accurately freed/non-freed/..., just keep all cmd_deopt() string allocated until done. Needless to say that this should have been implemented on a lower level upon inventing optional args, but at least this is fixing a program crash. Related: OS#33903390 Change-Id: Ia71ba742108b5ff020997bfb612ad5eb30d04fcd
* use osmo_init_logging2() with proper talloc ctxNeels Hofmeyr2018-04-061-3/+7
| | | | | | | | Ironically, when deprecating osmo_init_logging() in I216837780e9405fdaec8059c63d10699c695b360, I forgot to change the callers within libosmocore itself, i.e. in the various regression tests. Change-Id: Ia36c248f99353d5baaa2533f46a2f60a8579bdf8
* Fix/Update copyright notices; Add SPDX annotationHarald Welte2017-11-131-3/+5
| | | | | | | | Let's fix some erroneous/accidential references to wrong license, update copyright information where applicable and introduce a SPDX-License-Identifier to all files. Change-Id: I39af26c6aaaf5c926966391f6565fc5936be21af
* vty: install 'exit', 'end',... commands on *all* nodesNeels Hofmeyr2017-09-271-3/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | In many callers of the VTY API, we are lacking the vty_install_default() step at certain node levels. This creates nodes that lack the 'exit' command, and hence the only way to exit such a node is to restart the telnet session. Historically, the VTY looked for missing commands on the immediate parent node, and hence possibly found the parent's 'exit' command when the local node was missing it. That is why we so far did not notice the missing default commands. Furthermore, some callers call install_default() instead of vty_install_default(). Only vty_install_default() also includes the 'exit' and 'end' commands. There is no reason why there are two sets of default commands. To end this confusion, to catch all missing 'exit' commands and to prevent this from re-appearing in the future, simply *always* install all default commands implicitly when calling install_node(). In cmd_init(), there are some top-level nodes that apparently do not want the default commands installed. Keep those the way they are, by changing the invocation to new install_node_bare() ({VIEW,AUTH,AUTH_ENABLE}_NODE). Make both install_default() and vty_install_default() no-ops so that users of the API may still call them without harm. Do not yet deprecate yet, which follows in Icf5d83f641e838cebcccc635a043e94ba352abff. Drop all invocations to these two functions found in libosmocore. Change-Id: I5021c64a787b63314e0f2f1cba0b8fc7bff4f09b
* vty_test: add artificial node levels for better testingNeels Hofmeyr2017-09-2013-39/+440
| | | | | | | | | | | | | In vty_test, add three levels of parent nodes (level1, level2, level3) with each having a leaf child (child1, child2, child3). Use these to enhance the vty_test cfg files and test more diverse situations. The current VTY code expects a go_parent_cb() to be present, otherwise it will bump right back to the CONFIG_NODE, which will not work with more than one node level below the CONFIG_NODE. Hence provide a minimal go_parent_cb(). Change-Id: Ib9bcf58b655fbd85e196f363fb7d8305d7dfc997
* fix vty regression: empty parent nodeNeels Hofmeyr2017-09-203-0/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | The recent exit-by-indent patch breaks a VTY case where a node is entered but directly followed by a sibling or ancestor without listing any child nodes. Regression introduced by I24cbb3f6de111f2d31110c3c484c066f1153aac9. An example is a common usage in osmo-bts, where 'phy N' / 'instance N' is a parent node that is commonly left empty: phy 0 instance 0 bts 0 band 1800 Before this patch, this case produces the error: There is no such command. Error occurred during reading the below line: bts 0 Fix indentation parsing logic in command.c to accomodate this case. Add a unit test for empty parent node. Change-Id: Ia0880a17ae55accb092ae8585cc3a1bec9986891
* VTY: implicit node exit by de-indenting, not parent lookupNeels Hofmeyr2017-09-1912-0/+82
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Note: This will break users' config files if they do not use consistent indenting. (see below for a definition of "consistent".) When reading VTY commands from a file, use indenting as means to implicitly exit child nodes. Do not look for commands in the parent node implicitly. The VTY so far implies 'exit' commands if a VTY line cannot be parsed on the current node, but succeeds on the parent node. That is the mechanism by which our VTY config files do not need 'exit' at the end of each child node. We've hit problems with this in the following scenarios, which will show improved user experience after this patch: *) When both a parent and its child node have commands with identical names: cs7 instace 0 point-code 1.2.3 sccp-address osmo-msc point-code 0.0.1 If I put the parent's command below the child, it is still interpreted in the context of the child node: cs7 instace 0 sccp-address osmo-msc point-code 0.0.1 point-code 1.2.3 Though the indenting lets me assume I am setting the cs7 instance's global PC to 1.2.3, I'm actually overwriting osmo-msc's PC with 1.2.3 and discarding the 0.0.1. *) When a software change moves a VTY command from a child to a parent. Say 'timezone' moved from 'bts' to 'network' level: network timezone 1 2 Say a user still has an old config file with 'timezone' on the child level: network bts 0 timezone 1 2 trx 0 The user would expect an error message that 'timezone' is invalid on the 'bts' level. Instead, the VTY finds the parent node's 'timezone', steps out of 'bts' to the 'network' level, and instead says that the 'trx' command does not exist. Format: Consistent means that two adjacent indenting lines have the exact same indenting characters for the common length: Weird mix if you ask me, but correct and consistent: ROOT <space>PARENT <space><tab><space>CHILD <space><tab><space><tab><tab>GRANDCHILD <space><tab><space><tab><tab>GRANDCHILD2 <space>SIBLING Inconsistent: ROOT <space>PARENT <tab><space>CHILD <space><space><tab>GRANDCHILD <space><tab><tab>GRANDCHILD2 <tab>SIBLING Also, when going back to a parent level, the exact same indenting must be used as before in that node: Incorrect: ROOT <tab>PARENT <tab><tab><tab>CHILD <tab><tab>SIBLING As not really intended side effect, it is also permitted to indent the entire file starting from the root level. We could guard against it but there's no harm: Correct and consistent: <tab>ROOT <tab><tab>PARENT <tab><tab><tab><tab>CHILD <tab><tab>SIBLING Implementation: Track parent nodes state: whenever a command enters a child node, push a parent node onto an llist to remember the exact indentation characters used for that level. As soon as the first line on a child node is parsed, remember this new indentation (which must have a longer strlen() than its parent level) to apply to all remaining child siblings and grandchildren. If the amount of spaces that indent a following VTY command are less than this expected indentation, call vty_go_parent() until it matches up. At any level, if the common length of indentation characters mismatch, abort parsing in error. Transitions to child node are spread across VTY implementations and are hard to change. But transitions to the parent node are all handled by vty_go_parent(). By popping a parent from the list of parents in vty_go_parent(), we can also detect that a command has changed the node without changing the parent, hence it must have stepped into a child node, and we can push a parent frame. The behavior on the interactive telnet VTY remains unchanged. Change-Id: I24cbb3f6de111f2d31110c3c484c066f1153aac9
* VTY: interactive: never look for matching commands on parent nodeNeels Hofmeyr2017-09-082-7/+3
| | | | | | | | | | | | | | | | | | | | | | For interactive telnet VTY, remove the implicit move up to the parent node when a command did not succeed on the current node level. When reading config files, this behavior was useful to allow skipping explicit 'exit' commands. (A different patch deals with that.) In the telnet VTY, this behavior was never necessary. Explicit 'exit' commands can move to the parent node, and typically uninformed users expect to require that. On a telnet VTY, counting indents like for reading config files is not an option: a user will always type from the first column or may paste some leading spaces without intended meaning. After this patch, it is thus no longer possible to paste a complete config across several node levels directly to a telnet session, unless it contains 'exit' commands. Change-Id: Id73cba2dd34676bad8a130e9c45e67a272f19588
* vty: cleanup logging functionsMax2017-05-091-1/+1
| | | | | | | | | | | | * remove unused parameter from logging_vty_add_cmds() * mark log level descriptors static * change internal static function int check_log_to_target() to more appropriate bool should_log_to_target() * deprecate log_vty_command_*() from public API as it should only be used by logging_vty_add_cmds() Change-Id: I0e9ddd7ba3ce211302d99a3494eb408907a2916e Related: OS#71
* stats/test: Add tests to check VTY configurationJacob Erlbeck2015-08-222-0/+194
| | | | | | | This commit adds tests to verify the stats related VTY configuration commands. Sponsored-by: On-Waves ehf
* vty/test: Refactor vty creation/deletion into separate functionsJacob Erlbeck2015-08-221-29/+46
| | | | | | | | | | Currently this is part of the only test function that uses the vty directly. In preperation for more such test cases, this commit moves this code into separate functions. Sponsored-by: On-Waves ehf
* stats/vty: Add stats configurationJacob Erlbeck2015-10-291-3/+3
| | | | | | | | | | | | | | | | | | | | | | | This commit provides stats configuration similar to the log configuration. The following vty commands are added to the config node: stats reporter statsd Create/Modify a statsd reporter no stats reporter statsd Remove a statsd reporter To actually configure a reporter, the config-stats node is entered when the "stats reporter" command has succeeded. The following new vty commands are available there: local-ip ADDR Set the IP address to which we bind locally no local-ip Do not bind to a certain IP address remote-ip ADDR Set the remote IP address to which we connect remote-port <1-65535> Set the remote port to which we connect prefix PREFIX Set the item/counter name prefix no prefix Do not use a prefix enable Enable the reporter disable Disable the reporter Sponsored-by: On-Waves ehf
* vty: Make vty_event dispatch signals and use it in the testcaseHolger Hans Peter Freyther2013-10-101-4/+17
| | | | | | | | | The testcase didn't work on Ubuntu 12.04 because vty_create will directly call vty_event (e.g. not through the plt). This means that the approach to override vty_event in the testcase failed. Use the signal interface of libosmocore and make the testcase use it. The signals can be generally useful as well.
* vty: Fix compiler warning in the testHolger Hans Peter Freyther2013-09-101-1/+2
|
* vty: Add vty_install_default() and use for the vty nodesJacob Erlbeck2013-09-082-0/+167
| | | | | | | | | | | This adds the vty_install_default() function that is basically the install_default() function plus the registration of the commands 'exit' and 'end'. The latter is only provided in subnodes of ENABLED_NODE and CONFIG_NONE. The VTY test program is extended to check these commands. Ticket: OW#952
* vty: Support multi-char separators and end stringsJacob Erlbeck2013-08-061-1/+1
| | | | | In vty_cmd_string_from_valstr() include the real string lengths of the sep and end arguments into the buffer size calculation.
* vty: Fix misusage of snprintf in vty/utils.cJacob Erlbeck2013-08-062-0/+55
Compiled with ubuntu 1204 (precise), where -Wformat-security is enabled by -Wall. Test yields ok, but the current implementation doesn't properly support multi-character separators and end strings. So the test output is truncated. Addresses: utils.c: In function 'vty_cmd_string_from_valstr': utils.c:84:2: warning: format not a string literal and no format arguments [-Wformat-security] utils.c:84:2: warning: format not a string literal and no format arguments [-Wformat-security] utils.c:108:2: warning: format not a string literal and no format arguments [-Wformat-security] utils.c:108:2: warning: format not a string literal and no format arguments [-Wformat-security]