From ae0945733333f60fccb0b4ac170ca3ee7351828b Mon Sep 17 00:00:00 2001 From: Renato Westphal Date: Thu, 28 Oct 2021 12:35:56 -0300 Subject: [PATCH 1/4] lib: fix BFD IPv6 session address change Pass the correct family type and remove unneeded casts. Signed-off-by: Renato Westphal --- lib/bfd.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/bfd.c b/lib/bfd.c index 70cbe0f2a6..cad0916d7d 100644 --- a/lib/bfd.c +++ b/lib/bfd.c @@ -578,8 +578,7 @@ void bfd_sess_set_ipv4_addrs(struct bfd_session_params *bsp, void bfd_sess_set_ipv6_addrs(struct bfd_session_params *bsp, struct in6_addr *src, struct in6_addr *dst) { - if (!bfd_sess_address_changed(bsp, AF_INET, (struct in6_addr *)src, - (struct in6_addr *)dst)) + if (!bfd_sess_address_changed(bsp, AF_INET6, src, dst)) return; /* If already installed, remove the old setting. */ From ca30ac7fc375e3979776bb229587415f05bd4ce9 Mon Sep 17 00:00:00 2001 From: Rafael Zalamena Date: Wed, 3 Nov 2021 08:45:02 -0300 Subject: [PATCH 2/4] 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 --- lib/bfd.c | 6 ++++-- lib/bfd.h | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/bfd.c b/lib/bfd.c index cad0916d7d..9800ed4924 100644 --- a/lib/bfd.c +++ b/lib/bfd.c @@ -552,7 +552,8 @@ static bool bfd_sess_address_changed(const struct bfd_session_params *bsp, } void bfd_sess_set_ipv4_addrs(struct bfd_session_params *bsp, - struct in_addr *src, struct in_addr *dst) + const struct in_addr *src, + const struct in_addr *dst) { if (!bfd_sess_address_changed(bsp, AF_INET, (struct in6_addr *)src, (struct in6_addr *)dst)) @@ -576,7 +577,8 @@ void bfd_sess_set_ipv4_addrs(struct bfd_session_params *bsp, } void bfd_sess_set_ipv6_addrs(struct bfd_session_params *bsp, - struct in6_addr *src, struct in6_addr *dst) + const struct in6_addr *src, + const struct in6_addr *dst) { if (!bfd_sess_address_changed(bsp, AF_INET6, src, dst)) return; diff --git a/lib/bfd.h b/lib/bfd.h index 6c0d1c177e..cc9659ff79 100644 --- a/lib/bfd.h +++ b/lib/bfd.h @@ -124,7 +124,8 @@ void bfd_sess_free(struct bfd_session_params **bsp); * \param dst remote address (mandatory). */ void bfd_sess_set_ipv4_addrs(struct bfd_session_params *bsp, - struct in_addr *src, struct in_addr *dst); + const struct in_addr *src, + const struct in_addr *dst); /** * Set the local and peer address of the BFD session. @@ -138,7 +139,8 @@ void bfd_sess_set_ipv4_addrs(struct bfd_session_params *bsp, * \param dst remote address (mandatory). */ void bfd_sess_set_ipv6_addrs(struct bfd_session_params *bsp, - struct in6_addr *src, struct in6_addr *dst); + const struct in6_addr *src, + const struct in6_addr *dst); /** * Configure the BFD session interface. From 4ba37eb691f9574e908ec7ed03e8f4cb4214f2d5 Mon Sep 17 00:00:00 2001 From: Rafael Zalamena Date: Tue, 2 Nov 2021 18:54:23 -0300 Subject: [PATCH 3/4] bgpd: fix BFD configuration update on TTL change When altering the TTL of a eBGP peer also update the BFD configuration. This was only working when the configuration happened after the peer connection had been established. Signed-off-by: Rafael Zalamena --- bgpd/bgpd.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/bgpd/bgpd.c b/bgpd/bgpd.c index c5a5e49a48..bc731ff2b8 100644 --- a/bgpd/bgpd.c +++ b/bgpd/bgpd.c @@ -4752,6 +4752,10 @@ int peer_ebgp_multihop_set(struct peer *peer, int ttl) BGP_NOTIFY_CEASE_CONFIG_CHANGE); else bgp_session_reset(peer); + + /* Reconfigure BFD peer with new TTL. */ + if (peer->bfd_config) + bgp_peer_bfd_update_source(peer); } } else { group = peer->group; @@ -4766,6 +4770,10 @@ int peer_ebgp_multihop_set(struct peer *peer, int ttl) BGP_NOTIFY_CEASE_CONFIG_CHANGE); else bgp_session_reset(peer); + + /* Reconfigure BFD peer with new TTL. */ + if (peer->bfd_config) + bgp_peer_bfd_update_source(peer); } } return 0; @@ -4799,6 +4807,10 @@ int peer_ebgp_multihop_unset(struct peer *peer) BGP_NOTIFY_CEASE_CONFIG_CHANGE); else bgp_session_reset(peer); + + /* Reconfigure BFD peer with new TTL. */ + if (peer->bfd_config) + bgp_peer_bfd_update_source(peer); } else { group = peer->group; for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) { @@ -4815,6 +4827,10 @@ int peer_ebgp_multihop_unset(struct peer *peer) else bgp_session_reset(peer); } + + /* Reconfigure BFD peer with new TTL. */ + if (peer->bfd_config) + bgp_peer_bfd_update_source(peer); } } return 0; From 7196f56eb3d3866ccafee095c8be66f058d99abf Mon Sep 17 00:00:00 2001 From: Rafael Zalamena Date: Wed, 3 Nov 2021 08:43:17 -0300 Subject: [PATCH 4/4] 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 --- bgpd/bgp_bfd.c | 34 ++++++++++++++++++---------------- bgpd/bgpd.c | 24 ++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 16 deletions(-) diff --git a/bgpd/bgp_bfd.c b/bgpd/bgp_bfd.c index 4995f9a1fd..f23e6b2e9b 100644 --- a/bgpd/bgp_bfd.c +++ b/bgpd/bgp_bfd.c @@ -150,6 +150,7 @@ void bgp_peer_config_apply(struct peer *p, struct peer_group *pg) void bgp_peer_bfd_update_source(struct peer *p) { struct bfd_session_params *session = p->bfd_config->session; + const union sockunion *source; bool changed = false; int family; union { @@ -161,44 +162,45 @@ void bgp_peer_bfd_update_source(struct peer *p) if (CHECK_FLAG(p->sflags, PEER_STATUS_GROUP)) return; + /* Figure out the correct source to use. */ + if (CHECK_FLAG(p->flags, PEER_FLAG_UPDATE_SOURCE)) + source = p->update_source; + else + source = p->su_local; + /* Update peer's source/destination addresses. */ bfd_sess_addresses(session, &family, &src.v6, &dst.v6); if (family == AF_INET) { - if ((p->su_local - && p->su_local->sin.sin_addr.s_addr != src.v4.s_addr) + if ((source && source->sin.sin_addr.s_addr != src.v4.s_addr) || p->su.sin.sin_addr.s_addr != dst.v4.s_addr) { if (BGP_DEBUG(bfd, BFD_LIB)) zlog_debug( "%s: address [%pI4->%pI4] to [%pI4->%pI4]", __func__, &src.v4, &dst.v4, - p->su_local ? &p->su_local->sin.sin_addr - : &src.v4, + source ? &source->sin.sin_addr + : &src.v4, &p->su.sin.sin_addr); bfd_sess_set_ipv4_addrs( - session, - p->su_local ? &p->su_local->sin.sin_addr : NULL, + session, source ? &source->sin.sin_addr : NULL, &p->su.sin.sin_addr); changed = true; } } else { - if ((p->su_local - && memcmp(&p->su_local->sin6, &src.v6, sizeof(src.v6))) + if ((source && memcmp(&source->sin6, &src.v6, sizeof(src.v6))) || memcmp(&p->su.sin6, &dst.v6, sizeof(dst.v6))) { if (BGP_DEBUG(bfd, BFD_LIB)) zlog_debug( "%s: address [%pI6->%pI6] to [%pI6->%pI6]", __func__, &src.v6, &dst.v6, - p->su_local - ? &p->su_local->sin6.sin6_addr - : &src.v6, + source ? &source->sin6.sin6_addr + : &src.v6, &p->su.sin6.sin6_addr); - bfd_sess_set_ipv6_addrs( - session, - p->su_local ? &p->su_local->sin6.sin6_addr - : NULL, - &p->su.sin6.sin6_addr); + bfd_sess_set_ipv6_addrs(session, + source ? &source->sin6.sin6_addr + : NULL, + &p->su.sin6.sin6_addr); changed = true; } } diff --git a/bgpd/bgpd.c b/bgpd/bgpd.c index bc731ff2b8..c35d35d623 100644 --- a/bgpd/bgpd.c +++ b/bgpd/bgpd.c @@ -4876,6 +4876,10 @@ int peer_update_source_if_set(struct peer *peer, const char *ifname) } else bgp_session_reset(peer); + /* Apply new source configuration to BFD session. */ + if (peer->bfd_config) + bgp_peer_bfd_update_source(peer); + /* Skip peer-group mechanics for regular peers. */ return 0; } @@ -4909,6 +4913,10 @@ int peer_update_source_if_set(struct peer *peer, const char *ifname) BGP_NOTIFY_CEASE_CONFIG_CHANGE); } else bgp_session_reset(member); + + /* Apply new source configuration to BFD session. */ + if (member->bfd_config) + bgp_peer_bfd_update_source(member); } return 0; @@ -4939,6 +4947,10 @@ int peer_update_source_addr_set(struct peer *peer, const union sockunion *su) } else bgp_session_reset(peer); + /* Apply new source configuration to BFD session. */ + if (peer->bfd_config) + bgp_peer_bfd_update_source(peer); + /* Skip peer-group mechanics for regular peers. */ return 0; } @@ -4971,6 +4983,10 @@ int peer_update_source_addr_set(struct peer *peer, const union sockunion *su) BGP_NOTIFY_CEASE_CONFIG_CHANGE); } else bgp_session_reset(member); + + /* Apply new source configuration to BFD session. */ + if (member->bfd_config) + bgp_peer_bfd_update_source(member); } return 0; @@ -5008,6 +5024,10 @@ int peer_update_source_unset(struct peer *peer) } else bgp_session_reset(peer); + /* Apply new source configuration to BFD session. */ + if (peer->bfd_config) + bgp_peer_bfd_update_source(peer); + /* Skip peer-group mechanics for regular peers. */ return 0; } @@ -5039,6 +5059,10 @@ int peer_update_source_unset(struct peer *peer) BGP_NOTIFY_CEASE_CONFIG_CHANGE); } else bgp_session_reset(member); + + /* Apply new source configuration to BFD session. */ + if (member->bfd_config) + bgp_peer_bfd_update_source(member); } return 0;