Skip to content
This repository has been archived by the owner on Jun 20, 2024. It is now read-only.

Commit

Permalink
Merge pull request #1313 from /issues/1306-dns-compress-1-0-2
Browse files Browse the repository at this point in the history
Try to compress too long replies (when forwarding).

Fixes #1306.
  • Loading branch information
rade committed Aug 17, 2015
2 parents d220542 + c50c90e commit 7fb597a
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 7fb597a

Please sign in to comment.