From 89c55c241e15d6cc6cd45975ea6abe9290fdafe9 Mon Sep 17 00:00:00 2001 From: Igor Putovny Date: Tue, 5 Mar 2024 10:47:30 +0100 Subject: [PATCH] Use idiomatic functions for manipulating net_addr, remove unnecessary use of alloca --- proto/aggregator/aggregator.c | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/proto/aggregator/aggregator.c b/proto/aggregator/aggregator.c index 313c2f2c..825253c7 100644 --- a/proto/aggregator/aggregator.c +++ b/proto/aggregator/aggregator.c @@ -678,13 +678,15 @@ print_prefixes(const struct trie_node *node, int type) { if (type == NET_IP4) { - struct net_addr_ip4 *addr = allocz(sizeof(struct net_addr_ip4)); - print_prefixes_ip4_helper(node, addr, 0); + struct net_addr_ip4 addr = { 0 }; + net_fill_ip4((net_addr *)&addr, IP4_NONE, 0); + print_prefixes_ip4_helper(node, &addr, 0); } else if (type == NET_IP6) { - struct net_addr_ip6 *addr = allocz(sizeof(struct net_addr_ip6)); - print_prefixes_ip6_helper(node, addr, 0); + struct net_addr_ip6 addr = { 0 }; + net_fill_ip6((net_addr *)&addr, IP6_NONE, 0); + print_prefixes_ip6_helper(node, &addr, 0); } } @@ -796,18 +798,18 @@ collect_prefixes(struct aggregator_proto *p) if (type == NET_IP4) { - struct net_addr_ip4 *addr = allocz(sizeof(struct net_addr_ip4)); - addr->type = NET_IP4; - addr->length = sizeof(struct net_addr_ip4); - collect_prefixes_helper_ip4(p->root, addr, p, 0, &count); + struct net_addr_ip4 addr = { 0 }; + net_fill_ip4((net_addr *)&addr, IP4_NONE, 0); + collect_prefixes_helper_ip4(p->root, &addr, p, 0, &count); } else if (type == NET_IP6) { - struct net_addr_ip6 *addr = allocz(sizeof(struct net_addr_ip6)); - addr->type = NET_IP6; - addr->length = sizeof(struct net_addr_ip6); - collect_prefixes_helper_ip6(p->root, addr, p, 0, &count); + struct net_addr_ip6 addr = { 0 }; + net_fill_ip6((net_addr *)&addr, IP6_NONE, 0); + collect_prefixes_helper_ip6(p->root, &addr, p, 0, &count); } + else + bug("Invalid NET type"); log("%d prefixes collected", count); } @@ -1504,7 +1506,7 @@ aggregator_start(struct proto *P) }; struct network *default_net = mb_alloc(P->pool, sizeof(struct network) + sizeof(struct net_addr_ip4)); - net_fill_ip4(default_net->n.addr, (struct ip4_addr) { 0 }, 0); + net_fill_ip4(default_net->n.addr, IP4_NONE, 0); log("Creating net %p for default route", default_net); /* Create route attributes with zero nexthop */