mirror of
https://github.com/coredns/coredns.git
synced 2025-10-28 16:54:15 -04:00
plugin/file: fix wildcard CNAME answer (#4828)
* plugin/file: fix wildcard CNAME answer Signed-off-by: Yoshida <ykhr53@yokohei.com> * plugin/file: fix synthesized CNAME answer Signed-off-by: Yoshida <ykhr53@yokohei.com>
This commit is contained in:
@@ -115,8 +115,21 @@ func (z *Zone) Lookup(ctx context.Context, state request.Request, qname string)
|
|||||||
// Only one DNAME is allowed per name. We just pick the first one to synthesize from.
|
// Only one DNAME is allowed per name. We just pick the first one to synthesize from.
|
||||||
dname := dnamerrs[0]
|
dname := dnamerrs[0]
|
||||||
if cname := synthesizeCNAME(state.Name(), dname.(*dns.DNAME)); cname != nil {
|
if cname := synthesizeCNAME(state.Name(), dname.(*dns.DNAME)); cname != nil {
|
||||||
|
var (
|
||||||
|
answer, ns, extra []dns.RR
|
||||||
|
rcode Result
|
||||||
|
)
|
||||||
|
|
||||||
|
// We don't need to chase CNAME chain for synthesized CNAME
|
||||||
|
if qtype == dns.TypeCNAME {
|
||||||
|
answer = []dns.RR{cname}
|
||||||
|
ns = ap.ns(do)
|
||||||
|
extra = nil
|
||||||
|
rcode = Success
|
||||||
|
} else {
|
||||||
ctx = context.WithValue(ctx, dnsserver.LoopKey{}, loop+1)
|
ctx = context.WithValue(ctx, dnsserver.LoopKey{}, loop+1)
|
||||||
answer, ns, extra, rcode := z.externalLookup(ctx, state, elem, []dns.RR{cname})
|
answer, ns, extra, rcode = z.externalLookup(ctx, state, elem, []dns.RR{cname})
|
||||||
|
}
|
||||||
|
|
||||||
if do {
|
if do {
|
||||||
sigs := elem.Type(dns.TypeRRSIG)
|
sigs := elem.Type(dns.TypeRRSIG)
|
||||||
@@ -203,7 +216,7 @@ func (z *Zone) Lookup(ctx context.Context, state request.Request, qname string)
|
|||||||
if wildElem != nil {
|
if wildElem != nil {
|
||||||
auth := ap.ns(do)
|
auth := ap.ns(do)
|
||||||
|
|
||||||
if rrs := wildElem.TypeForWildcard(dns.TypeCNAME, qname); len(rrs) > 0 {
|
if rrs := wildElem.TypeForWildcard(dns.TypeCNAME, qname); len(rrs) > 0 && qtype != dns.TypeCNAME {
|
||||||
ctx = context.WithValue(ctx, dnsserver.LoopKey{}, loop+1)
|
ctx = context.WithValue(ctx, dnsserver.LoopKey{}, loop+1)
|
||||||
return z.externalLookup(ctx, state, wildElem, rrs)
|
return z.externalLookup(ctx, state, wildElem, rrs)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -95,6 +95,28 @@ var dnsTestCases = []test.Case{
|
|||||||
},
|
},
|
||||||
Ns: miekAuth,
|
Ns: miekAuth,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
Qname: "asterisk.x.miek.nl.", Qtype: dns.TypeCNAME,
|
||||||
|
Answer: []dns.RR{
|
||||||
|
test.CNAME("asterisk.x.miek.nl. 1800 IN CNAME www.miek.nl."),
|
||||||
|
},
|
||||||
|
Ns: miekAuth,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Qname: "asterisk.y.miek.nl.", Qtype: dns.TypeA,
|
||||||
|
Answer: []dns.RR{
|
||||||
|
test.A("asterisk.y.miek.nl. 1800 IN A 139.162.196.78"),
|
||||||
|
},
|
||||||
|
Ns: miekAuth,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Qname: "foo.dname.miek.nl.", Qtype: dns.TypeCNAME,
|
||||||
|
Answer: []dns.RR{
|
||||||
|
test.DNAME("dname.miek.nl. 1800 IN DNAME x.miek.nl."),
|
||||||
|
test.CNAME("foo.dname.miek.nl. 1800 IN CNAME foo.x.miek.nl."),
|
||||||
|
},
|
||||||
|
Ns: miekAuth,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -191,6 +213,9 @@ a IN A 139.162.196.78
|
|||||||
IN AAAA 2a01:7e00::f03c:91ff:fef1:6735
|
IN AAAA 2a01:7e00::f03c:91ff:fef1:6735
|
||||||
www IN CNAME a
|
www IN CNAME a
|
||||||
archive IN CNAME a
|
archive IN CNAME a
|
||||||
|
*.x IN CNAME www
|
||||||
|
*.y IN A 139.162.196.78
|
||||||
|
dname IN DNAME x
|
||||||
|
|
||||||
srv IN SRV 10 10 8080 a.miek.nl.
|
srv IN SRV 10 10 8080 a.miek.nl.
|
||||||
mx IN MX 10 a.miek.nl.`
|
mx IN MX 10 a.miek.nl.`
|
||||||
|
|||||||
Reference in New Issue
Block a user