diff --git a/records.go b/records.go index 6ac41ca..eec9799 100644 --- a/records.go +++ b/records.go @@ -4,6 +4,7 @@ import ( "context" "github.com/coredns/coredns/plugin" + "github.com/coredns/coredns/plugin/pkg/upstream" "github.com/coredns/coredns/request" "github.com/miekg/dns" @@ -13,8 +14,9 @@ const maxCnameStackDepth = 10 // Records is the plugin handler. type Records struct { - origins []string // for easy matching, these strings are the index in the map m. - m map[string][]dns.RR + origins []string // for easy matching, these strings are the index in the map m. + m map[string][]dns.RR + upstream *upstream.Upstream Next plugin.Handler } @@ -61,9 +63,14 @@ resolveLoop: 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, break and return. - // The administrator can configure the `finalize` plugin (https://coredns.io/explugins/finalize/) - // to complete resolution of these names. + // 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 } goto resolveLoop @@ -105,7 +112,9 @@ func (re *Records) Name() string { return "records" } // New returns a pointer to a new and intialized Records. func New() *Records { - re := new(Records) - re.m = make(map[string][]dns.RR) + re := &Records{ + m: make(map[string][]dns.RR), + upstream: upstream.New(), + } return re }