]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
add mod_bootstrap to io.c
authorAlan T. DeKok <aland@freeradius.org>
Wed, 25 Apr 2018 15:01:12 +0000 (11:01 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Wed, 25 Apr 2018 16:53:45 +0000 (12:53 -0400)
and move code from proto_radius over there

src/modules/proto_radius/io.c
src/modules/proto_radius/proto_radius.c
src/modules/proto_radius/proto_radius.h

index b120f536ae72004bac1eb4e562a8f3a1745d01a9..db05d1ff3c671a4315210f68b2de5c7d3326b2b6 100644 (file)
@@ -2005,13 +2005,56 @@ static int mod_detach(void *instance)
        return 0;
 }
 
+static int mod_bootstrap(void *instance, CONF_SECTION *cs)
+{
+       proto_radius_t *inst = instance;
+
+       /*
+        *      Bootstrap the protocol agnostic IO handler.
+        */
+       inst->io.server_cs = cf_item_to_section(cf_parent(cs));
+
+       /*
+        *      We will need this for dynamic clients and connected sockets.
+        */
+       inst->io.dl_inst = dl_instance_find(inst);
+       rad_assert(inst != NULL);
+
+       /*
+        *      Find and bootstrap the application IO handler.
+        */
+       inst->io.app_io = (fr_app_io_t const *) inst->io.submodule->module->common;
+
+       inst->io.app_io_instance = inst->io.submodule->data;
+       inst->io.app_io_conf = inst->io.submodule->conf;
+
+       if (inst->io.app_io->bootstrap && (inst->io.app_io->bootstrap(inst->io.app_io_instance,
+                                                               inst->io.app_io_conf) < 0)) {
+               cf_log_err(inst->io.app_io_conf, "Bootstrap failed for \"%s\"", inst->io.app_io->name);
+               return -1;
+       }
+
+       /*
+        *      @todo - move these to public APIs
+        */
+       inst->app_io_private = inst->io.app_io->private;
+       rad_assert(inst->app_io_private != NULL);
+
+       /*
+        *      Get various information after bootstrapping the
+        *      application IO module.
+        */
+       inst->app_io_private->network_get(inst->io.app_io_instance, &inst->io.ipproto, &inst->io.dynamic_clients, &inst->io.networks);
+
+       return 0;
+}
 
 fr_app_io_t proto_radius_master_io = {
        .magic                  = RLM_MODULE_INIT,
        .name                   = "radius_master_io",
 
        .detach                 = mod_detach,
-//     .bootstrap              = mod_bootstrap,
+       .bootstrap              = mod_bootstrap,
 //     .instantiate            = mod_instantiate,
 
        .default_message_size   = 4096,
index 1938208adb562706826cad7156a89a8860a5d07c..41ed8c486944a14c8ac2e69af6caade7c32bb66f 100644 (file)
@@ -60,7 +60,7 @@ static CONF_PARSER const limit_config[] = {
 static CONF_PARSER const proto_radius_config[] = {
        { FR_CONF_OFFSET("type", FR_TYPE_VOID | FR_TYPE_MULTI | FR_TYPE_NOT_EMPTY, proto_radius_t,
                          type_submodule), .func = type_parse },
-       { FR_CONF_OFFSET("transport", FR_TYPE_VOID, proto_radius_t, io_submodule),
+       { FR_CONF_OFFSET("transport", FR_TYPE_VOID, proto_radius_t, io.submodule),
          .func = transport_parse },
 
        /*
@@ -876,44 +876,21 @@ static int mod_bootstrap(void *instance, CONF_SECTION *conf)
        /*
         *      No IO module, it's an empty listener.
         */
-       if (!inst->io_submodule) return 0;
+       if (!inst->io.submodule) return 0;
 
        /*
-        *      Bootstrap the protocol agnostic IO handler.
+        *      Tell the master handler about the main protocol instance.
         */
-       inst->io.server_cs = cf_item_to_section(cf_parent(conf));
        inst->io.app = &proto_radius;
        inst->io.app_instance = inst;
 
        /*
-        *      We will need this for dynamic clients and connected sockets.
+        *      Bootstrap the master IO handler.
         */
-       inst->io.dl_inst = dl_instance_find(inst);
-       rad_assert(inst != NULL);
-
-       /*
-        *      Bootstrap the application IO handler.
-        */
-       inst->io.app_io = (fr_app_io_t const *) inst->io_submodule->module->common;
-
-       inst->io.app_io_instance = inst->io_submodule->data;
-       inst->io.app_io_conf = inst->io_submodule->conf;
-
-       inst->app_io_private = inst->io.app_io->private;
-       rad_assert(inst->app_io_private != NULL);
-
-       if (inst->io.app_io->bootstrap && (inst->io.app_io->bootstrap(inst->io.app_io_instance,
-                                                               inst->io.app_io_conf) < 0)) {
-               cf_log_err(inst->io.app_io_conf, "Bootstrap failed for \"%s\"", inst->io.app_io->name);
+       if (proto_radius_master_io.bootstrap(inst, conf) < 0) {
                return -1;
        }
 
-       /*
-        *      Get various information after bootstrapping the
-        *      application IO module.
-        */
-       inst->app_io_private->network_get(inst->io.app_io_instance, &inst->io.ipproto, &inst->io.dynamic_clients, &inst->io.networks);
-
        /*
         *      Load proto_radius_dynamic_client
         */
index 79410e5262588b73a2803f4b449b10f95f508e53..69712c6aab641eeb2c27047f4a03addf0ad9ec06 100644 (file)
@@ -172,6 +172,10 @@ typedef struct {
 
        CONF_SECTION                    *server_cs;                     //!< server CS for this listener
 
+       dl_instance_t                   *submodule;                     //!< As provided by the transport_parse
+                                                                       ///< callback.  Broken out into the
+                                                                       ///< app_io_* fields below for convenience.
+
        fr_app_t                        *app;                           //!< main protocol handler
        void                            *app_instance;                  //!< instance data for main protocol handler
 
@@ -203,9 +207,6 @@ typedef struct proto_radius_t {
        fr_io_instance_t                io;                             //!< wrapper for IO abstraction
 
        dl_instance_t const             *dl_inst;                       //!< our dl_inst
-       dl_instance_t                   *io_submodule;                  //!< As provided by the transport_parse
-                                                                       ///< callback.  Broken out into the
-                                                                       ///< app_io_* fields below for convenience.
 
        proto_radius_app_io_t           *app_io_private;                //!< Internal interface for proto_radius.