From 9382fb0213e18349f335d2f9d714d9e46a446e83 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 24 Aug 2016 10:30:24 +0200 Subject: [PATCH 1/3] device/team: fix assuming non-NULL team-config in NMDeviceTeam::act_stage1_prepare() (cherry picked from commit 4f6fd1bf0ed57abe3e208664a4de23ee11c67f57) --- src/devices/team/nm-device-team.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/devices/team/nm-device-team.c b/src/devices/team/nm-device-team.c index d32d3cc9b..09eefe701 100644 --- a/src/devices/team/nm-device-team.c +++ b/src/devices/team/nm-device-team.c @@ -575,7 +575,7 @@ act_stage1_prepare (NMDevice *device, NMDeviceStateReason *reason) * have a PID, then we must fail. */ cfg = teamdctl_config_get_raw (priv->tdc); - if (cfg && strcmp (cfg, nm_setting_team_get_config (s_team)) == 0) { + if (cfg && nm_streq0 (cfg, nm_setting_team_get_config (s_team))) { _LOGD (LOGD_TEAM, "using existing matching teamd config"); return NM_ACT_STAGE_RETURN_SUCCESS; } From 5f1662066dcf5143b9065ebb56704a061ca2ffd9 Mon Sep 17 00:00:00 2001 From: Lubomir Rintel Date: Mon, 1 Aug 2016 18:48:15 +0200 Subject: [PATCH 2/3] libnm-core/team: treat "" team config as no config https://bugzilla.redhat.com/show_bug.cgi?id=1366300 (cherry picked from commit 0fc8b856c37374daaf3ec4d95e25e2e670d8d3f5) --- libnm-core/nm-connection.c | 34 +++++++++++++++++++++++++++++++ libnm-core/nm-setting-team-port.c | 22 +++++++++++--------- libnm-core/nm-setting-team.c | 3 ++- 3 files changed, 48 insertions(+), 11 deletions(-) diff --git a/libnm-core/nm-connection.c b/libnm-core/nm-connection.c index 2fd3401c0..57f964095 100644 --- a/libnm-core/nm-connection.c +++ b/libnm-core/nm-connection.c @@ -907,6 +907,38 @@ _normalize_wireless_mac_address_randomization (NMConnection *self, GHashTable *p return FALSE; } +static gboolean +_normalize_team_config (NMConnection *self, GHashTable *parameters) +{ + NMSettingTeam *s_team = nm_connection_get_setting_team (self); + + if (s_team) { + const char *config = nm_setting_team_get_config (s_team); + + if (config && !*config) { + g_object_set (s_team, NM_SETTING_TEAM_CONFIG, NULL, NULL); + return TRUE; + } + } + return FALSE; +} + +static gboolean +_normalize_team_port_config (NMConnection *self, GHashTable *parameters) +{ + NMSettingTeamPort *s_team_port = nm_connection_get_setting_team_port (self); + + if (s_team_port) { + const char *config = nm_setting_team_port_get_config (s_team_port); + + if (config && !*config) { + g_object_set (s_team_port, NM_SETTING_TEAM_PORT_CONFIG, NULL, NULL); + return TRUE; + } + } + return FALSE; +} + /** * nm_connection_verify: * @connection: the #NMConnection to verify @@ -1150,6 +1182,8 @@ nm_connection_normalize (NMConnection *connection, was_modified |= _normalize_infiniband_mtu (connection, parameters); was_modified |= _normalize_bond_mode (connection, parameters); was_modified |= _normalize_wireless_mac_address_randomization (connection, parameters); + was_modified |= _normalize_team_config (connection, parameters); + was_modified |= _normalize_team_port_config (connection, parameters); /* Verify anew. */ success = _nm_connection_verify (connection, error); diff --git a/libnm-core/nm-setting-team-port.c b/libnm-core/nm-setting-team-port.c index 8d570c9e1..123304fee 100644 --- a/libnm-core/nm-setting-team-port.c +++ b/libnm-core/nm-setting-team-port.c @@ -87,16 +87,6 @@ verify (NMSetting *setting, NMConnection *connection, GError **error) { NMSettingTeamPortPrivate *priv = NM_SETTING_TEAM_PORT_GET_PRIVATE (setting); - if (priv->config) { - if (!_nm_utils_check_valid_json (priv->config, error)) { - g_prefix_error (error, - "%s.%s: ", - NM_SETTING_TEAM_PORT_SETTING_NAME, - NM_SETTING_TEAM_PORT_CONFIG); - return FALSE; - } - } - if (connection) { NMSettingConnection *s_con; const char *slave_type; @@ -125,6 +115,18 @@ verify (NMSetting *setting, NMConnection *connection, GError **error) return FALSE; } } + + if (priv->config) { + if (!_nm_utils_check_valid_json (priv->config, error)) { + g_prefix_error (error, + "%s.%s: ", + NM_SETTING_TEAM_PORT_SETTING_NAME, + NM_SETTING_TEAM_PORT_CONFIG); + /* We treat an empty string as no config for compatibility. */ + return *priv->config ? FALSE : NM_SETTING_VERIFY_NORMALIZABLE; + } + } + return TRUE; } diff --git a/libnm-core/nm-setting-team.c b/libnm-core/nm-setting-team.c index 36cd312b6..df89694f6 100644 --- a/libnm-core/nm-setting-team.c +++ b/libnm-core/nm-setting-team.c @@ -94,7 +94,8 @@ verify (NMSetting *setting, NMConnection *connection, GError **error) "%s.%s: ", NM_SETTING_TEAM_SETTING_NAME, NM_SETTING_TEAM_CONFIG); - return FALSE; + /* We treat an empty string as no config for compatibility. */ + return *priv->config ? FALSE : NM_SETTING_VERIFY_NORMALIZABLE; } } From 5b9f7169eda94ec829f28df7d385be0e62482bb8 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 24 Aug 2016 09:59:06 +0200 Subject: [PATCH 3/3] libnm-core/team: normalize invalid config to NULL A user may very well have connections on disk with bogus json. Such connections may have failed to activate before, but rejecting them now as invalid means that we stop loading them from disk. That is, they disappear after upgrade. Instead of doing that, also accept invalid json (beside "") and normalize/coerce it to NULL. https://bugzilla.redhat.com/show_bug.cgi?id=1366300 (cherry picked from commit 476810c29016d569ac3885542a6c91e7af8a7f6d) --- libnm-core/nm-connection.c | 5 +++-- libnm-core/nm-setting-team-port.c | 12 ++++++++++-- libnm-core/nm-setting-team.c | 12 ++++++++++-- 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/libnm-core/nm-connection.c b/libnm-core/nm-connection.c index 57f964095..f39d41c58 100644 --- a/libnm-core/nm-connection.c +++ b/libnm-core/nm-connection.c @@ -28,6 +28,7 @@ #include "nm-connection.h" #include "nm-connection-private.h" #include "nm-utils.h" +#include "nm-utils-private.h" #include "nm-setting-private.h" #include "nm-core-internal.h" @@ -915,7 +916,7 @@ _normalize_team_config (NMConnection *self, GHashTable *parameters) if (s_team) { const char *config = nm_setting_team_get_config (s_team); - if (config && !*config) { + if (config && !_nm_utils_check_valid_json (config, NULL)) { g_object_set (s_team, NM_SETTING_TEAM_CONFIG, NULL, NULL); return TRUE; } @@ -931,7 +932,7 @@ _normalize_team_port_config (NMConnection *self, GHashTable *parameters) if (s_team_port) { const char *config = nm_setting_team_port_get_config (s_team_port); - if (config && !*config) { + if (config && !_nm_utils_check_valid_json (config, NULL)) { g_object_set (s_team_port, NM_SETTING_TEAM_PORT_CONFIG, NULL, NULL); return TRUE; } diff --git a/libnm-core/nm-setting-team-port.c b/libnm-core/nm-setting-team-port.c index 123304fee..0d175d5eb 100644 --- a/libnm-core/nm-setting-team-port.c +++ b/libnm-core/nm-setting-team-port.c @@ -122,11 +122,19 @@ verify (NMSetting *setting, NMConnection *connection, GError **error) "%s.%s: ", NM_SETTING_TEAM_PORT_SETTING_NAME, NM_SETTING_TEAM_PORT_CONFIG); - /* We treat an empty string as no config for compatibility. */ - return *priv->config ? FALSE : NM_SETTING_VERIFY_NORMALIZABLE; + /* for backward compatibility, we accept invalid json and normalize it */ + if (!priv->config[0]) { + /* be more forgiving to "" and let it verify() as valid because + * at least anaconda used to write such configs */ + return NM_SETTING_VERIFY_NORMALIZABLE; + } + return NM_SETTING_VERIFY_NORMALIZABLE_ERROR; } } + /* NOTE: normalizable/normalizable-errors must appear at the end with decreasing severity. + * Take care to properly order statements with priv->config above. */ + return TRUE; } diff --git a/libnm-core/nm-setting-team.c b/libnm-core/nm-setting-team.c index df89694f6..a559e0db7 100644 --- a/libnm-core/nm-setting-team.c +++ b/libnm-core/nm-setting-team.c @@ -94,11 +94,19 @@ verify (NMSetting *setting, NMConnection *connection, GError **error) "%s.%s: ", NM_SETTING_TEAM_SETTING_NAME, NM_SETTING_TEAM_CONFIG); - /* We treat an empty string as no config for compatibility. */ - return *priv->config ? FALSE : NM_SETTING_VERIFY_NORMALIZABLE; + /* for backward compatibility, we accept invalid json and normalize it */ + if (!priv->config[0]) { + /* be more forgiving to "" and let it verify() as valid because + * at least anaconda used to write such configs */ + return NM_SETTING_VERIFY_NORMALIZABLE; + } + return NM_SETTING_VERIFY_NORMALIZABLE_ERROR; } } + /* NOTE: normalizable/normalizable-errors must appear at the end with decreasing severity. + * Take care to properly order statements with priv->config above. */ + return TRUE; }