]> git.ipfire.org Git - thirdparty/bird.git/commitdiff
Many small improvements
authorIgor Putovny <igor.putovny@nic.cz>
Fri, 25 Apr 2025 11:43:23 +0000 (13:43 +0200)
committerIgor Putovny <igor.putovny@nic.cz>
Tue, 29 Apr 2025 13:01:15 +0000 (15:01 +0200)
proto/aggregator/aggregator.c
proto/aggregator/aggregator.h
proto/aggregator/trie.c

index d35a67266c972c42213f4cd8754430333e6d3aa3..b70147d4f24e204c43c21128d294b56b706107ae 100644 (file)
@@ -83,8 +83,8 @@ aggregator_withdraw_rte(struct aggregator_proto *p)
 {
   if ((p->addr_type == NET_IP4 && p->rte_withdrawal_count > IP4_WITHDRAWAL_MAX_EXPECTED_LIMIT) ||
       (p->addr_type == NET_IP6 && p->rte_withdrawal_count > IP6_WITHDRAWAL_MAX_EXPECTED_LIMIT))
-    log(L_WARN "This number of updates was not expected."
-               "They will be processed. Please, report this to developers.");
+    log(L_WARN "This number of updates was not expected. "
+               "Please, report this to developers.");
 
   struct rte_withdrawal_item *node = NULL;
 
@@ -139,8 +139,8 @@ aggregator_aggregate_on_feed_end(struct channel *C)
   ASSERT_DIE(p->aggr_mode == PREFIX_AGGR);
   ASSERT_DIE(p->root != NULL);
 
-  aggregator_aggregate(p);
   p->initial_feed = false;
+  aggregator_aggregate(p);
 }
 
 /*
@@ -212,7 +212,7 @@ aggregator_rta_set_static_attr(struct rta *rta, const struct rta *old, struct f_
  * @count: number of &f_val entries
  */
 static int
-aggregator_same_val_list(const struct f_val *v1, const struct f_val *v2, u32 len)
+aggregator_same_val_list(const struct f_val *v1, const struct f_val *v2, uint len)
 {
   for (u32 i = 0; i < len; i++)
     if (!val_same(&v1[i], &v2[i]))
@@ -600,7 +600,7 @@ aggregator_rt_notify(struct proto *P, struct channel *src_ch, net *net, rte *new
     }
 
     /* Compute the hash */
-    u64 haux;
+    u64 haux = 0;
     mem_hash_init(&haux);
 
     for (u32 i = 0; i < p->aggr_on_count; i++)
@@ -827,7 +827,6 @@ aggregator_postconfig(struct proto_config *CF)
   cf->dst->debug = cf->src->debug;
 }
 
-// TODO: set pools to NULL?
 static struct proto *
 aggregator_init(struct proto_config *CF)
 {
@@ -844,13 +843,10 @@ aggregator_init(struct proto_config *CF)
   p->aggr_on            = cf->aggr_on;
   p->merge_by           = cf->merge_by;
   p->logging            = cf->logging;
-  p->bucket_list        = NULL;
-  p->bucket_list_size   = 0;
-  p->buckets_count      = 0;
 
   P->rt_notify = aggregator_rt_notify;
   P->preexport = aggregator_preexport;
-  P->feed_end = aggregator_aggregate_on_feed_end;
+  P->feed_end  = aggregator_aggregate_on_feed_end;
 
   return P;
 }
@@ -867,12 +863,9 @@ aggregator_trie_init(struct aggregator_proto *p)
   /* Zero prefix for default route */
   ip_addr prefix = (p->addr_type == NET_IP4) ? ipa_from_ip4(IP4_NONE) : ipa_from_ip6(IP6_NONE);
 
-  struct net_addr addr = { 0 };
-  net_fill_ipa(&addr, prefix, 0);
-
   /* Create net for zero prefix */
-  struct network *default_net = mb_allocz(p->p.pool, sizeof(*default_net) + sizeof(addr));
-  net_copy(default_net->n.addr, &addr);
+  struct network *default_net = mb_allocz(p->p.pool, sizeof(*default_net) + sizeof(struct net_addr));
+  net_fill_ipa(default_net->n.addr, prefix, 0);
 
   /* Create route attributes with zero nexthop */
   struct rta rta = { 0 };
@@ -987,20 +980,18 @@ aggregator_cleanup(struct proto *P)
   p->trie_slab = NULL;
   p->rte_withdrawal_pool = NULL;
 
+  p->bucket_id_map = (struct hmap) { 0 };
+  p->buckets_count = 0;
+
   p->root = NULL;
+  p->bitmap_size = 0;
+  p->initial_feed = true;
 
   p->bucket_list = NULL;
   p->bucket_list_size = 0;
-  p->buckets_count = 0;
 
   p->rte_withdrawal_stack = NULL;
   p->rte_withdrawal_count = 0;
-
-  p->bucket_id_map = (struct hmap) { 0 };
-
-  p->initial_feed = true;
-
-  p->bitmap_size = 0;
 }
 
 static int
index d45e784bc60dc47116936fa27d5e71643f0024d5..22fe611bfca686c408c0bfb94acc227be71af6f5 100644 (file)
@@ -28,12 +28,12 @@ enum aggregation_mode {
 struct aggregator_config {
   struct proto_config c;
   struct channel_config *src, *dst;
-  enum aggregation_mode aggr_mode;
+  struct aggr_item *aggr_on;
   u32 aggr_on_count;
   u32 aggr_on_da_count;
-  struct aggr_item *aggr_on;
   const struct f_line *merge_by;
-  int logging;
+  enum aggregation_mode aggr_mode;
+  bool logging;
 };
 
 struct aggregator_route {
@@ -49,7 +49,7 @@ struct aggregator_bucket {
   u32 count;
   u32 hash;
   u32 id;
-  struct f_val aggr_data[0];
+  struct f_val aggr_data[];
 };
 
 struct rte_withdrawal_item {
index c5508417d2e51d2c59297c53b1bb7f74f0a32d1f..acf6f111f2d7944ca3832c6fe3ae651587bdd729 100644 (file)
 #include "filter/filter.h"
 #include "proto/aggregator/aggregator.h"
 
+/* Only u32 is allowed to use in bitmap because of use of BIT32 macros */
+STATIC_ASSERT(sizeof(((struct trie_node *)0)->potential_buckets[0]) == sizeof(u32));
+
 static const char *px_origin_str[] = {
   [FILLER]     = "filler",
   [ORIGINAL]   = "original",
@@ -456,12 +459,6 @@ aggregator_prepare_rte_withdrawal(struct aggregator_proto *p, ip_addr prefix, u3
 
   /* Fill in net and bucket */
   net_fill_ipa(&item->addr, prefix, pxlen);
-#if 0 // TODO
-  struct net_addr addr = { 0 };
-  net_fill_ipa(&addr, prefix, pxlen);
-  net_copy(&item->addr, &addr);
-#endif
-
   item->bucket = bucket;
 
   /* Push item onto stack */
@@ -774,7 +771,6 @@ aggregator_export_node_prefix(struct aggregator_proto *p, struct trie_node *node
 
   /* Select bucket with the lowest ID */
   node->selected_bucket = aggregator_select_lowest_id_bucket(p, node);
-  ASSERT_DIE(node->selected_bucket != NULL);
 
   /* Node status is changing from NON_FIB to IN_FIB, export its route */
   if (node->status != IN_FIB)
@@ -804,7 +800,7 @@ aggregator_export_node_prefix(struct aggregator_proto *p, struct trie_node *node
  * Remove prefix of the current node from FIB and set node status to NON_FIB
  */
 static void
-aggregator_remove_node_prefix(struct aggregator_proto *p, struct trie_node *node, ip_addr prefix, u32 pxlen)
+aggregator_withdraw_node_prefix(struct aggregator_proto *p, struct trie_node *node, ip_addr prefix, u32 pxlen)
 {
   /* Node status is changing from IN_FIB to NON_FIB, withdraw its route */
   if (node->status == IN_FIB)
@@ -856,7 +852,7 @@ aggregator_group_prefixes_helper(struct aggregator_proto *p, struct trie_node *n
    * inherits one, and its prefix is thus not needed in FIB.
    */
   if (aggregator_is_bucket_potential(node, inherited_bucket->id, p->bitmap_size))
-    aggregator_remove_node_prefix(p, node, *prefix, pxlen);
+    aggregator_withdraw_node_prefix(p, node, *prefix, pxlen);
   else
     aggregator_export_node_prefix(p, node, *prefix, pxlen);
 
@@ -1024,8 +1020,8 @@ aggregator_construct_trie(struct aggregator_proto *p)
     {
       const struct net_addr *addr = rte->net->n.addr;
 
-      const ip_addr prefix = net_prefix(addr);
-      const u32 pxlen = net_pxlen(addr);
+      ip_addr prefix = net_prefix(addr);
+      u32 pxlen = net_pxlen(addr);
 
       aggregator_trie_insert_prefix(p, prefix, pxlen, bucket);
     }
@@ -1069,8 +1065,8 @@ aggregator_recompute(struct aggregator_proto *p, struct aggregator_route *old, s
   {
     const struct net_addr *addr = old->rte.net->n.addr;
 
-    const ip_addr prefix = net_prefix(addr);
-    const u32 pxlen = net_pxlen(addr);
+    ip_addr prefix = net_prefix(addr);
+    u32 pxlen = net_pxlen(addr);
 
     updated_node = aggregator_trie_remove_prefix(p, prefix, pxlen);
     ASSERT_DIE(updated_node != NULL);
@@ -1079,8 +1075,8 @@ aggregator_recompute(struct aggregator_proto *p, struct aggregator_route *old, s
   {
     const struct net_addr *addr = new->rte.net->n.addr;
 
-    const ip_addr prefix = net_prefix(addr);
-    const u32 pxlen = net_pxlen(addr);
+    ip_addr prefix = net_prefix(addr);
+    u32 pxlen = net_pxlen(addr);
 
     updated_node = aggregator_trie_insert_prefix(p, prefix, pxlen, new->bucket);