mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-02-05 22:50:28 +01:00
bonding: apply bonding settings when setting up bonding device
Adds a new function nm_system_apply_bonding_config() which applies the parameters specified in the NMSettingBond object via sysfs. Calls that function after creating/updating the bonding master device. If a parameter is not specified in the ifcfg the parameter will be re-initialized to the default value. This may overwrite changes which have been done manually via sysfs but it is the only reliable way of setting up the bond. Supported parameters for now: - mode (default: balance-rr) - miimon (default: 100) - updelay (default: 0) - downdelay (default: 0) - arp_interval (default: 0) - arp_ip_target (default: none) Thomas Graf <tgraf@redhat.com>
This commit is contained in:
parent
d839e1c817
commit
3ef7bca6fa
2 changed files with 71 additions and 0 deletions
|
|
@ -1216,6 +1216,74 @@ nm_system_device_set_priority (int ifindex,
|
|||
}
|
||||
}
|
||||
|
||||
static gboolean
|
||||
set_bond_attr (const char *iface, const char *attr, const char *value)
|
||||
{
|
||||
char file[FILENAME_MAX];
|
||||
gboolean ret;
|
||||
|
||||
snprintf (file, sizeof(file), "/sys/class/net/%s/bonding/%s",
|
||||
iface, attr);
|
||||
|
||||
ret = nm_utils_do_sysctl (file, value);
|
||||
if (!ret)
|
||||
nm_log_warn (LOGD_HW, "(%s): failed to set bonding attribute "
|
||||
"'%s' to '%s'", iface, attr, value);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
set_bond_attr_int (const char *iface, const char *attr,
|
||||
guint32 value)
|
||||
{
|
||||
char buf[128];
|
||||
|
||||
snprintf (buf, sizeof(buf), "%u", value);
|
||||
|
||||
return set_bond_attr (iface, attr, buf);
|
||||
}
|
||||
|
||||
gboolean
|
||||
nm_system_apply_bonding_config (NMSettingBond *s_bond)
|
||||
{
|
||||
const char *name, *val;
|
||||
|
||||
name = nm_setting_bond_get_interface_name (s_bond);
|
||||
g_assert (name);
|
||||
|
||||
if ((val = nm_setting_bond_get_mode (s_bond)))
|
||||
set_bond_attr (name, "mode", val);
|
||||
|
||||
/*
|
||||
* FIXME:
|
||||
*
|
||||
* ifup-eth contains code to append targets if the value is prefixed
|
||||
* with '+':
|
||||
*
|
||||
* if [ "${key}" = "arp_ip_target" -a "${value:0:1}" != "+" ]; then
|
||||
* OLDIFS=$IFS;
|
||||
* IFS=',';
|
||||
* for arp_ip in $value; do
|
||||
* if ! grep -q $arp_ip /sys/class/net/${DEVICE}/bonding/$key; then
|
||||
* echo +$arp_ip > /sys/class/net/${DEVICE}/bonding/$key
|
||||
* fi
|
||||
* done
|
||||
*
|
||||
* Not sure if this is actually being used and it seems dangerous as
|
||||
* the result is pretty much unforeseeable.
|
||||
*/
|
||||
if ((val = nm_setting_bond_get_arp_ip_target (s_bond)))
|
||||
set_bond_attr (name, "arp_ip_target", val);
|
||||
|
||||
set_bond_attr_int (name, "miimon", nm_setting_bond_get_miimon (s_bond));
|
||||
set_bond_attr_int (name, "downdelay", nm_setting_bond_get_downdelay (s_bond));
|
||||
set_bond_attr_int (name, "updelay", nm_setting_bond_get_updelay (s_bond));
|
||||
set_bond_attr_int (name, "arp_interval", nm_setting_bond_get_arp_interval (s_bond));
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* nm_system_add_bonding_master:
|
||||
* @setting: bonding setting
|
||||
|
|
@ -1244,6 +1312,8 @@ nm_system_add_bonding_master (NMSettingBond *setting)
|
|||
return FALSE;
|
||||
}
|
||||
|
||||
nm_system_apply_bonding_config (setting);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -91,6 +91,7 @@ gboolean nm_system_iface_set_mtu (int ifindex, guint32 mtu);
|
|||
|
||||
gboolean nm_system_iface_set_mac (int ifindex, const struct ether_addr *mac);
|
||||
|
||||
gboolean nm_system_apply_bonding_config (NMSettingBond *s_bond);
|
||||
gboolean nm_system_add_bonding_master (NMSettingBond *setting);
|
||||
gboolean nm_system_iface_enslave (NMDevice *slave, NMDevice *master);
|
||||
gboolean nm_system_iface_release (NMDevice *slave, NMDevice *master);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue