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

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