Skip to content

Commit c92064f

Browse files
committed
conn: don't enable GRO on Linux < 5.12
Kernels below 5.12 are missing this: commit 98184612aca0a9ee42b8eb0262a49900ee9eef0d Author: Norman Maurer <[email protected]> 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 <[email protected]> Reviewed-by: David Ahern <[email protected]> Signed-off-by: David S. Miller <[email protected]> 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 <[email protected]>
1 parent 264889f commit c92064f

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

conn/controlfns_linux.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,35 @@ import (
1313
"golang.org/x/sys/unix"
1414
)
1515

16+
// Taken from go/src/internal/syscall/unix/kernel_version_linux.go
17+
func kernelVersion() (major, minor int) {
18+
var uname unix.Utsname
19+
if err := unix.Uname(&uname); err != nil {
20+
return
21+
}
22+
23+
var (
24+
values [2]int
25+
value, vi int
26+
)
27+
for _, c := range uname.Release {
28+
if '0' <= c && c <= '9' {
29+
value = (value * 10) + int(c-'0')
30+
} else {
31+
// Note that we're assuming N.N.N here.
32+
// If we see anything else, we are likely to mis-parse it.
33+
values[vi] = value
34+
vi++
35+
if vi >= len(values) {
36+
break
37+
}
38+
value = 0
39+
}
40+
}
41+
42+
return values[0], values[1]
43+
}
44+
1645
func init() {
1746
controlFns = append(controlFns,
1847

@@ -60,6 +89,17 @@ func init() {
6089

6190
// Attempt to enable UDP_GRO
6291
func(network, address string, c syscall.RawConn) error {
92+
// Kernels below 5.12 are missing 98184612aca0 ("net:
93+
// udp: Add support for getsockopt(..., ..., UDP_GRO,
94+
// ..., ...);"), which means we can't read this back
95+
// later. We could pipe the return value through to
96+
// the rest of the code, but UDP_GRO is kind of buggy
97+
// anyway, so just gate this here.
98+
major, minor := kernelVersion()
99+
if major < 5 || (major == 5 && minor < 12) {
100+
return nil
101+
}
102+
63103
c.Control(func(fd uintptr) {
64104
_ = unix.SetsockoptInt(int(fd), unix.IPPROTO_UDP, unix.UDP_GRO, 1)
65105
})

0 commit comments

Comments
 (0)