summaryrefslogtreecommitdiff
path: root/lib/command_match.c
AgeCommit message (Collapse)Author
2019-10-07lib: reject leading 0 in ipv4 decimal quadQuentin Young
inet_pton() is used to parse ipv4 addresses internally, therefore FRR does not support octal notation for quads. The ipv4 cli token validator should make sure that str2prefix() can parse tokens it allows, and str2prefix uses inet_pton, so we have to disallow leading zeros in ipv4 quads. In short, 1.1.1.01 is no longer valid and must be expressed as 1.1.1.1. Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2019-08-06*: fix ctype (isalpha & co.) castsDavid Lamparter
The correct cast for these is (unsigned char), because "char" could be signed and thus have some negative value. isalpha & co. expect an int arg that is positive, i.e. 0-255. So we need to cast to (unsigned char) when calling any of these. Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2019-05-29lib, zebra: remove uses of strncpyQuentin Young
This removes the last removable uses of strncpy in FRR. Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2018-10-02*: list_delete_and_null() -> list_delete()David Lamparter
Signed-off-by: David Lamparter <equinox@diac24.net>
2018-09-12lib vtysh zebra: variable shadowing fixesF. Aragon
Signed-off-by: F. Aragon <paco@voltanet.io>
2018-06-27lib: null check (2) (Coverity 1451361)paco
Additional correction to fa3016309b33395c02cf10e7e198517c5b81e55a Signed-off-by: F. Aragon <paco@voltanet.io>
2018-06-20bgpd, lib: null check (Coverity 1436344, 1451361)paco
Signed-off-by: F. Aragon <paco@voltanet.io>
2018-04-13lib: add asserts on returned matcher valsQuentin Young
These asserts verify that the status correlates with the expected result and fixes a clang-analyze warning. Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2018-01-11lib, bgpd: fixup use of of CMD_ARGC_MAXQuentin Young
The constant to limit # of allowed cli tokens on any one line was defined in multiple places, all inconsistent with each other. Fix. Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2017-10-05*: Convert list_delete(struct list *) to ** to allow nullingDonald Sharp
Convert the list_delete(struct list *) function to use struct list **. This is to allow the list pointer to be nulled. I keep running into uses of this list_delete function where we forget to set the returned pointer to NULL and attempt to use it and then experience a crash, usually after the developer has long since left the building. Let's make the api explicit in it setting the list pointer to null. Cynical Prediction: This code will expose a attempt to use the NULL'ed list pointer in some obscure bit of code. Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2017-09-14*: support keywords that begin with uppercase letterDaniel Walton
Signed-off-by: Daniel Walton <dwalton@cumulusnetworks.com> VARIABLE tokens must be all uppercase, this allows us to support WORD tokens that begin with an uppercase letter. The "Null0" keyword is an example of where this is needed. The only VARIABLE we had that wasn't already all uppercase was ASN:nn_or_IP-address:nn
2017-09-13lib, doc: increase maximum cli tokensQuentin Young
When matching user input against a CLI graph, we keep a stack of tokens matched. Stack size was limited to 64, making the effective number of tokens that could be entered on a line 64. This is too limiting in some circumstances, so bump it to 256 (and document it). Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2017-08-25lib: remove static variable from cli matcherQuentin Young
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2017-08-25lib: fix rare bug in ambiguous command resolutionQuentin Young
In certain situations, the CLI matcher would not handle ambiguous commands properly. If it found an ambiguous result in a lower subgraph, the ambiguous result would not correctly propagate up to previous frames in the resolution DFS as ambiguous; instead it would propagate up as a non-match, which could subsequently be overridden by a partial match. Example CLI space: show ip route summary show ip route supernet-only show ipv6 route summary Entering `show ip route su` would result in an ambiguous resolution for the `show ip route` subgraph but would propagate up to the `show ip` subgraph as a no-match, allowing `ip` to partial-match `ipv6` and execute that command. In this example entering `show ip route summary` would disambiguate the `show ip` subgraph. So this bug would only appear when entering input that caused ambiguities in at least two parallel subgraphs. Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2017-08-11lib: add CLI token for 48-bit mac addressesQuentin Young
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2017-07-17*: reindentreindent-master-afterwhitespace / reindent
indent.py `git ls-files | pcregrep '\.[ch]$' | pcregrep -v '^(ldpd|babeld|nhrpd)/'` Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2017-07-14*: fix GCC 7 switch/case fallthrough warningsDavid Lamparter
Need a comment on these. Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2017-05-15*: make consistent & update GPLv2 file headersDavid Lamparter
The FSF's address changed, and we had a mixture of comment styles for the GPL file header. (The style with * at the beginning won out with 580 to 141 in existing files.) Note: I've intentionally left intact other "variations" of the copyright header, e.g. whether it says "Zebra", "Quagga", "FRR", or nothing. Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2017-05-15lib: cli: fix IPv6 address partial matchingDavid Lamparter
A partially-entered IPv6 address would never return a "partly_match", meaning some possible completions weren't listed by the matcher. This specifically breaks autocompleting BGP IPv6 neighbor addresses. Before: aegaeon# show ip bg ne 2001:<?> WORD Neighbor on BGP configured interface After: aegaeon# show ip bg ne 2001:<?> WORD Neighbor on BGP configured interface X:X::X:X Neighbor to display information about 2001:db8::2 Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2017-05-15lib: parser: split off & rename graph handlingDavid Lamparter
Put core CLI graph stuff in lib/command_graph.[ch] and consistently prefix all function names with "cmd_". Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2017-01-25Merge pull request #105 from opensourcerouting/cli_merge_step_prepDonald Sharp
Prepare for split-off cli parser "merge" step
2017-01-25lib: parser: fix memory managementDavid Lamparter
command.c had: DEFINE_MTYPE_STATIC(LIB, CMD_TOKENS, "Command desc") while command_match.c had: DEFINE_MTYPE_STATIC(LIB, CMD_TOKENS, "Command Tokens") ... which means that there are 2 distinct MTYPE_CMD_TOKENS. (The description text being different does not matter, even with the same text it'd be 2 distinct types.) command_match.c allocates token->arg in command_match_r() while command.c frees it in del_cmd_token(). Therefore with each command being executed, the allocation count goes up on one, down on the other. => clean up parser allocation counting. Also, use separate MTYPEs for the different fields in struct cmd_token. Fixes: #108 / ee9216cf ("lib, ripngd: clean up merge leftovers") Signed-off-by: David Lamparter <equinox@opensourcerouting.org> Cc: Quentin Young <qlyoung@cumulusnetworks.com>
2017-01-23lib: parser: simplify OPTION_TKN & SELECTOR_TKNDavid Lamparter
These are functionally identical as "fork" tokens. Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2016-12-20bgpd, lib: fix a few scan-build catchesQuentin Young
Fixes a couple null pointer derefs and uninit'd values. Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2016-12-16lib: parser: move allowrepeat to cmd_tokenDavid Lamparter
struct graph_node isn't quite the right place to control matcher behaviour. Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2016-12-15lib: parser: support keyword argumentsDavid Lamparter
This re-adds "{foo WORD|bar WORD}" keyword-argument support to the CLI parser. Note that token graphs may now contain loops for this purpose; therefore the matching functions retain a history of already-matched tokens. Each token can thus only be consumed once. And then LINE... gets its special treatment with allowrepeat. Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2016-12-06lib, ripngd: clean up merge leftoversQuentin Young
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2016-12-06Merge remote-tracking branch 'osr/master' into vtysh-grammarQuentin Young
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com> Conflicts: lib/command_match.c
2016-12-06lib, tests: fix failing cli testsQuentin Young
Some tests still failing pending reimplementation of {} cli definition constructs Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2016-12-06lib: add back original ipv6 matcherQuentin Young
inet_pton is not suitable for well behaved cli completions Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2016-12-05Revert "lib: Macroize CLI matcher tracing"David Lamparter
This reverts commit 54c5dce6a5e46717ad52c80f2dc99fc36a372e28.
2016-12-02lib: make CLI completions less surprisingQuentin Young
* If a token matches exactly at the end of input, it still shows up in completions, e.g. ex# clear<?> clear Reset functions ex(config)# ip route 1.2.3.4<?> A.B.C.D IP destination prefix A.B.C.D/M IP destination prefix (e.g. 10.0.0.0/8) * If a token in mid-line exactly matches one token and partially matches on one or more additional tokens, the command tree(s) under the partially matching tokens will be ignored in favor of the exact match when compiling completions for the full line, e.g. ex(config)# ip <?> will only show completions for commands under 'ip' and not those under 'ipv6', which the input partially matches. Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2016-12-02lib: Macroize CLI matcher tracingQuentin Young
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2016-12-01lib: move command_parse_format prototypeDavid Lamparter
The function prototype for command_parse_format() is better left in command.h, so that the bison-generated header file doesn't need to be included for that. Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2016-12-01lib: allow all characters in WORD tokensDavid Lamparter
WORD tokens (which are also used for "LINE..." input) should really accept all characters. Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2016-11-15lib: Fix nondeterministic command matches in rare casesQuentin Young
When a user erroneously defines two commands which can match the same input and at least one of the tokens defined last in the command is a selector or option, the matcher does not detect an ambiguous match and matches the command installed first (leftmost in the graph). Fix is to do a full walkthrough of the follow set when matching the final token in a command to check that there is exactly one possible match, and to throw an ambiguity error otherwise. Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2016-11-12lib, vtysh: Fix memory leaks, change cmd_element to constQuentin Young
Fix a few memory issues: * Not freeing tab-completions upon input match failure * Invalid write when null-terminating tab-completions * Not freeing argv[] itself in additinon to elements * Use XFREE() instead of free() as appropriate * Not freeing final token of an [option] during parsing Make a few minor changes to CLI internals: * Improve documentation on matching & completion functions * Only make one copy of cmd_token's when building argv, instead of three * Don't make a copy of the matching cmd_element Make one major(ish) change to CLI internals: * Change all pointers to struct cmd_element to const Code outside of the core CLI units should never have an occasion to modify the internal state of the command system. Doing so could easily amount to having a CLI interface that changes during runtime, and could conceivably lead to security issues. Explicitly disallowing this removes any chance of confusion. Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2016-11-11lib: Allow '-' to match VARIABLE_TKNQuentin Young
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2016-11-10lib: Implement hidden and deprecated commandsQuentin Young
Each token now knows whether it is part of a hidden or deprecated command. Command completion logic hides such tokens when generating completions. Command matching logic works as before and will still match on hidden and deprecated commands. Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2016-10-20lib: Allow '_' in arguments to VARIABLE_TKNQuentin Young
second attempt Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2016-10-20Revert "lib: Allow '_' in arguments to VARIABLE_TKN"Quentin Young
This reverts commit e0a467872b307021477ea7b4ba27ffc5d20aedd0.
2016-10-20lib: Allow '_' in arguments to VARIABLE_TKNQuentin Young
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2016-10-07lib: Improve formatting for matcher tracing outputQuentin Young
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2016-10-06lib: Check match level when calculating completionsQuentin Young
Adds a missing check that resulted in partial token matches being accepted as exact matches when calculating input completions. Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2016-10-05lib: Add tracing capabilities to command matcherQuentin Young
Compile with -DTRACE_MATCHER to enable matcher debugging to stdout. Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2016-10-04lib: Allow / and . to match VARIABLE_TKN, fix range matchesQuentin Young
Range matching function was returning 0 instead of no_match on failed match, causing all input to match ranges. Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2016-10-02lib: explicitly support the case of empty input for completionsQuentin Young
When the user tab- or ?-completes when the character prior to the position of the cursor is a space, completion logic is passed null. Explicitly handle this case instead of using partly_match, which has special logic associated with it to allow abbreviating certain tokens. Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2016-09-22lib: argv fixes, XFREE -> free, rm decl in matcherQuentin Young
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2016-09-22lib: Remove last remnants of NUMBER_TKN...againQuentin Young
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2016-09-21lib: Use listnode_add_before for prepending nodesQuentin Young
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>