dns_acl_t *acl = isc_mem_get(mctx, sizeof(*acl));
*acl = (dns_acl_t){
- .refcount = 1,
+ .references = ISC_REFCOUNT_INITIALIZER(1),
.nextincache = ISC_LINK_INITIALIZER,
.elements = isc_mem_cget(mctx, n, sizeof(acl->elements[0])),
.alloc = n,
return (false);
}
-void
-dns_acl_attach(dns_acl_t *source, dns_acl_t **target) {
- REQUIRE(DNS_ACL_VALID(source));
-
- isc_refcount_increment(&source->refcount);
- *target = source;
-}
-
static void
-destroy(dns_acl_t *dacl) {
+dns__acl_destroy(dns_acl_t *dacl) {
unsigned int i;
dns_acl_port_transports_t *port_proto;
port_proto = next;
}
- isc_refcount_destroy(&dacl->refcount);
+ isc_refcount_destroy(&dacl->references);
dacl->magic = 0;
isc_mem_putanddetach(&dacl->mctx, dacl, sizeof(*dacl));
}
-void
-dns_acl_detach(dns_acl_t **aclp) {
- REQUIRE(aclp != NULL && DNS_ACL_VALID(*aclp));
- dns_acl_t *acl = *aclp;
- *aclp = NULL;
-
- if (isc_refcount_decrement(&acl->refcount) == 1) {
- destroy(acl);
- }
-}
+#if DNS_ACL_TRACE
+ISC_REFCOUNT_TRACE_IMPL(dns_acl, dns__acl_destroy);
+#else
+ISC_REFCOUNT_IMPL(dns_acl, dns__acl_destroy);
+#endif
static isc_once_t insecure_prefix_once = ISC_ONCE_INIT;
static isc_mutex_t insecure_prefix_lock;
dns_aclenv_create(isc_mem_t *mctx, dns_aclenv_t **envp) {
dns_aclenv_t *env = isc_mem_get(mctx, sizeof(*env));
*env = (dns_aclenv_t){
- .references = 1,
+ .references = ISC_REFCOUNT_INITIALIZER(1),
.magic = DNS_ACLENV_MAGIC,
};
isc_mem_putanddetach(&aclenv->mctx, aclenv, sizeof(*aclenv));
}
-void
-dns_aclenv_attach(dns_aclenv_t *source, dns_aclenv_t **targetp) {
- REQUIRE(VALID_ACLENV(source));
- REQUIRE(targetp != NULL && *targetp == NULL);
-
- isc_refcount_increment(&source->references);
- *targetp = source;
-}
-
-void
-dns_aclenv_detach(dns_aclenv_t **aclenvp) {
- dns_aclenv_t *aclenv = NULL;
-
- REQUIRE(aclenvp != NULL && VALID_ACLENV(*aclenvp));
-
- aclenv = *aclenvp;
- *aclenvp = NULL;
-
- if (isc_refcount_decrement(&aclenv->references) == 1) {
- dns__aclenv_destroy(aclenv);
- }
-}
+#if DNS_ACL_TRACE
+ISC_REFCOUNT_TRACE_IMPL(dns_aclenv, dns__aclenv_destroy);
+#else
+ISC_REFCOUNT_IMPL(dns_aclenv, dns__aclenv_destroy);
+#endif
void
dns_acl_add_port_transports(dns_acl_t *acl, const in_port_t port,
* Address match list handling.
*/
+/* Add -DDNS_ACL_TRACE=1 to CFLAGS for detailed reference tracing */
+
/***
*** Imports
***/
struct dns_acl {
unsigned int magic;
isc_mem_t *mctx;
- isc_refcount_t refcount;
+ isc_refcount_t references;
dns_iptable_t *iptable;
dns_aclelement_t *elements;
bool has_negatives;
* an unexpected positive match in the parent ACL.
*/
-void
-dns_acl_attach(dns_acl_t *source, dns_acl_t **target);
-/*%<
- * Attach to acl 'source'.
- *
- * Requires:
- *\li 'source' to be a valid acl.
- *\li 'target' to be non NULL and '*target' to be NULL.
- */
-
-void
-dns_acl_detach(dns_acl_t **aclp);
-/*%<
- * Detach the acl. On final detach the acl must not be linked on any
- * list.
- *
- * Requires:
- *\li '*aclp' to be a valid acl.
- *
- * Insists:
- *\li '*aclp' is not linked on final detach.
- */
+#if DNS_ACL_TRACE
+#define dns_acl_ref(ptr) dns_acl__ref(ptr, __func__, __FILE__, __LINE__)
+#define dns_acl_unref(ptr) dns_acl__unref(ptr, __func__, __FILE__, __LINE__)
+#define dns_acl_attach(ptr, ptrp) \
+ dns_acl__attach(ptr, ptrp, __func__, __FILE__, __LINE__)
+#define dns_acl_detach(ptrp) dns_acl__detach(ptrp, __func__, __FILE__, __LINE__)
+ISC_REFCOUNT_TRACE_DECL(dns_acl);
+#else
+ISC_REFCOUNT_DECL(dns_acl);
+#endif
bool
dns_acl_isinsecure(const dns_acl_t *a);
* Attach the 'localhost' and 'localnets' arguments to 'env' ACL environment
*/
-void
-dns_aclenv_attach(dns_aclenv_t *source, dns_aclenv_t **targetp);
-/*%<
- * Attach '*targetp' to ACL environment 'source'.
- *
- * Requires:
- *\li 'source' is a valid ACL environment.
- *\li 'targetp' is not NULL and '*targetp' is NULL.
- */
-
-void
-dns_aclenv_detach(dns_aclenv_t **aclenvp);
-/*%<
- * Detach an ACL environment; on final detach, destroy it.
- *
- * Requires:
- *\li '*aclenvp' to be a valid ACL environment
- */
+#if DNS_ACL_TRACE
+#define dns_aclenv_ref(ptr) dns_aclenv__ref(ptr, __func__, __FILE__, __LINE__)
+#define dns_aclenv_unref(ptr) \
+ dns_aclenv__unref(ptr, __func__, __FILE__, __LINE__)
+#define dns_aclenv_attach(ptr, ptrp) \
+ dns_aclenv__attach(ptr, ptrp, __func__, __FILE__, __LINE__)
+#define dns_aclenv_detach(ptrp) \
+ dns_aclenv__detach(ptrp, __func__, __FILE__, __LINE__)
+ISC_REFCOUNT_TRACE_DECL(dns_aclenv);
+#else
+ISC_REFCOUNT_DECL(dns_aclenv);
+#endif
isc_result_t
dns_acl_match(const isc_netaddr_t *reqaddr, const dns_name_t *reqsigner,