mirror of
https://gitlab.isc.org/isc-projects/bind9
synced 2025-08-29 13:38:26 +00:00
Use a refcount instead of an explicit mutex and integer.
This commit is contained in:
parent
8126e45e8c
commit
100d0d2ec6
@ -15,13 +15,13 @@
|
|||||||
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* $Id: tsig.h,v 1.37 2001/01/09 21:53:36 bwelling Exp $ */
|
/* $Id: tsig.h,v 1.38 2001/02/13 03:57:06 bwelling Exp $ */
|
||||||
|
|
||||||
#ifndef DNS_TSIG_H
|
#ifndef DNS_TSIG_H
|
||||||
#define DNS_TSIG_H 1
|
#define DNS_TSIG_H 1
|
||||||
|
|
||||||
#include <isc/lang.h>
|
#include <isc/lang.h>
|
||||||
#include <isc/mutex.h>
|
#include <isc/refcount.h>
|
||||||
#include <isc/rwlock.h>
|
#include <isc/rwlock.h>
|
||||||
#include <isc/stdtime.h>
|
#include <isc/stdtime.h>
|
||||||
|
|
||||||
@ -63,10 +63,7 @@ struct dns_tsigkey {
|
|||||||
isc_stdtime_t inception; /* start of validity period */
|
isc_stdtime_t inception; /* start of validity period */
|
||||||
isc_stdtime_t expire; /* end of validity period */
|
isc_stdtime_t expire; /* end of validity period */
|
||||||
dns_tsig_keyring_t *ring; /* the enclosing keyring */
|
dns_tsig_keyring_t *ring; /* the enclosing keyring */
|
||||||
isc_mutex_t lock;
|
isc_refcount_t refs; /* reference counter */
|
||||||
/* Locked */
|
|
||||||
isc_uint32_t refs; /* reference counter */
|
|
||||||
/* Unlocked */
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#define dns_tsigkey_identity(tsigkey) \
|
#define dns_tsigkey_identity(tsigkey) \
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* $Id: tsig.c,v 1.105 2001/01/22 20:27:04 bwelling Exp $
|
* $Id: tsig.c,v 1.106 2001/02/13 03:57:04 bwelling Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
@ -25,6 +25,7 @@
|
|||||||
#include <isc/buffer.h>
|
#include <isc/buffer.h>
|
||||||
#include <isc/mem.h>
|
#include <isc/mem.h>
|
||||||
#include <isc/print.h>
|
#include <isc/print.h>
|
||||||
|
#include <isc/refcount.h>
|
||||||
#include <isc/string.h> /* Required for HP/UX (and others?) */
|
#include <isc/string.h> /* Required for HP/UX (and others?) */
|
||||||
#include <isc/util.h>
|
#include <isc/util.h>
|
||||||
|
|
||||||
@ -126,6 +127,7 @@ dns_tsigkey_createfromkey(dns_name_t *name, dns_name_t *algorithm,
|
|||||||
{
|
{
|
||||||
dns_tsigkey_t *tkey;
|
dns_tsigkey_t *tkey;
|
||||||
isc_result_t ret;
|
isc_result_t ret;
|
||||||
|
unsigned int refs = 0;
|
||||||
|
|
||||||
REQUIRE(key == NULL || *key == NULL);
|
REQUIRE(key == NULL || *key == NULL);
|
||||||
REQUIRE(name != NULL);
|
REQUIRE(name != NULL);
|
||||||
@ -182,7 +184,6 @@ dns_tsigkey_createfromkey(dns_name_t *name, dns_name_t *algorithm,
|
|||||||
|
|
||||||
tkey->key = dstkey;
|
tkey->key = dstkey;
|
||||||
tkey->ring = ring;
|
tkey->ring = ring;
|
||||||
tkey->refs = 0;
|
|
||||||
|
|
||||||
if (ring != NULL) {
|
if (ring != NULL) {
|
||||||
RWLOCK(&ring->lock, isc_rwlocktype_write);
|
RWLOCK(&ring->lock, isc_rwlocktype_write);
|
||||||
@ -191,23 +192,17 @@ dns_tsigkey_createfromkey(dns_name_t *name, dns_name_t *algorithm,
|
|||||||
RWUNLOCK(&ring->lock, isc_rwlocktype_write);
|
RWUNLOCK(&ring->lock, isc_rwlocktype_write);
|
||||||
goto cleanup_algorithm;
|
goto cleanup_algorithm;
|
||||||
}
|
}
|
||||||
tkey->refs++;
|
refs++;
|
||||||
RWUNLOCK(&ring->lock, isc_rwlocktype_write);
|
RWUNLOCK(&ring->lock, isc_rwlocktype_write);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (key != NULL)
|
if (key != NULL)
|
||||||
tkey->refs++;
|
refs++;
|
||||||
|
isc_refcount_init(&tkey->refs, refs);
|
||||||
tkey->generated = generated;
|
tkey->generated = generated;
|
||||||
tkey->inception = inception;
|
tkey->inception = inception;
|
||||||
tkey->expire = expire;
|
tkey->expire = expire;
|
||||||
tkey->mctx = mctx;
|
tkey->mctx = mctx;
|
||||||
ret = isc_mutex_init(&tkey->lock);
|
|
||||||
if (ret != ISC_R_SUCCESS) {
|
|
||||||
UNEXPECTED_ERROR(__FILE__, __LINE__,
|
|
||||||
"isc_mutex_init() failed: %s",
|
|
||||||
isc_result_totext(ret));
|
|
||||||
return (ISC_R_UNEXPECTED);
|
|
||||||
}
|
|
||||||
|
|
||||||
tkey->magic = TSIG_MAGIC;
|
tkey->magic = TSIG_MAGIC;
|
||||||
|
|
||||||
@ -281,9 +276,7 @@ dns_tsigkey_attach(dns_tsigkey_t *source, dns_tsigkey_t **targetp) {
|
|||||||
REQUIRE(VALID_TSIG_KEY(source));
|
REQUIRE(VALID_TSIG_KEY(source));
|
||||||
REQUIRE(targetp != NULL && *targetp == NULL);
|
REQUIRE(targetp != NULL && *targetp == NULL);
|
||||||
|
|
||||||
LOCK(&source->lock);
|
isc_refcount_increment(&source->refs, NULL);
|
||||||
source->refs++;
|
|
||||||
UNLOCK(&source->lock);
|
|
||||||
*targetp = source;
|
*targetp = source;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -303,27 +296,25 @@ tsigkey_free(dns_tsigkey_t *key) {
|
|||||||
dns_name_free(key->creator, key->mctx);
|
dns_name_free(key->creator, key->mctx);
|
||||||
isc_mem_put(key->mctx, key->creator, sizeof(dns_name_t));
|
isc_mem_put(key->mctx, key->creator, sizeof(dns_name_t));
|
||||||
}
|
}
|
||||||
DESTROYLOCK(&key->lock);
|
isc_refcount_destroy(&key->refs);
|
||||||
isc_mem_put(key->mctx, key, sizeof(dns_tsigkey_t));
|
isc_mem_put(key->mctx, key, sizeof(dns_tsigkey_t));
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
dns_tsigkey_detach(dns_tsigkey_t **keyp) {
|
dns_tsigkey_detach(dns_tsigkey_t **keyp) {
|
||||||
dns_tsigkey_t *key;
|
dns_tsigkey_t *key;
|
||||||
isc_boolean_t should_free = ISC_FALSE;
|
unsigned int refs;
|
||||||
|
|
||||||
REQUIRE(keyp != NULL);
|
REQUIRE(keyp != NULL);
|
||||||
REQUIRE(VALID_TSIG_KEY(*keyp));
|
REQUIRE(VALID_TSIG_KEY(*keyp));
|
||||||
key = *keyp;
|
|
||||||
*keyp = NULL;
|
|
||||||
|
|
||||||
LOCK(&key->lock);
|
key = *keyp;
|
||||||
key->refs--;
|
isc_refcount_decrement(&key->refs, &refs);
|
||||||
if (key->refs == 0)
|
|
||||||
should_free = ISC_TRUE;
|
if (refs == 0)
|
||||||
UNLOCK(&key->lock);
|
|
||||||
if (should_free)
|
|
||||||
tsigkey_free(key);
|
tsigkey_free(key);
|
||||||
|
|
||||||
|
*keyp = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -1125,18 +1116,14 @@ dns_tsigkey_find(dns_tsigkey_t **tsigkey, dns_name_t *name,
|
|||||||
* The key has expired.
|
* The key has expired.
|
||||||
*/
|
*/
|
||||||
RWUNLOCK(&ring->lock, isc_rwlocktype_read);
|
RWUNLOCK(&ring->lock, isc_rwlocktype_read);
|
||||||
LOCK(&key->lock);
|
isc_refcount_decrement(&key->refs, NULL);
|
||||||
key->refs--;
|
|
||||||
UNLOCK(&key->lock);
|
|
||||||
RWLOCK(&ring->lock, isc_rwlocktype_write);
|
RWLOCK(&ring->lock, isc_rwlocktype_write);
|
||||||
(void) dns_rbt_deletename(ring->keys, name, ISC_FALSE);
|
(void) dns_rbt_deletename(ring->keys, name, ISC_FALSE);
|
||||||
RWUNLOCK(&ring->lock, isc_rwlocktype_write);
|
RWUNLOCK(&ring->lock, isc_rwlocktype_write);
|
||||||
return (ISC_R_NOTFOUND);
|
return (ISC_R_NOTFOUND);
|
||||||
}
|
}
|
||||||
|
|
||||||
LOCK(&key->lock);
|
isc_refcount_increment(&key->refs, NULL);
|
||||||
key->refs++;
|
|
||||||
UNLOCK(&key->lock);
|
|
||||||
RWUNLOCK(&ring->lock, isc_rwlocktype_read);
|
RWUNLOCK(&ring->lock, isc_rwlocktype_read);
|
||||||
*tsigkey = key;
|
*tsigkey = key;
|
||||||
return (ISC_R_SUCCESS);
|
return (ISC_R_SUCCESS);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user