Skip to content
Permalink

Comparing changes

This is a direct comparison between two commits made in this repository or its related repositories. View the default comparison for this range or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: coredns/records
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 61cf6e2831165be4c8f8fc33000e9a4ab51829bd
Choose a base ref
..
head repository: coredns/records
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 1c15aaf95584ec1e841c544f7c072e632d3c0fff
Choose a head ref
Showing with 22 additions and 11 deletions.
  1. +22 −11 records.go
33 changes: 22 additions & 11 deletions records.go
Original file line number Diff line number Diff line change
@@ -37,6 +37,10 @@ func (re *Records) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Ms
m.Authoritative = true

nxdomain := true
// cnameMaybeUpstream tracks whether we are currently trying to resolve a CNAME. We always look for a match among
// the records handled by this plugin first, then we go upstream. This is required to enforce stack depth and loop
// detection.
cnameMaybeUpstream := false
var soa dns.RR
cnameStack := make(map[string]struct{}, 0)

@@ -62,18 +66,25 @@ resolveLoop:
if r.Header().Rrtype == dns.TypeCNAME {
cnameStack[qname] = struct{}{}
qname = r.(*dns.CNAME).Target
if plugin.Zones(re.origins).Matches(qname) == "" {
// if the CNAME target isn't a record in this zone, restart with upstream.
msgs, err := re.upstream.Lookup(ctx, state, qname, state.QType())
if err != nil {
return dns.RcodeServerFailure, err
}
for _, ans := range msgs.Answer {
m.Answer = append(m.Answer, ans)
}
break resolveLoop
}
cnameMaybeUpstream = true
// restart resolution with new query name
goto resolveLoop
} else {
// If we found a match but the record type in the zone we control isn't
// another CNAME, that means we have reached the end of our chain and we
// don't need to go upstream.
cnameMaybeUpstream = false
}
}
}

if cnameMaybeUpstream {
// we've found a CNAME but it doesn't point to a record managed by this
// plugin. In these cases we always restart with upstream.
msgs, err := re.upstream.Lookup(ctx, state, qname, state.QType())
if err == nil && len(msgs.Answer) > 0 {
for _, ans := range msgs.Answer {
m.Answer = append(m.Answer, ans)
}
}
}