From 8e22d7137a9d46ce48ede098414b425c842e78b3 Mon Sep 17 00:00:00 2001 From: Arceliar Date: Sat, 5 Oct 2019 10:47:15 -0500 Subject: [PATCH 1/4] 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 From fb3430207c686fa71e903e70dba36ae278b7331d Mon Sep 17 00:00:00 2001 From: Arceliar Date: Sat, 5 Oct 2019 11:03:38 -0500 Subject: [PATCH 2/4] don't fail if there's an error setting bbr, just log it and continue --- src/yggdrasil/tcp_linux.go | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/yggdrasil/tcp_linux.go b/src/yggdrasil/tcp_linux.go index d957ceba..90a55d7e 100644 --- a/src/yggdrasil/tcp_linux.go +++ b/src/yggdrasil/tcp_linux.go @@ -19,10 +19,14 @@ func (t *tcp) tcpContext(network, address string, c syscall.RawConn) error { bbr = unix.SetsockoptString(int(fd), unix.IPPROTO_TCP, unix.TCP_CONGESTION, "bbr") }) - switch { - case bbr != nil: - return bbr - default: - return control + // Log any errors + if bbr != nil { + t.link.core.log.Debugln("Failed to set tcp_congestion_control to bbr for socket, SetsockoptString error:", bbr) } + if control != nil { + t.link.core.log.Debugln("Failed to set tcp_congestion_control to bbr for socket, Control error:", control) + } + + // Return nil because errors here are not considered fatal for the connection, it just means congestion control is suboptimal + return nil } From b519802fcb5959983932376309f8f2000b84489d Mon Sep 17 00:00:00 2001 From: Arceliar Date: Sat, 5 Oct 2019 12:16:22 -0500 Subject: [PATCH 3/4] update phony dependency --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index d86101bf..185a9e3d 100644 --- a/go.mod +++ b/go.mod @@ -1,7 +1,7 @@ module github.com/yggdrasil-network/yggdrasil-go require ( - github.com/Arceliar/phony v0.0.0-20190907031509-af5bdbeecab6 + github.com/Arceliar/phony v0.0.0-20191004004458-c7ba8368bafa github.com/gologme/log v0.0.0-20181207131047-4e5d8ccb38e8 github.com/hashicorp/go-syslog v1.0.0 github.com/hjson/hjson-go v3.0.1-0.20190209023717-9147687966d9+incompatible diff --git a/go.sum b/go.sum index cdabc402..8a2b52f3 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,5 @@ -github.com/Arceliar/phony v0.0.0-20190907031509-af5bdbeecab6 h1:zMj5Q1V0yF4WNfV/FpXG6iXfPJ965Xc5asR2vHXanXc= -github.com/Arceliar/phony v0.0.0-20190907031509-af5bdbeecab6/go.mod h1:6Lkn+/zJilRMsKmbmG1RPoamiArC6HS73xbwRyp3UyI= +github.com/Arceliar/phony v0.0.0-20191004004458-c7ba8368bafa h1:bFoWgQ17NKP4FBB2Tnt1QZ8fZqrxLYORIlHUa5ioDjc= +github.com/Arceliar/phony v0.0.0-20191004004458-c7ba8368bafa/go.mod h1:6Lkn+/zJilRMsKmbmG1RPoamiArC6HS73xbwRyp3UyI= github.com/gologme/log v0.0.0-20181207131047-4e5d8ccb38e8 h1:WD8iJ37bRNwvETMfVTusVSAi0WdXTpfNVGY2aHycNKY= github.com/gologme/log v0.0.0-20181207131047-4e5d8ccb38e8/go.mod h1:gq31gQ8wEHkR+WekdWsqDuf8pXTUZA9BnnzTuPz1Y9U= github.com/hashicorp/go-syslog v1.0.0 h1:KaodqZuhUoZereWVIYmpUgZysurB1kBLX2j0MwMrUAE= From f474869ad9ab094fcd625d6c6ee3634bbc07bc52 Mon Sep 17 00:00:00 2001 From: Arceliar Date: Sat, 5 Oct 2019 12:17:40 -0500 Subject: [PATCH 4/4] cleanup bad comment --- src/yggdrasil/tcp_linux.go | 1 - 1 file changed, 1 deletion(-) diff --git a/src/yggdrasil/tcp_linux.go b/src/yggdrasil/tcp_linux.go index 90a55d7e..7eda3b5e 100644 --- a/src/yggdrasil/tcp_linux.go +++ b/src/yggdrasil/tcp_linux.go @@ -15,7 +15,6 @@ func (t *tcp) tcpContext(network, address string, c syscall.RawConn) 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") })