zebra: Convert the zrouter.client_list to a typesafe list

This list should just be a typesafe list.

Signed-off-by: Donald Sharp <donaldsharp72@gmail.com>
This commit is contained in:
Donald Sharp 2025-03-16 16:56:19 -04:00 committed by Donald Sharp
parent 5602e5fe28
commit 24d293277f
13 changed files with 59 additions and 89 deletions

View file

@ -134,7 +134,6 @@ static void sigint(void)
{ {
struct vrf *vrf; struct vrf *vrf;
struct zebra_vrf *zvrf; struct zebra_vrf *zvrf;
struct listnode *ln, *nn;
struct zserv *client; struct zserv *client;
static bool sigint_done; static bool sigint_done;
@ -167,11 +166,10 @@ static void sigint(void)
list_delete_all_node(zrouter.stale_client_list); list_delete_all_node(zrouter.stale_client_list);
/* Clean up zapi clients and server module */ /* 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_client(client);
zserv_close(); zserv_close();
list_delete_all_node(zrouter.client_list);
/* Once all the zclients are cleaned up, clean up the opaque module */ /* Once all the zclients are cleaned up, clean up the opaque module */
zebra_opaque_finish(); zebra_opaque_finish();
@ -202,7 +200,6 @@ static void sigint(void)
rib_update_finish(); rib_update_finish();
list_delete(&zrouter.client_list);
list_delete(&zrouter.stale_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_walk_func(zebra_ns_final_shutdown, NULL, NULL);
ns_terminate(); ns_terminate();
zserv_client_list_fini(&zrouter.client_list);
frr_fini(); frr_fini();
exit(0); exit(0);
} }

View file

@ -243,7 +243,6 @@ void redistribute_update(const struct route_node *rn,
const struct route_entry *re, const struct route_entry *re,
const struct route_entry *prev_re) const struct route_entry *prev_re)
{ {
struct listnode *node, *nnode;
struct zserv *client; struct zserv *client;
if (IS_ZEBRA_DEBUG_RIB) if (IS_ZEBRA_DEBUG_RIB)
@ -259,7 +258,7 @@ void redistribute_update(const struct route_node *rn,
return; 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 (zebra_redistribute_check(rn, re, client)) {
if (IS_ZEBRA_DEBUG_RIB) { if (IS_ZEBRA_DEBUG_RIB) {
zlog_debug( zlog_debug(
@ -298,7 +297,6 @@ void redistribute_delete(const struct route_node *rn,
const struct route_entry *old_re, const struct route_entry *old_re,
const struct route_entry *new_re) const struct route_entry *new_re)
{ {
struct listnode *node, *nnode;
struct zserv *client; struct zserv *client;
vrf_id_t vrfid; vrf_id_t vrfid;
@ -342,7 +340,7 @@ void redistribute_delete(const struct route_node *rn,
return; 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. */ /* Do not send unsolicited messages to synchronous clients. */
if (client->synchronous) if (client->synchronous)
continue; continue;
@ -527,7 +525,6 @@ stream_failure:
/* Interface up information. */ /* Interface up information. */
void zebra_interface_up_update(struct interface *ifp) void zebra_interface_up_update(struct interface *ifp)
{ {
struct listnode *node, *nnode;
struct zserv *client; struct zserv *client;
if (IS_ZEBRA_DEBUG_EVENT) 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); ifp->name, ifp->vrf->name, ifp->vrf->vrf_id);
if (ifp->ptm_status || !ifp->ptm_enable) { if (ifp->ptm_status || !ifp->ptm_enable) {
for (ALL_LIST_ELEMENTS(zrouter.client_list, node, nnode, frr_each (zserv_client_list, &zrouter.client_list, client) {
client)) {
/* Do not send unsolicited messages to synchronous /* Do not send unsolicited messages to synchronous
* clients. * clients.
*/ */
@ -553,14 +549,13 @@ void zebra_interface_up_update(struct interface *ifp)
/* Interface down information. */ /* Interface down information. */
void zebra_interface_down_update(struct interface *ifp) void zebra_interface_down_update(struct interface *ifp)
{ {
struct listnode *node, *nnode;
struct zserv *client; struct zserv *client;
if (IS_ZEBRA_DEBUG_EVENT) if (IS_ZEBRA_DEBUG_EVENT)
zlog_debug("MESSAGE: ZEBRA_INTERFACE_DOWN %s vrf %s(%u)", zlog_debug("MESSAGE: ZEBRA_INTERFACE_DOWN %s vrf %s(%u)",
ifp->name, ifp->vrf->name, ifp->vrf->vrf_id); 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. */ /* Do not send unsolicited messages to synchronous clients. */
if (client->synchronous) if (client->synchronous)
continue; continue;
@ -574,14 +569,13 @@ void zebra_interface_down_update(struct interface *ifp)
/* Interface information update. */ /* Interface information update. */
void zebra_interface_add_update(struct interface *ifp) void zebra_interface_add_update(struct interface *ifp)
{ {
struct listnode *node, *nnode;
struct zserv *client; struct zserv *client;
if (IS_ZEBRA_DEBUG_EVENT) if (IS_ZEBRA_DEBUG_EVENT)
zlog_debug("MESSAGE: ZEBRA_INTERFACE_ADD %s vrf %s(%u)", zlog_debug("MESSAGE: ZEBRA_INTERFACE_ADD %s vrf %s(%u)",
ifp->name, ifp->vrf->name, ifp->vrf->vrf_id); 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. */ /* Do not send unsolicited messages to synchronous clients. */
if (client->synchronous) if (client->synchronous)
continue; continue;
@ -594,14 +588,13 @@ void zebra_interface_add_update(struct interface *ifp)
void zebra_interface_delete_update(struct interface *ifp) void zebra_interface_delete_update(struct interface *ifp)
{ {
struct listnode *node, *nnode;
struct zserv *client; struct zserv *client;
if (IS_ZEBRA_DEBUG_EVENT) if (IS_ZEBRA_DEBUG_EVENT)
zlog_debug("MESSAGE: ZEBRA_INTERFACE_DELETE %s vrf %s(%u)", zlog_debug("MESSAGE: ZEBRA_INTERFACE_DELETE %s vrf %s(%u)",
ifp->name, ifp->vrf->name, ifp->vrf->vrf_id); 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. */ /* Do not send unsolicited messages to synchronous clients. */
if (client->synchronous) if (client->synchronous)
continue; continue;
@ -615,7 +608,6 @@ void zebra_interface_delete_update(struct interface *ifp)
void zebra_interface_address_add_update(struct interface *ifp, void zebra_interface_address_add_update(struct interface *ifp,
struct connected *ifc) struct connected *ifc)
{ {
struct listnode *node, *nnode;
struct zserv *client; struct zserv *client;
if (IS_ZEBRA_DEBUG_EVENT) if (IS_ZEBRA_DEBUG_EVENT)
@ -633,7 +625,7 @@ void zebra_interface_address_add_update(struct interface *ifp,
router_id_add_address(ifc); 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. */ /* Do not send unsolicited messages to synchronous clients. */
if (client->synchronous) if (client->synchronous)
continue; continue;
@ -650,7 +642,6 @@ void zebra_interface_address_add_update(struct interface *ifp,
void zebra_interface_address_delete_update(struct interface *ifp, void zebra_interface_address_delete_update(struct interface *ifp,
struct connected *ifc) struct connected *ifc)
{ {
struct listnode *node, *nnode;
struct zserv *client; struct zserv *client;
if (IS_ZEBRA_DEBUG_EVENT) if (IS_ZEBRA_DEBUG_EVENT)
@ -663,7 +654,7 @@ void zebra_interface_address_delete_update(struct interface *ifp,
router_id_del_address(ifc); 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. */ /* Do not send unsolicited messages to synchronous clients. */
if (client->synchronous) if (client->synchronous)
continue; 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) void zebra_interface_vrf_update_del(struct interface *ifp, vrf_id_t new_vrf_id)
{ {
struct listnode *node, *nnode;
struct zserv *client; struct zserv *client;
if (IS_ZEBRA_DEBUG_EVENT) if (IS_ZEBRA_DEBUG_EVENT)
zlog_debug("MESSAGE: ZEBRA_INTERFACE_DELETE %s VRF Id %u -> %u", zlog_debug("MESSAGE: ZEBRA_INTERFACE_DELETE %s VRF Id %u -> %u",
ifp->name, ifp->vrf->vrf_id, new_vrf_id); 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. */ /* Do not send unsolicited messages to synchronous clients. */
if (client->synchronous) if (client->synchronous)
continue; 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) void zebra_interface_vrf_update_add(struct interface *ifp, vrf_id_t old_vrf_id)
{ {
struct listnode *node, *nnode;
struct zserv *client; struct zserv *client;
if (IS_ZEBRA_DEBUG_EVENT) if (IS_ZEBRA_DEBUG_EVENT)
zlog_debug("MESSAGE: ZEBRA_INTERFACE_ADD %s VRF Id %u -> %u", zlog_debug("MESSAGE: ZEBRA_INTERFACE_ADD %s VRF Id %u -> %u",
ifp->name, old_vrf_id, ifp->vrf->vrf_id); 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. */ /* Do not send unsolicited messages to synchronous clients. */
if (client->synchronous) if (client->synchronous)
continue; continue;
@ -993,14 +982,13 @@ void zebra_import_table_rm_update(const char *rmap)
/* Interface parameters update */ /* Interface parameters update */
void zebra_interface_parameters_update(struct interface *ifp) void zebra_interface_parameters_update(struct interface *ifp)
{ {
struct listnode *node, *nnode;
struct zserv *client; struct zserv *client;
if (IS_ZEBRA_DEBUG_EVENT) if (IS_ZEBRA_DEBUG_EVENT)
zlog_debug("MESSAGE: ZEBRA_INTERFACE_LINK_PARAMS %s vrf %s(%u)", zlog_debug("MESSAGE: ZEBRA_INTERFACE_LINK_PARAMS %s vrf %s(%u)",
ifp->name, ifp->vrf->name, ifp->vrf->vrf_id); 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. */ /* Do not send unsolicited messages to synchronous clients. */
if (client->synchronous) if (client->synchronous)
continue; continue;

View 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) int router_id_set(afi_t afi, struct prefix *p, struct zebra_vrf *zvrf)
{ {
struct prefix after, before; struct prefix after, before;
struct listnode *node;
struct zserv *client; struct zserv *client;
router_id_get(afi, &before, zvrf); 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)) if (prefix_same(&before, &after))
return 0; 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); zsend_router_id_update(client, afi, &after, zvrf->vrf->vrf_id);
return 0; 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) void router_id_add_address(struct connected *ifc)
{ {
struct list *l = NULL; struct list *l = NULL;
struct listnode *node;
struct prefix before; struct prefix before;
struct prefix after; struct prefix after;
struct zserv *client; struct zserv *client;
@ -187,7 +185,7 @@ void router_id_add_address(struct connected *ifc)
if (prefix_same(&before, &after)) if (prefix_same(&before, &after))
return; 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)); 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 list *l;
struct prefix after; struct prefix after;
struct prefix before; struct prefix before;
struct listnode *node;
struct zserv *client; struct zserv *client;
struct zebra_vrf *zvrf = ifc->ifp->vrf->info; struct zebra_vrf *zvrf = ifc->ifp->vrf->info;
afi_t afi; afi_t afi;
@ -237,7 +234,7 @@ void router_id_del_address(struct connected *ifc)
if (prefix_same(&before, &after)) if (prefix_same(&before, &after))
return; 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)); zsend_router_id_update(client, afi, &after, zvrf_id(zvrf));
} }

View 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, static void zebra_interface_nbr_address_add_update(struct interface *ifp,
struct nbr_connected *ifc) struct nbr_connected *ifc)
{ {
struct listnode *node, *nnode;
struct zserv *client; struct zserv *client;
struct prefix *p; struct prefix *p;
@ -368,7 +367,7 @@ static void zebra_interface_nbr_address_add_update(struct interface *ifp,
p->prefixlen, ifc->ifp->name); 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. */ /* Do not send unsolicited messages to synchronous clients. */
if (client->synchronous) if (client->synchronous)
continue; 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, static void zebra_interface_nbr_address_delete_update(struct interface *ifp,
struct nbr_connected *ifc) struct nbr_connected *ifc)
{ {
struct listnode *node, *nnode;
struct zserv *client; struct zserv *client;
struct prefix *p; struct prefix *p;
@ -397,7 +395,7 @@ static void zebra_interface_nbr_address_delete_update(struct interface *ifp,
p->prefixlen, ifc->ifp->name); 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. */ /* Do not send unsolicited messages to synchronous clients. */
if (client->synchronous) if (client->synchronous)
continue; continue;
@ -836,7 +834,6 @@ stream_failure:
void zsend_rule_notify_owner(const struct zebra_dplane_ctx *ctx, void zsend_rule_notify_owner(const struct zebra_dplane_ctx *ctx,
enum zapi_rule_notify_owner note) enum zapi_rule_notify_owner note)
{ {
struct listnode *node;
struct zserv *client; struct zserv *client;
struct stream *s; struct stream *s;
@ -844,7 +841,7 @@ void zsend_rule_notify_owner(const struct zebra_dplane_ctx *ctx,
zlog_debug("%s: Notifying %u", __func__, zlog_debug("%s: Notifying %u", __func__,
dplane_ctx_rule_get_unique(ctx)); 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) if (dplane_ctx_rule_get_sock(ctx) == client->sock)
break; 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, void zsend_iptable_notify_owner(const struct zebra_dplane_ctx *ctx,
enum zapi_iptable_notify_owner note) enum zapi_iptable_notify_owner note)
{ {
struct listnode *node;
struct zserv *client; struct zserv *client;
struct stream *s; struct stream *s;
struct zebra_pbr_iptable ipt; 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__, zlog_debug("%s: Notifying %s id %u note %u", __func__,
zserv_command_string(cmd), ipt.unique, note); 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) if (ipt.sock == client->sock)
break; 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, void zsend_ipset_notify_owner(const struct zebra_dplane_ctx *ctx,
enum zapi_ipset_notify_owner note) enum zapi_ipset_notify_owner note)
{ {
struct listnode *node;
struct zserv *client; struct zserv *client;
struct stream *s; struct stream *s;
struct zebra_pbr_ipset ipset; 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__, zlog_debug("%s: Notifying %s id %u note %u", __func__,
zserv_command_string(cmd), ipset.unique, note); 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) if (ipset.sock == client->sock)
break; 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, void zsend_ipset_entry_notify_owner(const struct zebra_dplane_ctx *ctx,
enum zapi_ipset_entry_notify_owner note) enum zapi_ipset_entry_notify_owner note)
{ {
struct listnode *node;
struct zserv *client; struct zserv *client;
struct stream *s; struct stream *s;
struct zebra_pbr_ipset_entry ipent; 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__, zlog_debug("%s: Notifying %s id %u note %u", __func__,
zserv_command_string(cmd), ipent.unique, note); 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) if (ipent.sock == client->sock)
break; break;
} }
@ -992,7 +986,6 @@ void zsend_neighbor_notify(int cmd, struct interface *ifp,
union sockunion *link_layer_ipv4, int ip_len) union sockunion *link_layer_ipv4, int ip_len)
{ {
struct stream *s; struct stream *s;
struct listnode *node, *nnode;
struct zserv *client; struct zserv *client;
afi_t afi; afi_t afi;
union sockunion ip; 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, memcpy((char *)sockunion_get_addr(&ip), &ipaddr->ip.addr,
family2addrsize(sockunion_family(&ip))); 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], if (!vrf_bitmap_check(&client->neighinfo[afi],
ifp->vrf->vrf_id)) ifp->vrf->vrf_id))
continue; continue;
@ -2439,12 +2432,11 @@ static void zsend_capabilities(struct zserv *client, struct zebra_vrf *zvrf)
void zsend_capabilities_all_clients(void) void zsend_capabilities_all_clients(void)
{ {
struct listnode *node, *nnode;
struct zebra_vrf *zvrf; struct zebra_vrf *zvrf;
struct zserv *client; struct zserv *client;
zvrf = zebra_vrf_lookup_by_id(VRF_DEFAULT); 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. */ /* Do not send unsolicited messages to synchronous clients. */
if (client->synchronous) if (client->synchronous)
continue; continue;

View 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 *s = EVENT_ARG(thread);
struct stream *zebra_s = NULL; struct stream *zebra_s = NULL;
struct listnode *node;
struct zserv *client; struct zserv *client;
uint32_t msg_type = 0; uint32_t msg_type = 0;
uint32_t msg_len = 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); __func__, msg_type);
msg_len = s->endp - ZEBRA_MLAG_METADATA_LEN; 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 (client->mlag_updates_interested == true) {
if (msg_type != ZEBRA_MLAG_MSG_BCAST if (msg_type != ZEBRA_MLAG_MSG_BCAST
&& !CHECK_FLAG(client->mlag_reg_mask1, && !CHECK_FLAG(client->mlag_reg_mask1,

View file

@ -1224,7 +1224,6 @@ static void pp_free_all(void)
*/ */
static void zebra_ptm_send_bfdd(struct stream *msg) static void zebra_ptm_send_bfdd(struct stream *msg)
{ {
struct listnode *node;
struct zserv *client; struct zserv *client;
struct stream *msgc; struct stream *msgc;
@ -1232,7 +1231,7 @@ static void zebra_ptm_send_bfdd(struct stream *msg)
msgc = stream_dup(msg); msgc = stream_dup(msg);
/* Send message to all running BFDd daemons. */ /* 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) if (client->proto != ZEBRA_ROUTE_BFD)
continue; continue;
@ -1248,7 +1247,6 @@ static void zebra_ptm_send_bfdd(struct stream *msg)
static void zebra_ptm_send_clients(struct stream *msg) static void zebra_ptm_send_clients(struct stream *msg)
{ {
struct listnode *node;
struct zserv *client; struct zserv *client;
struct stream *msgc; struct stream *msgc;
@ -1256,7 +1254,7 @@ static void zebra_ptm_send_clients(struct stream *msg)
msgc = stream_dup(msg); msgc = stream_dup(msg);
/* Send message to all running client daemons. */ /* 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)) if (!IS_BFD_ENABLED_PROTOCOL(client->proto))
continue; continue;

View 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, void zebra_interface_bfd_update(struct interface *ifp, struct prefix *dp,
struct prefix *sp, int status, vrf_id_t vrf_id) struct prefix *sp, int status, vrf_id_t vrf_id)
{ {
struct listnode *node, *nnode;
struct zserv *client; 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)) if (!IS_BFD_ENABLED_PROTOCOL(client->proto))
continue; continue;
@ -86,10 +85,9 @@ static int zsend_bfd_peer_replay(int cmd, struct zserv *client)
void zebra_bfd_peer_replay_req(void) void zebra_bfd_peer_replay_req(void)
{ {
struct listnode *node, *nnode;
struct zserv *client; 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)) if (!IS_BFD_ENABLED_PROTOCOL(client->proto))
continue; continue;

View file

@ -126,7 +126,7 @@ struct zebra_router {
struct timer_wheel *ra_wheel; struct timer_wheel *ra_wheel;
/* Lists of clients who have connected to us */ /* Lists of clients who have connected to us */
struct list *client_list; struct zserv_client_list_head client_list;
/* List of clients in GR */ /* List of clients in GR */
struct list *stale_client_list; struct list *stale_client_list;

View file

@ -603,7 +603,6 @@ void zebra_srv6_locator_add(struct srv6_locator *locator)
{ {
struct zebra_srv6 *srv6 = zebra_srv6_get_default(); struct zebra_srv6 *srv6 = zebra_srv6_get_default();
struct srv6_locator *tmp; struct srv6_locator *tmp;
struct listnode *node;
struct zserv *client; struct zserv *client;
tmp = zebra_srv6_locator_lookup(locator->name); 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 * frequently than adding rib entries, so a broad to all zclients will
* not degrade the overall performance of FRRouting. * 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); zsend_zebra_srv6_locator_add(client, locator);
}
} }
void zebra_srv6_locator_delete(struct srv6_locator *locator) void zebra_srv6_locator_delete(struct srv6_locator *locator)
{ {
struct listnode *n;
struct zebra_srv6 *srv6 = zebra_srv6_get_default(); struct zebra_srv6 *srv6 = zebra_srv6_get_default();
struct zserv *client; 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 * by ZEBRA_SRV6_LOCATOR_DELETE, and this notification is sent to the
* owner of each chunk. * 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); zsend_zebra_srv6_locator_delete(client, locator);
}
listnode_delete(srv6->locators, locator); listnode_delete(srv6->locators, locator);
srv6_locator_free(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) void zebra_notify_srv6_locator_add(struct srv6_locator *locator)
{ {
struct listnode *node;
struct zserv *client; 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 * frequently than adding rib entries, so a broad to all zclients will
* not degrade the overall performance of FRRouting. * 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); zsend_zebra_srv6_locator_add(client, locator);
}
} }
void zebra_notify_srv6_locator_delete(struct srv6_locator *locator) void zebra_notify_srv6_locator_delete(struct srv6_locator *locator)
{ {
struct listnode *n;
struct zserv *client; 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 * by ZEBRA_SRV6_LOCATOR_DELETE, and this notification is sent to the
* owner of each chunk. * 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); zsend_zebra_srv6_locator_delete(client, locator);
}
} }
struct zebra_srv6 srv6; struct zebra_srv6 srv6;

View file

@ -484,14 +484,10 @@ DEFPY (locator_prefix,
if (memcmp(&chunk->prefix.prefix, zero, 16) == 0) { if (memcmp(&chunk->prefix.prefix, zero, 16) == 0) {
struct zserv *client; struct zserv *client;
struct listnode *client_node;
chunk->prefix = *prefix; chunk->prefix = *prefix;
for (ALL_LIST_ELEMENTS_RO(zrouter.client_list, frr_each (zserv_client_list, &zrouter.client_list, client) {
client_node,
client)) {
struct srv6_locator *tmp; struct srv6_locator *tmp;
if (client->proto != chunk->proto) if (client->proto != chunk->proto)
continue; continue;

View file

@ -45,13 +45,12 @@ DEFINE_MTYPE_STATIC(ZEBRA, OTHER_TABLE, "Other Table");
/* VRF information update. */ /* VRF information update. */
static void zebra_vrf_add_update(struct zebra_vrf *zvrf) static void zebra_vrf_add_update(struct zebra_vrf *zvrf)
{ {
struct listnode *node, *nnode;
struct zserv *client; struct zserv *client;
if (IS_ZEBRA_DEBUG_EVENT) if (IS_ZEBRA_DEBUG_EVENT)
zlog_debug("MESSAGE: ZEBRA_VRF_ADD %s", zvrf_name(zvrf)); 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. */ /* Do not send unsolicited messages to synchronous clients. */
if (client->synchronous) if (client->synchronous)
continue; 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) static void zebra_vrf_delete_update(struct zebra_vrf *zvrf)
{ {
struct listnode *node, *nnode;
struct zserv *client; struct zserv *client;
if (IS_ZEBRA_DEBUG_EVENT) if (IS_ZEBRA_DEBUG_EVENT)
zlog_debug("MESSAGE: ZEBRA_VRF_DELETE %s", zvrf_name(zvrf)); 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. */ /* Do not send unsolicited messages to synchronous clients. */
if (client->synchronous) if (client->synchronous)
continue; continue;

View file

@ -23,7 +23,6 @@
#include "lib/buffer.h" /* for BUFFER_EMPTY, BUFFER_ERROR, BUFFE... */ #include "lib/buffer.h" /* for BUFFER_EMPTY, BUFFER_ERROR, BUFFE... */
#include "lib/command.h" /* for vty, install_element, CMD_SUCCESS... */ #include "lib/command.h" /* for vty, install_element, CMD_SUCCESS... */
#include "lib/hook.h" /* for DEFINE_HOOK, DEFINE_KOOH, hook_call */ #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/libfrr.h" /* for frr_zclient_addr */
#include "lib/log.h" /* for zlog_warn, zlog_debug, safe_strerror */ #include "lib/log.h" /* for zlog_warn, zlog_debug, safe_strerror */
#include "lib/memory.h" /* for MTYPE_TMP, XCALLOC, XFREE */ #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) { frr_with_mutex (&client_mutex) {
if (client->busy_count <= 0) { if (client->busy_count <= 0) {
/* remove from client list */ /* remove from client list */
listnode_delete(zrouter.client_list, client); zserv_client_list_del(&zrouter.client_list, client);
} else { } else {
/* /*
* The client session object may be in use, although * 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. */ /* Add this client to linked list. */
frr_with_mutex (&client_mutex) { 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 = { struct frr_pthread_attr zclient_pthr_attrs = {
@ -1311,10 +1310,9 @@ static struct zserv *find_client_internal(uint8_t proto,
unsigned short instance, unsigned short instance,
uint32_t session_id) uint32_t session_id)
{ {
struct listnode *node, *nnode;
struct zserv *client = NULL; 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 && if (client->proto == proto && client->instance == instance &&
client->session_id == session_id) client->session_id == session_id)
break; break;
@ -1362,10 +1360,9 @@ DEFUN (show_zebra_client,
ZEBRA_STR ZEBRA_STR
"Client information\n") "Client information\n")
{ {
struct listnode *node;
struct zserv *client; 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); zebra_show_client_detail(vty, client);
/* Show GR info if present */ /* Show GR info if present */
zebra_show_stale_client_detail(vty, client); zebra_show_stale_client_detail(vty, client);
@ -1383,7 +1380,6 @@ DEFUN (show_zebra_client_summary,
"Client information brief\n" "Client information brief\n"
"Brief Summary\n") "Brief Summary\n")
{ {
struct listnode *node;
struct zserv *client; struct zserv *client;
vty_out(vty, vty_out(vty,
@ -1391,7 +1387,7 @@ DEFUN (show_zebra_client_summary,
vty_out(vty, vty_out(vty,
"------------------------------------------------------------------------------------------\n"); "------------------------------------------------------------------------------------------\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); zebra_show_client_brief(vty, client);
vty_out(vty, "Routes column shows (added+updated)/deleted\n"); 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) static int zserv_client_close_cb(struct zserv *closed_client)
{ {
struct listnode *node, *nnode;
struct zserv *client = NULL; 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) if (client->proto == closed_client->proto)
continue; continue;
@ -1416,7 +1411,7 @@ static int zserv_client_close_cb(struct zserv *closed_client)
void zserv_init(void) void zserv_init(void)
{ {
/* Client list init. */ /* Client list init. */
zrouter.client_list = list_new(); zserv_client_list_init(&zrouter.client_list);
zrouter.stale_client_list = list_new(); zrouter.stale_client_list = list_new();
/* Misc init. */ /* Misc init. */

View file

@ -70,6 +70,9 @@ struct client_gr_info {
TAILQ_ENTRY(client_gr_info) gr_info; TAILQ_ENTRY(client_gr_info) gr_info;
}; };
/* For managing client list */
PREDECL_LIST(zserv_client_list);
/* Client structure. */ /* Client structure. */
struct zserv { struct zserv {
/* Client pthread */ /* Client pthread */
@ -86,6 +89,9 @@ struct zserv {
int busy_count; int busy_count;
bool is_closed; 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. */ /* Input/output buffer to the client. */
pthread_mutex_t ibuf_mtx; pthread_mutex_t ibuf_mtx;
struct stream_fifo *ibuf_fifo; struct stream_fifo *ibuf_fifo;
@ -230,6 +236,9 @@ struct zserv {
TAILQ_HEAD(info_list, client_gr_info) gr_info_queue; 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 \ #define ZAPI_HANDLER_ARGS \
struct zserv *client, struct zmsghdr *hdr, struct stream *msg, \ struct zserv *client, struct zmsghdr *hdr, struct stream *msg, \
struct zebra_vrf *zvrf struct zebra_vrf *zvrf