From 860ff77f1b1e66952ce384ae89f6f9546b67e843 Mon Sep 17 00:00:00 2001 From: Thomas Gschwantner Date: Tue, 16 Jul 2019 01:06:54 +0200 Subject: 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. --- radix-trie.c | 24 ++++++++---------------- 1 file 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; -- cgit v1.2.3-59-g8ed1b