From fadf3c96c515e8002a6f0dd1b0c1c348560bcd33 Mon Sep 17 00:00:00 2001
From: Andre Noll <maan@tuebingen.mpg.de>
Date: Thu, 20 Mar 2025 14:24:55 +0100
Subject: [PATCH] Use random mac addresses by default.

---
 micoforia.c | 5 +++--
 util.c      | 3 ---
 2 files changed, 3 insertions(+), 5 deletions(-)

diff --git a/micoforia.c b/micoforia.c
index 9afd269..1b03f92 100644
--- a/micoforia.c
+++ b/micoforia.c
@@ -13,6 +13,7 @@
 #include <sys/socket.h>
 #include <sys/capability.h>
 #include <sys/syscall.h>
+#include <sys/random.h>
 
 #include "micoforia.lsg.h"
 
@@ -368,8 +369,8 @@ static void check_options(void)
 			c->num_ifspecs = 1;
 			c->ifspec = xmalloc(sizeof(struct ifspec));
 			c->ifspec[0].bridge = xstrdup(br);
-			memset(c->ifspec[0].hwaddr, 0, 6);
-			continue;
+			if (getrandom(c->ifspec[0].hwaddr, 6, 0) < 0)
+				WARNING_LOG("%s: getrandom error: %m\n", c->name);
 		}
 	}
 }
diff --git a/util.c b/util.c
index 08f4832..8ef6181 100644
--- a/util.c
+++ b/util.c
@@ -646,11 +646,8 @@ bool set_hwaddr(const char *iface, const uint8_t *hwaddr)
 	struct nlmsghdr *nlh;
 	struct ifinfomsg *ifm;
 	bool success;
-	const uint8_t zero[6] = {0};
 	char pretty_hwaddr[18];
 
-	if (!memcmp(hwaddr, zero, 6))
-		return true; /* no hwaddr specified, nothing to do */
 	pretty_print_hwaddr(hwaddr, pretty_hwaddr);
 	INFO_LOG("hardware address of %s: %s\n", iface, pretty_hwaddr);
 	if (!(nl = get_and_bind_netlink_socket()))
-- 
2.39.5