]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Code cleanups (#41656)
authorMukund Sivaraman <muks@isc.org>
Fri, 4 Mar 2016 07:10:14 +0000 (12:40 +0530)
committerMukund Sivaraman <muks@isc.org>
Fri, 4 Mar 2016 07:30:43 +0000 (13:00 +0530)
(cherry picked from commit 9da98335c185c39591150ccb4e307adc4cea44bc)
(cherry picked from commit b15dde288977f70bdebfadaeaee6505e0e61f0bd)

bin/named/query.c
configure
configure.in
lib/dns/message.c
lib/isc/hash.c
lib/isc/include/isc/hash.h
lib/isc/mem.c

index fa9bca94bcf84247265d0b37eb72f2ef2db575fb..d780671eb5392da775b65bc235dfc85099d06525 100644 (file)
@@ -488,7 +488,7 @@ query_getnamebuf(ns_client_t *client) {
        dbuf = ISC_LIST_TAIL(client->query.namebufs);
        INSIST(dbuf != NULL);
        isc_buffer_availableregion(dbuf, &r);
-       if (r.length < 255) {
+       if (r.length < DNS_NAME_MAXWIRE) {
                result = query_newnamebuf(client);
                if (result != ISC_R_SUCCESS) {
                    CTRACE(ISC_LOG_DEBUG(3),
@@ -5911,11 +5911,14 @@ query_find(ns_client_t *client, dns_fetchevent_t *event, dns_rdatatype_t qtype)
                options |= DNS_GETDB_NOEXACT;
        result = query_getdb(client, client->query.qname, qtype, options,
                             &zone, &db, &version, &is_zone);
-       if ((result != ISC_R_SUCCESS || !is_zone) && !RECURSIONOK(client) &&
-           (options & DNS_GETDB_NOEXACT) != 0 && qtype == dns_rdatatype_ds) {
+       if (ISC_UNLIKELY((result != ISC_R_SUCCESS || !is_zone) &&
+                        qtype == dns_rdatatype_ds &&
+                        !RECURSIONOK(client) &&
+                        (options & DNS_GETDB_NOEXACT) != 0))
+       {
                /*
-                * Look to see if we are authoritative for the
-                * child zone if the query type is DS.
+                * If the query type is DS, look to see if we are
+                * authoritative for the child zone.
                 */
                dns_db_t *tdb = NULL;
                dns_zone_t *tzone = NULL;
@@ -5988,7 +5991,7 @@ query_find(ns_client_t *client, dns_fetchevent_t *event, dns_rdatatype_t qtype)
         * We'll need some resources...
         */
        dbuf = query_getnamebuf(client);
-       if (dbuf == NULL) {
+       if (ISC_UNLIKELY(dbuf == NULL)) {
                CTRACE(ISC_LOG_ERROR,
                       "query_find: query_getnamebuf failed (2)");
                QUERY_ERROR(DNS_R_SERVFAIL);
@@ -5996,7 +5999,7 @@ query_find(ns_client_t *client, dns_fetchevent_t *event, dns_rdatatype_t qtype)
        }
        fname = query_newname(client, dbuf, &b);
        rdataset = query_newrdataset(client);
-       if (fname == NULL || rdataset == NULL) {
+       if (ISC_UNLIKELY(fname == NULL || rdataset == NULL)) {
                CTRACE(ISC_LOG_ERROR,
                       "query_find: query_newname failed (2)");
                QUERY_ERROR(DNS_R_SERVFAIL);
@@ -7878,6 +7881,14 @@ ns_query_start(ns_client_t *client) {
                client->query.attributes &= ~NS_QUERYATTR_RECURSIONOK;
        }
 
+       /*
+        * Check for multiple question queries, since edns1 is dead.
+        */
+       if (message->counts[DNS_SECTION_QUESTION] > 1) {
+               query_error(client, DNS_R_FORMERR, __LINE__);
+               return;
+       }
+
        /*
         * Get the question name.
         */
@@ -7905,14 +7916,6 @@ ns_query_start(ns_client_t *client) {
        if (ns_g_server->log_queries)
                log_query(client, saved_flags, saved_extflags);
 
-       /*
-        * Check for multiple question queries, since edns1 is dead.
-        */
-       if (message->counts[DNS_SECTION_QUESTION] > 1) {
-               query_error(client, DNS_R_FORMERR, __LINE__);
-               return;
-       }
-
        /*
         * Check for meta-queries like IXFR and AXFR.
         */
index 77024000f30517996e0c3e7e924dbfa42b0897ea..dcca31b07ed67c78bb6818318e715ccd16fc87a2 100755 (executable)
--- a/configure
+++ b/configure
@@ -18489,8 +18489,6 @@ ISC_PLATFORM_USEGCCASM="#undef ISC_PLATFORM_USEGCCASM"
 ISC_PLATFORM_USESTDASM="#undef ISC_PLATFORM_USESTDASM"
 ISC_PLATFORM_USEMACASM="#undef ISC_PLATFORM_USEMACASM"
 if test "$use_atomic" = "yes"; then
-       { $as_echo "$as_me:${as_lineno-$LINENO}: checking architecture type for atomic operations" >&5
-$as_echo_n "checking architecture type for atomic operations... " >&6; }
        have_atomic=yes         # set default
        case "$host" in
        i[3456]86-*)
@@ -18594,6 +18592,8 @@ _ACEOF
                arch=noatomic
        ;;
        esac
+       { $as_echo "$as_me:${as_lineno-$LINENO}: checking architecture type for atomic operations" >&5
+$as_echo_n "checking architecture type for atomic operations... " >&6; }
        { $as_echo "$as_me:${as_lineno-$LINENO}: result: $arch" >&5
 $as_echo "$arch" >&6; }
 fi
@@ -19800,6 +19800,8 @@ else
 fi
 
 
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether to enable query trace logging" >&5
+$as_echo_n "checking whether to enable query trace logging... " >&6; }
 case "$want_querytrace" in
 yes)
        { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
index 6a60718132ab2bee1e2fb7e7a23cea29bdced77b..b705bc4f2ef9eca2db91c585a694d95329c79dba 100644 (file)
@@ -3112,7 +3112,6 @@ ISC_PLATFORM_USEGCCASM="#undef ISC_PLATFORM_USEGCCASM"
 ISC_PLATFORM_USESTDASM="#undef ISC_PLATFORM_USESTDASM"
 ISC_PLATFORM_USEMACASM="#undef ISC_PLATFORM_USEMACASM"
 if test "$use_atomic" = "yes"; then
-       AC_MSG_CHECKING([architecture type for atomic operations])
        have_atomic=yes         # set default
        case "$host" in
        [i[3456]86-*])
@@ -3152,6 +3151,7 @@ if test "$use_atomic" = "yes"; then
                arch=noatomic
        ;;
        esac
+       AC_MSG_CHECKING([architecture type for atomic operations])
        AC_MSG_RESULT($arch)
 fi
 
@@ -3647,6 +3647,7 @@ AC_ARG_ENABLE(querytrace,
        [  --enable-querytrace     enable very verbose query trace logging [[default=no]]],
        want_querytrace="$enableval", want_querytrace="no")
 
+AC_MSG_CHECKING([whether to enable query trace logging])
 case "$want_querytrace" in
 yes)
        AC_MSG_RESULT(yes)
index bc7df345ce27ef76918efe3cb43bf0645160c0f6..a8d420c572eb509053cead884f50226cc327830b 100644 (file)
@@ -830,9 +830,8 @@ dns_message_find(dns_name_t *name, dns_rdataclass_t rdclass,
 {
        dns_rdataset_t *curr;
 
-       if (rdataset != NULL) {
-               REQUIRE(*rdataset == NULL);
-       }
+       REQUIRE(name != NULL);
+       REQUIRE(rdataset == NULL || *rdataset == NULL);
 
        for (curr = ISC_LIST_TAIL(name->list);
             curr != NULL;
@@ -855,15 +854,13 @@ dns_message_findtype(dns_name_t *name, dns_rdatatype_t type,
        dns_rdataset_t *curr;
 
        REQUIRE(name != NULL);
-       if (rdataset != NULL) {
-               REQUIRE(*rdataset == NULL);
-       }
+       REQUIRE(rdataset == NULL || *rdataset == NULL);
 
        for (curr = ISC_LIST_TAIL(name->list);
             curr != NULL;
             curr = ISC_LIST_PREV(curr, link)) {
                if (curr->type == type && curr->covers == covers) {
-                       if (rdataset != NULL)
+                       if (ISC_UNLIKELY(rdataset != NULL))
                                *rdataset = curr;
                        return (ISC_R_SUCCESS);
                }
@@ -2341,13 +2338,12 @@ dns_message_findname(dns_message_t *msg, dns_section_t section,
        REQUIRE(msg != NULL);
        REQUIRE(VALID_SECTION(section));
        REQUIRE(target != NULL);
-       if (name != NULL)
-               REQUIRE(*name == NULL);
+       REQUIRE(name == NULL || *name == NULL);
+
        if (type == dns_rdatatype_any) {
                REQUIRE(rdataset == NULL);
        } else {
-               if (rdataset != NULL)
-                       REQUIRE(*rdataset == NULL);
+               REQUIRE(rdataset == NULL || *rdataset == NULL);
        }
 
        result = findname(&foundname, target,
@@ -2364,7 +2360,7 @@ dns_message_findname(dns_message_t *msg, dns_section_t section,
        /*
         * And now look for the type.
         */
-       if (type == dns_rdatatype_any)
+       if (ISC_UNLIKELY(type == dns_rdatatype_any))
                return (ISC_R_SUCCESS);
 
        result = dns_message_findtype(foundname, type, covers, rdataset);
index 8c187ef8171c3ba635a6c27b3e5a5807a5f7c7ee..8fd58532838d3e13252e8d6379231277a9f53239 100644 (file)
@@ -400,7 +400,7 @@ isc_hash_calc(const unsigned char *key, unsigned int keylen,
        return (hash_calc(hash, key, keylen, case_sensitive));
 }
 
-static unsigned int fnv_offset_basis;
+static isc_uint32_t fnv_offset_basis;
 static isc_once_t fnv_once = ISC_ONCE_INIT;
 
 static void
@@ -415,19 +415,20 @@ fnv_initialize(void) {
        }
 }
 
-unsigned int
+isc_uint32_t
 isc_hash_function(const void *data, size_t length,
                  isc_boolean_t case_sensitive,
-                 unsigned int *previous_hashp)
+                 const isc_uint32_t *previous_hashp)
 {
-       unsigned int hval;
+       isc_uint32_t hval;
        const unsigned char *bp;
        const unsigned char *be;
 
        INSIST(data == NULL || length > 0);
        RUNTIME_CHECK(isc_once_do(&fnv_once, fnv_initialize) == ISC_R_SUCCESS);
 
-       hval = previous_hashp != NULL ? *previous_hashp : fnv_offset_basis;
+       hval = ISC_UNLIKELY(previous_hashp != NULL) ?
+               *previous_hashp : fnv_offset_basis;
 
        if (length == 0)
                return (hval);
@@ -446,34 +447,34 @@ isc_hash_function(const void *data, size_t length,
 
        if (case_sensitive) {
                while (bp < be - 4) {
-                       hval ^= (unsigned int) bp[0];
+                       hval ^= (isc_uint32_t) bp[0];
                        hval *= 16777619;
-                       hval ^= (unsigned int) bp[1];
+                       hval ^= (isc_uint32_t) bp[1];
                        hval *= 16777619;
-                       hval ^= (unsigned int) bp[2];
+                       hval ^= (isc_uint32_t) bp[2];
                        hval *= 16777619;
-                       hval ^= (unsigned int) bp[3];
+                       hval ^= (isc_uint32_t) bp[3];
                        hval *= 16777619;
                        bp += 4;
                }
                while (bp < be) {
-                       hval ^= (unsigned int) *bp++;
+                       hval ^= (isc_uint32_t) *bp++;
                        hval *= 16777619;
                }
        } else {
                while (bp < be - 4) {
-                       hval ^= (unsigned int) maptolower[bp[0]];
+                       hval ^= (isc_uint32_t) maptolower[bp[0]];
                        hval *= 16777619;
-                       hval ^= (unsigned int) maptolower[bp[1]];
+                       hval ^= (isc_uint32_t) maptolower[bp[1]];
                        hval *= 16777619;
-                       hval ^= (unsigned int) maptolower[bp[2]];
+                       hval ^= (isc_uint32_t) maptolower[bp[2]];
                        hval *= 16777619;
-                       hval ^= (unsigned int) maptolower[bp[3]];
+                       hval ^= (isc_uint32_t) maptolower[bp[3]];
                        hval *= 16777619;
                        bp += 4;
                }
                while (bp < be) {
-                       hval ^= (unsigned int) maptolower[*bp++];
+                       hval ^= (isc_uint32_t) maptolower[*bp++];
                        hval *= 16777619;
                }
        }
@@ -481,19 +482,20 @@ isc_hash_function(const void *data, size_t length,
        return (hval);
 }
 
-unsigned int
+isc_uint32_t
 isc_hash_function_reverse(const void *data, size_t length,
                          isc_boolean_t case_sensitive,
-                         unsigned int *previous_hashp)
+                         const isc_uint32_t *previous_hashp)
 {
-       unsigned int hval;
+       isc_uint32_t hval;
        const unsigned char *bp;
        const unsigned char *be;
 
        INSIST(data == NULL || length > 0);
        RUNTIME_CHECK(isc_once_do(&fnv_once, fnv_initialize) == ISC_R_SUCCESS);
 
-       hval = ISC_UNLIKELY(previous_hashp != NULL) ? *previous_hashp : fnv_offset_basis;
+       hval = ISC_UNLIKELY(previous_hashp != NULL) ?
+               *previous_hashp : fnv_offset_basis;
 
        if (length == 0)
                return (hval);
@@ -513,33 +515,33 @@ isc_hash_function_reverse(const void *data, size_t length,
        if (case_sensitive) {
                while (be >= bp + 4) {
                        be -= 4;
-                       hval ^= (unsigned int) be[3];
+                       hval ^= (isc_uint32_t) be[3];
                        hval *= 16777619;
-                       hval ^= (unsigned int) be[2];
+                       hval ^= (isc_uint32_t) be[2];
                        hval *= 16777619;
-                       hval ^= (unsigned int) be[1];
+                       hval ^= (isc_uint32_t) be[1];
                        hval *= 16777619;
-                       hval ^= (unsigned int) be[0];
+                       hval ^= (isc_uint32_t) be[0];
                        hval *= 16777619;
                }
                while (--be >= bp) {
-                       hval ^= (unsigned int) *be;
+                       hval ^= (isc_uint32_t) *be;
                        hval *= 16777619;
                }
        } else {
                while (be >= bp + 4) {
                        be -= 4;
-                       hval ^= (unsigned int) maptolower[be[3]];
+                       hval ^= (isc_uint32_t) maptolower[be[3]];
                        hval *= 16777619;
-                       hval ^= (unsigned int) maptolower[be[2]];
+                       hval ^= (isc_uint32_t) maptolower[be[2]];
                        hval *= 16777619;
-                       hval ^= (unsigned int) maptolower[be[1]];
+                       hval ^= (isc_uint32_t) maptolower[be[1]];
                        hval *= 16777619;
-                       hval ^= (unsigned int) maptolower[be[0]];
+                       hval ^= (isc_uint32_t) maptolower[be[0]];
                        hval *= 16777619;
                }
                while (--be >= bp) {
-                       hval ^= (unsigned int) maptolower[*be];
+                       hval ^= (isc_uint32_t) maptolower[*be];
                        hval *= 16777619;
                }
        }
index b084ad2810afaba005040c34c2a5ce451fe651fc..4f35c46c37d9c0122a27f654b7bc6cc89d16032e 100644 (file)
@@ -180,14 +180,14 @@ isc_hash_calc(const unsigned char *key, unsigned int keylen,
  */
 /*@}*/
 
-unsigned int
+isc_uint32_t
 isc_hash_function(const void *data, size_t length,
                  isc_boolean_t case_sensitive,
-                 unsigned int *previous_hashp);
-unsigned int
+                 const isc_uint32_t *previous_hashp);
+isc_uint32_t
 isc_hash_function_reverse(const void *data, size_t length,
                          isc_boolean_t case_sensitive,
-                         unsigned int *previous_hashp);
+                         const isc_uint32_t *previous_hashp);
 /*!<
  * \brief Calculate a hash over data.
  *
index 854425750bcd2230337fd0b8abf976b112d6affa..c16255843b4f8d63634db1e92726a264359a9c63 100644 (file)
@@ -1987,53 +1987,43 @@ isc___mempool_get(isc_mempool_t *mpctx0 FLARG) {
        /*
         * Don't let the caller go over quota
         */
-       if (mpctx->allocated >= mpctx->maxalloc) {
+       if (ISC_UNLIKELY(mpctx->allocated >= mpctx->maxalloc)) {
                item = NULL;
                goto out;
        }
 
-       /*
-        * if we have a free list item, return the first here
-        */
-       item = mpctx->items;
-       if (item != NULL) {
-               mpctx->items = item->next;
-               INSIST(mpctx->freecount > 0);
-               mpctx->freecount--;
-               mpctx->gets++;
-               mpctx->allocated++;
-               goto out;
-       }
-
-       /*
-        * We need to dip into the well.  Lock the memory context here and
-        * fill up our free list.
-        */
-       MCTXLOCK(mctx, &mctx->lock);
-       for (i = 0; i < mpctx->fillcount; i++) {
-               if ((mctx->flags & ISC_MEMFLAG_INTERNAL) != 0) {
-                       item = mem_getunlocked(mctx, mpctx->size);
-               } else {
-                       item = mem_get(mctx, mpctx->size);
-                       if (item != NULL)
-                               mem_getstats(mctx, mpctx->size);
+       if (ISC_UNLIKELY(mpctx->items == NULL)) {
+               /*
+                * We need to dip into the well.  Lock the memory context here and
+                * fill up our free list.
+                */
+               MCTXLOCK(mctx, &mctx->lock);
+               for (i = 0; i < mpctx->fillcount; i++) {
+                       if ((mctx->flags & ISC_MEMFLAG_INTERNAL) != 0) {
+                               item = mem_getunlocked(mctx, mpctx->size);
+                       } else {
+                               item = mem_get(mctx, mpctx->size);
+                               if (item != NULL)
+                                       mem_getstats(mctx, mpctx->size);
+                       }
+                       if (ISC_UNLIKELY(item == NULL))
+                               break;
+                       item->next = mpctx->items;
+                       mpctx->items = item;
+                       mpctx->freecount++;
                }
-               if (item == NULL)
-                       break;
-               item->next = mpctx->items;
-               mpctx->items = item;
-               mpctx->freecount++;
+               MCTXUNLOCK(mctx, &mctx->lock);
        }
-       MCTXUNLOCK(mctx, &mctx->lock);
 
        /*
         * If we didn't get any items, return NULL.
         */
        item = mpctx->items;
-       if (item == NULL)
+       if (ISC_UNLIKELY(item == NULL))
                goto out;
 
        mpctx->items = item->next;
+       INSIST(mpctx->freecount > 0);
        mpctx->freecount--;
        mpctx->gets++;
        mpctx->allocated++;