erldns_zones (erldns v13.0.0)
View SourceThe system responsible for loading and caching zone data.
Zones are loaded by default from JSON files in the priv/zones/ directory.
The path is configured in erldns.config using the zones.path setting.
Zones in JSON are decoded with decode/2, and encoded back with encode/2. Their records go
through erldns_zone_pipeline, whose pipes also decode the records of the types erldns doesn't
know, and encode them back.
For more details about zone file format and configuration, see ZONES.
For more details about its subsections, see:
Configuration
{erldns, [
{zones, #{
path => "zones.json",
keys_path => "/root/dnssec/",
strict => true,
format => auto,
timeout => timer:minutes(5),
grace_period => timer:seconds(30),
pipeline => [erldns_zone_context, erldns_zone_standard, sample_custom_zone_pipe],
context_options => #{match_empty => true, allow => [<<"anycast">>, <<"AMS">>, <<"TKO">>]}
}},
]}See the type config/0 for details.
Summary
Functions
Builds a zone from its records and keysets.
Takes a JSON map and turns it into a zone, as decode/2 does with no options.
Takes a JSON map and turns it into a zone, through erldns_zone_pipeline.
Takes records of a zone, such as those of an RRSet, through erldns_zone_pipeline.
Equivalent to encode(Zone, #{mode => zone_to_json}).
Takes a zone and turns it into a map.
Types
-type config() :: #{path => undefined | file:name_all(), keys_path => undefined | file:name_all(), strict => boolean(), format => format(), timeout => timeout(), grace_period => non_neg_integer(), pipeline => [erldns_zone_pipeline:pipe()], context_options => #{match_empty => boolean(), allow => [binary()]}}.
Zone configuration.
path: can be a file or a directory:- If it is a file,
formatwill be ignored - If it is a directory, it will find all nested files matching the format specified in
format
- If it is a file,
strict: declares whether any loading error should crash the whole loading process or be ignored.keys_path: specifies the path to DNSSEC keys used for signing and validating zones. These file should be named after the zone name with the.privatefile extension (i.e.: "example.com.private") and should contain a JSON formatted list of keysets as in theJSONzone format documentation.format: specifies the zone file format to look for. The records of both formats go through the zone pipeline, those of zone files already decoded. Valid values are:timeout: specify how long zone loading can take before being aborted. Defaults to 30 minutes.grace_period: how long, in milliseconds, the records of a replaced or deleted zone stay readable for queries that started on them, before they are deleted. Defaults to 30 seconds.pipeline: the pipes that the records of a zone go through when it is decoded, seeerldns_zone_pipeline. Defaults toerldns_zone_contextanderldns_zone_standard, and the pipes that decode custom record types go after them. Not to be confused with the top-levelpipelineandpacket_pipelinekeys, which are about queries.context_options: allow you to filter loading certain records in a zone depending on configuration details. SeeZONESfor more details.
See erldns_zone_loader for more details.
-type format() :: json | zonefile | auto.
-type version() :: binary().
Functions
-spec build_zone(dns:dname(), version(), [dns:rr()], [erldns:keyset()]) -> erldns:zone().
Builds a zone from its records and keysets.
-spec decode(json:decode_value()) -> erldns:zone().
Takes a JSON map and turns it into a zone, as decode/2 does with no options.
-spec decode(json:decode_value(), #{atom() => dynamic()}) -> erldns:zone().
Takes a JSON map and turns it into a zone, through erldns_zone_pipeline.
The pipes get Opts with the zone's name and version, and scope set to zone unless Opts sets
it.
-spec decode_records(Entries, Opts) -> [dns:rr()] when Entries :: [erldns_zone_pipeline:entry()], Opts :: #{zone_name := dns:dname(), atom() => dynamic()}.
Takes records of a zone, such as those of an RRSet, through erldns_zone_pipeline.
The records can be JSON or already decoded. The pipes get Opts, with scope set to partial
and version to <<>> unless Opts sets them. Returns the records, sorted and deduplicated.
-spec encode(erldns:zone()) -> json:encode_value().
Equivalent to encode(Zone, #{mode => zone_to_json}).
-spec encode(erldns:zone(), #{atom() => dynamic()}) -> json:encode_value().
Takes a zone and turns it into a map.
The records of the types erldns doesn't know are encoded by the erldns_zone_pipeline:encode/1
of the pipes of the zone pipeline.