From 24d293277f9e34c57605c7e62aa9658abf617063 Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Sun, 16 Mar 2025 16:56:19 -0400 Subject: [PATCH] zebra: Convert the zrouter.client_list to a typesafe list This list should just be a typesafe list. Signed-off-by: Donald Sharp --- zebra/main.c | 8 ++++---- zebra/redistribute.c | 34 +++++++++++----------------------- zebra/router-id.c | 9 +++------ zebra/zapi_msg.c | 24 ++++++++---------------- zebra/zebra_mlag.c | 3 +-- zebra/zebra_ptm.c | 6 ++---- zebra/zebra_ptm_redistribute.c | 6 ++---- zebra/zebra_router.h | 2 +- zebra/zebra_srv6.c | 16 ++++++++-------- zebra/zebra_srv6_vty.c | 6 +----- zebra/zebra_vrf.c | 6 ++---- zebra/zserv.c | 19 +++++++------------ zebra/zserv.h | 9 +++++++++ 13 files changed, 59 insertions(+), 89 deletions(-) diff --git a/zebra/main.c b/zebra/main.c index fd242e762a..dd910e45ca 100644 --- a/zebra/main.c +++ b/zebra/main.c @@ -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); } diff --git a/zebra/redistribute.c b/zebra/redistribute.c index 9bf7e2cbb5..ff1d9134e9 100644 --- a/zebra/redistribute.c +++ b/zebra/redistribute.c @@ -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; diff --git a/zebra/router-id.c b/zebra/router-id.c index 2f251a79e5..5a857abd85 100644 --- a/zebra/router-id.c +++ b/zebra/router-id.c @@ -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)); } diff --git a/zebra/zapi_msg.c b/zebra/zapi_msg.c index 066859d380..064b377f28 100644 --- a/zebra/zapi_msg.c +++ b/zebra/zapi_msg.c @@ -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; diff --git a/zebra/zebra_mlag.c b/zebra/zebra_mlag.c index 8fd373cb19..f1fc046737 100644 --- a/zebra/zebra_mlag.c +++ b/zebra/zebra_mlag.c @@ -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, diff --git a/zebra/zebra_ptm.c b/zebra/zebra_ptm.c index d7d752f01e..9188921fe4 100644 --- a/zebra/zebra_ptm.c +++ b/zebra/zebra_ptm.c @@ -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; diff --git a/zebra/zebra_ptm_redistribute.c b/zebra/zebra_ptm_redistribute.c index cab6944a87..267820aceb 100644 --- a/zebra/zebra_ptm_redistribute.c +++ b/zebra/zebra_ptm_redistribute.c @@ -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; diff --git a/zebra/zebra_router.h b/zebra/zebra_router.h index d357994ec2..e0f492b36b 100644 --- a/zebra/zebra_router.h +++ b/zebra/zebra_router.h @@ -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; diff --git a/zebra/zebra_srv6.c b/zebra/zebra_srv6.c index f9b5dd8808..ebfd5c0908 100644 --- a/zebra/zebra_srv6.c +++ b/zebra/zebra_srv6.c @@ -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; diff --git a/zebra/zebra_srv6_vty.c b/zebra/zebra_srv6_vty.c index 6867b1bbb6..22ba9386d9 100644 --- a/zebra/zebra_srv6_vty.c +++ b/zebra/zebra_srv6_vty.c @@ -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; diff --git a/zebra/zebra_vrf.c b/zebra/zebra_vrf.c index d652c57388..3231b03b81 100644 --- a/zebra/zebra_vrf.c +++ b/zebra/zebra_vrf.c @@ -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; diff --git a/zebra/zserv.c b/zebra/zserv.c index 6965c285cd..dda6a3e13d 100644 --- a/zebra/zserv.c +++ b/zebra/zserv.c @@ -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. */ diff --git a/zebra/zserv.h b/zebra/zserv.h index 1ff7ccd981..ec631339b8 100644 --- a/zebra/zserv.h +++ b/zebra/zserv.h @@ -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 -- 2.39.5