]> git.ipfire.org Git - thirdparty/bird.git/commitdiff
Add variable to track node depth in the trie
authorIgor Putovny <igor.putovny@nic.cz>
Wed, 27 Mar 2024 11:03:47 +0000 (12:03 +0100)
committerIgor Putovny <igor.putovny@nic.cz>
Thu, 30 May 2024 10:30:00 +0000 (12:30 +0200)
proto/aggregator/aggregator.c
proto/aggregator/aggregator.h

index a1889588c0c708a5fee1123dd703cb3886334f4a..a1834ccc7f2649543b7ed3e157dccf37ebf4dbbc 100644 (file)
@@ -169,6 +169,7 @@ trie_insert_prefix_ip4(const struct net_addr_ip4 *addr, struct trie_node *const
       struct trie_node *new = new_node(trie_slab);
       new->parent = node;
       node->child[bit] = new;
+      new->depth = new->parent->depth + 1;
     }
 
     node = node->child[bit];
@@ -197,10 +198,14 @@ trie_insert_prefix_ip6(const struct net_addr_ip6 *addr, struct trie_node * const
       struct trie_node *new = new_node(trie_slab);
       new->parent = node;
       node->child[bit] = new;
+      new->depth = new->parent->depth + 1;
     }
 
     node = node->child[bit];
   }
+
+  /* Assign bucket to the last node */
+  node->bucket = bucket;
 }
 
 /*
@@ -255,6 +260,7 @@ first_pass(struct trie_node *node, slab *trie_slab)
       new->parent = node;
       new->bucket = get_ancestor_bucket(new);
       node->child[i] = new;
+      new->depth = new->parent->depth + 1;
     }
   }
 
@@ -1537,6 +1543,7 @@ aggregator_start(struct proto *P)
 
   p->trie_slab = sl_new(p->p.pool, sizeof(struct trie_node));
   p->root = new_node(p->trie_slab);
+  p->root->depth = 1;
 
   p->reload_trie = (event) {
     .hook = calculate_trie,
index a40fb8120cb80e562d0a8474a18861bc7e86f2e9..c92c46462dafe5c7a1d007360ee3dcbc37c9d283 100644 (file)
@@ -100,6 +100,7 @@ struct trie_node {
   struct aggregator_bucket *bucket;
   struct aggregator_bucket *potential_buckets[MAX_POTENTIAL_BUCKETS_COUNT];
   int potential_buckets_count;
+  int depth;
 };
 
 struct prefix_bucket {