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:
@@ -71,6 +71,7 @@
|
|||||||
#include "wifi-utils.h"
|
#include "wifi-utils.h"
|
||||||
#include "nm-enum-types.h"
|
#include "nm-enum-types.h"
|
||||||
#include "nm-sleep-monitor.h"
|
#include "nm-sleep-monitor.h"
|
||||||
|
#include "nm-platform.h"
|
||||||
|
|
||||||
#if WITH_CONCHECK
|
#if WITH_CONCHECK
|
||||||
#include "nm-connectivity.h"
|
#include "nm-connectivity.h"
|
||||||
@@ -2158,31 +2159,6 @@ is_olpc_mesh (GUdevDevice *device)
|
|||||||
return (prop != NULL);
|
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
|
static gboolean
|
||||||
is_adsl (GUdevDevice *device)
|
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 (device == NULL) {
|
||||||
if (is_olpc_mesh (udev_device)) /* must be before is_wireless */
|
NMLinkType type;
|
||||||
device = nm_device_olpc_mesh_new (sysfs_path, iface, driver);
|
int parent_ifindex = -1;
|
||||||
else if (is_wireless (udev_device))
|
NMDevice *parent;
|
||||||
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)) {
|
|
||||||
|
|
||||||
|
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 */
|
/* FIXME: always create device when we handle bridges non-destructively */
|
||||||
if (bridge_created_by_nm (self, iface))
|
if (bridge_created_by_nm (self, iface))
|
||||||
device = nm_device_bridge_new (sysfs_path, iface);
|
device = nm_device_bridge_new (sysfs_path, iface);
|
||||||
else
|
else
|
||||||
nm_log_info (LOGD_BRIDGE, "(%s): ignoring bridge not created by NetworkManager", iface);
|
nm_log_info (LOGD_BRIDGE, "(%s): ignoring bridge not created by NetworkManager", iface);
|
||||||
} else if (is_vlan (ifindex)) {
|
break;
|
||||||
int parent_ifindex = -1;
|
case NM_LINK_TYPE_VLAN:
|
||||||
NMDevice *parent;
|
|
||||||
|
|
||||||
/* Have to find the parent device */
|
/* Have to find the parent device */
|
||||||
if (nm_platform_vlan_get_info (ifindex, &parent_ifindex, NULL)) {
|
if (nm_platform_vlan_get_info (ifindex, &parent_ifindex, NULL)) {
|
||||||
parent = find_device_by_ifindex (self, parent_ifindex);
|
parent = find_device_by_ifindex (self, parent_ifindex);
|
||||||
@@ -2283,24 +2271,11 @@ udev_device_added_cb (NMUdevManager *udev_mgr,
|
|||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
nm_log_err (LOGD_HW, "(%s): failed to get VLAN parent ifindex", iface);
|
nm_log_err (LOGD_HW, "(%s): failed to get VLAN parent ifindex", iface);
|
||||||
} else if (is_adsl (udev_device)) {
|
break;
|
||||||
device = nm_device_adsl_new (sysfs_path, iface, driver);
|
|
||||||
} else {
|
|
||||||
gint etype;
|
|
||||||
gboolean is_ctc;
|
|
||||||
|
|
||||||
/* For anything else, if it uses Ethernet encapsulation, consider it
|
default:
|
||||||
* an Ethernet device. (But some s390 CTC-type devices report 256 for
|
device = nm_device_generic_new (sysfs_path, iface, driver);
|
||||||
* some reason, and we need to call them Ethernet too. FIXME: use
|
break;
|
||||||
* 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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -265,17 +265,18 @@ delete_kernel_object (struct nl_sock *sock, struct nl_object *object)
|
|||||||
static const char *
|
static const char *
|
||||||
type_to_string (NMLinkType type)
|
type_to_string (NMLinkType type)
|
||||||
{
|
{
|
||||||
|
/* Note that this only has to support virtual types */
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case NM_LINK_TYPE_DUMMY:
|
case NM_LINK_TYPE_DUMMY:
|
||||||
return "dummy";
|
return "dummy";
|
||||||
|
case NM_LINK_TYPE_VLAN:
|
||||||
|
return "vlan";
|
||||||
case NM_LINK_TYPE_BRIDGE:
|
case NM_LINK_TYPE_BRIDGE:
|
||||||
return "bridge";
|
return "bridge";
|
||||||
case NM_LINK_TYPE_BOND:
|
case NM_LINK_TYPE_BOND:
|
||||||
return "bond";
|
return "bond";
|
||||||
case NM_LINK_TYPE_TEAM:
|
case NM_LINK_TYPE_TEAM:
|
||||||
return "team";
|
return "team";
|
||||||
case NM_LINK_TYPE_VLAN:
|
|
||||||
return "vlan";
|
|
||||||
default:
|
default:
|
||||||
g_warning ("Wrong type: %d", type);
|
g_warning ("Wrong type: %d", type);
|
||||||
return NULL;
|
return NULL;
|
||||||
@@ -299,25 +300,36 @@ link_extract_type (struct rtnl_link *rtnllink, const char **out_name)
|
|||||||
|
|
||||||
type = rtnl_link_get_type (rtnllink);
|
type = rtnl_link_get_type (rtnllink);
|
||||||
|
|
||||||
if (!type)
|
if (!type) {
|
||||||
switch (rtnl_link_get_arptype (rtnllink)) {
|
switch (rtnl_link_get_arptype (rtnllink)) {
|
||||||
case ARPHRD_LOOPBACK:
|
case ARPHRD_LOOPBACK:
|
||||||
return_type (NM_LINK_TYPE_LOOPBACK, "loopback");
|
return_type (NM_LINK_TYPE_LOOPBACK, "loopback");
|
||||||
case ARPHRD_ETHER:
|
case ARPHRD_ETHER:
|
||||||
return_type (NM_LINK_TYPE_ETHERNET, "ethernet");
|
return_type (NM_LINK_TYPE_ETHERNET, "ethernet");
|
||||||
default:
|
case 256:
|
||||||
return_type (NM_LINK_TYPE_GENERIC, "generic");
|
/* 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"))
|
else if (!strcmp (type, "dummy"))
|
||||||
return_type (NM_LINK_TYPE_DUMMY, "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"))
|
else if (!strcmp (type, "bridge"))
|
||||||
return_type (NM_LINK_TYPE_BRIDGE, "bridge");
|
return_type (NM_LINK_TYPE_BRIDGE, "bridge");
|
||||||
else if (!strcmp (type, "bond"))
|
else if (!strcmp (type, "bond"))
|
||||||
return_type (NM_LINK_TYPE_BOND, "bond");
|
return_type (NM_LINK_TYPE_BOND, "bond");
|
||||||
else if (!strcmp (type, "team"))
|
else if (!strcmp (type, "team"))
|
||||||
return_type (NM_LINK_TYPE_TEAM, "team");
|
return_type (NM_LINK_TYPE_TEAM, "team");
|
||||||
else if (!strcmp (type, "vlan"))
|
|
||||||
return_type (NM_LINK_TYPE_VLAN, "vlan");
|
|
||||||
else
|
else
|
||||||
return_type (NM_LINK_TYPE_UNKNOWN, "unknown");
|
return_type (NM_LINK_TYPE_UNKNOWN, "unknown");
|
||||||
}
|
}
|
||||||
|
@@ -51,13 +51,21 @@ typedef enum {
|
|||||||
NM_LINK_TYPE_NONE,
|
NM_LINK_TYPE_NONE,
|
||||||
NM_LINK_TYPE_UNKNOWN,
|
NM_LINK_TYPE_UNKNOWN,
|
||||||
NM_LINK_TYPE_GENERIC,
|
NM_LINK_TYPE_GENERIC,
|
||||||
NM_LINK_TYPE_LOOPBACK,
|
|
||||||
|
/* Hardware types */
|
||||||
NM_LINK_TYPE_ETHERNET,
|
NM_LINK_TYPE_ETHERNET,
|
||||||
|
NM_LINK_TYPE_INFINIBAND,
|
||||||
|
|
||||||
|
/* Virtual types */
|
||||||
NM_LINK_TYPE_DUMMY,
|
NM_LINK_TYPE_DUMMY,
|
||||||
|
NM_LINK_TYPE_LOOPBACK,
|
||||||
|
NM_LINK_TYPE_VLAN,
|
||||||
|
|
||||||
|
/* Virtual types with slaves */
|
||||||
NM_LINK_TYPE_BRIDGE,
|
NM_LINK_TYPE_BRIDGE,
|
||||||
NM_LINK_TYPE_BOND,
|
NM_LINK_TYPE_BOND,
|
||||||
NM_LINK_TYPE_TEAM,
|
NM_LINK_TYPE_TEAM,
|
||||||
NM_LINK_TYPE_VLAN,
|
|
||||||
} NMLinkType;
|
} NMLinkType;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
Reference in New Issue
Block a user