Handle TUN loopback in direct outbound

This commit is contained in:
世界
2026-06-03 10:37:53 +08:00
parent 1086ab2563
commit 761b7f4e12
8 changed files with 77 additions and 19 deletions

View File

@@ -11,6 +11,7 @@ import (
"unsafe"
"github.com/sagernet/sing-box/adapter"
"github.com/sagernet/sing/common"
"github.com/sagernet/sing/service"
"golang.org/x/sys/windows"
@@ -77,12 +78,12 @@ func dnsReadConfig(ctx context.Context, _ string) *dnsConfig {
}{ifName: windows.UTF16PtrToString(address.FriendlyName), Addr: dnsServerAddr})
}
}
var myInterface string
var myInterfaces []string
if networkManager := service.FromContext[adapter.NetworkManager](ctx); networkManager != nil {
myInterface = networkManager.InterfaceMonitor().MyInterface()
myInterfaces = networkManager.InterfaceMonitor().MyInterfaces()
}
for _, address := range dnsAddresses {
if address.ifName == myInterface {
if common.Contains(myInterfaces, address.ifName) {
continue
}
conf.servers = append(conf.servers, net.JoinHostPort(address.String(), "53"))