From 67ea41f0a0190b1cb8ff7525794d5637fcac6c6b Mon Sep 17 00:00:00 2001 From: Beniamino Galvani Date: Tue, 25 Oct 2016 16:41:42 +0200 Subject: [PATCH 1/3] device: add @set_permanent argument to nm_device_hw_addr_set() In a later commit the function will be used to restore a MAC address without changing its type. --- src/devices/nm-device-private.h | 5 ++++- src/devices/nm-device-vlan.c | 2 +- src/devices/nm-device.c | 16 +++++++++++----- src/devices/wifi/nm-device-wifi.c | 2 +- 4 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/devices/nm-device-private.h b/src/devices/nm-device-private.h index 927dc8c46c..c5b4936b51 100644 --- a/src/devices/nm-device-private.h +++ b/src/devices/nm-device-private.h @@ -57,7 +57,10 @@ gboolean nm_device_bring_up (NMDevice *self, gboolean wait, gboolean *no_firmwar void nm_device_take_down (NMDevice *self, gboolean block); -gboolean nm_device_hw_addr_set (NMDevice *device, const char *addr, const char *detail); +gboolean nm_device_hw_addr_set (NMDevice *device, + const char *addr, + const char *detail, + gboolean set_permanent); gboolean nm_device_hw_addr_set_cloned (NMDevice *device, NMConnection *connection, gboolean is_wifi); gboolean nm_device_hw_addr_reset (NMDevice *device, const char *detail); diff --git a/src/devices/nm-device-vlan.c b/src/devices/nm-device-vlan.c index 87a36130b8..f80f8efff1 100644 --- a/src/devices/nm-device-vlan.c +++ b/src/devices/nm-device-vlan.c @@ -117,7 +117,7 @@ parent_hwaddr_maybe_changed (NMDevice *parent, _LOGD (LOGD_VLAN, "parent hardware address changed to %s%s%s", NM_PRINT_FMT_QUOTE_STRING (new_mac)); if (new_mac) { - nm_device_hw_addr_set ((NMDevice *) self, new_mac, "vlan-parent"); + nm_device_hw_addr_set ((NMDevice *) self, new_mac, "vlan-parent", TRUE); /* When changing the hw address the interface is taken down, * removing the IPv6 configuration; reapply it. */ diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c index 27c111964f..7b41ee911b 100644 --- a/src/devices/nm-device.c +++ b/src/devices/nm-device.c @@ -12049,7 +12049,10 @@ handle_fail: } gboolean -nm_device_hw_addr_set (NMDevice *self, const char *addr, const char *detail) +nm_device_hw_addr_set (NMDevice *self, + const char *addr, + const char *detail, + gboolean set_permanent) { NMDevicePrivate *priv; @@ -12060,10 +12063,13 @@ nm_device_hw_addr_set (NMDevice *self, const char *addr, const char *detail) if (!addr) g_return_val_if_reached (FALSE); - /* this is called by NMDeviceVlan to take the MAC address from the parent - * and by NMDeviceWifi to set a random MAC address during scanning. - * In this case, it's like setting it to PERMANENT. */ - priv->hw_addr_type = HW_ADDR_TYPE_PERMANENT; + if (set_permanent) { + /* The type is set to PERMANENT by NMDeviceVlan when taking the MAC + * address from the parent and by NMDeviceWifi when setting a random MAC + * address during scanning. + */ + priv->hw_addr_type = HW_ADDR_TYPE_PERMANENT; + } return _hw_addr_set (self, addr, "set", detail); } diff --git a/src/devices/wifi/nm-device-wifi.c b/src/devices/wifi/nm-device-wifi.c index 8381aaccb3..89fa49e4ff 100644 --- a/src/devices/wifi/nm-device-wifi.c +++ b/src/devices/wifi/nm-device-wifi.c @@ -1107,7 +1107,7 @@ _hw_addr_set_scanning (NMDeviceWifi *self, gboolean do_reset) generate_mac_address_mask); } - nm_device_hw_addr_set (device, priv->hw_addr_scan, "scanning"); + nm_device_hw_addr_set (device, priv->hw_addr_scan, "scanning", TRUE); } static void From f1d595d1290a94493c9cbd7d9d33449a95e53b10 Mon Sep 17 00:00:00 2001 From: Beniamino Galvani Date: Fri, 21 Oct 2016 14:40:37 +0200 Subject: [PATCH 2/3] bridge: support the ethernet.cloned-mac-address property --- src/devices/nm-device-bridge.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/devices/nm-device-bridge.c b/src/devices/nm-device-bridge.c index 326cafd6bf..8bef03be9a 100644 --- a/src/devices/nm-device-bridge.c +++ b/src/devices/nm-device-bridge.c @@ -316,6 +316,9 @@ act_stage1_prepare (NMDevice *device, NMDeviceStateReason *reason) if (ret != NM_ACT_STAGE_RETURN_SUCCESS) return ret; + if (!nm_device_hw_addr_set_cloned (device, nm_device_get_applied_connection (device), FALSE)) + return NM_ACT_STAGE_RETURN_FAILURE; + commit_master_options (device, nm_connection_get_setting_bridge (connection)); return NM_ACT_STAGE_RETURN_SUCCESS; From 06418b2034bb7decf84ebd1ba7830f180fd9e580 Mon Sep 17 00:00:00 2001 From: Beniamino Galvani Date: Fri, 21 Oct 2016 14:37:05 +0200 Subject: [PATCH 3/3] bond: support the ethernet.cloned-mac-address property --- src/devices/nm-device-bond.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/devices/nm-device-bond.c b/src/devices/nm-device-bond.c index e70b1ba0f4..853158d483 100644 --- a/src/devices/nm-device-bond.c +++ b/src/devices/nm-device-bond.c @@ -376,6 +376,8 @@ act_stage1_prepare (NMDevice *dev, NMDeviceStateReason *reason) /* Interface must be down to set bond options */ nm_device_take_down (dev, TRUE); ret = apply_bonding_config (dev); + if (ret) + ret = nm_device_hw_addr_set_cloned (dev, nm_device_get_applied_connection (dev), FALSE); nm_device_bring_up (dev, TRUE, &no_firmware); return ret; @@ -436,8 +438,14 @@ release_slave (NMDevice *device, { NMDeviceBond *self = NM_DEVICE_BOND (device); gboolean success, no_firmware = FALSE; + gs_free char *address = NULL; if (configure) { + /* When the last slave is released the bond MAC will be set to a random + * value by kernel; remember the current one and restore it afterwards. + */ + address = g_strdup (nm_device_get_hw_address (device)); + success = nm_platform_link_release (NM_PLATFORM_GET, nm_device_get_ip_ifindex (device), nm_device_get_ip_ifindex (slave)); @@ -450,6 +458,10 @@ release_slave (NMDevice *device, nm_device_get_ip_iface (slave)); } + nm_platform_process_events (NM_PLATFORM_GET); + if (nm_device_update_hw_address (device)) + nm_device_hw_addr_set (device, address, "restore", FALSE); + /* Kernel bonding code "closes" the slave when releasing it, (which clears * IFF_UP), so we must bring it back up here to ensure carrier changes and * other state is noticed by the now-released slave.