mirror of
https://gitclone.com/github.com/MetaCubeX/Clash.Meta
synced 2025-02-23 04:33:16 +08:00
fix: tun lookback when don't have an activated network
This commit is contained in:
parent
914bc8a3e9
commit
4542fc0991
@ -173,6 +173,7 @@ func New(options LC.Tun, tunnel C.Tunnel, additions ...inbound.Addition) (l *Lis
|
|||||||
closed: false,
|
closed: false,
|
||||||
options: options,
|
options: options,
|
||||||
handler: handler,
|
handler: handler,
|
||||||
|
tunName: tunName,
|
||||||
}
|
}
|
||||||
defer func() {
|
defer func() {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -279,7 +280,6 @@ func New(options LC.Tun, tunnel C.Tunnel, additions ...inbound.Addition) (l *Lis
|
|||||||
|
|
||||||
func (l *Listener) FlushDefaultInterface() {
|
func (l *Listener) FlushDefaultInterface() {
|
||||||
if l.options.AutoDetectInterface {
|
if l.options.AutoDetectInterface {
|
||||||
targetInterface := dialer.DefaultInterface.Load()
|
|
||||||
for _, destination := range []netip.Addr{netip.IPv4Unspecified(), netip.IPv6Unspecified(), netip.MustParseAddr("1.1.1.1")} {
|
for _, destination := range []netip.Addr{netip.IPv4Unspecified(), netip.IPv6Unspecified(), netip.MustParseAddr("1.1.1.1")} {
|
||||||
autoDetectInterfaceName := l.defaultInterfaceMonitor.DefaultInterfaceName(destination)
|
autoDetectInterfaceName := l.defaultInterfaceMonitor.DefaultInterfaceName(destination)
|
||||||
if autoDetectInterfaceName == l.tunName {
|
if autoDetectInterfaceName == l.tunName {
|
||||||
@ -287,17 +287,16 @@ func (l *Listener) FlushDefaultInterface() {
|
|||||||
} else if autoDetectInterfaceName == "" || autoDetectInterfaceName == "<nil>" {
|
} else if autoDetectInterfaceName == "" || autoDetectInterfaceName == "<nil>" {
|
||||||
log.Warnln("[TUN] Auto detect interface by %s get empty name.", destination.String())
|
log.Warnln("[TUN] Auto detect interface by %s get empty name.", destination.String())
|
||||||
} else {
|
} else {
|
||||||
targetInterface = autoDetectInterfaceName
|
if old := dialer.DefaultInterface.Swap(autoDetectInterfaceName); old != autoDetectInterfaceName {
|
||||||
if old := dialer.DefaultInterface.Load(); old != targetInterface {
|
log.Warnln("[TUN] default interface changed by monitor, %s => %s", old, autoDetectInterfaceName)
|
||||||
log.Warnln("[TUN] default interface changed by monitor, %s => %s", old, targetInterface)
|
|
||||||
|
|
||||||
dialer.DefaultInterface.Store(targetInterface)
|
|
||||||
|
|
||||||
iface.FlushCache()
|
iface.FlushCache()
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if dialer.DefaultInterface.CompareAndSwap("", "<invalid>") {
|
||||||
|
log.Warnln("[TUN] Auto detect interface failed, set '<invalid>' to DefaultInterface to avoid lookback")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user