diff options
author | 2016-04-12 21:30:08 +0100 | |
---|---|---|
committer | 2016-04-12 21:30:08 +0100 | |
commit | 27ff83e70f554314b8162d2a3d29d26023e7bd6c (patch) | |
tree | e08c28d4d5abbb607c335c74f117094116743f97 /middleware/etcd/stub_handler.go | |
parent | 9f651a397baabcd7d1876771f8568e14d7b4b6ef (diff) | |
download | coredns-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_handler.go')
-rw-r--r-- | middleware/etcd/stub_handler.go | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/middleware/etcd/stub_handler.go b/middleware/etcd/stub_handler.go index 44a2f9ce8..4c00e82ee 100644 --- a/middleware/etcd/stub_handler.go +++ b/middleware/etcd/stub_handler.go @@ -1,7 +1,10 @@ package etcd import ( + "log" + "github.com/miekg/coredns/middleware" + "github.com/miekg/dns" "golang.org/x/net/context" ) @@ -14,8 +17,8 @@ type Stub struct { func (s Stub) ServeDNS(ctx context.Context, w dns.ResponseWriter, req *dns.Msg) (int, error) { if hasStubEdns0(req) { - // TODO(miek): actual error here - return dns.RcodeServerFailure, nil + log.Printf("[WARNING] Forwarding cycle detected, refusing msg: %s", req.Question[0].Name) + return dns.RcodeRefused, nil } req = addStubEdns0(req) proxy, ok := (*s.Etcd.Stubmap)[s.Zone] @@ -55,9 +58,10 @@ func addStubEdns0(m *dns.Msg) *dns.Msg { // Add a custom EDNS0 option to the packet, so we can detect loops when 2 stubs are forwarding to each other. if option != nil { option.Option = append(option.Option, &dns.EDNS0_LOCAL{ednsStubCode, []byte{1}}) - } else { - m.Extra = append(m.Extra, ednsStub) + return m } + + m.Extra = append(m.Extra, ednsStub) return m } @@ -70,6 +74,7 @@ var ednsStub = func() *dns.OPT { o := new(dns.OPT) o.Hdr.Name = "." o.Hdr.Rrtype = dns.TypeOPT + o.SetUDPSize(4096) e := new(dns.EDNS0_LOCAL) e.Code = ednsStubCode |