mirror of
https://gitlab.isc.org/isc-projects/bind9
synced 2025-08-29 13:38:26 +00:00
Fully implement the cachefile option, which allows persistent caching. This
removes some unused code in view.c and uncomments some code in cache.c. This still isn't really usable, since the trust level of cached data is not persistent, so all data in the persistent cache will be promoted to "ultimate" trust on reload.
This commit is contained in:
parent
619ee46ac6
commit
f0e246e271
@ -15,7 +15,7 @@
|
||||
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
/* $Id: server.c,v 1.280 2001/01/12 00:37:11 bwelling Exp $ */
|
||||
/* $Id: server.c,v 1.281 2001/01/12 22:22:14 bwelling Exp $ */
|
||||
|
||||
#include <config.h>
|
||||
|
||||
@ -417,6 +417,8 @@ configure_view(dns_view_t *view, dns_c_ctx_t *cctx, dns_c_view_t *cview,
|
||||
dns_dispatch_t *dispatch4 = NULL;
|
||||
dns_dispatch_t *dispatch6 = NULL;
|
||||
in_port_t port;
|
||||
isc_boolean_t reused_cache = ISC_FALSE;
|
||||
char *cachefile = NULL;
|
||||
|
||||
REQUIRE(DNS_VIEW_VALID(view));
|
||||
|
||||
@ -460,6 +462,7 @@ configure_view(dns_view_t *view, dns_c_ctx_t *cctx, dns_c_view_t *cview,
|
||||
isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,
|
||||
NS_LOGMODULE_SERVER, ISC_LOG_DEBUG(3),
|
||||
"reusing existing cache");
|
||||
reused_cache = ISC_TRUE;
|
||||
dns_cache_attach(pview->cache, &cache);
|
||||
dns_view_detach(&pview);
|
||||
} else {
|
||||
@ -469,6 +472,18 @@ configure_view(dns_view_t *view, dns_c_ctx_t *cctx, dns_c_view_t *cview,
|
||||
}
|
||||
dns_view_setcache(view, cache);
|
||||
|
||||
if (cview != NULL)
|
||||
result = dns_c_view_getcachefile(cview, &cachefile);
|
||||
else
|
||||
result = dns_c_ctx_getcachefile(cctx, &cachefile);
|
||||
if (result != ISC_R_SUCCESS && result != ISC_R_NOTFOUND)
|
||||
goto cleanup;
|
||||
if (cachefile != NULL) {
|
||||
dns_cache_setfilename(cache, cachefile);
|
||||
if (!reused_cache)
|
||||
CHECK(dns_cache_load(cache));
|
||||
}
|
||||
|
||||
result = ISC_R_NOTFOUND;
|
||||
if (cview != NULL)
|
||||
result = dns_c_view_getcleaninterval(cview,
|
||||
@ -706,32 +721,6 @@ configure_view(dns_view_t *view, dns_c_ctx_t *cctx, dns_c_view_t *cview,
|
||||
val = 7 * 24 * 3600;
|
||||
view->maxncachettl = val;
|
||||
}
|
||||
{
|
||||
char *cachefile = NULL, *p = NULL;
|
||||
if (cview != NULL)
|
||||
result = dns_c_view_getcachefile(cview, &cachefile);
|
||||
else
|
||||
result = dns_c_ctx_getcachefile(cctx, &cachefile);
|
||||
if (result != ISC_R_SUCCESS && result != ISC_R_NOTFOUND)
|
||||
goto cleanup;
|
||||
if (cachefile != NULL) {
|
||||
p = isc_mem_strdup(view->mctx, cachefile);
|
||||
if (p == NULL) {
|
||||
result = ISC_R_NOMEMORY;
|
||||
goto cleanup;
|
||||
}
|
||||
}
|
||||
if (view->cachefile != NULL)
|
||||
isc_mem_free(view->mctx, view->cachefile);
|
||||
view->cachefile = p;
|
||||
if (view->cachefile != NULL) {
|
||||
isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,
|
||||
NS_LOGMODULE_SERVER, ISC_LOG_DEBUG(1),
|
||||
"loading cache '%s'", view->cachefile);
|
||||
/* DNS_R_SEENINCLUDE should be impossible here. */
|
||||
CHECK(dns_db_load(view->cachedb, view->cachefile));
|
||||
}
|
||||
}
|
||||
|
||||
result = ISC_R_SUCCESS;
|
||||
|
||||
|
@ -15,7 +15,7 @@
|
||||
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
/* $Id: cache.c,v 1.32 2001/01/09 21:50:40 bwelling Exp $ */
|
||||
/* $Id: cache.c,v 1.33 2001/01/12 22:22:15 bwelling Exp $ */
|
||||
|
||||
#include <config.h>
|
||||
|
||||
@ -30,6 +30,7 @@
|
||||
#include <dns/dbiterator.h>
|
||||
#include <dns/events.h>
|
||||
#include <dns/log.h>
|
||||
#include <dns/masterdump.h>
|
||||
#include <dns/result.h>
|
||||
|
||||
#define CACHE_MAGIC 0x24242424U /* $$$$. */
|
||||
@ -151,6 +152,15 @@ dns_cache_create(isc_mem_t *mctx, isc_taskmgr_t *taskmgr,
|
||||
goto cleanup_mem;
|
||||
}
|
||||
|
||||
result = isc_mutex_init(&cache->filelock);
|
||||
if (result != ISC_R_SUCCESS) {
|
||||
UNEXPECTED_ERROR(__FILE__, __LINE__,
|
||||
"isc_mutex_init() failed: %s",
|
||||
dns_result_totext(result));
|
||||
result = ISC_R_UNEXPECTED;
|
||||
goto cleanup_lock;
|
||||
}
|
||||
|
||||
cache->references = 1;
|
||||
cache->live_tasks = 0;
|
||||
cache->rdclass = rdclass;
|
||||
@ -160,7 +170,7 @@ dns_cache_create(isc_mem_t *mctx, isc_taskmgr_t *taskmgr,
|
||||
dns_dbtype_cache, rdclass, db_argc, db_argv,
|
||||
&cache->db);
|
||||
if (result != ISC_R_SUCCESS)
|
||||
goto cleanup_mutex;
|
||||
goto cleanup_filelock;
|
||||
|
||||
cache->filename = NULL;
|
||||
|
||||
@ -176,7 +186,9 @@ dns_cache_create(isc_mem_t *mctx, isc_taskmgr_t *taskmgr,
|
||||
|
||||
cleanup_db:
|
||||
dns_db_detach(&cache->db);
|
||||
cleanup_mutex:
|
||||
cleanup_filelock:
|
||||
DESTROYLOCK(&cache->filelock);
|
||||
cleanup_lock:
|
||||
DESTROYLOCK(&cache->lock);
|
||||
cleanup_mem:
|
||||
isc_mem_put(mctx, cache, sizeof *cache);
|
||||
@ -214,6 +226,7 @@ cache_free(dns_cache_t *cache) {
|
||||
dns_db_detach(&cache->db);
|
||||
|
||||
DESTROYLOCK(&cache->lock);
|
||||
DESTROYLOCK(&cache->filelock);
|
||||
cache->magic = 0;
|
||||
mctx = cache->mctx;
|
||||
isc_mem_put(cache->mctx, cache, sizeof *cache);
|
||||
@ -253,6 +266,12 @@ dns_cache_detach(dns_cache_t **cachep) {
|
||||
UNLOCK(&cache->lock);
|
||||
*cachep = NULL;
|
||||
if (free_cache) {
|
||||
/*
|
||||
* When the cache is shut down, dump it to a file if one is
|
||||
* specified.
|
||||
*/
|
||||
dns_cache_dump(cache);
|
||||
|
||||
/* XXXRTH This is not locked! */
|
||||
if (cache->live_tasks > 0)
|
||||
isc_task_shutdown(cache->cleaner.task);
|
||||
@ -271,12 +290,14 @@ dns_cache_attachdb(dns_cache_t *cache, dns_db_t **dbp) {
|
||||
UNLOCK(&cache->lock);
|
||||
}
|
||||
|
||||
#ifdef NOTYET
|
||||
|
||||
/* ARGSUSED */
|
||||
isc_result_t
|
||||
dns_cache_setfilename(dns_cache_t *cahce, char *filename) {
|
||||
char *newname = isc_mem_strdup(filename);
|
||||
dns_cache_setfilename(dns_cache_t *cache, char *filename) {
|
||||
char *newname;
|
||||
|
||||
REQUIRE(VALID_CACHE(cache));
|
||||
REQUIRE(filename != NULL);
|
||||
|
||||
newname = isc_mem_strdup(cache->mctx, filename);
|
||||
if (newname == NULL)
|
||||
return (ISC_R_NOMEMORY);
|
||||
LOCK(&cache->filelock);
|
||||
@ -290,10 +311,12 @@ dns_cache_setfilename(dns_cache_t *cahce, char *filename) {
|
||||
isc_result_t
|
||||
dns_cache_load(dns_cache_t *cache) {
|
||||
isc_result_t result;
|
||||
|
||||
REQUIRE(VALID_CACHE(cache));
|
||||
|
||||
if (cache->filename == NULL)
|
||||
return (ISC_R_SUCCESS);
|
||||
LOCK(&cache->filelock);
|
||||
/* XXX handle TTLs in a way appropriate for the cache */
|
||||
result = dns_db_load(cache->db, cache->filename);
|
||||
UNLOCK(&cache->filelock);
|
||||
return (result);
|
||||
@ -301,11 +324,18 @@ dns_cache_load(dns_cache_t *cache) {
|
||||
|
||||
isc_result_t
|
||||
dns_cache_dump(dns_cache_t *cache) {
|
||||
/* XXX to be written */
|
||||
return (ISC_R_NOTIMPLEMENTED);
|
||||
}
|
||||
isc_result_t result;
|
||||
|
||||
#endif
|
||||
REQUIRE(VALID_CACHE(cache));
|
||||
|
||||
LOCK(&cache->filelock);
|
||||
if (cache->filename == NULL)
|
||||
return (ISC_R_SUCCESS);
|
||||
result = dns_master_dump(cache->mctx, cache->db, NULL,
|
||||
&dns_master_style_cache, cache->filename);
|
||||
UNLOCK(&cache->filelock);
|
||||
return (result);
|
||||
}
|
||||
|
||||
void
|
||||
dns_cache_setcleaninginterval(dns_cache_t *cache, unsigned int t) {
|
||||
|
@ -15,7 +15,7 @@
|
||||
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
/* $Id: view.h,v 1.63 2001/01/09 21:53:40 bwelling Exp $ */
|
||||
/* $Id: view.h,v 1.64 2001/01/12 22:22:17 bwelling Exp $ */
|
||||
|
||||
#ifndef DNS_VIEW_H
|
||||
#define DNS_VIEW_H 1
|
||||
@ -115,7 +115,6 @@ struct dns_view {
|
||||
dns_ttl_t maxcachettl;
|
||||
dns_ttl_t maxncachettl;
|
||||
in_port_t dstport;
|
||||
char * cachefile;
|
||||
|
||||
/*
|
||||
* Configurable data for server use only,
|
||||
@ -644,21 +643,6 @@ dns_view_dialup(dns_view_t *view);
|
||||
* Perform dialup-time maintenance on the zones of 'view'.
|
||||
*/
|
||||
|
||||
isc_result_t
|
||||
dns_view_dumpcache(dns_view_t *view);
|
||||
/*
|
||||
* Dump the view's cache to the the view's cache file.
|
||||
*
|
||||
* Requires:
|
||||
*
|
||||
* 'view' is valid.
|
||||
*
|
||||
* Returns:
|
||||
* ISC_R_SUCCESS The cache was successfully dumped.
|
||||
* ISC_R_IGNORE No cachefile was specified.
|
||||
* others An error occurred (see dns_master_dump)
|
||||
*/
|
||||
|
||||
isc_result_t
|
||||
dns_view_dumpdbtostream(dns_view_t *view, FILE *fp);
|
||||
/*
|
||||
@ -678,7 +662,6 @@ dns_view_dumpdbtostream(dns_view_t *view, FILE *fp);
|
||||
*
|
||||
* Returns:
|
||||
* ISC_R_SUCCESS The cache was successfully dumped.
|
||||
* ISC_R_IGNORE No cachefile was specified.
|
||||
* others An error occurred (see dns_master_dump)
|
||||
*/
|
||||
|
||||
|
@ -15,7 +15,7 @@
|
||||
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
/* $Id: view.c,v 1.91 2001/01/09 21:51:44 bwelling Exp $ */
|
||||
/* $Id: view.c,v 1.92 2001/01/12 22:22:16 bwelling Exp $ */
|
||||
|
||||
#include <config.h>
|
||||
|
||||
@ -164,7 +164,6 @@ dns_view_create(isc_mem_t *mctx, dns_rdataclass_t rdclass,
|
||||
view->maxcachettl = 7 * 24 * 3600;
|
||||
view->maxncachettl = 3 * 3600;
|
||||
view->dstport = 53;
|
||||
view->cachefile = NULL;
|
||||
|
||||
result = dns_peerlist_new(view->mctx, &view->peers);
|
||||
if (result != ISC_R_SUCCESS)
|
||||
@ -256,8 +255,6 @@ destroy(dns_view_t *view) {
|
||||
dns_acl_detach(&view->v6synthesisacl);
|
||||
if (view->sortlist != NULL)
|
||||
dns_acl_detach(&view->sortlist);
|
||||
if (view->cachefile != NULL)
|
||||
isc_mem_free(view->mctx, view->cachefile);
|
||||
dns_keytable_detach(&view->trustedkeys);
|
||||
dns_keytable_detach(&view->secroots);
|
||||
dns_fwdtable_destroy(&view->fwdtable);
|
||||
@ -1100,17 +1097,6 @@ dns_view_checksig(dns_view_t *view, isc_buffer_t *source, dns_message_t *msg) {
|
||||
view->dynamickeys));
|
||||
}
|
||||
|
||||
isc_result_t
|
||||
dns_view_dumpcache(dns_view_t *view) {
|
||||
REQUIRE(DNS_VIEW_VALID(view));
|
||||
|
||||
if (view->cachefile == NULL)
|
||||
return (ISC_R_IGNORE);
|
||||
return (dns_master_dump(view->mctx, view->cachedb, NULL,
|
||||
&dns_master_style_default, view->cachefile));
|
||||
|
||||
}
|
||||
|
||||
isc_result_t
|
||||
dns_view_dumpdbtostream(dns_view_t *view, FILE *fp) {
|
||||
isc_result_t result;
|
||||
@ -1119,7 +1105,7 @@ dns_view_dumpdbtostream(dns_view_t *view, FILE *fp) {
|
||||
|
||||
(void)fprintf(fp, ";\n; Cache dump of view '%s'\n;\n", view->name);
|
||||
result = dns_master_dumptostream(view->mctx, view->cachedb, NULL,
|
||||
&dns_master_style_explicitttl, fp);
|
||||
&dns_master_style_cache, fp);
|
||||
if (result != ISC_R_SUCCESS)
|
||||
return (result);
|
||||
#ifdef notyet /* clean up adb dump format first */
|
||||
|
Loading…
x
Reference in New Issue
Block a user