Commit graph

366 commits

Author SHA1 Message Date
Mark Andrews
53738b0e5e Use clang-format-20 to update formatting
(cherry picked from commit 422b9118e8)
2025-06-25 13:32:08 +10:00
Mark Andrews
072f5d0009 Preserve brackets around string concatenation
We need disable clang-format here to preserve the brackets around
the string concatenation to prevent -Wstring-concatenation -Werror
breaking the build.

(cherry picked from commit eeafcee7ad)
2025-06-25 13:26:13 +10:00
Mark Andrews
3b20e48658 Silence potential divide by zero warning in qpmulti.c
Coverity flagged a potential divide by zero error in collect in
qpmulti.c when the elapsed time is zero but that is only called
once the elapsed time is greater than or equal to RUNTIME (1/4
second) so INSIST this is the case.

(cherry picked from commit 081dbb1108)
2025-06-02 23:41:21 +00:00
Evan Hunt
12d13ff071
Prevent assertion when processing TSIG algorithm
In a previous change, the "algorithm" value passed to
dns_tsigkey_create() was changed from a DNS name to an integer;
the name was then chosen from a table of known algorithms. A
side effect of this change was that a query using an unknown TSIG
algorithm was no longer handled correctly, and could trigger an
assertion failure.  This has been corrected.

The dns_tsigkey struct now stores the signing algorithm
as dst_algorithm_t value 'alg' instead of as a dns_name,
but retains an 'algname' field, which is used only when the
algorithm is DST_ALG_UNKNOWN.  This allows the name of the
unrecognized algorithm name to be returned in a BADKEY
response.

(cherry picked from commit decf461d68846d6754c1f64790c3f9006d158a1d)
2025-05-07 13:45:48 +02:00
Aram Sargsyan
b959ac44a7 Fix the isc_rwlock_tryupgrade() function's unit test
The pthread-based implementation of the isc_rwlock_tryupgrade()
function always returns ISC_R_LOCKBUSY. Fix the test by adding
conditional checks.

(cherry picked from commit c27659bc62)
2025-04-16 16:04:08 +00:00
Mark Andrews
e09eb2ff21 Fix OID check for PRIVATEOID keys and signatures
We were failing to account for the length byte before the OID.
See RFC 4034.

   Algorithm number 254 is reserved for private use and will never be
   assigned to a specific algorithm.  The public key area in the DNSKEY
   RR and the signature area in the RRSIG RR begin with an unsigned
   length byte followed by a BER encoded Object Identifier (ISO OID) of
   that length.  The OID indicates the private algorithm in use, and the
   remainder of the area is whatever is required by that algorithm.
   Entities should only use OIDs they control to designate their private
   algorithms.

(cherry picked from commit ca7355b7d0)
2025-04-09 20:07:31 +00:00
Colin Vidal
30a5031c8c fix out-of-tree mem_test
Previously changed mem_test (!10320) introduces a test which checks for
the value of `__FILE__`, which is different if the build is done
out-of-tree or not, even though this is not relevant for the test (only
the base filename is). This result in a broken test for out-of-tree
builds. Fix this by changing the way the "grep" is done in the test,
ignoring the optional path prefix in the filename.

(cherry picked from commit b7ae514b3b)
2025-03-28 14:55:15 +00:00
Colin Vidal
c1352b79ca copy __FILE__ when allocating memory
When allocating memory under -m trace|record, the __FILE__ pointer is
stored, so it can be printed out later in order to figure out in which
file an allocation leaked. (among others, like the line number).

However named crashes when called with -m record and using a plugin
leaking memory. The reason is that plugins are unloaded earlier than
when the leaked allocations are dumped (obviously, as it's done as late
as possible). In such circumstances, __FILE__ is dangling because the
dynamically loaded library (the plugin) is not in memory anymore.

Fix the crash by systematically copying the __FILE__ string
instead of copying the pointer. Of course, this make each allocation to
consume a bit more memory (and longer, as it needs to calculate the
length of __FILE__) but this occurs only under -m trace|record debugging
flags.

In term of unit test, because grepping in C is not fun, and because the
whole "syntax" of the dump output is tested in other tests, this simply
search for a substring in the whole buffer to make sure the expected
allocations are found.

(cherry picked from commit 4eb2cd364a)
2025-03-27 14:21:00 +01:00
Colin Vidal
ad3e09a6af IPv6 case to isc_netaddr_masktoprefixlen tests
Unit test for isc_netaddr_masktoprefixlen were missing IPv6 mask cases.
Add those and few other IPv4 cases. Also, the test is refactored in
order to make it easy to add new cases.

(cherry picked from commit ad2c3fa4f7)
2025-03-26 13:30:46 +00:00
Mark Andrews
6d2bd55794 Silence warning when initialising compress
The string literal initialalising compressed was too big for the
array as it has an unwanted NUL terminator.  This is allowed for
in C for historical reasons but produces a warning with some
compilers.  Adjust the declaration to include the NUL and adjust
the users to pass in an adjusted size which excludes the NUL rather
than sizeof(compressed).

(cherry picked from commit 6a6b6be824)
2025-03-26 12:43:55 +00:00
Evan Hunt
dd1050e938 qpzone find() function could set foundname incorrectly
when a requested name is found in the QP trie during a lookup, but its
records have been marked as nonexistent by a previous deletion, then
it's treated as a partial match, but the foundname could be left
pointing to the original qname rather than the parent. this could
lead to an assertion failure in query_findclosestnsec3().
2025-03-17 09:27:09 +00:00
Evan Hunt
ba8d69648e add a unit test with an empty node
the db_test unit test now looks up an empty nonterminal node
to exercise the behavior of the step() function in qpzone.

(cherry picked from commit ecde0ea2d7)
2025-03-14 23:23:00 +00:00
Evan Hunt
6a9e04d46a add a unit test to check database rollback
check that a database rollback works and the correct
(original) data is found on lookup.

(cherry picked from commit 7d98aba3ac)
2025-03-14 23:23:00 +00:00
Evan Hunt
cc0fc98244 wrap ns_client_error() for unit testing
When testing, the client object doesn't have a proper
netmgr handle, so ns_client_error() needs to be a no-op.

(cherry picked from commit ae37ef45ff)
2025-02-26 00:55:51 +00:00
Mark Andrews
a0dae15cd1 Relax private DNSKEY and RRSIG constraints
DNSKEY, KEY, RRSIG and SIG constraints have been relaxed to allow
empty key and signature material after the algorithm identifier for
PRIVATEOID and PRIVATEDNS. It is arguable whether this falls within
the expected use of these types as no key material is shared and
the signatures are ineffective but these are private algorithms and
they can be totally insecure.

(cherry picked from commit b048190e23)
2025-02-25 23:40:38 +00:00
Ondřej Surý
c6c03a6b11
Reduce false sharing in dns_qpzone
Instead of having many node_lock_count * sizeof(<member>) arrays, pack
all the members into a qpzone_bucket_t that is cacheline aligned and have
a single array of those.

(cherry picked from commit 6dcc398726)
2025-02-04 23:28:50 +01:00
Ondřej Surý
7dab6cdfbc
Remove db_nodelock_t in favor of reference counted qpdb
This removes the db_nodelock_t structure and changes the node_locks
array to be composed only of isc_rwlock_t pointers.  The .reference
member has been moved to qpdb->references in addition to
common.references that's external to dns_db API users.  The .exiting
members has been completely removed as it has no use when the reference
counting is used correctly.

(cherry picked from commit 431513d8b3)
2025-01-31 05:49:36 +01:00
Colin Vidal
3bc6de9265 update EDE copy and add dup tests
Update EDE tests to exercise the bitmap and next ede index logic

(cherry picked from commit c7b0fe5bec)
2025-01-30 12:37:55 +00:00
Colin Vidal
7e3a650ae2 Refactor test covering dns_ede API
Migrate tests cases in client_test code which were exclusively testing
code which is now all wrapped inside ede compilation unit. Those are
testing maximum number of EDE, duplicate EDE as well as truncation of
text of an EDE.

Also add coverage for the copy of EDE from an edectx to another one, as
well as checking the assertion of the maximum EDE info code which can be
used.

(cherry picked from commit f9f41190b3)
2025-01-30 12:37:55 +00:00
Ondřej Surý
1ffb67a135 Split and simplify the use of EDE list implementation
Instead of mixing the dns_resolver and dns_validator units directly with
the EDE code, split-out the dns_ede functionality into own separate
compilation unit and hide the implementation details behind abstraction.

Additionally, the EDE codes are directly copied into the ns_client
buffers by passing the EDE context to dns_resolver_createfetch().

This makes the dns_ede implementation simpler to use, although sligtly
more complicated on the inside.

Co-authored-by: Colin Vidal <colin@isc.org>
Co-authored-by: Ondřej Surý <ondrej@isc.org>
(cherry picked from commit 2f8e0edf3b)
2025-01-30 12:37:55 +00:00
Colin Vidal
01bbc357c7 add unit tests covering multiple EDE support
(cherry picked from commit 950a0cffb3)
2025-01-23 13:12:53 +00:00
Artem Boldariev
4f8ade0e1e TLS SNI - add low level support for SNI to the networking code
This commit adds support for setting SNI hostnames in outgoing
connections over TLS.

Most of the changes are related to either adapting the code to accept
and extra argument in *connect() functions and a couple of changes to
the TLS Stream to actually make use of the new SNI hostname
information.

(cherry picked from commit 6691a1530d)
2024-12-26 18:31:03 +02:00
Michal Nowak
75931127ac Drop superfluous isc_mem_get() NULL check
coccinelle v1.1 trips over a superfluous isc_mem_get() NULL check in
tests/libtest/ns.c and reports the following failure in CI:

    EXN: Failure("rule starting on line 26: already tagged token:\nC code context\nFile \"./tests/libtest/ns.c\", line 350, column 1, charpos = 7939\n  around = 'if',\n  whole content = \tif (qctx != NULL) {") in ./tests/libtest/ns.c

(cherry picked from commit cf76851c75)
2024-12-13 13:50:06 +00:00
Mark Andrews
d6026a7255 Move resconf_test.c to tests/dns and cleanup
(cherry picked from commit b711b5b10d)
2024-12-12 22:50:22 +00:00
Mark Andrews
3b13f75629 Check that nameservers are parsed correctly
Add checks that the expected nameservers where actuall addes when
parsing resolv.conf.

(cherry picked from commit c38eb87158)
2024-12-12 22:50:22 +00:00
Colin Vidal
32f5b69703 Add none parameter to query-source and query-source-v6 to disable IPv4 or IPv6 upstream queries
Add a none parameter to named configuration option `query-source` (respectively `query-source-v6`) which forbid usage of IPv4 (respectively IPv6) addresses when named is doing an upstream query.

Closes #4981 Turning-off upstream IPv6 queries while still listening to downstream queries on IPv6.

Merge branch 'colin/querysource-none' into 'main'

See merge request isc-projects/bind9!9727

Backport of MR !9727

Some changes had to be done to the existing 9.20.x code in order to
make this backport compatible:

- first, the 9.20.x branches support the `port` parameter in
  query-source[-v6], where 9.21.x does not. The original changes
  depend on things that can't be backported because that would break
  `port` support.

- second, the changes remove the optional `address` parameter from the
  canonical form. So `query-source address <ip>` is now printed as
  `query-source <ip>`. This means that `named-checkconf -p` will now
  generate different output if users have `query-source address <ip>` or
  `query-source address <ip> port <port>`; it will now generate
  `query-source <ip>` or `query-source <ip> port <port>`. This is a
  non-breaking change, because the parser has been updated to support
  this form as well.
2024-12-10 11:58:20 +01:00
Mark Andrews
ff6db0bea4 Extend resconf_test
Update to the new unit test framework.

Add a test for an unknown directive without any arguments.

Add test for an unknown directive without arguments, followed
by a search directive.

(cherry picked from commit c44c4fcbfb)
2024-12-10 00:49:07 +00:00
Colin Vidal
c586d9a658 Add EDE 22 No reachable authority code
Add support for Extended DNS Errors (EDE) error 22: No reachable
authority. This occurs when after a timeout delay when the resolver is
trying to query an authority server.

(cherry picked from commit d13e94b930)

Commit amended in order to fix usage of isc_log_write (adding dns_lctx
parameter)
2024-12-05 10:30:28 +01:00
Ondřej Surý
6c3f1f09b2 Improve the badcache cleaning by adding LRU and using RCU
Instead of cleaning the dns_badcache opportunistically, add per-loop
LRU, so each thread-loop can clean the expired entries.  This also
allows removal of the atomic operations as the badcache entries are now
immutable, instead of updating the badcache entry in place, the old
entry is now deleted from the hashtable and the LRU list, and the new
entry is inserted in the LRU.

(cherry picked from commit 2cb5a6210f)
2024-11-27 17:07:03 +00:00
Alessio Podda
0472494417 Incrementally apply AXFR transfer
Reintroduce logic to apply diffs when the number of pending tuples is
above 128. The previous strategy of accumulating all the tuples and
pushing them at the end leads to excessive memory consumption during
transfer.

This effectively reverts half of e3892805d6

(cherry picked from commit 99b4f01b33)
2024-11-26 07:17:06 +00:00
Mark Andrews
0e00e28ec6 Parse the URI template and check for a dns variable
The 'dns' variable in dohpath can be in various forms ({?dns},
{dns}, {&dns} etc.).  To check for a valid dohpath it ends up
being simpler to just parse the URI template rather than looking
for all the various forms if substring.

(cherry picked from commit af54ef9f5d)
2024-11-26 03:41:46 +00:00
Remi Gacogne
cc9366031b '{&dns}' is as valid as '{?dns}' in a SVCB's dohpath
See for example section 1.2. "Levels and Expression Types" of rfc6570.

(cherry picked from commit e74052ea71)
2024-11-26 03:41:45 +00:00
Ondřej Surý
58a15d38c2
Remove redundant parentheses from the return statement
(cherry picked from commit 0258850f20)
2024-11-19 14:26:52 +01:00
Mark Andrews
d5da28d1ca Fix TCP dispatches and transport
Dispatch needs to know the transport that is being used over the
TCP connection to correctly allow for it to be reused.  Add a
transport parameter to dns_dispatch_createtcp and dns_dispatch_gettcp
and use it when selecting a TCP socket for reuse.

(cherry picked from commit baab8a5d75)
2024-10-24 01:21:37 +00:00
Evan Hunt
b5475c9cda corrected code style errors
- add missing brackets around one-line statements
- add paretheses around return values
2024-10-18 19:31:56 +00:00
Mark Andrews
10a599d3e8 Add regression test for [GL #4987]
(cherry picked from commit 677abded6b)
2024-10-17 22:05:22 +00:00
Ondřej Surý
4b4c550cd8 Don't enable SO_REUSEADDR on outgoing UDP sockets
Currently, the outgoing UDP sockets have enabled
SO_REUSEADDR (SO_REUSEPORT on BSDs) which allows multiple UDP sockets to
bind to the same address+port.  There's one caveat though - only a
single (the last one) socket is going to receive all the incoming
traffic.  This in turn could lead to incoming DNS message matching to
invalid dns_dispatch and getting dropped.

Disable setting the SO_REUSEADDR on the outgoing UDP sockets.  This
needs to be done explicitly because `uv_udp_open()` silently enables the
option on the socket.

(cherry picked from commit eec30c33c2)
2024-10-02 12:16:58 +00:00
Mark Andrews
c6045acc41 Add the new record type WALLET (262)
This provides a mapping from a domain name to a cryptographic
currency wallet and is a clone of TXT.

(cherry picked from commit b919b9b4f3)
2024-09-25 12:07:52 +00:00
Matthijs Mekking
c89230efcf Remove test.skr unit test file
This file was initially created for unit testing, but later code was
added to generate the file. The static file should have been removed
from the git repo.

(cherry picked from commit 903534c9a9)
2024-09-09 17:42:05 +00:00
Ondřej Surý
95faca929e
Reduce the size of hashmap_nodes.h file
Instead of keeping the whole array of test_node_t objects, just keep the
hashvalues and generated the rest of the test_node_t on the fly.  The
test still works this way and the file size has been reduced from 2M to
90k.

(cherry picked from commit 2310c322c0)
2024-09-03 14:46:58 +02:00
Matthijs Mekking
c92ae2b010 Add skr unit test
Add a test file for testing the skr related code.

(cherry picked from commit 1ce163795e)
2024-08-22 10:17:08 +00:00
Ondřej Surý
46069fe5c7 Use clang-format-19 to update formatting
This is purely result of running:

    git-clang-format-19 --binary clang-format-19 origin/main

(cherry picked from commit 7b756350f5)
2024-08-22 08:16:03 +00:00
Mark Andrews
394df760b2 Extend ISC_TEST_MAIN for debugging
ISC_TEST_MAIN now supports turning on/off debugging and
running individual tests.

(cherry picked from commit d8a6ff5c3e)
2024-08-22 11:34:42 +10:00
Ondřej Surý
673c1c8b96 Allow TTL skew in the badcache print unit test
If the machine running the job is extra loaded (or extra slow), the
print test in the badcache unit test would fail because the TTL would be
59 (possibly even lower) and the test expects the badcache.out to only
have TTL 60.  Refactor the test to check for the expected strings and
check whether the TTL is in the expected range.

(cherry picked from commit 7860b6519d)
2024-08-20 17:33:43 +00:00
Ondřej Surý
18398da61c Ignore ISC_R_CONNECTIONRESET in the TCP tests
On FreeBSD, the TCP connection callback could spuriously receive
ISC_R_CONNECTIONRESET even when connection to the loopback interface.
Skip the other checks in such case and graciously shutdown the TCP
connection.

(cherry picked from commit e53cb61cf7)
2024-08-20 12:49:57 +00:00
Ondřej Surý
27a7647559 Change the NS_PER_SEC (and friends) from enum to static const
New version of clang (19) has introduced a stricter checks when mixing
integer (and float types) with enums.  In this case, we used enum {}
as C17 doesn't have constexpr yet.  Change the time conversion constants
to be static const unsigned int instead of enum values.

(cherry picked from commit b03e90e0d4)
2024-08-19 09:10:04 +00:00
Ondřej Surý
54b3fec145 Add known-to-crash static hashmap iterator nodes array
Add second iterator test with a well-known configuration of the nodes
array that causes the last element of the array to migrate two times to
the previous node.

(cherry picked from commit 482eed2e31)
2024-08-15 12:09:28 +00:00
Ondřej Surý
0e1d47c171 Add tsig unit test for bad time and bad signatures
The tsig unit test was only testing if everything went ok, but it was
not testing whether the error paths work.  Add two more unit tests - one
uses the time outside of the TSIG skew, and the second trashes the
signature with random data.

(cherry picked from commit 3835d75f00)
2024-08-05 11:11:40 +00:00
Ondřej Surý
36265057f9 Don't open route socket if we don't need it
When automatic-interface-scan is disabled, the route socket was still
being opened.  Add new API to connect / disconnect from the route socket
only as needed.

Additionally, move the block that disables periodic interface rescans to
a place where it actually have access to the configuration values.
Previously, the values were being checked before the configuration was
loaded.

(cherry picked from commit b26079fdaf)
2024-08-05 10:17:08 +00:00
Aram Sargsyan
fa15c1fb23 Update the resolver unit test
Before there was a gap from 301 to 9999 which would be converted
to 10000 and now there is no such gap.

This settimeout_belowmin test was checking the behavior of a value
in the gap. As there is now no gap left, the minimum is 301 and
anything below that is converted to seconds as before. In order
for this check to still test the "below minimum" behavior, change
the value from 9000 to 300.

Update the settimeout_overmax value test too so it logically aligns
with the minimum value test.

(cherry picked from commit 63b787effe)
2024-08-01 19:23:06 +00:00