Skip to content

Commit

Permalink
use upstream pkg
Browse files Browse the repository at this point in the history
  • Loading branch information
fuhry committed Mar 14, 2023
1 parent 8c87240 commit 17d8eb8
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions records.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
}

0 comments on commit 17d8eb8

Please sign in to comment.