]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Squash dns_name_fullhash() and dns_name_hash()
authorOndřej Surý <ondrej@isc.org>
Thu, 30 Mar 2023 19:37:12 +0000 (21:37 +0200)
committerOndřej Surý <ondrej@isc.org>
Fri, 31 Mar 2023 12:43:30 +0000 (12:43 +0000)
The only place where dns_name_hash() was being used is the old hash
table in the dns_badcache unit.  Squash the dns_name_fullhash() and
dns_name_hash() into single dns_name_hash() function that's always
case-insensitive as it doesn't make to do case-sensitive hashing of the
domain names and we were not using this anywhere.

lib/dns/badcache.c
lib/dns/include/dns/name.h
lib/dns/name.c
lib/dns/rbt.c
lib/dns/rrl.c
tests/dns/name_test.c

index 274ef9b55b3ffcc14781de6b7e12b6591f19be2a..873e328360ceb30182fcdec565a1be1c1b5ad5f3 100644 (file)
@@ -229,7 +229,7 @@ dns_badcache_add(dns_badcache_t *bc, const dns_name_t *name,
                isc_time_settoepoch(&now);
        }
 
-       hashval = dns_name_hash(name, false);
+       hashval = dns_name_hash(name);
        hash = hashval % bc->size;
        LOCK(&bc->tlocks[hash]);
        prev = NULL;
@@ -318,7 +318,7 @@ dns_badcache_find(dns_badcache_t *bc, const dns_name_t *name,
                goto skip;
        }
 
-       hash = dns_name_hash(name, false) % bc->size;
+       hash = dns_name_hash(name) % bc->size;
        prev = NULL;
        LOCK(&bc->tlocks[hash]);
        for (bad = bc->table[hash]; bad != NULL; bad = next) {
@@ -402,7 +402,7 @@ dns_badcache_flushname(dns_badcache_t *bc, const dns_name_t *name) {
        if (result != ISC_R_SUCCESS) {
                isc_time_settoepoch(&now);
        }
-       hash = dns_name_hash(name, false) % bc->size;
+       hash = dns_name_hash(name) % bc->size;
        LOCK(&bc->tlocks[hash]);
        prev = NULL;
        for (bad = bc->table[hash]; bad != NULL; bad = next) {
index 9e3a5191b5149d8d7b6d034a25b2f56fe11fadcc..e079a59a1e1dbf82cf1afc1d3cfe8470037ee54f 100644 (file)
@@ -341,29 +341,14 @@ dns_name_iswildcard(const dns_name_t *name);
  * \li FALSE           The least significant label of 'name' is not '*'.
  */
 
-unsigned int
-dns_name_hash(const dns_name_t *name, bool case_sensitive);
+uint32_t
+dns_name_hash(const dns_name_t *name);
 /*%<
  * Provide a hash value for 'name'.
  *
- * Note: if 'case_sensitive' is false, then names which differ only in
- * case will have the same hash value.
- *
- * Requires:
- * \li 'name' is a valid name
- *
- * Returns:
- * \li A hash value
- */
-
-unsigned int
-dns_name_fullhash(const dns_name_t *name, bool case_sensitive);
-/*%<
- * Provide a hash value for 'name'.  Unlike dns_name_hash(), this function
- * always takes into account of the entire name to calculate the hash value.
- *
- * Note: if 'case_sensitive' is false, then names which differ only in
- * case will have the same hash value.
+ * Note: This function always takes into account of the entire name to calculate
+ * the hash value. The names which differ only in case will have the same hash
+ * value.
  *
  * Requires:
  *\li  'name' is a valid name
index 039b9b17f57e44fd76342c40141f81317eebdc87..3a44c1dc901d240ab6eee6687991b1121964a2a8 100644 (file)
@@ -397,39 +397,11 @@ dns_name_internalwildcard(const dns_name_t *name) {
        return (false);
 }
 
-unsigned int
-dns_name_hash(const dns_name_t *name, bool case_sensitive) {
-       unsigned int length;
-
-       /*
-        * Provide a hash value for 'name'.
-        */
+uint32_t
+dns_name_hash(const dns_name_t *name) {
        REQUIRE(VALID_NAME(name));
 
-       if (name->labels == 0) {
-               return (0);
-       }
-
-       length = name->length;
-       if (length > 16) {
-               length = 16;
-       }
-
-       return (isc_hash32(name->ndata, length, case_sensitive));
-}
-
-unsigned int
-dns_name_fullhash(const dns_name_t *name, bool case_sensitive) {
-       /*
-        * Provide a hash value for 'name'.
-        */
-       REQUIRE(VALID_NAME(name));
-
-       if (name->labels == 0) {
-               return (0);
-       }
-
-       return (isc_hash32(name->ndata, name->length, case_sensitive));
+       return (isc_hash32(name->ndata, name->length, false));
 }
 
 dns_namereln_t
index a8f40dadb336f45faa9d5e69d8c0e2267bb58de0..9109a9ce057724835dcb6aee7f65b190ef686746 100644 (file)
@@ -872,7 +872,7 @@ dns__rbt_findnode(dns_rbt_t *rbt, const dns_name_t *name, dns_name_t *foundname,
                        dns_name_getlabelsequence(name, nlabels - tlabels,
                                                  hlabels + tlabels,
                                                  &hash_name);
-                       hashval = dns_name_fullhash(&hash_name, false);
+                       hashval = dns_name_hash(&hash_name);
 
                        dns_name_getlabelsequence(search_name,
                                                  nlabels - tlabels, tlabels,
@@ -1569,7 +1569,7 @@ hash_add_node(dns_rbt_t *rbt, dns_rbtnode_t *node, const dns_name_t *name) {
 
        REQUIRE(name != NULL);
 
-       node->hashval = dns_name_fullhash(name, false);
+       node->hashval = dns_name_hash(name);
 
        hash = isc_hash_bits32(node->hashval, rbt->hashbits[rbt->hindex]);
        node->hashnext = rbt->hashtable[rbt->hindex][hash];
index f48258ef93919cb10083de2851b1768e07f7de9d..3a4921b8034f8272f69f9cb9eac76f81e5973c51 100644 (file)
@@ -459,9 +459,9 @@ make_key(const dns_rrl_t *rrl, dns_rrl_key_t *key,
                                 */
                                wild = origin;
                        }
-                       key->s.qname_hash = dns_name_fullhash(wild, false);
+                       key->s.qname_hash = dns_name_hash(wild);
                } else {
-                       key->s.qname_hash = dns_name_fullhash(qname, false);
+                       key->s.qname_hash = dns_name_hash(qname);
                }
        }
 
index a20eb79536e8ba11524d020f934a0cbac8bb1d25..fa923fb6ec685eba0b588502b5565016ae27a79e 100644 (file)
@@ -629,8 +629,8 @@ ISC_RUN_TEST_IMPL(hash) {
                assert_int_equal(result, ISC_R_SUCCESS);
 
                /* Check case-insensitive hashing first */
-               h1 = dns_name_hash(n1, false);
-               h2 = dns_name_hash(n2, false);
+               h1 = dns_name_hash(n1);
+               h2 = dns_name_hash(n2);
 
                if (verbose) {
                        print_message("# %s hashes to %u, "
@@ -642,8 +642,8 @@ ISC_RUN_TEST_IMPL(hash) {
                assert_int_equal((h1 == h2), testcases[i].expect);
 
                /* Now case-sensitive */
-               h1 = dns_name_hash(n1, false);
-               h2 = dns_name_hash(n2, false);
+               h1 = dns_name_hash(n1);
+               h2 = dns_name_hash(n2);
 
                if (verbose) {
                        print_message("# %s hashes to %u, "