From 5cb526136a3d4498d277a907568a5c3ee9a27fb8 Mon Sep 17 00:00:00 2001 From: Donatas Abraitis Date: Thu, 27 Jan 2022 10:12:59 +0200 Subject: [PATCH] bgpd: Add bgp_check_selected() helper for abstraction Just check if the path is selected to be advertised: best path or addpath capable. Signed-off-by: Donatas Abraitis --- bgpd/bgp_conditional_adv.c | 8 ++------ bgpd/bgp_updgrp.c | 9 +++++++++ bgpd/bgp_updgrp.h | 2 ++ bgpd/bgp_updgrp_adv.c | 7 ++----- 4 files changed, 15 insertions(+), 11 deletions(-) diff --git a/bgpd/bgp_conditional_adv.c b/bgpd/bgp_conditional_adv.c index 6f72985876..c0dd3d6f81 100644 --- a/bgpd/bgp_conditional_adv.c +++ b/bgpd/bgp_conditional_adv.c @@ -124,12 +124,8 @@ static void bgp_conditional_adv_routes(struct peer *peer, afi_t afi, if (ret != RMAP_PERMITMATCH) continue; - if (CHECK_FLAG(pi->flags, BGP_PATH_SELECTED) - || (addpath_capable - && bgp_addpath_tx_path( - peer->addpath_type[afi][safi], - pi))) { - + if (bgp_check_selected(pi, peer, addpath_capable, afi, + safi)) { /* Skip route-map checks in * subgroup_announce_check while executing from * the conditional advertise scanner process. diff --git a/bgpd/bgp_updgrp.c b/bgpd/bgp_updgrp.c index 79433d6a5b..bfcb4810d1 100644 --- a/bgpd/bgp_updgrp.c +++ b/bgpd/bgp_updgrp.c @@ -49,6 +49,7 @@ #include "bgpd/bgp_debug.h" #include "bgpd/bgp_errors.h" #include "bgpd/bgp_fsm.h" +#include "bgpd/bgp_addpath.h" #include "bgpd/bgp_advertise.h" #include "bgpd/bgp_packet.h" #include "bgpd/bgp_updgrp.h" @@ -1931,3 +1932,11 @@ bool bgp_addpath_encode_tx(struct peer *peer, afi_t afi, safi_t safi) && CHECK_FLAG(peer->af_cap[afi][safi], PEER_CAP_ADDPATH_AF_RX_RCV)); } + +bool bgp_check_selected(struct bgp_path_info *bpi, struct peer *peer, + bool addpath_capable, afi_t afi, safi_t safi) +{ + return (CHECK_FLAG(bpi->flags, BGP_PATH_SELECTED) || + (addpath_capable && + bgp_addpath_tx_path(peer->addpath_type[afi][safi], bpi))); +} diff --git a/bgpd/bgp_updgrp.h b/bgpd/bgp_updgrp.h index f00853fc6f..5a9bebf8fe 100644 --- a/bgpd/bgp_updgrp.h +++ b/bgpd/bgp_updgrp.h @@ -462,6 +462,8 @@ extern int update_group_clear_update_dbg(struct update_group *updgrp, extern void update_bgp_group_free(struct bgp *bgp); extern bool bgp_addpath_encode_tx(struct peer *peer, afi_t afi, safi_t safi); +extern bool bgp_check_selected(struct bgp_path_info *bpi, struct peer *peer, + bool addpath_capable, afi_t afi, safi_t safi); /* * Inline functions diff --git a/bgpd/bgp_updgrp_adv.c b/bgpd/bgp_updgrp_adv.c index 806abbeba1..2110dcb8bc 100644 --- a/bgpd/bgp_updgrp_adv.c +++ b/bgpd/bgp_updgrp_adv.c @@ -687,11 +687,8 @@ void subgroup_announce_table(struct update_subgroup *subgrp, for (ri = bgp_dest_get_bgp_path_info(dest); ri; ri = ri->next) - if (CHECK_FLAG(ri->flags, BGP_PATH_SELECTED) - || (addpath_capable - && bgp_addpath_tx_path( - peer->addpath_type[afi][safi], - ri))) { + if (bgp_check_selected(ri, peer, addpath_capable, afi, + safi)) { if (subgroup_announce_check(dest, ri, subgrp, dest_p, &attr, false)) { -- 2.39.5