]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Use the new isc_sockaddr_hash_ex() to fix QID table hashing
authorOndřej Surý <ondrej@isc.org>
Mon, 18 Sep 2023 08:02:37 +0000 (10:02 +0200)
committerOndřej Surý <ondrej@isc.org>
Tue, 19 Sep 2023 17:56:33 +0000 (19:56 +0200)
The QID table hashing used a custom merging of the sockaddr, port and id
into a single hashvalue.  Normalize the QID table hashing function to
use isc_hash32 API for all the values.

lib/dns/dispatch.c

index 3ba6d91b32806f17f458f41b6ec814776f9c00a0..0b82990a1a2dc47c6d84d69e3bb90b4dd08fc937 100644 (file)
@@ -373,12 +373,15 @@ setup_socket(dns_dispatch_t *disp, dns_dispentry_t *resp,
 
 static uint32_t
 qid_hash(const dns_dispentry_t *dispentry) {
-       /*
-        * TODO(OS): Add incremental isc_sockaddr_hash() function and then use
-        * isc_hash32 API
-        */
-       uint32_t hashval = isc_sockaddr_hash(&dispentry->peer, true);
-       return (hashval ^ (((uint32_t)dispentry->id << 16) | dispentry->port));
+       isc_hash32_t hash;
+
+       isc_hash32_init(&hash);
+
+       isc_sockaddr_hash_ex(&hash, &dispentry->peer, true);
+       isc_hash32_hash(&hash, &dispentry->id, sizeof(dispentry->id), true);
+       isc_hash32_hash(&hash, &dispentry->port, sizeof(dispentry->port), true);
+
+       return (isc_hash32_finalize(&hash));
 }
 
 static int