From nobody Thu Apr 25 21:50:33 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1565557194; cv=none; d=zoho.com; s=zohoarc; b=PgUaJUqYcLW6JkkzldbMks1IwW2ULgZqTKGKoMLb61Gz9NuG76Bnp0z50+GuX0+xK/hpSf37SRDOpe0iEbqkAJOecpzi/VhNayR7FA1p6/AvUwhReHPtdChfymOjxp7cu5RptTlyAWROUrAWdgJlEVzg9Wg9E6dJCLt43To1wCA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565557194; h=Content-Type:Content-Transfer-Encoding:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To:ARC-Authentication-Results; bh=Mf3ns7EhQlOXHKW7fEO0JXnMigz4CvKbVoV9aj4xWRY=; b=j5zeH8XCenNcuYO0nnTLl/igCSEmtyJodNrUjSdqaqouVS1fW436rm6MPtfUOUJT/RymojxlpUaxqaD+Mdpt5hMUucL35jtZbdtEnu2LZ5DcsPOBtXhA+mfjqjK6Hh3UT1dp1BpJiVoewWkaoU/koRilHjJEbVnjNJni9fcwLqU= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1565557194103603.4724204561704; Sun, 11 Aug 2019 13:59:54 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B4A75301A893; Sun, 11 Aug 2019 20:59:50 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 91D0E7CD73; Sun, 11 Aug 2019 20:59:48 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id AB8F11C8A; Sun, 11 Aug 2019 20:59:43 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x7BKxeiT024216 for ; Sun, 11 Aug 2019 16:59:40 -0400 Received: by smtp.corp.redhat.com (Postfix) id 18F2C5C3F8; Sun, 11 Aug 2019 20:59:40 +0000 (UTC) Received: from vhost2.laine.org (ovpn-116-52.phx2.redhat.com [10.3.116.52]) by smtp.corp.redhat.com (Postfix) with ESMTP id CB43671932 for ; Sun, 11 Aug 2019 20:59:35 +0000 (UTC) From: Laine Stump To: libvir-list@redhat.com Date: Sun, 11 Aug 2019 16:59:33 -0400 Message-Id: <20190811205933.29736-1-laine@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH] util: allow tap-based guest interfaces to have MAC address prefix 0xFE X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.45]); Sun, 11 Aug 2019 20:59:52 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Back in July 2010, commit 6ea90b84 (meant to resolve https://bugzilla.redhat.com/571991 ) added code to set the MAC address of any tap device to the associated guest interface's MAC, but with the first byte replaced with 0xFE. This was done in order to assure that 1) the tap MAC and guest interface MAC were different (otherwise L2 forwarding through the tap would not work, and the kernel would repeatedly issue a warning stating as much). 2) any bridge device that had one of these taps attached would *not* take on the MAC of the tap (leading to network instability as guests started and stopped) A couple years later, https://bugzilla.redhat.com/798467 was filed, complaining that a user could configure a tap-based guest interface to have a MAC address that itself had a first byte of 0xFE, silently (other than the kernel warning messages) resulting in a non-working configuration. This was fixed by commit 5d571045, which logged an error and failed the guest start / interface attach if the MAC's first byte was 0xFE. Although this restriction only reduces the potential pool of MAC addresses from 2^46 (last two bits of byte 1 must be set to 10) by 2^32 (still 4 orders of magnitude larger than the entire IPv4 address space), it also means that management software that autogenerates MAC addresses must have special code to avoid an 0xFE prefix. Now after 7 years, someone has noticed this restriction and requested that we remove it. So instead of failing when 0xFE is found as the first byte, this patch removes the restriction by just replacing the first byte in the tap device MAC with 0xFA if the first byte in the guest interface is 0xFE. 0xFA is the next-highest value that still has 10 as the lowest two bits, and still 2) meets the requirement of "tap MAC must be different from guest interface MAC", and 3) is high enough that there should never be an issue of the attached bridge device taking on the MAC of the tap. The result is that *any* MAC can be chosen by management software (although it would still not work correctly if a multicast MAC (lowest bit of first byte set to 1) was chosen), but that's a different issue). Signed-off-by: Laine Stump Reviewed-by: Michal Privoznik --- Yes, I find it slightly problematic that the same setting is in two different places in the code, but 1) that is pre-existing, and 2) if I moved the MAC address setting down one level into virNetDevTapCreate(), the code would *still* need to be duplicated, since there are two different implementations of virNetDevTapCreate(). If anyone is bothered by this, then I can resubmit with an extra patch to add a new virNetDevTapCreate() that just calls a platform-specific virNetDevTapCreateInternal(), then sets the tap mac address. Only by request though :-). src/qemu/qemu_interface.c | 11 ++++++++++- src/util/virnetdevtap.c | 26 ++++++++++++-------------- 2 files changed, 22 insertions(+), 15 deletions(-) diff --git a/src/qemu/qemu_interface.c b/src/qemu/qemu_interface.c index c8effa68f4..72ed51cb1f 100644 --- a/src/qemu/qemu_interface.c +++ b/src/qemu/qemu_interface.c @@ -444,8 +444,17 @@ qemuInterfaceEthernetConnect(virDomainDefPtr def, } =20 virDomainAuditNetDevice(def, net, tunpath, true); + + /* 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. + */ virMacAddrSet(&tapmac, &net->mac); - tapmac.addr[0] =3D 0xFE; + if (tapmac.addr[0] =3D=3D 0xFE) + tapmac.addr[0] =3D 0xFA; + else + tapmac.addr[0] =3D 0xFE; =20 if (virNetDevSetMAC(net->ifname, &tapmac) < 0) goto cleanup; diff --git a/src/util/virnetdevtap.c b/src/util/virnetdevtap.c index b65c26bee1..4548b51b5b 100644 --- a/src/util/virnetdevtap.c +++ b/src/util/virnetdevtap.c @@ -668,7 +668,6 @@ int virNetDevTapCreateInBridgePort(const char *brname, unsigned int flags) { virMacAddr tapmac; - char macaddrstr[VIR_MAC_STRING_BUFLEN]; size_t i; =20 if (virNetDevTapCreate(ifname, tunpath, tapfd, tapfdSize, flags) < 0) @@ -682,19 +681,18 @@ int virNetDevTapCreateInBridgePort(const char *brname, */ virMacAddrSet(&tapmac, macaddr); if (!(flags & VIR_NETDEV_TAP_CREATE_USE_MAC_FOR_BRIDGE)) { - if (macaddr->addr[0] =3D=3D 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 - '%s' - "), - virMacAddrFormat(macaddr, macaddrstr)); - goto error; - } - tapmac.addr[0] =3D 0xFE; /* Discourage bridge from using TAP dev M= AC */ + /* 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. Making the tap address as high as possible + * discourages the bridge from using this tap's MAC as its own + * (a Linux host bridge will take on the lowest numbered MAC + * of all devices attached to it). + */ + if (tapmac.addr[0] =3D=3D 0xFE) + tapmac.addr[0] =3D 0xFA; + else + tapmac.addr[0] =3D 0xFE; } =20 if (virNetDevSetMAC(*ifname, &tapmac) < 0) --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list