device: merge branch 'bg/sw-devices-cloned-mac-rh1386872'

Honor the ethernet.cloned-mac-address property for bond and bridge
connections.

https://bugzilla.redhat.com/show_bug.cgi?id=1386872
This commit is contained in:
Beniamino Galvani 2016-11-07 14:08:01 +01:00
commit 948a183d48
6 changed files with 32 additions and 8 deletions

View file

@ -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.

View file

@ -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;

View file

@ -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);

View file

@ -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.
*/

View file

@ -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);
}

View file

@ -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