Skip to content

Commit

Permalink
bgpd: Remove afi/safi from calling of bgp_zebra_XX
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
donaldsharp committed Jan 31, 2024
1 parent 6511552 commit 346c90d
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 29 deletions.
12 changes: 6 additions & 6 deletions bgpd/bgp_route.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -3516,17 +3516,17 @@ 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
&& (old_select->sub_type == BGP_ROUTE_NORMAL
|| 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);
}
}

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down
41 changes: 23 additions & 18 deletions bgpd/bgp_zebra.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -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);

Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 */
Expand All @@ -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
Expand All @@ -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) {
Expand Down Expand Up @@ -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);
}
}
}
Expand Down
8 changes: 3 additions & 5 deletions bgpd/bgp_zebra.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 346c90d

Please sign in to comment.