Skip to content

Commit

Permalink
🪚 service: add option to allow IP fragmentation
Browse files Browse the repository at this point in the history
  • Loading branch information
database64128 committed Dec 3, 2024
1 parent 7e18187 commit cb963b3
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 6 deletions.
15 changes: 12 additions & 3 deletions docs/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@
"relayBatchSize": 0,
"serverRecvBatchSize": 0,
"sendChannelCapacity": 0,
"natTimeout": "180s"
"natTimeout": "180s",
"allowFragmentation": false
},
{
"network": "udp4",
Expand All @@ -121,7 +122,8 @@
"relayBatchSize": 0,
"serverRecvBatchSize": 0,
"sendChannelCapacity": 0,
"natTimeout": "180s"
"natTimeout": "180s",
"allowFragmentation": false
},
{
"network": "udp6",
Expand All @@ -133,7 +135,8 @@
"relayBatchSize": 0,
"serverRecvBatchSize": 0,
"sendChannelCapacity": 0,
"natTimeout": "180s"
"natTimeout": "180s",
"allowFragmentation": false
}
],
"mtu": 1500
Expand Down Expand Up @@ -287,6 +290,7 @@
"multipathTCP": false,
"allowSegmentedFixedLengthHeader": false,
"enableUDP": true,
"allowFragmentation": false,
"mtu": 1500,
"psk": "oE/s2z9Q8EWORAB8B3UCxw==",
"iPSKs": [
Expand All @@ -308,6 +312,7 @@
"multipathTCP": false,
"allowSegmentedFixedLengthHeader": false,
"enableUDP": true,
"allowFragmentation": false,
"mtu": 1500,
"psk": "QzhDwx0lKZ+0Sustgwtjtw==",
"iPSKs": [
Expand All @@ -325,6 +330,7 @@
"enableTCP": true,
"multipathTCP": false,
"enableUDP": true,
"allowFragmentation": false,
"mtu": 1500,
"socks5": {
"username": "username",
Expand Down Expand Up @@ -364,6 +370,7 @@
"tcpFastOpenFallback": false,
"multipathTCP": false,
"enableUDP": true,
"allowFragmentation": false,
"mtu": 1500
},
{
Expand All @@ -377,6 +384,7 @@
"tcpFastOpenFallback": false,
"multipathTCP": false,
"enableUDP": true,
"allowFragmentation": false,
"mtu": 1500
},
{
Expand All @@ -390,6 +398,7 @@
"tcpFastOpenFallback": false,
"multipathTCP": false,
"enableUDP": true,
"allowFragmentation": false,
"mtu": 1500
}
],
Expand Down
13 changes: 11 additions & 2 deletions service/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,16 @@ type ClientConfig struct {
// UDP

EnableUDP bool `json:"enableUDP"`
MTU int `json:"mtu"`

// AllowFragmentation controls whether to allow fragmented UDP packets.
//
// IP fragmentation does not reliably work over the Internet.
// Sending fragmented packets will significantly reduce throughput.
// Do not enable this option unless it is absolutely necessary.
AllowFragmentation bool `json:"allowFragmentation"`

// MTU is the MTU of the client's designated network path.
MTU int `json:"mtu"`

// Socks5 is the protocol-specific configuration for "socks5".
Socks5 Socks5ClientConfig `json:"socks5"`
Expand Down Expand Up @@ -308,7 +317,7 @@ func (cc *ClientConfig) UDPClient() (zerocopy.UDPClient, error) {
ReceiveBufferSize: conn.DefaultUDPSocketBufferSize,
Fwmark: cc.DialerFwmark,
TrafficClass: cc.DialerTrafficClass,
PathMTUDiscovery: true,
PathMTUDiscovery: !cc.AllowFragmentation,
})

switch cc.Protocol {
Expand Down
9 changes: 8 additions & 1 deletion service/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,13 @@ type UDPListenerConfig struct {
//
// The default value is 5 minutes.
NATTimeout jsonhelper.Duration `json:"natTimeout"`

// AllowFragmentation controls whether to allow IP fragmentation.
//
// IP fragmentation does not reliably work over the Internet.
// Sending fragmented packets will significantly reduce throughput.
// Do not enable this option unless it is absolutely necessary.
AllowFragmentation bool `json:"allowFragmentation"`
}

// Configure returns a UDP server socket configuration.
Expand Down Expand Up @@ -196,7 +203,7 @@ func (lnc *UDPListenerConfig) Configure(listenConfigCache conn.ListenConfigCache
TrafficClass: lnc.TrafficClass,
ReusePort: lnc.ReusePort,
Transparent: transparent,
PathMTUDiscovery: true,
PathMTUDiscovery: !lnc.AllowFragmentation,
ReceivePacketInfo: true,
}),
network: lnc.Network,
Expand Down

0 comments on commit cb963b3

Please sign in to comment.