diff options
author | Beniamino Galvani <bgalvani@redhat.com> | 2022-02-22 16:58:46 +0100 |
---|---|---|
committer | Beniamino Galvani <bgalvani@redhat.com> | 2022-03-06 09:12:06 +0100 |
commit | 392daa5dabdbabcd5025a125b3d358aeb2587161 (patch) | |
tree | 55ac283e98163dbb95b97721e3166881d6028dd3 | |
parent | f018afcd538d4eb2267bf5bcb5334db316642107 (diff) | |
download | NetworkManager-392daa5dabdbabcd5025a125b3d358aeb2587161.tar.gz |
core: fall back to loading all known settings plugins
Currently it is possible to specify a list of default settings plugins
to be used when configuration doesn't contain the main.plugins key.
We want to add a mechanism that allows to automatically load any
plugin found in the plugins directory without needing
configuration. This mechanism is useful when plugins are shipped in a
different, optional subpackage, to automatically use them.
With such mechanism, the actual list of plugins will be determined
(in order of evaluation):
1. via explicit user configuration in /etc, if any
2. via distro configuration in /usr, if any
3. using the build-time default, if any
4. looking for known plugins in /usr/lib
-rw-r--r-- | NEWS | 5 | ||||
-rw-r--r-- | config.h.meson | 6 | ||||
-rw-r--r-- | configure.ac | 18 | ||||
-rw-r--r-- | meson.build | 16 | ||||
-rw-r--r-- | src/core/settings/nm-settings.c | 28 |
5 files changed, 46 insertions, 27 deletions
@@ -13,6 +13,11 @@ USE AT YOUR OWN RISK. NOT RECOMMENDED FOR PRODUCTION USE! * libnm: add new dummy crypto backend "null" that does nothing. * Veth devices with name "eth*" are now managed by default via the udev rule. This is to support managing the network in LXD containers. +* When the list of plugins is not specified via "main.plugins" in + NetworkManager.conf and no build-time default is set with + "--with-config-plugins-default" configure argument, now all known + plugins found in the plugin directory are loaded (and the built-in + "keyfile" plugin is preferred over others). ============================================= NetworkManager-1.36 diff --git a/config.h.meson b/config.h.meson index 192246e558..7d1feb53ad 100644 --- a/config.h.meson +++ b/config.h.meson @@ -82,6 +82,12 @@ /* Path to netconfig */ #mesondefine NETCONFIG_PATH +/* Build with ifcfg-rh settings plugin */ +#mesondefine WITH_CONFIG_PLUGIN_IFCFG_RH + +/* Build with ifupdown settings plugin */ +#mesondefine WITH_CONFIG_PLUGIN_IFUPDOWN + /* The default value of the logging.audit configuration option */ #mesondefine NM_CONFIG_DEFAULT_LOGGING_AUDIT diff --git a/configure.ac b/configure.ac index cd373d4d34..46013af1d8 100644 --- a/configure.ac +++ b/configure.ac @@ -185,12 +185,6 @@ AC_ARG_WITH(config-plugins-default, AS_HELP_STRING([--with-config-plugins-default=PLUGINS], [Default configuration option for main.plugins setting, used as fallback if the configuration option is unset]), [config_plugins_default="$withval"], [config_plugins_default=""]) -if test -z "$config_plugins_default" -o "$config_plugins_default" = no; then - config_plugins_default='' - test "$enable_ifcfg_rh" = "yes" && config_plugins_default="$config_plugins_default,ifcfg-rh" - test "$enable_ifupdown" = "yes" && config_plugins_default="$config_plugins_default,ifupdown" - config_plugins_default="${config_plugins_default#,}" -fi AC_DEFINE_UNQUOTED(NM_CONFIG_DEFAULT_MAIN_PLUGINS, "$config_plugins_default", [Default configuration option for main.plugins setting]) @@ -199,6 +193,18 @@ if test "$enable_ifcfg_rh" = "yes"; then fi AC_SUBST(DISTRO_NETWORK_SERVICE) +if test "$enable_ifcfg_rh" = yes; then + AC_DEFINE(WITH_CONFIG_PLUGIN_IFCFG_RH, 1, [Build with ifcfg-rh settings plugin]) +else + AC_DEFINE(WITH_CONFIG_PLUGIN_IFCFG_RH, 0, [Build with ifcfg-rh settings plugin]) +fi + +if test "$enable_ifupdown" = yes; then + AC_DEFINE(WITH_CONFIG_PLUGIN_IFUPDOWN, 1, [Build with ifupdown settings plugin]) +else + AC_DEFINE(WITH_CONFIG_PLUGIN_IFUPDOWN, 0, [Build with ifupdown settings plugin]) +fi + # Code coverage GNOME_CODE_COVERAGE diff --git a/meson.build b/meson.build index c1016e0068..b5c6944659 100644 --- a/meson.build +++ b/meson.build @@ -308,21 +308,11 @@ enable_ifcfg_rh = get_option('ifcfg_rh') or (distro == 'redhat') enable_ifupdown = get_option('ifupdown') or (distro == 'debian') config_plugins_default = get_option('config_plugins_default') -if config_plugins_default == '' - config_plugins = [] - - if enable_ifcfg_rh - config_plugins += ['ifcfg-rh'] - endif - - if enable_ifupdown - config_plugins += ['ifupdown'] - endif - - config_plugins_default = ','.join(config_plugins) -endif config_h.set_quoted('NM_CONFIG_DEFAULT_MAIN_PLUGINS', config_plugins_default) +config_h.set10('WITH_CONFIG_PLUGIN_IFCFG_RH', enable_ifcfg_rh) +config_h.set10('WITH_CONFIG_PLUGIN_IFUPDOWN', enable_ifupdown) + config_h.set_quoted('NM_DIST_VERSION', dist_version) enable_wifi = get_option('wifi') diff --git a/src/core/settings/nm-settings.c b/src/core/settings/nm-settings.c index da09571b0d..6619d3e0a2 100644 --- a/src/core/settings/nm-settings.c +++ b/src/core/settings/nm-settings.c @@ -3266,7 +3266,7 @@ add_plugin(NMSettings *self, NMSettingsPlugin *plugin, const char *pname, const } static gboolean -add_plugin_load_file(NMSettings *self, const char *pname, GError **error) +add_plugin_load_file(NMSettings *self, const char *pname, gboolean ignore_not_found, GError **error) { gs_free char *full_name = NULL; gs_free char *path = NULL; @@ -3281,10 +3281,12 @@ add_plugin_load_file(NMSettings *self, const char *pname, GError **error) if (stat(path, &st) != 0) { errsv = errno; - _LOGW("could not load plugin '%s' from file '%s': %s", - pname, - path, - nm_strerror_native(errsv)); + if (!ignore_not_found) { + _LOGW("could not load plugin '%s' from file '%s': %s", + pname, + path, + nm_strerror_native(errsv)); + } return TRUE; } if (!S_ISREG(st.st_mode)) { @@ -3378,7 +3380,7 @@ load_plugins(NMSettings *self, const char *const *plugins, GError **error) continue; } - success = add_plugin_load_file(self, pname, error); + success = add_plugin_load_file(self, pname, FALSE, error); if (!success) break; } @@ -3872,8 +3874,18 @@ nm_settings_start(NMSettings *self, GError **error) /* Load the plugins; fail if a plugin is not found. */ plugins = nm_config_data_get_plugins(nm_config_get_data_orig(priv->config), TRUE); - if (!load_plugins(self, (const char *const *) plugins, error)) - return FALSE; + if (plugins && plugins[0]) { + if (!load_plugins(self, (const char *const *) plugins, error)) + return FALSE; + } else { + add_plugin_keyfile(self); +#if WITH_CONFIG_PLUGIN_IFCFG_RH + add_plugin_load_file(self, "ifcfg-rh", TRUE, NULL); +#endif +#if WITH_CONFIG_PLUGIN_IFUPDOWN + add_plugin_load_file(self, "ifupdown", TRUE, NULL); +#endif + } for (iter = priv->plugins; iter; iter = iter->next) { NMSettingsPlugin *plugin = NM_SETTINGS_PLUGIN(iter->data); |