Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 7c75d2b

Browse files
committedNov 24, 2024
Add UDP timeout route option
1 parent c18c7d8 commit 7c75d2b

File tree

13 files changed

+143
-223
lines changed

13 files changed

+143
-223
lines changed
 

‎adapter/inbound.go

+6-4
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,12 @@ type InboundContext struct {
7070
InboundOptions option.InboundOptions
7171
UDPDisableDomainUnmapping bool
7272
UDPConnect bool
73-
NetworkStrategy C.NetworkStrategy
74-
NetworkType []C.InterfaceType
75-
FallbackNetworkType []C.InterfaceType
76-
FallbackDelay time.Duration
73+
UDPTimeout time.Duration
74+
75+
NetworkStrategy C.NetworkStrategy
76+
NetworkType []C.InterfaceType
77+
FallbackNetworkType []C.InterfaceType
78+
FallbackDelay time.Duration
7779

7880
DNSServer string
7981

‎adapter/outbound/default.go

-157
This file was deleted.

‎constant/protocol.go

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const (
1010
ProtocolDTLS = "dtls"
1111
ProtocolSSH = "ssh"
1212
ProtocolRDP = "rdp"
13+
ProtocolNTP = "ntp"
1314
)
1415

1516
const (

‎constant/timeout.go

+15-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ const (
99
TCPTimeout = 15 * time.Second
1010
ReadPayloadTimeout = 300 * time.Millisecond
1111
DNSTimeout = 10 * time.Second
12-
QUICTimeout = 30 * time.Second
13-
STUNTimeout = 15 * time.Second
1412
UDPTimeout = 5 * time.Minute
1513
DefaultURLTestInterval = 3 * time.Minute
1614
DefaultURLTestIdleTimeout = 30 * time.Minute
@@ -19,3 +17,18 @@ const (
1917
FatalStopTimeout = 10 * time.Second
2018
FakeIPMetadataSaveInterval = 10 * time.Second
2119
)
20+
21+
var PortProtocols = map[uint16]string{
22+
53: ProtocolDNS,
23+
123: ProtocolNTP,
24+
3478: ProtocolSTUN,
25+
443: ProtocolQUIC,
26+
}
27+
28+
var ProtocolTimeouts = map[string]time.Duration{
29+
ProtocolDNS: 10 * time.Second,
30+
ProtocolNTP: 10 * time.Second,
31+
ProtocolSTUN: 10 * time.Second,
32+
ProtocolQUIC: 30 * time.Second,
33+
ProtocolDTLS: 30 * time.Second,
34+
}

‎docs/configuration/route/rule_action.md

+24-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ See `route-options` fields below.
4141
"network_strategy": "",
4242
"fallback_delay": "",
4343
"udp_disable_domain_unmapping": false,
44-
"udp_connect": false
44+
"udp_connect": false,
45+
"udp_timeout": ""
4546
}
4647
```
4748

@@ -86,6 +87,28 @@ do not support receiving UDP packets with domain addresses, such as Surge.
8687

8788
If enabled, attempts to connect UDP connection to the destination instead of listen.
8889

90+
#### udp_timeout
91+
92+
Timeout for UDP connections.
93+
94+
Setting a larger value than the UDP timeout in inbounds will have no effect.
95+
96+
Default value for protocol sniffed connections:
97+
98+
| Timeout | Protocol |
99+
|---------|----------------------|
100+
| `10s` | `dns`, `ntp`, `stun` |
101+
| `30s` | `quic`, `dtls` |
102+
103+
If no protocol is sniffed, the following ports will be recognized as protocols by default:
104+
105+
| Port | Protocol |
106+
|------|----------|
107+
| 53 | `dns` |
108+
| 123 | `ntp` |
109+
| 443 | `quic` |
110+
| 3478 | `stun` |
111+
89112
### reject
90113

91114
```json

‎docs/configuration/route/rule_action.zh.md

+24-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ icon: material/new-box
3737
"network_strategy": "",
3838
"fallback_delay": "",
3939
"udp_disable_domain_unmapping": false,
40-
"udp_connect": false
40+
"udp_connect": false,
41+
"udp_timeout": ""
4142
}
4243
```
4344

@@ -84,6 +85,28 @@ icon: material/new-box
8485

8586
如果启用,将尝试将 UDP 连接 connect 到目标而不是 listen。
8687

88+
#### udp_timeout
89+
90+
UDP 连接超时时间。
91+
92+
设置比入站 UDP 超时更大的值将无效。
93+
94+
已探测协议连接的默认值:
95+
96+
| 超时 | 协议 |
97+
|-------|----------------------|
98+
| `10s` | `dns`, `ntp`, `stun` |
99+
| `30s` | `quic`, `dtls` |
100+
101+
如果没有探测到协议,以下端口将默认识别为协议:
102+
103+
| 端口 | 协议 |
104+
|------|--------|
105+
| 53 | `dns` |
106+
| 123 | `ntp` |
107+
| 443 | `quic` |
108+
| 3478 | `stun` |
109+
87110
### reject
88111

89112
```json

‎option/rule_action.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,9 @@ type RawRouteOptionsActionOptions struct {
148148
NetworkStrategy NetworkStrategy `json:"network_strategy,omitempty"`
149149
FallbackDelay uint32 `json:"fallback_delay,omitempty"`
150150

151-
UDPDisableDomainUnmapping bool `json:"udp_disable_domain_unmapping,omitempty"`
152-
UDPConnect bool `json:"udp_connect,omitempty"`
151+
UDPDisableDomainUnmapping bool `json:"udp_disable_domain_unmapping,omitempty"`
152+
UDPConnect bool `json:"udp_connect,omitempty"`
153+
UDPTimeout badoption.Duration `json:"udp_timeout,omitempty"`
153154
}
154155

155156
type RouteOptionsActionOptions RawRouteOptionsActionOptions

‎option/wireguard.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ type WireGuardEndpointOptions struct {
1414
PrivateKey string `json:"private_key"`
1515
ListenPort uint16 `json:"listen_port,omitempty"`
1616
Peers []WireGuardPeer `json:"peers,omitempty"`
17-
UDPTimeout UDPTimeoutCompat `json:"udp_timeout,omitempty"`
17+
UDPTimeout badoption.Duration `json:"udp_timeout,omitempty"`
1818
Workers int `json:"workers,omitempty"`
1919
DialerOptions
2020
}

0 commit comments

Comments
 (0)
Please sign in to comment.