mirror of
https://github.com/isc-projects/bind9.git
synced 2026-02-24 10:21:10 -05:00
2502. [cleanup] isc_radix: Improve compliance with coding style,
document function in <isc/radix.h>. [RT #18534]
This commit is contained in:
parent
46018d5d23
commit
175a8bd2b7
5 changed files with 81 additions and 14 deletions
3
CHANGES
3
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]
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
/*%<
|
||||
* 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_search(isc_radix_tree_t *radix, isc_radix_node_t **target, isc_prefix_t *prefix);
|
||||
|
||||
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))
|
||||
|
|
|
|||
|
|
@ -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));
|
||||
|
|
|
|||
Loading…
Reference in a new issue