#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"
free(s);
}
-/** print fixed line over the ssl connection */
-static int
+int
ssl_print_text(SSL* ssl, const char* text)
{
int r;
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;
return ret;
}
-/** read until \n */
-static int
+int
ssl_read_line(SSL* ssl, char* buf, size_t max)
{
int r;
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);
}
/** 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 */
+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.
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
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"
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);
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[])
}
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) {