From nobody Mon Feb 9 00:30:34 2026 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=1770386225; cv=none; d=zohomail.com; s=zohoarc; b=fyxm7yftTcFfCGKxVUtDAryIainirJ8KTRGxcNDX41B+0YnCjfAUd5xMY3QFBnmG3HWPxIfVIdftbWgd/vyhniwRfT8leX0nAmE7/GIcpWwft00x3FTtxeYMs8kUNT/NACh/YWIU1u93Aarscdmai1rb46nJ0V17OtZu6g+kCaQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1770386225; h=Content-Type:Content-Transfer-Encoding:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Owner: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=nS0FSPKBP69a1nxhOi7P3Vm6u9ZFyAcid1cSI+XcJZc=; b=KYFVTZ5RP6S1Zs7LyVScZCLABgoGvSWZKFm6Pe8SGXxK8WdNIMp9D5IqIKtTeksuV+bh8GsDujDqs1RQvs1VZW/yYd7aFbjdsr9rl3881MLd3/x+ALpuMp66QKiOdq5yj+9kwuHQ3bgyRt9SkULTm8M+1QUGICwChucrizwg9Kc= 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 1770386225401690.2705006451326; Fri, 6 Feb 2026 05:57:05 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 993) id E115E3FCA7; Fri, 6 Feb 2026 08:57:04 -0500 (EST) Received: from [172.19.199.6] (lists.libvirt.org [8.43.85.245]) by lists.libvirt.org (Postfix) with ESMTP id 4A40143E59; Fri, 6 Feb 2026 08:53:04 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 993) id B1A273FBC9; Fri, 6 Feb 2026 08:52:58 -0500 (EST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (3072 bits) server-digest SHA256) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id EE7EE4181F for ; Fri, 6 Feb 2026 08:52:47 -0500 (EST) Received: from mx-prod-mc-08.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-672-v51nykMVOX-w6S-_uVPF0g-1; Fri, 06 Feb 2026 08:52:46 -0500 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (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-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 2F1EB18003F6 for ; Fri, 6 Feb 2026 13:52:45 +0000 (UTC) Received: from moe (unknown [10.43.3.236]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 8F3D21800465 for ; Fri, 6 Feb 2026 13:52:44 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED,SPF_PASS autolearn=unavailable autolearn_force=no version=4.0.1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1770385967; 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=nS0FSPKBP69a1nxhOi7P3Vm6u9ZFyAcid1cSI+XcJZc=; b=BDydoEK/KIW+v+GZ8g5K466DDeeWIvsCvStoDMCqW4gZiitVhm9j0eNtrgn/CnNby9gXE4 v5vmiTKrhBbE1G/B1fkcwneXixfcxz1ou1jkOU6eL2ZukcFkNA62oaMukfzrrbm6GSM7uf Dj/Y13qXWEgh1lG9GNNPIrcY7lfygco= X-MC-Unique: v51nykMVOX-w6S-_uVPF0g-1 X-Mimecast-MFC-AGG-ID: v51nykMVOX-w6S-_uVPF0g_1770385965 To: devel@lists.libvirt.org Subject: [PATCH 4/4] hyperv: Implement virDomainInterfaceAddresses() Date: Fri, 6 Feb 2026 14:52:37 +0100 Message-ID: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: LZVlXJ4sUneCYODBCIZydEQZtGVpMyjS92rzDBsXvrA_1770385965 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: TGTNVWK3GP2X7FIE3R75P4IVKQN7V7FK X-Message-ID-Hash: TGTNVWK3GP2X7FIE3R75P4IVKQN7V7FK X-MailFrom: mprivozn@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; header-match-devel.lists.libvirt.org-0; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Owner: 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: 1770386229449154100 Content-Type: text/plain; charset="utf-8"; x-default="true" From: Michal Privoznik The virDomainInterfaceAddresses() API accepts @source argument, but since this is hyperv, we can't really use _SRC_LEASE (we didn't spawn any dnsmasq there), not _SRC_ARP. The only source that's more or less usable is _SRC_AGENT. Okay, there's no QEMU guest agent running, but hyperv has its own guest agent. In my testing (with Linux guest) I had to install 'hyperv' package and then enable 'hv_kvp_daemon.service'. After that, Msvm_GuestNetworkAdapterConfiguration struct [1] contained guest IP addresses. There's one caveat though: the interface name (virDomainInterface::name). We don't fetch that one even for hypervDomainGetXMLDesc() case. And there's no either nor device alias (v12.0.0-43-g4009126f17). So just put InstanceID there for now, which is this long path, with some UUIDs, e.g.: Microsoft:5C58E5F2-946E-490F-B81D-6E2A7328640D\C85554E0-2B3B-487C-A557-D= 230BFF5F9E6\ But hey, at least it's unique. 1: https://learn.microsoft.com/en-us/windows/win32/hyperv_v2/msvm-guestnetw= orkadapterconfiguration Resolves: https://issues.redhat.com/browse/RHEL-145306 Signed-off-by: Michal Privoznik --- Admittedly, the 'virsh domifaddr' output is misaligned after this, but I'll post a separate patch for that. src/hyperv/hyperv_driver.c | 169 ++++++++++++++++++++++++++ src/hyperv/hyperv_wmi_generator.input | 12 ++ 2 files changed, 181 insertions(+) diff --git a/src/hyperv/hyperv_driver.c b/src/hyperv/hyperv_driver.c index fbc76544df..c25cb91c13 100644 --- a/src/hyperv/hyperv_driver.c +++ b/src/hyperv/hyperv_driver.c @@ -3654,6 +3654,174 @@ hypervDomainSendKey(virDomainPtr domain, unsigned i= nt codeset, } =20 =20 +static int +hypervDomainInterfaceAddressesParseOne(hypervPrivate *priv, + Msvm_EthernetPortAllocationSettingD= ata *net, + virDomainInterfacePtr *oneIfaceRet) +{ + g_autoptr(virDomainInterface) iface =3D NULL; + g_autoptr(Msvm_SyntheticEthernetPortSettingData) sepsd =3D NULL; + g_autoptr(Msvm_GuestNetworkAdapterConfiguration) aConfig =3D NULL; + g_auto(virBuffer) query =3D VIR_BUFFER_INITIALIZER; + virMacAddr macAddr =3D { 0 }; + char macAddrStr[VIR_MAC_STRING_BUFLEN] =3D { 0 }; + + VIR_DEBUG("Parsing ethernet adapter '%s'", net->data->InstanceID); + + iface =3D g_new0(virDomainInterface, 1); + iface->name =3D g_strdup(net->data->InstanceID); + + if (hypervDomainDefParseEthernetAdapterMAC(priv, net, &macAddr) < 0) + return -1; + + iface->hwaddr =3D g_strdup(virMacAddrFormat(&macAddr, macAddrStr)); + + virBufferAsprintf(&query, + "ASSOCIATORS OF {%s} " + "WHERE AssocClass=3DMsvm_SettingDataComponent " + "ResultClass=3DMsvm_GuestNetworkAdapterConfiguration= ", + net->data->Parent); + + if (hypervGetWmiClass(Msvm_GuestNetworkAdapterConfiguration, &aConfig)= < 0) + return -1; + + if (aConfig) { + size_t nAddr =3D aConfig->data->IPAddresses.count; + size_t i; + + if (aConfig->data->Subnets.count !=3D nAddr) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("the number of IP addresses (%1$zu) does not = match the number of subnets (%2$d)"), + nAddr, aConfig->data->Subnets.count); + return -1; + } + + iface->addrs =3D g_new0(virDomainIPAddress, nAddr); + iface->naddrs =3D nAddr; + for (i =3D 0; i < nAddr; i++) { + const char *ipAddrStr =3D ((const char **) aConfig->data->IPAd= dresses.data)[i]; + const char *subnetAddrStr =3D ((const char **) aConfig->data->= Subnets.data)[i]; + virDomainIPAddressPtr ip =3D &iface->addrs[i]; + int family; + int prefix; + + VIR_DEBUG("ipAddrStr=3D'%s' subnetAddrStr=3D'%s'", + ipAddrStr, subnetAddrStr); + + ip->addr =3D g_strdup(ipAddrStr); + family =3D virSocketAddrNumericFamily(ipAddrStr); + if (family =3D=3D AF_INET6) { + ip->type =3D VIR_IP_ADDR_TYPE_IPV6; + } else if (family =3D=3D AF_INET) { + ip->type =3D VIR_IP_ADDR_TYPE_IPV4; + } else { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("unknown IP address family of '%1$s'"), + ipAddrStr); + return -1; + } + + prefix =3D virSocketAddrSubnetToPrefix(subnetAddrStr); + if (prefix < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("unexpected subnet mask '%1$s'"), + subnetAddrStr); + return -1; + } + ip->prefix =3D prefix; + } + } + + *oneIfaceRet =3D g_steal_pointer(&iface); + return 0; +} + + +static ssize_t +hypervDomainInterfaceAddressesParseList(hypervPrivate *priv, + Msvm_EthernetPortAllocationSetting= Data *nets, + virDomainInterfacePtr **ifaces) +{ + Msvm_EthernetPortAllocationSettingData *entry =3D nets; + size_t nifaces =3D 0; + + while (entry) { + virDomainInterfacePtr oneIface =3D NULL; + + if (hypervDomainInterfaceAddressesParseOne(priv, entry, &oneIface)= < 0) + return -1; + + if (oneIface) + VIR_APPEND_ELEMENT(*ifaces, nifaces, oneIface); + + entry =3D entry->next; + } + + return nifaces; +} + + +static int +hypervDomainInterfaceAddresses(virDomainPtr dom, + virDomainInterfacePtr **ifaces, + unsigned int source, + unsigned int flags) +{ + hypervPrivate *priv =3D NULL; + char uuid_string[VIR_UUID_STRING_BUFLEN]; + g_autoptr(Msvm_ComputerSystem) computerSystem =3D NULL; + g_autoptr(Msvm_VirtualSystemSettingData) virtualSystemSettingData =3D = NULL; + g_autoptr(Msvm_EthernetPortAllocationSettingData) nets =3D NULL; + virDomainInterfacePtr *ifacesRet =3D NULL; + ssize_t ifacesRetCount =3D 0; + int ret =3D -1; + + virCheckFlags(0, -1); + + if (source !=3D VIR_DOMAIN_INTERFACE_ADDRESSES_SRC_AGENT) { + virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED, + _("Unknown IP address data source %1$d"), + source); + return -1; + } + + if (hypervMsvmComputerSystemFromDomain(dom, &computerSystem) < 0) + return -1; + + priv =3D dom->conn->privateData; + virUUIDFormat(dom->uuid, uuid_string); + + if (hypervGetMsvmVirtualSystemSettingDataFromUUID(priv, + uuid_string, + &virtualSystemSettin= gData) < 0) { + return -1; + } + + if (hypervGetEthernetPortAllocationSD(priv, + virtualSystemSettingData->data->= InstanceID, + &nets) < 0) { + return -1; + } + + ifacesRetCount =3D hypervDomainInterfaceAddressesParseList(priv, nets,= &ifacesRet); + if (ifacesRetCount < 0) + goto cleanup; + + *ifaces =3D g_steal_pointer(&ifacesRet); + ret =3D ifacesRetCount; + + cleanup: + if (ret < 0) { + while (ifacesRetCount > 0) { + virDomainInterfaceFree(ifacesRet[--ifacesRetCount]); + } + VIR_FREE(ifacesRet); + } + + return ret; +} + + static virHypervisorDriver hypervHypervisorDriver =3D { .name =3D "Hyper-V", .connectOpen =3D hypervConnectOpen, /* 0.9.5 */ @@ -3717,6 +3885,7 @@ static virHypervisorDriver hypervHypervisorDriver =3D= { .domainManagedSaveRemove =3D hypervDomainManagedSaveRemove, /* 0.9.5 */ .domainSendKey =3D hypervDomainSendKey, /* 3.6.0 */ .connectIsAlive =3D hypervConnectIsAlive, /* 0.9.8 */ + .domainInterfaceAddresses =3D hypervDomainInterfaceAddresses, /* 12.1.= 0 */ }; =20 =20 diff --git a/src/hyperv/hyperv_wmi_generator.input b/src/hyperv/hyperv_wmi_= generator.input index 0b342cbfa6..e6053267f8 100644 --- a/src/hyperv/hyperv_wmi_generator.input +++ b/src/hyperv/hyperv_wmi_generator.input @@ -866,6 +866,18 @@ class Msvm_SyntheticEthernetPortSettingData end =20 =20 +class Msvm_GuestNetworkAdapterConfiguration + string InstanceID + uint16 ProtocolIFType + boolean DHCPEnabled + string IPAddresses[] + string Subnets[] + string DefaultGateways[] + string DNSServers[] + uint16 IPAddressOrigins[] +end + + class Msvm_EthernetPortAllocationSettingData string InstanceID string Caption --=20 2.52.0