mirror of
https://github.com/shtorm-7/sing-box-extended.git
synced 2026-05-14 00:51:12 +03:00
Fix process search skipped for Android again
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user