From 8cf23f1947bebba5a3240ecf925bd3909e342dc4 Mon Sep 17 00:00:00 2001 From: xqzr <34030394+xqzr@users.noreply.github.com> Date: Tue, 11 Oct 2022 01:13:50 +0800 Subject: [PATCH] add `tcpcongestion` (#1234) * add `tcpcongestion` * Update sockopt_linux.go * Update config.pb.go * Update transport_internet.go * Update config.pb.go * Update transport_internet.go * Update config.proto --- infra/conf/transport_internet.go | 2 ++ transport/internet/config.pb.go | 1 + transport/internet/config.proto | 2 ++ transport/internet/sockopt_linux.go | 12 ++++++++++++ 4 files changed, 17 insertions(+) diff --git a/infra/conf/transport_internet.go b/infra/conf/transport_internet.go index 30626a35..efbe4075 100644 --- a/infra/conf/transport_internet.go +++ b/infra/conf/transport_internet.go @@ -533,6 +533,7 @@ type SocketConfig struct { DialerProxy string `json:"dialerProxy"` TCPKeepAliveInterval int32 `json:"tcpKeepAliveInterval"` TCPKeepAliveIdle int32 `json:"tcpKeepAliveIdle"` + TCPCongestion string `json:"tcpCongestion"` } // Build implements Buildable. @@ -581,6 +582,7 @@ func (c *SocketConfig) Build() (*internet.SocketConfig, error) { DialerProxy: c.DialerProxy, TcpKeepAliveInterval: c.TCPKeepAliveInterval, TcpKeepAliveIdle: c.TCPKeepAliveIdle, + TcpCongestion: c.TCPCongestion, }, nil } diff --git a/transport/internet/config.pb.go b/transport/internet/config.pb.go index b9c0b2fa..3e31bf75 100644 --- a/transport/internet/config.pb.go +++ b/transport/internet/config.pb.go @@ -424,6 +424,7 @@ type SocketConfig struct { DialerProxy string `protobuf:"bytes,9,opt,name=dialer_proxy,json=dialerProxy,proto3" json:"dialer_proxy,omitempty"` TcpKeepAliveInterval int32 `protobuf:"varint,10,opt,name=tcp_keep_alive_interval,json=tcpKeepAliveInterval,proto3" json:"tcp_keep_alive_interval,omitempty"` TcpKeepAliveIdle int32 `protobuf:"varint,11,opt,name=tcp_keep_alive_idle,json=tcpKeepAliveIdle,proto3" json:"tcp_keep_alive_idle,omitempty"` + TcpCongestion string `protobuf:"bytes,12,opt,name=tcp_congestion,json=tcpCongestion,proto3 json:"tcp_congestion,omitempty"` } func (x *SocketConfig) Reset() { diff --git a/transport/internet/config.proto b/transport/internet/config.proto index 92f70a8b..8b81302f 100644 --- a/transport/internet/config.proto +++ b/transport/internet/config.proto @@ -96,4 +96,6 @@ message SocketConfig { int32 tcp_keep_alive_interval = 10; int32 tcp_keep_alive_idle = 11; + + string tcp_congestion = 12; } diff --git a/transport/internet/sockopt_linux.go b/transport/internet/sockopt_linux.go index f82970d9..a5a83298 100644 --- a/transport/internet/sockopt_linux.go +++ b/transport/internet/sockopt_linux.go @@ -77,6 +77,12 @@ func applyOutboundSocketOptions(network string, address string, fd uintptr, conf return newError("failed to unset SO_KEEPALIVE", err) } } + + if config.TcpCongestion != "" { + if err := syscall.SetsockoptString(int(fd), syscall.SOL_TCP, syscall.TCP_CONGESTION, config.TcpCongestion); err != nil { + return newError("failed to set TCP_CONGESTION", err) + } + } } if config.Tproxy.IsEnabled() { @@ -121,6 +127,12 @@ func applyInboundSocketOptions(network string, fd uintptr, config *SocketConfig) return newError("failed to unset SO_KEEPALIVE", err) } } + + if config.TcpCongestion != "" { + if err := syscall.SetsockoptString(int(fd), syscall.SOL_TCP, syscall.TCP_CONGESTION, config.TcpCongestion); err != nil { + return newError("failed to set TCP_CONGESTION", err) + } + } } if config.Tproxy.IsEnabled() {