]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Include disptype and transport in dispatch hash key
authorOndřej Surý <ondrej@sury.org>
Thu, 9 Apr 2026 15:35:09 +0000 (17:35 +0200)
committerOndřej Surý <ondrej@isc.org>
Tue, 14 Apr 2026 15:48:24 +0000 (17:48 +0200)
Move disptype and transport into dispatch_hash() and dispatch_match()
so that the match function is the single source of truth for whether
two TCP dispatches are interchangeable.  This replaces the post-loop
disptype filter in dispatch_gettcp() and makes the disptype field in
struct dispatch_key actually used.

lib/dns/dispatch.c

index 8dfd4bd3fe247e45b7dd5591b51f69775eb5e6c8..4b12f8888845aadcdfba108682577b60f6a96e2e 100644 (file)
@@ -1130,12 +1130,21 @@ struct dispatch_key {
 
 static uint32_t
 dispatch_hash(struct dispatch_key *key) {
-       uint32_t hashval = isc_sockaddr_hash(key->peer, false);
-       if (key->local) {
-               hashval ^= isc_sockaddr_hash(key->local, true);
+       isc_hash32_t hash;
+
+       isc_hash32_init(&hash);
+
+       isc_sockaddr_hash_ex(&hash, key->peer, false);
+       if (key->local != NULL) {
+               isc_sockaddr_hash_ex(&hash, key->local, true);
        }
+       if (key->transport != NULL) {
+               uintptr_t transport = (uintptr_t)key->transport;
+               isc_hash32_hash(&hash, &transport, sizeof(transport), true);
+       }
+       isc_hash32_hash(&hash, &key->disptype, sizeof(key->disptype), true);
 
-       return hashval;
+       return isc_hash32_finalize(&hash);
 }
 
 static int
@@ -1143,7 +1152,8 @@ dispatch_match(struct cds_lfht_node *node, const void *key0) {
        dns_dispatch_t *disp = caa_container_of(node, dns_dispatch_t, ht_node);
        const struct dispatch_key *key = key0;
 
-       return disp->transport == key->transport &&
+       return disp->disptype == key->disptype &&
+              disp->transport == key->transport &&
               isc_sockaddr_equal(&disp->peer, key->peer) &&
               (key->local == NULL ||
                isc_sockaddr_equal(&disp->local, key->local));
@@ -1178,10 +1188,6 @@ dispatch_gettcp(dns_dispatchmgr_t *mgr, const isc_sockaddr_t *localaddr,
                INSIST(disp->tid == isc_tid());
                INSIST(disp->socktype == isc_socktype_tcp);
 
-               if (disp->disptype != disptype) {
-                       continue;
-               }
-
                switch (disp->state) {
                case DNS_DISPATCHSTATE_NONE:
                        /* A dispatch in indeterminate state, skip it */