@@ -7,13 +7,6 @@ import (
7
7
"golang.org/x/sys/unix"
8
8
)
9
9
10
- const (
11
- // For incoming connections.
12
- TCP_FASTOPEN = 23
13
- // For out-going connections.
14
- TCP_FASTOPEN_CONNECT = 30
15
- )
16
-
17
10
func bindAddr (fd uintptr , ip []byte , port uint32 ) error {
18
11
setReuseAddr (fd )
19
12
setReusePort (fd )
@@ -59,8 +52,8 @@ func applyOutboundSocketOptions(network string, address string, fd uintptr, conf
59
52
tfo = 1
60
53
}
61
54
if tfo >= 0 {
62
- if err := syscall .SetsockoptInt (int (fd ), syscall .SOL_TCP , TCP_FASTOPEN_CONNECT , tfo ); err != nil {
63
- return newError ("failed to set TCP_FASTOPEN_CONNECT= " , tfo ).Base (err )
55
+ if err := syscall .SetsockoptInt (int (fd ), syscall .SOL_TCP , unix . TCP_FASTOPEN_CONNECT , tfo ); err != nil {
56
+ return newError ("failed to set TCP_FASTOPEN_CONNECT" , tfo ).Base (err )
64
57
}
65
58
}
66
59
@@ -95,6 +88,12 @@ func applyOutboundSocketOptions(network string, address string, fd uintptr, conf
95
88
return newError ("failed to set TCP_WINDOW_CLAMP" , err )
96
89
}
97
90
}
91
+
92
+ if config .TcpUserTimeout > 0 {
93
+ if err := syscall .SetsockoptInt (int (fd ), syscall .IPPROTO_TCP , unix .TCP_USER_TIMEOUT , int (config .TcpUserTimeout )); err != nil {
94
+ return newError ("failed to set TCP_USER_TIMEOUT" , err )
95
+ }
96
+ }
98
97
}
99
98
100
99
if config .Tproxy .IsEnabled () {
@@ -115,8 +114,8 @@ func applyInboundSocketOptions(network string, fd uintptr, config *SocketConfig)
115
114
if isTCPSocket (network ) {
116
115
tfo := config .ParseTFOValue ()
117
116
if tfo >= 0 {
118
- if err := syscall .SetsockoptInt (int (fd ), syscall .SOL_TCP , TCP_FASTOPEN , tfo ); err != nil {
119
- return newError ("failed to set TCP_FASTOPEN= " , tfo ).Base (err )
117
+ if err := syscall .SetsockoptInt (int (fd ), syscall .SOL_TCP , unix . TCP_FASTOPEN , tfo ); err != nil {
118
+ return newError ("failed to set TCP_FASTOPEN" , tfo ).Base (err )
120
119
}
121
120
}
122
121
@@ -151,6 +150,12 @@ func applyInboundSocketOptions(network string, fd uintptr, config *SocketConfig)
151
150
return newError ("failed to set TCP_WINDOW_CLAMP" , err )
152
151
}
153
152
}
153
+
154
+ if config .TcpUserTimeout > 0 {
155
+ if err := syscall .SetsockoptInt (int (fd ), syscall .IPPROTO_TCP , unix .TCP_USER_TIMEOUT , int (config .TcpUserTimeout )); err != nil {
156
+ return newError ("failed to set TCP_USER_TIMEOUT" , err )
157
+ }
158
+ }
154
159
}
155
160
156
161
if config .Tproxy .IsEnabled () {
0 commit comments