diff --git a/src/nm-device-ethernet.c b/src/nm-device-ethernet.c index e88e09d573..f8685f018a 100644 --- a/src/nm-device-ethernet.c +++ b/src/nm-device-ethernet.c @@ -277,6 +277,7 @@ constructor (GType type, GObject *object; NMDeviceEthernetPrivate *priv; NMDevice *self; + int itype; object = G_OBJECT_CLASS (nm_device_ethernet_parent_class)->constructor (type, n_construct_params, @@ -289,7 +290,8 @@ constructor (GType type, // FIXME: Convert this into a no-export property so type can be specified // when the device is created. - if (!strcmp(nm_device_get_driver (self), "bonding")) + itype = nm_system_get_iface_type (nm_device_get_ifindex (self), nm_device_get_iface (self)); + if (itype == NM_IFACE_TYPE_BOND) priv->type = NM_ETHERNET_TYPE_BOND; else priv->type = NM_ETHERNET_TYPE_UNSPEC; diff --git a/src/nm-system.c b/src/nm-system.c index 08f5084da7..c72566791d 100644 --- a/src/nm-system.c +++ b/src/nm-system.c @@ -1499,25 +1499,30 @@ out: /** * nm_system_get_iface_type: + * @ifindex: interface index * @name: name of interface * - * Lookup the type of an interface + * Lookup the type of an interface. At least one of @ifindex or @name must + * be provided. * * Returns: Interface type (NM_IFACE_TYPE_*) or NM_IFACE_TYPE_UNSPEC. **/ int -nm_system_get_iface_type (const char *name) +nm_system_get_iface_type (int ifindex, const char *name) { struct rtnl_link *result; struct nl_sock *nlh; char *type; int res = NM_IFACE_TYPE_UNSPEC; + g_return_val_if_fail (ifindex >= 0 || name, NM_IFACE_TYPE_UNSPEC); + nlh = nm_netlink_get_default_handle (); if (!nlh) goto out; - if (rtnl_link_get_kernel (nlh, 0, name, &result) < 0) + /* Prefer interface indexes to names */ + if (rtnl_link_get_kernel (nlh, ifindex, ifindex < 0 ? name : NULL, &result) < 0) goto out; type = rtnl_link_get_type (result); diff --git a/src/nm-system.h b/src/nm-system.h index 34bfb864df..66fd57d83b 100644 --- a/src/nm-system.h +++ b/src/nm-system.h @@ -100,6 +100,6 @@ enum { NM_IFACE_TYPE_DUMMY, }; -int nm_system_get_iface_type (const char *name); +int nm_system_get_iface_type (int ifindex, const char *name); #endif diff --git a/src/nm-udev-manager.c b/src/nm-udev-manager.c index 0c2ab4b50e..d8d213ef10 100644 --- a/src/nm-udev-manager.c +++ b/src/nm-udev-manager.c @@ -399,8 +399,14 @@ net_add (NMUdevManager *self, GUdevDevice *udev_device) } } + ifindex = g_udev_device_get_sysfs_attr_as_int (udev_device, "ifindex"); + if (ifindex <= 0) { + nm_log_warn (LOGD_HW, "%s: device had invalid ifindex %d; ignoring...", path, (guint32) ifindex); + goto out; + } + if (!driver) { - switch (nm_system_get_iface_type (ifname)) { + switch (nm_system_get_iface_type (ifindex, ifname)) { case NM_IFACE_TYPE_BOND: driver = "bonding"; break; @@ -416,12 +422,6 @@ net_add (NMUdevManager *self, GUdevDevice *udev_device) } } - ifindex = g_udev_device_get_sysfs_attr_as_int (udev_device, "ifindex"); - if (ifindex <= 0) { - nm_log_warn (LOGD_HW, "%s: device had invalid ifindex %d; ignoring...", path, (guint32) ifindex); - goto out; - } - g_signal_emit (self, signals[DEVICE_ADDED], 0, udev_device, ifname, path, driver, ifindex); out: