From 2566eb2194e3d9581a6b6103e70aa34992eab4f0 Mon Sep 17 00:00:00 2001 From: Thomas Egerer Date: Thu, 28 Jan 2021 17:49:08 +0000 Subject: [PATCH] plugin-loader: Add optional filter for plugin features 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 --- src/libstrongswan/plugins/plugin_loader.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/libstrongswan/plugins/plugin_loader.c b/src/libstrongswan/plugins/plugin_loader.c index 8e70e5fe81..538de2abec 100644 --- a/src/libstrongswan/plugins/plugin_loader.c +++ b/src/libstrongswan/plugins/plugin_loader.c @@ -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; } -- 2.47.2