db.c revision 7f79448198139145cebc2540188b16b1861b98c5
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister/*
ddad35552931651426ad70912d29d9ab7d2a8d80Automatic Updater * Database API implementation. The interface is defined in lib/dns/db.h.
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews *
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence * dns_db_*() calls on database instances backed by this driver use
ec5347e2c775f027573ce5648b910361aa926c01Automatic Updater * struct sampledb_methods to find appropriate function implementation.
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister *
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister * This example re-uses RBT DB implementation from original BIND and blindly
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence * proxies most of dns_db_*() calls to this underlying RBT DB.
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * See struct sampledb below.
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews *
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * Copyright (C) 2009-2015 Red Hat ; see COPYRIGHT for license
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews */
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews#include <config.h>
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews#include <isc/string.h>
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister#include <dns/db.h>
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉#include <dns/diff.h>
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein#include <dns/enumclass.h>
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein#include <dns/rbt.h>
9c3531d72aeaad6c5f01efe6a1c82023e1379e4dDavid Lawrence#include <dns/rdatalist.h>
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister#include <dns/rdatastruct.h>
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister#include <dns/soa.h>
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence#include <dns/types.h>
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence
364a82f7c25b62967678027043425201a5e5171aBob Halley#include "db.h"
600cbd1fcea3c9cc9706dc1ff8fc0d0034ebdeacTatuya JINMEI 神明達哉#include "instance.h"
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister#include "syncptr.h"
b3e77535185043f089b346166440402d092030c3David Lawrence#include "util.h"
590f840d3484114576d9f8a7f7d73fbe31228888Brian Wellington
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister#define SAMPLEDB_MAGIC ISC_MAGIC('S', 'M', 'D', 'B')
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister#define VALID_SAMPLEDB(sampledb) \
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister ((sampledb) != NULL && (sampledb)->common.impmagic == SAMPLEDB_MAGIC)
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein
2cde028c51055c9fd4837337116cd4fdfe8ff623James Bristerstruct sampledb {
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister dns_db_t common;
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister isc_refcount_t refs;
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister sample_instance_t *inst;
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
72166c5cf59db011cce11e98abe377f5aa6f7052Andreas Gustafsson /*
5475a2d296215b7a93bd89804dc33c36a6de7cb5James Brister * Internal RBT database implementation provided by BIND.
d25dd5b0567f67ecf40b7ed1cb20e0dce7b41c49Brian Wellington * Most dns_db_* calls (find(), createiterator(), etc.)
1c153afce556ff3c687986fb7c4a0b0a7f5e7cd8Mark Andrews * are blindly forwarded to this RBT DB.
08c90261660649ca7d92065f6f13a61ec5a9a86dMark Andrews */
db30f4bdcb66afb7eb1ab0c6882cc70be9a53d79Mark Andrews dns_db_t *rbtdb;
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister};
1f1d36a87b65186d9f89aac7f456ab1fd2a39ef6Andreas Gustafsson
1f1d36a87b65186d9f89aac7f456ab1fd2a39ef6Andreas Gustafssontypedef struct sampledb sampledb_t;
b3e77535185043f089b346166440402d092030c3David Lawrence
1f1d36a87b65186d9f89aac7f456ab1fd2a39ef6Andreas Gustafsson/*
1f1d36a87b65186d9f89aac7f456ab1fd2a39ef6Andreas Gustafsson * Get full DNS name from the node.
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister *
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister * @warning
b3e77535185043f089b346166440402d092030c3David Lawrence * The code silently expects that "node" came from RBTDB and thus
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister * assumption dns_dbnode_t (from RBTDB) == dns_rbtnode_t is correct.
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence *
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister * This should work as long as we use only RBTDB and nothing else.
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence */
f3ca27e9fe307b55e35ea8d7b37351650630e5a3Andreas Gustafssonstatic isc_result_t
1f1d36a87b65186d9f89aac7f456ab1fd2a39ef6Andreas Gustafssonsample_name_fromnode(dns_dbnode_t *node, dns_name_t *name) {
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister dns_rbtnode_t *rbtnode = (dns_rbtnode_t *) node;
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence return (dns_rbt_fullnamefromnode(rbtnode, name));
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister}
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
2cde028c51055c9fd4837337116cd4fdfe8ff623James Bristerstatic void
2cde028c51055c9fd4837337116cd4fdfe8ff623James Bristerattach(dns_db_t *source, dns_db_t **targetp) {
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence sampledb_t *sampledb = (sampledb_t *)source;
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence REQUIRE(VALID_SAMPLEDB(sampledb));
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister isc_refcount_increment(&sampledb->refs, NULL);
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister *targetp = source;
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister}
b3e77535185043f089b346166440402d092030c3David Lawrence
2cde028c51055c9fd4837337116cd4fdfe8ff623James Bristerstatic void
2cde028c51055c9fd4837337116cd4fdfe8ff623James Bristerfree_sampledb(sampledb_t *sampledb) {
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister REQUIRE(VALID_SAMPLEDB(sampledb));
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister dns_db_detach(&sampledb->rbtdb);
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence dns_name_free(&sampledb->common.origin, sampledb->common.mctx);
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister isc_mem_putanddetach(&sampledb->common.mctx, sampledb, sizeof(*sampledb));
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister}
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
2cde028c51055c9fd4837337116cd4fdfe8ff623James Bristerstatic void
2cde028c51055c9fd4837337116cd4fdfe8ff623James Bristerdetach(dns_db_t **dbp) {
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister sampledb_t *sampledb = (sampledb_t *)(*dbp);
b3e77535185043f089b346166440402d092030c3David Lawrence unsigned int refs;
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence REQUIRE(VALID_SAMPLEDB(sampledb));
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister isc_refcount_decrement(&sampledb->refs, &refs);
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister if (refs == 0)
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister free_sampledb(sampledb);
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister *dbp = NULL;
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister}
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister/*
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister * This method should never be called, because DB is "persistent".
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister * See ispersistent() function. It means that database do not need to be
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister * loaded in the usual sense.
1f1d36a87b65186d9f89aac7f456ab1fd2a39ef6Andreas Gustafsson */
1f1d36a87b65186d9f89aac7f456ab1fd2a39ef6Andreas Gustafssonstatic isc_result_t
2cde028c51055c9fd4837337116cd4fdfe8ff623James Bristerbeginload(dns_db_t *db, dns_rdatacallbacks_t *callbacks) {
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister UNUSED(db);
1f1d36a87b65186d9f89aac7f456ab1fd2a39ef6Andreas Gustafsson UNUSED(callbacks);
1f1d36a87b65186d9f89aac7f456ab1fd2a39ef6Andreas Gustafsson
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister fatal_error("current implementation should never call beginload()");
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
b3e77535185043f089b346166440402d092030c3David Lawrence /* Not reached */
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister return (ISC_R_SUCCESS);
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister}
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister/*
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister * This method should never be called, because DB is "persistent".
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister * See ispersistent() function. It means that database do not need to be
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence * loaded in the usual sense.
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister */
2cde028c51055c9fd4837337116cd4fdfe8ff623James Bristerstatic isc_result_t
2cde028c51055c9fd4837337116cd4fdfe8ff623James Bristerendload(dns_db_t *db, dns_rdatacallbacks_t *callbacks) {
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister UNUSED(db);
1f1d36a87b65186d9f89aac7f456ab1fd2a39ef6Andreas Gustafsson UNUSED(callbacks);
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister fatal_error("current implementation should never call endload()");
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister /* Not reached */
f3ca27e9fe307b55e35ea8d7b37351650630e5a3Andreas Gustafsson return (ISC_R_SUCCESS);
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence}
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
2cde028c51055c9fd4837337116cd4fdfe8ff623James Bristerstatic isc_result_t
2cde028c51055c9fd4837337116cd4fdfe8ff623James Bristerserialize(dns_db_t *db, dns_dbversion_t *version, FILE *file) {
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister sampledb_t *sampledb = (sampledb_t *) db;
b3e77535185043f089b346166440402d092030c3David Lawrence
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister REQUIRE(VALID_SAMPLEDB(sampledb));
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister return (dns_db_serialize(sampledb->rbtdb, version, file));
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence}
4844ed026a9b5a91044e76399cee80a6514cbf0dMark Andrews
4844ed026a9b5a91044e76399cee80a6514cbf0dMark Andrewsstatic isc_result_t
4844ed026a9b5a91044e76399cee80a6514cbf0dMark Andrewsdump(dns_db_t *db, dns_dbversion_t *version, const char *filename,
4844ed026a9b5a91044e76399cee80a6514cbf0dMark Andrews dns_masterformat_t masterformat)
4844ed026a9b5a91044e76399cee80a6514cbf0dMark Andrews{
4844ed026a9b5a91044e76399cee80a6514cbf0dMark Andrews
4844ed026a9b5a91044e76399cee80a6514cbf0dMark Andrews UNUSED(db);
4844ed026a9b5a91044e76399cee80a6514cbf0dMark Andrews UNUSED(version);
4844ed026a9b5a91044e76399cee80a6514cbf0dMark Andrews UNUSED(filename);
4844ed026a9b5a91044e76399cee80a6514cbf0dMark Andrews UNUSED(masterformat);
4844ed026a9b5a91044e76399cee80a6514cbf0dMark Andrews
4844ed026a9b5a91044e76399cee80a6514cbf0dMark Andrews fatal_error("current implementation should never call dump()");
4844ed026a9b5a91044e76399cee80a6514cbf0dMark Andrews
db30f4bdcb66afb7eb1ab0c6882cc70be9a53d79Mark Andrews /* Not reached */
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister return (ISC_R_SUCCESS);
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence}
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
2cde028c51055c9fd4837337116cd4fdfe8ff623James Bristerstatic void
2cde028c51055c9fd4837337116cd4fdfe8ff623James Bristercurrentversion(dns_db_t *db, dns_dbversion_t **versionp) {
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister sampledb_t *sampledb = (sampledb_t *)db;
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister REQUIRE(VALID_SAMPLEDB(sampledb));
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister dns_db_currentversion(sampledb->rbtdb, versionp);
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister}
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
2cde028c51055c9fd4837337116cd4fdfe8ff623James Bristerstatic isc_result_t
2cde028c51055c9fd4837337116cd4fdfe8ff623James Bristernewversion(dns_db_t *db, dns_dbversion_t **versionp) {
4844ed026a9b5a91044e76399cee80a6514cbf0dMark Andrews sampledb_t *sampledb = (sampledb_t *)db;
4844ed026a9b5a91044e76399cee80a6514cbf0dMark Andrews
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister REQUIRE(VALID_SAMPLEDB(sampledb));
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister return (dns_db_newversion(sampledb->rbtdb, versionp));
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister}
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
2cde028c51055c9fd4837337116cd4fdfe8ff623James Bristerstatic void
2cde028c51055c9fd4837337116cd4fdfe8ff623James Bristerattachversion(dns_db_t *db, dns_dbversion_t *source,
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister dns_dbversion_t **targetp)
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister{
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister sampledb_t *sampledb = (sampledb_t *)db;
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence REQUIRE(VALID_SAMPLEDB(sampledb));
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister dns_db_attachversion(sampledb->rbtdb, source, targetp);
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister}
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
2cde028c51055c9fd4837337116cd4fdfe8ff623James Bristerstatic void
2cde028c51055c9fd4837337116cd4fdfe8ff623James Bristercloseversion(dns_db_t *db, dns_dbversion_t **versionp, isc_boolean_t commit) {
b3e77535185043f089b346166440402d092030c3David Lawrence sampledb_t *sampledb = (sampledb_t *)db;
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister REQUIRE(VALID_SAMPLEDB(sampledb));
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister dns_db_closeversion(sampledb->rbtdb, versionp, commit);
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister}
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
2cde028c51055c9fd4837337116cd4fdfe8ff623James Bristerstatic isc_result_t
2cde028c51055c9fd4837337116cd4fdfe8ff623James Bristerfindnode(dns_db_t *db, dns_name_t *name, isc_boolean_t create,
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence dns_dbnode_t **nodep)
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister{
b3e77535185043f089b346166440402d092030c3David Lawrence sampledb_t *sampledb = (sampledb_t *) db;
4844ed026a9b5a91044e76399cee80a6514cbf0dMark Andrews
4844ed026a9b5a91044e76399cee80a6514cbf0dMark Andrews REQUIRE(VALID_SAMPLEDB(sampledb));
4844ed026a9b5a91044e76399cee80a6514cbf0dMark Andrews
4844ed026a9b5a91044e76399cee80a6514cbf0dMark Andrews return (dns_db_findnode(sampledb->rbtdb, name, create, nodep));
4844ed026a9b5a91044e76399cee80a6514cbf0dMark Andrews}
4844ed026a9b5a91044e76399cee80a6514cbf0dMark Andrews
4844ed026a9b5a91044e76399cee80a6514cbf0dMark Andrewsstatic isc_result_t
4844ed026a9b5a91044e76399cee80a6514cbf0dMark Andrewsfind(dns_db_t *db, dns_name_t *name, dns_dbversion_t *version,
4844ed026a9b5a91044e76399cee80a6514cbf0dMark Andrews dns_rdatatype_t type, unsigned int options, isc_stdtime_t now,
4844ed026a9b5a91044e76399cee80a6514cbf0dMark Andrews dns_dbnode_t **nodep, dns_name_t *foundname, dns_rdataset_t *rdataset,
4844ed026a9b5a91044e76399cee80a6514cbf0dMark Andrews dns_rdataset_t *sigrdataset)
4844ed026a9b5a91044e76399cee80a6514cbf0dMark Andrews{
4844ed026a9b5a91044e76399cee80a6514cbf0dMark Andrews sampledb_t *sampledb = (sampledb_t *) db;
4844ed026a9b5a91044e76399cee80a6514cbf0dMark Andrews
4844ed026a9b5a91044e76399cee80a6514cbf0dMark Andrews REQUIRE(VALID_SAMPLEDB(sampledb));
4844ed026a9b5a91044e76399cee80a6514cbf0dMark Andrews
4844ed026a9b5a91044e76399cee80a6514cbf0dMark Andrews return (dns_db_find(sampledb->rbtdb, name, version, type,
4844ed026a9b5a91044e76399cee80a6514cbf0dMark Andrews options, now, nodep, foundname,
4844ed026a9b5a91044e76399cee80a6514cbf0dMark Andrews rdataset, sigrdataset));
4844ed026a9b5a91044e76399cee80a6514cbf0dMark Andrews}
db30f4bdcb66afb7eb1ab0c6882cc70be9a53d79Mark Andrews
2cde028c51055c9fd4837337116cd4fdfe8ff623James Bristerstatic isc_result_t
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrencefindzonecut(dns_db_t *db, dns_name_t *name, unsigned int options,
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister isc_stdtime_t now, dns_dbnode_t **nodep, dns_name_t *foundname,
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence dns_rdataset_t *rdataset, dns_rdataset_t *sigrdataset)
f3ca27e9fe307b55e35ea8d7b37351650630e5a3Andreas Gustafsson{
1f1d36a87b65186d9f89aac7f456ab1fd2a39ef6Andreas Gustafsson sampledb_t *sampledb = (sampledb_t *) db;
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence REQUIRE(VALID_SAMPLEDB(sampledb));
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister return (dns_db_findzonecut(sampledb->rbtdb, name, options,
4844ed026a9b5a91044e76399cee80a6514cbf0dMark Andrews now, nodep, foundname, rdataset,
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister sigrdataset));
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister}
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
2cde028c51055c9fd4837337116cd4fdfe8ff623James Bristerstatic void
5475a2d296215b7a93bd89804dc33c36a6de7cb5James Bristerattachnode(dns_db_t *db, dns_dbnode_t *source, dns_dbnode_t **targetp) {
5475a2d296215b7a93bd89804dc33c36a6de7cb5James Brister sampledb_t *sampledb = (sampledb_t *) db;
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister REQUIRE(VALID_SAMPLEDB(sampledb));
600cbd1fcea3c9cc9706dc1ff8fc0d0034ebdeacTatuya JINMEI 神明達哉
7d4a465de03b26bf9f5ef131d03253b8f6afc169Mark Andrews dns_db_attachnode(sampledb->rbtdb, source, targetp);
7d4a465de03b26bf9f5ef131d03253b8f6afc169Mark Andrews
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence}
f3ca27e9fe307b55e35ea8d7b37351650630e5a3Andreas Gustafsson
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrencestatic void
2cde028c51055c9fd4837337116cd4fdfe8ff623James Bristerdetachnode(dns_db_t *db, dns_dbnode_t **targetp) {
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence sampledb_t *sampledb = (sampledb_t *) db;
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence REQUIRE(VALID_SAMPLEDB(sampledb));
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister dns_db_detachnode(sampledb->rbtdb, targetp);
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister}
1f1d36a87b65186d9f89aac7f456ab1fd2a39ef6Andreas Gustafsson
b3e77535185043f089b346166440402d092030c3David Lawrencestatic isc_result_t
2cde028c51055c9fd4837337116cd4fdfe8ff623James Bristerexpirenode(dns_db_t *db, dns_dbnode_t *node, isc_stdtime_t now) {
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister sampledb_t *sampledb = (sampledb_t *) db;
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister REQUIRE(VALID_SAMPLEDB(sampledb));
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence return (dns_db_expirenode(sampledb->rbtdb, node, now));
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister}
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
2cde028c51055c9fd4837337116cd4fdfe8ff623James Bristerstatic void
2cde028c51055c9fd4837337116cd4fdfe8ff623James Bristerprintnode(dns_db_t *db, dns_dbnode_t *node, FILE *out) {
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister sampledb_t *sampledb = (sampledb_t *) db;
1f1d36a87b65186d9f89aac7f456ab1fd2a39ef6Andreas Gustafsson
b3e77535185043f089b346166440402d092030c3David Lawrence REQUIRE(VALID_SAMPLEDB(sampledb));
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence dns_db_printnode(sampledb->rbtdb, node, out);
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister}
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
2cde028c51055c9fd4837337116cd4fdfe8ff623James Bristerstatic isc_result_t
2cde028c51055c9fd4837337116cd4fdfe8ff623James Bristercreateiterator(dns_db_t *db, unsigned int options,
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister dns_dbiterator_t **iteratorp)
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister{
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister sampledb_t *sampledb = (sampledb_t *) db;
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister REQUIRE(VALID_SAMPLEDB(sampledb));
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister return (dns_db_createiterator(sampledb->rbtdb, options, iteratorp));
1f1d36a87b65186d9f89aac7f456ab1fd2a39ef6Andreas Gustafsson}
1f1d36a87b65186d9f89aac7f456ab1fd2a39ef6Andreas Gustafsson
2cde028c51055c9fd4837337116cd4fdfe8ff623James Bristerstatic isc_result_t
2cde028c51055c9fd4837337116cd4fdfe8ff623James Bristerfindrdataset(dns_db_t *db, dns_dbnode_t *node, dns_dbversion_t *version,
1f1d36a87b65186d9f89aac7f456ab1fd2a39ef6Andreas Gustafsson dns_rdatatype_t type, dns_rdatatype_t covers, isc_stdtime_t now,
1f1d36a87b65186d9f89aac7f456ab1fd2a39ef6Andreas Gustafsson dns_rdataset_t *rdataset, dns_rdataset_t *sigrdataset)
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister{
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister sampledb_t *sampledb = (sampledb_t *) db;
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister REQUIRE(VALID_SAMPLEDB(sampledb));
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence return (dns_db_findrdataset(sampledb->rbtdb, node, version, type,
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister covers, now, rdataset, sigrdataset));
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister}
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrencestatic isc_result_t
2cde028c51055c9fd4837337116cd4fdfe8ff623James Bristerallrdatasets(dns_db_t *db, dns_dbnode_t *node, dns_dbversion_t *version,
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister isc_stdtime_t now, dns_rdatasetiter_t **iteratorp)
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister{
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence sampledb_t *sampledb = (sampledb_t *) db;
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister REQUIRE(VALID_SAMPLEDB(sampledb));
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister return (dns_db_allrdatasets(sampledb->rbtdb, node, version,
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence now, iteratorp));
600cbd1fcea3c9cc9706dc1ff8fc0d0034ebdeacTatuya JINMEI 神明達哉}
600cbd1fcea3c9cc9706dc1ff8fc0d0034ebdeacTatuya JINMEI 神明達哉
600cbd1fcea3c9cc9706dc1ff8fc0d0034ebdeacTatuya JINMEI 神明達哉static isc_result_t
600cbd1fcea3c9cc9706dc1ff8fc0d0034ebdeacTatuya JINMEI 神明達哉addrdataset(dns_db_t *db, dns_dbnode_t *node, dns_dbversion_t *version,
600cbd1fcea3c9cc9706dc1ff8fc0d0034ebdeacTatuya JINMEI 神明達哉 isc_stdtime_t now, dns_rdataset_t *rdataset, unsigned int options,
f3ca27e9fe307b55e35ea8d7b37351650630e5a3Andreas Gustafsson dns_rdataset_t *addedrdataset)
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence{
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister sampledb_t *sampledb = (sampledb_t *) db;
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister isc_result_t result;
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister dns_fixedname_t name;
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
b3e77535185043f089b346166440402d092030c3David Lawrence REQUIRE(VALID_SAMPLEDB(sampledb));
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence dns_fixedname_init(&name);
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister CHECK(dns_db_addrdataset(sampledb->rbtdb, node, version, now,
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence rdataset, options, addedrdataset));
b3e77535185043f089b346166440402d092030c3David Lawrence if (rdataset->type == dns_rdatatype_a ||
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence rdataset->type == dns_rdatatype_aaaa) {
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister CHECK(sample_name_fromnode(node, dns_fixedname_name(&name)));
b3e77535185043f089b346166440402d092030c3David Lawrence CHECK(syncptrs(sampledb->inst, dns_fixedname_name(&name),
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence rdataset, DNS_DIFFOP_ADD));
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister }
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
2cde028c51055c9fd4837337116cd4fdfe8ff623James Bristercleanup:
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister return (result);
b3e77535185043f089b346166440402d092030c3David Lawrence}
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
2cde028c51055c9fd4837337116cd4fdfe8ff623James Bristerstatic isc_result_t
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrencesubtractrdataset(dns_db_t *db, dns_dbnode_t *node, dns_dbversion_t *version,
b3e77535185043f089b346166440402d092030c3David Lawrence dns_rdataset_t *rdataset, unsigned int options,
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister dns_rdataset_t *newrdataset)
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister{
b3e77535185043f089b346166440402d092030c3David Lawrence sampledb_t *sampledb = (sampledb_t *) db;
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister isc_result_t result;
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister dns_fixedname_t name;
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister REQUIRE(VALID_SAMPLEDB(sampledb));
5475a2d296215b7a93bd89804dc33c36a6de7cb5James Brister
b3e77535185043f089b346166440402d092030c3David Lawrence dns_fixedname_init(&name);
5475a2d296215b7a93bd89804dc33c36a6de7cb5James Brister result = dns_db_subtractrdataset(sampledb->rbtdb, node, version,
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence rdataset, options, newrdataset);
5475a2d296215b7a93bd89804dc33c36a6de7cb5James Brister if (result != ISC_R_SUCCESS && result != DNS_R_NXRRSET)
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence goto cleanup;
b3e77535185043f089b346166440402d092030c3David Lawrence
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence if (rdataset->type == dns_rdatatype_a ||
5475a2d296215b7a93bd89804dc33c36a6de7cb5James Brister rdataset->type == dns_rdatatype_aaaa) {
b3e77535185043f089b346166440402d092030c3David Lawrence CHECK(sample_name_fromnode(node, dns_fixedname_name(&name)));
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence CHECK(syncptrs(sampledb->inst, dns_fixedname_name(&name),
5475a2d296215b7a93bd89804dc33c36a6de7cb5James Brister rdataset, DNS_DIFFOP_DEL));
5475a2d296215b7a93bd89804dc33c36a6de7cb5James Brister }
5475a2d296215b7a93bd89804dc33c36a6de7cb5James Brister
5475a2d296215b7a93bd89804dc33c36a6de7cb5James Bristercleanup:
b3e77535185043f089b346166440402d092030c3David Lawrence return (result);
5475a2d296215b7a93bd89804dc33c36a6de7cb5James Brister}
5475a2d296215b7a93bd89804dc33c36a6de7cb5James Brister
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence/*
b3e77535185043f089b346166440402d092030c3David Lawrence * deleterdataset() function is not used during DNS update processing so syncptr
5475a2d296215b7a93bd89804dc33c36a6de7cb5James Brister * implementation is left as an exercise to the reader.
5475a2d296215b7a93bd89804dc33c36a6de7cb5James Brister */
5475a2d296215b7a93bd89804dc33c36a6de7cb5James Bristerstatic isc_result_t
5475a2d296215b7a93bd89804dc33c36a6de7cb5James Bristerdeleterdataset(dns_db_t *db, dns_dbnode_t *node, dns_dbversion_t *version,
5475a2d296215b7a93bd89804dc33c36a6de7cb5James Brister dns_rdatatype_t type, dns_rdatatype_t covers)
5475a2d296215b7a93bd89804dc33c36a6de7cb5James Brister{
5475a2d296215b7a93bd89804dc33c36a6de7cb5James Brister sampledb_t *sampledb = (sampledb_t *) db;
5475a2d296215b7a93bd89804dc33c36a6de7cb5James Brister
b3e77535185043f089b346166440402d092030c3David Lawrence REQUIRE(VALID_SAMPLEDB(sampledb));
5475a2d296215b7a93bd89804dc33c36a6de7cb5James Brister
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence return (dns_db_deleterdataset(sampledb->rbtdb, node, version,
5475a2d296215b7a93bd89804dc33c36a6de7cb5James Brister type, covers));
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence}
b3e77535185043f089b346166440402d092030c3David Lawrence
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrencestatic isc_boolean_t
5475a2d296215b7a93bd89804dc33c36a6de7cb5James Bristerissecure(dns_db_t *db) {
b3e77535185043f089b346166440402d092030c3David Lawrence sampledb_t *sampledb = (sampledb_t *) db;
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
5475a2d296215b7a93bd89804dc33c36a6de7cb5James Brister REQUIRE(VALID_SAMPLEDB(sampledb));
5475a2d296215b7a93bd89804dc33c36a6de7cb5James Brister
5475a2d296215b7a93bd89804dc33c36a6de7cb5James Brister return (dns_db_issecure(sampledb->rbtdb));
5475a2d296215b7a93bd89804dc33c36a6de7cb5James Brister}
b3e77535185043f089b346166440402d092030c3David Lawrence
5475a2d296215b7a93bd89804dc33c36a6de7cb5James Bristerstatic unsigned int
5475a2d296215b7a93bd89804dc33c36a6de7cb5James Bristernodecount(dns_db_t *db) {
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence sampledb_t *sampledb = (sampledb_t *) db;
b3e77535185043f089b346166440402d092030c3David Lawrence
5475a2d296215b7a93bd89804dc33c36a6de7cb5James Brister REQUIRE(VALID_SAMPLEDB(sampledb));
5475a2d296215b7a93bd89804dc33c36a6de7cb5James Brister
b3e77535185043f089b346166440402d092030c3David Lawrence return (dns_db_nodecount(sampledb->rbtdb));
5475a2d296215b7a93bd89804dc33c36a6de7cb5James Brister}
5475a2d296215b7a93bd89804dc33c36a6de7cb5James Brister
5475a2d296215b7a93bd89804dc33c36a6de7cb5James Brister/*
d25dd5b0567f67ecf40b7ed1cb20e0dce7b41c49Brian Wellington * The database does not need to be loaded from disk or written to disk.
d25dd5b0567f67ecf40b7ed1cb20e0dce7b41c49Brian Wellington * Always return ISC_TRUE.
d25dd5b0567f67ecf40b7ed1cb20e0dce7b41c49Brian Wellington */
d25dd5b0567f67ecf40b7ed1cb20e0dce7b41c49Brian Wellingtonstatic isc_boolean_t
d25dd5b0567f67ecf40b7ed1cb20e0dce7b41c49Brian Wellingtonispersistent(dns_db_t *db) {
d25dd5b0567f67ecf40b7ed1cb20e0dce7b41c49Brian Wellington UNUSED(db);
d25dd5b0567f67ecf40b7ed1cb20e0dce7b41c49Brian Wellington
d25dd5b0567f67ecf40b7ed1cb20e0dce7b41c49Brian Wellington return (ISC_TRUE);
d25dd5b0567f67ecf40b7ed1cb20e0dce7b41c49Brian Wellington}
d25dd5b0567f67ecf40b7ed1cb20e0dce7b41c49Brian Wellington
d25dd5b0567f67ecf40b7ed1cb20e0dce7b41c49Brian Wellingtonstatic void
d25dd5b0567f67ecf40b7ed1cb20e0dce7b41c49Brian Wellingtonovermem(dns_db_t *db, isc_boolean_t overmem) {
d25dd5b0567f67ecf40b7ed1cb20e0dce7b41c49Brian Wellington sampledb_t *sampledb = (sampledb_t *) db;
d25dd5b0567f67ecf40b7ed1cb20e0dce7b41c49Brian Wellington
d25dd5b0567f67ecf40b7ed1cb20e0dce7b41c49Brian Wellington REQUIRE(VALID_SAMPLEDB(sampledb));
d25dd5b0567f67ecf40b7ed1cb20e0dce7b41c49Brian Wellington
d25dd5b0567f67ecf40b7ed1cb20e0dce7b41c49Brian Wellington dns_db_overmem(sampledb->rbtdb, overmem);
d25dd5b0567f67ecf40b7ed1cb20e0dce7b41c49Brian Wellington}
d25dd5b0567f67ecf40b7ed1cb20e0dce7b41c49Brian Wellington
d25dd5b0567f67ecf40b7ed1cb20e0dce7b41c49Brian Wellingtonstatic void
d25dd5b0567f67ecf40b7ed1cb20e0dce7b41c49Brian Wellingtonsettask(dns_db_t *db, isc_task_t *task) {
d25dd5b0567f67ecf40b7ed1cb20e0dce7b41c49Brian Wellington sampledb_t *sampledb = (sampledb_t *) db;
d25dd5b0567f67ecf40b7ed1cb20e0dce7b41c49Brian Wellington
d25dd5b0567f67ecf40b7ed1cb20e0dce7b41c49Brian Wellington REQUIRE(VALID_SAMPLEDB(sampledb));
d25dd5b0567f67ecf40b7ed1cb20e0dce7b41c49Brian Wellington
d25dd5b0567f67ecf40b7ed1cb20e0dce7b41c49Brian Wellington dns_db_settask(sampledb->rbtdb, task);
db30f4bdcb66afb7eb1ab0c6882cc70be9a53d79Mark Andrews}
db30f4bdcb66afb7eb1ab0c6882cc70be9a53d79Mark Andrews
db30f4bdcb66afb7eb1ab0c6882cc70be9a53d79Mark Andrewsstatic isc_result_t
db30f4bdcb66afb7eb1ab0c6882cc70be9a53d79Mark Andrewsgetoriginnode(dns_db_t *db, dns_dbnode_t **nodep) {
db30f4bdcb66afb7eb1ab0c6882cc70be9a53d79Mark Andrews sampledb_t *sampledb = (sampledb_t *) db;
db30f4bdcb66afb7eb1ab0c6882cc70be9a53d79Mark Andrews
db30f4bdcb66afb7eb1ab0c6882cc70be9a53d79Mark Andrews REQUIRE(VALID_SAMPLEDB(sampledb));
db30f4bdcb66afb7eb1ab0c6882cc70be9a53d79Mark Andrews
db30f4bdcb66afb7eb1ab0c6882cc70be9a53d79Mark Andrews return (dns_db_getoriginnode(sampledb->rbtdb, nodep));
db30f4bdcb66afb7eb1ab0c6882cc70be9a53d79Mark Andrews}
db30f4bdcb66afb7eb1ab0c6882cc70be9a53d79Mark Andrews
db30f4bdcb66afb7eb1ab0c6882cc70be9a53d79Mark Andrewsstatic void
db30f4bdcb66afb7eb1ab0c6882cc70be9a53d79Mark Andrewstransfernode(dns_db_t *db, dns_dbnode_t **sourcep, dns_dbnode_t **targetp) {
db30f4bdcb66afb7eb1ab0c6882cc70be9a53d79Mark Andrews sampledb_t *sampledb = (sampledb_t *) db;
db30f4bdcb66afb7eb1ab0c6882cc70be9a53d79Mark Andrews
db30f4bdcb66afb7eb1ab0c6882cc70be9a53d79Mark Andrews REQUIRE(VALID_SAMPLEDB(sampledb));
db30f4bdcb66afb7eb1ab0c6882cc70be9a53d79Mark Andrews
db30f4bdcb66afb7eb1ab0c6882cc70be9a53d79Mark Andrews dns_db_transfernode(sampledb->rbtdb, sourcep, targetp);
db30f4bdcb66afb7eb1ab0c6882cc70be9a53d79Mark Andrews
db30f4bdcb66afb7eb1ab0c6882cc70be9a53d79Mark Andrews}
db30f4bdcb66afb7eb1ab0c6882cc70be9a53d79Mark Andrews
db30f4bdcb66afb7eb1ab0c6882cc70be9a53d79Mark Andrewsstatic isc_result_t
db30f4bdcb66afb7eb1ab0c6882cc70be9a53d79Mark Andrewsgetnsec3parameters(dns_db_t *db, dns_dbversion_t *version,
db30f4bdcb66afb7eb1ab0c6882cc70be9a53d79Mark Andrews dns_hash_t *hash, isc_uint8_t *flags,
db30f4bdcb66afb7eb1ab0c6882cc70be9a53d79Mark Andrews isc_uint16_t *iterations,
db30f4bdcb66afb7eb1ab0c6882cc70be9a53d79Mark Andrews unsigned char *salt, size_t *salt_length)
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister{
3e42bdfdc901b6b921b02028bd51ca2af8e84adcMark Andrews sampledb_t *sampledb = (sampledb_t *) db;
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence REQUIRE(VALID_SAMPLEDB(sampledb));
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence return (dns_db_getnsec3parameters(sampledb->rbtdb, version,
b3e77535185043f089b346166440402d092030c3David Lawrence hash, flags, iterations,
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence salt, salt_length));
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
b3e77535185043f089b346166440402d092030c3David Lawrence}
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
2cde028c51055c9fd4837337116cd4fdfe8ff623James Bristerstatic isc_result_t
2cde028c51055c9fd4837337116cd4fdfe8ff623James Bristerfindnsec3node(dns_db_t *db, dns_name_t *name, isc_boolean_t create,
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister dns_dbnode_t **nodep)
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister{
3e42bdfdc901b6b921b02028bd51ca2af8e84adcMark Andrews sampledb_t *sampledb = (sampledb_t *) db;
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister REQUIRE(VALID_SAMPLEDB(sampledb));
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
b3e77535185043f089b346166440402d092030c3David Lawrence return (dns_db_findnsec3node(sampledb->rbtdb, name, create, nodep));
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister}
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
2cde028c51055c9fd4837337116cd4fdfe8ff623James Bristerstatic isc_result_t
2cde028c51055c9fd4837337116cd4fdfe8ff623James Bristersetsigningtime(dns_db_t *db, dns_rdataset_t *rdataset, isc_stdtime_t resign) {
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister sampledb_t *sampledb = (sampledb_t *) db;
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister REQUIRE(VALID_SAMPLEDB(sampledb));
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
b3e77535185043f089b346166440402d092030c3David Lawrence return (dns_db_setsigningtime(sampledb->rbtdb, rdataset, resign));
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister}
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
2cde028c51055c9fd4837337116cd4fdfe8ff623James Bristerstatic isc_result_t
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrencegetsigningtime(dns_db_t *db, dns_rdataset_t *rdataset, dns_name_t *name) {
b3e77535185043f089b346166440402d092030c3David Lawrence sampledb_t *sampledb = (sampledb_t *) db;
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence REQUIRE(VALID_SAMPLEDB(sampledb));
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
b3e77535185043f089b346166440402d092030c3David Lawrence return (dns_db_getsigningtime(sampledb->rbtdb, rdataset, name));
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence}
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
2cde028c51055c9fd4837337116cd4fdfe8ff623James Bristerstatic void
2cde028c51055c9fd4837337116cd4fdfe8ff623James Bristerresigned(dns_db_t *db, dns_rdataset_t *rdataset, dns_dbversion_t *version) {
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister sampledb_t *sampledb = (sampledb_t *) db;
b3e77535185043f089b346166440402d092030c3David Lawrence
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister REQUIRE(VALID_SAMPLEDB(sampledb));
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence dns_db_resigned(sampledb->rbtdb, rdataset, version);
b3e77535185043f089b346166440402d092030c3David Lawrence}
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
2cde028c51055c9fd4837337116cd4fdfe8ff623James Bristerstatic isc_boolean_t
2cde028c51055c9fd4837337116cd4fdfe8ff623James Bristerisdnssec(dns_db_t *db) {
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister sampledb_t *sampledb = (sampledb_t *) db;
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister REQUIRE(VALID_SAMPLEDB(sampledb));
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister return (dns_db_isdnssec(sampledb->rbtdb));
b3e77535185043f089b346166440402d092030c3David Lawrence}
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
2cde028c51055c9fd4837337116cd4fdfe8ff623James Bristerstatic dns_stats_t *
2cde028c51055c9fd4837337116cd4fdfe8ff623James Bristergetrrsetstats(dns_db_t *db) {
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister sampledb_t *sampledb = (sampledb_t *) db;
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister REQUIRE(VALID_SAMPLEDB(sampledb));
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister return (dns_db_getrrsetstats(sampledb->rbtdb));
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister}
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
b3e77535185043f089b346166440402d092030c3David Lawrencestatic void
2cde028c51055c9fd4837337116cd4fdfe8ff623James Bristerrpz_attach(dns_db_t *db, dns_rpz_zones_t *rpzs, dns_rpz_num_t rpz_num) {
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister sampledb_t *sampledb = (sampledb_t *) db;
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister REQUIRE(VALID_SAMPLEDB(sampledb));
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister dns_db_rpz_attach(sampledb->rbtdb, rpzs, rpz_num);
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister}
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
2cde028c51055c9fd4837337116cd4fdfe8ff623James Bristerstatic isc_result_t
2cde028c51055c9fd4837337116cd4fdfe8ff623James Bristerrpz_ready(dns_db_t *db) {
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence sampledb_t *sampledb = (sampledb_t *) db;
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister REQUIRE(VALID_SAMPLEDB(sampledb));
590f840d3484114576d9f8a7f7d73fbe31228888Brian Wellington
590f840d3484114576d9f8a7f7d73fbe31228888Brian Wellington return (dns_db_rpz_ready(sampledb->rbtdb));
590f840d3484114576d9f8a7f7d73fbe31228888Brian Wellington}
590f840d3484114576d9f8a7f7d73fbe31228888Brian Wellington
590f840d3484114576d9f8a7f7d73fbe31228888Brian Wellingtonstatic isc_result_t
590f840d3484114576d9f8a7f7d73fbe31228888Brian Wellingtonfindnodeext(dns_db_t *db, dns_name_t *name,
590f840d3484114576d9f8a7f7d73fbe31228888Brian Wellington isc_boolean_t create, dns_clientinfomethods_t *methods,
590f840d3484114576d9f8a7f7d73fbe31228888Brian Wellington dns_clientinfo_t *clientinfo, dns_dbnode_t **nodep)
15c5b240a6122795212c1aff03634e7156951e91Brian Wellington{
590f840d3484114576d9f8a7f7d73fbe31228888Brian Wellington sampledb_t *sampledb = (sampledb_t *) db;
590f840d3484114576d9f8a7f7d73fbe31228888Brian Wellington
590f840d3484114576d9f8a7f7d73fbe31228888Brian Wellington REQUIRE(VALID_SAMPLEDB(sampledb));
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉
590f840d3484114576d9f8a7f7d73fbe31228888Brian Wellington return (dns_db_findnodeext(sampledb->rbtdb, name, create,
590f840d3484114576d9f8a7f7d73fbe31228888Brian Wellington methods, clientinfo, nodep));
590f840d3484114576d9f8a7f7d73fbe31228888Brian Wellington}
590f840d3484114576d9f8a7f7d73fbe31228888Brian Wellington
590f840d3484114576d9f8a7f7d73fbe31228888Brian Wellingtonstatic isc_result_t
590f840d3484114576d9f8a7f7d73fbe31228888Brian Wellingtonfindext(dns_db_t *db, dns_name_t *name, dns_dbversion_t *version,
590f840d3484114576d9f8a7f7d73fbe31228888Brian Wellington dns_rdatatype_t type, unsigned int options, isc_stdtime_t now,
590f840d3484114576d9f8a7f7d73fbe31228888Brian Wellington dns_dbnode_t **nodep, dns_name_t *foundname,
590f840d3484114576d9f8a7f7d73fbe31228888Brian Wellington dns_clientinfomethods_t *methods, dns_clientinfo_t *clientinfo,
590f840d3484114576d9f8a7f7d73fbe31228888Brian Wellington dns_rdataset_t *rdataset, dns_rdataset_t *sigrdataset)
590f840d3484114576d9f8a7f7d73fbe31228888Brian Wellington{
590f840d3484114576d9f8a7f7d73fbe31228888Brian Wellington sampledb_t *sampledb = (sampledb_t *) db;
590f840d3484114576d9f8a7f7d73fbe31228888Brian Wellington
590f840d3484114576d9f8a7f7d73fbe31228888Brian Wellington REQUIRE(VALID_SAMPLEDB(sampledb));
590f840d3484114576d9f8a7f7d73fbe31228888Brian Wellington
590f840d3484114576d9f8a7f7d73fbe31228888Brian Wellington return (dns_db_findext(sampledb->rbtdb, name, version, type,
590f840d3484114576d9f8a7f7d73fbe31228888Brian Wellington options, now, nodep, foundname, methods,
590f840d3484114576d9f8a7f7d73fbe31228888Brian Wellington clientinfo, rdataset, sigrdataset));
590f840d3484114576d9f8a7f7d73fbe31228888Brian Wellington}
590f840d3484114576d9f8a7f7d73fbe31228888Brian Wellington
600cbd1fcea3c9cc9706dc1ff8fc0d0034ebdeacTatuya JINMEI 神明達哉static isc_result_t
600cbd1fcea3c9cc9706dc1ff8fc0d0034ebdeacTatuya JINMEI 神明達哉setcachestats(dns_db_t *db, isc_stats_t *stats) {
45e1bd63587102c3bb361eaca42ee7b714fb3542Mark Andrews sampledb_t *sampledb = (sampledb_t *) db;
45e1bd63587102c3bb361eaca42ee7b714fb3542Mark Andrews
45e1bd63587102c3bb361eaca42ee7b714fb3542Mark Andrews REQUIRE(VALID_SAMPLEDB(sampledb));
600cbd1fcea3c9cc9706dc1ff8fc0d0034ebdeacTatuya JINMEI 神明達哉
600cbd1fcea3c9cc9706dc1ff8fc0d0034ebdeacTatuya JINMEI 神明達哉 return (dns_db_setcachestats(sampledb->rbtdb, stats));
600cbd1fcea3c9cc9706dc1ff8fc0d0034ebdeacTatuya JINMEI 神明達哉}
600cbd1fcea3c9cc9706dc1ff8fc0d0034ebdeacTatuya JINMEI 神明達哉
600cbd1fcea3c9cc9706dc1ff8fc0d0034ebdeacTatuya JINMEI 神明達哉static size_t
600cbd1fcea3c9cc9706dc1ff8fc0d0034ebdeacTatuya JINMEI 神明達哉hashsize(dns_db_t *db) {
600cbd1fcea3c9cc9706dc1ff8fc0d0034ebdeacTatuya JINMEI 神明達哉 sampledb_t *sampledb = (sampledb_t *) db;
600cbd1fcea3c9cc9706dc1ff8fc0d0034ebdeacTatuya JINMEI 神明達哉
600cbd1fcea3c9cc9706dc1ff8fc0d0034ebdeacTatuya JINMEI 神明達哉 REQUIRE(VALID_SAMPLEDB(sampledb));
db30f4bdcb66afb7eb1ab0c6882cc70be9a53d79Mark Andrews
600cbd1fcea3c9cc9706dc1ff8fc0d0034ebdeacTatuya JINMEI 神明達哉 return (dns_db_hashsize(sampledb->rbtdb));
600cbd1fcea3c9cc9706dc1ff8fc0d0034ebdeacTatuya JINMEI 神明達哉}
600cbd1fcea3c9cc9706dc1ff8fc0d0034ebdeacTatuya JINMEI 神明達哉
600cbd1fcea3c9cc9706dc1ff8fc0d0034ebdeacTatuya JINMEI 神明達哉/*
600cbd1fcea3c9cc9706dc1ff8fc0d0034ebdeacTatuya JINMEI 神明達哉 * DB interface definition. Database driver uses this structure to
600cbd1fcea3c9cc9706dc1ff8fc0d0034ebdeacTatuya JINMEI 神明達哉 * determine which implementation of dns_db_*() function to call.
600cbd1fcea3c9cc9706dc1ff8fc0d0034ebdeacTatuya JINMEI 神明達哉 */
600cbd1fcea3c9cc9706dc1ff8fc0d0034ebdeacTatuya JINMEI 神明達哉static dns_dbmethods_t sampledb_methods = {
600cbd1fcea3c9cc9706dc1ff8fc0d0034ebdeacTatuya JINMEI 神明達哉 attach,
600cbd1fcea3c9cc9706dc1ff8fc0d0034ebdeacTatuya JINMEI 神明達哉 detach,
600cbd1fcea3c9cc9706dc1ff8fc0d0034ebdeacTatuya JINMEI 神明達哉 beginload,
600cbd1fcea3c9cc9706dc1ff8fc0d0034ebdeacTatuya JINMEI 神明達哉 endload,
600cbd1fcea3c9cc9706dc1ff8fc0d0034ebdeacTatuya JINMEI 神明達哉 serialize,
600cbd1fcea3c9cc9706dc1ff8fc0d0034ebdeacTatuya JINMEI 神明達哉 dump,
600cbd1fcea3c9cc9706dc1ff8fc0d0034ebdeacTatuya JINMEI 神明達哉 currentversion,
600cbd1fcea3c9cc9706dc1ff8fc0d0034ebdeacTatuya JINMEI 神明達哉 newversion,
600cbd1fcea3c9cc9706dc1ff8fc0d0034ebdeacTatuya JINMEI 神明達哉 attachversion,
600cbd1fcea3c9cc9706dc1ff8fc0d0034ebdeacTatuya JINMEI 神明達哉 closeversion,
1c153afce556ff3c687986fb7c4a0b0a7f5e7cd8Mark Andrews findnode,
7d4a465de03b26bf9f5ef131d03253b8f6afc169Mark Andrews find,
45e1bd63587102c3bb361eaca42ee7b714fb3542Mark Andrews findzonecut,
45e1bd63587102c3bb361eaca42ee7b714fb3542Mark Andrews attachnode,
45e1bd63587102c3bb361eaca42ee7b714fb3542Mark Andrews detachnode,
7d4a465de03b26bf9f5ef131d03253b8f6afc169Mark Andrews expirenode,
7d4a465de03b26bf9f5ef131d03253b8f6afc169Mark Andrews printnode,
7d4a465de03b26bf9f5ef131d03253b8f6afc169Mark Andrews createiterator,
7d4a465de03b26bf9f5ef131d03253b8f6afc169Mark Andrews findrdataset,
7d4a465de03b26bf9f5ef131d03253b8f6afc169Mark Andrews allrdatasets,
7d4a465de03b26bf9f5ef131d03253b8f6afc169Mark Andrews addrdataset,
7d4a465de03b26bf9f5ef131d03253b8f6afc169Mark Andrews subtractrdataset,
7d4a465de03b26bf9f5ef131d03253b8f6afc169Mark Andrews deleterdataset,
7d4a465de03b26bf9f5ef131d03253b8f6afc169Mark Andrews issecure,
db30f4bdcb66afb7eb1ab0c6882cc70be9a53d79Mark Andrews nodecount,
7d4a465de03b26bf9f5ef131d03253b8f6afc169Mark Andrews ispersistent,
7d4a465de03b26bf9f5ef131d03253b8f6afc169Mark Andrews overmem,
7d4a465de03b26bf9f5ef131d03253b8f6afc169Mark Andrews settask,
7d4a465de03b26bf9f5ef131d03253b8f6afc169Mark Andrews getoriginnode,
7d4a465de03b26bf9f5ef131d03253b8f6afc169Mark Andrews transfernode,
7d4a465de03b26bf9f5ef131d03253b8f6afc169Mark Andrews getnsec3parameters,
7d4a465de03b26bf9f5ef131d03253b8f6afc169Mark Andrews findnsec3node,
7d4a465de03b26bf9f5ef131d03253b8f6afc169Mark Andrews setsigningtime,
7d4a465de03b26bf9f5ef131d03253b8f6afc169Mark Andrews getsigningtime,
7d4a465de03b26bf9f5ef131d03253b8f6afc169Mark Andrews resigned,
7d4a465de03b26bf9f5ef131d03253b8f6afc169Mark Andrews isdnssec,
7d4a465de03b26bf9f5ef131d03253b8f6afc169Mark Andrews getrrsetstats,
7d4a465de03b26bf9f5ef131d03253b8f6afc169Mark Andrews rpz_attach,
7d4a465de03b26bf9f5ef131d03253b8f6afc169Mark Andrews rpz_ready,
7d4a465de03b26bf9f5ef131d03253b8f6afc169Mark Andrews findnodeext,
7d4a465de03b26bf9f5ef131d03253b8f6afc169Mark Andrews findext,
7d4a465de03b26bf9f5ef131d03253b8f6afc169Mark Andrews setcachestats,
7d4a465de03b26bf9f5ef131d03253b8f6afc169Mark Andrews hashsize
7d4a465de03b26bf9f5ef131d03253b8f6afc169Mark Andrews};
7d4a465de03b26bf9f5ef131d03253b8f6afc169Mark Andrews
45e1bd63587102c3bb361eaca42ee7b714fb3542Mark Andrews/* Auxiliary driver functions. */
7d4a465de03b26bf9f5ef131d03253b8f6afc169Mark Andrews
7d4a465de03b26bf9f5ef131d03253b8f6afc169Mark Andrews/*
7d4a465de03b26bf9f5ef131d03253b8f6afc169Mark Andrews * Auxiliary functions add_*() create minimal database which can be loaded.
7d4a465de03b26bf9f5ef131d03253b8f6afc169Mark Andrews * This is necessary because this driver create empty 'fake' zone which
7d4a465de03b26bf9f5ef131d03253b8f6afc169Mark Andrews * is not loaded from disk so there is no way for user to supply SOA, NS and A
7d4a465de03b26bf9f5ef131d03253b8f6afc169Mark Andrews * records.
7d4a465de03b26bf9f5ef131d03253b8f6afc169Mark Andrews *
7d4a465de03b26bf9f5ef131d03253b8f6afc169Mark Andrews * Following functions were copied from BIND 9.10.2rc1 named/server.c,
7d4a465de03b26bf9f5ef131d03253b8f6afc169Mark Andrews * credit goes to ISC.
db30f4bdcb66afb7eb1ab0c6882cc70be9a53d79Mark Andrews */
7d4a465de03b26bf9f5ef131d03253b8f6afc169Mark Andrewsstatic isc_result_t
7d4a465de03b26bf9f5ef131d03253b8f6afc169Mark Andrewsadd_soa(dns_db_t *db, dns_dbversion_t *version, dns_name_t *name,
7d4a465de03b26bf9f5ef131d03253b8f6afc169Mark Andrews dns_name_t *origin, dns_name_t *contact)
7d4a465de03b26bf9f5ef131d03253b8f6afc169Mark Andrews{
7d4a465de03b26bf9f5ef131d03253b8f6afc169Mark Andrews dns_dbnode_t *node = NULL;
7d4a465de03b26bf9f5ef131d03253b8f6afc169Mark Andrews dns_rdata_t rdata = DNS_RDATA_INIT;
7d4a465de03b26bf9f5ef131d03253b8f6afc169Mark Andrews dns_rdatalist_t rdatalist;
7d4a465de03b26bf9f5ef131d03253b8f6afc169Mark Andrews dns_rdataset_t rdataset;
7d4a465de03b26bf9f5ef131d03253b8f6afc169Mark Andrews isc_result_t result;
7d4a465de03b26bf9f5ef131d03253b8f6afc169Mark Andrews unsigned char buf[DNS_SOA_BUFFERSIZE];
7d4a465de03b26bf9f5ef131d03253b8f6afc169Mark Andrews
7d4a465de03b26bf9f5ef131d03253b8f6afc169Mark Andrews dns_rdataset_init(&rdataset);
7d4a465de03b26bf9f5ef131d03253b8f6afc169Mark Andrews dns_rdatalist_init(&rdatalist);
7d4a465de03b26bf9f5ef131d03253b8f6afc169Mark Andrews CHECK(dns_soa_buildrdata(origin, contact, dns_db_class(db),
7d4a465de03b26bf9f5ef131d03253b8f6afc169Mark Andrews 0, 28800, 7200, 604800, 86400, buf, &rdata));
7d4a465de03b26bf9f5ef131d03253b8f6afc169Mark Andrews rdatalist.type = rdata.type;
7d4a465de03b26bf9f5ef131d03253b8f6afc169Mark Andrews rdatalist.covers = 0;
7d4a465de03b26bf9f5ef131d03253b8f6afc169Mark Andrews rdatalist.rdclass = rdata.rdclass;
7d4a465de03b26bf9f5ef131d03253b8f6afc169Mark Andrews rdatalist.ttl = 86400;
1c153afce556ff3c687986fb7c4a0b0a7f5e7cd8Mark Andrews ISC_LIST_APPEND(rdatalist.rdata, &rdata, link);
1c153afce556ff3c687986fb7c4a0b0a7f5e7cd8Mark Andrews CHECK(dns_rdatalist_tordataset(&rdatalist, &rdataset));
1c153afce556ff3c687986fb7c4a0b0a7f5e7cd8Mark Andrews CHECK(dns_db_findnode(db, name, ISC_TRUE, &node));
1c153afce556ff3c687986fb7c4a0b0a7f5e7cd8Mark Andrews CHECK(dns_db_addrdataset(db, node, version, 0, &rdataset, 0, NULL));
1c153afce556ff3c687986fb7c4a0b0a7f5e7cd8Mark Andrews cleanup:
1c153afce556ff3c687986fb7c4a0b0a7f5e7cd8Mark Andrews if (node != NULL)
1c153afce556ff3c687986fb7c4a0b0a7f5e7cd8Mark Andrews dns_db_detachnode(db, &node);
1c153afce556ff3c687986fb7c4a0b0a7f5e7cd8Mark Andrews return (result);
1c153afce556ff3c687986fb7c4a0b0a7f5e7cd8Mark Andrews}
1c153afce556ff3c687986fb7c4a0b0a7f5e7cd8Mark Andrews
1c153afce556ff3c687986fb7c4a0b0a7f5e7cd8Mark Andrews
1c153afce556ff3c687986fb7c4a0b0a7f5e7cd8Mark Andrewsstatic isc_result_t
1c153afce556ff3c687986fb7c4a0b0a7f5e7cd8Mark Andrewsadd_ns(dns_db_t *db, dns_dbversion_t *version, dns_name_t *name,
1c153afce556ff3c687986fb7c4a0b0a7f5e7cd8Mark Andrews dns_name_t *nsname)
1c153afce556ff3c687986fb7c4a0b0a7f5e7cd8Mark Andrews{
1c153afce556ff3c687986fb7c4a0b0a7f5e7cd8Mark Andrews dns_dbnode_t *node = NULL;
1c153afce556ff3c687986fb7c4a0b0a7f5e7cd8Mark Andrews dns_rdata_ns_t ns;
1c153afce556ff3c687986fb7c4a0b0a7f5e7cd8Mark Andrews dns_rdata_t rdata = DNS_RDATA_INIT;
1c153afce556ff3c687986fb7c4a0b0a7f5e7cd8Mark Andrews dns_rdatalist_t rdatalist;
1c153afce556ff3c687986fb7c4a0b0a7f5e7cd8Mark Andrews dns_rdataset_t rdataset;
1c153afce556ff3c687986fb7c4a0b0a7f5e7cd8Mark Andrews isc_result_t result;
db30f4bdcb66afb7eb1ab0c6882cc70be9a53d79Mark Andrews isc_buffer_t b;
db30f4bdcb66afb7eb1ab0c6882cc70be9a53d79Mark Andrews unsigned char buf[DNS_NAME_MAXWIRE];
db30f4bdcb66afb7eb1ab0c6882cc70be9a53d79Mark Andrews
db30f4bdcb66afb7eb1ab0c6882cc70be9a53d79Mark Andrews isc_buffer_init(&b, buf, sizeof(buf));
db30f4bdcb66afb7eb1ab0c6882cc70be9a53d79Mark Andrews
1c153afce556ff3c687986fb7c4a0b0a7f5e7cd8Mark Andrews dns_rdataset_init(&rdataset);
08c90261660649ca7d92065f6f13a61ec5a9a86dMark Andrews dns_rdatalist_init(&rdatalist);
08c90261660649ca7d92065f6f13a61ec5a9a86dMark Andrews ns.common.rdtype = dns_rdatatype_ns;
08c90261660649ca7d92065f6f13a61ec5a9a86dMark Andrews ns.common.rdclass = dns_db_class(db);
08c90261660649ca7d92065f6f13a61ec5a9a86dMark Andrews ns.mctx = NULL;
08c90261660649ca7d92065f6f13a61ec5a9a86dMark Andrews dns_name_init(&ns.name, NULL);
08c90261660649ca7d92065f6f13a61ec5a9a86dMark Andrews dns_name_clone(nsname, &ns.name);
08c90261660649ca7d92065f6f13a61ec5a9a86dMark Andrews CHECK(dns_rdata_fromstruct(&rdata, dns_db_class(db), dns_rdatatype_ns,
08c90261660649ca7d92065f6f13a61ec5a9a86dMark Andrews &ns, &b));
08c90261660649ca7d92065f6f13a61ec5a9a86dMark Andrews rdatalist.type = rdata.type;
08c90261660649ca7d92065f6f13a61ec5a9a86dMark Andrews rdatalist.covers = 0;
08c90261660649ca7d92065f6f13a61ec5a9a86dMark Andrews rdatalist.rdclass = rdata.rdclass;
08c90261660649ca7d92065f6f13a61ec5a9a86dMark Andrews rdatalist.ttl = 86400;
08c90261660649ca7d92065f6f13a61ec5a9a86dMark Andrews ISC_LIST_APPEND(rdatalist.rdata, &rdata, link);
08c90261660649ca7d92065f6f13a61ec5a9a86dMark Andrews CHECK(dns_rdatalist_tordataset(&rdatalist, &rdataset));
08c90261660649ca7d92065f6f13a61ec5a9a86dMark Andrews CHECK(dns_db_findnode(db, name, ISC_TRUE, &node));
08c90261660649ca7d92065f6f13a61ec5a9a86dMark Andrews CHECK(dns_db_addrdataset(db, node, version, 0, &rdataset, 0, NULL));
08c90261660649ca7d92065f6f13a61ec5a9a86dMark Andrews cleanup:
08c90261660649ca7d92065f6f13a61ec5a9a86dMark Andrews if (node != NULL)
08c90261660649ca7d92065f6f13a61ec5a9a86dMark Andrews dns_db_detachnode(db, &node);
08c90261660649ca7d92065f6f13a61ec5a9a86dMark Andrews return (result);
08c90261660649ca7d92065f6f13a61ec5a9a86dMark Andrews}
08c90261660649ca7d92065f6f13a61ec5a9a86dMark Andrews
db30f4bdcb66afb7eb1ab0c6882cc70be9a53d79Mark Andrewsstatic isc_result_t
db30f4bdcb66afb7eb1ab0c6882cc70be9a53d79Mark Andrewsadd_a(dns_db_t *db, dns_dbversion_t *version, dns_name_t *name,
db30f4bdcb66afb7eb1ab0c6882cc70be9a53d79Mark Andrews struct in_addr addr)
db30f4bdcb66afb7eb1ab0c6882cc70be9a53d79Mark Andrews{
db30f4bdcb66afb7eb1ab0c6882cc70be9a53d79Mark Andrews dns_dbnode_t *node = NULL;
08c90261660649ca7d92065f6f13a61ec5a9a86dMark Andrews dns_rdata_in_a_t a;
dns_rdata_t rdata = DNS_RDATA_INIT;
dns_rdatalist_t rdatalist;
dns_rdataset_t rdataset;
isc_result_t result;
isc_buffer_t b;
unsigned char buf[DNS_NAME_MAXWIRE];
isc_buffer_init(&b, buf, sizeof(buf));
dns_rdataset_init(&rdataset);
dns_rdatalist_init(&rdatalist);
a.common.rdtype = dns_rdatatype_a;
a.common.rdclass = dns_db_class(db);
a.in_addr = addr;
CHECK(dns_rdata_fromstruct(&rdata, dns_db_class(db), dns_rdatatype_a,
&a, &b));
rdatalist.type = rdata.type;
rdatalist.covers = 0;
rdatalist.rdclass = rdata.rdclass;
rdatalist.ttl = 86400;
ISC_LIST_APPEND(rdatalist.rdata, &rdata, link);
CHECK(dns_rdatalist_tordataset(&rdatalist, &rdataset));
CHECK(dns_db_findnode(db, name, ISC_TRUE, &node));
CHECK(dns_db_addrdataset(db, node, version, 0, &rdataset, 0, NULL));
cleanup:
if (node != NULL)
dns_db_detachnode(db, &node);
return (result);
}
/*
* Driver-specific implementation of dns_db_create().
*
* @param[in] argv Database-specific parameters from dns_db_create().
* @param[in] driverarg Driver-specific parameter from dns_db_register().
*/
isc_result_t
create_db(isc_mem_t *mctx, dns_name_t *origin, dns_dbtype_t type,
dns_rdataclass_t rdclass, unsigned int argc, char *argv[],
void *driverarg, dns_db_t **dbp)
{
sampledb_t *sampledb = NULL;
isc_result_t result;
dns_dbversion_t *version = NULL;
struct in_addr a_addr;
REQUIRE(type == dns_dbtype_zone);
REQUIRE(rdclass == dns_rdataclass_in);
REQUIRE(argc == 0);
REQUIRE(argv != NULL);
REQUIRE(driverarg != NULL); /* pointer to driver instance */
REQUIRE(dbp != NULL && *dbp == NULL);
UNUSED(driverarg); /* no driver-specific configuration */
a_addr.s_addr = 0x0100007fU;
CHECKED_MEM_GET_PTR(mctx, sampledb);
ZERO_PTR(sampledb);
isc_mem_attach(mctx, &sampledb->common.mctx);
dns_name_init(&sampledb->common.origin, NULL);
isc_ondestroy_init(&sampledb->common.ondest);
sampledb->common.magic = DNS_DB_MAGIC;
sampledb->common.impmagic = SAMPLEDB_MAGIC;
sampledb->common.methods = &sampledb_methods;
sampledb->common.attributes = 0;
sampledb->common.rdclass = rdclass;
CHECK(dns_name_dupwithoffsets(origin, mctx, &sampledb->common.origin));
CHECK(isc_refcount_init(&sampledb->refs, 1));
/* Translate instance name to instance pointer. */
sampledb->inst = driverarg;
/* Create internal instance of RBT DB implementation from BIND. */
CHECK(dns_db_create(mctx, "rbt", origin, dns_dbtype_zone,
dns_rdataclass_in, 0, NULL, &sampledb->rbtdb));
/* Create fake SOA, NS, and A records to make database loadable. */
CHECK(dns_db_newversion(sampledb->rbtdb, &version));
CHECK(add_soa(sampledb->rbtdb, version, origin, origin, origin));
CHECK(add_ns(sampledb->rbtdb, version, origin, origin));
CHECK(add_a(sampledb->rbtdb, version, origin, a_addr));
dns_db_closeversion(sampledb->rbtdb, &version, ISC_TRUE);
*dbp = (dns_db_t *)sampledb;
return (ISC_R_SUCCESS);
cleanup:
if (sampledb != NULL) {
if (dns_name_dynamic(&sampledb->common.origin))
dns_name_free(&sampledb->common.origin, mctx);
isc_mem_putanddetach(&sampledb->common.mctx, sampledb,
sizeof(*sampledb));
}
return (result);
}