mirror of
https://github.com/coredns/coredns.git
synced 2025-10-27 08:14:18 -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:
@@ -106,7 +106,7 @@ func (z *Zone) Lookup(state request.Request, qname string) ([]dns.RR, []dns.RR,
|
||||
// Only one DNAME is allowed per name. We just pick the first one to synthesize from.
|
||||
dname := dnamerrs[0]
|
||||
if cname := synthesizeCNAME(state.Name(), dname.(*dns.DNAME)); cname != nil {
|
||||
answer, ns, extra, rcode := z.searchCNAME(state, elem, []dns.RR{cname})
|
||||
answer, ns, extra, rcode := z.additionalProcessing(state, elem, []dns.RR{cname})
|
||||
|
||||
if do {
|
||||
sigs := elem.Types(dns.TypeRRSIG)
|
||||
@@ -157,7 +157,7 @@ func (z *Zone) Lookup(state request.Request, qname string) ([]dns.RR, []dns.RR,
|
||||
if found && shot {
|
||||
|
||||
if rrs := elem.Types(dns.TypeCNAME); len(rrs) > 0 && qtype != dns.TypeCNAME {
|
||||
return z.searchCNAME(state, elem, rrs)
|
||||
return z.additionalProcessing(state, elem, rrs)
|
||||
}
|
||||
|
||||
rrs := elem.Types(qtype, qname)
|
||||
@@ -193,7 +193,7 @@ func (z *Zone) Lookup(state request.Request, qname string) ([]dns.RR, []dns.RR,
|
||||
auth := z.ns(do)
|
||||
|
||||
if rrs := wildElem.Types(dns.TypeCNAME, qname); len(rrs) > 0 {
|
||||
return z.searchCNAME(state, wildElem, rrs)
|
||||
return z.additionalProcessing(state, wildElem, rrs)
|
||||
}
|
||||
|
||||
rrs := wildElem.Types(qtype, qname)
|
||||
@@ -295,8 +295,8 @@ func (z *Zone) ns(do bool) []dns.RR {
|
||||
return z.Apex.NS
|
||||
}
|
||||
|
||||
// TODO(miek): should be better named, like aditionalProcessing?
|
||||
func (z *Zone) searchCNAME(state request.Request, elem *tree.Elem, rrs []dns.RR) ([]dns.RR, []dns.RR, []dns.RR, Result) {
|
||||
// aditionalProcessing adds signatures and tries to resolve CNAMEs that point to external names.
|
||||
func (z *Zone) additionalProcessing(state request.Request, elem *tree.Elem, rrs []dns.RR) ([]dns.RR, []dns.RR, []dns.RR, Result) {
|
||||
|
||||
qtype := state.QType()
|
||||
do := state.Do()
|
||||
@@ -312,9 +312,7 @@ func (z *Zone) searchCNAME(state request.Request, elem *tree.Elem, rrs []dns.RR)
|
||||
targetName := rrs[0].(*dns.CNAME).Target
|
||||
elem, _ = z.Tree.Search(targetName)
|
||||
if elem == nil {
|
||||
if !dns.IsSubDomain(z.origin, targetName) {
|
||||
rrs = append(rrs, z.externalLookup(state, targetName, qtype)...)
|
||||
}
|
||||
rrs = append(rrs, z.externalLookup(state, targetName, qtype)...)
|
||||
return rrs, z.ns(do), nil, Success
|
||||
}
|
||||
|
||||
@@ -335,11 +333,7 @@ Redo:
|
||||
targetName := cname[0].(*dns.CNAME).Target
|
||||
elem, _ = z.Tree.Search(targetName)
|
||||
if elem == nil {
|
||||
if !dns.IsSubDomain(z.origin, targetName) {
|
||||
if !dns.IsSubDomain(z.origin, targetName) {
|
||||
rrs = append(rrs, z.externalLookup(state, targetName, qtype)...)
|
||||
}
|
||||
}
|
||||
rrs = append(rrs, z.externalLookup(state, targetName, qtype)...)
|
||||
return rrs, z.ns(do), nil, Success
|
||||
}
|
||||
|
||||
@@ -380,7 +374,10 @@ func cnameForType(targets []dns.RR, origQtype uint16) []dns.RR {
|
||||
func (z *Zone) externalLookup(state request.Request, target string, qtype uint16) []dns.RR {
|
||||
m, e := z.Upstream.Lookup(state, target, qtype)
|
||||
if e != nil {
|
||||
// TODO(miek): debugMsg for this as well? Log?
|
||||
// TODO(miek): Log, or return error here?
|
||||
return nil
|
||||
}
|
||||
if m == nil {
|
||||
return nil
|
||||
}
|
||||
return m.Answer
|
||||
|
||||
Reference in New Issue
Block a user