Skip to content

Commit

Permalink
Compress all DNS responses to prevent them from going over the 512 byte
Browse files Browse the repository at this point in the history
limit from RFC 1035
  • Loading branch information
MGPOwner committed May 22, 2015
1 parent 0949790 commit 08b7313
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions command/agent/dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,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)

Expand Down Expand Up @@ -228,6 +229,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)

Expand Down Expand Up @@ -625,6 +627,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)
Expand All @@ -640,6 +643,7 @@ func (d *DNSServer) handleRecurse(resp dns.ResponseWriter, req *dns.Msg) {
d.logger.Printf("[ERR] dns: all resolvers failed for %v", q)
m := &dns.Msg{}
m.SetReply(req)
m.Compress = true
m.RecursionAvailable = true
m.SetRcode(req, dns.RcodeServerFailure)
resp.WriteMsg(m)
Expand Down

0 comments on commit 08b7313

Please sign in to comment.