44 "context"
55
66 "github.com/coredns/coredns/plugin"
7+ "github.com/coredns/coredns/plugin/pkg/upstream"
78 "github.com/coredns/coredns/request"
89
910 "github.com/miekg/dns"
@@ -13,8 +14,9 @@ const maxCnameStackDepth = 10
1314
1415// Records is the plugin handler.
1516type Records struct {
16- origins []string // for easy matching, these strings are the index in the map m.
17- m map [string ][]dns.RR
17+ origins []string // for easy matching, these strings are the index in the map m.
18+ m map [string ][]dns.RR
19+ upstream * upstream.Upstream
1820
1921 Next plugin.Handler
2022}
@@ -61,9 +63,14 @@ resolveLoop:
6163 cnameStack [qname ] = struct {}{}
6264 qname = r .(* dns.CNAME ).Target
6365 if plugin .Zones (re .origins ).Matches (qname ) == "" {
64- // if the CNAME target isn't a record in this zone, break and return.
65- // The administrator can configure the `finalize` plugin (https://coredns.io/explugins/finalize/)
66- // to complete resolution of these names.
66+ // if the CNAME target isn't a record in this zone, restart with upstream.
67+ msgs , err := re .upstream .Lookup (ctx , state , qname , state .QType ())
68+ if err != nil {
69+ return dns .RcodeServerFailure , err
70+ }
71+ for _ , ans := range msgs .Answer {
72+ m .Answer = append (m .Answer , ans )
73+ }
6774 break resolveLoop
6875 }
6976 goto resolveLoop
@@ -105,7 +112,9 @@ func (re *Records) Name() string { return "records" }
105112
106113// New returns a pointer to a new and intialized Records.
107114func New () * Records {
108- re := new (Records )
109- re .m = make (map [string ][]dns.RR )
115+ re := & Records {
116+ m : make (map [string ][]dns.RR ),
117+ upstream : upstream .New (),
118+ }
110119 return re
111120}
0 commit comments