Skip to content

Read RFC 3597 generic RDATA of known types as their records - #196

Merged
NelsonVides merged 2 commits into
mainfrom
zone-generic-rdata-known-types
Nov 16, 2026
Merged

NelsonVides merged 2 commits into
mainfrom
zone-generic-rdata-known-types

Conversation

@NelsonVides

Copy link
Copy Markdown
Contributor

RFC 3597 §5 lets a zone write the RDATA of any type in the generic form, \# <length> <hex>, and has an RR of a known type in that form be treated as that type: "all further processing by the server MUST treat it as a known type". The zone reader kept the octets of every type, so A \# 4 C0000201 read as <<192,0,2,1>> where A 192.0.2.1 reads as #dns_rrdata_a{}, and took octets that are no RDATA of their type at all.

The octets of a type the reader knows are now read as its record, by the wire decoder, dns_decode:decode_rrdata/4, with no message for a compression pointer to point into. Octets the decoder cannot read as a record of the type are refused. Against BIND 9.20.30's named-checkzone:

Zone text BIND main now
A \# 4 C0000201, TYPE1 \# 4 C0000201 A 192.0.2.1 <<192,0,2,1>> #dns_rrdata_a{ip = {192,0,2,1}}
MX \# 7 000A0378797A00 MX 10 xyz. its octets #dns_rrdata_mx{preference = 10, exchange = <<"xyz">>}
TXT \# 3 026869 TXT "hi" its octets #dns_rrdata_txt{txt = [<<"hi">>]}
A \# 3 C00002, A \# 5 C000020100 refused its octets refused
MX \# 4 000AC000, a compression pointer refused its octets refused
MX \# 4 000A0178, NS \# 4 036E7332, no root label refused its octets refused
TXT \# 0 refused its octets refused
TYPE65280 \# 2 ABCD, NULL \# 2 ABCD kept <<16#AB,16#CD>> <<16#AB,16#CD>>

The refusal is {semantic_error, rfc3597_not_rdata_of_type}. Names in such RDATA come as the wire decoder gives them, without a final dot (xyz), where the presentation form gives xyz.; dns_erlang takes both as the same name. What the wire decoder takes, the generic form takes too, so an HTTPS record whose mandatory names a key twice, which the presentation form refuses, reads from its generic form, as it decodes from the wire.

The zone writer writes in the generic form what the presentation form cannot hold, such as a DS without a digest, and that now reads back as the record it wrote, where it read back as octets.

dns_decode:decode_rrdata/4, exported for tests only, is exported for the reader now, its message typed binary(), as RDATA outside a message has none. dns_decode is not documented.

Tests: parse_generic_rdata_of_known_types has BIND's readings and refusals above, and reads each of the 106 dnspython wire samples of data_samples:rrdata_wire/0 in the generic form as the wire decoder reads it, a record wherever it reads one; and the writer's DS without a digest reads back as that DS. parse_uncommon_type_numbers gave 20 known types the octets C0000201, which are no RDATA of most of them, and gives each a dnspython sample of its type now. Five tests used TYPE99 as an unassigned type, but 99 is SPF, which the reader reads; they use TYPE65280, of the private use range, now. Not decoding, decoding with pointers, keeping octets the decoder could not read, or letting its errors through makes a test fail.

RFC 3597 section 5 has an RR of a known type in the generic form, \#
and the length and hex of its RDATA, be treated as a known type. The
zone reader kept the octets of every type, so A \# 4 C0000201 read as
<<192,0,2,1>>, and took octets that are no RDATA of their type at all.

The octets of a type the reader knows are now read as its record by the
wire decoder, with no message for a compression pointer to point into,
and octets it cannot read as a record of the type are refused, as BIND
refuses them. Other types keep their octets. Names come as the wire
decoder gives them, without a final dot. What the zone writer writes in
the generic form, such as a DS without a digest, reads back as the
record it wrote.

dns_decode:decode_rrdata/4 is exported for the reader, its message
typed binary(), as RDATA outside a message has none. Five tests used
TYPE99 as unassigned, but it is SPF; they use TYPE65280 now.
@NelsonVides NelsonVides added the bug Code defect or incorrect behavior label Nov 16, 2026
@NelsonVides NelsonVides self-assigned this Nov 16, 2026
The wire decoder reads an A, AAAA, EUI48, EUI64 or DHCID only in class
IN, and the zone reader gives it the record's class. A CH A in the
generic form is refused as no RDATA of its type; read as class IN, it
would be refused later, as an A that does not fit its class, and no test
told the two apart.
@NelsonVides
NelsonVides merged commit 78031e3 into main Nov 16, 2026
6 checks passed
@NelsonVides
NelsonVides deleted the zone-generic-rdata-known-types branch November 16, 2026 14:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Code defect or incorrect behavior

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant