From 3a92bf993dab51662eb32d834ffb24ea11499c46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=96=E7=95=8C?= Date: Fri, 21 Apr 2023 17:04:55 +0800 Subject: [PATCH] platform: Add UsePlatformAutoDetectInterfaceControl --- experimental/libbox/platform.go | 1 + experimental/libbox/platform/interface.go | 1 + experimental/libbox/service.go | 4 ++++ route/router.go | 2 +- 4 files changed, 7 insertions(+), 1 deletion(-) diff --git a/experimental/libbox/platform.go b/experimental/libbox/platform.go index 60198b22..d968d571 100644 --- a/experimental/libbox/platform.go +++ b/experimental/libbox/platform.go @@ -5,6 +5,7 @@ import ( ) type PlatformInterface interface { + UsePlatformAutoDetectInterfaceControl() bool AutoDetectInterfaceControl(fd int32) error OpenTun(options TunOptions) (int32, error) WriteLog(message string) diff --git a/experimental/libbox/platform/interface.go b/experimental/libbox/platform/interface.go index 0f3680ca..a5920695 100644 --- a/experimental/libbox/platform/interface.go +++ b/experimental/libbox/platform/interface.go @@ -15,6 +15,7 @@ import ( type Interface interface { Initialize(ctx context.Context, router adapter.Router) error + UsePlatformAutoDetectInterfaceControl() bool AutoDetectInterfaceControl() control.Func OpenTun(options *tun.Options, platformOptions option.TunPlatformOptions) (tun.Tun, error) UsePlatformDefaultInterfaceMonitor() bool diff --git a/experimental/libbox/service.go b/experimental/libbox/service.go index b247a631..fe75049c 100644 --- a/experimental/libbox/service.go +++ b/experimental/libbox/service.go @@ -68,6 +68,10 @@ func (w *platformInterfaceWrapper) Initialize(ctx context.Context, router adapte return nil } +func (w *platformInterfaceWrapper) UsePlatformAutoDetectInterfaceControl() bool { + return w.iif.UsePlatformAutoDetectInterfaceControl() +} + func (w *platformInterfaceWrapper) AutoDetectInterfaceControl() control.Func { return func(network, address string, conn syscall.RawConn) error { return control.Raw(conn, func(fd uintptr) error { diff --git a/route/router.go b/route/router.go index 7eeb20c5..aabd94c1 100644 --- a/route/router.go +++ b/route/router.go @@ -823,7 +823,7 @@ func (r *Router) AutoDetectInterface() bool { } func (r *Router) AutoDetectInterfaceFunc() control.Func { - if r.platformInterface != nil { + if r.platformInterface != nil && r.platformInterface.UsePlatformAutoDetectInterfaceControl() { return r.platformInterface.AutoDetectInterfaceControl() } else { return control.BindToInterfaceFunc(r.InterfaceFinder(), func(network string, address string) (interfaceName string, interfaceIndex int) {