X-Cam-Scannerinfo: http://help.uis.cam.ac.uk/email-scanner-virus Delivered-To: bind9-confidential@bugs.isc.org CC: "Tony Finch" Date: Wed, 21 Jun 2017 18:41:29 +0100 Return-Path: Message-ID: To: bind9-bugs@isc.org Received: from mx.pao1.isc.org (mx.pao1.isc.org [149.20.64.53]) by bugs.isc.org (Postfix) with ESMTP id EE19BD78A7C for ; Wed, 21 Jun 2017 17:41:32 +0000 (UTC) Received: from ppsw-30.csi.cam.ac.uk (ppsw-30.csi.cam.ac.uk [131.111.8.130]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx.pao1.isc.org (Postfix) with ESMTPS id 9065B349452 for ; Wed, 21 Jun 2017 17:41:30 +0000 (UTC) Received: from grey.csi.cam.ac.uk ([131.111.57.57]:54308) by ppsw-30.csi.cam.ac.uk (ppsw.cam.ac.uk [131.111.8.136]:25) with esmtps (TLSv1:ECDHE-RSA-AES256-SHA:256) id 1dNjdB-000tAz-dF (Exim 4.89) (return-path ); Wed, 21 Jun 2017 18:41:29 +0100 X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL autolearn=ham autolearn_force=no version=3.4.0 From: "Tony Finch" content-type: TEXT/PLAIN; charset="utf-8" X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on mx.pao1.isc.org X-Original-To: bind9-confidential@bugs.isc.org User-Agent: Alpine 2.11 (DEB 23 2013-08-11) MIME-Version: 1.0 X-Cam-Antivirus: no malware found Subject: [PATCH] Deprecate dns_name_hashbylabel() since it isn't a very good hash. From dot@dotat.at Wed Jun 21 17:41:33 2017 X-RT-Incoming-Encryption: Not encrypted X-RT-Original-Encoding: ascii X-RT-Interface: Email Content-Length: 3066 The rbt stopped using it in 2004 (change 1740) and it was not used after that point until RRL started using it in 2013. I have left the entry points in place for backwards compatibility, though the hash values will be different. --- lib/dns/include/dns/name.h | 16 ---------------- lib/dns/name.c | 34 ++++------------------------------ lib/dns/rrl.c | 4 ++-- 3 files changed, 6 insertions(+), 48 deletions(-) diff --git a/lib/dns/include/dns/name.h b/lib/dns/include/dns/name.h index ab76458..346188e 100644 --- a/lib/dns/include/dns/name.h +++ b/lib/dns/include/dns/name.h @@ -349,22 +349,6 @@ dns_name_fullhash(const dns_name_t *name, isc_boolean_t case_sensitive); *\li A hash value */ -unsigned int -dns_name_hashbylabel(const dns_name_t *name, isc_boolean_t case_sensitive); -/*%< - * Provide a hash value for 'name', where the hash value is the sum - * of the hash values of each label. - * - * Note: if 'case_sensitive' is ISC_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 - */ - /* *** Comparisons ***/ diff --git a/lib/dns/name.c b/lib/dns/name.c index d07b5fc..b41740b 100644 --- a/lib/dns/name.c +++ b/lib/dns/name.c @@ -498,38 +498,12 @@ dns_fullname_hash(const dns_name_t *name, isc_boolean_t case_sensitive) { unsigned int dns_name_hashbylabel(const dns_name_t *name, isc_boolean_t case_sensitive) { - unsigned char *offsets; - dns_offsets_t odata; - dns_name_t tname; - unsigned int h = 0; - unsigned int i; - /* - * Provide a hash value for 'name'. + * This function was deprecated because of its poor performance. + * We only keep this internally to provide binary backward + * compatibility. */ - REQUIRE(VALID_NAME(name)); - - if (name->labels == 0) - return (0); - else if (name->labels == 1) - return (isc_hash_function_reverse(name->ndata, name->length, - case_sensitive, NULL)); - - SETUP_OFFSETS(name, offsets, odata); - DNS_NAME_INIT(&tname, NULL); - tname.labels = 1; - h = 0; - for (i = 0; i < name->labels; i++) { - tname.ndata = name->ndata + offsets[i]; - if (i == name->labels - 1) - tname.length = name->length - offsets[i]; - else - tname.length = offsets[i + 1] - offsets[i]; - h += isc_hash_function_reverse(tname.ndata, tname.length, - case_sensitive, NULL); - } - - return (h); + return (dns_name_fullhash(name, case_sensitive)); } dns_namereln_t diff --git a/lib/dns/rrl.c b/lib/dns/rrl.c index 252ebd8..53a86d3 100644 --- a/lib/dns/rrl.c +++ b/lib/dns/rrl.c @@ -417,10 +417,10 @@ make_key(const dns_rrl_t *rrl, dns_rrl_key_t *key, { dns_name_init(&base, base_offsets); dns_name_getlabelsequence(qname, 1, labels-1, &base); - key->s.qname_hash = dns_name_hashbylabel(&base, + key->s.qname_hash = dns_name_fullhash(&base, ISC_FALSE); } else { - key->s.qname_hash = dns_name_hashbylabel(qname, + key->s.qname_hash = dns_name_fullhash(qname, ISC_FALSE); } } -- 2.10.1.445.g3cdd5d1