]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
2502. [cleanup] isc_radix: Improve compliance with coding style,
authorMark Andrews <marka@isc.org>
Mon, 1 Dec 2008 00:04:21 +0000 (00:04 +0000)
committerMark Andrews <marka@isc.org>
Mon, 1 Dec 2008 00:04:21 +0000 (00:04 +0000)
                        document function in <isc/radix.h>. [RT #18534]

CHANGES
lib/dns/acl.c
lib/dns/iptable.c
lib/isc/include/isc/radix.h
lib/isc/radix.c

diff --git a/CHANGES b/CHANGES
index 07c4466550c1d1e9a31958a08fed333dd112321e..d7a8815740e81a690e144bb7a9560c133cf97eea 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,3 +1,6 @@
+2502.  [cleanup]       isc_radix: Improve compliance with coding style,
+                       document function in <isc/radix.h>. [RT #18534]
+
 2501.  [func]          $GENERATE now supports all rdata types.  Multi-field
                        rdata types need to be quoted.  See the ARM for
                        details. [RT #18368]
index ed4aab9d7bad476d7523e42dc22f8dc3038544fd..4c5909ffdbb251bd2c8efd963bf1d9ff8baa00ae 100644 (file)
@@ -15,7 +15,7 @@
  * PERFORMANCE OF THIS SOFTWARE.
  */
 
-/* $Id: acl.c,v 1.50 2008/09/26 23:47:06 tbox Exp $ */
+/* $Id: acl.c,v 1.51 2008/12/01 00:04:21 marka Exp $ */
 
 /*! \file */
 
@@ -191,7 +191,7 @@ dns_acl_match(const isc_netaddr_t *reqaddr,
 {
        isc_uint16_t bitlen, family;
        isc_prefix_t pfx;
-       isc_radix_node_t *node;
+       isc_radix_node_t *node = NULL;
        const isc_netaddr_t *addr;
        isc_netaddr_t v4addr;
        isc_result_t result;
index 5e9c63f2a10d2ad4fcc59100b89fc59150068e95..9edbad94482192df5b51ca5b09f4a837ad170b23 100644 (file)
@@ -14,7 +14,7 @@
  * PERFORMANCE OF THIS SOFTWARE.
  */
 
-/* $Id: iptable.c,v 1.12 2008/09/26 21:12:02 each Exp $ */
+/* $Id: iptable.c,v 1.13 2008/12/01 00:04:21 marka Exp $ */
 
 #include <isc/mem.h>
 #include <isc/radix.h>
@@ -36,6 +36,7 @@ dns_iptable_create(isc_mem_t *mctx, dns_iptable_t **target) {
                return (ISC_R_NOMEMORY);
        tab->mctx = mctx;
        isc_refcount_init(&tab->refcount, 1);
+       tab->radix = NULL;
        tab->magic = DNS_IPTABLE_MAGIC;
 
        result = isc_radix_create(mctx, &tab->radix, RADIX_MAXBITS);
index 7a62ee59ce641339668dddd360c7bc9f993beb60..f9105ed6ac2fbd335f7360fb25963348f4ec024c 100644 (file)
@@ -14,7 +14,7 @@
  * PERFORMANCE OF THIS SOFTWARE.
  */
 
-/* $Id: radix.h,v 1.11 2008/09/26 21:12:02 each Exp $ */
+/* $Id: radix.h,v 1.12 2008/12/01 00:04:21 marka Exp $ */
 
 /*
  * This source was adapted from MRT's RCS Ids:
@@ -111,25 +111,84 @@ typedef struct isc_radix_tree {
    int num_added_node;                 /* total number of nodes */
 } isc_radix_tree_t;
 
-
 isc_result_t
-isc_radix_search(isc_radix_tree_t *radix, isc_radix_node_t **target, isc_prefix_t *prefix);
+isc_radix_search(isc_radix_tree_t *radix, isc_radix_node_t **target,
+                isc_prefix_t *prefix);
+/*%<
+ * Search 'radix' for the best match to 'prefix'.
+ * Return the node found in '*target'.
+ *
+ * Requires:
+ * \li 'radix' to be valid.
+ * \li 'target' is not NULL and "*target" is NULL.
+ * \li 'prefix' to be valid.
+ *
+ * Returns:
+ * \li ISC_R_NOTFOUND
+ * \li ISC_R_SUCCESS
+ */
 
 isc_result_t
-isc_radix_insert(isc_radix_tree_t *radix, isc_radix_node_t **target, isc_radix_node_t *source, isc_prefix_t *prefix);
+isc_radix_insert(isc_radix_tree_t *radix, isc_radix_node_t **target,
+                isc_radix_node_t *source, isc_prefix_t *prefix);
+/*%<
+ * Insert 'source' or 'prefix' into the radix tree 'radix'.
+ * Return the node added in 'target'.
+ *
+ * Requires:
+ * \li 'radix' to be valid.
+ * \li 'target' is not NULL and "*target" is NULL.
+ * \li 'prefix' to be valid or 'source' to be non NULL and contain
+ *     a valid prefix.
+ *
+ * Returns:
+ * \li ISC_R_NOMEMORY
+ * \li ISC_R_SUCCESS
+ */
 
 void
 isc_radix_remove(isc_radix_tree_t *radix, isc_radix_node_t *node);
+/*%<
+ * Remove the node 'node' from the radix tree 'radix'.
+ *
+ * Requires:
+ * \li 'radix' to be valid.
+ * \li 'node' to be valid.
+ */
 
 isc_result_t
 isc_radix_create(isc_mem_t *mctx, isc_radix_tree_t **target, int maxbits);
+/*%<
+ * Create a radix tree with a maximum depth of 'maxbits';
+ *
+ * Requires:
+ * \li 'mctx' to be valid.
+ * \li 'target' to be non NULL and '*target' to be NULL.
+ * \li 'maxbits' to be less than or equal to RADIX_MAXBITS.
+ *
+ * Returns:
+ * \li ISC_R_NOMEMORY
+ * \li ISC_R_SUCCESS
+ */
 
 void
 isc_radix_destroy(isc_radix_tree_t *radix, isc_radix_destroyfunc_t func);
+/*%<
+ * Destroy a radix tree optionally calling 'func' to clean up node data.
+ *
+ * Requires:
+ * \li 'radix' to be valid.
+ */
 
 void
 isc_radix_process(isc_radix_tree_t *radix, isc_radix_processfunc_t func);
-
+/*%<
+ * Walk a radix tree calling 'func' to process node data.
+ *
+ * Requires:
+ * \li 'radix' to be valid.
+ * \li 'func' to point to a function.
+ */
 
 #define RADIX_MAXBITS 128
 #define RADIX_NBIT(x)        (0x80 >> ((x) & 0x7f))
index c223e8acc9d45c7a6f2871b6a246ec250f39ccad..5342934ca4e41d86cb769acd641c1d65eecd01af 100644 (file)
@@ -14,7 +14,7 @@
  * PERFORMANCE OF THIS SOFTWARE.
  */
 
-/* $Id: radix.c,v 1.20 2008/10/23 00:00:58 marka Exp $ */
+/* $Id: radix.c,v 1.21 2008/12/01 00:04:21 marka Exp $ */
 
 /*
  * This source was adapted from MRT's RCS Ids:
@@ -98,7 +98,7 @@ _ref_prefix(isc_mem_t *mctx, isc_prefix_t **target, isc_prefix_t *prefix) {
        INSIST((prefix->family == AF_INET && prefix->bitlen <= 32) ||
               (prefix->family == AF_INET6 && prefix->bitlen <= 128) ||
               (prefix->family == AF_UNSPEC && prefix->bitlen == 0));
-       REQUIRE(target != NULL);
+       REQUIRE(target != NULL && *target == NULL);
 
        /*
         * If this prefix is a static allocation, copy it into new memory.
@@ -140,7 +140,7 @@ isc_result_t
 isc_radix_create(isc_mem_t *mctx, isc_radix_tree_t **target, int maxbits) {
        isc_radix_tree_t *radix;
 
-       REQUIRE(target != NULL);
+       REQUIRE(target != NULL && *target == NULL);
 
        radix = isc_mem_get(mctx, sizeof(isc_radix_tree_t));
        if (radix == NULL)
@@ -235,7 +235,8 @@ isc_radix_process(isc_radix_tree_t *radix, isc_radix_processfunc_t func)
 
 isc_result_t
 isc_radix_search(isc_radix_tree_t *radix, isc_radix_node_t **target,
-                isc_prefix_t *prefix) {
+                isc_prefix_t *prefix)
+{
        isc_radix_node_t *node;
        isc_radix_node_t *stack[RADIX_MAXBITS + 1];
        u_char *addr;
@@ -245,6 +246,7 @@ isc_radix_search(isc_radix_tree_t *radix, isc_radix_node_t **target,
 
        REQUIRE(radix != NULL);
        REQUIRE(prefix != NULL);
+       REQUIRE(target != NULL && *target == NULL);
        RUNTIME_CHECK(prefix->bitlen <= radix->maxbits);
 
        *target = NULL;
@@ -257,7 +259,6 @@ isc_radix_search(isc_radix_tree_t *radix, isc_radix_node_t **target,
        addr = isc_prefix_touchar(prefix);
        bitlen = prefix->bitlen;
 
-
        while (node->bit < bitlen) {
                if (node->prefix)
                        stack[cnt++] = node;
@@ -308,6 +309,7 @@ isc_radix_insert(isc_radix_tree_t *radix, isc_radix_node_t **target,
        isc_result_t result;
 
        REQUIRE(radix != NULL);
+       REQUIRE(target != NULL && *target == NULL);
        REQUIRE(prefix != NULL || (source != NULL && source->prefix != NULL));
        RUNTIME_CHECK(prefix == NULL || prefix->bitlen <= radix->maxbits);
 
@@ -325,6 +327,7 @@ isc_radix_insert(isc_radix_tree_t *radix, isc_radix_node_t **target,
                        return (ISC_R_NOMEMORY);
                node->bit = bitlen;
                node->node_num[0] = node->node_num[1] = -1;
+               node->prefix = NULL;
                result = _ref_prefix(radix->mctx, &node->prefix, prefix);
                if (result != ISC_R_SUCCESS) {
                        isc_mem_put(radix->mctx, node,
@@ -503,6 +506,7 @@ isc_radix_insert(isc_radix_tree_t *radix, isc_radix_node_t **target,
                }
        }
        new_node->bit = bitlen;
+       new_node->prefix = NULL;
        result = _ref_prefix(radix->mctx, &new_node->prefix, prefix);
        if (result != ISC_R_SUCCESS) {
                isc_mem_put(radix->mctx, new_node, sizeof(isc_radix_node_t));