Commit 4dcfa48c authored by Antonio Cardace's avatar Antonio Cardace

nm-device-bond: use 'set_simple_option()' rather than setting hardcoded values

We should prefer 'set_simple_option()' since it retrieves a value for
the option if set or the default one otherwise.
parent 00dcedc2
......@@ -207,22 +207,8 @@ apply_bonding_config (NMDeviceBond *self)
int ifindex = nm_device_get_ifindex (device);
const char *mode_str, *value;
char *contents;
gboolean set_arp_interval = TRUE;
NMBondMode mode;
/* Option restrictions:
*
* arp_interval conflicts miimon > 0
* arp_interval conflicts [ alb, tlb ]
* arp_validate does not work with [ BOND_MODE_8023AD, BOND_MODE_TLB, BOND_MODE_ALB ]
* downdelay needs miimon
* updelay needs miimon
* primary needs [ active-backup, tlb, alb ]
*
* clearing miimon requires that arp_interval be 0, but clearing
* arp_interval doesn't require miimon to be 0
*/
s_bond = nm_device_get_applied_setting (device, NM_TYPE_SETTING_BOND);
g_return_val_if_fail (s_bond, FALSE);
......@@ -240,38 +226,19 @@ apply_bonding_config (NMDeviceBond *self)
/* Set mode first, as some other options (e.g. arp_interval) are valid
* only for certain modes.
*/
set_bond_attr (device, mode, NM_SETTING_BOND_OPTION_MODE, mode_str);
value = nm_setting_bond_get_option_by_name (s_bond, NM_SETTING_BOND_OPTION_MIIMON);
if (value && atoi (value)) {
/* clear arp interval */
set_bond_attr (device, mode, NM_SETTING_BOND_OPTION_ARP_INTERVAL, "0");
set_arp_interval = FALSE;
set_bond_attr (device, mode, NM_SETTING_BOND_OPTION_MIIMON, value);
if (_nm_utils_ascii_str_to_uint64 (value, 10, 0, G_MAXINT, 0)) {
set_simple_option (device, mode, s_bond, NM_SETTING_BOND_OPTION_MIIMON);
set_simple_option (device, mode, s_bond, NM_SETTING_BOND_OPTION_UPDELAY);
set_simple_option (device, mode, s_bond, NM_SETTING_BOND_OPTION_DOWNDELAY);
} else if (!value) {
/* If not given, and arp_interval is not given or disabled, set to default */
value = nm_setting_bond_get_option_by_name (s_bond, NM_SETTING_BOND_OPTION_ARP_INTERVAL);
if (_nm_utils_ascii_str_to_int64 (value, 10, 0, G_MAXUINT32, 0) == 0)
set_simple_option (device, mode, s_bond, NM_SETTING_BOND_OPTION_MIIMON);
}
if (set_arp_interval) {
} else {
set_simple_option (device, mode, s_bond, NM_SETTING_BOND_OPTION_ARP_INTERVAL);
/* Just let miimon get cleared automatically; even setting miimon to
* 0 (disabled) clears arp_interval.
*/
}
value = nm_setting_bond_get_option_by_name (s_bond, NM_SETTING_BOND_OPTION_ARP_VALIDATE);
set_bond_attr (device, mode, NM_SETTING_BOND_OPTION_ARP_VALIDATE, value ?: "0");
/* Primary */
value = nm_setting_bond_get_option_by_name (s_bond, NM_SETTING_BOND_OPTION_PRIMARY);
set_bond_attr (device, mode, NM_SETTING_BOND_OPTION_PRIMARY, value ?: "");
set_simple_option (device, mode, s_bond, NM_SETTING_BOND_OPTION_ARP_VALIDATE);
set_simple_option (device, mode, s_bond, NM_SETTING_BOND_OPTION_PRIMARY);
/* ARP targets: clear and initialize the list */
contents = nm_platform_sysctl_master_get_option (nm_device_get_platform (device), ifindex,
......
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