Commit graph

89 commits

Author SHA1 Message Date
wumu.zsl e766b68a18 bfdd: Fix CI build issue on kernel with no IPV6_HDRINCL
Signed-off-by: wumu.zsl <wumu.zsl@alibaba-inc.com>
2025-01-23 03:25:02 +00:00
wumu.zsl 0ef6003167 bfdd: add bfdname info when notify bfd status to PTM
Signed-off-by: wumu.zsl <wumu.zsl@alibaba-inc.com>
2025-01-23 02:59:55 +00:00
Donald Sharp 2c6fcbdf84 lib: Fix session re-establishment
Currently if you have this sequence of events:

a) BGP starts
b) BGP reads cli that has bfd configuration
c) BGP attempts to install bfd configuration but fails because
zebra is not connected to yet
d) BGP connects to zebra
e) BGP receives resend bfd code from bfdd
f) BGP was not sending down the unsent data to bfd, never causing
the bfd session to be established.

So effectively bfd was attempting to install but failed
and then when it was asked to replay everything it decided
that the bfd information for a particular peer was actually
installed and does not need to be resent.  Modify the code
such that the bfd code now tracks failed installation and
allows the resend of data to bfdd.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2024-12-03 12:08:12 -05:00
Donatas Abraitis 1fb48f5d13 bgpd: Do not start BGP session if BFD profile is in shutdown state
If we do:

```
bfd
 profile foo
  shutdown
```

The session is dropped, but immediately established again because we don't
have a proper check on BFD.

If BFD is administratively shutdown, ignore starting the session.

Fixes: https://github.com/FRRouting/frr/issues/16186

Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2024-06-12 08:39:48 +03:00
David Lamparter 8b23c0b0bd *: convert struct interface->connected to DLIST
Replace `struct list *` with `DLIST(if_connected, ...)`.

NB: while converting this, I found multiple places using connected
prefixes assuming they were IPv4 without checking:

- vrrpd/vrrp.c: vrrp_socket()
- zebra/irdp_interface.c: irdp_get_prefix(), irdp_if_start(),
  irdp_advert_off()

(these fixes are really hard to split off into separate commits as that
would require going back and reapplying the change but with the old list
handling)

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2023-11-22 23:00:30 +01:00
Mark Stapp adca5c22c5 * : include event ptr in event_execute api
Include an event ptr-to-ptr in the event_execute() api
call, like the various schedule api calls. This allows the
execute() api to cancel an existing scheduled task if that
task is being executed inline.

Signed-off-by: Mark Stapp <mjs@labn.net>
2023-07-25 10:17:48 -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 e16d030c65 *: Convert THREAD_XXX macros to EVENT_XXX macros
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 8c1186d38e *: Convert thread_execute to event_execute
Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2023-03-24 08:32:17 -04:00
Donald Sharp 907a2395f4 *: Convert thread_add_XXX functions to event_add_XXX
Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2023-03-24 08:32:17 -04:00
Donald Sharp e6685141aa *: Rename struct thread to struct event
Effectively a massive search and replace of
`struct thread` to `struct event`.  Using the
term `thread` gives people the thought that
this event system is a pthread when it is not

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

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

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2023-03-24 08:32:16 -04:00
Donald Sharp f83431c7e8 lib: on bfd peer shutdown actually stop event
When deleting a bfd peer during shutdown, let's ensure
that any scheduled events are actually stopped.

==7759== Invalid read of size 4
==7759==    at 0x48BF700: _bfd_sess_valid (bfd.c:419)
==7759==    by 0x48BF700: _bfd_sess_send (bfd.c:470)
==7759==    by 0x492F79C: thread_call (thread.c:2008)
==7759==    by 0x48E9BD7: frr_run (libfrr.c:1223)
==7759==    by 0x1C739B: main (bgp_main.c:550)
==7759==  Address 0xfb687a4 is 4 bytes inside a block of size 272 free'd
==7759==    at 0x48369AB: free (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so)
==7759==    by 0x48BFA5A: bfd_sess_free (bfd.c:535)
==7759==    by 0x2B7034: bgp_peer_remove_bfd (bgp_bfd.c:339)
==7759==    by 0x29FF8A: peer_free (bgpd.c:1160)
==7759==    by 0x29FF8A: peer_unlock_with_caller (bgpd.c:1192)
==7759==    by 0x2A0506: peer_delete (bgpd.c:2633)
==7759==    by 0x208190: bgp_stop (bgp_fsm.c:1639)
==7759==    by 0x20C082: bgp_event_update (bgp_fsm.c:2751)
==7759==    by 0x492F79C: thread_call (thread.c:2008)
==7759==    by 0x48E9BD7: frr_run (libfrr.c:1223)
==7759==    by 0x1C739B: main (bgp_main.c:550)
==7759==  Block was alloc'd at
==7759==    at 0x4837B65: calloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so)
==7759==    by 0x48F53AF: qcalloc (memory.c:116)
==7759==    by 0x48BF98D: bfd_sess_new (bfd.c:397)
==7759==    by 0x2B76DC: bgp_peer_configure_bfd (bgp_bfd.c:298)
==7759==    by 0x2B76DC: bgp_peer_configure_bfd (bgp_bfd.c:279)
==7759==    by 0x29BA06: peer_group2peer_config_copy (bgpd.c:2803)
==7759==    by 0x2A3D96: peer_create_bind_dynamic_neighbor (bgpd.c:4107)
==7759==    by 0x2A4195: peer_lookup_dynamic_neighbor (bgpd.c:4239)
==7759==    by 0x21AB72: bgp_accept (bgp_network.c:422)
==7759==    by 0x492F79C: thread_call (thread.c:2008)
==7759==    by 0x48E9BD7: frr_run (libfrr.c:1223)
==7759==    by 0x1C739B: main (bgp_main.c:550)

tl;dr -> Effectively, in this test setup we have 300 dynamic bgp
sessions all of which are using bfd.  When a peer collision is detected
or we remove the peers, if an event has been scheduled but not actually
executed yet the event event was not actually being stopped, leaving
the bsp pointer on the thread->arg and causing a crash when it is
executed.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2023-03-20 16:07:20 -04: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
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
Rafael Zalamena 4e35b32ee5 lib: BFD integration clean up function
Implement clean up function to be called on shutdown to make daemon exit
clean for valgrind and other memory sanitizers.

Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
2023-01-13 15:32:12 -03:00
Rafael Zalamena b7ca809d1c lib: BFD automatic source selection
Implement new BFD library issue to allow protocols to configure BFD
sessions with automatic source selection.

The source selection will be based on the Next Hop Tracking feature:
`zebra` will do RIB lookups to determine the output interface and the
primary source address of that interface will be used as source.

Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
2023-01-13 15:32:12 -03:00
Donald Sharp cc9f21da22 *: Change thread->func to return void instead of int
The int return value is never used.  Modify the code
base to just return a void instead.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2022-02-23 19:56:04 -05:00
anlan_cs 10f02a2ac9 lib: fix the right value is returned for fail cases
Currently `bfd_get_peer_info` should return invalid sp->family
and dp->family during fail cases.

Before this fix, in those fail cases `bfd_get_peer_info` maybe
return valid sp->family and dp->family.

This fix ensures all fail cases return invalid sp->family and
dp->family for outside callers.

Signed-off-by: anlan_cs <anlan_cs@tom.com>
2022-01-12 08:08:29 -05:00
anlan_cs 03ff0db15d lib: rename one bfd parameter name to reflect real meaning
As to "struct bfd_session_arg", just rename parameter "ttl" to "hops", in order
to  reflect real meaning.

Signed-off-by: anlan_cs <anlan_cs@tom.com>
2022-01-10 08:15:08 -05:00
anlan_cs 8b3fd12cda lib: small debug adjustment for bfd
Just use `__func__` to display function name.

Signed-off-by: anlan_cs <anlan_cs@tom.com>
2022-01-08 06:01:08 -05:00
Igor Ryzhov 3e51a84a22 lib: rename bfd function to reflect real functionality
Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2021-11-15 18:16:30 +03:00
Igor Ryzhov 92f85e656b lib: remove confusing bfd TTL API
There are two APIs to control the expected number of hops for a BFD
session – `bfd_sess_set_mininum_ttl` and `bfd_sess_set_hop_count`.
The former is very confusing, as it takes an expected TTL in the
BFD packet which is actually a protocol internal value. The latter is
simple and straightforward – it takes an expected number of hops, which
is always 1 for single-hop and >1 for multi-hop.

As the former API is not used anywhere, just remove it to avoid any
confusion.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2021-11-11 14:56:04 +03:00
Rafael Zalamena ca30ac7fc3 lib: constify read only parameters
Constify some BFD library function parameters to signalize they are
not going to get modified.

Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
2021-11-04 08:01:28 -03:00
Renato Westphal ae09457333 lib: fix BFD IPv6 session address change
Pass the correct family type and remove unneeded casts.

Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2021-11-04 08:00:30 -03:00
David Lamparter a243d1db93 *: convert zclient callbacks to table
This removes a giant `switch { }` block from lib/zclient.c and
harmonizes all zclient callback function types to be the same (some had
a subset of the args, some had a void return, now they all have
ZAPI_CALLBACK_ARGS and int return.)

Apart from getting rid of the giant switch, this is a minor security
benefit since the function pointers are now in a `const` array, so they
can't be overwritten by e.g. heap overflows for code execution anymore.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2021-10-20 13:28:46 +02:00
ewlumpkin 214d8a60e1 lib: fix spelling nits in more lib files
Signed-off-by: ewlumpkin <ewlumpkin@gmail.com>
2021-10-05 21:42:57 +00:00
Donald Sharp 4cc6d2cef6 lib: Send c-bit when not using bfdd as daemon of choice
Commit: 4b983eef2c

Modified the zapi send receive of the c-bit to only
be under the HAVE_BFDD.  If you are using ptm-bfd
then the decoder function still expects this to be
sent down.  This commit puts this behavior back

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2021-08-27 09:32:27 -04:00
Igor Ryzhov 7bb5c50c83 lib: fix default ttl for single-hop bfd sessions
The TTL field is actually the number of hops, not a TTL.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2021-06-01 18:08:29 +03:00
Igor Ryzhov b6c87c3576 lib: fix bfd multihop
Never send an interface name/index for multihop sessions. It breaks
"neighbor A.B.C.D update-source" config in BGP.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2021-06-01 18:07:54 +03:00
Igor Ryzhov c97b34cf1a lib: remove old bfd library
This commit also adds missing `bfd_protocol_integration_set_shutdown` to
ospf6d and pimd.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2021-05-07 12:03:57 +03:00
Igor Ryzhov 2ccc493333
Merge pull request #8495 from opensourcerouting/ospfv3-bfd-rework
ospf6d: rework BFD integration and add BFD profiles support
2021-04-24 00:47:31 +03:00
Rafael Zalamena ac506cb20e lib: BFD session handling improvement
Don't uninstall sessions if the address, interface, VRF or TTL didn't change.

Update the library documentation to make it clear to other developers.

Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
2021-04-22 16:10:04 -03:00
Rafael Zalamena 464e6541b1 lib: fix possible crash on BFD notification
Allow sessions to remove themselves from the notifications without
risking crashes.

Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
2021-04-22 15:12:18 -03:00
Igor Ryzhov e82acdce22 lib: remove enabled flag for bfd sessions
Currently this flag is only helpful in an extremely rare situation when
the BFD session registration was unsuccessful and after that zebra is
restarted. Let's remove this flag to simplify the API. If we ever want
to solve the problem of unsuccessful registration/deregistration, this
can be done using internal flags, without API modification.

Also add the error log to help user understand why the BFD session is
not working.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2021-04-22 16:39:29 +03:00
Rafael Zalamena 9c39d19742 lib: fix BFD crash on interface removal
- Handle badly formatted messages (don't set `ifp` in that case)
- Handle unread messages (e.g. when family is not don't trigger `assert`)

Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
2021-04-14 15:28:09 -03:00
Igor Ryzhov 83c4442202 ospfd: fix crash on "show ip ospf neighbor detail"
Fixes #8419.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2021-04-09 11:24:51 +03:00
Rafael Zalamena 3e6376b813 lib: small BFD session notifier improvement
Cache current monotime to avoid unnecessary calls.

Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
2021-03-23 12:40:09 -03:00
Rafael Zalamena a099abe55b lib: new BFD integration API
New BFD protocol integration API with abstractions to fix most common
protocol integration errors:

 - Set address family together with the source/destination addresses

 - Set the TTL together with the single/multi hop option

 - Set/unset profile/interface easily

 - Keep the arguments so we don't have to rebuild them every time

 - Install/uninstall functions that keep track of current state so the
  daemon doesn't have to

 - Reinstall when critical configuration changes (address, multi hop
   etc...)

 - Reconfigure BFD when the daemon restarts automatically

 - Automatically calls the user defined callback for session update

 - Shutdown handler for all protocols

Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
2021-03-23 12:40:09 -03:00
David Lamparter bf8d3d6aca *: require semicolon after DEFINE_MTYPE & co
Back when I put this together in 2015, ISO C11 was still reasonably new
and we couldn't require it just yet.  Without ISO C11, there is no
"good" way (only bad hacks) to require a semicolon after a macro that
ends with a function definition.  And if you added one anyway, you'd get
"spurious semicolon" warnings on some compilers...

With C11, `_Static_assert()` at the end of a macro will make it so that
the semicolon is properly required, consumed, and not warned about.

Consistently requiring semicolons after "file-level" macros matches
Linux kernel coding style and helps some editors against mis-syntax'ing
these macros.

Signed-off-by: David Lamparter <equinox@diac24.net>
2021-03-17 06:18:17 +01:00
Donald Sharp 37a74717c7 *: Fix usage of bfd_adj_event
Valgrind reports:

469901-==469901==
469901-==469901== Conditional jump or move depends on uninitialised value(s)
469901:==469901==    at 0x3A090D: bgp_bfd_dest_update (bgp_bfd.c:416)
469901-==469901==    by 0x497469E: zclient_read (zclient.c:3701)
469901-==469901==    by 0x4955AEC: thread_call (thread.c:1684)
469901-==469901==    by 0x48FF64E: frr_run (libfrr.c:1126)
469901-==469901==    by 0x213AB3: main (bgp_main.c:540)
469901-==469901==  Uninitialised value was created by a stack allocation
469901:==469901==    at 0x3A0725: bgp_bfd_dest_update (bgp_bfd.c:376)
469901-==469901==
469901-==469901== Conditional jump or move depends on uninitialised value(s)
469901:==469901==    at 0x3A093C: bgp_bfd_dest_update (bgp_bfd.c:421)
469901-==469901==    by 0x497469E: zclient_read (zclient.c:3701)
469901-==469901==    by 0x4955AEC: thread_call (thread.c:1684)
469901-==469901==    by 0x48FF64E: frr_run (libfrr.c:1126)
469901-==469901==    by 0x213AB3: main (bgp_main.c:540)
469901-==469901==  Uninitialised value was created by a stack allocation
469901:==469901==    at 0x3A0725: bgp_bfd_dest_update (bgp_bfd.c:376)

On looking at bgp_bfd_dest_update the function call into bfd_get_peer_info
when it fails to lookup the ifindex ifp pointer just returns leaving
the dest and src prefix pointers pointing to whatever was passed in.

Let's do two things:

a) The src pointer was sometimes assumed to be passed in and sometimes not.
Forget that.  Make it always be passed in
b) memset the src and dst pointers to be all zeros.  Then when we look
at either of the pointers we are not making decisions based upon random
data in the pointers.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2021-02-07 14:59:53 -05:00
Mark Stapp 926bc58f78
Merge pull request #7478 from donaldsharp/buffer
Buffer
2020-11-18 08:30:47 -05:00
Donald Sharp 8a3f8f2e4a bgpd, lib, sharpd: Add enum for zclient_send_message return
Add a `enum zclient_send_status` for appropriate handling
of return codes from zclient_send_message.  Touch all the places
where we handle this.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2020-11-15 14:50:17 -05:00
Rafael Zalamena a29c51a187 lib: notify BFD when adding new profile
When a BFD integrated session already exists setting the profile
doesn't cause a session update (or vice versa): fix this issue by
handling the other cases.

Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
2020-11-08 12:06:32 -03:00
Rafael Zalamena 4b983eef2c bfdd,lib: simplify integration protocol
Let the integration protocol always send the full configuration
instead of saving a few bytes. It will also allow protocols to specify
source address for IPv4 single hop connections and interface for multi
hop configuration.

Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
2020-11-08 12:06:32 -03:00
Quentin Young 65b86778c1
Merge pull request #6711 from GalaxyGorilla/bfd_isis_profiles
Add BFD profiles for IS-IS
2020-07-21 14:45:31 -04:00
David Lamparter 3efd0893d0 *: un-split strings across lines
Remove mid-string line breaks, cf. workflow doc:

  .. [#tool_style_conflicts] For example, lines over 80 characters are allowed
     for text strings to make it possible to search the code for them: please
     see `Linux kernel style (breaking long lines and strings)
     <https://www.kernel.org/doc/html/v4.10/process/coding-style.html#breaking-long-lines-and-strings>`_
     and `Issue #1794 <https://github.com/FRRouting/frr/issues/1794>`_.

Scripted commit, idempotent to running:
```
python3 tools/stringmangle.py --unwrap `git ls-files | egrep '\.[ch]$'`
```

Signed-off-by: David Lamparter <equinox@diac24.net>
2020-07-14 10:37:25 +02:00