From a6733246eafeb43755ce6d7ec3627ac4209cbccb Mon Sep 17 00:00:00 2001 From: Mark Andrews Date: Wed, 7 Jun 2000 02:38:41 +0000 Subject: [PATCH] 240. [func] databases now come in three flavours: zone, cache and stub. --- CHANGES | 3 +++ bin/dnssec/dnssec-makekeyset.c | 2 +- bin/dnssec/dnssec-signkey.c | 2 +- bin/dnssec/dnssec-signzone.c | 10 +++++----- bin/named/server.c | 16 +--------------- bin/tests/db_test.c | 4 +++- bin/tests/nxtify.c | 2 +- lib/dns/cache.c | 7 ++++--- lib/dns/db.c | 25 ++++++++++++++++++++----- lib/dns/include/dns/db.h | 22 +++++++++++++++------- lib/dns/include/dns/types.h | 4 ++++ lib/dns/rbtdb.c | 19 ++++++++++++++----- lib/dns/rbtdb.h | 2 +- lib/dns/rootns.c | 2 +- lib/dns/view.c | 18 +++++++++--------- lib/dns/xfrin.c | 4 ++-- 16 files changed, 85 insertions(+), 57 deletions(-) diff --git a/CHANGES b/CHANGES index 184774f45d..5b7a780143 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,6 @@ + 240. [func] databases now come in three flavours: zone, cache + and stub. + 239. [feature] If ISC_MEM_DEBUG is enabled, the variable isc_mem_debugging controls whether messages are printed or not. diff --git a/bin/dnssec/dnssec-makekeyset.c b/bin/dnssec/dnssec-makekeyset.c index 4b83978a76..96ea9a87a5 100644 --- a/bin/dnssec/dnssec-makekeyset.c +++ b/bin/dnssec/dnssec-makekeyset.c @@ -334,7 +334,7 @@ main(int argc, char *argv[]) { } db = NULL; - result = dns_db_create(mctx, "rbt", domain, ISC_FALSE, + result = dns_db_create(mctx, "rbt", domain, dns_dbtype_zone, dns_rdataclass_in, 0, NULL, &db); if (result != ISC_R_SUCCESS) fatal("failed to create a database for %s", nametostr(domain)); diff --git a/bin/dnssec/dnssec-signkey.c b/bin/dnssec/dnssec-signkey.c index 14a8398d19..07277dd75e 100644 --- a/bin/dnssec/dnssec-signkey.c +++ b/bin/dnssec/dnssec-signkey.c @@ -203,7 +203,7 @@ main(int argc, char *argv[]) { strcat(output, "signedkey"); db = NULL; - result = dns_db_create(mctx, "rbt", domain, ISC_FALSE, + result = dns_db_create(mctx, "rbt", domain, dns_dbtype_zone, dns_rdataclass_in, 0, NULL, &db); check_result(result, "dns_db_create()"); diff --git a/bin/dnssec/dnssec-signzone.c b/bin/dnssec/dnssec-signzone.c index 59b4cd4317..34242743fd 100644 --- a/bin/dnssec/dnssec-signzone.c +++ b/bin/dnssec/dnssec-signzone.c @@ -517,8 +517,8 @@ importparentsig(dns_db_t *db, dns_dbversion_t *version, dns_dbnode_t *node, check_result(result, "dns_name_totext()"); isc_buffer_usedregion(&b, &r); strcpy((char *)r.base + r.length, "signedkey"); - result = dns_db_create(mctx, "rbt", name, ISC_FALSE, dns_db_class(db), - 0, NULL, &newdb); + result = dns_db_create(mctx, "rbt", name, dns_dbtype_zone, + dns_db_class(db), 0, NULL, &newdb); check_result(result, "dns_db_create()"); result = dns_db_load(newdb, (char *)filename); if (result != ISC_R_SUCCESS) @@ -596,8 +596,8 @@ haschildkey(dns_db_t *db, dns_name_t *name) { check_result(result, "dns_name_totext()"); isc_buffer_usedregion(&b, &r); strcpy((char *)r.base + r.length, "signedkey"); - result = dns_db_create(mctx, "rbt", name, ISC_FALSE, dns_db_class(db), - 0, NULL, &newdb); + result = dns_db_create(mctx, "rbt", name, dns_dbtype_zone, + dns_db_class(db), 0, NULL, &newdb); check_result(result, "dns_db_create()"); result = dns_db_load(newdb, (char *)filename); if (result != ISC_R_SUCCESS) @@ -1077,7 +1077,7 @@ loadzone(char *file, char *origin, dns_db_t **db) { fatal("failed converting name '%s' to dns format: %s", origin, isc_result_totext(result)); - result = dns_db_create(mctx, "rbt", &name, ISC_FALSE, + result = dns_db_create(mctx, "rbt", &name, dns_dbtype_zone, dns_rdataclass_in, 0, NULL, db); check_result(result, "dns_db_create()"); diff --git a/bin/named/server.c b/bin/named/server.c index 491dc1e624..0ddcc18350 100644 --- a/bin/named/server.c +++ b/bin/named/server.c @@ -744,7 +744,7 @@ create_version_view(dns_c_ctx_t *cctx, dns_zonemgr_t *zmgr, dns_view_t **viewp) CHECK(dns_zonemgr_managezone(zmgr, zone)); - CHECK(dns_db_create(ns_g_mctx, "rbt", &origin, ISC_FALSE, + CHECK(dns_db_create(ns_g_mctx, "rbt", &origin, dns_dbtype_zone, dns_rdataclass_ch, 0, NULL, &db)); CHECK(dns_db_newversion(db, &dbver)); @@ -929,20 +929,6 @@ configure_zone(dns_c_ctx_t *cctx, dns_c_zone_t *czone, dns_c_view_t *cview, goto cleanup; } - /* - * "stub zones" aren't zones either. Eventually we'll - * create a "cache freshener" to keep the stub data in the - * cache. - */ - if (czone->ztype == dns_c_zone_stub) { - isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, - NS_LOGMODULE_SERVER, ISC_LOG_WARNING, - "stub zone '%s': stub zones are not supported in this release", - corigin); - result = ISC_R_SUCCESS; - goto cleanup; - } - /* * "forward zones" aren't zones either. Eventually we'll * translate this syntax into the appropriate selective forwarding diff --git a/bin/tests/db_test.c b/bin/tests/db_test.c index a61b6d98c0..eaa3f6b1cd 100644 --- a/bin/tests/db_test.c +++ b/bin/tests/db_test.c @@ -271,7 +271,9 @@ load(const char *filename, const char *origintext, isc_boolean_t cache) { if (result != ISC_R_SUCCESS) return (result); - result = dns_db_create(mctx, dbtype, origin, cache, dns_rdataclass_in, + result = dns_db_create(mctx, dbtype, origin, + cache? dns_rb_cache : dns_dbtype_zone, + dns_rdataclass_in, 0, NULL, &dbi->db); if (result != ISC_R_SUCCESS) { isc_mem_put(mctx, dbi, sizeof *dbi); diff --git a/bin/tests/nxtify.c b/bin/tests/nxtify.c index 0decc97101..e3a73ea207 100644 --- a/bin/tests/nxtify.c +++ b/bin/tests/nxtify.c @@ -140,7 +140,7 @@ nxtify(char *filename) { check_result(result, "dns_name_fromtext()"); db = NULL; - result = dns_db_create(mctx, "rbt", name, ISC_FALSE, + result = dns_db_create(mctx, "rbt", name, dns_dbtype_zone, dns_rdataclass_in, 0, NULL, &db); check_result(result, "dns_db_create()"); result = dns_db_load(db, filename); diff --git a/lib/dns/cache.c b/lib/dns/cache.c index 9f74bf1fb6..5d01070af3 100644 --- a/lib/dns/cache.c +++ b/lib/dns/cache.c @@ -15,7 +15,7 @@ * SOFTWARE. */ -/* $Id: cache.c,v 1.22 2000/06/01 18:25:25 tale Exp $ */ +/* $Id: cache.c,v 1.23 2000/06/07 02:38:30 marka Exp $ */ #include @@ -151,8 +151,9 @@ dns_cache_create(isc_mem_t *mctx, isc_taskmgr_t *taskmgr, cache->rdclass = rdclass; cache->db = NULL; - result = dns_db_create(cache->mctx, db_type, dns_rootname, ISC_TRUE, - rdclass, db_argc, db_argv, &cache->db); + result = dns_db_create(cache->mctx, db_type, dns_rootname, + dns_dbtype_cache, rdclass, db_argc, db_argv, + &cache->db); if (result != ISC_R_SUCCESS) goto cleanup_mutex; diff --git a/lib/dns/db.c b/lib/dns/db.c index b2312a8022..5a047493b6 100644 --- a/lib/dns/db.c +++ b/lib/dns/db.c @@ -37,7 +37,7 @@ typedef struct { const char * name; isc_result_t (*create)(isc_mem_t *mctx, dns_name_t *name, - isc_boolean_t cache, + dns_dbtype_t type, dns_rdataclass_t rdclass, unsigned int argc, char *argv[], dns_db_t **dbp); @@ -68,7 +68,7 @@ static impinfo_t implementations[] = { isc_result_t dns_db_create(isc_mem_t *mctx, const char *db_type, dns_name_t *origin, - isc_boolean_t cache, dns_rdataclass_t rdclass, + dns_dbtype_t type, dns_rdataclass_t rdclass, unsigned int argc, char *argv[], dns_db_t **dbp) { impinfo_t *impinfo; @@ -82,7 +82,7 @@ dns_db_create(isc_mem_t *mctx, const char *db_type, dns_name_t *origin, for (impinfo = implementations; impinfo->name != NULL; impinfo++) if (strcasecmp(db_type, impinfo->name) == 0) - return ((impinfo->create)(mctx, origin, cache, rdclass, + return ((impinfo->create)(mctx, origin, type, rdclass, argc, argv, dbp)); return (ISC_R_NOTFOUND); @@ -151,7 +151,22 @@ dns_db_iszone(dns_db_t *db) { REQUIRE(DNS_DB_VALID(db)); - if ((db->attributes & DNS_DBATTR_CACHE) == 0) + if ((db->attributes & (DNS_DBATTR_CACHE|DNS_DBATTR_STUB)) == 0) + return (ISC_TRUE); + + return (ISC_FALSE); +} + +isc_boolean_t +dns_db_isstub(dns_db_t *db) { + + /* + * Does 'db' have stub semantics? + */ + + REQUIRE(DNS_DB_VALID(db)); + + if ((db->attributes & DNS_DBATTR_STUB) != 0) return (ISC_TRUE); return (ISC_FALSE); @@ -598,7 +613,7 @@ dns_db_getsoaserial(dns_db_t *db, dns_dbversion_t *ver, isc_uint32_t *serialp) dns_rdata_t rdata; isc_buffer_t buffer; - REQUIRE(dns_db_iszone(db)); + REQUIRE(dns_db_iszone(db) || dns_db_isstub(db)); result = dns_db_findnode(db, dns_db_origin(db), ISC_FALSE, &node); if (result != ISC_R_SUCCESS) diff --git a/lib/dns/include/dns/db.h b/lib/dns/include/dns/db.h index 31729413fb..90a971b21f 100644 --- a/lib/dns/include/dns/db.h +++ b/lib/dns/include/dns/db.h @@ -164,6 +164,7 @@ struct dns_db { }; #define DNS_DBATTR_CACHE 0x01 +#define DNS_DBATTR_STUB 0x02 /* * Options that can be specified for dns_db_find(). @@ -190,7 +191,7 @@ struct dns_db { isc_result_t dns_db_create(isc_mem_t *mctx, const char *db_type, dns_name_t *origin, - isc_boolean_t cache, dns_rdataclass_t rdclass, + dns_dbtype_t type, dns_rdataclass_t rdclass, unsigned int argc, char *argv[], dns_db_t **dbp); /* * Create a new database using implementation 'db_type'. @@ -201,9 +202,6 @@ dns_db_create(isc_mem_t *mctx, const char *db_type, dns_name_t *origin, * caller may do whatever they like with 'origin' and its storage once the * call returns. * - * If 'cache' is ISC_TRUE, then cache semantics will be used, otherwise - * zone semantics will apply. - * * DB implementation-specific parameters are passed using argc and argv. * * Requires: @@ -280,8 +278,6 @@ dns_db_iscache(dns_db_t *db); /* * Does 'db' have cache semantics? * - * Note: dns_db_iscache(db) == !dns_db_iszone(db) - * * Requires: * * 'db' is a valid database. @@ -296,7 +292,19 @@ dns_db_iszone(dns_db_t *db); /* * Does 'db' have zone semantics? * - * Note: dns_db_iszone(db) == !dns_db_iscache(db) + * Requires: + * + * 'db' is a valid database. + * + * Returns: + * ISC_TRUE 'db' has zone semantics + * ISC_FALSE otherwise + */ + +isc_boolean_t +dns_db_isstub(dns_db_t *db); +/* + * Does 'db' have stub semantics? * * Requires: * diff --git a/lib/dns/include/dns/types.h b/lib/dns/include/dns/types.h index 6d3d7b1fa8..422208f4fe 100644 --- a/lib/dns/include/dns/types.h +++ b/lib/dns/include/dns/types.h @@ -129,6 +129,10 @@ typedef enum { dns_one_answer, dns_many_answers } dns_transfer_format_t; +typedef enum { + dns_dbtype_zone = 0, dns_dbtype_cache = 1, dns_dbtype_stub = 3 +} dns_dbtype_t; + /* * These are generated by gen.c for dns_rdatatype_t and dns_rdataclass_t. */ diff --git a/lib/dns/rbtdb.c b/lib/dns/rbtdb.c index 546e78a106..ce47de1992 100644 --- a/lib/dns/rbtdb.c +++ b/lib/dns/rbtdb.c @@ -268,6 +268,8 @@ typedef struct rbtdb_dbiterator { } rbtdb_dbiterator_t; +#define IS_STUB(rbtdb) (((rbtdb)->common.attributes & DNS_DBATTR_STUB) != 0) + /* * Locking * @@ -1048,7 +1050,8 @@ zone_zonecut_callback(dns_rbtnode_t *node, dns_name_t *name, void *arg) { */ found = header; break; - } else if (node != onode) { + } else if (node != onode || + IS_STUB(search->rbtdb)) { /* * We've found an NS rdataset that * isn't at the origin node. We check @@ -1707,7 +1710,9 @@ zone_find(dns_db_t *db, dns_name_t *name, dns_dbversion_t *version, * The node may be a zone cut itself. If it might be one, * make sure we check for it later. */ - if (node->find_callback && node != search.rbtdb->origin_node) + if (node->find_callback && + (node != search.rbtdb->origin_node || + IS_STUB(search.rbtdb))) maybe_zonecut = ISC_TRUE; } @@ -3323,7 +3328,8 @@ delegating_type(dns_rbtdb_t *rbtdb, dns_rbtnode_t *node, else return (ISC_FALSE); } else if (type == dns_rdatatype_dname || - (type == dns_rdatatype_ns && node != rbtdb->origin_node)) + (type == dns_rdatatype_ns && + (node != rbtdb->origin_node || IS_STUB(rbtdb)))) return (ISC_TRUE); return (ISC_FALSE); } @@ -3813,7 +3819,7 @@ dns_rbtdb64_create #else dns_rbtdb_create #endif - (isc_mem_t *mctx, dns_name_t *origin, isc_boolean_t cache, + (isc_mem_t *mctx, dns_name_t *origin, dns_dbtype_t type, dns_rdataclass_t rdclass, unsigned int argc, char *argv[], dns_db_t **dbp) { @@ -3832,9 +3838,12 @@ dns_rbtdb_create memset(rbtdb, '\0', sizeof *rbtdb); dns_name_init(&rbtdb->common.origin, NULL); rbtdb->common.attributes = 0; - if (cache) { + if (type == dns_dbtype_cache) { rbtdb->common.methods = &cache_methods; rbtdb->common.attributes |= DNS_DBATTR_CACHE; + } else if (type == dns_dbtype_stub) { + rbtdb->common.methods = &zone_methods; + rbtdb->common.attributes |= DNS_DBATTR_STUB; } else rbtdb->common.methods = &zone_methods; rbtdb->common.rdclass = rdclass; diff --git a/lib/dns/rbtdb.h b/lib/dns/rbtdb.h index 989505da5c..57b49c115b 100644 --- a/lib/dns/rbtdb.h +++ b/lib/dns/rbtdb.h @@ -32,7 +32,7 @@ ISC_LANG_BEGINDECLS isc_result_t -dns_rbtdb_create(isc_mem_t *mctx, dns_name_t *base, isc_boolean_t is_cache, +dns_rbtdb_create(isc_mem_t *mctx, dns_name_t *base, dns_dbtype_t type, dns_rdataclass_t rdclass, unsigned int argc, char *argv[], dns_db_t **dbp); diff --git a/lib/dns/rootns.c b/lib/dns/rootns.c index 70f4664c1e..d24c14a218 100644 --- a/lib/dns/rootns.c +++ b/lib/dns/rootns.c @@ -73,7 +73,7 @@ dns_rootns_create(isc_mem_t *mctx, dns_rdataclass_t rdclass, REQUIRE(target != NULL && *target == NULL); - result = dns_db_create(mctx, "rbt", dns_rootname, ISC_FALSE, + result = dns_db_create(mctx, "rbt", dns_rootname, dns_dbtype_zone, rdclass, 0, NULL, &db); if (result != ISC_R_SUCCESS) return (result); diff --git a/lib/dns/view.c b/lib/dns/view.c index e7b8d66a01..b348ce5422 100644 --- a/lib/dns/view.c +++ b/lib/dns/view.c @@ -577,7 +577,7 @@ dns_view_find(dns_view_t *view, dns_name_t *name, dns_rdatatype_t type, { isc_result_t result; dns_db_t *db; - isc_boolean_t is_zone; + isc_boolean_t is_cache; dns_rdataset_t zrdataset, zsigrdataset; dns_zone_t *zone; @@ -613,7 +613,7 @@ dns_view_find(dns_view_t *view, dns_name_t *name, dns_rdatatype_t type, else goto cleanup; - is_zone = dns_db_iszone(db); + is_cache = dns_db_iscache(db); db_find: /* @@ -629,13 +629,13 @@ dns_view_find(dns_view_t *view, dns_name_t *name, dns_rdatatype_t type, if (sigrdataset != NULL && dns_rdataset_isassociated(sigrdataset)) dns_rdataset_disassociate(sigrdataset); - if (is_zone) { + if (!is_cache) { if (view->cachedb != NULL) { /* * Either the answer is in the cache, or we * don't know it. */ - is_zone = ISC_FALSE; + is_cache = ISC_TRUE; dns_db_detach(&db); dns_db_attach(view->cachedb, &db); goto db_find; @@ -665,7 +665,7 @@ dns_view_find(dns_view_t *view, dns_name_t *name, dns_rdatatype_t type, * We found an answer, but the cache may be better. * Remember what we've got and go look in the cache. */ - is_zone = ISC_FALSE; + is_cache = ISC_TRUE; dns_rdataset_clone(rdataset, &zrdataset); dns_rdataset_disassociate(rdataset); if (sigrdataset != NULL && @@ -780,7 +780,7 @@ dns_view_findzonecut(dns_view_t *view, dns_name_t *name, dns_name_t *fname, { isc_result_t result; dns_db_t *db; - isc_boolean_t is_zone, use_zone, try_hints; + isc_boolean_t is_cache, use_zone, try_hints; dns_zone_t *zone; dns_name_t *zfname; dns_rdataset_t zrdataset, zsigrdataset; @@ -836,13 +836,13 @@ dns_view_findzonecut(dns_view_t *view, dns_name_t *name, dns_name_t *fname, */ goto cleanup; } - is_zone = dns_db_iszone(db); + is_cache = dns_db_iscache(db); db_find: /* * Look for the zonecut. */ - if (is_zone) { + if (!is_cache) { result = dns_db_find(db, name, NULL, dns_rdatatype_ns, options, now, NULL, fname, rdataset, sigrdataset); if (result == DNS_R_DELEGATION) @@ -867,7 +867,7 @@ dns_view_findzonecut(dns_view_t *view, dns_name_t *name, dns_name_t *fname, } dns_db_detach(&db); dns_db_attach(view->cachedb, &db); - is_zone = ISC_FALSE; + is_cache = ISC_TRUE; goto db_find; } } else { diff --git a/lib/dns/xfrin.c b/lib/dns/xfrin.c index 0b6f06ff0c..3452df266c 100644 --- a/lib/dns/xfrin.c +++ b/lib/dns/xfrin.c @@ -15,7 +15,7 @@ * SOFTWARE. */ -/* $Id: xfrin.c,v 1.77 2000/06/02 18:59:19 bwelling Exp $ */ +/* $Id: xfrin.c,v 1.78 2000/06/07 02:38:37 marka Exp $ */ #include @@ -251,7 +251,7 @@ axfr_makedb(dns_xfrin_ctx_t *xfr, dns_db_t **dbp) { return (dns_db_create(xfr->mctx, /* XXX */ "rbt", /* XXX guess */ &xfr->name, - ISC_FALSE, + dns_dbtype_zone, xfr->rdclass, 0, NULL, /* XXX guess */ dbp));