Module Dns_server

The main purpose of this module is to provide an implementation of a standard DNS server based on Dns.Query and Dns.Loader.

For a basic DNS server, call process_of_zonebuf, pass the result to processor_of_process, and then invoke the resulting processor function for each received packet.

This module also provides a way to override the parsing and marshaling of DNS packets to allow extensions of DNS to be implemented, such as DNSCurve.

type ip_endpoint = Ipaddr.t * int

A tuple consisting of an IPv4 or IPv6 address and a TCP or UDP port number.

type 'a process = src:ip_endpoint -> dst:ip_endpoint -> 'a -> Dns.Query.answer option Lwt.t

A type of function that takes an abstract request plus source and destination endpoint addresses, and asynchronously produces an answer to the request, or None if no answer is possible. For most applications the type 'a will be Dns.Packet.t, but may be different if a custom parsing/marshalling layer is required.

module type PROCESSOR : sig ... end

This type of module provides functions for parsing, marshalling and processing DNS requests to produce answers.

type 'a processor = (module PROCESSOR)
val compose : Dns.Packet.t process -> Dns.Packet.t process -> Dns.Packet.t process

compose process backup_process is process unless it returns an rcode other than NoError in which case it becomes backup_process.

val process_query : Dns.Buf.t -> int -> Dns.Buf.t -> ip_endpoint -> ip_endpoint -> (module PROCESSOR) -> Dns.Buf.t option Lwt.t

process_query ibuf ibuflen obuf src dst processor

val processor_of_process : Dns.Packet.t process -> Dns.Packet.t processor

Returns a packet processor module by combining Dns.Protocol.Server with the specified packet processing function.

val process_of_zonebufs : string list -> Dns.Packet.t process

Given a list of DNS zone files as strings, parses them using Dns.Loader and returns a processing function that answers requests through the use of Dns.Query.

val process_of_zonebuf : string -> Dns.Packet.t process

This is a convenience function that is equivalent to calling process_of_zonebufs with a list containing a single zone file string.