device: when activating without cloned-mac-address, set the permanent one
authorLubomir Rintel <lkundrak@v3.sk>
Fri, 26 Feb 2016 16:15:10 +0000 (17:15 +0100)
committerLubomir Rintel <lkundrak@v3.sk>
Fri, 26 Feb 2016 16:35:21 +0000 (17:35 +0100)
Don't rely on what's already on the device. It could be that the MAC address
set on the device is not meaningful -- the NM crashed while two devices were
teamed together and now they have the same hardware address and now it's
impossible to bond them with mode=5.

src/devices/nm-device-ethernet.c
src/devices/nm-device-macvlan.c
src/devices/nm-device-tun.c
src/devices/nm-device-vlan.c
src/devices/nm-device-vxlan.c
src/devices/nm-device.c
src/devices/wifi/nm-device-wifi.c

index 5333aba..2fb8427 100644 (file)
@@ -819,8 +819,7 @@ act_stage1_prepare (NMDevice *dev, NMDeviceStateReason *reason)
                if (s_wired) {
                        /* Set device MAC address if the connection wants to change it */
                        cloned_mac = nm_setting_wired_get_cloned_mac_address (s_wired);
-                       if (cloned_mac)
-                               nm_device_set_hw_addr (dev, cloned_mac, "set", LOGD_ETHER);
+                       nm_device_set_hw_addr (dev, cloned_mac, "set", LOGD_ETHER);
                }
 
                /* If we're re-activating a PPPoE connection a short while after
index dfb0431..2dc9d4f 100644 (file)
@@ -508,8 +508,7 @@ act_stage1_prepare (NMDevice *dev, NMDeviceStateReason *reason)
        if (s_wired) {
                /* Set device MAC address if the connection wants to change it */
                cloned_mac = nm_setting_wired_get_cloned_mac_address (s_wired);
-               if (cloned_mac)
-                       nm_device_set_hw_addr (dev, cloned_mac, "set", LOGD_HW);
+               nm_device_set_hw_addr (dev, cloned_mac, "set", LOGD_HW);
        }
 
        return TRUE;
index fdb72e4..a8ae3ed 100644 (file)
@@ -302,8 +302,7 @@ act_stage1_prepare (NMDevice *device, NMDeviceStateReason *reason)
        if (s_wired) {
                /* Set device MAC address if the connection wants to change it */
                cloned_mac = nm_setting_wired_get_cloned_mac_address (s_wired);
-               if (cloned_mac)
-                       nm_device_set_hw_addr (device, cloned_mac, "set", LOGD_DEVICE);
+               nm_device_set_hw_addr (device, cloned_mac, "set", LOGD_DEVICE);
        }
 
        return NM_ACT_STAGE_RETURN_SUCCESS;
index 5685b24..e6e3708 100644 (file)
@@ -551,8 +551,7 @@ act_stage1_prepare (NMDevice *dev, NMDeviceStateReason *reason)
        if (s_wired) {
                /* Set device MAC address if the connection wants to change it */
                cloned_mac = nm_setting_wired_get_cloned_mac_address (s_wired);
-               if (cloned_mac)
-                       nm_device_set_hw_addr (dev, cloned_mac, "set", LOGD_VLAN);
+               nm_device_set_hw_addr (dev, cloned_mac, "set", LOGD_VLAN);
        }
 
        s_vlan = (NMSettingVlan *) nm_device_get_applied_setting (dev, NM_TYPE_SETTING_VLAN);
index ff0f234..7994245 100644 (file)
@@ -517,8 +517,7 @@ act_stage1_prepare (NMDevice *device, NMDeviceStateReason *reason)
        if (s_wired) {
                /* Set device MAC address if the connection wants to change it */
                cloned_mac = nm_setting_wired_get_cloned_mac_address (s_wired);
-               if (cloned_mac)
-                       nm_device_set_hw_addr (device, cloned_mac, "set", LOGD_DEVICE);
+               nm_device_set_hw_addr (device, cloned_mac, "set", LOGD_DEVICE);
        }
 
        return NM_ACT_STAGE_RETURN_SUCCESS;
index b9a3485..641b429 100644 (file)
@@ -10858,7 +10858,11 @@ nm_device_set_hw_addr (NMDevice *self, const char *addr,
        const char *cur_addr = nm_device_get_hw_address (self);
        guint8 addr_bytes[NM_UTILS_HWADDR_LEN_MAX];
 
-       g_return_val_if_fail (addr != NULL, FALSE);
+       /* Fall back to the permanent address */
+       if (!addr)
+               addr = priv->perm_hw_addr;
+       if (!addr)
+               return FALSE;
 
        /* Do nothing if current MAC is same */
        if (cur_addr && nm_utils_hwaddr_matches (cur_addr, -1, addr, -1)) {
index 64f728d..da2a0f4 100644 (file)
@@ -2316,8 +2316,7 @@ act_stage1_prepare (NMDevice *device, NMDeviceStateReason *reason)
 
        /* Set spoof MAC to the interface */
        cloned_mac = nm_setting_wireless_get_cloned_mac_address (s_wireless);
-       if (cloned_mac)
-               nm_device_set_hw_addr (device, cloned_mac, "set", LOGD_WIFI);
+       nm_device_set_hw_addr (device, cloned_mac, "set", LOGD_WIFI);
 
        /* AP mode never uses a specific object or existing scanned AP */
        if (priv->mode != NM_802_11_MODE_AP) {