diff options
| author | Dmitry Vyukov <dvyukov@google.com> | 2020-11-28 14:51:12 +0100 |
|---|---|---|
| committer | Dmitry Vyukov <dvyukov@google.com> | 2020-11-28 15:45:07 +0100 |
| commit | 4325e66ebc806f5b00f3b7a895aba8dbd4f2d804 (patch) | |
| tree | c378fef602468e97772a7eadde6e3b4c63100df2 /pkg/host/features_linux.go | |
| parent | 76b4dcc777ca842ee42225411c5c9d5ac3e91b8a (diff) | |
pkg/host: make wifi check more precise
WiFi setup fails on 4.4 kernel with:
2020/11/28 12:22:49 BUG: program execution failed: executor 0: exit status 67
initialize_wifi_devices: failed to create device #0 (errno 19)
There is at least HWSIM_ATTR_PERM_ADDR not support, but maybe something else.
The setup seems to work at least on 4.17 where HWSIM_ATTR_PERM_ADDR was added.
So require at least 4.17 for WiFi testing.
Diffstat (limited to 'pkg/host/features_linux.go')
| -rw-r--r-- | pkg/host/features_linux.go | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/pkg/host/features_linux.go b/pkg/host/features_linux.go index 5a91fc8ea..f3c358c2c 100644 --- a/pkg/host/features_linux.go +++ b/pkg/host/features_linux.go @@ -5,7 +5,9 @@ package host import ( "fmt" + "regexp" "runtime" + "strconv" "syscall" "unsafe" @@ -225,5 +227,50 @@ func checkWifiEmulation() string { if err := osutil.IsAccessible("/sys/class/mac80211_hwsim/"); err != nil { return err.Error() } + // We use HWSIM_ATTR_PERM_ADDR which was added in 4.17. + return requireKernel(4, 17) +} + +func requireKernel(x, y int) string { + info := new(syscall.Utsname) + if err := syscall.Uname(info); err != nil { + return fmt.Sprintf("uname failed: %v", err) + } + var ver []byte + for _, b := range info.Release { + if b == 0 { + break + } + ver = append(ver, byte(b)) + } + if ok, bad := matchKernelVersion(string(ver), x, y); bad { + return fmt.Sprintf("failed to parse kernel version (%v)", ver) + } else if !ok { + return fmt.Sprintf("kernel %v.%v required (have %s)", x, y, ver) + } return "" } + +func matchKernelVersion(ver string, x, y int) (bool, bool) { + match := kernelVersionRe.FindStringSubmatch(ver) + if match == nil { + return false, true + } + major, err := strconv.Atoi(match[1]) + if err != nil { + return false, true + } + if major <= 0 || major > 999 { + return false, true + } + minor, err := strconv.Atoi(match[2]) + if err != nil { + return false, true + } + if minor <= 0 || minor > 999 { + return false, true + } + return major*1000+minor >= x*1000+y, false +} + +var kernelVersionRe = regexp.MustCompile(`^([0-9]+)\.([0-9]+)`) |
