wifi(linux): skip nl80211 when no wireless devices are registered

Check /sys/class/ieee80211 before opening netlink sockets. Looking up
the
nl80211 family while cfg80211 is not loaded makes the kernel run
modprobe,
which loads the module on hosts without wireless hardware, or fails
again
on every poll when the module is unavailable.
This commit is contained in:
henrygd
2026-10-02 12:46:38 -04:00
parent 0cca9d0602
commit b115e2aa6a
3 changed files with 40 additions and 0 deletions

View File

@@ -7,6 +7,8 @@ import (
"context"
"errors"
"net"
"os"
"path/filepath"
"testing"
"time"
@@ -132,6 +134,22 @@ func TestLinuxInvalidSSID(t *testing.T) {
}
}
func TestHasWirelessDevice(t *testing.T) {
dir := t.TempDir()
if hasWirelessDevice(filepath.Join(dir, "missing")) {
t.Fatal("missing class directory")
}
if hasWirelessDevice(dir) {
t.Fatal("empty class directory")
}
if err := os.Mkdir(filepath.Join(dir, "phy0"), 0o755); err != nil {
t.Fatal(err)
}
if !hasWirelessDevice(dir) {
t.Fatal("registered device not detected")
}
}
func TestLinuxCancelled(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
cancel()