0
0
mirror of https://gitlab.nic.cz/labs/bird.git synced 2024-12-23 02:01:55 +00:00

Use net_addr_ip4 instead of ip4_addr for printing prefixes

This commit is contained in:
Igor Putovny 2023-10-20 12:20:12 +02:00
parent 990cd14e4a
commit f7e3a3f0a0

View File

@ -549,27 +549,48 @@ get_trie_depth(const struct trie_node *node)
} }
static void static void
print_prefixes_helper(const struct trie_node *node, ip4_addr prefix, int depth) print_prefixes_helper(const struct trie_node *node, struct net_addr_ip4 address, int depth)
{ {
assert(node != NULL); assert(node != NULL);
if (is_leaf(node)) if (is_leaf(node))
{ {
log("%I4", prefix); log("%I4/%d\t-> %p", address.prefix, address.pxlen, node->bucket);
return; return;
} }
if (node->bucket != NULL)
log("%I4/%d\t-> %p", address.prefix, address.pxlen, node->bucket);
if (node->child[0]) if (node->child[0])
print_prefixes_helper(node->child[0], _MI4(_I(prefix) | (0 << (31 - depth))), depth + 1); {
//print_prefixes_helper(node->child[0], _MI4(_I(prefix) | (0 << (31 - depth))), depth + 1);
struct net_addr_ip4 new = {
.prefix = (_I(address.prefix) | (0 << (31 - depth))),
.pxlen = address.pxlen + 1,
};
print_prefixes_helper(node->child[0], new, depth + 1);
}
if (node->child[1]) if (node->child[1])
print_prefixes_helper(node->child[1], _MI4(_I(prefix) | (1 << (31 - depth))), depth + 1); {
//print_prefixes_helper(node->child[1], _MI4(_I(prefix) | (1 << (31 - depth))), depth + 1);
struct net_addr_ip4 new = {
.prefix = (_I(address.prefix) | (1 << (31 - depth))),
.pxlen = address.pxlen + 1,
};
print_prefixes_helper(node->child[1], new, depth + 1);
}
} }
static void static void
print_prefixes(const struct trie_node *node) print_prefixes(const struct trie_node *node)
{ {
print_prefixes_helper(node, _MI4(0), 0); //print_prefixes_helper(node, _MI4(0), 0);
struct net_addr_ip4 addr = { 0 };
print_prefixes_helper(node, addr, 0);
log("==== END PREFIXES ===="); log("==== END PREFIXES ====");
} }
@ -1109,6 +1130,8 @@ aggregator_rt_notify(struct proto *P, struct channel *src_ch, net *net, rte *new
{ {
union net_addr_union *uptr = (net_addr_union *)rte->net->n.addr; union net_addr_union *uptr = (net_addr_union *)rte->net->n.addr;
trie_insert_prefix(uptr, p->root, bucket, p->trie_slab); trie_insert_prefix(uptr, p->root, bucket, p->trie_slab);
const struct net_addr_ip4 * const ip4 = &uptr->ip4;
log("insert %I4/%d", ip4->prefix.addr, ip4->pxlen);
} }
} }
HASH_WALK_END; HASH_WALK_END;