summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJiří Klimeš <jklimes@redhat.com>2014-12-17 15:02:58 +0100
committerJiří Klimeš <jklimes@redhat.com>2015-01-12 14:41:35 +0100
commitfb35bb004497651e0fee47fdfc4a1a5791571445 (patch)
tree2c08e47e536c6d173cbc66797111fc5fdfe04475
parent8ffc16e79306d9573ceaee31c6647fbc4ecf6bd4 (diff)
downloadNetworkManager-fb35bb004497651e0fee47fdfc4a1a5791571445.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.c22
-rw-r--r--libnm-core/nm-setting-bond.c22
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