]> git.proxmox.com Git - mirror_frr.git/blobdiff - bgpd/bgp_addpath.c
Merge pull request #10904 from mobash-rasool/fixes
[mirror_frr.git] / bgpd / bgp_addpath.c
index e7e7c3cc1f30637a76acf31c5887ed74d6284d3f..d822f6e3301a3a85682a7b63dd06f1c492a28fae 100644 (file)
@@ -65,8 +65,8 @@ bgp_addpath_names(enum bgp_addpath_strat strat)
 /*
  * Returns if any peer is transmitting addpaths for a given afi/safi.
  */
-int bgp_addpath_is_addpath_used(struct bgp_addpath_bgp_data *d, afi_t afi,
-                             safi_t safi)
+bool bgp_addpath_is_addpath_used(struct bgp_addpath_bgp_data *d, afi_t afi,
+                                safi_t safi)
 {
        return d->total_peercount[afi][safi] > 0;
 }
@@ -80,14 +80,12 @@ void bgp_addpath_init_bgp_data(struct bgp_addpath_bgp_data *d)
        afi_t afi;
        int i;
 
-       for (afi = AFI_IP; afi < AFI_MAX; afi++) {
-               for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++) {
-                       for (i = 0; i < BGP_ADDPATH_MAX; i++) {
-                               d->id_allocators[afi][safi][i] = NULL;
-                               d->peercount[afi][safi][i] = 0;
-                       }
-                       d->total_peercount[afi][safi] = 0;
+       FOREACH_AFI_SAFI (afi, safi) {
+               for (i = 0; i < BGP_ADDPATH_MAX; i++) {
+                       d->id_allocators[afi][safi][i] = NULL;
+                       d->peercount[afi][safi][i] = 0;
                }
+               d->total_peercount[afi][safi] = 0;
        }
 }
 
@@ -123,15 +121,15 @@ uint32_t bgp_addpath_id_for_peer(struct peer *peer, afi_t afi, safi_t safi,
  * Returns true if the path has an assigned addpath ID for any of the addpath
  * strategies.
  */
-int bgp_addpath_info_has_ids(struct bgp_addpath_info_data *d)
+bool bgp_addpath_info_has_ids(struct bgp_addpath_info_data *d)
 {
        int i;
 
        for (i = 0; i < BGP_ADDPATH_MAX; i++)
                if (d->addpath_tx_id[i] != 0)
-                       return 1;
+                       return true;
 
-       return 0;
+       return false;
 }
 
 /*
@@ -152,7 +150,7 @@ void bgp_addpath_free_node_data(struct bgp_addpath_bgp_data *bd,
 /*
  * Check to see if the addpath strategy requires DMED to be configured to work.
  */
-int bgp_addpath_dmed_required(int strategy)
+bool bgp_addpath_dmed_required(int strategy)
 {
        return strategy == BGP_ADDPATH_BEST_PER_AS;
 }
@@ -161,34 +159,33 @@ int bgp_addpath_dmed_required(int strategy)
  * Return true if this is a path we should advertise due to a
  * configured addpath-tx knob
  */
-int bgp_addpath_tx_path(enum bgp_addpath_strat strat,
-                           struct bgp_path_info *pi)
+bool bgp_addpath_tx_path(enum bgp_addpath_strat strat, struct bgp_path_info *pi)
 {
        switch (strat) {
        case BGP_ADDPATH_NONE:
-               return 0;
+               return false;
        case BGP_ADDPATH_ALL:
-               return 1;
+               return true;
        case BGP_ADDPATH_BEST_PER_AS:
                if (CHECK_FLAG(pi->flags, BGP_PATH_DMED_SELECTED))
-                       return 1;
+                       return true;
                else
-                       return 0;
+                       return false;
        default:
-               return 0;
+               return false;
        }
 }
 
 static void bgp_addpath_flush_type_rn(struct bgp *bgp, afi_t afi, safi_t safi,
                                      enum bgp_addpath_strat addpath_type,
-                                     struct bgp_node *rn)
+                                     struct bgp_dest *dest)
 {
        struct bgp_path_info *pi;
 
        idalloc_drain_pool(
                bgp->tx_addpath.id_allocators[afi][safi][addpath_type],
-               &(rn->tx_addpath.free_ids[addpath_type]));
-       for (pi = bgp_node_get_bgp_path_info(rn); pi; pi = pi->next) {
+               &(dest->tx_addpath.free_ids[addpath_type]));
+       for (pi = bgp_dest_get_bgp_path_info(dest); pi; pi = pi->next) {
                if (pi->tx_addpath.addpath_tx_id[addpath_type]
                    != IDALLOC_INVALID) {
                        idalloc_free(
@@ -211,24 +208,24 @@ static void bgp_addpath_flush_type_rn(struct bgp *bgp, afi_t afi, safi_t safi,
 static void bgp_addpath_flush_type(struct bgp *bgp, afi_t afi, safi_t safi,
                                   enum bgp_addpath_strat addpath_type)
 {
-       struct bgp_node *rn, *nrn;
+       struct bgp_dest *dest, *ndest;
 
-       for (rn = bgp_table_top(bgp->rib[afi][safi]); rn;
-            rn = bgp_route_next(rn)) {
+       for (dest = bgp_table_top(bgp->rib[afi][safi]); dest;
+            dest = bgp_route_next(dest)) {
                if (safi == SAFI_MPLS_VPN) {
                        struct bgp_table *table;
 
-                       table = bgp_node_get_bgp_table_info(rn);
+                       table = bgp_dest_get_bgp_table_info(dest);
                        if (!table)
                                continue;
 
-                       for (nrn = bgp_table_top(table); nrn;
-                            nrn = bgp_route_next(nrn))
+                       for (ndest = bgp_table_top(table); ndest;
+                            ndest = bgp_route_next(ndest))
                                bgp_addpath_flush_type_rn(bgp, afi, safi,
-                                                         addpath_type, nrn);
+                                                         addpath_type, ndest);
                } else {
                        bgp_addpath_flush_type_rn(bgp, afi, safi, addpath_type,
-                                                 rn);
+                                                 dest);
                }
        }
 
@@ -258,7 +255,7 @@ static void bgp_addpath_populate_path(struct id_alloc *allocator,
 static void bgp_addpath_populate_type(struct bgp *bgp, afi_t afi, safi_t safi,
                                    enum bgp_addpath_strat addpath_type)
 {
-       struct bgp_node *rn, *nrn;
+       struct bgp_dest *dest, *ndest;
        char buf[200];
        struct id_alloc *allocator;
 
@@ -277,25 +274,25 @@ static void bgp_addpath_populate_type(struct bgp *bgp, afi_t afi, safi_t safi,
 
        allocator = bgp->tx_addpath.id_allocators[afi][safi][addpath_type];
 
-       for (rn = bgp_table_top(bgp->rib[afi][safi]); rn;
-            rn = bgp_route_next(rn)) {
+       for (dest = bgp_table_top(bgp->rib[afi][safi]); dest;
+            dest = bgp_route_next(dest)) {
                struct bgp_path_info *bi;
 
                if (safi == SAFI_MPLS_VPN) {
                        struct bgp_table *table;
 
-                       table = bgp_node_get_bgp_table_info(rn);
+                       table = bgp_dest_get_bgp_table_info(dest);
                        if (!table)
                                continue;
 
-                       for (nrn = bgp_table_top(table); nrn;
-                            nrn = bgp_route_next(nrn))
-                               for (bi = bgp_node_get_bgp_path_info(nrn); bi;
+                       for (ndest = bgp_table_top(table); ndest;
+                            ndest = bgp_route_next(ndest))
+                               for (bi = bgp_dest_get_bgp_path_info(ndest); bi;
                                     bi = bi->next)
                                        bgp_addpath_populate_path(allocator, bi,
                                                                  addpath_type);
                } else {
-                       for (bi = bgp_node_get_bgp_path_info(rn); bi;
+                       for (bi = bgp_dest_get_bgp_path_info(dest); bi;
                             bi = bi->next)
                                bgp_addpath_populate_path(allocator, bi,
                                                          addpath_type);
@@ -380,11 +377,13 @@ void bgp_addpath_set_peer_type(struct peer *peer, afi_t afi, safi_t safi,
 
        if (addpath_type != BGP_ADDPATH_NONE) {
                if (bgp_addpath_dmed_required(addpath_type)) {
-                       if (!bgp_flag_check(bgp, BGP_FLAG_DETERMINISTIC_MED)) {
+                       if (!CHECK_FLAG(bgp->flags,
+                                       BGP_FLAG_DETERMINISTIC_MED)) {
                                zlog_warn(
                                        "%s: enabling bgp deterministic-med, this is required for addpath-tx-bestpath-per-AS",
                                        peer->host);
-                               bgp_flag_set(bgp, BGP_FLAG_DETERMINISTIC_MED);
+                               SET_FLAG(bgp->flags,
+                                        BGP_FLAG_DETERMINISTIC_MED);
                                bgp_recalculate_all_bestpaths(bgp);
                        }
                }
@@ -425,8 +424,8 @@ void bgp_addpath_set_peer_type(struct peer *peer, afi_t afi, safi_t safi,
  * best-per-as updates from needing to do a separate withdraw and update just to
  * swap out which path is sent.
  */
-void bgp_addpath_update_ids(struct bgp *bgp, struct bgp_node *bn, afi_t afi,
-                         safi_t safi)
+void bgp_addpath_update_ids(struct bgp *bgp, struct bgp_dest *bn, afi_t afi,
+                           safi_t safi)
 {
        int i;
        struct bgp_path_info *pi;
@@ -441,7 +440,7 @@ void bgp_addpath_update_ids(struct bgp *bgp, struct bgp_node *bn, afi_t afi,
                        continue;
 
                /* Free Unused IDs back to the pool.*/
-               for (pi = bgp_node_get_bgp_path_info(bn); pi; pi = pi->next) {
+               for (pi = bgp_dest_get_bgp_path_info(bn); pi; pi = pi->next) {
                        if (pi->tx_addpath.addpath_tx_id[i] != IDALLOC_INVALID
                            && !bgp_addpath_tx_path(i, pi)) {
                                idalloc_free_to_pool(pool_ptr,
@@ -452,7 +451,7 @@ void bgp_addpath_update_ids(struct bgp *bgp, struct bgp_node *bn, afi_t afi,
                }
 
                /* Give IDs to paths that need them (pulling from the pool) */
-               for (pi = bgp_node_get_bgp_path_info(bn); pi; pi = pi->next) {
+               for (pi = bgp_dest_get_bgp_path_info(bn); pi; pi = pi->next) {
                        if (pi->tx_addpath.addpath_tx_id[i] == IDALLOC_INVALID
                            && bgp_addpath_tx_path(i, pi)) {
                                pi->tx_addpath.addpath_tx_id[i] =