Skip to content

Commit 5ba9663

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 5ba9663

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

conn/controlfns_linux.go

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

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

@@ -60,6 +88,17 @@ func init() {
6088

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

0 commit comments

Comments
 (0)