diff --git a/service/core/dnsPoison/entity/entity.go b/service/core/dnsPoison/entity/entity.go index ba17b36f..29918944 100644 --- a/service/core/dnsPoison/entity/entity.go +++ b/service/core/dnsPoison/entity/entity.go @@ -63,6 +63,12 @@ func dnsPortValid() bool { 2: redirect + fakedns */ func ShouldDnsPoisonOpen() int { + setting := configure.GetSettingNotNil() + if setting.Transparent == configure.TransparentClose || + setting.AntiPollution == configure.AntipollutionClosed || + (global.SupportTproxy && !setting.EnhancedMode) { + return 0 + } ver, err := where.GetV2rayServiceVersion() if err != nil { ver = "0.0.0" @@ -72,20 +78,15 @@ func ShouldDnsPoisonOpen() int { fakednsValid = false } if fakednsValid && !dnsPortValid() { - log.Println("[fakedns] unable to use fakedns: port 53 is occupied") + if setting.EnhancedMode { + log.Println("[fakedns] unable to use fakedns: port 53 is occupied") + } fakednsValid = false } - if setting := configure.GetSettingNotNil(); - setting.Transparent != configure.TransparentClose && - setting.AntiPollution != configure.AntipollutionClosed && - (!global.SupportTproxy || setting.EnhancedMode) { - if fakednsValid { - return 2 - } else { - return 1 - } + if !fakednsValid { + return 1 } - return 0 + return 2 } func CheckAndSetupDnsPoisonWithExtraInfo(info *ExtraInfo) { diff --git a/service/core/v2ray/transparent.go b/service/core/v2ray/transparent.go index a5fcd27f..3d40e031 100644 --- a/service/core/v2ray/transparent.go +++ b/service/core/v2ray/transparent.go @@ -25,12 +25,6 @@ func DeleteTransparentProxyRules() { } func WriteTransparentProxyRules(preprocess *func(c *iptables.SetupCommands)) error { - if entity.ShouldDnsPoisonOpen() == 1 { - if e := iptables.DropSpoofing.GetSetupCommands().Setup(preprocess); e != nil { - log.Println(newError("[WARNING] DropSpoofing can't be enable").Base(e)) - iptables.DropSpoofing.GetCleanCommands().Clean() - } - } setting := configure.GetSettingNotNil() if global.SupportTproxy && !setting.EnhancedMode { if err := iptables.Tproxy.GetSetupCommands().Setup(preprocess); err == nil { @@ -47,6 +41,12 @@ func WriteTransparentProxyRules(preprocess *func(c *iptables.SetupCommands)) err global.SupportTproxy = false } } else { + if entity.ShouldDnsPoisonOpen() == 1 { + if e := iptables.DropSpoofing.GetSetupCommands().Setup(preprocess); e != nil { + log.Println(newError("[WARNING] DropSpoofing can't be enable").Base(e)) + iptables.DropSpoofing.GetCleanCommands().Clean() + } + } if err := iptables.Redirect.GetSetupCommands().Setup(preprocess); err == nil { if setting.AntiPollution != configure.AntipollutionClosed { resetDnsHijacker()