From: Igor Putovny Date: Tue, 11 Mar 2025 15:50:13 +0000 (+0100) Subject: Refactor second_pass() X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2cf65b429906699f411fbeefec045359140acb5b;p=thirdparty%2Fbird.git Refactor second_pass() --- diff --git a/proto/aggregator/trie.c b/proto/aggregator/trie.c index 4aef6c222..6a0bc7571 100644 --- a/proto/aggregator/trie.c +++ b/proto/aggregator/trie.c @@ -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);