Commit graph

317 commits

Author SHA1 Message Date
anlan_cs 4518d386f7 zebra: fix missing static routes
Use `vtysh` with this input file:
```
ip route A nh1
ip route A nh2
ip route B nh1
ip route B nh2
```

When running "ip route B" with "nh1" and "nh2", the procedure maybe is:
1) Create the two nexthops: "nh1" and "nh2".
2) Register "nh1" with `static_zebra_nht_register()`, then the states of both
   "nh1" and "nht2" are set to "STATIC_SENT_TO_ZEBRA".
3) Register "nh2" with `static_zebra_nht_register()`, then only the routes with
   nexthop of "STATIC_START" will be sent to zebra.

So, send the routes with the nexthop of "STATIC_SENT_TO_ZEBRA" to zebra.

Signed-off-by: anlan_cs <vic.lan@pica8.com>
2024-07-12 22:23:42 +08:00
Donald Sharp c70af155d2
Merge pull request #15285 from idryzhov/staticd-nexthop-refcounter
staticd: fix nexthop tracking memory leak and add a topotest for VRFs
2024-02-08 15:53:30 -05:00
Igor Ryzhov 4bde9511c3 staticd: coverity fixes
Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2024-02-04 22:28:33 +02:00
Igor Ryzhov 3c05d53bf8 staticd: fix nht memory leak
When a static route with a gateway nexthop is created, the nexthop is
sent to zebra for NHT, and added to a local hash. When the nexthop's VRF
is deleted from kernel, nexthop still stays in the hash. This is a
memory leak, because it is never deleted from there. Even if the VRF is
recreated in kernel, it is assigned with a new `vrf_id` so the old hash
entry is not reused, and a new one is created. To fix the issue, remove
all nexthops from the hash when the corresponding VRF is deleted, do not
add nexthops to the hash if their corresponding VRF doesn't exist in
kernel and don't add the same nexthop to the hash multiple times.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2024-02-04 22:28:10 +02:00
Igor Ryzhov 6090b2b939 staticd: add a separate function for uninstalling nexthops
Will be used in the following commit.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2024-02-04 22:28:10 +02:00
Igor Ryzhov 0d9127bca1 staticd: don't send routes from disabled vrfs to zebra
Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2024-02-04 22:28:10 +02:00
Igor Ryzhov 6da3e78ce5 staticd: fix processing nht updates
When processing an NHT update, we should go though all `static_vrf`
structures instead of regualar `vrf`, because some of `static_vrf` may
not have corresponding `vrf` and will miss the update.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2024-02-04 22:28:10 +02:00
Igor Ryzhov cb781f6097 staticd: fix NB dependency hack
Currently, staticd configuration is tightly coupled with VRF existence.
Because of that, it has to use a hack in NB infrastructure to create a
VRF configuration when at least one static route is configured for this
VRF. This hack is incompatible with mgmtd, because mgmtd doesn't execute
configuration callbacks. Because of that, the configuration may become
out of sync between mgmtd and staticd. There are two main cases:

1. Create static route in a VRF. The VRF data node will be created
   automatically in staticd by the NB hack, but not in mgmtd.
2. Delete VRF which has some static routes configured. The static route
   configuration will be deleted from staticd by the NB hack, but not
   from mgmtd.

To fix the problem, decouple configuration of static routes from VRF
configuration. Now it is possible to configure static routes even if the
VRF doesn't exist yet. Once the VRF is created, staticd applies all the
preconfigured routes.

This change also fixes the problem with static routes being preserved in
the system when staticd "control-plane-protocol" container is deleted
but the VRF is still configured.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2024-02-02 00:57:59 +02:00
Igor Ryzhov 5dfa36b6a7 staticd: fix nexthops without interface
When interface is not set in "ip route" command, CLI passes "(null)" as
an interface name instead of an empty string. The actual code in turn
uses "nh->ifname[0] != 0" to check if the interface name was set. Fix
the problem by changing the "(null)" string into an empty string when
populating the nexthop structure.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2024-02-02 00:25:15 +02:00
Igor Ryzhov d205208f57 Revert "staticd: Accept full blackhole typed keywords for ip_route_cmd"
This reverts commit 76b2bc97e7.

This change is wrong for several reasons:
- it is backwards incompatible - previously it was always possible to
  create blackhole/reject routes using shortened versions of the words
  and it suddenly became impossible if there's an interface in the
  system with the same name
- it uses operational data for validation which is prohibited
- it doesn't really solve the problem with inability to create routes
  using interface names like `bla` or `rej`
2024-02-02 00:25:15 +02:00
Mark Stapp 72b31b96fc *: create a single registry of daemons' default port values
Create a single registry of default port values that daemons
are using. Most of these are vty ports, but there are some
others for features like ospfapi and zebra FPM.

Signed-off-by: Mark Stapp <mjs@labn.net>
2024-02-01 11:40:02 -05:00
Igor Ryzhov 42d6b864cd build: remove mgmtd exception from xref2vtysh
We may actually need to send CLI commands to mgmtd and another daemon at
the same time, for example, if this daemon is not mgmtd-converted. The
only daemon this exception protects is staticd. But we don't actually
need any configuration commands in staticd, so just remove the exception
and don't install unnecessary commands to staticd.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2024-01-28 23:28:40 +02:00
David Lamparter 634f481113 *: fix frr_daemon_info indentation
clang-format doesn't understand FRR_DAEMON_INFO is a long macro where
laying out items semantically makes sense.

(Also use only one `FRR_DAEMON_INFO(` in isisd so editors don't get
confused with the mismatching `( ( )`.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2024-01-27 19:02:51 +01:00
Christian Hopps 83abe9c3cb ripd: ripd convert to mgmtd
Signed-off-by: Christian Hopps <chopps@labn.net>
2024-01-26 12:34:46 -05:00
Igor Ryzhov 34721972ba lib, mgmtd: rename ignore_cbs to ignore_cfg_cbs
Setting this variable to true makes NB ignore only configuration-related
callbacks. CLI-related callbacks are still loaded and executed, so
rename the variable to make it clearer.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2024-01-11 23:47:48 +02:00
Christian Hopps 29340e6b06 lib: fix the ASAN OneDefinitionRule violation.
Rename global client pointer variables and make the linkage static.

Signed-off-by: Christian Hopps <chopps@labn.net>
2023-12-11 19:53:03 -05:00
Rafael Zalamena cad5ee56be
Merge pull request #14922 from louis-6wind/fix-bfd-static-source
staticd: fix changing to source auto in bfd monitor
2023-12-06 09:51:32 -03:00
Louis Scalbert 580c605194 staticd: fix changing to source auto in bfd monitor
When monitoring a static route with BFD multi-hop, the source IP can be
either configured or retrieved from NextHop-Tracking (NHT). After
removing a configured source, the source is supposed to be retrieved
from NHT but it remains to the previous value. This is problematic if
the user desires to fix the configuration of a incorrect source IP.

For example, theses two commands results in the incorrect state:

> ip route 10.0.0.0/24 10.1.0.1 bfd multi-hop source 10.2.2.2
> ip route 10.0.0.0/24 10.1.0.1 bfd multi-hop

When removing the source, BFD is unable to find the source from NHT via
bfd_nht_update() were called.

Force zebra to resend the information to BFD by unregistering and
registering again NHT. The (...)/frr-nexthops/nexthop northbound
apply_finish function will trigger a call to static_install_nexthop()
that does a call to static_zebra_nht_register(nh, true);

Fixes: b7ca809d1c ("lib: BFD automatic source selection")
Signed-off-by: Louis Scalbert <louis.scalbert@6wind.com>
2023-12-01 14:08:57 +01:00
Christian Hopps 2c01083d35 lib: all: remove './' from xpath 22% speedup
fixes #8299

Signed-off-by: Christian Hopps <chopps@labn.net>
2023-11-29 14:37:23 -05:00
Christian Hopps e7064647b9
Merge pull request #14838 from idryzhov/mgmtd-cli-out
Output configuration of mgmtd-converted daemons from mgmtd
2023-11-29 14:50:16 +01:00
David Lamparter f1a15bd2a4 staticd: replace receive_notify with request
Send `ZEBRA_ROUTE_NOTIFY_REQUEST` rather than relying on the options
field in zclient startup.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2023-11-23 14:59:09 +01:00
Donatas Abraitis b84476e0bb
Merge pull request #14850 from donaldsharp/IFNAMSIZ_GET_YOUR_SHIT_TOGETHER
*: Let's use the native IFNAMSIZ instead of INTERFACE_NAMSIZ
2023-11-22 09:13:58 +02:00
Donald Sharp 07b91ca096 *: Let's use the native IFNAMSIZ instead of INTERFACE_NAMSIZ
INTERFACE_NAMSIZ is just a redefine of IFNAMSIZ and IFNAMSIZ
is the standard for interface name length on all platforms
that FRR currently compiles on.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2023-11-21 08:08:29 -05:00
Igor Ryzhov d532771eaa mgmtd, staticd: output staticd configuration from mgmtd
As mgmtd now implements vty for staticd, it's logical to output the
configuration from there as well. Fully-converted backend daemons should
not handle vty commands at all.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2023-11-21 13:28:40 +02:00
David Lamparter 088250ff04 staticd: use zclient->nexthop_update
Same as before.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2023-11-20 11:24:28 +01:00
Igor Ryzhov 649f04d679 staticd: fix debug commands
Debug commands should be installed in staticd, not in mgmtd.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2023-11-17 03:18:28 +01:00
Donald Sharp 6de9f7fbf5 *: Move distance related defines into their own header
Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2023-11-07 06:47:51 -05:00
David Lamparter d889055d8e lib: convert if_zapi_callbacks into actual hooks
...so that multiple functions can be subscribed.

The create/destroy hooks are renamed to real/unreal because that's what
they *actually* signal.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2023-11-02 17:10:43 -07:00
Christian Hopps 81d1d39952 isisd: staticd: need to link directly against libyang
Signed-off-by: Christian Hopps <chopps@labn.net>
2023-10-26 22:53:44 -04:00
Donald Sharp 0dc12c9003 Revert "lib: register bgp link-state afi/safi"
This reverts commit 1642a68d60.
2023-10-10 16:45:57 -04:00
Donald Sharp 7d86229ca6 staticd: Memory leak of string in staticd
XSTRDUP and then calling strsep mangles the
pointer returned by XSTRDUP.  Keep a copy
of the orig and when we are done, free that instead.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2023-10-04 14:11:49 -04:00
Russ White 8e755a03a3
Merge pull request #12649 from louis-6wind/bgp-link-state
bgpd: add basic support of BGP Link-State RFC7752
2023-09-26 10:07:02 -04:00
Russ White 90d19d1489
Merge pull request #14089 from dmytroshytyi-6WIND/srv6_multiple_segs_sids
bgpd,doc,lib,sharpd,staticd,yang,zebra: SRv6 multiple segs SIDs
2023-09-20 23:09:35 -04:00
Dmytro Shytyi d91a38a4db staticd: add vtysh srv6 multiple segs SIDs
Append staticd vty with multiple segs SIDs.

Signed-off-by: Dmytro Shytyi <dmytro.shytyi@6wind.com>
2023-09-20 15:07:15 +02:00
Dmytro Shytyi b13b5f85f9 staticd: northbound srv6 hooks for segs stack yang model
Provive hooks for srv6 segs SIDs stack yang model.

Signed-off-by: Dmytro Shytyi <dmytro.shytyi@6wind.com>
2023-09-20 15:07:15 +02:00
Dmytro Shytyi 35028f833c staticd: zebra, modify nexthop to support multiple srv6 segs SIDs
Adapt the nexthop from 1 to multiple srv6 seg SIDs

Signed-off-by: Dmytro Shytyi <dmytro.shytyi@6wind.com>
2023-09-20 15:07:15 +02:00
Dmytro Shytyi 21eb1449c7 staticd: add srv6 static route seg information
Signed-off-by: Dmytro Shytyi <dmytro.shytyi@6wind.com>
2023-09-20 15:07:15 +02:00
Donatas Abraitis a914bd1643 staticd: Check against NULL before dereferencing vrf
If VRF is not found by the given name, validate it and return an error.

Fixes: 76b2bc97e7 ("staticd: Accept full blackhole typed keywords for ip_route_cmd")

Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2023-09-20 15:25:29 +03:00
Louis Scalbert 1642a68d60 lib: register bgp link-state afi/safi
Register BGP Link-State AFI/SAFI values from RFC7752.

Signed-off-by: Louis Scalbert <louis.scalbert@6wind.com>
Signed-off-by: Olivier Dugeon <olivier.dugeon@orange.com>
2023-09-18 14:22:51 +02:00
Donatas Abraitis 76b2bc97e7 staticd: Accept full blackhole typed keywords for ip_route_cmd
Before this patch we allow entering next-hop interface address as any string.

Like, we can type: `ip route 10.10.10.10/32 bla`, but this will create a blackhole
route instead of using an interface `bla`.

The same is with reject.

After the patch:

```
$ vtysh -c 'con' -c 'ip route 10.10.10.100/32 bla'
ERROR: SET_CONFIG request failed, Error: nexthop interface name must be (reject, blackhole)

$ ip link show dev bla
472: bla: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc fq_codel state DOWN mode DEFAULT group default qlen 1000
    link/ether fa:45:bd:f1:f8:f0 brd ff:ff:ff:ff:ff:ff

$ vtysh -c 'sh run | include ip route'
$ vtysh -c 'con' -c 'ip route 10.10.10.100/32 blac'
$ vtysh -c 'sh run | include ip route'
ip route 10.10.10.100/32 blackhole

$ vtysh -c 'con' -c 'no ip route 10.10.10.100/32 blac'
$ vtysh -c 'sh run | include ip route'
$ vtysh -c 'con' -c 'ip route 10.10.10.100/32 blackhole'
$ vtysh -c 'sh run | include ip route'
ip route 10.10.10.100/32 blackhole

$ vtysh -c 'con' -c 'no ip route 10.10.10.100/32 blackhole'
$ vtysh -c 'sh run | include ip route'
$ vtysh -c 'con' -c 'ip route 10.10.10.100/32 Null0'
$ vtysh -c 'sh run | include ip route'
ip route 10.10.10.100/32 Null0

$ vtysh -c 'con' -c 'no ip route 10.10.10.100/32 Null0'
$ vtysh -c 'sh run | include ip route'
$
```

Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2023-08-25 12:00:33 +03:00
Igor Ryzhov 3eb4d42e62 staticd: fix comparison of nexthop-vrf
When displaying the configuration, the order of nexthop-vrf is wrong,
because the default VRF is not displayed, but still compared as the word
"default". Therefore it is placed in the middle of the list instead of
always being the first one.

Before the fix:
```
ip route 1.1.1.0/24 2.2.2.2 nexthop-vrf ccc
ip route 1.1.1.0/24 2.2.2.2
ip route 1.1.1.0/24 2.2.2.2 nexthop-vrf eee
```

After the fix:
```
ip route 1.1.1.0/24 2.2.2.2
ip route 1.1.1.0/24 2.2.2.2 nexthop-vrf ccc
ip route 1.1.1.0/24 2.2.2.2 nexthop-vrf eee
```

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2023-08-04 18:24:51 +03:00
Christian Hopps 579d00e167
Merge pull request #13838 from ak503/static_bfd_vrf
staticd: Fix bfd for static route in VRF
2023-06-27 11:34:50 -04:00
Christian Hopps 632440683f staticd: remove unused YANG module
Signed-off-by: Christian Hopps <chopps@labn.net>
2023-06-23 13:17:32 -04:00
Dmitrii Turlupov 7cc6b6b65f staticd: Fix bfd for static route in VRF
vrf BELLA
 ip route 1.1.1.1/32 192.168.1.1 bfd profile test
exit-vrf

Before patch:
# do show bfd peers
BFD Peers:
	peer 192.168.1.1 vrf default

After patch:
# do show bfd peers
BFD Peers:
	peer 192.168.1.1 vrf BELLA

Signed-off-by: Dmitrii Turlupov <turlupov@zts.ru>
2023-06-23 19:02:44 +03:00
Christian Hopps f7a2c2ab5a staticd: staticd no longer loads config files
We need to ignore SIGHUP rather than reload config now.

Signed-off-by: Christian Hopps <chopps@labn.net>
2023-06-12 02:02:18 -04:00
Christian Hopps 7aecb8639c lib: mgmtd: remove abstraction layer and other cleanup
Code is no longer using a global FE "client context", and instead
creates client objects, rename the structure and it's uses to reflect this.

Remove an obfuscating abstraction layer whose existence was entirely
based on using a uintptr_t rather than a pointer to an declared-only struct.

Change multi-duty "params" structure into a single duty callbacks one.

Remove unsupported API code.

Signed-off-by: Christian Hopps <chopps@labn.net>
2023-06-04 16:41:24 -04:00
Christian Hopps 43f7196f3a staticd: remove connect notify function, not needed
Signed-off-by: Christian Hopps <chopps@labn.net>
2023-05-28 05:13:22 -04:00
Christian Hopps 070c5e7a91 lib: msg: refactor common connection code from mgmtd
Signed-off-by: Christian Hopps <chopps@labn.net>
2023-05-28 05:13:22 -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
Christian Hopps 8033bf3976 mgmtd: lib: read transitioned daemons split config files in mgmtd
When daemons transition to mgmtd they should stop reading their split config
files, and let mgmtd do that, otherwise things can get out of sync.

Signed-off-by: Christian Hopps <chopps@labn.net>
2023-04-01 18:06:43 -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 cd9d053741 *: Convert struct event_master to struct event_loop
Let's find a better name for it.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2023-03-24 08:32:17 -04:00
Donald Sharp 2453d15dbf *: Convert struct thread_master to struct event_master and it's ilk
Convert the `struct thread_master` to `struct event_master`
across the code base.

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
Christian Hopps 39c329bbd1 lib: staticd: vtysh: apply frrbot style requirements
Signed-off-by: Christian Hopps <chopps@labn.net>
2023-03-22 05:22:56 +00:00
Christian Hopps 1462450eaa staticd: handle distance value
Signed-off-by: Christian Hopps <chopps@labn.net>
2023-03-22 05:22:56 +00:00
Christian Hopps d1e85e3600 mgmtd: Enroll Staticd as a backend client for MGMTD
This commmit introduces Staticd as a backend client for the MGMTd
framework. All the static commands will be diverted to the MGMT
daemon and will use the transactional model to make changes to the
internal state. Similar mechanism can be used by other daemons to use
the MGMT framework in the future.

This commit includes the following functionalities in the changeset:
1. Diverts all the staticd (config only) commands to MGMTd.
2. Enrolls staticd as a backend client to use the MGMT framework.
3. Modify the staticd NB config handlers so that they can be compiled
   into a library and loaded in the MGMTd process context.

Co-authored-by: Pushpasis Sarkar <pushpasis@gmail.com>
Co-authored-by: Abhinay Ramesh <rabhinay@vmware.com>
Co-authored-by: Ujwal P <ujwalp@vmware.com>
Signed-off-by: Yash Ranjan <ranjany@vmware.com>
2023-03-21 22:09:07 -04:00
Donald Sharp 7a185ac85e staticd: Tell bfd that we are shutting down
Prevent a use after free and tell the bfd subsystem
we are shutting down in staticd.

./bfd_topo3.test_bfd_topo3/r4.staticd.asan.2264460:==2264460==ERROR: AddressSanitizer: heap-use-after-free on address 0x61f000004698 at pc 0x7f65d1eb11b2 bp 0x7ffdbface490 sp 0x7ffdbface488
./bfd_topo3.test_bfd_topo3/r4.staticd.asan.2264460-READ of size 4 at 0x61f000004698 thread T0
./bfd_topo3.test_bfd_topo3/r4.staticd.asan.2264460-    #0 0x7f65d1eb11b1 in zclient_bfd_command lib/bfd.c:307
./bfd_topo3.test_bfd_topo3/r4.staticd.asan.2264460-    #1 0x7f65d1eb20f5 in _bfd_sess_send lib/bfd.c:507
./bfd_topo3.test_bfd_topo3/r4.staticd.asan.2264460-    #2 0x7f65d20510aa in thread_call lib/thread.c:1989
./bfd_topo3.test_bfd_topo3/r4.staticd.asan.2264460-    #3 0x7f65d2051f0a in _thread_execute lib/thread.c:2081
./bfd_topo3.test_bfd_topo3/r4.staticd.asan.2264460-    #4 0x7f65d1eb271b in _bfd_sess_remove lib/bfd.c:544
./bfd_topo3.test_bfd_topo3/r4.staticd.asan.2264460-    #5 0x7f65d1eb278d in bfd_sess_free lib/bfd.c:553
./bfd_topo3.test_bfd_topo3/r4.staticd.asan.2264460-    #6 0x7f65d1eb5400 in bfd_protocol_integration_finish lib/bfd.c:1029
./bfd_topo3.test_bfd_topo3/r4.staticd.asan.2264460-    #7 0x7f65d1f42f77 in hook_call_frr_fini lib/libfrr.c:41
./bfd_topo3.test_bfd_topo3/r4.staticd.asan.2264460-    #8 0x7f65d1f494a1 in frr_fini lib/libfrr.c:1199
./bfd_topo3.test_bfd_topo3/r4.staticd.asan.2264460-    #9 0x563b7abefd76 in sigint staticd/static_main.c:70
./bfd_topo3.test_bfd_topo3/r4.staticd.asan.2264460-    #10 0x7f65d200ef91 in frr_sigevent_process lib/sigevent.c:115
./bfd_topo3.test_bfd_topo3/r4.staticd.asan.2264460-    #11 0x7f65d204fac6 in thread_fetch lib/thread.c:1758
./bfd_topo3.test_bfd_topo3/r4.staticd.asan.2264460-    #12 0x7f65d1f49377 in frr_run lib/libfrr.c:1184
./bfd_topo3.test_bfd_topo3/r4.staticd.asan.2264460-    #13 0x563b7abefed1 in main staticd/static_main.c:160
./bfd_topo3.test_bfd_topo3/r4.staticd.asan.2264460-    #14 0x7f65d1b92d09 in __libc_start_main ../csu/libc-start.c:308
./bfd_topo3.test_bfd_topo3/r4.staticd.asan.2264460-    #15 0x563b7abefa99 in _start (/usr/lib/frr/staticd+0x15a99)
./bfd_topo3.test_bfd_topo3/r4.staticd.asan.2264460-

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2023-03-21 09:25:38 -04:00
David Lamparter cca918fe04 *: remove some leftover license blurbs
The regex'ing left some paragraphs that didn't exactly match.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2023-02-09 14:09:11 +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 7c734d8020 staticd: Add missing enum's to switch statement
Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2023-01-31 15:15:42 -05:00
Donald Sharp ea768492f1
Merge pull request #12695 from opensourcerouting/format-warnings
build: `-Wformat-nonliteral -Wformat-security`
2023-01-31 09:01:32 -05:00
David Lamparter ae08de9f42 *: fix non-const northbound XPath format strings
Passing a pre-formatted buffer in these places needs a `"%s"` in front
so it doesn't get formatted twice.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2023-01-27 12:01:20 +01:00
Louis Scalbert f6e7fbdae9 lib: remove concurrent nexthop zapi (un)registration
Daemons like staticd already implement nexthop zapi (un)registration.
b7ca809d1c ("lib: BFD automatic source selection") has implemented a
concurrent nexthop (un)registration. Some nexthop could be unregistred
by the bfd whereas they were still needed by the daemon.

Let the deamons deal with nexthop zapi (un)registration.

Fixes: b7ca809d1c ("lib: BFD automatic source selection")
Signed-off-by: Louis Scalbert <louis.scalbert@6wind.com>
2023-01-24 16:08:26 +01:00
Louis Scalbert a77ea81ef3 lib: do not reopen a zclient socket for bfd
b7ca809d1c ("lib: BFD automatic source selection") has added a dedicated
zclient socket for nht tracking. Since the bfd lib is used by daemons
that already has a zclient socket, those daemons has now a second
zclient socket. However, zebra does not distinguish the two zclient
sessions. For example, the interfaces are asked a second via
zebra_message_send(zclient, ZEBRA_INTERFACE_ADD, VRF_DEFAULT) in
zclient_start(). As a result, callbacks functions like bgp_ifp_create()
are called a second time, which causes some processing overhead and
might cause bugs.

Re-use the existing zclient socket for nht tracking.

Note that BFD automatic source selection is only currently implemented
in staticd. Other daemons will require to add the following in their
ZEBRA_NEXTHOP_UPDATE callback function:

> 	if (zclient->bfd_integration)
>		bfd_nht_update(&matched, &nhr);

Fixes: b7ca809d1c ("lib: BFD automatic source selection")
Signed-off-by: Louis Scalbert <louis.scalbert@6wind.com>
2023-01-24 16:08:04 +01:00
Philippe Guibert b27499d6ba staticd: add debug static bfd command
This command helps in troubleshooting static bfd feature.
Add traces upon bfd events.

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
2023-01-13 15:32:12 -03:00
Rafael Zalamena 4fd9906bcf staticd: fix bug on route reinstallation
When configuring a route with multiple next hops on boot and the
interface is missing the route never shows up (even after interface is
properly learned).

Fix: force route clean up by uninstalling it and putting it back
entirely instead of just updating the missing next hop.

Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
2023-01-13 15:32:12 -03:00
Rafael Zalamena d8c78a8db5 staticd: add command to show monitored routes
Add command to visualize all monitored routes and their state.

Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
2023-01-13 15:32:12 -03:00
Rafael Zalamena e280279d5a lib,staticd: BFD integration CLI commands
Implement the static route monitoring feature with BFD integration.

Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
2023-01-13 15:32:12 -03:00
Rafael Zalamena 351ad68405 staticd: BFD integration northbound support
Implement all BFD integration northbound callbacks and integrate BFD
with `staticd` route installation procedure.

Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
2023-01-13 15:32:12 -03:00
Donald Sharp 16c150f27b lib, staticd: return values even after an assert
When compiling with -fsanitize=thread.  I started getting this error:

staticd/static_zebra.c: In function ‘static_zebra_nht_get_prefix’:
staticd/static_zebra.c:316:1: error: control reaches end of non-void function [-Werror=return-type]
  316 | }
      | ^

Just to make future efforts still work, let's just make the compiler happy.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2022-12-16 07:38:58 -05:00
Donald Sharp b90a00d151
Merge pull request #12405 from opensourcerouting/static-improv
staticd: improve CLI/northbound translation code
2022-11-28 08:13:09 -05:00
Rafael Zalamena fc6f9d7425 staticd: improve CLI/northbound translation code
Simplify all DEFUNs by moving all logic to the northbound translation
function and transforming all function parameters into a single
structure.

Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
2022-11-25 16:26:10 -03:00
Donatas Abraitis 3278956b17 staticd: Do not crash when modifying an existing static route with color
```
$ vtysh -c 'conf' -c 'ip route 192.168.0.0/32 192.168.10.65 color 123'
$ vtysh -c 'show ip route 192.168.0.0/32 json' | jq '."192.168.0.0/32"[0].nexthops[0].srteColor'
123
$ vtysh -c 'conf' -c 'ip route 192.168.0.0/32 192.168.10.65'
$ vtysh -c 'show ip route 192.168.0.0/32 json' | jq '."192.168.0.0/32"[0].nexthops[0].srteColor'
0
```

Before this patch:
```
STATIC: Received signal 6 at 1666938633 (si_addr 0x4e1a, PC 0x7f295139c438); aborting...
STATIC: /home/u1/mGIT/frr-master/lib/.libs/libfrr.so.0(zlog_backtrace_sigsafe+0x70) [0x7f29519ef0a0]
STATIC: /home/u1/mGIT/frr-master/lib/.libs/libfrr.so.0(zlog_signal+0xec) [0x7f29519ef28c]
STATIC: /home/u1/mGIT/frr-master/lib/.libs/libfrr.so.0(+0xccee2) [0x7f2951a1aee2]
STATIC: /lib/x86_64-linux-gnu/libpthread.so.0(+0x11390) [0x7f2951742390]
STATIC: /lib/x86_64-linux-gnu/libc.so.6(gsignal+0x38) [0x7f295139c438]
STATIC: /lib/x86_64-linux-gnu/libc.so.6(abort+0x16a) [0x7f295139e03a]
STATIC: /home/u1/mGIT/frr-master/lib/.libs/libfrr.so.0(_zlog_assert_failed+0xe6) [0x7f2951a46766]
STATIC: /home/u1/mGIT/frr-master/lib/.libs/libfrr.so.0(+0xae7ee) [0x7f29519fc7ee]
STATIC: /home/u1/mGIT/frr-master/staticd/.libs/lt-staticd(routing_control_plane_protocols_control_plane_protocol_staticd_route_list_src_
STATIC: /home/u1/mGIT/frr-master/lib/.libs/libfrr.so.0(+0xaf264) [0x7f29519fd264]
STATIC: /home/u1/mGIT/frr-master/lib/.libs/libfrr.so.0(+0xafb4f) [0x7f29519fdb4f]
STATIC: /home/u1/mGIT/frr-master/lib/.libs/libfrr.so.0(nb_candidate_commit_apply+0x33) [0x7f29519fde33]
STATIC: /home/u1/mGIT/frr-master/lib/.libs/libfrr.so.0(nb_candidate_commit+0x9e) [0x7f29519fdf6e]
STATIC: /home/u1/mGIT/frr-master/lib/.libs/libfrr.so.0(+0xb0469) [0x7f29519fe469]
STATIC: /home/u1/mGIT/frr-master/lib/.libs/libfrr.so.0(+0xb3055) [0x7f2951a01055]
STATIC: /home/u1/mGIT/frr-master/lib/.libs/libfrr.so.0(nb_cli_apply_changes+0xd8) [0x7f2951a01358]
STATIC: /home/u1/mGIT/frr-master/staticd/.libs/lt-staticd() [0x407ec2]
STATIC: /home/u1/mGIT/frr-master/staticd/.libs/lt-staticd() [0x40a307]
STATIC: /home/u1/mGIT/frr-master/lib/.libs/libfrr.so.0(+0x74923) [0x7f29519c2923]
STATIC: /home/u1/mGIT/frr-master/lib/.libs/libfrr.so.0(cmd_execute_command+0xe4) [0x7f29519c2aa4]
STATIC: /home/u1/mGIT/frr-master/lib/.libs/libfrr.so.0(cmd_execute+0xc9) [0x7f29519c2c49]
STATIC: /home/u1/mGIT/frr-master/lib/.libs/libfrr.so.0(+0xe4184) [0x7f2951a32184]
STATIC: /home/u1/mGIT/frr-master/lib/.libs/libfrr.so.0(+0xe4436) [0x7f2951a32436]
STATIC: /home/u1/mGIT/frr-master/lib/.libs/libfrr.so.0(+0xe6fcc) [0x7f2951a34fcc]
STATIC: /home/u1/mGIT/frr-master/lib/.libs/libfrr.so.0(thread_call+0x98) [0x7f2951a2cc28]
STATIC: /home/u1/mGIT/frr-master/lib/.libs/libfrr.so.0(frr_run+0xe8) [0x7f29519e7518]
STATIC: /home/u1/mGIT/frr-master/staticd/.libs/lt-staticd(main+0xda) [0x40572a]
STATIC: /lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf0) [0x7f2951387840]
STATIC: /home/u1/mGIT/frr-master/staticd/.libs/lt-staticd(_start+0x29) [0x4058e9]
STATIC: in thread vtysh_read scheduled from lib/vty.c:2710 vty_event()
```

Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2022-11-25 16:22:34 +02:00
David Lamparter 89cb86aeb0 build, vtysh: extract vtysh commands from .xref
Rather than running selected source files through the preprocessor and a
bunch of perl regex'ing to get the list of all DEFUNs, use the data
collected in frr.xref.

This not only eliminates issues we've been having with preprocessor
failures due to nonexistent header files, but is also much faster.
Where extract.pl would take 5s, this now finishes in 0.2s.  And since
this is a non-parallelizable build step towards the end of the build
(dependent on a lot of other things being done already), the speedup is
actually noticeable.

Also files containing CLI no longer need to be listed in `vtysh_scan`
since the .xref data covers everything.  `#ifndef VTYSH_EXTRACT_PL`
checks are equally obsolete.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2022-10-26 17:12:34 +01:00
Donald Sharp 08040409cc staticd: Clean up zclient on shutdown
The zclient data structure was not being cleaned up on shutdown.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2022-10-12 07:39:23 -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
Donald Sharp eb6249d27d staticd: When changing the underlying nh ensure it is reinstalled
There exists some nexthop attributes that are not the unique
part of the nexthop and if you change the static route
with those values then the route is not being updated
in zebra with the new values:

Example of brokenness:

eva# conf
eva(config)# ip route 1.2.3.9/32 192.168.119.1 enp39s0 label 16020
eva(config)# do show ip route 1.2.3.9
Routing entry for 1.2.3.9/32
  Known via "static", distance 1, metric 0, best
  Last update 00:00:05 ago
  * 192.168.119.1, via enp39s0, label 16020, weight 1

eva(config)# ip route 1.2.3.9/32 192.168.119.1 enp39s0 label 16040
eva(config)# do show ip route 1.2.3.9
Routing entry for 1.2.3.9/32
  Known via "static", distance 1, metric 0, best
  Last update 00:00:12 ago
  * 192.168.119.1, via enp39s0, label 16020, weight 1

Fixed behavior:

eva# conf
eva(config)# ip route 1.2.3.10/32 192.168.119.1 enp39s0 label 16020
eva(config)# do show ip route 1.2.3.10
Routing entry for 1.2.3.10/32
  Known via "static", distance 1, metric 0, best
  Last update 00:00:04 ago
  * 192.168.119.1, via enp39s0, label 16020, weight 1

eva(config)# ip route 1.2.3.10/32 192.168.119.1 enp39s0 label 16040
eva(config)# do show ip route 1.2.3.10
Routing entry for 1.2.3.10/32
  Known via "static", distance 1, metric 0, best
  Last update 00:00:01 ago
  * 192.168.119.1, via enp39s0, label 16040, weight 1

I've gone through most of the items in staticd that can change
the nexthop
Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2022-08-08 16:02:40 -04:00
David Lamparter c006c875e7 staticd: redo VRF_DEFAULT NHT registers on connect
Other VRFs get VRF_ADD notifications from zebra which triggers
static_fixup_vrf_ids, but since the default VRF is implicit we need to
make that same call on connect.

This should fix problems with staticd being started before (or
concurrent with and thus racing) zebra.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2022-04-24 17:21:09 +02:00
David Lamparter f75d39259c staticd: merge NHT register & update, reorganize
nh_update is only called in two places and both precede a matching
follow-up nht_register call.  Fold the update into register, and make
register do the right thing™ for all cases (i.e. update refcounts as
needed, and retry zebra NHT registration if it failed before).

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2022-04-24 17:19:47 +02:00
David Lamparter ecb490350e staticd: use double pointer for NHT decref
Since this is a free()-type function, clear the caller's pointer to
NULL to aid static analysis and prevent UAF bugs.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2022-04-24 17:01:16 +02:00
David Lamparter c68cd5af44 staticd: minor refactor NHT register code
Put static_nexthop -> prefix code into a small helper, remove extra
prefix variable, and grab AFI from prefix.

This commit should not result in any functional change.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2022-04-24 15:47:58 +02:00
Donald Sharp 61879cab13 *: Fix spelling of Inteface
Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2022-04-02 07:46:19 -04:00
David Lamparter 6bcc46657e staticd: track nexthops per-SAFI
This stops intermixing SAFI_UNICAST NHT into SAFI_MULTICAST static
routes.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2022-03-27 14:57:22 +02:00
David Lamparter e203efe87b staticd: use inline prefix in NHT data
No need to waste malloc overhead on this.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2022-03-27 14:57:22 +02:00
David Lamparter 50efe4be1f staticd: use typesafe static_nht_hash
Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2022-03-27 14:57:22 +02:00
David Lamparter eb3c9d9774 *: add SAFI argument to zclient_send_rnh
Just pushing that SAFI_UNICAST up 1 level to the caller.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2022-03-27 14:57:22 +02:00
Donald Sharp 06e4e90132 *: When matching against a nexthop send and process what it matched against
Currently the nexthop tracking code is only sending to the requestor
what it was requested to match against.  When the nexthop tracking
code was simplified to not need an import check and a nexthop check
in b8210849b8 for bgpd.  It was not
noticed that a longer prefix could match but it would be seen
as a match because FRR was not sending up both the resolved
route prefix and the route FRR was asked to match against.

This code change causes the nexthop tracking code to pass
back up the matched requested route (so that the calling
protocol can figure out which one it is being told about )
as well as the actual prefix that was matched to.

Fixes: #10766
Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2022-03-12 11:18:45 -05:00
Jafar Al-Gharaibeh 5ff968abbe
Merge pull request #10678 from donaldsharp/staticd_make_check_fix
staticd: Fix `make check` failures
2022-02-28 09:40:12 -06:00
Donald Sharp 7c1e76aa8d staticd: Fix make check failures
Recent commit:
abc246e193

Has broken `make check` with recently new compilers:

/usr/bin/ld: staticd/libstatic.a(static_nb_config.o): warning: relocation against `zebra_ecmp_count' in read-only section `.text'
  CCLD     tests/bgpd/test_peer_attr
  CCLD     tests/bgpd/test_packet
/usr/bin/ld: staticd/libstatic.a(static_zebra.o): in function `static_zebra_capabilities':
/home/sharpd/frr5/staticd/static_zebra.c:208: undefined reference to `zebra_ecmp_count'
/usr/bin/ld: staticd/libstatic.a(static_zebra.o): in function `static_zebra_route_add':
/home/sharpd/frr5/staticd/static_zebra.c:418: undefined reference to `zebra_ecmp_count'
/usr/bin/ld: staticd/libstatic.a(static_nb_config.o): in function `static_nexthop_create':
/home/sharpd/frr5/staticd/static_nb_config.c:174: undefined reference to `zebra_ecmp_count'
/usr/bin/ld: /home/sharpd/frr5/staticd/static_nb_config.c:175: undefined reference to `zebra_ecmp_count'
/usr/bin/ld: warning: creating DT_TEXTREL in a PIE
collect2: error: ld returned 1 exit status
make: *** [Makefile:8679: tests/lib/test_grpc] Error 1
make: *** Waiting for unfinished jobs....

Essentially the newly introduced variable zebra_ecmp_count is not available in the
libstatic.a compiled and make check has code that compiles against it.

The fix is to just move the variable to the library.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2022-02-28 08:18:55 -05:00
Xiao Liang f1d6b7e36e staticd: Don't register existing nexthop to zebra
Zebra sends a nexthop-update message on registeration, which will cause
existing routes to be reconfigured even no changes actually happened.
Don't register the nexthop again if it's already done.

Signed-off-by: Xiao Liang <shaw.leon@gmail.com>
2022-02-28 18:08:49 +08:00
Mark Stapp 1f7ab1a2cc staticd: reject route config with too many nexthops
Restrict the number of nexthops for a route to the compiled-in
limit. Be careful with the zapi route struct's array of nexthops
too.

Signed-off-by: Mark Stapp <mstapp@nvidia.com>
2022-02-17 09:56:40 -05:00
Mark Stapp abc246e193 staticd: capture zebra's advertised ECMP limit
Capture the ECMP limit advertised by zebra (via zapi).

Signed-off-by: Mark Stapp <mstapp@nvidia.com>
2022-02-17 09:54:15 -05:00
Mark Stapp 423e32cb01 staticd: fix spelling in an error message
whitespace change to fix a typo.

Signed-off-by: Mark Stapp <mstapp@nvidia.com>
2022-02-17 09:48:07 -05:00
anlan_cs 32c0a2dd2c staticd: small cleanup
Two small cleanups, just remove duplication.

Signed-off-by: anlan_cs <vic.lan@pica8.com>
2022-01-31 18:44:17 +08:00
Igor Ryzhov ac2cb9bf94 *: rework renaming the default VRF
Currently, it is possible to rename the default VRF either by passing
`-o` option to zebra or by creating a file in `/var/run/netns` and
binding it to `/proc/self/ns/net`.

In both cases, only zebra knows about the rename and other daemons learn
about it only after they connect to zebra. This is a problem, because
daemons may read their config before they connect to zebra. To handle
this rename after the config is read, we have some special code in every
single daemon, which is not very bad but not desirable in my opinion.
But things are getting worse when we need to handle this in northbound
layer as we have to manually rewrite the config nodes. This approach is
already hacky, but still works as every daemon handles its own NB
structures. But it is completely incompatible with the central
management daemon architecture we are aiming for, as mgmtd doesn't even
have a connection with zebra to learn from it. And it shouldn't have it,
because operational state changes should never affect configuration.

To solve the problem and simplify the code, I propose to expand the `-o`
option to all daemons. By using the startup option, we let daemons know
about the rename before they read their configs so we don't need any
special code to deal with it. There's an easy way to pass the option to
all daemons by using `frr_global_options` variable.

Unfortunately, the second way of renaming by creating a file in
`/var/run/netns` is incompatible with the new mgmtd architecture.
Theoretically, we could force daemons to read their configs only after
they connect to zebra, but it means adding even more code to handle a
very specific use-case. And anyway this won't work for mgmtd as it
doesn't have a connection with zebra. So I had to remove this option.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2021-12-21 22:09:29 +03:00
Igor Ryzhov e122fe6b50 staticd: remove unnecessary function call
When the VRF interface is coming up, we don't need to fixup VRF ids - it
was already done in static_vrf_enable when the interface was created.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2021-11-23 12:46:21 +03:00
Igor Ryzhov 096f7609f9 *: cleanup ifp->vrf_id
Since f60a1188 we store a pointer to the VRF in the interface structure.
There's no need anymore to store a separate vrf_id field.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2021-11-22 20:47:23 +03:00
David Lamparter 1e9044be8d *: clean up ifp-by-local-address function(s)
Most users of if_lookup_address_exact only cared about whether the
address is any local address.  Split that off into a separate function.

For the users that actually need the ifp - which I'm about to add a few
of - change it to prefer returning interfaces that are UP.

(Function name changed due to slight change in behavior re. UP state, to
avoid possible bugs from this change.)

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2021-11-17 11:17:44 +01:00
Donald Sharp 7cc91e67a3 *: Convert quagga_signal_X to frr_signal_X
Naming functions/data structures more appropriately for
the project we are actually in.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2021-11-11 14:41:27 -05:00