From nobody Wed May 1 01:42:06 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 1506943517690540.788113077092; Mon, 2 Oct 2017 04:25:17 -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 51E7C806A7; Mon, 2 Oct 2017 11:25:16 +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 1C0568E7B5; Mon, 2 Oct 2017 11:25:16 +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 A4A3E4EE4F; Mon, 2 Oct 2017 11:25:15 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v92B1UFc012879 for ; Mon, 2 Oct 2017 07:01:30 -0400 Received: by smtp.corp.redhat.com (Postfix) id 6A92F503B0; Mon, 2 Oct 2017 11:01:30 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.192]) by smtp.corp.redhat.com (Postfix) with ESMTP id E51108E7A2 for ; Mon, 2 Oct 2017 11:01:28 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 51E7C806A7 Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=libvir-list-bounces@redhat.com From: Michal Privoznik To: libvir-list@redhat.com Date: Mon, 2 Oct 2017 13:01:18 +0200 Message-Id: In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 1/3] qemuParseCommandLineNet: Make more readable 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]); Mon, 02 Oct 2017 11:25:16 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Michal Privoznik Reviewed-by: Erik Skultety --- src/qemu/qemu_parse_command.c | 32 ++++++++++++-------------------- 1 file changed, 12 insertions(+), 20 deletions(-) diff --git a/src/qemu/qemu_parse_command.c b/src/qemu/qemu_parse_command.c index c9112dd90..37e1149c0 100644 --- a/src/qemu/qemu_parse_command.c +++ b/src/qemu/qemu_parse_command.c @@ -1055,9 +1055,7 @@ qemuParseCommandLineNet(virDomainXMLOptionPtr xmlopt, if (virStrToLong_i(values[i], NULL, 10, &wantvlan) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("cannot parse vlan in '%s'"), val); - virDomainNetDefFree(def); - def =3D NULL; - goto cleanup; + goto error; } } else if (def->type =3D=3D VIR_DOMAIN_NET_TYPE_ETHERNET && STREQ(keywords[i], "script") && STRNEQ(values[i], "")) { @@ -1076,18 +1074,13 @@ qemuParseCommandLineNet(virDomainXMLOptionPtr xmlop= t, */ =20 nic =3D qemuFindNICForVLAN(nnics, nics, wantvlan); - if (!nic) { - virDomainNetDefFree(def); - def =3D NULL; - goto cleanup; - } + if (!nic) + goto error; =20 if (!STRPREFIX(nic, "nic")) { virReportError(VIR_ERR_INTERNAL_ERROR, _("cannot parse NIC definition '%s'"), nic); - virDomainNetDefFree(def); - def =3D NULL; - goto cleanup; + goto error; } =20 for (i =3D 0; i < nkeywords; i++) { @@ -1103,9 +1096,7 @@ qemuParseCommandLineNet(virDomainXMLOptionPtr xmlopt, &values, &nkeywords, 0) < 0) { - virDomainNetDefFree(def); - def =3D NULL; - goto cleanup; + goto error; } } else { nkeywords =3D 0; @@ -1118,9 +1109,7 @@ qemuParseCommandLineNet(virDomainXMLOptionPtr xmlopt, virReportError(VIR_ERR_INTERNAL_ERROR, _("unable to parse mac address '%s'"), values[i]); - virDomainNetDefFree(def); - def =3D NULL; - goto cleanup; + goto error; } } else if (STREQ(keywords[i], "model")) { def->model =3D values[i]; @@ -1135,9 +1124,7 @@ qemuParseCommandLineNet(virDomainXMLOptionPtr xmlopt, if (virStrToLong_ul(values[i], NULL, 10, &def->tune.sndbuf) < = 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("cannot parse sndbuf size in '%s'"), val); - virDomainNetDefFree(def); - def =3D NULL; - goto cleanup; + goto error; } def->tune.sndbuf_specified =3D true; } @@ -1154,6 +1141,11 @@ qemuParseCommandLineNet(virDomainXMLOptionPtr xmlopt, VIR_FREE(keywords); VIR_FREE(values); return def; + + error: + virDomainNetDefFree(def); + def =3D NULL; + goto cleanup; } =20 =20 --=20 2.13.5 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Wed May 1 01:42:06 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 150694353988846.641701119611184; Mon, 2 Oct 2017 04:25:39 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 60719C04AC66; Mon, 2 Oct 2017 11:25:38 +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 37A425EDE2; Mon, 2 Oct 2017 11:25:38 +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 D4BF018355C4; Mon, 2 Oct 2017 11:25:37 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v92B1VG6012885 for ; Mon, 2 Oct 2017 07:01:31 -0400 Received: by smtp.corp.redhat.com (Postfix) id 8D5768E7A2; Mon, 2 Oct 2017 11:01:31 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.192]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1523F8E7A4 for ; Mon, 2 Oct 2017 11:01:30 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 60719C04AC66 Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=libvir-list-bounces@redhat.com From: Michal Privoznik To: libvir-list@redhat.com Date: Mon, 2 Oct 2017 13:01:19 +0200 Message-Id: <44ddc80e05caca6a621e6866939cf75c2c90a213.1506941768.git.mprivozn@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 2/3] virmacaddr: Track if MAC address is autogenerated 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.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Mon, 02 Oct 2017 11:25:39 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" It will come handy to know if the MAC address was generated (e.g. during XML parse) or if it was parsed since provided by user in the XML. Signed-off-by: Michal Privoznik Reviewed-by: Erik Skultety --- src/util/virmacaddr.c | 5 +++++ src/util/virmacaddr.h | 2 ++ tests/bhyveargv2xmlmock.c | 1 + tests/bhyvexml2argvmock.c | 1 + 4 files changed, 9 insertions(+) diff --git a/src/util/virmacaddr.c b/src/util/virmacaddr.c index 7afe032b9..409fdc34d 100644 --- a/src/util/virmacaddr.c +++ b/src/util/virmacaddr.c @@ -107,6 +107,7 @@ void virMacAddrSet(virMacAddrPtr dst, const virMacAddr *src) { memcpy(dst, src, sizeof(*src)); + dst->generated =3D false; } =20 /** @@ -120,6 +121,7 @@ void virMacAddrSetRaw(virMacAddrPtr dst, const unsigned char src[VIR_MAC_BUFLEN= ]) { memcpy(dst->addr, src, VIR_MAC_BUFLEN); + dst->generated =3D false; } =20 /** @@ -149,6 +151,7 @@ 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; @@ -217,6 +220,7 @@ 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])); @@ -232,6 +236,7 @@ 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 f4f5e2ce1..ef4285d63 100644 --- a/src/util/virmacaddr.h +++ b/src/util/virmacaddr.h @@ -36,6 +36,8 @@ 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 1f08bebb7..dd25f4e13 100644 --- a/tests/bhyveargv2xmlmock.c +++ b/tests/bhyveargv2xmlmock.c @@ -16,6 +16,7 @@ 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 diff --git a/tests/bhyvexml2argvmock.c b/tests/bhyvexml2argvmock.c index 7afa0e34c..bec7f902a 100644 --- a/tests/bhyvexml2argvmock.c +++ b/tests/bhyvexml2argvmock.c @@ -17,6 +17,7 @@ void virMacAddrGenerate(const unsigned char prefix[VIR_MA= C_PREFIX_BUFLEN], addr->addr[3] =3D 0; addr->addr[4] =3D 0; addr->addr[5] =3D 0; + addr->generated =3D true; } =20 int virNetDevTapCreateInBridgePort(const char *brname ATTRIBUTE_UNUSED, --=20 2.13.5 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Wed May 1 01:42:06 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 1506943560651156.13495884896042; Mon, 2 Oct 2017 04:26:00 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8995280F7A; Mon, 2 Oct 2017 11:25:59 +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 6743490817; Mon, 2 Oct 2017 11:25:59 +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 0AADA18355C7; Mon, 2 Oct 2017 11:25:59 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v92B1WMb012895 for ; Mon, 2 Oct 2017 07:01:32 -0400 Received: by smtp.corp.redhat.com (Postfix) id 61043503B0; Mon, 2 Oct 2017 11:01:32 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.192]) by smtp.corp.redhat.com (Postfix) with ESMTP id DB2B58E7A2 for ; Mon, 2 Oct 2017 11:01:31 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 8995280F7A Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=libvir-list-bounces@redhat.com From: Michal Privoznik To: libvir-list@redhat.com Date: Mon, 2 Oct 2017 13:01:20 +0200 Message-Id: In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 3/3] virDomainNetFindIdx: Ignore auto generated MAC addresses 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.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Mon, 02 Oct 2017 11:26:00 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" When detaching an from domain, it's MAC address is parsed and if not present one is generated. If, however, no corresponding interface is found in the domain, the following error is reported: error: operation failed: no device matching mac address 52:54:00:75:32:5b f= ound where the MAC address is the auto generated one. This might be very confusing. Solution to this is to ignore auto generated MAC address when looking up the device. Signed-off-by: Michal Privoznik Reviewed-by: Erik Skultety to this patch. --- src/conf/domain_conf.c | 45 +++++++++++++++++++++++++++++++++++---------- 1 file changed, 35 insertions(+), 10 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 87192eb2d..aab43d307 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -15634,11 +15634,17 @@ int virDomainNetInsert(virDomainDefPtr def, virDo= mainNetDefPtr net) return 0; } =20 -/* virDomainNetFindIdx: search according to mac address and guest side - * PCI address (if specified) +/** + * virDomainNetFindIdx: + * @def: domain definition + * @net: interface definition * - * Return: index of match if unique match found - * -1 otherwise and an error is logged + * Lookup domain's network interface based on passed @net + * definition. If @net's MAC address was auto generated, + * the MAC comparison is ignored. + * + * Return: index of match if unique match found, + * -1 otherwise and an error is logged. */ int virDomainNetFindIdx(virDomainDefPtr def, virDomainNetDefPtr net) @@ -15646,11 +15652,13 @@ virDomainNetFindIdx(virDomainDefPtr def, virDomai= nNetDefPtr net) size_t i; int matchidx =3D -1; char mac[VIR_MAC_STRING_BUFLEN]; + bool MACAddrSpecified =3D !net->mac.generated; bool PCIAddrSpecified =3D virDomainDeviceAddressIsValid(&net->info, VIR_DOMAIN_DEVIC= E_ADDRESS_TYPE_PCI); =20 for (i =3D 0; i < def->nnets; i++) { - if (virMacAddrCmp(&def->nets[i]->mac, &net->mac)) + if (MACAddrSpecified && + virMacAddrCmp(&def->nets[i]->mac, &net->mac) !=3D 0) continue; =20 if ((matchidx >=3D 0) && !PCIAddrSpecified) { @@ -15660,9 +15668,15 @@ virDomainNetFindIdx(virDomainDefPtr def, virDomain= NetDefPtr net) * specify only vendor and product ID, and there may be * multiples of those. */ - virReportError(VIR_ERR_OPERATION_FAILED, - _("multiple devices matching mac address %s fou= nd"), - virMacAddrFormat(&net->mac, mac)); + if (MACAddrSpecified) { + virReportError(VIR_ERR_OPERATION_FAILED, + _("multiple devices matching mac address %s= found"), + virMacAddrFormat(&net->mac, mac)); + } else { + virReportError(VIR_ERR_OPERATION_FAILED, "%s", + _("multiple matching devices found")); + } + return -1; } if (PCIAddrSpecified) { @@ -15679,8 +15693,9 @@ virDomainNetFindIdx(virDomainDefPtr def, virDomainN= etDefPtr net) matchidx =3D i; } } + if (matchidx < 0) { - if (PCIAddrSpecified) { + if (MACAddrSpecified && PCIAddrSpecified) { virReportError(VIR_ERR_OPERATION_FAILED, _("no device matching mac address %s found on " "%.4x:%.2x:%.2x.%.1x"), @@ -15689,10 +15704,20 @@ virDomainNetFindIdx(virDomainDefPtr def, virDomai= nNetDefPtr net) net->info.addr.pci.bus, net->info.addr.pci.slot, net->info.addr.pci.function); - } else { + } else if (PCIAddrSpecified) { + virReportError(VIR_ERR_OPERATION_FAILED, + _("no device found on %.4x:%.2x:%.2x.%.1x"), + net->info.addr.pci.domain, + net->info.addr.pci.bus, + net->info.addr.pci.slot, + net->info.addr.pci.function); + } else if (MACAddrSpecified) { virReportError(VIR_ERR_OPERATION_FAILED, _("no device matching mac address %s found"), virMacAddrFormat(&net->mac, mac)); + } else { + virReportError(VIR_ERR_OPERATION_FAILED, "%s", + _("no matching device found")); } } return matchidx; --=20 2.13.5 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list