2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-08-30 05:57:52 +00:00

9452 Commits

Author SHA1 Message Date
Evan Hunt
2789e58473 get foundname from the node
when calling dns_qp_lookup() from qpcache, instead of passing
'foundname' so that a name would be constructed from the QP key,
we now just use the name field in the node data. this makes
dns_qp_lookup() run faster.

the same optimization has also been added to qpzone.

the documentation for dns_qp_lookup() has been updated to
discuss this performance consideration.
2024-04-30 12:50:01 -07:00
Evan Hunt
04d319afe4 include the nodenames when calculating memory to purge
when the cache is over memory, we purge from the LRU list until
we've freed the approximate amount of memory to be added. this
approximation could fail because the memory allocated for nodenames
wasn't being counted.

add a dns_name_size() function so we can look up the size of nodenames,
then add that to the purgesize calculation.
2024-04-30 12:50:01 -07:00
Evan Hunt
a8bda6ff1e simplify qpcache iterators
in a cache database, unlike zones, NSEC3 records are stored in
the main tree. it is not necessary to maintain a separate 'nsec3'
tree, nor to have code in the dbiterator implementation to traverse
from one tree to another.

(if we ever implement synth-from-dnssec using NSEC3 records, we'll
need to revert this change. in the meantime, simpler code is better.)
2024-04-30 12:50:01 -07:00
Evan Hunt
7ff43befb7 clean up unnecessary dbiterator code related to origin
the QP database doesn't support relative names as the RBTDB did, so
there's no need for a 'new_origin' flag or to handle `DNS_R_NEWORIGIN`
result codes.
2024-04-30 12:42:32 -07:00
Evan Hunt
85ab92b6e0 more cleanups in qpcache.c
- remove unneeded struct members and misleading comments.
- remove unused parameters for static functions.
- rename 'find_callback' to 'delegating' for consistency with qpzone;
  the find callback mechanism is not used in QP databases.
2024-04-30 12:42:31 -07:00
Evan Hunt
3acab71d46 rename QPDB_HEADERNODE to HEADERNODE
this makes the macro consistent between qpcache.c and qpzone.c.

also removed a redundant definition of HEADERNODE in qpzone.c.
2024-04-30 12:42:31 -07:00
Evan Hunt
46d40b3dca fix structure names in qpcache.c and qpzone.c
- change dns_qpdata_t to qpcnode_t (QP cache node), and dns_qpdb_t to
  qpcache_t, as these types are only accessed locally.
- also change qpdata_t in qpzone.c to qpznode_t (QP zone node), for
  consistency.
- make the refcount declarations for qpcnode_t and qpznode_t static,
  using the new ISC_REFCOUNT_STATIC macros.
2024-04-30 12:42:07 -07:00
Evan Hunt
20d32512ca clean up unnecessary requirements in qpcache.c
qpcache can only support cache semantics now, so there's
no longer any need to check for that internally.
2024-04-30 12:31:48 -07:00
Ondřej Surý
c13a1d8b01
Improve the reference counting checks in newref()
In qpcache (and rbtdb), there are some functions that acquire
neither the tree lock nor the node lock when calling newref().
In theory, this could lead to a race in which a new reference
is added to a node that was about to be deleted.

We now detect this condition by passing the current tree and node
lock status to newref(). If the node was previously unreferenced
and we don't hold at least one read lock, we will assert.
2024-04-30 08:41:56 +02:00
Aydın Mercan
4a3f7fe1ef
Emit and read correct DoT and DoH dnstap entries
Other protocols still pretend to be TCP/UDP.
This only causes a difference when using dnstap-read on a file with DoQ
or DNSCrypt entries
2024-04-26 16:12:29 +03:00
Aydın Mercan
9d1a8a98c6
Update the dnstap protobuf definition
The new definition includes the missing protocol definitions and
specifies the protobuf version.
2024-04-26 16:08:46 +03:00
Ondřej Surý
6c54337f52 avoid a race in the qpzone getsigningtime() implementation
the previous commit introduced a possible race in getsigningtime()
where the rdataset header could change between being found on the
heap and being bound.

getsigningtime() now looks at the first element of the heap, gathers the
locknum, locks the respective lock, and retrieves the header from the
heap again.  If the locknum has changed, it will rinse and repeat.
Theoretically, this could spin forever, but practically, it almost never
will as the heap changes on the zone are very rare.

we simplify matters further by changing the dns_db_getsigningtime()
API call. instead of passing back a bound rdataset, we pass back the
information the caller actually needed: the resigning time, owner name
and type of the rdataset that was first on the heap.
2024-04-25 15:48:43 -07:00
Evan Hunt
7e6be9f1b5 simplify qpzone database by using only one heap for resigning
in RBTDB, the heap was used by zone databases for resigning, and
by the cache for TTL-based cache cleaning. the cache use case required
very frequent updates, so there was a separate heap for each of the
node lock buckets.

qpzone is for zones only, so it doesn't need to support the cache
use case; the heap will only be touched when the zone is updated or
incrementally signed. we can simplify the code by using only a single
heap.
2024-04-25 15:41:39 -07:00
Evan Hunt
237123e500 simplify code by removing return values where possible
fix_iterator() and related functions are quite difficult to read.
perhaps it would be a little clearer if we didn't assign values
to variables that won't subsequently be used, or unnecessarily
pop the stack and then push the same value back onto it.

also, in dns_qp_lookup() we previously called fix_iterator(),
removed the leaf from the top of the iterator stack, and then
added it back on. this would be clearer if we just push the leaf
onto the stack when we need to, but leave the stack alone when
it's already complete.
2024-04-25 10:29:07 -07:00
Evan Hunt
66dbff596b clean up fix_iterator() arguments
the value passed as 'start' was redundant; it's always the same
as the current top of the iterator stack.
2024-04-25 10:29:07 -07:00
Evan Hunt
2dff926624 yet another fix_iterator() bug
under some circumstances it was possible for the iterator to
be set to the first leaf in a set of twigs, when it should have
been set to the last.

a unit test has been added to test this scenario. if there is a
a tree containing the following values: {".", "abb.", "abc."}, and
we query for "acb.", previously the iterator would be positioned at
"abb." instead of "abc.".

the tree structure is:
    branch (offset 1, ".")
      branch (offset 3, ".ab")
        leaf (".abb")
        leaf (".abc")

we find the branch with offset 3 (indicating that its twigs differ
from each other in the third position of the label, "abB" vs "abC").
but the search key differs from the found keys at position 2
("aC" vs "aB").  we look up the bit value in position 3 of the
search key ("B"), and incorrectly follow it onto the wrong twig
("abB").

to correct for this, we need to check for the case where the search
key is greater than the found key in a position earlier than the
branch offset. if it is, then we need to pop from the current leaf
to its parent, and get the greatest leaf from there.

a further change is needed to ensure that we don't do this twice;
when we've moved to a new leaf and the point of difference between
it and the search key even earlier than before, then we're definitely
at a predecessor node and there's no need to continue the loop.
2024-04-25 10:29:07 -07:00
Michal Nowak
f454fa6dea
Update sources to Clang 18 formatting 2024-04-23 13:11:52 +02:00
Ondřej Surý
141e4c9805
Change the ADB_ENTRY_WINDOW to 60 seconds
The previous value of 30 minutes used to cache the ADB names and entries
was quite long.  Change the value to 60 seconds for faster recovery
after cached intermittent failure of the remote nameservers.
2024-04-22 10:36:36 +02:00
Ondřej Surý
6708da3112
Unify the expiration time handling for all ADB expiration
The algorithm from the previous commit[1] is now used to calculate all
the expiration values through the code (ncache results, cname/dname
targets).

1. ISC_MIN(cur, ISC_MAX(now + ADB_ENTRY_WINDOW, now + rdataset->ttl))
2024-04-22 10:36:36 +02:00
Ondřej Surý
53cc00ee3f
Fix the expire_v4 and expire_v6 logic
Correct the logic to set the expiration period of expire_{v4,v6} as
follows:

1. If the trust is ultimate (local entry), immediately set the entry as
   expired, so the changes to the local zones have immediate effect.

3. If the expiration is already set and smaller than the new value, then
   leave the expiration value as it is.

2. Otherwise pick larger of `now + ADB_ENTRY_WINDOW` and `now + TTL` as
   the new expiration value.
2024-04-22 10:36:36 +02:00
Ondřej Surý
932665410d
Always set ADB entry expiration to now + ADB_ENTRY_WINDOW
When ADB entry was created it was set to never expire.  If we never
called any of the functions that adjust the expiration, it could linger
in the ADB forever.

Set the expiration (.expires) to now + ADB_ENTRY_WINDOW when creating
the new ADB entry to ensure the ADB entry will always expire.
2024-04-22 10:36:36 +02:00
Mark Andrews
26375bdcf2 Break out of the switch if we have already reached the quota
This prevents consume_validation_fail being called and causing an
INSIST.
2024-04-22 12:32:36 +10:00
Matthijs Mekking
a3915e535a Move kasp key match function to kasp header
The dnssec-ksr tool needs to check if existing key files match lines
in the keys section of a dnssec-policy, so make this function publicly
available.
2024-04-19 10:41:04 +02:00
Ondřej Surý
3b9ea189b2
Don't count expired / future RRSIG against quota
These don't trigger a public key verification unless
dnssec-accept-expired is set.
2024-04-18 16:05:31 +02:00
Matthijs Mekking
c3d8932f79 Add checkconf check for signatures-jitter
Having a value higher than signatures-validity does not make sense
and should be treated as a configuration error.
2024-04-18 09:50:33 +02:00
Matthijs Mekking
67f403a423 Implement signature jitter
When calculating the RRSIG validity, jitter is now derived from the
config option rather than from the refresh value.
2024-04-18 09:50:10 +02:00
Matthijs Mekking
0438d3655b Refactor code that calculates signature validity
There are three code blocks that are (almost) similar, refactor it
to one function.
2024-04-18 09:50:10 +02:00
Matthijs Mekking
2a4daaedca Add signatures-jitter option
Add an option to speficy signatures jitter.
2024-04-18 09:50:10 +02:00
Mark Andrews
bf70d4840c dns_qpkey_toname failed to reset name correctly
This could lead to a mismatch between name->length and the rest
of the name structure.
2024-04-18 00:17:48 +00:00
Ondřej Surý
eb1829b970
Use atomic operations to access the trust byte in ncache data
Protect the access to the trust byte in the ncache data with relaxed
atomic operation to mimick the current behaviour.  This will teach
TSAN that the concurrent access is fine.
2024-04-17 17:14:34 +02:00
Mark Andrews
4ef755ffb0
Only copy the name data after we know its actual length
This prevents TSAN errors with the ncache code where the trust byte
access needs to be protected by a lock.  The old code copied the
entire region before determining where the name ended.  We now
determine where the name ends then copy just that data and in doing
so avoid reading the trust byte.
2024-04-17 17:14:34 +02:00
Mark Andrews
40fd4cd407 Wrong source address used for IPv6 notify messages
The source address field of 'newnotify' was not updated from the
default (0.0.0.0) when the destination address was an IPv6 address.
This resulted in the messages failing to be sent.  Set the source
address to :: when the destination address is an IPv6 address.
2024-04-11 18:05:25 +00:00
Evan Hunt
2c88946590 dns_name_dupwithoffsets() cannot fail
this function now always returns success; change it to void and
clean up its callers.
2024-04-10 22:51:07 -04:00
Aram Sargsyan
a5ea7bcd25
Rename and fix dns_validator_destroy() to dns_validator_shutdown()
Since the dns_validator_destroy() function doesn't guarantee that
it destroys the validator, rename it to dns_validator_shutdown()
and require explicit dns_validator_detach() to follow.

Enforce the documented function requirement that the validator must
be completed when the function is called.

Make sure to set val->name to NULL when the function is called,
so that the owner of the validator may destroy the name, even if
the validator is not destroyed immediately. This should be safe,
because the name can be used further only for logging by the
offloaded work callbacks when they detect that the validator is
already canceled/complete, and the logging function has a condition
to use the name only when it is non-NULL.
2024-04-02 16:21:54 +02:00
Aram Sargsyan
a6c6ad048d Remove a redundant log message and a comment
If val->result is not ISC_R_SUCCESS, a similar message is logged
further down in the function. Remove the redundant log message.

Also remove an unnecessary code comment line.
2024-04-02 10:34:31 +00:00
Evan Hunt
63659e2e3a
complete removal of isc_loop_current()
isc_loop() can now take its place.

This also requires changes to the test harness - instead of running the
setup and teardown outside of th main loop, we now schedule the setup
and teardown to run on the loop (via isc_loop_setup() and
isc_loop_teardown()) - this is needed because the new the isc_loop()
call has to be run on the active event loop, but previously the
isc_loop_current() (and the variants like isc_loop_main()) would work
even outside of the loop because it needed just isc_tid() to work, but
not the full loop (which was mainly true for the main thread).
2024-04-02 10:35:56 +02:00
Evan Hunt
c47fa689d4
use a thread-local variable to get the current running loop
if we had a method to get the running loop, similar to how
isc_tid() gets the current thread ID, we can simplify loop
and loopmgr initialization.

remove most uses of isc_loop_current() in favor of isc_loop().
in some places where that was the only reason to pass loopmgr,
remove loopmgr from the function parameters.
2024-04-02 10:35:56 +02:00
Evan Hunt
ea6659a5e9
update foundname when detecting a zonecut above qname
an assertion could be triggered in the QPDB cache if a DNAME
was found above a queried NS, because the 'foundname' value was
not correctly updated to point to the zone cut.

the same mistake existed in qpzone and has been fixed there as well.
2024-04-02 10:00:03 +02:00
Matthijs Mekking
77d4bb9751 Fix fix_iterator hang
If there are no more previous leaves, it means the queried name
precedes the entire range of names in the database, so we should just
move the iterator one step back and return, instead of continuing our
search for the predecessor.

This is similar to an earlier bug fixed in an earlier commit:

    ea9a8cb392ff59438a911485742b220d40f24d6f
2024-03-25 10:40:23 +01:00
Mark Andrews
4d2d80f534 Remove remenants of cache support from qpzone.c
These where leading to Coverity errors being reported.
2024-03-19 22:04:10 +00:00
Evan Hunt
17186e06bb reduce memory consumption of the remaining QP databases
use dynamically allocated names instead of fixednames in
forward.c, keytable.c, nametree.c, and nta.c
2024-03-14 10:25:07 -07:00
Evan Hunt
c0fcc2899e reduce memory consumption of rpz summary database
use dynamically allocated names instead of fixednames in rpz.c
2024-03-14 10:20:52 -07:00
Evan Hunt
8b67476249 reduce memory consumption of qpcache database
as with qpzone, use a dynamically-allocated dns_name instead
of a dns_fixedname object to store node names in the QP database.
2024-03-14 10:20:52 -07:00
Evan Hunt
f908d358c4 reduce memory consumption of qpzone database
every node of a QP database contains a copy of the nodename,
which is used as the key for the QP-trie. previously, the name
was stored as a dns_fixedname object, which has room for up to
255 characters. we can reduce the space consumed by dynamically
allocating a dns_name object that's just long enough for the name
to be stored.
2024-03-14 10:20:52 -07:00
Matthijs Mekking
ad33a73f83 Fix Coverity CID 487882: Error handling issues
The dns_qpiter_next() was called without checking the return value. If
we cannot move the iterator forward, there is no use in calling the
step() function.

/lib/dns/qpzone.c: 2804 in activeempty()
2798     	 * of the name we were searching for. Step the iterator
2799     	 * forward, then step() will continue forward until it
2800     	 * finds a node with active data. If that node is a
2801     	 * subdomain of the one we were looking for, then we're
2802     	 * at an active empty nonterminal node.
2803     	 */
>>>     CID 487882:  Error handling issues  (CHECKED_RETURN)
>>>     Calling "dns_qpiter_next" without checking return value (as is done elsewhere 26 out of 27 times).
2804     	dns_qpiter_next(it, NULL, NULL, NULL);
2805     	return (step(search, it, FORWARD, next) &&
2806     		dns_name_issubdomain(next, current));
2807     }
2024-03-14 14:01:23 +01:00
Matthijs Mekking
659fa0cbc3 Fix Coverity CID 487884: Dead code in qpcache.c
Adding a changed record is zonedb related and does not belong in
the cache code. This is a leftover dead code and can be safely
removed.

/lib/dns/qpcache.c: 3459 in add()
3453     			}
3454     			newheader->next = topheader->next;
3455     			newheader->down = topheader;
3456     			topheader->next = newheader;
3457     			qpnode->dirty = 1;
3458     			if (changed != NULL) {
>>>     CID 487884:    (DEADCODE)
>>>     Execution cannot reach this statement: "changed->dirty = true;".
3459     				changed->dirty = true;
3460     			}
3461     		} else {
3462     			/*
3463     			 * No rdatasets of the given type exist at the node.
3464     			 */
/lib/dns/qpcache.c: 3409 in add()
3403     			}
3404     			newheader->next = topheader->next;
3405     			newheader->down = topheader;
3406     			topheader->next = newheader;
3407     			qpnode->dirty = 1;
3408     			if (changed != NULL) {
>>>     CID 487884:    (DEADCODE)
>>>     Execution cannot reach this statement: "changed->dirty = true;".
3409     				changed->dirty = true;
3410     			}
3411     			mark_ancient(header);
3412     			if (sigheader != NULL) {
3413     				mark_ancient(sigheader);
3414
2024-03-14 10:42:30 +00:00
Evan Hunt
b3c8b5cfb2 remove dead code in rbtdb.c
dns_db_addrdataset() enforces a requirement that version can only
be NULL for a cache database. code that checks for zone semantics
and version == NULL can never be reached.
2024-03-13 17:15:18 -07:00
Evan Hunt
29f1c93734 support nodefullname in rbt-zonedb.c
this enables the 'dyndb' system test to pass when we
build using --with-zonedb=rbt.
2024-03-13 17:15:18 -07:00
Evan Hunt
f0b164430a remove dead code in qpzone.c
qpzone does not support cache semantics, so dns_db_addrdataset(),
_deleterdataset() and _subtractrdataset() can't be run with
version == NULL; there's no need to check for it.

we can also clean up free_qpdb() a bit since current_version
is always non-NULL.
2024-03-13 17:15:18 -07:00
Mark Andrews
228cc557fe Only call memmove if the rdata length is non zero
This avoids undefined behaviour on zero length rdata where the
data pointer is NULL.
2024-03-13 23:04:56 +00:00