diff --git a/sys/dev/virtual/vkernel/net/if_vke.c b/sys/dev/virtual/vkernel/net/if_vke.c index 66ae46e..b2036cf 100644 --- a/sys/dev/virtual/vkernel/net/if_vke.c +++ b/sys/dev/virtual/vkernel/net/if_vke.c @@ -700,16 +700,22 @@ vke_attach(const struct vknetif_info *info, int unit) return ENXIO; } } else { - int fd = open("/dev/urandom", O_RDONLY); - if (fd >= 0) { - read(fd, enaddr + 2, 4); - close(fd); + /* + * Convert our MAC string to its hw address representation + * and fall back to pseudo-random MAC generation in the case + * the conversion goes wrong. + */ + if (kether_aton(info->ethstr, enaddr) == NULL) { + int fd = open("/dev/urandom", O_RDONLY); + if (fd >= 0) { + read(fd, enaddr + 2, 4); + close(fd); + } + enaddr[4] = (int)getpid() >> 8; + enaddr[5] = (int)getpid() & 255; + enaddr[1] += 1; } - enaddr[4] = (int)getpid() >> 8; - enaddr[5] = (int)getpid() & 255; - } - enaddr[1] += 1; sc = kmalloc(sizeof(*sc), M_DEVBUF, M_WAITOK | M_ZERO); diff --git a/sys/platform/vkernel64/include/md_var.h b/sys/platform/vkernel64/include/md_var.h index 286b2fb..62c4e1c 100644 --- a/sys/platform/vkernel64/include/md_var.h +++ b/sys/platform/vkernel64/include/md_var.h @@ -40,6 +40,11 @@ #ifndef _SYS_TYPES_H_ #include #endif + +#ifndef _NET_ETHERNET_H_ +#include +#endif + #ifndef _SYS_VKERNEL_H_ #include #endif @@ -52,6 +57,7 @@ struct vknetif_info { int tap_unit; in_addr_t netif_addr; in_addr_t netif_mask; + char ethstr[ETHER_ADDRSTRLEN + 1]; }; struct vkdisk_info { diff --git a/sys/platform/vkernel64/platform/init.c b/sys/platform/vkernel64/platform/init.c index 2b0ca2d..2f30145 100644 --- a/sys/platform/vkernel64/platform/init.c +++ b/sys/platform/vkernel64/platform/init.c @@ -1178,6 +1178,7 @@ void init_netif(char *netifExp[], int netifExpNum) { int i, s; + char *tmp; if (netifExpNum == 0) return; @@ -1192,6 +1193,10 @@ init_netif(char *netifExp[], int netifExpNum) int tap_fd, tap_unit; char *netif; + /* Extract MAC address if there is one */ + tmp = netifExp[i]; + strsep(&tmp, "="); + netif = strtok(netifExp[i], ":"); if (netif == NULL) { warnx("Invalid argument to '-I'"); @@ -1227,6 +1232,11 @@ init_netif(char *netifExp[], int netifExpNum) info->tap_unit = tap_unit; info->netif_addr = netif_addr; info->netif_mask = netif_mask; + /* + * Set our MAC in the case it was correctly passed. + */ + if (tmp != NULL) + strlcpy(info->ethstr, tmp, ETHER_ADDRSTRLEN + 1); NetifNum++; if (NetifNum >= VKNETIF_MAX) /* XXX will this happen? */