From nobody Fri Dec 19 08:03:11 2025 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=1566956832; cv=none; d=zoho.com; s=zohoarc; b=MC1heIXnWWKGIc0A2bcEqsS+j96vXMRwqFMoZT5GBhyUjH9HaemzTxVC4Ka+hJJK9G5vjFXL3cBxnFyMse0kRuSpEnltRybtaYW/ydyYH9NMFvVbwN8nmadnefYWv62/8WpgTd5AJhuLT8N94lyp5ppyYtqopZFWBi8Pth/10oA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1566956832; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=L8S65dnURkp67xu3OnubpyaUOPADlI7lFmO6pW4icPQ=; b=VtGa6eTOnSLVGa+4prLfmt7ZBRUQbJTjOouZF4MvkI+J15eJ1ylDFll5N9weX/6QxGpQtDi4neElsu9RS/gckTHgpCsh/Rxv0v0DxrLAltZFKfPeeB3pod0f/AlgYViUsi9qn6DmpMYE3+WFhpjvKAE/m+KLYOebubvUZlj4L50= 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 1566956832582954.4597883007077; Tue, 27 Aug 2019 18:47:12 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 28E138980EF; Wed, 28 Aug 2019 01:47:11 +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 01F7C4D6F1; Wed, 28 Aug 2019 01:47:11 +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 6EE7B1802218; Wed, 28 Aug 2019 01:47:10 +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 x7S1kqBY014352 for ; Tue, 27 Aug 2019 21:46:52 -0400 Received: by smtp.corp.redhat.com (Postfix) id 4E44A5C221; Wed, 28 Aug 2019 01:46:52 +0000 (UTC) Received: from vhost2.laine.org (ovpn-116-137.phx2.redhat.com [10.3.116.137]) by smtp.corp.redhat.com (Postfix) with ESMTP id EB0F15C207; Wed, 28 Aug 2019 01:46:51 +0000 (UTC) From: Laine Stump To: libvir-list@redhat.com Date: Tue, 27 Aug 2019 21:46:33 -0400 Message-Id: <20190828014640.27582-4-laine@redhat.com> In-Reply-To: <20190828014640.27582-1-laine@redhat.com> References: <20190828014640.27582-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 3/9] qemu: reorganize qemuInterfaceEthernetConnect() 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.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.67]); Wed, 28 Aug 2019 01:47:11 +0000 (UTC) Content-Type: text/plain; charset="utf-8" This just moves around a few things in qemuInterfaceConnect() with no functional difference (except that a few failures that would have previously resulted in a "success" audit log will now properly produce a "fail" audit). The change is so that adding support for unmanaged tap/macvtap devices will be more easily reviewable. Signed-off-by: Laine Stump --- src/qemu/qemu_interface.c | 69 ++++++++++++++++++++------------------- 1 file changed, 35 insertions(+), 34 deletions(-) diff --git a/src/qemu/qemu_interface.c b/src/qemu/qemu_interface.c index 72ed51cb1f..1e3b7f0d06 100644 --- a/src/qemu/qemu_interface.c +++ b/src/qemu/qemu_interface.c @@ -414,6 +414,7 @@ qemuInterfaceEthernetConnect(virDomainDefPtr def, bool template_ifname =3D false; virQEMUDriverConfigPtr cfg =3D virQEMUDriverGetConfig(driver); const char *tunpath =3D "/dev/net/tun"; + const char *auditdev =3D tunpath; =20 if (net->backend.tap) { tunpath =3D net->backend.tap; @@ -424,43 +425,39 @@ qemuInterfaceEthernetConnect(virDomainDefPtr def, } } =20 - if (!net->ifname || - STRPREFIX(net->ifname, VIR_NET_GENERATED_TAP_PREFIX) || - strchr(net->ifname, '%')) { - VIR_FREE(net->ifname); - if (VIR_STRDUP(net->ifname, VIR_NET_GENERATED_TAP_PREFIX "%d") < 0) - goto cleanup; - /* avoid exposing vnet%d in getXMLDesc or error outputs */ - template_ifname =3D true; - } - if (virDomainNetIsVirtioModel(net)) tap_create_flags |=3D VIR_NETDEV_TAP_CREATE_VNET_HDR; =20 - if (virNetDevTapCreate(&net->ifname, tunpath, tapfd, tapfdSize, - tap_create_flags) < 0) { - virDomainAuditNetDevice(def, net, tunpath, false); - goto cleanup; - } - - 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); - if (tapmac.addr[0] =3D=3D 0xFE) - tapmac.addr[0] =3D 0xFA; - else - tapmac.addr[0] =3D 0xFE; - - if (virNetDevSetMAC(net->ifname, &tapmac) < 0) - goto cleanup; - - if (virNetDevSetOnline(net->ifname, true) < 0) - goto cleanup; + if (!net->ifname || + STRPREFIX(net->ifname, VIR_NET_GENERATED_TAP_PREFIX) || + strchr(net->ifname, '%')) { + VIR_FREE(net->ifname); + if (VIR_STRDUP(net->ifname, VIR_NET_GENERATED_TAP_PREFIX "%d") < 0) + goto cleanup; + /* avoid exposing vnet%d in getXMLDesc or error outputs */ + template_ifname =3D true; + } + if (virNetDevTapCreate(&net->ifname, tunpath, tapfd, tapfdSize, + tap_create_flags) < 0) { + goto cleanup; + } + + /* 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); + if (tapmac.addr[0] =3D=3D 0xFE) + tapmac.addr[0] =3D 0xFA; + else + tapmac.addr[0] =3D 0xFE; + + if (virNetDevSetMAC(net->ifname, &tapmac) < 0) + goto cleanup; + + if (virNetDevSetOnline(net->ifname, true) < 0) + goto cleanup; =20 if (net->script && virNetDevRunEthernetScript(net->ifname, net->script) < 0) @@ -477,11 +474,15 @@ qemuInterfaceEthernetConnect(virDomainDefPtr def, goto cleanup; } =20 + virDomainAuditNetDevice(def, net, auditdev, true); + ret =3D 0; =20 cleanup: if (ret < 0) { size_t i; + + virDomainAuditNetDevice(def, net, auditdev, false); for (i =3D 0; i < tapfdSize && tapfd[i] >=3D 0; i++) VIR_FORCE_CLOSE(tapfd[i]); if (template_ifname) --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list