#include <isc/lang.h>
#include <isc/magic.h>
#include <isc/radix.h>
+#include <isc/refcount.h>
#include <dns/types.h>
struct dns_iptable {
unsigned int magic;
isc_mem_t *mctx;
- isc_refcount_t refcount;
+ isc_refcount_t references;
isc_radix_tree_t *radix;
ISC_LINK(dns_iptable_t) nextincache;
};
+/* Add -DDNS_IPTABLE_TRACE=1 to CFLAGS for detailed reference tracing */
+
#define DNS_IPTABLE_MAGIC ISC_MAGIC('T', 'a', 'b', 'l')
#define DNS_IPTABLE_VALID(a) ISC_MAGIC_VALID(a, DNS_IPTABLE_MAGIC)
* Merge one IP table into another one.
*/
-void
-dns_iptable_attach(dns_iptable_t *source, dns_iptable_t **target);
-
-void
-dns_iptable_detach(dns_iptable_t **tabp);
+#if DNS_IPTABLE_TRACE
+#define dns_iptable_ref(ptr) dns_iptable__ref(ptr, __func__, __FILE__, __LINE__)
+#define dns_iptable_unref(ptr) \
+ dns_iptable__unref(ptr, __func__, __FILE__, __LINE__)
+#define dns_iptable_attach(ptr, ptrp) \
+ dns_iptable__attach(ptr, ptrp, __func__, __FILE__, __LINE__)
+#define dns_iptable_detach(ptrp) \
+ dns_iptable__detach(ptrp, __func__, __FILE__, __LINE__)
+ISC_REFCOUNT_TRACE_DECL(dns_iptable);
+#else
+ISC_REFCOUNT_DECL(dns_iptable);
+#endif
ISC_LANG_ENDDECLS
#include <dns/acl.h>
-static void
-destroy_iptable(dns_iptable_t *dtab);
-
/*
* Create a new IP table and the underlying radix structure
*/
dns_iptable_create(isc_mem_t *mctx, dns_iptable_t **target) {
dns_iptable_t *tab = isc_mem_get(mctx, sizeof(*tab));
*tab = (dns_iptable_t){
- .refcount = 1,
+ .references = ISC_REFCOUNT_INITIALIZER(1),
.magic = DNS_IPTABLE_MAGIC,
};
isc_mem_attach(mctx, &tab->mctx);
return (ISC_R_SUCCESS);
}
-void
-dns_iptable_attach(dns_iptable_t *source, dns_iptable_t **target) {
- REQUIRE(DNS_IPTABLE_VALID(source));
- isc_refcount_increment(&source->refcount);
- *target = source;
-}
-
-void
-dns_iptable_detach(dns_iptable_t **tabp) {
- REQUIRE(tabp != NULL && DNS_IPTABLE_VALID(*tabp));
- dns_iptable_t *tab = *tabp;
- *tabp = NULL;
-
- if (isc_refcount_decrement(&tab->refcount) == 1) {
- isc_refcount_destroy(&tab->refcount);
- destroy_iptable(tab);
- }
-}
-
static void
-destroy_iptable(dns_iptable_t *dtab) {
+dns__iptable_destroy(dns_iptable_t *dtab) {
REQUIRE(DNS_IPTABLE_VALID(dtab));
+ dtab->magic = 0;
+
if (dtab->radix != NULL) {
isc_radix_destroy(dtab->radix, NULL);
dtab->radix = NULL;
}
- dtab->magic = 0;
isc_mem_putanddetach(&dtab->mctx, dtab, sizeof(*dtab));
}
+
+#if DNS_IPTABLE_TRACE
+ISC_REFCOUNT_TRACE_IMPL(dns_iptable, dns__iptable_destroy);
+#else
+ISC_REFCOUNT_IMPL(dns_iptable, dns__iptable_destroy);
+#endif