]> git.ipfire.org Git - thirdparty/unbound.git/commitdiff
- fast-reload, make a thread to service the unbound-control command.
authorW.C.A. Wijngaards <wouter@nlnetlabs.nl>
Fri, 3 Nov 2023 10:44:22 +0000 (11:44 +0100)
committerW.C.A. Wijngaards <wouter@nlnetlabs.nl>
Fri, 3 Nov 2023 10:44:22 +0000 (11:44 +0100)
Makefile.in
daemon/daemon.c
daemon/daemon.h
daemon/remote.c
daemon/remote.h

index 22fb75c123bdacc72c3138a897d38eaa19b698ec..a1d98a97180e072858e59fb585a335dd747838ab 100644 (file)
@@ -1296,7 +1296,7 @@ remote.lo remote.o: $(srcdir)/daemon/remote.c config.h $(srcdir)/daemon/remote.h
  $(srcdir)/validator/val_anchor.h $(srcdir)/iterator/iterator.h $(srcdir)/services/outbound_list.h \
  $(srcdir)/iterator/iter_fwd.h $(srcdir)/iterator/iter_hints.h $(srcdir)/iterator/iter_delegpt.h \
  $(srcdir)/services/outside_network.h $(srcdir)/sldns/str2wire.h $(srcdir)/sldns/parseutil.h \
- $(srcdir)/sldns/wire2str.h
+ $(srcdir)/sldns/wire2str.h $(srcdir)/util/locks.h
 stats.lo stats.o: $(srcdir)/daemon/stats.c config.h $(srcdir)/daemon/stats.h $(srcdir)/util/timehist.h \
  $(srcdir)/libunbound/unbound.h $(srcdir)/daemon/worker.h $(srcdir)/libunbound/worker.h $(srcdir)/sldns/sbuffer.h \
  $(srcdir)/util/data/packed_rrset.h $(srcdir)/util/storage/lruhash.h $(srcdir)/util/locks.h $(srcdir)/util/log.h \
index 193608d40e0561e40620b6ad39129f467c18a2a1..186ae42f2ed5acd60a653a3256fdeef9a6a20396 100644 (file)
@@ -861,6 +861,8 @@ daemon_cleanup(struct daemon* daemon)
        dnsc_delete(daemon->dnscenv);
        daemon->dnscenv = NULL;
 #endif
+       if(daemon->fast_reload_thread)
+               fast_reload_thread_stop(daemon->fast_reload_thread);
        daemon->cfg = NULL;
 }
 
index 57665446d41b327f6cb677d773023f93e918562d..69e9a7280448da296e930ee2cf1ac17c1ca3892b 100644 (file)
@@ -58,6 +58,7 @@ struct ub_randstate;
 struct daemon_remote;
 struct respip_set;
 struct shm_main_info;
+struct fast_reload_thread;
 
 #include "dnstap/dnstap_config.h"
 #ifdef USE_DNSTAP
@@ -146,6 +147,8 @@ struct daemon {
 #endif
        /** reuse existing cache on reload if other conditions allow it. */
        int reuse_cache;
+       /** the fast reload thread, or NULL */
+       struct fast_reload_thread* fast_reload_thread;
 };
 
 /**
index 1ce9f2119e4a979de4d94809fcc77039f394e074..bdc4dd4f87dcf76fcd1abdf6fba85e089b367e8a 100644 (file)
@@ -658,7 +658,7 @@ do_fast_reload(RES* ssl, struct worker* worker)
 {
        if(!ssl_printf(ssl, "start fast_reload\n"))
                return;
-       (void)worker;
+       fast_reload_thread_start(ssl, worker);
 }
 
 /** do the verbosity command */
@@ -3369,3 +3369,69 @@ int remote_control_callback(struct comm_point* c, void* arg, int err,
        clean_point(rc, s);
        return 0;
 }
+
+#ifndef THREADS_DISABLED
+/** fast reload thread. the thread main function */
+static void* fast_reload_thread_main(void* arg)
+{
+       struct fast_reload_thread* frio = (struct fast_reload_thread*)arg;
+       log_thread_set(&frio->threadnum);
+
+       verbose(VERB_ALGO, "start fast reload thread");
+
+       verbose(VERB_ALGO, "stop fast reload thread");
+       return NULL;
+}
+#endif /* !THREADS_DISABLED */
+
+/** fast reload thread. setup the thread info */
+static int
+fast_reload_thread_setup(struct worker* worker)
+{
+       int numworkers = worker->daemon->num;
+       worker->daemon->fast_reload_thread = (struct fast_reload_thread*)
+               calloc(1, sizeof(*worker->daemon->fast_reload_thread));
+       if(!worker->daemon->fast_reload_thread)
+               return 0;
+       /* The thread id printed in logs, numworker+1 is the dnstap thread.
+        * This is numworkers+2. */
+       worker->daemon->fast_reload_thread->threadnum = numworkers+2;
+       return 1;
+}
+
+/** fast reload thread. desetup and delete the thread info. */
+static void
+fast_reload_thread_desetup(struct fast_reload_thread* fast_reload_thread)
+{
+       if(!fast_reload_thread)
+               return;
+       free(fast_reload_thread);
+}
+
+void
+fast_reload_thread_start(RES* ssl, struct worker* worker)
+{
+       if(worker->daemon->fast_reload_thread) {
+               log_err("fast reload thread already running");
+               return;
+       }
+       if(!fast_reload_thread_setup(worker)) {
+               if(!ssl_printf(ssl, "error could not setup thread\n"))
+                       return;
+               return;
+       }
+       worker->daemon->fast_reload_thread->started = 1;
+#ifndef THREADS_DISABLED
+       ub_thread_create(&worker->daemon->fast_reload_thread->tid,
+               fast_reload_thread_main, worker->daemon->fast_reload_thread);
+#else
+#endif
+}
+
+void
+fast_reload_thread_stop(struct fast_reload_thread* fast_reload_thread)
+{
+       if(!fast_reload_thread)
+               return;
+       fast_reload_thread_desetup(fast_reload_thread);
+}
index 4902803f5e42bef5a6a87dc43d86eaa13757adc2..cb80d4e84942b32133f3515b912b8ab1ed1a5f5c 100644 (file)
@@ -48,6 +48,7 @@
 #ifdef HAVE_OPENSSL_SSL_H
 #include <openssl/ssl.h>
 #endif
+#include "util/locks.h"
 struct config_file;
 struct listen_list;
 struct listen_port;
@@ -118,6 +119,21 @@ struct remote_stream {
 };
 typedef struct remote_stream RES;
 
+/**
+ * Fast reload thread structure
+ */
+struct fast_reload_thread {
+       /** the thread number for the dtio thread,
+        * must be first to cast thread arg to int* in checklock code. */
+       int threadnum;
+       /** event base, for event handling */
+       void* event_base;
+       /** thread id, of the io thread */
+       ub_thread_type tid;
+       /** if the io processing has started */
+       int started;
+};
+
 /**
  * Create new remote control state for the daemon.
  * @param cfg: config file with key file settings.
@@ -203,4 +219,17 @@ int ssl_printf(RES* ssl, const char* format, ...)
 int ssl_read_line(RES* ssl, char* buf, size_t max);
 #endif /* HAVE_SSL */
 
+/**
+ * Start fast reload thread
+ * @param ssl: the RES connection to print to.
+ * @param worker: the remote servicing worker.
+ */
+void fast_reload_thread_start(RES* ssl, struct worker* worker);
+
+/**
+ * Stop fast reload thread
+ * @param fast_reload_thread: the thread struct.
+ */
+void fast_reload_thread_stop(struct fast_reload_thread* fast_reload_thread);
+
 #endif /* DAEMON_REMOTE_H */