aboutsummaryrefslogtreecommitdiff
path: root/contrib/bind9/lib/dns/resolver.c
diff options
context:
space:
mode:
authorDoug Barton <dougb@FreeBSD.org>2005-03-17 08:04:02 +0000
committerDoug Barton <dougb@FreeBSD.org>2005-03-17 08:04:02 +0000
commit6bc6438a36e1c5d65a4752b125d5fb5cf8015879 (patch)
tree56538def4af42f6875185c84274a942bf33b5d24 /contrib/bind9/lib/dns/resolver.c
parent8e4912ed0640ee7da1e4372381213ceb13023eee (diff)
downloadsrc-6bc6438a36e1c5d65a4752b125d5fb5cf8015879.tar.gz
src-6bc6438a36e1c5d65a4752b125d5fb5cf8015879.zip
Vendor import of BIND 9.3.1
Notes
Notes: svn path=/vendor/bind9/dist/; revision=143731
Diffstat (limited to 'contrib/bind9/lib/dns/resolver.c')
-rw-r--r--contrib/bind9/lib/dns/resolver.c162
1 files changed, 133 insertions, 29 deletions
diff --git a/contrib/bind9/lib/dns/resolver.c b/contrib/bind9/lib/dns/resolver.c
index c76631a2bbf1..90af5b020e7b 100644
--- a/contrib/bind9/lib/dns/resolver.c
+++ b/contrib/bind9/lib/dns/resolver.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2004 Internet Systems Consortium, Inc. ("ISC")
+ * Copyright (C) 2004, 2005 Internet Systems Consortium, Inc. ("ISC")
* Copyright (C) 1999-2003 Internet Software Consortium.
*
* Permission to use, copy, modify, and distribute this software for any
@@ -15,7 +15,7 @@
* PERFORMANCE OF THIS SOFTWARE.
*/
-/* $Id: resolver.c,v 1.218.2.18.4.43 2004/08/28 06:25:19 marka Exp $ */
+/* $Id: resolver.c,v 1.218.2.18.4.51 2005/02/08 23:59:44 marka Exp $ */
#include <config.h>
@@ -524,7 +524,7 @@ fctx_cancelquery(resquery_t **queryp, dns_dispatchevent_t **deventp,
*/
INSIST(no_response);
rtt = query->addrinfo->srtt +
- (100000 * fctx->restarts);
+ (200000 * fctx->restarts);
if (rtt > 10000000)
rtt = 10000000;
/*
@@ -762,6 +762,9 @@ static void
resquery_senddone(isc_task_t *task, isc_event_t *event) {
isc_socketevent_t *sevent = (isc_socketevent_t *)event;
resquery_t *query = event->ev_arg;
+ isc_boolean_t retry = ISC_FALSE;
+ isc_result_t result;
+ fetchctx_t *fctx;
REQUIRE(event->ev_type == ISC_SOCKEVENT_SENDDONE);
@@ -780,6 +783,7 @@ resquery_senddone(isc_task_t *task, isc_event_t *event) {
INSIST(RESQUERY_SENDING(query));
query->sends--;
+ fctx = query->fctx;
if (RESQUERY_CANCELED(query)) {
if (query->sends == 0) {
@@ -791,10 +795,43 @@ resquery_senddone(isc_task_t *task, isc_event_t *event) {
isc_socket_detach(&query->tcpsocket);
resquery_destroy(&query);
}
- } else if (sevent->result != ISC_R_SUCCESS)
- fctx_cancelquery(&query, NULL, NULL, ISC_FALSE);
+ } else
+ switch (sevent->result) {
+ case ISC_R_SUCCESS:
+ break;
+
+ case ISC_R_HOSTUNREACH:
+ case ISC_R_NETUNREACH:
+ case ISC_R_NOPERM:
+ case ISC_R_ADDRNOTAVAIL:
+ case ISC_R_CONNREFUSED:
+
+ /*
+ * No route to remote.
+ */
+ fctx_cancelquery(&query, NULL, NULL, ISC_TRUE);
+ retry = ISC_TRUE;
+ break;
+
+ default:
+ fctx_cancelquery(&query, NULL, NULL, ISC_FALSE);
+ break;
+ }
isc_event_free(&event);
+
+ if (retry) {
+ /*
+ * Behave as if the idle timer has expired. For TCP
+ * this may not actually reflect the latest timer.
+ */
+ fctx->attributes &= ~FCTX_ATTR_ADDRWAIT;
+ result = fctx_stopidletimer(fctx);
+ if (result != ISC_R_SUCCESS)
+ fctx_done(fctx, result);
+ else
+ fctx_try(fctx);
+ }
}
static inline isc_result_t
@@ -1311,7 +1348,10 @@ static void
resquery_connected(isc_task_t *task, isc_event_t *event) {
isc_socketevent_t *sevent = (isc_socketevent_t *)event;
resquery_t *query = event->ev_arg;
+ isc_boolean_t retry = ISC_FALSE;
isc_result_t result;
+ unsigned int attrs;
+ fetchctx_t *fctx;
REQUIRE(event->ev_type == ISC_SOCKEVENT_CONNECT);
REQUIRE(VALID_QUERY(query));
@@ -1329,6 +1369,7 @@ resquery_connected(isc_task_t *task, isc_event_t *event) {
*/
query->connects--;
+ fctx = query->fctx;
if (RESQUERY_CANCELED(query)) {
/*
@@ -1338,9 +1379,8 @@ resquery_connected(isc_task_t *task, isc_event_t *event) {
isc_socket_detach(&query->tcpsocket);
resquery_destroy(&query);
} else {
- if (sevent->result == ISC_R_SUCCESS) {
- unsigned int attrs;
-
+ switch (sevent->result) {
+ case ISC_R_SUCCESS:
/*
* We are connected. Create a dispatcher and
* send the query.
@@ -1373,22 +1413,48 @@ resquery_connected(isc_task_t *task, isc_event_t *event) {
result = resquery_send(query);
if (result != ISC_R_SUCCESS) {
- fetchctx_t *fctx = query->fctx;
fctx_cancelquery(&query, NULL, NULL,
ISC_FALSE);
fctx_done(fctx, result);
}
- } else {
+ break;
+
+ case ISC_R_NETUNREACH:
+ case ISC_R_HOSTUNREACH:
+ case ISC_R_CONNREFUSED:
+ case ISC_R_NOPERM:
+ case ISC_R_ADDRNOTAVAIL:
+ /*
+ * No route to remote.
+ */
+ isc_socket_detach(&query->tcpsocket);
+ fctx_cancelquery(&query, NULL, NULL, ISC_TRUE);
+ retry = ISC_TRUE;
+ break;
+
+ default:
isc_socket_detach(&query->tcpsocket);
fctx_cancelquery(&query, NULL, NULL, ISC_FALSE);
+ break;
}
}
isc_event_free(&event);
+
+ if (retry) {
+ /*
+ * Behave as if the idle timer has expired. For TCP
+ * connections this may not actually reflect the latest timer.
+ */
+ fctx->attributes &= ~FCTX_ATTR_ADDRWAIT;
+ result = fctx_stopidletimer(fctx);
+ if (result != ISC_R_SUCCESS)
+ fctx_done(fctx, result);
+ else
+ fctx_try(fctx);
+ }
}
-
-
static void
fctx_finddone(isc_task_t *task, isc_event_t *event) {
fetchctx_t *fctx;
@@ -3519,6 +3585,14 @@ cache_name(fetchctx_t *fctx, dns_name_t *name, isc_stdtime_t now) {
fctx->validators,
validator, link);
}
+ } else if (CHAINING(rdataset)) {
+ if (rdataset->type == dns_rdatatype_cname)
+ eresult = DNS_R_CNAME;
+ else {
+ INSIST(rdataset->type ==
+ dns_rdatatype_dname);
+ eresult = DNS_R_DNAME;
+ }
}
} else if (!EXTERNAL(rdataset)) {
/*
@@ -4127,7 +4201,7 @@ noanswer_response(fetchctx_t *fctx, dns_name_t *oqname,
dns_message_currentname(message, section, &name);
if (dns_name_issubdomain(name, &fctx->domain)) {
/*
- * Look for NS RRset first.
+ * Look for NS/SOA RRsets first.
*/
for (rdataset = ISC_LIST_HEAD(name->list);
rdataset != NULL;
@@ -4141,7 +4215,7 @@ noanswer_response(fetchctx_t *fctx, dns_name_t *oqname,
return (DNS_R_FORMERR);
if (type == dns_rdatatype_ns) {
/*
- * NS or SIG NS.
+ * NS or RRSIG NS.
*
* Only one set of NS RRs is allowed.
*/
@@ -4159,17 +4233,9 @@ noanswer_response(fetchctx_t *fctx, dns_name_t *oqname,
DNS_RDATASETATTR_CACHE;
rdataset->trust = dns_trust_glue;
}
- }
- for (rdataset = ISC_LIST_HEAD(name->list);
- rdataset != NULL;
- rdataset = ISC_LIST_NEXT(rdataset, link)) {
- type = rdataset->type;
- if (type == dns_rdatatype_rrsig)
- type = rdataset->covers;
- if (type == dns_rdatatype_soa ||
- type == dns_rdatatype_nsec) {
+ if (type == dns_rdatatype_soa) {
/*
- * SOA, RRSIG SOA, NSEC, or RRSIG NSEC.
+ * SOA, or RRSIG SOA.
*
* Only one SOA is allowed.
*/
@@ -4180,8 +4246,38 @@ noanswer_response(fetchctx_t *fctx, dns_name_t *oqname,
return (DNS_R_FORMERR);
soa_name = name;
}
- if (ns_name == NULL) {
- 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;
+ }
+ }
+ /*
+ * A negative response has a SOA record (Type 2)
+ * and a optional NS RRset (Type 1) or it has neither
+ * a SOA or a NS RRset (Type 3, handled above) or
+ * rcode is NXDOMAIN (handled above) in which case
+ * the NS RRset is allowed (Type 4).
+ */
+ if (soa_name != NULL)
+ negative_response = ISC_TRUE;
+ for (rdataset = ISC_LIST_HEAD(name->list);
+ rdataset != NULL;
+ rdataset = ISC_LIST_NEXT(rdataset, link)) {
+ type = rdataset->type;
+ if (type == dns_rdatatype_rrsig)
+ type = rdataset->covers;
+ if (type == dns_rdatatype_nsec) {
+ /*
+ * NSEC or RRSIG NSEC.
+ */
+ if (negative_response) {
name->attributes |=
DNS_NAMEATTR_NCACHE;
rdataset->attributes |=
@@ -4210,7 +4306,7 @@ noanswer_response(fetchctx_t *fctx, dns_name_t *oqname,
* this is a referral, and there
* should only be one DS.
*/
- if (negative_response)
+ if (ns_name == NULL)
return (DNS_R_FORMERR);
if (rdataset->type ==
dns_rdatatype_ds) {
@@ -5229,10 +5325,15 @@ resquery_response(isc_task_t *task, isc_event_t *event) {
domainbuf, namebuf, typebuf, classbuf, addrbuf);
}
- if ((fctx->res->options | DNS_RESOLVER_CHECKNAMES) != 0)
+ if ((fctx->res->options & DNS_RESOLVER_CHECKNAMES) != 0)
checknames(message);
/*
+ * Clear cache bits.
+ */
+ fctx->attributes &= ~(FCTX_ATTR_WANTNCACHE | FCTX_ATTR_WANTCACHE);
+
+ /*
* Did we get any answers?
*/
if (message->counts[DNS_SECTION_ANSWER] > 0 &&
@@ -5380,13 +5481,16 @@ resquery_response(isc_task_t *task, isc_event_t *event) {
return;
}
findoptions = 0;
+ if (dns_rdatatype_atparent(fctx->type))
+ findoptions |= DNS_DBFIND_NOEXACT;
if ((options & DNS_FETCHOPT_UNSHARED) == 0)
name = &fctx->name;
else
name = &fctx->domain;
result = dns_view_findzonecut(fctx->res->view,
name, fname,
- now, 0, ISC_TRUE,
+ now, findoptions,
+ ISC_TRUE,
&fctx->nameservers,
NULL);
if (result != ISC_R_SUCCESS) {