diff options
author | Thomas Haller <thaller@redhat.com> | 2016-05-20 10:09:39 +0200 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2016-06-30 08:29:55 +0200 |
commit | e92b743ce926a49d84847d7c951cbc0ee343d19c (patch) | |
tree | 57fceaf166160a75f88ac150e7dae40ea74c9ec5 | |
parent | fa5230e25537481854e023062fbc7869c855c746 (diff) | |
download | NetworkManager-e92b743ce926a49d84847d7c951cbc0ee343d19c.tar.gz |
device: don't use g_warning for differing hw-addr-len after reading permanent address
Accessing the platform cache might anytime yield unexpected results.
E.g. the link could be gone, or the ifindex could even be replaced
by a different interface (yes, that can happen when moving links
between network namespaces).
It's not clear how to handle such a case at runtime. It seems wrong to
me to just error out. Still, such case might happen under normal
conditions, so it's wrong to just warn and proceed.
-rw-r--r-- | src/devices/nm-device.c | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c index 22af8b17ea..25bf01d4a6 100644 --- a/src/devices/nm-device.c +++ b/src/devices/nm-device.c @@ -11391,15 +11391,20 @@ nm_device_update_initial_hw_address (NMDevice *self) if (priv->ifindex > 0) { guint8 buf[NM_UTILS_HWADDR_LEN_MAX]; size_t len = 0; + gboolean success_read; - if (nm_platform_link_get_permanent_address (NM_PLATFORM_GET, priv->ifindex, buf, &len)) { - g_warn_if_fail (len == priv->hw_addr_len); + success_read = nm_platform_link_get_permanent_address (NM_PLATFORM_GET, priv->ifindex, buf, &len); + + if (success_read && len == priv->hw_addr_len) { priv->perm_hw_addr = nm_utils_hwaddr_ntoa (buf, priv->hw_addr_len); _LOGD (LOGD_DEVICE | LOGD_HW, "read permanent MAC address %s", priv->perm_hw_addr); } else { /* Fall back to current address */ - _LOGD (LOGD_HW | LOGD_ETHER, "unable to read permanent MAC address"); + _LOGD (LOGD_HW | LOGD_ETHER, "%s", + success_read + ? "unable to read permanent MAC address" + : "read HW addr length of permanent MAC address differs"); priv->perm_hw_addr = g_strdup (priv->hw_addr); } } |