Fix process search skipped for Android again

This commit is contained in:
世界 2026-04-23 05:52:14 +08:00
parent 3312b8da50
commit f102ef1d94
No known key found for this signature in database
GPG key ID: CD109927C34A63C4
4 changed files with 34 additions and 5 deletions

View file

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

View file

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

View file

@ -29,6 +29,7 @@ type platformInterfaceWrapper struct {
useProcFS bool
networkManager adapter.NetworkManager
myTunName string
myTunAddress []netip.Addr
defaultInterfaceAccess sync.Mutex
defaultInterface *control.Interface
isExpensive bool
@ -78,9 +79,25 @@ func (w *platformInterfaceWrapper) OpenInterface(options *tun.Options, platformO
}
options.FileDescriptor = dupFd
w.myTunName = options.Name
w.myTunAddress = myTunAddress(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 {
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 {
if !source.IsValid() {
return false
}
source = source.Unmap()
if source.IsLoopback() {
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 _, prefix := range netInterface.Addresses {
if prefix.Addr().Unmap() == source {
if prefix.Addr() == source {
return true
}
}