2000-08-21 22:15:28 +00:00
|
|
|
/*
|
2018-02-23 09:53:12 +01:00
|
|
|
* Copyright (C) Internet Systems Consortium, Inc. ("ISC")
|
2000-08-21 22:15:28 +00:00
|
|
|
*
|
2016-06-27 14:56:38 +10: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
|
2020-09-14 16:20:40 -07:00
|
|
|
* file, you can obtain one at https://mozilla.org/MPL/2.0/.
|
2018-02-23 09:53:12 +01:00
|
|
|
*
|
|
|
|
* See the COPYRIGHT file distributed with this work for additional
|
|
|
|
* information regarding copyright ownership.
|
2000-08-21 22:15:28 +00:00
|
|
|
*/
|
|
|
|
|
2005-04-27 04:57:32 +00:00
|
|
|
/*! \file */
|
2000-08-21 22:15:28 +00:00
|
|
|
|
2018-03-28 14:19:37 +02:00
|
|
|
#include <inttypes.h>
|
2018-04-17 08:29:14 -07:00
|
|
|
#include <stdbool.h>
|
2000-10-06 21:20:59 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
2000-08-21 22:15:28 +00:00
|
|
|
#include <isc/buffer.h>
|
|
|
|
#include <isc/lex.h>
|
2000-11-16 22:33:53 +00:00
|
|
|
#include <isc/log.h>
|
2000-08-21 22:15:28 +00:00
|
|
|
#include <isc/magic.h>
|
|
|
|
#include <isc/mem.h>
|
|
|
|
#include <isc/once.h>
|
|
|
|
#include <isc/print.h>
|
2019-05-20 16:53:47 +02:00
|
|
|
#include <isc/refcount.h>
|
2000-08-21 22:15:28 +00:00
|
|
|
#include <isc/region.h>
|
|
|
|
#include <isc/util.h>
|
|
|
|
|
2000-11-17 23:32:27 +00:00
|
|
|
#include <dns/callbacks.h>
|
2000-08-21 22:15:28 +00:00
|
|
|
#include <dns/db.h>
|
2000-08-23 18:28:03 +00:00
|
|
|
#include <dns/dbiterator.h>
|
2000-08-21 22:15:28 +00:00
|
|
|
#include <dns/fixedname.h>
|
2000-11-16 22:33:53 +00:00
|
|
|
#include <dns/log.h>
|
2000-08-21 22:15:28 +00:00
|
|
|
#include <dns/rdata.h>
|
|
|
|
#include <dns/rdatalist.h>
|
|
|
|
#include <dns/rdataset.h>
|
|
|
|
#include <dns/rdatasetiter.h>
|
|
|
|
#include <dns/rdatatype.h>
|
|
|
|
#include <dns/result.h>
|
|
|
|
#include <dns/sdb.h>
|
|
|
|
#include <dns/types.h>
|
|
|
|
|
|
|
|
#include "rdatalist_p.h"
|
|
|
|
|
2000-11-16 22:33:53 +00:00
|
|
|
struct dns_sdbimplementation {
|
2020-02-12 13:59:18 +01:00
|
|
|
const dns_sdbmethods_t *methods;
|
2020-02-13 14:44:37 -08:00
|
|
|
void *driverdata;
|
|
|
|
unsigned int flags;
|
|
|
|
isc_mem_t *mctx;
|
|
|
|
isc_mutex_t driverlock;
|
2020-02-12 13:59:18 +01:00
|
|
|
dns_dbimplementation_t *dbimp;
|
2000-11-16 22:33:53 +00:00
|
|
|
};
|
2000-08-21 22:15:28 +00:00
|
|
|
|
|
|
|
struct dns_sdb {
|
|
|
|
/* Unlocked */
|
2020-02-13 14:44:37 -08:00
|
|
|
dns_db_t common;
|
|
|
|
char *zone;
|
2020-02-12 13:59:18 +01:00
|
|
|
dns_sdbimplementation_t *implementation;
|
2020-02-13 14:44:37 -08:00
|
|
|
void *dbdata;
|
2019-05-20 16:53:47 +02:00
|
|
|
|
|
|
|
/* Atomic */
|
2020-02-12 13:59:18 +01:00
|
|
|
isc_refcount_t references;
|
2000-08-21 22:15:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct dns_sdblookup {
|
|
|
|
/* Unlocked */
|
2020-02-12 13:59:18 +01:00
|
|
|
unsigned int magic;
|
2020-02-13 14:44:37 -08:00
|
|
|
dns_sdb_t *sdb;
|
2020-02-12 13:59:18 +01:00
|
|
|
ISC_LIST(dns_rdatalist_t) lists;
|
|
|
|
ISC_LIST(isc_buffer_t) buffers;
|
|
|
|
dns_name_t *name;
|
|
|
|
ISC_LINK(dns_sdblookup_t) link;
|
|
|
|
dns_rdatacallbacks_t callbacks;
|
2019-05-20 16:53:47 +02:00
|
|
|
|
|
|
|
/* Atomic */
|
2020-02-12 13:59:18 +01:00
|
|
|
isc_refcount_t references;
|
2000-08-21 22:15:28 +00:00
|
|
|
};
|
|
|
|
|
2000-08-23 18:28:03 +00:00
|
|
|
typedef struct dns_sdblookup dns_sdbnode_t;
|
|
|
|
|
|
|
|
struct dns_sdballnodes {
|
2020-02-12 13:59:18 +01:00
|
|
|
dns_dbiterator_t common;
|
|
|
|
ISC_LIST(dns_sdbnode_t) nodelist;
|
|
|
|
dns_sdbnode_t *current;
|
|
|
|
dns_sdbnode_t *origin;
|
2000-08-23 18:28:03 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
typedef dns_sdballnodes_t sdb_dbiterator_t;
|
|
|
|
|
2000-08-21 22:15:28 +00:00
|
|
|
typedef struct sdb_rdatasetiter {
|
2020-02-12 13:59:18 +01:00
|
|
|
dns_rdatasetiter_t common;
|
2020-02-13 14:44:37 -08:00
|
|
|
dns_rdatalist_t *current;
|
2000-08-21 22:15:28 +00:00
|
|
|
} sdb_rdatasetiter_t;
|
|
|
|
|
2020-02-12 13:59:18 +01:00
|
|
|
#define SDB_MAGIC ISC_MAGIC('S', 'D', 'B', '-')
|
2001-06-06 22:03:58 +00:00
|
|
|
|
2005-04-27 04:57:32 +00:00
|
|
|
/*%
|
2001-06-06 22:03:58 +00:00
|
|
|
* Note that "impmagic" is not the first four bytes of the struct, so
|
|
|
|
* ISC_MAGIC_VALID cannot be used.
|
|
|
|
*/
|
2020-02-12 13:59:18 +01:00
|
|
|
#define VALID_SDB(sdb) ((sdb) != NULL && (sdb)->common.impmagic == SDB_MAGIC)
|
2000-08-21 22:15:28 +00:00
|
|
|
|
2020-02-13 14:44:37 -08:00
|
|
|
#define SDBLOOKUP_MAGIC ISC_MAGIC('S', 'D', 'B', 'L')
|
2020-02-12 13:59:18 +01:00
|
|
|
#define VALID_SDBLOOKUP(sdbl) ISC_MAGIC_VALID(sdbl, SDBLOOKUP_MAGIC)
|
2020-02-13 14:44:37 -08:00
|
|
|
#define VALID_SDBNODE(sdbn) VALID_SDBLOOKUP(sdbn)
|
2000-08-21 22:15:28 +00:00
|
|
|
|
2005-04-27 04:57:32 +00:00
|
|
|
/* These values are taken from RFC1537 */
|
2020-02-13 14:44:37 -08:00
|
|
|
#define SDB_DEFAULT_REFRESH 28800U /* 8 hours */
|
|
|
|
#define SDB_DEFAULT_RETRY 7200U /* 2 hours */
|
|
|
|
#define SDB_DEFAULT_EXPIRE 604800U /* 7 days */
|
|
|
|
#define SDB_DEFAULT_MINIMUM 86400U /* 1 day */
|
2000-08-21 22:15:28 +00:00
|
|
|
|
|
|
|
/* This is a reasonable value */
|
2020-02-12 13:59:18 +01:00
|
|
|
#define SDB_DEFAULT_TTL (60 * 60 * 24)
|
2000-08-21 22:15:28 +00:00
|
|
|
|
2007-08-27 03:32:27 +00:00
|
|
|
#ifdef __COVERITY__
|
2020-02-13 14:44:37 -08:00
|
|
|
#define MAYBE_LOCK(sdb) LOCK(&sdb->implementation->driverlock)
|
2007-08-27 03:32:27 +00:00
|
|
|
#define MAYBE_UNLOCK(sdb) UNLOCK(&sdb->implementation->driverlock)
|
2020-02-13 21:48:23 +01:00
|
|
|
#else /* ifdef __COVERITY__ */
|
2020-02-12 13:59:18 +01:00
|
|
|
#define MAYBE_LOCK(sdb) \
|
|
|
|
do { \
|
|
|
|
unsigned int flags = sdb->implementation->flags; \
|
|
|
|
if ((flags & DNS_SDBFLAG_THREADSAFE) == 0) \
|
|
|
|
LOCK(&sdb->implementation->driverlock); \
|
2000-12-06 01:08:41 +00:00
|
|
|
} while (0)
|
|
|
|
|
2020-02-12 13:59:18 +01:00
|
|
|
#define MAYBE_UNLOCK(sdb) \
|
|
|
|
do { \
|
|
|
|
unsigned int flags = sdb->implementation->flags; \
|
|
|
|
if ((flags & DNS_SDBFLAG_THREADSAFE) == 0) \
|
|
|
|
UNLOCK(&sdb->implementation->driverlock); \
|
2000-12-06 01:08:41 +00:00
|
|
|
} while (0)
|
2020-02-13 21:48:23 +01:00
|
|
|
#endif /* ifdef __COVERITY__ */
|
2000-12-06 01:08:41 +00:00
|
|
|
|
2000-08-21 22:15:28 +00:00
|
|
|
static int dummy;
|
|
|
|
|
2020-02-14 08:14:03 +01:00
|
|
|
static isc_result_t
|
|
|
|
dns_sdb_create(isc_mem_t *mctx, const dns_name_t *origin, dns_dbtype_t type,
|
|
|
|
dns_rdataclass_t rdclass, unsigned int argc, char *argv[],
|
|
|
|
void *driverarg, dns_db_t **dbp);
|
|
|
|
|
|
|
|
static isc_result_t
|
|
|
|
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);
|
|
|
|
|
|
|
|
static isc_result_t
|
|
|
|
createnode(dns_sdb_t *sdb, dns_sdbnode_t **nodep);
|
|
|
|
|
|
|
|
static void
|
|
|
|
destroynode(dns_sdbnode_t *node);
|
|
|
|
|
|
|
|
static void
|
|
|
|
detachnode(dns_db_t *db, dns_dbnode_t **targetp);
|
|
|
|
|
|
|
|
static void
|
|
|
|
list_tordataset(dns_rdatalist_t *rdatalist, dns_db_t *db, dns_dbnode_t *node,
|
|
|
|
dns_rdataset_t *rdataset);
|
|
|
|
|
|
|
|
static void
|
|
|
|
dbiterator_destroy(dns_dbiterator_t **iteratorp);
|
|
|
|
static isc_result_t
|
|
|
|
dbiterator_first(dns_dbiterator_t *iterator);
|
|
|
|
static isc_result_t
|
|
|
|
dbiterator_last(dns_dbiterator_t *iterator);
|
|
|
|
static isc_result_t
|
|
|
|
dbiterator_seek(dns_dbiterator_t *iterator, const dns_name_t *name);
|
|
|
|
static isc_result_t
|
|
|
|
dbiterator_prev(dns_dbiterator_t *iterator);
|
|
|
|
static isc_result_t
|
|
|
|
dbiterator_next(dns_dbiterator_t *iterator);
|
|
|
|
static isc_result_t
|
|
|
|
dbiterator_current(dns_dbiterator_t *iterator, dns_dbnode_t **nodep,
|
|
|
|
dns_name_t *name);
|
|
|
|
static isc_result_t
|
|
|
|
dbiterator_pause(dns_dbiterator_t *iterator);
|
|
|
|
static isc_result_t
|
|
|
|
dbiterator_origin(dns_dbiterator_t *iterator, dns_name_t *name);
|
2000-08-23 18:28:03 +00:00
|
|
|
|
|
|
|
static dns_dbiteratormethods_t dbiterator_methods = {
|
2020-02-12 13:59:18 +01:00
|
|
|
dbiterator_destroy, dbiterator_first, dbiterator_last,
|
|
|
|
dbiterator_seek, dbiterator_prev, dbiterator_next,
|
|
|
|
dbiterator_current, dbiterator_pause, dbiterator_origin
|
2000-08-23 18:28:03 +00:00
|
|
|
};
|
2000-08-21 22:15:28 +00:00
|
|
|
|
2020-02-14 08:14:03 +01:00
|
|
|
static void
|
|
|
|
rdatasetiter_destroy(dns_rdatasetiter_t **iteratorp);
|
|
|
|
static isc_result_t
|
|
|
|
rdatasetiter_first(dns_rdatasetiter_t *iterator);
|
|
|
|
static isc_result_t
|
|
|
|
rdatasetiter_next(dns_rdatasetiter_t *iterator);
|
|
|
|
static void
|
|
|
|
rdatasetiter_current(dns_rdatasetiter_t *iterator, dns_rdataset_t *rdataset);
|
2000-08-21 22:15:28 +00:00
|
|
|
|
|
|
|
static dns_rdatasetitermethods_t rdatasetiter_methods = {
|
2020-02-12 13:59:18 +01:00
|
|
|
rdatasetiter_destroy, rdatasetiter_first, rdatasetiter_next,
|
2000-08-21 22:15:28 +00:00
|
|
|
rdatasetiter_current
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Functions used by implementors of simple databases
|
|
|
|
*/
|
|
|
|
isc_result_t
|
2000-08-22 22:06:46 +00:00
|
|
|
dns_sdb_register(const char *drivername, const dns_sdbmethods_t *methods,
|
2000-11-16 22:33:53 +00:00
|
|
|
void *driverdata, unsigned int flags, isc_mem_t *mctx,
|
2020-02-13 14:44:37 -08:00
|
|
|
dns_sdbimplementation_t **sdbimp) {
|
2000-11-16 22:33:53 +00:00
|
|
|
dns_sdbimplementation_t *imp;
|
2020-02-13 14:44:37 -08:00
|
|
|
isc_result_t result;
|
2000-08-21 22:15:28 +00:00
|
|
|
|
|
|
|
REQUIRE(drivername != NULL);
|
2000-08-22 22:06:46 +00:00
|
|
|
REQUIRE(methods != NULL);
|
2012-04-11 12:17:57 +10:00
|
|
|
REQUIRE(methods->lookup != NULL || methods->lookup2 != NULL);
|
2000-11-16 22:33:53 +00:00
|
|
|
REQUIRE(mctx != NULL);
|
|
|
|
REQUIRE(sdbimp != NULL && *sdbimp == NULL);
|
2020-02-12 13:59:18 +01:00
|
|
|
REQUIRE((flags &
|
|
|
|
~(DNS_SDBFLAG_RELATIVEOWNER | DNS_SDBFLAG_RELATIVERDATA |
|
|
|
|
DNS_SDBFLAG_THREADSAFE | DNS_SDBFLAG_DNS64)) == 0);
|
2000-08-21 22:15:28 +00:00
|
|
|
|
2000-11-16 22:33:53 +00:00
|
|
|
imp = isc_mem_get(mctx, sizeof(dns_sdbimplementation_t));
|
|
|
|
imp->methods = methods;
|
|
|
|
imp->driverdata = driverdata;
|
|
|
|
imp->flags = flags;
|
|
|
|
imp->mctx = NULL;
|
|
|
|
isc_mem_attach(mctx, &imp->mctx);
|
2018-11-16 15:33:22 +01:00
|
|
|
isc_mutex_init(&imp->driverlock);
|
2001-05-29 18:34:24 +00:00
|
|
|
|
2000-11-16 22:33:53 +00:00
|
|
|
imp->dbimp = NULL;
|
|
|
|
result = dns_db_register(drivername, dns_sdb_create, imp, mctx,
|
|
|
|
&imp->dbimp);
|
2020-02-13 21:48:23 +01:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
2001-05-29 18:34:24 +00:00
|
|
|
goto cleanup_mutex;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2000-11-16 22:33:53 +00:00
|
|
|
*sdbimp = imp;
|
2000-08-21 22:15:28 +00:00
|
|
|
|
|
|
|
return (ISC_R_SUCCESS);
|
2001-05-29 18:34:24 +00:00
|
|
|
|
2020-02-12 13:59:18 +01:00
|
|
|
cleanup_mutex:
|
2018-11-19 10:31:09 +00:00
|
|
|
isc_mutex_destroy(&imp->driverlock);
|
2001-05-29 18:34:24 +00:00
|
|
|
isc_mem_put(mctx, imp, sizeof(dns_sdbimplementation_t));
|
|
|
|
return (result);
|
2000-08-21 22:15:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2020-02-13 14:44:37 -08:00
|
|
|
dns_sdb_unregister(dns_sdbimplementation_t **sdbimp) {
|
2000-11-16 22:33:53 +00:00
|
|
|
dns_sdbimplementation_t *imp;
|
2000-08-21 22:15:28 +00:00
|
|
|
|
2000-11-16 22:33:53 +00:00
|
|
|
REQUIRE(sdbimp != NULL && *sdbimp != NULL);
|
|
|
|
|
|
|
|
imp = *sdbimp;
|
2020-02-08 04:37:54 -08:00
|
|
|
*sdbimp = NULL;
|
2000-11-16 22:33:53 +00:00
|
|
|
dns_db_unregister(&imp->dbimp);
|
2018-11-19 10:31:09 +00:00
|
|
|
isc_mutex_destroy(&imp->driverlock);
|
2000-11-16 22:33:53 +00:00
|
|
|
|
2019-07-23 17:16:57 -04:00
|
|
|
isc_mem_putanddetach(&imp->mctx, imp, sizeof(dns_sdbimplementation_t));
|
2000-08-21 22:15:28 +00:00
|
|
|
}
|
|
|
|
|
2001-05-02 18:58:56 +00:00
|
|
|
static inline unsigned int
|
2020-02-13 14:44:37 -08:00
|
|
|
initial_size(unsigned int len) {
|
2001-05-02 19:25:19 +00:00
|
|
|
unsigned int size;
|
2005-08-18 00:57:31 +00:00
|
|
|
|
2020-02-13 18:16:57 +01:00
|
|
|
for (size = 1024; size < (64 * 1024); size *= 2) {
|
|
|
|
if (len < size) {
|
2001-05-02 18:58:56 +00:00
|
|
|
return (size);
|
2020-02-13 18:16:57 +01:00
|
|
|
}
|
|
|
|
}
|
2005-08-18 00:57:31 +00:00
|
|
|
return (65535);
|
2001-05-02 18:58:56 +00:00
|
|
|
}
|
|
|
|
|
2000-08-21 22:15:28 +00:00
|
|
|
isc_result_t
|
2012-04-11 12:17:57 +10:00
|
|
|
dns_sdb_putrdata(dns_sdblookup_t *lookup, dns_rdatatype_t typeval,
|
2020-02-13 14:44:37 -08:00
|
|
|
dns_ttl_t ttl, const unsigned char *rdatap,
|
|
|
|
unsigned int rdlen) {
|
2000-08-21 22:15:28 +00:00
|
|
|
dns_rdatalist_t *rdatalist;
|
2020-02-13 14:44:37 -08:00
|
|
|
dns_rdata_t *rdata;
|
|
|
|
isc_buffer_t *rdatabuf = NULL;
|
|
|
|
isc_mem_t *mctx;
|
|
|
|
isc_region_t region;
|
2000-08-21 22:15:28 +00:00
|
|
|
|
|
|
|
mctx = lookup->sdb->common.mctx;
|
|
|
|
|
|
|
|
rdatalist = ISC_LIST_HEAD(lookup->lists);
|
|
|
|
while (rdatalist != NULL) {
|
2020-02-13 21:48:23 +01:00
|
|
|
if (rdatalist->type == typeval) {
|
2000-08-21 22:15:28 +00:00
|
|
|
break;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2000-08-21 22:15:28 +00:00
|
|
|
rdatalist = ISC_LIST_NEXT(rdatalist, link);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rdatalist == NULL) {
|
|
|
|
rdatalist = isc_mem_get(mctx, sizeof(dns_rdatalist_t));
|
2015-03-03 16:43:42 +11:00
|
|
|
dns_rdatalist_init(rdatalist);
|
2000-08-21 22:15:28 +00:00
|
|
|
rdatalist->rdclass = lookup->sdb->common.rdclass;
|
|
|
|
rdatalist->type = typeval;
|
|
|
|
rdatalist->ttl = ttl;
|
|
|
|
ISC_LIST_APPEND(lookup->lists, rdatalist, link);
|
2020-02-13 21:48:23 +01:00
|
|
|
} else if (rdatalist->ttl != ttl) {
|
2020-02-12 13:59:18 +01:00
|
|
|
return (DNS_R_BADTTL);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2000-08-21 22:15:28 +00:00
|
|
|
|
|
|
|
rdata = isc_mem_get(mctx, sizeof(dns_rdata_t));
|
2001-11-15 20:32:05 +00:00
|
|
|
|
2020-02-02 08:35:46 +01:00
|
|
|
isc_buffer_allocate(mctx, &rdatabuf, rdlen);
|
2001-11-15 20:32:05 +00:00
|
|
|
DE_CONST(rdatap, region.base);
|
|
|
|
region.length = rdlen;
|
|
|
|
isc_buffer_copyregion(rdatabuf, ®ion);
|
|
|
|
isc_buffer_usedregion(rdatabuf, ®ion);
|
2000-08-21 22:15:28 +00:00
|
|
|
dns_rdata_init(rdata);
|
2001-11-15 20:32:05 +00:00
|
|
|
dns_rdata_fromregion(rdata, rdatalist->rdclass, rdatalist->type,
|
|
|
|
®ion);
|
|
|
|
ISC_LIST_APPEND(rdatalist->rdata, rdata, link);
|
|
|
|
ISC_LIST_APPEND(lookup->buffers, rdatabuf, link);
|
|
|
|
|
2020-02-02 08:35:46 +01:00
|
|
|
return (ISC_R_SUCCESS);
|
2001-11-15 20:32:05 +00:00
|
|
|
}
|
2008-01-18 23:46:58 +00:00
|
|
|
|
2001-11-15 20:32:05 +00:00
|
|
|
isc_result_t
|
|
|
|
dns_sdb_putrr(dns_sdblookup_t *lookup, const char *type, dns_ttl_t ttl,
|
2020-02-13 14:44:37 -08:00
|
|
|
const char *data) {
|
|
|
|
unsigned int datalen;
|
|
|
|
dns_rdatatype_t typeval;
|
2004-02-03 00:59:05 +00:00
|
|
|
isc_textregion_t r;
|
2020-02-13 14:44:37 -08:00
|
|
|
isc_lex_t *lex = NULL;
|
|
|
|
isc_result_t result;
|
|
|
|
unsigned char *p = NULL;
|
|
|
|
unsigned int size = 0; /* Init to suppress compiler warning */
|
|
|
|
isc_mem_t *mctx;
|
2001-11-15 20:32:05 +00:00
|
|
|
dns_sdbimplementation_t *imp;
|
2020-02-13 14:44:37 -08:00
|
|
|
const dns_name_t *origin;
|
|
|
|
isc_buffer_t b;
|
|
|
|
isc_buffer_t rb;
|
2001-11-15 20:32:05 +00:00
|
|
|
|
|
|
|
REQUIRE(VALID_SDBLOOKUP(lookup));
|
|
|
|
REQUIRE(type != NULL);
|
|
|
|
REQUIRE(data != NULL);
|
|
|
|
|
|
|
|
mctx = lookup->sdb->common.mctx;
|
|
|
|
|
2004-02-03 00:59:05 +00:00
|
|
|
DE_CONST(type, r.base);
|
2001-11-15 20:32:05 +00:00
|
|
|
r.length = strlen(type);
|
2004-02-03 00:59:05 +00:00
|
|
|
result = dns_rdatatype_fromtext(&typeval, &r);
|
2020-02-13 21:48:23 +01:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
2001-11-15 20:32:05 +00:00
|
|
|
return (result);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2000-08-21 22:15:28 +00:00
|
|
|
|
2000-08-22 00:53:31 +00:00
|
|
|
imp = lookup->sdb->implementation;
|
2020-02-13 21:48:23 +01:00
|
|
|
if ((imp->flags & DNS_SDBFLAG_RELATIVERDATA) != 0) {
|
2000-08-22 00:53:31 +00:00
|
|
|
origin = &lookup->sdb->common.origin;
|
2020-02-13 21:48:23 +01:00
|
|
|
} else {
|
2000-08-22 00:53:31 +00:00
|
|
|
origin = dns_rootname;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2000-08-22 00:53:31 +00:00
|
|
|
|
2000-08-21 22:15:28 +00:00
|
|
|
result = isc_lex_create(mctx, 64, &lex);
|
2020-02-13 21:48:23 +01:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
2000-08-21 22:15:28 +00:00
|
|
|
goto failure;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2000-08-21 22:15:28 +00:00
|
|
|
|
2001-11-15 20:32:05 +00:00
|
|
|
datalen = strlen(data);
|
|
|
|
size = initial_size(datalen);
|
2008-01-16 21:44:41 +00:00
|
|
|
do {
|
2012-12-08 12:48:57 +11:00
|
|
|
isc_buffer_constinit(&b, data, datalen);
|
2001-11-15 20:32:05 +00:00
|
|
|
isc_buffer_add(&b, datalen);
|
2000-08-21 22:15:28 +00:00
|
|
|
result = isc_lex_openbuffer(lex, &b);
|
2020-02-13 21:48:23 +01:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
2000-08-21 22:15:28 +00:00
|
|
|
goto failure;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2000-08-21 22:15:28 +00:00
|
|
|
|
2020-02-13 21:48:23 +01:00
|
|
|
if (size >= 65535) {
|
2005-08-18 00:57:31 +00:00
|
|
|
size = 65535;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2001-11-15 20:32:05 +00:00
|
|
|
p = isc_mem_get(mctx, size);
|
|
|
|
isc_buffer_init(&rb, p, size);
|
2020-02-12 13:59:18 +01:00
|
|
|
result = dns_rdata_fromtext(NULL, lookup->sdb->common.rdclass,
|
|
|
|
typeval, lex, origin, 0, mctx, &rb,
|
2000-11-17 23:32:27 +00:00
|
|
|
&lookup->callbacks);
|
2020-02-13 21:48:23 +01:00
|
|
|
if (result != ISC_R_NOSPACE) {
|
2001-11-15 20:32:05 +00:00
|
|
|
break;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2001-11-15 20:32:05 +00:00
|
|
|
|
2005-08-18 00:57:31 +00:00
|
|
|
/*
|
|
|
|
* Is the RR too big?
|
|
|
|
*/
|
2020-02-13 21:48:23 +01:00
|
|
|
if (size >= 65535) {
|
2005-08-18 00:57:31 +00:00
|
|
|
break;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2001-11-15 20:32:05 +00:00
|
|
|
isc_mem_put(mctx, p, size);
|
|
|
|
p = NULL;
|
2000-08-21 22:15:28 +00:00
|
|
|
size *= 2;
|
|
|
|
} while (result == ISC_R_NOSPACE);
|
|
|
|
|
2020-02-13 21:48:23 +01:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
2000-08-21 22:15:28 +00:00
|
|
|
goto failure;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2000-08-21 22:15:28 +00:00
|
|
|
|
2020-02-12 13:59:18 +01:00
|
|
|
result = dns_sdb_putrdata(lookup, typeval, ttl, isc_buffer_base(&rb),
|
2001-11-15 20:32:05 +00:00
|
|
|
isc_buffer_usedlength(&rb));
|
2020-02-12 13:59:18 +01:00
|
|
|
failure:
|
2020-02-13 21:48:23 +01:00
|
|
|
if (p != NULL) {
|
2001-11-15 20:32:05 +00:00
|
|
|
isc_mem_put(mctx, p, size);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
|
|
|
if (lex != NULL) {
|
2000-08-21 22:15:28 +00:00
|
|
|
isc_lex_destroy(&lex);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2000-08-21 22:15:28 +00:00
|
|
|
|
|
|
|
return (result);
|
|
|
|
}
|
|
|
|
|
2001-11-15 20:32:05 +00:00
|
|
|
static isc_result_t
|
2020-02-13 14:44:37 -08:00
|
|
|
getnode(dns_sdballnodes_t *allnodes, const char *name, dns_sdbnode_t **nodep) {
|
|
|
|
dns_name_t *newname;
|
|
|
|
const dns_name_t *origin;
|
|
|
|
dns_fixedname_t fnewname;
|
|
|
|
dns_sdb_t *sdb = (dns_sdb_t *)allnodes->common.db;
|
2000-11-16 22:33:53 +00:00
|
|
|
dns_sdbimplementation_t *imp = sdb->implementation;
|
2020-02-13 14:44:37 -08:00
|
|
|
dns_sdbnode_t *sdbnode;
|
|
|
|
isc_mem_t *mctx = sdb->common.mctx;
|
|
|
|
isc_buffer_t b;
|
|
|
|
isc_result_t result;
|
2000-08-23 18:28:03 +00:00
|
|
|
|
2018-03-28 14:38:09 +02:00
|
|
|
newname = dns_fixedname_initname(&fnewname);
|
2000-08-23 18:28:03 +00:00
|
|
|
|
2020-02-13 21:48:23 +01:00
|
|
|
if ((imp->flags & DNS_SDBFLAG_RELATIVERDATA) != 0) {
|
2000-08-23 18:28:03 +00:00
|
|
|
origin = &sdb->common.origin;
|
2020-02-13 21:48:23 +01:00
|
|
|
} else {
|
2000-08-23 18:28:03 +00:00
|
|
|
origin = dns_rootname;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2012-12-08 12:48:57 +11:00
|
|
|
isc_buffer_constinit(&b, name, strlen(name));
|
2000-08-23 18:28:03 +00:00
|
|
|
isc_buffer_add(&b, strlen(name));
|
|
|
|
|
2009-09-01 00:22:28 +00:00
|
|
|
result = dns_name_fromtext(newname, &b, origin, 0, NULL);
|
2020-02-13 21:48:23 +01:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
2000-08-23 18:28:03 +00:00
|
|
|
return (result);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2000-08-23 18:28:03 +00:00
|
|
|
|
|
|
|
if (allnodes->common.relative_names) {
|
|
|
|
/* All names are relative to the root */
|
|
|
|
unsigned int nlabels = dns_name_countlabels(newname);
|
|
|
|
dns_name_getlabelsequence(newname, 0, nlabels - 1, newname);
|
|
|
|
}
|
|
|
|
|
|
|
|
sdbnode = ISC_LIST_HEAD(allnodes->nodelist);
|
|
|
|
if (sdbnode == NULL || !dns_name_equal(sdbnode->name, newname)) {
|
|
|
|
sdbnode = NULL;
|
|
|
|
result = createnode(sdb, &sdbnode);
|
2020-02-13 21:48:23 +01:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
2000-08-23 18:28:03 +00:00
|
|
|
return (result);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2000-08-23 18:28:03 +00:00
|
|
|
sdbnode->name = isc_mem_get(mctx, sizeof(dns_name_t));
|
|
|
|
dns_name_init(sdbnode->name, NULL);
|
2019-11-01 08:31:13 -05:00
|
|
|
dns_name_dup(newname, mctx, sdbnode->name);
|
2000-08-23 18:28:03 +00:00
|
|
|
ISC_LIST_PREPEND(allnodes->nodelist, sdbnode, link);
|
|
|
|
if (allnodes->origin == NULL &&
|
2020-02-13 21:48:23 +01:00
|
|
|
dns_name_equal(newname, &sdb->common.origin)) {
|
2000-08-23 18:28:03 +00:00
|
|
|
allnodes->origin = sdbnode;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2000-08-23 18:28:03 +00:00
|
|
|
}
|
2001-11-15 20:32:05 +00:00
|
|
|
*nodep = sdbnode;
|
|
|
|
return (ISC_R_SUCCESS);
|
|
|
|
}
|
|
|
|
|
|
|
|
isc_result_t
|
|
|
|
dns_sdb_putnamedrr(dns_sdballnodes_t *allnodes, const char *name,
|
2020-02-13 14:44:37 -08:00
|
|
|
const char *type, dns_ttl_t ttl, const char *data) {
|
|
|
|
isc_result_t result;
|
2001-11-15 20:32:05 +00:00
|
|
|
dns_sdbnode_t *sdbnode = NULL;
|
|
|
|
result = getnode(allnodes, name, &sdbnode);
|
2020-02-13 21:48:23 +01:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
2001-11-15 20:32:05 +00:00
|
|
|
return (result);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2000-08-23 18:28:03 +00:00
|
|
|
return (dns_sdb_putrr(sdbnode, type, ttl, data));
|
2001-11-15 20:32:05 +00:00
|
|
|
}
|
2000-08-23 18:28:03 +00:00
|
|
|
|
2001-11-15 20:32:05 +00:00
|
|
|
isc_result_t
|
|
|
|
dns_sdb_putnamedrdata(dns_sdballnodes_t *allnodes, const char *name,
|
2020-02-12 13:59:18 +01:00
|
|
|
dns_rdatatype_t type, dns_ttl_t ttl, const void *rdata,
|
2020-02-13 14:44:37 -08:00
|
|
|
unsigned int rdlen) {
|
|
|
|
isc_result_t result;
|
2001-11-15 20:32:05 +00:00
|
|
|
dns_sdbnode_t *sdbnode = NULL;
|
|
|
|
result = getnode(allnodes, name, &sdbnode);
|
2020-02-13 21:48:23 +01:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
2001-11-15 20:32:05 +00:00
|
|
|
return (result);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2001-11-15 20:32:05 +00:00
|
|
|
return (dns_sdb_putrdata(sdbnode, type, ttl, rdata, rdlen));
|
2000-08-23 18:28:03 +00:00
|
|
|
}
|
|
|
|
|
2000-08-21 22:15:28 +00:00
|
|
|
isc_result_t
|
|
|
|
dns_sdb_putsoa(dns_sdblookup_t *lookup, const char *mname, const char *rname,
|
2020-02-13 14:44:37 -08:00
|
|
|
uint32_t serial) {
|
2000-08-21 22:15:28 +00:00
|
|
|
char str[2 * DNS_NAME_MAXTEXT + 5 * (sizeof("2147483647")) + 7];
|
2020-02-13 14:44:37 -08:00
|
|
|
int n;
|
2000-08-21 22:15:28 +00:00
|
|
|
|
|
|
|
REQUIRE(mname != NULL);
|
|
|
|
REQUIRE(rname != NULL);
|
|
|
|
|
2020-02-12 13:59:18 +01:00
|
|
|
n = snprintf(str, sizeof(str), "%s %s %u %u %u %u %u", mname, rname,
|
|
|
|
serial, SDB_DEFAULT_REFRESH, SDB_DEFAULT_RETRY,
|
2000-08-21 22:15:28 +00:00
|
|
|
SDB_DEFAULT_EXPIRE, SDB_DEFAULT_MINIMUM);
|
2020-02-13 21:48:23 +01:00
|
|
|
if (n >= (int)sizeof(str) || n < 0) {
|
2000-08-21 22:15:28 +00:00
|
|
|
return (ISC_R_NOSPACE);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2000-08-21 22:15:28 +00:00
|
|
|
return (dns_sdb_putrr(lookup, "SOA", SDB_DEFAULT_TTL, str));
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* DB routines
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void
|
2020-02-13 14:44:37 -08:00
|
|
|
attach(dns_db_t *source, dns_db_t **targetp) {
|
2020-02-12 13:59:18 +01:00
|
|
|
dns_sdb_t *sdb = (dns_sdb_t *)source;
|
2000-08-21 22:15:28 +00:00
|
|
|
|
|
|
|
REQUIRE(VALID_SDB(sdb));
|
|
|
|
|
2019-05-20 16:53:47 +02:00
|
|
|
isc_refcount_increment(&sdb->references);
|
2000-08-21 22:15:28 +00:00
|
|
|
|
|
|
|
*targetp = source;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2020-02-13 14:44:37 -08:00
|
|
|
destroy(dns_sdb_t *sdb) {
|
2000-11-16 22:33:53 +00:00
|
|
|
dns_sdbimplementation_t *imp = sdb->implementation;
|
2000-08-21 22:15:28 +00:00
|
|
|
|
2019-07-23 08:27:30 -04:00
|
|
|
isc_refcount_destroy(&sdb->references);
|
|
|
|
|
2001-05-29 18:34:24 +00:00
|
|
|
if (imp->methods->destroy != NULL) {
|
|
|
|
MAYBE_LOCK(sdb);
|
2020-02-12 13:59:18 +01:00
|
|
|
imp->methods->destroy(sdb->zone, imp->driverdata, &sdb->dbdata);
|
2001-05-29 18:34:24 +00:00
|
|
|
MAYBE_UNLOCK(sdb);
|
|
|
|
}
|
2000-08-21 22:15:28 +00:00
|
|
|
|
2019-07-23 17:16:57 -04:00
|
|
|
isc_mem_free(sdb->common.mctx, sdb->zone);
|
2000-08-21 22:15:28 +00:00
|
|
|
|
|
|
|
sdb->common.magic = 0;
|
|
|
|
sdb->common.impmagic = 0;
|
|
|
|
|
2019-07-23 17:16:57 -04:00
|
|
|
dns_name_free(&sdb->common.origin, sdb->common.mctx);
|
2000-08-21 22:15:28 +00:00
|
|
|
|
2019-07-23 17:16:57 -04:00
|
|
|
isc_mem_putanddetach(&sdb->common.mctx, sdb, sizeof(dns_sdb_t));
|
2000-08-21 22:15:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2020-02-13 14:44:37 -08:00
|
|
|
detach(dns_db_t **dbp) {
|
2000-08-21 22:15:28 +00:00
|
|
|
dns_sdb_t *sdb = (dns_sdb_t *)(*dbp);
|
|
|
|
|
|
|
|
REQUIRE(VALID_SDB(sdb));
|
|
|
|
|
|
|
|
*dbp = NULL;
|
2019-05-20 16:53:47 +02:00
|
|
|
|
|
|
|
if (isc_refcount_decrement(&sdb->references) == 1) {
|
|
|
|
destroy(sdb);
|
|
|
|
}
|
2000-08-21 22:15:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static isc_result_t
|
2020-02-13 14:44:37 -08:00
|
|
|
beginload(dns_db_t *db, dns_rdatacallbacks_t *callbacks) {
|
2000-08-21 22:15:28 +00:00
|
|
|
UNUSED(db);
|
2012-06-20 14:13:12 -05:00
|
|
|
UNUSED(callbacks);
|
2000-08-21 22:15:28 +00:00
|
|
|
return (ISC_R_NOTIMPLEMENTED);
|
|
|
|
}
|
|
|
|
|
|
|
|
static isc_result_t
|
2020-02-13 14:44:37 -08:00
|
|
|
endload(dns_db_t *db, dns_rdatacallbacks_t *callbacks) {
|
2000-08-21 22:15:28 +00:00
|
|
|
UNUSED(db);
|
2012-06-20 14:13:12 -05:00
|
|
|
UNUSED(callbacks);
|
2000-08-21 22:15:28 +00:00
|
|
|
return (ISC_R_NOTIMPLEMENTED);
|
|
|
|
}
|
|
|
|
|
|
|
|
static isc_result_t
|
2005-06-20 01:05:33 +00:00
|
|
|
dump(dns_db_t *db, dns_dbversion_t *version, const char *filename,
|
2020-02-13 14:44:37 -08:00
|
|
|
dns_masterformat_t masterformat) {
|
2000-08-21 22:15:28 +00:00
|
|
|
UNUSED(db);
|
|
|
|
UNUSED(version);
|
|
|
|
UNUSED(filename);
|
2005-06-20 01:05:33 +00:00
|
|
|
UNUSED(masterformat);
|
2000-08-21 22:15:28 +00:00
|
|
|
return (ISC_R_NOTIMPLEMENTED);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2020-02-13 14:44:37 -08:00
|
|
|
currentversion(dns_db_t *db, dns_dbversion_t **versionp) {
|
2000-08-21 22:15:28 +00:00
|
|
|
REQUIRE(versionp != NULL && *versionp == NULL);
|
|
|
|
|
|
|
|
UNUSED(db);
|
|
|
|
|
2020-02-12 13:59:18 +01:00
|
|
|
*versionp = (void *)&dummy;
|
2000-08-21 22:15:28 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
static isc_result_t
|
2020-02-13 14:44:37 -08:00
|
|
|
newversion(dns_db_t *db, dns_dbversion_t **versionp) {
|
2000-08-21 22:15:28 +00:00
|
|
|
UNUSED(db);
|
|
|
|
UNUSED(versionp);
|
|
|
|
|
|
|
|
return (ISC_R_NOTIMPLEMENTED);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2020-02-13 14:44:37 -08:00
|
|
|
attachversion(dns_db_t *db, dns_dbversion_t *source,
|
|
|
|
dns_dbversion_t **targetp) {
|
2020-02-12 13:59:18 +01:00
|
|
|
REQUIRE(source != NULL && source == (void *)&dummy);
|
2004-07-22 03:58:07 +00:00
|
|
|
REQUIRE(targetp != NULL && *targetp == NULL);
|
2000-08-21 22:15:28 +00:00
|
|
|
|
|
|
|
UNUSED(db);
|
2004-07-22 03:58:07 +00:00
|
|
|
*targetp = source;
|
2000-08-21 22:15:28 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2020-02-13 14:44:37 -08:00
|
|
|
closeversion(dns_db_t *db, dns_dbversion_t **versionp, bool commit) {
|
2020-02-12 13:59:18 +01:00
|
|
|
REQUIRE(versionp != NULL && *versionp == (void *)&dummy);
|
2020-03-30 13:49:55 -07:00
|
|
|
REQUIRE(!commit);
|
2000-08-21 22:15:28 +00:00
|
|
|
|
|
|
|
UNUSED(db);
|
|
|
|
UNUSED(commit);
|
|
|
|
|
|
|
|
*versionp = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static isc_result_t
|
2020-02-13 14:44:37 -08:00
|
|
|
createnode(dns_sdb_t *sdb, dns_sdbnode_t **nodep) {
|
2000-08-21 22:15:28 +00:00
|
|
|
dns_sdbnode_t *node;
|
|
|
|
|
|
|
|
node = isc_mem_get(sdb->common.mctx, sizeof(dns_sdbnode_t));
|
|
|
|
|
|
|
|
node->sdb = NULL;
|
|
|
|
attach((dns_db_t *)sdb, (dns_db_t **)&node->sdb);
|
|
|
|
ISC_LIST_INIT(node->lists);
|
|
|
|
ISC_LIST_INIT(node->buffers);
|
2000-08-23 18:28:03 +00:00
|
|
|
ISC_LINK_INIT(node, link);
|
|
|
|
node->name = NULL;
|
2000-11-17 23:32:27 +00:00
|
|
|
dns_rdatacallbacks_init(&node->callbacks);
|
2019-05-20 16:53:47 +02:00
|
|
|
|
|
|
|
isc_refcount_init(&node->references, 1);
|
|
|
|
|
2000-08-21 22:15:28 +00:00
|
|
|
node->magic = SDBLOOKUP_MAGIC;
|
|
|
|
|
|
|
|
*nodep = node;
|
|
|
|
return (ISC_R_SUCCESS);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2020-02-13 14:44:37 -08:00
|
|
|
destroynode(dns_sdbnode_t *node) {
|
2000-08-21 22:15:28 +00:00
|
|
|
dns_rdatalist_t *list;
|
2020-02-13 14:44:37 -08:00
|
|
|
dns_rdata_t *rdata;
|
|
|
|
isc_buffer_t *b;
|
|
|
|
dns_sdb_t *sdb;
|
|
|
|
isc_mem_t *mctx;
|
2000-08-23 18:28:03 +00:00
|
|
|
|
|
|
|
sdb = node->sdb;
|
|
|
|
mctx = sdb->common.mctx;
|
2000-08-21 22:15:28 +00:00
|
|
|
|
|
|
|
while (!ISC_LIST_EMPTY(node->lists)) {
|
|
|
|
list = ISC_LIST_HEAD(node->lists);
|
|
|
|
while (!ISC_LIST_EMPTY(list->rdata)) {
|
|
|
|
rdata = ISC_LIST_HEAD(list->rdata);
|
|
|
|
ISC_LIST_UNLINK(list->rdata, rdata, link);
|
2000-08-23 18:28:03 +00:00
|
|
|
isc_mem_put(mctx, rdata, sizeof(dns_rdata_t));
|
2000-08-21 22:15:28 +00:00
|
|
|
}
|
|
|
|
ISC_LIST_UNLINK(node->lists, list, link);
|
2000-08-23 18:28:03 +00:00
|
|
|
isc_mem_put(mctx, list, sizeof(dns_rdatalist_t));
|
2000-08-21 22:15:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
while (!ISC_LIST_EMPTY(node->buffers)) {
|
|
|
|
b = ISC_LIST_HEAD(node->buffers);
|
|
|
|
ISC_LIST_UNLINK(node->buffers, b, link);
|
|
|
|
isc_buffer_free(&b);
|
|
|
|
}
|
|
|
|
|
2000-08-23 18:28:03 +00:00
|
|
|
if (node->name != NULL) {
|
|
|
|
dns_name_free(node->name, mctx);
|
|
|
|
isc_mem_put(mctx, node->name, sizeof(dns_name_t));
|
|
|
|
}
|
2019-05-20 16:53:47 +02:00
|
|
|
|
2000-08-21 22:15:28 +00:00
|
|
|
node->magic = 0;
|
2000-08-23 18:28:03 +00:00
|
|
|
isc_mem_put(mctx, node, sizeof(dns_sdbnode_t));
|
2020-02-12 13:59:18 +01:00
|
|
|
detach((dns_db_t **)(void *)&sdb);
|
2000-08-21 22:15:28 +00:00
|
|
|
}
|
|
|
|
|
2019-08-09 16:25:49 +10:00
|
|
|
static isc_result_t
|
2020-02-13 14:44:37 -08:00
|
|
|
getoriginnode(dns_db_t *db, dns_dbnode_t **nodep) {
|
|
|
|
dns_sdb_t *sdb = (dns_sdb_t *)db;
|
|
|
|
dns_sdbnode_t *node = NULL;
|
|
|
|
isc_result_t result;
|
|
|
|
isc_buffer_t b;
|
|
|
|
char namestr[DNS_NAME_MAXTEXT + 1];
|
2019-08-09 16:25:49 +10:00
|
|
|
dns_sdbimplementation_t *imp;
|
2020-02-13 14:44:37 -08:00
|
|
|
dns_name_t relname;
|
|
|
|
dns_name_t *name;
|
2019-08-09 16:25:49 +10:00
|
|
|
|
|
|
|
REQUIRE(VALID_SDB(sdb));
|
|
|
|
REQUIRE(nodep != NULL && *nodep == NULL);
|
|
|
|
|
|
|
|
imp = sdb->implementation;
|
|
|
|
name = &sdb->common.origin;
|
|
|
|
|
|
|
|
if (imp->methods->lookup2 != NULL) {
|
|
|
|
if ((imp->flags & DNS_SDBFLAG_RELATIVEOWNER) != 0) {
|
|
|
|
dns_name_init(&relname, NULL);
|
|
|
|
name = &relname;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
isc_buffer_init(&b, namestr, sizeof(namestr));
|
|
|
|
if ((imp->flags & DNS_SDBFLAG_RELATIVEOWNER) != 0) {
|
|
|
|
dns_name_init(&relname, NULL);
|
|
|
|
result = dns_name_totext(&relname, true, &b);
|
|
|
|
if (result != ISC_R_SUCCESS) {
|
|
|
|
return (result);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
result = dns_name_totext(name, true, &b);
|
|
|
|
if (result != ISC_R_SUCCESS) {
|
|
|
|
return (result);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
isc_buffer_putuint8(&b, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
result = createnode(sdb, &node);
|
|
|
|
if (result != ISC_R_SUCCESS) {
|
|
|
|
return (result);
|
|
|
|
}
|
|
|
|
|
|
|
|
MAYBE_LOCK(sdb);
|
|
|
|
if (imp->methods->lookup2 != NULL) {
|
|
|
|
result = imp->methods->lookup2(&sdb->common.origin, name,
|
|
|
|
sdb->dbdata, node, NULL, NULL);
|
|
|
|
} else {
|
|
|
|
result = imp->methods->lookup(sdb->zone, namestr, sdb->dbdata,
|
|
|
|
node, NULL, NULL);
|
|
|
|
}
|
|
|
|
MAYBE_UNLOCK(sdb);
|
|
|
|
if (result != ISC_R_SUCCESS &&
|
2020-02-13 14:44:37 -08:00
|
|
|
!(result == ISC_R_NOTFOUND && imp->methods->authority != NULL))
|
|
|
|
{
|
2019-08-09 16:25:49 +10:00
|
|
|
destroynode(node);
|
|
|
|
return (result);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (imp->methods->authority != NULL) {
|
|
|
|
MAYBE_LOCK(sdb);
|
|
|
|
result = imp->methods->authority(sdb->zone, sdb->dbdata, node);
|
|
|
|
MAYBE_UNLOCK(sdb);
|
|
|
|
if (result != ISC_R_SUCCESS) {
|
|
|
|
destroynode(node);
|
|
|
|
return (result);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*nodep = node;
|
|
|
|
return (ISC_R_SUCCESS);
|
|
|
|
}
|
|
|
|
|
2000-08-21 22:15:28 +00:00
|
|
|
static isc_result_t
|
2018-04-17 08:29:14 -07:00
|
|
|
findnodeext(dns_db_t *db, const dns_name_t *name, bool create,
|
2011-10-11 00:09:03 +00:00
|
|
|
dns_clientinfomethods_t *methods, dns_clientinfo_t *clientinfo,
|
2020-02-13 14:44:37 -08:00
|
|
|
dns_dbnode_t **nodep) {
|
|
|
|
dns_sdb_t *sdb = (dns_sdb_t *)db;
|
|
|
|
dns_sdbnode_t *node = NULL;
|
|
|
|
isc_result_t result;
|
|
|
|
isc_buffer_t b;
|
|
|
|
char namestr[DNS_NAME_MAXTEXT + 1];
|
|
|
|
bool isorigin;
|
2000-11-16 22:33:53 +00:00
|
|
|
dns_sdbimplementation_t *imp;
|
2020-02-13 14:44:37 -08:00
|
|
|
dns_name_t relname;
|
|
|
|
unsigned int labels;
|
2000-08-21 22:15:28 +00:00
|
|
|
|
|
|
|
REQUIRE(VALID_SDB(sdb));
|
|
|
|
REQUIRE(nodep != NULL && *nodep == NULL);
|
|
|
|
|
|
|
|
UNUSED(name);
|
2000-12-01 01:00:47 +00:00
|
|
|
UNUSED(create);
|
2000-08-21 22:15:28 +00:00
|
|
|
|
2000-08-22 00:53:31 +00:00
|
|
|
imp = sdb->implementation;
|
|
|
|
|
2012-04-11 12:17:57 +10:00
|
|
|
isorigin = dns_name_equal(name, &sdb->common.origin);
|
2000-08-22 00:53:31 +00:00
|
|
|
|
2012-04-11 12:17:57 +10:00
|
|
|
if (imp->methods->lookup2 != NULL) {
|
|
|
|
if ((imp->flags & DNS_SDBFLAG_RELATIVEOWNER) != 0) {
|
|
|
|
labels = dns_name_countlabels(name) -
|
|
|
|
dns_name_countlabels(&db->origin);
|
|
|
|
dns_name_init(&relname, NULL);
|
|
|
|
dns_name_getlabelsequence(name, 0, labels, &relname);
|
|
|
|
name = &relname;
|
|
|
|
}
|
2000-08-22 00:53:31 +00:00
|
|
|
} else {
|
2012-04-11 12:17:57 +10:00
|
|
|
isc_buffer_init(&b, namestr, sizeof(namestr));
|
|
|
|
if ((imp->flags & DNS_SDBFLAG_RELATIVEOWNER) != 0) {
|
|
|
|
labels = dns_name_countlabels(name) -
|
|
|
|
dns_name_countlabels(&db->origin);
|
|
|
|
dns_name_init(&relname, NULL);
|
|
|
|
dns_name_getlabelsequence(name, 0, labels, &relname);
|
2018-04-17 08:29:14 -07:00
|
|
|
result = dns_name_totext(&relname, true, &b);
|
2020-02-13 21:48:23 +01:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
2012-04-11 12:17:57 +10:00
|
|
|
return (result);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2012-04-11 12:17:57 +10:00
|
|
|
} else {
|
2018-04-17 08:29:14 -07:00
|
|
|
result = dns_name_totext(name, true, &b);
|
2020-02-13 21:48:23 +01:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
2012-04-11 12:17:57 +10:00
|
|
|
return (result);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2012-04-11 12:17:57 +10:00
|
|
|
}
|
|
|
|
isc_buffer_putuint8(&b, 0);
|
2000-08-22 00:53:31 +00:00
|
|
|
}
|
2000-08-21 22:15:28 +00:00
|
|
|
|
|
|
|
result = createnode(sdb, &node);
|
2020-02-13 21:48:23 +01:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
2000-08-21 22:15:28 +00:00
|
|
|
return (result);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2000-08-21 22:15:28 +00:00
|
|
|
|
2000-12-06 01:08:41 +00:00
|
|
|
MAYBE_LOCK(sdb);
|
2020-02-13 21:48:23 +01:00
|
|
|
if (imp->methods->lookup2 != NULL) {
|
2012-04-11 12:17:57 +10:00
|
|
|
result = imp->methods->lookup2(&sdb->common.origin, name,
|
|
|
|
sdb->dbdata, node, methods,
|
|
|
|
clientinfo);
|
2020-02-13 21:48:23 +01:00
|
|
|
} else {
|
2012-04-11 12:17:57 +10:00
|
|
|
result = imp->methods->lookup(sdb->zone, namestr, sdb->dbdata,
|
|
|
|
node, methods, clientinfo);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2000-12-06 01:08:41 +00:00
|
|
|
MAYBE_UNLOCK(sdb);
|
2020-02-12 13:59:18 +01:00
|
|
|
if (result != ISC_R_SUCCESS && !(result == ISC_R_NOTFOUND && isorigin &&
|
2020-02-13 14:44:37 -08:00
|
|
|
imp->methods->authority != NULL))
|
|
|
|
{
|
2000-08-21 22:15:28 +00:00
|
|
|
destroynode(node);
|
|
|
|
return (result);
|
|
|
|
}
|
|
|
|
|
2000-08-22 22:06:46 +00:00
|
|
|
if (isorigin && imp->methods->authority != NULL) {
|
2000-12-06 01:08:41 +00:00
|
|
|
MAYBE_LOCK(sdb);
|
2000-08-22 22:06:46 +00:00
|
|
|
result = imp->methods->authority(sdb->zone, sdb->dbdata, node);
|
2000-12-06 01:08:41 +00:00
|
|
|
MAYBE_UNLOCK(sdb);
|
2000-08-21 22:15:28 +00:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
|
|
|
destroynode(node);
|
|
|
|
return (result);
|
|
|
|
}
|
|
|
|
}
|
2008-01-18 23:46:58 +00:00
|
|
|
|
2000-08-21 22:15:28 +00:00
|
|
|
*nodep = node;
|
|
|
|
return (ISC_R_SUCCESS);
|
|
|
|
}
|
|
|
|
|
|
|
|
static isc_result_t
|
2016-12-30 15:45:08 +11:00
|
|
|
findext(dns_db_t *db, const dns_name_t *name, dns_dbversion_t *version,
|
2011-10-11 00:09:03 +00:00
|
|
|
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,
|
2020-02-13 14:44:37 -08:00
|
|
|
dns_rdataset_t *rdataset, dns_rdataset_t *sigrdataset) {
|
|
|
|
dns_sdb_t *sdb = (dns_sdb_t *)db;
|
|
|
|
dns_dbnode_t *node = NULL;
|
2000-08-21 22:15:28 +00:00
|
|
|
dns_fixedname_t fname;
|
2020-02-13 14:44:37 -08:00
|
|
|
dns_rdataset_t xrdataset;
|
|
|
|
dns_name_t *xname;
|
|
|
|
unsigned int nlabels, olabels;
|
|
|
|
isc_result_t result;
|
|
|
|
unsigned int i;
|
|
|
|
unsigned int flags;
|
2000-08-21 22:15:28 +00:00
|
|
|
|
|
|
|
REQUIRE(VALID_SDB(sdb));
|
|
|
|
REQUIRE(nodep == NULL || *nodep == NULL);
|
2020-02-12 13:59:18 +01:00
|
|
|
REQUIRE(version == NULL || version == (void *)&dummy);
|
2000-08-21 22:15:28 +00:00
|
|
|
|
|
|
|
UNUSED(options);
|
|
|
|
|
2020-02-13 21:48:23 +01:00
|
|
|
if (!dns_name_issubdomain(name, &db->origin)) {
|
2000-08-21 22:15:28 +00:00
|
|
|
return (DNS_R_NXDOMAIN);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2000-08-21 22:15:28 +00:00
|
|
|
|
|
|
|
olabels = dns_name_countlabels(&db->origin);
|
|
|
|
nlabels = dns_name_countlabels(name);
|
|
|
|
|
2018-03-28 14:38:09 +02:00
|
|
|
xname = dns_fixedname_initname(&fname);
|
2000-08-21 22:15:28 +00:00
|
|
|
|
2003-09-17 05:34:55 +00:00
|
|
|
if (rdataset == NULL) {
|
|
|
|
dns_rdataset_init(&xrdataset);
|
2000-08-21 22:15:28 +00:00
|
|
|
rdataset = &xrdataset;
|
2003-09-17 05:34:55 +00:00
|
|
|
}
|
2000-08-21 22:15:28 +00:00
|
|
|
|
|
|
|
result = DNS_R_NXDOMAIN;
|
2012-04-11 12:17:57 +10:00
|
|
|
flags = sdb->implementation->flags;
|
|
|
|
i = (flags & DNS_SDBFLAG_DNS64) != 0 ? nlabels : olabels;
|
|
|
|
for (; i <= nlabels; i++) {
|
2000-08-21 22:15:28 +00:00
|
|
|
/*
|
|
|
|
* Look up the next label.
|
|
|
|
*/
|
|
|
|
dns_name_getlabelsequence(name, nlabels - i, i, xname);
|
2020-02-12 13:59:18 +01:00
|
|
|
result = findnodeext(db, xname, false, methods, clientinfo,
|
|
|
|
&node);
|
2012-03-28 10:21:13 +11:00
|
|
|
if (result == ISC_R_NOTFOUND) {
|
|
|
|
/*
|
|
|
|
* No data at zone apex?
|
|
|
|
*/
|
2020-02-13 21:48:23 +01:00
|
|
|
if (i == olabels) {
|
2012-03-28 10:21:13 +11:00
|
|
|
return (DNS_R_BADDB);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2000-08-21 22:15:28 +00:00
|
|
|
result = DNS_R_NXDOMAIN;
|
|
|
|
continue;
|
|
|
|
}
|
2020-02-13 21:48:23 +01:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
2012-03-28 10:21:13 +11:00
|
|
|
return (result);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2000-08-21 22:15:28 +00:00
|
|
|
|
2012-04-11 12:17:57 +10:00
|
|
|
/*
|
|
|
|
* DNS64 zone's don't have DNAME or NS records.
|
|
|
|
*/
|
2020-02-13 21:48:23 +01:00
|
|
|
if ((flags & DNS_SDBFLAG_DNS64) != 0) {
|
2012-04-11 12:17:57 +10:00
|
|
|
goto skip;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2012-04-11 12:17:57 +10:00
|
|
|
|
|
|
|
/*
|
|
|
|
* DNS64 zone's don't have DNAME or NS records.
|
|
|
|
*/
|
2020-02-13 21:48:23 +01:00
|
|
|
if ((flags & DNS_SDBFLAG_DNS64) != 0) {
|
2012-04-11 12:17:57 +10:00
|
|
|
goto skip;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2012-04-11 12:17:57 +10:00
|
|
|
|
2000-08-21 22:15:28 +00:00
|
|
|
/*
|
|
|
|
* Look for a DNAME at the current label, unless this is
|
|
|
|
* the qname.
|
|
|
|
*/
|
|
|
|
if (i < nlabels) {
|
|
|
|
result = findrdataset(db, node, version,
|
2020-02-12 13:59:18 +01:00
|
|
|
dns_rdatatype_dname, 0, now,
|
|
|
|
rdataset, sigrdataset);
|
2000-08-21 22:15:28 +00:00
|
|
|
if (result == ISC_R_SUCCESS) {
|
2001-03-17 02:52:29 +00:00
|
|
|
result = DNS_R_DNAME;
|
2000-08-21 22:15:28 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Look for an NS at the current label, unless this is the
|
2000-08-23 18:45:13 +00:00
|
|
|
* origin or glue is ok.
|
2000-08-21 22:15:28 +00:00
|
|
|
*/
|
2000-08-23 18:45:13 +00:00
|
|
|
if (i != olabels && (options & DNS_DBFIND_GLUEOK) == 0) {
|
2000-08-21 22:15:28 +00:00
|
|
|
result = findrdataset(db, node, version,
|
2020-02-12 13:59:18 +01:00
|
|
|
dns_rdatatype_ns, 0, now,
|
|
|
|
rdataset, sigrdataset);
|
2000-08-21 22:15:28 +00:00
|
|
|
if (result == ISC_R_SUCCESS) {
|
2020-02-12 13:59:18 +01:00
|
|
|
if (i == nlabels && type == dns_rdatatype_any) {
|
2001-03-17 02:52:29 +00:00
|
|
|
result = DNS_R_ZONECUT;
|
|
|
|
dns_rdataset_disassociate(rdataset);
|
2009-04-21 00:41:02 +00:00
|
|
|
if (sigrdataset != NULL &&
|
2020-02-12 13:59:18 +01:00
|
|
|
dns_rdataset_isassociated(
|
|
|
|
sigrdataset)) {
|
|
|
|
dns_rdataset_disassociate(
|
|
|
|
sigrdataset);
|
2009-04-21 00:41:02 +00:00
|
|
|
}
|
2020-02-13 21:48:23 +01:00
|
|
|
} else {
|
2000-08-21 22:15:28 +00:00
|
|
|
result = DNS_R_DELEGATION;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2000-08-21 22:15:28 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If the current name is not the qname, add another label
|
|
|
|
* and try again.
|
|
|
|
*/
|
|
|
|
if (i < nlabels) {
|
|
|
|
destroynode(node);
|
|
|
|
node = NULL;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2020-02-12 13:59:18 +01:00
|
|
|
skip:
|
2000-08-21 22:15:28 +00:00
|
|
|
/*
|
|
|
|
* If we're looking for ANY, we're done.
|
|
|
|
*/
|
|
|
|
if (type == dns_rdatatype_any) {
|
|
|
|
result = ISC_R_SUCCESS;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Look for the qtype.
|
|
|
|
*/
|
2020-02-12 13:59:18 +01:00
|
|
|
result = findrdataset(db, node, version, type, 0, now, rdataset,
|
|
|
|
sigrdataset);
|
2020-02-13 21:48:23 +01:00
|
|
|
if (result == ISC_R_SUCCESS) {
|
2000-08-21 22:15:28 +00:00
|
|
|
break;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2000-08-21 22:15:28 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Look for a CNAME
|
|
|
|
*/
|
|
|
|
if (type != dns_rdatatype_cname) {
|
|
|
|
result = findrdataset(db, node, version,
|
2020-02-12 13:59:18 +01:00
|
|
|
dns_rdatatype_cname, 0, now,
|
|
|
|
rdataset, sigrdataset);
|
2000-08-21 22:15:28 +00:00
|
|
|
if (result == ISC_R_SUCCESS) {
|
|
|
|
result = DNS_R_CNAME;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
result = DNS_R_NXRRSET;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2020-02-13 21:48:23 +01:00
|
|
|
if (rdataset == &xrdataset && dns_rdataset_isassociated(rdataset)) {
|
2000-08-21 22:15:28 +00:00
|
|
|
dns_rdataset_disassociate(rdataset);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2000-08-21 22:15:28 +00:00
|
|
|
|
|
|
|
if (foundname != NULL) {
|
2019-09-10 14:42:41 +02:00
|
|
|
dns_name_copynf(xname, foundname);
|
2000-08-21 22:15:28 +00:00
|
|
|
}
|
|
|
|
|
2020-02-13 21:48:23 +01:00
|
|
|
if (nodep != NULL) {
|
2000-08-21 22:15:28 +00:00
|
|
|
*nodep = node;
|
2020-02-13 21:48:23 +01:00
|
|
|
} else if (node != NULL) {
|
2000-08-21 22:15:28 +00:00
|
|
|
detachnode(db, &node);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2000-08-21 22:15:28 +00:00
|
|
|
|
|
|
|
return (result);
|
|
|
|
}
|
|
|
|
|
|
|
|
static isc_result_t
|
2016-12-30 15:45:08 +11:00
|
|
|
findzonecut(dns_db_t *db, const dns_name_t *name, unsigned int options,
|
2000-08-21 22:15:28 +00:00
|
|
|
isc_stdtime_t now, dns_dbnode_t **nodep, dns_name_t *foundname,
|
2018-06-13 09:29:40 +02:00
|
|
|
dns_name_t *dcname, dns_rdataset_t *rdataset,
|
2020-02-13 14:44:37 -08:00
|
|
|
dns_rdataset_t *sigrdataset) {
|
2000-08-21 22:15:28 +00:00
|
|
|
UNUSED(db);
|
|
|
|
UNUSED(name);
|
|
|
|
UNUSED(options);
|
|
|
|
UNUSED(now);
|
|
|
|
UNUSED(nodep);
|
|
|
|
UNUSED(foundname);
|
2018-06-13 09:29:40 +02:00
|
|
|
UNUSED(dcname);
|
2000-08-21 22:15:28 +00:00
|
|
|
UNUSED(rdataset);
|
|
|
|
UNUSED(sigrdataset);
|
|
|
|
|
|
|
|
return (ISC_R_NOTIMPLEMENTED);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2020-02-13 14:44:37 -08:00
|
|
|
attachnode(dns_db_t *db, dns_dbnode_t *source, dns_dbnode_t **targetp) {
|
|
|
|
dns_sdb_t *sdb = (dns_sdb_t *)db;
|
2000-08-21 22:15:28 +00:00
|
|
|
dns_sdbnode_t *node = (dns_sdbnode_t *)source;
|
|
|
|
|
|
|
|
REQUIRE(VALID_SDB(sdb));
|
2000-12-01 01:00:47 +00:00
|
|
|
|
|
|
|
UNUSED(sdb);
|
|
|
|
|
2019-05-20 16:53:47 +02:00
|
|
|
isc_refcount_increment(&node->references);
|
2000-08-21 22:15:28 +00:00
|
|
|
|
|
|
|
*targetp = source;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2020-02-13 14:44:37 -08:00
|
|
|
detachnode(dns_db_t *db, dns_dbnode_t **targetp) {
|
|
|
|
dns_sdb_t *sdb = (dns_sdb_t *)db;
|
2000-08-21 22:15:28 +00:00
|
|
|
dns_sdbnode_t *node;
|
|
|
|
|
|
|
|
REQUIRE(VALID_SDB(sdb));
|
|
|
|
REQUIRE(targetp != NULL && *targetp != NULL);
|
|
|
|
|
2000-12-01 01:00:47 +00:00
|
|
|
UNUSED(sdb);
|
|
|
|
|
2000-08-21 22:15:28 +00:00
|
|
|
node = (dns_sdbnode_t *)(*targetp);
|
|
|
|
|
2019-05-20 16:53:47 +02:00
|
|
|
*targetp = NULL;
|
2000-08-21 22:15:28 +00:00
|
|
|
|
2019-05-20 16:53:47 +02:00
|
|
|
if (isc_refcount_decrement(&node->references) == 1) {
|
2000-08-21 22:15:28 +00:00
|
|
|
destroynode(node);
|
2019-05-20 16:53:47 +02:00
|
|
|
}
|
2000-08-21 22:15:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static isc_result_t
|
2020-02-13 14:44:37 -08:00
|
|
|
expirenode(dns_db_t *db, dns_dbnode_t *node, isc_stdtime_t now) {
|
2000-08-21 22:15:28 +00:00
|
|
|
UNUSED(db);
|
|
|
|
UNUSED(node);
|
|
|
|
UNUSED(now);
|
|
|
|
INSIST(0);
|
2018-11-07 15:00:07 +07:00
|
|
|
ISC_UNREACHABLE();
|
2000-08-21 22:15:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2020-02-13 14:44:37 -08:00
|
|
|
printnode(dns_db_t *db, dns_dbnode_t *node, FILE *out) {
|
2000-08-21 22:15:28 +00:00
|
|
|
UNUSED(db);
|
|
|
|
UNUSED(node);
|
|
|
|
UNUSED(out);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
static isc_result_t
|
2020-02-13 14:44:37 -08:00
|
|
|
createiterator(dns_db_t *db, unsigned int options,
|
|
|
|
dns_dbiterator_t **iteratorp) {
|
2000-08-23 18:28:03 +00:00
|
|
|
dns_sdb_t *sdb = (dns_sdb_t *)db;
|
2019-07-23 17:16:57 -04:00
|
|
|
REQUIRE(VALID_SDB(sdb));
|
|
|
|
|
2020-02-13 14:44:37 -08:00
|
|
|
sdb_dbiterator_t *sdbiter;
|
|
|
|
isc_result_t result;
|
2019-07-23 17:16:57 -04:00
|
|
|
dns_sdbimplementation_t *imp = sdb->implementation;
|
2000-08-23 18:28:03 +00:00
|
|
|
|
2020-02-13 21:48:23 +01:00
|
|
|
if (imp->methods->allnodes == NULL) {
|
2000-08-23 18:28:03 +00:00
|
|
|
return (ISC_R_NOTIMPLEMENTED);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2000-08-23 18:28:03 +00:00
|
|
|
|
2008-09-24 02:46:23 +00:00
|
|
|
if ((options & DNS_DB_NSEC3ONLY) != 0 ||
|
2020-02-13 21:48:23 +01:00
|
|
|
(options & DNS_DB_NONSEC3) != 0) {
|
2008-09-24 03:16:58 +00:00
|
|
|
return (ISC_R_NOTIMPLEMENTED);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2008-09-24 02:46:23 +00:00
|
|
|
|
2000-08-23 18:28:03 +00:00
|
|
|
sdbiter = isc_mem_get(sdb->common.mctx, sizeof(sdb_dbiterator_t));
|
|
|
|
|
|
|
|
sdbiter->common.methods = &dbiterator_methods;
|
|
|
|
sdbiter->common.db = NULL;
|
|
|
|
dns_db_attach(db, &sdbiter->common.db);
|
2020-02-13 14:44:37 -08:00
|
|
|
sdbiter->common.relative_names = ((options & DNS_DB_RELATIVENAMES) !=
|
|
|
|
0);
|
2000-08-23 18:28:03 +00:00
|
|
|
sdbiter->common.magic = DNS_DBITERATOR_MAGIC;
|
|
|
|
ISC_LIST_INIT(sdbiter->nodelist);
|
|
|
|
sdbiter->current = NULL;
|
|
|
|
sdbiter->origin = NULL;
|
|
|
|
|
2000-12-06 01:08:41 +00:00
|
|
|
MAYBE_LOCK(sdb);
|
2000-08-23 18:28:03 +00:00
|
|
|
result = imp->methods->allnodes(sdb->zone, sdb->dbdata, sdbiter);
|
2000-12-06 01:08:41 +00:00
|
|
|
MAYBE_UNLOCK(sdb);
|
2000-08-23 18:28:03 +00:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
2020-02-12 13:59:18 +01:00
|
|
|
dbiterator_destroy((dns_dbiterator_t **)(void *)&sdbiter);
|
2000-08-23 18:28:03 +00:00
|
|
|
return (result);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sdbiter->origin != NULL) {
|
|
|
|
ISC_LIST_UNLINK(sdbiter->nodelist, sdbiter->origin, link);
|
|
|
|
ISC_LIST_PREPEND(sdbiter->nodelist, sdbiter->origin, link);
|
|
|
|
}
|
|
|
|
|
|
|
|
*iteratorp = (dns_dbiterator_t *)sdbiter;
|
|
|
|
|
|
|
|
return (ISC_R_SUCCESS);
|
2000-08-21 22:15:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static isc_result_t
|
|
|
|
findrdataset(dns_db_t *db, dns_dbnode_t *node, dns_dbversion_t *version,
|
2020-02-12 13:59:18 +01:00
|
|
|
dns_rdatatype_t type, dns_rdatatype_t covers, isc_stdtime_t now,
|
2020-02-13 14:44:37 -08:00
|
|
|
dns_rdataset_t *rdataset, dns_rdataset_t *sigrdataset) {
|
2019-07-23 17:16:57 -04:00
|
|
|
REQUIRE(VALID_SDBNODE(node));
|
|
|
|
|
2000-08-21 22:15:28 +00:00
|
|
|
dns_rdatalist_t *list;
|
2020-02-13 14:44:37 -08:00
|
|
|
dns_sdbnode_t *sdbnode = (dns_sdbnode_t *)node;
|
2000-08-21 22:15:28 +00:00
|
|
|
|
|
|
|
UNUSED(db);
|
|
|
|
UNUSED(version);
|
|
|
|
UNUSED(covers);
|
|
|
|
UNUSED(now);
|
|
|
|
UNUSED(sigrdataset);
|
|
|
|
|
2020-02-13 21:48:23 +01:00
|
|
|
if (type == dns_rdatatype_rrsig) {
|
2000-08-21 22:15:28 +00:00
|
|
|
return (ISC_R_NOTIMPLEMENTED);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2000-08-21 22:15:28 +00:00
|
|
|
|
|
|
|
list = ISC_LIST_HEAD(sdbnode->lists);
|
|
|
|
while (list != NULL) {
|
2020-02-13 21:48:23 +01:00
|
|
|
if (list->type == type) {
|
2000-08-21 22:15:28 +00:00
|
|
|
break;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2000-08-21 22:15:28 +00:00
|
|
|
list = ISC_LIST_NEXT(list, link);
|
|
|
|
}
|
2020-02-13 21:48:23 +01:00
|
|
|
if (list == NULL) {
|
2000-08-21 22:15:28 +00:00
|
|
|
return (ISC_R_NOTFOUND);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2000-08-21 22:15:28 +00:00
|
|
|
|
|
|
|
list_tordataset(list, db, node, rdataset);
|
|
|
|
|
|
|
|
return (ISC_R_SUCCESS);
|
|
|
|
}
|
|
|
|
|
|
|
|
static isc_result_t
|
|
|
|
allrdatasets(dns_db_t *db, dns_dbnode_t *node, dns_dbversion_t *version,
|
2020-02-13 14:44:37 -08:00
|
|
|
isc_stdtime_t now, dns_rdatasetiter_t **iteratorp) {
|
2000-08-21 22:15:28 +00:00
|
|
|
sdb_rdatasetiter_t *iterator;
|
|
|
|
|
|
|
|
REQUIRE(version == NULL || version == &dummy);
|
2008-01-18 23:46:58 +00:00
|
|
|
|
2000-08-21 22:15:28 +00:00
|
|
|
UNUSED(version);
|
|
|
|
UNUSED(now);
|
|
|
|
|
|
|
|
iterator = isc_mem_get(db->mctx, sizeof(sdb_rdatasetiter_t));
|
|
|
|
|
|
|
|
iterator->common.magic = DNS_RDATASETITER_MAGIC;
|
|
|
|
iterator->common.methods = &rdatasetiter_methods;
|
|
|
|
iterator->common.db = db;
|
|
|
|
iterator->common.node = NULL;
|
|
|
|
attachnode(db, node, &iterator->common.node);
|
|
|
|
iterator->common.version = version;
|
|
|
|
iterator->common.now = now;
|
|
|
|
|
|
|
|
*iteratorp = (dns_rdatasetiter_t *)iterator;
|
|
|
|
|
|
|
|
return (ISC_R_SUCCESS);
|
|
|
|
}
|
|
|
|
|
|
|
|
static isc_result_t
|
|
|
|
addrdataset(dns_db_t *db, dns_dbnode_t *node, dns_dbversion_t *version,
|
|
|
|
isc_stdtime_t now, dns_rdataset_t *rdataset, unsigned int options,
|
2020-02-13 14:44:37 -08:00
|
|
|
dns_rdataset_t *addedrdataset) {
|
2000-08-21 22:15:28 +00:00
|
|
|
UNUSED(db);
|
|
|
|
UNUSED(node);
|
|
|
|
UNUSED(version);
|
|
|
|
UNUSED(now);
|
|
|
|
UNUSED(rdataset);
|
|
|
|
UNUSED(options);
|
|
|
|
UNUSED(addedrdataset);
|
|
|
|
|
|
|
|
return (ISC_R_NOTIMPLEMENTED);
|
|
|
|
}
|
|
|
|
|
|
|
|
static isc_result_t
|
|
|
|
subtractrdataset(dns_db_t *db, dns_dbnode_t *node, dns_dbversion_t *version,
|
2000-12-01 01:22:45 +00:00
|
|
|
dns_rdataset_t *rdataset, unsigned int options,
|
2020-02-13 14:44:37 -08:00
|
|
|
dns_rdataset_t *newrdataset) {
|
2000-08-21 22:15:28 +00:00
|
|
|
UNUSED(db);
|
|
|
|
UNUSED(node);
|
|
|
|
UNUSED(version);
|
|
|
|
UNUSED(rdataset);
|
2000-12-01 01:22:45 +00:00
|
|
|
UNUSED(options);
|
2000-08-21 22:15:28 +00:00
|
|
|
UNUSED(newrdataset);
|
|
|
|
|
|
|
|
return (ISC_R_NOTIMPLEMENTED);
|
|
|
|
}
|
|
|
|
|
|
|
|
static isc_result_t
|
|
|
|
deleterdataset(dns_db_t *db, dns_dbnode_t *node, dns_dbversion_t *version,
|
2020-02-13 14:44:37 -08:00
|
|
|
dns_rdatatype_t type, dns_rdatatype_t covers) {
|
2000-08-21 22:15:28 +00:00
|
|
|
UNUSED(db);
|
|
|
|
UNUSED(node);
|
|
|
|
UNUSED(version);
|
|
|
|
UNUSED(type);
|
|
|
|
UNUSED(covers);
|
|
|
|
|
|
|
|
return (ISC_R_NOTIMPLEMENTED);
|
|
|
|
}
|
|
|
|
|
2018-04-17 08:29:14 -07:00
|
|
|
static bool
|
2020-02-13 14:44:37 -08:00
|
|
|
issecure(dns_db_t *db) {
|
2000-08-21 22:15:28 +00:00
|
|
|
UNUSED(db);
|
|
|
|
|
2018-04-17 08:29:14 -07:00
|
|
|
return (false);
|
2000-08-21 22:15:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned int
|
2020-02-13 14:44:37 -08:00
|
|
|
nodecount(dns_db_t *db) {
|
2000-08-21 22:15:28 +00:00
|
|
|
UNUSED(db);
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2018-04-17 08:29:14 -07:00
|
|
|
static bool
|
2020-02-13 14:44:37 -08:00
|
|
|
ispersistent(dns_db_t *db) {
|
2000-08-21 22:15:28 +00:00
|
|
|
UNUSED(db);
|
2018-04-17 08:29:14 -07:00
|
|
|
return (true);
|
2000-08-21 22:15:28 +00:00
|
|
|
}
|
|
|
|
|
2000-08-31 13:04:47 +00:00
|
|
|
static void
|
2020-02-13 14:44:37 -08:00
|
|
|
overmem(dns_db_t *db, bool over) {
|
2000-08-31 13:04:47 +00:00
|
|
|
UNUSED(db);
|
2015-02-27 10:55:55 +11:00
|
|
|
UNUSED(over);
|
2000-08-31 13:04:47 +00:00
|
|
|
}
|
|
|
|
|
2004-03-04 06:56:41 +00:00
|
|
|
static void
|
2020-02-13 14:44:37 -08:00
|
|
|
settask(dns_db_t *db, isc_task_t *task) {
|
2004-03-04 06:56:41 +00:00
|
|
|
UNUSED(db);
|
|
|
|
UNUSED(task);
|
|
|
|
}
|
|
|
|
|
2000-08-21 22:15:28 +00:00
|
|
|
static dns_dbmethods_t sdb_methods = {
|
|
|
|
attach,
|
|
|
|
detach,
|
|
|
|
beginload,
|
|
|
|
endload,
|
2020-02-12 13:59:18 +01:00
|
|
|
NULL, /* serialize */
|
2000-08-21 22:15:28 +00:00
|
|
|
dump,
|
|
|
|
currentversion,
|
|
|
|
newversion,
|
|
|
|
attachversion,
|
|
|
|
closeversion,
|
2020-02-12 13:59:18 +01:00
|
|
|
NULL, /* findnode */
|
|
|
|
NULL, /* find */
|
2000-08-21 22:15:28 +00:00
|
|
|
findzonecut,
|
|
|
|
attachnode,
|
|
|
|
detachnode,
|
|
|
|
expirenode,
|
|
|
|
printnode,
|
|
|
|
createiterator,
|
|
|
|
findrdataset,
|
|
|
|
allrdatasets,
|
|
|
|
addrdataset,
|
|
|
|
subtractrdataset,
|
|
|
|
deleterdataset,
|
|
|
|
issecure,
|
|
|
|
nodecount,
|
2000-08-31 13:04:47 +00:00
|
|
|
ispersistent,
|
2004-03-04 06:56:41 +00:00
|
|
|
overmem,
|
2004-12-21 10:45:20 +00:00
|
|
|
settask,
|
2020-02-12 13:59:18 +01:00
|
|
|
getoriginnode, /* getoriginnode */
|
|
|
|
NULL, /* transfernode */
|
|
|
|
NULL, /* getnsec3parameters */
|
|
|
|
NULL, /* findnsec3node */
|
|
|
|
NULL, /* setsigningtime */
|
|
|
|
NULL, /* getsigningtime */
|
|
|
|
NULL, /* resigned */
|
|
|
|
NULL, /* isdnssec */
|
|
|
|
NULL, /* getrrsetstats */
|
|
|
|
NULL, /* rpz_attach */
|
|
|
|
NULL, /* rpz_ready */
|
2011-10-11 00:09:03 +00:00
|
|
|
findnodeext,
|
2012-05-14 10:06:05 -07:00
|
|
|
findext,
|
2020-02-12 13:59:18 +01:00
|
|
|
NULL, /* setcachestats */
|
|
|
|
NULL, /* hashsize */
|
|
|
|
NULL, /* nodefullname */
|
|
|
|
NULL, /* getsize */
|
|
|
|
NULL, /* setservestalettl */
|
|
|
|
NULL, /* getservestalettl */
|
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
|
|
|
NULL, /* setservestalerefresh */
|
|
|
|
NULL, /* getservestalerefresh */
|
Fix the rbt hashtable and grow it when setting max-cache-size
There were several problems with rbt hashtable implementation:
1. Our internal hashing function returns uint64_t value, but it was
silently truncated to unsigned int in dns_name_hash() and
dns_name_fullhash() functions. As the SipHash 2-4 higher bits are
more random, we need to use the upper half of the return value.
2. The hashtable implementation in rbt.c was using modulo to pick the
slot number for the hash table. This has several problems because
modulo is: a) slow, b) oblivious to patterns in the input data. This
could lead to very uneven distribution of the hashed data in the
hashtable. Combined with the single-linked lists we use, it could
really hog-down the lookup and removal of the nodes from the rbt
tree[a]. The Fibonacci Hashing is much better fit for the hashtable
function here. For longer description, read "Fibonacci Hashing: The
Optimization that the World Forgot"[b] or just look at the Linux
kernel. Also this will make Diego very happy :).
3. The hashtable would rehash every time the number of nodes in the rbt
tree would exceed 3 * (hashtable size). The overcommit will make the
uneven distribution in the hashtable even worse, but the main problem
lies in the rehashing - every time the database grows beyond the
limit, each subsequent rehashing will be much slower. The mitigation
here is letting the rbt know how big the cache can grown and
pre-allocate the hashtable to be big enough to actually never need to
rehash. This will consume more memory at the start, but since the
size of the hashtable is capped to `1 << 32` (e.g. 4 mio entries), it
will only consume maximum of 32GB of memory for hashtable in the
worst case (and max-cache-size would need to be set to more than
4TB). Calling the dns_db_adjusthashsize() will also cap the maximum
size of the hashtable to the pre-computed number of bits, so it won't
try to consume more gigabytes of memory than available for the
database.
FIXME: What is the average size of the rbt node that gets hashed? I
chose the pagesize (4k) as initial value to precompute the size of
the hashtable, but the value is based on feeling and not any real
data.
For future work, there are more places where we use result of the hash
value modulo some small number and that would benefit from Fibonacci
Hashing to get better distribution.
Notes:
a. A doubly linked list should be used here to speedup the removal of
the entries from the hashtable.
b. https://probablydance.com/2018/06/16/fibonacci-hashing-the-optimization-that-the-world-forgot-or-a-better-alternative-to-integer-modulo/
2020-07-16 10:29:54 +02:00
|
|
|
NULL, /* setgluecachestats */
|
|
|
|
NULL /* adjusthashsize */
|
2000-08-21 22:15:28 +00:00
|
|
|
};
|
|
|
|
|
2000-11-18 01:35:13 +00:00
|
|
|
static isc_result_t
|
2016-12-30 15:45:08 +11:00
|
|
|
dns_sdb_create(isc_mem_t *mctx, const dns_name_t *origin, dns_dbtype_t type,
|
2000-08-21 22:15:28 +00:00
|
|
|
dns_rdataclass_t rdclass, unsigned int argc, char *argv[],
|
2020-02-13 14:44:37 -08:00
|
|
|
void *driverarg, dns_db_t **dbp) {
|
|
|
|
dns_sdb_t *sdb;
|
|
|
|
isc_result_t result;
|
|
|
|
char zonestr[DNS_NAME_MAXTEXT + 1];
|
|
|
|
isc_buffer_t b;
|
2000-11-16 22:33:53 +00:00
|
|
|
dns_sdbimplementation_t *imp;
|
2000-08-21 22:15:28 +00:00
|
|
|
|
2000-11-16 22:33:53 +00:00
|
|
|
REQUIRE(driverarg != NULL);
|
2000-08-21 22:15:28 +00:00
|
|
|
|
2000-11-16 22:33:53 +00:00
|
|
|
imp = driverarg;
|
2000-08-21 22:15:28 +00:00
|
|
|
|
2020-02-13 21:48:23 +01:00
|
|
|
if (type != dns_dbtype_zone) {
|
2000-08-21 22:15:28 +00:00
|
|
|
return (ISC_R_NOTIMPLEMENTED);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2000-08-21 22:15:28 +00:00
|
|
|
|
|
|
|
sdb = isc_mem_get(mctx, sizeof(dns_sdb_t));
|
|
|
|
memset(sdb, 0, sizeof(dns_sdb_t));
|
|
|
|
|
|
|
|
dns_name_init(&sdb->common.origin, NULL);
|
|
|
|
sdb->common.attributes = 0;
|
|
|
|
sdb->common.methods = &sdb_methods;
|
|
|
|
sdb->common.rdclass = rdclass;
|
|
|
|
sdb->common.mctx = NULL;
|
|
|
|
sdb->implementation = imp;
|
|
|
|
|
|
|
|
isc_mem_attach(mctx, &sdb->common.mctx);
|
|
|
|
|
2001-02-13 20:11:15 +00:00
|
|
|
result = dns_name_dupwithoffsets(origin, mctx, &sdb->common.origin);
|
2020-02-13 21:48:23 +01:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
2001-05-29 18:34:24 +00:00
|
|
|
goto cleanup_lock;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2001-02-13 20:11:15 +00:00
|
|
|
|
2000-08-21 22:15:28 +00:00
|
|
|
isc_buffer_init(&b, zonestr, sizeof(zonestr));
|
2018-04-17 08:29:14 -07:00
|
|
|
result = dns_name_totext(origin, true, &b);
|
2020-02-13 21:48:23 +01:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
2001-02-13 20:11:15 +00:00
|
|
|
goto cleanup_origin;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2000-08-21 22:15:28 +00:00
|
|
|
isc_buffer_putuint8(&b, 0);
|
2001-02-13 20:11:15 +00:00
|
|
|
|
2000-08-21 22:15:28 +00:00
|
|
|
sdb->zone = isc_mem_strdup(mctx, zonestr);
|
2001-02-13 20:11:15 +00:00
|
|
|
|
2000-08-21 22:15:28 +00:00
|
|
|
sdb->dbdata = NULL;
|
2000-08-22 22:06:46 +00:00
|
|
|
if (imp->methods->create != NULL) {
|
2001-05-29 18:34:24 +00:00
|
|
|
MAYBE_LOCK(sdb);
|
2000-11-17 01:27:34 +00:00
|
|
|
result = imp->methods->create(sdb->zone, argc, argv,
|
2000-08-22 22:06:46 +00:00
|
|
|
imp->driverdata, &sdb->dbdata);
|
2001-05-29 18:34:24 +00:00
|
|
|
MAYBE_UNLOCK(sdb);
|
2020-02-13 21:48:23 +01:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
2001-02-13 20:11:15 +00:00
|
|
|
goto cleanup_zonestr;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2000-08-21 22:15:28 +00:00
|
|
|
}
|
|
|
|
|
2019-05-20 16:53:47 +02:00
|
|
|
isc_refcount_init(&sdb->references, 1);
|
2000-08-21 22:15:28 +00:00
|
|
|
|
|
|
|
sdb->common.magic = DNS_DB_MAGIC;
|
|
|
|
sdb->common.impmagic = SDB_MAGIC;
|
|
|
|
|
|
|
|
*dbp = (dns_db_t *)sdb;
|
|
|
|
|
|
|
|
return (ISC_R_SUCCESS);
|
2001-02-13 20:11:15 +00:00
|
|
|
|
2020-02-12 13:59:18 +01:00
|
|
|
cleanup_zonestr:
|
2001-02-13 20:11:15 +00:00
|
|
|
isc_mem_free(mctx, sdb->zone);
|
2020-02-12 13:59:18 +01:00
|
|
|
cleanup_origin:
|
2001-02-13 20:11:15 +00:00
|
|
|
dns_name_free(&sdb->common.origin, mctx);
|
2020-02-12 13:59:18 +01:00
|
|
|
cleanup_lock:
|
2019-07-23 17:16:57 -04:00
|
|
|
isc_mem_putanddetach(&mctx, sdb, sizeof(dns_sdb_t));
|
2001-02-13 20:11:15 +00:00
|
|
|
|
|
|
|
return (result);
|
2000-08-21 22:15:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Rdataset Methods
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void
|
2020-02-13 14:44:37 -08:00
|
|
|
disassociate(dns_rdataset_t *rdataset) {
|
|
|
|
dns_dbnode_t *node = rdataset->private5;
|
2020-02-12 13:59:18 +01:00
|
|
|
dns_sdbnode_t *sdbnode = (dns_sdbnode_t *)node;
|
2020-02-13 14:44:37 -08:00
|
|
|
dns_db_t *db = (dns_db_t *)sdbnode->sdb;
|
2000-08-21 22:15:28 +00:00
|
|
|
|
|
|
|
detachnode(db, &node);
|
|
|
|
isc__rdatalist_disassociate(rdataset);
|
|
|
|
}
|
|
|
|
|
2001-02-20 23:20:44 +00:00
|
|
|
static void
|
2020-02-13 14:44:37 -08:00
|
|
|
rdataset_clone(dns_rdataset_t *source, dns_rdataset_t *target) {
|
|
|
|
dns_dbnode_t *node = source->private5;
|
2020-02-12 13:59:18 +01:00
|
|
|
dns_sdbnode_t *sdbnode = (dns_sdbnode_t *)node;
|
2020-02-13 14:44:37 -08:00
|
|
|
dns_db_t *db = (dns_db_t *)sdbnode->sdb;
|
|
|
|
dns_dbnode_t *tempdb = NULL;
|
2001-02-20 23:20:44 +00:00
|
|
|
|
|
|
|
isc__rdatalist_clone(source, target);
|
|
|
|
attachnode(db, node, &tempdb);
|
|
|
|
source->private5 = tempdb;
|
|
|
|
}
|
|
|
|
|
2018-03-19 17:31:53 +00:00
|
|
|
static dns_rdatasetmethods_t sdb_rdataset_methods = {
|
2000-08-21 22:15:28 +00:00
|
|
|
disassociate,
|
|
|
|
isc__rdatalist_first,
|
|
|
|
isc__rdatalist_next,
|
|
|
|
isc__rdatalist_current,
|
2001-02-20 23:20:44 +00:00
|
|
|
rdataset_clone,
|
2004-01-14 02:06:51 +00:00
|
|
|
isc__rdatalist_count,
|
|
|
|
isc__rdatalist_addnoqname,
|
2004-12-21 10:45:20 +00:00
|
|
|
isc__rdatalist_getnoqname,
|
2017-04-22 08:25:10 +05:30
|
|
|
NULL, /* addclosest */
|
|
|
|
NULL, /* getclosest */
|
|
|
|
NULL, /* settrust */
|
|
|
|
NULL, /* expire */
|
|
|
|
NULL, /* clearprefetch */
|
|
|
|
NULL, /* setownercase */
|
|
|
|
NULL, /* getownercase */
|
|
|
|
NULL /* addglue */
|
2000-08-21 22:15:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
2020-02-12 13:59:18 +01:00
|
|
|
list_tordataset(dns_rdatalist_t *rdatalist, dns_db_t *db, dns_dbnode_t *node,
|
2020-02-13 14:44:37 -08:00
|
|
|
dns_rdataset_t *rdataset) {
|
2001-02-20 23:20:44 +00:00
|
|
|
/*
|
|
|
|
* The sdb rdataset is an rdatalist with some additions.
|
|
|
|
* - private1 & private2 are used by the rdatalist.
|
|
|
|
* - private3 & private 4 are unused.
|
|
|
|
* - private5 is the node.
|
|
|
|
*/
|
|
|
|
|
2000-08-21 22:15:28 +00:00
|
|
|
/* This should never fail. */
|
|
|
|
RUNTIME_CHECK(dns_rdatalist_tordataset(rdatalist, rdataset) ==
|
|
|
|
ISC_R_SUCCESS);
|
|
|
|
|
2018-03-19 17:31:53 +00:00
|
|
|
rdataset->methods = &sdb_rdataset_methods;
|
2000-08-21 22:15:28 +00:00
|
|
|
dns_db_attachnode(db, node, &rdataset->private5);
|
|
|
|
}
|
|
|
|
|
2000-08-23 18:28:03 +00:00
|
|
|
/*
|
|
|
|
* Database Iterator Methods
|
|
|
|
*/
|
|
|
|
static void
|
2020-02-13 14:44:37 -08:00
|
|
|
dbiterator_destroy(dns_dbiterator_t **iteratorp) {
|
2000-08-23 18:28:03 +00:00
|
|
|
sdb_dbiterator_t *sdbiter = (sdb_dbiterator_t *)(*iteratorp);
|
2020-02-13 14:44:37 -08:00
|
|
|
dns_sdb_t *sdb = (dns_sdb_t *)sdbiter->common.db;
|
2000-08-23 18:28:03 +00:00
|
|
|
|
|
|
|
while (!ISC_LIST_EMPTY(sdbiter->nodelist)) {
|
|
|
|
dns_sdbnode_t *node;
|
|
|
|
node = ISC_LIST_HEAD(sdbiter->nodelist);
|
|
|
|
ISC_LIST_UNLINK(sdbiter->nodelist, node, link);
|
|
|
|
destroynode(node);
|
|
|
|
}
|
|
|
|
|
|
|
|
dns_db_detach(&sdbiter->common.db);
|
|
|
|
isc_mem_put(sdb->common.mctx, sdbiter, sizeof(sdb_dbiterator_t));
|
|
|
|
|
|
|
|
*iteratorp = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static isc_result_t
|
2020-02-13 14:44:37 -08:00
|
|
|
dbiterator_first(dns_dbiterator_t *iterator) {
|
2000-08-23 18:28:03 +00:00
|
|
|
sdb_dbiterator_t *sdbiter = (sdb_dbiterator_t *)iterator;
|
|
|
|
|
|
|
|
sdbiter->current = ISC_LIST_HEAD(sdbiter->nodelist);
|
2020-02-13 21:48:23 +01:00
|
|
|
if (sdbiter->current == NULL) {
|
2000-08-23 18:28:03 +00:00
|
|
|
return (ISC_R_NOMORE);
|
2020-02-13 21:48:23 +01:00
|
|
|
} else {
|
2000-08-23 18:28:03 +00:00
|
|
|
return (ISC_R_SUCCESS);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2000-08-23 18:28:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static isc_result_t
|
2020-02-13 14:44:37 -08:00
|
|
|
dbiterator_last(dns_dbiterator_t *iterator) {
|
2000-08-23 18:28:03 +00:00
|
|
|
sdb_dbiterator_t *sdbiter = (sdb_dbiterator_t *)iterator;
|
|
|
|
|
|
|
|
sdbiter->current = ISC_LIST_TAIL(sdbiter->nodelist);
|
2020-02-13 21:48:23 +01:00
|
|
|
if (sdbiter->current == NULL) {
|
2000-08-23 18:28:03 +00:00
|
|
|
return (ISC_R_NOMORE);
|
2020-02-13 21:48:23 +01:00
|
|
|
} else {
|
2000-08-23 18:28:03 +00:00
|
|
|
return (ISC_R_SUCCESS);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2000-08-23 18:28:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static isc_result_t
|
2020-02-13 14:44:37 -08:00
|
|
|
dbiterator_seek(dns_dbiterator_t *iterator, const dns_name_t *name) {
|
2000-08-23 18:28:03 +00:00
|
|
|
sdb_dbiterator_t *sdbiter = (sdb_dbiterator_t *)iterator;
|
|
|
|
|
|
|
|
sdbiter->current = ISC_LIST_HEAD(sdbiter->nodelist);
|
2009-06-26 06:21:03 +00:00
|
|
|
while (sdbiter->current != NULL) {
|
2020-02-13 21:48:23 +01:00
|
|
|
if (dns_name_equal(sdbiter->current->name, name)) {
|
2000-08-23 18:28:03 +00:00
|
|
|
return (ISC_R_SUCCESS);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2009-06-26 06:21:03 +00:00
|
|
|
sdbiter->current = ISC_LIST_NEXT(sdbiter->current, link);
|
|
|
|
}
|
2000-08-23 18:28:03 +00:00
|
|
|
return (ISC_R_NOTFOUND);
|
|
|
|
}
|
|
|
|
|
|
|
|
static isc_result_t
|
2020-02-13 14:44:37 -08:00
|
|
|
dbiterator_prev(dns_dbiterator_t *iterator) {
|
2000-08-23 18:28:03 +00:00
|
|
|
sdb_dbiterator_t *sdbiter = (sdb_dbiterator_t *)iterator;
|
|
|
|
|
|
|
|
sdbiter->current = ISC_LIST_PREV(sdbiter->current, link);
|
2020-02-13 21:48:23 +01:00
|
|
|
if (sdbiter->current == NULL) {
|
2000-08-23 18:28:03 +00:00
|
|
|
return (ISC_R_NOMORE);
|
2020-02-13 21:48:23 +01:00
|
|
|
} else {
|
2000-08-23 18:28:03 +00:00
|
|
|
return (ISC_R_SUCCESS);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2000-08-23 18:28:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static isc_result_t
|
2020-02-13 14:44:37 -08:00
|
|
|
dbiterator_next(dns_dbiterator_t *iterator) {
|
2000-08-23 18:28:03 +00:00
|
|
|
sdb_dbiterator_t *sdbiter = (sdb_dbiterator_t *)iterator;
|
|
|
|
|
|
|
|
sdbiter->current = ISC_LIST_NEXT(sdbiter->current, link);
|
2020-02-13 21:48:23 +01:00
|
|
|
if (sdbiter->current == NULL) {
|
2000-08-23 18:28:03 +00:00
|
|
|
return (ISC_R_NOMORE);
|
2020-02-13 21:48:23 +01:00
|
|
|
} else {
|
2000-08-23 18:28:03 +00:00
|
|
|
return (ISC_R_SUCCESS);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2000-08-23 18:28:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static isc_result_t
|
|
|
|
dbiterator_current(dns_dbiterator_t *iterator, dns_dbnode_t **nodep,
|
2020-02-13 14:44:37 -08:00
|
|
|
dns_name_t *name) {
|
2000-08-23 18:28:03 +00:00
|
|
|
sdb_dbiterator_t *sdbiter = (sdb_dbiterator_t *)iterator;
|
|
|
|
|
|
|
|
attachnode(iterator->db, sdbiter->current, nodep);
|
2019-09-10 13:16:48 +02:00
|
|
|
if (name != NULL) {
|
2019-09-10 14:42:41 +02:00
|
|
|
dns_name_copynf(sdbiter->current->name, name);
|
2019-09-10 13:16:48 +02:00
|
|
|
return (ISC_R_SUCCESS);
|
|
|
|
}
|
2000-08-23 18:28:03 +00:00
|
|
|
return (ISC_R_SUCCESS);
|
|
|
|
}
|
|
|
|
|
|
|
|
static isc_result_t
|
2020-02-13 14:44:37 -08:00
|
|
|
dbiterator_pause(dns_dbiterator_t *iterator) {
|
2000-08-23 18:28:03 +00:00
|
|
|
UNUSED(iterator);
|
|
|
|
return (ISC_R_SUCCESS);
|
|
|
|
}
|
|
|
|
|
2000-12-21 01:58:37 +00:00
|
|
|
static isc_result_t
|
2020-02-13 14:44:37 -08:00
|
|
|
dbiterator_origin(dns_dbiterator_t *iterator, dns_name_t *name) {
|
2000-08-23 18:28:03 +00:00
|
|
|
UNUSED(iterator);
|
2019-09-10 14:42:41 +02:00
|
|
|
dns_name_copynf(dns_rootname, name);
|
2019-09-10 13:16:48 +02:00
|
|
|
return (ISC_R_SUCCESS);
|
2000-08-23 18:28:03 +00:00
|
|
|
}
|
|
|
|
|
2000-08-21 22:15:28 +00:00
|
|
|
/*
|
|
|
|
* Rdataset Iterator Methods
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void
|
2020-02-13 14:44:37 -08:00
|
|
|
rdatasetiter_destroy(dns_rdatasetiter_t **iteratorp) {
|
2000-08-21 22:15:28 +00:00
|
|
|
sdb_rdatasetiter_t *sdbiterator = (sdb_rdatasetiter_t *)(*iteratorp);
|
|
|
|
detachnode(sdbiterator->common.db, &sdbiterator->common.node);
|
|
|
|
isc_mem_put(sdbiterator->common.db->mctx, sdbiterator,
|
|
|
|
sizeof(sdb_rdatasetiter_t));
|
|
|
|
*iteratorp = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static isc_result_t
|
2020-02-13 14:44:37 -08:00
|
|
|
rdatasetiter_first(dns_rdatasetiter_t *iterator) {
|
2000-08-21 22:15:28 +00:00
|
|
|
sdb_rdatasetiter_t *sdbiterator = (sdb_rdatasetiter_t *)iterator;
|
2020-02-13 14:44:37 -08:00
|
|
|
dns_sdbnode_t *sdbnode = (dns_sdbnode_t *)iterator->node;
|
2000-08-21 22:15:28 +00:00
|
|
|
|
2020-02-13 21:48:23 +01:00
|
|
|
if (ISC_LIST_EMPTY(sdbnode->lists)) {
|
2000-08-21 22:15:28 +00:00
|
|
|
return (ISC_R_NOMORE);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2000-08-21 22:15:28 +00:00
|
|
|
sdbiterator->current = ISC_LIST_HEAD(sdbnode->lists);
|
|
|
|
return (ISC_R_SUCCESS);
|
|
|
|
}
|
|
|
|
|
|
|
|
static isc_result_t
|
2020-02-13 14:44:37 -08:00
|
|
|
rdatasetiter_next(dns_rdatasetiter_t *iterator) {
|
2000-08-21 22:15:28 +00:00
|
|
|
sdb_rdatasetiter_t *sdbiterator = (sdb_rdatasetiter_t *)iterator;
|
|
|
|
|
|
|
|
sdbiterator->current = ISC_LIST_NEXT(sdbiterator->current, link);
|
2020-02-13 21:48:23 +01:00
|
|
|
if (sdbiterator->current == NULL) {
|
2000-08-21 22:15:28 +00:00
|
|
|
return (ISC_R_NOMORE);
|
2020-02-13 21:48:23 +01:00
|
|
|
} else {
|
2000-08-21 22:15:28 +00:00
|
|
|
return (ISC_R_SUCCESS);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2000-08-21 22:15:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2020-02-13 14:44:37 -08:00
|
|
|
rdatasetiter_current(dns_rdatasetiter_t *iterator, dns_rdataset_t *rdataset) {
|
2000-08-21 22:15:28 +00:00
|
|
|
sdb_rdatasetiter_t *sdbiterator = (sdb_rdatasetiter_t *)iterator;
|
|
|
|
|
|
|
|
list_tordataset(sdbiterator->current, iterator->db, iterator->node,
|
|
|
|
rdataset);
|
|
|
|
}
|