2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-08-31 06:25:31 +00:00

Zone support

This commit is contained in:
Bob Halley
1999-10-14 01:37:00 +00:00
parent 659175b7d4
commit d60f5b9bc8
7 changed files with 156 additions and 85 deletions

View File

@@ -38,6 +38,7 @@ typedef struct ns_dbinfo {
isc_boolean_t iscache; isc_boolean_t iscache;
isc_boolean_t isslave; isc_boolean_t isslave;
dns_view_t * view; dns_view_t * view;
dns_zone_t * zone;
dns_db_t * db; dns_db_t * db;
ISC_LINK(struct ns_dbinfo) link; ISC_LINK(struct ns_dbinfo) link;
} ns_dbinfo_t; } ns_dbinfo_t;

View File

@@ -39,6 +39,8 @@
#include <dns/rdatasetiter.h> #include <dns/rdatasetiter.h>
#include <dns/resolver.h> #include <dns/resolver.h>
#include <dns/view.h> #include <dns/view.h>
#include <dns/zone.h>
#include <dns/zt.h>
#include <named/client.h> #include <named/client.h>
#include <named/globals.h> #include <named/globals.h>
@@ -404,6 +406,7 @@ query_simplefind(void *arg, dns_name_t *name, dns_rdatatype_t type,
unsigned int dboptions; unsigned int dboptions;
isc_boolean_t is_zone; isc_boolean_t is_zone;
dns_rdataset_t zrdataset, zsigrdataset; dns_rdataset_t zrdataset, zsigrdataset;
dns_zone_t *zone;
REQUIRE(NS_CLIENT_VALID(client)); REQUIRE(NS_CLIENT_VALID(client));
@@ -413,11 +416,15 @@ query_simplefind(void *arg, dns_name_t *name, dns_rdatatype_t type,
/* /*
* Find a database to answer the query. * Find a database to answer the query.
*/ */
zone = NULL;
db = NULL; db = NULL;
result = dns_dbtable_find(client->view->dbtable, name, &db); result = dns_zt_find(client->view->zonetable, name, NULL, &zone);
if (result == DNS_R_SUCCESS || result == DNS_R_PARTIALMATCH)
result = dns_zone_getdb(zone, &db);
if (result == ISC_R_NOTFOUND && USECACHE(client)) if (result == ISC_R_NOTFOUND && USECACHE(client))
dns_db_attach(client->view->cachedb, &db); dns_db_attach(client->view->cachedb, &db);
else if (result != ISC_R_SUCCESS && result != DNS_R_PARTIALMATCH) else if (result != DNS_R_SUCCESS)
goto cleanup; goto cleanup;
/* /*
@@ -514,6 +521,8 @@ query_simplefind(void *arg, dns_name_t *name, dns_rdatatype_t type,
} }
if (db != NULL) if (db != NULL)
dns_db_detach(&db); dns_db_detach(&db);
if (zone != NULL)
dns_zone_detach(&zone);
return (result); return (result);
} }
@@ -573,6 +582,7 @@ query_addadditional(void *arg, dns_name_t *name, dns_rdatatype_t type) {
dns_dbversion_t *version, *zversion; dns_dbversion_t *version, *zversion;
unsigned int dboptions; unsigned int dboptions;
isc_boolean_t is_zone, nxglue, added_something, need_addname; isc_boolean_t is_zone, nxglue, added_something, need_addname;
dns_zone_t *zone;
REQUIRE(NS_CLIENT_VALID(client)); REQUIRE(NS_CLIENT_VALID(client));
REQUIRE(type != dns_rdatatype_any); REQUIRE(type != dns_rdatatype_any);
@@ -598,14 +608,18 @@ query_addadditional(void *arg, dns_name_t *name, dns_rdatatype_t type) {
nxglue = ISC_FALSE; nxglue = ISC_FALSE;
added_something = ISC_FALSE; added_something = ISC_FALSE;
need_addname = ISC_FALSE; need_addname = ISC_FALSE;
zone = NULL;
/* /*
* Find a database to answer the query. * Find a database to answer the query.
*/ */
result = dns_dbtable_find(client->view->dbtable, name, &db); result = dns_zt_find(client->view->zonetable, name, NULL, &zone);
if (result == DNS_R_SUCCESS || result == DNS_R_PARTIALMATCH)
result = dns_zone_getdb(zone, &db);
if (result == ISC_R_NOTFOUND && USECACHE(client)) if (result == ISC_R_NOTFOUND && USECACHE(client))
dns_db_attach(client->view->cachedb, &db); dns_db_attach(client->view->cachedb, &db);
else if (result != ISC_R_SUCCESS && result != DNS_R_PARTIALMATCH) else if (result != DNS_R_SUCCESS)
goto cleanup; goto cleanup;
/* /*
@@ -914,6 +928,8 @@ query_addadditional(void *arg, dns_name_t *name, dns_rdatatype_t type) {
dns_db_detachnode(db, &node); dns_db_detachnode(db, &node);
if (db != NULL) if (db != NULL)
dns_db_detach(&db); dns_db_detach(&db);
if (zone != NULL)
dns_zone_detach(&zone);
if (zdb != NULL) { if (zdb != NULL) {
if (zfname != NULL) if (zfname != NULL)
query_releasename(client, &zfname); query_releasename(client, &zfname);
@@ -1409,6 +1425,7 @@ query_find(ns_client_t *client, dns_fetchevent_t *event) {
isc_result_t result, eresult; isc_result_t result, eresult;
dns_fixedname_t fixed; dns_fixedname_t fixed;
dns_dbversion_t *version; dns_dbversion_t *version;
dns_zone_t *zone;
/* /*
* One-time initialization. * One-time initialization.
@@ -1428,6 +1445,7 @@ query_find(ns_client_t *client, dns_fetchevent_t *event) {
db = NULL; db = NULL;
zdb = NULL; zdb = NULL;
version = NULL; version = NULL;
zone = NULL;
qcount = 0; qcount = 0;
if (event != NULL) { if (event != NULL) {
@@ -1487,8 +1505,11 @@ query_find(ns_client_t *client, dns_fetchevent_t *event) {
/* /*
* First we must find the right database. * First we must find the right database.
*/ */
result = dns_dbtable_find(client->view->dbtable, result = dns_zt_find(client->view->zonetable, client->query.qname,
client->query.qname, &db); NULL, &zone);
if (result == DNS_R_SUCCESS || result == DNS_R_PARTIALMATCH)
result = dns_zone_getdb(zone, &db);
if (result == ISC_R_NOTFOUND) { if (result == ISC_R_NOTFOUND) {
/* /*
* We're not directly authoritative for this query name, nor * We're not directly authoritative for this query name, nor
@@ -1507,7 +1528,7 @@ query_find(ns_client_t *client, dns_fetchevent_t *event) {
} }
INSIST(client->view->cachedb != NULL); INSIST(client->view->cachedb != NULL);
dns_db_attach(client->view->cachedb, &db); dns_db_attach(client->view->cachedb, &db);
} else if (result != ISC_R_SUCCESS && result != DNS_R_PARTIALMATCH) { } else if (result != ISC_R_SUCCESS) {
/* /*
* Something is broken. * Something is broken.
*/ */
@@ -2109,6 +2130,8 @@ query_find(ns_client_t *client, dns_fetchevent_t *event) {
dns_db_detachnode(db, &node); dns_db_detachnode(db, &node);
if (db != NULL) if (db != NULL)
dns_db_detach(&db); dns_db_detach(&db);
if (zone != NULL)
dns_zone_detach(&zone);
if (zdb != NULL) { if (zdb != NULL) {
query_putrdataset(client, &zrdataset); query_putrdataset(client, &zrdataset);
query_putrdataset(client, &zsigrdataset); query_putrdataset(client, &zsigrdataset);

View File

@@ -109,21 +109,33 @@ load(ns_dbinfo_t *dbi, char *view_name) {
if (result != DNS_R_SUCCESS) if (result != DNS_R_SUCCESS)
goto view_detach; goto view_detach;
if (dbi->iscache) {
result = dns_db_create(ns_g_mctx, "rbt", origin, dbi->iscache, result = dns_db_create(ns_g_mctx, "rbt", origin, dbi->iscache,
view->rdclass, 0, NULL, &dbi->db); view->rdclass, 0, NULL, &dbi->db);
if (result != DNS_R_SUCCESS) if (result != DNS_R_SUCCESS)
goto view_detach; goto view_detach;
printf("loading cache %s (%s)\n", dbi->path, dbi->origin);
result = dns_db_load(dbi->db, dbi->path);
if (result != DNS_R_SUCCESS)
goto db_detach;
dns_view_setcachedb(view, dbi->db);
} else {
result = dns_zone_create(&dbi->zone, ns_g_mctx);
printf("loading %s (%s)\n", dbi->path, dbi->origin); printf("loading %s (%s)\n", dbi->path, dbi->origin);
result = dns_db_load(dbi->db, dbi->path); result = dns_zone_setdatabase(dbi->zone, dbi->path);
if (result != DNS_R_SUCCESS)
goto zone_detach;
result = dns_zone_load(dbi->zone);
if (result != DNS_R_SUCCESS) { if (result != DNS_R_SUCCESS) {
if (dbi->isslave) { if (dbi->isslave) {
/* Ignore the error, just leave dbi->db == NULL. */ /*
dns_db_detach(&dbi->db); * Ignore the error.
*/
return (DNS_R_SUCCESS); return (DNS_R_SUCCESS);
} else { } else {
goto db_detach; goto zone_detach;
} }
} }
@@ -137,14 +149,19 @@ load(ns_dbinfo_t *dbi, char *view_name) {
/* Continue anyway... */ /* Continue anyway... */
} }
if (dbi->iscache) result = dns_view_addzone(view, dbi->zone);
dns_view_setcachedb(view, dbi->db); if (result != DNS_R_SUCCESS)
else if (dns_view_addzonedb(view, dbi->db) != DNS_R_SUCCESS) goto zone_detach;
goto db_detach; }
return (DNS_R_SUCCESS); return (DNS_R_SUCCESS);
zone_detach:
if (dbi->zone != NULL)
dns_zone_detach(&dbi->zone);
db_detach: db_detach:
if (dbi->db != NULL)
dns_db_detach(&dbi->db); dns_db_detach(&dbi->db);
view_detach: view_detach:
@@ -162,8 +179,10 @@ load_version(void) {
size_t len; size_t len;
int soacount, nscount; int soacount, nscount;
dns_rdatacallbacks_t callbacks; dns_rdatacallbacks_t callbacks;
dns_view_t *view; dns_view_t *view = NULL;
char version_text[1024]; char version_text[1024];
dns_zone_t *version_zone = NULL;
dns_db_t *version_db = NULL;
sprintf(version_text, "version 0 CHAOS TXT \"%s\"\n", ns_g_version); sprintf(version_text, "version 0 CHAOS TXT \"%s\"\n", ns_g_version);
@@ -175,7 +194,6 @@ load_version(void) {
view != NULL; view != NULL;
view = ISC_LIST_NEXT(view, link)) { view = ISC_LIST_NEXT(view, link)) {
if (strcasecmp(view->name, "default/CHAOS") == 0) { if (strcasecmp(view->name, "default/CHAOS") == 0) {
version_view = NULL;
dns_view_attach(view, &version_view); dns_view_attach(view, &version_view);
break; break;
} }
@@ -192,13 +210,18 @@ load_version(void) {
result = dns_name_fromtext(origin, &source, dns_rootname, ISC_FALSE, result = dns_name_fromtext(origin, &source, dns_rootname, ISC_FALSE,
NULL); NULL);
if (result != DNS_R_SUCCESS) if (result != DNS_R_SUCCESS)
goto view_detach; goto cleanup;
version_zone = NULL;
result = dns_zone_create(&version_zone, ns_g_mctx);
if (result != DNS_R_SUCCESS)
goto cleanup;
version_db = NULL; version_db = NULL;
result = dns_db_create(ns_g_mctx, "rbt", origin, ISC_FALSE, result = dns_db_create(ns_g_mctx, "rbt", origin, ISC_FALSE,
view->rdclass, 0, NULL, &version_db); view->rdclass, 0, NULL, &version_db);
if (result != DNS_R_SUCCESS) if (result != DNS_R_SUCCESS)
goto view_detach; goto cleanup;
dns_rdatacallbacks_init(&callbacks); dns_rdatacallbacks_init(&callbacks);
@@ -219,17 +242,23 @@ load_version(void) {
if (result == ISC_R_SUCCESS) if (result == ISC_R_SUCCESS)
result = eresult; result = eresult;
if (result != ISC_R_SUCCESS) if (result != ISC_R_SUCCESS)
goto db_detach; goto cleanup;
if (dns_view_addzonedb(version_view, version_db) != DNS_R_SUCCESS) dns_zone_replacedb(version_zone, version_db, ISC_FALSE);
goto db_detach;
result = dns_view_addzone(version_view, version_zone);
if (result != DNS_R_SUCCESS)
goto cleanup;
return (DNS_R_SUCCESS); return (DNS_R_SUCCESS);
db_detach:
dns_db_detach(&version_db);
view_detach: cleanup:
if (version_zone != NULL)
dns_zone_detach(&version_zone);
if (version_db != NULL)
dns_db_detach(&version_db);
if (version_view != NULL)
dns_view_detach(&version_view); dns_view_detach(&version_view);
return (result); return (result);

View File

@@ -27,25 +27,26 @@
#include <isc/mem.h> #include <isc/mem.h>
#include <isc/result.h> #include <isc/result.h>
#include <dns/types.h> #include <dns/db.h>
#include <dns/result.h> #include <dns/dbiterator.h>
#include <dns/name.h> #include <dns/dbtable.h>
#include <dns/dnssec.h>
#include <dns/events.h>
#include <dns/fixedname.h> #include <dns/fixedname.h>
#include <dns/journal.h>
#include <dns/message.h>
#include <dns/name.h>
#include <dns/nxt.h>
#include <dns/rdata.h> #include <dns/rdata.h>
#include <dns/rdatalist.h> #include <dns/rdatalist.h>
#include <dns/rdataset.h> #include <dns/rdataset.h>
#include <dns/rdatasetiter.h> #include <dns/rdatasetiter.h>
#include <dns/db.h> #include <dns/rdatastruct.h>
#include <dns/dbiterator.h> #include <dns/result.h>
#include <dns/types.h>
#include <dns/view.h>
#include <dns/zone.h> #include <dns/zone.h>
#include <dns/zt.h> #include <dns/zt.h>
#include <dns/message.h>
#include <dns/rdatastruct.h>
#include <dns/journal.h>
#include <dns/view.h>
#include <dns/dnssec.h>
#include <dns/nxt.h>
#include <dns/events.h>
#include <named/globals.h> #include <named/globals.h>
#include <named/client.h> #include <named/client.h>
@@ -2132,6 +2133,31 @@ update_action(isc_task_t *task, isc_event_t *event)
if (db != NULL) if (db != NULL)
dns_db_detach(&db); dns_db_detach(&db);
if (zone != NULL)
dns_zone_detach(&zone);
/*
* Construct the response message.
*/
render_result = dns_message_create(mctx, DNS_MESSAGE_INTENTRENDER,
&response);
if (render_result != DNS_R_SUCCESS)
goto render_failure;
response->id = request->id;
response->rcode = response_rcode;
response->flags = request->flags;
response->flags |= DNS_MESSAGEFLAG_QR;
*responsep = response;
goto render_success;
render_failure:
if (response != NULL)
dns_message_destroy(&response);
render_success:
/* /*
* If we could send a response, we have succeded, even if it * If we could send a response, we have succeded, even if it
* was a failure response. * was a failure response.

View File

@@ -15,7 +15,7 @@
* SOFTWARE. * SOFTWARE.
*/ */
/* $Id: xfrin.c,v 1.12 1999/10/14 00:05:02 gson Exp $ */ /* $Id: xfrin.c,v 1.13 1999/10/14 01:36:59 halley Exp $ */
#include <config.h> #include <config.h>
@@ -51,6 +51,8 @@
#include <dns/journal.h> #include <dns/journal.h>
#include <dns/view.h> #include <dns/view.h>
#include <dns/tsig.h> #include <dns/tsig.h>
#include <dns/zone.h>
#include <dns/zt.h>
#include <named/globals.h> #include <named/globals.h>
#include <named/xfrin.h> #include <named/xfrin.h>
@@ -123,7 +125,6 @@ struct xfrin_ctx {
isc_boolean_t tcpmsg_valid; isc_boolean_t tcpmsg_valid;
dns_db_t *db; dns_db_t *db;
dns_db_t *olddb;
dns_dbversion_t *ver; dns_dbversion_t *ver;
dns_diff_t diff; /* Pending database changes */ dns_diff_t diff; /* Pending database changes */
int difflen; /* Number of pending tuples */ int difflen; /* Number of pending tuples */
@@ -219,10 +220,8 @@ axfr_init(xfrin_ctx_t *xfr) {
dns_result_t result; dns_result_t result;
xfr->is_ixfr = ISC_FALSE; xfr->is_ixfr = ISC_FALSE;
if (xfr->db != NULL) { if (xfr->db != NULL)
xfr->olddb = xfr->db; dns_db_detach(&xfr->db);
xfr->db = NULL;
}
CHECK(axfr_makedb(xfr, &xfr->db)); CHECK(axfr_makedb(xfr, &xfr->db));
CHECK(dns_db_beginload(xfr->db, &xfr->axfr.add_func, CHECK(dns_db_beginload(xfr->db, &xfr->axfr.add_func,
@@ -577,7 +576,6 @@ xfrin_create(isc_mem_t *mctx,
xfr->tcpmsg_valid = ISC_FALSE; xfr->tcpmsg_valid = ISC_FALSE;
xfr->db = db; xfr->db = db;
xfr->olddb = NULL;
xfr->ver = NULL; xfr->ver = NULL;
dns_diff_init(xfr->mctx, &xfr->diff); dns_diff_init(xfr->mctx, &xfr->diff);
xfr->difflen = 0; xfr->difflen = 0;
@@ -990,10 +988,7 @@ maybe_free(xfrin_ctx_t *xfr) {
dns_db_closeversion(xfr->db, &xfr->ver, ISC_FALSE); dns_db_closeversion(xfr->db, &xfr->ver, ISC_FALSE);
if (xfr->db != NULL) if (xfr->db != NULL)
dns_db_detach(&xfr->db); /* XXX ??? */ dns_db_detach(&xfr->db);
if (xfr->olddb != NULL)
dns_db_detach(&xfr->olddb);
if (xfr->zone != NULL) if (xfr->zone != NULL)
dns_zone_detach(&xfr->zone); dns_zone_detach(&xfr->zone);

View File

@@ -15,7 +15,7 @@
* SOFTWARE. * SOFTWARE.
*/ */
/* $Id: xfrout.c,v 1.13 1999/10/14 00:06:11 gson Exp $ */ /* $Id: xfrout.c,v 1.14 1999/10/14 01:36:59 halley Exp $ */
#include <config.h> #include <config.h>
@@ -942,6 +942,8 @@ ns_xfr_start(ns_client_t *client, dns_rdatatype_t reqtype)
dns_db_closeversion(db, &ver, ISC_FALSE); dns_db_closeversion(db, &ver, ISC_FALSE);
if (db != NULL) if (db != NULL)
dns_db_detach(&db); dns_db_detach(&db);
if (zone != NULL)
dns_zone_detach(&zone);
/* XXX kludge */ /* XXX kludge */
if (xfr != NULL) { if (xfr != NULL) {

View File

@@ -15,7 +15,7 @@
* SOFTWARE. * SOFTWARE.
*/ */
/* $Id: xfrin.c,v 1.12 1999/10/14 00:05:02 gson Exp $ */ /* $Id: xfrin.c,v 1.13 1999/10/14 01:36:59 halley Exp $ */
#include <config.h> #include <config.h>
@@ -51,6 +51,8 @@
#include <dns/journal.h> #include <dns/journal.h>
#include <dns/view.h> #include <dns/view.h>
#include <dns/tsig.h> #include <dns/tsig.h>
#include <dns/zone.h>
#include <dns/zt.h>
#include <named/globals.h> #include <named/globals.h>
#include <named/xfrin.h> #include <named/xfrin.h>
@@ -123,7 +125,6 @@ struct xfrin_ctx {
isc_boolean_t tcpmsg_valid; isc_boolean_t tcpmsg_valid;
dns_db_t *db; dns_db_t *db;
dns_db_t *olddb;
dns_dbversion_t *ver; dns_dbversion_t *ver;
dns_diff_t diff; /* Pending database changes */ dns_diff_t diff; /* Pending database changes */
int difflen; /* Number of pending tuples */ int difflen; /* Number of pending tuples */
@@ -219,10 +220,8 @@ axfr_init(xfrin_ctx_t *xfr) {
dns_result_t result; dns_result_t result;
xfr->is_ixfr = ISC_FALSE; xfr->is_ixfr = ISC_FALSE;
if (xfr->db != NULL) { if (xfr->db != NULL)
xfr->olddb = xfr->db; dns_db_detach(&xfr->db);
xfr->db = NULL;
}
CHECK(axfr_makedb(xfr, &xfr->db)); CHECK(axfr_makedb(xfr, &xfr->db));
CHECK(dns_db_beginload(xfr->db, &xfr->axfr.add_func, CHECK(dns_db_beginload(xfr->db, &xfr->axfr.add_func,
@@ -577,7 +576,6 @@ xfrin_create(isc_mem_t *mctx,
xfr->tcpmsg_valid = ISC_FALSE; xfr->tcpmsg_valid = ISC_FALSE;
xfr->db = db; xfr->db = db;
xfr->olddb = NULL;
xfr->ver = NULL; xfr->ver = NULL;
dns_diff_init(xfr->mctx, &xfr->diff); dns_diff_init(xfr->mctx, &xfr->diff);
xfr->difflen = 0; xfr->difflen = 0;
@@ -990,10 +988,7 @@ maybe_free(xfrin_ctx_t *xfr) {
dns_db_closeversion(xfr->db, &xfr->ver, ISC_FALSE); dns_db_closeversion(xfr->db, &xfr->ver, ISC_FALSE);
if (xfr->db != NULL) if (xfr->db != NULL)
dns_db_detach(&xfr->db); /* XXX ??? */ dns_db_detach(&xfr->db);
if (xfr->olddb != NULL)
dns_db_detach(&xfr->olddb);
if (xfr->zone != NULL) if (xfr->zone != NULL)
dns_zone_detach(&xfr->zone); dns_zone_detach(&xfr->zone);