From e0040b7e5d13a873ef90ab385a5bdc816e9b08d1 Mon Sep 17 00:00:00 2001 From: admin <2833154405@qq.com> Date: Mon, 21 Mar 2022 20:29:07 +0800 Subject: [PATCH] [Fix] do not monitor when auto-iptables is false --- hub/executor/executor.go | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/hub/executor/executor.go b/hub/executor/executor.go index dd62c7f2..bf4e2a1c 100644 --- a/hub/executor/executor.go +++ b/hub/executor/executor.go @@ -302,15 +302,6 @@ 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() - if runtime.GOOS != "linux" || general.TProxyPort == 0 { return } @@ -333,14 +324,23 @@ func updateIPTables(dns *config.DNS, general *config.General, tun *config.Tun) { return } + err = updateIPTables(dns, general) + go commons.DefaultInterfaceChangeMonitor(func(_ string) { + updateIPTables(dns, general) + }) +} + +func updateIPTables(dns *config.DNS, general *config.General) error { + tproxy.CleanUpTProxyLinuxIPTables() + _, dnsPortStr, err := net.SplitHostPort(dns.Listen) if dnsPortStr == "0" || dnsPortStr == "" || err != nil { - return + return err } dnsPort, err := strconv.Atoi(dnsPortStr) if err != nil { - return + return err } if dialer.DefaultRoutingMark.Load() == 0 { @@ -349,6 +349,7 @@ func updateIPTables(dns *config.DNS, general *config.General, tun *config.Tun) { if general.AutoIptables { err = tproxy.SetTProxyLinuxIPTables(dialer.DefaultInterface.Load(), general.TProxyPort, dnsPort) } + return err } func Cleanup() {