From: Donald Sharp Date: Sun, 16 Mar 2025 22:43:25 +0000 (-0400) Subject: zebra: Rework the stale client list to a typesafe list X-Git-Url: https://git.puffer.fish/?a=commitdiff_plain;h=4d6f5c7e27b231b7bb4a8a2a10d80f08c63cbd42;p=matthieu%2Ffrr.git zebra: Rework the stale client list to a typesafe list The stale client list was just a linked list, let's use the typesafe list. Signed-off-by: Donald Sharp --- diff --git a/zebra/main.c b/zebra/main.c index dd910e45ca..5c169bb839 100644 --- a/zebra/main.c +++ b/zebra/main.c @@ -162,8 +162,7 @@ static void sigint(void) zebra_dplane_pre_finish(); /* Clean up GR related info. */ - zebra_gr_stale_client_cleanup(zrouter.stale_client_list); - list_delete_all_node(zrouter.stale_client_list); + zebra_gr_stale_client_cleanup(); /* Clean up zapi clients and server module */ frr_each_safe (zserv_client_list, &zrouter.client_list, client) @@ -200,8 +199,6 @@ static void sigint(void) rib_update_finish(); - list_delete(&zrouter.stale_client_list); - /* * Besides other clean-ups zebra's vrf_disable() also enqueues installed * routes for removal from the kernel, unless ZEBRA_VRF_RETAIN is set. @@ -255,6 +252,7 @@ void zebra_finalize(struct event *dummy) ns_terminate(); zserv_client_list_fini(&zrouter.client_list); + zserv_stale_client_list_fini(&zrouter.stale_client_list); frr_fini(); exit(0); diff --git a/zebra/zebra_gr.c b/zebra/zebra_gr.c index 07391b7ac7..3be9512c77 100644 --- a/zebra/zebra_gr.c +++ b/zebra/zebra_gr.c @@ -62,15 +62,13 @@ static void zebra_gr_delete_stale_route_table_afi(struct event *event); * function will also clean up all per instance * capabilities that are exchanged. */ -void zebra_gr_stale_client_cleanup(struct list *client_list) +void zebra_gr_stale_client_cleanup(void) { - struct listnode *node, *nnode; struct zserv *s_client = NULL; struct client_gr_info *info, *ninfo; /* Find the stale client */ - for (ALL_LIST_ELEMENTS(client_list, node, nnode, s_client)) { - + frr_each_safe (zserv_stale_client_list, &zrouter.stale_client_list, s_client) { LOG_GR("%s: Stale client %s is being deleted", __func__, zebra_route_string(s_client->proto)); @@ -173,7 +171,7 @@ int32_t zebra_gr_client_disconnect(struct zserv *client) } } - listnode_add(zrouter.stale_client_list, client); + zserv_stale_client_list_add_tail(&zrouter.stale_client_list, client); return 0; } @@ -215,7 +213,7 @@ static void zebra_gr_delete_stale_client(struct client_gr_info *info) info->vrf_id); TAILQ_INIT(&(s_client->gr_info_queue)); - listnode_delete(zrouter.stale_client_list, s_client); + zserv_stale_client_list_del(&zrouter.stale_client_list, s_client); if (info->stale_client) zserv_client_delete(s_client); XFREE(MTYPE_ZEBRA_GR, info); @@ -226,12 +224,10 @@ static void zebra_gr_delete_stale_client(struct client_gr_info *info) */ static struct zserv *zebra_gr_find_stale_client(struct zserv *client) { - struct listnode *node, *nnode; struct zserv *stale_client; /* Find the stale client */ - for (ALL_LIST_ELEMENTS(zrouter.stale_client_list, node, nnode, - stale_client)) { + frr_each (zserv_stale_client_list, &zrouter.stale_client_list, stale_client) { if (client->proto == stale_client->proto && client->instance == stale_client->instance) { return stale_client; @@ -246,17 +242,11 @@ static struct zserv *zebra_gr_find_stale_client(struct zserv *client) */ void zebra_gr_client_reconnect(struct zserv *client) { - struct listnode *node, *nnode; struct zserv *old_client = NULL; struct client_gr_info *info = NULL; /* Find the stale client */ - for (ALL_LIST_ELEMENTS(zrouter.stale_client_list, node, nnode, - old_client)) { - if (client->proto == old_client->proto - && client->instance == old_client->instance) - break; - } + old_client = zebra_gr_find_stale_client(client); /* Copy the timers */ if (!old_client) @@ -281,7 +271,7 @@ void zebra_gr_client_reconnect(struct zserv *client) } /* Delete the stale client */ - listnode_delete(zrouter.stale_client_list, old_client); + zserv_stale_client_list_del(&zrouter.stale_client_list, old_client); /* Delete old client */ zserv_client_delete(old_client); } diff --git a/zebra/zebra_router.h b/zebra/zebra_router.h index e0f492b36b..597d3f4572 100644 --- a/zebra/zebra_router.h +++ b/zebra/zebra_router.h @@ -129,7 +129,7 @@ struct zebra_router { struct zserv_client_list_head client_list; /* List of clients in GR */ - struct list *stale_client_list; + struct zserv_stale_client_list_head stale_client_list; struct zebra_router_table_head tables; diff --git a/zebra/zserv.c b/zebra/zserv.c index dda6a3e13d..d477cd051f 100644 --- a/zebra/zserv.c +++ b/zebra/zserv.c @@ -1412,7 +1412,7 @@ void zserv_init(void) { /* Client list init. */ zserv_client_list_init(&zrouter.client_list); - zrouter.stale_client_list = list_new(); + zserv_stale_client_list_init(&zrouter.stale_client_list); /* Misc init. */ zsock = -1; diff --git a/zebra/zserv.h b/zebra/zserv.h index ec631339b8..3110f7f94b 100644 --- a/zebra/zserv.h +++ b/zebra/zserv.h @@ -72,6 +72,7 @@ struct client_gr_info { /* For managing client list */ PREDECL_LIST(zserv_client_list); +PREDECL_LIST(zserv_stale_client_list); /* Client structure. */ struct zserv { @@ -92,6 +93,9 @@ struct zserv { /* For managing this node in the client list */ struct zserv_client_list_item client_list_entry; + /* For managing this node in the stale client list */ + struct zserv_stale_client_list_item stale_client_list_entry; + /* Input/output buffer to the client. */ pthread_mutex_t ibuf_mtx; struct stream_fifo *ibuf_fifo; @@ -238,6 +242,7 @@ struct zserv { /* Declare the list operations */ DECLARE_LIST(zserv_client_list, struct zserv, client_list_entry); +DECLARE_LIST(zserv_stale_client_list, struct zserv, stale_client_list_entry); #define ZAPI_HANDLER_ARGS \ struct zserv *client, struct zmsghdr *hdr, struct stream *msg, \ @@ -404,7 +409,7 @@ __attribute__((__noreturn__)) void zebra_finalize(struct event *event); extern void zebra_gr_client_final_shutdown(struct zserv *client); extern int zebra_gr_client_disconnect(struct zserv *client); extern void zebra_gr_client_reconnect(struct zserv *client); -extern void zebra_gr_stale_client_cleanup(struct list *client_list); +extern void zebra_gr_stale_client_cleanup(void); extern void zread_client_capabilities(struct zserv *client, struct zmsghdr *hdr, struct stream *msg, struct zebra_vrf *zvrf);