mirror of
https://github.com/coredns/coredns.git
synced 2025-11-01 18:53:43 -04:00
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.
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user