Blame SOURCES/1000-bond-avoid-logging-warning-to-set-ad_actor_system-00.patch

964b59
From 9f90c590d73eb86e357bf4a854af41b73039342c Mon Sep 17 00:00:00 2001
964b59
From: Thomas Haller <thaller@redhat.com>
964b59
Date: Tue, 23 Feb 2021 13:28:10 +0100
964b59
Subject: [PATCH 1/1] bond: avoid logging warning to set
964b59
 "ad_actor_system=00:00:00:00:00:00"
964b59
964b59
The bond option ad_actor_system only matters (and is available) with
964b59
mode=802.3ad.
964b59
964b59
When you create a new bond, the sysctl value will be set to "00:00:00:00:00:00".
964b59
So this seems to be a valid value, and in fact the default value for
964b59
this option. However, kernel will fail with EINVAL to set the sysctl to
964b59
"00:00:00:00:00:00". Kernel fails both if the value is already
964b59
"00:00:00:00:00:00" (i.e. setting the same value results in an error) and
964b59
it also fails otherwise (i.e. we cannot ever reset the value to
964b59
"00:00:00:00:00:00", at least not via sysfs).
964b59
964b59
Avoid the warning in the common case, where the value is already as
964b59
expected.
964b59
964b59
Otherwise, we still get the warning and won't be able to set the right
964b59
value. But this is really a limitation of the kernel API where we cannot
964b59
do anything about it (in NetworkManager).
964b59
964b59
https://bugzilla.redhat.com/show_bug.cgi?id=1923999
964b59
(cherry picked from commit 9e7af314546d7912ee23b3850230008902aca4d3)
964b59
(cherry picked from commit 199ac9b146b0d7b1d6679a8d703822447abc3ce7)
964b59
---
964b59
 libnm-core/nm-core-internal.h     |  2 ++
964b59
 libnm-core/nm-setting-bond.c      |  2 +-
964b59
 src/core/devices/nm-device-bond.c | 18 ++++++++++++++++++
964b59
 3 files changed, 21 insertions(+), 1 deletion(-)
964b59
964b59
diff --git a/libnm-core/nm-core-internal.h b/libnm-core/nm-core-internal.h
964b59
index d9374fe5a7a8..e386d5e9d074 100644
964b59
--- a/libnm-core/nm-core-internal.h
964b59
+++ b/libnm-core/nm-core-internal.h
964b59
@@ -586,6 +586,8 @@ NMBondOptionType _nm_setting_bond_get_option_type(NMSettingBond *setting, const
964b59
 
964b59
 const char *nm_setting_bond_get_option_or_default(NMSettingBond *self, const char *option);
964b59
 
964b59
+#define NM_BOND_AD_ACTOR_SYSTEM_DEFAULT "00:00:00:00:00:00"
964b59
+
964b59
 /*****************************************************************************/
964b59
 
964b59
 /* nm_connection_get_uuid() asserts against NULL, which is the right thing to
964b59
diff --git a/libnm-core/nm-setting-bond.c b/libnm-core/nm-setting-bond.c
964b59
index 2d64ef02b48c..68d4ca88f678 100644
964b59
--- a/libnm-core/nm-setting-bond.c
964b59
+++ b/libnm-core/nm-setting-bond.c
964b59
@@ -337,7 +337,7 @@ _bond_get_option_normalized(NMSettingBond *self, const char *option, gboolean ge
964b59
     if (nm_streq(option, NM_SETTING_BOND_OPTION_AD_ACTOR_SYSTEM)) {
964b59
         /* The default value depends on the current mode */
964b59
         if (mode == NM_BOND_MODE_8023AD)
964b59
-            return "00:00:00:00:00:00";
964b59
+            return NM_BOND_AD_ACTOR_SYSTEM_DEFAULT;
964b59
         return "";
964b59
     }
964b59
 
964b59
diff --git a/src/core/devices/nm-device-bond.c b/src/core/devices/nm-device-bond.c
964b59
index f68c080b1839..5814aef4518f 100644
964b59
--- a/src/core/devices/nm-device-bond.c
964b59
+++ b/src/core/devices/nm-device-bond.c
964b59
@@ -109,6 +109,24 @@ _set_bond_attr(NMDevice *device, const char *attr, const char *value)
964b59
     int           ifindex = nm_device_get_ifindex(device);
964b59
     gboolean      ret;
964b59
 
964b59
+    nm_assert(attr && attr[0]);
964b59
+    nm_assert(value);
964b59
+
964b59
+    if (nm_streq(value, NM_BOND_AD_ACTOR_SYSTEM_DEFAULT)
964b59
+        && nm_streq(attr, NM_SETTING_BOND_OPTION_AD_ACTOR_SYSTEM)) {
964b59
+        gs_free char *cur_val = NULL;
964b59
+
964b59
+        /* kernel does not allow setting ad_actor_system to "00:00:00:00:00:00". We would thus
964b59
+         * log an EINVAL error. Avoid that... at least, if the value is already "00:00:00:00:00:00". */
964b59
+        cur_val =
964b59
+            nm_platform_sysctl_master_get_option(nm_device_get_platform(device), ifindex, attr);
964b59
+        if (nm_streq0(cur_val, NM_BOND_AD_ACTOR_SYSTEM_DEFAULT))
964b59
+            return TRUE;
964b59
+
964b59
+        /* OK, the current value is different, and we will proceed setting "00:00:00:00:00:00".
964b59
+         * That will fail, and we will log a warning. There is nothing else to do. */
964b59
+    }
964b59
+
964b59
     ret =
964b59
         nm_platform_sysctl_master_set_option(nm_device_get_platform(device), ifindex, attr, value);
964b59
     if (!ret)
964b59
-- 
964b59
2.29.2
964b59