Optimize size for SRV records, should improve performance a bit

Stricter Unit tests that checks if truncation was OK.
This commit is contained in:
Pierre Souchay 2018-03-09 18:25:29 +01:00
parent b0b243bf1b
commit 871b9907cb
2 changed files with 9 additions and 5 deletions

View File

@ -732,8 +732,12 @@ func (d *DNSServer) trimTCPResponse(req, resp *dns.Msg) (trimmed bool) {
// Beyond 2500 records, performance gets bad
// Limit the number of records at once, anyway, it won't fit in 64k
// For SRV Records, the max is around 500 records, for A, less than 2k
if len(resp.Answer) > 2048 {
resp.Answer = resp.Answer[:2048]
truncateAt := 2048
if req.Question[0].Qtype == dns.TypeSRV {
truncateAt = 640
}
if len(resp.Answer) > truncateAt {
resp.Answer = resp.Answer[:truncateAt]
}
if hasExtra {
index = make(map[string]dns.RR, len(resp.Extra))

View File

@ -2818,9 +2818,9 @@ func TestDNS_TCP_and_UDP_Truncate(t *testing.T) {
// Check for the truncate bit
shouldBeTruncated := numServices > 4095
if shouldBeTruncated != in.Truncated {
info := fmt.Sprintf("service %s question:=%s (%s) (%d total records) in %v",
service, question, protocol, numServices, out)
if shouldBeTruncated != in.Truncated || len(in.Answer) > 2000 || len(in.Answer) < 1 || in.Len() > 65535 {
info := fmt.Sprintf("service %s question:=%s (%s) (%d total records) sz:= %d in %v",
service, question, protocol, numServices, len(in.Answer), out)
t.Fatalf("Should have truncate:=%v for %s", shouldBeTruncated, info)
}
})