Skip to content

Commit 47deea3

Browse files
authored
Merge pull request FRRouting#19427 from FRRouting/mergify/bp/stable/10.1/pr-19362
bgpd: Fix crash due to dangling pointer in bnc nht_info (backport FRRouting#19362)
2 parents 11ea60c + fbbf871 commit 47deea3

File tree

1 file changed

+17
-20
lines changed

1 file changed

+17
-20
lines changed

bgpd/bgp_nht.c

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -525,26 +525,23 @@ void bgp_delete_connected_nexthop(afi_t afi, struct peer *peer)
525525
if (!peer)
526526
return;
527527

528-
/*
529-
* In case the below check evaluates true and if
530-
* the bnc has not been freed at this point, then
531-
* we might have to do something similar to what's
532-
* done in bgp_unlink_nexthop_by_peer(). Since
533-
* bgp_unlink_nexthop_by_peer() loops through the
534-
* nodes of V6 nexthop cache to find the bnc, it is
535-
* currently not being called here.
536-
*/
537-
if (!sockunion2hostprefix(&peer->connection->su, &p))
538-
return;
539-
/*
540-
* Gather the ifindex for if up/down events to be
541-
* tagged into this fun
542-
*/
543-
if (afi == AFI_IP6 &&
544-
IN6_IS_ADDR_LINKLOCAL(&peer->connection->su.sin6.sin6_addr))
545-
ifindex = peer->connection->su.sin6.sin6_scope_id;
546-
bnc = bnc_find(&peer->bgp->nexthop_cache_table[family2afi(p.family)],
547-
&p, 0, ifindex);
528+
if (!sockunion2hostprefix(&peer->connection->su, &p)) {
529+
/*
530+
* If peer->connection->su is cleared before peer deletion,
531+
* find the bnc whose nht_info matches the peer and free it.
532+
*/
533+
bnc = bgp_find_ipv6_nexthop_matching_peer(peer);
534+
} else {
535+
/*
536+
* Gather the ifindex for if up/down events to be
537+
* tagged into this fun
538+
*/
539+
if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&peer->connection->su.sin6.sin6_addr))
540+
ifindex = peer->connection->su.sin6.sin6_scope_id;
541+
bnc = bnc_find(&peer->bgp->nexthop_cache_table[family2afi(p.family)], &p, 0,
542+
ifindex);
543+
}
544+
548545
if (!bnc) {
549546
if (BGP_DEBUG(nht, NHT))
550547
zlog_debug(

0 commit comments

Comments
 (0)