1- /* $NetBSD: zone.c,v 1.21 2025/01/26 16:25:26 christos Exp $ */
1+ /* $NetBSD: zone.c,v 1.22 2025/01/27 02: 16:05 christos Exp $ */
22
33/*
44 * Copyright (C) Internet Systems Consortium, Inc. ("ISC")
@@ -260,6 +260,9 @@ struct dns_zone {
260260 /* Unlocked */
261261 unsigned int magic;
262262 isc_mutex_t lock;
263+ #ifndef _LP64
264+ isc_mutex_t atomic_lock;
265+ #endif
263266#ifdef DNS_ZONE_CHECKLOCK
264267 bool locked;
265268#endif /* ifdef DNS_ZONE_CHECKLOCK */
@@ -289,8 +292,13 @@ struct dns_zone {
289292 int32_t journalsize;
290293 dns_rdataclass_t rdclass;
291294 dns_zonetype_t type;
295+ #ifdef _LP64
292296 atomic_uint_fast64_t flags;
293297 atomic_uint_fast64_t options;
298+ #else
299+ uint64_t flags;
300+ uint64_t options;
301+ #endif
294302 unsigned int db_argc;
295303 char **db_argv;
296304 isc_time_t expiretime;
@@ -431,7 +439,11 @@ struct dns_zone {
431439 /*%
432440 * Autosigning/key-maintenance options
433441 */
442+ #ifdef _LP64
434443 atomic_uint_fast64_t keyopts;
444+ #else
445+ uint64_t keyopts;
446+ #endif
435447
436448 /*%
437449 * True if added by "rndc addzone"
@@ -518,10 +530,38 @@ struct dns_zone {
518530 (_z)->diff = (d); \
519531 (_z)->offline = false; \
520532 } while (0)
533+ #ifdef _LP64
534+ #define ISC_ZONE_GET(z, f) atomic_load_relaxed(&(z)->f)
535+ #define ISC_ZONE_SET(z, f, o) atomic_fetch_or(&(z)->f, (o))
536+ #define DNS_ZONE_CLR(z, f, o) atomic_fetch_and(&(z)->f, ~(o))
537+ #else
538+ #define ISC_ZONE_GET(z, f) \
539+ ({ \
540+ isc_mutex_lock(&(z)->atomic_lock); \
541+ uint64_t x = (z)->f; \
542+ isc_mutex_unlock(&(z)->atomic_lock); \
543+ x; \
544+ })
545+ #define ISC_ZONE_SET(z, f, o) \
546+ ({ \
547+ isc_mutex_lock(&(z)->atomic_lock); \
548+ uint64_t x = ((z)->f | (o)); \
549+ isc_mutex_unlock(&(z)->atomic_lock); \
550+ x; \
551+ })
552+ #define ISC_ZONE_CLR(z, f, o) \
553+ ({ \
554+ isc_mutex_lock(&(z)->atomic_lock); \
555+ uint64_t x = ((z)->f & ~(o)); \
556+ isc_mutex_unlock(&(z)->atomic_lock); \
557+ x; \
558+ })
559+ #endif
560+ #define ISC_ZONE_TEST(z, f, o) ((ISC_ZONE_GET(z, f) & (o)) != 0)
521561
522- #define DNS_ZONE_FLAG(z, f) ((atomic_load_relaxed(&(z)-> flags) & (f)) != 0 )
523- #define DNS_ZONE_SETFLAG(z, f) atomic_fetch_or(&(z)-> flags, (f) )
524- #define DNS_ZONE_CLRFLAG(z, f) atomic_fetch_and(&(z)-> flags, ~(f) )
562+ #define DNS_ZONE_FLAG(z, f) ISC_ZONE_TEST(z, flags, f )
563+ #define DNS_ZONE_SETFLAG(z, f) ISC_ZONE_SET(z, flags, f )
564+ #define DNS_ZONE_CLRFLAG(z, f) ISC_ZONE_CLR(z, flags, f )
525565typedef enum {
526566 DNS_ZONEFLG_REFRESH = 0x00000001U, /*%< refresh check in progress */
527567 DNS_ZONEFLG_NEEDDUMP = 0x00000002U, /*%< zone need consolidation */
@@ -571,14 +611,14 @@ typedef enum {
571611 DNS_ZONEFLG___MAX = UINT64_MAX, /* trick to make the ENUM 64-bit wide */
572612} dns_zoneflg_t;
573613
574- #define DNS_ZONE_OPTION(z, o) ((atomic_load_relaxed(&(z)->options) & (o)) != 0)
575- #define DNS_ZONE_SETOPTION(z, o) atomic_fetch_or(&(z)->options, (o))
576- #define DNS_ZONE_CLROPTION(z, o) atomic_fetch_and(&(z)->options, ~(o))
577614
578- #define DNS_ZONEKEY_OPTION(z, o) \
579- ((atomic_load_relaxed(&(z)->keyopts) & (o)) != 0)
580- #define DNS_ZONEKEY_SETOPTION(z, o) atomic_fetch_or(&(z)->keyopts, (o))
581- #define DNS_ZONEKEY_CLROPTION(z, o) atomic_fetch_and(&(z)->keyopts, ~(o))
615+ #define DNS_ZONE_OPTION(z, o) ISC_ZONE_TEST(z, options, o)
616+ #define DNS_ZONE_SETOPTION(z, o) ISC_ZONE_SET(z, options, o)
617+ #define DNS_ZONE_CLROPTION(z, o) ISC_ZONE_CLR(z, options, o)
618+ #define DNS_ZONEKEY_OPTION(z, o) ISC_ZONE_TEST(z, keyopts, o)
619+ #define DNS_ZONEKEY_SETOPTION(z, o) ISC_ZONE_SET(z, keyopts, o)
620+ #define DNS_ZONEKEY_CLROPTION(z, o) ISC_ZONE_CLR(z, keyopts, o)
621+
582622
583623/* Flags for zone_load() */
584624typedef enum {
@@ -1166,6 +1206,9 @@ dns_zone_create(dns_zone_t **zonep, isc_mem_t *mctx, unsigned int tid) {
11661206
11671207 isc_mem_attach(mctx, &zone->mctx);
11681208 isc_mutex_init(&zone->lock);
1209+ #ifndef _LP64
1210+ isc_mutex_init(&zone->atomic_lock);
1211+ #endif
11691212 ZONEDB_INITLOCK(&zone->dblock);
11701213
11711214 isc_refcount_init(&zone->references, 1);
@@ -1374,6 +1417,9 @@ zone_free(dns_zone_t *zone) {
13741417 /* last stuff */
13751418 ZONEDB_DESTROYLOCK(&zone->dblock);
13761419 isc_mutex_destroy(&zone->lock);
1420+ #ifndef _LP64
1421+ isc_mutex_destroy(&zone->atomic_lock);
1422+ #endif
13771423 zone->magic = 0;
13781424 isc_mem_putanddetach(&zone->mctx, zone, sizeof(*zone));
13791425}
@@ -5803,7 +5849,7 @@ dns_zoneopt_t
58035849dns_zone_getoptions(dns_zone_t *zone) {
58045850 REQUIRE(DNS_ZONE_VALID(zone));
58055851
5806- return atomic_load_relaxed(& zone-> options);
5852+ return ISC_ZONE_GET( zone, options);
58075853}
58085854
58095855void
@@ -5821,7 +5867,7 @@ unsigned int
58215867dns_zone_getkeyopts(dns_zone_t *zone) {
58225868 REQUIRE(DNS_ZONE_VALID(zone));
58235869
5824- return atomic_load_relaxed(& zone-> keyopts);
5870+ return ISC_ZONE_GET( zone, keyopts);
58255871}
58265872
58275873isc_result_t
@@ -11431,7 +11477,7 @@ zone_refresh(dns_zone_t *zone) {
1143111477 * in progress at a time.
1143211478 */
1143311479
11434- oldflags = atomic_load(& zone-> flags);
11480+ oldflags = ISC_ZONE_GET( zone, flags);
1143511481 if (dns_remote_addresses(&zone->primaries) == NULL) {
1143611482 DNS_ZONE_SETFLAG(zone, DNS_ZONEFLG_NOPRIMARIES);
1143711483 if ((oldflags & DNS_ZONEFLG_NOPRIMARIES) == 0) {
0 commit comments