From: Michael Tremer Date: Thu, 11 Dec 2025 20:24:51 +0000 (+0000) Subject: exporters: Drop exporting zones using dnspython X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=75930821a05b58dc550b72975e20613ead54230c;p=dbl.git exporters: Drop exporting zones using dnspython 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 --- diff --git a/configure.ac b/configure.ac index a570ec3..f707deb 100644 --- a/configure.ac +++ b/configure.ac @@ -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]) diff --git a/src/dnsbl/exporters.py b/src/dnsbl/exporters.py index d413054..dfc6ddf 100644 --- a/src/dnsbl/exporters.py +++ b/src/dnsbl/exporters.py @@ -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 = "."