summaryrefslogtreecommitdiff
path: root/src/devices/nm-device-bond.c
diff options
context:
space:
mode:
authorPavel Šimerda <psimerda@redhat.com>2013-08-28 11:47:44 +0200
committerDan Williams <dcbw@redhat.com>2013-11-08 16:38:49 -0600
commitc90730fa431301916a0af2a1c0645ffb051d7777 (patch)
tree3dbae0d1c555a3f66f016b6c4009228ad12db230 /src/devices/nm-device-bond.c
parenta3af5cfe9d2011f9bec399fe9bffece2ee338441 (diff)
downloadNetworkManager-c90730fa431301916a0af2a1c0645ffb051d7777.tar.gz
core: implement update_connection() for bonds
Diffstat (limited to 'src/devices/nm-device-bond.c')
-rw-r--r--src/devices/nm-device-bond.c62
1 files changed, 54 insertions, 8 deletions
diff --git a/src/devices/nm-device-bond.c b/src/devices/nm-device-bond.c
index 923af8269d..30fa54384f 100644
--- a/src/devices/nm-device-bond.c
+++ b/src/devices/nm-device-bond.c
@@ -184,13 +184,6 @@ complete_connection (NMDevice *device,
return TRUE;
}
-static gboolean
-match_l2_config (NMDevice *self, NMConnection *connection)
-{
- /* FIXME */
- return TRUE;
-}
-
/******************************************************************/
static gboolean
@@ -207,6 +200,57 @@ set_bond_attr (NMDevice *device, const char *attr, const char *value)
return ret;
}
+/* Ignore certain bond options if they are zero (off/disabled) */
+static gboolean
+ignore_if_zero (const char *option, const char *value)
+{
+ if (strcmp (option, "arp_interval") &&
+ strcmp (option, "miimon") &&
+ strcmp (option, "downdelay") &&
+ strcmp (option, "updelay"))
+ return FALSE;
+
+ return g_strcmp0 (value, "0") == 0 ? TRUE : FALSE;
+}
+
+static void
+update_connection (NMDevice *device, NMConnection *connection)
+{
+ NMSettingBond *s_bond = nm_connection_get_setting_bond (connection);
+ const char *ifname = nm_device_get_iface (device);
+ int ifindex = nm_device_get_ifindex (device);
+ const char **options;
+
+ if (!s_bond) {
+ s_bond = (NMSettingBond *) nm_setting_bond_new ();
+ nm_connection_add_setting (connection, (NMSetting *) s_bond);
+ g_object_set (s_bond, NM_SETTING_BOND_INTERFACE_NAME, ifname, NULL);
+ }
+
+ /* Read bond options from sysfs and update the Bond setting to match */
+ options = nm_setting_bond_get_valid_options (s_bond);
+ while (options && *options) {
+ gs_free char *value = nm_platform_master_get_option (ifindex, *options);
+ const char *defvalue = nm_setting_bond_get_option_default (s_bond, *options);
+
+ if (value && !ignore_if_zero (*options, value) && (g_strcmp0 (value, defvalue) != 0)) {
+ /* Replace " " with "," for arp_ip_targets from the kernel */
+ if (strcmp (*options, "arp_ip_target") == 0) {
+ char *p = value;
+
+ while (p && *p) {
+ if (*p == ' ')
+ *p = ',';
+ p++;
+ }
+ }
+
+ nm_setting_bond_add_option (s_bond, *options, value);
+ }
+ options++;
+ }
+}
+
static void
set_arp_targets (NMDevice *device,
const char *value,
@@ -518,6 +562,8 @@ nm_device_bond_class_init (NMDeviceBondClass *klass)
g_type_class_add_private (object_class, sizeof (NMDeviceBondPrivate));
+ parent_class->connection_type = NM_SETTING_BOND_SETTING_NAME;
+
/* virtual methods */
object_class->constructed = constructed;
object_class->get_property = get_property;
@@ -529,7 +575,7 @@ nm_device_bond_class_init (NMDeviceBondClass *klass)
parent_class->check_connection_available = check_connection_available;
parent_class->complete_connection = complete_connection;
- parent_class->match_l2_config = match_l2_config;
+ parent_class->update_connection = update_connection;
parent_class->act_stage1_prepare = act_stage1_prepare;
parent_class->enslave_slave = enslave_slave;