From: W.C.A. Wijngaards Date: Fri, 26 Jun 2026 12:00:04 +0000 (+0200) Subject: - auth-load-thread, add services/authload.c and services/authload.h X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1578b6e180c5b18603a406ae4b69efb0df2fd5b2;p=thirdparty%2Funbound.git - auth-load-thread, add services/authload.c and services/authload.h --- diff --git a/services/authload.c b/services/authload.c new file mode 100644 index 000000000..37d099fe2 --- /dev/null +++ b/services/authload.c @@ -0,0 +1,54 @@ +/* + * services/authload.c - authoritative zone load thread + * + * Copyright (c) 2026, NLnet Labs. All rights reserved. + * + * This software is open source. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * Neither the name of the NLNET LABS nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED + * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/** + * \file + * + * This file contains the auth load thread. This loads authority zone + * and RPZ zone information in a thread, in a separate memory structure. + * When it is done, the information is swapped over to the running server. + */ + +#include "config.h" +#include "services/authload.h" + +int auth_load_add_task_xfr(struct auth_xfer* xfr, struct worker* worker) +{ + /* Check auth load count */ + + /* Create new thread */ + + /* Make wait item */ +} diff --git a/services/authload.h b/services/authload.h new file mode 100644 index 000000000..d842f77af --- /dev/null +++ b/services/authload.h @@ -0,0 +1,142 @@ +/* + * services/authload.h - authoritative zone load thread + * + * Copyright (c) 2026, NLnet Labs. All rights reserved. + * + * This software is open source. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * Neither the name of the NLNET LABS nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED + * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/** + * \file + * + * This file contains the auth load thread. This loads authority zone + * and RPZ zone information in a thread, in a separate memory structure. + * When it is done, the information is swapped over to the running server. + */ + +#ifndef SERVICES_AUTHLOAD_H +#define SERVICES_AUTHLOAD_H +#include "util/locks.h" +struct worker; +struct auth_xfer; +struct module_env; +struct auth_load_task; + +/** + * The auth load thread. The thread runs to load authority zone information + * and RPZ information into memory. It loads into a copy. Then that is swapped + * over to the running server. This keeps the server responsive while the + * information is loaded. + */ +struct auth_load_thread { + /** the thread number for the thread, + * must be first to cast thread arg to int* in checklock code. */ + int threadnum; + /** thread id, of the io thread */ + ub_thread_type tid; +#ifdef HAVE_GETTID + /** thread tid, the LWP id */ + pid_t thread_tid; + /** if logging should include the LWP id */ + int thread_tid_log; +#endif + + /** communication socket pair, that sends commands */ + int commpair[2]; + /** if the thread has to quit */ + int need_to_quit; + + /** the worker that the auth load is connected to */ + struct worker* worker; + + /** The task that the thread is working on */ + struct auth_load_task* task; +}; + +/** + * The types of tasks that the auth load can perform. + */ +enum auth_load_task_type { + AUTH_LOAD_TASK_TRANSFER, + AUTH_LOAD_TASK_ZONEFILE_READ, + AUTH_LOAD_TASK_ZONEFILE_WRITE, + AUTH_LOAD_TASK_CHUNKS +}; + +/** + * The task for the auth load. The task can be to load a zone transfer, AXFR, + * IXFR, from zonefile, and from a http read, from chunks. + */ +struct auth_load_task { + /** The type of the task */ + enum auth_load_task_type task_type; + /** The task is connected with this worker */ + struct worker* worker; + + /** The zone name */ + uint8_t* name; + /** The zone namelen */ + size_t namelen; + /** The zone class */ + uint16_t dclass; + + /** name of the host that the transfer comes from. */ + char* host; + /** file part of the url that the transfer comes from, or NULL. */ + char* file; + /** Set if the host is http transfer, if false it is AXFR or IXFR. */ + int on_http; + /** Set if the transfer is doing IXFR */ + int on_ixfr; + /** Set if the transfer is an IXFR but we detected an AXFR contents */ + int on_ixfr_is_axfr; + + /** current serial (from SOA), if we have no zone, 0 + * This is for checking the IXFR result. */ + uint32_t serial; + + /** the data chunks, or NULL, to process. */ + struct auth_chunk* chunks_first; + /** last data chunk */ + struct auth_chunk* chunks_last; + /** size of data in data chunks. */ + size_t chunks_total; +}; + +/** + * Add a new task to be performed by the auth load thread. + * It starts a thread, or makes a wait list item. + * @param xfr: zone transfer to start for. + * @param worker: worker that is connected to the task. + * @return false on failure. + */ +int auth_load_add_task_xfr(struct auth_xfer* xfr, struct worker* worker); + +#endif /* SERVICES_AUTHLOAD_H */ diff --git a/services/authzone.c b/services/authzone.c index 430674b0c..f91fb461e 100644 --- a/services/authzone.c +++ b/services/authzone.c @@ -60,6 +60,7 @@ #include "services/outside_network.h" #include "services/listen_dnsport.h" #include "services/mesh.h" +#include "services/authload.h" #include "sldns/rrdef.h" #include "sldns/pkthdr.h" #include "sldns/sbuffer.h" @@ -6282,7 +6283,14 @@ static void process_list_end_transfer(struct auth_xfer* xfr, struct module_env* env) { int ixfr_fail = 0; - if(xfr_process_chunk_list(xfr, env, &ixfr_fail)) { + if(1 /* auth load enabled: max-auth-load-threads > 0 */ ) { + /* Create auth load thread task to process the data. */ + if(auth_load_add_task_xfr(xfr, env->worker)) { + /* Task is created, wait for it to be done. The worker + * is signalled with the result. */ + return; + } + } else if(xfr_process_chunk_list(xfr, env, &ixfr_fail)) { /* it worked! */ auth_chunks_delete(xfr->task_transfer);