From nobody Sat May 18 03:15:25 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 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=1687949634; cv=none; d=zohomail.com; s=zohoarc; b=UxF8BX4fGXgOSA18KchAAJRhQQAENLFGLq98boDTIWPEM1mZ3+32NV8yNaah/98mQ0nYD2B31pGM4vPJ2EcWPm685a3xvswQSpYSfxc2cZWMXDTlvw8TKOhUde/i32MyxMuzS5BfGZoXJp4CUAXhPVmZl2/v9y+ZwBaQ9EEKWnA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1687949634; 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; bh=beftYfidEYq8kg9D1ccmPeY68+HdLmvOloUWJUEj4UA=; b=jHouGMF/zf0JZXp8omY+05HBkOO2phiG7ocXvzhCndNwRpJ6dPxAAEE/MXdyioTxcVy6nCNhUsHj7Z6uM5w/otnXHry3UO8ng1Ql39sm4cdKktg6a5mBCKvAmKgc5cD09pQsuPDHffaOQRmW5zy6B2gQAGaGCIB+SDn+1GS6/4U= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 168794963493167.604825214882; Wed, 28 Jun 2023 03:53:54 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-653-Dt_FwhTEOt-drOQJpeDC3g-1; Wed, 28 Jun 2023 06:53:49 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 4EE2638117F5; Wed, 28 Jun 2023 10:53:46 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3719140C2073; Wed, 28 Jun 2023 10:53:46 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 1F2EE1946589; Wed, 28 Jun 2023 10:53:41 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 113211946A40 for ; Wed, 28 Jun 2023 10:53:40 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 0012414682FA; Wed, 28 Jun 2023 10:53:40 +0000 (UTC) Received: from localhost.localdomain (unknown [10.43.2.36]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9C35D140EBB8 for ; Wed, 28 Jun 2023 10:53:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1687949633; h=from:from:sender:sender: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:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=beftYfidEYq8kg9D1ccmPeY68+HdLmvOloUWJUEj4UA=; b=UbNPX0FSaZShUW2jSgIs/sEYr5XK7qazPJipsMJnGD+vtwet9Au6Xw+iiROLIFWxMgyOxF DbgvCuPeuNStHIvOTlGFIc8Pey7Z05VjANz8NoIGjxNX4pHiQhcy8EbTkA98cio02NTGPO F2Rm0wnZYacCliy2814h84vX84Uk9mc= X-MC-Unique: Dt_FwhTEOt-drOQJpeDC3g-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 1/3] qemu: Reflect MAC address change in live domain XML Date: Wed, 28 Jun 2023 12:53:35 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1687949637047100001 Content-Type: text/plain; charset="utf-8"; x-default="true" 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. NB, we should relay this event to clients, but that is covered in next commits. Signed-off-by: Michal Privoznik --- src/qemu/qemu_domain.c | 18 ++++++++++++++++++ src/qemu/qemu_driver.c | 2 +- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 94587638c3..5e5789a28c 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -12482,6 +12482,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, @@ -12535,6 +12548,11 @@ qemuDomainSyncRxFilter(virDomainObj *vm, return -1; } =20 + /* Reflect changed MAC address in the domain XML. */ + if (virMacAddrCmp(&def->mac, &guestFilter->mac)) { + virMacAddrSet(&def->mac, &guestFilter->mac); + } + return 0; } =20 diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index f20544590d..ccf653d201 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -3712,7 +3712,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.39.3 From nobody Sat May 18 03:15:25 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 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=1687949639; cv=none; d=zohomail.com; s=zohoarc; b=ggGl0A2wEX3xLOYi/pd2JHcuyQ+lxJwUqtd9FxupVPuTgdl0SY/PRM2oP/XgsQCy+aVzms3c/UAy64lvi1Bj4L9EcqC9wyHXTbmUvRu2UVWvRWe8SbVrQA9jwKseJ+JFjFaqWg7zDaPzC/Esssv4VHbclus557rPn0SKRDmwPWQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1687949639; 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; bh=nLYkyi6lE7tz2RPOtvAWujcpFq0HqXhnSpdXMCvL1Aw=; b=TgvL8NksPXAqypG0pNpZKwDHXvLczEKR5MjZHhs5Ew2RPpxWCF8UYaMCZ3Yj0jylpYutoaiG1+PzsUz9DqlakOl5Jr2DczfpSsxcyrjaG3FRR/3eMk6c/xJLNTe7zneSNz8Y8RyMxfszaca/Ow0cvYjhlQl2udKC7DtCBZlJmpk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1687949639490656.7998654518975; Wed, 28 Jun 2023 03:53:59 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-440-3xYbdojLO22YLIv48gZ_pA-1; Wed, 28 Jun 2023 06:53:54 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id DFC3A296A60F; Wed, 28 Jun 2023 10:53:51 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id C7385111F3B0; Wed, 28 Jun 2023 10:53:51 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 20C8A1946589; Wed, 28 Jun 2023 10:53:47 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id CE9B31946A7E for ; Wed, 28 Jun 2023 10:53:45 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id AA97F140EBB8; Wed, 28 Jun 2023 10:53:40 +0000 (UTC) Received: from localhost.localdomain (unknown [10.43.2.36]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3702E14682FC for ; Wed, 28 Jun 2023 10:53:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1687949638; h=from:from:sender:sender: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:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=nLYkyi6lE7tz2RPOtvAWujcpFq0HqXhnSpdXMCvL1Aw=; b=I5Di4epAyRKcZMVehWumiAFBYvD72fbXA9c/fBbAZXJAU47bwWGoPOOU8qOJ86JKiG3faZ a3t0LY4Znn+CnGFYo6tMWsU+vjXtq4iTcTKa4mzJ9OG6wjaQ2cQkpFAleBPmsGB4wbkvtk 1B7UatXxkNtXBMHp3N57s0MU25QGqR0= X-MC-Unique: 3xYbdojLO22YLIv48gZ_pA-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 2/3] Introduce NIC_MAC_CHANGE event Date: Wed, 28 Jun 2023 12:53:36 +0200 Message-Id: <412f51ed16f86d533d80b4892cdacad3bd0f530e.1687948764.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1687949641094100001 Content-Type: text/plain; charset="utf-8"; x-default="true" 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 --- 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 | 17 +++++- tools/virsh-domain-event.c | 20 +++++++ 9 files changed, 251 insertions(+), 1 deletion(-) diff --git a/examples/c/misc/event-test.c b/examples/c/misc/event-test.c index 64652b0153..1d6c47474d 100644 --- a/examples/c/misc/event-test.c +++ b/examples/c/misc/event-test.c @@ -1065,6 +1065,19 @@ myDomainEventMetadataChangeCallback(virConnectPtr co= nn 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) @@ -1123,6 +1136,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 a1902546bb..d39f2d2395 100644 --- a/include/libvirt/libvirt-domain.h +++ b/include/libvirt/libvirt-domain.h @@ -5756,6 +5756,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: 9.6.0 + */ +typedef void (*virConnectDomainEventNICMACChangeCallback)(virConnectPtr co= nn, + virDom= ainPtr dom, + const = char *alias, + const = char *oldMAC, + const = char *newMAC, + void *= opaque); + /** * VIR_DOMAIN_EVENT_CALLBACK: * @@ -5804,6 +5831,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: 9.6.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 75603a933a..4d544f2d2f 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, @@ -1734,6 +1757,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, @@ -2042,6 +2121,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 fb7ad9c855..d5e9f321b9 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -754,6 +754,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 7144e9e7ca..f347e7bcce 100644 --- a/src/remote/remote_daemon_dispatch.c +++ b/src/remote/remote_daemon_dispatch.c @@ -1357,6 +1357,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), @@ -1385,6 +1416,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 65ec239fb7..43f61321dc 100644 --- a/src/remote/remote_driver.c +++ b/src/remote/remote_driver.c @@ -427,6 +427,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, @@ -641,6 +646,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 @@ -5198,6 +5207,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 5d86a51116..af19846668 100644 --- a/src/remote/remote_protocol.x +++ b/src/remote/remote_protocol.x @@ -3935,6 +3935,15 @@ struct remote_domain_fd_associate_args { remote_nonnull_string name; unsigned int flags; }; + +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.= */ @@ -6974,5 +6983,11 @@ enum remote_procedure { * @generate: none * @acl: domain:write */ - REMOTE_PROC_DOMAIN_FD_ASSOCIATE =3D 443 + REMOTE_PROC_DOMAIN_FD_ASSOCIATE =3D 443, + + /** + * @generate: both + * @acl: none + */ + REMOTE_PROC_DOMAIN_EVENT_NIC_MAC_CHANGE =3D 444 }; diff --git a/tools/virsh-domain-event.c b/tools/virsh-domain-event.c index 2969c22a91..2467fa00a8 100644 --- a/tools/virsh-domain-event.c +++ b/tools/virsh-domain-event.c @@ -788,6 +788,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), }, @@ -841,6 +859,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.39.3 From nobody Sat May 18 03:15:25 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 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=1687949637; cv=none; d=zohomail.com; s=zohoarc; b=a3KHdGiQidy6JDQwXLZdzjZXGHmVugTesXTIfW3KeI6FDVyjn7bT7aHiGQy8QGTW1jd3EZQz/l9Gwm6WCy4RkpkJq3QmAN1ehqJUJ91ieecKjrgeta8gBQLweK8ANG9aQNdXpH2V0ouWo4YqJeInIXRcgA+MlYw7A+w6HV/5o+4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1687949637; 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; bh=2Mwe+3bNemP1+WbGAgSTfVfpyfel+mUlSk/kMO//D/k=; b=hPaSGr7pgH51R3gxyAs6AvcVKmYqqOaNawNkgy72cLxHvEUDvWlXdeLbMym7hSWcnE/ztpBywjR5UlWDZ1ILYunt5r3IHbMxvMOmaI9wSdKQGiMsw9qokpaZ+RkTUxTZBZkwG0hH5OOkiO0mbRDueM9fs4oWT0zQaZxuorex+Ws= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1687949637346445.6958291441198; Wed, 28 Jun 2023 03:53:57 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-286-zKVukHvSPjqFRAp-aCTADw-1; Wed, 28 Jun 2023 06:53:54 -0400 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id AC015296A60A; Wed, 28 Jun 2023 10:53:51 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9126848FB03; Wed, 28 Jun 2023 10:53:51 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 552B41946A70; Wed, 28 Jun 2023 10:53:43 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 57BFB1946A6F for ; Wed, 28 Jun 2023 10:53:41 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 458E314682FB; Wed, 28 Jun 2023 10:53:41 +0000 (UTC) Received: from localhost.localdomain (unknown [10.43.2.36]) by smtp.corp.redhat.com (Postfix) with ESMTP id E104114682FA for ; Wed, 28 Jun 2023 10:53:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1687949636; h=from:from:sender:sender: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:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=2Mwe+3bNemP1+WbGAgSTfVfpyfel+mUlSk/kMO//D/k=; b=NLmhj7cLc9jj4nOxsbdBta/J2DoZYWINIXHAFfW1Qjwk0ftbAOHwA6E8KIatSTubvbQLd9 NfeGNICSUHMkpW0h/mIm5t9KaDHJX5q/a6eCTc75rTNyjPWTjGJH3QN8N0GOwcutHRbI2i ZdpNK+0Q8xavRWyJdxxyJl8fea6Qnjo= X-MC-Unique: zKVukHvSPjqFRAp-aCTADw-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 3/3] qemu: Emit NIC_MAC_CHANGE event Date: Wed, 28 Jun 2023 12:53:37 +0200 Message-Id: <013584099828319285c6771bdb292d85439acbbd.1687948764.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1687949638498100003 Content-Type: text/plain; charset="utf-8"; x-default="true" 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://bugzilla.redhat.com/show_bug.cgi?id=3D2025303 Signed-off-by: Michal Privoznik --- 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 5e5789a28c..51e5db6631 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -12498,7 +12498,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; @@ -12550,6 +12551,19 @@ qemuDomainSyncRxFilter(virDomainObj *vm, =20 /* Reflect changed MAC address in the domain XML. */ if (virMacAddrCmp(&def->mac, &guestFilter->mac)) { + if (event) { + char oldMAC[VIR_MAC_STRING_BUFLEN] =3D { 0 }; + char newMAC[VIR_MAC_STRING_BUFLEN] =3D { 0 }; + + virMacAddrFormat(&def->mac, oldMAC); + virMacAddrFormat(&guestFilter->mac, newMAC); + + *event =3D virDomainEventNICMACChangeNewFromObj(vm, + def->info.alias, + oldMAC, + newMAC); + } + virMacAddrSet(&def->mac, &guestFilter->mac); } =20 diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h index 999190e381..3021208c4c 100644 --- a/src/qemu/qemu_domain.h +++ b/src/qemu/qemu_domain.h @@ -1127,7 +1127,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 ccf653d201..f713bff6ab 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -3702,9 +3702,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 @@ -3749,11 +3751,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 @@ -4054,7 +4057,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 db06991450..61c1a75639 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -7925,7 +7925,7 @@ qemuProcessRefreshRxFilters(virDomainObj *vm, if (!virDomainNetGetActualTrustGuestRxFilters(def)) continue; =20 - if (qemuDomainSyncRxFilter(vm, def, asyncJob) < 0) + if (qemuDomainSyncRxFilter(vm, def, asyncJob, NULL) < 0) return -1; } =20 --=20 2.39.3