From: Igor Putovny Date: Wed, 12 Feb 2025 17:38:33 +0000 (+0100) Subject: Rewrite find_subtree_prefix() using ip_addr instead of net_addr X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1dda94c33cb981fc0d4161bfd4aac134e0ee1c2f;p=thirdparty%2Fbird.git Rewrite find_subtree_prefix() using ip_addr instead of net_addr --- diff --git a/proto/aggregator/aggregator.c b/proto/aggregator/aggregator.c index cee45ee8f..1117160d9 100644 --- a/proto/aggregator/aggregator.c +++ b/proto/aggregator/aggregator.c @@ -495,19 +495,25 @@ trie_remove_prefix(struct aggregator_proto *p, ip_addr prefix, u32 pxlen) return node; } +/* + * Find prefix corresponding to the position of @target in the trie. + * Save result in @prefix and @pxlen. + */ static void -find_subtree_prefix(const struct trie_node *target, struct net_addr_ip4 *addr) +find_subtree_prefix(const struct trie_node *target, ip_addr *prefix, u32 *pxlen, u32 type) { assert(target != NULL); - assert(addr != NULL); + assert(prefix != NULL); + assert(pxlen != NULL); - int path[128] = { 0 }; + int path[IP6_MAX_PREFIX_LENGTH] = { 0 }; int pos = 0; + u32 len = 0; const struct trie_node *node = target; const struct trie_node *parent = node->parent; - /* Go from the target node to the root node and save the path taken */ + /* Ascend to the root node */ while (parent) { if (node == parent->child[0]) @@ -515,27 +521,29 @@ find_subtree_prefix(const struct trie_node *target, struct net_addr_ip4 *addr) else if (node == parent->child[1]) path[pos++] = 1; else - bug("Impossible"); + bug("Fatal error"); - assert(pos < 128); + assert(pos < IP6_MAX_PREFIX_LENGTH); node = parent; parent = node->parent; } assert(node->parent == NULL); - /* Descend from the root node to the target node */ + /* Descend to the target node */ for (int i = pos - 1; i >= 0; i--) { if (path[i] == 0) - ip4_clrbit(&addr->prefix, node->depth); - else if (path[i] == 1) - ip4_setbit(&addr->prefix, node->depth); + ipa_clrbit(prefix, node->depth + ipa_shift[type]); + else + ipa_setbit(prefix, node->depth + ipa_shift[type]); - addr->pxlen = node->depth + 1; + len++; node = node->child[path[i]]; + assert(node->depth + 1 == len); } + *pxlen = len; assert(node == target); }