diff options
author | Thomas Haller <thaller@redhat.com> | 2016-08-24 10:58:41 +0200 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2016-08-24 10:58:41 +0200 |
commit | eb982b9d9442085abc825df7797f4679f7c7c53c (patch) | |
tree | 41cdc9e3e6f77f37f6fb6114686b974b7ba6e9d8 | |
parent | 0a04b55491d98a3450cf1750ec96d4c4c819fa5b (diff) | |
parent | 476810c29016d569ac3885542a6c91e7af8a7f6d (diff) | |
download | NetworkManager-eb982b9d9442085abc825df7797f4679f7c7c53c.tar.gz |
team: merge branch 'th/team-invalid-config-rh1366300'
https://bugzilla.redhat.com/show_bug.cgi?id=1366300
-rw-r--r-- | libnm-core/nm-connection.c | 35 | ||||
-rw-r--r-- | libnm-core/nm-setting-team-port.c | 30 | ||||
-rw-r--r-- | libnm-core/nm-setting-team.c | 11 | ||||
-rw-r--r-- | src/devices/team/nm-device-team.c | 2 |
4 files changed, 66 insertions, 12 deletions
diff --git a/libnm-core/nm-connection.c b/libnm-core/nm-connection.c index 2fd3401c0c..f39d41c58e 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" @@ -907,6 +908,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 && !_nm_utils_check_valid_json (config, NULL)) { + 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 && !_nm_utils_check_valid_json (config, NULL)) { + 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 +1183,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 8d570c9e1c..0d175d5ebd 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,26 @@ 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); + /* 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 36cd312b6e..a559e0db78 100644 --- a/libnm-core/nm-setting-team.c +++ b/libnm-core/nm-setting-team.c @@ -94,10 +94,19 @@ verify (NMSetting *setting, NMConnection *connection, GError **error) "%s.%s: ", NM_SETTING_TEAM_SETTING_NAME, NM_SETTING_TEAM_CONFIG); - return FALSE; + /* 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/src/devices/team/nm-device-team.c b/src/devices/team/nm-device-team.c index d32d3cc9b0..09eefe7014 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; } |