Skip to content

Commit

Permalink
bgpd: backpressure - cleanup bgp_zebra_XX func args
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,
 - Retrieve the afi/safi to use based upon the dest's afi/safi
   instead of passing it in.
 - Prefix is known by the dest. Remove this arg as well

Ticket: #3390099

Signed-off-by: Donald Sharp <[email protected]>
Signed-off-by: Rajasekar Raja <[email protected]>
  • Loading branch information
donaldsharp authored and raja-rajasekar committed Mar 25, 2024
1 parent 705fed7 commit 5f379be
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 39 deletions.
17 changes: 7 additions & 10 deletions bgpd/bgp_route.c
Original file line number Diff line number Diff line change
Expand Up @@ -3399,8 +3399,8 @@ static void bgp_process_main_one(struct bgp *bgp, struct bgp_dest *dest,
|| new_select->sub_type
== BGP_ROUTE_IMPORTED))

bgp_zebra_announce(dest, p, old_select,
bgp, afi, safi);
bgp_zebra_announce(dest, old_select,
bgp);
}
}

Expand Down Expand Up @@ -3517,19 +3517,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, afi,
safi);
bgp_zebra_withdraw(dest, old_select, bgp);

bgp_zebra_announce(dest, p, new_select, bgp, afi, safi);
bgp_zebra_announce(dest, 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, afi,
safi);
bgp_zebra_withdraw(dest, old_select, bgp);
}
}

Expand Down Expand Up @@ -4426,7 +4424,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, afi, safi);
bgp_zebra_withdraw(dest, pi, bgp);
}

if (peer->sort == BGP_PEER_EBGP) {
Expand Down Expand Up @@ -6052,8 +6050,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, afi,
safi);
bgp_zebra_withdraw(dest, pi, bgp);
}

dest = bgp_path_info_reap(dest, pi);
Expand Down
45 changes: 22 additions & 23 deletions bgpd/bgp_zebra.c
Original file line number Diff line number Diff line change
Expand Up @@ -1524,9 +1524,8 @@ 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)
void bgp_zebra_announce(struct bgp_dest *dest, struct bgp_path_info *info,
struct bgp *bgp)
{
struct bgp_path_info *bpi_ultimate;
struct zapi_route api = { 0 };
Expand All @@ -1539,6 +1538,8 @@ 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 *table = bgp_dest_table(dest);
const struct prefix *p = bgp_dest_get_prefix(dest);

/*
* BGP is installing this route and bgp has been configured
Expand All @@ -1557,16 +1558,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 (table->safi == SAFI_FLOWSPEC) {
bgp_pbr_update_entry(bgp, p, info, table->afi, table->safi,
true);
return;
}

/* Make Zebra API structure. */
api.vrf_id = bgp->vrf_id;
api.type = ZEBRA_ROUTE_BGP;
api.safi = safi;
api.safi = table->safi;
api.prefix = *p;
SET_FLAG(api.message, ZAPI_MESSAGE_NEXTHOP);

Expand Down Expand Up @@ -1603,8 +1604,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);
table->afi, table->safi, &nhg_id,
&metric, &tag, &allow_recursion);

is_add = (valid_nh_count || nhg_id) ? true : false;

Expand Down Expand Up @@ -1657,7 +1658,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, table->afi, table->safi, bgp);
if (distance) {
SET_FLAG(api.message, ZAPI_MESSAGE_DISTANCE);
api.distance = distance;
Expand Down Expand Up @@ -1706,9 +1707,7 @@ void bgp_zebra_announce_table(struct bgp *bgp, afi_t afi, safi_t safi)
&& (pi->sub_type == BGP_ROUTE_NORMAL
|| pi->sub_type == BGP_ROUTE_IMPORTED)))

bgp_zebra_announce(dest,
bgp_dest_get_prefix(dest),
pi, bgp, afi, safi);
bgp_zebra_announce(dest, pi, bgp);
}

/* Announce routes of any bgp subtype of a table to zebra */
Expand All @@ -1730,16 +1729,16 @@ void bgp_zebra_announce_table_all_subtypes(struct bgp *bgp, afi_t afi,
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_announce(dest,
bgp_dest_get_prefix(dest),
pi, bgp, afi, safi);
bgp_zebra_announce(dest, pi, bgp);
}

void bgp_zebra_withdraw(const struct prefix *p, struct bgp_path_info *info,
struct bgp *bgp, afi_t afi, safi_t safi)
void bgp_zebra_withdraw(struct bgp_dest *dest, struct bgp_path_info *info,
struct bgp *bgp)
{
struct zapi_route api;
struct peer *peer;
struct bgp_table *table = bgp_dest_table(dest);
const struct prefix *p = bgp_dest_get_prefix(dest);

/*
* If we are withdrawing the route, we don't need to have this
Expand All @@ -1753,16 +1752,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 (table->safi == SAFI_FLOWSPEC) {
peer = info->peer;
bgp_pbr_update_entry(peer->bgp, p, info, afi, safi, false);
bgp_pbr_update_entry(peer->bgp, p, info, table->afi,
table->safi, false);
return;
}

memset(&api, 0, sizeof(api));
api.vrf_id = bgp->vrf_id;
api.type = ZEBRA_ROUTE_BGP;
api.safi = safi;
api.safi = table->safi;
api.prefix = *p;

if (info->attr->rmap_table_id) {
Expand Down Expand Up @@ -1795,8 +1795,7 @@ 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, afi, safi);
bgp_zebra_withdraw(dest, pi, bgp);
}
}
}
Expand Down
10 changes: 4 additions & 6 deletions bgpd/bgp_zebra.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,11 @@ extern void bgp_zebra_destroy(void);
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);
extern void bgp_zebra_announce(struct bgp_dest *dest,
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,
afi_t afi, safi_t safi);
extern void bgp_zebra_withdraw(struct bgp_dest *dest,
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 5f379be

Please sign in to comment.