diff options
author | 2018-06-12 14:54:37 +0100 | |
---|---|---|
committer | 2018-06-12 14:54:37 +0100 | |
commit | 26c41a0c177fbe89f1f81214634aed49790581f4 (patch) | |
tree | 7e957105a4256d875c4985a75a3c9fb92b49234d /plugin/pkg | |
parent | 6e466d509281953fdf0209a5b50611e89b4689ae (diff) | |
download | coredns-26c41a0c177fbe89f1f81214634aed49790581f4.tar.gz coredns-26c41a0c177fbe89f1f81214634aed49790581f4.tar.zst coredns-26c41a0c177fbe89f1f81214634aed49790581f4.zip |
plugin/file: fix local CNAME lookup (#1866)
* plugin/file: fix local CNAME lookup
Issue #1864 explains it will, when we serve the child zone as well we
should just recursive into ourself (upstream self). Thus relax the
IsSubDomain check in file/lookup.go and just query (even if the query
will hit a remote server).
I've looped over all other plugins that do something similar (CNAME
resolving) and they didn't do the IsSubDomain check; therefor I've
removed it from *file* as well.
Added test in file_upstream_test that shows this failed before but now
results in a reply.
Fixes #1864
* self does not need to be exported
* Fix test
We don't know if we had a valid reply. Check this.
Diffstat (limited to 'plugin/pkg')
-rw-r--r-- | plugin/pkg/upstream/upstream.go | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/plugin/pkg/upstream/upstream.go b/plugin/pkg/upstream/upstream.go index fc85d3f5c..6ef131755 100644 --- a/plugin/pkg/upstream/upstream.go +++ b/plugin/pkg/upstream/upstream.go @@ -18,7 +18,8 @@ type Upstream struct { Forward *proxy.Proxy } -// NewUpstream creates a new Upstream for given destination(s) +// NewUpstream creates a new Upstream for given destination(s). If dests is empty +// it default to upstreaming to Self. func NewUpstream(dests []string) (Upstream, error) { u := Upstream{} if len(dests) == 0 { @@ -35,21 +36,23 @@ func NewUpstream(dests []string) (Upstream, error) { return u, nil } -// Lookup routes lookups to Self or Forward +// Lookup routes lookups to our selves or forward to a remote. func (u Upstream) Lookup(state request.Request, name string, typ uint16) (*dns.Msg, error) { if u.self { - // lookup via self req := new(dns.Msg) req.SetQuestion(name, typ) - state.SizeAndDo(req) + nw := nonwriter.New(state.W) - state2 := request.Request{W: nw, Req: req} server := state.Context.Value(dnsserver.Key{}).(*dnsserver.Server) - server.ServeDNS(state.Context, state2.W, req) + + server.ServeDNS(state.Context, nw, req) + return nw.Msg, nil } + if u.Forward != nil { return u.Forward.Lookup(state, name, typ) } - return &dns.Msg{}, nil + + return nil, nil } |