0
0
mirror of https://gitlab.nic.cz/labs/bird.git synced 2024-11-09 20:58:44 +00:00

Add debugging logs

This commit is contained in:
Igor Putovny 2024-02-29 14:40:21 +01:00
parent ade731e02a
commit da65a073c5
3 changed files with 88 additions and 0 deletions

View File

@ -73,11 +73,19 @@
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; \
})

View File

@ -65,6 +65,24 @@
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);

View 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 {