summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.clang-format1
-rw-r--r--bgpd/bgp_fsm.c86
-rw-r--r--bgpd/bgp_vty.c292
-rw-r--r--bgpd/bgpd.c5
-rw-r--r--lib/zebra.h4
-rw-r--r--zebra/zebra_gr.c20
6 files changed, 192 insertions, 216 deletions
diff --git a/.clang-format b/.clang-format
index c84a29f86..a620b5c2c 100644
--- a/.clang-format
+++ b/.clang-format
@@ -69,6 +69,7 @@ ForEachMacros:
- SUBGRP_FOREACH_ADJ_SAFE
- AF_FOREACH
- FOREACH_AFI_SAFI
+ - FOREACH_AFI_SAFI_NSF
- FOREACH_SAFI
# ospfd
- LSDB_LOOP
diff --git a/bgpd/bgp_fsm.c b/bgpd/bgp_fsm.c
index 1e9dd21fd..45e9aad1b 100644
--- a/bgpd/bgp_fsm.c
+++ b/bgpd/bgp_fsm.c
@@ -848,10 +848,9 @@ static int bgp_graceful_stale_timer_expire(struct thread *thread)
peer->host);
/* NSF delete stale route */
- for (afi = AFI_IP; afi < AFI_MAX; afi++)
- for (safi = SAFI_UNICAST; safi <= SAFI_MPLS_VPN; safi++)
- if (peer->nsf[afi][safi])
- bgp_clear_stale_route(peer, afi, safi);
+ FOREACH_AFI_SAFI_NSF (afi, safi)
+ if (peer->nsf[afi][safi])
+ bgp_clear_stale_route(peer, afi, safi);
return 0;
}
@@ -1441,10 +1440,8 @@ int bgp_stop(struct peer *peer)
} else {
UNSET_FLAG(peer->sflags, PEER_STATUS_NSF_MODE);
- for (afi = AFI_IP; afi < AFI_MAX; afi++)
- for (safi = SAFI_UNICAST; safi <= SAFI_MPLS_VPN;
- safi++)
- peer->nsf[afi][safi] = 0;
+ FOREACH_AFI_SAFI_NSF (afi, safi)
+ peer->nsf[afi][safi] = 0;
}
/* Stop route-refresh stalepath timer */
@@ -2125,48 +2122,43 @@ static int bgp_establish(struct peer *peer)
else if (BGP_PEER_HELPER_MODE(peer))
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++) {
- if (peer->afc_nego[afi][safi]
- && CHECK_FLAG(peer->cap, PEER_CAP_RESTART_ADV)
- && CHECK_FLAG(peer->af_cap[afi][safi],
- PEER_CAP_RESTART_AF_RCV)) {
- if (peer->nsf[afi][safi]
- && !CHECK_FLAG(
- peer->af_cap[afi][safi],
- PEER_CAP_RESTART_AF_PRESERVE_RCV))
- bgp_clear_stale_route(peer, afi, safi);
-
- peer->nsf[afi][safi] = 1;
- nsf_af_count++;
+
+ FOREACH_AFI_SAFI_NSF (afi, safi) {
+ if (peer->afc_nego[afi][safi] &&
+ CHECK_FLAG(peer->cap, PEER_CAP_RESTART_ADV) &&
+ CHECK_FLAG(peer->af_cap[afi][safi],
+ PEER_CAP_RESTART_AF_RCV)) {
+ if (peer->nsf[afi][safi] &&
+ !CHECK_FLAG(peer->af_cap[afi][safi],
+ PEER_CAP_RESTART_AF_PRESERVE_RCV))
+ bgp_clear_stale_route(peer, afi, safi);
+
+ peer->nsf[afi][safi] = 1;
+ nsf_af_count++;
+ } else {
+ if (peer->nsf[afi][safi])
+ bgp_clear_stale_route(peer, afi, safi);
+ peer->nsf[afi][safi] = 0;
+ }
+ /* Update the graceful restart information */
+ if (peer->afc_nego[afi][safi]) {
+ if (!BGP_SELECT_DEFER_DISABLE(peer->bgp)) {
+ status = bgp_update_gr_info(peer, afi, safi);
+ if (status < 0)
+ zlog_err(
+ "Error in updating graceful restart for %s",
+ get_afi_safi_str(afi, safi,
+ false));
} else {
- if (peer->nsf[afi][safi])
- bgp_clear_stale_route(peer, afi, safi);
- peer->nsf[afi][safi] = 0;
- }
- /* Update the graceful restart information */
- if (peer->afc_nego[afi][safi]) {
- if (!BGP_SELECT_DEFER_DISABLE(peer->bgp)) {
- status = bgp_update_gr_info(peer, afi,
- safi);
- if (status < 0)
- zlog_err(
- "Error in updating graceful restart for %s",
- get_afi_safi_str(
- afi, safi,
- false));
- } else {
- if (BGP_PEER_GRACEFUL_RESTART_CAPABLE(
- peer)
- && BGP_PEER_RESTARTING_MODE(peer)
- && CHECK_FLAG(
- peer->bgp->flags,
- BGP_FLAG_GR_PRESERVE_FWD))
- peer->bgp->gr_info[afi][safi]
- .eor_required++;
- }
+ if (BGP_PEER_GRACEFUL_RESTART_CAPABLE(peer) &&
+ BGP_PEER_RESTARTING_MODE(peer) &&
+ CHECK_FLAG(peer->bgp->flags,
+ BGP_FLAG_GR_PRESERVE_FWD))
+ peer->bgp->gr_info[afi][safi]
+ .eor_required++;
}
}
+ }
if (!CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
if ((bgp_peer_gr_mode_get(peer) == PEER_GR)
diff --git a/bgpd/bgp_vty.c b/bgpd/bgp_vty.c
index d6fdbfd0d..39a35ac55 100644
--- a/bgpd/bgp_vty.c
+++ b/bgpd/bgp_vty.c
@@ -11322,185 +11322,167 @@ static void bgp_show_neighbor_graceful_restart_capability_per_afi_safi(
json_object *json_endofrib_status = NULL;
bool eor_flag = false;
- for (afi = AFI_IP; afi < AFI_MAX; afi++) {
- for (safi = SAFI_UNICAST; safi <= SAFI_MPLS_VPN; safi++) {
- if (!peer->afc[afi][safi])
- continue;
+ FOREACH_AFI_SAFI_NSF (afi, safi) {
+ if (!peer->afc[afi][safi])
+ continue;
- if (!CHECK_FLAG(peer->cap, PEER_CAP_RESTART_ADV)
- || !CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV))
- continue;
+ if (!CHECK_FLAG(peer->cap, PEER_CAP_RESTART_ADV) ||
+ !CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV))
+ continue;
- if (use_json) {
- json_afi_safi = json_object_new_object();
- json_endofrib_status = json_object_new_object();
- json_timer = json_object_new_object();
- }
+ if (use_json) {
+ json_afi_safi = json_object_new_object();
+ json_endofrib_status = json_object_new_object();
+ json_timer = json_object_new_object();
+ }
- if (peer->eor_stime[afi][safi]
- >= peer->pkt_stime[afi][safi])
- eor_flag = true;
- else
- eor_flag = false;
+ if (peer->eor_stime[afi][safi] >= peer->pkt_stime[afi][safi])
+ eor_flag = true;
+ else
+ eor_flag = false;
- if (!use_json) {
- vty_out(vty, " %s:\n",
- get_afi_safi_str(afi, safi, false));
+ if (!use_json) {
+ vty_out(vty, " %s:\n",
+ get_afi_safi_str(afi, safi, false));
- vty_out(vty, " F bit: ");
- }
+ vty_out(vty, " F bit: ");
+ }
- if (peer->nsf[afi][safi]
- && CHECK_FLAG(peer->af_cap[afi][safi],
- PEER_CAP_RESTART_AF_PRESERVE_RCV)) {
+ if (peer->nsf[afi][safi] &&
+ CHECK_FLAG(peer->af_cap[afi][safi],
+ PEER_CAP_RESTART_AF_PRESERVE_RCV)) {
- if (use_json) {
- json_object_boolean_true_add(
- json_afi_safi, "fBit");
- } else
- vty_out(vty, "True\n");
- } else {
- if (use_json)
- json_object_boolean_false_add(
- json_afi_safi, "fBit");
- else
- vty_out(vty, "False\n");
- }
+ if (use_json) {
+ json_object_boolean_true_add(json_afi_safi,
+ "fBit");
+ } else
+ vty_out(vty, "True\n");
+ } else {
+ if (use_json)
+ json_object_boolean_false_add(json_afi_safi,
+ "fBit");
+ else
+ vty_out(vty, "False\n");
+ }
- if (!use_json)
- vty_out(vty, " End-of-RIB sent: ");
+ if (!use_json)
+ vty_out(vty, " End-of-RIB sent: ");
- if (CHECK_FLAG(peer->af_sflags[afi][safi],
- PEER_STATUS_EOR_SEND)) {
- if (use_json) {
- json_object_boolean_true_add(
- json_endofrib_status,
- "endOfRibSend");
+ if (CHECK_FLAG(peer->af_sflags[afi][safi],
+ PEER_STATUS_EOR_SEND)) {
+ if (use_json) {
+ json_object_boolean_true_add(
+ json_endofrib_status, "endOfRibSend");
- PRINT_EOR_JSON(eor_flag);
- } else {
- vty_out(vty, "Yes\n");
- vty_out(vty,
- " End-of-RIB sent after update: ");
+ PRINT_EOR_JSON(eor_flag);
+ } else {
+ vty_out(vty, "Yes\n");
+ vty_out(vty,
+ " End-of-RIB sent after update: ");
- PRINT_EOR(eor_flag);
- }
+ PRINT_EOR(eor_flag);
+ }
+ } else {
+ if (use_json) {
+ json_object_boolean_false_add(
+ json_endofrib_status, "endOfRibSend");
+ json_object_boolean_false_add(
+ json_endofrib_status,
+ "endOfRibSentAfterUpdate");
} else {
- if (use_json) {
- json_object_boolean_false_add(
- json_endofrib_status,
- "endOfRibSend");
- json_object_boolean_false_add(
- json_endofrib_status,
- "endOfRibSentAfterUpdate");
- } else {
- vty_out(vty, "No\n");
- vty_out(vty,
- " End-of-RIB sent after update: ");
- vty_out(vty, "No\n");
- }
+ vty_out(vty, "No\n");
+ vty_out(vty,
+ " End-of-RIB sent after update: ");
+ vty_out(vty, "No\n");
}
+ }
- if (!use_json)
- vty_out(vty, " End-of-RIB received: ");
+ if (!use_json)
+ vty_out(vty, " End-of-RIB received: ");
- if (CHECK_FLAG(peer->af_sflags[afi][safi],
- PEER_STATUS_EOR_RECEIVED)) {
- if (use_json)
- json_object_boolean_true_add(
- json_endofrib_status,
- "endOfRibRecv");
- else
- vty_out(vty, "Yes\n");
- } else {
- if (use_json)
- json_object_boolean_false_add(
- json_endofrib_status,
- "endOfRibRecv");
- else
- vty_out(vty, "No\n");
+ if (CHECK_FLAG(peer->af_sflags[afi][safi],
+ PEER_STATUS_EOR_RECEIVED)) {
+ if (use_json)
+ json_object_boolean_true_add(
+ json_endofrib_status, "endOfRibRecv");
+ else
+ vty_out(vty, "Yes\n");
+ } else {
+ if (use_json)
+ json_object_boolean_false_add(
+ json_endofrib_status, "endOfRibRecv");
+ else
+ vty_out(vty, "No\n");
+ }
+
+ if (use_json) {
+ json_object_int_add(json_timer, "stalePathTimer",
+ peer->bgp->stalepath_time);
+
+ if (peer->t_gr_stale != NULL) {
+ json_object_int_add(json_timer,
+ "stalePathTimerRemaining",
+ thread_timer_remain_second(
+ peer->t_gr_stale));
}
- if (use_json) {
+ /* Display Configured Selection
+ * Deferral only when when
+ * Gr mode is enabled.
+ */
+ if (CHECK_FLAG(peer->flags,
+ PEER_FLAG_GRACEFUL_RESTART)) {
json_object_int_add(json_timer,
- "stalePathTimer",
+ "selectionDeferralTimer",
peer->bgp->stalepath_time);
+ }
- if (peer->t_gr_stale != NULL) {
- json_object_int_add(
- json_timer,
- "stalePathTimerRemaining",
- thread_timer_remain_second(
- peer->t_gr_stale));
- }
-
- /* Display Configured Selection
- * Deferral only when when
- * Gr mode is enabled.
- */
- if (CHECK_FLAG(peer->flags,
- PEER_FLAG_GRACEFUL_RESTART)) {
- json_object_int_add(
- json_timer,
- "selectionDeferralTimer",
- peer->bgp->stalepath_time);
- }
+ if (peer->bgp->gr_info[afi][safi].t_select_deferral !=
+ NULL) {
- if (peer->bgp->gr_info[afi][safi]
- .t_select_deferral
- != NULL) {
+ json_object_int_add(
+ json_timer,
+ "selectionDeferralTimerRemaining",
+ thread_timer_remain_second(
+ peer->bgp->gr_info[afi][safi]
+ .t_select_deferral));
+ }
+ } else {
+ vty_out(vty, " Timers:\n");
+ vty_out(vty,
+ " Configured Stale Path Time(sec): %u\n",
+ peer->bgp->stalepath_time);
- json_object_int_add(
- json_timer,
- "selectionDeferralTimerRemaining",
- thread_timer_remain_second(
- peer->bgp
- ->gr_info[afi]
- [safi]
- .t_select_deferral));
- }
- } else {
- vty_out(vty, " Timers:\n");
+ if (peer->t_gr_stale != NULL)
vty_out(vty,
- " Configured Stale Path Time(sec): %u\n",
- peer->bgp->stalepath_time);
-
- if (peer->t_gr_stale != NULL)
- vty_out(vty,
- " Stale Path Remaining(sec): %ld\n",
- thread_timer_remain_second(
- peer->t_gr_stale));
- /* Display Configured Selection
- * Deferral only when when
- * Gr mode is enabled.
- */
- if (CHECK_FLAG(peer->flags,
- PEER_FLAG_GRACEFUL_RESTART))
- vty_out(vty,
- " Configured Selection Deferral Time(sec): %u\n",
- peer->bgp->select_defer_time);
+ " Stale Path Remaining(sec): %ld\n",
+ thread_timer_remain_second(
+ peer->t_gr_stale));
+ /* Display Configured Selection
+ * Deferral only when when
+ * Gr mode is enabled.
+ */
+ if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
+ vty_out(vty,
+ " Configured Selection Deferral Time(sec): %u\n",
+ peer->bgp->select_defer_time);
- if (peer->bgp->gr_info[afi][safi]
- .t_select_deferral
- != NULL)
- vty_out(vty,
- " Selection Deferral Time Remaining(sec): %ld\n",
- thread_timer_remain_second(
- peer->bgp
- ->gr_info[afi]
- [safi]
- .t_select_deferral));
- }
- if (use_json) {
- json_object_object_add(json_afi_safi,
- "endOfRibStatus",
- json_endofrib_status);
- json_object_object_add(json_afi_safi, "timers",
- json_timer);
- json_object_object_add(
- json, get_afi_safi_str(afi, safi, true),
- json_afi_safi);
- }
+ if (peer->bgp->gr_info[afi][safi].t_select_deferral !=
+ NULL)
+ vty_out(vty,
+ " Selection Deferral Time Remaining(sec): %ld\n",
+ thread_timer_remain_second(
+ peer->bgp->gr_info[afi][safi]
+ .t_select_deferral));
+ }
+ if (use_json) {
+ json_object_object_add(json_afi_safi, "endOfRibStatus",
+ json_endofrib_status);
+ json_object_object_add(json_afi_safi, "timers",
+ json_timer);
+ json_object_object_add(
+ json, get_afi_safi_str(afi, safi, true),
+ json_afi_safi);
}
}
}
diff --git a/bgpd/bgpd.c b/bgpd/bgpd.c
index 56e299e4c..8dc6a09cb 100644
--- a/bgpd/bgpd.c
+++ b/bgpd/bgpd.c
@@ -2340,9 +2340,8 @@ void peer_nsf_stop(struct peer *peer)
UNSET_FLAG(peer->sflags, PEER_STATUS_NSF_WAIT);
UNSET_FLAG(peer->sflags, PEER_STATUS_NSF_MODE);
- for (afi = AFI_IP; afi < AFI_MAX; afi++)
- for (safi = SAFI_UNICAST; safi <= SAFI_MPLS_VPN; safi++)
- peer->nsf[afi][safi] = 0;
+ FOREACH_AFI_SAFI_NSF (afi, safi)
+ peer->nsf[afi][safi] = 0;
if (peer->t_gr_restart) {
BGP_TIMER_OFF(peer->t_gr_restart);
diff --git a/lib/zebra.h b/lib/zebra.h
index c9794352c..139e47e8d 100644
--- a/lib/zebra.h
+++ b/lib/zebra.h
@@ -346,6 +346,10 @@ typedef enum {
for (afi = AFI_IP; afi < AFI_MAX; afi++) \
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. */
#define ZEBRA_KERNEL_DISTANCE_DEFAULT 0
#define ZEBRA_CONNECT_DISTANCE_DEFAULT 0
diff --git a/zebra/zebra_gr.c b/zebra/zebra_gr.c
index 5373f2788..b153ac1d8 100644
--- a/zebra/zebra_gr.c
+++ b/zebra/zebra_gr.c
@@ -649,19 +649,17 @@ static void zebra_gr_process_client_stale_routes(struct zserv *client,
return;
/* Check if route update completed for all AFI, SAFI */
- for (afi = AFI_IP; afi < AFI_MAX; afi++)
- for (safi = SAFI_UNICAST; safi <= SAFI_MPLS_VPN; safi++) {
- if (info->af_enabled[afi][safi]) {
- if (!info->route_sync[afi][safi]) {
- LOG_GR(
- "%s: Client %s route update not completed for AFI %d, SAFI %d",
- __func__, zebra_route_string(
- client->proto),
- afi, safi);
- return;
- }
+ FOREACH_AFI_SAFI_NSF (afi, safi) {
+ if (info->af_enabled[afi][safi]) {
+ if (!info->route_sync[afi][safi]) {
+ LOG_GR("%s: Client %s route update not completed for AFI %d, SAFI %d",
+ __func__,
+ zebra_route_string(client->proto), afi,
+ safi);
+ return;
}
}
+ }
/*
* Route update completed for all AFI, SAFI