Add StackOptions.IncludeAllNetworks

This commit is contained in:
世界 2024-05-07 20:20:44 +08:00
parent e272ff0ad3
commit fb6e917a2c
No known key found for this signature in database
GPG Key ID: CD109927C34A63C4
2 changed files with 12 additions and 1 deletions

View File

@ -25,6 +25,7 @@ type StackOptions struct {
Handler Handler
Logger logger.Logger
ForwarderBindInterface bool
IncludeAllNetworks bool
InterfaceFinder control.InterfaceFinder
}
@ -34,7 +35,9 @@ func NewStack(
) (Stack, error) {
switch stack {
case "":
if WithGVisor && !options.TunOptions.GSO {
if options.IncludeAllNetworks {
return NewGVisor(options)
} else if WithGVisor && !options.TunOptions.GSO {
return NewMixed(options)
} else {
return NewSystem(options)
@ -42,8 +45,14 @@ func NewStack(
case "gvisor":
return NewGVisor(options)
case "mixed":
if options.IncludeAllNetworks {
return nil, ErrIncludeAllNetworks
}
return NewMixed(options)
case "system":
if options.IncludeAllNetworks {
return nil, ErrIncludeAllNetworks
}
return NewSystem(options)
default:
return nil, E.New("unknown stack: ", stack)

View File

@ -18,6 +18,8 @@ import (
"github.com/sagernet/sing/common/udpnat"
)
var ErrIncludeAllNetworks = E.New("`system` and `mixed` stack are not available when `includeAllNetworks` is enabled. See https://github.com/SagerNet/sing-tun/issues/25")
type System struct {
ctx context.Context
tun Tun