aboutsummaryrefslogtreecommitdiff
path: root/middleware/etcd/stub.go
diff options
context:
space:
mode:
authorGravatar Miek Gieben <miek@miek.nl> 2016-04-12 21:30:08 +0100
committerGravatar Miek Gieben <miek@miek.nl> 2016-04-12 21:30:08 +0100
commit27ff83e70f554314b8162d2a3d29d26023e7bd6c (patch)
treee08c28d4d5abbb607c335c74f117094116743f97 /middleware/etcd/stub.go
parent9f651a397baabcd7d1876771f8568e14d7b4b6ef (diff)
downloadcoredns-27ff83e70f554314b8162d2a3d29d26023e7bd6c.tar.gz
coredns-27ff83e70f554314b8162d2a3d29d26023e7bd6c.tar.zst
coredns-27ff83e70f554314b8162d2a3d29d26023e7bd6c.zip
Stub forward/proxy tests (#108)
Test the handling of EDNS0 payloads and forwarding to stubzones servers.
Diffstat (limited to 'middleware/etcd/stub.go')
-rw-r--r--middleware/etcd/stub.go64
1 files changed, 33 insertions, 31 deletions
diff --git a/middleware/etcd/stub.go b/middleware/etcd/stub.go
index 849bafa5b..83611b896 100644
--- a/middleware/etcd/stub.go
+++ b/middleware/etcd/stub.go
@@ -1,6 +1,7 @@
package etcd
import (
+ "log"
"net"
"strconv"
"strings"
@@ -23,46 +24,47 @@ func (e Etcd) UpdateStubZones() {
// Look in .../dns/stub/<zone>/xx for msg.Services. Loop through them
// extract <zone> and add them as forwarders (ip:port-combos) for
// the stub zones. Only numeric (i.e. IP address) hosts are used.
-func (e Etcd) updateStubZones() {
+// Only the first zone configured on e is used for the lookup.
+func (e *Etcd) updateStubZones() {
+ zone := e.Zones[0]
+ services, err := e.Records(stubDomain+"."+zone, false)
+ if err != nil {
+ return
+ }
+
stubmap := make(map[string]proxy.Proxy)
- for _, zone := range e.Zones {
- services, err := e.Records(stubDomain+"."+zone, false)
- if err != nil {
+ // track the nameservers on a per domain basis, but allow a list on the domain.
+ nameservers := map[string][]string{}
+
+ for _, serv := range services {
+ if serv.Port == 0 {
+ serv.Port = 53
+ }
+ ip := net.ParseIP(serv.Host)
+ if ip == nil {
+ log.Printf("[WARNING] Non IP address stub nameserver: %s", serv.Host)
continue
}
- // track the nameservers on a per domain basis, but allow a list on the domain.
- nameservers := map[string][]string{}
+ domain := e.Domain(serv.Key)
+ labels := dns.SplitDomainName(domain)
- for _, serv := range services {
- if serv.Port == 0 {
- serv.Port = 53
- }
- ip := net.ParseIP(serv.Host)
- if ip == nil {
+ // If the remaining name equals any of the zones we have, we ignore it.
+ for _, z := range e.Zones {
+ // Chop of left most label, because that is used as the nameserver place holder
+ // and drop the right most labels that belong to zone.
+ // We must *also* chop of dns.stub. which means cutting two more labels.
+ domain = dns.Fqdn(strings.Join(labels[1:len(labels)-dns.CountLabel(z)-2], "."))
+ if domain == z {
+ log.Printf("[WARNING] Skipping nameserver for domain we are authoritative for: %s", domain)
continue
}
-
- domain := e.Domain(serv.Key)
- labels := dns.SplitDomainName(domain)
- // nameserver need to be tracked by domain and *then* added
-
- // If the remaining name equals any of the zones we have, we ignore it.
- for _, z := range e.Zones {
- // Chop of left most label, because that is used as the nameserver place holder
- // and drop the right most labels that belong to zone.
- domain = dns.Fqdn(strings.Join(labels[1:len(labels)-dns.CountLabel(z)], "."))
- if domain == z {
- continue
- }
- nameservers[domain] = append(nameservers[domain], net.JoinHostPort(serv.Host, strconv.Itoa(serv.Port)))
- }
- }
- for domain, nss := range nameservers {
- stubmap[domain] = proxy.New(nss)
+ nameservers[domain] = append(nameservers[domain], net.JoinHostPort(serv.Host, strconv.Itoa(serv.Port)))
}
}
-
+ for domain, nss := range nameservers {
+ stubmap[domain] = proxy.New(nss)
+ }
// atomic swap (at least that's what we hope it is)
if len(stubmap) > 0 {
e.Stubmap = &stubmap