From 346c90d8c86681192fc65a3d4913861e480ed45e Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Thu, 25 Jan 2024 13:07:37 -0500 Subject: [PATCH] bgpd: Remove afi/safi from calling of bgp_zebra_XX Since installing/withdrawing routes into zebra is going to be changed around to be dest based in a list, let's retrieve the afi/safi to use based upon the dest's afi/safi instead of passing it in. Signed-off-by: Donald Sharp --- bgpd/bgp_route.c | 12 ++++++------ bgpd/bgp_zebra.c | 41 +++++++++++++++++++++++------------------ bgpd/bgp_zebra.h | 8 +++----- 3 files changed, 32 insertions(+), 29 deletions(-) diff --git a/bgpd/bgp_route.c b/bgpd/bgp_route.c index 518e848258ff..0488fee199ce 100644 --- a/bgpd/bgp_route.c +++ b/bgpd/bgp_route.c @@ -3399,7 +3399,7 @@ static void bgp_process_main_one(struct bgp *bgp, struct bgp_dest *dest, == BGP_ROUTE_IMPORTED)) bgp_zebra_announce(dest, p, old_select, - bgp, afi, safi); + bgp); } } @@ -3516,9 +3516,9 @@ static void bgp_process_main_one(struct bgp *bgp, struct bgp_dest *dest, */ if (old_select && is_route_parent_evpn(old_select)) - bgp_zebra_withdraw(p, old_select, bgp, safi); + bgp_zebra_withdraw(dest, p, old_select, bgp); - bgp_zebra_announce(dest, p, new_select, bgp, afi, safi); + bgp_zebra_announce(dest, p, new_select, bgp); } else { /* Withdraw the route from the kernel. */ if (old_select && old_select->type == ZEBRA_ROUTE_BGP @@ -3526,7 +3526,7 @@ static void bgp_process_main_one(struct bgp *bgp, struct bgp_dest *dest, || old_select->sub_type == BGP_ROUTE_AGGREGATE || old_select->sub_type == BGP_ROUTE_IMPORTED)) - bgp_zebra_withdraw(p, old_select, bgp, safi); + bgp_zebra_withdraw(dest, p, old_select, bgp); } } @@ -4427,7 +4427,7 @@ void bgp_update(struct peer *peer, const struct prefix *p, uint32_t addpath_id, if (pi && pi->attr->rmap_table_id != new_attr.rmap_table_id) { if (CHECK_FLAG(pi->flags, BGP_PATH_SELECTED)) /* remove from RIB previous entry */ - bgp_zebra_withdraw(p, pi, bgp, safi); + bgp_zebra_withdraw(dest, p, pi, bgp); } if (peer->sort == BGP_PEER_EBGP) { @@ -6053,7 +6053,7 @@ static void bgp_cleanup_table(struct bgp *bgp, struct bgp_table *table, || pi->sub_type == BGP_ROUTE_IMPORTED)) { if (bgp_fibupd_safi(safi)) - bgp_zebra_withdraw(p, pi, bgp, safi); + bgp_zebra_withdraw(dest, p, pi, bgp); } dest = bgp_path_info_reap(dest, pi); diff --git a/bgpd/bgp_zebra.c b/bgpd/bgp_zebra.c index 0db0ac487380..6c4724b19915 100644 --- a/bgpd/bgp_zebra.c +++ b/bgpd/bgp_zebra.c @@ -1508,8 +1508,7 @@ static void bgp_debug_zebra_nh(struct zapi_route *api) } void bgp_zebra_announce(struct bgp_dest *dest, const struct prefix *p, - struct bgp_path_info *info, struct bgp *bgp, afi_t afi, - safi_t safi) + struct bgp_path_info *info, struct bgp *bgp) { struct zapi_route api = { 0 }; unsigned int valid_nh_count = 0; @@ -1521,6 +1520,9 @@ void bgp_zebra_announce(struct bgp_dest *dest, const struct prefix *p, bool is_add; uint32_t nhg_id = 0; uint32_t recursion_flag = 0; + struct bgp_table *bti; + + bti = bgp_dest_table(dest); /* * BGP is installing this route and bgp has been configured @@ -1539,16 +1541,16 @@ void bgp_zebra_announce(struct bgp_dest *dest, const struct prefix *p, if (bgp->main_zebra_update_hold) return; - if (safi == SAFI_FLOWSPEC) { - bgp_pbr_update_entry(bgp, bgp_dest_get_prefix(dest), info, afi, - safi, true); + if (bti->safi == SAFI_FLOWSPEC) { + bgp_pbr_update_entry(bgp, bgp_dest_get_prefix(dest), info, + bti->afi, bti->safi, true); return; } /* Make Zebra API structure. */ api.vrf_id = bgp->vrf_id; api.type = ZEBRA_ROUTE_BGP; - api.safi = safi; + api.safi = bti->safi; api.prefix = *p; SET_FLAG(api.message, ZAPI_MESSAGE_NEXTHOP); @@ -1591,8 +1593,8 @@ void bgp_zebra_announce(struct bgp_dest *dest, const struct prefix *p, metric = info->attr->med; bgp_zebra_announce_parse_nexthop(info, p, bgp, &api, &valid_nh_count, - afi, safi, &nhg_id, &metric, &tag, - &allow_recursion); + bti->afi, bti->safi, &nhg_id, &metric, + &tag, &allow_recursion); is_add = (valid_nh_count || nhg_id) ? true : false; @@ -1645,7 +1647,7 @@ void bgp_zebra_announce(struct bgp_dest *dest, const struct prefix *p, api.tag = tag; } - distance = bgp_distance_apply(p, info, afi, safi, bgp); + distance = bgp_distance_apply(p, info, bti->afi, bti->safi, bgp); if (distance) { SET_FLAG(api.message, ZAPI_MESSAGE_DISTANCE); api.distance = distance; @@ -1696,7 +1698,7 @@ void bgp_zebra_announce_table(struct bgp *bgp, afi_t afi, safi_t safi) bgp_zebra_announce(dest, bgp_dest_get_prefix(dest), - pi, bgp, afi, safi); + pi, bgp); } /* Announce routes of any bgp subtype of a table to zebra */ @@ -1720,14 +1722,15 @@ void bgp_zebra_announce_table_all_subtypes(struct bgp *bgp, afi_t afi, pi->type == ZEBRA_ROUTE_BGP) bgp_zebra_announce(dest, bgp_dest_get_prefix(dest), - pi, bgp, afi, safi); + pi, bgp); } -void bgp_zebra_withdraw(const struct prefix *p, struct bgp_path_info *info, - struct bgp *bgp, safi_t safi) +void bgp_zebra_withdraw(struct bgp_dest *dest, const struct prefix *p, + struct bgp_path_info *info, struct bgp *bgp) { struct zapi_route api; struct peer *peer; + struct bgp_table *bti = bgp_dest_table(dest); /* * If we are withdrawing the route, we don't need to have this @@ -1741,16 +1744,17 @@ void bgp_zebra_withdraw(const struct prefix *p, struct bgp_path_info *info, if (!bgp_install_info_to_zebra(bgp)) return; - if (safi == SAFI_FLOWSPEC) { + if (bti->safi == SAFI_FLOWSPEC) { peer = info->peer; - bgp_pbr_update_entry(peer->bgp, p, info, AFI_IP, safi, false); + bgp_pbr_update_entry(peer->bgp, p, info, bti->afi, bti->safi, + false); return; } memset(&api, 0, sizeof(api)); api.vrf_id = bgp->vrf_id; api.type = ZEBRA_ROUTE_BGP; - api.safi = safi; + api.safi = bti->safi; api.prefix = *p; if (info->attr->rmap_table_id) { @@ -1783,8 +1787,9 @@ void bgp_zebra_withdraw_table_all_subtypes(struct bgp *bgp, afi_t afi, safi_t sa for (pi = bgp_dest_get_bgp_path_info(dest); pi; pi = pi->next) { if (CHECK_FLAG(pi->flags, BGP_PATH_SELECTED) && (pi->type == ZEBRA_ROUTE_BGP)) - bgp_zebra_withdraw(bgp_dest_get_prefix(dest), - pi, bgp, safi); + bgp_zebra_withdraw(dest, + bgp_dest_get_prefix(dest), + pi, bgp); } } } diff --git a/bgpd/bgp_zebra.h b/bgpd/bgp_zebra.h index 4696e4dc44cb..5e0e7aba461a 100644 --- a/bgpd/bgp_zebra.h +++ b/bgpd/bgp_zebra.h @@ -29,12 +29,10 @@ extern int bgp_zebra_get_table_range(struct zclient *zc, uint32_t chunk_size, uint32_t *start, uint32_t *end); extern int bgp_if_update_all(void); extern void bgp_zebra_announce(struct bgp_dest *dest, const struct prefix *p, - struct bgp_path_info *path, struct bgp *bgp, - afi_t afi, safi_t safi); + struct bgp_path_info *path, struct bgp *bgp); extern void bgp_zebra_announce_table(struct bgp *bgp, afi_t afi, safi_t safi); -extern void bgp_zebra_withdraw(const struct prefix *p, - struct bgp_path_info *path, struct bgp *bgp, - safi_t safi); +extern void bgp_zebra_withdraw(struct bgp_dest *dest, const struct prefix *p, + struct bgp_path_info *path, struct bgp *bgp); /* Announce routes of any bgp subtype of a table to zebra */ extern void bgp_zebra_announce_table_all_subtypes(struct bgp *bgp, afi_t afi,