From 6c8abf481df85a67c3f32f5f107b554d3ff5a3ed Mon Sep 17 00:00:00 2001 From: Mark Andrews Date: Tue, 27 Nov 2001 03:10:32 +0000 Subject: [PATCH] 1138. [func] It is now possible to flush given names from the cache dns_cache_flushname(). --- CHANGES | 3 ++ lib/dns/cache.c | 75 ++++++++++++++++++++++++++++++++++++- lib/dns/include/dns/cache.h | 17 ++++++++- 3 files changed, 93 insertions(+), 2 deletions(-) diff --git a/CHANGES b/CHANGES index 22b67dca64..f0540fa293 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,6 @@ +1138. [func] It is now possible to flush given names from the + cache dns_cache_flushname(). + 1137. [func] It is now possible to flush given names from the adb cache dns_adb_flushname(). diff --git a/lib/dns/cache.c b/lib/dns/cache.c index e24b84fb46..a5135fbbeb 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.50 2001/11/12 19:05:13 gson Exp $ */ +/* $Id: cache.c,v 1.51 2001/11/27 03:10:29 marka Exp $ */ #include @@ -31,6 +31,9 @@ #include #include #include +#include +#include +#include #include #define CACHE_MAGIC ISC_MAGIC('$', '$', '$', '$') @@ -966,3 +969,73 @@ dns_cache_flush(dns_cache_t *cache) { cache->db = db; return (ISC_R_SUCCESS); } + +isc_result_t +dns_cache_flushname(dns_cache_t *cache, dns_name_t *name) { + isc_result_t result; + dns_rdatasetiter_t *iter = NULL; + dns_dbnode_t *node = NULL; + dns_db_t *db = NULL; + + LOCK(&cache->lock); + if (cache->db != NULL) + dns_db_attach(cache->db, &db); + UNLOCK(&cache->lock); + if (db == NULL) + return (ISC_R_SUCCESS); + result = dns_db_findnode(cache->db, name, ISC_FALSE, &node); + if (result == ISC_R_NOTFOUND) { + result = ISC_R_SUCCESS; + goto cleanup_db; + } + if (result != ISC_R_SUCCESS) + goto cleanup_db; + + result = dns_db_allrdatasets(cache->db, node, NULL, + (isc_stdtime_t)0, &iter); + if (result != ISC_R_SUCCESS) + goto cleanup_node; + + for (result = dns_rdatasetiter_first(iter); + result == ISC_R_SUCCESS; + result = dns_rdatasetiter_next(iter)) + { + dns_rdataset_t rdataset; + dns_rdataset_init(&rdataset); + + dns_rdatasetiter_current(iter, &rdataset); + + for (result = dns_rdataset_first(&rdataset); + result == ISC_R_SUCCESS; + result = dns_rdataset_next(&rdataset)) + { + dns_rdata_t rdata = DNS_RDATA_INIT; + dns_rdatatype_t covers; + + dns_rdataset_current(&rdataset, &rdata); + if (rdata.type == dns_rdatatype_sig) + covers = dns_rdata_covers(&rdata); + else + covers = 0; + result = dns_db_deleterdataset(cache->db, node, NULL, + rdata.type, covers); + if (result != ISC_R_SUCCESS && + result != DNS_R_UNCHANGED) + break; + } + dns_rdataset_disassociate(&rdataset); + if (result != ISC_R_NOMORE) + break; + } + if (result == ISC_R_NOMORE) + result = ISC_R_SUCCESS; + + dns_rdatasetiter_destroy(&iter); + + cleanup_node: + dns_db_detachnode(cache->db, &node); + + cleanup_db: + dns_db_detach(&db); + return (result); +} diff --git a/lib/dns/include/dns/cache.h b/lib/dns/include/dns/cache.h index 1b75cb666e..71e4e1e25d 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.17 2001/04/11 20:37:49 bwelling Exp $ */ +/* $Id: cache.h,v 1.18 2001/11/27 03:10:31 marka Exp $ */ #ifndef DNS_CACHE_H #define DNS_CACHE_H 1 @@ -235,6 +235,21 @@ dns_cache_flush(dns_cache_t *cache); * ISC_R_NOMEMORY */ +isc_result_t +dns_cache_flushname(dns_cache_t *cache, dns_name_t *name); +/* + * Flushes a given name from the cache. + * + * Requires: + * 'cache' to be valid. + * 'name' to be valid. + * + * Returns: + * ISC_R_SUCCESS + * ISC_R_NOMEMORY + * other error returns. + */ + ISC_LANG_ENDDECLS #endif /* DNS_CACHE_H */