mirror of
https://git.proxmox.com/git/mirror_frr
synced 2025-08-08 01:15:12 +00:00
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>
This commit is contained in:
parent
0f5ef7f9b1
commit
9c1c21da8a
145
zebra/zebra_gr.c
145
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 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 int32_t zebra_gr_delete_stale_routes(struct client_gr_info *info);
|
||||||
static void zebra_gr_process_client_stale_routes(struct zserv *client,
|
static void zebra_gr_process_client_stale_routes(struct zserv *client,
|
||||||
vrf_id_t vrf_id);
|
struct client_gr_info *info);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Debug macros.
|
* Debug macros.
|
||||||
@ -290,17 +290,43 @@ void zebra_gr_client_reconnect(struct zserv *client)
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Update the graceful restart information
|
* Function to decode and call appropriate functions
|
||||||
* for the client instance.
|
* to handle client capabilities.
|
||||||
* This function handles all the capabilities that are received.
|
|
||||||
*/
|
*/
|
||||||
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 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 */
|
/* Find the bgp information for the specified vrf id */
|
||||||
TAILQ_FOREACH (info, &client->gr_info_queue, gr_info) {
|
TAILQ_FOREACH (info, &client->gr_info_queue, gr_info) {
|
||||||
if (info->vrf_id == api->vrf_id)
|
if (info->vrf_id == api.vrf_id)
|
||||||
break;
|
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
|
* If the command is delete, then cancel the stale timer and
|
||||||
* delete the bgp info
|
* delete the bgp info
|
||||||
*/
|
*/
|
||||||
switch (api->cap) {
|
switch (api.cap) {
|
||||||
case ZEBRA_CLIENT_GR_DISABLE:
|
case ZEBRA_CLIENT_GR_DISABLE:
|
||||||
if (!info)
|
if (!info)
|
||||||
return;
|
return;
|
||||||
@ -329,18 +355,16 @@ static void zebra_client_update_info(struct zserv *client, struct zapi_cap *api)
|
|||||||
|
|
||||||
/* Update other parameters */
|
/* Update other parameters */
|
||||||
if (!info->gr_enable) {
|
if (!info->gr_enable) {
|
||||||
struct vrf *vrf = vrf_lookup_by_id(api->vrf_id);
|
|
||||||
|
|
||||||
client->gr_instance_count++;
|
client->gr_instance_count++;
|
||||||
|
|
||||||
LOG_GR("%s: Cient %s vrf %s(%u) GR enabled count %d",
|
LOG_GR("%s: Cient %s vrf %s(%u) GR enabled count %d",
|
||||||
__func__, zebra_route_string(client->proto),
|
__func__, zebra_route_string(client->proto),
|
||||||
VRF_LOGNAME(vrf), api->vrf_id,
|
VRF_LOGNAME(vrf), api.vrf_id,
|
||||||
client->gr_instance_count);
|
client->gr_instance_count);
|
||||||
|
|
||||||
info->capabilities = api->cap;
|
info->capabilities = api.cap;
|
||||||
info->stale_removal_time = api->stale_removal_time;
|
info->stale_removal_time = api.stale_removal_time;
|
||||||
info->vrf_id = api->vrf_id;
|
info->vrf_id = api.vrf_id;
|
||||||
info->gr_enable = true;
|
info->gr_enable = true;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -350,14 +374,13 @@ static void zebra_client_update_info(struct zserv *client, struct zapi_cap *api)
|
|||||||
|
|
||||||
/* Update the stale removal timer */
|
/* Update the stale removal timer */
|
||||||
if (info && info->t_stale_removal == NULL) {
|
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",
|
LOG_GR("%s: vrf %s(%u) Stale time: %d is now update to: %d",
|
||||||
__func__, VRF_LOGNAME(vrf), info->vrf_id,
|
__func__, VRF_LOGNAME(vrf), info->vrf_id,
|
||||||
info->stale_removal_time,
|
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;
|
break;
|
||||||
@ -365,86 +388,33 @@ static void zebra_client_update_info(struct zserv *client, struct zapi_cap *api)
|
|||||||
if (!info) {
|
if (!info) {
|
||||||
LOG_GR("%s: Client %s route update complete for AFI %d, SAFI %d",
|
LOG_GR("%s: Client %s route update complete for AFI %d, SAFI %d",
|
||||||
__func__, zebra_route_string(client->proto),
|
__func__, zebra_route_string(client->proto),
|
||||||
api->afi, api->safi);
|
api.afi, api.safi);
|
||||||
} else {
|
} 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",
|
LOG_GR("%s: Client %s vrf %s(%u) route update complete for AFI %d, SAFI %d",
|
||||||
__func__, zebra_route_string(client->proto),
|
__func__, zebra_route_string(client->proto),
|
||||||
VRF_LOGNAME(vrf), info->vrf_id, api->afi,
|
VRF_LOGNAME(vrf), info->vrf_id, api.afi,
|
||||||
api->safi);
|
api.safi);
|
||||||
info->route_sync[api->afi] = true;
|
info->route_sync[api.afi] = true;
|
||||||
}
|
}
|
||||||
|
zebra_gr_process_client_stale_routes(client, info);
|
||||||
break;
|
break;
|
||||||
case ZEBRA_CLIENT_ROUTE_UPDATE_PENDING:
|
case ZEBRA_CLIENT_ROUTE_UPDATE_PENDING:
|
||||||
if (!info) {
|
if (!info) {
|
||||||
LOG_GR("%s: Client %s route update pending for AFI %d, SAFI %d",
|
LOG_GR("%s: Client %s route update pending for AFI %d, SAFI %d",
|
||||||
__func__, zebra_route_string(client->proto),
|
__func__, zebra_route_string(client->proto),
|
||||||
api->afi, api->safi);
|
api.afi, api.safi);
|
||||||
} else {
|
} 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",
|
LOG_GR("%s: Client %s vrf %s(%u) route update pending for AFI %d, SAFI %d",
|
||||||
__func__, zebra_route_string(client->proto),
|
__func__, zebra_route_string(client->proto),
|
||||||
VRF_LOGNAME(vrf), info->vrf_id, api->afi,
|
VRF_LOGNAME(vrf), info->vrf_id, api.afi,
|
||||||
api->safi);
|
api.safi);
|
||||||
|
|
||||||
info->af_enabled[api->afi] = true;
|
info->af_enabled[api.afi] = true;
|
||||||
}
|
}
|
||||||
break;
|
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
|
* Stale route handling
|
||||||
*/
|
*/
|
||||||
@ -613,40 +583,31 @@ static int32_t zebra_gr_delete_stale_routes(struct client_gr_info *info)
|
|||||||
* and cancels the stale timer
|
* and cancels the stale timer
|
||||||
*/
|
*/
|
||||||
static void zebra_gr_process_client_stale_routes(struct zserv *client,
|
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;
|
afi_t afi;
|
||||||
|
|
||||||
TAILQ_FOREACH (info, &client->gr_info_queue, gr_info) {
|
|
||||||
if (info->vrf_id == vrf_id)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (info == NULL)
|
if (info == NULL)
|
||||||
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++) {
|
for (afi = AFI_IP; afi < AFI_MAX; afi++) {
|
||||||
if (info->af_enabled[afi]) {
|
if (info->af_enabled[afi] && !info->route_sync[afi]) {
|
||||||
if (!info->route_sync[afi]) {
|
struct vrf *vrf = vrf_lookup_by_id(info->vrf_id);
|
||||||
struct vrf *vrf = vrf_lookup_by_id(vrf_id);
|
|
||||||
|
|
||||||
LOG_GR("%s: Client %s vrf: %s(%u) route update not completed for AFI %d",
|
LOG_GR("%s: Client %s vrf: %s(%u) route update not completed for AFI %d",
|
||||||
__func__,
|
__func__, zebra_route_string(client->proto),
|
||||||
zebra_route_string(client->proto),
|
|
||||||
VRF_LOGNAME(vrf), info->vrf_id, afi);
|
VRF_LOGNAME(vrf), info->vrf_id, afi);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Route update completed for all AFI, SAFI
|
* Route update completed for all AFI, SAFI
|
||||||
* Cancel the stale timer and process the routes
|
* Cancel the stale timer and process the routes
|
||||||
*/
|
*/
|
||||||
if (info->t_stale_removal) {
|
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)",
|
LOG_GR("%s: Client %s canceled stale delete timer vrf %s(%d)",
|
||||||
__func__, zebra_route_string(client->proto),
|
__func__, zebra_route_string(client->proto),
|
||||||
|
Loading…
Reference in New Issue
Block a user