summaryrefslogtreecommitdiffhomepage
path: root/tun/netstack/tun.go
diff options
context:
space:
mode:
authorJordan Whited <jordan@tailscale.com>2023-03-09 11:06:01 -0800
committerJason A. Donenfeld <Jason@zx2c4.com>2023-03-10 14:52:39 +0100
commit5819c6af28239b973958a8d197f9e39926e7b9f1 (patch)
tree4796a021b130d99799bec6ed04e1cea712324092 /tun/netstack/tun.go
parent6901984f6aa6de37a7b3979134f8b29c81735861 (diff)
tun/netstack: enable TCP Selective Acknowledgements
Enable TCP SACK for the gVisor Stack used in tun/netstack. This can improve throughput by an order of magnitude in the presence of packet loss. Reviewed-by: James Tucker <james@tailscale.com> Signed-off-by: Jordan Whited <jordan@tailscale.com> Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'tun/netstack/tun.go')
-rw-r--r--tun/netstack/tun.go7
1 files changed, 6 insertions, 1 deletions
diff --git a/tun/netstack/tun.go b/tun/netstack/tun.go
index a0b212a..fa15f53 100644
--- a/tun/netstack/tun.go
+++ b/tun/netstack/tun.go
@@ -65,8 +65,13 @@ func CreateNetTUN(localAddresses, dnsServers []netip.Addr, mtu int) (tun.Device,
dnsServers: dnsServers,
mtu: mtu,
}
+ sackEnabledOpt := tcpip.TCPSACKEnabled(true) // TCP SACK is disabled by default
+ tcpipErr := dev.stack.SetTransportProtocolOption(tcp.ProtocolNumber, &sackEnabledOpt)
+ if tcpipErr != nil {
+ return nil, nil, fmt.Errorf("could not enable TCP SACK: %v", tcpipErr)
+ }
dev.ep.AddNotify(dev)
- tcpipErr := dev.stack.CreateNIC(1, dev.ep)
+ tcpipErr = dev.stack.CreateNIC(1, dev.ep)
if tcpipErr != nil {
return nil, nil, fmt.Errorf("CreateNIC: %v", tcpipErr)
}