sdb.c revision 34f991028382079af7c2b53bac6768803ff28f8c
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * Copyright (C) 2000 Internet Software Consortium.
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 * 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.
34f991028382079af7c2b53bac6768803ff28f8cBrian Wellington/* $Id: sdb.c,v 1.16 2000/11/17 01:27:34 bwelling Exp $ */
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington /* Unlocked */
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington /* Unlocked */
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/* These values are taken from RFC 1537 */
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington#define SDB_DEFAULT_EXPIRE (60 * 60 * 24 * 7)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington/* This is a reasonable value */
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,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonstatic isc_result_t findrdataset(dns_db_t *db, dns_dbnode_t *node,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_rdatatype_t type, dns_rdatatype_t covers,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_stdtime_t now, dns_rdataset_t *rdataset,
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellingtonstatic isc_result_t createnode(dns_sdb_t *sdb, dns_sdbnode_t **nodep);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellingtonstatic void destroynode(dns_sdbnode_t *node);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonstatic void detachnode(dns_db_t *db, dns_dbnode_t **targetp);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonstatic void list_tordataset(dns_rdatalist_t *rdatalist,
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 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 Wellingtonstatic isc_result_t dbiterator_pause(dns_dbiterator_t *iterator);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellingtonstatic isc_result_t dbiterator_origin(dns_dbiterator_t *iterator,
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellingtonstatic dns_dbiteratormethods_t dbiterator_methods = {
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,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonstatic dns_rdatasetitermethods_t rdatasetiter_methods = {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * Functions used by implementors of simple databases
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 REQUIRE(sdbimp != NULL && *sdbimp == NULL);
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington imp = isc_mem_get(mctx, sizeof(dns_sdbimplementation_t));
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington result = dns_db_register(drivername, dns_sdb_create, imp, mctx,
77ac297199fc44809d9628558223627c10ae3f31Brian Wellingtondns_sdb_unregister(dns_sdbimplementation_t **sdbimp) {
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington REQUIRE(sdbimp != NULL && *sdbimp != NULL);
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington isc_mem_put(mctx, imp, sizeof(dns_sdbimplementation_t));
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtondns_sdb_putrr(dns_sdblookup_t *lookup, const char *type, dns_ttl_t ttl,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington unsigned int size;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington result = dns_rdatatype_fromtext(&typeval, (isc_textregion_t *)&r);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington rdatalist = ISC_LIST_NEXT(rdatalist, link);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington rdatalist = isc_mem_get(mctx, sizeof(dns_rdatalist_t));
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington rdatalist->rdclass = lookup->sdb->common.rdclass;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington ISC_LIST_APPEND(lookup->lists, rdatalist, link);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington rdata = isc_mem_get(mctx, sizeof(dns_rdata_t));
a4c351fcef77fb332e3cb20253fb96556a414a17Brian Wellington if ((imp->flags & DNS_SDBFLAG_RELATIVERDATA) != 0)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington result = isc_buffer_allocate(mctx, &rdatabuf, size);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington result = dns_rdata_fromtext(rdata, rdatalist->rdclass,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington ISC_LIST_APPEND(rdatalist->rdata, rdata, link);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington ISC_LIST_APPEND(lookup->buffers, rdatabuf, link);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_mem_put(mctx, rdata, sizeof(dns_rdata_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 dns_sdb_t *sdb = (dns_sdb_t *)allnodes->common.db;
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington dns_sdbimplementation_t *imp = sdb->implementation;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington if ((imp->flags & DNS_SDBFLAG_RELATIVERDATA) != 0)
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington result = dns_name_fromtext(newname, &b, origin, ISC_FALSE, NULL);
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 sdbnode = ISC_LIST_HEAD(allnodes->nodelist);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington if (sdbnode == NULL || !dns_name_equal(sdbnode->name, newname)) {
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington sdbnode->name = isc_mem_get(mctx, sizeof(dns_name_t));
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington result = dns_name_dup(newname, mctx, sdbnode->name);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington isc_mem_put(mctx, sdbnode->name, sizeof(dns_name_t));
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington ISC_LIST_PREPEND(allnodes->nodelist, sdbnode, link);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington dns_name_equal(newname, &sdb->common.origin))
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington return (dns_sdb_putrr(sdbnode, type, ttl, data));
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtondns_sdb_putsoa(dns_sdblookup_t *lookup, const char *mname, const char *rname,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington char str[2 * DNS_NAME_MAXTEXT + 5 * (sizeof("2147483647")) + 7];
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington n = snprintf(str, sizeof str, "%s %s %u %u %u %u %u",
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (n >= (int)sizeof(str) || n < 0)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington return (dns_sdb_putrr(lookup, "SOA", SDB_DEFAULT_TTL, str));
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * DB routines
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonattach(dns_db_t *source, dns_db_t **targetp) {
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington dns_sdbimplementation_t *imp = sdb->implementation;
75e1e12f48012505699f504cfa364260cb2bc1afBrian Wellington imp->methods->destroy(sdb->zone, imp->driverdata,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonbeginload(dns_db_t *db, dns_addrdatasetfunc_t *addp, dns_dbload_t **dbloadp) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonendload(dns_db_t *db, dns_dbload_t **dbloadp) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtondump(dns_db_t *db, dns_dbversion_t *version, const char *filename) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtoncurrentversion(dns_db_t *db, dns_dbversion_t **versionp) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington REQUIRE(versionp != NULL && *versionp == NULL);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonnewversion(dns_db_t *db, dns_dbversion_t **versionp) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonattachversion(dns_db_t *db, dns_dbversion_t *source,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington REQUIRE(source != NULL && source == (void *) &dummy);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtoncloseversion(dns_db_t *db, dns_dbversion_t **versionp, isc_boolean_t commit) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington REQUIRE(versionp != NULL && *versionp == (void *) &dummy);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtoncreatenode(dns_sdb_t *sdb, dns_sdbnode_t **nodep) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington node = isc_mem_get(sdb->common.mctx, sizeof(dns_sdbnode_t));
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington attach((dns_db_t *)sdb, (dns_db_t **)&node->sdb);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_mem_put(sdb->common.mctx, sdb, sizeof(dns_sdb_t));
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington "isc_mutex_init() failed: %s",
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_mem_put(sdb->common.mctx, node, sizeof(dns_sdbnode_t));
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington isc_mem_put(mctx, rdata, sizeof(dns_rdata_t));
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington isc_mem_put(mctx, list, sizeof(dns_rdatalist_t));
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington isc_mem_put(mctx, node->name, sizeof(dns_name_t));
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington isc_mem_put(mctx, node, sizeof(dns_sdbnode_t));
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonfindnode(dns_db_t *db, dns_name_t *name, isc_boolean_t create,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_buffer_init(&b, namestr, sizeof(namestr));
a4c351fcef77fb332e3cb20253fb96556a414a17Brian Wellington if ((imp->flags & DNS_SDBFLAG_RELATIVEOWNER) != 0) {
a4c351fcef77fb332e3cb20253fb96556a414a17Brian Wellington dns_name_getlabelsequence(name, 0, labels, &relname);
a4c351fcef77fb332e3cb20253fb96556a414a17Brian Wellington result = dns_name_totext(&relname, ISC_TRUE, &b);
a4c351fcef77fb332e3cb20253fb96556a414a17Brian Wellington result = dns_name_totext(name, ISC_TRUE, &b);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isorigin = dns_name_equal(name, &sdb->common.origin);
75e1e12f48012505699f504cfa364260cb2bc1afBrian Wellington result = imp->methods->lookup(sdb->zone, namestr, sdb->dbdata, node);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (result != ISC_R_SUCCESS && !isorigin) {
75e1e12f48012505699f504cfa364260cb2bc1afBrian Wellington if (isorigin && imp->methods->authority != NULL) {
75e1e12f48012505699f504cfa364260cb2bc1afBrian Wellington result = imp->methods->authority(sdb->zone, sdb->dbdata, node);
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 unsigned int i;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington REQUIRE(version == NULL || version == (void *) &dummy);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (!dns_name_issubdomain(name, &db->origin))
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington olabels = dns_name_countlabels(&db->origin);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * Unless this is an explicit lookup at the origin, don't
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * look at the origin.
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * Look up the next label.
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_name_getlabelsequence(name, nlabels - i, i, xname);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington result = findnode(db, xname, ISC_FALSE, &node);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * Look for a DNAME at the current label, unless this is
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * Look for an NS at the current label, unless this is the
0a45f098e446a7f41c2a71d9dd0fd8f459b49c34Brian Wellington * origin or glue is ok.
0a45f098e446a7f41c2a71d9dd0fd8f459b49c34Brian Wellington if (i != olabels && (options & DNS_DBFIND_GLUEOK) == 0) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * If the current name is not the qname, add another label
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * and try again.
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * If we're looking for ANY, we're done.
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * Look for the qtype.
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington result = findrdataset(db, node, version, type,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * Look for a CNAME
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (rdataset == &xrdataset && dns_rdataset_isassociated(rdataset))
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington xresult = dns_name_concatenate(xname, NULL, foundname, NULL);
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 Wellingtonattachnode(dns_db_t *db, dns_dbnode_t *source, dns_dbnode_t **targetp) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_sdbnode_t *node = (dns_sdbnode_t *)source;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington INSIST(node->references != 0); /* Catch overflow. */
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtondetachnode(dns_db_t *db, dns_dbnode_t **targetp) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington REQUIRE(targetp != NULL && *targetp != NULL);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonexpirenode(dns_db_t *db, dns_dbnode_t *node, isc_stdtime_t now) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonprintnode(dns_db_t *db, dns_dbnode_t *node, FILE *out) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtoncreateiterator(dns_db_t *db, isc_boolean_t relative_names,
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington dns_sdbimplementation_t *imp = sdb->implementation;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington sdbiter = isc_mem_get(sdb->common.mctx, sizeof(sdb_dbiterator_t));
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington sdbiter->common.methods = &dbiterator_methods;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington sdbiter->common.relative_names = relative_names;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington sdbiter->common.magic = DNS_DBITERATOR_MAGIC;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington result = imp->methods->allnodes(sdb->zone, sdb->dbdata, sdbiter);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington dbiterator_destroy((dns_dbiterator_t **)&sdbiter);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington ISC_LIST_UNLINK(sdbiter->nodelist, sdbiter->origin, link);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington ISC_LIST_PREPEND(sdbiter->nodelist, sdbiter->origin, link);
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_sdbnode_t *sdbnode = (dns_sdbnode_t *)node;
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 REQUIRE(version == NULL || version == &dummy);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington iterator = isc_mem_get(db->mctx, sizeof(sdb_rdatasetiter_t));
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington iterator->common.magic = DNS_RDATASETITER_MAGIC;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington iterator->common.methods = &rdatasetiter_methods;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington attachnode(db, node, &iterator->common.node);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington *iteratorp = (dns_rdatasetiter_t *)iterator;
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 Wellingtonsubtractrdataset(dns_db_t *db, dns_dbnode_t *node, dns_dbversion_t *version,
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 Wellingtonstatic unsigned int
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[],
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington sdb = isc_mem_get(mctx, sizeof(dns_sdb_t));
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington "isc_mutex_init() failed: %s",
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington result = dns_name_dupwithoffsets(origin, mctx, &sdb->common.origin);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_buffer_init(&b, zonestr, sizeof(zonestr));
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington result = dns_name_totext(origin, ISC_TRUE, &b);
34f991028382079af7c2b53bac6768803ff28f8cBrian Wellington result = imp->methods->create(sdb->zone, argc, argv,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * Rdataset Methods
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_sdbnode_t *sdbnode = (dns_sdbnode_t *) node;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington /* This should never fail. */
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington RUNTIME_CHECK(dns_rdatalist_tordataset(rdatalist, rdataset) ==
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_db_attachnode(db, node, &rdataset->private5);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington * Database Iterator Methods
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 while (!ISC_LIST_EMPTY(sdbiter->nodelist)) {
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington ISC_LIST_UNLINK(sdbiter->nodelist, node, link);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington isc_mem_put(sdb->common.mctx, sdbiter, sizeof(sdb_dbiterator_t));
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellingtondbiterator_first(dns_dbiterator_t *iterator) {
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington sdb_dbiterator_t *sdbiter = (sdb_dbiterator_t *)iterator;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington sdbiter->current = ISC_LIST_HEAD(sdbiter->nodelist);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellingtondbiterator_last(dns_dbiterator_t *iterator) {
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington sdb_dbiterator_t *sdbiter = (sdb_dbiterator_t *)iterator;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington sdbiter->current = ISC_LIST_TAIL(sdbiter->nodelist);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellingtondbiterator_seek(dns_dbiterator_t *iterator, dns_name_t *name) {
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington sdb_dbiterator_t *sdbiter = (sdb_dbiterator_t *)iterator;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington sdbiter->current = ISC_LIST_HEAD(sdbiter->nodelist);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington if (dns_name_equal(sdbiter->current->name, name))
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellingtondbiterator_prev(dns_dbiterator_t *iterator) {
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington sdb_dbiterator_t *sdbiter = (sdb_dbiterator_t *)iterator;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington sdbiter->current = ISC_LIST_PREV(sdbiter->current, link);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellingtondbiterator_next(dns_dbiterator_t *iterator) {
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington sdb_dbiterator_t *sdbiter = (sdb_dbiterator_t *)iterator;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington sdbiter->current = ISC_LIST_NEXT(sdbiter->current, link);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellingtondbiterator_current(dns_dbiterator_t *iterator, dns_dbnode_t **nodep,
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington sdb_dbiterator_t *sdbiter = (sdb_dbiterator_t *)iterator;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington attachnode(iterator->db, sdbiter->current, nodep);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington return (dns_name_concatenate(sdbiter->current->name, NULL,
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellingtondbiterator_pause(dns_dbiterator_t *iterator) {
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellingtondbiterator_origin(dns_dbiterator_t *iterator, dns_name_t *name) {
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington return (dns_name_concatenate(dns_rootname, NULL, name, NULL));
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * Rdataset Iterator Methods
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 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 sdbiterator->current = ISC_LIST_HEAD(sdbnode->lists);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonrdatasetiter_next(dns_rdatasetiter_t *iterator) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington sdb_rdatasetiter_t *sdbiterator = (sdb_rdatasetiter_t *)iterator;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington sdbiterator->current = ISC_LIST_NEXT(sdbiterator->current, link);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonrdatasetiter_current(dns_rdatasetiter_t *iterator, dns_rdataset_t *rdataset) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington sdb_rdatasetiter_t *sdbiterator = (sdb_rdatasetiter_t *)iterator;