From: Andre Noll Date: Thu, 20 Mar 2025 13:24:55 +0000 (+0100) Subject: Use random mac addresses by default. X-Git-Tag: v1.0.1^0 X-Git-Url: https://git.tuebingen.mpg.de/?a=commitdiff_plain;p=micoforia.git Use random mac addresses by default. Currently we use the all-zeros MAC address to instruct linux to pick one by random. Unfortunately, this does not always work, presumably because the first byte of the address can be an odd number. It's easy enough to do create a random MAC address by hand, so... --- diff --git a/micoforia.c b/micoforia.c index d47694e..6af23a5 100644 --- a/micoforia.c +++ b/micoforia.c @@ -13,6 +13,7 @@ #include #include #include +#include #include "micoforia.lsg.h" @@ -368,8 +369,9 @@ 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); + c->ifspec[0].hwaddr[0] &= 0xfe; } } } diff --git a/util.c b/util.c index f4f941e..80ed7bd 100644 --- a/util.c +++ b/util.c @@ -635,11 +635,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()))