device: Deal with links that vanish during initialization

nm_device_get_hw_address() may return NULL and nm_platform_link_get_type may
return NM_LINK_TYPE_NONE. While it might be a good idea to check for such cases
at the init time it seems easier to just ignore it and prevent blowing up in
subsequent deactivation.

A quick test case:

  # while :; do ip link add moo0 type veth peer moo1; ip link del moo0 ; done

Yields:

  NetworkManager:ERROR:devices/nm-device-ethernet.c:268:constructor:
    assertion failed: (link_type == NM_LINK_TYPE_ETHERNET ||
    link_type == NM_LINK_TYPE_VETH)

  nm_device_set_hw_addr: assertion 'addr != NULL' failed

https://bugzilla.gnome.org/show_bug.cgi?id=740992
This commit is contained in:
Lubomir Rintel 2014-12-01 16:53:12 +01:00
parent 20566c76de
commit e257744f9e
3 changed files with 9 additions and 4 deletions

View file

@ -265,7 +265,9 @@ constructor (GType type,
int ifindex = nm_device_get_ifindex (NM_DEVICE (object));
NMLinkType link_type = nm_platform_link_get_type (ifindex);
g_assert (link_type == NM_LINK_TYPE_ETHERNET || link_type == NM_LINK_TYPE_VETH);
g_assert ( link_type == NM_LINK_TYPE_ETHERNET
|| link_type == NM_LINK_TYPE_VETH
|| link_type == NM_LINK_TYPE_NONE);
#endif
/* s390 stuff */
@ -1389,7 +1391,8 @@ deactivate (NMDevice *device)
NM_DEVICE_ETHERNET_GET_PRIVATE (device)->last_pppoe_time = nm_utils_get_monotonic_timestamp_s ();
/* Reset MAC address back to initial address */
nm_device_set_hw_addr (device, priv->initial_hw_addr, "reset", LOGD_ETHER);
if (priv->initial_hw_addr)
nm_device_set_hw_addr (device, priv->initial_hw_addr, "reset", LOGD_ETHER);
}
static gboolean

View file

@ -390,7 +390,8 @@ deactivate (NMDevice *device)
NMDeviceVlanPrivate *priv = NM_DEVICE_VLAN_GET_PRIVATE (self);
/* Reset MAC address back to initial address */
nm_device_set_hw_addr (device, priv->initial_hw_addr, "reset", LOGD_VLAN);
if (priv->initial_hw_addr)
nm_device_set_hw_addr (device, priv->initial_hw_addr, "reset", LOGD_VLAN);
}
/******************************************************************/

View file

@ -741,7 +741,8 @@ deactivate (NMDevice *device)
nm_platform_wifi_indicate_addressing_running (ifindex, FALSE);
/* Reset MAC address back to initial address */
nm_device_set_hw_addr (device, priv->initial_hw_addr, "reset", LOGD_WIFI);
if (priv->initial_hw_addr)
nm_device_set_hw_addr (device, priv->initial_hw_addr, "reset", LOGD_WIFI);
/* Ensure we're in infrastructure mode after deactivation; some devices
* (usually older ones) don't scan well in adhoc mode.