summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDonald Sharp <sharpd@nvidia.com>2023-03-24 15:58:41 -0400
committerDonald Sharp <sharpd@nvidia.com>2023-03-29 15:40:56 -0400
commit9c1c21da8a76c39e5af973d0752b75098529b1cd (patch)
tree7b9e5863288f2be4f45e1f1ed2a97b020ee7f5eb
parent0f5ef7f9b197f0a9fec86ec15885e06e843fd539 (diff)
zebra: Rearrange zebra_gr zapi functions
The zebra_gr code had 3 functions when effectively only 1 was needed. Cleans up some code weirdness around multiple switch statements for the same api->cap as well as consolidating down to only caring about SAFI_UNICAST, since that is all we care about at the moment. Signed-off-by: Donald Sharp <sharpd@nvidia.com>
-rw-r--r--zebra/zebra_gr.c153
1 files changed, 57 insertions, 96 deletions
diff --git a/zebra/zebra_gr.c b/zebra/zebra_gr.c
index 2823b6e743..a209eb8c3c 100644
--- a/zebra/zebra_gr.c
+++ b/zebra/zebra_gr.c
@@ -42,7 +42,7 @@ static struct zserv *zebra_gr_find_stale_client(struct zserv *client);
static void zebra_gr_route_stale_delete_timer_expiry(struct event *thread);
static int32_t zebra_gr_delete_stale_routes(struct client_gr_info *info);
static void zebra_gr_process_client_stale_routes(struct zserv *client,
- vrf_id_t vrf_id);
+ struct client_gr_info *info);
/*
* Debug macros.
@@ -290,17 +290,43 @@ void zebra_gr_client_reconnect(struct zserv *client)
*/
/*
- * Update the graceful restart information
- * for the client instance.
- * This function handles all the capabilities that are received.
+ * Function to decode and call appropriate functions
+ * to handle client capabilities.
*/
-static void zebra_client_update_info(struct zserv *client, struct zapi_cap *api)
+void zread_client_capabilities(ZAPI_HANDLER_ARGS)
{
+ struct zapi_cap api;
struct client_gr_info *info = NULL;
+ struct stream *s;
+ struct vrf *vrf;
+
+ s = msg;
+
+ if (zapi_capabilities_decode(s, &api)) {
+ LOG_GR("%s: Error in reading capabilities for client %s",
+ __func__, zebra_route_string(client->proto));
+ return;
+ }
+
+ vrf = vrf_lookup_by_id(api.vrf_id);
+
+ /*
+ * If this ever matters uncomment and add safi to the
+ * arrays as needed to track
+ */
+ if (api.safi != SAFI_UNICAST)
+ return;
+
+ /* GR only for dynamic clients */
+ if (client->proto <= ZEBRA_ROUTE_CONNECT) {
+ LOG_GR("%s: GR capabilities for client %s not supported",
+ __func__, zebra_route_string(client->proto));
+ return;
+ }
/* Find the bgp information for the specified vrf id */
TAILQ_FOREACH (info, &client->gr_info_queue, gr_info) {
- if (info->vrf_id == api->vrf_id)
+ if (info->vrf_id == api.vrf_id)
break;
}
@@ -308,7 +334,7 @@ static void zebra_client_update_info(struct zserv *client, struct zapi_cap *api)
* If the command is delete, then cancel the stale timer and
* delete the bgp info
*/
- switch (api->cap) {
+ switch (api.cap) {
case ZEBRA_CLIENT_GR_DISABLE:
if (!info)
return;
@@ -329,18 +355,16 @@ static void zebra_client_update_info(struct zserv *client, struct zapi_cap *api)
/* Update other parameters */
if (!info->gr_enable) {
- struct vrf *vrf = vrf_lookup_by_id(api->vrf_id);
-
client->gr_instance_count++;
LOG_GR("%s: Cient %s vrf %s(%u) GR enabled count %d",
__func__, zebra_route_string(client->proto),
- VRF_LOGNAME(vrf), api->vrf_id,
+ VRF_LOGNAME(vrf), api.vrf_id,
client->gr_instance_count);
- info->capabilities = api->cap;
- info->stale_removal_time = api->stale_removal_time;
- info->vrf_id = api->vrf_id;
+ info->capabilities = api.cap;
+ info->stale_removal_time = api.stale_removal_time;
+ info->vrf_id = api.vrf_id;
info->gr_enable = true;
}
break;
@@ -350,14 +374,13 @@ static void zebra_client_update_info(struct zserv *client, struct zapi_cap *api)
/* Update the stale removal timer */
if (info && info->t_stale_removal == NULL) {
- struct vrf *vrf = vrf_lookup_by_id(info->vrf_id);
LOG_GR("%s: vrf %s(%u) Stale time: %d is now update to: %d",
__func__, VRF_LOGNAME(vrf), info->vrf_id,
info->stale_removal_time,
- api->stale_removal_time);
+ api.stale_removal_time);
- info->stale_removal_time = api->stale_removal_time;
+ info->stale_removal_time = api.stale_removal_time;
}
break;
@@ -365,87 +388,34 @@ static void zebra_client_update_info(struct zserv *client, struct zapi_cap *api)
if (!info) {
LOG_GR("%s: Client %s route update complete for AFI %d, SAFI %d",
__func__, zebra_route_string(client->proto),
- api->afi, api->safi);
+ api.afi, api.safi);
} else {
- struct vrf *vrf = vrf_lookup_by_id(info->vrf_id);
-
LOG_GR("%s: Client %s vrf %s(%u) route update complete for AFI %d, SAFI %d",
__func__, zebra_route_string(client->proto),
- VRF_LOGNAME(vrf), info->vrf_id, api->afi,
- api->safi);
- info->route_sync[api->afi] = true;
+ VRF_LOGNAME(vrf), info->vrf_id, api.afi,
+ api.safi);
+ info->route_sync[api.afi] = true;
}
+ zebra_gr_process_client_stale_routes(client, info);
break;
case ZEBRA_CLIENT_ROUTE_UPDATE_PENDING:
if (!info) {
LOG_GR("%s: Client %s route update pending for AFI %d, SAFI %d",
__func__, zebra_route_string(client->proto),
- api->afi, api->safi);
+ api.afi, api.safi);
} else {
- struct vrf *vrf = vrf_lookup_by_id(info->vrf_id);
-
LOG_GR("%s: Client %s vrf %s(%u) route update pending for AFI %d, SAFI %d",
__func__, zebra_route_string(client->proto),
- VRF_LOGNAME(vrf), info->vrf_id, api->afi,
- api->safi);
+ VRF_LOGNAME(vrf), info->vrf_id, api.afi,
+ api.safi);
- info->af_enabled[api->afi] = true;
+ info->af_enabled[api.afi] = true;
}
break;
}
}
/*
- * Function to decode and call appropriate functions
- * to handle client capabilities.
- */
-void zread_client_capabilities(ZAPI_HANDLER_ARGS)
-{
- struct zapi_cap api;
- struct stream *s;
-
- s = msg;
-
- if (zapi_capabilities_decode(s, &api)) {
- LOG_GR("%s: Error in reading capabilities for client %s",
- __func__, zebra_route_string(client->proto));
- return;
- }
-
- if (api.safi != SAFI_UNICAST)
- return;
-
- /* GR only for dynamic clients */
- if (client->proto <= ZEBRA_ROUTE_CONNECT) {
- LOG_GR("%s: GR capabilities for client %s not supported",
- __func__, zebra_route_string(client->proto));
- return;
- }
-
- /* Call the capabilities handler */
- switch (api.cap) {
- case ZEBRA_CLIENT_GR_CAPABILITIES:
- case ZEBRA_CLIENT_ROUTE_UPDATE_PENDING:
- case ZEBRA_CLIENT_GR_DISABLE:
- case ZEBRA_CLIENT_RIB_STALE_TIME:
- /*
- * For all the cases we need to update the client info.
- */
- zebra_client_update_info(client, &api);
- break;
- case ZEBRA_CLIENT_ROUTE_UPDATE_COMPLETE:
- /*
- * After client info has been updated delete all
- * stale routes
- */
- zebra_client_update_info(client, &api);
- zebra_gr_process_client_stale_routes(client, api.vrf_id);
- break;
- }
-}
-
-
-/*
* Stale route handling
*/
@@ -613,31 +583,22 @@ static int32_t zebra_gr_delete_stale_routes(struct client_gr_info *info)
* and cancels the stale timer
*/
static void zebra_gr_process_client_stale_routes(struct zserv *client,
- vrf_id_t vrf_id)
+ struct client_gr_info *info)
{
- struct client_gr_info *info = NULL;
afi_t afi;
- TAILQ_FOREACH (info, &client->gr_info_queue, gr_info) {
- if (info->vrf_id == vrf_id)
- break;
- }
-
if (info == NULL)
return;
/* Check if route update completed for all AFI, SAFI */
for (afi = AFI_IP; afi < AFI_MAX; afi++) {
- if (info->af_enabled[afi]) {
- if (!info->route_sync[afi]) {
- struct vrf *vrf = vrf_lookup_by_id(vrf_id);
-
- LOG_GR("%s: Client %s vrf: %s(%u) route update not completed for AFI %d",
- __func__,
- zebra_route_string(client->proto),
- VRF_LOGNAME(vrf), info->vrf_id, afi);
- return;
- }
+ if (info->af_enabled[afi] && !info->route_sync[afi]) {
+ struct vrf *vrf = vrf_lookup_by_id(info->vrf_id);
+
+ LOG_GR("%s: Client %s vrf: %s(%u) route update not completed for AFI %d",
+ __func__, zebra_route_string(client->proto),
+ VRF_LOGNAME(vrf), info->vrf_id, afi);
+ return;
}
}
@@ -646,7 +607,7 @@ static void zebra_gr_process_client_stale_routes(struct zserv *client,
* Cancel the stale timer and process the routes
*/
if (info->t_stale_removal) {
- struct vrf *vrf = vrf_lookup_by_id(vrf_id);
+ struct vrf *vrf = vrf_lookup_by_id(info->vrf_id);
LOG_GR("%s: Client %s canceled stale delete timer vrf %s(%d)",
__func__, zebra_route_string(client->proto),