Commit graph

467 commits

Author SHA1 Message Date
Mark Stapp 028872bf40 lib: fix -Wshadow warnings in the lib modules
Fix various "shadow" warnings in lib.

Signed-off-by: Mark Stapp <mjs@cisco.com>
2025-04-08 14:41:26 -04:00
Mark Stapp 556d3c445d
Merge pull request #18359 from soumyar-roy/soumya/streamsize
zebra: zebra crash for zapi stream
2025-03-21 11:30:16 -04:00
Soumya Roy 860c1e4450 zebra: reduce memory usage by streams when redistributing routes
This commit undo 8c9b007a0c
stream lib has been modified to expand the stream if needed
Now for zapi route encode, we use expandable stream

Signed-off-by: Soumya Roy <souroy@nvidia.com>
2025-03-20 16:13:44 +00:00
Louis Scalbert c6afe42455 lib, tests, zebra: keep table routes at vrf disabling
At VRF disabling, keep the route entries that was associated to its
table ID but not to the VRF itself. Kernel flushes these entries so we
need to reinstall them.

To do so, add a flag to mean that a route entry is owned by a table ID
and not by a VRF. If the VRF associated to the table ID is deleted, the
route entry must not be deleted.

Update to tests with new flag. 2057 is in hexa 0x809, meaning that the
new flag has been to some prefix.

Signed-off-by: Louis Scalbert <louis.scalbert@6wind.com>
2025-03-10 09:54:18 +01:00
Mark Stapp b66145b8ca
Merge pull request #18030 from fdumontet6WIND/mem_alloc_stream
zebra: reduce memory usage by streams when redistributing routes
2025-03-03 11:09:47 -05:00
Francois Dumontet 8c9b007a0c zebra: reduce memory usage by streams when redistributing routes
required stream size is evaluated as a fix part and variable one.
the variable one depend on the number of nexthops.

Signed-off-by: Francois Dumontet <francois.dumontet@6wind.com>
2025-02-27 16:51:05 +01:00
Donald Sharp 14c4678771 lib: Prevent crash in getting label chunk
ldpd has this crash:

(gdb) bt
0  __pthread_kill_implementation (no_tid=0, signo=11, threadid=140329211443648) at ./nptl/pthread_kill.c:44
1  __pthread_kill_internal (signo=11, threadid=140329211443648) at ./nptl/pthread_kill.c:78
2  __GI___pthread_kill (threadid=140329211443648, signo=signo@entry=11) at ./nptl/pthread_kill.c:89
3  0x00007fa0f0642476 in __GI_raise (sig=11) at ../sysdeps/posix/raise.c:26
4  0x00007fa0f0b51944 in core_handler (signo=11, siginfo=0x7fff562810b0, context=0x7fff56280f80) at lib/sigevent.c:268
5  <signal handler called>
6  0x00007fa0f0b9534d in lm_get_label_chunk (zclient=0x0, keep=0 '\000', base=0, chunk_size=64, start=0x7fff56281bdc, end=0x7fff56281be0) at lib/zclient.c:3667
7  0x0000564e0d1c011e in lde_get_label_chunk () at ldpd/lde.c:2211
8  0x0000564e0d1c05f8 in lde_get_next_label () at ldpd/lde.c:2318
9  0x0000564e0d1bcb29 in lde_update_label (fn=0x564e16653050) at ldpd/lde.c:783
10 0x0000564e0d1c1fbe in lde_kernel_update (fec=0x7fff56281cb0) at ldpd/lde_lib.c:422
11 0x0000564e0d1b96c0 in l2vpn_pw_init (pw=0x564e165d1fa0) at ldpd/l2vpn.c:242
12 0x0000564e0d1b2d32 in merge_l2vpn (xconf=0x564e166424f0, l2vpn=0x564e166160a0, xl=0x564e165eabb0) at ldpd/ldpd.c:1883
13 0x0000564e0d1b28ea in merge_l2vpns (conf=0x564e166424f0, xconf=0x564e16653650) at ldpd/ldpd.c:1813
14 0x0000564e0d1b1244 in merge_config (conf=0x564e166424f0, xconf=0x564e16653650) at ldpd/ldpd.c:1321
15 0x0000564e0d1bc485 in lde_dispatch_parent (thread=0x7fff56282060) at ldpd/lde.c:611
16 0x00007fa0f0b6cebc in event_call (thread=0x7fff56282060) at lib/event.c:2019
17 0x0000564e0d1baee7 in lde () at ldpd/lde.c:155
18 0x0000564e0d1ae4b8 in main (argc=0, argv=0x7fff56282298) at ldpd/ldpd.c:312
(gdb)

Since it is possible to be asking for label data before the zclient has
been connected, let's just return -1 in the case where zclient is not
initialized yet either, since this is effectively the same thing as
the sock being < 0.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2025-02-27 08:29:26 -05:00
David Lamparter 4a0e1419a6 lib: guard against padding garbage in ZAPI read
When reading in a nexthop from ZAPI, only set the fields that actually
have meaning.  While it shouldn't happen to begin with, we can otherwise
carry padding garbage into the unused leftover union bytes.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2025-01-29 16:48:37 +01:00
Russ White bd82864d03
Merge pull request #17941 from opensourcerouting/fix-dst-src
static: fix botched staticd YANG conversion for dst-src
2025-01-28 12:23:06 -05:00
David Lamparter 2af780650f lib, zebra: carry source prefix in route_notify
When a daemon wants to know about its routes, make it possible to have
that work for dst-src routes.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2025-01-28 15:40:17 +01:00
Rafael Zalamena 5846339eae bgpd,lib: document the table id / instance usage
Document where relevant about the instance overload to table ID so users
know what to expect.

Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
2025-01-23 15:13:01 -03:00
Rafael Zalamena 28a9ca3405 lib,zebra: VRF table-direct support
Implement the necessary data structures and code changes to support sending
table-direct routes to protocols running in different VRFs.

Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
2025-01-23 14:37:09 -03:00
Rafael Zalamena dfdc12e164 lib: abstract instance redistribution management
Use the linked list `del` callback to free memory instead of manually calling.

Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
2025-01-23 14:37:09 -03:00
Donald Sharp fe180581bd lib: Speed up reconnection attempts for zapi
Currently the zapi reconnection is once every 10 seconds
for the first 3 times and then once every 60 seconds from then
on out.  We are seeing interesting behavior under loaded systems
where zebra is just slow to come up and daemons are spending a long
time waiting to connect.  Let's just make things a bit more aggressive.

Change the code to attempt to reconnect once every second for 30 seconds
and then change to once every 5 seconds from then on out.

This should help with non-integrated configuration on system startup.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2024-12-04 16:14:34 -05:00
Donald Sharp 645a9e4f83 *: Fix up improper handling of nexthops for nexthop tracking
Currently FRR needs to send a uint16_t value for the number
of nexthops as well it needs the ability to properly decode
all of this.  Find and handle all the places that this happens.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2024-10-15 11:57:23 -04:00
Russ White 7834c38ab3
Merge pull request #15604 from cscarpitta/srv6-sid-manager
Add support for SRv6 SID Manager
2024-06-18 12:16:24 -04:00
Donatas Abraitis 83b4706f30 lib: Get the weight from Zebra
Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2024-06-18 12:15:33 +03:00
Philippe Guibert 36a310cc9f zebra, lib: add locator name in sid notify messages
In the near future, some daemons may only register SIDs. This may be
the case for the pathd daemon when creating SRv6 binding SIDs.

When a locator is getting deleted at ZEBRA level, the daemon may have
an easy way to find out the SIds to unregister to.

This commit proposes to add the locator name to the SID_SRV6_NOTIFY
message whenever possible. Only case when an allocation failure happens,
the locator will not be present. In all other places, the notify API
at procol levels has the locator name extra-parameter.

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
Signed-off-by: Carmine Scarpitta <cscarpit@cisco.com>
2024-06-17 17:09:45 +02:00
Carmine Scarpitta 4dcb69e0f9 zebra: Fix checkpatch warning
Signed-off-by: Carmine Scarpitta <cscarpit@cisco.com>
2024-06-13 14:54:16 +02:00
Carmine Scarpitta b90cb00974 lib: Add ZAPI command ZEBRA_SRV6_SID_NOTIFY
Add a new ZAPI command `ZEBRA_SRV6_SID_NOTIFY` used by zebra to send
asynchronous SRv6 SIDs notifications to zclients.

Signed-off-by: Carmine Scarpitta <cscarpit@cisco.com>
2024-06-13 14:54:16 +02:00
Carmine Scarpitta 164117f2ec lib: Add missing info to locator encode/decode
Include block/node/function/argument lengthi when
encoding/decoding an SRv6 locator.

Signed-off-by: Carmine Scarpitta <cscarpit@cisco.com>
2024-06-13 14:54:16 +02:00
Carmine Scarpitta ee1d20879b lib: Add ZAPI operations to get/release SRv6 SIDs
Add two new ZAPI operations: `ZEBRA_SRV6_MANAGER_GET_SRV6_SID` and
`ZEBRA_SRV6_MANAGER_RELEASE_SRV6_SID`. These APIs allow a daemon to get and
release an SRv6 SID, respectively.

Signed-off-by: Carmine Scarpitta <cscarpit@cisco.com>
2024-06-13 14:54:16 +02:00
Carmine Scarpitta ded79d7013 lib: Add ZAPI operation get SRv6 locator
Add a new ZAPI operation, ZEBRA_SRV6_MANAGER_GET_LOCATOR, which allows a
daemon to request information about a specific locator from the SRv6 SID
Manager.

Signed-off-by: Carmine Scarpitta <cscarpit@cisco.com>
2024-06-13 14:54:16 +02:00
Philippe Guibert 49bc1b6c21 lib: fix copy srte_color from zapi_nexthop structure
When switching from nexthop to zapi_nexthop, the srte color
is copied. Do the same in reverse.

Fixes: 31f937fb43 ("lib, zebra: Add SR-TE policy infrastructure to zebra")

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2024-06-10 12:13:56 +02:00
Donatas Abraitis 48f5d828e3
Merge pull request #15673 from pguibert6WIND/isis_srv6_usid
lib: fix srv6 locator flags propagated to isis
2024-05-01 08:26:28 +03:00
Donatas Abraitis 5f059e0c7d
Merge pull request #15854 from mjstapp/dump_outofsync_flag
lib: add ZEBRA_FLAG_OUTOFSYNC to dump_flags function
2024-04-27 21:16:49 +03:00
Mark Stapp c943b71c9f lib: add ZEBRA_FLAG_OUTOFSYNC to dump_flags function
Right where the zapi route flags are defined, there's a comment
asking that the flag-dumper-function also be updated.

Also apply clang-format's preferences, so next person won't have
to.

Signed-off-by: Mark Stapp <mjs@cisco.com>
2024-04-26 14:48:00 -04:00
Philippe Guibert 03d2ad01a4 lib: fix srv6 locator flags propagated to isis
When usid is not used, the isis_srv6_topo1 test does not work.
The SID prefix allocated by isis is different when the usid
flags is set or not. When the flags is not transmitted to isis,
the SID allocated is supposed to be a 128 bit mask length SID,
which is not what the isis_srv6_topo1 test is supposed to obtain.

Fix this by exchanging the flags locator value in the zclient api.

Fixes: 9b7491e1fc ("lib: Add support for flags to the SRv6 locator")

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2024-04-23 14:25:48 +02:00
Donatas Abraitis a988a0a88a *: Use uint64_t for weight down the path to Zebra
Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2024-04-22 17:50:08 +03:00
Donald Sharp ccfe452763 bgpd : backpressure - Handle BGP-Zebra Install evt Creation
BGP is now keeping a list of dests with the dest having a pointer
to the bgp_path_info that it will be working on.

1) When bgp receives a prefix, process it, add the bgp_dest of the
prefix into the new Fifo list if not present, update the flags (Ex:
earlier if the prefix was advertised and now it is a withdrawn),
increment the ref_count and DO NOT advertise the install/withdraw
to zebra yet.

2) Schedule an event to wake up to invoke the new function which will
walk the list one by one and installs/withdraws the routes into zebra.
  a) if BUFFER_EMPTY, process the next item on the list
  b) if BUFFER_PENDING, bail out and the callback in
  zclient_flush_data() will invoke the same function when BUFFER_EMPTY

Changes
 - rename old bgp_zebra_announce to bgp_zebra_announce_actual
 - rename old bgp_zebra_withdrw to bgp_zebra_withdraw_actual
 - Handle new fifo list cleanup in bgp_exit()
 - New funcs: bgp_handle_route_announcements_to_zebra() and
   bgp_zebra_route_install()
 - Define a callback function to invoke
   bgp_handle_route_announcements_to_zebra() when BUFFER_EMPTY in
   zclient_flush_data()

The current change deals with bgp installing routes via
bgp_process_main_one()

Ticket: #3390099

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
Signed-off-by: Rajasekar Raja <rajasekarr@nvidia.com>
2024-03-25 17:49:35 -07:00
Louis Scalbert 2ee43c873e lib,zebra: add zapi message to control noarp flag
Add a ZAPI message to control the setting of the IFF_NOARP flag.

Signed-off-by: Louis Scalbert <louis.scalbert@6wind.com>
2024-01-24 10:05:29 +01:00
Donald Sharp a0d38a7ac6 lib, nhrpd: Move neighbor reg/unreg to lib/zclient.c
This is needed to be generic.  Let's make it so.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2024-01-22 12:14:59 -05:00
Louis Scalbert c6fe42f64d lib: remove zebra_interface_vrf_update_read()
zebra_interface_vrf_update_read is orphan. Remove it.

Fixes: b580c52698 ("*: remove ZEBRA_INTERFACE_VRF_UPDATE")
Signed-off-by: Louis Scalbert <louis.scalbert@6wind.com>
2024-01-05 11:08:55 +01:00
David Lamparter 5a40f2b0e7 lib, bgp/vnc: add .auxiliary zclient option
Avoids calling VRF/interface/... handlers in library code more than
once.  It's kinda surprising that this hasn't been blowing up already
for the VNC code, luckily these handlers are (mostly?) idempotent.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2023-11-23 15:42:59 +01:00
David Lamparter cc90c54b36 *: add zclient_options_sync
... and use it instead of fiddling with the `.synchronous` field.

(Make it const while at it.)

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2023-11-23 15:20:13 +01:00
David Lamparter a13d2933b7 zebra, lib: remove notify field from hello message
This is no longer used.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2023-11-23 15:20:11 +01:00
David Lamparter 25a1dccc56 lib: remove .receive_notify zclient option
This should just be set with `ZEBRA_ROUTE_NOTIFY_REQUEST` instead.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2023-11-23 15:05:10 +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
David Lamparter 03c4375a4a lib: make zapi_nexthop_update_decode private
zapi_nexthop_update_decode() is no longer called externally.

Also move the comment to zclient->nexthop_update where it now belongs.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2023-11-20 11:28:39 +01:00
David Lamparter b951e59300 lib: add common NHT update decode callback
All users of `ZEBRA_NEXTHOP_UPDATE` check the VRF and then call into
`zapi_nexthop_update_decode` before further processing.  Begin moving
this into common code in lib/.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2023-11-20 11:24:21 +01:00
Igor Ryzhov 7d67b9ff28 build: add -Wimplicit-fallthrough
Also:
- replace all /* fallthrough */ comments with portable fallthrough;
pseudo keyword to accomodate both gcc and clang
- add missing break; statements as required by older versions of gcc
- cleanup some code to remove unnecessary fallthrough

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2023-10-12 21:23:18 +03:00
Dmytro Shytyi f20cf1457d bgpd,lib,sharpd,zebra: srv6 introduce multiple segs/SIDs in nexthop
Append zebra and lib to use muliple SRv6 segs SIDs, and keep one
seg SID for bgpd and sharpd.

Note: bgpd and sharpd compilation relies on the lib and zebra files,
i.e if we separate this: lib or zebra or bgpd or sharpd in different
commits - this will not compile.

Signed-off-by: Dmytro Shytyi <dmytro.shytyi@6wind.com>
2023-09-20 15:07:15 +02:00
Mark Stapp 7b8a4249ea lib,zebra: add tx queuelen to interface struct
Add the txqlen attribute to the common interface struct. Capture
the value in zebra, and distribute it through the interface lib
module's zapi messaging.

Signed-off-by: Mark Stapp <mjs@labn.net>
2023-09-01 10:06:10 -04:00
G. Paul Ziemba ba240bcfa3 pbrd: add packet mangling actions (src/dst ip-addr/port, dscp, ecn)
Signed-off-by: G. Paul Ziemba <paulz@labn.net>
2023-08-09 12:11:43 -07:00
G. Paul Ziemba 887367a01c pbrd: use flags to indicate active fields
Before now, PBRD used non-zero values to imply that a rule's
    match or action field was active. This approach was getting
    cumbersome for fields where 0 is a valid active value and
    various field-specific magic values had to be used.

    This commit changes PBRD to use a flag bit per field to
    indicate that the field is active.

Signed-off-by: G. Paul Ziemba <paulz@labn.net>
2023-08-09 12:11:35 -07:00
G. Paul Ziemba c47fd378f3 pbrd: add explicit 'family' field for rules
In the netlink-mediated kernel dataplane, each rule is stored
    in either an IPv4-specific database or an IPv6-specific database.
    PBRD opportunistically gleans each rule's address family value
    from its source or destination IP address match value (if either
    exists), or from its nexthop or nexthop-group (if it exists).

    The 'family' value is particularly needed for netlink during
    incremental rule deletion when none of the above fields remain set.

    Before now, this address family has been encoded by occult means
    in the (possibly otherwise unset) source/destination IP match
    fields in ZAPI and zebra.

    This commit documents the reasons for maintaining the 'family'
    field in the PBRD rule structure, adds a 'family' field in the
    common lib/pbr.h rule structure, and carries it explicitly in ZAPI.

Signed-off-by: G. Paul Ziemba <paulz@labn.net>
2023-08-08 10:18:22 -07:00
Donald Sharp 68f52d7a0c lib, zebra: Send up whether or not v6_with_v4_nexthops are supported
After Zebra knows it's capability surrounding v6 with v4 nexthops
have it send this ability up to interested parties.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2023-08-03 08:25:20 -04:00
Mark Stapp fe2bbcb01d lib,pbrd: clean up style issues
Fix a couple of style warnings introduced by recent PR 14050.

Signed-off-by: Mark Stapp <mjs@labn.net>
2023-07-25 11:09:29 -04:00
G. Paul Ziemba 580a98b798 lib: zapi PBR common encode/decode
bgpd, pbrd: use common pbr encoder
    zebra: use common pbr decoder
    tests: pbr_topo1: check more filter fields

    Purpose:
	1. Reduce likelihood of zapi format mismatches when adding
	   PBR fields due to multiple parallel encoder implementations
	2. Encourage common PBR structure usage among various daemons
	3. Reduce coding errors via explicit per-field enable flags

Signed-off-by: G. Paul Ziemba <paulz@labn.net>
2023-07-20 08:10:45 -07:00