6.2 Rendering Replies
The outcome-to-response-code table and the rules for CNAME, RA, AA
and AD are PSPU §6.8. This article is how resolvd builds each reply.
6.2.1 The header and question #
- The reply copies the query's ID, opcode,
RDandCDbits and its question section. QRandRAare set.AA,ADandTCare clear, except thatTCis set on a truncated UDP reply (below).- No bit from an upstream server's reply reaches the stub reply.
6.2.2 By outcome #
6.2.2.1 found replies #
- The response code is
NOERROR, and the answer section holds the engine's records in the order the engine has them (§4.8). - When the answer was found at a candidate other than the question's
name — compared case-insensitively — the section begins with a
CNAMEfrom the question's name, in the query's case, to the candidate. Its TTL is the least TTL among the records when any are present. - A
foundwith no records at an expanded name isNOERRORwith only that leadingCNAME. Its TTL is the negative cache lifetime: the lesser of the enclosing upstreamSOArecord's TTL and minimum field, capped at 300 seconds and at the TTL of anyCNAMEpath the reply followed (§4.5). A cache hit uses the remaining lifetime, rounded down to whole seconds. With no enclosingSOA, the TTL is zero; no lifetime is invented. The authority section remains empty. An unexpanded emptyfoundhas noCNAME.
6.2.2.2 notfound replies #
NXDOMAIN, with empty answer and authority sections. No SOA is
supplied, so a client has nothing from which to cache the absence.
6.2.2.3 unavailable replies #
SERVFAIL, with empty sections.
6.2.3 EDNS in stub replies #
When the query carried an OPT record, the reply carries one
advertising a payload size of 1 232 bytes, with DO clear and no
options. A query without OPT gets a reply without one.
6.2.4 Size and truncation #
- Over UDP the reply's size limit is the payload size the query's
OPTadvertised, or 512 bytes when that is smaller or there is noOPT. - A reply over the limit is replaced by a truncated one, which keeps the
same header with
TCset, and the question. - The truncated reply keeps the
OPTrecord when the reply has one. - The truncated reply carries no records: nothing is partially included.
- A reply that cannot be encoded at all is not sent.
- Over TCP the whole reply is sent, whatever its size up to the 65 535 bytes a DNS message can hold.
- A TCP reply is written with its two-byte length, without blocking. Unfinished writes are queued with a fixed one-second deadline and a cap of 256 queued TCP replies (§2.5); a failed or expired write is not logged.