From d60f5b9bc8c1e1f7ddebc6c7834f7550a8e8be6f Mon Sep 17 00:00:00 2001 From: Bob Halley Date: Thu, 14 Oct 1999 01:37:00 +0000 Subject: [PATCH] Zone support --- bin/named/include/named/types.h | 1 + bin/named/query.c | 37 +++++++++-- bin/named/server.c | 111 ++++++++++++++++++++------------ bin/named/update.c | 50 ++++++++++---- bin/named/xfrin.c | 19 ++---- bin/named/xfrout.c | 4 +- lib/dns/xfrin.c | 19 ++---- 7 files changed, 156 insertions(+), 85 deletions(-) diff --git a/bin/named/include/named/types.h b/bin/named/include/named/types.h index a31f54d0f5..1de8253d49 100644 --- a/bin/named/include/named/types.h +++ b/bin/named/include/named/types.h @@ -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; diff --git a/bin/named/query.c b/bin/named/query.c index 71b0825ac4..9efd9101f1 100644 --- a/bin/named/query.c +++ b/bin/named/query.c @@ -39,6 +39,8 @@ #include #include #include +#include +#include #include #include @@ -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); diff --git a/bin/named/server.c b/bin/named/server.c index 5741a233e1..97e019ce22 100644 --- a/bin/named/server.c +++ b/bin/named/server.c @@ -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); } diff --git a/bin/named/update.c b/bin/named/update.c index 6f1f01299b..3634efdc36 100644 --- a/bin/named/update.c +++ b/bin/named/update.c @@ -27,25 +27,26 @@ #include #include -#include -#include -#include +#include +#include +#include +#include +#include #include +#include +#include +#include +#include #include #include #include #include -#include -#include +#include +#include +#include +#include #include #include -#include -#include -#include -#include -#include -#include -#include #include #include @@ -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. diff --git a/bin/named/xfrin.c b/bin/named/xfrin.c index c133d670cf..6c8d3255d8 100644 --- a/bin/named/xfrin.c +++ b/bin/named/xfrin.c @@ -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 @@ -51,6 +51,8 @@ #include #include #include +#include +#include #include #include @@ -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); diff --git a/bin/named/xfrout.c b/bin/named/xfrout.c index 9fcc574214..8f77c4d39b 100644 --- a/bin/named/xfrout.c +++ b/bin/named/xfrout.c @@ -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 @@ -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) { diff --git a/lib/dns/xfrin.c b/lib/dns/xfrin.c index c133d670cf..6c8d3255d8 100644 --- a/lib/dns/xfrin.c +++ b/lib/dns/xfrin.c @@ -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 @@ -51,6 +51,8 @@ #include #include #include +#include +#include #include #include @@ -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);