From b6efac8d790fa9bc73a981376ac6bf86a2528ad2 Mon Sep 17 00:00:00 2001 From: gVisor bot Date: Sun, 1 May 2022 09:38:43 +0800 Subject: [PATCH] refactor: remove dns and tun relationship, the enabled of dns module should be decided by user --- dns/patch.go | 16 ---------------- hub/executor/executor.go | 28 ++++++++++------------------ 2 files changed, 10 insertions(+), 34 deletions(-) delete mode 100644 dns/patch.go diff --git a/dns/patch.go b/dns/patch.go deleted file mode 100644 index 76974243..00000000 --- a/dns/patch.go +++ /dev/null @@ -1,16 +0,0 @@ -package dns - -import D "github.com/miekg/dns" - -type LocalServer struct { - handler handler -} - -// ServeMsg implement resolver.LocalServer ResolveMsg -func (s *LocalServer) ServeMsg(msg *D.Msg) (*D.Msg, error) { - return handlerWithContext(s.handler, msg) -} - -func NewLocalServer(resolver *Resolver, mapper *ResolverEnhancer) *LocalServer { - return &LocalServer{handler: NewHandler(resolver, mapper)} -} diff --git a/hub/executor/executor.go b/hub/executor/executor.go index 565d61cd..04a02dc7 100644 --- a/hub/executor/executor.go +++ b/hub/executor/executor.go @@ -76,7 +76,7 @@ func ApplyConfig(cfg *config.Config, force bool) { updateProxies(cfg.Proxies, cfg.Providers) updateRules(cfg.Rules, cfg.RuleProviders) updateSniffer(cfg.Sniffer) - updateDNS(cfg.DNS, cfg.Tun) + updateDNS(cfg.DNS) updateGeneral(cfg.General, force) updateIPTables(cfg) updateTun(cfg.Tun, cfg.DNS) @@ -118,7 +118,14 @@ func GetGeneral() *config.General { func updateExperimental(c *config.Config) {} -func updateDNS(c *config.DNS, t *config.Tun) { +func updateDNS(c *config.DNS) { + if !c.Enable { + resolver.DefaultResolver = nil + resolver.DefaultHostMapper = nil + dns.ReCreateServer("", nil, nil) + return + } + cfg := dns.Config{ Main: c.NameServer, Fallback: c.Fallback, @@ -156,22 +163,7 @@ func updateDNS(c *config.DNS, t *config.Tun) { resolver.ProxyServerHostResolver = pr } - if t.Enable { - resolver.DefaultLocalServer = dns.NewLocalServer(r, m) - log.Infoln("DNS enable IPv6 resolve") - } - - if c.Enable { - dns.ReCreateServer(c.Listen, r, m) - } else { - if !t.Enable { - resolver.DefaultResolver = nil - resolver.DefaultHostMapper = nil - resolver.DefaultLocalServer = nil - resolver.ProxyServerHostResolver = nil - } - dns.ReCreateServer("", nil, nil) - } + dns.ReCreateServer(c.Listen, r, m) } func updateHosts(tree *trie.DomainTrie[netip.Addr]) {