From b071c91eef15d6dbbf365d2db5aaca1b4eadcce0 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 13 Oct 2016 15:56:13 +0200 Subject: [PATCH] core: add nm_device_get_permanent_hw_address_full() function This is a partial cherry-pick from commit 5912b2f9a170893002b789fe37a7784eefac4e34. --- src/devices/nm-device.c | 32 ++++++++++++++++++++++++-------- src/devices/nm-device.h | 2 ++ 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c index 1935f4568c..db617c0be6 100644 --- a/src/devices/nm-device.c +++ b/src/devices/nm-device.c @@ -11609,8 +11609,10 @@ nm_device_update_permanent_hw_address (NMDevice *self) success_read = nm_platform_link_get_permanent_address (NM_PLATFORM_GET, priv->ifindex, buf, &len); if (!success_read || len != priv->hw_addr_len) { - /* Fall back to current address. We use the fake address and keep it - * until the device unrealizes. + priv->hw_addr_perm_fake = TRUE; + + /* we failed to read a permanent MAC address, thus we use a fake address, + * that is the current MAC address of the device. * * In some cases it might be necessary to know whether this is a "real" or * a temporary address (fake). */ @@ -11619,14 +11621,16 @@ nm_device_update_permanent_hw_address (NMDevice *self) ? "read HW addr length of permanent MAC address differs" : "unable to read permanent MAC address", priv->hw_addr); - priv->hw_addr_perm_fake = TRUE; priv->hw_addr_perm = g_strdup (priv->hw_addr); - } else { - priv->hw_addr_perm_fake = FALSE; - priv->hw_addr_perm = nm_utils_hwaddr_ntoa (buf, len); - _LOGD (LOGD_DEVICE, "hw-addr: read permanent MAC address '%s'", - priv->hw_addr_perm); + goto out; } + + priv->hw_addr_perm_fake = FALSE; + priv->hw_addr_perm = nm_utils_hwaddr_ntoa (buf, len); + _LOGD (LOGD_DEVICE, "hw-addr: read permanent MAC address '%s'", + priv->hw_addr_perm); + +out: _notify (self, PROP_PERM_HW_ADDRESS); } @@ -11962,6 +11966,18 @@ nm_device_hw_addr_reset (NMDevice *self, const char *detail) return _hw_addr_set (self, addr, "reset", detail); } +const char * +nm_device_get_permanent_hw_address_full (NMDevice *self, gboolean *out_is_fake) +{ + NMDevicePrivate *priv; + + g_return_val_if_fail (NM_IS_DEVICE (self), NULL); + + priv = NM_DEVICE_GET_PRIVATE (self); + NM_SET_OUT (out_is_fake, priv->hw_addr_perm && priv->hw_addr_perm_fake); + return priv->hw_addr_perm; +} + const char * nm_device_get_permanent_hw_address (NMDevice *self, gboolean fallback_fake) { diff --git a/src/devices/nm-device.h b/src/devices/nm-device.h index a757a37eb9..010c9b9f0d 100644 --- a/src/devices/nm-device.h +++ b/src/devices/nm-device.h @@ -366,6 +366,8 @@ guint32 nm_device_get_ip6_route_metric (NMDevice *dev); const char * nm_device_get_hw_address (NMDevice *dev); const char * nm_device_get_permanent_hw_address (NMDevice *dev, gboolean fallback_fake); +const char * nm_device_get_permanent_hw_address_full (NMDevice *self, + gboolean *out_is_fake); const char * nm_device_get_initial_hw_address (NMDevice *dev); NMDhcp4Config * nm_device_get_dhcp4_config (NMDevice *dev);