bgpd: Refactor subgroup_announce_table() to reuse an existing helpers

Reuse subgroup_process_announce_selected(). It does the same as we do here
duplicating the logic.

Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
This commit is contained in:
Donatas Abraitis 2023-05-25 15:46:21 +03:00
parent 575a0c5e3c
commit be393ade4a
3 changed files with 29 additions and 59 deletions

View File

@ -2894,20 +2894,16 @@ void bgp_best_selection(struct bgp *bgp, struct bgp_dest *dest,
*/ */
void subgroup_process_announce_selected(struct update_subgroup *subgrp, void subgroup_process_announce_selected(struct update_subgroup *subgrp,
struct bgp_path_info *selected, struct bgp_path_info *selected,
struct bgp_dest *dest, struct bgp_dest *dest, afi_t afi,
uint32_t addpath_tx_id) safi_t safi, uint32_t addpath_tx_id)
{ {
const struct prefix *p; const struct prefix *p;
struct peer *onlypeer; struct peer *onlypeer;
struct attr attr; struct attr attr;
afi_t afi;
safi_t safi;
struct bgp *bgp; struct bgp *bgp;
bool advertise; bool advertise;
p = bgp_dest_get_prefix(dest); p = bgp_dest_get_prefix(dest);
afi = SUBGRP_AFI(subgrp);
safi = SUBGRP_SAFI(subgrp);
bgp = SUBGRP_INST(subgrp); bgp = SUBGRP_INST(subgrp);
onlypeer = ((SUBGRP_PCOUNT(subgrp) == 1) ? (SUBGRP_PFIRST(subgrp))->peer onlypeer = ((SUBGRP_PCOUNT(subgrp) == 1) ? (SUBGRP_PFIRST(subgrp))->peer
: NULL); : NULL);

View File

@ -813,7 +813,8 @@ extern void bgp_notify_conditional_adv_scanner(struct update_subgroup *subgrp);
extern void subgroup_process_announce_selected(struct update_subgroup *subgrp, extern void subgroup_process_announce_selected(struct update_subgroup *subgrp,
struct bgp_path_info *selected, struct bgp_path_info *selected,
struct bgp_dest *dest, struct bgp_dest *dest, afi_t afi,
safi_t safi,
uint32_t addpath_tx_id); uint32_t addpath_tx_id);
extern bool subgroup_announce_check(struct bgp_dest *dest, extern bool subgroup_announce_check(struct bgp_dest *dest,

View File

@ -114,8 +114,9 @@ static void subgrp_withdraw_stale_addpath(struct updwalk_context *ctx,
} }
if (!pi) { if (!pi) {
subgroup_process_announce_selected( subgroup_process_announce_selected(subgrp, NULL,
subgrp, NULL, ctx->dest, adj->addpath_tx_id); ctx->dest, afi, safi,
adj->addpath_tx_id);
} }
} }
} }
@ -161,7 +162,8 @@ static int group_announce_route_walkcb(struct update_group *updgrp, void *arg)
continue; continue;
subgroup_process_announce_selected( subgroup_process_announce_selected(
subgrp, pi, ctx->dest, subgrp, pi, ctx->dest, afi,
safi,
bgp_addpath_id_for_peer( bgp_addpath_id_for_peer(
peer, afi, safi, peer, afi, safi,
&pi->tx_addpath)); &pi->tx_addpath));
@ -173,7 +175,8 @@ static int group_announce_route_walkcb(struct update_group *updgrp, void *arg)
*/ */
if (ctx->pi) if (ctx->pi)
subgroup_process_announce_selected( subgroup_process_announce_selected(
subgrp, ctx->pi, ctx->dest, subgrp, ctx->pi, ctx->dest, afi,
safi,
bgp_addpath_id_for_peer( bgp_addpath_id_for_peer(
peer, afi, safi, peer, afi, safi,
&ctx->pi->tx_addpath)); &ctx->pi->tx_addpath));
@ -182,7 +185,8 @@ static int group_announce_route_walkcb(struct update_group *updgrp, void *arg)
else { else {
if (ctx->pi) { if (ctx->pi) {
subgroup_process_announce_selected( subgroup_process_announce_selected(
subgrp, ctx->pi, ctx->dest, subgrp, ctx->pi, ctx->dest, afi,
safi,
bgp_addpath_id_for_peer( bgp_addpath_id_for_peer(
peer, afi, safi, peer, afi, safi,
&ctx->pi->tx_addpath)); &ctx->pi->tx_addpath));
@ -196,7 +200,8 @@ static int group_announce_route_walkcb(struct update_group *updgrp, void *arg)
if (adj->subgroup == subgrp) { if (adj->subgroup == subgrp) {
subgroup_process_announce_selected( subgroup_process_announce_selected(
subgrp, NULL, subgrp, NULL,
ctx->dest, ctx->dest, afi,
safi,
adj->addpath_tx_id); adj->addpath_tx_id);
} }
} }
@ -653,19 +658,15 @@ void subgroup_announce_table(struct update_subgroup *subgrp,
{ {
struct bgp_dest *dest; struct bgp_dest *dest;
struct bgp_path_info *ri; struct bgp_path_info *ri;
struct attr attr;
struct peer *peer; struct peer *peer;
afi_t afi; afi_t afi;
safi_t safi; safi_t safi;
safi_t safi_rib; safi_t safi_rib;
bool addpath_capable; bool addpath_capable;
struct bgp *bgp;
bool advertise;
peer = SUBGRP_PEER(subgrp); peer = SUBGRP_PEER(subgrp);
afi = SUBGRP_AFI(subgrp); afi = SUBGRP_AFI(subgrp);
safi = SUBGRP_SAFI(subgrp); safi = SUBGRP_SAFI(subgrp);
bgp = SUBGRP_INST(subgrp);
addpath_capable = bgp_addpath_encode_tx(peer, afi, safi); addpath_capable = bgp_addpath_encode_tx(peer, afi, safi);
if (safi == SAFI_LABELED_UNICAST) if (safi == SAFI_LABELED_UNICAST)
@ -685,37 +686,12 @@ void subgroup_announce_table(struct update_subgroup *subgrp,
SET_FLAG(subgrp->sflags, SUBGRP_STATUS_TABLE_REPARSING); SET_FLAG(subgrp->sflags, SUBGRP_STATUS_TABLE_REPARSING);
for (dest = bgp_table_top(table); dest; dest = bgp_route_next(dest)) { for (dest = bgp_table_top(table); dest; dest = bgp_route_next(dest)) {
const struct prefix *dest_p = bgp_dest_get_prefix(dest);
/* Check if the route can be advertised */
advertise = bgp_check_advertise(bgp, dest);
for (ri = bgp_dest_get_bgp_path_info(dest); ri; ri = ri->next) { for (ri = bgp_dest_get_bgp_path_info(dest); ri; ri = ri->next) {
if (!bgp_check_selected(ri, peer, addpath_capable, afi, if (!bgp_check_selected(ri, peer, addpath_capable, afi,
safi_rib)) safi_rib))
continue; continue;
if (subgroup_announce_check(dest, ri, subgrp, dest_p,
&attr, NULL)) {
/* Check if route can be advertised */
if (advertise) {
if (!bgp_check_withdrawal(bgp, dest)) {
struct attr *adv_attr =
bgp_attr_intern(&attr);
bgp_adj_out_set_subgroup(
dest, subgrp, adv_attr,
ri);
} else
bgp_adj_out_unset_subgroup(
dest, subgrp, 1,
bgp_addpath_id_for_peer(
peer, afi,
safi_rib,
&ri->tx_addpath));
}
} else {
/* If default originate is enabled for /* If default originate is enabled for
* the peer, do not send explicit * the peer, do not send explicit
* withdraw. This will prevent deletion * withdraw. This will prevent deletion
@ -724,18 +700,15 @@ void subgroup_announce_table(struct update_subgroup *subgrp,
*/ */
if (CHECK_FLAG(peer->af_flags[afi][safi], if (CHECK_FLAG(peer->af_flags[afi][safi],
PEER_FLAG_DEFAULT_ORIGINATE) && PEER_FLAG_DEFAULT_ORIGINATE) &&
is_default_prefix( is_default_prefix(bgp_dest_get_prefix(dest)))
bgp_dest_get_prefix(dest)))
break; break;
bgp_adj_out_unset_subgroup( subgroup_process_announce_selected(
dest, subgrp, 1, subgrp, ri, dest, afi, safi_rib,
bgp_addpath_id_for_peer( bgp_addpath_id_for_peer(peer, afi, safi_rib,
peer, afi, safi_rib,
&ri->tx_addpath)); &ri->tx_addpath));
} }
} }
}
UNSET_FLAG(subgrp->sflags, SUBGRP_STATUS_TABLE_REPARSING); UNSET_FLAG(subgrp->sflags, SUBGRP_STATUS_TABLE_REPARSING);
/* /*