Commit graph

11826 commits

Author SHA1 Message Date
Michał Kępień
149ffc529d Tweak buffer sizes to prevent compilation warnings
For some libc implementations, BUFSIZ is small enough (e.g. 1024 for
musl libc) to trigger compilation warnings about insufficient size of
certain buffers.  Since the relevant buffers are used for printing DNS
names, increase their size to '(n + 1) * DNS_NAME_FORMATSIZE', where 'n'
is the number of DNS names which are printed to a given buffer.  This
results in somewhat arbitrary, albeit nicely-aligned and large enough
buffer sizes.

(cherry picked from commit 3384455659)
2019-07-30 21:25:46 +02:00
Michał Kępień
3f341b996d Always include <errno.h> instead of <sys/errno.h>
Including <sys/errno.h> instead of <errno.h> raises a compiler warning
when building against musl libc.  Always include <errno.h> instead of
<sys/errno.h> to prevent that compilation warning from being triggered
and to achieve consistency in this regard across the entire source tree.

(cherry picked from commit b5cd146033)
2019-07-30 21:25:46 +02:00
Michał Kępień
80669d8c89 Unify header ordering in unit tests
Make sure all unit tests include headers in a similar order:

 1. Three headers which must be included before <cmocka.h>.
 2. System headers.
 3. UNIT_TESTING definition, followed by the <cmocka.h> header.
 4. libisc headers.
 5. Headers from other BIND libraries.
 6. Local headers.

Also make sure header file names are sorted alphabetically within each
block of #include directives.

(cherry picked from commit 5381ac0fcc)
2019-07-30 21:25:45 +02:00
Michał Kępień
77dc5be6b4 Include <sched.h> where necessary for musl libc
All unit tests define the UNIT_TESTING macro, which causes <cmocka.h> to
replace malloc(), calloc(), realloc(), and free() with its own functions
tracking memory allocations.  In order for this not to break
compilation, the system header declaring the prototypes for these
standard functions must be included before <cmocka.h>.

Normally, these prototypes are only present in <stdlib.h>, so we make
sure it is included before <cmocka.h>.  However, musl libc also defines
the prototypes for calloc() and free() in <sched.h>, which is included
by <pthread.h>, which is included e.g. by <isc/mutex.h>.  Thus, unit
tests including "dnstest.h" (which includes <isc/mem.h>, which includes
<isc/mutex.h>) after <cmocka.h> will not compile with musl libc as for
these programs, <sched.h> will be included after <cmocka.h>.

Always including <cmocka.h> after all other header files is not a
feasible solution as that causes the mock assertion macros defined in
<isc/util.h> to mangle the contents of <cmocka.h>, thus breaking
compilation.  We cannot really use the __noreturn__ or analyzer_noreturn
attributes with cmocka assertion functions because they do return if the
tested condition is true.  The problem is that what BIND unit tests do
is incompatible with Clang Static Analyzer's assumptions: since we use
cmocka, our custom assertion handlers are present in a shared library
(i.e. it is the cmocka library that checks the assertion condition, not
a macro in unit test code).  Redefining cmocka's assertion macros in
<isc/util.h> is an ugly hack to overcome that problem - unfortunately,
this is the only way we can think of to make Clang Static Analyzer
properly process unit test code.  Giving up on Clang Static Analyzer
being able to properly process unit test code is not a satisfactory
solution.

Undefining _GNU_SOURCE for unit test code could work around the problem
(musl libc's <sched.h> only defines the prototypes for calloc() and
free() when _GNU_SOURCE is defined), but doing that could introduce
discrepancies for unit tests including entire *.c files, so it is also
not a good solution.

All in all, including <sched.h> before <cmocka.h> for all affected unit
tests seems to be the most benign way of working around this musl libc
quirk.  While quite an ugly solution, it achieves our goals here, which
are to keep the benefit of proper static analysis of unit test code and
to fix compilation against musl libc.

(cherry picked from commit 59528d0e9d)
2019-07-30 21:25:30 +02:00
Evan Hunt
326349228a fix a bug that could cause an assert when configuring "geoip continent"
- incidentally fixed some typos in log messages
2019-07-25 15:55:00 -04:00
Ondřej Surý
16610d5477 Fix the lib/dns/tests/Makefile.in to work without LD_WRAP
(cherry picked from commit b558346437)
2019-07-23 09:06:12 -04:00
Mark Andrews
2524d76133 named-checkconf failed to report dnstap-output missing
from named.conf when dnstap was specified

(cherry picked from commit a4f38bec6a)
2019-07-23 21:09:34 +10:00
Evan Hunt
b8e6b68d88 Make the symbol wrapping work with dynamic linking
When the unit test is linked with dynamic libraries, the wrapping
doesn't occur, probably because it's different translation unit.

To workaround the issue, we provide thin wrappers with *real* symbol
names that just call the mocked functions.

(cherry picked from commit 839ed7894b)
2019-07-22 17:20:19 -04:00
Ondřej Surý
6ba4b02d67 Fix the configure.ac and Makefile.in to correctly test for --wrap
(cherry picked from commit 135519e59a)
2019-07-22 17:19:51 -04:00
Mark Andrews
4e63bacc04 Do not attempt to perform a DNS64 rewrite if RPZ returns NODATA.
(cherry picked from commit 1eb640049c)
2019-07-23 05:10:41 +10:00
Ondřej Surý
196b342bc9 Add new default siphash24 cookie algorithm
This commit changes the BIND cookie algorithms to match
draft-sury-toorop-dnsop-server-cookies-00.  Namely, it changes the Client Cookie
algorithm to use SipHash 2-4, adds the new Server Cookie algorithm using SipHash
2-4.  The change doesn't make the SipHash 2-4 to be the default algorithm, this
is up to the operator.
2019-07-21 17:30:53 -04:00
Ondřej Surý
84ff6a6963 Revise the Windows section of <isc/endian.h>
Add a comment and remove redundant definitions.
2019-07-21 15:37:22 -04:00
Ondřej Surý
c727a31eab Revise the macOS section of <isc/endian.h>
Move the macOS section of <isc/endian.h> to a lower spot as it is
believed not to be the most popular platform for running BIND.  Add a
comment and remove redundant definitions.
2019-07-21 15:37:22 -04:00
Ondřej Surý
a98c7408fc Make <isc/endian.h> detect GNU rather than Linux
Instead of only supporting Linux, try making <isc/endian.h> support
other GNU platforms as well.  Since some compilers define __GNUC__ on
BSDs (e.g. Clang on FreeBSD), move the relevant section to the bottom of
the platform-specific part of <isc/endian.h>, so that it only gets
evaluated when more specific platform determination criteria are not
met.  Also include <byteswap.h> so that any byte-swapping macros which
may be defined in that file on older platforms are used in the fallback
definitions of the nonstandard hto[bl]e{16,32,64}() and
[bl]e{16,32,64}toh() conversion functions.
2019-07-21 15:37:22 -04:00
Ondřej Surý
5b0f81e549 Add Solaris support for <isc/endian.h>
While Solaris does not support the nonstandard hto[bl]e{16,32,64}() and
[bl]e{16,32,64}toh() conversion functions, it does have some
byte-swapping macros available in <sys/byteorder.h>.  Ensure these
macros are used in the fallback definitions of the aforementioned
nonstandard functions.
2019-07-21 15:37:22 -04:00
Ondřej Surý
973d2991a0 Add fallback definitions to <isc/endian.h>
Since the hto[bl]e{16,32,64}() and [bl]e{16,32,64}toh() conversion
functions are nonstandard, add fallback definitions of these functions
to <isc/endian.h>, so that their unavailability does not prevent
compilation from succeeding.
2019-07-21 15:37:22 -04:00
Michał Kępień
588c14d5c9 Fix <isc/endian.h> on BSD systems
Current versions of DragonFly BSD, FreeBSD, NetBSD, and OpenBSD all
support the modern variants of functions converting values between host
and big-endian/little-endian byte order while older ones might not.
Ensure <isc/endian.h> works properly in both cases.
2019-07-21 15:37:21 -04:00
Ondřej Surý
3f826a923f Remove isc_hash_reverse function
(cherry picked from commit d5055665ca)
2019-07-21 15:32:57 -04:00
Ondřej Surý
4e04e3d861 Convert isc_hash functions to use isc_siphash24
(cherry picked from commit 2e7d82443f)
2019-07-21 15:32:57 -04:00
Ondřej Surý
2188a58171 Add tests for the isc_siphash24 function
(cherry picked from commit 2cbf633192)
2019-07-21 15:32:57 -04:00
Ondřej Surý
8d87ad53eb Add reference SipHash 2-4 implementation
(cherry picked from commit a197df137a)
2019-07-21 15:32:56 -04:00
Ondřej Surý
0b050ad4fd Add portable <isc/endian.h> header
(cherry picked from commit 0efc36c19a)
2019-07-21 15:32:56 -04:00
Ondřej Surý
aad88d2c00 Fix the memory leaks in GeoIP unit test
Each individual test opened GeoIP databases but the database handles were never
closed.  This commit moves the open/close from the individual unit tests into
the _setup and _teardown methods where they really belong.

(cherry picked from commit d1c7b79183)
2019-07-16 15:39:56 -07:00
Tinderbox User
1f83aca5e8 prep 9.14.4 2019-07-09 13:51:41 +00:00
Evan Hunt
b5032f7a8b add support for building GeoIP2 on windows 2019-07-04 12:05:32 -07:00
Evan Hunt
2b8cdc06f9 fix broken windows build
The MSVS C compiler requires every struct to have at least one member.
The dns_geoip_databases_t structure had one set of members for
HAVE_GEOIP and a different set for HAVE_GEOIP2, and none when neither
API is in use.

This commit silences the compiler error by moving the declaration of
dns_geoip_databases_t to types.h as an opaque reference, and commenting
out the contents of geoip.h when neither version of GeoIP is enabled.

(cherry picked from commit 81fcde5953)
2019-07-03 10:00:28 -07:00
Ondřej Surý
d995dc4661 Add rules to make sure subdirs are always built before testdirs
(cherry picked from commit 723433cbc6)
2019-07-02 19:40:26 +02:00
Evan Hunt
7468036226 add GeoIP2 lookups to unit test
(cherry picked from commit 6399a70cb4)
2019-06-27 16:32:29 -07:00
Evan Hunt
0283ab7512 implement searching of geoip2 database
- revise mapping of search terms to database types to match the
  GeoIP2 schemas.
- open GeoIP2 databases when starting up; close when shutting down.
- clarify the logged error message when an unknown database type
  is configured.
- add new geoip ACL subtypes to support searching for continent in
  country databases.
- map geoip ACL subtypes to specific MMDB database queries.
- perform MMDB lookups based on subtype, saving state between
  queries so repeated lookups for the same address aren't necessary.

(cherry picked from commit 6e0b93e5a0)
2019-06-27 16:32:29 -07:00
Evan Hunt
7fc92bee0c add HAVE_GEOIP2 #ifdef branches, without implementing yet
(cherry picked from commit fe46d5bc34)
2019-06-27 16:25:29 -07:00
Evan Hunt
6a7e805796 add a search for GeoIP2 libraries in configure
- "--with-geoip" is used to enable the legacy GeoIP library.
- "--with-geoip2" is used to enable the new GeoIP2 library
  (libmaxminddb), and is on by default if the library is found.
- using both "--with-geoip" and "--with-geoip2" at the same time
  is an error.
- an attempt is made to determine the default GeoIP2 database path at
  compile time if pkg-config is able to report the module prefix. if
  this fails, it will be necessary to set the path in named.conf with
  geoip-directory
- Makefiles have been updated, and a stub lib/dns/geoip2.c has been
  added for the eventual GeoIP2 search implementation.

(cherry picked from commit fea6b5bf10)
2019-06-27 16:25:28 -07:00
Matthijs Mekking
04c8c43f09 DNSSEC sign metrics: CHANGES, doc, release note
Add some information about the new statistic-channel DNS sign
metrics. Also add a CHANGES and release note entry.

(cherry picked from commit 3a3f40e372)
2019-06-27 12:37:48 +02:00
Matthijs Mekking
97041a38a7 Also collect DNSSEC refresh signature statistics
In addition to gather how many times signatures are created per
key in a zone, also count how many of those signature creations are
because of DNSSEC maintenance.  These maintenance counters are
incremented if a signature is refreshed (but the RRset did not
changed), when the DNSKEY RRset is changed, and when that leads
to additional RRset / RRSIG updates (for example SOA, NSEC).

(cherry picked from commit 6f67546cd6)
2019-06-27 12:37:27 +02:00
Matthijs Mekking
2c494feee6 Update dnskey sign operations statistics
Update per key tag the stats counter when it creates a new signature.
This can happen upon a dynamic update, or when doing DNSSEC
maintenance.

(cherry picked from commit 312fa7f65e)
2019-06-27 12:37:27 +02:00
Matthijs Mekking
ec799c667d Add DNSSEC sign operations statistics channel
Add a new statistics structure to record how many sign operations
a key has made within a zone.

(cherry picked from commit d8cf7aedfa)
2019-06-27 12:37:27 +02:00
Evan Hunt
11b4bd4d7e allow glue in authoritative responses to root priming queries
- when processing authoritative queries for ./NS, set 'gluedb' so
  that glue will be included in the response, regardless of how
  'minimal-responses' has been configured.

(cherry picked from commit e7684c7b64)
2019-06-26 09:21:05 -07:00
Evan Hunt
09fc9d4f87 don't overwrite the dns_master_loadfile() result before calling zone_postload()
if "rndc reload" fails, the result code is supposed to be passed to
zone_postload, but for inline-signing zones, the result can be
overwritten first by a call to the ZONE_TRYLOCK macro. this can lead
to the partially-loaded unsigned zone being synced over to the signed
zone instead of being rejected.

(cherry picked from commit 0b792bd37b)
2019-06-26 08:49:52 -07:00
Witold Kręcicki
0612da5d5d Make sure that recursclient gauge is calculated correctly.
We increase recursclients when we attach to recursion quota,
decrease when we detach. In some cases, when we hit soft
quota, we might attach to quota without increasing recursclients
gauge. We then decrease the gauge when we detach from quota,
and it causes the statistics to underflow.
Fix makes sure that we increase recursclients always when we
succesfully attach to recursion quota.

(cherry picked from commit 24cfee942f)
2019-06-26 11:08:44 +02:00
Mark Andrews
e98921fd8d silence unchecked return
(cherry picked from commit 134248531c)
2019-06-25 15:32:12 +10:00
Mark Andrews
7c963d0fc4 define ULLONG_MAX if not already defined
(cherry picked from commit 4110b9184d)
2019-06-25 09:48:59 +10:00
Michał Kępień
de65b8f0f8 Fix statistics for x86 Windows builds
Using atomic_int_fast64_t variables with atomic functions on x86 does
not cause Visual Studio to report build errors, but such operations
yield useless results.  Since the isc_stat_t type is unconditionally
typedef'd to atomic_int_fast64_t, any code performing atomic operations
on isc_stat_t variables is broken in x86 Windows builds.  Fix by using
the atomic_int_fast32_t type for isc_stat_t in x86 Windows builds.

(cherry picked from commit e21103f2d3)
2019-06-20 18:34:27 +02:00
Brian Conry
5de88e29f8 Bump DNS_CLIENTINFOMETHODS_VERSION/_AGE to 2/1 in clientinfo.h
BIND 9.11.0 has bumped DNS_CLIENTINFOMETHODS_VERSION and _AGE to
version 2 and 1 in the dlz_minimal.h because a member was addet to the
dnsclientinfo struct.  It was found out that the new member is not
used anywhere and there are no accessor functions therefore the change
was reverted.

Later on, it was found out that the revert caused some problems to the
users of BIND 9, and thus this changes takes a different approach by
syncing the values other way around.

(cherry picked from commit 39344dfb3e)
2019-06-20 14:18:50 +02:00
Tinderbox User
5a70336065 prep 9.14.3 2019-06-19 15:54:22 -07:00
Mark Andrews
878dfb1e52 move item_out test inside lock in dns_dispatch_getnext()
(cherry picked from commit 60c42f849d520564ed42e5ed0ba46b4b69c07712)
2019-06-19 15:54:21 -07:00
Michał Kępień
1d0bb1de10 Address GCC 9.1 -O3 compilation warnings
Compiling with -O3 triggers the following warnings with GCC 9.1:

    task.c: In function ‘isc_taskmgr_create’:
    task.c:1386:43: warning: ‘%04u’ directive output may be truncated writing between 4 and 10 bytes into a region of size 6 [-Wformat-truncation=]
     1386 |   snprintf(name, sizeof(name), "isc-worker%04u", i);
          |                                           ^~~~
    task.c:1386:32: note: directive argument in the range [0, 4294967294]
     1386 |   snprintf(name, sizeof(name), "isc-worker%04u", i);
          |                                ^~~~~~~~~~~~~~~~
    task.c:1386:3: note: ‘snprintf’ output between 15 and 21 bytes into a destination of size 16
     1386 |   snprintf(name, sizeof(name), "isc-worker%04u", i);
          |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    private_test.c: In function ‘private_nsec3_totext_test’:
    private_test.c:113:9: warning: array subscript 4 is outside array bounds of ‘uint32_t[1]’ {aka ‘unsigned int[1]’} [-Warray-bounds]
      113 |  while (*sp == '\0' && slen > 0) {
          |         ^~~
    private_test.c:106:11: note: while referencing ‘salt’
      106 |  uint32_t salt;
          |           ^~~~

Prevent these warnings from being triggered by increasing the size of
the relevant array (task.c) and reordering conditions (private_test.c).

(cherry picked from commit ce796ac1f4)
2019-06-11 10:19:04 +02:00
Mark Andrews
f33d9a825f POST(optlen)
(cherry picked from commit 4e97f7dccc)
2019-06-04 15:48:52 +10:00
Mark Andrews
65ece077c2 teach cppcheck that _assert_int_equal and _assert_int_not_equal don't return on failure
(cherry picked from commit 5d5d751c7f)
2019-06-04 15:23:49 +10:00
Witold Kręcicki
b6d11230b2 Fix a possible race between udp dispatch and socket code
There's a small possibility of race between udp dispatcher and
socket code - socket code can still hold internal reference to a
socket while dispatcher calls isc_socket_open, which can cause
an assertion failure. Fix it by relaxing the assertion test, and
instead simply locking the socket in isc_socket_open.

(cherry picked from commit e517c18d98)
2019-05-31 12:32:37 -07:00
Witold Kręcicki
60d0da833b Use experimental "_ A" minimization in relaxed mode.
qname minimization, even in relaxed mode, can fail on
some very broken domains. In relaxed mode, instead of
asking for "foo.bar NS" ask for "_.foo.bar A" to either
get a delegation or NXDOMAIN. It will require more queries
than regular mode for proper NXDOMAINs.

(cherry picked from commit ae52c2117e)
2019-05-31 09:25:44 +02:00
Witold Kręcicki
8b29a7cbf4 Don't SERVFAIL on lame delegations when doing minimization in relaxed mode.
qname minimization in relaxed mode should fall back to regular
resolution in case of failure.

(cherry picked from commit 2691e729f0)
2019-05-31 09:25:23 +02:00