Commit graph

103 commits

Author SHA1 Message Date
Mark Stapp 660cbf5651 bgpd: clean up variable-shadowing compiler warnings
Clean up -Wshadow warnings in bgp.

Signed-off-by: Mark Stapp <mjs@cisco.com>
2025-04-08 14:41:27 -04:00
Louis Scalbert dee3fd6f1b bgpd: fix bfd with update-source in peer-group
Fix BFD session not created when the peer is in update-group with the
update-source option.

Signed-off-by: Louis Scalbert <louis.scalbert@6wind.com>
2025-01-22 17:55:55 +01:00
Donald Sharp 78fa9b6feb bgpd: su_remote and su_local are properties of the connection
su_local and su_remote in the peer can change based upon
if we are initiating the remote connection or receiving it.
As such we need to treat it as a property of the connection.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2025-01-10 10:07:11 -05:00
Donald Sharp c1c6298dd3 bgpd: Allow bfd to work if peer known but interface address not yet
If bgp is coming up and bgp has not received the interface address yet
but bgp has knowledge about a bfd peering, allow it to set the peering
data appropriately.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2024-11-20 16:13:42 -05:00
Russ White fe56a659b6
Merge pull request #17410 from opensourcerouting/fix/bgpd_ebgp_multihop_set_unset
BGP BFD session things
2024-11-12 11:02:22 -05:00
Donatas Abraitis fcabeeaf79 bgpd: Update source address for BFD session
If BFD is down, we should try to detect the source automatically from the given
interface.

Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2024-11-12 13:09:09 +02:00
Donatas Abraitis 247a75d5c6 bgpd: Reset BGP session only if it was a real BFD DOWN event
Without this patch we always see a double-reset, e.g.:

```
2024/11/04 12:42:43.010 BGP: [VQY9X-CQZKG] bgp_peer_bfd_update_source: address [0.0.0.0->172.18.0.3] to [172.18.0.2->172.18.0.3]
2024/11/04 12:42:43.010 BGP: [X8BD9-8RKN4] bgp_peer_bfd_update_source: interface none to eth0
2024/11/04 12:42:43.010 BFD: [MSVDW-Y8Z5Q] ptm-del-dest: deregister peer [mhop:no peer:172.18.0.3 local:0.0.0.0 vrf:default cbit:0x00 minimum-ttl:255]
2024/11/04 12:42:43.010 BFD: [NYF5K-SE3NS] ptm-del-session: [mhop:no peer:172.18.0.3 local:0.0.0.0 vrf:default] refcount=0
2024/11/04 12:42:43.010 BFD: [NW21R-MRYNT] session-delete: mhop:no peer:172.18.0.3 local:0.0.0.0 vrf:default
2024/11/04 12:42:43.010 BGP: [P3D3N-3277A] 172.18.0.3 [FSM] Timer (routeadv timer expire)
2024/11/04 12:42:43.010 BFD: [YA0Q5-C0BPV] control-packet: no session found [mhop:no peer:172.18.0.3 local:172.18.0.2 port:11]
2024/11/04 12:42:43.010 BFD: [MSVDW-Y8Z5Q] ptm-add-dest: register peer [mhop:no peer:172.18.0.3 local:172.18.0.2 vrf:default cbit:0x00 minimum-ttl:255]
2024/11/04 12:42:43.011 BFD: [PSB4R-8T1TJ] session-new: mhop:no peer:172.18.0.3 local:172.18.0.2 vrf:default ifname:eth0
2024/11/04 12:42:43.011 BGP: [Q4BCV-6FHZ5] zclient_bfd_session_update: 172.18.0.2/32 -> 172.18.0.3/32 (interface eth0) VRF default(0) (CPI bit no): Down
2024/11/04 12:42:43.011 BGP: [MKVHZ-7MS3V] bfd_session_status_update: neighbor 172.18.0.3 vrf default(0) bfd state Up -> Down
2024/11/04 12:42:43.011 BGP: [HZN6M-XRM1G] %NOTIFICATION: sent to neighbor 172.18.0.3 6/10 (Cease/BFD Down) 0 bytes
2024/11/04 12:42:43.011 BGP: [QFMSE-NPSNN] zclient_bfd_session_update:   sessions updated: 1
2024/11/04 12:42:43.011 BGP: [ZWCSR-M7FG9] 172.18.0.3 [FSM] BGP_Stop (Established->Clearing), fd 22
```

Reset is due to the source address change.

With this patch, we reset the session only if it's a _REAL_ BFD down event, which
means we trigger session reset if BFD session is established earlier than BGP.

Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2024-11-05 20:07:30 +02:00
Dmitrii Turlupov 25739271a0 bgpd: fix disable bfd profile for neighbors.
Before this patch after command
'no neighbor <A.B.C.D|X:X::X:X|WORD> bfd profile [BFDPROF]'
has always been created bfd-config for neighbor.

Signed-off-by: Dmitrii Turlupov <turlupov@zts.ru>
2024-03-13 01:15:16 +03:00
Donald Sharp 0c3a70c644 bgpd: Move the peer->su to connection->su
The sockunion is per connection.  So let's move it over.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2023-09-10 08:31:25 -04:00
Donald Sharp b57e023cc2 bgpd: Convert bgp_fsm_nht_update to take a connection
Convert this function over to using a connection.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2023-09-10 08:31:25 -04:00
Donald Sharp d2ba78929f bgpd: bgp_fsm_change_status/BGP_TIMER_ON and BGP_EVENT_ADD
Modify bgp_fsm_change_status to be connection oriented and
also make the BGP_TIMER_ON and BGP_EVENT_ADD macros connection
oriented as well.  Attempt to make peer_xfer_conn a bit more
understandable because, frankly it was/is confusing.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2023-09-10 08:31:25 -04:00
Donald Sharp 7b1158b169 bgpd: peer_established should be connection oriented
The peer_established function should be connection oriented.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2023-09-10 08:31:25 -04:00
Donald Sharp 3842286ed4 bgpd: bgp_notify_send use peer_connection instead of peer
The bgp_notify_send function should use a peer_connection

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2023-09-09 16:28:05 -04:00
Donald Sharp 3e5a31b24e bgpd: Convert struct peer_connection to dynamically allocated
As part of the conversion to a `struct peer_connection` it will
be desirable to have 2 pointers one for when we open a connection
and one for when we receive a connection.  Start this actual
conversion over to this in `struct peer`.  If this sounds confusing
take a look at the bgp state machine for connections and how
it resolves the processing of this router opening -vs- this
router receiving an open.  At some point in time the state
machine decides that we are keeping one of the two connections.

Future commits will allow us to untangle the peer/doppelganger
duality with this abstraction.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2023-08-18 09:29:04 -04:00
Donald Sharp e20c23fa5b bgpd: Move status and ostatus to struct peer_connection
The status and ostatus are a function of the `struct peer_connection`
move it into that data structure.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2023-08-18 09:29:04 -04:00
Donatas Abraitis 50136862b9 doc: Add missing rfc9384 to BGP supported RFC list
Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2023-04-01 21:56:37 +03: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 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 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
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
Donatas Abraitis 0edec0dd29 bgpd: Don't warning twice for neighbor_bfd_check_controlplane_failure
When the peer is not defined first.

Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2023-01-11 15:58:10 +02:00
Donatas Abraitis 95291f18bc bgpd: Replace zlog_info -> zlog_debug under BGP_DEBUG()
Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2022-06-21 11:59:52 +03:00
Donatas Abraitis aebe2e379f bgpd: Add Notification CEASE BFD Down message
Related: https://datatracker.ietf.org/doc/html/draft-ietf-idr-bfd-subcode

When BFD Down notification comes and BGP is configured to track on BFD events,
send BGP Cease/BFD Down notification to the peer.

If RFC 8538 is enabled (Notification support for Graceful-Restart), notification
should be encapsulated into Hard Reset message.

Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2022-06-02 16:06:57 +03:00
Igor Ryzhov 5b7586900a bgpd: fix source-address for BFD sessions when using update-source IFNAME
When "update-source IFNAME" is used for the neighbor, p->update_source
is set to NULL, so we can't use it as a source address and should use
the address from p->su_local.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2021-11-12 19:32:06 +03:00
Rafael Zalamena 7196f56eb3 bgpd: update BFD config on update-source change
Update BFD sessions when the update-source configuration is set so the
session follows the new configured source address.

Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
2021-11-04 08:01:28 -03:00
Rafael Zalamena 373de4b5b0 bgpd: fix crash during configuration removal
Test the BFD config pointer before trying to free the session as it
might not exist.

Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
2021-07-14 14:42:48 -03:00
Donald Sharp feb1723846 bgpd: Convert to using peer_established(peer) function
We are inconsistently using peer_establiahed(peer) with
sometimes using `peer->status == Established`.  Just Convert
over to using the function for consistency.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2021-06-07 10:48:36 -04: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
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 4a0872fc73 bgpd: improve BFD with timers configuration
Move `bgp_peer_config_apply` outside `bgp_peer_configure_bfd` (and
document it) so we only call the session installation once with one
set of timers. It also makes all calls of that function
equal (e.g. always calls `bgp_peer_config_apply` afterwards).

Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
2021-03-23 12:40:11 -03:00
Rafael Zalamena 259f42367c bgpd: add debug option for BFD
Add new BGP debug option to enable BFD related debugging messages.

Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
2021-03-23 12:40:10 -03:00
Rafael Zalamena 21bfce9827 bgpd: rework BFD integration
Remove old BFD API usage and replace it with the new one.

Highlights:

 - More shared code: the daemon gets notified with callbacks instead of
   having to roll its own code to find the notified sessions.

 - Less code to integrate with BFD.

 - Remove hidden commands to configure single / multi hop. Use
   protocol data instead.

   BGP can determine if a peer is single/multi hop according to the
   following criteria:

    a. If the IP address is a link-local address (single hop)

    b. The network is shared with peer (single hop)

    c. BGP is configured for eBGP multi hop / TTL security (multi hop)

 - Respect the configuration hierarchy:

    a. Peer configuration take precendence over peer-group
       configuration.

    b. When peer group configuration is removed, reset peer
       BFD configurations to defaults (unless peer had specific
       configs).

       Example:

         neighbor foo peer-group
         neighbor foo bfd profile X
         neighbor 192.168.0.2 peer-group foo
         neighbor 192.168.0.2 bfd
         ! If peer-group is removed the profile configuration gets
         ! removed from peer 192.168.0.2, but BFD will still enabled
         ! because of the neighbor specific bfd configuration.

Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
2021-03-23 12:40:10 -03:00
Donald Sharp 374a068642 bgpd: Fix profiles compile issue when not using bfdd
When compiling w/ --enable-bfdd=no we get warnings
about functions not being used.

Add a #if check to include it as needed.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2020-10-26 11:25:28 -04:00
Donatas Abraitis 2dbe669bdf :* Convert prefix2str to %pFX
Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
2020-10-22 09:07:41 +03:00
Quentin Young f8dcd38ddb bgpd: rename bgp_fsm_event_update
This function is poorly named; it's really used to allow the FSM to
decide the next valid state based on whether a peer has valid /
reachable nexthops as determined by NHT or BFD.

Signed-off-by: Quentin Young <qlyoung@nvidia.com>
2020-09-17 12:45:37 -04: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
GalaxyGorilla 4affdba79e *: add BFD profile support for IS-IS
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-07-10 11:28:43 +00:00
Donald Sharp 7799deeed6
Merge pull request #6437 from opensourcerouting/bfd-profiles-bgp
bfdd,bgpd: profiles integration support
2020-07-02 12:22:44 -04:00
Rafael Zalamena 4aa283cd4e bgpd: attempt to fix test convergence failure
Don't reset BFD peer on BGP session establishment.

Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
2020-06-18 16:51:13 -03:00
Rafael Zalamena 95a99382cb bgpd: fix crash on daemon exit
Don't attempt to send BFD daemon a message to remove the peer
registration on daemon exit, otherwise we'll access a dangling
interface pointer and we'll crash.

This crash was not previosly possible because the function that built
the message was passing the interface pointer but not using it due to
the exit condition.

In `lib/bfd.c`:

```
void bfd_peer_sendmsg(struct zclient *zclient, struct bfd_info *bfd_info,
		      int family, void *dst_ip, void *src_ip, char *if_name,
		      int ttl, int multihop, int cbit, int command,
		      int set_flag, vrf_id_t vrf_id)
{
	struct bfd_session_arg args = {};
	size_t addrlen;

	/* Individual reg/dereg messages are suppressed during shutdown. */
	if (CHECK_FLAG(bfd_gbl.flags, BFD_GBL_FLAG_IN_SHUTDOWN)) {
		if (bfd_debug)
			zlog_debug(
				"%s: Suppressing BFD peer reg/dereg messages",
				__func__);
		return;
	}
```

Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
2020-05-29 17:48:14 -03:00
Rafael Zalamena 68286f9619 bgpd: command to remove profile configuration
To remove a BFD profile without removing the BFD configuration just call
`neighbor <A.B.C.D|X:X::X:X|WORD> bfd`.

Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
2020-05-29 17:48:14 -03:00
Rafael Zalamena 02012befe8 bgpd: support BFD profiles configuration
Allow BGP to use the new API to configure BFD session profiles. Now it
is possible to preconfigure BFD sessions without needing to create the
peers.

Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
2020-05-29 17:48:14 -03:00
Donatas Abraitis 3dc339cdc2 bgpd: Convert lots of int type functions to bool/void
Some were converted to bool, where true/false status is needed.
Converted to void only those, where the return status was only false or true.

Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
2020-03-21 14:59:18 +02:00
Philippe Guibert fe0c4ed7ba bgpd: reset bfd session when bgp comes up
This scenario has been seen against microtik virtual machine with
bfd enabled. When remote microtik bgp reestablishes the bgp session
after a bgp reset, the bgp establishment comes first, then bfd is
initialising.
The second point is true for microtik, but not for frrouting, as the
frrouting, when receiving bfd down messages, is not at init state.
Actually, bfd state is up, and sees the first bfd down packet from
bfd as an issue. Consequently, the BGP session is cleared.
The fix consists in resetting the BFD session, only if bfd status is
considered as up, once BGP comes up.
That permits to align state machines of both local and remote bfd.

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2020-03-13 16:38:33 +01:00
Donald Sharp 137147c66a bgpd: Print out vrf name as well as id
The vrf_id is not enough context for people.  Use the
actual name of the vrf if you can.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2020-02-14 08:44:27 -05:00
Donatas Abraitis 892fedb611 bgpd: Replace bgp_flag_* to [UN]SET/CHECK_FLAG macros
Most of the code uses macros, thus let's keep the code unified.

Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
2020-02-06 17:11:38 +02:00
SumitAgarwal123 7555dc6116 bfdd: Handling local and remote admin-down
Scenarios where this code change is required:

1. BFD is un-configured from BGP at remote end.

Neighbour BFD sends ADMIN_DOWN state, but BFD on local side will send
DOWN to BGP, resulting in BGP session DOWN.
Removing BFD session administratively shouldn't bring DOWN BGP session
at local or remote.

2. BFD is un-configured from BGP or shutdown locally.

BFD will send state DOWN to BGP resulting in BGP session DOWN.
(This is akin to saying do not use BFD for BGP)
Removing BFD session administratively shouldn't bring DOWN BGP session at
local or remote.

Signed-off-by: Sayed Mohd Saquib sayed.saquib@broadcom.com
2019-10-28 21:38:20 -07:00
Philippe Guibert dcffea6912 bgpd: add vty command to enable bfd control-plane-check-failure
new vty command is added:
neighbor XXX bfd check-control-plane-failure

this command will enforce the check of bgp controlplane, when bfd
detects changes in the dataplane.
- at configuration, the cbit will be set if that command is executed
- at flapping time, if the command is configured and remote cbit is set
  accordingly, then the bfd event will be ignored.

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2019-05-14 16:49:49 +02:00