Skip to content
  • David Johnson's avatar
    Add build_fake_macs and use it in getifconfig. · fe6c2807
    David Johnson authored
    build_fake_macs generates fake mac addresses for the inside and outside
    halves of a veth.  For openvz vnodes, we have to uniquely address
    both halves.  tmcd gives us the vmac for the inside of the container;
    it is basically 00:00:ipOct0:ipOct1:ipOct2:ip0ct3.  Normally, for openvz
    veths, this works fine, because only the inside of the container ever sees
    the vmac.  BUT, if we're not using openvz veths (i.e., using macvlan devices),
    we might not have inside/outside halves of the veth.  Consequently, we
    have to give the device a unique mac addr that is unique in both the
    root and container contexts.  This is trivial for non-shared vhosts, but
    if the vhost is shared, we can't just use the vmac as specified above.  So,
    we do the following:
    
        # We have to set the locally administered bit (0x02) in the first
        # octet, and we can't set the unicast/multicast bit (0x01).  So
        # we have the first two octets to play with, minus those two bits,
        # leaving us with 14 total bits.  But then, for veths, we need a
        # a MAC for the root context, and for the container.  So there goes
        # another bit.
        #
        # So, what we're going to do is, if the vmid fits in 13 bits,
        # take the 5 MSB and shift them into bits 3-7 of the first octet,
        # and take the 8 LSB and make them the second octet.  Then, we
        # always set bit 2, and the container MAC gets bit 8 set.
    
    Of course, this requires getifconfig to check for these "hacked" vmacs
    when ifsetup configures interfaces inside the container -- so now
    getifconfig checks for these special hacked vmacs if it can't find
    a device with the vmac itself.  Good times...
    fe6c2807