adb.c revision 1d761cb453c76353deb8423c78e98d00c5f86ffa
66bd3b3c6b171271c705b897823dcdcf29464698Michael Graff/*
431a83fb29482c5170b3e4026e59bb14849a6707Tinderbox User * Copyright (C) 2004-2014 Internet Systems Consortium, Inc. ("ISC")
fcb54ce0a4f7377486df5bec83b3aa4711bf4131Mark Andrews * Copyright (C) 1999-2003 Internet Software Consortium.
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence *
ec5347e2c775f027573ce5648b910361aa926c01Automatic Updater * Permission to use, copy, modify, and/or distribute this software for any
66bd3b3c6b171271c705b897823dcdcf29464698Michael Graff * purpose with or without fee is hereby granted, provided that the above
66bd3b3c6b171271c705b897823dcdcf29464698Michael 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.
66bd3b3c6b171271c705b897823dcdcf29464698Michael Graff */
66bd3b3c6b171271c705b897823dcdcf29464698Michael Graff
dd2a0a6d2dec1c23787351e51b434a838dec5603Evan Hunt/* $Id: adb.c,v 1.264.16.1 2011/12/22 07:48:27 marka Exp $ */
9c3531d72aeaad6c5f01efe6a1c82023e1379e4dDavid Lawrence
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff/*! \file
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff *
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * \note
c803787146cadcb2d7e10cbf4491f3be513dfa1aMichael Graff * In finds, if task == NULL, no events will be generated, and no events
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff * have been sent. If task != NULL but taskaction == NULL, an event has been
8cdfd17426179ae6f629a9b7475d46a22f535047Bob Halley * posted but not yet freed. If neither are NULL, no event was posted.
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff *
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff */
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff
66bd3b3c6b171271c705b897823dcdcf29464698Michael Graff#include <config.h>
66bd3b3c6b171271c705b897823dcdcf29464698Michael Graff
058eeac2105c39e7cb31fb75ee0b473717ec3bbcMark Andrews#include <limits.h>
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence
3024dbecbac365171bc6de0f3fa04951d6558be3Michael Graff#include <isc/mutexblock.h>
5fca48054b5e791a2fa0c5015bc3b6fef4fcdce1Andreas Gustafsson#include <isc/netaddr.h>
f181f94ec8da8b1dbcc6353e8be965ea4a5ea282Michael Graff#include <isc/random.h>
d9059b0c38bd630c367d81424d72b1308cd74b04Tatuya JINMEI 神明達哉#include <isc/stats.h>
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff#include <isc/string.h> /* Required for HP/UX (and others?) */
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence#include <isc/task.h>
440be4c866f6935ac069db79a414304507a664c2Michael Graff#include <isc/util.h>
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graff
e45d323a2a0f4ca08d4b139546e60a5fa7bd3f0cMichael Graff#include <dns/adb.h>
29f28fe573d4b3b318b3b026d567c1eb86738015Michael Graff#include <dns/db.h>
86944a4c8002e80ae9b6eb5a5e29b797879be45fMichael Graff#include <dns/events.h>
21e7034ec046105c00a0dab86c83732e2e77ad99Michael Graff#include <dns/log.h>
e51511aa3281f8dc384eb1283115c7f8d5c402aeMichael Graff#include <dns/rdata.h>
e51511aa3281f8dc384eb1283115c7f8d5c402aeMichael Graff#include <dns/rdataset.h>
d1cbf714097e900ed1703529584d3e1a50e8a4a8Brian Wellington#include <dns/rdatastruct.h>
bcf369e513a1cc2209e2a987f5772afa79813540Mark Andrews#include <dns/rdatatype.h>
11efdeb076d65fa9f0c5fc067dc040e7c99dfba6Michael Graff#include <dns/resolver.h>
09f22ac5b09e70bc526015f37168ba33e21ea91fDavid Lawrence#include <dns/result.h>
8907d8fa04fdaa65baf0bc6b01230b2ebde93106Mark Andrews#include <dns/stats.h>
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff#define DNS_ADB_MAGIC ISC_MAGIC('D', 'a', 'd', 'b')
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff#define DNS_ADB_VALID(x) ISC_MAGIC_VALID(x, DNS_ADB_MAGIC)
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff#define DNS_ADBNAME_MAGIC ISC_MAGIC('a', 'd', 'b', 'N')
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff#define DNS_ADBNAME_VALID(x) ISC_MAGIC_VALID(x, DNS_ADBNAME_MAGIC)
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff#define DNS_ADBNAMEHOOK_MAGIC ISC_MAGIC('a', 'd', 'N', 'H')
31fab17bcdbe302592a6c0dc5374ef56333ee879Michael Graff#define DNS_ADBNAMEHOOK_VALID(x) ISC_MAGIC_VALID(x, DNS_ADBNAMEHOOK_MAGIC)
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff#define DNS_ADBLAMEINFO_MAGIC ISC_MAGIC('a', 'd', 'b', 'Z')
bcf369e513a1cc2209e2a987f5772afa79813540Mark Andrews#define DNS_ADBLAMEINFO_VALID(x) ISC_MAGIC_VALID(x, DNS_ADBLAMEINFO_MAGIC)
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff#define DNS_ADBENTRY_MAGIC ISC_MAGIC('a', 'd', 'b', 'E')
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff#define DNS_ADBENTRY_VALID(x) ISC_MAGIC_VALID(x, DNS_ADBENTRY_MAGIC)
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff#define DNS_ADBFETCH_MAGIC ISC_MAGIC('a', 'd', 'F', '4')
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff#define DNS_ADBFETCH_VALID(x) ISC_MAGIC_VALID(x, DNS_ADBFETCH_MAGIC)
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff#define DNS_ADBFETCH6_MAGIC ISC_MAGIC('a', 'd', 'F', '6')
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff#define DNS_ADBFETCH6_VALID(x) ISC_MAGIC_VALID(x, DNS_ADBFETCH6_MAGIC)
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/*!
3115cd89bc1e1fd3ecc4705d253e3484a3f5c555Michael Graff * For type 3 negative cache entries, we will remember that the address is
d947011dc393d9f9988d1349d585b246d19cc3c7Michael Graff * broken for this long. XXXMLG This is also used for actual addresses, too.
49a940dc68b30d9e4f9e1bd3c0503d8b90bb1726Mark Andrews * The intent is to keep us from constantly asking about A/AAAA records
d947011dc393d9f9988d1349d585b246d19cc3c7Michael Graff * if the zone has extremely low TTLs.
3115cd89bc1e1fd3ecc4705d253e3484a3f5c555Michael Graff */
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff#define ADB_CACHE_MINIMUM 10 /*%< seconds */
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff#define ADB_CACHE_MAXIMUM 86400 /*%< seconds (86400 = 24 hours) */
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff#define ADB_ENTRY_WINDOW 1800 /*%< seconds */
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff/*%
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff * The period in seconds after which an ADB name entry is regarded as stale
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff * and forced to be cleaned up.
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff * TODO: This should probably be configurable at run-time.
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff */
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff#ifndef ADB_STALE_MARGIN
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff#define ADB_STALE_MARGIN 1800
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff#endif
3ac63b472022ff92691d1fe69ac715a729671965Michael Graff
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff#define FREE_ITEMS 64 /*%< free count for memory pools */
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff#define FILL_COUNT 16 /*%< fill count for memory pools */
213973a334f92d4aef4ef62b4538fc2e4d0e8082Michael Graff
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff#define DNS_ADB_INVALIDBUCKET (-1) /*%< invalid bucket address */
64828244e04e86dfa40f0a4f0c05f27923da499dMichael Graff
f3350b671881f175d03e16fa5d0f685a1691bcabMark Andrews#define DNS_ADB_MINADBSIZE (1024U*1024U) /*%< 1 Megabyte */
081cff0c33514a5dc63ab794fc199c07377ab756Mark Andrews
213973a334f92d4aef4ef62b4538fc2e4d0e8082Michael Grafftypedef ISC_LIST(dns_adbname_t) dns_adbnamelist_t;
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Grafftypedef struct dns_adbnamehook dns_adbnamehook_t;
ff9bb3fc5453bbf310b67c560fbf04a5c0fb60daMichael Grafftypedef ISC_LIST(dns_adbnamehook_t) dns_adbnamehooklist_t;
bcf369e513a1cc2209e2a987f5772afa79813540Mark Andrewstypedef struct dns_adblameinfo dns_adblameinfo_t;
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Grafftypedef ISC_LIST(dns_adbentry_t) dns_adbentrylist_t;
bb143613cf26e0f27dfd9caf1a7336065d064b26Michael Grafftypedef struct dns_adbfetch dns_adbfetch_t;
fe14eafefa91fada7cea0a55b09196c01477406cBob Halleytypedef struct dns_adbfetch6 dns_adbfetch6_t;
66bd3b3c6b171271c705b897823dcdcf29464698Michael Graff
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/*% dns adb structure */
66bd3b3c6b171271c705b897823dcdcf29464698Michael Graffstruct dns_adb {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater unsigned int magic;
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater isc_mutex_t lock;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater isc_mutex_t reflock; /*%< Covers irefcnt, erefcnt */
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater isc_mutex_t overmemlock; /*%< Covers overmem */
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater isc_mem_t *mctx;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater dns_view_t *view;
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater isc_taskmgr_t *taskmgr;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater isc_task_t *task;
c965b1869024ab38518fade703cc1dae2d71a59eMark Andrews isc_task_t *excl;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater isc_interval_t tick_interval;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater int next_cleanbucket;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater unsigned int irefcnt;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater unsigned int erefcnt;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater isc_mutex_t mplock;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater isc_mempool_t *nmp; /*%< dns_adbname_t */
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater isc_mempool_t *nhmp; /*%< dns_adbnamehook_t */
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater isc_mempool_t *limp; /*%< dns_adblameinfo_t */
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater isc_mempool_t *emp; /*%< dns_adbentry_t */
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater isc_mempool_t *ahmp; /*%< dns_adbfind_t */
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater isc_mempool_t *aimp; /*%< dns_adbaddrinfo_t */
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater isc_mempool_t *afmp; /*%< dns_adbfetch_t */
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater /*!
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * Bucketized locks and lists for names.
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater *
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * XXXRTH Have a per-bucket structure that contains all of these?
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater */
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews unsigned int nnames;
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews isc_mutex_t namescntlock;
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews unsigned int namescnt;
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews dns_adbnamelist_t *names;
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews dns_adbnamelist_t *deadnames;
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews isc_mutex_t *namelocks;
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews isc_boolean_t *name_sd;
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews unsigned int *name_refcnt;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater /*!
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews * Bucketized locks and lists for entries.
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater *
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * XXXRTH Have a per-bucket structure that contains all of these?
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater */
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews unsigned int nentries;
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews isc_mutex_t entriescntlock;
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews unsigned int entriescnt;
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews dns_adbentrylist_t *entries;
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews dns_adbentrylist_t *deadentries;
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews isc_mutex_t *entrylocks;
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews isc_boolean_t *entry_sd; /*%< shutting down */
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews unsigned int *entry_refcnt;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater isc_event_t cevent;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater isc_boolean_t cevent_sent;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater isc_boolean_t shutting_down;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater isc_eventlist_t whenshutdown;
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews isc_event_t growentries;
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews isc_boolean_t growentries_sent;
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews isc_event_t grownames;
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews isc_boolean_t grownames_sent;
66bd3b3c6b171271c705b897823dcdcf29464698Michael Graff};
66bd3b3c6b171271c705b897823dcdcf29464698Michael Graff
8cdfd17426179ae6f629a9b7475d46a22f535047Bob Halley/*
8cdfd17426179ae6f629a9b7475d46a22f535047Bob Halley * XXXMLG Document these structures.
8cdfd17426179ae6f629a9b7475d46a22f535047Bob Halley */
8cdfd17426179ae6f629a9b7475d46a22f535047Bob Halley
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/*% dns_adbname structure */
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graffstruct dns_adbname {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater unsigned int magic;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater dns_name_t name;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater dns_adb_t *adb;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater unsigned int partial_result;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater unsigned int flags;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater int lock_bucket;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater dns_name_t target;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater isc_stdtime_t expire_target;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater isc_stdtime_t expire_v4;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater isc_stdtime_t expire_v6;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater unsigned int chains;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater dns_adbnamehooklist_t v4;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater dns_adbnamehooklist_t v6;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater dns_adbfetch_t *fetch_a;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater dns_adbfetch_t *fetch_aaaa;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater unsigned int fetch_err;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater unsigned int fetch6_err;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater dns_adbfindlist_t finds;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater /* for LRU-based management */
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater isc_stdtime_t last_used;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater ISC_LINK(dns_adbname_t) plink;
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graff};
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graff
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/*% The adbfetch structure */
bb143613cf26e0f27dfd9caf1a7336065d064b26Michael Graffstruct dns_adbfetch {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater unsigned int magic;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater dns_fetch_t *fetch;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater dns_rdataset_t rdataset;
bb143613cf26e0f27dfd9caf1a7336065d064b26Michael Graff};
bb143613cf26e0f27dfd9caf1a7336065d064b26Michael Graff
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/*%
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graff * This is a small widget that dangles off a dns_adbname_t. It contains a
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graff * pointer to the address information about this host, and a link to the next
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graff * namehook that will contain the next address this host has.
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graff */
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graffstruct dns_adbnamehook {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater unsigned int magic;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater dns_adbentry_t *entry;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater ISC_LINK(dns_adbnamehook_t) plink;
66bd3b3c6b171271c705b897823dcdcf29464698Michael Graff};
66bd3b3c6b171271c705b897823dcdcf29464698Michael Graff
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/*%
bcf369e513a1cc2209e2a987f5772afa79813540Mark Andrews * This is a small widget that holds qname-specific information about an
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graff * address. Currently limited to lameness, but could just as easily be
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graff * extended to other types of information about zones.
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graff */
bcf369e513a1cc2209e2a987f5772afa79813540Mark Andrewsstruct dns_adblameinfo {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater unsigned int magic;
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graff
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater dns_name_t qname;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater dns_rdatatype_t qtype;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater isc_stdtime_t lame_timer;
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graff
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater ISC_LINK(dns_adblameinfo_t) plink;
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graff};
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graff
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/*%
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graff * An address entry. It holds quite a bit of information about addresses,
57ecc983c0b37ce7dbccf28f44c6bffdfd6491f7Andreas Gustafsson * including edns state (in "flags"), rtt, and of course the address of
57ecc983c0b37ce7dbccf28f44c6bffdfd6491f7Andreas Gustafsson * the host.
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graff */
66bd3b3c6b171271c705b897823dcdcf29464698Michael Graffstruct dns_adbentry {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater unsigned int magic;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater int lock_bucket;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater unsigned int refcnt;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater unsigned int flags;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater unsigned int srtt;
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews isc_uint16_t udpsize;
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews unsigned char plain;
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews unsigned char plainto;
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews unsigned char edns;
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews unsigned char to4096; /* Our max. */
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews /*
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews * Allow for encapsulated IPv4/IPv6 UDP packet over ethernet.
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews * Ethernet 1500 - IP(20) - IP6(40) - UDP(8) = 1432.
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews */
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews unsigned char to1432; /* Ethernet */
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews unsigned char to1232; /* IPv6 nofrag */
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews unsigned char to512; /* plain DNS */
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater isc_sockaddr_t sockaddr;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater isc_stdtime_t expires;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater /*%<
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * A nonzero 'expires' field indicates that the entry should
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * persist until that time. This allows entries found
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * using dns_adb_findaddrinfo() to persist for a limited time
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * even though they are not necessarily associated with a
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * name.
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater */
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater ISC_LIST(dns_adblameinfo_t) lameinfo;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater ISC_LINK(dns_adbentry_t) plink;
66bd3b3c6b171271c705b897823dcdcf29464698Michael Graff};
66bd3b3c6b171271c705b897823dcdcf29464698Michael Graff
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graff/*
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff * Internal functions (and prototypes).
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff */
d8590892d10fc9528b0dde7e2781935e7b8d7a87Michael Graffstatic inline dns_adbname_t *new_adbname(dns_adb_t *, dns_name_t *);
439c0011e642fb1d26011116144af698125262dbMichael Graffstatic inline void free_adbname(dns_adb_t *, dns_adbname_t **);
439c0011e642fb1d26011116144af698125262dbMichael Graffstatic inline dns_adbnamehook_t *new_adbnamehook(dns_adb_t *,
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater dns_adbentry_t *);
439c0011e642fb1d26011116144af698125262dbMichael Graffstatic inline void free_adbnamehook(dns_adb_t *, dns_adbnamehook_t **);
bcf369e513a1cc2209e2a987f5772afa79813540Mark Andrewsstatic inline dns_adblameinfo_t *new_adblameinfo(dns_adb_t *, dns_name_t *,
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater dns_rdatatype_t);
bcf369e513a1cc2209e2a987f5772afa79813540Mark Andrewsstatic inline void free_adblameinfo(dns_adb_t *, dns_adblameinfo_t **);
439c0011e642fb1d26011116144af698125262dbMichael Graffstatic inline dns_adbentry_t *new_adbentry(dns_adb_t *);
439c0011e642fb1d26011116144af698125262dbMichael Graffstatic inline void free_adbentry(dns_adb_t *, dns_adbentry_t **);
c803787146cadcb2d7e10cbf4491f3be513dfa1aMichael Graffstatic inline dns_adbfind_t *new_adbfind(dns_adb_t *);
e34efaccfaab4dbbe45edd0a58e2b6e930e5784bMichael Graffstatic inline isc_boolean_t free_adbfind(dns_adb_t *, dns_adbfind_t **);
d98c74e2ec5b96bd22aa4ed6d893e8993787493bMichael Graffstatic inline dns_adbaddrinfo_t *new_adbaddrinfo(dns_adb_t *, dns_adbentry_t *,
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater in_port_t);
ff9bb3fc5453bbf310b67c560fbf04a5c0fb60daMichael Graffstatic inline dns_adbfetch_t *new_adbfetch(dns_adb_t *);
ff9bb3fc5453bbf310b67c560fbf04a5c0fb60daMichael Graffstatic inline void free_adbfetch(dns_adb_t *, dns_adbfetch_t **);
439c0011e642fb1d26011116144af698125262dbMichael Graffstatic inline dns_adbname_t *find_name_and_lock(dns_adb_t *, dns_name_t *,
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater unsigned int, int *);
439c0011e642fb1d26011116144af698125262dbMichael Graffstatic inline dns_adbentry_t *find_entry_and_lock(dns_adb_t *,
c82bb6a709abe89c051485b49403ef5bad1b756cTatuya JINMEI 神明達哉 isc_sockaddr_t *, int *,
c82bb6a709abe89c051485b49403ef5bad1b756cTatuya JINMEI 神明達哉 isc_stdtime_t);
dd95acdbce0e2a2775391709cdfca0a9eda7e8f7Mark Andrewsstatic void dump_adb(dns_adb_t *, FILE *, isc_boolean_t debug, isc_stdtime_t);
439c0011e642fb1d26011116144af698125262dbMichael Graffstatic void print_dns_name(FILE *, dns_name_t *);
5fca48054b5e791a2fa0c5015bc3b6fef4fcdce1Andreas Gustafssonstatic void print_namehook_list(FILE *, const char *legend,
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater dns_adbnamehooklist_t *list,
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater isc_boolean_t debug,
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater isc_stdtime_t now);
c803787146cadcb2d7e10cbf4491f3be513dfa1aMichael Graffstatic void print_find_list(FILE *, dns_adbname_t *);
1c3bc66ada38236cc81c41b7174a9f0a872c9ab6Michael Graffstatic void print_fetch_list(FILE *, dns_adbname_t *);
e34efaccfaab4dbbe45edd0a58e2b6e930e5784bMichael Graffstatic inline isc_boolean_t dec_adb_irefcnt(dns_adb_t *);
e34efaccfaab4dbbe45edd0a58e2b6e930e5784bMichael Graffstatic inline void inc_adb_irefcnt(dns_adb_t *);
78bf1ca89505820ed7b03be4bf0c0b53b557f3cdAndreas Gustafssonstatic inline void inc_adb_erefcnt(dns_adb_t *);
439c0011e642fb1d26011116144af698125262dbMichael Graffstatic inline void inc_entry_refcnt(dns_adb_t *, dns_adbentry_t *,
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater isc_boolean_t);
27fe1966c948ba0c1c9d0d831ea3d8bf32d052acTatuya JINMEI 神明達哉static inline isc_boolean_t dec_entry_refcnt(dns_adb_t *, isc_boolean_t,
27fe1966c948ba0c1c9d0d831ea3d8bf32d052acTatuya JINMEI 神明達哉 dns_adbentry_t *, isc_boolean_t);
d8590892d10fc9528b0dde7e2781935e7b8d7a87Michael Graffstatic inline void violate_locking_hierarchy(isc_mutex_t *, isc_mutex_t *);
c82bb6a709abe89c051485b49403ef5bad1b756cTatuya JINMEI 神明達哉static isc_boolean_t clean_namehooks(dns_adb_t *, dns_adbnamehooklist_t *);
16508d9185e5eb96af2ebe900a08c46a6e5eb7edBob Halleystatic void clean_target(dns_adb_t *, dns_name_t *);
4281fe4a80af7402613f0d5c3eeff8829a4ede1fMichael Graffstatic void clean_finds_at_name(dns_adbname_t *, isc_eventtype_t,
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater unsigned int);
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graffstatic isc_boolean_t check_expire_namehooks(dns_adbname_t *, isc_stdtime_t);
c82bb6a709abe89c051485b49403ef5bad1b756cTatuya JINMEI 神明達哉static isc_boolean_t check_expire_entry(dns_adb_t *, dns_adbentry_t **,
c82bb6a709abe89c051485b49403ef5bad1b756cTatuya JINMEI 神明達哉 isc_stdtime_t);
4abed3e3563c7ad346178433130e6d150d3ffeafBob Halleystatic void cancel_fetches_at_name(dns_adbname_t *);
14b98cb34eda66c87ce41a207704a2c232280eafMichael Graffstatic isc_result_t dbfind_name(dns_adbname_t *, isc_stdtime_t,
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater dns_rdatatype_t);
49a940dc68b30d9e4f9e1bd3c0503d8b90bb1726Mark Andrewsstatic isc_result_t fetch_name(dns_adbname_t *, isc_boolean_t,
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater dns_rdatatype_t);
a253e35c2451818fb39f9b808c7641adb5275fb3Michael Graffstatic inline void check_exit(dns_adb_t *);
651228967966ba4fb2e52f92d1207c790af4b130Michael Graffstatic void destroy(dns_adb_t *);
e34efaccfaab4dbbe45edd0a58e2b6e930e5784bMichael Graffstatic isc_boolean_t shutdown_names(dns_adb_t *);
e34efaccfaab4dbbe45edd0a58e2b6e930e5784bMichael Graffstatic isc_boolean_t shutdown_entries(dns_adb_t *);
a253e35c2451818fb39f9b808c7641adb5275fb3Michael Graffstatic inline void link_name(dns_adb_t *, int, dns_adbname_t *);
e34efaccfaab4dbbe45edd0a58e2b6e930e5784bMichael Graffstatic inline isc_boolean_t unlink_name(dns_adb_t *, dns_adbname_t *);
a44c12b332b867f29631e235eb11d1263c73d6c0Bob Halleystatic inline void link_entry(dns_adb_t *, int, dns_adbentry_t *);
e34efaccfaab4dbbe45edd0a58e2b6e930e5784bMichael Graffstatic inline isc_boolean_t unlink_entry(dns_adb_t *, dns_adbentry_t *);
c82bb6a709abe89c051485b49403ef5bad1b756cTatuya JINMEI 神明達哉static isc_boolean_t kill_name(dns_adbname_t **, isc_eventtype_t);
dd95acdbce0e2a2775391709cdfca0a9eda7e8f7Mark Andrewsstatic void water(void *, int);
dd95acdbce0e2a2775391709cdfca0a9eda7e8f7Mark Andrewsstatic void dump_entry(FILE *, dns_adbentry_t *, isc_boolean_t, isc_stdtime_t);
ff9bb3fc5453bbf310b67c560fbf04a5c0fb60daMichael Graff
4281fe4a80af7402613f0d5c3eeff8829a4ede1fMichael Graff/*
4281fe4a80af7402613f0d5c3eeff8829a4ede1fMichael Graff * MUST NOT overlap DNS_ADBFIND_* flags!
4281fe4a80af7402613f0d5c3eeff8829a4ede1fMichael Graff */
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff#define FIND_EVENT_SENT 0x40000000
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff#define FIND_EVENT_FREED 0x80000000
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff#define FIND_EVENTSENT(h) (((h)->flags & FIND_EVENT_SENT) != 0)
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff#define FIND_EVENTFREED(h) (((h)->flags & FIND_EVENT_FREED) != 0)
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff#define NAME_NEEDS_POKE 0x80000000
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff#define NAME_IS_DEAD 0x40000000
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff#define NAME_HINT_OK DNS_ADBFIND_HINTOK
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff#define NAME_GLUE_OK DNS_ADBFIND_GLUEOK
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff#define NAME_STARTATZONE DNS_ADBFIND_STARTATZONE
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff#define NAME_DEAD(n) (((n)->flags & NAME_IS_DEAD) != 0)
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff#define NAME_NEEDSPOKE(n) (((n)->flags & NAME_NEEDS_POKE) != 0)
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff#define NAME_GLUEOK(n) (((n)->flags & NAME_GLUE_OK) != 0)
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff#define NAME_HINTOK(n) (((n)->flags & NAME_HINT_OK) != 0)
14b98cb34eda66c87ce41a207704a2c232280eafMichael Graff
c82bb6a709abe89c051485b49403ef5bad1b756cTatuya JINMEI 神明達哉/*
c82bb6a709abe89c051485b49403ef5bad1b756cTatuya JINMEI 神明達哉 * Private flag(s) for entries.
c82bb6a709abe89c051485b49403ef5bad1b756cTatuya JINMEI 神明達哉 * MUST NOT overlap FCTX_ADDRINFO_xxx and DNS_FETCHOPT_NOEDNS0.
c82bb6a709abe89c051485b49403ef5bad1b756cTatuya JINMEI 神明達哉 */
c82bb6a709abe89c051485b49403ef5bad1b756cTatuya JINMEI 神明達哉#define ENTRY_IS_DEAD 0x80000000
c82bb6a709abe89c051485b49403ef5bad1b756cTatuya JINMEI 神明達哉
65f6d2e1c1fce0989c13c2efb44b8dd26cd977f3Michael Graff/*
65f6d2e1c1fce0989c13c2efb44b8dd26cd977f3Michael Graff * To the name, address classes are all that really exist. If it has a
49a940dc68b30d9e4f9e1bd3c0503d8b90bb1726Mark Andrews * V6 address it doesn't care if it came from a AAAA query.
65f6d2e1c1fce0989c13c2efb44b8dd26cd977f3Michael Graff */
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff#define NAME_HAS_V4(n) (!ISC_LIST_EMPTY((n)->v4))
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff#define NAME_HAS_V6(n) (!ISC_LIST_EMPTY((n)->v6))
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff#define NAME_HAS_ADDRS(n) (NAME_HAS_V4(n) || NAME_HAS_V6(n))
a253e35c2451818fb39f9b808c7641adb5275fb3Michael Graff
65f6d2e1c1fce0989c13c2efb44b8dd26cd977f3Michael Graff/*
49a940dc68b30d9e4f9e1bd3c0503d8b90bb1726Mark Andrews * Fetches are broken out into A and AAAA types. In some cases,
65f6d2e1c1fce0989c13c2efb44b8dd26cd977f3Michael Graff * however, it makes more sense to test for a particular class of fetches,
65f6d2e1c1fce0989c13c2efb44b8dd26cd977f3Michael Graff * like V4 or V6 above.
49a940dc68b30d9e4f9e1bd3c0503d8b90bb1726Mark Andrews * Note: since we have removed the support of A6 in adb, FETCH_A and FETCH_AAAA
49a940dc68b30d9e4f9e1bd3c0503d8b90bb1726Mark Andrews * are now equal to FETCH_V4 and FETCH_V6, respectively.
65f6d2e1c1fce0989c13c2efb44b8dd26cd977f3Michael Graff */
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff#define NAME_FETCH_A(n) ((n)->fetch_a != NULL)
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff#define NAME_FETCH_AAAA(n) ((n)->fetch_aaaa != NULL)
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff#define NAME_FETCH_V4(n) (NAME_FETCH_A(n))
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff#define NAME_FETCH_V6(n) (NAME_FETCH_AAAA(n))
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff#define NAME_FETCH(n) (NAME_FETCH_V4(n) || NAME_FETCH_V6(n))
59e22acc4f79ff481f7bfa46ef0558957ae53cfcMichael Graff
65f6d2e1c1fce0989c13c2efb44b8dd26cd977f3Michael Graff/*
65f6d2e1c1fce0989c13c2efb44b8dd26cd977f3Michael Graff * Find options and tests to see if there are addresses on the list.
65f6d2e1c1fce0989c13c2efb44b8dd26cd977f3Michael Graff */
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff#define FIND_WANTEVENT(fn) (((fn)->options & DNS_ADBFIND_WANTEVENT) != 0)
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff#define FIND_WANTEMPTYEVENT(fn) (((fn)->options & DNS_ADBFIND_EMPTYEVENT) != 0)
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff#define FIND_AVOIDFETCHES(fn) (((fn)->options & DNS_ADBFIND_AVOIDFETCHES) \
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater != 0)
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff#define FIND_STARTATZONE(fn) (((fn)->options & DNS_ADBFIND_STARTATZONE) \
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater != 0)
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff#define FIND_HINTOK(fn) (((fn)->options & DNS_ADBFIND_HINTOK) != 0)
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff#define FIND_GLUEOK(fn) (((fn)->options & DNS_ADBFIND_GLUEOK) != 0)
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff#define FIND_HAS_ADDRS(fn) (!ISC_LIST_EMPTY((fn)->list))
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff#define FIND_RETURNLAME(fn) (((fn)->options & DNS_ADBFIND_RETURNLAME) != 0)
4a3ad0da975d7115d401700f955814a0dff1adb0Bob Halley
65f6d2e1c1fce0989c13c2efb44b8dd26cd977f3Michael Graff/*
65f6d2e1c1fce0989c13c2efb44b8dd26cd977f3Michael Graff * These are currently used on simple unsigned ints, so they are
65f6d2e1c1fce0989c13c2efb44b8dd26cd977f3Michael Graff * not really associated with any particular type.
65f6d2e1c1fce0989c13c2efb44b8dd26cd977f3Michael Graff */
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff#define WANT_INET(x) (((x) & DNS_ADBFIND_INET) != 0)
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff#define WANT_INET6(x) (((x) & DNS_ADBFIND_INET6) != 0)
65f6d2e1c1fce0989c13c2efb44b8dd26cd977f3Michael Graff
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff#define EXPIRE_OK(exp, now) ((exp == INT_MAX) || (exp < now))
3d12fa7e76c02d06e1adeaa7846b60378a3cd204Michael Graff
1a0e33bc2044e1902493111db14cbf793083ac47Michael Graff/*
1a0e33bc2044e1902493111db14cbf793083ac47Michael Graff * Find out if the flags on a name (nf) indicate if it is a hint or
1a0e33bc2044e1902493111db14cbf793083ac47Michael Graff * glue, and compare this to the appropriate bits set in o, to see if
1a0e33bc2044e1902493111db14cbf793083ac47Michael Graff * this is ok.
1a0e33bc2044e1902493111db14cbf793083ac47Michael Graff */
1a0e33bc2044e1902493111db14cbf793083ac47Michael Graff#define GLUE_OK(nf, o) (!NAME_GLUEOK(nf) || (((o) & DNS_ADBFIND_GLUEOK) != 0))
1a0e33bc2044e1902493111db14cbf793083ac47Michael Graff#define HINT_OK(nf, o) (!NAME_HINTOK(nf) || (((o) & DNS_ADBFIND_HINTOK) != 0))
1a0e33bc2044e1902493111db14cbf793083ac47Michael Graff#define GLUEHINT_OK(nf, o) (GLUE_OK(nf, o) || HINT_OK(nf, o))
53cf67186506f9557aaf2149898dd76715803db2Mark Andrews#define STARTATZONE_MATCHES(nf, o) (((nf)->flags & NAME_STARTATZONE) == \
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater ((o) & DNS_ADBFIND_STARTATZONE))
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff#define ENTER_LEVEL ISC_LOG_DEBUG(50)
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff#define EXIT_LEVEL ENTER_LEVEL
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff#define CLEAN_LEVEL ISC_LOG_DEBUG(100)
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff#define DEF_LEVEL ISC_LOG_DEBUG(5)
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff#define NCACHE_LEVEL ISC_LOG_DEBUG(20)
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff#define NCACHE_RESULT(r) ((r) == DNS_R_NCACHENXDOMAIN || \
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater (r) == DNS_R_NCACHENXRRSET)
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff#define AUTH_NX(r) ((r) == DNS_R_NXDOMAIN || \
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater (r) == DNS_R_NXRRSET)
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff#define NXDOMAIN_RESULT(r) ((r) == DNS_R_NXDOMAIN || \
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater (r) == DNS_R_NCACHENXDOMAIN)
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff#define NXRRSET_RESULT(r) ((r) == DNS_R_NCACHENXRRSET || \
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater (r) == DNS_R_NXRRSET || \
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater (r) == DNS_R_HINTNXRRSET)
294802790e8030f1c19b6c2c5d5204b6f464c729Michael Graff
306a93530536f05edfb477cac1c2667d90129a8fMichael Graff/*
306a93530536f05edfb477cac1c2667d90129a8fMichael Graff * Error state rankings.
306a93530536f05edfb477cac1c2667d90129a8fMichael Graff */
306a93530536f05edfb477cac1c2667d90129a8fMichael Graff
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff#define FIND_ERR_SUCCESS 0 /* highest rank */
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff#define FIND_ERR_CANCELED 1
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff#define FIND_ERR_FAILURE 2
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff#define FIND_ERR_NXDOMAIN 3
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff#define FIND_ERR_NXRRSET 4
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff#define FIND_ERR_UNEXPECTED 5
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff#define FIND_ERR_NOTFOUND 6
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff#define FIND_ERR_MAX 7
306a93530536f05edfb477cac1c2667d90129a8fMichael Graff
9e992ecf375cd1eaa5351d06eca8cf7f543d5938Andreas Gustafssonstatic const char *errnames[] = {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater "success",
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater "canceled",
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater "failure",
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater "nxdomain",
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater "nxrrset",
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater "unexpected",
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater "not_found"
9e992ecf375cd1eaa5351d06eca8cf7f543d5938Andreas Gustafsson};
9e992ecf375cd1eaa5351d06eca8cf7f543d5938Andreas Gustafsson
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff#define NEWERR(old, new) (ISC_MIN((old), (new)))
306a93530536f05edfb477cac1c2667d90129a8fMichael Graff
306a93530536f05edfb477cac1c2667d90129a8fMichael Graffstatic isc_result_t find_err_map[FIND_ERR_MAX] = {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater ISC_R_SUCCESS,
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater ISC_R_CANCELED,
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater ISC_R_FAILURE,
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater DNS_R_NXDOMAIN,
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater DNS_R_NXRRSET,
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater ISC_R_UNEXPECTED,
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater ISC_R_NOTFOUND /* not YET found */
306a93530536f05edfb477cac1c2667d90129a8fMichael Graff};
294802790e8030f1c19b6c2c5d5204b6f464c729Michael Graff
76c8294c81fb48b1da6e1fc5b83322a4cedb8e58Andreas Gustafssonstatic void
76c8294c81fb48b1da6e1fc5b83322a4cedb8e58Andreas GustafssonDP(int level, const char *format, ...) ISC_FORMAT_PRINTF(2, 3);
76c8294c81fb48b1da6e1fc5b83322a4cedb8e58Andreas Gustafsson
21e7034ec046105c00a0dab86c83732e2e77ad99Michael Graffstatic void
6d12fdf96621801e80f3f4c2a8a569fe48766a20David LawrenceDP(int level, const char *format, ...) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater va_list args;
21e7034ec046105c00a0dab86c83732e2e77ad99Michael Graff
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater va_start(args, format);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater isc_log_vwrite(dns_lctx,
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater DNS_LOGCATEGORY_DATABASE, DNS_LOGMODULE_ADB,
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater level, format, args);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater va_end(args);
21e7034ec046105c00a0dab86c83732e2e77ad99Michael Graff}
21e7034ec046105c00a0dab86c83732e2e77ad99Michael Graff
8907d8fa04fdaa65baf0bc6b01230b2ebde93106Mark Andrews/*%
8907d8fa04fdaa65baf0bc6b01230b2ebde93106Mark Andrews * Increment resolver-related statistics counters.
8907d8fa04fdaa65baf0bc6b01230b2ebde93106Mark Andrews */
8907d8fa04fdaa65baf0bc6b01230b2ebde93106Mark Andrewsstatic inline void
d9059b0c38bd630c367d81424d72b1308cd74b04Tatuya JINMEI 神明達哉inc_stats(dns_adb_t *adb, isc_statscounter_t counter) {
8907d8fa04fdaa65baf0bc6b01230b2ebde93106Mark Andrews if (adb->view->resstats != NULL)
d9059b0c38bd630c367d81424d72b1308cd74b04Tatuya JINMEI 神明達哉 isc_stats_increment(adb->view->resstats, counter);
8907d8fa04fdaa65baf0bc6b01230b2ebde93106Mark Andrews}
8907d8fa04fdaa65baf0bc6b01230b2ebde93106Mark Andrews
dd2a0a6d2dec1c23787351e51b434a838dec5603Evan Hunt/*%
dd2a0a6d2dec1c23787351e51b434a838dec5603Evan Hunt * Set adb-related statistics counters.
dd2a0a6d2dec1c23787351e51b434a838dec5603Evan Hunt */
dd2a0a6d2dec1c23787351e51b434a838dec5603Evan Huntstatic inline void
dd2a0a6d2dec1c23787351e51b434a838dec5603Evan Huntset_adbstat(dns_adb_t *adb, isc_uint64_t val, isc_statscounter_t counter) {
dd2a0a6d2dec1c23787351e51b434a838dec5603Evan Hunt if (adb->view->adbstats != NULL)
dd2a0a6d2dec1c23787351e51b434a838dec5603Evan Hunt isc_stats_set(adb->view->adbstats, val, counter);
dd2a0a6d2dec1c23787351e51b434a838dec5603Evan Hunt}
dd2a0a6d2dec1c23787351e51b434a838dec5603Evan Hunt
dd2a0a6d2dec1c23787351e51b434a838dec5603Evan Huntstatic inline void
dd2a0a6d2dec1c23787351e51b434a838dec5603Evan Huntdec_adbstats(dns_adb_t *adb, isc_statscounter_t counter) {
dd2a0a6d2dec1c23787351e51b434a838dec5603Evan Hunt if (adb->view->adbstats != NULL)
dd2a0a6d2dec1c23787351e51b434a838dec5603Evan Hunt isc_stats_increment(adb->view->adbstats, counter);
dd2a0a6d2dec1c23787351e51b434a838dec5603Evan Hunt}
dd2a0a6d2dec1c23787351e51b434a838dec5603Evan Hunt
dd2a0a6d2dec1c23787351e51b434a838dec5603Evan Huntstatic inline void
dd2a0a6d2dec1c23787351e51b434a838dec5603Evan Huntinc_adbstats(dns_adb_t *adb, isc_statscounter_t counter) {
dd2a0a6d2dec1c23787351e51b434a838dec5603Evan Hunt if (adb->view->adbstats != NULL)
dd2a0a6d2dec1c23787351e51b434a838dec5603Evan Hunt isc_stats_increment(adb->view->adbstats, counter);
dd2a0a6d2dec1c23787351e51b434a838dec5603Evan Hunt}
dd2a0a6d2dec1c23787351e51b434a838dec5603Evan Hunt
a14eb88840e06b8d458c1556e5452b6d2a50012eMichael Graffstatic inline dns_ttl_t
a14eb88840e06b8d458c1556e5452b6d2a50012eMichael Graffttlclamp(dns_ttl_t ttl) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (ttl < ADB_CACHE_MINIMUM)
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater ttl = ADB_CACHE_MINIMUM;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (ttl > ADB_CACHE_MAXIMUM)
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater ttl = ADB_CACHE_MAXIMUM;
a14eb88840e06b8d458c1556e5452b6d2a50012eMichael Graff
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater return (ttl);
a14eb88840e06b8d458c1556e5452b6d2a50012eMichael Graff}
a14eb88840e06b8d458c1556e5452b6d2a50012eMichael Graff
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews/*
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews * Hashing is most efficient if the number of buckets is prime.
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews * The sequence below is the closest previous primes to 2^n and
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews * 1.5 * 2^n, for values of n from 10 to 28. (The tables will
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews * no longer grow beyond 2^28 entries.)
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews */
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrewsstatic const unsigned nbuckets[] = { 1021, 1531, 2039, 3067, 4093, 6143,
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews 8191, 12281, 16381, 24571, 32749,
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews 49193, 65521, 98299, 131071, 199603,
8868ef9c6411a51697749be54328ed78d2d8be96Automatic Updater 262139, 393209, 524287, 768431, 1048573,
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews 1572853, 2097143, 3145721, 4194301,
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews 6291449, 8388593, 12582893, 16777213,
8868ef9c6411a51697749be54328ed78d2d8be96Automatic Updater 25165813, 33554393, 50331599, 67108859,
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews 100663291, 134217689, 201326557,
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews 268535431, 0 };
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrewsstatic void
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrewsgrow_entries(isc_task_t *task, isc_event_t *ev) {
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews dns_adb_t *adb;
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews dns_adbentry_t *e;
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews dns_adbentrylist_t *newdeadentries = NULL;
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews dns_adbentrylist_t *newentries = NULL;
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews isc_boolean_t *newentry_sd = NULL;
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews isc_mutex_t *newentrylocks = NULL;
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews isc_result_t result;
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews unsigned int *newentry_refcnt = NULL;
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews unsigned int i, n, bucket;
8868ef9c6411a51697749be54328ed78d2d8be96Automatic Updater
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews adb = ev->ev_arg;
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews INSIST(DNS_ADB_VALID(adb));
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews isc_event_free(&ev);
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews
3426bd337df23a83c1e9b45184600edfd056c667Mark Andrews result = isc_task_beginexclusive(task);
3426bd337df23a83c1e9b45184600edfd056c667Mark Andrews if (result != ISC_R_SUCCESS)
3426bd337df23a83c1e9b45184600edfd056c667Mark Andrews goto check_exit;
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews i = 0;
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews while (nbuckets[i] != 0 && adb->nentries >= nbuckets[i])
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews i++;
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews if (nbuckets[i] != 0)
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews n = nbuckets[i];
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews else
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews goto done;
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews DP(ISC_LOG_INFO, "adb: grow_entries to %u starting", n);
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews /*
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews * Are we shutting down?
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews */
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews for (i = 0; i < adb->nentries; i++)
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews if (adb->entry_sd[i])
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews goto cleanup;
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews /*
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews * Grab all the resources we need.
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews */
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews newentries = isc_mem_get(adb->mctx, sizeof(*newentries) * n);
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews newdeadentries = isc_mem_get(adb->mctx, sizeof(*newdeadentries) * n);
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews newentrylocks = isc_mem_get(adb->mctx, sizeof(*newentrylocks) * n);
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews newentry_sd = isc_mem_get(adb->mctx, sizeof(*newentry_sd) * n);
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews newentry_refcnt = isc_mem_get(adb->mctx, sizeof(*newentry_refcnt) * n);
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews if (newentries == NULL || newdeadentries == NULL ||
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews newentrylocks == NULL || newentry_sd == NULL ||
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews newentry_refcnt == NULL)
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews goto cleanup;
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews /*
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews * Initialise the new resources.
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews */
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews result = isc_mutexblock_init(newentrylocks, n);
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews if (result != ISC_R_SUCCESS)
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews goto cleanup;
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews for (i = 0; i < n; i++) {
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews ISC_LIST_INIT(newentries[i]);
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews ISC_LIST_INIT(newdeadentries[i]);
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews newentry_sd[i] = ISC_FALSE;
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews newentry_refcnt[i] = 0;
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews adb->irefcnt++;
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews }
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews /*
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews * Move entries to new arrays.
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews */
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews for (i = 0; i < adb->nentries; i++) {
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews e = ISC_LIST_HEAD(adb->entries[i]);
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews while (e != NULL) {
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews ISC_LIST_UNLINK(adb->entries[i], e, plink);
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews bucket = isc_sockaddr_hash(&e->sockaddr, ISC_TRUE) % n;
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews e->lock_bucket = bucket;
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews ISC_LIST_APPEND(newentries[bucket], e, plink);
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews INSIST(adb->entry_refcnt[i] > 0);
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews adb->entry_refcnt[i]--;
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews newentry_refcnt[bucket]++;
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews e = ISC_LIST_HEAD(adb->entries[i]);
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews }
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews e = ISC_LIST_HEAD(adb->deadentries[i]);
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews while (e != NULL) {
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews ISC_LIST_UNLINK(adb->deadentries[i], e, plink);
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews bucket = isc_sockaddr_hash(&e->sockaddr, ISC_TRUE) % n;
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews e->lock_bucket = bucket;
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews ISC_LIST_APPEND(newdeadentries[bucket], e, plink);
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews INSIST(adb->entry_refcnt[i] > 0);
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews adb->entry_refcnt[i]--;
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews newentry_refcnt[bucket]++;
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews e = ISC_LIST_HEAD(adb->deadentries[i]);
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews }
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews INSIST(adb->entry_refcnt[i] == 0);
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews adb->irefcnt--;
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews }
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews /*
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews * Cleanup old resources.
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews */
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews DESTROYMUTEXBLOCK(adb->entrylocks, adb->nentries);
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews isc_mem_put(adb->mctx, adb->entries,
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews sizeof(*adb->entries) * adb->nentries);
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews isc_mem_put(adb->mctx, adb->deadentries,
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews sizeof(*adb->deadentries) * adb->nentries);
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews isc_mem_put(adb->mctx, adb->entrylocks,
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews sizeof(*adb->entrylocks) * adb->nentries);
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews isc_mem_put(adb->mctx, adb->entry_sd,
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews sizeof(*adb->entry_sd) * adb->nentries);
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews isc_mem_put(adb->mctx, adb->entry_refcnt,
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews sizeof(*adb->entry_refcnt) * adb->nentries);
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews /*
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews * Install new resources.
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews */
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews adb->entries = newentries;
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews adb->deadentries = newdeadentries;
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews adb->entrylocks = newentrylocks;
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews adb->entry_sd = newentry_sd;
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews adb->entry_refcnt = newentry_refcnt;
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews adb->nentries = n;
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews
dd2a0a6d2dec1c23787351e51b434a838dec5603Evan Hunt set_adbstat(adb, adb->nentries, dns_adbstats_nentries);
dd2a0a6d2dec1c23787351e51b434a838dec5603Evan Hunt
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews /*
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews * Only on success do we set adb->growentries_sent to ISC_FALSE.
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews * This will prevent us being continuously being called on error.
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews */
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews adb->growentries_sent = ISC_FALSE;
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews goto done;
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews cleanup:
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews if (newentries != NULL)
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews isc_mem_put(adb->mctx, newentries,
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews sizeof(*newentries) * n);
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews if (newdeadentries != NULL)
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews isc_mem_put(adb->mctx, newdeadentries,
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews sizeof(*newdeadentries) * n);
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews if (newentrylocks != NULL)
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews isc_mem_put(adb->mctx, newentrylocks,
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews sizeof(*newentrylocks) * n);
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews if (newentry_sd != NULL)
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews isc_mem_put(adb->mctx, newentry_sd,
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews sizeof(*newentry_sd) * n);
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews if (newentry_refcnt != NULL)
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews isc_mem_put(adb->mctx, newentry_refcnt,
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews sizeof(*newentry_refcnt) * n);
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews done:
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews isc_task_endexclusive(task);
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews
3426bd337df23a83c1e9b45184600edfd056c667Mark Andrews check_exit:
8868ef9c6411a51697749be54328ed78d2d8be96Automatic Updater LOCK(&adb->lock);
8868ef9c6411a51697749be54328ed78d2d8be96Automatic Updater if (dec_adb_irefcnt(adb))
8868ef9c6411a51697749be54328ed78d2d8be96Automatic Updater check_exit(adb);
8868ef9c6411a51697749be54328ed78d2d8be96Automatic Updater UNLOCK(&adb->lock);
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews DP(ISC_LOG_INFO, "adb: grow_entries finished");
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews}
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrewsstatic void
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrewsgrow_names(isc_task_t *task, isc_event_t *ev) {
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews dns_adb_t *adb;
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews dns_adbname_t *name;
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews dns_adbnamelist_t *newdeadnames = NULL;
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews dns_adbnamelist_t *newnames = NULL;
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews isc_boolean_t *newname_sd = NULL;
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews isc_mutex_t *newnamelocks = NULL;
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews isc_result_t result;
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews unsigned int *newname_refcnt = NULL;
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews unsigned int i, n, bucket;
8868ef9c6411a51697749be54328ed78d2d8be96Automatic Updater
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews adb = ev->ev_arg;
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews INSIST(DNS_ADB_VALID(adb));
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews isc_event_free(&ev);
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews
3426bd337df23a83c1e9b45184600edfd056c667Mark Andrews result = isc_task_beginexclusive(task);
3426bd337df23a83c1e9b45184600edfd056c667Mark Andrews if (result != ISC_R_SUCCESS)
3426bd337df23a83c1e9b45184600edfd056c667Mark Andrews goto check_exit;
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews i = 0;
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews while (nbuckets[i] != 0 && adb->nnames >= nbuckets[i])
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews i++;
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews if (nbuckets[i] != 0)
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews n = nbuckets[i];
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews else
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews goto done;
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews DP(ISC_LOG_INFO, "adb: grow_names to %u starting", n);
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews /*
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews * Are we shutting down?
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews */
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews for (i = 0; i < adb->nnames; i++)
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews if (adb->name_sd[i])
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews goto cleanup;
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews /*
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews * Grab all the resources we need.
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews */
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews newnames = isc_mem_get(adb->mctx, sizeof(*newnames) * n);
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews newdeadnames = isc_mem_get(adb->mctx, sizeof(*newdeadnames) * n);
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews newnamelocks = isc_mem_get(adb->mctx, sizeof(*newnamelocks) * n);
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews newname_sd = isc_mem_get(adb->mctx, sizeof(*newname_sd) * n);
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews newname_refcnt = isc_mem_get(adb->mctx, sizeof(*newname_refcnt) * n);
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews if (newnames == NULL || newdeadnames == NULL ||
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews newnamelocks == NULL || newname_sd == NULL ||
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews newname_refcnt == NULL)
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews goto cleanup;
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews /*
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews * Initialise the new resources.
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews */
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews result = isc_mutexblock_init(newnamelocks, n);
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews if (result != ISC_R_SUCCESS)
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews goto cleanup;
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews for (i = 0; i < n; i++) {
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews ISC_LIST_INIT(newnames[i]);
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews ISC_LIST_INIT(newdeadnames[i]);
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews newname_sd[i] = ISC_FALSE;
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews newname_refcnt[i] = 0;
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews adb->irefcnt++;
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews }
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews /*
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews * Move names to new arrays.
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews */
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews for (i = 0; i < adb->nnames; i++) {
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews name = ISC_LIST_HEAD(adb->names[i]);
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews while (name != NULL) {
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews ISC_LIST_UNLINK(adb->names[i], name, plink);
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews bucket = dns_name_fullhash(&name->name, ISC_TRUE) % n;
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews name->lock_bucket = bucket;
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews ISC_LIST_APPEND(newnames[bucket], name, plink);
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews INSIST(adb->name_refcnt[i] > 0);
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews adb->name_refcnt[i]--;
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews newname_refcnt[bucket]++;
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews name = ISC_LIST_HEAD(adb->names[i]);
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews }
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews name = ISC_LIST_HEAD(adb->deadnames[i]);
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews while (name != NULL) {
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews ISC_LIST_UNLINK(adb->deadnames[i], name, plink);
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews bucket = dns_name_fullhash(&name->name, ISC_TRUE) % n;
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews name->lock_bucket = bucket;
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews ISC_LIST_APPEND(newdeadnames[bucket], name, plink);
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews INSIST(adb->name_refcnt[i] > 0);
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews adb->name_refcnt[i]--;
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews newname_refcnt[bucket]++;
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews name = ISC_LIST_HEAD(adb->deadnames[i]);
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews }
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews INSIST(adb->name_refcnt[i] == 0);
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews adb->irefcnt--;
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews }
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews /*
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews * Cleanup old resources.
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews */
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews DESTROYMUTEXBLOCK(adb->namelocks, adb->nnames);
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews isc_mem_put(adb->mctx, adb->names,
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews sizeof(*adb->names) * adb->nnames);
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews isc_mem_put(adb->mctx, adb->deadnames,
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews sizeof(*adb->deadnames) * adb->nnames);
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews isc_mem_put(adb->mctx, adb->namelocks,
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews sizeof(*adb->namelocks) * adb->nnames);
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews isc_mem_put(adb->mctx, adb->name_sd,
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews sizeof(*adb->name_sd) * adb->nnames);
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews isc_mem_put(adb->mctx, adb->name_refcnt,
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews sizeof(*adb->name_refcnt) * adb->nnames);
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews /*
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews * Install new resources.
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews */
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews adb->names = newnames;
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews adb->deadnames = newdeadnames;
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews adb->namelocks = newnamelocks;
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews adb->name_sd = newname_sd;
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews adb->name_refcnt = newname_refcnt;
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews adb->nnames = n;
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews
dd2a0a6d2dec1c23787351e51b434a838dec5603Evan Hunt set_adbstat(adb, adb->nnames, dns_adbstats_nnames);
dd2a0a6d2dec1c23787351e51b434a838dec5603Evan Hunt
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews /*
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews * Only on success do we set adb->grownames_sent to ISC_FALSE.
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews * This will prevent us being continuously being called on error.
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews */
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews adb->grownames_sent = ISC_FALSE;
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews goto done;
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews cleanup:
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews if (newnames != NULL)
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews isc_mem_put(adb->mctx, newnames, sizeof(*newnames) * n);
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews if (newdeadnames != NULL)
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews isc_mem_put(adb->mctx, newdeadnames, sizeof(*newdeadnames) * n);
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews if (newnamelocks != NULL)
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews isc_mem_put(adb->mctx, newnamelocks, sizeof(*newnamelocks) * n);
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews if (newname_sd != NULL)
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews isc_mem_put(adb->mctx, newname_sd, sizeof(*newname_sd) * n);
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews if (newname_refcnt != NULL)
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews isc_mem_put(adb->mctx, newname_refcnt,
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews sizeof(*newname_refcnt) * n);
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews done:
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews isc_task_endexclusive(task);
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews
3426bd337df23a83c1e9b45184600edfd056c667Mark Andrews check_exit:
8868ef9c6411a51697749be54328ed78d2d8be96Automatic Updater LOCK(&adb->lock);
8868ef9c6411a51697749be54328ed78d2d8be96Automatic Updater if (dec_adb_irefcnt(adb))
8868ef9c6411a51697749be54328ed78d2d8be96Automatic Updater check_exit(adb);
8868ef9c6411a51697749be54328ed78d2d8be96Automatic Updater UNLOCK(&adb->lock);
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews DP(ISC_LOG_INFO, "adb: grow_names finished");
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews}
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews
2bcb48cfcae36398454c98e40c563e2cde748e07Michael Graff/*
2bcb48cfcae36398454c98e40c563e2cde748e07Michael Graff * Requires the adbname bucket be locked and that no entry buckets be locked.
d1fb73ada84ee15ea078c80b1cd0ca8ddc6aa856Michael Graff *
d1fb73ada84ee15ea078c80b1cd0ca8ddc6aa856Michael Graff * This code handles A and AAAA rdatasets only.
2bcb48cfcae36398454c98e40c563e2cde748e07Michael Graff */
2bcb48cfcae36398454c98e40c563e2cde748e07Michael Graffstatic isc_result_t
d1fb73ada84ee15ea078c80b1cd0ca8ddc6aa856Michael Graffimport_rdataset(dns_adbname_t *adbname, dns_rdataset_t *rdataset,
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater isc_stdtime_t now)
2bcb48cfcae36398454c98e40c563e2cde748e07Michael Graff{
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater isc_result_t result;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater dns_adb_t *adb;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater dns_adbnamehook_t *nh;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater dns_adbnamehook_t *anh;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater dns_rdata_t rdata = DNS_RDATA_INIT;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater struct in_addr ina;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater struct in6_addr in6a;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater isc_sockaddr_t sockaddr;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater dns_adbentry_t *foundentry; /* NO CLEAN UP! */
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater int addr_bucket;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater isc_boolean_t new_addresses_added;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater dns_rdatatype_t rdtype;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater unsigned int findoptions;
a95a9de45ca739dab17ec1263186dbaaaba50d97Tatuya JINMEI 神明達哉 dns_adbnamehooklist_t *hookhead;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater INSIST(DNS_ADBNAME_VALID(adbname));
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater adb = adbname->adb;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater INSIST(DNS_ADB_VALID(adb));
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater rdtype = rdataset->type;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater INSIST((rdtype == dns_rdatatype_a) || (rdtype == dns_rdatatype_aaaa));
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (rdtype == dns_rdatatype_a)
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater findoptions = DNS_ADBFIND_INET;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater else
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater findoptions = DNS_ADBFIND_INET6;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater addr_bucket = DNS_ADB_INVALIDBUCKET;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater new_addresses_added = ISC_FALSE;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater nh = NULL;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater result = dns_rdataset_first(rdataset);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater while (result == ISC_R_SUCCESS) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater dns_rdata_reset(&rdata);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater dns_rdataset_current(rdataset, &rdata);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (rdtype == dns_rdatatype_a) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater INSIST(rdata.length == 4);
e851ea826066ac5a5b01c2c23218faa0273a12e8Evan Hunt memmove(&ina.s_addr, rdata.data, 4);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater isc_sockaddr_fromin(&sockaddr, &ina, 0);
a95a9de45ca739dab17ec1263186dbaaaba50d97Tatuya JINMEI 神明達哉 hookhead = &adbname->v4;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater } else {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater INSIST(rdata.length == 16);
e851ea826066ac5a5b01c2c23218faa0273a12e8Evan Hunt memmove(in6a.s6_addr, rdata.data, 16);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater isc_sockaddr_fromin6(&sockaddr, &in6a, 0);
a95a9de45ca739dab17ec1263186dbaaaba50d97Tatuya JINMEI 神明達哉 hookhead = &adbname->v6;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater }
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater INSIST(nh == NULL);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater nh = new_adbnamehook(adb, NULL);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (nh == NULL) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater adbname->partial_result |= findoptions;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater result = ISC_R_NOMEMORY;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater goto fail;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater }
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
c82bb6a709abe89c051485b49403ef5bad1b756cTatuya JINMEI 神明達哉 foundentry = find_entry_and_lock(adb, &sockaddr, &addr_bucket,
c82bb6a709abe89c051485b49403ef5bad1b756cTatuya JINMEI 神明達哉 now);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (foundentry == NULL) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater dns_adbentry_t *entry;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater entry = new_adbentry(adb);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (entry == NULL) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater adbname->partial_result |= findoptions;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater result = ISC_R_NOMEMORY;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater goto fail;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater }
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater entry->sockaddr = sockaddr;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater entry->refcnt = 1;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater nh->entry = entry;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater link_entry(adb, addr_bucket, entry);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater } else {
a95a9de45ca739dab17ec1263186dbaaaba50d97Tatuya JINMEI 神明達哉 for (anh = ISC_LIST_HEAD(*hookhead);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater anh != NULL;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater anh = ISC_LIST_NEXT(anh, plink))
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (anh->entry == foundentry)
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater break;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (anh == NULL) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater foundentry->refcnt++;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater nh->entry = foundentry;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater } else
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater free_adbnamehook(adb, &nh);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater }
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater new_addresses_added = ISC_TRUE;
a95a9de45ca739dab17ec1263186dbaaaba50d97Tatuya JINMEI 神明達哉 if (nh != NULL)
a95a9de45ca739dab17ec1263186dbaaaba50d97Tatuya JINMEI 神明達哉 ISC_LIST_APPEND(*hookhead, nh, plink);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater nh = NULL;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater result = dns_rdataset_next(rdataset);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater }
528829aa8ad69238e674cd81078bc14d4199691bMichael Graff
528829aa8ad69238e674cd81078bc14d4199691bMichael Graff fail:
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (nh != NULL)
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater free_adbnamehook(adb, &nh);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (addr_bucket != DNS_ADB_INVALIDBUCKET)
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater UNLOCK(&adb->entrylocks[addr_bucket]);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (rdataset->trust == dns_trust_glue ||
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater rdataset->trust == dns_trust_additional)
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater rdataset->ttl = ADB_CACHE_MINIMUM;
26b49e84597ab3ebaa9ae1eb0fe01befa46a8107Mark Andrews else if (rdataset->trust == dns_trust_ultimate)
26b49e84597ab3ebaa9ae1eb0fe01befa46a8107Mark Andrews rdataset->ttl = 0;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater else
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater rdataset->ttl = ttlclamp(rdataset->ttl);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (rdtype == dns_rdatatype_a) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater DP(NCACHE_LEVEL, "expire_v4 set to MIN(%u,%u) import_rdataset",
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater adbname->expire_v4, now + rdataset->ttl);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater adbname->expire_v4 = ISC_MIN(adbname->expire_v4,
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews ISC_MIN(now + ADB_ENTRY_WINDOW,
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews now + rdataset->ttl));
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater } else {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater DP(NCACHE_LEVEL, "expire_v6 set to MIN(%u,%u) import_rdataset",
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater adbname->expire_v6, now + rdataset->ttl);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater adbname->expire_v6 = ISC_MIN(adbname->expire_v6,
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews ISC_MIN(now + ADB_ENTRY_WINDOW,
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews now + rdataset->ttl));
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater }
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (new_addresses_added) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater /*
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * Lie a little here. This is more or less so code that cares
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * can find out if any new information was added or not.
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater */
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater return (ISC_R_SUCCESS);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater }
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater return (result);
2bcb48cfcae36398454c98e40c563e2cde748e07Michael Graff}
2bcb48cfcae36398454c98e40c563e2cde748e07Michael Graff
a253e35c2451818fb39f9b808c7641adb5275fb3Michael Graff/*
a253e35c2451818fb39f9b808c7641adb5275fb3Michael Graff * Requires the name's bucket be locked.
a253e35c2451818fb39f9b808c7641adb5275fb3Michael Graff */
e34efaccfaab4dbbe45edd0a58e2b6e930e5784bMichael Graffstatic isc_boolean_t
c82bb6a709abe89c051485b49403ef5bad1b756cTatuya JINMEI 神明達哉kill_name(dns_adbname_t **n, isc_eventtype_t ev) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater dns_adbname_t *name;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater isc_boolean_t result = ISC_FALSE;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater isc_boolean_t result4, result6;
c82bb6a709abe89c051485b49403ef5bad1b756cTatuya JINMEI 神明達哉 int bucket;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater dns_adb_t *adb;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater INSIST(n != NULL);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater name = *n;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater *n = NULL;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater INSIST(DNS_ADBNAME_VALID(name));
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater adb = name->adb;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater INSIST(DNS_ADB_VALID(adb));
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater DP(DEF_LEVEL, "killing name %p", name);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater /*
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * If we're dead already, just check to see if we should go
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * away now or not.
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater */
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (NAME_DEAD(name) && !NAME_FETCH(name)) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater result = unlink_name(adb, name);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater free_adbname(adb, &name);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (result)
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater result = dec_adb_irefcnt(adb);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater return (result);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater }
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater /*
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * Clean up the name's various lists. These two are destructive
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * in that they will always empty the list.
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater */
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater clean_finds_at_name(name, ev, DNS_ADBFIND_ADDRESSMASK);
c82bb6a709abe89c051485b49403ef5bad1b756cTatuya JINMEI 神明達哉 result4 = clean_namehooks(adb, &name->v4);
c82bb6a709abe89c051485b49403ef5bad1b756cTatuya JINMEI 神明達哉 result6 = clean_namehooks(adb, &name->v6);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater clean_target(adb, &name->target);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater result = ISC_TF(result4 || result6);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater /*
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * If fetches are running, cancel them. If none are running, we can
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * just kill the name here.
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater */
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (!NAME_FETCH(name)) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater INSIST(result == ISC_FALSE);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater result = unlink_name(adb, name);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater free_adbname(adb, &name);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (result)
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater result = dec_adb_irefcnt(adb);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater } else {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater cancel_fetches_at_name(name);
c82bb6a709abe89c051485b49403ef5bad1b756cTatuya JINMEI 神明達哉 if (!NAME_DEAD(name)) {
c82bb6a709abe89c051485b49403ef5bad1b756cTatuya JINMEI 神明達哉 bucket = name->lock_bucket;
c82bb6a709abe89c051485b49403ef5bad1b756cTatuya JINMEI 神明達哉 ISC_LIST_UNLINK(adb->names[bucket], name, plink);
c82bb6a709abe89c051485b49403ef5bad1b756cTatuya JINMEI 神明達哉 ISC_LIST_APPEND(adb->deadnames[bucket], name, plink);
c82bb6a709abe89c051485b49403ef5bad1b756cTatuya JINMEI 神明達哉 name->flags |= NAME_IS_DEAD;
c82bb6a709abe89c051485b49403ef5bad1b756cTatuya JINMEI 神明達哉 }
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater }
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater return (result);
a253e35c2451818fb39f9b808c7641adb5275fb3Michael Graff}
a253e35c2451818fb39f9b808c7641adb5275fb3Michael Graff
ff9bb3fc5453bbf310b67c560fbf04a5c0fb60daMichael Graff/*
ff9bb3fc5453bbf310b67c560fbf04a5c0fb60daMichael Graff * Requires the name's bucket be locked and no entry buckets be locked.
ff9bb3fc5453bbf310b67c560fbf04a5c0fb60daMichael Graff */
e34efaccfaab4dbbe45edd0a58e2b6e930e5784bMichael Graffstatic isc_boolean_t
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graffcheck_expire_namehooks(dns_adbname_t *name, isc_stdtime_t now) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater dns_adb_t *adb;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater isc_boolean_t result4 = ISC_FALSE;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater isc_boolean_t result6 = ISC_FALSE;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater INSIST(DNS_ADBNAME_VALID(name));
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater adb = name->adb;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater INSIST(DNS_ADB_VALID(adb));
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater /*
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * Check to see if we need to remove the v4 addresses
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater */
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (!NAME_FETCH_V4(name) && EXPIRE_OK(name->expire_v4, now)) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (NAME_HAS_V4(name)) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater DP(DEF_LEVEL, "expiring v4 for name %p", name);
c82bb6a709abe89c051485b49403ef5bad1b756cTatuya JINMEI 神明達哉 result4 = clean_namehooks(adb, &name->v4);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater name->partial_result &= ~DNS_ADBFIND_INET;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater }
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater name->expire_v4 = INT_MAX;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater name->fetch_err = FIND_ERR_UNEXPECTED;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater }
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater /*
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * Check to see if we need to remove the v6 addresses
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater */
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (!NAME_FETCH_V6(name) && EXPIRE_OK(name->expire_v6, now)) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (NAME_HAS_V6(name)) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater DP(DEF_LEVEL, "expiring v6 for name %p", name);
c82bb6a709abe89c051485b49403ef5bad1b756cTatuya JINMEI 神明達哉 result6 = clean_namehooks(adb, &name->v6);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater name->partial_result &= ~DNS_ADBFIND_INET6;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater }
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater name->expire_v6 = INT_MAX;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater name->fetch6_err = FIND_ERR_UNEXPECTED;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater }
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater /*
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * Check to see if we need to remove the alias target.
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater */
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (EXPIRE_OK(name->expire_target, now)) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater clean_target(adb, &name->target);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater name->expire_target = INT_MAX;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater }
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater return (ISC_TF(result4 || result6));
ff9bb3fc5453bbf310b67c560fbf04a5c0fb60daMichael Graff}
ff9bb3fc5453bbf310b67c560fbf04a5c0fb60daMichael Graff
a253e35c2451818fb39f9b808c7641adb5275fb3Michael Graff/*
a253e35c2451818fb39f9b808c7641adb5275fb3Michael Graff * Requires the name's bucket be locked.
a253e35c2451818fb39f9b808c7641adb5275fb3Michael Graff */
a253e35c2451818fb39f9b808c7641adb5275fb3Michael Graffstatic inline void
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrencelink_name(dns_adb_t *adb, int bucket, dns_adbname_t *name) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater INSIST(name->lock_bucket == DNS_ADB_INVALIDBUCKET);
a253e35c2451818fb39f9b808c7641adb5275fb3Michael Graff
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater ISC_LIST_PREPEND(adb->names[bucket], name, plink);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater name->lock_bucket = bucket;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater adb->name_refcnt[bucket]++;
a253e35c2451818fb39f9b808c7641adb5275fb3Michael Graff}
a253e35c2451818fb39f9b808c7641adb5275fb3Michael Graff
a253e35c2451818fb39f9b808c7641adb5275fb3Michael Graff/*
a253e35c2451818fb39f9b808c7641adb5275fb3Michael Graff * Requires the name's bucket be locked.
a253e35c2451818fb39f9b808c7641adb5275fb3Michael Graff */
e34efaccfaab4dbbe45edd0a58e2b6e930e5784bMichael Graffstatic inline isc_boolean_t
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrenceunlink_name(dns_adb_t *adb, dns_adbname_t *name) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater int bucket;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater isc_boolean_t result = ISC_FALSE;
a253e35c2451818fb39f9b808c7641adb5275fb3Michael Graff
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater bucket = name->lock_bucket;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater INSIST(bucket != DNS_ADB_INVALIDBUCKET);
a253e35c2451818fb39f9b808c7641adb5275fb3Michael Graff
c82bb6a709abe89c051485b49403ef5bad1b756cTatuya JINMEI 神明達哉 if (NAME_DEAD(name))
c82bb6a709abe89c051485b49403ef5bad1b756cTatuya JINMEI 神明達哉 ISC_LIST_UNLINK(adb->deadnames[bucket], name, plink);
c82bb6a709abe89c051485b49403ef5bad1b756cTatuya JINMEI 神明達哉 else
c82bb6a709abe89c051485b49403ef5bad1b756cTatuya JINMEI 神明達哉 ISC_LIST_UNLINK(adb->names[bucket], name, plink);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater name->lock_bucket = DNS_ADB_INVALIDBUCKET;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater INSIST(adb->name_refcnt[bucket] > 0);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater adb->name_refcnt[bucket]--;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (adb->name_sd[bucket] && adb->name_refcnt[bucket] == 0)
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater result = ISC_TRUE;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater return (result);
a253e35c2451818fb39f9b808c7641adb5275fb3Michael Graff}
a385f150bb21b8b81f70ed7df545357a83f1da82Michael Graff
a44c12b332b867f29631e235eb11d1263c73d6c0Bob Halley/*
a44c12b332b867f29631e235eb11d1263c73d6c0Bob Halley * Requires the entry's bucket be locked.
a44c12b332b867f29631e235eb11d1263c73d6c0Bob Halley */
a44c12b332b867f29631e235eb11d1263c73d6c0Bob Halleystatic inline void
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrencelink_entry(dns_adb_t *adb, int bucket, dns_adbentry_t *entry) {
c82bb6a709abe89c051485b49403ef5bad1b756cTatuya JINMEI 神明達哉 int i;
c82bb6a709abe89c051485b49403ef5bad1b756cTatuya JINMEI 神明達哉 dns_adbentry_t *e;
c82bb6a709abe89c051485b49403ef5bad1b756cTatuya JINMEI 神明達哉
27fe1966c948ba0c1c9d0d831ea3d8bf32d052acTatuya JINMEI 神明達哉 if (isc_mem_isovermem(adb->mctx)) {
c82bb6a709abe89c051485b49403ef5bad1b756cTatuya JINMEI 神明達哉 for (i = 0; i < 2; i++) {
c82bb6a709abe89c051485b49403ef5bad1b756cTatuya JINMEI 神明達哉 e = ISC_LIST_TAIL(adb->entries[bucket]);
c82bb6a709abe89c051485b49403ef5bad1b756cTatuya JINMEI 神明達哉 if (e == NULL)
c82bb6a709abe89c051485b49403ef5bad1b756cTatuya JINMEI 神明達哉 break;
c82bb6a709abe89c051485b49403ef5bad1b756cTatuya JINMEI 神明達哉 if (e->refcnt == 0) {
c82bb6a709abe89c051485b49403ef5bad1b756cTatuya JINMEI 神明達哉 unlink_entry(adb, e);
c82bb6a709abe89c051485b49403ef5bad1b756cTatuya JINMEI 神明達哉 free_adbentry(adb, &e);
c82bb6a709abe89c051485b49403ef5bad1b756cTatuya JINMEI 神明達哉 continue;
c82bb6a709abe89c051485b49403ef5bad1b756cTatuya JINMEI 神明達哉 }
c82bb6a709abe89c051485b49403ef5bad1b756cTatuya JINMEI 神明達哉 INSIST((e->flags & ENTRY_IS_DEAD) == 0);
c82bb6a709abe89c051485b49403ef5bad1b756cTatuya JINMEI 神明達哉 e->flags |= ENTRY_IS_DEAD;
c82bb6a709abe89c051485b49403ef5bad1b756cTatuya JINMEI 神明達哉 ISC_LIST_UNLINK(adb->entries[bucket], e, plink);
c82bb6a709abe89c051485b49403ef5bad1b756cTatuya JINMEI 神明達哉 ISC_LIST_PREPEND(adb->deadentries[bucket], e, plink);
c82bb6a709abe89c051485b49403ef5bad1b756cTatuya JINMEI 神明達哉 }
c82bb6a709abe89c051485b49403ef5bad1b756cTatuya JINMEI 神明達哉 }
c82bb6a709abe89c051485b49403ef5bad1b756cTatuya JINMEI 神明達哉
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater ISC_LIST_PREPEND(adb->entries[bucket], entry, plink);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater entry->lock_bucket = bucket;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater adb->entry_refcnt[bucket]++;
a44c12b332b867f29631e235eb11d1263c73d6c0Bob Halley}
a44c12b332b867f29631e235eb11d1263c73d6c0Bob Halley
a44c12b332b867f29631e235eb11d1263c73d6c0Bob Halley/*
a44c12b332b867f29631e235eb11d1263c73d6c0Bob Halley * Requires the entry's bucket be locked.
a44c12b332b867f29631e235eb11d1263c73d6c0Bob Halley */
e34efaccfaab4dbbe45edd0a58e2b6e930e5784bMichael Graffstatic inline isc_boolean_t
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrenceunlink_entry(dns_adb_t *adb, dns_adbentry_t *entry) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater int bucket;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater isc_boolean_t result = ISC_FALSE;
a44c12b332b867f29631e235eb11d1263c73d6c0Bob Halley
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater bucket = entry->lock_bucket;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater INSIST(bucket != DNS_ADB_INVALIDBUCKET);
a44c12b332b867f29631e235eb11d1263c73d6c0Bob Halley
c82bb6a709abe89c051485b49403ef5bad1b756cTatuya JINMEI 神明達哉 if ((entry->flags & ENTRY_IS_DEAD) != 0)
c82bb6a709abe89c051485b49403ef5bad1b756cTatuya JINMEI 神明達哉 ISC_LIST_UNLINK(adb->deadentries[bucket], entry, plink);
c82bb6a709abe89c051485b49403ef5bad1b756cTatuya JINMEI 神明達哉 else
c82bb6a709abe89c051485b49403ef5bad1b756cTatuya JINMEI 神明達哉 ISC_LIST_UNLINK(adb->entries[bucket], entry, plink);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater entry->lock_bucket = DNS_ADB_INVALIDBUCKET;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater INSIST(adb->entry_refcnt[bucket] > 0);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater adb->entry_refcnt[bucket]--;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (adb->entry_sd[bucket] && adb->entry_refcnt[bucket] == 0)
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater result = ISC_TRUE;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater return (result);
a44c12b332b867f29631e235eb11d1263c73d6c0Bob Halley}
a44c12b332b867f29631e235eb11d1263c73d6c0Bob Halley
30251e07d1705d1a85b0e1d5a969496e1aed612eMichael Graffstatic inline void
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrenceviolate_locking_hierarchy(isc_mutex_t *have, isc_mutex_t *want) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (isc_mutex_trylock(want) != ISC_R_SUCCESS) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater UNLOCK(have);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater LOCK(want);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater LOCK(have);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater }
30251e07d1705d1a85b0e1d5a969496e1aed612eMichael Graff}
30251e07d1705d1a85b0e1d5a969496e1aed612eMichael Graff
30251e07d1705d1a85b0e1d5a969496e1aed612eMichael Graff/*
a385f150bb21b8b81f70ed7df545357a83f1da82Michael Graff * The ADB _MUST_ be locked before calling. Also, exit conditions must be
a385f150bb21b8b81f70ed7df545357a83f1da82Michael Graff * checked after calling this function.
30251e07d1705d1a85b0e1d5a969496e1aed612eMichael Graff */
e34efaccfaab4dbbe45edd0a58e2b6e930e5784bMichael Graffstatic isc_boolean_t
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrenceshutdown_names(dns_adb_t *adb) {
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews unsigned int bucket;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater isc_boolean_t result = ISC_FALSE;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater dns_adbname_t *name;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater dns_adbname_t *next_name;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews for (bucket = 0; bucket < adb->nnames; bucket++) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater LOCK(&adb->namelocks[bucket]);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater adb->name_sd[bucket] = ISC_TRUE;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater name = ISC_LIST_HEAD(adb->names[bucket]);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (name == NULL) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater /*
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * This bucket has no names. We must decrement the
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * irefcnt ourselves, since it will not be
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * automatically triggered by a name being unlinked.
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater */
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater INSIST(result == ISC_FALSE);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater result = dec_adb_irefcnt(adb);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater } else {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater /*
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * Run through the list. For each name, clean up finds
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * found there, and cancel any fetches running. When
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * all the fetches are canceled, the name will destroy
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * itself.
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater */
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater while (name != NULL) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater next_name = ISC_LIST_NEXT(name, plink);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater INSIST(result == ISC_FALSE);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater result = kill_name(&name,
c82bb6a709abe89c051485b49403ef5bad1b756cTatuya JINMEI 神明達哉 DNS_EVENT_ADBSHUTDOWN);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater name = next_name;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater }
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater }
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater UNLOCK(&adb->namelocks[bucket]);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater }
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater return (result);
30251e07d1705d1a85b0e1d5a969496e1aed612eMichael Graff}
30251e07d1705d1a85b0e1d5a969496e1aed612eMichael Graff
a44c12b332b867f29631e235eb11d1263c73d6c0Bob Halley/*
a44c12b332b867f29631e235eb11d1263c73d6c0Bob Halley * The ADB _MUST_ be locked before calling. Also, exit conditions must be
a44c12b332b867f29631e235eb11d1263c73d6c0Bob Halley * checked after calling this function.
a44c12b332b867f29631e235eb11d1263c73d6c0Bob Halley */
e34efaccfaab4dbbe45edd0a58e2b6e930e5784bMichael Graffstatic isc_boolean_t
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrenceshutdown_entries(dns_adb_t *adb) {
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews unsigned int bucket;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater isc_boolean_t result = ISC_FALSE;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater dns_adbentry_t *entry;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater dns_adbentry_t *next_entry;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews for (bucket = 0; bucket < adb->nentries; bucket++) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater LOCK(&adb->entrylocks[bucket]);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater adb->entry_sd[bucket] = ISC_TRUE;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater entry = ISC_LIST_HEAD(adb->entries[bucket]);
c82bb6a709abe89c051485b49403ef5bad1b756cTatuya JINMEI 神明達哉 if (adb->entry_refcnt[bucket] == 0) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater /*
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * This bucket has no entries. We must decrement the
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * irefcnt ourselves, since it will not be
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * automatically triggered by an entry being unlinked.
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater */
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater result = dec_adb_irefcnt(adb);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater } else {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater /*
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * Run through the list. Cleanup any entries not
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * associated with names, and which are not in use.
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater */
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater while (entry != NULL) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater next_entry = ISC_LIST_NEXT(entry, plink);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (entry->refcnt == 0 &&
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater entry->expires != 0) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater result = unlink_entry(adb, entry);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater free_adbentry(adb, &entry);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (result)
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater result = dec_adb_irefcnt(adb);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater }
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater entry = next_entry;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater }
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater }
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater UNLOCK(&adb->entrylocks[bucket]);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater }
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater return (result);
a44c12b332b867f29631e235eb11d1263c73d6c0Bob Halley}
a44c12b332b867f29631e235eb11d1263c73d6c0Bob Halley
a253e35c2451818fb39f9b808c7641adb5275fb3Michael Graff/*
a253e35c2451818fb39f9b808c7641adb5275fb3Michael Graff * Name bucket must be locked
a253e35c2451818fb39f9b808c7641adb5275fb3Michael Graff */
a253e35c2451818fb39f9b808c7641adb5275fb3Michael Graffstatic void
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrencecancel_fetches_at_name(dns_adbname_t *name) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (NAME_FETCH_A(name))
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater dns_resolver_cancelfetch(name->fetch_a->fetch);
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (NAME_FETCH_AAAA(name))
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater dns_resolver_cancelfetch(name->fetch_aaaa->fetch);
a253e35c2451818fb39f9b808c7641adb5275fb3Michael Graff}
a253e35c2451818fb39f9b808c7641adb5275fb3Michael Graff
f181f94ec8da8b1dbcc6353e8be965ea4a5ea282Michael Graff/*
f181f94ec8da8b1dbcc6353e8be965ea4a5ea282Michael Graff * Assumes the name bucket is locked.
f181f94ec8da8b1dbcc6353e8be965ea4a5ea282Michael Graff */
e34efaccfaab4dbbe45edd0a58e2b6e930e5784bMichael Graffstatic isc_boolean_t
c82bb6a709abe89c051485b49403ef5bad1b756cTatuya JINMEI 神明達哉clean_namehooks(dns_adb_t *adb, dns_adbnamehooklist_t *namehooks) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater dns_adbentry_t *entry;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater dns_adbnamehook_t *namehook;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater int addr_bucket;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater isc_boolean_t result = ISC_FALSE;
27fe1966c948ba0c1c9d0d831ea3d8bf32d052acTatuya JINMEI 神明達哉 isc_boolean_t overmem = isc_mem_isovermem(adb->mctx);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater addr_bucket = DNS_ADB_INVALIDBUCKET;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater namehook = ISC_LIST_HEAD(*namehooks);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater while (namehook != NULL) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater INSIST(DNS_ADBNAMEHOOK_VALID(namehook));
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater /*
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * Clean up the entry if needed.
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater */
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater entry = namehook->entry;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (entry != NULL) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater INSIST(DNS_ADBENTRY_VALID(entry));
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (addr_bucket != entry->lock_bucket) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (addr_bucket != DNS_ADB_INVALIDBUCKET)
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater UNLOCK(&adb->entrylocks[addr_bucket]);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater addr_bucket = entry->lock_bucket;
b1fb5abb506f6389f4d093b5066c9436b0ad3b2fMark Andrews INSIST(addr_bucket != DNS_ADB_INVALIDBUCKET);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater LOCK(&adb->entrylocks[addr_bucket]);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater }
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
27fe1966c948ba0c1c9d0d831ea3d8bf32d052acTatuya JINMEI 神明達哉 result = dec_entry_refcnt(adb, overmem, entry,
27fe1966c948ba0c1c9d0d831ea3d8bf32d052acTatuya JINMEI 神明達哉 ISC_FALSE);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater }
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater /*
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * Free the namehook
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater */
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater namehook->entry = NULL;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater ISC_LIST_UNLINK(*namehooks, namehook, plink);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater free_adbnamehook(adb, &namehook);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater namehook = ISC_LIST_HEAD(*namehooks);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater }
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (addr_bucket != DNS_ADB_INVALIDBUCKET)
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater UNLOCK(&adb->entrylocks[addr_bucket]);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater return (result);
30251e07d1705d1a85b0e1d5a969496e1aed612eMichael Graff}
30251e07d1705d1a85b0e1d5a969496e1aed612eMichael Graff
16508d9185e5eb96af2ebe900a08c46a6e5eb7edBob Halleystatic void
16508d9185e5eb96af2ebe900a08c46a6e5eb7edBob Halleyclean_target(dns_adb_t *adb, dns_name_t *target) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (dns_name_countlabels(target) > 0) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater dns_name_free(target, adb->mctx);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater dns_name_init(target, NULL);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater }
16508d9185e5eb96af2ebe900a08c46a6e5eb7edBob Halley}
16508d9185e5eb96af2ebe900a08c46a6e5eb7edBob Halley
16508d9185e5eb96af2ebe900a08c46a6e5eb7edBob Halleystatic isc_result_t
16508d9185e5eb96af2ebe900a08c46a6e5eb7edBob Halleyset_target(dns_adb_t *adb, dns_name_t *name, dns_name_t *fname,
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater dns_rdataset_t *rdataset, dns_name_t *target)
16508d9185e5eb96af2ebe900a08c46a6e5eb7edBob Halley{
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater isc_result_t result;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater dns_namereln_t namereln;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater unsigned int nlabels;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater int order;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater dns_rdata_t rdata = DNS_RDATA_INIT;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater dns_fixedname_t fixed1, fixed2;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater dns_name_t *prefix, *new_target;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater REQUIRE(dns_name_countlabels(target) == 0);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (rdataset->type == dns_rdatatype_cname) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater dns_rdata_cname_t cname;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater /*
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * Copy the CNAME's target into the target name.
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater */
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater result = dns_rdataset_first(rdataset);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (result != ISC_R_SUCCESS)
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater return (result);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater dns_rdataset_current(rdataset, &rdata);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater result = dns_rdata_tostruct(&rdata, &cname, NULL);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (result != ISC_R_SUCCESS)
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater return (result);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater result = dns_name_dup(&cname.cname, adb->mctx, target);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater dns_rdata_freestruct(&cname);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (result != ISC_R_SUCCESS)
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater return (result);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater } else {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater dns_rdata_dname_t dname;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater INSIST(rdataset->type == dns_rdatatype_dname);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater namereln = dns_name_fullcompare(name, fname, &order, &nlabels);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater INSIST(namereln == dns_namereln_subdomain);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater /*
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * Get the target name of the DNAME.
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater */
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater result = dns_rdataset_first(rdataset);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (result != ISC_R_SUCCESS)
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater return (result);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater dns_rdataset_current(rdataset, &rdata);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater result = dns_rdata_tostruct(&rdata, &dname, NULL);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (result != ISC_R_SUCCESS)
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater return (result);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater /*
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * Construct the new target name.
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater */
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater dns_fixedname_init(&fixed1);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater prefix = dns_fixedname_name(&fixed1);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater dns_fixedname_init(&fixed2);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater new_target = dns_fixedname_name(&fixed2);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater dns_name_split(name, nlabels, prefix, NULL);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater result = dns_name_concatenate(prefix, &dname.dname, new_target,
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater NULL);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater dns_rdata_freestruct(&dname);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (result != ISC_R_SUCCESS)
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater return (result);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater result = dns_name_dup(new_target, adb->mctx, target);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (result != ISC_R_SUCCESS)
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater return (result);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater }
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater return (ISC_R_SUCCESS);
16508d9185e5eb96af2ebe900a08c46a6e5eb7edBob Halley}
16508d9185e5eb96af2ebe900a08c46a6e5eb7edBob Halley
897c9ddb4d745b2bfecf98b17e5487bb6656299aMichael Graff/*
897c9ddb4d745b2bfecf98b17e5487bb6656299aMichael Graff * Assumes nothing is locked, since this is called by the client.
897c9ddb4d745b2bfecf98b17e5487bb6656299aMichael Graff */
897c9ddb4d745b2bfecf98b17e5487bb6656299aMichael Graffstatic void
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrenceevent_free(isc_event_t *event) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater dns_adbfind_t *find;
897c9ddb4d745b2bfecf98b17e5487bb6656299aMichael Graff
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater INSIST(event != NULL);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater find = event->ev_destroy_arg;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater INSIST(DNS_ADBFIND_VALID(find));
897c9ddb4d745b2bfecf98b17e5487bb6656299aMichael Graff
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater LOCK(&find->lock);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater find->flags |= FIND_EVENT_FREED;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater event->ev_destroy_arg = NULL;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater UNLOCK(&find->lock);
897c9ddb4d745b2bfecf98b17e5487bb6656299aMichael Graff}
897c9ddb4d745b2bfecf98b17e5487bb6656299aMichael Graff
f181f94ec8da8b1dbcc6353e8be965ea4a5ea282Michael Graff/*
f181f94ec8da8b1dbcc6353e8be965ea4a5ea282Michael Graff * Assumes the name bucket is locked.
f181f94ec8da8b1dbcc6353e8be965ea4a5ea282Michael Graff */
30251e07d1705d1a85b0e1d5a969496e1aed612eMichael Graffstatic void
4281fe4a80af7402613f0d5c3eeff8829a4ede1fMichael Graffclean_finds_at_name(dns_adbname_t *name, isc_eventtype_t evtype,
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater unsigned int addrs)
30251e07d1705d1a85b0e1d5a969496e1aed612eMichael Graff{
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater isc_event_t *ev;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater isc_task_t *task;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater dns_adbfind_t *find;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater dns_adbfind_t *next_find;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater isc_boolean_t process;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater unsigned int wanted, notify;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater DP(ENTER_LEVEL,
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater "ENTER clean_finds_at_name, name %p, evtype %08x, addrs %08x",
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater name, evtype, addrs);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater find = ISC_LIST_HEAD(name->finds);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater while (find != NULL) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater LOCK(&find->lock);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater next_find = ISC_LIST_NEXT(find, plink);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater process = ISC_FALSE;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater wanted = find->flags & DNS_ADBFIND_ADDRESSMASK;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater notify = wanted & addrs;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater switch (evtype) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater case DNS_EVENT_ADBMOREADDRESSES:
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater DP(ISC_LOG_DEBUG(3), "DNS_EVENT_ADBMOREADDRESSES");
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if ((notify) != 0) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater find->flags &= ~addrs;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater process = ISC_TRUE;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater }
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater break;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater case DNS_EVENT_ADBNOMOREADDRESSES:
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater DP(ISC_LOG_DEBUG(3), "DNS_EVENT_ADBNOMOREADDRESSES");
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater find->flags &= ~addrs;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater wanted = find->flags & DNS_ADBFIND_ADDRESSMASK;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (wanted == 0)
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater process = ISC_TRUE;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater break;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater default:
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater find->flags &= ~addrs;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater process = ISC_TRUE;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater }
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (process) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater DP(DEF_LEVEL, "cfan: processing find %p", find);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater /*
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * Unlink the find from the name, letting the caller
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * call dns_adb_destroyfind() on it to clean it up
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * later.
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater */
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater ISC_LIST_UNLINK(name->finds, find, plink);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater find->adbname = NULL;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater find->name_bucket = DNS_ADB_INVALIDBUCKET;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater INSIST(!FIND_EVENTSENT(find));
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater ev = &find->event;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater task = ev->ev_sender;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater ev->ev_sender = find;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater find->result_v4 = find_err_map[name->fetch_err];
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater find->result_v6 = find_err_map[name->fetch6_err];
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater ev->ev_type = evtype;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater ev->ev_destroy = event_free;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater ev->ev_destroy_arg = find;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater DP(DEF_LEVEL,
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater "sending event %p to task %p for find %p",
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater ev, task, find);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater isc_task_sendanddetach(&task, (isc_event_t **)&ev);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater } else {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater DP(DEF_LEVEL, "cfan: skipping find %p", find);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater }
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater UNLOCK(&find->lock);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater find = next_find;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater }
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater DP(ENTER_LEVEL, "EXIT clean_finds_at_name, name %p", name);
30251e07d1705d1a85b0e1d5a969496e1aed612eMichael Graff}
30251e07d1705d1a85b0e1d5a969496e1aed612eMichael Graff
a253e35c2451818fb39f9b808c7641adb5275fb3Michael Graffstatic inline void
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrencecheck_exit(dns_adb_t *adb) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater isc_event_t *event;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater /*
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * The caller must be holding the adb lock.
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater */
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (adb->shutting_down) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater /*
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * If there aren't any external references either, we're
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * done. Send the control event to initiate shutdown.
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater */
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater INSIST(!adb->cevent_sent); /* Sanity check. */
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater event = &adb->cevent;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater isc_task_send(adb->task, &event);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater adb->cevent_sent = ISC_TRUE;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater }
e34efaccfaab4dbbe45edd0a58e2b6e930e5784bMichael Graff}
e34efaccfaab4dbbe45edd0a58e2b6e930e5784bMichael Graff
e34efaccfaab4dbbe45edd0a58e2b6e930e5784bMichael Graffstatic inline isc_boolean_t
e34efaccfaab4dbbe45edd0a58e2b6e930e5784bMichael Graffdec_adb_irefcnt(dns_adb_t *adb) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater isc_event_t *event;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater isc_task_t *etask;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater isc_boolean_t result = ISC_FALSE;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater LOCK(&adb->reflock);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater INSIST(adb->irefcnt > 0);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater adb->irefcnt--;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (adb->irefcnt == 0) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater event = ISC_LIST_HEAD(adb->whenshutdown);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater while (event != NULL) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater ISC_LIST_UNLINK(adb->whenshutdown, event, ev_link);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater etask = event->ev_sender;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater event->ev_sender = adb;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater isc_task_sendanddetach(&etask, &event);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater event = ISC_LIST_HEAD(adb->whenshutdown);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater }
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater }
e34efaccfaab4dbbe45edd0a58e2b6e930e5784bMichael Graff
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (adb->irefcnt == 0 && adb->erefcnt == 0)
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater result = ISC_TRUE;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater UNLOCK(&adb->reflock);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater return (result);
a385f150bb21b8b81f70ed7df545357a83f1da82Michael Graff}
a385f150bb21b8b81f70ed7df545357a83f1da82Michael Graff
30251e07d1705d1a85b0e1d5a969496e1aed612eMichael Graffstatic inline void
e34efaccfaab4dbbe45edd0a58e2b6e930e5784bMichael Graffinc_adb_irefcnt(dns_adb_t *adb) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater LOCK(&adb->reflock);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater adb->irefcnt++;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater UNLOCK(&adb->reflock);
30251e07d1705d1a85b0e1d5a969496e1aed612eMichael Graff}
e51511aa3281f8dc384eb1283115c7f8d5c402aeMichael Graff
e51511aa3281f8dc384eb1283115c7f8d5c402aeMichael Graffstatic inline void
78bf1ca89505820ed7b03be4bf0c0b53b557f3cdAndreas Gustafssoninc_adb_erefcnt(dns_adb_t *adb) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater LOCK(&adb->reflock);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater adb->erefcnt++;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater UNLOCK(&adb->reflock);
e51511aa3281f8dc384eb1283115c7f8d5c402aeMichael Graff}
e51511aa3281f8dc384eb1283115c7f8d5c402aeMichael Graff
439c0011e642fb1d26011116144af698125262dbMichael Graffstatic inline void
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrenceinc_entry_refcnt(dns_adb_t *adb, dns_adbentry_t *entry, isc_boolean_t lock) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater int bucket;
439c0011e642fb1d26011116144af698125262dbMichael Graff
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater bucket = entry->lock_bucket;
439c0011e642fb1d26011116144af698125262dbMichael Graff
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (lock)
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater LOCK(&adb->entrylocks[bucket]);
439c0011e642fb1d26011116144af698125262dbMichael Graff
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater entry->refcnt++;
439c0011e642fb1d26011116144af698125262dbMichael Graff
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (lock)
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater UNLOCK(&adb->entrylocks[bucket]);
439c0011e642fb1d26011116144af698125262dbMichael Graff}
439c0011e642fb1d26011116144af698125262dbMichael Graff
e34efaccfaab4dbbe45edd0a58e2b6e930e5784bMichael Graffstatic inline isc_boolean_t
27fe1966c948ba0c1c9d0d831ea3d8bf32d052acTatuya JINMEI 神明達哉dec_entry_refcnt(dns_adb_t *adb, isc_boolean_t overmem, dns_adbentry_t *entry,
27fe1966c948ba0c1c9d0d831ea3d8bf32d052acTatuya JINMEI 神明達哉 isc_boolean_t lock)
27fe1966c948ba0c1c9d0d831ea3d8bf32d052acTatuya JINMEI 神明達哉{
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater int bucket;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater isc_boolean_t destroy_entry;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater isc_boolean_t result = ISC_FALSE;
439c0011e642fb1d26011116144af698125262dbMichael Graff
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater bucket = entry->lock_bucket;
439c0011e642fb1d26011116144af698125262dbMichael Graff
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (lock)
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater LOCK(&adb->entrylocks[bucket]);
439c0011e642fb1d26011116144af698125262dbMichael Graff
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater INSIST(entry->refcnt > 0);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater entry->refcnt--;
439c0011e642fb1d26011116144af698125262dbMichael Graff
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater destroy_entry = ISC_FALSE;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (entry->refcnt == 0 &&
27fe1966c948ba0c1c9d0d831ea3d8bf32d052acTatuya JINMEI 神明達哉 (adb->entry_sd[bucket] || entry->expires == 0 || overmem ||
c82bb6a709abe89c051485b49403ef5bad1b756cTatuya JINMEI 神明達哉 (entry->flags & ENTRY_IS_DEAD) != 0)) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater destroy_entry = ISC_TRUE;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater result = unlink_entry(adb, entry);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater }
439c0011e642fb1d26011116144af698125262dbMichael Graff
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (lock)
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater UNLOCK(&adb->entrylocks[bucket]);
439c0011e642fb1d26011116144af698125262dbMichael Graff
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (!destroy_entry)
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater return (result);
439c0011e642fb1d26011116144af698125262dbMichael Graff
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater entry->lock_bucket = DNS_ADB_INVALIDBUCKET;
439c0011e642fb1d26011116144af698125262dbMichael Graff
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater free_adbentry(adb, &entry);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (result)
816496b22114ee7c2c15321c2c6cc4be77fdf822Mark Andrews result = dec_adb_irefcnt(adb);
5f1f24822fabe7b78af5f81553bfc11a170326c3Mark Andrews
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater return (result);
439c0011e642fb1d26011116144af698125262dbMichael Graff}
439c0011e642fb1d26011116144af698125262dbMichael Graff
e51511aa3281f8dc384eb1283115c7f8d5c402aeMichael Graffstatic inline dns_adbname_t *
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrencenew_adbname(dns_adb_t *adb, dns_name_t *dnsname) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater dns_adbname_t *name;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater name = isc_mempool_get(adb->nmp);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (name == NULL)
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater return (NULL);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater dns_name_init(&name->name, NULL);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (dns_name_dup(dnsname, adb->mctx, &name->name) != ISC_R_SUCCESS) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater isc_mempool_put(adb->nmp, name);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater return (NULL);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater }
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater dns_name_init(&name->target, NULL);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater name->magic = DNS_ADBNAME_MAGIC;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater name->adb = adb;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater name->partial_result = 0;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater name->flags = 0;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater name->expire_v4 = INT_MAX;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater name->expire_v6 = INT_MAX;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater name->expire_target = INT_MAX;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater name->chains = 0;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater name->lock_bucket = DNS_ADB_INVALIDBUCKET;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater ISC_LIST_INIT(name->v4);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater ISC_LIST_INIT(name->v6);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater name->fetch_a = NULL;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater name->fetch_aaaa = NULL;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater name->fetch_err = FIND_ERR_UNEXPECTED;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater name->fetch6_err = FIND_ERR_UNEXPECTED;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater ISC_LIST_INIT(name->finds);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater ISC_LINK_INIT(name, plink);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews LOCK(&adb->namescntlock);
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews adb->namescnt++;
dd2a0a6d2dec1c23787351e51b434a838dec5603Evan Hunt inc_adbstats(adb, dns_adbstats_namescnt);
c965b1869024ab38518fade703cc1dae2d71a59eMark Andrews if (!adb->grownames_sent && adb->excl != NULL &&
c965b1869024ab38518fade703cc1dae2d71a59eMark Andrews adb->namescnt > (adb->nnames * 8))
c965b1869024ab38518fade703cc1dae2d71a59eMark Andrews {
8868ef9c6411a51697749be54328ed78d2d8be96Automatic Updater isc_event_t *event = &adb->grownames;
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews inc_adb_irefcnt(adb);
c965b1869024ab38518fade703cc1dae2d71a59eMark Andrews isc_task_send(adb->excl, &event);
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews adb->grownames_sent = ISC_TRUE;
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews }
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews UNLOCK(&adb->namescntlock);
8868ef9c6411a51697749be54328ed78d2d8be96Automatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater return (name);
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff}
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff
e51511aa3281f8dc384eb1283115c7f8d5c402aeMichael Graffstatic inline void
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrencefree_adbname(dns_adb_t *adb, dns_adbname_t **name) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater dns_adbname_t *n;
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater INSIST(name != NULL && DNS_ADBNAME_VALID(*name));
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater n = *name;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater *name = NULL;
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater INSIST(!NAME_HAS_V4(n));
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater INSIST(!NAME_HAS_V6(n));
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater INSIST(!NAME_FETCH(n));
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater INSIST(ISC_LIST_EMPTY(n->finds));
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater INSIST(!ISC_LINK_LINKED(n, plink));
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater INSIST(n->lock_bucket == DNS_ADB_INVALIDBUCKET);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater INSIST(n->adb == adb);
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater n->magic = 0;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater dns_name_free(&n->name, adb->mctx);
64828244e04e86dfa40f0a4f0c05f27923da499dMichael Graff
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater isc_mempool_put(adb->nmp, n);
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews LOCK(&adb->namescntlock);
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews adb->namescnt--;
dd2a0a6d2dec1c23787351e51b434a838dec5603Evan Hunt dec_adbstats(adb, dns_adbstats_namescnt);
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews UNLOCK(&adb->namescntlock);
64828244e04e86dfa40f0a4f0c05f27923da499dMichael Graff}
64828244e04e86dfa40f0a4f0c05f27923da499dMichael Graff
e51511aa3281f8dc384eb1283115c7f8d5c402aeMichael Graffstatic inline dns_adbnamehook_t *
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrencenew_adbnamehook(dns_adb_t *adb, dns_adbentry_t *entry) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater dns_adbnamehook_t *nh;
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater nh = isc_mempool_get(adb->nhmp);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (nh == NULL)
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater return (NULL);
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater nh->magic = DNS_ADBNAMEHOOK_MAGIC;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater nh->entry = entry;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater ISC_LINK_INIT(nh, plink);
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater return (nh);
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff}
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff
e51511aa3281f8dc384eb1283115c7f8d5c402aeMichael Graffstatic inline void
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrencefree_adbnamehook(dns_adb_t *adb, dns_adbnamehook_t **namehook) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater dns_adbnamehook_t *nh;
64828244e04e86dfa40f0a4f0c05f27923da499dMichael Graff
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater INSIST(namehook != NULL && DNS_ADBNAMEHOOK_VALID(*namehook));
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater nh = *namehook;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater *namehook = NULL;
64828244e04e86dfa40f0a4f0c05f27923da499dMichael Graff
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater INSIST(nh->entry == NULL);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater INSIST(!ISC_LINK_LINKED(nh, plink));
64828244e04e86dfa40f0a4f0c05f27923da499dMichael Graff
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater nh->magic = 0;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater isc_mempool_put(adb->nhmp, nh);
64828244e04e86dfa40f0a4f0c05f27923da499dMichael Graff}
64828244e04e86dfa40f0a4f0c05f27923da499dMichael Graff
bcf369e513a1cc2209e2a987f5772afa79813540Mark Andrewsstatic inline dns_adblameinfo_t *
bcf369e513a1cc2209e2a987f5772afa79813540Mark Andrewsnew_adblameinfo(dns_adb_t *adb, dns_name_t *qname, dns_rdatatype_t qtype) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater dns_adblameinfo_t *li;
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater li = isc_mempool_get(adb->limp);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (li == NULL)
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater return (NULL);
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater dns_name_init(&li->qname, NULL);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (dns_name_dup(qname, adb->mctx, &li->qname) != ISC_R_SUCCESS) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater isc_mempool_put(adb->limp, li);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater return (NULL);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater }
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater li->magic = DNS_ADBLAMEINFO_MAGIC;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater li->lame_timer = 0;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater li->qtype = qtype;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater ISC_LINK_INIT(li, plink);
f36a81c88493985ee2d1c53cc6fe88f4b00dbbc8Michael Graff
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater return (li);
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff}
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff
439c0011e642fb1d26011116144af698125262dbMichael Graffstatic inline void
bcf369e513a1cc2209e2a987f5772afa79813540Mark Andrewsfree_adblameinfo(dns_adb_t *adb, dns_adblameinfo_t **lameinfo) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater dns_adblameinfo_t *li;
439c0011e642fb1d26011116144af698125262dbMichael Graff
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater INSIST(lameinfo != NULL && DNS_ADBLAMEINFO_VALID(*lameinfo));
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater li = *lameinfo;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater *lameinfo = NULL;
439c0011e642fb1d26011116144af698125262dbMichael Graff
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater INSIST(!ISC_LINK_LINKED(li, plink));
439c0011e642fb1d26011116144af698125262dbMichael Graff
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater dns_name_free(&li->qname, adb->mctx);
439c0011e642fb1d26011116144af698125262dbMichael Graff
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater li->magic = 0;
439c0011e642fb1d26011116144af698125262dbMichael Graff
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater isc_mempool_put(adb->limp, li);
439c0011e642fb1d26011116144af698125262dbMichael Graff}
439c0011e642fb1d26011116144af698125262dbMichael Graff
e51511aa3281f8dc384eb1283115c7f8d5c402aeMichael Graffstatic inline dns_adbentry_t *
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrencenew_adbentry(dns_adb_t *adb) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater dns_adbentry_t *e;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater isc_uint32_t r;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater e = isc_mempool_get(adb->emp);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (e == NULL)
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater return (NULL);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater e->magic = DNS_ADBENTRY_MAGIC;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater e->lock_bucket = DNS_ADB_INVALIDBUCKET;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater e->refcnt = 0;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater e->flags = 0;
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews e->udpsize = 0;
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews e->edns = 0;
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews e->plain = 0;
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews e->plainto = 0;
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews e->to4096 = 0;
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews e->to1432 = 0;
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews e->to1232 = 0;
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews e->to512 = 0;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater isc_random_get(&r);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater e->srtt = (r & 0x1f) + 1;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater e->expires = 0;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater ISC_LIST_INIT(e->lameinfo);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater ISC_LINK_INIT(e, plink);
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews LOCK(&adb->entriescntlock);
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews adb->entriescnt++;
dd2a0a6d2dec1c23787351e51b434a838dec5603Evan Hunt inc_adbstats(adb, dns_adbstats_entriescnt);
c965b1869024ab38518fade703cc1dae2d71a59eMark Andrews if (!adb->growentries_sent && adb->growentries_sent &&
c965b1869024ab38518fade703cc1dae2d71a59eMark Andrews adb->entriescnt > (adb->nentries * 8))
c965b1869024ab38518fade703cc1dae2d71a59eMark Andrews {
8868ef9c6411a51697749be54328ed78d2d8be96Automatic Updater isc_event_t *event = &adb->growentries;
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews inc_adb_irefcnt(adb);
8868ef9c6411a51697749be54328ed78d2d8be96Automatic Updater isc_task_send(adb->task, &event);
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews adb->growentries_sent = ISC_TRUE;
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews }
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews UNLOCK(&adb->entriescntlock);
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater return (e);
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff}
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff
e51511aa3281f8dc384eb1283115c7f8d5c402aeMichael Graffstatic inline void
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrencefree_adbentry(dns_adb_t *adb, dns_adbentry_t **entry) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater dns_adbentry_t *e;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater dns_adblameinfo_t *li;
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater INSIST(entry != NULL && DNS_ADBENTRY_VALID(*entry));
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater e = *entry;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater *entry = NULL;
6d14fe95e9ea5bbc5e863e5aab4618f7b3dbcc0fMichael Graff
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater INSIST(e->lock_bucket == DNS_ADB_INVALIDBUCKET);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater INSIST(e->refcnt == 0);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater INSIST(!ISC_LINK_LINKED(e, plink));
64828244e04e86dfa40f0a4f0c05f27923da499dMichael Graff
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater e->magic = 0;
64828244e04e86dfa40f0a4f0c05f27923da499dMichael Graff
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater li = ISC_LIST_HEAD(e->lameinfo);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater while (li != NULL) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater ISC_LIST_UNLINK(e->lameinfo, li, plink);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater free_adblameinfo(adb, &li);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater li = ISC_LIST_HEAD(e->lameinfo);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater }
3f6a66689410910ef601a4d26f10a24f331ef83cMichael Graff
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater isc_mempool_put(adb->emp, e);
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews LOCK(&adb->entriescntlock);
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews adb->entriescnt--;
dd2a0a6d2dec1c23787351e51b434a838dec5603Evan Hunt dec_adbstats(adb, dns_adbstats_entriescnt);
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews UNLOCK(&adb->entriescntlock);
64828244e04e86dfa40f0a4f0c05f27923da499dMichael Graff}
64828244e04e86dfa40f0a4f0c05f27923da499dMichael Graff
2992344aacdb08e4af936c176d49ef789f5673ddMichael Graffstatic inline dns_adbfind_t *
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrencenew_adbfind(dns_adb_t *adb) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater dns_adbfind_t *h;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater isc_result_t result;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater h = isc_mempool_get(adb->ahmp);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (h == NULL)
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater return (NULL);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater /*
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * Public members.
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater */
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater h->magic = 0;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater h->adb = adb;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater h->partial_result = 0;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater h->options = 0;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater h->flags = 0;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater h->result_v4 = ISC_R_UNEXPECTED;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater h->result_v6 = ISC_R_UNEXPECTED;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater ISC_LINK_INIT(h, publink);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater ISC_LINK_INIT(h, plink);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater ISC_LIST_INIT(h->list);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater h->adbname = NULL;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater h->name_bucket = DNS_ADB_INVALIDBUCKET;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater /*
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * private members
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater */
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater result = isc_mutex_init(&h->lock);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (result != ISC_R_SUCCESS) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater isc_mempool_put(adb->ahmp, h);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater return (NULL);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater }
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater ISC_EVENT_INIT(&h->event, sizeof(isc_event_t), 0, 0, 0, NULL, NULL,
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater NULL, NULL, h);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater inc_adb_irefcnt(adb);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater h->magic = DNS_ADBFIND_MAGIC;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater return (h);
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff}
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff
bb143613cf26e0f27dfd9caf1a7336065d064b26Michael Graffstatic inline dns_adbfetch_t *
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrencenew_adbfetch(dns_adb_t *adb) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater dns_adbfetch_t *f;
bb143613cf26e0f27dfd9caf1a7336065d064b26Michael Graff
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater f = isc_mempool_get(adb->afmp);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (f == NULL)
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater return (NULL);
bb143613cf26e0f27dfd9caf1a7336065d064b26Michael Graff
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater f->magic = 0;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater f->fetch = NULL;
bb143613cf26e0f27dfd9caf1a7336065d064b26Michael Graff
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater dns_rdataset_init(&f->rdataset);
bb143613cf26e0f27dfd9caf1a7336065d064b26Michael Graff
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater f->magic = DNS_ADBFETCH_MAGIC;
bb143613cf26e0f27dfd9caf1a7336065d064b26Michael Graff
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater return (f);
bb143613cf26e0f27dfd9caf1a7336065d064b26Michael Graff}
bb143613cf26e0f27dfd9caf1a7336065d064b26Michael Graff
bb143613cf26e0f27dfd9caf1a7336065d064b26Michael Graffstatic inline void
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrencefree_adbfetch(dns_adb_t *adb, dns_adbfetch_t **fetch) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater dns_adbfetch_t *f;
bb143613cf26e0f27dfd9caf1a7336065d064b26Michael Graff
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater INSIST(fetch != NULL && DNS_ADBFETCH_VALID(*fetch));
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater f = *fetch;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater *fetch = NULL;
bb143613cf26e0f27dfd9caf1a7336065d064b26Michael Graff
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater f->magic = 0;
bb143613cf26e0f27dfd9caf1a7336065d064b26Michael Graff
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (dns_rdataset_isassociated(&f->rdataset))
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater dns_rdataset_disassociate(&f->rdataset);
bb143613cf26e0f27dfd9caf1a7336065d064b26Michael Graff
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater isc_mempool_put(adb->afmp, f);
bb143613cf26e0f27dfd9caf1a7336065d064b26Michael Graff}
bb143613cf26e0f27dfd9caf1a7336065d064b26Michael Graff
e34efaccfaab4dbbe45edd0a58e2b6e930e5784bMichael Graffstatic inline isc_boolean_t
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrencefree_adbfind(dns_adb_t *adb, dns_adbfind_t **findp) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater dns_adbfind_t *find;
439c0011e642fb1d26011116144af698125262dbMichael Graff
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater INSIST(findp != NULL && DNS_ADBFIND_VALID(*findp));
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater find = *findp;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater *findp = NULL;
439c0011e642fb1d26011116144af698125262dbMichael Graff
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater INSIST(!FIND_HAS_ADDRS(find));
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater INSIST(!ISC_LINK_LINKED(find, publink));
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater INSIST(!ISC_LINK_LINKED(find, plink));
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater INSIST(find->name_bucket == DNS_ADB_INVALIDBUCKET);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater INSIST(find->adbname == NULL);
6d14fe95e9ea5bbc5e863e5aab4618f7b3dbcc0fMichael Graff
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater find->magic = 0;
439c0011e642fb1d26011116144af698125262dbMichael Graff
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater DESTROYLOCK(&find->lock);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater isc_mempool_put(adb->ahmp, find);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater return (dec_adb_irefcnt(adb));
439c0011e642fb1d26011116144af698125262dbMichael Graff}
439c0011e642fb1d26011116144af698125262dbMichael Graff
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff/*
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff * Copy bits from the entry into the newly allocated addrinfo. The entry
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff * must be locked, and the reference count must be bumped up by one
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff * if this function returns a valid pointer.
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graff */
e51511aa3281f8dc384eb1283115c7f8d5c402aeMichael Graffstatic inline dns_adbaddrinfo_t *
d98c74e2ec5b96bd22aa4ed6d893e8993787493bMichael Graffnew_adbaddrinfo(dns_adb_t *adb, dns_adbentry_t *entry, in_port_t port) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater dns_adbaddrinfo_t *ai;
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater ai = isc_mempool_get(adb->aimp);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (ai == NULL)
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater return (NULL);
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater ai->magic = DNS_ADBADDRINFO_MAGIC;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater ai->sockaddr = entry->sockaddr;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater isc_sockaddr_setport(&ai->sockaddr, port);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater ai->srtt = entry->srtt;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater ai->flags = entry->flags;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater ai->entry = entry;
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt ai->dscp = -1;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater ISC_LINK_INIT(ai, publink);
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater return (ai);
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff}
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff
6d14fe95e9ea5bbc5e863e5aab4618f7b3dbcc0fMichael Graffstatic inline void
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrencefree_adbaddrinfo(dns_adb_t *adb, dns_adbaddrinfo_t **ainfo) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater dns_adbaddrinfo_t *ai;
6d14fe95e9ea5bbc5e863e5aab4618f7b3dbcc0fMichael Graff
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater INSIST(ainfo != NULL && DNS_ADBADDRINFO_VALID(*ainfo));
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater ai = *ainfo;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater *ainfo = NULL;
6d14fe95e9ea5bbc5e863e5aab4618f7b3dbcc0fMichael Graff
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater INSIST(ai->entry == NULL);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater INSIST(!ISC_LINK_LINKED(ai, publink));
6d14fe95e9ea5bbc5e863e5aab4618f7b3dbcc0fMichael Graff
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater ai->magic = 0;
6d14fe95e9ea5bbc5e863e5aab4618f7b3dbcc0fMichael Graff
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater isc_mempool_put(adb->aimp, ai);
6d14fe95e9ea5bbc5e863e5aab4618f7b3dbcc0fMichael Graff}
6d14fe95e9ea5bbc5e863e5aab4618f7b3dbcc0fMichael Graff
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff/*
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff * Search for the name. NOTE: The bucket is kept locked on both
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff * success and failure, so it must always be unlocked by the caller!
64828244e04e86dfa40f0a4f0c05f27923da499dMichael Graff *
64828244e04e86dfa40f0a4f0c05f27923da499dMichael Graff * On the first call to this function, *bucketp must be set to
64828244e04e86dfa40f0a4f0c05f27923da499dMichael Graff * DNS_ADB_INVALIDBUCKET.
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff */
e51511aa3281f8dc384eb1283115c7f8d5c402aeMichael Graffstatic inline dns_adbname_t *
1a0e33bc2044e1902493111db14cbf793083ac47Michael Grafffind_name_and_lock(dns_adb_t *adb, dns_name_t *name,
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater unsigned int options, int *bucketp)
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff{
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater dns_adbname_t *adbname;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater int bucket;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews bucket = dns_name_fullhash(name, ISC_FALSE) % adb->nnames;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (*bucketp == DNS_ADB_INVALIDBUCKET) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater LOCK(&adb->namelocks[bucket]);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater *bucketp = bucket;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater } else if (*bucketp != bucket) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater UNLOCK(&adb->namelocks[*bucketp]);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater LOCK(&adb->namelocks[bucket]);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater *bucketp = bucket;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater }
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater adbname = ISC_LIST_HEAD(adb->names[bucket]);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater while (adbname != NULL) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (!NAME_DEAD(adbname)) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (dns_name_equal(name, &adbname->name)
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater && GLUEHINT_OK(adbname, options)
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater && STARTATZONE_MATCHES(adbname, options))
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater return (adbname);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater }
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater adbname = ISC_LIST_NEXT(adbname, plink);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater }
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater return (NULL);
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff}
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff/*
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff * Search for the address. NOTE: The bucket is kept locked on both
64828244e04e86dfa40f0a4f0c05f27923da499dMichael Graff * success and failure, so it must always be unlocked by the caller.
64828244e04e86dfa40f0a4f0c05f27923da499dMichael Graff *
64828244e04e86dfa40f0a4f0c05f27923da499dMichael Graff * On the first call to this function, *bucketp must be set to
64828244e04e86dfa40f0a4f0c05f27923da499dMichael Graff * DNS_ADB_INVALIDBUCKET. This will cause a lock to occur. On
64828244e04e86dfa40f0a4f0c05f27923da499dMichael Graff * later calls (within the same "lock path") it can be left alone, so
64828244e04e86dfa40f0a4f0c05f27923da499dMichael Graff * if this function is called multiple times locking is only done if
64828244e04e86dfa40f0a4f0c05f27923da499dMichael Graff * the bucket changes.
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff */
e51511aa3281f8dc384eb1283115c7f8d5c402aeMichael Graffstatic inline dns_adbentry_t *
c82bb6a709abe89c051485b49403ef5bad1b756cTatuya JINMEI 神明達哉find_entry_and_lock(dns_adb_t *adb, isc_sockaddr_t *addr, int *bucketp,
c82bb6a709abe89c051485b49403ef5bad1b756cTatuya JINMEI 神明達哉 isc_stdtime_t now)
c82bb6a709abe89c051485b49403ef5bad1b756cTatuya JINMEI 神明達哉{
c82bb6a709abe89c051485b49403ef5bad1b756cTatuya JINMEI 神明達哉 dns_adbentry_t *entry, *entry_next;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater int bucket;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews bucket = isc_sockaddr_hash(addr, ISC_TRUE) % adb->nentries;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (*bucketp == DNS_ADB_INVALIDBUCKET) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater LOCK(&adb->entrylocks[bucket]);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater *bucketp = bucket;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater } else if (*bucketp != bucket) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater UNLOCK(&adb->entrylocks[*bucketp]);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater LOCK(&adb->entrylocks[bucket]);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater *bucketp = bucket;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater }
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff
c82bb6a709abe89c051485b49403ef5bad1b756cTatuya JINMEI 神明達哉 /* Search the list, while cleaning up expired entries. */
c82bb6a709abe89c051485b49403ef5bad1b756cTatuya JINMEI 神明達哉 for (entry = ISC_LIST_HEAD(adb->entries[bucket]);
c82bb6a709abe89c051485b49403ef5bad1b756cTatuya JINMEI 神明達哉 entry != NULL;
c82bb6a709abe89c051485b49403ef5bad1b756cTatuya JINMEI 神明達哉 entry = entry_next) {
c82bb6a709abe89c051485b49403ef5bad1b756cTatuya JINMEI 神明達哉 entry_next = ISC_LIST_NEXT(entry, plink);
c82bb6a709abe89c051485b49403ef5bad1b756cTatuya JINMEI 神明達哉 (void)check_expire_entry(adb, &entry, now);
c82bb6a709abe89c051485b49403ef5bad1b756cTatuya JINMEI 神明達哉 if (entry != NULL &&
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews (entry->expires == 0 || entry->expires > now) &&
c82bb6a709abe89c051485b49403ef5bad1b756cTatuya JINMEI 神明達哉 isc_sockaddr_equal(addr, &entry->sockaddr)) {
c82bb6a709abe89c051485b49403ef5bad1b756cTatuya JINMEI 神明達哉 ISC_LIST_UNLINK(adb->entries[bucket], entry, plink);
c82bb6a709abe89c051485b49403ef5bad1b756cTatuya JINMEI 神明達哉 ISC_LIST_PREPEND(adb->entries[bucket], entry, plink);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater return (entry);
c82bb6a709abe89c051485b49403ef5bad1b756cTatuya JINMEI 神明達哉 }
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater }
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater return (NULL);
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff}
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graff
d8590892d10fc9528b0dde7e2781935e7b8d7a87Michael Graff/*
d8590892d10fc9528b0dde7e2781935e7b8d7a87Michael Graff * Entry bucket MUST be locked!
d8590892d10fc9528b0dde7e2781935e7b8d7a87Michael Graff */
d8590892d10fc9528b0dde7e2781935e7b8d7a87Michael Graffstatic isc_boolean_t
bcf369e513a1cc2209e2a987f5772afa79813540Mark Andrewsentry_is_lame(dns_adb_t *adb, dns_adbentry_t *entry, dns_name_t *qname,
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater dns_rdatatype_t qtype, isc_stdtime_t now)
d8590892d10fc9528b0dde7e2781935e7b8d7a87Michael Graff{
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater dns_adblameinfo_t *li, *next_li;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater isc_boolean_t is_bad;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater is_bad = ISC_FALSE;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater li = ISC_LIST_HEAD(entry->lameinfo);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (li == NULL)
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater return (ISC_FALSE);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater while (li != NULL) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater next_li = ISC_LIST_NEXT(li, plink);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater /*
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * Has the entry expired?
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater */
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (li->lame_timer < now) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater ISC_LIST_UNLINK(entry->lameinfo, li, plink);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater free_adblameinfo(adb, &li);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater }
d8590892d10fc9528b0dde7e2781935e7b8d7a87Michael Graff
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater /*
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * Order tests from least to most expensive.
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater *
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * We do not break out of the main loop here as
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * we use the loop for house keeping.
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater */
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (li != NULL && !is_bad && li->qtype == qtype &&
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater dns_name_equal(qname, &li->qname))
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater is_bad = ISC_TRUE;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater li = next_li;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater }
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater return (is_bad);
d8590892d10fc9528b0dde7e2781935e7b8d7a87Michael Graff}
d8590892d10fc9528b0dde7e2781935e7b8d7a87Michael Graff
439c0011e642fb1d26011116144af698125262dbMichael Graffstatic void
bcf369e513a1cc2209e2a987f5772afa79813540Mark Andrewscopy_namehook_lists(dns_adb_t *adb, dns_adbfind_t *find, dns_name_t *qname,
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater dns_rdatatype_t qtype, dns_adbname_t *name,
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater isc_stdtime_t now)
439c0011e642fb1d26011116144af698125262dbMichael Graff{
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater dns_adbnamehook_t *namehook;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater dns_adbaddrinfo_t *addrinfo;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater dns_adbentry_t *entry;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater int bucket;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater bucket = DNS_ADB_INVALIDBUCKET;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (find->options & DNS_ADBFIND_INET) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater namehook = ISC_LIST_HEAD(name->v4);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater while (namehook != NULL) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater entry = namehook->entry;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater bucket = entry->lock_bucket;
47c5b8af920a93763c97d9a93ea1fd766961a5b3Evan Hunt INSIST(bucket != DNS_ADB_INVALIDBUCKET);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater LOCK(&adb->entrylocks[bucket]);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (!FIND_RETURNLAME(find)
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater && entry_is_lame(adb, entry, qname, qtype, now)) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater find->options |= DNS_ADBFIND_LAMEPRUNED;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater goto nextv4;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater }
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater addrinfo = new_adbaddrinfo(adb, entry, find->port);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (addrinfo == NULL) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater find->partial_result |= DNS_ADBFIND_INET;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater goto out;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater }
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater /*
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * Found a valid entry. Add it to the find's list.
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater */
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater inc_entry_refcnt(adb, entry, ISC_FALSE);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater ISC_LIST_APPEND(find->list, addrinfo, publink);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater addrinfo = NULL;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater nextv4:
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater UNLOCK(&adb->entrylocks[bucket]);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater bucket = DNS_ADB_INVALIDBUCKET;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater namehook = ISC_LIST_NEXT(namehook, plink);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater }
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater }
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (find->options & DNS_ADBFIND_INET6) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater namehook = ISC_LIST_HEAD(name->v6);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater while (namehook != NULL) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater entry = namehook->entry;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater bucket = entry->lock_bucket;
47c5b8af920a93763c97d9a93ea1fd766961a5b3Evan Hunt INSIST(bucket != DNS_ADB_INVALIDBUCKET);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater LOCK(&adb->entrylocks[bucket]);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
698a4dcc8ae5c2a62a254ab2aff7b16d52598cc0Mark Andrews if (!FIND_RETURNLAME(find)
698a4dcc8ae5c2a62a254ab2aff7b16d52598cc0Mark Andrews && entry_is_lame(adb, entry, qname, qtype, now)) {
698a4dcc8ae5c2a62a254ab2aff7b16d52598cc0Mark Andrews find->options |= DNS_ADBFIND_LAMEPRUNED;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater goto nextv6;
698a4dcc8ae5c2a62a254ab2aff7b16d52598cc0Mark Andrews }
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater addrinfo = new_adbaddrinfo(adb, entry, find->port);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (addrinfo == NULL) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater find->partial_result |= DNS_ADBFIND_INET6;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater goto out;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater }
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater /*
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * Found a valid entry. Add it to the find's list.
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater */
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater inc_entry_refcnt(adb, entry, ISC_FALSE);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater ISC_LIST_APPEND(find->list, addrinfo, publink);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater addrinfo = NULL;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater nextv6:
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater UNLOCK(&adb->entrylocks[bucket]);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater bucket = DNS_ADB_INVALIDBUCKET;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater namehook = ISC_LIST_NEXT(namehook, plink);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater }
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater }
439c0011e642fb1d26011116144af698125262dbMichael Graff
d8590892d10fc9528b0dde7e2781935e7b8d7a87Michael Graff out:
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (bucket != DNS_ADB_INVALIDBUCKET)
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater UNLOCK(&adb->entrylocks[bucket]);
439c0011e642fb1d26011116144af698125262dbMichael Graff}
439c0011e642fb1d26011116144af698125262dbMichael Graff
08d131595373326ec4a3af793b536df8c33115ecMichael Graffstatic void
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrenceshutdown_task(isc_task_t *task, isc_event_t *ev) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater dns_adb_t *adb;
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater UNUSED(task);
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater adb = ev->ev_arg;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater INSIST(DNS_ADB_VALID(adb));
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater isc_event_free(&ev);
0dba2713dec4cf3f97f21b957e403a36ee989b3cMark Andrews /*
0dba2713dec4cf3f97f21b957e403a36ee989b3cMark Andrews * Wait for lock around check_exit() call to be released.
0dba2713dec4cf3f97f21b957e403a36ee989b3cMark Andrews */
816496b22114ee7c2c15321c2c6cc4be77fdf822Mark Andrews LOCK(&adb->lock);
816496b22114ee7c2c15321c2c6cc4be77fdf822Mark Andrews UNLOCK(&adb->lock);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater destroy(adb);
08d131595373326ec4a3af793b536df8c33115ecMichael Graff}
08d131595373326ec4a3af793b536df8c33115ecMichael Graff
3ac63b472022ff92691d1fe69ac715a729671965Michael Graff/*
ff303bcf27507c2bab1fab7f05e203fdccae7e19Andreas Gustafsson * Name bucket must be locked; adb may be locked; no other locks held.
3ac63b472022ff92691d1fe69ac715a729671965Michael Graff */
e34efaccfaab4dbbe45edd0a58e2b6e930e5784bMichael Graffstatic isc_boolean_t
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrencecheck_expire_name(dns_adbname_t **namep, isc_stdtime_t now) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater dns_adbname_t *name;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater isc_boolean_t result = ISC_FALSE;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater INSIST(namep != NULL && DNS_ADBNAME_VALID(*namep));
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater name = *namep;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (NAME_HAS_V4(name) || NAME_HAS_V6(name))
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater return (result);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (NAME_FETCH(name))
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater return (result);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (!EXPIRE_OK(name->expire_v4, now))
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater return (result);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (!EXPIRE_OK(name->expire_v6, now))
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater return (result);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (!EXPIRE_OK(name->expire_target, now))
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater return (result);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater /*
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * The name is empty. Delete it.
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater */
c82bb6a709abe89c051485b49403ef5bad1b756cTatuya JINMEI 神明達哉 result = kill_name(&name, DNS_EVENT_ADBEXPIRED);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater *namep = NULL;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater /*
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * Our caller, or one of its callers, will be calling check_exit() at
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * some point, so we don't need to do it here.
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater */
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater return (result);
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff}
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff/*%
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff * Examine the tail entry of the LRU list to see if it expires or is stale
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff * (unused for some period); if so, the name entry will be freed. If the ADB
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff * is in the overmem condition, the tail and the next to tail entries
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff * will be unconditionally removed (unless they have an outstanding fetch).
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff * We don't care about a race on 'overmem' at the risk of causing some
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff * collateral damage or a small delay in starting cleanup, so we don't bother
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff * to lock ADB (if it's not locked).
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff *
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff * Name bucket must be locked; adb may be locked; no other locks held.
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff */
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graffstatic void
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graffcheck_stale_name(dns_adb_t *adb, int bucket, isc_stdtime_t now) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater int victims, max_victims;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater dns_adbname_t *victim, *next_victim;
27fe1966c948ba0c1c9d0d831ea3d8bf32d052acTatuya JINMEI 神明達哉 isc_boolean_t overmem = isc_mem_isovermem(adb->mctx);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater int scans = 0;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater INSIST(bucket != DNS_ADB_INVALIDBUCKET);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater max_victims = overmem ? 2 : 1;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater /*
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * We limit the number of scanned entries to 10 (arbitrary choice)
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * in order to avoid examining too many entries when there are many
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * tail entries that have fetches (this should be rare, but could
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * happen).
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater */
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater victim = ISC_LIST_TAIL(adb->names[bucket]);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater for (victims = 0;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater victim != NULL && victims < max_victims && scans < 10;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater victim = next_victim) {
c82bb6a709abe89c051485b49403ef5bad1b756cTatuya JINMEI 神明達哉 INSIST(!NAME_DEAD(victim));
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater scans++;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater next_victim = ISC_LIST_PREV(victim, plink);
0874abad14e3e9ecfc3dc1a1a2b9969f2f027724Mark Andrews (void)check_expire_name(&victim, now);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (victim == NULL) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater victims++;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater goto next;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater }
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (!NAME_FETCH(victim) &&
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater (overmem || victim->last_used + ADB_STALE_MARGIN <= now)) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater RUNTIME_CHECK(kill_name(&victim,
c82bb6a709abe89c051485b49403ef5bad1b756cTatuya JINMEI 神明達哉 DNS_EVENT_ADBCANCELED) ==
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater ISC_FALSE);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater victims++;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater }
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater next:
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (!overmem)
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater break;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater }
84c46a7acb961cac19c0d857bfdd00f3383a9bc6Michael Graff}
84c46a7acb961cac19c0d857bfdd00f3383a9bc6Michael Graff
a44c12b332b867f29631e235eb11d1263c73d6c0Bob Halley/*
ff303bcf27507c2bab1fab7f05e203fdccae7e19Andreas Gustafsson * Entry bucket must be locked; adb may be locked; no other locks held.
a44c12b332b867f29631e235eb11d1263c73d6c0Bob Halley */
e34efaccfaab4dbbe45edd0a58e2b6e930e5784bMichael Graffstatic isc_boolean_t
a44c12b332b867f29631e235eb11d1263c73d6c0Bob Halleycheck_expire_entry(dns_adb_t *adb, dns_adbentry_t **entryp, isc_stdtime_t now)
a44c12b332b867f29631e235eb11d1263c73d6c0Bob Halley{
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater dns_adbentry_t *entry;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater isc_boolean_t result = ISC_FALSE;
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater INSIST(entryp != NULL && DNS_ADBENTRY_VALID(*entryp));
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater entry = *entryp;
5f1f24822fabe7b78af5f81553bfc11a170326c3Mark Andrews
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (entry->refcnt != 0)
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater return (result);
081cff0c33514a5dc63ab794fc199c07377ab756Mark Andrews
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (entry->expires == 0 || entry->expires > now)
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater return (result);
081cff0c33514a5dc63ab794fc199c07377ab756Mark Andrews
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater /*
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * The entry is not in use. Delete it.
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater */
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater DP(DEF_LEVEL, "killing entry %p", entry);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater INSIST(ISC_LINK_LINKED(entry, plink));
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater result = unlink_entry(adb, entry);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater free_adbentry(adb, &entry);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (result)
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater dec_adb_irefcnt(adb);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater *entryp = NULL;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater return (result);
a44c12b332b867f29631e235eb11d1263c73d6c0Bob Halley}
a44c12b332b867f29631e235eb11d1263c73d6c0Bob Halley
84c46a7acb961cac19c0d857bfdd00f3383a9bc6Michael Graff/*
84c46a7acb961cac19c0d857bfdd00f3383a9bc6Michael Graff * ADB must be locked, and no other locks held.
84c46a7acb961cac19c0d857bfdd00f3383a9bc6Michael Graff */
e34efaccfaab4dbbe45edd0a58e2b6e930e5784bMichael Graffstatic isc_boolean_t
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrencecleanup_names(dns_adb_t *adb, int bucket, isc_stdtime_t now) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater dns_adbname_t *name;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater dns_adbname_t *next_name;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater isc_boolean_t result = ISC_FALSE;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater DP(CLEAN_LEVEL, "cleaning name bucket %d", bucket);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater LOCK(&adb->namelocks[bucket]);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (adb->name_sd[bucket]) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater UNLOCK(&adb->namelocks[bucket]);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater return (result);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater }
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater name = ISC_LIST_HEAD(adb->names[bucket]);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater while (name != NULL) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater next_name = ISC_LIST_NEXT(name, plink);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater INSIST(result == ISC_FALSE);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater result = check_expire_namehooks(name, now);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (!result)
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater result = check_expire_name(&name, now);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater name = next_name;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater }
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater UNLOCK(&adb->namelocks[bucket]);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater return (result);
3ac63b472022ff92691d1fe69ac715a729671965Michael Graff}
3ac63b472022ff92691d1fe69ac715a729671965Michael Graff
a44c12b332b867f29631e235eb11d1263c73d6c0Bob Halley/*
a44c12b332b867f29631e235eb11d1263c73d6c0Bob Halley * ADB must be locked, and no other locks held.
a44c12b332b867f29631e235eb11d1263c73d6c0Bob Halley */
e34efaccfaab4dbbe45edd0a58e2b6e930e5784bMichael Graffstatic isc_boolean_t
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrencecleanup_entries(dns_adb_t *adb, int bucket, isc_stdtime_t now) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater dns_adbentry_t *entry, *next_entry;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater isc_boolean_t result = ISC_FALSE;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater DP(CLEAN_LEVEL, "cleaning entry bucket %d", bucket);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater LOCK(&adb->entrylocks[bucket]);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater entry = ISC_LIST_HEAD(adb->entries[bucket]);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater while (entry != NULL) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater next_entry = ISC_LIST_NEXT(entry, plink);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater INSIST(result == ISC_FALSE);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater result = check_expire_entry(adb, &entry, now);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater entry = next_entry;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater }
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater UNLOCK(&adb->entrylocks[bucket]);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater return (result);
a44c12b332b867f29631e235eb11d1263c73d6c0Bob Halley}
a44c12b332b867f29631e235eb11d1263c73d6c0Bob Halley
3024dbecbac365171bc6de0f3fa04951d6558be3Michael Graffstatic void
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrencedestroy(dns_adb_t *adb) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater adb->magic = 0;
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater isc_task_detach(&adb->task);
8013077aa7ed5d6e1daddc973ddb3c7cc7d28df1Mark Andrews if (adb->excl != NULL)
8013077aa7ed5d6e1daddc973ddb3c7cc7d28df1Mark Andrews isc_task_detach(&adb->excl);
3ac63b472022ff92691d1fe69ac715a729671965Michael Graff
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater isc_mempool_destroy(&adb->nmp);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater isc_mempool_destroy(&adb->nhmp);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater isc_mempool_destroy(&adb->limp);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater isc_mempool_destroy(&adb->emp);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater isc_mempool_destroy(&adb->ahmp);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater isc_mempool_destroy(&adb->aimp);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater isc_mempool_destroy(&adb->afmp);
3024dbecbac365171bc6de0f3fa04951d6558be3Michael Graff
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews DESTROYMUTEXBLOCK(adb->entrylocks, adb->nentries);
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews isc_mem_put(adb->mctx, adb->entries,
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews sizeof(*adb->entries) * adb->nentries);
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews isc_mem_put(adb->mctx, adb->deadentries,
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews sizeof(*adb->deadentries) * adb->nentries);
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews isc_mem_put(adb->mctx, adb->entrylocks,
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews sizeof(*adb->entrylocks) * adb->nentries);
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews isc_mem_put(adb->mctx, adb->entry_sd,
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews sizeof(*adb->entry_sd) * adb->nentries);
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews isc_mem_put(adb->mctx, adb->entry_refcnt,
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews sizeof(*adb->entry_refcnt) * adb->nentries);
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews DESTROYMUTEXBLOCK(adb->namelocks, adb->nnames);
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews isc_mem_put(adb->mctx, adb->names,
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews sizeof(*adb->names) * adb->nnames);
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews isc_mem_put(adb->mctx, adb->deadnames,
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews sizeof(*adb->deadnames) * adb->nnames);
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews isc_mem_put(adb->mctx, adb->namelocks,
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews sizeof(*adb->namelocks) * adb->nnames);
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews isc_mem_put(adb->mctx, adb->name_sd,
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews sizeof(*adb->name_sd) * adb->nnames);
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews isc_mem_put(adb->mctx, adb->name_refcnt,
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews sizeof(*adb->name_refcnt) * adb->nnames);
3024dbecbac365171bc6de0f3fa04951d6558be3Michael Graff
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater DESTROYLOCK(&adb->reflock);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater DESTROYLOCK(&adb->lock);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater DESTROYLOCK(&adb->mplock);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater DESTROYLOCK(&adb->overmemlock);
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews DESTROYLOCK(&adb->entriescntlock);
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews DESTROYLOCK(&adb->namescntlock);
3024dbecbac365171bc6de0f3fa04951d6558be3Michael Graff
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater isc_mem_putanddetach(&adb->mctx, adb, sizeof(dns_adb_t));
3024dbecbac365171bc6de0f3fa04951d6558be3Michael Graff}
3024dbecbac365171bc6de0f3fa04951d6558be3Michael Graff
3024dbecbac365171bc6de0f3fa04951d6558be3Michael Graff
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graff/*
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graff * Public functions.
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graff */
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graff
66bd3b3c6b171271c705b897823dcdcf29464698Michael Graffisc_result_t
fbcf7bc351f2d42d338cb1fa29e59babd9bee94eMichael Graffdns_adb_create(isc_mem_t *mem, dns_view_t *view, isc_timermgr_t *timermgr,
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater isc_taskmgr_t *taskmgr, dns_adb_t **newadb)
66bd3b3c6b171271c705b897823dcdcf29464698Michael Graff{
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater dns_adb_t *adb;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater isc_result_t result;
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews unsigned int i;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater REQUIRE(mem != NULL);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater REQUIRE(view != NULL);
5c024f787777143031c2c49f9811c39c84bfa259Tatuya JINMEI 神明達哉 REQUIRE(timermgr != NULL); /* this is actually unused */
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater REQUIRE(taskmgr != NULL);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater REQUIRE(newadb != NULL && *newadb == NULL);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
5c024f787777143031c2c49f9811c39c84bfa259Tatuya JINMEI 神明達哉 UNUSED(timermgr);
5c024f787777143031c2c49f9811c39c84bfa259Tatuya JINMEI 神明達哉
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater adb = isc_mem_get(mem, sizeof(dns_adb_t));
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (adb == NULL)
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater return (ISC_R_NOMEMORY);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater /*
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * Initialize things here that cannot fail, and especially things
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * that must be NULL for the error return to work properly.
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater */
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater adb->magic = 0;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater adb->erefcnt = 1;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater adb->irefcnt = 0;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater adb->nmp = NULL;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater adb->nhmp = NULL;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater adb->limp = NULL;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater adb->emp = NULL;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater adb->ahmp = NULL;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater adb->aimp = NULL;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater adb->afmp = NULL;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater adb->task = NULL;
c965b1869024ab38518fade703cc1dae2d71a59eMark Andrews adb->excl = NULL;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater adb->mctx = NULL;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater adb->view = view;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater adb->taskmgr = taskmgr;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater adb->next_cleanbucket = 0;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater ISC_EVENT_INIT(&adb->cevent, sizeof(adb->cevent), 0, NULL,
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater DNS_EVENT_ADBCONTROL, shutdown_task, adb,
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater adb, NULL, NULL);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater adb->cevent_sent = ISC_FALSE;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater adb->shutting_down = ISC_FALSE;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater ISC_LIST_INIT(adb->whenshutdown);
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews adb->nentries = nbuckets[0];
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews adb->entriescnt = 0;
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews adb->entries = NULL;
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews adb->deadentries = NULL;
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews adb->entry_sd = NULL;
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews adb->entry_refcnt = NULL;
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews adb->entrylocks = NULL;
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews ISC_EVENT_INIT(&adb->growentries, sizeof(adb->growentries), 0, NULL,
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews DNS_EVENT_ADBGROWENTRIES, grow_entries, adb,
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews adb, NULL, NULL);
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews adb->growentries_sent = ISC_FALSE;
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews adb->nnames = nbuckets[0];
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews adb->namescnt = 0;
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews adb->names = NULL;
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews adb->deadnames = NULL;
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews adb->name_sd = NULL;
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews adb->name_refcnt = NULL;
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews adb->namelocks = NULL;
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews ISC_EVENT_INIT(&adb->grownames, sizeof(adb->grownames), 0, NULL,
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews DNS_EVENT_ADBGROWNAMES, grow_names, adb,
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews adb, NULL, NULL);
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews adb->grownames_sent = ISC_FALSE;
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews
c965b1869024ab38518fade703cc1dae2d71a59eMark Andrews result = isc_taskmgr_excltask(adb->taskmgr, &adb->excl);
c965b1869024ab38518fade703cc1dae2d71a59eMark Andrews if (result != ISC_R_SUCCESS) {
1d761cb453c76353deb8423c78e98d00c5f86ffaEvan Hunt DP(DEF_LEVEL, "adb: task-exclusive mode unavailable, "
1d761cb453c76353deb8423c78e98d00c5f86ffaEvan Hunt "intializing table sizes to %u\n",
1d761cb453c76353deb8423c78e98d00c5f86ffaEvan Hunt nbuckets[11]);
c965b1869024ab38518fade703cc1dae2d71a59eMark Andrews adb->nentries = nbuckets[11];
c965b1869024ab38518fade703cc1dae2d71a59eMark Andrews adb->nnames= nbuckets[11];
c965b1869024ab38518fade703cc1dae2d71a59eMark Andrews
c965b1869024ab38518fade703cc1dae2d71a59eMark Andrews }
c965b1869024ab38518fade703cc1dae2d71a59eMark Andrews
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater isc_mem_attach(mem, &adb->mctx);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater result = isc_mutex_init(&adb->lock);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (result != ISC_R_SUCCESS)
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater goto fail0b;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater result = isc_mutex_init(&adb->mplock);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (result != ISC_R_SUCCESS)
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater goto fail0c;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater result = isc_mutex_init(&adb->reflock);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (result != ISC_R_SUCCESS)
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater goto fail0d;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater result = isc_mutex_init(&adb->overmemlock);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (result != ISC_R_SUCCESS)
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater goto fail0e;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews result = isc_mutex_init(&adb->entriescntlock);
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews if (result != ISC_R_SUCCESS)
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews goto fail0f;
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews result = isc_mutex_init(&adb->namescntlock);
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews if (result != ISC_R_SUCCESS)
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews goto fail0g;
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews#define ALLOCENTRY(adb, el) \
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews do { \
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews (adb)->el = isc_mem_get((adb)->mctx, \
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews sizeof(*(adb)->el) * (adb)->nentries); \
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews if ((adb)->el == NULL) { \
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews result = ISC_R_NOMEMORY; \
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews goto fail1; \
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews }\
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews } while (0)
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews ALLOCENTRY(adb, entries);
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews ALLOCENTRY(adb, deadentries);
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews ALLOCENTRY(adb, entrylocks);
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews ALLOCENTRY(adb, entry_sd);
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews ALLOCENTRY(adb, entry_refcnt);
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews#undef ALLOCENTRY
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews#define ALLOCNAME(adb, el) \
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews do { \
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews (adb)->el = isc_mem_get((adb)->mctx, \
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews sizeof(*(adb)->el) * (adb)->nnames); \
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews if ((adb)->el == NULL) { \
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews result = ISC_R_NOMEMORY; \
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews goto fail1; \
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews }\
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews } while (0)
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews ALLOCNAME(adb, names);
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews ALLOCNAME(adb, deadnames);
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews ALLOCNAME(adb, namelocks);
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews ALLOCNAME(adb, name_sd);
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews ALLOCNAME(adb, name_refcnt);
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews#undef ALLOCNAME
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater /*
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * Initialize the bucket locks for names and elements.
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * May as well initialize the list heads, too.
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater */
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews result = isc_mutexblock_init(adb->namelocks, adb->nnames);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (result != ISC_R_SUCCESS)
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater goto fail1;
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews for (i = 0; i < adb->nnames; i++) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater ISC_LIST_INIT(adb->names[i]);
c82bb6a709abe89c051485b49403ef5bad1b756cTatuya JINMEI 神明達哉 ISC_LIST_INIT(adb->deadnames[i]);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater adb->name_sd[i] = ISC_FALSE;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater adb->name_refcnt[i] = 0;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater adb->irefcnt++;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater }
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews for (i = 0; i < adb->nentries; i++) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater ISC_LIST_INIT(adb->entries[i]);
c82bb6a709abe89c051485b49403ef5bad1b756cTatuya JINMEI 神明達哉 ISC_LIST_INIT(adb->deadentries[i]);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater adb->entry_sd[i] = ISC_FALSE;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater adb->entry_refcnt[i] = 0;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater adb->irefcnt++;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater }
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews result = isc_mutexblock_init(adb->entrylocks, adb->nentries);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (result != ISC_R_SUCCESS)
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater goto fail2;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater /*
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * Memory pools
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater */
64574939c4a591a457bdd352f86375d6bb1d5435David Lawrence#define MPINIT(t, p, n) do { \
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater result = isc_mempool_create(mem, sizeof(t), &(p)); \
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (result != ISC_R_SUCCESS) \
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater goto fail3; \
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater isc_mempool_setfreemax((p), FREE_ITEMS); \
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater isc_mempool_setfillcount((p), FILL_COUNT); \
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater isc_mempool_setname((p), n); \
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater isc_mempool_associatelock((p), &adb->mplock); \
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff} while (0)
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater MPINIT(dns_adbname_t, adb->nmp, "adbname");
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater MPINIT(dns_adbnamehook_t, adb->nhmp, "adbnamehook");
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater MPINIT(dns_adblameinfo_t, adb->limp, "adblameinfo");
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater MPINIT(dns_adbentry_t, adb->emp, "adbentry");
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater MPINIT(dns_adbfind_t, adb->ahmp, "adbfind");
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater MPINIT(dns_adbaddrinfo_t, adb->aimp, "adbaddrinfo");
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater MPINIT(dns_adbfetch_t, adb->afmp, "adbfetch");
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff#undef MPINIT
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater /*
5c024f787777143031c2c49f9811c39c84bfa259Tatuya JINMEI 神明達哉 * Allocate an internal task.
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater */
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater result = isc_task_create(adb->taskmgr, 0, &adb->task);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (result != ISC_R_SUCCESS)
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater goto fail3;
c965b1869024ab38518fade703cc1dae2d71a59eMark Andrews
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater isc_task_setname(adb->task, "ADB", adb);
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff
dd2a0a6d2dec1c23787351e51b434a838dec5603Evan Hunt result = isc_stats_create(adb->mctx, &view->adbstats, dns_adbstats_max);
dd2a0a6d2dec1c23787351e51b434a838dec5603Evan Hunt if (result != ISC_R_SUCCESS)
dd2a0a6d2dec1c23787351e51b434a838dec5603Evan Hunt goto fail3;
c965b1869024ab38518fade703cc1dae2d71a59eMark Andrews
dd2a0a6d2dec1c23787351e51b434a838dec5603Evan Hunt set_adbstat(adb, adb->nentries, dns_adbstats_nentries);
dd2a0a6d2dec1c23787351e51b434a838dec5603Evan Hunt set_adbstat(adb, adb->nnames, dns_adbstats_nnames);
dd2a0a6d2dec1c23787351e51b434a838dec5603Evan Hunt
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater /*
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * Normal return.
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater */
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater adb->magic = DNS_ADB_MAGIC;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater *newadb = adb;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater return (ISC_R_SUCCESS);
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff
3ac63b472022ff92691d1fe69ac715a729671965Michael Graff fail3:
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (adb->task != NULL)
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater isc_task_detach(&adb->task);
3ac63b472022ff92691d1fe69ac715a729671965Michael Graff
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater /* clean up entrylocks */
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews DESTROYMUTEXBLOCK(adb->entrylocks, adb->nentries);
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff fail2: /* clean up namelocks */
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews DESTROYMUTEXBLOCK(adb->namelocks, adb->nnames);
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff fail1: /* clean up only allocated memory */
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews if (adb->entries != NULL)
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews isc_mem_put(adb->mctx, adb->entries,
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews sizeof(*adb->entries) * adb->nentries);
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews if (adb->deadentries != NULL)
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews isc_mem_put(adb->mctx, adb->deadentries,
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews sizeof(*adb->deadentries) * adb->nentries);
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews if (adb->entrylocks != NULL)
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews isc_mem_put(adb->mctx, adb->entrylocks,
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews sizeof(*adb->entrylocks) * adb->nentries);
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews if (adb->entry_sd != NULL)
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews isc_mem_put(adb->mctx, adb->entry_sd,
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews sizeof(*adb->entry_sd) * adb->nentries);
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews if (adb->entry_refcnt != NULL)
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews isc_mem_put(adb->mctx, adb->entry_refcnt,
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews sizeof(*adb->entry_refcnt) * adb->nentries);
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews if (adb->names != NULL)
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews isc_mem_put(adb->mctx, adb->names,
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews sizeof(*adb->names) * adb->nnames);
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews if (adb->deadnames != NULL)
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews isc_mem_put(adb->mctx, adb->deadnames,
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews sizeof(*adb->deadnames) * adb->nnames);
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews if (adb->namelocks != NULL)
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews isc_mem_put(adb->mctx, adb->namelocks,
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews sizeof(*adb->namelocks) * adb->nnames);
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews if (adb->name_sd != NULL)
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews isc_mem_put(adb->mctx, adb->name_sd,
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews sizeof(*adb->name_sd) * adb->nnames);
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews if (adb->name_refcnt != NULL)
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews isc_mem_put(adb->mctx, adb->name_refcnt,
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews sizeof(*adb->name_refcnt) * adb->nnames);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (adb->nmp != NULL)
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater isc_mempool_destroy(&adb->nmp);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (adb->nhmp != NULL)
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater isc_mempool_destroy(&adb->nhmp);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (adb->limp != NULL)
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater isc_mempool_destroy(&adb->limp);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (adb->emp != NULL)
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater isc_mempool_destroy(&adb->emp);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (adb->ahmp != NULL)
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater isc_mempool_destroy(&adb->ahmp);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (adb->aimp != NULL)
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater isc_mempool_destroy(&adb->aimp);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (adb->afmp != NULL)
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater isc_mempool_destroy(&adb->afmp);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews DESTROYLOCK(&adb->namescntlock);
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews fail0g:
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews DESTROYLOCK(&adb->entriescntlock);
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews fail0f:
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater DESTROYLOCK(&adb->overmemlock);
9a7d202077fae00fbdca610d8a8d90689e30f331Mark Andrews fail0e:
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater DESTROYLOCK(&adb->reflock);
45dadd25ba4b72ec2d8eecc342edc787d8421e3aBob Halley fail0d:
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater DESTROYLOCK(&adb->mplock);
f181f94ec8da8b1dbcc6353e8be965ea4a5ea282Michael Graff fail0c:
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater DESTROYLOCK(&adb->lock);
f181f94ec8da8b1dbcc6353e8be965ea4a5ea282Michael Graff fail0b:
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater isc_mem_putanddetach(&adb->mctx, adb, sizeof(dns_adb_t));
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater return (result);
66bd3b3c6b171271c705b897823dcdcf29464698Michael Graff}
66bd3b3c6b171271c705b897823dcdcf29464698Michael Graff
9b8057fce9ee7cdc39ad35f6e16d4ff5e623a941Mark Andrewsvoid
9b8057fce9ee7cdc39ad35f6e16d4ff5e623a941Mark Andrewsdns_adb_attach(dns_adb_t *adb, dns_adb_t **adbx) {
9b8057fce9ee7cdc39ad35f6e16d4ff5e623a941Mark Andrews
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater REQUIRE(DNS_ADB_VALID(adb));
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater REQUIRE(adbx != NULL && *adbx == NULL);
9b8057fce9ee7cdc39ad35f6e16d4ff5e623a941Mark Andrews
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater inc_adb_erefcnt(adb);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater *adbx = adb;
9b8057fce9ee7cdc39ad35f6e16d4ff5e623a941Mark Andrews}
9b8057fce9ee7cdc39ad35f6e16d4ff5e623a941Mark Andrews
66bd3b3c6b171271c705b897823dcdcf29464698Michael Graffvoid
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrencedns_adb_detach(dns_adb_t **adbx) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater dns_adb_t *adb;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater isc_boolean_t need_exit_check;
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater REQUIRE(adbx != NULL && DNS_ADB_VALID(*adbx));
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater adb = *adbx;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater *adbx = NULL;
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater INSIST(adb->erefcnt > 0);
ca50fa02308a99f5f30b4fac892a75f8ea2fd38bAndreas Gustafsson
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater LOCK(&adb->reflock);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater adb->erefcnt--;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater need_exit_check = ISC_TF(adb->erefcnt == 0 && adb->irefcnt == 0);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater UNLOCK(&adb->reflock);
ca50fa02308a99f5f30b4fac892a75f8ea2fd38bAndreas Gustafsson
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (need_exit_check) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater LOCK(&adb->lock);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater INSIST(adb->shutting_down);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater check_exit(adb);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater UNLOCK(&adb->lock);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater }
59c049874bbef182857c57bd9cca292898921c69Bob Halley}
59c049874bbef182857c57bd9cca292898921c69Bob Halley
59c049874bbef182857c57bd9cca292898921c69Bob Halleyvoid
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrencedns_adb_whenshutdown(dns_adb_t *adb, isc_task_t *task, isc_event_t **eventp) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater isc_task_t *clone;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater isc_event_t *event;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater isc_boolean_t zeroirefcnt = ISC_FALSE;
59c049874bbef182857c57bd9cca292898921c69Bob Halley
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater /*
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * Send '*eventp' to 'task' when 'adb' has shutdown.
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater */
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater REQUIRE(DNS_ADB_VALID(adb));
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater REQUIRE(eventp != NULL);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater event = *eventp;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater *eventp = NULL;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater LOCK(&adb->lock);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater LOCK(&adb->reflock);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater zeroirefcnt = ISC_TF(adb->irefcnt == 0);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (adb->shutting_down && zeroirefcnt &&
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater isc_mempool_getallocated(adb->ahmp) == 0) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater /*
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * We're already shutdown. Send the event.
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater */
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater event->ev_sender = adb;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater isc_task_send(task, &event);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater } else {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater clone = NULL;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater isc_task_attach(task, &clone);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater event->ev_sender = clone;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater ISC_LIST_APPEND(adb->whenshutdown, event, ev_link);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater }
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater UNLOCK(&adb->reflock);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater UNLOCK(&adb->lock);
59c049874bbef182857c57bd9cca292898921c69Bob Halley}
59c049874bbef182857c57bd9cca292898921c69Bob Halley
59c049874bbef182857c57bd9cca292898921c69Bob Halleyvoid
59c049874bbef182857c57bd9cca292898921c69Bob Halleydns_adb_shutdown(dns_adb_t *adb) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater isc_boolean_t need_check_exit;
59c049874bbef182857c57bd9cca292898921c69Bob Halley
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater /*
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * Shutdown 'adb'.
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater */
59c049874bbef182857c57bd9cca292898921c69Bob Halley
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater LOCK(&adb->lock);
59c049874bbef182857c57bd9cca292898921c69Bob Halley
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (!adb->shutting_down) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater adb->shutting_down = ISC_TRUE;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater isc_mem_setwater(adb->mctx, water, adb, 0, 0);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater need_check_exit = shutdown_names(adb);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (!need_check_exit)
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater need_check_exit = shutdown_entries(adb);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (need_check_exit)
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater check_exit(adb);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater }
59c049874bbef182857c57bd9cca292898921c69Bob Halley
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater UNLOCK(&adb->lock);
66bd3b3c6b171271c705b897823dcdcf29464698Michael Graff}
66bd3b3c6b171271c705b897823dcdcf29464698Michael Graff
66bd3b3c6b171271c705b897823dcdcf29464698Michael Graffisc_result_t
897c9ddb4d745b2bfecf98b17e5487bb6656299aMichael Graffdns_adb_createfind(dns_adb_t *adb, isc_task_t *task, isc_taskaction_t action,
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater void *arg, dns_name_t *name, dns_name_t *qname,
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater dns_rdatatype_t qtype, unsigned int options,
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater isc_stdtime_t now, dns_name_t *target,
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater in_port_t port, dns_adbfind_t **findp)
66bd3b3c6b171271c705b897823dcdcf29464698Michael Graff{
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater dns_adbfind_t *find;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater dns_adbname_t *adbname;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater int bucket;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater isc_boolean_t want_event, start_at_zone, alias, have_address;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater isc_result_t result;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater unsigned int wanted_addresses;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater unsigned int wanted_fetches;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater unsigned int query_pending;
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews char namebuf[DNS_NAME_FORMATSIZE];
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater REQUIRE(DNS_ADB_VALID(adb));
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (task != NULL) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater REQUIRE(action != NULL);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater }
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater REQUIRE(name != NULL);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater REQUIRE(qname != NULL);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater REQUIRE(findp != NULL && *findp == NULL);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater REQUIRE(target == NULL || dns_name_hasbuffer(target));
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater REQUIRE((options & DNS_ADBFIND_ADDRESSMASK) != 0);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater result = ISC_R_UNEXPECTED;
0874abad14e3e9ecfc3dc1a1a2b9969f2f027724Mark Andrews POST(result);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater wanted_addresses = (options & DNS_ADBFIND_ADDRESSMASK);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater wanted_fetches = 0;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater query_pending = 0;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater want_event = ISC_FALSE;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater start_at_zone = ISC_FALSE;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater alias = ISC_FALSE;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (now == 0)
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater isc_stdtime_get(&now);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater /*
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * XXXMLG Move this comment somewhere else!
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater *
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * Look up the name in our internal database.
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater *
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * Possibilities: Note that these are not always exclusive.
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater *
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * No name found. In this case, allocate a new name header and
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * an initial namehook or two. If any of these allocations
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * fail, clean up and return ISC_R_NOMEMORY.
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater *
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * Name found, valid addresses present. Allocate one addrinfo
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * structure for each found and append it to the linked list
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * of addresses for this header.
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater *
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * Name found, queries pending. In this case, if a task was
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * passed in, allocate a job id, attach it to the name's job
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * list and remember to tell the caller that there will be
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * more info coming later.
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater */
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater find = new_adbfind(adb);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (find == NULL)
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater return (ISC_R_NOMEMORY);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater find->port = port;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater /*
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * Remember what types of addresses we are interested in.
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater */
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater find->options = options;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater find->flags |= wanted_addresses;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (FIND_WANTEVENT(find)) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater REQUIRE(task != NULL);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater }
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews if (isc_log_wouldlog(dns_lctx, DEF_LEVEL))
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews dns_name_format(name, namebuf, sizeof(namebuf));
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews else
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews namebuf[0] = 0;
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater /*
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * Try to see if we know anything about this name at all.
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater */
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater bucket = DNS_ADB_INVALIDBUCKET;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater adbname = find_name_and_lock(adb, name, find->options, &bucket);
17c98e7adddf82b73f478e89213fd10148a53100Mark Andrews INSIST(bucket != DNS_ADB_INVALIDBUCKET);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (adb->name_sd[bucket]) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater DP(DEF_LEVEL,
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater "dns_adb_createfind: returning ISC_R_SHUTTINGDOWN");
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater RUNTIME_CHECK(free_adbfind(adb, &find) == ISC_FALSE);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater result = ISC_R_SHUTTINGDOWN;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater goto out;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater }
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater /*
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * Nothing found. Allocate a new adbname structure for this name.
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater */
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (adbname == NULL) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater /*
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * See if there is any stale name at the end of list, and purge
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * it if so.
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater */
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater check_stale_name(adb, bucket, now);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater adbname = new_adbname(adb, name);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (adbname == NULL) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater RUNTIME_CHECK(free_adbfind(adb, &find) == ISC_FALSE);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater result = ISC_R_NOMEMORY;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater goto out;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater }
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater link_name(adb, bucket, adbname);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (FIND_HINTOK(find))
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater adbname->flags |= NAME_HINT_OK;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (FIND_GLUEOK(find))
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater adbname->flags |= NAME_GLUE_OK;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (FIND_STARTATZONE(find))
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater adbname->flags |= NAME_STARTATZONE;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater } else {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater /* Move this name forward in the LRU list */
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater ISC_LIST_UNLINK(adb->names[bucket], adbname, plink);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater ISC_LIST_PREPEND(adb->names[bucket], adbname, plink);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater }
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater adbname->last_used = now;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater /*
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * Expire old entries, etc.
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater */
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater RUNTIME_CHECK(check_expire_namehooks(adbname, now) == ISC_FALSE);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater /*
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * Do we know that the name is an alias?
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater */
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (!EXPIRE_OK(adbname->expire_target, now)) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater /*
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * Yes, it is.
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater */
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater DP(DEF_LEVEL,
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews "dns_adb_createfind: name %s (%p) is an alias (cached)",
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews namebuf, adbname);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater alias = ISC_TRUE;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater goto post_copy;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater }
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater /*
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * Try to populate the name from the database and/or
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * start fetches. First try looking for an A record
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * in the database.
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater */
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (!NAME_HAS_V4(adbname) && EXPIRE_OK(adbname->expire_v4, now)
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater && WANT_INET(wanted_addresses)) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater result = dbfind_name(adbname, now, dns_rdatatype_a);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (result == ISC_R_SUCCESS) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater DP(DEF_LEVEL,
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews "dns_adb_createfind: found A for name %s (%p) in db",
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews namebuf, adbname);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater goto v6;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater }
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater /*
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * Did we get a CNAME or DNAME?
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater */
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (result == DNS_R_ALIAS) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater DP(DEF_LEVEL,
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews "dns_adb_createfind: name %s (%p) is an alias",
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews namebuf, adbname);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater alias = ISC_TRUE;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater goto post_copy;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater }
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater /*
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * If the name doesn't exist at all, don't bother with
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * v6 queries; they won't work.
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater *
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * If the name does exist but we didn't get our data, go
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * ahead and try AAAA.
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater *
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * If the result is neither of these, try a fetch for A.
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater */
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (NXDOMAIN_RESULT(result))
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater goto fetch;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater else if (NXRRSET_RESULT(result))
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater goto v6;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (!NAME_FETCH_V4(adbname))
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater wanted_fetches |= DNS_ADBFIND_INET;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater }
ea6228c9ce45dafa26e4cd79d71629c8ba5cd7c7Michael Graff
ff9bb3fc5453bbf310b67c560fbf04a5c0fb60daMichael Graff v6:
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (!NAME_HAS_V6(adbname) && EXPIRE_OK(adbname->expire_v6, now)
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater && WANT_INET6(wanted_addresses)) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater result = dbfind_name(adbname, now, dns_rdatatype_aaaa);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (result == ISC_R_SUCCESS) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater DP(DEF_LEVEL,
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews "dns_adb_createfind: found AAAA for name %s (%p)",
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews namebuf, adbname);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater goto fetch;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater }
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater /*
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * Did we get a CNAME or DNAME?
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater */
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (result == DNS_R_ALIAS) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater DP(DEF_LEVEL,
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews "dns_adb_createfind: name %s (%p) is an alias",
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews namebuf, adbname);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater alias = ISC_TRUE;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater goto post_copy;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater }
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater /*
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * Listen to negative cache hints, and don't start
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * another query.
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater */
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (NCACHE_RESULT(result) || AUTH_NX(result))
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater goto fetch;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (!NAME_FETCH_V6(adbname))
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater wanted_fetches |= DNS_ADBFIND_INET6;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater }
294802790e8030f1c19b6c2c5d5204b6f464c729Michael Graff
4a3ad0da975d7115d401700f955814a0dff1adb0Bob Halley fetch:
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if ((WANT_INET(wanted_addresses) && NAME_HAS_V4(adbname)) ||
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater (WANT_INET6(wanted_addresses) && NAME_HAS_V6(adbname)))
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater have_address = ISC_TRUE;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater else
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater have_address = ISC_FALSE;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (wanted_fetches != 0 &&
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater ! (FIND_AVOIDFETCHES(find) && have_address)) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater /*
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * We're missing at least one address family. Either the
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * caller hasn't instructed us to avoid fetches, or we don't
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * know anything about any of the address families that would
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * be acceptable so we have to launch fetches.
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater */
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (FIND_STARTATZONE(find))
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater start_at_zone = ISC_TRUE;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater /*
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * Start V4.
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater */
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (WANT_INET(wanted_fetches) &&
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater fetch_name(adbname, start_at_zone,
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater dns_rdatatype_a) == ISC_R_SUCCESS) {
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews DP(DEF_LEVEL, "dns_adb_createfind: "
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews "started A fetch for name %s (%p)",
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews namebuf, adbname);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater }
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater /*
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * Start V6.
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater */
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (WANT_INET6(wanted_fetches) &&
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater fetch_name(adbname, start_at_zone,
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater dns_rdatatype_aaaa) == ISC_R_SUCCESS) {
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews DP(DEF_LEVEL, "dns_adb_createfind: "
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews "started AAAA fetch for name %s (%p)",
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews namebuf, adbname);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater }
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater }
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater /*
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * Run through the name and copy out the bits we are
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * interested in.
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater */
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater copy_namehook_lists(adb, find, qname, qtype, adbname, now);
dec90b6caef758fe2890ee50db148cff6acffb90Michael Graff
5a675fa40aa755b21ab2906e90b1b80e2105291fMichael Graff post_copy:
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (NAME_FETCH_V4(adbname))
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater query_pending |= DNS_ADBFIND_INET;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (NAME_FETCH_V6(adbname))
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater query_pending |= DNS_ADBFIND_INET6;
306a93530536f05edfb477cac1c2667d90129a8fMichael Graff
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater /*
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * Attach to the name's query list if there are queries
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * already running, and we have been asked to.
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater */
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater want_event = ISC_TRUE;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (!FIND_WANTEVENT(find))
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater want_event = ISC_FALSE;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (FIND_WANTEMPTYEVENT(find) && FIND_HAS_ADDRS(find))
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater want_event = ISC_FALSE;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if ((wanted_addresses & query_pending) == 0)
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater want_event = ISC_FALSE;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (alias)
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater want_event = ISC_FALSE;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (want_event) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater find->adbname = adbname;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater find->name_bucket = bucket;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater ISC_LIST_APPEND(adbname->finds, find, plink);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater find->query_pending = (query_pending & wanted_addresses);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater find->flags &= ~DNS_ADBFIND_ADDRESSMASK;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater find->flags |= (find->query_pending & DNS_ADBFIND_ADDRESSMASK);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater DP(DEF_LEVEL, "createfind: attaching find %p to adbname %p",
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater find, adbname);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater } else {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater /*
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * Remove the flag so the caller knows there will never
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * be an event, and set internal flags to fake that
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * the event was sent and freed, so dns_adb_destroyfind() will
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * do the right thing.
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater */
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater find->query_pending = (query_pending & wanted_addresses);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater find->options &= ~DNS_ADBFIND_WANTEVENT;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater find->flags |= (FIND_EVENT_SENT | FIND_EVENT_FREED);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater find->flags &= ~DNS_ADBFIND_ADDRESSMASK;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater }
439c0011e642fb1d26011116144af698125262dbMichael Graff
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater find->partial_result |= (adbname->partial_result & wanted_addresses);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (alias) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (target != NULL) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater result = dns_name_copy(&adbname->target, target, NULL);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (result != ISC_R_SUCCESS)
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater goto out;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater }
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater result = DNS_R_ALIAS;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater } else
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater result = ISC_R_SUCCESS;
86944a4c8002e80ae9b6eb5a5e29b797879be45fMichael Graff
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater /*
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * Copy out error flags from the name structure into the find.
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater */
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater find->result_v4 = find_err_map[adbname->fetch_err];
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater find->result_v6 = find_err_map[adbname->fetch6_err];
86944a4c8002e80ae9b6eb5a5e29b797879be45fMichael Graff
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater out:
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (find != NULL) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater *findp = find;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (want_event) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater isc_task_t *taskp;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater INSIST((find->flags & DNS_ADBFIND_ADDRESSMASK) != 0);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater taskp = NULL;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater isc_task_attach(task, &taskp);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater find->event.ev_sender = taskp;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater find->event.ev_action = action;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater find->event.ev_arg = arg;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater }
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater }
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater UNLOCK(&adb->namelocks[bucket]);
439c0011e642fb1d26011116144af698125262dbMichael Graff
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater return (result);
3c5148c4d98af51d6dcb449c6dbd45fe8c645f61Michael Graff}
3c5148c4d98af51d6dcb449c6dbd45fe8c645f61Michael Graff
66bd3b3c6b171271c705b897823dcdcf29464698Michael Graffvoid
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrencedns_adb_destroyfind(dns_adbfind_t **findp) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater dns_adbfind_t *find;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater dns_adbentry_t *entry;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater dns_adbaddrinfo_t *ai;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater int bucket;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater dns_adb_t *adb;
27fe1966c948ba0c1c9d0d831ea3d8bf32d052acTatuya JINMEI 神明達哉 isc_boolean_t overmem;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater REQUIRE(findp != NULL && DNS_ADBFIND_VALID(*findp));
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater find = *findp;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater *findp = NULL;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater LOCK(&find->lock);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater DP(DEF_LEVEL, "dns_adb_destroyfind on find %p", find);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater adb = find->adb;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater REQUIRE(DNS_ADB_VALID(adb));
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater REQUIRE(FIND_EVENTFREED(find));
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater bucket = find->name_bucket;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater INSIST(bucket == DNS_ADB_INVALIDBUCKET);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater UNLOCK(&find->lock);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater /*
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * The find doesn't exist on any list, and nothing is locked.
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * Return the find to the memory pool, and decrement the adb's
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * reference count.
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater */
27fe1966c948ba0c1c9d0d831ea3d8bf32d052acTatuya JINMEI 神明達哉 overmem = isc_mem_isovermem(adb->mctx);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater ai = ISC_LIST_HEAD(find->list);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater while (ai != NULL) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater ISC_LIST_UNLINK(find->list, ai, publink);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater entry = ai->entry;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater ai->entry = NULL;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater INSIST(DNS_ADBENTRY_VALID(entry));
27fe1966c948ba0c1c9d0d831ea3d8bf32d052acTatuya JINMEI 神明達哉 RUNTIME_CHECK(dec_entry_refcnt(adb, overmem, entry, ISC_TRUE) ==
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater ISC_FALSE);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater free_adbaddrinfo(adb, &ai);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater ai = ISC_LIST_HEAD(find->list);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater }
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater /*
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * WARNING: The find is freed with the adb locked. This is done
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * to avoid a race condition where we free the find, some other
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * thread tests to see if it should be destroyed, detects it should
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * be, destroys it, and then we try to lock it for our check, but the
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * lock is destroyed.
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater */
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater LOCK(&adb->lock);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (free_adbfind(adb, &find))
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater check_exit(adb);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater UNLOCK(&adb->lock);
66bd3b3c6b171271c705b897823dcdcf29464698Michael Graff}
64828244e04e86dfa40f0a4f0c05f27923da499dMichael Graff
897c9ddb4d745b2bfecf98b17e5487bb6656299aMichael Graffvoid
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrencedns_adb_cancelfind(dns_adbfind_t *find) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater isc_event_t *ev;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater isc_task_t *task;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater dns_adb_t *adb;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater int bucket;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater int unlock_bucket;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater LOCK(&find->lock);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater DP(DEF_LEVEL, "dns_adb_cancelfind on find %p", find);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater adb = find->adb;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater REQUIRE(DNS_ADB_VALID(adb));
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater REQUIRE(!FIND_EVENTFREED(find));
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater REQUIRE(FIND_WANTEVENT(find));
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater bucket = find->name_bucket;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (bucket == DNS_ADB_INVALIDBUCKET)
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater goto cleanup;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater /*
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * We need to get the adbname's lock to unlink the find.
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater */
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater unlock_bucket = bucket;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater violate_locking_hierarchy(&find->lock, &adb->namelocks[unlock_bucket]);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater bucket = find->name_bucket;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (bucket != DNS_ADB_INVALIDBUCKET) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater ISC_LIST_UNLINK(find->adbname->finds, find, plink);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater find->adbname = NULL;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater find->name_bucket = DNS_ADB_INVALIDBUCKET;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater }
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater UNLOCK(&adb->namelocks[unlock_bucket]);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater bucket = DNS_ADB_INVALIDBUCKET;
0874abad14e3e9ecfc3dc1a1a2b9969f2f027724Mark Andrews POST(bucket);
897c9ddb4d745b2bfecf98b17e5487bb6656299aMichael Graff
897c9ddb4d745b2bfecf98b17e5487bb6656299aMichael Graff cleanup:
897c9ddb4d745b2bfecf98b17e5487bb6656299aMichael Graff
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (!FIND_EVENTSENT(find)) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater ev = &find->event;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater task = ev->ev_sender;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater ev->ev_sender = find;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater ev->ev_type = DNS_EVENT_ADBCANCELED;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater ev->ev_destroy = event_free;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater ev->ev_destroy_arg = find;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater find->result_v4 = ISC_R_CANCELED;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater find->result_v6 = ISC_R_CANCELED;
897c9ddb4d745b2bfecf98b17e5487bb6656299aMichael Graff
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater DP(DEF_LEVEL, "sending event %p to task %p for find %p",
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater ev, task, find);
897c9ddb4d745b2bfecf98b17e5487bb6656299aMichael Graff
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater isc_task_sendanddetach(&task, (isc_event_t **)&ev);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater }
897c9ddb4d745b2bfecf98b17e5487bb6656299aMichael Graff
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater UNLOCK(&find->lock);
897c9ddb4d745b2bfecf98b17e5487bb6656299aMichael Graff}
897c9ddb4d745b2bfecf98b17e5487bb6656299aMichael Graff
64828244e04e86dfa40f0a4f0c05f27923da499dMichael Graffvoid
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrencedns_adb_dump(dns_adb_t *adb, FILE *f) {
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews unsigned int i;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater isc_stdtime_t now;
dd95acdbce0e2a2775391709cdfca0a9eda7e8f7Mark Andrews
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater REQUIRE(DNS_ADB_VALID(adb));
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater REQUIRE(f != NULL);
64828244e04e86dfa40f0a4f0c05f27923da499dMichael Graff
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater /*
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * Lock the adb itself, lock all the name buckets, then lock all
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * the entry buckets. This should put the adb into a state where
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * nothing can change, so we can iterate through everything and
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * print at our leisure.
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater */
64828244e04e86dfa40f0a4f0c05f27923da499dMichael Graff
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater LOCK(&adb->lock);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater isc_stdtime_get(&now);
dd95acdbce0e2a2775391709cdfca0a9eda7e8f7Mark Andrews
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews for (i = 0; i < adb->nnames; i++)
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater RUNTIME_CHECK(cleanup_names(adb, i, now) == ISC_FALSE);
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews for (i = 0; i < adb->nentries; i++)
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater RUNTIME_CHECK(cleanup_entries(adb, i, now) == ISC_FALSE);
dd95acdbce0e2a2775391709cdfca0a9eda7e8f7Mark Andrews
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater dump_adb(adb, f, ISC_FALSE, now);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater UNLOCK(&adb->lock);
1c3bc66ada38236cc81c41b7174a9f0a872c9ab6Michael Graff}
1c3bc66ada38236cc81c41b7174a9f0a872c9ab6Michael Graff
1c3bc66ada38236cc81c41b7174a9f0a872c9ab6Michael Graffstatic void
5fca48054b5e791a2fa0c5015bc3b6fef4fcdce1Andreas Gustafssondump_ttl(FILE *f, const char *legend, isc_stdtime_t value, isc_stdtime_t now) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (value == INT_MAX)
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater return;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater fprintf(f, " [%s TTL %d]", legend, value - now);
5fca48054b5e791a2fa0c5015bc3b6fef4fcdce1Andreas Gustafsson}
5fca48054b5e791a2fa0c5015bc3b6fef4fcdce1Andreas Gustafsson
5fca48054b5e791a2fa0c5015bc3b6fef4fcdce1Andreas Gustafssonstatic void
dd95acdbce0e2a2775391709cdfca0a9eda7e8f7Mark Andrewsdump_adb(dns_adb_t *adb, FILE *f, isc_boolean_t debug, isc_stdtime_t now) {
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews unsigned int i;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater dns_adbname_t *name;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater dns_adbentry_t *entry;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater fprintf(f, ";\n; Address database dump\n;\n");
7c19754baccc946eb655f49b6981fe6c0d478dfaMark Andrews fprintf(f, "; [edns success/4096 timeout/1432 timeout/1232 timeout/"
7c19754baccc946eb655f49b6981fe6c0d478dfaMark Andrews "512 timeout]\n");
7c19754baccc946eb655f49b6981fe6c0d478dfaMark Andrews fprintf(f, "; [plain success/timeout]\n;\n");
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (debug)
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater fprintf(f, "; addr %p, erefcnt %u, irefcnt %u, finds out %u\n",
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater adb, adb->erefcnt, adb->irefcnt,
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater isc_mempool_getallocated(adb->nhmp));
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews for (i = 0; i < adb->nnames; i++)
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater LOCK(&adb->namelocks[i]);
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews for (i = 0; i < adb->nentries; i++)
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater LOCK(&adb->entrylocks[i]);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater /*
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * Dump the names
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater */
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews for (i = 0; i < adb->nnames; i++) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater name = ISC_LIST_HEAD(adb->names[i]);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (name == NULL)
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater continue;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (debug)
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater fprintf(f, "; bucket %d\n", i);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater for (;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater name != NULL;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater name = ISC_LIST_NEXT(name, plink))
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (debug)
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater fprintf(f, "; name %p (flags %08x)\n",
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater name, name->flags);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater fprintf(f, "; ");
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater print_dns_name(f, &name->name);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (dns_name_countlabels(&name->target) > 0) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater fprintf(f, " alias ");
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater print_dns_name(f, &name->target);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater }
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater dump_ttl(f, "v4", name->expire_v4, now);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater dump_ttl(f, "v6", name->expire_v6, now);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater dump_ttl(f, "target", name->expire_target, now);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater fprintf(f, " [v4 %s] [v6 %s]",
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater errnames[name->fetch_err],
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater errnames[name->fetch6_err]);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater fprintf(f, "\n");
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater print_namehook_list(f, "v4", &name->v4, debug, now);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater print_namehook_list(f, "v6", &name->v6, debug, now);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (debug)
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater print_fetch_list(f, name);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (debug)
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater print_find_list(f, name);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater }
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater }
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater fprintf(f, ";\n; Unassociated entries\n;\n");
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews for (i = 0; i < adb->nentries; i++) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater entry = ISC_LIST_HEAD(adb->entries[i]);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater while (entry != NULL) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (entry->refcnt == 0)
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater dump_entry(f, entry, debug, now);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater entry = ISC_LIST_NEXT(entry, plink);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater }
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater }
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater /*
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * Unlock everything
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater */
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews for (i = 0; i < adb->nentries; i++)
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater UNLOCK(&adb->entrylocks[i]);
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews for (i = 0; i < adb->nnames; i++)
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater UNLOCK(&adb->namelocks[i]);
64828244e04e86dfa40f0a4f0c05f27923da499dMichael Graff}
64828244e04e86dfa40f0a4f0c05f27923da499dMichael Graff
5fca48054b5e791a2fa0c5015bc3b6fef4fcdce1Andreas Gustafssonstatic void
550085fed1d0af54ba5b2f588898afec158195deMark Andrewsdump_entry(FILE *f, dns_adbentry_t *entry, isc_boolean_t debug,
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater isc_stdtime_t now)
5fca48054b5e791a2fa0c5015bc3b6fef4fcdce1Andreas Gustafsson{
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater char addrbuf[ISC_NETADDR_FORMATSIZE];
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater char typebuf[DNS_RDATATYPE_FORMATSIZE];
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater isc_netaddr_t netaddr;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater dns_adblameinfo_t *li;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater isc_netaddr_fromsockaddr(&netaddr, &entry->sockaddr);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater isc_netaddr_format(&netaddr, addrbuf, sizeof(addrbuf));
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (debug)
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater fprintf(f, ";\t%p: refcnt %u\n", entry, entry->refcnt);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews fprintf(f, ";\t%s [srtt %u] [flags %08x] [edns %u/%u/%u/%u/%u] "
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews "[plain %u/%u]", addrbuf, entry->srtt, entry->flags,
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews entry->edns, entry->to4096, entry->to1432, entry->to1232,
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews entry->to512, entry->plain, entry->plainto);
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews if (entry->udpsize != 0U)
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews fprintf(f, " [udpsize %u]", entry->udpsize);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (entry->expires != 0)
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater fprintf(f, " [ttl %d]", entry->expires - now);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater fprintf(f, "\n");
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater for (li = ISC_LIST_HEAD(entry->lameinfo);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater li != NULL;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater li = ISC_LIST_NEXT(li, plink)) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater fprintf(f, ";\t\t");
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater print_dns_name(f, &li->qname);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater dns_rdatatype_format(li->qtype, typebuf, sizeof(typebuf));
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater fprintf(f, " %s [lame TTL %d]\n", typebuf,
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater li->lame_timer - now);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater }
5fca48054b5e791a2fa0c5015bc3b6fef4fcdce1Andreas Gustafsson}
5fca48054b5e791a2fa0c5015bc3b6fef4fcdce1Andreas Gustafsson
86944a4c8002e80ae9b6eb5a5e29b797879be45fMichael Graffvoid
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrencedns_adb_dumpfind(dns_adbfind_t *find, FILE *f) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater char tmp[512];
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater const char *tmpp;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater dns_adbaddrinfo_t *ai;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater isc_sockaddr_t *sa;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater /*
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * Not used currently, in the API Just In Case we
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * want to dump out the name and/or entries too.
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater */
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater LOCK(&find->lock);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater fprintf(f, ";Find %p\n", find);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater fprintf(f, ";\tqpending %08x partial %08x options %08x flags %08x\n",
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater find->query_pending, find->partial_result,
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater find->options, find->flags);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater fprintf(f, ";\tname_bucket %d, name %p, event sender %p\n",
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater find->name_bucket, find->adbname, find->event.ev_sender);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater ai = ISC_LIST_HEAD(find->list);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (ai != NULL)
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater fprintf(f, "\tAddresses:\n");
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater while (ai != NULL) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater sa = &ai->sockaddr;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater switch (sa->type.sa.sa_family) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater case AF_INET:
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater tmpp = inet_ntop(AF_INET, &sa->type.sin.sin_addr,
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater tmp, sizeof(tmp));
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater break;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater case AF_INET6:
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater tmpp = inet_ntop(AF_INET6, &sa->type.sin6.sin6_addr,
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater tmp, sizeof(tmp));
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater break;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater default:
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater tmpp = "UnkFamily";
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater }
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (tmpp == NULL)
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater tmpp = "BadAddress";
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater fprintf(f, "\t\tentry %p, flags %08x"
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater " srtt %u addr %s\n",
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater ai->entry, ai->flags, ai->srtt, tmpp);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater ai = ISC_LIST_NEXT(ai, publink);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater }
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater UNLOCK(&find->lock);
86944a4c8002e80ae9b6eb5a5e29b797879be45fMichael Graff}
86944a4c8002e80ae9b6eb5a5e29b797879be45fMichael Graff
64828244e04e86dfa40f0a4f0c05f27923da499dMichael Graffstatic void
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrenceprint_dns_name(FILE *f, dns_name_t *name) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater char buf[DNS_NAME_FORMATSIZE];
64828244e04e86dfa40f0a4f0c05f27923da499dMichael Graff
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater INSIST(f != NULL);
64828244e04e86dfa40f0a4f0c05f27923da499dMichael Graff
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater dns_name_format(name, buf, sizeof(buf));
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater fprintf(f, "%s", buf);
64828244e04e86dfa40f0a4f0c05f27923da499dMichael Graff}
64828244e04e86dfa40f0a4f0c05f27923da499dMichael Graff
64828244e04e86dfa40f0a4f0c05f27923da499dMichael Graffstatic void
5fca48054b5e791a2fa0c5015bc3b6fef4fcdce1Andreas Gustafssonprint_namehook_list(FILE *f, const char *legend, dns_adbnamehooklist_t *list,
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater isc_boolean_t debug, isc_stdtime_t now)
5fca48054b5e791a2fa0c5015bc3b6fef4fcdce1Andreas Gustafsson{
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater dns_adbnamehook_t *nh;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater for (nh = ISC_LIST_HEAD(*list);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater nh != NULL;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater nh = ISC_LIST_NEXT(nh, plink))
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (debug)
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater fprintf(f, ";\tHook(%s) %p\n", legend, nh);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater dump_entry(f, nh->entry, debug, now);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater }
64828244e04e86dfa40f0a4f0c05f27923da499dMichael Graff}
86944a4c8002e80ae9b6eb5a5e29b797879be45fMichael Graff
517274e709a3c730cd42f37dc1260dde95d1ea38Michael Graffstatic inline void
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrenceprint_fetch(FILE *f, dns_adbfetch_t *ft, const char *type) {
5d0984f4fd3133c869b0736adb5291e6fca34a0cTatuya JINMEI 神明達哉 fprintf(f, "\t\tFetch(%s): %p -> { fetch %p }\n",
5d0984f4fd3133c869b0736adb5291e6fca34a0cTatuya JINMEI 神明達哉 type, ft, ft->fetch);
517274e709a3c730cd42f37dc1260dde95d1ea38Michael Graff}
517274e709a3c730cd42f37dc1260dde95d1ea38Michael Graff
59e22acc4f79ff481f7bfa46ef0558957ae53cfcMichael Graffstatic void
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrenceprint_fetch_list(FILE *f, dns_adbname_t *n) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (NAME_FETCH_A(n))
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater print_fetch(f, n->fetch_a, "A");
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (NAME_FETCH_AAAA(n))
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater print_fetch(f, n->fetch_aaaa, "AAAA");
1c3bc66ada38236cc81c41b7174a9f0a872c9ab6Michael Graff}
1c3bc66ada38236cc81c41b7174a9f0a872c9ab6Michael Graff
86944a4c8002e80ae9b6eb5a5e29b797879be45fMichael Graffstatic void
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrenceprint_find_list(FILE *f, dns_adbname_t *name) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater dns_adbfind_t *find;
86944a4c8002e80ae9b6eb5a5e29b797879be45fMichael Graff
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater find = ISC_LIST_HEAD(name->finds);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater while (find != NULL) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater dns_adb_dumpfind(find, f);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater find = ISC_LIST_NEXT(find, plink);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater }
86944a4c8002e80ae9b6eb5a5e29b797879be45fMichael Graff}
d8590892d10fc9528b0dde7e2781935e7b8d7a87Michael Graff
d8590892d10fc9528b0dde7e2781935e7b8d7a87Michael Graffstatic isc_result_t
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrencedbfind_name(dns_adbname_t *adbname, isc_stdtime_t now, dns_rdatatype_t rdtype)
d8590892d10fc9528b0dde7e2781935e7b8d7a87Michael Graff{
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater isc_result_t result;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater dns_rdataset_t rdataset;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater dns_adb_t *adb;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater dns_fixedname_t foundname;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater dns_name_t *fname;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater INSIST(DNS_ADBNAME_VALID(adbname));
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater adb = adbname->adb;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater INSIST(DNS_ADB_VALID(adb));
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater INSIST(rdtype == dns_rdatatype_a || rdtype == dns_rdatatype_aaaa);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater dns_fixedname_init(&foundname);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater fname = dns_fixedname_name(&foundname);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater dns_rdataset_init(&rdataset);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (rdtype == dns_rdatatype_a)
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater adbname->fetch_err = FIND_ERR_UNEXPECTED;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater else
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater adbname->fetch6_err = FIND_ERR_UNEXPECTED;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
743bbdc18f839499862e4fb28ec32f607b1632dcTatuya JINMEI 神明達哉 /*
743bbdc18f839499862e4fb28ec32f607b1632dcTatuya JINMEI 神明達哉 * We need to specify whether to search static-stub zones (if
743bbdc18f839499862e4fb28ec32f607b1632dcTatuya JINMEI 神明達哉 * configured) depending on whether this is a "start at zone" lookup,
743bbdc18f839499862e4fb28ec32f607b1632dcTatuya JINMEI 神明達哉 * i.e., whether it's a "bailiwick" glue. If it's bailiwick (in which
743bbdc18f839499862e4fb28ec32f607b1632dcTatuya JINMEI 神明達哉 * case NAME_STARTATZONE is set) we need to stop the search at any
743bbdc18f839499862e4fb28ec32f607b1632dcTatuya JINMEI 神明達哉 * matching static-stub zone without looking into the cache to honor
743bbdc18f839499862e4fb28ec32f607b1632dcTatuya JINMEI 神明達哉 * the configuration on which server we should send queries to.
743bbdc18f839499862e4fb28ec32f607b1632dcTatuya JINMEI 神明達哉 */
743bbdc18f839499862e4fb28ec32f607b1632dcTatuya JINMEI 神明達哉 result = dns_view_find2(adb->view, &adbname->name, rdtype, now,
743bbdc18f839499862e4fb28ec32f607b1632dcTatuya JINMEI 神明達哉 NAME_GLUEOK(adbname) ? DNS_DBFIND_GLUEOK : 0,
743bbdc18f839499862e4fb28ec32f607b1632dcTatuya JINMEI 神明達哉 ISC_TF(NAME_HINTOK(adbname)),
743bbdc18f839499862e4fb28ec32f607b1632dcTatuya JINMEI 神明達哉 (adbname->flags & NAME_STARTATZONE) != 0 ?
743bbdc18f839499862e4fb28ec32f607b1632dcTatuya JINMEI 神明達哉 ISC_TRUE : ISC_FALSE,
743bbdc18f839499862e4fb28ec32f607b1632dcTatuya JINMEI 神明達哉 NULL, NULL, fname, &rdataset, NULL);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater /* XXXVIX this switch statement is too sparse to gen a jump table. */
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater switch (result) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater case DNS_R_GLUE:
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater case DNS_R_HINT:
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater case ISC_R_SUCCESS:
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater /*
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * Found in the database. Even if we can't copy out
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * any information, return success, or else a fetch
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * will be made, which will only make things worse.
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater */
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (rdtype == dns_rdatatype_a)
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater adbname->fetch_err = FIND_ERR_SUCCESS;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater else
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater adbname->fetch6_err = FIND_ERR_SUCCESS;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater result = import_rdataset(adbname, &rdataset, now);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater break;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater case DNS_R_NXDOMAIN:
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater case DNS_R_NXRRSET:
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater /*
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * We're authoritative and the data doesn't exist.
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * Make up a negative cache entry so we don't ask again
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * for a while.
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater *
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * XXXRTH What time should we use? I'm putting in 30 seconds
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * for now.
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater */
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (rdtype == dns_rdatatype_a) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater adbname->expire_v4 = now + 30;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater DP(NCACHE_LEVEL,
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater "adb name %p: Caching auth negative entry for A",
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater adbname);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (result == DNS_R_NXDOMAIN)
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater adbname->fetch_err = FIND_ERR_NXDOMAIN;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater else
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater adbname->fetch_err = FIND_ERR_NXRRSET;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater } else {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater DP(NCACHE_LEVEL,
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater "adb name %p: Caching auth negative entry for AAAA",
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater adbname);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater adbname->expire_v6 = now + 30;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (result == DNS_R_NXDOMAIN)
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater adbname->fetch6_err = FIND_ERR_NXDOMAIN;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater else
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater adbname->fetch6_err = FIND_ERR_NXRRSET;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater }
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater break;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater case DNS_R_NCACHENXDOMAIN:
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater case DNS_R_NCACHENXRRSET:
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater /*
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * We found a negative cache entry. Pull the TTL from it
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * so we won't ask again for a while.
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater */
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater rdataset.ttl = ttlclamp(rdataset.ttl);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (rdtype == dns_rdatatype_a) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater adbname->expire_v4 = rdataset.ttl + now;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (result == DNS_R_NCACHENXDOMAIN)
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater adbname->fetch_err = FIND_ERR_NXDOMAIN;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater else
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater adbname->fetch_err = FIND_ERR_NXRRSET;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater DP(NCACHE_LEVEL,
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater "adb name %p: Caching negative entry for A (ttl %u)",
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater adbname, rdataset.ttl);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater } else {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater DP(NCACHE_LEVEL,
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater "adb name %p: Caching negative entry for AAAA (ttl %u)",
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater adbname, rdataset.ttl);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater adbname->expire_v6 = rdataset.ttl + now;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (result == DNS_R_NCACHENXDOMAIN)
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater adbname->fetch6_err = FIND_ERR_NXDOMAIN;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater else
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater adbname->fetch6_err = FIND_ERR_NXRRSET;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater }
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater break;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater case DNS_R_CNAME:
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater case DNS_R_DNAME:
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater /*
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * Clear the hint and glue flags, so this will match
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * more often.
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater */
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater adbname->flags &= ~(DNS_ADBFIND_GLUEOK | DNS_ADBFIND_HINTOK);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater rdataset.ttl = ttlclamp(rdataset.ttl);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater clean_target(adb, &adbname->target);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater adbname->expire_target = INT_MAX;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater result = set_target(adb, &adbname->name, fname, &rdataset,
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater &adbname->target);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (result == ISC_R_SUCCESS) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater result = DNS_R_ALIAS;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater DP(NCACHE_LEVEL,
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater "adb name %p: caching alias target",
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater adbname);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater adbname->expire_target = rdataset.ttl + now;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater }
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (rdtype == dns_rdatatype_a)
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater adbname->fetch_err = FIND_ERR_SUCCESS;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater else
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater adbname->fetch6_err = FIND_ERR_SUCCESS;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater break;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater }
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (dns_rdataset_isassociated(&rdataset))
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater dns_rdataset_disassociate(&rdataset);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater return (result);
528829aa8ad69238e674cd81078bc14d4199691bMichael Graff}
528829aa8ad69238e674cd81078bc14d4199691bMichael Graff
1c3bc66ada38236cc81c41b7174a9f0a872c9ab6Michael Graffstatic void
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrencefetch_callback(isc_task_t *task, isc_event_t *ev) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater dns_fetchevent_t *dev;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater dns_adbname_t *name;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater dns_adb_t *adb;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater dns_adbfetch_t *fetch;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater int bucket;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater isc_eventtype_t ev_status;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater isc_stdtime_t now;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater isc_result_t result;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater unsigned int address_type;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater isc_boolean_t want_check_exit = ISC_FALSE;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater UNUSED(task);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater INSIST(ev->ev_type == DNS_EVENT_FETCHDONE);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater dev = (dns_fetchevent_t *)ev;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater name = ev->ev_arg;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater INSIST(DNS_ADBNAME_VALID(name));
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater adb = name->adb;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater INSIST(DNS_ADB_VALID(adb));
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater bucket = name->lock_bucket;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater LOCK(&adb->namelocks[bucket]);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater INSIST(NAME_FETCH_A(name) || NAME_FETCH_AAAA(name));
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater address_type = 0;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (NAME_FETCH_A(name) && (name->fetch_a->fetch == dev->fetch)) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater address_type = DNS_ADBFIND_INET;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater fetch = name->fetch_a;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater name->fetch_a = NULL;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater } else if (NAME_FETCH_AAAA(name)
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater && (name->fetch_aaaa->fetch == dev->fetch)) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater address_type = DNS_ADBFIND_INET6;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater fetch = name->fetch_aaaa;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater name->fetch_aaaa = NULL;
f2d09cd90d63ea6842a7d4a2bfacb0d89be47d1cMark Andrews } else
f2d09cd90d63ea6842a7d4a2bfacb0d89be47d1cMark Andrews fetch = NULL;
f2d09cd90d63ea6842a7d4a2bfacb0d89be47d1cMark Andrews
f2d09cd90d63ea6842a7d4a2bfacb0d89be47d1cMark Andrews INSIST(address_type != 0 && fetch != NULL);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater dns_resolver_destroyfetch(&fetch->fetch);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater dev->fetch = NULL;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater ev_status = DNS_EVENT_ADBNOMOREADDRESSES;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater /*
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * Cleanup things we don't care about.
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater */
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (dev->node != NULL)
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater dns_db_detachnode(dev->db, &dev->node);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (dev->db != NULL)
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater dns_db_detach(&dev->db);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater /*
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * If this name is marked as dead, clean up, throwing away
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * potentially good data.
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater */
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (NAME_DEAD(name)) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater free_adbfetch(adb, &fetch);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater isc_event_free(&ev);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
c82bb6a709abe89c051485b49403ef5bad1b756cTatuya JINMEI 神明達哉 want_check_exit = kill_name(&name, DNS_EVENT_ADBCANCELED);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater UNLOCK(&adb->namelocks[bucket]);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (want_check_exit) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater LOCK(&adb->lock);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater check_exit(adb);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater UNLOCK(&adb->lock);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater }
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater return;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater }
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater isc_stdtime_get(&now);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater /*
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * If we got a negative cache response, remember it.
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater */
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (NCACHE_RESULT(dev->result)) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater dev->rdataset->ttl = ttlclamp(dev->rdataset->ttl);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (address_type == DNS_ADBFIND_INET) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater DP(NCACHE_LEVEL, "adb fetch name %p: "
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater "caching negative entry for A (ttl %u)",
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater name, dev->rdataset->ttl);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater name->expire_v4 = ISC_MIN(name->expire_v4,
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater dev->rdataset->ttl + now);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (dev->result == DNS_R_NCACHENXDOMAIN)
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater name->fetch_err = FIND_ERR_NXDOMAIN;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater else
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater name->fetch_err = FIND_ERR_NXRRSET;
8907d8fa04fdaa65baf0bc6b01230b2ebde93106Mark Andrews inc_stats(adb, dns_resstatscounter_gluefetchv4fail);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater } else {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater DP(NCACHE_LEVEL, "adb fetch name %p: "
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater "caching negative entry for AAAA (ttl %u)",
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater name, dev->rdataset->ttl);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater name->expire_v6 = ISC_MIN(name->expire_v6,
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater dev->rdataset->ttl + now);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (dev->result == DNS_R_NCACHENXDOMAIN)
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater name->fetch6_err = FIND_ERR_NXDOMAIN;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater else
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater name->fetch6_err = FIND_ERR_NXRRSET;
8907d8fa04fdaa65baf0bc6b01230b2ebde93106Mark Andrews inc_stats(adb, dns_resstatscounter_gluefetchv6fail);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater }
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater goto out;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater }
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater /*
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * Handle CNAME/DNAME.
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater */
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (dev->result == DNS_R_CNAME || dev->result == DNS_R_DNAME) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater dev->rdataset->ttl = ttlclamp(dev->rdataset->ttl);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater clean_target(adb, &name->target);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater name->expire_target = INT_MAX;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater result = set_target(adb, &name->name,
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater dns_fixedname_name(&dev->foundname),
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater dev->rdataset,
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater &name->target);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (result == ISC_R_SUCCESS) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater DP(NCACHE_LEVEL,
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater "adb fetch name %p: caching alias target",
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater name);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater name->expire_target = dev->rdataset->ttl + now;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater }
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater goto check_result;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater }
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater /*
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * Did we get back junk? If so, and there are no more fetches
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * sitting out there, tell all the finds about it.
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater */
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (dev->result != ISC_R_SUCCESS) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater char buf[DNS_NAME_FORMATSIZE];
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater dns_name_format(&name->name, buf, sizeof(buf));
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater DP(DEF_LEVEL, "adb: fetch of '%s' %s failed: %s",
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater buf, address_type == DNS_ADBFIND_INET ? "A" : "AAAA",
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater dns_result_totext(dev->result));
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater /* XXXMLG Don't pound on bad servers. */
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (address_type == DNS_ADBFIND_INET) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater name->expire_v4 = ISC_MIN(name->expire_v4, now + 300);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater name->fetch_err = FIND_ERR_FAILURE;
8907d8fa04fdaa65baf0bc6b01230b2ebde93106Mark Andrews inc_stats(adb, dns_resstatscounter_gluefetchv4fail);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater } else {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater name->expire_v6 = ISC_MIN(name->expire_v6, now + 300);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater name->fetch6_err = FIND_ERR_FAILURE;
8907d8fa04fdaa65baf0bc6b01230b2ebde93106Mark Andrews inc_stats(adb, dns_resstatscounter_gluefetchv6fail);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater }
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater goto out;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater }
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater /*
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * We got something potentially useful.
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater */
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater result = import_rdataset(name, &fetch->rdataset, now);
4abed3e3563c7ad346178433130e6d150d3ffeafBob Halley
4abed3e3563c7ad346178433130e6d150d3ffeafBob Halley check_result:
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (result == ISC_R_SUCCESS) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater ev_status = DNS_EVENT_ADBMOREADDRESSES;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (address_type == DNS_ADBFIND_INET)
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater name->fetch_err = FIND_ERR_SUCCESS;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater else
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater name->fetch6_err = FIND_ERR_SUCCESS;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater }
528829aa8ad69238e674cd81078bc14d4199691bMichael Graff
528829aa8ad69238e674cd81078bc14d4199691bMichael Graff out:
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater free_adbfetch(adb, &fetch);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater isc_event_free(&ev);
528829aa8ad69238e674cd81078bc14d4199691bMichael Graff
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater clean_finds_at_name(name, ev_status, address_type);
1c3bc66ada38236cc81c41b7174a9f0a872c9ab6Michael Graff
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater UNLOCK(&adb->namelocks[bucket]);
1c3bc66ada38236cc81c41b7174a9f0a872c9ab6Michael Graff}
1c3bc66ada38236cc81c41b7174a9f0a872c9ab6Michael Graff
ea6228c9ce45dafa26e4cd79d71629c8ba5cd7c7Michael Graffstatic isc_result_t
49a940dc68b30d9e4f9e1bd3c0503d8b90bb1726Mark Andrewsfetch_name(dns_adbname_t *adbname,
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater isc_boolean_t start_at_zone,
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater dns_rdatatype_t type)
49a940dc68b30d9e4f9e1bd3c0503d8b90bb1726Mark Andrews{
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater isc_result_t result;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater dns_adbfetch_t *fetch = NULL;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater dns_adb_t *adb;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater dns_fixedname_t fixed;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater dns_name_t *name;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater dns_rdataset_t rdataset;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater dns_rdataset_t *nameservers;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater unsigned int options;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater INSIST(DNS_ADBNAME_VALID(adbname));
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater adb = adbname->adb;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater INSIST(DNS_ADB_VALID(adb));
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater INSIST((type == dns_rdatatype_a && !NAME_FETCH_V4(adbname)) ||
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater (type == dns_rdatatype_aaaa && !NAME_FETCH_V6(adbname)));
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater adbname->fetch_err = FIND_ERR_NOTFOUND;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater name = NULL;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater nameservers = NULL;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater dns_rdataset_init(&rdataset);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater options = DNS_FETCHOPT_NOVALIDATE;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (start_at_zone) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater DP(ENTER_LEVEL,
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater "fetch_name: starting at zone for name %p",
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater adbname);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater dns_fixedname_init(&fixed);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater name = dns_fixedname_name(&fixed);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater result = dns_view_findzonecut2(adb->view, &adbname->name, name,
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater 0, 0, ISC_TRUE, ISC_FALSE,
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater &rdataset, NULL);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (result != ISC_R_SUCCESS && result != DNS_R_HINT)
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater goto cleanup;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater nameservers = &rdataset;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater options |= DNS_FETCHOPT_UNSHARED;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater }
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater fetch = new_adbfetch(adb);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (fetch == NULL) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater result = ISC_R_NOMEMORY;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater goto cleanup;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater }
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater result = dns_resolver_createfetch(adb->view->resolver, &adbname->name,
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater type, name, nameservers, NULL,
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater options, adb->task, fetch_callback,
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater adbname, &fetch->rdataset, NULL,
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater &fetch->fetch);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (result != ISC_R_SUCCESS)
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater goto cleanup;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
ddad35552931651426ad70912d29d9ab7d2a8d80Automatic Updater if (type == dns_rdatatype_a) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater adbname->fetch_a = fetch;
8907d8fa04fdaa65baf0bc6b01230b2ebde93106Mark Andrews inc_stats(adb, dns_resstatscounter_gluefetchv4);
ddad35552931651426ad70912d29d9ab7d2a8d80Automatic Updater } else {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater adbname->fetch_aaaa = fetch;
8907d8fa04fdaa65baf0bc6b01230b2ebde93106Mark Andrews inc_stats(adb, dns_resstatscounter_gluefetchv6);
8907d8fa04fdaa65baf0bc6b01230b2ebde93106Mark Andrews }
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater fetch = NULL; /* Keep us from cleaning this up below. */
1c3bc66ada38236cc81c41b7174a9f0a872c9ab6Michael Graff
1c3bc66ada38236cc81c41b7174a9f0a872c9ab6Michael Graff cleanup:
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (fetch != NULL)
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater free_adbfetch(adb, &fetch);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (dns_rdataset_isassociated(&rdataset))
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater dns_rdataset_disassociate(&rdataset);
e883738546c7c73b761bce8a15e08661863d3ae1Michael Graff
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater return (result);
e883738546c7c73b761bce8a15e08661863d3ae1Michael Graff}
e883738546c7c73b761bce8a15e08661863d3ae1Michael Graff
5f1f24822fabe7b78af5f81553bfc11a170326c3Mark Andrews/*
f58cfa95f77ae2c26847b41c731dc17366e273b2Andreas Gustafsson * XXXMLG Needs to take a find argument and an address info, no zone or adb,
f58cfa95f77ae2c26847b41c731dc17366e273b2Andreas Gustafsson * since these can be extracted from the find itself.
14b98cb34eda66c87ce41a207704a2c232280eafMichael Graff */
f36a81c88493985ee2d1c53cc6fe88f4b00dbbc8Michael Graffisc_result_t
bcf369e513a1cc2209e2a987f5772afa79813540Mark Andrewsdns_adb_marklame(dns_adb_t *adb, dns_adbaddrinfo_t *addr, dns_name_t *qname,
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater dns_rdatatype_t qtype, isc_stdtime_t expire_time)
f36a81c88493985ee2d1c53cc6fe88f4b00dbbc8Michael Graff{
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater dns_adblameinfo_t *li;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater int bucket;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater isc_result_t result = ISC_R_SUCCESS;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater REQUIRE(DNS_ADB_VALID(adb));
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater REQUIRE(DNS_ADBADDRINFO_VALID(addr));
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater REQUIRE(qname != NULL);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater bucket = addr->entry->lock_bucket;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater LOCK(&adb->entrylocks[bucket]);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater li = ISC_LIST_HEAD(addr->entry->lameinfo);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater while (li != NULL &&
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater (li->qtype != qtype || !dns_name_equal(qname, &li->qname)))
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater li = ISC_LIST_NEXT(li, plink);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (li != NULL) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (expire_time > li->lame_timer)
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater li->lame_timer = expire_time;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater goto unlock;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater }
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater li = new_adblameinfo(adb, qname, qtype);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (li == NULL) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater result = ISC_R_NOMEMORY;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater goto unlock;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater }
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater li->lame_timer = expire_time;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater ISC_LIST_PREPEND(addr->entry->lameinfo, li, plink);
fd447061627e77db3ccf2536e14134e50647b9beMark Andrews unlock:
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater UNLOCK(&adb->entrylocks[bucket]);
f00d96a15cdd11e764437f9359e67328631caaeaMichael Graff
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater return (result);
f36a81c88493985ee2d1c53cc6fe88f4b00dbbc8Michael Graff}
ca924f706b53b895a662de8345d88437b23b8f01Michael Graff
beb2b4f19624af46230a8e3df97e54d6c596573eMichael Graffvoid
beb2b4f19624af46230a8e3df97e54d6c596573eMichael Graffdns_adb_adjustsrtt(dns_adb_t *adb, dns_adbaddrinfo_t *addr,
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater unsigned int rtt, unsigned int factor)
beb2b4f19624af46230a8e3df97e54d6c596573eMichael Graff{
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater int bucket;
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews isc_uint64_t new_srtt;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater isc_stdtime_t now;
beb2b4f19624af46230a8e3df97e54d6c596573eMichael Graff
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater REQUIRE(DNS_ADB_VALID(adb));
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater REQUIRE(DNS_ADBADDRINFO_VALID(addr));
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater REQUIRE(factor <= 10);
beb2b4f19624af46230a8e3df97e54d6c596573eMichael Graff
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater bucket = addr->entry->lock_bucket;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater LOCK(&adb->entrylocks[bucket]);
beb2b4f19624af46230a8e3df97e54d6c596573eMichael Graff
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews if (factor == DNS_ADB_RTTADJAGE) {
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews new_srtt = addr->entry->srtt;
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews new_srtt <<= 9;
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews new_srtt -= addr->entry->srtt;
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews new_srtt >>= 9;
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews } else
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater new_srtt = (addr->entry->srtt / 10 * factor)
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater + (rtt / 10 * (10 - factor));
42fe494186d386ddda15eb9403038c3558bbd5bfMichael Graff
166c4c6c5bafd25283b797979f77d780856fef30Evan Hunt addr->entry->srtt = (unsigned int) new_srtt;
166c4c6c5bafd25283b797979f77d780856fef30Evan Hunt addr->srtt = (unsigned int) new_srtt;
beb2b4f19624af46230a8e3df97e54d6c596573eMichael Graff
ee2f98d5cf12c86e7590efcdf6725ab133a430f3Mark Andrews if (addr->entry->expires == 0) {
ee2f98d5cf12c86e7590efcdf6725ab133a430f3Mark Andrews isc_stdtime_get(&now);
ee2f98d5cf12c86e7590efcdf6725ab133a430f3Mark Andrews addr->entry->expires = now + ADB_ENTRY_WINDOW;
ee2f98d5cf12c86e7590efcdf6725ab133a430f3Mark Andrews }
4bb16c5856e5c6b05ac43c60f9f9376641bdcccfMark Andrews
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater UNLOCK(&adb->entrylocks[bucket]);
beb2b4f19624af46230a8e3df97e54d6c596573eMichael Graff}
4f6dd51441290a9feacbe62991a2cdfdc7554e8bMichael Graff
4f6dd51441290a9feacbe62991a2cdfdc7554e8bMichael Graffvoid
4f6dd51441290a9feacbe62991a2cdfdc7554e8bMichael Graffdns_adb_changeflags(dns_adb_t *adb, dns_adbaddrinfo_t *addr,
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater unsigned int bits, unsigned int mask)
4f6dd51441290a9feacbe62991a2cdfdc7554e8bMichael Graff{
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater int bucket;
ee2f98d5cf12c86e7590efcdf6725ab133a430f3Mark Andrews isc_stdtime_t now;
4f6dd51441290a9feacbe62991a2cdfdc7554e8bMichael Graff
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater REQUIRE(DNS_ADB_VALID(adb));
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater REQUIRE(DNS_ADBADDRINFO_VALID(addr));
4f6dd51441290a9feacbe62991a2cdfdc7554e8bMichael Graff
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater bucket = addr->entry->lock_bucket;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater LOCK(&adb->entrylocks[bucket]);
4f6dd51441290a9feacbe62991a2cdfdc7554e8bMichael Graff
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater addr->entry->flags = (addr->entry->flags & ~mask) | (bits & mask);
ee2f98d5cf12c86e7590efcdf6725ab133a430f3Mark Andrews if (addr->entry->expires == 0) {
ee2f98d5cf12c86e7590efcdf6725ab133a430f3Mark Andrews isc_stdtime_get(&now);
ee2f98d5cf12c86e7590efcdf6725ab133a430f3Mark Andrews addr->entry->expires = now + ADB_ENTRY_WINDOW;
ee2f98d5cf12c86e7590efcdf6725ab133a430f3Mark Andrews }
ee2f98d5cf12c86e7590efcdf6725ab133a430f3Mark Andrews
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater /*
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * Note that we do not update the other bits in addr->flags with
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * the most recent values from addr->entry->flags.
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater */
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater addr->flags = (addr->flags & ~mask) | (bits & mask);
4f6dd51441290a9feacbe62991a2cdfdc7554e8bMichael Graff
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater UNLOCK(&adb->entrylocks[bucket]);
4f6dd51441290a9feacbe62991a2cdfdc7554e8bMichael Graff}
a44c12b332b867f29631e235eb11d1263c73d6c0Bob Halley
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews#define EDNSTOS 3U
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrewsisc_boolean_t
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrewsdns_adb_noedns(dns_adb_t *adb, dns_adbaddrinfo_t *addr) {
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews int bucket;
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews isc_boolean_t noedns = ISC_FALSE;
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews REQUIRE(DNS_ADB_VALID(adb));
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews REQUIRE(DNS_ADBADDRINFO_VALID(addr));
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews bucket = addr->entry->lock_bucket;
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews LOCK(&adb->entrylocks[bucket]);
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews if (addr->entry->edns == 0U &&
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews (addr->entry->plain > EDNSTOS || addr->entry->to4096 > EDNSTOS)) {
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews if (((addr->entry->plain + addr->entry->to4096) & 0x3f) != 0) {
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews noedns = ISC_TRUE;
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews } else {
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews /*
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews * Increment plain so we don't get stuck.
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews */
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews addr->entry->plain++;
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews if (addr->entry->plain == 0xff) {
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews addr->entry->edns >>= 1;
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews addr->entry->to4096 >>= 1;
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews addr->entry->to1432 >>= 1;
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews addr->entry->to1232 >>= 1;
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews addr->entry->to512 >>= 1;
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews addr->entry->plain >>= 1;
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews addr->entry->plainto >>= 1;
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews }
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews }
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews }
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews UNLOCK(&adb->entrylocks[bucket]);
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews return (noedns);
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews}
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrewsvoid
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrewsdns_adb_plainresponse(dns_adb_t *adb, dns_adbaddrinfo_t *addr) {
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews int bucket;
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews REQUIRE(DNS_ADB_VALID(adb));
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews REQUIRE(DNS_ADBADDRINFO_VALID(addr));
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews bucket = addr->entry->lock_bucket;
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews LOCK(&adb->entrylocks[bucket]);
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews addr->entry->plain++;
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews if (addr->entry->plain == 0xff) {
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews addr->entry->edns >>= 1;
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews addr->entry->to4096 >>= 1;
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews addr->entry->to1432 >>= 1;
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews addr->entry->to1232 >>= 1;
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews addr->entry->to512 >>= 1;
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews addr->entry->plain >>= 1;
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews addr->entry->plainto >>= 1;
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews }
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews UNLOCK(&adb->entrylocks[bucket]);
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews}
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrewsvoid
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrewsdns_adb_timeout(dns_adb_t *adb, dns_adbaddrinfo_t *addr) {
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews int bucket;
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews REQUIRE(DNS_ADB_VALID(adb));
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews REQUIRE(DNS_ADBADDRINFO_VALID(addr));
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews bucket = addr->entry->lock_bucket;
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews LOCK(&adb->entrylocks[bucket]);
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews /*
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews * If we have not had a successful query then clear all
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews * edns timeout information.
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews */
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews if (addr->entry->edns == 0 && addr->entry->plain == 0) {
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews addr->entry->to512 = 0;
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews addr->entry->to1232 = 0;
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews addr->entry->to1432 = 0;
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews addr->entry->to4096 = 0;
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews } else {
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews addr->entry->to512 >>= 1;
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews addr->entry->to1232 >>= 1;
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews addr->entry->to1432 >>= 1;
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews addr->entry->to4096 >>= 1;
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews }
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews addr->entry->plainto++;
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews if (addr->entry->plainto == 0xff) {
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews addr->entry->edns >>= 1;
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews addr->entry->plain >>= 1;
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews addr->entry->plainto >>= 1;
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews }
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews UNLOCK(&adb->entrylocks[bucket]);
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews}
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrewsvoid
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrewsdns_adb_ednsto(dns_adb_t *adb, dns_adbaddrinfo_t *addr, unsigned int size) {
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews int bucket;
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews REQUIRE(DNS_ADB_VALID(adb));
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews REQUIRE(DNS_ADBADDRINFO_VALID(addr));
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews bucket = addr->entry->lock_bucket;
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews LOCK(&adb->entrylocks[bucket]);
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews if (size <= 512U) {
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews if (addr->entry->to512 <= EDNSTOS) {
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews addr->entry->to512++;
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews addr->entry->to1232++;
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews addr->entry->to1432++;
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews addr->entry->to4096++;
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews }
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews } else if (size <= 1232U) {
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews if (addr->entry->to1232 <= EDNSTOS) {
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews addr->entry->to1232++;
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews addr->entry->to1432++;
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews addr->entry->to4096++;
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews }
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews } else if (size <= 1432U) {
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews if (addr->entry->to1432 <= EDNSTOS) {
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews addr->entry->to1432++;
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews addr->entry->to4096++;
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews }
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews } else {
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews if (addr->entry->to4096 <= EDNSTOS)
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews addr->entry->to4096++;
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews }
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews if (addr->entry->to4096 == 0xff) {
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews addr->entry->edns >>= 1;
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews addr->entry->to4096 >>= 1;
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews addr->entry->to1432 >>= 1;
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews addr->entry->to1232 >>= 1;
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews addr->entry->to512 >>= 1;
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews addr->entry->plain >>= 1;
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews addr->entry->plainto >>= 1;
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews }
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews UNLOCK(&adb->entrylocks[bucket]);
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews}
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrewsvoid
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrewsdns_adb_setudpsize(dns_adb_t *adb, dns_adbaddrinfo_t *addr, unsigned int size) {
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews int bucket;
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews REQUIRE(DNS_ADB_VALID(adb));
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews REQUIRE(DNS_ADBADDRINFO_VALID(addr));
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews bucket = addr->entry->lock_bucket;
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews LOCK(&adb->entrylocks[bucket]);
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews if (size < 512U)
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews size = 512U;
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews if (size > addr->entry->udpsize)
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews addr->entry->udpsize = size;
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews addr->entry->edns++;
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews if (addr->entry->edns == 0xff) {
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews addr->entry->edns >>= 1;
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews addr->entry->to4096 >>= 1;
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews addr->entry->to1432 >>= 1;
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews addr->entry->to1232 >>= 1;
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews addr->entry->to512 >>= 1;
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews addr->entry->plain >>= 1;
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews addr->entry->plainto >>= 1;
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews }
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews UNLOCK(&adb->entrylocks[bucket]);
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews}
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrewsunsigned int
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrewsdns_adb_getudpsize(dns_adb_t *adb, dns_adbaddrinfo_t *addr) {
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews int bucket;
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews unsigned int size;
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews REQUIRE(DNS_ADB_VALID(adb));
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews REQUIRE(DNS_ADBADDRINFO_VALID(addr));
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews bucket = addr->entry->lock_bucket;
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews LOCK(&adb->entrylocks[bucket]);
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews size = addr->entry->udpsize;
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews UNLOCK(&adb->entrylocks[bucket]);
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews return (size);
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews}
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrewsunsigned int
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrewsdns_adb_probesize(dns_adb_t *adb, dns_adbaddrinfo_t *addr) {
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews int bucket;
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews unsigned int size;
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews REQUIRE(DNS_ADB_VALID(adb));
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews REQUIRE(DNS_ADBADDRINFO_VALID(addr));
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews bucket = addr->entry->lock_bucket;
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews LOCK(&adb->entrylocks[bucket]);
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews if (addr->entry->to1232 > EDNSTOS)
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews size = 512;
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews else if (addr->entry->to1432 > EDNSTOS)
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews size = 1232;
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews else if (addr->entry->to4096 > EDNSTOS)
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews size = 1432;
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews else
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews size = 4096;
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews UNLOCK(&adb->entrylocks[bucket]);
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews return (size);
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews}
8e15d5eb3a000f1341e6bea0ddbc28d6dd2a0591Mark Andrews
a44c12b332b867f29631e235eb11d1263c73d6c0Bob Halleyisc_result_t
a44c12b332b867f29631e235eb11d1263c73d6c0Bob Halleydns_adb_findaddrinfo(dns_adb_t *adb, isc_sockaddr_t *sa,
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater dns_adbaddrinfo_t **addrp, isc_stdtime_t now)
a44c12b332b867f29631e235eb11d1263c73d6c0Bob Halley{
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater int bucket;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater dns_adbentry_t *entry;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater dns_adbaddrinfo_t *addr;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater isc_result_t result;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater in_port_t port;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater REQUIRE(DNS_ADB_VALID(adb));
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater REQUIRE(addrp != NULL && *addrp == NULL);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater UNUSED(now);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater result = ISC_R_SUCCESS;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater bucket = DNS_ADB_INVALIDBUCKET;
c82bb6a709abe89c051485b49403ef5bad1b756cTatuya JINMEI 神明達哉 entry = find_entry_and_lock(adb, sa, &bucket, now);
17c98e7adddf82b73f478e89213fd10148a53100Mark Andrews INSIST(bucket != DNS_ADB_INVALIDBUCKET);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (adb->entry_sd[bucket]) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater result = ISC_R_SHUTTINGDOWN;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater goto unlock;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater }
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (entry == NULL) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater /*
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * We don't know anything about this address.
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater */
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater entry = new_adbentry(adb);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (entry == NULL) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater result = ISC_R_NOMEMORY;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater goto unlock;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater }
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater entry->sockaddr = *sa;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater link_entry(adb, bucket, entry);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater DP(ENTER_LEVEL, "findaddrinfo: new entry %p", entry);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater } else
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater DP(ENTER_LEVEL, "findaddrinfo: found entry %p", entry);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater port = isc_sockaddr_getport(sa);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater addr = new_adbaddrinfo(adb, entry, port);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (addr == NULL) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater result = ISC_R_NOMEMORY;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater } else {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater inc_entry_refcnt(adb, entry, ISC_FALSE);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater *addrp = addr;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater }
a44c12b332b867f29631e235eb11d1263c73d6c0Bob Halley
a44c12b332b867f29631e235eb11d1263c73d6c0Bob Halley unlock:
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater UNLOCK(&adb->entrylocks[bucket]);
a44c12b332b867f29631e235eb11d1263c73d6c0Bob Halley
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater return (result);
a44c12b332b867f29631e235eb11d1263c73d6c0Bob Halley}
a44c12b332b867f29631e235eb11d1263c73d6c0Bob Halley
a44c12b332b867f29631e235eb11d1263c73d6c0Bob Halleyvoid
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrencedns_adb_freeaddrinfo(dns_adb_t *adb, dns_adbaddrinfo_t **addrp) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater dns_adbaddrinfo_t *addr;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater dns_adbentry_t *entry;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater int bucket;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater isc_stdtime_t now;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater isc_boolean_t want_check_exit = ISC_FALSE;
27fe1966c948ba0c1c9d0d831ea3d8bf32d052acTatuya JINMEI 神明達哉 isc_boolean_t overmem;
a44c12b332b867f29631e235eb11d1263c73d6c0Bob Halley
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater REQUIRE(DNS_ADB_VALID(adb));
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater REQUIRE(addrp != NULL);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater addr = *addrp;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater REQUIRE(DNS_ADBADDRINFO_VALID(addr));
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater entry = addr->entry;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater REQUIRE(DNS_ADBENTRY_VALID(entry));
a44c12b332b867f29631e235eb11d1263c73d6c0Bob Halley
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater *addrp = NULL;
27fe1966c948ba0c1c9d0d831ea3d8bf32d052acTatuya JINMEI 神明達哉 overmem = isc_mem_isovermem(adb->mctx);
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater bucket = addr->entry->lock_bucket;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater LOCK(&adb->entrylocks[bucket]);
a44c12b332b867f29631e235eb11d1263c73d6c0Bob Halley
ee2f98d5cf12c86e7590efcdf6725ab133a430f3Mark Andrews if (entry->expires == 0) {
ee2f98d5cf12c86e7590efcdf6725ab133a430f3Mark Andrews isc_stdtime_get(&now);
ee2f98d5cf12c86e7590efcdf6725ab133a430f3Mark Andrews entry->expires = now + ADB_ENTRY_WINDOW;
ee2f98d5cf12c86e7590efcdf6725ab133a430f3Mark Andrews }
a44c12b332b867f29631e235eb11d1263c73d6c0Bob Halley
27fe1966c948ba0c1c9d0d831ea3d8bf32d052acTatuya JINMEI 神明達哉 want_check_exit = dec_entry_refcnt(adb, overmem, entry, ISC_FALSE);
a44c12b332b867f29631e235eb11d1263c73d6c0Bob Halley
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater UNLOCK(&adb->entrylocks[bucket]);
a44c12b332b867f29631e235eb11d1263c73d6c0Bob Halley
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater addr->entry = NULL;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater free_adbaddrinfo(adb, &addr);
45dadd25ba4b72ec2d8eecc342edc787d8421e3aBob Halley
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (want_check_exit) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater LOCK(&adb->lock);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater check_exit(adb);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater UNLOCK(&adb->lock);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater }
a44c12b332b867f29631e235eb11d1263c73d6c0Bob Halley}
c20ffa38dee7efa0dc01822d4bac5e41729b9b61Brian Wellington
c20ffa38dee7efa0dc01822d4bac5e41729b9b61Brian Wellingtonvoid
c20ffa38dee7efa0dc01822d4bac5e41729b9b61Brian Wellingtondns_adb_flush(dns_adb_t *adb) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater unsigned int i;
c20ffa38dee7efa0dc01822d4bac5e41729b9b61Brian Wellington
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater INSIST(DNS_ADB_VALID(adb));
c20ffa38dee7efa0dc01822d4bac5e41729b9b61Brian Wellington
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater LOCK(&adb->lock);
c20ffa38dee7efa0dc01822d4bac5e41729b9b61Brian Wellington
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater /*
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * Call our cleanup routines.
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater */
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews for (i = 0; i < adb->nnames; i++)
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater RUNTIME_CHECK(cleanup_names(adb, i, INT_MAX) == ISC_FALSE);
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews for (i = 0; i < adb->nentries; i++)
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater RUNTIME_CHECK(cleanup_entries(adb, i, INT_MAX) == ISC_FALSE);
c20ffa38dee7efa0dc01822d4bac5e41729b9b61Brian Wellington
c20ffa38dee7efa0dc01822d4bac5e41729b9b61Brian Wellington#ifdef DUMP_ADB_AFTER_CLEANING
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater dump_adb(adb, stdout, ISC_TRUE, INT_MAX);
c20ffa38dee7efa0dc01822d4bac5e41729b9b61Brian Wellington#endif
c20ffa38dee7efa0dc01822d4bac5e41729b9b61Brian Wellington
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater UNLOCK(&adb->lock);
c20ffa38dee7efa0dc01822d4bac5e41729b9b61Brian Wellington}
081cff0c33514a5dc63ab794fc199c07377ab756Mark Andrews
1e4bfff1855795853648f507422b96fc8fecbff1Mark Andrewsvoid
1e4bfff1855795853648f507422b96fc8fecbff1Mark Andrewsdns_adb_flushname(dns_adb_t *adb, dns_name_t *name) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater dns_adbname_t *adbname;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater dns_adbname_t *nextname;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater int bucket;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
9fa5a723e188ddb5e6165af4957ba789e17cfdf5Evan Hunt REQUIRE(DNS_ADB_VALID(adb));
9fa5a723e188ddb5e6165af4957ba789e17cfdf5Evan Hunt REQUIRE(name != NULL);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater LOCK(&adb->lock);
82f77687abd21349fa7c7f51e71fdc0c7367d2e2Mark Andrews bucket = dns_name_hash(name, ISC_FALSE) % adb->nnames;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater LOCK(&adb->namelocks[bucket]);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater adbname = ISC_LIST_HEAD(adb->names[bucket]);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater while (adbname != NULL) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater nextname = ISC_LIST_NEXT(adbname, plink);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (!NAME_DEAD(adbname) &&
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater dns_name_equal(name, &adbname->name)) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater RUNTIME_CHECK(kill_name(&adbname,
c82bb6a709abe89c051485b49403ef5bad1b756cTatuya JINMEI 神明達哉 DNS_EVENT_ADBCANCELED) ==
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater ISC_FALSE);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater }
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater adbname = nextname;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater }
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater UNLOCK(&adb->namelocks[bucket]);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater UNLOCK(&adb->lock);
1e4bfff1855795853648f507422b96fc8fecbff1Mark Andrews}
1e4bfff1855795853648f507422b96fc8fecbff1Mark Andrews
9fa5a723e188ddb5e6165af4957ba789e17cfdf5Evan Huntvoid
9fa5a723e188ddb5e6165af4957ba789e17cfdf5Evan Huntdns_adb_flushnames(dns_adb_t *adb, dns_name_t *name) {
9fa5a723e188ddb5e6165af4957ba789e17cfdf5Evan Hunt dns_adbname_t *adbname, *nextname;
9fa5a723e188ddb5e6165af4957ba789e17cfdf5Evan Hunt unsigned int i;
9fa5a723e188ddb5e6165af4957ba789e17cfdf5Evan Hunt
9fa5a723e188ddb5e6165af4957ba789e17cfdf5Evan Hunt REQUIRE(DNS_ADB_VALID(adb));
9fa5a723e188ddb5e6165af4957ba789e17cfdf5Evan Hunt REQUIRE(name != NULL);
9fa5a723e188ddb5e6165af4957ba789e17cfdf5Evan Hunt
9fa5a723e188ddb5e6165af4957ba789e17cfdf5Evan Hunt LOCK(&adb->lock);
9fa5a723e188ddb5e6165af4957ba789e17cfdf5Evan Hunt for (i = 0; i < adb->nnames; i++) {
9fa5a723e188ddb5e6165af4957ba789e17cfdf5Evan Hunt LOCK(&adb->namelocks[i]);
9fa5a723e188ddb5e6165af4957ba789e17cfdf5Evan Hunt adbname = ISC_LIST_HEAD(adb->names[i]);
9fa5a723e188ddb5e6165af4957ba789e17cfdf5Evan Hunt while (adbname != NULL) {
9fa5a723e188ddb5e6165af4957ba789e17cfdf5Evan Hunt isc_boolean_t ret;
9fa5a723e188ddb5e6165af4957ba789e17cfdf5Evan Hunt nextname = ISC_LIST_NEXT(adbname, plink);
9fa5a723e188ddb5e6165af4957ba789e17cfdf5Evan Hunt if (!NAME_DEAD(adbname) &&
9fa5a723e188ddb5e6165af4957ba789e17cfdf5Evan Hunt dns_name_issubdomain(&adbname->name, name))
9fa5a723e188ddb5e6165af4957ba789e17cfdf5Evan Hunt {
9fa5a723e188ddb5e6165af4957ba789e17cfdf5Evan Hunt ret = kill_name(&adbname,
9fa5a723e188ddb5e6165af4957ba789e17cfdf5Evan Hunt DNS_EVENT_ADBCANCELED);
9fa5a723e188ddb5e6165af4957ba789e17cfdf5Evan Hunt RUNTIME_CHECK(ret == ISC_FALSE);
9fa5a723e188ddb5e6165af4957ba789e17cfdf5Evan Hunt }
9fa5a723e188ddb5e6165af4957ba789e17cfdf5Evan Hunt adbname = nextname;
9fa5a723e188ddb5e6165af4957ba789e17cfdf5Evan Hunt }
9fa5a723e188ddb5e6165af4957ba789e17cfdf5Evan Hunt UNLOCK(&adb->namelocks[i]);
9fa5a723e188ddb5e6165af4957ba789e17cfdf5Evan Hunt }
9fa5a723e188ddb5e6165af4957ba789e17cfdf5Evan Hunt UNLOCK(&adb->lock);
9fa5a723e188ddb5e6165af4957ba789e17cfdf5Evan Hunt}
9fa5a723e188ddb5e6165af4957ba789e17cfdf5Evan Hunt
081cff0c33514a5dc63ab794fc199c07377ab756Mark Andrewsstatic void
081cff0c33514a5dc63ab794fc199c07377ab756Mark Andrewswater(void *arg, int mark) {
27fe1966c948ba0c1c9d0d831ea3d8bf32d052acTatuya JINMEI 神明達哉 /*
27fe1966c948ba0c1c9d0d831ea3d8bf32d052acTatuya JINMEI 神明達哉 * We're going to change the way to handle overmem condition: use
27fe1966c948ba0c1c9d0d831ea3d8bf32d052acTatuya JINMEI 神明達哉 * isc_mem_isovermem() instead of storing the state via this callback,
27fe1966c948ba0c1c9d0d831ea3d8bf32d052acTatuya JINMEI 神明達哉 * since the latter way tends to cause race conditions.
27fe1966c948ba0c1c9d0d831ea3d8bf32d052acTatuya JINMEI 神明達哉 * To minimize the change, and in case we re-enable the callback
27fe1966c948ba0c1c9d0d831ea3d8bf32d052acTatuya JINMEI 神明達哉 * approach, however, keep this function at the moment.
27fe1966c948ba0c1c9d0d831ea3d8bf32d052acTatuya JINMEI 神明達哉 */
27fe1966c948ba0c1c9d0d831ea3d8bf32d052acTatuya JINMEI 神明達哉
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater dns_adb_t *adb = arg;
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater isc_boolean_t overmem = ISC_TF(mark == ISC_MEM_HIWATER);
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater REQUIRE(DNS_ADB_VALID(adb));
5f1f24822fabe7b78af5f81553bfc11a170326c3Mark Andrews
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater DP(ISC_LOG_DEBUG(1),
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater "adb reached %s water mark", overmem ? "high" : "low");
081cff0c33514a5dc63ab794fc199c07377ab756Mark Andrews}
081cff0c33514a5dc63ab794fc199c07377ab756Mark Andrews
081cff0c33514a5dc63ab794fc199c07377ab756Mark Andrewsvoid
2a184ff86544cc67c36e2ce6bb3ddb5ac44684b8Evan Huntdns_adb_setadbsize(dns_adb_t *adb, size_t size) {
2a184ff86544cc67c36e2ce6bb3ddb5ac44684b8Evan Hunt size_t hiwater, lowater;
081cff0c33514a5dc63ab794fc199c07377ab756Mark Andrews
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater INSIST(DNS_ADB_VALID(adb));
081cff0c33514a5dc63ab794fc199c07377ab756Mark Andrews
f3350b671881f175d03e16fa5d0f685a1691bcabMark Andrews if (size != 0U && size < DNS_ADB_MINADBSIZE)
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater size = DNS_ADB_MINADBSIZE;
081cff0c33514a5dc63ab794fc199c07377ab756Mark Andrews
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater hiwater = size - (size >> 3); /* Approximately 7/8ths. */
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater lowater = size - (size >> 2); /* Approximately 3/4ths. */
081cff0c33514a5dc63ab794fc199c07377ab756Mark Andrews
f3350b671881f175d03e16fa5d0f685a1691bcabMark Andrews if (size == 0U || hiwater == 0U || lowater == 0U)
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater isc_mem_setwater(adb->mctx, water, adb, 0, 0);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater else
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater isc_mem_setwater(adb->mctx, water, adb, hiwater, lowater);
081cff0c33514a5dc63ab794fc199c07377ab756Mark Andrews}