summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDonald Sharp <sharpd@nvidia.com>2020-11-14 18:50:37 -0500
committerDonald Sharp <sharpd@nvidia.com>2020-11-14 18:53:03 -0500
commitf18ba3cd18210fceac80fc1bf21fcb116d4d4397 (patch)
tree7ec928e01f625f4114d3c522e6168b9518e8302f
parent3d1c148b07c7c81e98fd3059100bd84ba92c4546 (diff)
bgpd, lib, staticd, tests: Convert to using FOREACH_AFI_SAFI
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>
-rw-r--r--bgpd/bgp_addpath.c12
-rw-r--r--bgpd/bgp_packet.c21
-rw-r--r--bgpd/bgpd.h4
-rw-r--r--lib/zebra.h4
-rw-r--r--staticd/static_routes.c49
-rw-r--r--staticd/static_vrf.c14
-rw-r--r--tests/bgpd/test_mpath.c73
7 files changed, 79 insertions, 98 deletions
diff --git a/bgpd/bgp_addpath.c b/bgpd/bgp_addpath.c
index d07d41bef8..d822f6e330 100644
--- a/bgpd/bgp_addpath.c
+++ b/bgpd/bgp_addpath.c
@@ -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;
}
}
diff --git a/bgpd/bgp_packet.c b/bgpd/bgp_packet.c
index a23acda0a8..3d73e34235 100644
--- a/bgpd/bgp_packet.c
+++ b/bgpd/bgp_packet.c
@@ -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++;
diff --git a/bgpd/bgpd.h b/bgpd/bgpd.h
index a2a3f374e2..d22fd008d8 100644
--- a/bgpd/bgpd.h
+++ b/bgpd/bgpd.h
@@ -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++)
diff --git a/lib/zebra.h b/lib/zebra.h
index 14d66d6627..ded44ac636 100644
--- a/lib/zebra.h
+++ b/lib/zebra.h
@@ -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
diff --git a/staticd/static_routes.c b/staticd/static_routes.c
index 94299e0980..05355c48fe 100644
--- a/staticd/static_routes.c
+++ b/staticd/static_routes.c
@@ -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);
}
}
}
diff --git a/staticd/static_vrf.c b/staticd/static_vrf.c
index 5ae3425715..83894e9267 100644
--- a/staticd/static_vrf.c
+++ b/staticd/static_vrf.c
@@ -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;
diff --git a/tests/bgpd/test_mpath.c b/tests/bgpd/test_mpath.c
index 99fb7b620d..520c460f15 100644
--- a/tests/bgpd/test_mpath.c
+++ b/tests/bgpd/test_mpath.c
@@ -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;
}