Add optional LWIP tun stack support

This commit is contained in:
世界
2022-08-07 17:21:49 +08:00
parent 6ee10c03d1
commit 0f74f6cd60
7 changed files with 33 additions and 36 deletions

View File

@@ -1,5 +1,3 @@
//go:build (linux || windows || darwin) && !no_gvisor
package inbound
import (
@@ -27,8 +25,7 @@ import (
var _ adapter.Inbound = (*Tun)(nil)
type Tun struct {
tag string
tag string
ctx context.Context
router adapter.Router
logger log.ContextLogger
@@ -40,9 +37,9 @@ type Tun struct {
autoRoute bool
endpointIndependentNat bool
udpTimeout int64
tunIf tun.Tun
tunStack *tun.GVisorTun
stack string
tunIf tun.Tun
tunStack tun.Stack
}
func NewTun(ctx context.Context, router adapter.Router, logger log.ContextLogger, tag string, options option.TunInboundOptions) (*Tun, error) {
@@ -73,6 +70,7 @@ func NewTun(ctx context.Context, router adapter.Router, logger log.ContextLogger
autoRoute: options.AutoRoute,
endpointIndependentNat: options.EndpointIndependentNat,
udpTimeout: udpTimeout,
stack: options.Stack,
}, nil
}
@@ -90,7 +88,10 @@ func (t *Tun) Start() error {
return E.Cause(err, "configure tun interface")
}
t.tunIf = tunIf
t.tunStack = tun.NewGVisor(t.ctx, tunIf, t.tunMTU, t.endpointIndependentNat, t.udpTimeout, t)
t.tunStack, err = tun.NewStack(t.ctx, t.stack, tunIf, t.tunMTU, t.endpointIndependentNat, t.udpTimeout, t)
if err != nil {
return err
}
err = t.tunStack.Start()
if err != nil {
return err

View File

@@ -1,16 +0,0 @@
//go:build !(linux || windows || darwin) || no_gvisor
package inbound
import (
"context"
"os"
"github.com/sagernet/sing-box/adapter"
"github.com/sagernet/sing-box/log"
"github.com/sagernet/sing-box/option"
)
func NewTun(ctx context.Context, router adapter.Router, logger log.ContextLogger, tag string, options option.TunInboundOptions) (adapter.Inbound, error) {
return nil, os.ErrInvalid
}