From c8d0a0fcf7b8368b9fbe19f4fb2327349dcc5eba Mon Sep 17 00:00:00 2001 From: Beniamino Galvani Date: Tue, 25 Jul 2017 10:37:14 +0200 Subject: [PATCH] device: don't set a fake permanent hardware address Software devices don't have a permanent hardware address and thus it doesn't make sense to enforce the 'fake' (generated) permanent one when cloned-mac-address=permanent. Also, setting the fake permanent address on bond devices, prevents them from inheriting the first slave hardware address, so let's just skip the setting of MAC when cloned-mac-address=permanent and there is no real permanent address. https://bugzilla.redhat.com/show_bug.cgi?id=1472965 (cherry picked from commit 2f4dfd0f2e8f85dd86f5abfbeaafd7cb04655525) --- libnm-core/nm-setting-wired.c | 3 ++- src/devices/nm-device.c | 13 +++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/libnm-core/nm-setting-wired.c b/libnm-core/nm-setting-wired.c index 5569f55848..5476e357f4 100644 --- a/libnm-core/nm-setting-wired.c +++ b/libnm-core/nm-setting-wired.c @@ -1150,7 +1150,8 @@ nm_setting_wired_class_init (NMSettingWiredClass *setting_wired_class) * Beside explicitly specifing a MAC address, the special values "preserve", "permanent", * "random" and "stable" are supported. * "preserve" means not to touch the MAC address on activation. - * "permanent" means to use the permanent hardware address of the device. + * "permanent" means to use the permanent hardware address if the device + * has one (otherwise this is treated as "preserve"). * "random" creates a random MAC address on each connect. * "stable" creates a hashed MAC address based on connection.stable-id and a * machine dependent key. diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c index fbf315ed3b..45a71032bd 100644 --- a/src/devices/nm-device.c +++ b/src/devices/nm-device.c @@ -13475,8 +13475,17 @@ _hw_addr_get_cloned (NMDevice *self, NMConnection *connection, gboolean is_wifi, } if (nm_streq (addr, NM_CLONED_MAC_PERMANENT)) { - addr = nm_device_get_permanent_hw_address (self); - if (!addr) { + gboolean is_fake; + + addr = nm_device_get_permanent_hw_address_full (self, TRUE, &is_fake); + if (is_fake) { + /* Preserve the current address if the permanent address if fake */ + NM_SET_OUT (preserve, TRUE); + NM_SET_OUT (hwaddr, NULL); + NM_SET_OUT (hwaddr_type, HW_ADDR_TYPE_UNSET); + NM_SET_OUT (hwaddr_detail, g_steal_pointer (&addr_setting_free) ?: g_strdup (addr_setting)); + return TRUE; + } else if (!addr) { g_set_error_literal (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_FAILED,