]> git.ipfire.org Git - thirdparty/bird.git/commitdiff
Refactor second_pass()
authorIgor Putovny <igor.putovny@nic.cz>
Tue, 11 Mar 2025 15:50:13 +0000 (16:50 +0100)
committerIgor Putovny <igor.putovny@nic.cz>
Tue, 11 Mar 2025 15:50:13 +0000 (16:50 +0100)
proto/aggregator/trie.c

index 4aef6c222848d8fe9ceee83d7c3a18c7fb982309..6a0bc75714c47001a8e7ed62888bda95683576bd 100644 (file)
@@ -552,23 +552,35 @@ aggregator_second_pass(struct trie_node *node, int recomputing)
   ASSERT_DIE(node->status != UNASSIGNED_FIB);
   ASSERT_DIE(node->potential_buckets_count <= MAX_POTENTIAL_BUCKETS_COUNT);
 
+  if (!recomputing)
+    ASSERT_DIE(node->px_origin == ORIGINAL || node->px_origin == FILLER);
+
+  /* Propagate original buckets */
+  if (node->px_origin != ORIGINAL)
+  {
+    if (!recomputing)
+    {
+      ASSERT_DIE(node->px_origin == FILLER);
+      ASSERT_DIE(node->original_bucket == NULL);
+    }
+
+    node->original_bucket = node->parent->original_bucket;
+
+    /* When recomputing, aggregated nodes become fillers */
+    node->px_origin = FILLER;
+  }
+  else
+  {
+    ASSERT_DIE(node->original_bucket != NULL);
+  }
+
+  /* Clear sets */
   if (recomputing)
   {
-    // TODO: it is not necessary to clear sets of all nodes, only leaves. Sets
-    // of internal nodes will be overwritten by merging.
-    node->ancestor = NULL;
     node->potential_buckets_count = 0;
     memset(node->potential_buckets, 0, sizeof(node->potential_buckets));
-
-    if (node->px_origin != ORIGINAL)
-    {
-      ASSERT_DIE(node->parent != NULL);
-      node->original_bucket = node->parent->original_bucket;
-      node->px_origin = FILLER;
-    }
   }
 
-  /* Leaves get original bucket as their potential bucket */
   if (aggregator_is_leaf(node))
   {
     ASSERT_DIE(node->original_bucket != NULL);
@@ -577,15 +589,6 @@ aggregator_second_pass(struct trie_node *node, int recomputing)
     return;
   }
 
-  /* Propagate original buckets */
-  if (!node->original_bucket)
-  {
-    if (recomputing)
-      bug("Should not happen");
-
-    node->original_bucket = node->parent->original_bucket;
-  }
-
   /* Internal node */
   ASSERT_DIE(node->potential_buckets_count == 0);