mirror of
https://github.com/coredns/coredns.git
synced 2025-11-01 02:33:14 -04:00
Implement external lookups for CNAMEs
This commit is contained in:
@@ -25,7 +25,11 @@ const (
|
||||
|
||||
// Lookup looks up qname and qtype in the zone. When do is true DNSSEC records are included.
|
||||
// Three sets of records are returned, one for the answer, one for authority and one for the additional section.
|
||||
func (z *Zone) Lookup(qname string, qtype uint16, do bool) ([]dns.RR, []dns.RR, []dns.RR, Result) {
|
||||
func (z *Zone) Lookup(state request.Request, qname string) ([]dns.RR, []dns.RR, []dns.RR, Result) {
|
||||
|
||||
qtype := state.QType()
|
||||
do := state.Do()
|
||||
|
||||
if !z.NoReload {
|
||||
z.reloadMu.RLock()
|
||||
}
|
||||
@@ -121,7 +125,7 @@ func (z *Zone) Lookup(qname string, qtype uint16, do bool) ([]dns.RR, []dns.RR,
|
||||
|
||||
// DNAME...?
|
||||
if rrs := elem.Types(dns.TypeCNAME); len(rrs) > 0 && qtype != dns.TypeCNAME {
|
||||
return z.searchCNAME(elem, rrs, qtype, do)
|
||||
return z.searchCNAME(state, elem, rrs)
|
||||
}
|
||||
|
||||
rrs := elem.Types(qtype, qname)
|
||||
@@ -153,7 +157,7 @@ func (z *Zone) Lookup(qname string, qtype uint16, do bool) ([]dns.RR, []dns.RR,
|
||||
auth := []dns.RR{}
|
||||
|
||||
if rrs := wildElem.Types(dns.TypeCNAME, qname); len(rrs) > 0 {
|
||||
return z.searchCNAME(wildElem, rrs, qtype, do)
|
||||
return z.searchCNAME(state, wildElem, rrs)
|
||||
}
|
||||
|
||||
rrs := wildElem.Types(qtype, qname)
|
||||
@@ -252,7 +256,11 @@ func (z *Zone) ns(do bool) []dns.RR {
|
||||
return z.Apex.NS
|
||||
}
|
||||
|
||||
func (z *Zone) searchCNAME(elem *tree.Elem, rrs []dns.RR, qtype uint16, do bool) ([]dns.RR, []dns.RR, []dns.RR, Result) {
|
||||
func (z *Zone) searchCNAME(state request.Request, elem *tree.Elem, rrs []dns.RR) ([]dns.RR, []dns.RR, []dns.RR, Result) {
|
||||
|
||||
qtype := state.QType()
|
||||
do := state.Do()
|
||||
|
||||
if do {
|
||||
sigs := elem.Types(dns.TypeRRSIG)
|
||||
sigs = signatureForSubType(sigs, dns.TypeCNAME)
|
||||
@@ -263,14 +271,10 @@ func (z *Zone) searchCNAME(elem *tree.Elem, rrs []dns.RR, qtype uint16, do bool)
|
||||
|
||||
targetName := rrs[0].(*dns.CNAME).Target
|
||||
elem, _ = z.Tree.Search(targetName)
|
||||
println(targetName)
|
||||
if elem == nil {
|
||||
if !dns.IsSubDomain(z.origin, targetName) {
|
||||
println(targetName, "is not a child of", z.origin)
|
||||
rrs = append(rrs, z.externalLookup(state, targetName, qtype)...)
|
||||
}
|
||||
st := request.Request{}
|
||||
z.Proxy.Lookup(st, targetName, qtype)
|
||||
|
||||
return rrs, nil, nil, Success
|
||||
}
|
||||
|
||||
@@ -292,7 +296,9 @@ Redo:
|
||||
elem, _ = z.Tree.Search(targetName)
|
||||
if elem == nil {
|
||||
if !dns.IsSubDomain(z.origin, targetName) {
|
||||
println(targetName, "is not a child of", z.origin)
|
||||
if !dns.IsSubDomain(z.origin, targetName) {
|
||||
rrs = append(rrs, z.externalLookup(state, targetName, qtype)...)
|
||||
}
|
||||
}
|
||||
return rrs, nil, nil, Success
|
||||
}
|
||||
@@ -331,6 +337,15 @@ func cnameForType(targets []dns.RR, origQtype uint16) []dns.RR {
|
||||
return ret
|
||||
}
|
||||
|
||||
func (z *Zone) externalLookup(state request.Request, target string, qtype uint16) []dns.RR {
|
||||
m, e := z.Proxy.Lookup(state, target, qtype)
|
||||
if e != nil || m == nil {
|
||||
// TODO(miek): debugMsg for this as well? Log?
|
||||
return nil
|
||||
}
|
||||
return m.Answer
|
||||
}
|
||||
|
||||
// signatureForSubType range through the signature and return the correct ones for the subtype.
|
||||
func signatureForSubType(rrs []dns.RR, subtype uint16) []dns.RR {
|
||||
sigs := []dns.RR{}
|
||||
|
||||
Reference in New Issue
Block a user