Try to compress too long replies (when forwarding).
This commit is contained in:
1 parent
d220542491
commit
c50c90ea8d
2 files changed
+23
-5
No files matched your search
@@ -395,6 +395,9 @@ func (s *DNSServer) notUsHandler(proto dnsProtocol) dns.HandlerFunc {
|
|||||||
}
|
}
|
||||||
Debug.Printf("[dns msgid %d] Given answer by %s for query %s",
|
Debug.Printf("[dns msgid %d] Given answer by %s for query %s",
|
||||||
r.MsgHdr.Id, server, q.Name)
|
r.MsgHdr.Id, server, q.Name)
|
||||||
|
if reply.Len() > maxLen {
|
||||||
|
reply.Compress = true
|
||||||
|
}
|
||||||
w.WriteMsg(reply)
|
w.WriteMsg(reply)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,12 +3,14 @@ package nameserver
|
|||||||
import (
|
import (
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"math/rand"
|
||||||
"net"
|
"net"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/miekg/dns"
|
"github.com/miekg/dns"
|
||||||
. "github.com/weaveworks/weave/common"
|
. "github.com/weaveworks/weave/common"
|
||||||
|
"github.com/weaveworks/weave/ipam/address"
|
||||||
wt "github.com/weaveworks/weave/testing"
|
wt "github.com/weaveworks/weave/testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -32,11 +34,12 @@ func TestUDPDNSServer(t *testing.T) {
|
|||||||
setupForTest(t)
|
setupForTest(t)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
successTestName = "test1.weave.local."
|
successTestName = "test1.weave.local."
|
||||||
failTestName = "fail.weave.local."
|
failTestName = "fail.weave.local."
|
||||||
nonLocalName = "weave.works."
|
compressedTestName = "compressed.weave.works."
|
||||||
testAddr1 = "10.2.2.1"
|
nonLocalName = "weave.works."
|
||||||
containerID = "somecontainer"
|
testAddr1 = "10.2.2.1"
|
||||||
|
containerID = "somecontainer"
|
||||||
)
|
)
|
||||||
testCIDR1 := testAddr1 + "/24"
|
testCIDR1 := testAddr1 + "/24"
|
||||||
|
|
||||||
@@ -72,6 +75,15 @@ func TestUDPDNSServer(t *testing.T) {
|
|||||||
m.Answer[0] = &dns.PTR{Hdr: dns.RR_Header{Name: m.Question[0].Name, Rrtype: dns.TypePTR, Class: dns.ClassINET, Ttl: 0}, Ptr: "ns1.google.com."}
|
m.Answer[0] = &dns.PTR{Hdr: dns.RR_Header{Name: m.Question[0].Name, Rrtype: dns.TypePTR, Class: dns.ClassINET, Ttl: 0}, Ptr: "ns1.google.com."}
|
||||||
} else if q.Name == testRDNSfail && q.Qtype == dns.TypePTR {
|
} else if q.Name == testRDNSfail && q.Qtype == dns.TypePTR {
|
||||||
m.Rcode = dns.RcodeNameError
|
m.Rcode = dns.RcodeNameError
|
||||||
|
} else if q.Name == compressedTestName {
|
||||||
|
// Construct a response that is >512 when uncompressed, <512 when compressed
|
||||||
|
header := makeHeader(m, &q, 300)
|
||||||
|
for m.Len() <= minUDPSize {
|
||||||
|
ip := address.Address(rand.Uint32()).IP4()
|
||||||
|
m.Answer = append(m.Answer, &dns.A{Hdr: *header, A: ip})
|
||||||
|
}
|
||||||
|
m.Compress = true
|
||||||
|
wt.AssertTrue(t, m.Len() <= minUDPSize, fmt.Sprintf("length: %d", m.Len()))
|
||||||
}
|
}
|
||||||
w.WriteMsg(m)
|
w.WriteMsg(m)
|
||||||
}
|
}
|
||||||
@@ -125,6 +137,9 @@ func TestUDPDNSServer(t *testing.T) {
|
|||||||
|
|
||||||
assertExchange(t, testRDNSnonlocal, dns.TypePTR, testPort, 1, -1, 0)
|
assertExchange(t, testRDNSnonlocal, dns.TypePTR, testPort, 1, -1, 0)
|
||||||
|
|
||||||
|
_, r = assertExchange(t, compressedTestName, dns.TypeA, testPort, -1, -1, 0)
|
||||||
|
wt.AssertTrue(t, r.Len() > minUDPSize, "unexpected message length")
|
||||||
|
|
||||||
// Not testing MDNS functionality of server here (yet), since it
|
// Not testing MDNS functionality of server here (yet), since it
|
||||||
// needs two servers, each listening on its own address
|
// needs two servers, each listening on its own address
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user