Skip to content

Commit

Permalink
Try to compress too long replies (when forwarding).
Browse files Browse the repository at this point in the history
  • Loading branch information
inercia committed Aug 17, 2015
1 parent 9e65cc2 commit 341d58d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
3 changes: 3 additions & 0 deletions nameserver/server.go
Expand Up @@ -395,6 +395,9 @@ func (s *DNSServer) notUsHandler(proto dnsProtocol) dns.HandlerFunc {
}
Debug.Printf("[dns msgid %d] Given answer by %s for query %s",
r.MsgHdr.Id, server, q.Name)
if reply.Len() > maxLen {
reply.Compress = true
}
w.WriteMsg(reply)
return
}
Expand Down
25 changes: 20 additions & 5 deletions nameserver/server_test.go
Expand Up @@ -3,12 +3,14 @@ package nameserver
import (
"encoding/binary"
"fmt"
"math/rand"
"net"
"testing"
"time"

"github.com/miekg/dns"
. "github.com/weaveworks/weave/common"
"github.com/weaveworks/weave/ipam/address"
wt "github.com/weaveworks/weave/testing"
)

Expand All @@ -32,11 +34,12 @@ func TestUDPDNSServer(t *testing.T) {
setupForTest(t)

const (
successTestName = "test1.weave.local."
failTestName = "fail.weave.local."
nonLocalName = "weave.works."
testAddr1 = "10.2.2.1"
containerID = "somecontainer"
successTestName = "test1.weave.local."
failTestName = "fail.weave.local."
compressedTestName = "compressed.weave.works."
nonLocalName = "weave.works."
testAddr1 = "10.2.2.1"
containerID = "somecontainer"
)
testCIDR1 := testAddr1 + "/24"

Expand Down Expand Up @@ -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."}
} else if q.Name == testRDNSfail && q.Qtype == dns.TypePTR {
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)
}
Expand Down Expand Up @@ -125,6 +137,9 @@ func TestUDPDNSServer(t *testing.T) {

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
// needs two servers, each listening on its own address
}
Expand Down

0 comments on commit 341d58d

Please sign in to comment.