]> git.ipfire.org Git - dbl.git/commitdiff
exporters: Drop exporting zones using dnspython
authorMichael Tremer <michael.tremer@ipfire.org>
Thu, 11 Dec 2025 20:24:51 +0000 (20:24 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Thu, 11 Dec 2025 20:24:51 +0000 (20:24 +0000)
dnspython is taking hours as well as several gigabytes of memory to
generate a zone file. This is not sustainable at all since we want to be
able to push out updates fast.

I could not find any alternatives, but we are able to generate ZONEMD
records externally.

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
configure.ac
src/dnsbl/exporters.py

index a570ec34968e330d98fca0e53ed0ed5528a2b3eb..f707debd3d21b18266d595f0d7744466055a1781 100644 (file)
@@ -52,7 +52,6 @@ AC_PROG_MKDIR_P
 # Python
 AM_PATH_PYTHON([3.13])
 
-AX_PYTHON_MODULE([dns], [fatal])
 AX_PYTHON_MODULE([httpx], [fatal])
 AX_PYTHON_MODULE([rich], [fatal])
 AX_PYTHON_MODULE([sqlmodel], [fatal])
index d41305403a4217e0657d507bc7feda015cecae09..dfc6ddf0f534f67cb30c25c5d30944402ef59487 100644 (file)
@@ -20,9 +20,6 @@
 
 import abc
 import datetime
-import dns.name
-import dns.rdataclass
-import dns.zone
 import io
 import tarfile
 
@@ -154,88 +151,47 @@ class HostsExporter(TextExporter):
 
 
 class ZoneExporter(TextExporter):
-       def export(self, f, ttl=60, rpz_action="."):
+       def export(self, f, ttl=60):
                # Write the header
                self.write_header(f, ";")
 
-               # Create the origin
-               origin = dns.name.from_text(self.list.zone)
-
-               # Create a new zone
-               zone = dns.zone.Zone(origin)
-
                # Make the serial
                serial = self.list.updated_at.strftime("%s")
 
-               # Create the SOA
-               soa = dns.rdataset.from_text(
-                       dns.rdataclass.IN,
-                       dns.rdatatype.SOA,
-                       ttl,
-                       " ".join((
-                               "master.lwldns.net.",
-                               "hostmaster.ipfire.org.",
-                               serial,
-                               "3600",
-                               "600",
-                               "3600000",
-                               "%s" % ttl,
-                       )),
-               )
-               zone.replace_rdataset(origin, soa)
+               # Write $ORIGIN
+               f.write("$ORIGIN %s\n" % self.list.zone)
+
+               # Set the TTL
+               f.write("$TTL %s\n" % ttl)
+
+               # Write the SOA
+               f.write(" ".join((
+                       "@",
+                       "IN",
+                       "SOA",
+                       "master.lwldns.net.",
+                       "hostmaster.ipfire.org.",
+                       serial,
+                       "3600",
+                       "600",
+                       "3600000",
+                       "%s" % ttl,
+               )))
+               f.write("\n")
 
                # XXX Add NS
-
-               # Compute the rrset
-               rrset = dns.rdataset.from_text(
-                       dns.rdataclass.IN, self.type, ttl, self.content,
-               )
+               f.write("@ IN NS master.lwldns.net.\n")
 
                # Write all domains
                for domain in self.list.domains:
-                       zone.replace_rdataset(
-                               dns.name.from_text(
-                                       "%s.%s" % (domain, self.list.zone), origin=origin,
-                               ),
-                               rrset,
-                       )
-
-               # Add ZONEMD
-               self.add_zonemd(zone, ttl)
-
-               # Write the zone to file
-               zone.to_file(f)
-
-       def add_zonemd(self, zone, ttl):
-               """
-                       Adds ZONEMD records to the zone
-               """
-               # Create a new ZONEMD record
-               rrset = dns.rdataset.Rdataset(
-                       dns.rdataclass.IN, dns.rdatatype.ZONEMD, ttl=ttl,
-               )
-
-               # Compute the digest for SHA-512 and SHA-384
-               algorithms = (
-                       dns.zone.DigestHashAlgorithm.SHA512,
-                       dns.zone.DigestHashAlgorithm.SHA384,
-               )
-
-               # Compute the digests
-               for algorithm in algorithms:
-                       rrset.add(
-                               zone.compute_digest(algorithm),
-                       )
-
-               # Add the ZONEMD record
-               zone.replace_rdataset(zone.origin, rrset)
+                       f.write("%s IN %s %s\n" % (domain, self.type, self.content))
 
 
 class BlocklistExporter(ZoneExporter):
        """
                Exports the list as a regular DNSBL zone file
        """
-       type = dns.rdatatype.A
+       type = "A"
        content = "127.0.0.2"
 
 
@@ -243,7 +199,7 @@ class RPZExporter(ZoneExporter):
        """
                Exports the list as a RPZ zone file
        """
-       type = dns.rdatatype.CNAME
+       type = "CNAME"
        content = "."