Karta.DNS (Karta v1.0.0)

DNS lookups for the rest of Karta: DKIM keys, SPF and DMARC, MX records, MTA-STS policies, DANE's TLSA records and the records a domain's verification checks.

lookup/3 checks the name and type, answers from the cache when it can, and otherwise asks the configured resolver. Each lookup is measured by record type, whether the cache answered it, and whether it found an answer, an error or nothing (Karta.Metrics.dns/4); the name looked up is never part of the measurement.

config :karta, Karta.DNS,
  resolver: {Karta.DNS.Resolver.Unbound, server: {{127, 0, 0, 1}, 53}},
  cache: Karta.DNS.Cache

Both can be overridden per call with the :resolver and :cache options (cache: nil bypasses the cache, for checks that must see the current DNS, such as domain verification).

Summary

Functions

Looks up records of type for name.

The lower-case form of a lookup name without the final dot, or {:error, :invalid_name}: labels of 1 to 63 letters, digits, hyphens and underscores, at most 253 characters in all. With :any as the second argument, labels of any printable ASCII character but . and \.

A lookup failure as a person reads it, for sentences such as "Looking up the MX records of example.com failed (timed out)." An atom the resolver returns is never shown as Elixir (:timeout); anything that is not an atom is inspected.

Functions

lookup(name, type, opts \\ [])

@spec lookup(String.t(), Karta.DNS.Record.type(), keyword()) ::
  {:ok, Karta.DNS.Answer.t()} | {:error, Karta.DNS.Resolver.error()}

Looks up records of type for name.

name may have a final dot and any ASCII case; it must be an ASCII name (convert U-labels with Karta.Mail.Punycode.to_ascii/1 first) of labels made of letters, digits, hyphens and underscores. type is one of the atoms in Karta.DNS.Record or a numeric data type.

With names: :any, a label may hold any printable ASCII character but the dot and the backslash, spaces included: SPF looks up names that macros build from what a client sent (RFC 7208 §7), and those need not be host names. Such a name still reaches the resolver only as itself (a backslash, which the wire encoding reads as an escape, is refused).

normalize_name(name, kind \\ :hostname)

@spec normalize_name(String.t(), :hostname | :any) ::
  {:ok, String.t()} | {:error, :invalid_name}

The lower-case form of a lookup name without the final dot, or {:error, :invalid_name}: labels of 1 to 63 letters, digits, hyphens and underscores, at most 253 characters in all. With :any as the second argument, labels of any printable ASCII character but . and \.

reason_text(reason)

@spec reason_text(term()) :: String.t()

A lookup failure as a person reads it, for sentences such as "Looking up the MX records of example.com failed (timed out)." An atom the resolver returns is never shown as Elixir (:timeout); anything that is not an atom is inspected.