From 6fcfd0c35d3fd6aea3d36ad002b68e59ac62fdc7 Mon Sep 17 00:00:00 2001 From: Brian Wellington Date: Mon, 6 Mar 2000 19:06:07 +0000 Subject: [PATCH] ssutables are now attached/detached; zones get ssutables from config structs --- bin/named/zoneconf.c | 10 +++++ lib/dns/config/confzone.c | 6 +-- lib/dns/include/dns/ssu.h | 25 +++++++++-- lib/dns/ssu.c | 90 ++++++++++++++++++++++++++++++--------- lib/dns/zone.c | 4 +- lib/dns/zoneconf.c | 10 +++++ 6 files changed, 116 insertions(+), 29 deletions(-) diff --git a/bin/named/zoneconf.c b/bin/named/zoneconf.c index f5eaed7477..0b34a28052 100644 --- a/bin/named/zoneconf.c +++ b/bin/named/zoneconf.c @@ -26,6 +26,7 @@ #include #include #include +#include /* XXX copied from zone.c */ #define MAX_XFER_TIME (2*3600) /* Documented default is 2 hours. */ @@ -103,6 +104,7 @@ dns_zone_configure(dns_c_ctx_t *cctx, dns_aclconfctx_t *ac, in_port_t port; struct in_addr in4addr_any; isc_sockaddr_t sockaddr_any4, sockaddr_any6; + dns_ssutable_t *ssutable; in4addr_any.s_addr = htonl(INADDR_ANY); isc_sockaddr_fromin(&sockaddr_any4, &in4addr_any, 0); @@ -195,6 +197,14 @@ dns_zone_configure(dns_c_ctx_t *cctx, dns_aclconfctx_t *ac, } dns_zone_setidleout(zone, maxxfr); + ssutable = NULL; + result = dns_c_zone_getssuauth(czone, &ssutable); + if (result == ISC_R_SUCCESS) { + dns_ssutable_t *newssutable = NULL; + dns_ssutable_attach(ssutable, &newssutable); + dns_zone_setssutable(zone, newssutable); + } + break; diff --git a/lib/dns/config/confzone.c b/lib/dns/config/confzone.c index 984f9daacd..07ee00bcea 100644 --- a/lib/dns/config/confzone.c +++ b/lib/dns/config/confzone.c @@ -3770,7 +3770,7 @@ master_zone_clear(isc_mem_t *mem, dns_c_masterzone_t *mzone) dns_c_ipmatchlist_detach(&mzone->allow_update); if (mzone->ssuauth != NULL) - dns_ssutable_destroy(&mzone->ssuauth); + dns_ssutable_detach(&mzone->ssuauth); if (mzone->allow_update_forwarding != NULL) dns_c_ipmatchlist_detach(&mzone->allow_update_forwarding); @@ -3830,7 +3830,7 @@ slave_zone_clear(isc_mem_t *mem, dns_c_slavezone_t *szone) dns_c_ipmatchlist_detach(&szone->allow_update); if (szone->ssuauth != NULL) - dns_ssutable_destroy(&szone->ssuauth); + dns_ssutable_detach(&szone->ssuauth); if (szone->allow_update_forwarding != NULL) dns_c_ipmatchlist_detach(&szone->allow_update_forwarding); @@ -3875,7 +3875,7 @@ stub_zone_clear(isc_mem_t *mem, dns_c_stubzone_t *tzone) dns_c_ipmatchlist_detach(&tzone->allow_update); if (tzone->ssuauth != NULL) - dns_ssutable_destroy(&tzone->ssuauth); + dns_ssutable_detach(&tzone->ssuauth); if (tzone->allow_update_forwarding != NULL) dns_c_ipmatchlist_detach(&tzone->allow_update_forwarding); diff --git a/lib/dns/include/dns/ssu.h b/lib/dns/include/dns/ssu.h index e3953d43af..2126718378 100644 --- a/lib/dns/include/dns/ssu.h +++ b/lib/dns/include/dns/ssu.h @@ -31,13 +31,30 @@ dns_ssutable_create(isc_mem_t *mctx, dns_ssutable_t **table); */ void -dns_ssutable_destroy(dns_ssutable_t **table); +dns_ssutable_attach(dns_ssutable_t *source, dns_ssutable_t **targetp); /* - * Destroys a simple-secure-update rule table. *table is set to NULL. + * Attach '*targetp' to 'source'. * * Requires: - * 'table' is not NULL - * '*table' is a valid SSU table + * 'source' is a valid SSU table + * 'targetp' points to a NULL dns_ssutable_t *. + * + * Ensures: + * *targetp is attached to source. + */ + +void +dns_ssutable_detach(dns_ssutable_t **tablep); +/* + * Detach '*tablep' from its simple-secure-update rule table. + * + * Requires: + * 'tablep' points to a valid dns_ssutable_t + * + * Ensures: + * *tablep is NULL + * If '*tablep' is the last reference to the SSU table, all + * resources used by the table will be freed. */ isc_result_t diff --git a/lib/dns/ssu.c b/lib/dns/ssu.c index 3ab849eb5b..fb30e34af1 100644 --- a/lib/dns/ssu.c +++ b/lib/dns/ssu.c @@ -1,5 +1,5 @@ /* - * $Id: ssu.c,v 1.5 2000/03/02 20:39:23 brister Exp $ + * $Id: ssu.c,v 1.6 2000/03/06 19:06:00 bwelling Exp $ * Principal Author: Brian Wellington */ @@ -13,6 +13,8 @@ #include #include #include +#include +#include #include #include @@ -37,34 +39,44 @@ struct dns_ssurule { struct dns_ssutable { isc_uint32_t magic; isc_mem_t *mctx; + unsigned int references; + isc_mutex_t lock; ISC_LIST(dns_ssurule_t) rules; }; isc_result_t -dns_ssutable_create(isc_mem_t *mctx, dns_ssutable_t **table) { - REQUIRE(table != NULL && *table == NULL); +dns_ssutable_create(isc_mem_t *mctx, dns_ssutable_t **tablep) { + isc_result_t result; + dns_ssutable_t *table; + + REQUIRE(tablep != NULL && *tablep == NULL); REQUIRE(mctx != NULL); - *table = isc_mem_get(mctx, sizeof(dns_ssutable_t)); - if (*table == NULL) + table = isc_mem_get(mctx, sizeof(dns_ssutable_t)); + if (table == NULL) return (ISC_R_NOMEMORY); - - (*table)->mctx = mctx; - ISC_LIST_INIT((*table)->rules); - (*table)->magic = SSUTABLEMAGIC; + result = isc_mutex_init(&table->lock); + if (result != ISC_R_SUCCESS) { + isc_mem_put(mctx, table, sizeof(dns_ssutable_t)); + return (result); + } + table->references = 1; + table->mctx = mctx; + ISC_LIST_INIT(table->rules); + table->magic = SSUTABLEMAGIC; + *tablep = table; return (ISC_R_SUCCESS); } -void -dns_ssutable_destroy(dns_ssutable_t **table) { +static inline void +destroy(dns_ssutable_t *table) { isc_mem_t *mctx; - REQUIRE(table != NULL); - REQUIRE(VALID_SSUTABLE(*table)); + REQUIRE(VALID_SSUTABLE(table)); - mctx = (*table)->mctx; - while (!ISC_LIST_EMPTY((*table)->rules)) { - dns_ssurule_t *rule = ISC_LIST_HEAD((*table)->rules); + mctx = table->mctx; + while (!ISC_LIST_EMPTY(table->rules)) { + dns_ssurule_t *rule = ISC_LIST_HEAD(table->rules); if (rule->identity != NULL) { dns_name_free(rule->identity, mctx); isc_mem_put(mctx, rule->identity, sizeof(dns_name_t)); @@ -76,13 +88,51 @@ dns_ssutable_destroy(dns_ssutable_t **table) { if (rule->types != NULL) isc_mem_put(mctx, rule->types, rule->ntypes * sizeof(dns_rdatatype_t)); - ISC_LIST_UNLINK((*table)->rules, rule, link); + ISC_LIST_UNLINK(table->rules, rule, link); rule->magic = 0; isc_mem_put(mctx, rule, sizeof(dns_ssurule_t)); } - (*table)->magic = 0; - isc_mem_put(mctx, *table, sizeof(dns_ssutable_t)); - *table = NULL; + isc_mutex_destroy(&table->lock); + table->magic = 0; + isc_mem_put(mctx, table, sizeof(dns_ssutable_t)); +} + +void +dns_ssutable_attach(dns_ssutable_t *source, dns_ssutable_t **targetp) { + REQUIRE(VALID_SSUTABLE(source)); + REQUIRE(targetp != NULL && *targetp == NULL); + + LOCK(&source->lock); + + INSIST(source->references > 0); + source->references++; + INSIST(source->references != 0); + + UNLOCK(&source->lock); + + *targetp = source; +} + +void +dns_ssutable_detach(dns_ssutable_t **tablep) { + dns_ssutable_t *table; + isc_boolean_t done = ISC_FALSE; + + REQUIRE(tablep != NULL); + table = *tablep; + REQUIRE(VALID_SSUTABLE(table)); + + LOCK(&table->lock); + + INSIST(table->references > 0); + if (--table->references == 0) + done = ISC_TRUE; + UNLOCK(&table->lock); + + *tablep = NULL; + + if (done) + destroy(table); } isc_result_t diff --git a/lib/dns/zone.c b/lib/dns/zone.c index 0128240ced..b1df62174d 100644 --- a/lib/dns/zone.c +++ b/lib/dns/zone.c @@ -15,7 +15,7 @@ * SOFTWARE. */ - /* $Id: zone.c,v 1.84 2000/02/25 17:34:05 gson Exp $ */ + /* $Id: zone.c,v 1.85 2000/03/06 19:06:01 bwelling Exp $ */ #include @@ -409,7 +409,7 @@ zone_free(dns_zone_t *zone) { if (dns_name_dynamic(&zone->origin)) dns_name_free(&zone->origin, zone->mctx); if (zone->ssutable != NULL) - dns_ssutable_destroy(&zone->ssutable); + dns_ssutable_detach(&zone->ssutable); /* last stuff */ isc_mutex_destroy(&zone->lock); diff --git a/lib/dns/zoneconf.c b/lib/dns/zoneconf.c index f5eaed7477..0b34a28052 100644 --- a/lib/dns/zoneconf.c +++ b/lib/dns/zoneconf.c @@ -26,6 +26,7 @@ #include #include #include +#include /* XXX copied from zone.c */ #define MAX_XFER_TIME (2*3600) /* Documented default is 2 hours. */ @@ -103,6 +104,7 @@ dns_zone_configure(dns_c_ctx_t *cctx, dns_aclconfctx_t *ac, in_port_t port; struct in_addr in4addr_any; isc_sockaddr_t sockaddr_any4, sockaddr_any6; + dns_ssutable_t *ssutable; in4addr_any.s_addr = htonl(INADDR_ANY); isc_sockaddr_fromin(&sockaddr_any4, &in4addr_any, 0); @@ -195,6 +197,14 @@ dns_zone_configure(dns_c_ctx_t *cctx, dns_aclconfctx_t *ac, } dns_zone_setidleout(zone, maxxfr); + ssutable = NULL; + result = dns_c_zone_getssuauth(czone, &ssutable); + if (result == ISC_R_SUCCESS) { + dns_ssutable_t *newssutable = NULL; + dns_ssutable_attach(ssutable, &newssutable); + dns_zone_setssutable(zone, newssutable); + } + break;