This list should just be a typesafe list.
Signed-off-by: Donald Sharp <donaldsharp72@gmail.com>
{
struct vrf *vrf;
struct zebra_vrf *zvrf;
- struct listnode *ln, *nn;
struct zserv *client;
static bool sigint_done;
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();
rib_update_finish();
- list_delete(&zrouter.client_list);
list_delete(&zrouter.stale_client_list);
/*
ns_walk_func(zebra_ns_final_shutdown, NULL, NULL);
ns_terminate();
+
+ zserv_client_list_fini(&zrouter.client_list);
+
frr_fini();
exit(0);
}
const struct route_entry *re,
const struct route_entry *prev_re)
{
- struct listnode *node, *nnode;
struct zserv *client;
if (IS_ZEBRA_DEBUG_RIB)
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(
const struct route_entry *old_re,
const struct route_entry *new_re)
{
- struct listnode *node, *nnode;
struct zserv *client;
vrf_id_t vrfid;
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;
/* Interface up information. */
void zebra_interface_up_update(struct interface *ifp)
{
- struct listnode *node, *nnode;
struct zserv *client;
if (IS_ZEBRA_DEBUG_EVENT)
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.
*/
/* 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;
/* 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;
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;
void zebra_interface_address_add_update(struct interface *ifp,
struct connected *ifc)
{
- struct listnode *node, *nnode;
struct zserv *client;
if (IS_ZEBRA_DEBUG_EVENT)
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;
void zebra_interface_address_delete_update(struct interface *ifp,
struct connected *ifc)
{
- struct listnode *node, *nnode;
struct zserv *client;
if (IS_ZEBRA_DEBUG_EVENT)
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;
*/
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;
*/
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;
/* 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;
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);
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;
void router_id_add_address(struct connected *ifc)
{
struct list *l = NULL;
- struct listnode *node;
struct prefix before;
struct prefix after;
struct zserv *client;
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));
}
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;
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));
}
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;
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;
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;
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;
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;
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;
}
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;
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;
}
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;
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;
}
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;
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;
}
union sockunion *link_layer_ipv4, int ip_len)
{
struct stream *s;
- struct listnode *node, *nnode;
struct zserv *client;
afi_t afi;
union sockunion ip;
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;
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;
{
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;
__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,
*/
static void zebra_ptm_send_bfdd(struct stream *msg)
{
- struct listnode *node;
struct zserv *client;
struct stream *msgc;
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;
static void zebra_ptm_send_clients(struct stream *msg)
{
- struct listnode *node;
struct zserv *client;
struct stream *msgc;
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;
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;
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;
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;
{
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);
* 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;
* 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);
void zebra_notify_srv6_locator_add(struct srv6_locator *locator)
{
- struct listnode *node;
struct zserv *client;
/*
* 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;
/*
* 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;
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;
/* 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;
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;
#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 */
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
/* 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 = {
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;
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);
"Client information brief\n"
"Brief Summary\n")
{
- struct listnode *node;
struct zserv *client;
vty_out(vty,
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");
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;
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. */
TAILQ_ENTRY(client_gr_info) gr_info;
};
+/* For managing client list */
+PREDECL_LIST(zserv_client_list);
+
/* Client structure. */
struct zserv {
/* Client pthread */
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;
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