]> git.ipfire.org Git - thirdparty/knot-dns.git/commitdiff
zonedb-load: fix zone loading which were included by conf-set include
authorDaniel Salzman <daniel.salzman@nic.cz>
Wed, 8 Oct 2025 16:06:00 +0000 (18:06 +0200)
committerDaniel Salzman <daniel.salzman@nic.cz>
Thu, 9 Oct 2025 08:39:30 +0000 (10:39 +0200)
src/knot/zone/zonedb-load.c
tests-extra/tests/config/include/test.py
tests-extra/tools/dnstest/server.py

index e27737b1ab09936a583a80380d038ec0aacebb1c..f7135b0df3f34caa95abdc018331f8d37394d5db 100644 (file)
@@ -483,6 +483,26 @@ static knot_zonedb_t *create_zonedb_commit(conf_t *conf, server_t *server)
                return NULL;
        }
 
+       assert(conf->io.flags & CONF_IO_FACTIVE);
+       bool include = conf->io.flags & CONF_IO_FDIFF_ZONES;
+
+       // Insert possibly added zones by conf-set include.
+       if (include) {
+               for (conf_iter_t it = conf_iter(conf, C_ZONE); it.code == KNOT_EOK;
+                    conf_iter_next(conf, &it)) {
+                       conf_val_t id = conf_iter_id(conf, &it);
+                       const knot_dname_t *name = conf_dname(&id);
+                       zone_t *zone = knot_zonedb_find(db_new, name);
+                       if (zone == NULL) { // Create an included zone.
+                               zone = get_zone(conf, name, server, NULL);
+                               if (zone == NULL) {
+                                       continue;
+                               }
+                               knot_zonedb_insert(db_new, zone);
+                       }
+               }
+       }
+
        if (conf->io.zones != NULL) {
                trie_it_t *trie_it = trie_it_begin(conf->io.zones);
                for (; !trie_it_finished(trie_it); trie_it_next(trie_it)) {
index 113e61e675c5805e8258239c5c1b16fd239cfcd6..a448faab9acf809d761a3d937bed11433a999516 100644 (file)
@@ -30,6 +30,12 @@ ctl = libknot.control.KnotCtl()
 
 t.start()
 
+knot.use_confdb = True
+knot.gen_confile()
+knot.ctl("conf-import %s" % knot.confile, availability=False)
+knot.stop()
+knot.start()
+
 ctl.connect(os.path.join(knot.dir, "knot.sock"))
 
 ctl.send_block(cmd="conf-begin")
@@ -37,9 +43,11 @@ resp = ctl.receive_block()
 
 ctl.send_block(cmd="conf-set", section="include", data=added_file)
 resp = ctl.receive_block()
-# Cannot commit as it reloads the server without this include!
 
-ctl.send_block(cmd="conf-get", section="zone")
+ctl.send_block(cmd="conf-commit")
+resp = ctl.receive_block()
+
+ctl.send_block(cmd="conf-read", section="zone")
 resp = ctl.receive_block()
 
 isset(ZONE1 in resp['zone'], ZONE1)
@@ -47,15 +55,20 @@ isset(ZONE2 in resp['zone'], ZONE2)
 isset(ZONE3 in resp['zone'], ZONE3)
 isset(ZONE4 in resp['zone'], ZONE4)
 
-ctl.send_block(cmd="conf-commit")
-resp = ctl.receive_block()
-
 ctl.send_block(cmd="conf-read", section="server")
 resp = ctl.receive_block()
 
 isset('tcp-max-clients' in resp['server'], "server section item not set")
 isset('5' in resp['server']['tcp-max-clients'], "server section item value not set")
 
+ctl.send_block(cmd="zone-status")
+resp = ctl.receive_block()
+
+isset(ZONE1 in resp, ZONE1)
+isset(ZONE2 in resp, ZONE2)
+isset(ZONE3 in resp, ZONE3)
+isset(ZONE4 in resp, ZONE4)
+
 ctl.send(libknot.control.KnotCtlType.END)
 ctl.close()
 
index 88b890145f3525730532057f14eabd2ad270d449..22fa8a1545d6d4beef4889048e7c4a398f455f96 100644 (file)
@@ -158,6 +158,7 @@ class Server(object):
         self.start_params = None
         self.ctl_params = None
         self.ctl_params_append = None # The last parameter wins.
+        self.use_confdb = False
 
         self.data_dir = None
 
@@ -2048,8 +2049,12 @@ class Knot(Server):
         s.item_str("quic", "debug")
         s.end()
 
-        self.start_params = ["-c", self.confile]
-        self.ctl_params = ["-c", self.confile, "-t", "15"]
+        if self.use_confdb:
+            conf_params = ["-C", os.path.join(self.dir, "confdb")]
+        else:
+            conf_params = ["-c", self.confile]
+        self.start_params = conf_params
+        self.ctl_params = conf_params + ["-t", "15"]
         if self.ctl_params_append != None:
             self.ctl_params += self.ctl_params_append