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...
#include <sys/socket.h>
#include <sys/capability.h>
#include <sys/syscall.h>
+#include <sys/random.h>
#include "micoforia.lsg.h"
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;
}
}
}
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()))