Fix process search skipped for Android again

This commit is contained in:
世界
2026-04-23 05:52:14 +08:00
parent 3312b8da50
commit f102ef1d94
4 changed files with 34 additions and 5 deletions

View File

@@ -1,6 +1,8 @@
package adapter package adapter
import ( import (
"net/netip"
"github.com/sagernet/sing-box/option" "github.com/sagernet/sing-box/option"
"github.com/sagernet/sing-tun" "github.com/sagernet/sing-tun"
"github.com/sagernet/sing/common/logger" "github.com/sagernet/sing/common/logger"
@@ -36,6 +38,8 @@ type PlatformInterface interface {
UsePlatformNotification() bool UsePlatformNotification() bool
SendNotification(notification *Notification) error SendNotification(notification *Notification) error
MyInterfaceAddress() []netip.Addr
} }
type FindConnectionOwnerRequest struct { type FindConnectionOwnerRequest struct {

View File

@@ -3,6 +3,7 @@ package libbox
import ( import (
"bytes" "bytes"
"context" "context"
"net/netip"
"os" "os"
box "github.com/sagernet/sing-box" box "github.com/sagernet/sing-box"
@@ -144,6 +145,10 @@ func (s *platformInterfaceStub) SendNotification(notification *adapter.Notificat
return nil return nil
} }
func (s *platformInterfaceStub) MyInterfaceAddress() []netip.Addr {
return nil
}
func (s *platformInterfaceStub) UsePlatformLocalDNSTransport() bool { func (s *platformInterfaceStub) UsePlatformLocalDNSTransport() bool {
return false return false
} }

View File

@@ -29,6 +29,7 @@ type platformInterfaceWrapper struct {
useProcFS bool useProcFS bool
networkManager adapter.NetworkManager networkManager adapter.NetworkManager
myTunName string myTunName string
myTunAddress []netip.Addr
defaultInterfaceAccess sync.Mutex defaultInterfaceAccess sync.Mutex
defaultInterface *control.Interface defaultInterface *control.Interface
isExpensive bool isExpensive bool
@@ -78,9 +79,25 @@ func (w *platformInterfaceWrapper) OpenInterface(options *tun.Options, platformO
} }
options.FileDescriptor = dupFd options.FileDescriptor = dupFd
w.myTunName = options.Name w.myTunName = options.Name
w.myTunAddress = myTunAddress(options)
return tun.New(*options) return tun.New(*options)
} }
func myTunAddress(options *tun.Options) []netip.Addr {
addresses := make([]netip.Addr, 0, len(options.Inet4Address)+len(options.Inet6Address))
for _, prefix := range options.Inet4Address {
addresses = append(addresses, prefix.Addr())
}
for _, prefix := range options.Inet6Address {
addresses = append(addresses, prefix.Addr())
}
return addresses
}
func (w *platformInterfaceWrapper) MyInterfaceAddress() []netip.Addr {
return w.myTunAddress
}
func (w *platformInterfaceWrapper) UsePlatformDefaultInterfaceMonitor() bool { func (w *platformInterfaceWrapper) UsePlatformDefaultInterfaceMonitor() bool {
return true return true
} }

View File

@@ -74,16 +74,19 @@ func (r *Router) searchProcessInfo(ctx context.Context, metadata *adapter.Inboun
} }
func (r *Router) isLocalSource(source netip.Addr) bool { func (r *Router) isLocalSource(source netip.Addr) bool {
if !source.IsValid() {
return false
}
source = source.Unmap()
if source.IsLoopback() { if source.IsLoopback() {
return true return true
} }
if r.platformInterface != nil {
for _, addr := range r.platformInterface.MyInterfaceAddress() {
if addr == source {
return true
}
}
}
for _, netInterface := range r.network.InterfaceFinder().Interfaces() { for _, netInterface := range r.network.InterfaceFinder().Interfaces() {
for _, prefix := range netInterface.Addresses { for _, prefix := range netInterface.Addresses {
if prefix.Addr().Unmap() == source { if prefix.Addr() == source {
return true return true
} }
} }