From 9af6d498e77aa98acfb0a0ba90deaf6f24267347 Mon Sep 17 00:00:00 2001 From: Dreamacro <8615343+Dreamacro@users.noreply.github.com> Date: Wed, 1 Feb 2023 15:19:36 +0800 Subject: [PATCH] Change: remove `redir-host` as config --- constant/dns.go | 8 ++++---- dns/middleware.go | 9 ++++++--- hub/executor/executor.go | 5 ----- 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/constant/dns.go b/constant/dns.go index eee98e5..a6f1b9c 100644 --- a/constant/dns.go +++ b/constant/dns.go @@ -3,13 +3,13 @@ package constant import ( "encoding/json" "errors" + "fmt" ) // DNSModeMapping is a mapping for EnhancedMode enum var DNSModeMapping = map[string]DNSMode{ - DNSNormal.String(): DNSNormal, - DNSFakeIP.String(): DNSFakeIP, - DNSMapping.String(): DNSMapping, + DNSNormal.String(): DNSNormal, + DNSFakeIP.String(): DNSFakeIP, } const ( @@ -28,7 +28,7 @@ func (e *DNSMode) UnmarshalYAML(unmarshal func(any) error) error { } mode, exist := DNSModeMapping[tp] if !exist { - return errors.New("invalid mode") + return fmt.Errorf("invalid mode: %s", tp) } *e = mode return nil diff --git a/dns/middleware.go b/dns/middleware.go index 9d0da59..deb8015 100644 --- a/dns/middleware.go +++ b/dns/middleware.go @@ -87,9 +87,15 @@ func withMapping(mapping *cache.LruCache) middleware { case *D.A: ip = a.A ttl = a.Hdr.Ttl + if !ip.IsGlobalUnicast() { + continue + } case *D.AAAA: ip = a.AAAA ttl = a.Hdr.Ttl + if !ip.IsGlobalUnicast() { + continue + } default: continue } @@ -181,9 +187,6 @@ func newHandler(resolver *Resolver, mapper *ResolverEnhancer) handler { if mapper.mode == C.DNSFakeIP { middlewares = append(middlewares, withFakeIP(mapper.fakePool)) - } - - if mapper.mode != C.DNSNormal { middlewares = append(middlewares, withMapping(mapper.mapping)) } diff --git a/hub/executor/executor.go b/hub/executor/executor.go index 8f94bc7..447bfcd 100644 --- a/hub/executor/executor.go +++ b/hub/executor/executor.go @@ -133,11 +133,6 @@ func updateDNS(c *config.DNS) { Policy: c.NameServerPolicy, } - // deprecated warnning - if cfg.EnhancedMode == C.DNSMapping { - log.Warnln("[DNS] %s is deprecated, please use %s instead", cfg.EnhancedMode.String(), C.DNSFakeIP.String()) - } - r := dns.NewResolver(cfg) m := dns.NewEnhancer(cfg)