From 193f91db0b8cd713863aeab710f35381472b2e8e Mon Sep 17 00:00:00 2001 From: Ray Bellis Date: Wed, 24 May 2017 15:34:52 +0100 Subject: [PATCH] Fix default response generation (#492) - response Opcode must match request - RD and CD semantics are only defined for QUERY --- defaults.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/defaults.go b/defaults.go index 3308ec83..c34890ee 100644 --- a/defaults.go +++ b/defaults.go @@ -13,9 +13,12 @@ const hexDigit = "0123456789abcdef" // SetReply creates a reply message from a request message. func (dns *Msg) SetReply(request *Msg) *Msg { dns.Id = request.Id - dns.RecursionDesired = request.RecursionDesired // Copy rd bit dns.Response = true - dns.Opcode = OpcodeQuery + dns.Opcode = request.Opcode + if dns.Opcode == OpcodeQuery { + dns.RecursionDesired = request.RecursionDesired // Copy rd bit + dns.CheckingDisabled = request.CheckingDisabled // Copy cd bit + } dns.Rcode = RcodeSuccess if len(request.Question) > 0 { dns.Question = make([]Question, 1)