core: use nmp_utils_sysctl_open_netdir() to detect link-type
This commit is contained in:
@@ -573,18 +573,14 @@ _lookup_cached_link (const NMPCache *cache, int ifindex, gboolean *completed_fro
|
|||||||
#define DEVTYPE_PREFIX "DEVTYPE="
|
#define DEVTYPE_PREFIX "DEVTYPE="
|
||||||
|
|
||||||
static char *
|
static char *
|
||||||
_linktype_read_devtype (const char *ifname)
|
_linktype_read_devtype (int dirfd)
|
||||||
{
|
{
|
||||||
char uevent[NM_STRLEN ("/sys/class/net/123456789012345/uevent\0") + 100 /*safety*/];
|
|
||||||
char *contents = NULL;
|
char *contents = NULL;
|
||||||
char *cont, *end;
|
char *cont, *end;
|
||||||
|
|
||||||
nm_sprintf_buf (uevent,
|
nm_assert (dirfd >= 0);
|
||||||
"/sys/class/net/%s/uevent",
|
|
||||||
NM_ASSERT_VALID_PATH_COMPONENT (ifname));
|
|
||||||
nm_assert (strlen (uevent) < sizeof (uevent) - 1);
|
|
||||||
|
|
||||||
if (!g_file_get_contents (uevent, &contents, NULL, NULL))
|
if (nm_utils_file_get_contents (dirfd, "uevent", 1*1024*1024, &contents, NULL, NULL) < 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
for (cont = contents; cont; cont = end) {
|
for (cont = contents; cont; cont = end) {
|
||||||
end = strpbrk (cont, "\r\n");
|
end = strpbrk (cont, "\r\n");
|
||||||
@@ -680,9 +676,10 @@ _linktype_get_type (NMPlatform *platform,
|
|||||||
return NM_LINK_TYPE_IP6TNL;
|
return NM_LINK_TYPE_IP6TNL;
|
||||||
|
|
||||||
if (ifname) {
|
if (ifname) {
|
||||||
char anycast_mask[NM_STRLEN ("/sys/class/net/123456789012345/anycast_mask\0") + 100 /*safety*/];
|
nm_auto_close int dirfd = -1;
|
||||||
gs_free char *driver = NULL;
|
gs_free char *driver = NULL;
|
||||||
gs_free char *devtype = NULL;
|
gs_free char *devtype = NULL;
|
||||||
|
char ifname_verified[IFNAMSIZ];
|
||||||
|
|
||||||
/* Fallback OVS detection for kernel <= 3.16 */
|
/* Fallback OVS detection for kernel <= 3.16 */
|
||||||
if (nmp_utils_ethtool_get_driver_info (ifname, &driver, NULL, NULL)) {
|
if (nmp_utils_ethtool_get_driver_info (ifname, &driver, NULL, NULL)) {
|
||||||
@@ -698,15 +695,12 @@ _linktype_get_type (NMPlatform *platform,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
nm_sprintf_buf (anycast_mask,
|
dirfd = nmp_utils_sysctl_open_netdir (ifindex, ifname, ifname_verified);
|
||||||
"/sys/class/net/%s/anycast_mask",
|
if (dirfd >= 0) {
|
||||||
NM_ASSERT_VALID_PATH_COMPONENT (ifname));
|
if (faccessat (dirfd, "anycast_mask", F_OK, 0) == 0)
|
||||||
nm_assert (strlen (anycast_mask) < sizeof (anycast_mask) - 1);
|
|
||||||
|
|
||||||
if (g_file_test (anycast_mask, G_FILE_TEST_EXISTS))
|
|
||||||
return NM_LINK_TYPE_OLPC_MESH;
|
return NM_LINK_TYPE_OLPC_MESH;
|
||||||
|
|
||||||
devtype = _linktype_read_devtype (ifname);
|
devtype = _linktype_read_devtype (dirfd);
|
||||||
for (i = 0; devtype && i < G_N_ELEMENTS (linktypes); i++) {
|
for (i = 0; devtype && i < G_N_ELEMENTS (linktypes); i++) {
|
||||||
if (g_strcmp0 (devtype, linktypes[i].devtype) == 0) {
|
if (g_strcmp0 (devtype, linktypes[i].devtype) == 0) {
|
||||||
if (linktypes[i].nm_type == NM_LINK_TYPE_BNEP) {
|
if (linktypes[i].nm_type == NM_LINK_TYPE_BNEP) {
|
||||||
@@ -721,8 +715,9 @@ _linktype_get_type (NMPlatform *platform,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Fallback for drivers that don't call SET_NETDEV_DEVTYPE() */
|
/* Fallback for drivers that don't call SET_NETDEV_DEVTYPE() */
|
||||||
if (wifi_utils_is_wifi (ifindex, ifname))
|
if (wifi_utils_is_wifi (dirfd, ifname_verified))
|
||||||
return NM_LINK_TYPE_WIFI;
|
return NM_LINK_TYPE_WIFI;
|
||||||
|
}
|
||||||
|
|
||||||
if (arptype == ARPHRD_ETHER) {
|
if (arptype == ARPHRD_ETHER) {
|
||||||
/* Misc non-upstream WWAN drivers. rmnet is Qualcomm's proprietary
|
/* Misc non-upstream WWAN drivers. rmnet is Qualcomm's proprietary
|
||||||
|
@@ -183,39 +183,19 @@ wifi_utils_deinit (WifiData *data)
|
|||||||
}
|
}
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
wifi_utils_is_wifi (int ifindex, const char *ifname)
|
wifi_utils_is_wifi (int dirfd, const char *ifname)
|
||||||
{
|
{
|
||||||
int fd_sysnet;
|
g_return_val_if_fail (dirfd >= 0, FALSE);
|
||||||
int fd_phy80211;
|
|
||||||
char ifname_verified[IFNAMSIZ];
|
|
||||||
|
|
||||||
g_return_val_if_fail (ifindex > 0, FALSE);
|
if (faccessat (dirfd, "phy80211", F_OK, 0) == 0)
|
||||||
|
|
||||||
fd_sysnet = nmp_utils_sysctl_open_netdir (ifindex, ifname, ifname_verified);
|
|
||||||
if (fd_sysnet < 0)
|
|
||||||
return FALSE;
|
|
||||||
|
|
||||||
/* there might have been a race and ifname might be wrong. Below for checking
|
|
||||||
* wext, use the possibly improved name that we just verified. */
|
|
||||||
ifname = ifname_verified;
|
|
||||||
|
|
||||||
fd_phy80211 = openat (fd_sysnet, "phy80211", O_CLOEXEC);
|
|
||||||
close (fd_sysnet);
|
|
||||||
|
|
||||||
if (fd_phy80211 >= 0) {
|
|
||||||
close (fd_phy80211);
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
|
||||||
|
|
||||||
#if HAVE_WEXT
|
#if HAVE_WEXT
|
||||||
if (wifi_wext_is_wifi (ifname))
|
if (wifi_wext_is_wifi (ifname))
|
||||||
return TRUE;
|
return TRUE;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* OLPC Mesh-only functions */
|
/* OLPC Mesh-only functions */
|
||||||
|
|
||||||
guint32
|
guint32
|
||||||
|
@@ -28,7 +28,7 @@
|
|||||||
|
|
||||||
typedef struct WifiData WifiData;
|
typedef struct WifiData WifiData;
|
||||||
|
|
||||||
gboolean wifi_utils_is_wifi (int ifindex, const char *ifname);
|
gboolean wifi_utils_is_wifi (int dirfd, const char *ifname);
|
||||||
|
|
||||||
WifiData *wifi_utils_init (const char *iface, int ifindex, gboolean check_scan);
|
WifiData *wifi_utils_init (const char *iface, int ifindex, gboolean check_scan);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user