]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Add an edns attribute to StaticResponseHandler
authorŠtěpán Balážik <stepan@isc.org>
Thu, 23 Jul 2026 13:22:48 +0000 (15:22 +0200)
committerŠtěpán Balážik <stepan@isc.org>
Wed, 12 Aug 2026 09:34:18 +0000 (09:34 +0000)
Let a static handler set the response's EDNS declaratively via a value
passed straight to use_edns(), instead of overriding get_responses().
The attribute is left unset by default, so EDNS stays untouched for
every existing handler.

Assisted-by: Claude:claude-fable-5
bin/tests/system/isctest/asyncserver.py

index fefd03bb2742759ae960b866212095c17b1ba1a1..d55fcfcc190a2220d0152eef7dea72fcdf305b73 100644 (file)
@@ -658,6 +658,10 @@ class QnameQtypeHandler(QnameHandler):
         return qctx.qtype in self._qtypes and super().match(qctx)
 
 
+class _UnsetEdnsType:
+    pass
+
+
 class StaticResponseHandler(ResponseHandler):
     """
     Base class used for deriving custom static response handlers.
@@ -712,6 +716,15 @@ class StaticResponseHandler(ResponseHandler):
         """
         return 0.0
 
+    @property
+    def edns(self) -> int | bool | None | _UnsetEdnsType:
+        """
+        Value passed to the response's ``use_edns()``.  Left unset by default,
+        so EDNS is untouched; set it to anything ``use_edns()`` accepts (e.g.
+        ``None`` to strip EDNS and mimic a non-EDNS server).
+        """
+        return _UnsetEdnsType()
+
     async def get_responses(
         self, qctx: QueryContext
     ) -> AsyncGenerator[DnsResponseSend, None]:
@@ -721,6 +734,8 @@ class StaticResponseHandler(ResponseHandler):
         qctx.response.additional.extend(self.additional)
         if self.rcode is not None:
             qctx.response.set_rcode(self.rcode)
+        if not isinstance(self.edns, _UnsetEdnsType):
+            qctx.response.use_edns(self.edns)
         yield DnsResponseSend(
             qctx.response, authoritative=self.authoritative, delay=self.delay
         )