Skip to content

Commit 51f3216

Browse files
Pdoijodedonaldsharp
authored andcommitted
bgpd: BGP fails to free the nexthop node
In case of BGP unnumbered, BGP fails to free the nexthop node for peer if the interface is shutdown before unconfiguring/deleting the BGP neighbor. This is because, when the interface is shutdown, peer's LL neighbor address will be cleared. Therefore, during neighbor deletion, since the peer's neighbor address is not available, BGP will skip freeing the nexthop node of this peer. This results in a stale nexthop node that points to a peer that's already been freed. Ticket: 3191547 Signed-off-by: Pooja Jagadeesh Doijode <pdoijode@nvidia.com>
1 parent 58552d2 commit 51f3216

1 file changed

Lines changed: 64 additions & 9 deletions

File tree

‎bgpd/bgp_nht.c‎

Lines changed: 64 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -212,22 +212,68 @@ void bgp_replace_nexthop_by_peer(struct peer *from, struct peer *to)
212212
bnct->nht_info = to;
213213
}
214214

215+
/*
216+
* Returns the bnc whose bnc->nht_info matches the LL peer by
217+
* looping through the IPv6 nexthop table
218+
*/
219+
static struct bgp_nexthop_cache *
220+
bgp_find_ipv6_nexthop_matching_peer(struct peer *peer)
221+
{
222+
struct bgp_nexthop_cache *bnc;
223+
224+
frr_each (bgp_nexthop_cache, &peer->bgp->nexthop_cache_table[AFI_IP6],
225+
bnc) {
226+
if (bnc->nht_info == peer) {
227+
if (BGP_DEBUG(nht, NHT)) {
228+
zlog_debug(
229+
"Found bnc: %pFX(%u)(%u)(%p) for peer: %s(%s) %p",
230+
&bnc->prefix, bnc->ifindex,
231+
bnc->srte_color, bnc, peer->host,
232+
peer->bgp->name_pretty, peer);
233+
}
234+
return bnc;
235+
}
236+
}
237+
238+
if (BGP_DEBUG(nht, NHT))
239+
zlog_debug(
240+
"Could not find bnc for peer %s(%s) %p in v6 nexthop table",
241+
peer->host, peer->bgp->name_pretty, peer);
242+
243+
return NULL;
244+
}
245+
215246
void bgp_unlink_nexthop_by_peer(struct peer *peer)
216247
{
217248
struct prefix p;
218249
struct bgp_nexthop_cache *bnc;
219250
afi_t afi = family2afi(peer->su.sa.sa_family);
220251
ifindex_t ifindex = 0;
221252

222-
if (!sockunion2hostprefix(&peer->su, &p))
223-
return;
224-
/*
225-
* Gather the ifindex for if up/down events to be
226-
* tagged into this fun
227-
*/
228-
if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&peer->su.sin6.sin6_addr))
229-
ifindex = peer->su.sin6.sin6_scope_id;
230-
bnc = bnc_find(&peer->bgp->nexthop_cache_table[afi], &p, 0, ifindex);
253+
if (!sockunion2hostprefix(&peer->su, &p)) {
254+
/*
255+
* In scenarios where unnumbered BGP session is brought
256+
* down by shutting down the interface before unconfiguring
257+
* the BGP neighbor, neighbor information in peer->su.sa
258+
* will be cleared when the interface is shutdown. So
259+
* during the deletion of unnumbered bgp peer, above check
260+
* will return true. Therefore, in this case,BGP needs to
261+
* find the bnc whose bnc->nht_info matches the
262+
* peer being deleted and free it.
263+
*/
264+
bnc = bgp_find_ipv6_nexthop_matching_peer(peer);
265+
} else {
266+
/*
267+
* Gather the ifindex for if up/down events to be
268+
* tagged into this fun
269+
*/
270+
if (afi == AFI_IP6 &&
271+
IN6_IS_ADDR_LINKLOCAL(&peer->su.sin6.sin6_addr))
272+
ifindex = peer->su.sin6.sin6_scope_id;
273+
bnc = bnc_find(&peer->bgp->nexthop_cache_table[afi], &p, 0,
274+
ifindex);
275+
}
276+
231277
if (!bnc)
232278
return;
233279

@@ -443,6 +489,15 @@ void bgp_delete_connected_nexthop(afi_t afi, struct peer *peer)
443489
if (!peer)
444490
return;
445491

492+
/*
493+
* In case the below check evaluates true and if
494+
* the bnc has not been freed at this point, then
495+
* we might have to do something similar to what's
496+
* done in bgp_unlink_nexthop_by_peer(). Since
497+
* bgp_unlink_nexthop_by_peer() loops through the
498+
* nodes of V6 nexthop cache to find the bnc, it is
499+
* currently not being called here.
500+
*/
446501
if (!sockunion2hostprefix(&peer->su, &p))
447502
return;
448503
/*

0 commit comments

Comments
 (0)