erldns_edns (erldns v13.0.0)
View SourceSeparate the query's EDNS (RFC 6891) from the response's.
Put this pipe first in the pipeline. erldns_resolver requires it, and erldns_questions must
come after it, as it ends the pipeline for a query without a question.
The pipeline turns the query into the response, so the OPT RR in the query's additional section is what the response would send back. This pipe makes it the response's:
- The query's options move to the
query_edns_optionspipeline option, a map from option code to option (query_edns_options/0). If a code repeats, the first option is kept. The OPT RR keeps none: a server must ignore options it doesn't understand (RFC 6891 §6.1.2), and sending one back would claim support for it. A response only carries the options pipes add withadd_option/2. - The extended RCODE is reset to 0.
- The DO bit is kept, as it must be copied to the response (RFC 3225 §3).
- A query with an EDNS version above 0 gets BADVERS, with no answer and no options, and the pipeline stops there (RFC 6891 §6.1.3).
- Over UDP, the payload size is capped, see below.
A query without an OPT RR gets none back (RFC 6891 §7). Any other record the query carries in its additional section is dropped: the response's additional records are its own.
EDNS extensions
An EDNS option is handled by a pipe of its own, which lists erldns_edns as a prerequisite, reads
the query's option from query_edns_options and adds the response's with add_option/2.
erldns_edns_edeadds Extended DNS Errors (RFC 8914) to error responses.erldns_edns_nsididentifies the server with NSID (RFC 5001).
A pipe that adds an option depending on the query must run before the first
erldns_packet_cache, which looks answers up by the response's OPT RR as it is at that point.
Listing {optional, erldns_packet_cache} among its dependents makes the pipeline check that.
UDP payload size
DNS over UDP was limited to 512 bytes per message until EDNS let clients advertise a larger UDP payload size in the OPT RR. Over UDP, a size below 512 bytes or above 1232 bytes is set to 1232, the size recommended to avoid IP fragmentation, instead of rejecting the query. The size is the limit at which the response is truncated.
Summary
Types
The query's EDNS options, by option code.
Functions
Add an option to the response's OPT RR, if it has one. See update_options/2.
erldns_pipeline:call/2 callback.
erldns_pipeline:deps/0 callback.
Whether the message's OPT RR sets the DO bit (RFC 3225).
erldns_pipeline:prepare/1 callback.
Apply Fun to the options of the response's OPT RR.
Types
-type query_edns_options() :: #{dns:eoptcode() | atom() => dns:optrr_elem()}.
The query's EDNS options, by option code.
An option that dns_erlang decodes into a record this module doesn't know yet is kept under the record's name.
Functions
-spec add_option(dns:message(), dns:optrr_elem()) -> dns:message().
Add an option to the response's OPT RR, if it has one. See update_options/2.
-spec call(dns:message(), erldns_pipeline:opts()) -> erldns_pipeline:return().
erldns_pipeline:call/2 callback.
-spec deps() -> erldns_pipeline:deps().
erldns_pipeline:deps/0 callback.
-spec dnssec_ok(dns:message()) -> boolean().
Whether the message's OPT RR sets the DO bit (RFC 3225).
-spec prepare(erldns_pipeline:opts()) -> erldns_pipeline:opts().
erldns_pipeline:prepare/1 callback.
-spec update_options(dns:message(), fun(([dns:optrr_elem()]) -> [dns:optrr_elem()])) -> dns:message().
Apply Fun to the options of the response's OPT RR.
Does nothing when the message has no OPT RR: a query without one gets none back (RFC 6891 §7).