]> git.tuebingen.mpg.de Git - micoforia.git/commitdiff
Use random mac addresses by default. master pu v1.0.1
authorAndre Noll <maan@tuebingen.mpg.de>
Thu, 20 Mar 2025 13:24:55 +0000 (14:24 +0100)
committerAndre Noll <maan@tuebingen.mpg.de>
Sat, 23 Aug 2025 14:54:25 +0000 (16:54 +0200)
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...

micoforia.c
util.c

index d47694ebc7bc520181b55785ea129928ae293473..6af23a53c5ffd9d3ed0f24bb775d406fde6f2b78 100644 (file)
@@ -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,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 f4f941e94683b6810b7b9bbe59c57de32abd4145..80ed7bd4f6a1fc45cd6291d09e7bf2a6e1b65c31 100644 (file)
--- 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()))