Commit Graph

468 Commits

Author SHA1 Message Date
Yuan Yuan
f8aa257997 lib: fix vtysh core when handling questionmark
When issue vtysh command with ?, the initial buf size for the
element is 16. Then it would loop through each element in the cmd
output vector. If the required size for printing out the next
element is larger than the current buf size, realloc the buf memory
by doubling the current buf size regardless of the actual size
that's needed. This would cause vtysh core when the doubled size
is not enough for the next element.

Signed-off-by: Yuan Yuan <yyuanam@amazon.com>
2023-05-31 20:30:03 +00:00
Christian Hopps
a1d8c7a36e mgmtd: fix reading of config file[s]
Signed-off-by: Christian Hopps <chopps@labn.net>
2023-05-30 02:09:44 -04:00
Christian Hopps
3701780a15 lib: log commands read from config file
When the user specifies `--command-log-always` in CLI arguments then also log
commands executed from loading the config file.

Signed-off-by: Christian Hopps <chopps@labn.net>
2023-05-04 14:48:59 -04:00
Christian Hopps
cfa0facbf9 mgmtd: fully implement debug flags for mgmtd and clients
Signed-off-by: Christian Hopps <chopps@labn.net>
2023-05-01 13:47:12 -04:00
Donald Sharp
24a58196dd *: Convert event.h to frrevent.h
We should probably prevent any type of namespace collision
with something else.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2023-03-24 08:32:17 -04:00
Donald Sharp
5f6eaa9b96 *: Convert a bunch of thread_XX to event_XX
Convert these functions:

thread_getrusage
thread_cmd_init
thread_consumed_time
thread_timer_to_hhmmss
thread_is_scheduled
thread_ignore_late_timer

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2023-03-24 08:32:17 -04:00
Donald Sharp
cb37cb336a *: Rename thread.[ch] to event.[ch]
This is a first in a series of commits, whose goal is to rename
the thread system in FRR to an event system.  There is a continual
problem where people are confusing `struct thread` with a true
pthread.  In reality, our entire thread.c is an event system.

In this commit rename the thread.[ch] files to event.[ch].

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2023-03-24 08:32:16 -04:00
Donald Sharp
d8bc11a592 *: Add a hash_clean_and_free() function
Add a hash_clean_and_free() function as well as convert
the code to use it.  This function also takes a double
pointer to the hash to set it NULL.  Also it cleanly
does nothing if the pointer is NULL( as a bunch of
code tested for ).

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2023-03-21 08:54:21 -04:00
Russ White
ba755d35e5
Merge pull request #12248 from pguibert6WIND/bgpasdot
lib, bgp: add initial support for asdot format
2023-02-21 08:01:03 -05:00
Donald Sharp
8383d53e43
Merge pull request #12780 from opensourcerouting/spdx-license-id
*: convert to SPDX License identifiers
2023-02-17 09:43:05 -05:00
Donatas Abraitis
234f6fd4f4 bgpd: Add BGP Software Version Capability
Implement: https://datatracker.ietf.org/doc/html/draft-abraitis-bgp-version-capability

Tested with GoBGP:

```
% ./gobgp neighbor 192.168.10.124
BGP neighbor is 192.168.10.124, remote AS 65001
  BGP version 4, remote router ID 200.200.200.202
  BGP state = ESTABLISHED, up for 00:01:49
  BGP OutQ = 0, Flops = 0
  Hold time is 3, keepalive interval is 1 seconds
  Configured hold time is 90, keepalive interval is 30 seconds

  Neighbor capabilities:
    multiprotocol:
        ipv4-unicast:	advertised and received
        ipv6-unicast:	advertised
    route-refresh:	advertised and received
    extended-nexthop:	advertised
        Local:  nlri: ipv4-unicast, nexthop: ipv6
    UnknownCapability(6):	received
    UnknownCapability(9):	received
    graceful-restart:	advertised and received
        Local: restart time 10 sec
	    ipv6-unicast
	    ipv4-unicast
        Remote: restart time 120 sec, notification flag set
	    ipv4-unicast, forward flag set
    4-octet-as:	advertised and received
    add-path:	received
      Remote:
         ipv4-unicast:	receive
    enhanced-route-refresh:	received
    long-lived-graceful-restart:	advertised and received
        Local:
	    ipv6-unicast, restart time 10 sec
	    ipv4-unicast, restart time 20 sec
        Remote:
	    ipv4-unicast, restart time 0 sec, forward flag set
    fqdn:	advertised and received
      Local:
         name: donatas-pc, domain:
      Remote:
         name: spine1-debian-11, domain:
    software-version:	advertised and received
      Local:
         GoBGP/3.10.0
      Remote:
         FRRouting/8.5-dev-MyOwnFRRVersion-gdc92f44a45-dirt
    cisco-route-refresh:	received
  Message statistics:
```

FRR side:

```
root@spine1-debian-11:~# vtysh -c 'show bgp neighbor 192.168.10.17 json' | \
> jq '."192.168.10.17".neighborCapabilities.softwareVersion.receivedSoftwareVersion'
"GoBGP/3.10.0"
root@spine1-debian-11:~#
```

Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2023-02-15 23:14:48 +02:00
Philippe Guibert
8079a4138d lib, bgp: add initial support for asdot format
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-10 10:27:17 +01:00
David Lamparter
acddc0ed3c *: auto-convert to SPDX License IDs
Done with a combination of regex'ing and banging my head against a wall.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2023-02-09 14:09:11 +01:00
Donald Sharp
bde30e78cb lib: Add missing enum's to switch statement
Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2023-01-31 15:15:42 -05:00
Dmitrii Turlupov
ef78e4fdac lib: fix display cputime-warning and walltime-warning
Before patch:
```
# vtysh -c "c t" -c "service cputime-warning 1" -c "service walltime-warning 2"
# vtysh  -c "show run" | grep warn
service cputime-warning 1000
service walltime-warning 2000
```

After patch:
```
# vtysh -c "c t" -c "service cputime-warning 1" -c "service walltime-warning 2"
# vtysh  -c "show run" | grep warn
service cputime-warning 1
service walltime-warning 2
```

Signed-off-by: Dmitrii Turlupov <dturlupov@factor-ts.ru>
2022-12-28 11:33:09 +03:00
Donald Sharp
e3e3d729c4
Merge pull request #12066 from opensourcerouting/cleanup-cli-xref
*: clean up various CLI-related bits
2022-10-13 13:47:04 -04:00
Donald Sharp
cf00164b69 *: Create and use infrastructure to show debugs in lib
There are lib debugs being set but never show up in
`show debug` commands because there was no way to show
that they were being used.  Add a bit of infrastructure
to allow this and then use it for `debug route-map`

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2022-10-07 12:39:05 -04:00
David Lamparter
9eebf97e3d lib: make cmd_element->attr a bitmask & clarify
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>
2022-10-06 15:34:32 +02:00
Donatas Abraitis
ac156aecb5 lib, vtysh: Add allow-reserved-ranges global command
It will be used to allow/deny using IPv4 reserved ranges (Class E) for Zebra
(configuring interface address) or BGP (allow next-hop to be from this range).

Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2022-07-01 23:24:52 +03:00
Donald Sharp
00c89a3673 lib: Function crypt does not need to be declared mid function
Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2022-06-16 16:31:35 -04:00
anlan_cs
8e3aae66ce *: remove the checking returned value for hash_get()
Firstly, *keep no change* for `hash_get()` with NULL
`alloc_func`.

Only focus on cases with non-NULL `alloc_func` of
`hash_get()`.

Since `hash_get()` with non-NULL `alloc_func` parameter
shall not fail, just ignore the returned value of it.
The returned value must not be NULL.
So in this case, remove the unnecessary checking NULL
or not for the returned value and add `void` in front
of it.

Importantly, also *keep no change* for the two cases with
non-NULL `alloc_func` -
1) Use `assert(<returned_data> == <searching_data>)` to
   ensure it is a created node, not a found node.
   Refer to `isis_vertex_queue_insert()` of isisd, there
   are many examples of this case in isid.
2) Use `<returned_data> != <searching_data>` to judge it
   is a found node, then free <searching_data>.
   Refer to `aspath_intern()` of bgpd, there are many
   examples of this case in bgpd.

Here, <returned_data> is the returned value from `hash_get()`,
and <searching_data> is the data, which is to be put into
hash table.

Signed-off-by: anlan_cs <vic.lan@pica8.com>
2022-05-03 00:41:48 +08:00
Donald Sharp
a7141b85c8 lib: Ensure an empty string does not get printed for host/domain
End operator is showing:
!
frr version 8.0.1
frr defaults traditional
hostname test.example.com
domainname

domainname should not be printed in this case at all.  I do not
see any mechanism in current code that this could happen, but
what do I know?  Put some extra stupid insurance in place
to prevent bad config from being generated.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2022-04-21 14:13:01 -04:00
anlan_cs
4d4c404bf6 *: Add necessary new line for output of vty_out()
Signed-off-by: anlan_cs <vic.lan@pica8.com>
2022-02-27 10:59:19 +08:00
Donald Sharp
46b48b3302 lib: Add more information to show version
Add to lib/command.c the ability to remember the
release/version/system information and to allow
`show version` to dump some of it.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2022-02-04 10:29:38 -05:00
David Lamparter
dd2c81b8c0 lib: rework vty_check_node_for_xpath_decrement
...by having a flag in struct cmd_node rather than hardcoding it in
`lib/command.c`.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2021-11-16 18:51:22 +01:00
David Lamparter
0e06eb8b2e vtysh: defer CLI tree building
We don't need the CLI tree until we actually enter the node.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2021-10-18 19:48:11 +02:00
Quentin Young
32acb4a7ad
Merge pull request #9497 from opensourcerouting/cli-better-no 2021-09-09 12:22:53 -04:00
David Lamparter
90c8406c20 lib: add ![...] syntax for easy "no" forms
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-08-26 21:03:44 +02:00
Igor Ryzhov
c1e7a5e45e lib: make node_parent more generic
Instead of adding a separate case clause for every node, just find the
node structure in the global list and get its parent node from there.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2021-08-26 19:43:23 +03:00
Quentin Young
41d3d77496
Merge pull request #8982 from dlqs/lua-func-stack 2021-08-02 13:51:35 +00:00
Donald Lee
8be973f5c2 lib: Add function name to script command
Signed-off-by: Donald Lee <dlqs@gmx.com>
2021-07-24 00:45:22 +08:00
Igor Ryzhov
d9331fc67c lib, zebra: fix exit from link-params node
When exiting from link-params node, we must not decrement xpath_index
because it is not incremented when entering the node.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2021-07-21 17:23:45 +03:00
Donald Lee
596b44af8a lib: Remove warning about script not found
Signed-off-by: Donald Lee <dlqs@gmx.com>
2021-07-18 06:32:03 +08:00
Donald Lee
64d457d7ac lib: Rename frrscript_unload to delete
frrscript_load now loads a function instead of a file, so frrscript_unload
should be renamed since it does not unload a function.

Signed-off-by: Donald Lee <dlqs@gmx.com>
2021-07-18 06:32:03 +08:00
Donald Lee
ad6e9b854d test: Use frrscript_unload
Signed-off-by: Donald Lee <dlqs@gmx.com>
2021-07-18 06:32:03 +08:00
Donald Lee
a71096fb0a lib: Update Script command example to call function
Signed-off-by: Donald Lee <dlqs@gmx.com>
2021-07-18 06:32:03 +08:00
Quentin Young
71bae95e4a
Merge pull request #8888 from dlqs/lua-call 2021-07-05 04:13:20 +00:00
Donatas Abraitis
7702d0b720
Merge pull request #8911 from donaldsharp/command_node
lib: Add some hash name differentiation for Command Hash's
2021-06-29 11:47:16 +03:00
Donald Sharp
c81d78cf1c lib: Add some hash name differentiation for Command Hash's
Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2021-06-24 10:51:34 -04:00
David Lamparter
45f0118832 lib: make cputime checks runtime options (v2)
...really no reason to force this into a compile time decision.  The
only point is avoiding the getrusage() syscall, which can easily be a
runtime decision.

[v2: also split cputime & walltime limits]

Signed-off-by: David Lamparter <equinox@diac24.net>
2021-06-24 16:42:59 +02:00
Donald Lee
bdc1085d7b lib: Update script SCRIPT command
Can now test out script by modifying a prefix

Signed-off-by: Donald Lee <dlqs@gmx.com>
2021-06-22 05:02:12 +08:00
Quentin Young
fdb7f5d54f
Merge pull request #8593 from idryzhov/cmd-ambiguous
vtysh: fix searching commands in parent nodes
2021-06-08 15:41:45 +00:00
Rafael Zalamena
77af3a34ba lib: fix address sanitizer crash on find
Fix the following address sanitizer crash when running the command `find`:

  ERROR: AddressSanitizer: dynamic-stack-buffer-overflow
  WRITE of size 1 at 0x7fff4840fc1d thread T0
      0  in print_cmd ../lib/command.c:1541
      1  in cmd_find_cmds ../lib/command.c:2364
      2  in find ../vtysh/vtysh.c:3732
      3  in cmd_execute_command_real ../lib/command.c:995
      4  in cmd_execute_command ../lib/command.c:1055
      5  in cmd_execute ../lib/command.c:1219
      6  in vtysh_execute_func ../vtysh/vtysh.c:486
      7  in vtysh_execute ../vtysh/vtysh.c:671
      8  in main ../vtysh/vtysh_main.c:721
      9  in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x270b2)
      10 in _start (/usr/bin/vtysh+0x21f64d)

Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
2021-06-07 11:14:25 -03:00
Rafael Zalamena
4548fb256c
Merge pull request #8781 from idryzhov/fix-list-find
lib: fix output of "list" and "find" commands
2021-06-07 08:32:31 -03:00
Mark Stapp
e4768d32b8
Merge pull request #5865 from slankdev/slankdev-zebra-srv6-manager
zebra: srv6 manager
2021-06-04 13:41:55 -04:00
Igor Ryzhov
5b96d81c86 lib: fix output of "list" and "find" commands
Currently, we output the command exactly how it is defined in DEFUN.
We shouldn't output varnames and excessive whitespace.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2021-06-03 02:03:20 +03:00
Igor Ryzhov
c22789620d lib, vtysh: reduce code duplication
Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2021-06-03 02:03:15 +03:00
Hiroki Shirokura
6c0a7c0941 *: new cli-nodes for SRv6 manager (step2)
This commit is a part of #5853 that add new cmd-node for SRv6 configuration.
This commit just add cmd-node and moving node cli only, acutual SRv6 config
command isn't added. (that is added later commit. of this branch)

new cli nodes:
* SRv6
* SRv6-locators
* SRv6-locator

Signed-off-by: Hiroki Shirokura <slank.dev@gmail.com>
2021-06-02 10:24:47 -04:00
Christian Hopps
fd396924d6 northbound: KISS always batch yang config (file read), it's faster
The backoff code assumed that yang operations always completed quickly.
It checked for > 100 YANG modeled commands happening in under 1 second
to enable batching. If 100 yang modeled commands always take longer than
1 second batching is never enabled. This is the exact opposite of what
we want to happen since batching speeds the operations up.

Here are the results for libyang2 code without and with batching.

| action        |  1K rts |  2K rts | 1K rts | 2K rts | 20k rts |
|               | nobatch | nobatch |  batch |  batch |   batch |
| Add IPv4      |    .881 |    1.28 |   .703 |   1.04 |    8.16 |
| Add Same IPv4 |    28.7 |     113 |   .590 |   .860 |    6.09 |
| Rem 1/2 IPv4  |    .376 |    .442 |   .379 |   .435 |    1.44 |
| Add Same IPv4 |    28.7 |     113 |   .576 |   .841 |    6.02 |
| Rem All IPv4  |    17.4 |    71.8 |   .559 |   .813 |    5.57 |

(IPv6 numbers are basically the same as iPv4, a couple percent slower)

Clearly we need this. Please note the growth (1K to 2K) w/o batching is
non-linear and 100 times slower than batched.

Notes on code: The use of the new `nb_cli_apply_changes_clear_pending`
is to commit any pending changes (including the current one). This is
done when the code would not correctly handle a single diff that
included the current changes with possible following changes. For
example, a "no" command followed by a new value to replace it would be
merged into a change, and the code would not deal well with that. A good
example of this is BGP neighbor peer-group changing. The other use is
after entering a router level (e.g., "router bgp") where the follow-on
command handlers expect that router object to now exists. The code
eventually needs to be cleaned up to not fail in these cases, but that
is for future NB cleanup.

Signed-off-by: Christian Hopps <chopps@labn.net>
2021-06-02 14:05:26 +00:00
Pavel Ivashchenko
4bb7f7c2dd vtysh: fix searching commands in parent nodes
Do not check parent command nodes in case of ambiguous and incomplete commands

Signed-off-by: Pavel Ivashchenko <pivashchenko@nfware.com>
2021-04-29 18:35:07 +03:00