aboutsummaryrefslogtreecommitdiffstats
path: root/pkg
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2020-11-28 14:51:12 +0100
committerDmitry Vyukov <dvyukov@google.com>2020-11-28 15:45:07 +0100
commit4325e66ebc806f5b00f3b7a895aba8dbd4f2d804 (patch)
treec378fef602468e97772a7eadde6e3b4c63100df2 /pkg
parent76b4dcc777ca842ee42225411c5c9d5ac3e91b8a (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')
-rw-r--r--pkg/host/features_linux.go47
-rw-r--r--pkg/host/syscalls_linux_test.go118
2 files changed, 165 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]+)`)
diff --git a/pkg/host/syscalls_linux_test.go b/pkg/host/syscalls_linux_test.go
index 5d4f60082..70adfbae9 100644
--- a/pkg/host/syscalls_linux_test.go
+++ b/pkg/host/syscalls_linux_test.go
@@ -6,6 +6,7 @@
package host
import (
+ "fmt"
"runtime"
"syscall"
"testing"
@@ -185,3 +186,120 @@ ffffffe0005c9c76 T __se_sys_listen
}
}
}
+
+func TestMatchKernelVersion(t *testing.T) {
+ tests := []struct {
+ version string
+ major int
+ minor int
+ res bool
+ bad bool
+ }{
+ {
+ version: "5.9.0-rc5-next-20200918",
+ major: 5,
+ minor: 8,
+ res: true,
+ },
+ {
+ version: "5.9.0-rc5-next-20200918",
+ major: 4,
+ minor: 10,
+ res: true,
+ },
+ {
+ version: "5.9.0-rc5-next-20200918",
+ major: 5,
+ minor: 9,
+ res: true,
+ },
+ {
+ version: "5.9.0-rc5-next-20200918",
+ major: 5,
+ minor: 10,
+ res: false,
+ },
+ {
+ version: "5.9.0-rc5-next-20200918",
+ major: 6,
+ minor: 0,
+ res: false,
+ },
+ {
+ version: "4.4.246-19567-g2c01e3dada31",
+ major: 4,
+ minor: 3,
+ res: true,
+ },
+ {
+ version: "4.4.246-19567-g2c01e3dada31",
+ major: 4,
+ minor: 4,
+ res: true,
+ },
+ {
+ version: "5.17.17-1debian-amd64",
+ major: 5,
+ minor: 16,
+ res: true,
+ },
+ {
+ version: "5.17.17-1debian-amd64",
+ major: 5,
+ minor: 17,
+ res: true,
+ },
+ {
+ version: "3.5",
+ major: 3,
+ minor: 4,
+ res: true,
+ },
+ {
+ version: "3.5",
+ major: 3,
+ minor: 5,
+ res: true,
+ },
+ {
+ version: "3.5",
+ major: 3,
+ minor: 6,
+ res: false,
+ },
+ {
+ version: "",
+ bad: true,
+ },
+ {
+ version: "something unparsable",
+ bad: true,
+ },
+ {
+ version: "mykernel 4.17-5",
+ bad: true,
+ },
+ {
+ version: "999999.999999",
+ bad: true,
+ },
+ {
+ version: "4.abc.def",
+ bad: true,
+ },
+ }
+ for i, test := range tests {
+ t.Run(fmt.Sprint(i), func(t *testing.T) {
+ ok, bad := matchKernelVersion(test.version, test.major, test.minor)
+ if test.bad && !bad {
+ t.Fatal("want error, but got no error")
+ }
+ if !test.bad && bad {
+ t.Fatalf("want no error, but got error")
+ }
+ if test.res != ok {
+ t.Fatalf("want match %v, but got %v", test.res, ok)
+ }
+ })
+ }
+}