From 4f59489d4fc834e285dbe60a0d7b1c5e928dae81 Mon Sep 17 00:00:00 2001 From: Igor Putovny Date: Wed, 12 Feb 2025 19:43:08 +0100 Subject: [PATCH] Rewrite dump_trie() using ip_addr instead of net_addr --- proto/aggregator/aggregator.c | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/proto/aggregator/aggregator.c b/proto/aggregator/aggregator.c index 9d8d23a3c..0b1d280ec 100644 --- a/proto/aggregator/aggregator.c +++ b/proto/aggregator/aggregator.c @@ -1083,7 +1083,7 @@ trie_process_withdraw(struct aggregator_proto *p, struct aggregator_route *old) } static void -dump_trie_helper(const struct trie_node *node, struct net_addr_ip4 *addr, struct buffer *buf) +dump_trie_helper(const struct aggregator_proto *p, const struct trie_node *node, ip_addr *prefix, u32 pxlen, struct buffer *buf) { assert(node != NULL); assert(addr != NULL); @@ -1124,33 +1124,30 @@ dump_trie_helper(const struct trie_node *node, struct net_addr_ip4 *addr, struct if (node->child[0]) { - ip4_clrbit(&addr->prefix, node->depth); - addr->pxlen = node->depth + 1; - dump_trie_helper(node->child[0], addr, buf); + ipa_clrbit(prefix, node->depth + ipa_shift[p->addr_type]); + dump_trie_helper(p, node->child[0], prefix, pxlen + 1, buf); } if (node->child[1]) { - ip4_setbit(&addr->prefix, node->depth); - addr->pxlen = node->depth + 1; - dump_trie_helper(node->child[1], addr, buf); - ip4_clrbit(&addr->prefix, node->depth); + ipa_setbit(prefix, node->depth + ipa_shift[p->addr_type]); + dump_trie_helper(p, node->child[1], prefix, pxlen + 1, buf); + ipa_clrbit(prefix, node->depth + ipa_shift[p->addr_type]); } } static void -dump_trie(const struct trie_node *root) +dump_trie(const struct aggregator_proto *p) { assert(root != NULL); + ip_addr prefix = (NET_IP4 == p->addr_type) ? ipa_from_ip4(IP4_NONE) : ipa_from_ip6(IP6_NONE); + struct buffer buf = { 0 }; LOG_BUFFER_INIT(buf); - struct net_addr_ip4 addr = { 0 }; - net_fill_ip4((net_addr *)&addr, IP4_NONE, 0); - log("==== TRIE BEGIN ===="); - dump_trie_helper(root, &addr, &buf); + dump_trie_helper(p, root, &prefix, 0, &buf); log("==== TRIE END ===="); } -- 2.47.2