]> git.ipfire.org Git - thirdparty/strongswan.git/commitdiff
plugin-loader: Support a reload() callback for static features
authorMartin Willi <martin@revosec.ch>
Fri, 12 Sep 2014 09:07:22 +0000 (11:07 +0200)
committerMartin Willi <martin@revosec.ch>
Mon, 22 Sep 2014 11:55:12 +0000 (13:55 +0200)
src/charon-nm/nm/nm_backend.c
src/charon-tkm/src/charon-tkm.c
src/charon-tkm/src/tkm/tkm_diffie_hellman.c
src/charon-tkm/tests/tests.c
src/frontends/android/jni/libandroidbridge/charonservice.c
src/libcharon/daemon.c
src/libstrongswan/plugins/plugin_loader.c
src/libstrongswan/plugins/plugin_loader.h
src/pt-tls-client/pt-tls-client.c

index ebebde2c0d18e032f9678d67872051fda661420f..613c2f6b5749466c02989944ff35fbe53265df8d 100644 (file)
@@ -174,5 +174,5 @@ void nm_backend_register()
                                PLUGIN_SDEPEND(CERT_DECODE, CERT_X509),
        };
        lib->plugins->add_static_features(lib->plugins, "nm-backend", features,
-                                                                         countof(features), TRUE);
+                                                                         countof(features), TRUE, NULL, NULL);
 }
index 9a22f9ad9e02e4d651ccba2a30b896bc16dfba88..a6770fc5073940ca82eab21869dd3b148ae384ec 100644 (file)
@@ -296,7 +296,7 @@ int main(int argc, char *argv[])
                        PLUGIN_PROVIDE(CUSTOM, "kernel-ipsec"),
        };
        lib->plugins->add_static_features(lib->plugins, "tkm-backend", features,
-                       countof(features), TRUE);
+                       countof(features), TRUE, NULL, NULL);
 
        if (!register_dh_mapping())
        {
index a34d0b1d4ab1d541f4570f9152e7e00ebe847836..67db5e6d87d66f88ea9fd3f9baed383386d168dc 100644 (file)
@@ -159,7 +159,8 @@ int register_dh_mapping()
        }
        enumerator->destroy(enumerator);
 
-       lib->plugins->add_static_features(lib->plugins, "tkm-dh", f, countof(f), TRUE);
+       lib->plugins->add_static_features(lib->plugins, "tkm-dh", f, countof(f),
+                                                                         TRUE, NULL, NULL);
 
        if (count > 0)
        {
index 18754c717dc3f725ac48bfcdfa9154b05c15dba5..80894a133319c94f38c58dc194dc7ea176dfbf4d 100644 (file)
@@ -64,7 +64,7 @@ static bool test_runner_init(bool init)
                                PLUGIN_PROVIDE(CUSTOM, "kernel-ipsec"),
                };
                lib->plugins->add_static_features(lib->plugins, "tkm-tests", features,
-                                                                                 countof(features), TRUE);
+                                                                                 countof(features), TRUE, NULL, NULL);
 
                lib->settings->set_int(lib->settings, "%s.dh_mapping.%d", 1,
                                                           lib->ns, MODP_3072_BIT);
index 32bf28f098b77d50550d5d3678b9239885885aaf..e6c9126d7ad471c377f058caf815a747cd752c88 100644 (file)
@@ -543,7 +543,7 @@ static void charonservice_init(JNIEnv *env, jobject service, jobject builder,
        charonservice = &this->public;
 
        lib->plugins->add_static_features(lib->plugins, "androidbridge", features,
-                                                                         countof(features), TRUE);
+                                                                         countof(features), TRUE, NULL, NULL);
 
 #ifdef USE_BYOD
        if (byod)
@@ -556,7 +556,7 @@ static void charonservice_init(JNIEnv *env, jobject service, jobject builder,
                };
 
                lib->plugins->add_static_features(lib->plugins, "android-byod",
-                                                               byod_features, countof(byod_features), TRUE);
+                                       byod_features, countof(byod_features), TRUE, NULL, NULL);
        }
 #endif
 }
index a89995a51faada93c714f6f57a3719d9d6db7611..3ae7c4e6f0ba57f552926c3193405692ebf2fd0c 100644 (file)
@@ -593,7 +593,7 @@ METHOD(daemon_t, initialize, bool,
                                PLUGIN_DEPENDS(CUSTOM, "socket"),
        };
        lib->plugins->add_static_features(lib->plugins, lib->ns, features,
-                                                                         countof(features), TRUE);
+                                                                         countof(features), TRUE, NULL, NULL);
 
        /* load plugins, further infrastructure may need it */
        if (!lib->plugins->load(lib->plugins, plugins))
index c23f2f03f7d22bd7e1ccccdf27c35915da3feec5..1fec1b3eaa7c54413ee3082b8336f53cbed2441a 100644 (file)
@@ -217,6 +217,16 @@ typedef struct {
         */
        char *name;
 
+       /**
+        * Optional reload function for features
+        */
+       bool (*reload)(void *data);
+
+       /**
+        * User data to pass to reload function
+        */
+       void *reload_data;
+
        /**
         * Static plugin features
         */
@@ -242,6 +252,16 @@ METHOD(plugin_t, get_static_features, int,
        return this->count;
 }
 
+METHOD(plugin_t, static_reload, bool,
+       static_features_t *this)
+{
+       if (this->reload)
+       {
+               return this->reload(this->reload_data);
+       }
+       return FALSE;
+}
+
 METHOD(plugin_t, static_destroy, void,
        static_features_t *this)
 {
@@ -254,7 +274,8 @@ METHOD(plugin_t, static_destroy, void,
  * Create a wrapper around static plugin features.
  */
 static plugin_t *static_features_create(const char *name,
-                                                                               plugin_feature_t features[], int count)
+                                                                               plugin_feature_t features[], int count,
+                                                                               bool (*reload)(void*), void *reload_data)
 {
        static_features_t *this;
 
@@ -262,9 +283,12 @@ static plugin_t *static_features_create(const char *name,
                .public = {
                        .get_name = _get_static_name,
                        .get_features = _get_static_features,
+                       .reload = _static_reload,
                        .destroy = _static_destroy,
                },
                .name = strdup(name),
+               .reload = reload,
+               .reload_data = reload_data,
                .features = calloc(count, sizeof(plugin_feature_t)),
                .count = count,
        );
@@ -904,12 +928,13 @@ static void purge_plugins(private_plugin_loader_t *this)
 
 METHOD(plugin_loader_t, add_static_features, void,
        private_plugin_loader_t *this, const char *name,
-       plugin_feature_t features[], int count, bool critical)
+       plugin_feature_t features[], int count, bool critical,
+       bool (*reload)(void*), void *reload_data)
 {
        plugin_entry_t *entry;
        plugin_t *plugin;
 
-       plugin = static_features_create(name, features, count);
+       plugin = static_features_create(name, features, count, reload, reload_data);
 
        INIT(entry,
                .plugin = plugin,
index fec57ce981ee9f59b4ba32e5c6bec3128712950d..6be6a909c289e2b6989d80beaf588c4880f3c440 100644 (file)
@@ -44,6 +44,9 @@ struct plugin_loader_t {
         * If critical is TRUE load() will fail if any of the added features could
         * not be loaded.
         *
+        * If a reload callback function is given, it gets invoked for the
+        * registered feature set when reload() is invoked on the plugin_loader.
+        *
         * @note The name should be unique otherwise a plugin with the same name is
         * not loaded.
         *
@@ -51,10 +54,13 @@ struct plugin_loader_t {
         * @param features              array of plugin features
         * @param count                 number of features in the array
         * @param critical              TRUE if the features are critical
+        * @param reload                feature reload callback, or NULL
+        * @param reload_data   user data to pass to reload callback
         */
        void (*add_static_features) (plugin_loader_t *this, const char *name,
                                                                 struct plugin_feature_t *features, int count,
-                                                                bool critical);
+                                                                bool critical, bool (*reload)(void*),
+                                                                void *reload_data);
 
        /**
         * Load a list of plugins.
index 8b41ae25ee8650fd8294886738302840a2feead1..a8d45b54fd041d622a31e305be4ed9ea59a0eb96 100644 (file)
@@ -227,7 +227,7 @@ static void init()
        options = options_create();
 
        lib->plugins->add_static_features(lib->plugins, "pt-tls-client", features,
-                                                                         countof(features), TRUE);
+                                                                         countof(features), TRUE, NULL, NULL);
        if (!lib->plugins->load(lib->plugins,
                        lib->settings->get_str(lib->settings, "pt-tls-client.load", PLUGINS)))
        {