1999-09-16 00:02:20 +00:00
|
|
|
/*
|
2001-01-09 22:01:04 +00:00
|
|
|
* Copyright (C) 1999-2001 Internet Software Consortium.
|
2000-08-01 01:33:37 +00:00
|
|
|
*
|
1999-09-16 00:02:20 +00:00
|
|
|
* Permission to use, copy, modify, and distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
2000-08-01 01:33:37 +00:00
|
|
|
*
|
2000-07-27 09:55:03 +00:00
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM
|
|
|
|
* DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
|
|
|
|
* INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
|
|
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
|
|
|
|
* FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
|
|
|
|
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
|
|
|
|
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
1999-09-16 00:02:20 +00:00
|
|
|
*/
|
1999-06-28 23:37:54 +00:00
|
|
|
|
2001-11-14 01:31:12 +00:00
|
|
|
/* $Id: resolver.c,v 1.232 2001/11/14 01:31:12 gson Exp $ */
|
2000-06-22 22:00:42 +00:00
|
|
|
|
1999-07-03 15:07:01 +00:00
|
|
|
#include <config.h>
|
|
|
|
|
1999-06-28 23:37:54 +00:00
|
|
|
#include <isc/task.h>
|
2000-05-08 14:38:29 +00:00
|
|
|
#include <isc/timer.h>
|
1999-12-16 22:24:22 +00:00
|
|
|
#include <isc/util.h>
|
1999-06-28 23:37:54 +00:00
|
|
|
|
2000-11-03 02:45:55 +00:00
|
|
|
#include <dns/acl.h>
|
1999-10-29 03:30:49 +00:00
|
|
|
#include <dns/adb.h>
|
1999-10-07 19:41:16 +00:00
|
|
|
#include <dns/db.h>
|
2000-05-08 14:38:29 +00:00
|
|
|
#include <dns/dispatch.h>
|
1999-06-28 23:37:54 +00:00
|
|
|
#include <dns/events.h>
|
2000-08-24 22:15:40 +00:00
|
|
|
#include <dns/forward.h>
|
2000-03-16 23:59:33 +00:00
|
|
|
#include <dns/keytable.h>
|
2000-05-08 14:38:29 +00:00
|
|
|
#include <dns/log.h>
|
1999-06-28 23:37:54 +00:00
|
|
|
#include <dns/message.h>
|
1999-10-16 00:48:34 +00:00
|
|
|
#include <dns/ncache.h>
|
2000-11-04 02:20:58 +00:00
|
|
|
#include <dns/peer.h>
|
1999-08-20 18:56:24 +00:00
|
|
|
#include <dns/rdata.h>
|
1999-11-16 21:07:13 +00:00
|
|
|
#include <dns/rdatalist.h>
|
1999-07-24 01:26:18 +00:00
|
|
|
#include <dns/rdataset.h>
|
2000-05-30 23:14:57 +00:00
|
|
|
#include <dns/rdatastruct.h>
|
2000-01-24 18:13:06 +00:00
|
|
|
#include <dns/rdatatype.h>
|
2000-05-08 14:38:29 +00:00
|
|
|
#include <dns/resolver.h>
|
|
|
|
#include <dns/result.h>
|
1999-08-20 18:56:24 +00:00
|
|
|
#include <dns/tsig.h>
|
2000-04-07 17:34:28 +00:00
|
|
|
#include <dns/validator.h>
|
2000-03-16 23:59:33 +00:00
|
|
|
|
1999-06-28 23:37:54 +00:00
|
|
|
#define DNS_RESOLVER_TRACE
|
|
|
|
#ifdef DNS_RESOLVER_TRACE
|
1999-10-22 19:32:49 +00:00
|
|
|
#define RTRACE(m) isc_log_write(dns_lctx, \
|
|
|
|
DNS_LOGCATEGORY_RESOLVER, \
|
|
|
|
DNS_LOGMODULE_RESOLVER, \
|
1999-11-03 19:56:47 +00:00
|
|
|
ISC_LOG_DEBUG(3), \
|
1999-10-22 19:32:49 +00:00
|
|
|
"res %p: %s", res, (m))
|
|
|
|
#define RRTRACE(r, m) isc_log_write(dns_lctx, \
|
|
|
|
DNS_LOGCATEGORY_RESOLVER, \
|
|
|
|
DNS_LOGMODULE_RESOLVER, \
|
1999-11-03 19:56:47 +00:00
|
|
|
ISC_LOG_DEBUG(3), \
|
1999-10-22 19:32:49 +00:00
|
|
|
"res %p: %s", (r), (m))
|
|
|
|
#define FCTXTRACE(m) isc_log_write(dns_lctx, \
|
|
|
|
DNS_LOGCATEGORY_RESOLVER, \
|
|
|
|
DNS_LOGMODULE_RESOLVER, \
|
1999-11-03 19:56:47 +00:00
|
|
|
ISC_LOG_DEBUG(3), \
|
1999-10-22 19:32:49 +00:00
|
|
|
"fctx %p: %s", fctx, (m))
|
2000-05-26 02:16:10 +00:00
|
|
|
#define FCTXTRACE2(m1, m2) \
|
|
|
|
isc_log_write(dns_lctx, \
|
|
|
|
DNS_LOGCATEGORY_RESOLVER, \
|
|
|
|
DNS_LOGMODULE_RESOLVER, \
|
|
|
|
ISC_LOG_DEBUG(3), \
|
|
|
|
"fctx %p: %s %s", fctx, (m1), (m2))
|
1999-10-22 19:32:49 +00:00
|
|
|
#define FTRACE(m) isc_log_write(dns_lctx, \
|
|
|
|
DNS_LOGCATEGORY_RESOLVER, \
|
|
|
|
DNS_LOGMODULE_RESOLVER, \
|
1999-11-03 19:56:47 +00:00
|
|
|
ISC_LOG_DEBUG(3), \
|
1999-10-22 19:32:49 +00:00
|
|
|
"fetch %p (fctx %p): %s", \
|
|
|
|
fetch, fetch->private, (m))
|
|
|
|
#define QTRACE(m) isc_log_write(dns_lctx, \
|
|
|
|
DNS_LOGCATEGORY_RESOLVER, \
|
|
|
|
DNS_LOGMODULE_RESOLVER, \
|
1999-11-03 19:56:47 +00:00
|
|
|
ISC_LOG_DEBUG(3), \
|
1999-10-22 19:32:49 +00:00
|
|
|
"resquery %p (fctx %p): %s", \
|
|
|
|
query, query->fctx, (m))
|
1999-06-28 23:37:54 +00:00
|
|
|
#else
|
|
|
|
#define RTRACE(m)
|
|
|
|
#define RRTRACE(r, m)
|
|
|
|
#define FCTXTRACE(m)
|
|
|
|
#define FTRACE(m)
|
1999-07-24 01:26:18 +00:00
|
|
|
#define QTRACE(m)
|
1999-06-28 23:37:54 +00:00
|
|
|
#endif
|
|
|
|
|
1999-11-23 20:54:20 +00:00
|
|
|
/*
|
|
|
|
* Maximum EDNS0 input packet size.
|
|
|
|
*/
|
1999-11-16 21:07:13 +00:00
|
|
|
#define SEND_BUFFER_SIZE 2048 /* XXXRTH Constant. */
|
1999-10-19 19:52:56 +00:00
|
|
|
|
2000-06-26 21:07:36 +00:00
|
|
|
/*
|
2000-12-20 23:18:37 +00:00
|
|
|
* This defines the maximum number of timeouts we will permit before we
|
2000-06-26 21:07:36 +00:00
|
|
|
* disable EDNS0 on the query.
|
|
|
|
*/
|
2000-12-20 23:18:37 +00:00
|
|
|
#define MAX_EDNS0_TIMEOUTS 3
|
2000-06-26 21:07:36 +00:00
|
|
|
|
1999-07-24 01:26:18 +00:00
|
|
|
typedef struct fetchctx fetchctx_t;
|
|
|
|
|
1999-06-28 23:37:54 +00:00
|
|
|
typedef struct query {
|
1999-11-23 20:54:20 +00:00
|
|
|
/* Locked by task event serialization. */
|
1999-07-24 01:26:18 +00:00
|
|
|
unsigned int magic;
|
|
|
|
fetchctx_t * fctx;
|
2000-06-16 01:16:39 +00:00
|
|
|
isc_mem_t * mctx;
|
2000-05-17 20:33:29 +00:00
|
|
|
dns_dispatchmgr_t * dispatchmgr;
|
1999-07-24 01:26:18 +00:00
|
|
|
dns_dispatch_t * dispatch;
|
1999-11-05 09:50:52 +00:00
|
|
|
dns_adbaddrinfo_t * addrinfo;
|
2000-05-17 20:33:29 +00:00
|
|
|
isc_socket_t * tcpsocket;
|
1999-11-05 09:50:52 +00:00
|
|
|
isc_time_t start;
|
1999-06-28 23:37:54 +00:00
|
|
|
dns_messageid_t id;
|
1999-11-23 20:54:20 +00:00
|
|
|
dns_dispentry_t * dispentry;
|
1999-06-28 23:37:54 +00:00
|
|
|
ISC_LINK(struct query) link;
|
1999-07-03 20:54:56 +00:00
|
|
|
isc_buffer_t buffer;
|
2000-05-30 23:14:57 +00:00
|
|
|
isc_buffer_t *tsig;
|
1999-10-08 18:37:24 +00:00
|
|
|
dns_tsigkey_t *tsigkey;
|
1999-11-16 21:07:13 +00:00
|
|
|
unsigned int options;
|
1999-11-30 20:57:05 +00:00
|
|
|
unsigned int attributes;
|
2000-07-04 01:19:20 +00:00
|
|
|
unsigned int sends;
|
2001-03-16 21:50:59 +00:00
|
|
|
unsigned int connects;
|
1999-07-03 20:54:56 +00:00
|
|
|
unsigned char data[512];
|
1999-06-28 23:37:54 +00:00
|
|
|
} resquery_t;
|
|
|
|
|
2001-06-04 19:33:39 +00:00
|
|
|
#define QUERY_MAGIC ISC_MAGIC('Q', '!', '!', '!')
|
|
|
|
#define VALID_QUERY(query) ISC_MAGIC_VALID(query, QUERY_MAGIC)
|
1999-07-24 01:26:18 +00:00
|
|
|
|
1999-11-30 20:57:05 +00:00
|
|
|
#define RESQUERY_ATTR_CANCELED 0x02
|
|
|
|
|
2001-03-16 21:50:59 +00:00
|
|
|
#define RESQUERY_CONNECTING(q) ((q)->connects > 0)
|
1999-11-30 20:57:05 +00:00
|
|
|
#define RESQUERY_CANCELED(q) (((q)->attributes & \
|
|
|
|
RESQUERY_ATTR_CANCELED) != 0)
|
2000-07-04 01:19:20 +00:00
|
|
|
#define RESQUERY_SENDING(q) ((q)->sends > 0)
|
1999-11-30 20:57:05 +00:00
|
|
|
|
1999-06-28 23:37:54 +00:00
|
|
|
typedef enum {
|
1999-11-23 20:54:20 +00:00
|
|
|
fetchstate_init = 0, /* Start event has not run yet. */
|
1999-06-28 23:37:54 +00:00
|
|
|
fetchstate_active,
|
1999-11-23 20:54:20 +00:00
|
|
|
fetchstate_done /* FETCHDONE events posted. */
|
1999-06-28 23:37:54 +00:00
|
|
|
} fetchstate;
|
|
|
|
|
1999-07-24 01:26:18 +00:00
|
|
|
struct fetchctx {
|
|
|
|
/* Not locked. */
|
1999-06-28 23:37:54 +00:00
|
|
|
unsigned int magic;
|
|
|
|
dns_resolver_t * res;
|
|
|
|
dns_name_t name;
|
1999-10-07 19:41:16 +00:00
|
|
|
dns_rdatatype_t type;
|
1999-06-28 23:37:54 +00:00
|
|
|
unsigned int options;
|
1999-10-07 19:41:16 +00:00
|
|
|
unsigned int bucketnum;
|
1999-11-23 20:54:20 +00:00
|
|
|
/* Locked by appropriate bucket lock. */
|
1999-10-07 19:41:16 +00:00
|
|
|
fetchstate state;
|
1999-10-29 21:48:10 +00:00
|
|
|
isc_boolean_t want_shutdown;
|
2001-01-03 20:31:34 +00:00
|
|
|
isc_boolean_t cloned;
|
1999-10-07 19:41:16 +00:00
|
|
|
unsigned int references;
|
2000-02-14 23:19:45 +00:00
|
|
|
isc_event_t control_event;
|
1999-10-07 19:41:16 +00:00
|
|
|
ISC_LINK(struct fetchctx) link;
|
|
|
|
ISC_LIST(dns_fetchevent_t) events;
|
1999-11-23 20:54:20 +00:00
|
|
|
/* Locked by task event serialization. */
|
1999-07-24 01:26:18 +00:00
|
|
|
dns_name_t domain;
|
|
|
|
dns_rdataset_t nameservers;
|
1999-10-25 21:19:54 +00:00
|
|
|
unsigned int attributes;
|
1999-06-28 23:37:54 +00:00
|
|
|
isc_timer_t * timer;
|
|
|
|
isc_time_t expires;
|
|
|
|
isc_interval_t interval;
|
1999-07-03 20:54:56 +00:00
|
|
|
dns_message_t * qmessage;
|
|
|
|
dns_message_t * rmessage;
|
1999-06-28 23:37:54 +00:00
|
|
|
ISC_LIST(resquery_t) queries;
|
1999-11-05 09:50:52 +00:00
|
|
|
dns_adbfindlist_t finds;
|
1999-10-29 21:48:10 +00:00
|
|
|
dns_adbfind_t * find;
|
2000-01-12 02:59:48 +00:00
|
|
|
dns_adbaddrinfolist_t forwaddrs;
|
|
|
|
isc_sockaddrlist_t forwarders;
|
2000-08-24 22:15:40 +00:00
|
|
|
dns_fwdpolicy_t fwdpolicy;
|
2000-02-11 03:06:56 +00:00
|
|
|
isc_sockaddrlist_t bad;
|
2000-08-15 00:21:05 +00:00
|
|
|
ISC_LIST(dns_validator_t) validators;
|
2001-04-11 20:37:50 +00:00
|
|
|
dns_db_t * cache;
|
|
|
|
dns_adb_t * adb;
|
2001-01-02 20:46:07 +00:00
|
|
|
|
1999-11-23 20:54:20 +00:00
|
|
|
/*
|
2001-01-02 20:46:07 +00:00
|
|
|
* The number of events we're waiting for.
|
1999-11-23 20:54:20 +00:00
|
|
|
*/
|
1999-10-29 21:48:10 +00:00
|
|
|
unsigned int pending;
|
2001-01-02 20:46:07 +00:00
|
|
|
|
2000-12-20 23:18:37 +00:00
|
|
|
/*
|
2001-01-02 20:46:07 +00:00
|
|
|
* The number of times we've "restarted" the current
|
|
|
|
* nameserver set. This acts as a failsafe to prevent
|
|
|
|
* us from pounding constantly on a particular set of
|
|
|
|
* servers that, for whatever reason, are not giving
|
|
|
|
* us useful responses, but are responding in such a
|
|
|
|
* way that they are not marked "bad".
|
2000-12-20 23:18:37 +00:00
|
|
|
*/
|
1999-11-05 09:50:52 +00:00
|
|
|
unsigned int restarts;
|
2001-01-02 20:46:07 +00:00
|
|
|
|
2000-12-20 23:18:37 +00:00
|
|
|
/*
|
2001-01-02 20:46:07 +00:00
|
|
|
* The number of timeouts that have occurred since we
|
|
|
|
* last successfully received a response packet. This
|
|
|
|
* is used for EDNS0 black hole detection.
|
2000-12-20 23:18:37 +00:00
|
|
|
*/
|
|
|
|
unsigned int timeouts;
|
1999-07-24 01:26:18 +00:00
|
|
|
};
|
1999-06-28 23:37:54 +00:00
|
|
|
|
2001-06-04 19:33:39 +00:00
|
|
|
#define FCTX_MAGIC ISC_MAGIC('F', '!', '!', '!')
|
|
|
|
#define VALID_FCTX(fctx) ISC_MAGIC_VALID(fctx, FCTX_MAGIC)
|
1999-06-28 23:37:54 +00:00
|
|
|
|
1999-10-25 21:19:54 +00:00
|
|
|
#define FCTX_ATTR_HAVEANSWER 0x01
|
|
|
|
#define FCTX_ATTR_GLUING 0x02
|
1999-10-29 03:30:49 +00:00
|
|
|
#define FCTX_ATTR_ADDRWAIT 0x04
|
1999-10-29 21:48:10 +00:00
|
|
|
#define FCTX_ATTR_SHUTTINGDOWN 0x08
|
1999-11-03 03:19:17 +00:00
|
|
|
#define FCTX_ATTR_WANTCACHE 0x10
|
|
|
|
#define FCTX_ATTR_WANTNCACHE 0x20
|
2000-02-19 00:16:41 +00:00
|
|
|
#define FCTX_ATTR_NEEDEDNS0 0x40
|
1999-10-25 21:19:54 +00:00
|
|
|
|
|
|
|
#define HAVE_ANSWER(f) (((f)->attributes & FCTX_ATTR_HAVEANSWER) != \
|
|
|
|
0)
|
|
|
|
#define GLUING(f) (((f)->attributes & FCTX_ATTR_GLUING) != \
|
|
|
|
0)
|
1999-10-29 03:30:49 +00:00
|
|
|
#define ADDRWAIT(f) (((f)->attributes & FCTX_ATTR_ADDRWAIT) != \
|
|
|
|
0)
|
1999-10-29 21:48:10 +00:00
|
|
|
#define SHUTTINGDOWN(f) (((f)->attributes & FCTX_ATTR_SHUTTINGDOWN) \
|
|
|
|
!= 0)
|
1999-11-03 03:19:17 +00:00
|
|
|
#define WANTCACHE(f) (((f)->attributes & FCTX_ATTR_WANTCACHE) != 0)
|
|
|
|
#define WANTNCACHE(f) (((f)->attributes & FCTX_ATTR_WANTNCACHE) != 0)
|
2000-02-19 00:16:41 +00:00
|
|
|
#define NEEDEDNS0(f) (((f)->attributes & FCTX_ATTR_NEEDEDNS0) != 0)
|
1999-10-25 21:19:54 +00:00
|
|
|
|
1999-10-07 19:41:16 +00:00
|
|
|
struct dns_fetch {
|
|
|
|
unsigned int magic;
|
2001-02-17 02:16:14 +00:00
|
|
|
fetchctx_t * private;
|
1999-10-07 19:41:16 +00:00
|
|
|
};
|
|
|
|
|
2001-06-04 19:33:39 +00:00
|
|
|
#define DNS_FETCH_MAGIC ISC_MAGIC('F', 't', 'c', 'h')
|
|
|
|
#define DNS_FETCH_VALID(fetch) ISC_MAGIC_VALID(fetch, DNS_FETCH_MAGIC)
|
1999-10-07 19:41:16 +00:00
|
|
|
|
|
|
|
typedef struct fctxbucket {
|
|
|
|
isc_task_t * task;
|
|
|
|
isc_mutex_t lock;
|
|
|
|
ISC_LIST(fetchctx_t) fctxs;
|
1999-10-08 00:05:59 +00:00
|
|
|
isc_boolean_t exiting;
|
1999-10-07 19:41:16 +00:00
|
|
|
} fctxbucket_t;
|
|
|
|
|
1999-06-28 23:37:54 +00:00
|
|
|
struct dns_resolver {
|
1999-11-23 20:54:20 +00:00
|
|
|
/* Unlocked. */
|
1999-06-28 23:37:54 +00:00
|
|
|
unsigned int magic;
|
|
|
|
isc_mem_t * mctx;
|
|
|
|
isc_mutex_t lock;
|
|
|
|
dns_rdataclass_t rdclass;
|
1999-10-07 19:41:16 +00:00
|
|
|
isc_socketmgr_t * socketmgr;
|
1999-06-28 23:37:54 +00:00
|
|
|
isc_timermgr_t * timermgr;
|
Merge the mlg-20000518 branch onto the mainline. Change summary:
dns_dispatch_create() no longer exists. dns_dispatch_createtcp()
and dns_dispatch_getudp() are the replacements. _createtcp() takes
a bound, connected TCP socket, while _getudp() will search for
a sharable UDP socket, and if found, attach to it and return a
pointer to it. If one is not found, it will create a udp socket,
bind it to a supplied local address, and create a new dispatcher
around it.
dns_dispatch_remove{request,response}() no longer take the dispatch
as an argument.
query-source can now be set per view.
The dispatch manager holds onto three memory pools, one for
allocating dispatchers from, one for events, and one for
requests/replies. The free list on these pools is hard-coded,
but set to 1024. This keeps us from having to dig into the
isc_mem_t the pools draw from as often.
dns_resolver_create() and dns_view_createresolver() require that
valid dispatchers be passed in; dispatchers are no longer created
for the caller.
2000-05-19 21:46:46 +00:00
|
|
|
isc_taskmgr_t * taskmgr;
|
1999-09-22 19:45:09 +00:00
|
|
|
dns_view_t * view;
|
2000-01-12 02:59:48 +00:00
|
|
|
isc_boolean_t frozen;
|
2000-01-26 16:57:48 +00:00
|
|
|
unsigned int options;
|
2000-05-10 21:34:50 +00:00
|
|
|
dns_dispatchmgr_t * dispatchmgr;
|
2000-01-26 16:57:48 +00:00
|
|
|
dns_dispatch_t * dispatchv4;
|
|
|
|
dns_dispatch_t * dispatchv6;
|
1999-10-07 19:41:16 +00:00
|
|
|
unsigned int nbuckets;
|
|
|
|
fctxbucket_t * buckets;
|
2000-11-08 03:53:16 +00:00
|
|
|
isc_uint32_t lame_ttl;
|
2000-01-12 02:59:48 +00:00
|
|
|
/* Locked by lock. */
|
|
|
|
unsigned int references;
|
|
|
|
isc_boolean_t exiting;
|
|
|
|
isc_eventlist_t whenshutdown;
|
|
|
|
unsigned int activebuckets;
|
2000-01-27 02:55:47 +00:00
|
|
|
isc_boolean_t priming;
|
|
|
|
dns_fetch_t * primefetch;
|
2001-10-29 19:02:48 +00:00
|
|
|
unsigned int nfctx;
|
1999-06-28 23:37:54 +00:00
|
|
|
};
|
|
|
|
|
2001-06-04 19:33:39 +00:00
|
|
|
#define RES_MAGIC ISC_MAGIC('R', 'e', 's', '!')
|
|
|
|
#define VALID_RESOLVER(res) ISC_MAGIC_VALID(res, RES_MAGIC)
|
1999-06-28 23:37:54 +00:00
|
|
|
|
2000-01-12 02:59:48 +00:00
|
|
|
/*
|
|
|
|
* Private addrinfo flags. These must not conflict with DNS_FETCHOPT_NOEDNS0,
|
|
|
|
* which we also use as an addrinfo flag.
|
|
|
|
*/
|
|
|
|
#define FCTX_ADDRINFO_MARK 0x0001
|
|
|
|
#define FCTX_ADDRINFO_FORWARDER 0x1000
|
|
|
|
#define UNMARKED(a) (((a)->flags & FCTX_ADDRINFO_MARK) \
|
|
|
|
== 0)
|
|
|
|
#define ISFORWARDER(a) (((a)->flags & \
|
|
|
|
FCTX_ADDRINFO_FORWARDER) != 0)
|
1999-06-28 23:37:54 +00:00
|
|
|
|
|
|
|
static void destroy(dns_resolver_t *res);
|
1999-10-08 00:05:59 +00:00
|
|
|
static void empty_bucket(dns_resolver_t *res);
|
1999-11-16 21:07:13 +00:00
|
|
|
static isc_result_t resquery_send(resquery_t *query);
|
1999-10-20 19:20:48 +00:00
|
|
|
static void resquery_response(isc_task_t *task, isc_event_t *event);
|
1999-11-16 21:07:13 +00:00
|
|
|
static void resquery_connected(isc_task_t *task, isc_event_t *event);
|
1999-10-29 03:30:49 +00:00
|
|
|
static void fctx_try(fetchctx_t *fctx);
|
1999-10-29 21:48:10 +00:00
|
|
|
static isc_boolean_t fctx_destroy(fetchctx_t *fctx);
|
2000-05-04 16:38:09 +00:00
|
|
|
static isc_result_t ncache_adderesult(dns_message_t *message,
|
|
|
|
dns_db_t *cache, dns_dbnode_t *node,
|
|
|
|
dns_rdatatype_t covers,
|
2000-05-26 23:17:56 +00:00
|
|
|
isc_stdtime_t now, dns_ttl_t maxttl,
|
2000-05-04 16:38:09 +00:00
|
|
|
dns_rdataset_t *ardataset,
|
|
|
|
isc_result_t *eresultp);
|
1999-06-28 23:37:54 +00:00
|
|
|
|
1999-10-07 19:41:16 +00:00
|
|
|
static inline isc_result_t
|
1999-07-03 20:54:56 +00:00
|
|
|
fctx_starttimer(fetchctx_t *fctx) {
|
2000-02-11 21:10:40 +00:00
|
|
|
/*
|
|
|
|
* Start the lifetime timer for fctx.
|
2000-04-20 17:05:37 +00:00
|
|
|
*
|
|
|
|
* This is also used for stopping the idle timer; in that
|
|
|
|
* case we must purge events already posted to ensure that
|
|
|
|
* no further idle events are delivered.
|
2000-02-11 21:10:40 +00:00
|
|
|
*/
|
1999-10-20 19:20:48 +00:00
|
|
|
return (isc_timer_reset(fctx->timer, isc_timertype_once,
|
|
|
|
&fctx->expires, NULL,
|
2000-04-20 17:05:37 +00:00
|
|
|
ISC_TRUE));
|
1999-10-20 19:20:48 +00:00
|
|
|
}
|
|
|
|
|
1999-07-03 20:54:56 +00:00
|
|
|
static inline void
|
|
|
|
fctx_stoptimer(fetchctx_t *fctx) {
|
1999-10-07 19:41:16 +00:00
|
|
|
isc_result_t result;
|
1999-07-03 20:54:56 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* We don't return a result if resetting the timer to inactive fails
|
|
|
|
* since there's nothing to be done about it. Resetting to inactive
|
|
|
|
* should never fail anyway, since the code as currently written
|
|
|
|
* cannot fail in that case.
|
|
|
|
*/
|
1999-10-07 19:41:16 +00:00
|
|
|
result = isc_timer_reset(fctx->timer, isc_timertype_inactive,
|
1999-07-03 20:54:56 +00:00
|
|
|
NULL, NULL, ISC_TRUE);
|
1999-10-07 19:41:16 +00:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
1999-07-03 20:54:56 +00:00
|
|
|
UNEXPECTED_ERROR(__FILE__, __LINE__,
|
|
|
|
"isc_timer_reset(): %s",
|
1999-10-07 19:41:16 +00:00
|
|
|
isc_result_totext(result));
|
1999-07-03 20:54:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-02-11 21:10:40 +00:00
|
|
|
|
|
|
|
static inline isc_result_t
|
|
|
|
fctx_startidletimer(fetchctx_t *fctx) {
|
|
|
|
/*
|
|
|
|
* Start the idle timer for fctx. The lifetime timer continues
|
|
|
|
* to be in effect.
|
|
|
|
*/
|
|
|
|
return (isc_timer_reset(fctx->timer, isc_timertype_once,
|
|
|
|
&fctx->expires, &fctx->interval,
|
|
|
|
ISC_FALSE));
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Stopping the idle timer is equivalent to calling fctx_starttimer(), but
|
|
|
|
* we use fctx_stopidletimer for readability in the code below.
|
|
|
|
*/
|
|
|
|
#define fctx_stopidletimer fctx_starttimer
|
|
|
|
|
|
|
|
|
1999-11-30 20:57:05 +00:00
|
|
|
static inline void
|
|
|
|
resquery_destroy(resquery_t **queryp) {
|
|
|
|
resquery_t *query;
|
2000-08-01 01:33:37 +00:00
|
|
|
|
1999-11-30 20:57:05 +00:00
|
|
|
REQUIRE(queryp != NULL);
|
|
|
|
query = *queryp;
|
|
|
|
REQUIRE(!ISC_LINK_LINKED(query, link));
|
|
|
|
|
2000-05-17 20:33:29 +00:00
|
|
|
INSIST(query->tcpsocket == NULL);
|
2000-08-01 01:33:37 +00:00
|
|
|
|
1999-11-30 20:57:05 +00:00
|
|
|
query->magic = 0;
|
2000-07-04 01:19:20 +00:00
|
|
|
isc_mem_put(query->mctx, query, sizeof(*query));
|
1999-11-30 20:57:05 +00:00
|
|
|
*queryp = NULL;
|
|
|
|
}
|
|
|
|
|
1999-11-16 21:07:13 +00:00
|
|
|
static void
|
1999-11-05 09:50:52 +00:00
|
|
|
fctx_cancelquery(resquery_t **queryp, dns_dispatchevent_t **deventp,
|
1999-11-30 20:57:05 +00:00
|
|
|
isc_time_t *finish, isc_boolean_t no_response)
|
1999-11-05 09:50:52 +00:00
|
|
|
{
|
1999-10-12 20:39:35 +00:00
|
|
|
fetchctx_t *fctx;
|
|
|
|
resquery_t *query;
|
1999-11-05 09:50:52 +00:00
|
|
|
unsigned int rtt;
|
|
|
|
unsigned int factor;
|
1999-10-07 19:41:16 +00:00
|
|
|
|
1999-10-12 20:39:35 +00:00
|
|
|
query = *queryp;
|
|
|
|
fctx = query->fctx;
|
|
|
|
|
1999-10-13 02:08:30 +00:00
|
|
|
FCTXTRACE("cancelquery");
|
|
|
|
|
1999-11-30 20:57:05 +00:00
|
|
|
REQUIRE(!RESQUERY_CANCELED(query));
|
|
|
|
|
|
|
|
query->attributes |= RESQUERY_ATTR_CANCELED;
|
|
|
|
|
1999-11-23 20:54:20 +00:00
|
|
|
/*
|
1999-11-30 20:57:05 +00:00
|
|
|
* Should we update the RTT?
|
1999-11-23 20:54:20 +00:00
|
|
|
*/
|
1999-11-30 20:57:05 +00:00
|
|
|
if (finish != NULL || no_response) {
|
|
|
|
if (finish != NULL) {
|
|
|
|
/*
|
|
|
|
* We have both the start and finish times for this
|
|
|
|
* packet, so we can compute a real RTT.
|
|
|
|
*/
|
|
|
|
rtt = (unsigned int)isc_time_microdiff(finish,
|
|
|
|
&query->start);
|
|
|
|
factor = DNS_ADB_RTTADJDEFAULT;
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* We don't have an RTT for this query. Maybe the
|
|
|
|
* packet was lost, or maybe this server is very
|
|
|
|
* slow. We don't know. Increase the RTT.
|
|
|
|
*/
|
|
|
|
INSIST(no_response);
|
|
|
|
rtt = query->addrinfo->srtt +
|
|
|
|
(100000 * fctx->restarts);
|
|
|
|
if (rtt > 10000000)
|
|
|
|
rtt = 10000000;
|
|
|
|
/*
|
|
|
|
* Replace the current RTT with our value.
|
|
|
|
*/
|
|
|
|
factor = DNS_ADB_RTTADJREPLACE;
|
|
|
|
}
|
2001-04-11 20:37:50 +00:00
|
|
|
dns_adb_adjustsrtt(fctx->adb, query->addrinfo, rtt, factor);
|
1999-11-05 09:50:52 +00:00
|
|
|
}
|
|
|
|
|
1999-11-16 21:07:13 +00:00
|
|
|
if (query->dispentry != NULL)
|
Merge the mlg-20000518 branch onto the mainline. Change summary:
dns_dispatch_create() no longer exists. dns_dispatch_createtcp()
and dns_dispatch_getudp() are the replacements. _createtcp() takes
a bound, connected TCP socket, while _getudp() will search for
a sharable UDP socket, and if found, attach to it and return a
pointer to it. If one is not found, it will create a udp socket,
bind it to a supplied local address, and create a new dispatcher
around it.
dns_dispatch_remove{request,response}() no longer take the dispatch
as an argument.
query-source can now be set per view.
The dispatch manager holds onto three memory pools, one for
allocating dispatchers from, one for events, and one for
requests/replies. The free list on these pools is hard-coded,
but set to 1024. This keeps us from having to dig into the
isc_mem_t the pools draw from as often.
dns_resolver_create() and dns_view_createresolver() require that
valid dispatchers be passed in; dispatchers are no longer created
for the caller.
2000-05-19 21:46:46 +00:00
|
|
|
dns_dispatch_removeresponse(&query->dispentry, deventp);
|
2000-07-04 01:19:20 +00:00
|
|
|
|
1999-10-07 19:41:16 +00:00
|
|
|
ISC_LIST_UNLINK(fctx->queries, query, link);
|
2000-07-04 01:19:20 +00:00
|
|
|
|
2000-05-30 23:14:57 +00:00
|
|
|
if (query->tsig != NULL)
|
|
|
|
isc_buffer_free(&query->tsig);
|
2000-07-04 01:19:20 +00:00
|
|
|
|
2000-11-22 23:16:04 +00:00
|
|
|
if (query->tsigkey != NULL)
|
|
|
|
dns_tsigkey_detach(&query->tsigkey);
|
|
|
|
|
2000-07-04 01:19:20 +00:00
|
|
|
/*
|
|
|
|
* Check for any outstanding socket events. If they exist, cancel
|
|
|
|
* them and let the event handlers finish the cleanup. The resolver
|
|
|
|
* only needs to worry about managing the connect and send events;
|
|
|
|
* the dispatcher manages the recv events.
|
|
|
|
*/
|
|
|
|
if (RESQUERY_CONNECTING(query))
|
1999-11-30 20:57:05 +00:00
|
|
|
/*
|
|
|
|
* Cancel the connect.
|
|
|
|
*/
|
2000-05-17 20:33:29 +00:00
|
|
|
isc_socket_cancel(query->tcpsocket, NULL,
|
|
|
|
ISC_SOCKCANCEL_CONNECT);
|
2000-07-04 01:19:20 +00:00
|
|
|
else if (RESQUERY_SENDING(query))
|
|
|
|
/*
|
|
|
|
* Cancel the pending send.
|
|
|
|
*/
|
|
|
|
isc_socket_cancel(dns_dispatch_getsocket(query->dispatch),
|
|
|
|
NULL, ISC_SOCKCANCEL_SEND);
|
2000-05-17 20:33:29 +00:00
|
|
|
|
|
|
|
if (query->dispatch != NULL)
|
|
|
|
dns_dispatch_detach(&query->dispatch);
|
2000-08-01 01:33:37 +00:00
|
|
|
|
2000-07-04 01:19:20 +00:00
|
|
|
if (! (RESQUERY_CONNECTING(query) || RESQUERY_SENDING(query)))
|
1999-11-30 20:57:05 +00:00
|
|
|
/*
|
|
|
|
* It's safe to destroy the query now.
|
|
|
|
*/
|
|
|
|
resquery_destroy(&query);
|
1999-10-07 19:41:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
1999-11-30 20:57:05 +00:00
|
|
|
fctx_cancelqueries(fetchctx_t *fctx, isc_boolean_t no_response) {
|
1999-10-07 19:41:16 +00:00
|
|
|
resquery_t *query, *next_query;
|
|
|
|
|
|
|
|
FCTXTRACE("cancelqueries");
|
|
|
|
|
|
|
|
for (query = ISC_LIST_HEAD(fctx->queries);
|
|
|
|
query != NULL;
|
|
|
|
query = next_query) {
|
|
|
|
next_query = ISC_LIST_NEXT(query, link);
|
1999-11-30 20:57:05 +00:00
|
|
|
fctx_cancelquery(&query, NULL, NULL, no_response);
|
1999-10-07 19:41:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-10-12 20:39:35 +00:00
|
|
|
static void
|
1999-10-29 21:48:10 +00:00
|
|
|
fctx_cleanupfinds(fetchctx_t *fctx) {
|
|
|
|
dns_adbfind_t *find, *next_find;
|
|
|
|
|
1999-11-05 09:50:52 +00:00
|
|
|
REQUIRE(ISC_LIST_EMPTY(fctx->queries));
|
|
|
|
|
1999-10-29 21:48:10 +00:00
|
|
|
for (find = ISC_LIST_HEAD(fctx->finds);
|
|
|
|
find != NULL;
|
|
|
|
find = next_find) {
|
|
|
|
next_find = ISC_LIST_NEXT(find, publink);
|
|
|
|
ISC_LIST_UNLINK(fctx->finds, find, publink);
|
|
|
|
dns_adb_destroyfind(&find);
|
1999-10-12 20:39:35 +00:00
|
|
|
}
|
1999-10-29 21:48:10 +00:00
|
|
|
fctx->find = NULL;
|
1999-10-12 20:39:35 +00:00
|
|
|
}
|
|
|
|
|
2000-01-12 02:59:48 +00:00
|
|
|
static void
|
|
|
|
fctx_cleanupforwaddrs(fetchctx_t *fctx) {
|
|
|
|
dns_adbaddrinfo_t *addr, *next_addr;
|
|
|
|
|
|
|
|
REQUIRE(ISC_LIST_EMPTY(fctx->queries));
|
|
|
|
|
|
|
|
for (addr = ISC_LIST_HEAD(fctx->forwaddrs);
|
|
|
|
addr != NULL;
|
|
|
|
addr = next_addr) {
|
|
|
|
next_addr = ISC_LIST_NEXT(addr, publink);
|
|
|
|
ISC_LIST_UNLINK(fctx->forwaddrs, addr, publink);
|
2001-04-11 20:37:50 +00:00
|
|
|
dns_adb_freeaddrinfo(fctx->adb, &addr);
|
2000-01-12 02:59:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-10-29 21:48:10 +00:00
|
|
|
static inline void
|
2000-02-11 19:58:11 +00:00
|
|
|
fctx_stopeverything(fetchctx_t *fctx, isc_boolean_t no_response) {
|
1999-10-29 21:48:10 +00:00
|
|
|
FCTXTRACE("stopeverything");
|
2000-02-11 19:58:11 +00:00
|
|
|
fctx_cancelqueries(fctx, no_response);
|
1999-11-05 09:50:52 +00:00
|
|
|
fctx_cleanupfinds(fctx);
|
2000-01-12 02:59:48 +00:00
|
|
|
fctx_cleanupforwaddrs(fctx);
|
1999-07-03 20:54:56 +00:00
|
|
|
fctx_stoptimer(fctx);
|
1999-10-29 21:48:10 +00:00
|
|
|
}
|
1999-07-03 20:54:56 +00:00
|
|
|
|
1999-10-29 21:48:10 +00:00
|
|
|
static inline void
|
|
|
|
fctx_sendevents(fetchctx_t *fctx, isc_result_t result) {
|
|
|
|
dns_fetchevent_t *event, *next_event;
|
|
|
|
isc_task_t *task;
|
1999-10-07 19:41:16 +00:00
|
|
|
|
1999-10-29 21:48:10 +00:00
|
|
|
/*
|
|
|
|
* Caller must be holding the appropriate bucket lock.
|
|
|
|
*/
|
|
|
|
REQUIRE(fctx->state == fetchstate_done);
|
|
|
|
|
|
|
|
FCTXTRACE("sendevents");
|
1999-06-28 23:37:54 +00:00
|
|
|
|
|
|
|
for (event = ISC_LIST_HEAD(fctx->events);
|
|
|
|
event != NULL;
|
|
|
|
event = next_event) {
|
2000-04-17 19:21:30 +00:00
|
|
|
next_event = ISC_LIST_NEXT(event, ev_link);
|
2000-10-20 02:21:58 +00:00
|
|
|
ISC_LIST_UNLINK(fctx->events, event, ev_link);
|
2000-04-17 19:21:30 +00:00
|
|
|
task = event->ev_sender;
|
|
|
|
event->ev_sender = fctx;
|
1999-10-25 21:19:54 +00:00
|
|
|
if (!HAVE_ANSWER(fctx))
|
1999-10-11 19:24:28 +00:00
|
|
|
event->result = result;
|
2000-07-14 00:37:27 +00:00
|
|
|
|
|
|
|
INSIST(result != ISC_R_SUCCESS ||
|
|
|
|
dns_rdataset_isassociated(event->rdataset) ||
|
|
|
|
fctx->type == dns_rdatatype_any ||
|
|
|
|
fctx->type == dns_rdatatype_sig);
|
|
|
|
|
1999-09-23 21:31:03 +00:00
|
|
|
isc_task_sendanddetach(&task, (isc_event_t **)&event);
|
1999-06-28 23:37:54 +00:00
|
|
|
}
|
1999-10-29 21:48:10 +00:00
|
|
|
}
|
1999-10-07 19:41:16 +00:00
|
|
|
|
1999-10-29 21:48:10 +00:00
|
|
|
static void
|
|
|
|
fctx_done(fetchctx_t *fctx, isc_result_t result) {
|
|
|
|
dns_resolver_t *res;
|
2000-02-11 19:58:11 +00:00
|
|
|
isc_boolean_t no_response;
|
1999-10-29 21:48:10 +00:00
|
|
|
|
|
|
|
FCTXTRACE("done");
|
|
|
|
|
|
|
|
res = fctx->res;
|
|
|
|
|
2000-02-11 19:58:11 +00:00
|
|
|
if (result == ISC_R_SUCCESS)
|
|
|
|
no_response = ISC_TRUE;
|
|
|
|
else
|
|
|
|
no_response = ISC_FALSE;
|
|
|
|
fctx_stopeverything(fctx, no_response);
|
1999-10-29 21:48:10 +00:00
|
|
|
|
|
|
|
LOCK(&res->buckets[fctx->bucketnum].lock);
|
|
|
|
|
|
|
|
fctx->state = fetchstate_done;
|
2001-03-20 22:13:00 +00:00
|
|
|
fctx->attributes &= ~FCTX_ATTR_ADDRWAIT;
|
1999-10-29 21:48:10 +00:00
|
|
|
fctx_sendevents(fctx, result);
|
1999-10-07 19:41:16 +00:00
|
|
|
|
|
|
|
UNLOCK(&res->buckets[fctx->bucketnum].lock);
|
1999-06-28 23:37:54 +00:00
|
|
|
}
|
|
|
|
|
1999-07-24 01:26:18 +00:00
|
|
|
static void
|
1999-10-20 19:20:48 +00:00
|
|
|
resquery_senddone(isc_task_t *task, isc_event_t *event) {
|
1999-07-24 01:26:18 +00:00
|
|
|
isc_socketevent_t *sevent = (isc_socketevent_t *)event;
|
2000-04-17 19:21:30 +00:00
|
|
|
resquery_t *query = event->ev_arg;
|
1999-07-24 01:26:18 +00:00
|
|
|
|
2000-04-17 19:21:30 +00:00
|
|
|
REQUIRE(event->ev_type == ISC_SOCKEVENT_SENDDONE);
|
1999-07-24 01:26:18 +00:00
|
|
|
|
1999-11-16 21:07:13 +00:00
|
|
|
QTRACE("senddone");
|
|
|
|
|
1999-10-07 19:41:16 +00:00
|
|
|
/*
|
|
|
|
* XXXRTH
|
|
|
|
*
|
|
|
|
* Currently we don't wait for the senddone event before retrying
|
|
|
|
* a query. This means that if we get really behind, we may end
|
|
|
|
* up doing extra work!
|
|
|
|
*/
|
|
|
|
|
2000-04-11 23:15:30 +00:00
|
|
|
UNUSED(task);
|
1999-07-24 01:26:18 +00:00
|
|
|
|
2000-07-04 01:19:20 +00:00
|
|
|
INSIST(RESQUERY_SENDING(query));
|
|
|
|
|
|
|
|
query->sends--;
|
|
|
|
|
2000-07-07 19:43:14 +00:00
|
|
|
if (RESQUERY_CANCELED(query)) {
|
|
|
|
if (query->sends == 0) {
|
|
|
|
/*
|
|
|
|
* This query was canceled while the
|
|
|
|
* isc_socket_sendto() was in progress.
|
|
|
|
*/
|
|
|
|
if (query->tcpsocket != NULL)
|
|
|
|
isc_socket_detach(&query->tcpsocket);
|
|
|
|
resquery_destroy(&query);
|
|
|
|
}
|
|
|
|
} else if (sevent->result != ISC_R_SUCCESS)
|
|
|
|
fctx_cancelquery(&query, NULL, NULL, ISC_FALSE);
|
2000-07-04 01:19:20 +00:00
|
|
|
|
1999-07-24 01:26:18 +00:00
|
|
|
isc_event_free(&event);
|
|
|
|
}
|
|
|
|
|
1999-11-16 21:07:13 +00:00
|
|
|
static inline isc_result_t
|
|
|
|
fctx_addopt(dns_message_t *message) {
|
|
|
|
dns_rdataset_t *rdataset;
|
|
|
|
dns_rdatalist_t *rdatalist;
|
|
|
|
dns_rdata_t *rdata;
|
1999-10-07 19:41:16 +00:00
|
|
|
isc_result_t result;
|
1999-11-16 21:07:13 +00:00
|
|
|
|
|
|
|
rdatalist = NULL;
|
|
|
|
result = dns_message_gettemprdatalist(message, &rdatalist);
|
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
return (result);
|
|
|
|
rdata = NULL;
|
|
|
|
result = dns_message_gettemprdata(message, &rdata);
|
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
return (result);
|
|
|
|
rdataset = NULL;
|
|
|
|
result = dns_message_gettemprdataset(message, &rdataset);
|
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
return (result);
|
|
|
|
dns_rdataset_init(rdataset);
|
|
|
|
|
|
|
|
rdatalist->type = dns_rdatatype_opt;
|
|
|
|
rdatalist->covers = 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set Maximum UDP buffer size.
|
|
|
|
*/
|
|
|
|
rdatalist->rdclass = SEND_BUFFER_SIZE;
|
|
|
|
|
|
|
|
/*
|
2000-11-13 21:34:03 +00:00
|
|
|
* Set EXTENDED-RCODE, VERSION, and Z to 0, and the DO bit to 1.
|
1999-11-16 21:07:13 +00:00
|
|
|
*/
|
2000-11-13 21:34:03 +00:00
|
|
|
rdatalist->ttl = DNS_MESSAGEEXTFLAG_DO;
|
1999-11-16 21:07:13 +00:00
|
|
|
|
|
|
|
/*
|
2000-11-13 21:34:03 +00:00
|
|
|
* No EDNS options.
|
1999-11-16 21:07:13 +00:00
|
|
|
*/
|
|
|
|
rdata->data = NULL;
|
|
|
|
rdata->length = 0;
|
2000-03-29 18:53:57 +00:00
|
|
|
rdata->rdclass = rdatalist->rdclass;
|
|
|
|
rdata->type = rdatalist->type;
|
2000-10-25 04:26:57 +00:00
|
|
|
rdata->flags = 0;
|
1999-11-16 21:07:13 +00:00
|
|
|
|
|
|
|
ISC_LIST_INIT(rdatalist->rdata);
|
|
|
|
ISC_LIST_APPEND(rdatalist->rdata, rdata, link);
|
|
|
|
dns_rdatalist_tordataset(rdatalist, rdataset);
|
|
|
|
|
|
|
|
return (dns_message_setopt(message, rdataset));
|
|
|
|
}
|
|
|
|
|
1999-12-13 22:30:55 +00:00
|
|
|
static inline void
|
|
|
|
fctx_setretryinterval(fetchctx_t *fctx, unsigned int rtt) {
|
|
|
|
unsigned int seconds;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We retry every 2 seconds the first two times through the address
|
|
|
|
* list, and then we do exponential back-off.
|
|
|
|
*/
|
|
|
|
if (fctx->restarts < 3)
|
|
|
|
seconds = 2;
|
|
|
|
else
|
|
|
|
seconds = (2 << (fctx->restarts - 1));
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Double the round-trip time and convert to seconds.
|
|
|
|
*/
|
|
|
|
rtt /= 500000;
|
2000-08-01 01:33:37 +00:00
|
|
|
|
1999-12-13 22:30:55 +00:00
|
|
|
/*
|
|
|
|
* Always wait for at least the doubled round-trip time.
|
|
|
|
*/
|
|
|
|
if (seconds < rtt)
|
|
|
|
seconds = rtt;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* But don't ever wait for more than 30 seconds.
|
|
|
|
*/
|
|
|
|
if (seconds > 30)
|
|
|
|
seconds = 30;
|
|
|
|
|
|
|
|
isc_interval_set(&fctx->interval, seconds, 0);
|
|
|
|
}
|
|
|
|
|
1999-11-16 21:07:13 +00:00
|
|
|
static isc_result_t
|
|
|
|
fctx_query(fetchctx_t *fctx, dns_adbaddrinfo_t *addrinfo,
|
|
|
|
unsigned int options)
|
|
|
|
{
|
1999-10-07 19:41:16 +00:00
|
|
|
dns_resolver_t *res;
|
|
|
|
isc_task_t *task;
|
1999-11-16 21:07:13 +00:00
|
|
|
isc_result_t result;
|
|
|
|
resquery_t *query;
|
1999-06-28 23:37:54 +00:00
|
|
|
|
1999-11-16 21:07:13 +00:00
|
|
|
FCTXTRACE("query");
|
1999-06-28 23:37:54 +00:00
|
|
|
|
1999-10-07 19:41:16 +00:00
|
|
|
res = fctx->res;
|
|
|
|
task = res->buckets[fctx->bucketnum].task;
|
1999-07-24 01:26:18 +00:00
|
|
|
|
1999-12-13 22:30:55 +00:00
|
|
|
fctx_setretryinterval(fctx, addrinfo->srtt);
|
2000-02-11 21:10:40 +00:00
|
|
|
result = fctx_startidletimer(fctx);
|
1999-10-07 19:41:16 +00:00
|
|
|
if (result != ISC_R_SUCCESS)
|
1999-07-03 20:54:56 +00:00
|
|
|
return (result);
|
|
|
|
|
1999-07-24 01:26:18 +00:00
|
|
|
dns_message_reset(fctx->rmessage, DNS_MESSAGE_INTENTPARSE);
|
1999-07-03 20:54:56 +00:00
|
|
|
|
2001-11-12 19:05:39 +00:00
|
|
|
query = isc_mem_get(res->mctx, sizeof(*query));
|
1999-11-05 09:50:52 +00:00
|
|
|
if (query == NULL) {
|
Merge the mlg-20000518 branch onto the mainline. Change summary:
dns_dispatch_create() no longer exists. dns_dispatch_createtcp()
and dns_dispatch_getudp() are the replacements. _createtcp() takes
a bound, connected TCP socket, while _getudp() will search for
a sharable UDP socket, and if found, attach to it and return a
pointer to it. If one is not found, it will create a udp socket,
bind it to a supplied local address, and create a new dispatcher
around it.
dns_dispatch_remove{request,response}() no longer take the dispatch
as an argument.
query-source can now be set per view.
The dispatch manager holds onto three memory pools, one for
allocating dispatchers from, one for events, and one for
requests/replies. The free list on these pools is hard-coded,
but set to 1024. This keeps us from having to dig into the
isc_mem_t the pools draw from as often.
dns_resolver_create() and dns_view_createresolver() require that
valid dispatchers be passed in; dispatchers are no longer created
for the caller.
2000-05-19 21:46:46 +00:00
|
|
|
result = ISC_R_NOMEMORY;
|
2000-02-11 21:10:40 +00:00
|
|
|
goto stop_idle_timer;
|
1999-11-05 09:50:52 +00:00
|
|
|
}
|
2000-06-16 01:16:39 +00:00
|
|
|
query->mctx = res->mctx;
|
1999-11-16 21:07:13 +00:00
|
|
|
query->options = options;
|
1999-11-30 20:57:05 +00:00
|
|
|
query->attributes = 0;
|
2000-07-04 01:19:20 +00:00
|
|
|
query->sends = 0;
|
2001-03-16 21:50:59 +00:00
|
|
|
query->connects = 0;
|
1999-11-05 09:50:52 +00:00
|
|
|
/*
|
|
|
|
* Note that the caller MUST guarantee that 'addrinfo' will remain
|
|
|
|
* valid until this query is canceled.
|
|
|
|
*/
|
|
|
|
query->addrinfo = addrinfo;
|
|
|
|
result = isc_time_now(&query->start);
|
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
goto cleanup_query;
|
2000-08-01 01:33:37 +00:00
|
|
|
|
1999-07-24 01:26:18 +00:00
|
|
|
/*
|
|
|
|
* If this is a TCP query, then we need to make a socket and
|
|
|
|
* a dispatch for it here. Otherwise we use the resolver's
|
1999-11-16 21:07:13 +00:00
|
|
|
* shared dispatch.
|
|
|
|
*/
|
2000-05-17 20:33:29 +00:00
|
|
|
query->dispatchmgr = res->dispatchmgr;
|
1999-11-16 21:07:13 +00:00
|
|
|
query->dispatch = NULL;
|
2000-05-17 20:33:29 +00:00
|
|
|
query->tcpsocket = NULL;
|
1999-11-16 21:07:13 +00:00
|
|
|
if ((query->options & DNS_FETCHOPT_TCP) != 0) {
|
2001-03-13 05:49:58 +00:00
|
|
|
isc_sockaddr_t addr;
|
2000-06-01 00:30:58 +00:00
|
|
|
int pf;
|
2000-05-17 20:33:29 +00:00
|
|
|
|
2000-06-01 00:30:58 +00:00
|
|
|
pf = isc_sockaddr_pf(&addrinfo->sockaddr);
|
|
|
|
|
2001-03-13 05:49:58 +00:00
|
|
|
switch (pf) {
|
|
|
|
case PF_INET:
|
|
|
|
result = dns_dispatch_getlocaladdress(res->dispatchv4,
|
|
|
|
&addr);
|
|
|
|
break;
|
|
|
|
case PF_INET6:
|
|
|
|
result = dns_dispatch_getlocaladdress(res->dispatchv6,
|
|
|
|
&addr);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
result = ISC_R_NOTIMPLEMENTED;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
goto cleanup_query;
|
|
|
|
|
|
|
|
isc_sockaddr_setport(&addr, 0);
|
|
|
|
|
2000-08-01 01:33:37 +00:00
|
|
|
result = isc_socket_create(res->socketmgr, pf,
|
1999-11-16 21:07:13 +00:00
|
|
|
isc_sockettype_tcp,
|
2000-05-17 20:33:29 +00:00
|
|
|
&query->tcpsocket);
|
1999-11-16 21:07:13 +00:00
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
goto cleanup_query;
|
2000-05-17 20:33:29 +00:00
|
|
|
|
2001-03-13 05:49:58 +00:00
|
|
|
result = isc_socket_bind(query->tcpsocket, &addr);
|
2000-06-05 22:31:54 +00:00
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
goto cleanup_socket;
|
2000-08-01 01:33:37 +00:00
|
|
|
|
1999-11-16 21:07:13 +00:00
|
|
|
/*
|
2000-05-17 20:33:29 +00:00
|
|
|
* A dispatch will be created once the connect succeeds.
|
1999-11-16 21:07:13 +00:00
|
|
|
*/
|
1999-10-07 19:41:16 +00:00
|
|
|
} else {
|
2000-06-01 00:30:58 +00:00
|
|
|
switch (isc_sockaddr_pf(&addrinfo->sockaddr)) {
|
1999-11-16 21:07:13 +00:00
|
|
|
case PF_INET:
|
2000-01-26 16:57:48 +00:00
|
|
|
dns_dispatch_attach(res->dispatchv4, &query->dispatch);
|
1999-10-07 19:41:16 +00:00
|
|
|
break;
|
1999-11-16 21:07:13 +00:00
|
|
|
case PF_INET6:
|
2000-01-26 16:57:48 +00:00
|
|
|
dns_dispatch_attach(res->dispatchv6, &query->dispatch);
|
1999-10-07 19:41:16 +00:00
|
|
|
break;
|
|
|
|
default:
|
2000-04-06 22:03:35 +00:00
|
|
|
result = ISC_R_NOTIMPLEMENTED;
|
2000-05-17 20:33:29 +00:00
|
|
|
goto cleanup_query;
|
1999-10-07 19:41:16 +00:00
|
|
|
}
|
|
|
|
/*
|
|
|
|
* We should always have a valid dispatcher here. If we
|
|
|
|
* don't support a protocol family, then its dispatcher
|
|
|
|
* will be NULL, but we shouldn't be finding addresses for
|
|
|
|
* protocol types we don't support, so the dispatcher
|
|
|
|
* we found should never be NULL.
|
|
|
|
*/
|
|
|
|
INSIST(query->dispatch != NULL);
|
|
|
|
}
|
1999-11-16 21:07:13 +00:00
|
|
|
|
|
|
|
query->dispentry = NULL;
|
|
|
|
query->fctx = fctx;
|
|
|
|
query->tsig = NULL;
|
|
|
|
query->tsigkey = NULL;
|
2000-10-20 02:21:58 +00:00
|
|
|
ISC_LINK_INIT(query, link);
|
1999-11-16 21:07:13 +00:00
|
|
|
query->magic = QUERY_MAGIC;
|
|
|
|
|
|
|
|
if ((query->options & DNS_FETCHOPT_TCP) != 0) {
|
|
|
|
/*
|
|
|
|
* Connect to the remote server.
|
|
|
|
*
|
|
|
|
* XXXRTH Should we attach to the socket?
|
|
|
|
*/
|
2000-05-24 05:10:00 +00:00
|
|
|
result = isc_socket_connect(query->tcpsocket,
|
2000-06-01 00:30:58 +00:00
|
|
|
&addrinfo->sockaddr, task,
|
2000-05-24 05:10:00 +00:00
|
|
|
resquery_connected, query);
|
1999-11-16 21:07:13 +00:00
|
|
|
if (result != ISC_R_SUCCESS)
|
2000-06-05 22:31:54 +00:00
|
|
|
goto cleanup_socket;
|
2001-03-16 21:50:59 +00:00
|
|
|
query->connects++;
|
1999-11-16 21:07:13 +00:00
|
|
|
QTRACE("connecting via TCP");
|
|
|
|
} else {
|
|
|
|
result = resquery_send(query);
|
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
goto cleanup_dispatch;
|
|
|
|
}
|
|
|
|
|
1999-11-30 20:57:05 +00:00
|
|
|
ISC_LIST_APPEND(fctx->queries, query, link);
|
|
|
|
|
1999-11-16 21:07:13 +00:00
|
|
|
return (ISC_R_SUCCESS);
|
|
|
|
|
2000-06-05 22:31:54 +00:00
|
|
|
cleanup_socket:
|
|
|
|
isc_socket_detach(&query->tcpsocket);
|
|
|
|
|
1999-11-16 21:07:13 +00:00
|
|
|
cleanup_dispatch:
|
2000-06-05 22:31:54 +00:00
|
|
|
if (query->dispatch != NULL)
|
|
|
|
dns_dispatch_detach(&query->dispatch);
|
1999-11-16 21:07:13 +00:00
|
|
|
|
|
|
|
cleanup_query:
|
|
|
|
query->magic = 0;
|
2001-11-12 19:05:39 +00:00
|
|
|
isc_mem_put(res->mctx, query, sizeof(*query));
|
1999-11-16 21:07:13 +00:00
|
|
|
|
2000-02-11 21:10:40 +00:00
|
|
|
stop_idle_timer:
|
|
|
|
fctx_stopidletimer(fctx);
|
1999-11-16 21:07:13 +00:00
|
|
|
|
|
|
|
return (result);
|
|
|
|
}
|
|
|
|
|
|
|
|
static isc_result_t
|
|
|
|
resquery_send(resquery_t *query) {
|
|
|
|
fetchctx_t *fctx;
|
|
|
|
isc_result_t result;
|
2001-02-17 02:16:14 +00:00
|
|
|
dns_name_t *qname = NULL;
|
|
|
|
dns_rdataset_t *qrdataset = NULL;
|
1999-11-16 21:07:13 +00:00
|
|
|
isc_region_t r;
|
|
|
|
dns_resolver_t *res;
|
|
|
|
isc_task_t *task;
|
|
|
|
isc_socket_t *socket;
|
|
|
|
isc_buffer_t tcpbuffer;
|
2000-11-04 02:20:58 +00:00
|
|
|
isc_sockaddr_t *address;
|
1999-11-16 21:07:13 +00:00
|
|
|
isc_buffer_t *buffer;
|
2000-03-03 19:48:14 +00:00
|
|
|
isc_netaddr_t ipaddr;
|
2000-08-17 00:18:12 +00:00
|
|
|
dns_tsigkey_t *tsigkey = NULL;
|
2000-11-04 02:20:58 +00:00
|
|
|
dns_peer_t *peer = NULL;
|
2001-03-06 23:54:37 +00:00
|
|
|
isc_boolean_t useedns;
|
2001-03-05 21:15:47 +00:00
|
|
|
dns_compress_t cctx;
|
|
|
|
isc_boolean_t cleanup_cctx = ISC_FALSE;
|
1999-11-16 21:07:13 +00:00
|
|
|
|
|
|
|
fctx = query->fctx;
|
|
|
|
QTRACE("send");
|
|
|
|
|
|
|
|
res = fctx->res;
|
|
|
|
task = res->buckets[fctx->bucketnum].task;
|
|
|
|
address = NULL;
|
|
|
|
|
|
|
|
if ((query->options & DNS_FETCHOPT_TCP) != 0) {
|
|
|
|
/*
|
|
|
|
* Reserve space for the TCP message length.
|
|
|
|
*/
|
103. [func] libisc buffer API changes for <isc/buffer.h>:
Added:
isc_buffer_base(b) (pointer)
isc_buffer_current(b) (pointer)
isc_buffer_active(b) (pointer)
isc_buffer_used(b) (pointer)
isc_buffer_length(b) (int)
isc_buffer_usedlength(b) (int)
isc_buffer_consumedlength(b) (int)
isc_buffer_remaininglength(b) (int)
isc_buffer_activelength(b) (int)
isc_buffer_availablelength(b) (int)
Removed:
ISC_BUFFER_USEDCOUNT(b)
ISC_BUFFER_AVAILABLECOUNT(b)
isc_buffer_type(b)
Changed names:
isc_buffer_used(b, r) ->
isc_buffer_usedregion(b, r)
isc_buffer_available(b, r) ->
isc_buffer_available_region(b, r)
isc_buffer_consumed(b, r) ->
isc_buffer_consumedregion(b, r)
isc_buffer_active(b, r) ->
isc_buffer_activeregion(b, r)
isc_buffer_remaining(b, r) ->
isc_buffer_remainingregion(b, r)
Buffer types were removed, so the ISC_BUFFERTYPE_*
macros are no more, and the type argument to
isc_buffer_init and isc_buffer_allocate were removed.
isc_buffer_putstr is now void (instead of isc_result_t)
and requires that the caller ensure that there
is enough available buffer space for the string.
2000-04-27 00:03:12 +00:00
|
|
|
isc_buffer_init(&tcpbuffer, query->data, sizeof(query->data));
|
1999-11-16 21:07:13 +00:00
|
|
|
isc_buffer_init(&query->buffer, query->data + 2,
|
103. [func] libisc buffer API changes for <isc/buffer.h>:
Added:
isc_buffer_base(b) (pointer)
isc_buffer_current(b) (pointer)
isc_buffer_active(b) (pointer)
isc_buffer_used(b) (pointer)
isc_buffer_length(b) (int)
isc_buffer_usedlength(b) (int)
isc_buffer_consumedlength(b) (int)
isc_buffer_remaininglength(b) (int)
isc_buffer_activelength(b) (int)
isc_buffer_availablelength(b) (int)
Removed:
ISC_BUFFER_USEDCOUNT(b)
ISC_BUFFER_AVAILABLECOUNT(b)
isc_buffer_type(b)
Changed names:
isc_buffer_used(b, r) ->
isc_buffer_usedregion(b, r)
isc_buffer_available(b, r) ->
isc_buffer_available_region(b, r)
isc_buffer_consumed(b, r) ->
isc_buffer_consumedregion(b, r)
isc_buffer_active(b, r) ->
isc_buffer_activeregion(b, r)
isc_buffer_remaining(b, r) ->
isc_buffer_remainingregion(b, r)
Buffer types were removed, so the ISC_BUFFERTYPE_*
macros are no more, and the type argument to
isc_buffer_init and isc_buffer_allocate were removed.
isc_buffer_putstr is now void (instead of isc_result_t)
and requires that the caller ensure that there
is enough available buffer space for the string.
2000-04-27 00:03:12 +00:00
|
|
|
sizeof(query->data) - 2);
|
1999-11-16 21:07:13 +00:00
|
|
|
buffer = &tcpbuffer;
|
|
|
|
} else {
|
|
|
|
isc_buffer_init(&query->buffer, query->data,
|
103. [func] libisc buffer API changes for <isc/buffer.h>:
Added:
isc_buffer_base(b) (pointer)
isc_buffer_current(b) (pointer)
isc_buffer_active(b) (pointer)
isc_buffer_used(b) (pointer)
isc_buffer_length(b) (int)
isc_buffer_usedlength(b) (int)
isc_buffer_consumedlength(b) (int)
isc_buffer_remaininglength(b) (int)
isc_buffer_activelength(b) (int)
isc_buffer_availablelength(b) (int)
Removed:
ISC_BUFFER_USEDCOUNT(b)
ISC_BUFFER_AVAILABLECOUNT(b)
isc_buffer_type(b)
Changed names:
isc_buffer_used(b, r) ->
isc_buffer_usedregion(b, r)
isc_buffer_available(b, r) ->
isc_buffer_available_region(b, r)
isc_buffer_consumed(b, r) ->
isc_buffer_consumedregion(b, r)
isc_buffer_active(b, r) ->
isc_buffer_activeregion(b, r)
isc_buffer_remaining(b, r) ->
isc_buffer_remainingregion(b, r)
Buffer types were removed, so the ISC_BUFFERTYPE_*
macros are no more, and the type argument to
isc_buffer_init and isc_buffer_allocate were removed.
isc_buffer_putstr is now void (instead of isc_result_t)
and requires that the caller ensure that there
is enough available buffer space for the string.
2000-04-27 00:03:12 +00:00
|
|
|
sizeof(query->data));
|
1999-11-16 21:07:13 +00:00
|
|
|
buffer = &query->buffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
result = dns_message_gettempname(fctx->qmessage, &qname);
|
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
goto cleanup_temps;
|
|
|
|
result = dns_message_gettemprdataset(fctx->qmessage, &qrdataset);
|
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
goto cleanup_temps;
|
|
|
|
|
1999-07-03 20:54:56 +00:00
|
|
|
/*
|
1999-07-24 01:26:18 +00:00
|
|
|
* Get a query id from the dispatch.
|
1999-07-03 20:54:56 +00:00
|
|
|
*/
|
1999-07-24 01:26:18 +00:00
|
|
|
result = dns_dispatch_addresponse(query->dispatch,
|
2000-06-01 00:30:58 +00:00
|
|
|
&query->addrinfo->sockaddr,
|
1999-10-07 19:41:16 +00:00
|
|
|
task,
|
1999-10-20 19:20:48 +00:00
|
|
|
resquery_response,
|
1999-07-24 01:26:18 +00:00
|
|
|
query,
|
|
|
|
&query->id,
|
|
|
|
&query->dispentry);
|
1999-10-07 19:41:16 +00:00
|
|
|
if (result != ISC_R_SUCCESS)
|
1999-11-16 21:07:13 +00:00
|
|
|
goto cleanup_temps;
|
1999-07-03 20:54:56 +00:00
|
|
|
|
|
|
|
fctx->qmessage->opcode = dns_opcode_query;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set up question.
|
|
|
|
*/
|
1999-10-07 19:41:16 +00:00
|
|
|
dns_name_init(qname, NULL);
|
|
|
|
dns_name_clone(&fctx->name, qname);
|
|
|
|
dns_rdataset_init(qrdataset);
|
|
|
|
dns_rdataset_makequestion(qrdataset, res->rdclass, fctx->type);
|
|
|
|
ISC_LIST_APPEND(qname->list, qrdataset, link);
|
|
|
|
dns_message_addname(fctx->qmessage, qname, DNS_SECTION_QUESTION);
|
2000-02-19 00:16:41 +00:00
|
|
|
qname = NULL;
|
|
|
|
qrdataset = NULL;
|
2000-01-12 02:59:48 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Set RD if the client has requested that we do a recursive query,
|
|
|
|
* or if we're sending to a forwarder.
|
|
|
|
*/
|
|
|
|
if ((query->options & DNS_FETCHOPT_RECURSIVE) != 0 ||
|
|
|
|
ISFORWARDER(query->addrinfo))
|
1999-07-03 20:54:56 +00:00
|
|
|
fctx->qmessage->flags |= DNS_MESSAGEFLAG_RD;
|
2000-01-12 02:59:48 +00:00
|
|
|
|
1999-07-03 20:54:56 +00:00
|
|
|
/*
|
|
|
|
* We don't have to set opcode because it defaults to query.
|
|
|
|
*/
|
1999-07-24 01:26:18 +00:00
|
|
|
fctx->qmessage->id = query->id;
|
1999-07-03 20:54:56 +00:00
|
|
|
|
1999-07-24 01:26:18 +00:00
|
|
|
/*
|
|
|
|
* Convert the question to wire format.
|
|
|
|
*/
|
2001-03-05 21:15:47 +00:00
|
|
|
result = dns_compress_init(&cctx, -1, fctx->res->mctx);
|
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
goto cleanup_message;
|
|
|
|
cleanup_cctx = ISC_TRUE;
|
|
|
|
|
|
|
|
result = dns_message_renderbegin(fctx->qmessage, &cctx,
|
|
|
|
&query->buffer);
|
1999-10-07 19:41:16 +00:00
|
|
|
if (result != ISC_R_SUCCESS)
|
1999-07-24 01:26:18 +00:00
|
|
|
goto cleanup_message;
|
1999-11-16 21:07:13 +00:00
|
|
|
|
1999-07-03 20:54:56 +00:00
|
|
|
result = dns_message_rendersection(fctx->qmessage,
|
1999-12-22 03:22:59 +00:00
|
|
|
DNS_SECTION_QUESTION, 0);
|
1999-10-07 19:41:16 +00:00
|
|
|
if (result != ISC_R_SUCCESS)
|
1999-07-24 01:26:18 +00:00
|
|
|
goto cleanup_message;
|
1999-11-16 21:07:13 +00:00
|
|
|
|
2001-03-06 23:54:37 +00:00
|
|
|
peer = NULL;
|
|
|
|
isc_netaddr_fromsockaddr(&ipaddr, &query->addrinfo->sockaddr);
|
|
|
|
(void) dns_peerlist_peerbyaddr(fctx->res->view->peers, &ipaddr, &peer);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The ADB does not know about servers with "edns no". Check this,
|
|
|
|
* and then inform the ADB for future use.
|
|
|
|
*/
|
|
|
|
if ((query->addrinfo->flags & DNS_FETCHOPT_NOEDNS0) == 0 &&
|
|
|
|
peer != NULL &&
|
|
|
|
dns_peer_getsupportedns(peer, &useedns) == ISC_R_SUCCESS &&
|
|
|
|
!useedns)
|
|
|
|
{
|
|
|
|
query->options |= DNS_FETCHOPT_NOEDNS0;
|
2001-04-11 20:37:50 +00:00
|
|
|
dns_adb_changeflags(fctx->adb,
|
2001-03-06 23:54:37 +00:00
|
|
|
query->addrinfo,
|
|
|
|
DNS_FETCHOPT_NOEDNS0,
|
|
|
|
DNS_FETCHOPT_NOEDNS0);
|
|
|
|
}
|
|
|
|
|
1999-11-16 21:07:13 +00:00
|
|
|
/*
|
|
|
|
* Use EDNS0, unless the caller doesn't want it, or we know that
|
|
|
|
* the remote server doesn't like it.
|
|
|
|
*/
|
2001-01-02 17:59:13 +00:00
|
|
|
if (fctx->timeouts >= MAX_EDNS0_TIMEOUTS &&
|
|
|
|
(query->options & DNS_FETCHOPT_NOEDNS0) == 0) {
|
2000-06-26 21:07:36 +00:00
|
|
|
query->options |= DNS_FETCHOPT_NOEDNS0;
|
2000-12-20 23:18:37 +00:00
|
|
|
FCTXTRACE("too many timeouts, disabling EDNS0");
|
2000-06-26 21:07:36 +00:00
|
|
|
}
|
|
|
|
|
1999-11-16 21:07:13 +00:00
|
|
|
if ((query->options & DNS_FETCHOPT_NOEDNS0) == 0) {
|
|
|
|
if ((query->addrinfo->flags & DNS_FETCHOPT_NOEDNS0) == 0) {
|
|
|
|
result = fctx_addopt(fctx->qmessage);
|
|
|
|
if (result != ISC_R_SUCCESS) {
|
|
|
|
/*
|
|
|
|
* We couldn't add the OPT, but we'll press on.
|
|
|
|
* We're not using EDNS0, so set the NOEDNS0
|
|
|
|
* bit.
|
|
|
|
*/
|
|
|
|
query->options |= DNS_FETCHOPT_NOEDNS0;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* We know this server doesn't like EDNS0, so we
|
|
|
|
* won't use it. Set the NOEDNS0 bit since we're
|
|
|
|
* not using EDNS0.
|
|
|
|
*/
|
|
|
|
query->options |= DNS_FETCHOPT_NOEDNS0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-02-19 00:16:41 +00:00
|
|
|
/*
|
|
|
|
* If we need EDNS0 to do this query and aren't using it, we lose.
|
|
|
|
*/
|
|
|
|
if (NEEDEDNS0(fctx) && (query->options & DNS_FETCHOPT_NOEDNS0) != 0) {
|
|
|
|
result = DNS_R_SERVFAIL;
|
|
|
|
goto cleanup_message;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2000-11-13 21:34:03 +00:00
|
|
|
* If we're using EDNS, set CD. CD and EDNS aren't really related,
|
|
|
|
* but if we send a non EDNS query, there's a chance the server
|
|
|
|
* won't understand CD either.
|
2000-02-19 00:16:41 +00:00
|
|
|
*/
|
|
|
|
if ((query->options & DNS_FETCHOPT_NOEDNS0) == 0)
|
2000-11-13 21:34:03 +00:00
|
|
|
fctx->qmessage->flags |= DNS_MESSAGEFLAG_CD;
|
2000-02-19 00:16:41 +00:00
|
|
|
|
1999-11-16 21:07:13 +00:00
|
|
|
/*
|
2000-03-03 19:48:14 +00:00
|
|
|
* Add TSIG record tailored to the current recipient.
|
1999-11-16 21:07:13 +00:00
|
|
|
*/
|
2000-08-17 00:18:12 +00:00
|
|
|
result = dns_view_getpeertsig(fctx->res->view, &ipaddr, &tsigkey);
|
|
|
|
if (result != ISC_R_SUCCESS && result != ISC_R_NOTFOUND)
|
|
|
|
goto cleanup_message;
|
|
|
|
|
|
|
|
if (tsigkey != NULL) {
|
|
|
|
dns_message_settsigkey(fctx->qmessage, tsigkey);
|
|
|
|
dns_tsigkey_detach(&tsigkey);
|
2000-03-03 19:48:14 +00:00
|
|
|
}
|
1999-11-16 21:07:13 +00:00
|
|
|
|
1999-07-03 20:54:56 +00:00
|
|
|
result = dns_message_rendersection(fctx->qmessage,
|
1999-12-22 03:22:59 +00:00
|
|
|
DNS_SECTION_ADDITIONAL, 0);
|
1999-10-07 19:41:16 +00:00
|
|
|
if (result != ISC_R_SUCCESS)
|
1999-07-24 01:26:18 +00:00
|
|
|
goto cleanup_message;
|
1999-11-16 21:07:13 +00:00
|
|
|
|
1999-07-03 20:54:56 +00:00
|
|
|
result = dns_message_renderend(fctx->qmessage);
|
1999-10-07 19:41:16 +00:00
|
|
|
if (result != ISC_R_SUCCESS)
|
1999-07-24 01:26:18 +00:00
|
|
|
goto cleanup_message;
|
|
|
|
|
2001-03-05 21:15:47 +00:00
|
|
|
dns_compress_invalidate(&cctx);
|
|
|
|
cleanup_cctx = ISC_FALSE;
|
|
|
|
|
2000-05-26 00:16:46 +00:00
|
|
|
if (dns_message_gettsigkey(fctx->qmessage) != NULL) {
|
|
|
|
dns_tsigkey_attach(dns_message_gettsigkey(fctx->qmessage),
|
|
|
|
&query->tsigkey);
|
2000-05-30 23:14:57 +00:00
|
|
|
result = dns_message_getquerytsig(fctx->qmessage,
|
|
|
|
fctx->res->mctx,
|
|
|
|
&query->tsig);
|
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
goto cleanup_message;
|
1999-08-20 18:56:24 +00:00
|
|
|
}
|
|
|
|
|
1999-11-16 21:07:13 +00:00
|
|
|
/*
|
|
|
|
* If using TCP, write the length of the message at the beginning
|
|
|
|
* of the buffer.
|
|
|
|
*/
|
|
|
|
if ((query->options & DNS_FETCHOPT_TCP) != 0) {
|
103. [func] libisc buffer API changes for <isc/buffer.h>:
Added:
isc_buffer_base(b) (pointer)
isc_buffer_current(b) (pointer)
isc_buffer_active(b) (pointer)
isc_buffer_used(b) (pointer)
isc_buffer_length(b) (int)
isc_buffer_usedlength(b) (int)
isc_buffer_consumedlength(b) (int)
isc_buffer_remaininglength(b) (int)
isc_buffer_activelength(b) (int)
isc_buffer_availablelength(b) (int)
Removed:
ISC_BUFFER_USEDCOUNT(b)
ISC_BUFFER_AVAILABLECOUNT(b)
isc_buffer_type(b)
Changed names:
isc_buffer_used(b, r) ->
isc_buffer_usedregion(b, r)
isc_buffer_available(b, r) ->
isc_buffer_available_region(b, r)
isc_buffer_consumed(b, r) ->
isc_buffer_consumedregion(b, r)
isc_buffer_active(b, r) ->
isc_buffer_activeregion(b, r)
isc_buffer_remaining(b, r) ->
isc_buffer_remainingregion(b, r)
Buffer types were removed, so the ISC_BUFFERTYPE_*
macros are no more, and the type argument to
isc_buffer_init and isc_buffer_allocate were removed.
isc_buffer_putstr is now void (instead of isc_result_t)
and requires that the caller ensure that there
is enough available buffer space for the string.
2000-04-27 00:03:12 +00:00
|
|
|
isc_buffer_usedregion(&query->buffer, &r);
|
1999-11-16 21:07:13 +00:00
|
|
|
isc_buffer_putuint16(&tcpbuffer, (isc_uint16_t)r.length);
|
|
|
|
isc_buffer_add(&tcpbuffer, r.length);
|
|
|
|
}
|
|
|
|
|
1999-07-24 01:26:18 +00:00
|
|
|
/*
|
|
|
|
* We're now done with the query message.
|
|
|
|
*/
|
|
|
|
dns_message_reset(fctx->qmessage, DNS_MESSAGE_INTENTRENDER);
|
1999-06-28 23:37:54 +00:00
|
|
|
|
1999-11-16 21:07:13 +00:00
|
|
|
socket = dns_dispatch_getsocket(query->dispatch);
|
1999-07-24 01:26:18 +00:00
|
|
|
/*
|
|
|
|
* Send the query!
|
|
|
|
*/
|
2000-11-04 02:20:58 +00:00
|
|
|
if ((query->options & DNS_FETCHOPT_TCP) == 0)
|
2000-06-01 00:30:58 +00:00
|
|
|
address = &query->addrinfo->sockaddr;
|
103. [func] libisc buffer API changes for <isc/buffer.h>:
Added:
isc_buffer_base(b) (pointer)
isc_buffer_current(b) (pointer)
isc_buffer_active(b) (pointer)
isc_buffer_used(b) (pointer)
isc_buffer_length(b) (int)
isc_buffer_usedlength(b) (int)
isc_buffer_consumedlength(b) (int)
isc_buffer_remaininglength(b) (int)
isc_buffer_activelength(b) (int)
isc_buffer_availablelength(b) (int)
Removed:
ISC_BUFFER_USEDCOUNT(b)
ISC_BUFFER_AVAILABLECOUNT(b)
isc_buffer_type(b)
Changed names:
isc_buffer_used(b, r) ->
isc_buffer_usedregion(b, r)
isc_buffer_available(b, r) ->
isc_buffer_available_region(b, r)
isc_buffer_consumed(b, r) ->
isc_buffer_consumedregion(b, r)
isc_buffer_active(b, r) ->
isc_buffer_activeregion(b, r)
isc_buffer_remaining(b, r) ->
isc_buffer_remainingregion(b, r)
Buffer types were removed, so the ISC_BUFFERTYPE_*
macros are no more, and the type argument to
isc_buffer_init and isc_buffer_allocate were removed.
isc_buffer_putstr is now void (instead of isc_result_t)
and requires that the caller ensure that there
is enough available buffer space for the string.
2000-04-27 00:03:12 +00:00
|
|
|
isc_buffer_usedregion(buffer, &r);
|
2000-11-03 02:45:55 +00:00
|
|
|
|
2000-04-26 19:25:01 +00:00
|
|
|
/*
|
|
|
|
* XXXRTH Make sure we don't send to ourselves! We should probably
|
|
|
|
* prune out these addresses when we get them from the ADB.
|
|
|
|
*/
|
1999-11-16 21:07:13 +00:00
|
|
|
result = isc_socket_sendto(socket, &r, task, resquery_senddone,
|
1999-12-04 01:27:44 +00:00
|
|
|
query, address, NULL);
|
1999-07-24 01:26:18 +00:00
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
goto cleanup_message;
|
2000-07-04 01:19:20 +00:00
|
|
|
query->sends++;
|
1999-11-16 21:07:13 +00:00
|
|
|
QTRACE("sent");
|
1999-06-28 23:37:54 +00:00
|
|
|
|
1999-10-07 19:41:16 +00:00
|
|
|
return (ISC_R_SUCCESS);
|
1999-07-24 01:26:18 +00:00
|
|
|
|
|
|
|
cleanup_message:
|
2001-03-05 21:15:47 +00:00
|
|
|
if (cleanup_cctx)
|
|
|
|
dns_compress_invalidate(&cctx);
|
|
|
|
|
1999-07-24 01:26:18 +00:00
|
|
|
dns_message_reset(fctx->qmessage, DNS_MESSAGE_INTENTRENDER);
|
1999-07-03 20:54:56 +00:00
|
|
|
|
1999-07-24 01:26:18 +00:00
|
|
|
/*
|
1999-10-07 19:41:16 +00:00
|
|
|
* Stop the dispatcher from listening.
|
1999-07-24 01:26:18 +00:00
|
|
|
*/
|
Merge the mlg-20000518 branch onto the mainline. Change summary:
dns_dispatch_create() no longer exists. dns_dispatch_createtcp()
and dns_dispatch_getudp() are the replacements. _createtcp() takes
a bound, connected TCP socket, while _getudp() will search for
a sharable UDP socket, and if found, attach to it and return a
pointer to it. If one is not found, it will create a udp socket,
bind it to a supplied local address, and create a new dispatcher
around it.
dns_dispatch_remove{request,response}() no longer take the dispatch
as an argument.
query-source can now be set per view.
The dispatch manager holds onto three memory pools, one for
allocating dispatchers from, one for events, and one for
requests/replies. The free list on these pools is hard-coded,
but set to 1024. This keeps us from having to dig into the
isc_mem_t the pools draw from as often.
dns_resolver_create() and dns_view_createresolver() require that
valid dispatchers be passed in; dispatchers are no longer created
for the caller.
2000-05-19 21:46:46 +00:00
|
|
|
dns_dispatch_removeresponse(&query->dispentry, NULL);
|
1999-07-24 01:26:18 +00:00
|
|
|
|
1999-10-07 19:41:16 +00:00
|
|
|
cleanup_temps:
|
|
|
|
if (qname != NULL)
|
|
|
|
dns_message_puttempname(fctx->qmessage, &qname);
|
|
|
|
if (qrdataset != NULL)
|
|
|
|
dns_message_puttemprdataset(fctx->qmessage, &qrdataset);
|
1999-06-28 23:37:54 +00:00
|
|
|
|
1999-10-07 19:41:16 +00:00
|
|
|
return (result);
|
1999-07-24 01:26:18 +00:00
|
|
|
}
|
|
|
|
|
1999-11-16 21:07:13 +00:00
|
|
|
static void
|
|
|
|
resquery_connected(isc_task_t *task, isc_event_t *event) {
|
|
|
|
isc_socketevent_t *sevent = (isc_socketevent_t *)event;
|
2000-04-17 19:21:30 +00:00
|
|
|
resquery_t *query = event->ev_arg;
|
1999-11-16 21:07:13 +00:00
|
|
|
isc_result_t result;
|
|
|
|
|
2000-04-17 19:21:30 +00:00
|
|
|
REQUIRE(event->ev_type == ISC_SOCKEVENT_CONNECT);
|
1999-11-30 20:57:05 +00:00
|
|
|
REQUIRE(VALID_QUERY(query));
|
1999-11-16 21:07:13 +00:00
|
|
|
|
|
|
|
QTRACE("connected");
|
|
|
|
|
2000-04-11 23:15:30 +00:00
|
|
|
UNUSED(task);
|
1999-11-16 21:07:13 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* XXXRTH
|
|
|
|
*
|
|
|
|
* Currently we don't wait for the connect event before retrying
|
|
|
|
* a query. This means that if we get really behind, we may end
|
|
|
|
* up doing extra work!
|
|
|
|
*/
|
|
|
|
|
2001-03-16 21:50:59 +00:00
|
|
|
query->connects--;
|
1999-11-30 20:57:05 +00:00
|
|
|
|
|
|
|
if (RESQUERY_CANCELED(query)) {
|
|
|
|
/*
|
|
|
|
* This query was canceled while the connect() was in
|
|
|
|
* progress.
|
|
|
|
*/
|
2000-05-17 20:33:29 +00:00
|
|
|
isc_socket_detach(&query->tcpsocket);
|
1999-11-30 20:57:05 +00:00
|
|
|
resquery_destroy(&query);
|
|
|
|
} else {
|
|
|
|
if (sevent->result == ISC_R_SUCCESS) {
|
2000-05-17 20:33:29 +00:00
|
|
|
unsigned int attrs;
|
2000-08-01 01:33:37 +00:00
|
|
|
|
2000-05-17 20:33:29 +00:00
|
|
|
/*
|
|
|
|
* We are connected. Create a dispatcher and
|
|
|
|
* send the query.
|
|
|
|
*/
|
|
|
|
attrs = 0;
|
|
|
|
attrs |= DNS_DISPATCHATTR_TCP;
|
|
|
|
attrs |= DNS_DISPATCHATTR_PRIVATE;
|
2000-06-20 23:52:54 +00:00
|
|
|
attrs |= DNS_DISPATCHATTR_CONNECTED;
|
2000-06-01 00:30:58 +00:00
|
|
|
if (isc_sockaddr_pf(&query->addrinfo->sockaddr) ==
|
2000-05-17 20:33:29 +00:00
|
|
|
AF_INET)
|
|
|
|
attrs |= DNS_DISPATCHATTR_IPV4;
|
|
|
|
else
|
|
|
|
attrs |= DNS_DISPATCHATTR_IPV6;
|
|
|
|
attrs |= DNS_DISPATCHATTR_MAKEQUERY;
|
|
|
|
|
Merge the mlg-20000518 branch onto the mainline. Change summary:
dns_dispatch_create() no longer exists. dns_dispatch_createtcp()
and dns_dispatch_getudp() are the replacements. _createtcp() takes
a bound, connected TCP socket, while _getudp() will search for
a sharable UDP socket, and if found, attach to it and return a
pointer to it. If one is not found, it will create a udp socket,
bind it to a supplied local address, and create a new dispatcher
around it.
dns_dispatch_remove{request,response}() no longer take the dispatch
as an argument.
query-source can now be set per view.
The dispatch manager holds onto three memory pools, one for
allocating dispatchers from, one for events, and one for
requests/replies. The free list on these pools is hard-coded,
but set to 1024. This keeps us from having to dig into the
isc_mem_t the pools draw from as often.
dns_resolver_create() and dns_view_createresolver() require that
valid dispatchers be passed in; dispatchers are no longer created
for the caller.
2000-05-19 21:46:46 +00:00
|
|
|
result = dns_dispatch_createtcp(query->dispatchmgr,
|
2000-05-24 05:10:00 +00:00
|
|
|
query->tcpsocket,
|
|
|
|
query->fctx->res->taskmgr,
|
|
|
|
4096, 2, 1, 1, 3, attrs,
|
|
|
|
&query->dispatch);
|
2000-08-01 01:33:37 +00:00
|
|
|
|
1999-11-30 20:57:05 +00:00
|
|
|
/*
|
Merge the mlg-20000518 branch onto the mainline. Change summary:
dns_dispatch_create() no longer exists. dns_dispatch_createtcp()
and dns_dispatch_getudp() are the replacements. _createtcp() takes
a bound, connected TCP socket, while _getudp() will search for
a sharable UDP socket, and if found, attach to it and return a
pointer to it. If one is not found, it will create a udp socket,
bind it to a supplied local address, and create a new dispatcher
around it.
dns_dispatch_remove{request,response}() no longer take the dispatch
as an argument.
query-source can now be set per view.
The dispatch manager holds onto three memory pools, one for
allocating dispatchers from, one for events, and one for
requests/replies. The free list on these pools is hard-coded,
but set to 1024. This keeps us from having to dig into the
isc_mem_t the pools draw from as often.
dns_resolver_create() and dns_view_createresolver() require that
valid dispatchers be passed in; dispatchers are no longer created
for the caller.
2000-05-19 21:46:46 +00:00
|
|
|
* Regardless of whether dns_dispatch_create()
|
|
|
|
* succeeded or not, we don't need our reference
|
|
|
|
* to the socket anymore.
|
1999-11-30 20:57:05 +00:00
|
|
|
*/
|
2000-05-17 20:33:29 +00:00
|
|
|
isc_socket_detach(&query->tcpsocket);
|
|
|
|
|
|
|
|
if (result == ISC_R_SUCCESS)
|
|
|
|
result = resquery_send(query);
|
2000-08-01 01:33:37 +00:00
|
|
|
|
2000-02-19 00:16:41 +00:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
2000-06-16 01:16:39 +00:00
|
|
|
fetchctx_t *fctx = query->fctx;
|
2000-07-04 01:19:20 +00:00
|
|
|
fctx_cancelquery(&query, NULL, NULL,
|
|
|
|
ISC_FALSE);
|
2000-06-16 01:16:39 +00:00
|
|
|
fctx_done(fctx, result);
|
2000-02-19 00:16:41 +00:00
|
|
|
}
|
2000-05-17 20:33:29 +00:00
|
|
|
} else {
|
|
|
|
isc_socket_detach(&query->tcpsocket);
|
1999-11-30 20:57:05 +00:00
|
|
|
fctx_cancelquery(&query, NULL, NULL, ISC_FALSE);
|
2000-05-17 20:33:29 +00:00
|
|
|
}
|
1999-11-30 20:57:05 +00:00
|
|
|
}
|
2000-08-01 01:33:37 +00:00
|
|
|
|
1999-11-16 21:07:13 +00:00
|
|
|
isc_event_free(&event);
|
|
|
|
}
|
|
|
|
|
2000-04-20 17:05:37 +00:00
|
|
|
|
|
|
|
|
1999-10-29 03:30:49 +00:00
|
|
|
static void
|
1999-10-29 21:48:10 +00:00
|
|
|
fctx_finddone(isc_task_t *task, isc_event_t *event) {
|
1999-10-29 03:30:49 +00:00
|
|
|
fetchctx_t *fctx;
|
1999-10-29 21:48:10 +00:00
|
|
|
dns_adbfind_t *find;
|
|
|
|
dns_resolver_t *res;
|
1999-10-29 03:30:49 +00:00
|
|
|
isc_boolean_t want_try = ISC_FALSE;
|
|
|
|
isc_boolean_t want_done = ISC_FALSE;
|
1999-10-29 21:48:10 +00:00
|
|
|
isc_boolean_t bucket_empty = ISC_FALSE;
|
|
|
|
unsigned int bucketnum;
|
1999-10-29 03:30:49 +00:00
|
|
|
|
2000-04-17 19:21:30 +00:00
|
|
|
find = event->ev_sender;
|
|
|
|
fctx = event->ev_arg;
|
1999-10-29 03:30:49 +00:00
|
|
|
REQUIRE(VALID_FCTX(fctx));
|
1999-10-29 21:48:10 +00:00
|
|
|
res = fctx->res;
|
1999-10-29 03:30:49 +00:00
|
|
|
|
2000-04-11 23:15:30 +00:00
|
|
|
UNUSED(task);
|
1999-10-29 03:30:49 +00:00
|
|
|
|
1999-10-29 21:48:10 +00:00
|
|
|
FCTXTRACE("finddone");
|
|
|
|
|
|
|
|
INSIST(fctx->pending > 0);
|
|
|
|
fctx->pending--;
|
1999-10-29 03:30:49 +00:00
|
|
|
|
|
|
|
if (ADDRWAIT(fctx)) {
|
1999-10-29 21:48:10 +00:00
|
|
|
/*
|
|
|
|
* The fetch is waiting for a name to be found.
|
|
|
|
*/
|
2000-02-03 22:24:18 +00:00
|
|
|
INSIST(!SHUTTINGDOWN(fctx));
|
1999-10-29 03:30:49 +00:00
|
|
|
fctx->attributes &= ~FCTX_ATTR_ADDRWAIT;
|
2000-04-17 19:21:30 +00:00
|
|
|
if (event->ev_type == DNS_EVENT_ADBMOREADDRESSES)
|
1999-10-29 03:30:49 +00:00
|
|
|
want_try = ISC_TRUE;
|
1999-10-29 21:48:10 +00:00
|
|
|
else if (fctx->pending == 0) {
|
|
|
|
/*
|
|
|
|
* We've got nothing else to wait for and don't
|
|
|
|
* know the answer. There's nothing to do but
|
|
|
|
* fail the fctx.
|
|
|
|
*/
|
1999-10-29 03:30:49 +00:00
|
|
|
want_done = ISC_TRUE;
|
1999-10-29 21:48:10 +00:00
|
|
|
}
|
2000-01-14 02:38:02 +00:00
|
|
|
} else if (SHUTTINGDOWN(fctx) && fctx->pending == 0 &&
|
2000-08-15 00:21:05 +00:00
|
|
|
ISC_LIST_EMPTY(fctx->validators)) {
|
1999-10-29 21:48:10 +00:00
|
|
|
bucketnum = fctx->bucketnum;
|
|
|
|
LOCK(&res->buckets[bucketnum].lock);
|
2000-01-14 02:38:02 +00:00
|
|
|
/*
|
|
|
|
* Note that we had to wait until we had the lock before
|
|
|
|
* looking at fctx->references.
|
|
|
|
*/
|
|
|
|
if (fctx->references == 0)
|
|
|
|
bucket_empty = fctx_destroy(fctx);
|
1999-10-29 21:48:10 +00:00
|
|
|
UNLOCK(&res->buckets[bucketnum].lock);
|
1999-10-29 03:30:49 +00:00
|
|
|
}
|
1999-10-29 21:48:10 +00:00
|
|
|
|
1999-10-29 03:30:49 +00:00
|
|
|
isc_event_free(&event);
|
1999-10-29 21:48:10 +00:00
|
|
|
dns_adb_destroyfind(&find);
|
1999-10-29 03:30:49 +00:00
|
|
|
|
|
|
|
if (want_try)
|
|
|
|
fctx_try(fctx);
|
|
|
|
else if (want_done)
|
1999-10-29 21:48:10 +00:00
|
|
|
fctx_done(fctx, ISC_R_FAILURE);
|
|
|
|
else if (bucket_empty)
|
|
|
|
empty_bucket(res);
|
1999-10-29 03:30:49 +00:00
|
|
|
}
|
|
|
|
|
2000-02-11 03:06:56 +00:00
|
|
|
|
|
|
|
static inline isc_boolean_t
|
|
|
|
bad_server(fetchctx_t *fctx, isc_sockaddr_t *address) {
|
|
|
|
isc_sockaddr_t *sa;
|
|
|
|
|
|
|
|
for (sa = ISC_LIST_HEAD(fctx->bad);
|
|
|
|
sa != NULL;
|
|
|
|
sa = ISC_LIST_NEXT(sa, link)) {
|
|
|
|
if (isc_sockaddr_equal(sa, address))
|
|
|
|
return (ISC_TRUE);
|
|
|
|
}
|
2000-08-01 01:33:37 +00:00
|
|
|
|
2000-02-11 03:06:56 +00:00
|
|
|
return (ISC_FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline isc_boolean_t
|
|
|
|
mark_bad(fetchctx_t *fctx) {
|
|
|
|
dns_adbfind_t *curr;
|
|
|
|
dns_adbaddrinfo_t *addrinfo;
|
|
|
|
isc_boolean_t all_bad = ISC_TRUE;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Mark all known bad servers, so we don't try to talk to them
|
|
|
|
* again.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Mark any bad nameservers.
|
|
|
|
*/
|
|
|
|
for (curr = ISC_LIST_HEAD(fctx->finds);
|
|
|
|
curr != NULL;
|
|
|
|
curr = ISC_LIST_NEXT(curr, publink)) {
|
|
|
|
for (addrinfo = ISC_LIST_HEAD(curr->list);
|
|
|
|
addrinfo != NULL;
|
|
|
|
addrinfo = ISC_LIST_NEXT(addrinfo, publink)) {
|
2000-06-01 00:30:58 +00:00
|
|
|
if (bad_server(fctx, &addrinfo->sockaddr))
|
2000-02-11 03:06:56 +00:00
|
|
|
addrinfo->flags |= FCTX_ADDRINFO_MARK;
|
|
|
|
else
|
|
|
|
all_bad = ISC_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Mark any bad forwarders.
|
|
|
|
*/
|
|
|
|
for (addrinfo = ISC_LIST_HEAD(fctx->forwaddrs);
|
|
|
|
addrinfo != NULL;
|
|
|
|
addrinfo = ISC_LIST_NEXT(addrinfo, publink)) {
|
2000-06-01 00:30:58 +00:00
|
|
|
if (bad_server(fctx, &addrinfo->sockaddr))
|
2000-02-11 03:06:56 +00:00
|
|
|
addrinfo->flags |= FCTX_ADDRINFO_MARK;
|
|
|
|
else
|
|
|
|
all_bad = ISC_FALSE;
|
|
|
|
}
|
2000-08-01 01:33:37 +00:00
|
|
|
|
2000-02-11 03:06:56 +00:00
|
|
|
return (all_bad);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
add_bad(fetchctx_t *fctx, isc_sockaddr_t *address) {
|
|
|
|
isc_sockaddr_t *sa;
|
|
|
|
|
|
|
|
if (bad_server(fctx, address)) {
|
|
|
|
/*
|
|
|
|
* We already know this server is bad.
|
|
|
|
*/
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
FCTXTRACE("add_bad");
|
|
|
|
|
2001-11-12 19:05:39 +00:00
|
|
|
sa = isc_mem_get(fctx->res->mctx, sizeof(*sa));
|
2000-02-11 03:06:56 +00:00
|
|
|
if (sa == NULL)
|
|
|
|
return;
|
|
|
|
*sa = *address;
|
2000-12-07 20:15:58 +00:00
|
|
|
ISC_LIST_INITANDAPPEND(fctx->bad, sa, link);
|
2000-02-11 03:06:56 +00:00
|
|
|
}
|
|
|
|
|
1999-11-05 09:50:52 +00:00
|
|
|
static void
|
|
|
|
sort_adbfind(dns_adbfind_t *find) {
|
|
|
|
dns_adbaddrinfo_t *best, *curr;
|
|
|
|
dns_adbaddrinfolist_t sorted;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Lame N^2 bubble sort.
|
|
|
|
*/
|
|
|
|
|
|
|
|
ISC_LIST_INIT(sorted);
|
|
|
|
while (!ISC_LIST_EMPTY(find->list)) {
|
|
|
|
best = ISC_LIST_HEAD(find->list);
|
|
|
|
curr = ISC_LIST_NEXT(best, publink);
|
|
|
|
while (curr != NULL) {
|
|
|
|
if (curr->srtt < best->srtt)
|
|
|
|
best = curr;
|
|
|
|
curr = ISC_LIST_NEXT(curr, publink);
|
|
|
|
}
|
|
|
|
ISC_LIST_UNLINK(find->list, best, publink);
|
|
|
|
ISC_LIST_APPEND(sorted, best, publink);
|
2000-08-01 01:33:37 +00:00
|
|
|
}
|
1999-11-05 09:50:52 +00:00
|
|
|
find->list = sorted;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
sort_finds(fetchctx_t *fctx) {
|
|
|
|
dns_adbfind_t *best, *curr;
|
|
|
|
dns_adbfindlist_t sorted;
|
|
|
|
dns_adbaddrinfo_t *addrinfo, *bestaddrinfo;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Lame N^2 bubble sort.
|
|
|
|
*/
|
|
|
|
|
|
|
|
ISC_LIST_INIT(sorted);
|
|
|
|
while (!ISC_LIST_EMPTY(fctx->finds)) {
|
|
|
|
best = ISC_LIST_HEAD(fctx->finds);
|
|
|
|
bestaddrinfo = ISC_LIST_HEAD(best->list);
|
|
|
|
INSIST(bestaddrinfo != NULL);
|
|
|
|
curr = ISC_LIST_NEXT(best, publink);
|
|
|
|
while (curr != NULL) {
|
|
|
|
addrinfo = ISC_LIST_HEAD(curr->list);
|
|
|
|
INSIST(addrinfo != NULL);
|
|
|
|
if (addrinfo->srtt < bestaddrinfo->srtt) {
|
|
|
|
best = curr;
|
|
|
|
bestaddrinfo = addrinfo;
|
|
|
|
}
|
|
|
|
curr = ISC_LIST_NEXT(curr, publink);
|
|
|
|
}
|
|
|
|
ISC_LIST_UNLINK(fctx->finds, best, publink);
|
|
|
|
ISC_LIST_APPEND(sorted, best, publink);
|
|
|
|
}
|
|
|
|
fctx->finds = sorted;
|
|
|
|
}
|
|
|
|
|
1999-10-07 19:41:16 +00:00
|
|
|
static isc_result_t
|
1999-07-24 01:26:18 +00:00
|
|
|
fctx_getaddresses(fetchctx_t *fctx) {
|
2000-10-25 04:26:57 +00:00
|
|
|
dns_rdata_t rdata = DNS_RDATA_INIT;
|
1999-10-07 19:41:16 +00:00
|
|
|
isc_result_t result;
|
1999-10-29 03:30:49 +00:00
|
|
|
dns_resolver_t *res;
|
|
|
|
isc_stdtime_t now;
|
1999-10-29 21:48:10 +00:00
|
|
|
dns_adbfind_t *find;
|
2000-01-06 00:56:18 +00:00
|
|
|
unsigned int stdoptions, options;
|
2000-01-12 02:59:48 +00:00
|
|
|
isc_sockaddr_t *sa;
|
|
|
|
dns_adbaddrinfo_t *ai;
|
2000-02-11 03:06:56 +00:00
|
|
|
isc_boolean_t pruned, all_bad;
|
2000-10-07 00:09:28 +00:00
|
|
|
dns_rdata_ns_t ns;
|
1999-07-24 01:26:18 +00:00
|
|
|
|
|
|
|
FCTXTRACE("getaddresses");
|
|
|
|
|
1999-11-05 09:50:52 +00:00
|
|
|
/*
|
1999-11-23 20:54:20 +00:00
|
|
|
* Don't pound on remote servers. (Failsafe!)
|
1999-11-05 09:50:52 +00:00
|
|
|
*/
|
|
|
|
fctx->restarts++;
|
2000-01-14 02:38:02 +00:00
|
|
|
if (fctx->restarts > 10) {
|
|
|
|
FCTXTRACE("too many restarts");
|
1999-11-05 09:50:52 +00:00
|
|
|
return (DNS_R_SERVFAIL);
|
2000-01-14 02:38:02 +00:00
|
|
|
}
|
1999-11-05 09:50:52 +00:00
|
|
|
|
1999-10-29 03:30:49 +00:00
|
|
|
res = fctx->res;
|
2000-02-03 00:01:08 +00:00
|
|
|
pruned = ISC_FALSE;
|
|
|
|
stdoptions = 0; /* Keep compiler happy. */
|
2000-01-12 02:59:48 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Forwarders.
|
|
|
|
*/
|
|
|
|
|
|
|
|
INSIST(ISC_LIST_EMPTY(fctx->forwaddrs));
|
|
|
|
|
|
|
|
/*
|
2000-08-24 22:15:40 +00:00
|
|
|
* If this fctx has forwarders, use them; otherwise use any
|
|
|
|
* selective forwarders specified in the view; otherwise use the
|
2000-01-12 02:59:48 +00:00
|
|
|
* resolver's forwarders (if any).
|
|
|
|
*/
|
|
|
|
sa = ISC_LIST_HEAD(fctx->forwarders);
|
2000-08-24 22:15:40 +00:00
|
|
|
if (sa == NULL) {
|
|
|
|
dns_forwarders_t *forwarders = NULL;
|
|
|
|
result = dns_fwdtable_find(fctx->res->view->fwdtable,
|
|
|
|
&fctx->name, &forwarders);
|
|
|
|
if (result == ISC_R_SUCCESS) {
|
|
|
|
sa = ISC_LIST_HEAD(forwarders->addrs);
|
|
|
|
fctx->fwdpolicy = forwarders->fwdpolicy;
|
|
|
|
}
|
|
|
|
}
|
2000-01-12 02:59:48 +00:00
|
|
|
|
|
|
|
while (sa != NULL) {
|
|
|
|
ai = NULL;
|
2001-04-11 20:37:50 +00:00
|
|
|
result = dns_adb_findaddrinfo(fctx->adb,
|
2000-02-16 00:16:36 +00:00
|
|
|
sa, &ai, 0); /* XXXMLG */
|
2000-01-12 02:59:48 +00:00
|
|
|
if (result == ISC_R_SUCCESS) {
|
|
|
|
ai->flags |= FCTX_ADDRINFO_FORWARDER;
|
|
|
|
ISC_LIST_APPEND(fctx->forwaddrs, ai, publink);
|
|
|
|
}
|
|
|
|
sa = ISC_LIST_NEXT(sa, link);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If the forwarding policy is "only", we don't need the addresses
|
|
|
|
* of the nameservers.
|
|
|
|
*/
|
2000-08-24 22:15:40 +00:00
|
|
|
if (fctx->fwdpolicy == dns_fwdpolicy_only)
|
2000-01-12 02:59:48 +00:00
|
|
|
goto out;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Normal nameservers.
|
|
|
|
*/
|
|
|
|
|
2001-02-28 20:51:22 +00:00
|
|
|
stdoptions = DNS_ADBFIND_WANTEVENT | DNS_ADBFIND_EMPTYEVENT;
|
|
|
|
if (fctx->restarts == 1) {
|
|
|
|
/*
|
|
|
|
* To avoid sending out a flood of queries likely to
|
|
|
|
* result in NXRRSET, we suppress fetches for address
|
|
|
|
* families we don't have the first time through,
|
|
|
|
* provided that we have addresses in some family we
|
|
|
|
* can use.
|
|
|
|
*
|
|
|
|
* We don't want to set this option all the time, since
|
|
|
|
* if fctx->restarts > 1, we've clearly been having trouble
|
2001-02-28 21:19:53 +00:00
|
|
|
* with the addresses we had, so getting more could help.
|
|
|
|
*/
|
2001-02-28 20:51:22 +00:00
|
|
|
stdoptions |= DNS_ADBFIND_AVOIDFETCHES;
|
|
|
|
}
|
2000-01-26 16:57:48 +00:00
|
|
|
if (res->dispatchv4 != NULL)
|
2000-01-06 00:56:18 +00:00
|
|
|
stdoptions |= DNS_ADBFIND_INET;
|
2000-01-26 16:57:48 +00:00
|
|
|
if (res->dispatchv6 != NULL)
|
2000-01-06 00:56:18 +00:00
|
|
|
stdoptions |= DNS_ADBFIND_INET6;
|
1999-12-16 23:29:07 +00:00
|
|
|
isc_stdtime_get(&now);
|
1999-10-07 19:41:16 +00:00
|
|
|
|
2000-02-03 00:01:08 +00:00
|
|
|
restart:
|
1999-11-05 09:50:52 +00:00
|
|
|
INSIST(ISC_LIST_EMPTY(fctx->finds));
|
1999-10-07 19:41:16 +00:00
|
|
|
|
|
|
|
result = dns_rdataset_first(&fctx->nameservers);
|
|
|
|
while (result == ISC_R_SUCCESS) {
|
|
|
|
dns_rdataset_current(&fctx->nameservers, &rdata);
|
1999-10-29 03:30:49 +00:00
|
|
|
/*
|
|
|
|
* Extract the name from the NS record.
|
|
|
|
*/
|
2000-10-07 00:09:28 +00:00
|
|
|
result = dns_rdata_tostruct(&rdata, &ns, NULL);
|
|
|
|
if (result != ISC_R_SUCCESS) {
|
|
|
|
dns_rdataset_next(&fctx->nameservers);
|
|
|
|
continue;
|
|
|
|
}
|
2000-01-06 00:56:18 +00:00
|
|
|
options = stdoptions;
|
1999-10-29 03:30:49 +00:00
|
|
|
/*
|
2000-01-06 00:56:18 +00:00
|
|
|
* If this name is a subdomain of the query domain, tell
|
|
|
|
* the ADB to start looking at "." if it doesn't know the
|
|
|
|
* address. This keeps us from getting stuck if the
|
|
|
|
* nameserver is beneath the zone cut and we don't know its
|
|
|
|
* address (e.g. because the A record has expired).
|
|
|
|
* By restarting from ".", we ensure that any missing glue
|
|
|
|
* will be reestablished.
|
|
|
|
*
|
|
|
|
* A further optimization would be to get the ADB to start
|
|
|
|
* looking at the most enclosing zone cut above fctx->domain.
|
|
|
|
* We don't expect this situation to happen very frequently,
|
|
|
|
* so we've chosen the simple solution.
|
1999-10-29 03:30:49 +00:00
|
|
|
*/
|
2000-10-07 00:09:28 +00:00
|
|
|
if (dns_name_issubdomain(&ns.name, &fctx->domain))
|
2000-01-06 00:56:18 +00:00
|
|
|
options |= DNS_ADBFIND_STARTATROOT;
|
2000-02-02 23:24:04 +00:00
|
|
|
options |= DNS_ADBFIND_GLUEOK;
|
|
|
|
options |= DNS_ADBFIND_HINTOK;
|
|
|
|
|
1999-10-29 03:30:49 +00:00
|
|
|
/*
|
|
|
|
* See what we know about this address.
|
|
|
|
*/
|
1999-10-29 21:48:10 +00:00
|
|
|
find = NULL;
|
2001-04-11 20:37:50 +00:00
|
|
|
result = dns_adb_createfind(fctx->adb,
|
1999-10-29 18:00:31 +00:00
|
|
|
res->buckets[fctx->bucketnum].task,
|
2000-10-07 00:09:28 +00:00
|
|
|
fctx_finddone, fctx, &ns.name,
|
2000-01-21 02:47:30 +00:00
|
|
|
&fctx->domain, options, now, NULL,
|
2000-06-01 00:30:58 +00:00
|
|
|
res->view->dstport, &find);
|
2000-01-28 20:17:32 +00:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
|
|
|
if (result == DNS_R_ALIAS) {
|
|
|
|
/*
|
|
|
|
* XXXRTH Follow the CNAME/DNAME chain?
|
|
|
|
*/
|
|
|
|
dns_adb_destroyfind(&find);
|
|
|
|
}
|
|
|
|
} else if (!ISC_LIST_EMPTY(find->list)) {
|
1999-10-29 03:30:49 +00:00
|
|
|
/*
|
|
|
|
* We have at least some of the addresses for the
|
|
|
|
* name.
|
|
|
|
*/
|
1999-10-29 21:48:10 +00:00
|
|
|
INSIST((find->options & DNS_ADBFIND_WANTEVENT) == 0);
|
1999-11-05 09:50:52 +00:00
|
|
|
sort_adbfind(find);
|
1999-10-29 21:48:10 +00:00
|
|
|
ISC_LIST_APPEND(fctx->finds, find, publink);
|
1999-10-29 03:30:49 +00:00
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* We don't know any of the addresses for this
|
|
|
|
* name.
|
|
|
|
*/
|
1999-10-29 21:48:10 +00:00
|
|
|
if ((find->options & DNS_ADBFIND_WANTEVENT) != 0) {
|
1999-10-29 03:30:49 +00:00
|
|
|
/*
|
1999-10-29 21:48:10 +00:00
|
|
|
* We're looking for them and will get an
|
|
|
|
* event about it later.
|
1999-10-29 03:30:49 +00:00
|
|
|
*/
|
1999-10-29 21:48:10 +00:00
|
|
|
fctx->pending++;
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* And ADB isn't going to send us any events
|
2000-02-03 00:01:08 +00:00
|
|
|
* either. This find loses.
|
1999-10-29 21:48:10 +00:00
|
|
|
*/
|
2000-02-03 00:01:08 +00:00
|
|
|
if ((find->options & DNS_ADBFIND_LAMEPRUNED)
|
|
|
|
!= 0) {
|
|
|
|
/*
|
|
|
|
* The ADB pruned lame servers for
|
|
|
|
* this name. Remember that in case
|
|
|
|
* we get desperate later on.
|
|
|
|
*/
|
|
|
|
pruned = ISC_TRUE;
|
|
|
|
}
|
1999-10-29 21:48:10 +00:00
|
|
|
dns_adb_destroyfind(&find);
|
1999-10-07 19:41:16 +00:00
|
|
|
}
|
|
|
|
}
|
2000-10-31 03:22:05 +00:00
|
|
|
dns_rdata_reset(&rdata);
|
2000-10-07 00:09:28 +00:00
|
|
|
dns_rdata_freestruct(&ns);
|
1999-10-07 19:41:16 +00:00
|
|
|
result = dns_rdataset_next(&fctx->nameservers);
|
|
|
|
}
|
2000-04-06 22:03:35 +00:00
|
|
|
if (result != ISC_R_NOMORE)
|
1999-10-29 03:30:49 +00:00
|
|
|
return (result);
|
|
|
|
|
2000-01-12 02:59:48 +00:00
|
|
|
out:
|
2000-02-11 03:06:56 +00:00
|
|
|
/*
|
|
|
|
* Mark all known bad servers.
|
|
|
|
*/
|
|
|
|
all_bad = mark_bad(fctx);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* How are we doing?
|
|
|
|
*/
|
|
|
|
if (all_bad) {
|
1999-10-29 03:30:49 +00:00
|
|
|
/*
|
2000-01-12 02:59:48 +00:00
|
|
|
* We've got no addresses.
|
1999-10-29 03:30:49 +00:00
|
|
|
*/
|
2000-01-12 02:59:48 +00:00
|
|
|
if (fctx->pending > 0) {
|
|
|
|
/*
|
|
|
|
* We're fetching the addresses, but don't have any
|
|
|
|
* yet. Tell the caller to wait for an answer.
|
|
|
|
*/
|
|
|
|
result = DNS_R_WAIT;
|
2000-02-03 00:01:08 +00:00
|
|
|
} else if (pruned) {
|
|
|
|
/*
|
|
|
|
* Some addresses were removed by lame pruning.
|
|
|
|
* Turn pruning off and try again.
|
|
|
|
*/
|
|
|
|
FCTXTRACE("restarting with returnlame");
|
|
|
|
INSIST((stdoptions & DNS_ADBFIND_RETURNLAME) == 0);
|
|
|
|
stdoptions |= DNS_ADBFIND_RETURNLAME;
|
|
|
|
pruned = ISC_FALSE;
|
2000-11-27 19:56:16 +00:00
|
|
|
fctx_cleanupfinds(fctx);
|
2000-02-03 00:01:08 +00:00
|
|
|
goto restart;
|
2000-01-12 02:59:48 +00:00
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* We've lost completely. We don't know any
|
|
|
|
* addresses, and the ADB has told us it can't get
|
|
|
|
* them.
|
|
|
|
*/
|
2000-02-01 02:16:17 +00:00
|
|
|
FCTXTRACE("no addresses");
|
2000-01-12 02:59:48 +00:00
|
|
|
result = ISC_R_FAILURE;
|
|
|
|
}
|
1999-10-29 03:30:49 +00:00
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* We've found some addresses. We might still be looking
|
|
|
|
* for more addresses.
|
|
|
|
*/
|
2000-01-12 02:59:48 +00:00
|
|
|
/*
|
|
|
|
* XXXRTH We could sort the forwaddrs here if the caller
|
|
|
|
* wants to use the forwaddrs in "best order" as
|
|
|
|
* opposed to "fixed order".
|
|
|
|
*/
|
1999-11-05 09:50:52 +00:00
|
|
|
sort_finds(fctx);
|
1999-10-07 19:41:16 +00:00
|
|
|
result = ISC_R_SUCCESS;
|
1999-10-29 03:30:49 +00:00
|
|
|
}
|
1999-10-07 19:41:16 +00:00
|
|
|
|
|
|
|
return (result);
|
1999-06-28 23:37:54 +00:00
|
|
|
}
|
|
|
|
|
2000-05-26 02:16:10 +00:00
|
|
|
static inline void
|
|
|
|
possibly_mark(fetchctx_t *fctx, dns_adbaddrinfo_t *addr)
|
|
|
|
{
|
|
|
|
isc_netaddr_t na;
|
2000-05-26 23:17:56 +00:00
|
|
|
char buf[ISC_NETADDR_FORMATSIZE];
|
2000-05-26 02:16:10 +00:00
|
|
|
isc_sockaddr_t *sa;
|
2001-09-21 13:31:55 +00:00
|
|
|
isc_boolean_t aborted = ISC_FALSE;
|
|
|
|
isc_boolean_t bogus;
|
|
|
|
dns_acl_t *blackhole;
|
|
|
|
isc_netaddr_t ipaddr;
|
|
|
|
dns_peer_t *peer = NULL;
|
|
|
|
dns_resolver_t *res;
|
|
|
|
const char *msg = NULL;
|
2000-05-26 02:16:10 +00:00
|
|
|
|
2000-06-01 00:30:58 +00:00
|
|
|
sa = &addr->sockaddr;
|
2000-05-26 02:16:10 +00:00
|
|
|
|
2001-09-21 13:31:55 +00:00
|
|
|
res = fctx->res;
|
|
|
|
isc_netaddr_fromsockaddr(&ipaddr, sa);
|
|
|
|
blackhole = dns_dispatchmgr_getblackhole(res->dispatchmgr);
|
|
|
|
(void) dns_peerlist_peerbyaddr(res->view->peers, &ipaddr, &peer);
|
|
|
|
|
|
|
|
if (blackhole != NULL) {
|
|
|
|
int match;
|
|
|
|
|
|
|
|
if (dns_acl_match(&ipaddr, NULL, blackhole,
|
|
|
|
&res->view->aclenv,
|
|
|
|
&match, NULL) == ISC_R_SUCCESS &&
|
|
|
|
match > 0)
|
|
|
|
aborted = ISC_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (peer != NULL &&
|
|
|
|
dns_peer_getbogus(peer, &bogus) == ISC_R_SUCCESS &&
|
|
|
|
bogus)
|
|
|
|
aborted = ISC_TRUE;
|
2000-05-26 02:16:10 +00:00
|
|
|
|
2001-09-21 13:31:55 +00:00
|
|
|
if (aborted) {
|
|
|
|
addr->flags |= FCTX_ADDRINFO_MARK;
|
2001-11-04 19:20:39 +00:00
|
|
|
msg = "ignoring blackholed / bogus server: ";
|
2001-10-03 07:43:03 +00:00
|
|
|
} else if (isc_sockaddr_ismulticast(sa)) {
|
|
|
|
addr->flags |= FCTX_ADDRINFO_MARK;
|
|
|
|
msg = "ignoring multicast address: ";
|
2001-09-21 13:31:55 +00:00
|
|
|
} else if (sa->type.sa.sa_family != AF_INET6) {
|
|
|
|
return;
|
|
|
|
} else if (IN6_IS_ADDR_V4MAPPED(&sa->type.sin6.sin6_addr)) {
|
2000-05-26 02:16:10 +00:00
|
|
|
addr->flags |= FCTX_ADDRINFO_MARK;
|
2001-09-21 13:31:55 +00:00
|
|
|
msg = "ignoring IPv6 mapped IPV4 address: ";
|
2000-05-26 02:16:10 +00:00
|
|
|
} else if (IN6_IS_ADDR_V4COMPAT(&sa->type.sin6.sin6_addr)) {
|
|
|
|
addr->flags |= FCTX_ADDRINFO_MARK;
|
2001-09-21 13:31:55 +00:00
|
|
|
msg = "ignoring IPv6 compatibility IPV4 address: ";
|
|
|
|
} else
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!isc_log_wouldlog(dns_lctx, ISC_LOG_DEBUG(3)))
|
|
|
|
return;
|
|
|
|
|
|
|
|
isc_netaddr_fromsockaddr(&na, sa);
|
2001-11-12 19:05:39 +00:00
|
|
|
isc_netaddr_format(&na, buf, sizeof(buf));
|
2001-09-21 13:31:55 +00:00
|
|
|
FCTXTRACE2(msg, buf);
|
2000-05-26 02:16:10 +00:00
|
|
|
}
|
|
|
|
|
1999-10-29 03:30:49 +00:00
|
|
|
static inline dns_adbaddrinfo_t *
|
|
|
|
fctx_nextaddress(fetchctx_t *fctx) {
|
1999-10-29 21:48:10 +00:00
|
|
|
dns_adbfind_t *find;
|
1999-10-29 03:30:49 +00:00
|
|
|
dns_adbaddrinfo_t *addrinfo;
|
1999-06-28 23:37:54 +00:00
|
|
|
|
|
|
|
/*
|
1999-10-29 03:30:49 +00:00
|
|
|
* Return the next untried address, if any.
|
1999-06-28 23:37:54 +00:00
|
|
|
*/
|
|
|
|
|
1999-10-29 03:30:49 +00:00
|
|
|
/*
|
2000-01-12 02:59:48 +00:00
|
|
|
* Find the first unmarked forwarder (if any).
|
|
|
|
*/
|
|
|
|
for (addrinfo = ISC_LIST_HEAD(fctx->forwaddrs);
|
|
|
|
addrinfo != NULL;
|
|
|
|
addrinfo = ISC_LIST_NEXT(addrinfo, publink)) {
|
2000-05-26 02:16:10 +00:00
|
|
|
possibly_mark(fctx, addrinfo);
|
2000-01-12 02:59:48 +00:00
|
|
|
if (UNMARKED(addrinfo)) {
|
|
|
|
addrinfo->flags |= FCTX_ADDRINFO_MARK;
|
|
|
|
fctx->find = NULL;
|
|
|
|
return (addrinfo);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* No forwarders. Move to the next find.
|
1999-10-29 03:30:49 +00:00
|
|
|
*/
|
1999-10-29 21:48:10 +00:00
|
|
|
find = fctx->find;
|
|
|
|
if (find == NULL)
|
|
|
|
find = ISC_LIST_HEAD(fctx->finds);
|
1999-10-29 03:30:49 +00:00
|
|
|
else {
|
1999-10-29 21:48:10 +00:00
|
|
|
find = ISC_LIST_NEXT(find, publink);
|
|
|
|
if (find == NULL)
|
|
|
|
find = ISC_LIST_HEAD(fctx->finds);
|
1999-10-29 03:30:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Find the first unmarked addrinfo.
|
|
|
|
*/
|
|
|
|
addrinfo = NULL;
|
1999-10-29 21:48:10 +00:00
|
|
|
while (find != fctx->find) {
|
|
|
|
for (addrinfo = ISC_LIST_HEAD(find->list);
|
1999-10-29 03:30:49 +00:00
|
|
|
addrinfo != NULL;
|
|
|
|
addrinfo = ISC_LIST_NEXT(addrinfo, publink)) {
|
2000-05-26 02:16:10 +00:00
|
|
|
possibly_mark(fctx, addrinfo);
|
1999-10-29 03:30:49 +00:00
|
|
|
if (UNMARKED(addrinfo)) {
|
|
|
|
addrinfo->flags |= FCTX_ADDRINFO_MARK;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (addrinfo != NULL)
|
|
|
|
break;
|
1999-10-29 21:48:10 +00:00
|
|
|
find = ISC_LIST_NEXT(find, publink);
|
|
|
|
if (find != fctx->find && find == NULL)
|
|
|
|
find = ISC_LIST_HEAD(fctx->finds);
|
1999-10-29 03:30:49 +00:00
|
|
|
}
|
|
|
|
|
1999-10-29 21:48:10 +00:00
|
|
|
fctx->find = find;
|
1999-10-29 03:30:49 +00:00
|
|
|
|
|
|
|
return (addrinfo);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
fctx_try(fetchctx_t *fctx) {
|
|
|
|
isc_result_t result;
|
|
|
|
dns_adbaddrinfo_t *addrinfo;
|
|
|
|
|
1999-07-03 20:54:56 +00:00
|
|
|
FCTXTRACE("try");
|
1999-06-28 23:37:54 +00:00
|
|
|
|
1999-10-29 03:30:49 +00:00
|
|
|
REQUIRE(!ADDRWAIT(fctx));
|
|
|
|
|
|
|
|
addrinfo = fctx_nextaddress(fctx);
|
|
|
|
if (addrinfo == NULL) {
|
|
|
|
/*
|
|
|
|
* We have no more addresses. Start over.
|
|
|
|
*/
|
1999-11-30 20:57:05 +00:00
|
|
|
fctx_cancelqueries(fctx, ISC_TRUE);
|
1999-11-05 09:50:52 +00:00
|
|
|
fctx_cleanupfinds(fctx);
|
2000-01-12 02:59:48 +00:00
|
|
|
fctx_cleanupforwaddrs(fctx);
|
1999-10-07 19:41:16 +00:00
|
|
|
result = fctx_getaddresses(fctx);
|
1999-10-29 03:30:49 +00:00
|
|
|
if (result == DNS_R_WAIT) {
|
|
|
|
/*
|
|
|
|
* Sleep waiting for addresses.
|
|
|
|
*/
|
|
|
|
FCTXTRACE("addrwait");
|
2000-08-01 01:33:37 +00:00
|
|
|
fctx->attributes |= FCTX_ATTR_ADDRWAIT;
|
1999-10-29 03:30:49 +00:00
|
|
|
return;
|
|
|
|
} else if (result != ISC_R_SUCCESS) {
|
|
|
|
/*
|
|
|
|
* Something bad happened.
|
|
|
|
*/
|
1999-10-07 19:41:16 +00:00
|
|
|
fctx_done(fctx, result);
|
|
|
|
return;
|
|
|
|
}
|
1999-07-24 01:26:18 +00:00
|
|
|
|
1999-10-29 03:30:49 +00:00
|
|
|
addrinfo = fctx_nextaddress(fctx);
|
|
|
|
/*
|
2000-05-26 02:16:10 +00:00
|
|
|
* While we may have addresses from the ADB, they
|
|
|
|
* might be bad ones. In this case, return SERVFAIL.
|
1999-10-07 19:41:16 +00:00
|
|
|
*/
|
2000-05-26 02:16:10 +00:00
|
|
|
if (addrinfo == NULL) {
|
|
|
|
fctx_done(fctx, DNS_R_SERVFAIL);
|
|
|
|
return;
|
|
|
|
}
|
1999-07-24 01:26:18 +00:00
|
|
|
}
|
|
|
|
|
1999-11-23 20:54:20 +00:00
|
|
|
result = fctx_query(fctx, addrinfo, fctx->options);
|
1999-10-07 19:41:16 +00:00
|
|
|
if (result != ISC_R_SUCCESS)
|
1999-06-28 23:37:54 +00:00
|
|
|
fctx_done(fctx, result);
|
|
|
|
}
|
|
|
|
|
1999-10-08 00:05:59 +00:00
|
|
|
static isc_boolean_t
|
1999-06-28 23:37:54 +00:00
|
|
|
fctx_destroy(fetchctx_t *fctx) {
|
1999-10-08 00:05:59 +00:00
|
|
|
dns_resolver_t *res;
|
|
|
|
unsigned int bucketnum;
|
2000-02-11 03:06:56 +00:00
|
|
|
isc_sockaddr_t *sa, *next_sa;
|
1999-10-07 19:41:16 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Caller must be holding the bucket lock.
|
|
|
|
*/
|
|
|
|
|
1999-06-28 23:37:54 +00:00
|
|
|
REQUIRE(VALID_FCTX(fctx));
|
1999-11-22 19:57:17 +00:00
|
|
|
REQUIRE(fctx->state == fetchstate_done ||
|
|
|
|
fctx->state == fetchstate_init);
|
1999-06-28 23:37:54 +00:00
|
|
|
REQUIRE(ISC_LIST_EMPTY(fctx->events));
|
|
|
|
REQUIRE(ISC_LIST_EMPTY(fctx->queries));
|
1999-10-29 21:48:10 +00:00
|
|
|
REQUIRE(ISC_LIST_EMPTY(fctx->finds));
|
|
|
|
REQUIRE(fctx->pending == 0);
|
2000-08-15 00:21:05 +00:00
|
|
|
REQUIRE(ISC_LIST_EMPTY(fctx->validators));
|
2000-01-14 02:38:02 +00:00
|
|
|
REQUIRE(fctx->references == 0);
|
1999-06-28 23:37:54 +00:00
|
|
|
|
|
|
|
FCTXTRACE("destroy");
|
|
|
|
|
1999-10-08 00:05:59 +00:00
|
|
|
res = fctx->res;
|
|
|
|
bucketnum = fctx->bucketnum;
|
|
|
|
|
|
|
|
ISC_LIST_UNLINK(res->buckets[bucketnum].fctxs, fctx, link);
|
1999-10-07 19:41:16 +00:00
|
|
|
|
2000-02-11 03:06:56 +00:00
|
|
|
/*
|
|
|
|
* Free bad.
|
|
|
|
*/
|
|
|
|
for (sa = ISC_LIST_HEAD(fctx->bad);
|
|
|
|
sa != NULL;
|
|
|
|
sa = next_sa) {
|
|
|
|
next_sa = ISC_LIST_NEXT(sa, link);
|
|
|
|
ISC_LIST_UNLINK(fctx->bad, sa, link);
|
2001-11-12 19:05:39 +00:00
|
|
|
isc_mem_put(res->mctx, sa, sizeof(*sa));
|
2000-02-11 03:06:56 +00:00
|
|
|
}
|
|
|
|
|
1999-06-28 23:37:54 +00:00
|
|
|
isc_timer_detach(&fctx->timer);
|
1999-07-03 20:54:56 +00:00
|
|
|
dns_message_destroy(&fctx->rmessage);
|
|
|
|
dns_message_destroy(&fctx->qmessage);
|
2000-01-18 02:49:03 +00:00
|
|
|
if (dns_name_countlabels(&fctx->domain) > 0)
|
1999-10-08 00:05:59 +00:00
|
|
|
dns_name_free(&fctx->domain, res->mctx);
|
2000-01-18 02:49:03 +00:00
|
|
|
if (dns_rdataset_isassociated(&fctx->nameservers))
|
|
|
|
dns_rdataset_disassociate(&fctx->nameservers);
|
2000-02-11 03:06:56 +00:00
|
|
|
dns_name_free(&fctx->name, res->mctx);
|
2001-04-11 20:37:50 +00:00
|
|
|
dns_db_detach(&fctx->cache);
|
|
|
|
dns_adb_detach(&fctx->adb);
|
2001-11-12 19:05:39 +00:00
|
|
|
isc_mem_put(res->mctx, fctx, sizeof(*fctx));
|
1999-10-08 00:05:59 +00:00
|
|
|
|
2001-10-29 19:02:48 +00:00
|
|
|
LOCK(&res->lock);
|
|
|
|
res->nfctx--;
|
|
|
|
UNLOCK(&res->lock);
|
|
|
|
|
1999-10-08 00:05:59 +00:00
|
|
|
if (res->buckets[bucketnum].exiting &&
|
|
|
|
ISC_LIST_EMPTY(res->buckets[bucketnum].fctxs))
|
|
|
|
return (ISC_TRUE);
|
|
|
|
|
|
|
|
return (ISC_FALSE);
|
1999-06-28 23:37:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Fetch event handlers.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void
|
|
|
|
fctx_timeout(isc_task_t *task, isc_event_t *event) {
|
2000-04-17 19:21:30 +00:00
|
|
|
fetchctx_t *fctx = event->ev_arg;
|
1999-06-28 23:37:54 +00:00
|
|
|
|
|
|
|
REQUIRE(VALID_FCTX(fctx));
|
|
|
|
|
2000-04-11 23:15:30 +00:00
|
|
|
UNUSED(task);
|
1999-06-28 23:37:54 +00:00
|
|
|
|
|
|
|
FCTXTRACE("timeout");
|
|
|
|
|
2000-04-17 19:21:30 +00:00
|
|
|
if (event->ev_type == ISC_TIMEREVENT_LIFE) {
|
2000-04-06 22:03:35 +00:00
|
|
|
fctx_done(fctx, ISC_R_TIMEDOUT);
|
1999-06-28 23:37:54 +00:00
|
|
|
} else {
|
2000-12-20 23:18:37 +00:00
|
|
|
fctx->timeouts++;
|
1999-06-28 23:37:54 +00:00
|
|
|
/*
|
|
|
|
* We could cancel the running queries here, or we could let
|
|
|
|
* them keep going. Right now we choose the latter...
|
|
|
|
*/
|
1999-10-31 20:36:05 +00:00
|
|
|
fctx->attributes &= ~FCTX_ATTR_ADDRWAIT;
|
2000-02-11 21:10:40 +00:00
|
|
|
/*
|
|
|
|
* Our timer has triggered. Reestablish the fctx lifetime
|
|
|
|
* timer.
|
|
|
|
*/
|
|
|
|
fctx_starttimer(fctx);
|
|
|
|
/*
|
|
|
|
* Keep trying.
|
|
|
|
*/
|
1999-07-03 20:54:56 +00:00
|
|
|
fctx_try(fctx);
|
1999-06-28 23:37:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
isc_event_free(&event);
|
|
|
|
}
|
|
|
|
|
1999-10-07 19:41:16 +00:00
|
|
|
static void
|
1999-11-22 19:57:17 +00:00
|
|
|
fctx_shutdown(fetchctx_t *fctx) {
|
|
|
|
isc_event_t *cevent;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Start the shutdown process for fctx, if it isn't already underway.
|
|
|
|
*/
|
|
|
|
|
|
|
|
FCTXTRACE("shutdown");
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The caller must be holding the appropriate bucket lock.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (fctx->want_shutdown)
|
|
|
|
return;
|
2000-08-01 01:33:37 +00:00
|
|
|
|
1999-11-22 19:57:17 +00:00
|
|
|
fctx->want_shutdown = ISC_TRUE;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Unless we're still initializing (in which case the
|
|
|
|
* control event is still outstanding), we need to post
|
|
|
|
* the control event to tell the fetch we want it to
|
|
|
|
* exit.
|
|
|
|
*/
|
|
|
|
if (fctx->state != fetchstate_init) {
|
|
|
|
cevent = &fctx->control_event;
|
|
|
|
isc_task_send(fctx->res->buckets[fctx->bucketnum].task,
|
|
|
|
&cevent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
fctx_doshutdown(isc_task_t *task, isc_event_t *event) {
|
2000-04-17 19:21:30 +00:00
|
|
|
fetchctx_t *fctx = event->ev_arg;
|
1999-10-29 21:48:10 +00:00
|
|
|
isc_boolean_t bucket_empty = ISC_FALSE;
|
1999-10-07 19:41:16 +00:00
|
|
|
dns_resolver_t *res;
|
|
|
|
unsigned int bucketnum;
|
2000-08-15 00:21:05 +00:00
|
|
|
dns_validator_t *validator;
|
1999-10-07 19:41:16 +00:00
|
|
|
|
|
|
|
REQUIRE(VALID_FCTX(fctx));
|
|
|
|
|
2000-05-14 02:27:26 +00:00
|
|
|
UNUSED(task);
|
|
|
|
|
1999-10-07 19:41:16 +00:00
|
|
|
res = fctx->res;
|
|
|
|
bucketnum = fctx->bucketnum;
|
2000-08-01 01:33:37 +00:00
|
|
|
|
1999-11-22 19:57:17 +00:00
|
|
|
FCTXTRACE("doshutdown");
|
1999-10-07 19:41:16 +00:00
|
|
|
|
2000-02-03 22:24:18 +00:00
|
|
|
/*
|
|
|
|
* An fctx that is shutting down is no longer in ADDRWAIT mode.
|
|
|
|
*/
|
|
|
|
fctx->attributes &= ~FCTX_ATTR_ADDRWAIT;
|
|
|
|
|
2000-08-15 00:21:05 +00:00
|
|
|
/*
|
|
|
|
* Cancel all pending validators. Note that this must be done
|
|
|
|
* without the bucket lock held, since that could cause deadlock.
|
|
|
|
*/
|
|
|
|
validator = ISC_LIST_HEAD(fctx->validators);
|
|
|
|
while (validator != NULL) {
|
|
|
|
dns_validator_cancel(validator);
|
|
|
|
validator = ISC_LIST_NEXT(validator, link);
|
|
|
|
}
|
|
|
|
|
2001-07-11 01:19:56 +00:00
|
|
|
/*
|
|
|
|
* Shut down anything that is still running on behalf of this
|
|
|
|
* fetch. To avoid deadlock with the ADB, we must do this
|
|
|
|
* before we lock the bucket lock.
|
|
|
|
*/
|
|
|
|
fctx_stopeverything(fctx, ISC_FALSE);
|
|
|
|
|
1999-10-07 19:41:16 +00:00
|
|
|
LOCK(&res->buckets[bucketnum].lock);
|
2000-08-01 01:33:37 +00:00
|
|
|
|
2001-11-12 18:48:50 +00:00
|
|
|
fctx->attributes |= FCTX_ATTR_SHUTTINGDOWN;
|
|
|
|
|
1999-10-07 19:41:16 +00:00
|
|
|
INSIST(fctx->state == fetchstate_active ||
|
|
|
|
fctx->state == fetchstate_done);
|
1999-10-29 21:48:10 +00:00
|
|
|
INSIST(fctx->want_shutdown);
|
1999-10-07 19:41:16 +00:00
|
|
|
|
1999-10-29 21:48:10 +00:00
|
|
|
if (fctx->state != fetchstate_done) {
|
|
|
|
fctx->state = fetchstate_done;
|
|
|
|
fctx_sendevents(fctx, ISC_R_CANCELED);
|
|
|
|
}
|
|
|
|
|
2000-01-06 00:56:18 +00:00
|
|
|
if (fctx->references == 0 && fctx->pending == 0 &&
|
2000-08-15 00:21:05 +00:00
|
|
|
ISC_LIST_EMPTY(fctx->validators))
|
1999-10-29 21:48:10 +00:00
|
|
|
bucket_empty = fctx_destroy(fctx);
|
1999-10-07 19:41:16 +00:00
|
|
|
|
|
|
|
UNLOCK(&res->buckets[bucketnum].lock);
|
|
|
|
|
1999-10-29 21:48:10 +00:00
|
|
|
if (bucket_empty)
|
1999-10-08 00:05:59 +00:00
|
|
|
empty_bucket(res);
|
1999-10-07 19:41:16 +00:00
|
|
|
}
|
|
|
|
|
1999-06-28 23:37:54 +00:00
|
|
|
static void
|
|
|
|
fctx_start(isc_task_t *task, isc_event_t *event) {
|
2000-04-17 19:21:30 +00:00
|
|
|
fetchctx_t *fctx = event->ev_arg;
|
1999-10-08 00:05:59 +00:00
|
|
|
isc_boolean_t done = ISC_FALSE, bucket_empty = ISC_FALSE;
|
1999-06-28 23:37:54 +00:00
|
|
|
dns_resolver_t *res;
|
1999-10-07 19:41:16 +00:00
|
|
|
unsigned int bucketnum;
|
1999-06-28 23:37:54 +00:00
|
|
|
|
|
|
|
REQUIRE(VALID_FCTX(fctx));
|
|
|
|
|
2000-07-29 01:18:36 +00:00
|
|
|
UNUSED(task);
|
|
|
|
|
1999-06-28 23:37:54 +00:00
|
|
|
res = fctx->res;
|
1999-10-07 19:41:16 +00:00
|
|
|
bucketnum = fctx->bucketnum;
|
1999-06-28 23:37:54 +00:00
|
|
|
|
|
|
|
FCTXTRACE("start");
|
|
|
|
|
1999-10-07 19:41:16 +00:00
|
|
|
LOCK(&res->buckets[bucketnum].lock);
|
1999-06-28 23:37:54 +00:00
|
|
|
|
1999-10-07 19:41:16 +00:00
|
|
|
INSIST(fctx->state == fetchstate_init);
|
1999-10-29 21:48:10 +00:00
|
|
|
if (fctx->want_shutdown) {
|
1999-07-24 01:26:18 +00:00
|
|
|
/*
|
1999-10-07 19:41:16 +00:00
|
|
|
* We haven't started this fctx yet, and we've been requested
|
|
|
|
* to shut it down.
|
1999-07-24 01:26:18 +00:00
|
|
|
*/
|
2000-02-02 20:27:56 +00:00
|
|
|
fctx->attributes |= FCTX_ATTR_SHUTTINGDOWN;
|
|
|
|
fctx->state = fetchstate_done;
|
|
|
|
fctx_sendevents(fctx, ISC_R_CANCELED);
|
|
|
|
/*
|
|
|
|
* Since we haven't started, we INSIST that we have no
|
|
|
|
* pending ADB finds and no pending validations.
|
|
|
|
*/
|
|
|
|
INSIST(fctx->pending == 0);
|
2000-08-15 00:21:05 +00:00
|
|
|
INSIST(ISC_LIST_EMPTY(fctx->validators));
|
2000-02-02 20:27:56 +00:00
|
|
|
if (fctx->references == 0) {
|
|
|
|
/*
|
|
|
|
* It's now safe to destroy this fctx.
|
|
|
|
*/
|
|
|
|
bucket_empty = fctx_destroy(fctx);
|
|
|
|
}
|
1999-10-07 19:41:16 +00:00
|
|
|
done = ISC_TRUE;
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* Normal fctx startup.
|
|
|
|
*/
|
|
|
|
fctx->state = fetchstate_active;
|
|
|
|
/*
|
|
|
|
* Reset the control event for later use in shutting down
|
2000-07-29 01:18:36 +00:00
|
|
|
* the fctx.
|
1999-10-07 19:41:16 +00:00
|
|
|
*/
|
2000-05-14 02:27:26 +00:00
|
|
|
ISC_EVENT_INIT(event, sizeof(*event), 0, NULL,
|
1999-11-22 19:57:17 +00:00
|
|
|
DNS_EVENT_FETCHCONTROL, fctx_doshutdown, fctx,
|
2000-07-29 01:18:36 +00:00
|
|
|
NULL, NULL, NULL);
|
1999-06-28 23:37:54 +00:00
|
|
|
}
|
|
|
|
|
1999-10-07 19:41:16 +00:00
|
|
|
UNLOCK(&res->buckets[bucketnum].lock);
|
1999-06-28 23:37:54 +00:00
|
|
|
|
1999-10-07 19:41:16 +00:00
|
|
|
if (!done) {
|
|
|
|
/*
|
|
|
|
* All is well. Start working on the fetch.
|
|
|
|
*/
|
2000-02-11 21:10:40 +00:00
|
|
|
fctx_starttimer(fctx);
|
1999-10-07 19:41:16 +00:00
|
|
|
fctx_try(fctx);
|
1999-10-08 00:05:59 +00:00
|
|
|
} else if (bucket_empty)
|
|
|
|
empty_bucket(res);
|
1999-06-28 23:37:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Fetch Creation, Joining, and Cancelation.
|
|
|
|
*/
|
|
|
|
|
1999-10-07 19:41:16 +00:00
|
|
|
static inline isc_result_t
|
1999-06-28 23:37:54 +00:00
|
|
|
fctx_join(fetchctx_t *fctx, isc_task_t *task, isc_taskaction_t action,
|
1999-10-07 19:41:16 +00:00
|
|
|
void *arg, dns_rdataset_t *rdataset, dns_rdataset_t *sigrdataset,
|
|
|
|
dns_fetch_t *fetch)
|
1999-06-28 23:37:54 +00:00
|
|
|
{
|
|
|
|
isc_task_t *clone;
|
1999-10-07 19:41:16 +00:00
|
|
|
dns_fetchevent_t *event;
|
1999-06-28 23:37:54 +00:00
|
|
|
|
|
|
|
FCTXTRACE("join");
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We store the task we're going to send this event to in the
|
|
|
|
* sender field. We'll make the fetch the sender when we actually
|
|
|
|
* send the event.
|
|
|
|
*/
|
|
|
|
clone = NULL;
|
|
|
|
isc_task_attach(task, &clone);
|
1999-10-07 19:41:16 +00:00
|
|
|
event = (dns_fetchevent_t *)
|
1999-06-28 23:37:54 +00:00
|
|
|
isc_event_allocate(fctx->res->mctx, clone,
|
|
|
|
DNS_EVENT_FETCHDONE,
|
2001-11-12 19:05:39 +00:00
|
|
|
action, arg, sizeof(*event));
|
2000-01-14 02:38:02 +00:00
|
|
|
if (event == NULL) {
|
|
|
|
isc_task_detach(&clone);
|
1999-10-07 19:41:16 +00:00
|
|
|
return (ISC_R_NOMEMORY);
|
2000-01-14 02:38:02 +00:00
|
|
|
}
|
1999-10-07 19:41:16 +00:00
|
|
|
event->result = DNS_R_SERVFAIL;
|
|
|
|
event->qtype = fctx->type;
|
|
|
|
event->db = NULL;
|
|
|
|
event->node = NULL;
|
|
|
|
event->rdataset = rdataset;
|
|
|
|
event->sigrdataset = sigrdataset;
|
1999-10-20 01:57:05 +00:00
|
|
|
event->fetch = fetch;
|
1999-10-07 19:41:16 +00:00
|
|
|
dns_fixedname_init(&event->foundname);
|
1999-06-28 23:37:54 +00:00
|
|
|
|
2000-04-13 16:43:02 +00:00
|
|
|
/*
|
|
|
|
* Make sure that we can store the sigrdataset in the
|
|
|
|
* first event if it is needed by any of the events.
|
|
|
|
*/
|
|
|
|
if (event->sigrdataset != NULL)
|
2000-04-17 19:21:30 +00:00
|
|
|
ISC_LIST_PREPEND(fctx->events, event, ev_link);
|
2000-04-13 16:43:02 +00:00
|
|
|
else
|
2000-04-17 19:21:30 +00:00
|
|
|
ISC_LIST_APPEND(fctx->events, event, ev_link);
|
1999-06-28 23:37:54 +00:00
|
|
|
fctx->references++;
|
|
|
|
|
|
|
|
fetch->magic = DNS_FETCH_MAGIC;
|
|
|
|
fetch->private = fctx;
|
2000-08-01 01:33:37 +00:00
|
|
|
|
1999-10-07 19:41:16 +00:00
|
|
|
return (ISC_R_SUCCESS);
|
1999-06-28 23:37:54 +00:00
|
|
|
}
|
|
|
|
|
1999-10-07 19:41:16 +00:00
|
|
|
static isc_result_t
|
1999-06-28 23:37:54 +00:00
|
|
|
fctx_create(dns_resolver_t *res, dns_name_t *name, dns_rdatatype_t type,
|
1999-07-24 01:26:18 +00:00
|
|
|
dns_name_t *domain, dns_rdataset_t *nameservers,
|
1999-10-07 19:41:16 +00:00
|
|
|
unsigned int options, unsigned int bucketnum, fetchctx_t **fctxp)
|
1999-06-28 23:37:54 +00:00
|
|
|
{
|
|
|
|
fetchctx_t *fctx;
|
1999-10-07 19:41:16 +00:00
|
|
|
isc_result_t result = ISC_R_SUCCESS;
|
1999-06-28 23:37:54 +00:00
|
|
|
isc_result_t iresult;
|
|
|
|
isc_interval_t interval;
|
2000-01-18 02:49:03 +00:00
|
|
|
dns_fixedname_t qdomain;
|
2000-07-06 02:33:43 +00:00
|
|
|
unsigned int findoptions = 0;
|
1999-06-28 23:37:54 +00:00
|
|
|
|
1999-10-07 19:41:16 +00:00
|
|
|
/*
|
|
|
|
* Caller must be holding the lock for bucket number 'bucketnum'.
|
|
|
|
*/
|
|
|
|
REQUIRE(fctxp != NULL && *fctxp == NULL);
|
|
|
|
|
2001-11-12 19:05:39 +00:00
|
|
|
fctx = isc_mem_get(res->mctx, sizeof(*fctx));
|
1999-06-28 23:37:54 +00:00
|
|
|
if (fctx == NULL)
|
1999-10-07 19:41:16 +00:00
|
|
|
return (ISC_R_NOMEMORY);
|
1999-06-28 23:37:54 +00:00
|
|
|
FCTXTRACE("create");
|
1999-07-03 20:54:56 +00:00
|
|
|
dns_name_init(&fctx->name, NULL);
|
|
|
|
result = dns_name_dup(name, res->mctx, &fctx->name);
|
1999-10-07 19:41:16 +00:00
|
|
|
if (result != ISC_R_SUCCESS)
|
1999-06-28 23:37:54 +00:00
|
|
|
goto cleanup_fetch;
|
1999-07-24 01:26:18 +00:00
|
|
|
dns_name_init(&fctx->domain, NULL);
|
|
|
|
dns_rdataset_init(&fctx->nameservers);
|
2000-09-15 22:41:07 +00:00
|
|
|
|
|
|
|
fctx->type = type;
|
|
|
|
fctx->options = options;
|
|
|
|
/*
|
|
|
|
* Note! We do not attach to the task. We are relying on the
|
|
|
|
* resolver to ensure that this task doesn't go away while we are
|
|
|
|
* using it.
|
|
|
|
*/
|
|
|
|
fctx->res = res;
|
|
|
|
fctx->references = 0;
|
|
|
|
fctx->bucketnum = bucketnum;
|
|
|
|
fctx->state = fetchstate_init;
|
|
|
|
fctx->want_shutdown = ISC_FALSE;
|
2001-01-03 20:31:34 +00:00
|
|
|
fctx->cloned = ISC_FALSE;
|
2000-09-15 22:41:07 +00:00
|
|
|
ISC_LIST_INIT(fctx->queries);
|
|
|
|
ISC_LIST_INIT(fctx->finds);
|
|
|
|
ISC_LIST_INIT(fctx->forwaddrs);
|
|
|
|
ISC_LIST_INIT(fctx->forwarders);
|
|
|
|
fctx->fwdpolicy = dns_fwdpolicy_none;
|
|
|
|
ISC_LIST_INIT(fctx->bad);
|
|
|
|
ISC_LIST_INIT(fctx->validators);
|
|
|
|
fctx->find = NULL;
|
|
|
|
fctx->pending = 0;
|
|
|
|
fctx->restarts = 0;
|
2000-12-20 23:18:37 +00:00
|
|
|
fctx->timeouts = 0;
|
2000-09-15 22:41:07 +00:00
|
|
|
if (dns_name_requiresedns(name))
|
|
|
|
fctx->attributes = FCTX_ATTR_NEEDEDNS0;
|
|
|
|
else
|
|
|
|
fctx->attributes = 0;
|
|
|
|
|
2000-01-18 02:49:03 +00:00
|
|
|
if (domain == NULL) {
|
2000-09-15 22:41:07 +00:00
|
|
|
dns_forwarders_t *forwarders = NULL;
|
|
|
|
result = dns_fwdtable_find(fctx->res->view->fwdtable,
|
|
|
|
&fctx->name, &forwarders);
|
|
|
|
if (result == ISC_R_SUCCESS)
|
|
|
|
fctx->fwdpolicy = forwarders->fwdpolicy;
|
|
|
|
|
2000-08-24 22:15:40 +00:00
|
|
|
if (fctx->fwdpolicy != dns_fwdpolicy_only) {
|
2000-01-18 02:49:03 +00:00
|
|
|
/*
|
|
|
|
* The caller didn't supply a query domain and
|
|
|
|
* nameservers, and we're not in forward-only mode,
|
|
|
|
* so find the best nameservers to use.
|
|
|
|
*/
|
2000-07-06 02:33:43 +00:00
|
|
|
if (type == dns_rdatatype_key)
|
|
|
|
findoptions |= DNS_DBFIND_NOEXACT;
|
2000-01-18 02:49:03 +00:00
|
|
|
dns_fixedname_init(&qdomain);
|
|
|
|
result = dns_view_findzonecut(res->view, name,
|
|
|
|
dns_fixedname_name(&qdomain), 0,
|
2000-07-06 02:33:43 +00:00
|
|
|
findoptions, ISC_TRUE,
|
2000-01-18 02:49:03 +00:00
|
|
|
&fctx->nameservers,
|
|
|
|
NULL);
|
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
goto cleanup_name;
|
|
|
|
result = dns_name_dup(dns_fixedname_name(&qdomain),
|
|
|
|
res->mctx, &fctx->domain);
|
|
|
|
if (result != ISC_R_SUCCESS) {
|
|
|
|
dns_rdataset_disassociate(&fctx->nameservers);
|
|
|
|
goto cleanup_name;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* We're in forward-only mode. Set the query domain
|
|
|
|
* to ".".
|
|
|
|
*/
|
|
|
|
result = dns_name_dup(dns_rootname, res->mctx,
|
|
|
|
&fctx->domain);
|
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
goto cleanup_name;
|
|
|
|
}
|
|
|
|
} else {
|
1999-07-24 01:26:18 +00:00
|
|
|
result = dns_name_dup(domain, res->mctx, &fctx->domain);
|
1999-10-07 19:41:16 +00:00
|
|
|
if (result != ISC_R_SUCCESS)
|
1999-07-24 01:26:18 +00:00
|
|
|
goto cleanup_name;
|
|
|
|
dns_rdataset_clone(nameservers, &fctx->nameservers);
|
|
|
|
}
|
2000-07-14 00:37:27 +00:00
|
|
|
|
|
|
|
INSIST(dns_name_issubdomain(&fctx->name, &fctx->domain));
|
2000-08-01 01:33:37 +00:00
|
|
|
|
1999-07-03 20:54:56 +00:00
|
|
|
fctx->qmessage = NULL;
|
1999-07-24 01:26:18 +00:00
|
|
|
result = dns_message_create(res->mctx, DNS_MESSAGE_INTENTRENDER,
|
|
|
|
&fctx->qmessage);
|
2000-08-01 01:33:37 +00:00
|
|
|
|
1999-10-07 19:41:16 +00:00
|
|
|
if (result != ISC_R_SUCCESS)
|
1999-07-24 01:26:18 +00:00
|
|
|
goto cleanup_domain;
|
1999-06-28 23:37:54 +00:00
|
|
|
|
1999-07-03 20:54:56 +00:00
|
|
|
fctx->rmessage = NULL;
|
1999-07-24 01:26:18 +00:00
|
|
|
result = dns_message_create(res->mctx, DNS_MESSAGE_INTENTPARSE,
|
|
|
|
&fctx->rmessage);
|
2000-08-01 01:33:37 +00:00
|
|
|
|
1999-10-07 19:41:16 +00:00
|
|
|
if (result != ISC_R_SUCCESS)
|
1999-07-03 20:54:56 +00:00
|
|
|
goto cleanup_qmessage;
|
|
|
|
|
1999-06-28 23:37:54 +00:00
|
|
|
/*
|
|
|
|
* Compute an expiration time for the entire fetch.
|
|
|
|
*/
|
2001-11-14 01:31:12 +00:00
|
|
|
isc_interval_set(&interval, 30, 0); /* XXXRTH constant */
|
1999-06-28 23:37:54 +00:00
|
|
|
iresult = isc_time_nowplusinterval(&fctx->expires, &interval);
|
|
|
|
if (iresult != ISC_R_SUCCESS) {
|
|
|
|
UNEXPECTED_ERROR(__FILE__, __LINE__,
|
1999-10-07 19:41:16 +00:00
|
|
|
"isc_time_nowplusinterval: %s",
|
1999-06-28 23:37:54 +00:00
|
|
|
isc_result_totext(iresult));
|
2000-04-06 22:03:35 +00:00
|
|
|
result = ISC_R_UNEXPECTED;
|
1999-07-03 20:54:56 +00:00
|
|
|
goto cleanup_rmessage;
|
1999-06-28 23:37:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
1999-12-13 22:30:55 +00:00
|
|
|
* Default retry interval initialization. We set the interval now
|
|
|
|
* mostly so it won't be uninitialized. It will be set to the
|
|
|
|
* correct value before a query is issued.
|
1999-06-28 23:37:54 +00:00
|
|
|
*/
|
1999-12-13 22:30:55 +00:00
|
|
|
isc_interval_set(&fctx->interval, 2, 0);
|
1999-06-28 23:37:54 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Create an inactive timer. It will be made active when the fetch
|
|
|
|
* is actually started.
|
|
|
|
*/
|
1999-07-03 20:54:56 +00:00
|
|
|
fctx->timer = NULL;
|
1999-06-28 23:37:54 +00:00
|
|
|
iresult = isc_timer_create(res->timermgr, isc_timertype_inactive,
|
|
|
|
NULL, NULL,
|
1999-10-07 19:41:16 +00:00
|
|
|
res->buckets[bucketnum].task, fctx_timeout,
|
1999-06-28 23:37:54 +00:00
|
|
|
fctx, &fctx->timer);
|
|
|
|
if (iresult != ISC_R_SUCCESS) {
|
|
|
|
UNEXPECTED_ERROR(__FILE__, __LINE__,
|
|
|
|
"isc_timer_create: %s",
|
|
|
|
isc_result_totext(iresult));
|
2000-04-06 22:03:35 +00:00
|
|
|
result = ISC_R_UNEXPECTED;
|
1999-07-03 20:54:56 +00:00
|
|
|
goto cleanup_rmessage;
|
1999-06-28 23:37:54 +00:00
|
|
|
}
|
|
|
|
|
2001-04-11 20:37:50 +00:00
|
|
|
/*
|
|
|
|
* Attach to the view's cache and adb.
|
|
|
|
*/
|
|
|
|
fctx->cache = NULL;
|
|
|
|
dns_db_attach(res->view->cachedb, &fctx->cache);
|
|
|
|
fctx->adb = NULL;
|
|
|
|
dns_adb_attach(res->view->adb, &fctx->adb);
|
|
|
|
|
1999-06-28 23:37:54 +00:00
|
|
|
ISC_LIST_INIT(fctx->events);
|
|
|
|
ISC_LINK_INIT(fctx, link);
|
|
|
|
fctx->magic = FCTX_MAGIC;
|
|
|
|
|
1999-10-07 19:41:16 +00:00
|
|
|
ISC_LIST_APPEND(res->buckets[bucketnum].fctxs, fctx, link);
|
1999-06-28 23:37:54 +00:00
|
|
|
|
2001-10-29 19:02:48 +00:00
|
|
|
LOCK(&res->lock);
|
|
|
|
res->nfctx++;
|
|
|
|
UNLOCK(&res->lock);
|
|
|
|
|
1999-10-07 19:41:16 +00:00
|
|
|
*fctxp = fctx;
|
1999-06-28 23:37:54 +00:00
|
|
|
|
1999-10-07 19:41:16 +00:00
|
|
|
return (ISC_R_SUCCESS);
|
1999-06-28 23:37:54 +00:00
|
|
|
|
1999-07-03 20:54:56 +00:00
|
|
|
cleanup_rmessage:
|
|
|
|
dns_message_destroy(&fctx->rmessage);
|
|
|
|
|
|
|
|
cleanup_qmessage:
|
|
|
|
dns_message_destroy(&fctx->qmessage);
|
1999-06-28 23:37:54 +00:00
|
|
|
|
1999-07-24 01:26:18 +00:00
|
|
|
cleanup_domain:
|
2000-01-18 02:49:03 +00:00
|
|
|
if (dns_name_countlabels(&fctx->domain) > 0)
|
1999-07-24 01:26:18 +00:00
|
|
|
dns_name_free(&fctx->domain, res->mctx);
|
2000-01-18 02:49:03 +00:00
|
|
|
if (dns_rdataset_isassociated(&fctx->nameservers))
|
|
|
|
dns_rdataset_disassociate(&fctx->nameservers);
|
1999-07-24 01:26:18 +00:00
|
|
|
|
1999-06-28 23:37:54 +00:00
|
|
|
cleanup_name:
|
|
|
|
dns_name_free(&fctx->name, res->mctx);
|
|
|
|
|
|
|
|
cleanup_fetch:
|
2001-11-12 19:05:39 +00:00
|
|
|
isc_mem_put(res->mctx, fctx, sizeof(*fctx));
|
1999-06-28 23:37:54 +00:00
|
|
|
|
|
|
|
return (result);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Handle Responses
|
|
|
|
*/
|
2000-11-08 03:53:16 +00:00
|
|
|
static inline isc_boolean_t
|
|
|
|
is_lame(fetchctx_t *fctx) {
|
|
|
|
dns_message_t *message = fctx->rmessage;
|
|
|
|
dns_name_t *name;
|
|
|
|
dns_rdataset_t *rdataset;
|
|
|
|
isc_result_t result;
|
|
|
|
|
|
|
|
if (message->rcode != dns_rcode_noerror &&
|
|
|
|
message->rcode != dns_rcode_nxdomain)
|
|
|
|
return (ISC_FALSE);
|
|
|
|
|
|
|
|
if (message->counts[DNS_SECTION_ANSWER] != 0)
|
|
|
|
return (ISC_FALSE);
|
|
|
|
|
|
|
|
if (message->counts[DNS_SECTION_AUTHORITY] == 0)
|
|
|
|
return (ISC_FALSE);
|
|
|
|
|
|
|
|
result = dns_message_firstname(message, DNS_SECTION_AUTHORITY);
|
|
|
|
while (result == ISC_R_SUCCESS) {
|
|
|
|
name = NULL;
|
|
|
|
dns_message_currentname(message, DNS_SECTION_AUTHORITY, &name);
|
|
|
|
for (rdataset = ISC_LIST_HEAD(name->list);
|
|
|
|
rdataset != NULL;
|
|
|
|
rdataset = ISC_LIST_NEXT(rdataset, link)) {
|
|
|
|
dns_namereln_t namereln;
|
|
|
|
int order;
|
|
|
|
unsigned int labels, bits;
|
|
|
|
if (rdataset->type != dns_rdatatype_ns)
|
|
|
|
continue;
|
|
|
|
namereln = dns_name_fullcompare(name, &fctx->domain,
|
|
|
|
&order, &labels, &bits);
|
|
|
|
if (namereln == dns_namereln_equal &&
|
2000-11-15 04:53:06 +00:00
|
|
|
(message->flags & DNS_MESSAGEFLAG_AA) != 0)
|
|
|
|
return (ISC_FALSE);
|
2000-11-08 03:53:16 +00:00
|
|
|
if (namereln == dns_namereln_subdomain)
|
|
|
|
return (ISC_FALSE);
|
|
|
|
return (ISC_TRUE);
|
|
|
|
}
|
|
|
|
result = dns_message_nextname(message, DNS_SECTION_AUTHORITY);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (ISC_FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
log_lame(fetchctx_t *fctx, dns_adbaddrinfo_t *addrinfo) {
|
2001-01-02 18:51:07 +00:00
|
|
|
char namebuf[DNS_NAME_FORMATSIZE];
|
|
|
|
char domainbuf[DNS_NAME_FORMATSIZE];
|
2000-11-08 03:53:16 +00:00
|
|
|
char addrbuf[ISC_SOCKADDR_FORMATSIZE];
|
|
|
|
|
|
|
|
dns_name_format(&fctx->name, namebuf, sizeof(namebuf));
|
|
|
|
dns_name_format(&fctx->domain, domainbuf, sizeof(domainbuf));
|
|
|
|
isc_sockaddr_format(&addrinfo->sockaddr, addrbuf, sizeof(addrbuf));
|
2001-01-11 19:38:11 +00:00
|
|
|
isc_log_write(dns_lctx, DNS_LOGCATEGORY_LAME_SERVERS,
|
2000-11-08 03:53:16 +00:00
|
|
|
DNS_LOGMODULE_RESOLVER, ISC_LOG_INFO,
|
2001-03-07 18:03:07 +00:00
|
|
|
"lame server resolving '%s' (in '%s'?): %s",
|
2000-11-08 03:53:16 +00:00
|
|
|
namebuf, domainbuf, addrbuf);
|
|
|
|
}
|
1999-06-28 23:37:54 +00:00
|
|
|
|
1999-10-07 19:41:16 +00:00
|
|
|
static inline isc_result_t
|
1999-06-28 23:37:54 +00:00
|
|
|
same_question(fetchctx_t *fctx) {
|
1999-10-07 19:41:16 +00:00
|
|
|
isc_result_t result;
|
1999-07-03 20:54:56 +00:00
|
|
|
dns_message_t *message = fctx->rmessage;
|
1999-06-28 23:37:54 +00:00
|
|
|
dns_name_t *name;
|
|
|
|
dns_rdataset_t *rdataset;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Caller must be holding the fctx lock.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* XXXRTH Currently we support only one question.
|
|
|
|
*/
|
|
|
|
if (message->counts[DNS_SECTION_QUESTION] != 1)
|
|
|
|
return (DNS_R_FORMERR);
|
|
|
|
|
|
|
|
result = dns_message_firstname(message, DNS_SECTION_QUESTION);
|
1999-10-07 19:41:16 +00:00
|
|
|
if (result != ISC_R_SUCCESS)
|
1999-06-28 23:37:54 +00:00
|
|
|
return (result);
|
|
|
|
name = NULL;
|
|
|
|
dns_message_currentname(message, DNS_SECTION_QUESTION, &name);
|
|
|
|
rdataset = ISC_LIST_HEAD(name->list);
|
|
|
|
INSIST(rdataset != NULL);
|
|
|
|
INSIST(ISC_LIST_NEXT(rdataset, link) == NULL);
|
|
|
|
if (fctx->type != rdataset->type ||
|
|
|
|
fctx->res->rdclass != rdataset->rdclass ||
|
|
|
|
!dns_name_equal(&fctx->name, name))
|
|
|
|
return (DNS_R_FORMERR);
|
2000-08-01 01:33:37 +00:00
|
|
|
|
1999-10-07 19:41:16 +00:00
|
|
|
return (ISC_R_SUCCESS);
|
1999-06-28 23:37:54 +00:00
|
|
|
}
|
|
|
|
|
1999-10-13 02:08:30 +00:00
|
|
|
static void
|
|
|
|
clone_results(fetchctx_t *fctx) {
|
|
|
|
dns_fetchevent_t *event, *hevent;
|
|
|
|
isc_result_t result;
|
|
|
|
dns_name_t *name, *hname;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set up any other events to have the same data as the first
|
|
|
|
* event.
|
|
|
|
*
|
|
|
|
* Caller must be holding the appropriate lock.
|
|
|
|
*/
|
|
|
|
|
2001-01-03 20:31:34 +00:00
|
|
|
fctx->cloned = ISC_TRUE;
|
1999-10-13 02:08:30 +00:00
|
|
|
hevent = ISC_LIST_HEAD(fctx->events);
|
|
|
|
if (hevent == NULL)
|
|
|
|
return;
|
|
|
|
hname = dns_fixedname_name(&hevent->foundname);
|
2000-04-17 19:21:30 +00:00
|
|
|
for (event = ISC_LIST_NEXT(hevent, ev_link);
|
1999-10-13 02:08:30 +00:00
|
|
|
event != NULL;
|
2000-04-17 19:21:30 +00:00
|
|
|
event = ISC_LIST_NEXT(event, ev_link)) {
|
1999-10-13 02:08:30 +00:00
|
|
|
name = dns_fixedname_name(&event->foundname);
|
2001-01-03 00:05:15 +00:00
|
|
|
result = dns_name_copy(hname, name, NULL);
|
1999-10-13 02:08:30 +00:00
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
event->result = result;
|
|
|
|
else
|
|
|
|
event->result = hevent->result;
|
|
|
|
dns_db_attach(hevent->db, &event->db);
|
|
|
|
dns_db_attachnode(hevent->db, hevent->node, &event->node);
|
2000-04-13 16:43:02 +00:00
|
|
|
INSIST(hevent->rdataset != NULL);
|
|
|
|
INSIST(event->rdataset != NULL);
|
|
|
|
if (dns_rdataset_isassociated(hevent->rdataset))
|
1999-10-13 02:08:30 +00:00
|
|
|
dns_rdataset_clone(hevent->rdataset, event->rdataset);
|
2000-04-13 16:43:02 +00:00
|
|
|
INSIST(! (hevent->sigrdataset == NULL &&
|
|
|
|
event->sigrdataset != NULL));
|
1999-10-13 02:08:30 +00:00
|
|
|
if (hevent->sigrdataset != NULL &&
|
2000-04-13 16:43:02 +00:00
|
|
|
dns_rdataset_isassociated(hevent->sigrdataset) &&
|
|
|
|
event->sigrdataset != NULL)
|
1999-10-13 02:08:30 +00:00
|
|
|
dns_rdataset_clone(hevent->sigrdataset,
|
|
|
|
event->sigrdataset);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-10-11 19:24:28 +00:00
|
|
|
#define CACHE(r) (((r)->attributes & DNS_RDATASETATTR_CACHE) != 0)
|
|
|
|
#define ANSWER(r) (((r)->attributes & DNS_RDATASETATTR_ANSWER) != 0)
|
|
|
|
#define ANSWERSIG(r) (((r)->attributes & DNS_RDATASETATTR_ANSWERSIG) != 0)
|
|
|
|
#define EXTERNAL(r) (((r)->attributes & DNS_RDATASETATTR_EXTERNAL) != 0)
|
1999-10-17 19:21:43 +00:00
|
|
|
#define CHAINING(r) (((r)->attributes & DNS_RDATASETATTR_CHAINING) != 0)
|
1999-10-11 19:24:28 +00:00
|
|
|
|
2000-04-20 17:05:37 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Destroy '*fctx' if it is ready to be destroyed (i.e., if it has
|
|
|
|
* no references and is no longer waiting for any events). If this
|
|
|
|
* was the last fctx in the resolver, destroy the resolver.
|
|
|
|
*
|
|
|
|
* Requires:
|
|
|
|
* '*fctx' is shutting down.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
maybe_destroy(fetchctx_t *fctx) {
|
|
|
|
unsigned int bucketnum;
|
|
|
|
isc_boolean_t bucket_empty = ISC_FALSE;
|
2000-05-04 16:38:09 +00:00
|
|
|
dns_resolver_t *res = fctx->res;
|
2000-08-01 01:33:37 +00:00
|
|
|
|
2000-04-20 17:05:37 +00:00
|
|
|
REQUIRE(SHUTTINGDOWN(fctx));
|
|
|
|
|
2000-08-15 00:21:05 +00:00
|
|
|
if (fctx->pending != 0 || !ISC_LIST_EMPTY(fctx->validators))
|
2000-04-20 17:05:37 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
bucketnum = fctx->bucketnum;
|
2000-05-04 16:38:09 +00:00
|
|
|
LOCK(&res->buckets[bucketnum].lock);
|
2000-04-20 17:05:37 +00:00
|
|
|
if (fctx->references == 0)
|
|
|
|
bucket_empty = fctx_destroy(fctx);
|
2000-05-04 16:38:09 +00:00
|
|
|
UNLOCK(&res->buckets[bucketnum].lock);
|
2000-04-20 17:05:37 +00:00
|
|
|
|
|
|
|
if (bucket_empty)
|
2000-05-04 16:38:09 +00:00
|
|
|
empty_bucket(res);
|
2000-04-20 17:05:37 +00:00
|
|
|
}
|
|
|
|
|
2000-05-04 16:38:09 +00:00
|
|
|
/*
|
|
|
|
* The validator has finished.
|
|
|
|
*/
|
2000-01-06 00:56:18 +00:00
|
|
|
static void
|
2000-02-19 00:16:41 +00:00
|
|
|
validated(isc_task_t *task, isc_event_t *event) {
|
2000-04-13 22:35:49 +00:00
|
|
|
isc_result_t result = ISC_R_SUCCESS;
|
2000-05-04 16:38:09 +00:00
|
|
|
isc_result_t eresult = ISC_R_SUCCESS;
|
2000-04-13 22:35:49 +00:00
|
|
|
isc_stdtime_t now;
|
2000-07-25 22:04:33 +00:00
|
|
|
fetchctx_t *fctx;
|
|
|
|
dns_validatorevent_t *vevent;
|
2000-04-13 22:35:49 +00:00
|
|
|
dns_fetchevent_t *hevent;
|
|
|
|
dns_rdataset_t *ardataset = NULL;
|
|
|
|
dns_rdataset_t *asigrdataset = NULL;
|
|
|
|
dns_dbnode_t *node = NULL;
|
2000-07-19 23:19:05 +00:00
|
|
|
isc_boolean_t negative;
|
2001-02-21 05:16:44 +00:00
|
|
|
isc_boolean_t chaining;
|
2000-07-25 22:03:25 +00:00
|
|
|
isc_boolean_t sentresponse;
|
2000-09-28 06:43:36 +00:00
|
|
|
isc_uint32_t ttl;
|
2000-04-13 22:35:49 +00:00
|
|
|
|
2000-07-25 22:04:33 +00:00
|
|
|
UNUSED(task); /* for now */
|
2000-04-17 19:21:30 +00:00
|
|
|
|
2000-07-25 22:04:33 +00:00
|
|
|
REQUIRE(event->ev_type == DNS_EVENT_VALIDATORDONE);
|
|
|
|
fctx = event->ev_arg;
|
|
|
|
REQUIRE(VALID_FCTX(fctx));
|
2000-08-15 00:21:05 +00:00
|
|
|
REQUIRE(!ISC_LIST_EMPTY(fctx->validators));
|
2000-04-13 22:35:49 +00:00
|
|
|
|
2000-07-25 22:04:33 +00:00
|
|
|
vevent = (dns_validatorevent_t *)event;
|
2000-08-01 01:33:37 +00:00
|
|
|
|
2000-07-19 23:19:05 +00:00
|
|
|
FCTXTRACE("received validation completion event");
|
2000-04-20 17:05:37 +00:00
|
|
|
|
2000-08-15 00:21:05 +00:00
|
|
|
ISC_LIST_UNLINK(fctx->validators, vevent->validator, link);
|
|
|
|
|
2000-04-20 17:05:37 +00:00
|
|
|
/*
|
|
|
|
* Destroy the validator early so that we can
|
|
|
|
* destroy the fctx if necessary.
|
|
|
|
*/
|
2000-07-19 23:19:05 +00:00
|
|
|
dns_validator_destroy(&vevent->validator);
|
|
|
|
|
|
|
|
negative = ISC_TF(vevent->rdataset == NULL);
|
2000-04-20 17:05:37 +00:00
|
|
|
|
2000-07-25 22:03:25 +00:00
|
|
|
sentresponse = ISC_TF((fctx->options & DNS_FETCHOPT_NOVALIDATE) != 0);
|
|
|
|
|
2000-07-25 22:04:33 +00:00
|
|
|
/*
|
|
|
|
* If shutting down, ignore the results. Check to see if we're
|
|
|
|
* done waiting for validator completions and ADB pending events; if
|
|
|
|
* so, destroy the fctx.
|
2000-04-13 22:35:49 +00:00
|
|
|
*/
|
2000-07-25 22:03:25 +00:00
|
|
|
if (SHUTTINGDOWN(fctx) && !sentresponse ) {
|
2000-04-20 17:05:37 +00:00
|
|
|
maybe_destroy(fctx);
|
|
|
|
goto cleanup_event;
|
2000-04-13 22:35:49 +00:00
|
|
|
}
|
2000-01-06 00:56:18 +00:00
|
|
|
|
2001-02-21 05:16:44 +00:00
|
|
|
/*
|
|
|
|
* If chaining, we need to make sure that the right result code is
|
|
|
|
* returned, and that the rdatasets are bound.
|
|
|
|
*/
|
|
|
|
if (vevent->result == ISC_R_SUCCESS &&
|
|
|
|
!negative &&
|
|
|
|
vevent->rdataset != NULL &&
|
|
|
|
CHAINING(vevent->rdataset))
|
|
|
|
{
|
|
|
|
if (vevent->rdataset->type == dns_rdatatype_cname)
|
|
|
|
eresult = DNS_R_CNAME;
|
|
|
|
else {
|
|
|
|
INSIST(vevent->rdataset->type == dns_rdatatype_dname);
|
|
|
|
eresult = DNS_R_DNAME;
|
|
|
|
}
|
|
|
|
chaining = ISC_TRUE;
|
|
|
|
} else
|
|
|
|
chaining = ISC_FALSE;
|
|
|
|
|
2000-04-13 22:35:49 +00:00
|
|
|
/*
|
2000-07-25 22:03:25 +00:00
|
|
|
* Either we're not shutting down, or we are shutting down but want
|
|
|
|
* to cache the result anyway (if this was a validation started by
|
|
|
|
* a query with cd set)
|
|
|
|
*/
|
2000-04-13 22:35:49 +00:00
|
|
|
|
2000-05-02 18:10:19 +00:00
|
|
|
hevent = ISC_LIST_HEAD(fctx->events);
|
|
|
|
if (hevent != NULL) {
|
2001-02-21 05:16:44 +00:00
|
|
|
if (!negative && !chaining &&
|
2000-07-19 23:19:05 +00:00
|
|
|
(fctx->type == dns_rdatatype_any ||
|
|
|
|
fctx->type == dns_rdatatype_sig)) {
|
|
|
|
/*
|
|
|
|
* Don't bind rdatasets; the caller
|
|
|
|
* will iterate the node.
|
|
|
|
*/
|
|
|
|
} else {
|
|
|
|
ardataset = hevent->rdataset;
|
|
|
|
asigrdataset = hevent->sigrdataset;
|
|
|
|
}
|
2000-05-02 18:10:19 +00:00
|
|
|
}
|
|
|
|
|
2000-07-25 22:04:33 +00:00
|
|
|
if (vevent->result != ISC_R_SUCCESS) {
|
2000-05-02 18:10:19 +00:00
|
|
|
FCTXTRACE("validation failed");
|
2000-07-25 22:03:25 +00:00
|
|
|
if (vevent->rdataset != NULL) {
|
2001-04-11 20:37:50 +00:00
|
|
|
result = dns_db_findnode(fctx->cache, vevent->name,
|
|
|
|
ISC_TRUE, &node);
|
2000-07-25 22:03:25 +00:00
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
goto noanswer_response;
|
2001-04-11 20:37:50 +00:00
|
|
|
(void)dns_db_deleterdataset(fctx->cache, node, NULL,
|
2000-07-25 22:03:25 +00:00
|
|
|
vevent->type, 0);
|
|
|
|
if (vevent->sigrdataset != NULL)
|
2001-04-11 20:37:50 +00:00
|
|
|
(void)dns_db_deleterdataset(fctx->cache,
|
|
|
|
node, NULL,
|
|
|
|
dns_rdatatype_sig,
|
|
|
|
vevent->type);
|
2000-07-25 22:03:25 +00:00
|
|
|
}
|
2000-05-02 18:10:19 +00:00
|
|
|
result = vevent->result;
|
2000-06-21 22:47:38 +00:00
|
|
|
goto noanswer_response;
|
2000-04-13 22:35:49 +00:00
|
|
|
}
|
|
|
|
|
2000-05-14 02:27:26 +00:00
|
|
|
isc_stdtime_get(&now);
|
|
|
|
|
2000-07-19 23:19:05 +00:00
|
|
|
if (negative) {
|
2000-05-04 16:38:09 +00:00
|
|
|
dns_rdatatype_t covers;
|
|
|
|
FCTXTRACE("nonexistence validation OK");
|
|
|
|
|
|
|
|
if (fctx->rmessage->rcode == dns_rcode_nxdomain)
|
|
|
|
covers = dns_rdatatype_any;
|
|
|
|
else
|
|
|
|
covers = fctx->type;
|
|
|
|
|
2001-04-11 20:37:50 +00:00
|
|
|
result = dns_db_findnode(fctx->cache, vevent->name, ISC_TRUE,
|
|
|
|
&node);
|
2000-05-04 16:38:09 +00:00
|
|
|
if (result != ISC_R_SUCCESS)
|
2000-06-21 22:47:38 +00:00
|
|
|
goto noanswer_response;
|
2000-08-01 01:33:37 +00:00
|
|
|
|
2000-09-28 06:43:36 +00:00
|
|
|
/*
|
|
|
|
* If we are asking for a SOA record set the cache time
|
|
|
|
* to zero to facilitate locating the containing zone of
|
|
|
|
* a arbitary zone.
|
|
|
|
*/
|
|
|
|
ttl = fctx->res->view->maxncachettl;
|
|
|
|
if (fctx->type == dns_rdatatype_soa &&
|
|
|
|
covers == dns_rdatatype_any)
|
|
|
|
ttl = 0;
|
|
|
|
|
2001-04-11 20:37:50 +00:00
|
|
|
result = ncache_adderesult(fctx->rmessage, fctx->cache, node,
|
2000-09-28 06:43:36 +00:00
|
|
|
covers, now, ttl,
|
2000-05-26 23:17:56 +00:00
|
|
|
ardataset, &eresult);
|
2000-05-04 16:38:09 +00:00
|
|
|
if (result != ISC_R_SUCCESS)
|
2000-08-01 01:33:37 +00:00
|
|
|
goto noanswer_response;
|
2000-05-04 16:38:09 +00:00
|
|
|
|
2000-06-21 22:47:38 +00:00
|
|
|
goto answer_response;
|
2000-04-13 22:35:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
FCTXTRACE("validation OK");
|
2000-08-01 01:33:37 +00:00
|
|
|
|
2000-01-06 00:56:18 +00:00
|
|
|
/*
|
2000-04-13 22:35:49 +00:00
|
|
|
* The data was already cached as pending data.
|
|
|
|
* Re-cache it as secure and bind the cached
|
|
|
|
* rdatasets to the first event on the fetch
|
|
|
|
* event list.
|
2000-01-06 00:56:18 +00:00
|
|
|
*/
|
2001-04-11 20:37:50 +00:00
|
|
|
result = dns_db_findnode(fctx->cache, vevent->name, ISC_TRUE, &node);
|
2000-04-13 22:35:49 +00:00
|
|
|
if (result != ISC_R_SUCCESS)
|
2000-06-21 22:47:38 +00:00
|
|
|
goto noanswer_response;
|
2000-04-13 22:35:49 +00:00
|
|
|
|
2001-04-11 20:37:50 +00:00
|
|
|
result = dns_db_addrdataset(fctx->cache, node, NULL, now,
|
|
|
|
vevent->rdataset, 0, ardataset);
|
2000-04-13 22:35:49 +00:00
|
|
|
if (result != ISC_R_SUCCESS &&
|
|
|
|
result != DNS_R_UNCHANGED)
|
2000-06-21 22:47:38 +00:00
|
|
|
goto noanswer_response;
|
2000-04-18 17:44:22 +00:00
|
|
|
if (vevent->sigrdataset != NULL) {
|
2001-04-11 20:37:50 +00:00
|
|
|
result = dns_db_addrdataset(fctx->cache, node, NULL, now,
|
2000-04-18 17:44:22 +00:00
|
|
|
vevent->sigrdataset, 0,
|
|
|
|
asigrdataset);
|
|
|
|
if (result != ISC_R_SUCCESS &&
|
|
|
|
result != DNS_R_UNCHANGED)
|
2000-06-21 22:47:38 +00:00
|
|
|
goto noanswer_response;
|
2000-04-18 17:44:22 +00:00
|
|
|
}
|
2000-07-19 23:19:05 +00:00
|
|
|
|
2000-07-25 22:03:25 +00:00
|
|
|
if (sentresponse) {
|
2000-08-01 01:33:37 +00:00
|
|
|
/*
|
2000-07-25 22:03:25 +00:00
|
|
|
* If we only deferred the destroy because we wanted to cache
|
|
|
|
* the data, destroy now.
|
|
|
|
*/
|
|
|
|
if (SHUTTINGDOWN(fctx))
|
|
|
|
maybe_destroy(fctx);
|
|
|
|
|
|
|
|
goto cleanup_event;
|
|
|
|
}
|
|
|
|
|
2000-08-15 00:21:05 +00:00
|
|
|
if (!ISC_LIST_EMPTY(fctx->validators)) {
|
2000-07-19 23:19:05 +00:00
|
|
|
INSIST(!negative);
|
|
|
|
INSIST(fctx->type == dns_rdatatype_any ||
|
|
|
|
fctx->type == dns_rdatatype_sig);
|
|
|
|
/*
|
|
|
|
* Don't send a response yet - we have
|
|
|
|
* more rdatasets that still need to
|
|
|
|
* be validated.
|
|
|
|
*/
|
|
|
|
goto cleanup_event;
|
|
|
|
}
|
2000-08-01 01:33:37 +00:00
|
|
|
|
2000-05-02 18:10:19 +00:00
|
|
|
result = ISC_R_SUCCESS;
|
|
|
|
|
2000-06-21 22:47:38 +00:00
|
|
|
answer_response:
|
|
|
|
/*
|
|
|
|
* Respond with an answer, positive or negative,
|
|
|
|
* as opposed to an error. 'node' must be non-NULL.
|
|
|
|
*/
|
2000-08-01 01:33:37 +00:00
|
|
|
|
2000-06-21 22:47:38 +00:00
|
|
|
fctx->attributes |= FCTX_ATTR_HAVEANSWER;
|
2000-08-01 01:33:37 +00:00
|
|
|
|
2000-04-13 22:35:49 +00:00
|
|
|
if (hevent != NULL) {
|
2000-05-04 16:38:09 +00:00
|
|
|
hevent->result = eresult;
|
2001-01-03 00:05:15 +00:00
|
|
|
dns_name_copy(vevent->name,
|
|
|
|
dns_fixedname_name(&hevent->foundname), NULL);
|
2001-04-11 20:37:50 +00:00
|
|
|
dns_db_attach(fctx->cache, &hevent->db);
|
2000-04-13 22:35:49 +00:00
|
|
|
hevent->node = node;
|
|
|
|
node = NULL;
|
|
|
|
clone_results(fctx);
|
|
|
|
}
|
|
|
|
|
2000-06-21 22:47:38 +00:00
|
|
|
noanswer_response:
|
2000-04-13 22:35:49 +00:00
|
|
|
if (node != NULL)
|
2001-04-11 20:37:50 +00:00
|
|
|
dns_db_detachnode(fctx->cache, &node);
|
2000-04-13 22:35:49 +00:00
|
|
|
|
|
|
|
fctx_done(fctx, result);
|
2000-04-20 17:05:37 +00:00
|
|
|
|
|
|
|
cleanup_event:
|
|
|
|
isc_event_free(&event);
|
2000-01-06 00:56:18 +00:00
|
|
|
}
|
|
|
|
|
1999-10-11 19:24:28 +00:00
|
|
|
static inline isc_result_t
|
|
|
|
cache_name(fetchctx_t *fctx, dns_name_t *name, isc_stdtime_t now) {
|
2000-01-06 00:56:18 +00:00
|
|
|
dns_rdataset_t *rdataset, *sigrdataset;
|
|
|
|
dns_rdataset_t *addedrdataset, *ardataset, *asigrdataset;
|
2000-05-05 17:26:47 +00:00
|
|
|
dns_rdataset_t *valrdataset = NULL, *valsigrdataset = NULL;
|
1999-10-11 19:24:28 +00:00
|
|
|
dns_dbnode_t *node, **anodep;
|
|
|
|
dns_db_t **adbp;
|
2000-03-16 23:59:33 +00:00
|
|
|
dns_name_t *aname;
|
1999-10-11 19:24:28 +00:00
|
|
|
dns_resolver_t *res;
|
2000-07-25 22:03:25 +00:00
|
|
|
isc_boolean_t need_validation, secure_domain, have_answer;
|
1999-10-13 02:08:30 +00:00
|
|
|
isc_result_t result, eresult;
|
1999-10-11 19:24:28 +00:00
|
|
|
dns_fetchevent_t *event;
|
2000-01-25 19:27:30 +00:00
|
|
|
unsigned int options;
|
2000-02-19 00:16:41 +00:00
|
|
|
isc_task_t *task;
|
2000-07-19 23:19:05 +00:00
|
|
|
dns_validator_t *validator;
|
1999-10-11 19:24:28 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* The appropriate bucket lock must be held.
|
|
|
|
*/
|
|
|
|
|
|
|
|
res = fctx->res;
|
|
|
|
need_validation = ISC_FALSE;
|
2000-07-25 22:03:25 +00:00
|
|
|
secure_domain = ISC_FALSE;
|
1999-10-13 02:08:30 +00:00
|
|
|
have_answer = ISC_FALSE;
|
|
|
|
eresult = ISC_R_SUCCESS;
|
2000-07-19 23:19:05 +00:00
|
|
|
task = res->buckets[fctx->bucketnum].task;
|
1999-10-11 19:24:28 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Is DNSSEC validation required for this name?
|
|
|
|
*/
|
2000-03-16 23:59:33 +00:00
|
|
|
result = dns_keytable_issecuredomain(res->view->secroots, name,
|
2000-07-25 22:03:25 +00:00
|
|
|
&secure_domain);
|
2000-03-16 23:59:33 +00:00
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
return (result);
|
1999-10-11 19:24:28 +00:00
|
|
|
|
2000-07-25 22:03:25 +00:00
|
|
|
if ((fctx->options & DNS_FETCHOPT_NOVALIDATE) != 0)
|
|
|
|
need_validation = ISC_FALSE;
|
|
|
|
else
|
|
|
|
need_validation = secure_domain;
|
|
|
|
|
1999-10-11 19:24:28 +00:00
|
|
|
adbp = NULL;
|
|
|
|
aname = NULL;
|
|
|
|
anodep = NULL;
|
|
|
|
ardataset = NULL;
|
|
|
|
asigrdataset = NULL;
|
1999-10-13 02:08:30 +00:00
|
|
|
event = NULL;
|
2000-02-19 00:16:41 +00:00
|
|
|
if ((name->attributes & DNS_NAMEATTR_ANSWER) != 0 &&
|
|
|
|
!need_validation) {
|
1999-10-13 02:08:30 +00:00
|
|
|
have_answer = ISC_TRUE;
|
1999-10-11 19:24:28 +00:00
|
|
|
event = ISC_LIST_HEAD(fctx->events);
|
|
|
|
if (event != NULL) {
|
|
|
|
adbp = &event->db;
|
|
|
|
aname = dns_fixedname_name(&event->foundname);
|
2001-01-03 00:05:15 +00:00
|
|
|
result = dns_name_copy(name, aname, NULL);
|
1999-10-11 19:24:28 +00:00
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
return (result);
|
|
|
|
anodep = &event->node;
|
2001-02-19 08:54:54 +00:00
|
|
|
/*
|
|
|
|
* If this is an ANY or SIG query, we're not going
|
|
|
|
* to return any rdatasets, unless we encountered
|
|
|
|
* a CNAME or DNAME as "the answer". In this case,
|
|
|
|
* we're going to return DNS_R_CNAME or DNS_R_DNAME
|
|
|
|
* and we must set up the rdatasets.
|
|
|
|
*/
|
|
|
|
if ((fctx->type != dns_rdatatype_any &&
|
|
|
|
fctx->type != dns_rdatatype_sig) ||
|
|
|
|
(name->attributes & DNS_NAMEATTR_CHAINING) != 0) {
|
1999-10-11 19:24:28 +00:00
|
|
|
ardataset = event->rdataset;
|
|
|
|
asigrdataset = event->sigrdataset;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2000-08-01 01:33:37 +00:00
|
|
|
|
1999-10-11 19:24:28 +00:00
|
|
|
/*
|
|
|
|
* Find or create the cache node.
|
|
|
|
*/
|
|
|
|
node = NULL;
|
2001-04-11 20:37:50 +00:00
|
|
|
result = dns_db_findnode(fctx->cache, name, ISC_TRUE, &node);
|
1999-10-11 19:24:28 +00:00
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
return (result);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Cache or validate each cacheable rdataset.
|
|
|
|
*/
|
|
|
|
for (rdataset = ISC_LIST_HEAD(name->list);
|
|
|
|
rdataset != NULL;
|
|
|
|
rdataset = ISC_LIST_NEXT(rdataset, link)) {
|
|
|
|
if (!CACHE(rdataset))
|
|
|
|
continue;
|
2000-05-26 23:17:56 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Enforce the configure maximum cache TTL.
|
|
|
|
*/
|
|
|
|
if (rdataset->ttl > res->view->maxcachettl)
|
|
|
|
rdataset->ttl = res->view->maxcachettl;
|
|
|
|
|
2000-01-06 00:56:18 +00:00
|
|
|
/*
|
|
|
|
* If this rrset is in a secure domain, do DNSSEC validation
|
|
|
|
* for it, unless it is glue.
|
|
|
|
*/
|
2000-07-25 22:03:25 +00:00
|
|
|
if (secure_domain && rdataset->trust != dns_trust_glue) {
|
2000-01-06 00:56:18 +00:00
|
|
|
/*
|
|
|
|
* SIGs are validated as part of validating the
|
|
|
|
* type they cover.
|
|
|
|
*/
|
|
|
|
if (rdataset->type == dns_rdatatype_sig)
|
|
|
|
continue;
|
1999-10-19 19:52:56 +00:00
|
|
|
/*
|
2000-01-06 00:56:18 +00:00
|
|
|
* Find the SIG for this rdataset, if we have it.
|
1999-10-19 19:52:56 +00:00
|
|
|
*/
|
2000-01-06 00:56:18 +00:00
|
|
|
for (sigrdataset = ISC_LIST_HEAD(name->list);
|
|
|
|
sigrdataset != NULL;
|
|
|
|
sigrdataset = ISC_LIST_NEXT(sigrdataset, link)) {
|
|
|
|
if (sigrdataset->type == dns_rdatatype_sig &&
|
|
|
|
sigrdataset->covers == rdataset->type)
|
|
|
|
break;
|
|
|
|
}
|
2000-02-19 00:16:41 +00:00
|
|
|
if (sigrdataset == NULL) {
|
2000-07-25 22:03:25 +00:00
|
|
|
if (!ANSWER(rdataset) && need_validation) {
|
2000-02-19 00:16:41 +00:00
|
|
|
/*
|
|
|
|
* Ignore non-answer rdatasets that
|
|
|
|
* are missing signatures.
|
|
|
|
*/
|
|
|
|
continue;
|
|
|
|
}
|
2000-01-06 00:56:18 +00:00
|
|
|
}
|
2000-02-19 00:16:41 +00:00
|
|
|
|
2000-05-31 22:01:39 +00:00
|
|
|
/*
|
|
|
|
* Normalize the rdataset and sigrdataset TTLs.
|
|
|
|
*/
|
|
|
|
if (sigrdataset != NULL) {
|
|
|
|
rdataset->ttl = ISC_MIN(rdataset->ttl,
|
|
|
|
sigrdataset->ttl);
|
|
|
|
sigrdataset->ttl = rdataset->ttl;
|
|
|
|
}
|
|
|
|
|
2000-02-19 00:16:41 +00:00
|
|
|
/*
|
|
|
|
* Cache this rdataset/sigrdataset pair as
|
|
|
|
* pending data.
|
|
|
|
*/
|
|
|
|
rdataset->trust = dns_trust_pending;
|
2000-04-18 17:44:22 +00:00
|
|
|
if (sigrdataset != NULL)
|
|
|
|
sigrdataset->trust = dns_trust_pending;
|
2000-07-25 22:03:25 +00:00
|
|
|
if (!need_validation)
|
|
|
|
addedrdataset = ardataset;
|
|
|
|
else
|
|
|
|
addedrdataset = NULL;
|
2001-04-11 20:37:50 +00:00
|
|
|
result = dns_db_addrdataset(fctx->cache, node, NULL,
|
|
|
|
now, rdataset, 0,
|
2000-07-25 22:03:25 +00:00
|
|
|
addedrdataset);
|
2000-04-20 17:56:03 +00:00
|
|
|
if (result == DNS_R_UNCHANGED)
|
|
|
|
result = ISC_R_SUCCESS;
|
|
|
|
if (result != ISC_R_SUCCESS)
|
2000-02-19 00:16:41 +00:00
|
|
|
break;
|
2000-04-18 17:44:22 +00:00
|
|
|
if (sigrdataset != NULL) {
|
2000-07-25 22:03:25 +00:00
|
|
|
if (!need_validation)
|
|
|
|
addedrdataset = asigrdataset;
|
|
|
|
else
|
|
|
|
addedrdataset = NULL;
|
2001-04-11 20:37:50 +00:00
|
|
|
result = dns_db_addrdataset(fctx->cache,
|
2000-04-18 17:44:22 +00:00
|
|
|
node, NULL, now,
|
|
|
|
sigrdataset, 0,
|
2000-07-25 22:03:25 +00:00
|
|
|
addedrdataset);
|
2000-04-20 17:56:03 +00:00
|
|
|
if (result == DNS_R_UNCHANGED)
|
|
|
|
result = ISC_R_SUCCESS;
|
|
|
|
if (result != ISC_R_SUCCESS)
|
2000-04-18 17:44:22 +00:00
|
|
|
break;
|
2000-07-26 00:03:18 +00:00
|
|
|
} else if (!ANSWER(rdataset))
|
2000-07-25 22:03:25 +00:00
|
|
|
continue;
|
|
|
|
|
2000-07-27 21:29:58 +00:00
|
|
|
if (ANSWER(rdataset) && need_validation) {
|
2000-07-19 23:19:05 +00:00
|
|
|
if (fctx->type != dns_rdatatype_any &&
|
|
|
|
fctx->type != dns_rdatatype_sig) {
|
|
|
|
/*
|
|
|
|
* This is The Answer. We will
|
|
|
|
* validate it, but first we cache
|
|
|
|
* the rest of the response - it may
|
|
|
|
* contain useful keys.
|
|
|
|
*/
|
|
|
|
INSIST(valrdataset == NULL &&
|
|
|
|
valsigrdataset == NULL);
|
|
|
|
valrdataset = rdataset;
|
|
|
|
valsigrdataset = sigrdataset;
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* This is one of (potentially)
|
|
|
|
* multiple answers to an ANY
|
|
|
|
* or SIG query. To keep things
|
|
|
|
* simple, we just start the
|
|
|
|
* validator right away rather
|
|
|
|
* than caching first and
|
|
|
|
* having to remember which
|
|
|
|
* rdatasets needed validation.
|
|
|
|
*/
|
|
|
|
validator = NULL;
|
|
|
|
result = dns_validator_create(
|
|
|
|
res->view,
|
|
|
|
name,
|
|
|
|
rdataset->type,
|
|
|
|
rdataset,
|
|
|
|
sigrdataset,
|
|
|
|
fctx->rmessage,
|
|
|
|
0,
|
|
|
|
task,
|
|
|
|
validated,
|
|
|
|
fctx,
|
|
|
|
&validator);
|
|
|
|
if (result == ISC_R_SUCCESS)
|
2000-08-15 00:21:05 +00:00
|
|
|
ISC_LIST_APPEND(
|
|
|
|
fctx->validators,
|
|
|
|
validator, link);
|
2000-07-19 23:19:05 +00:00
|
|
|
}
|
2000-02-19 00:16:41 +00:00
|
|
|
}
|
1999-10-11 19:24:28 +00:00
|
|
|
} else if (!EXTERNAL(rdataset)) {
|
|
|
|
/*
|
|
|
|
* It's OK to cache this rdataset now.
|
|
|
|
*/
|
|
|
|
if (ANSWER(rdataset))
|
|
|
|
addedrdataset = ardataset;
|
2000-04-04 21:13:45 +00:00
|
|
|
else if (ANSWERSIG(rdataset))
|
|
|
|
addedrdataset = asigrdataset;
|
1999-10-11 19:24:28 +00:00
|
|
|
else
|
|
|
|
addedrdataset = NULL;
|
1999-10-17 19:21:43 +00:00
|
|
|
if (CHAINING(rdataset)) {
|
|
|
|
if (rdataset->type == dns_rdatatype_cname)
|
|
|
|
eresult = DNS_R_CNAME;
|
|
|
|
else {
|
|
|
|
INSIST(rdataset->type ==
|
|
|
|
dns_rdatatype_dname);
|
|
|
|
eresult = DNS_R_DNAME;
|
|
|
|
}
|
|
|
|
}
|
2000-01-25 19:27:30 +00:00
|
|
|
if (rdataset->trust == dns_trust_glue) {
|
|
|
|
/*
|
|
|
|
* If the trust level is 'dns_trust_glue'
|
|
|
|
* then we are adding data from a referral
|
|
|
|
* we got while executing the search algorithm.
|
|
|
|
* New referral data always takes precedence
|
|
|
|
* over the existing cache contents.
|
|
|
|
*/
|
|
|
|
options = DNS_DBADD_FORCE;
|
|
|
|
} else
|
|
|
|
options = 0;
|
2000-02-19 00:16:41 +00:00
|
|
|
/*
|
|
|
|
* Now we can add the rdataset.
|
|
|
|
*/
|
2001-04-11 20:37:50 +00:00
|
|
|
result = dns_db_addrdataset(fctx->cache,
|
1999-10-11 19:24:28 +00:00
|
|
|
node, NULL, now,
|
|
|
|
rdataset,
|
2000-01-25 19:27:30 +00:00
|
|
|
options,
|
1999-10-11 19:24:28 +00:00
|
|
|
addedrdataset);
|
1999-10-15 20:51:19 +00:00
|
|
|
if (result == DNS_R_UNCHANGED) {
|
|
|
|
if (ANSWER(rdataset) &&
|
1999-10-19 19:52:56 +00:00
|
|
|
ardataset != NULL &&
|
|
|
|
ardataset->type == 0) {
|
1999-10-15 20:51:19 +00:00
|
|
|
/*
|
1999-10-19 19:52:56 +00:00
|
|
|
* The answer in the cache is better
|
|
|
|
* than the answer we found, and is
|
|
|
|
* a negative cache entry, so we
|
|
|
|
* must set eresult appropriately.
|
1999-10-15 20:51:19 +00:00
|
|
|
*/
|
1999-10-19 19:52:56 +00:00
|
|
|
if (ardataset->covers ==
|
|
|
|
dns_rdatatype_any)
|
|
|
|
eresult =
|
|
|
|
DNS_R_NCACHENXDOMAIN;
|
|
|
|
else
|
|
|
|
eresult =
|
|
|
|
DNS_R_NCACHENXRRSET;
|
1999-10-15 20:51:19 +00:00
|
|
|
}
|
1999-10-17 19:21:43 +00:00
|
|
|
result = ISC_R_SUCCESS;
|
1999-10-15 20:51:19 +00:00
|
|
|
} else if (result != ISC_R_SUCCESS)
|
1999-10-11 19:24:28 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-05-05 17:26:47 +00:00
|
|
|
if (valrdataset != NULL) {
|
2000-08-01 01:33:37 +00:00
|
|
|
validator = NULL;
|
2000-05-05 17:26:47 +00:00
|
|
|
result = dns_validator_create(res->view,
|
|
|
|
name,
|
|
|
|
fctx->type,
|
|
|
|
valrdataset,
|
|
|
|
valsigrdataset,
|
|
|
|
fctx->rmessage,
|
|
|
|
0,
|
|
|
|
task,
|
|
|
|
validated,
|
|
|
|
fctx,
|
2000-07-19 23:19:05 +00:00
|
|
|
&validator);
|
2000-05-05 17:26:47 +00:00
|
|
|
if (result == ISC_R_SUCCESS)
|
2000-08-15 00:21:05 +00:00
|
|
|
ISC_LIST_APPEND(fctx->validators, validator, link);
|
2000-05-05 17:26:47 +00:00
|
|
|
}
|
|
|
|
|
1999-10-13 02:08:30 +00:00
|
|
|
if (result == ISC_R_SUCCESS && have_answer) {
|
1999-10-25 21:19:54 +00:00
|
|
|
fctx->attributes |= FCTX_ATTR_HAVEANSWER;
|
1999-10-13 02:08:30 +00:00
|
|
|
if (event != NULL) {
|
|
|
|
event->result = eresult;
|
2001-04-11 20:37:50 +00:00
|
|
|
dns_db_attach(fctx->cache, adbp);
|
1999-10-11 19:24:28 +00:00
|
|
|
*anodep = node;
|
2000-01-21 02:47:30 +00:00
|
|
|
node = NULL;
|
1999-10-13 02:08:30 +00:00
|
|
|
clone_results(fctx);
|
1999-10-11 19:24:28 +00:00
|
|
|
}
|
2000-01-21 02:47:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (node != NULL)
|
2001-04-11 20:37:50 +00:00
|
|
|
dns_db_detachnode(fctx->cache, &node);
|
1999-10-11 19:24:28 +00:00
|
|
|
|
|
|
|
return (result);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline isc_result_t
|
1999-10-29 03:30:49 +00:00
|
|
|
cache_message(fetchctx_t *fctx, isc_stdtime_t now) {
|
1999-10-11 19:24:28 +00:00
|
|
|
isc_result_t result;
|
|
|
|
dns_section_t section;
|
|
|
|
dns_name_t *name;
|
|
|
|
|
1999-11-03 03:19:17 +00:00
|
|
|
FCTXTRACE("cache_message");
|
|
|
|
|
|
|
|
fctx->attributes &= ~FCTX_ATTR_WANTCACHE;
|
|
|
|
|
1999-10-11 19:24:28 +00:00
|
|
|
LOCK(&fctx->res->buckets[fctx->bucketnum].lock);
|
|
|
|
|
|
|
|
for (section = DNS_SECTION_ANSWER;
|
|
|
|
section <= DNS_SECTION_ADDITIONAL;
|
|
|
|
section++) {
|
|
|
|
result = dns_message_firstname(fctx->rmessage, section);
|
|
|
|
while (result == ISC_R_SUCCESS) {
|
|
|
|
name = NULL;
|
|
|
|
dns_message_currentname(fctx->rmessage, section,
|
|
|
|
&name);
|
|
|
|
if ((name->attributes & DNS_NAMEATTR_CACHE) != 0) {
|
|
|
|
result = cache_name(fctx, name, now);
|
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
result = dns_message_nextname(fctx->rmessage, section);
|
|
|
|
}
|
|
|
|
if (result != ISC_R_NOMORE)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (result == ISC_R_NOMORE)
|
|
|
|
result = ISC_R_SUCCESS;
|
|
|
|
|
|
|
|
UNLOCK(&fctx->res->buckets[fctx->bucketnum].lock);
|
|
|
|
|
|
|
|
return (result);
|
|
|
|
}
|
|
|
|
|
2000-05-04 16:38:09 +00:00
|
|
|
/*
|
|
|
|
* Do what dns_ncache_add() does, and then compute an appropriate eresult.
|
|
|
|
*/
|
|
|
|
static isc_result_t
|
|
|
|
ncache_adderesult(dns_message_t *message, dns_db_t *cache, dns_dbnode_t *node,
|
2000-05-26 23:17:56 +00:00
|
|
|
dns_rdatatype_t covers, isc_stdtime_t now, dns_ttl_t maxttl,
|
2000-05-04 16:38:09 +00:00
|
|
|
dns_rdataset_t *ardataset,
|
|
|
|
isc_result_t *eresultp)
|
|
|
|
{
|
|
|
|
isc_result_t result;
|
2000-05-26 23:17:56 +00:00
|
|
|
result = dns_ncache_add(message, cache, node, covers, now,
|
|
|
|
maxttl, ardataset);
|
2000-05-04 16:38:09 +00:00
|
|
|
if (result == DNS_R_UNCHANGED) {
|
|
|
|
/*
|
2001-09-17 20:24:13 +00:00
|
|
|
* The data in the cache are better than the negative cache
|
2000-05-04 16:38:09 +00:00
|
|
|
* entry we're trying to add.
|
|
|
|
*/
|
|
|
|
if (ardataset != NULL && ardataset->type == 0) {
|
|
|
|
/*
|
|
|
|
* The cache data is also a negative cache
|
|
|
|
* entry.
|
|
|
|
*/
|
|
|
|
if (ardataset->covers == dns_rdatatype_any)
|
|
|
|
*eresultp = DNS_R_NCACHENXDOMAIN;
|
|
|
|
else
|
|
|
|
*eresultp = DNS_R_NCACHENXRRSET;
|
|
|
|
result = ISC_R_SUCCESS;
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* Either we don't care about the nature of the
|
|
|
|
* cache rdataset (because no fetch is interested
|
|
|
|
* in the outcome), or the cache rdataset is not
|
|
|
|
* a negative cache entry. Whichever case it is,
|
2000-08-01 01:33:37 +00:00
|
|
|
* we can return success.
|
2000-05-04 16:38:09 +00:00
|
|
|
*
|
|
|
|
* XXXRTH There's a CNAME/DNAME problem here.
|
|
|
|
*/
|
|
|
|
*eresultp = ISC_R_SUCCESS;
|
|
|
|
result = ISC_R_SUCCESS;
|
|
|
|
}
|
|
|
|
} else if (result == ISC_R_SUCCESS) {
|
|
|
|
if (covers == dns_rdatatype_any)
|
|
|
|
*eresultp = DNS_R_NCACHENXDOMAIN;
|
|
|
|
else
|
|
|
|
*eresultp = DNS_R_NCACHENXRRSET;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (result);
|
|
|
|
}
|
|
|
|
|
1999-10-16 00:48:34 +00:00
|
|
|
static inline isc_result_t
|
1999-10-27 00:44:24 +00:00
|
|
|
ncache_message(fetchctx_t *fctx, dns_rdatatype_t covers, isc_stdtime_t now) {
|
1999-10-16 00:48:34 +00:00
|
|
|
isc_result_t result, eresult;
|
|
|
|
dns_name_t *name;
|
|
|
|
dns_resolver_t *res;
|
|
|
|
dns_db_t **adbp;
|
|
|
|
dns_dbnode_t *node, **anodep;
|
|
|
|
dns_rdataset_t *ardataset;
|
2000-07-27 18:42:08 +00:00
|
|
|
isc_boolean_t need_validation, secure_domain;
|
2000-03-16 23:59:33 +00:00
|
|
|
dns_name_t *aname;
|
1999-10-16 00:48:34 +00:00
|
|
|
dns_fetchevent_t *event;
|
2000-09-28 06:43:36 +00:00
|
|
|
isc_uint32_t ttl;
|
1999-10-16 00:48:34 +00:00
|
|
|
|
1999-11-03 03:19:17 +00:00
|
|
|
FCTXTRACE("ncache_message");
|
|
|
|
|
|
|
|
fctx->attributes &= ~FCTX_ATTR_WANTNCACHE;
|
|
|
|
|
1999-10-16 00:48:34 +00:00
|
|
|
res = fctx->res;
|
|
|
|
need_validation = ISC_FALSE;
|
2000-07-27 18:42:08 +00:00
|
|
|
secure_domain = ISC_FALSE;
|
1999-10-16 00:48:34 +00:00
|
|
|
eresult = ISC_R_SUCCESS;
|
|
|
|
name = &fctx->name;
|
2001-05-29 23:07:28 +00:00
|
|
|
node = NULL;
|
1999-10-16 00:48:34 +00:00
|
|
|
|
2001-10-10 04:11:32 +00:00
|
|
|
/*
|
|
|
|
* XXXMPA remove when we follow cnames and adjust the setting
|
|
|
|
* of FCTX_ATTR_WANTNCACHE in noanswer_response().
|
|
|
|
*/
|
|
|
|
INSIST(fctx->rmessage->counts[DNS_SECTION_ANSWER] == 0);
|
|
|
|
|
1999-10-16 00:48:34 +00:00
|
|
|
/*
|
|
|
|
* Is DNSSEC validation required for this name?
|
|
|
|
*/
|
2000-03-16 23:59:33 +00:00
|
|
|
result = dns_keytable_issecuredomain(res->view->secroots, name,
|
2000-07-27 18:42:08 +00:00
|
|
|
&secure_domain);
|
2000-03-16 23:59:33 +00:00
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
return (result);
|
2000-07-27 18:42:08 +00:00
|
|
|
|
|
|
|
if ((fctx->options & DNS_FETCHOPT_NOVALIDATE) != 0)
|
|
|
|
need_validation = ISC_FALSE;
|
|
|
|
else
|
|
|
|
need_validation = secure_domain;
|
|
|
|
|
|
|
|
if (secure_domain) {
|
2000-02-19 00:16:41 +00:00
|
|
|
/*
|
2000-07-27 21:29:58 +00:00
|
|
|
* Mark all rdatasets as pending.
|
2000-02-19 00:16:41 +00:00
|
|
|
*/
|
2000-07-27 18:42:08 +00:00
|
|
|
dns_rdataset_t *trdataset;
|
|
|
|
dns_name_t *tname;
|
|
|
|
|
|
|
|
result = dns_message_firstname(fctx->rmessage,
|
|
|
|
DNS_SECTION_AUTHORITY);
|
|
|
|
while (result == ISC_R_SUCCESS) {
|
|
|
|
tname = NULL;
|
|
|
|
dns_message_currentname(fctx->rmessage,
|
|
|
|
DNS_SECTION_AUTHORITY,
|
|
|
|
&tname);
|
|
|
|
for (trdataset = ISC_LIST_HEAD(tname->list);
|
|
|
|
trdataset != NULL;
|
|
|
|
trdataset = ISC_LIST_NEXT(trdataset, link))
|
|
|
|
trdataset->trust = dns_trust_pending;
|
|
|
|
result = dns_message_nextname(fctx->rmessage,
|
|
|
|
DNS_SECTION_AUTHORITY);
|
|
|
|
}
|
|
|
|
if (result != ISC_R_NOMORE)
|
|
|
|
return (result);
|
|
|
|
|
2000-07-27 21:29:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (need_validation) {
|
|
|
|
/*
|
|
|
|
* Do negative response validation.
|
|
|
|
*/
|
|
|
|
dns_validator_t *validator = NULL;
|
|
|
|
isc_task_t *task = res->buckets[fctx->bucketnum].task;
|
|
|
|
|
2000-07-25 22:04:33 +00:00
|
|
|
result = dns_validator_create(res->view, name, fctx->type,
|
2000-05-02 18:10:19 +00:00
|
|
|
NULL, NULL,
|
2000-07-25 22:04:33 +00:00
|
|
|
fctx->rmessage, 0, task,
|
|
|
|
validated, fctx,
|
|
|
|
&validator);
|
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
return (result);
|
2000-08-15 00:21:05 +00:00
|
|
|
ISC_LIST_APPEND(fctx->validators, validator, link);
|
2000-07-27 18:42:08 +00:00
|
|
|
/*
|
|
|
|
* If validation is necessary, return now. Otherwise continue
|
|
|
|
* to process the message, letting the validation complete
|
|
|
|
* in its own good time.
|
|
|
|
*/
|
2000-07-27 21:29:58 +00:00
|
|
|
return (ISC_R_SUCCESS);
|
1999-10-16 00:48:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
LOCK(&res->buckets[fctx->bucketnum].lock);
|
|
|
|
|
|
|
|
adbp = NULL;
|
|
|
|
aname = NULL;
|
|
|
|
anodep = NULL;
|
|
|
|
ardataset = NULL;
|
1999-11-04 18:38:14 +00:00
|
|
|
if (!HAVE_ANSWER(fctx)) {
|
|
|
|
event = ISC_LIST_HEAD(fctx->events);
|
|
|
|
if (event != NULL) {
|
|
|
|
adbp = &event->db;
|
|
|
|
aname = dns_fixedname_name(&event->foundname);
|
2001-01-03 00:05:15 +00:00
|
|
|
result = dns_name_copy(name, aname, NULL);
|
1999-11-04 18:38:14 +00:00
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
goto unlock;
|
|
|
|
anodep = &event->node;
|
|
|
|
ardataset = event->rdataset;
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
event = NULL;
|
1999-10-16 00:48:34 +00:00
|
|
|
|
2001-04-11 20:37:50 +00:00
|
|
|
result = dns_db_findnode(fctx->cache, name, ISC_TRUE, &node);
|
1999-10-16 00:48:34 +00:00
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
goto unlock;
|
|
|
|
|
2000-09-28 06:43:36 +00:00
|
|
|
/*
|
|
|
|
* If we are asking for a SOA record set the cache time
|
|
|
|
* to zero to facilitate locating the containing zone of
|
|
|
|
* a arbitary zone.
|
|
|
|
*/
|
|
|
|
ttl = fctx->res->view->maxncachettl;
|
|
|
|
if (fctx->type == dns_rdatatype_soa &&
|
|
|
|
covers == dns_rdatatype_any)
|
|
|
|
ttl = 0;
|
|
|
|
|
2001-04-11 20:37:50 +00:00
|
|
|
result = ncache_adderesult(fctx->rmessage, fctx->cache, node,
|
2000-09-28 06:43:36 +00:00
|
|
|
covers, now, ttl, ardataset, &eresult);
|
2000-05-04 16:38:09 +00:00
|
|
|
if (result != ISC_R_SUCCESS)
|
2000-08-01 01:33:37 +00:00
|
|
|
goto unlock;
|
|
|
|
|
1999-11-04 18:38:14 +00:00
|
|
|
if (!HAVE_ANSWER(fctx)) {
|
|
|
|
fctx->attributes |= FCTX_ATTR_HAVEANSWER;
|
|
|
|
if (event != NULL) {
|
|
|
|
event->result = eresult;
|
2001-04-11 20:37:50 +00:00
|
|
|
dns_db_attach(fctx->cache, adbp);
|
1999-11-04 18:38:14 +00:00
|
|
|
*anodep = node;
|
|
|
|
node = NULL;
|
|
|
|
clone_results(fctx);
|
|
|
|
}
|
1999-10-16 00:48:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
unlock:
|
|
|
|
UNLOCK(&res->buckets[fctx->bucketnum].lock);
|
|
|
|
|
|
|
|
if (node != NULL)
|
2001-04-11 20:37:50 +00:00
|
|
|
dns_db_detachnode(fctx->cache, &node);
|
1999-10-16 00:48:34 +00:00
|
|
|
|
|
|
|
return (result);
|
|
|
|
}
|
|
|
|
|
1999-10-11 19:24:28 +00:00
|
|
|
static inline void
|
|
|
|
mark_related(dns_name_t *name, dns_rdataset_t *rdataset,
|
1999-10-25 21:19:54 +00:00
|
|
|
isc_boolean_t external, isc_boolean_t gluing)
|
1999-10-11 19:24:28 +00:00
|
|
|
{
|
|
|
|
name->attributes |= DNS_NAMEATTR_CACHE;
|
2001-02-08 19:14:58 +00:00
|
|
|
if (gluing) {
|
1999-10-25 21:19:54 +00:00
|
|
|
rdataset->trust = dns_trust_glue;
|
2001-02-08 19:14:58 +00:00
|
|
|
/*
|
|
|
|
* Glue with 0 TTL causes problems. We force the TTL to
|
|
|
|
* 1 second to prevent this.
|
|
|
|
*/
|
|
|
|
if (rdataset->ttl == 0)
|
|
|
|
rdataset->ttl = 1;
|
|
|
|
} else
|
1999-10-25 21:19:54 +00:00
|
|
|
rdataset->trust = dns_trust_additional;
|
1999-10-11 19:24:28 +00:00
|
|
|
rdataset->attributes |= DNS_RDATASETATTR_CACHE;
|
|
|
|
if (external)
|
|
|
|
rdataset->attributes |= DNS_RDATASETATTR_EXTERNAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static isc_result_t
|
2000-06-01 21:42:42 +00:00
|
|
|
check_related(void *arg, dns_name_t *addname, dns_rdatatype_t type) {
|
1999-10-11 19:24:28 +00:00
|
|
|
fetchctx_t *fctx = arg;
|
|
|
|
isc_result_t result;
|
|
|
|
dns_name_t *name;
|
|
|
|
dns_rdataset_t *rdataset;
|
|
|
|
isc_boolean_t external;
|
|
|
|
dns_rdatatype_t rtype;
|
1999-10-25 21:19:54 +00:00
|
|
|
isc_boolean_t gluing;
|
1999-10-11 19:24:28 +00:00
|
|
|
|
|
|
|
REQUIRE(VALID_FCTX(fctx));
|
|
|
|
|
1999-10-25 21:19:54 +00:00
|
|
|
if (GLUING(fctx))
|
|
|
|
gluing = ISC_TRUE;
|
|
|
|
else
|
|
|
|
gluing = ISC_FALSE;
|
1999-10-11 19:24:28 +00:00
|
|
|
name = NULL;
|
|
|
|
rdataset = NULL;
|
|
|
|
result = dns_message_findname(fctx->rmessage, DNS_SECTION_ADDITIONAL,
|
|
|
|
addname, dns_rdatatype_any, 0, &name,
|
|
|
|
NULL);
|
|
|
|
if (result == ISC_R_SUCCESS) {
|
1999-10-29 12:56:58 +00:00
|
|
|
external = ISC_TF(!dns_name_issubdomain(name, &fctx->domain));
|
1999-10-11 19:24:28 +00:00
|
|
|
if (type == dns_rdatatype_a) {
|
|
|
|
for (rdataset = ISC_LIST_HEAD(name->list);
|
|
|
|
rdataset != NULL;
|
|
|
|
rdataset = ISC_LIST_NEXT(rdataset, link)) {
|
|
|
|
if (rdataset->type == dns_rdatatype_sig)
|
|
|
|
rtype = rdataset->covers;
|
|
|
|
else
|
|
|
|
rtype = rdataset->type;
|
|
|
|
if (rtype == dns_rdatatype_a ||
|
|
|
|
rtype == dns_rdatatype_aaaa ||
|
|
|
|
rtype == dns_rdatatype_a6)
|
1999-10-25 21:19:54 +00:00
|
|
|
mark_related(name, rdataset, external,
|
|
|
|
gluing);
|
1999-10-11 19:24:28 +00:00
|
|
|
/*
|
|
|
|
* XXXRTH Need to do a controlled recursion
|
|
|
|
* on the A6 prefix names to mark
|
|
|
|
* any additional data related to them.
|
|
|
|
*
|
|
|
|
* Ick.
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
result = dns_message_findtype(name, type, 0,
|
|
|
|
&rdataset);
|
|
|
|
if (result == ISC_R_SUCCESS) {
|
1999-10-25 21:19:54 +00:00
|
|
|
mark_related(name, rdataset, external, gluing);
|
1999-10-11 19:24:28 +00:00
|
|
|
/*
|
|
|
|
* Do we have its SIG too?
|
|
|
|
*/
|
|
|
|
result = dns_message_findtype(name,
|
|
|
|
dns_rdatatype_sig,
|
|
|
|
type, &rdataset);
|
|
|
|
if (result == ISC_R_SUCCESS)
|
1999-10-25 21:19:54 +00:00
|
|
|
mark_related(name, rdataset, external,
|
|
|
|
gluing);
|
1999-10-11 19:24:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* XXXRTH Some other stuff still needs to be marked.
|
|
|
|
* See query.c.
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
|
|
|
|
return (ISC_R_SUCCESS);
|
|
|
|
}
|
|
|
|
|
1999-10-17 19:21:43 +00:00
|
|
|
static inline isc_result_t
|
|
|
|
cname_target(dns_rdataset_t *rdataset, dns_name_t *tname) {
|
|
|
|
isc_result_t result;
|
2000-10-25 04:26:57 +00:00
|
|
|
dns_rdata_t rdata = DNS_RDATA_INIT;
|
2000-10-07 00:09:28 +00:00
|
|
|
dns_rdata_cname_t cname;
|
1999-10-17 19:21:43 +00:00
|
|
|
|
|
|
|
result = dns_rdataset_first(rdataset);
|
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
return (result);
|
|
|
|
dns_rdataset_current(rdataset, &rdata);
|
2000-10-07 00:09:28 +00:00
|
|
|
result = dns_rdata_tostruct(&rdata, &cname, NULL);
|
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
return (result);
|
1999-10-18 21:05:49 +00:00
|
|
|
dns_name_init(tname, NULL);
|
2000-10-07 00:09:28 +00:00
|
|
|
dns_name_clone(&cname.cname, tname);
|
|
|
|
dns_rdata_freestruct(&cname);
|
1999-10-17 19:21:43 +00:00
|
|
|
|
|
|
|
return (ISC_R_SUCCESS);
|
|
|
|
}
|
|
|
|
|
1999-10-18 21:05:49 +00:00
|
|
|
static inline isc_result_t
|
|
|
|
dname_target(dns_rdataset_t *rdataset, dns_name_t *qname, dns_name_t *oname,
|
|
|
|
dns_fixedname_t *fixeddname)
|
|
|
|
{
|
|
|
|
isc_result_t result;
|
2000-10-25 04:26:57 +00:00
|
|
|
dns_rdata_t rdata = DNS_RDATA_INIT;
|
1999-10-18 21:05:49 +00:00
|
|
|
unsigned int nlabels, nbits;
|
|
|
|
int order;
|
|
|
|
dns_namereln_t namereln;
|
2000-10-07 00:09:28 +00:00
|
|
|
dns_rdata_dname_t dname;
|
2000-10-13 18:55:11 +00:00
|
|
|
dns_fixedname_t prefix;
|
1999-10-18 21:05:49 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Get the target name of the DNAME.
|
|
|
|
*/
|
|
|
|
|
|
|
|
result = dns_rdataset_first(rdataset);
|
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
return (result);
|
|
|
|
dns_rdataset_current(rdataset, &rdata);
|
2000-10-07 00:09:28 +00:00
|
|
|
result = dns_rdata_tostruct(&rdata, &dname, NULL);
|
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
return (result);
|
1999-10-18 21:05:49 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Get the prefix of qname.
|
|
|
|
*/
|
|
|
|
namereln = dns_name_fullcompare(qname, oname, &order, &nlabels,
|
|
|
|
&nbits);
|
2000-10-07 00:09:28 +00:00
|
|
|
if (namereln != dns_namereln_subdomain) {
|
|
|
|
dns_rdata_freestruct(&dname);
|
1999-10-18 21:05:49 +00:00
|
|
|
return (DNS_R_FORMERR);
|
2000-10-07 00:09:28 +00:00
|
|
|
}
|
2000-10-13 18:55:11 +00:00
|
|
|
dns_fixedname_init(&prefix);
|
|
|
|
result = dns_name_split(qname, nlabels, nbits,
|
|
|
|
dns_fixedname_name(&prefix), NULL);
|
2000-10-07 00:09:28 +00:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
|
|
|
dns_rdata_freestruct(&dname);
|
1999-10-18 21:05:49 +00:00
|
|
|
return (result);
|
2000-10-07 00:09:28 +00:00
|
|
|
}
|
2000-10-13 18:55:11 +00:00
|
|
|
dns_fixedname_init(fixeddname);
|
|
|
|
result = dns_name_concatenate(dns_fixedname_name(&prefix),
|
|
|
|
&dname.dname,
|
|
|
|
dns_fixedname_name(fixeddname), NULL);
|
2000-10-07 00:09:28 +00:00
|
|
|
dns_rdata_freestruct(&dname);
|
|
|
|
return (result);
|
1999-10-18 21:05:49 +00:00
|
|
|
}
|
|
|
|
|
2001-09-14 21:04:35 +00:00
|
|
|
/*
|
|
|
|
* Handle a no-answer response (NXDOMAIN, NXRRSET, or referral).
|
|
|
|
* If bind8_ns_resp is ISC_TRUE, this is a suspected BIND 8
|
|
|
|
* response to an NS query that should be treated as a referral
|
|
|
|
* even though the NS records occur in the answer section
|
|
|
|
* rather than the authority section.
|
|
|
|
*/
|
1999-10-19 02:33:42 +00:00
|
|
|
static isc_result_t
|
2001-09-14 21:04:35 +00:00
|
|
|
noanswer_response(fetchctx_t *fctx, dns_name_t *oqname,
|
|
|
|
isc_boolean_t bind8_ns_resp)
|
|
|
|
{
|
1999-10-19 02:33:42 +00:00
|
|
|
isc_result_t result;
|
|
|
|
dns_message_t *message;
|
|
|
|
dns_name_t *name, *qname, *ns_name, *soa_name;
|
1999-11-03 03:19:17 +00:00
|
|
|
dns_rdataset_t *rdataset, *ns_rdataset;
|
1999-10-19 02:33:42 +00:00
|
|
|
isc_boolean_t done, aa, negative_response;
|
|
|
|
dns_rdatatype_t type;
|
2001-09-14 21:04:35 +00:00
|
|
|
dns_section_t section =
|
|
|
|
bind8_ns_resp ? DNS_SECTION_ANSWER : DNS_SECTION_AUTHORITY;
|
1999-10-19 02:33:42 +00:00
|
|
|
|
1999-11-03 03:19:17 +00:00
|
|
|
FCTXTRACE("noanswer_response");
|
|
|
|
|
1999-10-19 02:33:42 +00:00
|
|
|
message = fctx->rmessage;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Setup qname.
|
|
|
|
*/
|
|
|
|
if (oqname == NULL) {
|
|
|
|
/*
|
|
|
|
* We have a normal, non-chained negative response or
|
|
|
|
* referral.
|
|
|
|
*/
|
|
|
|
if ((message->flags & DNS_MESSAGEFLAG_AA) != 0)
|
|
|
|
aa = ISC_TRUE;
|
|
|
|
else
|
|
|
|
aa = ISC_FALSE;
|
|
|
|
qname = &fctx->name;
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* We're being invoked by answer_response() after it has
|
|
|
|
* followed a CNAME/DNAME chain.
|
|
|
|
*/
|
|
|
|
qname = oqname;
|
|
|
|
aa = ISC_FALSE;
|
1999-11-04 18:38:14 +00:00
|
|
|
/*
|
|
|
|
* If the current qname is not a subdomain of the query
|
|
|
|
* domain, there's no point in looking at the authority
|
|
|
|
* section without doing DNSSEC validation.
|
|
|
|
*
|
|
|
|
* Until we do that validation, we'll just return success
|
|
|
|
* in this case.
|
|
|
|
*/
|
|
|
|
if (!dns_name_issubdomain(qname, &fctx->domain))
|
|
|
|
return (ISC_R_SUCCESS);
|
1999-10-19 02:33:42 +00:00
|
|
|
}
|
2000-08-01 01:33:37 +00:00
|
|
|
|
1999-10-19 02:33:42 +00:00
|
|
|
/*
|
|
|
|
* We have to figure out if this is a negative response, or a
|
1999-11-03 03:19:17 +00:00
|
|
|
* referral.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Sometimes we can tell if its a negative response by looking at
|
|
|
|
* the message header.
|
1999-10-19 02:33:42 +00:00
|
|
|
*/
|
|
|
|
negative_response = ISC_FALSE;
|
1999-11-03 03:19:17 +00:00
|
|
|
if (message->rcode == dns_rcode_nxdomain ||
|
|
|
|
(message->counts[DNS_SECTION_ANSWER] == 0 &&
|
|
|
|
message->counts[DNS_SECTION_AUTHORITY] == 0))
|
1999-10-19 02:33:42 +00:00
|
|
|
negative_response = ISC_TRUE;
|
|
|
|
|
1999-11-03 03:19:17 +00:00
|
|
|
/*
|
|
|
|
* Process the authority section.
|
|
|
|
*/
|
1999-10-19 02:33:42 +00:00
|
|
|
done = ISC_FALSE;
|
|
|
|
ns_name = NULL;
|
1999-11-03 03:19:17 +00:00
|
|
|
ns_rdataset = NULL;
|
1999-10-19 02:33:42 +00:00
|
|
|
soa_name = NULL;
|
2001-09-14 21:04:35 +00:00
|
|
|
result = dns_message_firstname(message, section);
|
1999-10-19 02:33:42 +00:00
|
|
|
while (!done && result == ISC_R_SUCCESS) {
|
|
|
|
name = NULL;
|
2001-09-14 21:04:35 +00:00
|
|
|
dns_message_currentname(message, section, &name);
|
1999-10-19 02:33:42 +00:00
|
|
|
if (dns_name_issubdomain(name, &fctx->domain)) {
|
|
|
|
for (rdataset = ISC_LIST_HEAD(name->list);
|
|
|
|
rdataset != NULL;
|
|
|
|
rdataset = ISC_LIST_NEXT(rdataset, link)) {
|
|
|
|
type = rdataset->type;
|
|
|
|
if (type == dns_rdatatype_sig)
|
|
|
|
type = rdataset->covers;
|
2001-10-09 08:03:32 +00:00
|
|
|
if (((type == dns_rdatatype_ns ||
|
|
|
|
type == dns_rdatatype_soa) &&
|
|
|
|
!dns_name_issubdomain(qname, name)))
|
|
|
|
return (DNS_R_FORMERR);
|
2000-04-13 17:01:19 +00:00
|
|
|
if (type == dns_rdatatype_ns) {
|
1999-10-19 02:33:42 +00:00
|
|
|
/*
|
|
|
|
* NS or SIG NS.
|
|
|
|
*
|
|
|
|
* Only one set of NS RRs is allowed.
|
|
|
|
*/
|
|
|
|
if (ns_name != NULL && name != ns_name)
|
|
|
|
return (DNS_R_FORMERR);
|
|
|
|
ns_name = name;
|
|
|
|
name->attributes |=
|
|
|
|
DNS_NAMEATTR_CACHE;
|
|
|
|
rdataset->attributes |=
|
|
|
|
DNS_RDATASETATTR_CACHE;
|
1999-10-25 21:19:54 +00:00
|
|
|
rdataset->trust = dns_trust_glue;
|
1999-11-03 03:19:17 +00:00
|
|
|
ns_rdataset = rdataset;
|
2000-04-13 17:01:19 +00:00
|
|
|
} else if (type == dns_rdatatype_soa ||
|
|
|
|
type == dns_rdatatype_nxt) {
|
1999-10-19 02:33:42 +00:00
|
|
|
/*
|
|
|
|
* SOA, SIG SOA, NXT, or SIG NXT.
|
|
|
|
*
|
|
|
|
* Only one SOA is allowed.
|
|
|
|
*/
|
2000-05-24 05:10:00 +00:00
|
|
|
if (rdataset->type ==
|
|
|
|
dns_rdatatype_soa) {
|
2000-04-12 19:27:15 +00:00
|
|
|
if (soa_name != NULL &&
|
|
|
|
name != soa_name)
|
|
|
|
return (DNS_R_FORMERR);
|
|
|
|
soa_name = name;
|
|
|
|
}
|
1999-10-19 02:33:42 +00:00
|
|
|
negative_response = ISC_TRUE;
|
|
|
|
name->attributes |=
|
|
|
|
DNS_NAMEATTR_NCACHE;
|
|
|
|
rdataset->attributes |=
|
|
|
|
DNS_RDATASETATTR_NCACHE;
|
|
|
|
if (aa)
|
|
|
|
rdataset->trust =
|
|
|
|
dns_trust_authauthority;
|
|
|
|
else
|
|
|
|
rdataset->trust =
|
|
|
|
dns_trust_additional;
|
|
|
|
/*
|
|
|
|
* No additional data needs to be
|
|
|
|
* marked.
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2001-09-14 21:04:35 +00:00
|
|
|
result = dns_message_nextname(message, section);
|
2000-04-12 19:27:15 +00:00
|
|
|
if (result == ISC_R_NOMORE)
|
|
|
|
break;
|
|
|
|
else if (result != ISC_R_SUCCESS)
|
1999-10-19 02:33:42 +00:00
|
|
|
return (result);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Did we find anything?
|
|
|
|
*/
|
|
|
|
if (!negative_response && ns_name == NULL) {
|
|
|
|
/*
|
|
|
|
* Nope.
|
|
|
|
*/
|
|
|
|
if (oqname != NULL) {
|
|
|
|
/*
|
|
|
|
* We've already got a partial CNAME/DNAME chain,
|
|
|
|
* and haven't found else anything useful here, but
|
|
|
|
* no error has occurred since we have an answer.
|
|
|
|
*/
|
|
|
|
return (ISC_R_SUCCESS);
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* The responder is insane.
|
|
|
|
*/
|
|
|
|
return (DNS_R_FORMERR);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If we found both NS and SOA, they should be the same name.
|
|
|
|
*/
|
1999-11-04 18:38:14 +00:00
|
|
|
if (ns_name != NULL && soa_name != NULL && ns_name != soa_name)
|
|
|
|
return (DNS_R_FORMERR);
|
1999-10-19 02:33:42 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Do we have a referral? (We only want to follow a referral if
|
|
|
|
* we're not following a chain.)
|
|
|
|
*/
|
|
|
|
if (!negative_response && ns_name != NULL && oqname == NULL) {
|
2000-02-07 22:25:04 +00:00
|
|
|
/*
|
2000-07-16 18:26:18 +00:00
|
|
|
* We already know ns_name is a subdomain of fctx->domain.
|
2000-02-07 22:25:04 +00:00
|
|
|
* If ns_name is equal to fctx->domain, we're not making
|
|
|
|
* progress. We return DNS_R_FORMERR so that we'll keep
|
|
|
|
* keep trying other servers.
|
|
|
|
*/
|
|
|
|
if (dns_name_equal(ns_name, &fctx->domain))
|
|
|
|
return (DNS_R_FORMERR);
|
2000-07-15 01:02:25 +00:00
|
|
|
|
|
|
|
/*
|
2000-07-16 18:26:18 +00:00
|
|
|
* If the referral name is not a parent of the query
|
2000-08-01 01:33:37 +00:00
|
|
|
* name, consider the responder insane.
|
2000-07-15 01:02:25 +00:00
|
|
|
*/
|
2000-07-16 18:26:18 +00:00
|
|
|
if (! dns_name_issubdomain(&fctx->name, ns_name)) {
|
|
|
|
FCTXTRACE("referral to non-parent");
|
2000-07-15 01:02:25 +00:00
|
|
|
return (DNS_R_FORMERR);
|
|
|
|
}
|
|
|
|
|
1999-11-03 03:19:17 +00:00
|
|
|
/*
|
|
|
|
* Mark any additional data related to this rdataset.
|
|
|
|
* It's important that we do this before we change the
|
|
|
|
* query domain.
|
|
|
|
*/
|
|
|
|
INSIST(ns_rdataset != NULL);
|
|
|
|
fctx->attributes |= FCTX_ATTR_GLUING;
|
|
|
|
(void)dns_rdataset_additionaldata(ns_rdataset, check_related,
|
|
|
|
fctx);
|
|
|
|
fctx->attributes &= ~FCTX_ATTR_GLUING;
|
2001-02-02 00:10:26 +00:00
|
|
|
/*
|
|
|
|
* NS rdatasets with 0 TTL cause problems.
|
|
|
|
* dns_view_findzonecut() will not find them when we
|
|
|
|
* try to follow the referral, and we'll SERVFAIL
|
|
|
|
* because the best nameservers are now above QDOMAIN.
|
|
|
|
* We force the TTL to 1 second to prevent this.
|
|
|
|
*/
|
|
|
|
if (ns_rdataset->ttl == 0)
|
|
|
|
ns_rdataset->ttl = 1;
|
1999-10-19 02:33:42 +00:00
|
|
|
/*
|
|
|
|
* Set the current query domain to the referral name.
|
2000-01-18 02:49:03 +00:00
|
|
|
*
|
|
|
|
* XXXRTH We should check if we're in forward-only mode, and
|
|
|
|
* if so we should bail out.
|
1999-10-19 02:33:42 +00:00
|
|
|
*/
|
|
|
|
INSIST(dns_name_countlabels(&fctx->domain) > 0);
|
|
|
|
dns_name_free(&fctx->domain, fctx->res->mctx);
|
2000-01-18 02:49:03 +00:00
|
|
|
if (dns_rdataset_isassociated(&fctx->nameservers))
|
|
|
|
dns_rdataset_disassociate(&fctx->nameservers);
|
1999-10-19 02:33:42 +00:00
|
|
|
dns_name_init(&fctx->domain, NULL);
|
|
|
|
result = dns_name_dup(ns_name, fctx->res->mctx, &fctx->domain);
|
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
return (result);
|
1999-11-03 03:19:17 +00:00
|
|
|
fctx->attributes |= FCTX_ATTR_WANTCACHE;
|
1999-10-19 02:33:42 +00:00
|
|
|
return (DNS_R_DELEGATION);
|
|
|
|
}
|
|
|
|
|
1999-11-04 18:38:14 +00:00
|
|
|
/*
|
|
|
|
* Since we're not doing a referral, we don't want to cache any
|
|
|
|
* NS RRs we may have found.
|
|
|
|
*/
|
|
|
|
if (ns_name != NULL)
|
|
|
|
ns_name->attributes &= ~DNS_NAMEATTR_CACHE;
|
|
|
|
|
2001-10-10 04:11:32 +00:00
|
|
|
if (negative_response && oqname == NULL)
|
1999-11-03 03:19:17 +00:00
|
|
|
fctx->attributes |= FCTX_ATTR_WANTNCACHE;
|
2000-08-01 01:33:37 +00:00
|
|
|
|
1999-10-19 02:33:42 +00:00
|
|
|
return (ISC_R_SUCCESS);
|
|
|
|
}
|
|
|
|
|
1999-11-04 19:39:16 +00:00
|
|
|
static isc_result_t
|
1999-10-11 19:24:28 +00:00
|
|
|
answer_response(fetchctx_t *fctx) {
|
|
|
|
isc_result_t result;
|
|
|
|
dns_message_t *message;
|
1999-10-17 19:21:43 +00:00
|
|
|
dns_name_t *name, *qname, tname;
|
1999-10-11 19:24:28 +00:00
|
|
|
dns_rdataset_t *rdataset;
|
1999-10-18 21:05:49 +00:00
|
|
|
isc_boolean_t done, external, chaining, aa, found, want_chaining;
|
2000-07-28 22:37:47 +00:00
|
|
|
isc_boolean_t have_answer, found_cname, found_type;
|
1999-10-11 19:24:28 +00:00
|
|
|
unsigned int aflag;
|
1999-10-17 19:21:43 +00:00
|
|
|
dns_rdatatype_t type;
|
2000-10-13 18:55:11 +00:00
|
|
|
dns_fixedname_t dname, fqname;
|
1999-10-11 19:24:28 +00:00
|
|
|
|
1999-11-03 03:19:17 +00:00
|
|
|
FCTXTRACE("answer_response");
|
|
|
|
|
1999-10-11 19:24:28 +00:00
|
|
|
message = fctx->rmessage;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Examine the answer section, marking those rdatasets which are
|
|
|
|
* part of the answer and should be cached.
|
|
|
|
*/
|
|
|
|
|
2000-07-24 23:55:19 +00:00
|
|
|
done = ISC_FALSE;
|
2000-07-28 22:37:47 +00:00
|
|
|
found_cname = ISC_FALSE;
|
|
|
|
found_type = ISC_FALSE;
|
1999-10-11 19:24:28 +00:00
|
|
|
chaining = ISC_FALSE;
|
1999-10-19 02:33:42 +00:00
|
|
|
have_answer = ISC_FALSE;
|
|
|
|
want_chaining = ISC_FALSE;
|
1999-10-11 19:24:28 +00:00
|
|
|
if ((message->flags & DNS_MESSAGEFLAG_AA) != 0)
|
|
|
|
aa = ISC_TRUE;
|
|
|
|
else
|
|
|
|
aa = ISC_FALSE;
|
|
|
|
qname = &fctx->name;
|
1999-10-17 19:21:43 +00:00
|
|
|
type = fctx->type;
|
1999-10-11 19:24:28 +00:00
|
|
|
result = dns_message_firstname(message, DNS_SECTION_ANSWER);
|
2000-07-24 20:10:26 +00:00
|
|
|
while (!done && result == ISC_R_SUCCESS) {
|
1999-10-11 19:24:28 +00:00
|
|
|
name = NULL;
|
|
|
|
dns_message_currentname(message, DNS_SECTION_ANSWER, &name);
|
1999-10-29 12:56:58 +00:00
|
|
|
external = ISC_TF(!dns_name_issubdomain(name, &fctx->domain));
|
1999-10-11 19:24:28 +00:00
|
|
|
if (dns_name_equal(name, qname)) {
|
|
|
|
for (rdataset = ISC_LIST_HEAD(name->list);
|
|
|
|
rdataset != NULL;
|
|
|
|
rdataset = ISC_LIST_NEXT(rdataset, link)) {
|
|
|
|
found = ISC_FALSE;
|
1999-10-18 21:05:49 +00:00
|
|
|
want_chaining = ISC_FALSE;
|
1999-10-17 19:21:43 +00:00
|
|
|
aflag = 0;
|
2000-07-28 22:37:47 +00:00
|
|
|
if (rdataset->type == type && !found_cname) {
|
1999-10-11 19:24:28 +00:00
|
|
|
/*
|
|
|
|
* We've found an ordinary answer.
|
|
|
|
*/
|
|
|
|
found = ISC_TRUE;
|
2000-07-28 22:37:47 +00:00
|
|
|
found_type = ISC_TRUE;
|
2000-07-24 20:10:26 +00:00
|
|
|
done = ISC_TRUE;
|
|
|
|
aflag = DNS_RDATASETATTR_ANSWER;
|
|
|
|
} else if (type == dns_rdatatype_any) {
|
|
|
|
/*
|
|
|
|
* We've found an answer matching
|
|
|
|
* an ANY query. There may be
|
|
|
|
* more.
|
|
|
|
*/
|
|
|
|
found = ISC_TRUE;
|
1999-10-11 19:24:28 +00:00
|
|
|
aflag = DNS_RDATASETATTR_ANSWER;
|
|
|
|
} else if (rdataset->type == dns_rdatatype_sig
|
2000-07-28 22:37:47 +00:00
|
|
|
&& rdataset->covers == type
|
|
|
|
&& !found_cname) {
|
1999-10-11 19:24:28 +00:00
|
|
|
/*
|
|
|
|
* We've found a signature that
|
|
|
|
* covers the type we're looking for.
|
|
|
|
*/
|
|
|
|
found = ISC_TRUE;
|
2000-07-28 22:37:47 +00:00
|
|
|
found_type = ISC_TRUE;
|
1999-10-11 19:24:28 +00:00
|
|
|
aflag = DNS_RDATASETATTR_ANSWERSIG;
|
1999-10-17 19:21:43 +00:00
|
|
|
} else if (rdataset->type ==
|
2000-07-28 22:37:47 +00:00
|
|
|
dns_rdatatype_cname
|
|
|
|
&& !found_type) {
|
1999-10-17 19:21:43 +00:00
|
|
|
/*
|
|
|
|
* We're looking for something else,
|
|
|
|
* but we found a CNAME.
|
|
|
|
*
|
|
|
|
* Getting a CNAME response for some
|
|
|
|
* query types is an error.
|
|
|
|
*/
|
|
|
|
if (type == dns_rdatatype_sig ||
|
|
|
|
type == dns_rdatatype_key ||
|
|
|
|
type == dns_rdatatype_nxt)
|
|
|
|
return (DNS_R_FORMERR);
|
|
|
|
found = ISC_TRUE;
|
2000-07-28 22:37:47 +00:00
|
|
|
found_cname = ISC_TRUE;
|
1999-10-18 21:05:49 +00:00
|
|
|
want_chaining = ISC_TRUE;
|
1999-10-17 19:21:43 +00:00
|
|
|
aflag = DNS_RDATASETATTR_ANSWER;
|
|
|
|
result = cname_target(rdataset,
|
|
|
|
&tname);
|
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
return (result);
|
1999-10-19 02:33:42 +00:00
|
|
|
} else if (rdataset->type == dns_rdatatype_sig
|
|
|
|
&& rdataset->covers ==
|
2000-07-28 22:37:47 +00:00
|
|
|
dns_rdatatype_cname
|
|
|
|
&& !found_type) {
|
1999-10-19 02:33:42 +00:00
|
|
|
/*
|
|
|
|
* We're looking for something else,
|
|
|
|
* but we found a SIG CNAME.
|
|
|
|
*/
|
|
|
|
found = ISC_TRUE;
|
2000-07-28 22:37:47 +00:00
|
|
|
found_cname = ISC_TRUE;
|
1999-10-19 02:33:42 +00:00
|
|
|
aflag = DNS_RDATASETATTR_ANSWERSIG;
|
1999-10-11 19:24:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (found) {
|
|
|
|
/*
|
|
|
|
* We've found an answer to our
|
|
|
|
* question.
|
|
|
|
*/
|
|
|
|
name->attributes |=
|
|
|
|
DNS_NAMEATTR_CACHE;
|
|
|
|
rdataset->attributes |=
|
|
|
|
DNS_RDATASETATTR_CACHE;
|
|
|
|
rdataset->trust = dns_trust_answer;
|
|
|
|
if (!chaining) {
|
|
|
|
/*
|
|
|
|
* This data is "the" answer
|
|
|
|
* to our question only if
|
|
|
|
* we're not chaining (i.e.
|
|
|
|
* if we haven't followed
|
|
|
|
* a CNAME or DNAME).
|
|
|
|
*/
|
|
|
|
INSIST(!external);
|
1999-10-19 02:33:42 +00:00
|
|
|
if (aflag ==
|
|
|
|
DNS_RDATASETATTR_ANSWER)
|
|
|
|
have_answer = ISC_TRUE;
|
1999-10-11 19:24:28 +00:00
|
|
|
name->attributes |=
|
|
|
|
DNS_NAMEATTR_ANSWER;
|
|
|
|
rdataset->attributes |= aflag;
|
|
|
|
if (aa)
|
|
|
|
rdataset->trust =
|
|
|
|
dns_trust_authanswer;
|
|
|
|
} else if (external) {
|
|
|
|
/*
|
|
|
|
* This data is outside of
|
|
|
|
* our query domain, and
|
|
|
|
* may only be cached if it
|
|
|
|
* comes from a secure zone
|
|
|
|
* and validates.
|
|
|
|
*/
|
|
|
|
rdataset->attributes |=
|
|
|
|
DNS_RDATASETATTR_EXTERNAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Mark any additional data related
|
|
|
|
* to this rdataset.
|
|
|
|
*/
|
|
|
|
(void)dns_rdataset_additionaldata(
|
|
|
|
rdataset,
|
|
|
|
check_related,
|
|
|
|
fctx);
|
1999-10-17 19:21:43 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* CNAME chaining.
|
|
|
|
*/
|
1999-10-18 21:05:49 +00:00
|
|
|
if (want_chaining) {
|
1999-10-17 19:21:43 +00:00
|
|
|
chaining = ISC_TRUE;
|
2001-02-19 08:54:54 +00:00
|
|
|
name->attributes |=
|
|
|
|
DNS_NAMEATTR_CHAINING;
|
1999-10-17 19:21:43 +00:00
|
|
|
rdataset->attributes |=
|
|
|
|
DNS_RDATASETATTR_CHAINING;
|
|
|
|
qname = &tname;
|
|
|
|
}
|
1999-10-11 19:24:28 +00:00
|
|
|
}
|
|
|
|
/*
|
|
|
|
* We could add an "else" clause here and
|
|
|
|
* log that we're ignoring this rdataset.
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/*
|
1999-10-18 21:05:49 +00:00
|
|
|
* Look for a DNAME (or its SIG). Anything else is
|
|
|
|
* ignored.
|
1999-10-11 19:24:28 +00:00
|
|
|
*/
|
1999-10-18 21:05:49 +00:00
|
|
|
for (rdataset = ISC_LIST_HEAD(name->list);
|
|
|
|
rdataset != NULL;
|
|
|
|
rdataset = ISC_LIST_NEXT(rdataset, link)) {
|
|
|
|
found = ISC_FALSE;
|
|
|
|
want_chaining = ISC_FALSE;
|
|
|
|
aflag = 0;
|
|
|
|
if (rdataset->type == dns_rdatatype_dname) {
|
|
|
|
/*
|
|
|
|
* We're looking for something else,
|
|
|
|
* but we found a DNAME.
|
|
|
|
*
|
|
|
|
* If we're not chaining, then the
|
|
|
|
* DNAME should not be external.
|
|
|
|
*/
|
|
|
|
if (!chaining && external)
|
|
|
|
return (DNS_R_FORMERR);
|
|
|
|
found = ISC_TRUE;
|
|
|
|
want_chaining = ISC_TRUE;
|
|
|
|
aflag = DNS_RDATASETATTR_ANSWER;
|
|
|
|
result = dname_target(rdataset,
|
|
|
|
qname, name,
|
|
|
|
&dname);
|
|
|
|
if (result == ISC_R_NOSPACE) {
|
|
|
|
/*
|
|
|
|
* We can't construct the
|
|
|
|
* DNAME target. Do not
|
|
|
|
* try to continue.
|
|
|
|
*/
|
|
|
|
want_chaining = ISC_FALSE;
|
|
|
|
} else if (result != ISC_R_SUCCESS)
|
|
|
|
return (result);
|
|
|
|
} else if (rdataset->type == dns_rdatatype_sig
|
|
|
|
&& rdataset->covers ==
|
|
|
|
dns_rdatatype_dname) {
|
|
|
|
/*
|
|
|
|
* We've found a signature that
|
|
|
|
* covers the DNAME.
|
|
|
|
*/
|
|
|
|
found = ISC_TRUE;
|
|
|
|
aflag = DNS_RDATASETATTR_ANSWERSIG;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (found) {
|
|
|
|
/*
|
|
|
|
* We've found an answer to our
|
|
|
|
* question.
|
|
|
|
*/
|
|
|
|
name->attributes |=
|
|
|
|
DNS_NAMEATTR_CACHE;
|
|
|
|
rdataset->attributes |=
|
|
|
|
DNS_RDATASETATTR_CACHE;
|
|
|
|
rdataset->trust = dns_trust_answer;
|
|
|
|
if (!chaining) {
|
|
|
|
/*
|
|
|
|
* This data is "the" answer
|
|
|
|
* to our question only if
|
|
|
|
* we're not chaining.
|
|
|
|
*/
|
|
|
|
INSIST(!external);
|
2000-10-13 18:55:11 +00:00
|
|
|
if (aflag ==
|
|
|
|
DNS_RDATASETATTR_ANSWER)
|
|
|
|
have_answer = ISC_TRUE;
|
1999-10-18 21:05:49 +00:00
|
|
|
name->attributes |=
|
|
|
|
DNS_NAMEATTR_ANSWER;
|
|
|
|
rdataset->attributes |= aflag;
|
|
|
|
if (aa)
|
|
|
|
rdataset->trust =
|
|
|
|
dns_trust_authanswer;
|
|
|
|
} else if (external) {
|
|
|
|
rdataset->attributes |=
|
|
|
|
DNS_RDATASETATTR_EXTERNAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* DNAME chaining.
|
|
|
|
*/
|
|
|
|
if (want_chaining) {
|
2000-10-13 18:55:11 +00:00
|
|
|
/*
|
|
|
|
* Copy the the dname into the
|
|
|
|
* qname fixed name.
|
|
|
|
*
|
|
|
|
* Although we check for
|
2001-02-18 21:19:43 +00:00
|
|
|
* failure of the copy
|
2000-10-13 18:55:11 +00:00
|
|
|
* operation, in practice it
|
|
|
|
* should never fail since
|
|
|
|
* we already know that the
|
|
|
|
* result fits in a fixedname.
|
|
|
|
*/
|
|
|
|
dns_fixedname_init(&fqname);
|
2001-01-03 00:05:15 +00:00
|
|
|
result = dns_name_copy(
|
2000-12-11 19:24:30 +00:00
|
|
|
dns_fixedname_name(&dname),
|
2000-10-13 18:55:11 +00:00
|
|
|
dns_fixedname_name(&fqname),
|
|
|
|
NULL);
|
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
return (result);
|
1999-10-18 21:05:49 +00:00
|
|
|
chaining = ISC_TRUE;
|
2001-02-19 08:54:54 +00:00
|
|
|
name->attributes |=
|
|
|
|
DNS_NAMEATTR_CHAINING;
|
1999-10-18 21:05:49 +00:00
|
|
|
rdataset->attributes |=
|
|
|
|
DNS_RDATASETATTR_CHAINING;
|
|
|
|
qname = dns_fixedname_name(
|
2000-10-13 18:55:11 +00:00
|
|
|
&fqname);
|
1999-10-18 21:05:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1999-10-11 19:24:28 +00:00
|
|
|
}
|
|
|
|
result = dns_message_nextname(message, DNS_SECTION_ANSWER);
|
|
|
|
}
|
2000-07-24 20:10:26 +00:00
|
|
|
if (result == ISC_R_NOMORE)
|
|
|
|
result = ISC_R_SUCCESS;
|
|
|
|
if (result != ISC_R_SUCCESS)
|
1999-10-11 19:24:28 +00:00
|
|
|
return (result);
|
|
|
|
|
1999-10-19 02:33:42 +00:00
|
|
|
/*
|
|
|
|
* We should have found an answer.
|
|
|
|
*/
|
|
|
|
if (!have_answer)
|
|
|
|
return (DNS_R_FORMERR);
|
|
|
|
|
1999-11-03 03:19:17 +00:00
|
|
|
/*
|
|
|
|
* This response is now potentially cacheable.
|
|
|
|
*/
|
|
|
|
fctx->attributes |= FCTX_ATTR_WANTCACHE;
|
|
|
|
|
1999-10-19 02:33:42 +00:00
|
|
|
/*
|
|
|
|
* Did chaining end before we got the final answer?
|
|
|
|
*/
|
|
|
|
if (want_chaining) {
|
|
|
|
/*
|
|
|
|
* Yes. This may be a negative reply, so hand off
|
|
|
|
* authority section processing to the noanswer code.
|
|
|
|
* If it isn't a noanswer response, no harm will be
|
|
|
|
* done.
|
|
|
|
*/
|
2001-09-14 21:04:35 +00:00
|
|
|
return (noanswer_response(fctx, qname, ISC_FALSE));
|
1999-10-19 02:33:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We didn't end with an incomplete chain, so the rcode should be
|
|
|
|
* "no error".
|
|
|
|
*/
|
|
|
|
if (message->rcode != dns_rcode_noerror)
|
|
|
|
return (DNS_R_FORMERR);
|
|
|
|
|
1999-10-11 19:24:28 +00:00
|
|
|
/*
|
|
|
|
* Examine the authority section (if there is one).
|
|
|
|
*
|
|
|
|
* We expect there to be only one owner name for all the rdatasets
|
|
|
|
* in this section, and we expect that it is not external.
|
|
|
|
*/
|
1999-10-16 20:34:04 +00:00
|
|
|
done = ISC_FALSE;
|
1999-10-11 19:24:28 +00:00
|
|
|
result = dns_message_firstname(message, DNS_SECTION_AUTHORITY);
|
|
|
|
while (!done && result == ISC_R_SUCCESS) {
|
|
|
|
name = NULL;
|
|
|
|
dns_message_currentname(message, DNS_SECTION_AUTHORITY, &name);
|
1999-10-29 12:56:58 +00:00
|
|
|
external = ISC_TF(!dns_name_issubdomain(name, &fctx->domain));
|
1999-10-11 19:24:28 +00:00
|
|
|
if (!external) {
|
|
|
|
/*
|
|
|
|
* We expect to find NS or SIG NS rdatasets, and
|
|
|
|
* nothing else.
|
|
|
|
*/
|
|
|
|
for (rdataset = ISC_LIST_HEAD(name->list);
|
|
|
|
rdataset != NULL;
|
|
|
|
rdataset = ISC_LIST_NEXT(rdataset, link)) {
|
|
|
|
if (rdataset->type == dns_rdatatype_ns ||
|
|
|
|
(rdataset->type == dns_rdatatype_sig &&
|
|
|
|
rdataset->covers == dns_rdatatype_ns)) {
|
1999-10-16 20:34:04 +00:00
|
|
|
name->attributes |=
|
|
|
|
DNS_NAMEATTR_CACHE;
|
1999-10-11 19:24:28 +00:00
|
|
|
rdataset->attributes |=
|
|
|
|
DNS_RDATASETATTR_CACHE;
|
1999-10-19 02:33:42 +00:00
|
|
|
if (aa && !chaining)
|
1999-10-11 19:24:28 +00:00
|
|
|
rdataset->trust =
|
|
|
|
dns_trust_authauthority;
|
|
|
|
else
|
|
|
|
rdataset->trust =
|
|
|
|
dns_trust_additional;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Mark any additional data related
|
|
|
|
* to this rdataset.
|
|
|
|
*/
|
|
|
|
(void)dns_rdataset_additionaldata(
|
|
|
|
rdataset,
|
|
|
|
check_related,
|
|
|
|
fctx);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Since we've found a non-external name in the
|
|
|
|
* authority section, we should stop looking, even
|
|
|
|
* if we didn't find any NS or SIG NS.
|
|
|
|
*/
|
|
|
|
done = ISC_TRUE;
|
|
|
|
}
|
|
|
|
result = dns_message_nextname(message, DNS_SECTION_AUTHORITY);
|
|
|
|
}
|
2000-07-24 20:10:26 +00:00
|
|
|
if (result == ISC_R_NOMORE)
|
|
|
|
result = ISC_R_SUCCESS;
|
1999-10-11 19:24:28 +00:00
|
|
|
|
2000-07-24 20:10:26 +00:00
|
|
|
return (result);
|
1999-10-11 19:24:28 +00:00
|
|
|
}
|
|
|
|
|
1999-06-28 23:37:54 +00:00
|
|
|
static void
|
1999-10-20 19:20:48 +00:00
|
|
|
resquery_response(isc_task_t *task, isc_event_t *event) {
|
1999-10-07 19:41:16 +00:00
|
|
|
isc_result_t result;
|
2000-04-17 19:21:30 +00:00
|
|
|
resquery_t *query = event->ev_arg;
|
1999-06-28 23:37:54 +00:00
|
|
|
dns_dispatchevent_t *devent = (dns_dispatchevent_t *)event;
|
1999-11-16 21:07:13 +00:00
|
|
|
isc_boolean_t keep_trying, broken_server, get_nameservers, resend;
|
|
|
|
isc_boolean_t truncated;
|
1999-06-28 23:37:54 +00:00
|
|
|
dns_message_t *message;
|
1999-07-24 01:26:18 +00:00
|
|
|
fetchctx_t *fctx;
|
1999-10-27 00:44:24 +00:00
|
|
|
dns_name_t *fname;
|
|
|
|
dns_fixedname_t foundname;
|
|
|
|
isc_stdtime_t now;
|
1999-11-05 09:50:52 +00:00
|
|
|
isc_time_t tnow, *finish;
|
1999-11-05 20:16:45 +00:00
|
|
|
dns_adbaddrinfo_t *addrinfo;
|
1999-11-16 21:07:13 +00:00
|
|
|
unsigned int options;
|
1999-06-28 23:37:54 +00:00
|
|
|
|
1999-07-24 01:26:18 +00:00
|
|
|
REQUIRE(VALID_QUERY(query));
|
|
|
|
fctx = query->fctx;
|
1999-11-16 21:07:13 +00:00
|
|
|
options = query->options;
|
1999-06-28 23:37:54 +00:00
|
|
|
REQUIRE(VALID_FCTX(fctx));
|
2000-04-17 19:21:30 +00:00
|
|
|
REQUIRE(event->ev_type == DNS_EVENT_DISPATCH);
|
1999-06-28 23:37:54 +00:00
|
|
|
|
2000-04-11 23:15:30 +00:00
|
|
|
UNUSED(task);
|
1999-07-24 01:26:18 +00:00
|
|
|
QTRACE("response");
|
1999-07-03 20:54:56 +00:00
|
|
|
|
1999-10-20 19:20:48 +00:00
|
|
|
(void)isc_timer_touch(fctx->timer);
|
|
|
|
|
1999-10-12 20:39:35 +00:00
|
|
|
keep_trying = ISC_FALSE;
|
|
|
|
broken_server = ISC_FALSE;
|
|
|
|
get_nameservers = ISC_FALSE;
|
1999-11-16 21:07:13 +00:00
|
|
|
resend = ISC_FALSE;
|
|
|
|
truncated = ISC_FALSE;
|
1999-11-05 09:50:52 +00:00
|
|
|
finish = NULL;
|
1999-10-12 20:39:35 +00:00
|
|
|
|
2001-11-14 01:01:28 +00:00
|
|
|
if (fctx->res->exiting) {
|
|
|
|
result = ISC_R_SHUTTINGDOWN;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2000-12-20 23:18:37 +00:00
|
|
|
fctx->timeouts = 0;
|
|
|
|
|
1999-11-05 09:50:52 +00:00
|
|
|
/*
|
|
|
|
* XXXRTH We should really get the current time just once. We
|
|
|
|
* need a routine to convert from an isc_time_t to an
|
|
|
|
* isc_stdtime_t.
|
|
|
|
*/
|
|
|
|
result = isc_time_now(&tnow);
|
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
goto done;
|
|
|
|
finish = &tnow;
|
1999-12-16 23:29:07 +00:00
|
|
|
isc_stdtime_get(&now);
|
1999-10-28 01:37:43 +00:00
|
|
|
|
2000-02-03 22:48:30 +00:00
|
|
|
/*
|
|
|
|
* Did the dispatcher have a problem?
|
|
|
|
*/
|
|
|
|
if (devent->result != ISC_R_SUCCESS) {
|
|
|
|
if (devent->result == ISC_R_EOF &&
|
|
|
|
(query->options & DNS_FETCHOPT_NOEDNS0) == 0) {
|
|
|
|
/*
|
|
|
|
* The problem might be that they
|
|
|
|
* don't understand EDNS0. Turn it
|
|
|
|
* off and try again.
|
|
|
|
*/
|
|
|
|
options |= DNS_FETCHOPT_NOEDNS0;
|
|
|
|
resend = ISC_TRUE;
|
|
|
|
/*
|
|
|
|
* Remember that they don't like EDNS0.
|
|
|
|
*/
|
2001-04-11 20:37:50 +00:00
|
|
|
dns_adb_changeflags(fctx->adb,
|
2000-02-03 22:48:30 +00:00
|
|
|
query->addrinfo,
|
|
|
|
DNS_FETCHOPT_NOEDNS0,
|
|
|
|
DNS_FETCHOPT_NOEDNS0);
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* There's no hope for this query.
|
|
|
|
*/
|
|
|
|
keep_trying = ISC_TRUE;
|
|
|
|
}
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
1999-07-03 20:54:56 +00:00
|
|
|
message = fctx->rmessage;
|
2000-03-03 19:48:14 +00:00
|
|
|
|
2000-05-30 23:14:57 +00:00
|
|
|
if (query->tsig != NULL) {
|
|
|
|
result = dns_message_setquerytsig(message, query->tsig);
|
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
goto done;
|
|
|
|
}
|
2000-03-03 19:48:14 +00:00
|
|
|
|
2000-11-22 23:16:04 +00:00
|
|
|
if (query->tsigkey) {
|
|
|
|
result = dns_message_settsigkey(message, query->tsigkey);
|
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2000-10-06 18:58:30 +00:00
|
|
|
result = dns_message_parse(message, &devent->buffer, 0);
|
1999-10-07 19:41:16 +00:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
1999-06-28 23:37:54 +00:00
|
|
|
switch (result) {
|
2000-04-06 22:03:35 +00:00
|
|
|
case ISC_R_UNEXPECTEDEND:
|
1999-11-16 21:07:13 +00:00
|
|
|
if (!message->question_ok ||
|
|
|
|
(message->flags & DNS_MESSAGEFLAG_TC) == 0 ||
|
|
|
|
(options & DNS_FETCHOPT_TCP) != 0) {
|
|
|
|
/*
|
|
|
|
* Either the message ended prematurely,
|
|
|
|
* and/or wasn't marked as being truncated,
|
|
|
|
* and/or this is a response to a query we
|
|
|
|
* sent over TCP. In all of these cases,
|
|
|
|
* something is wrong with the remote
|
|
|
|
* server and we don't want to retry using
|
|
|
|
* TCP.
|
|
|
|
*/
|
1999-11-30 20:57:05 +00:00
|
|
|
if ((query->options & DNS_FETCHOPT_NOEDNS0)
|
|
|
|
== 0) {
|
|
|
|
/*
|
|
|
|
* The problem might be that they
|
|
|
|
* don't understand EDNS0. Turn it
|
|
|
|
* off and try again.
|
|
|
|
*/
|
|
|
|
options |= DNS_FETCHOPT_NOEDNS0;
|
|
|
|
resend = ISC_TRUE;
|
|
|
|
/*
|
|
|
|
* Remember that they don't like EDNS0.
|
|
|
|
*/
|
|
|
|
dns_adb_changeflags(
|
2001-04-11 20:37:50 +00:00
|
|
|
fctx->adb,
|
1999-11-30 20:57:05 +00:00
|
|
|
query->addrinfo,
|
|
|
|
DNS_FETCHOPT_NOEDNS0,
|
|
|
|
DNS_FETCHOPT_NOEDNS0);
|
|
|
|
} else {
|
|
|
|
broken_server = ISC_TRUE;
|
|
|
|
keep_trying = ISC_TRUE;
|
|
|
|
}
|
1999-11-16 21:07:13 +00:00
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* We defer retrying via TCP for a bit so we can
|
|
|
|
* check out this message further.
|
|
|
|
*/
|
|
|
|
truncated = ISC_TRUE;
|
|
|
|
break;
|
|
|
|
case DNS_R_FORMERR:
|
2000-08-01 01:33:37 +00:00
|
|
|
if ((query->options & DNS_FETCHOPT_NOEDNS0) == 0) {
|
1999-11-30 20:57:05 +00:00
|
|
|
/*
|
|
|
|
* The problem might be that they
|
|
|
|
* don't understand EDNS0. Turn it
|
|
|
|
* off and try again.
|
|
|
|
*/
|
|
|
|
options |= DNS_FETCHOPT_NOEDNS0;
|
|
|
|
resend = ISC_TRUE;
|
|
|
|
/*
|
|
|
|
* Remember that they don't like EDNS0.
|
|
|
|
*/
|
2001-04-11 20:37:50 +00:00
|
|
|
dns_adb_changeflags(fctx->adb,
|
1999-11-30 20:57:05 +00:00
|
|
|
query->addrinfo,
|
|
|
|
DNS_FETCHOPT_NOEDNS0,
|
|
|
|
DNS_FETCHOPT_NOEDNS0);
|
|
|
|
} else {
|
|
|
|
broken_server = ISC_TRUE;
|
|
|
|
keep_trying = ISC_TRUE;
|
|
|
|
}
|
1999-11-16 21:07:13 +00:00
|
|
|
goto done;
|
1999-11-30 20:57:05 +00:00
|
|
|
default:
|
|
|
|
/*
|
|
|
|
* Something bad has happened.
|
|
|
|
*/
|
|
|
|
goto done;
|
1999-06-28 23:37:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-03-03 19:48:14 +00:00
|
|
|
/*
|
|
|
|
* If the message is signed, check the signature. If not, this
|
|
|
|
* returns success anyway.
|
|
|
|
*/
|
|
|
|
result = dns_message_checksig(message, fctx->res->view);
|
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
goto done;
|
|
|
|
|
1999-11-16 21:07:13 +00:00
|
|
|
/*
|
|
|
|
* The dispatcher should ensure we only get responses with QR set.
|
|
|
|
*/
|
1999-06-28 23:37:54 +00:00
|
|
|
INSIST((message->flags & DNS_MESSAGEFLAG_QR) != 0);
|
|
|
|
/*
|
|
|
|
* INSIST() that the message comes from the place we sent it to,
|
|
|
|
* since the dispatch code should ensure this.
|
|
|
|
*
|
2000-08-01 01:33:37 +00:00
|
|
|
* INSIST() that the message id is correct (this should also be
|
1999-06-28 23:37:54 +00:00
|
|
|
* ensured by the dispatch code).
|
|
|
|
*/
|
|
|
|
|
1999-11-16 21:07:13 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Deal with truncated responses by retrying using TCP.
|
|
|
|
*/
|
1999-12-10 17:31:08 +00:00
|
|
|
if ((message->flags & DNS_MESSAGEFLAG_TC) != 0)
|
|
|
|
truncated = ISC_TRUE;
|
2000-08-01 01:33:37 +00:00
|
|
|
|
1999-11-16 21:07:13 +00:00
|
|
|
if (truncated) {
|
1999-12-10 17:31:08 +00:00
|
|
|
if ((options & DNS_FETCHOPT_TCP) != 0) {
|
|
|
|
broken_server = ISC_TRUE;
|
|
|
|
keep_trying = ISC_TRUE;
|
|
|
|
} else {
|
|
|
|
options |= DNS_FETCHOPT_TCP;
|
|
|
|
resend = ISC_TRUE;
|
|
|
|
}
|
1999-11-16 21:07:13 +00:00
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
1999-06-28 23:37:54 +00:00
|
|
|
/*
|
|
|
|
* Is it a query response?
|
|
|
|
*/
|
|
|
|
if (message->opcode != dns_opcode_query) {
|
|
|
|
/* XXXRTH Log */
|
1999-10-11 19:24:28 +00:00
|
|
|
broken_server = ISC_TRUE;
|
|
|
|
keep_trying = ISC_TRUE;
|
1999-06-28 23:37:54 +00:00
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Is the remote server broken, or does it dislike us?
|
|
|
|
*/
|
|
|
|
if (message->rcode != dns_rcode_noerror &&
|
|
|
|
message->rcode != dns_rcode_nxdomain) {
|
2000-02-19 00:16:41 +00:00
|
|
|
if (message->rcode == dns_rcode_formerr) {
|
|
|
|
if ((query->options & DNS_FETCHOPT_NOEDNS0) == 0) {
|
|
|
|
/*
|
|
|
|
* It's very likely they don't like EDNS0.
|
|
|
|
*
|
|
|
|
* XXXRTH We should check if the question
|
|
|
|
* we're asking requires EDNS0, and
|
|
|
|
* if so, we should bail out.
|
|
|
|
*/
|
|
|
|
options |= DNS_FETCHOPT_NOEDNS0;
|
|
|
|
resend = ISC_TRUE;
|
|
|
|
/*
|
|
|
|
* Remember that they don't like EDNS0.
|
|
|
|
*/
|
2001-04-11 20:37:50 +00:00
|
|
|
dns_adb_changeflags(fctx->adb,
|
2000-02-19 00:16:41 +00:00
|
|
|
query->addrinfo,
|
|
|
|
DNS_FETCHOPT_NOEDNS0,
|
|
|
|
DNS_FETCHOPT_NOEDNS0);
|
|
|
|
} else if (ISFORWARDER(query->addrinfo)) {
|
|
|
|
/*
|
|
|
|
* This forwarder doesn't understand us,
|
|
|
|
* but other forwarders might. Keep trying.
|
|
|
|
*/
|
|
|
|
broken_server = ISC_TRUE;
|
|
|
|
keep_trying = ISC_TRUE;
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* The server doesn't understand us. Since
|
|
|
|
* all servers for a zone need similar
|
|
|
|
* capabilities, we assume that we will get
|
|
|
|
* FORMERR from all servers, and thus we
|
|
|
|
* cannot make any more progress with this
|
|
|
|
* fetch.
|
|
|
|
*/
|
|
|
|
result = DNS_R_FORMERR;
|
|
|
|
}
|
|
|
|
} else if (message->rcode == dns_rcode_yxdomain) {
|
1999-11-16 21:07:13 +00:00
|
|
|
/*
|
2000-02-19 00:16:41 +00:00
|
|
|
* DNAME mapping failed because the new name
|
|
|
|
* was too long. There's no chance of success
|
|
|
|
* for this fetch.
|
1999-11-16 21:07:13 +00:00
|
|
|
*/
|
2000-02-19 00:16:41 +00:00
|
|
|
result = DNS_R_YXDOMAIN;
|
1999-11-16 21:07:13 +00:00
|
|
|
} else {
|
1999-11-24 23:24:11 +00:00
|
|
|
/*
|
|
|
|
* XXXRTH log.
|
|
|
|
*/
|
1999-11-16 21:07:13 +00:00
|
|
|
broken_server = ISC_TRUE;
|
|
|
|
keep_trying = ISC_TRUE;
|
|
|
|
}
|
1999-06-28 23:37:54 +00:00
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
1999-09-22 19:45:09 +00:00
|
|
|
* Is the question the same as the one we asked?
|
1999-06-28 23:37:54 +00:00
|
|
|
*/
|
|
|
|
result = same_question(fctx);
|
1999-10-07 19:41:16 +00:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
1999-06-28 23:37:54 +00:00
|
|
|
/* XXXRTH Log */
|
1999-10-20 19:20:48 +00:00
|
|
|
if (result == DNS_R_FORMERR)
|
1999-10-11 19:24:28 +00:00
|
|
|
keep_trying = ISC_TRUE;
|
1999-06-28 23:37:54 +00:00
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2000-11-08 03:53:16 +00:00
|
|
|
/*
|
|
|
|
* Is the server lame?
|
|
|
|
*/
|
|
|
|
if (fctx->res->lame_ttl != 0 && !ISFORWARDER(query->addrinfo) &&
|
|
|
|
is_lame(fctx)) {
|
|
|
|
log_lame(fctx, query->addrinfo);
|
2001-04-11 20:37:50 +00:00
|
|
|
dns_adb_marklame(fctx->adb, query->addrinfo,
|
2000-11-08 03:53:16 +00:00
|
|
|
&fctx->domain, now + fctx->res->lame_ttl);
|
|
|
|
broken_server = ISC_TRUE;
|
|
|
|
keep_trying = ISC_TRUE;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
1999-10-07 19:41:16 +00:00
|
|
|
/*
|
|
|
|
* Did we get any answers?
|
|
|
|
*/
|
1999-10-11 19:24:28 +00:00
|
|
|
if (message->counts[DNS_SECTION_ANSWER] > 0 &&
|
1999-10-19 02:33:42 +00:00
|
|
|
(message->rcode == dns_rcode_noerror ||
|
|
|
|
message->rcode == dns_rcode_nxdomain)) {
|
1999-10-07 19:41:16 +00:00
|
|
|
/*
|
2001-09-14 21:04:35 +00:00
|
|
|
* We've got answers. However, if we sent
|
|
|
|
* a BIND 8 server an NS query, it may have
|
|
|
|
* incorrectly responded with a non-authoritative
|
|
|
|
* answer instead of a referral. Since this
|
|
|
|
* answer lacks the SIGs necessary to do DNSSEC
|
|
|
|
* validation, we must invoke the following special
|
|
|
|
* kludge to treat it as a referral.
|
1999-10-07 19:41:16 +00:00
|
|
|
*/
|
2001-09-14 21:04:35 +00:00
|
|
|
if (fctx->type == dns_rdatatype_ns &&
|
|
|
|
(message->flags & DNS_MESSAGEFLAG_AA) == 0 &&
|
|
|
|
!ISFORWARDER(query->addrinfo))
|
|
|
|
{
|
|
|
|
result = noanswer_response(fctx, NULL, ISC_TRUE);
|
|
|
|
if (result != DNS_R_DELEGATION) {
|
|
|
|
/*
|
|
|
|
* The answer section must have contained
|
|
|
|
* something other than the NS records
|
|
|
|
* we asked for. Since AA is not set
|
|
|
|
* and the server is not a forwarder,
|
|
|
|
* it is technically lame and it's easier
|
|
|
|
* to treat it as such than to figure out
|
|
|
|
* some more elaborate course of action.
|
|
|
|
*/
|
|
|
|
broken_server = ISC_TRUE;
|
|
|
|
keep_trying = ISC_TRUE;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
goto force_referral;
|
|
|
|
}
|
1999-10-11 19:24:28 +00:00
|
|
|
result = answer_response(fctx);
|
|
|
|
if (result != ISC_R_SUCCESS) {
|
|
|
|
if (result == DNS_R_FORMERR)
|
1999-10-20 19:20:48 +00:00
|
|
|
keep_trying = ISC_TRUE;
|
1999-10-11 19:24:28 +00:00
|
|
|
goto done;
|
|
|
|
}
|
1999-11-04 19:39:16 +00:00
|
|
|
} else if (message->counts[DNS_SECTION_AUTHORITY] > 0 ||
|
|
|
|
message->rcode == dns_rcode_noerror ||
|
|
|
|
message->rcode == dns_rcode_nxdomain) {
|
1999-10-07 19:41:16 +00:00
|
|
|
/*
|
|
|
|
* NXDOMAIN, NXRDATASET, or referral.
|
|
|
|
*/
|
2001-09-14 21:04:35 +00:00
|
|
|
result = noanswer_response(fctx, NULL, ISC_FALSE);
|
1999-10-12 20:39:35 +00:00
|
|
|
if (result == DNS_R_DELEGATION) {
|
2001-09-14 21:04:35 +00:00
|
|
|
force_referral:
|
1999-10-12 20:39:35 +00:00
|
|
|
/*
|
|
|
|
* We don't have the answer, but we know a better
|
|
|
|
* place to look.
|
|
|
|
*/
|
|
|
|
get_nameservers = ISC_TRUE;
|
|
|
|
keep_trying = ISC_TRUE;
|
2001-01-02 20:46:07 +00:00
|
|
|
/*
|
|
|
|
* We have a new set of name servers, and it
|
|
|
|
* has not experienced any restarts yet.
|
|
|
|
*/
|
|
|
|
fctx->restarts = 0;
|
1999-11-03 03:19:17 +00:00
|
|
|
result = ISC_R_SUCCESS;
|
|
|
|
} else if (result != ISC_R_SUCCESS) {
|
1999-10-16 00:48:34 +00:00
|
|
|
/*
|
|
|
|
* Something has gone wrong.
|
|
|
|
*/
|
1999-10-11 19:24:28 +00:00
|
|
|
if (result == DNS_R_FORMERR)
|
1999-10-20 19:20:48 +00:00
|
|
|
keep_trying = ISC_TRUE;
|
1999-10-11 19:24:28 +00:00
|
|
|
goto done;
|
|
|
|
}
|
1999-10-07 19:41:16 +00:00
|
|
|
} else {
|
|
|
|
/*
|
1999-10-11 19:24:28 +00:00
|
|
|
* The server is insane.
|
1999-10-07 19:41:16 +00:00
|
|
|
*/
|
|
|
|
/* XXXRTH Log */
|
1999-10-11 19:24:28 +00:00
|
|
|
broken_server = ISC_TRUE;
|
|
|
|
keep_trying = ISC_TRUE;
|
1999-10-07 19:41:16 +00:00
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
1999-10-20 19:20:48 +00:00
|
|
|
/*
|
|
|
|
* Cache the cacheable parts of the message. This may also cause
|
|
|
|
* work to be queued to the DNSSEC validator.
|
|
|
|
*/
|
1999-11-03 03:19:17 +00:00
|
|
|
if (WANTCACHE(fctx)) {
|
|
|
|
result = cache_message(fctx, now);
|
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Ncache the negatively cacheable parts of the message. This may
|
|
|
|
* also cause work to be queued to the DNSSEC validator.
|
|
|
|
*/
|
|
|
|
if (WANTNCACHE(fctx)) {
|
2000-05-04 16:38:09 +00:00
|
|
|
dns_rdatatype_t covers;
|
1999-11-03 03:19:17 +00:00
|
|
|
if (message->rcode == dns_rcode_nxdomain)
|
|
|
|
covers = dns_rdatatype_any;
|
|
|
|
else
|
|
|
|
covers = fctx->type;
|
2000-05-04 16:38:09 +00:00
|
|
|
|
1999-11-03 03:19:17 +00:00
|
|
|
/*
|
|
|
|
* Cache any negative cache entries in the message.
|
|
|
|
*/
|
|
|
|
result = ncache_message(fctx, covers, now);
|
|
|
|
}
|
1999-06-28 23:37:54 +00:00
|
|
|
|
|
|
|
done:
|
1999-11-05 20:16:45 +00:00
|
|
|
/*
|
|
|
|
* Remember the query's addrinfo, in case we need to mark the
|
|
|
|
* server as broken.
|
|
|
|
*/
|
|
|
|
addrinfo = query->addrinfo;
|
|
|
|
|
1999-06-28 23:37:54 +00:00
|
|
|
/*
|
1999-11-05 09:50:52 +00:00
|
|
|
* Cancel the query.
|
1999-12-13 22:30:55 +00:00
|
|
|
*
|
|
|
|
* XXXRTH Don't cancel the query if waiting for validation?
|
1999-10-20 19:20:48 +00:00
|
|
|
*/
|
1999-11-30 20:57:05 +00:00
|
|
|
fctx_cancelquery(&query, &devent, finish, ISC_FALSE);
|
1999-10-20 19:20:48 +00:00
|
|
|
|
1999-10-11 19:24:28 +00:00
|
|
|
if (keep_trying) {
|
1999-10-20 19:20:48 +00:00
|
|
|
if (result == DNS_R_FORMERR)
|
|
|
|
broken_server = ISC_TRUE;
|
1999-11-04 19:39:16 +00:00
|
|
|
if (broken_server) {
|
2000-02-11 03:06:56 +00:00
|
|
|
/*
|
|
|
|
* Add this server to the list of bad servers for
|
|
|
|
* this fctx.
|
|
|
|
*/
|
2000-06-01 00:30:58 +00:00
|
|
|
add_bad(fctx, &addrinfo->sockaddr);
|
1999-11-04 19:39:16 +00:00
|
|
|
}
|
|
|
|
|
1999-10-12 20:39:35 +00:00
|
|
|
if (get_nameservers) {
|
1999-10-27 00:44:24 +00:00
|
|
|
dns_fixedname_init(&foundname);
|
|
|
|
fname = dns_fixedname_name(&foundname);
|
|
|
|
if (result != ISC_R_SUCCESS) {
|
|
|
|
fctx_done(fctx, DNS_R_SERVFAIL);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
result = dns_view_findzonecut(fctx->res->view,
|
|
|
|
&fctx->domain,
|
|
|
|
fname,
|
|
|
|
now, 0, ISC_TRUE,
|
|
|
|
&fctx->nameservers,
|
|
|
|
NULL);
|
|
|
|
if (result != ISC_R_SUCCESS) {
|
2000-01-14 02:38:02 +00:00
|
|
|
FCTXTRACE("couldn't find a zonecut");
|
1999-10-27 00:44:24 +00:00
|
|
|
fctx_done(fctx, DNS_R_SERVFAIL);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!dns_name_issubdomain(fname, &fctx->domain)) {
|
|
|
|
/*
|
|
|
|
* The best nameservers are now above our
|
2000-02-14 23:19:45 +00:00
|
|
|
* QDOMAIN.
|
1999-10-27 00:44:24 +00:00
|
|
|
*/
|
2000-01-14 02:38:02 +00:00
|
|
|
FCTXTRACE("nameservers now above QDOMAIN");
|
1999-10-27 00:44:24 +00:00
|
|
|
fctx_done(fctx, DNS_R_SERVFAIL);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
dns_name_free(&fctx->domain, fctx->res->mctx);
|
|
|
|
dns_name_init(&fctx->domain, NULL);
|
|
|
|
result = dns_name_dup(fname, fctx->res->mctx,
|
|
|
|
&fctx->domain);
|
1999-10-25 21:19:54 +00:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
1999-10-12 20:39:35 +00:00
|
|
|
fctx_done(fctx, DNS_R_SERVFAIL);
|
1999-10-25 21:19:54 +00:00
|
|
|
return;
|
|
|
|
}
|
1999-11-30 20:57:05 +00:00
|
|
|
fctx_cancelqueries(fctx, ISC_TRUE);
|
1999-10-29 21:48:10 +00:00
|
|
|
fctx_cleanupfinds(fctx);
|
2000-01-12 02:59:48 +00:00
|
|
|
fctx_cleanupforwaddrs(fctx);
|
2000-08-01 01:33:37 +00:00
|
|
|
}
|
1999-06-28 23:37:54 +00:00
|
|
|
/*
|
1999-10-12 20:39:35 +00:00
|
|
|
* Try again.
|
1999-06-28 23:37:54 +00:00
|
|
|
*/
|
1999-07-03 20:54:56 +00:00
|
|
|
fctx_try(fctx);
|
1999-11-16 21:07:13 +00:00
|
|
|
} else if (resend) {
|
|
|
|
/*
|
|
|
|
* Resend (probably with changed options).
|
|
|
|
*/
|
|
|
|
FCTXTRACE("resend");
|
|
|
|
result = fctx_query(fctx, addrinfo, options);
|
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
fctx_done(fctx, result);
|
1999-10-25 21:19:54 +00:00
|
|
|
} else if (result == ISC_R_SUCCESS && !HAVE_ANSWER(fctx)) {
|
1999-10-20 19:20:48 +00:00
|
|
|
/*
|
|
|
|
* All has gone well so far, but we are waiting for the
|
|
|
|
* DNSSEC validator to validate the answer.
|
|
|
|
*/
|
2000-04-20 17:05:37 +00:00
|
|
|
FCTXTRACE("wait for validator");
|
1999-11-30 20:57:05 +00:00
|
|
|
fctx_cancelqueries(fctx, ISC_TRUE);
|
2000-04-20 17:05:37 +00:00
|
|
|
/*
|
|
|
|
* We must not retransmit while the validator is working;
|
|
|
|
* it has references to the current rmessage.
|
|
|
|
*/
|
1999-10-20 19:20:48 +00:00
|
|
|
result = fctx_stopidletimer(fctx);
|
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
fctx_done(fctx, result);
|
1999-06-28 23:37:54 +00:00
|
|
|
} else {
|
|
|
|
/*
|
1999-10-20 19:20:48 +00:00
|
|
|
* We're done.
|
1999-06-28 23:37:54 +00:00
|
|
|
*/
|
|
|
|
fctx_done(fctx, result);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***
|
|
|
|
*** Resolver Methods
|
|
|
|
***/
|
|
|
|
|
|
|
|
static void
|
|
|
|
destroy(dns_resolver_t *res) {
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
REQUIRE(res->references == 0);
|
2000-01-27 02:55:47 +00:00
|
|
|
REQUIRE(!res->priming);
|
|
|
|
REQUIRE(res->primefetch == NULL);
|
1999-06-28 23:37:54 +00:00
|
|
|
|
|
|
|
RTRACE("destroy");
|
|
|
|
|
2001-10-29 19:02:48 +00:00
|
|
|
INSIST(res->nfctx == 0);
|
|
|
|
|
2000-08-26 01:37:00 +00:00
|
|
|
DESTROYLOCK(&res->lock);
|
1999-10-07 19:41:16 +00:00
|
|
|
for (i = 0; i < res->nbuckets; i++) {
|
|
|
|
INSIST(ISC_LIST_EMPTY(res->buckets[i].fctxs));
|
|
|
|
isc_task_shutdown(res->buckets[i].task);
|
|
|
|
isc_task_detach(&res->buckets[i].task);
|
2000-08-26 01:37:00 +00:00
|
|
|
DESTROYLOCK(&res->buckets[i].lock);
|
1999-06-28 23:37:54 +00:00
|
|
|
}
|
1999-10-07 19:41:16 +00:00
|
|
|
isc_mem_put(res->mctx, res->buckets,
|
2001-11-12 19:05:39 +00:00
|
|
|
res->nbuckets * sizeof(fctxbucket_t));
|
2000-01-26 16:57:48 +00:00
|
|
|
if (res->dispatchv4 != NULL)
|
|
|
|
dns_dispatch_detach(&res->dispatchv4);
|
|
|
|
if (res->dispatchv6 != NULL)
|
|
|
|
dns_dispatch_detach(&res->dispatchv6);
|
1999-06-28 23:37:54 +00:00
|
|
|
res->magic = 0;
|
2001-11-12 19:05:39 +00:00
|
|
|
isc_mem_put(res->mctx, res, sizeof(*res));
|
1999-06-28 23:37:54 +00:00
|
|
|
}
|
|
|
|
|
1999-10-08 00:05:59 +00:00
|
|
|
static void
|
1999-11-22 19:57:17 +00:00
|
|
|
send_shutdown_events(dns_resolver_t *res) {
|
|
|
|
isc_event_t *event, *next_event;
|
|
|
|
isc_task_t *etask;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Caller must be holding the resolver lock.
|
|
|
|
*/
|
1999-10-08 00:05:59 +00:00
|
|
|
|
1999-11-22 19:57:17 +00:00
|
|
|
for (event = ISC_LIST_HEAD(res->whenshutdown);
|
|
|
|
event != NULL;
|
|
|
|
event = next_event) {
|
2000-04-17 19:21:30 +00:00
|
|
|
next_event = ISC_LIST_NEXT(event, ev_link);
|
|
|
|
ISC_LIST_UNLINK(res->whenshutdown, event, ev_link);
|
|
|
|
etask = event->ev_sender;
|
|
|
|
event->ev_sender = res;
|
1999-11-22 19:57:17 +00:00
|
|
|
isc_task_sendanddetach(&etask, &event);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
empty_bucket(dns_resolver_t *res) {
|
1999-10-08 00:05:59 +00:00
|
|
|
RTRACE("empty_bucket");
|
|
|
|
|
|
|
|
LOCK(&res->lock);
|
|
|
|
|
|
|
|
INSIST(res->activebuckets > 0);
|
|
|
|
res->activebuckets--;
|
|
|
|
if (res->activebuckets == 0)
|
1999-11-22 19:57:17 +00:00
|
|
|
send_shutdown_events(res);
|
1999-10-08 00:05:59 +00:00
|
|
|
|
|
|
|
UNLOCK(&res->lock);
|
|
|
|
}
|
|
|
|
|
1999-10-07 19:41:16 +00:00
|
|
|
isc_result_t
|
|
|
|
dns_resolver_create(dns_view_t *view,
|
1999-06-28 23:37:54 +00:00
|
|
|
isc_taskmgr_t *taskmgr, unsigned int ntasks,
|
1999-10-07 19:41:16 +00:00
|
|
|
isc_socketmgr_t *socketmgr,
|
|
|
|
isc_timermgr_t *timermgr,
|
2000-01-26 16:57:48 +00:00
|
|
|
unsigned int options,
|
2000-05-10 21:34:50 +00:00
|
|
|
dns_dispatchmgr_t *dispatchmgr,
|
2000-01-26 16:57:48 +00:00
|
|
|
dns_dispatch_t *dispatchv4,
|
|
|
|
dns_dispatch_t *dispatchv6,
|
|
|
|
dns_resolver_t **resp)
|
1999-06-28 23:37:54 +00:00
|
|
|
{
|
|
|
|
dns_resolver_t *res;
|
1999-10-07 19:41:16 +00:00
|
|
|
isc_result_t result = ISC_R_SUCCESS;
|
|
|
|
unsigned int i, buckets_created = 0;
|
2000-01-25 19:27:30 +00:00
|
|
|
char name[16];
|
1999-06-28 23:37:54 +00:00
|
|
|
|
1999-11-23 20:54:20 +00:00
|
|
|
/*
|
|
|
|
* Create a resolver.
|
|
|
|
*/
|
|
|
|
|
|
|
|
REQUIRE(DNS_VIEW_VALID(view));
|
1999-06-28 23:37:54 +00:00
|
|
|
REQUIRE(ntasks > 0);
|
1999-11-23 20:54:20 +00:00
|
|
|
REQUIRE(resp != NULL && *resp == NULL);
|
2000-05-10 21:34:50 +00:00
|
|
|
REQUIRE(dispatchmgr != NULL);
|
Merge the mlg-20000518 branch onto the mainline. Change summary:
dns_dispatch_create() no longer exists. dns_dispatch_createtcp()
and dns_dispatch_getudp() are the replacements. _createtcp() takes
a bound, connected TCP socket, while _getudp() will search for
a sharable UDP socket, and if found, attach to it and return a
pointer to it. If one is not found, it will create a udp socket,
bind it to a supplied local address, and create a new dispatcher
around it.
dns_dispatch_remove{request,response}() no longer take the dispatch
as an argument.
query-source can now be set per view.
The dispatch manager holds onto three memory pools, one for
allocating dispatchers from, one for events, and one for
requests/replies. The free list on these pools is hard-coded,
but set to 1024. This keeps us from having to dig into the
isc_mem_t the pools draw from as often.
dns_resolver_create() and dns_view_createresolver() require that
valid dispatchers be passed in; dispatchers are no longer created
for the caller.
2000-05-19 21:46:46 +00:00
|
|
|
REQUIRE(dispatchv4 != NULL || dispatchv6 != NULL);
|
1999-06-28 23:37:54 +00:00
|
|
|
|
2001-11-12 19:05:39 +00:00
|
|
|
res = isc_mem_get(view->mctx, sizeof(*res));
|
1999-06-28 23:37:54 +00:00
|
|
|
if (res == NULL)
|
1999-10-07 19:41:16 +00:00
|
|
|
return (ISC_R_NOMEMORY);
|
1999-06-28 23:37:54 +00:00
|
|
|
RTRACE("create");
|
1999-10-07 19:41:16 +00:00
|
|
|
res->mctx = view->mctx;
|
1999-09-22 19:45:09 +00:00
|
|
|
res->rdclass = view->rdclass;
|
1999-10-07 19:41:16 +00:00
|
|
|
res->socketmgr = socketmgr;
|
1999-06-28 23:37:54 +00:00
|
|
|
res->timermgr = timermgr;
|
Merge the mlg-20000518 branch onto the mainline. Change summary:
dns_dispatch_create() no longer exists. dns_dispatch_createtcp()
and dns_dispatch_getudp() are the replacements. _createtcp() takes
a bound, connected TCP socket, while _getudp() will search for
a sharable UDP socket, and if found, attach to it and return a
pointer to it. If one is not found, it will create a udp socket,
bind it to a supplied local address, and create a new dispatcher
around it.
dns_dispatch_remove{request,response}() no longer take the dispatch
as an argument.
query-source can now be set per view.
The dispatch manager holds onto three memory pools, one for
allocating dispatchers from, one for events, and one for
requests/replies. The free list on these pools is hard-coded,
but set to 1024. This keeps us from having to dig into the
isc_mem_t the pools draw from as often.
dns_resolver_create() and dns_view_createresolver() require that
valid dispatchers be passed in; dispatchers are no longer created
for the caller.
2000-05-19 21:46:46 +00:00
|
|
|
res->taskmgr = taskmgr;
|
2000-05-10 21:34:50 +00:00
|
|
|
res->dispatchmgr = dispatchmgr;
|
1999-09-22 19:45:09 +00:00
|
|
|
res->view = view;
|
2000-01-26 16:57:48 +00:00
|
|
|
res->options = options;
|
2000-11-08 03:53:16 +00:00
|
|
|
res->lame_ttl = 0;
|
1999-10-07 19:41:16 +00:00
|
|
|
|
|
|
|
res->nbuckets = ntasks;
|
1999-10-08 00:05:59 +00:00
|
|
|
res->activebuckets = ntasks;
|
1999-10-07 19:41:16 +00:00
|
|
|
res->buckets = isc_mem_get(view->mctx,
|
2001-11-12 19:05:39 +00:00
|
|
|
ntasks * sizeof(fctxbucket_t));
|
1999-10-07 19:41:16 +00:00
|
|
|
if (res->buckets == NULL) {
|
|
|
|
result = ISC_R_NOMEMORY;
|
1999-06-28 23:37:54 +00:00
|
|
|
goto cleanup_res;
|
|
|
|
}
|
|
|
|
for (i = 0; i < ntasks; i++) {
|
1999-10-07 19:41:16 +00:00
|
|
|
result = isc_mutex_init(&res->buckets[i].lock);
|
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
goto cleanup_buckets;
|
|
|
|
res->buckets[i].task = NULL;
|
2000-04-12 01:41:21 +00:00
|
|
|
result = isc_task_create(taskmgr, 0, &res->buckets[i].task);
|
1999-10-07 19:41:16 +00:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
2000-08-26 01:37:00 +00:00
|
|
|
DESTROYLOCK(&res->buckets[i].lock);
|
1999-10-07 19:41:16 +00:00
|
|
|
goto cleanup_buckets;
|
1999-06-28 23:37:54 +00:00
|
|
|
}
|
2000-01-25 19:27:30 +00:00
|
|
|
sprintf(name, "res%u", i);
|
|
|
|
isc_task_setname(res->buckets[i].task, name, res);
|
1999-10-07 19:41:16 +00:00
|
|
|
ISC_LIST_INIT(res->buckets[i].fctxs);
|
1999-10-08 00:05:59 +00:00
|
|
|
res->buckets[i].exiting = ISC_FALSE;
|
1999-10-07 19:41:16 +00:00
|
|
|
buckets_created++;
|
|
|
|
}
|
|
|
|
|
2000-01-26 16:57:48 +00:00
|
|
|
res->dispatchv4 = NULL;
|
Merge the mlg-20000518 branch onto the mainline. Change summary:
dns_dispatch_create() no longer exists. dns_dispatch_createtcp()
and dns_dispatch_getudp() are the replacements. _createtcp() takes
a bound, connected TCP socket, while _getudp() will search for
a sharable UDP socket, and if found, attach to it and return a
pointer to it. If one is not found, it will create a udp socket,
bind it to a supplied local address, and create a new dispatcher
around it.
dns_dispatch_remove{request,response}() no longer take the dispatch
as an argument.
query-source can now be set per view.
The dispatch manager holds onto three memory pools, one for
allocating dispatchers from, one for events, and one for
requests/replies. The free list on these pools is hard-coded,
but set to 1024. This keeps us from having to dig into the
isc_mem_t the pools draw from as often.
dns_resolver_create() and dns_view_createresolver() require that
valid dispatchers be passed in; dispatchers are no longer created
for the caller.
2000-05-19 21:46:46 +00:00
|
|
|
if (dispatchv4 != NULL)
|
2000-01-26 16:57:48 +00:00
|
|
|
dns_dispatch_attach(dispatchv4, &res->dispatchv4);
|
|
|
|
res->dispatchv6 = NULL;
|
Merge the mlg-20000518 branch onto the mainline. Change summary:
dns_dispatch_create() no longer exists. dns_dispatch_createtcp()
and dns_dispatch_getudp() are the replacements. _createtcp() takes
a bound, connected TCP socket, while _getudp() will search for
a sharable UDP socket, and if found, attach to it and return a
pointer to it. If one is not found, it will create a udp socket,
bind it to a supplied local address, and create a new dispatcher
around it.
dns_dispatch_remove{request,response}() no longer take the dispatch
as an argument.
query-source can now be set per view.
The dispatch manager holds onto three memory pools, one for
allocating dispatchers from, one for events, and one for
requests/replies. The free list on these pools is hard-coded,
but set to 1024. This keeps us from having to dig into the
isc_mem_t the pools draw from as often.
dns_resolver_create() and dns_view_createresolver() require that
valid dispatchers be passed in; dispatchers are no longer created
for the caller.
2000-05-19 21:46:46 +00:00
|
|
|
if (dispatchv6 != NULL)
|
2000-01-26 16:57:48 +00:00
|
|
|
dns_dispatch_attach(dispatchv6, &res->dispatchv6);
|
2000-01-12 02:59:48 +00:00
|
|
|
|
1999-06-28 23:37:54 +00:00
|
|
|
res->references = 1;
|
|
|
|
res->exiting = ISC_FALSE;
|
2000-01-12 02:59:48 +00:00
|
|
|
res->frozen = ISC_FALSE;
|
1999-11-22 19:57:17 +00:00
|
|
|
ISC_LIST_INIT(res->whenshutdown);
|
2000-01-27 02:55:47 +00:00
|
|
|
res->priming = ISC_FALSE;
|
|
|
|
res->primefetch = NULL;
|
2001-10-29 19:02:48 +00:00
|
|
|
res->nfctx = 0;
|
1999-06-28 23:37:54 +00:00
|
|
|
|
1999-10-07 19:41:16 +00:00
|
|
|
result = isc_mutex_init(&res->lock);
|
|
|
|
if (result != ISC_R_SUCCESS)
|
Merge the mlg-20000518 branch onto the mainline. Change summary:
dns_dispatch_create() no longer exists. dns_dispatch_createtcp()
and dns_dispatch_getudp() are the replacements. _createtcp() takes
a bound, connected TCP socket, while _getudp() will search for
a sharable UDP socket, and if found, attach to it and return a
pointer to it. If one is not found, it will create a udp socket,
bind it to a supplied local address, and create a new dispatcher
around it.
dns_dispatch_remove{request,response}() no longer take the dispatch
as an argument.
query-source can now be set per view.
The dispatch manager holds onto three memory pools, one for
allocating dispatchers from, one for events, and one for
requests/replies. The free list on these pools is hard-coded,
but set to 1024. This keeps us from having to dig into the
isc_mem_t the pools draw from as often.
dns_resolver_create() and dns_view_createresolver() require that
valid dispatchers be passed in; dispatchers are no longer created
for the caller.
2000-05-19 21:46:46 +00:00
|
|
|
goto cleanup_dispatches;
|
1999-06-28 23:37:54 +00:00
|
|
|
|
|
|
|
res->magic = RES_MAGIC;
|
2000-08-01 01:33:37 +00:00
|
|
|
|
1999-06-28 23:37:54 +00:00
|
|
|
*resp = res;
|
|
|
|
|
1999-10-07 19:41:16 +00:00
|
|
|
return (ISC_R_SUCCESS);
|
|
|
|
|
Merge the mlg-20000518 branch onto the mainline. Change summary:
dns_dispatch_create() no longer exists. dns_dispatch_createtcp()
and dns_dispatch_getudp() are the replacements. _createtcp() takes
a bound, connected TCP socket, while _getudp() will search for
a sharable UDP socket, and if found, attach to it and return a
pointer to it. If one is not found, it will create a udp socket,
bind it to a supplied local address, and create a new dispatcher
around it.
dns_dispatch_remove{request,response}() no longer take the dispatch
as an argument.
query-source can now be set per view.
The dispatch manager holds onto three memory pools, one for
allocating dispatchers from, one for events, and one for
requests/replies. The free list on these pools is hard-coded,
but set to 1024. This keeps us from having to dig into the
isc_mem_t the pools draw from as often.
dns_resolver_create() and dns_view_createresolver() require that
valid dispatchers be passed in; dispatchers are no longer created
for the caller.
2000-05-19 21:46:46 +00:00
|
|
|
cleanup_dispatches:
|
2000-01-26 16:57:48 +00:00
|
|
|
if (res->dispatchv6 != NULL)
|
|
|
|
dns_dispatch_detach(&res->dispatchv6);
|
|
|
|
if (res->dispatchv4 != NULL)
|
|
|
|
dns_dispatch_detach(&res->dispatchv4);
|
1999-10-07 19:41:16 +00:00
|
|
|
|
|
|
|
cleanup_buckets:
|
|
|
|
for (i = 0; i < buckets_created; i++) {
|
2000-08-26 01:37:00 +00:00
|
|
|
DESTROYLOCK(&res->buckets[i].lock);
|
1999-10-07 19:41:16 +00:00
|
|
|
isc_task_shutdown(res->buckets[i].task);
|
|
|
|
isc_task_detach(&res->buckets[i].task);
|
1999-06-28 23:37:54 +00:00
|
|
|
}
|
1999-10-07 19:41:16 +00:00
|
|
|
isc_mem_put(view->mctx, res->buckets,
|
2001-11-12 19:05:39 +00:00
|
|
|
res->nbuckets * sizeof(fctxbucket_t));
|
1999-06-28 23:37:54 +00:00
|
|
|
|
|
|
|
cleanup_res:
|
2001-11-12 19:05:39 +00:00
|
|
|
isc_mem_put(view->mctx, res, sizeof(*res));
|
1999-06-28 23:37:54 +00:00
|
|
|
|
|
|
|
return (result);
|
|
|
|
}
|
|
|
|
|
2000-01-27 02:55:47 +00:00
|
|
|
static void
|
|
|
|
prime_done(isc_task_t *task, isc_event_t *event) {
|
|
|
|
dns_resolver_t *res;
|
|
|
|
dns_fetchevent_t *fevent;
|
|
|
|
dns_fetch_t *fetch;
|
|
|
|
|
2000-04-17 19:21:30 +00:00
|
|
|
REQUIRE(event->ev_type == DNS_EVENT_FETCHDONE);
|
2000-01-27 02:55:47 +00:00
|
|
|
fevent = (dns_fetchevent_t *)event;
|
2000-04-17 19:21:30 +00:00
|
|
|
res = event->ev_arg;
|
2000-01-27 02:55:47 +00:00
|
|
|
REQUIRE(VALID_RESOLVER(res));
|
|
|
|
|
2000-04-11 23:15:30 +00:00
|
|
|
UNUSED(task);
|
2000-01-27 02:55:47 +00:00
|
|
|
|
|
|
|
LOCK(&res->lock);
|
|
|
|
|
|
|
|
INSIST(res->priming);
|
|
|
|
res->priming = ISC_FALSE;
|
|
|
|
fetch = res->primefetch;
|
|
|
|
res->primefetch = NULL;
|
|
|
|
|
|
|
|
UNLOCK(&res->lock);
|
|
|
|
|
|
|
|
if (fevent->node != NULL)
|
|
|
|
dns_db_detachnode(fevent->db, &fevent->node);
|
|
|
|
if (fevent->db != NULL)
|
|
|
|
dns_db_detach(&fevent->db);
|
|
|
|
if (dns_rdataset_isassociated(fevent->rdataset))
|
|
|
|
dns_rdataset_disassociate(fevent->rdataset);
|
|
|
|
INSIST(fevent->sigrdataset == NULL);
|
|
|
|
|
2001-11-12 19:05:39 +00:00
|
|
|
isc_mem_put(res->mctx, fevent->rdataset, sizeof(*fevent->rdataset));
|
2000-01-27 02:55:47 +00:00
|
|
|
|
|
|
|
isc_event_free(&event);
|
|
|
|
dns_resolver_destroyfetch(&fetch);
|
|
|
|
}
|
2000-08-01 01:33:37 +00:00
|
|
|
|
2000-01-27 02:55:47 +00:00
|
|
|
void
|
|
|
|
dns_resolver_prime(dns_resolver_t *res) {
|
|
|
|
isc_boolean_t want_priming = ISC_FALSE;
|
|
|
|
dns_fetch_t *fetch;
|
|
|
|
dns_rdataset_t *rdataset;
|
|
|
|
isc_result_t result;
|
|
|
|
|
|
|
|
REQUIRE(VALID_RESOLVER(res));
|
|
|
|
REQUIRE(res->frozen);
|
|
|
|
|
|
|
|
RTRACE("dns_resolver_prime");
|
|
|
|
|
|
|
|
LOCK(&res->lock);
|
2000-08-01 01:33:37 +00:00
|
|
|
|
2000-01-27 02:55:47 +00:00
|
|
|
if (!res->exiting && !res->priming) {
|
|
|
|
INSIST(res->primefetch == NULL);
|
|
|
|
res->priming = ISC_TRUE;
|
|
|
|
want_priming = ISC_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
UNLOCK(&res->lock);
|
|
|
|
|
|
|
|
if (want_priming) {
|
|
|
|
/*
|
|
|
|
* To avoid any possible recursive locking problems, we
|
|
|
|
* start the priming fetch like any other fetch, and holding
|
|
|
|
* no resolver locks. No one else will try to start it
|
|
|
|
* because we're the ones who set res->priming to true.
|
|
|
|
* Any other callers of dns_resolver_prime() while we're
|
|
|
|
* running will see that res->priming is already true and
|
|
|
|
* do nothing.
|
|
|
|
*/
|
|
|
|
RTRACE("priming");
|
2001-11-12 19:05:39 +00:00
|
|
|
rdataset = isc_mem_get(res->mctx, sizeof(*rdataset));
|
2000-01-27 02:55:47 +00:00
|
|
|
if (rdataset == NULL) {
|
|
|
|
LOCK(&res->lock);
|
|
|
|
INSIST(res->priming);
|
|
|
|
INSIST(res->primefetch == NULL);
|
|
|
|
res->priming = ISC_FALSE;
|
|
|
|
UNLOCK(&res->lock);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
dns_rdataset_init(rdataset);
|
|
|
|
fetch = NULL;
|
|
|
|
result = dns_resolver_createfetch(res, dns_rootname,
|
|
|
|
dns_rdatatype_ns,
|
|
|
|
NULL, NULL, NULL, 0,
|
|
|
|
res->buckets[0].task,
|
|
|
|
prime_done,
|
|
|
|
res, rdataset, NULL, &fetch);
|
|
|
|
LOCK(&res->lock);
|
|
|
|
INSIST(res->priming);
|
|
|
|
INSIST(res->primefetch == NULL);
|
|
|
|
if (result == ISC_R_SUCCESS)
|
|
|
|
res->primefetch = fetch;
|
|
|
|
else
|
|
|
|
res->priming = ISC_FALSE;
|
|
|
|
UNLOCK(&res->lock);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-01-12 02:59:48 +00:00
|
|
|
void
|
|
|
|
dns_resolver_freeze(dns_resolver_t *res) {
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Freeze resolver.
|
|
|
|
*/
|
|
|
|
|
|
|
|
REQUIRE(VALID_RESOLVER(res));
|
|
|
|
REQUIRE(!res->frozen);
|
|
|
|
|
|
|
|
res->frozen = ISC_TRUE;
|
|
|
|
}
|
|
|
|
|
1999-06-28 23:37:54 +00:00
|
|
|
void
|
|
|
|
dns_resolver_attach(dns_resolver_t *source, dns_resolver_t **targetp) {
|
|
|
|
REQUIRE(VALID_RESOLVER(source));
|
|
|
|
REQUIRE(targetp != NULL && *targetp == NULL);
|
|
|
|
|
|
|
|
RRTRACE(source, "attach");
|
|
|
|
LOCK(&source->lock);
|
|
|
|
REQUIRE(!source->exiting);
|
1999-10-08 00:05:59 +00:00
|
|
|
|
1999-06-28 23:37:54 +00:00
|
|
|
INSIST(source->references > 0);
|
|
|
|
source->references++;
|
|
|
|
INSIST(source->references != 0);
|
|
|
|
UNLOCK(&source->lock);
|
|
|
|
|
|
|
|
*targetp = source;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1999-11-22 19:57:17 +00:00
|
|
|
dns_resolver_whenshutdown(dns_resolver_t *res, isc_task_t *task,
|
|
|
|
isc_event_t **eventp)
|
|
|
|
{
|
|
|
|
isc_task_t *clone;
|
|
|
|
isc_event_t *event;
|
|
|
|
|
|
|
|
REQUIRE(VALID_RESOLVER(res));
|
|
|
|
REQUIRE(eventp != NULL);
|
|
|
|
|
|
|
|
event = *eventp;
|
|
|
|
*eventp = NULL;
|
|
|
|
|
|
|
|
LOCK(&res->lock);
|
2000-08-01 01:33:37 +00:00
|
|
|
|
1999-11-22 19:57:17 +00:00
|
|
|
if (res->exiting && res->activebuckets == 0) {
|
|
|
|
/*
|
|
|
|
* We're already shutdown. Send the event.
|
|
|
|
*/
|
2000-04-17 19:21:30 +00:00
|
|
|
event->ev_sender = res;
|
1999-11-22 19:57:17 +00:00
|
|
|
isc_task_send(task, &event);
|
|
|
|
} else {
|
|
|
|
clone = NULL;
|
|
|
|
isc_task_attach(task, &clone);
|
2000-04-17 19:21:30 +00:00
|
|
|
event->ev_sender = clone;
|
|
|
|
ISC_LIST_APPEND(res->whenshutdown, event, ev_link);
|
1999-11-22 19:57:17 +00:00
|
|
|
}
|
2000-08-01 01:33:37 +00:00
|
|
|
|
1999-11-22 19:57:17 +00:00
|
|
|
UNLOCK(&res->lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
dns_resolver_shutdown(dns_resolver_t *res) {
|
1999-10-08 00:05:59 +00:00
|
|
|
unsigned int i;
|
1999-11-22 19:57:17 +00:00
|
|
|
fetchctx_t *fctx;
|
Merge the mlg-20000518 branch onto the mainline. Change summary:
dns_dispatch_create() no longer exists. dns_dispatch_createtcp()
and dns_dispatch_getudp() are the replacements. _createtcp() takes
a bound, connected TCP socket, while _getudp() will search for
a sharable UDP socket, and if found, attach to it and return a
pointer to it. If one is not found, it will create a udp socket,
bind it to a supplied local address, and create a new dispatcher
around it.
dns_dispatch_remove{request,response}() no longer take the dispatch
as an argument.
query-source can now be set per view.
The dispatch manager holds onto three memory pools, one for
allocating dispatchers from, one for events, and one for
requests/replies. The free list on these pools is hard-coded,
but set to 1024. This keeps us from having to dig into the
isc_mem_t the pools draw from as often.
dns_resolver_create() and dns_view_createresolver() require that
valid dispatchers be passed in; dispatchers are no longer created
for the caller.
2000-05-19 21:46:46 +00:00
|
|
|
isc_socket_t *sock;
|
1999-06-28 23:37:54 +00:00
|
|
|
|
|
|
|
REQUIRE(VALID_RESOLVER(res));
|
|
|
|
|
1999-11-22 19:57:17 +00:00
|
|
|
RTRACE("shutdown");
|
2000-08-01 01:33:37 +00:00
|
|
|
|
1999-06-28 23:37:54 +00:00
|
|
|
LOCK(&res->lock);
|
1999-11-22 19:57:17 +00:00
|
|
|
|
|
|
|
if (!res->exiting) {
|
1999-06-28 23:37:54 +00:00
|
|
|
RTRACE("exiting");
|
|
|
|
res->exiting = ISC_TRUE;
|
1999-11-22 19:57:17 +00:00
|
|
|
|
1999-10-08 00:05:59 +00:00
|
|
|
for (i = 0; i < res->nbuckets; i++) {
|
|
|
|
LOCK(&res->buckets[i].lock);
|
1999-11-22 19:57:17 +00:00
|
|
|
for (fctx = ISC_LIST_HEAD(res->buckets[i].fctxs);
|
|
|
|
fctx != NULL;
|
|
|
|
fctx = ISC_LIST_NEXT(fctx, link))
|
|
|
|
fctx_shutdown(fctx);
|
Merge the mlg-20000518 branch onto the mainline. Change summary:
dns_dispatch_create() no longer exists. dns_dispatch_createtcp()
and dns_dispatch_getudp() are the replacements. _createtcp() takes
a bound, connected TCP socket, while _getudp() will search for
a sharable UDP socket, and if found, attach to it and return a
pointer to it. If one is not found, it will create a udp socket,
bind it to a supplied local address, and create a new dispatcher
around it.
dns_dispatch_remove{request,response}() no longer take the dispatch
as an argument.
query-source can now be set per view.
The dispatch manager holds onto three memory pools, one for
allocating dispatchers from, one for events, and one for
requests/replies. The free list on these pools is hard-coded,
but set to 1024. This keeps us from having to dig into the
isc_mem_t the pools draw from as often.
dns_resolver_create() and dns_view_createresolver() require that
valid dispatchers be passed in; dispatchers are no longer created
for the caller.
2000-05-19 21:46:46 +00:00
|
|
|
if (res->dispatchv4 != NULL) {
|
|
|
|
sock = dns_dispatch_getsocket(res->dispatchv4);
|
|
|
|
isc_socket_cancel(sock, res->buckets[i].task,
|
1999-10-08 00:05:59 +00:00
|
|
|
ISC_SOCKCANCEL_ALL);
|
Merge the mlg-20000518 branch onto the mainline. Change summary:
dns_dispatch_create() no longer exists. dns_dispatch_createtcp()
and dns_dispatch_getudp() are the replacements. _createtcp() takes
a bound, connected TCP socket, while _getudp() will search for
a sharable UDP socket, and if found, attach to it and return a
pointer to it. If one is not found, it will create a udp socket,
bind it to a supplied local address, and create a new dispatcher
around it.
dns_dispatch_remove{request,response}() no longer take the dispatch
as an argument.
query-source can now be set per view.
The dispatch manager holds onto three memory pools, one for
allocating dispatchers from, one for events, and one for
requests/replies. The free list on these pools is hard-coded,
but set to 1024. This keeps us from having to dig into the
isc_mem_t the pools draw from as often.
dns_resolver_create() and dns_view_createresolver() require that
valid dispatchers be passed in; dispatchers are no longer created
for the caller.
2000-05-19 21:46:46 +00:00
|
|
|
}
|
|
|
|
if (res->dispatchv6 != NULL) {
|
|
|
|
sock = dns_dispatch_getsocket(res->dispatchv6);
|
|
|
|
isc_socket_cancel(sock, res->buckets[i].task,
|
1999-10-08 00:05:59 +00:00
|
|
|
ISC_SOCKCANCEL_ALL);
|
Merge the mlg-20000518 branch onto the mainline. Change summary:
dns_dispatch_create() no longer exists. dns_dispatch_createtcp()
and dns_dispatch_getudp() are the replacements. _createtcp() takes
a bound, connected TCP socket, while _getudp() will search for
a sharable UDP socket, and if found, attach to it and return a
pointer to it. If one is not found, it will create a udp socket,
bind it to a supplied local address, and create a new dispatcher
around it.
dns_dispatch_remove{request,response}() no longer take the dispatch
as an argument.
query-source can now be set per view.
The dispatch manager holds onto three memory pools, one for
allocating dispatchers from, one for events, and one for
requests/replies. The free list on these pools is hard-coded,
but set to 1024. This keeps us from having to dig into the
isc_mem_t the pools draw from as often.
dns_resolver_create() and dns_view_createresolver() require that
valid dispatchers be passed in; dispatchers are no longer created
for the caller.
2000-05-19 21:46:46 +00:00
|
|
|
}
|
1999-10-08 00:05:59 +00:00
|
|
|
res->buckets[i].exiting = ISC_TRUE;
|
|
|
|
if (ISC_LIST_EMPTY(res->buckets[i].fctxs)) {
|
|
|
|
INSIST(res->activebuckets > 0);
|
|
|
|
res->activebuckets--;
|
|
|
|
}
|
|
|
|
UNLOCK(&res->buckets[i].lock);
|
|
|
|
}
|
|
|
|
if (res->activebuckets == 0)
|
1999-11-22 19:57:17 +00:00
|
|
|
send_shutdown_events(res);
|
1999-06-28 23:37:54 +00:00
|
|
|
}
|
1999-11-22 19:57:17 +00:00
|
|
|
|
|
|
|
UNLOCK(&res->lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
dns_resolver_detach(dns_resolver_t **resp) {
|
|
|
|
dns_resolver_t *res;
|
|
|
|
isc_boolean_t need_destroy = ISC_FALSE;
|
|
|
|
|
|
|
|
REQUIRE(resp != NULL);
|
|
|
|
res = *resp;
|
|
|
|
REQUIRE(VALID_RESOLVER(res));
|
|
|
|
|
|
|
|
RTRACE("detach");
|
|
|
|
|
|
|
|
LOCK(&res->lock);
|
|
|
|
|
|
|
|
INSIST(res->references > 0);
|
|
|
|
res->references--;
|
|
|
|
if (res->references == 0) {
|
|
|
|
INSIST(res->exiting && res->activebuckets == 0);
|
|
|
|
need_destroy = ISC_TRUE;
|
|
|
|
}
|
|
|
|
|
1999-06-28 23:37:54 +00:00
|
|
|
UNLOCK(&res->lock);
|
|
|
|
|
|
|
|
if (need_destroy)
|
|
|
|
destroy(res);
|
|
|
|
|
|
|
|
*resp = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline isc_boolean_t
|
|
|
|
fctx_match(fetchctx_t *fctx, dns_name_t *name, dns_rdatatype_t type,
|
|
|
|
unsigned int options)
|
|
|
|
{
|
|
|
|
if (fctx->type != type || fctx->options != options)
|
|
|
|
return (ISC_FALSE);
|
|
|
|
return (dns_name_equal(&fctx->name, name));
|
|
|
|
}
|
|
|
|
|
1999-11-03 19:56:47 +00:00
|
|
|
static inline void
|
|
|
|
log_fetch(dns_name_t *name, dns_rdatatype_t type) {
|
2001-01-02 18:51:07 +00:00
|
|
|
char namebuf[DNS_NAME_FORMATSIZE];
|
|
|
|
char typebuf[DNS_RDATATYPE_FORMATSIZE];
|
|
|
|
int level = ISC_LOG_DEBUG(1);
|
1999-11-03 19:56:47 +00:00
|
|
|
|
2001-01-02 18:51:07 +00:00
|
|
|
if (! isc_log_wouldlog(dns_lctx, level))
|
1999-11-03 19:56:47 +00:00
|
|
|
return;
|
2001-01-02 18:51:07 +00:00
|
|
|
|
|
|
|
dns_name_format(name, namebuf, sizeof(namebuf));
|
|
|
|
dns_rdatatype_format(type, typebuf, sizeof(typebuf));
|
|
|
|
|
1999-11-03 19:56:47 +00:00
|
|
|
isc_log_write(dns_lctx, DNS_LOGCATEGORY_RESOLVER,
|
2001-01-02 18:51:07 +00:00
|
|
|
DNS_LOGMODULE_RESOLVER, level,
|
|
|
|
"createfetch: %s %s", namebuf, typebuf);
|
1999-11-03 19:56:47 +00:00
|
|
|
}
|
|
|
|
|
1999-10-07 19:41:16 +00:00
|
|
|
isc_result_t
|
1999-06-28 23:37:54 +00:00
|
|
|
dns_resolver_createfetch(dns_resolver_t *res, dns_name_t *name,
|
|
|
|
dns_rdatatype_t type,
|
1999-07-24 01:26:18 +00:00
|
|
|
dns_name_t *domain, dns_rdataset_t *nameservers,
|
1999-06-28 23:37:54 +00:00
|
|
|
dns_forwarders_t *forwarders,
|
|
|
|
unsigned int options, isc_task_t *task,
|
|
|
|
isc_taskaction_t action, void *arg,
|
1999-10-07 19:41:16 +00:00
|
|
|
dns_rdataset_t *rdataset,
|
2000-08-01 01:33:37 +00:00
|
|
|
dns_rdataset_t *sigrdataset,
|
1999-06-28 23:37:54 +00:00
|
|
|
dns_fetch_t **fetchp)
|
|
|
|
{
|
|
|
|
dns_fetch_t *fetch;
|
|
|
|
fetchctx_t *fctx = NULL;
|
1999-10-07 19:41:16 +00:00
|
|
|
isc_result_t result;
|
|
|
|
unsigned int bucketnum;
|
|
|
|
isc_boolean_t new_fctx = ISC_FALSE;
|
|
|
|
isc_event_t *event;
|
1999-06-28 23:37:54 +00:00
|
|
|
|
2000-04-11 23:15:30 +00:00
|
|
|
UNUSED(forwarders);
|
1999-06-28 23:37:54 +00:00
|
|
|
|
|
|
|
REQUIRE(VALID_RESOLVER(res));
|
2000-01-12 02:59:48 +00:00
|
|
|
REQUIRE(res->frozen);
|
1999-11-23 20:54:20 +00:00
|
|
|
/* XXXRTH Check for meta type */
|
2000-01-18 02:49:03 +00:00
|
|
|
if (domain != NULL) {
|
|
|
|
REQUIRE(DNS_RDATASET_VALID(nameservers));
|
|
|
|
REQUIRE(nameservers->type == dns_rdatatype_ns);
|
|
|
|
} else
|
|
|
|
REQUIRE(nameservers == NULL);
|
1999-11-23 20:54:20 +00:00
|
|
|
REQUIRE(forwarders == NULL);
|
|
|
|
REQUIRE(!dns_rdataset_isassociated(rdataset));
|
|
|
|
REQUIRE(sigrdataset == NULL ||
|
|
|
|
!dns_rdataset_isassociated(sigrdataset));
|
1999-06-28 23:37:54 +00:00
|
|
|
REQUIRE(fetchp != NULL && *fetchp == NULL);
|
|
|
|
|
1999-11-03 19:56:47 +00:00
|
|
|
log_fetch(name, type);
|
1999-06-28 23:37:54 +00:00
|
|
|
|
1999-10-07 19:41:16 +00:00
|
|
|
/*
|
|
|
|
* XXXRTH use a mempool?
|
|
|
|
*/
|
2001-11-12 19:05:39 +00:00
|
|
|
fetch = isc_mem_get(res->mctx, sizeof(*fetch));
|
1999-06-28 23:37:54 +00:00
|
|
|
if (fetch == NULL)
|
1999-10-07 19:41:16 +00:00
|
|
|
return (ISC_R_NOMEMORY);
|
1999-06-28 23:37:54 +00:00
|
|
|
|
1999-10-07 19:41:16 +00:00
|
|
|
bucketnum = dns_name_hash(name, ISC_FALSE) % res->nbuckets;
|
1999-06-28 23:37:54 +00:00
|
|
|
|
1999-10-07 19:41:16 +00:00
|
|
|
LOCK(&res->buckets[bucketnum].lock);
|
1999-06-28 23:37:54 +00:00
|
|
|
|
1999-10-08 00:05:59 +00:00
|
|
|
if (res->buckets[bucketnum].exiting) {
|
|
|
|
result = ISC_R_SHUTTINGDOWN;
|
|
|
|
goto unlock;
|
|
|
|
}
|
|
|
|
|
1999-06-28 23:37:54 +00:00
|
|
|
if ((options & DNS_FETCHOPT_UNSHARED) == 0) {
|
1999-10-07 19:41:16 +00:00
|
|
|
for (fctx = ISC_LIST_HEAD(res->buckets[bucketnum].fctxs);
|
1999-06-28 23:37:54 +00:00
|
|
|
fctx != NULL;
|
|
|
|
fctx = ISC_LIST_NEXT(fctx, link)) {
|
|
|
|
if (fctx_match(fctx, name, type, options))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-01-03 20:31:34 +00:00
|
|
|
/*
|
|
|
|
* If we didn't have a fetch, would attach to a done fetch, this
|
|
|
|
* fetch has already cloned its results, or if the fetch has gone
|
|
|
|
* "idle" (no one was interested in it), we need to start a new
|
|
|
|
* fetch instead of joining with the existing one.
|
|
|
|
*/
|
|
|
|
if (fctx == NULL ||
|
|
|
|
fctx->state == fetchstate_done ||
|
|
|
|
fctx->cloned ||
|
|
|
|
ISC_LIST_EMPTY(fctx->events)) {
|
1999-10-07 19:41:16 +00:00
|
|
|
fctx = NULL;
|
|
|
|
result = fctx_create(res, name, type, domain, nameservers,
|
|
|
|
options, bucketnum, &fctx);
|
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
goto unlock;
|
|
|
|
new_fctx = ISC_TRUE;
|
|
|
|
}
|
2001-01-03 20:31:34 +00:00
|
|
|
|
1999-10-07 19:41:16 +00:00
|
|
|
result = fctx_join(fctx, task, action, arg,
|
|
|
|
rdataset, sigrdataset, fetch);
|
|
|
|
if (new_fctx) {
|
|
|
|
if (result == ISC_R_SUCCESS) {
|
|
|
|
/*
|
2000-07-29 01:18:36 +00:00
|
|
|
* Launch this fctx.
|
1999-10-07 19:41:16 +00:00
|
|
|
*/
|
|
|
|
event = &fctx->control_event;
|
2000-05-14 02:27:26 +00:00
|
|
|
ISC_EVENT_INIT(event, sizeof(*event), 0, NULL,
|
1999-10-07 19:41:16 +00:00
|
|
|
DNS_EVENT_FETCHCONTROL,
|
2000-07-29 01:18:36 +00:00
|
|
|
fctx_start, fctx, NULL,
|
1999-10-07 19:41:16 +00:00
|
|
|
NULL, NULL);
|
|
|
|
isc_task_send(res->buckets[bucketnum].task, &event);
|
1999-10-08 00:05:59 +00:00
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* We don't care about the result of fctx_destroy()
|
|
|
|
* since we know we're not exiting.
|
|
|
|
*/
|
|
|
|
(void)fctx_destroy(fctx);
|
|
|
|
}
|
1999-10-07 19:41:16 +00:00
|
|
|
}
|
1999-06-28 23:37:54 +00:00
|
|
|
|
1999-10-07 19:41:16 +00:00
|
|
|
unlock:
|
|
|
|
UNLOCK(&res->buckets[bucketnum].lock);
|
1999-06-28 23:37:54 +00:00
|
|
|
|
1999-10-07 19:41:16 +00:00
|
|
|
if (result == ISC_R_SUCCESS) {
|
1999-06-28 23:37:54 +00:00
|
|
|
FTRACE("created");
|
|
|
|
*fetchp = fetch;
|
|
|
|
} else
|
2001-11-12 19:05:39 +00:00
|
|
|
isc_mem_put(res->mctx, fetch, sizeof(*fetch));
|
1999-06-28 23:37:54 +00:00
|
|
|
|
|
|
|
return (result);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2000-01-21 02:47:30 +00:00
|
|
|
dns_resolver_cancelfetch(dns_fetch_t *fetch) {
|
1999-06-28 23:37:54 +00:00
|
|
|
fetchctx_t *fctx;
|
2000-01-21 02:47:30 +00:00
|
|
|
dns_resolver_t *res;
|
1999-10-20 01:57:05 +00:00
|
|
|
dns_fetchevent_t *event, *next_event;
|
1999-06-28 23:37:54 +00:00
|
|
|
isc_task_t *etask;
|
|
|
|
|
|
|
|
REQUIRE(DNS_FETCH_VALID(fetch));
|
|
|
|
fctx = fetch->private;
|
2000-01-14 02:38:02 +00:00
|
|
|
REQUIRE(VALID_FCTX(fctx));
|
2000-01-21 02:47:30 +00:00
|
|
|
res = fctx->res;
|
1999-06-28 23:37:54 +00:00
|
|
|
|
1999-10-20 01:57:05 +00:00
|
|
|
FTRACE("cancelfetch");
|
1999-06-28 23:37:54 +00:00
|
|
|
|
1999-10-07 19:41:16 +00:00
|
|
|
LOCK(&res->buckets[fctx->bucketnum].lock);
|
1999-06-28 23:37:54 +00:00
|
|
|
|
2000-06-16 01:16:39 +00:00
|
|
|
/*
|
|
|
|
* Find the completion event for this fetch (as opposed
|
|
|
|
* to those for other fetches that have joined the same
|
|
|
|
* fctx) and send it with result = ISC_R_CANCELED.
|
|
|
|
*/
|
1999-06-28 23:37:54 +00:00
|
|
|
event = NULL;
|
|
|
|
if (fctx->state != fetchstate_done) {
|
|
|
|
for (event = ISC_LIST_HEAD(fctx->events);
|
|
|
|
event != NULL;
|
|
|
|
event = next_event) {
|
2000-04-17 19:21:30 +00:00
|
|
|
next_event = ISC_LIST_NEXT(event, ev_link);
|
1999-10-20 01:57:05 +00:00
|
|
|
if (event->fetch == fetch) {
|
2000-04-17 19:21:30 +00:00
|
|
|
ISC_LIST_UNLINK(fctx->events, event, ev_link);
|
1999-06-28 23:37:54 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
1999-10-07 19:41:16 +00:00
|
|
|
}
|
|
|
|
if (event != NULL) {
|
2000-04-17 19:21:30 +00:00
|
|
|
etask = event->ev_sender;
|
|
|
|
event->ev_sender = fctx;
|
1999-10-07 19:41:16 +00:00
|
|
|
event->result = ISC_R_CANCELED;
|
|
|
|
isc_task_sendanddetach(&etask, (isc_event_t **)&event);
|
|
|
|
}
|
2000-06-16 01:16:39 +00:00
|
|
|
/*
|
|
|
|
* The fctx continues running even if no fetches remain;
|
|
|
|
* the answer is still cached.
|
|
|
|
*/
|
1999-06-28 23:37:54 +00:00
|
|
|
|
1999-10-20 01:57:05 +00:00
|
|
|
UNLOCK(&res->buckets[fctx->bucketnum].lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2000-01-21 02:47:30 +00:00
|
|
|
dns_resolver_destroyfetch(dns_fetch_t **fetchp) {
|
1999-10-20 01:57:05 +00:00
|
|
|
dns_fetch_t *fetch;
|
2000-01-21 02:47:30 +00:00
|
|
|
dns_resolver_t *res;
|
1999-10-20 01:57:05 +00:00
|
|
|
dns_fetchevent_t *event, *next_event;
|
|
|
|
fetchctx_t *fctx;
|
1999-11-22 19:57:17 +00:00
|
|
|
unsigned int bucketnum;
|
|
|
|
isc_boolean_t bucket_empty = ISC_FALSE;
|
1999-10-20 01:57:05 +00:00
|
|
|
|
|
|
|
REQUIRE(fetchp != NULL);
|
|
|
|
fetch = *fetchp;
|
|
|
|
REQUIRE(DNS_FETCH_VALID(fetch));
|
|
|
|
fctx = fetch->private;
|
2000-01-14 02:38:02 +00:00
|
|
|
REQUIRE(VALID_FCTX(fctx));
|
2000-01-21 02:47:30 +00:00
|
|
|
res = fctx->res;
|
1999-10-20 01:57:05 +00:00
|
|
|
|
|
|
|
FTRACE("destroyfetch");
|
|
|
|
|
1999-11-22 19:57:17 +00:00
|
|
|
bucketnum = fctx->bucketnum;
|
|
|
|
LOCK(&res->buckets[bucketnum].lock);
|
1999-10-20 01:57:05 +00:00
|
|
|
|
|
|
|
/*
|
1999-11-22 19:57:17 +00:00
|
|
|
* Sanity check: the caller should have gotten its event before
|
|
|
|
* trying to destroy the fetch.
|
1999-10-20 01:57:05 +00:00
|
|
|
*/
|
|
|
|
event = NULL;
|
|
|
|
if (fctx->state != fetchstate_done) {
|
|
|
|
for (event = ISC_LIST_HEAD(fctx->events);
|
|
|
|
event != NULL;
|
|
|
|
event = next_event) {
|
2000-04-17 19:21:30 +00:00
|
|
|
next_event = ISC_LIST_NEXT(event, ev_link);
|
1999-10-20 01:57:05 +00:00
|
|
|
RUNTIME_CHECK(event->fetch != fetch);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-06-28 23:37:54 +00:00
|
|
|
INSIST(fctx->references > 0);
|
|
|
|
fctx->references--;
|
|
|
|
if (fctx->references == 0) {
|
1999-10-07 19:41:16 +00:00
|
|
|
/*
|
|
|
|
* No one cares about the result of this fetch anymore.
|
|
|
|
*/
|
2000-08-15 00:21:05 +00:00
|
|
|
if (fctx->pending == 0 && ISC_LIST_EMPTY(fctx->validators) &&
|
2000-01-06 00:56:18 +00:00
|
|
|
SHUTTINGDOWN(fctx)) {
|
1999-11-22 19:57:17 +00:00
|
|
|
/*
|
|
|
|
* This fctx is already shutdown; we were just
|
|
|
|
* waiting for the last reference to go away.
|
|
|
|
*/
|
|
|
|
bucket_empty = fctx_destroy(fctx);
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* Initiate shutdown.
|
|
|
|
*/
|
|
|
|
fctx_shutdown(fctx);
|
1999-06-28 23:37:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-11-22 19:57:17 +00:00
|
|
|
UNLOCK(&res->buckets[bucketnum].lock);
|
1999-06-28 23:37:54 +00:00
|
|
|
|
2001-11-12 19:05:39 +00:00
|
|
|
isc_mem_put(res->mctx, fetch, sizeof(*fetch));
|
1999-06-29 07:03:17 +00:00
|
|
|
*fetchp = NULL;
|
1999-11-22 19:57:17 +00:00
|
|
|
|
|
|
|
if (bucket_empty)
|
|
|
|
empty_bucket(res);
|
1999-09-02 01:59:19 +00:00
|
|
|
}
|
2000-04-18 08:30:24 +00:00
|
|
|
|
2000-05-10 21:34:50 +00:00
|
|
|
dns_dispatchmgr_t *
|
|
|
|
dns_resolver_dispatchmgr(dns_resolver_t *resolver) {
|
|
|
|
REQUIRE(VALID_RESOLVER(resolver));
|
|
|
|
return (resolver->dispatchmgr);
|
|
|
|
}
|
|
|
|
|
2000-04-18 08:30:24 +00:00
|
|
|
dns_dispatch_t *
|
|
|
|
dns_resolver_dispatchv4(dns_resolver_t *resolver) {
|
|
|
|
REQUIRE(VALID_RESOLVER(resolver));
|
|
|
|
return (resolver->dispatchv4);
|
|
|
|
}
|
|
|
|
|
|
|
|
dns_dispatch_t *
|
|
|
|
dns_resolver_dispatchv6(dns_resolver_t *resolver) {
|
|
|
|
REQUIRE(VALID_RESOLVER(resolver));
|
|
|
|
return (resolver->dispatchv6);
|
|
|
|
}
|
|
|
|
|
|
|
|
isc_socketmgr_t *
|
|
|
|
dns_resolver_socketmgr(dns_resolver_t *resolver) {
|
|
|
|
REQUIRE(VALID_RESOLVER(resolver));
|
|
|
|
return (resolver->socketmgr);
|
|
|
|
}
|
Merge the mlg-20000518 branch onto the mainline. Change summary:
dns_dispatch_create() no longer exists. dns_dispatch_createtcp()
and dns_dispatch_getudp() are the replacements. _createtcp() takes
a bound, connected TCP socket, while _getudp() will search for
a sharable UDP socket, and if found, attach to it and return a
pointer to it. If one is not found, it will create a udp socket,
bind it to a supplied local address, and create a new dispatcher
around it.
dns_dispatch_remove{request,response}() no longer take the dispatch
as an argument.
query-source can now be set per view.
The dispatch manager holds onto three memory pools, one for
allocating dispatchers from, one for events, and one for
requests/replies. The free list on these pools is hard-coded,
but set to 1024. This keeps us from having to dig into the
isc_mem_t the pools draw from as often.
dns_resolver_create() and dns_view_createresolver() require that
valid dispatchers be passed in; dispatchers are no longer created
for the caller.
2000-05-19 21:46:46 +00:00
|
|
|
|
|
|
|
isc_taskmgr_t *
|
|
|
|
dns_resolver_taskmgr(dns_resolver_t *resolver) {
|
|
|
|
REQUIRE(VALID_RESOLVER(resolver));
|
|
|
|
return (resolver->taskmgr);
|
|
|
|
}
|
2000-11-08 03:53:16 +00:00
|
|
|
|
|
|
|
isc_uint32_t
|
|
|
|
dns_resolver_getlamettl(dns_resolver_t *resolver) {
|
|
|
|
REQUIRE(VALID_RESOLVER(resolver));
|
|
|
|
return (resolver->lame_ttl);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
dns_resolver_setlamettl(dns_resolver_t *resolver, isc_uint32_t lame_ttl) {
|
|
|
|
REQUIRE(VALID_RESOLVER(resolver));
|
|
|
|
resolver->lame_ttl = lame_ttl;
|
|
|
|
}
|
2001-10-29 19:02:48 +00:00
|
|
|
|
|
|
|
unsigned int
|
|
|
|
dns_resolver_nrunning(dns_resolver_t *resolver) {
|
|
|
|
unsigned int n;
|
|
|
|
LOCK(&resolver->lock);
|
|
|
|
n = resolver->nfctx;
|
|
|
|
UNLOCK(&resolver->lock);
|
|
|
|
return (n);
|
|
|
|
}
|