Commit graph

42366 commits

Author SHA1 Message Date
Aram Sargsyan
e61ba5865f Use a suitable response in tcp_connected() when initiating a read
When 'ISC_R_TIMEDOUT' is received in 'tcp_recv()', it times out the
oldest response in the active responses queue, and only after that it
checks whether other active responses have also timed out. So when
setting a timeout value for a read operation after a successful
connection, it makes sense to take the timeout value from the oldest
response in the active queue too, because, theoretically, the responses
can have different timeout values, e.g. when the TCP dispatch is shared.
Currently 'resp' is always NULL. Previously when connect and read
timeouts were not separated in dispatch this affected only logging, but
now since we are setting a new timeout after a successful connection,
we need to choose a suitable response from the active queue.
2025-01-22 13:40:45 +00:00
Ondřej Surý
48471fd50c fix: usr: Avoid unnecessary locking in the zone/cache database
Prevent lock contention among many worker threads referring to the same database node at the same time.  This would improve zone and cache database performance for the heavily contended database nodes.

Closes #5130

Merge branch '5130-reduce-lock-contention-in-decrement-reference' into 'main'

See merge request isc-projects/bind9!9963
2025-01-22 13:27:40 +00:00
JINMEI Tatuya
7f4471594d
Optimize database decref by avoiding locking with refs > 1
Previously, this function always acquires a node write lock if it
might need node cleanup in case the reference decrements to 0.  In
fact, the lock is unnecessary if the reference is larger than 1 and it
can be optimized as an "easy" case. This optimization could even be
"necessary". In some extreme cases, many worker threads could repeat
acquring and releasing the reference on the same node, resulting in
severe lock contention for nothing (as the ref wouldn't decrement to 0
in most cases). This change would prevent noticeable performance
drop like query timeout for such cases.

Co-authored-by: JINMEI Tatuya <jtatuya@infoblox.com>
Co-authored-by: Ondřej Surý <ondrej@isc.org>
2025-01-22 14:27:13 +01:00
Ondřej Surý
3fe440f0cf chg: dev: Shutdown the fetch context after canceling the last fetch
Shutdown the fetch context immediately after the last fetch has been canceled from
that particular fetch context.

Merge branch 'ondrej/shutdown-the-fetch-context-early' into 'main'

See merge request isc-projects/bind9!9958
2025-01-22 13:21:23 +00:00
Ondřej Surý
9f945c8b67
Shutdown the fetch context after canceling the last fetch
Currently, the fetch context will continue running even when the last
fetch (response) has been removed from the context, so named can process
and cache the answer.  This can lead to a situation where the number of
outgoing recursing clients exceeds the the configured number for
recursive-clients.

Be more stringent about the recursive-clients limit and shutdown the
fetch context immediately after the last fetch has been canceled from
that particular fetch context.
2025-01-22 14:19:20 +01:00
Ondřej Surý
0673568c17 fix: usr: Apply the memory limit only to ADB database items
Resolver under heavy-load could exhaust the memory available for storing
the information in the Address Database (ADB) effectively evicting already
stored information in the ADB.  The memory used to retrieve and provide
information from the ADB is now not a subject of the same memory limits
that are applied for storing the information in the Address Database.

Closes #5127

Merge branch '5127-change-ADB-memory-split' into 'main'

See merge request isc-projects/bind9!9954
2025-01-22 13:14:40 +00:00
Ondřej Surý
05faff6d53
Remove memory limit on ADB finds and fetches
Address Database (ADB) shares the memory for the short lived ADB
objects (finds, fetches, addrinfo) and the long lived ADB
objects (names, entries, namehooks).  This could lead to a situation
where the resolver-heavy load would force evict ADB objects from the
database to point where ADB is completely empty, leading to even more
resolver-heavy load.

Make the short lived ADB objects use the other memory context that we
already created for the hashmaps.  This makes the ADB overmem condition
to not be triggered by the ongoing resolver fetches.
2025-01-22 14:13:35 +01:00
Arаm Sаrgsyаn
3f490fe3fb chg: dev: Separate the connect and the read TCP timeouts in dispatch
The network manager layer has two different timers with their
own timeout values for TCP connections: connect timeout and read
timeout. Separate the connect and the read TCP timeouts in the
dispatch module too.

Closes #5009

Merge branch '5009-dispatch-separate-connect-and-read-timeouts' into 'main'

See merge request isc-projects/bind9!9698
2025-01-22 12:58:29 +00:00
Aram Sargsyan
612d76b83d Remove dispatch timeout INT16_MAX limitation
In some places there was a limitation of the maximum timeout
value of INT16_MAX, which is only about 32 seconds. Refactor
the code to remove the limitation.
2025-01-22 11:57:53 +00:00
Aram Sargsyan
64ffbe82c0 Separate the connect and the read timeouts in dispatch
The network manager layer has two different timers with their
own timeout values for TCP connections: connect timeout and read
timeout. Separate the connect and the read TCP timeouts in the
dispatch module too.
2025-01-22 11:57:52 +00:00
Aram Sargsyan
114555ea65 dispatch_test: make client timeouts shorter
Use shorter timeouts for the client to ensure that the clients
time out before the server.
2025-01-22 11:52:24 +00:00
Aram Sargsyan
9ccd1be482 Update the dns_dispatch_add() function's documentation
The 'timedout' callback no longer exists. Remove the mentioning of
the 'timedout' callback.
2025-01-22 11:52:24 +00:00
Colin Vidal
65c557c536 new: nil: ignore TAGS files
Merge branch 'colin/ignoreTAGS' into 'main'

See merge request isc-projects/bind9!9956
2025-01-22 11:22:41 +00:00
Colin Vidal
2164ea8abd ignore TAGS files
TAGS file are generated from `make tags` using etags. Other index tags
are already ignored (GTAGS, GPATH, etc.). Also ignoring `TAGS`.
2025-01-22 10:42:35 +00:00
Colin Vidal
1732346fcc rem: dev: remove fields from struct fetchctx
struct fetchctx does have several fields which are now unused or confusing, removing those.

Merge branch 'colin/remove-fctx-validator' into 'main'

See merge request isc-projects/bind9!9945
2025-01-22 10:31:22 +00:00
Colin Vidal
c9529c0acb remove ISC_LINK(link) property from fetchctx
Likely because of historical reasons, struct fetchctx does have a list
link property but is never used as a list. Remove this link property.
2025-01-22 09:56:09 +00:00
Colin Vidal
93e6e72eb6 remove validator link form fetchctx
struct fetchctx does have a list of pending validators as well as a
pointer to the HEAD validator. Remove the validator pointer to avoid
confusion, as there is no perticular reasons to have it directly
accessible outside of the list.
2025-01-22 09:56:09 +00:00
Andoni Duarte
87b0c1c1a0 chg: doc: Set up version for BIND 9.21.5
Merge branch 'andoni/set-up-version-for-bind-9.21.5' into 'main'

See merge request isc-projects/bind9!9968
2025-01-22 08:33:12 +00:00
Andoni Duarte Pintado
bdef1e2176 Update BIND version to 9.21.5-dev 2025-01-21 15:58:51 +01:00
Nicki Křížek
3a94afa03a fix: usr: querying an NSEC3-signed zone for an empty record could trigger an assertion
A bug in the qpzone database could trigger a crash when querying for a deleted name, or a newly-added empty non-terminal name, in an NSEC3-signed zone. This has been fixed.

Closes #5108

Merge branch '5108-nsec3-empty-node' into 'main'

See merge request isc-projects/bind9!9928
2025-01-14 08:34:16 +00:00
Evan Hunt
232dac8cd5 detect when closest-encloser name is too long
there was a database bug in which dns_db_find() could get a partial
match for the query name, but still set foundname to match the full
query name.  this triggered an assertion when query_addwildcardproof()
assumed that foundname would be shorter.

the database bug has been fixed, but in case it happens again, we
can just copy the name instead of splitting it. we will also log a
warning that the closest-encloser name was invalid.
2025-01-09 17:04:08 -08:00
Evan Hunt
71e1c91695 dns_nsec3_addnsec3() can fail when iterating back
when adding a new NSEC3 record, dns_nsec3_addnsec3() uses a
dbiterator to seek to the newly created node and then find its
predecessor.  dbiterators in the qpzone use snapshots, so changes
to the database are not reflected in an already-existing iterator.
consequently, when we add a new node, we have to create a new iterator
before we can seek to it.
2025-01-09 17:04:08 -08:00
Evan Hunt
3e367a23f9 add a regression test for a new ENT node
this test adds a record with empty non-terminal nodes above it. this
has also been observed to trigger the crash in NSEC3 zones.

NOTE: the test currently fails, because while there is no crash, the
query results are not as expected.  when we add a node below an ENT,
receive_secure_serial() gets DNS_R_PARTIALMATCH, and the signed
zone is never updated. this is not a regression from fixing the
crash bug; it's a separate inline-signing bug.
2025-01-09 17:03:51 -08:00
Evan Hunt
7b94c34965 add a regression test for record deletion
test that there's no crash when querying for a newly-deleted node.

(incidentally also renamed ns3/named.conf.in to ns3/named1.conf.in,
because named2.conf.in does exist, and they should match.)
2025-01-09 17:03:51 -08:00
Evan Hunt
ad4bab306c 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-01-09 17:03:51 -08:00
Michał Kępień
9636dc1a1e fix: nil: Fix default IANA root zone mirror configuration
Closes #5115

Merge branch '5115-fix-default-iana-root-zone-mirror-configuration' into 'main'

See merge request isc-projects/bind9!9934
2025-01-09 11:22:07 +00:00
Michał Kępień
010d2eb436
Fix default IANA root zone mirror configuration
Commit b121f02eac renamed the top-level
"primaries" block in bin/named/config.c to "remote-servers".  This
configuration block lists the primary servers used for an IANA root zone
mirror when no primary servers are explicitly specified for it in the
configuration.  However, the relevant part of the named_zone_configure()
function only looks for a top-level "primaries" block and not for any of
its synonyms.  As a result, configuring an IANA root zone mirror with
just:

    zone "." {
        type mirror;
    };

now results in a cryptic fatal error on startup:

    loading configuration: not found
    exiting (due to fatal error)

Fix by using the correct top-level block name in named_zone_configure().
2025-01-09 12:16:48 +01:00
Arаm Sаrgsyаn
19a2aab136 fix: usr: Fix response policy zones and catalog zones with an $INCLUDE statement defined
Response policy zones (RPZ) and catalog zones were not working correctly if they had an $INCLUDE statement defined. This has been fixed.

Closes #5111

Merge branch '5111-includes-disable-rpz-and-catz-fix' into 'main'

See merge request isc-projects/bind9!9930
2025-01-08 14:01:36 +00:00
Aram Sargsyan
d75bdabe51 Fix a typo in dns/master.h
The ISC_R_SEENINCLUDE definition does not exist, the correct one
is DNS_R_SEENINCLUDE.
2025-01-08 14:00:55 +00:00
Aram Sargsyan
3d7a9fba3b Don't disable RPZ and CATZ for zones with an $INCLUDE statement
The code in zone_startload() disables RPZ and CATZ for a zone if
dns_master_loadfile() returns anything other than ISC_R_SUCCESS,
which makes sense, but it's an error because zone_startload() can
also return DNS_R_SEENINCLUDE upon success when the zone had an
$INCLUDE statement.
2025-01-08 14:00:55 +00:00
Nicki Křížek
e71549eaba new: ci: Add shotgun perf test of DoH GET to CI
Add performance tests of DoH using the GET protocol to nightly pipelines.

Merge branch 'nicki/ci-shotgun-doh-get' into 'main'

See merge request isc-projects/bind9!9926
2025-01-08 13:43:40 +00:00
Nicki Křížek
32c5f24713 Add shotgun perf test of DoH GET to CI 2025-01-08 12:45:48 +00:00
Michal Nowak
b1b004ed01 fix: test: Fix "checking startup notify rate limit" fails on OL 8 FIPS
Adjust number of zones down to 23 to match those present when testing in FIPS mode.

Closes #5097

Merge branch '5097-checking-startup-notify-rate-limit-fails-on-ol-8-fips' into 'main'

See merge request isc-projects/bind9!9919
2025-01-02 15:32:55 +00:00
Mark Andrews
17804f5154 Adjust number of zones to those in FIPS mode 2025-01-02 14:38:24 +00:00
Michał Kępień
6230bc883a new: dev: Log both "from" and "to" socket in debug messages
Debug messages logging network traffic now include information about both sides of each communication channel rather than just one of them.

Closes #4345

Merge branch '4345-log-both-from-and-to-socket-in-debug-messages' into 'main'

See merge request isc-projects/bind9!8349
2024-12-31 04:42:41 +00:00
Michał Kępień
dd2c509521
Account for revised log messages in test code
Adjust test code so that it expects the extended output that the
dns_message_logpacketfromto() function now emits.
2024-12-31 05:40:48 +01:00
Michał Kępień
7bdf5152d6
Adjust dns_message_logpacketfrom() log prefixes
Ensure the log prefixes passed to the dns_message_logpacketfrom()
function by its callers do not include the word "from" as the latter is
now emitted by the logfmtpacket() helper function.
2024-12-31 05:40:48 +01:00
Michał Kępień
58d38352ee
Adjust dns_message_logpacketfromto() log prefixes
Ensure the log prefixes passed to the dns_message_logpacketfromto()
function by its callers do not include the words "from" or "to" as those
are now emitted by the logfmtpacket() helper function.
2024-12-31 05:40:48 +01:00
Michał Kępień
c5555a5ca2
Log both "from" and "to" socket in debug messages
Move dns_dispentry_getlocaladdress() calls around so that they are not
only invoked when dnstap support is compiled in.  This function calls
isc_nmhandle_localaddr(), which may issue a system call, but only if the
ISC_SOCKET_DETAILS preprocessor macro is set at compile time.

Pass the value extracted by dns_dispentry_getlocaladdress() to
dns_message_logpacketfromto() so that it gets logged, adding useful
information to the relevant debug messages.
2024-12-31 05:40:48 +01:00
Michał Kępień
4ab35f6839
Rename dns_message_logpacket()
Since dns_message_logpacket() only takes a single socket address as a
parameter (and it is always the sending socket's address), rename it to
dns_message_logpacketfrom() so that its name better conveys its purpose
and so that the difference in purpose between this function and
dns_message_logpacketfromto() becomes more apparent.
2024-12-31 05:40:48 +01:00
Michał Kępień
fa073a0a63
Rename dns_message_logfmtpacket()
Since dns_message_logfmtpacket() needs to be provided with both "from"
and "to" socket addresses, rename it to dns_message_logpacketfromto() so
that its name better conveys its purpose.  Clean up the code comments
for that function.
2024-12-31 05:40:48 +01:00
Michał Kępień
bafa5d3c2e
Enable logging both "from" and "to" socket
Change the function prototype for dns_message_logfmtpacket() so that it
takes two isc_sockaddr_t parameters: one for the sending side and
another one for the receiving side.  This enables debug messages to be
more precise.

Also adjust the function prototype for logfmtpacket() accordingly.
Unlike dns_message_logfmtpacket(), this function must not require both
'from' and 'to' parameters to be non-NULL as it is still going to be
used by dns_message_logpacket(), which only provides a single socket
address.  Adjust its log format to handle both of these cases properly.

Adjust both dns_message_logfmtpacket() call sites accordingly, without
actually providing the second socket address yet.  (This causes the
revised REQUIRE() assertion in dns_message_logfmtpacket() to fail; the
issue will be addressed in a separate commit.)
2024-12-31 05:40:48 +01:00
Michał Kępień
05d69bd7a4
dns_message_logfmtpacket(): drop 'style' parameter
Both existing callers of the dns_message_logfmtpacket() function set the
argument passed as 'style' to &dns_master_style_comment.  To simplify
these call sites, drop the 'style' parameter from the prototype for
dns_message_logfmtpacket() and use a fixed value of
&dns_master_style_comment in the function's body instead.
2024-12-31 05:40:48 +01:00
Michał Kępień
064b2c6889
logfmtpacket(): drop useless local variables
All callers of the logfmtpacket() helper function require the argument
passed as 'address' to be non-NULL.  Meanwhile, the 'newline' and
'space' local variables in logfmtpacket() are only set to values
different than their initial values if the 'address' parameter is NULL.
Replace the 'newline' and 'space' local variables in logfmtpacket() with
fixed strings to improve code readability.
2024-12-31 05:40:48 +01:00
Michał Kępień
44d5dbeab6 new: dev: Enable extraction of exact local socket addresses
Enable extracting the exact address/port that a local wildcard/TCP socket is bound to, improving the accuracy of dnstap logging and providing more information in debug logs produced by system tests.  Since this requires issuing an extra system call on some hot paths, this new feature is only enabled when the ``ISC_SOCKET_DETAILS`` preprocessor macro is set at compile time.

Closes #4344

Merge branch '4344-enable-extraction-of-exact-local-socket-addresses' into 'main'

See merge request isc-projects/bind9!8348
2024-12-31 04:40:12 +00:00
Michał Kępień
d6f9785ac6
Enable extraction of exact local socket addresses
Extracting the exact address that each wildcard/TCP socket is bound to
locally requires issuing the getsockname() system call, which libuv
exposes via its uv_*_getsockname() functions.  This is only required for
detailed logging and comes at a noticeable performance cost, so it
should not happen by default.  However, it is useful for debugging
certain problems (e.g. cryptic system test failures), so a convenient
way of enabling that behavior should exist.

Update isc_nmhandle_localaddr() so that it calls uv_*_getsockname() when
the ISC_SOCKET_DETAILS preprocessor macro is set at compile time.
Ensure proper handling of sockets that wrap other sockets.

Set the new ISC_SOCKET_DETAILS macro by default when --enable-developer
is passed to ./configure.  This enables detailed logging in the system
tests run in GitLab CI without affecting performance in non-development
BIND 9 builds.

Note that setting the ISC_SOCKET_DETAILS preprocessor macro at compile
time enables all callers of isc_nmhandle_localaddr() to extract the
exact address of a given local socket, which results e.g. in dnstap
captures containing more accurate information.

Mention the new preprocessor macro in the section of the ARM that
discusses why exact socket addresses may not be logged by default.
2024-12-29 12:32:05 +01:00
Michał Kępień
dc90e977fc chg: nil: Improve reuse of outgoing TCP connections
This MR is a prerequisite for !8348.

It intentionally does not have a changelog entry associated with it, to
prevent making a false impression of improving connection reuse **for
existing code**.  It will only make a difference once !8348 gets merged
(and even then, only if the new `ISC_SOCKET_DETAILS` macro will be set
during build).  That's because `isc_nmhandle_localaddr()` currently
simply returns `handle->local` and its return value will only be set to
the actual address the socket is bound to with !8348 in place.

Note that `dns_dispatch_gettcp()` is currently only used by the
`dns_request` API, so this MR's potential for introducing new breakage
is relatively low.

Closes #4693

Merge branch '4693-improve-reuse-of-outgoing-tcp-connections' into 'main'

See merge request isc-projects/bind9!8972
2024-12-29 11:31:29 +00:00
Michał Kępień
086c325ad3
Improve reuse of outgoing TCP connections
The dns_dispatch_gettcp() function is used for finding an existing TCP
connection that can be reused for sending a query from a specified local
address to a specified remote address.  The logic for matching the
provided <local address, remote address> tuple to one of the existing
TCP connections is implemented in the dispatch_match() function:

  - if the examined TCP connection already has a libuv handle assigned,
    it means the connection has already been established; therefore,
    compare the provided <local address, remote address> tuple against
    the corresponding address tuple for the libuv handle associated with
    the connection,

  - if the examined TCP connection does not yet have a libuv handle
    assigned, it means the connection has not yet been established;
    therefore, compare the provided <local address, remote address>
    tuple against the corresponding address tuple that the TCP
    connection was originally created for.

This logic limits TCP connection reuse potential as the libuv handle
assigned to an existing dispatch object may have a more specific local
<address, port> tuple associated with it than the local <address, port>
tuple that the dispatch object was originally created for.  That's
because the local address for outgoing connections can be set to a
wildcard <address, port> tuple (indicating that the caller does not care
what source <address, port> tuple will be used for establishing the
connection, thereby delegating the task of picking it to the operating
system) and then get "upgraded" to a specific <address, port> tuple when
the socket is bound (and a libuv handle gets associated with it).  When
another dns_dispatch_gettcp() caller then tries to look for an existing
TCP connection to the same peer and passes a wildcard address in the
local part of the tuple, the function will not match that request to a
previously-established TCP connection (unless isc_nmhandle_localaddr()
returns a wildcard address as well).

Simplify dispatch_match() so that the libuv handle associated with an
existing dispatch object is not examined for the purpose of matching it
to the provided <local address, remote address> tuple; instead, always
examine the <local address, remote address> tuple that the dispatch
object was originally created for.  This enables reuse of TCP
connections created without providing a specific local socket address
while still preventing other connections (created for a specific local
socket address) from being inadvertently shared.
2024-12-29 10:22:20 +01:00
Artem Boldariev
6eb77ed2b0 chg: dev: Add TLS SNI extension to all outgoing TLS connections
This change ensures that SNI extension is used in outgoing connections over TLS (e.g. for DoT and DoH) when applicable.

Closes #5099

Merge branch 'artem-outgoing-tls-sni-support' into 'main'

See merge request isc-projects/bind9!9923
2024-12-26 15:57:10 +00:00
Artem Boldariev
740292d3ec BIND - enable TLS SNI support for outgoing TLS connections
This commit ensures that BIND enables TLS SNI support for outgoing DoT
connections (when possible) in order to improve compatibility with
other DNS server software.
2024-12-26 17:23:25 +02:00