Lines Matching refs:adb

31 #include <dns/adb.h>
92 /*% dns adb structure */
173 dns_adb_t *adb;
308 dns_adb_t *adb,
388 * Note: since we have removed the support of A6 in adb, FETCH_A and FETCH_AAAA
500 inc_stats(dns_adb_t *adb, isc_statscounter_t counter) {
501 if (adb->view->resstats != NULL)
502 isc_stats_increment(adb->view->resstats, counter);
506 * Set adb-related statistics counters.
509 set_adbstat(dns_adb_t *adb, isc_uint64_t val, isc_statscounter_t counter) {
510 if (adb->view->adbstats != NULL)
511 isc_stats_set(adb->view->adbstats, val, counter);
515 dec_adbstats(dns_adb_t *adb, isc_statscounter_t counter) {
516 if (adb->view->adbstats != NULL)
517 isc_stats_decrement(adb->view->adbstats, counter);
521 inc_adbstats(dns_adb_t *adb, isc_statscounter_t counter) {
522 if (adb->view->adbstats != NULL)
523 isc_stats_increment(adb->view->adbstats, counter);
554 dns_adb_t *adb;
564 adb = ev->ev_arg;
565 INSIST(DNS_ADB_VALID(adb));
574 while (nbuckets[i] != 0 && adb->nentries >= nbuckets[i])
581 DP(ISC_LOG_INFO, "adb: grow_entries to %u starting", n);
586 for (i = 0; i < adb->nentries; i++)
587 if (adb->entry_sd[i])
593 newentries = isc_mem_get(adb->mctx, sizeof(*newentries) * n);
594 newdeadentries = isc_mem_get(adb->mctx, sizeof(*newdeadentries) * n);
595 newentrylocks = isc_mem_get(adb->mctx, sizeof(*newentrylocks) * n);
596 newentry_sd = isc_mem_get(adb->mctx, sizeof(*newentry_sd) * n);
597 newentry_refcnt = isc_mem_get(adb->mctx, sizeof(*newentry_refcnt) * n);
615 adb->irefcnt++;
621 for (i = 0; i < adb->nentries; i++) {
622 e = ISC_LIST_HEAD(adb->entries[i]);
624 ISC_LIST_UNLINK(adb->entries[i], e, plink);
628 INSIST(adb->entry_refcnt[i] > 0);
629 adb->entry_refcnt[i]--;
631 e = ISC_LIST_HEAD(adb->entries[i]);
633 e = ISC_LIST_HEAD(adb->deadentries[i]);
635 ISC_LIST_UNLINK(adb->deadentries[i], e, plink);
639 INSIST(adb->entry_refcnt[i] > 0);
640 adb->entry_refcnt[i]--;
642 e = ISC_LIST_HEAD(adb->deadentries[i]);
644 INSIST(adb->entry_refcnt[i] == 0);
645 adb->irefcnt--;
651 DESTROYMUTEXBLOCK(adb->entrylocks, adb->nentries);
652 isc_mem_put(adb->mctx, adb->entries,
653 sizeof(*adb->entries) * adb->nentries);
654 isc_mem_put(adb->mctx, adb->deadentries,
655 sizeof(*adb->deadentries) * adb->nentries);
656 isc_mem_put(adb->mctx, adb->entrylocks,
657 sizeof(*adb->entrylocks) * adb->nentries);
658 isc_mem_put(adb->mctx, adb->entry_sd,
659 sizeof(*adb->entry_sd) * adb->nentries);
660 isc_mem_put(adb->mctx, adb->entry_refcnt,
661 sizeof(*adb->entry_refcnt) * adb->nentries);
666 adb->entries = newentries;
667 adb->deadentries = newdeadentries;
668 adb->entrylocks = newentrylocks;
669 adb->entry_sd = newentry_sd;
670 adb->entry_refcnt = newentry_refcnt;
671 adb->nentries = n;
673 set_adbstat(adb, adb->nentries, dns_adbstats_nentries);
676 * Only on success do we set adb->growentries_sent to ISC_FALSE.
679 adb->growentries_sent = ISC_FALSE;
684 isc_mem_put(adb->mctx, newentries,
687 isc_mem_put(adb->mctx, newdeadentries,
690 isc_mem_put(adb->mctx, newentrylocks,
693 isc_mem_put(adb->mctx, newentry_sd,
696 isc_mem_put(adb->mctx, newentry_refcnt,
702 LOCK(&adb->lock);
703 if (dec_adb_irefcnt(adb))
704 check_exit(adb);
705 UNLOCK(&adb->lock);
706 DP(ISC_LOG_INFO, "adb: grow_entries finished");
711 dns_adb_t *adb;
721 adb = ev->ev_arg;
722 INSIST(DNS_ADB_VALID(adb));
731 while (nbuckets[i] != 0 && adb->nnames >= nbuckets[i])
738 DP(ISC_LOG_INFO, "adb: grow_names to %u starting", n);
743 for (i = 0; i < adb->nnames; i++)
744 if (adb->name_sd[i])
750 newnames = isc_mem_get(adb->mctx, sizeof(*newnames) * n);
751 newdeadnames = isc_mem_get(adb->mctx, sizeof(*newdeadnames) * n);
752 newnamelocks = isc_mem_get(adb->mctx, sizeof(*newnamelocks) * n);
753 newname_sd = isc_mem_get(adb->mctx, sizeof(*newname_sd) * n);
754 newname_refcnt = isc_mem_get(adb->mctx, sizeof(*newname_refcnt) * n);
772 adb->irefcnt++;
778 for (i = 0; i < adb->nnames; i++) {
779 name = ISC_LIST_HEAD(adb->names[i]);
781 ISC_LIST_UNLINK(adb->names[i], name, plink);
785 INSIST(adb->name_refcnt[i] > 0);
786 adb->name_refcnt[i]--;
788 name = ISC_LIST_HEAD(adb->names[i]);
790 name = ISC_LIST_HEAD(adb->deadnames[i]);
792 ISC_LIST_UNLINK(adb->deadnames[i], name, plink);
796 INSIST(adb->name_refcnt[i] > 0);
797 adb->name_refcnt[i]--;
799 name = ISC_LIST_HEAD(adb->deadnames[i]);
801 INSIST(adb->name_refcnt[i] == 0);
802 adb->irefcnt--;
808 DESTROYMUTEXBLOCK(adb->namelocks, adb->nnames);
809 isc_mem_put(adb->mctx, adb->names,
810 sizeof(*adb->names) * adb->nnames);
811 isc_mem_put(adb->mctx, adb->deadnames,
812 sizeof(*adb->deadnames) * adb->nnames);
813 isc_mem_put(adb->mctx, adb->namelocks,
814 sizeof(*adb->namelocks) * adb->nnames);
815 isc_mem_put(adb->mctx, adb->name_sd,
816 sizeof(*adb->name_sd) * adb->nnames);
817 isc_mem_put(adb->mctx, adb->name_refcnt,
818 sizeof(*adb->name_refcnt) * adb->nnames);
823 adb->names = newnames;
824 adb->deadnames = newdeadnames;
825 adb->namelocks = newnamelocks;
826 adb->name_sd = newname_sd;
827 adb->name_refcnt = newname_refcnt;
828 adb->nnames = n;
830 set_adbstat(adb, adb->nnames, dns_adbstats_nnames);
833 * Only on success do we set adb->grownames_sent to ISC_FALSE.
836 adb->grownames_sent = ISC_FALSE;
841 isc_mem_put(adb->mctx, newnames, sizeof(*newnames) * n);
843 isc_mem_put(adb->mctx, newdeadnames, sizeof(*newdeadnames) * n);
845 isc_mem_put(adb->mctx, newnamelocks, sizeof(*newnamelocks) * n);
847 isc_mem_put(adb->mctx, newname_sd, sizeof(*newname_sd) * n);
849 isc_mem_put(adb->mctx, newname_refcnt,
855 LOCK(&adb->lock);
856 if (dec_adb_irefcnt(adb))
857 check_exit(adb);
858 UNLOCK(&adb->lock);
859 DP(ISC_LOG_INFO, "adb: grow_names finished");
872 dns_adb_t *adb;
887 adb = adbname->adb;
888 INSIST(DNS_ADB_VALID(adb));
918 nh = new_adbnamehook(adb, NULL);
925 foundentry = find_entry_and_lock(adb, &sockaddr, &addr_bucket,
930 entry = new_adbentry(adb);
943 link_entry(adb, addr_bucket, entry);
955 free_adbnamehook(adb, &nh);
967 free_adbnamehook(adb, &nh);
970 UNLOCK(&adb->entrylocks[addr_bucket]);
1014 dns_adb_t *adb;
1020 adb = name->adb;
1021 INSIST(DNS_ADB_VALID(adb));
1030 result = unlink_name(adb, name);
1031 free_adbname(adb, &name);
1033 result = dec_adb_irefcnt(adb);
1042 result4 = clean_namehooks(adb, &name->v4);
1043 result6 = clean_namehooks(adb, &name->v6);
1044 clean_target(adb, &name->target);
1053 result = unlink_name(adb, name);
1054 free_adbname(adb, &name);
1056 result = dec_adb_irefcnt(adb);
1061 ISC_LIST_UNLINK(adb->names[bucket], name, plink);
1062 ISC_LIST_APPEND(adb->deadnames[bucket], name, plink);
1074 dns_adb_t *adb;
1079 adb = name->adb;
1080 INSIST(DNS_ADB_VALID(adb));
1088 result4 = clean_namehooks(adb, &name->v4);
1101 result6 = clean_namehooks(adb, &name->v6);
1112 clean_target(adb, &name->target);
1122 link_name(dns_adb_t *adb, int bucket, dns_adbname_t *name) {
1125 ISC_LIST_PREPEND(adb->names[bucket], name, plink);
1127 adb->name_refcnt[bucket]++;
1134 unlink_name(dns_adb_t *adb, dns_adbname_t *name) {
1142 ISC_LIST_UNLINK(adb->deadnames[bucket], name, plink);
1144 ISC_LIST_UNLINK(adb->names[bucket], name, plink);
1146 INSIST(adb->name_refcnt[bucket] > 0);
1147 adb->name_refcnt[bucket]--;
1148 if (adb->name_sd[bucket] && adb->name_refcnt[bucket] == 0)
1157 link_entry(dns_adb_t *adb, int bucket, dns_adbentry_t *entry) {
1161 if (isc_mem_isovermem(adb->mctx)) {
1163 e = ISC_LIST_TAIL(adb->entries[bucket]);
1167 unlink_entry(adb, e);
1168 free_adbentry(adb, &e);
1173 ISC_LIST_UNLINK(adb->entries[bucket], e, plink);
1174 ISC_LIST_PREPEND(adb->deadentries[bucket], e, plink);
1178 ISC_LIST_PREPEND(adb->entries[bucket], entry, plink);
1180 adb->entry_refcnt[bucket]++;
1187 unlink_entry(dns_adb_t *adb, dns_adbentry_t *entry) {
1195 ISC_LIST_UNLINK(adb->deadentries[bucket], entry, plink);
1197 ISC_LIST_UNLINK(adb->entries[bucket], entry, plink);
1199 INSIST(adb->entry_refcnt[bucket] > 0);
1200 adb->entry_refcnt[bucket]--;
1201 if (adb->entry_sd[bucket] && adb->entry_refcnt[bucket] == 0)
1220 shutdown_names(dns_adb_t *adb) {
1226 for (bucket = 0; bucket < adb->nnames; bucket++) {
1227 LOCK(&adb->namelocks[bucket]);
1228 adb->name_sd[bucket] = ISC_TRUE;
1230 name = ISC_LIST_HEAD(adb->names[bucket]);
1238 result = dec_adb_irefcnt(adb);
1255 UNLOCK(&adb->namelocks[bucket]);
1265 shutdown_entries(dns_adb_t *adb) {
1271 for (bucket = 0; bucket < adb->nentries; bucket++) {
1272 LOCK(&adb->entrylocks[bucket]);
1273 adb->entry_sd[bucket] = ISC_TRUE;
1275 entry = ISC_LIST_HEAD(adb->entries[bucket]);
1276 if (adb->entry_refcnt[bucket] == 0) {
1282 result = dec_adb_irefcnt(adb);
1292 result = unlink_entry(adb, entry);
1293 free_adbentry(adb, &entry);
1295 result = dec_adb_irefcnt(adb);
1301 UNLOCK(&adb->entrylocks[bucket]);
1322 clean_namehooks(dns_adb_t *adb, dns_adbnamehooklist_t *namehooks) {
1327 isc_boolean_t overmem = isc_mem_isovermem(adb->mctx);
1343 UNLOCK(&adb->entrylocks[addr_bucket]);
1346 LOCK(&adb->entrylocks[addr_bucket]);
1350 result = dec_entry_refcnt(adb, overmem, entry,
1359 free_adbnamehook(adb, &namehook);
1365 UNLOCK(&adb->entrylocks[addr_bucket]);
1370 clean_target(dns_adb_t *adb, dns_name_t *target) {
1372 dns_name_free(target, adb->mctx);
1378 set_target(dns_adb_t *adb, dns_name_t *name, dns_name_t *fname,
1404 result = dns_name_dup(&cname.cname, adb->mctx, target);
1437 result = dns_name_dup(new_target, adb->mctx, target);
1549 check_exit(dns_adb_t *adb) {
1552 * The caller must be holding the adb lock.
1554 if (adb->shutting_down) {
1559 INSIST(!adb->cevent_out); /* Sanity check. */
1560 ISC_EVENT_INIT(&adb->cevent, sizeof(adb->cevent), 0, NULL,
1561 DNS_EVENT_ADBCONTROL, shutdown_task, adb,
1562 adb, NULL, NULL);
1563 event = &adb->cevent;
1564 isc_task_send(adb->task, &event);
1565 adb->cevent_out = ISC_TRUE;
1570 dec_adb_irefcnt(dns_adb_t *adb) {
1575 LOCK(&adb->reflock);
1577 INSIST(adb->irefcnt > 0);
1578 adb->irefcnt--;
1580 if (adb->irefcnt == 0) {
1581 event = ISC_LIST_HEAD(adb->whenshutdown);
1583 ISC_LIST_UNLINK(adb->whenshutdown, event, ev_link);
1585 event->ev_sender = adb;
1587 event = ISC_LIST_HEAD(adb->whenshutdown);
1591 if (adb->irefcnt == 0 && adb->erefcnt == 0)
1593 UNLOCK(&adb->reflock);
1598 inc_adb_irefcnt(dns_adb_t *adb) {
1599 LOCK(&adb->reflock);
1600 adb->irefcnt++;
1601 UNLOCK(&adb->reflock);
1605 inc_adb_erefcnt(dns_adb_t *adb) {
1606 LOCK(&adb->reflock);
1607 adb->erefcnt++;
1608 UNLOCK(&adb->reflock);
1612 inc_entry_refcnt(dns_adb_t *adb, dns_adbentry_t *entry, isc_boolean_t lock) {
1618 LOCK(&adb->entrylocks[bucket]);
1623 UNLOCK(&adb->entrylocks[bucket]);
1627 dec_entry_refcnt(dns_adb_t *adb, isc_boolean_t overmem, dns_adbentry_t *entry,
1637 LOCK(&adb->entrylocks[bucket]);
1644 (adb->entry_sd[bucket] || entry->expires == 0 || overmem ||
1647 result = unlink_entry(adb, entry);
1651 UNLOCK(&adb->entrylocks[bucket]);
1658 free_adbentry(adb, &entry);
1660 result = dec_adb_irefcnt(adb);
1666 new_adbname(dns_adb_t *adb, dns_name_t *dnsname) {
1669 name = isc_mempool_get(adb->nmp);
1674 if (dns_name_dup(dnsname, adb->mctx, &name->name) != ISC_R_SUCCESS) {
1675 isc_mempool_put(adb->nmp, name);
1680 name->adb = adb;
1697 LOCK(&adb->namescntlock);
1698 adb->namescnt++;
1699 inc_adbstats(adb, dns_adbstats_namescnt);
1700 if (!adb->grownames_sent && adb->excl != NULL &&
1701 adb->namescnt > (adb->nnames * 8))
1703 isc_event_t *event = &adb->grownames;
1704 inc_adb_irefcnt(adb);
1705 isc_task_send(adb->excl, &event);
1706 adb->grownames_sent = ISC_TRUE;
1708 UNLOCK(&adb->namescntlock);
1714 free_adbname(dns_adb_t *adb, dns_adbname_t **name) {
1727 INSIST(n->adb == adb);
1730 dns_name_free(&n->name, adb->mctx);
1732 isc_mempool_put(adb->nmp, n);
1733 LOCK(&adb->namescntlock);
1734 adb->namescnt--;
1735 dec_adbstats(adb, dns_adbstats_namescnt);
1736 UNLOCK(&adb->namescntlock);
1740 new_adbnamehook(dns_adb_t *adb, dns_adbentry_t *entry) {
1743 nh = isc_mempool_get(adb->nhmp);
1755 free_adbnamehook(dns_adb_t *adb, dns_adbnamehook_t **namehook) {
1766 isc_mempool_put(adb->nhmp, nh);
1770 new_adblameinfo(dns_adb_t *adb, dns_name_t *qname, dns_rdatatype_t qtype) {
1773 li = isc_mempool_get(adb->limp);
1778 if (dns_name_dup(qname, adb->mctx, &li->qname) != ISC_R_SUCCESS) {
1779 isc_mempool_put(adb->limp, li);
1791 free_adblameinfo(dns_adb_t *adb, dns_adblameinfo_t **lameinfo) {
1800 dns_name_free(&li->qname, adb->mctx);
1804 isc_mempool_put(adb->limp, li);
1808 new_adbentry(dns_adb_t *adb) {
1812 e = isc_mempool_get(adb->emp);
1839 e->quota = adb->quota;
1843 LOCK(&adb->entriescntlock);
1844 adb->entriescnt++;
1845 inc_adbstats(adb, dns_adbstats_entriescnt);
1846 if (!adb->growentries_sent && adb->excl != NULL &&
1847 adb->entriescnt > (adb->nentries * 8))
1849 isc_event_t *event = &adb->growentries;
1850 inc_adb_irefcnt(adb);
1851 isc_task_send(adb->excl, &event);
1852 adb->growentries_sent = ISC_TRUE;
1854 UNLOCK(&adb->entriescntlock);
1860 free_adbentry(dns_adb_t *adb, dns_adbentry_t **entry) {
1875 isc_mem_put(adb->mctx, e->cookie, e->cookielen);
1880 free_adblameinfo(adb, &li);
1884 isc_mempool_put(adb->emp, e);
1885 LOCK(&adb->entriescntlock);
1886 adb->entriescnt--;
1887 dec_adbstats(adb, dns_adbstats_entriescnt);
1888 UNLOCK(&adb->entriescntlock);
1892 new_adbfind(dns_adb_t *adb) {
1896 h = isc_mempool_get(adb->ahmp);
1904 h->adb = adb;
1921 isc_mempool_put(adb->ahmp, h);
1928 inc_adb_irefcnt(adb);
1934 new_adbfetch(dns_adb_t *adb) {
1937 f = isc_mempool_get(adb->afmp);
1952 free_adbfetch(dns_adb_t *adb, dns_adbfetch_t **fetch) {
1964 isc_mempool_put(adb->afmp, f);
1968 free_adbfind(dns_adb_t *adb, dns_adbfind_t **findp) {
1984 isc_mempool_put(adb->ahmp, find);
1985 return (dec_adb_irefcnt(adb));
1994 new_adbaddrinfo(dns_adb_t *adb, dns_adbentry_t *entry, in_port_t port) {
1997 ai = isc_mempool_get(adb->aimp);
2014 free_adbaddrinfo(dns_adb_t *adb, dns_adbaddrinfo_t **ainfo) {
2026 isc_mempool_put(adb->aimp, ai);
2037 find_name_and_lock(dns_adb_t *adb, dns_name_t *name,
2043 bucket = dns_name_fullhash(name, ISC_FALSE) % adb->nnames;
2046 LOCK(&adb->namelocks[bucket]);
2049 UNLOCK(&adb->namelocks[*bucketp]);
2050 LOCK(&adb->namelocks[bucket]);
2054 adbname = ISC_LIST_HEAD(adb->names[bucket]);
2079 find_entry_and_lock(dns_adb_t *adb, isc_sockaddr_t *addr, int *bucketp,
2085 bucket = isc_sockaddr_hash(addr, ISC_TRUE) % adb->nentries;
2088 LOCK(&adb->entrylocks[bucket]);
2091 UNLOCK(&adb->entrylocks[*bucketp]);
2092 LOCK(&adb->entrylocks[bucket]);
2097 for (entry = ISC_LIST_HEAD(adb->entries[bucket]);
2101 (void)check_expire_entry(adb, &entry, now);
2105 ISC_LIST_UNLINK(adb->entries[bucket], entry, plink);
2106 ISC_LIST_PREPEND(adb->entries[bucket], entry, plink);
2118 entry_is_lame(dns_adb_t *adb, dns_adbentry_t *entry, dns_name_t *qname,
2137 free_adblameinfo(adb, &li);
2171 ISC_LOG_INFO, "adb: quota %s (%u/%u): %s",
2176 copy_namehook_lists(dns_adb_t *adb, dns_adbfind_t *find, dns_name_t *qname,
2193 LOCK(&adb->entrylocks[bucket]);
2205 && entry_is_lame(adb, entry, qname, qtype, now)) {
2209 addrinfo = new_adbaddrinfo(adb, entry, find->port);
2217 inc_entry_refcnt(adb, entry, ISC_FALSE);
2221 UNLOCK(&adb->entrylocks[bucket]);
2233 LOCK(&adb->entrylocks[bucket]);
2245 && entry_is_lame(adb, entry, qname, qtype, now)) {
2249 addrinfo = new_adbaddrinfo(adb, entry, find->port);
2257 inc_entry_refcnt(adb, entry, ISC_FALSE);
2261 UNLOCK(&adb->entrylocks[bucket]);
2269 UNLOCK(&adb->entrylocks[bucket]);
2274 dns_adb_t *adb;
2278 adb = ev->ev_arg;
2279 INSIST(DNS_ADB_VALID(adb));
2285 LOCK(&adb->lock);
2286 UNLOCK(&adb->lock);
2287 destroy(adb);
2291 * Name bucket must be locked; adb may be locked; no other locks held.
2334 * Name bucket must be locked; adb may be locked; no other locks held.
2337 check_stale_name(dns_adb_t *adb, int bucket, isc_stdtime_t now) {
2340 isc_boolean_t overmem = isc_mem_isovermem(adb->mctx);
2353 victim = ISC_LIST_TAIL(adb->names[bucket]);
2381 * Entry bucket must be locked; adb may be locked; no other locks held.
2384 check_expire_entry(dns_adb_t *adb, dns_adbentry_t **entryp, isc_stdtime_t now)
2403 result = unlink_entry(adb, entry);
2404 free_adbentry(adb, &entry);
2406 dec_adb_irefcnt(adb);
2415 cleanup_names(dns_adb_t *adb, int bucket, isc_stdtime_t now) {
2422 LOCK(&adb->namelocks[bucket]);
2423 if (adb->name_sd[bucket]) {
2424 UNLOCK(&adb->namelocks[bucket]);
2428 name = ISC_LIST_HEAD(adb->names[bucket]);
2437 UNLOCK(&adb->namelocks[bucket]);
2445 cleanup_entries(dns_adb_t *adb, int bucket, isc_stdtime_t now) {
2451 LOCK(&adb->entrylocks[bucket]);
2452 entry = ISC_LIST_HEAD(adb->entries[bucket]);
2456 result = check_expire_entry(adb, &entry, now);
2459 UNLOCK(&adb->entrylocks[bucket]);
2464 destroy(dns_adb_t *adb) {
2465 adb->magic = 0;
2467 isc_task_detach(&adb->task);
2468 if (adb->excl != NULL)
2469 isc_task_detach(&adb->excl);
2471 isc_mempool_destroy(&adb->nmp);
2472 isc_mempool_destroy(&adb->nhmp);
2473 isc_mempool_destroy(&adb->limp);
2474 isc_mempool_destroy(&adb->emp);
2475 isc_mempool_destroy(&adb->ahmp);
2476 isc_mempool_destroy(&adb->aimp);
2477 isc_mempool_destroy(&adb->afmp);
2479 DESTROYMUTEXBLOCK(adb->entrylocks, adb->nentries);
2480 isc_mem_put(adb->mctx, adb->entries,
2481 sizeof(*adb->entries) * adb->nentries);
2482 isc_mem_put(adb->mctx, adb->deadentries,
2483 sizeof(*adb->deadentries) * adb->nentries);
2484 isc_mem_put(adb->mctx, adb->entrylocks,
2485 sizeof(*adb->entrylocks) * adb->nentries);
2486 isc_mem_put(adb->mctx, adb->entry_sd,
2487 sizeof(*adb->entry_sd) * adb->nentries);
2488 isc_mem_put(adb->mctx, adb->entry_refcnt,
2489 sizeof(*adb->entry_refcnt) * adb->nentries);
2491 DESTROYMUTEXBLOCK(adb->namelocks, adb->nnames);
2492 isc_mem_put(adb->mctx, adb->names,
2493 sizeof(*adb->names) * adb->nnames);
2494 isc_mem_put(adb->mctx, adb->deadnames,
2495 sizeof(*adb->deadnames) * adb->nnames);
2496 isc_mem_put(adb->mctx, adb->namelocks,
2497 sizeof(*adb->namelocks) * adb->nnames);
2498 isc_mem_put(adb->mctx, adb->name_sd,
2499 sizeof(*adb->name_sd) * adb->nnames);
2500 isc_mem_put(adb->mctx, adb->name_refcnt,
2501 sizeof(*adb->name_refcnt) * adb->nnames);
2503 DESTROYLOCK(&adb->reflock);
2504 DESTROYLOCK(&adb->lock);
2505 DESTROYLOCK(&adb->mplock);
2506 DESTROYLOCK(&adb->overmemlock);
2507 DESTROYLOCK(&adb->entriescntlock);
2508 DESTROYLOCK(&adb->namescntlock);
2510 isc_mem_putanddetach(&adb->mctx, adb, sizeof(dns_adb_t));
2522 dns_adb_t *adb;
2534 adb = isc_mem_get(mem, sizeof(dns_adb_t));
2535 if (adb == NULL)
2542 adb->magic = 0;
2543 adb->erefcnt = 1;
2544 adb->irefcnt = 0;
2545 adb->nmp = NULL;
2546 adb->nhmp = NULL;
2547 adb->limp = NULL;
2548 adb->emp = NULL;
2549 adb->ahmp = NULL;
2550 adb->aimp = NULL;
2551 adb->afmp = NULL;
2552 adb->task = NULL;
2553 adb->excl = NULL;
2554 adb->mctx = NULL;
2555 adb->view = view;
2556 adb->taskmgr = taskmgr;
2557 adb->next_cleanbucket = 0;
2558 ISC_EVENT_INIT(&adb->cevent, sizeof(adb->cevent),
2560 adb->cevent_out = ISC_FALSE;
2561 adb->shutting_down = ISC_FALSE;
2562 ISC_LIST_INIT(adb->whenshutdown);
2564 adb->nentries = nbuckets[0];
2565 adb->entriescnt = 0;
2566 adb->entries = NULL;
2567 adb->deadentries = NULL;
2568 adb->entry_sd = NULL;
2569 adb->entry_refcnt = NULL;
2570 adb->entrylocks = NULL;
2571 ISC_EVENT_INIT(&adb->growentries, sizeof(adb->growentries), 0, NULL,
2572 DNS_EVENT_ADBGROWENTRIES, grow_entries, adb,
2573 adb, NULL, NULL);
2574 adb->growentries_sent = ISC_FALSE;
2576 adb->quota = 0;
2577 adb->atr_freq = 0;
2578 adb->atr_low = 0.0;
2579 adb->atr_high = 0.0;
2580 adb->atr_discount = 0.0;
2582 adb->nnames = nbuckets[0];
2583 adb->namescnt = 0;
2584 adb->names = NULL;
2585 adb->deadnames = NULL;
2586 adb->name_sd = NULL;
2587 adb->name_refcnt = NULL;
2588 adb->namelocks = NULL;
2589 ISC_EVENT_INIT(&adb->grownames, sizeof(adb->grownames), 0, NULL,
2590 DNS_EVENT_ADBGROWNAMES, grow_names, adb,
2591 adb, NULL, NULL);
2592 adb->grownames_sent = ISC_FALSE;
2594 result = isc_taskmgr_excltask(adb->taskmgr, &adb->excl);
2596 DP(DEF_LEVEL, "adb: task-exclusive mode unavailable, "
2599 adb->nentries = nbuckets[11];
2600 adb->nnames = nbuckets[11];
2603 isc_mem_attach(mem, &adb->mctx);
2605 result = isc_mutex_init(&adb->lock);
2609 result = isc_mutex_init(&adb->mplock);
2613 result = isc_mutex_init(&adb->reflock);
2617 result = isc_mutex_init(&adb->overmemlock);
2621 result = isc_mutex_init(&adb->entriescntlock);
2625 result = isc_mutex_init(&adb->namescntlock);
2629 #define ALLOCENTRY(adb, el) \
2631 (adb)->el = isc_mem_get((adb)->mctx, \
2632 sizeof(*(adb)->el) * (adb)->nentries); \
2633 if ((adb)->el == NULL) { \
2638 ALLOCENTRY(adb, entries);
2639 ALLOCENTRY(adb, deadentries);
2640 ALLOCENTRY(adb, entrylocks);
2641 ALLOCENTRY(adb, entry_sd);
2642 ALLOCENTRY(adb, entry_refcnt);
2645 #define ALLOCNAME(adb, el) \
2647 (adb)->el = isc_mem_get((adb)->mctx, \
2648 sizeof(*(adb)->el) * (adb)->nnames); \
2649 if ((adb)->el == NULL) { \
2654 ALLOCNAME(adb, names);
2655 ALLOCNAME(adb, deadnames);
2656 ALLOCNAME(adb, namelocks);
2657 ALLOCNAME(adb, name_sd);
2658 ALLOCNAME(adb, name_refcnt);
2665 result = isc_mutexblock_init(adb->namelocks, adb->nnames);
2668 for (i = 0; i < adb->nnames; i++) {
2669 ISC_LIST_INIT(adb->names[i]);
2670 ISC_LIST_INIT(adb->deadnames[i]);
2671 adb->name_sd[i] = ISC_FALSE;
2672 adb->name_refcnt[i] = 0;
2673 adb->irefcnt++;
2675 for (i = 0; i < adb->nentries; i++) {
2676 ISC_LIST_INIT(adb->entries[i]);
2677 ISC_LIST_INIT(adb->deadentries[i]);
2678 adb->entry_sd[i] = ISC_FALSE;
2679 adb->entry_refcnt[i] = 0;
2680 adb->irefcnt++;
2682 result = isc_mutexblock_init(adb->entrylocks, adb->nentries);
2696 isc_mempool_associatelock((p), &adb->mplock); \
2699 MPINIT(dns_adbname_t, adb->nmp, "adbname");
2700 MPINIT(dns_adbnamehook_t, adb->nhmp, "adbnamehook");
2701 MPINIT(dns_adblameinfo_t, adb->limp, "adblameinfo");
2702 MPINIT(dns_adbentry_t, adb->emp, "adbentry");
2703 MPINIT(dns_adbfind_t, adb->ahmp, "adbfind");
2704 MPINIT(dns_adbaddrinfo_t, adb->aimp, "adbaddrinfo");
2705 MPINIT(dns_adbfetch_t, adb->afmp, "adbfetch");
2712 result = isc_task_create(adb->taskmgr, 0, &adb->task);
2716 isc_task_setname(adb->task, "ADB", adb);
2718 result = isc_stats_create(adb->mctx, &view->adbstats, dns_adbstats_max);
2722 set_adbstat(adb, adb->nentries, dns_adbstats_nentries);
2723 set_adbstat(adb, adb->nnames, dns_adbstats_nnames);
2728 adb->magic = DNS_ADB_MAGIC;
2729 *newadb = adb;
2733 if (adb->task != NULL)
2734 isc_task_detach(&adb->task);
2737 DESTROYMUTEXBLOCK(adb->entrylocks, adb->nentries);
2740 DESTROYMUTEXBLOCK(adb->namelocks, adb->nnames);
2743 if (adb->entries != NULL)
2744 isc_mem_put(adb->mctx, adb->entries,
2745 sizeof(*adb->entries) * adb->nentries);
2746 if (adb->deadentries != NULL)
2747 isc_mem_put(adb->mctx, adb->deadentries,
2748 sizeof(*adb->deadentries) * adb->nentries);
2749 if (adb->entrylocks != NULL)
2750 isc_mem_put(adb->mctx, adb->entrylocks,
2751 sizeof(*adb->entrylocks) * adb->nentries);
2752 if (adb->entry_sd != NULL)
2753 isc_mem_put(adb->mctx, adb->entry_sd,
2754 sizeof(*adb->entry_sd) * adb->nentries);
2755 if (adb->entry_refcnt != NULL)
2756 isc_mem_put(adb->mctx, adb->entry_refcnt,
2757 sizeof(*adb->entry_refcnt) * adb->nentries);
2758 if (adb->names != NULL)
2759 isc_mem_put(adb->mctx, adb->names,
2760 sizeof(*adb->names) * adb->nnames);
2761 if (adb->deadnames != NULL)
2762 isc_mem_put(adb->mctx, adb->deadnames,
2763 sizeof(*adb->deadnames) * adb->nnames);
2764 if (adb->namelocks != NULL)
2765 isc_mem_put(adb->mctx, adb->namelocks,
2766 sizeof(*adb->namelocks) * adb->nnames);
2767 if (adb->name_sd != NULL)
2768 isc_mem_put(adb->mctx, adb->name_sd,
2769 sizeof(*adb->name_sd) * adb->nnames);
2770 if (adb->name_refcnt != NULL)
2771 isc_mem_put(adb->mctx, adb->name_refcnt,
2772 sizeof(*adb->name_refcnt) * adb->nnames);
2773 if (adb->nmp != NULL)
2774 isc_mempool_destroy(&adb->nmp);
2775 if (adb->nhmp != NULL)
2776 isc_mempool_destroy(&adb->nhmp);
2777 if (adb->limp != NULL)
2778 isc_mempool_destroy(&adb->limp);
2779 if (adb->emp != NULL)
2780 isc_mempool_destroy(&adb->emp);
2781 if (adb->ahmp != NULL)
2782 isc_mempool_destroy(&adb->ahmp);
2783 if (adb->aimp != NULL)
2784 isc_mempool_destroy(&adb->aimp);
2785 if (adb->afmp != NULL)
2786 isc_mempool_destroy(&adb->afmp);
2788 DESTROYLOCK(&adb->namescntlock);
2790 DESTROYLOCK(&adb->entriescntlock);
2792 DESTROYLOCK(&adb->overmemlock);
2794 DESTROYLOCK(&adb->reflock);
2796 DESTROYLOCK(&adb->mplock);
2798 DESTROYLOCK(&adb->lock);
2800 if (adb->excl != NULL)
2801 isc_task_detach(&adb->excl);
2802 isc_mem_putanddetach(&adb->mctx, adb, sizeof(dns_adb_t));
2808 dns_adb_attach(dns_adb_t *adb, dns_adb_t **adbx) {
2810 REQUIRE(DNS_ADB_VALID(adb));
2813 inc_adb_erefcnt(adb);
2814 *adbx = adb;
2819 dns_adb_t *adb;
2824 adb = *adbx;
2827 INSIST(adb->erefcnt > 0);
2829 LOCK(&adb->reflock);
2830 adb->erefcnt--;
2831 need_exit_check = ISC_TF(adb->erefcnt == 0 && adb->irefcnt == 0);
2832 UNLOCK(&adb->reflock);
2835 LOCK(&adb->lock);
2836 INSIST(adb->shutting_down);
2837 check_exit(adb);
2838 UNLOCK(&adb->lock);
2843 dns_adb_whenshutdown(dns_adb_t *adb, isc_task_t *task, isc_event_t **eventp) {
2849 * Send '*eventp' to 'task' when 'adb' has shutdown.
2852 REQUIRE(DNS_ADB_VALID(adb));
2858 LOCK(&adb->lock);
2859 LOCK(&adb->reflock);
2861 zeroirefcnt = ISC_TF(adb->irefcnt == 0);
2863 if (adb->shutting_down && zeroirefcnt &&
2864 isc_mempool_getallocated(adb->ahmp) == 0) {
2868 event->ev_sender = adb;
2874 ISC_LIST_APPEND(adb->whenshutdown, event, ev_link);
2877 UNLOCK(&adb->reflock);
2878 UNLOCK(&adb->lock);
2883 dns_adb_t *adb;
2887 adb = event->ev_arg;
2888 INSIST(DNS_ADB_VALID(adb));
2890 LOCK(&adb->lock);
2891 INSIST(adb->shutting_down);
2892 adb->cevent_out = ISC_FALSE;
2893 (void)shutdown_names(adb);
2894 (void)shutdown_entries(adb);
2895 if (dec_adb_irefcnt(adb))
2896 check_exit(adb);
2897 UNLOCK(&adb->lock);
2901 dns_adb_shutdown(dns_adb_t *adb) {
2905 * Shutdown 'adb'.
2908 LOCK(&adb->lock);
2910 if (!adb->shutting_down) {
2911 adb->shutting_down = ISC_TRUE;
2912 isc_mem_setwater(adb->mctx, water, adb, 0, 0);
2916 inc_adb_irefcnt(adb);
2917 ISC_EVENT_INIT(&adb->cevent, sizeof(adb->cevent), 0, NULL,
2918 DNS_EVENT_ADBCONTROL, shutdown_stage2, adb,
2919 adb, NULL, NULL);
2920 adb->cevent_out = ISC_TRUE;
2921 event = &adb->cevent;
2922 isc_task_send(adb->task, &event);
2925 UNLOCK(&adb->lock);
2929 dns_adb_createfind(dns_adb_t *adb, isc_task_t *task, isc_taskaction_t action,
2935 return (dns_adb_createfind2(adb, task, action, arg, name,
2941 dns_adb_createfind2(dns_adb_t *adb, isc_task_t *task, isc_taskaction_t action,
2958 REQUIRE(DNS_ADB_VALID(adb));
3002 find = new_adbfind(adb);
3026 adbname = find_name_and_lock(adb, name, find->options, &bucket);
3028 if (adb->name_sd[bucket]) {
3031 RUNTIME_CHECK(free_adbfind(adb, &find) == ISC_FALSE);
3044 check_stale_name(adb, bucket, now);
3046 adbname = new_adbname(adb, name);
3048 RUNTIME_CHECK(free_adbfind(adb, &find) == ISC_FALSE);
3052 link_name(adb, bucket, adbname);
3061 ISC_LIST_UNLINK(adb->names[bucket], adbname, plink);
3062 ISC_LIST_PREPEND(adb->names[bucket], adbname, plink);
3207 copy_namehook_lists(adb, find, qname, qtype, adbname, now);
3283 UNLOCK(&adb->namelocks[bucket]);
3294 dns_adb_t *adb;
3305 adb = find->adb;
3306 REQUIRE(DNS_ADB_VALID(adb));
3317 * Return the find to the memory pool, and decrement the adb's
3320 overmem = isc_mem_isovermem(adb->mctx);
3327 RUNTIME_CHECK(dec_entry_refcnt(adb, overmem, entry, ISC_TRUE) ==
3329 free_adbaddrinfo(adb, &ai);
3334 * WARNING: The find is freed with the adb locked. This is done
3340 LOCK(&adb->lock);
3341 if (free_adbfind(adb, &find))
3342 check_exit(adb);
3343 UNLOCK(&adb->lock);
3350 dns_adb_t *adb;
3358 adb = find->adb;
3359 REQUIRE(DNS_ADB_VALID(adb));
3372 violate_locking_hierarchy(&find->lock, &adb->namelocks[unlock_bucket]);
3379 UNLOCK(&adb->namelocks[unlock_bucket]);
3405 dns_adb_dump(dns_adb_t *adb, FILE *f) {
3409 REQUIRE(DNS_ADB_VALID(adb));
3413 * Lock the adb itself, lock all the name buckets, then lock all
3414 * the entry buckets. This should put the adb into a state where
3419 LOCK(&adb->lock);
3422 for (i = 0; i < adb->nnames; i++)
3423 RUNTIME_CHECK(cleanup_names(adb, i, now) == ISC_FALSE);
3424 for (i = 0; i < adb->nentries; i++)
3425 RUNTIME_CHECK(cleanup_entries(adb, i, now) == ISC_FALSE);
3427 dump_adb(adb, f, ISC_FALSE, now);
3428 UNLOCK(&adb->lock);
3439 dump_adb(dns_adb_t *adb, FILE *f, isc_boolean_t debug, isc_stdtime_t now) {
3450 adb, adb->erefcnt, adb->irefcnt,
3451 isc_mempool_getallocated(adb->nhmp));
3453 for (i = 0; i < adb->nnames; i++)
3454 LOCK(&adb->namelocks[i]);
3455 for (i = 0; i < adb->nentries; i++)
3456 LOCK(&adb->entrylocks[i]);
3461 for (i = 0; i < adb->nnames; i++) {
3462 name = ISC_LIST_HEAD(adb->names[i]);
3492 print_namehook_list(f, "v4", adb,
3494 print_namehook_list(f, "v6", adb,
3506 for (i = 0; i < adb->nentries; i++) {
3507 entry = ISC_LIST_HEAD(adb->entries[i]);
3510 dump_entry(f, adb, entry, debug, now);
3518 for (i = 0; i < adb->nentries; i++)
3519 UNLOCK(&adb->entrylocks[i]);
3520 for (i = 0; i < adb->nnames; i++)
3521 UNLOCK(&adb->namelocks[i]);
3525 dump_entry(FILE *f, dns_adb_t *adb, dns_adbentry_t *entry,
3555 if (adb != NULL && adb->quota != 0 && adb->atr_freq != 0) {
3637 dns_adb_t *adb, dns_adbnamehooklist_t *list,
3648 dump_entry(f, adb, nh->entry, debug, now);
3682 dns_adb_t *adb;
3687 adb = adbname->adb;
3688 INSIST(DNS_ADB_VALID(adb));
3708 result = dns_view_find2(adb->view, &adbname->name, rdtype, now,
3744 "adb name %p: Caching auth negative entry for A",
3752 "adb name %p: Caching auth negative entry for AAAA",
3775 "adb name %p: Caching negative entry for A (ttl %u)",
3779 "adb name %p: Caching negative entry for AAAA (ttl %u)",
3797 clean_target(adb, &adbname->target);
3799 result = set_target(adb, &adbname->name, fname, &rdataset,
3804 "adb name %p: caching alias target",
3825 dns_adb_t *adb;
3840 adb = name->adb;
3841 INSIST(DNS_ADB_VALID(adb));
3844 LOCK(&adb->namelocks[bucket]);
3880 free_adbfetch(adb, &fetch);
3885 UNLOCK(&adb->namelocks[bucket]);
3888 LOCK(&adb->lock);
3889 check_exit(adb);
3890 UNLOCK(&adb->lock);
3904 DP(NCACHE_LEVEL, "adb fetch name %p: "
3913 inc_stats(adb, dns_resstatscounter_gluefetchv4fail);
3915 DP(NCACHE_LEVEL, "adb fetch name %p: "
3924 inc_stats(adb, dns_resstatscounter_gluefetchv6fail);
3934 clean_target(adb, &name->target);
3936 result = set_target(adb, &name->name,
3942 "adb fetch name %p: caching alias target",
3957 DP(DEF_LEVEL, "adb: fetch of '%s' %s failed: %s",
3970 inc_stats(adb, dns_resstatscounter_gluefetchv4fail);
3974 inc_stats(adb, dns_resstatscounter_gluefetchv6fail);
3994 free_adbfetch(adb, &fetch);
3999 UNLOCK(&adb->namelocks[bucket]);
4008 dns_adb_t *adb;
4016 adb = adbname->adb;
4017 INSIST(DNS_ADB_VALID(adb));
4035 result = dns_view_findzonecut2(adb->view, &adbname->name, name,
4044 fetch = new_adbfetch(adb);
4051 result = dns_resolver_createfetch3(adb->view->resolver, &adbname->name,
4054 adb->task, fetch_callback, adbname,
4062 inc_stats(adb, dns_resstatscounter_gluefetchv4);
4065 inc_stats(adb, dns_resstatscounter_gluefetchv6);
4071 free_adbfetch(adb, &fetch);
4079 * XXXMLG Needs to take a find argument and an address info, no zone or adb,
4083 dns_adb_marklame(dns_adb_t *adb, dns_adbaddrinfo_t *addr, dns_name_t *qname,
4090 REQUIRE(DNS_ADB_VALID(adb));
4095 LOCK(&adb->entrylocks[bucket]);
4105 li = new_adblameinfo(adb, qname, qtype);
4115 UNLOCK(&adb->entrylocks[bucket]);
4121 dns_adb_adjustsrtt(dns_adb_t *adb, dns_adbaddrinfo_t *addr,
4127 REQUIRE(DNS_ADB_VALID(adb));
4132 LOCK(&adb->entrylocks[bucket]);
4138 UNLOCK(&adb->entrylocks[bucket]);
4142 dns_adb_agesrtt(dns_adb_t *adb, dns_adbaddrinfo_t *addr, isc_stdtime_t now) {
4145 REQUIRE(DNS_ADB_VALID(adb));
4149 LOCK(&adb->entrylocks[bucket]);
4153 UNLOCK(&adb->entrylocks[bucket]);
4183 dns_adb_changeflags(dns_adb_t *adb, dns_adbaddrinfo_t *addr,
4189 REQUIRE(DNS_ADB_VALID(adb));
4196 LOCK(&adb->entrylocks[bucket]);
4210 UNLOCK(&adb->entrylocks[bucket]);
4236 maybe_adjust_quota(dns_adb_t *adb, dns_adbaddrinfo_t *addr,
4241 UNUSED(adb);
4243 if (adb->quota == 0 || adb->atr_freq == 0)
4249 if (addr->entry->completed++ <= adb->atr_freq)
4261 INSIST(adb->atr_discount >= 0.0);
4262 INSIST(adb->atr_discount <= 1.0);
4263 addr->entry->atr *= 1.0 - adb->atr_discount;
4264 addr->entry->atr += tr * adb->atr_discount;
4267 if (addr->entry->atr < adb->atr_low && addr->entry->mode > 0) {
4268 addr->entry->quota = adb->quota *
4272 } else if (addr->entry->atr > adb->atr_high &&
4274 addr->entry->quota = adb->quota *
4287 dns_adb_noedns(dns_adb_t *adb, dns_adbaddrinfo_t *addr) {
4291 REQUIRE(DNS_ADB_VALID(adb));
4295 LOCK(&adb->entrylocks[bucket]);
4317 UNLOCK(&adb->entrylocks[bucket]);
4322 dns_adb_plainresponse(dns_adb_t *adb, dns_adbaddrinfo_t *addr) {
4325 REQUIRE(DNS_ADB_VALID(adb));
4329 LOCK(&adb->entrylocks[bucket]);
4331 maybe_adjust_quota(adb, addr, ISC_FALSE);
4343 UNLOCK(&adb->entrylocks[bucket]);
4347 dns_adb_timeout(dns_adb_t *adb, dns_adbaddrinfo_t *addr) {
4350 REQUIRE(DNS_ADB_VALID(adb));
4354 LOCK(&adb->entrylocks[bucket]);
4356 maybe_adjust_quota(adb, addr, ISC_TRUE);
4380 UNLOCK(&adb->entrylocks[bucket]);
4384 dns_adb_ednsto(dns_adb_t *adb, dns_adbaddrinfo_t *addr, unsigned int size) {
4387 REQUIRE(DNS_ADB_VALID(adb));
4391 LOCK(&adb->entrylocks[bucket]);
4393 maybe_adjust_quota(adb, addr, ISC_TRUE);
4427 UNLOCK(&adb->entrylocks[bucket]);
4431 dns_adb_setudpsize(dns_adb_t *adb, dns_adbaddrinfo_t *addr, unsigned int size) {
4434 REQUIRE(DNS_ADB_VALID(adb));
4438 LOCK(&adb->entrylocks[bucket]);
4444 maybe_adjust_quota(adb, addr, ISC_FALSE);
4456 UNLOCK(&adb->entrylocks[bucket]);
4460 dns_adb_getudpsize(dns_adb_t *adb, dns_adbaddrinfo_t *addr) {
4464 REQUIRE(DNS_ADB_VALID(adb));
4468 LOCK(&adb->entrylocks[bucket]);
4470 UNLOCK(&adb->entrylocks[bucket]);
4476 dns_adb_probesize(dns_adb_t *adb, dns_adbaddrinfo_t *addr) {
4477 return dns_adb_probesize2(adb, addr, 0);
4481 dns_adb_probesize2(dns_adb_t *adb, dns_adbaddrinfo_t *addr, int lookups) {
4485 REQUIRE(DNS_ADB_VALID(adb));
4489 LOCK(&adb->entrylocks[bucket]);
4505 UNLOCK(&adb->entrylocks[bucket]);
4511 dns_adb_setcookie(dns_adb_t *adb, dns_adbaddrinfo_t *addr,
4516 REQUIRE(DNS_ADB_VALID(adb));
4520 LOCK(&adb->entrylocks[bucket]);
4524 isc_mem_put(adb->mctx, addr->entry->cookie,
4531 addr->entry->cookie = isc_mem_get(adb->mctx, len);
4538 UNLOCK(&adb->entrylocks[bucket]);
4542 dns_adb_getcookie(dns_adb_t *adb, dns_adbaddrinfo_t *addr,
4547 REQUIRE(DNS_ADB_VALID(adb));
4551 LOCK(&adb->entrylocks[bucket]);
4559 UNLOCK(&adb->entrylocks[bucket]);
4565 dns_adb_findaddrinfo(dns_adb_t *adb, isc_sockaddr_t *sa,
4574 REQUIRE(DNS_ADB_VALID(adb));
4581 entry = find_entry_and_lock(adb, sa, &bucket, now);
4583 if (adb->entry_sd[bucket]) {
4591 entry = new_adbentry(adb);
4597 link_entry(adb, bucket, entry);
4603 addr = new_adbaddrinfo(adb, entry, port);
4607 inc_entry_refcnt(adb, entry, ISC_FALSE);
4612 UNLOCK(&adb->entrylocks[bucket]);
4618 dns_adb_freeaddrinfo(dns_adb_t *adb, dns_adbaddrinfo_t **addrp) {
4626 REQUIRE(DNS_ADB_VALID(adb));
4634 overmem = isc_mem_isovermem(adb->mctx);
4637 LOCK(&adb->entrylocks[bucket]);
4644 want_check_exit = dec_entry_refcnt(adb, overmem, entry, ISC_FALSE);
4646 UNLOCK(&adb->entrylocks[bucket]);
4649 free_adbaddrinfo(adb, &addr);
4652 LOCK(&adb->lock);
4653 check_exit(adb);
4654 UNLOCK(&adb->lock);
4659 dns_adb_flush(dns_adb_t *adb) {
4662 INSIST(DNS_ADB_VALID(adb));
4664 LOCK(&adb->lock);
4669 for (i = 0; i < adb->nnames; i++)
4670 RUNTIME_CHECK(cleanup_names(adb, i, INT_MAX) == ISC_FALSE);
4671 for (i = 0; i < adb->nentries; i++)
4672 RUNTIME_CHECK(cleanup_entries(adb, i, INT_MAX) == ISC_FALSE);
4675 dump_adb(adb, stdout, ISC_TRUE, INT_MAX);
4678 UNLOCK(&adb->lock);
4682 dns_adb_flushname(dns_adb_t *adb, dns_name_t *name) {
4687 REQUIRE(DNS_ADB_VALID(adb));
4690 LOCK(&adb->lock);
4691 bucket = dns_name_hash(name, ISC_FALSE) % adb->nnames;
4692 LOCK(&adb->namelocks[bucket]);
4693 adbname = ISC_LIST_HEAD(adb->names[bucket]);
4704 UNLOCK(&adb->namelocks[bucket]);
4705 UNLOCK(&adb->lock);
4709 dns_adb_flushnames(dns_adb_t *adb, dns_name_t *name) {
4713 REQUIRE(DNS_ADB_VALID(adb));
4716 LOCK(&adb->lock);
4717 for (i = 0; i < adb->nnames; i++) {
4718 LOCK(&adb->namelocks[i]);
4719 adbname = ISC_LIST_HEAD(adb->names[i]);
4732 UNLOCK(&adb->namelocks[i]);
4734 UNLOCK(&adb->lock);
4747 dns_adb_t *adb = arg;
4750 REQUIRE(DNS_ADB_VALID(adb));
4753 "adb reached %s water mark", overmem ? "high" : "low");
4757 dns_adb_setadbsize(dns_adb_t *adb, size_t size) {
4760 INSIST(DNS_ADB_VALID(adb));
4769 isc_mem_setwater(adb->mctx, water, adb, 0, 0);
4771 isc_mem_setwater(adb->mctx, water, adb, hiwater, lowater);
4775 dns_adb_setquota(dns_adb_t *adb, isc_uint32_t quota, isc_uint32_t freq,
4778 REQUIRE(DNS_ADB_VALID(adb));
4780 adb->quota = quota;
4781 adb->atr_freq = freq;
4782 adb->atr_low = low;
4783 adb->atr_high = high;
4784 adb->atr_discount = discount;
4796 dns_adb_beginudpfetch(dns_adb_t *adb, dns_adbaddrinfo_t *addr) {
4799 REQUIRE(DNS_ADB_VALID(adb));
4804 LOCK(&adb->entrylocks[bucket]);
4806 UNLOCK(&adb->entrylocks[bucket]);
4810 dns_adb_endudpfetch(dns_adb_t *adb, dns_adbaddrinfo_t *addr) {
4813 REQUIRE(DNS_ADB_VALID(adb));
4818 LOCK(&adb->entrylocks[bucket]);
4821 UNLOCK(&adb->entrylocks[bucket]);