From e6458d36b7f9347815ccd2aa2d4af8107f84fce5 Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Sun, 10 Sep 2023 09:27:51 -0400 Subject: [PATCH] bgpd: bgp_adj_in_unset needs to return the dest pointer This is incase it has been freed ( it wont due to locking ) and then we need to ensure that we can continue to use the pointer. Signed-off-by: Donald Sharp --- bgpd/bgp_advertise.c | 8 ++++---- bgpd/bgp_advertise.h | 2 +- bgpd/bgp_route.c | 4 +++- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/bgpd/bgp_advertise.c b/bgpd/bgp_advertise.c index c215611edf..6f4916b3c3 100644 --- a/bgpd/bgp_advertise.c +++ b/bgpd/bgp_advertise.c @@ -197,13 +197,13 @@ void bgp_adj_in_remove(struct bgp_dest **dest, struct bgp_adj_in *bai) XFREE(MTYPE_BGP_ADJ_IN, bai); } -bool bgp_adj_in_unset(struct bgp_dest *dest, struct peer *peer, +bool bgp_adj_in_unset(struct bgp_dest **dest, struct peer *peer, uint32_t addpath_id) { struct bgp_adj_in *adj; struct bgp_adj_in *adj_next; - adj = dest->adj_in; + adj = (*dest)->adj_in; if (!adj) return false; @@ -212,11 +212,11 @@ bool bgp_adj_in_unset(struct bgp_dest *dest, struct peer *peer, adj_next = adj->next; if (adj->peer == peer && adj->addpath_rx_id == addpath_id) - bgp_adj_in_remove(&dest, adj); + bgp_adj_in_remove(dest, adj); adj = adj_next; - assert(dest); + assert(*dest); } return true; diff --git a/bgpd/bgp_advertise.h b/bgpd/bgp_advertise.h index e597c56d13..94168e2fd7 100644 --- a/bgpd/bgp_advertise.h +++ b/bgpd/bgp_advertise.h @@ -130,7 +130,7 @@ extern bool bgp_adj_out_lookup(struct peer *peer, struct bgp_dest *dest, uint32_t addpath_tx_id); extern void bgp_adj_in_set(struct bgp_dest *dest, struct peer *peer, struct attr *attr, uint32_t addpath_id); -extern bool bgp_adj_in_unset(struct bgp_dest *dest, struct peer *peer, +extern bool bgp_adj_in_unset(struct bgp_dest **dest, struct peer *peer, uint32_t addpath_id); extern void bgp_adj_in_remove(struct bgp_dest **dest, struct bgp_adj_in *bai); diff --git a/bgpd/bgp_route.c b/bgpd/bgp_route.c index e72ebe3ae7..34d36a6375 100644 --- a/bgpd/bgp_route.c +++ b/bgpd/bgp_route.c @@ -5083,7 +5083,8 @@ void bgp_withdraw(struct peer *peer, const struct prefix *p, */ if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG) && peer != bgp->peer_self) - if (!bgp_adj_in_unset(dest, peer, addpath_id)) { + if (!bgp_adj_in_unset(&dest, peer, addpath_id)) { + assert(dest); peer->stat_pfx_dup_withdraw++; if (bgp_debug_update(peer, p, NULL, 1)) { @@ -5100,6 +5101,7 @@ void bgp_withdraw(struct peer *peer, const struct prefix *p, } /* Lookup withdrawn route. */ + assert(dest); for (pi = bgp_dest_get_bgp_path_info(dest); pi; pi = pi->next) if (pi->peer == peer && pi->type == type && pi->sub_type == sub_type -- 2.39.5