mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-02-05 14:40:33 +01:00
core: let nm_system_get_iface_type() take an interface index
We prefer indexes to names in the core since indexes don't change.
This commit is contained in:
parent
0a18078b73
commit
8fd900c2dc
4 changed files with 19 additions and 12 deletions
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue