async-dns icon indicating copy to clipboard operation
async-dns copied to clipboard

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

Open valodzka opened this issue 2 years ago • 1 comments

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?

valodzka avatar Mar 24 '23 07:03 valodzka

I will take a look.

ioquatix avatar Mar 24 '23 10:03 ioquatix