summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2016-05-24 13:45:58 +0200
committerThomas Haller <thaller@redhat.com>2016-06-30 08:29:55 +0200
commit3704197d873a4f7d94947299dd3d750cd6d46e6c (patch)
tree3922f93a8abe1bac85f51fcbbf65f29a606bb98f
parent4bb1e2a536b1e96205a2afc98244644e095b079c (diff)
downloadNetworkManager-3704197d873a4f7d94947299dd3d750cd6d46e6c.tar.gz
device: re-read the current MAC address when the link changes
The current MAC address is part of NMPlatformLink in the platform cache. When it changes, we must update the device's current value. Also, the MAC address of NMDeviceEthernet is exposed on D-Bus. That property should show the currently configured MAC address, not a state that was read some time in the past. Also, nm_device_hw_addr_set() compares the current MAC address before resetting it. If that field is out-of-date, nm_device_hw_addr_set() will behave wrongly. NMDeviceEthernet had some special handling in link_changed() that would re-read the MAC addresses and possibly bring up the interface. Move that code to the parent device.
-rw-r--r--src/devices/nm-device-ethernet.c25
-rw-r--r--src/devices/nm-device.c26
2 files changed, 26 insertions, 25 deletions
diff --git a/src/devices/nm-device-ethernet.c b/src/devices/nm-device-ethernet.c
index 06a7a4e0bc..7c03ae6ac5 100644
--- a/src/devices/nm-device-ethernet.c
+++ b/src/devices/nm-device-ethernet.c
@@ -1578,35 +1578,10 @@ link_changed (NMDevice *device, NMPlatformLink *info)
{
NMDeviceEthernet *self = NM_DEVICE_ETHERNET (device);
NMDeviceEthernetPrivate *priv = NM_DEVICE_ETHERNET_GET_PRIVATE (self);
- const guint8 *hwaddr;
- gsize hwaddrlen = 0;
NM_DEVICE_CLASS (nm_device_ethernet_parent_class)->link_changed (device, info);
if (!priv->subchan1 && info->initialized)
_update_s390_subchannels (self);
-
- if (!nm_device_get_initial_hw_address (device)) {
- hwaddr = nm_platform_link_get_address (NM_PLATFORM_GET,
- nm_device_get_ifindex (self),
- &hwaddrlen);
- if (!nm_utils_hwaddr_matches (hwaddr, hwaddrlen, nm_ip_addr_zero.addr_eth, sizeof (nm_ip_addr_zero.addr_eth))) {
- _LOGD (LOGD_DEVICE, "device got a valid hw address");
- nm_device_update_hw_address (self);
- nm_device_update_initial_hw_address (self);
- nm_device_update_permanent_hw_address (self);
- if (nm_device_get_state (device) == NM_DEVICE_STATE_UNAVAILABLE) {
- /*
- * If the device is UNAVAILABLE, any previous try to
- * bring it up probably has failed because of the
- * invalid hardware address; try again.
- */
- nm_device_bring_up (self, TRUE, NULL);
- nm_device_queue_recheck_available (device,
- NM_DEVICE_STATE_REASON_NONE,
- NM_DEVICE_STATE_REASON_NONE);
- }
- }
- }
}
static gboolean
diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c
index 4711069a16..1f6c72406b 100644
--- a/src/devices/nm-device.c
+++ b/src/devices/nm-device.c
@@ -1664,6 +1664,7 @@ device_link_changed (NMDevice *self)
int ifindex;
gboolean was_up;
gboolean update_unmanaged_specs = FALSE;
+ gboolean got_hw_addr = FALSE, had_hw_addr;
priv->device_link_changed_id = 0;
@@ -1701,6 +1702,11 @@ device_link_changed (NMDevice *self)
_notify (self, PROP_DRIVER);
}
+ had_hw_addr = (priv->hw_addr != NULL);
+ nm_device_update_hw_address (self);
+ got_hw_addr = (!had_hw_addr && priv->hw_addr);
+ nm_device_update_permanent_hw_address (self);
+
if (info.name[0] && strcmp (priv->iface, info.name) != 0) {
_LOGI (LOGD_DEVICE, "interface index %d renamed iface from '%s' to '%s'",
priv->ifindex, priv->iface, info.name);
@@ -1792,6 +1798,20 @@ device_link_changed (NMDevice *self)
if (update_unmanaged_specs)
nm_device_set_unmanaged_by_user_settings (self, nm_settings_get_unmanaged_specs (priv->settings));
+ if ( got_hw_addr
+ && !priv->up
+ && nm_device_get_state (self) == NM_DEVICE_STATE_UNAVAILABLE) {
+ /*
+ * If the device is UNAVAILABLE, any previous try to
+ * bring it up probably has failed because of the
+ * invalid hardware address; try again.
+ */
+ nm_device_bring_up (self, TRUE, NULL);
+ nm_device_queue_recheck_available (self,
+ NM_DEVICE_STATE_REASON_NONE,
+ NM_DEVICE_STATE_REASON_NONE);
+ }
+
return G_SOURCE_REMOVE;
}
@@ -11373,6 +11393,12 @@ nm_device_update_hw_address (NMDevice *self)
_LOGD (LOGD_HW | LOGD_DEVICE, "hw-addr: hardware address now %s", priv->hw_addr);
_notify (self, PROP_HW_ADDRESS);
+
+ if (!priv->initial_hw_addr) {
+ /* when we get a hw_addr the first time, always update our inital
+ * hw-address as well. */
+ nm_device_update_initial_hw_address (self);
+ }
}
} else {
/* Invalid or no hardware address */