erldns_zone_cache (erldns v8.0.0-rc2)

View Source

A cache holding all of the zone data.

This module expects all input to use normalised (that is, lowercase) names, therefore it is the responsibility of the client to call this API with normalised names. This is to avoid normalising already normalised names, which can result into computational waste. As the client might need to call multiple points of this API, the client can ensure to normalise once and use multiple times.

Summary

API: Boolean Operations

Check if the name is in any available zone.

Check if the exact record name is in the zone, without recursing nor traversing the zone tree.

Check if the record name, or any wildcard or parent wildcard, is in the zone.

Check if the record name, or any wildcard, or parent wildcard, or descendant, is in the zone.

API: Lookups

Find an authoritative zone for a given qname.

Get the list of NS and glue records for the given name.

Return the record set for the given dname.

Return the record set for the given dname in the given zone.

Get all records for the given type and given name.

Get all records for the given name and type in the given zone.

Return the full record set for the tree below the given dname

Return the record set for the given dname in the given zone, including parent wildcard matches.

Return the record set for the given dname in the given zone, including parent exact and wildcard matches.

Get all records for the given zone.

Get a zone for the specific name.

API: Mutations

Remove a zone from the cache without waiting for a response.

Put a name and its records into the cache, along with a SHA which can be used to determine if the zone requires updating.

Given a zone name, list of records, and a digest, update the zone metadata in cache.

API: Utilities

Return a list of tuples with each tuple as a name and the version SHA for the zone.

API: Boolean Operations

is_in_any_zone/1

-spec is_in_any_zone(dns:dname() | dns:labels()) -> boolean().

Check if the name is in any available zone.

is_name_in_zone/2

-spec is_name_in_zone(erldns:zone(), dns:dname() | dns:labels()) -> boolean().

Check if the exact record name is in the zone, without recursing nor traversing the zone tree.

is_record_name_in_zone/2

-spec is_record_name_in_zone(erldns:zone(), dns:dname() | dns:labels()) -> boolean().

Check if the record name, or any wildcard or parent wildcard, is in the zone.

is_record_name_in_zone_strict/2

-spec is_record_name_in_zone_strict(erldns:zone(), dns:dname() | dns:labels()) -> boolean().

Check if the record name, or any wildcard, or parent wildcard, or descendant, is in the zone.

Will also return true if a wildcard is present at the node, or if any descendant has existing records (and the queried name is an ENT).

API: Lookups

get_authoritative_zone/1

-spec get_authoritative_zone(dns:dname() | dns:labels()) ->
                                erldns:zone() | zone_not_found | not_authoritative.

Find an authoritative zone for a given qname.

get_delegations/1

-spec get_delegations(dns:dname() | dns:labels()) -> [dns:rr()].

Get the list of NS and glue records for the given name.

This function will always return a list, even if it is empty.

get_records_by_name/1

-spec get_records_by_name(dns:dname() | dns:labels()) -> [dns:rr()].

Return the record set for the given dname.

get_records_by_name/2

-spec get_records_by_name(erldns:zone(), dns:dname() | dns:labels()) -> [dns:rr()].

Return the record set for the given dname in the given zone.

get_records_by_name_and_type/2

-spec get_records_by_name_and_type(dns:dname() | dns:labels(), dns:type()) -> [dns:rr()].

Get all records for the given type and given name.

get_records_by_name_and_type/3

-spec get_records_by_name_and_type(erldns:zone(), dns:dname() | dns:labels(), dns:type()) -> [dns:rr()].

Get all records for the given name and type in the given zone.

get_records_by_name_ent/2

-spec get_records_by_name_ent(erldns:zone(), dns:dname() | dns:labels()) -> [dns:rr()].

Return the full record set for the tree below the given dname

get_records_by_name_wildcard/2

-spec get_records_by_name_wildcard(erldns:zone(), dns:dname() | dns:labels()) -> [dns:rr()].

Return the record set for the given dname in the given zone, including parent wildcard matches.

get_records_by_name_wildcard_strict/2

-spec get_records_by_name_wildcard_strict(erldns:zone(), dns:dname() | dns:labels()) -> [dns:rr()].

Return the record set for the given dname in the given zone, including parent exact and wildcard matches.

get_rrset_sync_counter(NormalizedZoneName, RRFqdn, Type)

-spec get_rrset_sync_counter(dns:dname(), dns:dname(), dns:type()) -> integer().

Return current sync counter

get_zone_records/1

-spec get_zone_records(erldns:zone() | dns:dname() | dns:labels()) -> [dns:rr()].

Get all records for the given zone.

lookup_zone/1

-spec lookup_zone(dns:dname() | dns:labels()) -> erldns:zone() | zone_not_found.

Get a zone for the specific name.

This function will not attempt to resolve the dname in any way, it will simply look up the name in the underlying data store.

API: Mutations

delete_zone/1

-spec delete_zone(dns:dname() | dns:labels()) -> term().

Remove a zone from the cache without waiting for a response.

delete_zone_rrset(ZoneName, Digest, RRFqdn, Type, Counter)

-spec delete_zone_rrset(dns:dname(), erldns_zones:version(), dns:dname(), integer(), integer()) ->
                           ok | zone_not_found.

Remove zone RRSet

put_zone/1

-spec put_zone(Zone | {Name, Sha, Records} | {Name, Sha, Records, Keys}) -> ok
                  when
                      Zone :: erldns:zone(),
                      Name :: dns:dname(),
                      Sha :: erldns_zones:version(),
                      Records :: [dns:rr()],
                      Keys :: [erldns:keyset()].

Put a name and its records into the cache, along with a SHA which can be used to determine if the zone requires updating.

This function will build the necessary Zone record before inserting.

The name of each record must be the fully qualified domain name (including the zone part).

Here's an example:

erldns_zone_cache:put_zone({
  <<"example.com">>, <<"someDigest">>, [
    #dns_rr{
      name = <<"example.com">>,
      type = ?DNS_TYPE_A,
      ttl = 3600,
      data = #dns_rrdata_a{ip = {1,2,3,4}}
    },
    #dns_rr{
      name = <<"www.example.com">>,
      type = ?DNS_TYPE_CNAME,
      ttl = 3600,
      data = #dns_rrdata_cname{dname = <<"example.com">>}
    }
  ]}).

put_zone_rrset(RRSet, RRFqdn, Type, Counter)

-spec put_zone_rrset(RRSet, RRFqdn, Type, Counter) -> ok | zone_not_found
                        when
                            RRSet ::
                                erldns:zone() |
                                {dns:dname(), erldns_zones:version(), [dns:rr()]} |
                                {dns:dname(), erldns_zones:version(), [dns:rr()], [term()]},
                            RRFqdn :: dns:dname(),
                            Type :: dns:type(),
                            Counter :: integer().

Put zone RRSet

update_zone_records_and_digest(ZLabels, RecordsCount, Digest)

-spec update_zone_records_and_digest(dns:labels(), non_neg_integer(), erldns_zones:version()) ->
                                        ok | zone_not_found.

Given a zone name, list of records, and a digest, update the zone metadata in cache.

API: Utilities

zone_names_and_versions()

-spec zone_names_and_versions() -> [{dns:dname(), erldns_zones:version()}].

Return a list of tuples with each tuple as a name and the version SHA for the zone.