From 168253b8519572fc583de382603f11103b4f333a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=96=E7=95=8C?= Date: Thu, 19 Jan 2023 10:35:26 +0800 Subject: [PATCH] Fix inbound default DF --- inbound/default_udp.go | 8 +++++++- inbound/direct.go | 1 + inbound/hysteria.go | 1 + option/inbound.go | 3 ++- 4 files changed, 11 insertions(+), 2 deletions(-) diff --git a/inbound/default_udp.go b/inbound/default_udp.go index 55a8462d..90cd7b19 100644 --- a/inbound/default_udp.go +++ b/inbound/default_udp.go @@ -18,7 +18,13 @@ import ( func (a *myInboundAdapter) ListenUDP() (net.PacketConn, error) { bindAddr := M.SocksaddrFrom(netip.Addr(a.listenOptions.Listen), a.listenOptions.ListenPort) var lc net.ListenConfig - if !a.listenOptions.UDPFragment { + var udpFragment bool + if a.listenOptions.UDPFragment != nil { + udpFragment = *a.listenOptions.UDPFragment + } else { + udpFragment = a.listenOptions.UDPFragmentDefault + } + if !udpFragment { lc.Control = control.Append(lc.Control, control.DisableUDPFragment()) } udpConn, err := lc.ListenPacket(a.ctx, M.NetworkFromNetAddr(N.NetworkUDP, bindAddr.Addr), bindAddr.String()) diff --git a/inbound/direct.go b/inbound/direct.go index aefcafaf..08d0726a 100644 --- a/inbound/direct.go +++ b/inbound/direct.go @@ -25,6 +25,7 @@ type Direct struct { } func NewDirect(ctx context.Context, router adapter.Router, logger log.ContextLogger, tag string, options option.DirectInboundOptions) *Direct { + options.UDPFragmentDefault = true inbound := &Direct{ myInboundAdapter: myInboundAdapter{ protocol: C.TypeDirect, diff --git a/inbound/hysteria.go b/inbound/hysteria.go index 557f7b45..363f92d7 100644 --- a/inbound/hysteria.go +++ b/inbound/hysteria.go @@ -43,6 +43,7 @@ type Hysteria struct { } func NewHysteria(ctx context.Context, router adapter.Router, logger log.ContextLogger, tag string, options option.HysteriaInboundOptions) (*Hysteria, error) { + options.UDPFragmentDefault = true quicConfig := &quic.Config{ InitialStreamReceiveWindow: options.ReceiveWindowConn, MaxStreamReceiveWindow: options.ReceiveWindowConn, diff --git a/option/inbound.go b/option/inbound.go index e717c7ba..89e580e7 100644 --- a/option/inbound.go +++ b/option/inbound.go @@ -115,7 +115,8 @@ type ListenOptions struct { Listen ListenAddress `json:"listen"` ListenPort uint16 `json:"listen_port,omitempty"` TCPFastOpen bool `json:"tcp_fast_open,omitempty"` - UDPFragment bool `json:"udp_fragment,omitempty"` + UDPFragment *bool `json:"udp_fragment,omitempty"` + UDPFragmentDefault bool `json:"-"` UDPTimeout int64 `json:"udp_timeout,omitempty"` ProxyProtocol bool `json:"proxy_protocol,omitempty"` ProxyProtocolAcceptNoHeader bool `json:"proxy_protocol_accept_no_header,omitempty"`