aboutsummaryrefslogtreecommitdiffstats
path: root/radix-trie.c
diff options
context:
space:
mode:
authorThomas Gschwantner <tharre3@gmail.com>2019-07-16 01:06:54 +0200
committerThomas Gschwantner <tharre3@gmail.com>2019-07-16 01:06:54 +0200
commit860ff77f1b1e66952ce384ae89f6f9546b67e843 (patch)
tree1278c79435b0247314109e62334ff21d75e01ee3 /radix-trie.c
parentUse epoll() instead of poll() (diff)
downloadwg-dynamic-860ff77f1b1e66952ce384ae89f6f9546b67e843.tar.xz
wg-dynamic-860ff77f1b1e66952ce384ae89f6f9546b67e843.zip
radix-trie: inline find_node() into ipp_addpool()
The way find_node() was written to suit ipp_addpool() means it's not really generic and rather confusing, so we inline it instead.
Diffstat (limited to 'radix-trie.c')
-rw-r--r--radix-trie.c24
1 files changed, 8 insertions, 16 deletions
diff --git a/radix-trie.c b/radix-trie.c
index fbbfea2..00d9941 100644
--- a/radix-trie.c
+++ b/radix-trie.c
@@ -350,24 +350,11 @@ static int insert_v6(struct radix_node **root, const struct in6_addr *ip,
return ret;
}
-static struct radix_node *find_node(struct radix_node *trie, uint8_t bits,
- const uint8_t *key)
-{
- struct radix_node *node = trie, *found = NULL;
-
- while (node && prefix_matches(node, key, bits)) {
- found = node;
- if (node->cidr == bits)
- break;
- node = CHOOSE_NODE(node, key);
- }
- return found;
-}
-
static int ipp_addpool(struct radix_pool **pool, struct radix_node **root,
uint8_t bits, const uint8_t *key, uint8_t cidr)
{
struct radix_pool *newpool;
+ struct radix_node *node;
while (*pool) {
if (common_bits((*pool)->node, key, bits) >= cidr)
@@ -388,8 +375,13 @@ static int ipp_addpool(struct radix_pool **pool, struct radix_node **root,
if (!newpool)
fatal("malloc()");
- newpool->node = find_node(*root, bits, key);
- BUG_ON(!newpool->node);
+ node = *root;
+ while (node->cidr != cidr) {
+ node = CHOOSE_NODE(node, key);
+
+ BUG_ON(!node || !prefix_matches(node, key, bits));
+ }
+ newpool->node = node;
newpool->next = NULL;
*pool = newpool;