]> git.ipfire.org Git - thirdparty/bird.git/commitdiff
Use idiomatic functions for manipulating net_addr, remove unnecessary use of alloca
authorIgor Putovny <igor.putovny@nic.cz>
Tue, 5 Mar 2024 09:47:30 +0000 (10:47 +0100)
committerIgor Putovny <igor.putovny@nic.cz>
Thu, 30 May 2024 10:30:00 +0000 (12:30 +0200)
proto/aggregator/aggregator.c

index 313c2f2c270460a091f40d1e153526b885e5e35d..825253c77089278f905267fd1e74daf7b66d3baf 100644 (file)
@@ -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 */