nl80211: prefer non-supplicant-based devices

If a phy has multiple devices, prefer non-supplicant-based ones as per
link_mode, see [0] and [1].

The nl80211 API provides more information than wpa_supplicant/hostapd does,
like HT/VHT operation, which are used by e.g. luci's channel analysis.

[0] https://www.kernel.org/doc/Documentation/ABI/testing/sysfs-class-net
[1] https://github.com/openwrt/luci/issues/6167#issuecomment-1364500296

Signed-off-by: Andre Heider <a.heider@gmail.com>
This commit is contained in:
Andre Heider 2022-12-24 12:03:01 +01:00 committed by Christian Marangi
parent 6194aaf052
commit 2c4ee842e5
No known key found for this signature in database
GPG key ID: AC001D09ADBFEAD7

View file

@ -807,10 +807,9 @@ nla_put_failure:
static char * nl80211_phy2ifname(const char *ifname) static char * nl80211_phy2ifname(const char *ifname)
{ {
int ifidx = -1, cifidx = -1, phyidx = -1; int ifidx = -1, cifidx, lmode = 1, clmode, phyidx;
char buffer[512]; char buffer[512];
static char nif[IFNAMSIZ] = { 0 }; static char nif[IFNAMSIZ] = { 0 };
DIR *d; DIR *d;
struct dirent *e; struct dirent *e;
@ -835,11 +834,20 @@ static char * nl80211_phy2ifname(const char *ifname)
{ {
snprintf(buffer, sizeof(buffer), snprintf(buffer, sizeof(buffer),
"/sys/class/net/%s/ifindex", e->d_name); "/sys/class/net/%s/ifindex", e->d_name);
cifidx = nl80211_readint(buffer);
if ((cifidx = nl80211_readint(buffer)) >= 0 && if (cifidx < 0)
((ifidx < 0) || (cifidx < ifidx))) continue;
snprintf(buffer, sizeof(buffer),
"/sys/class/net/%s/link_mode", e->d_name);
clmode = nl80211_readint(buffer);
/* prefer non-supplicant-based devices */
if ((ifidx < 0) || (cifidx < ifidx) || ((lmode == 1) && (clmode != 1)))
{ {
ifidx = cifidx; ifidx = cifidx;
lmode = clmode;
strncpy(nif, e->d_name, sizeof(nif) - 1); strncpy(nif, e->d_name, sizeof(nif) - 1);
} }
} }