1999-01-28 23:53:03 +00:00
|
|
|
/*
|
2018-02-15 11:56:13 -08:00
|
|
|
* Copyright (C) Internet Systems Consortium, Inc. ("ISC")
|
1999-01-28 23:53:03 +00:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: MPL-2.0
|
2021-06-03 08:37:05 +02:00
|
|
|
*
|
1999-01-28 23:53:03 +00:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, you can obtain one at https://mozilla.org/MPL/2.0/.
|
2018-02-23 09:53:12 +01:00
|
|
|
*
|
1999-01-28 23:53:03 +00:00
|
|
|
* See the COPYRIGHT file distributed with this work for additional
|
1999-02-11 04:55:38 +00:00
|
|
|
* information regarding copyright ownership.
|
1999-01-28 23:53:03 +00:00
|
|
|
*/
|
|
|
|
|
2005-04-27 04:57:32 +00:00
|
|
|
/*! \file */
|
2000-06-22 22:00:42 +00:00
|
|
|
|
1999-02-11 04:55:38 +00:00
|
|
|
/***
|
|
|
|
*** Imports
|
|
|
|
***/
|
|
|
|
|
2018-03-28 14:19:37 +02:00
|
|
|
#include <inttypes.h>
|
2018-04-17 08:29:14 -07:00
|
|
|
#include <stdbool.h>
|
2018-03-28 14:19:37 +02:00
|
|
|
|
2000-05-20 01:32:03 +00:00
|
|
|
#include <isc/buffer.h>
|
2023-07-10 11:36:19 +02:00
|
|
|
#include <isc/hash.h>
|
2000-11-16 22:33:53 +00:00
|
|
|
#include <isc/mem.h>
|
|
|
|
#include <isc/once.h>
|
2021-10-04 17:14:53 +02:00
|
|
|
#include <isc/result.h>
|
2000-11-16 22:33:53 +00:00
|
|
|
#include <isc/rwlock.h>
|
2000-05-08 14:38:29 +00:00
|
|
|
#include <isc/string.h>
|
2023-01-05 09:12:35 +01:00
|
|
|
#include <isc/tid.h>
|
2023-07-10 11:36:19 +02:00
|
|
|
#include <isc/urcu.h>
|
2000-04-28 01:12:23 +00:00
|
|
|
#include <isc/util.h>
|
1999-01-28 23:53:03 +00:00
|
|
|
|
2000-05-08 14:38:29 +00:00
|
|
|
#include <dns/callbacks.h>
|
2011-10-11 00:09:03 +00:00
|
|
|
#include <dns/clientinfo.h>
|
2000-11-16 22:33:53 +00:00
|
|
|
#include <dns/db.h>
|
2009-06-30 02:53:46 +00:00
|
|
|
#include <dns/dbiterator.h>
|
2000-08-10 18:38:10 +00:00
|
|
|
#include <dns/log.h>
|
1999-07-30 23:32:19 +00:00
|
|
|
#include <dns/master.h>
|
2000-05-20 01:32:03 +00:00
|
|
|
#include <dns/rdata.h>
|
1999-02-11 04:55:38 +00:00
|
|
|
#include <dns/rdataset.h>
|
2009-06-30 02:53:46 +00:00
|
|
|
#include <dns/rdatasetiter.h>
|
1999-02-11 04:55:38 +00:00
|
|
|
|
|
|
|
/***
|
|
|
|
*** Private Types
|
|
|
|
***/
|
|
|
|
|
2000-11-16 22:33:53 +00:00
|
|
|
struct dns_dbimplementation {
|
|
|
|
const char *name;
|
|
|
|
dns_dbcreatefunc_t create;
|
|
|
|
isc_mem_t *mctx;
|
|
|
|
void *driverarg;
|
|
|
|
ISC_LINK(dns_dbimplementation_t) link;
|
|
|
|
};
|
1999-02-11 04:55:38 +00:00
|
|
|
|
|
|
|
/***
|
|
|
|
*** Supported DB Implementations Registry
|
|
|
|
***/
|
|
|
|
|
|
|
|
/*
|
2000-11-16 22:33:53 +00:00
|
|
|
* Built in database implementations are registered here.
|
1999-02-11 04:55:38 +00:00
|
|
|
*/
|
1999-01-28 23:53:03 +00:00
|
|
|
|
2023-10-01 01:06:49 -07:00
|
|
|
#include "db_p.h"
|
2023-05-08 17:44:12 -07:00
|
|
|
#include "rbtdb_p.h"
|
1999-01-28 23:53:03 +00:00
|
|
|
|
2021-09-15 01:40:31 -07:00
|
|
|
unsigned int dns_pps = 0U;
|
|
|
|
|
2000-11-16 22:33:53 +00:00
|
|
|
static ISC_LIST(dns_dbimplementation_t) implementations;
|
|
|
|
static isc_rwlock_t implock;
|
|
|
|
static isc_once_t once = ISC_ONCE_INIT;
|
|
|
|
|
|
|
|
static dns_dbimplementation_t rbtimp;
|
|
|
|
|
|
|
|
static void
|
2001-07-24 05:23:38 +00:00
|
|
|
initialize(void) {
|
Add the reader-writer synchronization with modified C-RW-WP
This changes the internal isc_rwlock implementation to:
Irina Calciu, Dave Dice, Yossi Lev, Victor Luchangco, Virendra
J. Marathe, and Nir Shavit. 2013. NUMA-aware reader-writer locks.
SIGPLAN Not. 48, 8 (August 2013), 157–166.
DOI:https://doi.org/10.1145/2517327.24425
(The full article available from:
http://mcg.cs.tau.ac.il/papers/ppopp2013-rwlocks.pdf)
The implementation is based on the The Writer-Preference Lock (C-RW-WP)
variant (see the 3.4 section of the paper for the rationale).
The implemented algorithm has been modified for simplicity and for usage
patterns in rbtdb.c.
The changes compared to the original algorithm:
* We haven't implemented the cohort locks because that would require a
knowledge of NUMA nodes, instead a simple atomic_bool is used as
synchronization point for writer lock.
* The per-thread reader counters are not being used - this would
require the internal thread id (isc_tid_v) to be always initialized,
even in the utilities; the change has a slight performance penalty,
so we might revisit this change in the future. However, this change
also saves a lot of memory, because cache-line aligned counters were
used, so on 32-core machine, the rwlock would be 4096+ bytes big.
* The readers use a writer_barrier that will raise after a while when
readers lock can't be acquired to prevent readers starvation.
* Separate ingress and egress readers counters queues to reduce both
inter and intra-thread contention.
2021-03-24 17:52:56 +01:00
|
|
|
isc_rwlock_init(&implock);
|
2000-11-16 22:33:53 +00:00
|
|
|
|
|
|
|
rbtimp.name = "rbt";
|
2023-05-08 17:44:12 -07:00
|
|
|
rbtimp.create = dns__rbtdb_create;
|
2000-11-16 22:33:53 +00:00
|
|
|
rbtimp.mctx = NULL;
|
|
|
|
rbtimp.driverarg = NULL;
|
|
|
|
ISC_LINK_INIT(&rbtimp, link);
|
|
|
|
|
|
|
|
ISC_LIST_INIT(implementations);
|
|
|
|
ISC_LIST_APPEND(implementations, &rbtimp, link);
|
|
|
|
}
|
|
|
|
|
2021-10-11 13:43:12 +02:00
|
|
|
static dns_dbimplementation_t *
|
2000-11-16 22:33:53 +00:00
|
|
|
impfind(const char *name) {
|
|
|
|
dns_dbimplementation_t *imp;
|
|
|
|
|
2008-04-01 23:47:10 +00:00
|
|
|
for (imp = ISC_LIST_HEAD(implementations); imp != NULL;
|
2020-02-13 18:16:57 +01:00
|
|
|
imp = ISC_LIST_NEXT(imp, link))
|
|
|
|
{
|
|
|
|
if (strcasecmp(name, imp->name) == 0) {
|
2000-11-16 22:33:53 +00:00
|
|
|
return (imp);
|
2020-02-13 18:16:57 +01:00
|
|
|
}
|
|
|
|
}
|
2000-11-16 22:33:53 +00:00
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
|
2023-07-10 11:36:19 +02:00
|
|
|
static void
|
|
|
|
call_updatenotify(dns_db_t *db);
|
|
|
|
|
1999-02-11 04:55:38 +00:00
|
|
|
/***
|
|
|
|
*** Basic DB Methods
|
|
|
|
***/
|
|
|
|
|
1999-12-23 00:09:04 +00:00
|
|
|
isc_result_t
|
2016-12-30 15:45:08 +11:00
|
|
|
dns_db_create(isc_mem_t *mctx, const char *db_type, const dns_name_t *origin,
|
2000-06-07 02:38:41 +00:00
|
|
|
dns_dbtype_t type, dns_rdataclass_t rdclass, unsigned int argc,
|
1999-01-28 23:53:03 +00:00
|
|
|
char *argv[], dns_db_t **dbp) {
|
2023-02-17 13:04:12 -08:00
|
|
|
dns_dbimplementation_t *impinfo = NULL;
|
2000-11-16 22:33:53 +00:00
|
|
|
|
2022-10-14 16:10:41 +02:00
|
|
|
isc_once_do(&once, initialize);
|
1999-02-11 04:55:38 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Create a new database using implementation 'db_type'.
|
|
|
|
*/
|
|
|
|
|
|
|
|
REQUIRE(dbp != NULL && *dbp == NULL);
|
|
|
|
REQUIRE(dns_name_isabsolute(origin));
|
1999-01-28 23:53:03 +00:00
|
|
|
|
2000-11-16 22:33:53 +00:00
|
|
|
RWLOCK(&implock, isc_rwlocktype_read);
|
|
|
|
impinfo = impfind(db_type);
|
|
|
|
if (impinfo != NULL) {
|
|
|
|
isc_result_t result;
|
|
|
|
result = ((impinfo->create)(mctx, origin, type, rdclass, argc,
|
|
|
|
argv, impinfo->driverarg, dbp));
|
|
|
|
RWUNLOCK(&implock, isc_rwlocktype_read);
|
2023-02-17 13:04:12 -08:00
|
|
|
|
|
|
|
#if DNS_DB_TRACE
|
|
|
|
fprintf(stderr, "dns_db_create:%s:%s:%d:%p->references = 1\n",
|
|
|
|
__func__, __FILE__, __LINE__ + 1, *dbp);
|
|
|
|
#endif
|
2000-11-16 22:33:53 +00:00
|
|
|
return (result);
|
|
|
|
}
|
|
|
|
|
|
|
|
RWUNLOCK(&implock, isc_rwlocktype_read);
|
1999-01-28 23:53:03 +00:00
|
|
|
|
2000-08-10 18:38:10 +00:00
|
|
|
isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE, DNS_LOGMODULE_DB,
|
|
|
|
ISC_LOG_ERROR, "unsupported database type '%s'", db_type);
|
|
|
|
|
2000-04-06 22:03:35 +00:00
|
|
|
return (ISC_R_NOTFOUND);
|
1999-01-28 23:53:03 +00:00
|
|
|
}
|
|
|
|
|
2023-02-17 13:04:12 -08:00
|
|
|
static void
|
|
|
|
dns__db_destroy(dns_db_t *db) {
|
|
|
|
(db->methods->destroy)(db);
|
1999-01-28 23:53:03 +00:00
|
|
|
}
|
|
|
|
|
2023-02-17 13:04:12 -08:00
|
|
|
#if DNS_DB_TRACE
|
|
|
|
ISC_REFCOUNT_TRACE_IMPL(dns_db, dns__db_destroy);
|
|
|
|
#else
|
|
|
|
ISC_REFCOUNT_IMPL(dns_db, dns__db_destroy);
|
|
|
|
#endif
|
1999-01-28 23:53:03 +00:00
|
|
|
|
2018-04-17 08:29:14 -07:00
|
|
|
bool
|
1999-01-28 23:53:03 +00:00
|
|
|
dns_db_iscache(dns_db_t *db) {
|
1999-02-11 04:55:38 +00:00
|
|
|
/*
|
|
|
|
* Does 'db' have cache semantics?
|
|
|
|
*/
|
2000-08-01 01:33:37 +00:00
|
|
|
|
1999-01-28 23:53:03 +00:00
|
|
|
REQUIRE(DNS_DB_VALID(db));
|
|
|
|
|
1999-02-11 04:55:38 +00:00
|
|
|
if ((db->attributes & DNS_DBATTR_CACHE) != 0) {
|
2018-04-17 08:29:14 -07:00
|
|
|
return (true);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
1999-02-11 04:55:38 +00:00
|
|
|
|
2018-04-17 08:29:14 -07:00
|
|
|
return (false);
|
1999-01-28 23:53:03 +00:00
|
|
|
}
|
|
|
|
|
2018-04-17 08:29:14 -07:00
|
|
|
bool
|
1999-01-28 23:53:03 +00:00
|
|
|
dns_db_iszone(dns_db_t *db) {
|
1999-02-11 04:55:38 +00:00
|
|
|
/*
|
|
|
|
* Does 'db' have zone semantics?
|
|
|
|
*/
|
2000-08-01 01:33:37 +00:00
|
|
|
|
1999-01-28 23:53:03 +00:00
|
|
|
REQUIRE(DNS_DB_VALID(db));
|
|
|
|
|
2000-06-07 02:38:41 +00:00
|
|
|
if ((db->attributes & (DNS_DBATTR_CACHE | DNS_DBATTR_STUB)) == 0) {
|
2018-04-17 08:29:14 -07:00
|
|
|
return (true);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2000-06-07 02:38:41 +00:00
|
|
|
|
2018-04-17 08:29:14 -07:00
|
|
|
return (false);
|
2000-06-07 02:38:41 +00:00
|
|
|
}
|
|
|
|
|
2018-04-17 08:29:14 -07:00
|
|
|
bool
|
2000-06-07 02:38:41 +00:00
|
|
|
dns_db_isstub(dns_db_t *db) {
|
|
|
|
/*
|
|
|
|
* Does 'db' have stub semantics?
|
|
|
|
*/
|
2000-08-01 01:33:37 +00:00
|
|
|
|
2000-06-07 02:38:41 +00:00
|
|
|
REQUIRE(DNS_DB_VALID(db));
|
|
|
|
|
|
|
|
if ((db->attributes & DNS_DBATTR_STUB) != 0) {
|
2018-04-17 08:29:14 -07:00
|
|
|
return (true);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
1999-02-11 04:55:38 +00:00
|
|
|
|
2018-04-17 08:29:14 -07:00
|
|
|
return (false);
|
1999-01-28 23:53:03 +00:00
|
|
|
}
|
|
|
|
|
2018-04-17 08:29:14 -07:00
|
|
|
bool
|
1999-09-07 18:12:11 +00:00
|
|
|
dns_db_issecure(dns_db_t *db) {
|
|
|
|
/*
|
|
|
|
* Is 'db' secure?
|
|
|
|
*/
|
2000-08-01 01:33:37 +00:00
|
|
|
|
1999-09-07 18:12:11 +00:00
|
|
|
REQUIRE(DNS_DB_VALID(db));
|
|
|
|
REQUIRE((db->attributes & DNS_DBATTR_CACHE) == 0);
|
|
|
|
|
2023-02-17 12:05:25 -08:00
|
|
|
if (db->methods->issecure != NULL) {
|
|
|
|
return ((db->methods->issecure)(db));
|
|
|
|
}
|
|
|
|
return (false);
|
1999-09-07 18:12:11 +00:00
|
|
|
}
|
|
|
|
|
2018-04-17 08:29:14 -07:00
|
|
|
bool
|
2000-08-18 18:25:28 +00:00
|
|
|
dns_db_ispersistent(dns_db_t *db) {
|
|
|
|
/*
|
|
|
|
* Is 'db' persistent?
|
|
|
|
*/
|
|
|
|
|
|
|
|
REQUIRE(DNS_DB_VALID(db));
|
|
|
|
|
clean up unused dns_db methods
to reduce the amount of common code that will need to be shared
between the separated cache and zone database implementations,
clean up unused portions of dns_db.
the methods dns_db_dump(), dns_db_isdnssec(), dns_db_printnode(),
dns_db_resigned(), dns_db_expirenode() and dns_db_overmem() were
either never called or were only implemented as nonoperational stub
functions: they have now been removed.
dns_db_nodefullname() was only used in one place, which turned out
to be unnecessary, so it has also been removed.
dns_db_ispersistent() and dns_db_transfernode() are used, but only
the default implementation in db.c was ever actually called. since
they were never overridden by database methods, there's no need to
retain methods for them.
in rbtdb.c, beginload() and endload() methods are no longer defined for
the cache database, because that was never used (except in a few unit
tests which can easily be modified to use the zone implementation
instead). issecure() is also no longer defined for the cache database,
as the cache is always insecure and the default implementation of
dns_db_issecure() returns false.
for similar reasons, hashsize() is no longer defined for zone databases.
implementation functions that are shared between zone and cache are now
prepended with 'dns__rbtdb_' so they can become nonstatic.
serve_stale_ttl is now a common member of dns_db.
2023-05-08 11:47:18 -07:00
|
|
|
if (db->methods->beginload == NULL) {
|
2023-02-17 12:05:25 -08:00
|
|
|
/* If the database can't be loaded, assume it's persistent */
|
|
|
|
return (true);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (false);
|
2000-08-18 18:25:28 +00:00
|
|
|
}
|
|
|
|
|
1999-02-01 21:21:35 +00:00
|
|
|
dns_name_t *
|
|
|
|
dns_db_origin(dns_db_t *db) {
|
1999-02-11 04:55:38 +00:00
|
|
|
/*
|
|
|
|
* The origin of the database.
|
|
|
|
*/
|
|
|
|
|
1999-02-01 21:21:35 +00:00
|
|
|
REQUIRE(DNS_DB_VALID(db));
|
|
|
|
|
1999-02-11 04:55:38 +00:00
|
|
|
return (&db->origin);
|
1999-02-01 21:21:35 +00:00
|
|
|
}
|
|
|
|
|
1999-04-20 22:26:12 +00:00
|
|
|
dns_rdataclass_t
|
|
|
|
dns_db_class(dns_db_t *db) {
|
|
|
|
/*
|
|
|
|
* The class of the database.
|
|
|
|
*/
|
|
|
|
|
|
|
|
REQUIRE(DNS_DB_VALID(db));
|
|
|
|
|
|
|
|
return (db->rdclass);
|
|
|
|
}
|
|
|
|
|
1999-12-23 00:09:04 +00:00
|
|
|
isc_result_t
|
2012-06-20 14:13:12 -05:00
|
|
|
dns_db_beginload(dns_db_t *db, dns_rdatacallbacks_t *callbacks) {
|
1999-07-30 23:32:19 +00:00
|
|
|
/*
|
|
|
|
* Begin loading 'db'.
|
|
|
|
*/
|
|
|
|
|
|
|
|
REQUIRE(DNS_DB_VALID(db));
|
2012-06-20 14:13:12 -05:00
|
|
|
REQUIRE(DNS_CALLBACK_VALID(callbacks));
|
1999-07-30 23:32:19 +00:00
|
|
|
|
2023-02-17 12:05:25 -08:00
|
|
|
if (db->methods->beginload != NULL) {
|
|
|
|
return ((db->methods->beginload)(db, callbacks));
|
|
|
|
}
|
|
|
|
return (ISC_R_NOTIMPLEMENTED);
|
1999-07-30 23:32:19 +00:00
|
|
|
}
|
|
|
|
|
1999-12-23 00:09:04 +00:00
|
|
|
isc_result_t
|
2012-06-20 14:13:12 -05:00
|
|
|
dns_db_endload(dns_db_t *db, dns_rdatacallbacks_t *callbacks) {
|
1999-07-30 23:32:19 +00:00
|
|
|
/*
|
|
|
|
* Finish loading 'db'.
|
|
|
|
*/
|
|
|
|
|
|
|
|
REQUIRE(DNS_DB_VALID(db));
|
2012-06-20 14:13:12 -05:00
|
|
|
REQUIRE(DNS_CALLBACK_VALID(callbacks));
|
|
|
|
REQUIRE(callbacks->add_private != NULL);
|
1999-07-30 23:32:19 +00:00
|
|
|
|
2023-02-17 12:05:25 -08:00
|
|
|
/*
|
|
|
|
* When dns_db_endload() is called, we call the onupdate function
|
|
|
|
* for all registered listeners, regardless of whether the underlying
|
|
|
|
* database has an 'endload' implementation.
|
|
|
|
*/
|
2023-07-10 11:36:19 +02:00
|
|
|
call_updatenotify(db);
|
2016-05-26 21:23:19 +02:00
|
|
|
|
2023-02-17 12:05:25 -08:00
|
|
|
if (db->methods->endload != NULL) {
|
|
|
|
return ((db->methods->endload)(db, callbacks));
|
|
|
|
}
|
|
|
|
|
|
|
|
return (ISC_R_NOTIMPLEMENTED);
|
1999-07-30 23:32:19 +00:00
|
|
|
}
|
|
|
|
|
1999-12-23 00:09:04 +00:00
|
|
|
isc_result_t
|
2018-04-03 13:22:09 +02:00
|
|
|
dns_db_load(dns_db_t *db, const char *filename, dns_masterformat_t format,
|
|
|
|
unsigned int options) {
|
1999-12-23 00:09:04 +00:00
|
|
|
isc_result_t result, eresult;
|
1999-07-30 23:32:19 +00:00
|
|
|
dns_rdatacallbacks_t callbacks;
|
|
|
|
|
1999-02-11 04:55:38 +00:00
|
|
|
/*
|
|
|
|
* Load master file 'filename' into 'db'.
|
|
|
|
*/
|
1999-01-29 07:03:42 +00:00
|
|
|
|
|
|
|
REQUIRE(DNS_DB_VALID(db));
|
|
|
|
|
1999-07-30 23:32:19 +00:00
|
|
|
if ((db->attributes & DNS_DBATTR_CACHE) != 0) {
|
2001-01-05 03:12:45 +00:00
|
|
|
options |= DNS_MASTER_AGETTL;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
1999-07-30 23:32:19 +00:00
|
|
|
|
|
|
|
dns_rdatacallbacks_init(&callbacks);
|
2012-06-20 14:13:12 -05:00
|
|
|
result = dns_db_beginload(db, &callbacks);
|
2000-04-06 22:03:35 +00:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
1999-07-30 23:32:19 +00:00
|
|
|
return (result);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2018-04-03 13:09:55 +02:00
|
|
|
result = dns_master_loadfile(filename, &db->origin, &db->origin,
|
|
|
|
db->rdclass, options, 0, &callbacks, NULL,
|
|
|
|
NULL, db->mctx, format, 0);
|
2012-06-20 14:13:12 -05:00
|
|
|
eresult = dns_db_endload(db, &callbacks);
|
1999-07-30 23:32:19 +00:00
|
|
|
/*
|
|
|
|
* We always call dns_db_endload(), but we only want to return its
|
1999-08-05 22:12:38 +00:00
|
|
|
* result if dns_master_loadfile() succeeded. If dns_master_loadfile()
|
1999-07-30 23:32:19 +00:00
|
|
|
* failed, we want to return the result code it gave us.
|
|
|
|
*/
|
2001-04-10 03:05:55 +00:00
|
|
|
if (eresult != ISC_R_SUCCESS &&
|
|
|
|
(result == ISC_R_SUCCESS || result == DNS_R_SEENINCLUDE))
|
|
|
|
{
|
1999-07-30 23:32:19 +00:00
|
|
|
result = eresult;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
1999-07-30 23:32:19 +00:00
|
|
|
|
|
|
|
return (result);
|
1999-01-29 07:03:42 +00:00
|
|
|
}
|
|
|
|
|
1999-02-11 04:55:38 +00:00
|
|
|
/***
|
|
|
|
*** Version Methods
|
|
|
|
***/
|
1999-01-28 23:53:03 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
dns_db_currentversion(dns_db_t *db, dns_dbversion_t **versionp) {
|
1999-02-11 04:55:38 +00:00
|
|
|
/*
|
|
|
|
* Open the current version for reading.
|
|
|
|
*/
|
2000-08-01 01:33:37 +00:00
|
|
|
|
1999-01-28 23:53:03 +00:00
|
|
|
REQUIRE(DNS_DB_VALID(db));
|
1999-03-04 02:42:40 +00:00
|
|
|
REQUIRE((db->attributes & DNS_DBATTR_CACHE) == 0);
|
1999-02-11 04:55:38 +00:00
|
|
|
REQUIRE(versionp != NULL && *versionp == NULL);
|
1999-01-28 23:53:03 +00:00
|
|
|
|
|
|
|
(db->methods->currentversion)(db, versionp);
|
|
|
|
}
|
|
|
|
|
1999-12-23 00:09:04 +00:00
|
|
|
isc_result_t
|
1999-01-28 23:53:03 +00:00
|
|
|
dns_db_newversion(dns_db_t *db, dns_dbversion_t **versionp) {
|
1999-02-11 04:55:38 +00:00
|
|
|
/*
|
|
|
|
* Open a new version for reading and writing.
|
|
|
|
*/
|
|
|
|
|
1999-01-28 23:53:03 +00:00
|
|
|
REQUIRE(DNS_DB_VALID(db));
|
1999-03-04 02:42:40 +00:00
|
|
|
REQUIRE((db->attributes & DNS_DBATTR_CACHE) == 0);
|
1999-02-11 04:55:38 +00:00
|
|
|
REQUIRE(versionp != NULL && *versionp == NULL);
|
1999-01-28 23:53:03 +00:00
|
|
|
|
2023-02-17 12:05:25 -08:00
|
|
|
if (db->methods->newversion != NULL) {
|
|
|
|
return ((db->methods->newversion)(db, versionp));
|
|
|
|
}
|
|
|
|
return (ISC_R_NOTIMPLEMENTED);
|
1999-01-28 23:53:03 +00:00
|
|
|
}
|
|
|
|
|
1999-04-19 22:51:48 +00:00
|
|
|
void
|
|
|
|
dns_db_attachversion(dns_db_t *db, dns_dbversion_t *source,
|
|
|
|
dns_dbversion_t **targetp) {
|
|
|
|
/*
|
|
|
|
* Attach '*targetp' to 'source'.
|
|
|
|
*/
|
|
|
|
|
|
|
|
REQUIRE(DNS_DB_VALID(db));
|
|
|
|
REQUIRE((db->attributes & DNS_DBATTR_CACHE) == 0);
|
|
|
|
REQUIRE(source != NULL);
|
2001-09-04 12:17:13 +00:00
|
|
|
REQUIRE(targetp != NULL && *targetp == NULL);
|
1999-04-19 22:51:48 +00:00
|
|
|
|
|
|
|
(db->methods->attachversion)(db, source, targetp);
|
|
|
|
|
|
|
|
ENSURE(*targetp != NULL);
|
|
|
|
}
|
|
|
|
|
1999-01-28 23:53:03 +00:00
|
|
|
void
|
2023-01-05 09:12:35 +01:00
|
|
|
dns__db_closeversion(dns_db_t *db, dns_dbversion_t **versionp,
|
|
|
|
bool commit DNS__DB_FLARG) {
|
1999-02-11 04:55:38 +00:00
|
|
|
/*
|
|
|
|
* Close version '*versionp'.
|
|
|
|
*/
|
|
|
|
|
1999-01-28 23:53:03 +00:00
|
|
|
REQUIRE(DNS_DB_VALID(db));
|
1999-03-04 02:42:40 +00:00
|
|
|
REQUIRE((db->attributes & DNS_DBATTR_CACHE) == 0);
|
1999-02-11 04:55:38 +00:00
|
|
|
REQUIRE(versionp != NULL && *versionp != NULL);
|
|
|
|
|
2023-01-05 09:12:35 +01:00
|
|
|
(db->methods->closeversion)(db, versionp, commit DNS__DB_FLARG_PASS);
|
1999-01-28 23:53:03 +00:00
|
|
|
|
2020-03-30 13:47:58 -07:00
|
|
|
if (commit) {
|
2023-07-10 11:36:19 +02:00
|
|
|
call_updatenotify(db);
|
2016-05-26 21:23:19 +02:00
|
|
|
}
|
|
|
|
|
1999-02-11 04:55:38 +00:00
|
|
|
ENSURE(*versionp == NULL);
|
1999-01-28 23:53:03 +00:00
|
|
|
}
|
|
|
|
|
1999-02-11 04:55:38 +00:00
|
|
|
/***
|
|
|
|
*** Node Methods
|
|
|
|
***/
|
1999-01-28 23:53:03 +00:00
|
|
|
|
1999-12-23 00:09:04 +00:00
|
|
|
isc_result_t
|
2023-01-05 09:12:35 +01:00
|
|
|
dns__db_findnode(dns_db_t *db, const dns_name_t *name, bool create,
|
|
|
|
dns_dbnode_t **nodep DNS__DB_FLARG) {
|
1999-02-11 04:55:38 +00:00
|
|
|
/*
|
|
|
|
* Find the node with name 'name'.
|
|
|
|
*/
|
|
|
|
|
1999-01-28 23:53:03 +00:00
|
|
|
REQUIRE(DNS_DB_VALID(db));
|
1999-02-11 04:55:38 +00:00
|
|
|
REQUIRE(nodep != NULL && *nodep == NULL);
|
1999-01-28 23:53:03 +00:00
|
|
|
|
2011-10-11 00:09:03 +00:00
|
|
|
if (db->methods->findnode != NULL) {
|
2023-01-05 09:12:35 +01:00
|
|
|
return ((db->methods->findnode)(db, name, create,
|
|
|
|
nodep DNS__DB_FLARG_PASS));
|
2011-10-11 00:09:03 +00:00
|
|
|
} else {
|
|
|
|
return ((db->methods->findnodeext)(db, name, create, NULL, NULL,
|
2023-01-05 09:12:35 +01:00
|
|
|
nodep DNS__DB_FLARG_PASS));
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2011-10-11 00:09:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
isc_result_t
|
2023-01-05 09:12:35 +01:00
|
|
|
dns__db_findnodeext(dns_db_t *db, const dns_name_t *name, bool create,
|
|
|
|
dns_clientinfomethods_t *methods,
|
|
|
|
dns_clientinfo_t *clientinfo,
|
|
|
|
dns_dbnode_t **nodep DNS__DB_FLARG) {
|
2011-10-11 00:09:03 +00:00
|
|
|
/*
|
|
|
|
* Find the node with name 'name', passing 'arg' to the database
|
|
|
|
* implementation.
|
|
|
|
*/
|
|
|
|
|
|
|
|
REQUIRE(DNS_DB_VALID(db));
|
|
|
|
REQUIRE(nodep != NULL && *nodep == NULL);
|
|
|
|
|
|
|
|
if (db->methods->findnodeext != NULL) {
|
|
|
|
return ((db->methods->findnodeext)(db, name, create, methods,
|
2023-01-05 09:12:35 +01:00
|
|
|
clientinfo,
|
|
|
|
nodep DNS__DB_FLARG_PASS));
|
2011-10-11 00:09:03 +00:00
|
|
|
} else {
|
2023-01-05 09:12:35 +01:00
|
|
|
return ((db->methods->findnode)(db, name, create,
|
|
|
|
nodep DNS__DB_FLARG_PASS));
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
1999-01-28 23:53:03 +00:00
|
|
|
}
|
|
|
|
|
2008-09-24 02:46:23 +00:00
|
|
|
isc_result_t
|
2023-01-05 09:12:35 +01:00
|
|
|
dns__db_findnsec3node(dns_db_t *db, const dns_name_t *name, bool create,
|
|
|
|
dns_dbnode_t **nodep DNS__DB_FLARG) {
|
2008-09-24 02:46:23 +00:00
|
|
|
/*
|
|
|
|
* Find the node with name 'name'.
|
|
|
|
*/
|
|
|
|
|
|
|
|
REQUIRE(DNS_DB_VALID(db));
|
|
|
|
REQUIRE(nodep != NULL && *nodep == NULL);
|
|
|
|
|
2023-01-05 09:12:35 +01:00
|
|
|
return ((db->methods->findnsec3node)(db, name, create,
|
|
|
|
nodep DNS__DB_FLARG_PASS));
|
2008-09-24 02:46:23 +00:00
|
|
|
}
|
|
|
|
|
1999-12-23 00:09:04 +00:00
|
|
|
isc_result_t
|
2023-01-05 09:12:35 +01:00
|
|
|
dns__db_find(dns_db_t *db, const dns_name_t *name, dns_dbversion_t *version,
|
|
|
|
dns_rdatatype_t type, unsigned int options, isc_stdtime_t now,
|
|
|
|
dns_dbnode_t **nodep, dns_name_t *foundname,
|
|
|
|
dns_rdataset_t *rdataset,
|
|
|
|
dns_rdataset_t *sigrdataset DNS__DB_FLARG) {
|
1999-04-05 20:47:20 +00:00
|
|
|
/*
|
|
|
|
* Find the best match for 'name' and 'type' in version 'version'
|
|
|
|
* of 'db'.
|
|
|
|
*/
|
|
|
|
|
|
|
|
REQUIRE(DNS_DB_VALID(db));
|
2003-09-30 06:00:40 +00:00
|
|
|
REQUIRE(type != dns_rdatatype_rrsig);
|
2018-07-11 10:46:25 +10:00
|
|
|
REQUIRE(nodep == NULL || *nodep == NULL);
|
1999-08-12 07:45:58 +00:00
|
|
|
REQUIRE(dns_name_hasbuffer(foundname));
|
2000-04-28 23:46:43 +00:00
|
|
|
REQUIRE(rdataset == NULL || (DNS_RDATASET_VALID(rdataset) &&
|
|
|
|
!dns_rdataset_isassociated(rdataset)));
|
1999-08-31 22:14:06 +00:00
|
|
|
REQUIRE(sigrdataset == NULL ||
|
|
|
|
(DNS_RDATASET_VALID(sigrdataset) &&
|
2000-04-28 23:46:43 +00:00
|
|
|
!dns_rdataset_isassociated(sigrdataset)));
|
1999-04-05 20:47:20 +00:00
|
|
|
|
2011-10-11 00:09:03 +00:00
|
|
|
if (db->methods->find != NULL) {
|
|
|
|
return ((db->methods->find)(db, name, version, type, options,
|
|
|
|
now, nodep, foundname, rdataset,
|
2023-01-05 09:12:35 +01:00
|
|
|
sigrdataset DNS__DB_FLARG_PASS));
|
2011-10-11 00:09:03 +00:00
|
|
|
} else {
|
2023-01-05 09:12:35 +01:00
|
|
|
return ((db->methods->findext)(
|
|
|
|
db, name, version, type, options, now, nodep, foundname,
|
|
|
|
NULL, NULL, rdataset, sigrdataset DNS__DB_FLARG_PASS));
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2011-10-11 00:09:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
isc_result_t
|
2023-01-05 09:12:35 +01:00
|
|
|
dns__db_findext(dns_db_t *db, const dns_name_t *name, dns_dbversion_t *version,
|
|
|
|
dns_rdatatype_t type, unsigned int options, isc_stdtime_t now,
|
|
|
|
dns_dbnode_t **nodep, dns_name_t *foundname,
|
|
|
|
dns_clientinfomethods_t *methods, dns_clientinfo_t *clientinfo,
|
|
|
|
dns_rdataset_t *rdataset,
|
|
|
|
dns_rdataset_t *sigrdataset DNS__DB_FLARG) {
|
2011-10-11 00:09:03 +00:00
|
|
|
/*
|
|
|
|
* Find the best match for 'name' and 'type' in version 'version'
|
|
|
|
* of 'db', passing in 'arg'.
|
|
|
|
*/
|
|
|
|
|
|
|
|
REQUIRE(DNS_DB_VALID(db));
|
|
|
|
REQUIRE(type != dns_rdatatype_rrsig);
|
2018-07-11 10:46:25 +10:00
|
|
|
REQUIRE(nodep == NULL || *nodep == NULL);
|
2011-10-11 00:09:03 +00:00
|
|
|
REQUIRE(dns_name_hasbuffer(foundname));
|
|
|
|
REQUIRE(rdataset == NULL || (DNS_RDATASET_VALID(rdataset) &&
|
|
|
|
!dns_rdataset_isassociated(rdataset)));
|
|
|
|
REQUIRE(sigrdataset == NULL ||
|
|
|
|
(DNS_RDATASET_VALID(sigrdataset) &&
|
|
|
|
!dns_rdataset_isassociated(sigrdataset)));
|
|
|
|
|
|
|
|
if (db->methods->findext != NULL) {
|
2023-01-05 09:12:35 +01:00
|
|
|
return ((db->methods->findext)(db, name, version, type, options,
|
|
|
|
now, nodep, foundname, methods,
|
|
|
|
clientinfo, rdataset,
|
|
|
|
sigrdataset DNS__DB_FLARG_PASS));
|
2011-10-11 00:09:03 +00:00
|
|
|
} else {
|
|
|
|
return ((db->methods->find)(db, name, version, type, options,
|
|
|
|
now, nodep, foundname, rdataset,
|
2023-01-05 09:12:35 +01:00
|
|
|
sigrdataset DNS__DB_FLARG_PASS));
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
1999-04-01 04:03:22 +00:00
|
|
|
}
|
|
|
|
|
1999-12-23 00:09:04 +00:00
|
|
|
isc_result_t
|
2023-01-05 09:12:35 +01:00
|
|
|
dns__db_findzonecut(dns_db_t *db, const dns_name_t *name, unsigned int options,
|
|
|
|
isc_stdtime_t now, dns_dbnode_t **nodep,
|
|
|
|
dns_name_t *foundname, dns_name_t *dcname,
|
|
|
|
dns_rdataset_t *rdataset,
|
|
|
|
dns_rdataset_t *sigrdataset DNS__DB_FLARG) {
|
1999-10-21 17:50:36 +00:00
|
|
|
/*
|
|
|
|
* Find the deepest known zonecut which encloses 'name' in 'db'.
|
2018-06-13 09:29:40 +02:00
|
|
|
* foundname is the zonecut, dcname is the deepest name we have
|
|
|
|
* in database that is part of queried name.
|
1999-10-21 17:50:36 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
REQUIRE(DNS_DB_VALID(db));
|
|
|
|
REQUIRE((db->attributes & DNS_DBATTR_CACHE) != 0);
|
2018-07-11 10:46:25 +10:00
|
|
|
REQUIRE(nodep == NULL || *nodep == NULL);
|
1999-10-21 17:50:36 +00:00
|
|
|
REQUIRE(dns_name_hasbuffer(foundname));
|
|
|
|
REQUIRE(sigrdataset == NULL ||
|
|
|
|
(DNS_RDATASET_VALID(sigrdataset) &&
|
2000-04-28 23:46:43 +00:00
|
|
|
!dns_rdataset_isassociated(sigrdataset)));
|
1999-10-21 17:50:36 +00:00
|
|
|
|
2023-02-17 12:05:25 -08:00
|
|
|
if (db->methods->findzonecut != NULL) {
|
2023-01-05 09:12:35 +01:00
|
|
|
return ((db->methods->findzonecut)(
|
|
|
|
db, name, options, now, nodep, foundname, dcname,
|
|
|
|
rdataset, sigrdataset DNS__DB_FLARG_PASS));
|
2023-02-17 12:05:25 -08:00
|
|
|
}
|
|
|
|
return (ISC_R_NOTIMPLEMENTED);
|
1999-10-21 17:50:36 +00:00
|
|
|
}
|
|
|
|
|
1999-01-28 23:53:03 +00:00
|
|
|
void
|
2023-01-05 09:12:35 +01:00
|
|
|
dns__db_attachnode(dns_db_t *db, dns_dbnode_t *source,
|
|
|
|
dns_dbnode_t **targetp DNS__DB_FLARG) {
|
1999-02-11 04:55:38 +00:00
|
|
|
/*
|
|
|
|
* Attach *targetp to source.
|
|
|
|
*/
|
|
|
|
|
1999-01-28 23:53:03 +00:00
|
|
|
REQUIRE(DNS_DB_VALID(db));
|
1999-02-11 04:55:38 +00:00
|
|
|
REQUIRE(source != NULL);
|
|
|
|
REQUIRE(targetp != NULL && *targetp == NULL);
|
1999-01-28 23:53:03 +00:00
|
|
|
|
2023-01-05 09:12:35 +01:00
|
|
|
(db->methods->attachnode)(db, source, targetp DNS__DB_FLARG_PASS);
|
1999-01-28 23:53:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2023-01-05 09:12:35 +01:00
|
|
|
dns__db_detachnode(dns_db_t *db, dns_dbnode_t **nodep DNS__DB_FLARG) {
|
1999-02-11 04:55:38 +00:00
|
|
|
/*
|
|
|
|
* Detach *nodep from its node.
|
|
|
|
*/
|
|
|
|
|
1999-01-28 23:53:03 +00:00
|
|
|
REQUIRE(DNS_DB_VALID(db));
|
1999-02-11 04:55:38 +00:00
|
|
|
REQUIRE(nodep != NULL && *nodep != NULL);
|
1999-01-28 23:53:03 +00:00
|
|
|
|
2023-01-05 09:12:35 +01:00
|
|
|
(db->methods->detachnode)(db, nodep DNS__DB_FLARG_PASS);
|
1999-02-11 04:55:38 +00:00
|
|
|
|
|
|
|
ENSURE(*nodep == NULL);
|
1999-01-28 23:53:03 +00:00
|
|
|
}
|
|
|
|
|
2007-03-06 00:38:58 +00:00
|
|
|
void
|
|
|
|
dns_db_transfernode(dns_db_t *db, dns_dbnode_t **sourcep,
|
|
|
|
dns_dbnode_t **targetp) {
|
|
|
|
REQUIRE(DNS_DB_VALID(db));
|
|
|
|
REQUIRE(targetp != NULL && *targetp == NULL);
|
|
|
|
REQUIRE(sourcep != NULL && *sourcep != NULL);
|
|
|
|
|
clean up unused dns_db methods
to reduce the amount of common code that will need to be shared
between the separated cache and zone database implementations,
clean up unused portions of dns_db.
the methods dns_db_dump(), dns_db_isdnssec(), dns_db_printnode(),
dns_db_resigned(), dns_db_expirenode() and dns_db_overmem() were
either never called or were only implemented as nonoperational stub
functions: they have now been removed.
dns_db_nodefullname() was only used in one place, which turned out
to be unnecessary, so it has also been removed.
dns_db_ispersistent() and dns_db_transfernode() are used, but only
the default implementation in db.c was ever actually called. since
they were never overridden by database methods, there's no need to
retain methods for them.
in rbtdb.c, beginload() and endload() methods are no longer defined for
the cache database, because that was never used (except in a few unit
tests which can easily be modified to use the zone implementation
instead). issecure() is also no longer defined for the cache database,
as the cache is always insecure and the default implementation of
dns_db_issecure() returns false.
for similar reasons, hashsize() is no longer defined for zone databases.
implementation functions that are shared between zone and cache are now
prepended with 'dns__rbtdb_' so they can become nonstatic.
serve_stale_ttl is now a common member of dns_db.
2023-05-08 11:47:18 -07:00
|
|
|
*targetp = *sourcep;
|
|
|
|
*sourcep = NULL;
|
1999-03-05 23:25:44 +00:00
|
|
|
}
|
|
|
|
|
1999-03-08 19:00:55 +00:00
|
|
|
/***
|
|
|
|
*** DB Iterator Creation
|
|
|
|
***/
|
|
|
|
|
1999-12-23 00:09:04 +00:00
|
|
|
isc_result_t
|
2008-09-24 02:46:23 +00:00
|
|
|
dns_db_createiterator(dns_db_t *db, unsigned int flags,
|
1999-03-08 19:00:55 +00:00
|
|
|
dns_dbiterator_t **iteratorp) {
|
|
|
|
/*
|
|
|
|
* Create an iterator for version 'version' of 'db'.
|
|
|
|
*/
|
|
|
|
|
|
|
|
REQUIRE(DNS_DB_VALID(db));
|
|
|
|
REQUIRE(iteratorp != NULL && *iteratorp == NULL);
|
2024-02-14 12:58:01 -08:00
|
|
|
REQUIRE((flags & (DNS_DB_NSEC3ONLY | DNS_DB_NONSEC3)) !=
|
|
|
|
(DNS_DB_NSEC3ONLY | DNS_DB_NONSEC3));
|
1999-03-08 19:00:55 +00:00
|
|
|
|
2023-02-17 12:04:32 -08:00
|
|
|
if (db->methods->createiterator != NULL) {
|
|
|
|
return (db->methods->createiterator(db, flags, iteratorp));
|
|
|
|
}
|
|
|
|
return (ISC_R_NOTIMPLEMENTED);
|
1999-03-08 19:00:55 +00:00
|
|
|
}
|
|
|
|
|
1999-02-11 04:55:38 +00:00
|
|
|
/***
|
|
|
|
*** Rdataset Methods
|
|
|
|
***/
|
|
|
|
|
1999-12-23 00:09:04 +00:00
|
|
|
isc_result_t
|
2023-01-05 09:12:35 +01:00
|
|
|
dns__db_findrdataset(dns_db_t *db, dns_dbnode_t *node, dns_dbversion_t *version,
|
|
|
|
dns_rdatatype_t type, dns_rdatatype_t covers,
|
|
|
|
isc_stdtime_t now, dns_rdataset_t *rdataset,
|
|
|
|
dns_rdataset_t *sigrdataset DNS__DB_FLARG) {
|
1999-01-28 23:53:03 +00:00
|
|
|
REQUIRE(DNS_DB_VALID(db));
|
1999-02-11 04:55:38 +00:00
|
|
|
REQUIRE(node != NULL);
|
|
|
|
REQUIRE(DNS_RDATASET_VALID(rdataset));
|
2000-04-28 23:46:43 +00:00
|
|
|
REQUIRE(!dns_rdataset_isassociated(rdataset));
|
2003-09-30 06:00:40 +00:00
|
|
|
REQUIRE(covers == 0 || type == dns_rdatatype_rrsig);
|
1999-08-31 22:14:06 +00:00
|
|
|
REQUIRE(type != dns_rdatatype_any);
|
1999-09-08 01:10:08 +00:00
|
|
|
REQUIRE(sigrdataset == NULL ||
|
|
|
|
(DNS_RDATASET_VALID(sigrdataset) &&
|
2000-04-28 23:46:43 +00:00
|
|
|
!dns_rdataset_isassociated(sigrdataset)));
|
1999-01-28 23:53:03 +00:00
|
|
|
|
2011-10-11 00:09:03 +00:00
|
|
|
return ((db->methods->findrdataset)(db, node, version, type, covers,
|
2023-01-05 09:12:35 +01:00
|
|
|
now, rdataset,
|
|
|
|
sigrdataset DNS__DB_FLARG_PASS));
|
1999-01-28 23:53:03 +00:00
|
|
|
}
|
|
|
|
|
1999-12-23 00:09:04 +00:00
|
|
|
isc_result_t
|
2023-01-05 09:12:35 +01:00
|
|
|
dns__db_allrdatasets(dns_db_t *db, dns_dbnode_t *node, dns_dbversion_t *version,
|
|
|
|
unsigned int options, isc_stdtime_t now,
|
|
|
|
dns_rdatasetiter_t **iteratorp DNS__DB_FLARG) {
|
1999-03-11 06:00:22 +00:00
|
|
|
/*
|
|
|
|
* Make '*iteratorp' an rdataset iteratator for all rdatasets at
|
|
|
|
* 'node' in version 'version' of 'db'.
|
|
|
|
*/
|
|
|
|
|
|
|
|
REQUIRE(DNS_DB_VALID(db));
|
|
|
|
REQUIRE(iteratorp != NULL && *iteratorp == NULL);
|
|
|
|
|
2022-11-16 10:47:40 +11:00
|
|
|
return ((db->methods->allrdatasets)(db, node, version, options, now,
|
2023-01-05 09:12:35 +01:00
|
|
|
iteratorp DNS__DB_FLARG_PASS));
|
1999-03-11 06:00:22 +00:00
|
|
|
}
|
|
|
|
|
1999-12-23 00:09:04 +00:00
|
|
|
isc_result_t
|
2023-01-05 09:12:35 +01:00
|
|
|
dns__db_addrdataset(dns_db_t *db, dns_dbnode_t *node, dns_dbversion_t *version,
|
|
|
|
isc_stdtime_t now, dns_rdataset_t *rdataset,
|
|
|
|
unsigned int options,
|
|
|
|
dns_rdataset_t *addedrdataset DNS__DB_FLARG) {
|
1999-02-11 04:55:38 +00:00
|
|
|
/*
|
|
|
|
* Add 'rdataset' to 'node' in version 'version' of 'db'.
|
|
|
|
*/
|
|
|
|
|
1999-01-28 23:53:03 +00:00
|
|
|
REQUIRE(DNS_DB_VALID(db));
|
1999-02-11 04:55:38 +00:00
|
|
|
REQUIRE(node != NULL);
|
1999-04-09 19:14:06 +00:00
|
|
|
REQUIRE(((db->attributes & DNS_DBATTR_CACHE) == 0 && version != NULL) ||
|
1999-06-16 21:02:17 +00:00
|
|
|
((db->attributes & DNS_DBATTR_CACHE) != 0 && version == NULL &&
|
2000-01-25 19:26:45 +00:00
|
|
|
(options & DNS_DBADD_MERGE) == 0));
|
2000-11-30 13:19:09 +00:00
|
|
|
REQUIRE((options & DNS_DBADD_EXACT) == 0 ||
|
|
|
|
(options & DNS_DBADD_MERGE) != 0);
|
1999-02-11 04:55:38 +00:00
|
|
|
REQUIRE(DNS_RDATASET_VALID(rdataset));
|
2000-04-28 23:46:43 +00:00
|
|
|
REQUIRE(dns_rdataset_isassociated(rdataset));
|
1999-04-20 22:31:39 +00:00
|
|
|
REQUIRE(rdataset->rdclass == db->rdclass);
|
1999-05-05 22:57:20 +00:00
|
|
|
REQUIRE(addedrdataset == NULL ||
|
|
|
|
(DNS_RDATASET_VALID(addedrdataset) &&
|
2000-04-28 23:46:43 +00:00
|
|
|
!dns_rdataset_isassociated(addedrdataset)));
|
1999-01-28 23:53:03 +00:00
|
|
|
|
2023-02-17 12:05:25 -08:00
|
|
|
if (db->methods->addrdataset != NULL) {
|
2023-01-05 09:12:35 +01:00
|
|
|
return ((db->methods->addrdataset)(
|
|
|
|
db, node, version, now, rdataset, options,
|
|
|
|
addedrdataset DNS__DB_FLARG_PASS));
|
2023-02-17 12:05:25 -08:00
|
|
|
}
|
|
|
|
return (ISC_R_NOTIMPLEMENTED);
|
1999-06-16 21:02:17 +00:00
|
|
|
}
|
|
|
|
|
1999-12-23 00:09:04 +00:00
|
|
|
isc_result_t
|
2023-01-05 09:12:35 +01:00
|
|
|
dns__db_subtractrdataset(dns_db_t *db, dns_dbnode_t *node,
|
|
|
|
dns_dbversion_t *version, dns_rdataset_t *rdataset,
|
|
|
|
unsigned int options,
|
|
|
|
dns_rdataset_t *newrdataset DNS__DB_FLARG) {
|
1999-06-16 21:02:17 +00:00
|
|
|
/*
|
|
|
|
* Remove any rdata in 'rdataset' from 'node' in version 'version' of
|
|
|
|
* 'db'.
|
|
|
|
*/
|
|
|
|
|
|
|
|
REQUIRE(DNS_DB_VALID(db));
|
|
|
|
REQUIRE(node != NULL);
|
1999-06-17 00:30:46 +00:00
|
|
|
REQUIRE((db->attributes & DNS_DBATTR_CACHE) == 0 && version != NULL);
|
1999-06-16 21:02:17 +00:00
|
|
|
REQUIRE(DNS_RDATASET_VALID(rdataset));
|
2000-04-28 23:46:43 +00:00
|
|
|
REQUIRE(dns_rdataset_isassociated(rdataset));
|
1999-06-16 21:02:17 +00:00
|
|
|
REQUIRE(rdataset->rdclass == db->rdclass);
|
|
|
|
REQUIRE(newrdataset == NULL ||
|
|
|
|
(DNS_RDATASET_VALID(newrdataset) &&
|
2000-04-28 23:46:43 +00:00
|
|
|
!dns_rdataset_isassociated(newrdataset)));
|
1999-06-16 21:02:17 +00:00
|
|
|
|
2023-02-17 12:05:25 -08:00
|
|
|
if (db->methods->subtractrdataset != NULL) {
|
|
|
|
return ((db->methods->subtractrdataset)(
|
2023-01-05 09:12:35 +01:00
|
|
|
db, node, version, rdataset, options,
|
|
|
|
newrdataset DNS__DB_FLARG_PASS));
|
2023-02-17 12:05:25 -08:00
|
|
|
}
|
|
|
|
return (ISC_R_NOTIMPLEMENTED);
|
1999-01-28 23:53:03 +00:00
|
|
|
}
|
|
|
|
|
1999-12-23 00:09:04 +00:00
|
|
|
isc_result_t
|
2023-01-05 09:12:35 +01:00
|
|
|
dns__db_deleterdataset(dns_db_t *db, dns_dbnode_t *node,
|
|
|
|
dns_dbversion_t *version, dns_rdatatype_t type,
|
|
|
|
dns_rdatatype_t covers DNS__DB_FLARG) {
|
1999-02-11 04:55:38 +00:00
|
|
|
/*
|
|
|
|
* Make it so that no rdataset of type 'type' exists at 'node' in
|
|
|
|
* version version 'version' of 'db'.
|
|
|
|
*/
|
|
|
|
|
1999-01-28 23:53:03 +00:00
|
|
|
REQUIRE(DNS_DB_VALID(db));
|
1999-02-11 04:55:38 +00:00
|
|
|
REQUIRE(node != NULL);
|
1999-04-13 01:52:58 +00:00
|
|
|
REQUIRE(((db->attributes & DNS_DBATTR_CACHE) == 0 && version != NULL) ||
|
|
|
|
((db->attributes & DNS_DBATTR_CACHE) != 0 && version == NULL));
|
1999-01-28 23:53:03 +00:00
|
|
|
|
2023-02-17 12:05:25 -08:00
|
|
|
if (db->methods->deleterdataset != NULL) {
|
2023-01-05 09:12:35 +01:00
|
|
|
return ((db->methods->deleterdataset)(
|
|
|
|
db, node, version, type, covers DNS__DB_FLARG_PASS));
|
2023-02-17 12:05:25 -08:00
|
|
|
}
|
|
|
|
return (ISC_R_NOTIMPLEMENTED);
|
1999-01-28 23:53:03 +00:00
|
|
|
}
|
2000-05-20 01:32:03 +00:00
|
|
|
|
|
|
|
isc_result_t
|
2018-03-28 14:19:37 +02:00
|
|
|
dns_db_getsoaserial(dns_db_t *db, dns_dbversion_t *ver, uint32_t *serialp) {
|
2000-05-20 01:32:03 +00:00
|
|
|
isc_result_t result;
|
|
|
|
dns_dbnode_t *node = NULL;
|
|
|
|
dns_rdataset_t rdataset;
|
2000-10-25 04:26:57 +00:00
|
|
|
dns_rdata_t rdata = DNS_RDATA_INIT;
|
2000-05-20 01:32:03 +00:00
|
|
|
isc_buffer_t buffer;
|
|
|
|
|
2000-06-07 02:38:41 +00:00
|
|
|
REQUIRE(dns_db_iszone(db) || dns_db_isstub(db));
|
2000-08-01 01:33:37 +00:00
|
|
|
|
2018-04-17 08:29:14 -07:00
|
|
|
result = dns_db_findnode(db, dns_db_origin(db), false, &node);
|
2000-05-20 01:32:03 +00:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
|
|
|
return (result);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2000-05-20 01:32:03 +00:00
|
|
|
|
|
|
|
dns_rdataset_init(&rdataset);
|
|
|
|
result = dns_db_findrdataset(db, node, ver, dns_rdatatype_soa, 0,
|
|
|
|
(isc_stdtime_t)0, &rdataset, NULL);
|
2008-04-01 23:47:10 +00:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
2000-05-20 01:32:03 +00:00
|
|
|
goto freenode;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2000-08-01 01:33:37 +00:00
|
|
|
|
2000-05-20 01:32:03 +00:00
|
|
|
result = dns_rdataset_first(&rdataset);
|
2008-04-01 23:47:10 +00:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
2000-05-20 01:32:03 +00:00
|
|
|
goto freerdataset;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2000-05-20 01:32:03 +00:00
|
|
|
dns_rdataset_current(&rdataset, &rdata);
|
2000-10-25 04:26:57 +00:00
|
|
|
result = dns_rdataset_next(&rdataset);
|
2000-11-15 23:16:33 +00:00
|
|
|
INSIST(result == ISC_R_NOMORE);
|
2000-05-20 01:32:03 +00:00
|
|
|
|
|
|
|
INSIST(rdata.length > 20);
|
|
|
|
isc_buffer_init(&buffer, rdata.data, rdata.length);
|
|
|
|
isc_buffer_add(&buffer, rdata.length);
|
|
|
|
isc_buffer_forward(&buffer, rdata.length - 20);
|
|
|
|
*serialp = isc_buffer_getuint32(&buffer);
|
|
|
|
|
|
|
|
result = ISC_R_SUCCESS;
|
|
|
|
|
|
|
|
freerdataset:
|
|
|
|
dns_rdataset_disassociate(&rdataset);
|
2000-08-01 01:33:37 +00:00
|
|
|
|
2000-05-20 01:32:03 +00:00
|
|
|
freenode:
|
|
|
|
dns_db_detachnode(db, &node);
|
|
|
|
return (result);
|
|
|
|
}
|
2000-08-03 19:46:37 +00:00
|
|
|
|
|
|
|
unsigned int
|
2021-10-20 12:01:00 +11:00
|
|
|
dns_db_nodecount(dns_db_t *db, dns_dbtree_t tree) {
|
2000-08-03 19:46:37 +00:00
|
|
|
REQUIRE(DNS_DB_VALID(db));
|
|
|
|
|
2023-02-17 12:05:25 -08:00
|
|
|
if (db->methods->nodecount != NULL) {
|
|
|
|
return ((db->methods->nodecount)(db, tree));
|
|
|
|
}
|
|
|
|
return (0);
|
2000-08-03 19:46:37 +00:00
|
|
|
}
|
2000-11-16 22:33:53 +00:00
|
|
|
|
2015-12-09 19:07:20 +05:30
|
|
|
size_t
|
2012-05-14 10:06:05 -07:00
|
|
|
dns_db_hashsize(dns_db_t *db) {
|
|
|
|
REQUIRE(DNS_DB_VALID(db));
|
|
|
|
|
|
|
|
if (db->methods->hashsize == NULL) {
|
2015-12-09 19:07:20 +05:30
|
|
|
return (0);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2012-05-14 10:06:05 -07:00
|
|
|
|
|
|
|
return ((db->methods->hashsize)(db));
|
|
|
|
}
|
|
|
|
|
2004-03-04 06:56:41 +00:00
|
|
|
void
|
2022-10-26 22:36:04 -07:00
|
|
|
dns_db_setloop(dns_db_t *db, isc_loop_t *loop) {
|
2004-03-04 06:56:41 +00:00
|
|
|
REQUIRE(DNS_DB_VALID(db));
|
|
|
|
|
2023-02-17 12:05:25 -08:00
|
|
|
if (db->methods->setloop != NULL) {
|
|
|
|
(db->methods->setloop)(db, loop);
|
|
|
|
}
|
2004-03-04 06:56:41 +00:00
|
|
|
}
|
|
|
|
|
2000-11-16 22:33:53 +00:00
|
|
|
isc_result_t
|
|
|
|
dns_db_register(const char *name, dns_dbcreatefunc_t create, void *driverarg,
|
|
|
|
isc_mem_t *mctx, dns_dbimplementation_t **dbimp) {
|
|
|
|
dns_dbimplementation_t *imp;
|
|
|
|
|
|
|
|
REQUIRE(name != NULL);
|
|
|
|
REQUIRE(dbimp != NULL && *dbimp == NULL);
|
|
|
|
|
2022-10-14 16:10:41 +02:00
|
|
|
isc_once_do(&once, initialize);
|
2000-11-17 01:06:37 +00:00
|
|
|
|
2000-11-16 22:33:53 +00:00
|
|
|
RWLOCK(&implock, isc_rwlocktype_write);
|
|
|
|
imp = impfind(name);
|
|
|
|
if (imp != NULL) {
|
|
|
|
RWUNLOCK(&implock, isc_rwlocktype_write);
|
|
|
|
return (ISC_R_EXISTS);
|
|
|
|
}
|
2008-04-01 23:47:10 +00:00
|
|
|
|
2000-11-16 22:33:53 +00:00
|
|
|
imp = isc_mem_get(mctx, sizeof(dns_dbimplementation_t));
|
|
|
|
imp->name = name;
|
|
|
|
imp->create = create;
|
|
|
|
imp->mctx = NULL;
|
|
|
|
imp->driverarg = driverarg;
|
|
|
|
isc_mem_attach(mctx, &imp->mctx);
|
|
|
|
ISC_LINK_INIT(imp, link);
|
|
|
|
ISC_LIST_APPEND(implementations, imp, link);
|
|
|
|
RWUNLOCK(&implock, isc_rwlocktype_write);
|
|
|
|
|
|
|
|
*dbimp = imp;
|
|
|
|
|
|
|
|
return (ISC_R_SUCCESS);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
dns_db_unregister(dns_dbimplementation_t **dbimp) {
|
|
|
|
dns_dbimplementation_t *imp;
|
|
|
|
|
|
|
|
REQUIRE(dbimp != NULL && *dbimp != NULL);
|
|
|
|
|
2022-10-14 16:10:41 +02:00
|
|
|
isc_once_do(&once, initialize);
|
2000-11-17 01:06:37 +00:00
|
|
|
|
2000-11-16 22:33:53 +00:00
|
|
|
imp = *dbimp;
|
2009-04-29 22:11:34 +00:00
|
|
|
*dbimp = NULL;
|
2000-11-16 22:33:53 +00:00
|
|
|
RWLOCK(&implock, isc_rwlocktype_write);
|
|
|
|
ISC_LIST_UNLINK(implementations, imp, link);
|
2019-07-23 17:16:57 -04:00
|
|
|
isc_mem_putanddetach(&imp->mctx, imp, sizeof(dns_dbimplementation_t));
|
2000-11-16 22:33:53 +00:00
|
|
|
RWUNLOCK(&implock, isc_rwlocktype_write);
|
2009-04-29 22:11:34 +00:00
|
|
|
ENSURE(*dbimp == NULL);
|
2000-11-16 22:33:53 +00:00
|
|
|
}
|
2004-12-21 10:45:20 +00:00
|
|
|
|
|
|
|
isc_result_t
|
2023-01-05 09:12:35 +01:00
|
|
|
dns__db_getoriginnode(dns_db_t *db, dns_dbnode_t **nodep DNS__DB_FLARG) {
|
2004-12-21 10:45:20 +00:00
|
|
|
REQUIRE(DNS_DB_VALID(db));
|
2020-03-30 13:47:58 -07:00
|
|
|
REQUIRE(dns_db_iszone(db));
|
2004-12-21 10:45:20 +00:00
|
|
|
REQUIRE(nodep != NULL && *nodep == NULL);
|
|
|
|
|
2005-10-13 01:58:32 +00:00
|
|
|
if (db->methods->getoriginnode != NULL) {
|
2023-01-05 09:12:35 +01:00
|
|
|
return ((db->methods->getoriginnode)(db,
|
|
|
|
nodep DNS__DB_FLARG_PASS));
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2004-12-21 10:45:20 +00:00
|
|
|
|
|
|
|
return (ISC_R_NOTFOUND);
|
|
|
|
}
|
2008-04-01 01:37:25 +00:00
|
|
|
|
2008-04-03 05:55:52 +00:00
|
|
|
dns_stats_t *
|
|
|
|
dns_db_getrrsetstats(dns_db_t *db) {
|
|
|
|
REQUIRE(DNS_DB_VALID(db));
|
|
|
|
|
|
|
|
if (db->methods->getrrsetstats != NULL) {
|
|
|
|
return ((db->methods->getrrsetstats)(db));
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2008-04-03 05:55:52 +00:00
|
|
|
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
|
2012-05-14 10:06:05 -07:00
|
|
|
isc_result_t
|
|
|
|
dns_db_setcachestats(dns_db_t *db, isc_stats_t *stats) {
|
|
|
|
REQUIRE(DNS_DB_VALID(db));
|
|
|
|
|
|
|
|
if (db->methods->setcachestats != NULL) {
|
|
|
|
return ((db->methods->setcachestats)(db, stats));
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2012-05-14 10:06:05 -07:00
|
|
|
|
|
|
|
return (ISC_R_NOTIMPLEMENTED);
|
|
|
|
}
|
|
|
|
|
2008-09-24 02:46:23 +00:00
|
|
|
isc_result_t
|
|
|
|
dns_db_getnsec3parameters(dns_db_t *db, dns_dbversion_t *version,
|
2018-03-28 14:19:37 +02:00
|
|
|
dns_hash_t *hash, uint8_t *flags,
|
|
|
|
uint16_t *iterations, unsigned char *salt,
|
2008-09-24 02:46:23 +00:00
|
|
|
size_t *salt_length) {
|
|
|
|
REQUIRE(DNS_DB_VALID(db));
|
2020-03-30 13:47:58 -07:00
|
|
|
REQUIRE(dns_db_iszone(db));
|
2008-09-24 02:46:23 +00:00
|
|
|
|
|
|
|
if (db->methods->getnsec3parameters != NULL) {
|
|
|
|
return ((db->methods->getnsec3parameters)(db, version, hash,
|
|
|
|
flags, iterations,
|
|
|
|
salt, salt_length));
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2008-09-24 02:46:23 +00:00
|
|
|
|
|
|
|
return (ISC_R_NOTFOUND);
|
|
|
|
}
|
|
|
|
|
2016-11-02 17:31:27 +11:00
|
|
|
isc_result_t
|
2018-03-28 14:19:37 +02:00
|
|
|
dns_db_getsize(dns_db_t *db, dns_dbversion_t *version, uint64_t *records,
|
|
|
|
uint64_t *bytes) {
|
2016-11-02 17:31:27 +11:00
|
|
|
REQUIRE(DNS_DB_VALID(db));
|
2020-03-30 13:47:58 -07:00
|
|
|
REQUIRE(dns_db_iszone(db));
|
2016-11-02 17:31:27 +11:00
|
|
|
|
|
|
|
if (db->methods->getsize != NULL) {
|
|
|
|
return ((db->methods->getsize)(db, version, records, bytes));
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2016-11-02 17:31:27 +11:00
|
|
|
|
|
|
|
return (ISC_R_NOTFOUND);
|
|
|
|
}
|
|
|
|
|
2008-04-01 01:37:25 +00:00
|
|
|
isc_result_t
|
|
|
|
dns_db_setsigningtime(dns_db_t *db, dns_rdataset_t *rdataset,
|
|
|
|
isc_stdtime_t resign) {
|
|
|
|
if (db->methods->setsigningtime != NULL) {
|
|
|
|
return ((db->methods->setsigningtime)(db, rdataset, resign));
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2008-04-01 01:37:25 +00:00
|
|
|
return (ISC_R_NOTIMPLEMENTED);
|
|
|
|
}
|
|
|
|
|
|
|
|
isc_result_t
|
2023-01-05 09:12:35 +01:00
|
|
|
dns__db_getsigningtime(dns_db_t *db, dns_rdataset_t *rdataset,
|
|
|
|
dns_name_t *name DNS__DB_FLARG) {
|
2008-04-01 01:37:25 +00:00
|
|
|
if (db->methods->getsigningtime != NULL) {
|
2023-01-05 09:12:35 +01:00
|
|
|
return ((db->methods->getsigningtime)(db, rdataset,
|
|
|
|
name DNS__DB_FLARG_PASS));
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2008-04-01 01:37:25 +00:00
|
|
|
return (ISC_R_NOTFOUND);
|
|
|
|
}
|
|
|
|
|
2023-07-10 11:36:19 +02:00
|
|
|
static void
|
|
|
|
call_updatenotify(dns_db_t *db) {
|
|
|
|
rcu_read_lock();
|
|
|
|
struct cds_lfht *update_listeners =
|
|
|
|
rcu_dereference(db->update_listeners);
|
|
|
|
if (update_listeners != NULL) {
|
|
|
|
struct cds_lfht_iter iter;
|
|
|
|
dns_dbonupdatelistener_t *listener;
|
|
|
|
cds_lfht_for_each_entry(update_listeners, &iter, listener,
|
|
|
|
ht_node) {
|
|
|
|
if (!cds_lfht_is_node_deleted(&listener->ht_node)) {
|
|
|
|
listener->onupdate(db, listener->onupdate_arg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
rcu_read_unlock();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
updatenotify_free(struct rcu_head *rcu_head) {
|
|
|
|
dns_dbonupdatelistener_t *listener =
|
|
|
|
caa_container_of(rcu_head, dns_dbonupdatelistener_t, rcu_head);
|
|
|
|
isc_mem_putanddetach(&listener->mctx, listener, sizeof(*listener));
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
updatenotify_match(struct cds_lfht_node *ht_node, const void *_key) {
|
|
|
|
const dns_dbonupdatelistener_t *listener =
|
|
|
|
caa_container_of(ht_node, dns_dbonupdatelistener_t, ht_node);
|
|
|
|
const dns_dbonupdatelistener_t *key = _key;
|
|
|
|
|
|
|
|
return (listener->onupdate == key->onupdate &&
|
|
|
|
listener->onupdate_arg == key->onupdate_arg);
|
|
|
|
}
|
|
|
|
|
2022-11-30 18:40:27 +11:00
|
|
|
/*
|
2016-05-26 21:23:19 +02:00
|
|
|
* Attach a notify-on-update function the database
|
|
|
|
*/
|
2023-07-10 11:36:19 +02:00
|
|
|
void
|
2016-05-26 21:23:19 +02:00
|
|
|
dns_db_updatenotify_register(dns_db_t *db, dns_dbupdate_callback_t fn,
|
|
|
|
void *fn_arg) {
|
|
|
|
REQUIRE(db != NULL);
|
|
|
|
REQUIRE(fn != NULL);
|
|
|
|
|
2023-07-10 11:36:19 +02:00
|
|
|
dns_dbonupdatelistener_t key = { .onupdate = fn,
|
|
|
|
.onupdate_arg = fn_arg };
|
|
|
|
uint32_t hash = isc_hash32(&key, sizeof(key), true);
|
|
|
|
dns_dbonupdatelistener_t *listener = isc_mem_get(db->mctx,
|
|
|
|
sizeof(*listener));
|
|
|
|
*listener = key;
|
|
|
|
|
|
|
|
isc_mem_attach(db->mctx, &listener->mctx);
|
|
|
|
|
|
|
|
rcu_read_lock();
|
|
|
|
struct cds_lfht *update_listeners =
|
|
|
|
rcu_dereference(db->update_listeners);
|
|
|
|
INSIST(update_listeners != NULL);
|
|
|
|
struct cds_lfht_node *ht_node =
|
|
|
|
cds_lfht_add_unique(update_listeners, hash, updatenotify_match,
|
|
|
|
&key, &listener->ht_node);
|
|
|
|
rcu_read_unlock();
|
|
|
|
|
|
|
|
if (ht_node != &listener->ht_node) {
|
|
|
|
updatenotify_free(&listener->rcu_head);
|
2022-11-30 18:40:27 +11:00
|
|
|
}
|
2016-05-26 21:23:19 +02:00
|
|
|
}
|
|
|
|
|
2023-07-10 11:36:19 +02:00
|
|
|
void
|
2016-05-26 21:23:19 +02:00
|
|
|
dns_db_updatenotify_unregister(dns_db_t *db, dns_dbupdate_callback_t fn,
|
|
|
|
void *fn_arg) {
|
|
|
|
REQUIRE(db != NULL);
|
|
|
|
|
2023-07-10 11:36:19 +02:00
|
|
|
dns_dbonupdatelistener_t key = { .onupdate = fn,
|
|
|
|
.onupdate_arg = fn_arg };
|
|
|
|
uint32_t hash = isc_hash32(&key, sizeof(key), true);
|
|
|
|
struct cds_lfht_iter iter;
|
|
|
|
|
|
|
|
rcu_read_lock();
|
|
|
|
struct cds_lfht *update_listeners =
|
|
|
|
rcu_dereference(db->update_listeners);
|
|
|
|
INSIST(update_listeners != NULL);
|
|
|
|
cds_lfht_lookup(update_listeners, hash, updatenotify_match, &key,
|
|
|
|
&iter);
|
|
|
|
|
|
|
|
struct cds_lfht_node *ht_node = cds_lfht_iter_get_node(&iter);
|
|
|
|
if (ht_node != NULL && !cds_lfht_del(update_listeners, ht_node)) {
|
|
|
|
dns_dbonupdatelistener_t *listener = caa_container_of(
|
|
|
|
ht_node, dns_dbonupdatelistener_t, ht_node);
|
|
|
|
call_rcu(&listener->rcu_head, updatenotify_free);
|
2016-05-26 21:23:19 +02:00
|
|
|
}
|
2023-07-10 11:36:19 +02:00
|
|
|
rcu_read_unlock();
|
2016-05-26 21:23:19 +02:00
|
|
|
}
|
2016-08-12 14:08:48 +10:00
|
|
|
|
2017-09-06 09:58:29 +10:00
|
|
|
isc_result_t
|
|
|
|
dns_db_setservestalettl(dns_db_t *db, dns_ttl_t ttl) {
|
|
|
|
REQUIRE(DNS_DB_VALID(db));
|
|
|
|
REQUIRE((db->attributes & DNS_DBATTR_CACHE) != 0);
|
|
|
|
|
|
|
|
if (db->methods->setservestalettl != NULL) {
|
|
|
|
return ((db->methods->setservestalettl)(db, ttl));
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2017-09-06 09:58:29 +10:00
|
|
|
return (ISC_R_NOTIMPLEMENTED);
|
|
|
|
}
|
|
|
|
|
|
|
|
isc_result_t
|
|
|
|
dns_db_getservestalettl(dns_db_t *db, dns_ttl_t *ttl) {
|
|
|
|
REQUIRE(DNS_DB_VALID(db));
|
|
|
|
REQUIRE((db->attributes & DNS_DBATTR_CACHE) != 0);
|
|
|
|
|
|
|
|
if (db->methods->getservestalettl != NULL) {
|
|
|
|
return ((db->methods->getservestalettl)(db, ttl));
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2017-09-06 09:58:29 +10:00
|
|
|
return (ISC_R_NOTIMPLEMENTED);
|
|
|
|
}
|
2017-10-06 15:24:16 +05:30
|
|
|
|
Add stale-refresh-time option
Before this update, BIND would attempt to do a full recursive resolution
process for each query received if the requested rrset had its ttl
expired. If the resolution fails for any reason, only then BIND would
check for stale rrset in cache (if 'stale-cache-enable' and
'stale-answer-enable' is on).
The problem with this approach is that if an authoritative server is
unreachable or is failing to respond, it is very unlikely that the
problem will be fixed in the next seconds.
A better approach to improve performance in those cases, is to mark the
moment in which a resolution failed, and if new queries arrive for that
same rrset, try to respond directly from the stale cache, and do that
for a window of time configured via 'stale-refresh-time'.
Only when this interval expires we then try to do a normal refresh of
the rrset.
The logic behind this commit is as following:
- In query.c / query_gotanswer(), if the test of 'result' variable falls
to the default case, an error is assumed to have happened, and a call
to 'query_usestale()' is made to check if serving of stale rrset is
enabled in configuration.
- If serving of stale answers is enabled, a flag will be turned on in
the query context to look for stale records:
query.c:6839
qctx->client->query.dboptions |= DNS_DBFIND_STALEOK;
- A call to query_lookup() will be made again, inside it a call to
'dns_db_findext()' is made, which in turn will invoke rbdb.c /
cache_find().
- In rbtdb.c / cache_find() the important bits of this change is the
call to 'check_stale_header()', which is a function that yields true
if we should skip the stale entry, or false if we should consider it.
- In check_stale_header() we now check if the DNS_DBFIND_STALEOK option
is set, if that is the case we know that this new search for stale
records was made due to a failure in a normal resolution, so we keep
track of the time in which the failured occured in rbtdb.c:4559:
header->last_refresh_fail_ts = search->now;
- In check_stale_header(), if DNS_DBFIND_STALEOK is not set, then we
know this is a normal lookup, if the record is stale and the query
time is between last failure time + stale-refresh-time window, then
we return false so cache_find() knows it can consider this stale
rrset entry to return as a response.
The last additions are two new methods to the database interface:
- setservestale_refresh
- getservestale_refresh
Those were added so rbtdb can be aware of the value set in configuration
option, since in that level we have no access to the view object.
2020-10-19 17:02:03 -03:00
|
|
|
isc_result_t
|
|
|
|
dns_db_setservestalerefresh(dns_db_t *db, uint32_t interval) {
|
|
|
|
REQUIRE(DNS_DB_VALID(db));
|
|
|
|
REQUIRE((db->attributes & DNS_DBATTR_CACHE) != 0);
|
|
|
|
|
|
|
|
if (db->methods->setservestalerefresh != NULL) {
|
|
|
|
return ((db->methods->setservestalerefresh)(db, interval));
|
|
|
|
}
|
|
|
|
return (ISC_R_NOTIMPLEMENTED);
|
|
|
|
}
|
|
|
|
|
|
|
|
isc_result_t
|
|
|
|
dns_db_getservestalerefresh(dns_db_t *db, uint32_t *interval) {
|
|
|
|
REQUIRE(DNS_DB_VALID(db));
|
|
|
|
REQUIRE((db->attributes & DNS_DBATTR_CACHE) != 0);
|
|
|
|
|
|
|
|
if (db->methods->getservestalerefresh != NULL) {
|
|
|
|
return ((db->methods->getservestalerefresh)(db, interval));
|
|
|
|
}
|
|
|
|
return (ISC_R_NOTIMPLEMENTED);
|
|
|
|
}
|
|
|
|
|
2017-10-06 15:24:16 +05:30
|
|
|
isc_result_t
|
|
|
|
dns_db_setgluecachestats(dns_db_t *db, isc_stats_t *stats) {
|
|
|
|
REQUIRE(dns_db_iszone(db));
|
|
|
|
REQUIRE(stats != NULL);
|
|
|
|
|
2017-10-06 12:52:21 -07:00
|
|
|
if (db->methods->setgluecachestats != NULL) {
|
2017-10-06 15:24:16 +05:30
|
|
|
return ((db->methods->setgluecachestats)(db, stats));
|
2017-10-06 12:52:21 -07:00
|
|
|
}
|
2017-10-06 15:24:16 +05:30
|
|
|
|
|
|
|
return (ISC_R_NOTIMPLEMENTED);
|
|
|
|
}
|
2023-05-09 23:07:50 -07:00
|
|
|
|
|
|
|
isc_result_t
|
|
|
|
dns_db_addglue(dns_db_t *db, dns_dbversion_t *version, dns_rdataset_t *rdataset,
|
|
|
|
dns_message_t *msg) {
|
|
|
|
REQUIRE(DNS_DB_VALID(db));
|
|
|
|
REQUIRE((db->attributes & DNS_DBATTR_CACHE) == 0);
|
|
|
|
REQUIRE(DNS_RDATASET_VALID(rdataset));
|
|
|
|
REQUIRE(rdataset->methods != NULL);
|
|
|
|
REQUIRE(rdataset->type == dns_rdatatype_ns);
|
|
|
|
|
|
|
|
if (db->methods->addglue != NULL) {
|
|
|
|
return ((db->methods->addglue)(db, version, rdataset, msg));
|
|
|
|
}
|
|
|
|
|
|
|
|
return (ISC_R_NOTIMPLEMENTED);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
dns_db_locknode(dns_db_t *db, dns_dbnode_t *node, isc_rwlocktype_t type) {
|
|
|
|
if (db->methods->locknode != NULL) {
|
|
|
|
(db->methods->locknode)(db, node, type);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
dns_db_unlocknode(dns_db_t *db, dns_dbnode_t *node, isc_rwlocktype_t type) {
|
|
|
|
if (db->methods->unlocknode != NULL) {
|
|
|
|
(db->methods->unlocknode)(db, node, type);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
dns_db_expiredata(dns_db_t *db, dns_dbnode_t *node, void *data) {
|
|
|
|
if (db->methods->expiredata != NULL) {
|
|
|
|
(db->methods->expiredata)(db, node, data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
dns_db_deletedata(dns_db_t *db, dns_dbnode_t *node, void *data) {
|
|
|
|
if (db->methods->deletedata != NULL) {
|
|
|
|
(db->methods->deletedata)(db, node, data);
|
|
|
|
}
|
|
|
|
}
|