Commit eb8713ed authored by Brian Wellington's avatar Brian Wellington
Browse files

Add support for the 'rndc dumpdb' command. Also add the 'cachefile'

option to the config file, which will be used for persistent cache
storage.
parent 31874cf8
......@@ -15,7 +15,7 @@
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/* $Id: server.h,v 1.47 2000/12/01 23:49:52 gson Exp $ */
/* $Id: server.h,v 1.48 2000/12/12 21:33:11 bwelling Exp $ */
#ifndef NAMED_SERVER_H
#define NAMED_SERVER_H 1
......@@ -71,6 +71,8 @@ struct ns_server {
char * statsfile; /* Statistics file name */
isc_uint64_t * querystats; /* Query statistics counters */
char * dumpfile; /* Dump file name */
};
#define NS_SERVER_MAGIC 0x53564552 /* SVER */
......@@ -125,9 +127,15 @@ ns_server_togglequerylog(ns_server_t *server);
*/
/*
* Dump the current statistics to the statstics file.
* Dump the current statistics to the statistics file.
*/
isc_result_t
ns_server_dumpstats(ns_server_t *server);
/*
* Dump the current cache to the dump file.
*/
isc_result_t
ns_server_dumpdb(ns_server_t *server);
#endif /* NAMED_SERVER_H */
......@@ -15,7 +15,7 @@
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/* $Id: omapi.c,v 1.26 2000/11/30 19:38:00 gson Exp $ */
/* $Id: omapi.c,v 1.27 2000/12/12 21:33:08 bwelling Exp $ */
/*
* Principal Author: DCL
......@@ -110,6 +110,10 @@ control_setvalue(omapi_object_t *handle, omapi_string_t *name,
result = ns_server_dumpstats(ns_g_server);
} else if (omapi_string_strcmp(name, NS_OMAPI_COMMAND_QUERYLOG) == 0) {
result = ns_server_togglequerylog(ns_g_server);
} else if (omapi_string_strcmp(name, NS_OMAPI_COMMAND_DUMPDB) == 0)
{
ns_server_dumpdb(ns_g_server);
result = ISC_R_SUCCESS;
} else {
isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,
NS_LOGMODULE_OMAPI, ISC_LOG_WARNING,
......
......@@ -15,7 +15,7 @@
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/* $Id: server.c,v 1.270 2000/12/06 01:21:04 tale Exp $ */
/* $Id: server.c,v 1.271 2000/12/12 21:33:10 bwelling Exp $ */
#include <config.h>
......@@ -43,6 +43,7 @@
#include <dns/journal.h>
#include <dns/keytable.h>
#include <dns/master.h>
#include <dns/masterdump.h>
#include <dns/peer.h>
#include <dns/rdataclass.h>
#include <dns/rdatastruct.h>
......@@ -712,6 +713,25 @@ 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;
}
result = ISC_R_SUCCESS;
......@@ -1326,6 +1346,21 @@ setstatsfile(ns_server_t *server, const char *name) {
return (ISC_R_SUCCESS);
}
static isc_result_t
setdumpfile(ns_server_t *server, const char *name) {
char *p;
REQUIRE(name != NULL);
p = isc_mem_strdup(server->mctx, name);
if (p == NULL)
return (ISC_R_NOMEMORY);
if (server->dumpfile != NULL)
isc_mem_free(server->mctx, server->dumpfile);
server->dumpfile = p;
return (ISC_R_SUCCESS);
}
#define SETLIMIT(cfgvar, resource, description) \
if (dns_c_ctx_get ## cfgvar(cctx, &resource) == ISC_R_SUCCESS) { \
if (resource == DNS_C_SIZE_SPEC_DEFAULT) \
......@@ -1376,6 +1411,7 @@ load_configuration(const char *filename, ns_server_t *server,
dns_dispatch_t *dispatchv6 = NULL;
char *pidfilename;
char *statsfilename;
char *dumpfilename;
isc_uint32_t interface_interval;
isc_uint32_t heartbeat_interval;
in_port_t listen_port;
......@@ -1748,6 +1784,13 @@ load_configuration(const char *filename, ns_server_t *server,
CHECKM(setstatsfile(server, statsfilename), "strdup");
}
result = dns_c_ctx_getdumpfilename(cctx, &dumpfilename);
if (result == ISC_R_NOTFOUND) {
CHECKM(setdumpfile(server, "named_dump.db"), "strdup");
} else {
CHECKM(setdumpfile(server, dumpfilename), "strdup");
}
cleanup:
ns_aclconfctx_destroy(&aclconfctx);
......@@ -1998,6 +2041,10 @@ ns_server_create(isc_mem_t *mctx, ns_server_t **serverp) {
CHECKFATAL(dns_stats_alloccounters(ns_g_mctx, &server->querystats),
"dns_stats_alloccounters");
server->dumpfile = isc_mem_strdup(server->mctx, "named.dump");
CHECKFATAL(server->dumpfile == NULL ? ISC_R_NOMEMORY : ISC_R_SUCCESS,
"isc_mem_strdup");
server->flushonshutdown = ISC_FALSE;
server->log_queries = ISC_FALSE;
......@@ -2013,6 +2060,8 @@ ns_server_destroy(ns_server_t **serverp) {
dns_stats_freecounters(server->mctx, &server->querystats);
isc_mem_free(server->mctx, server->statsfile);
isc_mem_free(server->mctx, server->dumpfile);
dns_loadmgr_detach(&server->loadmgr);
dns_zonemgr_detach(&server->zonemgr);
......@@ -2346,3 +2395,25 @@ ns_server_dumpstats(ns_server_t *server) {
(void)isc_stdio_close(fp);
return (result);
}
isc_result_t
ns_server_dumpdb(ns_server_t *server) {
FILE *fp = NULL;
dns_view_t *view;
isc_result_t result;
CHECKM(isc_stdio_open(server->dumpfile, "w", &fp),
"could not open dump file");
view = ISC_LIST_HEAD(server->viewlist);
while (view != NULL) {
if (view->cachedb != NULL)
CHECKM(dns_view_dumpcachetostream(view, fp),
"could not dump cache");
view = ISC_LIST_NEXT(view, link);
}
cleanup:
if (fp != NULL)
(void)isc_stdio_close(fp);
return (result);
}
......@@ -15,7 +15,7 @@
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/* $Id: rndc.c,v 1.35 2000/12/01 21:32:02 gson Exp $ */
/* $Id: rndc.c,v 1.36 2000/12/12 21:33:12 bwelling Exp $ */
/*
* Principal Author: DCL
......@@ -267,10 +267,10 @@ command is one of the following:\n\
Schedule immediate maintenance for a zone.\n\
stats Write server statistics to the statistics file.\n\
querylog Toggle query logging.\n\
dumpdb Dump cache to the dumpfile (named_dump.db).\n\
stop Save pending updates to master files and stop the server.\n\
halt Stop the server without saving pending updates.\n\
*status Display ps(1) status of named.\n\
*dumpdb Dump database and cache to /var/tmp/named_dump.db.\n\
*trace Increment debugging level by one.\n\
*notrace Set debugging level to 0.\n\
*restart Restart the server.\n\
......@@ -513,8 +513,7 @@ main(int argc, char **argv) {
notify(command);
if (strcmp(command, "dumpdb") == 0 ||
strcmp(command, "notrace") == 0 ||
if (strcmp(command, "notrace") == 0 ||
strcmp(command, "restart") == 0 ||
strcmp(command, "status") == 0 ||
strcmp(command, "trace") == 0) {
......
......@@ -15,7 +15,7 @@
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/* $Id: confctx.c,v 1.111 2000/12/07 01:45:53 brister Exp $ */
/* $Id: confctx.c,v 1.112 2000/12/12 21:33:15 bwelling Exp $ */
#include <config.h>
......@@ -349,12 +349,6 @@ dns_c_checkconfig(dns_c_ctx_t *cfg)
"option 'named-xfer' is obsolete");
}
if (dns_c_ctx_getdumpfilename(cfg, &cpval) != ISC_R_NOTFOUND) {
isc_log_write(dns_lctx, DNS_LOGCATEGORY_CONFIG,
DNS_LOGMODULE_CONFIG, ISC_LOG_WARNING,
"option 'dump-file' is not yet implemented");
}
if (dns_c_ctx_getmemstatsfilename(cfg, &cpval) != ISC_R_NOTFOUND) {
isc_log_write(dns_lctx, DNS_LOGCATEGORY_CONFIG,
DNS_LOGMODULE_CONFIG, ISC_LOG_WARNING,
......@@ -528,6 +522,16 @@ dns_c_checkconfig(dns_c_ctx_t *cfg)
}
}
if (dns_c_ctx_getcachefile(cfg, &cpval) == ISC_R_SUCCESS &&
cfg->views != NULL)
{
isc_log_write(dns_lctx, DNS_LOGCATEGORY_CONFIG,
DNS_LOGMODULE_CONFIG, ISC_LOG_WARNING,
"option 'cachefile' cannot be present if views "
"are present");
result = ISC_R_FAILURE;
}
return (result);
}
......@@ -976,6 +980,7 @@ dns_c_ctx_optionsprint(FILE *fp, int indent, dns_c_options_t *options)
PRINT_CHAR_P(pid_filename, "pid-file");
PRINT_CHAR_P(stats_filename, "statistics-file");
PRINT_CHAR_P(memstats_filename, "memstatistics-file");
PRINT_CHAR_P(cache_filename, "cache-file");
PRINT_CHAR_P(named_xfer, "named-xfer");
PRINT_CHAR_P(random_device, "random-device");
PRINT_CHAR_P(random_seed_file, "random-seed-file");
......@@ -1526,6 +1531,7 @@ dns_c_ctx_optionsnew(isc_mem_t *mem, dns_c_options_t **options)
opts->pid_filename = NULL;
opts->stats_filename = NULL;
opts->memstats_filename = NULL;
opts->cache_filename = NULL;
opts->named_xfer = NULL;
opts->random_device = NULL;
opts->random_seed_file = NULL;
......@@ -1682,6 +1688,7 @@ dns_c_ctx_optionsdelete(dns_c_options_t **opts)
FREESTRING(pid_filename);
FREESTRING(stats_filename);
FREESTRING(memstats_filename);
FREESTRING(cache_filename);
FREESTRING(named_xfer);
FREESTRING(random_device);
FREESTRING(random_seed_file);
......@@ -1829,6 +1836,7 @@ STRING_FUNCS(dumpfilename, dump_filename)
STRING_FUNCS(pidfilename, pid_filename)
STRING_FUNCS(statsfilename, stats_filename)
STRING_FUNCS(memstatsfilename, memstats_filename)
STRING_FUNCS(cachefile, cache_filename)
STRING_FUNCS(namedxfer, named_xfer)
STRING_FUNCS(randomdevice, random_device)
STRING_FUNCS(randomseedfile, random_seed_file)
......
......@@ -33,7 +33,7 @@
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/* $Id: confparser.y.dirty,v 1.41 2000/12/11 23:38:25 bwelling Exp $ */
/* $Id: confparser.y.dirty,v 1.42 2000/12/12 21:33:16 bwelling Exp $ */
#include <config.h>
......@@ -276,6 +276,7 @@ static isc_boolean_t int_too_big(isc_uint32_t base, isc_uint32_t mult);
%token L_BANG
%token L_BLACKHOLE
%token L_BOGUS
%token L_CACHE_FILE
%token L_CATEGORY
%token L_CHANNEL
%token L_CHECK_NAMES
......@@ -795,6 +796,21 @@ option: /* Empty */
isc_mem_free(memctx, $2);
}
| L_CACHE_FILE L_QSTRING
{
tmpres = dns_c_ctx_setcachefile(currcfg, $2);
if (tmpres == ISC_R_EXISTS) {
parser_error(ISC_FALSE,
"cannot redefine cache-file");
YYABORT;
} else if (tmpres != ISC_R_SUCCESS) {
parser_error(ISC_FALSE, "set cachefile error %s: %s",
isc_result_totext(tmpres), $2);
YYABORT;
}
isc_mem_free(memctx, $2);
}
| L_EXPERT_MODE yea_or_nay
{
tmpres = dns_c_ctx_setexpertmode(currcfg, $2);
......@@ -4612,6 +4628,25 @@ view_option: L_FORWARD zone_forward_opt
YYABORT;
}
}
| L_CACHE_FILE L_QSTRING
{
dns_c_view_t *view = dns_c_ctx_getcurrview(currcfg);
INSIST(view != NULL);
tmpres = dns_c_view_setcachefile(view, $2);
if (tmpres == ISC_R_EXISTS) {
parser_error(ISC_FALSE,
"cannot redefine cache-file");
YYABORT;
} else if (tmpres != ISC_R_SUCCESS) {
parser_error(ISC_FALSE, "set cachefile error %s: %s",
isc_result_totext(tmpres), $2);
YYABORT;
}
isc_mem_free(memctx, $2);
}
| key_stmt
| zone_stmt
| server_stmt
......@@ -6209,6 +6244,7 @@ static struct token keyword_tokens [] = {
{ "auth-nxdomain", L_AUTH_NXDOMAIN },
{ "blackhole", L_BLACKHOLE },
{ "bogus", L_BOGUS },
{ "cache-file", L_CACHE_FILE },
{ "category", L_CATEGORY },
{ "channel", L_CHANNEL },
{ "check-names", L_CHECK_NAMES },
......
......@@ -15,7 +15,7 @@
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/* $Id: confview.c,v 1.64 2000/12/07 01:45:55 brister Exp $ */
/* $Id: confview.c,v 1.65 2000/12/12 21:33:18 bwelling Exp $ */
#include <config.h>
......@@ -143,6 +143,8 @@ PVT_CONCAT(dns_c_view_unset, FUNCNAME)(dns_c_view_t *view) { \
} \
}
#define BYTYPE_FUNCS(TYPE, FUNC, FIELD) \
SETBYTYPE(TYPE, FUNC, FIELD) \
GETBYTYPE(TYPE, FUNC, FIELD) \
......@@ -210,6 +212,64 @@ PVT_CONCAT(dns_c_view_get, FUNCNAME)(dns_c_view_t *view, \
UNSETIPMLIST(FUNC, FIELD)
#define SETSTRING(FUNC, FIELD) \
isc_result_t \
PVT_CONCAT(dns_c_view_set, FUNC)(dns_c_view_t *view, const char *newval) \
{ \
char *p = NULL; \
\
REQUIRE(DNS_C_VIEW_VALID(view)); \
REQUIRE(newval != NULL); \
REQUIRE(*newval != '\0'); \
\
if (newval != NULL) { \
p = isc_mem_strdup(view->mem, newval); \
if (p == NULL) \
return (ISC_R_NOMEMORY); \
} \
if (view->FIELD != NULL) { \
isc_mem_free(view->mem, view->FIELD); \
view->FIELD = NULL; \
} \
view->FIELD = p; \
return (ISC_R_SUCCESS); \
}
#define GETSTRING(FUNC, FIELD) \
isc_result_t \
PVT_CONCAT(dns_c_view_get, FUNC)(dns_c_view_t *view, char **retval) \
{ \
REQUIRE(DNS_C_VIEW_VALID(view)); \
REQUIRE(retval != NULL); \
\
*retval = view->FIELD; \
\
return (*retval == NULL ? ISC_R_NOTFOUND : ISC_R_SUCCESS); \
}
#define UNSETSTRING(FUNC, FIELD) \
isc_result_t \
PVT_CONCAT(dns_c_view_unset, FUNC)(dns_c_view_t *view) \
{ \
REQUIRE(DNS_C_VIEW_VALID(view)); \
\
if (view->FIELD == NULL) { \
return (ISC_R_NOTFOUND); \
} \
\
isc_mem_free(view->mem, view->FIELD); \
view->FIELD = NULL; \
\
return (ISC_R_SUCCESS); \
}
#define STRING_FUNCS(FUNC, FIELD) \
SETSTRING(FUNC, FIELD) \
GETSTRING(FUNC, FIELD) \
UNSETSTRING(FUNC, FIELD)
isc_result_t
dns_c_viewtable_new(isc_mem_t *mem, dns_c_viewtable_t **viewtable) {
dns_c_viewtable_t *table;
......@@ -533,6 +593,8 @@ dns_c_view_new(isc_mem_t *mem, const char *name, dns_rdataclass_t viewclass,
view->trusted_keys = NULL;
view->cache_file = NULL;
#if 0
view->max_transfer_time_in = NULL;
view->max_transfer_idle_in = NULL;
......@@ -958,6 +1020,8 @@ dns_c_view_delete(dns_c_view_t **viewptr) {
dns_c_view_unsettrustedkeys(view);
dns_c_view_unsetcachefile(view);
#if 0
FREEFIELD(max_transfer_time_in);
FREEFIELD(max_transfer_idle_in);
......@@ -1578,6 +1642,8 @@ SOCKADDR_FUNCS(transfersourcev6, transfer_source_v6)
SOCKADDR_FUNCS(querysource, query_source)
SOCKADDR_FUNCS(querysourcev6, query_source_v6)
STRING_FUNCS(cachefile, cache_file)
UINT32_FUNCS(maxtransfertimeout, max_transfer_time_out)
UINT32_FUNCS(maxtransferidleout, max_transfer_idle_out)
UINT32_FUNCS(cleaninterval, clean_interval)
......
......@@ -15,7 +15,7 @@
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/* $Id: confctx.h,v 1.58 2000/11/25 02:43:52 marka Exp $ */
/* $Id: confctx.h,v 1.59 2000/12/12 21:33:19 bwelling Exp $ */
#ifndef DNS_CONFCTX_H
#define DNS_CONFCTX_H 1
......@@ -118,6 +118,7 @@ struct dns_c_options {
char *pid_filename;
char *stats_filename;
char *memstats_filename;
char *cache_filename;
char *named_xfer;
char *random_device;
char *random_seed_file;
......@@ -336,6 +337,11 @@ isc_result_t dns_c_ctx_getmemstatsfilename(dns_c_ctx_t *ctx, char **retval);
isc_result_t dns_c_ctx_unsetmemstatsfilename(dns_c_ctx_t *ctx);
isc_result_t dns_c_ctx_setcachefile(dns_c_ctx_t *ctx, const char *newval);
isc_result_t dns_c_ctx_getcachefile(dns_c_ctx_t *ctx, char **retval);
isc_result_t dns_c_ctx_unsetcachefile(dns_c_ctx_t *ctx);
isc_result_t dns_c_ctx_setnamedxfer(dns_c_ctx_t *ctx, const char *newval);
isc_result_t dns_c_ctx_getnamedxfer(dns_c_ctx_t *ctx, char **retval);
isc_result_t dns_c_ctx_unsetnamedxfer(dns_c_ctx_t *ctx);
......
......@@ -15,7 +15,7 @@
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/* $Id: confview.h,v 1.46 2000/12/01 23:27:43 marka Exp $ */
/* $Id: confview.h,v 1.47 2000/12/12 21:33:20 bwelling Exp $ */
#ifndef DNS_CONFVIEW_H
#define DNS_CONFVIEW_H 1
......@@ -167,6 +167,8 @@ struct dns_c_view {
dns_c_tkeylist_t *trusted_keys;
char *cache_file;
#if 0
/*
* To implement later.
......@@ -617,6 +619,12 @@ isc_result_t dns_c_view_settrustedkeys(dns_c_view_t *view,
dns_c_tkeylist_t *newval,
isc_boolean_t copy);
isc_result_t dns_c_view_getcachefile(dns_c_view_t *view,
char **cachefile);
isc_result_t dns_c_view_unsetcachefile(dns_c_view_t *view);
isc_result_t dns_c_view_setcachefile(dns_c_view_t *view,
const char *newval);
#if 0
......
......@@ -15,7 +15,7 @@
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/* $Id: view.h,v 1.56 2000/11/10 03:16:26 gson Exp $ */
/* $Id: view.h,v 1.57 2000/12/12 21:33:21 bwelling Exp $ */
#ifndef DNS_VIEW_H
#define DNS_VIEW_H 1
......@@ -112,6 +112,7 @@ struct dns_view {
dns_ttl_t maxcachettl;
dns_ttl_t maxncachettl;
in_port_t dstport;
char * cachefile;
/*
* Configurable data for server use only,
......@@ -626,6 +627,27 @@ 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);
isc_result_t
dns_view_dumpcachetostream(dns_view_t *view, FILE *fp);
/*
* Dump the cache to the specified cache file (if there is one) or stream.
*
* Requires:
*
* 'view' is valid.
*
* 'fp' is an open file.
*
* 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_LANG_ENDDECLS
#endif /* DNS_VIEW_H */
......@@ -15,7 +15,7 @@
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/* $Id: view.c,v 1.85 2000/11/10 03:16:20 gson Exp $ */
/* $Id: view.c,v 1.86 2000/12/12 21:33:14 bwelling Exp $ */
#include <config.h>
......@@ -31,6 +31,7 @@
#include <dns/forward.h>
#include <dns/keytable.h>
#include <dns/master.h>
#include <dns/masterdump.h>
#include <dns/peer.h>
#include <dns/rdataset.h>
#include <dns/request.h>
......@@ -162,6 +163,7 @@ 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)
......@@ -251,6 +253,8 @@ destroy(dns_view_t *view) {
dns_acl_detach(&view->recursionacl);
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);
......@@ -1052,3 +1056,23 @@ 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_dumpcachetostream(dns_view_t *view, FILE *fp) {
REQUIRE(DNS_VIEW_VALID(view));
return (dns_master_dumptostream(view->mctx, view->cachedb, NULL,
&dns_master_style_default, fp));
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment