erldns_zones (erldns v13.0.0)

View Source

The 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

Types

Zone configuration.

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.

Takes a zone and turns it into a map.

Types

config()

-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, format will be ignored
    • If it is a directory, it will find all nested files matching the format specified in format
  • 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 .private file extension (i.e.: "example.com.private") and should contain a JSON formatted list of keysets as in the JSON zone 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:

    • json: zones are parsed using erldns's JSON zone format.
    • zonefile: zones are parsed using the zone format.
    • auto: both filetypes will be loaded depending on their file extension.
  • 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, see erldns_zone_pipeline. Defaults to erldns_zone_context and erldns_zone_standard, and the pipes that decode custom record types go after them. Not to be confused with the top-level pipeline and packet_pipeline keys, which are about queries.

  • context_options: allow you to filter loading certain records in a zone depending on configuration details. See ZONES for more details.

See erldns_zone_loader for more details.

format()

-type format() :: json | zonefile | auto.

version()

-type version() :: binary().

Functions

build_zone(Name, Version, Records, Keys)

-spec build_zone(dns:dname(), version(), [dns:rr()], [erldns:keyset()]) -> erldns:zone().

Builds a zone from its records and keysets.

decode(Zone)

-spec decode(json:decode_value()) -> erldns:zone().

Takes a JSON map and turns it into a zone, as decode/2 does with no options.

decode/2

-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.

decode_records(Entries, Opts)

-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.

encode(Zone)

-spec encode(erldns:zone()) -> json:encode_value().

Equivalent to encode(Zone, #{mode => zone_to_json}).

encode(Zone, Opts)

-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.