From 46e50e861f268bfacd45743d28007e939e0b372d Mon Sep 17 00:00:00 2001 From: Wouter Wijngaards Date: Mon, 22 Sep 2008 15:20:18 +0000 Subject: [PATCH] dump and load cache. git-svn-id: file:///svn/unbound/trunk@1263 be551aaa-1e26-0410-a405-d3ace91eadb9 --- daemon/remote.c | 21 ++++++++------------- daemon/remote.h | 27 +++++++++++++++++++++++++++ doc/Changelog | 5 +++++ doc/plan | 2 +- doc/unbound-control.8.in | 9 +++++++++ smallapp/unbound-control.c | 17 +++++++++++++++++ 6 files changed, 67 insertions(+), 14 deletions(-) diff --git a/daemon/remote.c b/daemon/remote.c index 870fec0a0..845527ae9 100644 --- a/daemon/remote.c +++ b/daemon/remote.c @@ -47,6 +47,7 @@ #include "daemon/worker.h" #include "daemon/daemon.h" #include "daemon/stats.h" +#include "daemon/cachedump.h" #include "util/log.h" #include "util/config_file.h" #include "util/net_help.h" @@ -431,8 +432,7 @@ clean_point(struct daemon_remote* rc, struct rc_state* s) free(s); } -/** print fixed line over the ssl connection */ -static int +int ssl_print_text(SSL* ssl, const char* text) { int r; @@ -458,16 +458,8 @@ ssl_print_vmsg(SSL* ssl, const char* format, va_list args) return ssl_print_text(ssl, msg); } -/** declare for printf format checking by gcc - * @param ssl: the SSL connection to print to. Blocking. - * @param format: printf style format string. - * @return success or false on a network failure. - */ -static int ssl_printf(SSL* ssl, const char* format, ...) - ATTR_FORMAT(printf, 2, 3); - /** printf style printing to the ssl connection */ -static int ssl_printf(SSL* ssl, const char* format, ...) +int ssl_printf(SSL* ssl, const char* format, ...) { va_list args; int ret; @@ -477,8 +469,7 @@ static int ssl_printf(SSL* ssl, const char* format, ...) return ret; } -/** read until \n */ -static int +int ssl_read_line(SSL* ssl, char* buf, size_t max) { int r; @@ -996,6 +987,10 @@ execute_cmd(struct daemon_remote* rc, SSL* ssl, char* cmd) do_data_remove(ssl, rc->worker, skipwhite(p+17)); } else if(strncmp(p, "local_data", 10) == 0) { do_data_add(ssl, rc->worker, skipwhite(p+10)); + } else if(strncmp(p, "dump_cache", 10) == 0) { + (void)dump_cache(ssl, rc->worker); + } else if(strncmp(p, "load_cache", 10) == 0) { + if(load_cache(ssl, rc->worker)) send_ok(ssl); } else { (void)ssl_printf(ssl, "error unknown command '%s'\n", p); } diff --git a/daemon/remote.h b/daemon/remote.h index fd16ffd93..ea30c803e 100644 --- a/daemon/remote.h +++ b/daemon/remote.h @@ -130,4 +130,31 @@ int remote_accept_callback(struct comm_point*, void*, int, struct comm_reply*); /** handle remote control data callbacks */ int remote_control_callback(struct comm_point*, void*, int, struct comm_reply*); +/** + * Print fixed line of text over ssl connection in blocking mode + * @param ssl: print to + * @param text: the text. + * @return false on connection failure. + */ +int ssl_print_text(SSL* ssl, const char* text); + +/** + * printf style printing to the ssl connection + * @param ssl: the SSL connection to print to. Blocking. + * @param format: printf style format string. + * @return success or false on a network failure. + */ +int ssl_printf(SSL* ssl, const char* format, ...) + ATTR_FORMAT(printf, 2, 3); + +/** + * Read until \n is encountered + * If SSL signals EOF, the string up to then is returned (without \n). + * @param ssl: the SSL connection to read from. blocking. + * @param buf: buffer to read to. + * @param max: size of buffer. + * @return false on connection failure. + */ +int ssl_read_line(SSL* ssl, char* buf, size_t max); + #endif /* DAEMON_REMOTE_H */ diff --git a/doc/Changelog b/doc/Changelog index 97b5eb18d..cadc87eb8 100644 --- a/doc/Changelog +++ b/doc/Changelog @@ -1,3 +1,8 @@ +22 September 2008: Wouter + - dump_cache and load_cache statements in unbound-control. + RRsets are dumped and loaded correctly. + Msg cache is dumped. + 19 September 2008: Wouter - locking on the localdata structure. - add and remove local zone and data with unbound-control. diff --git a/doc/plan b/doc/plan index 305a0860e..cd4cc0c61 100644 --- a/doc/plan +++ b/doc/plan @@ -53,7 +53,7 @@ like dnswall does. Allow certain subdomains to do it, config options. stats-file possible with key: value or key=value lines in it. addup stats over threads. not stats on SIGUSR1. perhaps also see which slow auth servers cause >1sec values. -* remote control to add/remove localinfo, redirects. ++ remote control to add/remove localinfo, redirects. * remote control to load/store cache contents + remote control to start, stop, reload. * remote control to flush names or domains (all under a name) from the diff --git a/doc/unbound-control.8.in b/doc/unbound-control.8.in index 0cecc5c81..85b5e8c4f 100644 --- a/doc/unbound-control.8.in +++ b/doc/unbound-control.8.in @@ -82,6 +82,15 @@ nothing happens. Often results in NXDOMAIN for the name (in a static zone), but if the name has become an empty nonterminal (there is still data in domain names below the removed name), NOERROR nodata answers are the result for that name. +.TP +.B dump_cache +The contents of the cache is printed in a text format to stdout. You can +redirect it to a file to store the cache in a file. +.TP +.B load_cache +The contents of the cache is loaded from stdin. Uses the same format as +dump_cache uses. Loading the cache with old, or wrong data can result +in old or wrong data returned to clients. .SH "EXIT CODE" The unbound-control program exits with status code 1 on error, 0 on success. .SH "SET UP" diff --git a/smallapp/unbound-control.c b/smallapp/unbound-control.c index 53964ff52..65fcbe682 100644 --- a/smallapp/unbound-control.c +++ b/smallapp/unbound-control.c @@ -68,6 +68,8 @@ usage() printf(" local_data [RR data...] add local data, for example\n"); printf(" local_data www.example.com A 192.0.2.1\n"); printf(" local_data_remove [name] remove local RR data from name\n"); + printf(" dump_cache print cache to stdout\n"); + printf(" load_cache load cache from stdin\n"); printf("Version %s\n", PACKAGE_VERSION); printf("BSD licensed, see LICENSE in source package for details.\n"); printf("Report bugs to %s\n", PACKAGE_BUGREPORT); @@ -197,6 +199,16 @@ setup_ssl(SSL_CTX* ctx, int fd) return ssl; } +/** send stdin to server */ +static void +send_file(SSL* ssl, FILE* in, char* buf, size_t sz) +{ + while(fgets(buf, sz, in)) { + if(SSL_write(ssl, buf, (int)strlen(buf)) <= 0) + ssl_err("could not SSL_write contents"); + } +} + /** send command and display result */ static int go_cmd(SSL* ssl, int argc, char* argv[]) @@ -217,6 +229,11 @@ go_cmd(SSL* ssl, int argc, char* argv[]) } if(SSL_write(ssl, newline, (int)strlen(newline)) <= 0) ssl_err("could not SSL_write"); + + if(argc == 1 && strcmp(argv[0], "load_cache") == 0) { + send_file(ssl, stdin, buf, sizeof(buf)); + } + while(1) { ERR_clear_error(); if((r = SSL_read(ssl, buf, (int)sizeof(buf)-1)) <= 0) {