Commit graph

43838 commits

Author SHA1 Message Date
Colin Vidal
d676ce8085 remove query_ctx_t detach_client property
Since the removal of NS_QUERY_QCTX_DESTROYED hook, there is no need for
the `qctx->detach_client` object anymore, as this was designed to tell
the plugin whether the client object is about to be, or is already,
freed from memory.  This is not needed anymore, as NS_QUERY_RESET is
called _always_ when the client object is about to be freed from memory.

Remove `detach_client` and tidy up the code a bit by including the
freeing of the qctx object (when allocated) inside the qctx_destroy
function instead of requiring extra calls.
2025-09-09 10:02:32 +02:00
Colin Vidal
125e3832bc update hooks tests to use NS_QUERY_RESET
Update hooks-related unit tests since the removal of
NS_QUERY_QCTX_DESTROY and the introduction of NS_QUERY_RESET hook. This
also simplifies (a bit) the plugin usage as NS_QUERY_RESET is _always_
called when the client plugin is about to be freed from memory.
2025-09-09 09:42:34 +02:00
Colin Vidal
95c71c2739 replace QCTX_INIT/_DESTROY hooks with QUERY_SETUP/_RESET
The hook NS_QUERY_QCTX_DESTROY is problematic with zone plugins because
it can be called in some contexts where `qctx->client` is invalid (the
pointer is dangling); which would lead to a use-after-free (spotted by
TSAN build) as `qctx->client` is used to get the zone hooktable, to find
out whether there is an authoritive zone which would have
NS_QUERY_QCTX_DESTROY registered.

This can't easily be fixed, because there is no easy way to know from
query.c code if `client` is still a valid object: `client->reqhandle`,
representing the request from a client, is refcounted, and the `client`
object is freed from memory once its refcounter gets to 0. While
`reqhandle` is attached from query.c code, it can be attached more than
once from asynchronous code and there is no clear path where detaching
it would lead to a client free. Hence, there is no way to know for sure
when to set `qctx->client = NULL` (this is why the pointer remains
dangling).

Back to the original problem; this is why the NS_QUERY_QCTX_DESTROY hook
is incompatible with zone plugins. `qctx->detach_client`, which is used
to tell a plugin that the `client` object is either free or about to be
free can't be use either, because in some cases the client is still
there, and should be used.

Code issue aside, the `qctx` object is really just an aggregate of
various data to pass easily in the various functions and callbacks,
initially stored on the stack, but allocated in some cases (for some
asynchronous flow, when recursion is needed), so the point it gets
created/"destroyed" is really just an implementation "detail", and
providing a higher level hook for the plugin would be beneficial. Hence,
NS_QUERY_RESET and NS_QUERY_INIT are removed, and instead, the existing
NS_QUERY_SETUP can be used as well as the newly introduced
NS_QUERY_RESET (which replaces NS_QUERY_QCTX_DESTROY). The advanage is
that NS_QUERY_RESET is called _only_ when the client object is _always_
about to be freed, which avoids usage of the extra `qctx->detach_client`
usage from the plugin.

The way NS_QUERY_RESET works is that when the `client` is freed, a
callback (from `query.c`) is called. This callback creates a transient
qctx object on the stack with a pointer to the view, and uses that
to call the hook.
2025-09-09 09:42:34 +02:00
Colin Vidal
ced276b266 add unit test for plugin_register source param
Update the existing test's syncplugin plugin with a new parameter
indicating whether the plugin should be loaded in a view or a zone.
If it doesn't match where the plugin is actually loaded, it fails the
initialization. This covers the correctless of the `source` parameter of
`plugin_register` API.
2025-09-09 09:42:34 +02:00
Colin Vidal
260bbc24c9 add plugin_register param telling the source
The plugin `plugin_register` API has a new parameter `source` indicating
whether the plugin is loaded from a view or a zone.

This extra parameter enables the plugin to fail early during
initialization if a plugin written to be used in a zone exclusively
is loaded at a view level, or vice versa.
2025-09-09 09:42:34 +02:00
Colin Vidal
e8156b394e filter-aaaa can be used as zone or view plugin
Update the filter-aaaa system test so the two authoritative zones
in ns4 both configure filter-aaaa as a zone plugin.

In order to work in both contexts, the plugin must register both
the `NS_QUERY_QCTX_INITIALIZED` and `NS_QUERY_AUTHZONE_ATTACHED`
hooks.

When the plugin is configured at the zone level in an authoritative
server, `NS_QUERY_QCTX_INITIALIZED` is skipped, because no zone will
have been looked up by the time it is called.  When the zone is
found, calling `NS_QUERY_AUTHZONE_ATTACHED` will allow the same
initialization to occur.
2025-09-09 09:42:34 +02:00
Colin Vidal
1566634fae add NS_QUERY_AUTHZONE_ATTACHED hook
Add a new query hook called `NS_QUERY_AUTHZONE_ATTACHED`. This hook is
called whenever an authoritative zone is found and attached during a
query answer.

From code level, this hook is called when `qctx->client->query->authzone`
is attached during a query.  This enables zone-specific plugins to
initialize specific states whenever a local zone is found that can
answer a query.
2025-09-09 09:42:34 +02:00
Colin Vidal
91cd7b865c update hook developer documentation
Attempt to add zone plugin specificities into the hook developer
documentation. In particular about the hook call order and hookpoint
which can't be called on a zone plugin.
2025-09-09 09:42:34 +02:00
Colin Vidal
1d010b6340 add zone plugin documentation
Update ARM documentation to mention plugin usage at the zone level (as
well as template level).
2025-09-09 09:42:34 +02:00
Colin Vidal
bd46aecd22 add template support for zone plugins
The zone plugin loading code now also looks into the zone template
configuration property of a zone. If it exists, it checks whether there
is a plugin sub-tree defined in the template and, if that exists, loads
the plugin definition from the template.
2025-09-09 09:42:34 +02:00
Colin Vidal
1114b1eac0 add query unit test
A new query unit test covers the logic where zone hooks must be called
first, then view ones, and finally the default hooks. It also ensures
that if any hook returns NS_HOOK_RETURN the chain immediately stops.
2025-09-09 09:42:34 +02:00
Colin Vidal
b8e44d6259 add tests for per-zone hook instance support
add system tests covering the individual support of zone plugins.
2025-09-09 09:42:34 +02:00
Colin Vidal
5893770cd9 add zone-specific plugin instance
The zone object now has its own hooktable and plugins, which are
initialized during zone initialization.
2025-09-09 09:42:34 +02:00
Colin Vidal
0247506ddc test for namedconf zone plugin support
add a system test, using a dummy plugin, to test named.conf
validation of a plugin inside a zone definition.
2025-09-09 09:42:34 +02:00
Colin Vidal
7ea70b4e19 add namedconf support for plugin inside a zone
The named.conf parser now accepts the plugin clause inside a zone
definition.  This enables us to add (in later commits) support for
zone plugins.
2025-09-09 09:42:34 +02:00
Ondřej Surý
014a05a278 rem: usr: Remove randomized RRset ordering
The rrset-order random doesn't offer uniform distribution of all
permutations and it isn't superior to cyclic order in any way.  Make the
random ordering an alias to the cyclic ordering.

Closes: #5513

Merge branch 'ondrej/remove-rrset-order-random' into 'main'

See merge request isc-projects/bind9!10912
2025-09-08 17:05:05 +02:00
Ondřej Surý
2963d1aaf1
Refactor the cyclic ordering to use query ID as offset
Mimic the Unbound behaviour where the cyclic offset is taken from query
ID, and remove recording of the current state.  As the incoming query ID
should have random distribution, the cyclic ordering should also have
uniform distribution of the starting record.
2025-09-08 14:04:13 +02:00
Ondřej Surý
b3f5c3b0fc
Refactor the cyclic ordering to be more efficient
With random ordering removed, the cyclic ordering can be rewritten in a
that it uses thread_local static array to keep the cyclic order.

This could be further improved by keeping the current position inside
the slabheader and adding a function to start directly there instead at
dns_rdataset_first().
2025-09-08 14:04:13 +02:00
Ondřej Surý
7dc6048f93
Remove the random ordering of resource records in RRset
The rrset-order random doesn't offer uniform distribution of all
permutations and it isn't superior to cyclic order in any way.  Make the
random ordering an alias to the cyclic ordering.
2025-09-08 14:04:13 +02:00
Colin Vidal
b449fa9500 new: usr: add extra tokens to the zone file name template
Extend the `$name`, `$view` and `$type` tokens (expanding into the zone
name, zone's view name and type); the new following tokens are now also
accepted:

- `$name` or `%s` is replaced with the zone name in lower case;
- `$type` or `%t` is replaced with the zone type -- i.e., primary,
  secondary, etc);
- `$view` or `%v` is replaced with the view name;
- `$char1` or `%1` is replaced with the first character of the zone name;
- `$char2` or `%2` is replaced with the second character of the zone name
  (or a dot if there is no second character);
- `$char3` or `%3` is replaced with the third character of the zone name (or
  a dot if there is no third character);
- `$label1` or `%z` is replaced with the toplevel domain of the zone (or a
  dot if it is the root zone);
- `$label2` or `%y` is replaced with the next label under the toplevel
  domain (or a dot if there is no next label);
- `$label3` or `%x` is replaced with the next-next label under the toplevel
  domain (or a dot if there is no next-next label).

Closes #85

Merge branch '85-file-template' into 'main'

See merge request isc-projects/bind9!10779
2025-09-08 12:46:48 +02:00
Colin Vidal
0e1f13e05c add extra tokens to the zone file name template
Extend the `$name`, `$view` and `$type` tokens (expanding into the zone
name, zone's view name and type); the new following tokens are now also
accepted:

- $name or %s is replaced with the zone name in lower case;
- $type or %t is replaced with the zone type -- i.e., primary,
  secondary, etc);
- $view or %v is replaced with the view name;
- $char1 or %1 is replaced with the first character of the zone name;
- $char2 or %2 is replaced with the second character of the zone name
  (or a dot if there is no second character);
- $char3 or %3 is replaced with the third character of the zone name (or
  a dot if there is no third character);
- $label1 or %z is replaced with the toplevel domain of the zone (or a
  dot if it is the root zone);
- $label2 or %y is replaced with the next label under the toplevel
  domain (or a dot if there is no next label);
- $label3 or %x is replaced with the next-next label under the toplevel
  domain (or a dot if there is no next-next label).
2025-09-08 12:10:09 +02:00
Petr Špaček
c0d12c1328 chg: doc: Set up version for BIND 9.21.13
Merge branch 'andoni/set-up-version-for-bind-9.21.13' into 'main'

See merge request isc-projects/bind9!10952
2025-09-08 09:45:16 +00:00
Andoni Duarte Pintado
c6d0278a4b Update BIND version to 9.21.13-dev 2025-09-08 11:41:27 +02:00
Ondřej Surý
15672f3eaa fix: nil: Replace .reuse/dep5 with REUSE.toml
Update to REUSE Specification 3.2+ that uses REUSE.toml instead of DEP5
based specification.

Merge branch 'ondrej/cover-reuse-dep5-to-toml' into 'main'

See merge request isc-projects/bind9!10945
2025-09-08 11:22:51 +02:00
Ondřej Surý
5d03261448
Replace .reuse/dep5 with REUSE.toml
Update to REUSE Specification 3.2+ that uses REUSE.toml instead of DEP5
based specification.
2025-09-06 15:58:22 +02:00
Petr Špaček
3e8d31b47b chg: doc: Document rndc dnssec -step
Related to #4606

Merge branch '4606-document-rndc-dnssec-step' into 'main'

See merge request isc-projects/bind9!10941
2025-09-04 13:49:56 +00:00
Matthijs Mekking
b1a9ce7104 Document rndc dnssec -step
This documentation was missing from !10774.
2025-09-04 15:41:43 +02:00
Petr Špaček
d8b975735a fix: dev: RPZ 'servfail-until-ready': skip updating SERVFAIL cache
In order to not pollute the SERVFAIL cache with the configured
SERVFAIL answers while RPZ is loading, set the NS_CLIENTATTR_NOSETFC
attribute for the client.

Merge branch 'aram/rpz-servfail-until-ready-tunings' into 'main'

See merge request isc-projects/bind9!10904
2025-09-03 13:23:38 +00:00
Aram Sargsyan
1962857ac4 Log the servfail-until-ready message not faster than once per second
Since the log level has been raised, busy servers can "explode" from
the amount of log messages. Use the usual practice of logging "every
once in a while".
2025-09-03 13:23:12 +00:00
Aram Sargsyan
49356ce944 Change the "RPZ not ready yet" message and its log level
The "RPZ not ready yet" message is logged at debug 3 level. Use the
info level instead for better visibility.

After raising the log level, the rpz_log_fail_helper() function starts
appending " failed: " the the message. Change the log message so it
makes more sense.
2025-09-03 13:23:12 +00:00
Aram Sargsyan
d9b5f6c502 RPZ 'servfail-until-ready': skip updating SERVFAIL cache
In order to not pollute the SERVFAIL cache with the configured
SERVFAIL answers while RPZ is loading, set the NS_CLIENTATTR_NOSETFC
attribute for the client.
2025-09-03 13:23:12 +00:00
Ondřej Surý
46c88265da chg: doc: Clarify rrset-order random distribution
The randomized order of the records in the rrset is not uniform across
all permutations.  Clarify this in the documentation.

Closes #5485

Merge branch 'ondrej/clarify-rrset-order-random' into 'main'

See merge request isc-projects/bind9!10909
2025-09-03 08:50:50 +02:00
Ondřej Surý
369c8dc388 Clarify rrset-order random distribution
The randomized order of the records in the rrset is not uniform across
all permutations.  Clarify this in the documentation.
2025-09-03 08:50:40 +02:00
Mark Andrews
bdcb90f43c new: usr: Support for parsing HHIT and BRID records has been added
Closes #5444

Merge branch '5444-add-hhit-and-brid-records' into 'main'

See merge request isc-projects/bind9!10795
2025-09-03 10:47:37 +10:00
Mark Andrews
92621e6390 Add tests for BRID and HHIT 2025-09-03 10:05:13 +10:00
Mark Andrews
6b29da55fc Add support for parsing and displaying BRID rdata type 2025-09-03 10:05:13 +10:00
Mark Andrews
37041c3ec3 Add support for parsing and displaying HHIT rdata type 2025-09-03 10:05:13 +10:00
Mark Andrews
70757a47e6 fix: usr: RPZ canonical warning displays zone entry incorrectly
When an IPv6 rpz prefix entry is entered incorrectly the log
message was just displaying the prefix rather than the full
entry.  This has been corrected.

Closes #5491

Merge branch '5491-rpz-canonical-warning-displays-zone-entry-incorrectly' into 'main'

See merge request isc-projects/bind9!10890
2025-09-03 09:41:18 +10:00
Mark Andrews
76db9e276f Add non canonical form entry to trigger log message 2025-09-03 09:01:54 +10:00
Mark Andrews
283da99f02 RPZ canonical warning displays zone entry incorrectly
Do not insert a NUL into ip_str too early as the full value
is needed later.  Only insert the NUL immediately before
displaying just the prefix string.
2025-09-03 09:01:54 +10:00
Ondřej Surý
b0d3a36a0a rem: nil: Remove qname/qtype from dns_adb_createfind() call
Both qname and qtype arguments to dns_adb_createfind() were unused.
Remove both these arguments from the function prototype.

Merge branch 'ondrej/minor-dns_adb-cleanup' into 'main'

See merge request isc-projects/bind9!10918
2025-09-02 21:41:05 +02:00
Ondřej Surý
5b025d6e43
Remove qname/qtype from dns_adb_createfind() call
Both qname and qtype arguments to dns_adb_createfind() were unused.
Remove both these arguments from the function prototype.
2025-09-02 20:16:58 +02:00
Matthijs Mekking
085653d8b7 chg: test: Wait for rekey_done log in rollover system tests
Waiting for "keymgr: done" logs caused some manual-mode tests to fail intermittently. Waiting for "rekey done" logs should be more reliable.

Closes #5493

Merge branch '5493-algoroll-csk-step3-manual-unstable-test' into 'main'

See merge request isc-projects/bind9!10923
2025-09-02 13:03:08 +00:00
Matthijs Mekking
4141ae1275 Wait for rekey_done log in rollover system tests
Waiting for "keymgr: done" logs caused some manual-mode tests to fail
intermittently. Waiting for "rekey done" logs should be more reliable.
2025-09-02 14:28:48 +02:00
Alessio Podda
8e3e4a5c19 chg: dev: Lazily allocate fetch counter
The counter in ns_client_t is used to track the maximum number of
recursions in the resolver, but it is created unconditionally when
starting the client and deallocated when resetting it.

This commit defers the allocation of the counter till recursion needs to
actually happen, speeding up authoritative workloads in perflab by
1.5~2%.

Merge branch 'alessio/lazy-fetch-counter-alloc' into 'main'

See merge request isc-projects/bind9!10917
2025-09-02 09:57:30 +00:00
Alessio Podda
20a1583661 Lazily allocate fetch counter
The counter in ns_client_t is used to track the maximum number of
recursions in the resolver, but it is created unconditionally when
starting the client and deallocated when resetting it.

This commit defers the allocation of the counter till recursion needs to
actually happen, speeding up authoritative workloads in perflab by
1.5~2%.
2025-09-02 11:22:28 +02:00
Andoni Duarte
3762bf7fed new: test: Test another 'stale-answer-client-timeout 0' scenario
Add a test to check serve-stale with the 'stale-answer-client-timeout 0'
configuration option and with a delegation which is a CNAME to a auth
zone.

Closes #5372

Merge branch '5372-serve-stale-crash-on-insist-unreachable-test' into 'main'

See merge request isc-projects/bind9!10920
2025-09-02 08:50:18 +00:00
Aram Sargsyan
04ed44e7d7 Test another 'stale-answer-client-timeout 0' scenario
Add a test to check serve-stale with the 'stale-answer-client-timeout 0'
configuration option and with a delegation which is a CNAME to a auth
zone.
2025-09-02 08:07:15 +00:00
Michał Kępień
bed752f57f rem: usr: Obsolete the "tkey-domain" statement
Mark the ``tkey-domain`` statement as obsolete, since it has not had any
effect on server behavior since support for TKEY Mode 2 (Diffie-Hellman)
was removed (in BIND 9.20.0).

See #4204

Merge branch '4204-obsolete-tkey-domain' into 'main'

See merge request isc-projects/bind9!10798
2025-09-01 22:29:23 +02:00
Michał Kępień
805f1c0f65
Obsolete the "tkey-domain" statement
The "tkey-domain" statement has effectively been a no-op since commit
bd4576b3ce, which removed the only bit of
code using it: the logic implementing TKEY Mode 2 (Diffie-Hellman).

A subsequent cleanup commit, 885c132f4a,
also missed the opportunity to remove the "tkey-domain" statement
altogether.

Mark the "tkey-domain" statement as obsolete and remove all code and
documentation related to it.
2025-09-01 21:35:33 +02:00