Re: [hackers] [slstatus][PATCH] Fix 'ifindex' to retry detection if interface is down at startup

From: Taha Medhous <tahamedhous_AT_gmail.com>
Date: Mon, 04 Aug 2025 22:06:47 +0100

hello,

Turns out issue is related to iwd. by default it takes control of the wireless interfaces and destroys them when its service is down, which explains why the interface couldn't be found when slstatus started.

the patch work around this by continually checking the cached interface until iwd is up
(this can be avoided by setting 'UseDefaultInterface=true' in the iwd configuration, stopping iwd from recreating/destroying the -default- interfaces)

as for the steps to reproduce the issue, set up a default iwd installation with its service down at boot. start it up, then take it down. After that, the interfaces will be linked to the service status, whether it's up or down.

On August 3, 2025 11:47:20 PM GMT+01:00, drkhsh <me_AT_drkhsh.at> wrote:
>i cannot reproduce the problem here and i do not quite understand what
>your patch (with whitespace errors) should fix other than having the
>wrong interface configured.
>
>- drkhsh
>
>On Mon, Jul 28, 2025 at 05:24:11PM +0100, ryhpez wrote:
>> this patch fixes a problem with the 'ifindex' function (in 'components/wifi.c'). if the wireless interface was down when 'slstatus' started, it wouldn’t detect it even after bringing the interface up later.
>> I ran into this because I usually boot with all interfaces down and only enable them when needed. After updating to v1.1, I noticed the SSID never showed unless the interface was already up at launch.
>>
>> the issue is that the code caches the interface name in 'ifr' (a static 'struct ifreq' in 'ifindex') and skips calling 'ioctl(ifsock, SIOCGIFINDEX, &ifr)' after the first time because of this check:
>> `
>> if (strcmp(ifr.ifr_name, interface) != 0) {
>> strcpy(ifr.ifr_name, interface);
>> if (ioctl(ifsock, SIOCGIFINDEX, &ifr) != 0) {
>> warn("ioctl 'SIOCGIFINDEX':");
>> return -1;
>> }
>> }
>> `
>> since the interface name doesn’t change, it never retries 'ioctl' when the interface comes up later, the patch changes this to always call 'ioctl', this way, it detects the interface as soon as it’s available.
>>
>> let me know if you want this included in the mainbranch or if I just add it to the patches page in case the current behavior is intentional.
>> ---
>> components/wifi.c | 10 +++++-----
>> 1 file changed, 5 insertions(+), 5 deletions(-)
>>
>> diff --git a/components/wifi.c b/components/wifi.c
>> index 23af201..8639957 100644
>> --- a/components/wifi.c
>> +++ b/components/wifi.c
>> _AT__AT_ -108,12 +108,12 @@
>> warn("socket 'AF_UNIX':");
>> return -1;
>> }
>> - if (strcmp(ifr.ifr_name, interface) != 0) {
>> + if (strcmp(ifr.ifr_name, interface) != 0) {
>> strcpy(ifr.ifr_name, interface);
>> - if (ioctl(ifsock, SIOCGIFINDEX, &ifr) != 0) {
>> - warn("ioctl 'SIOCGIFINDEX':");
>> - return -1;
>> - }
>> + }
>> + if (ioctl(ifsock, SIOCGIFINDEX, &ifr) != 0) {
>> + warn("ioctl 'SIOCGIFINDEX':");
>> + return -1;
>> }
>> return ifr.ifr_ifindex;
>> }
>> --
>> 2.49.0
>>
>>
Received on Mon Aug 04 2025 - 23:06:47 CEST

This archive was generated by hypermail 2.3.0 : Mon Aug 04 2025 - 23:48:36 CEST