diff --git a/include/mptcpd/plugin.h b/include/mptcpd/plugin.h index 25ff5308..69aeb1b5 100644 --- a/include/mptcpd/plugin.h +++ b/include/mptcpd/plugin.h @@ -345,6 +345,10 @@ MPTCPD_API bool mptcpd_plugin_register_ops( char const *name, struct mptcpd_plugin_ops const *ops); +MPTCPD_API bool mptcpd_plugin_read_config(char const *filename, + mptcpd_parse_func_t fun, + void *user_data); + #ifdef __cplusplus } #endif diff --git a/include/mptcpd/private/plugin.h b/include/mptcpd/private/plugin.h index b8e00ba9..a5ea38c6 100644 --- a/include/mptcpd/private/plugin.h +++ b/include/mptcpd/private/plugin.h @@ -42,6 +42,7 @@ struct mptcpd_interface; */ MPTCPD_API bool mptcpd_plugin_load(char const *dir, char const *default_name, + char const *plugins_conf_dir, struct l_queue const *plugins_to_load, struct mptcpd_pm *pm); diff --git a/lib/plugin.c b/lib/plugin.c index 3d322b42..06df5648 100644 --- a/lib/plugin.c +++ b/lib/plugin.c @@ -39,6 +39,7 @@ # define MPTCP_PM_NAME_LEN GENL_NAMSIZ #endif +#include #include #include @@ -86,6 +87,8 @@ static char _default_name[MPTCP_PM_NAME_LEN + 1]; */ static struct mptcpd_plugin_ops const *_default_ops; +static char *_conf_dir; + // ---------------------------------------------------------------- // Implementation Details // ---------------------------------------------------------------- @@ -432,6 +435,7 @@ static void unload_plugins(struct mptcpd_pm *pm) bool mptcpd_plugin_load(char const *dir, char const *default_name, + char const *plugins_conf_dir, struct l_queue const *plugins_to_load, struct mptcpd_pm *pm) { @@ -440,6 +444,14 @@ bool mptcpd_plugin_load(char const *dir, return false; } + if (plugins_conf_dir == NULL) { + l_error("No plugins configuration directory specified."); + return false; + } + + if (_conf_dir == NULL) + _conf_dir = l_strdup(plugins_conf_dir); + if (_plugin_infos == NULL) _plugin_infos = l_queue_new(); @@ -569,6 +581,25 @@ bool mptcpd_plugin_register_ops(char const *name, return registered; } +bool mptcpd_plugin_read_config(char const *filename, + mptcpd_parse_func_t fun, + void *user_data) +{ + assert(filename != NULL); + assert(fun != NULL); + + char *const path = l_strdup_printf("%s/%s.conf", + _conf_dir, + filename); + + bool success = mptcpd_config_read(path, fun, user_data); + + l_free(path); + + return success; +} + + // ---------------------------------------------------------------- // Plugin Operation Callback Invocation // ---------------------------------------------------------------- diff --git a/src/path_manager.c b/src/path_manager.c index 5ccd849d..4e4234d2 100644 --- a/src/path_manager.c +++ b/src/path_manager.c @@ -826,6 +826,7 @@ static void complete_pm_init(void *data) */ if (!mptcpd_plugin_load(pm->config->plugin_dir, pm->config->default_plugin, + pm->config->plugins_conf_dir, pm->config->plugins_to_load, pm)) { l_error("Unable to load path manager plugins.");