This module provides types and traits for working with DNS data as well as parsing and composing wire-format DNS messages.
The module contains abstractions for two concepts used in DNS data:
domain names and character strings. In both cases, the supplied types
internally contain the binary data and work directly on it. Similar
to raw bytes slices, there types for borrowed and owned domain names
and character strings where the owned type derefs to the borrowed one.
For domain names, these types are
for character strings
For domain names there is a third variant,
ParsedDName. This type is
necessary to represent compressed names where the remainder of a name is
to be found elsewhere in the message. It avoids allocations when access
to the entire name isn’t necessary.
Traits are used when constructing composite types to allow them to work
on borrowed and owned data as well as on parsed domain names. For
character strings and raw bytes data,
are being used. For domain names, there is a separate trait,
with the same purpose. However, its functionality is limited to the
what parsed domain names can provide.
Instead of having one big enum, the data of resource records is kept
generic through two traits:
RecordData provides functions common to
all variants of record data types while
the ability to construct a value from a wire-format message for those
variants that can use borrowed data and parsed domain names. The actual
types implementing these traits can by found in the crate’s rdata
In order to easily distinguish the process of creating and disecting wire-format messages from working with master files, we use the term parsing and composing for reading from and writing to wire-format data.
Both parsing and composing happen on bytes buffers. This seems to be a reasonably good choice given the relatively small size of DNS messages and the complexities introduced by name compression. The details are explained in the parse and compose sub-modules. Unless you are implementing your own resource record types, you are unlikely to ever having to deal with parsing and composing directly.
Instead, the types
MessageBuilder are there to make
parsing and constructing DNS messages easy. A
Message takes the
binary data of a DNS message and allows iterating over its four
sections to look at the questions and resource records. Similarly,
MessageBuilder takes a bytes vector (or creates one for you) and
has functionality to build the sections of the message step-by-step.
Assembling wire-format DNS data.
The header of a DNS message.
Accessing exisiting DNS messages.
Building a new message.
Record data for OPT records.
Parsing of DNS wire-format data.
A single question of a DNS message.
Basic resource data handling.
An owned complete domain name.
A slice of a domain name.
A domain name parsed from a DNS message.
A trait implemented by all domain name types.