From nobody Sat Feb 7 17:42:26 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=1770386022; cv=none; d=zohomail.com; s=zohoarc; b=QMOHA9Z6Y4JZzG07aRoNnGq9mFxoL5yvuWm9Hwowvm2d66KlYabgrrgBO11xUiud6KHlUxbqSPQep4tqz5gCG4UVd4GBMSf5MM7gy60vDR0QnZtOopFkODTC+Qk1PusJx1oebMu9kb1aqCBpjGmTA3JyQp7SHe/NMsOZ+nrKAeE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1770386022; 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=hzvYVSRNcAtKu4olm2Zdyvk7XcJLWoEbYUpbD6789iQ=; b=Lylm603oGbd7Nbqq/rmhF9IjaezA6R1dl7IzC4QCFXiwafOxfPAxGwlnycIDyfoPYv13ireDaRcI9xD6LiaB7ElVHUy1KkekJMylGdWx1oA+vVQOig43UAWLOK/iXv/8HvJDOpXYMe5clg9OEV2hpJWitp8/5rdJVh0CndgFgT0= 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 1770386022950379.5910360376213; Fri, 6 Feb 2026 05:53:42 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 993) id 1914E41A1D; Fri, 6 Feb 2026 08:53:42 -0500 (EST) Received: from [172.19.199.6] (lists.libvirt.org [8.43.85.245]) by lists.libvirt.org (Postfix) with ESMTP id 947FE41B1B; Fri, 6 Feb 2026 08:52:49 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 993) id 206793FC5D; Fri, 6 Feb 2026 08:52:45 -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 924283FBB5 for ; Fri, 6 Feb 2026 08:52:44 -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-55-Fus-xlbiMDKgc1GD91m4Ew-1; Fri, 06 Feb 2026 08:52:42 -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 370FE18003F6 for ; Fri, 6 Feb 2026 13:52:42 +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 8CEF018003F6 for ; Fri, 6 Feb 2026 13:52:41 +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=1770385964; 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=hzvYVSRNcAtKu4olm2Zdyvk7XcJLWoEbYUpbD6789iQ=; b=cjVRnktzZHl/UYQzDfnjewwUT4ow8fUsgb4k4PviNlSuTcOH3XL0ha2HcaCrFqOSusIl+U fbXZWMPO/nGd8Dt6X1YaUZYFDq2ShdhmjVWpE6fsCOnD/6+7cc5aCO6G+Wp/8eteVSKLNp P6mfyiQZXxUcvKU2aVU7fHfLkoXCspQ= X-MC-Unique: Fus-xlbiMDKgc1GD91m4Ew-1 X-Mimecast-MFC-AGG-ID: Fus-xlbiMDKgc1GD91m4Ew_1770385962 To: devel@lists.libvirt.org Subject: [PATCH 1/4] datatypes: Declare autofree func for virDomainInterface type Date: Fri, 6 Feb 2026 14:52:34 +0100 Message-ID: <0a55b25c7647f4a90460dba5b2cc040b48e351a2.1770385874.git.mprivozn@redhat.com> 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: 9X18SkfwoJ2Ms213rP_PeWG9jt5iCP9ZUfPeQUvTCGY_1770385962 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: KNWJJSL6EP5GIWFXNAAIYW4LOVUPSYOE X-Message-ID-Hash: KNWJJSL6EP5GIWFXNAAIYW4LOVUPSYOE 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: 1770386023136158500 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 --- 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 Sat Feb 7 17:42:26 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=1770386125; cv=none; d=zohomail.com; s=zohoarc; b=JDvuc7HbPdWYqZjcySpAD7RymWmzG/4pZfZn3B+mKue49bngh0OeHpu8ZP37HyHZ9ufiR/toVRVtgED+4hGii/KlNZwc4NcVfmmyF8b6FSsJUbVz855CJQqPOq/ZY1K/R820t96RrGtUmPOF2Hy2YV4n9GCJCi0QRIApUTS5m8w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1770386125; 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=7QMySzdfnhB3aR2dqTdsgp1W/UkEuJbLukzaageWjfM=; b=Ry0gfWUDreBTXdNCSrvNN9CEXra5nnFZA0tjVjzkB+izFkHVinFBHabTsnH1EeIFC9i9i823Pw4BOBblINfisD5D7cDB3KIommwhmYN+80C3jS+6P9Xyx7nPNkL2NTxKWyaovJvijeMF4G4JMHsityDkq0D8FuVw//jASEFBIuQ= 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 1770386125289929.178674955156; Fri, 6 Feb 2026 05:55:25 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 993) id 98BC941B1B; Fri, 6 Feb 2026 08:55:24 -0500 (EST) Received: from [172.19.199.6] (lists.libvirt.org [8.43.85.245]) by lists.libvirt.org (Postfix) with ESMTP id 7A7DF43DAA; Fri, 6 Feb 2026 08:52:53 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 993) id D4B4B3FBC9; Fri, 6 Feb 2026 08:52:45 -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 521FC3FBB5 for ; Fri, 6 Feb 2026 08:52:45 -0500 (EST) Received: from mx-prod-mc-01.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-486-HWyrcijNP8G9_TIHp3Arzw-1; Fri, 06 Feb 2026 08:52:44 -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-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 35F5419560A5 for ; Fri, 6 Feb 2026 13:52:43 +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 9417B1800465 for ; Fri, 6 Feb 2026 13:52:42 +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=1770385965; 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=7QMySzdfnhB3aR2dqTdsgp1W/UkEuJbLukzaageWjfM=; b=dI6jEQ1X83mGIvtTXPGJj+gAwsrzedaqZvhJ8BEPAIdcWmc6HnZdpkXxdFpsecTsghKbyy p2a3YrBoPbkUaruxWKFgcQ9oJ2sIR7pJvI1HDOFcO7LtTA9jRqy6XXBkmoaxI9Hby0u8B8 dMZYvtBRo4kERjpKYiKeb4S5IY6kBKo= X-MC-Unique: HWyrcijNP8G9_TIHp3Arzw-1 X-Mimecast-MFC-AGG-ID: HWyrcijNP8G9_TIHp3Arzw_1770385963 To: devel@lists.libvirt.org Subject: [PATCH 2/4] virsocketaddr: Introduce virSocketAddrSubnetToPrefix() Date: Fri, 6 Feb 2026 14:52:35 +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: 1rmsSePJkgNI6n1BoAci54qT0nftjyrx8bktSeRR1U0_1770385963 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: DDTV7X6VAVQHNZS2K6O445P7VOSC23LF X-Message-ID-Hash: DDTV7X6VAVQHNZS2K6O445P7VOSC23LF 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: 1770386127903154100 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 0. Additionally, if the input string is already a prefix (with optional leading slash character) just return that number parsed. Signed-off-by: Michal Privoznik --- src/libvirt_private.syms | 1 + src/util/virsocketaddr.c | 51 ++++++++++++++++++++++++++++++++++++++++ src/util/virsocketaddr.h | 2 ++ tests/sockettest.c | 29 +++++++++++++++++++++++ 4 files changed, 83 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..89d41d7656 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,56 @@ 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. + * + * 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..df62dc6f3b 100644 --- a/tests/sockettest.c +++ b/tests/sockettest.c @@ -257,6 +257,21 @@ 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; + + if (virSocketAddrSubnetToPrefix(data->addr) !=3D data->prefix) + return -1; + return 0; +} + static int mymain(void) { @@ -352,6 +367,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 +499,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 Sat Feb 7 17:42:26 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=1770386169; cv=none; d=zohomail.com; s=zohoarc; b=T2dVQqNEXkJrN475Jax4HfWInmP/cqoMRucNB59IY/Pm5r1/KE/lkbDStMhEy5GGB4S7kW/dtzm1JCXnThnrTv7uUhoHowy+hs438tNEEP6Yq5HPMCswGw6ZQ6ylHZlWROQkq2D136kN40KjcawjaABS0iWrq2s72HluT/AwxWI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1770386169; 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=MMv3TbRzSb0U/auVwjYyshvg9EwnU0SaD8x5MjyT4/Y=; b=IVOagk7GBSLHz0iGVFciIaP9TY5MJm3TukvDQI43Nk0aARHihOxzm5PdR462WBCMNIhEjdPSbA/+Sn/8Jcc6qJMuASoKC7YPrsWkbYSNhZdO4sFMR6tRw04WCCG8BTbmWgXL8ZM8/Ys7H/Iu1D8lC9qxG4oQ6USZPTF7XY1Y8m8= 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 1770386169456665.6197926674691; Fri, 6 Feb 2026 05:56:09 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 993) id 8658541826; Fri, 6 Feb 2026 08:56:08 -0500 (EST) Received: from [172.19.199.6] (lists.libvirt.org [8.43.85.245]) by lists.libvirt.org (Postfix) with ESMTP id 485A343E0C; Fri, 6 Feb 2026 08:52:55 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 993) id AF15941A97; Fri, 6 Feb 2026 08:52:48 -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 92BCA3FBC9 for ; Fri, 6 Feb 2026 08:52:46 -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-6-uqvg3TVfOOmTpHaljKAj3Q-1; Fri, 06 Feb 2026 08:52:45 -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-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 347401955F27 for ; Fri, 6 Feb 2026 13:52:44 +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 91B801800465 for ; Fri, 6 Feb 2026 13:52:43 +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=1770385966; 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=MMv3TbRzSb0U/auVwjYyshvg9EwnU0SaD8x5MjyT4/Y=; b=XlQJ4dCjJ0LnU8sRcO1h9pWj4mnYynnJfgIr4Sok++npftShH2wHybZ4mDATDCypxBXjjz kKreeEz9JAHtkZ/NpqWwV/1FpjQDZfJlFdi9cS7aDUh+ay3PCRT0q+WIaPHtu5e1Q4WuMT yU1HyJbje1zJZK61nVxY/H3xnKQvQHQ= X-MC-Unique: uqvg3TVfOOmTpHaljKAj3Q-1 X-Mimecast-MFC-AGG-ID: uqvg3TVfOOmTpHaljKAj3Q_1770385964 To: devel@lists.libvirt.org Subject: [PATCH 3/4] hyperv: Move MAC parsing into a separate function Date: Fri, 6 Feb 2026 14:52:36 +0100 Message-ID: <9a9b0e656db21ef4f54a42999fa9f38e5f2f6349.1770385874.git.mprivozn@redhat.com> 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: KHGEO5AkvTNJkA37ZNcsBY4OR1kPhVsIuysb0qsfm2Y_1770385964 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: WWCNG4XKF6MNVDE473UUDKGZ65IYOM2Q X-Message-ID-Hash: WWCNG4XKF6MNVDE473UUDKGZ65IYOM2Q 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: 1770386171818158500 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 --- 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 8dd56f39dc..fbc76544df 100644 --- a/src/hyperv/hyperv_driver.c +++ b/src/hyperv/hyperv_driver.c @@ -1550,18 +1550,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); @@ -1580,28 +1610,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 Sat Feb 7 17:42:26 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