2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-09-05 00:55:24 +00:00
Commit Graph

15510 Commits

Author SHA1 Message Date
Matthijs Mekking
fe97aa59b9 Replace dns_rbtnode_t with dns_qpdata_t
This for now has almost the same structure contents except for
dns_qpdata_t has 'fn' and 'name' to store the domain name.
2024-03-06 09:57:25 +01:00
Matthijs Mekking
cc3a40dafa Replace dns_rbt_nodecount with dns_qp_memusage
We now count the nodes by getting the memory usage and return the
number of leaves.
2024-03-06 09:57:25 +01:00
Matthijs Mekking
e95dfc0119 Replace dns_rbt_namefromnode with dns_name_copy
The name will be stored inside the node now so we can just copy it.

These are leftovers, most of the namefromnode code has been replaced
already in previous commits.
2024-03-06 09:57:24 +01:00
Matthijs Mekking
6a5de6390f Replace rbtnodechain with qpchain and qpiter
The qp approach pulled apart the chain and iterator into two separate
things. Replace the rbtnodechain with qpchain and qpiter. Most of the
times we are interested in the iterator only, the rbtnodechain was
mainly used as an an iterator to get the previous and next name in the
DNS canonical order.

Since dns_qpiter_prev() and dns_qpiter_next() store the name, origin,
and node in the provided parameters, often there is no need to call
a current() function anymore.

Getting the first or last item from the iterator is done by
re-initializing the iterator and then call dns_qpiter_next() or
dns_qpiter_prev() respectively.

The dbiterator no longer needs to maintain a chain, only an iterator.
2024-03-06 09:57:24 +01:00
Matthijs Mekking
8572435a31 Replace rbt_findnode with qp_lookup
All dns_qp_lookup() calls assume it is okay to find empty data, so
we don't need to do anything special for the DNS_RBTFIND_EMPTYDATA.

You can pass a callback function to dns_rbt_findnode(), something that
qp does not support. Instead, call the function afterwards. This has
the drawback that we do more lookup work if there was a zonecut.

With dns_qp_lookup() we also don't pass any options. In this case,
when DNS_RBTFIND_NOEXACT was set, we adapt the result after the lookup.
2024-03-06 09:57:24 +01:00
Matthijs Mekking
8fcfa36660 Replace rbt_deletenode with qp_deletename
Replace dns_rbt_deletenode calls with dns_qp_deletename. For removing
the name from the nsec tree, we no longer first have to find it: we can
just remove the key (retrieved by name).
2024-03-06 09:57:24 +01:00
Matthijs Mekking
c53b95e134 Replace rbt_addnode with qp_insert
Replace dns_rbt_addnode calls with dns_qp_insert. With QP, it sometimes
makes more sense to first lookup the name and see if there is an
existing node (rather than create new data, insert, find out a node
already exists, and destroy the data again). This is done with
dns_qp_getname(), which is more lightweight than dns_qp_lookup(),
and we are only interested in if there is already a leaf node for this
name or not.
2024-03-06 09:57:24 +01:00
Evan Hunt
bb4464181a switch database defaults from "rbt" to "qp"
replace the string "rbt" throughout BIND with "qp" so that
qpdb databases will be used by default instead of rbtdb.
rbtdb databases can still be used by specifying "database rbt;"
in a zone statement.
2024-03-06 09:57:24 +01:00
Evan Hunt
845f832308 rename dns_rbtdb to dns_qpdb
this commit renames all variables and macros with the string "rbtdb"
or "RBDTB" to "qpdb" or "QPDB".
2024-03-06 09:57:24 +01:00
Matthijs Mekking
2edf73dc05 Begin replacement of rbt with qp in rbtdb
- Copy rbtdb.c, rbt-zonedb.c and rbt-cachedb.c to qp-*.
- Added qpmethods.
- Added a new structure dns_qpdata that will replace dns_rbtnode.
- Replaced normal, nsec, and nsec3 dns_rbt trees with dns_qp tries.
- Replaced dns_rbt_create() calls with dns_qp_create().
- Replaced the dns_rbt_destroy() call with dns_qp_destroy().
- Create a dns_qpdata struct and create/destroy methods.

This commit will not build.
2024-03-06 09:57:24 +01:00
Mark Andrews
5ff55e13e8 Restore the disassociate call to before the fetch
[GL #3709] reordered the dns_rdataset_disassociate call to after
the dns_resolver_createfetch call resulting in qctx->nsrrset still
being associated when dns_resolver_createfetch is called in
resume_dslookup (7e4e125e).  Revert that part of the change and add
comments as to why the multiple dns_rdataset_disassociate calls are
where they are.
2024-03-06 10:08:30 +11:00
Ondřej Surý
e74c7dcf51 Always call the TCP dispatch connected callbacks asynchronously
The TCP dispatch connected callbacks could be called synchronously which
in turn could destroy xfrin before we return from dns_xfrin_create().

Delay the calling the callback called from tcp_dispatch_connect() by
calling it always asynchronously.
2024-03-04 16:34:14 +01:00
Ondřej Surý
98d59bdf62 Pin the xfr to a specific loop
Instead of getting the loop from the zone every time, attach the xfrin
directly to the loop.  This also allows to remove the extra safety tid
checks from the dns_xfrin unit.
2024-03-04 16:34:14 +01:00
Ondřej Surý
d8220ca4ca Make the TTL-based cleaning more aggressive
It was discovered that the TTL-based cleaning could build up
a significant backlog of the rdataset headers during the periods where
the top of the TTL heap isn't expired yet.  Make the TTL-based cleaning
more aggressive by cleaning more headers from the heap when we are
adding new header into the RBTDB.
2024-02-29 12:57:06 +01:00
Ondřej Surý
a9383e4b95 Remove expired rdataset headers from the heap
It was discovered that an expired header could sit on top of the heap
a little longer than desireable.  Remove expired headers (headers with
rdh_ttl set to 0) from the heap completely, so they don't block the next
TTL-based cleaning.
2024-02-29 12:56:36 +01:00
Ondřej Surý
0b32d323e0 Simplify the parent cleaning in the prune_tree() mechanism
Instead of juggling with node locks in a cycle, cleanup the node we are
just pruning and send any the parent that's also subject to the pruning
to the prune tree via normal way (e.g. enqueue pruning on the parent).

This simplifies the code and also spreads the pruning load across more
event loop ticks which is better for lock contention as less things run
in a tight loop.
2024-02-29 11:23:03 +01:00
Ondřej Surý
eed17611d8 Reduce lock contention during RBTDB tree pruning
The log message for commit 24381cc36d
explained:

    In some older BIND 9 branches, the extra queuing overhead eliminated by
    this change could be remotely exploited to cause excessive memory use.
    Due to architectural shift, this branch is not vulnerable to that issue,
    but applying the fix to the latter is nevertheless deemed prudent for
    consistency and to make the code future-proof.

However, it turned out that having a single queue for the nodes to be
pruned increased lock contention to a level where cleaning up nodes from
the RBTDB took too long, causing the amount of memory used by the cache
to grow indefinitely over time.

This commit reverts the change to the pruning mechanism introduced by
commit 24381cc36d as BIND branches newer
than 9.16 were not affected by the excessive event queueing overhead
issue mentioned in the log message for the above commit.
2024-02-29 11:23:03 +01:00
Mark Andrews
0651063658 Add RESINFO record type
This is a TXT clone using code point 261.
2024-02-26 12:02:40 +11:00
Mark Andrews
7ce2e86024 Do not use header_prev in expire_lru_headers
dns__cacherbt_expireheader can unlink / free header_prev underneath
it.  Use ISC_LIST_TAIL after calling dns__cacherbt_expireheader
instead to get the next pointer to be processed.
2024-02-23 12:00:12 +01:00
Artem Boldariev
f8812d4184 Do not lock workers when using -T transferslowly/transferstuck
This commit ensures that worker threads are not sleeping (by using
select()) when '-T transferslowly/transferstuck' test options are
used. This commit converts synchronous implementation of the code into
an asynchronous one based on timers.
2024-02-22 00:09:04 +02:00
Artem Boldariev
4cbe1eb368 DoT: do not crash resolver on TLS context creation failure
The resolver's code was not ready to failures when trying to establish
a connection via TCP-based transports (e.g. when creating TLS contexts
before establishing a TLS connection).

This commit fixes that.
2024-02-21 21:05:21 +02:00
Aram Sargsyan
9e38d0e3af Clean up fetch_answered
After the changes in [GL #4447] the 'fetch_answered' variable is
always false now. Delete the unnecessary code.
2024-02-20 10:46:40 +00:00
Aram Sargsyan
03b68b8c38 Address scan-build warnings
The warnings (see below) seem to be false-positives. Address them
by adding runtime checks.

    resolver.c:1627:10: warning: Access to field 'tid' results in a dereference of a null pointer (loaded from variable 'fctx') [core.NullDereference]
     1627 |         REQUIRE(fctx->tid == isc_tid());
          |                 ^~~~~~~~~
    ../../lib/isc/include/isc/util.h:332:34: note: expanded from macro 'REQUIRE'
      332 | #define REQUIRE(e)   ISC_REQUIRE(e)
          |                                  ^
    ../../lib/isc/include/isc/assertions.h:45:11: note: expanded from macro 'ISC_REQUIRE'
       45 |         ((void)((cond) ||                                                  \
          |                  ^~~~
    resolver.c:10335:6: warning: Access to field 'depth' results in a dereference of a null pointer (loaded from variable 'fctx') [core.NullDereference]
     10335 |         if (fctx->depth > depth) {
           |             ^~~~~~~~~~~
    2 warnings generated.
2024-02-16 08:42:48 +00:00
Aram Sargsyan
bd7463914f Disallow stale-answer-client-timeout non-zero values
Remove all the code and tests which support non-zero
stale-answer-client-timeout values, and adjust the
documentation.
2024-02-16 08:41:52 +00:00
Evan Hunt
e40fd4ed06 fix several bugs in the RBTDB dbiterator implementation
- the DNS_DB_NSEC3ONLY and DNS_DB_NONSEC3 flags are mutually
  exclusive; it never made sense to set both at the same time.
  to enforce this, it is now a fatal error to do so.  the
  dbiterator implementation has been cleaned up to remove
  code that treated the two as independent: if nonsec3 is
  true, we can be certain nsec3only is false, and vice versa.
- previously, iterating a database backwards omitted
  NSEC3 records even if DNS_DB_NONSEC3 had not been set. this
  has been corrected.
- when an iterator reaches the origin node of the NSEC3 tree, we
  need to skip over it and go to the next node in the sequence.
  the NSEC3 origin node is there for housekeeping purposes and
  never contains data.
- the dbiterator_test unit test has been expanded, several
  incorrect expectations have been fixed. (for example, the
  expected number of iterations has been reduced by one; we were
  previously counting the NSEC3 origin node and we should not
  have been doing so.)
2024-02-15 10:15:50 -08:00
Evan Hunt
7d59a0ed81 prevent a possible race in setting up zone->xfr
the call to dns_xfrin_create() wrote to zone->xfr with
the zone unlocked.
2024-02-14 18:53:17 +00:00
Evan Hunt
3e683a9ed5 test for SIGTYPE correctly
a comparison was incorrectly removed during a previous merge.
2024-02-14 09:32:20 -08:00
Michał Kępień
8610799317 Merge tag 'v9.19.21'
BIND 9.19.21
2024-02-14 13:24:56 +01:00
Evan Hunt
ac9bd03a0d clean up dns_rbt
- create_node() in rbt.c cannot fail
- the dns_rbt_*name() functions, which are wrappers around
  dns_rbt_[add|find|delete]node(), were never used except in tests.

this change isn't really necessary since RBT is likely to go away
eventually anyway. but keeping the API as simple as possible while it
persists is a good thing, and may reduce confusion while QPDB is being
developed from RBTDB code.
2024-02-14 01:36:44 -08:00
Evan Hunt
78d173b548 move DNS_RBT_NSEC_* to db.h
these values pertain to whether a node is in the main, nsec, or nsec3
tree of an RBTDB. they need to be moved to a more generic location so
they can also be used by QPDB.

(this is in db.h rather than db_p.h because rbt.c needs access to it.
technically, that's a layer violation, but it's a long-existing one;
refactoring to get rid of it would be a large hassle, and eventually
we expect to remove rbt.c anyway.)
2024-02-14 01:13:44 -08:00
Evan Hunt
27c862d953 separate generic DB helpers into db_p.h
when the QPDB is implemented, we will need to have both qpdb_p.h and
rbtdb_p.h. in order to prevent name collisions or code duplication,
this commit adds a generic private header file, db_p.h, containing
structures and macros that will be used by both databases.

some functions and structs have been renamed to more specifically refer
to the RBT database, in order to avoid namespace collision with similar
things that will be needed by the QPDB later.
2024-02-14 09:00:27 +01:00
Evan Hunt
d1acc987e9 refactor wildcard matching
refactor the wildcard matching code to make it a bit easier to
understand, in hopes that it will reduce the difficulty of converting
from RBTDB to QPDB later.

there are also some minor optimizations: previously, after stepping
backward to find the predecessor, we stepped back foward *from* the
predecessor to find the successor.  we now reset the rbtnode chain to
its original starting point before stepping forward; this eliminates
some unnecessary processing. and, if neither predecessor nor successor
is found, we return early rather than carrying on with an unnecessary
effort to match labels.
2024-02-13 22:14:17 +00:00
Mark Andrews
dc94f42209 Dissassociate rdatasets returned from dns_ncache_current
lib/dns/validator.c:findnsec3proofs failed to disassociate the
temporary rdataset returned by dns_ncache_current on all paths.
2024-02-13 11:42:56 +00:00
Mark Andrews
371defc357 Address CID 486326: Memory - corruptions (OVERRUN)
Coverity detected that address->type.sa was too small when copying
a struct sockaddr_sin6, use the alterative union element
address->type.sin6 instead.
2024-02-13 09:21:49 +11:00
Mark Andrews
dd57db2274 Remove duplicate unreachable code block
This was accidentially left in during the developement of !8299.
2024-02-12 15:18:46 +11:00
Ondřej Surý
175655b771 Fix case insensitive matching in isc_ht hash table implementation
The case insensitive matching in isc_ht was basically completely broken
as only the hashvalue computation was case insensitive, but the key
comparison was always case sensitive.
2024-02-11 09:36:56 +01:00
Aydın Mercan
a911949ebc Convert rwlock in isc_log_t to RCU
The isc_log_t contains a isc_logconfig_t that is swapped, dereferenced
or accessed its fields through a mutex. Instead of protecting it with a
rwlock, use RCU.
2024-02-09 13:11:48 +03:00
Ondřej Surý
315aa3135a Fix UAF in ccmsg.c when reading stopped before sending
When shutting down the whole server, the reading could stop and detach
from controlconnection before sending is done.  If send callback then
detaches from the last controlconnection handle, the ccmsg would be
invalidated after the send callback and thus we must not access ccmsg
after calling the send_cb().
2024-02-08 17:24:11 +01:00
Ondřej Surý
88a14985db Add isc_nm_read_stop() and remove .reading member from ccmsg
We need to stop reading when calling isc_ccmsg_disconnect() as the
reading handle doesn't have to be last because sending might be in
progress.  After that, we can safely remove .reading member because the
reading would not be called after the disconnect has been called.

The ccmsg_senddone() should also not call the recv callback if the
sending failed, that's the job of the caller's send callback - in fact
it already does that, so the code in ccmsg_senddone() was superfluous.
2024-02-08 17:23:39 +01:00
Ondřej Surý
15329d471e Add memory pools for isc_nmsocket_t structures
To reduce memory pressure, we can add light per-loop (netmgr worker)
memory pools for isc_nmsocket_t structures.  This will help in
situations where there's a lot of churn creating and destroying the
nmsockets.
2024-02-08 15:13:47 +01:00
Ondřej Surý
750bd364b5 Reduce the isc_nmsocket_t size from 1840 to 1208 bytes
Embedding isc_nmsocket_h2_t directly inside isc_nmsocket_t had increased
the size of isc_nmsocket_t to 1840 bytes.  Making the isc_nmsocket_h2_t
to be a pointer to the structure and allocated on demand allows us to
reduce the size to 1208 bytes.  While there are still some possible
reductions in the isc_nmsocket_t (embedded tlsstream, streamdns
structures), this was the far biggest drop in the memory usage.
2024-02-08 15:13:47 +01:00
Ondřej Surý
eada7b6e13 Reduce struct isc__nm_uvreq size from 1560 to 560 bytes
The uv_req union member of struct isc__nm_uvreq contained libuv request
types that we don't use.  Turns out that uv_getnameinfo_t is 1000 bytes
big and unnecessarily enlarged the whole structure.  Remove all the
unused members from the uv_req union.
2024-02-08 15:13:47 +01:00
Ondřej Surý
2367b6a2e1 Reduce sizeof isc_sockaddr from 152 to 48 bytes
After removing sockaddr_unix from isc_sockaddr, we can also remove
sockaddr_storage and reduce the isc_sockaddr size from 152 bytes to just
48 bytes needed to hold IPv6 addresses.
2024-02-08 15:13:47 +01:00
Ondřej Surý
2463e5232d Use proper padding instead of using alignas()
As it was pointed out, the alignas() can't be used on objects larger
than `max_align_t` otherwise the compiler might miscompile the code to
use auto-vectorization on unaligned memory.

As we were only using alignas() as a way to prevent false memory
sharing, we can use manual padding in the affected structures.
2024-02-08 10:54:35 +01:00
Ondřej Surý
3f774c2a8a Optimize cname_and_other_data to stop as earliest as possible
Stop the cname_and_other_data processing if we already know that the
result is true.  Also, we know that CNAME will be placed in the priority
headers, so we can stop looking for CNAME if we haven't found CNAME and
we are past the priority headers.
2024-02-08 08:33:36 +01:00
Ondřej Surý
3ac482be7f Optimize the slabheader placement for certain RRTypes
Mark the infrastructure RRTypes as "priority" types and place them at
the beginning of the rdataslab header data graph.  The non-priority
types either go right after the priority types (if any).
2024-02-08 08:33:36 +01:00
Ondřej Surý
5070c7f5c7 Fix missing RRSIG for CNAME with different slabheader order
The cachedb was missing piece of code (already found in zonedb) that
would make lookups in the slabheaders to miss the RRSIGs for CNAME if
the order of CNAME and RRSIG(CNAME) was reversed in the node->data.
2024-02-08 08:02:48 +01:00
Ondřej Surý
0c18ed7ec6 Remove isc__tls_setfatalmode() function and the calls
With _exit() instead of exit() in place, we don't need
isc__tls_setfatalmode() mechanism as the atexit() calls will not be
executed including OpenSSL atexit hooks.
2024-02-08 08:01:58 +01:00
Ondřej Surý
76997983fd Use EXIT_SUCCESS and EXIT_FAILURE
Instead of randomly using -1 or 1 as a failure status, properly utilize
the EXIT_FAILURE define that's platform specific (as it should be).
2024-02-08 08:01:58 +01:00
Ondřej Surý
e140743e6a Improve the rcu_barrier() call when destroying the mem context
Instead of crude 5x rcu_barrier() call in the isc__mem_destroy(), change
the mechanism to call rcu_barrier() until the memory use and references
stops decreasing.  This should deal with any number of nested call_rcu()
levels.

Additionally, don't destroy the contextslock if the list of the contexts
isn't empty.  Destroying the lock could make the late threads crash.
2024-02-08 08:01:58 +01:00