mirror of
https://github.com/SagerNet/sing-tun.git
synced 2025-04-03 03:47:39 +03:00
Fix monitor for ios
This commit is contained in:
parent
8848c0e4cb
commit
499c0aed67
1 changed files with 10 additions and 5 deletions
|
@ -5,6 +5,8 @@ import (
|
||||||
"net"
|
"net"
|
||||||
"net/netip"
|
"net/netip"
|
||||||
"os"
|
"os"
|
||||||
|
"runtime"
|
||||||
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
|
@ -85,6 +87,13 @@ func (m *defaultInterfaceMonitor) checkUpdate() error {
|
||||||
}
|
}
|
||||||
for _, rawRouteMessage := range routeMessages {
|
for _, rawRouteMessage := range routeMessages {
|
||||||
routeMessage := rawRouteMessage.(*route.RouteMessage)
|
routeMessage := rawRouteMessage.(*route.RouteMessage)
|
||||||
|
routeInterface, err := net.InterfaceByIndex(routeMessage.Index)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if runtime.GOOS == "ios" && strings.HasPrefix(routeInterface.Name, "utun") {
|
||||||
|
continue
|
||||||
|
}
|
||||||
if common.Any(common.FilterIsInstance(routeMessage.Addrs, func(it route.Addr) (*route.Inet4Addr, bool) {
|
if common.Any(common.FilterIsInstance(routeMessage.Addrs, func(it route.Addr) (*route.Inet4Addr, bool) {
|
||||||
addr, loaded := it.(*route.Inet4Addr)
|
addr, loaded := it.(*route.Inet4Addr)
|
||||||
return addr, loaded
|
return addr, loaded
|
||||||
|
@ -95,11 +104,7 @@ func (m *defaultInterfaceMonitor) checkUpdate() error {
|
||||||
oldIndex := m.defaultInterfaceIndex
|
oldIndex := m.defaultInterfaceIndex
|
||||||
|
|
||||||
m.defaultInterfaceIndex = routeMessage.Index
|
m.defaultInterfaceIndex = routeMessage.Index
|
||||||
defaultInterface, err := net.InterfaceByIndex(routeMessage.Index)
|
m.defaultInterfaceName = routeInterface.Name
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
m.defaultInterfaceName = defaultInterface.Name
|
|
||||||
if oldInterface == m.defaultInterfaceName && oldIndex == m.defaultInterfaceIndex {
|
if oldInterface == m.defaultInterfaceName && oldIndex == m.defaultInterfaceIndex {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue