From nobody Tue Dec 16 03:19:52 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=1742894358; cv=none; d=zohomail.com; s=zohoarc; b=U6CslMeb+/FWZhZwRgup2uYO3BHNuja4MXMCKHV/kAlB+rOn5YJt9lrI5haqnWS3+nR1U41YekLkoGH8/s80frg+CIz3MXCrN6HtVoYFSNLt4+2/0qrTJiEUQ/dYsdEy5lq6NKmOLxS4/p8qn0Ain6FuXMAxBZBTE6jeFFu+cI8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1742894358; 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=w79YlAvhySQRhRp5LKivOnXnYmMNFicI6K+2/qvW/BA=; b=PUa3Ji5JZTuQMB0oboUgOzQ9NwIPyiUrd5/Urk421Anko/zwe/e9XxXkeUVB1fRyGv4Ezp7eJ4RMMIeKl5Np6AIkvURI7GtnRVlvFbdftXlUPRF+nc+KugCrg0jUuWD14PmhBxA6KVfEZhjJqmqoDtMjpzawuxyLtB1SQwz1kM4= 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 1742894358390531.0129874681288; Tue, 25 Mar 2025 02:19:18 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id B2AD4157B; Tue, 25 Mar 2025 05:19:17 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 0275E15AE; Tue, 25 Mar 2025 05:18:27 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 80B9714E5; Tue, 25 Mar 2025 05:18:22 -0400 (EDT) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.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 D790B14F1 for ; Tue, 25 Mar 2025 05:18:21 -0400 (EDT) Received: from mx-prod-mc-03.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-374-noesOhqDNmqz2cJ9DNIChQ-1; Tue, 25 Mar 2025 05:18:19 -0400 Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (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-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 1306A19560AA for ; Tue, 25 Mar 2025 09:18:19 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.3.236]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 5D77E1956095 for ; Tue, 25 Mar 2025 09:18:18 +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_H2, 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=1742894301; 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=jmc5TnQQ1MxmhExCRPvTKRz1v5Z3+dMAoo0UVZBVj04=; b=I8x2fl7X9nxY17X1vp28pQFhi5mB+7AdyYcCs5cETZ92ewyHftOzpDroSkBNMn5jO6EHuY 3AiVv1G7xhSgX7zJ9ls2jJh1/5kMUzXEK8RZlDP3hCPKR8+lf6UMr5Ptww2ztXf5p2SpOG 51gETBrRtlapf0y+2J/V8mgt9Do8I9s= X-MC-Unique: noesOhqDNmqz2cJ9DNIChQ-1 X-Mimecast-MFC-AGG-ID: noesOhqDNmqz2cJ9DNIChQ_1742894299 To: devel@lists.libvirt.org Subject: [PATCH v3 1/3] qemu: Reflect MAC address change in live domain XML Date: Tue, 25 Mar 2025 10:18:11 +0100 Message-ID: <9c1291905389e365fdf0b902c44720e36f08c027.1742894006.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: kndOW7GrJehzUAfpxucajB2EflzfGtqqbCELucZDvJI_1742894299 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: RL3WZRQI53LJZGRCZ6337TJO6UE7AX4E X-Message-ID-Hash: RL3WZRQI53LJZGRCZ6337TJO6UE7AX4E 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: 1742894359805019000 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 aae58fab60..3be7ee0ff4 100644 --- a/docs/formatdomain.rst +++ b/docs/formatdomain.rst @@ -5052,6 +5052,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 +``currentAddress`` attribute (output only), which contains new MAC address= if 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 7ea74b9b64..99ecb03067 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -2853,6 +2853,7 @@ virDomainNetDefFree(virDomainNetDef *def) if (!def) return; =20 + g_free(def->currentAddress); g_free(def->modelstr); =20 switch (def->type) { @@ -24948,6 +24949,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->currentAddress && + !(flags & VIR_DOMAIN_DEF_FORMAT_INACTIVE)) { + virBufferAsprintf(&macAttrBuf, " currentAddress=3D'%s'", + virMacAddrFormat(def->currentAddress, macstr)); + } virXMLFormatElement(buf, "mac", &macAttrBuf, NULL); =20 if (publicActual) { diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index ed39b60f6d..0d1dd954ae 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -1091,6 +1091,9 @@ struct _virDomainNetDef { bool mac_generated; /* true if mac was *just now* auto-generated by li= bvirt */ virDomainNetMacType mac_type; virTristateBool mac_check; + virMacAddr *currentAddress; /* MAC address from query-rx-filter (as re= ported + by guest). Not parsed from domain XML. = Output + only. */ int model; /* virDomainNetModelType */ char *modelstr; union { diff --git a/src/conf/schemas/domaincommon.rng b/src/conf/schemas/domaincom= mon.rng index 8bf909e6fb..5597d5a66b 100644 --- a/src/conf/schemas/domaincommon.rng +++ b/src/conf/schemas/domaincommon.rng @@ -3844,6 +3844,11 @@ + + + + + diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index fcdf28f3fc..7f89b193f9 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -11072,6 +11072,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, @@ -11080,6 +11093,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) @@ -11125,6 +11139,24 @@ qemuDomainSyncRxFilter(virDomainObj *vm, return -1; } =20 + if (def->currentAddress) + oldMac =3D def->currentAddress; + 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->currentAddress) { + def->currentAddress =3D g_new0(virMacAddr, 1); + } + + virMacAddrSet(def->currentAddress, &guestFilter->mac); + } else { + VIR_FREE(def->currentAddress); + } + } + return 0; } =20 diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 3cf21380ed..20b94ccdf0 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -3689,7 +3689,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 From nobody Tue Dec 16 03:19:52 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=1742894399; cv=none; d=zohomail.com; s=zohoarc; b=mg9GVQvm/YITIRnNsF7KUB1Y6csHrQdm8c0BOI/klcHecwDYCQccbizs6jdg9JcnlZwmSEVFTjQ/LXQIu/H/F4ODlGA6rGD58YCNJmR9C2oU6bG2TWUwH1Tx4sYEILo4sPoA+hWUiAphkDqhhWC5yV/FkPqW4lNIKXPp0BbLB2c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1742894399; 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=xmksjKlibQaQE/UJPt8n3SpaifCcYrno4Fb5RjJcY3s=; b=VuVXiiKMTWlllOXH+ULTF2cH1A37PXU8/fKnBX88fzboUfdBDE48/y5n34jaxDnTmrHlDXyJn6wF8iZL1Yb9G9OhtdLFSFFoDVkOb7kBYyp00AVZamS+r0pITjP0rKND1JypfcMmVahQUh51xgrC4ipN77BnCTNlW72yHtMJrM8= 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 1742894399968874.4369646784278; Tue, 25 Mar 2025 02:19:59 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id E6D151586; Tue, 25 Mar 2025 05:19:58 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 5AF0A15C5; Tue, 25 Mar 2025 05:18:30 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id F14F314F1; Tue, 25 Mar 2025 05:18:23 -0400 (EDT) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.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 0E71F13F0 for ; Tue, 25 Mar 2025 05:18:23 -0400 (EDT) Received: from mx-prod-mc-03.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-76-zbU76XNRP2KV3S_1i5zi7w-1; Tue, 25 Mar 2025 05:18:21 -0400 Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (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-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 66A761956067 for ; Tue, 25 Mar 2025 09:18:20 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.3.236]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 7BA921956095 for ; Tue, 25 Mar 2025 09:18:19 +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_H2, 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=1742894302; 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=NmkoFpqTT1s1iG/oiRN1Y0Bei+TBJ+lkRshky+UbxNs=; b=X2pLym9+YdUqPZm7QAaNZiAMXwvyFOHDS9kp78tNKifVG7JGjWoUaAre8Yo8nsTg0QQR4N YmNJb18GvJbqHtsDCAgWEapfBc/317GBAZZs6zGBx105pwvGAxarFBaaHjtlJIKQOeB216 Cr14QIbsqoHRbv+p9gPutaXNX4hQYZw= X-MC-Unique: zbU76XNRP2KV3S_1i5zi7w-1 X-Mimecast-MFC-AGG-ID: zbU76XNRP2KV3S_1i5zi7w_1742894300 To: devel@lists.libvirt.org Subject: [PATCH v3 2/3] Introduce NIC_MAC_CHANGE event Date: Tue, 25 Mar 2025 10:18:12 +0100 Message-ID: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: s0HfJy8VOPj8aMdoqpLOOvwypDHDSjL80yEq314JVQc_1742894300 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: 545D3K3QO3LA32YBIKCXZYL3EMVJA6CO X-Message-ID-Hash: 545D3K3QO3LA32YBIKCXZYL3EMVJA6CO 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: 1742894401772019100 Content-Type: text/plain; charset="utf-8"; x-default="true" From: Michal Privoznik The aim off this event is to notify management application that guest changed MAC address on one of its vNICs so the app can update its internal records, e.g. for finding match between guest/host view of vNICs. Signed-off-by: Michal Privoznik Reviewed-by: Martin Kletzander --- examples/c/misc/event-test.c | 14 +++++ include/libvirt/libvirt-domain.h | 28 +++++++++ src/conf/domain_event.c | 93 +++++++++++++++++++++++++++++ src/conf/domain_event.h | 12 ++++ src/libvirt_private.syms | 2 + src/remote/remote_daemon_dispatch.c | 32 ++++++++++ src/remote/remote_driver.c | 34 +++++++++++ src/remote/remote_protocol.x | 16 ++++- src/remote_protocol-structs | 8 +++ tools/virsh-domain-event.c | 20 +++++++ 10 files changed, 258 insertions(+), 1 deletion(-) diff --git a/examples/c/misc/event-test.c b/examples/c/misc/event-test.c index 88d99dff56..a61dbf4529 100644 --- a/examples/c/misc/event-test.c +++ b/examples/c/misc/event-test.c @@ -1102,6 +1102,19 @@ myNetworkEventMetadataChangeCallback(virConnectPtr c= onn G_GNUC_UNUSED, } =20 =20 +static int +myDomainEventNICMACChangeCallback(virConnectPtr conn G_GNUC_UNUSED, + virDomainPtr dom, + const char *alias, + const char *oldMAC, + const char *newMAC, + void *opaque G_GNUC_UNUSED) +{ + printf("%s EVENT: Domain %s(%d) NIC MAC changed: alias: '%s' oldMAC: '= %s' newMAC: '%s'\n", + __func__, virDomainGetName(dom), virDomainGetID(dom), alias, ol= dMAC, newMAC); + return 0; +} + =20 static void myFreeFunc(void *opaque) @@ -1160,6 +1173,7 @@ struct domainEventData domainEvents[] =3D { DOMAIN_EVENT(VIR_DOMAIN_EVENT_ID_BLOCK_THRESHOLD, myDomainEventBlockTh= resholdCallback), DOMAIN_EVENT(VIR_DOMAIN_EVENT_ID_MEMORY_FAILURE, myDomainEventMemoryFa= ilureCallback), DOMAIN_EVENT(VIR_DOMAIN_EVENT_ID_MEMORY_DEVICE_SIZE_CHANGE, myDomainEv= entMemoryDeviceSizeChangeCallback), + DOMAIN_EVENT(VIR_DOMAIN_EVENT_ID_NIC_MAC_CHANGE, myDomainEventNICMACCh= angeCallback), }; =20 struct storagePoolEventData { diff --git a/include/libvirt/libvirt-domain.h b/include/libvirt/libvirt-dom= ain.h index 6e11baa3d3..9496631bcc 100644 --- a/include/libvirt/libvirt-domain.h +++ b/include/libvirt/libvirt-domain.h @@ -6993,6 +6993,33 @@ typedef void (*virConnectDomainEventMemoryDeviceSize= ChangeCallback)(virConnectPt void *= opaque); =20 =20 +/** + * virConnectDomainEventNICMACChangeCallback: + * @conn: connection object + * @dom: domain on which the event occurred + * @alias: network interface device alias + * @oldMAC: the old value of network interface MAC address + * @newMAC: the new value of network interface MAC address + * @opaque: application specified data + * + * The callback occurs when the guest changes MAC address on one of + * its virtual network interfaces, for QEMU domains this is emitted + * only for vNICs of model virtio. The event is not emitted for + * other types (e.g. PCI device passthrough). + * + * The callback signature to use when registering for an event of + * type VIR_DOMAIN_EVENT_ID_NIC_MAC_CHANGE with + * virConnectDomainEventRegisterAny(). + * + * Since: 11.2.0 + */ +typedef void (*virConnectDomainEventNICMACChangeCallback)(virConnectPtr co= nn, + virDomainPtr dom, + const char *alia= s, + const char *oldM= AC, + const char *newM= AC, + void *opaque); + /** * VIR_DOMAIN_EVENT_CALLBACK: * @@ -7041,6 +7068,7 @@ typedef enum { VIR_DOMAIN_EVENT_ID_BLOCK_THRESHOLD =3D 24, /* virConnectDomainEventBl= ockThresholdCallback (Since: 3.2.0) */ VIR_DOMAIN_EVENT_ID_MEMORY_FAILURE =3D 25, /* virConnectDomainEventMe= moryFailureCallback (Since: 6.9.0) */ VIR_DOMAIN_EVENT_ID_MEMORY_DEVICE_SIZE_CHANGE =3D 26, /* virConnectDom= ainEventMemoryDeviceSizeChangeCallback (Since: 7.9.0) */ + VIR_DOMAIN_EVENT_ID_NIC_MAC_CHANGE =3D 27, /* virConnectDomainEventNIC= MACChangeCallback (Since: 11.2.0) */ =20 # ifdef VIR_ENUM_SENTINELS VIR_DOMAIN_EVENT_ID_LAST diff --git a/src/conf/domain_event.c b/src/conf/domain_event.c index 09f3368064..88087bad4f 100644 --- a/src/conf/domain_event.c +++ b/src/conf/domain_event.c @@ -57,6 +57,7 @@ static virClass *virDomainEventMetadataChangeClass; static virClass *virDomainEventBlockThresholdClass; static virClass *virDomainEventMemoryFailureClass; static virClass *virDomainEventMemoryDeviceSizeChangeClass; +static virClass *virDomainEventNICMACChangeClass; =20 static void virDomainEventDispose(void *obj); static void virDomainEventLifecycleDispose(void *obj); @@ -81,6 +82,7 @@ static void virDomainEventMetadataChangeDispose(void *obj= ); static void virDomainEventBlockThresholdDispose(void *obj); static void virDomainEventMemoryFailureDispose(void *obj); static void virDomainEventMemoryDeviceSizeChangeDispose(void *obj); +static void virDomainEventNICMACChangeDispose(void *obj); =20 static void virDomainEventDispatchDefaultFunc(virConnectPtr conn, @@ -285,6 +287,15 @@ struct _virDomainEventMemoryDeviceSizeChange { }; typedef struct _virDomainEventMemoryDeviceSizeChange virDomainEventMemoryD= eviceSizeChange; =20 +struct _virDomainEventNICMACChange { + virDomainEvent parent; + + char *alias; + char *oldMAC; + char *newMAC; +}; +typedef struct _virDomainEventNICMACChange virDomainEventNICMACChange; + static int virDomainEventsOnceInit(void) { @@ -334,6 +345,8 @@ virDomainEventsOnceInit(void) return -1; if (!VIR_CLASS_NEW(virDomainEventMemoryDeviceSizeChange, virDomainEven= tClass)) return -1; + if (!VIR_CLASS_NEW(virDomainEventNICMACChange, virDomainEventClass)) + return -1; return 0; } =20 @@ -559,6 +572,16 @@ virDomainEventMemoryDeviceSizeChangeDispose(void *obj) g_free(event->alias); } =20 +static void +virDomainEventNICMACChangeDispose(void *obj) +{ + virDomainEventNICMACChange *event =3D obj; + + g_free(event->alias); + g_free(event->oldMAC); + g_free(event->newMAC); +} + static void * virDomainEventNew(virClass *klass, int eventID, @@ -1733,6 +1756,62 @@ virDomainEventMemoryDeviceSizeChangeNewFromDom(virDo= mainPtr dom, } =20 =20 +static virObjectEvent * +virDomainEventNICMACChangeNew(int id, + const char *name, + unsigned char *uuid, + const char *alias, + const char *oldMAC, + const char *newMAC) + +{ + virDomainEventNICMACChange *ev; + + if (virDomainEventsInitialize() < 0) + return NULL; + + if (!(ev =3D virDomainEventNew(virDomainEventNICMACChangeClass, + VIR_DOMAIN_EVENT_ID_NIC_MAC_CHANGE, + id, name, uuid))) + return NULL; + + ev->alias =3D g_strdup(alias); + ev->oldMAC =3D g_strdup(oldMAC); + ev->newMAC =3D g_strdup(newMAC); + + return (virObjectEvent *)ev; +} + + +virObjectEvent * +virDomainEventNICMACChangeNewFromObj(virDomainObj *obj, + const char *alias, + const char *oldMAC, + const char *newMAC) +{ + return virDomainEventNICMACChangeNew(obj->def->id, + obj->def->name, + obj->def->uuid, + alias, + oldMAC, + newMAC); +} + +virObjectEvent * +virDomainEventNICMACChangeNewFromDom(virDomainPtr dom, + const char *alias, + const char *oldMAC, + const char *newMAC) +{ + return virDomainEventNICMACChangeNew(dom->id, + dom->name, + dom->uuid, + alias, + oldMAC, + newMAC); + +} + static void virDomainEventDispatchDefaultFunc(virConnectPtr conn, virObjectEvent *event, @@ -2041,6 +2120,20 @@ virDomainEventDispatchDefaultFunc(virConnectPtr conn, goto cleanup; } =20 + case VIR_DOMAIN_EVENT_ID_NIC_MAC_CHANGE: + { + virDomainEventNICMACChange *nicMacChangeEvent; + + nicMacChangeEvent =3D (virDomainEventNICMACChange *)event; + ((virConnectDomainEventNICMACChangeCallback)cb)(conn, dom, + nicMacChangeEv= ent->alias, + nicMacChangeEv= ent->oldMAC, + nicMacChangeEv= ent->newMAC, + cbopaque); + + goto cleanup; + } + case VIR_DOMAIN_EVENT_ID_LAST: break; } diff --git a/src/conf/domain_event.h b/src/conf/domain_event.h index f4016dc1e9..f31cfb9e42 100644 --- a/src/conf/domain_event.h +++ b/src/conf/domain_event.h @@ -277,6 +277,18 @@ virDomainEventMemoryDeviceSizeChangeNewFromDom(virDoma= inPtr dom, const char *alias, unsigned long long size); =20 +virObjectEvent * +virDomainEventNICMACChangeNewFromObj(virDomainObj *obj, + const char *alias, + const char *oldMAC, + const char *newMAC); + +virObjectEvent * +virDomainEventNICMACChangeNewFromDom(virDomainPtr dom, + const char *alias, + const char *oldMAC, + const char *newMAC); + int virDomainEventStateRegister(virConnectPtr conn, virObjectEventState *state, diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index f20ef34bca..812fa4e435 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -779,6 +779,8 @@ virDomainEventMetadataChangeNewFromDom; virDomainEventMetadataChangeNewFromObj; virDomainEventMigrationIterationNewFromDom; virDomainEventMigrationIterationNewFromObj; +virDomainEventNICMACChangeNewFromDom; +virDomainEventNICMACChangeNewFromObj; virDomainEventPMSuspendDiskNewFromDom; virDomainEventPMSuspendDiskNewFromObj; virDomainEventPMSuspendNewFromDom; diff --git a/src/remote/remote_daemon_dispatch.c b/src/remote/remote_daemon= _dispatch.c index e812f5c3e9..5dfed7ceef 100644 --- a/src/remote/remote_daemon_dispatch.c +++ b/src/remote/remote_daemon_dispatch.c @@ -1323,6 +1323,37 @@ remoteRelayDomainEventMemoryDeviceSizeChange(virConn= ectPtr conn, } =20 =20 +static int +remoteRelayDomainEventNICMACChange(virConnectPtr conn, + virDomainPtr dom, + const char *alias, + const char *oldMAC, + const char *newMAC, + void *opaque) +{ + daemonClientEventCallback *callback =3D opaque; + remote_domain_event_nic_mac_change_msg data; + + if (callback->callbackID < 0 || + !remoteRelayDomainEventCheckACL(callback->client, conn, dom)) + return -1; + + /* build return data */ + memset(&data, 0, sizeof(data)); + data.callbackID =3D callback->callbackID; + data.alias =3D g_strdup(alias); + data.oldMAC =3D g_strdup(oldMAC); + data.newMAC =3D g_strdup(newMAC); + make_nonnull_domain(&data.dom, dom); + + remoteDispatchObjectEventSend(callback->client, remoteProgram, + REMOTE_PROC_DOMAIN_EVENT_NIC_MAC_CHANGE, + (xdrproc_t)xdr_remote_domain_event_nic_m= ac_change_msg, + &data); + return 0; +} + + static virConnectDomainEventGenericCallback domainEventCallbacks[] =3D { VIR_DOMAIN_EVENT_CALLBACK(remoteRelayDomainEventLifecycle), VIR_DOMAIN_EVENT_CALLBACK(remoteRelayDomainEventReboot), @@ -1351,6 +1382,7 @@ static virConnectDomainEventGenericCallback domainEve= ntCallbacks[] =3D { VIR_DOMAIN_EVENT_CALLBACK(remoteRelayDomainEventBlockThreshold), VIR_DOMAIN_EVENT_CALLBACK(remoteRelayDomainEventMemoryFailure), VIR_DOMAIN_EVENT_CALLBACK(remoteRelayDomainEventMemoryDeviceSizeChange= ), + VIR_DOMAIN_EVENT_CALLBACK(remoteRelayDomainEventNICMACChange), }; =20 G_STATIC_ASSERT(G_N_ELEMENTS(domainEventCallbacks) =3D=3D VIR_DOMAIN_EVENT= _ID_LAST); diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c index 7d9f5421bf..745cd34f83 100644 --- a/src/remote/remote_driver.c +++ b/src/remote/remote_driver.c @@ -432,6 +432,11 @@ remoteConnectNotifyEventConnectionClosed(virNetClientP= rogram *prog G_GNUC_UNUSED virNetClient *client G_GNUC_UNUSE= D, void *evdata, void *opaque); =20 +static void +remoteDomainBuildEventNICMACChange(virNetClientProgram *prog, + virNetClient *client, + void *evdata, void *opaque); + static virNetClientProgramEvent remoteEvents[] =3D { { REMOTE_PROC_DOMAIN_EVENT_LIFECYCLE, remoteDomainBuildEventLifecycle, @@ -650,6 +655,10 @@ static virNetClientProgramEvent remoteEvents[] =3D { remoteDomainBuildEventMemoryDeviceSizeChange, sizeof(remote_domain_event_memory_device_size_change_msg), (xdrproc_t)xdr_remote_domain_event_memory_device_size_change_msg }, + { REMOTE_PROC_DOMAIN_EVENT_NIC_MAC_CHANGE, + remoteDomainBuildEventNICMACChange, + sizeof(remote_domain_event_nic_mac_change_msg), + (xdrproc_t)xdr_remote_domain_event_nic_mac_change_msg }, }; =20 static void @@ -5068,6 +5077,31 @@ remoteDomainBuildEventMemoryDeviceSizeChange(virNetC= lientProgram *prog G_GNUC_UN } =20 =20 +static void +remoteDomainBuildEventNICMACChange(virNetClientProgram *prog G_GNUC_UNUSED, + virNetClient *client G_GNUC_UNUSED, + void *evdata, void *opaque) +{ + virConnectPtr conn =3D opaque; + remote_domain_event_nic_mac_change_msg *msg =3D evdata; + struct private_data *priv =3D conn->privateData; + virDomainPtr dom; + virObjectEvent *event =3D NULL; + + if (!(dom =3D get_nonnull_domain(conn, msg->dom))) + return; + + event =3D virDomainEventNICMACChangeNewFromDom(dom, + msg->alias, + msg->oldMAC, + msg->newMAC); + + virObjectUnref(dom); + + virObjectEventStateQueueRemote(priv->eventState, event, msg->callbackI= D); +} + + static int remoteStreamSend(virStreamPtr st, const char *data, diff --git a/src/remote/remote_protocol.x b/src/remote/remote_protocol.x index d6bdc75d03..57cd5796af 100644 --- a/src/remote/remote_protocol.x +++ b/src/remote/remote_protocol.x @@ -4000,6 +4000,14 @@ struct remote_domain_set_autostart_once_args { int autostart; }; =20 +struct remote_domain_event_nic_mac_change_msg { + int callbackID; + remote_nonnull_domain dom; + remote_nonnull_string alias; + remote_nonnull_string oldMAC; + remote_nonnull_string newMAC; +}; + /*----- Protocol. -----*/ =20 /* Define the program number, protocol version and procedure numbers here.= */ @@ -7105,5 +7113,11 @@ enum remote_procedure { * @acl: domain:save:!VIR_DOMAIN_AFFECT_CONFIG|VIR_DOMAIN_AFFECT_LIVE * @acl: domain:save:VIR_DOMAIN_AFFECT_CONFIG */ - REMOTE_PROC_DOMAIN_DEL_THROTTLE_GROUP =3D 452 + REMOTE_PROC_DOMAIN_DEL_THROTTLE_GROUP =3D 452, + + /** + * @generate: both + * @acl: none + */ + REMOTE_PROC_DOMAIN_EVENT_NIC_MAC_CHANGE =3D 453 }; diff --git a/src/remote_protocol-structs b/src/remote_protocol-structs index 8acc5475c2..dd612b4dc6 100644 --- a/src/remote_protocol-structs +++ b/src/remote_protocol-structs @@ -3330,6 +3330,13 @@ struct remote_domain_set_autostart_once_args { remote_nonnull_domain dom; int autostart; }; +struct remote_domain_event_nic_mac_change_msg { + int callbackID; + remote_nonnull_domain dom; + remote_nonnull_string alias; + remote_nonnull_string oldMAC; + remote_nonnull_string newMAC; +}; enum remote_procedure { REMOTE_PROC_CONNECT_OPEN =3D 1, REMOTE_PROC_CONNECT_CLOSE =3D 2, @@ -3783,4 +3790,5 @@ enum remote_procedure { REMOTE_PROC_DOMAIN_SET_AUTOSTART_ONCE =3D 450, REMOTE_PROC_DOMAIN_SET_THROTTLE_GROUP =3D 451, REMOTE_PROC_DOMAIN_DEL_THROTTLE_GROUP =3D 452, + REMOTE_PROC_DOMAIN_EVENT_NIC_MAC_CHANGE =3D 453, }; diff --git a/tools/virsh-domain-event.c b/tools/virsh-domain-event.c index cd33d4d938..69a68d857d 100644 --- a/tools/virsh-domain-event.c +++ b/tools/virsh-domain-event.c @@ -783,6 +783,24 @@ virshEventMemoryDeviceSizeChangePrint(virConnectPtr co= nn G_GNUC_UNUSED, } =20 =20 +static void +virshEventNICMACChangePrint(virConnectPtr conn G_GNUC_UNUSED, + virDomainPtr dom, + const char *alias, + const char *oldMAC, + const char *newMAC, + void *opaque) +{ + g_auto(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; + + virBufferAsprintf(&buf, + _("event 'nic-mac-change' for domain '%1$s':\nalias:= %2$s\noldMAC: %3$s\nnewMAC: %4$s\n"), + virDomainGetName(dom), alias, oldMAC, newMAC); + + virshEventPrint(opaque, &buf); +} + + virshDomainEventCallback virshDomainEventCallbacks[] =3D { { "lifecycle", VIR_DOMAIN_EVENT_CALLBACK(virshEventLifecyclePrint), }, @@ -836,6 +854,8 @@ virshDomainEventCallback virshDomainEventCallbacks[] = =3D { VIR_DOMAIN_EVENT_CALLBACK(virshEventMemoryFailurePrint), }, { "memory-device-size-change", VIR_DOMAIN_EVENT_CALLBACK(virshEventMemoryDeviceSizeChangePrint), }, + { "nic-mac-change", + VIR_DOMAIN_EVENT_CALLBACK(virshEventNICMACChangePrint), }, }; G_STATIC_ASSERT(VIR_DOMAIN_EVENT_ID_LAST =3D=3D G_N_ELEMENTS(virshDomainEv= entCallbacks)); =20 --=20 2.48.1 From nobody Tue Dec 16 03:19:52 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=1742894429; cv=none; d=zohomail.com; s=zohoarc; b=AxDekN6JXW1TPJW9oH5m2f7uRRri9xxyqXf18gCN8X+gCy1ZDahQL02F+2iWoS7ELoDNj2tayKDs7qhCvKiOw60xSm/BUdElb0i+4irExfnSslyUDd0Vb7ksTfDiHdzAGtWF31ZZPDKViMpbgJuKdEZW9rSKerxqFLZW240ZjI8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1742894429; 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=LxEp3c1yxb66IsSaj1E6y7dK4N1tuLDvdT13O2Jx51A=; b=LdQ1ipCjL7+ZkLqD3HlS4MftZWhrGp3RsFQNL4ikOl5kIW1UqwbFZNJkpnMVKNN3LPZ/I3BimDaOi6LTQj8bZc7CUWQX18RL7BVs8BUtKfS4eZA2745VJKJEOfa1BkYkFPQSAYGJw5JeBX91b1yOQzkyMHsuIWdSlFJo8mOyzcI= 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 1742894429879109.62266652618416; Tue, 25 Mar 2025 02:20:29 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id E93A5152C; Tue, 25 Mar 2025 05:20:28 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 7E51C1557; Tue, 25 Mar 2025 05:18:35 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 95F9B1549; Tue, 25 Mar 2025 05:18: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 88812152D for ; Tue, 25 Mar 2025 05:18:24 -0400 (EDT) Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-9-tDHslBIKP22tZUkRZF79yw-1; Tue, 25 Mar 2025 05:18:22 -0400 Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (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-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 83D78180035C for ; Tue, 25 Mar 2025 09:18:21 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.3.236]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id CEF8F1955BC1 for ; Tue, 25 Mar 2025 09:18:20 +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=1742894304; 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=EWQtkhj2RQbsBHwSnAYkn/DmGHGOjsUUvQ8uxF1molc=; b=AGP08wKk0m/5Yiy4Yx2EoSVUo7TN1s1Y52b9NpHmkCclRrMuQhS15HfbBQxCQPE6PNhJnX f+55nv97BGmW5n3qr6XNaFoRve3r8V9bAZJKxvWyfkhpcETeZ/ifKPrYoMSGMDSFHJnVhS xjQ/blSfQ5dATh2g6bvWT+6/Gf3o47A= X-MC-Unique: tDHslBIKP22tZUkRZF79yw-1 X-Mimecast-MFC-AGG-ID: tDHslBIKP22tZUkRZF79yw_1742894301 To: devel@lists.libvirt.org Subject: [PATCH v3 3/3] qemu: Emit NIC_MAC_CHANGE event Date: Tue, 25 Mar 2025 10:18:13 +0100 Message-ID: <2a6bd6c9350a01f8172e2f78f006a79a1d3dfdd9.1742894007.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: BU6dE-8mITu4tJpikT0TXZJ0WKA5tVCJkkgT2v_cMzc_1742894301 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: AFF6TXRSF5KCLFEIEZ2EO3ZYGAK3DI2I X-Message-ID-Hash: AFF6TXRSF5KCLFEIEZ2EO3ZYGAK3DI2I 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: 1742894431527019100 Content-Type: text/plain; charset="utf-8"; x-default="true" From: Michal Privoznik So far, we only process NIC_RX_FILTER_CHANGED event when the corresponding device has 'trustGuestRxFilters' enabled. And the event is emitted only for virtio model. IOW, this is fairly limited situation and other scenarios don't emit any event (e.g. change of MAC address on a PCI passthrough device). Resolves: https://issues.redhat.com/browse/RHEL-7035 Signed-off-by: Michal Privoznik Reviewed-by: Martin Kletzander --- src/qemu/qemu_domain.c | 16 +++++++++++++++- src/qemu/qemu_domain.h | 3 ++- src/qemu/qemu_driver.c | 9 ++++++--- src/qemu/qemu_process.c | 2 +- 4 files changed, 24 insertions(+), 6 deletions(-) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 7f89b193f9..e45eef4787 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -11088,7 +11088,8 @@ syncNicRxFilterMulticast(char *ifname, int qemuDomainSyncRxFilter(virDomainObj *vm, virDomainNetDef *def, - virDomainAsyncJob asyncJob) + virDomainAsyncJob asyncJob, + virObjectEvent **event) { qemuDomainObjPrivate *priv =3D vm->privateData; g_autoptr(virNetDevRxFilter) guestFilter =3D NULL; @@ -11145,6 +11146,19 @@ qemuDomainSyncRxFilter(virDomainObj *vm, oldMac =3D &def->mac; =20 if (virMacAddrCmp(oldMac, &guestFilter->mac)) { + if (event) { + char oldMACStr[VIR_MAC_STRING_BUFLEN] =3D { 0 }; + char newMACStr[VIR_MAC_STRING_BUFLEN] =3D { 0 }; + + virMacAddrFormat(oldMac, oldMACStr); + virMacAddrFormat(&guestFilter->mac, newMACStr); + + *event =3D virDomainEventNICMACChangeNewFromObj(vm, + def->info.alias, + oldMACStr, + newMACStr); + } + /* Reflect changed MAC address in the domain XML. */ if (virMacAddrCmp(&def->mac, &guestFilter->mac)) { if (!def->currentAddress) { diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h index e3b206763c..70e1fb187f 100644 --- a/src/qemu/qemu_domain.h +++ b/src/qemu/qemu_domain.h @@ -1132,7 +1132,8 @@ qemuDomainRefreshStatsSchema(virDomainObj *dom); int qemuDomainSyncRxFilter(virDomainObj *vm, virDomainNetDef *def, - virDomainAsyncJob asyncJob); + virDomainAsyncJob asyncJob, + virObjectEvent **event); =20 int qemuDomainSchedCoreStart(virQEMUDriverConfig *cfg, diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 20b94ccdf0..1be32c01b1 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -3679,9 +3679,11 @@ processNetdevStreamDisconnectedEvent(virDomainObj *v= m, =20 =20 static void -processNicRxFilterChangedEvent(virDomainObj *vm, +processNicRxFilterChangedEvent(virQEMUDriver *driver, + virDomainObj *vm, const char *devAlias) { + virObjectEvent *event =3D NULL; virDomainDeviceDef dev; virDomainNetDef *def; =20 @@ -3726,11 +3728,12 @@ processNicRxFilterChangedEvent(virDomainObj *vm, VIR_DEBUG("process NIC_RX_FILTER_CHANGED event for network " "device %s in domain %s", def->info.alias, vm->def->name); =20 - if (qemuDomainSyncRxFilter(vm, def, VIR_ASYNC_JOB_NONE) < 0) + if (qemuDomainSyncRxFilter(vm, def, VIR_ASYNC_JOB_NONE, &event) < 0) goto endjob; =20 endjob: virDomainObjEndJob(vm); + virObjectEventStateQueue(driver->domainEventState, event); } =20 =20 @@ -4074,7 +4077,7 @@ static void qemuProcessEventHandler(void *data, void = *opaque) processNetdevStreamDisconnectedEvent(vm, processEvent->data); break; case QEMU_PROCESS_EVENT_NIC_RX_FILTER_CHANGED: - processNicRxFilterChangedEvent(vm, processEvent->data); + processNicRxFilterChangedEvent(driver, vm, processEvent->data); break; case QEMU_PROCESS_EVENT_SERIAL_CHANGED: processSerialChangedEvent(driver, vm, processEvent->data, diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index c3eeadfc3b..842f559439 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -8362,7 +8362,7 @@ qemuProcessRefreshRxFilters(virDomainObj *vm, continue; } =20 - if (qemuDomainSyncRxFilter(vm, def, asyncJob) < 0) + if (qemuDomainSyncRxFilter(vm, def, asyncJob, NULL) < 0) return -1; } =20 --=20 2.48.1