From 701e9e9f8fc992d3733afc4013e22be852074ac7 Mon Sep 17 00:00:00 2001 From: Igor Putovny Date: Wed, 12 Feb 2025 17:24:03 +0100 Subject: [PATCH] Rewrite trie_insert_prefix() using ip_addr instead of net_addr --- proto/aggregator/aggregator.c | 38 ++++------------------------------- 1 file changed, 4 insertions(+), 34 deletions(-) diff --git a/proto/aggregator/aggregator.c b/proto/aggregator/aggregator.c index acbb7ac35..7d87fcdd0 100644 --- a/proto/aggregator/aggregator.c +++ b/proto/aggregator/aggregator.c @@ -398,57 +398,27 @@ create_route(struct aggregator_proto *p, ip_addr prefix, u32 pxlen, struct aggre * Insert prefix in @addr to prefix trie with beginning at @root and assign @bucket to this prefix. * If the prefix is already in the trie, update its bucket to @bucket and return updated node. */ -static struct trie_node * -trie_insert_prefix_ip4(struct trie_node * const root, const struct net_addr_ip4 *addr, struct aggregator_bucket *bucket, linpool *trie_pool) -{ - assert(addr != NULL); - assert(bucket != NULL); - assert(root != NULL); - assert(trie_pool != NULL); - struct trie_node *node = root; - for (u32 i = 0; i < addr->pxlen; i++) - { - u32 bit = ip4_getbit(addr->prefix, i); - if (!node->child[bit]) - { - struct trie_node *new = create_new_node(trie_pool); - *new = (struct trie_node) { - .parent = node, - .status = NON_FIB, - .px_origin = FILLER, - .depth = node->depth + 1, - }; - node->child[bit] = new; - } - node = node->child[bit]; - } - /* Assign bucket to the last node */ - node->original_bucket = bucket; - node->px_origin = ORIGINAL; - return node; -} static struct trie_node * -trie_insert_prefix_ip6(struct trie_node * const root, const struct net_addr_ip6 *addr, struct aggregator_bucket *bucket, linpool *trie_pool) +trie_insert_prefix(struct trie_node * const root, ip_addr prefix, u32 pxlen, struct aggregator_bucket *bucket, linpool *trie_pool) { - assert(addr != NULL); - assert(bucket != NULL); assert(root != NULL); + assert(bucket != NULL); assert(trie_pool != NULL); struct trie_node *node = root; - for (u32 i = 0; i < addr->pxlen; i++) + for (u32 i = 0; i < pxlen; i++) { - u32 bit = ip6_getbit(addr->prefix, i); + u32 bit = ipa_getbit(prefix, i + ipa_shift[p->addr_type]); if (!node->child[bit]) { -- 2.47.2