nl80211: restore iterating over all devices in nl80211_phy2ifname()

This reverts to the earlier behaviour, because:
* phys can be renamed, which breaks hardcoding "phy%d"
* /sys/class/ieee80211/*/device can return networks of other phys,
  since "device" is a symlink which can have multiple phys

The earlier behaviour fixes both points.

Fixes: 6194aaf0 "nl80211: simplify iterating over phy's devices"
Signed-off-by: Andre Heider <a.heider@gmail.com>
Tested-by: Olcay Korkmaz <nuke_mania@hotmail.com>
[ drop extra Fixes tag related to openwrt issue ]
Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
This commit is contained in:
Andre Heider 2023-01-30 19:57:57 +01:00 committed by Christian Marangi
parent 1e4e709d6f
commit c7eb8ebe33
No known key found for this signature in database
GPG key ID: AC001D09ADBFEAD7

View file

@ -825,13 +825,15 @@ static char * nl80211_phy2ifname(const char *ifname)
memset(nif, 0, sizeof(nif));
snprintf(buffer, sizeof(buffer),
"/sys/class/ieee80211/phy%d/device/net", phyidx);
if ((d = opendir(buffer)) != NULL)
if ((d = opendir("/sys/class/net")) != NULL)
{
while ((e = readdir(d)) != NULL)
{
snprintf(buffer, sizeof(buffer),
"/sys/class/net/%s/phy80211/index", e->d_name);
if (nl80211_readint(buffer) != phyidx)
continue;
snprintf(buffer, sizeof(buffer),
"/sys/class/net/%s/ifindex", e->d_name);
cifidx = nl80211_readint(buffer);