settings: merge branch 'bg/ifcfg-migrate-option'

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1700
This commit is contained in:
Fernando Fernandez Mancera 2023-07-25 15:40:02 +02:00
commit 9f01cff04f
13 changed files with 107 additions and 15 deletions

View file

@ -219,6 +219,7 @@ data_edit = sed \
-e 's|@NM_CONFIG_DEFAULT_LOGGING_AUDIT_TEXT[@]|$(NM_CONFIG_DEFAULT_LOGGING_AUDIT_TEXT)|g' \
-e 's|@NM_CONFIG_DEFAULT_MAIN_RC_MANAGER[@]|$(NM_CONFIG_DEFAULT_MAIN_RC_MANAGER)|g' \
-e 's|@NM_CONFIG_DEFAULT_MAIN_DHCP[@]|$(NM_CONFIG_DEFAULT_MAIN_DHCP)|g' \
-e 's|@NM_CONFIG_DEFAULT_MAIN_MIGRATE_IFCFG_RH_TEXT[@]|$(NM_CONFIG_DEFAULT_MAIN_MIGRATE_IFCFG_RH_TEXT)|g' \
-e 's|@NM_CONFIG_DEFAULT_WIFI_BACKEND_TEXT[@]|$(NM_CONFIG_DEFAULT_WIFI_BACKEND_TEXT)|g'
###############################################################################

View file

@ -106,6 +106,9 @@
/* Default configuration option for main.plugins setting */
#mesondefine NM_CONFIG_DEFAULT_MAIN_PLUGINS
/* Default configuration value for main.migrate-ifcfg-rh setting */
#mesondefine NM_CONFIG_DEFAULT_MAIN_MIGRATE_IFCFG_RH
/* Default value for main.rc-manager setting */
#mesondefine NM_CONFIG_DEFAULT_MAIN_RC_MANAGER

View file

@ -409,6 +409,26 @@ AC_DEFINE_UNQUOTED(NM_CONFIG_DEFAULT_LOGGING_BACKEND, "$nm_config_logging_backen
NM_CONFIG_DEFAULT_LOGGING_BACKEND_TEXT="$nm_config_logging_backend_default"
AC_SUBST(NM_CONFIG_DEFAULT_LOGGING_BACKEND_TEXT)
AC_ARG_WITH(config-migrate-ifcfg-rh-default,
AS_HELP_STRING([--with-config-migrate-ifcfg-rh-default=yes|no],
[Default value for main.migrate-ifcfg-rh]),
nm_config_migrate_ifcfg_rh_default="$withval",
nm_config_migrate_ifcfg_rh_default="no")
if test "$nm_config_migrate_ifcfg_rh_default" = yes; then
if test "$enable_ifcfg_rh" = no; then
AC_MSG_ERROR([ifcfg-rh migration can be enabled by default only when the ifcfg-rh plugin is enabled])
fi
AC_DEFINE(NM_CONFIG_DEFAULT_MAIN_MIGRATE_IFCFG_RH, "true", [The default value of the main.migrate-ifcfg-rh configuration option])
NM_CONFIG_DEFAULT_MAIN_MIGRATE_IFCFG_RH_TEXT='true'
elif test "$nm_config_migrate_ifcfg_rh_default" = no; then
AC_DEFINE(NM_CONFIG_DEFAULT_MAIN_MIGRATE_IFCFG_RH, "false", [The default value of the main.migrate-ifcfg-rh configuration option])
NM_CONFIG_DEFAULT_MAIN_MIGRATE_IFCFG_RH_TEXT='false'
else
AC_MSG_ERROR([The value of --with-config-migrate-ifcfg-rh-default must be either "yes" or "no".])
fi
AC_SUBST(NM_CONFIG_DEFAULT_MAIN_MIGRATE_IFCFG_RH_TEXT)
AC_ARG_WITH(config-wifi-backend-default,
AS_HELP_STRING([--with-config-wifi-backend-default=backend],
[Default value for wifi.backend]),
@ -1440,6 +1460,7 @@ echo
echo "Configuration plugins (main.plugins=${config_plugins_default})"
echo " ifcfg-rh: ${enable_ifcfg_rh}"
echo " default value of main.migrate-ifcfg-rh: ${nm_config_migrate_ifcfg_rh_default}"
echo " ifupdown: ${enable_ifupdown}"
echo

View file

@ -528,6 +528,17 @@ no-auto-default=*
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><varname>migrate-ifcfg-rh</varname></term>
<listitem><para>Whether NetworkManager tries to automatically convert
any connection profile stored in ifcfg-rh format to the keyfile format.
Support for ifcfg-rh is deprecated and will be eventually removed. If
enabled, the migration is performed at every startup of the daemon.
The default value is <literal>&NM_CONFIG_DEFAULT_MAIN_MIGRATE_IFCFG_RH_TEXT;</literal>.
</para></listitem>
</varlistentry>
</variablelist>
</refsect1>

View file

@ -8,4 +8,5 @@
<!ENTITY NM_CONFIG_DEFAULT_LOGGING_AUDIT_TEXT "@NM_CONFIG_DEFAULT_LOGGING_AUDIT_TEXT@">
<!ENTITY NM_CONFIG_DEFAULT_MAIN_RC_MANAGER "@NM_CONFIG_DEFAULT_MAIN_RC_MANAGER@">
<!ENTITY NM_CONFIG_DEFAULT_MAIN_DHCP "@NM_CONFIG_DEFAULT_MAIN_DHCP@">
<!ENTITY NM_CONFIG_DEFAULT_MAIN_MIGRATE_IFCFG_RH_TEXT "@NM_CONFIG_DEFAULT_MAIN_MIGRATE_IFCFG_RH_TEXT@">
<!ENTITY NM_CONFIG_DEFAULT_WIFI_BACKEND_TEXT "@NM_CONFIG_DEFAULT_WIFI_BACKEND_TEXT@">

View file

@ -290,6 +290,12 @@ glib_dep = declare_dependency(
enable_ifcfg_rh = get_option('ifcfg_rh')
config_migrate_ifcfg_rh_default = get_option('config_migrate_ifcfg_rh_default').to_string()
if config_migrate_ifcfg_rh_default == 'true'
assert(enable_ifcfg_rh, 'ifcfg-rh migration can be enabled by default only when the ifcfg-rh plugin is enabled')
endif
config_h.set_quoted('NM_CONFIG_DEFAULT_MAIN_MIGRATE_IFCFG_RH', config_migrate_ifcfg_rh_default)
enable_ifupdown = get_option('ifupdown')
if enable_ifupdown == 'auto'
enable_ifupdown = (run_command('test', '-e', '/etc/debian_version').returncode() == 0)
@ -889,6 +895,7 @@ data_conf.set('NM_CONFIG_DEFAULT_LOGGING_BACKEND_TEXT', config_logging_backend_
data_conf.set('NM_CONFIG_DEFAULT_MAIN_AUTH_POLKIT_TEXT', config_auth_polkit_default)
data_conf.set('NM_CONFIG_DEFAULT_MAIN_DHCP', config_dhcp_default)
data_conf.set('NM_CONFIG_DEFAULT_MAIN_RC_MANAGER', config_dns_rc_manager_default)
data_conf.set('NM_CONFIG_DEFAULT_MAIN_MIGRATE_IFCFG_RH_TEXT', config_migrate_ifcfg_rh_default)
data_conf.set('NM_CONFIG_DEFAULT_WIFI_BACKEND_TEXT', config_wifi_backend_default)
data_conf.set('NM_MAJOR_VERSION', nm_major_version)
data_conf.set('NM_MICRO_VERSION', nm_micro_version)
@ -1086,6 +1093,7 @@ output += ' nmtui: ' + enable_nmtui.to_string() + '\n'
output += ' nm-cloud-setup: ' + enable_nm_cloud_setup.to_string() + '\n'
output += '\nConfiguration_plugins (main.plugins=' + config_plugins_default + ')\n'
output += ' ifcfg-rh: ' + enable_ifcfg_rh.to_string() + '\n'
output += ' default value of main.migrate-ifcfg-rh: ' + config_migrate_ifcfg_rh_default + '\n'
output += ' ifupdown: ' + enable_ifupdown.to_string() + '\n'
output += '\nHandlers for /etc/resolv.conf:\n' + resolv_conf_summary
output += '\n'

View file

@ -48,6 +48,7 @@ option('ebpf', type: 'combo', choices: ['auto', 'true', 'false'], description: '
option('config_plugins_default', type: 'string', value: '', description: 'Default configuration option for main.plugins setting, used as fallback if the configuration option is unset')
option('ifcfg_rh', type: 'boolean', value: false, description: 'enable ifcfg-rh configuration plugin (Fedora/RHEL) (deprecated)')
option('ifupdown', type: 'combo', choices:['auto', 'true', 'false'], value: 'auto', description: 'enable ifupdown configuration plugin (Debian/Ubuntu)')
option('config_migrate_ifcfg_rh_default', type: 'boolean', value: false, description: 'The default value of the main.migrate-ifcfg-rh configuration option')
# handlers for resolv.conf
option('resolvconf', type: 'string', value: '', description: 'Enable resolvconf support')

View file

@ -760,6 +760,7 @@ static const struct {
} default_values[] = {
{NM_CONFIG_KEYFILE_GROUP_MAIN, "plugins", NM_CONFIG_DEFAULT_MAIN_PLUGINS},
{NM_CONFIG_KEYFILE_GROUP_MAIN, "rc-manager", NM_CONFIG_DEFAULT_MAIN_RC_MANAGER},
{NM_CONFIG_KEYFILE_GROUP_MAIN, "migrate-ifcfg-rh", NM_CONFIG_DEFAULT_MAIN_MIGRATE_IFCFG_RH},
{NM_CONFIG_KEYFILE_GROUP_MAIN,
NM_CONFIG_KEYFILE_KEY_MAIN_AUTH_POLKIT,
NM_CONFIG_DEFAULT_MAIN_AUTH_POLKIT},

View file

@ -853,6 +853,7 @@ static const ConfigGroup config_groups[] = {
NM_CONFIG_KEYFILE_KEY_MAIN_HOSTNAME_MODE,
NM_CONFIG_KEYFILE_KEY_MAIN_IGNORE_CARRIER,
NM_CONFIG_KEYFILE_KEY_MAIN_IWD_CONFIG_PATH,
NM_CONFIG_KEYFILE_KEY_MAIN_MIGRATE_IFCFG_RH,
NM_CONFIG_KEYFILE_KEY_MAIN_MONITOR_CONNECTION_FILES,
NM_CONFIG_KEYFILE_KEY_MAIN_NO_AUTO_DEFAULT,
NM_CONFIG_KEYFILE_KEY_MAIN_PLUGINS,

View file

@ -150,6 +150,8 @@ extern char *_nm_config_match_env;
#define NM_CONFIG_DEVICE_STATE_DIR "" NMRUNDIR "/devices"
#define NM_CONFIG_DEFAULT_LOGGING_AUDIT_BOOL (nm_streq("" NM_CONFIG_DEFAULT_LOGGING_AUDIT, "true"))
#define NM_CONFIG_DEFAULT_MAIN_MIGRATE_IFCFG_RH_BOOL \
(nm_streq("" NM_CONFIG_DEFAULT_MAIN_MIGRATE_IFCFG_RH, "true"))
typedef enum {
NM_CONFIG_DEVICE_STATE_MANAGED_TYPE_UNKNOWN = -1,

View file

@ -1469,10 +1469,16 @@ static void
_plugin_connections_reload(NMSettings *self)
{
NMSettingsPrivate *priv = NM_SETTINGS_GET_PRIVATE(self);
GSList *iter;
GSList *iter_plugin;
GHashTableIter iter_entry;
SettConnEntry *entry;
gboolean warned = FALSE;
gboolean migrate;
for (iter = priv->plugins; iter; iter = iter->next) {
nm_settings_plugin_reload_connections(iter->data, _plugin_connections_reload_cb, self);
for (iter_plugin = priv->plugins; iter_plugin; iter_plugin = iter_plugin->next) {
nm_settings_plugin_reload_connections(iter_plugin->data,
_plugin_connections_reload_cb,
self);
}
_connection_changed_process_all_dirty(
@ -1485,8 +1491,53 @@ _plugin_connections_reload(NMSettings *self)
| NM_SETTINGS_CONNECTION_UPDATE_REASON_RESET_AGENT_SECRETS
| NM_SETTINGS_CONNECTION_UPDATE_REASON_UPDATE_NON_SECRET);
for (iter = priv->plugins; iter; iter = iter->next)
nm_settings_plugin_load_connections_done(iter->data);
for (iter_plugin = priv->plugins; iter_plugin; iter_plugin = iter_plugin->next)
nm_settings_plugin_load_connections_done(iter_plugin->data);
migrate = nm_config_data_get_value_boolean(nm_config_get_data(priv->config),
NM_CONFIG_KEYFILE_GROUP_MAIN,
NM_CONFIG_KEYFILE_KEY_MAIN_MIGRATE_IFCFG_RH,
NM_CONFIG_DEFAULT_MAIN_MIGRATE_IFCFG_RH_BOOL);
g_hash_table_iter_init(&iter_entry, priv->sce_idx);
while (g_hash_table_iter_next(&iter_entry, (gpointer *) &entry, NULL)) {
const char *plugin;
plugin = nm_settings_plugin_get_plugin_name(nm_settings_storage_get_plugin(entry->storage));
if (nm_streq0(plugin, "ifcfg-rh")) {
if (!warned) {
if (migrate) {
nm_log_warn(
LOGD_SETTINGS,
"Warning: connections were found in ifcfg-rh format and the "
"\"main.migrate-ifcfg-rh\" option is enabled. Those connections will be "
"migrated to keyfile. To convert them back, disable the option and then "
"run \"nmcli connection migrate --plugin ifcfg-rh $UUID\"");
} else {
nm_log_info(
LOGD_SETTINGS,
"Warning: the ifcfg-rh plugin is deprecated, please migrate connections "
"to the keyfile format using \"nmcli connection migrate\"");
}
warned = TRUE;
}
if (migrate) {
_LOGW("migrating connection %s ('%s') from ifcfg-rh to keyfile",
entry->uuid,
nm_settings_connection_get_id(entry->sett_conn));
nm_settings_connection_update(entry->sett_conn,
"keyfile",
NULL,
NM_SETTINGS_CONNECTION_PERSIST_MODE_KEEP,
NM_SETTINGS_CONNECTION_INT_FLAGS_NONE,
NM_SETTINGS_CONNECTION_INT_FLAGS_NONE,
NM_SETTINGS_CONNECTION_UPDATE_REASON_NONE,
"migrate-ifcfg-rh",
NULL);
}
}
}
}
/*****************************************************************************/

View file

@ -52,8 +52,6 @@ typedef struct {
GHashTable *unmanaged_specs;
GHashTable *unrecognized_specs;
gboolean warned;
} NMSIfcfgRHPluginPrivate;
struct _NMSIfcfgRHPlugin {
@ -178,7 +176,6 @@ nm_assert_self(NMSIfcfgRHPlugin *self, gboolean unhandled_specs_consistent)
static NMSIfcfgRHStorage *
_load_file(NMSIfcfgRHPlugin *self, const char *filename, GError **error)
{
NMSIfcfgRHPluginPrivate *priv = NMS_IFCFG_RH_PLUGIN_GET_PRIVATE(self);
NMSIfcfgRHStorage *ret = NULL;
gs_unref_object NMConnection *connection = NULL;
gs_free_error GError *load_error = NULL;
@ -236,13 +233,6 @@ _load_file(NMSIfcfgRHPlugin *self, const char *filename, GError **error)
&st.st_mtim);
}
if (!priv->warned) {
nm_log_info(_NMLOG_DOMAIN,
"Warning: the ifcfg-rh plugin is deprecated, please migrate connections "
"to the keyfile format using \"nmcli connection migrate\".");
priv->warned = TRUE;
}
return ret;
}

View file

@ -30,6 +30,7 @@
#define NM_CONFIG_KEYFILE_KEY_MAIN_HOSTNAME_MODE "hostname-mode"
#define NM_CONFIG_KEYFILE_KEY_MAIN_IGNORE_CARRIER "ignore-carrier"
#define NM_CONFIG_KEYFILE_KEY_MAIN_IWD_CONFIG_PATH "iwd-config-path"
#define NM_CONFIG_KEYFILE_KEY_MAIN_MIGRATE_IFCFG_RH "migrate-ifcfg-rh"
#define NM_CONFIG_KEYFILE_KEY_MAIN_MONITOR_CONNECTION_FILES "monitor-connection-files"
#define NM_CONFIG_KEYFILE_KEY_MAIN_NO_AUTO_DEFAULT "no-auto-default"
#define NM_CONFIG_KEYFILE_KEY_MAIN_PLUGINS "plugins"