mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-05-08 06:38:11 +02:00
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
This commit is contained in:
parent
93438dd092
commit
3d1b6bd4d8
2 changed files with 41 additions and 3 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue