From nobody Fri Dec 19 04:17:22 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=pass(p=reject dis=none) header.from=lists.libvirt.org ARC-Seal: i=1; a=rsa-sha256; t=1742306361; cv=none; d=zohomail.com; s=zohoarc; b=MlcZ+wjFhPzCLT9SL7n4107rM5zUdOxHHo9B0v8MbHig2+aocHo+Em8fkijdlG/5AH37OfI0j8tKZrHobM9wEbvCgU7BxkBwD+m8tlijrjluvQIbaL1Dga0oaMGq6L0HC4aFmSx+fVmt92smio2tqNu4BK7kLi8Jd8tdgEcj9kw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1742306361; h=Content-Type:Content-Transfer-Encoding:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Subject:Subject:To:To:Message-Id:Cc; bh=tTCZFlEHMb9+7hwOZP5qwDjkBgHTxAI8+lixt19/kZ0=; b=BufYyAA1tfCYGgn7y34CEwXqAzn6TGQs/VAwFGHZhWwaE0EXIBoGKEOlPxvL9A9y2DjVB4XSDeI5ZPaoD+co0bUDbs8F0MYkNHd40eDTJci6838YHGGxU6lsZc+fuWztFxWnMBau2Mc51NP+O85RHGsfxsmLQBY5PJfFvEi8kU4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1742306361736654.9887783659219; Tue, 18 Mar 2025 06:59:21 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 1A62317DE; Tue, 18 Mar 2025 09:59:21 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 4D682147F; Tue, 18 Mar 2025 09:58:34 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 6CB06144B; Tue, 18 Mar 2025 09:58:30 -0400 (EDT) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id C7DC81442 for ; Tue, 18 Mar 2025 09:58:29 -0400 (EDT) Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-635-A5yNLLz2P_K-JG_iRN8q7A-1; Tue, 18 Mar 2025 09:58:28 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 891C0195608D for ; Tue, 18 Mar 2025 13:58:26 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.3.236]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id D432F1955DCD for ; Tue, 18 Mar 2025 13:58:25 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H5, RCVD_IN_MSPIKE_WL,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED,SPF_HELO_NONE autolearn=unavailable autolearn_force=no version=3.4.4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1742306309; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Q9czxY0ue1deryNvI7dh9JiTNG1ygpJDKW7lwB5ye9M=; b=O7iQJJMg1sHmibs5opKM9FVPR9jMaChxEYkTjDl1QYqb9B7qBSvJDvFOsC/3v3Tvc1Kl5B HBPDl46kKyIfWzo2XBOzVXPegWAOArRubYsqkWFPcaVn7XBaoSh7Ah9SYS46oFmj2By2x7 LhUJTGp76P5rR2tR46Jq4dWg7Nx01pw= X-MC-Unique: A5yNLLz2P_K-JG_iRN8q7A-1 X-Mimecast-MFC-AGG-ID: A5yNLLz2P_K-JG_iRN8q7A_1742306306 To: devel@lists.libvirt.org Subject: [PATCH v2 1/3] qemu: Reflect MAC address change in live domain XML Date: Tue, 18 Mar 2025 14:58:18 +0100 Message-ID: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: F4r4xZQTacw0ONDz77UEotGuOssX_8eyuiMoiqL-RL4_1742306306 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: 4CJWFQZMPHLLUYYP2VMROPPQTTNQZPX4 X-Message-ID-Hash: 4CJWFQZMPHLLUYYP2VMROPPQTTNQZPX4 X-MailFrom: mprivozn@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: From: Michal Privoznik via Devel Reply-To: Michal Privoznik X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1742306362889019000 Content-Type: text/plain; charset="utf-8"; x-default="true" From: Michal Privoznik If a guest changes MAC address on its vNIC, then QEMU emits NIC_RX_FILTER_CHANGED event (the event is emitted in other cases too, but that's not important right now). Now, domain XML allows users to chose whether to trust these events or not: For the 'no' case no action is performed and the event is ignored. But for the 'yes' case, some host side features of corresponding vNIC (well tap/macvtap device) are tweaked to reflect changed MAC address. But what is missing is reflecting this new MAC address in domain XML. Basically, what happens is: the host sees traffic with new MAC address, all tools inside the guest see the new MAC address (including 'virsh domifaddr --source agent') which makes it harder to match device in the guest with the one in the domain XML. Therefore, report this new MAC address as another attribute of the element: Signed-off-by: Michal Privoznik Reviewed-by: Martin Kletzander --- docs/formatdomain.rst | 5 +++++ src/conf/domain_conf.c | 6 ++++++ src/conf/domain_conf.h | 3 +++ src/conf/schemas/domaincommon.rng | 5 +++++ src/qemu/qemu_domain.c | 32 +++++++++++++++++++++++++++++++ src/qemu/qemu_driver.c | 2 +- 6 files changed, 52 insertions(+), 1 deletion(-) diff --git a/docs/formatdomain.rst b/docs/formatdomain.rst index 4bc6a318f5..c82d158922 100644 --- a/docs/formatdomain.rst +++ b/docs/formatdomain.rst @@ -4966,6 +4966,11 @@ when it's in the reserved VMware range by adding a `= `type=3D"static"`` attribute to the ```` element. Note that this attribute is useless if the prov= ided MAC address is outside of the reserved VMWare ranges. =20 +:since:`Since 11.2.0`, the ```` element can optionally contain +``guestAddress`` attribute (output only), which contains new MAC address i= f the +guest changed it. This is currently implemented only for QEMU/KVM and requ= ires +setting ``trustGuestRxFilters`` to ``yes``. + :since:`Since 7.3.0`, one can set the ACPI index against network interface= s. With some operating systems (eg Linux with systemd), the ACPI index is used to provide network interface device naming, that is stable across changes diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index dedcf76511..7c68fd6f2a 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -2840,6 +2840,7 @@ virDomainNetDefFree(virDomainNetDef *def) if (!def) return; =20 + g_free(def->guestAddress); g_free(def->modelstr); =20 switch (def->type) { @@ -24586,6 +24587,11 @@ virDomainNetDefFormat(virBuffer *buf, virBufferAsprintf(&macAttrBuf, " type=3D'%s'", virDomainNetMacType= TypeToString(def->mac_type)); if (def->mac_check !=3D VIR_TRISTATE_BOOL_ABSENT) virBufferAsprintf(&macAttrBuf, " check=3D'%s'", virTristateBoolTyp= eToString(def->mac_check)); + if (def->guestAddress && + !(flags & VIR_DOMAIN_DEF_FORMAT_INACTIVE)) { + virBufferAsprintf(&macAttrBuf, " guestAddress=3D'%s'", + virMacAddrFormat(def->guestAddress, macstr)); + } virXMLFormatElement(buf, "mac", &macAttrBuf, NULL); =20 if (publicActual) { diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 3a97fd866c..3368921d6d 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -1078,6 +1078,9 @@ struct _virDomainNetDef { bool mac_generated; /* true if mac was *just now* auto-generated by li= bvirt */ virDomainNetMacType mac_type; virTristateBool mac_check; + virMacAddr *guestAddress; /* MAC address from query-rx-filter (as repo= rted + by guest). Not parsed from domain XML. Ou= tput + only. */ int model; /* virDomainNetModelType */ char *modelstr; union { diff --git a/src/conf/schemas/domaincommon.rng b/src/conf/schemas/domaincom= mon.rng index 3276569325..ad6b889a93 100644 --- a/src/conf/schemas/domaincommon.rng +++ b/src/conf/schemas/domaincommon.rng @@ -3837,6 +3837,11 @@ + + + + + diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 29fac0034e..47ae59d408 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -11002,6 +11002,19 @@ syncNicRxFilterMulticast(char *ifname, } =20 =20 +/** + * qemuDomainSyncRxFilter: + * @vm: domain object + * @def: domain interface definition + * @asyncJob: async job type + * + * Fetch new state of RX Filter and set host side of the interface + * accordingly (e.g. reflect MAC address change on macvtap). + * + * Reflect changed MAC address in the domain definition. + * + * Returns: 0 on success, -1 on error. + */ int qemuDomainSyncRxFilter(virDomainObj *vm, virDomainNetDef *def, @@ -11010,6 +11023,7 @@ qemuDomainSyncRxFilter(virDomainObj *vm, qemuDomainObjPrivate *priv =3D vm->privateData; g_autoptr(virNetDevRxFilter) guestFilter =3D NULL; g_autoptr(virNetDevRxFilter) hostFilter =3D NULL; + virMacAddr *oldMac =3D NULL; int rc; =20 if (qemuDomainObjEnterMonitorAsync(vm, asyncJob) < 0) @@ -11055,6 +11069,24 @@ qemuDomainSyncRxFilter(virDomainObj *vm, return -1; } =20 + if (def->guestAddress) + oldMac =3D def->guestAddress; + else + oldMac =3D &def->mac; + + if (virMacAddrCmp(oldMac, &guestFilter->mac)) { + /* Reflect changed MAC address in the domain XML. */ + if (virMacAddrCmp(&def->mac, &guestFilter->mac)) { + if (!def->guestAddress) { + def->guestAddress =3D g_new0(virMacAddr, 1); + } + + virMacAddrSet(def->guestAddress, &guestFilter->mac); + } else { + VIR_FREE(def->guestAddress); + } + } + return 0; } =20 diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index f0e9681161..a4866450fc 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -3677,7 +3677,7 @@ processNicRxFilterChangedEvent(virDomainObj *vm, "from domain %p %s", devAlias, vm, vm->def->name); =20 - if (virDomainObjBeginJob(vm, VIR_JOB_QUERY) < 0) + if (virDomainObjBeginJob(vm, VIR_JOB_MODIFY) < 0) return; =20 if (!virDomainObjIsActive(vm)) { --=20 2.48.1