socketry / async-dns

An asynchronous DNS resolver and server.
MIT License
96 stars 14 forks source link

DNS response with CNAME and A record causes "Message parser reports malformed message packet" error #24

Open valodzka opened 1 year ago

valodzka commented 1 year ago

Based on example from here I'm trying implement CNAME:

if (resource_class == Resolv::DNS::Resource::IN::A || resource_class == Resolv::DNS::Resource::IN::AAAA) && name.match?(/.*\.test/)
    transaction.respond!(Name.create('google.com'), resource_class: IN::CNAME)
    transaction.append!('google.com', IN::A)
else
    transaction.passthrough!(@upstream)
end

When I use dig -p 5300 @127.0.0.1 test.test to test this code, I get the following error:

;; Warning: Message parser reports malformed message packet.
;; ;; Question section mismatch: got google.com/A/IN

Based on my understanding, this is because transaction.append! incorrectly adds an extra answer section to the DNS response, causing a mismatch between the question section and the answer section.

Can someone please suggest a solution to this issue? Is there a way to avoid the extra answer section being added to the DNS response?

ioquatix commented 1 year ago

I will take a look.