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

37813 Commits

Author SHA1 Message Date
Artem Boldariev
f18a9b3743 TLS: add isc__nmsocket_timer_running() support
This commit adds isc__nmsocket_timer_running() support to the generic
TLS code in order to make it more compatible with TCP.
2022-12-20 21:24:44 +02:00
Artem Boldariev
c0808532e1 TLS: isc_nm_bad_request() and isc__nmsocket_reset() support
This commit adds implementations of isc_nm_bad_request() and
isc__nmsocket_reset() to the generic TLS stream code in order to make
it more compatible with TCP code.
2022-12-20 21:24:44 +02:00
Ondřej Surý
858e06e58d Merge branch 'ondrej-refactor-isc_buffer-for-dnsstream' into 'main'
Change the isc_buffer_reserve() to take just buffer pointer

See merge request isc-projects/bind9!7235
2022-12-20 19:22:12 +00:00
Artem Boldariev
94e650ce89 Use 'restrict' and 'const' for 'isc_buffer_t'
The purpose of this commit is to aid compiler in generating better
code when working with `isc_buffer_t` objects by using restricted
pointers (and, to a lesser extent, 'const' modifier for read-only
arguments).

This way we, basically, instruct the compiler that the members of
structured passed by pointers into the functions can be treated as
local variables in the scope of a function. That should reduce the
number of load/store operations emitted by compilers when accessing
objects (e.g. 'isc_buffer_t') via pointers.
2022-12-20 21:01:27 +02:00
Ondřej Surý
460afcda18 Add isc_buffer_trycompact() function needed for StreamDNS
Add isc_buffer_trycompact() that's an optimization; it will compact the
buffer only when the remaining length is smaller than used length.
2022-12-20 19:13:48 +01:00
Ondřej Surý
e6062ee3ae Add isc_buffer_setmctx() and isc_buffer_clearmctx() function
Add two extra functions needed by StreamDNS:

1. isc_buffer_setmctx() sets the buffer internal memory context, so we
   can use isc_buffer_reserve() on the buffer.  For this, we also need
   to track whether the .base was dynamically allocated or not.  This
   needs to be called after isc_buffer_init() and before first
   isc_buffer_reserve() call.

2. isc_buffer_clearmctx() clears the buffer internal memory context, and
   frees any dynamically allocated buffer.  This needs to be called
   after the last isc_buffer_reserve() call and before calling the
   isc_buffer_invalidate()
2022-12-20 19:13:48 +01:00
Ondřej Surý
8e3a86f6dd Make the isc_buffer unit header-only
The isc_buffer is often used in the hot-path, so make it header-only
implementation.
2022-12-20 19:13:48 +01:00
Ondřej Surý
302bc50340 Cleanup the isc_buffer_reserve() usage in put*() helpers
There are couple places where we use putstr(), putmem(), ... helpers
that tries to reserve space and only if successful puts the data onto
the buffer.  Cleanup the double reference as it's not needed there.
2022-12-20 19:13:48 +01:00
Ondřej Surý
2ddea1e41c Add a static pre-allocated buffer to isc_buffer_t
When the buffer is allocated via isc_buffer_allocate() and the size is
smaller or equal ISC_BUFFER_STATIC_SIZE (currently 512 bytes), the
buffer will be allocated as a flexible array member in the buffer
structure itself instead of allocating it on the heap.  This should help
when the buffer is used on the hot-path with small allocations.
2022-12-20 19:13:48 +01:00
Ondřej Surý
6bd2b34180 Enable auto-reallocation for all isc_buffer_allocate() buffers
When isc_buffer_t buffer is created with isc_buffer_allocate() assume
that we want it to always auto-reallocate instead of having an extra
call to enable auto-reallocation.
2022-12-20 19:13:48 +01:00
Ondřej Surý
135ec7a0f0 Remove single use isc_buffer_putdecint() function
The isc_buffer_putdecint() could be easily replaced with
isc_buffer_printf() with just a small overhead of calling vsnprintf()
twice instead once.  This is not on a hot-path (dns_catz unit), so we
can ignore the overhead and instead have less single-use code in favor
of using reusable more generic function.
2022-12-20 19:13:48 +01:00
Ondřej Surý
2a94123d5b Refactor the isc_buffer_{get,put}uintN, add isc_buffer_peekuintN
The Stream DNS implementation needs a peek methods that read the value
from the buffer, but it doesn't advance the current position.  Add
isc_buffer_peekuintX methods, refactor the isc_buffer_{get,put}uintN
methods to modern integer types, and move the isc_buffer_getuintN to the
header as static inline functions.
2022-12-20 19:13:48 +01:00
Ondřej Surý
a1d45685e6 Move and extend the uint8_t low-endian to uint{32,64}t to endian.h
Move the U8TO{32,64}_LE and U{32,64}TO8_LE macros to endian.h and extend
the macros for 16-bit and Big-Endian variants.

Use the macros both in isc_siphash (LE) and isc_buffer (BE) units.
2022-12-20 19:13:48 +01:00
Ondřej Surý
aea251f3bc Change the isc_buffer_reserve() to take just buffer pointer
The isc_buffer_reserve() would be passed a reference to the buffer
pointer, which was unnecessary as the pointer would never be changed
in the current implementation.  Remove the extra dereference.
2022-12-20 19:13:48 +01:00
Ondřej Surý
9fd83ea971 Merge branch '3178-dispatch-race' into 'main'
Fix the thread safety in the dns_dispatch unit

Closes #3178

See merge request isc-projects/bind9!7025
2022-12-19 12:07:12 +00:00
Ondřej Surý
2df311eb21 Add CHANGES and release note for [GL #3178] and [GL #3636] 2022-12-19 11:42:50 +01:00
Ondřej Surý
6f317f27ea Fix the thread safety in the dns_dispatch unit
The dispatches are not thread-bound, and used freely between various
threads (see the dns_resolver and dns_request units for details).

This refactoring make sure that all non-const dns_dispatch_t and
dns_dispentry_t members are accessed under a lock, and both object now
track their internal state (NONE, CONNECTING, CONNECTED, CANCELED)
instead of guessing the state from the state of various struct members.

During the refactoring, the artificial limit DNS_DISPATCH_SOCKSQUOTA on
UDP sockets per dispatch was removed as the limiting needs to happen and
happens on in dns_resolver and limiting the number of UDP sockets
artificially in dispatch could lead to unpredictable behaviour in case
one dispatch has the limit exhausted by others are idle.

The TCP artificial limit of DNS_DISPATCH_MAXREQUESTS makes even less
sense as the TCP connections are only reused in the dns_request API
that's not a heavy user of the outgoing connections.

As a side note, the fact that UDP and TCP dispatch pretends to be same
thing, but in fact the connected UDP is handled from dns_dispentry_t and
dns_dispatch_t acts as a broker, but connected TCP is handled from
dns_dispatch_t and dns_dispatchmgr_t acts as a broker doesn't really
help the clarity of this unit.

This refactoring kept to API almost same - only dns_dispatch_cancel()
and dns_dispatch_done() were merged into dns_dispatch_done() as we need
to cancel active netmgr handles in any case to not leave dangling
connections around.  The functions handling UDP and TCP have been mostly
split to their matching counterparts and the dns_dispatch_<function>
functions are now thing wrappers that call <udp|tcp>_dispatch_<function>
based on the socket type.

More debugging-level logging was added to the unit to accomodate for
this fact.
2022-12-19 11:42:13 +01:00
Ondřej Surý
5b79127780 Merge branch '3712-fix-reference-counting-in-dns_adb-get_attached_entry-v2' into 'main'
Fix reference counting in get_attached_entry (again)

Closes #3712

See merge request isc-projects/bind9!7250
2022-12-16 20:49:49 +00:00
Ondřej Surý
32ff134eeb Fix reference counting in get_attached_entry (again)
When get_attached_entry() encounters entry that would be expired, it
needs to get reference to the entry before calling maybe_expire_entry(),
so the ADB entry doesn't get destroyed inside the its own lock.

This creeped into the code base again during review, so I am adding
an extra comment to prevent this.
2022-12-16 21:48:43 +01:00
Tom Krizek
096b047628 Merge branch 'tkrizek/danger-backports' into 'main'
Check backport workflow in danger CI

See merge request isc-projects/bind9!7243
2022-12-16 13:18:01 +00:00
Tom Krizek
e8a5ebaee5 danger: remove obsolete check for cherry pick msg
With proper backport commit detection, this check has been made
redundant.
2022-12-16 13:37:12 +01:00
Tom Krizek
c617f97784 danger: check backport commits for original commit IDs
A full backport must have all the commit from the original MR and the
original commit IDs must be referenced in the backport commit messages.

If the criteria above is not met, the MR should be marked as a partial
backport. In that case, any discrepencies are only logged as informative
messages rather than failures.
2022-12-16 13:37:12 +01:00
Tom Krizek
89530f1a1c danger: check that original MR has been merged
When checking a backport MR, ensure that the original MR has been merged
already. This is vital for followup checks that verify commit IDs from
original commits are present in backport commit messages.
2022-12-16 13:37:12 +01:00
Tom Krizek
12e0b05738 danger: check backport links to the original MR
When doing archeology, it is much easier to find stuff if it's properly
linked. This check ensures that backport MR are linked to their original
MR via a "Backport of !XXXX" message.

The regular expression is fairly broad and has been tested to accept the
following variants of the message:
Backport of MR !XXXX
Backport of: !XXXX
backport of mr !XXXX
Backport of   !XXXX
Backport of https://gitlab.isc.org/isc-projects/bind9/-/merge_requests/XXXX
2022-12-16 13:37:12 +01:00
Tom Krizek
14b027cf83 danger: ensure target branch is in the MR title
Having the MR title clearly marked in its title can be very useful when
looking through older issues/MRs.

This check also ensures that the version from the version label matches
the proper version branch (i.e. v9.16 must be marked with [v9_16]).
2022-12-16 13:37:11 +01:00
Tom Krizek
1c0c1ba8b9 danger: support partial backport label
Treat the Backport::Partial label as a backport as well.
2022-12-16 13:37:10 +01:00
Tony Finch
94f2da42e0 Merge branch '3740-rpz-reconfig' into 'main'
A couple of RPZ options were not reconfigured as expected

Closes #3740

See merge request isc-projects/bind9!7230
2022-12-16 09:48:35 +00:00
Tony Finch
d8a3d328db A couple of RPZ options were not reconfigured as expected
[bug]	Changes to the RPZ response-policy min-update-interval
	and add-soa options now take effect as expected when
	named is reconfigured. [GL #3740]
2022-12-15 16:21:38 +00:00
Ondřej Surý
1af9aa849e Merge branch '3739-adb-cleans-overzealously-under-memory-pressure' into 'main'
Exclude the ADB hashmaps from ADB overmem accounting

Closes #3739

See merge request isc-projects/bind9!7228
2022-12-15 15:44:01 +00:00
Ondřej Surý
11df7f02fd Add CHANGES and release note for [GL #3739] 2022-12-15 16:15:39 +01:00
Ondřej Surý
0b661b6f95 Don't expire fresh ADB names and entries
The overmem cleaning in ADB could become overzealous and clean fresh ADB
names and entries.  Add a safety check to not clean any ADB names and
entries that are below ADB_CACHE_MINIMUM threshold.
2022-12-15 16:15:19 +01:00
Ondřej Surý
59dee0b078 Exclude the ADB hashmaps from ADB overmem accounting
The ADB overmem accounting would include the memory used by hashtables
thus vastly reducing the space that can be used for ADB names and
entries when the hashtables would grow.  Create own memory context for
the ADB names and entries hash tables.
2022-12-15 16:14:16 +01:00
Ondřej Surý
f74841fab7 Merge branch 'ondrej-fix-data-race-in-dns_adb' into 'main'
Lock the adbname and adbentry prior to unlocking hash locks

See merge request isc-projects/bind9!7216
2022-12-15 14:58:56 +00:00
Ondřej Surý
a27ea1bba0 Lock the adbname and adbentry prior to unlocking hash locks
There was a datarace that could expire a freshly created ADB names and
entries between the return from get_attached_{name,entry} and locking it
again.  Lock the ADB name and ADB entry inside the hash table lock, so
they won't get expired until the full initialization has been complete.
2022-12-15 15:19:22 +01:00
Arаm Sаrgsyаn
b8a915b0ac Merge branch '3742-catz-update-log-incorrect-soa-serial-representation' into 'main'
Fix an incorrect SOA serial representation in catz

Closes #3742

See merge request isc-projects/bind9!7229
2022-12-15 13:51:18 +00:00
Aram Sargsyan
ac7149aa88 Add a CHANGES note for [GL #3742] 2022-12-15 13:27:09 +00:00
Aram Sargsyan
72b1760ea6 Fix logging a uint32_t SOA serial value in dns_catz_update_from_db()
The dns_catz_update_from_db() function prints serial number as a signed
number (with "%d" in the format string), but the `vers` variable's type
is 'uint32_t'. This breaks serials bigger than 2^31.

Use PRIu32 instead of "d" in the format string.
2022-12-15 13:24:58 +00:00
Aram Sargsyan
de232ab446 Add big SOA serial logging check into the catz system test
Check that the SOA serial numbers printed when updating a catalog zone
is represented correctly for numbers bigger than 2^31.
2022-12-15 13:24:58 +00:00
Arаm Sаrgsyаn
3600e0f491 Merge branch 'aram/dns_adb_getcookie-cleanup' into 'main'
Clean up and refactor dns_adb_getcookie()

See merge request isc-projects/bind9!7211
2022-12-15 13:22:54 +00:00
Aram Sargsyan
03442d922b Clean up and refactor dns_adb_getcookie()
The dns_adb_getcookie() doesn't use the 'adb' parameter, remove it.

Refactor the dns_adb_getcookie() function to just return the size of
the cookie when the caller passes 'NULL' as the 'cookie' argument.
2022-12-15 12:34:26 +00:00
Ondřej Surý
5266444e35 Merge branch 'ondrej-use-isc_hashmap-for-zonemgr_keymgmt' into 'main'
Replace zonemgr_keymgmt own hash table with isc_hashmap

See merge request isc-projects/bind9!7191
2022-12-14 18:39:41 +00:00
Ondřej Surý
578de673b1 Replace zonemgr_keymgmt own hash table with isc_hashmap
Instead of maintaining own hashtable implementation for zonemgr_keymgmt,
use isc_hashmap that already can resize (grow and shrink).
2022-12-14 19:37:07 +01:00
Ondřej Surý
ea88da8692 Merge branch 'ondrej-add-more-logging-to-netmgr' into 'main'
Add internal logging functions to the netmgr

See merge request isc-projects/bind9!7233
2022-12-14 18:35:17 +00:00
Ondřej Surý
52307f8116 Add internal logging functions to the netmgr
Add internal logging functions isc__netmgr_log, isc__nmsocket_log(), and
isc__nmhandle_log() that can be used to add logging messages to the
netmgr, and change all direct use of isc_log_write() to use those
logging functions to properly prefix them with netmgr, nmsocket and
nmsocket+nmhandle.
2022-12-14 19:34:48 +01:00
Ondřej Surý
eeb545a2a9 Merge branch '3637-try-next-server-on-resolver-timeout' into 'main'
Try next server on resolver timeout

Closes #3637

See merge request isc-projects/bind9!7212
2022-12-14 17:52:32 +00:00
Ondřej Surý
d1f1db2f5a Add CHANGES and release notes for [GL #3637] 2022-12-14 18:49:54 +01:00
Ondřej Surý
b8c7dc2dc2 Expire names in shutdown_names() under the lock
Since there could be fetches running, we need to run expire_name() under
the lock when shutting down the names.
2022-12-14 18:49:18 +01:00
Ondřej Surý
32c2acf6fc Add comment why statistics/ns3 has misconfigure root.hints
To count pending queries in the statistics, we need the ns3 to be
misconfigured.  Document the fact in the statistics/ns3/root.hints.
2022-12-14 18:49:18 +01:00
Ondřej Surý
b679640950 Revert the statistics system test change after we fixed the resolver
When the resolver was refactored, the statistics system test had to be
adjusted in c6b4d82557.  Unfortunately,
this change had to be done because of an error in the resolver
refactoring where timeout would not retry next server, but keep trying
the same server.  As we have now fixed this bug, revert the change to
the test back to the previous state.
2022-12-14 18:49:18 +01:00
Ondřej Surý
5466a48fc9 Try next server on resolver timeout
Instead of resending to the same server on the (dispatch) timeout in the
resolver, try the next server.
2022-12-14 18:49:18 +01:00