From: Alan T. DeKok Date: Wed, 26 Sep 2018 12:53:13 +0000 (-0400) Subject: move "bootstrap app_process" into common function X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=b819e2b5a6bf2daedf1093af6ceb6bd1a2f8eb8f;p=thirdparty%2Ffreeradius-server.git move "bootstrap app_process" into common function --- diff --git a/src/lib/io/master.c b/src/lib/io/master.c index 5b279f3e030..77105d4d416 100644 --- a/src/lib/io/master.c +++ b/src/lib/io/master.c @@ -2731,6 +2731,49 @@ int fr_master_io_listen(TALLOC_CTX *ctx, fr_io_instance_t *inst, fr_schedule_t * return 0; } +int fr_app_process_bootstrap(dl_instance_t **type_submodule, CONF_SECTION *conf, CONF_SECTION *server_cs) +{ + int i = 0; + CONF_PAIR *cp = NULL; + + /* + * Bootstrap the process modules + */ + while ((cp = cf_pair_find_next(conf, cp, "type"))) { + char const *value; + dl_t const *module = talloc_get_type_abort_const(type_submodule[i]->module, dl_t); + fr_app_worker_t const *app_process = (fr_app_worker_t const *)module->common; + + if (app_process->bootstrap && (app_process->bootstrap(type_submodule[i]->data, + type_submodule[i]->conf) < 0)) { + cf_log_err(conf, "Bootstrap failed for \"%s\"", app_process->name); + return -1; + } + + value = cf_pair_value(cp); + + /* + * Add handlers for the virtual server calls. + * This is so that when one virtual server wants + * to call another, it just looks up the data + * here by packet name, and doesn't need to trawl + * through all of the listeners. + */ + if (!cf_data_find(server_cs, fr_io_process_t, value)) { + fr_io_process_t *process_p; + + process_p = talloc(server_cs, fr_io_process_t); + *process_p = app_process->entry_point; + + (void) cf_data_add(server_cs, process_p, value, NULL); + } + + i++; + } + + return 0; +} + fr_app_io_t fr_master_app_io = { .magic = RLM_MODULE_INIT, diff --git a/src/lib/io/master.h b/src/lib/io/master.h index 9781ba89072..c53a2d3c5f7 100644 --- a/src/lib/io/master.h +++ b/src/lib/io/master.h @@ -114,6 +114,7 @@ extern fr_app_io_t fr_master_app_io; fr_trie_t *fr_master_io_network(TALLOC_CTX *ctx, int af, fr_ipaddr_t *allow, fr_ipaddr_t *deny); int fr_master_io_listen(TALLOC_CTX *ctx, fr_io_instance_t *io, fr_schedule_t *sc, size_t default_message_size, size_t num_messages) CC_HINT(nonnull); +int fr_app_process_bootstrap(dl_instance_t **type_submodule, CONF_SECTION *conf, CONF_SECTION *server_cs); #ifdef __cplusplus } diff --git a/src/modules/proto_control/proto_control.c b/src/modules/proto_control/proto_control.c index 6c04c3d6250..8e3fb01e995 100644 --- a/src/modules/proto_control/proto_control.c +++ b/src/modules/proto_control/proto_control.c @@ -531,8 +531,6 @@ static int mod_instantiate(void *instance, CONF_SECTION *conf) static int mod_bootstrap(void *instance, CONF_SECTION *conf) { proto_control_t *inst = talloc_get_type_abort(instance, proto_control_t); - size_t i = 0; - CONF_PAIR *cp = NULL; /* * Ensure that the server CONF_SECTION is always set. @@ -540,41 +538,9 @@ static int mod_bootstrap(void *instance, CONF_SECTION *conf) inst->io.server_cs = cf_item_to_section(cf_parent(conf)); /* - * Bootstrap the process modules + * Bootstrap the app_process modules. */ - while ((cp = cf_pair_find_next(conf, cp, "type"))) { - char const *value; - dl_t const *module = talloc_get_type_abort_const(inst->type_submodule[i]->module, dl_t); - fr_app_worker_t const *app_process = (fr_app_worker_t const *)module->common; - - if (app_process->bootstrap && (app_process->bootstrap(inst->type_submodule[i]->data, - inst->type_submodule[i]->conf) < 0)) { - cf_log_err(conf, "Bootstrap failed for \"%s\"", app_process->name); - return -1; - } - - value = cf_pair_value(cp); - - /* - * Add handlers for the virtual server calls. - * This is so that when one virtual server wants - * to call another, it just looks up the data - * here by packet name, and doesn't need to troll - * through all of the listeners. - */ - if (!cf_data_find(inst->io.server_cs, fr_io_process_t, value)) { - fr_io_process_t *process_p; - - rad_assert(inst->io.server_cs); /* Ensure we don't leak memory */ - - process_p = talloc(inst->io.server_cs, fr_io_process_t); - *process_p = app_process->entry_point; - - (void) cf_data_add(inst->io.server_cs, process_p, value, NULL); - } - - i++; - } + if (fr_app_process_bootstrap(inst->type_submodule, conf, inst->io.server_cs) < 0) return -1; /* * No IO module, it's an empty listener. diff --git a/src/modules/proto_dhcpv4/proto_dhcpv4.c b/src/modules/proto_dhcpv4/proto_dhcpv4.c index 143ea3fe3a3..354ca03ec23 100644 --- a/src/modules/proto_dhcpv4/proto_dhcpv4.c +++ b/src/modules/proto_dhcpv4/proto_dhcpv4.c @@ -678,8 +678,6 @@ static int mod_instantiate(void *instance, CONF_SECTION *conf) static int mod_bootstrap(void *instance, CONF_SECTION *conf) { proto_dhcpv4_t *inst = talloc_get_type_abort(instance, proto_dhcpv4_t); - size_t i = 0; - CONF_PAIR *cp = NULL; /* * Ensure that the server CONF_SECTION is always set. @@ -690,41 +688,9 @@ static int mod_bootstrap(void *instance, CONF_SECTION *conf) rad_assert(attr_message_type != NULL); /* - * Bootstrap the process modules + * Bootstrap the app_process modules. */ - while ((cp = cf_pair_find_next(conf, cp, "type"))) { - char const *value; - dl_t const *module = talloc_get_type_abort_const(inst->type_submodule[i]->module, dl_t); - fr_app_worker_t const *app_process = (fr_app_worker_t const *)module->common; - - if (app_process->bootstrap && (app_process->bootstrap(inst->type_submodule[i]->data, - inst->type_submodule[i]->conf) < 0)) { - cf_log_err(conf, "Bootstrap failed for \"%s\"", app_process->name); - return -1; - } - - value = cf_pair_value(cp); - - /* - * Add handlers for the virtual server calls. - * This is so that when one virtual server wants - * to call another, it just looks up the data - * here by packet name, and doesn't need to troll - * through all of the listeners. - */ - if (!cf_data_find(inst->io.server_cs, fr_io_process_t, value)) { - fr_io_process_t *process_p; - - rad_assert(inst->io.server_cs); /* Ensure we don't leak memory */ - - process_p = talloc(inst->io.server_cs, fr_io_process_t); - *process_p = app_process->entry_point; - - (void) cf_data_add(inst->io.server_cs, process_p, value, NULL); - } - - i++; - } + if (fr_app_process_bootstrap(inst->type_submodule, conf, inst->io.server_cs) < 0) return -1; /* * No IO module, it's an empty listener. diff --git a/src/modules/proto_radius/proto_radius.c b/src/modules/proto_radius/proto_radius.c index 22f2d4970a3..0817b9eed9d 100644 --- a/src/modules/proto_radius/proto_radius.c +++ b/src/modules/proto_radius/proto_radius.c @@ -778,8 +778,6 @@ static int mod_instantiate(void *instance, CONF_SECTION *conf) static int mod_bootstrap(void *instance, CONF_SECTION *conf) { proto_radius_t *inst = talloc_get_type_abort(instance, proto_radius_t); - size_t i = 0; - CONF_PAIR *cp = NULL; /* * Ensure that the server CONF_SECTION is always set. @@ -787,41 +785,9 @@ static int mod_bootstrap(void *instance, CONF_SECTION *conf) inst->io.server_cs = cf_item_to_section(cf_parent(conf)); /* - * Bootstrap the process modules + * Bootstrap the app_process modules. */ - while ((cp = cf_pair_find_next(conf, cp, "type"))) { - char const *value; - dl_t const *module = talloc_get_type_abort_const(inst->type_submodule[i]->module, dl_t); - fr_app_worker_t const *app_process = (fr_app_worker_t const *)module->common; - - if (app_process->bootstrap && (app_process->bootstrap(inst->type_submodule[i]->data, - inst->type_submodule[i]->conf) < 0)) { - cf_log_err(conf, "Bootstrap failed for \"%s\"", app_process->name); - return -1; - } - - value = cf_pair_value(cp); - - /* - * Add handlers for the virtual server calls. - * This is so that when one virtual server wants - * to call another, it just looks up the data - * here by packet name, and doesn't need to trawl - * through all of the listeners. - */ - if (!cf_data_find(inst->io.server_cs, fr_io_process_t, value)) { - fr_io_process_t *process_p; - - rad_assert(inst->io.server_cs); /* Ensure we don't leak memory */ - - process_p = talloc(inst->io.server_cs, fr_io_process_t); - *process_p = app_process->entry_point; - - (void) cf_data_add(inst->io.server_cs, process_p, value, NULL); - } - - i++; - } + if (fr_app_process_bootstrap(inst->type_submodule, conf, inst->io.server_cs) < 0) return -1; /* * No IO module, it's an empty listener. diff --git a/src/modules/proto_vmps/proto_vmps.c b/src/modules/proto_vmps/proto_vmps.c index d483bdc6c8e..60df1c82c2b 100644 --- a/src/modules/proto_vmps/proto_vmps.c +++ b/src/modules/proto_vmps/proto_vmps.c @@ -623,8 +623,6 @@ static int mod_instantiate(void *instance, CONF_SECTION *conf) static int mod_bootstrap(void *instance, CONF_SECTION *conf) { proto_vmps_t *inst = talloc_get_type_abort(instance, proto_vmps_t); - size_t i = 0; - CONF_PAIR *cp = NULL; /* * Ensure that the server CONF_SECTION is always set. @@ -635,41 +633,9 @@ static int mod_bootstrap(void *instance, CONF_SECTION *conf) rad_assert(attr_vmps_packet_type != NULL); /* - * Bootstrap the process modules + * Bootstrap the app_process modules. */ - while ((cp = cf_pair_find_next(conf, cp, "type"))) { - char const *value; - dl_t const *module = talloc_get_type_abort_const(inst->type_submodule[i]->module, dl_t); - fr_app_worker_t const *app_process = (fr_app_worker_t const *)module->common; - - if (app_process->bootstrap && (app_process->bootstrap(inst->type_submodule[i]->data, - inst->type_submodule[i]->conf) < 0)) { - cf_log_err(conf, "Bootstrap failed for \"%s\"", app_process->name); - return -1; - } - - value = cf_pair_value(cp); - - /* - * Add handlers for the virtual server calls. - * This is so that when one virtual server wants - * to call another, it just looks up the data - * here by packet name, and doesn't need to troll - * through all of the listeners. - */ - if (!cf_data_find(inst->io.server_cs, fr_io_process_t, value)) { - fr_io_process_t *process_p; - - rad_assert(inst->io.server_cs); /* Ensure we don't leak memory */ - - process_p = talloc(inst->io.server_cs, fr_io_process_t); - *process_p = app_process->entry_point; - - (void) cf_data_add(inst->io.server_cs, process_p, value, NULL); - } - - i++; - } + if (fr_app_process_bootstrap(inst->type_submodule, conf, inst->io.server_cs) < 0) return -1; /* * No IO module, it's an empty listener.