From nobody Wed Sep 10 01:32:52 2025 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=1753197235; cv=none; d=zohomail.com; s=zohoarc; b=ijPqQ2fXbKIrgnNpl7kZ1TdUfiK6TjJQjjYeMST+snz1MZOXY8KhxjO9lnwmvt0jD1gFK1uE1PBIVdGDBSjXT2Y4zTsc73QKvdByJ8MrpsrgnHzfUTVeGA6bMGrIObtQaiywYhUgTP1AiOLdaZxcACA4tz7pvoyBbZIoEFYzGE4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1753197235; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Subject:Subject:To:To:Message-Id; bh=jTHGuK2fvS1oOBayr2uuYigtQrODtwBF7Z3KRlUSwiU=; b=H6Kg5q3r3O+RLCMG1upAmw/GGfDyAcESavty4v9ImiEHtZDygsuJ9QP0aLc0XuWAagCJcEiCss2DjUDi7QFjI9UDqKWFKCF0Cl4EZB7uGAlOudpjdkQRcLrYj1898Q6CeSjXriXdmYanuHWHgza4NLLQbiwph8VmNef4OdL/35Y= 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 175319723533135.68707696696708; Tue, 22 Jul 2025 08:13:55 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 66A9512C0; Tue, 22 Jul 2025 11:13:54 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 1FE72EA1; Tue, 22 Jul 2025 11:13:10 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id CE599DEE; Tue, 22 Jul 2025 11:13:05 -0400 (EDT) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 4C298DCF for ; Tue, 22 Jul 2025 11:13:05 -0400 (EDT) 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-300-87hR07q8MuGjhNncmOvIcw-1; Tue, 22 Jul 2025 11:13:03 -0400 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (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 42C5E1800291 for ; Tue, 22 Jul 2025 15:13:02 +0000 (UTC) Received: from kshcheti-thinkpadp1gen4i.tpbc.csb (unknown [10.43.2.246]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 4ED5C19560AD; Tue, 22 Jul 2025 15:13:01 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H5, RCVD_IN_MSPIKE_WL,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED,SPF_HELO_PASS autolearn=unavailable autolearn_force=no version=3.4.4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1753197185; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=O4vIJHwsGlrtMYHl+uSQPuaBdIOlziXZbWx+ySmy96A=; b=OxOzsI8StmqvzY1iXaiUZUrtIOyS/SmI3hWCcU/IJdCJ6A2cnpHCPrNQM86HLupQ6qi7ab OLBxH8V+v+oY2jxA6G89Riz8kktYaasoxFr77nL1gZ2M+M+d1HPFAurLd5Mz4oPfNJQwpl vWrw1EWkRsPedA11kIPBHk2Qqc1GfoI= X-MC-Unique: 87hR07q8MuGjhNncmOvIcw-1 X-Mimecast-MFC-AGG-ID: 87hR07q8MuGjhNncmOvIcw_1753197182 To: devel@lists.libvirt.org Subject: [PATCH v2 1/4] conf: virNetDevVPortProfileParse refactor Date: Tue, 22 Jul 2025 17:12:02 +0200 Message-ID: <20250722151250.32533-2-kshcheti@redhat.com> In-Reply-To: <20250722151250.32533-1-kshcheti@redhat.com> References: <20250722151250.32533-1-kshcheti@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: 6b1QGtKpiLKwpI_Q_Ea18S5TAX2WPB1DUU8PUT7RwLY_1753197182 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: 24PB6PEFLQNHT7LER5XZQZZURIJKMZWP X-Message-ID-Hash: 24PB6PEFLQNHT7LER5XZQZZURIJKMZWP X-MailFrom: kshcheti@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header CC: Kirill Shchetiniuk X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: From: Kirill Shchetiniuk via Devel Reply-To: Kirill Shchetiniuk X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1753197237428116600 Content-Type: text/plain; charset="utf-8"; x-default="true" From: Kirill Shchetiniuk Refactored the virNetDevVPortProfileParse function to use the appropriate virXMLProp* functions to parse input configuration XML. Signed-off-by: Kirill Shchetiniuk --- src/conf/netdev_vport_profile_conf.c | 112 +++++++++++---------------- 1 file changed, 44 insertions(+), 68 deletions(-) diff --git a/src/conf/netdev_vport_profile_conf.c b/src/conf/netdev_vport_p= rofile_conf.c index 032a3147d7..92819c2f34 100644 --- a/src/conf/netdev_vport_profile_conf.c +++ b/src/conf/netdev_vport_profile_conf.c @@ -29,12 +29,6 @@ virNetDevVPortProfile * virNetDevVPortProfileParse(xmlNodePtr node, unsigned int flags) { g_autofree char *virtPortType =3D NULL; - g_autofree char *virtPortManagerID =3D NULL; - g_autofree char *virtPortTypeID =3D NULL; - g_autofree char *virtPortTypeIDVersion =3D NULL; - g_autofree char *virtPortInstanceID =3D NULL; - g_autofree char *virtPortProfileID =3D NULL; - g_autofree char *virtPortInterfaceID =3D NULL; g_autofree virNetDevVPortProfile *virtPort =3D NULL; xmlNodePtr parameters; =20 @@ -55,88 +49,70 @@ virNetDevVPortProfileParse(xmlNodePtr node, unsigned in= t flags) } =20 if ((parameters =3D virXMLNodeGetSubelement(node, "parameters"))) { - virtPortManagerID =3D virXMLPropString(parameters, "managerid"); - virtPortTypeID =3D virXMLPropString(parameters, "typeid"); - virtPortTypeIDVersion =3D virXMLPropString(parameters, "typeidvers= ion"); - virtPortInstanceID =3D virXMLPropString(parameters, "instanceid"); - virtPortProfileID =3D virXMLPropString(parameters, "profileid"); - virtPortInterfaceID =3D virXMLPropString(parameters, "interfaceid"= ); - } - - if (virtPortManagerID) { + int rc; unsigned int val; + g_autofree char *virtPortProfileID =3D virXMLPropString(parameters= , "profileid"); =20 - if (virStrToLong_ui(virtPortManagerID, NULL, 0, &val)) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("cannot parse value of managerid parameter")); + if ((rc =3D virXMLPropUInt(parameters, "managerid", 10, VIR_XML_PR= OP_NONE, &val)) < 0) return NULL; + + if (rc > 0) { + if (val > 0xff) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("value of managerid out of range")); + return NULL; + } + + virtPort->managerID =3D (uint8_t)val; + virtPort->managerID_specified =3D true; } - if (val > 0xff) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("value of managerid out of range")); + + if ((rc =3D virXMLPropUInt(parameters, "typeid", 10, VIR_XML_PROP_= NONE, &val)) < 0) return NULL; - } - virtPort->managerID =3D (uint8_t)val; - virtPort->managerID_specified =3D true; - } =20 - if (virtPortTypeID) { - unsigned int val; + if (rc > 0) { + if (val > 0xffffff) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("value for typeid out of range")); + return NULL; + } =20 - if (virStrToLong_ui(virtPortTypeID, NULL, 0, &val)) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("cannot parse value of typeid parameter")); - return NULL; + virtPort->typeID =3D (uint32_t)val; + virtPort->typeID_specified =3D true; } - if (val > 0xffffff) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("value for typeid out of range")); + + if ((rc =3D virXMLPropUInt(parameters, "typeidversion", 10, VIR_XM= L_PROP_NONE, &val)) < 0) return NULL; - } - virtPort->typeID =3D (uint32_t)val; - virtPort->typeID_specified =3D true; - } =20 - if (virtPortTypeIDVersion) { - unsigned int val; + if (rc > 0) { + if (val > 0xff) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("value of typeidversion out of range")); + return NULL; + } =20 - if (virStrToLong_ui(virtPortTypeIDVersion, NULL, 0, &val)) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("cannot parse value of typeidversion paramete= r")); - return NULL; + virtPort->typeIDVersion =3D (uint8_t)val; + virtPort->typeIDVersion_specified =3D true; } - if (val > 0xff) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("value of typeidversion out of range")); + + if ((rc =3D virXMLPropUUID(parameters, "instanceid", VIR_XML_PROP_= NONE, virtPort->instanceID)) < 0) return NULL; - } - virtPort->typeIDVersion =3D (uint8_t)val; - virtPort->typeIDVersion_specified =3D true; - } =20 - if (virtPortInstanceID) { - if (virUUIDParse(virtPortInstanceID, virtPort->instanceID) < 0) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("cannot parse instanceid parameter as a uuid"= )); + if (rc > 0) + virtPort->instanceID_specified =3D true; + + if ((rc =3D virXMLPropUUID(parameters, "interfaceid", VIR_XML_PROP= _NONE, virtPort->interfaceID)) < 0) return NULL; - } - virtPort->instanceID_specified =3D true; - } =20 - if (virtPortProfileID && - virStrcpyStatic(virtPort->profileID, virtPortProfileID) < 0) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("profileid parameter too long")); - return NULL; - } + if (rc > 0) + virtPort->interfaceID_specified =3D true; =20 - if (virtPortInterfaceID) { - if (virUUIDParse(virtPortInterfaceID, virtPort->interfaceID) < 0) { + if (virtPortProfileID && + virStrcpyStatic(virtPort->profileID, virtPortProfileID) < 0) { virReportError(VIR_ERR_XML_ERROR, "%s", - _("cannot parse interfaceid parameter as a uuid= ")); + _("profileid parameter too long")); return NULL; } - virtPort->interfaceID_specified =3D true; } =20 /* generate default instanceID/interfaceID if appropriate */ --=20 2.49.0