2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-08-30 05:57:52 +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 isslave;
dns_view_t * view;
dns_zone_t * zone;
dns_db_t * db;
ISC_LINK(struct ns_dbinfo) link;
} ns_dbinfo_t;

View File

@ -39,6 +39,8 @@
#include <dns/rdatasetiter.h>
#include <dns/resolver.h>
#include <dns/view.h>
#include <dns/zone.h>
#include <dns/zt.h>
#include <named/client.h>
#include <named/globals.h>
@ -404,6 +406,7 @@ query_simplefind(void *arg, dns_name_t *name, dns_rdatatype_t type,
unsigned int dboptions;
isc_boolean_t is_zone;
dns_rdataset_t zrdataset, zsigrdataset;
dns_zone_t *zone;
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.
*/
zone = 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))
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;
/*
@ -514,6 +521,8 @@ query_simplefind(void *arg, dns_name_t *name, dns_rdatatype_t type,
}
if (db != NULL)
dns_db_detach(&db);
if (zone != NULL)
dns_zone_detach(&zone);
return (result);
}
@ -573,6 +582,7 @@ query_addadditional(void *arg, dns_name_t *name, dns_rdatatype_t type) {
dns_dbversion_t *version, *zversion;
unsigned int dboptions;
isc_boolean_t is_zone, nxglue, added_something, need_addname;
dns_zone_t *zone;
REQUIRE(NS_CLIENT_VALID(client));
REQUIRE(type != dns_rdatatype_any);
@ -598,14 +608,18 @@ query_addadditional(void *arg, dns_name_t *name, dns_rdatatype_t type) {
nxglue = ISC_FALSE;
added_something = ISC_FALSE;
need_addname = ISC_FALSE;
zone = NULL;
/*
* 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))
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;
/*
@ -914,6 +928,8 @@ query_addadditional(void *arg, dns_name_t *name, dns_rdatatype_t type) {
dns_db_detachnode(db, &node);
if (db != NULL)
dns_db_detach(&db);
if (zone != NULL)
dns_zone_detach(&zone);
if (zdb != NULL) {
if (zfname != NULL)
query_releasename(client, &zfname);
@ -1409,6 +1425,7 @@ query_find(ns_client_t *client, dns_fetchevent_t *event) {
isc_result_t result, eresult;
dns_fixedname_t fixed;
dns_dbversion_t *version;
dns_zone_t *zone;
/*
* One-time initialization.
@ -1428,6 +1445,7 @@ query_find(ns_client_t *client, dns_fetchevent_t *event) {
db = NULL;
zdb = NULL;
version = NULL;
zone = NULL;
qcount = 0;
if (event != NULL) {
@ -1487,8 +1505,11 @@ query_find(ns_client_t *client, dns_fetchevent_t *event) {
/*
* First we must find the right database.
*/
result = dns_dbtable_find(client->view->dbtable,
client->query.qname, &db);
result = dns_zt_find(client->view->zonetable, client->query.qname,
NULL, &zone);
if (result == DNS_R_SUCCESS || result == DNS_R_PARTIALMATCH)
result = dns_zone_getdb(zone, &db);
if (result == ISC_R_NOTFOUND) {
/*
* 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);
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.
*/
@ -2109,6 +2130,8 @@ query_find(ns_client_t *client, dns_fetchevent_t *event) {
dns_db_detachnode(db, &node);
if (db != NULL)
dns_db_detach(&db);
if (zone != NULL)
dns_zone_detach(&zone);
if (zdb != NULL) {
query_putrdataset(client, &zrdataset);
query_putrdataset(client, &zsigrdataset);

View File

@ -109,43 +109,60 @@ load(ns_dbinfo_t *dbi, char *view_name) {
if (result != DNS_R_SUCCESS)
goto view_detach;
result = dns_db_create(ns_g_mctx, "rbt", origin, dbi->iscache,
if (dbi->iscache) {
result = dns_db_create(ns_g_mctx, "rbt", origin, dbi->iscache,
view->rdclass, 0, NULL, &dbi->db);
if (result != DNS_R_SUCCESS)
goto view_detach;
printf("loading %s (%s)\n", dbi->path, dbi->origin);
result = dns_db_load(dbi->db, dbi->path);
if (result != DNS_R_SUCCESS) {
if (dbi->isslave) {
/* Ignore the error, just leave dbi->db == NULL. */
dns_db_detach(&dbi->db);
return (DNS_R_SUCCESS);
} else {
if (result != DNS_R_SUCCESS)
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;
}
}
printf("loaded\n");
printf("journal rollforward\n");
result = dns_journal_rollforward(ns_g_mctx, dbi->db, "journal");
if (result != DNS_R_SUCCESS) {
UNEXPECTED_ERROR(__FILE__, __LINE__,
"ns_rollforward(): %s",
dns_result_totext(result));
/* Continue anyway... */
}
if (dbi->iscache)
dns_view_setcachedb(view, dbi->db);
else if (dns_view_addzonedb(view, dbi->db) != DNS_R_SUCCESS)
goto db_detach;
} else {
result = dns_zone_create(&dbi->zone, ns_g_mctx);
printf("loading %s (%s)\n", dbi->path, dbi->origin);
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 (dbi->isslave) {
/*
* Ignore the error.
*/
return (DNS_R_SUCCESS);
} else {
goto zone_detach;
}
}
printf("loaded\n");
printf("journal rollforward\n");
result = dns_journal_rollforward(ns_g_mctx, dbi->db, "journal");
if (result != DNS_R_SUCCESS) {
UNEXPECTED_ERROR(__FILE__, __LINE__,
"ns_rollforward(): %s",
dns_result_totext(result));
/* Continue anyway... */
}
result = dns_view_addzone(view, dbi->zone);
if (result != DNS_R_SUCCESS)
goto zone_detach;
}
return (DNS_R_SUCCESS);
zone_detach:
if (dbi->zone != NULL)
dns_zone_detach(&dbi->zone);
db_detach:
dns_db_detach(&dbi->db);
if (dbi->db != NULL)
dns_db_detach(&dbi->db);
view_detach:
dns_view_detach(&dbi->view);
@ -162,8 +179,10 @@ load_version(void) {
size_t len;
int soacount, nscount;
dns_rdatacallbacks_t callbacks;
dns_view_t *view;
dns_view_t *view = NULL;
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);
@ -175,7 +194,6 @@ load_version(void) {
view != NULL;
view = ISC_LIST_NEXT(view, link)) {
if (strcasecmp(view->name, "default/CHAOS") == 0) {
version_view = NULL;
dns_view_attach(view, &version_view);
break;
}
@ -192,13 +210,18 @@ load_version(void) {
result = dns_name_fromtext(origin, &source, dns_rootname, ISC_FALSE,
NULL);
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;
result = dns_db_create(ns_g_mctx, "rbt", origin, ISC_FALSE,
view->rdclass, 0, NULL, &version_db);
if (result != DNS_R_SUCCESS)
goto view_detach;
goto cleanup;
dns_rdatacallbacks_init(&callbacks);
@ -219,18 +242,24 @@ load_version(void) {
if (result == ISC_R_SUCCESS)
result = eresult;
if (result != ISC_R_SUCCESS)
goto db_detach;
goto cleanup;
if (dns_view_addzonedb(version_view, version_db) != DNS_R_SUCCESS)
goto db_detach;
dns_zone_replacedb(version_zone, version_db, ISC_FALSE);
result = dns_view_addzone(version_view, version_zone);
if (result != DNS_R_SUCCESS)
goto cleanup;
return (DNS_R_SUCCESS);
db_detach:
dns_db_detach(&version_db);
view_detach:
dns_view_detach(&version_view);
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);
return (result);
}

View File

@ -27,25 +27,26 @@
#include <isc/mem.h>
#include <isc/result.h>
#include <dns/types.h>
#include <dns/result.h>
#include <dns/name.h>
#include <dns/db.h>
#include <dns/dbiterator.h>
#include <dns/dbtable.h>
#include <dns/dnssec.h>
#include <dns/events.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/rdatalist.h>
#include <dns/rdataset.h>
#include <dns/rdatasetiter.h>
#include <dns/db.h>
#include <dns/dbiterator.h>
#include <dns/rdatastruct.h>
#include <dns/result.h>
#include <dns/types.h>
#include <dns/view.h>
#include <dns/zone.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/client.h>
@ -2131,7 +2132,32 @@ update_action(isc_task_t *task, isc_event_t *event)
if (db != NULL)
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
* was a failure response.

View File

@ -15,7 +15,7 @@
* 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>
@ -51,6 +51,8 @@
#include <dns/journal.h>
#include <dns/view.h>
#include <dns/tsig.h>
#include <dns/zone.h>
#include <dns/zt.h>
#include <named/globals.h>
#include <named/xfrin.h>
@ -123,7 +125,6 @@ struct xfrin_ctx {
isc_boolean_t tcpmsg_valid;
dns_db_t *db;
dns_db_t *olddb;
dns_dbversion_t *ver;
dns_diff_t diff; /* Pending database changes */
int difflen; /* Number of pending tuples */
@ -219,11 +220,9 @@ axfr_init(xfrin_ctx_t *xfr) {
dns_result_t result;
xfr->is_ixfr = ISC_FALSE;
if (xfr->db != NULL) {
xfr->olddb = xfr->db;
xfr->db = NULL;
}
if (xfr->db != NULL)
dns_db_detach(&xfr->db);
CHECK(axfr_makedb(xfr, &xfr->db));
CHECK(dns_db_beginload(xfr->db, &xfr->axfr.add_func,
&xfr->axfr.add_private));
@ -577,7 +576,6 @@ xfrin_create(isc_mem_t *mctx,
xfr->tcpmsg_valid = ISC_FALSE;
xfr->db = db;
xfr->olddb = NULL;
xfr->ver = NULL;
dns_diff_init(xfr->mctx, &xfr->diff);
xfr->difflen = 0;
@ -990,10 +988,7 @@ maybe_free(xfrin_ctx_t *xfr) {
dns_db_closeversion(xfr->db, &xfr->ver, ISC_FALSE);
if (xfr->db != NULL)
dns_db_detach(&xfr->db); /* XXX ??? */
if (xfr->olddb != NULL)
dns_db_detach(&xfr->olddb);
dns_db_detach(&xfr->db);
if (xfr->zone != NULL)
dns_zone_detach(&xfr->zone);

View File

@ -15,7 +15,7 @@
* 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>
@ -942,6 +942,8 @@ ns_xfr_start(ns_client_t *client, dns_rdatatype_t reqtype)
dns_db_closeversion(db, &ver, ISC_FALSE);
if (db != NULL)
dns_db_detach(&db);
if (zone != NULL)
dns_zone_detach(&zone);
/* XXX kludge */
if (xfr != NULL) {

View File

@ -15,7 +15,7 @@
* 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>
@ -51,6 +51,8 @@
#include <dns/journal.h>
#include <dns/view.h>
#include <dns/tsig.h>
#include <dns/zone.h>
#include <dns/zt.h>
#include <named/globals.h>
#include <named/xfrin.h>
@ -123,7 +125,6 @@ struct xfrin_ctx {
isc_boolean_t tcpmsg_valid;
dns_db_t *db;
dns_db_t *olddb;
dns_dbversion_t *ver;
dns_diff_t diff; /* Pending database changes */
int difflen; /* Number of pending tuples */
@ -219,11 +220,9 @@ axfr_init(xfrin_ctx_t *xfr) {
dns_result_t result;
xfr->is_ixfr = ISC_FALSE;
if (xfr->db != NULL) {
xfr->olddb = xfr->db;
xfr->db = NULL;
}
if (xfr->db != NULL)
dns_db_detach(&xfr->db);
CHECK(axfr_makedb(xfr, &xfr->db));
CHECK(dns_db_beginload(xfr->db, &xfr->axfr.add_func,
&xfr->axfr.add_private));
@ -577,7 +576,6 @@ xfrin_create(isc_mem_t *mctx,
xfr->tcpmsg_valid = ISC_FALSE;
xfr->db = db;
xfr->olddb = NULL;
xfr->ver = NULL;
dns_diff_init(xfr->mctx, &xfr->diff);
xfr->difflen = 0;
@ -990,10 +988,7 @@ maybe_free(xfrin_ctx_t *xfr) {
dns_db_closeversion(xfr->db, &xfr->ver, ISC_FALSE);
if (xfr->db != NULL)
dns_db_detach(&xfr->db); /* XXX ??? */
if (xfr->olddb != NULL)
dns_db_detach(&xfr->olddb);
dns_db_detach(&xfr->db);
if (xfr->zone != NULL)
dns_zone_detach(&xfr->zone);