std/dns/message
std/dns/src/message.trb
Message: a DNS message of RFC 1035 section 4 as a value - the header with its flags, the four sections, and the
EDNS0 record of RFC 6891 taken out of the additional section into Edns. Message.tryFrom(bytes) reads one and
encoded() writes one; the codec is in ./wire.
type Question
type Question with Show, Equals, Hash
A question: which records of which name a message asks for (RFC 1035 section 4.1.2).
field name
name: DomainName
The name asked about.
field recordType
recordType: RecordType
The type of the records asked for; Any asks for all of them.
field recordClass
recordClass: RecordClass = RecordClass.Internet
Internet everywhere but in a Chaosnet query.
fn show
fn show(): String
A line of a zone file without a time to live: example.test. IN A.
type MessageKind
type MessageKind with Show, Equals, Hash
QR, the first bit of the header: whether a message asks or answers (RFC 1035 section 4.1.1).
type EdnsOption
type EdnsOption with Show, Equals, Hash
One option of the EDNS0 record (RFC 6891 section 6.1.2): its code and its data, as the bytes they are.
type Edns
type Edns with Show, Equals, Hash
The EDNS0 record (RFC 6891): what a client or a server says about itself beyond RFC 1035. A message has one or none,
and it is not part of Message.additional.
field payloadSize
payloadSize: Int = 1232
The largest UDP payload the sender can receive, in bytes. 1232 avoids fragmentation on every path (the DNS Flag Day of 2020), and a value below 512 is read as 512 by the receiver.
field version
version: Int = 0
The version of EDNS; 0 is the only one there is.
field dnssecOk
dnssecOk: Bool = false
The DO bit: the sender wants DNSSEC records in the answer (RFC 3225).
field options
options: List<EdnsOption> = []
The options, in order.
type Message
type Message with Show, Equals, Hash, TryFrom<Bytes, DnsError>
A DNS message: a query or a response, as its kind says. Every field is plain data, so a message is built with the
constructor and read field by field; the flags are the bits of the header (RFC 1035 section 4.1.1, RFC 4035 section
3.2 for the last two), and Message.responseCode holds all twelve bits of the response code, four from the header
and eight from the EDNS0 record.
Examples
fn printAnswers(bytes: Bytes): Result<Void, DnsError> {
const response = Message.tryFrom(bytes)?
for record in response.answers {
print record
}
Ok void
}
Related
queryofstd/dns- the bytes of a query, for a transport.readResponseofstd/dns- a message read and checked against the query it answers.
field identifier
identifier: Int = 0
The identifier that pairs a response with its query, from 0 to 65535.
field kind
kind: MessageKind = MessageKind.Query
QR: a query or a response.
field operation
operation: Operation = Operation.Query
What the message asks the server to do.
field authoritative
authoritative: Bool = false
AA: the server is an authority for the name in the question.
field truncated
truncated: Bool = false
TC: the response did not fit and was cut short; a client asks again over TCP (RFC 7766).
field recursionDesired
recursionDesired: Bool = false
RD: the client wants the server to resolve the name recursively.
field recursionAvailable
recursionAvailable: Bool = false
RA: the server resolves recursively.
field authenticated
authenticated: Bool = false
AD: the server says it validated every record of the answer with DNSSEC (RFC 4035 section 3.2.3). This package validates nothing itself; the bit is as trustworthy as the path to the server.
field checkingDisabled
checkingDisabled: Bool = false
CD: the client does its own DNSSEC validation and asks the server not to.
field responseCode
responseCode: ResponseCode = ResponseCode.NoError
How the server answered, with the eight extended bits of the EDNS0 record.
field questions
questions: List<Question> = []
The question section: in practice one question.
field answers
answers: List<Record> = []
The answer section.
field authority
authority: List<Record> = []
The authority section: the name servers of a referral, or the SOA record of a negative answer.
field additional
additional: List<Record> = []
The additional section, without the EDNS0 record, which is Message.edns.
field edns
edns: Edns? = None
The EDNS0 record, where the message has one.
fn tryFrom
static fn tryFrom(bytes: Bytes): Result<Self, DnsError>
The message these bytes are, after RFC 1035 section 4 with compressed names and the EDNS0 record of RFC 6891. Bytes
from the network cannot make this panic: every problem is a DnsError.
Errors
DnsError.Truncatedwhere the bytes end inside of a part of the message.DnsError.InvalidPointerandDnsError.PointerLoopfor a compression pointer outside the message or in a cycle.DnsError.InvalidNamefor a name longer than 255 bytes.DnsError.InvalidRecordfor the data of a record that does not fit its type.DnsError.InvalidMessagefor an undefined label type, an OPT record outside the additional section or a second one, and bytes after the last record.
fn encoded
fn encoded(): Result<Bytes, DnsError>
The bytes of the message, with every name in the question and in the owner of a record compressed, and the names in the data of the types of RFC 1035 (CNAME, MX, NS, PTR, SOA) - never those of SRV, SVCB and HTTPS, which their RFCs forbid to compress.
Errors
DnsError.Unencodablefor a number outside the bits of its field, a text string longer than 255 bytes, record data longer than 65535 bytes, more than 65535 entries in a section, a response code above 15 without an EDNS0 record, an empty or invalid CAA tag, two service parameters with one key, and anUnknownrecord of type OPT.
fn answersFor
fn answersFor(name: DomainName, recordType: RecordType): List<Record>
The records of recordType for name in the answer section, following the chain of CNAME records from name to
the canonical name: what a stub resolver answers. Empty where the answer holds none; a chain that runs in a circle
ends where it closes.
fn addresses
fn addresses(of: DomainName): List<IpAddress>
The IPv4 and IPv6 addresses of name in the answer section, CNAME chains followed, IPv4 first.