Skip to content

Commit 3795733

Browse files
rzalamenamergify-bot
authored andcommitted
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> (cherry picked from commit 7196f56)
1 parent b01ab32 commit 3795733

File tree

2 files changed

+42
-16
lines changed

2 files changed

+42
-16
lines changed

bgpd/bgp_bfd.c

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ void bgp_peer_config_apply(struct peer *p, struct peer_group *pg)
150150
void bgp_peer_bfd_update_source(struct peer *p)
151151
{
152152
struct bfd_session_params *session = p->bfd_config->session;
153+
const union sockunion *source;
153154
bool changed = false;
154155
int family;
155156
union {
@@ -161,44 +162,45 @@ void bgp_peer_bfd_update_source(struct peer *p)
161162
if (CHECK_FLAG(p->sflags, PEER_STATUS_GROUP))
162163
return;
163164

165+
/* Figure out the correct source to use. */
166+
if (CHECK_FLAG(p->flags, PEER_FLAG_UPDATE_SOURCE))
167+
source = p->update_source;
168+
else
169+
source = p->su_local;
170+
164171
/* Update peer's source/destination addresses. */
165172
bfd_sess_addresses(session, &family, &src.v6, &dst.v6);
166173
if (family == AF_INET) {
167-
if ((p->su_local
168-
&& p->su_local->sin.sin_addr.s_addr != src.v4.s_addr)
174+
if ((source && source->sin.sin_addr.s_addr != src.v4.s_addr)
169175
|| p->su.sin.sin_addr.s_addr != dst.v4.s_addr) {
170176
if (BGP_DEBUG(bfd, BFD_LIB))
171177
zlog_debug(
172178
"%s: address [%pI4->%pI4] to [%pI4->%pI4]",
173179
__func__, &src.v4, &dst.v4,
174-
p->su_local ? &p->su_local->sin.sin_addr
175-
: &src.v4,
180+
source ? &source->sin.sin_addr
181+
: &src.v4,
176182
&p->su.sin.sin_addr);
177183

178184
bfd_sess_set_ipv4_addrs(
179-
session,
180-
p->su_local ? &p->su_local->sin.sin_addr : NULL,
185+
session, source ? &source->sin.sin_addr : NULL,
181186
&p->su.sin.sin_addr);
182187
changed = true;
183188
}
184189
} else {
185-
if ((p->su_local
186-
&& memcmp(&p->su_local->sin6, &src.v6, sizeof(src.v6)))
190+
if ((source && memcmp(&source->sin6, &src.v6, sizeof(src.v6)))
187191
|| memcmp(&p->su.sin6, &dst.v6, sizeof(dst.v6))) {
188192
if (BGP_DEBUG(bfd, BFD_LIB))
189193
zlog_debug(
190194
"%s: address [%pI6->%pI6] to [%pI6->%pI6]",
191195
__func__, &src.v6, &dst.v6,
192-
p->su_local
193-
? &p->su_local->sin6.sin6_addr
194-
: &src.v6,
196+
source ? &source->sin6.sin6_addr
197+
: &src.v6,
195198
&p->su.sin6.sin6_addr);
196199

197-
bfd_sess_set_ipv6_addrs(
198-
session,
199-
p->su_local ? &p->su_local->sin6.sin6_addr
200-
: NULL,
201-
&p->su.sin6.sin6_addr);
200+
bfd_sess_set_ipv6_addrs(session,
201+
source ? &source->sin6.sin6_addr
202+
: NULL,
203+
&p->su.sin6.sin6_addr);
202204
changed = true;
203205
}
204206
}

bgpd/bgpd.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4875,6 +4875,10 @@ int peer_update_source_if_set(struct peer *peer, const char *ifname)
48754875
} else
48764876
bgp_session_reset(peer);
48774877

4878+
/* Apply new source configuration to BFD session. */
4879+
if (peer->bfd_config)
4880+
bgp_peer_bfd_update_source(peer);
4881+
48784882
/* Skip peer-group mechanics for regular peers. */
48794883
return 0;
48804884
}
@@ -4908,6 +4912,10 @@ int peer_update_source_if_set(struct peer *peer, const char *ifname)
49084912
BGP_NOTIFY_CEASE_CONFIG_CHANGE);
49094913
} else
49104914
bgp_session_reset(member);
4915+
4916+
/* Apply new source configuration to BFD session. */
4917+
if (member->bfd_config)
4918+
bgp_peer_bfd_update_source(member);
49114919
}
49124920

49134921
return 0;
@@ -4938,6 +4946,10 @@ int peer_update_source_addr_set(struct peer *peer, const union sockunion *su)
49384946
} else
49394947
bgp_session_reset(peer);
49404948

4949+
/* Apply new source configuration to BFD session. */
4950+
if (peer->bfd_config)
4951+
bgp_peer_bfd_update_source(peer);
4952+
49414953
/* Skip peer-group mechanics for regular peers. */
49424954
return 0;
49434955
}
@@ -4970,6 +4982,10 @@ int peer_update_source_addr_set(struct peer *peer, const union sockunion *su)
49704982
BGP_NOTIFY_CEASE_CONFIG_CHANGE);
49714983
} else
49724984
bgp_session_reset(member);
4985+
4986+
/* Apply new source configuration to BFD session. */
4987+
if (member->bfd_config)
4988+
bgp_peer_bfd_update_source(member);
49734989
}
49744990

49754991
return 0;
@@ -5007,6 +5023,10 @@ int peer_update_source_unset(struct peer *peer)
50075023
} else
50085024
bgp_session_reset(peer);
50095025

5026+
/* Apply new source configuration to BFD session. */
5027+
if (peer->bfd_config)
5028+
bgp_peer_bfd_update_source(peer);
5029+
50105030
/* Skip peer-group mechanics for regular peers. */
50115031
return 0;
50125032
}
@@ -5038,6 +5058,10 @@ int peer_update_source_unset(struct peer *peer)
50385058
BGP_NOTIFY_CEASE_CONFIG_CHANGE);
50395059
} else
50405060
bgp_session_reset(member);
5061+
5062+
/* Apply new source configuration to BFD session. */
5063+
if (member->bfd_config)
5064+
bgp_peer_bfd_update_source(member);
50415065
}
50425066

50435067
return 0;

0 commit comments

Comments
 (0)