Blame SOURCES/1004-fix-warning-setting-bond-active-slave-rh1858326.patch

063fa4
From cb125986922b6e0bd33d68306f1602b19ea1a3de Mon Sep 17 00:00:00 2001
063fa4
From: Thomas Haller <thaller@redhat.com>
063fa4
Date: Tue, 14 Jul 2020 09:16:51 +0200
063fa4
Subject: [PATCH 1/1] bond: avoid setting "active_slave" option without
063fa4
 interface enslaved
063fa4
063fa4
Kernel will reject setting "active_slave", if the interface is not enslaved or not
063fa4
up. We already handle that by setting the option whenever we enslave an interface.
063fa4
However, we also must not set it initially, otherwise we get an ugly error log message:
063fa4
063fa4
    NetworkManager[939]: <debug> [1594709143.7459] platform-linux: sysctl: setting net:/sys/class/net/bond99/bonding/active_slave to eth1 (current value is )
063fa4
    NetworkManager[939]: <error> [1594709143.7459] platform-linux: sysctl: failed to set bonding/active_slave to eth1: (22) Invalid argument
063fa4
    NetworkManager[939]: <warn>  [1594709143.7460] device (bond99): failed to set bonding attribute active_slave to eth1
063fa4
    ...
063fa4
    kernel: bond99: (slave eth1): Device is not bonding slave
063fa4
    kernel: bond99: option active_slave: invalid value (eth1)
063fa4
063fa4
See-also: https://bugzilla.redhat.com/show_bug.cgi?id=1856640
063fa4
063fa4
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/577
063fa4
(cherry picked from commit f0a39b517e06470c4b176ef0bbd49c2eef1d7ad7)
063fa4
(cherry picked from commit e48c908e8cb5e0b426a4bf8d99608f73cd7890e4)
063fa4
---
063fa4
 src/devices/nm-device-bond.c | 43 +++++++++++++++++++++++++++++++-----
063fa4
 1 file changed, 38 insertions(+), 5 deletions(-)
063fa4
063fa4
diff --git a/src/devices/nm-device-bond.c b/src/devices/nm-device-bond.c
063fa4
index 2fedc753f350..e36eba61b0b2 100644
063fa4
--- a/src/devices/nm-device-bond.c
063fa4
+++ b/src/devices/nm-device-bond.c
063fa4
@@ -8,6 +8,7 @@
063fa4
 #include "nm-device-bond.h"
063fa4
 
063fa4
 #include <stdlib.h>
063fa4
+#include <net/if.h>
063fa4
 
063fa4
 #include "NetworkManagerUtils.h"
063fa4
 #include "nm-device-private.h"
063fa4
@@ -261,6 +262,40 @@ set_bond_attr_or_default (NMDevice *device,
063fa4
 	_set_bond_attr (device, opt, value);
063fa4
 }
063fa4
 
063fa4
+static void
063fa4
+set_bond_attr_active_slave (NMDevice *device, NMSettingBond *s_bond)
063fa4
+{
063fa4
+	NMDeviceBond *self = NM_DEVICE_BOND (device);
063fa4
+	const NMPlatformLink *plink;
063fa4
+	const char *value;
063fa4
+	const char *error_reason;
063fa4
+	int ifindex;
063fa4
+
063fa4
+	value = nm_setting_bond_get_option_or_default (s_bond, NM_SETTING_BOND_OPTION_ACTIVE_SLAVE);
063fa4
+	if (!value)
063fa4
+		return;
063fa4
+
063fa4
+	if (!nm_str_is_empty (value)) {
063fa4
+		ifindex = nm_device_get_ifindex (device);
063fa4
+		plink = nm_platform_link_get_by_ifname (nm_device_get_platform (device), value);
063fa4
+		if (!plink)
063fa4
+			error_reason = "does not exist";
063fa4
+		else if (plink->master != ifindex)
063fa4
+			error_reason = "is not yet enslaved";
063fa4
+		else if (!NM_FLAGS_HAS (plink->n_ifi_flags, IFF_UP))
063fa4
+			error_reason = "is not up";
063fa4
+		else
063fa4
+			error_reason = NULL;
063fa4
+
063fa4
+		if (error_reason) {
063fa4
+			_LOGT (LOGD_BOND, "bond option 'active_slave' not set as device \"%s\" %s", value, error_reason);
063fa4
+			return;
063fa4
+		}
063fa4
+	}
063fa4
+
063fa4
+	_set_bond_attr (device, NM_SETTING_BOND_OPTION_ACTIVE_SLAVE, value);
063fa4
+}
063fa4
+
063fa4
 static gboolean
063fa4
 apply_bonding_config (NMDeviceBond *self)
063fa4
 {
063fa4
@@ -300,7 +335,7 @@ apply_bonding_config (NMDeviceBond *self)
063fa4
 	                 nm_setting_bond_get_option_or_default (s_bond, NM_SETTING_BOND_OPTION_ARP_IP_TARGET));
063fa4
 
063fa4
 	set_bond_attr_or_default (device, s_bond, NM_SETTING_BOND_OPTION_AD_ACTOR_SYSTEM);
063fa4
-	set_bond_attr_or_default (device, s_bond, NM_SETTING_BOND_OPTION_ACTIVE_SLAVE);
063fa4
+	set_bond_attr_active_slave (device, s_bond);
063fa4
 	set_bond_attr_or_default (device, s_bond, NM_SETTING_BOND_OPTION_AD_ACTOR_SYS_PRIO);
063fa4
 	set_bond_attr_or_default (device, s_bond, NM_SETTING_BOND_OPTION_AD_SELECT);
063fa4
 	set_bond_attr_or_default (device, s_bond, NM_SETTING_BOND_OPTION_AD_USER_PORT_KEY);
063fa4
@@ -378,7 +413,7 @@ enslave_slave (NMDevice *device,
063fa4
 				if (nm_streq0 (active, nm_device_get_iface (slave))) {
063fa4
 					nm_platform_sysctl_master_set_option (nm_device_get_platform (device),
063fa4
 					                                      nm_device_get_ifindex (device),
063fa4
-					                                      "active_slave",
063fa4
+					                                      NM_SETTING_BOND_OPTION_ACTIVE_SLAVE,
063fa4
 					                                      active);
063fa4
 					_LOGD (LOGD_BOND, "setting slave %s as active one for master %s",
063fa4
 					       active, nm_device_get_iface (device));
063fa4
@@ -577,10 +612,8 @@ reapply_connection (NMDevice *device, NMConnection *con_old, NMConnection *con_n
063fa4
 	mode = _nm_setting_bond_mode_from_string (value);
063fa4
 	g_return_if_fail (mode != NM_BOND_MODE_UNKNOWN);
063fa4
 
063fa4
-	/* Primary */
063fa4
 	set_bond_attr_or_default (device, s_bond, NM_SETTING_BOND_OPTION_PRIMARY);
063fa4
-	/* Active slave */
063fa4
-	set_bond_attr_or_default (device, s_bond, NM_SETTING_BOND_OPTION_ACTIVE_SLAVE);
063fa4
+	set_bond_attr_active_slave (device, s_bond);
063fa4
 }
063fa4
 
063fa4
 /*****************************************************************************/
063fa4
-- 
063fa4
2.26.2
063fa4