aboutsummaryrefslogtreecommitdiff
path: root/request
diff options
context:
space:
mode:
Diffstat (limited to 'request')
-rw-r--r--request/request.go13
-rw-r--r--request/request_test.go27
2 files changed, 34 insertions, 6 deletions
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()