diff options
author | Jiří Klimeš <jklimes@redhat.com> | 2014-12-17 15:02:58 +0100 |
---|---|---|
committer | Jiří Klimeš <jklimes@redhat.com> | 2015-01-13 09:35:49 +0100 |
commit | 3d1b6bd4d893fbd73769001a3d2f21432111c884 (patch) | |
tree | dd3559cb77b6e5a9180f47c5e01b4ad597355a4b | |
parent | 93438dd0923fb2ca9dc6ae77a4937d1acd748fa5 (diff) | |
download | NetworkManager-3d1b6bd4d893fbd73769001a3d2f21432111c884.tar.gz |
bond: normalize bond mode to string notation (rh #1171009)
Use descriptive string value as preferred bond mode representation.
Numeric modes still verify but with NM_SETTING_VERIFY_NORMALIZABLE,
suggesting a normalization action.
https://bugzilla.redhat.com/show_bug.cgi?id=1171009
-rw-r--r-- | libnm-core/nm-connection.c | 22 | ||||
-rw-r--r-- | libnm-core/nm-setting-bond.c | 22 |
2 files changed, 41 insertions, 3 deletions
diff --git a/libnm-core/nm-connection.c b/libnm-core/nm-connection.c index 907713bd08..239079e3b1 100644 --- a/libnm-core/nm-connection.c +++ b/libnm-core/nm-connection.c @@ -723,6 +723,27 @@ _normalize_infiniband_mtu (NMConnection *self, GHashTable *parameters) return FALSE; } +static gboolean +_normalize_bond_mode (NMConnection *self, GHashTable *parameters) +{ + NMSettingBond *s_bond = nm_connection_get_setting_bond (self); + + /* Convert mode from numeric to string notation */ + if (s_bond) { + const char *mode = nm_setting_bond_get_option_by_name (s_bond, NM_SETTING_BOND_OPTION_MODE); + int mode_int = nm_utils_bond_mode_string_to_int (mode); + + if (mode_int != -1) { + const char *mode_new = nm_utils_bond_mode_int_to_string (mode_int); + if (g_strcmp0 (mode_new, mode) != 0) { + nm_setting_bond_add_option (s_bond, NM_SETTING_BOND_OPTION_MODE, mode_new); + return TRUE; + } + } + } + return FALSE; +} + /** * nm_connection_verify: * @connection: the #NMConnection to verify @@ -936,6 +957,7 @@ nm_connection_normalize (NMConnection *connection, was_modified |= _normalize_connection_slave_type (connection); was_modified |= _normalize_ip_config (connection, parameters); was_modified |= _normalize_infiniband_mtu (connection, parameters); + was_modified |= _normalize_bond_mode (connection, parameters); /* Verify anew. */ success = _nm_connection_verify (connection, error); diff --git a/libnm-core/nm-setting-bond.c b/libnm-core/nm-setting-bond.c index 9cea9d6a82..5441a090da 100644 --- a/libnm-core/nm-setting-bond.c +++ b/libnm-core/nm-setting-bond.c @@ -441,6 +441,7 @@ verify (NMSetting *setting, NMConnection *connection, GError **error) GHashTableIter iter; const char *key, *value; int mode, miimon = 0, arp_interval = 0; + const char *mode_orig, *mode_new; const char *arp_ip_target = NULL; const char *lacp_rate; const char *primary; @@ -477,7 +478,7 @@ verify (NMSetting *setting, NMConnection *connection, GError **error) } /* Verify bond mode */ - value = g_hash_table_lookup (priv->options, NM_SETTING_BOND_OPTION_MODE); + mode_orig = value = g_hash_table_lookup (priv->options, NM_SETTING_BOND_OPTION_MODE); if (!value) { g_set_error (error, NM_CONNECTION_ERROR, @@ -497,7 +498,7 @@ verify (NMSetting *setting, NMConnection *connection, GError **error) g_prefix_error (error, "%s.%s: ", NM_SETTING_BOND_SETTING_NAME, NM_SETTING_BOND_OPTIONS); return FALSE; } - value = nm_utils_bond_mode_int_to_string (mode); + mode_new = value = nm_utils_bond_mode_int_to_string (mode); /* Make sure mode is compatible with other settings */ if ( strcmp (value, "balance-alb") == 0 @@ -640,7 +641,22 @@ verify (NMSetting *setting, NMConnection *connection, GError **error) return FALSE; } - return _nm_connection_verify_required_interface_name (connection, error); + if (!_nm_connection_verify_required_interface_name (connection, error)) + return FALSE; + + /* *** errors above here should be always fatal, below NORMALIZABLE_ERROR *** */ + + if (g_strcmp0 (mode_orig, mode_new) != 0) { + g_set_error (error, + NM_CONNECTION_ERROR, + NM_CONNECTION_ERROR_INVALID_PROPERTY, + _("'%s' option should be string"), + NM_SETTING_BOND_OPTION_MODE); + g_prefix_error (error, "%s.%s: ", NM_SETTING_BOND_SETTING_NAME, NM_SETTING_BOND_OPTIONS); + return NM_SETTING_VERIFY_NORMALIZABLE; + } + + return TRUE; } static void |