summaryrefslogtreecommitdiff
path: root/lib/bfd.c
AgeCommit message (Collapse)Author
2024-06-12bgpd: Do not start BGP session if BFD profile is in shutdown stateDonatas Abraitis
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>
2023-11-22*: convert `struct interface->connected` to DLISTDavid Lamparter
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-07-25* : include event ptr in event_execute apiMark Stapp
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-03-24*: Convert event.h to frrevent.hDonald Sharp
We should probably prevent any type of namespace collision with something else. Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2023-03-24*: Convert `struct event_master` to `struct event_loop`Donald Sharp
Let's find a better name for it. Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2023-03-24*: Convert THREAD_XXX macros to EVENT_XXX macrosDonald Sharp
Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2023-03-24*: Convert struct thread_master to struct event_master and it's ilkDonald Sharp
Convert the `struct thread_master` to `struct event_master` across the code base. Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2023-03-24*: Convert thread_execute to event_executeDonald Sharp
Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2023-03-24*: Convert thread_add_XXX functions to event_add_XXXDonald Sharp
Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2023-03-24*: Rename `struct thread` to `struct event`Donald Sharp
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*: Rename thread.[ch] to event.[ch]Donald Sharp
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-20lib: on bfd peer shutdown actually stop eventDonald Sharp
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-02-09*: auto-convert to SPDX License IDsDavid Lamparter
Done with a combination of regex'ing and banging my head against a wall. Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2023-01-24lib: remove concurrent nexthop zapi (un)registrationLouis Scalbert
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-24lib: do not reopen a zclient socket for bfdLouis Scalbert
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-13lib: BFD integration clean up functionRafael Zalamena
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-13lib: BFD automatic source selectionRafael Zalamena
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>
2022-02-23*: Change thread->func to return void instead of intDonald Sharp
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-01-12lib: fix the right value is returned for fail casesanlan_cs
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-10lib: rename one bfd parameter name to reflect real meaninganlan_cs
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-08lib: small debug adjustment for bfdanlan_cs
Just use `__func__` to display function name. Signed-off-by: anlan_cs <anlan_cs@tom.com>
2021-11-15lib: rename bfd function to reflect real functionalityIgor Ryzhov
Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2021-11-11lib: remove confusing bfd TTL APIIgor Ryzhov
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-04lib: constify read only parametersRafael Zalamena
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-04lib: fix BFD IPv6 session address changeRenato Westphal
Pass the correct family type and remove unneeded casts. Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2021-10-20*: convert zclient callbacks to tableDavid Lamparter
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-05lib: fix spelling nits in more lib filesewlumpkin
Signed-off-by: ewlumpkin <ewlumpkin@gmail.com>
2021-08-27lib: Send c-bit when not using bfdd as daemon of choiceDonald Sharp
Commit: 4b983eef2cb5c7306a8303f002d0e053ebeabdca 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-06-01lib: fix default ttl for single-hop bfd sessionsIgor Ryzhov
The TTL field is actually the number of hops, not a TTL. Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2021-06-01lib: fix bfd multihopIgor Ryzhov
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-05-07lib: remove old bfd libraryIgor Ryzhov
This commit also adds missing `bfd_protocol_integration_set_shutdown` to ospf6d and pimd. Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2021-04-24Merge pull request #8495 from opensourcerouting/ospfv3-bfd-reworkIgor Ryzhov
ospf6d: rework BFD integration and add BFD profiles support
2021-04-22lib: BFD session handling improvementRafael Zalamena
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-22lib: fix possible crash on BFD notificationRafael Zalamena
Allow sessions to remove themselves from the notifications without risking crashes. Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
2021-04-22lib: remove enabled flag for bfd sessionsIgor Ryzhov
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-14lib: fix BFD crash on interface removalRafael Zalamena
- 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-09ospfd: fix crash on "show ip ospf neighbor detail"Igor Ryzhov
Fixes #8419. Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2021-03-23lib: small BFD session notifier improvementRafael Zalamena
Cache current monotime to avoid unnecessary calls. Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
2021-03-23lib: new BFD integration APIRafael Zalamena
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-17*: require semicolon after DEFINE_MTYPE & coDavid Lamparter
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-02-07*: Fix usage of bfd_adj_eventDonald Sharp
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>
2020-11-18Merge pull request #7478 from donaldsharp/bufferMark Stapp
Buffer
2020-11-15bgpd, lib, sharpd: Add enum for zclient_send_message returnDonald Sharp
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-08lib: notify BFD when adding new profileRafael Zalamena
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-08bfdd,lib: simplify integration protocolRafael Zalamena
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-07-21Merge pull request #6711 from GalaxyGorilla/bfd_isis_profilesQuentin Young
Add BFD profiles for IS-IS
2020-07-14*: un-split strings across linesDavid Lamparter
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-10isisd: lib: refactor ISIS BFD APIGalaxyGorilla
Use `zclient_bfd_command` instead of `bfd_peer_sendmsg`. Signed-off-by: GalaxyGorilla <sascha@netdef.org>
2020-07-10 *: add BFD profile support for IS-ISGalaxyGorilla
BFD profiles can now be used on the interface level like this: interface eth1 ip router isis 1 isis bfd isis bfd profile default Here the 'default' profile needs to be specified as usual in the bfdd configuration. Signed-off-by: GalaxyGorilla <sascha@netdef.org>
2020-06-12lib: permit BFD library users to pass NULLRafael Zalamena
Add the proper handling for cases where user forgets or doesn't have the pointer needed to call the library function. Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>