From nobody Tue Mar 3 04:55:51 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=1770908983; cv=none; d=zohomail.com; s=zohoarc; b=A1UEwgxGc/Y67oVXsc9oBeAMGyP3GZLQbEwRUjaAg+gbSfu1onWTDGdOyRyO4iPnz74Xw9WczIOKyGp2HyTH6GsQZcw2kd79ORJtVzKr3ZXGsHFjRdLRy4Mg+l1qgxlGv6krOS7MK/tRXq2YBJBknZ5v+tVUtsl1T0wSDMu/zJw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1770908983; 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=jfQhFFOJsH8TsFKK3+c/JBeomdr4ka8kN+lccCc8970=; b=fp9197nG71zZmjggRZOsMtvULbfbEHRYszhUOPwdOW6+9HQ7LiGTNyWZhpLpPzd2cTGmltoCJw+ryAmT6OHOSIpCz2K2PZhPK/EpsmZnyQ6uffPM1a1dYQEprvOllSSzRrJe2vzsceQ8iwDclD4azgu2T4+mkcbLNIPQyekx5LI= 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 1770908983826669.9343782605039; Thu, 12 Feb 2026 07:09:43 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 993) id 17D8C440ED; Thu, 12 Feb 2026 10:09:43 -0500 (EST) Received: from [172.19.199.6] (lists.libvirt.org [8.43.85.245]) by lists.libvirt.org (Postfix) with ESMTP id 1C5A145205; Thu, 12 Feb 2026 09:59:05 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 993) id 6DEFB44F65; Thu, 12 Feb 2026 09:58:54 -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 3F7F243EE3 for ; Thu, 12 Feb 2026 08:53:08 -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-690-VTkZoGWhMrW7HW7MROFOfw-1; Thu, 12 Feb 2026 08:53:06 -0500 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (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 F0ACE1800464 for ; Thu, 12 Feb 2026 13:53:05 +0000 (UTC) Received: from moe (unknown [10.43.3.236]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 5D6FB180035A for ; Thu, 12 Feb 2026 13:53:05 +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=1770904387; 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=jfQhFFOJsH8TsFKK3+c/JBeomdr4ka8kN+lccCc8970=; b=dLbg4uveI02xjo7N1HAZhuqykaxr2MDAXvZmPwAZgCCKHuxo3nJrYkJSQvKDto2QC090zO H9lr02G0q/d28O3PFOs3AzqdpV+YctJGTww8dABuBLGi9i89YdNlYcHx6hoO8nvQqdK/S+ 9FmOYVMqwJsN23ihXViCX4saYRN4Mz0= X-MC-Unique: VTkZoGWhMrW7HW7MROFOfw-1 X-Mimecast-MFC-AGG-ID: VTkZoGWhMrW7HW7MROFOfw_1770904386 To: devel@lists.libvirt.org Subject: [PATCH v2 4/4] hyperv: Implement virDomainInterfaceAddresses() Date: Thu, 12 Feb 2026 14:52:58 +0100 Message-ID: <5f1bbf9dc61b3f9f0196b9e51ae9d415cc494c5f.1770904246.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: I4zNWMF_13SLZDnthZSZcEpQnec-kbzbWn6BnH2Ap4Q_1770904386 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: 4A543EFVPOFYKXXC3ZCPFII7WNDVNIGS X-Message-ID-Hash: 4A543EFVPOFYKXXC3ZCPFII7WNDVNIGS 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: 1770908986874154100 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 --- src/hyperv/hyperv_driver.c | 167 ++++++++++++++++++++++++++ src/hyperv/hyperv_wmi_generator.input | 12 ++ 2 files changed, 179 insertions(+) diff --git a/src/hyperv/hyperv_driver.c b/src/hyperv/hyperv_driver.c index f295cc4b8f..eb28093028 100644 --- a/src/hyperv/hyperv_driver.c +++ b/src/hyperv/hyperv_driver.c @@ -3655,6 +3655,172 @@ 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 **ifacesRet) +{ + Msvm_EthernetPortAllocationSettingData *entry =3D nets; + virDomainInterfacePtr *ifaces =3D NULL; + size_t nifaces =3D 0; + + while (entry) { + virDomainInterfacePtr oneIface =3D NULL; + + if (hypervDomainInterfaceAddressesParseOne(priv, entry, &oneIface)= < 0) + goto error; + + if (oneIface) + VIR_APPEND_ELEMENT(ifaces, nifaces, oneIface); + + entry =3D entry->next; + } + + *ifacesRet =3D g_steal_pointer(&ifaces); + return nifaces; + + error: + while (nifaces > 0) { + virDomainInterfaceFree(ifaces[--nifaces]); + } + VIR_FREE(ifaces); + return -1; +} + + +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; + + 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) + return -1; + + *ifaces =3D g_steal_pointer(&ifacesRet); + return ifacesRetCount; +} + + static virHypervisorDriver hypervHypervisorDriver =3D { .name =3D "Hyper-V", .connectOpen =3D hypervConnectOpen, /* 0.9.5 */ @@ -3718,6 +3884,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