chore: limit tuicv5's maxUdpRelayPacketSize up to 1200-PacketOverHead

This commit is contained in:
gVisor bot 2023-09-21 23:49:45 +08:00
parent 73366050a4
commit 4cdb789918
4 changed files with 15 additions and 1 deletions

View file

@ -323,6 +323,10 @@ func NewTuic(option TuicOption) (*Tuic, error) {
t.client = tuic.NewPoolClientV4(clientOption) t.client = tuic.NewPoolClientV4(clientOption)
} else { } else {
maxUdpRelayPacketSize := option.MaxUdpRelayPacketSize
if maxUdpRelayPacketSize > tuic.MaxFragSizeV5 {
maxUdpRelayPacketSize = tuic.MaxFragSizeV5
}
clientOption := &tuic.ClientOptionV5{ clientOption := &tuic.ClientOptionV5{
TlsConfig: tlsConfig, TlsConfig: tlsConfig,
QuicConfig: quicConfig, QuicConfig: quicConfig,
@ -331,7 +335,7 @@ func NewTuic(option TuicOption) (*Tuic, error) {
UdpRelayMode: udpRelayMode, UdpRelayMode: udpRelayMode,
CongestionController: option.CongestionController, CongestionController: option.CongestionController,
ReduceRtt: option.ReduceRtt, ReduceRtt: option.ReduceRtt,
MaxUdpRelayPacketSize: option.MaxUdpRelayPacketSize, MaxUdpRelayPacketSize: maxUdpRelayPacketSize,
MaxOpenStreams: clientMaxOpenStreams, MaxOpenStreams: clientMaxOpenStreams,
CWND: option.CWND, CWND: option.CWND,
} }

View file

@ -223,6 +223,10 @@ func NewServer(option *ServerOption, pc net.PacketConn) (*Server, error) {
} }
} }
if len(option.Users) > 0 { if len(option.Users) > 0 {
maxUdpRelayPacketSize := option.MaxUdpRelayPacketSize
if maxUdpRelayPacketSize > MaxFragSizeV5 {
maxUdpRelayPacketSize = MaxFragSizeV5
}
server.optionV5 = &v5.ServerOption{ server.optionV5 = &v5.ServerOption{
HandleTcpFn: option.HandleTcpFn, HandleTcpFn: option.HandleTcpFn,
HandleUdpFn: option.HandleUdpFn, HandleUdpFn: option.HandleUdpFn,

View file

@ -30,6 +30,7 @@ const DefaultConnectionReceiveWindow = common.DefaultConnectionReceiveWindow
var GenTKN = v4.GenTKN var GenTKN = v4.GenTKN
var PacketOverHeadV4 = v4.PacketOverHead var PacketOverHeadV4 = v4.PacketOverHead
var PacketOverHeadV5 = v5.PacketOverHead var PacketOverHeadV5 = v5.PacketOverHead
var MaxFragSizeV5 = v5.MaxFragSize
type UdpRelayMode = common.UdpRelayMode type UdpRelayMode = common.UdpRelayMode

View file

@ -9,6 +9,11 @@ import (
"github.com/metacubex/quic-go" "github.com/metacubex/quic-go"
) )
// MaxFragSize is a safe udp relay packet size
// because tuicv5 support udp fragment so we unneeded to do a magic modify for quic-go to increase MaxDatagramFrameSize
// it may not work fine in some platform
var MaxFragSize = 1200 - PacketOverHead
func fragWriteNative(quicConn quic.Connection, packet Packet, buf *bytes.Buffer, fragSize int) (err error) { func fragWriteNative(quicConn quic.Connection, packet Packet, buf *bytes.Buffer, fragSize int) (err error) {
fullPayload := packet.DATA fullPayload := packet.DATA
off := 0 off := 0