+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]
* 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 */
{
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;
* 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>
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);
* 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:
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))
* 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:
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.
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)
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;
REQUIRE(radix != NULL);
REQUIRE(prefix != NULL);
+ REQUIRE(target != NULL && *target == NULL);
RUNTIME_CHECK(prefix->bitlen <= radix->maxbits);
*target = NULL;
addr = isc_prefix_touchar(prefix);
bitlen = prefix->bitlen;
-
while (node->bit < bitlen) {
if (node->prefix)
stack[cnt++] = node;
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);
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,
}
}
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));