How does the libvirt deal with the vnet mac address?

Greetings,
if I establish a network for the VM (hypervisor is KVM) using bridge in the 
virt-manager , a vnet0 device is created . There are some relationships about 
mac address between the vnet0 device in the hypervisor and the ethX device in 
the VM, for example :
the mac address of vnet0 is FE:54:00:84:E3:62
the mac address of ethX in the VM is 52:54:00:84:E3:62
two mac addresses above are almost the same except the first part of the 
address .
but if I created a tap device manually , 
tunctl -t tap0 -u root
brctl addif br0 tap0
and add tap0 to the VM, I will find that mac address between the tap0 device in 
the hypervisor and the ethX device in the VM will totally different . so I 
think that libvirt must do something about the mac address handling, could you 
please kindly tell me something about this ?
 
I have found a function in libvirt-0.10.2.8\src\util\ virnetdevtap.c
int virNetDevTapCreateInBridgePort(const char *brname,
                                   char **ifname,
                                   const virMacAddrPtr macaddr,
                                   const unsigned char *vmuuid,
                                   int *tapfd,
                                   virNetDevVPortProfilePtr virtPortProfile,
                                   virNetDevVlanPtr virtVlan,
                                   unsigned int flags)
{
    ….
    virMacAddr tapmac;
    if (virNetDevTapCreate(ifname, tapfd, flags) < 0)
        return -1;
 
    /* We need to set the interface MAC before adding it
     * to the bridge, because the bridge assumes the lowest
     * MAC of all enslaved interfaces & we don't want it
     * seeing the kernel allocate random MAC for the TAP
     * device before we set our static MAC.
     */
    virMacAddrSet(&tapmac, macaddr);
    if (!(flags & VIR_NETDEV_TAP_CREATE_USE_MAC_FOR_BRIDGE)) {
        if (macaddr->addr[0] == 0xFE) {
            /* For normal use, the tap device's MAC address cannot
             * match the MAC address used by the guest. This results
             * in "received packet on vnetX with own address as source
             * address" error logs from the kernel.
             */
            virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
                           _("Unable to use MAC address starting with "
                             "reserved value 0xFE - 
'%02X:%02X:%02X:%02X:%02X:%02X' - "),
                           macaddr->addr[0], macaddr->addr[1],
                           macaddr->addr[2], macaddr->addr[3],
                           macaddr->addr[4], macaddr->addr[5]);
            goto error;
        }
        tapmac.addr[0] = 0xFE; /* Discourage bridge from using TAP dev MAC */ 
//the first part of mac address is set to 0xFE.
    }
    if (virNetDevSetMAC(*ifname, &tapmac) < 0)
        goto error;
    ….
}
 
How does the libvirt establish the arp table in the hypervisor if the vnet0 
device in the hypervisor and the ethX device in the VM is different?
 
If I want to create tap device manually , how should I deal with the mac 
address ?I have setup the mac address of the tap0 device in the hypervisor and 
the ethX device in the VM in the same way with libvirt , but the network of VM 
cannot work.
 
weihua 
 
w...@foxmail.com



w...@foxmail.com
_______________________________________________
libvirt-users mailing list
libvirt-users@redhat.com
https://www.redhat.com/mailman/listinfo/libvirt-users

Reply via email to