From ee7ca6c05986a86967b7e92fc6213a2f33dd498a Mon Sep 17 00:00:00 2001 From: vivek Date: Wed, 9 Aug 2017 17:32:19 -0700 Subject: [PATCH] bgpd: Cleanup NHT state when underlying VRF goes down When the underlying VRF is deleted, ensure that state for the next hops that BGP registers with zebra for tracking purposes is properly updated. Otherwise BGP will not re-register the next hop when the VRF is re-created, resulting in the next hop staying unresolved. Signed-off-by: Vivek Venkatraman Reviewed-by: Don Slice Ticket: CM-17456 Reviewed By: CCR-6587 Testing Done: Manual, bgp-min, vrf --- bgpd/bgp_nht.c | 27 +++++++++++++++++++++++++++ bgpd/bgp_nht.h | 6 ++++++ bgpd/bgpd.c | 3 +++ 3 files changed, 36 insertions(+) diff --git a/bgpd/bgp_nht.c b/bgpd/bgp_nht.c index 3a7a60b14d..55a2f10132 100644 --- a/bgpd/bgp_nht.c +++ b/bgpd/bgp_nht.c @@ -482,6 +482,33 @@ void bgp_parse_nexthop_update(int command, vrf_id_t vrf_id) evaluate_paths(bnc); } +/* + * Cleanup nexthop registration and status information for BGP nexthops + * pertaining to this VRF. This is invoked upon VRF deletion. + */ +void bgp_cleanup_nexthops(struct bgp *bgp) +{ + afi_t afi; + struct bgp_node *rn; + struct bgp_nexthop_cache *bnc; + + for (afi = AFI_IP; afi < AFI_MAX; afi++) { + if (!bgp->nexthop_cache_table[afi]) + continue; + + for (rn = bgp_table_top(bgp->nexthop_cache_table[afi]); rn; + rn = bgp_route_next(rn)) { + if ((bnc = rn->info) == NULL) + continue; + + /* Clear relevant flags. */ + UNSET_FLAG(bnc->flags, BGP_NEXTHOP_VALID); + UNSET_FLAG(bnc->flags, BGP_NEXTHOP_REGISTERED); + UNSET_FLAG(bnc->flags, BGP_NEXTHOP_PEER_NOTIFIED); + } + } +} + /** * make_prefix - make a prefix structure from the path (essentially * path's node. diff --git a/bgpd/bgp_nht.h b/bgpd/bgp_nht.h index f649bb2259..4b297f410c 100644 --- a/bgpd/bgp_nht.h +++ b/bgpd/bgp_nht.h @@ -66,4 +66,10 @@ void bgp_unlink_nexthop_by_peer(struct peer *); */ extern void bgp_delete_connected_nexthop(afi_t afi, struct peer *peer); +/* + * Cleanup nexthop registration and status information for BGP nexthops + * pertaining to this VRF. This is invoked upon VRF deletion. + */ +extern void bgp_cleanup_nexthops(struct bgp *bgp); + #endif /* _BGP_NHT_H */ diff --git a/bgpd/bgpd.c b/bgpd/bgpd.c index c58e4e70cd..a017c4fa26 100644 --- a/bgpd/bgpd.c +++ b/bgpd/bgpd.c @@ -3031,6 +3031,9 @@ void bgp_instance_down(struct bgp *bgp) /* Purge network and redistributed routes. */ bgp_purge_static_redist_routes(bgp); + + /* Cleanup registered nexthops (flags) */ + bgp_cleanup_nexthops(bgp); } /* Delete BGP instance. */ -- 2.39.5