summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Williams <dcbw@redhat.com>2015-04-13 15:44:10 -0500
committerLubomir Rintel <lkundrak@v3.sk>2015-05-28 11:52:32 +0200
commitf71e5c27e0dd0f418f9dac18248d0a2f3d56b38a (patch)
treece85c63258b3611653ac7d04e7c9bf42f22607d4
parent67c0693f94074195b5714aa407663ada5e416581 (diff)
downloadNetworkManager-f71e5c27e0dd0f418f9dac18248d0a2f3d56b38a.tar.gz
platform: don't use udev for link type determination
This allows us to always announce links when the kernel advertises them, instead of waiting for udev. (cherry picked from commit 2599dadc2859262de784567384ba72ab92204d55)
-rw-r--r--data/77-nm-olpc-mesh.rules6
-rw-r--r--data/Makefile.am4
-rw-r--r--src/platform/nm-linux-platform.c83
3 files changed, 47 insertions, 46 deletions
diff --git a/data/77-nm-olpc-mesh.rules b/data/77-nm-olpc-mesh.rules
deleted file mode 100644
index a1a1554c2b..0000000000
--- a/data/77-nm-olpc-mesh.rules
+++ /dev/null
@@ -1,6 +0,0 @@
-# do not edit this file, it will be overwritten on update
-
-# The fact that this device is driven by libertas is not currently exposed
-# in the sysfs tree..?
-KERNEL=="msh*", SUBSYSTEM=="net", DRIVERS=="usb", ATTRS{idVendor}=="1286", ATTRS{idProduct}=="2001", ENV{ID_NM_OLPC_MESH}="1"
-
diff --git a/data/Makefile.am b/data/Makefile.am
index 5a95ea2a42..64ff337636 100644
--- a/data/Makefile.am
+++ b/data/Makefile.am
@@ -37,8 +37,7 @@ examples_DATA = server.conf
if WITH_UDEV_DIR
udevrulesdir = $(UDEV_DIR)/rules.d
udevrules_DATA = \
- 85-nm-unmanaged.rules \
- 77-nm-olpc-mesh.rules
+ 85-nm-unmanaged.rules
endif
server.conf: server.conf.in
@@ -59,7 +58,6 @@ EXTRA_DIST = \
NetworkManager-dispatcher.service.in \
org.freedesktop.NetworkManager.service.in \
85-nm-unmanaged.rules \
- 77-nm-olpc-mesh.rules \
server.conf.in
CLEANFILES = \
diff --git a/src/platform/nm-linux-platform.c b/src/platform/nm-linux-platform.c
index 8d0fb0b531..0b469a9ea9 100644
--- a/src/platform/nm-linux-platform.c
+++ b/src/platform/nm-linux-platform.c
@@ -412,35 +412,6 @@ udev_get_driver (GUdevDevice *device, int ifindex)
return driver;
}
-static NMLinkType
-udev_detect_link_type_from_device (GUdevDevice *udev_device, const char *ifname, int arptype, const char **out_name)
-{
- const char *prop, *sysfs_path;
-
- g_assert (ifname);
-
- if (!udev_device)
- return_type (NM_LINK_TYPE_UNKNOWN, "unknown");
-
- if ( g_udev_device_get_property (udev_device, "ID_NM_OLPC_MESH")
- || g_udev_device_get_sysfs_attr (udev_device, "anycast_mask"))
- return_type (NM_LINK_TYPE_OLPC_MESH, "olpc-mesh");
-
- prop = g_udev_device_get_property (udev_device, "DEVTYPE");
- sysfs_path = g_udev_device_get_sysfs_path (udev_device);
- if (wifi_utils_is_wifi (ifname, sysfs_path, prop))
- return_type (NM_LINK_TYPE_WIFI, "wifi");
- else if (g_strcmp0 (prop, "wwan") == 0)
- return_type (NM_LINK_TYPE_WWAN_ETHERNET, "wwan");
- else if (g_strcmp0 (prop, "wimax") == 0)
- return_type (NM_LINK_TYPE_WIMAX, "wimax");
-
- if (arptype == ARPHRD_ETHER)
- return_type (NM_LINK_TYPE_ETHERNET, "ethernet");
-
- return_type (NM_LINK_TYPE_UNKNOWN, "unknown");
-}
-
/******************************************************************
* NMPlatform types and functions
******************************************************************/
@@ -854,6 +825,31 @@ link_is_announceable (NMPlatform *platform, struct rtnl_link *rtnllink)
return FALSE;
}
+#define DEVTYPE_PREFIX "DEVTYPE="
+
+static char *
+read_devtype (const char *sysfs_path)
+{
+ gs_free char *uevent = g_strdup_printf ("%s/uevent", sysfs_path);
+ char *contents = NULL;
+ char *cont, *end;
+
+ if (!g_file_get_contents (uevent, &contents, NULL, NULL))
+ return NULL;
+ for (cont = contents; cont; cont = end) {
+ end = strpbrk (cont, "\r\n");
+ if (end)
+ *end++ = '\0';
+ if (strncmp (cont, DEVTYPE_PREFIX, STRLEN (DEVTYPE_PREFIX)) == 0) {
+ cont += STRLEN (DEVTYPE_PREFIX);
+ memmove (contents, cont, strlen (cont) + 1);
+ return contents;
+ }
+ }
+ g_free (contents);
+ return NULL;
+}
+
static NMLinkType
link_extract_type (NMPlatform *platform, struct rtnl_link *rtnllink, const char **out_name)
{
@@ -868,7 +864,9 @@ link_extract_type (NMPlatform *platform, struct rtnl_link *rtnllink, const char
int arptype = rtnl_link_get_arptype (rtnllink);
const char *driver;
const char *ifname;
- GUdevDevice *udev_device = NULL;
+ gs_free char *anycast_mask = NULL;
+ gs_free char *sysfs_path = NULL;
+ gs_free char *devtype = NULL;
if (arptype == ARPHRD_LOOPBACK)
return_type (NM_LINK_TYPE_LOOPBACK, "loopback");
@@ -891,14 +889,25 @@ link_extract_type (NMPlatform *platform, struct rtnl_link *rtnllink, const char
if (!g_strcmp0 (driver, "openvswitch"))
return_type (NM_LINK_TYPE_OPENVSWITCH, "openvswitch");
- if (platform) {
- udev_device = g_hash_table_lookup (NM_LINUX_PLATFORM_GET_PRIVATE (platform)->udev_devices,
- GINT_TO_POINTER (rtnl_link_get_ifindex (rtnllink)));
+ sysfs_path = g_strdup_printf ("/sys/class/net/%s", ifname);
+ anycast_mask = g_strdup_printf ("%s/anycast_mask", sysfs_path);
+ if (g_file_test (anycast_mask, G_FILE_TEST_EXISTS))
+ return_type (NM_LINK_TYPE_OLPC_MESH, "olpc-mesh");
+
+ devtype = read_devtype (sysfs_path);
+ if (devtype) {
+ if (wifi_utils_is_wifi (ifname, sysfs_path, devtype))
+ return_type (NM_LINK_TYPE_WIFI, "wifi");
+ else if (g_strcmp0 (devtype, "wwan") == 0)
+ return_type (NM_LINK_TYPE_WWAN_ETHERNET, "wwan");
+ else if (g_strcmp0 (devtype, "wimax") == 0)
+ return_type (NM_LINK_TYPE_WIMAX, "wimax");
}
- return udev_detect_link_type_from_device (udev_device,
- ifname,
- arptype,
- out_name);
+
+ if (arptype == ARPHRD_ETHER)
+ return_type (NM_LINK_TYPE_ETHERNET, "ethernet");
+
+ return_type (NM_LINK_TYPE_UNKNOWN, "unknown");
} else if (!strcmp (type, "dummy"))
return_type (NM_LINK_TYPE_DUMMY, "dummy");
else if (!strcmp (type, "gre"))