]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
move "bootstrap app_process" into common function
authorAlan T. DeKok <aland@freeradius.org>
Wed, 26 Sep 2018 12:53:13 +0000 (08:53 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Wed, 26 Sep 2018 14:38:58 +0000 (10:38 -0400)
src/lib/io/master.c
src/lib/io/master.h
src/modules/proto_control/proto_control.c
src/modules/proto_dhcpv4/proto_dhcpv4.c
src/modules/proto_radius/proto_radius.c
src/modules/proto_vmps/proto_vmps.c

index 5b279f3e030ef5b9a976237f40ea3e27c63aeee2..77105d4d416b06a59b6a85d4cf20792075d4734c 100644 (file)
@@ -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,
index 9781ba89072385afddd55aaf53eaa9db7f2ebb6c..c53a2d3c5f737e9deb905761766c3f717d53e152 100644 (file)
@@ -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
 }
index 6c04c3d6250df38011b775e0a7b84781310b800e..8e3fb01e995c5091cfc79c561fdf898d73253548 100644 (file)
@@ -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.
index 143ea3fe3a3398ab05db7214eff4e0306889523f..354ca03ec231c9eacbb540c143b028e4d062b37a 100644 (file)
@@ -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.
index 22f2d4970a3cbc254e86d38a6ddf003c9a585d3e..0817b9eed9d6202dc4c4e886878d042955763131 100644 (file)
@@ -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.
index d483bdc6c8e4d16806b27afeab9e25368e358cb9..60df1c82c2b4a7663a29127986985a03e025802e 100644 (file)
@@ -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.