Commit a6733246 authored by Mark Andrews's avatar Mark Andrews
Browse files

240. [func] databases now come in three flavours: zone, cache

                        and stub.
parent bb36b310
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.
......
......@@ -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));
......
......@@ -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()");
......
......@@ -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()");
......
......@@ -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
......
......@@ -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);
......
......@@ -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);
......
......@@ -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 <config.h>
......@@ -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;
......
......@@ -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)
......
......@@ -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:
*
......
......@@ -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.
*/
......
......@@ -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;
......
......@@ -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);
......
......@@ -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);
......
......@@ -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 {
......
......@@ -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 <config.h>
......@@ -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));
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment