Compress all DNS responses to prevent them from going over the 512 byte

limit from RFC 1035
This commit is contained in:
epipho 2015-05-22 18:10:27 -04:00 committed by James Phillips
parent db94764354
commit d965e90306
No known key found for this signature in database
GPG Key ID: 77183E682AC5FC11
1 changed files with 4 additions and 0 deletions

View File

@ -180,6 +180,7 @@ func (d *DNSServer) handlePtr(resp dns.ResponseWriter, req *dns.Msg) {
// Setup the message response
m := new(dns.Msg)
m.SetReply(req)
m.Compress = true
m.Authoritative = true
m.RecursionAvailable = (len(d.recursors) > 0)
@ -249,6 +250,7 @@ func (d *DNSServer) handleQuery(resp dns.ResponseWriter, req *dns.Msg) {
// Setup the message response
m := new(dns.Msg)
m.SetReply(req)
m.Compress = true
m.Authoritative = true
m.RecursionAvailable = (len(d.recursors) > 0)
@ -785,6 +787,7 @@ func (d *DNSServer) handleRecurse(resp dns.ResponseWriter, req *dns.Msg) {
var err error
for _, recursor := range d.recursors {
r, rtt, err = c.Exchange(req, recursor)
r.Compress = true
if err == nil {
// Forward the response
d.logger.Printf("[DEBUG] dns: recurse RTT for %v (%v)", q, rtt)
@ -801,6 +804,7 @@ func (d *DNSServer) handleRecurse(resp dns.ResponseWriter, req *dns.Msg) {
q, resp.RemoteAddr().String(), resp.RemoteAddr().Network())
m := &dns.Msg{}
m.SetReply(req)
m.Compress = true
m.RecursionAvailable = true
m.SetRcode(req, dns.RcodeServerFailure)
resp.WriteMsg(m)