]> git.puffer.fish Git - matthieu/frr.git/commitdiff
zebra: Convert the zrouter.client_list to a typesafe list
authorDonald Sharp <donaldsharp72@gmail.com>
Sun, 16 Mar 2025 20:56:19 +0000 (16:56 -0400)
committerDonald Sharp <sharpd@nvidia.com>
Wed, 19 Mar 2025 17:27:36 +0000 (13:27 -0400)
This list should just be a typesafe list.

Signed-off-by: Donald Sharp <donaldsharp72@gmail.com>
13 files changed:
zebra/main.c
zebra/redistribute.c
zebra/router-id.c
zebra/zapi_msg.c
zebra/zebra_mlag.c
zebra/zebra_ptm.c
zebra/zebra_ptm_redistribute.c
zebra/zebra_router.h
zebra/zebra_srv6.c
zebra/zebra_srv6_vty.c
zebra/zebra_vrf.c
zebra/zserv.c
zebra/zserv.h

index fd242e762a34aef2b0c3d558a6635202f7f30c37..dd910e45ca2683a3c55cfe5288ec6c1fd03de270 100644 (file)
@@ -134,7 +134,6 @@ static void sigint(void)
 {
        struct vrf *vrf;
        struct zebra_vrf *zvrf;
-       struct listnode *ln, *nn;
        struct zserv *client;
        static bool sigint_done;
 
@@ -167,11 +166,10 @@ static void sigint(void)
        list_delete_all_node(zrouter.stale_client_list);
 
        /* Clean up zapi clients and server module */
-       for (ALL_LIST_ELEMENTS(zrouter.client_list, ln, nn, client))
+       frr_each_safe (zserv_client_list, &zrouter.client_list, client)
                zserv_close_client(client);
 
        zserv_close();
-       list_delete_all_node(zrouter.client_list);
 
        /* Once all the zclients are cleaned up, clean up the opaque module */
        zebra_opaque_finish();
@@ -202,7 +200,6 @@ static void sigint(void)
 
        rib_update_finish();
 
-       list_delete(&zrouter.client_list);
        list_delete(&zrouter.stale_client_list);
 
        /*
@@ -256,6 +253,9 @@ void zebra_finalize(struct event *dummy)
        ns_walk_func(zebra_ns_final_shutdown, NULL, NULL);
 
        ns_terminate();
+
+       zserv_client_list_fini(&zrouter.client_list);
+
        frr_fini();
        exit(0);
 }
index 9bf7e2cbb52b5cb8656110879fa23c738169c814..ff1d9134e9d89e7d04851ebcd5cca8aaf2eebfbc 100644 (file)
@@ -243,7 +243,6 @@ void redistribute_update(const struct route_node *rn,
                         const struct route_entry *re,
                         const struct route_entry *prev_re)
 {
-       struct listnode *node, *nnode;
        struct zserv *client;
 
        if (IS_ZEBRA_DEBUG_RIB)
@@ -259,7 +258,7 @@ void redistribute_update(const struct route_node *rn,
                return;
        }
 
-       for (ALL_LIST_ELEMENTS(zrouter.client_list, node, nnode, client)) {
+       frr_each (zserv_client_list, &zrouter.client_list, client) {
                if (zebra_redistribute_check(rn, re, client)) {
                        if (IS_ZEBRA_DEBUG_RIB) {
                                zlog_debug(
@@ -298,7 +297,6 @@ void redistribute_delete(const struct route_node *rn,
                         const struct route_entry *old_re,
                         const struct route_entry *new_re)
 {
-       struct listnode *node, *nnode;
        struct zserv *client;
        vrf_id_t vrfid;
 
@@ -342,7 +340,7 @@ void redistribute_delete(const struct route_node *rn,
                return;
        }
 
-       for (ALL_LIST_ELEMENTS(zrouter.client_list, node, nnode, client)) {
+       frr_each (zserv_client_list, &zrouter.client_list, client) {
                /* Do not send unsolicited messages to synchronous clients. */
                if (client->synchronous)
                        continue;
@@ -527,7 +525,6 @@ stream_failure:
 /* Interface up information. */
 void zebra_interface_up_update(struct interface *ifp)
 {
-       struct listnode *node, *nnode;
        struct zserv *client;
 
        if (IS_ZEBRA_DEBUG_EVENT)
@@ -535,8 +532,7 @@ void zebra_interface_up_update(struct interface *ifp)
                           ifp->name, ifp->vrf->name, ifp->vrf->vrf_id);
 
        if (ifp->ptm_status || !ifp->ptm_enable) {
-               for (ALL_LIST_ELEMENTS(zrouter.client_list, node, nnode,
-                                      client)) {
+               frr_each (zserv_client_list, &zrouter.client_list, client) {
                        /* Do not send unsolicited messages to synchronous
                         * clients.
                         */
@@ -553,14 +549,13 @@ void zebra_interface_up_update(struct interface *ifp)
 /* Interface down information. */
 void zebra_interface_down_update(struct interface *ifp)
 {
-       struct listnode *node, *nnode;
        struct zserv *client;
 
        if (IS_ZEBRA_DEBUG_EVENT)
                zlog_debug("MESSAGE: ZEBRA_INTERFACE_DOWN %s vrf %s(%u)",
                           ifp->name, ifp->vrf->name, ifp->vrf->vrf_id);
 
-       for (ALL_LIST_ELEMENTS(zrouter.client_list, node, nnode, client)) {
+       frr_each (zserv_client_list, &zrouter.client_list, client) {
                /* Do not send unsolicited messages to synchronous clients. */
                if (client->synchronous)
                        continue;
@@ -574,14 +569,13 @@ void zebra_interface_down_update(struct interface *ifp)
 /* Interface information update. */
 void zebra_interface_add_update(struct interface *ifp)
 {
-       struct listnode *node, *nnode;
        struct zserv *client;
 
        if (IS_ZEBRA_DEBUG_EVENT)
                zlog_debug("MESSAGE: ZEBRA_INTERFACE_ADD %s vrf %s(%u)",
                           ifp->name, ifp->vrf->name, ifp->vrf->vrf_id);
 
-       for (ALL_LIST_ELEMENTS(zrouter.client_list, node, nnode, client)) {
+       frr_each (zserv_client_list, &zrouter.client_list, client) {
                /* Do not send unsolicited messages to synchronous clients. */
                if (client->synchronous)
                        continue;
@@ -594,14 +588,13 @@ void zebra_interface_add_update(struct interface *ifp)
 
 void zebra_interface_delete_update(struct interface *ifp)
 {
-       struct listnode *node, *nnode;
        struct zserv *client;
 
        if (IS_ZEBRA_DEBUG_EVENT)
                zlog_debug("MESSAGE: ZEBRA_INTERFACE_DELETE %s vrf %s(%u)",
                           ifp->name, ifp->vrf->name, ifp->vrf->vrf_id);
 
-       for (ALL_LIST_ELEMENTS(zrouter.client_list, node, nnode, client)) {
+       frr_each (zserv_client_list, &zrouter.client_list, client) {
                /* Do not send unsolicited messages to synchronous clients. */
                if (client->synchronous)
                        continue;
@@ -615,7 +608,6 @@ void zebra_interface_delete_update(struct interface *ifp)
 void zebra_interface_address_add_update(struct interface *ifp,
                                        struct connected *ifc)
 {
-       struct listnode *node, *nnode;
        struct zserv *client;
 
        if (IS_ZEBRA_DEBUG_EVENT)
@@ -633,7 +625,7 @@ void zebra_interface_address_add_update(struct interface *ifp,
 
        router_id_add_address(ifc);
 
-       for (ALL_LIST_ELEMENTS(zrouter.client_list, node, nnode, client)) {
+       frr_each (zserv_client_list, &zrouter.client_list, client) {
                /* Do not send unsolicited messages to synchronous clients. */
                if (client->synchronous)
                        continue;
@@ -650,7 +642,6 @@ void zebra_interface_address_add_update(struct interface *ifp,
 void zebra_interface_address_delete_update(struct interface *ifp,
                                           struct connected *ifc)
 {
-       struct listnode *node, *nnode;
        struct zserv *client;
 
        if (IS_ZEBRA_DEBUG_EVENT)
@@ -663,7 +654,7 @@ void zebra_interface_address_delete_update(struct interface *ifp,
 
        router_id_del_address(ifc);
 
-       for (ALL_LIST_ELEMENTS(zrouter.client_list, node, nnode, client)) {
+       frr_each (zserv_client_list, &zrouter.client_list, client) {
                /* Do not send unsolicited messages to synchronous clients. */
                if (client->synchronous)
                        continue;
@@ -681,14 +672,13 @@ void zebra_interface_address_delete_update(struct interface *ifp,
  */
 void zebra_interface_vrf_update_del(struct interface *ifp, vrf_id_t new_vrf_id)
 {
-       struct listnode *node, *nnode;
        struct zserv *client;
 
        if (IS_ZEBRA_DEBUG_EVENT)
                zlog_debug("MESSAGE: ZEBRA_INTERFACE_DELETE %s VRF Id %u -> %u",
                           ifp->name, ifp->vrf->vrf_id, new_vrf_id);
 
-       for (ALL_LIST_ELEMENTS(zrouter.client_list, node, nnode, client)) {
+       frr_each (zserv_client_list, &zrouter.client_list, client) {
                /* Do not send unsolicited messages to synchronous clients. */
                if (client->synchronous)
                        continue;
@@ -706,14 +696,13 @@ void zebra_interface_vrf_update_del(struct interface *ifp, vrf_id_t new_vrf_id)
  */
 void zebra_interface_vrf_update_add(struct interface *ifp, vrf_id_t old_vrf_id)
 {
-       struct listnode *node, *nnode;
        struct zserv *client;
 
        if (IS_ZEBRA_DEBUG_EVENT)
                zlog_debug("MESSAGE: ZEBRA_INTERFACE_ADD %s VRF Id %u -> %u",
                           ifp->name, old_vrf_id, ifp->vrf->vrf_id);
 
-       for (ALL_LIST_ELEMENTS(zrouter.client_list, node, nnode, client)) {
+       frr_each (zserv_client_list, &zrouter.client_list, client) {
                /* Do not send unsolicited messages to synchronous clients. */
                if (client->synchronous)
                        continue;
@@ -993,14 +982,13 @@ void zebra_import_table_rm_update(const char *rmap)
 /* Interface parameters update */
 void zebra_interface_parameters_update(struct interface *ifp)
 {
-       struct listnode *node, *nnode;
        struct zserv *client;
 
        if (IS_ZEBRA_DEBUG_EVENT)
                zlog_debug("MESSAGE: ZEBRA_INTERFACE_LINK_PARAMS %s vrf %s(%u)",
                           ifp->name, ifp->vrf->name, ifp->vrf->vrf_id);
 
-       for (ALL_LIST_ELEMENTS(zrouter.client_list, node, nnode, client)) {
+       frr_each (zserv_client_list, &zrouter.client_list, client) {
                /* Do not send unsolicited messages to synchronous clients. */
                if (client->synchronous)
                        continue;
index 2f251a79e58451ae6847fb662291ec15936ab0b3..5a857abd8547375283ecae752e7b1c168c9578d6 100644 (file)
@@ -112,7 +112,6 @@ int router_id_get(afi_t afi, struct prefix *p, struct zebra_vrf *zvrf)
 int router_id_set(afi_t afi, struct prefix *p, struct zebra_vrf *zvrf)
 {
        struct prefix after, before;
-       struct listnode *node;
        struct zserv *client;
 
        router_id_get(afi, &before, zvrf);
@@ -139,7 +138,7 @@ int router_id_set(afi_t afi, struct prefix *p, struct zebra_vrf *zvrf)
        if (prefix_same(&before, &after))
                return 0;
 
-       for (ALL_LIST_ELEMENTS_RO(zrouter.client_list, node, client))
+       frr_each (zserv_client_list, &zrouter.client_list, client)
                zsend_router_id_update(client, afi, &after, zvrf->vrf->vrf_id);
 
        return 0;
@@ -148,7 +147,6 @@ int router_id_set(afi_t afi, struct prefix *p, struct zebra_vrf *zvrf)
 void router_id_add_address(struct connected *ifc)
 {
        struct list *l = NULL;
-       struct listnode *node;
        struct prefix before;
        struct prefix after;
        struct zserv *client;
@@ -187,7 +185,7 @@ void router_id_add_address(struct connected *ifc)
        if (prefix_same(&before, &after))
                return;
 
-       for (ALL_LIST_ELEMENTS_RO(zrouter.client_list, node, client))
+       frr_each (zserv_client_list, &zrouter.client_list, client)
                zsend_router_id_update(client, afi, &after, zvrf_id(zvrf));
 }
 
@@ -197,7 +195,6 @@ void router_id_del_address(struct connected *ifc)
        struct list *l;
        struct prefix after;
        struct prefix before;
-       struct listnode *node;
        struct zserv *client;
        struct zebra_vrf *zvrf = ifc->ifp->vrf->info;
        afi_t afi;
@@ -237,7 +234,7 @@ void router_id_del_address(struct connected *ifc)
        if (prefix_same(&before, &after))
                return;
 
-       for (ALL_LIST_ELEMENTS_RO(zrouter.client_list, node, client))
+       frr_each (zserv_client_list, &zrouter.client_list, client)
                zsend_router_id_update(client, afi, &after, zvrf_id(zvrf));
 }
 
index 066859d380da30f6839d8140abe7da932338f60f..064b377f283d2672b9bfdd9c4d4b268098d031a0 100644 (file)
@@ -353,7 +353,6 @@ static int zsend_interface_nbr_address(int cmd, struct zserv *client,
 static void zebra_interface_nbr_address_add_update(struct interface *ifp,
                                                   struct nbr_connected *ifc)
 {
-       struct listnode *node, *nnode;
        struct zserv *client;
        struct prefix *p;
 
@@ -368,7 +367,7 @@ static void zebra_interface_nbr_address_add_update(struct interface *ifp,
                        p->prefixlen, ifc->ifp->name);
        }
 
-       for (ALL_LIST_ELEMENTS(zrouter.client_list, node, nnode, client)) {
+       frr_each (zserv_client_list, &zrouter.client_list, client) {
                /* Do not send unsolicited messages to synchronous clients. */
                if (client->synchronous)
                        continue;
@@ -382,7 +381,6 @@ static void zebra_interface_nbr_address_add_update(struct interface *ifp,
 static void zebra_interface_nbr_address_delete_update(struct interface *ifp,
                                                      struct nbr_connected *ifc)
 {
-       struct listnode *node, *nnode;
        struct zserv *client;
        struct prefix *p;
 
@@ -397,7 +395,7 @@ static void zebra_interface_nbr_address_delete_update(struct interface *ifp,
                        p->prefixlen, ifc->ifp->name);
        }
 
-       for (ALL_LIST_ELEMENTS(zrouter.client_list, node, nnode, client)) {
+       frr_each (zserv_client_list, &zrouter.client_list, client) {
                /* Do not send unsolicited messages to synchronous clients. */
                if (client->synchronous)
                        continue;
@@ -836,7 +834,6 @@ stream_failure:
 void zsend_rule_notify_owner(const struct zebra_dplane_ctx *ctx,
                             enum zapi_rule_notify_owner note)
 {
-       struct listnode *node;
        struct zserv *client;
        struct stream *s;
 
@@ -844,7 +841,7 @@ void zsend_rule_notify_owner(const struct zebra_dplane_ctx *ctx,
                zlog_debug("%s: Notifying %u", __func__,
                           dplane_ctx_rule_get_unique(ctx));
 
-       for (ALL_LIST_ELEMENTS_RO(zrouter.client_list, node, client)) {
+       frr_each (zserv_client_list, &zrouter.client_list, client) {
                if (dplane_ctx_rule_get_sock(ctx) == client->sock)
                        break;
        }
@@ -871,7 +868,6 @@ void zsend_rule_notify_owner(const struct zebra_dplane_ctx *ctx,
 void zsend_iptable_notify_owner(const struct zebra_dplane_ctx *ctx,
                                enum zapi_iptable_notify_owner note)
 {
-       struct listnode *node;
        struct zserv *client;
        struct stream *s;
        struct zebra_pbr_iptable ipt;
@@ -898,7 +894,7 @@ void zsend_iptable_notify_owner(const struct zebra_dplane_ctx *ctx,
                zlog_debug("%s: Notifying %s id %u note %u", __func__,
                           zserv_command_string(cmd), ipt.unique, note);
 
-       for (ALL_LIST_ELEMENTS_RO(zrouter.client_list, node, client)) {
+       frr_each (zserv_client_list, &zrouter.client_list, client) {
                if (ipt.sock == client->sock)
                        break;
        }
@@ -920,7 +916,6 @@ void zsend_iptable_notify_owner(const struct zebra_dplane_ctx *ctx,
 void zsend_ipset_notify_owner(const struct zebra_dplane_ctx *ctx,
                              enum zapi_ipset_notify_owner note)
 {
-       struct listnode *node;
        struct zserv *client;
        struct stream *s;
        struct zebra_pbr_ipset ipset;
@@ -932,7 +927,7 @@ void zsend_ipset_notify_owner(const struct zebra_dplane_ctx *ctx,
                zlog_debug("%s: Notifying %s id %u note %u", __func__,
                           zserv_command_string(cmd), ipset.unique, note);
 
-       for (ALL_LIST_ELEMENTS_RO(zrouter.client_list, node, client)) {
+       frr_each (zserv_client_list, &zrouter.client_list, client) {
                if (ipset.sock == client->sock)
                        break;
        }
@@ -954,7 +949,6 @@ void zsend_ipset_notify_owner(const struct zebra_dplane_ctx *ctx,
 void zsend_ipset_entry_notify_owner(const struct zebra_dplane_ctx *ctx,
                                    enum zapi_ipset_entry_notify_owner note)
 {
-       struct listnode *node;
        struct zserv *client;
        struct stream *s;
        struct zebra_pbr_ipset_entry ipent;
@@ -968,7 +962,7 @@ void zsend_ipset_entry_notify_owner(const struct zebra_dplane_ctx *ctx,
                zlog_debug("%s: Notifying %s id %u note %u", __func__,
                           zserv_command_string(cmd), ipent.unique, note);
 
-       for (ALL_LIST_ELEMENTS_RO(zrouter.client_list, node, client)) {
+       frr_each (zserv_client_list, &zrouter.client_list, client) {
                if (ipent.sock == client->sock)
                        break;
        }
@@ -992,7 +986,6 @@ void zsend_neighbor_notify(int cmd, struct interface *ifp,
                           union sockunion *link_layer_ipv4, int ip_len)
 {
        struct stream *s;
-       struct listnode *node, *nnode;
        struct zserv *client;
        afi_t afi;
        union sockunion ip;
@@ -1005,7 +998,7 @@ void zsend_neighbor_notify(int cmd, struct interface *ifp,
        memcpy((char *)sockunion_get_addr(&ip), &ipaddr->ip.addr,
               family2addrsize(sockunion_family(&ip)));
 
-       for (ALL_LIST_ELEMENTS(zrouter.client_list, node, nnode, client)) {
+       frr_each (zserv_client_list, &zrouter.client_list, client) {
                if (!vrf_bitmap_check(&client->neighinfo[afi],
                                      ifp->vrf->vrf_id))
                        continue;
@@ -2439,12 +2432,11 @@ static void zsend_capabilities(struct zserv *client, struct zebra_vrf *zvrf)
 
 void zsend_capabilities_all_clients(void)
 {
-       struct listnode *node, *nnode;
        struct zebra_vrf *zvrf;
        struct zserv *client;
 
        zvrf = zebra_vrf_lookup_by_id(VRF_DEFAULT);
-       for (ALL_LIST_ELEMENTS(zrouter.client_list, node, nnode, client)) {
+       frr_each (zserv_client_list, &zrouter.client_list, client) {
                /* Do not send unsolicited messages to synchronous clients. */
                if (client->synchronous)
                        continue;
index 8fd373cb19d16578a08dc5c12a2e6d5f324314a5..f1fc0467379b4b0c7bca1085d79745e811f62f19 100644 (file)
@@ -296,7 +296,6 @@ static void zebra_mlag_post_data_from_main_thread(struct event *thread)
 {
        struct stream *s = EVENT_ARG(thread);
        struct stream *zebra_s = NULL;
-       struct listnode *node;
        struct zserv *client;
        uint32_t msg_type = 0;
        uint32_t msg_len = 0;
@@ -311,7 +310,7 @@ static void zebra_mlag_post_data_from_main_thread(struct event *thread)
                        __func__, msg_type);
 
        msg_len = s->endp - ZEBRA_MLAG_METADATA_LEN;
-       for (ALL_LIST_ELEMENTS_RO(zrouter.client_list, node, client)) {
+       frr_each (zserv_client_list, &zrouter.client_list, client) {
                if (client->mlag_updates_interested == true) {
                        if (msg_type != ZEBRA_MLAG_MSG_BCAST
                            && !CHECK_FLAG(client->mlag_reg_mask1,
index d7d752f01e61458bd41396813885b1122788a7b8..9188921fe42b880df063ad82f5ebc056f3b34ce5 100644 (file)
@@ -1224,7 +1224,6 @@ static void pp_free_all(void)
  */
 static void zebra_ptm_send_bfdd(struct stream *msg)
 {
-       struct listnode *node;
        struct zserv *client;
        struct stream *msgc;
 
@@ -1232,7 +1231,7 @@ static void zebra_ptm_send_bfdd(struct stream *msg)
        msgc = stream_dup(msg);
 
        /* Send message to all running BFDd daemons. */
-       for (ALL_LIST_ELEMENTS_RO(zrouter.client_list, node, client)) {
+       frr_each (zserv_client_list, &zrouter.client_list, client) {
                if (client->proto != ZEBRA_ROUTE_BFD)
                        continue;
 
@@ -1248,7 +1247,6 @@ static void zebra_ptm_send_bfdd(struct stream *msg)
 
 static void zebra_ptm_send_clients(struct stream *msg)
 {
-       struct listnode *node;
        struct zserv *client;
        struct stream *msgc;
 
@@ -1256,7 +1254,7 @@ static void zebra_ptm_send_clients(struct stream *msg)
        msgc = stream_dup(msg);
 
        /* Send message to all running client daemons. */
-       for (ALL_LIST_ELEMENTS_RO(zrouter.client_list, node, client)) {
+       frr_each (zserv_client_list, &zrouter.client_list, client) {
                if (!IS_BFD_ENABLED_PROTOCOL(client->proto))
                        continue;
 
index cab6944a87a5e19456a9e929c46121550f8542de..267820aceb7e1c89b87821c7fcaedafc24118c9b 100644 (file)
@@ -56,10 +56,9 @@ static int zsend_interface_bfd_update(int cmd, struct zserv *client,
 void zebra_interface_bfd_update(struct interface *ifp, struct prefix *dp,
                                struct prefix *sp, int status, vrf_id_t vrf_id)
 {
-       struct listnode *node, *nnode;
        struct zserv *client;
 
-       for (ALL_LIST_ELEMENTS(zrouter.client_list, node, nnode, client)) {
+       frr_each (zserv_client_list, &zrouter.client_list, client) {
                if (!IS_BFD_ENABLED_PROTOCOL(client->proto))
                        continue;
 
@@ -86,10 +85,9 @@ static int zsend_bfd_peer_replay(int cmd, struct zserv *client)
 
 void zebra_bfd_peer_replay_req(void)
 {
-       struct listnode *node, *nnode;
        struct zserv *client;
 
-       for (ALL_LIST_ELEMENTS(zrouter.client_list, node, nnode, client)) {
+       frr_each (zserv_client_list, &zrouter.client_list, client) {
                if (!IS_BFD_ENABLED_PROTOCOL(client->proto))
                        continue;
 
index d357994ec26b5e3bf9ef00c2fa27f37aa9c95eec..e0f492b36b80248a3521908fa456fba6e9057c5d 100644 (file)
@@ -126,7 +126,7 @@ struct zebra_router {
        struct timer_wheel *ra_wheel;
 
        /* Lists of clients who have connected to us */
-       struct list *client_list;
+       struct zserv_client_list_head client_list;
 
        /* List of clients in GR */
        struct list *stale_client_list;
index f9b5dd8808573746f38c99caecb41ca2931d5b4c..ebfd5c090862c78165087a4aeef6c7a76e4800e9 100644 (file)
@@ -603,7 +603,6 @@ void zebra_srv6_locator_add(struct srv6_locator *locator)
 {
        struct zebra_srv6 *srv6 = zebra_srv6_get_default();
        struct srv6_locator *tmp;
-       struct listnode *node;
        struct zserv *client;
 
        tmp = zebra_srv6_locator_lookup(locator->name);
@@ -623,13 +622,13 @@ void zebra_srv6_locator_add(struct srv6_locator *locator)
         * frequently than adding rib entries, so a broad to all zclients will
         * not degrade the overall performance of FRRouting.
         */
-       for (ALL_LIST_ELEMENTS_RO(zrouter.client_list, node, client))
+       frr_each (zserv_client_list, &zrouter.client_list, client) {
                zsend_zebra_srv6_locator_add(client, locator);
+       }
 }
 
 void zebra_srv6_locator_delete(struct srv6_locator *locator)
 {
-       struct listnode *n;
        struct zebra_srv6 *srv6 = zebra_srv6_get_default();
        struct zserv *client;
 
@@ -644,8 +643,9 @@ void zebra_srv6_locator_delete(struct srv6_locator *locator)
         * by ZEBRA_SRV6_LOCATOR_DELETE, and this notification is sent to the
         * owner of each chunk.
         */
-       for (ALL_LIST_ELEMENTS_RO(zrouter.client_list, n, client))
+       frr_each (zserv_client_list, &zrouter.client_list, client) {
                zsend_zebra_srv6_locator_delete(client, locator);
+       }
 
        listnode_delete(srv6->locators, locator);
        srv6_locator_free(locator);
@@ -665,7 +665,6 @@ struct srv6_locator *zebra_srv6_locator_lookup(const char *name)
 
 void zebra_notify_srv6_locator_add(struct srv6_locator *locator)
 {
-       struct listnode *node;
        struct zserv *client;
 
        /*
@@ -681,13 +680,13 @@ void zebra_notify_srv6_locator_add(struct srv6_locator *locator)
         * frequently than adding rib entries, so a broad to all zclients will
         * not degrade the overall performance of FRRouting.
         */
-       for (ALL_LIST_ELEMENTS_RO(zrouter.client_list, node, client))
+       frr_each (zserv_client_list, &zrouter.client_list, client) {
                zsend_zebra_srv6_locator_add(client, locator);
+       }
 }
 
 void zebra_notify_srv6_locator_delete(struct srv6_locator *locator)
 {
-       struct listnode *n;
        struct zserv *client;
 
        /*
@@ -701,8 +700,9 @@ void zebra_notify_srv6_locator_delete(struct srv6_locator *locator)
         * by ZEBRA_SRV6_LOCATOR_DELETE, and this notification is sent to the
         * owner of each chunk.
         */
-       for (ALL_LIST_ELEMENTS_RO(zrouter.client_list, n, client))
+       frr_each (zserv_client_list, &zrouter.client_list, client) {
                zsend_zebra_srv6_locator_delete(client, locator);
+       }
 }
 
 struct zebra_srv6 srv6;
index 6867b1bbb6c4ef9bf7bb7f6f8f4214abb3c0c1b9..22ba9386d9624979385839b619abd0324ac5f851 100644 (file)
@@ -484,14 +484,10 @@ DEFPY (locator_prefix,
 
                        if (memcmp(&chunk->prefix.prefix, zero, 16) == 0) {
                                struct zserv *client;
-                               struct listnode *client_node;
 
                                chunk->prefix = *prefix;
-                               for (ALL_LIST_ELEMENTS_RO(zrouter.client_list,
-                                                         client_node,
-                                                         client)) {
+                               frr_each (zserv_client_list, &zrouter.client_list, client) {
                                        struct srv6_locator *tmp;
-
                                        if (client->proto != chunk->proto)
                                                continue;
 
index d652c57388ac29b96ae5d01410510bee88dd1285..3231b03b8152889eedf5f275571f7ba8ff9acf98 100644 (file)
@@ -45,13 +45,12 @@ DEFINE_MTYPE_STATIC(ZEBRA, OTHER_TABLE, "Other Table");
 /* VRF information update. */
 static void zebra_vrf_add_update(struct zebra_vrf *zvrf)
 {
-       struct listnode *node, *nnode;
        struct zserv *client;
 
        if (IS_ZEBRA_DEBUG_EVENT)
                zlog_debug("MESSAGE: ZEBRA_VRF_ADD %s", zvrf_name(zvrf));
 
-       for (ALL_LIST_ELEMENTS(zrouter.client_list, node, nnode, client)) {
+       frr_each (zserv_client_list, &zrouter.client_list, client) {
                /* Do not send unsolicited messages to synchronous clients. */
                if (client->synchronous)
                        continue;
@@ -62,13 +61,12 @@ static void zebra_vrf_add_update(struct zebra_vrf *zvrf)
 
 static void zebra_vrf_delete_update(struct zebra_vrf *zvrf)
 {
-       struct listnode *node, *nnode;
        struct zserv *client;
 
        if (IS_ZEBRA_DEBUG_EVENT)
                zlog_debug("MESSAGE: ZEBRA_VRF_DELETE %s", zvrf_name(zvrf));
 
-       for (ALL_LIST_ELEMENTS(zrouter.client_list, node, nnode, client)) {
+       frr_each (zserv_client_list, &zrouter.client_list, client) {
                /* Do not send unsolicited messages to synchronous clients. */
                if (client->synchronous)
                        continue;
index 6965c285cdc09beaeb7fde4688256725e050ff5c..dda6a3e13d119b7a08511b148f34df84f39e8055 100644 (file)
@@ -23,7 +23,6 @@
 #include "lib/buffer.h"           /* for BUFFER_EMPTY, BUFFER_ERROR, BUFFE... */
 #include "lib/command.h"          /* for vty, install_element, CMD_SUCCESS... */
 #include "lib/hook.h"             /* for DEFINE_HOOK, DEFINE_KOOH, hook_call */
-#include "lib/linklist.h"         /* for ALL_LIST_ELEMENTS_RO, ALL_LIST_EL... */
 #include "lib/libfrr.h"           /* for frr_zclient_addr */
 #include "lib/log.h"              /* for zlog_warn, zlog_debug, safe_strerror */
 #include "lib/memory.h"           /* for MTYPE_TMP, XCALLOC, XFREE */
@@ -728,7 +727,7 @@ void zserv_close_client(struct zserv *client)
        frr_with_mutex (&client_mutex) {
                if (client->busy_count <= 0) {
                        /* remove from client list */
-                       listnode_delete(zrouter.client_list, client);
+                       zserv_client_list_del(&zrouter.client_list, client);
                } else {
                        /*
                         * The client session object may be in use, although
@@ -802,7 +801,7 @@ static struct zserv *zserv_client_create(int sock)
 
        /* Add this client to linked list. */
        frr_with_mutex (&client_mutex) {
-               listnode_add(zrouter.client_list, client);
+               zserv_client_list_add_tail(&zrouter.client_list, client);
        }
 
        struct frr_pthread_attr zclient_pthr_attrs = {
@@ -1311,10 +1310,9 @@ static struct zserv *find_client_internal(uint8_t proto,
                                          unsigned short instance,
                                          uint32_t session_id)
 {
-       struct listnode *node, *nnode;
        struct zserv *client = NULL;
 
-       for (ALL_LIST_ELEMENTS(zrouter.client_list, node, nnode, client)) {
+       frr_each (zserv_client_list, &zrouter.client_list, client) {
                if (client->proto == proto && client->instance == instance &&
                    client->session_id == session_id)
                        break;
@@ -1362,10 +1360,9 @@ DEFUN (show_zebra_client,
        ZEBRA_STR
        "Client information\n")
 {
-       struct listnode *node;
        struct zserv *client;
 
-       for (ALL_LIST_ELEMENTS_RO(zrouter.client_list, node, client)) {
+       frr_each (zserv_client_list, &zrouter.client_list, client) {
                zebra_show_client_detail(vty, client);
                /* Show GR info if present */
                zebra_show_stale_client_detail(vty, client);
@@ -1383,7 +1380,6 @@ DEFUN (show_zebra_client_summary,
        "Client information brief\n"
        "Brief Summary\n")
 {
-       struct listnode *node;
        struct zserv *client;
 
        vty_out(vty,
@@ -1391,7 +1387,7 @@ DEFUN (show_zebra_client_summary,
        vty_out(vty,
                "------------------------------------------------------------------------------------------\n");
 
-       for (ALL_LIST_ELEMENTS_RO(zrouter.client_list, node, client))
+       frr_each (zserv_client_list, &zrouter.client_list, client)
                zebra_show_client_brief(vty, client);
 
        vty_out(vty, "Routes column shows (added+updated)/deleted\n");
@@ -1400,10 +1396,9 @@ DEFUN (show_zebra_client_summary,
 
 static int zserv_client_close_cb(struct zserv *closed_client)
 {
-       struct listnode *node, *nnode;
        struct zserv *client = NULL;
 
-       for (ALL_LIST_ELEMENTS(zrouter.client_list, node, nnode, client)) {
+       frr_each (zserv_client_list, &zrouter.client_list, client) {
                if (client->proto == closed_client->proto)
                        continue;
 
@@ -1416,7 +1411,7 @@ static int zserv_client_close_cb(struct zserv *closed_client)
 void zserv_init(void)
 {
        /* Client list init. */
-       zrouter.client_list = list_new();
+       zserv_client_list_init(&zrouter.client_list);
        zrouter.stale_client_list = list_new();
 
        /* Misc init. */
index 1ff7ccd9810c2810cbce7231a8167a2df1c69033..ec631339b815e7cb9edd076d518bac929be7f823 100644 (file)
@@ -70,6 +70,9 @@ struct client_gr_info {
        TAILQ_ENTRY(client_gr_info) gr_info;
 };
 
+/* For managing client list */
+PREDECL_LIST(zserv_client_list);
+
 /* Client structure. */
 struct zserv {
        /* Client pthread */
@@ -86,6 +89,9 @@ struct zserv {
        int busy_count;
        bool is_closed;
 
+       /* For managing this node in the client list */
+       struct zserv_client_list_item client_list_entry;
+
        /* Input/output buffer to the client. */
        pthread_mutex_t ibuf_mtx;
        struct stream_fifo *ibuf_fifo;
@@ -230,6 +236,9 @@ struct zserv {
        TAILQ_HEAD(info_list, client_gr_info) gr_info_queue;
 };
 
+/* Declare the list operations */
+DECLARE_LIST(zserv_client_list, struct zserv, client_list_entry);
+
 #define ZAPI_HANDLER_ARGS                                                      \
        struct zserv *client, struct zmsghdr *hdr, struct stream *msg,         \
                struct zebra_vrf *zvrf