]> git.ipfire.org Git - thirdparty/bird.git/commitdiff
Add debugging logs
authorIgor Putovny <igor.putovny@nic.cz>
Thu, 29 Feb 2024 13:40:21 +0000 (14:40 +0100)
committerIgor Putovny <igor.putovny@nic.cz>
Thu, 30 May 2024 10:30:00 +0000 (12:30 +0200)
lib/hash.h
proto/aggregator/aggregator.c
proto/aggregator/aggregator.h

index 3c173958ff8146b006c748ddc9715ea4a59d7ea4..389be8e3bf798a629eb9a83b0b96e2e381eae870 100644 (file)
     u32 _h = HASH_FN(v, id, id##_KEY((node)));                         \
     HASH_TYPE(v) *_n, **_nn = (v).data + _h;                           \
                                                                        \
+    log(L_WARN "hash: %u", _h); \
+                                    \
     while ((*_nn) && (*_nn != (node)))                                 \
+    {       \
+      log(L_WARN "_nn: %p", *_nn);  \
       _nn = &(id##_NEXT((*_nn)));                                      \
+    }   \
                                                                        \
     if (_n = *_nn)                                                     \
+    {       \
+      log(L_WARN "Success %p", _n);       \
       HASH_DO_REMOVE(v,id,_nn);                                                \
+    }       \
     _n;                                                                        \
   })
 
index f014bfd1be64112617525edb858980c942771174..b1b23fd32ac1c01c097a231cfb82dffea210f59f 100644 (file)
 
 extern linpool *rte_update_pool;
 
+static void
+dump_hash_table(const struct aggregator_proto *p)
+{
+  log("================ HASH TABLE DUMP ================");
+
+  HASH_WALK(p->buckets, next_hash, b)
+  {
+    for (const struct rte *rte = b->rte; rte; rte = rte->next)
+    {
+      struct net_addr *addr = rte->net->n.addr;
+      log("bucket %p: addr: %N,\troute: %p, net: %p, src: %p", b, addr, rte, rte->net, rte->src);
+    }
+  }
+  HASH_WALK_END;
+
+  log("============== END HASH TABLE DUMP ==============");
+}
+
 static void aggregator_bucket_update(struct aggregator_proto *p, struct aggregator_bucket *bucket, struct network *net);
 
 static inline int
@@ -671,6 +689,8 @@ print_prefixes(const struct trie_node *node, int type)
 static void
 create_route_ip4(struct aggregator_proto *p, const struct net_addr_ip4 *addr, struct aggregator_bucket *bucket)
 {
+  log("create route XXX arte: %p, src: %p", p->default_arte, p->default_arte->rte.src);
+
   struct {
     struct network net;
     union net_addr_union u;
@@ -699,6 +719,8 @@ create_route_ip6(struct aggregator_proto *p, struct net_addr_ip6 *addr, struct a
 static void
 collect_prefixes_helper_ip4(const struct trie_node *node, struct net_addr_ip4 *addr, struct aggregator_proto *p, int depth, int *count)
 {
+  log("collect prefixes XXX arte: %p, src: %p", p->default_arte, p->default_arte->rte.src);
+
   assert(node != NULL);
 
   if (is_leaf(node))
@@ -909,6 +931,8 @@ same_val_list(const struct f_val *v1, const struct f_val *v2, uint len)
 static void
 aggregator_bucket_update(struct aggregator_proto *p, struct aggregator_bucket *bucket, struct network *net)
 {
+  log("XXX arte: %p, src: %p", p->default_arte, p->default_arte->rte.src);
+
   /* Empty bucket */
   if (!bucket->rte)
   {
@@ -950,6 +974,8 @@ aggregator_bucket_update(struct aggregator_proto *p, struct aggregator_bucket *b
   log("New route created: id = %d, protocol: %s", new->src->global_id, new->src->proto->name);
   log("===================================================");
 
+  log("XXX arte: %p, src: %p", p->default_arte, p->default_arte->rte.src);
+
 
   /* merge filter needs one argument called "routes" */
   struct f_val val = {
@@ -1323,6 +1349,8 @@ aggregator_rt_notify(struct proto *P, struct channel *src_ch, net *net, rte *new
     else
       new->attrs = rta_lookup(new->attrs);
 
+    log("new rte: %p, net: %p, src: %p, hash: %x", new, new->net, new->src, aggr_route_hash(new));
+
     /* Insert the new route into the bucket */
     struct aggregator_route *arte = sl_alloc(p->route_slab);
     *arte = (struct aggregator_route) {
@@ -1333,6 +1361,7 @@ aggregator_rt_notify(struct proto *P, struct channel *src_ch, net *net, rte *new
     new_bucket->rte = &arte->rte;
     new_bucket->count++;
     HASH_INSERT2(p->routes, AGGR_RTE, p->p.pool, arte);
+    log("Inserting rte: %p, arte: %p, net: %p, src: %p, hash: %x", &arte->rte, arte, arte->rte.net, arte->rte.src, aggr_route_hash(&arte->rte));
   }
 
   /* Remove the old route from its bucket */
@@ -1351,6 +1380,8 @@ aggregator_rt_notify(struct proto *P, struct channel *src_ch, net *net, rte *new
     sl_free(old_route);
   }
 
+  dump_hash_table(p);
+
   HASH_WALK(p->buckets, next_hash, bucket)
   {
     for (const struct rte *rte = bucket->rte; rte; rte = rte->next)
@@ -1497,6 +1528,8 @@ aggregator_start(struct proto *P)
   arte->rte.net = default_net;
   default_net->routes = &arte->rte;
 
+  p->default_arte = arte;
+
   HASH_INSERT2(p->routes, AGGR_RTE, p->p.pool, arte);
   HASH_INSERT2(p->buckets, AGGR_BUCK, p->p.pool, new_bucket);
 
@@ -1511,16 +1544,61 @@ aggregator_shutdown(struct proto *P)
 {
   struct aggregator_proto *p = SKIP_BACK(struct aggregator_proto, p, P);
 
+  HASH_WALK(p->buckets, next_hash, b)
+  {
+    log(L_WARN "Buckets: %u %p", _i, b);
+
+    for (struct rte *r = b->rte; r; r = r->next)
+    {
+      log(L_WARN "    in bucket: %p", SKIP_BACK(struct aggregator_route, rte, r));
+    }
+  }
+  HASH_WALK_END;
+
+  HASH_WALK(p->routes, next_hash, r)
+  {
+    log(L_WARN "Routes: %u %p, net: %p, src: %p, hash: %x", _i, r, r->rte.net, r->rte.src, aggr_route_hash(&r->rte));
+  }
+  HASH_WALK_END;
+
   HASH_WALK_DELSAFE(p->buckets, next_hash, b)
   {
     while (b->rte)
     {
+      {
+        HASH_WALK(p->routes, next_hash, r)
+        {
+          log(L_WARN "%u %p", _i, r);
+        }
+        HASH_WALK_END;
+      }
+
+      log("Hash table dump before");
+      dump_hash_table(p);
+
       struct aggregator_route *arte = SKIP_BACK(struct aggregator_route, rte, b->rte);
+      struct net_addr *addr = arte->rte.net->n.addr;
+
+      log("Removing arte %p, rte: %p, addr: %N, net: %p, src: %p, hash: %x",
+          arte, &arte->rte, addr, arte->rte.net, arte->rte.src, aggr_route_hash(&arte->rte));
+
+      net_addr_union *n = (void *)arte->rte.net->n.addr;
+      log("Net type: %d", n->n.type);
       b->rte = arte->rte.next;
       b->count--;
+      int count_before_remove = p->routes.count;
+
+      assert(n->n.type == NET_IP4);
+      log("Hash count before HASH_REMOVE: %d", count_before_remove);
       HASH_REMOVE(p->routes, AGGR_RTE, arte);
+      int count_after_remove = p->routes.count;
+      log("Hash count after HASH_REMOVE:  %d", count_after_remove);
+      assert(count_before_remove == count_after_remove + 1);
       rta_free(arte->rte.attrs);
       sl_free(arte);
+
+      log("Hash table dump after");
+      dump_hash_table(p);
     }
 
     ASSERT_DIE(b->count == 0);
index b2fd01551b714f85eccfceded232a35e38079f2f..37c439dd7082f1d6d037b9d6521821a887f838e9 100644 (file)
@@ -71,6 +71,8 @@ struct aggregator_proto {
   struct trie_node *root;
 
   struct event reload_trie;
+
+  struct aggregator_route *default_arte;
 };
 
 enum aggr_item_type {