fix: don't set auto detect interface with tun name
This commit is contained in:
parent
1bd6a4c4c2
commit
a73f1f0b37
2 changed files with 25 additions and 18 deletions
|
@ -373,8 +373,8 @@ func UnmarshalRawConfig(buf []byte) (*RawConfig, error) {
|
||||||
Device: "",
|
Device: "",
|
||||||
Stack: "gvisor",
|
Stack: "gvisor",
|
||||||
DNSHijack: []string{"0.0.0.0:53"}, // default hijack all dns query
|
DNSHijack: []string{"0.0.0.0:53"}, // default hijack all dns query
|
||||||
AutoRoute: false,
|
AutoRoute: true,
|
||||||
AutoDetectInterface: false,
|
AutoDetectInterface: true,
|
||||||
Inet6Address: []ListenPrefix{ListenPrefix(netip.MustParsePrefix("fdfe:dcba:9876::1/126"))},
|
Inet6Address: []ListenPrefix{ListenPrefix(netip.MustParsePrefix("fdfe:dcba:9876::1/126"))},
|
||||||
},
|
},
|
||||||
EBpf: EBpf{
|
EBpf: EBpf{
|
||||||
|
|
|
@ -142,19 +142,22 @@ func New(options config.Tun, tcpIn chan<- C.ConnContext, udpIn chan<- *inbound.P
|
||||||
}
|
}
|
||||||
l.networkUpdateMonitor = networkUpdateMonitor
|
l.networkUpdateMonitor = networkUpdateMonitor
|
||||||
|
|
||||||
defaultInterfaceMonitor, err := tun.NewDefaultInterfaceMonitor(networkUpdateMonitor, tun.DefaultInterfaceMonitorOptions{})
|
defaultInterfaceMonitor, err := tun.NewDefaultInterfaceMonitor(networkUpdateMonitor, tun.DefaultInterfaceMonitorOptions{OverrideAndroidVPN: true})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = E.Cause(err, "create DefaultInterfaceMonitor")
|
err = E.Cause(err, "create DefaultInterfaceMonitor")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if options.AutoDetectInterface {
|
||||||
defaultInterfaceMonitor.RegisterCallback(func(event int) error {
|
defaultInterfaceMonitor.RegisterCallback(func(event int) error {
|
||||||
targetInterface := dialer.DefaultInterface.Load()
|
targetInterface := dialer.DefaultInterface.Load()
|
||||||
autoDetectInterfaceName := defaultInterfaceMonitor.DefaultInterfaceName(netip.IPv4Unspecified())
|
for _, destination := range []netip.Addr{netip.IPv4Unspecified(), netip.IPv6Unspecified(), netip.MustParseAddr("1.1.1.1")} {
|
||||||
if autoDetectInterfaceName != "" && autoDetectInterfaceName != "<nil>" {
|
autoDetectInterfaceName := defaultInterfaceMonitor.DefaultInterfaceName(destination)
|
||||||
targetInterface = autoDetectInterfaceName
|
if autoDetectInterfaceName == tunName {
|
||||||
|
log.Warnln("Auto detect interface by %s get same name with tun", destination.String())
|
||||||
|
} else if autoDetectInterfaceName == "" || autoDetectInterfaceName == "<nil>" {
|
||||||
|
log.Warnln("Auto detect interface by %s get empty name.", destination.String())
|
||||||
} else {
|
} else {
|
||||||
log.Warnln("Auto detect interface name is empty.")
|
targetInterface = autoDetectInterfaceName
|
||||||
}
|
|
||||||
if old := dialer.DefaultInterface.Load(); old != targetInterface {
|
if old := dialer.DefaultInterface.Load(); old != targetInterface {
|
||||||
log.Warnln("[TUN] default interface changed by monitor, %s => %s", old, targetInterface)
|
log.Warnln("[TUN] default interface changed by monitor, %s => %s", old, targetInterface)
|
||||||
|
|
||||||
|
@ -163,7 +166,11 @@ func New(options config.Tun, tcpIn chan<- C.ConnContext, udpIn chan<- *inbound.P
|
||||||
iface.FlushCache()
|
iface.FlushCache()
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
})
|
})
|
||||||
|
}
|
||||||
err = defaultInterfaceMonitor.Start()
|
err = defaultInterfaceMonitor.Start()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = E.Cause(err, "start DefaultInterfaceMonitor")
|
err = E.Cause(err, "start DefaultInterfaceMonitor")
|
||||||
|
|
Loading…
Reference in a new issue