Blame SOURCES/1003-bond-only-restore-mac-if-cloned.patch

964b59
From ccc66f603d5fac8748d2271d051bbd1c42eeb682 Mon Sep 17 00:00:00 2001
964b59
From: Beniamino Galvani <bgalvani@redhat.com>
964b59
Date: Sat, 6 Mar 2021 11:35:12 +0100
964b59
Subject: [PATCH] bond: restore MAC on release only when there is a cloned MAC
964b59
 address
964b59
964b59
Currently we unconditionally reset the MAC to the previous value after
964b59
releasing ports. This has some disadvantages:
964b59
964b59
 - by default, after the last port is removed the bond will have one
964b59
   of the previous port's address, which could conflict with the port;
964b59
964b59
 - in some cases, changing the bond MAC is not possible. For example
964b59
   when the bond is active-backup and has fail_over_mac=1|2. In such
964b59
   case the netlink call succeeds, but the address doesn't
964b59
   change; then NM would keep waiting for some time.
964b59
964b59
Don't try to restore the MAC unless the bond connection has a cloned
964b59
MAC set.
964b59
964b59
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/775
964b59
(cherry picked from commit 190fd9aa9f3fbf5705c2b80b9fc64c89d22b7593)
964b59
(cherry picked from commit 4c1e60549a5be170185a77439379cc170d6b3631)
964b59
---
964b59
 src/core/devices/nm-device-bond.c | 20 ++++++++++++++------
964b59
 1 file changed, 14 insertions(+), 6 deletions(-)
964b59
964b59
diff --git a/src/core/devices/nm-device-bond.c b/src/core/devices/nm-device-bond.c
964b59
index 5814aef451..247ce41c07 100644
964b59
--- a/src/core/devices/nm-device-bond.c
964b59
+++ b/src/core/devices/nm-device-bond.c
964b59
@@ -444,9 +444,10 @@ release_slave(NMDevice *device, NMDevice *slave, gboolean configure)
964b59
         _LOGD(LOGD_BOND, "bond slave %s is already released", nm_device_get_ip_iface(slave));
964b59
 
964b59
     if (configure) {
964b59
-        /* When the last slave is released the bond MAC will be set to a random
964b59
-         * value by kernel; remember the current one and restore it afterwards.
964b59
-         */
964b59
+        NMConnection *  applied;
964b59
+        NMSettingWired *s_wired;
964b59
+        const char *    cloned_mac;
964b59
+
964b59
         address = g_strdup(nm_device_get_hw_address(device));
964b59
 
964b59
         if (ifindex_slave > 0) {
964b59
@@ -461,9 +462,16 @@ release_slave(NMDevice *device, NMDevice *slave, gboolean configure)
964b59
             }
964b59
         }
964b59
 
964b59
-        nm_platform_process_events(nm_device_get_platform(device));
964b59
-        if (nm_device_update_hw_address(device))
964b59
-            nm_device_hw_addr_set(device, address, "restore", FALSE);
964b59
+        if ((applied = nm_device_get_applied_connection(device))
964b59
+            && ((s_wired = nm_connection_get_setting_wired(applied)))
964b59
+            && ((cloned_mac = nm_setting_wired_get_cloned_mac_address(s_wired)))) {
964b59
+            /* When the last slave is released the bond MAC will be set to a random
964b59
+             * value by kernel; if we have set a cloned-mac-address, we need to
964b59
+             * restore it to the previous value. */
964b59
+            nm_platform_process_events(nm_device_get_platform(device));
964b59
+            if (nm_device_update_hw_address(device))
964b59
+                nm_device_hw_addr_set(device, address, "restore", FALSE);
964b59
+        }
964b59
 
964b59
         /* Kernel bonding code "closes" the slave when releasing it, (which clears
964b59
          * IFF_UP), so we must bring it back up here to ensure carrier changes and
964b59
-- 
964b59
2.29.2
964b59