From 1fb48f5d13faf4ec1e6d4c2cdded9ca2dcd6d609 Mon Sep 17 00:00:00 2001 From: Donatas Abraitis Date: Wed, 12 Jun 2024 08:39:48 +0300 Subject: [PATCH] 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 --- bgpd/bgpd.c | 6 ++++++ lib/bfd.c | 6 ++++++ lib/bfd.h | 2 ++ 3 files changed, 14 insertions(+) diff --git a/bgpd/bgpd.c b/bgpd/bgpd.c index 81506f4410..869d2b4552 100644 --- a/bgpd/bgpd.c +++ b/bgpd/bgpd.c @@ -4507,6 +4507,12 @@ bool peer_active(struct peer *peer) { if (BGP_CONNECTION_SU_UNSPEC(peer->connection)) return false; + + if (peer->bfd_config) { + if (bfd_session_is_down(peer->bfd_config->session)) + return false; + } + if (peer->afc[AFI_IP][SAFI_UNICAST] || peer->afc[AFI_IP][SAFI_MULTICAST] || peer->afc[AFI_IP][SAFI_LABELED_UNICAST] || peer->afc[AFI_IP][SAFI_MPLS_VPN] || peer->afc[AFI_IP][SAFI_ENCAP] diff --git a/lib/bfd.c b/lib/bfd.c index 2222bb9547..4535fc1233 100644 --- a/lib/bfd.c +++ b/lib/bfd.c @@ -1334,3 +1334,9 @@ int bfd_nht_update(const struct prefix *match, const struct zapi_route *route) return 0; } + +bool bfd_session_is_down(const struct bfd_session_params *session) +{ + return session->bss.state == BSS_DOWN || + session->bss.state == BSS_ADMIN_DOWN; +} diff --git a/lib/bfd.h b/lib/bfd.h index bfa5287340..48929a9564 100644 --- a/lib/bfd.h +++ b/lib/bfd.h @@ -464,6 +464,8 @@ extern bool bfd_protocol_integration_shutting_down(void); extern int bfd_nht_update(const struct prefix *match, const struct zapi_route *route); +extern bool bfd_session_is_down(const struct bfd_session_params *session); + #ifdef __cplusplus } #endif -- 2.39.5