zebra: Rework the stale client list to a typesafe list

The stale client list was just a linked list, let's use
the typesafe list.

Signed-off-by: Donald Sharp <donaldsharp72@gmail.com>
This commit is contained in:
Donald Sharp 2025-03-16 18:43:25 -04:00 committed by Donald Sharp
parent 24d293277f
commit 4d6f5c7e27
5 changed files with 17 additions and 24 deletions

View file

@ -162,8 +162,7 @@ static void sigint(void)
zebra_dplane_pre_finish();
/* Clean up GR related info. */
zebra_gr_stale_client_cleanup(zrouter.stale_client_list);
list_delete_all_node(zrouter.stale_client_list);
zebra_gr_stale_client_cleanup();
/* Clean up zapi clients and server module */
frr_each_safe (zserv_client_list, &zrouter.client_list, client)
@ -200,8 +199,6 @@ static void sigint(void)
rib_update_finish();
list_delete(&zrouter.stale_client_list);
/*
* Besides other clean-ups zebra's vrf_disable() also enqueues installed
* routes for removal from the kernel, unless ZEBRA_VRF_RETAIN is set.
@ -255,6 +252,7 @@ void zebra_finalize(struct event *dummy)
ns_terminate();
zserv_client_list_fini(&zrouter.client_list);
zserv_stale_client_list_fini(&zrouter.stale_client_list);
frr_fini();
exit(0);

View file

@ -62,15 +62,13 @@ static void zebra_gr_delete_stale_route_table_afi(struct event *event);
* function will also clean up all per instance
* capabilities that are exchanged.
*/
void zebra_gr_stale_client_cleanup(struct list *client_list)
void zebra_gr_stale_client_cleanup(void)
{
struct listnode *node, *nnode;
struct zserv *s_client = NULL;
struct client_gr_info *info, *ninfo;
/* Find the stale client */
for (ALL_LIST_ELEMENTS(client_list, node, nnode, s_client)) {
frr_each_safe (zserv_stale_client_list, &zrouter.stale_client_list, s_client) {
LOG_GR("%s: Stale client %s is being deleted", __func__,
zebra_route_string(s_client->proto));
@ -173,7 +171,7 @@ int32_t zebra_gr_client_disconnect(struct zserv *client)
}
}
listnode_add(zrouter.stale_client_list, client);
zserv_stale_client_list_add_tail(&zrouter.stale_client_list, client);
return 0;
}
@ -215,7 +213,7 @@ static void zebra_gr_delete_stale_client(struct client_gr_info *info)
info->vrf_id);
TAILQ_INIT(&(s_client->gr_info_queue));
listnode_delete(zrouter.stale_client_list, s_client);
zserv_stale_client_list_del(&zrouter.stale_client_list, s_client);
if (info->stale_client)
zserv_client_delete(s_client);
XFREE(MTYPE_ZEBRA_GR, info);
@ -226,12 +224,10 @@ static void zebra_gr_delete_stale_client(struct client_gr_info *info)
*/
static struct zserv *zebra_gr_find_stale_client(struct zserv *client)
{
struct listnode *node, *nnode;
struct zserv *stale_client;
/* Find the stale client */
for (ALL_LIST_ELEMENTS(zrouter.stale_client_list, node, nnode,
stale_client)) {
frr_each (zserv_stale_client_list, &zrouter.stale_client_list, stale_client) {
if (client->proto == stale_client->proto
&& client->instance == stale_client->instance) {
return stale_client;
@ -246,17 +242,11 @@ static struct zserv *zebra_gr_find_stale_client(struct zserv *client)
*/
void zebra_gr_client_reconnect(struct zserv *client)
{
struct listnode *node, *nnode;
struct zserv *old_client = NULL;
struct client_gr_info *info = NULL;
/* Find the stale client */
for (ALL_LIST_ELEMENTS(zrouter.stale_client_list, node, nnode,
old_client)) {
if (client->proto == old_client->proto
&& client->instance == old_client->instance)
break;
}
old_client = zebra_gr_find_stale_client(client);
/* Copy the timers */
if (!old_client)
@ -281,7 +271,7 @@ void zebra_gr_client_reconnect(struct zserv *client)
}
/* Delete the stale client */
listnode_delete(zrouter.stale_client_list, old_client);
zserv_stale_client_list_del(&zrouter.stale_client_list, old_client);
/* Delete old client */
zserv_client_delete(old_client);
}

View file

@ -129,7 +129,7 @@ struct zebra_router {
struct zserv_client_list_head client_list;
/* List of clients in GR */
struct list *stale_client_list;
struct zserv_stale_client_list_head stale_client_list;
struct zebra_router_table_head tables;

View file

@ -1412,7 +1412,7 @@ void zserv_init(void)
{
/* Client list init. */
zserv_client_list_init(&zrouter.client_list);
zrouter.stale_client_list = list_new();
zserv_stale_client_list_init(&zrouter.stale_client_list);
/* Misc init. */
zsock = -1;

View file

@ -72,6 +72,7 @@ struct client_gr_info {
/* For managing client list */
PREDECL_LIST(zserv_client_list);
PREDECL_LIST(zserv_stale_client_list);
/* Client structure. */
struct zserv {
@ -92,6 +93,9 @@ struct zserv {
/* For managing this node in the client list */
struct zserv_client_list_item client_list_entry;
/* For managing this node in the stale client list */
struct zserv_stale_client_list_item stale_client_list_entry;
/* Input/output buffer to the client. */
pthread_mutex_t ibuf_mtx;
struct stream_fifo *ibuf_fifo;
@ -238,6 +242,7 @@ struct zserv {
/* Declare the list operations */
DECLARE_LIST(zserv_client_list, struct zserv, client_list_entry);
DECLARE_LIST(zserv_stale_client_list, struct zserv, stale_client_list_entry);
#define ZAPI_HANDLER_ARGS \
struct zserv *client, struct zmsghdr *hdr, struct stream *msg, \
@ -404,7 +409,7 @@ __attribute__((__noreturn__)) void zebra_finalize(struct event *event);
extern void zebra_gr_client_final_shutdown(struct zserv *client);
extern int zebra_gr_client_disconnect(struct zserv *client);
extern void zebra_gr_client_reconnect(struct zserv *client);
extern void zebra_gr_stale_client_cleanup(struct list *client_list);
extern void zebra_gr_stale_client_cleanup(void);
extern void zread_client_capabilities(struct zserv *client, struct zmsghdr *hdr,
struct stream *msg,
struct zebra_vrf *zvrf);