aboutsummaryrefslogtreecommitdiff
path: root/plugin
diff options
context:
space:
mode:
Diffstat (limited to 'plugin')
-rw-r--r--plugin/backend_lookup.go5
-rw-r--r--plugin/file/lookup.go25
-rw-r--r--plugin/pkg/upstream/upstream.go17
-rw-r--r--plugin/secondary/setup.go2
4 files changed, 23 insertions, 26 deletions
diff --git a/plugin/backend_lookup.go b/plugin/backend_lookup.go
index 33d1846a8..7ae6f8cce 100644
--- a/plugin/backend_lookup.go
+++ b/plugin/backend_lookup.go
@@ -122,12 +122,9 @@ func AAAA(b ServiceBackend, zone string, state request.Request, previousRecords
}
continue
}
+
// This means we can not complete the CNAME, try to look else where.
target := newRecord.Target
- if dns.IsSubDomain(zone, target) {
- // We should already have found it
- continue
- }
m1, e1 := b.Lookup(state, target, state.QType())
if e1 != nil {
continue
diff --git a/plugin/file/lookup.go b/plugin/file/lookup.go
index 943b1d52f..31248f314 100644
--- a/plugin/file/lookup.go
+++ b/plugin/file/lookup.go
@@ -106,7 +106,7 @@ func (z *Zone) Lookup(state request.Request, qname string) ([]dns.RR, []dns.RR,
// Only one DNAME is allowed per name. We just pick the first one to synthesize from.
dname := dnamerrs[0]
if cname := synthesizeCNAME(state.Name(), dname.(*dns.DNAME)); cname != nil {
- answer, ns, extra, rcode := z.searchCNAME(state, elem, []dns.RR{cname})
+ answer, ns, extra, rcode := z.additionalProcessing(state, elem, []dns.RR{cname})
if do {
sigs := elem.Types(dns.TypeRRSIG)
@@ -157,7 +157,7 @@ func (z *Zone) Lookup(state request.Request, qname string) ([]dns.RR, []dns.RR,
if found && shot {
if rrs := elem.Types(dns.TypeCNAME); len(rrs) > 0 && qtype != dns.TypeCNAME {
- return z.searchCNAME(state, elem, rrs)
+ return z.additionalProcessing(state, elem, rrs)
}
rrs := elem.Types(qtype, qname)
@@ -193,7 +193,7 @@ func (z *Zone) Lookup(state request.Request, qname string) ([]dns.RR, []dns.RR,
auth := z.ns(do)
if rrs := wildElem.Types(dns.TypeCNAME, qname); len(rrs) > 0 {
- return z.searchCNAME(state, wildElem, rrs)
+ return z.additionalProcessing(state, wildElem, rrs)
}
rrs := wildElem.Types(qtype, qname)
@@ -295,8 +295,8 @@ func (z *Zone) ns(do bool) []dns.RR {
return z.Apex.NS
}
-// TODO(miek): should be better named, like aditionalProcessing?
-func (z *Zone) searchCNAME(state request.Request, elem *tree.Elem, rrs []dns.RR) ([]dns.RR, []dns.RR, []dns.RR, Result) {
+// aditionalProcessing adds signatures and tries to resolve CNAMEs that point to external names.
+func (z *Zone) additionalProcessing(state request.Request, elem *tree.Elem, rrs []dns.RR) ([]dns.RR, []dns.RR, []dns.RR, Result) {
qtype := state.QType()
do := state.Do()
@@ -312,9 +312,7 @@ func (z *Zone) searchCNAME(state request.Request, elem *tree.Elem, rrs []dns.RR)
targetName := rrs[0].(*dns.CNAME).Target
elem, _ = z.Tree.Search(targetName)
if elem == nil {
- if !dns.IsSubDomain(z.origin, targetName) {
- rrs = append(rrs, z.externalLookup(state, targetName, qtype)...)
- }
+ rrs = append(rrs, z.externalLookup(state, targetName, qtype)...)
return rrs, z.ns(do), nil, Success
}
@@ -335,11 +333,7 @@ Redo:
targetName := cname[0].(*dns.CNAME).Target
elem, _ = z.Tree.Search(targetName)
if elem == nil {
- if !dns.IsSubDomain(z.origin, targetName) {
- if !dns.IsSubDomain(z.origin, targetName) {
- rrs = append(rrs, z.externalLookup(state, targetName, qtype)...)
- }
- }
+ rrs = append(rrs, z.externalLookup(state, targetName, qtype)...)
return rrs, z.ns(do), nil, Success
}
@@ -380,7 +374,10 @@ func cnameForType(targets []dns.RR, origQtype uint16) []dns.RR {
func (z *Zone) externalLookup(state request.Request, target string, qtype uint16) []dns.RR {
m, e := z.Upstream.Lookup(state, target, qtype)
if e != nil {
- // TODO(miek): debugMsg for this as well? Log?
+ // TODO(miek): Log, or return error here?
+ return nil
+ }
+ if m == nil {
return nil
}
return m.Answer
diff --git a/plugin/pkg/upstream/upstream.go b/plugin/pkg/upstream/upstream.go
index fc85d3f5c..6ef131755 100644
--- a/plugin/pkg/upstream/upstream.go
+++ b/plugin/pkg/upstream/upstream.go
@@ -18,7 +18,8 @@ type Upstream struct {
Forward *proxy.Proxy
}
-// NewUpstream creates a new Upstream for given destination(s)
+// NewUpstream creates a new Upstream for given destination(s). If dests is empty
+// it default to upstreaming to Self.
func NewUpstream(dests []string) (Upstream, error) {
u := Upstream{}
if len(dests) == 0 {
@@ -35,21 +36,23 @@ func NewUpstream(dests []string) (Upstream, error) {
return u, nil
}
-// Lookup routes lookups to Self or Forward
+// Lookup routes lookups to our selves or forward to a remote.
func (u Upstream) Lookup(state request.Request, name string, typ uint16) (*dns.Msg, error) {
if u.self {
- // lookup via self
req := new(dns.Msg)
req.SetQuestion(name, typ)
- state.SizeAndDo(req)
+
nw := nonwriter.New(state.W)
- state2 := request.Request{W: nw, Req: req}
server := state.Context.Value(dnsserver.Key{}).(*dnsserver.Server)
- server.ServeDNS(state.Context, state2.W, req)
+
+ server.ServeDNS(state.Context, nw, req)
+
return nw.Msg, nil
}
+
if u.Forward != nil {
return u.Forward.Lookup(state, name, typ)
}
- return &dns.Msg{}, nil
+
+ return nil, nil
}
diff --git a/plugin/secondary/setup.go b/plugin/secondary/setup.go
index 1ccc09648..90c3a3dc5 100644
--- a/plugin/secondary/setup.go
+++ b/plugin/secondary/setup.go
@@ -5,8 +5,8 @@ import (
"github.com/coredns/coredns/plugin"
"github.com/coredns/coredns/plugin/file"
"github.com/coredns/coredns/plugin/pkg/parse"
-
"github.com/coredns/coredns/plugin/pkg/upstream"
+
"github.com/mholt/caddy"
)