From 2eff9c8277fbd4e5ad6cbe1a260b2f72872d78ed Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Tue, 20 Dec 2022 10:17:21 -0800 Subject: [PATCH] wgengine/magicsock: avoid ReadBatch/WriteBatch on old Linux kernels Fixes #6807 Change-Id: I161424ef8a7338e1941d5e43d72dc6529993a0e3 Signed-off-by: Brad Fitzpatrick --- wgengine/magicsock/magicsock.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/wgengine/magicsock/magicsock.go b/wgengine/magicsock/magicsock.go index 5c42867d3..415726d7c 100644 --- a/wgengine/magicsock/magicsock.go +++ b/wgengine/magicsock/magicsock.go @@ -37,6 +37,7 @@ import ( "tailscale.com/derp/derphttp" "tailscale.com/disco" "tailscale.com/health" + "tailscale.com/hostinfo" "tailscale.com/ipn/ipnstate" "tailscale.com/logtail/backoff" "tailscale.com/net/connstats" @@ -3208,6 +3209,14 @@ type RebindingUDPConn struct { func upgradePacketConn(p nettype.PacketConn, network string) nettype.PacketConn { uc, ok := p.(*net.UDPConn) if ok && runtime.GOOS == "linux" && (network == "udp4" || network == "udp6") { + // recvmmsg/sendmmsg were added in 2.6.33 but we support down to 2.6.32 + // for old NAS devices. See https://github.com/tailscale/tailscale/issues/6807. + // As a cheap heuristic: if the Linux kernel starts with "2", just consider + // it too old for the fast paths. Nobody who cares about performance runs such + // ancient kernels. + if strings.HasPrefix(hostinfo.GetOSVersion(), "2") { + return p + } // Non-Linux does not support batch operations. x/net will fall back to // recv/sendmsg, but not all platforms have recv/sendmsg support. Keep // this simple for now.