From nobody Sun Apr 28 09:19:03 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 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1518811505611521.3246916802682; Fri, 16 Feb 2018 12:05:05 -0800 (PST) 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 B7DA45B300; Fri, 16 Feb 2018 20:05:02 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E31FC60BEB; Fri, 16 Feb 2018 20:05:01 +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 9C79718033E8; Fri, 16 Feb 2018 20:04:59 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w1GK4vCQ007877 for ; Fri, 16 Feb 2018 15:04:57 -0500 Received: by smtp.corp.redhat.com (Postfix) id 528E6AF019; Fri, 16 Feb 2018 20:04:57 +0000 (UTC) Received: from vhost2.laine.org (ovpn-117-234.phx2.redhat.com [10.3.117.234]) by smtp.corp.redhat.com (Postfix) with ESMTP id B5151AF009; Fri, 16 Feb 2018 20:04:54 +0000 (UTC) From: Laine Stump To: libvir-list@redhat.com Date: Fri, 16 Feb 2018 15:04:46 -0500 Message-Id: <20180216200446.16133-1-laine@laine.org> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-loop: libvir-list@redhat.com Cc: Michal Privoznik Subject: [libvirt] [PATCH] conf: move 'generated' member from virMacAddr to virDomainNetDef 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: , MIME-Version: 1.0 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.26]); Fri, 16 Feb 2018 20:05:04 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Commit 7e62c4cd26d (first appearing in libvirt-3.9.0 as a resolution to rhbz #1343919) added a "generated" attribute to virMacAddr that was set whenever a mac address was auto-generated by libvirt. This knowledge was used in a single place - when trying to match a NetDef from the domain to delete with user-provided XML. Since the XML parser always auto-generates a MAC address for NetDefs when none is provided, it was previously impossible to make a search where the MAC address wasn't significant, but the addition of the "generated" attribute made it possible for the search function to ignore auto-generated MACs. This implementation had a problem though - it was adding a field to a "low level" struct - virMacAddr - which is used in other places with the assumption that it contains exactly a 6 byte MAC address and nothing else. In particular, virNWFilterSnoopEthHdr uses virMacAddr as part of the definition of an ethernet packet header, whose layout must of course match an actual ethernet packet. Adding the extra bools into virNWFilterSnoopEthHdr caused the nwfilter driver's "IP discovery via DHCP packet snooping" functionality to mysteriously stop working. In order to fix that behavior, and prevent potential future similar odd behavior, this patch moves the "generated" member out of virMacAddr (so that it is again really just a MAC address) and into virDomainNetDef, and sets it only when virDomainNetGenerateMAC() is called from virDomainNetDefParseXML() (which is the only time we care about it). Resolves: https://bugzilla.redhat.com/1529338 (It should also be applied to any maintenance branch that applies commit 7e62c4cd26 and friends to resolve https://bugzilla.redhat.com/1343919) Signed-off-by: Laine Stump --- src/conf/domain_conf.c | 3 ++- src/conf/domain_conf.h | 1 + src/util/virmacaddr.c | 5 ----- src/util/virmacaddr.h | 2 -- tests/bhyveargv2xmlmock.c | 1 - 5 files changed, 3 insertions(+), 9 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 3cfd6de5e0..7783a3dbef 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -11064,6 +11064,7 @@ virDomainNetDefParseXML(virDomainXMLOptionPtr xmlop= t, } } else { virDomainNetGenerateMAC(xmlopt, &def->mac); + def->mac_generated =3D true; } =20 if (devaddr) { @@ -16283,7 +16284,7 @@ virDomainNetFindIdx(virDomainDefPtr def, virDomainN= etDefPtr net) size_t i; int matchidx =3D -1; char mac[VIR_MAC_STRING_BUFLEN]; - bool MACAddrSpecified =3D !net->mac.generated; + bool MACAddrSpecified =3D !net->mac_generated; bool PCIAddrSpecified =3D virDomainDeviceAddressIsValid(&net->info, VIR_DOMAIN_DEVIC= E_ADDRESS_TYPE_PCI); =20 diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index e6212818aa..b0a175b4a4 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -966,6 +966,7 @@ struct _virDomainActualNetDef { struct _virDomainNetDef { virDomainNetType type; virMacAddr mac; + bool mac_generated; /* true if mac was *just now* auto-generated by li= bvirt */ char *model; union { struct { diff --git a/src/util/virmacaddr.c b/src/util/virmacaddr.c index 409fdc34d5..7afe032b9c 100644 --- a/src/util/virmacaddr.c +++ b/src/util/virmacaddr.c @@ -107,7 +107,6 @@ void virMacAddrSet(virMacAddrPtr dst, const virMacAddr *src) { memcpy(dst, src, sizeof(*src)); - dst->generated =3D false; } =20 /** @@ -121,7 +120,6 @@ void virMacAddrSetRaw(virMacAddrPtr dst, const unsigned char src[VIR_MAC_BUFLEN= ]) { memcpy(dst->addr, src, VIR_MAC_BUFLEN); - dst->generated =3D false; } =20 /** @@ -151,7 +149,6 @@ virMacAddrParse(const char* str, virMacAddrPtr addr) { size_t i; =20 - addr->generated =3D false; errno =3D 0; for (i =3D 0; i < VIR_MAC_BUFLEN; i++) { char *end_ptr; @@ -220,7 +217,6 @@ virMacAddrParseHex(const char *str, virMacAddrPtr addr) str[VIR_MAC_HEXLEN]) return -1; =20 - addr->generated =3D false; for (i =3D 0; i < VIR_MAC_BUFLEN; i++) addr->addr[i] =3D (virHexToBin(str[2 * i]) << 4 | virHexToBin(str[2 * i + 1])); @@ -236,7 +232,6 @@ void virMacAddrGenerate(const unsigned char prefix[VIR_= MAC_PREFIX_BUFLEN], addr->addr[3] =3D virRandomBits(8); addr->addr[4] =3D virRandomBits(8); addr->addr[5] =3D virRandomBits(8); - addr->generated =3D true; } =20 /* The low order bit of the first byte is the "multicast" bit. */ diff --git a/src/util/virmacaddr.h b/src/util/virmacaddr.h index ef4285d639..f4f5e2ce11 100644 --- a/src/util/virmacaddr.h +++ b/src/util/virmacaddr.h @@ -36,8 +36,6 @@ typedef virMacAddr *virMacAddrPtr; =20 struct _virMacAddr { unsigned char addr[VIR_MAC_BUFLEN]; - bool generated; /* True if MAC address was autogenerated, - false otherwise. */ }; =20 int virMacAddrCompare(const char *mac1, const char *mac2); diff --git a/tests/bhyveargv2xmlmock.c b/tests/bhyveargv2xmlmock.c index dd25f4e13a..1f08bebb7b 100644 --- a/tests/bhyveargv2xmlmock.c +++ b/tests/bhyveargv2xmlmock.c @@ -16,7 +16,6 @@ virMacAddrGenerate(const unsigned char prefix[VIR_MAC_PRE= FIX_BUFLEN], addr->addr[3] =3D 0; addr->addr[4] =3D 0; addr->addr[5] =3D 0; - addr->generated =3D true; } =20 int --=20 2.14.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list