From 532711c7a8735c2b3e728f7b8ce50dff6db9b2c7 Mon Sep 17 00:00:00 2001 From: Arran Cudbard-Bell Date: Thu, 7 Apr 2022 14:34:27 -0500 Subject: [PATCH] Use the standard instantiate bootstrap callbacks for proto and proc modules --- src/lib/io/app_io.c | 8 +- src/lib/io/app_io.h | 5 +- src/lib/io/application.h | 38 +-------- src/lib/io/master.c | 107 ++++++++++++------------ src/lib/io/network.c | 2 +- src/lib/server/virtual_servers.c | 14 ++-- src/listen/arp/proto_arp.c | 52 ++++++------ src/listen/arp/proto_arp_ethernet.c | 21 ++--- src/listen/control/proto_control.c | 32 ++++--- src/listen/control/proto_control_unix.c | 26 +++--- src/listen/cron/proto_cron.c | 33 ++++---- src/listen/cron/proto_cron_crontab.c | 35 ++++---- src/listen/detail/proto_detail.c | 62 +++++++------- src/listen/detail/proto_detail_file.c | 43 +++++----- src/listen/detail/proto_detail_work.c | 28 ++++--- src/listen/dhcpv4/proto_dhcpv4.c | 40 +++++---- src/listen/dhcpv4/proto_dhcpv4_udp.c | 42 +++++----- src/listen/dhcpv6/proto_dhcpv6.c | 39 ++++----- src/listen/dhcpv6/proto_dhcpv6_udp.c | 44 +++++----- src/listen/dns/proto_dns.c | 40 +++++---- src/listen/dns/proto_dns_udp.c | 30 +++---- src/listen/load/proto_load.c | 34 ++++---- src/listen/load/proto_load_step.c | 36 ++++---- src/listen/radius/proto_radius.c | 37 ++++---- src/listen/radius/proto_radius_tcp.c | 50 +++++------ src/listen/radius/proto_radius_udp.c | 34 ++++---- src/listen/tacacs/proto_tacacs.c | 38 ++++----- src/listen/tacacs/proto_tacacs_tcp.c | 34 ++++---- src/listen/vmps/proto_vmps.c | 37 ++++---- src/listen/vmps/proto_vmps_udp.c | 34 ++++---- 30 files changed, 520 insertions(+), 555 deletions(-) diff --git a/src/lib/io/app_io.c b/src/lib/io/app_io.c index e36d8724fc..5ea8727e96 100644 --- a/src/lib/io/app_io.c +++ b/src/lib/io/app_io.c @@ -53,20 +53,20 @@ char const *fr_app_io_socket_name(TALLOC_CTX *ctx, fr_app_io_t const *app_io, if (!interface) { if (!src_ipaddr) { return talloc_typed_asprintf(ctx, "%s server %s port %u", - app_io->name, dst_buf, dst_port); + app_io->common.name, dst_buf, dst_port); } return talloc_typed_asprintf(ctx, "%s from client %s port %u to server %s port %u", - app_io->name, src_buf, src_port, dst_buf, dst_port); + app_io->common.name, src_buf, src_port, dst_buf, dst_port); } if (!src_ipaddr) { return talloc_typed_asprintf(ctx, "%s server %s port %u on interface %s", - app_io->name, dst_buf, dst_port, interface); + app_io->common.name, dst_buf, dst_port, interface); } return talloc_typed_asprintf(ctx, "%s from client %s port %u to server %s port %u on interface %s", - app_io->name, src_buf, src_port, dst_buf, dst_port, interface); + app_io->common.name, src_buf, src_port, dst_buf, dst_port, interface); } diff --git a/src/lib/io/app_io.h b/src/lib/io/app_io.h index f57db729c0..16d0a9c790 100644 --- a/src/lib/io/app_io.h +++ b/src/lib/io/app_io.h @@ -31,16 +31,13 @@ * This structure is exported by I/O modules e.g. proto_radius_udp. */ typedef struct { - DL_MODULE_COMMON; //!< Common fields to all loadable modules. + module_t common; //!< Common fields to all loadable modules. - fr_app_bootstrap_t bootstrap; - fr_app_instantiate_t instantiate; fr_app_event_list_set_t event_list_set; //!< Called by the network thread to pass an event list //!< for use by the app_io_t. size_t default_message_size; //!< Usually maximum message size size_t default_reply_size; //!< same for replies - size_t thread_inst_size; //!< thread-specific socket information size bool track_duplicates; //!< track duplicate packets fr_io_open_t open; //!< Open a new socket for listening, or accept/connect a new diff --git a/src/lib/io/application.h b/src/lib/io/application.h index 6cffaf4984..2af8079411 100644 --- a/src/lib/io/application.h +++ b/src/lib/io/application.h @@ -33,31 +33,6 @@ */ typedef struct fr_schedule_s fr_schedule_t; -/** Bootstrap the #fr_app_t - * - * Primarily used to allow the #fr_app_t to load its submodules. - * - * @param[in] instance of the #fr_app_t. - * @param[in] cs of the listen section that created this #fr_app_t. - * @return - * - 0 on success. - * - <0 on failure. - */ -typedef int (*fr_app_bootstrap_t)( void *instance, CONF_SECTION *cs); - -/** Instantiate the #fr_app_t - * - * Primarily used to allow the #fr_app_t to validate its config - * and to allow its submodules to validate their configurations. - * - * @param[in] instance of the #fr_app_t. - * @param[in] cs of the listen section that created this #fr_app_t. - * @return - * - 0 on success. - * - <0 on failure. - */ -typedef int (*fr_app_instantiate_t)(void *instance, CONF_SECTION *cs); - /** Open a new socket or other packet source * * @param[in] instance of the #fr_app_t. @@ -94,16 +69,10 @@ typedef void (*fr_app_event_list_set_t)(fr_listen_t *li, fr_event_list_t *el, vo * How the fr_app_t operates is specific to each protocol. */ typedef struct { - DL_MODULE_COMMON; //!< Common fields to all loadable modules. + module_t common; //!< Common fields provided by all modules. fr_dict_t const **dict; //!< default dictionary for this application. - fr_app_bootstrap_t bootstrap; //!< Bootstrap function to allow the fr_app_t to load the - ///< various submodules it requires. - - fr_app_instantiate_t instantiate; //!< Instantiate function to perform config validation and - ///< massaging. - fr_app_open_t open; //!< Callback to allow the #fr_app_t to build an #fr_listen_t ///< and register it with the scheduler so we can receive ///< data. @@ -127,10 +96,7 @@ typedef struct { * the packet after its been decoded. */ typedef struct { - DL_MODULE_COMMON; //!< Common fields to all loadable modules. - - fr_app_bootstrap_t bootstrap; - fr_app_instantiate_t instantiate; + module_t common; //!< Common fields to all loadable modules. module_method_t entry_point; //!< Entry point into the protocol subtype's state machine. virtual_server_compile_t const *compile_list; //!< list of processing sections } fr_app_worker_t; diff --git a/src/lib/io/master.c b/src/lib/io/master.c index e802e5f3ac..47e0150b67 100644 --- a/src/lib/io/master.c +++ b/src/lib/io/master.c @@ -496,7 +496,7 @@ static fr_io_connection_t *fr_io_connection_alloc(fr_io_instance_t const *inst, } if (dl_module_instance(NULL, &dl_inst, NULL, inst->dl_inst, inst->transport, DL_MODULE_TYPE_SUBMODULE) < 0) { - DEBUG("Failed to find proto_%s_%s", inst->app->name, inst->transport); + DEBUG("Failed to find proto_%s_%s", inst->app->common.name, inst->transport); return NULL; } @@ -636,10 +636,10 @@ static fr_io_connection_t *fr_io_connection_alloc(fr_io_instance_t const *inst, * Create writable thread instance data. */ connection->child->thread_instance = talloc_zero_array(NULL, uint8_t, - inst->app_io->thread_inst_size); + inst->app_io->common.thread_inst_size); talloc_set_destructor(connection->child, fr_io_listen_free); talloc_set_name(connection->child->thread_instance, "proto_%s_thread_t", - inst->app_io->name); + inst->app_io->common.name); /* * This is "const", and the user can't @@ -721,7 +721,7 @@ static fr_io_connection_t *fr_io_connection_alloc(fr_io_instance_t const *inst, * Set the new FD, and get the module to set it's connection name. */ if (inst->app_io->fd_set(connection->child, fd) < 0) { - DEBUG3("Failed setting FD to %s", inst->app_io->name); + DEBUG3("Failed setting FD to %s", inst->app_io->common.name); close(fd); return NULL; } @@ -731,7 +731,7 @@ static fr_io_connection_t *fr_io_connection_alloc(fr_io_instance_t const *inst, if (!inst->app_io->get_name) { connection->name = fr_asprintf(connection, "proto_%s from client %pV port " "%u to server %pV port %u", - inst->app_io->name, + inst->app_io->common.name, fr_box_ipaddr(connection->address->socket.inet.src_ipaddr), connection->address->socket.inet.src_port, fr_box_ipaddr(connection->address->socket.inet.dst_ipaddr), @@ -761,7 +761,7 @@ static fr_io_connection_t *fr_io_connection_alloc(fr_io_instance_t const *inst, if (!ret) { ERROR("proto_%s - Failed inserting connection into tracking table. " "Closing it, and discarding all packets for connection %s.", - inst->app_io->name, connection->name); + inst->app_io->common.name, connection->name); goto cleanup; } } @@ -777,12 +777,12 @@ static fr_io_connection_t *fr_io_connection_alloc(fr_io_instance_t const *inst, return connection; } - DEBUG("proto_%s - starting connection %s", inst->app_io->name, connection->name); + DEBUG("proto_%s - starting connection %s", inst->app_io->common.name, connection->name); connection->nr = fr_schedule_listen_add(thread->sc, connection->listen); if (!connection->nr) { ERROR("proto_%s - Failed inserting connection into scheduler. " "Closing it, and diuscarding all packets for connection %s.", - inst->app_io->name, connection->name); + inst->app_io->common.name, connection->name); pthread_mutex_lock(&client->mutex); (void) fr_hash_table_delete(client->ht, connection); pthread_mutex_unlock(&client->mutex); @@ -1231,7 +1231,7 @@ redo: */ if (accept_fd < 0) { DEBUG("proto_%s_%s - failed to accept new socket: %s", - inst->app->name, inst->transport, fr_syserror(errno)); + inst->app->common.name, inst->transport, fr_syserror(errno)); return 0; } @@ -1307,7 +1307,7 @@ do_read: * listener? */ DEBUG2("proto_%s - ignoring packet from IP %pV. It is not configured as 'type = ...'", - inst->app_io->name, fr_box_ipaddr(address.socket.inet.src_ipaddr)); + inst->app_io->common.name, fr_box_ipaddr(address.socket.inet.src_ipaddr)); return 0; } *priority = value; @@ -1390,11 +1390,11 @@ do_read: if (accept_fd < 0) { DEBUG("proto_%s - ignoring packet from client IP address %pV - " "too many dynamic clients are defined", - inst->app_io->name, fr_box_ipaddr(address.socket.inet.src_ipaddr)); + inst->app_io->common.name, fr_box_ipaddr(address.socket.inet.src_ipaddr)); } else { DEBUG("proto_%s - ignoring connection attempt from client IP address %pV " "- too many dynamic clients are defined", - inst->app_io->name, fr_box_ipaddr(address.socket.inet.src_ipaddr)); + inst->app_io->common.name, fr_box_ipaddr(address.socket.inet.src_ipaddr)); close(accept_fd); } return 0; @@ -1423,10 +1423,10 @@ do_read: ignore: if (accept_fd < 0) { DEBUG("proto_%s - ignoring packet from unknown client IP address %pV", - inst->app_io->name, fr_box_ipaddr(address.socket.inet.src_ipaddr)); + inst->app_io->common.name, fr_box_ipaddr(address.socket.inet.src_ipaddr)); } else { DEBUG("proto_%s - ignoring connection attempt from unknown client IP address %pV", - inst->app_io->name, fr_box_ipaddr(address.socket.inet.src_ipaddr)); + inst->app_io->common.name, fr_box_ipaddr(address.socket.inet.src_ipaddr)); close(accept_fd); } return 0; @@ -1498,7 +1498,7 @@ do_read: */ if (fr_trie_insert_by_key(thread->trie, &client->src_ipaddr.addr, client->src_ipaddr.prefix, client)) { ERROR("proto_%s - Failed inserting client %s into tracking table. Discarding client, and all packets for it.", - inst->app_io->name, client->radclient->shortname); + inst->app_io->common.name, client->radclient->shortname); talloc_free(client); if (accept_fd >= 0) close(accept_fd); return -1; @@ -1814,7 +1814,7 @@ static int mod_open(fr_listen_t *li) * Set the name of the socket. */ if (!li->app_io->get_name) { - li->name = li->app_io->name; + li->name = li->app_io->common.name; } else { li->name = li->app_io->get_name(li); } @@ -2032,9 +2032,9 @@ idle_timeout: */ if (client->ready_to_delete) { if (connection) { - DEBUG("proto_%s - idle timeout for connection %s", inst->app_io->name, connection->name); + DEBUG("proto_%s - idle timeout for connection %s", inst->app_io->common.name, connection->name); } else { - DEBUG("proto_%s - idle timeout for client %s", inst->app_io->name, client->radclient->shortname); + DEBUG("proto_%s - idle timeout for client %s", inst->app_io->common.name, client->radclient->shortname); } goto delete_client; } @@ -2064,7 +2064,7 @@ reset_timer: if (fr_event_timer_in(client, el, &client->ev, delay, client_expiry_timer, client) < 0) { ERROR("proto_%s - Failed adding timeout for dynamic client %s. It will be permanent!", - inst->app_io->name, client->radclient->shortname); + inst->app_io->common.name, client->radclient->shortname); return; } @@ -2099,13 +2099,13 @@ static void packet_expiry_timer(fr_event_list_t *el, fr_time_t now, void *uctx) */ if (fr_event_timer_at(track, el, &track->ev, track->expires, packet_expiry_timer, track) == 0) { - DEBUG("proto_%s - cleaning up request in %.6fs", inst->app_io->name, + DEBUG("proto_%s - cleaning up request in %.6fs", inst->app_io->common.name, fr_time_delta_unwrap(inst->cleanup_delay) / (double)NSEC); return; } DEBUG("proto_%s - Failed adding cleanup_delay for packet. Discarding packet immediately", - inst->app_io->name); + inst->app_io->common.name); } /* @@ -2113,9 +2113,9 @@ static void packet_expiry_timer(fr_event_list_t *el, fr_time_t now, void *uctx) * timeout ones. */ if (fr_time_neq(now, fr_time_wrap(0))) { - DEBUG2("TIMER - proto_%s - cleanup delay", inst->app_io->name); + DEBUG2("TIMER - proto_%s - cleanup delay", inst->app_io->common.name); } else { - DEBUG2("proto_%s - cleaning up", inst->app_io->name); + DEBUG2("proto_%s - cleaning up", inst->app_io->common.name); } /* @@ -2439,7 +2439,7 @@ static ssize_t mod_write(fr_listen_t *li, void *packet_ctx, fr_time_t request_ti */ if (radclient->use_connected && !inst->app_io->connection_set) { DEBUG("proto_%s - cannot use connected sockets as underlying 'transport = %s' does not support it.", - inst->app_io->name, inst->transport); + inst->app_io->common.name, inst->transport); goto error; } @@ -2550,9 +2550,10 @@ static int mod_close(fr_listen_t *li) } -static int mod_bootstrap(void *instance, CONF_SECTION *cs) +static int mod_bootstrap(module_inst_ctx_t const *mctx) { - fr_io_instance_t *inst = instance; + fr_io_instance_t *inst = mctx->inst->data; + CONF_SECTION *conf = mctx->inst->conf; /* * Find and bootstrap the application IO handler. @@ -2580,9 +2581,8 @@ static int mod_bootstrap(void *instance, CONF_SECTION *cs) } } - if (inst->app_io->bootstrap && (inst->app_io->bootstrap(inst->app_io_instance, - inst->app_io_conf) < 0)) { - cf_log_err(inst->app_io_conf, "Bootstrap failed for proto_%s", inst->app_io->name); + if (inst->app_io->common.bootstrap && (inst->app_io->common.bootstrap(MODULE_INST_CTX(inst->submodule)) < 0)) { + cf_log_err(inst->app_io_conf, "Bootstrap failed for proto_%s", inst->app_io->common.name); return -1; } @@ -2601,9 +2601,9 @@ static int mod_bootstrap(void *instance, CONF_SECTION *cs) /* * Load proto_dhcpv4_dynamic_client */ - if (dl_module_instance(cs, &inst->dynamic_submodule, - cs, inst->dl_inst, "dynamic_client", DL_MODULE_TYPE_SUBMODULE) < 0) { - cf_log_err(cs, "Failed finding proto_%s_dynamic_client", inst->app->name); + if (dl_module_instance(conf, &inst->dynamic_submodule, + conf, inst->dl_inst, "dynamic_client", DL_MODULE_TYPE_SUBMODULE) < 0) { + cf_log_err(conf, "Failed finding proto_%s_dynamic_client", inst->app->common.name); return -1; } @@ -2624,7 +2624,7 @@ static int mod_bootstrap(void *instance, CONF_SECTION *cs) } if (inst->ipproto && !inst->app_io->connection_set) { - cf_log_err(inst->app_io_conf, "Cannot set TCP for proto_%s - internal set error", inst->app_io->name); + cf_log_err(inst->app_io_conf, "Cannot set TCP for proto_%s - internal set error", inst->app_io->common.name); return -1; } @@ -2646,16 +2646,16 @@ static char const *mod_name(fr_listen_t *li) } -static int mod_instantiate(void *instance, CONF_SECTION *conf) +static int mod_instantiate(module_inst_ctx_t const *mctx) { - fr_io_instance_t *inst = instance; + fr_io_instance_t *inst = mctx->inst->data; + CONF_SECTION *conf = mctx->inst->conf; fr_assert(inst->app_io != NULL); - if (inst->app_io->instantiate && - (inst->app_io->instantiate(inst->app_io_instance, - inst->app_io_conf) < 0)) { - cf_log_err(conf, "Instantiation failed for \"proto_%s\"", inst->app_io->name); + if (inst->app_io->common.instantiate && + (inst->app_io->common.instantiate(MODULE_INST_CTX(inst->submodule)) < 0)) { + cf_log_err(conf, "Instantiation failed for \"proto_%s\"", inst->app_io->common.name); return -1; } @@ -2666,7 +2666,7 @@ static int mod_instantiate(void *instance, CONF_SECTION *conf) fr_app_worker_t const *app_process; if (!inst->dynamic_submodule) { - cf_log_err(conf, "Instantiation failed for \"proto_%s\" - there is no way to define dynamic clients", inst->app_io->name); + cf_log_err(conf, "Instantiation failed for \"proto_%s\" - there is no way to define dynamic clients", inst->app_io->common.name); return -1; } @@ -2692,8 +2692,8 @@ static int mod_instantiate(void *instance, CONF_SECTION *conf) }; } - if (app_process->instantiate && (app_process->instantiate(inst->dynamic_submodule->data, conf) < 0)) { - cf_log_err(conf, "Instantiation failed for \"%s\"", app_process->name); + if (app_process->common.instantiate && (app_process->common.instantiate(MODULE_INST_CTX(inst->dynamic_submodule)) < 0)) { + cf_log_err(conf, "Instantiation failed for \"%s\"", app_process->common.name); return -1; } } @@ -2904,7 +2904,7 @@ int fr_master_io_listen(TALLOC_CTX *ctx, fr_io_instance_t *inst, fr_schedule_t * return 0; } - if (!inst->app_io->thread_inst_size) { + if (!inst->app_io->common.thread_inst_size) { fr_strerror_const("IO modules MUST set 'thread_inst_size' when using the master IO handler."); return -1; } @@ -2982,13 +2982,13 @@ int fr_master_io_listen(TALLOC_CTX *ctx, fr_io_instance_t *inst, fr_schedule_t * child->app_io = inst->app_io; child->track_duplicates = inst->app_io->track_duplicates; - if (child->app_io->thread_inst_size > 0) { + if (child->app_io->common.thread_inst_size > 0) { child->thread_instance = talloc_zero_array(NULL, uint8_t, - inst->app_io->thread_inst_size); + inst->app_io->common.thread_inst_size); talloc_set_destructor(child, fr_io_listen_free); talloc_set_name(child->thread_instance, "proto_%s_thread_t", - inst->app_io->name); + inst->app_io->common.name); /* * This is "const", and the user can't @@ -3008,7 +3008,7 @@ int fr_master_io_listen(TALLOC_CTX *ctx, fr_io_instance_t *inst, fr_schedule_t * * socket for us. */ if (inst->app_io->open(child) < 0) { - cf_log_err(inst->app_io_conf, "Failed opening %s interface", inst->app_io->name); + cf_log_err(inst->app_io_conf, "Failed opening %s interface", inst->app_io->common.name); talloc_free(li); return -1; } @@ -3016,7 +3016,7 @@ int fr_master_io_listen(TALLOC_CTX *ctx, fr_io_instance_t *inst, fr_schedule_t * li->fd = child->fd; /* copy this back up */ if (!child->app_io->get_name) { - child->name = child->app_io->name; + child->name = child->app_io->common.name; } else { child->name = child->app_io->get_name(child); } @@ -3056,12 +3056,13 @@ int fr_master_io_listen(TALLOC_CTX *ctx, fr_io_instance_t *inst, fr_schedule_t * fr_app_io_t fr_master_app_io = { - .magic = MODULE_MAGIC_INIT, - .name = "radius_master_io", - - .bootstrap = mod_bootstrap, - .instantiate = mod_instantiate, + .common = { + .magic = MODULE_MAGIC_INIT, + .name = "radius_master_io", + .bootstrap = mod_bootstrap, + .instantiate = mod_instantiate, + }, .default_message_size = 4096, .track_duplicates = true, diff --git a/src/lib/io/network.c b/src/lib/io/network.c index 657d9bd2fa..271d9686b3 100644 --- a/src/lib/io/network.c +++ b/src/lib/io/network.c @@ -1876,7 +1876,7 @@ static int cmd_socket_list(FILE *fp, UNUSED FILE *fp_err, void *ctx, UNUSED fr_c socket; socket = fr_rb_iter_next_inorder(&iter)) { if (!socket->listen->app_io->get_name) { - fprintf(fp, "%s\n", socket->listen->app_io->name); + fprintf(fp, "%s\n", socket->listen->app_io->common.name); } else { fprintf(fp, "%d\t%s\n", socket->number, socket->listen->app_io->get_name(socket->listen)); } diff --git a/src/lib/server/virtual_servers.c b/src/lib/server/virtual_servers.c index 823c1778a9..abebb74201 100644 --- a/src/lib/server/virtual_servers.c +++ b/src/lib/server/virtual_servers.c @@ -802,8 +802,8 @@ int virtual_servers_instantiate(void) fr_assert(listen->proto_module != NULL); fr_assert(listen->app != NULL); - if (listen->app->instantiate && - listen->app->instantiate(listen->proto_module->data, listen->proto_module->conf) < 0) { + if (listen->app->common.instantiate && + listen->app->common.instantiate(MODULE_INST_CTX(listen->proto_module)) < 0) { cf_log_err(listen->proto_module->conf, "Could not load virtual server \"%s\".", cf_section_name2(server_cs)); return -1; @@ -982,8 +982,8 @@ int virtual_servers_bootstrap(CONF_SECTION *config) talloc_get_type_abort(listen->proto_module, dl_module_inst_t); listen->app = (fr_app_t const *)listen->proto_module->module->common; - if (listen->app->bootstrap && - listen->app->bootstrap(listen->proto_module->data, listen->proto_module->conf) < 0) { + if (listen->app->common.bootstrap && + listen->app->common.bootstrap(MODULE_INST_CTX(listen->proto_module)) < 0) { cf_log_err(listen->proto_module->conf, "Bootstrap failed"); return -1; } @@ -1046,8 +1046,8 @@ int virtual_servers_open(fr_schedule_t *sc) */ if (listen->app->open && listen->app->open(listen->proto_module->data, sc, listen->proto_module->conf) < 0) { - cf_log_err(listen->proto_module->conf, "Opening %s I/O interface failed", - listen->app->name); + cf_log_perr(listen->proto_module->conf, "Opening %s I/O interface failed", + listen->app->common.name); return -1; } @@ -1055,7 +1055,7 @@ int virtual_servers_open(fr_schedule_t *sc) * Socket information is printed out by * the socket handlers. e.g. proto_radius_udp */ - DEBUG3("Opened listener for %s", listen->app->name); + DEBUG3("Opened listener for %s", listen->app->common.name); } } diff --git a/src/listen/arp/proto_arp.c b/src/listen/arp/proto_arp.c index c77ba5c7e1..03327e7a7d 100644 --- a/src/listen/arp/proto_arp.c +++ b/src/listen/arp/proto_arp.c @@ -175,9 +175,9 @@ static int mod_open(void *instance, fr_schedule_t *sc, UNUSED CONF_SECTION *conf li->app_io = inst->app_io; li->app_io_instance = inst->app_io_instance; - if (li->app_io->thread_inst_size) { - li->thread_instance = talloc_zero_array(NULL, uint8_t, li->app_io->thread_inst_size); - talloc_set_name(li->thread_instance, "proto_%s_thread_t", inst->app_io->name); + if (li->app_io->common.thread_inst_size) { + li->thread_instance = talloc_zero_array(NULL, uint8_t, li->app_io->common.thread_inst_size); + talloc_set_name(li->thread_instance, "proto_%s_thread_t", inst->app_io->common.name); } /* @@ -209,24 +209,21 @@ static int mod_open(void *instance, fr_schedule_t *sc, UNUSED CONF_SECTION *conf * * Instantiate I/O and type submodules. * - * @param[in] instance Ctx data for this application. - * @param[in] conf Listen section parsed to give us instance. * @return * - 0 on success. * - -1 on failure. */ -static int mod_instantiate(void *instance, CONF_SECTION *conf) +static int mod_instantiate(module_inst_ctx_t const *mctx) { - proto_arp_t *inst = talloc_get_type_abort(instance, proto_arp_t); - + proto_arp_t *inst = talloc_get_type_abort(mctx->inst->data, proto_arp_t); + CONF_SECTION *conf = mctx->inst->conf; /* * Instantiate the I/O module. But DON'T instantiate the * work submodule. We leave that until later. */ - if (inst->app_io->instantiate && - (inst->app_io->instantiate(inst->app_io_instance, - inst->app_io_conf) < 0)) { - cf_log_err(conf, "Instantiation failed for \"%s\"", inst->app_io->name); + if (inst->app_io->common.instantiate && + (inst->app_io->common.instantiate(MODULE_INST_CTX(inst->io_submodule)) < 0)) { + cf_log_err(conf, "Instantiation failed for \"%s\"", inst->app_io->common.name); return -1; } @@ -243,15 +240,14 @@ static int mod_instantiate(void *instance, CONF_SECTION *conf) * * Bootstrap I/O and type submodules. * - * @param[in] instance Ctx data for this application. - * @param[in] conf Listen section parsed to give us instance. * @return * - 0 on success. * - -1 on failure. */ -static int mod_bootstrap(void *instance, CONF_SECTION *conf) +static int mod_bootstrap(module_inst_ctx_t const *mctx) { - proto_arp_t *inst = talloc_get_type_abort(instance, proto_arp_t); + proto_arp_t *inst = talloc_get_type_abort(mctx->inst->data, proto_arp_t); + CONF_SECTION *conf = mctx->inst->conf; dl_module_inst_t *parent_inst; /* @@ -281,9 +277,8 @@ static int mod_bootstrap(void *instance, CONF_SECTION *conf) inst->app_io_instance = inst->io_submodule->data; inst->app_io_conf = conf; - if (inst->app_io->bootstrap && (inst->app_io->bootstrap(inst->app_io_instance, - inst->app_io_conf) < 0)) { - cf_log_err(inst->app_io_conf, "Bootstrap failed for \"%s\"", inst->app_io->name); + if (inst->app_io->common.bootstrap && (inst->app_io->common.bootstrap(MODULE_INST_CTX(inst->io_submodule)) < 0)) { + cf_log_err(inst->app_io_conf, "Bootstrap failed for \"%s\"", inst->app_io->common.name); return -1; } @@ -305,16 +300,17 @@ static void mod_unload(void) } fr_app_t proto_arp = { - .magic = MODULE_MAGIC_INIT, - .name = "arp", - .config = proto_arp_config, - .inst_size = sizeof(proto_arp_t), + .common = { + .magic = MODULE_MAGIC_INIT, + .name = "arp", + .config = proto_arp_config, + .inst_size = sizeof(proto_arp_t), + .onload = mod_load, + .unload = mod_unload, + .bootstrap = mod_bootstrap, + .instantiate = mod_instantiate + }, .dict = &dict_arp, - - .onload = mod_load, - .unload = mod_unload, - .bootstrap = mod_bootstrap, - .instantiate = mod_instantiate, .open = mod_open, .decode = mod_decode, .encode = mod_encode, diff --git a/src/listen/arp/proto_arp_ethernet.c b/src/listen/arp/proto_arp_ethernet.c index 0fdf6cbfef..312bab4d73 100644 --- a/src/listen/arp/proto_arp_ethernet.c +++ b/src/listen/arp/proto_arp_ethernet.c @@ -216,24 +216,25 @@ static char const *mod_name(fr_listen_t *li) } -static int mod_bootstrap(void *instance, CONF_SECTION *cs) +static int mod_bootstrap(module_inst_ctx_t const *mctx) { - proto_arp_ethernet_t *inst = talloc_get_type_abort(instance, proto_arp_ethernet_t); + proto_arp_ethernet_t *inst = talloc_get_type_abort(mctx->inst->data, proto_arp_ethernet_t); - inst->cs = cs; + inst->cs = mctx->inst->conf; return 0; } fr_app_io_t proto_arp_ethernet = { - .magic = MODULE_MAGIC_INIT, - .name = "arp_ethernet", - .config = arp_listen_config, - .inst_size = sizeof(proto_arp_ethernet_t), - .thread_inst_size = sizeof(proto_arp_ethernet_thread_t), - .bootstrap = mod_bootstrap, - + .common = { + .magic = MODULE_MAGIC_INIT, + .name = "arp_ethernet", + .config = arp_listen_config, + .inst_size = sizeof(proto_arp_ethernet_t), + .thread_inst_size = sizeof(proto_arp_ethernet_thread_t), + .bootstrap = mod_bootstrap, + }, .default_message_size = FR_ARP_PACKET_SIZE, .open = mod_open, diff --git a/src/listen/control/proto_control.c b/src/listen/control/proto_control.c index 2bbba2ddad..9021f8e65f 100644 --- a/src/listen/control/proto_control.c +++ b/src/listen/control/proto_control.c @@ -138,15 +138,13 @@ static int mod_open(void *instance, fr_schedule_t *sc, UNUSED CONF_SECTION *conf * * Instantiate I/O and type submodules. * - * @param[in] instance Ctx data for this application. - * @param[in] conf Listen section parsed to give us instance. * @return * - 0 on success. * - -1 on failure. */ -static int mod_instantiate(void *instance, CONF_SECTION *conf) +static int mod_instantiate(module_inst_ctx_t const *mctx) { - proto_control_t *inst = talloc_get_type_abort(instance, proto_control_t); + proto_control_t *inst = talloc_get_type_abort(mctx->inst->data, proto_control_t); fr_assert(inst->io.submodule != NULL); @@ -167,7 +165,7 @@ static int mod_instantiate(void *instance, CONF_SECTION *conf) /* * Instantiate the master io submodule */ - return fr_master_app_io.instantiate(&inst->io, conf); + return fr_master_app_io.common.instantiate(MODULE_INST_CTX(inst->io.dl_inst)); } @@ -175,15 +173,14 @@ static int mod_instantiate(void *instance, CONF_SECTION *conf) * * Bootstrap I/O and type submodules. * - * @param[in] instance Ctx data for this application. - * @param[in] conf Listen section parsed to give us instance. * @return * - 0 on success. * - -1 on failure. */ -static int mod_bootstrap(void *instance, CONF_SECTION *conf) +static int mod_bootstrap(module_inst_ctx_t const *mctx) { - proto_control_t *inst = talloc_get_type_abort(instance, proto_control_t); + proto_control_t *inst = talloc_get_type_abort(mctx->inst->data, proto_control_t); + CONF_SECTION *conf = mctx->inst->conf; /* * Ensure that the server CONF_SECTION is always set. @@ -222,16 +219,17 @@ static int mod_bootstrap(void *instance, CONF_SECTION *conf) /* * Bootstrap the master IO handler. */ - return fr_master_app_io.bootstrap(&inst->io, conf); + return fr_master_app_io.common.bootstrap(MODULE_INST_CTX(inst->io.dl_inst)); } fr_app_t proto_control = { - .magic = MODULE_MAGIC_INIT, - .name = "control", - .config = proto_control_config, - .inst_size = sizeof(proto_control_t), - - .bootstrap = mod_bootstrap, - .instantiate = mod_instantiate, + .common = { + .magic = MODULE_MAGIC_INIT, + .name = "control", + .config = proto_control_config, + .inst_size = sizeof(proto_control_t), + .bootstrap = mod_bootstrap, + .instantiate = mod_instantiate + }, .open = mod_open, }; diff --git a/src/listen/control/proto_control_unix.c b/src/listen/control/proto_control_unix.c index e562b06064..f1091f5a44 100644 --- a/src/listen/control/proto_control_unix.c +++ b/src/listen/control/proto_control_unix.c @@ -1105,11 +1105,12 @@ static char const *mod_name(fr_listen_t *li) } -static int mod_bootstrap(void *instance, CONF_SECTION *cs) +static int mod_bootstrap(module_inst_ctx_t const *mctx) { - proto_control_unix_t *inst = talloc_get_type_abort(instance, proto_control_unix_t); + proto_control_unix_t *inst = talloc_get_type_abort(mctx->inst->data, proto_control_unix_t); + CONF_SECTION *conf = mctx->inst->conf; - inst->cs = cs; + inst->cs = conf; if (inst->recv_buff_is_set) { FR_INTEGER_BOUND_CHECK("recv_buff", inst->recv_buff, >=, 32); @@ -1126,7 +1127,7 @@ static int mod_bootstrap(void *instance, CONF_SECTION *cs) if (inst->uid_name) { struct passwd *pwd; - if (fr_perm_getpwnam(cs, &pwd, inst->uid_name) < 0) { + if (fr_perm_getpwnam(conf, &pwd, inst->uid_name) < 0) { PERROR("Failed getting uid for %s", inst->uid_name); return -1; } @@ -1137,7 +1138,7 @@ static int mod_bootstrap(void *instance, CONF_SECTION *cs) } if (inst->gid_name) { - if (fr_perm_gid_from_str(cs, &inst->gid, inst->gid_name) < 0) { + if (fr_perm_gid_from_str(conf, &inst->gid, inst->gid_name) < 0) { PERROR("Failed getting gid for %s", inst->gid_name); return -1; } @@ -1179,13 +1180,14 @@ static RADCLIENT *mod_client_find(fr_listen_t *li, UNUSED fr_ipaddr_t const *ipa extern fr_app_io_t proto_control_unix; fr_app_io_t proto_control_unix = { - .magic = MODULE_MAGIC_INIT, - .name = "control_unix", - .config = unix_listen_config, - .inst_size = sizeof(proto_control_unix_t), - .thread_inst_size = sizeof(proto_control_unix_thread_t), - .bootstrap = mod_bootstrap, - + .common = { + .magic = MODULE_MAGIC_INIT, + .name = "control_unix", + .config = unix_listen_config, + .inst_size = sizeof(proto_control_unix_t), + .thread_inst_size = sizeof(proto_control_unix_thread_t), + .bootstrap = mod_bootstrap, + }, .default_message_size = 4096, .open = mod_open, diff --git a/src/listen/cron/proto_cron.c b/src/listen/cron/proto_cron.c index af48499a96..d14a3d4c88 100644 --- a/src/listen/cron/proto_cron.c +++ b/src/listen/cron/proto_cron.c @@ -244,15 +244,13 @@ static int mod_open(void *instance, fr_schedule_t *sc, UNUSED CONF_SECTION *conf * * Instantiate I/O and type submodules. * - * @param[in] instance Ctx data for this application. - * @param[in] conf Listen section parsed to give us isntance. * @return * - 0 on success. * - -1 on failure. */ -static int mod_instantiate(void *instance, CONF_SECTION *conf) +static int mod_instantiate(module_inst_ctx_t const *mctx) { - proto_cron_t *inst = talloc_get_type_abort(instance, proto_cron_t); + proto_cron_t *inst = talloc_get_type_abort(mctx->inst->data, proto_cron_t); fr_assert(inst->io.submodule); @@ -273,22 +271,21 @@ static int mod_instantiate(void *instance, CONF_SECTION *conf) /* * Instantiate the master io submodule */ - return fr_master_app_io.instantiate(&inst->io, conf); + return fr_master_app_io.common.instantiate(MODULE_INST_CTX(inst->io.dl_inst)); } /** Bootstrap the application * * Bootstrap I/O and type submodules. * - * @param[in] instance Ctx data for this application. - * @param[in] conf Listen section parsed to give us instance. * @return * - 0 on success. * - -1 on failure. */ -static int mod_bootstrap(void *instance, CONF_SECTION *conf) +static int mod_bootstrap(module_inst_ctx_t const *mctx) { - proto_cron_t *inst = talloc_get_type_abort(instance, proto_cron_t); + proto_cron_t *inst = talloc_get_type_abort(mctx->inst->data, proto_cron_t); + CONF_SECTION *conf = mctx->inst->conf; /* * Ensure that the server CONF_SECTION is always set. @@ -325,18 +322,20 @@ static int mod_bootstrap(void *instance, CONF_SECTION *conf) /* * Bootstrap the master IO handler. */ - return fr_master_app_io.bootstrap(&inst->io, conf); + return fr_master_app_io.common.bootstrap(MODULE_INST_CTX(inst->io.dl_inst)); } fr_app_t proto_cron = { - .magic = MODULE_MAGIC_INIT, - .name = "cron", - .config = proto_cron_config, - .inst_size = sizeof(proto_cron_t), - - .bootstrap = mod_bootstrap, - .instantiate = mod_instantiate, + .common = { + .magic = MODULE_MAGIC_INIT, + .name = "cron", + .config = proto_cron_config, + .inst_size = sizeof(proto_cron_t), + + .bootstrap = mod_bootstrap, + .instantiate = mod_instantiate + }, .open = mod_open, .decode = mod_decode, .encode = mod_encode, diff --git a/src/listen/cron/proto_cron_crontab.c b/src/listen/cron/proto_cron_crontab.c index 3709d368f0..5acdee4740 100644 --- a/src/listen/cron/proto_cron_crontab.c +++ b/src/listen/cron/proto_cron_crontab.c @@ -682,9 +682,10 @@ static char const *mod_name(fr_listen_t *li) } -static int mod_bootstrap(void *instance, CONF_SECTION *cs) +static int mod_bootstrap(module_inst_ctx_t const *mctx) { - proto_cron_crontab_t *inst = talloc_get_type_abort(instance, proto_cron_crontab_t); + proto_cron_crontab_t *inst = talloc_get_type_abort(mctx->inst->data, proto_cron_crontab_t); + CONF_SECTION *conf = mctx->inst->data; dl_module_inst_t const *dl_inst; /* @@ -692,12 +693,12 @@ static int mod_bootstrap(void *instance, CONF_SECTION *cs) * so we can find out what the parent of our instance * was. */ - dl_inst = dl_module_instance_by_data(instance); + dl_inst = dl_module_instance_by_data(inst); fr_assert(dl_inst); inst->parent = talloc_get_type_abort(dl_inst->parent->data, proto_cron_t); - inst->cs = cs; + inst->cs = conf; return 0; } @@ -710,9 +711,10 @@ static RADCLIENT *mod_client_find(fr_listen_t *li, UNUSED fr_ipaddr_t const *ipa } -static int mod_instantiate(void *instance, CONF_SECTION *cs) +static int mod_instantiate(module_inst_ctx_t const *mctx) { - proto_cron_crontab_t *inst = talloc_get_type_abort(instance, proto_cron_crontab_t); + proto_cron_crontab_t *inst = talloc_get_type_abort(mctx->inst->data, proto_cron_crontab_t); + CONF_SECTION *conf = mctx->inst->data; RADCLIENT *client; fr_pair_t *vp; FILE *fp; @@ -732,13 +734,13 @@ static int mod_instantiate(void *instance, CONF_SECTION *cs) fp = fopen(inst->filename, "r"); if (!fp) { - cf_log_err(cs, "Failed opening %s - %s", + cf_log_err(conf, "Failed opening %s - %s", inst->filename, fr_syserror(errno)); return -1; } if (fr_pair_list_afrom_file(inst, inst->parent->dict, &inst->pair_list, fp, &done) < 0) { - cf_log_perr(cs, "Failed reading %s", inst->filename); + cf_log_perr(conf, "Failed reading %s", inst->filename); fclose(fp); return -1; } @@ -752,14 +754,15 @@ static int mod_instantiate(void *instance, CONF_SECTION *cs) } fr_app_io_t proto_cron_crontab = { - .magic = MODULE_MAGIC_INIT, - .name = "cron_crontab", - .config = crontab_listen_config, - .inst_size = sizeof(proto_cron_crontab_t), - .thread_inst_size = sizeof(proto_cron_crontab_thread_t), - .bootstrap = mod_bootstrap, - .instantiate = mod_instantiate, - + .common = { + .magic = MODULE_MAGIC_INIT, + .name = "cron_crontab", + .config = crontab_listen_config, + .inst_size = sizeof(proto_cron_crontab_t), + .thread_inst_size = sizeof(proto_cron_crontab_thread_t), + .bootstrap = mod_bootstrap, + .instantiate = mod_instantiate + }, .default_message_size = 4096, .track_duplicates = false, diff --git a/src/listen/detail/proto_detail.c b/src/listen/detail/proto_detail.c index 4151e130f3..085e373547 100644 --- a/src/listen/detail/proto_detail.c +++ b/src/listen/detail/proto_detail.c @@ -373,8 +373,8 @@ static int mod_open(void *instance, fr_schedule_t *sc, CONF_SECTION *conf) talloc_set_destructor(li, fr_io_listen_free); li->app_io = inst->app_io; - li->thread_instance = talloc_zero_array(NULL, uint8_t, li->app_io->thread_inst_size); - talloc_set_name(li->thread_instance, "proto_%s_thread_t", inst->app_io->name); + li->thread_instance = talloc_zero_array(NULL, uint8_t, li->app_io->common.thread_inst_size); + talloc_set_name(li->thread_instance, "proto_%s_thread_t", inst->app_io->common.name); li->app_io_instance = inst->app_io_instance; li->app = &proto_detail; @@ -391,7 +391,7 @@ static int mod_open(void *instance, fr_schedule_t *sc, CONF_SECTION *conf) * Open the file. */ if (inst->app_io->open(li) < 0) { - cf_log_err(conf, "Failed opening %s file", inst->app_io->name); + cf_log_err(conf, "Failed opening %s file", inst->app_io->common.name); talloc_free(li); return -1; } @@ -435,24 +435,22 @@ static int mod_open(void *instance, fr_schedule_t *sc, CONF_SECTION *conf) * * Instantiate I/O and type submodules. * - * @param[in] instance Ctx data for this application. - * @param[in] conf Listen section parsed to give us isntance. * @return * - 0 on success. * - -1 on failure. */ -static int mod_instantiate(void *instance, CONF_SECTION *conf) +static int mod_instantiate(module_inst_ctx_t const *mctx) { - proto_detail_t *inst = talloc_get_type_abort(instance, proto_detail_t); + proto_detail_t *inst = talloc_get_type_abort(mctx->inst->data, proto_detail_t); + CONF_SECTION *conf = mctx->inst->conf; /* * Instantiate the I/O module. But DON'T instantiate the * work submodule. We leave that until later. */ - if (inst->app_io->instantiate && - (inst->app_io->instantiate(inst->app_io_instance, - inst->app_io_conf) < 0)) { - cf_log_err(conf, "Instantiation failed for \"%s\"", inst->app_io->name); + if (inst->app_io->common.instantiate && + (inst->app_io->common.instantiate(MODULE_INST_CTX(inst->io_submodule)) < 0)) { + cf_log_err(conf, "Instantiation failed for \"%s\"", inst->app_io->common.name); return -1; } @@ -476,9 +474,9 @@ static int mod_instantiate(void *instance, CONF_SECTION *conf) * If the IO is "file" and not the worker, instantiate the worker now. */ if (strcmp(inst->io_submodule->module->dl->name, "proto_detail_work") != 0) { - if (inst->work_io->instantiate && (inst->work_io->instantiate(inst->work_io_instance, - inst->work_io_conf) < 0)) { - cf_log_err(inst->work_io_conf, "Instantiation failed for \"%s\"", inst->work_io->name); + if (inst->work_io->common.instantiate && + (inst->work_io->common.instantiate(MODULE_INST_CTX(inst->io_submodule)) < 0)) { + cf_log_err(inst->work_io_conf, "Instantiation failed for \"%s\"", inst->work_io->common.name); return -1; } } @@ -490,15 +488,14 @@ static int mod_instantiate(void *instance, CONF_SECTION *conf) * * Bootstrap I/O and type submodules. * - * @param[in] instance Ctx data for this application. - * @param[in] conf Listen section parsed to give us instance. * @return * - 0 on success. * - -1 on failure. */ -static int mod_bootstrap(void *instance, CONF_SECTION *conf) +static int mod_bootstrap(module_inst_ctx_t const *mctx) { - proto_detail_t *inst = talloc_get_type_abort(instance, proto_detail_t); + proto_detail_t *inst = talloc_get_type_abort(mctx->inst->data, proto_detail_t); + CONF_SECTION *conf = mctx->inst->conf; /* * The listener is inside of a virtual server. @@ -507,8 +504,6 @@ static int mod_bootstrap(void *instance, CONF_SECTION *conf) inst->cs = conf; inst->self = &proto_detail; - virtual_server_dict_set(inst->server_cs, inst->dict, false); - /* * No IO module, it's an empty listener. That's not * allowed for the detail file reader. @@ -525,9 +520,8 @@ static int mod_bootstrap(void *instance, CONF_SECTION *conf) inst->app_io_instance = inst->io_submodule->data; inst->app_io_conf = inst->io_submodule->conf; - if (inst->app_io->bootstrap && (inst->app_io->bootstrap(inst->app_io_instance, - inst->app_io_conf) < 0)) { - cf_log_err(inst->app_io_conf, "Bootstrap failed for \"%s\"", inst->app_io->name); + if (inst->app_io->common.bootstrap && (inst->app_io->common.bootstrap(MODULE_INST_CTX(inst->io_submodule)) < 0)) { + cf_log_err(inst->app_io_conf, "Bootstrap failed for \"%s\"", inst->app_io->common.name); return -1; } @@ -571,9 +565,9 @@ static int mod_bootstrap(void *instance, CONF_SECTION *conf) inst->work_io_instance = inst->work_submodule->data; inst->work_io_conf = inst->work_submodule->conf; - if (inst->work_io->bootstrap && (inst->work_io->bootstrap(inst->work_io_instance, - inst->work_io_conf) < 0)) { - cf_log_err(inst->work_io_conf, "Bootstrap failed for \"%s\"", inst->work_io->name); + if (inst->work_io->common.bootstrap && + (inst->work_io->common.bootstrap(MODULE_INST_CTX(inst->work_submodule)) < 0)) { + cf_log_err(inst->work_io_conf, "Bootstrap failed for \"%s\"", inst->work_io->common.name); TALLOC_FREE(inst->work_submodule); return -1; } @@ -584,13 +578,15 @@ static int mod_bootstrap(void *instance, CONF_SECTION *conf) fr_app_t proto_detail = { - .magic = MODULE_MAGIC_INIT, - .name = "detail", - .config = proto_detail_config, - .inst_size = sizeof(proto_detail_t), - - .bootstrap = mod_bootstrap, - .instantiate = mod_instantiate, + .common = { + .magic = MODULE_MAGIC_INIT, + .name = "detail", + .config = proto_detail_config, + .inst_size = sizeof(proto_detail_t), + + .bootstrap = mod_bootstrap, + .instantiate = mod_instantiate, + }, .open = mod_open, .decode = mod_decode, .encode = mod_encode, diff --git a/src/listen/detail/proto_detail_file.c b/src/listen/detail/proto_detail_file.c index 3dec2c463d..5759839d8f 100644 --- a/src/listen/detail/proto_detail_file.c +++ b/src/listen/detail/proto_detail_file.c @@ -379,7 +379,7 @@ static int work_exists(proto_detail_file_thread_t *thread, int fd) * Open the detail.work file. */ if (li->app_io->open(li) < 0) { - ERROR("Failed opening %s", li->app_io->name); + ERROR("Failed opening %s", li->app_io->common.name); goto error; } opened = true; @@ -584,9 +584,10 @@ static char const *mod_name(fr_listen_t *li) } -static int mod_bootstrap(void *instance, CONF_SECTION *cs) +static int mod_bootstrap(module_inst_ctx_t const *mctx) { - proto_detail_file_t *inst = talloc_get_type_abort(instance, proto_detail_file_t); + proto_detail_file_t *inst = talloc_get_type_abort(mctx->inst->data, proto_detail_file_t); + CONF_SECTION *conf = mctx->inst->conf; dl_module_inst_t const *dl_inst; char *p; @@ -617,7 +618,7 @@ static int mod_bootstrap(void *instance, CONF_SECTION *cs) * so we can find out what the parent of our instance * was. */ - dl_inst = dl_module_instance_by_data(instance); + dl_inst = dl_module_instance_by_data(mctx->inst->data); fr_assert(dl_inst); #ifndef __linux__ @@ -629,13 +630,13 @@ static int mod_bootstrap(void *instance, CONF_SECTION *cs) FR_INTEGER_BOUND_CHECK("poll_interval", inst->poll_interval, <=, 3600); inst->parent = talloc_get_type_abort(dl_inst->parent->data, proto_detail_t); - inst->cs = cs; + inst->cs = conf; inst->directory = p = talloc_strdup(inst, inst->filename); p = strrchr(p, '/'); if (!p) { - cf_log_err(cs, "Filename must contain '/'"); + cf_log_err(conf, "Filename must contain '/'"); return -1; } @@ -672,16 +673,17 @@ static int8_t _detail_file_cmp(void const *one, void const *two) /* * Check for multiple readers on the same set of files. */ -static int mod_instantiate(void *instance, CONF_SECTION *cs) +static int mod_instantiate(module_inst_ctx_t const *mctx) { - proto_detail_file_t *inst = talloc_get_type_abort(instance, proto_detail_file_t); + proto_detail_file_t *inst = talloc_get_type_abort(mctx->inst->data, proto_detail_file_t); + CONF_SECTION *conf = mctx->inst->conf; pthread_mutex_lock(&detail_file_mutex); if (!detail_file_tree) { - detail_file_tree = fr_rb_inline_talloc_alloc(cs, proto_detail_file_t, filename_node, _detail_file_cmp, NULL); + detail_file_tree = fr_rb_inline_talloc_alloc(conf, proto_detail_file_t, filename_node, _detail_file_cmp, NULL); if (!detail_file_tree) { pthread_mutex_unlock(&detail_file_mutex); - cf_log_err(cs, "Failed initializing detail_file"); + cf_log_err(conf, "Failed initializing detail_file"); return -1; } } @@ -693,8 +695,8 @@ static int mod_instantiate(void *instance, CONF_SECTION *cs) fr_assert(old); pthread_mutex_unlock(&detail_file_mutex); - cf_log_err(cs, "Duplicate detail listener %s", inst->filename); - cf_log_err(cs, "Original detail listener is in virtual server %s", cf_section_name2(old->parent->server_cs)); + cf_log_err(conf, "Duplicate detail listener %s", inst->filename); + cf_log_err(conf, "Original detail listener is in virtual server %s", cf_section_name2(old->parent->server_cs)); return -1; } pthread_mutex_unlock(&detail_file_mutex); @@ -740,14 +742,15 @@ static int mod_close(fr_listen_t *li) */ extern fr_app_io_t proto_detail_file; fr_app_io_t proto_detail_file = { - .magic = MODULE_MAGIC_INIT, - .name = "detail_file", - .config = file_listen_config, - .inst_size = sizeof(proto_detail_file_t), - .thread_inst_size = sizeof(proto_detail_file_thread_t), - .bootstrap = mod_bootstrap, - .instantiate = mod_instantiate, - + .common = { + .magic = MODULE_MAGIC_INIT, + .name = "detail_file", + .config = file_listen_config, + .inst_size = sizeof(proto_detail_file_t), + .thread_inst_size = sizeof(proto_detail_file_thread_t), + .bootstrap = mod_bootstrap, + .instantiate = mod_instantiate, + }, .default_message_size = 65536, .default_reply_size = 32, diff --git a/src/listen/detail/proto_detail_work.c b/src/listen/detail/proto_detail_work.c index 3e9f7acdc5..f85d1609d9 100644 --- a/src/listen/detail/proto_detail_work.c +++ b/src/listen/detail/proto_detail_work.c @@ -814,9 +814,9 @@ static char const *mod_name(fr_listen_t *li) return thread->name; } -static int mod_instantiate(void *instance, UNUSED CONF_SECTION *cs) +static int mod_instantiate(module_inst_ctx_t const *mctx) { - proto_detail_work_t *inst = talloc_get_type_abort(instance, proto_detail_work_t); + proto_detail_work_t *inst = talloc_get_type_abort(mctx->inst->data, proto_detail_work_t); RADCLIENT *client; client = inst->client = talloc_zero(inst, RADCLIENT); @@ -832,9 +832,10 @@ static int mod_instantiate(void *instance, UNUSED CONF_SECTION *cs) return 0; } -static int mod_bootstrap(void *instance, CONF_SECTION *cs) +static int mod_bootstrap(module_inst_ctx_t const *mctx) { - proto_detail_work_t *inst = talloc_get_type_abort(instance, proto_detail_work_t); + proto_detail_work_t *inst = talloc_get_type_abort(mctx->inst->data, proto_detail_work_t); + CONF_SECTION *cs = mctx->inst->conf; dl_module_inst_t const *dl_inst; /* @@ -842,7 +843,7 @@ static int mod_bootstrap(void *instance, CONF_SECTION *cs) * so we can find out what the parent of our instance * was. */ - dl_inst = dl_module_instance_by_data(instance); + dl_inst = dl_module_instance_by_data(mctx->inst->data); fr_assert(dl_inst); inst->parent = talloc_get_type_abort(dl_inst->parent->data, proto_detail_t); @@ -882,14 +883,15 @@ static int mod_bootstrap(void *instance, CONF_SECTION *cs) */ extern fr_app_io_t proto_detail_work; fr_app_io_t proto_detail_work = { - .magic = MODULE_MAGIC_INIT, - .name = "detail_work", - .config = file_listen_config, - .inst_size = sizeof(proto_detail_work_t), - .thread_inst_size = sizeof(proto_detail_work_thread_t), - .bootstrap = mod_bootstrap, - .instantiate = mod_instantiate, - + .common = { + .magic = MODULE_MAGIC_INIT, + .name = "detail_work", + .config = file_listen_config, + .inst_size = sizeof(proto_detail_work_t), + .thread_inst_size = sizeof(proto_detail_work_thread_t), + .bootstrap = mod_bootstrap, + .instantiate = mod_instantiate + }, .default_message_size = 65536, .default_reply_size = 32, diff --git a/src/listen/dhcpv4/proto_dhcpv4.c b/src/listen/dhcpv4/proto_dhcpv4.c index b7fc0ed9ad..305b35a966 100644 --- a/src/listen/dhcpv4/proto_dhcpv4.c +++ b/src/listen/dhcpv4/proto_dhcpv4.c @@ -398,15 +398,13 @@ static int mod_open(void *instance, fr_schedule_t *sc, UNUSED CONF_SECTION *conf * * Instantiate I/O and type submodules. * - * @param[in] instance Ctx data for this application. - * @param[in] conf Listen section parsed to give us instance. * @return * - 0 on success. * - -1 on failure. */ -static int mod_instantiate(void *instance, CONF_SECTION *conf) +static int mod_instantiate(module_inst_ctx_t const *mctx) { - proto_dhcpv4_t *inst = talloc_get_type_abort(instance, proto_dhcpv4_t); + proto_dhcpv4_t *inst = talloc_get_type_abort(mctx->inst->data, proto_dhcpv4_t); /* * No IO module, it's an empty listener. @@ -430,7 +428,7 @@ static int mod_instantiate(void *instance, CONF_SECTION *conf) /* * Instantiate the master io submodule */ - return fr_master_app_io.instantiate(&inst->io, conf); + return fr_master_app_io.common.instantiate(MODULE_INST_CTX(inst->io.dl_inst)); } @@ -438,20 +436,18 @@ static int mod_instantiate(void *instance, CONF_SECTION *conf) * * Bootstrap I/O and type submodules. * - * @param[in] instance Ctx data for this application. - * @param[in] conf Listen section parsed to give us instance. * @return * - 0 on success. * - -1 on failure. */ -static int mod_bootstrap(void *instance, CONF_SECTION *conf) +static int mod_bootstrap(module_inst_ctx_t const *mctx) { - proto_dhcpv4_t *inst = talloc_get_type_abort(instance, proto_dhcpv4_t); + proto_dhcpv4_t *inst = talloc_get_type_abort(mctx->inst->data, proto_dhcpv4_t); /* * Ensure that the server CONF_SECTION is always set. */ - inst->io.server_cs = cf_item_to_section(cf_parent(conf)); + inst->io.server_cs = cf_item_to_section(cf_parent(mctx->inst->conf)); fr_assert(dict_dhcpv4 != NULL); fr_assert(attr_message_type != NULL); @@ -488,7 +484,7 @@ static int mod_bootstrap(void *instance, CONF_SECTION *conf) /* * Bootstrap the master IO handler. */ - return fr_master_app_io.bootstrap(&inst->io, conf); + return fr_master_app_io.common.bootstrap(MODULE_INST_CTX(inst->io.dl_inst)); } static int mod_load(void) @@ -507,17 +503,19 @@ static void mod_unload(void) } fr_app_t proto_dhcpv4 = { - .magic = MODULE_MAGIC_INIT, - .name = "dhcpv4", - .config = proto_dhcpv4_config, - .inst_size = sizeof(proto_dhcpv4_t), + .common = { + .magic = MODULE_MAGIC_INIT, + .name = "dhcpv4", + .config = proto_dhcpv4_config, + .inst_size = sizeof(proto_dhcpv4_t), + + .onload = mod_load, + .unload = mod_unload, + + .bootstrap = mod_bootstrap, + .instantiate = mod_instantiate + }, .dict = &dict_dhcpv4, - - .onload = mod_load, - .unload = mod_unload, - - .bootstrap = mod_bootstrap, - .instantiate = mod_instantiate, .open = mod_open, .decode = mod_decode, .encode = mod_encode, diff --git a/src/listen/dhcpv4/proto_dhcpv4_udp.c b/src/listen/dhcpv4/proto_dhcpv4_udp.c index 36a620fd29..06d1df097e 100644 --- a/src/listen/dhcpv4/proto_dhcpv4_udp.c +++ b/src/listen/dhcpv4/proto_dhcpv4_udp.c @@ -653,26 +653,27 @@ static char const *mod_name(fr_listen_t *li) } -static int mod_bootstrap(void *instance, CONF_SECTION *cs) +static int mod_bootstrap(module_inst_ctx_t const *mctx) { - proto_dhcpv4_udp_t *inst = talloc_get_type_abort(instance, proto_dhcpv4_udp_t); + proto_dhcpv4_udp_t *inst = talloc_get_type_abort(mctx->inst->data, proto_dhcpv4_udp_t); + CONF_SECTION *conf = mctx->inst->conf; size_t num; CONF_ITEM *ci; CONF_SECTION *server_cs; RADCLIENT *client; - inst->cs = cs; + inst->cs = conf; /* * Complain if no "ipaddr" is set. */ if (inst->ipaddr.af == AF_UNSPEC) { - cf_log_err(cs, "No 'ipaddr' was specified in the 'udp' section"); + cf_log_err(conf, "No 'ipaddr' was specified in the 'udp' section"); return -1; } if (inst->ipaddr.af != AF_INET) { - cf_log_err(cs, "DHCPv4 transport cannot use IPv6 for 'ipaddr'"); + cf_log_err(conf, "DHCPv4 transport cannot use IPv6 for 'ipaddr'"); return -1; } @@ -681,7 +682,7 @@ static int mod_bootstrap(void *instance, CONF_SECTION *cs) */ if ((inst->src_ipaddr.af != AF_UNSPEC) && (inst->src_ipaddr.af != inst->ipaddr.af)) { - cf_log_err(cs, "Both 'ipaddr' and 'src_ipaddr' must be from the same address family"); + cf_log_err(conf, "Both 'ipaddr' and 'src_ipaddr' must be from the same address family"); return -1; } @@ -705,13 +706,13 @@ static int mod_bootstrap(void *instance, CONF_SECTION *cs) struct servent *s; if (!inst->port_name) { - cf_log_err(cs, "No 'port' was specified in the 'udp' section"); + cf_log_err(conf, "No 'port' was specified in the 'udp' section"); return -1; } s = getservbyname(inst->port_name, "udp"); if (!s) { - cf_log_err(cs, "Unknown value for 'port_name = %s", inst->port_name); + cf_log_err(conf, "Unknown value for 'port_name = %s", inst->port_name); return -1; } @@ -723,8 +724,8 @@ static int mod_bootstrap(void *instance, CONF_SECTION *cs) * If we're listening for broadcast requests, we MUST */ if (inst->broadcast && !inst->interface) { - cf_log_warn(cs, "You SHOULD set 'interface' if you have set 'broadcast = yes'."); - cf_log_warn(cs, "All replies will be broadcast, as ARP updates require 'interface' to be set."); + cf_log_warn(conf, "You SHOULD set 'interface' if you have set 'broadcast = yes'."); + cf_log_warn(conf, "All replies will be broadcast, as ARP updates require 'interface' to be set."); } #endif @@ -735,13 +736,13 @@ static int mod_bootstrap(void *instance, CONF_SECTION *cs) num = talloc_array_length(inst->allow); if (!num) { if (inst->dynamic_clients) { - cf_log_err(cs, "The 'allow' subsection MUST contain at least one 'network' entry when 'dynamic_clients = true'."); + cf_log_err(conf, "The 'allow' subsection MUST contain at least one 'network' entry when 'dynamic_clients = true'."); return -1; } } else { inst->trie = fr_master_io_network(inst, inst->ipaddr.af, inst->allow, inst->deny); if (!inst->trie) { - cf_log_perr(cs, "Failed creating list of networks"); + cf_log_perr(conf, "Failed creating list of networks"); return -1; } } @@ -762,7 +763,7 @@ static int mod_bootstrap(void *instance, CONF_SECTION *cs) if (cf_section_find_next(server_cs, NULL, "client", CF_IDENT_ANY)) { inst->clients = client_list_parse_section(server_cs, IPPROTO_UDP, false); if (!inst->clients) { - cf_log_err(cs, "Failed creating local clients"); + cf_log_err(conf, "Failed creating local clients"); return -1; } } @@ -801,13 +802,14 @@ static RADCLIENT *mod_client_find(fr_listen_t *li, fr_ipaddr_t const *ipaddr, in } fr_app_io_t proto_dhcpv4_udp = { - .magic = MODULE_MAGIC_INIT, - .name = "dhcpv4_udp", - .config = udp_listen_config, - .inst_size = sizeof(proto_dhcpv4_udp_t), - .thread_inst_size = sizeof(proto_dhcpv4_udp_thread_t), - .bootstrap = mod_bootstrap, - + .common = { + .magic = MODULE_MAGIC_INIT, + .name = "dhcpv4_udp", + .config = udp_listen_config, + .inst_size = sizeof(proto_dhcpv4_udp_t), + .thread_inst_size = sizeof(proto_dhcpv4_udp_thread_t), + .bootstrap = mod_bootstrap, + }, .default_message_size = 4096, .track_duplicates = true, diff --git a/src/listen/dhcpv6/proto_dhcpv6.c b/src/listen/dhcpv6/proto_dhcpv6.c index dc4c0da563..5f35c47d93 100644 --- a/src/listen/dhcpv6/proto_dhcpv6.c +++ b/src/listen/dhcpv6/proto_dhcpv6.c @@ -396,15 +396,13 @@ static int mod_open(void *instance, fr_schedule_t *sc, UNUSED CONF_SECTION *conf * * Instantiate I/O and type submodules. * - * @param[in] instance Ctx data for this application. - * @param[in] conf Listen section parsed to give us instance. * @return * - 0 on success. * - -1 on failure. */ -static int mod_instantiate(void *instance, CONF_SECTION *conf) +static int mod_instantiate(module_inst_ctx_t const *mctx) { - proto_dhcpv6_t *inst = talloc_get_type_abort(instance, proto_dhcpv6_t); + proto_dhcpv6_t *inst = talloc_get_type_abort(mctx->inst->data, proto_dhcpv6_t); /* * No IO module, it's an empty listener. @@ -428,27 +426,25 @@ static int mod_instantiate(void *instance, CONF_SECTION *conf) /* * Instantiate the master io submodule */ - return fr_master_app_io.instantiate(&inst->io, conf); + return fr_master_app_io.common.instantiate(MODULE_INST_CTX(inst->io.dl_inst)); } /** Bootstrap the application * * Bootstrap I/O and type submodules. * - * @param[in] instance Ctx data for this application. - * @param[in] conf Listen section parsed to give us instance. * @return * - 0 on success. * - -1 on failure. */ -static int mod_bootstrap(void *instance, CONF_SECTION *conf) +static int mod_bootstrap(module_inst_ctx_t const *mctx) { - proto_dhcpv6_t *inst = talloc_get_type_abort(instance, proto_dhcpv6_t); + proto_dhcpv6_t *inst = talloc_get_type_abort(mctx->inst->data, proto_dhcpv6_t); /* * Ensure that the server CONF_SECTION is always set. */ - inst->io.server_cs = cf_item_to_section(cf_parent(conf)); + inst->io.server_cs = cf_item_to_section(cf_parent(mctx->inst->data)); fr_assert(dict_dhcpv6 != NULL); fr_assert(attr_packet_type != NULL); @@ -485,7 +481,7 @@ static int mod_bootstrap(void *instance, CONF_SECTION *conf) /* * Bootstrap the master IO handler. */ - return fr_master_app_io.bootstrap(&inst->io, conf); + return fr_master_app_io.common.bootstrap(MODULE_INST_CTX(inst->io.dl_inst)); } static int mod_load(void) @@ -504,17 +500,18 @@ static void mod_unload(void) } fr_app_t proto_dhcpv6 = { - .magic = MODULE_MAGIC_INIT, - .name = "dhcpv6", - .config = proto_dhcpv6_config, - .inst_size = sizeof(proto_dhcpv6_t), + .common = { + .magic = MODULE_MAGIC_INIT, + .name = "dhcpv6", + .config = proto_dhcpv6_config, + .inst_size = sizeof(proto_dhcpv6_t), + .onload = mod_load, + .unload = mod_unload, + + .bootstrap = mod_bootstrap, + .instantiate = mod_instantiate + }, .dict = &dict_dhcpv6, - - .onload = mod_load, - .unload = mod_unload, - - .bootstrap = mod_bootstrap, - .instantiate = mod_instantiate, .open = mod_open, .decode = mod_decode, .encode = mod_encode, diff --git a/src/listen/dhcpv6/proto_dhcpv6_udp.c b/src/listen/dhcpv6/proto_dhcpv6_udp.c index 3a02949cf2..50808ef32e 100644 --- a/src/listen/dhcpv6/proto_dhcpv6_udp.c +++ b/src/listen/dhcpv6/proto_dhcpv6_udp.c @@ -453,22 +453,23 @@ static char const *mod_name(fr_listen_t *li) } -static int mod_bootstrap(void *instance, CONF_SECTION *cs) +static int mod_bootstrap(module_inst_ctx_t const *mctx) { - proto_dhcpv6_udp_t *inst = talloc_get_type_abort(instance, proto_dhcpv6_udp_t); + proto_dhcpv6_udp_t *inst = talloc_get_type_abort(mctx->inst->data, proto_dhcpv6_udp_t); size_t num; CONF_ITEM *ci; CONF_SECTION *server_cs; RADCLIENT *client; + CONF_SECTION *conf = mctx->inst->conf; - inst->cs = cs; + inst->cs = conf; /* * Complain if no "ipaddr" is set. */ if (inst->ipaddr.af == AF_UNSPEC) { if (!inst->interface) { - cf_log_err(cs, "No 'ipaddr' was specified in the 'udp' section"); + cf_log_err(conf, "No 'ipaddr' was specified in the 'udp' section"); return -1; } @@ -479,14 +480,14 @@ static int mod_bootstrap(void *instance, CONF_SECTION *cs) */ if (inst->interface && (fr_interface_to_ipaddr(inst->interface, &inst->ipaddr, AF_INET6, true) < 0)) { - cf_log_err(cs, "No 'ipaddr' specified, and we cannot determine one for interface '%s'", + cf_log_err(conf, "No 'ipaddr' specified, and we cannot determine one for interface '%s'", inst->interface); return -1; } } if (inst->ipaddr.af != AF_INET6) { - cf_log_err(cs, "DHCPv6 cannot use IPv4 for 'ipaddr'"); + cf_log_err(conf, "DHCPv6 cannot use IPv4 for 'ipaddr'"); return -1; } @@ -512,7 +513,7 @@ static int mod_bootstrap(void *instance, CONF_SECTION *cs) inst->interface = fr_ipaddr_to_interface(inst, &inst->ipaddr); if (!inst->interface) { interface_fail: - cf_log_err(cs, "No 'interface' specified, and we cannot " + cf_log_err(conf, "No 'interface' specified, and we cannot " "determine one for 'ipaddr = %pV'", fr_box_ipaddr(inst->ipaddr)); return -1; @@ -526,7 +527,7 @@ static int mod_bootstrap(void *instance, CONF_SECTION *cs) if (!inst->interface) goto interface_fail; if (fr_interface_to_ipaddr(inst->interface, &inst->src_ipaddr, AF_INET6, true) < 0) { - cf_log_err(cs, "No 'src_ipaddr' specified, and we cannot determine " + cf_log_err(conf, "No 'src_ipaddr' specified, and we cannot determine " "one for 'ipaddr = %pV and interface '%s'", fr_box_ipaddr(inst->ipaddr), inst->interface); return -1; @@ -538,7 +539,7 @@ static int mod_bootstrap(void *instance, CONF_SECTION *cs) * src_ipaddr must be of the same address family as "ipaddr" */ if (inst->src_ipaddr.af != inst->ipaddr.af) { - cf_log_err(cs, "Both 'ipaddr' and 'src_ipaddr' must be from the same address family"); + cf_log_err(conf, "Both 'ipaddr' and 'src_ipaddr' must be from the same address family"); return -1; } @@ -560,13 +561,13 @@ static int mod_bootstrap(void *instance, CONF_SECTION *cs) struct servent *s; if (!inst->port_name) { - cf_log_err(cs, "No 'port' was specified in the 'udp' section"); + cf_log_err(conf, "No 'port' was specified in the 'udp' section"); return -1; } s = getservbyname(inst->port_name, "udp"); if (!s) { - cf_log_err(cs, "Unknown value for 'port_name = %s", inst->port_name); + cf_log_err(conf, "Unknown value for 'port_name = %s", inst->port_name); return -1; } @@ -580,14 +581,14 @@ static int mod_bootstrap(void *instance, CONF_SECTION *cs) num = talloc_array_length(inst->allow); if (!num) { if (inst->dynamic_clients) { - cf_log_err(cs, "The 'allow' subsection MUST contain at least one 'network' entry when " + cf_log_err(conf, "The 'allow' subsection MUST contain at least one 'network' entry when " "'dynamic_clients = true'."); return -1; } } else { inst->trie = fr_master_io_network(inst, inst->ipaddr.af, inst->allow, inst->deny); if (!inst->trie) { - cf_log_perr(cs, "Failed creating list of networks"); + cf_log_perr(conf, "Failed creating list of networks"); return -1; } } @@ -608,7 +609,7 @@ static int mod_bootstrap(void *instance, CONF_SECTION *cs) if (cf_section_find_next(server_cs, NULL, "client", CF_IDENT_ANY)) { inst->clients = client_list_parse_section(server_cs, IPPROTO_UDP, false); if (!inst->clients) { - cf_log_err(cs, "Failed creating local clients"); + cf_log_err(conf, "Failed creating local clients"); return -1; } } @@ -649,13 +650,14 @@ static RADCLIENT *mod_client_find(fr_listen_t *li, fr_ipaddr_t const *ipaddr, in } fr_app_io_t proto_dhcpv6_udp = { - .magic = MODULE_MAGIC_INIT, - .name = "dhcpv6_udp", - .config = udp_listen_config, - .inst_size = sizeof(proto_dhcpv6_udp_t), - .thread_inst_size = sizeof(proto_dhcpv6_udp_thread_t), - .bootstrap = mod_bootstrap, - + .common = { + .magic = MODULE_MAGIC_INIT, + .name = "dhcpv6_udp", + .config = udp_listen_config, + .inst_size = sizeof(proto_dhcpv6_udp_t), + .thread_inst_size = sizeof(proto_dhcpv6_udp_thread_t), + .bootstrap = mod_bootstrap + }, .default_message_size = 4096, .track_duplicates = true, diff --git a/src/listen/dns/proto_dns.c b/src/listen/dns/proto_dns.c index 7807996988..94f19a6645 100644 --- a/src/listen/dns/proto_dns.c +++ b/src/listen/dns/proto_dns.c @@ -347,15 +347,13 @@ static int mod_open(void *instance, fr_schedule_t *sc, UNUSED CONF_SECTION *conf * * Instantiate I/O and type submodules. * - * @param[in] instance Ctx data for this application. - * @param[in] conf Listen section parsed to give us instance. * @return * - 0 on success. * - -1 on failure. */ -static int mod_instantiate(void *instance, CONF_SECTION *conf) +static int mod_instantiate(module_inst_ctx_t const *mctx) { - proto_dns_t *inst = talloc_get_type_abort(instance, proto_dns_t); + proto_dns_t *inst = talloc_get_type_abort(mctx->inst->data, proto_dns_t); /* * No IO module, it's an empty listener. @@ -379,27 +377,25 @@ static int mod_instantiate(void *instance, CONF_SECTION *conf) /* * Instantiate the master io submodule */ - return fr_master_app_io.instantiate(&inst->io, conf); + return fr_master_app_io.common.instantiate(MODULE_INST_CTX(inst->io.dl_inst)); } /** Bootstrap the application * * Bootstrap I/O and type submodules. * - * @param[in] instance Ctx data for this application. - * @param[in] conf Listen section parsed to give us instance. * @return * - 0 on success. * - -1 on failure. */ -static int mod_bootstrap(void *instance, CONF_SECTION *conf) +static int mod_bootstrap(module_inst_ctx_t const *mctx) { - proto_dns_t *inst = talloc_get_type_abort(instance, proto_dns_t); + proto_dns_t *inst = talloc_get_type_abort(mctx->inst->data, proto_dns_t); /* * Ensure that the server CONF_SECTION is always set. */ - inst->io.server_cs = cf_item_to_section(cf_parent(conf)); + inst->io.server_cs = cf_item_to_section(cf_parent(mctx->inst->data)); fr_assert(dict_dns != NULL); fr_assert(attr_packet_type != NULL); @@ -430,7 +426,7 @@ static int mod_bootstrap(void *instance, CONF_SECTION *conf) /* * Bootstrap the master IO handler. */ - return fr_master_app_io.bootstrap(&inst->io, conf); + return fr_master_app_io.common.bootstrap(MODULE_INST_CTX(inst->io.dl_inst)); } static int mod_load(void) @@ -449,17 +445,19 @@ static void mod_unload(void) } fr_app_t proto_dns = { - .magic = MODULE_MAGIC_INIT, - .name = "dns", - .config = proto_dns_config, - .inst_size = sizeof(proto_dns_t), + .common = { + .magic = MODULE_MAGIC_INIT, + .name = "dns", + .config = proto_dns_config, + .inst_size = sizeof(proto_dns_t), + + .onload = mod_load, + .unload = mod_unload, + + .bootstrap = mod_bootstrap, + .instantiate = mod_instantiate + }, .dict = &dict_dns, - - .onload = mod_load, - .unload = mod_unload, - - .bootstrap = mod_bootstrap, - .instantiate = mod_instantiate, .open = mod_open, .decode = mod_decode, .encode = mod_encode, diff --git a/src/listen/dns/proto_dns_udp.c b/src/listen/dns/proto_dns_udp.c index 3b15303eb4..13c75758e1 100644 --- a/src/listen/dns/proto_dns_udp.c +++ b/src/listen/dns/proto_dns_udp.c @@ -334,22 +334,23 @@ static char const *mod_name(fr_listen_t *li) } -static int mod_bootstrap(void *instance, CONF_SECTION *cs) +static int mod_bootstrap(module_inst_ctx_t const *mctx) { - proto_dns_udp_t *inst = talloc_get_type_abort(instance, proto_dns_udp_t); + proto_dns_udp_t *inst = talloc_get_type_abort(mctx->inst->data, proto_dns_udp_t); + CONF_SECTION *conf = mctx->inst->conf; size_t num; CONF_ITEM *ci; CONF_SECTION *server_cs; RADCLIENT *client; - inst->cs = cs; + inst->cs = conf; /* * Complain if no "ipaddr" is set. */ if (inst->ipaddr.af == AF_UNSPEC) { if (!inst->interface) { - cf_log_err(cs, "No 'ipaddr' was specified in the 'udp' section"); + cf_log_err(conf, "No 'ipaddr' was specified in the 'udp' section"); return -1; } @@ -360,7 +361,7 @@ static int mod_bootstrap(void *instance, CONF_SECTION *cs) */ if (inst->interface && (fr_interface_to_ipaddr(inst->interface, &inst->ipaddr, AF_INET, true) < 0)) { - cf_log_err(cs, "No 'ipaddr' specified, and we cannot determine one for interface '%s'", + cf_log_err(conf, "No 'ipaddr' specified, and we cannot determine one for interface '%s'", inst->interface); return -1; } @@ -382,7 +383,7 @@ static int mod_bootstrap(void *instance, CONF_SECTION *cs) if (num) { inst->trie = fr_master_io_network(inst, inst->ipaddr.af, inst->allow, inst->deny); if (!inst->trie) { - cf_log_perr(cs, "Failed creating list of networks"); + cf_log_perr(conf, "Failed creating list of networks"); return -1; } } @@ -403,7 +404,7 @@ static int mod_bootstrap(void *instance, CONF_SECTION *cs) if (cf_section_find_next(server_cs, NULL, "client", CF_IDENT_ANY)) { inst->clients = client_list_parse_section(server_cs, IPPROTO_UDP, false); if (!inst->clients) { - cf_log_err(cs, "Failed creating local clients"); + cf_log_err(conf, "Failed creating local clients"); return -1; } } @@ -444,13 +445,14 @@ static RADCLIENT *mod_client_find(fr_listen_t *li, fr_ipaddr_t const *ipaddr, in } fr_app_io_t proto_dns_udp = { - .magic = MODULE_MAGIC_INIT, - .name = "dns_udp", - .config = udp_listen_config, - .inst_size = sizeof(proto_dns_udp_t), - .thread_inst_size = sizeof(proto_dns_udp_thread_t), - .bootstrap = mod_bootstrap, - + .common = { + .magic = MODULE_MAGIC_INIT, + .name = "dns_udp", + .config = udp_listen_config, + .inst_size = sizeof(proto_dns_udp_t), + .thread_inst_size = sizeof(proto_dns_udp_thread_t), + .bootstrap = mod_bootstrap + }, .default_message_size = 576, .track_duplicates = false, diff --git a/src/listen/load/proto_load.c b/src/listen/load/proto_load.c index 1de8c44283..481e77f820 100644 --- a/src/listen/load/proto_load.c +++ b/src/listen/load/proto_load.c @@ -244,15 +244,13 @@ static int mod_open(void *instance, fr_schedule_t *sc, UNUSED CONF_SECTION *conf * * Instantiate I/O and type submodules. * - * @param[in] instance Ctx data for this application. - * @param[in] conf Listen section parsed to give us isntance. * @return * - 0 on success. * - -1 on failure. */ -static int mod_instantiate(void *instance, CONF_SECTION *conf) +static int mod_instantiate(module_inst_ctx_t const *mctx) { - proto_load_t *inst = talloc_get_type_abort(instance, proto_load_t); + proto_load_t *inst = talloc_get_type_abort(mctx->inst->data, proto_load_t); fr_assert(inst->io.submodule); @@ -273,22 +271,21 @@ static int mod_instantiate(void *instance, CONF_SECTION *conf) /* * Instantiate the master io submodule */ - return fr_master_app_io.instantiate(&inst->io, conf); + return fr_master_app_io.common.instantiate(MODULE_INST_CTX(inst->io.dl_inst)); } /** Bootstrap the application * * Bootstrap I/O and type submodules. * - * @param[in] instance Ctx data for this application. - * @param[in] conf Listen section parsed to give us instance. * @return * - 0 on success. * - -1 on failure. */ -static int mod_bootstrap(void *instance, CONF_SECTION *conf) +static int mod_bootstrap(module_inst_ctx_t const *mctx) { - proto_load_t *inst = talloc_get_type_abort(instance, proto_load_t); + proto_load_t *inst = talloc_get_type_abort(mctx->inst->data, proto_load_t); + CONF_SECTION *conf = mctx->inst->conf; /* * Ensure that the server CONF_SECTION is always set. @@ -316,7 +313,6 @@ static int mod_bootstrap(void *instance, CONF_SECTION *conf) inst->cs = conf; inst->self = &proto_load; - virtual_server_dict_set(inst->server_cs, inst->dict, false); /* * We will need this for dynamic clients and connected sockets. @@ -327,18 +323,20 @@ static int mod_bootstrap(void *instance, CONF_SECTION *conf) /* * Bootstrap the master IO handler. */ - return fr_master_app_io.bootstrap(&inst->io, conf); + return fr_master_app_io.common.bootstrap(MODULE_INST_CTX(inst->io.dl_inst)); } fr_app_t proto_load = { - .magic = MODULE_MAGIC_INIT, - .name = "load", - .config = proto_load_config, - .inst_size = sizeof(proto_load_t), - - .bootstrap = mod_bootstrap, - .instantiate = mod_instantiate, + .common = { + .magic = MODULE_MAGIC_INIT, + .name = "load", + .config = proto_load_config, + .inst_size = sizeof(proto_load_t), + + .bootstrap = mod_bootstrap, + .instantiate = mod_instantiate + }, .open = mod_open, .decode = mod_decode, .encode = mod_encode, diff --git a/src/listen/load/proto_load_step.c b/src/listen/load/proto_load_step.c index 2e47bfd1d6..cbbcb93dbc 100644 --- a/src/listen/load/proto_load_step.c +++ b/src/listen/load/proto_load_step.c @@ -343,9 +343,10 @@ static char const *mod_name(fr_listen_t *li) } -static int mod_bootstrap(void *instance, CONF_SECTION *cs) +static int mod_bootstrap(module_inst_ctx_t const *mctx) { - proto_load_step_t *inst = talloc_get_type_abort(instance, proto_load_step_t); + proto_load_step_t *inst = talloc_get_type_abort(mctx->inst->data, proto_load_step_t); + CONF_SECTION *conf = mctx->inst->conf; dl_module_inst_t const *dl_inst; /* @@ -353,12 +354,11 @@ static int mod_bootstrap(void *instance, CONF_SECTION *cs) * so we can find out what the parent of our instance * was. */ - dl_inst = dl_module_instance_by_data(instance); + dl_inst = dl_module_instance_by_data(inst); fr_assert(dl_inst); inst->parent = talloc_get_type_abort(dl_inst->parent->data, proto_load_t); - - inst->cs = cs; + inst->cs = conf; FR_INTEGER_BOUND_CHECK("start_pps", inst->load.start_pps, >=, 10); FR_INTEGER_BOUND_CHECK("start_pps", inst->load.start_pps, <, 400000); @@ -390,9 +390,10 @@ static RADCLIENT *mod_client_find(fr_listen_t *li, UNUSED fr_ipaddr_t const *ipa } -static int mod_instantiate(void *instance, CONF_SECTION *cs) +static int mod_instantiate(module_inst_ctx_t const *mctx) { - proto_load_step_t *inst = talloc_get_type_abort(instance, proto_load_step_t); + proto_load_step_t *inst = talloc_get_type_abort(mctx->inst->data, proto_load_step_t); + CONF_SECTION *conf = mctx->inst->conf; RADCLIENT *client; fr_pair_t *vp; @@ -414,13 +415,13 @@ static int mod_instantiate(void *instance, CONF_SECTION *cs) fp = fopen(inst->filename, "r"); if (!fp) { - cf_log_err(cs, "Failed opening %s - %s", + cf_log_err(conf, "Failed opening %s - %s", inst->filename, fr_syserror(errno)); return -1; } if (fr_pair_list_afrom_file(inst, inst->parent->dict, &inst->pair_list, fp, &done) < 0) { - cf_log_perr(cs, "Failed reading %s", inst->filename); + cf_log_perr(conf, "Failed reading %s", inst->filename); fclose(fp); return -1; } @@ -435,14 +436,15 @@ static int mod_instantiate(void *instance, CONF_SECTION *cs) } fr_app_io_t proto_load_step = { - .magic = MODULE_MAGIC_INIT, - .name = "load_step", - .config = load_listen_config, - .inst_size = sizeof(proto_load_step_t), - .thread_inst_size = sizeof(proto_load_step_thread_t), - .bootstrap = mod_bootstrap, - .instantiate = mod_instantiate, - + .common = { + .magic = MODULE_MAGIC_INIT, + .name = "load_step", + .config = load_listen_config, + .inst_size = sizeof(proto_load_step_t), + .thread_inst_size = sizeof(proto_load_step_thread_t), + .bootstrap = mod_bootstrap, + .instantiate = mod_instantiate + }, .default_message_size = 4096, .track_duplicates = false, diff --git a/src/listen/radius/proto_radius.c b/src/listen/radius/proto_radius.c index b9b34a1e63..c1e36a7a28 100644 --- a/src/listen/radius/proto_radius.c +++ b/src/listen/radius/proto_radius.c @@ -476,15 +476,13 @@ static int mod_open(void *instance, fr_schedule_t *sc, UNUSED CONF_SECTION *conf * * Instantiate I/O and type submodules. * - * @param[in] instance Ctx data for this application. - * @param[in] conf Listen section parsed to give us instance. * @return * - 0 on success. * - -1 on failure. */ -static int mod_instantiate(void *instance, CONF_SECTION *conf) +static int mod_instantiate(module_inst_ctx_t const *mctx) { - proto_radius_t *inst = talloc_get_type_abort(instance, proto_radius_t); + proto_radius_t *inst = talloc_get_type_abort(mctx->inst->data, proto_radius_t); /* * No IO module, it's an empty listener. @@ -508,7 +506,7 @@ static int mod_instantiate(void *instance, CONF_SECTION *conf) /* * Instantiate the master io submodule */ - return fr_master_app_io.instantiate(&inst->io, conf); + return fr_master_app_io.common.instantiate(MODULE_INST_CTX(inst->io.dl_inst)); } @@ -516,20 +514,18 @@ static int mod_instantiate(void *instance, CONF_SECTION *conf) * * Bootstrap I/O and type submodules. * - * @param[in] instance Ctx data for this application. - * @param[in] conf Listen section parsed to give us instance. * @return * - 0 on success. * - -1 on failure. */ -static int mod_bootstrap(void *instance, CONF_SECTION *conf) +static int mod_bootstrap(module_inst_ctx_t const *mctx) { - proto_radius_t *inst = talloc_get_type_abort(instance, proto_radius_t); + proto_radius_t *inst = talloc_get_type_abort(mctx->inst->data, proto_radius_t); /* * Ensure that the server CONF_SECTION is always set. */ - inst->io.server_cs = cf_item_to_section(cf_parent(conf)); + inst->io.server_cs = cf_item_to_section(cf_parent(mctx->inst->conf)); /* * No IO module, it's an empty listener. @@ -572,7 +568,7 @@ static int mod_bootstrap(void *instance, CONF_SECTION *conf) /* * Bootstrap the master IO handler. */ - return fr_master_app_io.bootstrap(&inst->io, conf); + return fr_master_app_io.common.bootstrap(MODULE_INST_CTX(inst->io.dl_inst)); } static int mod_load(void) @@ -590,16 +586,17 @@ static void mod_unload(void) } fr_app_t proto_radius = { - .magic = MODULE_MAGIC_INIT, - .name = "radius", - .config = proto_radius_config, - .inst_size = sizeof(proto_radius_t), + .common = { + .magic = MODULE_MAGIC_INIT, + .name = "radius", + .config = proto_radius_config, + .inst_size = sizeof(proto_radius_t), + .onload = mod_load, + .unload = mod_unload, + .bootstrap = mod_bootstrap, + .instantiate = mod_instantiate + }, .dict = &dict_radius, - - .onload = mod_load, - .unload = mod_unload, - .bootstrap = mod_bootstrap, - .instantiate = mod_instantiate, .open = mod_open, .decode = mod_decode, .encode = mod_encode, diff --git a/src/listen/radius/proto_radius_tcp.c b/src/listen/radius/proto_radius_tcp.c index 25043961ad..a9f6c6400a 100644 --- a/src/listen/radius/proto_radius_tcp.c +++ b/src/listen/radius/proto_radius_tcp.c @@ -381,18 +381,19 @@ static char const *mod_name(fr_listen_t *li) } -static int mod_bootstrap(void *instance, CONF_SECTION *cs) +static int mod_bootstrap(module_inst_ctx_t const *mctx) { - proto_radius_tcp_t *inst = talloc_get_type_abort(instance, proto_radius_tcp_t); + proto_radius_tcp_t *inst = talloc_get_type_abort(mctx->inst->data, proto_radius_tcp_t); + CONF_SECTION *conf = mctx->inst->conf; size_t i, num; - inst->cs = cs; + inst->cs = conf; /* * Complain if no "ipaddr" is set. */ if (inst->ipaddr.af == AF_UNSPEC) { - cf_log_err(cs, "No 'ipaddr' was specified in the 'tcp' section"); + cf_log_err(conf, "No 'ipaddr' was specified in the 'tcp' section"); return -1; } @@ -408,13 +409,13 @@ static int mod_bootstrap(void *instance, CONF_SECTION *cs) struct servent *s; if (!inst->port_name) { - cf_log_err(cs, "No 'port' was specified in the 'tcp' section"); + cf_log_err(conf, "No 'port' was specified in the 'tcp' section"); return -1; } s = getservbyname(inst->port_name, "tcp"); if (!s) { - cf_log_err(cs, "Unknown value for 'port_name = %s", inst->port_name); + cf_log_err(conf, "Unknown value for 'port_name = %s", inst->port_name); return -1; } @@ -432,7 +433,7 @@ static int mod_bootstrap(void *instance, CONF_SECTION *cs) num = talloc_array_length(inst->allow); if (!num) { if (inst->dynamic_clients) { - cf_log_err(cs, "The 'allow' subsection MUST contain at least one 'network' entry when 'dynamic_clients = true'."); + cf_log_err(conf, "The 'allow' subsection MUST contain at least one 'network' entry when 'dynamic_clients = true'."); return -1; } } else { @@ -445,7 +446,7 @@ static int mod_bootstrap(void *instance, CONF_SECTION *cs) * Can't add v4 networks to a v6 socket, or vice versa. */ if (inst->allow[i].af != inst->ipaddr.af) { - cf_log_err(cs, "Address family in entry %zd - 'allow = %pV' does not match 'ipaddr'", + cf_log_err(conf, "Address family in entry %zd - 'allow = %pV' does not match 'ipaddr'", i + 1, fr_box_ipaddr(inst->allow[i])); return -1; } @@ -456,7 +457,7 @@ static int mod_bootstrap(void *instance, CONF_SECTION *cs) network = fr_trie_match_by_key(inst->trie, &inst->allow[i].addr, inst->allow[i].prefix); if (network) { - cf_log_err(cs, "Cannot add duplicate entry 'allow = %pV'", + cf_log_err(conf, "Cannot add duplicate entry 'allow = %pV'", fr_box_ipaddr(inst->allow[i])); return -1; } @@ -475,9 +476,9 @@ static int mod_bootstrap(void *instance, CONF_SECTION *cs) network = fr_trie_lookup_by_key(inst->trie, &inst->allow[i].addr, inst->allow[i].prefix); if (network && (network->prefix <= inst->allow[i].prefix)) { - cf_log_err(cs, "Cannot add overlapping entry 'allow = %pV'", + cf_log_err(conf, "Cannot add overlapping entry 'allow = %pV'", fr_box_ipaddr(inst->allow[i])); - cf_log_err(cs, "Entry is completely enclosed inside of a previously defined network"); + cf_log_err(conf, "Entry is completely enclosed inside of a previously defined network"); return -1; } @@ -489,7 +490,7 @@ static int mod_bootstrap(void *instance, CONF_SECTION *cs) if (fr_trie_insert_by_key(inst->trie, &inst->allow[i].addr, inst->allow[i].prefix, &inst->allow[i]) < 0) { - cf_log_err(cs, "Failed adding 'allow = %pV' to tracking table", + cf_log_err(conf, "Failed adding 'allow = %pV' to tracking table", fr_box_ipaddr(inst->allow[i])); return -1; } @@ -512,7 +513,7 @@ static int mod_bootstrap(void *instance, CONF_SECTION *cs) * Can't add v4 networks to a v6 socket, or vice versa. */ if (inst->deny[i].af != inst->ipaddr.af) { - cf_log_err(cs, "Address family in entry %zd - 'deny = %pV' does not match 'ipaddr'", + cf_log_err(conf, "Address family in entry %zd - 'deny = %pV' does not match 'ipaddr'", i + 1, fr_box_ipaddr(inst->deny[i])); return -1; } @@ -523,7 +524,7 @@ static int mod_bootstrap(void *instance, CONF_SECTION *cs) network = fr_trie_match_by_key(inst->trie, &inst->deny[i].addr, inst->deny[i].prefix); if (network) { - cf_log_err(cs, "Cannot add duplicate entry 'deny = %pV'", fr_box_ipaddr(inst->deny[i])); + cf_log_err(conf, "Cannot add duplicate entry 'deny = %pV'", fr_box_ipaddr(inst->deny[i])); return -1; } @@ -533,7 +534,7 @@ static int mod_bootstrap(void *instance, CONF_SECTION *cs) network = fr_trie_lookup_by_key(inst->trie, &inst->deny[i].addr, inst->deny[i].prefix); if (!network) { - cf_log_err(cs, "The network in entry %zd - 'deny = %pV' is not contained " + cf_log_err(conf, "The network in entry %zd - 'deny = %pV' is not contained " "within a previous 'allow'", i + 1, fr_box_ipaddr(inst->deny[i])); return -1; } @@ -544,7 +545,7 @@ static int mod_bootstrap(void *instance, CONF_SECTION *cs) * adding a "deny" inside of a "deny". */ if (network->af != inst->ipaddr.af) { - cf_log_err(cs, "The network in entry %zd - 'deny = %pV' overlaps with " + cf_log_err(conf, "The network in entry %zd - 'deny = %pV' overlaps with " "another 'deny' rule", i + 1, fr_box_ipaddr(inst->deny[i])); return -1; } @@ -557,7 +558,7 @@ static int mod_bootstrap(void *instance, CONF_SECTION *cs) if (fr_trie_insert_by_key(inst->trie, &inst->deny[i].addr, inst->deny[i].prefix, &inst->deny[i]) < 0) { - cf_log_err(cs, "Failed adding 'deny = %pV' to tracking table", + cf_log_err(conf, "Failed adding 'deny = %pV' to tracking table", fr_box_ipaddr(inst->deny[i])); return -1; } @@ -578,13 +579,14 @@ static RADCLIENT *mod_client_find(UNUSED fr_listen_t *li, fr_ipaddr_t const *ipa } fr_app_io_t proto_radius_tcp = { - .magic = MODULE_MAGIC_INIT, - .name = "radius_tcp", - .config = tcp_listen_config, - .inst_size = sizeof(proto_radius_tcp_t), - .thread_inst_size = sizeof(proto_radius_tcp_thread_t), - .bootstrap = mod_bootstrap, - + .common = { + .magic = MODULE_MAGIC_INIT, + .name = "radius_tcp", + .config = tcp_listen_config, + .inst_size = sizeof(proto_radius_tcp_t), + .thread_inst_size = sizeof(proto_radius_tcp_thread_t), + .bootstrap = mod_bootstrap, + }, .default_message_size = 4096, .open = mod_open, diff --git a/src/listen/radius/proto_radius_udp.c b/src/listen/radius/proto_radius_udp.c index 883b14188f..0169d41402 100644 --- a/src/listen/radius/proto_radius_udp.c +++ b/src/listen/radius/proto_radius_udp.c @@ -579,20 +579,21 @@ static char const *mod_name(fr_listen_t *li) } -static int mod_bootstrap(void *instance, CONF_SECTION *cs) +static int mod_bootstrap(module_inst_ctx_t const *mctx) { - proto_radius_udp_t *inst = talloc_get_type_abort(instance, proto_radius_udp_t); + proto_radius_udp_t *inst = talloc_get_type_abort(mctx->inst->data, proto_radius_udp_t); + CONF_SECTION *conf = mctx->inst->conf; size_t num; CONF_ITEM *ci; CONF_SECTION *server_cs; - inst->cs = cs; + inst->cs = conf; /* * Complain if no "ipaddr" is set. */ if (inst->ipaddr.af == AF_UNSPEC) { - cf_log_err(cs, "No 'ipaddr' was specified in the 'udp' section"); + cf_log_err(conf, "No 'ipaddr' was specified in the 'udp' section"); return -1; } @@ -613,13 +614,13 @@ static int mod_bootstrap(void *instance, CONF_SECTION *cs) struct servent *s; if (!inst->port_name) { - cf_log_err(cs, "No 'port' was specified in the 'udp' section"); + cf_log_err(conf, "No 'port' was specified in the 'udp' section"); return -1; } s = getservbyname(inst->port_name, "udp"); if (!s) { - cf_log_err(cs, "Unknown value for 'port_name = %s", inst->port_name); + cf_log_err(conf, "Unknown value for 'port_name = %s", inst->port_name); return -1; } @@ -633,13 +634,13 @@ static int mod_bootstrap(void *instance, CONF_SECTION *cs) num = talloc_array_length(inst->allow); if (!num) { if (inst->dynamic_clients) { - cf_log_err(cs, "The 'allow' subsection MUST contain at least one 'network' entry when 'dynamic_clients = true'."); + cf_log_err(conf, "The 'allow' subsection MUST contain at least one 'network' entry when 'dynamic_clients = true'."); return -1; } } else { inst->trie = fr_master_io_network(inst, inst->ipaddr.af, inst->allow, inst->deny); if (!inst->trie) { - cf_log_perr(cs, "Failed creating list of networks"); + cf_log_perr(conf, "Failed creating list of networks"); return -1; } } @@ -660,7 +661,7 @@ static int mod_bootstrap(void *instance, CONF_SECTION *cs) if (cf_section_find_next(server_cs, NULL, "client", CF_IDENT_ANY)) { inst->clients = client_list_parse_section(server_cs, IPPROTO_UDP, false); if (!inst->clients) { - cf_log_err(cs, "Failed creating local clients"); + cf_log_err(conf, "Failed creating local clients"); return -1; } } @@ -685,13 +686,14 @@ static RADCLIENT *mod_client_find(fr_listen_t *li, fr_ipaddr_t const *ipaddr, in } fr_app_io_t proto_radius_udp = { - .magic = MODULE_MAGIC_INIT, - .name = "radius_udp", - .config = udp_listen_config, - .inst_size = sizeof(proto_radius_udp_t), - .thread_inst_size = sizeof(proto_radius_udp_thread_t), - .bootstrap = mod_bootstrap, - + .common = { + .magic = MODULE_MAGIC_INIT, + .name = "radius_udp", + .config = udp_listen_config, + .inst_size = sizeof(proto_radius_udp_t), + .thread_inst_size = sizeof(proto_radius_udp_thread_t), + .bootstrap = mod_bootstrap + }, .default_message_size = 4096, .track_duplicates = true, diff --git a/src/listen/tacacs/proto_tacacs.c b/src/listen/tacacs/proto_tacacs.c index 3c926a4775..2cf64ea617 100644 --- a/src/listen/tacacs/proto_tacacs.c +++ b/src/listen/tacacs/proto_tacacs.c @@ -457,15 +457,13 @@ static int mod_open(void *instance, fr_schedule_t *sc, UNUSED CONF_SECTION *conf * * Instantiate I/O and type submodules. * - * @param[in] instance Ctx data for this application. - * @param[in] conf Listen section parsed to give us instance. * @return * - 0 on success. * - -1 on failure. */ -static int mod_instantiate(void *instance, CONF_SECTION *conf) +static int mod_instantiate(module_inst_ctx_t const *mctx) { - proto_tacacs_t *inst = talloc_get_type_abort(instance, proto_tacacs_t); + proto_tacacs_t *inst = talloc_get_type_abort(mctx->inst->data, proto_tacacs_t); /* * No IO module, it's an empty listener. @@ -489,7 +487,7 @@ static int mod_instantiate(void *instance, CONF_SECTION *conf) /* * Instantiate the master io submodule */ - return fr_master_app_io.instantiate(&inst->io, conf); + return fr_master_app_io.common.instantiate(MODULE_INST_CTX(inst->io.dl_inst)); } @@ -497,20 +495,18 @@ static int mod_instantiate(void *instance, CONF_SECTION *conf) * * Bootstrap I/O and type submodules. * - * @param[in] instance Ctx data for this application. - * @param[in] conf Listen section parsed to give us instance. * @return * - 0 on success. * - -1 on failure. */ -static int mod_bootstrap(void *instance, CONF_SECTION *conf) +static int mod_bootstrap(module_inst_ctx_t const *mctx) { - proto_tacacs_t *inst = talloc_get_type_abort(instance, proto_tacacs_t); + proto_tacacs_t *inst = talloc_get_type_abort(mctx->inst->data, proto_tacacs_t); /* * Ensure that the server CONF_SECTION is always set. */ - inst->io.server_cs = cf_item_to_section(cf_parent(conf)); + inst->io.server_cs = cf_item_to_section(cf_parent(mctx->inst->conf)); fr_assert(dict_tacacs != NULL); @@ -543,7 +539,7 @@ static int mod_bootstrap(void *instance, CONF_SECTION *conf) /* * Bootstrap the master IO handler. */ - return fr_master_app_io.bootstrap(&inst->io, conf); + return fr_master_app_io.common.bootstrap(MODULE_INST_CTX(inst->io.dl_inst)); } static int mod_load(void) @@ -562,16 +558,18 @@ static void mod_unload(void) } fr_app_t proto_tacacs = { - .magic = MODULE_MAGIC_INIT, - .name = "tacacs", - .config = proto_tacacs_config, - .inst_size = sizeof(proto_tacacs_t), + .common = { + .magic = MODULE_MAGIC_INIT, + .name = "tacacs", + .config = proto_tacacs_config, + .inst_size = sizeof(proto_tacacs_t), + + .onload = mod_load, + .unload = mod_unload, + .bootstrap = mod_bootstrap, + .instantiate = mod_instantiate + }, .dict = &dict_tacacs, - - .onload = mod_load, - .unload = mod_unload, - .bootstrap = mod_bootstrap, - .instantiate = mod_instantiate, .open = mod_open, .decode = mod_decode, .encode = mod_encode, diff --git a/src/listen/tacacs/proto_tacacs_tcp.c b/src/listen/tacacs/proto_tacacs_tcp.c index e73f2c7a9e..a0a62ebcf6 100644 --- a/src/listen/tacacs/proto_tacacs_tcp.c +++ b/src/listen/tacacs/proto_tacacs_tcp.c @@ -379,20 +379,21 @@ static char const *mod_name(fr_listen_t *li) return thread->name; } -static int mod_bootstrap(void *instance, CONF_SECTION *cs) +static int mod_bootstrap(module_inst_ctx_t const *mctx) { - proto_tacacs_tcp_t *inst = talloc_get_type_abort(instance, proto_tacacs_tcp_t); + proto_tacacs_tcp_t *inst = talloc_get_type_abort(mctx->inst->data, proto_tacacs_tcp_t); + CONF_SECTION *conf = mctx->inst->conf; size_t num; CONF_ITEM *ci; CONF_SECTION *server_cs; - inst->cs = cs; + inst->cs = conf; /* * Complain if no "ipaddr" is set. */ if (inst->ipaddr.af == AF_UNSPEC) { - cf_log_err(cs, "No 'ipaddr' was specified in the 'tcp' section"); + cf_log_err(conf, "No 'ipaddr' was specified in the 'tcp' section"); return -1; } @@ -408,13 +409,13 @@ static int mod_bootstrap(void *instance, CONF_SECTION *cs) struct servent *s; if (!inst->port_name) { - cf_log_err(cs, "No 'port' was specified in the 'tcp' section"); + cf_log_err(conf, "No 'port' was specified in the 'tcp' section"); return -1; } s = getservbyname(inst->port_name, "tcp"); if (!s) { - cf_log_err(cs, "Unknown value for 'port_name = %s", inst->port_name); + cf_log_err(conf, "Unknown value for 'port_name = %s", inst->port_name); return -1; } @@ -428,13 +429,13 @@ static int mod_bootstrap(void *instance, CONF_SECTION *cs) num = talloc_array_length(inst->allow); if (!num) { if (inst->dynamic_clients) { - cf_log_err(cs, "The 'allow' subsection MUST contain at least one 'network' entry when 'dynamic_clients = true'."); + cf_log_err(conf, "The 'allow' subsection MUST contain at least one 'network' entry when 'dynamic_clients = true'."); return -1; } } else { inst->trie = fr_master_io_network(inst, inst->ipaddr.af, inst->allow, inst->deny); if (!inst->trie) { - cf_log_perr(cs, "Failed creating list of networks"); + cf_log_perr(conf, "Failed creating list of networks"); return -1; } } @@ -455,7 +456,7 @@ static int mod_bootstrap(void *instance, CONF_SECTION *cs) if (cf_section_find_next(server_cs, NULL, "client", CF_IDENT_ANY)) { inst->clients = client_list_parse_section(server_cs, IPPROTO_TCP, false); if (!inst->clients) { - cf_log_err(cs, "Failed creating local clients"); + cf_log_err(conf, "Failed creating local clients"); return -1; } } @@ -469,13 +470,14 @@ static RADCLIENT *mod_client_find(UNUSED fr_listen_t *li, fr_ipaddr_t const *ipa } fr_app_io_t proto_tacacs_tcp = { - .magic = MODULE_MAGIC_INIT, - .name = "tacacs_tcp", - .config = tcp_listen_config, - .inst_size = sizeof(proto_tacacs_tcp_t), - .thread_inst_size = sizeof(proto_tacacs_tcp_thread_t), - .bootstrap = mod_bootstrap, - + .common = { + .magic = MODULE_MAGIC_INIT, + .name = "tacacs_tcp", + .config = tcp_listen_config, + .inst_size = sizeof(proto_tacacs_tcp_t), + .thread_inst_size = sizeof(proto_tacacs_tcp_thread_t), + .bootstrap = mod_bootstrap, + }, .default_message_size = 4096, .track_duplicates = true, diff --git a/src/listen/vmps/proto_vmps.c b/src/listen/vmps/proto_vmps.c index 250894cf4e..5f88ecf452 100644 --- a/src/listen/vmps/proto_vmps.c +++ b/src/listen/vmps/proto_vmps.c @@ -369,15 +369,13 @@ static int mod_open(void *instance, fr_schedule_t *sc, UNUSED CONF_SECTION *conf * * Instantiate I/O and type submodules. * - * @param[in] instance Ctx data for this application. - * @param[in] conf Listen section parsed to give us instance. * @return * - 0 on success. * - -1 on failure. */ -static int mod_instantiate(void *instance, CONF_SECTION *conf) +static int mod_instantiate(module_inst_ctx_t const *mctx) { - proto_vmps_t *inst = talloc_get_type_abort(instance, proto_vmps_t); + proto_vmps_t *inst = talloc_get_type_abort(mctx->inst->data, proto_vmps_t); /* * No IO module, it's an empty listener. @@ -401,7 +399,7 @@ static int mod_instantiate(void *instance, CONF_SECTION *conf) /* * Instantiate the master io submodule */ - return fr_master_app_io.instantiate(&inst->io, conf); + return fr_master_app_io.common.instantiate(MODULE_INST_CTX(inst->io.dl_inst)); } @@ -409,15 +407,14 @@ static int mod_instantiate(void *instance, CONF_SECTION *conf) * * Bootstrap I/O and type submodules. * - * @param[in] instance Ctx data for this application. - * @param[in] conf Listen section parsed to give us instance. * @return * - 0 on success. * - -1 on failure. */ -static int mod_bootstrap(void *instance, CONF_SECTION *conf) +static int mod_bootstrap(module_inst_ctx_t const *mctx) { - proto_vmps_t *inst = talloc_get_type_abort(instance, proto_vmps_t); + proto_vmps_t *inst = talloc_get_type_abort(mctx->inst->data, proto_vmps_t); + CONF_SECTION *conf = mctx->inst->conf; /* * Ensure that the server CONF_SECTION is always set. @@ -456,7 +453,7 @@ static int mod_bootstrap(void *instance, CONF_SECTION *conf) /* * Bootstrap the master IO handler. */ - return fr_master_app_io.bootstrap(&inst->io, conf); + return fr_master_app_io.common.bootstrap(MODULE_INST_CTX(inst->io.dl_inst)); } static int mod_load(void) @@ -475,16 +472,18 @@ static void mod_unload(void) } fr_app_t proto_vmps = { - .magic = MODULE_MAGIC_INIT, - .name = "vmps", - .config = proto_vmps_config, - .inst_size = sizeof(proto_vmps_t), + .common = { + .magic = MODULE_MAGIC_INIT, + .name = "vmps", + .config = proto_vmps_config, + .inst_size = sizeof(proto_vmps_t), + + .onload = mod_load, + .unload = mod_unload, + .bootstrap = mod_bootstrap, + .instantiate = mod_instantiate + }, .dict = &dict_vmps, - - .onload = mod_load, - .unload = mod_unload, - .bootstrap = mod_bootstrap, - .instantiate = mod_instantiate, .open = mod_open, .decode = mod_decode, .encode = mod_encode, diff --git a/src/listen/vmps/proto_vmps_udp.c b/src/listen/vmps/proto_vmps_udp.c index fed2f6e1fa..62ee498326 100644 --- a/src/listen/vmps/proto_vmps_udp.c +++ b/src/listen/vmps/proto_vmps_udp.c @@ -387,20 +387,21 @@ static int mod_track_compare(UNUSED void const *instance, UNUSED void *thread_in return (a->opcode < b->opcode) - (a->opcode > b->opcode); } -static int mod_bootstrap(void *instance, CONF_SECTION *cs) +static int mod_bootstrap(module_inst_ctx_t const *mctx) { - proto_vmps_udp_t *inst = talloc_get_type_abort(instance, proto_vmps_udp_t); + proto_vmps_udp_t *inst = talloc_get_type_abort(mctx->inst->data, proto_vmps_udp_t); + CONF_SECTION *conf = mctx->inst->conf; size_t num; CONF_ITEM *ci; CONF_SECTION *server_cs; - inst->cs = cs; + inst->cs = conf; /* * Complain if no "ipaddr" is set. */ if (inst->ipaddr.af == AF_UNSPEC) { - cf_log_err(cs, "No 'ipaddr' was specified in the 'udp' section"); + cf_log_err(conf, "No 'ipaddr' was specified in the 'udp' section"); return -1; } @@ -416,13 +417,13 @@ static int mod_bootstrap(void *instance, CONF_SECTION *cs) struct servent *s; if (!inst->port_name) { - cf_log_err(cs, "No 'port' was specified in the 'udp' section"); + cf_log_err(conf, "No 'port' was specified in the 'udp' section"); return -1; } s = getservbyname(inst->port_name, "udp"); if (!s) { - cf_log_err(cs, "Unknown value for 'port_name = %s", inst->port_name); + cf_log_err(conf, "Unknown value for 'port_name = %s", inst->port_name); return -1; } @@ -440,13 +441,13 @@ static int mod_bootstrap(void *instance, CONF_SECTION *cs) num = talloc_array_length(inst->allow); if (!num) { if (inst->dynamic_clients) { - cf_log_err(cs, "The 'allow' subsection MUST contain at least one 'network' entry when 'dynamic_clients = true'."); + cf_log_err(conf, "The 'allow' subsection MUST contain at least one 'network' entry when 'dynamic_clients = true'."); return -1; } } else { inst->trie = fr_master_io_network(inst, inst->ipaddr.af, inst->allow, inst->deny); if (!inst->trie) { - cf_log_perr(cs, "Failed creating list of networks"); + cf_log_perr(conf, "Failed creating list of networks"); return -1; } } @@ -467,7 +468,7 @@ static int mod_bootstrap(void *instance, CONF_SECTION *cs) if (cf_section_find_next(server_cs, NULL, "client", CF_IDENT_ANY)) { inst->clients = client_list_parse_section(server_cs, IPPROTO_UDP, false); if (!inst->clients) { - cf_log_err(cs, "Failed creating local clients"); + cf_log_err(conf, "Failed creating local clients"); return -1; } } @@ -502,13 +503,14 @@ static char const *mod_name(fr_listen_t *li) } fr_app_io_t proto_vmps_udp = { - .magic = MODULE_MAGIC_INIT, - .name = "vmps_udp", - .config = udp_listen_config, - .inst_size = sizeof(proto_vmps_udp_t), - .thread_inst_size = sizeof(proto_vmps_udp_thread_t), - .bootstrap = mod_bootstrap, - + .common = { + .magic = MODULE_MAGIC_INIT, + .name = "vmps_udp", + .config = udp_listen_config, + .inst_size = sizeof(proto_vmps_udp_t), + .thread_inst_size = sizeof(proto_vmps_udp_thread_t), + .bootstrap = mod_bootstrap, + }, .default_message_size = 4096, .track_duplicates = true, -- 2.47.2