mirror of
https://github.com/MetaCubeX/mihomo.git
synced 2024-11-16 11:42:43 +08:00
auto change interface for tproxy
This commit is contained in:
parent
652759a9ae
commit
e773595e33
|
@ -2,7 +2,7 @@ package executor
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/Dreamacro/clash/listener/tun/ipstack/commons"
|
||||
"net"
|
||||
"os"
|
||||
"runtime"
|
||||
|
@ -75,14 +75,14 @@ func ApplyConfig(cfg *config.Config, force bool) {
|
|||
defer mux.Unlock()
|
||||
|
||||
updateUsers(cfg.Users)
|
||||
updateHosts(cfg.Hosts)
|
||||
updateProxies(cfg.Proxies, cfg.Providers)
|
||||
updateRules(cfg.Rules, cfg.RuleProviders)
|
||||
updateGeneral(cfg.General, force)
|
||||
updateDNS(cfg.DNS, cfg.Tun)
|
||||
updateTun(cfg.Tun)
|
||||
updateIPTables(cfg.DNS, cfg.General, cfg.Tun)
|
||||
autoUpdateIPTables(cfg.DNS, cfg.General, cfg.Tun)
|
||||
updateExperimental(cfg)
|
||||
updateHosts(cfg.Hosts)
|
||||
loadProvider(cfg.RuleProviders, cfg.Providers)
|
||||
updateProfile(cfg)
|
||||
|
||||
|
@ -301,6 +301,13 @@ func patchSelectGroup(proxies map[string]C.Proxy) {
|
|||
}
|
||||
}
|
||||
|
||||
func autoUpdateIPTables(dns *config.DNS, general *config.General, tun *config.Tun) {
|
||||
updateIPTables(dns, general, tun)
|
||||
go commons.DefaultInterfaceChangeMonitor(func(_ string) {
|
||||
updateIPTables(dns, general, tun)
|
||||
})
|
||||
}
|
||||
|
||||
func updateIPTables(dns *config.DNS, general *config.General, tun *config.Tun) {
|
||||
tproxy.CleanUpTProxyLinuxIPTables()
|
||||
|
||||
|
@ -340,7 +347,7 @@ func updateIPTables(dns *config.DNS, general *config.General, tun *config.Tun) {
|
|||
dialer.DefaultRoutingMark.Store(2158)
|
||||
}
|
||||
if general.AutoIptables {
|
||||
err = tproxy.SetTProxyLinuxIPTables(general.Interface, general.TProxyPort, dnsPort)
|
||||
err = tproxy.SetTProxyLinuxIPTables(dialer.DefaultInterface.Load(), general.TProxyPort, dnsPort)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -24,7 +24,7 @@ func ipv4MaskString(bits int) string {
|
|||
return fmt.Sprintf("%d.%d.%d.%d", m[0], m[1], m[2], m[3])
|
||||
}
|
||||
|
||||
func defaultInterfaceChangeMonitor() {
|
||||
func DefaultInterfaceChangeMonitor(cb func(ifName string)) {
|
||||
t := time.NewTicker(defaultInterfaceMonitorDuration)
|
||||
defer t.Stop()
|
||||
|
||||
|
@ -43,6 +43,9 @@ func defaultInterfaceChangeMonitor() {
|
|||
}
|
||||
|
||||
dialer.DefaultInterface.Store(interfaceName)
|
||||
if cb != nil {
|
||||
cb(interfaceName)
|
||||
}
|
||||
|
||||
log.Warnln("[TUN] default interface changed by monitor, %s => %s", old, interfaceName)
|
||||
}
|
||||
|
|
|
@ -54,7 +54,7 @@ func configInterfaceRouting(interfaceName string, addr netip.Prefix) error {
|
|||
}
|
||||
}
|
||||
|
||||
go defaultInterfaceChangeMonitor()
|
||||
go DefaultInterfaceChangeMonitor(nil)
|
||||
|
||||
return execRouterCmd("add", "-inet6", "2000::/3", interfaceName)
|
||||
}
|
||||
|
|
|
@ -42,7 +42,7 @@ func configInterfaceRouting(interfaceName string, addr netip.Prefix) error {
|
|||
}
|
||||
}
|
||||
|
||||
go defaultInterfaceChangeMonitor()
|
||||
go DefaultInterfaceChangeMonitor(nil)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -203,7 +203,7 @@ startOver:
|
|||
|
||||
wintunInterfaceName = dev.Name()
|
||||
|
||||
go defaultInterfaceChangeMonitor()
|
||||
go DefaultInterfaceChangeMonitor(nil)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user