8804fd9936acd703073c4a75072852c38738a990Brian Wellington/*
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * Copyright (C) 2000, 2001, 2003-2005, 2007, 2013, 2016 Internet Systems Consortium, Inc. ("ISC")
8804fd9936acd703073c4a75072852c38738a990Brian Wellington *
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * This Source Code Form is subject to the terms of the Mozilla Public
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * License, v. 2.0. If a copy of the MPL was not distributed with this
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8804fd9936acd703073c4a75072852c38738a990Brian Wellington */
8804fd9936acd703073c4a75072852c38738a990Brian Wellington
ec5347e2c775f027573ce5648b910361aa926c01Automatic Updater/* $Id: lookup.c,v 1.21 2007/06/18 23:47:40 tbox Exp $ */
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/*! \file */
8804fd9936acd703073c4a75072852c38738a990Brian Wellington
8804fd9936acd703073c4a75072852c38738a990Brian Wellington#include <config.h>
8804fd9936acd703073c4a75072852c38738a990Brian Wellington
8804fd9936acd703073c4a75072852c38738a990Brian Wellington#include <isc/mem.h>
8804fd9936acd703073c4a75072852c38738a990Brian Wellington#include <isc/netaddr.h>
8804fd9936acd703073c4a75072852c38738a990Brian Wellington#include <isc/string.h> /* Required for HP/UX (and others?) */
8804fd9936acd703073c4a75072852c38738a990Brian Wellington#include <isc/task.h>
8804fd9936acd703073c4a75072852c38738a990Brian Wellington#include <isc/util.h>
8804fd9936acd703073c4a75072852c38738a990Brian Wellington
8804fd9936acd703073c4a75072852c38738a990Brian Wellington#include <dns/db.h>
8804fd9936acd703073c4a75072852c38738a990Brian Wellington#include <dns/events.h>
8804fd9936acd703073c4a75072852c38738a990Brian Wellington#include <dns/lookup.h>
8804fd9936acd703073c4a75072852c38738a990Brian Wellington#include <dns/rdata.h>
8804fd9936acd703073c4a75072852c38738a990Brian Wellington#include <dns/rdataset.h>
8804fd9936acd703073c4a75072852c38738a990Brian Wellington#include <dns/rdatastruct.h>
8804fd9936acd703073c4a75072852c38738a990Brian Wellington#include <dns/resolver.h>
8804fd9936acd703073c4a75072852c38738a990Brian Wellington#include <dns/result.h>
8804fd9936acd703073c4a75072852c38738a990Brian Wellington#include <dns/view.h>
8804fd9936acd703073c4a75072852c38738a990Brian Wellington
8804fd9936acd703073c4a75072852c38738a990Brian Wellingtonstruct dns_lookup {
8804fd9936acd703073c4a75072852c38738a990Brian Wellington /* Unlocked. */
8804fd9936acd703073c4a75072852c38738a990Brian Wellington unsigned int magic;
8804fd9936acd703073c4a75072852c38738a990Brian Wellington isc_mem_t * mctx;
8804fd9936acd703073c4a75072852c38738a990Brian Wellington isc_mutex_t lock;
8804fd9936acd703073c4a75072852c38738a990Brian Wellington dns_rdatatype_t type;
8804fd9936acd703073c4a75072852c38738a990Brian Wellington dns_fixedname_t name;
8804fd9936acd703073c4a75072852c38738a990Brian Wellington /* Locked by lock. */
8804fd9936acd703073c4a75072852c38738a990Brian Wellington unsigned int options;
8804fd9936acd703073c4a75072852c38738a990Brian Wellington isc_task_t * task;
8804fd9936acd703073c4a75072852c38738a990Brian Wellington dns_view_t * view;
8804fd9936acd703073c4a75072852c38738a990Brian Wellington dns_lookupevent_t * event;
8804fd9936acd703073c4a75072852c38738a990Brian Wellington dns_fetch_t * fetch;
8804fd9936acd703073c4a75072852c38738a990Brian Wellington unsigned int restarts;
8804fd9936acd703073c4a75072852c38738a990Brian Wellington isc_boolean_t canceled;
8804fd9936acd703073c4a75072852c38738a990Brian Wellington dns_rdataset_t rdataset;
e3e3bafa138a20558a2253470effc01702fc6dfdBrian Wellington dns_rdataset_t sigrdataset;
8804fd9936acd703073c4a75072852c38738a990Brian Wellington};
8804fd9936acd703073c4a75072852c38738a990Brian Wellington
8804fd9936acd703073c4a75072852c38738a990Brian Wellington#define LOOKUP_MAGIC ISC_MAGIC('l', 'o', 'o', 'k')
8804fd9936acd703073c4a75072852c38738a990Brian Wellington#define VALID_LOOKUP(l) ISC_MAGIC_VALID((l), LOOKUP_MAGIC)
8804fd9936acd703073c4a75072852c38738a990Brian Wellington
8804fd9936acd703073c4a75072852c38738a990Brian Wellington#define MAX_RESTARTS 16
8804fd9936acd703073c4a75072852c38738a990Brian Wellington
8804fd9936acd703073c4a75072852c38738a990Brian Wellingtonstatic void lookup_find(dns_lookup_t *lookup, dns_fetchevent_t *event);
8804fd9936acd703073c4a75072852c38738a990Brian Wellington
8804fd9936acd703073c4a75072852c38738a990Brian Wellingtonstatic void
8804fd9936acd703073c4a75072852c38738a990Brian Wellingtonfetch_done(isc_task_t *task, isc_event_t *event) {
8804fd9936acd703073c4a75072852c38738a990Brian Wellington dns_lookup_t *lookup = event->ev_arg;
8804fd9936acd703073c4a75072852c38738a990Brian Wellington dns_fetchevent_t *fevent;
8804fd9936acd703073c4a75072852c38738a990Brian Wellington
8804fd9936acd703073c4a75072852c38738a990Brian Wellington UNUSED(task);
8804fd9936acd703073c4a75072852c38738a990Brian Wellington REQUIRE(event->ev_type == DNS_EVENT_FETCHDONE);
8804fd9936acd703073c4a75072852c38738a990Brian Wellington REQUIRE(VALID_LOOKUP(lookup));
8804fd9936acd703073c4a75072852c38738a990Brian Wellington REQUIRE(lookup->task == task);
8804fd9936acd703073c4a75072852c38738a990Brian Wellington fevent = (dns_fetchevent_t *)event;
8804fd9936acd703073c4a75072852c38738a990Brian Wellington REQUIRE(fevent->fetch == lookup->fetch);
8804fd9936acd703073c4a75072852c38738a990Brian Wellington
8804fd9936acd703073c4a75072852c38738a990Brian Wellington lookup_find(lookup, fevent);
8804fd9936acd703073c4a75072852c38738a990Brian Wellington}
8804fd9936acd703073c4a75072852c38738a990Brian Wellington
8804fd9936acd703073c4a75072852c38738a990Brian Wellingtonstatic inline isc_result_t
8804fd9936acd703073c4a75072852c38738a990Brian Wellingtonstart_fetch(dns_lookup_t *lookup) {
8804fd9936acd703073c4a75072852c38738a990Brian Wellington isc_result_t result;
8804fd9936acd703073c4a75072852c38738a990Brian Wellington
8804fd9936acd703073c4a75072852c38738a990Brian Wellington /*
8804fd9936acd703073c4a75072852c38738a990Brian Wellington * The caller must be holding the lookup's lock.
8804fd9936acd703073c4a75072852c38738a990Brian Wellington */
8804fd9936acd703073c4a75072852c38738a990Brian Wellington
8804fd9936acd703073c4a75072852c38738a990Brian Wellington REQUIRE(lookup->fetch == NULL);
8804fd9936acd703073c4a75072852c38738a990Brian Wellington
8804fd9936acd703073c4a75072852c38738a990Brian Wellington result = dns_resolver_createfetch(lookup->view->resolver,
8804fd9936acd703073c4a75072852c38738a990Brian Wellington dns_fixedname_name(&lookup->name),
8804fd9936acd703073c4a75072852c38738a990Brian Wellington lookup->type,
8804fd9936acd703073c4a75072852c38738a990Brian Wellington NULL, NULL, NULL, 0,
8804fd9936acd703073c4a75072852c38738a990Brian Wellington lookup->task, fetch_done, lookup,
e3e3bafa138a20558a2253470effc01702fc6dfdBrian Wellington &lookup->rdataset,
e3e3bafa138a20558a2253470effc01702fc6dfdBrian Wellington &lookup->sigrdataset,
8804fd9936acd703073c4a75072852c38738a990Brian Wellington &lookup->fetch);
8804fd9936acd703073c4a75072852c38738a990Brian Wellington
8804fd9936acd703073c4a75072852c38738a990Brian Wellington return (result);
8804fd9936acd703073c4a75072852c38738a990Brian Wellington}
8804fd9936acd703073c4a75072852c38738a990Brian Wellington
8804fd9936acd703073c4a75072852c38738a990Brian Wellingtonstatic isc_result_t
8804fd9936acd703073c4a75072852c38738a990Brian Wellingtonbuild_event(dns_lookup_t *lookup) {
8804fd9936acd703073c4a75072852c38738a990Brian Wellington dns_name_t *name = NULL;
8804fd9936acd703073c4a75072852c38738a990Brian Wellington dns_rdataset_t *rdataset = NULL;
e3e3bafa138a20558a2253470effc01702fc6dfdBrian Wellington dns_rdataset_t *sigrdataset = NULL;
8804fd9936acd703073c4a75072852c38738a990Brian Wellington isc_result_t result;
8804fd9936acd703073c4a75072852c38738a990Brian Wellington
8804fd9936acd703073c4a75072852c38738a990Brian Wellington name = isc_mem_get(lookup->mctx, sizeof(dns_name_t));
8804fd9936acd703073c4a75072852c38738a990Brian Wellington if (name == NULL) {
8804fd9936acd703073c4a75072852c38738a990Brian Wellington result = ISC_R_NOMEMORY;
8804fd9936acd703073c4a75072852c38738a990Brian Wellington goto fail;
8804fd9936acd703073c4a75072852c38738a990Brian Wellington }
8804fd9936acd703073c4a75072852c38738a990Brian Wellington dns_name_init(name, NULL);
8804fd9936acd703073c4a75072852c38738a990Brian Wellington result = dns_name_dup(dns_fixedname_name(&lookup->name),
8804fd9936acd703073c4a75072852c38738a990Brian Wellington lookup->mctx, name);
8804fd9936acd703073c4a75072852c38738a990Brian Wellington if (result != ISC_R_SUCCESS)
8804fd9936acd703073c4a75072852c38738a990Brian Wellington goto fail;
8804fd9936acd703073c4a75072852c38738a990Brian Wellington
13090db2b1c210b8386793ff0cbbb0b4348c1ecaBrian Wellington if (dns_rdataset_isassociated(&lookup->rdataset)) {
13090db2b1c210b8386793ff0cbbb0b4348c1ecaBrian Wellington rdataset = isc_mem_get(lookup->mctx, sizeof(dns_rdataset_t));
13090db2b1c210b8386793ff0cbbb0b4348c1ecaBrian Wellington if (rdataset == NULL) {
13090db2b1c210b8386793ff0cbbb0b4348c1ecaBrian Wellington result = ISC_R_NOMEMORY;
13090db2b1c210b8386793ff0cbbb0b4348c1ecaBrian Wellington goto fail;
13090db2b1c210b8386793ff0cbbb0b4348c1ecaBrian Wellington }
13090db2b1c210b8386793ff0cbbb0b4348c1ecaBrian Wellington dns_rdataset_init(rdataset);
13090db2b1c210b8386793ff0cbbb0b4348c1ecaBrian Wellington dns_rdataset_clone(&lookup->rdataset, rdataset);
8804fd9936acd703073c4a75072852c38738a990Brian Wellington }
8804fd9936acd703073c4a75072852c38738a990Brian Wellington
e3e3bafa138a20558a2253470effc01702fc6dfdBrian Wellington if (dns_rdataset_isassociated(&lookup->sigrdataset)) {
e3e3bafa138a20558a2253470effc01702fc6dfdBrian Wellington sigrdataset = isc_mem_get(lookup->mctx,
e3e3bafa138a20558a2253470effc01702fc6dfdBrian Wellington sizeof(dns_rdataset_t));
e3e3bafa138a20558a2253470effc01702fc6dfdBrian Wellington if (sigrdataset == NULL) {
e3e3bafa138a20558a2253470effc01702fc6dfdBrian Wellington result = ISC_R_NOMEMORY;
e3e3bafa138a20558a2253470effc01702fc6dfdBrian Wellington goto fail;
e3e3bafa138a20558a2253470effc01702fc6dfdBrian Wellington }
e3e3bafa138a20558a2253470effc01702fc6dfdBrian Wellington dns_rdataset_init(sigrdataset);
e3e3bafa138a20558a2253470effc01702fc6dfdBrian Wellington dns_rdataset_clone(&lookup->sigrdataset, sigrdataset);
e3e3bafa138a20558a2253470effc01702fc6dfdBrian Wellington }
e3e3bafa138a20558a2253470effc01702fc6dfdBrian Wellington
8804fd9936acd703073c4a75072852c38738a990Brian Wellington lookup->event->name = name;
8804fd9936acd703073c4a75072852c38738a990Brian Wellington lookup->event->rdataset = rdataset;
e3e3bafa138a20558a2253470effc01702fc6dfdBrian Wellington lookup->event->sigrdataset = sigrdataset;
8804fd9936acd703073c4a75072852c38738a990Brian Wellington
8804fd9936acd703073c4a75072852c38738a990Brian Wellington return (ISC_R_SUCCESS);
8804fd9936acd703073c4a75072852c38738a990Brian Wellington
8804fd9936acd703073c4a75072852c38738a990Brian Wellington fail:
8804fd9936acd703073c4a75072852c38738a990Brian Wellington if (name != NULL) {
8804fd9936acd703073c4a75072852c38738a990Brian Wellington if (dns_name_dynamic(name))
8804fd9936acd703073c4a75072852c38738a990Brian Wellington dns_name_free(name, lookup->mctx);
8804fd9936acd703073c4a75072852c38738a990Brian Wellington isc_mem_put(lookup->mctx, name, sizeof(dns_name_t));
8804fd9936acd703073c4a75072852c38738a990Brian Wellington }
8804fd9936acd703073c4a75072852c38738a990Brian Wellington if (rdataset != NULL) {
8804fd9936acd703073c4a75072852c38738a990Brian Wellington if (dns_rdataset_isassociated(rdataset))
8804fd9936acd703073c4a75072852c38738a990Brian Wellington dns_rdataset_disassociate(rdataset);
8804fd9936acd703073c4a75072852c38738a990Brian Wellington isc_mem_put(lookup->mctx, rdataset, sizeof(dns_rdataset_t));
8804fd9936acd703073c4a75072852c38738a990Brian Wellington }
8804fd9936acd703073c4a75072852c38738a990Brian Wellington return (result);
8804fd9936acd703073c4a75072852c38738a990Brian Wellington}
8804fd9936acd703073c4a75072852c38738a990Brian Wellington
13090db2b1c210b8386793ff0cbbb0b4348c1ecaBrian Wellingtonstatic isc_result_t
13090db2b1c210b8386793ff0cbbb0b4348c1ecaBrian Wellingtonview_find(dns_lookup_t *lookup, dns_name_t *foundname) {
13090db2b1c210b8386793ff0cbbb0b4348c1ecaBrian Wellington isc_result_t result;
13090db2b1c210b8386793ff0cbbb0b4348c1ecaBrian Wellington dns_name_t *name = dns_fixedname_name(&lookup->name);
13090db2b1c210b8386793ff0cbbb0b4348c1ecaBrian Wellington dns_rdatatype_t type;
13090db2b1c210b8386793ff0cbbb0b4348c1ecaBrian Wellington
93d6dfaf66258337985427c86181f01fc51f0bb4Mark Andrews if (lookup->type == dns_rdatatype_rrsig)
13090db2b1c210b8386793ff0cbbb0b4348c1ecaBrian Wellington type = dns_rdatatype_any;
13090db2b1c210b8386793ff0cbbb0b4348c1ecaBrian Wellington else
13090db2b1c210b8386793ff0cbbb0b4348c1ecaBrian Wellington type = lookup->type;
13090db2b1c210b8386793ff0cbbb0b4348c1ecaBrian Wellington
13090db2b1c210b8386793ff0cbbb0b4348c1ecaBrian Wellington result = dns_view_find(lookup->view, name, type, 0, 0, ISC_FALSE,
13090db2b1c210b8386793ff0cbbb0b4348c1ecaBrian Wellington &lookup->event->db, &lookup->event->node,
13090db2b1c210b8386793ff0cbbb0b4348c1ecaBrian Wellington foundname, &lookup->rdataset,
13090db2b1c210b8386793ff0cbbb0b4348c1ecaBrian Wellington &lookup->sigrdataset);
13090db2b1c210b8386793ff0cbbb0b4348c1ecaBrian Wellington return (result);
13090db2b1c210b8386793ff0cbbb0b4348c1ecaBrian Wellington}
13090db2b1c210b8386793ff0cbbb0b4348c1ecaBrian Wellington
8804fd9936acd703073c4a75072852c38738a990Brian Wellingtonstatic void
8804fd9936acd703073c4a75072852c38738a990Brian Wellingtonlookup_find(dns_lookup_t *lookup, dns_fetchevent_t *event) {
8804fd9936acd703073c4a75072852c38738a990Brian Wellington isc_result_t result;
8804fd9936acd703073c4a75072852c38738a990Brian Wellington isc_boolean_t want_restart;
a56f5ada432128085e4a06815328023ee0c9610dMark Andrews isc_boolean_t send_event;
8804fd9936acd703073c4a75072852c38738a990Brian Wellington dns_name_t *name, *fname, *prefix;
8804fd9936acd703073c4a75072852c38738a990Brian Wellington dns_fixedname_t foundname, fixed;
c03bb27f0675a6e60ceea66b451548e8481bc05cMark Andrews dns_rdata_t rdata = DNS_RDATA_INIT;
e407562a75eb93073bb72089cced150d7ffe4d4fTatuya JINMEI 神明達哉 unsigned int nlabels;
8804fd9936acd703073c4a75072852c38738a990Brian Wellington int order;
8804fd9936acd703073c4a75072852c38738a990Brian Wellington dns_namereln_t namereln;
8804fd9936acd703073c4a75072852c38738a990Brian Wellington dns_rdata_cname_t cname;
8804fd9936acd703073c4a75072852c38738a990Brian Wellington dns_rdata_dname_t dname;
8804fd9936acd703073c4a75072852c38738a990Brian Wellington
8804fd9936acd703073c4a75072852c38738a990Brian Wellington REQUIRE(VALID_LOOKUP(lookup));
8804fd9936acd703073c4a75072852c38738a990Brian Wellington
8804fd9936acd703073c4a75072852c38738a990Brian Wellington LOCK(&lookup->lock);
8804fd9936acd703073c4a75072852c38738a990Brian Wellington
8804fd9936acd703073c4a75072852c38738a990Brian Wellington result = ISC_R_SUCCESS;
8804fd9936acd703073c4a75072852c38738a990Brian Wellington name = dns_fixedname_name(&lookup->name);
8804fd9936acd703073c4a75072852c38738a990Brian Wellington
8804fd9936acd703073c4a75072852c38738a990Brian Wellington do {
8804fd9936acd703073c4a75072852c38738a990Brian Wellington lookup->restarts++;
8804fd9936acd703073c4a75072852c38738a990Brian Wellington want_restart = ISC_FALSE;
a56f5ada432128085e4a06815328023ee0c9610dMark Andrews send_event = ISC_TRUE;
8804fd9936acd703073c4a75072852c38738a990Brian Wellington
8804fd9936acd703073c4a75072852c38738a990Brian Wellington if (event == NULL && !lookup->canceled) {
8804fd9936acd703073c4a75072852c38738a990Brian Wellington dns_fixedname_init(&foundname);
8804fd9936acd703073c4a75072852c38738a990Brian Wellington fname = dns_fixedname_name(&foundname);
8804fd9936acd703073c4a75072852c38738a990Brian Wellington INSIST(!dns_rdataset_isassociated(&lookup->rdataset));
e3e3bafa138a20558a2253470effc01702fc6dfdBrian Wellington INSIST(!dns_rdataset_isassociated
e3e3bafa138a20558a2253470effc01702fc6dfdBrian Wellington (&lookup->sigrdataset));
a56f5ada432128085e4a06815328023ee0c9610dMark Andrews /*
a56f5ada432128085e4a06815328023ee0c9610dMark Andrews * If we have restarted then clear the old node. */
a56f5ada432128085e4a06815328023ee0c9610dMark Andrews if (lookup->event->node != NULL) {
a56f5ada432128085e4a06815328023ee0c9610dMark Andrews INSIST(lookup->event->db != NULL);
a56f5ada432128085e4a06815328023ee0c9610dMark Andrews dns_db_detachnode(lookup->event->db,
a56f5ada432128085e4a06815328023ee0c9610dMark Andrews &lookup->event->node);
a56f5ada432128085e4a06815328023ee0c9610dMark Andrews }
a56f5ada432128085e4a06815328023ee0c9610dMark Andrews if (lookup->event->db != NULL)
a56f5ada432128085e4a06815328023ee0c9610dMark Andrews dns_db_detach(&lookup->event->db);
13090db2b1c210b8386793ff0cbbb0b4348c1ecaBrian Wellington result = view_find(lookup, fname);
8804fd9936acd703073c4a75072852c38738a990Brian Wellington if (result == ISC_R_NOTFOUND) {
8804fd9936acd703073c4a75072852c38738a990Brian Wellington /*
8804fd9936acd703073c4a75072852c38738a990Brian Wellington * We don't know anything about the name.
8804fd9936acd703073c4a75072852c38738a990Brian Wellington * Launch a fetch.
8804fd9936acd703073c4a75072852c38738a990Brian Wellington */
13090db2b1c210b8386793ff0cbbb0b4348c1ecaBrian Wellington if (lookup->event->node != NULL) {
13090db2b1c210b8386793ff0cbbb0b4348c1ecaBrian Wellington INSIST(lookup->event->db != NULL);
13090db2b1c210b8386793ff0cbbb0b4348c1ecaBrian Wellington dns_db_detachnode(lookup->event->db,
13090db2b1c210b8386793ff0cbbb0b4348c1ecaBrian Wellington &lookup->event->node);
13090db2b1c210b8386793ff0cbbb0b4348c1ecaBrian Wellington }
13090db2b1c210b8386793ff0cbbb0b4348c1ecaBrian Wellington if (lookup->event->db != NULL)
13090db2b1c210b8386793ff0cbbb0b4348c1ecaBrian Wellington dns_db_detach(&lookup->event->db);
8804fd9936acd703073c4a75072852c38738a990Brian Wellington result = start_fetch(lookup);
a56f5ada432128085e4a06815328023ee0c9610dMark Andrews if (result == ISC_R_SUCCESS)
a56f5ada432128085e4a06815328023ee0c9610dMark Andrews send_event = ISC_FALSE;
8804fd9936acd703073c4a75072852c38738a990Brian Wellington goto done;
8804fd9936acd703073c4a75072852c38738a990Brian Wellington }
2674e1a455d4f71de09b2b60e7a8304b9a305588Mark Andrews } else if (event != NULL) {
8804fd9936acd703073c4a75072852c38738a990Brian Wellington result = event->result;
8804fd9936acd703073c4a75072852c38738a990Brian Wellington fname = dns_fixedname_name(&event->foundname);
8804fd9936acd703073c4a75072852c38738a990Brian Wellington dns_resolver_destroyfetch(&lookup->fetch);
8804fd9936acd703073c4a75072852c38738a990Brian Wellington INSIST(event->rdataset == &lookup->rdataset);
e3e3bafa138a20558a2253470effc01702fc6dfdBrian Wellington INSIST(event->sigrdataset == &lookup->sigrdataset);
2674e1a455d4f71de09b2b60e7a8304b9a305588Mark Andrews } else
2674e1a455d4f71de09b2b60e7a8304b9a305588Mark Andrews fname = NULL; /* Silence compiler warning. */
8804fd9936acd703073c4a75072852c38738a990Brian Wellington
8804fd9936acd703073c4a75072852c38738a990Brian Wellington /*
8804fd9936acd703073c4a75072852c38738a990Brian Wellington * If we've been canceled, forget about the result.
8804fd9936acd703073c4a75072852c38738a990Brian Wellington */
8804fd9936acd703073c4a75072852c38738a990Brian Wellington if (lookup->canceled)
8804fd9936acd703073c4a75072852c38738a990Brian Wellington result = ISC_R_CANCELED;
8804fd9936acd703073c4a75072852c38738a990Brian Wellington
8804fd9936acd703073c4a75072852c38738a990Brian Wellington switch (result) {
8804fd9936acd703073c4a75072852c38738a990Brian Wellington case ISC_R_SUCCESS:
8804fd9936acd703073c4a75072852c38738a990Brian Wellington result = build_event(lookup);
13090db2b1c210b8386793ff0cbbb0b4348c1ecaBrian Wellington if (event == NULL)
13090db2b1c210b8386793ff0cbbb0b4348c1ecaBrian Wellington break;
13090db2b1c210b8386793ff0cbbb0b4348c1ecaBrian Wellington if (event->db != NULL)
13090db2b1c210b8386793ff0cbbb0b4348c1ecaBrian Wellington dns_db_attach(event->db, &lookup->event->db);
13090db2b1c210b8386793ff0cbbb0b4348c1ecaBrian Wellington if (event->node != NULL)
13090db2b1c210b8386793ff0cbbb0b4348c1ecaBrian Wellington dns_db_attachnode(lookup->event->db,
13090db2b1c210b8386793ff0cbbb0b4348c1ecaBrian Wellington event->node,
13090db2b1c210b8386793ff0cbbb0b4348c1ecaBrian Wellington &lookup->event->node);
8804fd9936acd703073c4a75072852c38738a990Brian Wellington break;
8804fd9936acd703073c4a75072852c38738a990Brian Wellington case DNS_R_CNAME:
8804fd9936acd703073c4a75072852c38738a990Brian Wellington /*
8804fd9936acd703073c4a75072852c38738a990Brian Wellington * Copy the CNAME's target into the lookup's
8804fd9936acd703073c4a75072852c38738a990Brian Wellington * query name and start over.
8804fd9936acd703073c4a75072852c38738a990Brian Wellington */
8804fd9936acd703073c4a75072852c38738a990Brian Wellington result = dns_rdataset_first(&lookup->rdataset);
8804fd9936acd703073c4a75072852c38738a990Brian Wellington if (result != ISC_R_SUCCESS)
8804fd9936acd703073c4a75072852c38738a990Brian Wellington break;
8804fd9936acd703073c4a75072852c38738a990Brian Wellington dns_rdataset_current(&lookup->rdataset, &rdata);
8804fd9936acd703073c4a75072852c38738a990Brian Wellington result = dns_rdata_tostruct(&rdata, &cname, NULL);
368b37b616234fce3d23099eb180f1dd38e1fb62Mark Andrews dns_rdata_reset(&rdata);
8804fd9936acd703073c4a75072852c38738a990Brian Wellington if (result != ISC_R_SUCCESS)
8804fd9936acd703073c4a75072852c38738a990Brian Wellington break;
b7cd261f2fca2c7138cdc6ae8ee434e9c0031303Brian Wellington result = dns_name_copy(&cname.cname, name, NULL);
8804fd9936acd703073c4a75072852c38738a990Brian Wellington dns_rdata_freestruct(&cname);
a56f5ada432128085e4a06815328023ee0c9610dMark Andrews if (result == ISC_R_SUCCESS) {
8804fd9936acd703073c4a75072852c38738a990Brian Wellington want_restart = ISC_TRUE;
a56f5ada432128085e4a06815328023ee0c9610dMark Andrews send_event = ISC_FALSE;
a56f5ada432128085e4a06815328023ee0c9610dMark Andrews }
8804fd9936acd703073c4a75072852c38738a990Brian Wellington break;
8804fd9936acd703073c4a75072852c38738a990Brian Wellington case DNS_R_DNAME:
8804fd9936acd703073c4a75072852c38738a990Brian Wellington namereln = dns_name_fullcompare(name, fname, &order,
e407562a75eb93073bb72089cced150d7ffe4d4fTatuya JINMEI 神明達哉 &nlabels);
8804fd9936acd703073c4a75072852c38738a990Brian Wellington INSIST(namereln == dns_namereln_subdomain);
8804fd9936acd703073c4a75072852c38738a990Brian Wellington /*
8804fd9936acd703073c4a75072852c38738a990Brian Wellington * Get the target name of the DNAME.
8804fd9936acd703073c4a75072852c38738a990Brian Wellington */
8804fd9936acd703073c4a75072852c38738a990Brian Wellington result = dns_rdataset_first(&lookup->rdataset);
8804fd9936acd703073c4a75072852c38738a990Brian Wellington if (result != ISC_R_SUCCESS)
8804fd9936acd703073c4a75072852c38738a990Brian Wellington break;
8804fd9936acd703073c4a75072852c38738a990Brian Wellington dns_rdataset_current(&lookup->rdataset, &rdata);
8804fd9936acd703073c4a75072852c38738a990Brian Wellington result = dns_rdata_tostruct(&rdata, &dname, NULL);
368b37b616234fce3d23099eb180f1dd38e1fb62Mark Andrews dns_rdata_reset(&rdata);
8804fd9936acd703073c4a75072852c38738a990Brian Wellington if (result != ISC_R_SUCCESS)
8804fd9936acd703073c4a75072852c38738a990Brian Wellington break;
8804fd9936acd703073c4a75072852c38738a990Brian Wellington /*
8804fd9936acd703073c4a75072852c38738a990Brian Wellington * Construct the new query name and start over.
8804fd9936acd703073c4a75072852c38738a990Brian Wellington */
8804fd9936acd703073c4a75072852c38738a990Brian Wellington dns_fixedname_init(&fixed);
8804fd9936acd703073c4a75072852c38738a990Brian Wellington prefix = dns_fixedname_name(&fixed);
e407562a75eb93073bb72089cced150d7ffe4d4fTatuya JINMEI 神明達哉 dns_name_split(name, nlabels, prefix, NULL);
8804fd9936acd703073c4a75072852c38738a990Brian Wellington result = dns_name_concatenate(prefix, &dname.dname,
8804fd9936acd703073c4a75072852c38738a990Brian Wellington name, NULL);
8804fd9936acd703073c4a75072852c38738a990Brian Wellington dns_rdata_freestruct(&dname);
a56f5ada432128085e4a06815328023ee0c9610dMark Andrews if (result == ISC_R_SUCCESS) {
8804fd9936acd703073c4a75072852c38738a990Brian Wellington want_restart = ISC_TRUE;
a56f5ada432128085e4a06815328023ee0c9610dMark Andrews send_event = ISC_FALSE;
a56f5ada432128085e4a06815328023ee0c9610dMark Andrews }
8804fd9936acd703073c4a75072852c38738a990Brian Wellington break;
8804fd9936acd703073c4a75072852c38738a990Brian Wellington default:
8804fd9936acd703073c4a75072852c38738a990Brian Wellington send_event = ISC_TRUE;
8804fd9936acd703073c4a75072852c38738a990Brian Wellington }
8804fd9936acd703073c4a75072852c38738a990Brian Wellington
8804fd9936acd703073c4a75072852c38738a990Brian Wellington if (dns_rdataset_isassociated(&lookup->rdataset))
8804fd9936acd703073c4a75072852c38738a990Brian Wellington dns_rdataset_disassociate(&lookup->rdataset);
e3e3bafa138a20558a2253470effc01702fc6dfdBrian Wellington if (dns_rdataset_isassociated(&lookup->sigrdataset))
e3e3bafa138a20558a2253470effc01702fc6dfdBrian Wellington dns_rdataset_disassociate(&lookup->sigrdataset);
8804fd9936acd703073c4a75072852c38738a990Brian Wellington
86c3cd20dd2aff4b1c52ce13d8587abd8d2bd16cBrian Wellington done:
13090db2b1c210b8386793ff0cbbb0b4348c1ecaBrian Wellington if (event != NULL) {
13090db2b1c210b8386793ff0cbbb0b4348c1ecaBrian Wellington if (event->node != NULL)
13090db2b1c210b8386793ff0cbbb0b4348c1ecaBrian Wellington dns_db_detachnode(event->db, &event->node);
13090db2b1c210b8386793ff0cbbb0b4348c1ecaBrian Wellington if (event->db != NULL)
13090db2b1c210b8386793ff0cbbb0b4348c1ecaBrian Wellington dns_db_detach(&event->db);
42b48d11ca7b296324d7a8a98cdbf0070b0deb1dMark Andrews isc_event_free(ISC_EVENT_PTR(&event));
13090db2b1c210b8386793ff0cbbb0b4348c1ecaBrian Wellington }
8804fd9936acd703073c4a75072852c38738a990Brian Wellington
8804fd9936acd703073c4a75072852c38738a990Brian Wellington /*
8804fd9936acd703073c4a75072852c38738a990Brian Wellington * Limit the number of restarts.
8804fd9936acd703073c4a75072852c38738a990Brian Wellington */
8804fd9936acd703073c4a75072852c38738a990Brian Wellington if (want_restart && lookup->restarts == MAX_RESTARTS) {
8804fd9936acd703073c4a75072852c38738a990Brian Wellington want_restart = ISC_FALSE;
8804fd9936acd703073c4a75072852c38738a990Brian Wellington result = ISC_R_QUOTA;
8804fd9936acd703073c4a75072852c38738a990Brian Wellington send_event = ISC_TRUE;
8804fd9936acd703073c4a75072852c38738a990Brian Wellington }
8804fd9936acd703073c4a75072852c38738a990Brian Wellington
8804fd9936acd703073c4a75072852c38738a990Brian Wellington } while (want_restart);
8804fd9936acd703073c4a75072852c38738a990Brian Wellington
8804fd9936acd703073c4a75072852c38738a990Brian Wellington if (send_event) {
8804fd9936acd703073c4a75072852c38738a990Brian Wellington lookup->event->result = result;
8804fd9936acd703073c4a75072852c38738a990Brian Wellington lookup->event->ev_sender = lookup;
8804fd9936acd703073c4a75072852c38738a990Brian Wellington isc_task_sendanddetach(&lookup->task,
8804fd9936acd703073c4a75072852c38738a990Brian Wellington (isc_event_t **)&lookup->event);
8804fd9936acd703073c4a75072852c38738a990Brian Wellington dns_view_detach(&lookup->view);
8804fd9936acd703073c4a75072852c38738a990Brian Wellington }
8804fd9936acd703073c4a75072852c38738a990Brian Wellington
8804fd9936acd703073c4a75072852c38738a990Brian Wellington UNLOCK(&lookup->lock);
8804fd9936acd703073c4a75072852c38738a990Brian Wellington}
8804fd9936acd703073c4a75072852c38738a990Brian Wellington
8804fd9936acd703073c4a75072852c38738a990Brian Wellingtonstatic void
8804fd9936acd703073c4a75072852c38738a990Brian Wellingtonlevent_destroy(isc_event_t *event) {
8804fd9936acd703073c4a75072852c38738a990Brian Wellington dns_lookupevent_t *levent;
8804fd9936acd703073c4a75072852c38738a990Brian Wellington isc_mem_t *mctx;
573d78f3d53859bc01ce5d5cebbaac9b8b90bfbaTinderbox User
8804fd9936acd703073c4a75072852c38738a990Brian Wellington REQUIRE(event->ev_type == DNS_EVENT_LOOKUPDONE);
8804fd9936acd703073c4a75072852c38738a990Brian Wellington mctx = event->ev_destroy_arg;
8804fd9936acd703073c4a75072852c38738a990Brian Wellington levent = (dns_lookupevent_t *)event;
8804fd9936acd703073c4a75072852c38738a990Brian Wellington
8804fd9936acd703073c4a75072852c38738a990Brian Wellington if (levent->name != NULL) {
8804fd9936acd703073c4a75072852c38738a990Brian Wellington if (dns_name_dynamic(levent->name))
8804fd9936acd703073c4a75072852c38738a990Brian Wellington dns_name_free(levent->name, mctx);
8804fd9936acd703073c4a75072852c38738a990Brian Wellington isc_mem_put(mctx, levent->name, sizeof(dns_name_t));
8804fd9936acd703073c4a75072852c38738a990Brian Wellington }
8804fd9936acd703073c4a75072852c38738a990Brian Wellington if (levent->rdataset != NULL) {
8804fd9936acd703073c4a75072852c38738a990Brian Wellington dns_rdataset_disassociate(levent->rdataset);
8804fd9936acd703073c4a75072852c38738a990Brian Wellington isc_mem_put(mctx, levent->rdataset, sizeof(dns_rdataset_t));
8804fd9936acd703073c4a75072852c38738a990Brian Wellington }
e3e3bafa138a20558a2253470effc01702fc6dfdBrian Wellington if (levent->sigrdataset != NULL) {
e3e3bafa138a20558a2253470effc01702fc6dfdBrian Wellington dns_rdataset_disassociate(levent->sigrdataset);
e3e3bafa138a20558a2253470effc01702fc6dfdBrian Wellington isc_mem_put(mctx, levent->sigrdataset, sizeof(dns_rdataset_t));
e3e3bafa138a20558a2253470effc01702fc6dfdBrian Wellington }
13090db2b1c210b8386793ff0cbbb0b4348c1ecaBrian Wellington if (levent->node != NULL)
13090db2b1c210b8386793ff0cbbb0b4348c1ecaBrian Wellington dns_db_detachnode(levent->db, &levent->node);
13090db2b1c210b8386793ff0cbbb0b4348c1ecaBrian Wellington if (levent->db != NULL)
13090db2b1c210b8386793ff0cbbb0b4348c1ecaBrian Wellington dns_db_detach(&levent->db);
8804fd9936acd703073c4a75072852c38738a990Brian Wellington isc_mem_put(mctx, event, event->ev_size);
8804fd9936acd703073c4a75072852c38738a990Brian Wellington}
8804fd9936acd703073c4a75072852c38738a990Brian Wellington
8804fd9936acd703073c4a75072852c38738a990Brian Wellingtonisc_result_t
8804fd9936acd703073c4a75072852c38738a990Brian Wellingtondns_lookup_create(isc_mem_t *mctx, dns_name_t *name, dns_rdatatype_t type,
8804fd9936acd703073c4a75072852c38738a990Brian Wellington dns_view_t *view, unsigned int options, isc_task_t *task,
8804fd9936acd703073c4a75072852c38738a990Brian Wellington isc_taskaction_t action, void *arg, dns_lookup_t **lookupp)
8804fd9936acd703073c4a75072852c38738a990Brian Wellington{
8804fd9936acd703073c4a75072852c38738a990Brian Wellington isc_result_t result;
8804fd9936acd703073c4a75072852c38738a990Brian Wellington dns_lookup_t *lookup;
8804fd9936acd703073c4a75072852c38738a990Brian Wellington isc_event_t *ievent;
8804fd9936acd703073c4a75072852c38738a990Brian Wellington
f3ca27e9fe307b55e35ea8d7b37351650630e5a3Andreas Gustafsson lookup = isc_mem_get(mctx, sizeof(*lookup));
8804fd9936acd703073c4a75072852c38738a990Brian Wellington if (lookup == NULL)
8804fd9936acd703073c4a75072852c38738a990Brian Wellington return (ISC_R_NOMEMORY);
df925e6c66d45d960fbac0383169763967d2111cEvan Hunt lookup->mctx = NULL;
df925e6c66d45d960fbac0383169763967d2111cEvan Hunt isc_mem_attach(mctx, &lookup->mctx);
8804fd9936acd703073c4a75072852c38738a990Brian Wellington lookup->options = options;
8804fd9936acd703073c4a75072852c38738a990Brian Wellington
8804fd9936acd703073c4a75072852c38738a990Brian Wellington ievent = isc_event_allocate(mctx, lookup, DNS_EVENT_LOOKUPDONE,
f3ca27e9fe307b55e35ea8d7b37351650630e5a3Andreas Gustafsson action, arg, sizeof(*lookup->event));
8804fd9936acd703073c4a75072852c38738a990Brian Wellington if (ievent == NULL) {
8804fd9936acd703073c4a75072852c38738a990Brian Wellington result = ISC_R_NOMEMORY;
8804fd9936acd703073c4a75072852c38738a990Brian Wellington goto cleanup_lookup;
8804fd9936acd703073c4a75072852c38738a990Brian Wellington }
8804fd9936acd703073c4a75072852c38738a990Brian Wellington lookup->event = (dns_lookupevent_t *)ievent;
8804fd9936acd703073c4a75072852c38738a990Brian Wellington lookup->event->ev_destroy = levent_destroy;
8804fd9936acd703073c4a75072852c38738a990Brian Wellington lookup->event->ev_destroy_arg = mctx;
8804fd9936acd703073c4a75072852c38738a990Brian Wellington lookup->event->result = ISC_R_FAILURE;
8804fd9936acd703073c4a75072852c38738a990Brian Wellington lookup->event->name = NULL;
8804fd9936acd703073c4a75072852c38738a990Brian Wellington lookup->event->rdataset = NULL;
e3e3bafa138a20558a2253470effc01702fc6dfdBrian Wellington lookup->event->sigrdataset = NULL;
13090db2b1c210b8386793ff0cbbb0b4348c1ecaBrian Wellington lookup->event->db = NULL;
13090db2b1c210b8386793ff0cbbb0b4348c1ecaBrian Wellington lookup->event->node = NULL;
8804fd9936acd703073c4a75072852c38738a990Brian Wellington
8804fd9936acd703073c4a75072852c38738a990Brian Wellington lookup->task = NULL;
8804fd9936acd703073c4a75072852c38738a990Brian Wellington isc_task_attach(task, &lookup->task);
8804fd9936acd703073c4a75072852c38738a990Brian Wellington
8804fd9936acd703073c4a75072852c38738a990Brian Wellington result = isc_mutex_init(&lookup->lock);
8804fd9936acd703073c4a75072852c38738a990Brian Wellington if (result != ISC_R_SUCCESS)
8804fd9936acd703073c4a75072852c38738a990Brian Wellington goto cleanup_event;
8804fd9936acd703073c4a75072852c38738a990Brian Wellington
8804fd9936acd703073c4a75072852c38738a990Brian Wellington dns_fixedname_init(&lookup->name);
8804fd9936acd703073c4a75072852c38738a990Brian Wellington
b7cd261f2fca2c7138cdc6ae8ee434e9c0031303Brian Wellington result = dns_name_copy(name, dns_fixedname_name(&lookup->name), NULL);
8804fd9936acd703073c4a75072852c38738a990Brian Wellington if (result != ISC_R_SUCCESS)
8804fd9936acd703073c4a75072852c38738a990Brian Wellington goto cleanup_lock;
8804fd9936acd703073c4a75072852c38738a990Brian Wellington
8804fd9936acd703073c4a75072852c38738a990Brian Wellington lookup->type = type;
8804fd9936acd703073c4a75072852c38738a990Brian Wellington lookup->view = NULL;
8804fd9936acd703073c4a75072852c38738a990Brian Wellington dns_view_attach(view, &lookup->view);
8804fd9936acd703073c4a75072852c38738a990Brian Wellington lookup->fetch = NULL;
8804fd9936acd703073c4a75072852c38738a990Brian Wellington lookup->restarts = 0;
8804fd9936acd703073c4a75072852c38738a990Brian Wellington lookup->canceled = ISC_FALSE;
8804fd9936acd703073c4a75072852c38738a990Brian Wellington dns_rdataset_init(&lookup->rdataset);
e3e3bafa138a20558a2253470effc01702fc6dfdBrian Wellington dns_rdataset_init(&lookup->sigrdataset);
8804fd9936acd703073c4a75072852c38738a990Brian Wellington lookup->magic = LOOKUP_MAGIC;
8804fd9936acd703073c4a75072852c38738a990Brian Wellington
8804fd9936acd703073c4a75072852c38738a990Brian Wellington *lookupp = lookup;
8804fd9936acd703073c4a75072852c38738a990Brian Wellington
8804fd9936acd703073c4a75072852c38738a990Brian Wellington lookup_find(lookup, NULL);
8804fd9936acd703073c4a75072852c38738a990Brian Wellington
8804fd9936acd703073c4a75072852c38738a990Brian Wellington return (ISC_R_SUCCESS);
8804fd9936acd703073c4a75072852c38738a990Brian Wellington
8804fd9936acd703073c4a75072852c38738a990Brian Wellington cleanup_lock:
8804fd9936acd703073c4a75072852c38738a990Brian Wellington DESTROYLOCK(&lookup->lock);
8804fd9936acd703073c4a75072852c38738a990Brian Wellington
8804fd9936acd703073c4a75072852c38738a990Brian Wellington cleanup_event:
8804fd9936acd703073c4a75072852c38738a990Brian Wellington ievent = (isc_event_t *)lookup->event;
8804fd9936acd703073c4a75072852c38738a990Brian Wellington isc_event_free(&ievent);
8804fd9936acd703073c4a75072852c38738a990Brian Wellington lookup->event = NULL;
8804fd9936acd703073c4a75072852c38738a990Brian Wellington
8804fd9936acd703073c4a75072852c38738a990Brian Wellington isc_task_detach(&lookup->task);
8804fd9936acd703073c4a75072852c38738a990Brian Wellington
8804fd9936acd703073c4a75072852c38738a990Brian Wellington cleanup_lookup:
df925e6c66d45d960fbac0383169763967d2111cEvan Hunt isc_mem_putanddetach(&mctx, lookup, sizeof(*lookup));
8804fd9936acd703073c4a75072852c38738a990Brian Wellington
8804fd9936acd703073c4a75072852c38738a990Brian Wellington return (result);
8804fd9936acd703073c4a75072852c38738a990Brian Wellington}
8804fd9936acd703073c4a75072852c38738a990Brian Wellington
8804fd9936acd703073c4a75072852c38738a990Brian Wellingtonvoid
8804fd9936acd703073c4a75072852c38738a990Brian Wellingtondns_lookup_cancel(dns_lookup_t *lookup) {
8804fd9936acd703073c4a75072852c38738a990Brian Wellington REQUIRE(VALID_LOOKUP(lookup));
8804fd9936acd703073c4a75072852c38738a990Brian Wellington
8804fd9936acd703073c4a75072852c38738a990Brian Wellington LOCK(&lookup->lock);
8804fd9936acd703073c4a75072852c38738a990Brian Wellington
8804fd9936acd703073c4a75072852c38738a990Brian Wellington if (!lookup->canceled) {
8804fd9936acd703073c4a75072852c38738a990Brian Wellington lookup->canceled = ISC_TRUE;
8804fd9936acd703073c4a75072852c38738a990Brian Wellington if (lookup->fetch != NULL) {
8804fd9936acd703073c4a75072852c38738a990Brian Wellington INSIST(lookup->view != NULL);
8804fd9936acd703073c4a75072852c38738a990Brian Wellington dns_resolver_cancelfetch(lookup->fetch);
8804fd9936acd703073c4a75072852c38738a990Brian Wellington }
8804fd9936acd703073c4a75072852c38738a990Brian Wellington }
8804fd9936acd703073c4a75072852c38738a990Brian Wellington
8804fd9936acd703073c4a75072852c38738a990Brian Wellington UNLOCK(&lookup->lock);
8804fd9936acd703073c4a75072852c38738a990Brian Wellington}
8804fd9936acd703073c4a75072852c38738a990Brian Wellington
8804fd9936acd703073c4a75072852c38738a990Brian Wellingtonvoid
8804fd9936acd703073c4a75072852c38738a990Brian Wellingtondns_lookup_destroy(dns_lookup_t **lookupp) {
8804fd9936acd703073c4a75072852c38738a990Brian Wellington dns_lookup_t *lookup;
8804fd9936acd703073c4a75072852c38738a990Brian Wellington
8804fd9936acd703073c4a75072852c38738a990Brian Wellington REQUIRE(lookupp != NULL);
8804fd9936acd703073c4a75072852c38738a990Brian Wellington lookup = *lookupp;
8804fd9936acd703073c4a75072852c38738a990Brian Wellington REQUIRE(VALID_LOOKUP(lookup));
8804fd9936acd703073c4a75072852c38738a990Brian Wellington REQUIRE(lookup->event == NULL);
8804fd9936acd703073c4a75072852c38738a990Brian Wellington REQUIRE(lookup->task == NULL);
8804fd9936acd703073c4a75072852c38738a990Brian Wellington REQUIRE(lookup->view == NULL);
8804fd9936acd703073c4a75072852c38738a990Brian Wellington if (dns_rdataset_isassociated(&lookup->rdataset))
8804fd9936acd703073c4a75072852c38738a990Brian Wellington dns_rdataset_disassociate(&lookup->rdataset);
e3e3bafa138a20558a2253470effc01702fc6dfdBrian Wellington if (dns_rdataset_isassociated(&lookup->sigrdataset))
e3e3bafa138a20558a2253470effc01702fc6dfdBrian Wellington dns_rdataset_disassociate(&lookup->sigrdataset);
8804fd9936acd703073c4a75072852c38738a990Brian Wellington
8804fd9936acd703073c4a75072852c38738a990Brian Wellington DESTROYLOCK(&lookup->lock);
8804fd9936acd703073c4a75072852c38738a990Brian Wellington lookup->magic = 0;
df925e6c66d45d960fbac0383169763967d2111cEvan Hunt isc_mem_putanddetach(&lookup->mctx, lookup, sizeof(*lookup));
8804fd9936acd703073c4a75072852c38738a990Brian Wellington
8804fd9936acd703073c4a75072852c38738a990Brian Wellington *lookupp = NULL;
8804fd9936acd703073c4a75072852c38738a990Brian Wellington}