[virt-tools-list] random MAC generation and top bit?

John Levon levon at movementarian.org
Mon Nov 30 16:48:19 UTC 2009


On Mon, Nov 30, 2009 at 03:27:28PM +0000, Daniel P. Berrange wrote:

> On Mon, Nov 30, 2009 at 10:24:50AM -0500, John Levon wrote:
> > 
> >     mac = oui + [
> >             random.randint(0x00, 0x7f),
> >             random.randint(0x00, 0xff),
> >             random.randint(0x00, 0xff) ]
> >     return ':'.join(map(lambda x: "%02x" % x, mac))
> > 
> > Why the 0x7f?
> 
> Looks like a typo to me - there's no reason to restrict the first
> byte in this way

I thought so too. Looks like this code came from xend, and I dug
some into the history (don't know why I didn't do this before):

+        # NB2. The first bit of the first random octet is set to zero for
+        # all dynamic MAC addresses. This may allow us to manually specify
+        # MAC addresses for some VIFs with no fear of clashes.

Someone decided this comment wasn't useful back in 2004. Sigh.

regards
john




More information about the virt-tools-list mailing list