Commit 3d1b6bd4 authored by Jiří Klimeš's avatar Jiří Klimeš

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
parent 93438dd0
......@@ -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);
......
......@@ -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
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment