diff options
-rw-r--r-- | plugin/etcd/other_test.go | 8 | ||||
-rw-r--r-- | request/request.go | 13 | ||||
-rw-r--r-- | request/request_test.go | 27 |
3 files changed, 36 insertions, 12 deletions
diff --git a/plugin/etcd/other_test.go b/plugin/etcd/other_test.go index 7e6e8febb..c873d9412 100644 --- a/plugin/etcd/other_test.go +++ b/plugin/etcd/other_test.go @@ -131,16 +131,12 @@ var dnsTestCasesOther = []test.Case{ // Large txt greater than 512 (UDP) { Qname: "large600.skydns.test.", Qtype: dns.TypeTXT, - Answer: []dns.RR{ - test.TXT(fmt.Sprintf("large600.skydns.test. 300 IN TXT \"%s\"", strings.Repeat("0", 600))), - }, + Answer: []dns.RR{}, }, // Large txt greater than 1500 (typical Ethernet) { Qname: "large2000.skydns.test.", Qtype: dns.TypeTXT, - Answer: []dns.RR{ - test.TXT(fmt.Sprintf("large2000.skydns.test. 300 IN TXT \"%s\"", strings.Repeat("0", 2000))), - }, + Answer: []dns.RR{}, }, // Duplicate IP address test { diff --git a/request/request.go b/request/request.go index 2ce2c7acc..9672edeb1 100644 --- a/request/request.go +++ b/request/request.go @@ -180,11 +180,11 @@ const ( ScrubDone ) -// Scrub scrubs the reply message so that it will fit the client's buffer. If even after dropping -// the additional section, it still does not fit the TC bit will be set on the message. Note, -// the TC bit will be set regardless of protocol, even TCP message will get the bit, the client -// should then retry with pigeons. -// TODO(referral). +// Scrub scrubs the reply message so that it will fit the client's buffer. If +// even after dropping the additional section it does not fit, the answer will +// be cleared and the TC bit will be set on the message. Note, the TC bit will +// be set regardless of protocol, even TCP message will get the bit, the client +// should then retry with pigeons. TODO(referral). func (r *Request) Scrub(reply *dns.Msg) (*dns.Msg, Result) { size := r.Size() l := reply.Len() @@ -200,8 +200,9 @@ func (r *Request) Scrub(reply *dns.Msg) (*dns.Msg, Result) { if size >= l { return reply, ScrubDone } - // Still?!! does not fit. + reply.Truncated = true + reply.Answer = nil return reply, ScrubDone } diff --git a/request/request_test.go b/request/request_test.go index 2311d89ea..49b825627 100644 --- a/request/request_test.go +++ b/request/request_test.go @@ -1,6 +1,7 @@ package request import ( + "fmt" "testing" "github.com/coredns/coredns/plugin/test" @@ -60,6 +61,32 @@ func TestRequestMalformed(t *testing.T) { } } +func TestRequestScrub(t *testing.T) { + m := new(dns.Msg) + m.SetQuestion("large.example.com.", dns.TypeSRV) + req := Request{W: &test.ResponseWriter{}, Req: m} + + reply := new(dns.Msg) + reply.SetReply(m) + for i := 1; i < 200; i++ { + reply.Answer = append(reply.Answer, test.SRV(fmt.Sprintf( + "large.example.com. 10 IN SRV 0 0 80 10-0-0-%d.default.pod.k8s.example.com.", + i, + ))) + } + + msg, got := req.Scrub(reply) + if want := ScrubDone; want != got { + t.Errorf("want scrub result %d, got %d", want, got) + } + if want, got := req.Size(), msg.Len(); want < got { + t.Errorf("want scrub to reduce message length below %d bytes, got %d bytes", want, got) + } + if !msg.Truncated { + t.Errorf("want scrub to set truncated bit") + } +} + func BenchmarkRequestDo(b *testing.B) { st := testRequest() |