0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * Copyright (C) 2000, 2001, 2003-2016 Internet Systems Consortium, Inc. ("ISC")
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * This Source Code Form is subject to the terms of the Mozilla Public
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * License, v. 2.0. If a copy of the MPL was not distributed with this
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * file, You can obtain one at http://mozilla.org/MPL/2.0/.
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington /* Unlocked */
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington /* Unlocked */
92ef1a9b9dbd48ecb507b42ac62c15afefdaf838David Lawrence#define SDB_MAGIC ISC_MAGIC('S', 'D', 'B', '-')
571688b02f955f6304649866e768b1f81739cbedBrian Wellington * Note that "impmagic" is not the first four bytes of the struct, so
571688b02f955f6304649866e768b1f81739cbedBrian Wellington * ISC_MAGIC_VALID cannot be used.
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)
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/* These values are taken from RFC1537 */
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington#define SDB_DEFAULT_EXPIRE (60 * 60 * 24 * 7)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington/* This is a reasonable value */
557bcc2092642b2d4668c9b08872c9f2bb88bddbMark Andrews#define MAYBE_LOCK(sdb) LOCK(&sdb->implementation->driverlock)
557bcc2092642b2d4668c9b08872c9f2bb88bddbMark Andrews#define MAYBE_UNLOCK(sdb) UNLOCK(&sdb->implementation->driverlock)
23f64ea0dcd7f5b7094ae6ade2a002fb7dde1466Brian Wellington unsigned int flags = sdb->implementation->flags; \
23f64ea0dcd7f5b7094ae6ade2a002fb7dde1466Brian Wellington if ((flags & DNS_SDBFLAG_THREADSAFE) == 0) \
23f64ea0dcd7f5b7094ae6ade2a002fb7dde1466Brian Wellington unsigned int flags = sdb->implementation->flags; \
23f64ea0dcd7f5b7094ae6ade2a002fb7dde1466Brian Wellington if ((flags & DNS_SDBFLAG_THREADSAFE) == 0) \
e2fd12f3a020ca8c5de168a44fb72e339cdaa3e9Brian Wellington UNLOCK(&sdb->implementation->driverlock); \
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,
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews REQUIRE(methods->lookup != NULL || methods->lookup2 != NULL);
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington REQUIRE(sdbimp != NULL && *sdbimp == NULL);
23f64ea0dcd7f5b7094ae6ade2a002fb7dde1466Brian Wellington REQUIRE((flags & ~(DNS_SDBFLAG_RELATIVEOWNER |
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington imp = isc_mem_get(mctx, sizeof(dns_sdbimplementation_t));
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington result = dns_db_register(drivername, dns_sdb_create, imp, mctx,
e2fd12f3a020ca8c5de168a44fb72e339cdaa3e9Brian Wellington isc_mem_put(mctx, imp, sizeof(dns_sdbimplementation_t));
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));
d2aebe24c477c70e79dc33ea0507e8886eb7d626Brian Wellingtonstatic inline unsigned int
6b79e960e6ba2991aeb02a6c39af255ab7f06d99Mark Andrews for (size = 1024; size < (64 * 1024); size *= 2)
6b79e960e6ba2991aeb02a6c39af255ab7f06d99Mark Andrews return (65535);
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrewsdns_sdb_putrdata(dns_sdblookup_t *lookup, dns_rdatatype_t typeval,
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews unsigned int rdlen)
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));
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson result = isc_buffer_allocate(mctx, &rdatabuf, rdlen);
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson isc_buffer_copyregion(rdatabuf, ®ion);
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson isc_buffer_usedregion(rdatabuf, ®ion);
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson dns_rdata_fromregion(rdata, rdatalist->rdclass, rdatalist->type,
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson ISC_LIST_APPEND(rdatalist->rdata, rdata, link);
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson ISC_LIST_APPEND(lookup->buffers, rdatabuf, link);
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson isc_mem_put(mctx, rdata, sizeof(dns_rdata_t));
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafssondns_sdb_putrr(dns_sdblookup_t *lookup, const char *type, dns_ttl_t ttl,
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson unsigned char *p = NULL;
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson unsigned int size = 0; /* Init to suppress compiler warning */
a4c351fcef77fb332e3cb20253fb96556a414a17Brian Wellington if ((imp->flags & DNS_SDBFLAG_RELATIVERDATA) != 0)
6b79e960e6ba2991aeb02a6c39af255ab7f06d99Mark Andrews * Is the RR too big?
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson result = dns_sdb_putrdata(lookup, typeval, ttl,
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafssongetnode(dns_sdballnodes_t *allnodes, const char *name, dns_sdbnode_t **nodep) {
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)
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 result = dns_name_fromtext(newname, &b, origin, 0, 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))
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafssondns_sdb_putnamedrr(dns_sdballnodes_t *allnodes, const char *name,
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson const char *type, dns_ttl_t ttl, const char *data)
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson result = getnode(allnodes, name, &sdbnode);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington return (dns_sdb_putrr(sdbnode, type, ttl, data));
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafssondns_sdb_putnamedrdata(dns_sdballnodes_t *allnodes, const char *name,
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson result = getnode(allnodes, name, &sdbnode);
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson return (dns_sdb_putrdata(sdbnode, type, ttl, rdata, rdlen));
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];
f3ca27e9fe307b55e35ea8d7b37351650630e5a3Andreas Gustafsson 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,
7829fad4093f2c1985b1efb7cea00287ff015d2bckbbeginload(dns_db_t *db, dns_rdatacallbacks_t *callbacks) {
a903095bf4512dae561c7f6fc7854a51bebf334aMark Andrewsdump(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) {
2f012d936b5ccdf6520c96a4de23721dc58a2221Automatic Updaterattachversion(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, 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));
793814f80703afdd69b59ade91e63efa81ae4178Evan Huntfindnodeext(dns_db_t *db, dns_name_t *name, isc_boolean_t create,
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt dns_clientinfomethods_t *methods, dns_clientinfo_t *clientinfo,
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews isorigin = dns_name_equal(name, &sdb->common.origin);
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews if ((imp->flags & DNS_SDBFLAG_RELATIVEOWNER) != 0) {
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews dns_name_getlabelsequence(name, 0, labels, &relname);
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews if ((imp->flags & DNS_SDBFLAG_RELATIVEOWNER) != 0) {
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews dns_name_getlabelsequence(name, 0, labels, &relname);
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews result = dns_name_totext(&relname, ISC_TRUE, &b);
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews result = imp->methods->lookup2(&sdb->common.origin, name,
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews result = imp->methods->lookup(sdb->zone, namestr, sdb->dbdata,
6e93e6ea4557291e847aced6a88adcdf39f06843Andreas Gustafsson isorigin && imp->methods->authority != NULL))
75e1e12f48012505699f504cfa364260cb2bc1afBrian Wellington if (isorigin && imp->methods->authority != NULL) {
75e1e12f48012505699f504cfa364260cb2bc1afBrian Wellington result = imp->methods->authority(sdb->zone, sdb->dbdata, node);
793814f80703afdd69b59ade91e63efa81ae4178Evan Huntfindext(dns_db_t *db, dns_name_t *name, dns_dbversion_t *version,
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt dns_rdatatype_t type, unsigned int options, isc_stdtime_t now,
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt dns_clientinfomethods_t *methods, dns_clientinfo_t *clientinfo,
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt 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);
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews i = (flags & DNS_SDBFLAG_DNS64) != 0 ? nlabels : olabels;
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews for (; i <= nlabels; i++) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * Look up the next label.
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_name_getlabelsequence(name, nlabels - i, i, xname);
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt result = findnodeext(db, xname, ISC_FALSE, methods,
85fcd0b9b2d80be4646187d7094e5644a52e3263Mark Andrews * No data at zone apex?
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews * DNS64 zone's don't have DNAME or NS records.
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews * DNS64 zone's don't have DNAME or NS records.
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) {
c302b021cc65cc9a358a9a1cbe48de12364f4cb6Brian Wellington if (i == nlabels && type == dns_rdatatype_any)
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))
b7cd261f2fca2c7138cdc6ae8ee434e9c0031303Brian Wellington xresult = dns_name_copy(xname, 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) {
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrewscreateiterator(dns_db_t *db, unsigned int options, dns_dbiterator_t **iteratorp)
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;
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews sdbiter->common.relative_names = ISC_TF(options & DNS_DB_RELATIVENAMES);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington sdbiter->common.magic = DNS_DBITERATOR_MAGIC;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington result = imp->methods->allnodes(sdb->zone, sdb->dbdata, sdbiter);
daa73eae708d568d453e6082e0890d35886a9e0fMark Andrews dbiterator_destroy((dns_dbiterator_t **) (void *)&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,
f8abaa0fae7f75d9601c10b6a4af8dd907494d45Mark Andrews dns_rdataset_t *rdataset, unsigned int options,
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));
f24c135e09214c3843a49fd32ebef2f6a436ba8eBrian 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;
a012d6dbfb100390efa7d0d4be64ada0210b09ddBrian Wellingtonrdataset_clone(dns_rdataset_t *source, dns_rdataset_t *target) {
a012d6dbfb100390efa7d0d4be64ada0210b09ddBrian Wellington dns_sdbnode_t *sdbnode = (dns_sdbnode_t *) node;
a012d6dbfb100390efa7d0d4be64ada0210b09ddBrian Wellington * The sdb rdataset is an rdatalist with some additions.
a012d6dbfb100390efa7d0d4be64ada0210b09ddBrian Wellington * - private1 & private2 are used by the rdatalist.
a012d6dbfb100390efa7d0d4be64ada0210b09ddBrian Wellington * - private3 & private 4 are unused.
a012d6dbfb100390efa7d0d4be64ada0210b09ddBrian Wellington * - private5 is the node.
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))
01dbc4fc00adc933af96e88bfce95c07ef1f3c39Mark Andrews sdbiter->current = ISC_LIST_NEXT(sdbiter->current, link);
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);
b7cd261f2fca2c7138cdc6ae8ee434e9c0031303Brian Wellington return (dns_name_copy(sdbiter->current->name, name, NULL));
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellingtondbiterator_pause(dns_dbiterator_t *iterator) {
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellingtondbiterator_origin(dns_dbiterator_t *iterator, dns_name_t *name) {
b7cd261f2fca2c7138cdc6ae8ee434e9c0031303Brian Wellington return (dns_name_copy(dns_rootname, 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;