aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2025-05-22 01:33:55 +0200
committerJason A. Donenfeld <Jason@zx2c4.com>2025-05-22 01:43:39 +0200
commitc92064f1ce35f82bf0c5a183b54e51fd5d58ad50 (patch)
treee0f56c257ab3d95bf9ac833cf8c616633985f527
parentdevice: optimize message encoding (diff)
downloadwireguard-go-c92064f1ce35f82bf0c5a183b54e51fd5d58ad50.tar.xz
wireguard-go-c92064f1ce35f82bf0c5a183b54e51fd5d58ad50.zip
conn: don't enable GRO on Linux < 5.12
Kernels below 5.12 are missing this: commit 98184612aca0a9ee42b8eb0262a49900ee9eef0d Author: Norman Maurer <norman_maurer@apple.com> Date: Thu Apr 1 08:59:17 2021 net: udp: Add support for getsockopt(..., ..., UDP_GRO, ..., ...); Support for UDP_GRO was added in the past but the implementation for getsockopt was missed which did lead to an error when we tried to retrieve the setting for UDP_GRO. This patch adds the missing switch case for UDP_GRO Fixes: e20cf8d3f1f7 ("udp: implement GRO for plain UDP sockets.") Signed-off-by: Norman Maurer <norman_maurer@apple.com> Reviewed-by: David Ahern <dsahern@kernel.org> Signed-off-by: David S. Miller <davem@davemloft.net> That means we can't set the option and then read it back later. Given how buggy UDP_GRO is in general on odd kernels, just disable it on older kernels all together. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
-rw-r--r--conn/controlfns_linux.go40
1 files changed, 40 insertions, 0 deletions
diff --git a/conn/controlfns_linux.go b/conn/controlfns_linux.go
index 3447349..f0deefa 100644
--- a/conn/controlfns_linux.go
+++ b/conn/controlfns_linux.go
@@ -13,6 +13,35 @@ import (
"golang.org/x/sys/unix"
)
+// Taken from go/src/internal/syscall/unix/kernel_version_linux.go
+func kernelVersion() (major, minor int) {
+ var uname unix.Utsname
+ if err := unix.Uname(&uname); err != nil {
+ return
+ }
+
+ var (
+ values [2]int
+ value, vi int
+ )
+ for _, c := range uname.Release {
+ if '0' <= c && c <= '9' {
+ value = (value * 10) + int(c-'0')
+ } else {
+ // Note that we're assuming N.N.N here.
+ // If we see anything else, we are likely to mis-parse it.
+ values[vi] = value
+ vi++
+ if vi >= len(values) {
+ break
+ }
+ value = 0
+ }
+ }
+
+ return values[0], values[1]
+}
+
func init() {
controlFns = append(controlFns,
@@ -60,6 +89,17 @@ func init() {
// Attempt to enable UDP_GRO
func(network, address string, c syscall.RawConn) error {
+ // Kernels below 5.12 are missing 98184612aca0 ("net:
+ // udp: Add support for getsockopt(..., ..., UDP_GRO,
+ // ..., ...);"), which means we can't read this back
+ // later. We could pipe the return value through to
+ // the rest of the code, but UDP_GRO is kind of buggy
+ // anyway, so just gate this here.
+ major, minor := kernelVersion()
+ if major < 5 || (major == 5 && minor < 12) {
+ return nil
+ }
+
c.Control(func(fd uintptr) {
_ = unix.SetsockoptInt(int(fd), unix.IPPROTO_UDP, unix.UDP_GRO, 1)
})