2 * Copyright (C) 2004-2012 Internet Systems Consortium, Inc. ("ISC")
3 * Copyright (C) 1999-2001, 2003 Internet Software Consortium.
5 * Permission to use, copy, modify, and/or distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
9 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
10 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
12 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
14 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15 * PERFORMANCE OF THIS SOFTWARE.
18 /* $Id: resolver.h,v 1.72 2011/12/05 17:10:51 each Exp $ */
20 #ifndef DNS_RESOLVER_H
21 #define DNS_RESOLVER_H 1
27 /*! \file dns/resolver.h
30 * This is the BIND 9 resolver, the module responsible for resolving DNS
31 * requests by iteratively querying authoritative servers and following
32 * referrals. This is a "full resolver", not to be confused with
33 * the stub resolvers most people associate with the word "resolver".
34 * The full resolver is part of the caching name server or resolver
35 * daemon the stub resolver talks to.
38 *\li The module ensures appropriate synchronization of data structures it
39 * creates and manipulates.
42 *\li No anticipated impact.
48 *\li No anticipated impact.
51 *\li RFCs: 1034, 1035, 2181, TBS
56 #include <isc/socket.h>
58 #include <dns/types.h>
59 #include <dns/fixedname.h>
64 * A dns_fetchevent_t is sent when a 'fetch' completes. Any of 'db',
65 * 'node', 'rdataset', and 'sigrdataset' may be bound. It is the
66 * receiver's responsibility to detach before freeing the event.
68 * 'rdataset', 'sigrdataset', 'client' and 'id' are the values that were
69 * supplied when dns_resolver_createfetch() was called. They are returned
70 * to the caller so that they may be freed.
72 typedef struct dns_fetchevent {
73 ISC_EVENT_COMMON(struct dns_fetchevent);
76 dns_rdatatype_t qtype;
79 dns_rdataset_t * rdataset;
80 dns_rdataset_t * sigrdataset;
81 dns_fixedname_t foundname;
82 isc_sockaddr_t * client;
88 * Options that modify how a 'fetch' is done.
90 #define DNS_FETCHOPT_TCP 0x01 /*%< Use TCP. */
91 #define DNS_FETCHOPT_UNSHARED 0x02 /*%< See below. */
92 #define DNS_FETCHOPT_RECURSIVE 0x04 /*%< Set RD? */
93 #define DNS_FETCHOPT_NOEDNS0 0x08 /*%< Do not use EDNS. */
94 #define DNS_FETCHOPT_FORWARDONLY 0x10 /*%< Only use forwarders. */
95 #define DNS_FETCHOPT_NOVALIDATE 0x20 /*%< Disable validation. */
96 #define DNS_FETCHOPT_EDNS512 0x40 /*%< Advertise a 512 byte
98 #define DNS_FETCHOPT_WANTNSID 0x80 /*%< Request NSID */
100 #define DNS_FETCHOPT_EDNSVERSIONSET 0x00800000
101 #define DNS_FETCHOPT_EDNSVERSIONMASK 0xff000000
102 #define DNS_FETCHOPT_EDNSVERSIONSHIFT 24
105 * Upper bounds of class of query RTT (ms). Corresponds to
106 * dns_resstatscounter_queryrttX statistics counters.
108 #define DNS_RESOLVER_QRYRTTCLASS0 10
109 #define DNS_RESOLVER_QRYRTTCLASS0STR "10"
110 #define DNS_RESOLVER_QRYRTTCLASS1 100
111 #define DNS_RESOLVER_QRYRTTCLASS1STR "100"
112 #define DNS_RESOLVER_QRYRTTCLASS2 500
113 #define DNS_RESOLVER_QRYRTTCLASS2STR "500"
114 #define DNS_RESOLVER_QRYRTTCLASS3 800
115 #define DNS_RESOLVER_QRYRTTCLASS3STR "800"
116 #define DNS_RESOLVER_QRYRTTCLASS4 1600
117 #define DNS_RESOLVER_QRYRTTCLASS4STR "1600"
120 * XXXRTH Should this API be made semi-private? (I.e.
121 * _dns_resolver_create()).
124 #define DNS_RESOLVER_CHECKNAMES 0x01
125 #define DNS_RESOLVER_CHECKNAMESFAIL 0x02
128 dns_resolver_create(dns_view_t *view,
129 isc_taskmgr_t *taskmgr,
130 unsigned int ntasks, unsigned int ndisp,
131 isc_socketmgr_t *socketmgr,
132 isc_timermgr_t *timermgr,
133 unsigned int options,
134 dns_dispatchmgr_t *dispatchmgr,
135 dns_dispatch_t *dispatchv4,
136 dns_dispatch_t *dispatchv6,
137 dns_resolver_t **resp);
144 *\li Generally, applications should not create a resolver directly, but
145 * should instead call dns_view_createresolver().
149 *\li 'view' is a valid view.
151 *\li 'taskmgr' is a valid task manager.
155 *\li 'socketmgr' is a valid socket manager.
157 *\li 'timermgr' is a valid timer manager.
159 *\li 'dispatchv4' is a dispatch with an IPv4 UDP socket, or is NULL.
160 * If not NULL, 'ndisp' clones of it will be created by the resolver.
162 *\li 'dispatchv6' is a dispatch with an IPv6 UDP socket, or is NULL.
163 * If not NULL, 'ndisp' clones of it will be created by the resolver.
165 *\li resp != NULL && *resp == NULL.
169 *\li #ISC_R_SUCCESS On success.
171 *\li Anything else Failure.
175 dns_resolver_freeze(dns_resolver_t *res);
181 *\li Certain configuration changes cannot be made after the resolver
182 * is frozen. Fetches cannot be created until the resolver is frozen.
186 *\li 'res' is a valid resolver.
190 *\li 'res' is frozen.
194 dns_resolver_prime(dns_resolver_t *res);
200 *\li Resolvers which have a forwarding policy other than dns_fwdpolicy_only
201 * need to be primed with the root nameservers, otherwise the root
202 * nameserver hints data may be used indefinitely. This function requests
203 * that the resolver start a priming fetch, if it isn't already priming.
207 *\li 'res' is a valid, frozen resolver.
212 dns_resolver_whenshutdown(dns_resolver_t *res, isc_task_t *task,
213 isc_event_t **eventp);
215 * Send '*eventp' to 'task' when 'res' has completed shutdown.
219 *\li It is not safe to detach the last reference to 'res' until
220 * shutdown is complete.
224 *\li 'res' is a valid resolver.
226 *\li 'task' is a valid task.
228 *\li *eventp is a valid event.
232 *\li *eventp == NULL.
236 dns_resolver_shutdown(dns_resolver_t *res);
238 * Start the shutdown process for 'res'.
242 *\li This call has no effect if the resolver is already shutting down.
246 *\li 'res' is a valid resolver.
250 dns_resolver_attach(dns_resolver_t *source, dns_resolver_t **targetp);
253 dns_resolver_detach(dns_resolver_t **resp);
256 dns_resolver_createfetch(dns_resolver_t *res, dns_name_t *name,
257 dns_rdatatype_t type,
258 dns_name_t *domain, dns_rdataset_t *nameservers,
259 dns_forwarders_t *forwarders,
260 unsigned int options, isc_task_t *task,
261 isc_taskaction_t action, void *arg,
262 dns_rdataset_t *rdataset,
263 dns_rdataset_t *sigrdataset,
264 dns_fetch_t **fetchp);
267 dns_resolver_createfetch2(dns_resolver_t *res, dns_name_t *name,
268 dns_rdatatype_t type,
269 dns_name_t *domain, dns_rdataset_t *nameservers,
270 dns_forwarders_t *forwarders,
271 isc_sockaddr_t *client, isc_uint16_t id,
272 unsigned int options, isc_task_t *task,
273 isc_taskaction_t action, void *arg,
274 dns_rdataset_t *rdataset,
275 dns_rdataset_t *sigrdataset,
276 dns_fetch_t **fetchp);
278 * Recurse to answer a question.
282 *\li This call starts a query for 'name', type 'type'.
284 *\li The 'domain' is a parent domain of 'name' for which
285 * a set of name servers 'nameservers' is known. If no
286 * such name server information is available, set
287 * 'domain' and 'nameservers' to NULL.
289 *\li 'forwarders' is unimplemented, and subject to change when
290 * we figure out how selective forwarding will work.
292 *\li When the fetch completes (successfully or otherwise), a
293 * #DNS_EVENT_FETCHDONE event with action 'action' and arg 'arg' will be
296 *\li The values of 'rdataset' and 'sigrdataset' will be returned in
297 * the FETCHDONE event.
299 *\li 'client' and 'id' are used for duplicate query detection. '*client'
300 * must remain stable until after 'action' has been called or
301 * dns_resolver_cancelfetch() is called.
305 *\li 'res' is a valid resolver that has been frozen.
307 *\li 'name' is a valid name.
309 *\li 'type' is not a meta type other than ANY.
311 *\li 'domain' is a valid name or NULL.
313 *\li 'nameservers' is a valid NS rdataset (whose owner name is 'domain')
314 * iff. 'domain' is not NULL.
316 *\li 'forwarders' is NULL.
318 *\li 'client' is a valid sockaddr or NULL.
320 *\li 'options' contains valid options.
322 *\li 'rdataset' is a valid, disassociated rdataset.
324 *\li 'sigrdataset' is NULL, or is a valid, disassociated rdataset.
326 *\li fetchp != NULL && *fetchp == NULL.
330 *\li #ISC_R_SUCCESS Success
331 *\li #DNS_R_DUPLICATE
334 *\li Many other values are possible, all of which indicate failure.
338 dns_resolver_cancelfetch(dns_fetch_t *fetch);
344 *\li If 'fetch' has not completed, post its FETCHDONE event with a
345 * result code of #ISC_R_CANCELED.
349 *\li 'fetch' is a valid fetch.
353 dns_resolver_destroyfetch(dns_fetch_t **fetchp);
359 *\li '*fetchp' is a valid fetch.
361 *\li The caller has received the FETCHDONE event (either because the
362 * fetch completed or because dns_resolver_cancelfetch() was called).
366 *\li *fetchp == NULL.
370 dns_resolver_logfetch(dns_fetch_t *fetch, isc_log_t *lctx,
371 isc_logcategory_t *category, isc_logmodule_t *module,
372 int level, isc_boolean_t duplicateok);
374 * Dump a log message on internal state at the completion of given 'fetch'.
375 * 'lctx', 'category', 'module', and 'level' are used to write the log message.
376 * By default, only one log message is written even if the corresponding fetch
377 * context serves multiple clients; if 'duplicateok' is true the suppression
378 * is disabled and the message can be written every time this function is
383 *\li 'fetch' is a valid fetch, and has completed.
387 dns_resolver_dispatchmgr(dns_resolver_t *resolver);
390 dns_resolver_dispatchv4(dns_resolver_t *resolver);
393 dns_resolver_dispatchv6(dns_resolver_t *resolver);
396 dns_resolver_socketmgr(dns_resolver_t *resolver);
399 dns_resolver_taskmgr(dns_resolver_t *resolver);
402 dns_resolver_getlamettl(dns_resolver_t *resolver);
404 * Get the resolver's lame-ttl. zero => no lame processing.
407 *\li 'resolver' to be valid.
411 dns_resolver_setlamettl(dns_resolver_t *resolver, isc_uint32_t lame_ttl);
413 * Set the resolver's lame-ttl. zero => no lame processing.
416 *\li 'resolver' to be valid.
420 dns_resolver_nrunning(dns_resolver_t *resolver);
422 * Return the number of currently running resolutions in this
423 * resolver. This is may be less than the number of outstanding
424 * fetches due to multiple identical fetches, or more than the
425 * number of of outstanding fetches due to the fact that resolution
426 * can continue even though a fetch has been canceled.
430 dns_resolver_addalternate(dns_resolver_t *resolver, isc_sockaddr_t *alt,
431 dns_name_t *name, in_port_t port);
433 * Add alternate addresses to be tried in the event that the nameservers
434 * for a zone are not available in the address families supported by the
438 * \li only one of 'name' or 'alt' to be valid.
442 dns_resolver_setudpsize(dns_resolver_t *resolver, isc_uint16_t udpsize);
444 * Set the EDNS UDP buffer size advertised by the server.
448 dns_resolver_getudpsize(dns_resolver_t *resolver);
450 * Get the current EDNS UDP buffer size.
454 dns_resolver_reset_algorithms(dns_resolver_t *resolver);
456 * Clear the disabled DNSSEC algorithms.
460 dns_resolver_disable_algorithm(dns_resolver_t *resolver, dns_name_t *name,
463 * Mark the give DNSSEC algorithm as disabled and below 'name'.
464 * Valid algorithms are less than 256.
473 dns_resolver_algorithm_supported(dns_resolver_t *resolver, dns_name_t *name,
476 * Check if the given algorithm is supported by this resolver.
477 * This checks if the algorithm has been disabled via
478 * dns_resolver_disable_algorithm() then the underlying
479 * crypto libraries if not specifically disabled.
483 dns_resolver_digest_supported(dns_resolver_t *resolver, unsigned int digest_type);
485 * Is this digest type supported.
489 dns_resolver_resetmustbesecure(dns_resolver_t *resolver);
492 dns_resolver_setmustbesecure(dns_resolver_t *resolver, dns_name_t *name,
493 isc_boolean_t value);
496 dns_resolver_getmustbesecure(dns_resolver_t *resolver, dns_name_t *name);
500 dns_resolver_settimeout(dns_resolver_t *resolver, unsigned int seconds);
502 * Set the length of time the resolver will work on a query, in seconds.
504 * If timeout is 0, the default timeout will be applied.
507 * \li resolver to be valid.
511 dns_resolver_gettimeout(dns_resolver_t *resolver);
513 * Get the current length of time the resolver will work on a query, in seconds.
516 * \li resolver to be valid.
520 dns_resolver_setclientsperquery(dns_resolver_t *resolver,
521 isc_uint32_t min, isc_uint32_t max);
524 dns_resolver_getclientsperquery(dns_resolver_t *resolver, isc_uint32_t *cur,
525 isc_uint32_t *min, isc_uint32_t *max);
528 dns_resolver_getzeronosoattl(dns_resolver_t *resolver);
531 dns_resolver_setzeronosoattl(dns_resolver_t *resolver, isc_boolean_t state);
534 dns_resolver_getoptions(dns_resolver_t *resolver);
537 dns_resolver_addbadcache(dns_resolver_t *resolver, dns_name_t *name,
538 dns_rdatatype_t type, isc_time_t *expire);
540 * Add a entry to the bad cache for <name,type> that will expire at 'expire'.
543 * \li resolver to be valid.
544 * \li name to be valid.
548 dns_resolver_getbadcache(dns_resolver_t *resolver, dns_name_t *name,
549 dns_rdatatype_t type, isc_time_t *now);
551 * Check to see if there is a unexpired entry in the bad cache for
555 * \li resolver to be valid.
556 * \li name to be valid.
560 dns_resolver_flushbadcache(dns_resolver_t *resolver, dns_name_t *name);
562 * Flush the bad cache of all entries at 'name' if 'name' is non NULL.
563 * Flush the entire bad cache if 'name' is NULL.
566 * \li resolver to be valid.
570 dns_resolver_printbadcache(dns_resolver_t *resolver, FILE *fp);
572 * Print out the contents of the bad cache to 'fp'.
575 * \li resolver to be valid.
580 #endif /* DNS_RESOLVER_H */