Increase default mtu to 65535

This commit is contained in:
世界 2025-07-12 14:47:27 +08:00
parent 0098a2adc5
commit ae2ecd6002
No known key found for this signature in database
GPG Key ID: CD109927C34A63C4

View File

@ -132,12 +132,13 @@ func NewInbound(ctx context.Context, router adapter.Router, logger log.ContextLo
platformInterface := service.FromContext[platform.Interface](ctx) platformInterface := service.FromContext[platform.Interface](ctx)
tunMTU := options.MTU tunMTU := options.MTU
enableGSO := C.IsLinux && options.Stack == "gvisor" && platformInterface == nil && tunMTU > 0 && tunMTU < 49152
if tunMTU == 0 { if tunMTU == 0 {
if platformInterface != nil && platformInterface.UnderNetworkExtension() { if platformInterface != nil && platformInterface.UnderNetworkExtension() {
// In Network Extension, when MTU exceeds 4064 (4096-UTUN_IF_HEADROOM_SIZE), the performance of tun will drop significantly, which may be a system bug. // In Network Extension, when MTU exceeds 4064 (4096-UTUN_IF_HEADROOM_SIZE), the performance of tun will drop significantly, which may be a system bug.
tunMTU = 4064 tunMTU = 4064
} else { } else {
tunMTU = 9000 tunMTU = 65535
} }
} }
var udpTimeout time.Duration var udpTimeout time.Duration
@ -189,6 +190,7 @@ func NewInbound(ctx context.Context, router adapter.Router, logger log.ContextLo
tunOptions: tun.Options{ tunOptions: tun.Options{
Name: options.InterfaceName, Name: options.InterfaceName,
MTU: tunMTU, MTU: tunMTU,
GSO: enableGSO,
Inet4Address: inet4Address, Inet4Address: inet4Address,
Inet6Address: inet6Address, Inet6Address: inet6Address,
AutoRoute: options.AutoRoute, AutoRoute: options.AutoRoute,