aboutsummaryrefslogtreecommitdiff
path: root/plugin/backend_lookup.go
diff options
context:
space:
mode:
authorGravatar Miek Gieben <miek@miek.nl> 2018-04-28 10:03:35 +0100
committerGravatar GitHub <noreply@github.com> 2018-04-28 10:03:35 +0100
commitc0590e4ec4537f9c26e04ea68d310324b3225c59 (patch)
treee316feab71a70e2b88b90a13a75d677d4f106f24 /plugin/backend_lookup.go
parent82d3195f2f593898b6869b0da6c436af3a93665a (diff)
downloadcoredns-c0590e4ec4537f9c26e04ea68d310324b3225c59.tar.gz
coredns-c0590e4ec4537f9c26e04ea68d310324b3225c59.tar.zst
coredns-c0590e4ec4537f9c26e04ea68d310324b3225c59.zip
plugin/etcd: small refactor (#1749)
* plugin/etcd: small refactor I think this function can be smaller. * and make it compile
Diffstat (limited to 'plugin/backend_lookup.go')
-rw-r--r--plugin/backend_lookup.go47
1 files changed, 18 insertions, 29 deletions
diff --git a/plugin/backend_lookup.go b/plugin/backend_lookup.go
index 1860ad8ff..07b147d3f 100644
--- a/plugin/backend_lookup.go
+++ b/plugin/backend_lookup.go
@@ -14,7 +14,7 @@ import (
// A returns A records from Backend or an error.
func A(b ServiceBackend, zone string, state request.Request, previousRecords []dns.RR, opt Options) (records []dns.RR, err error) {
- services, err := checkZoneForRecord(b, zone, state, opt)
+ services, err := checkForApex(b, zone, state, opt)
if err != nil {
return nil, err
}
@@ -78,7 +78,7 @@ func A(b ServiceBackend, zone string, state request.Request, previousRecords []d
// AAAA returns AAAA records from Backend or an error.
func AAAA(b ServiceBackend, zone string, state request.Request, previousRecords []dns.RR, opt Options) (records []dns.RR, err error) {
- services, err := checkZoneForRecord(b, zone, state, opt)
+ services, err := checkForApex(b, zone, state, opt)
if err != nil {
return nil, err
}
@@ -403,37 +403,26 @@ func newAddress(s msg.Service, name string, ip net.IP, what uint16) dns.RR {
return &dns.AAAA{Hdr: hdr, AAAA: ip}
}
-func checkZoneForRecord(b ServiceBackend, zone string, state request.Request, opt Options) ([]msg.Service, error) {
- var services []msg.Service
- var err error
- // if the zone name itself is queried we fake the query to search for a special entry
- // this is equivalent to the NS search code
- if state.Name() == zone {
- old := state.QName()
- state.Clear()
- state.Req.Question[0].Name = dnsutil.Join([]string{"apex.dns", zone})
-
- services, err = b.Services(state, false, opt)
- if err != nil {
- // it might be possible, that "apex.dns.zone" does not exists
- // we set back the query and try it once again to restore the backward compatibility behavior
- state.Req.Question[0].Name = old
- services, err = b.Services(state, false, opt)
- // if it still errors, we return the error
- if err != nil {
- return services, err
- }
- }
+// checkForApex checks the spcecial apex.dns directory for records that will be returned as A or AAAA.
+func checkForApex(b ServiceBackend, zone string, state request.Request, opt Options) ([]msg.Service, error) {
+ if state.Name() != zone {
+ return b.Services(state, false, opt)
+ }
+ // If the zone name itself is queried we fake the query to search for a special entry
+ // this is equivalent to the NS search code.
+ old := state.QName()
+ state.Clear()
+ state.Req.Question[0].Name = dnsutil.Join([]string{"apex.dns", zone})
+
+ services, err := b.Services(state, false, opt)
+ if err == nil {
state.Req.Question[0].Name = old
- } else {
- services, err = b.Services(state, false, opt)
- if err != nil {
- return services, err
- }
+ return services, err
}
- return services, err
+ state.Req.Question[0].Name = old
+ return b.Services(state, false, opt)
}
const hostmaster = "hostmaster"