Commit 6fcfd0c3 authored by Brian Wellington's avatar Brian Wellington
Browse files

ssutables are now attached/detached; zones get ssutables from config structs

parent 2b71493a
......@@ -26,6 +26,7 @@
#include <dns/types.h>
#include <dns/zone.h>
#include <dns/zoneconf.h>
#include <dns/ssu.h>
/* 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;
......
......@@ -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);
......
......@@ -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
......
/*
* $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 <isc/magic.h>
#include <isc/result.h>
#include <isc/types.h>
#include <isc/mutex.h>
#include <isc/util.h>
#include <dns/name.h>
#include <dns/ssu.h>
......@@ -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
......
......@@ -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 <config.h>
......@@ -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);
......
......@@ -26,6 +26,7 @@
#include <dns/types.h>
#include <dns/zone.h>
#include <dns/zoneconf.h>
#include <dns/ssu.h>
/* 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;
......
Supports Markdown
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