Commit 13090db2 authored by Brian Wellington's avatar Brian Wellington
Browse files

dns_view_find can now do ANY queries; it takes additional db and node

parameters used for return values.
parent 2a80a4e1
......@@ -15,7 +15,7 @@
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/* $Id: adb.c,v 1.160 2000/12/18 20:03:33 gson Exp $ */
/* $Id: adb.c,v 1.161 2000/12/20 03:38:41 bwelling Exp $ */
/*
* Implementation notes
......@@ -3155,7 +3155,7 @@ dbfind_name(dns_adbname_t *adbname, isc_stdtime_t now, dns_rdatatype_t rdtype)
result = dns_view_find(adb->view, &adbname->name, rdtype, now,
NAME_GLUEOK(adbname),
ISC_TF(NAME_HINTOK(adbname)),
fname, &rdataset, NULL);
NULL, NULL, fname, &rdataset, NULL);
switch (result) {
case DNS_R_GLUE:
......@@ -3287,7 +3287,7 @@ dbfind_a6(dns_adbname_t *adbname, isc_stdtime_t now) {
result = dns_view_find(adb->view, &adbname->name, dns_rdatatype_a6,
now, NAME_GLUEOK(adbname),
ISC_TF(NAME_HINTOK(adbname)),
fname, &rdataset, NULL);
NULL, NULL, fname, &rdataset, NULL);
switch (result) {
case DNS_R_GLUE:
......
......@@ -15,7 +15,7 @@
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/* $Id: lookup.h,v 1.3 2000/11/02 00:55:41 bwelling Exp $ */
/* $Id: lookup.h,v 1.4 2000/12/20 03:38:45 bwelling Exp $ */
#ifndef DNS_LOOKUP_H
#define DNS_LOOKUP_H 1
......@@ -69,6 +69,8 @@ typedef struct dns_lookupevent {
dns_name_t *name;
dns_rdataset_t *rdataset;
dns_rdataset_t *sigrdataset;
dns_db_t *db;
dns_dbnode_t *node;
} dns_lookupevent_t;
isc_result_t
......
......@@ -15,7 +15,7 @@
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/* $Id: view.h,v 1.59 2000/12/15 21:11:36 gson Exp $ */
/* $Id: view.h,v 1.60 2000/12/20 03:38:46 bwelling Exp $ */
#ifndef DNS_VIEW_H
#define DNS_VIEW_H 1
......@@ -377,8 +377,8 @@ dns_view_freeze(dns_view_t *view);
isc_result_t
dns_view_find(dns_view_t *view, dns_name_t *name, dns_rdatatype_t type,
isc_stdtime_t now, unsigned int options,
isc_boolean_t use_hints, dns_name_t *foundname,
isc_stdtime_t now, unsigned int options, isc_boolean_t use_hints,
dns_db_t **dbp, dns_dbnode_t **nodep, dns_name_t *foundname,
dns_rdataset_t *rdataset, dns_rdataset_t *sigrdataset);
/*
* Find an rdataset whose owner name is 'name', and whose type is
......@@ -408,9 +408,13 @@ dns_view_find(dns_view_t *view, dns_name_t *name, dns_rdatatype_t type,
* 'name' is valid name.
*
* 'type' is a valid dns_rdatatype_t, and is not a meta query type
* (e.g. dns_rdatatype_any), or dns_rdatatype_sig.
* except dns_rdatatype_any.
*
* dbp == NULL || *dbp == NULL
*
* nodep == NULL || *nodep == NULL. If nodep != NULL, dbp != NULL.
*
* 'foundname' is
* 'foundname' is a valid name with a dedicated buffer or NULL.
*
* 'rdataset' is a valid, disassociated rdataset.
*
......@@ -421,6 +425,12 @@ dns_view_find(dns_view_t *view, dns_name_t *name, dns_rdatatype_t type,
* In successful cases, 'rdataset', and possibly 'sigrdataset', are
* bound to the found data.
*
* If dbp != NULL, it points to the database containing the data.
*
* If nodep != NULL, it points to the database node containing the data.
*
* If foundname != NULL, it contains the full name of the found data.
*
* Returns:
*
* Any result that dns_db_find() can return, with the exception of
......
......@@ -15,7 +15,7 @@
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/* $Id: lookup.c,v 1.5 2000/12/11 19:24:10 bwelling Exp $ */
/* $Id: lookup.c,v 1.6 2000/12/20 03:38:42 bwelling Exp $ */
#include <config.h>
......@@ -116,13 +116,15 @@ build_event(dns_lookup_t *lookup) {
if (result != ISC_R_SUCCESS)
goto fail;
rdataset = isc_mem_get(lookup->mctx, sizeof(dns_rdataset_t));
if (rdataset == NULL) {
result = ISC_R_NOMEMORY;
goto fail;
if (dns_rdataset_isassociated(&lookup->rdataset)) {
rdataset = isc_mem_get(lookup->mctx, sizeof(dns_rdataset_t));
if (rdataset == NULL) {
result = ISC_R_NOMEMORY;
goto fail;
}
dns_rdataset_init(rdataset);
dns_rdataset_clone(&lookup->rdataset, rdataset);
}
dns_rdataset_init(rdataset);
dns_rdataset_clone(&lookup->rdataset, rdataset);
if (dns_rdataset_isassociated(&lookup->sigrdataset)) {
sigrdataset = isc_mem_get(lookup->mctx,
......@@ -160,6 +162,24 @@ build_event(dns_lookup_t *lookup) {
return (result);
}
static isc_result_t
view_find(dns_lookup_t *lookup, dns_name_t *foundname) {
isc_result_t result;
dns_name_t *name = dns_fixedname_name(&lookup->name);
dns_rdatatype_t type;
if (lookup->type == dns_rdatatype_sig)
type = dns_rdatatype_any;
else
type = lookup->type;
result = dns_view_find(lookup->view, name, type, 0, 0, ISC_FALSE,
&lookup->event->db, &lookup->event->node,
foundname, &lookup->rdataset,
&lookup->sigrdataset);
return (result);
}
static void
lookup_find(dns_lookup_t *lookup, dns_fetchevent_t *event) {
isc_result_t result;
......@@ -191,16 +211,19 @@ lookup_find(dns_lookup_t *lookup, dns_fetchevent_t *event) {
INSIST(!dns_rdataset_isassociated(&lookup->rdataset));
INSIST(!dns_rdataset_isassociated
(&lookup->sigrdataset));
result = dns_view_find(lookup->view, name,
lookup->type, 0, 0,
ISC_FALSE, fname,
&lookup->rdataset,
&lookup->sigrdataset);
result = view_find(lookup, fname);
if (result == ISC_R_NOTFOUND) {
/*
* We don't know anything about the name.
* Launch a fetch.
*/
if (lookup->event->node != NULL) {
INSIST(lookup->event->db != NULL);
dns_db_detachnode(lookup->event->db,
&lookup->event->node);
}
if (lookup->event->db != NULL)
dns_db_detach(&lookup->event->db);
result = start_fetch(lookup);
if (result != ISC_R_SUCCESS)
send_event = ISC_TRUE;
......@@ -212,14 +235,6 @@ lookup_find(dns_lookup_t *lookup, dns_fetchevent_t *event) {
dns_resolver_destroyfetch(&lookup->fetch);
INSIST(event->rdataset == &lookup->rdataset);
INSIST(event->sigrdataset == &lookup->sigrdataset);
/*
* Detach (if necessary) from things we know we
* don't care about.
*/
if (event->node != NULL)
dns_db_detachnode(event->db, &event->node);
if (event->db != NULL)
dns_db_detach(&event->db);
}
/*
......@@ -232,6 +247,14 @@ lookup_find(dns_lookup_t *lookup, dns_fetchevent_t *event) {
case ISC_R_SUCCESS:
result = build_event(lookup);
send_event = ISC_TRUE;
if (event == NULL)
break;
if (event->db != NULL)
dns_db_attach(event->db, &lookup->event->db);
if (event->node != NULL)
dns_db_attachnode(lookup->event->db,
event->node,
&lookup->event->node);
break;
case DNS_R_CNAME:
/*
......@@ -294,8 +317,13 @@ lookup_find(dns_lookup_t *lookup, dns_fetchevent_t *event) {
if (dns_rdataset_isassociated(&lookup->sigrdataset))
dns_rdataset_disassociate(&lookup->sigrdataset);
if (event != NULL)
if (event != NULL) {
if (event->node != NULL)
dns_db_detachnode(event->db, &event->node);
if (event->db != NULL)
dns_db_detach(&event->db);
isc_event_free((isc_event_t **)&event);
}
/*
* Limit the number of restarts.
......@@ -341,6 +369,10 @@ levent_destroy(isc_event_t *event) {
dns_rdataset_disassociate(levent->sigrdataset);
isc_mem_put(mctx, levent->sigrdataset, sizeof(dns_rdataset_t));
}
if (levent->node != NULL)
dns_db_detachnode(levent->db, &levent->node);
if (levent->db != NULL)
dns_db_detach(&levent->db);
isc_mem_put(mctx, event, event->ev_size);
}
......@@ -373,6 +405,8 @@ dns_lookup_create(isc_mem_t *mctx, dns_name_t *name, dns_rdatatype_t type,
lookup->event->name = NULL;
lookup->event->rdataset = NULL;
lookup->event->sigrdataset = NULL;
lookup->event->db = NULL;
lookup->event->node = NULL;
lookup->task = NULL;
isc_task_attach(task, &lookup->task);
......
......@@ -15,7 +15,7 @@
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/* $Id: view.c,v 1.87 2000/12/15 21:11:35 gson Exp $ */
/* $Id: view.c,v 1.88 2000/12/20 03:38:43 bwelling Exp $ */
#include <config.h>
......@@ -611,12 +611,13 @@ dns_view_findzone(dns_view_t *view, dns_name_t *name, dns_zone_t **zonep) {
isc_result_t
dns_view_find(dns_view_t *view, dns_name_t *name, dns_rdatatype_t type,
isc_stdtime_t now, unsigned int options,
isc_boolean_t use_hints, dns_name_t *foundname,
isc_stdtime_t now, unsigned int options, isc_boolean_t use_hints,
dns_db_t **dbp, dns_dbnode_t **nodep, dns_name_t *foundname,
dns_rdataset_t *rdataset, dns_rdataset_t *sigrdataset)
{
isc_result_t result;
dns_db_t *db;
dns_db_t *db, *zdb;
dns_dbnode_t *node, *znode;
isc_boolean_t is_cache;
dns_rdataset_t zrdataset, zsigrdataset;
dns_zone_t *zone;
......@@ -628,19 +629,23 @@ dns_view_find(dns_view_t *view, dns_name_t *name, dns_rdatatype_t type,
REQUIRE(DNS_VIEW_VALID(view));
REQUIRE(view->frozen);
REQUIRE(type != dns_rdatatype_any && type != dns_rdatatype_sig);
REQUIRE(type != dns_rdatatype_sig);
REQUIRE(rdataset != NULL); /* XXXBEW - remove this */
/*
* Initialize.
*/
dns_rdataset_init(&zrdataset);
dns_rdataset_init(&zsigrdataset);
zdb = NULL;
znode = NULL;
/*
* Find a database to answer the query.
*/
zone = NULL;
db = NULL;
node = NULL;
result = dns_zt_find(view->zonetable, name, 0, NULL, &zone);
if (result == ISC_R_SUCCESS || result == DNS_R_PARTIALMATCH) {
result = dns_zone_getdb(zone, &db);
......@@ -660,7 +665,7 @@ dns_view_find(dns_view_t *view, dns_name_t *name, dns_rdatatype_t type,
* Now look for an answer in the database.
*/
result = dns_db_find(db, name, NULL, type, options,
now, NULL, foundname, rdataset, sigrdataset);
now, &node, foundname, rdataset, sigrdataset);
if (result == DNS_R_DELEGATION ||
result == ISC_R_NOTFOUND) {
......@@ -669,14 +674,16 @@ dns_view_find(dns_view_t *view, dns_name_t *name, dns_rdatatype_t type,
if (sigrdataset != NULL &&
dns_rdataset_isassociated(sigrdataset))
dns_rdataset_disassociate(sigrdataset);
if (node != NULL)
dns_db_detachnode(db, &node);
if (!is_cache) {
dns_db_detach(&db);
if (view->cachedb != NULL) {
/*
* Either the answer is in the cache, or we
* don't know it.
*/
is_cache = ISC_TRUE;
dns_db_detach(&db);
dns_db_attach(view->cachedb, &db);
goto db_find;
}
......@@ -692,6 +699,10 @@ dns_view_find(dns_view_t *view, dns_name_t *name, dns_rdatatype_t type,
dns_rdataset_clone(&zsigrdataset,
sigrdataset);
result = DNS_R_GLUE;
if (db != NULL)
dns_db_detach(&db);
dns_db_attach(zdb, &db);
dns_db_attachnode(db, znode, &node);
goto cleanup;
}
}
......@@ -713,6 +724,9 @@ dns_view_find(dns_view_t *view, dns_name_t *name, dns_rdatatype_t type,
dns_rdataset_clone(sigrdataset, &zsigrdataset);
dns_rdataset_disassociate(sigrdataset);
}
dns_db_attach(db, &zdb);
dns_db_attachnode(zdb, node, &znode);
dns_db_detachnode(db, &node);
dns_db_detach(&db);
dns_db_attach(view->cachedb, &db);
goto db_find;
......@@ -729,8 +743,13 @@ dns_view_find(dns_view_t *view, dns_name_t *name, dns_rdatatype_t type,
if (sigrdataset != NULL &&
dns_rdataset_isassociated(sigrdataset))
dns_rdataset_disassociate(sigrdataset);
if (db != NULL) {
if (node != NULL)
dns_db_detachnode(db, &node);
dns_db_detach(&db);
}
result = dns_db_find(view->hints, name, NULL, type, options,
now, NULL, foundname,
now, &node, foundname,
rdataset, sigrdataset);
if (result == ISC_R_SUCCESS || result == DNS_R_GLUE) {
/*
......@@ -738,6 +757,7 @@ dns_view_find(dns_view_t *view, dns_name_t *name, dns_rdatatype_t type,
* should consider priming.
*/
dns_resolver_prime(view->resolver);
dns_db_attach(view->hints, &db);
result = DNS_R_HINT;
} else if (result == DNS_R_NXDOMAIN ||
result == DNS_R_NXRRSET)
......@@ -761,8 +781,26 @@ dns_view_find(dns_view_t *view, dns_name_t *name, dns_rdatatype_t type,
if (dns_rdataset_isassociated(&zsigrdataset))
dns_rdataset_disassociate(&zsigrdataset);
}
if (db != NULL)
dns_db_detach(&db);
if (zdb != NULL) {
if (znode != NULL)
dns_db_detachnode(zdb, &znode);
dns_db_detach(&zdb);
}
if (db != NULL) {
if (node != NULL) {
if (nodep != NULL)
*nodep = node;
else
dns_db_detachnode(db, &node);
}
if (dbp != NULL)
*dbp = db;
else
dns_db_detach(&db);
}
if (zone != NULL)
dns_zone_detach(&zone);
......@@ -780,7 +818,7 @@ dns_view_simplefind(dns_view_t *view, dns_name_t *name, dns_rdatatype_t type,
dns_fixedname_init(&foundname);
result = dns_view_find(view, name, type, now, options, use_hints,
dns_fixedname_name(&foundname),
NULL, NULL, dns_fixedname_name(&foundname),
rdataset, sigrdataset);
if (result == DNS_R_NXDOMAIN) {
/*
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment