*: Add FOREACH_AFI_SAFI_NSF(afi, safi) macro to reduce nesting

Used for graceful-restart mostly.

Especially for bgp_show_neighbor_graceful_restart_capability_per_afi_safi()

Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
This commit is contained in:
Donatas Abraitis 2022-01-12 22:43:52 +02:00
parent 379effbf70
commit df8d723c5f
6 changed files with 201 additions and 225 deletions

View File

@ -69,6 +69,7 @@ ForEachMacros:
- SUBGRP_FOREACH_ADJ_SAFE - SUBGRP_FOREACH_ADJ_SAFE
- AF_FOREACH - AF_FOREACH
- FOREACH_AFI_SAFI - FOREACH_AFI_SAFI
- FOREACH_AFI_SAFI_NSF
- FOREACH_SAFI - FOREACH_SAFI
# ospfd # ospfd
- LSDB_LOOP - LSDB_LOOP

View File

@ -848,8 +848,7 @@ static int bgp_graceful_stale_timer_expire(struct thread *thread)
peer->host); peer->host);
/* NSF delete stale route */ /* NSF delete stale route */
for (afi = AFI_IP; afi < AFI_MAX; afi++) FOREACH_AFI_SAFI_NSF (afi, safi)
for (safi = SAFI_UNICAST; safi <= SAFI_MPLS_VPN; safi++)
if (peer->nsf[afi][safi]) if (peer->nsf[afi][safi])
bgp_clear_stale_route(peer, afi, safi); bgp_clear_stale_route(peer, afi, safi);
@ -1441,9 +1440,7 @@ int bgp_stop(struct peer *peer)
} else { } else {
UNSET_FLAG(peer->sflags, PEER_STATUS_NSF_MODE); UNSET_FLAG(peer->sflags, PEER_STATUS_NSF_MODE);
for (afi = AFI_IP; afi < AFI_MAX; afi++) FOREACH_AFI_SAFI_NSF (afi, safi)
for (safi = SAFI_UNICAST; safi <= SAFI_MPLS_VPN;
safi++)
peer->nsf[afi][safi] = 0; peer->nsf[afi][safi] = 0;
} }
@ -2125,15 +2122,14 @@ static int bgp_establish(struct peer *peer)
else if (BGP_PEER_HELPER_MODE(peer)) else if (BGP_PEER_HELPER_MODE(peer))
zlog_debug("peer %s BGP_HELPER_MODE", peer->host); zlog_debug("peer %s BGP_HELPER_MODE", peer->host);
} }
for (afi = AFI_IP; afi < AFI_MAX; afi++)
for (safi = SAFI_UNICAST; safi <= SAFI_MPLS_VPN; safi++) { FOREACH_AFI_SAFI_NSF (afi, safi) {
if (peer->afc_nego[afi][safi] if (peer->afc_nego[afi][safi] &&
&& CHECK_FLAG(peer->cap, PEER_CAP_RESTART_ADV) CHECK_FLAG(peer->cap, PEER_CAP_RESTART_ADV) &&
&& CHECK_FLAG(peer->af_cap[afi][safi], CHECK_FLAG(peer->af_cap[afi][safi],
PEER_CAP_RESTART_AF_RCV)) { PEER_CAP_RESTART_AF_RCV)) {
if (peer->nsf[afi][safi] if (peer->nsf[afi][safi] &&
&& !CHECK_FLAG( !CHECK_FLAG(peer->af_cap[afi][safi],
peer->af_cap[afi][safi],
PEER_CAP_RESTART_AF_PRESERVE_RCV)) PEER_CAP_RESTART_AF_PRESERVE_RCV))
bgp_clear_stale_route(peer, afi, safi); bgp_clear_stale_route(peer, afi, safi);
@ -2147,20 +2143,16 @@ static int bgp_establish(struct peer *peer)
/* Update the graceful restart information */ /* Update the graceful restart information */
if (peer->afc_nego[afi][safi]) { if (peer->afc_nego[afi][safi]) {
if (!BGP_SELECT_DEFER_DISABLE(peer->bgp)) { if (!BGP_SELECT_DEFER_DISABLE(peer->bgp)) {
status = bgp_update_gr_info(peer, afi, status = bgp_update_gr_info(peer, afi, safi);
safi);
if (status < 0) if (status < 0)
zlog_err( zlog_err(
"Error in updating graceful restart for %s", "Error in updating graceful restart for %s",
get_afi_safi_str( get_afi_safi_str(afi, safi,
afi, safi,
false)); false));
} else { } else {
if (BGP_PEER_GRACEFUL_RESTART_CAPABLE( if (BGP_PEER_GRACEFUL_RESTART_CAPABLE(peer) &&
peer) BGP_PEER_RESTARTING_MODE(peer) &&
&& BGP_PEER_RESTARTING_MODE(peer) CHECK_FLAG(peer->bgp->flags,
&& CHECK_FLAG(
peer->bgp->flags,
BGP_FLAG_GR_PRESERVE_FWD)) BGP_FLAG_GR_PRESERVE_FWD))
peer->bgp->gr_info[afi][safi] peer->bgp->gr_info[afi][safi]
.eor_required++; .eor_required++;

View File

@ -11322,13 +11322,12 @@ static void bgp_show_neighbor_graceful_restart_capability_per_afi_safi(
json_object *json_endofrib_status = NULL; json_object *json_endofrib_status = NULL;
bool eor_flag = false; bool eor_flag = false;
for (afi = AFI_IP; afi < AFI_MAX; afi++) { FOREACH_AFI_SAFI_NSF (afi, safi) {
for (safi = SAFI_UNICAST; safi <= SAFI_MPLS_VPN; safi++) {
if (!peer->afc[afi][safi]) if (!peer->afc[afi][safi])
continue; continue;
if (!CHECK_FLAG(peer->cap, PEER_CAP_RESTART_ADV) if (!CHECK_FLAG(peer->cap, PEER_CAP_RESTART_ADV) ||
|| !CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) !CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV))
continue; continue;
if (use_json) { if (use_json) {
@ -11337,8 +11336,7 @@ static void bgp_show_neighbor_graceful_restart_capability_per_afi_safi(
json_timer = json_object_new_object(); json_timer = json_object_new_object();
} }
if (peer->eor_stime[afi][safi] if (peer->eor_stime[afi][safi] >= peer->pkt_stime[afi][safi])
>= peer->pkt_stime[afi][safi])
eor_flag = true; eor_flag = true;
else else
eor_flag = false; eor_flag = false;
@ -11350,19 +11348,19 @@ static void bgp_show_neighbor_graceful_restart_capability_per_afi_safi(
vty_out(vty, " F bit: "); vty_out(vty, " F bit: ");
} }
if (peer->nsf[afi][safi] if (peer->nsf[afi][safi] &&
&& CHECK_FLAG(peer->af_cap[afi][safi], CHECK_FLAG(peer->af_cap[afi][safi],
PEER_CAP_RESTART_AF_PRESERVE_RCV)) { PEER_CAP_RESTART_AF_PRESERVE_RCV)) {
if (use_json) { if (use_json) {
json_object_boolean_true_add( json_object_boolean_true_add(json_afi_safi,
json_afi_safi, "fBit"); "fBit");
} else } else
vty_out(vty, "True\n"); vty_out(vty, "True\n");
} else { } else {
if (use_json) if (use_json)
json_object_boolean_false_add( json_object_boolean_false_add(json_afi_safi,
json_afi_safi, "fBit"); "fBit");
else else
vty_out(vty, "False\n"); vty_out(vty, "False\n");
} }
@ -11374,8 +11372,7 @@ static void bgp_show_neighbor_graceful_restart_capability_per_afi_safi(
PEER_STATUS_EOR_SEND)) { PEER_STATUS_EOR_SEND)) {
if (use_json) { if (use_json) {
json_object_boolean_true_add( json_object_boolean_true_add(
json_endofrib_status, json_endofrib_status, "endOfRibSend");
"endOfRibSend");
PRINT_EOR_JSON(eor_flag); PRINT_EOR_JSON(eor_flag);
} else { } else {
@ -11388,8 +11385,7 @@ static void bgp_show_neighbor_graceful_restart_capability_per_afi_safi(
} else { } else {
if (use_json) { if (use_json) {
json_object_boolean_false_add( json_object_boolean_false_add(
json_endofrib_status, json_endofrib_status, "endOfRibSend");
"endOfRibSend");
json_object_boolean_false_add( json_object_boolean_false_add(
json_endofrib_status, json_endofrib_status,
"endOfRibSentAfterUpdate"); "endOfRibSentAfterUpdate");
@ -11408,27 +11404,23 @@ static void bgp_show_neighbor_graceful_restart_capability_per_afi_safi(
PEER_STATUS_EOR_RECEIVED)) { PEER_STATUS_EOR_RECEIVED)) {
if (use_json) if (use_json)
json_object_boolean_true_add( json_object_boolean_true_add(
json_endofrib_status, json_endofrib_status, "endOfRibRecv");
"endOfRibRecv");
else else
vty_out(vty, "Yes\n"); vty_out(vty, "Yes\n");
} else { } else {
if (use_json) if (use_json)
json_object_boolean_false_add( json_object_boolean_false_add(
json_endofrib_status, json_endofrib_status, "endOfRibRecv");
"endOfRibRecv");
else else
vty_out(vty, "No\n"); vty_out(vty, "No\n");
} }
if (use_json) { if (use_json) {
json_object_int_add(json_timer, json_object_int_add(json_timer, "stalePathTimer",
"stalePathTimer",
peer->bgp->stalepath_time); peer->bgp->stalepath_time);
if (peer->t_gr_stale != NULL) { if (peer->t_gr_stale != NULL) {
json_object_int_add( json_object_int_add(json_timer,
json_timer,
"stalePathTimerRemaining", "stalePathTimerRemaining",
thread_timer_remain_second( thread_timer_remain_second(
peer->t_gr_stale)); peer->t_gr_stale));
@ -11440,23 +11432,19 @@ static void bgp_show_neighbor_graceful_restart_capability_per_afi_safi(
*/ */
if (CHECK_FLAG(peer->flags, if (CHECK_FLAG(peer->flags,
PEER_FLAG_GRACEFUL_RESTART)) { PEER_FLAG_GRACEFUL_RESTART)) {
json_object_int_add( json_object_int_add(json_timer,
json_timer,
"selectionDeferralTimer", "selectionDeferralTimer",
peer->bgp->stalepath_time); peer->bgp->stalepath_time);
} }
if (peer->bgp->gr_info[afi][safi] if (peer->bgp->gr_info[afi][safi].t_select_deferral !=
.t_select_deferral NULL) {
!= NULL) {
json_object_int_add( json_object_int_add(
json_timer, json_timer,
"selectionDeferralTimerRemaining", "selectionDeferralTimerRemaining",
thread_timer_remain_second( thread_timer_remain_second(
peer->bgp peer->bgp->gr_info[afi][safi]
->gr_info[afi]
[safi]
.t_select_deferral)); .t_select_deferral));
} }
} else { } else {
@ -11474,26 +11462,21 @@ static void bgp_show_neighbor_graceful_restart_capability_per_afi_safi(
* Deferral only when when * Deferral only when when
* Gr mode is enabled. * Gr mode is enabled.
*/ */
if (CHECK_FLAG(peer->flags, if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
PEER_FLAG_GRACEFUL_RESTART))
vty_out(vty, vty_out(vty,
" Configured Selection Deferral Time(sec): %u\n", " Configured Selection Deferral Time(sec): %u\n",
peer->bgp->select_defer_time); peer->bgp->select_defer_time);
if (peer->bgp->gr_info[afi][safi] if (peer->bgp->gr_info[afi][safi].t_select_deferral !=
.t_select_deferral NULL)
!= NULL)
vty_out(vty, vty_out(vty,
" Selection Deferral Time Remaining(sec): %ld\n", " Selection Deferral Time Remaining(sec): %ld\n",
thread_timer_remain_second( thread_timer_remain_second(
peer->bgp peer->bgp->gr_info[afi][safi]
->gr_info[afi]
[safi]
.t_select_deferral)); .t_select_deferral));
} }
if (use_json) { if (use_json) {
json_object_object_add(json_afi_safi, json_object_object_add(json_afi_safi, "endOfRibStatus",
"endOfRibStatus",
json_endofrib_status); json_endofrib_status);
json_object_object_add(json_afi_safi, "timers", json_object_object_add(json_afi_safi, "timers",
json_timer); json_timer);
@ -11502,7 +11485,6 @@ static void bgp_show_neighbor_graceful_restart_capability_per_afi_safi(
json_afi_safi); json_afi_safi);
} }
} }
}
} }
static void bgp_show_neighbor_graceful_restart_time(struct vty *vty, static void bgp_show_neighbor_graceful_restart_time(struct vty *vty,

View File

@ -2340,8 +2340,7 @@ void peer_nsf_stop(struct peer *peer)
UNSET_FLAG(peer->sflags, PEER_STATUS_NSF_WAIT); UNSET_FLAG(peer->sflags, PEER_STATUS_NSF_WAIT);
UNSET_FLAG(peer->sflags, PEER_STATUS_NSF_MODE); UNSET_FLAG(peer->sflags, PEER_STATUS_NSF_MODE);
for (afi = AFI_IP; afi < AFI_MAX; afi++) FOREACH_AFI_SAFI_NSF (afi, safi)
for (safi = SAFI_UNICAST; safi <= SAFI_MPLS_VPN; safi++)
peer->nsf[afi][safi] = 0; peer->nsf[afi][safi] = 0;
if (peer->t_gr_restart) { if (peer->t_gr_restart) {

View File

@ -346,6 +346,10 @@ typedef enum {
for (afi = AFI_IP; afi < AFI_MAX; afi++) \ for (afi = AFI_IP; afi < AFI_MAX; afi++) \
for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++) for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
#define FOREACH_AFI_SAFI_NSF(afi, safi) \
for (afi = AFI_IP; afi < AFI_MAX; afi++) \
for (safi = SAFI_UNICAST; safi <= SAFI_MPLS_VPN; safi++)
/* Default Administrative Distance of each protocol. */ /* Default Administrative Distance of each protocol. */
#define ZEBRA_KERNEL_DISTANCE_DEFAULT 0 #define ZEBRA_KERNEL_DISTANCE_DEFAULT 0
#define ZEBRA_CONNECT_DISTANCE_DEFAULT 0 #define ZEBRA_CONNECT_DISTANCE_DEFAULT 0

View File

@ -649,15 +649,13 @@ static void zebra_gr_process_client_stale_routes(struct zserv *client,
return; return;
/* Check if route update completed for all AFI, SAFI */ /* Check if route update completed for all AFI, SAFI */
for (afi = AFI_IP; afi < AFI_MAX; afi++) FOREACH_AFI_SAFI_NSF (afi, safi) {
for (safi = SAFI_UNICAST; safi <= SAFI_MPLS_VPN; safi++) {
if (info->af_enabled[afi][safi]) { if (info->af_enabled[afi][safi]) {
if (!info->route_sync[afi][safi]) { if (!info->route_sync[afi][safi]) {
LOG_GR( LOG_GR("%s: Client %s route update not completed for AFI %d, SAFI %d",
"%s: Client %s route update not completed for AFI %d, SAFI %d", __func__,
__func__, zebra_route_string( zebra_route_string(client->proto), afi,
client->proto), safi);
afi, safi);
return; return;
} }
} }