Skip to content

Commit

Permalink
Add StackOptions.IncludeAllNetworks
Browse files Browse the repository at this point in the history
  • Loading branch information
nekohasekai committed May 7, 2024
1 parent e272ff0 commit fb6e917
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
11 changes: 10 additions & 1 deletion stack.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ type StackOptions struct {
Handler Handler
Logger logger.Logger
ForwarderBindInterface bool
IncludeAllNetworks bool
InterfaceFinder control.InterfaceFinder
}

Expand All @@ -34,16 +35,24 @@ 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)
}
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)
Expand Down
2 changes: 2 additions & 0 deletions stack_system.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit fb6e917

Please sign in to comment.