]> git.ipfire.org Git - thirdparty/strongswan.git/commitdiff
plugin-loader: Add optional filter for plugin features
authorThomas Egerer <thomas.egerer@secunet.com>
Thu, 28 Jan 2021 17:49:08 +0000 (17:49 +0000)
committerTobias Brunner <tobias@strongswan.org>
Thu, 4 Feb 2021 15:39:27 +0000 (16:39 +0100)
In some cases, the algorithms that have been compiled into a plugin have
to be disabled at runtime. Based on the array returned by the get_features()
function the optionally provided function can strip algorithms or even
callbacks or registrations from a plugin, giving us a handy and powerful way
for runtime feature configuration aside from the plugin list.

Signed-off-by: Thomas Egerer <thomas.egerer@secunet.com>
src/libstrongswan/plugins/plugin_loader.c

index 8e70e5fe812dacf63215c079cc6fc6cbfdad7671..538de2abec2f84880fae79a76357b4a1deb9c136 100644 (file)
@@ -93,6 +93,12 @@ struct private_plugin_loader_t {
                /** Number of features in critical plugins that failed to load */
                int critical;
        } stats;
+
+       /**
+        * Fetch features from the given plugin, can optionally be overridden to
+        * modify feature arrays at loading time
+        */
+       int (*get_features)(plugin_t *plugin, plugin_feature_t *features[]);
 };
 
 /**
@@ -886,6 +892,14 @@ static void load_features(private_plugin_loader_t *this)
        enumerator->destroy(enumerator);
 }
 
+/**
+ * Default implementation for plugin feature retrieval
+ */
+static int get_features_default(plugin_t *plugin, plugin_feature_t *features[])
+{
+       return plugin->get_features(plugin, features);
+}
+
 /**
  * Register plugin features provided by the given plugin
  */
@@ -904,7 +918,7 @@ static void register_features(private_plugin_loader_t *this,
                return;
        }
        reg = NULL;
-       count = entry->plugin->get_features(entry->plugin, &feature);
+       count = this->get_features(entry->plugin, &feature);
        for (i = 0; i < count; i++)
        {
                switch (feature->kind)
@@ -1449,8 +1463,14 @@ plugin_loader_t *plugin_loader_create()
                .features = hashlist_create(
                                                        (hashtable_hash_t)registered_feature_hash,
                                                        (hashtable_equals_t)registered_feature_equals, 64),
+               .get_features = dlsym(RTLD_DEFAULT, "plugin_loader_feature_filter"),
        );
 
+       if (!this->get_features)
+       {
+               this->get_features = get_features_default;
+       }
+
        return &this->public;
 }