device: suppress log message in nm_device_update_hw_address() when no MAC address

For example for tun devices we get a lot of

  (tun7): hw-addr: failed reading current MAC address

warnings. Just be silent about it. We log when something
changes, we don't need to log when we fail to obtain
a MAC address.

Thereby, refactor nm_device_update_hw_address() to return early.
This commit is contained in:
Thomas Haller
2016-10-28 17:06:13 +02:00
parent 31ca7962f8
commit 0e0018c801

View File

@@ -11666,7 +11666,6 @@ nm_device_update_hw_address (NMDevice *self)
NMDevicePrivate *priv;
const guint8 *hwaddr;
gsize hwaddrlen = 0;
gboolean changed = FALSE;
priv = NM_DEVICE_GET_PRIVATE (self);
if (priv->ifindex <= 0)
@@ -11679,7 +11678,9 @@ nm_device_update_hw_address (NMDevice *self)
&& nm_utils_hwaddr_matches (hwaddr, hwaddrlen, nm_ip_addr_zero.addr_eth, sizeof (nm_ip_addr_zero.addr_eth)))
hwaddrlen = 0;
if (hwaddrlen) {
if (!hwaddrlen)
return FALSE;
if ( priv->hw_addr_len
&& priv->hw_addr_len != hwaddrlen) {
char s_buf[NM_UTILS_HWADDR_LEN_MAX_STR];
@@ -11696,7 +11697,10 @@ nm_device_update_hw_address (NMDevice *self)
return FALSE;
}
if (!priv->hw_addr || !nm_utils_hwaddr_matches (priv->hw_addr, -1, hwaddr, hwaddrlen)) {
if ( priv->hw_addr
&& nm_utils_hwaddr_matches (priv->hw_addr, -1, hwaddr, hwaddrlen))
return FALSE;
g_free (priv->hw_addr);
priv->hw_addr_len_ = hwaddrlen;
priv->hw_addr = nm_utils_hwaddr_ntoa (hwaddr, hwaddrlen);
@@ -11713,20 +11717,7 @@ nm_device_update_hw_address (NMDevice *self)
* update our inital hw-address as well. */
nm_device_update_initial_hw_address (self);
}
changed = TRUE;
}
} else {
/* Invalid or no hardware address */
if (priv->hw_addr_len != 0) {
_LOGD (LOGD_PLATFORM | LOGD_DEVICE,
"hw-addr: failed reading current MAC address (stay with %s)",
priv->hw_addr);
} else {
_LOGD (LOGD_PLATFORM | LOGD_DEVICE,
"hw-addr: failed reading current MAC address");
}
}
return changed;
return TRUE;
}
void