diff --git a/share/man/man9/ether_gen_addr.9 b/share/man/man9/ether_gen_addr.9 --- a/share/man/man9/ether_gen_addr.9 +++ b/share/man/man9/ether_gen_addr.9 @@ -61,8 +61,9 @@ .Xr loader 8 . .Pp .Nm -can fail to derive a MAC address due to memory allocation failure. -In this case, a locally-administered unicast MAC address will be randomly +can fail to derive a MAC address due to memory allocation failure, or because +the hostid has not been populated. +In these cases, a locally-administered unicast MAC address will be randomly generated and returned via the .Ar hwaddr parameter. diff --git a/sys/kern/kern_jail.c b/sys/kern/kern_jail.c --- a/sys/kern/kern_jail.c +++ b/sys/kern/kern_jail.c @@ -76,7 +76,6 @@ #include -#define DEFAULT_HOSTUUID "00000000-0000-0000-0000-000000000000" #define PRISON0_HOSTUUID_MODULE "hostuuid" MALLOC_DEFINE(M_PRISON, "prison", "Prison structures"); diff --git a/sys/net/if_ethersubr.c b/sys/net/if_ethersubr.c --- a/sys/net/if_ethersubr.c +++ b/sys/net/if_ethersubr.c @@ -1443,6 +1443,11 @@ char jailname[MAXHOSTNAMELEN]; getcredhostuuid(curthread->td_ucred, uuid, sizeof(uuid)); + if (strncmp(uuid, DEFAULT_HOSTUUID, sizeof(uuid)) == 0) { + /* Fall back to a random mac address. */ + goto rando; + } + /* If each (vnet) jail would also have a unique hostuuid this would not * be necessary. */ getjailname(curthread->td_ucred, jailname, sizeof(jailname)); @@ -1450,9 +1455,7 @@ jailname); if (sz < 0) { /* Fall back to a random mac address. */ - arc4rand(hwaddr, sizeof(*hwaddr), 0); - hwaddr->octet[0] = 0x02; - return; + goto rando; } SHA1Init(&ctx); @@ -1467,6 +1470,14 @@ hwaddr->octet[i] = addr >> ((ETHER_ADDR_LEN - i - 1) * 8) & 0xFF; } + + return; +rando: + arc4rand(hwaddr, sizeof(*hwaddr), 0); + /* Unicast */ + hwaddr->octet[0] &= 0xFE; + /* Locally administered. */ + hwaddr->octet[0] |= 0x02; } DECLARE_MODULE(ether, ether_mod, SI_SUB_INIT_IF, SI_ORDER_ANY); diff --git a/sys/sys/jail.h b/sys/sys/jail.h --- a/sys/sys/jail.h +++ b/sys/sys/jail.h @@ -140,6 +140,7 @@ #include #define HOSTUUIDLEN 64 +#define DEFAULT_HOSTUUID "00000000-0000-0000-0000-000000000000" #define OSRELEASELEN 32 struct racct;