From nobody Tue Mar 3 04:52:36 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=1771919690; cv=none; d=zohomail.com; s=zohoarc; b=MrQsd/aQ4T9RiOrWV0PyuTmPTvIL8biir6vO9UOU2nIS6PSa+j7KOqruLjwJ5s1GD0rUpbj0JgRbCWWlfCta+cFhkNZc2Kufc6pNw2ddt+aliraw/baWMpJbta51LiRw/rFdinajrj6UsDhXOc3N9ZxZ+rS3QATz9uksOTgMvW0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1771919690; 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=OmZlcN0SYF9AgsC2FkB3l+cdEzYwD/F6fgVJ9Nyh0tc=; b=k3v+mV8hLHS3JQ5ATToFKS2c8hVO6tmlgpJnD5GCTk/pz/ziYvpb+dGn9R0Us767RN2fp7CcM+uoSe8cfAMUEbTs299jql5/N1idXTzmGtZNFJWbV4BWqJ8bjBCTQ+AT2Lc0HGfJo4g/8CM/wCZKdZDoXMeBoz2Gd+mgO0BV/7g= 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 1771919690123972.8849253096374; Mon, 23 Feb 2026 23:54:50 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 993) id 3CB0F41BB1; Tue, 24 Feb 2026 02:54:49 -0500 (EST) Received: from [172.19.199.9] (lists.libvirt.org [8.43.85.245]) by lists.libvirt.org (Postfix) with ESMTP id 2619041CCA; Tue, 24 Feb 2026 02:52:24 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 993) id ACB7841A0A; Tue, 24 Feb 2026 02:52:14 -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 3783F41B43 for ; Tue, 24 Feb 2026 02:52:14 -0500 (EST) Received: from mx-prod-mc-05.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-110-y9cK0-36MwSLAgg5_JfY-Q-1; Tue, 24 Feb 2026 02:52:11 -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-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id D9800195609E for ; Tue, 24 Feb 2026 07:52:10 +0000 (UTC) Received: from vhost3.router.laine.org (unknown [10.22.64.82]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 7ED531800676 for ; Tue, 24 Feb 2026 07:52:10 +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=-2.6 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HELO_MISC_IP,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=1771919533; 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=OmZlcN0SYF9AgsC2FkB3l+cdEzYwD/F6fgVJ9Nyh0tc=; b=I+e9zMmoB7Wdy90eIoFu+lmYtkniixAhiwL11jQju2ACJH/s2n3p+el2sS65hd3QSO6n+V fczPgEA4USOYzB/JHkdk40mTpYQeqZL3i9qaBD62jW+hx1SYvXIB7MynFYJmg3W7tc0Ifm PJyh4qtV2xZ9nu4hfNxz4cnbihSoCY0= X-MC-Unique: y9cK0-36MwSLAgg5_JfY-Q-1 X-Mimecast-MFC-AGG-ID: y9cK0-36MwSLAgg5_JfY-Q_1771919531 To: devel@lists.libvirt.org Subject: [PATCH 2/6] qemu: reorganize qemuValidateDomainDeviceDefNetwork() Date: Tue, 24 Feb 2026 02:52:04 -0500 Message-ID: <20260224075208.225959-3-laine@redhat.com> In-Reply-To: <20260224075208.225959-1-laine@redhat.com> References: <20260224075208.225959-1-laine@redhat.com> 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: 3pkLnBcga2PIOGeYxLHmGgrnRx81GnwChW6x06w5YaU_1771919531 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: ELGV7VGP7QSHCJDDLPOVQGQI5BTVVG3N X-Message-ID-Hash: ELGV7VGP7QSHCJDDLPOVQGQI5BTVVG3N X-MailFrom: laine@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: Laine Stump via Devel Reply-To: Laine Stump X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1771919690873158500 Content-Type: text/plain; charset="utf-8"; x-default="true" From: Laine Stump This will make existing code more consistent with upcoming validation for routes. Signed-off-by: Laine Stump Reviewed-by: Michal Privoznik --- src/qemu/qemu_validate.c | 95 +++++++++++++++++++++------------------- 1 file changed, 49 insertions(+), 46 deletions(-) diff --git a/src/qemu/qemu_validate.c b/src/qemu/qemu_validate.c index 16dd5fef1a..a0ddf512f1 100644 --- a/src/qemu/qemu_validate.c +++ b/src/qemu/qemu_validate.c @@ -1882,16 +1882,10 @@ qemuValidateDomainDeviceDefNetwork(const virDomainN= etDef *net, const virDomainDef *def, virQEMUCaps *qemuCaps) { - bool hasIPv4 =3D false; - bool hasIPv6 =3D false; + bool hasV4Addr =3D false; + bool hasV6Addr =3D false; size_t i; =20 - if (net->guestIP.nroutes) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("Invalid attempt to set network interface guest-s= ide IP route, not supported by QEMU")); - return -1; - } - if (net->type =3D=3D VIR_DOMAIN_NET_TYPE_USER || (net->type =3D=3D VIR_DOMAIN_NET_TYPE_VHOSTUSER && net->backend.type =3D=3D VIR_DOMAIN_NET_BACKEND_PASST)) { @@ -1906,57 +1900,66 @@ qemuValidateDomainDeviceDefNetwork(const virDomainN= etDef *net, virDomainNetBackendTypeToString(net->backend.ty= pe)); return -1; } + } + + for (i =3D 0; i < net->guestIP.nips; i++) { + const virNetDevIPAddr *ip =3D net->guestIP.ips[i]; + + if (net->type !=3D VIR_DOMAIN_NET_TYPE_USER && + net->backend.type !=3D VIR_DOMAIN_NET_BACKEND_PASST) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("Invalid attempt to set network interface gue= st-side IP address info, not supported for this interface type/backend")); + return -1; + } =20 - for (i =3D 0; i < net->guestIP.nips; i++) { - const virNetDevIPAddr *ip =3D net->guestIP.ips[i]; + if (VIR_SOCKET_ADDR_VALID(&net->guestIP.ips[i]->peer)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("Invalid attempt to set peer IP for guest")); + return -1; + } =20 - if (VIR_SOCKET_ADDR_VALID(&net->guestIP.ips[i]->peer)) { + if (VIR_SOCKET_ADDR_IS_FAMILY(&ip->address, AF_INET)) { + if (hasV4Addr) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("Invalid attempt to set peer IP for guest= ")); + _("Only one IPv4 address per interface is a= llowed")); return -1; } + hasV4Addr =3D true; =20 - if (VIR_SOCKET_ADDR_IS_FAMILY(&ip->address, AF_INET)) { - if (hasIPv4) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("Only one IPv4 address per interface = is allowed")); - return -1; - } - hasIPv4 =3D true; - - if (ip->prefix > 0 && - (ip->prefix < 4 || ip->prefix > 27)) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("invalid prefix, must be in range of = 4-27")); - return -1; - } + if (ip->prefix > 0 && + (ip->prefix < 4 || ip->prefix > 27)) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("invalid prefix, must be in range of 4-27= ")); + return -1; } + } =20 - if (VIR_SOCKET_ADDR_IS_FAMILY(&ip->address, AF_INET6)) { - if (hasIPv6) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("Only one IPv6 address per interface = is allowed")); - return -1; - } - hasIPv6 =3D true; + if (VIR_SOCKET_ADDR_IS_FAMILY(&ip->address, AF_INET6)) { + if (hasV6Addr) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("Only one IPv6 address per interface is a= llowed")); + return -1; + } + hasV6Addr =3D true; =20 - if (ip->prefix && ip->prefix !=3D 64) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unsupported IPv6 address prefix=3D'%= 1$u' - must be 64"), - ip->prefix); - return -1; - } + if (ip->prefix && ip->prefix !=3D 64) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("unsupported IPv6 address prefix=3D'%1$u'= - must be 64"), + ip->prefix); + return -1; + } =20 - if (ip->prefix > 120) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("prefix too long")); - return -1; - } + if (ip->prefix > 120) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("prefix too long")); + return -1; } } - } else if (net->guestIP.nips) { + } + + if (net->guestIP.nroutes) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("Invalid attempt to set network interface guest-s= ide IP address info, not supported by QEMU")); + _("Invalid attempt to set network interface guest-s= ide IP route, not supported by QEMU")); return -1; } =20 --=20 2.52.0