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

8548 Commits

Author SHA1 Message Date
Ondřej Surý
efb385ecdc Clean up isc_mempool API
- isc_mempool_get() can no longer fail; when there are no more objects
  in the pool, more are always allocated. checking for NULL return is
  no longer necessary.
- the isc_mempool_setmaxalloc() and isc_mempool_getmaxalloc() functions
  are no longer used and have been removed.
2021-07-09 15:58:02 +02:00
Ondřej Surý
7cbfbc8faa Clean up the dns_dispatch_getudp API
Cleanup unused parts of dns_dispatch_getudp API, remove
dns_dispatch_getudp_dup() function and related code.
2021-07-09 15:58:02 +02:00
Ondřej Surý
f487c6948b Replace locked mempools with memory contexts
Current mempools are kind of hybrid structures - they serve two
purposes:

 1. mempool with a lock is basically static sized allocator with
    pre-allocated free items

 2. mempool without a lock is a doubly-linked list of preallocated items

The first kind of usage could be easily replaced with jemalloc small
sized arena objects and thread-local caches.

The second usage not-so-much and we need to keep this (in
libdns:message.c) for performance reasons.
2021-07-09 15:58:02 +02:00
Ondřej Surý
29c2e52484 The isc/platform.h header has been completely removed
The isc/platform.h header was left empty which things either already
moved to config.h or to appropriate headers.  This is just the final
cleanup commit.
2021-07-06 05:33:48 +00:00
Ondřej Surý
bf4a0e26dc Move NAME_MAX and PATH_MAX from isc/platform.h to isc/dir.h
The last remaining defines needed for platforms without NAME_MAX and
PATH_MAX (I'm looking at you, GNU Hurd) were moved to isc/dir.h where
it's prevalently used.
2021-07-06 05:33:48 +00:00
Ondřej Surý
d881e30b0a Remove LIB<*>_EXTERNAL_DATA defines
After Windows has been removed, the LIB<*>_EXTERNAL_DATA defines
were just dummy leftovers.  Remove them.
2021-07-06 05:33:48 +00:00
Matthijs Mekking
b4a0e19290 Fix CID 332468: Memory - illegal accesses (UNINIT)
*** CID 332468:  Memory - illegal accesses  (UNINIT)
/lib/dns/zone.c: 6613 in dns_zone_getdnsseckeys()
6607                 ISC_LIST_UNLINK(dnskeys, k1, link);
6608                 ISC_LIST_APPEND(*keys, k1, link);
6609             }
6610         }
6611     6612     failure:
>>>     CID 332468:  Memory - illegal accesses  (UNINIT)
>>>     Using uninitialized value "keyset.methods" when calling
>>>     "dns_rdataset_isassociated".
6613         if (dns_rdataset_isassociated(&keyset)) {
6614             dns_rdataset_disassociate(&keyset);
6615         }
6616         if (node != NULL) {
6617             dns_db_detachnode(db, &node);
6618         }

Fix by initializing the 'keyset' with 'dns_rdataset_init'.
2021-07-01 15:49:43 +02:00
Mark Andrews
c6fa8a1d45 Handle placeholder KEYDATA record
A placeholder keydata record can appear in a zone file.  Allow them
to be read back in.
2021-07-01 14:34:28 +10:00
Matthijs Mekking
39df3f0475 Protect dst key metadata with lock
The DST key metadata can be written by several threads in parralel.
Protect the dst_key_get* and dst_key_set* functions with a mutex.
2021-06-30 17:28:49 +02:00
Matthijs Mekking
28c5179904 Replace zone keyflock with zonemgr keymgmt
The old approach where each zone structure has its own mutex that
a thread needs to obtain multiple locks to do safe keyfile I/O
operations lead to a race condition ending in a possible deadlock.

Consider a zone in two views. Each such zone is stored in a separate
zone structure. A thread that needs to read or write the key files for
this zone needs to obtain both mutexes in seperate structures. If
another thread is working on the same zone in a different view, they
race to get the locks. It would be possible that thread1 grabs the
lock of the zone in view1, while thread2 wins the race for the lock
of the zone in view2. Now both threads try to get the other lock,  both
of them are already locked.

Ideally, when a thread wants to do key file operations, it only needs
to lock a single mutex. This commit introduces a key management hash
table, stored in the zonemgr structure. Each time a zone is being
managed, an object is added to the hash table (and removed when the
zone is being released). This object is identified by the zone name
and contains a mutex that needs to be locked prior to reading or
writing key files.

(cherry-picked from commit ef4619366d49efd46f9fae5f75c4a67c246ba2e6)
2021-06-30 17:28:49 +02:00
Matthijs Mekking
f7872dbd20 Add checkds code
Similar to notify, add code to send and keep track of checkds requests.

On every zone_rekey event, we will check the DS at parental agents
(but we will only actually query parental agents if theree is a DS
scheduled to be published/withdrawn).

On a zone_rekey event, we will first clear the ongoing checkds requests.
Reset the counter, to avoid continuing KSK rollover premature.

This has the risk that if zone_rekey events happen too soon after each
other, there are redundant DS queries to the parental agents. But
if TTLs and the configured durations in the dnssec-policy are sane (as
in not ridiculous short) the chance of this happening is low.
2021-06-30 17:28:49 +02:00
Matthijs Mekking
1a50554963 Add checkds log notice
When the checkds published/withdrawn is activated, log a notice. Can
be used for testing, but also operationally useful.
2021-06-30 17:28:48 +02:00
Matthijs Mekking
6e2c24be7c Add key metadata for DS published/withdrawn
In order to keep track of how many parents have the DS for a given key
published or withdrawn, keep a counter.
2021-06-30 17:28:48 +02:00
Matthijs Mekking
40331a20c4 Add helpful function 'dns_zone_getdnsseckeys'
This code gathers DNSSEC keys from key files and from the DNSKEY RRset.
It is used for the 'rndc dnssec -status' command, but will also be
needed for "checkds". Turn it into a function.
2021-06-30 17:28:48 +02:00
Matthijs Mekking
2872d6a12e Add "parental-source[-v6]" config option
Similar to "notify-source" and "transfer-source", add options to
set the source address when querying parental agents for DS records.
2021-06-30 17:28:48 +02:00
Matthijs Mekking
c9b7f62767 Add dst_key_role function
Change the static function 'get_ksk_zsk' to a library function that
can be used to determine the role of a dst_key. Add checks if the
boolean parameters to store the role are not NULL. Rename to
'dst_key_role'.
2021-06-30 17:28:48 +02:00
Matthijs Mekking
6f92d4b9a5 Parse "parental-agents" configuration
Parse the new "parental-agents" configuration and store it in the zone
structure.
2021-06-30 17:28:48 +02:00
Matthijs Mekking
6040c71478 Make "primaries" config parsing generic
Make the code to parse "primaries" configuration more generic so
it can be reused for "parental-agents".
2021-06-30 17:28:48 +02:00
Matthijs Mekking
0311705d4b Add parental-agents configuration
Introduce a way to configure parental agents that can be used to
query DS records to be used in automatic key rollovers.
2021-06-30 17:28:47 +02:00
Matthijs Mekking
10055d44e3 Fix setnsec3param hang on shutdown
When performing the 'setnsec3param' task, zones that are not loaded will have
their task rescheduled. We should do this only if the zone load is still
pending, this prevents zones that failed to load get stuck in a busy wait and
causing a hang on shutdown.
2021-06-28 10:35:34 +02:00
Ondřej Surý
e59a359929 Move the include Makefile.tests to the bottom of Makefile.am(s)
The Makefile.tests was modifying global AM_CFLAGS and LDADD and could
accidentally pull /usr/include to be listed before the internal
libraries, which is known to cause problems if the headers from the
previous version of BIND 9 has been installed on the build machine.
2021-06-24 15:33:52 +02:00
Ondřej Surý
c7a11bd5b4 Add rbtdb setownercase/getownercase unit test
This commit adds a unittest that tests private rdataset_getownercase()
and rdataset_setownercase() methods from rbtdb.c.  The test setups
minimal mock dns_rbtdb_t and dns_rbtdbnode_t data structures.

As the rbtdb methods are generally hidden behind layers and layers, we
include the "rbtdb.c" directly from rbtdb_test.c, and thus we can use
the private methods and data structures directly.  This also opens up
opportunity to add more unittest for the rbtdb private functions without
going through all the layers.
2021-06-23 16:38:46 +02:00
Ondřej Surý
7ccbe52060 Use POSIX tolower(), toupper() and isupper() functions
In the code that rdataset_setownercase() and rdataset_getownercase() we
now use tolower()/toupper()/isupper() functions appropriately instead of
rolling our own code.
2021-06-23 11:12:00 +02:00
Matthijs Mekking
42c601ae14 Fix deadlock issue with key-directory and in-view
When locking key files for a zone, we iterate over all the views and
lock a mutex inside the zone structure. However, if we envounter an
in-view zone, we will try to lock the key files twice, one time for
the home view and one time for the in-view view. This will lead to
a deadlock because one thread is trying to get the same lock twice.
2021-06-22 09:04:11 +02:00
Mark Andrews
08eeebb6a7 Add w and W to maptoupper and maptolower tables 2021-06-18 11:29:45 +10:00
Michał Kępień
6b77583f54 Allow resetting hash table size limits for DNS DBs
When "max-cache-size" is changed to "unlimited" (or "0") for a running
named instance (using "rndc reconfig"), the hash table size limit for
each affected cache DB is not reset to the maximum possible value,
preventing those hash tables from being allowed to grow as a result of
new nodes being added.

Extend dns_rbt_adjusthashsize() to interpret "size" set to 0 as a signal
to remove any previously imposed limits on the hash table size.  Adjust
API documentation for dns_db_adjusthashsize() accordingly.  Move the
call to dns_db_adjusthashsize() from dns_cache_setcachesize() so that it
also happens when "size" is set to 0.
2021-06-17 17:09:37 +02:00
Michał Kępień
c096f91451 Allow hash tables for cache RBTs to be grown
Upon creation, each dns_rbt_t structure has its "maxhashbits" field
initialized to the value of the RBT_HASH_MAX_BITS preprocessor macro,
i.e. 32.  When the dns_rbt_adjusthashsize() function is called for the
first time for a given RBT (for cache RBTs, this happens when they are
first created, i.e. upon named startup), it lowers the value of the
"maxhashbits" field to the number of bits required to index the
requested number of hash table slots.  When a larger hash table size is
subsequently requested, the value of the "maxhashbits" field should be
increased accordingly, up to RBT_HASH_MAX_BITS.  However, the loop in
the rehash_bits() function currently ensures that the number of bits
necessary to index the resized hash table will not be larger than
rbt->maxhashbits instead of RBT_HASH_MAX_BITS, preventing the hash table
from being grown once the "maxhashbits" field of a given dns_rbt_t
structure is set to any value lower than RBT_HASH_MAX_BITS.

Fix by tweaking the loop guard condition in the rehash_bits() function
so that it compares the new number of bits used for indexing the hash
table against RBT_HASH_MAX_BITS rather than rbt->maxhashbits.
2021-06-17 17:09:37 +02:00
Ondřej Surý
4677bb28d1 Remove atomics emulated by a mutex-locked variable
Mutex atomics were intended to be used as a debugging tool only
and it has already served its purpose and it's not needed anymore.
2021-06-17 09:51:04 +02:00
Ondřej Surý
b3de93e54c Update the source code formatting using clang-format-12
clang-format now tries to keep the type-cast on the same line as the
variable.  Update the formatting.
2021-06-13 08:46:28 +02:00
Mark Andrews
098639dc59 Fix the variable checked by a post-load assertion
Instead of checking the value of the variable modified two lines earlier
(the number of SOA records present at the apex of the old version of the
zone), one of the RUNTIME_CHECK() assertions in zone_postload() checks
the number of SOA records present at the apex of the new version of the
zone, which is already checked before.  Fix the assertion by making it
check the correct variable.
2021-06-10 10:01:34 +02:00
Mark Andrews
2bc454dc2d Adjust acceptable count values
usleep(100000) can be slightly less than 10ms so allow the count
to reach 11.
2021-06-09 22:05:55 +00:00
Mark Andrews
3d66e97a28 Address race between zone_settimer and set_key_expiry_warning by
adding missing lock.

    WARNING: ThreadSanitizer: data race
    Read of size 4 at 0x000000000001 by thread T1 (mutexes: read M1, write M2):
    #0 isc_time_isepoch lib/isc/unix/time.c:110
    #1 zone_settimer lib/dns/zone.c:14649
    #2 dns_zone_maintenance lib/dns/zone.c:6281
    #3 dns_zonemgr_forcemaint lib/dns/zone.c:18190
    #4 view_loaded server.c:9654
    #5 call_loaddone lib/dns/zt.c:301
    #6 doneloading lib/dns/zt.c:575
    #7 zone_asyncload lib/dns/zone.c:2259
    #8 task_run lib/isc/task.c:845
    #9 isc_task_run lib/isc/task.c:938
    #10 isc__nm_async_task lib/isc/netmgr/netmgr.c:855
    #11 process_netievent lib/isc/netmgr/netmgr.c:934
    #12 process_queue lib/isc/netmgr/netmgr.c:1003
    #13 process_all_queues lib/isc/netmgr/netmgr.c:775
    #14 async_cb lib/isc/netmgr/netmgr.c:804
    #15 <null> <null>
    #16 isc__trampoline_run lib/isc/trampoline.c:191
    #17 <null> <null>

    Previous write of size 4 at 0x000000000001 by thread T2:
    #0 isc_time_set lib/isc/unix/time.c:93
    #1 set_key_expiry_warning lib/dns/zone.c:6430
    #2 del_sigs lib/dns/zone.c:6711
    #3 zone_resigninc lib/dns/zone.c:7113
    #4 zone_maintenance lib/dns/zone.c:11111
    #5 zone_timer lib/dns/zone.c:14588
    #6 task_run lib/isc/task.c:845
    #7 isc_task_run lib/isc/task.c:938
    #8 isc__nm_async_task lib/isc/netmgr/netmgr.c:855
    #9 process_netievent lib/isc/netmgr/netmgr.c:934
    #10 process_queue lib/isc/netmgr/netmgr.c:1003
    #11 process_all_queues lib/isc/netmgr/netmgr.c:775
    #12 async_cb lib/isc/netmgr/netmgr.c:804
    #13 <null> <null>
    #14 isc__trampoline_run lib/isc/trampoline.c:191
    #15 <null> <null>

    SUMMARY: ThreadSanitizer: data race lib/isc/unix/time.c:110 in isc_time_isepoch
2021-06-09 13:31:05 +00:00
Ondřej Surý
440fb3d225 Completely remove BIND 9 Windows support
The Windows support has been completely removed from the source tree
and BIND 9 now no longer supports native compilation on Windows.

We might consider reviewing mingw-w64 port if contributed by external
party, but no development efforts will be put into making BIND 9 compile
and run on Windows again.
2021-06-09 14:35:14 +02:00
Matthijs Mekking
0ae3ffdc1c Fix NSEC3 resalting upon restart
When named restarts, it will examine signed zones and checks if the
current denial of existence strategy matches the dnssec-policy. If not,
it will schedule to create a new NSEC(3) chain.

However, on startup the zone database may not be read yet, fooling
BIND that the denial of existence chain needs to be created. This
results in a replacement of the previous NSEC(3) chain.

Change the code such that if the NSEC3PARAM lookup failed (the result
did not return in ISC_R_SUCCESS or ISC_R_NOTFOUND), we will try
again later. The nsec3param structure has additional variables to
signal if the lookup is postponed. We also need to save the signal
if an explicit resalt was requested.

In addition to the two added boolean variables, we add a variable to
store the NSEC3PARAM rdata. This may have a yet to be determined salt
value. We can't create the private data yet because there may be a
mismatch in salt length and the NULL salt value.
2021-06-09 09:14:09 +02:00
Ondřej Surý
7e59b8a4a1 Pause the dbiterator when dumping the zone to the disk
When we rewrote the zone dumping to use the separate threadpool, the
dumping would acquire the read lock for the whole time the zone dumping
process is dumping the zone.

When combined with incoming IXFR that tries to acquire the write lock on
the same rwlock, we would end up blocking all the other readers.

In this commit, we pause the dbiterator every time we get next record
and before start dumping it to the disk.
2021-06-04 08:25:05 +00:00
Ondřej Surý
e83b6569da Indicate to the kernel that we won't be needing the zone dumps
Add a call to posix_fadvise() to indicate to the kernel, that `named`
won't be needing the dumped zone files any time soon with:

 * POSIX_FADV_DONTNEED - The specified data will not be accessed in the
   near future.

Notes:

 POSIX_FADV_DONTNEED attempts to free cached pages associated with the
 specified region. This is useful, for example, while streaming large
 files. A program may periodically request the kernel to free cached
 data that has already been used, so that more useful cached pages are
 not discarded instead.
2021-05-31 14:52:05 +02:00
Ondřej Surý
8a5c62de83 Refactor zone dumping code to use netmgr async threadpools
Previously, dumping the zones to the files were quantized, so it doesn't
slow down network IO processing.  With the introduction of network
manager asynchronous threadpools, we can move the IO intensive work to
use that API and we don't have to quantize the work anymore as it the
file IO won't block anything except other zone dumping processes.
2021-05-31 14:52:05 +02:00
Matthijs Mekking
f7f543d99b Reuse rdatset->ttl when dumping ancient RRsets
Rather than having an expensive 'expired' (fka 'stale_ttl') in the
rdataset structure, that is only used to be printed in a comment on
ancient RRsets, reuse the TTL field of the RRset.
2021-05-30 11:48:36 -07:00
Kevin Chen
0cdf85d204 Several serve-stale improvements
Commit a83c8cb0afd88d54b9cf67239f2495c9b0391e97 updated masterdump so
that stale records in "rndc dumpdb" output no longer shows 0 TTLs.  In
this commit we change the name of the `rdataset->stale_ttl` field to
`rdataset->expired` to make its purpose clearer, and set it to zero in
cases where it's unused.

Add 'rbtdb->serve_stale_ttl' to various checks so that stale records
are not purged from the cache when they've been stale for RBTDB_VIRTUAL
(300) seconds.

Increment 'ns_statscounter_usedstale' when a stale answer is used.

Note: There was a question of whether 'overmem_purge' should be
purging ancient records, instead of stale ones.  It is left as purging
stale records, since stale records could take up the majority of the
cache.

This submission is copyrighted Akamai Technologies, Inc. and provided
under an MPL 2.0 license.

This commit was originally authored by Kevin Chen, and was updated by
Matthijs Mekking to match recent serve-stale developments.
2021-05-30 11:45:35 -07:00
Mark Andrews
715a2c7fc1 Add missing initialisations
configuring with --enable-mutex-atomics flagged these incorrectly
initialised variables on systems where pthread_mutex_init doesn't
just zero out the structure.
2021-05-26 08:15:08 +00:00
Ondřej Surý
50270de8a0 Refactor the interface handling in the netmgr
The isc_nmiface_t type was holding just a single isc_sockaddr_t,
so we got rid of the datatype and use plain isc_sockaddr_t in place
where isc_nmiface_t was used before.  This means less type-casting and
shorter path to access isc_sockaddr_t members.

At the same time, instead of keeping the reference to the isc_sockaddr_t
that was passed to us when we start listening, we will keep a local
copy. This prevents the data race on destruction of the ns_interface_t
objects where pending nmsockets could reference the sockaddr of already
destroyed ns_interface_t object.
2021-05-26 09:43:12 +02:00
Mark Andrews
0a45af2e2f Consolidate xhdr fixups 2021-05-26 08:16:35 +10:00
Mark Andrews
00609f5094 Correct size calculation in dns_journal_iter_init()
* dns_journal_next() leaves the read point in the journal after the
transaction header so journal_seek() should be inside the loop.
* we need to recover from transaction header inconsistencies

Additionally when correcting for <size, serial0, serial1, 0> the
correct consistency check is isc_serial_gt() rather than
isc_serial_ge().  All instances updated.
2021-05-25 22:27:54 +10:00
Ondřej Surý
d0d37aa6d1 Don't set memory context name in resolver.c
We now attach to existing memory context instead of creating a new
memory context, so we should not set its name.
2021-05-25 07:25:44 +02:00
Ondřej Surý
a1c6fd5ede Adjust the fillcount and freemax for dns_message mempools
According to the measurements (recorded on GL!5085), the fillcount of 2
for namepool and fillcount of 4 for rdspool can fit 99.99% of request
for tested scenarios.

This was discovered by perf recording the single second recursive test
using flamethrower where the initial malloc lit up like a flare.
2021-05-24 20:44:58 +02:00
Ondřej Surý
28b65d8256 Reduce the number of clientmgr objects created
Previously, as a way of reducing the contention between threads a
clientmgr object would be created for each interface/IP address.

We tasks being more strictly bound to netmgr workers, this is no longer
needed and we can just create clientmgr object per worker queue (ncpus).

Each clientmgr object than would have a single task and single memory
context.
2021-05-24 20:44:54 +02:00
Ondřej Surý
aad7856b8e Don't create per bucket memory contexts in resolver
Similarly, the resolver code would create hundreds of memory contexts
just on the resolver setup.  The contention will be reduced directly in
the allocator, so for now just attach to the view memory instead of
creating separate memory context for each bucket.
2021-05-24 20:02:20 +02:00
Evan Hunt
b0aadaac8e rename dns_name_copynf() to dns_name_copy()
dns_name_copy() is now the standard name-copying function.
2021-05-22 00:37:27 -07:00
Evan Hunt
ea7b28f101 remove dns_name_copy() implementation
Remove dns_name_copy() and refactor the underlying code since
it will only be called by dns_name_copynf() now, and can't fail.
2021-05-22 00:22:32 -07:00
Evan Hunt
b1fe1b8ae3 remove the remaining uses of dns_name_copy()
dns_name_copy() has been replaced nearly everywhere with
dns_name_copynf().  this commit changes the last two uses of
the original function.  afterward, we can remove the old
dns_name_copy() implementation, and replace it with _copynf().
2021-05-22 00:22:32 -07:00