load-tester: Register kernel-ipsec implementation as plugin feature
[strongswan.git] / src / libcharon / plugins / load_tester / load_tester_plugin.c
index 4a982d4..a0c467e 100644 (file)
@@ -18,6 +18,7 @@
 #include "load_tester_creds.h"
 #include "load_tester_ipsec.h"
 #include "load_tester_listener.h"
+#include "load_tester_control.h"
 #include "load_tester_diffie_hellman.h"
 
 #include <unistd.h>
@@ -51,6 +52,11 @@ struct private_load_tester_plugin_t {
        load_tester_creds_t *creds;
 
        /**
+        * Unix control socket to initiate load-tests
+        */
+       load_tester_control_t *control;
+
+       /**
         * event handler, listens on bus
         */
        load_tester_listener_t *listener;
@@ -146,7 +152,7 @@ static job_requeue_t do_load_test(private_load_tester_plugin_t *this)
 
                charon->controller->initiate(charon->controller,
                                        peer_cfg, child_cfg->get_ref(child_cfg),
-                                       NULL, NULL, 0);
+                                       NULL, NULL, 0, FALSE);
                if (s)
                {
                        sleep(s);
@@ -181,16 +187,17 @@ static bool register_load_tester(private_load_tester_plugin_t *this,
 
                this->config = load_tester_config_create();
                this->creds = load_tester_creds_create();
+               this->control = load_tester_control_create();
 
                charon->backends->add_backend(charon->backends, &this->config->backend);
                lib->credmgr->add_set(lib->credmgr, &this->creds->credential_set);
 
                if (lib->settings->get_bool(lib->settings,
-                               "%s.plugins.load-tester.shutdown_when_complete", 0, charon->name))
+                               "%s.plugins.load-tester.shutdown_when_complete", 0, lib->ns))
                {
                        shutdown_on = this->iterations * this->initiators;
                }
-               this->listener = load_tester_listener_create(shutdown_on);
+               this->listener = load_tester_listener_create(shutdown_on, this->config);
                charon->bus->add_listener(charon->bus, &this->listener->listener);
 
                for (i = 0; i < this->initiators; i++)
@@ -215,6 +222,7 @@ static bool register_load_tester(private_load_tester_plugin_t *this,
                this->config->destroy(this->config);
                this->creds->destroy(this->creds);
                this->listener->destroy(this->listener);
+               this->control->destroy(this->control);
        }
        return TRUE;
 }
@@ -228,19 +236,28 @@ METHOD(plugin_t, get_features, int,
                                PLUGIN_DEPENDS(CUSTOM, "load-tester"),
                PLUGIN_CALLBACK((plugin_feature_callback_t)register_load_tester, NULL),
                        PLUGIN_PROVIDE(CUSTOM, "load-tester"),
+                               PLUGIN_DEPENDS(CUSTOM, "kernel-net"),
                                PLUGIN_SDEPEND(PRIVKEY, KEY_RSA),
                                PLUGIN_SDEPEND(CERT_DECODE, CERT_ANY),
                                PLUGIN_SDEPEND(CERT_DECODE, CERT_X509),
+               PLUGIN_CALLBACK(kernel_ipsec_register, load_tester_ipsec_create),
+                       PLUGIN_PROVIDE(CUSTOM, "kernel-ipsec"),
        };
+       int count = countof(f);
+
        *features = f;
-       return countof(f);
+
+       if (!lib->settings->get_bool(lib->settings,
+                       "%s.plugins.load-tester.fake_kernel", FALSE, lib->ns))
+       {
+               count -= 2;
+       }
+       return count;
 }
 
 METHOD(plugin_t, destroy, void,
        private_load_tester_plugin_t *this)
 {
-       hydra->kernel_interface->remove_ipsec_interface(hydra->kernel_interface,
-                                               (kernel_ipsec_constructor_t)load_tester_ipsec_create);
        this->mutex->destroy(this->mutex);
        this->condvar->destroy(this->condvar);
        free(this);
@@ -253,8 +270,8 @@ plugin_t *load_tester_plugin_create()
 {
        private_load_tester_plugin_t *this;
 
-       if (!lib->settings->get_bool(lib->settings,
-                                               "%s.plugins.load-tester.enable", FALSE, charon->name))
+       if (!lib->settings->get_bool(lib->settings, "%s.plugins.load-tester.enable",
+                                                                FALSE, lib->ns))
        {
                DBG1(DBG_CFG, "disabling load-tester plugin, not configured");
                return NULL;
@@ -270,23 +287,15 @@ plugin_t *load_tester_plugin_create()
                        },
                },
                .delay = lib->settings->get_int(lib->settings,
-                                               "%s.plugins.load-tester.delay", 0, charon->name),
+                                                       "%s.plugins.load-tester.delay", 0, lib->ns),
                .iterations = lib->settings->get_int(lib->settings,
-                                               "%s.plugins.load-tester.iterations", 1, charon->name),
+                                                       "%s.plugins.load-tester.iterations", 1, lib->ns),
                .initiators = lib->settings->get_int(lib->settings,
-                                               "%s.plugins.load-tester.initiators", 0, charon->name),
+                                                       "%s.plugins.load-tester.initiators", 0, lib->ns),
                .init_limit = lib->settings->get_int(lib->settings,
-                                               "%s.plugins.load-tester.init_limit", 0, charon->name),
+                                                       "%s.plugins.load-tester.init_limit", 0, lib->ns),
                .mutex = mutex_create(MUTEX_TYPE_DEFAULT),
                .condvar = condvar_create(CONDVAR_TYPE_DEFAULT),
        );
-
-       if (lib->settings->get_bool(lib->settings,
-                       "%s.plugins.load-tester.fake_kernel", FALSE, charon->name))
-       {
-               hydra->kernel_interface->add_ipsec_interface(hydra->kernel_interface,
-                                               (kernel_ipsec_constructor_t)load_tester_ipsec_create);
-       }
        return &this->public.plugin;
 }
-