From c20ffa38dee7efa0dc01822d4bac5e41729b9b61 Mon Sep 17 00:00:00 2001 From: Brian Wellington Date: Wed, 11 Apr 2001 20:37:50 +0000 Subject: [PATCH] 808. [func] Add 'rndc flush' to flush the server's cache. --- CHANGES | 2 + bin/named/control.c | 4 +- bin/named/include/named/control.h | 3 +- bin/named/include/named/server.h | 8 ++- bin/named/server.c | 23 ++++++- bin/rndc/rndc.c | 3 +- lib/dns/adb.c | 25 +++++++- lib/dns/cache.c | 83 +++++++++++++++++++++++--- lib/dns/include/dns/adb.h | 11 +++- lib/dns/include/dns/cache.h | 12 +++- lib/dns/include/dns/view.h | 17 +++++- lib/dns/resolver.c | 99 ++++++++++++++++--------------- lib/dns/view.c | 20 ++++++- 13 files changed, 244 insertions(+), 66 deletions(-) diff --git a/CHANGES b/CHANGES index 0e578122d9..34f259b59c 100644 --- a/CHANGES +++ b/CHANGES @@ -1,4 +1,6 @@ + 808. [func] Add 'rndc flush' to flush the server's cache. + 807. [bug] When setting up TCP connections for incoming zone transfers, the transfer-source port was not ignored like it should be. diff --git a/bin/named/control.c b/bin/named/control.c index bcb8a621ff..14f26b43d3 100644 --- a/bin/named/control.c +++ b/bin/named/control.c @@ -15,7 +15,7 @@ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: control.c,v 1.2 2001/04/10 21:50:40 bwelling Exp $ */ +/* $Id: control.c,v 1.3 2001/04/11 20:37:33 bwelling Exp $ */ #include @@ -109,6 +109,8 @@ ns_control_docommand(isccc_sexpr_t *message) { ns_g_debuglevel = 0; isc_log_setdebuglevel(ns_g_lctx, ns_g_debuglevel); result = ISC_R_SUCCESS; + } else if (command_compare(command, NS_COMMAND_FLUSH)) { + result = ns_server_flushcache(ns_g_server); } else { isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_CONTROL, ISC_LOG_WARNING, diff --git a/bin/named/include/named/control.h b/bin/named/include/named/control.h index d1b0949703..d2697f357a 100644 --- a/bin/named/include/named/control.h +++ b/bin/named/include/named/control.h @@ -15,7 +15,7 @@ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: control.h,v 1.2 2001/04/10 21:50:45 bwelling Exp $ */ +/* $Id: control.h,v 1.3 2001/04/11 20:37:36 bwelling Exp $ */ #ifndef NAMED_CONTROL_H #define NAMED_CONTROL_H 1 @@ -37,6 +37,7 @@ #define NS_COMMAND_DUMPDB "dumpdb" #define NS_COMMAND_TRACE "trace" #define NS_COMMAND_NOTRACE "notrace" +#define NS_COMMAND_FLUSH "flush" isc_result_t ns_control_init(void); diff --git a/bin/named/include/named/server.h b/bin/named/include/named/server.h index 8035faaf1c..629ef531e0 100644 --- a/bin/named/include/named/server.h +++ b/bin/named/include/named/server.h @@ -15,7 +15,7 @@ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: server.h,v 1.52 2001/02/14 03:50:08 gson Exp $ */ +/* $Id: server.h,v 1.53 2001/04/11 20:37:37 bwelling Exp $ */ #ifndef NAMED_SERVER_H #define NAMED_SERVER_H 1 @@ -148,4 +148,10 @@ ns_server_dumpdb(ns_server_t *server); isc_result_t ns_server_setdebuglevel(ns_server_t *server, char *args); +/* + * Flush the server's cache(s) + */ +isc_result_t +ns_server_flushcache(ns_server_t *server); + #endif /* NAMED_SERVER_H */ diff --git a/bin/named/server.c b/bin/named/server.c index 848e880c1e..2c05ca93b2 100644 --- a/bin/named/server.c +++ b/bin/named/server.c @@ -15,7 +15,7 @@ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: server.c,v 1.315 2001/03/29 04:25:59 gson Exp $ */ +/* $Id: server.c,v 1.316 2001/04/11 20:37:34 bwelling Exp $ */ #include @@ -2685,3 +2685,24 @@ ns_server_setdebuglevel(ns_server_t *server, char *args) { isc_log_setdebuglevel(ns_g_lctx, ns_g_debuglevel); return (ISC_R_SUCCESS); } + +isc_result_t +ns_server_flushcache(ns_server_t *server) { + dns_view_t *view; + isc_result_t result; + + result = isc_task_beginexclusive(server->task); + RUNTIME_CHECK(result == ISC_R_SUCCESS); + for (view = ISC_LIST_HEAD(server->viewlist); + view != NULL; + view = ISC_LIST_NEXT(view, link)) + { + result = dns_view_flushcache(view); + if (result != ISC_R_SUCCESS) + goto out; + } + result = ISC_R_SUCCESS; + out: + isc_task_endexclusive(server->task); + return (result); +} diff --git a/bin/rndc/rndc.c b/bin/rndc/rndc.c index 300c5e0ec6..759d59b436 100644 --- a/bin/rndc/rndc.c +++ b/bin/rndc/rndc.c @@ -15,7 +15,7 @@ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: rndc.c,v 1.52 2001/04/10 22:00:41 bwelling Exp $ */ +/* $Id: rndc.c,v 1.53 2001/04/11 20:37:39 bwelling Exp $ */ /* * Principal Author: DCL @@ -110,6 +110,7 @@ command is one of the following:\n\ trace Increment debugging level by one.\n\ trace level Change the debugging level.\n\ notrace Set debugging level to 0.\n\ + flush Flushes the server's cache.\n\ *status Display ps(1) status of named.\n\ *restart Restart the server.\n\ \n\ diff --git a/lib/dns/adb.c b/lib/dns/adb.c index f01eb223b1..74c0d1d1cc 100644 --- a/lib/dns/adb.c +++ b/lib/dns/adb.c @@ -15,7 +15,7 @@ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: adb.c,v 1.173 2001/04/10 00:18:27 gson Exp $ */ +/* $Id: adb.c,v 1.174 2001/04/11 20:37:40 bwelling Exp $ */ /* * Implementation notes @@ -4008,3 +4008,26 @@ dns_adb_freeaddrinfo(dns_adb_t *adb, dns_adbaddrinfo_t **addrp) { UNLOCK(&adb->lock); } } + +void +dns_adb_flush(dns_adb_t *adb) { + unsigned int i; + + INSIST(DNS_ADB_VALID(adb)); + + LOCK(&adb->lock); + + for (i = 0 ; i < NBUCKETS ; i++) { + /* + * Call our cleanup routines. + */ + cleanup_names(adb, i, INT_MAX); + cleanup_entries(adb, i, INT_MAX); + } + +#ifdef DUMP_ADB_AFTER_CLEANING + dump_adb(adb, stdout, ISC_TRUE); +#endif + + UNLOCK(&adb->lock); +} diff --git a/lib/dns/cache.c b/lib/dns/cache.c index a38825ef8b..78ce64bbd4 100644 --- a/lib/dns/cache.c +++ b/lib/dns/cache.c @@ -15,7 +15,7 @@ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: cache.c,v 1.35 2001/03/08 01:22:48 tale Exp $ */ +/* $Id: cache.c,v 1.36 2001/04/11 20:37:42 bwelling Exp $ */ #include @@ -97,6 +97,9 @@ struct dns_cache { dns_rdataclass_t rdclass; dns_db_t *db; cache_cleaner_t cleaner; + char *db_type; + int db_argc; + char **db_argv; /* Locked by 'filelock'. */ char * filename; @@ -124,6 +127,13 @@ cleaner_shutdown_action(isc_task_t *task, isc_event_t *event); static void overmem_cleaning_action(isc_task_t *task, isc_event_t *event); +static inline isc_result_t +cache_create_db(dns_cache_t *cache, dns_db_t **db) { + return (dns_db_create(cache->mctx, cache->db_type, dns_rootname, + dns_dbtype_cache, cache->rdclass, + cache->db_argc, cache->db_argv, db)); +} + isc_result_t dns_cache_create(isc_mem_t *mctx, isc_taskmgr_t *taskmgr, isc_timermgr_t *timermgr, dns_rdataclass_t rdclass, @@ -132,6 +142,7 @@ dns_cache_create(isc_mem_t *mctx, isc_taskmgr_t *taskmgr, { isc_result_t result; dns_cache_t *cache; + int i; REQUIRE(cachep != NULL); REQUIRE(*cachep == NULL); @@ -166,12 +177,37 @@ dns_cache_create(isc_mem_t *mctx, isc_taskmgr_t *taskmgr, cache->live_tasks = 0; cache->rdclass = rdclass; - cache->db = NULL; - result = dns_db_create(cache->mctx, db_type, dns_rootname, - dns_dbtype_cache, rdclass, db_argc, db_argv, - &cache->db); - if (result != ISC_R_SUCCESS) + cache->db_type = isc_mem_strdup(mctx, db_type); + if (cache->db_type == NULL) { + result = ISC_R_NOMEMORY; goto cleanup_filelock; + } + + cache->db_argc = db_argc; + if (cache->db_argc == 0) + cache->db_argv = NULL; + else { + cache->db_argv = isc_mem_get(mctx, + cache->db_argc * sizeof(char *)); + if (cache->db_argv == NULL) { + result = ISC_R_NOMEMORY; + goto cleanup_dbtype; + } + for (i = 0; i < cache->db_argc; i++) + cache->db_argv[i] = NULL; + for (i = 0; i < cache->db_argc; i++) { + cache->db_argv[i] = isc_mem_strdup(mctx, db_argv[i]); + if (cache->db_argv[i] == NULL) { + result = ISC_R_NOMEMORY; + goto cleanup_dbargv; + } + } + } + + cache->db = NULL; + result = cache_create_db(cache, &cache->db); + if (result != ISC_R_SUCCESS) + goto cleanup_dbargv; cache->filename = NULL; @@ -187,6 +223,13 @@ dns_cache_create(isc_mem_t *mctx, isc_taskmgr_t *taskmgr, cleanup_db: dns_db_detach(&cache->db); + cleanup_dbargv: + for (i = 0; i < cache->db_argc; i++) + if (cache->db_argv[i] != NULL) + isc_mem_free(mctx, cache->db_argv[i]); + isc_mem_put(mctx, cache->db_argv, cache->db_argc * sizeof(char *)); + cleanup_dbtype: + isc_mem_free(mctx, cache->db_type); cleanup_filelock: DESTROYLOCK(&cache->filelock); cleanup_lock: @@ -200,6 +243,7 @@ dns_cache_create(isc_mem_t *mctx, isc_taskmgr_t *taskmgr, static void cache_free(dns_cache_t *cache) { isc_mem_t *mctx; + int i; REQUIRE(VALID_CACHE(cache)); REQUIRE(cache->references == 0); @@ -223,9 +267,20 @@ cache_free(dns_cache_t *cache) { cache->filename = NULL; } - if (cache->db) + if (cache->db != NULL) dns_db_detach(&cache->db); + if (cache->db_argv != NULL) { + for (i = 0; i < cache->db_argc; i++) + if (cache->db_argv[i] != NULL) + isc_mem_free(cache->mctx, cache->db_argv[i]); + isc_mem_put(cache->mctx, cache->db_argv, + cache->db_argc * sizeof(char *)); + } + + if (cache->db_type != NULL) + isc_mem_free(cache->mctx, cache->db_type); + DESTROYLOCK(&cache->lock); DESTROYLOCK(&cache->filelock); cache->magic = 0; @@ -802,3 +857,17 @@ cleaner_shutdown_action(isc_task_t *task, isc_event_t *event) { if (should_free) cache_free(cache); } + +isc_result_t +dns_cache_flush(dns_cache_t *cache) { + dns_db_t *db = NULL; + isc_result_t result; + + result = cache_create_db(cache, &db); + if (result != ISC_R_SUCCESS) + return (result); + + dns_db_detach(&cache->db); + cache->db = db; + return (ISC_R_SUCCESS); +} diff --git a/lib/dns/include/dns/adb.h b/lib/dns/include/dns/adb.h index 222c3ab6ae..ed22d2d15e 100644 --- a/lib/dns/include/dns/adb.h +++ b/lib/dns/include/dns/adb.h @@ -15,7 +15,7 @@ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: adb.h,v 1.64 2001/02/28 20:47:36 gson Exp $ */ +/* $Id: adb.h,v 1.65 2001/04/11 20:37:48 bwelling Exp $ */ #ifndef DNS_ADB_H #define DNS_ADB_H 1 @@ -559,6 +559,15 @@ dns_adb_freeaddrinfo(dns_adb_t *adb, dns_adbaddrinfo_t **addrp); * *addrp is a valid dns_adbaddrinfo_t *. */ +void +dns_adb_flush(dns_adb_t *adb); +/* + * Flushes all cached data from the adb. + * + * Requires: + * adb is valid. + */ + ISC_LANG_ENDDECLS #endif /* DNS_ADB_H */ diff --git a/lib/dns/include/dns/cache.h b/lib/dns/include/dns/cache.h index e54f369b3b..1b75cb666e 100644 --- a/lib/dns/include/dns/cache.h +++ b/lib/dns/include/dns/cache.h @@ -15,7 +15,7 @@ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: cache.h,v 1.16 2001/01/09 21:52:19 bwelling Exp $ */ +/* $Id: cache.h,v 1.17 2001/04/11 20:37:49 bwelling Exp $ */ #ifndef DNS_CACHE_H #define DNS_CACHE_H 1 @@ -225,6 +225,16 @@ dns_cache_setcachesize(dns_cache_t *cache, isc_uint32_t size); * Set the maximum cache size. 0 means unlimited. */ +isc_result_t +dns_cache_flush(dns_cache_t *cache); +/* + * Flushes all data from the cache. + * + * Returns: + * ISC_R_SUCCESS + * ISC_R_NOMEMORY + */ + ISC_LANG_ENDDECLS #endif /* DNS_CACHE_H */ diff --git a/lib/dns/include/dns/view.h b/lib/dns/include/dns/view.h index daadb60a9c..8473e2ef46 100644 --- a/lib/dns/include/dns/view.h +++ b/lib/dns/include/dns/view.h @@ -15,7 +15,7 @@ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: view.h,v 1.69 2001/03/26 21:33:04 bwelling Exp $ */ +/* $Id: view.h,v 1.70 2001/04/11 20:37:50 bwelling Exp $ */ #ifndef DNS_VIEW_H #define DNS_VIEW_H 1 @@ -666,6 +666,21 @@ dns_view_dumpdbtostream(dns_view_t *view, FILE *fp); * others An error occurred (see dns_master_dump) */ +isc_result_t +dns_view_flushcache(dns_view_t *view); +/* + * Flush the view's cache (and ADB). + * + * Requires: + * 'view' is valid. + * + * No other tasks are executing. + * + * Returns: + * ISC_R_SUCCESS + * ISC_R_NOMEMORY + */ + ISC_LANG_ENDDECLS #endif /* DNS_VIEW_H */ diff --git a/lib/dns/resolver.c b/lib/dns/resolver.c index 6ebe698690..f5bb912d99 100644 --- a/lib/dns/resolver.c +++ b/lib/dns/resolver.c @@ -15,7 +15,7 @@ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: resolver.c,v 1.214 2001/03/26 21:32:58 bwelling Exp $ */ +/* $Id: resolver.c,v 1.215 2001/04/11 20:37:44 bwelling Exp $ */ #include @@ -173,6 +173,8 @@ struct fetchctx { dns_fwdpolicy_t fwdpolicy; isc_sockaddrlist_t bad; ISC_LIST(dns_validator_t) validators; + dns_db_t * cache; + dns_adb_t * adb; /* * The number of events we're waiting for. @@ -406,8 +408,7 @@ fctx_cancelquery(resquery_t **queryp, dns_dispatchevent_t **deventp, */ factor = DNS_ADB_RTTADJREPLACE; } - dns_adb_adjustsrtt(fctx->res->view->adb, query->addrinfo, rtt, - factor); + dns_adb_adjustsrtt(fctx->adb, query->addrinfo, rtt, factor); } if (query->dispentry != NULL) @@ -491,7 +492,7 @@ fctx_cleanupforwaddrs(fetchctx_t *fctx) { addr = next_addr) { next_addr = ISC_LIST_NEXT(addr, publink); ISC_LIST_UNLINK(fctx->forwaddrs, addr, publink); - dns_adb_freeaddrinfo(fctx->res->view->adb, &addr); + dns_adb_freeaddrinfo(fctx->adb, &addr); } } @@ -976,7 +977,7 @@ resquery_send(resquery_t *query) { !useedns) { query->options |= DNS_FETCHOPT_NOEDNS0; - dns_adb_changeflags(fctx->res->view->adb, + dns_adb_changeflags(fctx->adb, query->addrinfo, DNS_FETCHOPT_NOEDNS0, DNS_FETCHOPT_NOEDNS0); @@ -1477,7 +1478,7 @@ fctx_getaddresses(fetchctx_t *fctx) { while (sa != NULL) { ai = NULL; - result = dns_adb_findaddrinfo(fctx->res->view->adb, + result = dns_adb_findaddrinfo(fctx->adb, sa, &ai, 0); /* XXXMLG */ if (result == ISC_R_SUCCESS) { ai->flags |= FCTX_ADDRINFO_FORWARDER; @@ -1556,7 +1557,7 @@ fctx_getaddresses(fetchctx_t *fctx) { * See what we know about this address. */ find = NULL; - result = dns_adb_createfind(res->view->adb, + result = dns_adb_createfind(fctx->adb, res->buckets[fctx->bucketnum].task, fctx_finddone, fctx, &ns.name, &fctx->domain, options, now, NULL, @@ -1848,6 +1849,8 @@ fctx_destroy(fetchctx_t *fctx) { if (dns_rdataset_isassociated(&fctx->nameservers)) dns_rdataset_disassociate(&fctx->nameservers); dns_name_free(&fctx->name, res->mctx); + dns_db_detach(&fctx->cache); + dns_adb_detach(&fctx->adb); isc_mem_put(res->mctx, fctx, sizeof *fctx); if (res->buckets[bucketnum].exiting && @@ -2258,6 +2261,14 @@ fctx_create(dns_resolver_t *res, dns_name_t *name, dns_rdatatype_t type, goto cleanup_rmessage; } + /* + * Attach to the view's cache and adb. + */ + fctx->cache = NULL; + dns_db_attach(res->view->cachedb, &fctx->cache); + fctx->adb = NULL; + dns_adb_attach(res->view->adb, &fctx->adb); + ISC_LIST_INIT(fctx->events); ISC_LINK_INIT(fctx, link); fctx->magic = FCTX_MAGIC; @@ -2558,20 +2569,17 @@ validated(isc_task_t *task, isc_event_t *event) { if (vevent->result != ISC_R_SUCCESS) { FCTXTRACE("validation failed"); if (vevent->rdataset != NULL) { - result = dns_db_findnode(fctx->res->view->cachedb, - vevent->name, ISC_TRUE, - &node); + result = dns_db_findnode(fctx->cache, vevent->name, + ISC_TRUE, &node); if (result != ISC_R_SUCCESS) goto noanswer_response; - (void)dns_db_deleterdataset(fctx->res->view->cachedb, - node, NULL, + (void)dns_db_deleterdataset(fctx->cache, node, NULL, vevent->type, 0); if (vevent->sigrdataset != NULL) - (void)dns_db_deleterdataset( - fctx->res->view->cachedb, - node, NULL, - dns_rdatatype_sig, - vevent->type); + (void)dns_db_deleterdataset(fctx->cache, + node, NULL, + dns_rdatatype_sig, + vevent->type); } result = vevent->result; goto noanswer_response; @@ -2588,8 +2596,8 @@ validated(isc_task_t *task, isc_event_t *event) { else covers = fctx->type; - result = dns_db_findnode(fctx->res->view->cachedb, - vevent->name, ISC_TRUE, &node); + result = dns_db_findnode(fctx->cache, vevent->name, ISC_TRUE, + &node); if (result != ISC_R_SUCCESS) goto noanswer_response; @@ -2603,8 +2611,7 @@ validated(isc_task_t *task, isc_event_t *event) { covers == dns_rdatatype_any) ttl = 0; - result = ncache_adderesult(fctx->rmessage, - fctx->res->view->cachedb, node, + result = ncache_adderesult(fctx->rmessage, fctx->cache, node, covers, now, ttl, ardataset, &eresult); if (result != ISC_R_SUCCESS) @@ -2621,21 +2628,17 @@ validated(isc_task_t *task, isc_event_t *event) { * rdatasets to the first event on the fetch * event list. */ - result = dns_db_findnode(fctx->res->view->cachedb, - vevent->name, ISC_TRUE, &node); + result = dns_db_findnode(fctx->cache, vevent->name, ISC_TRUE, &node); if (result != ISC_R_SUCCESS) goto noanswer_response; - result = dns_db_addrdataset(fctx->res->view->cachedb, - node, NULL, now, - vevent->rdataset, 0, - ardataset); + result = dns_db_addrdataset(fctx->cache, node, NULL, now, + vevent->rdataset, 0, ardataset); if (result != ISC_R_SUCCESS && result != DNS_R_UNCHANGED) goto noanswer_response; if (vevent->sigrdataset != NULL) { - result = dns_db_addrdataset(fctx->res->view->cachedb, - node, NULL, now, + result = dns_db_addrdataset(fctx->cache, node, NULL, now, vevent->sigrdataset, 0, asigrdataset); if (result != ISC_R_SUCCESS && @@ -2680,7 +2683,7 @@ validated(isc_task_t *task, isc_event_t *event) { hevent->result = eresult; dns_name_copy(vevent->name, dns_fixedname_name(&hevent->foundname), NULL); - dns_db_attach(fctx->res->view->cachedb, &hevent->db); + dns_db_attach(fctx->cache, &hevent->db); hevent->node = node; node = NULL; clone_results(fctx); @@ -2688,7 +2691,7 @@ validated(isc_task_t *task, isc_event_t *event) { noanswer_response: if (node != NULL) - dns_db_detachnode(fctx->res->view->cachedb, &node); + dns_db_detachnode(fctx->cache, &node); fctx_done(fctx, result); @@ -2773,7 +2776,7 @@ cache_name(fetchctx_t *fctx, dns_name_t *name, isc_stdtime_t now) { * Find or create the cache node. */ node = NULL; - result = dns_db_findnode(res->view->cachedb, name, ISC_TRUE, &node); + result = dns_db_findnode(fctx->cache, name, ISC_TRUE, &node); if (result != ISC_R_SUCCESS) return (result); @@ -2843,9 +2846,8 @@ cache_name(fetchctx_t *fctx, dns_name_t *name, isc_stdtime_t now) { addedrdataset = ardataset; else addedrdataset = NULL; - result = dns_db_addrdataset(res->view->cachedb, - node, NULL, now, - rdataset, 0, + result = dns_db_addrdataset(fctx->cache, node, NULL, + now, rdataset, 0, addedrdataset); if (result == DNS_R_UNCHANGED) result = ISC_R_SUCCESS; @@ -2856,7 +2858,7 @@ cache_name(fetchctx_t *fctx, dns_name_t *name, isc_stdtime_t now) { addedrdataset = asigrdataset; else addedrdataset = NULL; - result = dns_db_addrdataset(res->view->cachedb, + result = dns_db_addrdataset(fctx->cache, node, NULL, now, sigrdataset, 0, addedrdataset); @@ -2943,7 +2945,7 @@ cache_name(fetchctx_t *fctx, dns_name_t *name, isc_stdtime_t now) { /* * Now we can add the rdataset. */ - result = dns_db_addrdataset(res->view->cachedb, + result = dns_db_addrdataset(fctx->cache, node, NULL, now, rdataset, options, @@ -2993,7 +2995,7 @@ cache_name(fetchctx_t *fctx, dns_name_t *name, isc_stdtime_t now) { fctx->attributes |= FCTX_ATTR_HAVEANSWER; if (event != NULL) { event->result = eresult; - dns_db_attach(res->view->cachedb, adbp); + dns_db_attach(fctx->cache, adbp); *anodep = node; node = NULL; clone_results(fctx); @@ -3001,7 +3003,7 @@ cache_name(fetchctx_t *fctx, dns_name_t *name, isc_stdtime_t now) { } if (node != NULL) - dns_db_detachnode(res->view->cachedb, &node); + dns_db_detachnode(fctx->cache, &node); return (result); } @@ -3200,8 +3202,7 @@ ncache_message(fetchctx_t *fctx, dns_rdatatype_t covers, isc_stdtime_t now) { event = NULL; node = NULL; - result = dns_db_findnode(res->view->cachedb, name, ISC_TRUE, - &node); + result = dns_db_findnode(fctx->cache, name, ISC_TRUE, &node); if (result != ISC_R_SUCCESS) goto unlock; @@ -3215,7 +3216,7 @@ ncache_message(fetchctx_t *fctx, dns_rdatatype_t covers, isc_stdtime_t now) { covers == dns_rdatatype_any) ttl = 0; - result = ncache_adderesult(fctx->rmessage, res->view->cachedb, node, + result = ncache_adderesult(fctx->rmessage, fctx->cache, node, covers, now, ttl, ardataset, &eresult); if (result != ISC_R_SUCCESS) goto unlock; @@ -3224,7 +3225,7 @@ ncache_message(fetchctx_t *fctx, dns_rdatatype_t covers, isc_stdtime_t now) { fctx->attributes |= FCTX_ATTR_HAVEANSWER; if (event != NULL) { event->result = eresult; - dns_db_attach(res->view->cachedb, adbp); + dns_db_attach(fctx->cache, adbp); *anodep = node; node = NULL; clone_results(fctx); @@ -3235,7 +3236,7 @@ ncache_message(fetchctx_t *fctx, dns_rdatatype_t covers, isc_stdtime_t now) { UNLOCK(&res->buckets[fctx->bucketnum].lock); if (node != NULL) - dns_db_detachnode(res->view->cachedb, &node); + dns_db_detachnode(fctx->cache, &node); return (result); } @@ -4073,7 +4074,7 @@ resquery_response(isc_task_t *task, isc_event_t *event) { /* * Remember that they don't like EDNS0. */ - dns_adb_changeflags(fctx->res->view->adb, + dns_adb_changeflags(fctx->adb, query->addrinfo, DNS_FETCHOPT_NOEDNS0, DNS_FETCHOPT_NOEDNS0); @@ -4129,7 +4130,7 @@ resquery_response(isc_task_t *task, isc_event_t *event) { * Remember that they don't like EDNS0. */ dns_adb_changeflags( - fctx->res->view->adb, + fctx->adb, query->addrinfo, DNS_FETCHOPT_NOEDNS0, DNS_FETCHOPT_NOEDNS0); @@ -4157,7 +4158,7 @@ resquery_response(isc_task_t *task, isc_event_t *event) { /* * Remember that they don't like EDNS0. */ - dns_adb_changeflags(fctx->res->view->adb, + dns_adb_changeflags(fctx->adb, query->addrinfo, DNS_FETCHOPT_NOEDNS0, DNS_FETCHOPT_NOEDNS0); @@ -4241,7 +4242,7 @@ resquery_response(isc_task_t *task, isc_event_t *event) { /* * Remember that they don't like EDNS0. */ - dns_adb_changeflags(fctx->res->view->adb, + dns_adb_changeflags(fctx->adb, query->addrinfo, DNS_FETCHOPT_NOEDNS0, DNS_FETCHOPT_NOEDNS0); @@ -4297,7 +4298,7 @@ resquery_response(isc_task_t *task, isc_event_t *event) { if (fctx->res->lame_ttl != 0 && !ISFORWARDER(query->addrinfo) && is_lame(fctx)) { log_lame(fctx, query->addrinfo); - dns_adb_marklame(fctx->res->view->adb, query->addrinfo, + dns_adb_marklame(fctx->adb, query->addrinfo, &fctx->domain, now + fctx->res->lame_ttl); broken_server = ISC_TRUE; keep_trying = ISC_TRUE; diff --git a/lib/dns/view.c b/lib/dns/view.c index dc0117bec3..52ea8ad60e 100644 --- a/lib/dns/view.c +++ b/lib/dns/view.c @@ -15,7 +15,7 @@ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: view.c,v 1.98 2001/03/26 21:33:00 bwelling Exp $ */ +/* $Id: view.c,v 1.99 2001/04/11 20:37:45 bwelling Exp $ */ #include @@ -1093,3 +1093,21 @@ dns_view_dumpdbtostream(dns_view_t *view, FILE *fp) { #endif return (ISC_R_SUCCESS); } + +isc_result_t +dns_view_flushcache(dns_view_t *view) { + isc_result_t result; + + REQUIRE(DNS_VIEW_VALID(view)); + + if (view->cachedb == NULL) + return (ISC_R_SUCCESS); + result = dns_cache_flush(view->cache); + if (result != ISC_R_SUCCESS) + return (result); + dns_db_detach(&view->cachedb); + dns_cache_attachdb(view->cache, &view->cachedb); + + dns_adb_flush(view->adb); + return (ISC_R_SUCCESS); +}