package dns

  1. Overview
  2. Docs

A map whose keys are record types and their values are the time-to-live and the record set. The relation between key and value type is restricted by the below defined GADT.

module Mx_set : Set.S with type elt = Mx.t
module Txt_set : Set.S with type elt = Txt.t
module Srv_set : Set.S with type elt = Srv.t
module Dnskey_set : Set.S with type elt = Dnskey.t
module Caa_set : Set.S with type elt = Caa.t
module Tlsa_set : Set.S with type elt = Tlsa.t
module Sshfp_set : Set.S with type elt = Sshfp.t
module Ds_set : Set.S with type elt = Ds.t
module Rrsig_set : Set.S with type elt = Rrsig.t
module I : sig ... end
type 'a with_ttl = int32 * 'a

A tuple type whose first component is a time-to-live counter in seconds.

type _ rr =
  1. | Soa : Soa.t rr
  2. | Ns : Domain_name.Host_set.t with_ttl rr
  3. | Mx : Mx_set.t with_ttl rr
  4. | Cname : Cname.t with_ttl rr
  5. | A : Ipaddr.V4.Set.t with_ttl rr
  6. | Aaaa : Ipaddr.V6.Set.t with_ttl rr
  7. | Ptr : Ptr.t with_ttl rr
  8. | Srv : Srv_set.t with_ttl rr
  9. | Dnskey : Dnskey_set.t with_ttl rr
  10. | Caa : Caa_set.t with_ttl rr
  11. | Tlsa : Tlsa_set.t with_ttl rr
  12. | Sshfp : Sshfp_set.t with_ttl rr
  13. | Txt : Txt_set.t with_ttl rr
  14. | Ds : Ds_set.t with_ttl rr
  15. | Rrsig : Rrsig_set.t with_ttl rr
  16. | Nsec : Nsec.t with_ttl rr
  17. | Nsec3 : Nsec3.t with_ttl rr
  18. | Unknown : I.t -> Txt_set.t with_ttl rr
    (*

    The type of resource record sets, as GADT: the value depends on the specific constructor. There may only be a single SOA and Cname and Ptr record, while other constructors, such as address (A), contain a set of the respective types. The Unknown constructor is used for not specifically supported records. These resource records are usually persisted to disk by a server or resolver. Resource records that are only meant for a single transaction (such as EDNS or TSIG) are not in this GADT, neither is the query type ANY (which answer is computed on the fly), or zone transfer operations (AXFR/IXFR).

    *)
module K : Gmap.KEY with type 'a t = 'a rr
include Gmap.S with type 'a key = 'a rr
type 'a key = 'a rr

The type for map keys whose lookup value is 'a.

type t

The type of maps from type 'a key to 'a.

Constructors

val empty : t

empty is the empty map.

val singleton : 'a key -> 'a -> t

singleton key value creates a one-element map that contains a binding value for key.

Basic operations

val is_empty : t -> bool

is_empty m returns true if the map m is empty, false otherwise.

val cardinal : t -> int

cardinal m returns the number of bindings of the map m.

Lookup operations

val mem : 'a key -> t -> bool

mem key m returns true if the map m contains a binding for key.

val find : 'a key -> t -> 'a option

find key m returns Some v if the binding of key in m is v, or None if key is not bound m.

val get : 'a key -> t -> 'a

find key m returns v if the binding of key in m is v.

  • raises Not_found

    if m does not contain a binding for key.

Insertion and removal operations

val add_unless_bound : 'a key -> 'a -> t -> t option

add_unless_bound key value m returns Some m', a map containing the same bindings as m, plus a binding of key to value. Or, None if key was already bound in m.

val add : 'a key -> 'a -> t -> t

add key value m returns a map containing the same bindings as m, plus a binding of key to value. If key was already bound in m, the previous binding disappears.

val remove : 'a key -> t -> t

remove key m returns a map containing the same bindings as m, except for key which is not bound in the returned map. If key was not bound in m, m is returned unchanged.

val update : 'a key -> ('a option -> 'a option) -> t -> t

update k f m returns a map containing the same bindings as m, except for the binding v of k. Depending the value of v, which is f (find k m), the binding of k is added, removed, or updated.

Bindings

type b =
  1. | B : 'a key * 'a -> b
    (*

    The type for a binding: a pair containing a key and its value.

    *)

Selection of bindings

val min_binding : t -> b option

min_binding m is the minimal binding in m, None if m is empty.

val max_binding : t -> b option

max_binding m is the maximal binding in m, None if m is empty.

val any_binding : t -> b option

any_binding m is any binding in m, None if m is empty.

val bindings : t -> b list

bindings m returns the list of all bindings in the given map m. The list is sorted with respect to the ordering over the type of the keys.

Higher-order functions

type eq = {
  1. f : 'a. 'a key -> 'a -> 'a -> bool;
}

The function type for the equal operation, using a record type for "first-class" semi-explicit polymorphism.

val equal : eq -> t -> t -> bool

equal p m m' tests whether the maps m and m' are equal, that is contain equal keys and associate them with equal data. p is the equality predicate used to compare the data associated with the keys.

type mapper = {
  1. f : 'a. 'a key -> 'a -> 'a;
}

The function type for the map operation, using a record type for "first-class" semi-explicit polymorphism.

val map : mapper -> t -> t

map f m returns a map with the same domain as m, where the associated binding b has been replaced by the result of the application of f to b. The bindings are passed to f in increasing order with respect to the ordering over the type of the keys.

val iter : (b -> unit) -> t -> unit

iter f m applies f to all bindings in m. The bindings are passed in increasing order with respect to the ordering over the type of keys.

val fold : (b -> 'a -> 'a) -> t -> 'a -> 'a

fold f m acc computes (f bN .. (f b1 acc)), where b1 .. bN are the bindings of m in increasing order with respect to the ordering over the type of the keys.

val for_all : (b -> bool) -> t -> bool

for_all p m checks if all bindings of the map m satisfy the predicate p.

val exists : (b -> bool) -> t -> bool

exists p m checks if at least one binding of the map m satisfies p.

val filter : (b -> bool) -> t -> t

filter p m returns the map with all the bindings in m that satisfy p.

type merger = {
  1. f : 'a. 'a key -> 'a option -> 'a option -> 'a option;
}

The function type for the merge operation, using a record type for "first-class" semi-explicit polymorphism.

val merge : merger -> t -> t -> t

merge f m m' computes a map whose keys is a subset of keys of m and m'. The presence of each such binding, and the corresponding value, is determined with the function f.

type unionee = {
  1. f : 'a. 'a key -> 'a -> 'a -> 'a option;
}

The function type for the union operation, using a record type for "first-class" semi-explicit polymorphism.

val union : unionee -> t -> t -> t

union f m m' computes a map whose keys is the union of the keys of m and m'. When the same binding is defined in both maps, the function f is used to combine them.

val equal_rr : 'a key -> 'a -> 'a -> bool

equal_rr k v v' is true if v = v', false otherwise.

val equalb : b -> b -> bool

equalb b b' is true if the bindings are equal.

type k =
  1. | K : 'a key -> k
    (*

    The monomorphic type of keys.

    *)
val comparek : k -> k -> int

comparek k k' compares k with k' using the defined ordering.

val ppk : k Fmt.t

ppk ppf k pretty-prints k.

val of_int : ?off:int -> int -> (k, [> `Malformed of int * string ]) result

of_int ~off i constructs a k of the provided integer.

val to_int : 'a key -> int

to_int k is the integer representing the key k.

val of_string : string -> (k, [> `Msg of string ]) result

of_string i constructs a k of the provided string.

val names : 'a key -> 'a -> Domain_name.Host_set.t

names k v are the referenced domain names in the given binding.

val pp_b : b Fmt.t

pp_b ppf b pretty-prints the binding b.

val text_b : ?origin:'a Domain_name.t -> ?default_ttl:int32 -> 'b Domain_name.t -> b -> string

text_b ~origin ~default_ttl domain-name binding is the zone file format of binding using domain-name.

val remove_rr : 'a key -> 'a -> 'a -> 'a option

remove_rr k v rem removes rem from v. If the result is an empty set, None is returned.

val union_rr : 'a key -> 'a -> 'a -> 'a

union_rr k l r builds the union of l with r. A potential r Soa or Cname overwrites its l counterpart.

val unionee : 'a key -> 'a -> 'a -> 'a option

unionee k l r unions l with r using union_rr.

val diff : old:t -> t -> t option * t option

diff ~old m computes the difference between old and m. The left projection are the deleted entries, the right projection are the added entries. Soa entries are ignored.

val text : ?origin:'a Domain_name.t -> ?default_ttl:int32 -> 'b Domain_name.t -> 'c rr -> 'c -> string

text ~origin ~default_ttl name k v is the zone file data for k, v.

val ttl : 'a key -> 'a -> int32

get_ttl k v returns the time-to-live of v.

val with_ttl : 'a key -> 'a -> int32 -> 'a

with_ttl k v ttl updates ttl in v.

val prep_for_sig : [ `raw ] Domain_name.t -> Rrsig.t -> 'a key -> 'a -> ([ `raw ] Domain_name.t * Cstruct.t, [ `Msg of string ]) result
val canonical_encoded_name : [ `raw ] Domain_name.t -> Cstruct.t
OCaml

Innovation. Community. Security.