Commit Graph

5443 Commits

Author SHA1 Message Date
Carmine Scarpitta
7f2dec4f09 zebra: Fix crash when dplane_fpm_nl fails to process received routes
When `dplane_fpm_nl` receives a route, it allocates memory for a dplane
context and calls `netlink_route_change_read_unicast_internal` without
initializing the `intf_extra_list` contained in the dplane context. If
`netlink_route_change_read_unicast_internal` is not able to process the
route, we call `dplane_ctx_fini` to free the dplane context. This causes
a crash because `dplane_ctx_fini` attempts to access the intf_extra_list
which is not initialized.

To solve this issue, we can call `dplane_ctx_route_init`to initialize
the dplane route context properly, just after the dplane context
allocation.

(gdb) bt
#0 0x0000555dd5ceae80 in dplane_intf_extra_list_pop (h=0x7fae1c007e68) at ../zebra/zebra_dplane.c:427
#1 dplane_ctx_free_internal (ctx=0x7fae1c0074b0) at ../zebra/zebra_dplane.c:724
#2 0x0000555dd5cebc99 in dplane_ctx_free (pctx=0x7fae2aa88c98) at ../zebra/zebra_dplane.c:869
#3 dplane_ctx_free (pctx=0x7fae2aa88c98, pctx@entry=0x7fae2aa78c28) at ../zebra/zebra_dplane.c:855
#4 dplane_ctx_fini (pctx=pctx@entry=0x7fae2aa88c98) at ../zebra/zebra_dplane.c:890
#5 0x00007fae31e93f29 in fpm_read (t=) at ../zebra/dplane_fpm_nl.c:605
#6 0x00007fae325191dd in thread_call (thread=thread@entry=0x7fae2aa98da0) at ../lib/thread.c:2006
#7 0x00007fae324c42b8 in fpt_run (arg=0x555dd74777c0) at ../lib/frr_pthread.c:309
#8 0x00007fae32405ea7 in start_thread () from /lib/x86_64-linux-gnu/libpthread.so.0
#9 0x00007fae32325a2f in clone () from /lib/x86_64-linux-gnu/libc.so.6

Fixes: #13754
Signed-off-by: Carmine Scarpitta <carmine.scarpitta@uniroma2.it>
2023-07-07 10:59:28 +02:00
Carmine Scarpitta
745a0fcbb2 zebra: Abstract dplane_ctx_route_init to init route without copying
The function `dplane_ctx_route_init` initializes a dplane route context
from the route object passed as an argument. Let's abstract this
function to allow initializing the dplane route context without actually
copying a route object.

This allows us to use this function for initializing a dplane route
context when we don't have any route to copy in it.

Signed-off-by: Carmine Scarpitta <carmine.scarpitta@uniroma2.it>
2023-07-07 10:59:28 +02:00
Russ White
1e9e82e803
Merge pull request #13396 from donaldsharp/interface_is_interface
move interface ( LINK and ADDR ) events to the dplane
2023-07-06 08:31:16 -04:00
Donatas Abraitis
2ec7477a26
Merge pull request #13808 from anlancs/fix/zebra-kernel-route-reserved
zebra: fix wrong nexthop check for kernel routes
2023-07-06 09:01:21 +03:00
Donald Sharp
605df8d44f zebra: Use zebra dplane for RTM link and addr
a) Move the reads of link and address information
into the dplane
b) Move the startup read of data into the dplane
as well.
c) Break up startup reading of the linux kernel data
into multiple phases.  As that we have implied ordering
of data that must be read first and if the dplane has
taken over some data reading then we must delay initial
read-in of other data.

Fixes: #13288
Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2023-07-05 13:03:14 -04:00
Donald Sharp
a014450441 zebra: Add code to get/set interface to pass up from dplane
1) Add a bunch of get/set functions and associated data
structure in zebra_dplane to allow the setting and retrieval
of interface netlink data up into the master pthread.

2) Add a bit of code to breakup startup into stages.  This is
because FRR currently has a mix of dplane and non dplane interactions
and the code needs to be paused before continuing on.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2023-07-05 13:03:14 -04:00
Donald Sharp
487a96a35f zebra: Remove duplicate function for netlink interface changes
Turns out FRR has 2 functions one specifically for startup
and one for normal day to day operations.  There were only
a couple of minor differences from what I could tell, and
where they were different the after startup functionality should
have been updated too.  I cannot figure out why we have 2.

Non-startup handling of bonds appears to be incorrect
so let's fix that.  Additionally the speed was not
properly being set in non-startup situations.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2023-07-05 13:03:14 -04:00
Donald Sharp
bc0bac5524 zebra: Remove unused add variable
Function was not using the add variable.  Remove it.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2023-07-05 11:49:36 -04:00
Donald Sharp
cd7324dfa6 zebra: Remove unused dplane_intf_delete
There is no need for this functionality and it is
not used.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2023-07-05 11:49:36 -04:00
Donald Sharp
c3c9683f99 zebra: Move protodown_r_bit to a better spot
Since we are moving some code handling out of the dataplane
and into zebra proper, lets move the protodown r bit as well.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2023-07-05 11:49:36 -04:00
Donald Sharp
6a3ae11c9b zebra: Rename vrf_lookup_by_tableid to zebra_vrf_lookup..
Rename the vrf_lookup_by_id function to zebra_vrf_lookup_by_id
and move to zebra_vrf.c where it nominally belongs, as that
we need zebra specific data to find this vrf_id and as such
it does not belong in vrf.c

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2023-07-05 11:49:36 -04:00
Mark Stapp
d6caf0dbd7
Merge pull request #13875 from donaldsharp/static_dplane_issues
zebra: Static routes async notification do not need this test
2023-07-05 08:27:23 -04:00
Donatas Abraitis
9a0bb7bcd1
Merge pull request #13333 from donaldsharp/vrf_bitmap_cleanup
*: Rearrange vrf_bitmap_X api to reduce memory footprint
2023-07-04 22:11:11 +03:00
anlan_cs
098519caf8 zebra: fix wrong nexthop check for kernel routes
When changing one interface's vrf, the kernel routes are wrongly kept
in old vrf.  Finally, the forwarding table in that old vrf can't forward
traffic correctly for those residual entries.

Follow these steps to make this problem happen:
( Firstly, "x1" interface of default vrf is with address of "6.6.6.6/24". )

```
anlan# ip route add 4.4.4.0/24 via 6.6.6.8 dev x1
anlan# ip link add vrf1 type vrf table 1
anlan# ip link set vrf1 up
anlan# ip link set x1 master vrf1
```

Then check `show ip route`, the route of "4.4.4.0/24" is still selected
in default vrf.

If the interface goes down, the kernel routes will be reevaluated.  Those
kernel routes with active interface of nexthop can be kept no change, it
is a fast path.  Otherwise, it enters into slow path to do careful examination
on this nexthop.

After the interface's vrf had been changed into new vrf, the down message of
this interface came.  It means the interface is not in old vrf although it
still exists during that checking, so the kernel routes should be dropped
after this nexthop matching against a default route in slow path. But, in
current code they are wrongly kept in fast path for not checking vrf.

So, modified the checking active nexthop with vrf comparision for the interface
during reevaluation.

Signed-off-by: anlan_cs <vic.lan@pica8.com>
2023-07-02 10:30:09 +08:00
anlan_cs
caf896d6ef zebra: Remove unnecessary condition check for kernel routes
There are relaxed nexthop requirements for kernel routes because we
trust kernel routes.

Two minor changes for kernel routes:

1. `if_is_up()` is one of the necessary conditions for `if_is_operative()`.
Here, we can remove this unnecessary check for clarity.

2. Since `nexthop_active()` doesn't distinguish whether it is kernel route,
modified the corresponding comment in it.

Signed-off-by: anlan_cs <vic.lan@pica8.com>
2023-07-02 10:30:09 +08:00
Donatas Abraitis
64510b9467 zebra: Dump route details when deleting a route
Just more details what's going on when deleting a route.

Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2023-06-29 17:39:45 +03:00
Donald Sharp
d0123a9012 zebra: Static routes async notification do not need this test
When using asic_offload with an asynchronous notification the
rib_route_match_ctx function is testing for distance and tag
being correct against the re.

Normal route notification for static routes is this(well really all routes):
a) zebra dplane generates a ctx to send to the dplane for route install
b) dplane installs it in the kernel
c) if the dplane_fpm_nl.c module is being used it installs it.
d) The context's success code is set to it worked and passes the context
back up to zebra for processing.
e) Zebra master receives this and checks the distance and tag are correct
for static routes and accepts the route and marks it installed.

If the operator is using a wait for install mechansim where the dplane
is asynchronously sending the result back up at a future time *and*
it is using the dplane_fpm_nl.c code where it uses the rt_netlink.c
route parsing code, then there is no way to set distance as that we
do not pass distance to the kernel.

As such static routes were never being properly handled since the re and
context would not match and the route would still be marked as queued.

Modify the code such that the asynchronous path notification for static
routes ignores the distance and tag's as that there is no way to test
for this data from that path at this point in time.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2023-06-29 09:35:00 -04:00
Mark Stapp
59b8965aa6
Merge pull request #13861 from opensourcerouting/fix/memory_leak_zserv
zebra: Free Zebra client resources
2023-06-28 08:18:11 -04:00
Donatas Abraitis
97072d144e zebra: Free Zebra client resources
Memory leaks started flowing:

```
AddressSanitizer Topotests Part 0:  15 KB -> 283 KB
AddressSanitizer Topotests Part 1:  1 KB -> 495 KB
AddressSanitizer Topotests Part 2:  13 KB -> 478 KB
AddressSanitizer Topotests Part 3:  39 KB -> 213 KB
AddressSanitizer Topotests Part 4:  30 KB -> 836 KB
AddressSanitizer Topotests Part 5:  0 bytes -> 356 KB
AddressSanitizer Topotests Part 6:  86 KB -> 783 KB
AddressSanitizer Topotests Part 7:  0 bytes -> 354 KB
AddressSanitizer Topotests Part 8:  0 bytes -> 62 KB
AddressSanitizer Topotests Part 9:  408 KB -> 518 KB
```

```
Direct leak of 3584 byte(s) in 1 object(s) allocated from:
    #0 0x7f1957b02d28 in __interceptor_calloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xded28)
    #1 0x559895c55df0 in qcalloc lib/memory.c:105
    #2 0x559895bc1cdf in zserv_client_create zebra/zserv.c:743
    #3 0x559895bc1cdf in zserv_accept zebra/zserv.c:880
    #4 0x559895cf3438 in event_call lib/event.c:1995
    #5 0x559895c3901c in frr_run lib/libfrr.c:1213
    #6 0x559895a698f1 in main zebra/main.c:472
    #7 0x7f195635ec86 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21c86)
```

Fixes b20acd0 ("bgpd: Use synchronous way to get labels from Zebra")

Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2023-06-27 22:48:39 +03:00
Russ White
1f08a055a8
Merge pull request #13852 from mjstapp/fix_opq_cov_msg
zebra: clean up coverity warning in opaque api
2023-06-27 11:28:31 -04:00
Chirag Shah
a7d77ee58b zebra: fix evpn rmac nh list cmp function
EVPN RMAC (Router MAC) nexthop list compare
function needs to return all values so
the list element can be compared and added/deleted
properly.

Ticket:#3486989
Testing Done:
Originate EVPN Type-5 route with PIP IP and MAC as remote
nexthops.
Change the PIP IP address which triggers nexthop change.

Before fix:
When PIP IP changes RMAC is deleted from remote VTEPs.

TORS1# show evpn next-hops vni 4001 | include 00:02:00:00:00:2d
27.0.0.11       00:02:00:00:00:2d
TORS1# show evpn rmac vni 4001 | include 00:02:00:00:00:2d
00:02:00:00:00:2d 27.0.0.11

----- Remote VTEP change nexthop IP to 172.16.16.16 -----

TORS1# show evpn next-hops vni 4001 | include 00:02:00:00:00:2d
172.16.16.16    00:02:00:00:00:2d
TORS1# show evpn rmac vni 4001 | include 00:02:00:00:00:2d
TORS1#

After fix:
RMAC is retained as its nexthop list is not empty,
thus it is not deleted from remote VTEPs.

TORS1# show evpn rmac vni 4001 | include 00:02:00:00:00:2d
00:02:00:00:00:2d 172.16.16.16

Log:
2023/06/27 00:50:36.833474 ZEBRA: [XREH0-ZYMH6] L3VNI 4001 Remote VTEP
change(27.0.0.11 -> 172.16.16.16) for RMAC 00:02:00:00:00:2d

Signed-off-by: Chirag Shah <chirag@nvidia.com>
2023-06-26 17:59:16 -07:00
Donald Sharp
161972c9fe *: Rearrange vrf_bitmap_X api to reduce memory footprint
When running all daemons with config for most of them, FRR has
sharpd@janelle:~/frr$ vtysh -c "show debug hashtable"  | grep "VRF BIT HASH" | wc -l
3570

3570 hashes for bitmaps associated with the vrf.  This is a very
large number of hashes.  Let's do two things:

a) Reduce the created size of the actually created hashes to 2
instead of 32.

b) Delay generation of the hash *until* a set operation happens.
As that no hash directly implies a unset value if/when checked.

This reduces the number of hashes to 61 in my setup for normal
operation.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2023-06-26 14:59:21 -04:00
Mark Stapp
0ee56dd332 zebra: clean up coverity warning in opaque api
Seems a bit fussy of coverity, but ... don't NULL a variable
unnecessarily.

Signed-off-by: Mark Stapp <mjs@labn.net>
2023-06-26 13:19:23 -04:00
Mark Stapp
de1a9ce0a7 zebra: support notifications for opaque ZAPI messages
Allow zapi clients to register to be notified when a server
for an  opaque message type is present. Zebra maintains these
notification registrations in the same data structures that it
uses for opaque message handling.

Signed-off-by: Mark Stapp <mjs@labn.net>
2023-06-23 08:57:37 -04:00
Mark Stapp
ef8e3ac02c lib, zebra: include source client zapi info in opaque messages
Include the sending zapi client info (proto, instance, and
session id) in each opaque zapi message. Add opaque 'init'
apis for clients who want to encode their opaque data inline,
into the zclient's internal stream buffer. Use these init apis
in the TE/link-state lib code, instead of hand-coding the
zapi opaque header info.

Signed-off-by: Mark Stapp <mjs@labn.net>
2023-06-23 08:27:42 -04:00
Donatas Abraitis
3cbc7150bb
Merge pull request #13545 from idryzhov/remove-bond-slave
zebra: remove ZEBRA_IF_BOND_SLAVE interface type
2023-06-23 11:01:19 +03:00
Donatas Abraitis
52dde8747b zebra: Ignore non GR-aware zclient handling for BGP
This is for synchronous client (label/table manager) - aka session_id == 1.

Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2023-06-20 20:50:40 +03:00
Donatas Abraitis
20c2c8787a zebra: Show session id when printing an error when the client disconnects
Before:

```
2023/06/18 22:00:42 ZEBRA: [VXKFG-8SJRV][EC 4043309121] Client 'bgp' encountered an error and is shutting down.
2023/06/18 22:00:42 ZEBRA: [VXKFG-8SJRV][EC 4043309121] Client 'bgp' encountered an error and is shutting down.
```

After:

```
2023/06/18 22:06:44 ZEBRA: [N5M5Y-J5BPG][EC 4043309121] Client 'bgp' (session id 0) encountered an error and is shutting down.
2023/06/18 22:06:44 ZEBRA: [N5M5Y-J5BPG][EC 4043309121] Client 'bgp' (session id 1) encountered an error and is shutting down.
```

Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2023-06-20 20:50:40 +03:00
Russ White
40502902f4
Merge pull request #13394 from mjstapp/fix_zebra_mpls_config
zebra: clarify interface-level mpls config
2023-06-20 09:10:53 -04:00
Donald Sharp
f89d090230
Merge pull request #13755 from LabNConsulting/ziemba/zebra-dplane-priority
zebra: bugfix dplane priority sorting
2023-06-13 10:36:57 -04:00
Mark Stapp
a32d40a676 zebra: clarify interface-level mpls config
We have both interface-level configuration to enable mpls,
and runtime mpls status. They need to be distinct.

Signed-off-by: Mark Stapp <mjs@labn.net>
2023-06-12 16:41:27 -04:00
Mark Stapp
4112baec9f pbrd, zebra: fix zapi and netlink rule encoding
In pbrd, don't encode a rule without a table. There are cases
where the zapi encoding was incorrect because the 4-octet
table id was missing. In zebra, mask off the ECN bits in the
TOS byte when encoding an iprule to match netlink's
expectation.

Signed-off-by: Mark Stapp <mjs@labn.net>
2023-06-12 16:39:26 -04:00
G. Paul Ziemba
9e5c9e6d65 zebra: bugfix dplane priority sorting
Signed-off-by: G. Paul Ziemba <paulz@labn.net>
2023-06-09 06:58:20 -07:00
Donald Sharp
977d7e24ff zebra: Prevent crash because nl is NULL on shutdown
When shutting down the main pthread was first closing
the sockets associated with the dplane pthread and
then telling it to shutdown the pthread at a later point
in time.  This caused the dplane to crash because the nl
data has been freed already.  Change the shutdown order
to stop the dplane pthread *and* then close the sockets.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2023-06-08 12:03:49 -04:00
Donatas Abraitis
29f6fb04d8
Merge pull request #13649 from donaldsharp/unlock_the_node_or_else
zebra: Unlock the route node when sending route notifications
2023-06-06 08:52:40 +03:00
Donald Sharp
3ddf7680fd zebra: Consolidate the stream_failure section with normal return
Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2023-06-01 08:58:16 -04:00
Donald Sharp
c2cf522347 zebra: No need to set msg to NULL
The msg value is always reset to something new before it is used inside
the mutex.  No need to set it to NULL.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2023-06-01 08:54:25 -04:00
Donald Sharp
82c6e4fea5 zebra: Unlock the route node when sending route notifications
When using a context to send route notifications to upper
level protocols, the code was using a locking function to
get the route node.  There is no need for this to be locked
as such FRR should free it up.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2023-06-01 07:35:12 -04:00
Donatas Abraitis
147c7a2de3
Merge pull request #13631 from donaldsharp/fix_some_ping_issues
various issues
2023-05-30 21:26:24 +03:00
Christian Hopps
ff6b14a658 zebra: use ifindex vs ifp to avoid use-after-free on shutdown
Signed-off-by: Christian Hopps <chopps@labn.net>
2023-05-30 04:09:29 -04:00
Christian Hopps
8cfe36bc7e zebra: avoid unneeded vxlan work on shutdown
Signed-off-by: Christian Hopps <chopps@labn.net>
2023-05-30 04:09:29 -04:00
Donald Sharp
46d725f76b lib, zebra: Ensure that the ifp->node exists
On removal, ensure that the ifp->node is set to a null
pointer so that FRR does not use data after freed.
In addition ensure that the ifp->node exists before
attempting to free it.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2023-05-28 10:13:16 -04:00
Russ White
7b7da41def
Merge pull request #13556 from donaldsharp/token_to_desc
memory desciprtion shortening
2023-05-23 08:21:51 -04:00
Donald Sharp
d7c9666e06 zebra: Fix paths that have already de-refed ctx
There is no path in some functions where the ctx
has not already been de-refed.  As such no need
to test for it's existence.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2023-05-22 10:52:54 -04:00
Igor Ryzhov
9ce24c31bf zebra: remove ZEBRA_IF_BOND_SLAVE interface type
It is never actually used in the code.

Closes #13532.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2023-05-21 23:37:39 +03:00
Donald Sharp
a01f310709 zebra: Make memory description string smaller to fit in vty space
Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2023-05-19 21:31:35 -04:00
Donald Sharp
5ec001aa53 zebra: On shutdown stop hook calls for fpm rmac updates
When shutting down zebra, the hook for the rmac update was
not being unregistered.  As such it would be possible
to get into a condition where more rmacs are being
added to the queue for handling in the future after we
are told to shutdown.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2023-05-19 10:02:19 -04:00
Donald Sharp
540334324c zebra: Properly handle zfpm_g->t_conn_down in zebra_fpm.c
The t_conn_down pointer was being set to NULL when it already
was.  The t_conn_down pointer was being dropped( and leaving
a thread possibly running in the background ) which could
cause problems on shutdown.  And finally when shutting down
the t_conn_down event was not being stopped at all.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2023-05-19 10:02:19 -04:00
Donald Sharp
0eaa6523f6 zebra: Do not allow old FPM to access freed memory after shutdown
On shutdown, the old FPM queues up dests to be sent to
the FPM listener.  This is done through the rib_shutdown
hook.  Which is called when the table that the routes are
stored in are being deleted.  This dest has pointers
to the rnode.  The rnode has pointers to the table it
is associated with as well as the table->info pointer for
the zebra data associated with this table.

The FPM after this attempts to tell this to it's listener
via events.  Unfortunately the zvrf, table_id and nl_pid
was being grabbed from memory that had been freed!  Since
all this can be grabbed from memory that has not been freed
on shutdown let's switch over to using that instead of freed
memory for gathering data.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2023-05-19 10:02:19 -04:00
Carmine Scarpitta
eb68d4a04c zebra: Fix build error when --disable-bfdd
When FRR is built with the option `--disable-bfdd`, the build process
fails with the following error:

```
zebra/zebra_ptm.c: In function ‘zebra_ptm_init’:
zebra/zebra_ptm.c:119:35: error: ‘FRR_PTM_NAME’ undeclared (first use in this function)
  119 |  snprintf(buf, sizeof(buf), "%s", FRR_PTM_NAME);
      |                                   ^~~~~~~~~~~~
zebra/zebra_ptm.c:119:35: note: each undeclared identifier is reported only once for each function it appears in
make[1]: *** [Makefile:10520: zebra/zebra_ptm.o] Error 1
```

The reason is that `FRR_PTM_NAME` is defined in `version.h` which is not
imported.

This commit adds the missing import.

Signed-off-by: Carmine Scarpitta <carmine.scarpitta@uniroma2.it>
2023-05-17 18:47:23 +02:00