Commit Graph

614 Commits

Author SHA1 Message Date
Spoorthi K
4a563f2714 zebra_fpm: Add support for other protocols in fpm:netlink
fpm:netlink format doesn't indicate the protocol information
    in routes of BGP, OSPF and other protocols. Routes of those
    protocols just indicate protocol as zebra.

    The below route is actually BGP route but 'proto': 11
    indicates that it is zebra.

    {'attrs': [('RTA_DST', 'dummy'),
               ('RTA_PRIORITY', 0),
               ('RTA_GATEWAY', 'dummy'),
               ('RTA_OIF', 2)],
     'dst_len': 32,
     'family': 2,
     'flags': 0,
     'header': {'flags': 1025,
                'length': 60,
                'pid': 3160253895,
                'sequence_number': 0,
                'type': 24},
     'proto': 11,
     'scope': 0,
     'src_len': 0,
     'table': 254,
     'tos': 0,
     'type': 1}

    with this change it is now seen with 'proto': 186
    indicates that it is BGP.

    {'attrs': [('RTA_DST', 'dummy'),
               ('RTA_PRIORITY', 0),
               ('RTA_GATEWAY', 'dummy'),
               ('RTA_OIF', 2)],
     'dst_len': 32,
     'family': 2,
     'flags': 0,
     'header': {'flags': 1025,
                'length': 60,
                'pid': 3160253895,
                'sequence_number': 0,
                'type': 24},
     'proto': 186,
     'scope': 0,
     'src_len': 0,
     'table': 254,
     'tos': 0,
     'type': 1}

Signed-off-by: Spoorthi K <spk@redhat.com>
2023-01-24 09:48:21 +05:30
Russ White
bb1d52b3c0
Merge pull request #12604 from donaldsharp/distance_metric_offload_fixes
Distance/metric offload fixes
2023-01-18 15:57:48 -05:00
anlan_cs
64a29a00f7 zebra: cosmetic changes for debug
Just remove redundant white spaces in debug information.

Before:
```
2023/01/11 05:04:48 ZEBRA: [W8V7C-6W4DS] init neigh ctx NEIGH_INSTALL: ifp vlan100, mac  9a:68:e9:73:74:88, ip 88.88.88.88
2023/01/11 05:04:48 ZEBRA: [NH6N7-54CD1] Tx RTM_NEWNEIGH family ipv4 IF vlan100(8) Neigh 88.88.88.88 MAC  9a:68:e9:73:74:88 flags 0x10 state 0x40 ext_flags 0x0
```

After:
```
2023/01/11 05:17:26 ZEBRA: [W8V7C-6W4DS] init neigh ctx NEIGH_INSTALL: ifp vlan100, mac 9a:68:e9:73:74:88, ip 88.88.88.88
2023/01/11 05:17:26 ZEBRA: [NH6N7-54CD1] Tx RTM_NEWNEIGH family ipv4 IF vlan100(8) Neigh 88.88.88.88 MAC 9a:68:e9:73:74:88 flags 0x10 state 0x40 ext_flags 0x0
```

Signed-off-by: anlan_cs <vic.lan@pica8.com>
2023-01-11 18:16:40 +08:00
Donald Sharp
68ff69fa27 zebra: Set metric appropriately on route offload to asic
When FRR receives a route from the kernel about the route
offload success/failure.  The metric being reported is not
going to be correct since we may not know it appropriately
at this point in time.  If we can set the metric to something
appropriate.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2023-01-05 14:31:36 -05:00
Yutaro Hayakawa
45c129948c fpm: Send NH message to FPM even if the local kernel doesn't support it
netlink_route_multipath_msg_encode checks whether the local kernel
supports NextHop Netlink message and doesn't send the message if the
local kernel doesn't have support. This is also applied to the FPM since
kernel dataplane and FPM shares the same code. However, for the FPM,
it's not necessary to have this limit.

This commit adds extra check if netlink_route_multipath_msg_encode is
called from the FPM and bypass kernel support check if it is from the
FPM.

Signed-off-by: Yutaro Hayakawa <yutaro.hayakawa@isovalent.com>
2022-12-25 14:52:57 +09:00
Donald Sharp
478c62e21d zebra: Fix nexthop group memory leak
Address Sanitizer found this:

=================================================================
==418623==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 128 byte(s) in 4 object(s) allocated from:
    #0 0x4bd732 in calloc (/usr/lib/frr/zebra+0x4bd732)
    #1 0x7feaeab8f798 in qcalloc /home/sharpd/frr8/lib/memory.c:116:27
    #2 0x7feaeaba40f4 in nexthop_group_new /home/sharpd/frr8/lib/nexthop_group.c:270:9
    #3 0x56859b in netlink_route_change_read_unicast /home/sharpd/frr8/zebra/rt_netlink.c:950:9
    #4 0x5651c2 in netlink_route_change /home/sharpd/frr8/zebra/rt_netlink.c:1204:2
    #5 0x54af15 in netlink_information_fetch /home/sharpd/frr8/zebra/kernel_netlink.c:407:10
    #6 0x53e7a3 in netlink_parse_info /home/sharpd/frr8/zebra/kernel_netlink.c:1184:12
    #7 0x548d46 in kernel_read /home/sharpd/frr8/zebra/kernel_netlink.c:501:2
    #8 0x7feaeacc87f6 in thread_call /home/sharpd/frr8/lib/thread.c:2006:2
    #9 0x7feaeab36503 in frr_run /home/sharpd/frr8/lib/libfrr.c:1198:3
    #10 0x550d38 in main /home/sharpd/frr8/zebra/main.c:476:2
    #11 0x7feaea492d09 in __libc_start_main csu/../csu/libc-start.c:308:16

Indirect leak of 576 byte(s) in 4 object(s) allocated from:
    #0 0x4bd732 in calloc (/usr/lib/frr/zebra+0x4bd732)
    #1 0x7feaeab8f798 in qcalloc /home/sharpd/frr8/lib/memory.c:116:27
    #2 0x7feaeab9b3f8 in nexthop_new /home/sharpd/frr8/lib/nexthop.c:373:7
    #3 0x56875e in netlink_route_change_read_unicast /home/sharpd/frr8/zebra/rt_netlink.c:960:15
    #4 0x5651c2 in netlink_route_change /home/sharpd/frr8/zebra/rt_netlink.c:1204:2
    #5 0x54af15 in netlink_information_fetch /home/sharpd/frr8/zebra/kernel_netlink.c:407:10
    #6 0x53e7a3 in netlink_parse_info /home/sharpd/frr8/zebra/kernel_netlink.c:1184:12
    #7 0x548d46 in kernel_read /home/sharpd/frr8/zebra/kernel_netlink.c:501:2
    #8 0x7feaeacc87f6 in thread_call /home/sharpd/frr8/lib/thread.c:2006:2
    #9 0x7feaeab36503 in frr_run /home/sharpd/frr8/lib/libfrr.c:1198:3
    #10 0x550d38 in main /home/sharpd/frr8/zebra/main.c:476:2
    #11 0x7feaea492d09 in __libc_start_main csu/../csu/libc-start.c:308:16

SUMMARY: AddressSanitizer: 704 byte(s) leaked in 8 allocation(s).

Fix this!

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2022-12-15 11:15:33 -05:00
Donald Sharp
45f0a10bef zebra: Add ctx to netlink message parsing
Add the initial step of passing in a dplane context
to reading route netlink messages.  This code
will be run in two contexts:

a) The normal pthread for reading netlink messages from
the kernel
b) The dplane_fpm_nl pthread.

The goal of this commit is too just allow a) to work
b) will be filled in in the future.  Effectively
everything should still be working as it should
pre this change.  We will just possibly allow
the passing of the context around( but not used )

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2022-12-12 10:44:57 -05:00
Donatas Abraitis
47f3d0905b
Merge pull request #12238 from donaldsharp/append
lib, zebra: Allow for zebra to recognize that a route has gotten desy…
2022-11-07 10:37:05 +02:00
Donald Sharp
569e141113 lib, zebra: Add ability to encode/decode resilient nhg's
Add ability to read the nexthop group resilient linux
kernel data as well as write it.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2022-11-04 13:29:36 -04:00
Donald Sharp
a048d52399 lib, zebra: Allow for zebra to recognize that a route has gotten desynced
FRR does not use the NLM_F_APPEND semantics ( in fact I would argue that
the NLM_F_APPEND semantics just introduce pain for all parties involved )
I would also argue that most people who use the kernel netlink api
have recognized that NLM_F_APPEND for a route is a recipe for disaster
that is well documented and as such it is not used as anything other
than a curiousity by operators.

See:
https://bugzilla.redhat.com/show_bug.cgi?id=1337855
https://github.com/thom311/libnl/issues/226

Are 2 great examples of how confusing it is for anyone in user
space to know what the correct thing to do is.  Given that
new fields can be added with no semantics to allow us to know
what has resulted in a change or not.

In an attempt to recognize this, let's note that FRR
believes it has gotten out of sync with the kernel.
Future commits will react to the desynchronized route
and request from the kernel a reload of that specific
route if possible.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2022-11-04 12:02:00 -04:00
Carmine Scarpitta
8bea07e49f zebra, lib: add support for SRv6 End.DT46 behavior
This commit enables zebra to install End.DT46 nexthops into the Linux kernel.

Signed-off-by: Carmine Scarpitta <carmine.scarpitta@uniroma2.it>
2022-10-18 15:37:25 +02:00
Donald Sharp
07fd1f7e94 zebra: use rib_add_multipath in rt_netlink.c
The new route code path was using a combination of
both rib_add() and rib_add_multipath() let's clean
it up some to use rib_add_multipath()

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2022-08-17 16:04:50 -04:00
Donald Sharp
b0385873fa zebra: Create a zebra_rib_route_entry_new function and use it
Abstract the creation of the route_entry and use it.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2022-08-17 16:04:50 -04:00
Donatas Abraitis
ce39ca16dd zebra: Avoid buffer overflow using netlink_parse_rtattr_nested()
memset(tb, 0, sizeof(struct rtattr *) * (max + 1)); in netlink_parse_rtattr()
seems a good candidate to buffer overflow.

Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2022-07-17 22:31:48 +03:00
David Lamparter
e1cd4bb178 zebra: fix remaining MR RTM_GETROUTE oddities
The IPv6 version needs rtm_src_len and rtm_dst_len filled in due to
strict validation.  IPv4 also has this requirement, but zebra is running
in non-strict mode there so the kernel accepts it...

Also the table ID hack is IPv4 only.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2022-07-07 11:36:40 +02:00
David Lamparter
c6a89c8ef5 zebra: IIF/OIF are not used in MR RTM_GETROUTE
The multicast routing RTM_GETROUTE command does not use IIF/OIF
attributes, and the IPv6 version will refuse them with an error due to
being new netlink API and thus using strict validation.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2022-07-06 11:29:56 +02:00
David Lamparter
31071fe357 zebra: netlink MR is a rtmsg, not ndmsg
These two structs happen to be the same size and have the family field
in the same spot, but the correct one to use here is rtmsg not ndmsg.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2022-07-06 11:23:06 +02:00
David Lamparter
afeb8524e2 zebra: correctly ignore multicast nl msgs
zebra does not care about _notifications_ from the kernel regarding
multicast routing;  we only use the MR netlink API to request stats from
the kernel by actively sending a RTM_GETROUTE.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2022-07-06 11:19:05 +02:00
Donald Sharp
b09388f0ea zebra: Add more cases to proto2zebra for understanding kernel routes
Just some missing ones.  Make zebra stop complaining, was getting
some messages from proto2zebra when doing testing, let's clean
that up from happening.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2022-07-01 07:59:53 -04:00
Donald Sharp
c3dcd24bc2 zebra: Notice to end operator when a failure happens
When reading a multipath route and we detect an encoding
error from the kernel( yeah I don't think so either ),
let's tell the operator what happened to that route.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2022-07-01 07:59:53 -04:00
Anuradha Karuppiah
4cf4fad153 zebra: add support for maintaining local neigh entries
Currently specific local neighbors (attached to SVIs) are maintatined
in an EVPN specific database. There is a need to maintain L3 neighbors
for other purposes including MAC resolution for PBR nexthops.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
   Cleanup compile and fix crash
Signed-off-by: Anuradha Karuppiah <anuradhak@nvidia.com>
2022-06-27 07:56:55 -04:00
Russ White
a9adefc22f
Merge pull request #11464 from donaldsharp/linkdown
Linkdown
2022-06-24 10:15:55 -04:00
Donald Sharp
c704cb44a9 lib, zebra: Notice when a nexthop is set linkdown
When a nexthop is set RTNH_F_LINKDOWN, start noticing
that this flag is set.  Allow FRR to know about this
flag but at this point do not do anything with it.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2022-06-23 11:23:37 -04:00
Ricardo
63eaefa86c zebra: rtnetlink: flow attr per gateway attr in multipath updates
Signed-off-by: Ricardo <rbarroetavena@anura.com.ar>
2022-06-23 12:05:26 -03:00
anlan_cs
81157cbd10 zebra: remove unnecessary check for "zevpn_vrf"
The global vrf in zebra is always non-NULL. In general, it is bound to
default vrf by `zebra_vrf_init()`, at other times bound to some specific
vrf. Anyway, non-NULL.

So remove all redundant checkings for the returned value of
`zebra_vrf_get_evpn()`.

Additionally, remove the unnecessary check for `zvrf` in
`zebra_vxlan_cleanup_tables()`.

Signed-off-by: anlan_cs <vic.lan@pica8.com>
2022-05-13 23:31:52 -04:00
Donatas Abraitis
6006b807b1 *: Properly use memset() when zeroing
Wrong: memset(&a, 0, sizeof(struct ...));
    Good:  memset(&a, 0, sizeof(a));

Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2022-05-11 14:08:47 +03:00
Mobashshera Rasool
4d3b4b1851 zebra: Modify base code to get ipv6 stats from kernel
Modify the structure mcast_route_data to store ipv4/ipv6
addr and lastused multicast information from kernel.
Adjust the related APIs to parse ipv4/ipv6 informations.

Signed-off-by: Mobashshera Rasool <mrasool@vmware.com>
2022-04-28 01:10:49 -07:00
Donald Sharp
3cee213500 zebra: Add tracepoint for netlink_route_change_read_unicast
Add a tracepoint to zebra for the netlink_route_change_read_unicast
functionality.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2022-04-20 09:43:47 -04:00
Donald Sharp
1d80c20919 zebra: Add netlink_nexthop_change tracepoint
Add a tracepoint for the netlink_nexthop_change function.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2022-04-20 09:43:47 -04:00
Donald Sharp
3819e4ced7 *: Fix spelling of inteface
Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2022-04-19 08:21:31 -04:00
anlan_cs
2be18df4dc zebra: remove unnecessary check for parsing macfdb
Since `NDA_VLAN` is no longer mannually defined in header file,
the check for `NDA_VLAN` should be removed.

Signed-off-by: anlan_cs <vic.lan@pica8.com>
2022-03-30 05:50:21 -04:00
Donatas Abraitis
ecf0ea4b00
Merge pull request #9953 from donaldsharp/system_route_replace
zebra: Better handle replacing our route by a system route
2022-03-20 23:25:52 +02:00
Donald Sharp
d4000d7ba3 zebra: Remove struct nlsock from dataplane information and use int fd
Store the fd that corresponds to the appropriate `struct nlsock` and pass
that around in the dplane context instead of the pointer to the nlsock.
Modify the kernel_netlink.c code to store in a hash the `struct nlsock`
with the socket fd as the key.

Why do this?  The dataplane context is used to pass around the `struct nlsock`
but the zebra code has a bug where the received buffer for kernel netlink
messages from the kernel is not big enough.  So we need to dynamically
grow the receive buffer per socket, instead of having a non-dynamic buffer
that we read into.  By passing around the fd we can look up the `struct nlsock`
that will soon have the associated buffer and not have to worry about `const`
issues that will arise.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2022-02-08 17:28:19 -05:00
Russ White
1a8a7016a6
Merge pull request #9066 from donaldsharp/ships_in_the_night
zebra: Fix ships in the night issue
2022-02-08 14:41:01 -05:00
Russ White
e735c8073c
Merge pull request #9649 from proelbtn/add-support-for-end-dt4
add support for SRv6 IPv4 L3VPN
2022-02-08 08:30:02 -05:00
Donald Sharp
c6eee91f66 zebra: Fix ships in the night issue
When using wait for install there exists situations where
zebra will issue several route change operations to the kernel
but end up in a state where we shouldn't be at the end
due to extra data being received.  Example:

a) zebra receives from bgp a route change, installs sends the
route to the kernel.
b) zebra receives a route deletion from bgp, removes the
struct route entry and then sends to the kernel a deletion.
c) zebra receives an asynchronous notification that (a) succeeded
but we treat this as a new route.

This is the ships in the night problem.  In this case if we receive
notification from the kernel about a route that we know nothing
about and we are not in startup and we are doing asic offload
then we can ignore this update.

Ticket: #2563300
Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2022-02-07 16:10:03 -05:00
Donald Sharp
090ee85656 zebra: Add kernel nexthop group support to show zebra
Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2022-02-04 10:29:38 -05:00
Donald Sharp
6b390b3c7b zebra: Better handle replacing our route by a system route
When a operator has a FRR based route installed into the
FIB and a better route comes in from the system.  There
is code in the data plane to schedule the batching
and continue processing.  But in this case we are done
so we can just return

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2022-01-26 10:26:46 -05: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
Ryoga Saito
7eab60a793 zebra: add support for End.DT4
This patch enables zebra to insert End.DT4 nexthop into linux kernel.

Signed-off-by: Ryoga Saito <ryoga.saito@linecorp.com>
2021-11-22 23:32:30 +09:00
Donald Sharp
6e1e2e8da9 zebra: Fix netlink RTM_NEWNEXTHOP parsing for nested attributes
With the addition of resillient hashing for nexthops, the
parsing of nexthops requires telling the decoder functions
that there may be nested attributes.  This was found by
code inspection of iproute2/ipnexthop.c when trying to
understand resillient hashing as well as statistics
gathering for nexthops that are / will be in upstream
kernels in the near future.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2021-10-28 08:10:28 -04:00
Donald Sharp
ba3df8987f
Merge pull request #9686 from idryzhov/fix-nda-lladdr
zebra: fix buffer overflow
2021-10-12 12:04:00 -04:00
Donald Sharp
9bfadae860 zebra: Use a bool for startup indications
Let's not pass around an int startup when all we are doing
is true/falsing it.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2021-10-04 20:26:38 -04:00
Igor Ryzhov
b7c21fad11 zebra: fix buffer overflow
mac is only 6 bytes long and we shouldn't blindly copy unknown number of
bytes into it.

Fixes #9671.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2021-09-28 15:45:14 +03:00
Donald Sharp
f2595bd505 zebra: Convert to struct zebra_nhlfe as per our internal standard
We do not use typedef's to talk about structures as per our standard.
Fixing.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2021-09-02 10:33:23 -04:00
Philippe Guibert
80f6b5faeb lib, zebra: complete the ndm flags on zclient api
Insist on the fact that zclient neighbor state flags are
mapped over netlink state flags. List all the defines
currently known on kernel, and create a netlink API to
convert netlink values to zclient values. The function is
simplified as it is a 1-1 match.

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2021-08-26 09:19:42 +02:00
Mark Stapp
deb28338de zebra: ignore unknown address-family in netlink route msg
Ignore AFs we don't handle in incoming netlink route
updates.

Signed-off-by: Mark Stapp <mjs.ietf@gmail.com>
2021-08-10 11:44:08 -04:00
Mark Stapp
1a3bd37f7c zebra: use more const
Use const in many more evpn apis, especially for macaddr,
ipaddr arguments.

Signed-off-by: Mark Stapp <mjs@voltanet.io>
2021-07-19 10:36:12 -04:00
Hiroki Shirokura
0a543b7929 zebra: early return on seg6local nlmsg crafting
Signed-off-by: Hiroki Shirokura <slank.dev@gmail.com>
2021-06-02 10:24:48 -04:00
Hiroki Shirokura
eab0f8f0a2 lib,sharpd,zebra: update nexthop object with nh_srv6
Signed-off-by: Hiroki Shirokura <slank.dev@gmail.com>
2021-06-02 10:24:48 -04:00