ruby / resolv

A thread-aware DNS resolver library written in Ruby
Other
36 stars 28 forks source link

Name compression should not be performed in RDATA for SRV RRs #29

Closed hanazuki closed 1 year ago

hanazuki commented 1 year ago

RFC 2782 states that domain names in the RDATA of SRV records should not be compressed.

Target The domain name of the target host. There MUST be one or more address records for this name, the name MUST NOT be an alias (in the sense of RFC 1034 or RFC 2181). Implementors are urged, but not required, to return the address record(s) in the Additional Data section. Unless and until permitted by future standards action, name compression is not to be used for this field.

I guess this is a requirement for interoperability with old DNS implementations that don't know this RR type. For name compression in RDATA to work, all of the client, server, and proxies need to agree on the RDATA format; or otherwise, the receiver cannot decompress it correctly as it does not know which part of the message is the domain name.

Test case:

Resolv::DNS::Message.new(0).tap {|m| m.add_answer 'example.com', 0, Resolv::DNS::Resource::IN::SRV.new(0, 0, 0, "www.example.com") }.encode
# => "\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\aexample\x03com\x00\x00!\x00\x01\x00\x00\x00\x00\x00\f\x00\x00\x00\x00\x00\x00\x03www\xC0\f"