This commit is contained in:
Maze.tsz
2021-12-04 17:41:13 +08:00
parent 58552447ef
commit 8580ee8898
5 changed files with 60 additions and 33 deletions

View File

@ -2,7 +2,11 @@ package executor
import (
"fmt"
"github.com/Dreamacro/clash/listener/tproxy"
"net"
"os"
"runtime"
"strconv"
"strings"
"sync"
@ -74,7 +78,7 @@ func ApplyConfig(cfg *config.Config, force bool) {
updateRules(cfg.Rules, cfg.RuleProviders)
updateHosts(cfg.Hosts)
updateProfile(cfg)
//updateIPTables(cfg.DNS, cfg.General)
updateIPTables(cfg.DNS, cfg.General)
updateDNS(cfg.DNS, cfg.General)
updateGeneral(cfg.General, force)
updateExperimental(cfg)
@ -284,35 +288,35 @@ func patchSelectGroup(proxies map[string]C.Proxy) {
}
}
//func updateIPTables(dns *config.DNS, general *config.General) {
// if runtime.GOOS != "linux" || dns.Listen == "" || general.TProxyPort == 0 || general.Tun.Enable {
// return
// }
//
// _, dnsPortStr, err := net.SplitHostPort(dns.Listen)
// if dnsPortStr == "0" || dnsPortStr == "" || err != nil {
// return
// }
//
// dnsPort, err := strconv.Atoi(dnsPortStr)
// if err != nil {
// return
// }
//
// tproxy.CleanUpTProxyLinuxIPTables()
//
// err = tproxy.SetTProxyLinuxIPTables(general.Interface, general.TProxyPort, dnsPort)
//
// if err != nil {
// log.Errorln("Can not setting iptables for TProxy on linux, %s", err.Error())
// os.Exit(2)
// }
//}
func updateIPTables(dns *config.DNS, general *config.General) {
if runtime.GOOS != "linux" || dns.Listen == "" || general.TProxyPort == 0 || general.Tun.Enable || C.OpenWrt {
return
}
_, dnsPortStr, err := net.SplitHostPort(dns.Listen)
if dnsPortStr == "0" || dnsPortStr == "" || err != nil {
return
}
dnsPort, err := strconv.Atoi(dnsPortStr)
if err != nil {
return
}
tproxy.CleanUpTProxyLinuxIPTables()
err = tproxy.SetTProxyLinuxIPTables(general.Interface, general.TProxyPort, dnsPort)
if err != nil {
log.Errorln("Can not setting iptables for TProxy on linux, %s", err.Error())
os.Exit(2)
}
}
func CleanUp() {
P.CleanUp()
//if runtime.GOOS == "linux" {
// tproxy.CleanUpTProxyLinuxIPTables()
//}
if runtime.GOOS == "linux" && C.OpenWrt {
tproxy.CleanUpTProxyLinuxIPTables()
}
}