]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Store the most specific matched domain in DomainHandler
authorŠtěpán Balážik <stepan@isc.org>
Thu, 25 Dec 2025 15:58:35 +0000 (16:58 +0100)
committerŠtěpán Balážik <stepan@isc.org>
Fri, 23 Jan 2026 15:39:00 +0000 (16:39 +0100)
Store the most specific matching domain in DomainHandler and
expose it through the `matched_domain` property for subclasses
to use in their implementations of `get_responses`.

bin/tests/system/isctest/asyncserver.py

index 165a6db9dedd7819b0ce203625b407ae958622c5..3b4529ebe88a39ebc048cba38db44cda0ef6a1b4 100644 (file)
@@ -649,6 +649,8 @@ class DomainHandler(ResponseHandler):
     The derived class must specify a list of `domains` that it wants to handle.
     Queries for any of these domains (and their subdomains) will then be passed
     to the `get_response()` method in the derived class.
+
+    The most specific matching domain is stored in the `matched_domain` attribute.
     """
 
     @property
@@ -660,9 +662,15 @@ class DomainHandler(ResponseHandler):
         raise NotImplementedError
 
     def __init__(self) -> None:
-        self._domains: List[dns.name.Name] = [
-            dns.name.from_text(d) for d in self.domains
-        ]
+        self._domains: List[dns.name.Name] = sorted(
+            [dns.name.from_text(d) for d in self.domains], reverse=True
+        )
+        self._matched_domain: Optional[dns.name.Name] = None
+
+    @property
+    def matched_domain(self) -> dns.name.Name:
+        assert self._matched_domain is not None
+        return self._matched_domain
 
     def __str__(self) -> str:
         return f"{self.__class__.__name__}(domains: {', '.join(self.domains)})"
@@ -672,8 +680,10 @@ class DomainHandler(ResponseHandler):
         Handle queries whose QNAME matches any of the domains handled by this
         class.
         """
+        self._matched_domain = None
         for domain in self._domains:
             if qctx.qname.is_subdomain(domain):
+                self._matched_domain = domain
                 return True
         return False