mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager
synced 2024-10-01 13:55:36 +00:00
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
This commit is contained in:
parent
f018afcd53
commit
392daa5dab
5
NEWS
5
NEWS
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
18
configure.ac
18
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
|
||||
|
||||
|
|
16
meson.build
16
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')
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue