Fix default response generation (#492)

- response Opcode must match request
- RD and CD semantics are only defined for QUERY
This commit is contained in:
Ray Bellis 2017-05-24 15:34:52 +01:00 committed by Miek Gieben
parent babbdab23a
commit 193f91db0b
1 changed files with 5 additions and 2 deletions

View File

@ -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)