]> git.ipfire.org Git - thirdparty/bird.git/commitdiff
Rewrite dump_trie() using ip_addr instead of net_addr
authorIgor Putovny <igor.putovny@nic.cz>
Wed, 12 Feb 2025 18:43:08 +0000 (19:43 +0100)
committerIgor Putovny <igor.putovny@nic.cz>
Wed, 12 Feb 2025 18:43:08 +0000 (19:43 +0100)
proto/aggregator/aggregator.c

index 9d8d23a3c7de07e578a5806cf35a0ae7f2134da5..0b1d280ec16ab69e84c5caf1fe7ec0e4ab723a96 100644 (file)
@@ -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 ====");
 }