lookup.c revision 573d78f3d53859bc01ce5d5cebbaac9b8b90bfba
cd82aa8fa32698240ecd6634f11e3052ca7a2448Michael Graff/*
69fe9aaafdd6a141610e86a777d325db75422070Mark Andrews * Copyright (C) 2004, 2005, 2007, 2013 Internet Systems Consortium, Inc. ("ISC")
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * Copyright (C) 2000, 2001, 2003 Internet Software Consortium.
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence *
cd82aa8fa32698240ecd6634f11e3052ca7a2448Michael Graff * Permission to use, copy, modify, and/or distribute this software for any
cd82aa8fa32698240ecd6634f11e3052ca7a2448Michael Graff * purpose with or without fee is hereby granted, provided that the above
cd82aa8fa32698240ecd6634f11e3052ca7a2448Michael Graff * copyright notice and this permission notice appear in all copies.
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence *
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * PERFORMANCE OF THIS SOFTWARE.
cd82aa8fa32698240ecd6634f11e3052ca7a2448Michael Graff */
cd82aa8fa32698240ecd6634f11e3052ca7a2448Michael Graff
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews/* $Id: lookup.c,v 1.21 2007/06/18 23:47:40 tbox Exp $ */
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/*! \file */
cd82aa8fa32698240ecd6634f11e3052ca7a2448Michael Graff
cd82aa8fa32698240ecd6634f11e3052ca7a2448Michael Graff#include <config.h>
cd82aa8fa32698240ecd6634f11e3052ca7a2448Michael Graff
88b9c12a3cbafc3bebedf50a731bec9ce2f99a13Brian Wellington#include <isc/mem.h>
88b9c12a3cbafc3bebedf50a731bec9ce2f99a13Brian Wellington#include <isc/netaddr.h>
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence#include <isc/string.h> /* Required for HP/UX (and others?) */
cd82aa8fa32698240ecd6634f11e3052ca7a2448Michael Graff#include <isc/task.h>
6028d1ce0380d0ba7f6c6ecd1ad20b31ddd1becbDavid Lawrence#include <isc/util.h>
364a82f7c25b62967678027043425201a5e5171aBob Halley
cd82aa8fa32698240ecd6634f11e3052ca7a2448Michael Graff#include <dns/db.h>
cd82aa8fa32698240ecd6634f11e3052ca7a2448Michael Graff#include <dns/events.h>
cd82aa8fa32698240ecd6634f11e3052ca7a2448Michael Graff#include <dns/lookup.h>
cd82aa8fa32698240ecd6634f11e3052ca7a2448Michael Graff#include <dns/rdata.h>
cd82aa8fa32698240ecd6634f11e3052ca7a2448Michael Graff#include <dns/rdataset.h>
cd82aa8fa32698240ecd6634f11e3052ca7a2448Michael Graff#include <dns/rdatastruct.h>
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews#include <dns/resolver.h>
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews#include <dns/result.h>
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews#include <dns/view.h>
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrewsstruct dns_lookup {
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews /* Unlocked. */
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews unsigned int magic;
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews isc_mem_t * mctx;
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews isc_mutex_t lock;
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews dns_rdatatype_t type;
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews dns_fixedname_t name;
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews /* Locked by lock. */
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews unsigned int options;
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews isc_task_t * task;
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews dns_view_t * view;
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews dns_lookupevent_t * event;
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews dns_fetch_t * fetch;
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews unsigned int restarts;
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews isc_boolean_t canceled;
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews dns_rdataset_t rdataset;
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews dns_rdataset_t sigrdataset;
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews};
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews#define LOOKUP_MAGIC ISC_MAGIC('l', 'o', 'o', 'k')
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews#define VALID_LOOKUP(l) ISC_MAGIC_VALID((l), LOOKUP_MAGIC)
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews#define MAX_RESTARTS 16
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrewsstatic void lookup_find(dns_lookup_t *lookup, dns_fetchevent_t *event);
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrewsstatic void
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrewsfetch_done(isc_task_t *task, isc_event_t *event) {
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews dns_lookup_t *lookup = event->ev_arg;
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews dns_fetchevent_t *fevent;
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews UNUSED(task);
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews REQUIRE(event->ev_type == DNS_EVENT_FETCHDONE);
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews REQUIRE(VALID_LOOKUP(lookup));
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein REQUIRE(lookup->task == task);
88b9c12a3cbafc3bebedf50a731bec9ce2f99a13Brian Wellington fevent = (dns_fetchevent_t *)event;
88b9c12a3cbafc3bebedf50a731bec9ce2f99a13Brian Wellington REQUIRE(fevent->fetch == lookup->fetch);
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews lookup_find(lookup, fevent);
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews}
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrewsstatic inline isc_result_t
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrewsstart_fetch(dns_lookup_t *lookup) {
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews isc_result_t result;
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews /*
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews * The caller must be holding the lookup's lock.
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews */
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews REQUIRE(lookup->fetch == NULL);
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews result = dns_resolver_createfetch(lookup->view->resolver,
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews dns_fixedname_name(&lookup->name),
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews lookup->type,
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews NULL, NULL, NULL, 0,
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews lookup->task, fetch_done, lookup,
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews &lookup->rdataset,
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews &lookup->sigrdataset,
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews &lookup->fetch);
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews return (result);
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews}
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrewsstatic isc_result_t
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrewsbuild_event(dns_lookup_t *lookup) {
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews dns_name_t *name = NULL;
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews dns_rdataset_t *rdataset = NULL;
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews dns_rdataset_t *sigrdataset = NULL;
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews isc_result_t result;
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews
88b9c12a3cbafc3bebedf50a731bec9ce2f99a13Brian Wellington name = isc_mem_get(lookup->mctx, sizeof(dns_name_t));
88b9c12a3cbafc3bebedf50a731bec9ce2f99a13Brian Wellington if (name == NULL) {
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graff result = ISC_R_NOMEMORY;
cd82aa8fa32698240ecd6634f11e3052ca7a2448Michael Graff goto fail;
cd82aa8fa32698240ecd6634f11e3052ca7a2448Michael Graff }
cd82aa8fa32698240ecd6634f11e3052ca7a2448Michael Graff dns_name_init(name, NULL);
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews result = dns_name_dup(dns_fixedname_name(&lookup->name),
cd82aa8fa32698240ecd6634f11e3052ca7a2448Michael Graff lookup->mctx, name);
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews if (result != ISC_R_SUCCESS)
cd82aa8fa32698240ecd6634f11e3052ca7a2448Michael Graff goto fail;
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graff
cd82aa8fa32698240ecd6634f11e3052ca7a2448Michael Graff if (dns_rdataset_isassociated(&lookup->rdataset)) {
88b9c12a3cbafc3bebedf50a731bec9ce2f99a13Brian Wellington rdataset = isc_mem_get(lookup->mctx, sizeof(dns_rdataset_t));
88b9c12a3cbafc3bebedf50a731bec9ce2f99a13Brian Wellington if (rdataset == NULL) {
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews result = ISC_R_NOMEMORY;
cd82aa8fa32698240ecd6634f11e3052ca7a2448Michael Graff goto fail;
cd82aa8fa32698240ecd6634f11e3052ca7a2448Michael Graff }
88b9c12a3cbafc3bebedf50a731bec9ce2f99a13Brian Wellington dns_rdataset_init(rdataset);
88b9c12a3cbafc3bebedf50a731bec9ce2f99a13Brian Wellington dns_rdataset_clone(&lookup->rdataset, rdataset);
88b9c12a3cbafc3bebedf50a731bec9ce2f99a13Brian Wellington }
383665e42ad838046472e847b16c4e0d3f1aaf76Bob Halley
383665e42ad838046472e847b16c4e0d3f1aaf76Bob Halley if (dns_rdataset_isassociated(&lookup->sigrdataset)) {
88b9c12a3cbafc3bebedf50a731bec9ce2f99a13Brian Wellington sigrdataset = isc_mem_get(lookup->mctx,
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews sizeof(dns_rdataset_t));
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews if (sigrdataset == NULL) {
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews result = ISC_R_NOMEMORY;
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews goto fail;
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews }
88b9c12a3cbafc3bebedf50a731bec9ce2f99a13Brian Wellington dns_rdataset_init(sigrdataset);
88b9c12a3cbafc3bebedf50a731bec9ce2f99a13Brian Wellington dns_rdataset_clone(&lookup->sigrdataset, sigrdataset);
88b9c12a3cbafc3bebedf50a731bec9ce2f99a13Brian Wellington }
88b9c12a3cbafc3bebedf50a731bec9ce2f99a13Brian Wellington
88b9c12a3cbafc3bebedf50a731bec9ce2f99a13Brian Wellington lookup->event->name = name;
1b088f46804fd569bf1b2274583d48e83f4f7aebAndreas Gustafsson lookup->event->rdataset = rdataset;
383665e42ad838046472e847b16c4e0d3f1aaf76Bob Halley lookup->event->sigrdataset = sigrdataset;
383665e42ad838046472e847b16c4e0d3f1aaf76Bob Halley
383665e42ad838046472e847b16c4e0d3f1aaf76Bob Halley return (ISC_R_SUCCESS);
88b9c12a3cbafc3bebedf50a731bec9ce2f99a13Brian Wellington
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews fail:
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews if (name != NULL) {
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews if (dns_name_dynamic(name))
88b9c12a3cbafc3bebedf50a731bec9ce2f99a13Brian Wellington dns_name_free(name, lookup->mctx);
88b9c12a3cbafc3bebedf50a731bec9ce2f99a13Brian Wellington isc_mem_put(lookup->mctx, name, sizeof(dns_name_t));
383665e42ad838046472e847b16c4e0d3f1aaf76Bob Halley }
383665e42ad838046472e847b16c4e0d3f1aaf76Bob Halley if (rdataset != NULL) {
383665e42ad838046472e847b16c4e0d3f1aaf76Bob Halley if (dns_rdataset_isassociated(rdataset))
383665e42ad838046472e847b16c4e0d3f1aaf76Bob Halley dns_rdataset_disassociate(rdataset);
383665e42ad838046472e847b16c4e0d3f1aaf76Bob Halley isc_mem_put(lookup->mctx, rdataset, sizeof(dns_rdataset_t));
383665e42ad838046472e847b16c4e0d3f1aaf76Bob Halley }
383665e42ad838046472e847b16c4e0d3f1aaf76Bob Halley return (result);
383665e42ad838046472e847b16c4e0d3f1aaf76Bob Halley}
383665e42ad838046472e847b16c4e0d3f1aaf76Bob Halley
383665e42ad838046472e847b16c4e0d3f1aaf76Bob Halleystatic isc_result_t
88b9c12a3cbafc3bebedf50a731bec9ce2f99a13Brian Wellingtonview_find(dns_lookup_t *lookup, dns_name_t *foundname) {
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews isc_result_t result;
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews dns_name_t *name = dns_fixedname_name(&lookup->name);
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews dns_rdatatype_t type;
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews
88b9c12a3cbafc3bebedf50a731bec9ce2f99a13Brian Wellington if (lookup->type == dns_rdatatype_rrsig)
88b9c12a3cbafc3bebedf50a731bec9ce2f99a13Brian Wellington type = dns_rdatatype_any;
383665e42ad838046472e847b16c4e0d3f1aaf76Bob Halley else
383665e42ad838046472e847b16c4e0d3f1aaf76Bob Halley type = lookup->type;
383665e42ad838046472e847b16c4e0d3f1aaf76Bob Halley
383665e42ad838046472e847b16c4e0d3f1aaf76Bob Halley result = dns_view_find(lookup->view, name, type, 0, 0, ISC_FALSE,
383665e42ad838046472e847b16c4e0d3f1aaf76Bob Halley &lookup->event->db, &lookup->event->node,
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews foundname, &lookup->rdataset,
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews &lookup->sigrdataset);
88b9c12a3cbafc3bebedf50a731bec9ce2f99a13Brian Wellington return (result);
88b9c12a3cbafc3bebedf50a731bec9ce2f99a13Brian Wellington}
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrewsstatic void
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrewslookup_find(dns_lookup_t *lookup, dns_fetchevent_t *event) {
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews isc_result_t result;
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews isc_boolean_t want_restart;
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews isc_boolean_t send_event;
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews dns_name_t *name, *fname, *prefix;
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews dns_fixedname_t foundname, fixed;
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews dns_rdata_t rdata = DNS_RDATA_INIT;
88b9c12a3cbafc3bebedf50a731bec9ce2f99a13Brian Wellington unsigned int nlabels;
383665e42ad838046472e847b16c4e0d3f1aaf76Bob Halley int order;
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews dns_namereln_t namereln;
88b9c12a3cbafc3bebedf50a731bec9ce2f99a13Brian Wellington dns_rdata_cname_t cname;
cd82aa8fa32698240ecd6634f11e3052ca7a2448Michael Graff dns_rdata_dname_t dname;
383665e42ad838046472e847b16c4e0d3f1aaf76Bob Halley
cd82aa8fa32698240ecd6634f11e3052ca7a2448Michael Graff REQUIRE(VALID_LOOKUP(lookup));
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews
cd82aa8fa32698240ecd6634f11e3052ca7a2448Michael Graff LOCK(&lookup->lock);
383665e42ad838046472e847b16c4e0d3f1aaf76Bob Halley
bab57cc87ffc890ba1ba3dbc6c022ae1a36726bcBob Halley result = ISC_R_SUCCESS;
383665e42ad838046472e847b16c4e0d3f1aaf76Bob Halley name = dns_fixedname_name(&lookup->name);
383665e42ad838046472e847b16c4e0d3f1aaf76Bob Halley
383665e42ad838046472e847b16c4e0d3f1aaf76Bob Halley do {
383665e42ad838046472e847b16c4e0d3f1aaf76Bob Halley lookup->restarts++;
383665e42ad838046472e847b16c4e0d3f1aaf76Bob Halley want_restart = ISC_FALSE;
383665e42ad838046472e847b16c4e0d3f1aaf76Bob Halley send_event = ISC_TRUE;
383665e42ad838046472e847b16c4e0d3f1aaf76Bob Halley
383665e42ad838046472e847b16c4e0d3f1aaf76Bob Halley if (event == NULL && !lookup->canceled) {
88b9c12a3cbafc3bebedf50a731bec9ce2f99a13Brian Wellington dns_fixedname_init(&foundname);
cd82aa8fa32698240ecd6634f11e3052ca7a2448Michael Graff fname = dns_fixedname_name(&foundname);
cd82aa8fa32698240ecd6634f11e3052ca7a2448Michael Graff INSIST(!dns_rdataset_isassociated(&lookup->rdataset));
cd82aa8fa32698240ecd6634f11e3052ca7a2448Michael Graff INSIST(!dns_rdataset_isassociated
cd82aa8fa32698240ecd6634f11e3052ca7a2448Michael Graff (&lookup->sigrdataset));
cd82aa8fa32698240ecd6634f11e3052ca7a2448Michael Graff /*
cd82aa8fa32698240ecd6634f11e3052ca7a2448Michael Graff * If we have restarted then clear the old node. */
88b9c12a3cbafc3bebedf50a731bec9ce2f99a13Brian Wellington if (lookup->event->node != NULL) {
da41917c3f882b6e12c7101b653926830a396b81Andreas Gustafsson INSIST(lookup->event->db != NULL);
da41917c3f882b6e12c7101b653926830a396b81Andreas Gustafsson dns_db_detachnode(lookup->event->db,
88b9c12a3cbafc3bebedf50a731bec9ce2f99a13Brian Wellington &lookup->event->node);
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews }
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews if (lookup->event->db != NULL)
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews dns_db_detach(&lookup->event->db);
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews result = view_find(lookup, fname);
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews if (result == ISC_R_NOTFOUND) {
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews /*
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews * We don't know anything about the name.
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews * Launch a fetch.
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews */
cd82aa8fa32698240ecd6634f11e3052ca7a2448Michael Graff if (lookup->event->node != NULL) {
cd82aa8fa32698240ecd6634f11e3052ca7a2448Michael Graff INSIST(lookup->event->db != NULL);
cd82aa8fa32698240ecd6634f11e3052ca7a2448Michael Graff dns_db_detachnode(lookup->event->db,
cd82aa8fa32698240ecd6634f11e3052ca7a2448Michael Graff &lookup->event->node);
cd82aa8fa32698240ecd6634f11e3052ca7a2448Michael Graff }
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews if (lookup->event->db != NULL)
cd82aa8fa32698240ecd6634f11e3052ca7a2448Michael Graff dns_db_detach(&lookup->event->db);
cd82aa8fa32698240ecd6634f11e3052ca7a2448Michael Graff result = start_fetch(lookup);
cd82aa8fa32698240ecd6634f11e3052ca7a2448Michael Graff if (result == ISC_R_SUCCESS)
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews send_event = ISC_FALSE;
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews goto done;
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews }
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews } else if (event != NULL) {
88b9c12a3cbafc3bebedf50a731bec9ce2f99a13Brian Wellington result = event->result;
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews fname = dns_fixedname_name(&event->foundname);
88b9c12a3cbafc3bebedf50a731bec9ce2f99a13Brian Wellington dns_resolver_destroyfetch(&lookup->fetch);
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews INSIST(event->rdataset == &lookup->rdataset);
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews INSIST(event->sigrdataset == &lookup->sigrdataset);
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews } else
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews fname = NULL; /* Silence compiler warning. */
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews /*
cd82aa8fa32698240ecd6634f11e3052ca7a2448Michael Graff * If we've been canceled, forget about the result.
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews */
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews if (lookup->canceled)
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews result = ISC_R_CANCELED;
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews switch (result) {
da41917c3f882b6e12c7101b653926830a396b81Andreas Gustafsson case ISC_R_SUCCESS:
cd82aa8fa32698240ecd6634f11e3052ca7a2448Michael Graff result = build_event(lookup);
da41917c3f882b6e12c7101b653926830a396b81Andreas Gustafsson if (event == NULL)
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews break;
da41917c3f882b6e12c7101b653926830a396b81Andreas Gustafsson if (event->db != NULL)
cd82aa8fa32698240ecd6634f11e3052ca7a2448Michael Graff dns_db_attach(event->db, &lookup->event->db);
cd82aa8fa32698240ecd6634f11e3052ca7a2448Michael Graff if (event->node != NULL)
8cf24d101a291aa3274e8fd07d1a13cb5fe9976bBrian Wellington dns_db_attachnode(lookup->event->db,
8cf24d101a291aa3274e8fd07d1a13cb5fe9976bBrian Wellington event->node,
8cf24d101a291aa3274e8fd07d1a13cb5fe9976bBrian Wellington &lookup->event->node);
8cf24d101a291aa3274e8fd07d1a13cb5fe9976bBrian Wellington break;
8cf24d101a291aa3274e8fd07d1a13cb5fe9976bBrian Wellington case DNS_R_CNAME:
8cf24d101a291aa3274e8fd07d1a13cb5fe9976bBrian Wellington /*
8cf24d101a291aa3274e8fd07d1a13cb5fe9976bBrian Wellington * Copy the CNAME's target into the lookup's
8cf24d101a291aa3274e8fd07d1a13cb5fe9976bBrian Wellington * query name and start over.
8cf24d101a291aa3274e8fd07d1a13cb5fe9976bBrian Wellington */
8cf24d101a291aa3274e8fd07d1a13cb5fe9976bBrian Wellington result = dns_rdataset_first(&lookup->rdataset);
8cf24d101a291aa3274e8fd07d1a13cb5fe9976bBrian Wellington if (result != ISC_R_SUCCESS)
8cf24d101a291aa3274e8fd07d1a13cb5fe9976bBrian Wellington break;
8cf24d101a291aa3274e8fd07d1a13cb5fe9976bBrian Wellington dns_rdataset_current(&lookup->rdataset, &rdata);
8cf24d101a291aa3274e8fd07d1a13cb5fe9976bBrian Wellington result = dns_rdata_tostruct(&rdata, &cname, NULL);
8cf24d101a291aa3274e8fd07d1a13cb5fe9976bBrian Wellington dns_rdata_reset(&rdata);
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews if (result != ISC_R_SUCCESS)
8cf24d101a291aa3274e8fd07d1a13cb5fe9976bBrian Wellington break;
80b782f356f0692c11b4e52e8dd46ec41704e5a2Mark Andrews result = dns_name_copy(&cname.cname, name, NULL);
8cf24d101a291aa3274e8fd07d1a13cb5fe9976bBrian Wellington dns_rdata_freestruct(&cname);
8cf24d101a291aa3274e8fd07d1a13cb5fe9976bBrian Wellington if (result == ISC_R_SUCCESS) {
8cf24d101a291aa3274e8fd07d1a13cb5fe9976bBrian Wellington want_restart = ISC_TRUE;
8cf24d101a291aa3274e8fd07d1a13cb5fe9976bBrian Wellington send_event = ISC_FALSE;
80b782f356f0692c11b4e52e8dd46ec41704e5a2Mark Andrews }
8cf24d101a291aa3274e8fd07d1a13cb5fe9976bBrian Wellington break;
8cf24d101a291aa3274e8fd07d1a13cb5fe9976bBrian Wellington case DNS_R_DNAME:
8cf24d101a291aa3274e8fd07d1a13cb5fe9976bBrian Wellington namereln = dns_name_fullcompare(name, fname, &order,
8cf24d101a291aa3274e8fd07d1a13cb5fe9976bBrian Wellington &nlabels);
8cf24d101a291aa3274e8fd07d1a13cb5fe9976bBrian Wellington INSIST(namereln == dns_namereln_subdomain);
8cf24d101a291aa3274e8fd07d1a13cb5fe9976bBrian Wellington /*
8cf24d101a291aa3274e8fd07d1a13cb5fe9976bBrian Wellington * Get the target name of the DNAME.
8cf24d101a291aa3274e8fd07d1a13cb5fe9976bBrian Wellington */
8cf24d101a291aa3274e8fd07d1a13cb5fe9976bBrian Wellington result = dns_rdataset_first(&lookup->rdataset);
8cf24d101a291aa3274e8fd07d1a13cb5fe9976bBrian Wellington if (result != ISC_R_SUCCESS)
8cf24d101a291aa3274e8fd07d1a13cb5fe9976bBrian Wellington break;
80b782f356f0692c11b4e52e8dd46ec41704e5a2Mark Andrews dns_rdataset_current(&lookup->rdataset, &rdata);
8cf24d101a291aa3274e8fd07d1a13cb5fe9976bBrian Wellington result = dns_rdata_tostruct(&rdata, &dname, NULL);
8cf24d101a291aa3274e8fd07d1a13cb5fe9976bBrian Wellington dns_rdata_reset(&rdata);
8cf24d101a291aa3274e8fd07d1a13cb5fe9976bBrian Wellington if (result != ISC_R_SUCCESS)
80b782f356f0692c11b4e52e8dd46ec41704e5a2Mark Andrews break;
8cf24d101a291aa3274e8fd07d1a13cb5fe9976bBrian Wellington /*
8cf24d101a291aa3274e8fd07d1a13cb5fe9976bBrian Wellington * Construct the new query name and start over.
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews */
8cf24d101a291aa3274e8fd07d1a13cb5fe9976bBrian Wellington dns_fixedname_init(&fixed);
8cf24d101a291aa3274e8fd07d1a13cb5fe9976bBrian Wellington prefix = dns_fixedname_name(&fixed);
8cf24d101a291aa3274e8fd07d1a13cb5fe9976bBrian Wellington dns_name_split(name, nlabels, prefix, NULL);
8cf24d101a291aa3274e8fd07d1a13cb5fe9976bBrian Wellington result = dns_name_concatenate(prefix, &dname.dname,
8cf24d101a291aa3274e8fd07d1a13cb5fe9976bBrian Wellington name, NULL);
8cf24d101a291aa3274e8fd07d1a13cb5fe9976bBrian Wellington dns_rdata_freestruct(&dname);
8cf24d101a291aa3274e8fd07d1a13cb5fe9976bBrian Wellington if (result == ISC_R_SUCCESS) {
8cf24d101a291aa3274e8fd07d1a13cb5fe9976bBrian Wellington want_restart = ISC_TRUE;
8cf24d101a291aa3274e8fd07d1a13cb5fe9976bBrian Wellington send_event = ISC_FALSE;
8cf24d101a291aa3274e8fd07d1a13cb5fe9976bBrian Wellington }
8cf24d101a291aa3274e8fd07d1a13cb5fe9976bBrian Wellington break;
8cf24d101a291aa3274e8fd07d1a13cb5fe9976bBrian Wellington default:
8cf24d101a291aa3274e8fd07d1a13cb5fe9976bBrian Wellington send_event = ISC_TRUE;
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews }
8cf24d101a291aa3274e8fd07d1a13cb5fe9976bBrian Wellington
8cf24d101a291aa3274e8fd07d1a13cb5fe9976bBrian Wellington if (dns_rdataset_isassociated(&lookup->rdataset))
8cf24d101a291aa3274e8fd07d1a13cb5fe9976bBrian Wellington dns_rdataset_disassociate(&lookup->rdataset);
8cf24d101a291aa3274e8fd07d1a13cb5fe9976bBrian Wellington if (dns_rdataset_isassociated(&lookup->sigrdataset))
8cf24d101a291aa3274e8fd07d1a13cb5fe9976bBrian Wellington dns_rdataset_disassociate(&lookup->sigrdataset);
8cf24d101a291aa3274e8fd07d1a13cb5fe9976bBrian Wellington
8cf24d101a291aa3274e8fd07d1a13cb5fe9976bBrian Wellington done:
8cf24d101a291aa3274e8fd07d1a13cb5fe9976bBrian Wellington if (event != NULL) {
8cf24d101a291aa3274e8fd07d1a13cb5fe9976bBrian Wellington if (event->node != NULL)
8cf24d101a291aa3274e8fd07d1a13cb5fe9976bBrian Wellington dns_db_detachnode(event->db, &event->node);
8cf24d101a291aa3274e8fd07d1a13cb5fe9976bBrian Wellington if (event->db != NULL)
80b782f356f0692c11b4e52e8dd46ec41704e5a2Mark Andrews dns_db_detach(&event->db);
8cf24d101a291aa3274e8fd07d1a13cb5fe9976bBrian Wellington isc_event_free(ISC_EVENT_PTR(&event));
8cf24d101a291aa3274e8fd07d1a13cb5fe9976bBrian Wellington }
8cf24d101a291aa3274e8fd07d1a13cb5fe9976bBrian Wellington
8cf24d101a291aa3274e8fd07d1a13cb5fe9976bBrian Wellington /*
8cf24d101a291aa3274e8fd07d1a13cb5fe9976bBrian Wellington * Limit the number of restarts.
8cf24d101a291aa3274e8fd07d1a13cb5fe9976bBrian Wellington */
8cf24d101a291aa3274e8fd07d1a13cb5fe9976bBrian Wellington if (want_restart && lookup->restarts == MAX_RESTARTS) {
8cf24d101a291aa3274e8fd07d1a13cb5fe9976bBrian Wellington want_restart = ISC_FALSE;
8cf24d101a291aa3274e8fd07d1a13cb5fe9976bBrian Wellington result = ISC_R_QUOTA;
8cf24d101a291aa3274e8fd07d1a13cb5fe9976bBrian Wellington send_event = ISC_TRUE;
8cf24d101a291aa3274e8fd07d1a13cb5fe9976bBrian Wellington }
8cf24d101a291aa3274e8fd07d1a13cb5fe9976bBrian Wellington
8cf24d101a291aa3274e8fd07d1a13cb5fe9976bBrian Wellington } while (want_restart);
8cf24d101a291aa3274e8fd07d1a13cb5fe9976bBrian Wellington
8cf24d101a291aa3274e8fd07d1a13cb5fe9976bBrian Wellington if (send_event) {
8cf24d101a291aa3274e8fd07d1a13cb5fe9976bBrian Wellington lookup->event->result = result;
8cf24d101a291aa3274e8fd07d1a13cb5fe9976bBrian Wellington lookup->event->ev_sender = lookup;
8cf24d101a291aa3274e8fd07d1a13cb5fe9976bBrian Wellington isc_task_sendanddetach(&lookup->task,
8cf24d101a291aa3274e8fd07d1a13cb5fe9976bBrian Wellington (isc_event_t **)&lookup->event);
35541328a8c18ba1f984300dfe30ec8713c90031Mark Andrews dns_view_detach(&lookup->view);
35541328a8c18ba1f984300dfe30ec8713c90031Mark Andrews }
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 UNLOCK(&lookup->lock);
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉}
35541328a8c18ba1f984300dfe30ec8713c90031Mark Andrews
8cf24d101a291aa3274e8fd07d1a13cb5fe9976bBrian Wellingtonstatic void
8cf24d101a291aa3274e8fd07d1a13cb5fe9976bBrian Wellingtonlevent_destroy(isc_event_t *event) {
8cf24d101a291aa3274e8fd07d1a13cb5fe9976bBrian Wellington dns_lookupevent_t *levent;
8cf24d101a291aa3274e8fd07d1a13cb5fe9976bBrian Wellington isc_mem_t *mctx;
8cf24d101a291aa3274e8fd07d1a13cb5fe9976bBrian Wellington
8cf24d101a291aa3274e8fd07d1a13cb5fe9976bBrian Wellington REQUIRE(event->ev_type == DNS_EVENT_LOOKUPDONE);
8cf24d101a291aa3274e8fd07d1a13cb5fe9976bBrian Wellington mctx = event->ev_destroy_arg;
8cf24d101a291aa3274e8fd07d1a13cb5fe9976bBrian Wellington levent = (dns_lookupevent_t *)event;
f9f2e770a992cb0ed2234b2f985162273059c6d3Brian Wellington
f9f2e770a992cb0ed2234b2f985162273059c6d3Brian Wellington if (levent->name != NULL) {
f9f2e770a992cb0ed2234b2f985162273059c6d3Brian Wellington if (dns_name_dynamic(levent->name))
8cf24d101a291aa3274e8fd07d1a13cb5fe9976bBrian Wellington dns_name_free(levent->name, mctx);
8cf24d101a291aa3274e8fd07d1a13cb5fe9976bBrian Wellington isc_mem_put(mctx, levent->name, sizeof(dns_name_t));
8cf24d101a291aa3274e8fd07d1a13cb5fe9976bBrian Wellington }
8cf24d101a291aa3274e8fd07d1a13cb5fe9976bBrian Wellington if (levent->rdataset != NULL) {
8cf24d101a291aa3274e8fd07d1a13cb5fe9976bBrian Wellington dns_rdataset_disassociate(levent->rdataset);
8cf24d101a291aa3274e8fd07d1a13cb5fe9976bBrian Wellington isc_mem_put(mctx, levent->rdataset, sizeof(dns_rdataset_t));
8cf24d101a291aa3274e8fd07d1a13cb5fe9976bBrian Wellington }
8cf24d101a291aa3274e8fd07d1a13cb5fe9976bBrian Wellington if (levent->sigrdataset != NULL) {
8cf24d101a291aa3274e8fd07d1a13cb5fe9976bBrian Wellington dns_rdataset_disassociate(levent->sigrdataset);
8cf24d101a291aa3274e8fd07d1a13cb5fe9976bBrian Wellington isc_mem_put(mctx, levent->sigrdataset, sizeof(dns_rdataset_t));
8cf24d101a291aa3274e8fd07d1a13cb5fe9976bBrian Wellington }
8cf24d101a291aa3274e8fd07d1a13cb5fe9976bBrian Wellington if (levent->node != NULL)
8cf24d101a291aa3274e8fd07d1a13cb5fe9976bBrian Wellington dns_db_detachnode(levent->db, &levent->node);
80b782f356f0692c11b4e52e8dd46ec41704e5a2Mark Andrews if (levent->db != NULL)
8cf24d101a291aa3274e8fd07d1a13cb5fe9976bBrian Wellington dns_db_detach(&levent->db);
8cf24d101a291aa3274e8fd07d1a13cb5fe9976bBrian Wellington isc_mem_put(mctx, event, event->ev_size);
8cf24d101a291aa3274e8fd07d1a13cb5fe9976bBrian Wellington}
e800570a5a7572a94604815cd7d7e788c0479ed2Bob Halley
e800570a5a7572a94604815cd7d7e788c0479ed2Bob Halleyisc_result_t
e800570a5a7572a94604815cd7d7e788c0479ed2Bob Halleydns_lookup_create(isc_mem_t *mctx, dns_name_t *name, dns_rdatatype_t type,
e800570a5a7572a94604815cd7d7e788c0479ed2Bob Halley dns_view_t *view, unsigned int options, isc_task_t *task,
e800570a5a7572a94604815cd7d7e788c0479ed2Bob Halley isc_taskaction_t action, void *arg, dns_lookup_t **lookupp)
e800570a5a7572a94604815cd7d7e788c0479ed2Bob Halley{
e800570a5a7572a94604815cd7d7e788c0479ed2Bob Halley isc_result_t result;
e800570a5a7572a94604815cd7d7e788c0479ed2Bob Halley dns_lookup_t *lookup;
e800570a5a7572a94604815cd7d7e788c0479ed2Bob Halley isc_event_t *ievent;
e800570a5a7572a94604815cd7d7e788c0479ed2Bob Halley
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews lookup = isc_mem_get(mctx, sizeof(*lookup));
e800570a5a7572a94604815cd7d7e788c0479ed2Bob Halley if (lookup == NULL)
e800570a5a7572a94604815cd7d7e788c0479ed2Bob Halley return (ISC_R_NOMEMORY);
e800570a5a7572a94604815cd7d7e788c0479ed2Bob Halley lookup->mctx = NULL;
e800570a5a7572a94604815cd7d7e788c0479ed2Bob Halley isc_mem_attach(mctx, &lookup->mctx);
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews lookup->options = options;
e800570a5a7572a94604815cd7d7e788c0479ed2Bob Halley
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence ievent = isc_event_allocate(mctx, lookup, DNS_EVENT_LOOKUPDONE,
e800570a5a7572a94604815cd7d7e788c0479ed2Bob Halley action, arg, sizeof(*lookup->event));
cd82aa8fa32698240ecd6634f11e3052ca7a2448Michael Graff if (ievent == NULL) {
5bfea18ff8bfa907b86ba7d17fb38b9cf493ae97Bob Halley result = ISC_R_NOMEMORY;
da41917c3f882b6e12c7101b653926830a396b81Andreas Gustafsson goto cleanup_lookup;
da41917c3f882b6e12c7101b653926830a396b81Andreas Gustafsson }
da41917c3f882b6e12c7101b653926830a396b81Andreas Gustafsson lookup->event = (dns_lookupevent_t *)ievent;
da41917c3f882b6e12c7101b653926830a396b81Andreas Gustafsson lookup->event->ev_destroy = levent_destroy;
da41917c3f882b6e12c7101b653926830a396b81Andreas Gustafsson lookup->event->ev_destroy_arg = mctx;
da41917c3f882b6e12c7101b653926830a396b81Andreas Gustafsson lookup->event->result = ISC_R_FAILURE;
da41917c3f882b6e12c7101b653926830a396b81Andreas Gustafsson lookup->event->name = NULL;
da41917c3f882b6e12c7101b653926830a396b81Andreas Gustafsson lookup->event->rdataset = NULL;
da41917c3f882b6e12c7101b653926830a396b81Andreas Gustafsson lookup->event->sigrdataset = NULL;
da41917c3f882b6e12c7101b653926830a396b81Andreas Gustafsson lookup->event->db = NULL;
da41917c3f882b6e12c7101b653926830a396b81Andreas Gustafsson lookup->event->node = NULL;
da41917c3f882b6e12c7101b653926830a396b81Andreas Gustafsson
da41917c3f882b6e12c7101b653926830a396b81Andreas Gustafsson lookup->task = NULL;
da41917c3f882b6e12c7101b653926830a396b81Andreas Gustafsson isc_task_attach(task, &lookup->task);
da41917c3f882b6e12c7101b653926830a396b81Andreas Gustafsson
da41917c3f882b6e12c7101b653926830a396b81Andreas Gustafsson result = isc_mutex_init(&lookup->lock);
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews if (result != ISC_R_SUCCESS)
da41917c3f882b6e12c7101b653926830a396b81Andreas Gustafsson goto cleanup_event;
da41917c3f882b6e12c7101b653926830a396b81Andreas Gustafsson
da41917c3f882b6e12c7101b653926830a396b81Andreas Gustafsson dns_fixedname_init(&lookup->name);
da41917c3f882b6e12c7101b653926830a396b81Andreas Gustafsson
da41917c3f882b6e12c7101b653926830a396b81Andreas Gustafsson result = dns_name_copy(name, dns_fixedname_name(&lookup->name), NULL);
da41917c3f882b6e12c7101b653926830a396b81Andreas Gustafsson if (result != ISC_R_SUCCESS)
da41917c3f882b6e12c7101b653926830a396b81Andreas Gustafsson goto cleanup_lock;
da41917c3f882b6e12c7101b653926830a396b81Andreas Gustafsson
da41917c3f882b6e12c7101b653926830a396b81Andreas Gustafsson lookup->type = type;
da41917c3f882b6e12c7101b653926830a396b81Andreas Gustafsson lookup->view = NULL;
da41917c3f882b6e12c7101b653926830a396b81Andreas Gustafsson dns_view_attach(view, &lookup->view);
88b9c12a3cbafc3bebedf50a731bec9ce2f99a13Brian Wellington lookup->fetch = NULL;
88b9c12a3cbafc3bebedf50a731bec9ce2f99a13Brian Wellington lookup->restarts = 0;
88b9c12a3cbafc3bebedf50a731bec9ce2f99a13Brian Wellington lookup->canceled = ISC_FALSE;
88b9c12a3cbafc3bebedf50a731bec9ce2f99a13Brian Wellington dns_rdataset_init(&lookup->rdataset);
88b9c12a3cbafc3bebedf50a731bec9ce2f99a13Brian Wellington dns_rdataset_init(&lookup->sigrdataset);
88b9c12a3cbafc3bebedf50a731bec9ce2f99a13Brian Wellington lookup->magic = LOOKUP_MAGIC;
88b9c12a3cbafc3bebedf50a731bec9ce2f99a13Brian Wellington
c03bb27f0675a6e60ceea66b451548e8481bc05cMark Andrews *lookupp = lookup;
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews
88b9c12a3cbafc3bebedf50a731bec9ce2f99a13Brian Wellington lookup_find(lookup, NULL);
88b9c12a3cbafc3bebedf50a731bec9ce2f99a13Brian Wellington
88b9c12a3cbafc3bebedf50a731bec9ce2f99a13Brian Wellington return (ISC_R_SUCCESS);
88b9c12a3cbafc3bebedf50a731bec9ce2f99a13Brian Wellington
88b9c12a3cbafc3bebedf50a731bec9ce2f99a13Brian Wellington cleanup_lock:
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews DESTROYLOCK(&lookup->lock);
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews
88b9c12a3cbafc3bebedf50a731bec9ce2f99a13Brian Wellington cleanup_event:
da41917c3f882b6e12c7101b653926830a396b81Andreas Gustafsson ievent = (isc_event_t *)lookup->event;
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews isc_event_free(&ievent);
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews lookup->event = NULL;
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews
88b9c12a3cbafc3bebedf50a731bec9ce2f99a13Brian Wellington isc_task_detach(&lookup->task);
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews cleanup_lookup:
368b37b616234fce3d23099eb180f1dd38e1fb62Mark Andrews isc_mem_putanddetach(&mctx, lookup, sizeof(*lookup));
88b9c12a3cbafc3bebedf50a731bec9ce2f99a13Brian Wellington
88b9c12a3cbafc3bebedf50a731bec9ce2f99a13Brian Wellington return (result);
88b9c12a3cbafc3bebedf50a731bec9ce2f99a13Brian Wellington}
88b9c12a3cbafc3bebedf50a731bec9ce2f99a13Brian Wellington
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graffvoid
5bfea18ff8bfa907b86ba7d17fb38b9cf493ae97Bob Halleydns_lookup_cancel(dns_lookup_t *lookup) {
5bfea18ff8bfa907b86ba7d17fb38b9cf493ae97Bob Halley REQUIRE(VALID_LOOKUP(lookup));
5bfea18ff8bfa907b86ba7d17fb38b9cf493ae97Bob Halley
9d2c9f789654ace01489c29af64c68cf42c6cb30Mark Andrews LOCK(&lookup->lock);
5bfea18ff8bfa907b86ba7d17fb38b9cf493ae97Bob Halley
5bfea18ff8bfa907b86ba7d17fb38b9cf493ae97Bob Halley if (!lookup->canceled) {
5bfea18ff8bfa907b86ba7d17fb38b9cf493ae97Bob Halley lookup->canceled = ISC_TRUE;
88b9c12a3cbafc3bebedf50a731bec9ce2f99a13Brian Wellington if (lookup->fetch != NULL) {
c03bb27f0675a6e60ceea66b451548e8481bc05cMark Andrews INSIST(lookup->view != NULL);
c03bb27f0675a6e60ceea66b451548e8481bc05cMark Andrews dns_resolver_cancelfetch(lookup->fetch);
926cde044f4334f7afd9d1123ab0f01ec93e7e72Bob Halley }
88b9c12a3cbafc3bebedf50a731bec9ce2f99a13Brian Wellington }
88b9c12a3cbafc3bebedf50a731bec9ce2f99a13Brian Wellington
88b9c12a3cbafc3bebedf50a731bec9ce2f99a13Brian Wellington UNLOCK(&lookup->lock);
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews}
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrewsvoid
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrewsdns_lookup_destroy(dns_lookup_t **lookupp) {
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews dns_lookup_t *lookup;
5bfea18ff8bfa907b86ba7d17fb38b9cf493ae97Bob Halley
5bfea18ff8bfa907b86ba7d17fb38b9cf493ae97Bob Halley REQUIRE(lookupp != NULL);
5bfea18ff8bfa907b86ba7d17fb38b9cf493ae97Bob Halley lookup = *lookupp;
5bfea18ff8bfa907b86ba7d17fb38b9cf493ae97Bob Halley REQUIRE(VALID_LOOKUP(lookup));
5bfea18ff8bfa907b86ba7d17fb38b9cf493ae97Bob Halley REQUIRE(lookup->event == NULL);
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence REQUIRE(lookup->task == NULL);
5bfea18ff8bfa907b86ba7d17fb38b9cf493ae97Bob Halley REQUIRE(lookup->view == NULL);
5bfea18ff8bfa907b86ba7d17fb38b9cf493ae97Bob Halley if (dns_rdataset_isassociated(&lookup->rdataset))
5bfea18ff8bfa907b86ba7d17fb38b9cf493ae97Bob Halley dns_rdataset_disassociate(&lookup->rdataset);
5bfea18ff8bfa907b86ba7d17fb38b9cf493ae97Bob Halley if (dns_rdataset_isassociated(&lookup->sigrdataset))
5bfea18ff8bfa907b86ba7d17fb38b9cf493ae97Bob Halley dns_rdataset_disassociate(&lookup->sigrdataset);
5bfea18ff8bfa907b86ba7d17fb38b9cf493ae97Bob Halley
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews DESTROYLOCK(&lookup->lock);
5bfea18ff8bfa907b86ba7d17fb38b9cf493ae97Bob Halley lookup->magic = 0;
5bfea18ff8bfa907b86ba7d17fb38b9cf493ae97Bob Halley isc_mem_putanddetach(&lookup->mctx, lookup, sizeof(*lookup));
5bfea18ff8bfa907b86ba7d17fb38b9cf493ae97Bob Halley
5bfea18ff8bfa907b86ba7d17fb38b9cf493ae97Bob Halley *lookupp = NULL;
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews}
5bfea18ff8bfa907b86ba7d17fb38b9cf493ae97Bob Halley