]> git.puffer.fish Git - matthieu/frr.git/commitdiff
zebra: Rework the stale client list to a typesafe list
authorDonald Sharp <donaldsharp72@gmail.com>
Sun, 16 Mar 2025 22:43:25 +0000 (18:43 -0400)
committerDonald Sharp <sharpd@nvidia.com>
Wed, 19 Mar 2025 17:43:00 +0000 (13:43 -0400)
The stale client list was just a linked list, let's use
the typesafe list.

Signed-off-by: Donald Sharp <donaldsharp72@gmail.com>
zebra/main.c
zebra/zebra_gr.c
zebra/zebra_router.h
zebra/zserv.c
zebra/zserv.h

index dd910e45ca2683a3c55cfe5288ec6c1fd03de270..5c169bb839d4cf0b230afa37aaf8611c04c2856b 100644 (file)
@@ -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);
index 07391b7ac7192f39f12dec94101c2f4f00d921aa..3be9512c778e7389759c629d8abb13f89d733d26 100644 (file)
@@ -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);
 }
index e0f492b36b80248a3521908fa456fba6e9057c5d..597d3f4572a58935f8383e1c3f3e615702b94fa5 100644 (file)
@@ -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;
 
index dda6a3e13d119b7a08511b148f34df84f39e8055..d477cd051f4b47eb18d7430ed68ea8876611be7f 100644 (file)
@@ -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;
index ec631339b815e7cb9edd076d518bac929be7f823..3110f7f94bdca745e808f2e8e26ae709af385b29 100644 (file)
@@ -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);