View Source dns (dns_erlang v3.0.5)

Summary

Functions

Generates and then appends a TSIG RR to a message. Supports MD5, SHA1, SHA224, SHA256, SHA384 and SHA512 algorithms.

Returns the name of a DNS algorithm as a binary string.

Returns the name of the class as a binary string.

Compare two domain names insensitive of case.

Compares two equal sized binaries over their entire length. Returns immediately if sizes do not match.

Decode a binary DNS message.

Splits a dname into a list of labels and removes unneeded escapes.

Returns provided name with case-insensitive characters in lowercase.

Returns provided name with case-insensitive characters in uppercase.

Encode a dns_message record.

Encode a dns_message record - will truncate the message as needed.

Returns the name of an extended option as a binary string.

Returns the name of an extended rcode as a binary string.

Escapes dots in a DNS label

Joins a list of DNS labels, escaping where necessary.

Returns the name of an LLQ error code as a binary string.

Returns the name of an LLQ opcode as a binary string.

Returns the name of an opcode as a binary string.

Returns a random integer suitable for use as DNS message identifier.

Returns the name of an rcode as a binary string.

Returns the name of a TSIG error as a binary string.

Returns the name of the type as a binary string.

Return current unix time.

Return the unix time from a now or universal time.

Verifies a TSIG message signature.

Types

additional/0

-type additional() :: [optrr() | [rr()]] | [rr()].

alg/0

-type alg() :: 3 | 6 | 5 | 7 | 8 | 10.

answers/0

-type answers() :: [rr()].

authority/0

-type authority() :: [rr()].

class/0

-type class() :: uint16().

decode_error/0

-type decode_error() :: formerr | truncated | trailing_garbage.

dname/0

-type dname() :: binary().

encode_message_opt/0

-type encode_message_opt() ::
          {max_size, 512..65535} |
          {tc_mode, default | axfr | llq_event} |
          {tsig, [encode_message_tsig_opt()]}.

encode_message_tsig_opt/0

-type encode_message_tsig_opt() ::
          {msgid, message_id()} |
          {alg, tsig_alg()} |
          {name, dname()} |
          {secret, binary()} |
          {errcode, tsig_error()} |
          {other, binary()} |
          tsig_opt().

eoptcode/0

-type eoptcode() :: 0..65535.

ercode/0

-type ercode() :: 0 | 16.

label/0

-type label() :: binary().

llqerrcode/0

-type llqerrcode() :: 0..6.

llqopcode/0

-type llqopcode() :: 1..3.

message/0

-type message() ::
          #dns_message{id :: dns:message_id(),
                       qr :: boolean(),
                       oc :: dns:opcode(),
                       aa :: boolean(),
                       tc :: boolean(),
                       rd :: boolean(),
                       ra :: boolean(),
                       ad :: boolean(),
                       cd :: boolean(),
                       rc :: dns:rcode(),
                       qc :: dns:uint16(),
                       anc :: dns:uint16(),
                       auc :: dns:uint16(),
                       adc :: dns:uint16(),
                       questions :: dns:questions(),
                       answers :: dns:answers(),
                       authority :: dns:authority(),
                       additional :: dns:additional()}.

message_bin/0

-type message_bin() :: <<_:64, _:_*8>>.

message_id/0

-type message_id() :: uint16().

opcode/0

-type opcode() :: uint4().

opt_ecs/0

-type opt_ecs() ::
          #dns_opt_ecs{family :: dns:uint16(),
                       source_prefix_length :: dns:uint8(),
                       scope_prefix_length :: dns:uint8(),
                       address :: binary()}.

opt_llq/0

-type opt_llq() ::
          #dns_opt_llq{opcode :: dns:uint16(),
                       errorcode :: dns:uint16(),
                       id :: dns:uint64(),
                       leaselife :: dns:uint32()}.

opt_nsid/0

-type opt_nsid() :: #dns_opt_nsid{data :: binary()}.

opt_owner/0

-type opt_owner() ::
          #dns_opt_owner{seq :: dns:uint8(),
                         primary_mac :: <<_:(6 * 8)>>,
                         wakeup_mac :: <<>> | <<_:(6 * 8)>>,
                         password :: <<>> | <<_:(6 * 8)>>}.

opt_ul/0

-type opt_ul() :: #dns_opt_ul{lease :: dns:uint32()}.

opt_unknown/0

-type opt_unknown() :: #dns_opt_unknown{id :: integer(), bin :: binary()}.

optrr/0

-type optrr() ::
          #dns_optrr{udp_payload_size :: integer(),
                     ext_rcode :: dns:rcode(),
                     version :: dns:uint8(),
                     dnssec :: boolean(),
                     data ::
                         [dns:opt_nsid() |
                          dns:opt_ul() |
                          dns:opt_unknown() |
                          dns:opt_ecs() |
                          dns:opt_llq() |
                          dns:opt_owner()]}.

query/0

-type query() :: #dns_query{name :: dns:dname(), class :: dns:class(), type :: dns:type()}.

questions/0

-type questions() :: [query()].

rcode/0

-type rcode() :: uint4().

rr/0

-type rr() ::
          #dns_rr{name :: dns:dname(),
                  type :: dns:type(),
                  class :: dns:class(),
                  ttl :: dns:ttl(),
                  data :: dns:rrdata()}.

rrdata/0

-type rrdata() ::
          binary() |
          #dns_rrdata_a{ip :: inet:ip4_address()} |
          #dns_rrdata_aaaa{ip :: inet:ip6_address()} |
          #dns_rrdata_afsdb{subtype :: dns:uint16(), hostname :: dns:dname()} |
          #dns_rrdata_caa{flags :: dns:uint8(), tag :: binary(), value :: binary()} |
          #dns_rrdata_cdnskey{flags :: dns:uint16(),
                              protocol :: dns:uint8(),
                              alg :: dns:uint8(),
                              public_key :: iodata(),
                              key_tag :: integer()} |
          #dns_rrdata_cds{keytag :: dns:uint16(),
                          alg :: dns:uint8(),
                          digest_type :: dns:uint8(),
                          digest :: binary()} |
          #dns_rrdata_cert{type :: dns:uint16(),
                           key_tag :: dns:uint16(),
                           alg :: dns:uint8(),
                           cert :: binary()} |
          #dns_rrdata_cname{dname :: dns:dname()} |
          #dns_rrdata_dhcid{data :: binary()} |
          #dns_rrdata_dlv{keytag :: dns:uint16(),
                          alg :: dns:uint8(),
                          digest_type :: dns:uint8(),
                          digest :: binary()} |
          #dns_rrdata_dname{dname :: dns:dname()} |
          #dns_rrdata_dnskey{flags :: dns:uint16(),
                             protocol :: dns:uint8(),
                             alg :: dns:uint8(),
                             public_key :: iodata(),
                             key_tag :: integer()} |
          #dns_rrdata_ds{keytag :: dns:uint16(),
                         alg :: dns:uint8(),
                         digest_type :: dns:uint8(),
                         digest :: binary()} |
          #dns_rrdata_hinfo{cpu :: binary(), os :: binary()} |
          #dns_rrdata_ipseckey{precedence :: dns:uint8(),
                               alg :: dns:uint8(),
                               gateway :: dns:dname() | inet:ip_address(),
                               public_key :: binary()} |
          #dns_rrdata_key{type :: dns:uint2(),
                          xt :: 0..1,
                          name_type :: dns:uint2(),
                          sig :: dns:uint4(),
                          protocol :: dns:uint8(),
                          alg :: dns:uint8(),
                          public_key :: binary()} |
          #dns_rrdata_kx{preference :: dns:uint16(), exchange :: dns:dname()} |
          #dns_rrdata_loc{size :: integer(),
                          horiz :: integer(),
                          vert :: integer(),
                          lat :: dns:uint32(),
                          lon :: dns:uint32(),
                          alt :: dns:uint32()} |
          #dns_rrdata_mb{madname :: dns:dname()} |
          #dns_rrdata_mg{madname :: dns:dname()} |
          #dns_rrdata_minfo{rmailbx :: dns:dname(), emailbx :: dns:dname()} |
          #dns_rrdata_mr{newname :: dns:dname()} |
          #dns_rrdata_mx{preference :: dns:uint16(), exchange :: dns:dname()} |
          #dns_rrdata_naptr{order :: dns:uint16(),
                            preference :: dns:uint16(),
                            flags :: binary(),
                            services :: binary(),
                            regexp :: binary(),
                            replacement :: dns:dname()} |
          #dns_rrdata_ns{dname :: dns:dname()} |
          #dns_rrdata_nsec{next_dname :: dns:dname(), types :: [non_neg_integer()]} |
          #dns_rrdata_nsec3{hash_alg :: dns:uint8(),
                            opt_out :: boolean(),
                            iterations :: dns:uint16(),
                            salt :: binary(),
                            hash :: binary(),
                            types :: [non_neg_integer()]} |
          #dns_rrdata_nsec3param{hash_alg :: dns:uint8(),
                                 flags :: dns:uint8(),
                                 iterations :: dns:uint16(),
                                 salt :: binary()} |
          #dns_rrdata_nxt{dname :: dns:dname(), types :: [non_neg_integer()]} |
          #dns_rrdata_ptr{dname :: dns:dname()} |
          #dns_rrdata_rp{mbox :: dns:dname(), txt :: dns:dname()} |
          #dns_rrdata_rrsig{type_covered :: dns:uint16(),
                            alg :: 3 | 5 | 6 | 7 | 8 | 10,
                            labels :: dns:uint8(),
                            original_ttl :: dns:uint32(),
                            expiration :: dns:uint32(),
                            inception :: dns:uint32(),
                            key_tag :: dns:uint16(),
                            signers_name :: dns:dname(),
                            signature :: binary()} |
          #dns_rrdata_rt{preference :: dns:uint16(), host :: dns:dname()} |
          #dns_rrdata_soa{mname :: dns:dname(),
                          rname :: dns:dname(),
                          serial :: dns:uint32(),
                          refresh :: dns:uint32(),
                          retry :: dns:uint32(),
                          expire :: dns:uint32(),
                          minimum :: dns:uint32()} |
          #dns_rrdata_spf{spf :: [binary()]} |
          #dns_rrdata_srv{priority :: dns:uint16(),
                          weight :: dns:uint16(),
                          port :: dns:uint16(),
                          target :: dns:dname()} |
          #dns_rrdata_svcb{svc_priority :: dns:uint16(),
                           target_name :: dns:dname(),
                           svc_params :: dns:svcb_svc_params()} |
          #dns_rrdata_sshfp{alg :: dns:uint8(), fp_type :: dns:uint8(), fp :: binary()} |
          #dns_rrdata_tsig{alg :: dns:tsig_alg(),
                           time :: dns:uint48(),
                           fudge :: dns:uint16(),
                           mac :: binary(),
                           msgid :: dns:uint16(),
                           err :: dns:uint16(),
                           other :: binary()} |
          #dns_rrdata_txt{txt :: [binary()]}.

rrdata_rrsig/0

-type rrdata_rrsig() ::
          #dns_rrdata_rrsig{type_covered :: dns:uint16(),
                            alg :: 3 | 5 | 6 | 7 | 8 | 10,
                            labels :: dns:uint8(),
                            original_ttl :: dns:uint32(),
                            expiration :: dns:uint32(),
                            inception :: dns:uint32(),
                            key_tag :: dns:uint16(),
                            signers_name :: dns:dname(),
                            signature :: binary()}.

svcb_svc_params/0

-type svcb_svc_params() :: #{1..6 => none | char() | binary()}.

tsig_alg/0

-type tsig_alg() :: binary().

tsig_error/0

-type tsig_error() :: 0 | 16..18.

tsig_mac/0

-type tsig_mac() :: binary().

tsig_opt/0

-type tsig_opt() ::
          {time, unix_time()} | {fudge, non_neg_integer()} | {mac, tsig_mac()} | {tail, boolean()}.

ttl/0

-type ttl() :: 0..1 bsl 31 - 1.

type/0

-type type() :: uint16().

uint2/0

-type uint2() :: 0..1.

uint4/0

-type uint4() :: 0..15.

uint8/0

-type uint8() :: 0..1 bsl 8 - 1.

uint16/0

-type uint16() :: 0..1 bsl 16 - 1.

uint32/0

-type uint32() :: 0..1 bsl 32 - 1.

uint48/0

-type uint48() :: 0..1 bsl 48 - 1.

uint64/0

-type uint64() :: 0..1 bsl 64 - 1.

unix_time/0

-type unix_time() :: 0..4294967295.

Functions

add_tsig(Msg, Alg, Name, Secret, ErrCode)

-spec add_tsig(message(), tsig_alg(), dname(), binary(), tsig_error()) -> message().

Equivalent to add_tsig(Msg, Alg, Name, Secret, ErrCode, []).

Generates and then appends a TSIG RR to a message. Supports MD5, SHA1, SHA224, SHA256, SHA384 and SHA512 algorithms.

add_tsig(Msg, Alg, Name, Secret, ErrCode, Options)

-spec add_tsig(message(), tsig_alg(), dname(), binary(), tsig_error(), [tsig_opt()]) -> message().

Generates and then appends a TSIG RR to a message. Supports MD5, SHA1, SHA224, SHA256, SHA384 and SHA512 algorithms.

alg_name(Int)

-spec alg_name(alg()) -> binary() | undefined.

Returns the name of a DNS algorithm as a binary string.

class_name(Int)

-spec class_name(class()) -> binary() | undefined.

Returns the name of the class as a binary string.

compare_dname(Name, NameB)

-spec compare_dname(dname(), dname()) -> boolean().

Compare two domain names insensitive of case.

const_compare(A, B)

-spec const_compare(dname(), dname()) -> boolean().

Compares two equal sized binaries over their entire length. Returns immediately if sizes do not match.

decode_message(MsgBin)

-spec decode_message(message_bin()) -> {decode_error(), message() | undefined, binary()} | message().

Decode a binary DNS message.

dname_to_labels(Name)

-spec dname_to_labels(dname()) -> [label()].

Splits a dname into a list of labels and removes unneeded escapes.

dname_to_lower(Bin)

-spec dname_to_lower(dname()) -> dname().

Returns provided name with case-insensitive characters in lowercase.

dname_to_upper(Bin)

-spec dname_to_upper(dname()) -> dname().

Returns provided name with case-insensitive characters in uppercase.

encode_message(Dns_message)

-spec encode_message(message()) -> message_bin().

Encode a dns_message record.

encode_message(Dns_message, Opts)

-spec encode_message(message(), [encode_message_opt()]) ->
                        {false, message_bin()} |
                        {true, message_bin(), message()} |
                        {false, message_bin(), tsig_mac()} |
                        {true, message_bin(), tsig_mac(), message()}.

Encode a dns_message record - will truncate the message as needed.

eoptcode_name(Int)

-spec eoptcode_name(eoptcode()) -> binary() | undefined.

Returns the name of an extended option as a binary string.

ercode_name(Int)

-spec ercode_name(ercode()) -> binary() | undefined.

Returns the name of an extended rcode as a binary string.

escape_label(Label)

-spec escape_label(label()) -> label().

Escapes dots in a DNS label

labels_to_dname(Labels)

-spec labels_to_dname([label()]) -> dname().

Joins a list of DNS labels, escaping where necessary.

llqerrcode_name(Int)

-spec llqerrcode_name(llqerrcode()) -> binary() | undefined.

Returns the name of an LLQ error code as a binary string.

llqopcode_name(Int)

-spec llqopcode_name(llqopcode()) -> binary() | undefined.

Returns the name of an LLQ opcode as a binary string.

opcode_name(Int)

-spec opcode_name(opcode()) -> binary() | undefined.

Returns the name of an opcode as a binary string.

random_id()

-spec random_id() -> message_id().

Returns a random integer suitable for use as DNS message identifier.

rcode_name(Int)

-spec rcode_name(rcode()) -> binary() | undefined.

Returns the name of an rcode as a binary string.

tsigerr_name(Int)

-spec tsigerr_name(tsig_error()) -> binary() | undefined.

Returns the name of a TSIG error as a binary string.

type_name(Int)

-spec type_name(type()) -> binary() | undefined.

Returns the name of the type as a binary string.

unix_time()

-spec unix_time() -> unix_time().

Return current unix time.

unix_time(NowTime)

-spec unix_time(erlang:timestamp() | calendar:datetime1970()) -> unix_time().

Return the unix time from a now or universal time.

verify_tsig(MsgBin, Name, Secret)

-spec verify_tsig(message_bin(), dname(), binary()) -> {ok, tsig_mac()} | {error, tsig_error()}.

Equivalent to verify_tsig(MsgBin, Name, Secret, []).

verify_tsig(MsgBin, Name, Secret, Options)

-spec verify_tsig(message_bin(), dname(), binary(), [tsig_opt()]) ->
                     {ok, tsig_mac()} | {error, tsig_error()}.

Verifies a TSIG message signature.