]> git.puffer.fish Git - mirror/frr.git/commitdiff
bgpd, lib, staticd, tests: Convert to using FOREACH_AFI_SAFI
authorDonald Sharp <sharpd@nvidia.com>
Sat, 14 Nov 2020 23:50:37 +0000 (18:50 -0500)
committerDonald Sharp <sharpd@nvidia.com>
Sat, 14 Nov 2020 23:53:03 +0000 (18:53 -0500)
Move the FOREACH_AFI_SAFI macro from bgpd.h to zebra.h( GLOBAL's YOUALL )

Then convert all the places that have the two level for loop to
iterate over all afi/safis

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
bgpd/bgp_addpath.c
bgpd/bgp_packet.c
bgpd/bgpd.h
lib/zebra.h
staticd/static_routes.c
staticd/static_vrf.c
tests/bgpd/test_mpath.c

index d07d41bef8f4f71d2d073616674ca73efc5fe527..d822f6e3301a3a85682a7b63dd06f1c492a28fae 100644 (file)
@@ -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;
        }
 }
 
index a23acda0a85ce654ef1f13062d22e9e5a93652ad..3d73e34235978d8e1f7bc4e5d1a1b6b32358d07c 100644 (file)
@@ -279,18 +279,17 @@ static void bgp_update_explicit_eors(struct peer *peer)
        if (bgp_debug_neighbor_events(peer))
                zlog_debug("Peer %s: Checking explicit EORs", peer->host);
 
-       for (afi = AFI_IP; afi < AFI_MAX; afi++)
-               for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++) {
-                       if (peer->afc_nego[afi][safi]
-                           && !CHECK_FLAG(peer->af_sflags[afi][safi],
-                                          PEER_STATUS_EOR_RECEIVED)) {
-                               if (bgp_debug_neighbor_events(peer))
-                                       zlog_debug(
-                                               "   afi %d safi %d didn't receive EOR",
-                                               afi, safi);
-                               return;
-                       }
+       FOREACH_AFI_SAFI (afi, safi) {
+               if (peer->afc_nego[afi][safi]
+                   && !CHECK_FLAG(peer->af_sflags[afi][safi],
+                                  PEER_STATUS_EOR_RECEIVED)) {
+                       if (bgp_debug_neighbor_events(peer))
+                               zlog_debug(
+                                       "   afi %d safi %d didn't receive EOR",
+                                       afi, safi);
+                       return;
                }
+       }
 
        peer->update_delay_over = 1;
        peer->bgp->explicit_eors++;
index a2a3f374e2ce469e0b281a4768f2ee485fa14a91..d22fd008d8f561f1b8a24b5474965532024f169a 100644 (file)
@@ -104,10 +104,6 @@ enum bgp_af_index {
 
 #define AF_FOREACH(af) for ((af) = BGP_AF_START; (af) < BGP_AF_MAX; (af)++)
 
-#define FOREACH_AFI_SAFI(afi, safi)                                            \
-       for (afi = AFI_IP; afi < AFI_MAX; afi++)                               \
-               for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
-
 #define FOREACH_SAFI(safi)                                            \
        for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
 
index 14d66d6627e9b22ef62ccd193dec9a5d9e700bbd..ded44ac63669f91ecaaf64ff62fe3af0637ea8de 100644 (file)
@@ -359,6 +359,10 @@ typedef enum {
        SAFI_MAX = 8
 } safi_t;
 
+#define FOREACH_AFI_SAFI(afi, safi)                                            \
+       for (afi = AFI_IP; afi < AFI_MAX; afi++)                               \
+               for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
+
 /* Default Administrative Distance of each protocol. */
 #define ZEBRA_KERNEL_DISTANCE_DEFAULT      0
 #define ZEBRA_CONNECT_DISTANCE_DEFAULT     0
index 94299e0980c5012e5135a6f513b9ed27d04e29ad..05355c48fe800ba66617b5d9f05c1c31c758db70 100644 (file)
@@ -546,19 +546,15 @@ void static_fixup_vrf_ids(struct static_vrf *enable_svrf)
 
                svrf = vrf->info;
                /* Install any static routes configured for this VRF. */
-               for (afi = AFI_IP; afi < AFI_MAX; afi++) {
-                       for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++) {
-                               stable = svrf->stable[afi][safi];
-                               if (!stable)
-                                       continue;
+               FOREACH_AFI_SAFI (afi, safi) {
+                       stable = svrf->stable[afi][safi];
+                       if (!stable)
+                               continue;
 
-                               static_fixup_vrf(enable_svrf, stable,
-                                                afi, safi);
+                       static_fixup_vrf(enable_svrf, stable, afi, safi);
 
-                               if (enable_svrf == svrf)
-                                       static_enable_vrf(svrf, stable,
-                                                         afi, safi);
-                       }
+                       if (enable_svrf == svrf)
+                               static_enable_vrf(svrf, stable, afi, safi);
                }
        }
 }
@@ -649,20 +645,17 @@ void static_cleanup_vrf_ids(struct static_vrf *disable_svrf)
                svrf = vrf->info;
 
                /* Uninstall any static routes configured for this VRF. */
-               for (afi = AFI_IP; afi < AFI_MAX; afi++) {
-                       for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++) {
-                               struct route_table *stable;
+               FOREACH_AFI_SAFI (afi, safi) {
+                       struct route_table *stable;
 
-                               stable = svrf->stable[afi][safi];
-                               if (!stable)
-                                       continue;
+                       stable = svrf->stable[afi][safi];
+                       if (!stable)
+                               continue;
 
-                               static_cleanup_vrf(disable_svrf, stable,
-                                                  afi, safi);
+                       static_cleanup_vrf(disable_svrf, stable, afi, safi);
 
-                               if (disable_svrf == svrf)
-                                       static_disable_vrf(stable, afi, safi);
-                       }
+                       if (disable_svrf == svrf)
+                               static_disable_vrf(stable, afi, safi);
                }
        }
 }
@@ -725,14 +718,12 @@ void static_install_intf_nh(struct interface *ifp)
                        continue;
 
                /* Install any static routes configured for this interface. */
-               for (afi = AFI_IP; afi < AFI_MAX; afi++) {
-                       for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++) {
-                               stable = svrf->stable[afi][safi];
-                               if (!stable)
-                                       continue;
+               FOREACH_AFI_SAFI (afi, safi) {
+                       stable = svrf->stable[afi][safi];
+                       if (!stable)
+                               continue;
 
-                               static_fixup_intf_nh(stable, ifp, afi, safi);
-                       }
+                       static_fixup_intf_nh(stable, ifp, afi, safi);
                }
        }
 }
index 5ae34257158cca6d0628ea64432874751212b4cd..83894e92672f5a7ae1dc6a6c9b0f1a0c5e8e1c96 100644 (file)
@@ -238,14 +238,12 @@ int static_vrf_has_config(struct static_vrf *svrf)
         * NOTE: This is a don't care for the default VRF, but we go through
         * the motions to keep things consistent.
         */
-       for (afi = AFI_IP; afi < AFI_MAX; afi++) {
-               for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++) {
-                       table = svrf->stable[afi][safi];
-                       if (!table)
-                               continue;
-                       if (route_table_count(table))
-                               return 1;
-               }
+       FOREACH_AFI_SAFI (afi, safi) {
+               table = svrf->stable[afi][safi];
+               if (!table)
+                       continue;
+               if (route_table_count(table))
+                       return 1;
        }
 
        return 0;
index 99fb7b620d4433343764a71db6185dff9253c7b2..520c460f159096d71e1e43c268827300b9549c38 100644 (file)
@@ -106,15 +106,13 @@ static struct bgp *bgp_create_fake(as_t *as, const char *name)
        // bgp->group->cmp = (int (*)(void *, void *)) peer_group_cmp;
 
        bgp_evpn_init(bgp);
-       for (afi = AFI_IP; afi < AFI_MAX; afi++)
-               for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++) {
-                       bgp->route[afi][safi] = bgp_table_init(bgp, afi, safi);
-                       bgp->aggregate[afi][safi] = bgp_table_init(
-                               bgp, afi, safi);
-                       bgp->rib[afi][safi] = bgp_table_init(bgp, afi, safi);
-                       bgp->maxpaths[afi][safi].maxpaths_ebgp = MULTIPATH_NUM;
-                       bgp->maxpaths[afi][safi].maxpaths_ibgp = MULTIPATH_NUM;
-               }
+       FOREACH_AFI_SAFI (afi, safi) {
+               bgp->route[afi][safi] = bgp_table_init(bgp, afi, safi);
+               bgp->aggregate[afi][safi] = bgp_table_init(bgp, afi, safi);
+               bgp->rib[afi][safi] = bgp_table_init(bgp, afi, safi);
+               bgp->maxpaths[afi][safi].maxpaths_ebgp = MULTIPATH_NUM;
+               bgp->maxpaths[afi][safi].maxpaths_ibgp = MULTIPATH_NUM;
+       }
 
        bgp_scan_init(bgp);
        bgp->default_local_pref = BGP_DEFAULT_LOCAL_PREF;
@@ -152,36 +150,33 @@ static int run_bgp_cfg_maximum_paths(testcase_t *t)
        int test_result = TEST_PASSED;
 
        bgp = t->tmp_data;
-       for (afi = AFI_IP; afi < AFI_MAX; afi++)
-               for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++) {
-                       /* test bgp_maximum_paths_set */
-                       api_result = bgp_maximum_paths_set(
-                               bgp, afi, safi, BGP_PEER_EBGP, 10, 0);
-                       EXPECT_TRUE(api_result == 0, test_result);
-                       api_result = bgp_maximum_paths_set(
-                               bgp, afi, safi, BGP_PEER_IBGP, 10, 0);
-                       EXPECT_TRUE(api_result == 0, test_result);
-                       EXPECT_TRUE(bgp->maxpaths[afi][safi].maxpaths_ebgp
-                                           == 10,
-                                   test_result);
-                       EXPECT_TRUE(bgp->maxpaths[afi][safi].maxpaths_ibgp
-                                           == 10,
-                                   test_result);
-
-                       /* test bgp_maximum_paths_unset */
-                       api_result = bgp_maximum_paths_unset(bgp, afi, safi,
-                                                            BGP_PEER_EBGP);
-                       EXPECT_TRUE(api_result == 0, test_result);
-                       api_result = bgp_maximum_paths_unset(bgp, afi, safi,
-                                                            BGP_PEER_IBGP);
-                       EXPECT_TRUE(api_result == 0, test_result);
-                       EXPECT_TRUE((bgp->maxpaths[afi][safi].maxpaths_ebgp
-                                    == MULTIPATH_NUM),
-                                   test_result);
-                       EXPECT_TRUE((bgp->maxpaths[afi][safi].maxpaths_ibgp
-                                    == MULTIPATH_NUM),
-                                   test_result);
-               }
+       FOREACH_AFI_SAFI (afi, safi) {
+               /* test bgp_maximum_paths_set */
+               api_result = bgp_maximum_paths_set(bgp, afi, safi,
+                                                  BGP_PEER_EBGP, 10, 0);
+               EXPECT_TRUE(api_result == 0, test_result);
+               api_result = bgp_maximum_paths_set(bgp, afi, safi,
+                                                  BGP_PEER_IBGP, 10, 0);
+               EXPECT_TRUE(api_result == 0, test_result);
+               EXPECT_TRUE(bgp->maxpaths[afi][safi].maxpaths_ebgp == 10,
+                           test_result);
+               EXPECT_TRUE(bgp->maxpaths[afi][safi].maxpaths_ibgp == 10,
+                           test_result);
+
+               /* test bgp_maximum_paths_unset */
+               api_result =
+                       bgp_maximum_paths_unset(bgp, afi, safi, BGP_PEER_EBGP);
+               EXPECT_TRUE(api_result == 0, test_result);
+               api_result =
+                       bgp_maximum_paths_unset(bgp, afi, safi, BGP_PEER_IBGP);
+               EXPECT_TRUE(api_result == 0, test_result);
+               EXPECT_TRUE((bgp->maxpaths[afi][safi].maxpaths_ebgp
+                            == MULTIPATH_NUM),
+                           test_result);
+               EXPECT_TRUE((bgp->maxpaths[afi][safi].maxpaths_ibgp
+                            == MULTIPATH_NUM),
+                           test_result);
+       }
 
        return test_result;
 }