summaryrefslogtreecommitdiff
path: root/lib/command_match.c
AgeCommit message (Collapse)Author
2023-10-12build: add -Wimplicit-fallthroughIgor Ryzhov
Also: - replace all /* fallthrough */ comments with portable fallthrough; pseudo keyword to accomodate both gcc and clang - add missing break; statements as required by older versions of gcc - cleanup some code to remove unnecessary fallthrough Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2023-08-15lib: Lower precedence for ASNUM_TKN when using together with IPV4/IPV6_TKNDonatas Abraitis
When using together with IPV4/IPV6_TKN, this breaks an existing command like: ``` donatas-pc# clear bgp ipv6 unicast 2a02::1 % Ambiguous command: clear bgp ipv6 unicast 2a02::1 donatas-pc# ``` With this fix: ``` donatas-pc# clear bgp ipv6 unicast 2a02::1 % BGP: Unknown neighbor - "2a02::1" donatas-pc# clear bgp ipv6 unicast 2.2 % BGP: No IPv6 Unicast peer is configured with AS 2.2 donatas-pc# clear bgp ipv6 unicast 123 % BGP: No IPv6 Unicast peer is configured with AS 123 donatas-pc# clear bgp ipv4 unicast 127.0.0.1 donatas-pc# ``` Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2023-02-21Merge pull request #12248 from pguibert6WIND/bgpasdotRuss White
lib, bgp: add initial support for asdot format
2023-02-10lib, bgp: add initial support for asdot formatPhilippe Guibert
AS number can be defined as an unsigned long number, or two uint16 values separated by a period (.). The possible valus are: - usual 32 bit values : [1;2^32 -1] - <1.65535>.<0.65535> for dot notation - <0.65535>.<0.65535> for dot+ notation. The 0.0 value is forbidden when configuring BGP instances or peer configurations. A new ASN type is added for parsing in the vty. The following commands use that new identifier: - router bgp .. - bgp confederation .. - neighbor <> remote-as <> - neighbor <> local-as <> - clear ip bgp <> - route-map / set as-path <> An asn library is available in lib/ and provides some services: - convert an as string into an as number. - parse an as path list string and extract a number. - convert an as number into a string. Also, the bgp tests forge an as_zero_path, and to do that, an API to relax the possibility to have a 0 as value is specifically called from the tests. Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2023-02-09*: auto-convert to SPDX License IDsDavid Lamparter
Done with a combination of regex'ing and banging my head against a wall. Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2023-01-31lib: Add missing enum's to switch statementDonald Sharp
Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2022-10-06lib: make cmd_element->attr a bitmask & clarifyDavid Lamparter
It already "looks" like a bitmask, but we currently can't flag a command both YANG and HIDDEN at the same time. It really should be a bitmask. Also clarify DEPRECATED behaviour (or the absence thereof.) Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2021-09-14lib: fix segfault on question mark on empty lineIgor Ryzhov
Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2021-08-26lib: add `![...]` syntax for easy "no" formsDavid Lamparter
This allows defining a CLI command like this: `[no] some setting ![VALUE]` with VALUE being optional for the "no" form, but required for the positive form. It's just a `[...]` where the empty branch can only be taken for commands starting with `no`. Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2021-07-01*: Convert numeric 32 into IPV4_MAX_BITLEN for prefixlenDonatas Abraitis
Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
2021-07-01*: Convert numeric 128 into IPV6_MAX_BITLEN for prefixlenDonatas Abraitis
Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
2021-03-17*: require semicolon after DEFINE_MTYPE & coDavid Lamparter
Back when I put this together in 2015, ISO C11 was still reasonably new and we couldn't require it just yet. Without ISO C11, there is no "good" way (only bad hacks) to require a semicolon after a macro that ends with a function definition. And if you added one anyway, you'd get "spurious semicolon" warnings on some compilers... With C11, `_Static_assert()` at the end of a macro will make it so that the semicolon is properly required, consumed, and not warned about. Consistently requiring semicolons after "file-level" macros matches Linux kernel coding style and helps some editors against mis-syntax'ing these macros. Signed-off-by: David Lamparter <equinox@diac24.net>
2020-04-08*: Do not cast to the same typeDonatas Abraitis
Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
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>