feat(wireguard): WIREGUARD_GSO option to disable TUN vnet hdr batching (#3424)

This commit is contained in:
Tyler MacDonald
2026-08-04 21:31:22 -04:00
committed by GitHub
parent 297d6480d0
commit 0186f2ff4a
20 changed files with 260 additions and 11 deletions
+26 -2
View File
@@ -1,6 +1,10 @@
package wireguard
import (
"fmt"
"strings"
"sync"
"golang.zx2c4.com/wireguard/device"
)
@@ -10,6 +14,7 @@ type Logger interface {
Debug(s string)
Debugf(format string, args ...interface{})
Info(s string)
Warn(s string)
Error(s string)
Erroer
}
@@ -18,9 +23,28 @@ type Erroer interface {
Errorf(format string, args ...any)
}
func makeDeviceLogger(logger Logger) (deviceLogger *device.Logger) {
func makeDeviceLogger(logger Logger, gso bool) (deviceLogger *device.Logger) {
errorf := logger.Errorf
if gso {
// Kernels advertising IFF_VNET_HDR support but rejecting
// GRO-coalesced writes make wireguard-go log this error for
// each failed write batch, see
// https://github.com/tailscale/tailscale/issues/13041
var suggestOnce sync.Once
errorf = func(format string, args ...any) {
logger.Errorf(format, args...)
message := fmt.Sprintf(format, args...)
if strings.Contains(message, "Failed to write packets to TUN device") &&
strings.Contains(message, "invalid argument") {
suggestOnce.Do(func() {
logger.Warn("The kernel seems to reject GRO-coalesced writes to " +
"the TUN device; consider setting WIREGUARD_GSO=off")
})
}
}
}
return &device.Logger{
Verbosef: logger.Debugf,
Errorf: logger.Errorf,
Errorf: errorf,
}
}