From: Peter Thomassen <4242683+peterthomassen@users.noreply.github.com> Date: Sun, 30 Mar 2025 18:45:58 +0000 (+0200) Subject: Add DSYNC rdatatype support (#1185) X-Git-Tag: v2.8.0rc1~44 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=af5cc101a40ebab31453e240bc201cf989328784;p=thirdparty%2Fdnspython.git Add DSYNC rdatatype support (#1185) Add DSYNC rdatatype support. --- diff --git a/dns/rdatatype.py b/dns/rdatatype.py index aa9e561c..f2d0eef7 100644 --- a/dns/rdatatype.py +++ b/dns/rdatatype.py @@ -86,6 +86,7 @@ class RdataType(dns.enum.IntEnum): ZONEMD = 63 SVCB = 64 HTTPS = 65 + DSYNC = 66 SPF = 99 UNSPEC = 103 NID = 104 @@ -332,5 +333,6 @@ RESINFO = RdataType.RESINFO WALLET = RdataType.WALLET TA = RdataType.TA DLV = RdataType.DLV +DSYNC = RdataType.DSYNC ### END generated RdataType constants diff --git a/dns/rdtypes/ANY/DSYNC.py b/dns/rdtypes/ANY/DSYNC.py new file mode 100644 index 00000000..26b740f1 --- /dev/null +++ b/dns/rdtypes/ANY/DSYNC.py @@ -0,0 +1,69 @@ +# Copyright (C) Dnspython Contributors, see LICENSE for text of ISC license + +import struct + +import dns.immutable +import dns.rdata +import dns.rdatatype +import dns.rdtypes.util + + +schemes = {1: "NOTIFY"} +schemes_by_mnemonic = {v: k for k, v in schemes.items()} + + +def _scheme_from_text(scheme): + try: + return int(scheme) + except ValueError: + return schemes_by_mnemonic[scheme] + + +def _scheme_to_text(scheme): + return schemes.get(scheme, str(scheme)) + + +@dns.immutable.immutable +class DSYNC(dns.rdata.Rdata): + """DSYNC record""" + + # see: draft-ietf-dnsop-generalized-notify + + __slots__ = ["rrtype", "scheme", "port", "target"] + + def __init__(self, rdclass, rdtype, rrtype, scheme, port, target): + super().__init__(rdclass, rdtype) + self.rrtype = self._as_uint16(rrtype) + self.scheme = self._as_uint8(scheme) + self.port = self._as_uint16(port) + self.target = self._as_name(target) + + def to_text(self, origin=None, relativize=True, **kw): + target = self.target.choose_relativity(origin, relativize) + return "%s %s %d %s" % ( + dns.rdatatype.to_text(self.rrtype), + _scheme_to_text(self.scheme), + self.port, + target, + ) + + @classmethod + def from_text( + cls, rdclass, rdtype, tok, origin=None, relativize=True, relativize_to=None + ): + rrtype = dns.rdatatype.from_text(tok.get_string()) + scheme = _scheme_from_text(tok.get_string()) + port = tok.get_uint16() + target = tok.get_name(origin, relativize, relativize_to) + return cls(rdclass, rdtype, rrtype, scheme, port, target) + + def _to_wire(self, file, compress=None, origin=None, canonicalize=False): + three_ints = struct.pack("!HBH", self.rrtype, self.scheme, self.port) + file.write(three_ints) + self.target.to_wire(file, None, origin, False) + + @classmethod + def from_wire_parser(cls, rdclass, rdtype, parser, origin=None): + (rrtype, scheme, port) = parser.get_struct("!HBH") + target = parser.get_name(origin) + return cls(rdclass, rdtype, rrtype, scheme, port, target) diff --git a/dns/rdtypes/ANY/__init__.py b/dns/rdtypes/ANY/__init__.py index 647b215b..cc39f864 100644 --- a/dns/rdtypes/ANY/__init__.py +++ b/dns/rdtypes/ANY/__init__.py @@ -31,6 +31,7 @@ __all__ = [ "DNAME", "DNSKEY", "DS", + "DSYNC", "EUI48", "EUI64", "GPOS", diff --git a/tests/example b/tests/example index a0e864b9..ad404fb9 100644 --- a/tests/example +++ b/tests/example @@ -266,4 +266,6 @@ svcb05 SVCB 16 foo.example.org. ohttp https01 HTTPS 0 svc https02 HTTPS 1 . port=8002 ech="abcd" resinfo RESINFO qnamemin exterr=15,16,17 infourl=https://resolver.example.com/guide -wallet WALLET EXAMPLE 01234567890abcdef +wallet WALLET EXAMPLE 01234567890abcdef +dsync DSYNC CDS NOTIFY 5300 notify-endpoint.parent.net. +dsync DSYNC CSYNC 128 443 notify-endpoint.parent.net. diff --git a/tests/example1.good b/tests/example1.good index 9e333c80..038a2c25 100644 --- a/tests/example1.good +++ b/tests/example1.good @@ -46,6 +46,8 @@ dname03 3600 IN DNAME . dnskey01 3600 IN DNSKEY 512 255 1 AQMFD5raczCJHViKtLYhWGz8hMY9UGRu niJDBzC7w0aRyzWZriO6i2odGWWQVucZ qKVsENW91IOW4vqudngPZsY3GvQ/xVA8 /7pyFj6b7Esga60zyGW6LFe9r8n6paHr lG5ojqf0BaqHT+8= dnskey02 3600 IN DNSKEY 257 3 1 AQMFD5raczCJHViKtLYhWGz8hMY9UGRu niJDBzC7w0aRyzWZriO6i2odGWWQVucZ qKVsENW91IOW4vqudngPZsY3GvQ/xVA8 /7pyFj6b7Esga60zyGW6LFe9r8n6paHr lG5ojqf0BaqHT+8= ds01 3600 IN DS 12345 3 1 123456789abcdef67890123456789abcdef67890 +dsync 3600 IN DSYNC CDS NOTIFY 5300 notify-endpoint.parent.net. +dsync 3600 IN DSYNC CSYNC 128 443 notify-endpoint.parent.net. e 300 IN MX 10 mail e 300 IN TXT "one" e 300 IN TXT "three" diff --git a/tests/example2.good b/tests/example2.good index 3ba638c1..129d8cdf 100644 --- a/tests/example2.good +++ b/tests/example2.good @@ -46,6 +46,8 @@ dname03.example. 3600 IN DNAME . dnskey01.example. 3600 IN DNSKEY 512 255 1 AQMFD5raczCJHViKtLYhWGz8hMY9UGRu niJDBzC7w0aRyzWZriO6i2odGWWQVucZ qKVsENW91IOW4vqudngPZsY3GvQ/xVA8 /7pyFj6b7Esga60zyGW6LFe9r8n6paHr lG5ojqf0BaqHT+8= dnskey02.example. 3600 IN DNSKEY 257 3 1 AQMFD5raczCJHViKtLYhWGz8hMY9UGRu niJDBzC7w0aRyzWZriO6i2odGWWQVucZ qKVsENW91IOW4vqudngPZsY3GvQ/xVA8 /7pyFj6b7Esga60zyGW6LFe9r8n6paHr lG5ojqf0BaqHT+8= ds01.example. 3600 IN DS 12345 3 1 123456789abcdef67890123456789abcdef67890 +dsync.example. 3600 IN DSYNC CDS NOTIFY 5300 notify-endpoint.parent.net. +dsync.example. 3600 IN DSYNC CSYNC 128 443 notify-endpoint.parent.net. e.example. 300 IN MX 10 mail.example. e.example. 300 IN TXT "one" e.example. 300 IN TXT "three" diff --git a/tests/example3.good b/tests/example3.good index 9e333c80..038a2c25 100644 --- a/tests/example3.good +++ b/tests/example3.good @@ -46,6 +46,8 @@ dname03 3600 IN DNAME . dnskey01 3600 IN DNSKEY 512 255 1 AQMFD5raczCJHViKtLYhWGz8hMY9UGRu niJDBzC7w0aRyzWZriO6i2odGWWQVucZ qKVsENW91IOW4vqudngPZsY3GvQ/xVA8 /7pyFj6b7Esga60zyGW6LFe9r8n6paHr lG5ojqf0BaqHT+8= dnskey02 3600 IN DNSKEY 257 3 1 AQMFD5raczCJHViKtLYhWGz8hMY9UGRu niJDBzC7w0aRyzWZriO6i2odGWWQVucZ qKVsENW91IOW4vqudngPZsY3GvQ/xVA8 /7pyFj6b7Esga60zyGW6LFe9r8n6paHr lG5ojqf0BaqHT+8= ds01 3600 IN DS 12345 3 1 123456789abcdef67890123456789abcdef67890 +dsync 3600 IN DSYNC CDS NOTIFY 5300 notify-endpoint.parent.net. +dsync 3600 IN DSYNC CSYNC 128 443 notify-endpoint.parent.net. e 300 IN MX 10 mail e 300 IN TXT "one" e 300 IN TXT "three" diff --git a/tests/example4.good b/tests/example4.good index 42d19089..c5c0d1b6 100644 --- a/tests/example4.good +++ b/tests/example4.good @@ -47,6 +47,8 @@ dname03 3600 IN DNAME . dnskey01 3600 IN DNSKEY 512 255 1 AQMFD5raczCJHViKtLYhWGz8hMY9UGRu niJDBzC7w0aRyzWZriO6i2odGWWQVucZ qKVsENW91IOW4vqudngPZsY3GvQ/xVA8 /7pyFj6b7Esga60zyGW6LFe9r8n6paHr lG5ojqf0BaqHT+8= dnskey02 3600 IN DNSKEY 257 3 1 AQMFD5raczCJHViKtLYhWGz8hMY9UGRu niJDBzC7w0aRyzWZriO6i2odGWWQVucZ qKVsENW91IOW4vqudngPZsY3GvQ/xVA8 /7pyFj6b7Esga60zyGW6LFe9r8n6paHr lG5ojqf0BaqHT+8= ds01 3600 IN DS 12345 3 1 123456789abcdef67890123456789abcdef67890 +dsync 3600 IN DSYNC CDS NOTIFY 5300 notify-endpoint.parent.net. +dsync 3600 IN DSYNC CSYNC 128 443 notify-endpoint.parent.net. e 300 IN MX 10 mail e 300 IN TXT "one" e 300 IN TXT "three" diff --git a/tests/test_rdata.py b/tests/test_rdata.py index 8c4c5104..061e7b70 100644 --- a/tests/test_rdata.py +++ b/tests/test_rdata.py @@ -68,6 +68,7 @@ class RdataTestCase(unittest.TestCase): def test_class_registration(self): CTXT = 64003 + class CTXTImp(dns.rdtypes.txtbase.TXTBase): """Test TXT-like record"""