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);
}
* 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
*/
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.
* 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.
* 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;
}
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;
}
* 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
* 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;
}
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),
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;
}
}
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);
*/
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;
}
* 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;
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;
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;
*/
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;
* 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);
}
*/
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;
}
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;
}
*/
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);
}
/*
* 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);
}
/*
*/
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;
}
}
-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.
}
}
- 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;
}
/*
* 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;
}
}
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;
}
}
-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;
}
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;
}
};
}
- 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;
}
}
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;
}
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
* 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;
}
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);
}
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,
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));
}
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;
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;
}
*/
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;
}
* 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);
}
}
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);
}
/*
*
* 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;
}
*
* 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;
/*
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;
}
}
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,
}
-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,
*
* 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);
/*
* 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 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.
/*
* 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,
};
}
-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);
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;
}
}
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;
}
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,
*
* 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);
/*
* 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.
/*
* 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,
}
-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;
/*
* 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;
}
}
-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;
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;
}
}
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,
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;
* 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;
}
*
* 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;
}
* 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;
}
}
*
* 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.
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.
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;
}
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;
}
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,
* 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;
}
-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;
* 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__
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;
}
/*
* 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;
}
}
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);
*/
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,
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);
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;
/*
* 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);
*/
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,
*
* 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.
/*
* 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 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);
/*
* 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)
}
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,
}
-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;
}
*/
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;
}
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;
}
* 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
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;
}
}
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;
}
}
}
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,
*
* 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.
/*
* 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);
/*
* 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)
}
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,
}
-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;
}
*/
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;
}
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;
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;
* 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;
}
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;
}
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;
}
}
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;
}
}
}
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,
*
* 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.
/*
* 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);
/*
* 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)
}
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,
}
-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;
}
*/
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;
}
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;
}
}
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;
}
}
}
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,
*
* 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);
/*
* 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.
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.
/*
* 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,
}
-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;
/*
* 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);
}
-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;
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;
}
}
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,
*
* 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.
/*
* 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 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.
/*
* 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)
}
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,
}
-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;
}
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;
}
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 {
* 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;
}
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;
}
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;
}
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;
}
* 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;
}
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;
}
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;
}
* 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;
}
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;
}
}
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,
}
-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;
}
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;
}
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;
}
}
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;
}
}
}
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,
*
* 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.
/*
* 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 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);
/*
* 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)
}
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,
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;
}
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;
}
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;
}
}
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;
}
}
}
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,
*
* 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.
/*
* 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 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.
/*
* 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)
}
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,
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;
}
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;
}
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;
}
}
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;
}
}
}
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,