2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-08-24 02:58:38 +00:00

81 Commits

Author SHA1 Message Date
Evan Hunt
d43dcef139 refactor filter-aaaa implementation
- the goal of this change is for AAAA filtering to be fully contained
   in the query logic, and implemented at discrete points that can be
   replaced with hook callouts later on.
 - the new code may be slightly less efficient than the old filter-aaaa
   implementation, but maximum efficiency was never a priority for AAAA
   filtering anyway.
 - we now use the rdataset RENDERED attribute to indicate that an AAAA
   rdataset should not be included when rendering the message. (this
   flag was originally meant to indicate that an rdataset has already
   been rendered and should not be repeated, but it can also be used to
   prevent rendering in the first place.)
 - the DNS_MESSAGERENDER_FILTER_AAAA, NS_CLIENTATTR_FILTER_AAAA,
   and DNS_RDATASETGLUE_FILTERAAAA flags are all now unnecessary and
   have been removed.
2018-12-06 10:29:10 -08:00
Evan Hunt
29897b14dc refactor query.c to make qctx more accessible
- the purpose of this change is allow for more well-defined hook points
  to be available in the query processing logic. some functions that
  formerly didn't have access to 'qctx' do now; this is needed because
  'qctx' is what gets passed when calling a hook function.
- query_addrdataset() has been broken up into three separate functions
  since it used to do three unrelated things, and what was formerly
  query_addadditional() has been renamed query_additional_cb() for
  clarity.
- client->filter_aaaa is now qctx->filter_aaaa. (later, it will be moved
  into opaque storage in the qctx, for use by the filter-aaaa module.)
- cleaned up style and braces
2018-12-06 10:29:10 -08:00
Evan Hunt
70cc3f803e set up hooks.c to enable setting hook points and loading modules
- move hooks.h to public include directory
- ns_hooktable_init() initializes a hook table. if NULL is passed in, it
  initializes the global hook table
- ns_hooktable_save() saves a pointer to the current global hook table.
- ns_hooktable_reset() replaces the global hook table with different
  one
- ns_hook_add() adds hooks at specified hook points in a hook table (or
  the global hook table if the specified table is NULL)
- load and unload functions support dlopen() of hook modules (this is
  adapted from dyndb and not yet functional)
- began adding new hook points to query.c
2018-12-06 10:29:05 -08:00
Witold Kręcicki
929ea7c2c4 - Make isc_mutex_destroy return void
- Make isc_mutexblock_init/destroy return void
- Minor cleanups
2018-11-22 11:52:08 +00:00
Ondřej Surý
2f3eee5a4f isc_mutex_init returns 'void' 2018-11-22 11:51:49 +00:00
Mark Andrews
333f718dd3 don't use 'typename' as it is reserved in C++ 2018-11-14 13:45:20 -05:00
Mark Andrews
28442f11f0 log RPZ type and class 2018-11-08 22:48:28 -05:00
Ondřej Surý
23fff6c569 Hint the compiler with ISC_UNREACHABLE(); that code after INSIST(0); cannot be reached 2018-11-08 12:22:17 +07:00
Ondřej Surý
b2b43fd235 Turn (int & flag) into (int & flag) != 0 when implicitly typed to bool 2018-11-08 12:21:53 +07:00
Ondřej Surý
fbd2e47f51 Add small tweaks to the code to fix compilation when ISC assertions are disabled
While implementing the new unit testing framework cmocka, it was found that the
BIND 9 code doesn't compile when assertions are disabled or replaced with any
function (such as mock_assert() from cmocka unit testing framework) that's not
directly recognized as assertion by the compiler.

This made the compiler to complain about blocks of code that was recognized as
unreachable before, but now it isn't.

The changes in this commit include:

* assigns default values to couple of local variables,
* moves some return statements around INSIST assertions,
* adds __builtin_unreachable(); annotations after some INSIST assertions,
* fixes one broken assertion (= instead of ==)
2018-11-08 12:21:53 +07:00
Mark Andrews
d6f6eeda9d check requireservercookie even if rrl is configured 2018-11-06 10:10:04 +11:00
Mark Andrews
e11cfafff2 always call RUNTIME_CHECK(result == ISC_R_SUCCESS); for dns_rdata_tostruct 2018-10-29 03:13:12 -04:00
Michał Kępień
2cb9e8a020 Replace the "mirror" zone option with "type mirror;"
Use a zone's 'type' field instead of the value of its DNS_ZONEOPT_MIRROR
option for checking whether it is a mirror zone.  This makes said zone
option and its associated helper function, dns_zone_mirror(), redundant,
so remove them.  Remove a check specific to mirror zones from
named_zone_reusable() since another check in that function ensures that
changing a zone's type prevents it from being reused during
reconfiguration.
2018-10-24 20:32:55 +02:00
Michał Kępień
e1bb8de6f0 Define a separate dns_zonetype_t for mirror zones
Rather than overloading dns_zone_slave and discerning between a slave
zone and a mirror zone using a zone option, define a separate enum
value, dns_zone_mirror, to be used exclusively by mirror zones.  Update
code handling slave zones to ensure it also handles mirror zones where
applicable.
2018-10-24 20:32:55 +02:00
Mark Andrews
b6e2d7bca9 use ns_client_log 2018-10-23 12:15:25 +00:00
Mark Andrews
ffb9f721f0 log pre rrl check state 2018-10-23 12:15:25 +00:00
Witold Kręcicki
70a1ba20ec QNAME miminimization should create a separate fetch context for each fetch -
this makes the cache more efficient and eliminates duplicates queries.
2018-10-23 12:15:04 +00:00
Witold Kręcicki
b5c9a8caad Set result to SERVFAIL if upstream responded with FORMERR
Commit ba912435427cf884fdc1ca26743eba6c00439106 causes the resolver to
respond to a client query with FORMERR when all upstream queries sent to
the servers authoritative for QNAME elicit FORMERR responses.  This
happens because resolver code returns DNS_R_FORMERR in such a case and
dns_result_torcode() acts as a pass-through for all arguments which are
already a valid RCODE.

The correct RCODE to set in the response returned to the client in the
case described above is SERVFAIL.  Make sure this happens by overriding
the RCODE in query_gotanswer(), on the grounds that any format errors in
the client query itself should be caught long before execution reaches
that point.  This change should not reduce query error logging accuracy
as the resolver code itself reports the exact reason for returning a
DNS_R_FORMERR result using log_formerr().
2018-10-23 13:50:27 +02:00
Michał Kępień
ba91243542 Do not set qctx->result to DNS_R_SERVFAIL unless necessary
In some cases, setting qctx->result to DNS_R_SERVFAIL causes the value
of a 'result' variable containing a more specific failure reason to be
effectively discarded.  This may cause certain query error log messages
to lack specificity despite a more accurate problem cause being
determined during query processing.

In other cases, qctx->result is set to DNS_R_SERVFAIL even though a more
specific error (e.g. ISC_R_NOMEMORY) could be explicitly indicated.

Since the response message's RCODE is derived from qctx->result using
dns_result_torcode(), which handles a number of possible isc_result_t
values and returns SERVFAIL for anything not explicitly listed, it is
fine to set qctx->result to something more specific than DNS_R_SERVFAIL
(in fact, this is already being done in a few cases).  Modify most
QUERY_ERROR() calls so that qctx->result is set to a more specific error
code when possible.  Adjust query_error() so that statistics are still
calculated properly.  Remove the RECURSE_ERROR() macro which was
introduced exactly because qctx->result could be set to DNS_R_SERVFAIL
instead of DNS_R_DUPLICATE or DNS_R_DROP, which need special handling.
Modify dns_sdlz_putrr() so that it returns DNS_R_SERVFAIL when a DLZ
driver returns invalid RDATA, in order to prevent setting RCODE to
FORMERR (which is what dns_result_torcode() translates e.g. DNS_R_SYNTAX
to) while responding authoritatively.
2018-10-08 12:47:28 +02:00
Michał Kępień
b3cd868c4b Remove the 'want_stale' field from struct query_ctx
As the previous commit makes the 'want_stale' field of struct query_ctx
redundant, remove it.
2018-10-08 12:47:28 +02:00
Michał Kępień
cb48d410d8 Set up stale response lookup before query_done() is called
When something goes wrong while recursing for an answer to a query,
query_gotanswer() sets a flag (qctx->want_stale) in the query context.
query_done() is subsequently called and it can either set up a stale
response lookup (if serve-stale is enabled) or conclude that a SERVFAIL
response should be sent.  This may cause confusion when looking at query
error logs since the QUERY_ERROR() line responsible for setting the
response's RCODE to SERVFAIL is not in a catch-all branch of a switch
statement inside query_gotanswer() (like it is for authoritative
responses) but rather in a code branch which appears to have something
to do with serve-stale, even when the latter is not enabled.

Extract the part of query_done() responsible for checking serve-stale
configuration and optionally setting up a stale response lookup into a
separate function, query_usestale(), shifting the responsibility for
setting the response's RCODE to SERVFAIL to the same QUERY_ERROR() line
in query_gotanswer() which is evaluated for authoritative responses.
2018-10-08 12:47:28 +02:00
Evan Hunt
2b61b83199 check both allow-query-cache and allow-query-cache-on 2018-09-27 21:48:44 -07:00
Evan Hunt
6a3afe2778 fix a formatting error in logged RPZ error messages 2018-09-27 19:59:21 -04:00
Tony Finch
9407d9e266 RPZ now treats covering NSEC records the same as negative answers 2018-09-27 14:53:34 -07:00
Mark Andrews
1056376d10 when filter-aaaa and dns64 are both configured a assertion failure could occur 2018-08-24 09:26:54 +10:00
Ondřej Surý
bdc9860262 Fix !!validate typo to -> !validate 2018-08-11 04:07:46 -04:00
Ondřej Surý
994e656977 Replace custom isc_boolean_t with C standard bool type 2018-08-08 09:37:30 +02:00
Ondřej Surý
cb6a185c69 Replace custom isc_u?intNN_t types with C99 u?intNN_t types 2018-08-08 09:37:28 +02:00
Michał Kępień
8e3fc5725f Extract code preparing a delegation response to a separate function
Changes introduced by the previous two commits make the parts of
query_delegation() and query_zone_delegation() which prepare a
delegation response functionally equivalent.  Extract this code into a
separate function, query_prepare_delegation_response(), and then call
the latter from both query_delegation() and query_zone_delegation() in
order to reduce code duplication.  Add a comment describing the purpose
of the extracted code.  Fix coding style issues.
2018-08-08 08:08:40 +02:00
Michał Kępień
7db4dedf6b Remove unused NS_QUERYATTR_CACHEGLUEOK query attribute
The NS_QUERYATTR_CACHEGLUEOK query attribute has no influence on query
processing.  Remove it.
2018-08-08 08:08:40 +02:00
Michał Kępień
b6c77202cb Restore zone database and zone node if cache search results are to be ignored
When query processing hits a delegation from a locally configured zone,
an attempt may be made to look for a better answer in the cache.  In
such a case, the zone-sourced delegation data is set aside and the
lookup is retried using the cache database.  When that lookup is
completed, a decision is made whether the answer found in the cache is
better than the answer found in the zone.

Currently, if the zone-sourced answer turns out to be better than the
one found in the cache:

  - qctx->zdb is not restored into qctx->db,
  - qctx->node, holding the zone database node found, is not even saved.

Thus, in such a case both qctx->db and qctx->node will point at cache
data.  This is not an issue for BIND versions which do not support
mirror zones because in these versions non-recursive queries always
cause the zone-sourced delegation to be returned and thus the
non-recursive part of query_delegation() is never reached if the
delegation is coming from a zone.  With mirror zones, however,
non-recursive queries may cause cache lookups even after a zone
delegation is found.  Leaving qctx->db assigned to the cache database
when query_delegation() determines that the zone-sourced delegation is
the best answer to the client's query prevents DS records from being
added to delegations coming from mirror zones.  Fix this issue by
keeping the zone database and zone node in qctx while the cache is
searched for an answer and then restoring them into qctx->db and
qctx->node, respectively, if the zone-sourced delegation turns out to be
the best answer.  Since this change means that qctx->zdb cannot be used
as the glue database any more as it will be reset to NULL by RESTORE(),
ensure that qctx->db is not a cache database before attaching it to
qctx->client->query.gluedb.

Furthermore, current code contains a conditional statement which
prevents a mirror zone from being used as a source of glue records.
Said statement was added to prevent assertion failures caused by
attempting to use a zone database's glue cache for finding glue for an
NS RRset coming from a cache database.  However, that check is overly
strict since it completely prevents glue from being added to delegations
coming from mirror zones.  With the changes described above in place,
the scenario this check was preventing can no longer happen, so remove
the aforementioned check.

If qctx->zdb is not NULL, qctx->zfname will also not be NULL;
qctx->zsigrdataset may be NULL in such a case, but query_putrdataset()
handles pointers to NULL pointers gracefully.  Remove redundant
conditional expressions to make the cleanup code in query_freedata()
match the corresponding sequences of SAVE() / RESTORE() macros more
closely.
2018-08-08 08:07:46 +02:00
Mark Andrews
69fd3f5ba4 use extracted netaddr rather than client->destaddr 2018-07-10 18:17:54 -07:00
Michał Kępień
c3f3b824e7 Treat mirror zone data as cache data for access control purposes
As mirror zone data should be treated the way validated, cached DNS
responses are, it should not be used when responding to clients who are
not allowed cache access.  Reuse code responsible for determining cache
database access for evaluating mirror zone access.
2018-06-28 13:38:39 +02:00
Michał Kępień
18ced94241 Rework query_checkcacheaccess()
Modify query_checkcacheaccess() so that it only contains a single return
statement rather than three and so that the "check_acl" variable is no
longer needed.  Tweak and expand comments.  Fix coding style issues.
2018-06-28 13:38:39 +02:00
Michał Kępień
cde16236fb Simplify query_getcachedb()
Modify query_getcachedb() so that it uses a common return path for both
success and failure.  Remove a redundant NULL check since 'db' will
never be NULL after being passed as a target pointer to dns_db_attach().
Fix coding style issues.
2018-06-28 13:38:39 +02:00
Michał Kępień
e9f17da6e9 Extract cache access checks in query_getcachedb() to a separate function
Extract the parts of query_getcachedb() responsible for checking whether
the client is allowed to access the cache to a separate function, so
that it can be reused for determining mirror zone access.
2018-06-28 13:38:39 +02:00
Michał Kępień
8d996fd79c Fall back to normal recursion when mirror zone data is unavailable
If transferring or loading a mirror zone fails, resolution should still
succeed by means of falling back to regular recursive queries.
Currently, though, if a slave zone is present in the zone table and not
loaded, a SERVFAIL response is generated.  Thus, mirror zones need
special handling in this regard.

Add a new dns_zt_find() flag, DNS_ZTFIND_MIRROR, and set it every time a
domain name is looked up rather than a zone itself.  Handle that flag in
dns_zt_find() in such a way that a mirror zone which is expired or not
yet loaded is ignored when looking up domain names, but still possible
to find when the caller wants to know whether the zone is configured.
This causes a fallback to recursion when mirror zone data is unavailable
without making unloaded mirror zones invisible to code checking a zone's
existence.
2018-06-28 13:38:39 +02:00
Michał Kępień
ad0ec2ea93 Do not treat mirror zone data as authoritative
Section 4 of RFC 7706 suggests that responses sourced from a local copy
of a zone should not have the AA bit set.  Follow that recommendation by
setting 'qctx->authoritative' to ISC_FALSE when a response to a query is
coming from a mirror zone.
2018-06-28 13:38:39 +02:00
Michał Kępień
179d5faa28 Ensure delegations inside mirror zones are properly handled for non-recursive queries
When a resolver is a regular slave (i.e. not a mirror) for some zone,
non-recursive queries for names below that slaved zone will return a
delegation sourced from it.  This behavior is suboptimal for mirror
zones as their contents should rather be treated as validated, cached
DNS responses.  Modify query_delegation() and query_zone_delegation() to
permit clients allowed cache access to check its contents for a better
answer when responding to non-recursive queries.
2018-06-28 13:38:39 +02:00
Evan Hunt
c8015eb33b style nits (mostly line length) 2018-06-12 09:18:47 +02:00
Witold Kręcicki
0698158eb0 QNAME minimization 2018-06-12 09:18:46 +02:00
Evan Hunt
8d923a05a9 ensure that we attempt to validate glue if it's signed
- incidentally fixed a bug in the dnssec system test where TTLs in the
  answer section rather than the additional section were being checked
2018-06-08 11:39:25 -07:00
Tony Finch
4b442c309d Move serve-stale logging to its own category, so that its verbosity can be curtailed. 2018-05-25 22:00:51 -07:00
Evan Hunt
9147a31b94 copyrights 2018-05-23 12:39:40 -04:00
Michał Kępień
46bb4dd124 Detect recursion loops during query processing
Interrupt query processing when query_recurse() attempts to ask the same
name servers for the same QNAME/QTYPE tuple for two times in a row as
this indicates that query processing may be stuck for an indeterminate
period of time, e.g. due to interactions between features able to
restart query_lookup().
2018-05-21 09:50:10 -07:00
Mukund Sivaraman
31bd3147d1 Don't validate non-pending glue when adding to the additional section 2018-05-16 08:15:36 +02:00
Mark Andrews
92e540df1e Silence clang static analyzer warnings; Consolidate multiple instances of splitting of batchline in dig into a single function. 2018-05-11 10:54:21 +10:00
Mark Andrews
68e9315c7d add named.conf option root-key-sentinel 2018-04-18 08:49:55 -07:00
Mark Andrews
8fc9f64df9 detect and processes root-key-sentinel labels. 2018-04-18 08:49:55 -07:00
Michał Kępień
4df4a8e731 Use dns_fixedname_initname() where possible
Replace dns_fixedname_init() calls followed by dns_fixedname_name()
calls with calls to dns_fixedname_initname() where it is possible
without affecting current behavior and/or performance.

This patch was mostly prepared using Coccinelle and the following
semantic patch:

    @@
    expression fixedname, name;
    @@
    -	dns_fixedname_init(&fixedname);
    	...
    -	name = dns_fixedname_name(&fixedname);
    +	name = dns_fixedname_initname(&fixedname);

The resulting set of changes was then manually reviewed to exclude false
positives and apply minor tweaks.

It is likely that more occurrences of this pattern can be refactored in
an identical way.  This commit only takes care of the low-hanging fruit.
2018-04-09 12:14:16 +02:00