Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: custom TCP Fast Open queue length #1293

Merged
merged 2 commits into from Sep 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions infra/conf/transport_internet.go
Expand Up @@ -387,6 +387,7 @@ func (p TransportProtocol) Build() (string, error) {
type SocketConfig struct {
Mark uint32 `json:"mark"`
TFO *bool `json:"tcpFastOpen"`
TFOQueueLength uint32 `json:"tcpFastOpenQueueLength"`
TProxy string `json:"tproxy"`
AcceptProxyProtocol bool `json:"acceptProxyProtocol"`
TCPKeepAliveInterval int32 `json:"tcpKeepAliveInterval"`
Expand All @@ -402,6 +403,12 @@ func (c *SocketConfig) Build() (*internet.SocketConfig, error) {
tfoSettings = internet.SocketConfig_Disable
}
}

tfoQueueLength := c.TFOQueueLength
if tfoQueueLength == 0 {
tfoQueueLength = 4096
}

var tproxy internet.SocketConfig_TProxyMode
switch strings.ToLower(c.TProxy) {
case "tproxy":
Expand All @@ -415,6 +422,7 @@ func (c *SocketConfig) Build() (*internet.SocketConfig, error) {
return &internet.SocketConfig{
Mark: c.Mark,
Tfo: tfoSettings,
TfoQueueLength: tfoQueueLength,
Tproxy: tproxy,
AcceptProxyProtocol: c.AcceptProxyProtocol,
TcpKeepAliveInterval: c.TCPKeepAliveInterval,
Expand Down
8 changes: 5 additions & 3 deletions infra/conf/transport_test.go
Expand Up @@ -35,12 +35,14 @@ func TestSocketConfig(t *testing.T) {
{
Input: `{
"mark": 1,
"tcpFastOpen": true
"tcpFastOpen": true,
"tcpFastOpenQueueLength": 1024
}`,
Parser: createParser(),
Output: &internet.SocketConfig{
Mark: 1,
Tfo: internet.SocketConfig_Enable,
Mark: 1,
Tfo: internet.SocketConfig_Enable,
TfoQueueLength: 1024,
},
},
})
Expand Down
58 changes: 34 additions & 24 deletions transport/internet/config.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions transport/internet/config.proto
Expand Up @@ -93,4 +93,6 @@ message SocketConfig {
bool accept_proxy_protocol = 7;

int32 tcp_keep_alive_interval = 8;

uint32 tfo_queue_length = 9;
}
4 changes: 2 additions & 2 deletions transport/internet/sockopt_linux.go
Expand Up @@ -84,8 +84,8 @@ func applyInboundSocketOptions(network string, fd uintptr, config *SocketConfig)
if isTCPSocket(network) {
switch config.Tfo {
case SocketConfig_Enable:
if err := syscall.SetsockoptInt(int(fd), syscall.SOL_TCP, TCP_FASTOPEN, 1); err != nil {
return newError("failed to set TCP_FASTOPEN=1").Base(err)
if err := syscall.SetsockoptInt(int(fd), syscall.SOL_TCP, TCP_FASTOPEN, int(config.TfoQueueLength)); err != nil {
return newError("failed to set TCP_FASTOPEN=", config.TfoQueueLength).Base(err)
}
case SocketConfig_Disable:
if err := syscall.SetsockoptInt(int(fd), syscall.SOL_TCP, TCP_FASTOPEN, 0); err != nil {
Expand Down