mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager
synced 2024-10-14 12:05:03 +00:00
core: use NMPlatform to figure out device types, where possible
Rather than having a bunch of udev-based tests, use nm_platform_link_get_type() to categorize devices. Incomplete, as NMPlatform still categorizes most hardware types as "ETHERNET", so we still need udev-based tests for those. https://bugzilla.gnome.org/show_bug.cgi?id=687254
This commit is contained in:
parent
fed36d13b6
commit
0d6f2faefa
|
@ -71,6 +71,7 @@
|
|||
#include "wifi-utils.h"
|
||||
#include "nm-enum-types.h"
|
||||
#include "nm-sleep-monitor.h"
|
||||
#include "nm-platform.h"
|
||||
|
||||
#if WITH_CONCHECK
|
||||
#include "nm-connectivity.h"
|
||||
|
@ -2158,31 +2159,6 @@ is_olpc_mesh (GUdevDevice *device)
|
|||
return (prop != NULL);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
is_infiniband (GUdevDevice *device)
|
||||
{
|
||||
gint etype = g_udev_device_get_sysfs_attr_as_int (device, "type");
|
||||
return etype == ARPHRD_INFINIBAND;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
is_bond (int ifindex)
|
||||
{
|
||||
return (nm_platform_link_get_type (ifindex) == NM_LINK_TYPE_BOND);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
is_bridge (int ifindex)
|
||||
{
|
||||
return (nm_platform_link_get_type (ifindex) == NM_LINK_TYPE_BRIDGE);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
is_vlan (int ifindex)
|
||||
{
|
||||
return (nm_platform_link_get_type (ifindex) == NM_LINK_TYPE_VLAN);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
is_adsl (GUdevDevice *device)
|
||||
{
|
||||
|
@ -2245,29 +2221,41 @@ udev_device_added_cb (NMUdevManager *udev_mgr,
|
|||
}
|
||||
}
|
||||
|
||||
if (device == NULL && driver == NULL)
|
||||
device = nm_device_generic_new (sysfs_path, iface, driver);
|
||||
|
||||
if (device == NULL) {
|
||||
if (is_olpc_mesh (udev_device)) /* must be before is_wireless */
|
||||
device = nm_device_olpc_mesh_new (sysfs_path, iface, driver);
|
||||
else if (is_wireless (udev_device))
|
||||
device = nm_device_wifi_new (sysfs_path, iface, driver);
|
||||
else if (is_infiniband (udev_device))
|
||||
device = nm_device_infiniband_new (sysfs_path, iface, driver);
|
||||
else if (is_bond (ifindex))
|
||||
device = nm_device_bond_new (sysfs_path, iface);
|
||||
else if (is_bridge (ifindex)) {
|
||||
NMLinkType type;
|
||||
int parent_ifindex = -1;
|
||||
NMDevice *parent;
|
||||
|
||||
type = nm_platform_link_get_type (ifindex);
|
||||
|
||||
switch (type) {
|
||||
case NM_LINK_TYPE_ETHERNET:
|
||||
if (driver == NULL)
|
||||
device = nm_device_generic_new (sysfs_path, iface, driver);
|
||||
else if (is_olpc_mesh (udev_device)) /* must be before is_wireless */
|
||||
device = nm_device_olpc_mesh_new (sysfs_path, iface, driver);
|
||||
else if (is_wireless (udev_device))
|
||||
device = nm_device_wifi_new (sysfs_path, iface, driver);
|
||||
else if (is_adsl (udev_device))
|
||||
device = nm_device_adsl_new (sysfs_path, iface, driver);
|
||||
else
|
||||
device = nm_device_ethernet_new (sysfs_path, iface, driver);
|
||||
break;
|
||||
|
||||
case NM_LINK_TYPE_INFINIBAND:
|
||||
device = nm_device_infiniband_new (sysfs_path, iface, driver);
|
||||
break;
|
||||
case NM_LINK_TYPE_BOND:
|
||||
device = nm_device_bond_new (sysfs_path, iface);
|
||||
break;
|
||||
case NM_LINK_TYPE_BRIDGE:
|
||||
/* FIXME: always create device when we handle bridges non-destructively */
|
||||
if (bridge_created_by_nm (self, iface))
|
||||
device = nm_device_bridge_new (sysfs_path, iface);
|
||||
else
|
||||
nm_log_info (LOGD_BRIDGE, "(%s): ignoring bridge not created by NetworkManager", iface);
|
||||
} else if (is_vlan (ifindex)) {
|
||||
int parent_ifindex = -1;
|
||||
NMDevice *parent;
|
||||
|
||||
break;
|
||||
case NM_LINK_TYPE_VLAN:
|
||||
/* Have to find the parent device */
|
||||
if (nm_platform_vlan_get_info (ifindex, &parent_ifindex, NULL)) {
|
||||
parent = find_device_by_ifindex (self, parent_ifindex);
|
||||
|
@ -2283,24 +2271,11 @@ udev_device_added_cb (NMUdevManager *udev_mgr,
|
|||
}
|
||||
} else
|
||||
nm_log_err (LOGD_HW, "(%s): failed to get VLAN parent ifindex", iface);
|
||||
} else if (is_adsl (udev_device)) {
|
||||
device = nm_device_adsl_new (sysfs_path, iface, driver);
|
||||
} else {
|
||||
gint etype;
|
||||
gboolean is_ctc;
|
||||
break;
|
||||
|
||||
/* For anything else, if it uses Ethernet encapsulation, consider it
|
||||
* an Ethernet device. (But some s390 CTC-type devices report 256 for
|
||||
* some reason, and we need to call them Ethernet too. FIXME: use
|
||||
* something other than interface name to detect CTC here.)
|
||||
*/
|
||||
etype = g_udev_device_get_sysfs_attr_as_int (udev_device, "type");
|
||||
is_ctc = g_str_has_prefix (iface, "ctc") && (etype == 256);
|
||||
|
||||
if (etype == ARPHRD_ETHER || is_ctc)
|
||||
device = nm_device_ethernet_new (sysfs_path, iface, driver);
|
||||
else
|
||||
device = nm_device_generic_new (sysfs_path, iface, driver);
|
||||
default:
|
||||
device = nm_device_generic_new (sysfs_path, iface, driver);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -265,17 +265,18 @@ delete_kernel_object (struct nl_sock *sock, struct nl_object *object)
|
|||
static const char *
|
||||
type_to_string (NMLinkType type)
|
||||
{
|
||||
/* Note that this only has to support virtual types */
|
||||
switch (type) {
|
||||
case NM_LINK_TYPE_DUMMY:
|
||||
return "dummy";
|
||||
case NM_LINK_TYPE_VLAN:
|
||||
return "vlan";
|
||||
case NM_LINK_TYPE_BRIDGE:
|
||||
return "bridge";
|
||||
case NM_LINK_TYPE_BOND:
|
||||
return "bond";
|
||||
case NM_LINK_TYPE_TEAM:
|
||||
return "team";
|
||||
case NM_LINK_TYPE_VLAN:
|
||||
return "vlan";
|
||||
default:
|
||||
g_warning ("Wrong type: %d", type);
|
||||
return NULL;
|
||||
|
@ -299,25 +300,36 @@ link_extract_type (struct rtnl_link *rtnllink, const char **out_name)
|
|||
|
||||
type = rtnl_link_get_type (rtnllink);
|
||||
|
||||
if (!type)
|
||||
if (!type) {
|
||||
switch (rtnl_link_get_arptype (rtnllink)) {
|
||||
case ARPHRD_LOOPBACK:
|
||||
return_type (NM_LINK_TYPE_LOOPBACK, "loopback");
|
||||
case ARPHRD_ETHER:
|
||||
return_type (NM_LINK_TYPE_ETHERNET, "ethernet");
|
||||
default:
|
||||
return_type (NM_LINK_TYPE_GENERIC, "generic");
|
||||
case 256:
|
||||
/* Some s390 CTC-type devices report 256 for the encapsulation type
|
||||
* for some reason, but we need to call them Ethernet too. FIXME: use
|
||||
* something other than interface name to detect CTC here.
|
||||
*/
|
||||
if (g_str_has_prefix (rtnl_link_get_name (rtnllink), "ctc"))
|
||||
return_type (NM_LINK_TYPE_ETHERNET, "ethernet");
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
return_type (NM_LINK_TYPE_GENERIC, "generic");
|
||||
} else if (!strcmp (type, "ipoib"))
|
||||
return_type (NM_LINK_TYPE_INFINIBAND, "infiniband");
|
||||
else if (!strcmp (type, "dummy"))
|
||||
return_type (NM_LINK_TYPE_DUMMY, "dummy");
|
||||
else if (!strcmp (type, "vlan"))
|
||||
return_type (NM_LINK_TYPE_VLAN, "vlan");
|
||||
else if (!strcmp (type, "bridge"))
|
||||
return_type (NM_LINK_TYPE_BRIDGE, "bridge");
|
||||
else if (!strcmp (type, "bond"))
|
||||
return_type (NM_LINK_TYPE_BOND, "bond");
|
||||
else if (!strcmp (type, "team"))
|
||||
return_type (NM_LINK_TYPE_TEAM, "team");
|
||||
else if (!strcmp (type, "vlan"))
|
||||
return_type (NM_LINK_TYPE_VLAN, "vlan");
|
||||
else
|
||||
return_type (NM_LINK_TYPE_UNKNOWN, "unknown");
|
||||
}
|
||||
|
|
|
@ -51,13 +51,21 @@ typedef enum {
|
|||
NM_LINK_TYPE_NONE,
|
||||
NM_LINK_TYPE_UNKNOWN,
|
||||
NM_LINK_TYPE_GENERIC,
|
||||
NM_LINK_TYPE_LOOPBACK,
|
||||
|
||||
/* Hardware types */
|
||||
NM_LINK_TYPE_ETHERNET,
|
||||
NM_LINK_TYPE_INFINIBAND,
|
||||
|
||||
/* Virtual types */
|
||||
NM_LINK_TYPE_DUMMY,
|
||||
NM_LINK_TYPE_LOOPBACK,
|
||||
NM_LINK_TYPE_VLAN,
|
||||
|
||||
/* Virtual types with slaves */
|
||||
NM_LINK_TYPE_BRIDGE,
|
||||
NM_LINK_TYPE_BOND,
|
||||
NM_LINK_TYPE_TEAM,
|
||||
NM_LINK_TYPE_VLAN,
|
||||
|
||||
} NMLinkType;
|
||||
|
||||
typedef struct {
|
||||
|
|
Loading…
Reference in a new issue