From b2605a901280e9428b75dd0db2b70ec554d3bde8 Mon Sep 17 00:00:00 2001 From: Skyxim Date: Mon, 2 May 2022 14:21:37 +0800 Subject: [PATCH] fix: tun dns --- dns/patch.go | 16 ++++++++++++++++ hub/executor/executor.go | 2 ++ 2 files changed, 18 insertions(+) create mode 100644 dns/patch.go diff --git a/dns/patch.go b/dns/patch.go new file mode 100644 index 00000000..76974243 --- /dev/null +++ b/dns/patch.go @@ -0,0 +1,16 @@ +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 04a02dc7..54faccb1 100644 --- a/hub/executor/executor.go +++ b/hub/executor/executor.go @@ -122,6 +122,7 @@ func updateDNS(c *config.DNS) { if !c.Enable { resolver.DefaultResolver = nil resolver.DefaultHostMapper = nil + resolver.DefaultLocalServer = nil dns.ReCreateServer("", nil, nil) return } @@ -158,6 +159,7 @@ func updateDNS(c *config.DNS) { resolver.DefaultResolver = r resolver.DefaultHostMapper = m + resolver.DefaultLocalServer = dns.NewLocalServer(r, m) if pr.HasProxyServer() { resolver.ProxyServerHostResolver = pr