Optimize size for SRV records, should improve performance a bit
Stricter Unit tests that checks if truncation was OK.
This commit is contained in:
parent
b0b243bf1b
commit
871b9907cb
|
@ -732,8 +732,12 @@ func (d *DNSServer) trimTCPResponse(req, resp *dns.Msg) (trimmed bool) {
|
||||||
// Beyond 2500 records, performance gets bad
|
// Beyond 2500 records, performance gets bad
|
||||||
// Limit the number of records at once, anyway, it won't fit in 64k
|
// 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
|
// For SRV Records, the max is around 500 records, for A, less than 2k
|
||||||
if len(resp.Answer) > 2048 {
|
truncateAt := 2048
|
||||||
resp.Answer = resp.Answer[:2048]
|
if req.Question[0].Qtype == dns.TypeSRV {
|
||||||
|
truncateAt = 640
|
||||||
|
}
|
||||||
|
if len(resp.Answer) > truncateAt {
|
||||||
|
resp.Answer = resp.Answer[:truncateAt]
|
||||||
}
|
}
|
||||||
if hasExtra {
|
if hasExtra {
|
||||||
index = make(map[string]dns.RR, len(resp.Extra))
|
index = make(map[string]dns.RR, len(resp.Extra))
|
||||||
|
|
|
@ -2818,9 +2818,9 @@ func TestDNS_TCP_and_UDP_Truncate(t *testing.T) {
|
||||||
// Check for the truncate bit
|
// Check for the truncate bit
|
||||||
shouldBeTruncated := numServices > 4095
|
shouldBeTruncated := numServices > 4095
|
||||||
|
|
||||||
if shouldBeTruncated != in.Truncated {
|
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) in %v",
|
info := fmt.Sprintf("service %s question:=%s (%s) (%d total records) sz:= %d in %v",
|
||||||
service, question, protocol, numServices, out)
|
service, question, protocol, numServices, len(in.Answer), out)
|
||||||
t.Fatalf("Should have truncate:=%v for %s", shouldBeTruncated, info)
|
t.Fatalf("Should have truncate:=%v for %s", shouldBeTruncated, info)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue