From 8e22d7137a9d46ce48ede098414b425c842e78b3 Mon Sep 17 00:00:00 2001 From: Arceliar Date: Sat, 5 Oct 2019 10:47:15 -0500 Subject: [PATCH] use bbr congestion control on linux, note that we're not doing anything intelligent with the errors right now if setting it fails --- src/yggdrasil/tcp_linux.go | 28 ++++++++++++++++++++++++++++ src/yggdrasil/tcp_other.go | 2 +- 2 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 src/yggdrasil/tcp_linux.go diff --git a/src/yggdrasil/tcp_linux.go b/src/yggdrasil/tcp_linux.go new file mode 100644 index 00000000..d957ceba --- /dev/null +++ b/src/yggdrasil/tcp_linux.go @@ -0,0 +1,28 @@ +// +build linux + +package yggdrasil + +import ( + "syscall" + + "golang.org/x/sys/unix" +) + +// WARNING: This context is used both by net.Dialer and net.Listen in tcp.go + +func (t *tcp) tcpContext(network, address string, c syscall.RawConn) error { + var control error + var bbr error + + control = c.Control(func(fd uintptr) { + // sys/socket.h: #define SO_RECV_ANYIF 0x1104 + bbr = unix.SetsockoptString(int(fd), unix.IPPROTO_TCP, unix.TCP_CONGESTION, "bbr") + }) + + switch { + case bbr != nil: + return bbr + default: + return control + } +} diff --git a/src/yggdrasil/tcp_other.go b/src/yggdrasil/tcp_other.go index 47bd772c..44c3d76d 100644 --- a/src/yggdrasil/tcp_other.go +++ b/src/yggdrasil/tcp_other.go @@ -1,4 +1,4 @@ -// +build !darwin +// +build !darwin,!linux package yggdrasil