summaryrefslogtreecommitdiff
path: root/lib/command_parse.y
AgeCommit message (Collapse)Author
2025-04-16lib: disable clang warning in parser yacc outputMark Stapp
Disable a clang 'unused' warning in the yacc source of command_parse.c. Signed-off-by: Mark Stapp <mjs@cisco.com>
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*: manual SPDX License ID conversionsDavid Lamparter
The files converted in this commit either had some random misspelling or formatting weirdness that made them escape automated replacement, or have a particularly "weird" licensing setup (e.g. dual-licensed.) This also marks a bunch of "public domain" files as SPDX License "NONE". Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2021-10-18lib: assign CLI varnames while parsingDavid Lamparter
... rather than running a costly extra pass across the finished tree. Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2021-10-05lib: fix spelling nits in more lib filesewlumpkin
Signed-off-by: ewlumpkin <ewlumpkin@gmail.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-04-21build: make builddir include path consistentDavid Lamparter
... by referencing all autogenerated headers relative to the root directory. (90% of the changes here is `version.h`.) Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
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>
2021-02-14*: remove tabs & newlines from log messagesDavid Lamparter
Neither tabs nor newlines are acceptable in syslog messages. They also break line-based parsing of file logs. Signed-off-by: David Lamparter <equinox@diac24.net>
2020-11-17lib: Change zlog_debug to zlog_err for doc string issuesDonald Sharp
Modify the code to change from zlog_debug to zlog_err. vtysh was not outputting the vtysh doc string issues after a change a couple of months back. By changing to error level we start seeing them on vtysh start up again. This will allow us to catch these issues in the CI runs again. Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2019-11-30lib: make cmd_element & qobj_type constDavid Lamparter
Signed-off-by: David Lamparter <equinox@diac24.net>
2019-06-25lib: add a check for {[...]} in DEFUNsDavid Lamparter
Our command matcher doesn't handle {[...]} correctly; let's warn about it so the DEFUN can be changed to [{...}] (which does work as expected.) Fixes: #4594 Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2018-08-14lib: Convert zlog_err for clippy buildDonald Sharp
The clippy code does not need to log the error messages as errors as that it is only run as part of the build itself and as long as we see the notifications we are good. So convert zlog_err to zlog_notice so that we do not think we have any zlog_err's in lib anymore Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2017-08-11lib: add CLI token for 48-bit mac addressesQuentin Young
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2017-07-31build: convert lib/ to non-recursive buildDavid Lamparter
Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2017-07-05lib: warn about too much docstringQuentin Young
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2017-06-14lib: fix CLI parser memleakDavid Lamparter
Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2017-06-14build: fix some cross-compilation issuesDavid Lamparter
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-05-15lib: parser: add named variables in CLIDavid Lamparter
struct cmd_token now has a "varname" field which is derived from the DEFUN's string definition. It can be manually specified with "$name" after some token, e.g. "foo WORD$var". A later commit adds code to automatically fill the value if nothing is specified. Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2017-02-10lib: parser: remove previous deduplication codeDavid Lamparter
Rewritten in next commit. Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2017-01-31lib: parser: fix allocation countingDavid Lamparter
command_lex.l was allocating as MTYPE_TMP, while command_parse.y would just call free(). Make both use MTYPE_LEX. 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-23build: support bison < 3.0 for parse.error=verboseDavid Lamparter
*sigh* Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2017-01-23lib: parser: add error location reportingDavid Lamparter
flex+bison have nice capabilities to track the location that is currently being processed; let's enable these and get better warnings for broken CLI specs. Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2017-01-23lib: parser: unify subgraphs & simplify even moreDavid Lamparter
This cuts a large piece of complexity from the parser by making the sequences between | the same, no matter whether it's <> () or []. This causes some changes in behaviour: - [foo|bar] is now accepted - <foo|[bar]> is now accepted (yes it's stupid) - {a|b} is now means "at least one of these, in any order"; to allow zero use [{a|b}] instead. Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2017-01-23lib: parser: keep subgraph pointers on stackDavid Lamparter
There's no need to malloc() these, we can just keep them on the stack. The entire struct will get copied around, but replacing a 2-pointer copy with a 1-pointer copy + malloc + free overhead is not quite efficient. Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2017-01-23lib: parser: track matching FORK_TKN & JOIN_TKNDavid Lamparter
This associates pairs of FORK and JOIN tokens, so the merge function can identify where a subgraph begins and ends. Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
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-16lib: parser: remove startnode & sentence_rootDavid Lamparter
This removes an artificial restriction for the first token in a command's graph to be a WORD_TKN. The intention seems to be to prohibit empty paths through a command, and to restrict "explosion" of choices in the root node. The better approach to the former is to check for an empty path after the definition is parsed. The latter will happen anyway, by duplication of the command, which just makes it worse... Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
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-16lib: parser: reorder bison incarnationsDavid Lamparter
This shuffles the code blocks in command_parser.y to match file output order, then adjusts things to make the include handling less messy. (also dropped unused DECIMAL_STRLEN_MAX define.) This should hopefully fix the build on NetBSD 6. Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2016-12-16build: fix bison < 3.0 compatibilityDavid Lamparter
bison-2.7.x really wants "foo" for api.prefix while bison-3.0.x really wants {foo} ... great. 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-02lib: Add back prototypes for lexer helper funcsQuentin Young
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2016-12-01lib: remove misleading copy/del_cmd_elementDavid Lamparter
struct cmd_element items are static global variables, they are never allocated, copied or freed. Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2016-12-01lib: parser: use reentrant mode on flex & bisonDavid Lamparter
This removes remaining global variables from the lexer, pushing the lexer state into struct parser_ctx too. At the same time, "cmd_yy" is used as prefix for all parser & lexer routines. The result is that (a) there is no collision anymore if a program uses flex/bison and links libzebra, and (b) the parser is fully encapsulated and could be called in parallel from multiple threads. Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2016-12-01lib: parser: wrap state in struct parser_ctxDavid Lamparter
This encapsulates all parser state into a new "struct parser_ctx", which is allocated on stack and passed around as pointer. The parser no longer has any global variables with this. Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
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-11-29lib: use traditional yacc empty statementDavid Lamparter
%empty was added in bison 2.7.1, which seems to not be available on some of the BSDs by default. Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
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-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-11-04ospfd, lib: Fix `no pce address` syntaxQuentin Young
And change parser debugging messages to zlog_debug Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2016-10-27lib: Log warning when commands have underfull doc stringQuentin Young
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2016-10-02lib: allow nesting selectorsQuentin Young
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2016-09-30lib: fix double free in parserQuentin Young
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2016-09-30lib, vtysh: refactor vtysh.c, allow parser continuanceQuentin Young
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2016-09-22lib: Remove NUMBER_TKN leftoversQuentin Young
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>