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

35845 Commits

Author SHA1 Message Date
Ondřej Surý
ae01ec2823 Don't use reference counting in isc_timer unit
The reference counting and isc_timer_attach()/isc_timer_detach()
semantic are actually misleading because it cannot be used under normal
conditions.  The usual conditions under which is timer used uses the
object where timer is used as argument to the "timer" itself.  This
means that when the caller is using `isc_timer_detach()` it needs the
timer to stop and the isc_timer_detach() does that only if this would be
the last reference.  Unfortunately, this also means that if the timer is
attached elsewhere and the timer is fired it will most likely be
use-after-free, because the object used in the timer no longer exists.

Remove the reference counting from the isc_timer unit, remove
isc_timer_attach() function and rename isc_timer_detach() to
isc_timer_destroy() to better reflect how the API needs to be used.

The only caveat is that the already executed event must be destroyed
before the isc_timer_destroy() is called because the timer is no longet
attached to .ev_destroy_arg.
2022-04-02 01:23:15 +02:00
Ondřej Surý
635fbc7f93 Merge branch 'ondrej-remove-task-privileged-mode' into 'main'
Remove task privileged mode

Closes #3253

See merge request isc-projects/bind9!6049
2022-04-01 23:01:48 +00:00
Ondřej Surý
e71e2d06f5 Add CHANGES note for [GL #3253] 2022-04-01 23:56:36 +02:00
Ondřej Surý
30e0fd942b Remove task privileged mode
Previously, the task privileged mode has been used only when the named
was starting up and loading the zones from the disk as the "first" thing
to do.  The privileged task was setup with quantum == 2, which made the
taskmgr/netmgr spin around the privileged queue processing two events at
the time.

The same effect can be achieved by setting the quantum to UINT_MAX (e.g.
practically unlimited) for the loadzone task, hence the privileged task
mode was removed in favor of just processing all the events on the
loadzone task in a single task_run().
2022-04-01 23:55:26 +02:00
Ondřej Surý
0519a5bfe9 Merge branch 'ondrej-cleanup-extra-memory-context-in-dns_zone' into 'main'
Cleanup the tasks and memory contexts in dns_zone

Closes #3226 and #3159

See merge request isc-projects/bind9!6004
2022-04-01 21:54:55 +00:00
Ondřej Surý
ae0898e328 Add CHANGES note for [GL #3226] 2022-04-01 23:51:12 +02:00
Ondřej Surý
62a72211aa Remove isc_pool API
Since the last user of the isc_pool API is gone, remove the whole
isc_pool API.
2022-04-01 23:50:34 +02:00
Ondřej Surý
2bc7303af2 Use isc_nm_getnworkers to manage zone resources
Instead of passing the number of worker to the dns_zonemgr manually,
get the number of nm threads using the new isc_nm_getnworkers() call.

Additionally, remove the isc_pool API and manage the array of memory
context, zonetasks and loadtasks directly in the zonemgr.
2022-04-01 23:50:34 +02:00
Ondřej Surý
2707d0eeb7 Set hard thread affinity for each zone
After switching to per-thread resources in the zonemgr, the performance
was decreased because the memory context, zonetask and loadtask was
picked from the pool at random.

Pin the zone to single threadid (.tid) and align the memory context,
zonetask and loadtask to be the same, this sets the hard affinity of the
zone to the netmgr thread.
2022-04-01 23:50:34 +02:00
Ondřej Surý
8b4ba366dd Remove the zone counting in the named
The zone counting in the named was used to properly size the zonemgr
resources (memory contexts, zonetasks and loadtasks).  Since this is no
longer the case, remove the whole zone counting from named.
2022-04-01 23:50:34 +02:00
Ondřej Surý
a94678ff77 Create per-thread task and memory context for zonemgr
Previously, the zonemgr created 1 task per 100 zones and 1 memory
context per 1000 zones (with minimum 10 tasks and 2 memory contexts) to
reduce the contention between threads.

Instead of reducing the contention by having many resources, create a
per-nm_thread memory context, loadtask and zonetask and spread the zones
between just per-thread resources.

Note: this commit alone does decrease performance when loading the zone
by couple seconds (in case of 1M zone) and thus there's more work in
this whole MR fixing the performance.
2022-04-01 23:50:34 +02:00
Ondřej Surý
abb5e9a575 Merge branch 'ondrej-repair-isc_task_purgeevent' into 'main'
Repair isc_task_purgeevent(), clean isc_task_unsend{,range}()

Closes #3252

See merge request isc-projects/bind9!6053
2022-04-01 21:50:04 +00:00
Ondřej Surý
a7cd0868a2 Add CHANGES note for [GL #3252] 2022-04-01 23:45:40 +02:00
Ondřej Surý
40971b22e7 Stop the zone timer before detaching the timer
Previously, the zone timer was not stopped before detaching the timer.
This could lead to a data race where the timer post_event() could fire
before the timer was detached, but then the event would be executed
after the zone was already destroyed.

This was not noticed before because the timing or the ordering of the
actions were different, but it was causing assertion failures in the
libns tests now.

Properly stop the zone timer before detaching the timer object from the
dns_zone.
2022-04-01 23:45:23 +02:00
Ondřej Surý
87c4c24cde Set quantum to infinity for the zone loading task
When we are loading the zones, set the quantum to UINT_MAX, which makes
task_run process all tasks at once.  After the zone loading is finished
the quantum will be dropped to 1 to not block server when we are loading
new zones after reconfiguration.
2022-04-01 23:45:23 +02:00
Ondřej Surý
15ea6f002f Add isc_task_setquantum() and use it for post-init zone loading
Add isc_task_setquantum() function that modifies quantum for the future
isc_task_run() invocations.

NOTE: The current isc_task_run() caches the task->quantum into a local
variable and therefore the current event loop is not affected by any
quantum change.
2022-04-01 23:45:23 +02:00
Ondřej Surý
c17eee034b Remove isc_task_purge() and isc_task_purgerange()
The isc_task_purge() and isc_task_purgerange() were now unused, so sweep
the task.c file.  Additionally remove unused ISC_EVENTATTR_NOPURGE event
attribute.
2022-04-01 23:45:23 +02:00
Ondřej Surý
9f7ba679ac Purge the .resched_event in dns_cache
Instead of sweeping the cache cleaner tasks, purge the more specific
cleaner.resched_event event.
2022-04-01 23:45:23 +02:00
Ondřej Surý
48b2a5df97 Keep the list of scheduled events on the timer
Instead of searching for the events to purge, keep the list of scheduled
events on the timer list and purge the events that we have scheduled.
2022-04-01 23:45:23 +02:00
Ondřej Surý
17aed2f895 Repair isc_task_purgeevent(), clean isc_task_unsend{,range}()
The isc_task_purgerange() was walking through all events on the task to
find a matching task.  Instead use the ISC_LINK_LINKED to find whether
the event is active.

Cleanup the related isc_task_unsend() and isc_task_unsendrange()
functions that were not used anywhere.
2022-04-01 23:45:23 +02:00
Ondřej Surý
fe4cd556b3 Merge branch '3243-mr-6035-fix' into 'main'
Turn isc_hash_bits32() into static online function

Closes #3243

See merge request isc-projects/bind9!6050
2022-04-01 21:32:48 +00:00
Ondřej Surý
96030f23a4 Help gcovr find isc/hash.h when included from lib/dns
Similar to other tweaks, copy the lib/isc/include/isc/hash.h to lib/dns
to help gcovr find the file.
2022-04-01 23:05:43 +02:00
Ondřej Surý
b84c9b2608 Turn isc_hash_bits32() into static online function
Adding extra val & 0xffff in the isc_hash_bits32() macros in the hotpath
has significantly reduced the performance.  Turn the macro into static
inline function matching the previous hash_32() function used to compute
hashval matching the hashtable->bits.
2022-04-01 23:04:24 +02:00
Evan Hunt
b1e966efaa Merge branch '3250-resolver-test-non-querytrace' into 'main'
fix resolver test when built without --enable-querytrace

Closes #3250

See merge request isc-projects/bind9!6064
2022-04-01 17:16:09 +00:00
Evan Hunt
5319d8adea fix resolver test when built without --enable-querytrace
a test case in the 'resolver' system test was reliant on
logged output that would only be present when query tracing
was enabled, as in developer builds. that test case is now
disabled when query tracing is not available. Thanks to
Anton Castelli.
2022-04-01 09:54:44 -07:00
Artem Boldariev
7dd8ab7336 Merge branch '3236-fix-debian9-no-SSL_CTX_set1_cert_store' into 'main'
Implement shim for SSL_CTX_set1_cert_store() (affects Debian 9)

Closes #3236

See merge request isc-projects/bind9!6054
2022-04-01 14:28:09 +00:00
Artem Boldariev
3edf7a9fe7 Implement shim for SSL_CTX_set1_cert_store() (affects Debian 9)
This commit implements a shim for SSL_CTX_set1_cert_store() for
OpenSSL/LibreSSL versions where it is not available.
2022-04-01 16:33:43 +03:00
Arаm Sаrgsyаn
d8cd4460bf Merge branch '3145-dig-+nssearch-does-not-exit-until-interrupted' into 'main'
Fix "dig +nssearch" indefinitely hanging issue

Closes #3145

See merge request isc-projects/bind9!6007
2022-04-01 11:51:17 +00:00
Aram Sargsyan
4477f71868 Synchronze udp_ready() and tcp_connected() functions entry behavior
The `udp_ready()` and `tcp_connected()` functions in dighost.c are
used for similar purposes for UDP and TCP respectively.

Synchronize the `udp_ready()` function entry code to behave like
`tcp_connected()` by adding input validation, debug messages and
early exit code when `cancel_now` is `true`.
2022-04-01 10:56:27 +00:00
Aram Sargsyan
3a5793ece2 Add CHANGES note for [GL #3145] 2022-04-01 10:56:27 +00:00
Aram Sargsyan
7d360bd05e Fix "dig +nssearch" indefinitely hanging issue
When finishing the NSSEARCH task and there is no more followup
lookups to start, dig does not destroy the last lookup, which
causes it to hang indefinitely.

Rename the unused `first_pass` member of `dig_query_t` to `started`
and make it `true` in the first callback after `start_udp()` or
`start_tcp()` of the query to indicate that the query has been
started.

Create a new `check_if_queries_done()` function to check whether
all of the queries inside a lookup have been started and finished,
or canceled.

Use the mentioned function in the TRACE code block in `recv_done()`
to check whether the current query is the last one in the lookup and
cancel the lookup in that case to free the resources.
2022-04-01 10:56:27 +00:00
Mark Andrews
5b76f0f80e Merge branch '3191-issue-45178-in-oss-fuzz-bind9-dns_master_load_fuzzer-integer-overflow-in-generate' into 'main'
Resolve "Issue 45178 in oss-fuzz: bind9:dns_master_load_fuzzer: Integer-overflow in generate"

Closes #3191

See merge request isc-projects/bind9!5928
2022-04-01 10:31:45 +00:00
Evan Hunt
bd814b79d4 add a system test for $GENERATE with an integer overflow
the line "$GENERATE 19-28/2147483645 $ CNAME x" should generate
a single CNAME with the owner "19.example.com", but prior to the
overflow bug it generated several CNAMEs, half of them with large
negative values.

we now test for the bugfix by using "named-checkzone -D" and
grepping for a single CNAME in the output.
2022-04-01 07:56:52 +00:00
Evan Hunt
2261c853b5 update shell syntax
clean up the shell syntax in the checkzone test prior to adding
a new test.
2022-04-01 07:56:52 +00:00
Mark Andrews
9039aad0f8 Add test case for issue-45178 2022-04-01 07:56:52 +00:00
Mark Andrews
5abdee9004 Prevent arithmetic overflow of 'i' in master.c:generate
the value of 'i' in generate could overflow when adding 'step' to
it in the 'for' loop.  Use an unsigned int for 'i' which will give
an additional bit and prevent the overflow.  The inputs are both
less than 2^31 and and the result will be less than 2^32-1.
2022-04-01 07:56:52 +00:00
Tony Finch
3dd8af9aa8 Merge branch '3209-notauth-subdomain' into 'main'
NOTAUTH errors should log the zone from the query not the nearest match

Closes #3209

See merge request isc-projects/bind9!5982
2022-03-30 12:12:08 +00:00
Tony Finch
84c4eb02e7 Log "not authoritative for update zone" more clearly
Ensure the update zone name is mentioned in the NOTAUTH error message
in the server log, so that it is easier to track down problematic
update clients. There are two cases: either the update zone is
unrelated to any of the server's zones (previously no zone was
mentioned); or the update zone is a subdomain of one or more of the
server's zones (previously the name of the irrelevant parent zone was
misleadingly logged).

Closes #3209
2022-03-30 12:50:30 +01:00
Ondřej Surý
8594cd00bc Merge branch '3230-remove-task-exclusive-mode-from-ns_clientmgr' into 'main'
Remove task exclusive mode from ns_clientmgr

Closes #3230

See merge request isc-projects/bind9!6024
2022-03-30 11:18:08 +00:00
Ondřej Surý
a243860562 Add CHANGES mode for [GL #3230] 2022-03-30 12:46:09 +02:00
Ondřej Surý
4f74e1010e Remove task exclusive mode from ns_clientmgr
The .lock, .exiting and .excl members were not using for anything else
than starting task exclusive mode, setting .exiting to true and ending
exclusive mode.

Remove all the stray members and dead code eliminating the task
exclusive mode use from ns_clientmgr.
2022-03-30 12:41:55 +02:00
Ondřej Surý
003e4b00c6 Merge branch '3213-remove-exclusive-task-mode-from-dns_adb' into 'main'
refactor ADB

Closes #3213

See merge request isc-projects/bind9!6033
2022-03-30 10:41:30 +00:00
Evan Hunt
2c419b7abc Add CHANGES note for [GL #3213] 2022-03-30 10:14:09 +02:00
Evan Hunt
199be183fa Add detailed ADB and entry attach/detach tracing
To turn on detailed debug tracing of dns_adb and dns_adbentry
reference counting, #define ADB_TRACE at the top of adb.c. This
is off by default.
2022-03-30 10:12:25 +02:00
Evan Hunt
d48d8e1cf0 Refactor ADB reference counting, shutdown and locking
The ADB previously used separate reference counters for internal
and external references, plus additional counters for ABD find
and namehook objects, and used all these counters to coordinate
its shutdown process, which was a multi-stage affair involving
a sequence of control events.

It also used a complex interlocking set of static functions for
referencing, deferencing, linking, unlinking, and cleaning up various
internal objects; these functions returned boolean values to their
callers to indicate what additional processing was needed.

The changes in the previous two commits destabilized this fragile
system in a way that was difficult to recover from, so in this commit
we refactor all of it. The dns_adb and dns_adbentry objects now use
conventional attach and detach functions for reference counting, and
the shutdown process is much more straightforward.  Instead of
handling shutdown asynchronously, we can just destroy the ADB when
references reach zero

In addition, ADB locking has been simplified. Instead of a
single `find_{name,entry}_and_lock()` function which searches for
a name or entry's hash bucket, locks it, and then searches for the
name or entry in the bucket, we now use one function to find the
bucket (leaving it to the caller to do the locking) and another
find the name or entry.  Instead of locking the entire ADB when
modifying hash tables, we now use read-write locks around the
specific hash table. The only remaining need for adb->lock
is when modifying the `whenshutdown` list.

Comments throughout the module have been improved.
2022-03-30 10:12:25 +02:00
Evan Hunt
76bcb4d16b Refactor how ADB names and entries are stored in the dns_adb
Replace adb->{names,entries} and related arrays (indexed by hashed
bucket) with a isc_ht hash tables storing the new struct
adb{name,entry}bucket_t that wraps all the variables that were
originally stored in arrays indexed by "bucket" number stored directly
in the struct dns_adb.

Previously, the task exclusive mode has been used to grow the internal
arrays used to store the named and entries objects.  The isc_ht hash
tables are now protected by the isc_rwlock instead and thus the usage of
the task exclusive mode has been removed from the dns_adb.

Co-authored-by: Ondřej Surý <ondrej@isc.org>
2022-03-30 10:09:18 +02:00
Evan Hunt
6e11211ac6 minor pre-refactoring cleanups
the use of "result" as a variable name for a boolean return value
was confusing; all 'result' variables that are not isc_result_t
have been renamed to 'ret'.

The static function print_dns_name() was a duplicate of
dns_name_print(), so it has been replaced with that.

Changed INSIST to REQUIRE where appropriate, and added NULL
initialization for pointer variables.
2022-03-30 09:55:00 +02:00
Ondřej Surý
ddf051df65 Merge branch 'ondrej-remove-multiple-application-contexts' into 'main'
Remove isc_appctx_t use in dns_client

See merge request isc-projects/bind9!6041
2022-03-29 22:24:20 +00:00
Ondřej Surý
bbea0be767 Add CHANGES note for [GL !6041] 2022-03-29 14:14:49 -07:00
Ondřej Surý
3a650d973f Remove isc_appctx_t use in dns_client
The use of isc_appctx_t in dns_client was used to wait for
dns_client_startresolve() to finish the processing (the resolve_done()
task callback).

This has been replaced with standard bool+cond+lock combination removing
the need of isc_appctx_t altogether.
2022-03-29 14:14:49 -07:00