2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-08-31 06:25:31 +00:00
Commit Graph

36267 Commits

Author SHA1 Message Date
Matthijs Mekking
f54dad005e Warn if multiple keys have same role
If a dnssec-policy has multiple keys configured with the
same algorithm and role.
2022-05-31 15:45:14 +02:00
Ondřej Surý
51a299d1fd Merge branch 'ondrej-unit-tests-refactoring' into 'main'
Give the unit tests a big overhaul and move all the unit tests to /tests/<libname>/

See merge request isc-projects/bind9!6243
2022-05-31 08:56:05 +00:00
Ondřej Surý
cd1f9c3d36 Add CHANGES note for [GL !6243] 2022-05-28 14:53:02 -07:00
Evan Hunt
2321cab4ee Exclude unit tests from gcov
Modify the .gitlab-ci.yml to match the previous lib/.*/tests/.* pattern
for excluding the unit tests from the gcov.
2022-05-28 14:53:02 -07:00
Evan Hunt
568f65cc56 Stop the unit tests from running twice
Move the libtest code into a 'libtest' subdirectory and make it
one of the SUBDIRS in the tests Makefile. having it at the top level
required having "." as one of the subdirs, and that caused the
unit tests to be executed twice.
2022-05-28 14:53:02 -07:00
Ondřej Surý
2c3b2dabe9 Move all the unit tests to /tests/<libname>/
The unit tests are now using a common base, which means that
lib/dns/tests/ code now has to include lib/isc/include/isc/test.h and
link with lib/isc/test.c and lib/ns/tests has to include both libisc and
libdns parts.

Instead of cross-linking code between the directories, move the
/lib/<foo>/test.c to /tests/<foo>.c and /lib/<foo>/include/<foo>test.h
to /tests/include/tests/<foo>.h and create a single libtest.la
convenience library in /tests/.

At the same time, move the /lib/<foo>/tests/ to /tests/<foo>/ (but keep
it symlinked to the old location) and adjust paths accordingly.  In few
places, we are now using absolute paths instead of relative paths,
because the directory level has changed.  By moving the directories
under the /tests/ directory, the test-related code is kept in a single
place and we can avoid referencing files between libns->libdns->libisc
which is unhealthy because they live in a separate Makefile-space.

In the future, the /bin/tests/ should be merged to /tests/ and symlink
kept, and the /fuzz/ directory moved to /tests/fuzz/.
2022-05-28 14:53:02 -07:00
Ondřej Surý
63fe9312ff Give the unit tests a big overhaul
The unit tests contain a lot of duplicated code and here's an attempt
to reduce code duplication.

This commit does several things:

1. Remove #ifdef HAVE_CMOCKA - we already solve this with automake
   conditionals.

2. Create a set of ISC_TEST_* and ISC_*_TEST_ macros to wrap the test
   implementations, test lists, and the main test routine, so we don't
   have to repeat this all over again.  The macros were modeled after
   libuv test suite but adapted to cmocka as the test driver.

   A simple example of a unit test would be:

    ISC_RUN_TEST_IMPL(test1) { assert_true(true); }

    ISC_TEST_LIST_START
    ISC_TEST_ENTRY(test1)
    ISC_TEST_LIST_END

    ISC_TEST_MAIN (Discussion: Should this be ISC_TEST_RUN ?)

   For more complicated examples including group setup and teardown
   functions, and per-test setup and teardown functions.

3. The macros prefix the test functions and cmocka entries, so the name
   of the test can now match the tested function name, and we don't have
   to append `_test` because `run_test_` is automatically prepended to
   the main test function, and `setup_test_` and `teardown_test_` is
   prepended to setup and teardown function.

4. Update all the unit tests to use the new syntax and fix a few bits
   here and there.

5. In the future, we can separate the test declarations and test
   implementations which are going to greatly help with uncluttering the
   bigger unit tests like doh_test and netmgr_test, because the test
   implementations are not declared static (see `ISC_RUN_TEST_DECLARE`
   and `ISC_RUN_TEST_IMPL` for more details.

NOTE: This heavily relies on preprocessor macros, but the result greatly
outweighs all the negatives of using the macros.  There's less
duplicated code, the tests are more uniform and the implementation can
be more flexible.
2022-05-28 14:52:56 -07:00
Ondřej Surý
3b757aa749 Merge branch 'ondrej-make-all-tasks-bound-to-thread' into 'main'
Make all tasks to be bound to a thread

See merge request isc-projects/bind9!6347
2022-05-25 14:45:32 +00:00
Ondřej Surý
1fe391fd40 Make all tasks to be bound to a thread
Previously, tasks could be created either unbound or bound to a specific
thread (worker loop).  The unbound tasks would be assigned to a random
thread every time isc_task_send() was called.  Because there's no logic
that would assign the task to the least busy worker, this just creates
unpredictability.  Instead of random assignment, bind all the previously
unbound tasks to worker 0, which is guaranteed to exist.
2022-05-25 16:04:51 +02:00
Ondřej Surý
9da46f3947 Merge branch 'ondrej-remove-dns_byaddr-API' into 'main'
Remove dns_lookup and unused functions in dns_byaddr

See merge request isc-projects/bind9!6348
2022-05-25 12:50:25 +00:00
Ondřej Surý
c06b661130 Remove dns_lookup and unused functions in dns_byaddr
Clean up unused functions from the dns_byaddr API and completely remove
the dns_lookup API.
2022-05-25 14:44:32 +02:00
Artem Boldariev
b6f1c242a4 Merge branch '3375-cids-352848-352849-handle-deadcode-flow-errors' into 'main'
Resolve: CID 352848, CID 352849: Control flow issues (DEADCODE)

Closes #3375

See merge request isc-projects/bind9!6351
2022-05-25 10:20:05 +00:00
Artem Boldariev
98f758ed4f CID 352848: split xfrin_start() and remove dead code
This commit separates TLS context creation code from xfrin_start() as
it has become too large and hard to follow into a new
function (similarly how it is done in dighost.c)

The dead code has been removed from the cleanup section of the TLS
creation code:

* there is no way 'tlsctx' can equal 'found';
* there is no way 'sess_cache' can be non-NULL in the cleanup section.

Also, it fixes a bug in the older version of the code, where TLS
client session context fetched from the cache would not get passed to
isc_nm_tlsdnsconnect().
2022-05-25 12:38:38 +03:00
Artem Boldariev
095b608412 CID 352849: refactor get_create_tls_context() within dighost.c
This commit removes dead code from cleanup handling part of the
get_create_tls_context().

In particular, currently:

* there is no way 'found_ctx' might equal 'ctx';
* there is no way 'session_cache' might equal a non-NULL value while
cleaning up after a TLS initialisation error.
2022-05-25 12:38:38 +03:00
Ondřej Surý
06b27a54f8 Merge branch '2801-unittest-isc-netmgr-s390x' into 'main'
Fix failures in isc netmgr_test on big endian machines

Closes #2801

See merge request isc-projects/bind9!6352
2022-05-24 18:22:54 +00:00
Petr Menšík
057438cb45 Fix failures in isc netmgr_test on big endian machines
Typing from libuv structure to isc_region_t is not possible, because
their sizes differ on 64 bit architectures. Little endian machines seems
to be lucky and still result in test passed. But big endian machine such
as s390x fails the test reliably.

Fix by directly creating the buffer as isc_region_t and skipping the
type conversion. More readable and still more correct.
2022-05-24 19:51:30 +02:00
Artem Boldariev
d50cb13d4d Merge branch '3064-avoid-periodic-interface-rescans' into 'main'
Disable periodic interface re-scans on Linux

Closes #3064

See merge request isc-projects/bind9!6111
2022-05-24 13:55:33 +00:00
Artem Boldariev
dad38620e5 Modify CHANGES [GL #3064]
Mention that "interface-interval" might be ignored if a reliable,
event-based mechanism to detect interface state changes is available.
2022-05-24 15:26:35 +03:00
Artem Boldariev
b58c4b8462 Disable periodic interface re-scans on modern platforms
This commit disables periodic interface re-scans timer on Linux where
a kernel-based dynamic interface mechanisms make it a thing of the
past in most cases.
2022-05-24 15:26:35 +03:00
Artem Boldariev
9da576c2ba Merge branch '3376-fix-openssl-1.1.0-unimplementable-SSL-SESSION-is-resumable' into 'main'
Resolve #3376: Do not provide a shim for SSL_SESSION_is_resumable()

Closes #3376

See merge request isc-projects/bind9!6346
2022-05-24 10:52:06 +00:00
Artem Boldariev
40be3c9263 Do not provide a shim for SSL_SESSION_is_resumable()
The recently added TLS client session cache used
SSL_SESSION_is_resumable() to avoid polluting the cache with
non-resumable sessions. However, it turned out that we cannot provide
a shim for this function across the whole range of OpenSSL versions
due to the fact that OpenSSL 1.1.0 does uses opaque pointers for
SSL_SESSION objects.

The commit replaces the shim for SSL_SESSION_is_resumable() with a non
public approximation of it on systems shipped with OpenSSL 1.1.0. It
is not turned into a proper shim because it does not fully emulate the
behaviour of SSL_SESSION_is_resumable(), but in our case it is good
enough, as it still helps to protect the cache from pollution.

For systems shipped with OpenSSL 1.0.X and derivatives (e.g. older
versions of LibreSSL), the provided replacement perfectly mimics the
function it is intended to replace.
2022-05-23 18:25:18 +03:00
Matthijs Mekking
31f937cb05 Merge branch '3341-servestale-extendederrors-test-failure' into 'main'
Tweak timings in serve-stale system test

Closes #3341

See merge request isc-projects/bind9!6276
2022-05-23 14:01:47 +00:00
Matthijs Mekking
f764cee136 Tweak timings in serve-stale system test
Give a little bit more time if we wait on a time out from the
authoritative (aka resolver failure), and give up after one try
(because the second attempt will likely result in a different EDE).
2022-05-23 14:23:07 +02:00
Matthijs Mekking
9a3dc23c66 Merge branch '3354-cid-352776-missing_lock' into 'main'
Fix CID 352776: Concurrent data access violations

Closes #3354

See merge request isc-projects/bind9!6315
2022-05-23 10:27:29 +00:00
Matthijs Mekking
888ec4e0d4 Require valid key for dst_key functions
Make sure that the key structure is valid when calling the following
functions:
- dst_key_setexternal
- dst_key_isexternal
- dst_key_setmodified
- dst_key_ismodified
2022-05-23 11:36:36 +02:00
Matthijs Mekking
1fa24d0afb Fix CID 352776: Concurrent data access violations
*** CID 352776:  Concurrent data access violations  (MISSING_LOCK)
/lib/dns/dst_api.c: 474 in dst_key_setmodified()
468     dst_key_isexternal(dst_key_t *key) {
469		return (key->external);
470     }
471
472     void
473     dst_key_setmodified(dst_key_t *key, bool value) {
>>>     CID 352776:  Concurrent data access violations  (MISSING_LOCK)
>>>     Accessing "key->modified" without holding lock
>>>	"dst_key.mdlock". Elsewhere, "dst_key.modified" is accessed with
>>>	"dst_key.mdlock" held 8 out of 11 times (8 of these accesses
>>>	strongly imply that it is necessary).
474		key->modified = value;
475     }
476
477     bool
478     dst_key_ismodified(dst_key_t *key) {
479		return (key->modified);
2022-05-23 11:36:13 +02:00
Artem Boldariev
0a19bb3bf3 Merge branch 'artem-client-tls-sessions-reuse' into 'main'
TLS session resumption support

See merge request isc-projects/bind9!6274
2022-05-20 17:53:33 +00:00
Artem Boldariev
90c52ca12b Dig: Do not call isc_nm_cancelread() for HTTP sockets
This commit ensures that isc_nm_cancelread() is not called from within
dig code for HTTP sockets, as these lack its implementation.

It does not have much sense to have it due to transactional nature of
HTTP.

Every HTTP request-response pair is represented by a virtual socket,
where read callback is called only when full DNS message is received
or when an error code is being passed there. That is, there is nothing
to cancel at the time of the call.
2022-05-20 20:18:40 +03:00
Artem Boldariev
9abb00bb5f Fix an abort in DoH (client-side) when writing on closing sock
The commit fixes a corner case in client-side DoH code, when a write
attempt is done on a closing socket (session).

The change ensures that the write call-back will be called with a
proper error code (see failed_send_cb() call in client_httpsend()).
2022-05-20 20:18:40 +03:00
Artem Boldariev
245f7cec2e Avoid aborting when uv_timer_start() is used on a closing socket
In such a case it will return UV_EINVAL (-EINVAL), leading to
aborting, as the code expects the function to succeed.
2022-05-20 20:18:40 +03:00
Artem Boldariev
aa8c258fba Modify CHANGES
Mention that TLS session resumption is now fully supported in the
client side code.
2022-05-20 20:18:38 +03:00
Artem Boldariev
35338b4105 Add SSL_SESSION_is_resumable() implementation shim
This commit adds SSL_SESSION_is_resumable() implementation if it is
missing.
2022-05-20 20:17:48 +03:00
Artem Boldariev
86465c1dac DoT: implement TLS client session resumption
This commit extends DoT code with TLS client session resumption
support implemented on top of the TLS client session cache.
2022-05-20 20:17:48 +03:00
Artem Boldariev
90bc13a5d5 TLS stream/DoH: implement TLS client session resumption
This commit extends TLS stream code and DoH code with TLS client
session resumption support implemented on top of the TLS client
session cache.
2022-05-20 20:17:45 +03:00
Artem Boldariev
987892d113 Extend TLS context cache with TLS client session cache
This commit extends TLS context cache with TLS client session cache so
that an associated session cache can be stored alongside the TLS
context within the context cache.
2022-05-20 20:13:20 +03:00
Artem Boldariev
4ef40988f3 Add TLS client session cache implementation
This commit adds an implementation of a client TLS session cache. TLS
client session cache is an object which allows efficient storing and
retrieval of previously saved TLS sessions so that they can be
resumed. This object is supposed to be a foundation for implementing
TLS session resumption - a standard technique to reduce the cost of
re-establishing a connection to the remote server endpoint.

OpenSSL does server-side TLS session caching transparently by
default. However, on the client-side, a TLS session to resume must be
manually specified when establishing the TLS connection. The TLS
client session cache is precisely the foundation for that.
2022-05-20 20:13:20 +03:00
Ondřej Surý
7d59a6f0ed Merge branch '3344-threadsanitizer-data-race-in-isc__nm_tcpdns_send' into 'main'
Move setting the sock->write_timeout to the async_*send

Closes #3344

See merge request isc-projects/bind9!6320
2022-05-19 20:37:16 +00:00
Ondřej Surý
61117840c1 Move setting the sock->write_timeout to the async_*send
Setting the sock->write_timeout from the TCP, TCPDNS, and TLSDNS send
functions could lead to (harmless) data race when setting the value for
the first time when the isc_nm_send() function would be called from
thread not-matching the socket we are sending to.  Move the setting the
sock->write_timeout to the matching async function which is always
called from the matching thread.
2022-05-19 22:36:47 +02:00
Ondřej Surý
c0d62c9287 Merge branch '3371-check-for-__attribute__-fallthrough-support-is-sometimes-incorrect' into 'main'
Use C2x [[fallthrough]] when supported by LLVM/clang

Closes #3371

See merge request isc-projects/bind9!6338
2022-05-19 20:01:06 +00:00
Ondřej Surý
14c8d43863 Use C2x [[fallthrough]] when supported by LLVM/clang
Clang added support for the gcc-style fallthrough
attribute (i.e. __attribute__((fallthrough))) in version 10.  However,
__has_attribute(fallthrough) will return 1 in C mode in older versions,
even though they only support the C++11 fallthrough attribute. At best,
the unsupported attribute is simply ignored; at worst, it causes errors.

The C2x fallthrough attribute has the advantages of being supported in
the broadest range of clang versions (added in version 9) and being easy
to check for support. Use C2x [[fallthrough]] attribute if possible, and
fall back to not using an attribute for clang versions that don't have
it.

Courtesy of Joshua Root
2022-05-19 21:40:24 +02:00
Michal Nowak
c9aca34b1e Merge tag 'v9_19_1'
BIND 9.19.1
2022-05-19 10:55:42 +02:00
Evan Hunt
0e0d39bfdb Merge branch 'each-resolver-hash-tables' into 'main'
Use self-resizing hash tables for resolver

See merge request isc-projects/bind9!6271
2022-05-19 07:49:11 +00:00
Evan Hunt
be841577f1 CHANGES for [GL !6271] 2022-05-19 00:48:06 -07:00
Evan Hunt
6936db2f59 Always use the number of CPUS for resolver->ntasks
Since the fctx hash table is now self-resizing, and resolver tasks are
selected to match the thread that created the fetch context, there
shouldn't be any significant advantage to having multiple tasks per CPU;
a single task per thread should be sufficient.

Additionally, the fetch context is always pinned to the calling netmgr
thread to minimize the contention just to coalesced fetches - if two
threads starts the same fetch, it will be pinned to the first one to get
the bucket.
2022-05-19 09:27:33 +02:00
Evan Hunt
857f3bede3 Use automatically-resizing hash table for resolver buckets
Replace the statically-sized hash table used for the resolver
fetch contexts with an isc_ht_t.
2022-05-19 09:27:28 +02:00
Evan Hunt
1595304312 Use automatically-resizing hash table for fetches-per-zone
Replace the statically-sized hash table used for fcount_incr()
and fcount_decr() with an isc_ht_t.
2022-05-19 09:27:23 +02:00
Evan Hunt
5731a3d7f0 Merge branch '3350-rndc-dnssec-checkds-doc' into 'main'
specify time format in the documentation for 'rdnc dnssec -checkds'

Closes #3350

See merge request isc-projects/bind9!6302
2022-05-18 22:28:39 +00:00
Evan Hunt
83f9466d61 specify time format in the documentation for 'rdnc dnssec -checkds'
also clarified the writing in the surrounding paragraph.
2022-05-18 15:24:54 -07:00
Michal Nowak
da7d0a7ea3 Merge branch 'mnowak/fix-typo-in-ednscompliance-test' into 'main'
Fix typo in ednscompliance test

See merge request isc-projects/bind9!6323
2022-05-18 17:15:04 +00:00
Michal Nowak
9de2c06a21 Fix typo in ednscompliance test
Caused by ba0313e649, an incomplete fix of
spelling errors.
2022-05-18 19:13:30 +02:00