* Copyright (C) Internet Systems Consortium, Inc. ("ISC")
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, you can obtain one at https://mozilla.org/MPL/2.0/.
* See the COPYRIGHT file distributed with this work for additional
* information regarding copyright ownership.
* This is the BIND 9 resolver, the module responsible for resolving DNS
* requests by iteratively querying authoritative servers and following
* referrals. This is a "full resolver", not to be confused with
* the stub resolvers most people associate with the word "resolver".
* The full resolver is part of the caching name server or resolver
* daemon the stub resolver talks to.
*\li The module ensures appropriate synchronization of data structures it
* creates and manipulates.
*\li No anticipated impact.
*\li No anticipated impact.
*\li RFCs: 1034, 1035, 2181, TBS
#include <dns/fixedname.h>
* A dns_fetchevent_t is sent when a 'fetch' completes. Any of 'db',
* 'node', 'rdataset', and 'sigrdataset' may be bound. It is the
* receiver's responsibility to detach before freeing the event.
* 'rdataset', 'sigrdataset', 'client' and 'id' are the values that were
* supplied when dns_resolver_createfetch() was called. They are returned
* to the caller so that they may be freed.
typedef struct dns_fetchevent {
ISC_EVENT_COMMON(struct dns_fetchevent);
dns_rdataset_t * rdataset;
dns_rdataset_t * sigrdataset;
dns_fixedname_t foundname;
* The two quota types (fetches-per-zone and fetches-per-server)
* Options that modify how a 'fetch' is done.
#define DNS_FETCHOPT_TCP 0x00001 /*%< Use TCP. */
#define DNS_FETCHOPT_UNSHARED 0x00002 /*%< See below. */
#define DNS_FETCHOPT_RECURSIVE 0x00004 /*%< Set RD? */
#define DNS_FETCHOPT_NOEDNS0 0x00008 /*%< Do not use EDNS. */
#define DNS_FETCHOPT_FORWARDONLY 0x00010 /*%< Only use forwarders. */
#define DNS_FETCHOPT_NOVALIDATE 0x00020 /*%< Disable validation. */
#define DNS_FETCHOPT_EDNS512 0x00040 /*%< Advertise a 512 byte
#define DNS_FETCHOPT_WANTNSID 0x00080 /*%< Request NSID */
#define DNS_FETCHOPT_PREFETCH 0x00100 /*%< Do prefetch */
#define DNS_FETCHOPT_NOCDFLAG 0x00200 /*%< Don't set CD flag. */
#define DNS_FETCHOPT_NONTA 0x00400 /*%< Ignore NTA table. */
/* RESERVED ECS 0x00000 */
/* RESERVED ECS 0x01000 */
/* RESERVED ECS 0x02000 */
/* RESERVED TCPCLIENT 0x04000 */
#define DNS_FETCHOPT_NOCACHED 0x08000 /*%< Force cache update. */
#define DNS_FETCHOPT_NOFORWARD 0x80000 /*%< Do not use forwarders
/* Reserved in use by adb.c 0x00400000 */
#define DNS_FETCHOPT_EDNSVERSIONSET 0x00800000
#define DNS_FETCHOPT_EDNSVERSIONMASK 0xff000000
#define DNS_FETCHOPT_EDNSVERSIONSHIFT 24
* Upper bounds of class of query RTT (ms). Corresponds to
* dns_resstatscounter_queryrttX statistics counters.
#define DNS_RESOLVER_QRYRTTCLASS0 10
#define DNS_RESOLVER_QRYRTTCLASS0STR "10"
#define DNS_RESOLVER_QRYRTTCLASS1 100
#define DNS_RESOLVER_QRYRTTCLASS1STR "100"
#define DNS_RESOLVER_QRYRTTCLASS2 500
#define DNS_RESOLVER_QRYRTTCLASS2STR "500"
#define DNS_RESOLVER_QRYRTTCLASS3 800
#define DNS_RESOLVER_QRYRTTCLASS3STR "800"
#define DNS_RESOLVER_QRYRTTCLASS4 1600
#define DNS_RESOLVER_QRYRTTCLASS4STR "1600"
* XXXRTH Should this API be made semi-private? (I.e.
* _dns_resolver_create()).
#define DNS_RESOLVER_CHECKNAMES 0x01
#define DNS_RESOLVER_CHECKNAMESFAIL 0x02
dns_resolver_create(dns_view_t *view,
unsigned int ntasks, unsigned int ndisp,
isc_socketmgr_t *socketmgr,
isc_timermgr_t *timermgr,
dns_dispatchmgr_t *dispatchmgr,
dns_dispatch_t *dispatchv4,
dns_dispatch_t *dispatchv6,
*\li Generally, applications should not create a resolver directly, but
* should instead call dns_view_createresolver().
*\li 'view' is a valid view.
*\li 'taskmgr' is a valid task manager.
*\li 'socketmgr' is a valid socket manager.
*\li 'timermgr' is a valid timer manager.
*\li 'dispatchv4' is a dispatch with an IPv4 UDP socket, or is NULL.
* If not NULL, 'ndisp' clones of it will be created by the resolver.
*\li 'dispatchv6' is a dispatch with an IPv6 UDP socket, or is NULL.
* If not NULL, 'ndisp' clones of it will be created by the resolver.
*\li resp != NULL && *resp == NULL.
*\li #ISC_R_SUCCESS On success.
*\li Anything else Failure.
dns_resolver_freeze(dns_resolver_t *res);
*\li Certain configuration changes cannot be made after the resolver
* is frozen. Fetches cannot be created until the resolver is frozen.
*\li 'res' is a valid resolver.
dns_resolver_prime(dns_resolver_t *res);
*\li Resolvers which have a forwarding policy other than dns_fwdpolicy_only
* need to be primed with the root nameservers, otherwise the root
* nameserver hints data may be used indefinitely. This function requests
* that the resolver start a priming fetch, if it isn't already priming.
*\li 'res' is a valid, frozen resolver.
dns_resolver_whenshutdown(dns_resolver_t *res, isc_task_t *task,
* Send '*eventp' to 'task' when 'res' has completed shutdown.
*\li It is not safe to detach the last reference to 'res' until
*\li 'res' is a valid resolver.
*\li 'task' is a valid task.
*\li *eventp is a valid event.
dns_resolver_shutdown(dns_resolver_t *res);
* Start the shutdown process for 'res'.
*\li This call has no effect if the resolver is already shutting down.
*\li 'res' is a valid resolver.
dns_resolver_attach(dns_resolver_t *source, dns_resolver_t **targetp);
dns_resolver_detach(dns_resolver_t **resp);
dns_resolver_createfetch(dns_resolver_t *res, dns_name_t *name,
dns_name_t *domain, dns_rdataset_t *nameservers,
dns_forwarders_t *forwarders,
unsigned int options, isc_task_t *task,
isc_taskaction_t action, void *arg,
dns_rdataset_t *rdataset,
dns_rdataset_t *sigrdataset,
dns_resolver_createfetch2(dns_resolver_t *res, dns_name_t *name,
dns_name_t *domain, dns_rdataset_t *nameservers,
dns_forwarders_t *forwarders,
isc_sockaddr_t *client, uint16_t id,
unsigned int options, isc_task_t *task,
isc_taskaction_t action, void *arg,
dns_rdataset_t *rdataset,
dns_rdataset_t *sigrdataset,
dns_resolver_createfetch3(dns_resolver_t *res, dns_name_t *name,
dns_name_t *domain, dns_rdataset_t *nameservers,
dns_forwarders_t *forwarders,
isc_sockaddr_t *client, uint16_t id,
unsigned int options, unsigned int depth,
isc_counter_t *qc, isc_task_t *task,
isc_taskaction_t action, void *arg,
dns_rdataset_t *rdataset,
dns_rdataset_t *sigrdataset,
* Recurse to answer a question.
*\li This call starts a query for 'name', type 'type'.
*\li The 'domain' is a parent domain of 'name' for which
* a set of name servers 'nameservers' is known. If no
* such name server information is available, set
* 'domain' and 'nameservers' to NULL.
*\li 'forwarders' is unimplemented, and subject to change when
* we figure out how selective forwarding will work.
*\li When the fetch completes (successfully or otherwise), a
* #DNS_EVENT_FETCHDONE event with action 'action' and arg 'arg' will be
*\li The values of 'rdataset' and 'sigrdataset' will be returned in
*\li 'client' and 'id' are used for duplicate query detection. '*client'
* must remain stable until after 'action' has been called or
* dns_resolver_cancelfetch() is called.
*\li 'res' is a valid resolver that has been frozen.
*\li 'name' is a valid name.
*\li 'type' is not a meta type other than ANY.
*\li 'domain' is a valid name or NULL.
*\li 'nameservers' is a valid NS rdataset (whose owner name is 'domain')
* iff. 'domain' is not NULL.
*\li 'forwarders' is NULL.
*\li 'client' is a valid sockaddr or NULL.
*\li 'options' contains valid options.
*\li 'rdataset' is a valid, disassociated rdataset.
*\li 'sigrdataset' is NULL, or is a valid, disassociated rdataset.
*\li fetchp != NULL && *fetchp == NULL.
*\li #ISC_R_SUCCESS Success
*\li Many other values are possible, all of which indicate failure.
dns_resolver_cancelfetch(dns_fetch_t *fetch);
*\li If 'fetch' has not completed, post its FETCHDONE event with a
* result code of #ISC_R_CANCELED.
*\li 'fetch' is a valid fetch.
dns_resolver_destroyfetch(dns_fetch_t **fetchp);
*\li '*fetchp' is a valid fetch.
*\li The caller has received the FETCHDONE event (either because the
* fetch completed or because dns_resolver_cancelfetch() was called).
dns_resolver_logfetch(dns_fetch_t *fetch, isc_log_t *lctx,
isc_logcategory_t *category, isc_logmodule_t *module,
int level, bool duplicateok);
* Dump a log message on internal state at the completion of given 'fetch'.
* 'lctx', 'category', 'module', and 'level' are used to write the log message.
* By default, only one log message is written even if the corresponding fetch
* context serves multiple clients; if 'duplicateok' is true the suppression
* is disabled and the message can be written every time this function is
*\li 'fetch' is a valid fetch, and has completed.
dns_resolver_dispatchmgr(dns_resolver_t *resolver);
dns_resolver_dispatchv4(dns_resolver_t *resolver);
dns_resolver_dispatchv6(dns_resolver_t *resolver);
dns_resolver_socketmgr(dns_resolver_t *resolver);
dns_resolver_taskmgr(dns_resolver_t *resolver);
dns_resolver_getlamettl(dns_resolver_t *resolver);
* Get the resolver's lame-ttl. zero => no lame processing.
*\li 'resolver' to be valid.
dns_resolver_setlamettl(dns_resolver_t *resolver, uint32_t lame_ttl);
* Set the resolver's lame-ttl. zero => no lame processing.
*\li 'resolver' to be valid.
dns_resolver_nrunning(dns_resolver_t *resolver);
* Return the number of currently running resolutions in this
* resolver. This is may be less than the number of outstanding
* fetches due to multiple identical fetches, or more than the
* number of of outstanding fetches due to the fact that resolution
* can continue even though a fetch has been canceled.
dns_resolver_addalternate(dns_resolver_t *resolver, isc_sockaddr_t *alt,
dns_name_t *name, in_port_t port);
* Add alternate addresses to be tried in the event that the nameservers
* for a zone are not available in the address families supported by the
* \li only one of 'name' or 'alt' to be valid.
dns_resolver_setudpsize(dns_resolver_t *resolver, uint16_t udpsize);
* Set the EDNS UDP buffer size advertised by the server.
dns_resolver_getudpsize(dns_resolver_t *resolver);
* Get the current EDNS UDP buffer size.
dns_resolver_reset_algorithms(dns_resolver_t *resolver);
* Clear the disabled DNSSEC algorithms.
dns_resolver_reset_ds_digests(dns_resolver_t *resolver);
* Clear the disabled DS/DLV digest types.
dns_resolver_disable_algorithm(dns_resolver_t *resolver, dns_name_t *name,
* Mark the given DNSSEC algorithm as disabled and below 'name'.
* Valid algorithms are less than 256.