From 056a973a4fdb68abe8bc7bfc5f31250345d71f21 Mon Sep 17 00:00:00 2001 From: Beniamino Galvani Date: Mon, 5 Jun 2017 14:48:08 +0200 Subject: [PATCH] bond: add only supported options to the generated connection Upstream commit [1] changed in the kernel the default value of tlb_dynamic_lb bond from 1 to 0 when the mode is not tlb. This is not wrong, as the option value doesn't really matter for other modes, but it breaks the connection matching because we read back a 0 value when we expect a default of 1. Fix this in a generic way by ignoring altogether options that are not relevant for the current bond mode, because they are removed from the connection during normalization. [1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=8b426dc54cf4056984bab7dfa48c92ee79a46434 https://bugzilla.redhat.com/show_bug.cgi?id=1457909 --- src/devices/nm-device-bond.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/devices/nm-device-bond.c b/src/devices/nm-device-bond.c index 18291397db..a964fa37d9 100644 --- a/src/devices/nm-device-bond.c +++ b/src/devices/nm-device-bond.c @@ -155,6 +155,7 @@ update_connection (NMDevice *device, NMConnection *connection) { NMSettingBond *s_bond = nm_connection_get_setting_bond (connection); int ifindex = nm_device_get_ifindex (device); + NMBondMode mode = NM_BOND_MODE_UNKNOWN; const char **options; if (!s_bond) { @@ -164,7 +165,7 @@ update_connection (NMDevice *device, NMConnection *connection) /* Read bond options from sysfs and update the Bond setting to match */ options = nm_setting_bond_get_valid_options (s_bond); - while (options && *options) { + for (; *options; options++) { gs_free char *value = nm_platform_sysctl_master_get_option (nm_device_get_platform (device), ifindex, *options); const char *defvalue = nm_setting_bond_get_option_default (s_bond, *options); char *p; @@ -176,6 +177,12 @@ update_connection (NMDevice *device, NMConnection *connection) *p = '\0'; } + if (nm_streq (*options, NM_SETTING_BOND_OPTION_MODE)) + mode = _nm_setting_bond_mode_from_string (value); + + if (!_nm_setting_bond_option_supported (*options, mode)) + continue; + if ( value && value[0] && !ignore_if_zero (*options, value) @@ -190,7 +197,6 @@ update_connection (NMDevice *device, NMConnection *connection) nm_setting_bond_add_option (s_bond, *options, value); } - options++; } }