2007-06-21 11:36:13 -04:00
|
|
|
/*
|
|
|
|
|
* services/mesh.c - deal with mesh of query states and handle events for that.
|
|
|
|
|
*
|
|
|
|
|
* Copyright (c) 2007, NLnet Labs. All rights reserved.
|
|
|
|
|
*
|
|
|
|
|
* This software is open source.
|
2023-04-20 11:39:55 -04:00
|
|
|
*
|
2007-06-21 11:36:13 -04:00
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
|
* are met:
|
2023-04-20 11:39:55 -04:00
|
|
|
*
|
2007-06-21 11:36:13 -04:00
|
|
|
* Redistributions of source code must retain the above copyright notice,
|
|
|
|
|
* this list of conditions and the following disclaimer.
|
2023-04-20 11:39:55 -04:00
|
|
|
*
|
2007-06-21 11:36:13 -04:00
|
|
|
* 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.
|
2023-04-20 11:39:55 -04:00
|
|
|
*
|
2007-06-21 11:36:13 -04:00
|
|
|
* 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.
|
2023-04-20 11:39:55 -04:00
|
|
|
*
|
2007-06-21 11:36:13 -04:00
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
2014-02-07 08:28:39 -05:00
|
|
|
* "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.
|
2007-06-21 11:36:13 -04:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* \file
|
|
|
|
|
*
|
|
|
|
|
* This file contains functions to assist in dealing with a mesh of
|
|
|
|
|
* query states. This mesh is supposed to be thread-specific.
|
|
|
|
|
* It consists of query states (per qname, qtype, qclass) and connections
|
|
|
|
|
* between query states and the super and subquery states, and replies to
|
|
|
|
|
* send back to clients.
|
|
|
|
|
*/
|
|
|
|
|
#include "config.h"
|
|
|
|
|
#include "services/mesh.h"
|
2007-06-25 09:54:03 -04:00
|
|
|
#include "services/outbound_list.h"
|
2007-08-02 04:07:50 -04:00
|
|
|
#include "services/cache/dns.h"
|
2020-02-05 08:20:27 -05:00
|
|
|
#include "services/cache/rrset.h"
|
2024-05-01 04:10:58 -04:00
|
|
|
#include "services/cache/infra.h"
|
2007-06-22 06:09:21 -04:00
|
|
|
#include "util/log.h"
|
|
|
|
|
#include "util/net_help.h"
|
|
|
|
|
#include "util/module.h"
|
2007-10-18 16:31:43 -04:00
|
|
|
#include "util/regional.h"
|
2007-06-25 09:54:03 -04:00
|
|
|
#include "util/data/msgencode.h"
|
2007-06-27 10:59:44 -04:00
|
|
|
#include "util/timehist.h"
|
2007-10-05 08:42:25 -04:00
|
|
|
#include "util/fptr_wlist.h"
|
2007-10-18 18:17:02 -04:00
|
|
|
#include "util/alloc.h"
|
2008-09-02 09:04:47 -04:00
|
|
|
#include "util/config_file.h"
|
2018-07-31 03:18:34 -04:00
|
|
|
#include "util/edns.h"
|
2015-03-26 06:21:38 -04:00
|
|
|
#include "sldns/sbuffer.h"
|
2016-12-06 08:42:51 -05:00
|
|
|
#include "sldns/wire2str.h"
|
2016-10-18 09:18:20 -04:00
|
|
|
#include "services/localzone.h"
|
|
|
|
|
#include "util/data/dname.h"
|
2017-03-07 09:58:51 -05:00
|
|
|
#include "respip/respip.h"
|
2019-01-11 09:12:27 -05:00
|
|
|
#include "services/listen_dnsport.h"
|
2023-04-18 09:50:12 -04:00
|
|
|
#include "util/timeval_func.h"
|
2008-09-02 09:04:47 -04:00
|
|
|
|
2021-02-17 07:39:15 -05:00
|
|
|
#ifdef CLIENT_SUBNET
|
|
|
|
|
#include "edns-subnet/subnetmod.h"
|
|
|
|
|
#include "edns-subnet/edns-subnet.h"
|
|
|
|
|
#endif
|
2023-12-05 04:05:51 -05:00
|
|
|
#ifdef HAVE_SYS_TYPES_H
|
|
|
|
|
# include <sys/types.h>
|
|
|
|
|
#endif
|
|
|
|
|
#ifdef HAVE_NETDB_H
|
|
|
|
|
#include <netdb.h>
|
|
|
|
|
#endif
|
2021-02-17 07:39:15 -05:00
|
|
|
|
Fast Reload Option (#1042)
* - fast-reload, add unbound-control fast_reload
* - fast-reload, make a thread to service the unbound-control command.
* - fast-reload, communication sockets for information transfer.
* - fast-reload, fix compile for unbound-dnstap-socket.
* - fast-reload, set nonblocking communication to keep the server thread
responding to DNS requests.
* - fast-reload, poll routine to test for readiness, timeout fails connection.
* - fast-reload, detect loop in sock_poll_timeout routine.
* - fast-reload, send done and exited notification.
* - fast-reload, defines for constants in ipc.
* - fast-reload, ipc socket recv and send resists partial reads and writes and
can continue byte by byte. Also it can continue after an interrupt.
* - fast-reload, send exit command to thread when done.
* - fast-reload, output strings for client on string list.
* - fast-reload, add newline to terminal output.
* - fast-reload, send client string to remote client.
* - fast-reload, better debug output.
* - fast-reload, print queue structure, for output to the remote client.
* - fast-reload, move print items to print queue from fast_reload_thread struct.
* - fast-reload, keep list of pending print queue items in daemon struct.
* - fast-reload, comment explains in_list for printq to print remainder.
* - fast-reload, unit test testdata/fast_reload_thread.tdir that tests the
thread output.
* - fast-reload, fix test link for fast_reload_printq_list_delete function.
* - fast-reload, reread config file from disk.
* - fast-reload, unshare forwards, making the structure locked, with an rwlock.
* - fast-reload, for nonthreaded, the unbound-control commands forward,
forward_add and forward_delete should be distributed to other processes,
but when threaded, they should not be distributed to other threads because
the structure is not thread specific any more.
* - fast-reload, unshared stub hints, making the structure locked, with an rwlock.
* - fast-reload, helpful comments for hints lookup function return value.
* - fast-reload, fix bug in fast reload printout, the strlist appendlist routine,
and printout time statistics after the reload is done.
* - fast-reload, keep track of reloadtime and deletestime and print them.
* - fast-reload, keep track of constructtime and print it.
* - fast-reload, construct new items.
* - fast-reload, better comment.
* - fast-reload, reload the config and swap trees for forwards and stub hints.
* - fast-reload, in forwards_swap_tree set protection of trees with locks.
* - fast-reload, in hints_swap_tree also swap the node count of the trees.
* - fast-reload, reload ipc to stop and start threads.
* - fast-reload, unused forward declarations removed.
* - fast-reload, unit test that fast reload works with forwards and stubs.
* - fast-reload, fix clang analyzer warnings.
* - fast-reload, small documentation entry in unbound-control -h output.
* - fast-reload, printout memory use by fast reload, in bytes.
* - fast-reload, compile without threads.
* - fast-reload, document fast_reload in man page.
* - fast-reload, print ok when done successfully.
* - fast-reload, option for fast-reload commandline, +v verbosity option,
with timing and memory use output.
* - fast-reload, option for fast-reload commandline, +p does not pause threads.
* - fast-reload, option for fast-reload commandline, +d drops mesh queries.
* - fast-reload, fix to poll every thread with nopause to make certain that
resources are not held by the threads and can be deleted.
* - fast-reload, fix to use atomic store for config variables with nopause.
* - fast-reload, reload views.
* - fast-reload, when tag defines are different, it drops the queries.
* - fast-reload, fix tag define check.
* - fast-reload, document that tag change causes drop of queries.
* - fast-reload, fix space in documentation man page.
* - fast-reload, copy respip client information to query state, put views tree
in module env for lookup.
* - fast-reload, nicer respip view comparison.
* - fast-reload, respip global set is in module env.
* - fast-reload, document that respip_client_info acl info is copied.
* - fast-reload, reload the respip_set.
* - fast-reload, document no pause and pick up of use_response_ip boolean.
* - fast-reload, fix test compile.
* - fast-reload, reload local zones.
* Update locking management for iter_fwd and iter_hints methods. (#1054)
fast reload, move most of the locking management to iter_fwd and
iter_hints methods. The caller still has the ability to handle its
own locking, if desired, for atomic operations on sets of different
structs.
Co-authored-by: Wouter Wijngaards <wcawijngaards@users.noreply.github.com>
* - fast-reload, reload access-control.
* - fast-reload, reload access control interface, such as interface-action.
* - fast-reload, reload tcp-connection-limit.
* - fast-reload, improve comments on acl_list and tcl_list swap tree.
* - fast-reload, fixup references to old tcp connection limits in open tcp
connections.
* - fast-reload, fixup to clean tcp connection also for different linked order.
* - fast-reload, if no tcp connection limits existed, no need to remove
references for that.
* - fast-reload, document more options that work and do not work.
* - fast-reload, reload auth_zone and rpz data.
* - fast-reload, fix auth_zones_get_mem.
* - fast-reload, fix compilation of testbound for the new comm_timer_get_mem
reference in remote control.
* - fast-reload, change use_rpz with reload.
* - fast-reload, list changes in auth zones and stop zonemd callbacks for
deleted auth zones.
* - fast-reload, note xtree is not swapped, and why it is not swapped.
* - fast-reload, for added auth zones, pick up zone transfer and zonemd tasks.
* - fast-reload, unlock xfr when done with transfer pick up.
* - fast-reload, unlock z when picking up the xfr for it during transfer task
pick up.
* - fast-reload, pick up task changes for added, deleted and modified auth zones.
* - fast-reload, remove xfr of auth zone deletion without tasks.
* - fast-reload, pick up zone transfer config.
* - fast-reload, the main worker thread picks up the transfer tasks and also
performs setup of the xfer struct.
* - fast-reload, keep writelock on newzone when auth zone changes.
* - fast-reload, change cachedb_enabled setting.
* - fast-reload, pick up edns-strings config.
* - fast-reload, note that settings are not updated.
* - fast-reload, pick up dnstap config.
* - fast-reload, dnstap options that need to be loaded without +p.
* - fast-reload, fix auth zone reload
* - fast-reload, remove debug for auth zone test.
* - fast-reload, fix auth zone reload with zone transfer.
* - fast-reload, fix auth zone reload lock order.
* - fast-reload, remove debug from fast reload test.
* - fast-reload, remove unused function.
* - fast-reload, fix the worker trust anchor probe timer lock acquisition in
the probe answer callback routine for trust anchor probes.
* - fast-reload, reload trust anchors.
* - fast-reload, fix trust anchor reload lock on autr global data and test
for trust anchor reload.
* - fast-reload, adjust cache sizes.
* - fast-reload, reload cache sizes when changed.
* - fast-reload, reload validator env changes.
* - fast-reload, reload mesh changes.
* - fast-reload, check for incompatible changes.
* - fast-reload, improve error text for incompatible change.
* - fast-reload, fix check config option compatibility.
* - fast-reload, improve error text for nopause change.
* - fast-reload, fix spelling of incompatible options.
* - fast-reload, reload target-fetch-policy, outbound-msg-retry, max-sent-count
and max-query-restarts.
* - fast-reload, check nopause config change for target-fetch-policy.
* - fast-reload, reload do-not-query-address, private-address and capt-exempt.
* - fast-reload, check nopause config change for do-not-query-address,
private-address and capt-exempt.
* - fast-reload, check fast reload not possible due to interface and
outgoing-interface changes.
* - fast-reload, reload nat64 settings.
* - fast-reload, reload settings stored in the infra structure.
* - fast-reload, fix modstack lookup and remove outgoing-range check.
* - fast-reload, more explanation for config parse failure.
* - fast-reload, reload worker outside network changes.
* - fast-reload, detect incompatible changes in network settings.
* fast-reload, commit test files.
* - fast-reload, fix warnings for call types in windows compile.
* - fast-reload, fix warnings and comm_point_internal for tcp wouldblock calls.
* - fast-reload, extend lock checks for repeat thread ids.
* - fast-reload, additional test cases, cache change and tag changes.
* - fast-reload, fix documentation for auth_zone_verify_zonemd_with_key.
* - fast-reload, fix copy_cfg type casts and memory leak on config parse failure.
* - fast-reload, fix use of WSAPoll.
* Review comments for the fast reload feature (#1259)
* - fast-reload review, respip set can be null from a view.
* - fast-reload review, typos.
* - fast-reload review, keep clang static analyzer happy.
* - fast-reload review, don't forget to copy tag_actions.
* - fast-reload review, less indentation.
* - fast-reload review, don't leak respip_actions when reloading.
* - fast-reload review, protect NULL pointer dereference in get_mem
functions.
* - fast-reload review, add fast_reload_most_options.tdir to test most
options with high verbosity when fast reloading.
* - fast-reload review, don't skip new line on long error printouts.
* - fast-reload review, typo.
* - fast-reload review, use new_z for consistency.
* - fast-reload review, nit for unlock ordering to make eye comparison
with the lock counterpart easier.
* - fast-reload review, in case of error the sockets are already closed.
* - fast-reload review, identation.
* - fast-reload review, add static keywords.
* - fast-reload review, update unbound-control usage text.
* - fast-reload review, updates to the man page.
* - fast-reload, the fast-reload command is experimental.
* - fast-reload, fix compile of doqclient for fast reload functions.
* Changelog comment for #1042
- Merge #1042: Fast Reload. The unbound-control fast_reload is added.
It reads changed config in a thread, then only briefly pauses the
service threads, that keep running. DNS service is only interrupted
briefly, less than a second.
---------
Co-authored-by: Yorgos Thessalonikefs <yorgos@nlnetlabs.nl>
2025-03-31 09:25:24 -04:00
|
|
|
/** Compare two views by name */
|
|
|
|
|
static int
|
|
|
|
|
view_name_compare(const char* v_a, const char* v_b)
|
|
|
|
|
{
|
|
|
|
|
if(v_a == NULL && v_b == NULL)
|
|
|
|
|
return 0;
|
|
|
|
|
/* The NULL name is smaller than if the name is set. */
|
|
|
|
|
if(v_a == NULL)
|
|
|
|
|
return -1;
|
|
|
|
|
if(v_b == NULL)
|
|
|
|
|
return 1;
|
|
|
|
|
return strcmp(v_a, v_b);
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-05 08:20:27 -05:00
|
|
|
/**
|
2017-03-07 09:58:51 -05:00
|
|
|
* Compare two response-ip client info entries for the purpose of mesh state
|
|
|
|
|
* compare. It returns 0 if ci_a and ci_b are considered equal; otherwise
|
|
|
|
|
* 1 or -1 (they mean 'ci_a is larger/smaller than ci_b', respectively, but
|
|
|
|
|
* in practice it should be only used to mean they are different).
|
|
|
|
|
* We cannot share the mesh state for two queries if different response-ip
|
|
|
|
|
* actions can apply in the end, even if those queries are otherwise identical.
|
|
|
|
|
* For this purpose we compare tag lists and tag action lists; they should be
|
|
|
|
|
* identical to share the same state.
|
|
|
|
|
* For tag data, we don't look into the data content, as it can be
|
|
|
|
|
* expensive; unless tag data are not defined for both or they point to the
|
|
|
|
|
* exact same data in memory (i.e., they come from the same ACL entry), we
|
|
|
|
|
* consider these data different.
|
|
|
|
|
* Likewise, if the client info is associated with views, we don't look into
|
|
|
|
|
* the views. They are considered different unless they are exactly the same
|
|
|
|
|
* even if the views only differ in the names.
|
|
|
|
|
*/
|
|
|
|
|
static int
|
|
|
|
|
client_info_compare(const struct respip_client_info* ci_a,
|
|
|
|
|
const struct respip_client_info* ci_b)
|
|
|
|
|
{
|
|
|
|
|
int cmp;
|
|
|
|
|
|
|
|
|
|
if(!ci_a && !ci_b)
|
|
|
|
|
return 0;
|
|
|
|
|
if(ci_a && !ci_b)
|
|
|
|
|
return -1;
|
|
|
|
|
if(!ci_a && ci_b)
|
|
|
|
|
return 1;
|
|
|
|
|
if(ci_a->taglen != ci_b->taglen)
|
|
|
|
|
return (ci_a->taglen < ci_b->taglen) ? -1 : 1;
|
2020-02-27 09:43:27 -05:00
|
|
|
if(ci_a->taglist && !ci_b->taglist)
|
|
|
|
|
return -1;
|
|
|
|
|
if(!ci_a->taglist && ci_b->taglist)
|
|
|
|
|
return 1;
|
|
|
|
|
if(ci_a->taglist && ci_b->taglist) {
|
|
|
|
|
cmp = memcmp(ci_a->taglist, ci_b->taglist, ci_a->taglen);
|
|
|
|
|
if(cmp != 0)
|
|
|
|
|
return cmp;
|
|
|
|
|
}
|
2017-03-07 09:58:51 -05:00
|
|
|
if(ci_a->tag_actions_size != ci_b->tag_actions_size)
|
|
|
|
|
return (ci_a->tag_actions_size < ci_b->tag_actions_size) ?
|
|
|
|
|
-1 : 1;
|
2020-02-27 09:43:27 -05:00
|
|
|
if(ci_a->tag_actions && !ci_b->tag_actions)
|
|
|
|
|
return -1;
|
|
|
|
|
if(!ci_a->tag_actions && ci_b->tag_actions)
|
|
|
|
|
return 1;
|
|
|
|
|
if(ci_a->tag_actions && ci_b->tag_actions) {
|
|
|
|
|
cmp = memcmp(ci_a->tag_actions, ci_b->tag_actions,
|
|
|
|
|
ci_a->tag_actions_size);
|
|
|
|
|
if(cmp != 0)
|
|
|
|
|
return cmp;
|
|
|
|
|
}
|
2017-03-07 09:58:51 -05:00
|
|
|
if(ci_a->tag_datas != ci_b->tag_datas)
|
|
|
|
|
return ci_a->tag_datas < ci_b->tag_datas ? -1 : 1;
|
Fast Reload Option (#1042)
* - fast-reload, add unbound-control fast_reload
* - fast-reload, make a thread to service the unbound-control command.
* - fast-reload, communication sockets for information transfer.
* - fast-reload, fix compile for unbound-dnstap-socket.
* - fast-reload, set nonblocking communication to keep the server thread
responding to DNS requests.
* - fast-reload, poll routine to test for readiness, timeout fails connection.
* - fast-reload, detect loop in sock_poll_timeout routine.
* - fast-reload, send done and exited notification.
* - fast-reload, defines for constants in ipc.
* - fast-reload, ipc socket recv and send resists partial reads and writes and
can continue byte by byte. Also it can continue after an interrupt.
* - fast-reload, send exit command to thread when done.
* - fast-reload, output strings for client on string list.
* - fast-reload, add newline to terminal output.
* - fast-reload, send client string to remote client.
* - fast-reload, better debug output.
* - fast-reload, print queue structure, for output to the remote client.
* - fast-reload, move print items to print queue from fast_reload_thread struct.
* - fast-reload, keep list of pending print queue items in daemon struct.
* - fast-reload, comment explains in_list for printq to print remainder.
* - fast-reload, unit test testdata/fast_reload_thread.tdir that tests the
thread output.
* - fast-reload, fix test link for fast_reload_printq_list_delete function.
* - fast-reload, reread config file from disk.
* - fast-reload, unshare forwards, making the structure locked, with an rwlock.
* - fast-reload, for nonthreaded, the unbound-control commands forward,
forward_add and forward_delete should be distributed to other processes,
but when threaded, they should not be distributed to other threads because
the structure is not thread specific any more.
* - fast-reload, unshared stub hints, making the structure locked, with an rwlock.
* - fast-reload, helpful comments for hints lookup function return value.
* - fast-reload, fix bug in fast reload printout, the strlist appendlist routine,
and printout time statistics after the reload is done.
* - fast-reload, keep track of reloadtime and deletestime and print them.
* - fast-reload, keep track of constructtime and print it.
* - fast-reload, construct new items.
* - fast-reload, better comment.
* - fast-reload, reload the config and swap trees for forwards and stub hints.
* - fast-reload, in forwards_swap_tree set protection of trees with locks.
* - fast-reload, in hints_swap_tree also swap the node count of the trees.
* - fast-reload, reload ipc to stop and start threads.
* - fast-reload, unused forward declarations removed.
* - fast-reload, unit test that fast reload works with forwards and stubs.
* - fast-reload, fix clang analyzer warnings.
* - fast-reload, small documentation entry in unbound-control -h output.
* - fast-reload, printout memory use by fast reload, in bytes.
* - fast-reload, compile without threads.
* - fast-reload, document fast_reload in man page.
* - fast-reload, print ok when done successfully.
* - fast-reload, option for fast-reload commandline, +v verbosity option,
with timing and memory use output.
* - fast-reload, option for fast-reload commandline, +p does not pause threads.
* - fast-reload, option for fast-reload commandline, +d drops mesh queries.
* - fast-reload, fix to poll every thread with nopause to make certain that
resources are not held by the threads and can be deleted.
* - fast-reload, fix to use atomic store for config variables with nopause.
* - fast-reload, reload views.
* - fast-reload, when tag defines are different, it drops the queries.
* - fast-reload, fix tag define check.
* - fast-reload, document that tag change causes drop of queries.
* - fast-reload, fix space in documentation man page.
* - fast-reload, copy respip client information to query state, put views tree
in module env for lookup.
* - fast-reload, nicer respip view comparison.
* - fast-reload, respip global set is in module env.
* - fast-reload, document that respip_client_info acl info is copied.
* - fast-reload, reload the respip_set.
* - fast-reload, document no pause and pick up of use_response_ip boolean.
* - fast-reload, fix test compile.
* - fast-reload, reload local zones.
* Update locking management for iter_fwd and iter_hints methods. (#1054)
fast reload, move most of the locking management to iter_fwd and
iter_hints methods. The caller still has the ability to handle its
own locking, if desired, for atomic operations on sets of different
structs.
Co-authored-by: Wouter Wijngaards <wcawijngaards@users.noreply.github.com>
* - fast-reload, reload access-control.
* - fast-reload, reload access control interface, such as interface-action.
* - fast-reload, reload tcp-connection-limit.
* - fast-reload, improve comments on acl_list and tcl_list swap tree.
* - fast-reload, fixup references to old tcp connection limits in open tcp
connections.
* - fast-reload, fixup to clean tcp connection also for different linked order.
* - fast-reload, if no tcp connection limits existed, no need to remove
references for that.
* - fast-reload, document more options that work and do not work.
* - fast-reload, reload auth_zone and rpz data.
* - fast-reload, fix auth_zones_get_mem.
* - fast-reload, fix compilation of testbound for the new comm_timer_get_mem
reference in remote control.
* - fast-reload, change use_rpz with reload.
* - fast-reload, list changes in auth zones and stop zonemd callbacks for
deleted auth zones.
* - fast-reload, note xtree is not swapped, and why it is not swapped.
* - fast-reload, for added auth zones, pick up zone transfer and zonemd tasks.
* - fast-reload, unlock xfr when done with transfer pick up.
* - fast-reload, unlock z when picking up the xfr for it during transfer task
pick up.
* - fast-reload, pick up task changes for added, deleted and modified auth zones.
* - fast-reload, remove xfr of auth zone deletion without tasks.
* - fast-reload, pick up zone transfer config.
* - fast-reload, the main worker thread picks up the transfer tasks and also
performs setup of the xfer struct.
* - fast-reload, keep writelock on newzone when auth zone changes.
* - fast-reload, change cachedb_enabled setting.
* - fast-reload, pick up edns-strings config.
* - fast-reload, note that settings are not updated.
* - fast-reload, pick up dnstap config.
* - fast-reload, dnstap options that need to be loaded without +p.
* - fast-reload, fix auth zone reload
* - fast-reload, remove debug for auth zone test.
* - fast-reload, fix auth zone reload with zone transfer.
* - fast-reload, fix auth zone reload lock order.
* - fast-reload, remove debug from fast reload test.
* - fast-reload, remove unused function.
* - fast-reload, fix the worker trust anchor probe timer lock acquisition in
the probe answer callback routine for trust anchor probes.
* - fast-reload, reload trust anchors.
* - fast-reload, fix trust anchor reload lock on autr global data and test
for trust anchor reload.
* - fast-reload, adjust cache sizes.
* - fast-reload, reload cache sizes when changed.
* - fast-reload, reload validator env changes.
* - fast-reload, reload mesh changes.
* - fast-reload, check for incompatible changes.
* - fast-reload, improve error text for incompatible change.
* - fast-reload, fix check config option compatibility.
* - fast-reload, improve error text for nopause change.
* - fast-reload, fix spelling of incompatible options.
* - fast-reload, reload target-fetch-policy, outbound-msg-retry, max-sent-count
and max-query-restarts.
* - fast-reload, check nopause config change for target-fetch-policy.
* - fast-reload, reload do-not-query-address, private-address and capt-exempt.
* - fast-reload, check nopause config change for do-not-query-address,
private-address and capt-exempt.
* - fast-reload, check fast reload not possible due to interface and
outgoing-interface changes.
* - fast-reload, reload nat64 settings.
* - fast-reload, reload settings stored in the infra structure.
* - fast-reload, fix modstack lookup and remove outgoing-range check.
* - fast-reload, more explanation for config parse failure.
* - fast-reload, reload worker outside network changes.
* - fast-reload, detect incompatible changes in network settings.
* fast-reload, commit test files.
* - fast-reload, fix warnings for call types in windows compile.
* - fast-reload, fix warnings and comm_point_internal for tcp wouldblock calls.
* - fast-reload, extend lock checks for repeat thread ids.
* - fast-reload, additional test cases, cache change and tag changes.
* - fast-reload, fix documentation for auth_zone_verify_zonemd_with_key.
* - fast-reload, fix copy_cfg type casts and memory leak on config parse failure.
* - fast-reload, fix use of WSAPoll.
* Review comments for the fast reload feature (#1259)
* - fast-reload review, respip set can be null from a view.
* - fast-reload review, typos.
* - fast-reload review, keep clang static analyzer happy.
* - fast-reload review, don't forget to copy tag_actions.
* - fast-reload review, less indentation.
* - fast-reload review, don't leak respip_actions when reloading.
* - fast-reload review, protect NULL pointer dereference in get_mem
functions.
* - fast-reload review, add fast_reload_most_options.tdir to test most
options with high verbosity when fast reloading.
* - fast-reload review, don't skip new line on long error printouts.
* - fast-reload review, typo.
* - fast-reload review, use new_z for consistency.
* - fast-reload review, nit for unlock ordering to make eye comparison
with the lock counterpart easier.
* - fast-reload review, in case of error the sockets are already closed.
* - fast-reload review, identation.
* - fast-reload review, add static keywords.
* - fast-reload review, update unbound-control usage text.
* - fast-reload review, updates to the man page.
* - fast-reload, the fast-reload command is experimental.
* - fast-reload, fix compile of doqclient for fast reload functions.
* Changelog comment for #1042
- Merge #1042: Fast Reload. The unbound-control fast_reload is added.
It reads changed config in a thread, then only briefly pauses the
service threads, that keep running. DNS service is only interrupted
briefly, less than a second.
---------
Co-authored-by: Yorgos Thessalonikefs <yorgos@nlnetlabs.nl>
2025-03-31 09:25:24 -04:00
|
|
|
if(ci_a->view || ci_a->view_name || ci_b->view || ci_b->view_name) {
|
|
|
|
|
/* Compare the views by name. */
|
|
|
|
|
cmp = view_name_compare(
|
|
|
|
|
(ci_a->view?ci_a->view->name:ci_a->view_name),
|
|
|
|
|
(ci_b->view?ci_b->view->name:ci_b->view_name));
|
|
|
|
|
if(cmp != 0)
|
|
|
|
|
return cmp;
|
|
|
|
|
}
|
2017-04-18 05:00:52 -04:00
|
|
|
return 0;
|
2017-03-07 09:58:51 -05:00
|
|
|
}
|
|
|
|
|
|
2007-10-05 07:41:12 -04:00
|
|
|
int
|
2007-06-22 06:09:21 -04:00
|
|
|
mesh_state_compare(const void* ap, const void* bp)
|
|
|
|
|
{
|
|
|
|
|
struct mesh_state* a = (struct mesh_state*)ap;
|
|
|
|
|
struct mesh_state* b = (struct mesh_state*)bp;
|
2017-03-07 09:58:51 -05:00
|
|
|
int cmp;
|
2007-06-22 06:09:21 -04:00
|
|
|
|
2016-12-06 08:42:51 -05:00
|
|
|
if(a->unique < b->unique)
|
|
|
|
|
return -1;
|
|
|
|
|
if(a->unique > b->unique)
|
|
|
|
|
return 1;
|
|
|
|
|
|
2007-08-01 08:59:37 -04:00
|
|
|
if(a->s.is_priming && !b->s.is_priming)
|
2007-06-22 06:09:21 -04:00
|
|
|
return -1;
|
2007-08-01 08:59:37 -04:00
|
|
|
if(!a->s.is_priming && b->s.is_priming)
|
2007-06-22 06:09:21 -04:00
|
|
|
return 1;
|
|
|
|
|
|
2014-11-18 10:15:57 -05:00
|
|
|
if(a->s.is_valrec && !b->s.is_valrec)
|
|
|
|
|
return -1;
|
|
|
|
|
if(!a->s.is_valrec && b->s.is_valrec)
|
|
|
|
|
return 1;
|
|
|
|
|
|
2007-06-22 08:39:08 -04:00
|
|
|
if((a->s.query_flags&BIT_RD) && !(b->s.query_flags&BIT_RD))
|
2007-06-22 06:09:21 -04:00
|
|
|
return -1;
|
2007-06-22 08:39:08 -04:00
|
|
|
if(!(a->s.query_flags&BIT_RD) && (b->s.query_flags&BIT_RD))
|
2007-06-22 06:09:21 -04:00
|
|
|
return 1;
|
|
|
|
|
|
2007-08-01 07:17:30 -04:00
|
|
|
if((a->s.query_flags&BIT_CD) && !(b->s.query_flags&BIT_CD))
|
|
|
|
|
return -1;
|
|
|
|
|
if(!(a->s.query_flags&BIT_CD) && (b->s.query_flags&BIT_CD))
|
|
|
|
|
return 1;
|
|
|
|
|
|
2017-03-07 09:58:51 -05:00
|
|
|
cmp = query_info_compare(&a->s.qinfo, &b->s.qinfo);
|
|
|
|
|
if(cmp != 0)
|
|
|
|
|
return cmp;
|
|
|
|
|
return client_info_compare(a->s.client_info, b->s.client_info);
|
2007-06-22 06:09:21 -04:00
|
|
|
}
|
|
|
|
|
|
2007-10-05 07:41:12 -04:00
|
|
|
int
|
2007-06-22 06:09:21 -04:00
|
|
|
mesh_state_ref_compare(const void* ap, const void* bp)
|
|
|
|
|
{
|
|
|
|
|
struct mesh_state_ref* a = (struct mesh_state_ref*)ap;
|
|
|
|
|
struct mesh_state_ref* b = (struct mesh_state_ref*)bp;
|
|
|
|
|
return mesh_state_compare(a->s, b->s);
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-20 11:39:55 -04:00
|
|
|
struct mesh_area*
|
2007-12-04 08:23:41 -05:00
|
|
|
mesh_create(struct module_stack* stack, struct module_env* env)
|
2007-06-22 06:09:21 -04:00
|
|
|
{
|
|
|
|
|
struct mesh_area* mesh = calloc(1, sizeof(struct mesh_area));
|
|
|
|
|
if(!mesh) {
|
|
|
|
|
log_err("mesh area alloc: out of memory");
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
2007-06-27 10:59:44 -04:00
|
|
|
mesh->histogram = timehist_setup();
|
2013-12-03 04:11:16 -05:00
|
|
|
mesh->qbuf_bak = sldns_buffer_new(env->cfg->msg_buffer_size);
|
2011-10-24 09:49:59 -04:00
|
|
|
if(!mesh->histogram || !mesh->qbuf_bak) {
|
2007-06-27 10:59:44 -04:00
|
|
|
free(mesh);
|
|
|
|
|
log_err("mesh area alloc: out of memory");
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
2007-12-04 08:23:41 -05:00
|
|
|
mesh->mods = *stack;
|
2007-06-25 09:54:03 -04:00
|
|
|
mesh->env = env;
|
2007-06-22 06:09:21 -04:00
|
|
|
rbtree_init(&mesh->run, &mesh_state_compare);
|
|
|
|
|
rbtree_init(&mesh->all, &mesh_state_compare);
|
|
|
|
|
mesh->num_reply_addrs = 0;
|
|
|
|
|
mesh->num_reply_states = 0;
|
|
|
|
|
mesh->num_detached_states = 0;
|
2008-09-02 09:04:47 -04:00
|
|
|
mesh->num_forever_states = 0;
|
|
|
|
|
mesh->stats_jostled = 0;
|
|
|
|
|
mesh->stats_dropped = 0;
|
2020-02-05 08:20:27 -05:00
|
|
|
mesh->ans_expired = 0;
|
2023-05-30 11:49:50 -04:00
|
|
|
mesh->ans_cachedb = 0;
|
2024-11-01 10:52:58 -04:00
|
|
|
mesh->num_queries_discard_timeout = 0;
|
|
|
|
|
mesh->num_queries_wait_limit = 0;
|
2025-04-07 04:25:10 -04:00
|
|
|
mesh->num_dns_error_reports = 0;
|
2008-09-02 09:04:47 -04:00
|
|
|
mesh->max_reply_states = env->cfg->num_queries_per_thread;
|
|
|
|
|
mesh->max_forever_states = (mesh->max_reply_states+1)/2;
|
2008-10-06 06:38:07 -04:00
|
|
|
#ifndef S_SPLINT_S
|
2008-10-06 05:28:50 -04:00
|
|
|
mesh->jostle_max.tv_sec = (time_t)(env->cfg->jostle_time / 1000);
|
|
|
|
|
mesh->jostle_max.tv_usec = (time_t)((env->cfg->jostle_time % 1000)
|
|
|
|
|
*1000);
|
2008-10-06 05:42:31 -04:00
|
|
|
#endif
|
2007-06-22 06:09:21 -04:00
|
|
|
return mesh;
|
|
|
|
|
}
|
|
|
|
|
|
2007-06-27 05:45:39 -04:00
|
|
|
/** help mesh delete delete mesh states */
|
|
|
|
|
static void
|
2017-01-19 05:25:41 -05:00
|
|
|
mesh_delete_helper(rbnode_type* n)
|
2007-06-27 05:45:39 -04:00
|
|
|
{
|
|
|
|
|
struct mesh_state* mstate = (struct mesh_state*)n->key;
|
2009-02-18 08:23:17 -05:00
|
|
|
/* perform a full delete, not only 'cleanup' routine,
|
|
|
|
|
* because other callbacks expect a clean state in the mesh.
|
|
|
|
|
* For 're-entrant' calls */
|
|
|
|
|
mesh_state_delete(&mstate->s);
|
2009-03-05 03:19:52 -05:00
|
|
|
/* but because these delete the items from the tree, postorder
|
|
|
|
|
* traversal and rbtree rebalancing do not work together */
|
2007-06-27 05:45:39 -04:00
|
|
|
}
|
|
|
|
|
|
2023-04-20 11:39:55 -04:00
|
|
|
void
|
2007-06-22 06:09:21 -04:00
|
|
|
mesh_delete(struct mesh_area* mesh)
|
|
|
|
|
{
|
|
|
|
|
if(!mesh)
|
|
|
|
|
return;
|
|
|
|
|
/* free all query states */
|
2009-03-05 03:19:52 -05:00
|
|
|
while(mesh->all.count)
|
|
|
|
|
mesh_delete_helper(mesh->all.root);
|
2007-06-27 10:59:44 -04:00
|
|
|
timehist_delete(mesh->histogram);
|
2013-12-03 04:11:16 -05:00
|
|
|
sldns_buffer_free(mesh->qbuf_bak);
|
2007-06-22 06:09:21 -04:00
|
|
|
free(mesh);
|
|
|
|
|
}
|
2007-06-22 08:39:08 -04:00
|
|
|
|
2009-02-12 08:21:19 -05:00
|
|
|
void
|
|
|
|
|
mesh_delete_all(struct mesh_area* mesh)
|
|
|
|
|
{
|
|
|
|
|
/* free all query states */
|
2009-03-05 03:19:52 -05:00
|
|
|
while(mesh->all.count)
|
|
|
|
|
mesh_delete_helper(mesh->all.root);
|
2009-02-12 08:21:19 -05:00
|
|
|
mesh->stats_dropped += mesh->num_reply_addrs;
|
|
|
|
|
/* clear mesh area references */
|
|
|
|
|
rbtree_init(&mesh->run, &mesh_state_compare);
|
|
|
|
|
rbtree_init(&mesh->all, &mesh_state_compare);
|
|
|
|
|
mesh->num_reply_addrs = 0;
|
|
|
|
|
mesh->num_reply_states = 0;
|
|
|
|
|
mesh->num_detached_states = 0;
|
|
|
|
|
mesh->num_forever_states = 0;
|
|
|
|
|
mesh->forever_first = NULL;
|
|
|
|
|
mesh->forever_last = NULL;
|
|
|
|
|
mesh->jostle_first = NULL;
|
|
|
|
|
mesh->jostle_last = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-03 04:11:16 -05:00
|
|
|
int mesh_make_new_space(struct mesh_area* mesh, sldns_buffer* qbuf)
|
2008-09-02 09:04:47 -04:00
|
|
|
{
|
2010-06-28 07:42:21 -04:00
|
|
|
struct mesh_state* m = mesh->jostle_first;
|
2008-09-02 09:04:47 -04:00
|
|
|
/* free space is available */
|
|
|
|
|
if(mesh->num_reply_states < mesh->max_reply_states)
|
|
|
|
|
return 1;
|
|
|
|
|
/* try to kick out a jostle-list item */
|
|
|
|
|
if(m && m->reply_list && m->list_select == mesh_jostle_list) {
|
|
|
|
|
/* how old is it? */
|
|
|
|
|
struct timeval age;
|
2023-04-20 11:39:55 -04:00
|
|
|
timeval_subtract(&age, mesh->env->now_tv,
|
2008-09-02 09:04:47 -04:00
|
|
|
&m->reply_list->start_time);
|
2008-10-06 05:28:50 -04:00
|
|
|
if(timeval_smaller(&mesh->jostle_max, &age)) {
|
2008-09-02 09:04:47 -04:00
|
|
|
/* its a goner */
|
|
|
|
|
log_nametypeclass(VERB_ALGO, "query jostled out to "
|
|
|
|
|
"make space for a new one",
|
|
|
|
|
m->s.qinfo.qname, m->s.qinfo.qtype,
|
|
|
|
|
m->s.qinfo.qclass);
|
2011-10-24 09:49:59 -04:00
|
|
|
/* backup the query */
|
2013-12-03 04:11:16 -05:00
|
|
|
if(qbuf) sldns_buffer_copy(mesh->qbuf_bak, qbuf);
|
2008-09-02 09:04:47 -04:00
|
|
|
/* notify supers */
|
|
|
|
|
if(m->super_set.count > 0) {
|
|
|
|
|
verbose(VERB_ALGO, "notify supers of failure");
|
|
|
|
|
m->s.return_msg = NULL;
|
|
|
|
|
m->s.return_rcode = LDNS_RCODE_SERVFAIL;
|
|
|
|
|
mesh_walk_supers(mesh, m);
|
|
|
|
|
}
|
|
|
|
|
mesh->stats_jostled ++;
|
|
|
|
|
mesh_state_delete(&m->s);
|
2011-10-24 09:49:59 -04:00
|
|
|
/* restore the query - note that the qinfo ptr to
|
|
|
|
|
* the querybuffer is then correct again. */
|
2013-12-03 04:11:16 -05:00
|
|
|
if(qbuf) sldns_buffer_copy(qbuf, mesh->qbuf_bak);
|
2008-09-02 09:04:47 -04:00
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/* no space for new item */
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-05 08:20:27 -05:00
|
|
|
struct dns_msg*
|
|
|
|
|
mesh_serve_expired_lookup(struct module_qstate* qstate,
|
2024-09-24 10:47:04 -04:00
|
|
|
struct query_info* lookup_qinfo, int* is_expired)
|
2020-02-05 08:20:27 -05:00
|
|
|
{
|
|
|
|
|
hashvalue_type h;
|
|
|
|
|
struct lruhash_entry* e;
|
|
|
|
|
struct dns_msg* msg;
|
2020-02-06 08:38:01 -05:00
|
|
|
struct reply_info* data;
|
2020-02-05 08:20:27 -05:00
|
|
|
struct msgreply_entry* key;
|
|
|
|
|
time_t timenow = *qstate->env->now;
|
|
|
|
|
int must_validate = (!(qstate->query_flags&BIT_CD)
|
|
|
|
|
|| qstate->env->cfg->ignore_cd) && qstate->env->need_to_validate;
|
2024-09-24 10:47:04 -04:00
|
|
|
*is_expired = 0;
|
2020-02-05 08:20:27 -05:00
|
|
|
/* Lookup cache */
|
|
|
|
|
h = query_info_hash(lookup_qinfo, qstate->query_flags);
|
|
|
|
|
e = slabhash_lookup(qstate->env->msg_cache, h, lookup_qinfo, 0);
|
|
|
|
|
if(!e) return NULL;
|
2020-02-06 08:38:01 -05:00
|
|
|
|
|
|
|
|
key = (struct msgreply_entry*)e->key;
|
|
|
|
|
data = (struct reply_info*)e->data;
|
2025-09-15 04:03:35 -04:00
|
|
|
if(TTL_IS_EXPIRED(data->ttl, timenow)) *is_expired = 1;
|
2020-02-06 08:38:01 -05:00
|
|
|
msg = tomsg(qstate->env, &key->key, data, qstate->region, timenow,
|
|
|
|
|
qstate->env->cfg->serve_expired, qstate->env->scratch);
|
|
|
|
|
if(!msg)
|
|
|
|
|
goto bail_out;
|
2020-02-05 08:20:27 -05:00
|
|
|
|
|
|
|
|
/* Check CNAME chain (if any)
|
2020-02-06 08:38:01 -05:00
|
|
|
* This is part of tomsg above; no need to check now. */
|
2020-02-05 08:20:27 -05:00
|
|
|
|
|
|
|
|
/* Check security status of the cached answer.
|
2020-02-06 08:38:01 -05:00
|
|
|
* tomsg above has a subset of these checks, so we are leaving
|
2020-02-05 08:20:27 -05:00
|
|
|
* these as is.
|
|
|
|
|
* In case of bogus or revalidation we don't care to reply here. */
|
2020-02-06 08:38:01 -05:00
|
|
|
if(must_validate && (msg->rep->security == sec_status_bogus ||
|
|
|
|
|
msg->rep->security == sec_status_secure_sentinel_fail)) {
|
2020-02-05 08:20:27 -05:00
|
|
|
verbose(VERB_ALGO, "Serve expired: bogus answer found in cache");
|
2020-02-06 08:01:45 -05:00
|
|
|
goto bail_out;
|
2020-02-06 08:38:01 -05:00
|
|
|
} else if(msg->rep->security == sec_status_unchecked && must_validate) {
|
2020-02-05 08:20:27 -05:00
|
|
|
verbose(VERB_ALGO, "Serve expired: unchecked entry needs "
|
|
|
|
|
"validation");
|
2020-02-06 08:01:45 -05:00
|
|
|
goto bail_out; /* need to validate cache entry first */
|
2020-02-06 08:38:01 -05:00
|
|
|
} else if(msg->rep->security == sec_status_secure &&
|
|
|
|
|
!reply_all_rrsets_secure(msg->rep) && must_validate) {
|
2020-02-05 08:20:27 -05:00
|
|
|
verbose(VERB_ALGO, "Serve expired: secure entry"
|
|
|
|
|
" changed status");
|
2020-02-06 08:01:45 -05:00
|
|
|
goto bail_out; /* rrset changed, re-verify */
|
2020-02-05 08:20:27 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
lock_rw_unlock(&e->lock);
|
|
|
|
|
return msg;
|
|
|
|
|
|
|
|
|
|
bail_out:
|
|
|
|
|
lock_rw_unlock(&e->lock);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** Init the serve expired data structure */
|
|
|
|
|
static int
|
|
|
|
|
mesh_serve_expired_init(struct mesh_state* mstate, int timeout)
|
|
|
|
|
{
|
|
|
|
|
struct timeval t;
|
|
|
|
|
|
|
|
|
|
/* Create serve_expired_data if not there yet */
|
|
|
|
|
if(!mstate->s.serve_expired_data) {
|
|
|
|
|
mstate->s.serve_expired_data = (struct serve_expired_data*)
|
|
|
|
|
regional_alloc_zero(
|
|
|
|
|
mstate->s.region, sizeof(struct serve_expired_data));
|
|
|
|
|
if(!mstate->s.serve_expired_data)
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Don't overwrite the function if already set */
|
|
|
|
|
mstate->s.serve_expired_data->get_cached_answer =
|
|
|
|
|
mstate->s.serve_expired_data->get_cached_answer?
|
|
|
|
|
mstate->s.serve_expired_data->get_cached_answer:
|
2021-07-16 11:55:10 -04:00
|
|
|
&mesh_serve_expired_lookup;
|
2020-02-05 08:20:27 -05:00
|
|
|
|
|
|
|
|
/* In case this timer already popped, start it again */
|
2024-04-10 05:21:28 -04:00
|
|
|
if(!mstate->s.serve_expired_data->timer && timeout != -1) {
|
2020-02-05 08:20:27 -05:00
|
|
|
mstate->s.serve_expired_data->timer = comm_timer_create(
|
|
|
|
|
mstate->s.env->worker_base, mesh_serve_expired_callback, mstate);
|
|
|
|
|
if(!mstate->s.serve_expired_data->timer)
|
|
|
|
|
return 0;
|
|
|
|
|
#ifndef S_SPLINT_S
|
|
|
|
|
t.tv_sec = timeout/1000;
|
|
|
|
|
t.tv_usec = (timeout%1000)*1000;
|
|
|
|
|
#endif
|
|
|
|
|
comm_timer_set(mstate->s.serve_expired_data->timer, &t);
|
|
|
|
|
}
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
2007-06-25 09:54:03 -04:00
|
|
|
void mesh_new_client(struct mesh_area* mesh, struct query_info* qinfo,
|
2017-03-07 09:58:51 -05:00
|
|
|
struct respip_client_info* cinfo, uint16_t qflags,
|
2022-02-15 10:20:12 -05:00
|
|
|
struct edns_data* edns, struct comm_reply* rep, uint16_t qid,
|
|
|
|
|
int rpz_passthru)
|
2007-06-25 09:54:03 -04:00
|
|
|
{
|
2016-12-06 08:42:51 -05:00
|
|
|
struct mesh_state* s = NULL;
|
2021-11-01 08:48:40 -04:00
|
|
|
int unique = unique_mesh_state(edns->opt_list_in, mesh->env);
|
2007-06-25 09:54:03 -04:00
|
|
|
int was_detached = 0;
|
|
|
|
|
int was_noreply = 0;
|
|
|
|
|
int added = 0;
|
2020-02-05 08:20:27 -05:00
|
|
|
int timeout = mesh->env->cfg->serve_expired?
|
|
|
|
|
mesh->env->cfg->serve_expired_client_timeout:0;
|
2019-06-11 06:15:43 -04:00
|
|
|
struct sldns_buffer* r_buffer = rep->c->buffer;
|
2024-06-26 09:51:58 -04:00
|
|
|
uint16_t mesh_flags = qflags&(BIT_RD|BIT_CD);
|
2019-06-11 06:15:43 -04:00
|
|
|
if(rep->c->tcp_req_info) {
|
|
|
|
|
r_buffer = rep->c->tcp_req_info->spool_buffer;
|
|
|
|
|
}
|
2024-05-01 04:10:58 -04:00
|
|
|
if(!infra_wait_limit_allowed(mesh->env->infra_cache, rep,
|
|
|
|
|
edns->cookie_valid, mesh->env->cfg)) {
|
|
|
|
|
verbose(VERB_ALGO, "Too many queries waiting from the IP. "
|
|
|
|
|
"dropping incoming query.");
|
|
|
|
|
comm_point_drop_reply(rep);
|
2024-11-01 10:52:58 -04:00
|
|
|
mesh->num_queries_wait_limit++;
|
2024-05-01 04:10:58 -04:00
|
|
|
return;
|
|
|
|
|
}
|
2016-12-06 08:42:51 -05:00
|
|
|
if(!unique)
|
2024-06-26 09:51:58 -04:00
|
|
|
s = mesh_area_find(mesh, cinfo, qinfo, mesh_flags, 0, 0);
|
2008-09-02 09:04:47 -04:00
|
|
|
/* does this create a new reply state? */
|
|
|
|
|
if(!s || s->list_select == mesh_no_list) {
|
2011-10-24 09:49:59 -04:00
|
|
|
if(!mesh_make_new_space(mesh, rep->c->buffer)) {
|
2008-09-02 09:04:47 -04:00
|
|
|
verbose(VERB_ALGO, "Too many queries. dropping "
|
|
|
|
|
"incoming query.");
|
|
|
|
|
comm_point_drop_reply(rep);
|
2020-02-05 08:20:27 -05:00
|
|
|
mesh->stats_dropped++;
|
2008-09-02 09:04:47 -04:00
|
|
|
return;
|
|
|
|
|
}
|
2010-06-28 08:50:04 -04:00
|
|
|
/* for this new reply state, the reply address is free,
|
|
|
|
|
* so the limit of reply addresses does not stop reply states*/
|
|
|
|
|
} else {
|
|
|
|
|
/* protect our memory usage from storing reply addresses */
|
|
|
|
|
if(mesh->num_reply_addrs > mesh->max_reply_states*16) {
|
|
|
|
|
verbose(VERB_ALGO, "Too many requests queued. "
|
|
|
|
|
"dropping incoming query.");
|
|
|
|
|
comm_point_drop_reply(rep);
|
2020-02-05 08:20:27 -05:00
|
|
|
mesh->stats_dropped++;
|
2010-06-28 08:50:04 -04:00
|
|
|
return;
|
|
|
|
|
}
|
2008-09-02 09:04:47 -04:00
|
|
|
}
|
2007-06-25 09:54:03 -04:00
|
|
|
/* see if it already exists, if not, create one */
|
|
|
|
|
if(!s) {
|
2011-09-16 07:35:01 -04:00
|
|
|
#ifdef UNBOUND_DEBUG
|
2017-01-19 05:25:41 -05:00
|
|
|
struct rbnode_type* n;
|
2011-09-16 07:35:01 -04:00
|
|
|
#endif
|
2017-03-07 09:58:51 -05:00
|
|
|
s = mesh_state_create(mesh->env, qinfo, cinfo,
|
2024-06-26 09:51:58 -04:00
|
|
|
mesh_flags, 0, 0);
|
2007-06-25 09:54:03 -04:00
|
|
|
if(!s) {
|
|
|
|
|
log_err("mesh_state_create: out of memory; SERVFAIL");
|
2016-12-06 08:42:51 -05:00
|
|
|
if(!inplace_cb_reply_servfail_call(mesh->env, qinfo, NULL, NULL,
|
2021-01-08 05:10:05 -05:00
|
|
|
LDNS_RCODE_SERVFAIL, edns, rep, mesh->env->scratch, mesh->env->now_tv))
|
2021-11-08 05:50:29 -05:00
|
|
|
edns->opt_list_inplace_cb_out = NULL;
|
2019-06-11 06:15:43 -04:00
|
|
|
error_encode(r_buffer, LDNS_RCODE_SERVFAIL,
|
2007-06-25 09:54:03 -04:00
|
|
|
qinfo, qid, qflags, edns);
|
|
|
|
|
comm_point_send_reply(rep);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2023-07-21 15:05:38 -04:00
|
|
|
/* set detached (it is now) */
|
|
|
|
|
mesh->num_detached_states++;
|
2016-12-06 08:42:51 -05:00
|
|
|
if(unique)
|
|
|
|
|
mesh_state_make_unique(s);
|
2022-02-15 10:20:12 -05:00
|
|
|
s->s.rpz_passthru = rpz_passthru;
|
2016-12-06 08:42:51 -05:00
|
|
|
/* copy the edns options we got from the front */
|
2021-11-01 08:48:40 -04:00
|
|
|
if(edns->opt_list_in) {
|
|
|
|
|
s->s.edns_opts_front_in = edns_opt_copy_region(edns->opt_list_in,
|
2016-12-06 08:42:51 -05:00
|
|
|
s->s.region);
|
|
|
|
|
if(!s->s.edns_opts_front_in) {
|
2023-05-23 03:23:03 -04:00
|
|
|
log_err("edns_opt_copy_region: out of memory; SERVFAIL");
|
2016-12-06 08:42:51 -05:00
|
|
|
if(!inplace_cb_reply_servfail_call(mesh->env, qinfo, NULL,
|
2021-01-08 05:10:05 -05:00
|
|
|
NULL, LDNS_RCODE_SERVFAIL, edns, rep, mesh->env->scratch, mesh->env->now_tv))
|
2021-11-08 05:50:29 -05:00
|
|
|
edns->opt_list_inplace_cb_out = NULL;
|
2019-06-11 06:15:43 -04:00
|
|
|
error_encode(r_buffer, LDNS_RCODE_SERVFAIL,
|
2016-12-06 08:42:51 -05:00
|
|
|
qinfo, qid, qflags, edns);
|
|
|
|
|
comm_point_send_reply(rep);
|
2023-05-23 03:23:03 -04:00
|
|
|
mesh_state_delete(&s->s);
|
2016-12-06 08:42:51 -05:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-09-16 07:35:01 -04:00
|
|
|
#ifdef UNBOUND_DEBUG
|
|
|
|
|
n =
|
2013-08-22 10:10:29 -04:00
|
|
|
#else
|
|
|
|
|
(void)
|
2011-09-16 07:35:01 -04:00
|
|
|
#endif
|
|
|
|
|
rbtree_insert(&mesh->all, &s->node);
|
2007-06-25 09:54:03 -04:00
|
|
|
log_assert(n != NULL);
|
|
|
|
|
added = 1;
|
|
|
|
|
}
|
2020-02-05 08:20:27 -05:00
|
|
|
if(!s->reply_list && !s->cb_list) {
|
2007-06-25 09:54:03 -04:00
|
|
|
was_noreply = 1;
|
2020-02-05 08:20:27 -05:00
|
|
|
if(s->super_set.count == 0) {
|
|
|
|
|
was_detached = 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
2007-06-25 09:54:03 -04:00
|
|
|
/* add reply to s */
|
2016-10-18 09:18:20 -04:00
|
|
|
if(!mesh_state_add_reply(s, edns, rep, qid, qflags, qinfo)) {
|
2020-02-05 08:20:27 -05:00
|
|
|
log_err("mesh_new_client: out of memory; SERVFAIL");
|
|
|
|
|
goto servfail_mem;
|
2007-06-25 09:54:03 -04:00
|
|
|
}
|
2019-01-11 09:12:27 -05:00
|
|
|
if(rep->c->tcp_req_info) {
|
|
|
|
|
if(!tcp_req_info_add_meshstate(rep->c->tcp_req_info, mesh, s)) {
|
|
|
|
|
log_err("mesh_new_client: out of memory add tcpreqinfo");
|
|
|
|
|
goto servfail_mem;
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-09-16 12:25:02 -04:00
|
|
|
if(rep->c->use_h2) {
|
2020-05-07 10:36:26 -04:00
|
|
|
http2_stream_add_meshstate(rep->c->h2_stream, mesh, s);
|
|
|
|
|
}
|
2020-02-05 08:20:27 -05:00
|
|
|
/* add serve expired timer if required and not already there */
|
|
|
|
|
if(timeout && !mesh_serve_expired_init(s, timeout)) {
|
|
|
|
|
log_err("mesh_new_client: out of memory initializing serve expired");
|
|
|
|
|
goto servfail_mem;
|
|
|
|
|
}
|
2024-04-10 05:33:52 -04:00
|
|
|
#ifdef USE_CACHEDB
|
2024-04-10 05:21:28 -04:00
|
|
|
if(!timeout && mesh->env->cfg->serve_expired &&
|
|
|
|
|
!mesh->env->cfg->serve_expired_client_timeout &&
|
|
|
|
|
(mesh->env->cachedb_enabled &&
|
|
|
|
|
mesh->env->cfg->cachedb_check_when_serve_expired)) {
|
|
|
|
|
if(!mesh_serve_expired_init(s, -1)) {
|
|
|
|
|
log_err("mesh_new_client: out of memory initializing serve expired");
|
|
|
|
|
goto servfail_mem;
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-04-10 05:33:52 -04:00
|
|
|
#endif
|
2024-05-01 04:10:58 -04:00
|
|
|
infra_wait_limit_inc(mesh->env->infra_cache, rep, *mesh->env->now,
|
|
|
|
|
mesh->env->cfg);
|
2007-06-25 09:54:03 -04:00
|
|
|
/* update statistics */
|
|
|
|
|
if(was_detached) {
|
|
|
|
|
log_assert(mesh->num_detached_states > 0);
|
|
|
|
|
mesh->num_detached_states--;
|
|
|
|
|
}
|
|
|
|
|
if(was_noreply) {
|
|
|
|
|
mesh->num_reply_states ++;
|
|
|
|
|
}
|
2007-06-26 11:24:07 -04:00
|
|
|
mesh->num_reply_addrs++;
|
2008-09-02 09:04:47 -04:00
|
|
|
if(s->list_select == mesh_no_list) {
|
|
|
|
|
/* move to either the forever or the jostle_list */
|
|
|
|
|
if(mesh->num_forever_states < mesh->max_forever_states) {
|
|
|
|
|
mesh->num_forever_states ++;
|
2023-04-20 11:39:55 -04:00
|
|
|
mesh_list_insert(s, &mesh->forever_first,
|
2008-09-02 09:04:47 -04:00
|
|
|
&mesh->forever_last);
|
|
|
|
|
s->list_select = mesh_forever_list;
|
|
|
|
|
} else {
|
2023-04-20 11:39:55 -04:00
|
|
|
mesh_list_insert(s, &mesh->jostle_first,
|
2008-09-02 09:04:47 -04:00
|
|
|
&mesh->jostle_last);
|
|
|
|
|
s->list_select = mesh_jostle_list;
|
|
|
|
|
}
|
|
|
|
|
}
|
2007-06-25 09:54:03 -04:00
|
|
|
if(added)
|
|
|
|
|
mesh_run(mesh, s, module_event_new, NULL);
|
2020-02-05 08:20:27 -05:00
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
servfail_mem:
|
|
|
|
|
if(!inplace_cb_reply_servfail_call(mesh->env, qinfo, &s->s,
|
2021-01-08 05:10:05 -05:00
|
|
|
NULL, LDNS_RCODE_SERVFAIL, edns, rep, mesh->env->scratch, mesh->env->now_tv))
|
2021-11-08 05:50:29 -05:00
|
|
|
edns->opt_list_inplace_cb_out = NULL;
|
2020-02-05 08:20:27 -05:00
|
|
|
error_encode(r_buffer, LDNS_RCODE_SERVFAIL,
|
|
|
|
|
qinfo, qid, qflags, edns);
|
2024-07-15 08:51:20 -04:00
|
|
|
if(rep->c->use_h2)
|
|
|
|
|
http2_stream_remove_mesh_state(rep->c->h2_stream);
|
2020-02-05 08:20:27 -05:00
|
|
|
comm_point_send_reply(rep);
|
|
|
|
|
if(added)
|
|
|
|
|
mesh_state_delete(&s->s);
|
|
|
|
|
return;
|
2007-06-25 09:54:03 -04:00
|
|
|
}
|
|
|
|
|
|
2023-04-20 11:39:55 -04:00
|
|
|
int
|
2007-12-06 10:11:07 -05:00
|
|
|
mesh_new_callback(struct mesh_area* mesh, struct query_info* qinfo,
|
2023-04-20 11:39:55 -04:00
|
|
|
uint16_t qflags, struct edns_data* edns, sldns_buffer* buf,
|
2022-02-15 10:20:12 -05:00
|
|
|
uint16_t qid, mesh_cb_func_type cb, void* cb_arg, int rpz_passthru)
|
2007-12-06 10:11:07 -05:00
|
|
|
{
|
2016-12-06 08:42:51 -05:00
|
|
|
struct mesh_state* s = NULL;
|
2021-11-01 08:48:40 -04:00
|
|
|
int unique = unique_mesh_state(edns->opt_list_in, mesh->env);
|
2020-02-05 08:20:27 -05:00
|
|
|
int timeout = mesh->env->cfg->serve_expired?
|
|
|
|
|
mesh->env->cfg->serve_expired_client_timeout:0;
|
2007-12-06 10:11:07 -05:00
|
|
|
int was_detached = 0;
|
|
|
|
|
int was_noreply = 0;
|
|
|
|
|
int added = 0;
|
2024-06-26 09:51:58 -04:00
|
|
|
uint16_t mesh_flags = qflags&(BIT_RD|BIT_CD);
|
2016-12-06 08:42:51 -05:00
|
|
|
if(!unique)
|
2024-06-26 09:51:58 -04:00
|
|
|
s = mesh_area_find(mesh, NULL, qinfo, mesh_flags, 0, 0);
|
2017-03-07 09:58:51 -05:00
|
|
|
|
2008-09-02 09:04:47 -04:00
|
|
|
/* there are no limits on the number of callbacks */
|
|
|
|
|
|
2007-12-06 10:11:07 -05:00
|
|
|
/* see if it already exists, if not, create one */
|
|
|
|
|
if(!s) {
|
2011-09-16 07:35:01 -04:00
|
|
|
#ifdef UNBOUND_DEBUG
|
2017-01-19 05:25:41 -05:00
|
|
|
struct rbnode_type* n;
|
2011-09-16 07:35:01 -04:00
|
|
|
#endif
|
2017-03-07 09:58:51 -05:00
|
|
|
s = mesh_state_create(mesh->env, qinfo, NULL,
|
2024-06-26 09:51:58 -04:00
|
|
|
mesh_flags, 0, 0);
|
2007-12-06 10:11:07 -05:00
|
|
|
if(!s) {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2023-07-21 15:05:38 -04:00
|
|
|
/* set detached (it is now) */
|
|
|
|
|
mesh->num_detached_states++;
|
2016-12-06 08:42:51 -05:00
|
|
|
if(unique)
|
|
|
|
|
mesh_state_make_unique(s);
|
2022-02-15 10:20:12 -05:00
|
|
|
s->s.rpz_passthru = rpz_passthru;
|
2021-11-01 08:48:40 -04:00
|
|
|
if(edns->opt_list_in) {
|
|
|
|
|
s->s.edns_opts_front_in = edns_opt_copy_region(edns->opt_list_in,
|
2016-12-06 08:42:51 -05:00
|
|
|
s->s.region);
|
|
|
|
|
if(!s->s.edns_opts_front_in) {
|
2023-05-23 03:23:03 -04:00
|
|
|
mesh_state_delete(&s->s);
|
2016-12-06 08:42:51 -05:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-09-16 07:35:01 -04:00
|
|
|
#ifdef UNBOUND_DEBUG
|
|
|
|
|
n =
|
2013-08-22 10:10:29 -04:00
|
|
|
#else
|
|
|
|
|
(void)
|
2011-09-16 07:35:01 -04:00
|
|
|
#endif
|
|
|
|
|
rbtree_insert(&mesh->all, &s->node);
|
2007-12-06 10:11:07 -05:00
|
|
|
log_assert(n != NULL);
|
|
|
|
|
added = 1;
|
|
|
|
|
}
|
2020-02-05 08:20:27 -05:00
|
|
|
if(!s->reply_list && !s->cb_list) {
|
2007-12-06 10:11:07 -05:00
|
|
|
was_noreply = 1;
|
2020-02-05 08:20:27 -05:00
|
|
|
if(s->super_set.count == 0) {
|
|
|
|
|
was_detached = 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
2007-12-06 10:11:07 -05:00
|
|
|
/* add reply to s */
|
|
|
|
|
if(!mesh_state_add_cb(s, edns, buf, cb, cb_arg, qid, qflags)) {
|
2020-02-05 08:20:27 -05:00
|
|
|
if(added)
|
|
|
|
|
mesh_state_delete(&s->s);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
/* add serve expired timer if not already there */
|
|
|
|
|
if(timeout && !mesh_serve_expired_init(s, timeout)) {
|
2023-07-21 15:05:38 -04:00
|
|
|
if(added)
|
|
|
|
|
mesh_state_delete(&s->s);
|
2020-02-05 08:20:27 -05:00
|
|
|
return 0;
|
2007-12-06 10:11:07 -05:00
|
|
|
}
|
2024-04-10 05:33:52 -04:00
|
|
|
#ifdef USE_CACHEDB
|
2024-04-10 05:21:28 -04:00
|
|
|
if(!timeout && mesh->env->cfg->serve_expired &&
|
|
|
|
|
!mesh->env->cfg->serve_expired_client_timeout &&
|
|
|
|
|
(mesh->env->cachedb_enabled &&
|
|
|
|
|
mesh->env->cfg->cachedb_check_when_serve_expired)) {
|
|
|
|
|
if(!mesh_serve_expired_init(s, -1)) {
|
|
|
|
|
if(added)
|
|
|
|
|
mesh_state_delete(&s->s);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-04-10 05:33:52 -04:00
|
|
|
#endif
|
2007-12-06 10:11:07 -05:00
|
|
|
/* update statistics */
|
|
|
|
|
if(was_detached) {
|
|
|
|
|
log_assert(mesh->num_detached_states > 0);
|
|
|
|
|
mesh->num_detached_states--;
|
|
|
|
|
}
|
|
|
|
|
if(was_noreply) {
|
|
|
|
|
mesh->num_reply_states ++;
|
|
|
|
|
}
|
|
|
|
|
mesh->num_reply_addrs++;
|
|
|
|
|
if(added)
|
|
|
|
|
mesh_run(mesh, s, module_event_new, NULL);
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-19 05:08:29 -04:00
|
|
|
/* Internal backend routine of mesh_new_prefetch(). It takes one additional
|
|
|
|
|
* parameter, 'run', which controls whether to run the prefetch state
|
|
|
|
|
* immediately. When this function is called internally 'run' could be
|
|
|
|
|
* 0 (false), in which case the new state is only made runnable so it
|
|
|
|
|
* will not be run recursively on top of the current state. */
|
|
|
|
|
static void mesh_schedule_prefetch(struct mesh_area* mesh,
|
2022-02-15 10:20:12 -05:00
|
|
|
struct query_info* qinfo, uint16_t qflags, time_t leeway, int run,
|
|
|
|
|
int rpz_passthru)
|
2010-01-07 09:38:18 -05:00
|
|
|
{
|
2024-06-26 09:51:58 -04:00
|
|
|
/* Explicitly set the BIT_RD regardless of the client's flags. This is
|
|
|
|
|
* for a prefetch query (no client attached) but it needs to be treated
|
|
|
|
|
* as a recursion query. */
|
|
|
|
|
uint16_t mesh_flags = BIT_RD|(qflags&BIT_CD);
|
2017-03-07 09:58:51 -05:00
|
|
|
struct mesh_state* s = mesh_area_find(mesh, NULL, qinfo,
|
2024-06-26 09:51:58 -04:00
|
|
|
mesh_flags, 0, 0);
|
2011-09-16 07:35:01 -04:00
|
|
|
#ifdef UNBOUND_DEBUG
|
2017-01-19 05:25:41 -05:00
|
|
|
struct rbnode_type* n;
|
2011-09-16 07:35:01 -04:00
|
|
|
#endif
|
2010-01-07 09:38:18 -05:00
|
|
|
/* already exists, and for a different purpose perhaps.
|
|
|
|
|
* if mesh_no_list, keep it that way. */
|
|
|
|
|
if(s) {
|
|
|
|
|
/* make it ignore the cache from now on */
|
|
|
|
|
if(!s->s.blacklist)
|
|
|
|
|
sock_list_insert(&s->s.blacklist, NULL, 0, s->s.region);
|
2010-01-08 10:59:36 -05:00
|
|
|
if(s->s.prefetch_leeway < leeway)
|
|
|
|
|
s->s.prefetch_leeway = leeway;
|
2010-01-07 09:38:18 -05:00
|
|
|
return;
|
|
|
|
|
}
|
2011-10-24 09:49:59 -04:00
|
|
|
if(!mesh_make_new_space(mesh, NULL)) {
|
2010-01-07 09:38:18 -05:00
|
|
|
verbose(VERB_ALGO, "Too many queries. dropped prefetch.");
|
|
|
|
|
mesh->stats_dropped ++;
|
|
|
|
|
return;
|
|
|
|
|
}
|
2016-12-06 08:42:51 -05:00
|
|
|
|
2024-06-26 09:51:58 -04:00
|
|
|
s = mesh_state_create(mesh->env, qinfo, NULL, mesh_flags, 0, 0);
|
2010-01-07 09:38:18 -05:00
|
|
|
if(!s) {
|
|
|
|
|
log_err("prefetch mesh_state_create: out of memory");
|
|
|
|
|
return;
|
|
|
|
|
}
|
2011-09-16 07:35:01 -04:00
|
|
|
#ifdef UNBOUND_DEBUG
|
|
|
|
|
n =
|
2013-08-22 10:10:29 -04:00
|
|
|
#else
|
|
|
|
|
(void)
|
2011-09-16 07:35:01 -04:00
|
|
|
#endif
|
|
|
|
|
rbtree_insert(&mesh->all, &s->node);
|
2010-01-07 09:38:18 -05:00
|
|
|
log_assert(n != NULL);
|
|
|
|
|
/* set detached (it is now) */
|
|
|
|
|
mesh->num_detached_states++;
|
|
|
|
|
/* make it ignore the cache */
|
|
|
|
|
sock_list_insert(&s->s.blacklist, NULL, 0, s->s.region);
|
2010-01-08 10:59:36 -05:00
|
|
|
s->s.prefetch_leeway = leeway;
|
2010-01-07 09:38:18 -05:00
|
|
|
|
|
|
|
|
if(s->list_select == mesh_no_list) {
|
|
|
|
|
/* move to either the forever or the jostle_list */
|
|
|
|
|
if(mesh->num_forever_states < mesh->max_forever_states) {
|
|
|
|
|
mesh->num_forever_states ++;
|
2021-02-17 07:39:15 -05:00
|
|
|
mesh_list_insert(s, &mesh->forever_first,
|
2010-01-07 09:38:18 -05:00
|
|
|
&mesh->forever_last);
|
|
|
|
|
s->list_select = mesh_forever_list;
|
|
|
|
|
} else {
|
2021-02-17 07:39:15 -05:00
|
|
|
mesh_list_insert(s, &mesh->jostle_first,
|
2010-01-07 09:38:18 -05:00
|
|
|
&mesh->jostle_last);
|
|
|
|
|
s->list_select = mesh_jostle_list;
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-02-15 10:20:12 -05:00
|
|
|
s->s.rpz_passthru = rpz_passthru;
|
2017-09-19 05:08:29 -04:00
|
|
|
|
|
|
|
|
if(!run) {
|
2017-09-19 05:15:59 -04:00
|
|
|
#ifdef UNBOUND_DEBUG
|
|
|
|
|
n =
|
|
|
|
|
#else
|
|
|
|
|
(void)
|
|
|
|
|
#endif
|
2017-09-19 05:08:29 -04:00
|
|
|
rbtree_insert(&mesh->run, &s->run_node);
|
2017-09-19 05:15:59 -04:00
|
|
|
log_assert(n != NULL);
|
2017-09-19 05:08:29 -04:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2010-01-07 09:38:18 -05:00
|
|
|
mesh_run(mesh, s, module_event_new, NULL);
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-17 07:39:15 -05:00
|
|
|
#ifdef CLIENT_SUBNET
|
|
|
|
|
/* Same logic as mesh_schedule_prefetch but tailored to the subnet module logic
|
|
|
|
|
* like passing along the comm_reply info. This will be faked into an EDNS
|
|
|
|
|
* option for processing by the subnet module if the client has not already
|
|
|
|
|
* attached its own ECS data. */
|
|
|
|
|
static void mesh_schedule_prefetch_subnet(struct mesh_area* mesh,
|
|
|
|
|
struct query_info* qinfo, uint16_t qflags, time_t leeway, int run,
|
2023-07-06 15:57:27 -04:00
|
|
|
int rpz_passthru, struct sockaddr_storage* addr, struct edns_option* edns_list)
|
2021-02-17 07:39:15 -05:00
|
|
|
{
|
|
|
|
|
struct mesh_state* s = NULL;
|
|
|
|
|
struct edns_option* opt = NULL;
|
|
|
|
|
#ifdef UNBOUND_DEBUG
|
|
|
|
|
struct rbnode_type* n;
|
|
|
|
|
#endif
|
2024-06-26 09:51:58 -04:00
|
|
|
/* Explicitly set the BIT_RD regardless of the client's flags. This is
|
|
|
|
|
* for a prefetch query (no client attached) but it needs to be treated
|
|
|
|
|
* as a recursion query. */
|
|
|
|
|
uint16_t mesh_flags = BIT_RD|(qflags&BIT_CD);
|
2021-02-17 07:39:15 -05:00
|
|
|
if(!mesh_make_new_space(mesh, NULL)) {
|
|
|
|
|
verbose(VERB_ALGO, "Too many queries. dropped prefetch.");
|
|
|
|
|
mesh->stats_dropped ++;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-26 09:51:58 -04:00
|
|
|
s = mesh_state_create(mesh->env, qinfo, NULL, mesh_flags, 0, 0);
|
2021-02-17 07:39:15 -05:00
|
|
|
if(!s) {
|
|
|
|
|
log_err("prefetch_subnet mesh_state_create: out of memory");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
mesh_state_make_unique(s);
|
|
|
|
|
|
|
|
|
|
opt = edns_opt_list_find(edns_list, mesh->env->cfg->client_subnet_opcode);
|
|
|
|
|
if(opt) {
|
|
|
|
|
/* Use the client's ECS data */
|
|
|
|
|
if(!edns_opt_list_append(&s->s.edns_opts_front_in, opt->opt_code,
|
|
|
|
|
opt->opt_len, opt->opt_data, s->s.region)) {
|
|
|
|
|
log_err("prefetch_subnet edns_opt_list_append: out of memory");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
2023-01-31 09:16:38 -05:00
|
|
|
/* Store the client's address. Later in the subnet module,
|
|
|
|
|
* it is decided whether to include an ECS option or not.
|
|
|
|
|
*/
|
2023-07-07 10:27:49 -04:00
|
|
|
s->s.client_addr = *addr;
|
2021-02-17 07:39:15 -05:00
|
|
|
}
|
|
|
|
|
#ifdef UNBOUND_DEBUG
|
|
|
|
|
n =
|
|
|
|
|
#else
|
|
|
|
|
(void)
|
|
|
|
|
#endif
|
|
|
|
|
rbtree_insert(&mesh->all, &s->node);
|
|
|
|
|
log_assert(n != NULL);
|
|
|
|
|
/* set detached (it is now) */
|
|
|
|
|
mesh->num_detached_states++;
|
|
|
|
|
/* make it ignore the cache */
|
|
|
|
|
sock_list_insert(&s->s.blacklist, NULL, 0, s->s.region);
|
|
|
|
|
s->s.prefetch_leeway = leeway;
|
|
|
|
|
|
|
|
|
|
if(s->list_select == mesh_no_list) {
|
|
|
|
|
/* move to either the forever or the jostle_list */
|
|
|
|
|
if(mesh->num_forever_states < mesh->max_forever_states) {
|
|
|
|
|
mesh->num_forever_states ++;
|
|
|
|
|
mesh_list_insert(s, &mesh->forever_first,
|
|
|
|
|
&mesh->forever_last);
|
|
|
|
|
s->list_select = mesh_forever_list;
|
|
|
|
|
} else {
|
|
|
|
|
mesh_list_insert(s, &mesh->jostle_first,
|
|
|
|
|
&mesh->jostle_last);
|
|
|
|
|
s->list_select = mesh_jostle_list;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
s->s.rpz_passthru = rpz_passthru;
|
|
|
|
|
|
|
|
|
|
if(!run) {
|
|
|
|
|
#ifdef UNBOUND_DEBUG
|
|
|
|
|
n =
|
|
|
|
|
#else
|
|
|
|
|
(void)
|
|
|
|
|
#endif
|
|
|
|
|
rbtree_insert(&mesh->run, &s->run_node);
|
|
|
|
|
log_assert(n != NULL);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
mesh_run(mesh, s, module_event_new, NULL);
|
|
|
|
|
}
|
|
|
|
|
#endif /* CLIENT_SUBNET */
|
|
|
|
|
|
2020-02-05 08:20:27 -05:00
|
|
|
void mesh_new_prefetch(struct mesh_area* mesh, struct query_info* qinfo,
|
2021-02-17 07:39:15 -05:00
|
|
|
uint16_t qflags, time_t leeway, int rpz_passthru,
|
2023-07-06 15:57:27 -04:00
|
|
|
struct sockaddr_storage* addr, struct edns_option* opt_list)
|
2020-02-05 08:20:27 -05:00
|
|
|
{
|
2023-07-06 15:57:27 -04:00
|
|
|
(void)addr;
|
2021-02-17 07:39:15 -05:00
|
|
|
(void)opt_list;
|
|
|
|
|
#ifdef CLIENT_SUBNET
|
2023-07-06 15:57:27 -04:00
|
|
|
if(addr)
|
2021-02-17 07:39:15 -05:00
|
|
|
mesh_schedule_prefetch_subnet(mesh, qinfo, qflags, leeway, 1,
|
2023-07-06 15:57:27 -04:00
|
|
|
rpz_passthru, addr, opt_list);
|
2021-02-17 07:39:15 -05:00
|
|
|
else
|
|
|
|
|
#endif
|
|
|
|
|
mesh_schedule_prefetch(mesh, qinfo, qflags, leeway, 1,
|
|
|
|
|
rpz_passthru);
|
2020-02-05 08:20:27 -05:00
|
|
|
}
|
|
|
|
|
|
2007-06-25 09:54:03 -04:00
|
|
|
void mesh_report_reply(struct mesh_area* mesh, struct outbound_entry* e,
|
2008-10-06 10:46:22 -04:00
|
|
|
struct comm_reply* reply, int what)
|
2007-06-25 09:54:03 -04:00
|
|
|
{
|
2008-10-06 10:46:22 -04:00
|
|
|
enum module_ev event = module_event_reply;
|
2007-06-25 09:54:03 -04:00
|
|
|
e->qstate->reply = reply;
|
2008-10-06 10:46:22 -04:00
|
|
|
if(what != NETEVENT_NOERROR) {
|
|
|
|
|
event = module_event_noreply;
|
|
|
|
|
if(what == NETEVENT_CAPSFAIL)
|
|
|
|
|
event = module_event_capsfail;
|
|
|
|
|
}
|
|
|
|
|
mesh_run(mesh, e->qstate->mesh_info, event, e);
|
2007-06-25 09:54:03 -04:00
|
|
|
}
|
|
|
|
|
|
Fast Reload Option (#1042)
* - fast-reload, add unbound-control fast_reload
* - fast-reload, make a thread to service the unbound-control command.
* - fast-reload, communication sockets for information transfer.
* - fast-reload, fix compile for unbound-dnstap-socket.
* - fast-reload, set nonblocking communication to keep the server thread
responding to DNS requests.
* - fast-reload, poll routine to test for readiness, timeout fails connection.
* - fast-reload, detect loop in sock_poll_timeout routine.
* - fast-reload, send done and exited notification.
* - fast-reload, defines for constants in ipc.
* - fast-reload, ipc socket recv and send resists partial reads and writes and
can continue byte by byte. Also it can continue after an interrupt.
* - fast-reload, send exit command to thread when done.
* - fast-reload, output strings for client on string list.
* - fast-reload, add newline to terminal output.
* - fast-reload, send client string to remote client.
* - fast-reload, better debug output.
* - fast-reload, print queue structure, for output to the remote client.
* - fast-reload, move print items to print queue from fast_reload_thread struct.
* - fast-reload, keep list of pending print queue items in daemon struct.
* - fast-reload, comment explains in_list for printq to print remainder.
* - fast-reload, unit test testdata/fast_reload_thread.tdir that tests the
thread output.
* - fast-reload, fix test link for fast_reload_printq_list_delete function.
* - fast-reload, reread config file from disk.
* - fast-reload, unshare forwards, making the structure locked, with an rwlock.
* - fast-reload, for nonthreaded, the unbound-control commands forward,
forward_add and forward_delete should be distributed to other processes,
but when threaded, they should not be distributed to other threads because
the structure is not thread specific any more.
* - fast-reload, unshared stub hints, making the structure locked, with an rwlock.
* - fast-reload, helpful comments for hints lookup function return value.
* - fast-reload, fix bug in fast reload printout, the strlist appendlist routine,
and printout time statistics after the reload is done.
* - fast-reload, keep track of reloadtime and deletestime and print them.
* - fast-reload, keep track of constructtime and print it.
* - fast-reload, construct new items.
* - fast-reload, better comment.
* - fast-reload, reload the config and swap trees for forwards and stub hints.
* - fast-reload, in forwards_swap_tree set protection of trees with locks.
* - fast-reload, in hints_swap_tree also swap the node count of the trees.
* - fast-reload, reload ipc to stop and start threads.
* - fast-reload, unused forward declarations removed.
* - fast-reload, unit test that fast reload works with forwards and stubs.
* - fast-reload, fix clang analyzer warnings.
* - fast-reload, small documentation entry in unbound-control -h output.
* - fast-reload, printout memory use by fast reload, in bytes.
* - fast-reload, compile without threads.
* - fast-reload, document fast_reload in man page.
* - fast-reload, print ok when done successfully.
* - fast-reload, option for fast-reload commandline, +v verbosity option,
with timing and memory use output.
* - fast-reload, option for fast-reload commandline, +p does not pause threads.
* - fast-reload, option for fast-reload commandline, +d drops mesh queries.
* - fast-reload, fix to poll every thread with nopause to make certain that
resources are not held by the threads and can be deleted.
* - fast-reload, fix to use atomic store for config variables with nopause.
* - fast-reload, reload views.
* - fast-reload, when tag defines are different, it drops the queries.
* - fast-reload, fix tag define check.
* - fast-reload, document that tag change causes drop of queries.
* - fast-reload, fix space in documentation man page.
* - fast-reload, copy respip client information to query state, put views tree
in module env for lookup.
* - fast-reload, nicer respip view comparison.
* - fast-reload, respip global set is in module env.
* - fast-reload, document that respip_client_info acl info is copied.
* - fast-reload, reload the respip_set.
* - fast-reload, document no pause and pick up of use_response_ip boolean.
* - fast-reload, fix test compile.
* - fast-reload, reload local zones.
* Update locking management for iter_fwd and iter_hints methods. (#1054)
fast reload, move most of the locking management to iter_fwd and
iter_hints methods. The caller still has the ability to handle its
own locking, if desired, for atomic operations on sets of different
structs.
Co-authored-by: Wouter Wijngaards <wcawijngaards@users.noreply.github.com>
* - fast-reload, reload access-control.
* - fast-reload, reload access control interface, such as interface-action.
* - fast-reload, reload tcp-connection-limit.
* - fast-reload, improve comments on acl_list and tcl_list swap tree.
* - fast-reload, fixup references to old tcp connection limits in open tcp
connections.
* - fast-reload, fixup to clean tcp connection also for different linked order.
* - fast-reload, if no tcp connection limits existed, no need to remove
references for that.
* - fast-reload, document more options that work and do not work.
* - fast-reload, reload auth_zone and rpz data.
* - fast-reload, fix auth_zones_get_mem.
* - fast-reload, fix compilation of testbound for the new comm_timer_get_mem
reference in remote control.
* - fast-reload, change use_rpz with reload.
* - fast-reload, list changes in auth zones and stop zonemd callbacks for
deleted auth zones.
* - fast-reload, note xtree is not swapped, and why it is not swapped.
* - fast-reload, for added auth zones, pick up zone transfer and zonemd tasks.
* - fast-reload, unlock xfr when done with transfer pick up.
* - fast-reload, unlock z when picking up the xfr for it during transfer task
pick up.
* - fast-reload, pick up task changes for added, deleted and modified auth zones.
* - fast-reload, remove xfr of auth zone deletion without tasks.
* - fast-reload, pick up zone transfer config.
* - fast-reload, the main worker thread picks up the transfer tasks and also
performs setup of the xfer struct.
* - fast-reload, keep writelock on newzone when auth zone changes.
* - fast-reload, change cachedb_enabled setting.
* - fast-reload, pick up edns-strings config.
* - fast-reload, note that settings are not updated.
* - fast-reload, pick up dnstap config.
* - fast-reload, dnstap options that need to be loaded without +p.
* - fast-reload, fix auth zone reload
* - fast-reload, remove debug for auth zone test.
* - fast-reload, fix auth zone reload with zone transfer.
* - fast-reload, fix auth zone reload lock order.
* - fast-reload, remove debug from fast reload test.
* - fast-reload, remove unused function.
* - fast-reload, fix the worker trust anchor probe timer lock acquisition in
the probe answer callback routine for trust anchor probes.
* - fast-reload, reload trust anchors.
* - fast-reload, fix trust anchor reload lock on autr global data and test
for trust anchor reload.
* - fast-reload, adjust cache sizes.
* - fast-reload, reload cache sizes when changed.
* - fast-reload, reload validator env changes.
* - fast-reload, reload mesh changes.
* - fast-reload, check for incompatible changes.
* - fast-reload, improve error text for incompatible change.
* - fast-reload, fix check config option compatibility.
* - fast-reload, improve error text for nopause change.
* - fast-reload, fix spelling of incompatible options.
* - fast-reload, reload target-fetch-policy, outbound-msg-retry, max-sent-count
and max-query-restarts.
* - fast-reload, check nopause config change for target-fetch-policy.
* - fast-reload, reload do-not-query-address, private-address and capt-exempt.
* - fast-reload, check nopause config change for do-not-query-address,
private-address and capt-exempt.
* - fast-reload, check fast reload not possible due to interface and
outgoing-interface changes.
* - fast-reload, reload nat64 settings.
* - fast-reload, reload settings stored in the infra structure.
* - fast-reload, fix modstack lookup and remove outgoing-range check.
* - fast-reload, more explanation for config parse failure.
* - fast-reload, reload worker outside network changes.
* - fast-reload, detect incompatible changes in network settings.
* fast-reload, commit test files.
* - fast-reload, fix warnings for call types in windows compile.
* - fast-reload, fix warnings and comm_point_internal for tcp wouldblock calls.
* - fast-reload, extend lock checks for repeat thread ids.
* - fast-reload, additional test cases, cache change and tag changes.
* - fast-reload, fix documentation for auth_zone_verify_zonemd_with_key.
* - fast-reload, fix copy_cfg type casts and memory leak on config parse failure.
* - fast-reload, fix use of WSAPoll.
* Review comments for the fast reload feature (#1259)
* - fast-reload review, respip set can be null from a view.
* - fast-reload review, typos.
* - fast-reload review, keep clang static analyzer happy.
* - fast-reload review, don't forget to copy tag_actions.
* - fast-reload review, less indentation.
* - fast-reload review, don't leak respip_actions when reloading.
* - fast-reload review, protect NULL pointer dereference in get_mem
functions.
* - fast-reload review, add fast_reload_most_options.tdir to test most
options with high verbosity when fast reloading.
* - fast-reload review, don't skip new line on long error printouts.
* - fast-reload review, typo.
* - fast-reload review, use new_z for consistency.
* - fast-reload review, nit for unlock ordering to make eye comparison
with the lock counterpart easier.
* - fast-reload review, in case of error the sockets are already closed.
* - fast-reload review, identation.
* - fast-reload review, add static keywords.
* - fast-reload review, update unbound-control usage text.
* - fast-reload review, updates to the man page.
* - fast-reload, the fast-reload command is experimental.
* - fast-reload, fix compile of doqclient for fast reload functions.
* Changelog comment for #1042
- Merge #1042: Fast Reload. The unbound-control fast_reload is added.
It reads changed config in a thread, then only briefly pauses the
service threads, that keep running. DNS service is only interrupted
briefly, less than a second.
---------
Co-authored-by: Yorgos Thessalonikefs <yorgos@nlnetlabs.nl>
2025-03-31 09:25:24 -04:00
|
|
|
/** copy strlist to region */
|
|
|
|
|
static struct config_strlist*
|
|
|
|
|
cfg_region_strlist_copy(struct regional* region, struct config_strlist* list)
|
|
|
|
|
{
|
|
|
|
|
struct config_strlist* result = NULL, *last = NULL, *s = list;
|
|
|
|
|
while(s) {
|
|
|
|
|
struct config_strlist* n = regional_alloc_zero(region,
|
|
|
|
|
sizeof(*n));
|
|
|
|
|
if(!n)
|
|
|
|
|
return NULL;
|
|
|
|
|
n->str = regional_strdup(region, s->str);
|
|
|
|
|
if(!n->str)
|
|
|
|
|
return NULL;
|
|
|
|
|
if(last)
|
|
|
|
|
last->next = n;
|
|
|
|
|
else result = n;
|
|
|
|
|
last = n;
|
|
|
|
|
s = s->next;
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** Copy the client info to the query region. */
|
|
|
|
|
static struct respip_client_info*
|
|
|
|
|
mesh_copy_client_info(struct regional* region, struct respip_client_info* cinfo)
|
|
|
|
|
{
|
|
|
|
|
size_t i;
|
|
|
|
|
struct respip_client_info* client_info;
|
|
|
|
|
client_info = regional_alloc_init(region, cinfo, sizeof(*cinfo));
|
|
|
|
|
if(!client_info)
|
|
|
|
|
return NULL;
|
|
|
|
|
/* Copy the client_info so that if the configuration changes,
|
|
|
|
|
* then the data stays valid. */
|
2025-04-04 02:57:24 -04:00
|
|
|
if(cinfo->taglist) {
|
|
|
|
|
client_info->taglist = regional_alloc_init(region, cinfo->taglist,
|
|
|
|
|
cinfo->taglen);
|
|
|
|
|
if(!client_info->taglist)
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
if(cinfo->tag_actions) {
|
|
|
|
|
client_info->tag_actions = regional_alloc_init(region, cinfo->tag_actions,
|
|
|
|
|
cinfo->tag_actions_size);
|
|
|
|
|
if(!client_info->tag_actions)
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
if(cinfo->tag_datas) {
|
|
|
|
|
client_info->tag_datas = regional_alloc_zero(region,
|
|
|
|
|
sizeof(struct config_strlist*)*cinfo->tag_datas_size);
|
|
|
|
|
if(!client_info->tag_datas)
|
|
|
|
|
return NULL;
|
|
|
|
|
for(i=0; i<cinfo->tag_datas_size; i++) {
|
|
|
|
|
if(cinfo->tag_datas[i]) {
|
|
|
|
|
client_info->tag_datas[i] = cfg_region_strlist_copy(
|
|
|
|
|
region, cinfo->tag_datas[i]);
|
|
|
|
|
if(!client_info->tag_datas[i])
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
Fast Reload Option (#1042)
* - fast-reload, add unbound-control fast_reload
* - fast-reload, make a thread to service the unbound-control command.
* - fast-reload, communication sockets for information transfer.
* - fast-reload, fix compile for unbound-dnstap-socket.
* - fast-reload, set nonblocking communication to keep the server thread
responding to DNS requests.
* - fast-reload, poll routine to test for readiness, timeout fails connection.
* - fast-reload, detect loop in sock_poll_timeout routine.
* - fast-reload, send done and exited notification.
* - fast-reload, defines for constants in ipc.
* - fast-reload, ipc socket recv and send resists partial reads and writes and
can continue byte by byte. Also it can continue after an interrupt.
* - fast-reload, send exit command to thread when done.
* - fast-reload, output strings for client on string list.
* - fast-reload, add newline to terminal output.
* - fast-reload, send client string to remote client.
* - fast-reload, better debug output.
* - fast-reload, print queue structure, for output to the remote client.
* - fast-reload, move print items to print queue from fast_reload_thread struct.
* - fast-reload, keep list of pending print queue items in daemon struct.
* - fast-reload, comment explains in_list for printq to print remainder.
* - fast-reload, unit test testdata/fast_reload_thread.tdir that tests the
thread output.
* - fast-reload, fix test link for fast_reload_printq_list_delete function.
* - fast-reload, reread config file from disk.
* - fast-reload, unshare forwards, making the structure locked, with an rwlock.
* - fast-reload, for nonthreaded, the unbound-control commands forward,
forward_add and forward_delete should be distributed to other processes,
but when threaded, they should not be distributed to other threads because
the structure is not thread specific any more.
* - fast-reload, unshared stub hints, making the structure locked, with an rwlock.
* - fast-reload, helpful comments for hints lookup function return value.
* - fast-reload, fix bug in fast reload printout, the strlist appendlist routine,
and printout time statistics after the reload is done.
* - fast-reload, keep track of reloadtime and deletestime and print them.
* - fast-reload, keep track of constructtime and print it.
* - fast-reload, construct new items.
* - fast-reload, better comment.
* - fast-reload, reload the config and swap trees for forwards and stub hints.
* - fast-reload, in forwards_swap_tree set protection of trees with locks.
* - fast-reload, in hints_swap_tree also swap the node count of the trees.
* - fast-reload, reload ipc to stop and start threads.
* - fast-reload, unused forward declarations removed.
* - fast-reload, unit test that fast reload works with forwards and stubs.
* - fast-reload, fix clang analyzer warnings.
* - fast-reload, small documentation entry in unbound-control -h output.
* - fast-reload, printout memory use by fast reload, in bytes.
* - fast-reload, compile without threads.
* - fast-reload, document fast_reload in man page.
* - fast-reload, print ok when done successfully.
* - fast-reload, option for fast-reload commandline, +v verbosity option,
with timing and memory use output.
* - fast-reload, option for fast-reload commandline, +p does not pause threads.
* - fast-reload, option for fast-reload commandline, +d drops mesh queries.
* - fast-reload, fix to poll every thread with nopause to make certain that
resources are not held by the threads and can be deleted.
* - fast-reload, fix to use atomic store for config variables with nopause.
* - fast-reload, reload views.
* - fast-reload, when tag defines are different, it drops the queries.
* - fast-reload, fix tag define check.
* - fast-reload, document that tag change causes drop of queries.
* - fast-reload, fix space in documentation man page.
* - fast-reload, copy respip client information to query state, put views tree
in module env for lookup.
* - fast-reload, nicer respip view comparison.
* - fast-reload, respip global set is in module env.
* - fast-reload, document that respip_client_info acl info is copied.
* - fast-reload, reload the respip_set.
* - fast-reload, document no pause and pick up of use_response_ip boolean.
* - fast-reload, fix test compile.
* - fast-reload, reload local zones.
* Update locking management for iter_fwd and iter_hints methods. (#1054)
fast reload, move most of the locking management to iter_fwd and
iter_hints methods. The caller still has the ability to handle its
own locking, if desired, for atomic operations on sets of different
structs.
Co-authored-by: Wouter Wijngaards <wcawijngaards@users.noreply.github.com>
* - fast-reload, reload access-control.
* - fast-reload, reload access control interface, such as interface-action.
* - fast-reload, reload tcp-connection-limit.
* - fast-reload, improve comments on acl_list and tcl_list swap tree.
* - fast-reload, fixup references to old tcp connection limits in open tcp
connections.
* - fast-reload, fixup to clean tcp connection also for different linked order.
* - fast-reload, if no tcp connection limits existed, no need to remove
references for that.
* - fast-reload, document more options that work and do not work.
* - fast-reload, reload auth_zone and rpz data.
* - fast-reload, fix auth_zones_get_mem.
* - fast-reload, fix compilation of testbound for the new comm_timer_get_mem
reference in remote control.
* - fast-reload, change use_rpz with reload.
* - fast-reload, list changes in auth zones and stop zonemd callbacks for
deleted auth zones.
* - fast-reload, note xtree is not swapped, and why it is not swapped.
* - fast-reload, for added auth zones, pick up zone transfer and zonemd tasks.
* - fast-reload, unlock xfr when done with transfer pick up.
* - fast-reload, unlock z when picking up the xfr for it during transfer task
pick up.
* - fast-reload, pick up task changes for added, deleted and modified auth zones.
* - fast-reload, remove xfr of auth zone deletion without tasks.
* - fast-reload, pick up zone transfer config.
* - fast-reload, the main worker thread picks up the transfer tasks and also
performs setup of the xfer struct.
* - fast-reload, keep writelock on newzone when auth zone changes.
* - fast-reload, change cachedb_enabled setting.
* - fast-reload, pick up edns-strings config.
* - fast-reload, note that settings are not updated.
* - fast-reload, pick up dnstap config.
* - fast-reload, dnstap options that need to be loaded without +p.
* - fast-reload, fix auth zone reload
* - fast-reload, remove debug for auth zone test.
* - fast-reload, fix auth zone reload with zone transfer.
* - fast-reload, fix auth zone reload lock order.
* - fast-reload, remove debug from fast reload test.
* - fast-reload, remove unused function.
* - fast-reload, fix the worker trust anchor probe timer lock acquisition in
the probe answer callback routine for trust anchor probes.
* - fast-reload, reload trust anchors.
* - fast-reload, fix trust anchor reload lock on autr global data and test
for trust anchor reload.
* - fast-reload, adjust cache sizes.
* - fast-reload, reload cache sizes when changed.
* - fast-reload, reload validator env changes.
* - fast-reload, reload mesh changes.
* - fast-reload, check for incompatible changes.
* - fast-reload, improve error text for incompatible change.
* - fast-reload, fix check config option compatibility.
* - fast-reload, improve error text for nopause change.
* - fast-reload, fix spelling of incompatible options.
* - fast-reload, reload target-fetch-policy, outbound-msg-retry, max-sent-count
and max-query-restarts.
* - fast-reload, check nopause config change for target-fetch-policy.
* - fast-reload, reload do-not-query-address, private-address and capt-exempt.
* - fast-reload, check nopause config change for do-not-query-address,
private-address and capt-exempt.
* - fast-reload, check fast reload not possible due to interface and
outgoing-interface changes.
* - fast-reload, reload nat64 settings.
* - fast-reload, reload settings stored in the infra structure.
* - fast-reload, fix modstack lookup and remove outgoing-range check.
* - fast-reload, more explanation for config parse failure.
* - fast-reload, reload worker outside network changes.
* - fast-reload, detect incompatible changes in network settings.
* fast-reload, commit test files.
* - fast-reload, fix warnings for call types in windows compile.
* - fast-reload, fix warnings and comm_point_internal for tcp wouldblock calls.
* - fast-reload, extend lock checks for repeat thread ids.
* - fast-reload, additional test cases, cache change and tag changes.
* - fast-reload, fix documentation for auth_zone_verify_zonemd_with_key.
* - fast-reload, fix copy_cfg type casts and memory leak on config parse failure.
* - fast-reload, fix use of WSAPoll.
* Review comments for the fast reload feature (#1259)
* - fast-reload review, respip set can be null from a view.
* - fast-reload review, typos.
* - fast-reload review, keep clang static analyzer happy.
* - fast-reload review, don't forget to copy tag_actions.
* - fast-reload review, less indentation.
* - fast-reload review, don't leak respip_actions when reloading.
* - fast-reload review, protect NULL pointer dereference in get_mem
functions.
* - fast-reload review, add fast_reload_most_options.tdir to test most
options with high verbosity when fast reloading.
* - fast-reload review, don't skip new line on long error printouts.
* - fast-reload review, typo.
* - fast-reload review, use new_z for consistency.
* - fast-reload review, nit for unlock ordering to make eye comparison
with the lock counterpart easier.
* - fast-reload review, in case of error the sockets are already closed.
* - fast-reload review, identation.
* - fast-reload review, add static keywords.
* - fast-reload review, update unbound-control usage text.
* - fast-reload review, updates to the man page.
* - fast-reload, the fast-reload command is experimental.
* - fast-reload, fix compile of doqclient for fast reload functions.
* Changelog comment for #1042
- Merge #1042: Fast Reload. The unbound-control fast_reload is added.
It reads changed config in a thread, then only briefly pauses the
service threads, that keep running. DNS service is only interrupted
briefly, less than a second.
---------
Co-authored-by: Yorgos Thessalonikefs <yorgos@nlnetlabs.nl>
2025-03-31 09:25:24 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if(cinfo->view) {
|
|
|
|
|
/* Do not copy the view pointer but store a name instead.
|
|
|
|
|
* The name is looked up later when done, this means that
|
|
|
|
|
* the view tree can be changed, by reloads. */
|
|
|
|
|
client_info->view = NULL;
|
|
|
|
|
client_info->view_name = regional_strdup(region,
|
|
|
|
|
cinfo->view->name);
|
|
|
|
|
if(!client_info->view_name)
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
return client_info;
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-03 10:00:46 -04:00
|
|
|
struct mesh_state*
|
|
|
|
|
mesh_state_create(struct module_env* env, struct query_info* qinfo,
|
2017-03-07 09:58:51 -05:00
|
|
|
struct respip_client_info* cinfo, uint16_t qflags, int prime,
|
|
|
|
|
int valrec)
|
2007-06-22 08:39:08 -04:00
|
|
|
{
|
2007-10-18 18:17:02 -04:00
|
|
|
struct regional* region = alloc_reg_obtain(env->alloc);
|
2007-06-22 08:39:08 -04:00
|
|
|
struct mesh_state* mstate;
|
|
|
|
|
int i;
|
|
|
|
|
if(!region)
|
|
|
|
|
return NULL;
|
2023-04-20 11:39:55 -04:00
|
|
|
mstate = (struct mesh_state*)regional_alloc(region,
|
2007-06-22 08:39:08 -04:00
|
|
|
sizeof(struct mesh_state));
|
|
|
|
|
if(!mstate) {
|
2007-10-18 18:17:02 -04:00
|
|
|
alloc_reg_release(env->alloc, region);
|
2007-06-22 08:39:08 -04:00
|
|
|
return NULL;
|
|
|
|
|
}
|
2007-06-25 09:54:03 -04:00
|
|
|
memset(mstate, 0, sizeof(*mstate));
|
2007-06-22 08:39:08 -04:00
|
|
|
mstate->node = *RBTREE_NULL;
|
|
|
|
|
mstate->run_node = *RBTREE_NULL;
|
|
|
|
|
mstate->node.key = mstate;
|
|
|
|
|
mstate->run_node.key = mstate;
|
|
|
|
|
mstate->reply_list = NULL;
|
2008-09-02 09:04:47 -04:00
|
|
|
mstate->list_select = mesh_no_list;
|
2008-11-05 05:38:22 -05:00
|
|
|
mstate->replies_sent = 0;
|
2007-06-22 08:39:08 -04:00
|
|
|
rbtree_init(&mstate->super_set, &mesh_state_ref_compare);
|
|
|
|
|
rbtree_init(&mstate->sub_set, &mesh_state_ref_compare);
|
2007-10-03 04:36:47 -04:00
|
|
|
mstate->num_activated = 0;
|
2016-12-06 08:42:51 -05:00
|
|
|
mstate->unique = NULL;
|
2007-06-22 08:39:08 -04:00
|
|
|
/* init module qstate */
|
|
|
|
|
mstate->s.qinfo.qtype = qinfo->qtype;
|
|
|
|
|
mstate->s.qinfo.qclass = qinfo->qclass;
|
2016-10-20 11:05:30 -04:00
|
|
|
mstate->s.qinfo.local_alias = NULL;
|
2007-06-22 08:39:08 -04:00
|
|
|
mstate->s.qinfo.qname_len = qinfo->qname_len;
|
2007-10-18 16:31:43 -04:00
|
|
|
mstate->s.qinfo.qname = regional_alloc_init(region, qinfo->qname,
|
2007-06-22 08:39:08 -04:00
|
|
|
qinfo->qname_len);
|
|
|
|
|
if(!mstate->s.qinfo.qname) {
|
2007-10-18 18:17:02 -04:00
|
|
|
alloc_reg_release(env->alloc, region);
|
2007-06-22 08:39:08 -04:00
|
|
|
return NULL;
|
|
|
|
|
}
|
2017-03-07 09:58:51 -05:00
|
|
|
if(cinfo) {
|
Fast Reload Option (#1042)
* - fast-reload, add unbound-control fast_reload
* - fast-reload, make a thread to service the unbound-control command.
* - fast-reload, communication sockets for information transfer.
* - fast-reload, fix compile for unbound-dnstap-socket.
* - fast-reload, set nonblocking communication to keep the server thread
responding to DNS requests.
* - fast-reload, poll routine to test for readiness, timeout fails connection.
* - fast-reload, detect loop in sock_poll_timeout routine.
* - fast-reload, send done and exited notification.
* - fast-reload, defines for constants in ipc.
* - fast-reload, ipc socket recv and send resists partial reads and writes and
can continue byte by byte. Also it can continue after an interrupt.
* - fast-reload, send exit command to thread when done.
* - fast-reload, output strings for client on string list.
* - fast-reload, add newline to terminal output.
* - fast-reload, send client string to remote client.
* - fast-reload, better debug output.
* - fast-reload, print queue structure, for output to the remote client.
* - fast-reload, move print items to print queue from fast_reload_thread struct.
* - fast-reload, keep list of pending print queue items in daemon struct.
* - fast-reload, comment explains in_list for printq to print remainder.
* - fast-reload, unit test testdata/fast_reload_thread.tdir that tests the
thread output.
* - fast-reload, fix test link for fast_reload_printq_list_delete function.
* - fast-reload, reread config file from disk.
* - fast-reload, unshare forwards, making the structure locked, with an rwlock.
* - fast-reload, for nonthreaded, the unbound-control commands forward,
forward_add and forward_delete should be distributed to other processes,
but when threaded, they should not be distributed to other threads because
the structure is not thread specific any more.
* - fast-reload, unshared stub hints, making the structure locked, with an rwlock.
* - fast-reload, helpful comments for hints lookup function return value.
* - fast-reload, fix bug in fast reload printout, the strlist appendlist routine,
and printout time statistics after the reload is done.
* - fast-reload, keep track of reloadtime and deletestime and print them.
* - fast-reload, keep track of constructtime and print it.
* - fast-reload, construct new items.
* - fast-reload, better comment.
* - fast-reload, reload the config and swap trees for forwards and stub hints.
* - fast-reload, in forwards_swap_tree set protection of trees with locks.
* - fast-reload, in hints_swap_tree also swap the node count of the trees.
* - fast-reload, reload ipc to stop and start threads.
* - fast-reload, unused forward declarations removed.
* - fast-reload, unit test that fast reload works with forwards and stubs.
* - fast-reload, fix clang analyzer warnings.
* - fast-reload, small documentation entry in unbound-control -h output.
* - fast-reload, printout memory use by fast reload, in bytes.
* - fast-reload, compile without threads.
* - fast-reload, document fast_reload in man page.
* - fast-reload, print ok when done successfully.
* - fast-reload, option for fast-reload commandline, +v verbosity option,
with timing and memory use output.
* - fast-reload, option for fast-reload commandline, +p does not pause threads.
* - fast-reload, option for fast-reload commandline, +d drops mesh queries.
* - fast-reload, fix to poll every thread with nopause to make certain that
resources are not held by the threads and can be deleted.
* - fast-reload, fix to use atomic store for config variables with nopause.
* - fast-reload, reload views.
* - fast-reload, when tag defines are different, it drops the queries.
* - fast-reload, fix tag define check.
* - fast-reload, document that tag change causes drop of queries.
* - fast-reload, fix space in documentation man page.
* - fast-reload, copy respip client information to query state, put views tree
in module env for lookup.
* - fast-reload, nicer respip view comparison.
* - fast-reload, respip global set is in module env.
* - fast-reload, document that respip_client_info acl info is copied.
* - fast-reload, reload the respip_set.
* - fast-reload, document no pause and pick up of use_response_ip boolean.
* - fast-reload, fix test compile.
* - fast-reload, reload local zones.
* Update locking management for iter_fwd and iter_hints methods. (#1054)
fast reload, move most of the locking management to iter_fwd and
iter_hints methods. The caller still has the ability to handle its
own locking, if desired, for atomic operations on sets of different
structs.
Co-authored-by: Wouter Wijngaards <wcawijngaards@users.noreply.github.com>
* - fast-reload, reload access-control.
* - fast-reload, reload access control interface, such as interface-action.
* - fast-reload, reload tcp-connection-limit.
* - fast-reload, improve comments on acl_list and tcl_list swap tree.
* - fast-reload, fixup references to old tcp connection limits in open tcp
connections.
* - fast-reload, fixup to clean tcp connection also for different linked order.
* - fast-reload, if no tcp connection limits existed, no need to remove
references for that.
* - fast-reload, document more options that work and do not work.
* - fast-reload, reload auth_zone and rpz data.
* - fast-reload, fix auth_zones_get_mem.
* - fast-reload, fix compilation of testbound for the new comm_timer_get_mem
reference in remote control.
* - fast-reload, change use_rpz with reload.
* - fast-reload, list changes in auth zones and stop zonemd callbacks for
deleted auth zones.
* - fast-reload, note xtree is not swapped, and why it is not swapped.
* - fast-reload, for added auth zones, pick up zone transfer and zonemd tasks.
* - fast-reload, unlock xfr when done with transfer pick up.
* - fast-reload, unlock z when picking up the xfr for it during transfer task
pick up.
* - fast-reload, pick up task changes for added, deleted and modified auth zones.
* - fast-reload, remove xfr of auth zone deletion without tasks.
* - fast-reload, pick up zone transfer config.
* - fast-reload, the main worker thread picks up the transfer tasks and also
performs setup of the xfer struct.
* - fast-reload, keep writelock on newzone when auth zone changes.
* - fast-reload, change cachedb_enabled setting.
* - fast-reload, pick up edns-strings config.
* - fast-reload, note that settings are not updated.
* - fast-reload, pick up dnstap config.
* - fast-reload, dnstap options that need to be loaded without +p.
* - fast-reload, fix auth zone reload
* - fast-reload, remove debug for auth zone test.
* - fast-reload, fix auth zone reload with zone transfer.
* - fast-reload, fix auth zone reload lock order.
* - fast-reload, remove debug from fast reload test.
* - fast-reload, remove unused function.
* - fast-reload, fix the worker trust anchor probe timer lock acquisition in
the probe answer callback routine for trust anchor probes.
* - fast-reload, reload trust anchors.
* - fast-reload, fix trust anchor reload lock on autr global data and test
for trust anchor reload.
* - fast-reload, adjust cache sizes.
* - fast-reload, reload cache sizes when changed.
* - fast-reload, reload validator env changes.
* - fast-reload, reload mesh changes.
* - fast-reload, check for incompatible changes.
* - fast-reload, improve error text for incompatible change.
* - fast-reload, fix check config option compatibility.
* - fast-reload, improve error text for nopause change.
* - fast-reload, fix spelling of incompatible options.
* - fast-reload, reload target-fetch-policy, outbound-msg-retry, max-sent-count
and max-query-restarts.
* - fast-reload, check nopause config change for target-fetch-policy.
* - fast-reload, reload do-not-query-address, private-address and capt-exempt.
* - fast-reload, check nopause config change for do-not-query-address,
private-address and capt-exempt.
* - fast-reload, check fast reload not possible due to interface and
outgoing-interface changes.
* - fast-reload, reload nat64 settings.
* - fast-reload, reload settings stored in the infra structure.
* - fast-reload, fix modstack lookup and remove outgoing-range check.
* - fast-reload, more explanation for config parse failure.
* - fast-reload, reload worker outside network changes.
* - fast-reload, detect incompatible changes in network settings.
* fast-reload, commit test files.
* - fast-reload, fix warnings for call types in windows compile.
* - fast-reload, fix warnings and comm_point_internal for tcp wouldblock calls.
* - fast-reload, extend lock checks for repeat thread ids.
* - fast-reload, additional test cases, cache change and tag changes.
* - fast-reload, fix documentation for auth_zone_verify_zonemd_with_key.
* - fast-reload, fix copy_cfg type casts and memory leak on config parse failure.
* - fast-reload, fix use of WSAPoll.
* Review comments for the fast reload feature (#1259)
* - fast-reload review, respip set can be null from a view.
* - fast-reload review, typos.
* - fast-reload review, keep clang static analyzer happy.
* - fast-reload review, don't forget to copy tag_actions.
* - fast-reload review, less indentation.
* - fast-reload review, don't leak respip_actions when reloading.
* - fast-reload review, protect NULL pointer dereference in get_mem
functions.
* - fast-reload review, add fast_reload_most_options.tdir to test most
options with high verbosity when fast reloading.
* - fast-reload review, don't skip new line on long error printouts.
* - fast-reload review, typo.
* - fast-reload review, use new_z for consistency.
* - fast-reload review, nit for unlock ordering to make eye comparison
with the lock counterpart easier.
* - fast-reload review, in case of error the sockets are already closed.
* - fast-reload review, identation.
* - fast-reload review, add static keywords.
* - fast-reload review, update unbound-control usage text.
* - fast-reload review, updates to the man page.
* - fast-reload, the fast-reload command is experimental.
* - fast-reload, fix compile of doqclient for fast reload functions.
* Changelog comment for #1042
- Merge #1042: Fast Reload. The unbound-control fast_reload is added.
It reads changed config in a thread, then only briefly pauses the
service threads, that keep running. DNS service is only interrupted
briefly, less than a second.
---------
Co-authored-by: Yorgos Thessalonikefs <yorgos@nlnetlabs.nl>
2025-03-31 09:25:24 -04:00
|
|
|
mstate->s.client_info = mesh_copy_client_info(region, cinfo);
|
2017-03-07 09:58:51 -05:00
|
|
|
if(!mstate->s.client_info) {
|
|
|
|
|
alloc_reg_release(env->alloc, region);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
}
|
2007-06-22 08:39:08 -04:00
|
|
|
/* remove all weird bits from qflags */
|
2007-08-01 07:17:30 -04:00
|
|
|
mstate->s.query_flags = (qflags & (BIT_RD|BIT_CD));
|
2007-08-01 08:59:37 -04:00
|
|
|
mstate->s.is_priming = prime;
|
2014-11-18 10:15:57 -05:00
|
|
|
mstate->s.is_valrec = valrec;
|
2007-06-22 08:39:08 -04:00
|
|
|
mstate->s.reply = NULL;
|
|
|
|
|
mstate->s.region = region;
|
|
|
|
|
mstate->s.curmod = 0;
|
2007-08-01 10:01:34 -04:00
|
|
|
mstate->s.return_msg = 0;
|
2007-08-01 08:59:37 -04:00
|
|
|
mstate->s.return_rcode = LDNS_RCODE_NOERROR;
|
2007-06-22 08:39:08 -04:00
|
|
|
mstate->s.env = env;
|
|
|
|
|
mstate->s.mesh_info = mstate;
|
2010-01-08 10:59:36 -05:00
|
|
|
mstate->s.prefetch_leeway = 0;
|
2020-02-05 08:20:27 -05:00
|
|
|
mstate->s.serve_expired_data = NULL;
|
2016-12-06 08:42:51 -05:00
|
|
|
mstate->s.no_cache_lookup = 0;
|
|
|
|
|
mstate->s.no_cache_store = 0;
|
2017-09-19 05:08:29 -04:00
|
|
|
mstate->s.need_refetch = 0;
|
2018-08-03 10:00:46 -04:00
|
|
|
mstate->s.was_ratelimited = 0;
|
2022-08-01 07:24:40 -04:00
|
|
|
mstate->s.qstarttime = *env->now;
|
2017-09-19 05:08:29 -04:00
|
|
|
|
2007-06-22 08:39:08 -04:00
|
|
|
/* init modules */
|
2007-12-04 08:23:41 -05:00
|
|
|
for(i=0; i<env->mesh->mods.num; i++) {
|
2007-06-22 08:39:08 -04:00
|
|
|
mstate->s.minfo[i] = NULL;
|
|
|
|
|
mstate->s.ext_state[i] = module_state_initial;
|
|
|
|
|
}
|
2016-12-06 08:42:51 -05:00
|
|
|
/* init edns option lists */
|
|
|
|
|
mstate->s.edns_opts_front_in = NULL;
|
|
|
|
|
mstate->s.edns_opts_back_out = NULL;
|
|
|
|
|
mstate->s.edns_opts_back_in = NULL;
|
|
|
|
|
mstate->s.edns_opts_front_out = NULL;
|
|
|
|
|
|
2007-06-22 08:39:08 -04:00
|
|
|
return mstate;
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-06 08:42:51 -05:00
|
|
|
void
|
|
|
|
|
mesh_state_make_unique(struct mesh_state* mstate)
|
|
|
|
|
{
|
|
|
|
|
mstate->unique = mstate;
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-20 11:39:55 -04:00
|
|
|
void
|
2007-06-22 08:39:08 -04:00
|
|
|
mesh_state_cleanup(struct mesh_state* mstate)
|
|
|
|
|
{
|
|
|
|
|
struct mesh_area* mesh;
|
|
|
|
|
int i;
|
|
|
|
|
if(!mstate)
|
|
|
|
|
return;
|
2011-06-30 07:01:44 -04:00
|
|
|
mesh = mstate->s.env->mesh;
|
2020-02-05 08:20:27 -05:00
|
|
|
/* Stop and delete the serve expired timer */
|
|
|
|
|
if(mstate->s.serve_expired_data && mstate->s.serve_expired_data->timer) {
|
|
|
|
|
comm_timer_delete(mstate->s.serve_expired_data->timer);
|
|
|
|
|
mstate->s.serve_expired_data->timer = NULL;
|
|
|
|
|
}
|
2008-11-05 05:38:22 -05:00
|
|
|
/* drop unsent replies */
|
|
|
|
|
if(!mstate->replies_sent) {
|
2019-01-14 10:52:50 -05:00
|
|
|
struct mesh_reply* rep = mstate->reply_list;
|
2009-06-12 03:53:36 -04:00
|
|
|
struct mesh_cb* cb;
|
2019-01-14 10:52:50 -05:00
|
|
|
/* in tcp_req_info, the mstates linked are removed, but
|
|
|
|
|
* the reply_list is now NULL, so the remove-from-empty-list
|
|
|
|
|
* takes no time and also it does not do the mesh accounting */
|
|
|
|
|
mstate->reply_list = NULL;
|
|
|
|
|
for(; rep; rep=rep->next) {
|
2024-05-01 04:10:58 -04:00
|
|
|
infra_wait_limit_dec(mesh->env->infra_cache,
|
|
|
|
|
&rep->query_reply, mesh->env->cfg);
|
2024-07-12 10:41:46 -04:00
|
|
|
if(rep->query_reply.c->use_h2)
|
2024-07-16 08:23:10 -04:00
|
|
|
http2_stream_remove_mesh_state(rep->h2_stream);
|
2008-11-05 05:38:22 -05:00
|
|
|
comm_point_drop_reply(&rep->query_reply);
|
2020-02-05 08:20:27 -05:00
|
|
|
log_assert(mesh->num_reply_addrs > 0);
|
2011-06-30 07:01:44 -04:00
|
|
|
mesh->num_reply_addrs--;
|
2008-11-05 05:38:22 -05:00
|
|
|
}
|
2018-04-23 08:51:00 -04:00
|
|
|
while((cb = mstate->cb_list)!=NULL) {
|
|
|
|
|
mstate->cb_list = cb->next;
|
2009-06-12 03:53:36 -04:00
|
|
|
fptr_ok(fptr_whitelist_mesh_cb(cb->cb));
|
|
|
|
|
(*cb->cb)(cb->cb_arg, LDNS_RCODE_SERVFAIL, NULL,
|
2018-08-03 10:00:46 -04:00
|
|
|
sec_status_unchecked, NULL, 0);
|
2020-02-05 08:20:27 -05:00
|
|
|
log_assert(mesh->num_reply_addrs > 0);
|
2011-06-30 07:01:44 -04:00
|
|
|
mesh->num_reply_addrs--;
|
2009-06-12 03:53:36 -04:00
|
|
|
}
|
2008-11-05 05:38:22 -05:00
|
|
|
}
|
|
|
|
|
|
2007-06-22 08:39:08 -04:00
|
|
|
/* de-init modules */
|
2007-12-04 08:23:41 -05:00
|
|
|
for(i=0; i<mesh->mods.num; i++) {
|
2008-02-20 02:18:42 -05:00
|
|
|
fptr_ok(fptr_whitelist_mod_clear(mesh->mods.mod[i]->clear));
|
2007-12-04 08:23:41 -05:00
|
|
|
(*mesh->mods.mod[i]->clear)(&mstate->s, i);
|
2007-06-22 08:39:08 -04:00
|
|
|
mstate->s.minfo[i] = NULL;
|
|
|
|
|
mstate->s.ext_state[i] = module_finished;
|
|
|
|
|
}
|
2007-10-18 18:17:02 -04:00
|
|
|
alloc_reg_release(mstate->s.env->alloc, mstate->s.region);
|
2007-06-22 08:39:08 -04:00
|
|
|
}
|
2007-06-25 09:54:03 -04:00
|
|
|
|
2023-04-20 11:39:55 -04:00
|
|
|
void
|
2007-06-26 09:06:44 -04:00
|
|
|
mesh_state_delete(struct module_qstate* qstate)
|
2007-06-25 09:54:03 -04:00
|
|
|
{
|
|
|
|
|
struct mesh_area* mesh;
|
|
|
|
|
struct mesh_state_ref* super, ref;
|
2007-06-26 09:06:44 -04:00
|
|
|
struct mesh_state* mstate;
|
|
|
|
|
if(!qstate)
|
2007-06-25 09:54:03 -04:00
|
|
|
return;
|
2007-06-26 09:06:44 -04:00
|
|
|
mstate = qstate->mesh_info;
|
2007-06-25 09:54:03 -04:00
|
|
|
mesh = mstate->s.env->mesh;
|
|
|
|
|
mesh_detach_subs(&mstate->s);
|
2008-09-02 09:04:47 -04:00
|
|
|
if(mstate->list_select == mesh_forever_list) {
|
|
|
|
|
mesh->num_forever_states --;
|
2023-04-20 11:39:55 -04:00
|
|
|
mesh_list_remove(mstate, &mesh->forever_first,
|
2008-09-02 09:04:47 -04:00
|
|
|
&mesh->forever_last);
|
|
|
|
|
} else if(mstate->list_select == mesh_jostle_list) {
|
2023-04-20 11:39:55 -04:00
|
|
|
mesh_list_remove(mstate, &mesh->jostle_first,
|
2008-09-02 09:04:47 -04:00
|
|
|
&mesh->jostle_last);
|
|
|
|
|
}
|
2007-12-06 10:11:07 -05:00
|
|
|
if(!mstate->reply_list && !mstate->cb_list
|
|
|
|
|
&& mstate->super_set.count == 0) {
|
2007-06-25 09:54:03 -04:00
|
|
|
log_assert(mesh->num_detached_states > 0);
|
|
|
|
|
mesh->num_detached_states--;
|
|
|
|
|
}
|
2007-12-06 10:11:07 -05:00
|
|
|
if(mstate->reply_list || mstate->cb_list) {
|
2007-06-25 09:54:03 -04:00
|
|
|
log_assert(mesh->num_reply_states > 0);
|
|
|
|
|
mesh->num_reply_states--;
|
|
|
|
|
}
|
|
|
|
|
ref.node.key = &ref;
|
|
|
|
|
ref.s = mstate;
|
|
|
|
|
RBTREE_FOR(super, struct mesh_state_ref*, &mstate->super_set) {
|
|
|
|
|
(void)rbtree_delete(&super->s->sub_set, &ref);
|
|
|
|
|
}
|
|
|
|
|
(void)rbtree_delete(&mesh->run, mstate);
|
|
|
|
|
(void)rbtree_delete(&mesh->all, mstate);
|
|
|
|
|
mesh_state_cleanup(mstate);
|
|
|
|
|
}
|
|
|
|
|
|
2010-06-10 10:10:17 -04:00
|
|
|
/** helper recursive rbtree find routine */
|
|
|
|
|
static int
|
|
|
|
|
find_in_subsub(struct mesh_state* m, struct mesh_state* tofind, size_t *c)
|
|
|
|
|
{
|
|
|
|
|
struct mesh_state_ref* r;
|
|
|
|
|
if((*c)++ > MESH_MAX_SUBSUB)
|
|
|
|
|
return 1;
|
|
|
|
|
RBTREE_FOR(r, struct mesh_state_ref*, &m->sub_set) {
|
|
|
|
|
if(r->s == tofind || find_in_subsub(r->s, tofind, c))
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** find cycle for already looked up mesh_state */
|
2020-02-05 08:20:27 -05:00
|
|
|
static int
|
2010-06-10 10:10:17 -04:00
|
|
|
mesh_detect_cycle_found(struct module_qstate* qstate, struct mesh_state* dep_m)
|
|
|
|
|
{
|
|
|
|
|
struct mesh_state* cyc_m = qstate->mesh_info;
|
|
|
|
|
size_t counter = 0;
|
2025-09-24 08:30:24 -04:00
|
|
|
log_assert(dep_m);
|
2010-06-10 10:10:17 -04:00
|
|
|
if(dep_m == cyc_m || find_in_subsub(dep_m, cyc_m, &counter)) {
|
|
|
|
|
if(counter > MESH_MAX_SUBSUB)
|
|
|
|
|
return 2;
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2007-06-25 09:54:03 -04:00
|
|
|
void mesh_detach_subs(struct module_qstate* qstate)
|
|
|
|
|
{
|
|
|
|
|
struct mesh_area* mesh = qstate->env->mesh;
|
|
|
|
|
struct mesh_state_ref* ref, lookup;
|
2011-09-16 07:35:01 -04:00
|
|
|
#ifdef UNBOUND_DEBUG
|
2017-01-19 05:25:41 -05:00
|
|
|
struct rbnode_type* n;
|
2011-09-16 07:35:01 -04:00
|
|
|
#endif
|
2007-06-25 09:54:03 -04:00
|
|
|
lookup.node.key = &lookup;
|
|
|
|
|
lookup.s = qstate->mesh_info;
|
|
|
|
|
RBTREE_FOR(ref, struct mesh_state_ref*, &qstate->mesh_info->sub_set) {
|
2011-09-16 07:35:01 -04:00
|
|
|
#ifdef UNBOUND_DEBUG
|
|
|
|
|
n =
|
2013-08-22 10:10:29 -04:00
|
|
|
#else
|
|
|
|
|
(void)
|
2011-09-16 07:35:01 -04:00
|
|
|
#endif
|
|
|
|
|
rbtree_delete(&ref->s->super_set, &lookup);
|
2007-06-25 09:54:03 -04:00
|
|
|
log_assert(n != NULL); /* must have been present */
|
2007-12-06 10:11:07 -05:00
|
|
|
if(!ref->s->reply_list && !ref->s->cb_list
|
|
|
|
|
&& ref->s->super_set.count == 0) {
|
2007-06-25 09:54:03 -04:00
|
|
|
mesh->num_detached_states++;
|
2023-04-20 11:39:55 -04:00
|
|
|
log_assert(mesh->num_detached_states +
|
2007-06-25 09:54:03 -04:00
|
|
|
mesh->num_reply_states <= mesh->all.count);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
rbtree_init(&qstate->mesh_info->sub_set, &mesh_state_ref_compare);
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-02 09:17:56 -04:00
|
|
|
int mesh_add_sub(struct module_qstate* qstate, struct query_info* qinfo,
|
2025-09-30 05:28:15 -04:00
|
|
|
struct respip_client_info* cinfo, uint16_t qflags, int prime,
|
|
|
|
|
int valrec, struct module_qstate** newq, struct mesh_state** sub)
|
2007-06-25 09:54:03 -04:00
|
|
|
{
|
|
|
|
|
/* find it, if not, create it */
|
|
|
|
|
struct mesh_area* mesh = qstate->env->mesh;
|
2025-09-30 05:28:15 -04:00
|
|
|
*sub = mesh_area_find(mesh, cinfo, qinfo, qflags, prime, valrec);
|
2017-05-02 09:17:56 -04:00
|
|
|
if(!*sub) {
|
2011-09-16 07:35:01 -04:00
|
|
|
#ifdef UNBOUND_DEBUG
|
2017-01-19 05:25:41 -05:00
|
|
|
struct rbnode_type* n;
|
2011-09-16 07:35:01 -04:00
|
|
|
#endif
|
2007-06-25 09:54:03 -04:00
|
|
|
/* create a new one */
|
2025-09-30 05:28:15 -04:00
|
|
|
*sub = mesh_state_create(qstate->env, qinfo, cinfo, qflags,
|
|
|
|
|
prime, valrec);
|
2017-05-02 09:17:56 -04:00
|
|
|
if(!*sub) {
|
2007-06-25 09:54:03 -04:00
|
|
|
log_err("mesh_attach_sub: out of memory");
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2011-09-16 07:35:01 -04:00
|
|
|
#ifdef UNBOUND_DEBUG
|
|
|
|
|
n =
|
2013-08-22 10:10:29 -04:00
|
|
|
#else
|
|
|
|
|
(void)
|
2011-09-16 07:35:01 -04:00
|
|
|
#endif
|
2017-05-02 09:17:56 -04:00
|
|
|
rbtree_insert(&mesh->all, &(*sub)->node);
|
2007-06-25 09:54:03 -04:00
|
|
|
log_assert(n != NULL);
|
|
|
|
|
/* set detached (it is now) */
|
|
|
|
|
mesh->num_detached_states++;
|
|
|
|
|
/* set new query state to run */
|
2011-09-16 08:43:07 -04:00
|
|
|
#ifdef UNBOUND_DEBUG
|
|
|
|
|
n =
|
2013-08-22 10:10:29 -04:00
|
|
|
#else
|
|
|
|
|
(void)
|
2011-09-16 08:43:07 -04:00
|
|
|
#endif
|
2017-05-02 09:17:56 -04:00
|
|
|
rbtree_insert(&mesh->run, &(*sub)->run_node);
|
2007-06-25 09:54:03 -04:00
|
|
|
log_assert(n != NULL);
|
2017-05-02 09:17:56 -04:00
|
|
|
*newq = &(*sub)->s;
|
2025-09-24 08:30:24 -04:00
|
|
|
} else {
|
2007-06-25 09:54:03 -04:00
|
|
|
*newq = NULL;
|
2025-09-24 08:30:24 -04:00
|
|
|
if(mesh_detect_cycle_found(qstate, *sub)) {
|
|
|
|
|
verbose(VERB_ALGO, "attach failed, cycle detected");
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-05-02 09:17:56 -04:00
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int mesh_attach_sub(struct module_qstate* qstate, struct query_info* qinfo,
|
2025-09-30 05:28:15 -04:00
|
|
|
struct respip_client_info* cinfo, uint16_t qflags, int prime,
|
|
|
|
|
int valrec, struct module_qstate** newq)
|
2017-05-02 09:17:56 -04:00
|
|
|
{
|
|
|
|
|
struct mesh_area* mesh = qstate->env->mesh;
|
|
|
|
|
struct mesh_state* sub = NULL;
|
|
|
|
|
int was_detached;
|
2025-09-30 05:28:15 -04:00
|
|
|
if(!mesh_add_sub(qstate, qinfo, cinfo, qflags, prime, valrec, newq,
|
|
|
|
|
&sub))
|
2017-05-02 09:17:56 -04:00
|
|
|
return 0;
|
2012-07-20 09:08:19 -04:00
|
|
|
was_detached = (sub->super_set.count == 0);
|
2007-06-25 09:54:03 -04:00
|
|
|
if(!mesh_state_attachment(qstate->mesh_info, sub))
|
|
|
|
|
return 0;
|
2012-07-20 09:08:19 -04:00
|
|
|
/* if it was a duplicate attachment, the count was not zero before */
|
2023-04-20 11:39:55 -04:00
|
|
|
if(!sub->reply_list && !sub->cb_list && was_detached &&
|
2012-07-20 09:08:19 -04:00
|
|
|
sub->super_set.count == 1) {
|
2007-06-25 09:54:03 -04:00
|
|
|
/* it used to be detached, before this one got added */
|
|
|
|
|
log_assert(mesh->num_detached_states > 0);
|
|
|
|
|
mesh->num_detached_states--;
|
|
|
|
|
}
|
|
|
|
|
/* *newq will be run when inited after the current module stops */
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int mesh_state_attachment(struct mesh_state* super, struct mesh_state* sub)
|
|
|
|
|
{
|
2011-09-16 07:35:01 -04:00
|
|
|
#ifdef UNBOUND_DEBUG
|
2017-01-19 05:25:41 -05:00
|
|
|
struct rbnode_type* n;
|
2011-09-16 07:35:01 -04:00
|
|
|
#endif
|
2007-06-25 09:54:03 -04:00
|
|
|
struct mesh_state_ref* subref; /* points to sub, inserted in super */
|
|
|
|
|
struct mesh_state_ref* superref; /* points to super, inserted in sub */
|
2007-10-18 16:31:43 -04:00
|
|
|
if( !(subref = regional_alloc(super->s.region,
|
2007-06-25 09:54:03 -04:00
|
|
|
sizeof(struct mesh_state_ref))) ||
|
2007-10-18 16:31:43 -04:00
|
|
|
!(superref = regional_alloc(sub->s.region,
|
2007-06-25 09:54:03 -04:00
|
|
|
sizeof(struct mesh_state_ref))) ) {
|
|
|
|
|
log_err("mesh_state_attachment: out of memory");
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
superref->node.key = superref;
|
|
|
|
|
superref->s = super;
|
|
|
|
|
subref->node.key = subref;
|
|
|
|
|
subref->s = sub;
|
2012-06-11 08:04:58 -04:00
|
|
|
if(!rbtree_insert(&sub->super_set, &superref->node)) {
|
|
|
|
|
/* this should not happen, iterator and validator do not
|
|
|
|
|
* attach subqueries that are identical. */
|
|
|
|
|
/* already attached, we are done, nothing todo.
|
|
|
|
|
* since superref and subref already allocated in region,
|
|
|
|
|
* we cannot free them */
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
2011-09-16 07:35:01 -04:00
|
|
|
#ifdef UNBOUND_DEBUG
|
|
|
|
|
n =
|
2013-08-22 10:10:29 -04:00
|
|
|
#else
|
|
|
|
|
(void)
|
2011-09-16 07:35:01 -04:00
|
|
|
#endif
|
|
|
|
|
rbtree_insert(&super->sub_set, &subref->node);
|
2012-06-11 08:04:58 -04:00
|
|
|
log_assert(n != NULL); /* we checked above if statement, the reverse
|
|
|
|
|
administration should not fail now, unless they are out of sync */
|
2007-06-25 09:54:03 -04:00
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
2007-12-06 10:11:07 -05:00
|
|
|
/**
|
|
|
|
|
* callback results to mesh cb entry
|
|
|
|
|
* @param m: mesh state to send it for.
|
|
|
|
|
* @param rcode: if not 0, error code.
|
|
|
|
|
* @param rep: reply to send (or NULL if rcode is set).
|
|
|
|
|
* @param r: callback entry
|
2021-01-08 05:01:06 -05:00
|
|
|
* @param start_time: the time to pass to callback functions, it is 0 or
|
|
|
|
|
* a value from one of the packets if the mesh state had packets.
|
2007-12-06 10:11:07 -05:00
|
|
|
*/
|
|
|
|
|
static void
|
|
|
|
|
mesh_do_callback(struct mesh_state* m, int rcode, struct reply_info* rep,
|
2021-01-08 03:47:46 -05:00
|
|
|
struct mesh_cb* r, struct timeval* start_time)
|
2007-12-06 10:11:07 -05:00
|
|
|
{
|
|
|
|
|
int secure;
|
2009-10-08 13:05:53 -04:00
|
|
|
char* reason = NULL;
|
2018-08-03 10:00:46 -04:00
|
|
|
int was_ratelimited = m->s.was_ratelimited;
|
|
|
|
|
/* bogus messages are not made into servfail, sec_status passed
|
2007-12-06 10:11:07 -05:00
|
|
|
* to the callback function */
|
|
|
|
|
if(rep && rep->security == sec_status_secure)
|
|
|
|
|
secure = 1;
|
|
|
|
|
else secure = 0;
|
|
|
|
|
if(!rep && rcode == LDNS_RCODE_NOERROR)
|
|
|
|
|
rcode = LDNS_RCODE_SERVFAIL;
|
2023-07-03 07:50:39 -04:00
|
|
|
if(!rcode && rep && (rep->security == sec_status_bogus ||
|
2018-04-24 05:03:49 -04:00
|
|
|
rep->security == sec_status_secure_sentinel_fail)) {
|
2024-04-29 04:15:19 -04:00
|
|
|
if(!(reason = errinf_to_str_bogus(&m->s, NULL)))
|
2009-10-08 13:05:53 -04:00
|
|
|
rcode = LDNS_RCODE_SERVFAIL;
|
|
|
|
|
}
|
2007-12-06 10:11:07 -05:00
|
|
|
/* send the reply */
|
|
|
|
|
if(rcode) {
|
2016-12-06 08:42:51 -05:00
|
|
|
if(rcode == LDNS_RCODE_SERVFAIL) {
|
|
|
|
|
if(!inplace_cb_reply_servfail_call(m->s.env, &m->s.qinfo, &m->s,
|
2021-01-01 17:29:32 -05:00
|
|
|
rep, rcode, &r->edns, NULL, m->s.region, start_time))
|
2021-11-08 05:50:29 -05:00
|
|
|
r->edns.opt_list_inplace_cb_out = NULL;
|
2016-12-06 08:42:51 -05:00
|
|
|
} else {
|
|
|
|
|
if(!inplace_cb_reply_call(m->s.env, &m->s.qinfo, &m->s, rep, rcode,
|
2021-01-01 17:29:32 -05:00
|
|
|
&r->edns, NULL, m->s.region, start_time))
|
2021-11-08 05:50:29 -05:00
|
|
|
r->edns.opt_list_inplace_cb_out = NULL;
|
2016-12-06 08:42:51 -05:00
|
|
|
}
|
2009-06-12 03:53:36 -04:00
|
|
|
fptr_ok(fptr_whitelist_mesh_cb(r->cb));
|
2018-08-03 10:00:46 -04:00
|
|
|
(*r->cb)(r->cb_arg, rcode, r->buf, sec_status_unchecked, NULL,
|
|
|
|
|
was_ratelimited);
|
2007-12-06 10:11:07 -05:00
|
|
|
} else {
|
|
|
|
|
size_t udp_size = r->edns.udp_size;
|
2013-12-03 04:11:16 -05:00
|
|
|
sldns_buffer_clear(r->buf);
|
2007-12-06 10:11:07 -05:00
|
|
|
r->edns.edns_version = EDNS_ADVERTISED_VERSION;
|
|
|
|
|
r->edns.udp_size = EDNS_ADVERTISED_SIZE;
|
|
|
|
|
r->edns.ext_rcode = 0;
|
|
|
|
|
r->edns.bits &= EDNS_DO;
|
2023-10-04 07:54:05 -04:00
|
|
|
if(m->s.env->cfg->disable_edns_do && (r->edns.bits&EDNS_DO))
|
|
|
|
|
r->edns.edns_present = 0;
|
2016-12-06 08:42:51 -05:00
|
|
|
|
|
|
|
|
if(!inplace_cb_reply_call(m->s.env, &m->s.qinfo, &m->s, rep,
|
2021-01-01 17:29:32 -05:00
|
|
|
LDNS_RCODE_NOERROR, &r->edns, NULL, m->s.region, start_time) ||
|
2023-04-20 11:39:55 -04:00
|
|
|
!reply_info_answer_encode(&m->s.qinfo, rep, r->qid,
|
|
|
|
|
r->qflags, r->buf, 0, 1,
|
|
|
|
|
m->s.env->scratch, udp_size, &r->edns,
|
2025-09-15 04:03:35 -04:00
|
|
|
(int)(r->edns.bits & EDNS_DO), secure))
|
2007-12-06 10:11:07 -05:00
|
|
|
{
|
2009-06-12 03:53:36 -04:00
|
|
|
fptr_ok(fptr_whitelist_mesh_cb(r->cb));
|
2007-12-06 10:11:07 -05:00
|
|
|
(*r->cb)(r->cb_arg, LDNS_RCODE_SERVFAIL, r->buf,
|
2018-08-03 10:00:46 -04:00
|
|
|
sec_status_unchecked, NULL, 0);
|
2009-06-12 03:53:36 -04:00
|
|
|
} else {
|
|
|
|
|
fptr_ok(fptr_whitelist_mesh_cb(r->cb));
|
|
|
|
|
(*r->cb)(r->cb_arg, LDNS_RCODE_NOERROR, r->buf,
|
2023-07-03 07:50:39 -04:00
|
|
|
(rep?rep->security:sec_status_unchecked),
|
|
|
|
|
reason, was_ratelimited);
|
2009-06-12 03:53:36 -04:00
|
|
|
}
|
2007-12-06 10:11:07 -05:00
|
|
|
}
|
2009-10-08 13:05:53 -04:00
|
|
|
free(reason);
|
2020-02-05 08:20:27 -05:00
|
|
|
log_assert(m->s.env->mesh->num_reply_addrs > 0);
|
2007-12-06 10:11:07 -05:00
|
|
|
m->s.env->mesh->num_reply_addrs--;
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-03 05:02:36 -05:00
|
|
|
static inline int
|
|
|
|
|
mesh_is_rpz_respip_tcponly_action(struct mesh_state const* m)
|
|
|
|
|
{
|
|
|
|
|
struct respip_action_info const* respip_info = m->s.respip_action_info;
|
2023-09-18 03:55:39 -04:00
|
|
|
return (respip_info == NULL
|
2020-11-03 05:02:36 -05:00
|
|
|
? 0
|
|
|
|
|
: (respip_info->rpz_used
|
|
|
|
|
&& !respip_info->rpz_disabled
|
2023-09-18 03:55:39 -04:00
|
|
|
&& respip_info->action == respip_truncate))
|
|
|
|
|
|| m->s.tcp_required;
|
2020-11-03 05:02:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline int
|
2023-07-19 08:52:20 -04:00
|
|
|
mesh_is_udp(struct mesh_reply const* r)
|
|
|
|
|
{
|
2020-11-03 05:02:36 -05:00
|
|
|
return r->query_reply.c->type == comm_udp;
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-05 05:41:17 -05:00
|
|
|
static inline void
|
|
|
|
|
mesh_find_and_attach_ede_and_reason(struct mesh_state* m,
|
2023-07-19 08:52:20 -04:00
|
|
|
struct reply_info* rep, struct mesh_reply* r)
|
|
|
|
|
{
|
|
|
|
|
/* OLD note:
|
|
|
|
|
* During validation the EDE code can be received via two
|
2022-12-05 05:41:17 -05:00
|
|
|
* code paths. One code path fills the reply_info EDE, and
|
|
|
|
|
* the other fills it in the errinf_strlist. These paths
|
|
|
|
|
* intersect at some points, but where is opaque due to
|
|
|
|
|
* the complexity of the validator. At the time of writing
|
|
|
|
|
* we make the choice to prefer the EDE from errinf_strlist
|
|
|
|
|
* but a compelling reason to do otherwise is just as valid
|
2023-07-19 08:52:20 -04:00
|
|
|
* NEW note:
|
|
|
|
|
* The compelling reason is that with caching support, the value
|
2023-07-28 06:50:36 -04:00
|
|
|
* in the reply_info is cached.
|
2023-07-19 08:52:20 -04:00
|
|
|
* The reason members of the reply_info struct should be
|
|
|
|
|
* updated as they are already cached. No reason to
|
|
|
|
|
* try and find the EDE information in errinf anymore.
|
2022-12-05 05:41:17 -05:00
|
|
|
*/
|
2023-07-19 08:52:20 -04:00
|
|
|
if(rep->reason_bogus != LDNS_EDE_NONE) {
|
2022-12-05 05:41:17 -05:00
|
|
|
edns_opt_list_append_ede(&r->edns.opt_list_out,
|
2023-07-19 08:52:20 -04:00
|
|
|
m->s.region, rep->reason_bogus, rep->reason_bogus_str);
|
2022-12-05 05:41:17 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2007-06-25 09:54:03 -04:00
|
|
|
/**
|
|
|
|
|
* Send reply to mesh reply entry
|
|
|
|
|
* @param m: mesh state to send it for.
|
|
|
|
|
* @param rcode: if not 0, error code.
|
|
|
|
|
* @param rep: reply to send (or NULL if rcode is set).
|
|
|
|
|
* @param r: reply entry
|
2019-01-11 09:12:27 -05:00
|
|
|
* @param r_buffer: buffer to use for reply entry.
|
2008-02-22 04:23:42 -05:00
|
|
|
* @param prev: previous reply, already has its answer encoded in buffer.
|
2019-01-11 09:12:27 -05:00
|
|
|
* @param prev_buffer: buffer for previous reply.
|
2007-06-25 09:54:03 -04:00
|
|
|
*/
|
|
|
|
|
static void
|
|
|
|
|
mesh_send_reply(struct mesh_state* m, int rcode, struct reply_info* rep,
|
2019-01-11 09:12:27 -05:00
|
|
|
struct mesh_reply* r, struct sldns_buffer* r_buffer,
|
|
|
|
|
struct mesh_reply* prev, struct sldns_buffer* prev_buffer)
|
2007-06-25 09:54:03 -04:00
|
|
|
{
|
|
|
|
|
struct timeval end_time;
|
2008-02-19 08:12:23 -05:00
|
|
|
struct timeval duration;
|
2007-08-21 09:12:10 -04:00
|
|
|
int secure;
|
2020-10-14 04:06:28 -04:00
|
|
|
/* briefly set the replylist to null in case the
|
|
|
|
|
* meshsendreply calls tcpreqinfo sendreply that
|
|
|
|
|
* comm_point_drops because of size, and then the
|
|
|
|
|
* null stops the mesh state remove and thus
|
|
|
|
|
* reply_list modification and accounting */
|
|
|
|
|
struct mesh_reply* rlist = m->reply_list;
|
2020-11-03 09:45:26 -05:00
|
|
|
|
2020-11-27 04:09:54 -05:00
|
|
|
/* rpz: apply actions */
|
2020-11-03 09:45:26 -05:00
|
|
|
rcode = mesh_is_udp(r) && mesh_is_rpz_respip_tcponly_action(m)
|
|
|
|
|
? (rcode|BIT_TC) : rcode;
|
|
|
|
|
|
2007-08-21 09:12:10 -04:00
|
|
|
/* examine security status */
|
2011-05-10 07:20:14 -04:00
|
|
|
if(m->s.env->need_to_validate && (!(r->qflags&BIT_CD) ||
|
2023-04-20 11:39:55 -04:00
|
|
|
m->s.env->cfg->ignore_cd) && rep &&
|
2018-04-24 05:03:49 -04:00
|
|
|
(rep->security <= sec_status_bogus ||
|
|
|
|
|
rep->security == sec_status_secure_sentinel_fail)) {
|
2007-08-21 09:12:10 -04:00
|
|
|
rcode = LDNS_RCODE_SERVFAIL;
|
2022-05-06 06:48:53 -04:00
|
|
|
if(m->s.env->cfg->stat_extended)
|
2008-09-16 10:08:38 -04:00
|
|
|
m->s.env->mesh->ans_bogus++;
|
2007-08-21 09:12:10 -04:00
|
|
|
}
|
2007-08-21 09:27:04 -04:00
|
|
|
if(rep && rep->security == sec_status_secure)
|
2007-08-21 09:12:10 -04:00
|
|
|
secure = 1;
|
|
|
|
|
else secure = 0;
|
2007-12-04 12:54:14 -05:00
|
|
|
if(!rep && rcode == LDNS_RCODE_NOERROR)
|
|
|
|
|
rcode = LDNS_RCODE_SERVFAIL;
|
2020-09-16 12:25:02 -04:00
|
|
|
if(r->query_reply.c->use_h2) {
|
2020-05-07 10:36:26 -04:00
|
|
|
r->query_reply.c->h2_stream = r->h2_stream;
|
2020-06-24 08:04:34 -04:00
|
|
|
/* Mesh reply won't exist for long anymore. Make it impossible
|
|
|
|
|
* for HTTP/2 stream to refer to mesh state, in case
|
|
|
|
|
* connection gets cleanup before HTTP/2 stream close. */
|
|
|
|
|
r->h2_stream->mesh_state = NULL;
|
2020-05-07 10:36:26 -04:00
|
|
|
}
|
2007-06-25 09:54:03 -04:00
|
|
|
/* send the reply */
|
2020-10-15 09:53:16 -04:00
|
|
|
/* We don't reuse the encoded answer if:
|
|
|
|
|
* - either the previous or current response has a local alias. We could
|
|
|
|
|
* compare the alias records and still reuse the previous answer if they
|
|
|
|
|
* are the same, but that would be complicated and error prone for the
|
|
|
|
|
* relatively minor case. So we err on the side of safety.
|
|
|
|
|
* - there are registered callback functions for the given rcode, as these
|
|
|
|
|
* need to be called for each reply. */
|
|
|
|
|
if(((rcode != LDNS_RCODE_SERVFAIL &&
|
|
|
|
|
!m->s.env->inplace_cb_lists[inplace_cb_reply]) ||
|
|
|
|
|
(rcode == LDNS_RCODE_SERVFAIL &&
|
|
|
|
|
!m->s.env->inplace_cb_lists[inplace_cb_reply_servfail])) &&
|
|
|
|
|
prev && prev_buffer && prev->qflags == r->qflags &&
|
2016-10-18 09:18:20 -04:00
|
|
|
!prev->local_alias && !r->local_alias &&
|
2020-10-15 09:53:16 -04:00
|
|
|
prev->edns.edns_present == r->edns.edns_present &&
|
|
|
|
|
prev->edns.bits == r->edns.bits &&
|
2016-05-31 11:08:05 -04:00
|
|
|
prev->edns.udp_size == r->edns.udp_size &&
|
2021-11-01 08:48:40 -04:00
|
|
|
edns_opt_list_compare(prev->edns.opt_list_out, r->edns.opt_list_out) == 0 &&
|
2021-11-08 05:50:29 -05:00
|
|
|
edns_opt_list_compare(prev->edns.opt_list_inplace_cb_out, r->edns.opt_list_inplace_cb_out) == 0
|
2021-11-01 08:48:40 -04:00
|
|
|
) {
|
2008-02-22 04:23:42 -05:00
|
|
|
/* if the previous reply is identical to this one, fix ID */
|
2019-01-11 09:12:27 -05:00
|
|
|
if(prev_buffer != r_buffer)
|
|
|
|
|
sldns_buffer_copy(r_buffer, prev_buffer);
|
|
|
|
|
sldns_buffer_write_at(r_buffer, 0, &r->qid, sizeof(uint16_t));
|
|
|
|
|
sldns_buffer_write_at(r_buffer, 12, r->qname,
|
|
|
|
|
m->s.qinfo.qname_len);
|
2020-10-14 04:06:28 -04:00
|
|
|
m->reply_list = NULL;
|
2008-02-22 04:23:42 -05:00
|
|
|
comm_point_send_reply(&r->query_reply);
|
2020-10-14 04:06:28 -04:00
|
|
|
m->reply_list = rlist;
|
2008-02-22 04:23:42 -05:00
|
|
|
} else if(rcode) {
|
2008-02-26 15:45:20 -05:00
|
|
|
m->s.qinfo.qname = r->qname;
|
2016-10-18 09:18:20 -04:00
|
|
|
m->s.qinfo.local_alias = r->local_alias;
|
2016-12-06 08:42:51 -05:00
|
|
|
if(rcode == LDNS_RCODE_SERVFAIL) {
|
|
|
|
|
if(!inplace_cb_reply_servfail_call(m->s.env, &m->s.qinfo, &m->s,
|
2021-01-08 03:47:46 -05:00
|
|
|
rep, rcode, &r->edns, &r->query_reply, m->s.region, &r->start_time))
|
2021-11-08 05:50:29 -05:00
|
|
|
r->edns.opt_list_inplace_cb_out = NULL;
|
2023-04-20 11:39:55 -04:00
|
|
|
} else {
|
2016-12-06 08:42:51 -05:00
|
|
|
if(!inplace_cb_reply_call(m->s.env, &m->s.qinfo, &m->s, rep, rcode,
|
2021-01-08 03:47:46 -05:00
|
|
|
&r->edns, &r->query_reply, m->s.region, &r->start_time))
|
2021-11-08 05:50:29 -05:00
|
|
|
r->edns.opt_list_inplace_cb_out = NULL;
|
2016-12-06 08:42:51 -05:00
|
|
|
}
|
2023-07-19 09:26:08 -04:00
|
|
|
/* Send along EDE EDNS0 option when SERVFAILing; usually
|
|
|
|
|
* DNSSEC validation failures */
|
|
|
|
|
/* Since we are SERVFAILing here, CD bit and rep->security
|
|
|
|
|
* is already handled. */
|
|
|
|
|
if(m->s.env->cfg->ede && rep) {
|
2022-12-05 05:41:17 -05:00
|
|
|
mesh_find_and_attach_ede_and_reason(m, rep, r);
|
2022-05-06 06:48:53 -04:00
|
|
|
}
|
2019-01-11 09:12:27 -05:00
|
|
|
error_encode(r_buffer, rcode, &m->s.qinfo, r->qid,
|
|
|
|
|
r->qflags, &r->edns);
|
2020-10-14 04:06:28 -04:00
|
|
|
m->reply_list = NULL;
|
2007-06-25 09:54:03 -04:00
|
|
|
comm_point_send_reply(&r->query_reply);
|
2020-10-14 04:06:28 -04:00
|
|
|
m->reply_list = rlist;
|
2007-06-25 09:54:03 -04:00
|
|
|
} else {
|
|
|
|
|
size_t udp_size = r->edns.udp_size;
|
|
|
|
|
r->edns.edns_version = EDNS_ADVERTISED_VERSION;
|
|
|
|
|
r->edns.udp_size = EDNS_ADVERTISED_SIZE;
|
|
|
|
|
r->edns.ext_rcode = 0;
|
|
|
|
|
r->edns.bits &= EDNS_DO;
|
2023-10-04 07:54:05 -04:00
|
|
|
if(m->s.env->cfg->disable_edns_do && (r->edns.bits&EDNS_DO))
|
|
|
|
|
r->edns.edns_present = 0;
|
2008-02-26 15:45:20 -05:00
|
|
|
m->s.qinfo.qname = r->qname;
|
2016-10-18 09:18:20 -04:00
|
|
|
m->s.qinfo.local_alias = r->local_alias;
|
2022-12-05 05:41:17 -05:00
|
|
|
|
2023-07-19 09:26:08 -04:00
|
|
|
/* Attach EDE without SERVFAIL if the validation failed.
|
|
|
|
|
* Need to explicitly check for rep->security otherwise failed
|
|
|
|
|
* validation paths may attach to a secure answer. */
|
|
|
|
|
if(m->s.env->cfg->ede && rep &&
|
2022-12-05 05:41:17 -05:00
|
|
|
(rep->security <= sec_status_bogus ||
|
|
|
|
|
rep->security == sec_status_secure_sentinel_fail)) {
|
|
|
|
|
mesh_find_and_attach_ede_and_reason(m, rep, r);
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-06 08:42:51 -05:00
|
|
|
if(!inplace_cb_reply_call(m->s.env, &m->s.qinfo, &m->s, rep,
|
2021-01-08 03:47:46 -05:00
|
|
|
LDNS_RCODE_NOERROR, &r->edns, &r->query_reply, m->s.region, &r->start_time) ||
|
2023-04-20 11:39:55 -04:00
|
|
|
!reply_info_answer_encode(&m->s.qinfo, rep, r->qid,
|
2019-01-11 09:12:27 -05:00
|
|
|
r->qflags, r_buffer, 0, 1, m->s.env->scratch,
|
|
|
|
|
udp_size, &r->edns, (int)(r->edns.bits & EDNS_DO),
|
2025-09-15 04:03:35 -04:00
|
|
|
secure))
|
2007-06-25 09:54:03 -04:00
|
|
|
{
|
2016-12-06 08:42:51 -05:00
|
|
|
if(!inplace_cb_reply_servfail_call(m->s.env, &m->s.qinfo, &m->s,
|
2021-01-08 03:47:46 -05:00
|
|
|
rep, LDNS_RCODE_SERVFAIL, &r->edns, &r->query_reply, m->s.region, &r->start_time))
|
2021-11-08 05:50:29 -05:00
|
|
|
r->edns.opt_list_inplace_cb_out = NULL;
|
2022-05-06 06:48:53 -04:00
|
|
|
/* internal server error (probably malloc failure) so no
|
|
|
|
|
* EDE (RFC8914) needed */
|
2019-01-11 09:12:27 -05:00
|
|
|
error_encode(r_buffer, LDNS_RCODE_SERVFAIL,
|
|
|
|
|
&m->s.qinfo, r->qid, r->qflags, &r->edns);
|
2007-06-25 09:54:03 -04:00
|
|
|
}
|
2020-10-14 04:06:28 -04:00
|
|
|
m->reply_list = NULL;
|
2007-06-25 09:54:03 -04:00
|
|
|
comm_point_send_reply(&r->query_reply);
|
2020-10-14 04:06:28 -04:00
|
|
|
m->reply_list = rlist;
|
2007-06-25 09:54:03 -04:00
|
|
|
}
|
2024-05-01 04:10:58 -04:00
|
|
|
infra_wait_limit_dec(m->s.env->infra_cache, &r->query_reply,
|
|
|
|
|
m->s.env->cfg);
|
2007-06-25 09:54:03 -04:00
|
|
|
/* account */
|
2020-02-05 08:20:27 -05:00
|
|
|
log_assert(m->s.env->mesh->num_reply_addrs > 0);
|
2007-06-26 11:24:07 -04:00
|
|
|
m->s.env->mesh->num_reply_addrs--;
|
2008-02-19 08:12:23 -05:00
|
|
|
end_time = *m->s.env->now_tv;
|
|
|
|
|
timeval_subtract(&duration, &end_time, &r->start_time);
|
2014-01-16 11:01:37 -05:00
|
|
|
verbose(VERB_ALGO, "query took " ARG_LL "d.%6.6d sec",
|
2013-08-22 03:33:51 -04:00
|
|
|
(long long)duration.tv_sec, (int)duration.tv_usec);
|
2008-02-19 08:12:23 -05:00
|
|
|
m->s.env->mesh->replies_sent++;
|
|
|
|
|
timeval_add(&m->s.env->mesh->replies_sum_wait, &duration);
|
|
|
|
|
timehist_insert(m->s.env->mesh->histogram, &duration);
|
2008-09-16 10:08:38 -04:00
|
|
|
if(m->s.env->cfg->stat_extended) {
|
2019-01-11 09:12:27 -05:00
|
|
|
uint16_t rc = FLAGS_GET_RCODE(sldns_buffer_read_u16_at(
|
|
|
|
|
r_buffer, 2));
|
2008-09-16 10:08:38 -04:00
|
|
|
if(secure) m->s.env->mesh->ans_secure++;
|
|
|
|
|
m->s.env->mesh->ans_rcode[ rc ] ++;
|
2019-01-11 09:12:27 -05:00
|
|
|
if(rc == 0 && LDNS_ANCOUNT(sldns_buffer_begin(r_buffer)) == 0)
|
2008-09-16 10:08:38 -04:00
|
|
|
m->s.env->mesh->ans_nodata++;
|
|
|
|
|
}
|
2017-01-05 06:39:54 -05:00
|
|
|
/* Log reply sent */
|
|
|
|
|
if(m->s.env->cfg->log_replies) {
|
2022-10-03 09:29:47 -04:00
|
|
|
log_reply_info(NO_VERBOSE, &m->s.qinfo,
|
|
|
|
|
&r->query_reply.client_addr,
|
2023-12-05 04:05:51 -05:00
|
|
|
r->query_reply.client_addrlen, duration, 0, r_buffer,
|
2024-03-15 08:39:49 -04:00
|
|
|
(m->s.env->cfg->log_destaddr?(void*)r->query_reply.c->socket->addr:NULL),
|
2025-04-10 03:33:51 -04:00
|
|
|
r->query_reply.c->type, r->query_reply.c->ssl);
|
2017-01-05 06:39:54 -05:00
|
|
|
}
|
2007-06-25 09:54:03 -04:00
|
|
|
}
|
|
|
|
|
|
2025-04-07 04:25:10 -04:00
|
|
|
/**
|
|
|
|
|
* Generate the DNS Error Report (RFC9567).
|
|
|
|
|
* If there is an EDE attached for this reply and there was a Report-Channel
|
|
|
|
|
* EDNS0 option from the upstream, fire up a report query.
|
|
|
|
|
* @param qstate: module qstate.
|
|
|
|
|
* @param rep: prepared reply to be sent.
|
|
|
|
|
*/
|
|
|
|
|
static void dns_error_reporting(struct module_qstate* qstate,
|
|
|
|
|
struct reply_info* rep)
|
|
|
|
|
{
|
|
|
|
|
struct query_info qinfo;
|
|
|
|
|
struct mesh_state* sub;
|
|
|
|
|
struct module_qstate* newq;
|
|
|
|
|
uint8_t buf[LDNS_MAX_DOMAINLEN];
|
|
|
|
|
size_t count = 0;
|
|
|
|
|
int written;
|
|
|
|
|
size_t expected_length;
|
|
|
|
|
struct edns_option* opt;
|
|
|
|
|
sldns_ede_code reason_bogus = LDNS_EDE_NONE;
|
|
|
|
|
sldns_rr_type qtype = qstate->qinfo.qtype;
|
|
|
|
|
uint8_t* qname = qstate->qinfo.qname;
|
|
|
|
|
size_t qname_len = qstate->qinfo.qname_len-1; /* skip the trailing \0 */
|
|
|
|
|
uint8_t* agent_domain;
|
|
|
|
|
size_t agent_domain_len;
|
|
|
|
|
|
|
|
|
|
/* We need a valid reporting agent;
|
|
|
|
|
* this is based on qstate->edns_opts_back_in that will probably have
|
|
|
|
|
* the latest reporting agent we found while iterating */
|
|
|
|
|
opt = edns_opt_list_find(qstate->edns_opts_back_in,
|
|
|
|
|
LDNS_EDNS_REPORT_CHANNEL);
|
|
|
|
|
if(!opt) return;
|
|
|
|
|
agent_domain_len = opt->opt_len;
|
|
|
|
|
agent_domain = opt->opt_data;
|
|
|
|
|
if(dname_valid(agent_domain, agent_domain_len) < 3) {
|
|
|
|
|
/* The agent domain needs to be a valid dname that is not the
|
|
|
|
|
* root; from RFC9567. */
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Get the EDE generated from the mesh state, these are mostly
|
|
|
|
|
* validator errors. If other errors are produced in the future (e.g.,
|
|
|
|
|
* RPZ) we would not want them to result in error reports. */
|
|
|
|
|
reason_bogus = errinf_to_reason_bogus(qstate);
|
|
|
|
|
if(rep && ((reason_bogus == LDNS_EDE_DNSSEC_BOGUS &&
|
|
|
|
|
rep->reason_bogus != LDNS_EDE_NONE) ||
|
|
|
|
|
reason_bogus == LDNS_EDE_NONE)) {
|
|
|
|
|
reason_bogus = rep->reason_bogus;
|
|
|
|
|
}
|
|
|
|
|
if(reason_bogus == LDNS_EDE_NONE ||
|
|
|
|
|
/* other, does not make sense without the text that comes
|
|
|
|
|
* with it */
|
|
|
|
|
reason_bogus == LDNS_EDE_OTHER) return;
|
|
|
|
|
|
|
|
|
|
/* Synthesize the error report query in the format:
|
|
|
|
|
* "_er.$qtype.$qname.$ede._er.$reporting-agent-domain" */
|
|
|
|
|
/* First check if the static length parts fit in the buffer.
|
|
|
|
|
* That is everything except for qtype and ede that need to be
|
|
|
|
|
* converted to decimal and checked further on. */
|
|
|
|
|
expected_length = 4/*_er*/+qname_len+4/*_er*/+agent_domain_len;
|
|
|
|
|
if(expected_length > LDNS_MAX_DOMAINLEN) goto skip;
|
|
|
|
|
|
|
|
|
|
memmove(buf+count, "\3_er", 4);
|
|
|
|
|
count += 4;
|
|
|
|
|
|
|
|
|
|
written = snprintf((char*)buf+count, LDNS_MAX_DOMAINLEN-count,
|
|
|
|
|
"X%d", qtype);
|
|
|
|
|
expected_length += written;
|
|
|
|
|
/* Skip on error, truncation or long expected length */
|
|
|
|
|
if(written < 0 || (size_t)written >= LDNS_MAX_DOMAINLEN-count ||
|
|
|
|
|
expected_length > LDNS_MAX_DOMAINLEN ) goto skip;
|
|
|
|
|
/* Put in the label length */
|
|
|
|
|
*(buf+count) = (char)(written - 1);
|
|
|
|
|
count += written;
|
|
|
|
|
|
|
|
|
|
memmove(buf+count, qname, qname_len);
|
|
|
|
|
count += qname_len;
|
|
|
|
|
|
|
|
|
|
written = snprintf((char*)buf+count, LDNS_MAX_DOMAINLEN-count,
|
|
|
|
|
"X%d", reason_bogus);
|
|
|
|
|
expected_length += written;
|
|
|
|
|
/* Skip on error, truncation or long expected length */
|
|
|
|
|
if(written < 0 || (size_t)written >= LDNS_MAX_DOMAINLEN-count ||
|
|
|
|
|
expected_length > LDNS_MAX_DOMAINLEN ) goto skip;
|
|
|
|
|
*(buf+count) = (char)(written - 1);
|
|
|
|
|
count += written;
|
|
|
|
|
|
|
|
|
|
memmove(buf+count, "\3_er", 4);
|
|
|
|
|
count += 4;
|
|
|
|
|
|
|
|
|
|
/* Copy the agent domain */
|
|
|
|
|
memmove(buf+count, agent_domain, agent_domain_len);
|
|
|
|
|
count += agent_domain_len;
|
|
|
|
|
|
|
|
|
|
qinfo.qname = buf;
|
|
|
|
|
qinfo.qname_len = count;
|
|
|
|
|
qinfo.qtype = LDNS_RR_TYPE_TXT;
|
|
|
|
|
qinfo.qclass = qstate->qinfo.qclass;
|
|
|
|
|
qinfo.local_alias = NULL;
|
|
|
|
|
|
|
|
|
|
log_query_info(VERB_ALGO, "DNS Error Reporting: generating report "
|
|
|
|
|
"query for", &qinfo);
|
2025-09-30 05:28:15 -04:00
|
|
|
if(mesh_add_sub(qstate, &qinfo, NULL, BIT_RD, 0, 0, &newq, &sub)) {
|
2025-04-07 04:25:10 -04:00
|
|
|
qstate->env->mesh->num_dns_error_reports++;
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
skip:
|
|
|
|
|
verbose(VERB_ALGO, "DNS Error Reporting: report query qname too long; "
|
|
|
|
|
"skip");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2007-08-02 05:58:24 -04:00
|
|
|
void mesh_query_done(struct mesh_state* mstate)
|
2007-06-25 09:54:03 -04:00
|
|
|
{
|
2020-06-30 10:20:09 -04:00
|
|
|
struct mesh_reply* r;
|
2008-02-22 04:23:42 -05:00
|
|
|
struct mesh_reply* prev = NULL;
|
2019-01-11 09:12:27 -05:00
|
|
|
struct sldns_buffer* prev_buffer = NULL;
|
2007-12-06 10:11:07 -05:00
|
|
|
struct mesh_cb* c;
|
2007-08-02 05:58:24 -04:00
|
|
|
struct reply_info* rep = (mstate->s.return_msg?
|
|
|
|
|
mstate->s.return_msg->rep:NULL);
|
2021-01-01 17:29:32 -05:00
|
|
|
struct timeval tv = {0, 0};
|
2023-05-30 17:34:31 -04:00
|
|
|
int i = 0;
|
2020-02-05 08:20:27 -05:00
|
|
|
/* No need for the serve expired timer anymore; we are going to reply. */
|
|
|
|
|
if(mstate->s.serve_expired_data) {
|
|
|
|
|
comm_timer_delete(mstate->s.serve_expired_data->timer);
|
|
|
|
|
mstate->s.serve_expired_data->timer = NULL;
|
|
|
|
|
}
|
|
|
|
|
if(mstate->s.return_rcode == LDNS_RCODE_SERVFAIL ||
|
|
|
|
|
(rep && FLAGS_GET_RCODE(rep->flags) == LDNS_RCODE_SERVFAIL)) {
|
2024-12-31 10:28:12 -05:00
|
|
|
if(mstate->s.env->cfg->serve_expired) {
|
|
|
|
|
/* we are SERVFAILing; check for expired answer here */
|
|
|
|
|
mesh_respond_serve_expired(mstate);
|
|
|
|
|
}
|
2020-02-05 08:20:27 -05:00
|
|
|
if((mstate->reply_list || mstate->cb_list)
|
2018-08-17 11:22:05 -04:00
|
|
|
&& mstate->s.env->cfg->log_servfail
|
|
|
|
|
&& !mstate->s.env->cfg->val_log_squelch) {
|
2020-02-05 08:20:27 -05:00
|
|
|
char* err = errinf_to_str_servfail(&mstate->s);
|
2024-04-29 04:15:19 -04:00
|
|
|
if(err) { log_err("%s", err); }
|
2020-02-05 08:20:27 -05:00
|
|
|
}
|
2018-08-17 09:29:27 -04:00
|
|
|
}
|
2025-04-07 04:25:10 -04:00
|
|
|
|
|
|
|
|
if(mstate->reply_list && mstate->s.env->cfg->dns_error_reporting)
|
|
|
|
|
dns_error_reporting(&mstate->s, rep);
|
|
|
|
|
|
2020-06-30 10:20:09 -04:00
|
|
|
for(r = mstate->reply_list; r; r = r->next) {
|
2024-05-01 04:10:58 -04:00
|
|
|
struct timeval old;
|
|
|
|
|
timeval_subtract(&old, mstate->s.env->now_tv, &r->start_time);
|
|
|
|
|
if(mstate->s.env->cfg->discard_timeout != 0 &&
|
|
|
|
|
((int)old.tv_sec)*1000+((int)old.tv_usec)/1000 >
|
|
|
|
|
mstate->s.env->cfg->discard_timeout) {
|
|
|
|
|
/* Drop the reply, it is too old */
|
|
|
|
|
/* briefly set the reply_list to NULL, so that the
|
|
|
|
|
* tcp req info cleanup routine that calls the mesh
|
|
|
|
|
* to deregister the meshstate for it is not done
|
|
|
|
|
* because the list is NULL and also accounting is not
|
|
|
|
|
* done there, but instead we do that here. */
|
|
|
|
|
struct mesh_reply* reply_list = mstate->reply_list;
|
|
|
|
|
verbose(VERB_ALGO, "drop reply, it is older than discard-timeout");
|
|
|
|
|
infra_wait_limit_dec(mstate->s.env->infra_cache,
|
|
|
|
|
&r->query_reply, mstate->s.env->cfg);
|
|
|
|
|
mstate->reply_list = NULL;
|
2024-07-15 08:51:20 -04:00
|
|
|
if(r->query_reply.c->use_h2)
|
2024-07-16 08:23:10 -04:00
|
|
|
http2_stream_remove_mesh_state(r->h2_stream);
|
2024-05-01 04:10:58 -04:00
|
|
|
comm_point_drop_reply(&r->query_reply);
|
|
|
|
|
mstate->reply_list = reply_list;
|
2024-11-01 10:52:58 -04:00
|
|
|
mstate->s.env->mesh->num_queries_discard_timeout++;
|
2024-05-01 04:10:58 -04:00
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-30 17:34:31 -04:00
|
|
|
i++;
|
2021-01-08 03:53:52 -05:00
|
|
|
tv = r->start_time;
|
2021-01-01 17:29:32 -05:00
|
|
|
|
2017-03-07 09:58:51 -05:00
|
|
|
/* if a response-ip address block has been stored the
|
|
|
|
|
* information should be logged for each client. */
|
|
|
|
|
if(mstate->s.respip_action_info &&
|
|
|
|
|
mstate->s.respip_action_info->addrinfo) {
|
2019-08-01 08:31:37 -04:00
|
|
|
respip_inform_print(mstate->s.respip_action_info,
|
2017-03-07 09:58:51 -05:00
|
|
|
r->qname, mstate->s.qinfo.qtype,
|
|
|
|
|
mstate->s.qinfo.qclass, r->local_alias,
|
2022-10-03 09:29:47 -04:00
|
|
|
&r->query_reply.client_addr,
|
|
|
|
|
r->query_reply.client_addrlen);
|
2017-03-07 09:58:51 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* if this query is determined to be dropped during the
|
|
|
|
|
* mesh processing, this is the point to take that action. */
|
2020-02-05 08:20:27 -05:00
|
|
|
if(mstate->s.is_drop) {
|
2020-06-30 10:20:09 -04:00
|
|
|
/* briefly set the reply_list to NULL, so that the
|
|
|
|
|
* tcp req info cleanup routine that calls the mesh
|
|
|
|
|
* to deregister the meshstate for it is not done
|
|
|
|
|
* because the list is NULL and also accounting is not
|
|
|
|
|
* done there, but instead we do that here. */
|
|
|
|
|
struct mesh_reply* reply_list = mstate->reply_list;
|
2024-05-01 04:10:58 -04:00
|
|
|
infra_wait_limit_dec(mstate->s.env->infra_cache,
|
|
|
|
|
&r->query_reply, mstate->s.env->cfg);
|
2020-06-30 10:20:09 -04:00
|
|
|
mstate->reply_list = NULL;
|
2024-07-15 08:51:20 -04:00
|
|
|
if(r->query_reply.c->use_h2) {
|
2024-07-16 08:23:10 -04:00
|
|
|
http2_stream_remove_mesh_state(r->h2_stream);
|
2024-07-15 08:51:20 -04:00
|
|
|
}
|
2017-03-07 09:58:51 -05:00
|
|
|
comm_point_drop_reply(&r->query_reply);
|
2020-06-30 10:20:09 -04:00
|
|
|
mstate->reply_list = reply_list;
|
2020-02-05 08:20:27 -05:00
|
|
|
} else {
|
2019-01-11 09:12:27 -05:00
|
|
|
struct sldns_buffer* r_buffer = r->query_reply.c->buffer;
|
2019-05-13 09:39:59 -04:00
|
|
|
if(r->query_reply.c->tcp_req_info) {
|
2019-01-11 09:12:27 -05:00
|
|
|
r_buffer = r->query_reply.c->tcp_req_info->spool_buffer;
|
2019-05-13 09:39:59 -04:00
|
|
|
prev_buffer = NULL;
|
|
|
|
|
}
|
2017-03-07 09:58:51 -05:00
|
|
|
mesh_send_reply(mstate, mstate->s.return_rcode, rep,
|
2019-01-11 09:12:27 -05:00
|
|
|
r, r_buffer, prev, prev_buffer);
|
2019-05-13 09:39:59 -04:00
|
|
|
if(r->query_reply.c->tcp_req_info) {
|
2019-01-11 09:12:27 -05:00
|
|
|
tcp_req_info_remove_mesh_state(r->query_reply.c->tcp_req_info, mstate);
|
2019-05-13 09:39:59 -04:00
|
|
|
r_buffer = NULL;
|
|
|
|
|
}
|
2024-07-16 08:23:10 -04:00
|
|
|
/* mesh_send_reply removed mesh state from
|
|
|
|
|
* http2_stream. */
|
2017-03-07 09:58:51 -05:00
|
|
|
prev = r;
|
2019-01-11 09:12:27 -05:00
|
|
|
prev_buffer = r_buffer;
|
2017-03-07 09:58:51 -05:00
|
|
|
}
|
2007-06-25 09:54:03 -04:00
|
|
|
}
|
2023-05-30 17:34:31 -04:00
|
|
|
/* Account for each reply sent. */
|
|
|
|
|
if(i > 0 && mstate->s.respip_action_info &&
|
|
|
|
|
mstate->s.respip_action_info->addrinfo &&
|
|
|
|
|
mstate->s.env->cfg->stat_extended &&
|
|
|
|
|
mstate->s.respip_action_info->rpz_used) {
|
|
|
|
|
if(mstate->s.respip_action_info->rpz_disabled)
|
|
|
|
|
mstate->s.env->mesh->rpz_action[RPZ_DISABLED_ACTION] += i;
|
|
|
|
|
if(mstate->s.respip_action_info->rpz_cname_override)
|
|
|
|
|
mstate->s.env->mesh->rpz_action[RPZ_CNAME_OVERRIDE_ACTION] += i;
|
|
|
|
|
else
|
|
|
|
|
mstate->s.env->mesh->rpz_action[respip_action_to_rpz_action(
|
|
|
|
|
mstate->s.respip_action_info->action)] += i;
|
|
|
|
|
}
|
|
|
|
|
if(!mstate->s.is_drop && i > 0) {
|
|
|
|
|
if(mstate->s.env->cfg->stat_extended
|
|
|
|
|
&& mstate->s.is_cachedb_answer) {
|
|
|
|
|
mstate->s.env->mesh->ans_cachedb += i;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Mesh area accounting */
|
2020-06-30 09:48:11 -04:00
|
|
|
if(mstate->reply_list) {
|
|
|
|
|
mstate->reply_list = NULL;
|
|
|
|
|
if(!mstate->reply_list && !mstate->cb_list) {
|
|
|
|
|
/* was a reply state, not anymore */
|
|
|
|
|
log_assert(mstate->s.env->mesh->num_reply_states > 0);
|
|
|
|
|
mstate->s.env->mesh->num_reply_states--;
|
|
|
|
|
}
|
|
|
|
|
if(!mstate->reply_list && !mstate->cb_list &&
|
|
|
|
|
mstate->super_set.count == 0)
|
|
|
|
|
mstate->s.env->mesh->num_detached_states++;
|
|
|
|
|
}
|
2008-11-05 05:38:22 -05:00
|
|
|
mstate->replies_sent = 1;
|
2023-05-30 17:34:31 -04:00
|
|
|
|
2018-04-23 08:51:00 -04:00
|
|
|
while((c = mstate->cb_list) != NULL) {
|
|
|
|
|
/* take this cb off the list; so that the list can be
|
|
|
|
|
* changed, eg. by adds from the callback routine */
|
2018-05-07 07:29:12 -04:00
|
|
|
if(!mstate->reply_list && mstate->cb_list && !c->next) {
|
|
|
|
|
/* was a reply state, not anymore */
|
2020-02-05 08:20:27 -05:00
|
|
|
log_assert(mstate->s.env->mesh->num_reply_states > 0);
|
2018-05-07 07:29:12 -04:00
|
|
|
mstate->s.env->mesh->num_reply_states--;
|
|
|
|
|
}
|
2018-04-23 08:51:00 -04:00
|
|
|
mstate->cb_list = c->next;
|
|
|
|
|
if(!mstate->reply_list && !mstate->cb_list &&
|
|
|
|
|
mstate->super_set.count == 0)
|
|
|
|
|
mstate->s.env->mesh->num_detached_states++;
|
2021-01-08 03:47:46 -05:00
|
|
|
mesh_do_callback(mstate, mstate->s.return_rcode, rep, c, &tv);
|
2007-12-06 10:11:07 -05:00
|
|
|
}
|
2007-06-25 09:54:03 -04:00
|
|
|
}
|
|
|
|
|
|
2007-08-02 08:22:29 -04:00
|
|
|
void mesh_walk_supers(struct mesh_area* mesh, struct mesh_state* mstate)
|
2007-06-25 09:54:03 -04:00
|
|
|
{
|
|
|
|
|
struct mesh_state_ref* ref;
|
2007-08-02 08:22:29 -04:00
|
|
|
RBTREE_FOR(ref, struct mesh_state_ref*, &mstate->super_set)
|
2007-06-25 09:54:03 -04:00
|
|
|
{
|
|
|
|
|
/* make super runnable */
|
|
|
|
|
(void)rbtree_insert(&mesh->run, &ref->s->run_node);
|
2007-08-01 10:01:34 -04:00
|
|
|
/* callback the function to inform super of result */
|
2008-02-20 02:18:42 -05:00
|
|
|
fptr_ok(fptr_whitelist_mod_inform_super(
|
2007-12-04 08:23:41 -05:00
|
|
|
mesh->mods.mod[ref->s->s.curmod]->inform_super));
|
2023-04-20 11:39:55 -04:00
|
|
|
(*mesh->mods.mod[ref->s->s.curmod]->inform_super)(&mstate->s,
|
2007-08-02 08:13:08 -04:00
|
|
|
ref->s->s.curmod, &ref->s->s);
|
2018-08-03 10:00:46 -04:00
|
|
|
/* copy state that is always relevant to super */
|
|
|
|
|
copy_state_to_super(&mstate->s, ref->s->s.curmod, &ref->s->s);
|
2007-06-25 09:54:03 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct mesh_state* mesh_area_find(struct mesh_area* mesh,
|
2017-03-07 09:58:51 -05:00
|
|
|
struct respip_client_info* cinfo, struct query_info* qinfo,
|
|
|
|
|
uint16_t qflags, int prime, int valrec)
|
2007-06-25 09:54:03 -04:00
|
|
|
{
|
|
|
|
|
struct mesh_state key;
|
|
|
|
|
struct mesh_state* result;
|
|
|
|
|
|
|
|
|
|
key.node.key = &key;
|
2007-08-01 08:59:37 -04:00
|
|
|
key.s.is_priming = prime;
|
2014-11-18 10:15:57 -05:00
|
|
|
key.s.is_valrec = valrec;
|
2007-06-25 09:54:03 -04:00
|
|
|
key.s.qinfo = *qinfo;
|
|
|
|
|
key.s.query_flags = qflags;
|
2016-12-06 08:42:51 -05:00
|
|
|
/* We are searching for a similar mesh state when we DO want to
|
|
|
|
|
* aggregate the state. Thus unique is set to NULL. (default when we
|
|
|
|
|
* desire aggregation).*/
|
|
|
|
|
key.unique = NULL;
|
2017-03-07 09:58:51 -05:00
|
|
|
key.s.client_info = cinfo;
|
2023-04-20 11:39:55 -04:00
|
|
|
|
2007-06-25 09:54:03 -04:00
|
|
|
result = (struct mesh_state*)rbtree_search(&mesh->all, &key);
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
Fast Reload Option (#1042)
* - fast-reload, add unbound-control fast_reload
* - fast-reload, make a thread to service the unbound-control command.
* - fast-reload, communication sockets for information transfer.
* - fast-reload, fix compile for unbound-dnstap-socket.
* - fast-reload, set nonblocking communication to keep the server thread
responding to DNS requests.
* - fast-reload, poll routine to test for readiness, timeout fails connection.
* - fast-reload, detect loop in sock_poll_timeout routine.
* - fast-reload, send done and exited notification.
* - fast-reload, defines for constants in ipc.
* - fast-reload, ipc socket recv and send resists partial reads and writes and
can continue byte by byte. Also it can continue after an interrupt.
* - fast-reload, send exit command to thread when done.
* - fast-reload, output strings for client on string list.
* - fast-reload, add newline to terminal output.
* - fast-reload, send client string to remote client.
* - fast-reload, better debug output.
* - fast-reload, print queue structure, for output to the remote client.
* - fast-reload, move print items to print queue from fast_reload_thread struct.
* - fast-reload, keep list of pending print queue items in daemon struct.
* - fast-reload, comment explains in_list for printq to print remainder.
* - fast-reload, unit test testdata/fast_reload_thread.tdir that tests the
thread output.
* - fast-reload, fix test link for fast_reload_printq_list_delete function.
* - fast-reload, reread config file from disk.
* - fast-reload, unshare forwards, making the structure locked, with an rwlock.
* - fast-reload, for nonthreaded, the unbound-control commands forward,
forward_add and forward_delete should be distributed to other processes,
but when threaded, they should not be distributed to other threads because
the structure is not thread specific any more.
* - fast-reload, unshared stub hints, making the structure locked, with an rwlock.
* - fast-reload, helpful comments for hints lookup function return value.
* - fast-reload, fix bug in fast reload printout, the strlist appendlist routine,
and printout time statistics after the reload is done.
* - fast-reload, keep track of reloadtime and deletestime and print them.
* - fast-reload, keep track of constructtime and print it.
* - fast-reload, construct new items.
* - fast-reload, better comment.
* - fast-reload, reload the config and swap trees for forwards and stub hints.
* - fast-reload, in forwards_swap_tree set protection of trees with locks.
* - fast-reload, in hints_swap_tree also swap the node count of the trees.
* - fast-reload, reload ipc to stop and start threads.
* - fast-reload, unused forward declarations removed.
* - fast-reload, unit test that fast reload works with forwards and stubs.
* - fast-reload, fix clang analyzer warnings.
* - fast-reload, small documentation entry in unbound-control -h output.
* - fast-reload, printout memory use by fast reload, in bytes.
* - fast-reload, compile without threads.
* - fast-reload, document fast_reload in man page.
* - fast-reload, print ok when done successfully.
* - fast-reload, option for fast-reload commandline, +v verbosity option,
with timing and memory use output.
* - fast-reload, option for fast-reload commandline, +p does not pause threads.
* - fast-reload, option for fast-reload commandline, +d drops mesh queries.
* - fast-reload, fix to poll every thread with nopause to make certain that
resources are not held by the threads and can be deleted.
* - fast-reload, fix to use atomic store for config variables with nopause.
* - fast-reload, reload views.
* - fast-reload, when tag defines are different, it drops the queries.
* - fast-reload, fix tag define check.
* - fast-reload, document that tag change causes drop of queries.
* - fast-reload, fix space in documentation man page.
* - fast-reload, copy respip client information to query state, put views tree
in module env for lookup.
* - fast-reload, nicer respip view comparison.
* - fast-reload, respip global set is in module env.
* - fast-reload, document that respip_client_info acl info is copied.
* - fast-reload, reload the respip_set.
* - fast-reload, document no pause and pick up of use_response_ip boolean.
* - fast-reload, fix test compile.
* - fast-reload, reload local zones.
* Update locking management for iter_fwd and iter_hints methods. (#1054)
fast reload, move most of the locking management to iter_fwd and
iter_hints methods. The caller still has the ability to handle its
own locking, if desired, for atomic operations on sets of different
structs.
Co-authored-by: Wouter Wijngaards <wcawijngaards@users.noreply.github.com>
* - fast-reload, reload access-control.
* - fast-reload, reload access control interface, such as interface-action.
* - fast-reload, reload tcp-connection-limit.
* - fast-reload, improve comments on acl_list and tcl_list swap tree.
* - fast-reload, fixup references to old tcp connection limits in open tcp
connections.
* - fast-reload, fixup to clean tcp connection also for different linked order.
* - fast-reload, if no tcp connection limits existed, no need to remove
references for that.
* - fast-reload, document more options that work and do not work.
* - fast-reload, reload auth_zone and rpz data.
* - fast-reload, fix auth_zones_get_mem.
* - fast-reload, fix compilation of testbound for the new comm_timer_get_mem
reference in remote control.
* - fast-reload, change use_rpz with reload.
* - fast-reload, list changes in auth zones and stop zonemd callbacks for
deleted auth zones.
* - fast-reload, note xtree is not swapped, and why it is not swapped.
* - fast-reload, for added auth zones, pick up zone transfer and zonemd tasks.
* - fast-reload, unlock xfr when done with transfer pick up.
* - fast-reload, unlock z when picking up the xfr for it during transfer task
pick up.
* - fast-reload, pick up task changes for added, deleted and modified auth zones.
* - fast-reload, remove xfr of auth zone deletion without tasks.
* - fast-reload, pick up zone transfer config.
* - fast-reload, the main worker thread picks up the transfer tasks and also
performs setup of the xfer struct.
* - fast-reload, keep writelock on newzone when auth zone changes.
* - fast-reload, change cachedb_enabled setting.
* - fast-reload, pick up edns-strings config.
* - fast-reload, note that settings are not updated.
* - fast-reload, pick up dnstap config.
* - fast-reload, dnstap options that need to be loaded without +p.
* - fast-reload, fix auth zone reload
* - fast-reload, remove debug for auth zone test.
* - fast-reload, fix auth zone reload with zone transfer.
* - fast-reload, fix auth zone reload lock order.
* - fast-reload, remove debug from fast reload test.
* - fast-reload, remove unused function.
* - fast-reload, fix the worker trust anchor probe timer lock acquisition in
the probe answer callback routine for trust anchor probes.
* - fast-reload, reload trust anchors.
* - fast-reload, fix trust anchor reload lock on autr global data and test
for trust anchor reload.
* - fast-reload, adjust cache sizes.
* - fast-reload, reload cache sizes when changed.
* - fast-reload, reload validator env changes.
* - fast-reload, reload mesh changes.
* - fast-reload, check for incompatible changes.
* - fast-reload, improve error text for incompatible change.
* - fast-reload, fix check config option compatibility.
* - fast-reload, improve error text for nopause change.
* - fast-reload, fix spelling of incompatible options.
* - fast-reload, reload target-fetch-policy, outbound-msg-retry, max-sent-count
and max-query-restarts.
* - fast-reload, check nopause config change for target-fetch-policy.
* - fast-reload, reload do-not-query-address, private-address and capt-exempt.
* - fast-reload, check nopause config change for do-not-query-address,
private-address and capt-exempt.
* - fast-reload, check fast reload not possible due to interface and
outgoing-interface changes.
* - fast-reload, reload nat64 settings.
* - fast-reload, reload settings stored in the infra structure.
* - fast-reload, fix modstack lookup and remove outgoing-range check.
* - fast-reload, more explanation for config parse failure.
* - fast-reload, reload worker outside network changes.
* - fast-reload, detect incompatible changes in network settings.
* fast-reload, commit test files.
* - fast-reload, fix warnings for call types in windows compile.
* - fast-reload, fix warnings and comm_point_internal for tcp wouldblock calls.
* - fast-reload, extend lock checks for repeat thread ids.
* - fast-reload, additional test cases, cache change and tag changes.
* - fast-reload, fix documentation for auth_zone_verify_zonemd_with_key.
* - fast-reload, fix copy_cfg type casts and memory leak on config parse failure.
* - fast-reload, fix use of WSAPoll.
* Review comments for the fast reload feature (#1259)
* - fast-reload review, respip set can be null from a view.
* - fast-reload review, typos.
* - fast-reload review, keep clang static analyzer happy.
* - fast-reload review, don't forget to copy tag_actions.
* - fast-reload review, less indentation.
* - fast-reload review, don't leak respip_actions when reloading.
* - fast-reload review, protect NULL pointer dereference in get_mem
functions.
* - fast-reload review, add fast_reload_most_options.tdir to test most
options with high verbosity when fast reloading.
* - fast-reload review, don't skip new line on long error printouts.
* - fast-reload review, typo.
* - fast-reload review, use new_z for consistency.
* - fast-reload review, nit for unlock ordering to make eye comparison
with the lock counterpart easier.
* - fast-reload review, in case of error the sockets are already closed.
* - fast-reload review, identation.
* - fast-reload review, add static keywords.
* - fast-reload review, update unbound-control usage text.
* - fast-reload review, updates to the man page.
* - fast-reload, the fast-reload command is experimental.
* - fast-reload, fix compile of doqclient for fast reload functions.
* Changelog comment for #1042
- Merge #1042: Fast Reload. The unbound-control fast_reload is added.
It reads changed config in a thread, then only briefly pauses the
service threads, that keep running. DNS service is only interrupted
briefly, less than a second.
---------
Co-authored-by: Yorgos Thessalonikefs <yorgos@nlnetlabs.nl>
2025-03-31 09:25:24 -04:00
|
|
|
/** remove mesh state callback */
|
|
|
|
|
int mesh_state_del_cb(struct mesh_state* s, mesh_cb_func_type cb, void* cb_arg)
|
|
|
|
|
{
|
|
|
|
|
struct mesh_cb* r, *prev = NULL;
|
|
|
|
|
r = s->cb_list;
|
|
|
|
|
while(r) {
|
|
|
|
|
if(r->cb == cb && r->cb_arg == cb_arg) {
|
|
|
|
|
/* Delete this entry. */
|
|
|
|
|
/* It was allocated in the s.region, so no free. */
|
|
|
|
|
if(prev) prev->next = r->next;
|
|
|
|
|
else s->cb_list = r->next;
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
prev = r;
|
|
|
|
|
r = r->next;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2007-12-06 10:11:07 -05:00
|
|
|
int mesh_state_add_cb(struct mesh_state* s, struct edns_data* edns,
|
2017-01-19 05:25:41 -05:00
|
|
|
sldns_buffer* buf, mesh_cb_func_type cb, void* cb_arg,
|
2007-12-06 10:11:07 -05:00
|
|
|
uint16_t qid, uint16_t qflags)
|
|
|
|
|
{
|
2023-04-20 11:39:55 -04:00
|
|
|
struct mesh_cb* r = regional_alloc(s->s.region,
|
2007-12-06 10:11:07 -05:00
|
|
|
sizeof(struct mesh_cb));
|
|
|
|
|
if(!r)
|
|
|
|
|
return 0;
|
|
|
|
|
r->buf = buf;
|
2009-06-12 10:16:13 -04:00
|
|
|
log_assert(fptr_whitelist_mesh_cb(cb)); /* early failure ifmissing*/
|
2007-12-06 10:11:07 -05:00
|
|
|
r->cb = cb;
|
|
|
|
|
r->cb_arg = cb_arg;
|
|
|
|
|
r->edns = *edns;
|
2021-11-01 09:48:31 -04:00
|
|
|
if(edns->opt_list_in && !(r->edns.opt_list_in =
|
|
|
|
|
edns_opt_copy_region(edns->opt_list_in, s->s.region)))
|
|
|
|
|
return 0;
|
|
|
|
|
if(edns->opt_list_out && !(r->edns.opt_list_out =
|
|
|
|
|
edns_opt_copy_region(edns->opt_list_out, s->s.region)))
|
|
|
|
|
return 0;
|
2021-11-08 05:50:29 -05:00
|
|
|
if(edns->opt_list_inplace_cb_out && !(r->edns.opt_list_inplace_cb_out =
|
|
|
|
|
edns_opt_copy_region(edns->opt_list_inplace_cb_out, s->s.region)))
|
2021-11-01 09:48:31 -04:00
|
|
|
return 0;
|
2007-12-06 10:11:07 -05:00
|
|
|
r->qid = qid;
|
|
|
|
|
r->qflags = qflags;
|
|
|
|
|
r->next = s->cb_list;
|
|
|
|
|
s->cb_list = r;
|
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2007-06-25 09:54:03 -04:00
|
|
|
int mesh_state_add_reply(struct mesh_state* s, struct edns_data* edns,
|
2016-10-18 09:18:20 -04:00
|
|
|
struct comm_reply* rep, uint16_t qid, uint16_t qflags,
|
|
|
|
|
const struct query_info* qinfo)
|
2007-06-25 09:54:03 -04:00
|
|
|
{
|
2021-02-17 07:39:15 -05:00
|
|
|
struct mesh_reply* r = regional_alloc(s->s.region,
|
2007-06-25 09:54:03 -04:00
|
|
|
sizeof(struct mesh_reply));
|
|
|
|
|
if(!r)
|
|
|
|
|
return 0;
|
|
|
|
|
r->query_reply = *rep;
|
|
|
|
|
r->edns = *edns;
|
2021-11-01 09:48:31 -04:00
|
|
|
if(edns->opt_list_in && !(r->edns.opt_list_in =
|
|
|
|
|
edns_opt_copy_region(edns->opt_list_in, s->s.region)))
|
|
|
|
|
return 0;
|
|
|
|
|
if(edns->opt_list_out && !(r->edns.opt_list_out =
|
|
|
|
|
edns_opt_copy_region(edns->opt_list_out, s->s.region)))
|
|
|
|
|
return 0;
|
2021-11-08 05:50:29 -05:00
|
|
|
if(edns->opt_list_inplace_cb_out && !(r->edns.opt_list_inplace_cb_out =
|
|
|
|
|
edns_opt_copy_region(edns->opt_list_inplace_cb_out, s->s.region)))
|
2021-11-01 09:48:31 -04:00
|
|
|
return 0;
|
2007-06-25 09:54:03 -04:00
|
|
|
r->qid = qid;
|
|
|
|
|
r->qflags = qflags;
|
2008-02-19 08:12:23 -05:00
|
|
|
r->start_time = *s->s.env->now_tv;
|
2007-06-25 09:54:03 -04:00
|
|
|
r->next = s->reply_list;
|
2016-10-18 09:18:20 -04:00
|
|
|
r->qname = regional_alloc_init(s->s.region, qinfo->qname,
|
2008-02-26 15:45:20 -05:00
|
|
|
s->s.qinfo.qname_len);
|
|
|
|
|
if(!r->qname)
|
|
|
|
|
return 0;
|
2020-09-16 12:25:02 -04:00
|
|
|
if(rep->c->use_h2)
|
2020-05-07 10:36:26 -04:00
|
|
|
r->h2_stream = rep->c->h2_stream;
|
2024-07-16 08:23:10 -04:00
|
|
|
else r->h2_stream = NULL;
|
2016-10-18 09:18:20 -04:00
|
|
|
|
|
|
|
|
/* Data related to local alias stored in 'qinfo' (if any) is ephemeral
|
|
|
|
|
* and can be different for different original queries (even if the
|
|
|
|
|
* replaced query name is the same). So we need to make a deep copy
|
|
|
|
|
* and store the copy for each reply info. */
|
|
|
|
|
if(qinfo->local_alias) {
|
|
|
|
|
struct packed_rrset_data* d;
|
|
|
|
|
struct packed_rrset_data* dsrc;
|
|
|
|
|
r->local_alias = regional_alloc_zero(s->s.region,
|
|
|
|
|
sizeof(*qinfo->local_alias));
|
|
|
|
|
if(!r->local_alias)
|
|
|
|
|
return 0;
|
|
|
|
|
r->local_alias->rrset = regional_alloc_init(s->s.region,
|
|
|
|
|
qinfo->local_alias->rrset,
|
|
|
|
|
sizeof(*qinfo->local_alias->rrset));
|
|
|
|
|
if(!r->local_alias->rrset)
|
|
|
|
|
return 0;
|
|
|
|
|
dsrc = qinfo->local_alias->rrset->entry.data;
|
|
|
|
|
|
|
|
|
|
/* In the current implementation, a local alias must be
|
|
|
|
|
* a single CNAME RR (see worker_handle_request()). */
|
|
|
|
|
log_assert(!qinfo->local_alias->next && dsrc->count == 1 &&
|
|
|
|
|
qinfo->local_alias->rrset->rk.type ==
|
|
|
|
|
htons(LDNS_RR_TYPE_CNAME));
|
2019-07-23 08:01:59 -04:00
|
|
|
/* we should make a local copy for the owner name of
|
|
|
|
|
* the RRset */
|
|
|
|
|
r->local_alias->rrset->rk.dname_len =
|
|
|
|
|
qinfo->local_alias->rrset->rk.dname_len;
|
|
|
|
|
r->local_alias->rrset->rk.dname = regional_alloc_init(
|
|
|
|
|
s->s.region, qinfo->local_alias->rrset->rk.dname,
|
|
|
|
|
qinfo->local_alias->rrset->rk.dname_len);
|
|
|
|
|
if(!r->local_alias->rrset->rk.dname)
|
|
|
|
|
return 0;
|
2016-10-18 09:18:20 -04:00
|
|
|
|
2019-04-25 10:07:42 -04:00
|
|
|
/* the rrset is not packed, like in the cache, but it is
|
2021-11-13 09:56:15 -05:00
|
|
|
* individually allocated with an allocator from localzone. */
|
2019-04-25 10:07:42 -04:00
|
|
|
d = regional_alloc_zero(s->s.region, sizeof(*d));
|
2016-10-18 09:18:20 -04:00
|
|
|
if(!d)
|
|
|
|
|
return 0;
|
|
|
|
|
r->local_alias->rrset->entry.data = d;
|
2019-04-25 10:07:42 -04:00
|
|
|
if(!rrset_insert_rr(s->s.region, d, dsrc->rr_data[0],
|
|
|
|
|
dsrc->rr_len[0], dsrc->rr_ttl[0], "CNAME local alias"))
|
2016-10-18 09:18:20 -04:00
|
|
|
return 0;
|
|
|
|
|
} else
|
|
|
|
|
r->local_alias = NULL;
|
|
|
|
|
|
2007-06-25 09:54:03 -04:00
|
|
|
s->reply_list = r;
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-19 05:08:29 -04:00
|
|
|
/* Extract the query info and flags from 'mstate' into '*qinfop' and '*qflags'.
|
|
|
|
|
* Since this is only used for internal refetch of otherwise-expired answer,
|
|
|
|
|
* we simply ignore the rare failure mode when memory allocation fails. */
|
|
|
|
|
static void
|
|
|
|
|
mesh_copy_qinfo(struct mesh_state* mstate, struct query_info** qinfop,
|
|
|
|
|
uint16_t* qflags)
|
|
|
|
|
{
|
|
|
|
|
struct regional* region = mstate->s.env->scratch;
|
|
|
|
|
struct query_info* qinfo;
|
|
|
|
|
|
|
|
|
|
qinfo = regional_alloc_init(region, &mstate->s.qinfo, sizeof(*qinfo));
|
|
|
|
|
if(!qinfo)
|
|
|
|
|
return;
|
|
|
|
|
qinfo->qname = regional_alloc_init(region, qinfo->qname,
|
|
|
|
|
qinfo->qname_len);
|
|
|
|
|
if(!qinfo->qname)
|
|
|
|
|
return;
|
|
|
|
|
*qinfop = qinfo;
|
|
|
|
|
*qflags = mstate->s.query_flags;
|
|
|
|
|
}
|
|
|
|
|
|
2007-08-02 05:58:24 -04:00
|
|
|
/**
|
|
|
|
|
* Continue processing the mesh state at another module.
|
2017-09-15 10:29:28 -04:00
|
|
|
* Handles module to modules transfer of control.
|
2007-08-02 05:58:24 -04:00
|
|
|
* Handles module finished.
|
|
|
|
|
* @param mesh: the mesh area.
|
|
|
|
|
* @param mstate: currently active mesh state.
|
2023-04-20 11:39:55 -04:00
|
|
|
* Deleted if finished, calls _done and _supers to
|
2007-08-02 05:58:24 -04:00
|
|
|
* send replies to clients and inform other mesh states.
|
|
|
|
|
* This in turn may create additional runnable mesh states.
|
|
|
|
|
* @param s: state at which the current module exited.
|
|
|
|
|
* @param ev: the event sent to the module.
|
|
|
|
|
* returned is the event to send to the next module.
|
|
|
|
|
* @return true if continue processing at the new module.
|
|
|
|
|
* false if not continued processing is needed.
|
|
|
|
|
*/
|
|
|
|
|
static int
|
|
|
|
|
mesh_continue(struct mesh_area* mesh, struct mesh_state* mstate,
|
|
|
|
|
enum module_ext_state s, enum module_ev* ev)
|
|
|
|
|
{
|
2007-10-03 04:36:47 -04:00
|
|
|
mstate->num_activated++;
|
|
|
|
|
if(mstate->num_activated > MESH_MAX_ACTIVATION) {
|
|
|
|
|
/* module is looping. Stop it. */
|
2017-09-21 04:19:47 -04:00
|
|
|
log_err("internal error: looping module (%s) stopped",
|
|
|
|
|
mesh->mods.mod[mstate->s.curmod]->name);
|
2019-11-20 08:22:06 -05:00
|
|
|
log_query_info(NO_VERBOSE, "pass error for qstate",
|
2007-10-03 04:36:47 -04:00
|
|
|
&mstate->s.qinfo);
|
|
|
|
|
s = module_error;
|
|
|
|
|
}
|
2009-10-06 04:31:47 -04:00
|
|
|
if(s == module_wait_module || s == module_restart_next) {
|
2007-08-02 05:58:24 -04:00
|
|
|
/* start next module */
|
|
|
|
|
mstate->s.curmod++;
|
2007-12-04 08:23:41 -05:00
|
|
|
if(mesh->mods.num == mstate->s.curmod) {
|
2007-08-02 05:58:24 -04:00
|
|
|
log_err("Cannot pass to next module; at last module");
|
2008-02-07 04:46:49 -05:00
|
|
|
log_query_info(VERB_QUERY, "pass error for qstate",
|
2007-08-02 05:58:24 -04:00
|
|
|
&mstate->s.qinfo);
|
|
|
|
|
mstate->s.curmod--;
|
|
|
|
|
return mesh_continue(mesh, mstate, module_error, ev);
|
|
|
|
|
}
|
2009-10-06 04:31:47 -04:00
|
|
|
if(s == module_restart_next) {
|
2017-04-06 09:13:06 -04:00
|
|
|
int curmod = mstate->s.curmod;
|
2023-04-20 11:39:55 -04:00
|
|
|
for(; mstate->s.curmod < mesh->mods.num;
|
2017-04-06 09:13:06 -04:00
|
|
|
mstate->s.curmod++) {
|
|
|
|
|
fptr_ok(fptr_whitelist_mod_clear(
|
|
|
|
|
mesh->mods.mod[mstate->s.curmod]->clear));
|
|
|
|
|
(*mesh->mods.mod[mstate->s.curmod]->clear)
|
|
|
|
|
(&mstate->s, mstate->s.curmod);
|
|
|
|
|
mstate->s.minfo[mstate->s.curmod] = NULL;
|
|
|
|
|
}
|
|
|
|
|
mstate->s.curmod = curmod;
|
2009-10-06 04:31:47 -04:00
|
|
|
}
|
2007-08-02 05:58:24 -04:00
|
|
|
*ev = module_event_pass;
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
2016-08-23 04:30:12 -04:00
|
|
|
if(s == module_wait_subquery && mstate->sub_set.count == 0) {
|
|
|
|
|
log_err("module cannot wait for subquery, subquery list empty");
|
|
|
|
|
log_query_info(VERB_QUERY, "pass error for qstate",
|
|
|
|
|
&mstate->s.qinfo);
|
|
|
|
|
s = module_error;
|
|
|
|
|
}
|
2007-08-02 05:58:24 -04:00
|
|
|
if(s == module_error && mstate->s.return_rcode == LDNS_RCODE_NOERROR) {
|
|
|
|
|
/* error is bad, handle pass back up below */
|
|
|
|
|
mstate->s.return_rcode = LDNS_RCODE_SERVFAIL;
|
|
|
|
|
}
|
2017-09-18 03:54:24 -04:00
|
|
|
if(s == module_error) {
|
|
|
|
|
mesh_query_done(mstate);
|
|
|
|
|
mesh_walk_supers(mesh, mstate);
|
|
|
|
|
mesh_state_delete(&mstate->s);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
if(s == module_finished) {
|
2007-08-02 05:58:24 -04:00
|
|
|
if(mstate->s.curmod == 0) {
|
2017-09-19 05:08:29 -04:00
|
|
|
struct query_info* qinfo = NULL;
|
2023-07-07 10:27:49 -04:00
|
|
|
struct edns_option* opt_list = NULL;
|
2023-07-06 15:57:27 -04:00
|
|
|
struct sockaddr_storage addr;
|
2017-09-19 05:08:29 -04:00
|
|
|
uint16_t qflags;
|
2022-02-15 10:20:12 -05:00
|
|
|
int rpz_p = 0;
|
2017-09-19 05:08:29 -04:00
|
|
|
|
2023-07-06 15:57:27 -04:00
|
|
|
#ifdef CLIENT_SUBNET
|
2023-07-07 10:27:49 -04:00
|
|
|
struct edns_option* ecs;
|
2023-07-06 15:57:27 -04:00
|
|
|
if(mstate->s.need_refetch && mstate->reply_list &&
|
|
|
|
|
modstack_find(&mesh->mods, "subnetcache") != -1 &&
|
|
|
|
|
mstate->s.env->unique_mesh) {
|
2023-07-07 10:27:49 -04:00
|
|
|
addr = mstate->reply_list->query_reply.client_addr;
|
2023-07-06 15:57:27 -04:00
|
|
|
} else
|
|
|
|
|
#endif
|
|
|
|
|
memset(&addr, 0, sizeof(addr));
|
2017-09-19 05:08:29 -04:00
|
|
|
|
2007-08-02 05:58:24 -04:00
|
|
|
mesh_query_done(mstate);
|
2007-08-02 08:22:29 -04:00
|
|
|
mesh_walk_supers(mesh, mstate);
|
2017-09-19 05:08:29 -04:00
|
|
|
|
|
|
|
|
/* If the answer to the query needs to be refetched
|
|
|
|
|
* from an external DNS server, we'll need to schedule
|
|
|
|
|
* a prefetch after removing the current state, so
|
|
|
|
|
* we need to make a copy of the query info here. */
|
2022-02-15 10:20:12 -05:00
|
|
|
if(mstate->s.need_refetch) {
|
2017-09-19 05:08:29 -04:00
|
|
|
mesh_copy_qinfo(mstate, &qinfo, &qflags);
|
2023-07-06 15:57:27 -04:00
|
|
|
#ifdef CLIENT_SUBNET
|
|
|
|
|
/* Make also a copy of the ecs option if any */
|
|
|
|
|
if((ecs = edns_opt_list_find(
|
|
|
|
|
mstate->s.edns_opts_front_in,
|
|
|
|
|
mstate->s.env->cfg->client_subnet_opcode)) != NULL) {
|
|
|
|
|
(void)edns_opt_list_append(&opt_list,
|
|
|
|
|
ecs->opt_code, ecs->opt_len,
|
|
|
|
|
ecs->opt_data,
|
|
|
|
|
mstate->s.env->scratch);
|
|
|
|
|
}
|
|
|
|
|
#endif
|
2022-02-15 10:20:12 -05:00
|
|
|
rpz_p = mstate->s.rpz_passthru;
|
|
|
|
|
}
|
2017-09-19 05:08:29 -04:00
|
|
|
|
|
|
|
|
if(qinfo) {
|
2022-04-15 15:26:16 -04:00
|
|
|
mesh_state_delete(&mstate->s);
|
2023-07-06 15:57:27 -04:00
|
|
|
mesh_new_prefetch(mesh, qinfo, qflags, 0,
|
|
|
|
|
rpz_p,
|
|
|
|
|
addr.ss_family!=AF_UNSPEC?&addr:NULL,
|
|
|
|
|
opt_list);
|
2022-04-15 15:26:16 -04:00
|
|
|
} else {
|
|
|
|
|
mesh_state_delete(&mstate->s);
|
2017-09-19 05:08:29 -04:00
|
|
|
}
|
2007-08-02 05:58:24 -04:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
/* pass along the locus of control */
|
|
|
|
|
mstate->s.curmod --;
|
2007-08-02 08:13:08 -04:00
|
|
|
*ev = module_event_moddone;
|
2007-08-02 05:58:24 -04:00
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2007-06-25 09:54:03 -04:00
|
|
|
void mesh_run(struct mesh_area* mesh, struct mesh_state* mstate,
|
|
|
|
|
enum module_ev ev, struct outbound_entry* e)
|
|
|
|
|
{
|
|
|
|
|
enum module_ext_state s;
|
|
|
|
|
verbose(VERB_ALGO, "mesh_run: start");
|
|
|
|
|
while(mstate) {
|
|
|
|
|
/* run the module */
|
2008-02-20 02:18:42 -05:00
|
|
|
fptr_ok(fptr_whitelist_mod_operate(
|
2007-12-04 08:23:41 -05:00
|
|
|
mesh->mods.mod[mstate->s.curmod]->operate));
|
|
|
|
|
(*mesh->mods.mod[mstate->s.curmod]->operate)
|
2007-06-25 09:54:03 -04:00
|
|
|
(&mstate->s, ev, mstate->s.curmod, e);
|
|
|
|
|
|
|
|
|
|
/* examine results */
|
|
|
|
|
mstate->s.reply = NULL;
|
2007-10-18 16:31:43 -04:00
|
|
|
regional_free_all(mstate->s.env->scratch);
|
2007-06-25 09:54:03 -04:00
|
|
|
s = mstate->s.ext_state[mstate->s.curmod];
|
2023-04-20 11:39:55 -04:00
|
|
|
verbose(VERB_ALGO, "mesh_run: %s module exit state is %s",
|
2007-12-04 08:23:41 -05:00
|
|
|
mesh->mods.mod[mstate->s.curmod]->name, strextstate(s));
|
2007-08-02 05:58:24 -04:00
|
|
|
e = NULL;
|
|
|
|
|
if(mesh_continue(mesh, mstate, s, &ev))
|
|
|
|
|
continue;
|
2007-06-25 09:54:03 -04:00
|
|
|
|
|
|
|
|
/* run more modules */
|
|
|
|
|
ev = module_event_pass;
|
|
|
|
|
if(mesh->run.count > 0) {
|
|
|
|
|
/* pop random element off the runnable tree */
|
|
|
|
|
mstate = (struct mesh_state*)mesh->run.root->key;
|
|
|
|
|
(void)rbtree_delete(&mesh->run, mstate);
|
|
|
|
|
} else mstate = NULL;
|
|
|
|
|
}
|
2007-08-13 08:23:49 -04:00
|
|
|
if(verbosity >= VERB_ALGO) {
|
2007-06-27 10:59:44 -04:00
|
|
|
mesh_stats(mesh, "mesh_run: end");
|
2007-08-13 08:23:49 -04:00
|
|
|
mesh_log_list(mesh);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-20 11:39:55 -04:00
|
|
|
void
|
2007-08-13 08:23:49 -04:00
|
|
|
mesh_log_list(struct mesh_area* mesh)
|
|
|
|
|
{
|
|
|
|
|
char buf[30];
|
|
|
|
|
struct mesh_state* m;
|
|
|
|
|
int num = 0;
|
|
|
|
|
RBTREE_FOR(m, struct mesh_state*, &mesh->all) {
|
2023-04-20 11:39:55 -04:00
|
|
|
snprintf(buf, sizeof(buf), "%d%s%s%s%s%s%s mod%d %s%s",
|
2007-08-13 08:23:49 -04:00
|
|
|
num++, (m->s.is_priming)?"p":"", /* prime */
|
2014-11-18 10:15:57 -05:00
|
|
|
(m->s.is_valrec)?"v":"", /* prime */
|
2007-08-13 08:23:49 -04:00
|
|
|
(m->s.query_flags&BIT_RD)?"RD":"",
|
|
|
|
|
(m->s.query_flags&BIT_CD)?"CD":"",
|
|
|
|
|
(m->super_set.count==0)?"d":"", /* detached */
|
|
|
|
|
(m->sub_set.count!=0)?"c":"", /* children */
|
2007-12-06 10:11:07 -05:00
|
|
|
m->s.curmod, (m->reply_list)?"rep":"", /*hasreply*/
|
|
|
|
|
(m->cb_list)?"cb":"" /* callbacks */
|
2023-04-20 11:39:55 -04:00
|
|
|
);
|
2007-08-13 08:23:49 -04:00
|
|
|
log_query_info(VERB_ALGO, buf, &m->s.qinfo);
|
|
|
|
|
}
|
2007-06-26 11:24:07 -04:00
|
|
|
}
|
|
|
|
|
|
2023-04-20 11:39:55 -04:00
|
|
|
void
|
2007-06-26 11:24:07 -04:00
|
|
|
mesh_stats(struct mesh_area* mesh, const char* str)
|
|
|
|
|
{
|
2008-02-11 04:19:32 -05:00
|
|
|
verbose(VERB_DETAIL, "%s %u recursion states (%u with reply, "
|
|
|
|
|
"%u detached), %u waiting replies, %u recursion replies "
|
2023-04-20 11:39:55 -04:00
|
|
|
"sent, %d replies dropped, %d states jostled out",
|
|
|
|
|
str, (unsigned)mesh->all.count,
|
2007-06-26 09:06:44 -04:00
|
|
|
(unsigned)mesh->num_reply_states,
|
|
|
|
|
(unsigned)mesh->num_detached_states,
|
2008-02-11 04:19:32 -05:00
|
|
|
(unsigned)mesh->num_reply_addrs,
|
2008-09-02 09:04:47 -04:00
|
|
|
(unsigned)mesh->replies_sent,
|
|
|
|
|
(unsigned)mesh->stats_dropped,
|
|
|
|
|
(unsigned)mesh->stats_jostled);
|
2007-06-26 11:24:07 -04:00
|
|
|
if(mesh->replies_sent > 0) {
|
2007-06-26 09:06:44 -04:00
|
|
|
struct timeval avg;
|
2023-04-20 11:39:55 -04:00
|
|
|
timeval_divide(&avg, &mesh->replies_sum_wait,
|
2007-06-26 09:06:44 -04:00
|
|
|
mesh->replies_sent);
|
2008-02-11 04:19:32 -05:00
|
|
|
log_info("average recursion processing time "
|
2014-01-16 11:01:37 -05:00
|
|
|
ARG_LL "d.%6.6d sec",
|
|
|
|
|
(long long)avg.tv_sec, (int)avg.tv_usec);
|
2008-02-11 04:19:32 -05:00
|
|
|
log_info("histogram of recursion processing times");
|
|
|
|
|
timehist_log(mesh->histogram, "recursions");
|
2007-06-26 09:06:44 -04:00
|
|
|
}
|
2007-06-25 09:54:03 -04:00
|
|
|
}
|
2007-07-20 11:51:06 -04:00
|
|
|
|
2023-04-20 11:39:55 -04:00
|
|
|
void
|
2008-02-05 05:23:44 -05:00
|
|
|
mesh_stats_clear(struct mesh_area* mesh)
|
|
|
|
|
{
|
|
|
|
|
if(!mesh)
|
|
|
|
|
return;
|
2024-10-29 10:21:52 -04:00
|
|
|
mesh->num_query_authzone_up = 0;
|
|
|
|
|
mesh->num_query_authzone_down = 0;
|
2008-02-05 05:23:44 -05:00
|
|
|
mesh->replies_sent = 0;
|
|
|
|
|
mesh->replies_sum_wait.tv_sec = 0;
|
|
|
|
|
mesh->replies_sum_wait.tv_usec = 0;
|
2008-09-02 09:04:47 -04:00
|
|
|
mesh->stats_jostled = 0;
|
|
|
|
|
mesh->stats_dropped = 0;
|
2008-02-05 05:23:44 -05:00
|
|
|
timehist_clear(mesh->histogram);
|
2008-09-16 10:08:38 -04:00
|
|
|
mesh->ans_secure = 0;
|
|
|
|
|
mesh->ans_bogus = 0;
|
2025-07-12 10:29:38 -04:00
|
|
|
mesh->val_ops = 0;
|
2020-02-05 08:20:27 -05:00
|
|
|
mesh->ans_expired = 0;
|
2023-05-30 11:49:50 -04:00
|
|
|
mesh->ans_cachedb = 0;
|
2019-12-23 10:02:43 -05:00
|
|
|
memset(&mesh->ans_rcode[0], 0, sizeof(size_t)*UB_STATS_RCODE_NUM);
|
|
|
|
|
memset(&mesh->rpz_action[0], 0, sizeof(size_t)*UB_STATS_RPZ_ACTION_NUM);
|
2008-09-16 10:08:38 -04:00
|
|
|
mesh->ans_nodata = 0;
|
2024-11-01 10:52:58 -04:00
|
|
|
mesh->num_queries_discard_timeout = 0;
|
|
|
|
|
mesh->num_queries_wait_limit = 0;
|
2025-04-07 04:25:10 -04:00
|
|
|
mesh->num_dns_error_reports = 0;
|
2008-02-05 05:23:44 -05:00
|
|
|
}
|
|
|
|
|
|
2023-04-20 11:39:55 -04:00
|
|
|
size_t
|
2007-07-20 11:51:06 -04:00
|
|
|
mesh_get_mem(struct mesh_area* mesh)
|
|
|
|
|
{
|
|
|
|
|
struct mesh_state* m;
|
|
|
|
|
size_t s = sizeof(*mesh) + sizeof(struct timehist) +
|
2011-10-24 09:49:59 -04:00
|
|
|
sizeof(struct th_buck)*mesh->histogram->num +
|
2013-12-03 04:11:16 -05:00
|
|
|
sizeof(sldns_buffer) + sldns_buffer_capacity(mesh->qbuf_bak);
|
2007-07-20 11:51:06 -04:00
|
|
|
RBTREE_FOR(m, struct mesh_state*, &mesh->all) {
|
|
|
|
|
/* all, including m itself allocated in qstate region */
|
2007-10-18 16:31:43 -04:00
|
|
|
s += regional_get_mem(m->s.region);
|
2007-07-20 11:51:06 -04:00
|
|
|
}
|
|
|
|
|
return s;
|
|
|
|
|
}
|
2007-07-26 05:29:21 -04:00
|
|
|
|
2023-04-20 11:39:55 -04:00
|
|
|
int
|
2007-08-01 07:29:12 -04:00
|
|
|
mesh_detect_cycle(struct module_qstate* qstate, struct query_info* qinfo,
|
2014-11-18 10:15:57 -05:00
|
|
|
uint16_t flags, int prime, int valrec)
|
2007-07-26 05:29:21 -04:00
|
|
|
{
|
|
|
|
|
struct mesh_area* mesh = qstate->env->mesh;
|
2016-12-06 08:42:51 -05:00
|
|
|
struct mesh_state* dep_m = NULL;
|
2021-03-04 08:13:44 -05:00
|
|
|
dep_m = mesh_area_find(mesh, NULL, qinfo, flags, prime, valrec);
|
2025-09-24 08:30:24 -04:00
|
|
|
return dep_m?mesh_detect_cycle_found(qstate, dep_m):0;
|
2007-07-26 05:29:21 -04:00
|
|
|
}
|
2008-09-02 09:04:47 -04:00
|
|
|
|
|
|
|
|
void mesh_list_insert(struct mesh_state* m, struct mesh_state** fp,
|
|
|
|
|
struct mesh_state** lp)
|
|
|
|
|
{
|
|
|
|
|
/* insert as last element */
|
|
|
|
|
m->prev = *lp;
|
|
|
|
|
m->next = NULL;
|
|
|
|
|
if(*lp)
|
|
|
|
|
(*lp)->next = m;
|
|
|
|
|
else *fp = m;
|
|
|
|
|
*lp = m;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void mesh_list_remove(struct mesh_state* m, struct mesh_state** fp,
|
|
|
|
|
struct mesh_state** lp)
|
|
|
|
|
{
|
|
|
|
|
if(m->next)
|
|
|
|
|
m->next->prev = m->prev;
|
|
|
|
|
else *lp = m->prev;
|
|
|
|
|
if(m->prev)
|
|
|
|
|
m->prev->next = m->next;
|
|
|
|
|
else *fp = m->next;
|
|
|
|
|
}
|
2019-01-11 09:12:27 -05:00
|
|
|
|
|
|
|
|
void mesh_state_remove_reply(struct mesh_area* mesh, struct mesh_state* m,
|
|
|
|
|
struct comm_point* cp)
|
|
|
|
|
{
|
|
|
|
|
struct mesh_reply* n, *prev = NULL;
|
|
|
|
|
n = m->reply_list;
|
2019-01-15 08:42:22 -05:00
|
|
|
/* when in mesh_cleanup, it sets the reply_list to NULL, so that
|
|
|
|
|
* there is no accounting twice */
|
2019-01-11 09:12:27 -05:00
|
|
|
if(!n) return; /* nothing to remove, also no accounting needed */
|
|
|
|
|
while(n) {
|
|
|
|
|
if(n->query_reply.c == cp) {
|
|
|
|
|
/* unlink it */
|
|
|
|
|
if(prev) prev->next = n->next;
|
|
|
|
|
else m->reply_list = n->next;
|
|
|
|
|
/* delete it, but allocated in m region */
|
2020-02-05 08:20:27 -05:00
|
|
|
log_assert(mesh->num_reply_addrs > 0);
|
2019-01-11 09:12:27 -05:00
|
|
|
mesh->num_reply_addrs--;
|
2024-05-01 04:10:58 -04:00
|
|
|
infra_wait_limit_dec(mesh->env->infra_cache,
|
|
|
|
|
&n->query_reply, mesh->env->cfg);
|
2019-01-11 09:12:27 -05:00
|
|
|
|
|
|
|
|
/* prev = prev; */
|
|
|
|
|
n = n->next;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
prev = n;
|
|
|
|
|
n = n->next;
|
|
|
|
|
}
|
|
|
|
|
/* it was not detached (because it had a reply list), could be now */
|
|
|
|
|
if(!m->reply_list && !m->cb_list
|
|
|
|
|
&& m->super_set.count == 0) {
|
|
|
|
|
mesh->num_detached_states++;
|
|
|
|
|
}
|
|
|
|
|
/* if not replies any more in mstate, it is no longer a reply_state */
|
|
|
|
|
if(!m->reply_list && !m->cb_list) {
|
|
|
|
|
log_assert(mesh->num_reply_states > 0);
|
|
|
|
|
mesh->num_reply_states--;
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-02-05 08:20:27 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
|
apply_respip_action(struct module_qstate* qstate,
|
|
|
|
|
const struct query_info* qinfo, struct respip_client_info* cinfo,
|
|
|
|
|
struct respip_action_info* actinfo, struct reply_info* rep,
|
|
|
|
|
struct ub_packed_rrset_key** alias_rrset,
|
|
|
|
|
struct reply_info** encode_repp, struct auth_zones* az)
|
|
|
|
|
{
|
|
|
|
|
if(qinfo->qtype != LDNS_RR_TYPE_A &&
|
|
|
|
|
qinfo->qtype != LDNS_RR_TYPE_AAAA &&
|
|
|
|
|
qinfo->qtype != LDNS_RR_TYPE_ANY)
|
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
|
|
if(!respip_rewrite_reply(qinfo, cinfo, rep, encode_repp, actinfo,
|
Fast Reload Option (#1042)
* - fast-reload, add unbound-control fast_reload
* - fast-reload, make a thread to service the unbound-control command.
* - fast-reload, communication sockets for information transfer.
* - fast-reload, fix compile for unbound-dnstap-socket.
* - fast-reload, set nonblocking communication to keep the server thread
responding to DNS requests.
* - fast-reload, poll routine to test for readiness, timeout fails connection.
* - fast-reload, detect loop in sock_poll_timeout routine.
* - fast-reload, send done and exited notification.
* - fast-reload, defines for constants in ipc.
* - fast-reload, ipc socket recv and send resists partial reads and writes and
can continue byte by byte. Also it can continue after an interrupt.
* - fast-reload, send exit command to thread when done.
* - fast-reload, output strings for client on string list.
* - fast-reload, add newline to terminal output.
* - fast-reload, send client string to remote client.
* - fast-reload, better debug output.
* - fast-reload, print queue structure, for output to the remote client.
* - fast-reload, move print items to print queue from fast_reload_thread struct.
* - fast-reload, keep list of pending print queue items in daemon struct.
* - fast-reload, comment explains in_list for printq to print remainder.
* - fast-reload, unit test testdata/fast_reload_thread.tdir that tests the
thread output.
* - fast-reload, fix test link for fast_reload_printq_list_delete function.
* - fast-reload, reread config file from disk.
* - fast-reload, unshare forwards, making the structure locked, with an rwlock.
* - fast-reload, for nonthreaded, the unbound-control commands forward,
forward_add and forward_delete should be distributed to other processes,
but when threaded, they should not be distributed to other threads because
the structure is not thread specific any more.
* - fast-reload, unshared stub hints, making the structure locked, with an rwlock.
* - fast-reload, helpful comments for hints lookup function return value.
* - fast-reload, fix bug in fast reload printout, the strlist appendlist routine,
and printout time statistics after the reload is done.
* - fast-reload, keep track of reloadtime and deletestime and print them.
* - fast-reload, keep track of constructtime and print it.
* - fast-reload, construct new items.
* - fast-reload, better comment.
* - fast-reload, reload the config and swap trees for forwards and stub hints.
* - fast-reload, in forwards_swap_tree set protection of trees with locks.
* - fast-reload, in hints_swap_tree also swap the node count of the trees.
* - fast-reload, reload ipc to stop and start threads.
* - fast-reload, unused forward declarations removed.
* - fast-reload, unit test that fast reload works with forwards and stubs.
* - fast-reload, fix clang analyzer warnings.
* - fast-reload, small documentation entry in unbound-control -h output.
* - fast-reload, printout memory use by fast reload, in bytes.
* - fast-reload, compile without threads.
* - fast-reload, document fast_reload in man page.
* - fast-reload, print ok when done successfully.
* - fast-reload, option for fast-reload commandline, +v verbosity option,
with timing and memory use output.
* - fast-reload, option for fast-reload commandline, +p does not pause threads.
* - fast-reload, option for fast-reload commandline, +d drops mesh queries.
* - fast-reload, fix to poll every thread with nopause to make certain that
resources are not held by the threads and can be deleted.
* - fast-reload, fix to use atomic store for config variables with nopause.
* - fast-reload, reload views.
* - fast-reload, when tag defines are different, it drops the queries.
* - fast-reload, fix tag define check.
* - fast-reload, document that tag change causes drop of queries.
* - fast-reload, fix space in documentation man page.
* - fast-reload, copy respip client information to query state, put views tree
in module env for lookup.
* - fast-reload, nicer respip view comparison.
* - fast-reload, respip global set is in module env.
* - fast-reload, document that respip_client_info acl info is copied.
* - fast-reload, reload the respip_set.
* - fast-reload, document no pause and pick up of use_response_ip boolean.
* - fast-reload, fix test compile.
* - fast-reload, reload local zones.
* Update locking management for iter_fwd and iter_hints methods. (#1054)
fast reload, move most of the locking management to iter_fwd and
iter_hints methods. The caller still has the ability to handle its
own locking, if desired, for atomic operations on sets of different
structs.
Co-authored-by: Wouter Wijngaards <wcawijngaards@users.noreply.github.com>
* - fast-reload, reload access-control.
* - fast-reload, reload access control interface, such as interface-action.
* - fast-reload, reload tcp-connection-limit.
* - fast-reload, improve comments on acl_list and tcl_list swap tree.
* - fast-reload, fixup references to old tcp connection limits in open tcp
connections.
* - fast-reload, fixup to clean tcp connection also for different linked order.
* - fast-reload, if no tcp connection limits existed, no need to remove
references for that.
* - fast-reload, document more options that work and do not work.
* - fast-reload, reload auth_zone and rpz data.
* - fast-reload, fix auth_zones_get_mem.
* - fast-reload, fix compilation of testbound for the new comm_timer_get_mem
reference in remote control.
* - fast-reload, change use_rpz with reload.
* - fast-reload, list changes in auth zones and stop zonemd callbacks for
deleted auth zones.
* - fast-reload, note xtree is not swapped, and why it is not swapped.
* - fast-reload, for added auth zones, pick up zone transfer and zonemd tasks.
* - fast-reload, unlock xfr when done with transfer pick up.
* - fast-reload, unlock z when picking up the xfr for it during transfer task
pick up.
* - fast-reload, pick up task changes for added, deleted and modified auth zones.
* - fast-reload, remove xfr of auth zone deletion without tasks.
* - fast-reload, pick up zone transfer config.
* - fast-reload, the main worker thread picks up the transfer tasks and also
performs setup of the xfer struct.
* - fast-reload, keep writelock on newzone when auth zone changes.
* - fast-reload, change cachedb_enabled setting.
* - fast-reload, pick up edns-strings config.
* - fast-reload, note that settings are not updated.
* - fast-reload, pick up dnstap config.
* - fast-reload, dnstap options that need to be loaded without +p.
* - fast-reload, fix auth zone reload
* - fast-reload, remove debug for auth zone test.
* - fast-reload, fix auth zone reload with zone transfer.
* - fast-reload, fix auth zone reload lock order.
* - fast-reload, remove debug from fast reload test.
* - fast-reload, remove unused function.
* - fast-reload, fix the worker trust anchor probe timer lock acquisition in
the probe answer callback routine for trust anchor probes.
* - fast-reload, reload trust anchors.
* - fast-reload, fix trust anchor reload lock on autr global data and test
for trust anchor reload.
* - fast-reload, adjust cache sizes.
* - fast-reload, reload cache sizes when changed.
* - fast-reload, reload validator env changes.
* - fast-reload, reload mesh changes.
* - fast-reload, check for incompatible changes.
* - fast-reload, improve error text for incompatible change.
* - fast-reload, fix check config option compatibility.
* - fast-reload, improve error text for nopause change.
* - fast-reload, fix spelling of incompatible options.
* - fast-reload, reload target-fetch-policy, outbound-msg-retry, max-sent-count
and max-query-restarts.
* - fast-reload, check nopause config change for target-fetch-policy.
* - fast-reload, reload do-not-query-address, private-address and capt-exempt.
* - fast-reload, check nopause config change for do-not-query-address,
private-address and capt-exempt.
* - fast-reload, check fast reload not possible due to interface and
outgoing-interface changes.
* - fast-reload, reload nat64 settings.
* - fast-reload, reload settings stored in the infra structure.
* - fast-reload, fix modstack lookup and remove outgoing-range check.
* - fast-reload, more explanation for config parse failure.
* - fast-reload, reload worker outside network changes.
* - fast-reload, detect incompatible changes in network settings.
* fast-reload, commit test files.
* - fast-reload, fix warnings for call types in windows compile.
* - fast-reload, fix warnings and comm_point_internal for tcp wouldblock calls.
* - fast-reload, extend lock checks for repeat thread ids.
* - fast-reload, additional test cases, cache change and tag changes.
* - fast-reload, fix documentation for auth_zone_verify_zonemd_with_key.
* - fast-reload, fix copy_cfg type casts and memory leak on config parse failure.
* - fast-reload, fix use of WSAPoll.
* Review comments for the fast reload feature (#1259)
* - fast-reload review, respip set can be null from a view.
* - fast-reload review, typos.
* - fast-reload review, keep clang static analyzer happy.
* - fast-reload review, don't forget to copy tag_actions.
* - fast-reload review, less indentation.
* - fast-reload review, don't leak respip_actions when reloading.
* - fast-reload review, protect NULL pointer dereference in get_mem
functions.
* - fast-reload review, add fast_reload_most_options.tdir to test most
options with high verbosity when fast reloading.
* - fast-reload review, don't skip new line on long error printouts.
* - fast-reload review, typo.
* - fast-reload review, use new_z for consistency.
* - fast-reload review, nit for unlock ordering to make eye comparison
with the lock counterpart easier.
* - fast-reload review, in case of error the sockets are already closed.
* - fast-reload review, identation.
* - fast-reload review, add static keywords.
* - fast-reload review, update unbound-control usage text.
* - fast-reload review, updates to the man page.
* - fast-reload, the fast-reload command is experimental.
* - fast-reload, fix compile of doqclient for fast reload functions.
* Changelog comment for #1042
- Merge #1042: Fast Reload. The unbound-control fast_reload is added.
It reads changed config in a thread, then only briefly pauses the
service threads, that keep running. DNS service is only interrupted
briefly, less than a second.
---------
Co-authored-by: Yorgos Thessalonikefs <yorgos@nlnetlabs.nl>
2025-03-31 09:25:24 -04:00
|
|
|
alias_rrset, 0, qstate->region, az, NULL, qstate->env->views,
|
|
|
|
|
qstate->env->respip_set))
|
2020-02-05 08:20:27 -05:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
/* xxx_deny actions mean dropping the reply, unless the original reply
|
|
|
|
|
* was redirected to response-ip data. */
|
|
|
|
|
if((actinfo->action == respip_deny ||
|
|
|
|
|
actinfo->action == respip_inform_deny) &&
|
|
|
|
|
*encode_repp == rep)
|
|
|
|
|
*encode_repp = NULL;
|
|
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
mesh_serve_expired_callback(void* arg)
|
|
|
|
|
{
|
|
|
|
|
struct mesh_state* mstate = (struct mesh_state*) arg;
|
|
|
|
|
struct module_qstate* qstate = &mstate->s;
|
2020-10-14 04:06:28 -04:00
|
|
|
struct mesh_reply* r;
|
2020-02-05 08:20:27 -05:00
|
|
|
struct mesh_area* mesh = qstate->env->mesh;
|
|
|
|
|
struct dns_msg* msg;
|
|
|
|
|
struct mesh_cb* c;
|
|
|
|
|
struct mesh_reply* prev = NULL;
|
|
|
|
|
struct sldns_buffer* prev_buffer = NULL;
|
|
|
|
|
struct sldns_buffer* r_buffer = NULL;
|
|
|
|
|
struct reply_info* partial_rep = NULL;
|
|
|
|
|
struct ub_packed_rrset_key* alias_rrset = NULL;
|
|
|
|
|
struct reply_info* encode_rep = NULL;
|
|
|
|
|
struct respip_action_info actinfo;
|
|
|
|
|
struct query_info* lookup_qinfo = &qstate->qinfo;
|
|
|
|
|
struct query_info qinfo_tmp;
|
2021-01-01 17:29:32 -05:00
|
|
|
struct timeval tv = {0, 0};
|
2020-02-05 08:20:27 -05:00
|
|
|
int must_validate = (!(qstate->query_flags&BIT_CD)
|
|
|
|
|
|| qstate->env->cfg->ignore_cd) && qstate->env->need_to_validate;
|
2024-12-03 08:10:17 -05:00
|
|
|
int i = 0, for_count;
|
2024-09-24 10:47:04 -04:00
|
|
|
int is_expired;
|
2020-02-05 08:20:27 -05:00
|
|
|
if(!qstate->serve_expired_data) return;
|
|
|
|
|
verbose(VERB_ALGO, "Serve expired: Trying to reply with expired data");
|
|
|
|
|
comm_timer_delete(qstate->serve_expired_data->timer);
|
|
|
|
|
qstate->serve_expired_data->timer = NULL;
|
2021-01-26 09:31:50 -05:00
|
|
|
/* If is_drop or no_cache_lookup (modules that handle their own cache e.g.,
|
|
|
|
|
* subnetmod) ignore stale data from the main cache. */
|
|
|
|
|
if(qstate->no_cache_lookup || qstate->is_drop) {
|
2020-02-05 08:20:27 -05:00
|
|
|
verbose(VERB_ALGO,
|
|
|
|
|
"Serve expired: Not allowed to look into cache for stale");
|
|
|
|
|
return;
|
|
|
|
|
}
|
2024-12-03 08:10:17 -05:00
|
|
|
/* The following for is used instead of the `goto lookup_cache`
|
|
|
|
|
* like in the worker. This loop should get max 2 passes if we need to
|
|
|
|
|
* do any aliasing. */
|
|
|
|
|
for(for_count = 0; for_count < 2; for_count++) {
|
2020-02-05 08:20:27 -05:00
|
|
|
fptr_ok(fptr_whitelist_serve_expired_lookup(
|
|
|
|
|
qstate->serve_expired_data->get_cached_answer));
|
2021-07-16 11:55:10 -04:00
|
|
|
msg = (*qstate->serve_expired_data->get_cached_answer)(qstate,
|
2024-09-24 10:47:04 -04:00
|
|
|
lookup_qinfo, &is_expired);
|
2024-12-02 06:28:11 -05:00
|
|
|
if(!msg || (FLAGS_GET_RCODE(msg->rep->flags) != LDNS_RCODE_NOERROR
|
|
|
|
|
&& FLAGS_GET_RCODE(msg->rep->flags) != LDNS_RCODE_NXDOMAIN
|
|
|
|
|
&& FLAGS_GET_RCODE(msg->rep->flags) != LDNS_RCODE_YXDOMAIN)) {
|
|
|
|
|
/* We don't care for cached failure answers at this
|
|
|
|
|
* stage. */
|
2020-02-05 08:20:27 -05:00
|
|
|
return;
|
2024-12-02 06:28:11 -05:00
|
|
|
}
|
2020-02-05 08:20:27 -05:00
|
|
|
/* Reset these in case we pass a second time from here. */
|
|
|
|
|
encode_rep = msg->rep;
|
|
|
|
|
memset(&actinfo, 0, sizeof(actinfo));
|
|
|
|
|
actinfo.action = respip_none;
|
|
|
|
|
alias_rrset = NULL;
|
|
|
|
|
if((mesh->use_response_ip || mesh->use_rpz) &&
|
|
|
|
|
!partial_rep && !apply_respip_action(qstate, &qstate->qinfo,
|
|
|
|
|
qstate->client_info, &actinfo, msg->rep, &alias_rrset, &encode_rep,
|
|
|
|
|
qstate->env->auth_zones)) {
|
|
|
|
|
return;
|
|
|
|
|
} else if(partial_rep &&
|
|
|
|
|
!respip_merge_cname(partial_rep, &qstate->qinfo, msg->rep,
|
|
|
|
|
qstate->client_info, must_validate, &encode_rep, qstate->region,
|
Fast Reload Option (#1042)
* - fast-reload, add unbound-control fast_reload
* - fast-reload, make a thread to service the unbound-control command.
* - fast-reload, communication sockets for information transfer.
* - fast-reload, fix compile for unbound-dnstap-socket.
* - fast-reload, set nonblocking communication to keep the server thread
responding to DNS requests.
* - fast-reload, poll routine to test for readiness, timeout fails connection.
* - fast-reload, detect loop in sock_poll_timeout routine.
* - fast-reload, send done and exited notification.
* - fast-reload, defines for constants in ipc.
* - fast-reload, ipc socket recv and send resists partial reads and writes and
can continue byte by byte. Also it can continue after an interrupt.
* - fast-reload, send exit command to thread when done.
* - fast-reload, output strings for client on string list.
* - fast-reload, add newline to terminal output.
* - fast-reload, send client string to remote client.
* - fast-reload, better debug output.
* - fast-reload, print queue structure, for output to the remote client.
* - fast-reload, move print items to print queue from fast_reload_thread struct.
* - fast-reload, keep list of pending print queue items in daemon struct.
* - fast-reload, comment explains in_list for printq to print remainder.
* - fast-reload, unit test testdata/fast_reload_thread.tdir that tests the
thread output.
* - fast-reload, fix test link for fast_reload_printq_list_delete function.
* - fast-reload, reread config file from disk.
* - fast-reload, unshare forwards, making the structure locked, with an rwlock.
* - fast-reload, for nonthreaded, the unbound-control commands forward,
forward_add and forward_delete should be distributed to other processes,
but when threaded, they should not be distributed to other threads because
the structure is not thread specific any more.
* - fast-reload, unshared stub hints, making the structure locked, with an rwlock.
* - fast-reload, helpful comments for hints lookup function return value.
* - fast-reload, fix bug in fast reload printout, the strlist appendlist routine,
and printout time statistics after the reload is done.
* - fast-reload, keep track of reloadtime and deletestime and print them.
* - fast-reload, keep track of constructtime and print it.
* - fast-reload, construct new items.
* - fast-reload, better comment.
* - fast-reload, reload the config and swap trees for forwards and stub hints.
* - fast-reload, in forwards_swap_tree set protection of trees with locks.
* - fast-reload, in hints_swap_tree also swap the node count of the trees.
* - fast-reload, reload ipc to stop and start threads.
* - fast-reload, unused forward declarations removed.
* - fast-reload, unit test that fast reload works with forwards and stubs.
* - fast-reload, fix clang analyzer warnings.
* - fast-reload, small documentation entry in unbound-control -h output.
* - fast-reload, printout memory use by fast reload, in bytes.
* - fast-reload, compile without threads.
* - fast-reload, document fast_reload in man page.
* - fast-reload, print ok when done successfully.
* - fast-reload, option for fast-reload commandline, +v verbosity option,
with timing and memory use output.
* - fast-reload, option for fast-reload commandline, +p does not pause threads.
* - fast-reload, option for fast-reload commandline, +d drops mesh queries.
* - fast-reload, fix to poll every thread with nopause to make certain that
resources are not held by the threads and can be deleted.
* - fast-reload, fix to use atomic store for config variables with nopause.
* - fast-reload, reload views.
* - fast-reload, when tag defines are different, it drops the queries.
* - fast-reload, fix tag define check.
* - fast-reload, document that tag change causes drop of queries.
* - fast-reload, fix space in documentation man page.
* - fast-reload, copy respip client information to query state, put views tree
in module env for lookup.
* - fast-reload, nicer respip view comparison.
* - fast-reload, respip global set is in module env.
* - fast-reload, document that respip_client_info acl info is copied.
* - fast-reload, reload the respip_set.
* - fast-reload, document no pause and pick up of use_response_ip boolean.
* - fast-reload, fix test compile.
* - fast-reload, reload local zones.
* Update locking management for iter_fwd and iter_hints methods. (#1054)
fast reload, move most of the locking management to iter_fwd and
iter_hints methods. The caller still has the ability to handle its
own locking, if desired, for atomic operations on sets of different
structs.
Co-authored-by: Wouter Wijngaards <wcawijngaards@users.noreply.github.com>
* - fast-reload, reload access-control.
* - fast-reload, reload access control interface, such as interface-action.
* - fast-reload, reload tcp-connection-limit.
* - fast-reload, improve comments on acl_list and tcl_list swap tree.
* - fast-reload, fixup references to old tcp connection limits in open tcp
connections.
* - fast-reload, fixup to clean tcp connection also for different linked order.
* - fast-reload, if no tcp connection limits existed, no need to remove
references for that.
* - fast-reload, document more options that work and do not work.
* - fast-reload, reload auth_zone and rpz data.
* - fast-reload, fix auth_zones_get_mem.
* - fast-reload, fix compilation of testbound for the new comm_timer_get_mem
reference in remote control.
* - fast-reload, change use_rpz with reload.
* - fast-reload, list changes in auth zones and stop zonemd callbacks for
deleted auth zones.
* - fast-reload, note xtree is not swapped, and why it is not swapped.
* - fast-reload, for added auth zones, pick up zone transfer and zonemd tasks.
* - fast-reload, unlock xfr when done with transfer pick up.
* - fast-reload, unlock z when picking up the xfr for it during transfer task
pick up.
* - fast-reload, pick up task changes for added, deleted and modified auth zones.
* - fast-reload, remove xfr of auth zone deletion without tasks.
* - fast-reload, pick up zone transfer config.
* - fast-reload, the main worker thread picks up the transfer tasks and also
performs setup of the xfer struct.
* - fast-reload, keep writelock on newzone when auth zone changes.
* - fast-reload, change cachedb_enabled setting.
* - fast-reload, pick up edns-strings config.
* - fast-reload, note that settings are not updated.
* - fast-reload, pick up dnstap config.
* - fast-reload, dnstap options that need to be loaded without +p.
* - fast-reload, fix auth zone reload
* - fast-reload, remove debug for auth zone test.
* - fast-reload, fix auth zone reload with zone transfer.
* - fast-reload, fix auth zone reload lock order.
* - fast-reload, remove debug from fast reload test.
* - fast-reload, remove unused function.
* - fast-reload, fix the worker trust anchor probe timer lock acquisition in
the probe answer callback routine for trust anchor probes.
* - fast-reload, reload trust anchors.
* - fast-reload, fix trust anchor reload lock on autr global data and test
for trust anchor reload.
* - fast-reload, adjust cache sizes.
* - fast-reload, reload cache sizes when changed.
* - fast-reload, reload validator env changes.
* - fast-reload, reload mesh changes.
* - fast-reload, check for incompatible changes.
* - fast-reload, improve error text for incompatible change.
* - fast-reload, fix check config option compatibility.
* - fast-reload, improve error text for nopause change.
* - fast-reload, fix spelling of incompatible options.
* - fast-reload, reload target-fetch-policy, outbound-msg-retry, max-sent-count
and max-query-restarts.
* - fast-reload, check nopause config change for target-fetch-policy.
* - fast-reload, reload do-not-query-address, private-address and capt-exempt.
* - fast-reload, check nopause config change for do-not-query-address,
private-address and capt-exempt.
* - fast-reload, check fast reload not possible due to interface and
outgoing-interface changes.
* - fast-reload, reload nat64 settings.
* - fast-reload, reload settings stored in the infra structure.
* - fast-reload, fix modstack lookup and remove outgoing-range check.
* - fast-reload, more explanation for config parse failure.
* - fast-reload, reload worker outside network changes.
* - fast-reload, detect incompatible changes in network settings.
* fast-reload, commit test files.
* - fast-reload, fix warnings for call types in windows compile.
* - fast-reload, fix warnings and comm_point_internal for tcp wouldblock calls.
* - fast-reload, extend lock checks for repeat thread ids.
* - fast-reload, additional test cases, cache change and tag changes.
* - fast-reload, fix documentation for auth_zone_verify_zonemd_with_key.
* - fast-reload, fix copy_cfg type casts and memory leak on config parse failure.
* - fast-reload, fix use of WSAPoll.
* Review comments for the fast reload feature (#1259)
* - fast-reload review, respip set can be null from a view.
* - fast-reload review, typos.
* - fast-reload review, keep clang static analyzer happy.
* - fast-reload review, don't forget to copy tag_actions.
* - fast-reload review, less indentation.
* - fast-reload review, don't leak respip_actions when reloading.
* - fast-reload review, protect NULL pointer dereference in get_mem
functions.
* - fast-reload review, add fast_reload_most_options.tdir to test most
options with high verbosity when fast reloading.
* - fast-reload review, don't skip new line on long error printouts.
* - fast-reload review, typo.
* - fast-reload review, use new_z for consistency.
* - fast-reload review, nit for unlock ordering to make eye comparison
with the lock counterpart easier.
* - fast-reload review, in case of error the sockets are already closed.
* - fast-reload review, identation.
* - fast-reload review, add static keywords.
* - fast-reload review, update unbound-control usage text.
* - fast-reload review, updates to the man page.
* - fast-reload, the fast-reload command is experimental.
* - fast-reload, fix compile of doqclient for fast reload functions.
* Changelog comment for #1042
- Merge #1042: Fast Reload. The unbound-control fast_reload is added.
It reads changed config in a thread, then only briefly pauses the
service threads, that keep running. DNS service is only interrupted
briefly, less than a second.
---------
Co-authored-by: Yorgos Thessalonikefs <yorgos@nlnetlabs.nl>
2025-03-31 09:25:24 -04:00
|
|
|
qstate->env->auth_zones, qstate->env->views,
|
|
|
|
|
qstate->env->respip_set)) {
|
2020-02-05 08:20:27 -05:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if(!encode_rep || alias_rrset) {
|
|
|
|
|
if(!encode_rep) {
|
|
|
|
|
/* Needs drop */
|
|
|
|
|
return;
|
|
|
|
|
} else {
|
|
|
|
|
/* A partial CNAME chain is found. */
|
|
|
|
|
partial_rep = encode_rep;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/* We've found a partial reply ending with an
|
|
|
|
|
* alias. Replace the lookup qinfo for the
|
|
|
|
|
* alias target and lookup the cache again to
|
|
|
|
|
* (possibly) complete the reply. As we're
|
|
|
|
|
* passing the "base" reply, there will be no
|
|
|
|
|
* more alias chasing. */
|
|
|
|
|
if(partial_rep) {
|
|
|
|
|
memset(&qinfo_tmp, 0, sizeof(qinfo_tmp));
|
|
|
|
|
get_cname_target(alias_rrset, &qinfo_tmp.qname,
|
|
|
|
|
&qinfo_tmp.qname_len);
|
|
|
|
|
if(!qinfo_tmp.qname) {
|
|
|
|
|
log_err("Serve expired: unexpected: invalid answer alias");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
qinfo_tmp.qtype = qstate->qinfo.qtype;
|
|
|
|
|
qinfo_tmp.qclass = qstate->qinfo.qclass;
|
|
|
|
|
lookup_qinfo = &qinfo_tmp;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(verbosity >= VERB_ALGO)
|
|
|
|
|
log_dns_msg("Serve expired lookup", &qstate->qinfo, msg->rep);
|
|
|
|
|
|
2020-06-30 10:20:09 -04:00
|
|
|
for(r = mstate->reply_list; r; r = r->next) {
|
2024-05-01 04:10:58 -04:00
|
|
|
struct timeval old;
|
|
|
|
|
timeval_subtract(&old, mstate->s.env->now_tv, &r->start_time);
|
|
|
|
|
if(mstate->s.env->cfg->discard_timeout != 0 &&
|
|
|
|
|
((int)old.tv_sec)*1000+((int)old.tv_usec)/1000 >
|
|
|
|
|
mstate->s.env->cfg->discard_timeout) {
|
|
|
|
|
/* Drop the reply, it is too old */
|
|
|
|
|
/* briefly set the reply_list to NULL, so that the
|
|
|
|
|
* tcp req info cleanup routine that calls the mesh
|
|
|
|
|
* to deregister the meshstate for it is not done
|
|
|
|
|
* because the list is NULL and also accounting is not
|
|
|
|
|
* done there, but instead we do that here. */
|
|
|
|
|
struct mesh_reply* reply_list = mstate->reply_list;
|
|
|
|
|
verbose(VERB_ALGO, "drop reply, it is older than discard-timeout");
|
|
|
|
|
infra_wait_limit_dec(mstate->s.env->infra_cache,
|
|
|
|
|
&r->query_reply, mstate->s.env->cfg);
|
|
|
|
|
mstate->reply_list = NULL;
|
2024-07-15 08:51:20 -04:00
|
|
|
if(r->query_reply.c->use_h2)
|
2024-07-16 08:23:10 -04:00
|
|
|
http2_stream_remove_mesh_state(r->h2_stream);
|
2024-05-01 04:10:58 -04:00
|
|
|
comm_point_drop_reply(&r->query_reply);
|
|
|
|
|
mstate->reply_list = reply_list;
|
2024-11-01 10:52:58 -04:00
|
|
|
mstate->s.env->mesh->num_queries_discard_timeout++;
|
2024-05-01 04:10:58 -04:00
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-30 17:34:31 -04:00
|
|
|
i++;
|
2021-01-08 03:53:52 -05:00
|
|
|
tv = r->start_time;
|
2021-01-01 17:29:32 -05:00
|
|
|
|
2020-02-05 08:20:27 -05:00
|
|
|
/* If address info is returned, it means the action should be an
|
|
|
|
|
* 'inform' variant and the information should be logged. */
|
|
|
|
|
if(actinfo.addrinfo) {
|
|
|
|
|
respip_inform_print(&actinfo, r->qname,
|
|
|
|
|
qstate->qinfo.qtype, qstate->qinfo.qclass,
|
2022-10-03 09:29:47 -04:00
|
|
|
r->local_alias, &r->query_reply.client_addr,
|
|
|
|
|
r->query_reply.client_addrlen);
|
2020-02-05 08:20:27 -05:00
|
|
|
}
|
|
|
|
|
|
2022-05-06 06:48:53 -04:00
|
|
|
/* Add EDE Stale Answer (RCF8914). Ignore global ede as this is
|
|
|
|
|
* warning instead of an error */
|
2024-09-24 10:47:04 -04:00
|
|
|
if(r->edns.edns_present &&
|
|
|
|
|
qstate->env->cfg->ede_serve_expired &&
|
|
|
|
|
qstate->env->cfg->ede &&
|
|
|
|
|
is_expired) {
|
2022-05-06 06:48:53 -04:00
|
|
|
edns_opt_list_append_ede(&r->edns.opt_list_out,
|
|
|
|
|
mstate->s.region, LDNS_EDE_STALE_ANSWER, NULL);
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-05 08:20:27 -05:00
|
|
|
r_buffer = r->query_reply.c->buffer;
|
|
|
|
|
if(r->query_reply.c->tcp_req_info)
|
|
|
|
|
r_buffer = r->query_reply.c->tcp_req_info->spool_buffer;
|
|
|
|
|
mesh_send_reply(mstate, LDNS_RCODE_NOERROR, msg->rep,
|
|
|
|
|
r, r_buffer, prev, prev_buffer);
|
|
|
|
|
if(r->query_reply.c->tcp_req_info)
|
|
|
|
|
tcp_req_info_remove_mesh_state(r->query_reply.c->tcp_req_info, mstate);
|
2024-07-16 08:23:10 -04:00
|
|
|
/* mesh_send_reply removed mesh state from http2_stream. */
|
2024-05-01 04:10:58 -04:00
|
|
|
infra_wait_limit_dec(mstate->s.env->infra_cache,
|
|
|
|
|
&r->query_reply, mstate->s.env->cfg);
|
2020-02-05 08:20:27 -05:00
|
|
|
prev = r;
|
|
|
|
|
prev_buffer = r_buffer;
|
|
|
|
|
}
|
2023-05-30 17:34:31 -04:00
|
|
|
/* Account for each reply sent. */
|
|
|
|
|
if(i > 0) {
|
|
|
|
|
mesh->ans_expired += i;
|
|
|
|
|
if(actinfo.addrinfo && qstate->env->cfg->stat_extended &&
|
|
|
|
|
actinfo.rpz_used) {
|
|
|
|
|
if(actinfo.rpz_disabled)
|
|
|
|
|
qstate->env->mesh->rpz_action[RPZ_DISABLED_ACTION] += i;
|
|
|
|
|
if(actinfo.rpz_cname_override)
|
|
|
|
|
qstate->env->mesh->rpz_action[RPZ_CNAME_OVERRIDE_ACTION] += i;
|
|
|
|
|
else
|
|
|
|
|
qstate->env->mesh->rpz_action[
|
|
|
|
|
respip_action_to_rpz_action(actinfo.action)] += i;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Mesh area accounting */
|
2020-06-30 09:48:11 -04:00
|
|
|
if(mstate->reply_list) {
|
|
|
|
|
mstate->reply_list = NULL;
|
2020-06-30 10:35:48 -04:00
|
|
|
if(!mstate->reply_list && !mstate->cb_list) {
|
2020-06-30 09:48:11 -04:00
|
|
|
log_assert(mesh->num_reply_states > 0);
|
|
|
|
|
mesh->num_reply_states--;
|
|
|
|
|
if(mstate->super_set.count == 0) {
|
|
|
|
|
mesh->num_detached_states++;
|
|
|
|
|
}
|
2020-06-30 07:41:26 -04:00
|
|
|
}
|
|
|
|
|
}
|
2023-05-30 17:34:31 -04:00
|
|
|
|
2020-02-05 08:20:27 -05:00
|
|
|
while((c = mstate->cb_list) != NULL) {
|
|
|
|
|
/* take this cb off the list; so that the list can be
|
|
|
|
|
* changed, eg. by adds from the callback routine */
|
|
|
|
|
if(!mstate->reply_list && mstate->cb_list && !c->next) {
|
|
|
|
|
/* was a reply state, not anymore */
|
|
|
|
|
log_assert(qstate->env->mesh->num_reply_states > 0);
|
|
|
|
|
qstate->env->mesh->num_reply_states--;
|
|
|
|
|
}
|
|
|
|
|
mstate->cb_list = c->next;
|
|
|
|
|
if(!mstate->reply_list && !mstate->cb_list &&
|
|
|
|
|
mstate->super_set.count == 0)
|
|
|
|
|
qstate->env->mesh->num_detached_states++;
|
2021-01-08 03:47:46 -05:00
|
|
|
mesh_do_callback(mstate, LDNS_RCODE_NOERROR, msg->rep, c, &tv);
|
2020-02-05 08:20:27 -05:00
|
|
|
}
|
|
|
|
|
}
|
2022-09-21 05:10:38 -04:00
|
|
|
|
2024-04-10 05:21:28 -04:00
|
|
|
void
|
|
|
|
|
mesh_respond_serve_expired(struct mesh_state* mstate)
|
|
|
|
|
{
|
2024-04-10 11:01:57 -04:00
|
|
|
if(!mstate->s.serve_expired_data)
|
|
|
|
|
mesh_serve_expired_init(mstate, -1);
|
2024-04-10 05:21:28 -04:00
|
|
|
mesh_serve_expired_callback(mstate);
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-21 05:10:38 -04:00
|
|
|
int mesh_jostle_exceeded(struct mesh_area* mesh)
|
|
|
|
|
{
|
|
|
|
|
if(mesh->all.count < mesh->max_reply_states)
|
|
|
|
|
return 0;
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
Fast Reload Option (#1042)
* - fast-reload, add unbound-control fast_reload
* - fast-reload, make a thread to service the unbound-control command.
* - fast-reload, communication sockets for information transfer.
* - fast-reload, fix compile for unbound-dnstap-socket.
* - fast-reload, set nonblocking communication to keep the server thread
responding to DNS requests.
* - fast-reload, poll routine to test for readiness, timeout fails connection.
* - fast-reload, detect loop in sock_poll_timeout routine.
* - fast-reload, send done and exited notification.
* - fast-reload, defines for constants in ipc.
* - fast-reload, ipc socket recv and send resists partial reads and writes and
can continue byte by byte. Also it can continue after an interrupt.
* - fast-reload, send exit command to thread when done.
* - fast-reload, output strings for client on string list.
* - fast-reload, add newline to terminal output.
* - fast-reload, send client string to remote client.
* - fast-reload, better debug output.
* - fast-reload, print queue structure, for output to the remote client.
* - fast-reload, move print items to print queue from fast_reload_thread struct.
* - fast-reload, keep list of pending print queue items in daemon struct.
* - fast-reload, comment explains in_list for printq to print remainder.
* - fast-reload, unit test testdata/fast_reload_thread.tdir that tests the
thread output.
* - fast-reload, fix test link for fast_reload_printq_list_delete function.
* - fast-reload, reread config file from disk.
* - fast-reload, unshare forwards, making the structure locked, with an rwlock.
* - fast-reload, for nonthreaded, the unbound-control commands forward,
forward_add and forward_delete should be distributed to other processes,
but when threaded, they should not be distributed to other threads because
the structure is not thread specific any more.
* - fast-reload, unshared stub hints, making the structure locked, with an rwlock.
* - fast-reload, helpful comments for hints lookup function return value.
* - fast-reload, fix bug in fast reload printout, the strlist appendlist routine,
and printout time statistics after the reload is done.
* - fast-reload, keep track of reloadtime and deletestime and print them.
* - fast-reload, keep track of constructtime and print it.
* - fast-reload, construct new items.
* - fast-reload, better comment.
* - fast-reload, reload the config and swap trees for forwards and stub hints.
* - fast-reload, in forwards_swap_tree set protection of trees with locks.
* - fast-reload, in hints_swap_tree also swap the node count of the trees.
* - fast-reload, reload ipc to stop and start threads.
* - fast-reload, unused forward declarations removed.
* - fast-reload, unit test that fast reload works with forwards and stubs.
* - fast-reload, fix clang analyzer warnings.
* - fast-reload, small documentation entry in unbound-control -h output.
* - fast-reload, printout memory use by fast reload, in bytes.
* - fast-reload, compile without threads.
* - fast-reload, document fast_reload in man page.
* - fast-reload, print ok when done successfully.
* - fast-reload, option for fast-reload commandline, +v verbosity option,
with timing and memory use output.
* - fast-reload, option for fast-reload commandline, +p does not pause threads.
* - fast-reload, option for fast-reload commandline, +d drops mesh queries.
* - fast-reload, fix to poll every thread with nopause to make certain that
resources are not held by the threads and can be deleted.
* - fast-reload, fix to use atomic store for config variables with nopause.
* - fast-reload, reload views.
* - fast-reload, when tag defines are different, it drops the queries.
* - fast-reload, fix tag define check.
* - fast-reload, document that tag change causes drop of queries.
* - fast-reload, fix space in documentation man page.
* - fast-reload, copy respip client information to query state, put views tree
in module env for lookup.
* - fast-reload, nicer respip view comparison.
* - fast-reload, respip global set is in module env.
* - fast-reload, document that respip_client_info acl info is copied.
* - fast-reload, reload the respip_set.
* - fast-reload, document no pause and pick up of use_response_ip boolean.
* - fast-reload, fix test compile.
* - fast-reload, reload local zones.
* Update locking management for iter_fwd and iter_hints methods. (#1054)
fast reload, move most of the locking management to iter_fwd and
iter_hints methods. The caller still has the ability to handle its
own locking, if desired, for atomic operations on sets of different
structs.
Co-authored-by: Wouter Wijngaards <wcawijngaards@users.noreply.github.com>
* - fast-reload, reload access-control.
* - fast-reload, reload access control interface, such as interface-action.
* - fast-reload, reload tcp-connection-limit.
* - fast-reload, improve comments on acl_list and tcl_list swap tree.
* - fast-reload, fixup references to old tcp connection limits in open tcp
connections.
* - fast-reload, fixup to clean tcp connection also for different linked order.
* - fast-reload, if no tcp connection limits existed, no need to remove
references for that.
* - fast-reload, document more options that work and do not work.
* - fast-reload, reload auth_zone and rpz data.
* - fast-reload, fix auth_zones_get_mem.
* - fast-reload, fix compilation of testbound for the new comm_timer_get_mem
reference in remote control.
* - fast-reload, change use_rpz with reload.
* - fast-reload, list changes in auth zones and stop zonemd callbacks for
deleted auth zones.
* - fast-reload, note xtree is not swapped, and why it is not swapped.
* - fast-reload, for added auth zones, pick up zone transfer and zonemd tasks.
* - fast-reload, unlock xfr when done with transfer pick up.
* - fast-reload, unlock z when picking up the xfr for it during transfer task
pick up.
* - fast-reload, pick up task changes for added, deleted and modified auth zones.
* - fast-reload, remove xfr of auth zone deletion without tasks.
* - fast-reload, pick up zone transfer config.
* - fast-reload, the main worker thread picks up the transfer tasks and also
performs setup of the xfer struct.
* - fast-reload, keep writelock on newzone when auth zone changes.
* - fast-reload, change cachedb_enabled setting.
* - fast-reload, pick up edns-strings config.
* - fast-reload, note that settings are not updated.
* - fast-reload, pick up dnstap config.
* - fast-reload, dnstap options that need to be loaded without +p.
* - fast-reload, fix auth zone reload
* - fast-reload, remove debug for auth zone test.
* - fast-reload, fix auth zone reload with zone transfer.
* - fast-reload, fix auth zone reload lock order.
* - fast-reload, remove debug from fast reload test.
* - fast-reload, remove unused function.
* - fast-reload, fix the worker trust anchor probe timer lock acquisition in
the probe answer callback routine for trust anchor probes.
* - fast-reload, reload trust anchors.
* - fast-reload, fix trust anchor reload lock on autr global data and test
for trust anchor reload.
* - fast-reload, adjust cache sizes.
* - fast-reload, reload cache sizes when changed.
* - fast-reload, reload validator env changes.
* - fast-reload, reload mesh changes.
* - fast-reload, check for incompatible changes.
* - fast-reload, improve error text for incompatible change.
* - fast-reload, fix check config option compatibility.
* - fast-reload, improve error text for nopause change.
* - fast-reload, fix spelling of incompatible options.
* - fast-reload, reload target-fetch-policy, outbound-msg-retry, max-sent-count
and max-query-restarts.
* - fast-reload, check nopause config change for target-fetch-policy.
* - fast-reload, reload do-not-query-address, private-address and capt-exempt.
* - fast-reload, check nopause config change for do-not-query-address,
private-address and capt-exempt.
* - fast-reload, check fast reload not possible due to interface and
outgoing-interface changes.
* - fast-reload, reload nat64 settings.
* - fast-reload, reload settings stored in the infra structure.
* - fast-reload, fix modstack lookup and remove outgoing-range check.
* - fast-reload, more explanation for config parse failure.
* - fast-reload, reload worker outside network changes.
* - fast-reload, detect incompatible changes in network settings.
* fast-reload, commit test files.
* - fast-reload, fix warnings for call types in windows compile.
* - fast-reload, fix warnings and comm_point_internal for tcp wouldblock calls.
* - fast-reload, extend lock checks for repeat thread ids.
* - fast-reload, additional test cases, cache change and tag changes.
* - fast-reload, fix documentation for auth_zone_verify_zonemd_with_key.
* - fast-reload, fix copy_cfg type casts and memory leak on config parse failure.
* - fast-reload, fix use of WSAPoll.
* Review comments for the fast reload feature (#1259)
* - fast-reload review, respip set can be null from a view.
* - fast-reload review, typos.
* - fast-reload review, keep clang static analyzer happy.
* - fast-reload review, don't forget to copy tag_actions.
* - fast-reload review, less indentation.
* - fast-reload review, don't leak respip_actions when reloading.
* - fast-reload review, protect NULL pointer dereference in get_mem
functions.
* - fast-reload review, add fast_reload_most_options.tdir to test most
options with high verbosity when fast reloading.
* - fast-reload review, don't skip new line on long error printouts.
* - fast-reload review, typo.
* - fast-reload review, use new_z for consistency.
* - fast-reload review, nit for unlock ordering to make eye comparison
with the lock counterpart easier.
* - fast-reload review, in case of error the sockets are already closed.
* - fast-reload review, identation.
* - fast-reload review, add static keywords.
* - fast-reload review, update unbound-control usage text.
* - fast-reload review, updates to the man page.
* - fast-reload, the fast-reload command is experimental.
* - fast-reload, fix compile of doqclient for fast reload functions.
* Changelog comment for #1042
- Merge #1042: Fast Reload. The unbound-control fast_reload is added.
It reads changed config in a thread, then only briefly pauses the
service threads, that keep running. DNS service is only interrupted
briefly, less than a second.
---------
Co-authored-by: Yorgos Thessalonikefs <yorgos@nlnetlabs.nl>
2025-03-31 09:25:24 -04:00
|
|
|
|
|
|
|
|
void mesh_remove_callback(struct mesh_area* mesh, struct query_info* qinfo,
|
|
|
|
|
uint16_t qflags, mesh_cb_func_type cb, void* cb_arg)
|
|
|
|
|
{
|
|
|
|
|
struct mesh_state* s = NULL;
|
|
|
|
|
s = mesh_area_find(mesh, NULL, qinfo, qflags&(BIT_RD|BIT_CD), 0, 0);
|
|
|
|
|
if(!s) return;
|
|
|
|
|
if(!mesh_state_del_cb(s, cb, cb_arg)) return;
|
|
|
|
|
|
|
|
|
|
/* It was in the list and removed. */
|
|
|
|
|
log_assert(mesh->num_reply_addrs > 0);
|
|
|
|
|
mesh->num_reply_addrs--;
|
|
|
|
|
if(!s->reply_list && !s->cb_list) {
|
|
|
|
|
/* was a reply state, not anymore */
|
|
|
|
|
log_assert(mesh->num_reply_states > 0);
|
|
|
|
|
mesh->num_reply_states--;
|
|
|
|
|
}
|
|
|
|
|
if(!s->reply_list && !s->cb_list &&
|
|
|
|
|
s->super_set.count == 0) {
|
|
|
|
|
mesh->num_detached_states++;
|
|
|
|
|
}
|
|
|
|
|
}
|