]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Move the slabheader attribute helpers to private header
authorOndřej Surý <ondrej@isc.org>
Tue, 12 Aug 2025 10:21:56 +0000 (12:21 +0200)
committerOndřej Surý <ondrej@isc.org>
Fri, 15 Aug 2025 05:35:14 +0000 (07:35 +0200)
The slabheader.c, qpzone.c and qpcache.c had couple of shared macros
that were copied and paste between the units.  Move these common
attributes access macros into private header, so these can be shared
among the three compilation units.

lib/dns/qpcache.c
lib/dns/qpzone.c
lib/dns/rdataslab.c
lib/dns/rdataslab_p.h [new file with mode: 0644]
tests/dns/qpzone_test.c

index 9d02239a248a1ae46dd04e936ffdf811bdcab0bd..c5de17203a02e16d4a47459eccc527deeac837bc 100644 (file)
@@ -59,6 +59,7 @@
 
 #include "db_p.h"
 #include "qpcache_p.h"
+#include "rdataslab_p.h"
 
 #ifndef DNS_QPCACHE_LOG_STATS_LEVEL
 #define DNS_QPCACHE_LOG_STATS_LEVEL 3
                        goto failure;        \
        } while (0)
 
-#define EXISTS(header)                                 \
-       ((atomic_load_acquire(&(header)->attributes) & \
-         DNS_SLABHEADERATTR_NONEXISTENT) == 0)
-#define NXDOMAIN(header)                               \
-       ((atomic_load_acquire(&(header)->attributes) & \
-         DNS_SLABHEADERATTR_NXDOMAIN) != 0)
-#define STALE(header)                                  \
-       ((atomic_load_acquire(&(header)->attributes) & \
-         DNS_SLABHEADERATTR_STALE) != 0)
-#define STALE_WINDOW(header)                           \
-       ((atomic_load_acquire(&(header)->attributes) & \
-         DNS_SLABHEADERATTR_STALE_WINDOW) != 0)
-#define OPTOUT(header)                                 \
-       ((atomic_load_acquire(&(header)->attributes) & \
-         DNS_SLABHEADERATTR_OPTOUT) != 0)
-#define NEGATIVE(header)                               \
-       ((atomic_load_acquire(&(header)->attributes) & \
-         DNS_SLABHEADERATTR_NEGATIVE) != 0)
-#define PREFETCH(header)                               \
-       ((atomic_load_acquire(&(header)->attributes) & \
-         DNS_SLABHEADERATTR_PREFETCH) != 0)
-#define ZEROTTL(header)                                \
-       ((atomic_load_acquire(&(header)->attributes) & \
-         DNS_SLABHEADERATTR_ZEROTTL) != 0)
-#define ANCIENT(header)                                \
-       ((atomic_load_acquire(&(header)->attributes) & \
-         DNS_SLABHEADERATTR_ANCIENT) != 0)
-#define STATCOUNT(header)                              \
-       ((atomic_load_acquire(&(header)->attributes) & \
-         DNS_SLABHEADERATTR_STATCOUNT) != 0)
-
 #define STALE_TTL(header, qpdb) \
        (NXDOMAIN(header) ? 0 : qpdb->common.serve_stale_ttl)
 
index 65f6c211b6eb374827319106a28a406522d00fa2..76eb96c9d554825d32556cb9390bf0f24d62626a 100644 (file)
@@ -62,6 +62,7 @@
 
 #include "db_p.h"
 #include "qpzone_p.h"
+#include "rdataslab_p.h"
 
 #define CHECK(op)                            \
        do {                                 \
                        goto failure;        \
        } while (0)
 
-#define EXISTS(header)                                 \
-       ((atomic_load_acquire(&(header)->attributes) & \
-         DNS_SLABHEADERATTR_NONEXISTENT) == 0)
-#define IGNORE(header)                                 \
-       ((atomic_load_acquire(&(header)->attributes) & \
-         DNS_SLABHEADERATTR_IGNORE) != 0)
-#define RESIGN(header)                                 \
-       ((atomic_load_acquire(&(header)->attributes) & \
-         DNS_SLABHEADERATTR_RESIGN) != 0)
-#define OPTOUT(header)                                 \
-       ((atomic_load_acquire(&(header)->attributes) & \
-         DNS_SLABHEADERATTR_OPTOUT) != 0)
-#define STATCOUNT(header)                              \
-       ((atomic_load_acquire(&(header)->attributes) & \
-         DNS_SLABHEADERATTR_STATCOUNT) != 0)
-
 #define HEADERNODE(h) ((qpznode_t *)((h)->node))
 
 #define QPDB_ATTR_LOADED  0x01
index f5d4cb24543d9fdb89649a02f6642e6869a7cfec..82e810c3efca174b6b1703b20c751652362f8b42 100644 (file)
 #include <dns/rdataslab.h>
 #include <dns/stats.h>
 
-#define CASESET(header)                                \
-       ((atomic_load_acquire(&(header)->attributes) & \
-         DNS_SLABHEADERATTR_CASESET) != 0)
-#define CASEFULLYLOWER(header)                         \
-       ((atomic_load_acquire(&(header)->attributes) & \
-         DNS_SLABHEADERATTR_CASEFULLYLOWER) != 0)
-#define NONEXISTENT(header)                            \
-       ((atomic_load_acquire(&(header)->attributes) & \
-         DNS_SLABHEADERATTR_NONEXISTENT) != 0)
-#define NEGATIVE(header)                               \
-       ((atomic_load_acquire(&(header)->attributes) & \
-         DNS_SLABHEADERATTR_NEGATIVE) != 0)
+#include "rdataslab_p.h"
 
 /*
  * The rdataslab structure allows iteration to occur in both load order
@@ -915,10 +904,10 @@ dns_slabheader_destroy(dns_slabheader_t **headerp) {
        isc_mem_t *mctx = header->node->mctx;
        dns_db_deletedata(header->node, header);
 
-       if (NONEXISTENT(header)) {
-               size = sizeof(*header);
-       } else {
+       if (EXISTS(header)) {
                size = dns_rdataslab_size(header);
+       } else {
+               size = sizeof(*header);
        }
 
        isc_mem_put(mctx, header, size);
diff --git a/lib/dns/rdataslab_p.h b/lib/dns/rdataslab_p.h
new file mode 100644 (file)
index 0000000..e3b4fbb
--- /dev/null
@@ -0,0 +1,59 @@
+/*
+ * Copyright (C) Internet Systems Consortium, Inc. ("ISC")
+ *
+ * SPDX-License-Identifier: MPL-2.0
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, you can obtain one at https://mozilla.org/MPL/2.0/.
+ *
+ * See the COPYRIGHT file distributed with this work for additional
+ * information regarding copyright ownership.
+ */
+
+#pragma once
+
+#include <dns/rdataslab.h>
+
+#define ANCIENT(header)                                \
+       ((atomic_load_acquire(&(header)->attributes) & \
+         DNS_SLABHEADERATTR_ANCIENT) != 0)
+#define CASEFULLYLOWER(header)                         \
+       ((atomic_load_acquire(&(header)->attributes) & \
+         DNS_SLABHEADERATTR_CASEFULLYLOWER) != 0)
+#define CASESET(header)                                \
+       ((atomic_load_acquire(&(header)->attributes) & \
+         DNS_SLABHEADERATTR_CASESET) != 0)
+#define EXISTS(header)                                 \
+       ((atomic_load_acquire(&(header)->attributes) & \
+         DNS_SLABHEADERATTR_NONEXISTENT) == 0)
+#define IGNORE(header)                                 \
+       ((atomic_load_acquire(&(header)->attributes) & \
+         DNS_SLABHEADERATTR_IGNORE) != 0)
+#define NEGATIVE(header)                               \
+       ((atomic_load_acquire(&(header)->attributes) & \
+         DNS_SLABHEADERATTR_NEGATIVE) != 0)
+#define NXDOMAIN(header)                               \
+       ((atomic_load_acquire(&(header)->attributes) & \
+         DNS_SLABHEADERATTR_NXDOMAIN) != 0)
+#define OPTOUT(header)                                 \
+       ((atomic_load_acquire(&(header)->attributes) & \
+         DNS_SLABHEADERATTR_OPTOUT) != 0)
+#define PREFETCH(header)                               \
+       ((atomic_load_acquire(&(header)->attributes) & \
+         DNS_SLABHEADERATTR_PREFETCH) != 0)
+#define RESIGN(header)                                 \
+       ((atomic_load_acquire(&(header)->attributes) & \
+         DNS_SLABHEADERATTR_RESIGN) != 0)
+#define STALE(header)                                  \
+       ((atomic_load_acquire(&(header)->attributes) & \
+         DNS_SLABHEADERATTR_STALE) != 0)
+#define STALE_WINDOW(header)                           \
+       ((atomic_load_acquire(&(header)->attributes) & \
+         DNS_SLABHEADERATTR_STALE_WINDOW) != 0)
+#define STATCOUNT(header)                              \
+       ((atomic_load_acquire(&(header)->attributes) & \
+         DNS_SLABHEADERATTR_STATCOUNT) != 0)
+#define ZEROTTL(header)                                \
+       ((atomic_load_acquire(&(header)->attributes) & \
+         DNS_SLABHEADERATTR_ZEROTTL) != 0)
index 73cd7514a1bbae11d04264b3f8847982f50037c6..ad3d5b972a65be4194038cdc8fd2cc63573995f5 100644 (file)
@@ -34,6 +34,8 @@
 #include <dns/rdatastruct.h>
 #define KEEP_BEFORE
 
+#include "rdataslab_p.h"
+
 /* Include the main file */
 
 #pragma GCC diagnostic push
 #undef CHECK
 #include <tests/dns.h>
 
-#define CASESET(header)                                \
-       ((atomic_load_acquire(&(header)->attributes) & \
-         DNS_SLABHEADERATTR_CASESET) != 0)
-
 const char *ownercase_vectors[12][2] = {
        {
                "AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz",