From 663281ca6a6b71cda391e3f64db8d51bfbac1a2f Mon Sep 17 00:00:00 2001 From: Yaroslav Kholod Date: Mon, 23 Dec 2024 17:35:12 +0200 Subject: [PATCH] BGP: Clean address-family config on daemon restart When stopping and restarting BGP daemon part of the configuration remains. It should be cleared. Particulary those are address-family parametes, like: distance, ead-es-frag, disable-ead-evi-rx, disable-ead-evi-tx. Signed-off-by: Yaroslav Kholod --- bgpd/bgp_route.c | 22 ++++++++++++++++++++++ bgpd/bgp_route.h | 1 + bgpd/bgpd.c | 8 ++++++++ 3 files changed, 31 insertions(+) diff --git a/bgpd/bgp_route.c b/bgpd/bgp_route.c index bd2fda56fc20..75427a905284 100644 --- a/bgpd/bgp_route.c +++ b/bgpd/bgp_route.c @@ -15778,6 +15778,28 @@ static int bgp_distance_unset(struct vty *vty, const char *distance_str, return CMD_SUCCESS; } +void bgp_address_family_distance_delete(void) +{ + afi_t afi = AFI_UNSPEC; + safi_t safi = SAFI_UNSPEC; + struct bgp_dest *dest = NULL; + struct bgp_distance *bdistance = NULL; + + FOREACH_AFI_SAFI (afi, safi) { + for (dest = bgp_table_top(bgp_distance_table[afi][safi]); dest; + dest = bgp_route_next(dest)) { + if (!bgp_dest_has_bgp_path_info_data(dest)) + continue; + bdistance = bgp_dest_get_bgp_distance_info(dest); + XFREE(MTYPE_AS_LIST, bdistance->access_list); + bgp_distance_free(bdistance); + + bgp_dest_set_bgp_distance_info(dest, NULL); + bgp_dest_unlock_node(dest); + } + } +} + /* Apply BGP information to distance method. */ uint8_t bgp_distance_apply(const struct prefix *p, struct bgp_path_info *pinfo, afi_t afi, safi_t safi, struct bgp *bgp) diff --git a/bgpd/bgp_route.h b/bgpd/bgp_route.h index bde0580d6c77..474e229575e6 100644 --- a/bgpd/bgp_route.h +++ b/bgpd/bgp_route.h @@ -831,6 +831,7 @@ extern void bgp_redistribute_withdraw(struct bgp *, afi_t, int, unsigned short); extern void bgp_static_add(struct bgp *); extern void bgp_static_delete(struct bgp *); +extern void bgp_address_family_distance_delete(void); extern void bgp_static_redo_import_check(struct bgp *); extern void bgp_purge_static_redist_routes(struct bgp *bgp); extern void bgp_static_update(struct bgp *bgp, const struct prefix *p, diff --git a/bgpd/bgpd.c b/bgpd/bgpd.c index a244e15fb8ec..ee8c61db338a 100644 --- a/bgpd/bgpd.c +++ b/bgpd/bgpd.c @@ -4237,6 +4237,14 @@ int bgp_delete(struct bgp *bgp) } } + /* Clean BGP address family parameters */ + bgp_mh_info->ead_evi_rx = BGP_EVPN_MH_EAD_EVI_RX_DEF; + bgp_evpn_switch_ead_evi_rx(); + bgp_mh_info->ead_evi_tx = BGP_EVPN_MH_EAD_EVI_TX_DEF; + bgp_mh_info->evi_per_es_frag = BGP_EVPN_MAX_EVI_PER_ES_FRAG; + + bgp_address_family_distance_delete(); + return 0; }