033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington/*
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * Copyright (C) 2000, 2001, 2003-2016 Internet Systems Consortium, Inc. ("ISC")
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington *
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * This Source Code Form is subject to the terms of the Mozilla Public
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * License, v. 2.0. If a copy of the MPL was not distributed with this
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * file, You can obtain one at http://mozilla.org/MPL/2.0/.
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington */
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
28a8f5b0de57d269cf2845c69cb6abe18cbd3b3aMark Andrews/* $Id$ */
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/*! \file */
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington#include <config.h>
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
f4b4e7c16211137332e50bcad3fef0d15639a4f1Brian Wellington#include <string.h>
f4b4e7c16211137332e50bcad3fef0d15639a4f1Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington#include <isc/buffer.h>
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington#include <isc/lex.h>
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington#include <isc/log.h>
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington#include <isc/magic.h>
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington#include <isc/mem.h>
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington#include <isc/once.h>
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington#include <isc/print.h>
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington#include <isc/region.h>
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington#include <isc/util.h>
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
229ce407c359b0b641759ba1fc4a5fa2054a44daBrian Wellington#include <dns/callbacks.h>
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington#include <dns/db.h>
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington#include <dns/dbiterator.h>
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington#include <dns/fixedname.h>
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington#include <dns/log.h>
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington#include <dns/rdata.h>
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington#include <dns/rdatalist.h>
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington#include <dns/rdataset.h>
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington#include <dns/rdatasetiter.h>
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington#include <dns/rdatatype.h>
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington#include <dns/result.h>
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington#include <dns/sdb.h>
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington#include <dns/types.h>
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington#include "rdatalist_p.h"
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
77ac297199fc44809d9628558223627c10ae3f31Brian Wellingtonstruct dns_sdbimplementation {
75e1e12f48012505699f504cfa364260cb2bc1afBrian Wellington const dns_sdbmethods_t *methods;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington void *driverdata;
a4c351fcef77fb332e3cb20253fb96556a414a17Brian Wellington unsigned int flags;
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington isc_mem_t *mctx;
e2fd12f3a020ca8c5de168a44fb72e339cdaa3e9Brian Wellington isc_mutex_t driverlock;
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington dns_dbimplementation_t *dbimp;
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington};
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonstruct dns_sdb {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington /* Unlocked */
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_db_t common;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington char *zone;
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington dns_sdbimplementation_t *implementation;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington void *dbdata;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_mutex_t lock;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington /* Locked */
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington unsigned int references;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington};
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonstruct dns_sdblookup {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington /* Unlocked */
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington unsigned int magic;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_sdb_t *sdb;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington ISC_LIST(dns_rdatalist_t) lists;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington ISC_LIST(isc_buffer_t) buffers;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington dns_name_t *name;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington ISC_LINK(dns_sdblookup_t) link;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_mutex_t lock;
229ce407c359b0b641759ba1fc4a5fa2054a44daBrian Wellington dns_rdatacallbacks_t callbacks;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington /* Locked */
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington unsigned int references;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington};
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellingtontypedef struct dns_sdblookup dns_sdbnode_t;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellingtonstruct dns_sdballnodes {
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington dns_dbiterator_t common;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington ISC_LIST(dns_sdbnode_t) nodelist;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington dns_sdbnode_t *current;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington dns_sdbnode_t *origin;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington};
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellingtontypedef dns_sdballnodes_t sdb_dbiterator_t;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtontypedef struct sdb_rdatasetiter {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_rdatasetiter_t common;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_rdatalist_t *current;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington} sdb_rdatasetiter_t;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
92ef1a9b9dbd48ecb507b42ac62c15afefdaf838David Lawrence#define SDB_MAGIC ISC_MAGIC('S', 'D', 'B', '-')
571688b02f955f6304649866e768b1f81739cbedBrian Wellington
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/*%
571688b02f955f6304649866e768b1f81739cbedBrian Wellington * Note that "impmagic" is not the first four bytes of the struct, so
571688b02f955f6304649866e768b1f81739cbedBrian Wellington * ISC_MAGIC_VALID cannot be used.
571688b02f955f6304649866e768b1f81739cbedBrian Wellington */
571688b02f955f6304649866e768b1f81739cbedBrian Wellington#define VALID_SDB(sdb) ((sdb) != NULL && \
571688b02f955f6304649866e768b1f81739cbedBrian Wellington (sdb)->common.impmagic == SDB_MAGIC)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington#define SDBLOOKUP_MAGIC ISC_MAGIC('S','D','B','L')
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington#define VALID_SDBLOOKUP(sdbl) ISC_MAGIC_VALID(sdbl, SDBLOOKUP_MAGIC)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington#define VALID_SDBNODE(sdbn) VALID_SDBLOOKUP(sdbn)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/* These values are taken from RFC1537 */
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington#define SDB_DEFAULT_REFRESH (60 * 60 * 8)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington#define SDB_DEFAULT_RETRY (60 * 60 * 2)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington#define SDB_DEFAULT_EXPIRE (60 * 60 * 24 * 7)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington#define SDB_DEFAULT_MINIMUM (60 * 60 * 24)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington/* This is a reasonable value */
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington#define SDB_DEFAULT_TTL (60 * 60 * 24)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
557bcc2092642b2d4668c9b08872c9f2bb88bddbMark Andrews#ifdef __COVERITY__
557bcc2092642b2d4668c9b08872c9f2bb88bddbMark Andrews#define MAYBE_LOCK(sdb) LOCK(&sdb->implementation->driverlock)
557bcc2092642b2d4668c9b08872c9f2bb88bddbMark Andrews#define MAYBE_UNLOCK(sdb) UNLOCK(&sdb->implementation->driverlock)
557bcc2092642b2d4668c9b08872c9f2bb88bddbMark Andrews#else
23f64ea0dcd7f5b7094ae6ade2a002fb7dde1466Brian Wellington#define MAYBE_LOCK(sdb) \
23f64ea0dcd7f5b7094ae6ade2a002fb7dde1466Brian Wellington do { \
23f64ea0dcd7f5b7094ae6ade2a002fb7dde1466Brian Wellington unsigned int flags = sdb->implementation->flags; \
23f64ea0dcd7f5b7094ae6ade2a002fb7dde1466Brian Wellington if ((flags & DNS_SDBFLAG_THREADSAFE) == 0) \
e2fd12f3a020ca8c5de168a44fb72e339cdaa3e9Brian Wellington LOCK(&sdb->implementation->driverlock); \
23f64ea0dcd7f5b7094ae6ade2a002fb7dde1466Brian Wellington } while (0)
23f64ea0dcd7f5b7094ae6ade2a002fb7dde1466Brian Wellington
23f64ea0dcd7f5b7094ae6ade2a002fb7dde1466Brian Wellington#define MAYBE_UNLOCK(sdb) \
23f64ea0dcd7f5b7094ae6ade2a002fb7dde1466Brian Wellington do { \
23f64ea0dcd7f5b7094ae6ade2a002fb7dde1466Brian Wellington unsigned int flags = sdb->implementation->flags; \
23f64ea0dcd7f5b7094ae6ade2a002fb7dde1466Brian Wellington if ((flags & DNS_SDBFLAG_THREADSAFE) == 0) \
e2fd12f3a020ca8c5de168a44fb72e339cdaa3e9Brian Wellington UNLOCK(&sdb->implementation->driverlock); \
23f64ea0dcd7f5b7094ae6ade2a002fb7dde1466Brian Wellington } while (0)
557bcc2092642b2d4668c9b08872c9f2bb88bddbMark Andrews#endif
23f64ea0dcd7f5b7094ae6ade2a002fb7dde1466Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonstatic int dummy;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
77ac297199fc44809d9628558223627c10ae3f31Brian Wellingtonstatic isc_result_t dns_sdb_create(isc_mem_t *mctx, dns_name_t *origin,
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington dns_dbtype_t type, dns_rdataclass_t rdclass,
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington unsigned int argc, char *argv[],
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington void *driverarg, dns_db_t **dbp);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonstatic isc_result_t findrdataset(dns_db_t *db, dns_dbnode_t *node,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_dbversion_t *version,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_rdatatype_t type, dns_rdatatype_t covers,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_stdtime_t now, dns_rdataset_t *rdataset,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_rdataset_t *sigrdataset);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellingtonstatic isc_result_t createnode(dns_sdb_t *sdb, dns_sdbnode_t **nodep);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellingtonstatic void destroynode(dns_sdbnode_t *node);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonstatic void detachnode(dns_db_t *db, dns_dbnode_t **targetp);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonstatic void list_tordataset(dns_rdatalist_t *rdatalist,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_db_t *db, dns_dbnode_t *node,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_rdataset_t *rdataset);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellingtonstatic void dbiterator_destroy(dns_dbiterator_t **iteratorp);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellingtonstatic isc_result_t dbiterator_first(dns_dbiterator_t *iterator);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellingtonstatic isc_result_t dbiterator_last(dns_dbiterator_t *iterator);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellingtonstatic isc_result_t dbiterator_seek(dns_dbiterator_t *iterator,
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington dns_name_t *name);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellingtonstatic isc_result_t dbiterator_prev(dns_dbiterator_t *iterator);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellingtonstatic isc_result_t dbiterator_next(dns_dbiterator_t *iterator);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellingtonstatic isc_result_t dbiterator_current(dns_dbiterator_t *iterator,
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington dns_dbnode_t **nodep,
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington dns_name_t *name);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellingtonstatic isc_result_t dbiterator_pause(dns_dbiterator_t *iterator);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellingtonstatic isc_result_t dbiterator_origin(dns_dbiterator_t *iterator,
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington dns_name_t *name);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellingtonstatic dns_dbiteratormethods_t dbiterator_methods = {
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington dbiterator_destroy,
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington dbiterator_first,
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington dbiterator_last,
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington dbiterator_seek,
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington dbiterator_prev,
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington dbiterator_next,
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington dbiterator_current,
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington dbiterator_pause,
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington dbiterator_origin
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington};
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellingtonstatic void rdatasetiter_destroy(dns_rdatasetiter_t **iteratorp);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellingtonstatic isc_result_t rdatasetiter_first(dns_rdatasetiter_t *iterator);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellingtonstatic isc_result_t rdatasetiter_next(dns_rdatasetiter_t *iterator);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellingtonstatic void rdatasetiter_current(dns_rdatasetiter_t *iterator,
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington dns_rdataset_t *rdataset);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonstatic dns_rdatasetitermethods_t rdatasetiter_methods = {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington rdatasetiter_destroy,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington rdatasetiter_first,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington rdatasetiter_next,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington rdatasetiter_current
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington};
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington/*
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * Functions used by implementors of simple databases
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington */
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonisc_result_t
75e1e12f48012505699f504cfa364260cb2bc1afBrian Wellingtondns_sdb_register(const char *drivername, const dns_sdbmethods_t *methods,
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington void *driverdata, unsigned int flags, isc_mem_t *mctx,
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington dns_sdbimplementation_t **sdbimp)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington{
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington dns_sdbimplementation_t *imp;
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington isc_result_t result;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington REQUIRE(drivername != NULL);
75e1e12f48012505699f504cfa364260cb2bc1afBrian Wellington REQUIRE(methods != NULL);
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews REQUIRE(methods->lookup != NULL || methods->lookup2 != NULL);
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington REQUIRE(mctx != NULL);
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington REQUIRE(sdbimp != NULL && *sdbimp == NULL);
23f64ea0dcd7f5b7094ae6ade2a002fb7dde1466Brian Wellington REQUIRE((flags & ~(DNS_SDBFLAG_RELATIVEOWNER |
23f64ea0dcd7f5b7094ae6ade2a002fb7dde1466Brian Wellington DNS_SDBFLAG_RELATIVERDATA |
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews DNS_SDBFLAG_THREADSAFE|
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews DNS_SDBFLAG_DNS64)) == 0);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington imp = isc_mem_get(mctx, sizeof(dns_sdbimplementation_t));
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington if (imp == NULL)
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington return (ISC_R_NOMEMORY);
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington imp->methods = methods;
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington imp->driverdata = driverdata;
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington imp->flags = flags;
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington imp->mctx = NULL;
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington isc_mem_attach(mctx, &imp->mctx);
e2fd12f3a020ca8c5de168a44fb72e339cdaa3e9Brian Wellington result = isc_mutex_init(&imp->driverlock);
18d0b5e54be891a1aa938c165b6d439859121ec8Mark Andrews if (result != ISC_R_SUCCESS)
e2fd12f3a020ca8c5de168a44fb72e339cdaa3e9Brian Wellington goto cleanup_mctx;
e2fd12f3a020ca8c5de168a44fb72e339cdaa3e9Brian Wellington
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington imp->dbimp = NULL;
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington result = dns_db_register(drivername, dns_sdb_create, imp, mctx,
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington &imp->dbimp);
e2fd12f3a020ca8c5de168a44fb72e339cdaa3e9Brian Wellington if (result != ISC_R_SUCCESS)
e2fd12f3a020ca8c5de168a44fb72e339cdaa3e9Brian Wellington goto cleanup_mutex;
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington *sdbimp = imp;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington return (ISC_R_SUCCESS);
e2fd12f3a020ca8c5de168a44fb72e339cdaa3e9Brian Wellington
e2fd12f3a020ca8c5de168a44fb72e339cdaa3e9Brian Wellington cleanup_mutex:
e2fd12f3a020ca8c5de168a44fb72e339cdaa3e9Brian Wellington DESTROYLOCK(&imp->driverlock);
e2fd12f3a020ca8c5de168a44fb72e339cdaa3e9Brian Wellington cleanup_mctx:
e2fd12f3a020ca8c5de168a44fb72e339cdaa3e9Brian Wellington isc_mem_put(mctx, imp, sizeof(dns_sdbimplementation_t));
e2fd12f3a020ca8c5de168a44fb72e339cdaa3e9Brian Wellington return (result);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington}
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonvoid
77ac297199fc44809d9628558223627c10ae3f31Brian Wellingtondns_sdb_unregister(dns_sdbimplementation_t **sdbimp) {
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington dns_sdbimplementation_t *imp;
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington isc_mem_t *mctx;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington REQUIRE(sdbimp != NULL && *sdbimp != NULL);
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington imp = *sdbimp;
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington dns_db_unregister(&imp->dbimp);
e2fd12f3a020ca8c5de168a44fb72e339cdaa3e9Brian Wellington DESTROYLOCK(&imp->driverlock);
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington mctx = imp->mctx;
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington isc_mem_put(mctx, imp, sizeof(dns_sdbimplementation_t));
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington isc_mem_detach(&mctx);
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington *sdbimp = NULL;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington}
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
d2aebe24c477c70e79dc33ea0507e8886eb7d626Brian Wellingtonstatic inline unsigned int
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafssoninitial_size(unsigned int len) {
de32cbd34e78bdd276e69cff239846760d4ee16eBrian Wellington unsigned int size;
6b79e960e6ba2991aeb02a6c39af255ab7f06d99Mark Andrews
6b79e960e6ba2991aeb02a6c39af255ab7f06d99Mark Andrews for (size = 1024; size < (64 * 1024); size *= 2)
d2aebe24c477c70e79dc33ea0507e8886eb7d626Brian Wellington if (len < size)
d2aebe24c477c70e79dc33ea0507e8886eb7d626Brian Wellington return (size);
6b79e960e6ba2991aeb02a6c39af255ab7f06d99Mark Andrews return (65535);
d2aebe24c477c70e79dc33ea0507e8886eb7d626Brian Wellington}
d2aebe24c477c70e79dc33ea0507e8886eb7d626Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonisc_result_t
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrewsdns_sdb_putrdata(dns_sdblookup_t *lookup, dns_rdatatype_t typeval,
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews dns_ttl_t ttl, const unsigned char *rdatap,
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews unsigned int rdlen)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington{
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_rdatalist_t *rdatalist;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_rdata_t *rdata;
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson isc_buffer_t *rdatabuf = NULL;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_result_t result;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_mem_t *mctx;
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson isc_region_t region;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington mctx = lookup->sdb->common.mctx;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington rdatalist = ISC_LIST_HEAD(lookup->lists);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington while (rdatalist != NULL) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (rdatalist->type == typeval)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington break;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington rdatalist = ISC_LIST_NEXT(rdatalist, link);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington }
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (rdatalist == NULL) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington rdatalist = isc_mem_get(mctx, sizeof(dns_rdatalist_t));
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (rdatalist == NULL)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington return (ISC_R_NOMEMORY);
29d52c001ff976561669375cf0c866b815a90c49Mark Andrews dns_rdatalist_init(rdatalist);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington rdatalist->rdclass = lookup->sdb->common.rdclass;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington rdatalist->type = typeval;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington rdatalist->ttl = ttl;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington ISC_LIST_APPEND(lookup->lists, rdatalist, link);
2f012d936b5ccdf6520c96a4de23721dc58a2221Automatic Updater } else
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (rdatalist->ttl != ttl)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington return (DNS_R_BADTTL);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington rdata = isc_mem_get(mctx, sizeof(dns_rdata_t));
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (rdata == NULL)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington return (ISC_R_NOMEMORY);
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson result = isc_buffer_allocate(mctx, &rdatabuf, rdlen);
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson if (result != ISC_R_SUCCESS)
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson goto failure;
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson DE_CONST(rdatap, region.base);
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson region.length = rdlen;
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson isc_buffer_copyregion(rdatabuf, &region);
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson isc_buffer_usedregion(rdatabuf, &region);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_rdata_init(rdata);
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson dns_rdata_fromregion(rdata, rdatalist->rdclass, rdatalist->type,
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson &region);
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson ISC_LIST_APPEND(rdatalist->rdata, rdata, link);
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson ISC_LIST_APPEND(lookup->buffers, rdatabuf, link);
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson rdata = NULL;
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson failure:
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson if (rdata != NULL)
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson isc_mem_put(mctx, rdata, sizeof(dns_rdata_t));
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson return (result);
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson}
2f012d936b5ccdf6520c96a4de23721dc58a2221Automatic Updater
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafssonisc_result_t
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafssondns_sdb_putrr(dns_sdblookup_t *lookup, const char *type, dns_ttl_t ttl,
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson const char *data)
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson{
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson unsigned int datalen;
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson dns_rdatatype_t typeval;
daa73eae708d568d453e6082e0890d35886a9e0fMark Andrews isc_textregion_t r;
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson isc_lex_t *lex = NULL;
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson isc_result_t result;
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson unsigned char *p = NULL;
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson unsigned int size = 0; /* Init to suppress compiler warning */
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson isc_mem_t *mctx;
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson dns_sdbimplementation_t *imp;
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson dns_name_t *origin;
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson isc_buffer_t b;
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson isc_buffer_t rb;
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson REQUIRE(VALID_SDBLOOKUP(lookup));
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson REQUIRE(type != NULL);
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson REQUIRE(data != NULL);
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson mctx = lookup->sdb->common.mctx;
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson
daa73eae708d568d453e6082e0890d35886a9e0fMark Andrews DE_CONST(type, r.base);
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson r.length = strlen(type);
daa73eae708d568d453e6082e0890d35886a9e0fMark Andrews result = dns_rdatatype_fromtext(&typeval, &r);
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson if (result != ISC_R_SUCCESS)
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson return (result);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
a4c351fcef77fb332e3cb20253fb96556a414a17Brian Wellington imp = lookup->sdb->implementation;
a4c351fcef77fb332e3cb20253fb96556a414a17Brian Wellington if ((imp->flags & DNS_SDBFLAG_RELATIVERDATA) != 0)
a4c351fcef77fb332e3cb20253fb96556a414a17Brian Wellington origin = &lookup->sdb->common.origin;
a4c351fcef77fb332e3cb20253fb96556a414a17Brian Wellington else
a4c351fcef77fb332e3cb20253fb96556a414a17Brian Wellington origin = dns_rootname;
a4c351fcef77fb332e3cb20253fb96556a414a17Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington result = isc_lex_create(mctx, 64, &lex);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (result != ISC_R_SUCCESS)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington goto failure;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson datalen = strlen(data);
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson size = initial_size(datalen);
6c7f722d31d12cf83964c8132f0a59ef70e34cb5Mark Andrews do {
6f7abb89ec22aef5eda40ed60fcf605a42b78d4dMark Andrews isc_buffer_constinit(&b, data, datalen);
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson isc_buffer_add(&b, datalen);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington result = isc_lex_openbuffer(lex, &b);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (result != ISC_R_SUCCESS)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington goto failure;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
6b79e960e6ba2991aeb02a6c39af255ab7f06d99Mark Andrews if (size >= 65535)
6b79e960e6ba2991aeb02a6c39af255ab7f06d99Mark Andrews size = 65535;
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson p = isc_mem_get(mctx, size);
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson if (p == NULL) {
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson result = ISC_R_NOMEMORY;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington goto failure;
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson }
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson isc_buffer_init(&rb, p, size);
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson result = dns_rdata_fromtext(NULL,
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson lookup->sdb->common.rdclass,
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson typeval, lex,
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews origin, 0,
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson mctx, &rb,
229ce407c359b0b641759ba1fc4a5fa2054a44daBrian Wellington &lookup->callbacks);
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson if (result != ISC_R_NOSPACE)
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson break;
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson
6b79e960e6ba2991aeb02a6c39af255ab7f06d99Mark Andrews /*
6b79e960e6ba2991aeb02a6c39af255ab7f06d99Mark Andrews * Is the RR too big?
6b79e960e6ba2991aeb02a6c39af255ab7f06d99Mark Andrews */
6b79e960e6ba2991aeb02a6c39af255ab7f06d99Mark Andrews if (size >= 65535)
6b79e960e6ba2991aeb02a6c39af255ab7f06d99Mark Andrews break;
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson isc_mem_put(mctx, p, size);
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson p = NULL;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington size *= 2;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington } while (result == ISC_R_NOSPACE);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (result != ISC_R_SUCCESS)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington goto failure;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson result = dns_sdb_putrdata(lookup, typeval, ttl,
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson isc_buffer_base(&rb),
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson isc_buffer_usedlength(&rb));
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington failure:
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson if (p != NULL)
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson isc_mem_put(mctx, p, size);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (lex != NULL)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_lex_destroy(&lex);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington return (result);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington}
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafssonstatic isc_result_t
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafssongetnode(dns_sdballnodes_t *allnodes, const char *name, dns_sdbnode_t **nodep) {
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington dns_name_t *newname, *origin;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington dns_fixedname_t fnewname;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington dns_sdb_t *sdb = (dns_sdb_t *)allnodes->common.db;
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington dns_sdbimplementation_t *imp = sdb->implementation;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington dns_sdbnode_t *sdbnode;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington isc_mem_t *mctx = sdb->common.mctx;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington isc_buffer_t b;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington isc_result_t result;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington dns_fixedname_init(&fnewname);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington newname = dns_fixedname_name(&fnewname);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington if ((imp->flags & DNS_SDBFLAG_RELATIVERDATA) != 0)
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington origin = &sdb->common.origin;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington else
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington origin = dns_rootname;
6f7abb89ec22aef5eda40ed60fcf605a42b78d4dMark Andrews isc_buffer_constinit(&b, name, strlen(name));
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington isc_buffer_add(&b, strlen(name));
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 result = dns_name_fromtext(newname, &b, origin, 0, NULL);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington if (result != ISC_R_SUCCESS)
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington return (result);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington if (allnodes->common.relative_names) {
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington /* All names are relative to the root */
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington unsigned int nlabels = dns_name_countlabels(newname);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington dns_name_getlabelsequence(newname, 0, nlabels - 1, newname);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington }
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington sdbnode = ISC_LIST_HEAD(allnodes->nodelist);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington if (sdbnode == NULL || !dns_name_equal(sdbnode->name, newname)) {
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington sdbnode = NULL;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington result = createnode(sdb, &sdbnode);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington if (result != ISC_R_SUCCESS)
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington return (result);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington sdbnode->name = isc_mem_get(mctx, sizeof(dns_name_t));
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington if (sdbnode->name == NULL) {
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington destroynode(sdbnode);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington return (ISC_R_NOMEMORY);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington }
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington dns_name_init(sdbnode->name, NULL);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington result = dns_name_dup(newname, mctx, sdbnode->name);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington if (result != ISC_R_SUCCESS) {
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington isc_mem_put(mctx, sdbnode->name, sizeof(dns_name_t));
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington destroynode(sdbnode);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington return (result);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington }
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington ISC_LIST_PREPEND(allnodes->nodelist, sdbnode, link);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington if (allnodes->origin == NULL &&
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington dns_name_equal(newname, &sdb->common.origin))
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington allnodes->origin = sdbnode;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington }
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson *nodep = sdbnode;
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson return (ISC_R_SUCCESS);
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson}
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafssonisc_result_t
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafssondns_sdb_putnamedrr(dns_sdballnodes_t *allnodes, const char *name,
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson const char *type, dns_ttl_t ttl, const char *data)
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson{
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson isc_result_t result;
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson dns_sdbnode_t *sdbnode = NULL;
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson result = getnode(allnodes, name, &sdbnode);
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson if (result != ISC_R_SUCCESS)
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson return (result);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington return (dns_sdb_putrr(sdbnode, type, ttl, data));
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson}
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafssonisc_result_t
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafssondns_sdb_putnamedrdata(dns_sdballnodes_t *allnodes, const char *name,
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson dns_rdatatype_t type, dns_ttl_t ttl,
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson const void *rdata, unsigned int rdlen)
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson{
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson isc_result_t result;
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson dns_sdbnode_t *sdbnode = NULL;
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson result = getnode(allnodes, name, &sdbnode);
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson if (result != ISC_R_SUCCESS)
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson return (result);
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson return (dns_sdb_putrdata(sdbnode, type, ttl, rdata, rdlen));
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington}
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonisc_result_t
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtondns_sdb_putsoa(dns_sdblookup_t *lookup, const char *mname, const char *rname,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_uint32_t serial)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington{
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington char str[2 * DNS_NAME_MAXTEXT + 5 * (sizeof("2147483647")) + 7];
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington int n;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington REQUIRE(mname != NULL);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington REQUIRE(rname != NULL);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
f3ca27e9fe307b55e35ea8d7b37351650630e5a3Andreas Gustafsson n = snprintf(str, sizeof(str), "%s %s %u %u %u %u %u",
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington mname, rname, serial,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington SDB_DEFAULT_REFRESH, SDB_DEFAULT_RETRY,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington SDB_DEFAULT_EXPIRE, SDB_DEFAULT_MINIMUM);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (n >= (int)sizeof(str) || n < 0)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington return (ISC_R_NOSPACE);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington return (dns_sdb_putrr(lookup, "SOA", SDB_DEFAULT_TTL, str));
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington}
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington/*
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * DB routines
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington */
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonstatic void
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonattach(dns_db_t *source, dns_db_t **targetp) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_sdb_t *sdb = (dns_sdb_t *) source;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington REQUIRE(VALID_SDB(sdb));
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington LOCK(&sdb->lock);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington REQUIRE(sdb->references > 0);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington sdb->references++;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington UNLOCK(&sdb->lock);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington *targetp = source;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington}
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonstatic void
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtondestroy(dns_sdb_t *sdb) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_mem_t *mctx;
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington dns_sdbimplementation_t *imp = sdb->implementation;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington mctx = sdb->common.mctx;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
e2fd12f3a020ca8c5de168a44fb72e339cdaa3e9Brian Wellington if (imp->methods->destroy != NULL) {
e2fd12f3a020ca8c5de168a44fb72e339cdaa3e9Brian Wellington MAYBE_LOCK(sdb);
75e1e12f48012505699f504cfa364260cb2bc1afBrian Wellington imp->methods->destroy(sdb->zone, imp->driverdata,
75e1e12f48012505699f504cfa364260cb2bc1afBrian Wellington &sdb->dbdata);
e2fd12f3a020ca8c5de168a44fb72e339cdaa3e9Brian Wellington MAYBE_UNLOCK(sdb);
e2fd12f3a020ca8c5de168a44fb72e339cdaa3e9Brian Wellington }
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_mem_free(mctx, sdb->zone);
5e387b9ce6bafdfadedb5b34e4c33a4404e5d589Brian Wellington DESTROYLOCK(&sdb->lock);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington sdb->common.magic = 0;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington sdb->common.impmagic = 0;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_name_free(&sdb->common.origin, mctx);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_mem_put(mctx, sdb, sizeof(dns_sdb_t));
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_mem_detach(&mctx);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington}
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonstatic void
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtondetach(dns_db_t **dbp) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_sdb_t *sdb = (dns_sdb_t *)(*dbp);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_boolean_t need_destroy = ISC_FALSE;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington REQUIRE(VALID_SDB(sdb));
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington LOCK(&sdb->lock);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington REQUIRE(sdb->references > 0);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington sdb->references--;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (sdb->references == 0)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington need_destroy = ISC_TRUE;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington UNLOCK(&sdb->lock);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (need_destroy)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington destroy(sdb);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington *dbp = NULL;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington}
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonstatic isc_result_t
7829fad4093f2c1985b1efb7cea00287ff015d2bckbbeginload(dns_db_t *db, dns_rdatacallbacks_t *callbacks) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington UNUSED(db);
7829fad4093f2c1985b1efb7cea00287ff015d2bckb UNUSED(callbacks);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington return (ISC_R_NOTIMPLEMENTED);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington}
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonstatic isc_result_t
7829fad4093f2c1985b1efb7cea00287ff015d2bckbendload(dns_db_t *db, dns_rdatacallbacks_t *callbacks) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington UNUSED(db);
7829fad4093f2c1985b1efb7cea00287ff015d2bckb UNUSED(callbacks);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington return (ISC_R_NOTIMPLEMENTED);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington}
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonstatic isc_result_t
a903095bf4512dae561c7f6fc7854a51bebf334aMark Andrewsdump(dns_db_t *db, dns_dbversion_t *version, const char *filename,
a903095bf4512dae561c7f6fc7854a51bebf334aMark Andrews dns_masterformat_t masterformat) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington UNUSED(db);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington UNUSED(version);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington UNUSED(filename);
a903095bf4512dae561c7f6fc7854a51bebf334aMark Andrews UNUSED(masterformat);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington return (ISC_R_NOTIMPLEMENTED);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington}
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonstatic void
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtoncurrentversion(dns_db_t *db, dns_dbversion_t **versionp) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington REQUIRE(versionp != NULL && *versionp == NULL);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington UNUSED(db);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington *versionp = (void *) &dummy;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington return;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington}
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonstatic isc_result_t
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonnewversion(dns_db_t *db, dns_dbversion_t **versionp) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington UNUSED(db);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington UNUSED(versionp);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington return (ISC_R_NOTIMPLEMENTED);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington}
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonstatic void
2f012d936b5ccdf6520c96a4de23721dc58a2221Automatic Updaterattachversion(dns_db_t *db, dns_dbversion_t *source,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_dbversion_t **targetp)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington{
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington REQUIRE(source != NULL && source == (void *) &dummy);
c0d2891f6e08fcf5379dfb9a1bf8fbbb63f1952aMark Andrews REQUIRE(targetp != NULL && *targetp == NULL);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington UNUSED(db);
c0d2891f6e08fcf5379dfb9a1bf8fbbb63f1952aMark Andrews *targetp = source;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington return;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington}
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonstatic void
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtoncloseversion(dns_db_t *db, dns_dbversion_t **versionp, isc_boolean_t commit) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington REQUIRE(versionp != NULL && *versionp == (void *) &dummy);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington REQUIRE(commit == ISC_FALSE);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington UNUSED(db);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington UNUSED(commit);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington *versionp = NULL;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington}
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonstatic isc_result_t
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtoncreatenode(dns_sdb_t *sdb, dns_sdbnode_t **nodep) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_sdbnode_t *node;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_result_t result;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington node = isc_mem_get(sdb->common.mctx, sizeof(dns_sdbnode_t));
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (node == NULL)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington return (ISC_R_NOMEMORY);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington node->sdb = NULL;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington attach((dns_db_t *)sdb, (dns_db_t **)&node->sdb);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington ISC_LIST_INIT(node->lists);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington ISC_LIST_INIT(node->buffers);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington ISC_LINK_INIT(node, link);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington node->name = NULL;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington result = isc_mutex_init(&node->lock);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (result != ISC_R_SUCCESS) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_mem_put(sdb->common.mctx, node, sizeof(dns_sdbnode_t));
18d0b5e54be891a1aa938c165b6d439859121ec8Mark Andrews return (result);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington }
229ce407c359b0b641759ba1fc4a5fa2054a44daBrian Wellington dns_rdatacallbacks_init(&node->callbacks);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington node->references = 1;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington node->magic = SDBLOOKUP_MAGIC;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington *nodep = node;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington return (ISC_R_SUCCESS);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington}
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonstatic void
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtondestroynode(dns_sdbnode_t *node) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_rdatalist_t *list;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_rdata_t *rdata;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_buffer_t *b;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_sdb_t *sdb;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington isc_mem_t *mctx;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington sdb = node->sdb;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington mctx = sdb->common.mctx;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington while (!ISC_LIST_EMPTY(node->lists)) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington list = ISC_LIST_HEAD(node->lists);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington while (!ISC_LIST_EMPTY(list->rdata)) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington rdata = ISC_LIST_HEAD(list->rdata);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington ISC_LIST_UNLINK(list->rdata, rdata, link);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington isc_mem_put(mctx, rdata, sizeof(dns_rdata_t));
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington }
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington ISC_LIST_UNLINK(node->lists, list, link);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington isc_mem_put(mctx, list, sizeof(dns_rdatalist_t));
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington }
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington while (!ISC_LIST_EMPTY(node->buffers)) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington b = ISC_LIST_HEAD(node->buffers);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington ISC_LIST_UNLINK(node->buffers, b, link);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_buffer_free(&b);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington }
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington if (node->name != NULL) {
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington dns_name_free(node->name, mctx);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington isc_mem_put(mctx, node->name, sizeof(dns_name_t));
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington }
5e387b9ce6bafdfadedb5b34e4c33a4404e5d589Brian Wellington DESTROYLOCK(&node->lock);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington node->magic = 0;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington isc_mem_put(mctx, node, sizeof(dns_sdbnode_t));
daa73eae708d568d453e6082e0890d35886a9e0fMark Andrews detach((dns_db_t **) (void *)&sdb);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington}
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonstatic isc_result_t
793814f80703afdd69b59ade91e63efa81ae4178Evan Huntfindnodeext(dns_db_t *db, dns_name_t *name, isc_boolean_t create,
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt dns_clientinfomethods_t *methods, dns_clientinfo_t *clientinfo,
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt dns_dbnode_t **nodep)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington{
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_sdb_t *sdb = (dns_sdb_t *)db;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_sdbnode_t *node = NULL;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_result_t result;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_buffer_t b;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington char namestr[DNS_NAME_MAXTEXT + 1];
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_boolean_t isorigin;
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington dns_sdbimplementation_t *imp;
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews dns_name_t relname;
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews unsigned int labels;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington REQUIRE(VALID_SDB(sdb));
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington REQUIRE(create == ISC_FALSE);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington REQUIRE(nodep != NULL && *nodep == NULL);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington UNUSED(name);
7a6f285bc933d08353d2f18290c85def575b6e57Andreas Gustafsson UNUSED(create);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
a4c351fcef77fb332e3cb20253fb96556a414a17Brian Wellington imp = sdb->implementation;
a4c351fcef77fb332e3cb20253fb96556a414a17Brian Wellington
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews isorigin = dns_name_equal(name, &sdb->common.origin);
a4c351fcef77fb332e3cb20253fb96556a414a17Brian Wellington
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews if (imp->methods->lookup2 != NULL) {
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews if ((imp->flags & DNS_SDBFLAG_RELATIVEOWNER) != 0) {
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews labels = dns_name_countlabels(name) -
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews dns_name_countlabels(&db->origin);
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews dns_name_init(&relname, NULL);
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews dns_name_getlabelsequence(name, 0, labels, &relname);
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews name = &relname;
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews }
a4c351fcef77fb332e3cb20253fb96556a414a17Brian Wellington } else {
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews isc_buffer_init(&b, namestr, sizeof(namestr));
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews if ((imp->flags & DNS_SDBFLAG_RELATIVEOWNER) != 0) {
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews labels = dns_name_countlabels(name) -
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews dns_name_countlabels(&db->origin);
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews dns_name_init(&relname, NULL);
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews dns_name_getlabelsequence(name, 0, labels, &relname);
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews result = dns_name_totext(&relname, ISC_TRUE, &b);
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews if (result != ISC_R_SUCCESS)
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews return (result);
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews } else {
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews result = dns_name_totext(name, ISC_TRUE, &b);
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews if (result != ISC_R_SUCCESS)
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews return (result);
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews }
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews isc_buffer_putuint8(&b, 0);
a4c351fcef77fb332e3cb20253fb96556a414a17Brian Wellington }
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington result = createnode(sdb, &node);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (result != ISC_R_SUCCESS)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington return (result);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
23f64ea0dcd7f5b7094ae6ade2a002fb7dde1466Brian Wellington MAYBE_LOCK(sdb);
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews if (imp->methods->lookup2 != NULL)
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews result = imp->methods->lookup2(&sdb->common.origin, name,
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews sdb->dbdata, node, methods,
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews clientinfo);
3fb95bfcb2e478d721d378f0be5ff0a32269bc2aTinderbox User else
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews result = imp->methods->lookup(sdb->zone, namestr, sdb->dbdata,
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews node, methods, clientinfo);
23f64ea0dcd7f5b7094ae6ade2a002fb7dde1466Brian Wellington MAYBE_UNLOCK(sdb);
6e93e6ea4557291e847aced6a88adcdf39f06843Andreas Gustafsson if (result != ISC_R_SUCCESS &&
6e93e6ea4557291e847aced6a88adcdf39f06843Andreas Gustafsson !(result == ISC_R_NOTFOUND &&
6e93e6ea4557291e847aced6a88adcdf39f06843Andreas Gustafsson isorigin && imp->methods->authority != NULL))
6e93e6ea4557291e847aced6a88adcdf39f06843Andreas Gustafsson {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington destroynode(node);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington return (result);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington }
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
75e1e12f48012505699f504cfa364260cb2bc1afBrian Wellington if (isorigin && imp->methods->authority != NULL) {
23f64ea0dcd7f5b7094ae6ade2a002fb7dde1466Brian Wellington MAYBE_LOCK(sdb);
75e1e12f48012505699f504cfa364260cb2bc1afBrian Wellington result = imp->methods->authority(sdb->zone, sdb->dbdata, node);
23f64ea0dcd7f5b7094ae6ade2a002fb7dde1466Brian Wellington MAYBE_UNLOCK(sdb);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (result != ISC_R_SUCCESS) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington destroynode(node);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington return (result);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington }
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington }
2f012d936b5ccdf6520c96a4de23721dc58a2221Automatic Updater
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington *nodep = node;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington return (ISC_R_SUCCESS);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington}
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonstatic isc_result_t
793814f80703afdd69b59ade91e63efa81ae4178Evan Huntfindext(dns_db_t *db, dns_name_t *name, dns_dbversion_t *version,
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt dns_rdatatype_t type, unsigned int options, isc_stdtime_t now,
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt dns_dbnode_t **nodep, dns_name_t *foundname,
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt dns_clientinfomethods_t *methods, dns_clientinfo_t *clientinfo,
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt dns_rdataset_t *rdataset, dns_rdataset_t *sigrdataset)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington{
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_sdb_t *sdb = (dns_sdb_t *)db;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_dbnode_t *node = NULL;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_fixedname_t fname;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_rdataset_t xrdataset;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_name_t *xname;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington unsigned int nlabels, olabels;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_result_t result;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington unsigned int i;
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews unsigned int flags;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington REQUIRE(VALID_SDB(sdb));
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington REQUIRE(nodep == NULL || *nodep == NULL);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington REQUIRE(version == NULL || version == (void *) &dummy);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington UNUSED(options);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (!dns_name_issubdomain(name, &db->origin))
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington return (DNS_R_NXDOMAIN);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington olabels = dns_name_countlabels(&db->origin);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington nlabels = dns_name_countlabels(name);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_fixedname_init(&fname);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington xname = dns_fixedname_name(&fname);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
fefe1106d96d3a89b21315f665b36a67cdea3840Mark Andrews if (rdataset == NULL) {
fefe1106d96d3a89b21315f665b36a67cdea3840Mark Andrews dns_rdataset_init(&xrdataset);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington rdataset = &xrdataset;
fefe1106d96d3a89b21315f665b36a67cdea3840Mark Andrews }
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington result = DNS_R_NXDOMAIN;
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews flags = sdb->implementation->flags;
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews i = (flags & DNS_SDBFLAG_DNS64) != 0 ? nlabels : olabels;
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews for (; i <= nlabels; i++) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington /*
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * Look up the next label.
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington */
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_name_getlabelsequence(name, nlabels - i, i, xname);
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt result = findnodeext(db, xname, ISC_FALSE, methods,
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt clientinfo, &node);
85fcd0b9b2d80be4646187d7094e5644a52e3263Mark Andrews if (result == ISC_R_NOTFOUND) {
85fcd0b9b2d80be4646187d7094e5644a52e3263Mark Andrews /*
85fcd0b9b2d80be4646187d7094e5644a52e3263Mark Andrews * No data at zone apex?
85fcd0b9b2d80be4646187d7094e5644a52e3263Mark Andrews */
85fcd0b9b2d80be4646187d7094e5644a52e3263Mark Andrews if (i == olabels)
85fcd0b9b2d80be4646187d7094e5644a52e3263Mark Andrews return (DNS_R_BADDB);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington result = DNS_R_NXDOMAIN;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington continue;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington }
85fcd0b9b2d80be4646187d7094e5644a52e3263Mark Andrews if (result != ISC_R_SUCCESS)
85fcd0b9b2d80be4646187d7094e5644a52e3263Mark Andrews return (result);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews /*
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews * DNS64 zone's don't have DNAME or NS records.
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews */
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews if ((flags & DNS_SDBFLAG_DNS64) != 0)
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews goto skip;
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews /*
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews * DNS64 zone's don't have DNAME or NS records.
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews */
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews if ((flags & DNS_SDBFLAG_DNS64) != 0)
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews goto skip;
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington /*
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * Look for a DNAME at the current label, unless this is
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * the qname.
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington */
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (i < nlabels) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington result = findrdataset(db, node, version,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_rdatatype_dname,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington 0, now, rdataset, sigrdataset);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (result == ISC_R_SUCCESS) {
c302b021cc65cc9a358a9a1cbe48de12364f4cb6Brian Wellington result = DNS_R_DNAME;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington break;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington }
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington }
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington /*
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * Look for an NS at the current label, unless this is the
0a45f098e446a7f41c2a71d9dd0fd8f459b49c34Brian Wellington * origin or glue is ok.
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington */
0a45f098e446a7f41c2a71d9dd0fd8f459b49c34Brian Wellington if (i != olabels && (options & DNS_DBFIND_GLUEOK) == 0) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington result = findrdataset(db, node, version,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_rdatatype_ns,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington 0, now, rdataset, sigrdataset);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (result == ISC_R_SUCCESS) {
c302b021cc65cc9a358a9a1cbe48de12364f4cb6Brian Wellington if (i == nlabels && type == dns_rdatatype_any)
c302b021cc65cc9a358a9a1cbe48de12364f4cb6Brian Wellington {
c302b021cc65cc9a358a9a1cbe48de12364f4cb6Brian Wellington result = DNS_R_ZONECUT;
c302b021cc65cc9a358a9a1cbe48de12364f4cb6Brian Wellington dns_rdataset_disassociate(rdataset);
b1b0dca1464a11b8a63623e8567e744dccfbcb41Tatuya JINMEI 神明達哉 if (sigrdataset != NULL &&
b1b0dca1464a11b8a63623e8567e744dccfbcb41Tatuya JINMEI 神明達哉 dns_rdataset_isassociated
ab381c1e22e0ed732170428937d20d13146d863aAutomatic Updater (sigrdataset)) {
c302b021cc65cc9a358a9a1cbe48de12364f4cb6Brian Wellington dns_rdataset_disassociate
c302b021cc65cc9a358a9a1cbe48de12364f4cb6Brian Wellington (sigrdataset);
b1b0dca1464a11b8a63623e8567e744dccfbcb41Tatuya JINMEI 神明達哉 }
c302b021cc65cc9a358a9a1cbe48de12364f4cb6Brian Wellington } else
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington result = DNS_R_DELEGATION;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington break;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington }
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington }
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington /*
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * If the current name is not the qname, add another label
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * and try again.
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington */
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (i < nlabels) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington destroynode(node);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington node = NULL;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington continue;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington }
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews skip:
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington /*
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * If we're looking for ANY, we're done.
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington */
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (type == dns_rdatatype_any) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington result = ISC_R_SUCCESS;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington break;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington }
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington /*
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * Look for the qtype.
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington */
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington result = findrdataset(db, node, version, type,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington 0, now, rdataset, sigrdataset);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (result == ISC_R_SUCCESS)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington break;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington /*
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * Look for a CNAME
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington */
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (type != dns_rdatatype_cname) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington result = findrdataset(db, node, version,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_rdatatype_cname,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington 0, now, rdataset, sigrdataset);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (result == ISC_R_SUCCESS) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington result = DNS_R_CNAME;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington break;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington }
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington }
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington result = DNS_R_NXRRSET;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington break;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington }
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (rdataset == &xrdataset && dns_rdataset_isassociated(rdataset))
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_rdataset_disassociate(rdataset);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (foundname != NULL) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_result_t xresult;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
b7cd261f2fca2c7138cdc6ae8ee434e9c0031303Brian Wellington xresult = dns_name_copy(xname, foundname, NULL);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (xresult != ISC_R_SUCCESS) {
cfcb0881d12db2b7cb33475b7d20ac6c9015203bMark Andrews if (node != NULL)
cfcb0881d12db2b7cb33475b7d20ac6c9015203bMark Andrews destroynode(node);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (dns_rdataset_isassociated(rdataset))
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_rdataset_disassociate(rdataset);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington return (DNS_R_BADDB);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington }
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington }
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (nodep != NULL)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington *nodep = node;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington else if (node != NULL)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington detachnode(db, &node);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington return (result);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington}
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonstatic isc_result_t
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonfindzonecut(dns_db_t *db, dns_name_t *name, unsigned int options,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_stdtime_t now, dns_dbnode_t **nodep, dns_name_t *foundname,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_rdataset_t *rdataset, dns_rdataset_t *sigrdataset)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington{
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington UNUSED(db);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington UNUSED(name);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington UNUSED(options);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington UNUSED(now);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington UNUSED(nodep);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington UNUSED(foundname);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington UNUSED(rdataset);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington UNUSED(sigrdataset);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington return (ISC_R_NOTIMPLEMENTED);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington}
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonstatic void
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonattachnode(dns_db_t *db, dns_dbnode_t *source, dns_dbnode_t **targetp) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_sdb_t *sdb = (dns_sdb_t *)db;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_sdbnode_t *node = (dns_sdbnode_t *)source;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington REQUIRE(VALID_SDB(sdb));
7a6f285bc933d08353d2f18290c85def575b6e57Andreas Gustafsson
7a6f285bc933d08353d2f18290c85def575b6e57Andreas Gustafsson UNUSED(sdb);
7a6f285bc933d08353d2f18290c85def575b6e57Andreas Gustafsson
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington LOCK(&node->lock);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington INSIST(node->references > 0);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington node->references++;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington INSIST(node->references != 0); /* Catch overflow. */
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington UNLOCK(&node->lock);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington *targetp = source;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington}
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonstatic void
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtondetachnode(dns_db_t *db, dns_dbnode_t **targetp) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_sdb_t *sdb = (dns_sdb_t *)db;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_sdbnode_t *node;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_boolean_t need_destroy = ISC_FALSE;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington REQUIRE(VALID_SDB(sdb));
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington REQUIRE(targetp != NULL && *targetp != NULL);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
7a6f285bc933d08353d2f18290c85def575b6e57Andreas Gustafsson UNUSED(sdb);
7a6f285bc933d08353d2f18290c85def575b6e57Andreas Gustafsson
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington node = (dns_sdbnode_t *)(*targetp);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington LOCK(&node->lock);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington INSIST(node->references > 0);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington node->references--;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (node->references == 0)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington need_destroy = ISC_TRUE;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington UNLOCK(&node->lock);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (need_destroy)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington destroynode(node);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington *targetp = NULL;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington}
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonstatic isc_result_t
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonexpirenode(dns_db_t *db, dns_dbnode_t *node, isc_stdtime_t now) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington UNUSED(db);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington UNUSED(node);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington UNUSED(now);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington INSIST(0);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington return (ISC_R_UNEXPECTED);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington}
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonstatic void
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonprintnode(dns_db_t *db, dns_dbnode_t *node, FILE *out) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington UNUSED(db);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington UNUSED(node);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington UNUSED(out);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington return;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington}
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonstatic isc_result_t
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrewscreateiterator(dns_db_t *db, unsigned int options, dns_dbiterator_t **iteratorp)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington{
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington dns_sdb_t *sdb = (dns_sdb_t *)db;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington sdb_dbiterator_t *sdbiter;
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington dns_sdbimplementation_t *imp = sdb->implementation;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington isc_result_t result;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington REQUIRE(VALID_SDB(sdb));
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington if (imp->methods->allnodes == NULL)
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington return (ISC_R_NOTIMPLEMENTED);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews if ((options & DNS_DB_NSEC3ONLY) != 0 ||
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews (options & DNS_DB_NONSEC3) != 0)
6e2871232f7ede047799480370aff444be1f5a13Automatic Updater return (ISC_R_NOTIMPLEMENTED);
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington sdbiter = isc_mem_get(sdb->common.mctx, sizeof(sdb_dbiterator_t));
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington if (sdbiter == NULL)
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington return (ISC_R_NOMEMORY);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington sdbiter->common.methods = &dbiterator_methods;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington sdbiter->common.db = NULL;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington dns_db_attach(db, &sdbiter->common.db);
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews sdbiter->common.relative_names = ISC_TF(options & DNS_DB_RELATIVENAMES);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington sdbiter->common.magic = DNS_DBITERATOR_MAGIC;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington ISC_LIST_INIT(sdbiter->nodelist);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington sdbiter->current = NULL;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington sdbiter->origin = NULL;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington
23f64ea0dcd7f5b7094ae6ade2a002fb7dde1466Brian Wellington MAYBE_LOCK(sdb);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington result = imp->methods->allnodes(sdb->zone, sdb->dbdata, sdbiter);
23f64ea0dcd7f5b7094ae6ade2a002fb7dde1466Brian Wellington MAYBE_UNLOCK(sdb);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington if (result != ISC_R_SUCCESS) {
daa73eae708d568d453e6082e0890d35886a9e0fMark Andrews dbiterator_destroy((dns_dbiterator_t **) (void *)&sdbiter);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington return (result);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington }
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington if (sdbiter->origin != NULL) {
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington ISC_LIST_UNLINK(sdbiter->nodelist, sdbiter->origin, link);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington ISC_LIST_PREPEND(sdbiter->nodelist, sdbiter->origin, link);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington }
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington *iteratorp = (dns_dbiterator_t *)sdbiter;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington return (ISC_R_SUCCESS);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington}
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonstatic isc_result_t
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonfindrdataset(dns_db_t *db, dns_dbnode_t *node, dns_dbversion_t *version,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_rdatatype_t type, dns_rdatatype_t covers,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_stdtime_t now, dns_rdataset_t *rdataset,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_rdataset_t *sigrdataset)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington{
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_rdatalist_t *list;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_sdbnode_t *sdbnode = (dns_sdbnode_t *)node;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington REQUIRE(VALID_SDBNODE(node));
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington UNUSED(db);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington UNUSED(version);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington UNUSED(covers);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington UNUSED(now);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington UNUSED(sigrdataset);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
93d6dfaf66258337985427c86181f01fc51f0bb4Mark Andrews if (type == dns_rdatatype_rrsig)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington return (ISC_R_NOTIMPLEMENTED);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington list = ISC_LIST_HEAD(sdbnode->lists);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington while (list != NULL) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (list->type == type)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington break;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington list = ISC_LIST_NEXT(list, link);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington }
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (list == NULL)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington return (ISC_R_NOTFOUND);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington list_tordataset(list, db, node, rdataset);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington return (ISC_R_SUCCESS);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington}
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonstatic isc_result_t
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonallrdatasets(dns_db_t *db, dns_dbnode_t *node, dns_dbversion_t *version,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_stdtime_t now, dns_rdatasetiter_t **iteratorp)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington{
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington sdb_rdatasetiter_t *iterator;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington REQUIRE(version == NULL || version == &dummy);
2f012d936b5ccdf6520c96a4de23721dc58a2221Automatic Updater
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington UNUSED(version);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington UNUSED(now);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington iterator = isc_mem_get(db->mctx, sizeof(sdb_rdatasetiter_t));
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (iterator == NULL)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington return (ISC_R_NOMEMORY);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington iterator->common.magic = DNS_RDATASETITER_MAGIC;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington iterator->common.methods = &rdatasetiter_methods;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington iterator->common.db = db;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington iterator->common.node = NULL;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington attachnode(db, node, &iterator->common.node);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington iterator->common.version = version;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington iterator->common.now = now;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington *iteratorp = (dns_rdatasetiter_t *)iterator;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington return (ISC_R_SUCCESS);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington}
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonstatic isc_result_t
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonaddrdataset(dns_db_t *db, dns_dbnode_t *node, dns_dbversion_t *version,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_stdtime_t now, dns_rdataset_t *rdataset, unsigned int options,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_rdataset_t *addedrdataset)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington{
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington UNUSED(db);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington UNUSED(node);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington UNUSED(version);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington UNUSED(now);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington UNUSED(rdataset);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington UNUSED(options);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington UNUSED(addedrdataset);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington return (ISC_R_NOTIMPLEMENTED);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington}
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonstatic isc_result_t
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonsubtractrdataset(dns_db_t *db, dns_dbnode_t *node, dns_dbversion_t *version,
f8abaa0fae7f75d9601c10b6a4af8dd907494d45Mark Andrews dns_rdataset_t *rdataset, unsigned int options,
b55c30f2de6e1baaa3a9ba69b92f428f2c255ac3Mark Andrews dns_rdataset_t *newrdataset)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington{
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington UNUSED(db);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington UNUSED(node);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington UNUSED(version);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington UNUSED(rdataset);
f8abaa0fae7f75d9601c10b6a4af8dd907494d45Mark Andrews UNUSED(options);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington UNUSED(newrdataset);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington return (ISC_R_NOTIMPLEMENTED);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington}
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonstatic isc_result_t
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtondeleterdataset(dns_db_t *db, dns_dbnode_t *node, dns_dbversion_t *version,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_rdatatype_t type, dns_rdatatype_t covers)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington{
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington UNUSED(db);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington UNUSED(node);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington UNUSED(version);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington UNUSED(type);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington UNUSED(covers);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington return (ISC_R_NOTIMPLEMENTED);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington}
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonstatic isc_boolean_t
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonissecure(dns_db_t *db) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington UNUSED(db);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington return (ISC_FALSE);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington}
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonstatic unsigned int
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonnodecount(dns_db_t *db) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington UNUSED(db);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington return (0);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington}
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonstatic isc_boolean_t
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonispersistent(dns_db_t *db) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington UNUSED(db);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington return (ISC_TRUE);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington}
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
4a30ede93d59137009db734661cde17612e8ffbeMark Andrewsstatic void
af669cb4fd7ecfb67ed145b176e5e764b249573bMark Andrewsovermem(dns_db_t *db, isc_boolean_t over) {
4a30ede93d59137009db734661cde17612e8ffbeMark Andrews UNUSED(db);
af669cb4fd7ecfb67ed145b176e5e764b249573bMark Andrews UNUSED(over);
4a30ede93d59137009db734661cde17612e8ffbeMark Andrews}
4a30ede93d59137009db734661cde17612e8ffbeMark Andrews
a03848252fa85734ca75beae3d0b01bb503c0a8bMark Andrewsstatic void
a03848252fa85734ca75beae3d0b01bb503c0a8bMark Andrewssettask(dns_db_t *db, isc_task_t *task) {
a03848252fa85734ca75beae3d0b01bb503c0a8bMark Andrews UNUSED(db);
a03848252fa85734ca75beae3d0b01bb503c0a8bMark Andrews UNUSED(task);
a03848252fa85734ca75beae3d0b01bb503c0a8bMark Andrews}
a03848252fa85734ca75beae3d0b01bb503c0a8bMark Andrews
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonstatic dns_dbmethods_t sdb_methods = {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington attach,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington detach,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington beginload,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington endload,
7829fad4093f2c1985b1efb7cea00287ff015d2bckb NULL,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dump,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington currentversion,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington newversion,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington attachversion,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington closeversion,
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt NULL,
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt NULL,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington findzonecut,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington attachnode,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington detachnode,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington expirenode,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington printnode,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington createiterator,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington findrdataset,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington allrdatasets,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington addrdataset,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington subtractrdataset,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington deleterdataset,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington issecure,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington nodecount,
4a30ede93d59137009db734661cde17612e8ffbeMark Andrews ispersistent,
a03848252fa85734ca75beae3d0b01bb503c0a8bMark Andrews overmem,
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 settask,
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt NULL, /* getoriginnode */
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt NULL, /* transfernode */
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt NULL, /* getnsec3parameters */
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt NULL, /* findnsec3node */
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt NULL, /* setsigningtime */
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt NULL, /* getsigningtime */
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt NULL, /* resigned */
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt NULL, /* isdnssec */
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt NULL, /* getrrsetstats */
94315060c2b0d9deafabe72d6a0482405fd9d377Evan Hunt NULL, /* rpz_attach */
94315060c2b0d9deafabe72d6a0482405fd9d377Evan Hunt NULL, /* rpz_ready */
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt findnodeext,
dd2a0a6d2dec1c23787351e51b434a838dec5603Evan Hunt findext,
dd2a0a6d2dec1c23787351e51b434a838dec5603Evan Hunt NULL, /* setcachestats */
b4bbf494183e4158b417d9200297ff0764af2f9dMark Andrews NULL, /* hashsize */
744c1db6352c4c3f11c8538e4a2a57c8b0e0d570Mark Andrews NULL, /* nodefullname */
744c1db6352c4c3f11c8538e4a2a57c8b0e0d570Mark Andrews NULL /* getsize */
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington};
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
6fd4ab217ef8e37703b029eac5ab7ae4f7a663c9Brian Wellingtonstatic isc_result_t
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtondns_sdb_create(isc_mem_t *mctx, dns_name_t *origin, dns_dbtype_t type,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_rdataclass_t rdclass, unsigned int argc, char *argv[],
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington void *driverarg, dns_db_t **dbp)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington{
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_sdb_t *sdb;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_result_t result;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington char zonestr[DNS_NAME_MAXTEXT + 1];
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_buffer_t b;
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington dns_sdbimplementation_t *imp;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington REQUIRE(driverarg != NULL);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington imp = driverarg;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (type != dns_dbtype_zone)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington return (ISC_R_NOTIMPLEMENTED);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington sdb = isc_mem_get(mctx, sizeof(dns_sdb_t));
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (sdb == NULL)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington return (ISC_R_NOMEMORY);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington memset(sdb, 0, sizeof(dns_sdb_t));
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_name_init(&sdb->common.origin, NULL);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington sdb->common.attributes = 0;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington sdb->common.methods = &sdb_methods;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington sdb->common.rdclass = rdclass;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington sdb->common.mctx = NULL;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington sdb->implementation = imp;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_mem_attach(mctx, &sdb->common.mctx);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington result = isc_mutex_init(&sdb->lock);
18d0b5e54be891a1aa938c165b6d439859121ec8Mark Andrews if (result != ISC_R_SUCCESS)
f24c135e09214c3843a49fd32ebef2f6a436ba8eBrian Wellington goto cleanup_mctx;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
f24c135e09214c3843a49fd32ebef2f6a436ba8eBrian Wellington result = dns_name_dupwithoffsets(origin, mctx, &sdb->common.origin);
f24c135e09214c3843a49fd32ebef2f6a436ba8eBrian Wellington if (result != ISC_R_SUCCESS)
e2fd12f3a020ca8c5de168a44fb72e339cdaa3e9Brian Wellington goto cleanup_lock;
f24c135e09214c3843a49fd32ebef2f6a436ba8eBrian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_buffer_init(&b, zonestr, sizeof(zonestr));
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington result = dns_name_totext(origin, ISC_TRUE, &b);
f24c135e09214c3843a49fd32ebef2f6a436ba8eBrian Wellington if (result != ISC_R_SUCCESS)
f24c135e09214c3843a49fd32ebef2f6a436ba8eBrian Wellington goto cleanup_origin;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_buffer_putuint8(&b, 0);
f24c135e09214c3843a49fd32ebef2f6a436ba8eBrian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington sdb->zone = isc_mem_strdup(mctx, zonestr);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (sdb->zone == NULL) {
f24c135e09214c3843a49fd32ebef2f6a436ba8eBrian Wellington result = ISC_R_NOMEMORY;
f24c135e09214c3843a49fd32ebef2f6a436ba8eBrian Wellington goto cleanup_origin;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington }
f24c135e09214c3843a49fd32ebef2f6a436ba8eBrian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington sdb->dbdata = NULL;
75e1e12f48012505699f504cfa364260cb2bc1afBrian Wellington if (imp->methods->create != NULL) {
e2fd12f3a020ca8c5de168a44fb72e339cdaa3e9Brian Wellington MAYBE_LOCK(sdb);
34f991028382079af7c2b53bac6768803ff28f8cBrian Wellington result = imp->methods->create(sdb->zone, argc, argv,
75e1e12f48012505699f504cfa364260cb2bc1afBrian Wellington imp->driverdata, &sdb->dbdata);
e2fd12f3a020ca8c5de168a44fb72e339cdaa3e9Brian Wellington MAYBE_UNLOCK(sdb);
f24c135e09214c3843a49fd32ebef2f6a436ba8eBrian Wellington if (result != ISC_R_SUCCESS)
f24c135e09214c3843a49fd32ebef2f6a436ba8eBrian Wellington goto cleanup_zonestr;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington }
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington sdb->references = 1;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington sdb->common.magic = DNS_DB_MAGIC;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington sdb->common.impmagic = SDB_MAGIC;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington *dbp = (dns_db_t *)sdb;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington return (ISC_R_SUCCESS);
f24c135e09214c3843a49fd32ebef2f6a436ba8eBrian Wellington
f24c135e09214c3843a49fd32ebef2f6a436ba8eBrian Wellington cleanup_zonestr:
f24c135e09214c3843a49fd32ebef2f6a436ba8eBrian Wellington isc_mem_free(mctx, sdb->zone);
f24c135e09214c3843a49fd32ebef2f6a436ba8eBrian Wellington cleanup_origin:
f24c135e09214c3843a49fd32ebef2f6a436ba8eBrian Wellington dns_name_free(&sdb->common.origin, mctx);
f24c135e09214c3843a49fd32ebef2f6a436ba8eBrian Wellington cleanup_lock:
0a25550b464ad40e4d90ebff8ecf23595b05ae3bFrancis Dupont (void)isc_mutex_destroy(&sdb->lock);
f24c135e09214c3843a49fd32ebef2f6a436ba8eBrian Wellington cleanup_mctx:
f24c135e09214c3843a49fd32ebef2f6a436ba8eBrian Wellington isc_mem_put(mctx, sdb, sizeof(dns_sdb_t));
f24c135e09214c3843a49fd32ebef2f6a436ba8eBrian Wellington isc_mem_detach(&mctx);
f24c135e09214c3843a49fd32ebef2f6a436ba8eBrian Wellington
f24c135e09214c3843a49fd32ebef2f6a436ba8eBrian Wellington return (result);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington}
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington/*
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * Rdataset Methods
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington */
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonstatic void
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtondisassociate(dns_rdataset_t *rdataset) {
78838d3e0cd62423c23de5503910e01884d2104bBrian Wellington dns_dbnode_t *node = rdataset->private5;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_sdbnode_t *sdbnode = (dns_sdbnode_t *) node;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_db_t *db = (dns_db_t *) sdbnode->sdb;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington detachnode(db, &node);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc__rdatalist_disassociate(rdataset);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington}
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
a012d6dbfb100390efa7d0d4be64ada0210b09ddBrian Wellingtonstatic void
a012d6dbfb100390efa7d0d4be64ada0210b09ddBrian Wellingtonrdataset_clone(dns_rdataset_t *source, dns_rdataset_t *target) {
a012d6dbfb100390efa7d0d4be64ada0210b09ddBrian Wellington dns_dbnode_t *node = source->private5;
a012d6dbfb100390efa7d0d4be64ada0210b09ddBrian Wellington dns_sdbnode_t *sdbnode = (dns_sdbnode_t *) node;
a012d6dbfb100390efa7d0d4be64ada0210b09ddBrian Wellington dns_db_t *db = (dns_db_t *) sdbnode->sdb;
a012d6dbfb100390efa7d0d4be64ada0210b09ddBrian Wellington dns_dbnode_t *tempdb = NULL;
a012d6dbfb100390efa7d0d4be64ada0210b09ddBrian Wellington
a012d6dbfb100390efa7d0d4be64ada0210b09ddBrian Wellington isc__rdatalist_clone(source, target);
a012d6dbfb100390efa7d0d4be64ada0210b09ddBrian Wellington attachnode(db, node, &tempdb);
a012d6dbfb100390efa7d0d4be64ada0210b09ddBrian Wellington source->private5 = tempdb;
a012d6dbfb100390efa7d0d4be64ada0210b09ddBrian Wellington}
a012d6dbfb100390efa7d0d4be64ada0210b09ddBrian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonstatic dns_rdatasetmethods_t methods = {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington disassociate,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc__rdatalist_first,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc__rdatalist_next,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc__rdatalist_current,
a012d6dbfb100390efa7d0d4be64ada0210b09ddBrian Wellington rdataset_clone,
35541328a8c18ba1f984300dfe30ec8713c90031Mark Andrews isc__rdatalist_count,
35541328a8c18ba1f984300dfe30ec8713c90031Mark Andrews isc__rdatalist_addnoqname,
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 isc__rdatalist_getnoqname,
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 NULL,
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 NULL,
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews NULL,
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews NULL,
0cae66577c69c89086cd065bb297690072b471b4Mark Andrews NULL,
0cae66577c69c89086cd065bb297690072b471b4Mark Andrews NULL,
092d3b76db6b93b8029bd7d083e74fc80fb41858Mark Andrews NULL,
a8da00ef95ba37b9d071c2b8db1a0c967e060106Mark Andrews NULL,
a8da00ef95ba37b9d071c2b8db1a0c967e060106Mark Andrews NULL,
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 NULL
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington};
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonstatic void
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonlist_tordataset(dns_rdatalist_t *rdatalist,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_db_t *db, dns_dbnode_t *node,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_rdataset_t *rdataset)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington{
a012d6dbfb100390efa7d0d4be64ada0210b09ddBrian Wellington /*
a012d6dbfb100390efa7d0d4be64ada0210b09ddBrian Wellington * The sdb rdataset is an rdatalist with some additions.
a012d6dbfb100390efa7d0d4be64ada0210b09ddBrian Wellington * - private1 & private2 are used by the rdatalist.
a012d6dbfb100390efa7d0d4be64ada0210b09ddBrian Wellington * - private3 & private 4 are unused.
a012d6dbfb100390efa7d0d4be64ada0210b09ddBrian Wellington * - private5 is the node.
a012d6dbfb100390efa7d0d4be64ada0210b09ddBrian Wellington */
a012d6dbfb100390efa7d0d4be64ada0210b09ddBrian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington /* This should never fail. */
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington RUNTIME_CHECK(dns_rdatalist_tordataset(rdatalist, rdataset) ==
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington ISC_R_SUCCESS);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington rdataset->methods = &methods;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_db_attachnode(db, node, &rdataset->private5);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington}
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington/*
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington * Database Iterator Methods
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington */
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellingtonstatic void
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellingtondbiterator_destroy(dns_dbiterator_t **iteratorp) {
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington sdb_dbiterator_t *sdbiter = (sdb_dbiterator_t *)(*iteratorp);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington dns_sdb_t *sdb = (dns_sdb_t *)sdbiter->common.db;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington while (!ISC_LIST_EMPTY(sdbiter->nodelist)) {
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington dns_sdbnode_t *node;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington node = ISC_LIST_HEAD(sdbiter->nodelist);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington ISC_LIST_UNLINK(sdbiter->nodelist, node, link);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington destroynode(node);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington }
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington dns_db_detach(&sdbiter->common.db);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington isc_mem_put(sdb->common.mctx, sdbiter, sizeof(sdb_dbiterator_t));
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington *iteratorp = NULL;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington}
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellingtonstatic isc_result_t
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellingtondbiterator_first(dns_dbiterator_t *iterator) {
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington sdb_dbiterator_t *sdbiter = (sdb_dbiterator_t *)iterator;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington sdbiter->current = ISC_LIST_HEAD(sdbiter->nodelist);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington if (sdbiter->current == NULL)
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington return (ISC_R_NOMORE);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington else
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington return (ISC_R_SUCCESS);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington}
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellingtonstatic isc_result_t
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellingtondbiterator_last(dns_dbiterator_t *iterator) {
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington sdb_dbiterator_t *sdbiter = (sdb_dbiterator_t *)iterator;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington sdbiter->current = ISC_LIST_TAIL(sdbiter->nodelist);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington if (sdbiter->current == NULL)
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington return (ISC_R_NOMORE);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington else
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington return (ISC_R_SUCCESS);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington}
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellingtonstatic isc_result_t
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellingtondbiterator_seek(dns_dbiterator_t *iterator, dns_name_t *name) {
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington sdb_dbiterator_t *sdbiter = (sdb_dbiterator_t *)iterator;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington sdbiter->current = ISC_LIST_HEAD(sdbiter->nodelist);
01dbc4fc00adc933af96e88bfce95c07ef1f3c39Mark Andrews while (sdbiter->current != NULL) {
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington if (dns_name_equal(sdbiter->current->name, name))
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington return (ISC_R_SUCCESS);
01dbc4fc00adc933af96e88bfce95c07ef1f3c39Mark Andrews sdbiter->current = ISC_LIST_NEXT(sdbiter->current, link);
01dbc4fc00adc933af96e88bfce95c07ef1f3c39Mark Andrews }
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington return (ISC_R_NOTFOUND);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington}
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellingtonstatic isc_result_t
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellingtondbiterator_prev(dns_dbiterator_t *iterator) {
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington sdb_dbiterator_t *sdbiter = (sdb_dbiterator_t *)iterator;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington sdbiter->current = ISC_LIST_PREV(sdbiter->current, link);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington if (sdbiter->current == NULL)
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington return (ISC_R_NOMORE);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington else
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington return (ISC_R_SUCCESS);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington}
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellingtonstatic isc_result_t
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellingtondbiterator_next(dns_dbiterator_t *iterator) {
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington sdb_dbiterator_t *sdbiter = (sdb_dbiterator_t *)iterator;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington sdbiter->current = ISC_LIST_NEXT(sdbiter->current, link);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington if (sdbiter->current == NULL)
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington return (ISC_R_NOMORE);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington else
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington return (ISC_R_SUCCESS);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington}
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellingtonstatic isc_result_t
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellingtondbiterator_current(dns_dbiterator_t *iterator, dns_dbnode_t **nodep,
78838d3e0cd62423c23de5503910e01884d2104bBrian Wellington dns_name_t *name)
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington{
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington sdb_dbiterator_t *sdbiter = (sdb_dbiterator_t *)iterator;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington attachnode(iterator->db, sdbiter->current, nodep);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington if (name != NULL)
b7cd261f2fca2c7138cdc6ae8ee434e9c0031303Brian Wellington return (dns_name_copy(sdbiter->current->name, name, NULL));
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington return (ISC_R_SUCCESS);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington}
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellingtonstatic isc_result_t
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellingtondbiterator_pause(dns_dbiterator_t *iterator) {
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington UNUSED(iterator);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington return (ISC_R_SUCCESS);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington}
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington
5d85bf183f957f9ea0902be1a6e3405b90bc7c0fBrian Wellingtonstatic isc_result_t
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellingtondbiterator_origin(dns_dbiterator_t *iterator, dns_name_t *name) {
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington UNUSED(iterator);
b7cd261f2fca2c7138cdc6ae8ee434e9c0031303Brian Wellington return (dns_name_copy(dns_rootname, name, NULL));
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington}
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington/*
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * Rdataset Iterator Methods
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington */
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonstatic void
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonrdatasetiter_destroy(dns_rdatasetiter_t **iteratorp) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington sdb_rdatasetiter_t *sdbiterator = (sdb_rdatasetiter_t *)(*iteratorp);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington detachnode(sdbiterator->common.db, &sdbiterator->common.node);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_mem_put(sdbiterator->common.db->mctx, sdbiterator,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington sizeof(sdb_rdatasetiter_t));
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington *iteratorp = NULL;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington}
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonstatic isc_result_t
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonrdatasetiter_first(dns_rdatasetiter_t *iterator) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington sdb_rdatasetiter_t *sdbiterator = (sdb_rdatasetiter_t *)iterator;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_sdbnode_t *sdbnode = (dns_sdbnode_t *)iterator->node;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (ISC_LIST_EMPTY(sdbnode->lists))
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington return (ISC_R_NOMORE);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington sdbiterator->current = ISC_LIST_HEAD(sdbnode->lists);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington return (ISC_R_SUCCESS);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington}
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonstatic isc_result_t
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonrdatasetiter_next(dns_rdatasetiter_t *iterator) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington sdb_rdatasetiter_t *sdbiterator = (sdb_rdatasetiter_t *)iterator;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington sdbiterator->current = ISC_LIST_NEXT(sdbiterator->current, link);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (sdbiterator->current == NULL)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington return (ISC_R_NOMORE);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington else
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington return (ISC_R_SUCCESS);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington}
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonstatic void
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonrdatasetiter_current(dns_rdatasetiter_t *iterator, dns_rdataset_t *rdataset) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington sdb_rdatasetiter_t *sdbiterator = (sdb_rdatasetiter_t *)iterator;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington list_tordataset(sdbiterator->current, iterator->db, iterator->node,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington rdataset);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington}