summaryrefslogtreecommitdiff
path: root/lib/command.c
AgeCommit message (Collapse)Author
2017-01-25Merge pull request #101 from LabNConsulting/working/master/patch-set/3-vrfDonald Sharp
Master version of basic vrf commands & some other missed fixes
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-23grammar_sandbox: add into daemons if DEV_BUILDDavid Lamparter
Also adds "grammar access <node>" to test/dump an existing command node (e.g. BGP_NODE). 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>
2017-01-22bgpd: add vrf-policy config using existing vnc codeLou Berger
add add/clear vrf prefix + Modified for FRR master parser Signed-off-by: Lou Berger <lberger@labn.net>
2017-01-19lib: guard strict cli completionsQuentin Young
Completions are checked for token and docstring equality before deduplicating. Put an ifdef guard around checking docstrings because many of them are inconsistent and may confuse users in a release build. It is a good idea to enable VTYSH_DEBUG when adding new CLI in the future to help check docstrings. Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2017-01-06Merge pull request #27 from qlyoung/fix-derefs2Donald Sharp
bgpd, lib: fix a few scan-build catches
2017-01-06Merge pull request #24 from qlyoung/fix-uninitialized-jumpDonald Sharp
lib: Initialize ->allowrepeat
2017-01-06Merge remote-tracking branch 'origin/stable/2.0'Donald Sharp
2017-01-03watchfrr: Rename watchquagga -> watchfrrDonald Sharp
Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2017-01-03Merge pull request #37 from LabNConsulting/working/2.0/patch-set-170102aDavid Lamparter
Working/2.0/patch set 170102a
2017-01-02lib/command.c: fix leak id'ed by valgrindLou Berger
Signed-off-by: Lou Berger <lberger@labn.net>
2016-12-20build: rename (1 of ?): configure.ac + preprocDavid Lamparter
This replaces Quagga -> FRR in most configure.ac settings as well as a handful of preprocessor macros in the source code. 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-18lib: Initialize ->allowrepeatQuentin Young
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2016-12-18lib: fix crash when tab-completing `do ...` commandsQuentin Young
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2016-12-16lib: parser: fix SEGV when Tab hits non-WORD_TKNDavid Lamparter
If <Tab> processing finds that there is only 1 candidate, but that candidate is not a WORD_TKN that we can tab-complete on, the status would remain at CMD_COMPLETE_FULL_MATCH, but the resulting list of possible completions is empty. This then SEGVs in lib/vty.c where it tries to access the first element of the list, assuming FULL_MATCH always has 1 element there... Signed-off-by: David Lamparter <equinox@opensourcerouting.org> Cc: Quentin Young <qlyoung@cumulusnetworks.com>
2016-12-08Merge branch 'fixes/command'David Lamparter
Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2016-12-05*: fix up DEFUNs without install_element callsDavid Lamparter
These now generate warnings which will break the build with -Werror. Note this may have enabled commands that should be disabled, or the other way around... Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2016-12-05Merge branch 'queue/osr/vtysh-generic'David Lamparter
WARNING: Merge contains nontrivial fixups in vrf_cmd handling. Conflicts: lib/if.c zebra/interface.c
2016-12-05lib: "write mem" should write to persistent configurationChristian Franke
Signed-off-by: Christian Franke <chris@opensourcerouting.org>
2016-12-05Merge branch 'stable/2.0'David Lamparter
Conflicts: bgpd/bgp_route.c lib/if.c ripd/rip_interface.c zebra/interface.c zebra/zebra_vty.c
2016-12-05Merge branch '-renato' into stable/2.0David Lamparter
This contains bgp memory leak fixes as well as cleanups to VRF/namespace handling and has been run through extended testing in Cumulus' testbed: Tested-by: Donald Sharp <sharpd@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: 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-01*: make DEFUN installations file-localDavid Lamparter
This moves all install_element calls into the file where the DEFUNs are located. This fixes several small related bugs: - ospf6d wasn't installing a "no interface FOO" command - zebra had a useless copy of "interface FOO" - pimd's copy of "interface FOO" was not setting qobj_index, which means "description LINE" commands would fail with an error The next commit will do the actual act of making "foo_cmd" static. Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2016-11-29*: fix "uninitialized" warningsDavid Lamparter
reported by clang for: - cmd_complete_command() - show_ip_bgp_ipv4() Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2016-11-28zebra/lib: plug several memleaksRenato Westphal
Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2016-11-15build: fix -Wmaybe-uninitialized warningsDavid Lamparter
Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2016-11-12Merge branch 'cmaster-next' into vtysh-grammarQuentin Young
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com> Conflicts: lib/command.c lib/vty.c
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: Update `list [permutations]`Quentin Young
Don't show hidden or deprecated commands. 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-10lib: add minimal no-config VTY modeDavid Lamparter
This silences the following warning from watchquagga: "Can't save to configuration file, using vtysh." which otherwise appears when doing a "write file" in vtysh when no integrated-config is in use. Also make "show memory" available in watchquagga. Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2016-11-03lib: Remove node debug message on `list` outputQuentin Young
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2016-10-31lib: Fix segfault on erroneous commandQuentin Young
Command completion vector should only be copied if it is non-null. Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2016-10-29lib: Various minor improvements & bugfixes to CLI backendQuentin Young
- Do not allow tab-completion on anything except words - Rewrite cmd_make_strvec to use strsep - Remove a few trailing whitespaces - Remove cmd_complete_command_lib Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2016-10-21Merge branch 'cmaster-next' into vtysh-grammarQuentin Young
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com> Conflicts: bgpd/bgp_encap.c bgpd/bgp_route.c lib/command.c lib/command.h ospf6d/ospf6d.c vtysh/vtysh.c
2016-10-20lib: Add helper function for working with argv, update bgpd to use itQuentin Young
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2016-10-20Merge branch 'cmaster-next' into vtysh-grammarQuentin Young
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com> Conflicts: isisd/isis_routemap.c zebra/rt_netlink.c
2016-10-19lib: keep hash of node's commands to detect duplicate installsPaul Jakma
* command.h: (struct cmd_node) Add a hash, so duplicate installs of a cmd_element to a command node can be detected. To help catch strays from the VIEW/ENABLE node consolidation particularly (installs to VIEW automatically install to ENABLE too now). * command.c: (cmd_hash_{key,cmp}) helpers for the hash - just directly on the pointer value is sufficient to catch the main problem. (install_node) setup the hash for the command node. (install_element) check for duplicate installs. The assert on the cmd_parse_format seems misplaced. (install_default_basic) separate the basic, VIEW, node default commands to here. (cmd_init) get rid of dupes, given consolidation. (cmd_terminate) clean up the node command hash. Not done: The (struct cmd_node)'s vector could be replaced with the cmd hash, however much of the command parser depends heavily on the vector and it's a lot of work to change. A vector_lookup_value could also work, particularly if vector could be backed by a hash. The duplicate check could be disabled in releases - but useful in development. It's a little extra overhead at startup. The command initialisation overhead is already something that bites in micro-benchmarks - makes it easy for other implementations to show how much faster they are with benchmarks where other load is low enough that startup time is a factor.
2016-10-18lib: add api method to read current config pathChristian Franke
Signed-off-by: Christian Franke <chris@opensourcerouting.org>
2016-10-17Merge branch 'cmaster-next' into vtysh-grammarQuentin Young
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com> Conflicts: bgpd/bgp_route.c bgpd/bgp_routemap.c bgpd/bgp_vty.c isisd/isis_redist.c isisd/isis_routemap.c isisd/isis_vty.c isisd/isisd.c lib/command.c lib/distribute.c lib/if.c lib/keychain.c lib/routemap.c lib/routemap.h ospf6d/ospf6_asbr.c ospf6d/ospf6_interface.c ospf6d/ospf6_neighbor.c ospf6d/ospf6_top.c ospf6d/ospf6_zebra.c ospf6d/ospf6d.c ospfd/ospf_routemap.c ospfd/ospf_vty.c ripd/rip_routemap.c ripngd/ripng_routemap.c vtysh/extract.pl.in vtysh/vtysh.c zebra/interface.c zebra/irdp_interface.c zebra/rt_netlink.c zebra/rtadv.c zebra/test_main.c zebra/zebra_routemap.c zebra/zebra_vty.c
2016-10-12lib/vtysh: fix duplicate installation of some vty commandsRenato Westphal
This is a followup to commits 735e62 and 0b1442, where we forgot to apply the same VIEW/ENABLE consolidation logic to vtysh. Also, we can't call install_default() for the ENABLE node because some of the vty commands installed by this function were already installed in the VIEW node before. Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2016-10-07*: Consolidate all double VIEW_NODE and ENABLE_NODE'sDonald Sharp
If a command is put into the VIEW_NODE, it is going into the ENABLE_NODE as well. This is especially true for show commands. As such if a command is in both consolidate it down to VIEW_NODE. Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2016-10-07lib: Consolidate VIEW_NODE to be ENABLE_NODE as wellDonald Sharp
If you are in VIEW_NODE, the command should exist in ENABLE_NODE as well. This is being done to reduce chances of code being added to one but not the other NODE. Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2016-10-07bgpd, lib: Remove RESTRICTED_NODE from code baseDonald Sharp
The RESTRICTED_NODE command is not used, introduces code complexity and provides no additional levels of security. The only way to get into RESTRICTED_NODE is to add, under vty configuration the command 'anonymous restricted', and then telnet to a daemon, provide a password, then type 'enable' and fail to enter the password three times. Then the user can enter a very limited set of commands to monitor bgp and only bgp behavior. This commit removes both the RESTRICTED_NODE usage as well as the lib/* usage of the code Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2016-10-07lib: Remove `show commandtree`, add `list permutations`Quentin Young
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2016-10-07lib: Add naive deduplication checks when installing commandsQuentin Young
Since not all duplicate commands can be caught during graph construction, do a linear search over all commands before installing. Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>