From nobody Tue Mar 3 03:04:10 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=1770908738; cv=none; d=zohomail.com; s=zohoarc; b=jpyxf/7yq5fcqfRV3Vxhx8JjPibcp8cCmvx/YHRgI2HF1hfr+nlNudUTA5EGC7BRMPGXxNxVPHDhEcoLENSWHoIudv2eVl4TpTBV+2Qrkz/XVh1h4GETYg5cpx+OloQJclUpoC5cr0Srf0nU8fkALDe2gMJ4dYnmnr7QVszX9wg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1770908738; 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=ON5+tKs/U2uJ0aEfUSGd7/g5fSe85Qen/puVHsRAycs=; b=T2i0ll8Tn1mm+6nHuQaKSdyuftDVlqCVRPQyEYNTrtRq+P2WN8YLD1BgOvXYgIdrGdTAJaAl8YhyrNYNtL3pveFRdokIzS9hmBgn1i4rWIeEqulTcS/VJwxuFbtFbtRWtVFXVP8z4DPIWjV/kx7fwzsNRK1DZYtQXJDQJTyfP88= 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 1770908738376620.6469044543319; Thu, 12 Feb 2026 07:05:38 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 993) id C3C453F292; Thu, 12 Feb 2026 10:05:37 -0500 (EST) Received: from [172.19.199.6] (lists.libvirt.org [8.43.85.245]) by lists.libvirt.org (Postfix) with ESMTP id CE89045000; Thu, 12 Feb 2026 09:58:57 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 993) id 714A241AE4; Thu, 12 Feb 2026 09:58:51 -0500 (EST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.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 774C744427 for ; Thu, 12 Feb 2026 08:53:05 -0500 (EST) 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-553-SPE5LwHNM2-GUdAuHahxVw-1; Thu, 12 Feb 2026 08:53:03 -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-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 0A0321955F14 for ; Thu, 12 Feb 2026 13:53:03 +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 614FD180035A for ; Thu, 12 Feb 2026 13:53:02 +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=1770904385; 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=ON5+tKs/U2uJ0aEfUSGd7/g5fSe85Qen/puVHsRAycs=; b=eECGax2GkF2/7Or5Y+OzNWmD4rOy2DXiVhqZxHrV6OI9MEVlkiQUL3nzewQ4OpPrOBoL54 3NTV25FoapVYD5ixL2LJ8zbH+AEJfvkX1GdeBW0uyBInU/ICs8yqJlqDpo7bvy3kp/WNpX wqwaDTzF8qBlMyQO5xnnUYjdWH6KIz8= X-MC-Unique: SPE5LwHNM2-GUdAuHahxVw-1 X-Mimecast-MFC-AGG-ID: SPE5LwHNM2-GUdAuHahxVw_1770904383 To: devel@lists.libvirt.org Subject: [PATCH v2 1/4] datatypes: Declare autofree func for virDomainInterface type Date: Thu, 12 Feb 2026 14:52:55 +0100 Message-ID: <7821550732c40ce40c30837e97031fa65b511878.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: TyHQXiMymZgb8WEtAdMB3USMY_tXEeQCcHpU6e20HXU_1770904383 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: RYYVMTMQHMAH3THQL3HL4VQGN3O5QYSR X-Message-ID-Hash: RYYVMTMQHMAH3THQL3HL4VQGN3O5QYSR 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: 1770908740957154100 Content-Type: text/plain; charset="utf-8"; x-default="true" From: Michal Privoznik The virDomainInterface type (struct _virDomainInterface) is defined in our public header and even has a public free function (virDomainInterfaceFree()). But in our code we will want to use automatic memory freeing for it. Hence, make appropriate declaration in datatypes.h. Signed-off-by: Michal Privoznik Reviewed-by: Peter Krempa --- src/datatypes.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/datatypes.h b/src/datatypes.h index c5a7ece786..5d543847e9 100644 --- a/src/datatypes.h +++ b/src/datatypes.h @@ -804,6 +804,8 @@ struct _virNWFilterBinding { =20 G_DEFINE_AUTOPTR_CLEANUP_FUNC(virNWFilterBinding, virObjectUnref); =20 +/* virDomainInterface is defined in the public API - libvirt-domain.h */ +G_DEFINE_AUTOPTR_CLEANUP_FUNC(virDomainInterface, virDomainInterfaceFree); =20 /* * Helper APIs for allocating new object instances --=20 2.52.0 From nobody Tue Mar 3 03:04:10 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=1770908815; cv=none; d=zohomail.com; s=zohoarc; b=mI7d3zKesqYl00Fw9rfbRVA8JhOVui1AckgTglfL4RQe39kSlVQzR532wcvYXOc6brgKToszIPNcAs2hDF0maf9/n3h1/P0wOQRCmmjdvJz9aLJPxfDs4MlqkDnhrPXzN2/C7kFg8qNNKH17/cr/5pjgHQz1T3KMd6wrgEIKITQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1770908815; 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=1ihP6FVgXxzCU6efVrzpf93yrBgRAlvJ3Wxf1avWq4A=; b=Itan3JymwoBSIzM/qG0EE3qSIaihJ1aLrXrff38X30tTkeR60qYmES4LD9l8hYSGzG8CSFFqnAMPNenp60HCoSAf0xPB863bpeojREiP0htXtqNaYKvfKGYzsyUrrxlzHeeTi6Rp0ssoDvG/g0uCMuVOEKaZqSKcApRf3VYDDsw= 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 1770908815636194.0865100832658; Thu, 12 Feb 2026 07:06:55 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 993) id 692D244B40; Thu, 12 Feb 2026 10:06:54 -0500 (EST) Received: from [172.19.199.6] (lists.libvirt.org [8.43.85.245]) by lists.libvirt.org (Postfix) with ESMTP id 821E1450B2; Thu, 12 Feb 2026 09:59:01 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 993) id 3AFC344362; Thu, 12 Feb 2026 09:58:52 -0500 (EST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.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 7D68F44D24 for ; Thu, 12 Feb 2026 08:53:06 -0500 (EST) 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-563-VTMijp5JNfObXRUSwXgiGA-1; Thu, 12 Feb 2026 08:53:04 -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-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 09E081800366 for ; Thu, 12 Feb 2026 13:53:04 +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 6BF82180066A for ; Thu, 12 Feb 2026 13:53:03 +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=1770904386; 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=1ihP6FVgXxzCU6efVrzpf93yrBgRAlvJ3Wxf1avWq4A=; b=iFQ90fFpkutURCxPcgJd2AdMmDqiVWgWHbLnyUWLiJsorFdJ1NRz2FaZYfFullzxJE5t5/ umceX/vnp8wZUUaG1VgmkQZ9b6jMLeth1nwcPjXaMxbtrjhZ1MXWJcgsCwxN7K49Fwbrow XER4Fe2G4dV435dvj0AcEs/Lg3xykDk= X-MC-Unique: VTMijp5JNfObXRUSwXgiGA-1 X-Mimecast-MFC-AGG-ID: VTMijp5JNfObXRUSwXgiGA_1770904384 To: devel@lists.libvirt.org Subject: [PATCH v2 2/4] virsocketaddr: Introduce virSocketAddrSubnetToPrefix() Date: Thu, 12 Feb 2026 14:52:56 +0100 Message-ID: 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: OKXCfazLcgzkb4tw8-QgX4Q64Q-DHPr5d5_s-8E8GnA_1770904384 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: ZTTQW2NFKEHDAIMDBAM4OZWWWEM3DTSO X-Message-ID-Hash: ZTTQW2NFKEHDAIMDBAM4OZWWWEM3DTSO 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: 1770908817856158500 Content-Type: text/plain; charset="utf-8"; x-default="true" From: Michal Privoznik The aim of this helper is to convert subnet mask to prefix. For instance for input "255.0.0.0" to return 8. Additionally, if the input string is already a prefix (with optional leading slash character) just return that number parsed. Signed-off-by: Michal Privoznik Reviewed-by: Peter Krempa --- src/libvirt_private.syms | 1 + src/util/virsocketaddr.c | 53 ++++++++++++++++++++++++++++++++++++++++ src/util/virsocketaddr.h | 2 ++ tests/sockettest.c | 33 +++++++++++++++++++++++++ 4 files changed, 89 insertions(+) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index d81b30f0b6..035eccf70a 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -3461,6 +3461,7 @@ virSocketAddrSetIPv4AddrNetOrder; virSocketAddrSetIPv6Addr; virSocketAddrSetIPv6AddrNetOrder; virSocketAddrSetPort; +virSocketAddrSubnetToPrefix; =20 =20 # util/virstoragefile.h diff --git a/src/util/virsocketaddr.c b/src/util/virsocketaddr.c index 1f203fb50d..25dad516f6 100644 --- a/src/util/virsocketaddr.c +++ b/src/util/virsocketaddr.c @@ -21,6 +21,7 @@ #include "virsocketaddr.h" #include "virerror.h" #include "virbuffer.h" +#include "virstring.h" =20 #define VIR_FROM_THIS VIR_FROM_NONE =20 @@ -1263,6 +1264,58 @@ virSocketAddrNumericFamily(const char *address) return family; } =20 +/** + * virSocketAddrSubnetToPrefix: + * @subnet: address to convert + * + * Converts subnet mask to prefix. If @subnet is of an IPv4 + * format (NNN.NNN.NNN.NNN) then corresponding prefix length is + * returned (i.e. number of leading bits.). If @subnet is just a + * number (optionally prefixed with '/') then the number is + * parsed and returned. There is a corner case: if @subnet is + * valid IPv4 address but not valid subnet mask then a positive + * value is returned, but obviously it is not valid prefix. + * + * Returns: prefix corresponding to @subnet, + * -1 otherwise. + */ +int +virSocketAddrSubnetToPrefix(const char *subnet) +{ + struct addrinfo *ai =3D NULL; + unsigned int prefix =3D 0; + struct sockaddr_in in; + int ret =3D -1; + + if (*subnet =3D=3D '/') { + /* /NN format */ + if (virStrToLong_ui(subnet + 1, NULL, 10, &prefix) < 0) + return -1; + return prefix; + } + + if (virStrToLong_ui(subnet, NULL, 10, &prefix) >=3D 0) { + /* plain NN format */ + return prefix; + } + + if (virSocketAddrParseInternal(&ai, subnet, AF_INET, AI_NUMERICHOST, f= alse) < 0) + return -1; + + if (ai->ai_family !=3D AF_INET) { + /* huh? */ + goto cleanup; + } + + memcpy(&in, ai->ai_addr, sizeof(in)); + prefix =3D __builtin_popcount(in.sin_addr.s_addr); + + ret =3D prefix; + cleanup: + freeaddrinfo(ai); + return ret; +} + /** * virSocketAddrIsNumericLocalhost: * @address: address to check diff --git a/src/util/virsocketaddr.h b/src/util/virsocketaddr.h index c7ad3250e0..dc6373793b 100644 --- a/src/util/virsocketaddr.h +++ b/src/util/virsocketaddr.h @@ -135,6 +135,8 @@ bool virSocketAddrIsWildcard(const virSocketAddr *addr); =20 int virSocketAddrNumericFamily(const char *address); =20 +int virSocketAddrSubnetToPrefix(const char *subnet); + bool virSocketAddrIsNumericLocalhost(const char *addr); =20 int virSocketAddrPTRDomain(const virSocketAddr *addr, diff --git a/tests/sockettest.c b/tests/sockettest.c index 5cb8a9fb72..a8621a2234 100644 --- a/tests/sockettest.c +++ b/tests/sockettest.c @@ -257,6 +257,25 @@ testIsLocalhostHelper(const void *opaque) return 0; } =20 +struct testSubnetToPrefixData { + const char *addr; + int prefix; +}; + +static int +testSubnetToPrefixHelper(const void *opaque) +{ + const struct testSubnetToPrefixData *data =3D opaque; + int val =3D virSocketAddrSubnetToPrefix(data->addr); + + if (val !=3D data->prefix) { + fprintf(stderr, "actual: '%d', expected: '%d'", val, data->prefix); + return -1; + } + + return 0; +} + static int mymain(void) { @@ -352,6 +371,14 @@ mymain(void) ret =3D -1; \ } while (0) =20 +#define DO_TEST_SUBNET_TO_PREFIX(addr, prefix) \ + do { \ + struct testSubnetToPrefixData data =3D { addr, prefix }; \ + if (virTestRun("Test subnet to prefix " addr, \ + testSubnetToPrefixHelper, &data) < 0) \ + ret =3D -1; \ + } while (0) + DO_TEST_PARSE_AND_FORMAT("127.0.0.1", AF_UNSPEC, true); DO_TEST_PARSE_AND_FORMAT("127.0.0.1", AF_INET, true); DO_TEST_PARSE_AND_FORMAT("127.0.0.1", AF_INET6, false); @@ -476,6 +503,12 @@ mymain(void) DO_TEST_LOCALHOST("hello", false); DO_TEST_LOCALHOST("fe80::1:1", false); =20 + DO_TEST_SUBNET_TO_PREFIX("0.0.0.0", 0); + DO_TEST_SUBNET_TO_PREFIX("255.0.0.0", 8); + DO_TEST_SUBNET_TO_PREFIX("255.255.255.254", 31); + DO_TEST_SUBNET_TO_PREFIX("64", 64); + DO_TEST_SUBNET_TO_PREFIX("/64", 64); + return ret =3D=3D 0 ? EXIT_SUCCESS : EXIT_FAILURE; } =20 --=20 2.52.0 From nobody Tue Mar 3 03:04:10 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=1770908895; cv=none; d=zohomail.com; s=zohoarc; b=HDKfs4mBG+hnqoGio5duB/QivRLO2aD0khB2hvvu8bC8vYrLxWv4PAVg2uxYow6yONyW2pTZhnTAtL2nFVASTowzMse06XJX2yD6CMQ88sgu8QWxvLP9rJirVuRUtM/XGUriJdeZH3HJ6JgbFThjXVTBOxs2N0zDeKKFCUlKWdU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1770908895; 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=1c9yyLDCOvIakn4S4AYNVJ6srzUMylQPy15eN5IH9zY=; b=lw9GNU3dRqXNHeiUKCvGTWXhVpZbc5rQtLyaH9IBuecIG1/Nh4ss8uNe+Z6a8zvrTkxLpT76EKiIfuBqxa9Z7WAHSuAwfs+FsuPHOelk091SrE+3CviSZgiDz9sfh5YjOApd3BYG/sLM70WH2+f9bAn1jddo6NQIPVclucZeBVM= 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 177090889579167.16688818440298; Thu, 12 Feb 2026 07:08:15 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 993) id 681F54448D; Thu, 12 Feb 2026 10:08:15 -0500 (EST) Received: from [172.19.199.6] (lists.libvirt.org [8.43.85.245]) by lists.libvirt.org (Postfix) with ESMTP id D9BFC450EA; Thu, 12 Feb 2026 09:59:02 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 993) id 1A22A41AE4; Thu, 12 Feb 2026 09:58:52 -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 B5508442FC for ; Thu, 12 Feb 2026 08:53:07 -0500 (EST) 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-WRAo3Vm6NcWLwDzNwwVm5Q-1; Thu, 12 Feb 2026 08:53:05 -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-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 1BD191956052 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 64CD9180035A for ; Thu, 12 Feb 2026 13:53:04 +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=1c9yyLDCOvIakn4S4AYNVJ6srzUMylQPy15eN5IH9zY=; b=Kc+StWQspnS28QQeA89lBlUZ8A5vM6rmZDavVXTiPfVmoDN1WcsSLP5oYN+OxFf7HRudlu usC63cIEsPIzpBywssbkJvYFecbcaSTE4tUCVEedFfi04QHS3AJRU7GSxr+dVLU/oquNcw VkJuktYVEALT+dn2gAhvMb4wd17QWV4= X-MC-Unique: WRAo3Vm6NcWLwDzNwwVm5Q-1 X-Mimecast-MFC-AGG-ID: WRAo3Vm6NcWLwDzNwwVm5Q_1770904385 To: devel@lists.libvirt.org Subject: [PATCH v2 3/4] hyperv: Move MAC parsing into a separate function Date: Thu, 12 Feb 2026 14:52:57 +0100 Message-ID: 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: UuqehofmZF4dqfxzaUIUYj8TftSNCrfRzD9XDo-mTVM_1770904385 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: CS2QCNNMBXP2FLXDR3HED3ENMYMYCXSI X-Message-ID-Hash: CS2QCNNMBXP2FLXDR3HED3ENMYMYCXSI 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: 1770908898126158500 Content-Type: text/plain; charset="utf-8"; x-default="true" From: Michal Privoznik When constructing a domain definition, NICs are fetched from WMI and their MAC addresses are then parsed. Move this code into a separate function so that it can be reused later. Signed-off-by: Michal Privoznik Reviewed-by: Peter Krempa --- src/hyperv/hyperv_driver.c | 59 ++++++++++++++++++++++---------------- 1 file changed, 34 insertions(+), 25 deletions(-) diff --git a/src/hyperv/hyperv_driver.c b/src/hyperv/hyperv_driver.c index 203bbeb8a5..f295cc4b8f 100644 --- a/src/hyperv/hyperv_driver.c +++ b/src/hyperv/hyperv_driver.c @@ -1551,18 +1551,48 @@ hypervDomainDefParseSerial(virDomainDef *def, Msvm_= ResourceAllocationSettingData } =20 =20 +static int +hypervDomainDefParseEthernetAdapterMAC(hypervPrivate *priv, + Msvm_EthernetPortAllocationSettingD= ata *net, + virMacAddr *mac) +{ + g_autoptr(Msvm_SyntheticEthernetPortSettingData) sepsd =3D NULL; + char *sepsdPATH =3D NULL; + g_autofree char *sepsdEscaped =3D NULL; + g_auto(virBuffer) query =3D VIR_BUFFER_INITIALIZER; + + sepsdPATH =3D net->data->Parent; + sepsdEscaped =3D virStringReplace(sepsdPATH, "\\", "\\\\"); + virBufferAsprintf(&query, + MSVM_SYNTHETICETHERNETPORTSETTINGDATA_WQL_SELECT "WH= ERE __PATH =3D '%s'", + sepsdEscaped); + + if (hypervGetWmiClass(Msvm_SyntheticEthernetPortSettingData, &sepsd) <= 0) + return -1; + + if (!sepsd) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Could not retrieve= NIC settings")); + return -1; + } + + /* set mac address */ + if (virMacAddrParseHex(sepsd->data->Address, mac) < 0) + return -1; + + return 0; +} + + static int hypervDomainDefParseEthernetAdapter(virDomainDef *def, Msvm_EthernetPortAllocationSettingData= *net, hypervPrivate *priv) { g_autoptr(virDomainNetDef) ndef =3D g_new0(virDomainNetDef, 1); - g_autoptr(Msvm_SyntheticEthernetPortSettingData) sepsd =3D NULL; g_autoptr(Msvm_VirtualEthernetSwitch) vSwitch =3D NULL; char **switchConnection =3D NULL; g_autofree char *switchConnectionEscaped =3D NULL; - char *sepsdPATH =3D NULL; - g_autofree char *sepsdEscaped =3D NULL; + g_autofree char *sepsdInstanceIDEscaped =3D NULL; g_auto(virBuffer) query =3D VIR_BUFFER_INITIALIZER; =20 VIR_DEBUG("Parsing ethernet adapter '%s'", net->data->InstanceID); @@ -1581,28 +1611,7 @@ hypervDomainDefParseEthernetAdapter(virDomainDef *de= f, return 0; } =20 - /* - * Now we retrieve the associated Msvm_SyntheticEthernetPortSettingDat= a and - * Msvm_VirtualEthernetSwitch objects and use them to build the XML de= finition. - */ - - /* begin by getting the Msvm_SyntheticEthernetPortSettingData object */ - sepsdPATH =3D net->data->Parent; - sepsdEscaped =3D virStringReplace(sepsdPATH, "\\", "\\\\"); - virBufferAsprintf(&query, - MSVM_SYNTHETICETHERNETPORTSETTINGDATA_WQL_SELECT "WH= ERE __PATH =3D '%s'", - sepsdEscaped); - - if (hypervGetWmiClass(Msvm_SyntheticEthernetPortSettingData, &sepsd) <= 0) - return -1; - - if (!sepsd) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Could not retrieve= NIC settings")); - return -1; - } - - /* set mac address */ - if (virMacAddrParseHex(sepsd->data->Address, &ndef->mac) < 0) + if (hypervDomainDefParseEthernetAdapterMAC(priv, net, &ndef->mac) < 0) return -1; =20 /* now we get the Msvm_VirtualEthernetSwitch */ --=20 2.52.0 From nobody Tue Mar 3 03:04:10 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 Reviewed-by: Peter Krempa --- 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