]> git.ipfire.org Git - thirdparty/knot-dns.git/commitdiff
zone/reverse: refactoring: pointer at reversed zone is a structure
authorLibor Peltan <libor.peltan@nic.cz>
Wed, 10 Sep 2025 15:48:32 +0000 (17:48 +0200)
committerDaniel Salzman <daniel.salzman@nic.cz>
Fri, 12 Sep 2025 05:50:09 +0000 (07:50 +0200)
src/knot/events/handlers/load.c
src/knot/zone/reverse.c
src/knot/zone/zone.c
src/knot/zone/zone.h
src/knot/zone/zonedb-load.c

index e7903f7923208015567212bb4360ed79947477a2..a6bf4e8668080324316b29f9572fdd497e9299be 100644 (file)
@@ -137,7 +137,7 @@ int event_load(conf_t *conf, zone_t *zone)
 
                // If configured, add reverse records to zone contents
                const knot_dname_t *fail_fwd = NULL;
-               ret = zones_reverse(&zone->reverse_from, zf_conts, &fail_fwd);
+               ret = zones_reverse(&zone->include_from, zf_conts, &fail_fwd);
                if (ret == KNOT_ETRYAGAIN) {
                        knot_dname_txt_storage_t forw_str;
                        (void)knot_dname_to_str(forw_str, fail_fwd, sizeof(forw_str));
index 472083baa964e82537e983d32e0adaa9b55b69d6..98734e7578f6d9261c76344c99f74e4a0af6d476 100644 (file)
@@ -129,9 +129,10 @@ int zone_reverse(zone_contents_t *from, zone_contents_t *to_conts,
 int zones_reverse(list_t *zones, zone_contents_t *to_conts, const knot_dname_t **fail_fwd)
 {
        int ret = KNOT_EOK;
-       ptrnode_t *n;
+       zone_include_t *n;
        WALK_LIST(n, *zones) {
-               zone_t *z = n->d;
+               zone_t *z = n->include;
+               assert(n->method == ZONE_INCLUDE_REVERSE);
                rcu_read_lock();
                if (z->contents == NULL) {
                        ret = KNOT_ETRYAGAIN;
index 0084dccab7a825ad0c209b0586cd951670f0bae1..489e849d54c77738bf15e57f745036e5ad217aa7 100644 (file)
@@ -181,7 +181,7 @@ zone_t* zone_new(const knot_dname_t *name)
        // Initialize query modules list.
        init_list(&zone->query_modules);
 
-       init_list(&zone->reverse_from);
+       init_list(&zone->include_from);
        init_list(&zone->internal_notify);
 
        ATOMIC_INIT(zone->backup_ctx, NULL);
@@ -242,7 +242,7 @@ void zone_free(zone_t **zone_ptr)
 
        conf_deactivate_modules(&zone->query_modules, &zone->query_plan);
 
-       ptrlist_free(&zone->reverse_from, NULL);
+       zone_includes_clear(zone);
        ptrlist_free(&zone->internal_notify, NULL);
 
        ATOMIC_DEINIT(zone->backup_ctx);
@@ -815,6 +815,38 @@ int zone_dump_to_dir(conf_t *conf, zone_t *zone, const char *dir)
        return zonefile_write_skip(target, zone->contents, conf);
 }
 
+int zone_includes_add(zone_t *zone, zone_t *include, zone_include_method_t method)
+{
+       zone_include_t *n = calloc(1, sizeof(*n));
+       if (n == NULL) {
+               return KNOT_ENOMEM;
+       }
+       n->include = include;
+       n->method = method;
+       add_tail(&zone->include_from, &n->n);
+       return KNOT_EOK;
+}
+
+void zone_includes_rem(zone_t *zone, zone_t *include)
+{
+       zone_include_t *n, *nxt;
+       WALK_LIST_DELSAFE(n, nxt, zone->include_from) {
+               if (n->include == include) {
+                       rem_node(&n->n);
+                       free(n);
+               }
+       }
+}
+
+void zone_includes_clear(zone_t *zone)
+{
+       zone_include_t *n, *next;
+       WALK_LIST_DELSAFE(n, next, zone->include_from) {
+               free(n);
+       }
+       init_list(&zone->include_from);
+}
+
 void zone_local_notify_subscribe(zone_t *zone, zone_t *subscribe)
 {
        ptrlist_add(&zone->internal_notify, subscribe, NULL);
index 561264e6712e57640594c27313f789396414e7ec..894a7abc3e8bfbf1366fab227a2b22d53e4d9463 100644 (file)
@@ -124,7 +124,7 @@ typedef struct zone
        const char *catalog_group;
 
        /*! \brief Auto-generated reverse zones... */
-       list_t reverse_from;
+       list_t include_from;
        list_t internal_notify;
 
        /*! \brief Preferred master lock. Also used for flags access. */
@@ -137,6 +137,16 @@ typedef struct zone
        struct query_plan *query_plan;
 } zone_t;
 
+typedef enum {
+       ZONE_INCLUDE_REVERSE,
+} zone_include_method_t;
+
+typedef struct {
+       node_t n;
+       zone_t *include;
+       zone_include_method_t method;
+} zone_include_t;
+
 /*!
  * \brief Creates new zone with empty zone content.
  *
@@ -284,6 +294,13 @@ int zone_master_try(conf_t *conf, zone_t *zone, zone_master_cb callback,
 /*! \brief Write zone contents to zonefile, but into different directory. */
 int zone_dump_to_dir(conf_t *conf, zone_t *zone, const char *dir);
 
+/*!
+ * \brief Zone inclusion (reverse generation) related ops.
+ */
+int zone_includes_add(zone_t *zone, zone_t *include, zone_include_method_t method);
+void zone_includes_rem(zone_t *zone, zone_t *include);
+void zone_includes_clear(zone_t *zone);
+
 void zone_local_notify_subscribe(zone_t *zone, zone_t *subscribe);
 void zone_local_notify_unsubscribe(zone_t *zone, zone_t *subscribe);
 void zone_local_notify(zone_t *zone);
index 4e2db0d4634de5d7149f6a881251cc06b7f29690..eee25c1ea3cb84923195399cc2d8f28e10c19d76 100644 (file)
@@ -389,11 +389,11 @@ static void reg_reverse(conf_t *conf, knot_zonedb_t *db_new, zone_t *zone)
                return;
        }
 
-       ptrnode_t *n;
-       WALK_LIST(n, zone->reverse_from) {
-               zone_local_notify_unsubscribe(n->d, zone);
+       zone_include_t *n;
+       WALK_LIST(n, zone->include_from) {
+               zone_local_notify_unsubscribe(n->include, zone);
        }
-       ptrlist_free(&zone->reverse_from, NULL);
+       zone_includes_clear(zone);
 
        conf_val_t val = conf_zone_get(conf, C_REVERSE_GEN, zone->name);
        while (val.code == KNOT_EOK) {
@@ -405,7 +405,7 @@ static void reg_reverse(conf_t *conf, knot_zonedb_t *db_new, zone_t *zone)
                        log_zone_warning(zone->name, "zone to reverse %s does not exist",
                                         forw_str);
                } else {
-                       ptrlist_add(&zone->reverse_from, forw, NULL);
+                       (void)zone_includes_add(zone, forw, ZONE_INCLUDE_REVERSE);
                        zone_local_notify_subscribe(forw, zone);
                }
                conf_val_next(&val);
@@ -418,15 +418,16 @@ static void unreg_reverse(zone_t *zone)
                return;
        }
 
-       ptrnode_t *n;
-       WALK_LIST(n, zone->reverse_from) {
-               zone_local_notify_unsubscribe(n->d, zone);
+       zone_include_t *in;
+       WALK_LIST(in, zone->include_from) {
+               zone_local_notify_unsubscribe(in->include, zone);
        }
-       ptrlist_free(&zone->reverse_from, NULL);
+       zone_includes_clear(zone);
 
+       ptrnode_t *n;
        WALK_LIST(n, zone->internal_notify) {
                zone_t *reverse = n->d;
-               ptrlist_find_rem(&reverse->reverse_from, zone, NULL);
+               zone_includes_rem(reverse, zone);
        }
        ptrlist_free(&zone->internal_notify, NULL);
 }