wifi: don't query nl80211 for non-WiFi devices (bgo #740131)

The upstream kernel added module aliases for nl80211 in commit
fb4e156886ce6e8309e912d8b370d192330d19d3, so querying nl80211
now auto-loads the module.  Previously NM was doing this to
determine whether an ethernet-like device was a Wi-Fi device
that supported nl80211, but this leads to the nl80211 loading
on platforms that will never have or use Wi-Fi.

Since every nl80211-capable device will already have
DEVTYPE=wlan set (from /sys/class/net/wlan0/uevent), we can use
that as an indicator that the ethernet-like device is WiFi
instead of asking nl80211.

https://bugzilla.gnome.org/show_bug.cgi?id=740131
This commit is contained in:
Dan Williams
2014-11-14 11:05:16 -06:00
parent eeb4306111
commit 45bfb653f3
5 changed files with 10 additions and 53 deletions

View File

@@ -766,7 +766,7 @@ link_type_from_udev (NMPlatform *platform, int ifindex, const char *ifname, int
prop = g_udev_device_get_property (udev_device, "DEVTYPE"); prop = g_udev_device_get_property (udev_device, "DEVTYPE");
sysfs_path = g_udev_device_get_sysfs_path (udev_device); sysfs_path = g_udev_device_get_sysfs_path (udev_device);
if (g_strcmp0 (prop, "wlan") == 0 || wifi_utils_is_wifi (ifname, sysfs_path)) if (wifi_utils_is_wifi (ifname, sysfs_path, prop))
return_type (NM_LINK_TYPE_WIFI, "wifi"); return_type (NM_LINK_TYPE_WIFI, "wifi");
else if (g_strcmp0 (prop, "wwan") == 0) else if (g_strcmp0 (prop, "wwan") == 0)
return_type (NM_LINK_TYPE_WWAN_ETHERNET, "wwan"); return_type (NM_LINK_TYPE_WWAN_ETHERNET, "wwan");

View File

@@ -934,48 +934,3 @@ error:
return NULL; return NULL;
} }
gboolean
wifi_nl80211_is_wifi (const char *iface)
{
struct nl_sock *nl_sock;
struct nl_cb *nl_cb = NULL;
struct nl_msg *msg = NULL;
int id, ifindex;
struct nl80211_iface_info iface_info = {
.mode = NM_802_11_MODE_UNKNOWN,
};
gboolean is_wifi = FALSE;
nl_sock = nl_socket_alloc ();
if (nl_sock == NULL)
return FALSE;
if (genl_connect (nl_sock))
goto error;
ifindex = nm_platform_link_get_ifindex (iface);
if (ifindex < 0)
goto error;
id = genl_ctrl_resolve (nl_sock, "nl80211");
if (id < 0)
goto error;
nl_cb = nl_cb_alloc (NL_CB_DEFAULT);
if (nl_cb) {
msg = _nl80211_alloc_msg (id, ifindex, -1, NL80211_CMD_GET_INTERFACE, 0);
if (_nl80211_send_and_recv (nl_sock,
nl_cb,
msg,
nl80211_iface_info_handler,
&iface_info) >= 0)
is_wifi = (iface_info.mode != NM_802_11_MODE_UNKNOWN);
}
error:
if (nl_cb)
nl_cb_put (nl_cb);
nl_socket_free (nl_sock);
return is_wifi;
}

View File

@@ -25,6 +25,4 @@
WifiData *wifi_nl80211_init (const char *iface, int ifindex); WifiData *wifi_nl80211_init (const char *iface, int ifindex);
gboolean wifi_nl80211_is_wifi (const char *iface);
#endif /* __WIFI_UTILS_NL80211_H__ */ #endif /* __WIFI_UTILS_NL80211_H__ */

View File

@@ -162,13 +162,20 @@ wifi_utils_deinit (WifiData *data)
} }
gboolean gboolean
wifi_utils_is_wifi (const char *iface, const char *sysfs_path) wifi_utils_is_wifi (const char *iface, const char *sysfs_path, const char *devtype)
{ {
char phy80211_path[255]; char phy80211_path[255];
struct stat s; struct stat s;
g_return_val_if_fail (iface != NULL, FALSE); g_return_val_if_fail (iface != NULL, FALSE);
if (g_strcmp0 (devtype, "wlan") == 0) {
/* All Wi-Fi drivers should set DEVTYPE=wlan. Since the kernel's
* cfg80211/nl80211 stack does, this check should match any nl80211
* capable driver (including mac82011-based ones). */
return TRUE;
}
if (sysfs_path) { if (sysfs_path) {
/* Check for nl80211 sysfs paths */ /* Check for nl80211 sysfs paths */
g_snprintf (phy80211_path, sizeof (phy80211_path), "%s/phy80211", sysfs_path); g_snprintf (phy80211_path, sizeof (phy80211_path), "%s/phy80211", sysfs_path);
@@ -176,9 +183,6 @@ wifi_utils_is_wifi (const char *iface, const char *sysfs_path)
return TRUE; return TRUE;
} }
if (wifi_nl80211_is_wifi (iface))
return TRUE;
#if HAVE_WEXT #if HAVE_WEXT
if (wifi_wext_is_wifi (iface)) if (wifi_wext_is_wifi (iface))
return TRUE; return TRUE;

View File

@@ -29,7 +29,7 @@
typedef struct WifiData WifiData; typedef struct WifiData WifiData;
gboolean wifi_utils_is_wifi (const char *iface, const char *sysfs_path); gboolean wifi_utils_is_wifi (const char *iface, const char *sysfs_path, const char *devtype);
WifiData *wifi_utils_init (const char *iface, int ifindex, gboolean check_scan); WifiData *wifi_utils_init (const char *iface, int ifindex, gboolean check_scan);