From 298e6c5e8f2aa73e7d69af4c6dd33d4194701bbc Mon Sep 17 00:00:00 2001 From: Arran Cudbard-Bell Date: Thu, 9 May 2024 23:21:10 -0600 Subject: [PATCH] Use new thread-local list for client connections --- src/lib/io/master.c | 29 ++++++++++++++++++++++------- src/lib/io/master.h | 5 ++++- 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/src/lib/io/master.c b/src/lib/io/master.c index c52e99b004cdf..8f69b0d8e1437 100644 --- a/src/lib/io/master.c +++ b/src/lib/io/master.c @@ -143,7 +143,7 @@ struct fr_io_connection_s { fr_listen_t *child; //!< child listener (app_io) for this socket fr_io_client_t *client; //!< our local client (pending or connected). fr_io_client_t *parent; //!< points to the parent client. - module_instance_t *mi; //!< for submodule + module_instance_t *mi; //!< for submodule bool dead; //!< roundabout way to get the network side to close a socket bool paused; //!< event filter doesn't like resuming something that isn't paused @@ -493,7 +493,6 @@ static fr_io_connection_t *fr_io_connection_alloc(fr_io_instance_t const *inst, */ if (!nak) { char *inst_name; - char const *transport_name = inst->submodule->module->exported->name; if (inst->max_connections || client->radclient->limit.max_connections) { uint32_t max_connections = inst->max_connections ? inst->max_connections : client->radclient->limit.max_connections; @@ -518,17 +517,27 @@ static fr_io_connection_t *fr_io_connection_alloc(fr_io_instance_t const *inst, } /* - * FIXME - This should a 'sub' module list + * Add a client module into a sublist */ - inst_name = talloc_asprintf(NULL, "%s%"PRIu64, transport_name, thread->client_id++); - mi = module_instance_alloc(inst->submodule->ml, inst->submodule, DL_MODULE_TYPE_SUBMODULE, - inst->submodule->module->exported->name, inst_name); + inst_name = talloc_asprintf(NULL, "%"PRIu64, thread->client_id++); + mi = module_instance_copy(inst->clients, inst->submodule, inst_name); - if (module_instance_conf_parse(mi, inst->server_cs) < 0) { + if (module_instance_conf_parse(mi, inst->submodule->conf) < 0) { cf_log_perr(inst->server_cs, "Failed parsing module config"); goto cleanup; } + /* Thread local module lists never run bootstrap */ + if (module_instantiate(mi) < 0) { + cf_log_perr(inst->server_cs, "Failed instantiating module"); + goto cleanup; + } + + if (module_thread_instantiate(mi, mi, thread->el) < 0) { + cf_log_perr(inst->server_cs, "Failed instantiating module"); + goto cleanup; + } + /* * FIXME - Instantiate the new module?! */ @@ -2695,6 +2704,12 @@ static int mod_bootstrap(module_inst_ctx_t const *mctx) } } + /* + * Create a list of client modules. + * + * FIXME - Probably only want to do this for connected sockets? + */ + inst->clients = module_list_alloc(inst, &module_list_type_thread_local, "clients"); return 0; } diff --git a/src/lib/io/master.h b/src/lib/io/master.h index 6ea7ae0b52d0b..fef64cb3c91e9 100644 --- a/src/lib/io/master.h +++ b/src/lib/io/master.h @@ -70,7 +70,10 @@ typedef struct fr_io_track_s { * creates the listener, and adds it to the scheduler. */ typedef struct { - module_instance_t const *mi; //!< our parent mi + module_instance_t const *mi; //!< our parent mi + module_list_t *clients; //!< Holds client modules created to represent + ///< sockets created as clients connect to the + ///< listener. uint32_t max_connections; //!< maximum number of connections to allow uint32_t max_clients; //!< maximum number of dynamic clients to allow