sdb.c revision 34f991028382079af7c2b53bac6768803ff28f8c
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington/*
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * Copyright (C) 2000 Internet Software Consortium.
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington *
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * Permission to use, copy, modify, and distribute this software for any
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * purpose with or without fee is hereby granted, provided that the above
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * copyright notice and this permission notice appear in all copies.
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington *
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington */
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
34f991028382079af7c2b53bac6768803ff28f8cBrian Wellington/* $Id: sdb.c,v 1.16 2000/11/17 01:27:34 bwelling Exp $ */
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
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;
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 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;
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
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington#define SDB_MAGIC 0x5344422d /* SDB- */
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington#define VALID_SDB(sdb) ((sdb) != NULL && \
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian 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
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington/* These values are taken from RFC 1537 */
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
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);
75e1e12f48012505699f504cfa364260cb2bc1afBrian Wellington REQUIRE(methods->lookup != NULL);
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington REQUIRE(mctx != NULL);
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington REQUIRE(sdbimp != NULL && *sdbimp == NULL);
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);
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington imp->dbimp = NULL;
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington result = dns_db_register(drivername, dns_sdb_create, imp, mctx,
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington &imp->dbimp);
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington if (result != ISC_R_SUCCESS) {
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington dns_sdb_unregister(&imp);
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington return (result);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington }
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington *sdbimp = imp;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington return (ISC_R_SUCCESS);
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);
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
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonisc_result_t
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtondns_sdb_putrr(dns_sdblookup_t *lookup, const char *type, dns_ttl_t ttl,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington const char *data)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington{
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_rdatalist_t *rdatalist;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_rdata_t *rdata;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_rdatatype_t typeval;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_consttextregion_t r;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_buffer_t b;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_buffer_t *rdatabuf;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_lex_t *lex;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_result_t result;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington unsigned int size;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_mem_t *mctx;
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington dns_sdbimplementation_t *imp;
a4c351fcef77fb332e3cb20253fb96556a414a17Brian Wellington dns_name_t *origin;
a4c351fcef77fb332e3cb20253fb96556a414a17Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington REQUIRE(VALID_SDBLOOKUP(lookup));
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington REQUIRE(type != NULL);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington REQUIRE(data != NULL);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington mctx = lookup->sdb->common.mctx;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington r.base = type;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington r.length = strlen(type);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington result = dns_rdatatype_fromtext(&typeval, (isc_textregion_t *)&r);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (result != ISC_R_SUCCESS)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington return (result);
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);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington rdatalist->rdclass = lookup->sdb->common.rdclass;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington rdatalist->type = typeval;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington rdatalist->covers = 0;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington rdatalist->ttl = ttl;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington ISC_LIST_INIT(rdatalist->rdata);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington ISC_LINK_INIT(rdatalist, link);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington ISC_LIST_APPEND(lookup->lists, rdatalist, link);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington } 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);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_rdata_init(rdata);
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 lex = NULL;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington result = isc_lex_create(mctx, 64, &lex);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (result != ISC_R_SUCCESS)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington goto failure;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington size = 64;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington do {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_buffer_init(&b, data, strlen(data));
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_buffer_add(&b, strlen(data));
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington result = isc_lex_openbuffer(lex, &b);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (result != ISC_R_SUCCESS)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington goto failure;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington rdatabuf = NULL;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington result = isc_buffer_allocate(mctx, &rdatabuf, size);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (result != ISC_R_SUCCESS)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington goto failure;
a4c351fcef77fb332e3cb20253fb96556a414a17Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington result = dns_rdata_fromtext(rdata, rdatalist->rdclass,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington rdatalist->type, lex,
a4c351fcef77fb332e3cb20253fb96556a414a17Brian Wellington origin, ISC_FALSE,
ebfcb6cf66283096ebda1503b6cc042ce86b6bedBrian Wellington mctx, rdatabuf, NULL);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (result != ISC_R_SUCCESS)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_buffer_free(&rdatabuf);
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
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington ISC_LIST_APPEND(rdatalist->rdata, rdata, link);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington ISC_LIST_APPEND(lookup->buffers, rdatabuf, link);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (lex != NULL)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_lex_destroy(&lex);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington return (ISC_R_SUCCESS);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington failure:
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (rdatabuf != NULL)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_buffer_free(&rdatabuf);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (lex != NULL)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_lex_destroy(&lex);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_mem_put(mctx, rdata, sizeof(dns_rdata_t));
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington return (result);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington}
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellingtonisc_result_t
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellingtondns_sdb_putnamedrr(dns_sdballnodes_t *allnodes, const char *name,
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington const char *type, dns_ttl_t ttl, const char *data)
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington{
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;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington isc_buffer_init(&b, name, strlen(name));
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington isc_buffer_add(&b, strlen(name));
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington result = dns_name_fromtext(newname, &b, origin, ISC_FALSE, 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 }
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington return (dns_sdb_putrr(sdbnode, type, ttl, data));
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington
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
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington 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
75e1e12f48012505699f504cfa364260cb2bc1afBrian Wellington if (imp->methods->destroy != NULL)
75e1e12f48012505699f504cfa364260cb2bc1afBrian Wellington imp->methods->destroy(sdb->zone, imp->driverdata,
75e1e12f48012505699f504cfa364260cb2bc1afBrian Wellington &sdb->dbdata);
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
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonbeginload(dns_db_t *db, dns_addrdatasetfunc_t *addp, dns_dbload_t **dbloadp) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington UNUSED(db);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington UNUSED(addp);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington UNUSED(dbloadp);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington return (ISC_R_NOTIMPLEMENTED);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington}
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonstatic isc_result_t
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonendload(dns_db_t *db, dns_dbload_t **dbloadp) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington UNUSED(db);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington UNUSED(dbloadp);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington return (ISC_R_NOTIMPLEMENTED);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington}
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonstatic isc_result_t
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtondump(dns_db_t *db, dns_dbversion_t *version, const char *filename) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington UNUSED(db);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington UNUSED(version);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington UNUSED(filename);
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
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonattachversion(dns_db_t *db, dns_dbversion_t *source,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_dbversion_t **targetp)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington{
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington REQUIRE(source != NULL && source == (void *) &dummy);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington UNUSED(db);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington UNUSED(source);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington UNUSED(targetp);
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, sdb, sizeof(dns_sdb_t));
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington UNEXPECTED_ERROR(__FILE__, __LINE__,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington "isc_mutex_init() failed: %s",
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_result_totext(result));
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_mem_put(sdb->common.mctx, node, sizeof(dns_sdbnode_t));
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington return (ISC_R_UNEXPECTED);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington }
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));
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington detach((dns_db_t **)&sdb);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington}
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonstatic isc_result_t
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonfindnode(dns_db_t *db, dns_name_t *name, isc_boolean_t create,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington 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;
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);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
a4c351fcef77fb332e3cb20253fb96556a414a17Brian Wellington imp = sdb->implementation;
a4c351fcef77fb332e3cb20253fb96556a414a17Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_buffer_init(&b, namestr, sizeof(namestr));
a4c351fcef77fb332e3cb20253fb96556a414a17Brian Wellington if ((imp->flags & DNS_SDBFLAG_RELATIVEOWNER) != 0) {
a4c351fcef77fb332e3cb20253fb96556a414a17Brian Wellington dns_name_t relname;
a4c351fcef77fb332e3cb20253fb96556a414a17Brian Wellington unsigned int labels;
a4c351fcef77fb332e3cb20253fb96556a414a17Brian Wellington
a4c351fcef77fb332e3cb20253fb96556a414a17Brian Wellington labels = dns_name_countlabels(name) -
a4c351fcef77fb332e3cb20253fb96556a414a17Brian Wellington dns_name_countlabels(&db->origin);
a4c351fcef77fb332e3cb20253fb96556a414a17Brian Wellington dns_name_init(&relname, NULL);
a4c351fcef77fb332e3cb20253fb96556a414a17Brian Wellington dns_name_getlabelsequence(name, 0, labels, &relname);
a4c351fcef77fb332e3cb20253fb96556a414a17Brian Wellington result = dns_name_totext(&relname, ISC_TRUE, &b);
a4c351fcef77fb332e3cb20253fb96556a414a17Brian Wellington if (result != ISC_R_SUCCESS)
a4c351fcef77fb332e3cb20253fb96556a414a17Brian Wellington return (result);
a4c351fcef77fb332e3cb20253fb96556a414a17Brian Wellington } else {
a4c351fcef77fb332e3cb20253fb96556a414a17Brian Wellington result = dns_name_totext(name, ISC_TRUE, &b);
a4c351fcef77fb332e3cb20253fb96556a414a17Brian Wellington if (result != ISC_R_SUCCESS)
a4c351fcef77fb332e3cb20253fb96556a414a17Brian Wellington return (result);
a4c351fcef77fb332e3cb20253fb96556a414a17Brian Wellington }
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_buffer_putuint8(&b, 0);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington result = createnode(sdb, &node);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (result != ISC_R_SUCCESS)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington return (result);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isorigin = dns_name_equal(name, &sdb->common.origin);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
75e1e12f48012505699f504cfa364260cb2bc1afBrian Wellington result = imp->methods->lookup(sdb->zone, namestr, sdb->dbdata, node);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (result != ISC_R_SUCCESS && !isorigin) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington destroynode(node);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington return (result);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington }
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
75e1e12f48012505699f504cfa364260cb2bc1afBrian Wellington if (isorigin && imp->methods->authority != NULL) {
75e1e12f48012505699f504cfa364260cb2bc1afBrian Wellington result = imp->methods->authority(sdb->zone, sdb->dbdata, node);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (result != ISC_R_SUCCESS) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington destroynode(node);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington return (result);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington }
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington }
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington *nodep = node;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington return (ISC_R_SUCCESS);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington}
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonstatic isc_result_t
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonfind(dns_db_t *db, dns_name_t *name, dns_dbversion_t *version,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_rdatatype_t type, unsigned int options, isc_stdtime_t now,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_dbnode_t **nodep, dns_name_t *foundname,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington 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;
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 UNUSED(sigrdataset);
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
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (rdataset == NULL)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington rdataset = &xrdataset;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington result = DNS_R_NXDOMAIN;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington for (i = olabels; i <= nlabels; i++) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington /*
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * Unless this is an explicit lookup at the origin, don't
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * look at the origin.
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington */
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (i == olabels && i != nlabels)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington continue;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington /*
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * Look up the next label.
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington */
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_name_getlabelsequence(name, nlabels - i, i, xname);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington result = findnode(db, xname, ISC_FALSE, &node);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (result != ISC_R_SUCCESS) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington result = DNS_R_NXDOMAIN;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington continue;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington }
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
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) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (type != dns_rdatatype_dname)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian 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) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (type != dns_rdatatype_ns)
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
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
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington xresult = dns_name_concatenate(xname, NULL, foundname, NULL);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (xresult != ISC_R_SUCCESS) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington 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));
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
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
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtoncreateiterator(dns_db_t *db, isc_boolean_t relative_names,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington 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
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);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington sdbiter->common.relative_names = relative_names;
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
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington result = imp->methods->allnodes(sdb->zone, sdb->dbdata, sdbiter);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington if (result != ISC_R_SUCCESS) {
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington dbiterator_destroy((dns_dbiterator_t **)&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
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (type == dns_rdatatype_sig)
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);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
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,
b55c30f2de6e1baaa3a9ba69b92f428f2c255ac3Mark Andrews dns_rdataset_t *rdataset, isc_boolean_t exact,
b55c30f2de6e1baaa3a9ba69b92f428f2c255ac3Mark Andrews dns_rdataset_t *newrdataset)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington{
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington UNUSED(db);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington UNUSED(node);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington UNUSED(version);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington UNUSED(rdataset);
b55c30f2de6e1baaa3a9ba69b92f428f2c255ac3Mark Andrews UNUSED(exact);
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
4a30ede93d59137009db734661cde17612e8ffbeMark Andrewsovermem(dns_db_t *db, isc_boolean_t overmem) {
4a30ede93d59137009db734661cde17612e8ffbeMark Andrews UNUSED(db);
4a30ede93d59137009db734661cde17612e8ffbeMark Andrews UNUSED(overmem);
4a30ede93d59137009db734661cde17612e8ffbeMark Andrews}
4a30ede93d59137009db734661cde17612e8ffbeMark Andrews
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonstatic dns_dbmethods_t sdb_methods = {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington attach,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington detach,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington beginload,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington endload,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dump,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington currentversion,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington newversion,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington attachversion,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington closeversion,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington findnode,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington find,
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,
4a30ede93d59137009db734661cde17612e8ffbeMark Andrews overmem
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington};
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonisc_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);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (result != ISC_R_SUCCESS) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_mem_put(mctx, sdb, sizeof(dns_sdb_t));
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington UNEXPECTED_ERROR(__FILE__, __LINE__,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington "isc_mutex_init() failed: %s",
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_result_totext(result));
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_mem_detach(&sdb->common.mctx);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington return (ISC_R_UNEXPECTED);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington }
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington result = dns_name_dupwithoffsets(origin, mctx, &sdb->common.origin);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (result != ISC_R_SUCCESS) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington destroy(sdb);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington return (result);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington }
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_buffer_init(&b, zonestr, sizeof(zonestr));
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington result = dns_name_totext(origin, ISC_TRUE, &b);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (result != ISC_R_SUCCESS) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington destroy(sdb);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington return (result);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington }
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_buffer_putuint8(&b, 0);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington sdb->zone = isc_mem_strdup(mctx, zonestr);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (sdb->zone == NULL) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington destroy(sdb);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington return (ISC_R_NOMEMORY);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington }
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington sdb->dbdata = NULL;
75e1e12f48012505699f504cfa364260cb2bc1afBrian Wellington if (imp->methods->create != NULL) {
34f991028382079af7c2b53bac6768803ff28f8cBrian Wellington result = imp->methods->create(sdb->zone, argc, argv,
75e1e12f48012505699f504cfa364260cb2bc1afBrian Wellington imp->driverdata, &sdb->dbdata);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (result != ISC_R_SUCCESS) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington destroy(sdb);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington return (result);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington }
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);
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) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian 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
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonstatic dns_rdatasetmethods_t methods = {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington disassociate,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc__rdatalist_first,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc__rdatalist_next,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc__rdatalist_current,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc__rdatalist_clone,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc__rdatalist_count
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{
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);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington while (sdbiter->current != NULL)
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington if (dns_name_equal(sdbiter->current->name, name))
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington return (ISC_R_SUCCESS);
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,
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian 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)
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington return (dns_name_concatenate(sdbiter->current->name, NULL,
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington 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
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellingtonisc_result_t
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellingtondbiterator_origin(dns_dbiterator_t *iterator, dns_name_t *name) {
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington UNUSED(iterator);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington return (dns_name_concatenate(dns_rootname, NULL, 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}