dnsbase
Copyright(c) IIJ Innovation Institute Inc. 2009
(c) Viktor Dukhovni 2020-2026
LicenseBSD-3-Clause
Maintainerietf-dane@dukhovni.org
Stabilityunstable
Safe HaskellNone
LanguageGHC2024

Net.DNSBase.Resolver

Description

The resolver is built in three stages:

  1. ResolverConf carries the caller's choices: nameserver source, per-attempt timeout, retry budget, default QueryControls, and any user-registered RR-type or EDNS option codecs. Build one by adjusting fields of defaultResolvConf.
  2. makeResolvSeed turns a ResolverConf into a ResolvSeed: nameserver hostnames are resolved to addresses, and the user's codec registrations are merged with the library's built-in defaults. The seed is immutable and safe to share across threads.
  3. withResolver produces a per-thread Resolver handle from a shared seed. A Resolver carries thread-local mutable state (a CSPRNG for query IDs) and must not be shared between threads — programs that issue queries concurrently should call withResolver once per worker thread.

A minimal example:

main :: IO ()
main = do
    seed <- makeResolvSeed defaultResolvConf >>= either throwIO pure
    withResolver seed \ r ->
        lookupA r $$(dnLit8 "example.com") >>= \ case
            Left  e -> throwIO e
            Right a -> print a

The codec set baked into the seed can be extended at conf-build time via registerRRtype / registerEdnsOption (new RR-type or EDNS-option codecs) and the four extendRRwithType extendRRwithValue extendEdnsOptionWithType / extendEdnsOptionWithValue combinators (extensions onto codecs that admit them). See Net.DNSBase.Extensible for worked examples.

Synopsis

Resolver configuration

data ResolverConf Source #

User-supplied resolver configuration. Carries the caller's choices: where nameservers come from, the per-attempt timeout and retry budget, default QueryControls, and any user-registered RR-type / EDNS option codecs. Built-in defaults are not stored here — they are merged into the effective configuration only when makeResolvSeed produces a ResolvSeed.

defaultResolvConf :: ResolverConf Source #

Default resolver configuration, with nameserver list from /etc/resolv.conf and no user-registered codec extensions.

data NameserverConf Source #

Configuration file name, or explicit list of addresses/hostnames.

data NameserverSpec Source #

Nameserver address string or hostname, with optional port.

Resolver seed

data ResolvSeed Source #

Resolved, immutable resolver state built by makeResolvSeed from a ResolverConf. Combines the user's choices with the library's built-in defaults: resolved nameserver addresses, and the effective RR-type and EDNS-option codec maps with user-registered code points overriding the library defaults (except at a small set of protected code points, where attempted user overrides are silently ignored).

A ResolvSeed is safe to share across threads; each query-issuing thread should call withResolver on the same seed to obtain its own per-thread Resolver handle.

makeResolvSeed :: ResolverConf -> IO (Either DNSError ResolvSeed) Source #

Build a ResolvSeed from a ResolverConf. The seed is immutable and safely shared across threads; each thread then calls withResolver to obtain its own Resolver.

The configured nameservers are resolved to socket addresses, and the user's codec registrations (from registerRRtype, extendRRwithType and registerEdnsOption) are combined with the library's built-in codec set. At each RR-type or EDNS option code point, the user-registered codec takes precedence over the library default — except at a small set of protected code points (e.g. the SVCB mandatory key), where any attempted user override is silently ignored.

Returns Left err if the configured nameservers cannot be resolved or the configuration file cannot be parsed.

Example:

>>> seed <- makeResolvSeed defaultResolvConf >>= either throwIO pure

Resolver instance

data Resolver Source #

Internal DNS Resolver handle, obtained via withResolver. Must not be used concurrently in multiple threads.

withResolver :: ResolvSeed -> (Resolver -> IO a) -> IO a Source #

Provide a Resolver to the supplied action. Concurrent use of a single Resolver is not supported: the handle carries internal mutable state and the library makes no soundness guarantees if it is shared across threads. Programs that issue queries from multiple threads must call withResolver once per worker thread (typically inside forkIO) to obtain a separate handle. The ResolvSeed itself is immutable and is the right object to share across threads.

The action runs in plain IO; DNS-protocol errors from individual lookups appear in the Either DNSError a return shape of each lookup function inside the action. This function does not itself produce or propagate DNSErrors.

Look up RRTYPE by name.

data RRtypeNames Source #

Mapping from RRTYPE name to RRTYPE code.

confTypeNames :: Maybe ResolvSeed -> RRtypeNames Source #

Construct a map of type names to RRTYPE from a given ResolvSeed value. This will include both the names of all the registered known types and the names of all known RRtypes, whether implemented or not.

The map is is not cached, compute it once and reuse for repeated queries.

rrtypeLookup :: ByteString -> RRtypeNames -> Maybe RRTYPE Source #

Attempt to find an RRTYPE' by name. The lookup map can be constructed via confTypeNames, and should be reused for multiple lookups when possible.

  • The input name is not case-senstive.
  • Names of the form TYPEnum (with num the type number) are supported, and return the corresponding RRTYPE.

Controls.

Query controls.

data QueryControls where Source #

Query controls consisting of an endomorphism over FlagOps to modify DNS flag bits, and an EdnsControls structure to configure EDNS behavior.

Constitutes a Monoid with left-biased mappend operation

Bundled Patterns

pattern EdnsDisabled :: QueryControls

Disable EDNS for this query. When EDNS is disabled, the OPT pseudo-RR is omitted from the outgoing query and the other EDNS-related tweaks (EdnsVersion, EdnsUdpSize, EdnsOptionCtl) have no effect on the wire.

pattern EdnsEnabled :: QueryControls

Enable EDNS for this query, overriding the resolver default if it had EDNS disabled. The OPT pseudo-RR is included in the outgoing query.

pattern EdnsOptionCtl

Carry a per-call modification of the OPT pseudo-RR's EDNS option list as an endomorphism OptionCtl -> OptionCtl. The endomorphism is applied to the resolver's ambient option list at query-build time, so callers express deltas — clear everything, add an option, replace an option — rather than full replacements.

optCtlAdd and optCtlSet are the standard ways to build the endomorphism. For example, to opt out of geolocation-tailored answers for a single query by signalling "do not use my subnet" via ECS with a zero-length source prefix (RFC 7871 section 7.1.2):

let noEcs = EdnsOptionCtl
          $ optCtlAdd [ EdnsOption
                      $ O_ECS 0 0 (IPv4 (toIPv4 [0,0,0,0])) ]
 in lookupAnswers rslv noEcs IN A $$(dnLit8 "example.org")

optCtlAdd replaces the resolver's existing ECS option (if any) with this one because they share an OPTCODE; other options the resolver had configured pass through untouched. optCtlSet would instead clear the entire option list and use only the supplied options.

Fields

pattern EdnsUdpSize

Override the maximum UDP payload size the client advertises to the server for this query. The value is clamped to the minUdpSize / maxUdpSize range.

Fields

pattern EdnsVersion

Override the EDNS version advertised in the OPT pseudo-RR for this query. Only version 0 is specified, and versions other than 0 are unlikely to be interoperable at present.

Fields

pattern QctlFlags

Apply the requested DNS flag operation, setting or clearing the requested flag bits, or restoring defaults.

Fields

data EdnsControls Source #

EDNS query controls. When EDNS is disabled via ednsEnabled FlagClear, all the other EDNS-related overrides have no effect. Semigroup append is left-biased

Extending the codec set.

The resolver knows about a set of RR-type and EDNS-option codecs at conf-build time. registerRRtype and registerEdnsOption install a fresh codec entry at the type's default extension value; the four extendRRwithType extendRRwithValue extendEdnsOptionWithType / extendEdnsOptionWithValue combinators fold typed or value-driven extensions onto an already-extensible codec's existing entry. See Net.DNSBase.Extensible for worked examples and the design behind the two extension flavours.

User registrations take precedence over the library's built-in codec set, except at a small number of protected code points (e.g. the SVCB mandatory key), where attempted user additions are silently ignored.

class TypeExtensible a v where Source #

RR-data or EDNS-option types whose codec admits a type-driven extension. See Adding a custom RR type for an example of this mechanism in use, and Writing a type-driven extensible codec for the steps to implement a type-driven extensible codec of your own.

Associated Types

type TypeExtensionArg a b Source #

Constraint a caller's extension type b must satisfy.

Methods

extendByType :: forall t b -> (t ~ a, TypeExtensionArg t b) => v -> v Source #

Fold a caller's extension type b into the existing codec context value of type v.

class (Typeable a, Eq a, Ord a, Show a, Presentable a) => KnownRData a where Source #

Abstract DNS Resource Record (type-specific) data.

The decoding, encoding and presentation functions are responsible for just the value, presentation of the associated RR type defaults to the built-in names, for novel types override rdTypePres.

The Show instance is typically derived, and will output the type constructor (its output strives to produce syntactically valid Haskell values), in contrast with Presentable which produces RFC-standard presentation forms.

Minimal complete definition

rdType, rdDecode, rdEncode

Associated Types

type RDataExtensionVal a Source #

The codec-consumed extension value for type a. Defaults to (). Types with non-trivial extension data (SVCB and HTTPS, which carry the SvcParam decoder map) supply their own associated-type definition.

type RDataExtensionVal a = ()

Methods

rdataExtensionVal :: forall b -> b ~ a => RDataExtensionVal a Source #

The library's built-in starting RDataExtensionVal for type a. Used as the baseline when the library installs its built-in registration for a, and as the starting point when the user extends the codec for a. For RDataExtensionVal a ~ () types the class default applies.

default rdataExtensionVal :: RDataExtensionVal a ~ () => forall b -> b ~ a => RDataExtensionVal a Source #

rdType :: forall b -> b ~ a => RRTYPE Source #

rdTypePres :: forall b -> b ~ a => Builder -> Builder Source #

rdDecode :: forall b -> b ~ a => RDataExtensionVal a -> Int -> SGet RData Source #

rdEncode :: a -> SPut s RData Source #

cnEncode :: a -> SPut s RData Source #

Instances

Instances details
KnownRData T_a Source # 
Instance details

Defined in Net.DNSBase.RData.A

Associated Types

type RDataExtensionVal T_a 
Instance details

Defined in Net.DNSBase.RData.A

Methods

rdataExtensionVal :: forall b -> b ~ T_a => RDataExtensionVal T_a Source #

rdType :: forall b -> b ~ T_a => RRTYPE Source #

rdTypePres :: forall b -> b ~ T_a => Builder -> Builder Source #

rdDecode :: forall b -> b ~ T_a => RDataExtensionVal T_a -> Int -> SGet RData Source #

rdEncode :: T_a -> SPut s RData Source #

cnEncode :: T_a -> SPut s RData Source #

KnownRData T_aaaa Source # 
Instance details

Defined in Net.DNSBase.RData.A

Associated Types

type RDataExtensionVal T_aaaa 
Instance details

Defined in Net.DNSBase.RData.A

KnownRData T_caa Source # 
Instance details

Defined in Net.DNSBase.RData.CAA

Associated Types

type RDataExtensionVal T_caa 
Instance details

Defined in Net.DNSBase.RData.CAA

Methods

rdataExtensionVal :: forall b -> b ~ T_caa => RDataExtensionVal T_caa Source #

rdType :: forall b -> b ~ T_caa => RRTYPE Source #

rdTypePres :: forall b -> b ~ T_caa => Builder -> Builder Source #

rdDecode :: forall b -> b ~ T_caa => RDataExtensionVal T_caa -> Int -> SGet RData Source #

rdEncode :: T_caa -> SPut s RData Source #

cnEncode :: T_caa -> SPut s RData Source #

KnownRData T_csync Source # 
Instance details

Defined in Net.DNSBase.RData.CSYNC

Associated Types

type RDataExtensionVal T_csync 
Instance details

Defined in Net.DNSBase.RData.CSYNC

KnownRData T_dsync Source # 
Instance details

Defined in Net.DNSBase.RData.CSYNC

Associated Types

type RDataExtensionVal T_dsync 
Instance details

Defined in Net.DNSBase.RData.CSYNC

KnownRData T_ipseckey Source # 
Instance details

Defined in Net.DNSBase.RData.Dnssec

Associated Types

type RDataExtensionVal T_ipseckey 
Instance details

Defined in Net.DNSBase.RData.Dnssec

KnownRData T_zonemd Source # 
Instance details

Defined in Net.DNSBase.RData.Dnssec

Associated Types

type RDataExtensionVal T_zonemd 
Instance details

Defined in Net.DNSBase.RData.Dnssec

KnownRData T_dname Source #

Name compression used on input only.

Instance details

Defined in Net.DNSBase.RData.Internal.XNAME

Associated Types

type RDataExtensionVal T_dname 
Instance details

Defined in Net.DNSBase.RData.Internal.XNAME

KnownRData T_nsec Source # 
Instance details

Defined in Net.DNSBase.RData.NSEC

Associated Types

type RDataExtensionVal T_nsec 
Instance details

Defined in Net.DNSBase.RData.NSEC

KnownRData T_nsec3 Source # 
Instance details

Defined in Net.DNSBase.RData.NSEC

Associated Types

type RDataExtensionVal T_nsec3 
Instance details

Defined in Net.DNSBase.RData.NSEC

KnownRData T_nsec3param Source # 
Instance details

Defined in Net.DNSBase.RData.NSEC

Associated Types

type RDataExtensionVal T_nsec3param 
Instance details

Defined in Net.DNSBase.RData.NSEC

KnownRData T_nxt Source # 
Instance details

Defined in Net.DNSBase.RData.NSEC

Associated Types

type RDataExtensionVal T_nxt 
Instance details

Defined in Net.DNSBase.RData.NSEC

Methods

rdataExtensionVal :: forall b -> b ~ T_nxt => RDataExtensionVal T_nxt Source #

rdType :: forall b -> b ~ T_nxt => RRTYPE Source #

rdTypePres :: forall b -> b ~ T_nxt => Builder -> Builder Source #

rdDecode :: forall b -> b ~ T_nxt => RDataExtensionVal T_nxt -> Int -> SGet RData Source #

rdEncode :: T_nxt -> SPut s RData Source #

cnEncode :: T_nxt -> SPut s RData Source #

KnownRData T_a6 Source # 
Instance details

Defined in Net.DNSBase.RData.Obsolete

Associated Types

type RDataExtensionVal T_a6 
Instance details

Defined in Net.DNSBase.RData.Obsolete

Methods

rdataExtensionVal :: forall b -> b ~ T_a6 => RDataExtensionVal T_a6 Source #

rdType :: forall b -> b ~ T_a6 => RRTYPE Source #

rdTypePres :: forall b -> b ~ T_a6 => Builder -> Builder Source #

rdDecode :: forall b -> b ~ T_a6 => RDataExtensionVal T_a6 -> Int -> SGet RData Source #

rdEncode :: T_a6 -> SPut s RData Source #

cnEncode :: T_a6 -> SPut s RData Source #

KnownRData T_gpos Source # 
Instance details

Defined in Net.DNSBase.RData.Obsolete

Associated Types

type RDataExtensionVal T_gpos 
Instance details

Defined in Net.DNSBase.RData.Obsolete

KnownRData T_isdn Source # 
Instance details

Defined in Net.DNSBase.RData.Obsolete

Associated Types

type RDataExtensionVal T_isdn 
Instance details

Defined in Net.DNSBase.RData.Obsolete

KnownRData T_kx Source # 
Instance details

Defined in Net.DNSBase.RData.Obsolete

Associated Types

type RDataExtensionVal T_kx 
Instance details

Defined in Net.DNSBase.RData.Obsolete

Methods

rdataExtensionVal :: forall b -> b ~ T_kx => RDataExtensionVal T_kx Source #

rdType :: forall b -> b ~ T_kx => RRTYPE Source #

rdTypePres :: forall b -> b ~ T_kx => Builder -> Builder Source #

rdDecode :: forall b -> b ~ T_kx => RDataExtensionVal T_kx -> Int -> SGet RData Source #

rdEncode :: T_kx -> SPut s RData Source #

cnEncode :: T_kx -> SPut s RData Source #

KnownRData T_minfo Source # 
Instance details

Defined in Net.DNSBase.RData.Obsolete

Associated Types

type RDataExtensionVal T_minfo 
Instance details

Defined in Net.DNSBase.RData.Obsolete

KnownRData T_nsap Source # 
Instance details

Defined in Net.DNSBase.RData.Obsolete

Associated Types

type RDataExtensionVal T_nsap 
Instance details

Defined in Net.DNSBase.RData.Obsolete

KnownRData T_nsapptr Source # 
Instance details

Defined in Net.DNSBase.RData.Obsolete

Associated Types

type RDataExtensionVal T_nsapptr 
Instance details

Defined in Net.DNSBase.RData.Obsolete

KnownRData T_px Source # 
Instance details

Defined in Net.DNSBase.RData.Obsolete

Associated Types

type RDataExtensionVal T_px 
Instance details

Defined in Net.DNSBase.RData.Obsolete

Methods

rdataExtensionVal :: forall b -> b ~ T_px => RDataExtensionVal T_px Source #

rdType :: forall b -> b ~ T_px => RRTYPE Source #

rdTypePres :: forall b -> b ~ T_px => Builder -> Builder Source #

rdDecode :: forall b -> b ~ T_px => RDataExtensionVal T_px -> Int -> SGet RData Source #

rdEncode :: T_px -> SPut s RData Source #

cnEncode :: T_px -> SPut s RData Source #

KnownRData T_rt Source # 
Instance details

Defined in Net.DNSBase.RData.Obsolete

Associated Types

type RDataExtensionVal T_rt 
Instance details

Defined in Net.DNSBase.RData.Obsolete

Methods

rdataExtensionVal :: forall b -> b ~ T_rt => RDataExtensionVal T_rt Source #

rdType :: forall b -> b ~ T_rt => RRTYPE Source #

rdTypePres :: forall b -> b ~ T_rt => Builder -> Builder Source #

rdDecode :: forall b -> b ~ T_rt => RDataExtensionVal T_rt -> Int -> SGet RData Source #

rdEncode :: T_rt -> SPut s RData Source #

cnEncode :: T_rt -> SPut s RData Source #

KnownRData T_x25 Source # 
Instance details

Defined in Net.DNSBase.RData.Obsolete

Associated Types

type RDataExtensionVal T_x25 
Instance details

Defined in Net.DNSBase.RData.Obsolete

Methods

rdataExtensionVal :: forall b -> b ~ T_x25 => RDataExtensionVal T_x25 Source #

rdType :: forall b -> b ~ T_x25 => RRTYPE Source #

rdTypePres :: forall b -> b ~ T_x25 => Builder -> Builder Source #

rdDecode :: forall b -> b ~ T_x25 => RDataExtensionVal T_x25 -> Int -> SGet RData Source #

rdEncode :: T_x25 -> SPut s RData Source #

cnEncode :: T_x25 -> SPut s RData Source #

KnownRData T_rp Source # 
Instance details

Defined in Net.DNSBase.RData.SOA

Associated Types

type RDataExtensionVal T_rp 
Instance details

Defined in Net.DNSBase.RData.SOA

Methods

rdataExtensionVal :: forall b -> b ~ T_rp => RDataExtensionVal T_rp Source #

rdType :: forall b -> b ~ T_rp => RRTYPE Source #

rdTypePres :: forall b -> b ~ T_rp => Builder -> Builder Source #

rdDecode :: forall b -> b ~ T_rp => RDataExtensionVal T_rp -> Int -> SGet RData Source #

rdEncode :: T_rp -> SPut s RData Source #

cnEncode :: T_rp -> SPut s RData Source #

KnownRData T_soa Source # 
Instance details

Defined in Net.DNSBase.RData.SOA

Associated Types

type RDataExtensionVal T_soa 
Instance details

Defined in Net.DNSBase.RData.SOA

Methods

rdataExtensionVal :: forall b -> b ~ T_soa => RDataExtensionVal T_soa Source #

rdType :: forall b -> b ~ T_soa => RRTYPE Source #

rdTypePres :: forall b -> b ~ T_soa => Builder -> Builder Source #

rdDecode :: forall b -> b ~ T_soa => RDataExtensionVal T_soa -> Int -> SGet RData Source #

rdEncode :: T_soa -> SPut s RData Source #

cnEncode :: T_soa -> SPut s RData Source #

KnownRData T_afsdb Source # 
Instance details

Defined in Net.DNSBase.RData.SRV

Associated Types

type RDataExtensionVal T_afsdb 
Instance details

Defined in Net.DNSBase.RData.SRV

KnownRData T_amtrelay Source # 
Instance details

Defined in Net.DNSBase.RData.SRV

Associated Types

type RDataExtensionVal T_amtrelay 
Instance details

Defined in Net.DNSBase.RData.SRV

KnownRData T_l32 Source # 
Instance details

Defined in Net.DNSBase.RData.SRV

Associated Types

type RDataExtensionVal T_l32 
Instance details

Defined in Net.DNSBase.RData.SRV

Methods

rdataExtensionVal :: forall b -> b ~ T_l32 => RDataExtensionVal T_l32 Source #

rdType :: forall b -> b ~ T_l32 => RRTYPE Source #

rdTypePres :: forall b -> b ~ T_l32 => Builder -> Builder Source #

rdDecode :: forall b -> b ~ T_l32 => RDataExtensionVal T_l32 -> Int -> SGet RData Source #

rdEncode :: T_l32 -> SPut s RData Source #

cnEncode :: T_l32 -> SPut s RData Source #

KnownRData T_lp Source # 
Instance details

Defined in Net.DNSBase.RData.SRV

Associated Types

type RDataExtensionVal T_lp 
Instance details

Defined in Net.DNSBase.RData.SRV

Methods

rdataExtensionVal :: forall b -> b ~ T_lp => RDataExtensionVal T_lp Source #

rdType :: forall b -> b ~ T_lp => RRTYPE Source #

rdTypePres :: forall b -> b ~ T_lp => Builder -> Builder Source #

rdDecode :: forall b -> b ~ T_lp => RDataExtensionVal T_lp -> Int -> SGet RData Source #

rdEncode :: T_lp -> SPut s RData Source #

cnEncode :: T_lp -> SPut s RData Source #

KnownRData T_mx Source # 
Instance details

Defined in Net.DNSBase.RData.SRV

Associated Types

type RDataExtensionVal T_mx 
Instance details

Defined in Net.DNSBase.RData.SRV

Methods

rdataExtensionVal :: forall b -> b ~ T_mx => RDataExtensionVal T_mx Source #

rdType :: forall b -> b ~ T_mx => RRTYPE Source #

rdTypePres :: forall b -> b ~ T_mx => Builder -> Builder Source #

rdDecode :: forall b -> b ~ T_mx => RDataExtensionVal T_mx -> Int -> SGet RData Source #

rdEncode :: T_mx -> SPut s RData Source #

cnEncode :: T_mx -> SPut s RData Source #

KnownRData T_naptr Source # 
Instance details

Defined in Net.DNSBase.RData.SRV

Associated Types

type RDataExtensionVal T_naptr 
Instance details

Defined in Net.DNSBase.RData.SRV

KnownRData T_srv Source # 
Instance details

Defined in Net.DNSBase.RData.SRV

Associated Types

type RDataExtensionVal T_srv 
Instance details

Defined in Net.DNSBase.RData.SRV

Methods

rdataExtensionVal :: forall b -> b ~ T_srv => RDataExtensionVal T_srv Source #

rdType :: forall b -> b ~ T_srv => RRTYPE Source #

rdTypePres :: forall b -> b ~ T_srv => Builder -> Builder Source #

rdDecode :: forall b -> b ~ T_srv => RDataExtensionVal T_srv -> Int -> SGet RData Source #

rdEncode :: T_srv -> SPut s RData Source #

cnEncode :: T_srv -> SPut s RData Source #

KnownRData T_openpgpkey Source # 
Instance details

Defined in Net.DNSBase.RData.TLSA

Associated Types

type RDataExtensionVal T_openpgpkey 
Instance details

Defined in Net.DNSBase.RData.TLSA

KnownRData T_sshfp Source # 
Instance details

Defined in Net.DNSBase.RData.TLSA

Associated Types

type RDataExtensionVal T_sshfp 
Instance details

Defined in Net.DNSBase.RData.TLSA

KnownRData T_hinfo Source # 
Instance details

Defined in Net.DNSBase.RData.TXT

Associated Types

type RDataExtensionVal T_hinfo 
Instance details

Defined in Net.DNSBase.RData.TXT

KnownRData T_null Source # 
Instance details

Defined in Net.DNSBase.RData.TXT

Associated Types

type RDataExtensionVal T_null 
Instance details

Defined in Net.DNSBase.RData.TXT

KnownRData T_txt Source # 
Instance details

Defined in Net.DNSBase.RData.TXT

Associated Types

type RDataExtensionVal T_txt 
Instance details

Defined in Net.DNSBase.RData.TXT

Methods

rdataExtensionVal :: forall b -> b ~ T_txt => RDataExtensionVal T_txt Source #

rdType :: forall b -> b ~ T_txt => RRTYPE Source #

rdTypePres :: forall b -> b ~ T_txt => Builder -> Builder Source #

rdDecode :: forall b -> b ~ T_txt => RDataExtensionVal T_txt -> Int -> SGet RData Source #

rdEncode :: T_txt -> SPut s RData Source #

cnEncode :: T_txt -> SPut s RData Source #

KnownRData T_wks Source # 
Instance details

Defined in Net.DNSBase.RData.WKS

Associated Types

type RDataExtensionVal T_wks 
Instance details

Defined in Net.DNSBase.RData.WKS

Methods

rdataExtensionVal :: forall b -> b ~ T_wks => RDataExtensionVal T_wks Source #

rdType :: forall b -> b ~ T_wks => RRTYPE Source #

rdTypePres :: forall b -> b ~ T_wks => Builder -> Builder Source #

rdDecode :: forall b -> b ~ T_wks => RDataExtensionVal T_wks -> Int -> SGet RData Source #

rdEncode :: T_wks -> SPut s RData Source #

cnEncode :: T_wks -> SPut s RData Source #

Nat16 n => KnownRData (OpaqueRData n) Source # 
Instance details

Defined in Net.DNSBase.Internal.RData

Associated Types

type RDataExtensionVal (OpaqueRData n) 
Instance details

Defined in Net.DNSBase.Internal.RData

(Nat16 n, KnownSymbol (XdsConName n)) => KnownRData (X_ds n) Source # 
Instance details

Defined in Net.DNSBase.RData.Dnssec

Associated Types

type RDataExtensionVal (X_ds n) 
Instance details

Defined in Net.DNSBase.RData.Dnssec

type RDataExtensionVal (X_ds n) = ()

Methods

rdataExtensionVal :: forall b -> b ~ X_ds n => RDataExtensionVal (X_ds n) Source #

rdType :: forall b -> b ~ X_ds n => RRTYPE Source #

rdTypePres :: forall b -> b ~ X_ds n => Builder -> Builder Source #

rdDecode :: forall b -> b ~ X_ds n => RDataExtensionVal (X_ds n) -> Int -> SGet RData Source #

rdEncode :: X_ds n -> SPut s RData Source #

cnEncode :: X_ds n -> SPut s RData Source #

(Nat16 n, KnownSymbol (XkeyConName n)) => KnownRData (X_key n) Source # 
Instance details

Defined in Net.DNSBase.RData.Dnssec

Associated Types

type RDataExtensionVal (X_key n) 
Instance details

Defined in Net.DNSBase.RData.Dnssec

type RDataExtensionVal (X_key n) = ()

Methods

rdataExtensionVal :: forall b -> b ~ X_key n => RDataExtensionVal (X_key n) Source #

rdType :: forall b -> b ~ X_key n => RRTYPE Source #

rdTypePres :: forall b -> b ~ X_key n => Builder -> Builder Source #

rdDecode :: forall b -> b ~ X_key n => RDataExtensionVal (X_key n) -> Int -> SGet RData Source #

rdEncode :: X_key n -> SPut s RData Source #

cnEncode :: X_key n -> SPut s RData Source #

(Nat16 n, KnownSymbol (XsigConName n)) => KnownRData (X_sig n) Source # 
Instance details

Defined in Net.DNSBase.RData.Dnssec

Associated Types

type RDataExtensionVal (X_sig n) 
Instance details

Defined in Net.DNSBase.RData.Dnssec

type RDataExtensionVal (X_sig n) = ()

Methods

rdataExtensionVal :: forall b -> b ~ X_sig n => RDataExtensionVal (X_sig n) Source #

rdType :: forall b -> b ~ X_sig n => RRTYPE Source #

rdTypePres :: forall b -> b ~ X_sig n => Builder -> Builder Source #

rdDecode :: forall b -> b ~ X_sig n => RDataExtensionVal (X_sig n) -> Int -> SGet RData Source #

rdEncode :: X_sig n -> SPut s RData Source #

cnEncode :: X_sig n -> SPut s RData Source #

(Typeable n, Nat16 n, KnownSymbol (XdomainConName n)) => KnownRData (X_domain n) Source #

Name compression used on input and output.

Instance details

Defined in Net.DNSBase.RData.Internal.XNAME

Associated Types

type RDataExtensionVal (X_domain n) 
Instance details

Defined in Net.DNSBase.RData.Internal.XNAME

Methods

rdataExtensionVal :: forall b -> b ~ X_domain n => RDataExtensionVal (X_domain n) Source #

rdType :: forall b -> b ~ X_domain n => RRTYPE Source #

rdTypePres :: forall b -> b ~ X_domain n => Builder -> Builder Source #

rdDecode :: forall b -> b ~ X_domain n => RDataExtensionVal (X_domain n) -> Int -> SGet RData Source #

rdEncode :: X_domain n -> SPut s RData Source #

cnEncode :: X_domain n -> SPut s RData Source #

(Nat16 n, KnownSymbol (XnidConName n)) => KnownRData (X_nid n) Source # 
Instance details

Defined in Net.DNSBase.RData.SRV

Associated Types

type RDataExtensionVal (X_nid n) 
Instance details

Defined in Net.DNSBase.RData.SRV

type RDataExtensionVal (X_nid n) = ()

Methods

rdataExtensionVal :: forall b -> b ~ X_nid n => RDataExtensionVal (X_nid n) Source #

rdType :: forall b -> b ~ X_nid n => RRTYPE Source #

rdTypePres :: forall b -> b ~ X_nid n => Builder -> Builder Source #

rdDecode :: forall b -> b ~ X_nid n => RDataExtensionVal (X_nid n) -> Int -> SGet RData Source #

rdEncode :: X_nid n -> SPut s RData Source #

cnEncode :: X_nid n -> SPut s RData Source #

(Nat16 n, KnownSymbol (XsvcbConName n)) => KnownRData (X_svcb n) Source # 
Instance details

Defined in Net.DNSBase.RData.SVCB

Associated Types

type RDataExtensionVal (X_svcb n) 
Instance details

Defined in Net.DNSBase.RData.SVCB

Methods

rdataExtensionVal :: forall b -> b ~ X_svcb n => RDataExtensionVal (X_svcb n) Source #

rdType :: forall b -> b ~ X_svcb n => RRTYPE Source #

rdTypePres :: forall b -> b ~ X_svcb n => Builder -> Builder Source #

rdDecode :: forall b -> b ~ X_svcb n => RDataExtensionVal (X_svcb n) -> Int -> SGet RData Source #

rdEncode :: X_svcb n -> SPut s RData Source #

cnEncode :: X_svcb n -> SPut s RData Source #

(Nat16 n, KnownSymbol (XtlsaConName n)) => KnownRData (X_tlsa n) Source # 
Instance details

Defined in Net.DNSBase.RData.TLSA

Associated Types

type RDataExtensionVal (X_tlsa n) 
Instance details

Defined in Net.DNSBase.RData.TLSA

Methods

rdataExtensionVal :: forall b -> b ~ X_tlsa n => RDataExtensionVal (X_tlsa n) Source #

rdType :: forall b -> b ~ X_tlsa n => RRTYPE Source #

rdTypePres :: forall b -> b ~ X_tlsa n => Builder -> Builder Source #

rdDecode :: forall b -> b ~ X_tlsa n => RDataExtensionVal (X_tlsa n) -> Int -> SGet RData Source #

rdEncode :: X_tlsa n -> SPut s RData Source #

cnEncode :: X_tlsa n -> SPut s RData Source #

registerRRtype :: forall a -> KnownRData a => ResolverConf -> ResolverConf Source #

Register a decoder for an RR-type. If the RR's data type is itself extensible, you can use extendRRwithType or extendRRwithValue to apply additional extensions on top.

The registration takes precedence over the library's built-in codec at the same RR-type code, except at protected code points (e.g. RR-type 0 and 65535, or the OPT pseudo-RR), where the registration is silently ignored.

extendRRwithType :: forall t -> (KnownRData t, TypeExtensible t (RDataExtensionVal t)) => forall b -> TypeExtensionArg t b => ResolverConf -> ResolverConf Source #

Extend the registered codec of a type-extensible RR type t with an additional typed extension b. If t is not yet known it is automatically registered, in either case extendByType is then applied to the existing decoder state to fold in b.

This is how one adds an extra SvcParam-key decoder for SVCB and/or HTTPS records.

conf
    & extendRRwithType T_svcb  MyParamType
    & extendRRwithType T_https MyParamType

extendRRwithValue :: forall t -> (KnownRData t, ValueExtensible t (RDataExtensionVal t)) => forall b. ValueExtensionArg t b => b -> ResolverConf -> ResolverConf Source #

Extend the registered codec for RR type t with a caller-supplied value v, whose type satisfies t's ValueExtensionArg constraint. Parallel to extendRRwithType, but for instances whose extension table is keyed by runtime data rather than user-supplied types.

class (Typeable a, Eq a, Show a, Presentable a) => KnownEdnsOption a where Source #

EDNS option class with conversion to/from opaque EdnsOption form.

Minimal complete definition

optNum, optEncode, optDecode

Associated Types

type OptionExtensionVal a Source #

The codec-consumed extension value for option type a. Defaults to (). Options with a non-trivial extension (currently only O_ede, whose extension carries the info-code name registry) supply their own associated-type definition.

type OptionExtensionVal a = ()

Methods

optionExtensionVal :: forall b -> b ~ a => OptionExtensionVal a Source #

The library's built-in starting OptionExtensionVal for option type a. Used as the baseline when the library installs its built-in registration for a, and as the starting point when the user extends the codec for a. For OptionExtensionVal a ~ () options the class default applies.

default optionExtensionVal :: OptionExtensionVal a ~ () => forall b -> b ~ a => OptionExtensionVal a Source #

optNum :: forall b -> b ~ a => OptNum Source #

The EDNS option number

optPres :: forall b -> b ~ a => Builder -> Builder Source #

CPS option number presentation form builder. Most useful for new option values not yet known to the library.

optEncode Source #

Arguments

:: forall s r. (Typeable r, Eq r, Show r) 
=> a

The value to encode

-> SPut s r 

Encoder of option data to wire form

optDecode Source #

Arguments

:: forall b -> b ~ a 
=> OptionExtensionVal b

Its extension value

-> Int

The encoded data length

-> SGet EdnsOption 

Decoder from wire form

Instances

Instances details
KnownEdnsOption O_ecs Source # 
Instance details

Defined in Net.DNSBase.EDNS.Option.ECS

Associated Types

type OptionExtensionVal O_ecs 
Instance details

Defined in Net.DNSBase.EDNS.Option.ECS

Methods

optionExtensionVal :: forall b -> b ~ O_ecs => OptionExtensionVal O_ecs Source #

optNum :: forall b -> b ~ O_ecs => OptNum Source #

optPres :: forall b -> b ~ O_ecs => Builder -> Builder Source #

optEncode :: forall s r. (Typeable r, Eq r, Show r) => O_ecs -> SPut s r Source #

optDecode :: forall b -> b ~ O_ecs => OptionExtensionVal b -> Int -> SGet EdnsOption Source #

KnownEdnsOption O_ede Source # 
Instance details

Defined in Net.DNSBase.EDNS.Option.EDE

Associated Types

type OptionExtensionVal O_ede 
Instance details

Defined in Net.DNSBase.EDNS.Option.EDE

Methods

optionExtensionVal :: forall b -> b ~ O_ede => OptionExtensionVal O_ede Source #

optNum :: forall b -> b ~ O_ede => OptNum Source #

optPres :: forall b -> b ~ O_ede => Builder -> Builder Source #

optEncode :: forall s r. (Typeable r, Eq r, Show r) => O_ede -> SPut s r Source #

optDecode :: forall b -> b ~ O_ede => OptionExtensionVal b -> Int -> SGet EdnsOption Source #

KnownEdnsOption O_nsid Source # 
Instance details

Defined in Net.DNSBase.EDNS.Option.NSID

Associated Types

type OptionExtensionVal O_nsid 
Instance details

Defined in Net.DNSBase.EDNS.Option.NSID

Methods

optionExtensionVal :: forall b -> b ~ O_nsid => OptionExtensionVal O_nsid Source #

optNum :: forall b -> b ~ O_nsid => OptNum Source #

optPres :: forall b -> b ~ O_nsid => Builder -> Builder Source #

optEncode :: forall s r. (Typeable r, Eq r, Show r) => O_nsid -> SPut s r Source #

optDecode :: forall b -> b ~ O_nsid => OptionExtensionVal b -> Int -> SGet EdnsOption Source #

KnownEdnsOption O_dau Source # 
Instance details

Defined in Net.DNSBase.EDNS.Option.Secalgs

Associated Types

type OptionExtensionVal O_dau 
Instance details

Defined in Net.DNSBase.EDNS.Option.Secalgs

Methods

optionExtensionVal :: forall b -> b ~ O_dau => OptionExtensionVal O_dau Source #

optNum :: forall b -> b ~ O_dau => OptNum Source #

optPres :: forall b -> b ~ O_dau => Builder -> Builder Source #

optEncode :: forall s r. (Typeable r, Eq r, Show r) => O_dau -> SPut s r Source #

optDecode :: forall b -> b ~ O_dau => OptionExtensionVal b -> Int -> SGet EdnsOption Source #

KnownEdnsOption O_dhu Source # 
Instance details

Defined in Net.DNSBase.EDNS.Option.Secalgs

Associated Types

type OptionExtensionVal O_dhu 
Instance details

Defined in Net.DNSBase.EDNS.Option.Secalgs

Methods

optionExtensionVal :: forall b -> b ~ O_dhu => OptionExtensionVal O_dhu Source #

optNum :: forall b -> b ~ O_dhu => OptNum Source #

optPres :: forall b -> b ~ O_dhu => Builder -> Builder Source #

optEncode :: forall s r. (Typeable r, Eq r, Show r) => O_dhu -> SPut s r Source #

optDecode :: forall b -> b ~ O_dhu => OptionExtensionVal b -> Int -> SGet EdnsOption Source #

KnownEdnsOption O_n3u Source # 
Instance details

Defined in Net.DNSBase.EDNS.Option.Secalgs

Associated Types

type OptionExtensionVal O_n3u 
Instance details

Defined in Net.DNSBase.EDNS.Option.Secalgs

Methods

optionExtensionVal :: forall b -> b ~ O_n3u => OptionExtensionVal O_n3u Source #

optNum :: forall b -> b ~ O_n3u => OptNum Source #

optPres :: forall b -> b ~ O_n3u => Builder -> Builder Source #

optEncode :: forall s r. (Typeable r, Eq r, Show r) => O_n3u -> SPut s r Source #

optDecode :: forall b -> b ~ O_n3u => OptionExtensionVal b -> Int -> SGet EdnsOption Source #

Nat16 n => KnownEdnsOption (OpaqueOption n) Source # 
Instance details

Defined in Net.DNSBase.EDNS.Internal.Option.Opaque

Associated Types

type OptionExtensionVal (OpaqueOption n) 
Instance details

Defined in Net.DNSBase.EDNS.Internal.Option.Opaque

Methods

optionExtensionVal :: forall b -> b ~ OpaqueOption n => OptionExtensionVal (OpaqueOption n) Source #

optNum :: forall b -> b ~ OpaqueOption n => OptNum Source #

optPres :: forall b -> b ~ OpaqueOption n => Builder -> Builder Source #

optEncode :: forall s r. (Typeable r, Eq r, Show r) => OpaqueOption n -> SPut s r Source #

optDecode :: forall b -> b ~ OpaqueOption n => OptionExtensionVal b -> Int -> SGet EdnsOption Source #

registerEdnsOption :: forall a -> KnownEdnsOption a => ResolverConf -> ResolverConf Source #

Register an EDNS option decoder. If the EDNS option's data type is itself extensible, you can use extendEdnsOptionWithType or extendEdnsOptionWithValue to apply additional extensions on top.

The registration takes precedence over the library's built-in decoder at the same option code (if any) after the merge step in makeResolvSeed.

extendEdnsOptionWithType :: forall t -> (KnownEdnsOption t, TypeExtensible t (OptionExtensionVal t)) => forall b -> TypeExtensionArg t b => ResolverConf -> ResolverConf Source #

Extend the registered decoder for a type-extensible EDNS option type t with an additional typed extension b. If t is not yet present in the resolver configuration, it is first registered, in either case extendByType is then applied fold in b.

This is the EDNS-option-side parallel to extendRRwithType.

extendEdnsOptionWithValue :: forall t -> (KnownEdnsOption t, ValueExtensible t (OptionExtensionVal t)) => forall b. ValueExtensionArg t b => b -> ResolverConf -> ResolverConf Source #

Extend the registered codec for EDNS option type t with a caller-supplied value v, whose type satisfies t's ValueExtensionArg constraint. The EDNS-option-side parallel to extendRRwithValue. This is the canonical way to add an EDE info-code → friendly-name mapping:

conf
    & extendEdnsOptionWithValue O_ede (33, "Frobnicated")
    & extendEdnsOptionWithValue O_ede (34, "Bogosity")

Chained-composition opt-in

The primary API (e.g. makeResolvSeed, lookupAnswers) returns IO (Either DNSError a): each call's error half is explicit at the type level and the user's surrounding code stays in plain IO. For programs that prefer transformer-style composition of many DNS calls with short-circuit error handling, DNSIO is a thin alias for ExceptT DNSError IO; runDNSIO and liftDNS convert between the two forms.

type DNSIO = ExceptT DNSError IO Source #

An opt-in monad for chaining multiple DNS operations with short-circuit error handling. The primary public API uses plain IO (Either DNSError a); DNSIO is a thin wrapper around ExceptT DNSError IO for users who prefer transformer-style composition. Convert between the two forms with runDNSIO and liftDNS.

runDNSIO :: DNSIO a -> IO (Either DNSError a) Source #

Run a DNSIO computation and return its Either DNSError a result in plain IO.

liftDNS :: IO (Either DNSError a) -> DNSIO a Source #

Lift a plain IO (Either DNSError a) action into DNSIO, for combining with other DNSIO steps.