Commit graph

16252 commits

Author SHA1 Message Date
Evan Hunt
6a57c6e8f6 save zone configuration as text
as previously mentioned in commit c65b2868ab, a cfg_obj_t
configuration tree structure takes up considerably more space than
the canonical text. since the zone configuration saved in the zone
object using dns_zone_setcfg() is only currently used for "rndc
showzone", it can be saved as text more efficiently than as an
object tree. (and, if a tree were needed, the text could be
re-parsed quickly; zone configuration text is generally small.)
2025-11-12 11:36:07 +01:00
Evan Hunt
e62895e999
Remove maybe_cancel_validators() function
When shutting down an fctx, validators can just be canceled
without checking whether there are pending finds.
2025-11-08 18:00:32 +01:00
Colin Vidal
0b93d5725b add query ID to the query trace message
Adding the query ID to the query trace message. The log is now as the
following (id is at the end):

    query client=0x7f75c5017000 thread=0x7f75c6dfe680(foo.fr/A): \
      client attr:0x22300, query attr:0x700, restarts:0, \
      origqname:foo.fr, timer:0, authdb:0, referral:0, id:21338

This should help debugging tests, in particular to quickly get a
specific query from the logs.
2025-11-06 15:11:45 +01:00
Colin Vidal
2a640adbc1 remove dns_zone_expire dead code
Removing `dns_zone_expire` function which is never called (the zone
expiration is detected internally in `lib/dns/zone.c`).
2025-11-06 15:11:45 +01:00
Matthijs Mekking
868ede012c Schedule a zonefetch
Scheduling and rescheduling a zonefetch is also similar.  Refactor into
zonefetch functions.  This also increments and decrements the zone's
internal reference counter in the same module, which may be less
confusing when reading the code.
2025-11-06 12:22:20 +01:00
Matthijs Mekking
77418fedce Fix comment in lib/ns/query.c
While renaming exit_check() to dns__zone_free_check() in lib/dns/zone.c,
a dead reference to exit_check() in the comments was found in
lib/ns/query.c.
2025-11-06 10:54:55 +01:00
Matthijs Mekking
6f70cb7a39 A unified way to verify the zone fetch
There is a lot of similarity when checking the completed fetch is legit.
Create a new function to verify the fetch and to reduce code
duplication.
2025-11-06 10:54:55 +01:00
Matthijs Mekking
94a82c2ecb Count per fetch type
Track fetch counts per type in an array, rather than special named
variables within the zone structure.
2025-11-06 10:54:55 +01:00
Matthijs Mekking
7ac02d4c04 Refactor zone fetch code
There is code duplication between keyfetch and nsfetch, refactor to
allow common code paths to differentiate between them.
2025-11-06 10:54:54 +01:00
Matthijs Mekking
6adfc2348b Export zone functions
Make some zone functions available that we are going to need in the
zonefetch code.
2025-11-06 10:54:54 +01:00
Ondřej Surý
a94a7c1a1e
Skip unsupported algorithms when looking for signing key
When looking for a signing key in select_signing_key(), the result code
indicating unsupported algorithm would abort the search.  Instead, skip
such keys and continue searching for the right key.

Co-Authored-By: Aram Sargsyan <aram@isc.org>
Co-Authored-By: Petr Menšík <pemensik@redhat.com>
2025-11-04 19:53:26 +01:00
Ondřej Surý
0d8dedf73b
Only unlink from SIEVE LRU if it is still linked
Under the overmem conditions, the header could get unlinked from the
SIEVE LRU using a different path.  This could lead to double-unlink
which causes assertion failure.  Add a guard to ISC_SIEVE_UNLINK() to
unlink only still linked headers.
2025-11-04 19:52:45 +01:00
Colin Vidal
e4851fcdb7 log that a zone is expired after setting the flag
When a (secondary) zone is expired, the log message `<zone> expired` is
printed and the flag `DNS_ZONEFLG_EXPIRED` is set. Change the order by
setting the expired flag first, then printing the log.

This should fixes (rare but persistent) timing-related CI error when the
EDE 24 tests expect the zone to be expired (from the log) and
immediately after request and expect an EDE 24 error. (In some rare
cases, the server was still answering the response).
2025-11-03 17:34:25 +01:00
Colin Vidal
59f116fbc9 support EDE 24 (Invalid Data)
Extended DNS Error 24 (Invalid Data) is returned when the server cannot
answer data for a zone it is configured for. This occurs typically when
an authoritative server does not have loaded the DB of a configured
zone, or a secondary server zone is expired.

See RFC 8914 section 4.25.
2025-11-03 17:34:25 +01:00
Colin Vidal
90b4f256a7 query_getzonedb can returns DNS_R_EXPIRED
If `query_getzonedb()` finds a zone but the zone is expired it
immediately returns `DNS_R_EXPIRED` and doesn't attempt to get the zone
DB (which would be NULL in this case).

This enable caller to have a more precise reason of why getting the DB
has failed.
2025-11-03 17:34:25 +01:00
Colin Vidal
6883282929 add dns_zone_isexpired API
Introduce the `dns_zone_isexpired()` API which returns `true` when a
secondary, mirror, etc. zone is expired.

This internally use the `DNS_ZONEFLG_EXPIRED` which was already set when
the zone gets expired, but never used.

The flag `DNS_ZONEFLG_EXPIRED` is also now cleared when the expiration
time of the zone is updated and in the future.
2025-11-03 17:34:25 +01:00
Petr Špaček
4e167e5c65 Remove leftover FCTX_ATTR_NEEDEDNS0
This is leftover from commit b6309ed962
which removed support for bitstring labels back in 2002.
2025-11-03 15:24:59 +00:00
Matthijs Mekking
c9ecc0bd26 Remove unused dns_zone_getnotifyacl() function
CID 638286: Concurrent data access violations (MISSING_LOCK).  This
complains about accessing "zone->notifyctx.notify_acl" without holding
the lock "dns_zone.lock".  Elsewhere, reading this data does have the
lock, so it makes sense that in the getter function this must also be
so.  However, the function is unused so we can just remove it.

CID 638287: Concurrent data access violations (MISSING_LOCK).  This
complains about accessing "zone->locked" without holding the lock
"dns_zone.lock". I think this is a false positive as "dns__zone_lock()"
and "dns__zone_unlock() are wrappers around "LOCK_ZONE()" and
"UNLOCK_ZONE()" and where these macros were used they were only
replaced with the internal zone functions. Moreover, "zone->locked"
is only accessed in these macros (and "TRYLOCK_ZONE()" and
"LOCKED_ZONE()").
2025-11-03 12:45:39 +01:00
Colin Vidal
608c56f4ac restore reuseport to yes by default on supported platforms
Changes introduced by 72862c2abc moved the
default configuration from within `bin/named` to a central place
`bin/includes`.

The default configuration is conditioned by several compile-time macro.
While for most of them it's fine because they are defined in the global
`config.h` file included by default to all binaries (by meson), one
specific is not defined here. `HAVE_SO_REUSEPORT_LB` was defined in
`lib/isc/include/isc/netmgr.h` which is of course not included in
`bin/includes/defaultconfig.h`.

As a result, reuseport was disabled for all platform by default, even
the supported ones. This fixes the problem by checking if reuseport is
available on the platform from meson `config.h` generation directly,
which makes `HAVE_SO_REUSEPORT_LB` available everywhere.
2025-10-31 15:11:08 +01:00
Matthijs Mekking
680becfb33 Move notify functions to notify source files
Move dns_notify_destroy, dns_notify_log, dns_notify_cancel,
dns_notify_queue, dns_notify_isqueued, dns_notify_find_address, and
notify related static functions over to the notify source files.
2025-10-31 13:43:47 +01:00
Matthijs Mekking
090a451e66 Export zone functions
Make some zone functions available that we are going to need in the
notify code.
2025-10-31 13:43:47 +01:00
Matthijs Mekking
e8eebf1ad6 Introduce notify source code files
Part of refactoring zone.c is to move the notify code into its own
source files. This commit initiates this work by creating notify.[c,h]
and move notify_create() and the notify state and context there.

The function notify_create() cannot fail, so it can return void instead
of isc_result_t.
2025-10-31 13:43:47 +01:00
Matthijs Mekking
35bdc94f51 Rename notify remote to alsonotify
Make it more clear it is tied to the 'also-notify' option.
2025-10-31 13:43:47 +01:00
Alessio Podda
a164492f3c Skip buffer allocations if not logging
Currently, during IXFR we allocate a 2KB buffer for IXFR change logging
regardless of the log level. This commit introduces an early check
on the log level in dns_diff_print to avoid this.

Results in a speedup from 28% in the test case from issue #5442.
2025-10-31 12:03:24 +01:00
Evan Hunt
fb6939b1c5 further shrink cfg_obj_t by using a pointer for duration
not storing the isccfg_duration object inside cfg_obj reduces
its size from 80 to 72 bytes.
2025-10-30 15:17:21 -07:00
Evan Hunt
714f73d786 reduce the size of cfg_obj by using pointers for addresses
instead of having sockaddr and netaddr members in the cfg_obj->value
union, we now just keep pointers, and allocate memory when parsing
these types. this reduces the size of cfg_obj_t from 112 to 80 bytes.
2025-10-30 15:17:21 -07:00
Colin Vidal
6601a30123 remove sun_path field from isc_netaddr
The sun_path field is not used anymore, and consumes over a hundred
bytes for every isc_netaddr_t object. Remove it.

As isc_netaddr_t is used in cfg_obj_t, in some huge configuration trees
(e.g., a million zones), the gain is almost 1GB of resident memory.
2025-10-30 11:44:08 -07:00
Evan Hunt
3d618684de refactor newzones configuration
instead of using an opaque ns_cfgctx pointer to store the configuration
data to be used by addzone and modzone, there are now fields in the
dns_view object to store the view configuration and LMDB database
environment. the global configuration is now stored in the named_server
object, along with the ACL context.
2025-10-29 23:49:49 +01:00
Colin Vidal
10eb99731c parser: add VALID_CFGOBJ macro
In order to harden `cfg_obj_t` usage now the configuration tree is
manipulated in various ways (cloned, merged, etc.), this introduce the
VALID_CFGOBJ macro to check the validity of a `cfg_obj_t` node.
2025-10-29 13:55:47 -07:00
Colin Vidal
a7080db211 fix delv when using the builtin trust-anchors
Since the builtin trust-anchors are now called `builtin-trust-anchors`,
delv needs specific handling in order to be able to parse those when
they are used.

Before, delv was simply parsing a single clause (either in the case of
an overriden trust-anchors value from bindkeys file or by simply reading
the builtin value). But since the name changed, the same code can't be
shared and the builtin version is expected to be in a map.
2025-10-29 13:55:47 -07:00
Colin Vidal
7ff1b7ef21 introduce default config builtin-root-anchors
Since the effective configuration tree is a "merged" configuration tree
from the user and the default configurations, the effective configuration
provides a unique configuration tree used by apply_confiuration() to
configure the server.

However, there is one specific case where the configuration code needs
to differentiate whether the configuration originally came from the
default or the user configuration: the trust-anchors. This is because
the default trust-anchors _have_ to be those for the root zone, and the
one provided by the user can be for any zone. A check enforces this.

In order to keep this difference visible from the configuration code,
with a unique configuration tree, we now introduce a default-only
`builtin-trust-anchors` statement which holds the builtin root
trust-anchors. It can't be used from the user configuration (this would
raise an error), hence it is not documented.
2025-10-29 13:55:47 -07:00
Colin Vidal
5b7445f507 effective config: specific check-names case
There are multiple check-names options provided in the default
configuration, and they must "complete" those provided by the user.
This is now handled when building the effective tree.
2025-10-29 13:55:04 -07:00
Colin Vidal
6643345a5b effective config: specific prefetch/trigger case
The prefetch statement can be overriden by the user, but the user might
specify the prefetch without the trigger value, which needs to be
pulled from the default configuration. Handle this case by directly
getting the default value if needed from the default configuration when
building the effective configuration tree.

Also take care of keeping the values inside their bounds, and simplify
the server configuration code which then just have to read effective
configuration values.
2025-10-29 13:55:04 -07:00
Colin Vidal
1f54a9107d effective config: specific dnssec-policy case
Default dnssec-policies are not overridden by user-provided ones. Add
this specific case to make sure those are kept, and also ensure that the
default dnssec-policy is always in the first position (which is an
implicit requirement in the existing implementation).

Also simplify the server configuration code, as it only needs to build
the list of dnssec-policy based on the effective config list.
2025-10-29 13:55:04 -07:00
Colin Vidal
27c4f68dcc effective config: specific view cases
User specified views don't override default views. In particular, the
_bind/CH view is still active. However, the order is important: if the
user defines a foo/CH view, it must be able to override _bind/CH by
matching clients first (this is how the view is documented).

The server configuration code is now simpler; it only has to build the
views based on the effective view list, and only creates the _default
view if there are no explicit views created by the user.
2025-10-29 13:55:04 -07:00
Colin Vidal
a99573d648 effective config: specific options/acl cases
Implement the specific rules of ACL inheritance when buiding the
effective configuration. As those rules are directly implemented in the
configuration tree, they are removed from `apply_configuation`.
2025-10-29 13:55:04 -07:00
Colin Vidal
9d477aa3d4 add cfg_effective_config() API
Add the entry point of the logic to merge the user and the default
configuration, called cfg_effective_config(). This function takes a user
configuration and a default configuration. It internally clones the user
configuration tree, then walks through the clauses recursively applying
default values if they are missing.

The newly built configuration tree, called the effective configuration
tree, is then returned.

Currently this is just the basic mechanism which is implemented (i.e.
enable to walk from clause to clause, goes into a nested clause, and so
on). The next commits will introduce the implementation of
clause-specific merge functions in order to preserve the existing
named.conf semantics.
2025-10-29 13:55:04 -07:00
Colin Vidal
a9a0af4359 add an optional merge method on cfg_clausedef_t
In order to handle specific cases when merging configurations (i.e.
some specific clauses which require specific handling, not just
overriding values for instance), the cfg_clausedef_t includes an
optional merge method.

The merge function is NULL by default. If it is defined for a given
clause, and this clause is defined in both the user and default
configurations, the merge function is then called with both the user and
default clause instances. It's up the the implementation of that function
do to anything needed to keep the correct named.conf semantic.
2025-10-29 13:55:04 -07:00
Colin Vidal
473bbeb54b add helper API calls to manipulate maps and lists
cfg_map_addclone() is a variant of cfg_map_add which internally clones
an object and adds it to a map. It ensures that the object is an
implicit list if the map clause has the CFG_CLAUSEFLAG_MULTI set

cfg_list_addclone() clones a list (internally cloning each individual
element) and appends or preprends it to an existing target list.

Both of these will be needed to merge the default configuration
with the user configuration.
2025-10-29 13:55:04 -07:00
Colin Vidal
35c8768fde parser firstclause/nextclause API changes
In order to make upcoming configuration tree changes easier, the
cfg_map_firstclause() and _nextclause() functions have been changed
to return the clause itself rather than only the clause name.
2025-10-29 13:55:04 -07:00
Evan Hunt
cd921cc7ef fix a "max-cache-size" configuration bug
"max-cache-size default;" is allowed, according to the documentation
and the parser, but when it's configured, named crashes due to an
INSIST that the only legal string value is "unlimited". this has
been fied.

the configuration has also been simplified. previously, we checked for
max-cache-size in view and options, then determined whether to look in
the global default options based on whether the view had recursion set.
the default value set there was only applicable to views with recursion.
now, the default is an explicit "default", which affects views with
and without recursion in different ways.

the cfg type for "max-cache-size" has been changed from
cfg_type_sizeorpercent to cfg_type_maxcachesize.
2025-10-29 18:28:12 +00:00
Mark Andrews
012a47476d Fix "shutdown system test crashed in dns_dispatchmgr_getblackhole"
While shutting down view->dispatchmgr is no longer valid.  Attach
to it and when creates a fetch context and use that pointer instead
of view->dispatchmgr.  Use dns_view_getdispatchmgr to do the attaching
as view->dispatchmgr is it managed using rcu.
2025-10-28 09:02:12 +11:00
Colin Vidal
cc91a5d1ec introduce cfg_obj_clone to clone a config tree
Introduce `cfg_obj_clone` which takes a `cfg_obj_t` node and clones it.
it allocates a new node, copies its scalar values and recursively
allocates child nodes, copying their scalar values as well and so on.

Internally, a new method `cfg_copyfunc_t` copy is added in `cfg_rep_t`,
which enables implementing a copy function specific for each
representation type a node can hold.
2025-10-27 21:33:18 +01:00
Mark Andrews
3594ad04e5 Remove unnecessary NULL checks in parser.c
In cfg_parse_buffer and cfg_parse_file 'pctx' was being checked
for being non-NULL when it was guarenteed to be non-NULL.  This
raised Coverity issues ID 637688 and ID 637689.
2025-10-28 06:28:52 +11:00
Ondřej Surý
871bce312b Fix assertion failure from arc4random_uniform with invalid limit
When the arc4random_uniform() is called on NetBSD with upper_bound that
makes no sense statistically (0 or 1), the call crashes the calling
program.  Fix this by returning 0 when upper bound is < 2 as does Linux,
FreeBSD and NetBSD.  (Hint: System CSPRNG should never crash.)
2025-10-24 22:20:43 +02:00
Evan Hunt
2877b57735 restore the former change_directory logging
change_directory() now lives in libisccfg. when it was moved,
the logging behavior changed: previously it had been logged
by named only, in the general logging category, and without the
named.conf filename and line number. it was not logged by
named-checkconf. this behavior has now been restored.
2025-10-23 13:01:31 -07:00
Colin Vidal
6b5246b3d2 ensure parser/cfg_obj log includes the line number
Since the `file` property of cfg_obj_t can now be null (instead of
"none"), cfg_obj_t would take a fallback flow where the line was not
logged. This fixes it.

Also, add the log line when parser_complain is called and `file` is null
(which might happend when parsing buffer only) to also include the line
number.
2025-10-23 13:01:11 -07:00
Evan Hunt
0db377da57 simplify and regularize cfg_* functions
- several functions that can no longer fail have been changed to
  type void, and unnecessary 'cleanup' sections were removed
- renamed cfg_create_obj() to cfg_obj_create(), and cfg_create_tuple()
  to cfg_tuple_create(), to match typical nomenclature.
- fixed a memory leak bug, in which an element could be removed
  from a list in delete_zoneconf() without being freed. this has
  been addressed by adding a cfg_list_unlink() function.
  list elements are now allocated based on the list they will
  be stored in, using the same mctx.
2025-10-23 13:01:10 -07:00
Evan Hunt
4f7f2dae59 simplify cfg_parser API
- the cfg_parser_create() and cfg_parser_destroy() calls are no
  longer used outside parser.c, so they are now static functions
- cfg_parser_attach(), cfg_parser_reset(), and cfg_parser_setflags()
  are no longer used at all, and have been removed.
- cfg_parser_mapadd() has been renamed for clarity to cfg_map_add().
2025-10-23 13:01:09 -07:00
Colin Vidal
d03f6e6fd4 cfg_parse_ functions internally handle the parser
Instead of (1) allocating a parser, (2) parsing a file/buffer then (3)
freeing the parser, the parser is now internally created/destroyed from
within the `cfg_parse_*` functions. This simplifies a lot the use cases,
especially around the error cases where the parser needs to be freed in
a cleanup goto.

The only trick was the parser callback mechanism, which would previously
have been set up between steps 1 and 2.  Since it's never been used for
any purpose other than the "directory" option, the chdir call has now
been moved inside the parser and the generic callback mechanism has been
removed, replacing CFG_CLAUSEFLAG_CALLBACK with CFG_CLAUSEFLAG_CHDIR.
2025-10-23 13:01:08 -07:00