Commit graph

526 commits

Author SHA1 Message Date
Colin Vidal
1b5f757084 Introduce a delegation database
Add `dns_delegdb_t`, a qpmulti-based database enabling to lookup a
delegation set (`dns_delegset_t`) from a zonecut name (`dns_name_t`). A
delegation set object essentially contains an expiration time and a list
of delegation (`dns_deleg_t`). Finally, a delegation can be either:

- A list of IP addresses (`isc_netaddrlist_t`), for NS-based delegation
  providing glues or DELEG-based delegation using `server-ipv4=` or
  `server-ipv6=`;
- Or a list of nameserver names, for NS-based delegation without glues,
  or DELEG-based delegation using `server-name=`;
- Or a list of nameserver names, for DELEG-based delegation using
  `include-delegparam=`.

The delegation database API provides lookup by closest zonecut,
delegation and delegation set builders as well as insertion of those
newly built delegation set, dumping to a `FILE *`, conversion from an NS
rdataset to a delegation set, deletion of a specific zonecut or all the
sub-tree of a given zonecut.

A memory context is internally used inside the delegation database and
can be constraint to a maximum size. Once it gets close to its maximum
size and a new delegation set is inserted into the database, a
reclamation flow is run internally removing the least recently used
entries.

The delegation set and delegation objects are, once they been inserted
into the database, read-only object. Thus, the caller can use them
without concurrency or locking concerns, and must detached them once its
done with it.
2026-03-30 20:41:13 +02:00
Mark Andrews
aa2a41b2d1 Test the ability to walk the iterators multiple times
It should be possible to walk APL, HIP, HTTPS and SVBC record
elements multiple times.  We now test this.
2026-03-27 12:00:22 +00:00
Mark Andrews
e435b0b7fb Test walking apl list entries 2026-03-27 12:00:22 +00:00
Alessio Podda
70b65648ac Move ns_highwater_recursclients to highwater stats
Since it is impossible to increase an isc_statsmulti counter and
retrieve the new counter atomically, and we need the output of
recursclients in order to compute ns_highwater_recursive, we change the
recursclients counter to an isc_stats one.
2026-03-26 10:19:25 +01:00
Alessio Podda
ed0ecb62e4 Add low contention stats counter
In the current statistics counter implementation, the statistics are
backed by an array of counters, which are updated via atomic operations.
This leads to contention, especially on high core count
machines.

This commit introduces a new isc_statsmulti_t counter that keeps a
separate array per thread. These counters are then aggregated only when
statistics are queried, shifting work off the critical path.

These changes lead to a ~2% improvement in perflab.
2026-03-26 10:19:25 +01:00
Aram Sargsyan
4ac3a6520e Convert dns_dtenv_t reference counting to standard macors
Use standard reference counting macros for dns_dtenv_t instead of
custom attach/detach functions.
2026-03-18 16:10:07 +00:00
Ondřej Surý
f1311d2d19
Enforce isc_work enqueue loop affinity
Add a REQUIRE(isc_loop() == loop) assertion to isc_work_enqueue()
to strictly enforce that work is enqueued from the loop it is
assigned to. This loudly prohibits cross-thread queue manipulation
before it inevitably turns into a concurrency debugging nightmare.
2026-03-14 06:32:50 +01:00
Michal Nowak
239464f276
Use clang-format-22 to update formatting 2026-03-04 10:56:41 +01:00
Mark Andrews
e83a182056
Test maximum length NSEC3 hash detection
Adds text and wire format unit tests to verify the newly enforced
maximum NSEC3 hash length constraints.  These tests ensure that hash
lengths up to the 39-byte maximum are accepted, while larger sizes
correctly fail.
2026-02-24 15:00:10 +01:00
Mark Andrews
3801d0ebbf
Enforce NSEC3 record consistency
NSEC3 hashes are required to fit within a single DNS label.  Since there
are 5 bits per label byte without pad characters, the maximum hash size
is floor(63*5/8) (39 bytes).

This patch enforces this maximum length for unknown algorithms, while
strictly enforcing the exact expected digest length for known algorithms
like SHA-1.
2026-02-24 14:57:22 +01:00
Matthijs Mekking
ce1d68cbc5
Add a regression test for the BRID/HHIT crash
Add two short records to example.com.db that cause assertion failures
when converted to wire form.

The checks added to tests.sh are technically not required: the relevant
assertion failures are already hit when the zone is transferred out of
ns1.

Update the relevant unit tests with 1-byte records.

Co-authored-by: Mark Andrews <marka@isc.org>
2026-02-05 18:21:52 +01:00
Aydın Mercan
8f106f2b66
Separate isc_hmac between pre and post OpenSSL 3.0
Instead of the `EVP_MD_CTX` based functions, use either the new
`EVP_MAC` or the old `HMAC_CTX` based functions.

`EVP_MAC` is the recommended way using using MAC functions in post-3.0
while `HMAC_CTX` is used internally by `EVP_MD_CTX`, making the latter
redundant.
2026-02-02 11:50:14 +03:00
Aydın Mercan
f9ec4a1cdf
switch isc_md_type_t to a proper enum
Get rid of the OpenSSL-isms that plague the codebase where the hash type
is `EVP_MD *`

By using a proper enum, alongside the cleanup, we also get the ability
to use constants for known hash sizes instead of having a function call
every time.

`EVP_MD_CTX_get0_md` has been removed instead of being adapted since it
wasn't used anymore.
2026-02-02 11:12:55 +03:00
Mark Andrews
22d664aa15 ISC_RUN_TEST_IMPL should use a static declaration
These functions don't need to be called from multiple places and
by making them static we will detect when they are not added to the
list functions to be tested.
2026-01-28 07:26:04 +11:00
Mark Andrews
97af8fc519 Fix brid and hhit unit tests
These tests were not being run.
2026-01-27 16:05:29 +11:00
Mark Andrews
8da2310511 Fix and call tsig_badsig unit test 2026-01-24 01:25:55 +11:00
Mark Andrews
2159f74a1f Fix dsync unit test
The dsync unit test was not being run and the domain names in
the test data should have been fully qualified.
2026-01-24 00:38:51 +11:00
Aram Sargsyan
dd313f41c5 Add a new dbversion unit test
Test that closing a writer with a rollback, then opening another
writer and adding a rdataset (while still holding the node reference)
works correctly.

This test checks that the bugfix in the previous commit is correct.
2026-01-21 10:47:17 +00:00
Aram Sargsyan
e2994d2b1a Fix a false positive compiler warning/error
When built with '-Doptimization=1', GCC produces a compiler warning:

    In file included from ../lib/isc/include/isc/lib.h:44,
                     from ../tests/dns/qp_test.c:26:
    ../tests/dns/qp_test.c: In function ‘check_predecessors_withchain’:
    ../lib/isc/include/isc/util.h:182:33: error: ‘ival’ may be used uninitialized [-Werror=maybe-uninitialized]
      182 |         (((a) == (b)) ? (void)0 : (_assert_int_equal(a, b, f, l), abort()))
          |         ~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    /usr/include/cmocka.h🔢5: note: in expansion of macro ‘_assert_int_equal’
     1234 |     _assert_int_equal(cast_to_largest_integral_type(a), \
          |     ^~~~~~~~~~~~~~~~~
    ../tests/dns/qp_test.c:859:18: note: ‘ival’ was declared here
      859 |         uint32_t ival;
          |                  ^~~~

This is apparently a false positive, because the qpiter_prev_with_name()
function, when returning ISC_R_SUCCESS, sets the 'ival' (passed to
it by a pointer), and the caller checks that the return value is
ISC_R_SUCCESS before using 'ival'.

Initialize the 'ival' variable to 0 anyway to avoid the build error.
2026-01-15 17:49:29 +00:00
Nicki Křížek
6843a4bd9a Support compilation with cmocka 2.0.0+
The `assert_in_range()` function was deprecated in favor of
`assert_int_in_range()` and `assert_uint_in_range()`. Add compatibility
shims for cmocka<2.0.0 and use the new functions.
2026-01-07 10:38:45 +01:00
Štěpán Balážik
237489caf4 Use CMocka generated JUnit reports where possible
Where applicable, use the more detailed CMocka generated JUnit
reports which include subtest results and timings instead of the
one generated by Meson.

Flaky tests also require retrying, so use a wrapper and mark them
with a environment variable. This is done to avoid the need to compute
an intersection of suites in Meson which is not supported out-of-the-box
(`meson test --suite=foo,bar` runs the union of foo and bar).
2025-12-19 18:26:22 +00:00
Štěpán Balážik
179c101bf0 Put CMocka unit tests in a suite
Distinguish them for JUnit report collection.
2025-12-19 18:26:22 +00:00
Štěpán Balážik
5126f782b1 Set unit test group name in CMocka tests
CMocka uses group names in the JUnit output.

Use dirname_filename as the group name, as there duplicate testnames
(e.g. time exists both in isc/ and dns/)
2025-12-19 18:26:22 +00:00
Ondřej Surý
8320faf64b
Apply the dns_rdataset_cleanup patch through the codebase
Add a semantic patch to turn the conditional rdataset disassociate into
dns_rdataset_cleanup() call and run it.
2025-12-17 15:19:55 +01:00
Matthijs Mekking
41159e9062 Implement dns_dbiterator_seek3
This is a new seek function for dbiterator that is meant to find an
NSEC3 node in a zone database. The difference with dns_dbiterator_seek
is that if the node does not exist, this seek function will point the
iterator to the next NSEC3 name.
2025-12-10 14:18:52 +01:00
Alessio Podda
f1d8c3059c Fix formatting 2025-12-10 12:18:34 +01:00
Alessio Podda
852041457e Add vecheader unit tests
Adds unit tests for the new rdatavec, doing basic size and case
checking.
2025-12-10 12:18:34 +01:00
Alessio Podda
4eb0b23efc Switch qpzone to rdatavec
Replaces rdataslab with rdatavec inside qpzone.c. This leads to a 19.92%
reduction of used memory across perflab workloads.
2025-12-10 12:18:34 +01:00
Alessio Podda
4d698ee0e3 Fix formatting after refactor
The removal of the foundname and name parameters from various qp.c
functions led to formatting issues. Restore the correct formatting via
clang-format.
2025-12-10 11:28:10 +01:00
Alessio Podda
46e25bd0db Remove maybe_set_name
Outside of unit tests, the name parameter in dns_qpiter_<...> and
dns_qpchain_<...> is only used in context where the name can be
extracted directly from the underlying node.

This commits modifies the signatures of dns_qpiter_<...> and
dns_qpchain_<...> not to have a name parameter. Where the name parameter
was needed, we now query the node and copy the name directly from it.

This allows us to remove maybe_set_name from qp.c. Besides simplifying
the API, this leads to a performance speedup for NXDOMAIN handling,
as we avoid calling maybe_set_name inside step, and maybe_set_name is
very inefficient.

A copy of the implementation maybe_set_name is retained for the unit
tests.
2025-12-10 11:28:10 +01:00
Alessio Podda
14f880761b Remove unused foundname parameter
The `foundname` parameter in dns_qp_lookup is used only in the unit
tests. This commit simplifies the API by removing it, and modifying the
unit tests to extract the name from pval.
2025-12-10 11:28:10 +01:00
Alessio Podda
ad0a382092 Fix formatting
Cleanup formatting after IXFR changes.
2025-12-09 13:32:24 +01:00
Alessio Podda
fb72ebcdd8 Add unit tests 2025-12-09 12:55:30 +01:00
Alessio Podda
da53708dcb Implement qpzone specific update path
This commit implements a batch update function for qpzone. The main
reason for this is speed: using addrdataset would cause a qp transaction
per rrdataset added, leading to a substantial slowdown compared to
RBTDB. The new API results in a qp transaction per applied diff.
2025-12-09 12:55:30 +01:00
Colin Vidal
77e0104cf4 shrunk cfgobj down to 48bytes
Make all non-scalar properties of `cfg_obj_t` allocated values, which
ensures the union size is the width of one pointer. Also reorder the
fields inside `cfg_obj_t` to avoid alignment padding that would increase
the size. As a result, a `cfg_obj_t` instance is now 48 bytes on a
64-bit platform.

Add a static assertion to avoid increasing the size of the struct by
mistake.

The function `parse_sockaddrsub` was taking advantage of the fact that
both sockaddr and sockaddrtls were in the same position, and used to
initialize the sockaddr field independently if this was a -tls one or
not. This doesn't work anymore now that all fields are allocated,
so it has been slightly rewritten to take both cases into account
separately.
2025-12-05 08:59:53 +01:00
Colin Vidal
f7b64e2e87 cfg_parse_ API doesn't need memory context
Because the parser now uses global memory context, the cfg_parse_* API
doesn't take a memory context anymore.
2025-12-04 16:09:40 +01:00
Mark Andrews
0e230c86d2 Rename isc_result_t ret; to isc_result_t result;
Standardize result variable naming by using 'result' in most places.
2025-12-03 13:45:43 -08:00
Evan Hunt
6b33b7fc77 switch to RETERR where it wasn't being used
replace all instances of the pattern:

        result = <statement>
        if (result != ISC_R_SUCCESS) {
                return result;
        }

with:

        RETERR(<statement>);
2025-12-03 13:45:43 -08:00
Evan Hunt
38e94cc7da switch to CHECK where it wasn't being used
replace all instances of the pattern:

        result = <statement>
        if (result != ISC_R_SUCCESS) {
                goto cleanup;
        }

with:

        CHECK(<statement>);
2025-12-03 13:45:42 -08:00
Evan Hunt
52bba5cc34 standardize CHECK and RETERR macros
previously, there were over 40 separate definitions of CHECK macros, of
which most used "goto cleanup", and the rest "goto failure" or "goto
out". there were another 10 definitions of RETERR, of which most were
identical to CHECK, but some simply returned a result code instead of
jumping to a cleanup label.

this has now been standardized throughout the code base: RETERR is for
returning an error code in the case of an error, and CHECK is for jumping
to a cleanup tag, which is now always called "cleanup". both macros are
defined in isc/util.h.
2025-12-03 13:26:28 -08:00
Aram Sargsyan
8c8bf4e45d Fix an issue with unreachable cache's unit test
The isc_stdtime_now() function used by dns_unreachcache_find() to
check if the entry needs to be expired has a one-second resolution,
and the test sleeps for 1 second and then for the amount of the
expiration interval, which in a worst-case scenario can cause the
test to fail, because the entry was expected to be expired but it
wasn't. Sleep for 2 seconds instead of 1 to avoid the timing
resolution issue.
2025-12-02 16:03:26 +00:00
Michal Nowak
1684556577
Disable 'doh' unit test on Enterprise Linux 8
Disable test that fails for months on this platform.
2025-11-25 10:55:03 +01:00
Evan Hunt
1a77ae2a7a fix allow-recursion/allow-query-cache inheritance
the merging of options and defaults into the effective configuration
broke the mutual inheritance of the allow-recursion, allow-query, and
allow-query-cache ACLs, and of the allow-recursion-on and
allow-query-cache-on ACLs.

this has been corrected by adding a 'cloned' flag to the cfg_obj
structure to indicate whether it was configured explicitly or
cloned from the defaults during parsing. we can then adjust the
ACLs while configuring a view, favoring user-configured values
when they're available over cloned defaults.

currently the adjustments to the ACLs are done in configure_view();
later they'll be moved into the effective configuration and this
special handling can be removed.
2025-11-20 11:24:11 -08:00
Mark Andrews
ae484d4501 AMTRELAY type 0 presentation format handling was wrong
RFC 8777 specifies a placeholder value of "." for the gateway field
when the gateway type is 0 (no gateway).
2025-11-20 18:28:32 +11:00
Mark Andrews
d9fc1f2471 Include <stdarg.h> in byaddr_test.c 2025-11-19 10:16:40 +11:00
Ondřej Surý
47328cc1f8 Fix parser test (missing string termination)
Parser test could crash because the `dumpb2` buffer hasn't explicit C
NULL string termination after dumping the configuration tree in it.
`cfg_printx` does not doing this by default.

Fix the test by comparing only the strings written with strncmp.
2025-11-05 13:06:38 +01:00
Matthijs Mekking
090a451e66 Export zone functions
Make some zone functions available that we are going to need in the
notify code.
2025-10-31 13:43:47 +01:00
Colin Vidal
35c8768fde parser firstclause/nextclause API changes
In order to make upcoming configuration tree changes easier, the
cfg_map_firstclause() and _nextclause() functions have been changed
to return the clause itself rather than only the clause name.
2025-10-29 13:55:04 -07:00
Colin Vidal
1439635118 add unit test for cfg_obj_clone
Add a unit test for `cfg_obj_clone` to verify that the cloned tree
indeed has independent child nodes. The test also verifies that the
clone is semantically correct by comparing a text dump of the original
tree and the cloned one.
2025-10-27 21:33:18 +01:00
Ondřej Surý
90b3def5e9
Drop the unit test for testing randomness
Since we are using system routines for randomness, there's no point
in spending time and run the statistical suite for testing PRNG.
2025-10-24 21:16:55 +02:00