mirror of
https://github.com/SagerNet/sing-box.git
synced 2024-11-27 11:01:28 +00:00
Make GSO adaptive
This commit is contained in:
parent
20f5acafaf
commit
fe79082008
|
@ -33,17 +33,31 @@ func (n Note) Impending() bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n Note) Message() string {
|
func (n Note) Message() string {
|
||||||
|
if n.MigrationLink != "" {
|
||||||
return F.ToString(
|
return F.ToString(
|
||||||
n.Description, " is deprecated in sing-box ", n.DeprecatedVersion,
|
n.Description, " is deprecated in sing-box ", n.DeprecatedVersion,
|
||||||
" and will be removed in sing-box ", n.ScheduledVersion, ", please checkout documentation for migration.",
|
" and will be removed in sing-box ", n.ScheduledVersion, ", please checkout documentation for migration.",
|
||||||
)
|
)
|
||||||
|
} else {
|
||||||
|
return F.ToString(
|
||||||
|
n.Description, " is deprecated in sing-box ", n.DeprecatedVersion,
|
||||||
|
" and will be removed in sing-box ", n.ScheduledVersion, ".",
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n Note) MessageWithLink() string {
|
func (n Note) MessageWithLink() string {
|
||||||
|
if n.MigrationLink != "" {
|
||||||
return F.ToString(
|
return F.ToString(
|
||||||
n.Description, " is deprecated in sing-box ", n.DeprecatedVersion,
|
n.Description, " is deprecated in sing-box ", n.DeprecatedVersion,
|
||||||
" and will be removed in sing-box ", n.ScheduledVersion, ", checkout documentation for migration: ", n.MigrationLink,
|
" and will be removed in sing-box ", n.ScheduledVersion, ", checkout documentation for migration: ", n.MigrationLink,
|
||||||
)
|
)
|
||||||
|
} else {
|
||||||
|
return F.ToString(
|
||||||
|
n.Description, " is deprecated in sing-box ", n.DeprecatedVersion,
|
||||||
|
" and will be removed in sing-box ", n.ScheduledVersion, ".",
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var OptionBadMatchSource = Note{
|
var OptionBadMatchSource = Note{
|
||||||
|
@ -118,6 +132,23 @@ var OptionWireGuardOutbound = Note{
|
||||||
MigrationLink: "https://sing-box.sagernet.org/migration/#migrate-wireguard-outbound-to-endpoint",
|
MigrationLink: "https://sing-box.sagernet.org/migration/#migrate-wireguard-outbound-to-endpoint",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var OptionWireGuardGSO = Note{
|
||||||
|
Name: "wireguard-gso",
|
||||||
|
Description: "GSO option in wireguard outbound",
|
||||||
|
DeprecatedVersion: "1.11.0",
|
||||||
|
ScheduledVersion: "1.13.0",
|
||||||
|
EnvName: "WIREGUARD_GSO",
|
||||||
|
MigrationLink: "https://sing-box.sagernet.org/migration/#migrate-wireguard-outbound-to-endpoint",
|
||||||
|
}
|
||||||
|
|
||||||
|
var OptionTUNGSO = Note{
|
||||||
|
Name: "tun-gso",
|
||||||
|
Description: "GSO option in tun",
|
||||||
|
DeprecatedVersion: "1.11.0",
|
||||||
|
ScheduledVersion: "1.12.0",
|
||||||
|
EnvName: "TUN_GSO",
|
||||||
|
}
|
||||||
|
|
||||||
var Options = []Note{
|
var Options = []Note{
|
||||||
OptionBadMatchSource,
|
OptionBadMatchSource,
|
||||||
OptionGEOIP,
|
OptionGEOIP,
|
||||||
|
@ -127,4 +158,6 @@ var Options = []Note{
|
||||||
OptionInboundOptions,
|
OptionInboundOptions,
|
||||||
OptionDestinationOverrideFields,
|
OptionDestinationOverrideFields,
|
||||||
OptionWireGuardOutbound,
|
OptionWireGuardOutbound,
|
||||||
|
OptionWireGuardGSO,
|
||||||
|
OptionTUNGSO,
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,5 +34,5 @@ func (f *stderrManager) ReportDeprecated(feature Note) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
f.logger.Error(feature.MessageWithLink())
|
f.logger.Error(feature.MessageWithLink())
|
||||||
f.logger.Fatal("to continuing using this feature, set ENABLE_DEPRECATED_" + feature.EnvName + "=true")
|
f.logger.Fatal("to continuing using this feature, set environment variable ENABLE_DEPRECATED_" + feature.EnvName + "=true")
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,6 @@ import (
|
||||||
type TunInboundOptions struct {
|
type TunInboundOptions struct {
|
||||||
InterfaceName string `json:"interface_name,omitempty"`
|
InterfaceName string `json:"interface_name,omitempty"`
|
||||||
MTU uint32 `json:"mtu,omitempty"`
|
MTU uint32 `json:"mtu,omitempty"`
|
||||||
GSO bool `json:"gso,omitempty"`
|
|
||||||
Address badoption.Listable[netip.Prefix] `json:"address,omitempty"`
|
Address badoption.Listable[netip.Prefix] `json:"address,omitempty"`
|
||||||
AutoRoute bool `json:"auto_route,omitempty"`
|
AutoRoute bool `json:"auto_route,omitempty"`
|
||||||
IPRoute2TableIndex int `json:"iproute2_table_index,omitempty"`
|
IPRoute2TableIndex int `json:"iproute2_table_index,omitempty"`
|
||||||
|
@ -41,6 +40,8 @@ type TunInboundOptions struct {
|
||||||
Platform *TunPlatformOptions `json:"platform,omitempty"`
|
Platform *TunPlatformOptions `json:"platform,omitempty"`
|
||||||
InboundOptions
|
InboundOptions
|
||||||
|
|
||||||
|
// Deprecated: removed
|
||||||
|
GSO bool `json:"gso,omitempty"`
|
||||||
// Deprecated: merged to Address
|
// Deprecated: merged to Address
|
||||||
Inet4Address badoption.Listable[netip.Prefix] `json:"inet4_address,omitempty"`
|
Inet4Address badoption.Listable[netip.Prefix] `json:"inet4_address,omitempty"`
|
||||||
// Deprecated: merged to Address
|
// Deprecated: merged to Address
|
||||||
|
|
|
@ -10,7 +10,6 @@ type WireGuardEndpointOptions struct {
|
||||||
System bool `json:"system,omitempty"`
|
System bool `json:"system,omitempty"`
|
||||||
Name string `json:"name,omitempty"`
|
Name string `json:"name,omitempty"`
|
||||||
MTU uint32 `json:"mtu,omitempty"`
|
MTU uint32 `json:"mtu,omitempty"`
|
||||||
GSO bool `json:"gso,omitempty"`
|
|
||||||
Address badoption.Listable[netip.Prefix] `json:"address"`
|
Address badoption.Listable[netip.Prefix] `json:"address"`
|
||||||
PrivateKey string `json:"private_key"`
|
PrivateKey string `json:"private_key"`
|
||||||
ListenPort uint16 `json:"listen_port,omitempty"`
|
ListenPort uint16 `json:"listen_port,omitempty"`
|
||||||
|
|
|
@ -64,14 +64,14 @@ type Inbound struct {
|
||||||
func NewInbound(ctx context.Context, router adapter.Router, logger log.ContextLogger, tag string, options option.TunInboundOptions) (adapter.Inbound, error) {
|
func NewInbound(ctx context.Context, router adapter.Router, logger log.ContextLogger, tag string, options option.TunInboundOptions) (adapter.Inbound, error) {
|
||||||
address := options.Address
|
address := options.Address
|
||||||
var deprecatedAddressUsed bool
|
var deprecatedAddressUsed bool
|
||||||
|
|
||||||
//nolint:staticcheck
|
//nolint:staticcheck
|
||||||
//goland:noinspection GoDeprecation
|
|
||||||
if len(options.Inet4Address) > 0 {
|
if len(options.Inet4Address) > 0 {
|
||||||
address = append(address, options.Inet4Address...)
|
address = append(address, options.Inet4Address...)
|
||||||
deprecatedAddressUsed = true
|
deprecatedAddressUsed = true
|
||||||
}
|
}
|
||||||
|
|
||||||
//nolint:staticcheck
|
//nolint:staticcheck
|
||||||
//goland:noinspection GoDeprecation
|
|
||||||
if len(options.Inet6Address) > 0 {
|
if len(options.Inet6Address) > 0 {
|
||||||
address = append(address, options.Inet6Address...)
|
address = append(address, options.Inet6Address...)
|
||||||
deprecatedAddressUsed = true
|
deprecatedAddressUsed = true
|
||||||
|
@ -84,14 +84,14 @@ func NewInbound(ctx context.Context, router adapter.Router, logger log.ContextLo
|
||||||
})
|
})
|
||||||
|
|
||||||
routeAddress := options.RouteAddress
|
routeAddress := options.RouteAddress
|
||||||
|
|
||||||
//nolint:staticcheck
|
//nolint:staticcheck
|
||||||
//goland:noinspection GoDeprecation
|
|
||||||
if len(options.Inet4RouteAddress) > 0 {
|
if len(options.Inet4RouteAddress) > 0 {
|
||||||
routeAddress = append(routeAddress, options.Inet4RouteAddress...)
|
routeAddress = append(routeAddress, options.Inet4RouteAddress...)
|
||||||
deprecatedAddressUsed = true
|
deprecatedAddressUsed = true
|
||||||
}
|
}
|
||||||
|
|
||||||
//nolint:staticcheck
|
//nolint:staticcheck
|
||||||
//goland:noinspection GoDeprecation
|
|
||||||
if len(options.Inet6RouteAddress) > 0 {
|
if len(options.Inet6RouteAddress) > 0 {
|
||||||
routeAddress = append(routeAddress, options.Inet6RouteAddress...)
|
routeAddress = append(routeAddress, options.Inet6RouteAddress...)
|
||||||
deprecatedAddressUsed = true
|
deprecatedAddressUsed = true
|
||||||
|
@ -104,14 +104,14 @@ func NewInbound(ctx context.Context, router adapter.Router, logger log.ContextLo
|
||||||
})
|
})
|
||||||
|
|
||||||
routeExcludeAddress := options.RouteExcludeAddress
|
routeExcludeAddress := options.RouteExcludeAddress
|
||||||
|
|
||||||
//nolint:staticcheck
|
//nolint:staticcheck
|
||||||
//goland:noinspection GoDeprecation
|
|
||||||
if len(options.Inet4RouteExcludeAddress) > 0 {
|
if len(options.Inet4RouteExcludeAddress) > 0 {
|
||||||
routeExcludeAddress = append(routeExcludeAddress, options.Inet4RouteExcludeAddress...)
|
routeExcludeAddress = append(routeExcludeAddress, options.Inet4RouteExcludeAddress...)
|
||||||
deprecatedAddressUsed = true
|
deprecatedAddressUsed = true
|
||||||
}
|
}
|
||||||
|
|
||||||
//nolint:staticcheck
|
//nolint:staticcheck
|
||||||
//goland:noinspection GoDeprecation
|
|
||||||
if len(options.Inet6RouteExcludeAddress) > 0 {
|
if len(options.Inet6RouteExcludeAddress) > 0 {
|
||||||
routeExcludeAddress = append(routeExcludeAddress, options.Inet6RouteExcludeAddress...)
|
routeExcludeAddress = append(routeExcludeAddress, options.Inet6RouteExcludeAddress...)
|
||||||
deprecatedAddressUsed = true
|
deprecatedAddressUsed = true
|
||||||
|
@ -127,6 +127,11 @@ func NewInbound(ctx context.Context, router adapter.Router, logger log.ContextLo
|
||||||
deprecated.Report(ctx, deprecated.OptionTUNAddressX)
|
deprecated.Report(ctx, deprecated.OptionTUNAddressX)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//nolint:staticcheck
|
||||||
|
if options.GSO {
|
||||||
|
deprecated.Report(ctx, deprecated.OptionTUNGSO)
|
||||||
|
}
|
||||||
|
|
||||||
tunMTU := options.MTU
|
tunMTU := options.MTU
|
||||||
if tunMTU == 0 {
|
if tunMTU == 0 {
|
||||||
tunMTU = 9000
|
tunMTU = 9000
|
||||||
|
@ -180,7 +185,6 @@ 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: options.GSO,
|
|
||||||
Inet4Address: inet4Address,
|
Inet4Address: inet4Address,
|
||||||
Inet6Address: inet6Address,
|
Inet6Address: inet6Address,
|
||||||
AutoRoute: options.AutoRoute,
|
AutoRoute: options.AutoRoute,
|
||||||
|
|
|
@ -51,8 +51,6 @@ func NewEndpoint(ctx context.Context, router adapter.Router, logger log.ContextL
|
||||||
}
|
}
|
||||||
if options.Detour == "" {
|
if options.Detour == "" {
|
||||||
options.IsWireGuardListener = true
|
options.IsWireGuardListener = true
|
||||||
} else if options.GSO {
|
|
||||||
return nil, E.New("gso is conflict with detour")
|
|
||||||
}
|
}
|
||||||
outboundDialer, err := dialer.New(ctx, options.DialerOptions)
|
outboundDialer, err := dialer.New(ctx, options.DialerOptions)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -72,7 +70,6 @@ func NewEndpoint(ctx context.Context, router adapter.Router, logger log.ContextL
|
||||||
},
|
},
|
||||||
Name: options.Name,
|
Name: options.Name,
|
||||||
MTU: options.MTU,
|
MTU: options.MTU,
|
||||||
GSO: options.GSO,
|
|
||||||
Address: options.Address,
|
Address: options.Address,
|
||||||
PrivateKey: options.PrivateKey,
|
PrivateKey: options.PrivateKey,
|
||||||
ListenPort: options.ListenPort,
|
ListenPort: options.ListenPort,
|
||||||
|
|
|
@ -42,6 +42,9 @@ type Outbound struct {
|
||||||
|
|
||||||
func NewOutbound(ctx context.Context, router adapter.Router, logger log.ContextLogger, tag string, options option.LegacyWireGuardOutboundOptions) (adapter.Outbound, error) {
|
func NewOutbound(ctx context.Context, router adapter.Router, logger log.ContextLogger, tag string, options option.LegacyWireGuardOutboundOptions) (adapter.Outbound, error) {
|
||||||
deprecated.Report(ctx, deprecated.OptionWireGuardOutbound)
|
deprecated.Report(ctx, deprecated.OptionWireGuardOutbound)
|
||||||
|
if options.GSO {
|
||||||
|
deprecated.Report(ctx, deprecated.OptionWireGuardGSO)
|
||||||
|
}
|
||||||
outbound := &Outbound{
|
outbound := &Outbound{
|
||||||
Adapter: outbound.NewAdapterWithDialerOptions(C.TypeWireGuard, tag, []string{N.NetworkTCP, N.NetworkUDP}, options.DialerOptions),
|
Adapter: outbound.NewAdapterWithDialerOptions(C.TypeWireGuard, tag, []string{N.NetworkTCP, N.NetworkUDP}, options.DialerOptions),
|
||||||
ctx: ctx,
|
ctx: ctx,
|
||||||
|
@ -70,7 +73,6 @@ func NewOutbound(ctx context.Context, router adapter.Router, logger log.ContextL
|
||||||
},
|
},
|
||||||
Name: options.InterfaceName,
|
Name: options.InterfaceName,
|
||||||
MTU: options.MTU,
|
MTU: options.MTU,
|
||||||
GSO: options.GSO,
|
|
||||||
Address: options.LocalAddress,
|
Address: options.LocalAddress,
|
||||||
PrivateKey: options.PrivateKey,
|
PrivateKey: options.PrivateKey,
|
||||||
ResolvePeer: func(domain string) (netip.Addr, error) {
|
ResolvePeer: func(domain string) (netip.Addr, error) {
|
||||||
|
|
|
@ -28,7 +28,6 @@ type DeviceOptions struct {
|
||||||
CreateDialer func(interfaceName string) N.Dialer
|
CreateDialer func(interfaceName string) N.Dialer
|
||||||
Name string
|
Name string
|
||||||
MTU uint32
|
MTU uint32
|
||||||
GSO bool
|
|
||||||
Address []netip.Prefix
|
Address []netip.Prefix
|
||||||
AllowedAddress []netip.Prefix
|
AllowedAddress []netip.Prefix
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,6 @@ import (
|
||||||
"github.com/sagernet/sing-box/adapter"
|
"github.com/sagernet/sing-box/adapter"
|
||||||
"github.com/sagernet/sing-tun"
|
"github.com/sagernet/sing-tun"
|
||||||
"github.com/sagernet/sing/common"
|
"github.com/sagernet/sing/common"
|
||||||
E "github.com/sagernet/sing/common/exceptions"
|
|
||||||
M "github.com/sagernet/sing/common/metadata"
|
M "github.com/sagernet/sing/common/metadata"
|
||||||
N "github.com/sagernet/sing/common/network"
|
N "github.com/sagernet/sing/common/network"
|
||||||
"github.com/sagernet/sing/service"
|
"github.com/sagernet/sing/service"
|
||||||
|
@ -64,7 +63,7 @@ func (w *systemDevice) Start() error {
|
||||||
return it.Addr().Is6()
|
return it.Addr().Is6()
|
||||||
}),
|
}),
|
||||||
MTU: w.options.MTU,
|
MTU: w.options.MTU,
|
||||||
GSO: w.options.GSO,
|
GSO: true,
|
||||||
InterfaceScope: true,
|
InterfaceScope: true,
|
||||||
Inet4RouteAddress: common.Filter(w.options.AllowedAddress, func(it netip.Prefix) bool {
|
Inet4RouteAddress: common.Filter(w.options.AllowedAddress, func(it netip.Prefix) bool {
|
||||||
return it.Addr().Is4()
|
return it.Addr().Is4()
|
||||||
|
@ -87,12 +86,8 @@ func (w *systemDevice) Start() error {
|
||||||
}
|
}
|
||||||
w.options.Logger.Info("started at ", w.options.Name)
|
w.options.Logger.Info("started at ", w.options.Name)
|
||||||
w.device = tunInterface
|
w.device = tunInterface
|
||||||
if w.options.GSO {
|
|
||||||
batchTUN, isBatchTUN := tunInterface.(tun.LinuxTUN)
|
batchTUN, isBatchTUN := tunInterface.(tun.LinuxTUN)
|
||||||
if !isBatchTUN {
|
if isBatchTUN {
|
||||||
tunInterface.Close()
|
|
||||||
return E.New("GSO is not supported on current platform")
|
|
||||||
}
|
|
||||||
w.batchDevice = batchTUN
|
w.batchDevice = batchTUN
|
||||||
}
|
}
|
||||||
w.events <- wgTun.EventUp
|
w.events <- wgTun.EventUp
|
||||||
|
|
|
@ -104,7 +104,6 @@ func NewEndpoint(options EndpointOptions) (*Endpoint, error) {
|
||||||
CreateDialer: options.CreateDialer,
|
CreateDialer: options.CreateDialer,
|
||||||
Name: options.Name,
|
Name: options.Name,
|
||||||
MTU: options.MTU,
|
MTU: options.MTU,
|
||||||
GSO: options.GSO,
|
|
||||||
Address: options.Address,
|
Address: options.Address,
|
||||||
AllowedAddress: allowedAddresses,
|
AllowedAddress: allowedAddresses,
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,6 @@ type EndpointOptions struct {
|
||||||
CreateDialer func(interfaceName string) N.Dialer
|
CreateDialer func(interfaceName string) N.Dialer
|
||||||
Name string
|
Name string
|
||||||
MTU uint32
|
MTU uint32
|
||||||
GSO bool
|
|
||||||
Address []netip.Prefix
|
Address []netip.Prefix
|
||||||
PrivateKey string
|
PrivateKey string
|
||||||
ListenPort uint16
|
ListenPort uint16
|
||||||
|
|
Loading…
Reference in a new issue