summaryrefslogtreecommitdiffstats
path: root/contrib/bind9/lib/dns/cache.c
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/bind9/lib/dns/cache.c')
-rw-r--r--contrib/bind9/lib/dns/cache.c78
1 files changed, 75 insertions, 3 deletions
diff --git a/contrib/bind9/lib/dns/cache.c b/contrib/bind9/lib/dns/cache.c
index 28ead66..bf93da2 100644
--- a/contrib/bind9/lib/dns/cache.c
+++ b/contrib/bind9/lib/dns/cache.c
@@ -15,7 +15,7 @@
* PERFORMANCE OF THIS SOFTWARE.
*/
-/* $Id: cache.c,v 1.80.50.3 2009-05-06 23:34:30 jinmei Exp $ */
+/* $Id: cache.c,v 1.87 2009-11-12 23:43:02 each Exp $ */
/*! \file */
@@ -122,6 +122,7 @@ struct dns_cache {
isc_mutex_t lock;
isc_mutex_t filelock;
isc_mem_t *mctx;
+ char *name;
/* Locked by 'lock'. */
int references;
@@ -132,6 +133,7 @@ struct dns_cache {
char *db_type;
int db_argc;
char **db_argv;
+ isc_uint32_t size;
/* Locked by 'filelock'. */
char *filename;
@@ -171,6 +173,16 @@ dns_cache_create(isc_mem_t *mctx, isc_taskmgr_t *taskmgr,
const char *db_type, unsigned int db_argc, char **db_argv,
dns_cache_t **cachep)
{
+ return (dns_cache_create2(mctx, taskmgr, timermgr, rdclass, "",
+ db_type, db_argc, db_argv, cachep));
+}
+
+isc_result_t
+dns_cache_create2(isc_mem_t *mctx, isc_taskmgr_t *taskmgr,
+ isc_timermgr_t *timermgr, dns_rdataclass_t rdclass,
+ const char *cachename, const char *db_type,
+ unsigned int db_argc, char **db_argv, dns_cache_t **cachep)
+{
isc_result_t result;
dns_cache_t *cache;
int i;
@@ -179,6 +191,7 @@ dns_cache_create(isc_mem_t *mctx, isc_taskmgr_t *taskmgr,
REQUIRE(cachep != NULL);
REQUIRE(*cachep == NULL);
REQUIRE(mctx != NULL);
+ REQUIRE(cachename != NULL);
cache = isc_mem_get(mctx, sizeof(*cache));
if (cache == NULL)
@@ -187,6 +200,15 @@ dns_cache_create(isc_mem_t *mctx, isc_taskmgr_t *taskmgr,
cache->mctx = NULL;
isc_mem_attach(mctx, &cache->mctx);
+ cache->name = NULL;
+ if (cachename != NULL) {
+ cache->name = isc_mem_strdup(mctx, cachename);
+ if (cache->name == NULL) {
+ result = ISC_R_NOMEMORY;
+ goto cleanup_mem;
+ }
+ }
+
result = isc_mutex_init(&cache->lock);
if (result != ISC_R_SUCCESS)
goto cleanup_mem;
@@ -275,6 +297,8 @@ dns_cache_create(isc_mem_t *mctx, isc_taskmgr_t *taskmgr,
cleanup_lock:
DESTROYLOCK(&cache->lock);
cleanup_mem:
+ if (cache->name != NULL)
+ isc_mem_free(mctx, cache->name);
isc_mem_put(mctx, cache, sizeof(*cache));
isc_mem_detach(&mctx);
return (result);
@@ -323,6 +347,9 @@ cache_free(dns_cache_t *cache) {
if (cache->db_type != NULL)
isc_mem_free(cache->mctx, cache->db_type);
+ if (cache->name != NULL)
+ isc_mem_free(cache->mctx, cache->name);
+
DESTROYLOCK(&cache->lock);
DESTROYLOCK(&cache->filelock);
cache->magic = 0;
@@ -423,6 +450,7 @@ dns_cache_setfilename(dns_cache_t *cache, const char *filename) {
return (ISC_R_SUCCESS);
}
+#ifdef BIND9
isc_result_t
dns_cache_load(dns_cache_t *cache) {
isc_result_t result;
@@ -438,22 +466,29 @@ dns_cache_load(dns_cache_t *cache) {
return (result);
}
+#endif /* BIND9 */
isc_result_t
dns_cache_dump(dns_cache_t *cache) {
+#ifdef BIND9
isc_result_t result;
+#endif
REQUIRE(VALID_CACHE(cache));
if (cache->filename == NULL)
return (ISC_R_SUCCESS);
+#ifdef BIND9
LOCK(&cache->filelock);
result = dns_master_dump(cache->mctx, cache->db, NULL,
&dns_master_style_cache, cache->filename);
UNLOCK(&cache->filelock);
-
return (result);
+#else
+ return (ISC_R_NOTIMPLEMENTED);
+#endif
+
}
void
@@ -493,6 +528,26 @@ dns_cache_setcleaninginterval(dns_cache_t *cache, unsigned int t) {
UNLOCK(&cache->lock);
}
+unsigned int
+dns_cache_getcleaninginterval(dns_cache_t *cache) {
+ unsigned int t;
+
+ REQUIRE(VALID_CACHE(cache));
+
+ LOCK(&cache->lock);
+ t = cache->cleaner.cleaning_interval;
+ UNLOCK(&cache->lock);
+
+ return (t);
+}
+
+const char *
+dns_cache_getname(dns_cache_t *cache) {
+ REQUIRE(VALID_CACHE(cache));
+
+ return (cache->name);
+}
+
/*
* Initialize the cache cleaner object at *cleaner.
* Space for the object must be allocated by the caller.
@@ -519,6 +574,7 @@ cache_cleaner_init(dns_cache_t *cache, isc_taskmgr_t *taskmgr,
cleaner->cleaning_timer = NULL;
cleaner->resched_event = NULL;
cleaner->overmem_event = NULL;
+ cleaner->cleaning_interval = 0; /* Initially turned off. */
result = dns_db_createiterator(cleaner->cache->db, ISC_FALSE,
&cleaner->iterator);
@@ -547,7 +603,6 @@ cache_cleaner_init(dns_cache_t *cache, isc_taskmgr_t *taskmgr,
goto cleanup;
}
- cleaner->cleaning_interval = 0; /* Initially turned off. */
result = isc_timer_create(timermgr, isc_timertype_inactive,
NULL, NULL, cleaner->task,
cleaning_timer_action, cleaner,
@@ -949,6 +1004,10 @@ dns_cache_setcachesize(dns_cache_t *cache, isc_uint32_t size) {
if (size != 0 && size < DNS_CACHE_MINSIZE)
size = DNS_CACHE_MINSIZE;
+ LOCK(&cache->lock);
+ cache->size = size;
+ UNLOCK(&cache->lock);
+
hiwater = size - (size >> 3); /* Approximately 7/8ths. */
lowater = size - (size >> 2); /* Approximately 3/4ths. */
@@ -972,6 +1031,19 @@ dns_cache_setcachesize(dns_cache_t *cache, isc_uint32_t size) {
isc_mem_setwater(cache->mctx, water, cache, hiwater, lowater);
}
+isc_uint32_t
+dns_cache_getcachesize(dns_cache_t *cache) {
+ isc_uint32_t size;
+
+ REQUIRE(VALID_CACHE(cache));
+
+ LOCK(&cache->lock);
+ size = cache->size;
+ UNLOCK(&cache->lock);
+
+ return (size);
+}
+
/*
* The cleaner task is shutting down; do the necessary cleanup.
*/
OpenPOWER on IntegriCloud