From owner-freebsd-virtualization@FreeBSD.ORG Wed Feb 5 17:46:20 2014 Return-Path: Delivered-To: freebsd-virtualization@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 3BE52610 for ; Wed, 5 Feb 2014 17:46:20 +0000 (UTC) Received: from hydra.pix.net (hydra.pix.net [IPv6:2001:470:e254::4]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id EFCDB1502 for ; Wed, 5 Feb 2014 17:46:19 +0000 (UTC) Received: from torb.pix.net (torb.pix.net [IPv6:2001:470:e254:10:12dd:b1ff:febf:eca9]) (authenticated bits=0) by hydra.pix.net (8.14.5/8.14.5) with ESMTP id s15HkIrJ094456; Wed, 5 Feb 2014 12:46:18 -0500 (EST) (envelope-from lidl@pix.net) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.98 at mail.pix.net Message-ID: <52F278EA.3020509@pix.net> Date: Wed, 05 Feb 2014 12:46:18 -0500 From: Kurt Lidl User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:24.0) Gecko/20100101 Thunderbird/24.3.0 MIME-Version: 1.0 To: freebsd-virtualization@freebsd.org Subject: Re: MAC addresses to use for BHyve VM's running under FreeBSD? References: <9BF7840E-03C2-47E4-A863-DE07FB1256F1@freebsd.org> In-Reply-To: <9BF7840E-03C2-47E4-A863-DE07FB1256F1@freebsd.org> Content-Type: multipart/mixed; boundary="------------050005050101010709030301" X-BeenThere: freebsd-virtualization@freebsd.org X-Mailman-Version: 2.1.17 Precedence: list List-Id: "Discussion of various virtualization techniques FreeBSD supports." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 05 Feb 2014 17:46:20 -0000 This is a multi-part message in MIME format. --------------050005050101010709030301 Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 8bit > On Feb 5, 2014, at 3:33 , Kai Gallasch wrote: > >> Am 05.02.2014 um 08:03 schrieb Craig Rodrigues: >>> Hi, >>> >>> I am running many BHyve VM's and am using tap interfaces >>> with a single bridge. I am configuring the IP addresses >>> of these VM's via DHCP. >>> >>> I need to have separate MAC addresses for each VM. >>> >>> Can anyone recommend a range of MAC addresses to use? >>> >>> I seem to recall that at the 2013 FreeBSD Vendor Summit in >>> Sunnyvale, California, that George mentioned that >>> there might be a Organizational Unique Identifier (OUI) for the FreeBSD >>> project that we can use for BHyve VM's. Is that right? >>> >>> If not, can people recommend a range of addresses to use? >> >> http://standards.ieee.org/develop/regauth/oui/public.html >> >> Using "Search the Public MA-L Listing" with search term FreeBSD reveals.. >> >> --- snip --- >> >> Here are the results of your search through the public section of the IEEE Standards OUI database report for freebsd: >> >> 58-9C-FC (hex) FreeBSD >> Foundation >> 589CFC (base 16) >> FreeBSD >> Foundation >> P.O. Box 20247 >> Boulder CO 80308-3247 >> UNITED STATES >> --- snap --- >> >> > > Correct, that is an address that the Foundation has registered with the IEEE. > > If you look at sys/net/ieee_oui.h you will see that I’ve allocated a range to bhyve already. At work, we modified the bhyverun command to seed the hostname of them machine running the hypervisor as part of the "generate a MAC address" routine. That means that for virtual machine "foo", you now get different MACs on server "bar" and server "baz". Without this patch, you're likely to get identical MAC addresses for virtual machine "foo" on different servers. I personally also have my virtual machines set bit 2 in the first octet of the MAC address, so it falls into the "locally administered" catagory of MAC addresses. My gut feel is that using the FreeBSD OUI bhyve range, *AND* setting the locally administered bit in the MAC address is the way to go. -Kurt --------------050005050101010709030301 Content-Type: text/plain; charset=UTF-8; x-mac-type="0"; x-mac-creator="0"; name="pci_virtio_net.diff" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="pci_virtio_net.diff" diff --git a/usr.sbin/bhyve/pci_virtio_net.c b/usr.sbin/bhyve/pci_virtio_net.c --- a/usr.sbin/bhyve/pci_virtio_net.c +++ b/usr.sbin/bhyve/pci_virtio_net.c @@ -579,27 +579,36 @@ pci_vtnet_init(struct vmctx *ctx, struct close(sc->vsc_tapfd); sc->vsc_tapfd = -1; } } } /* * The default MAC address is the standard NetApp OUI of 00-a0-98, - * followed by an MD5 of the PCI slot/func number and dev name + * followed by an MD5 of the PCI slot/func number, hostname, and + * vmname. The "locally administered" bit is also set in the + * resulting MAC address. */ if (!mac_provided) { - snprintf(nstr, sizeof(nstr), "%d-%d-%s", pi->pi_slot, - pi->pi_func, vmname); + char hostname[MAXHOSTNAMELEN]; + int rc; + + rc = gethostname(hostname, sizeof hostname - 1); + if (rc < 0) + hostname[0] = 0; + hostname[MAXHOSTNAMELEN-1] = 0; + snprintf(nstr, sizeof(nstr), "%d-%d-%s-%s", pi->pi_slot, + pi->pi_func, hostname, vmname); MD5Init(&mdctx); MD5Update(&mdctx, nstr, strlen(nstr)); MD5Final(digest, &mdctx); - sc->vsc_config.mac[0] = 0x00; + sc->vsc_config.mac[0] = 0x00 | 0x2; /* locally administered */ sc->vsc_config.mac[1] = 0xa0; sc->vsc_config.mac[2] = 0x98; sc->vsc_config.mac[3] = digest[0]; sc->vsc_config.mac[4] = digest[1]; sc->vsc_config.mac[5] = digest[2]; } /* initialize config space */ --------------050005050101010709030301--