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

Add tcpKeepAliveInterval in transport sockopt #754

Merged
merged 6 commits into from Oct 12, 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
15 changes: 9 additions & 6 deletions infra/conf/transport_internet.go
Expand Up @@ -489,6 +489,8 @@ type SocketConfig struct {
AcceptProxyProtocol bool `json:"acceptProxyProtocol"`
DomainStrategy string `json:"domainStrategy"`
DialerProxy string `json:"dialerProxy"`

TCPKeepAliveInterval int32 `json:"tcpKeepAliveInterval"`
}

// Build implements Buildable.
Expand Down Expand Up @@ -529,12 +531,13 @@ func (c *SocketConfig) Build() (*internet.SocketConfig, error) {
}

return &internet.SocketConfig{
Mark: c.Mark,
Tfo: tfo,
Tproxy: tproxy,
DomainStrategy: dStrategy,
AcceptProxyProtocol: c.AcceptProxyProtocol,
DialerProxy: c.DialerProxy,
Mark: c.Mark,
Tfo: tfo,
Tproxy: tproxy,
DomainStrategy: dStrategy,
AcceptProxyProtocol: c.AcceptProxyProtocol,
DialerProxy: c.DialerProxy,
TcpKeepAliveInterval: c.TCPKeepAliveInterval,
}, nil
}

Expand Down
56 changes: 34 additions & 22 deletions transport/internet/config.pb.go

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

3 changes: 3 additions & 0 deletions transport/internet/config.proto
Expand Up @@ -90,5 +90,8 @@ message SocketConfig {
bool accept_proxy_protocol = 7;

DomainStrategy domain_strategy = 8;

string dialer_proxy = 9;

int32 tcp_keep_alive_interval = 10;
}
12 changes: 12 additions & 0 deletions transport/internet/sockopt_linux.go
Expand Up @@ -57,6 +57,12 @@ func applyOutboundSocketOptions(network string, address string, fd uintptr, conf
return newError("failed to set TCP_FASTOPEN_CONNECT=", tfo).Base(err)
}
}

if config.TcpKeepAliveInterval != 0 {
if err := syscall.SetsockoptInt(int(fd), syscall.IPPROTO_TCP, syscall.TCP_KEEPINTVL, int(config.TcpKeepAliveInterval)); err != nil {
return newError("failed to set TCP_KEEPINTVL", err)
}
}
}

if config.Tproxy.IsEnabled() {
Expand All @@ -81,6 +87,12 @@ func applyInboundSocketOptions(network string, fd uintptr, config *SocketConfig)
return newError("failed to set TCP_FASTOPEN=", tfo).Base(err)
}
}

if config.TcpKeepAliveInterval != 0 {
if err := syscall.SetsockoptInt(int(fd), syscall.IPPROTO_TCP, syscall.TCP_KEEPINTVL, int(config.TcpKeepAliveInterval)); err != nil {
return newError("failed to set TCP_KEEPINTVL", err)
}
}
}

if config.Tproxy.IsEnabled() {
Expand Down