From nobody Tue Feb 10 07:21:27 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1619077409; cv=none; d=zohomail.com; s=zohoarc; b=YgaX/iZpbEILw+823tBC03SdpdKm3a1jZVpgc2HexsnnnK6ngqSFl2RAAdtwBVSTrfg5YOneuwJWlyTd834NsISA77tlVBiwK3XzcwmT+3Iyo9p6H5miDZXK6PjK9o3O60GgXn7NDIGaqy+Svyb0uubfqHADLeQPBduPgvhYTmk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1619077409; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=zf8tdpKSyIGCgw+FYtyxt4xzNdPYZSg6Kg1cQULBpMk=; b=a72UypVHx4vqbF+oaZXdtRL8edncyIqwUXI1KG1ELsjYNkbc8Q5pzMDQvPjtXiC8X5OMZ8vE8YqH2ihUWdgIg8270Z6FhcHT6Kp2CzbfrersZCSCSUax26WveQagmK7Fo4n7xy2St60267teXc7vbXO1vEFGU5vCLGZnlatHkvE= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1619077409184628.9483104414027; Thu, 22 Apr 2021 00:43:29 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-472-ssKLw4KtMZeAbIxVGY5YFg-1; Thu, 22 Apr 2021 03:43:24 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 7365D343A2; Thu, 22 Apr 2021 07:43:19 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 279A562688; Thu, 22 Apr 2021 07:43:19 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id DF72C44A5D; Thu, 22 Apr 2021 07:43:18 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 13M7hFak025538 for ; Thu, 22 Apr 2021 03:43:15 -0400 Received: by smtp.corp.redhat.com (Postfix) id 5AB44115D35F; Thu, 22 Apr 2021 07:43:15 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast04.extmail.prod.ext.rdu2.redhat.com [10.11.55.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 55EA5115D361 for ; Thu, 22 Apr 2021 07:43:12 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-1.mimecast.com [205.139.110.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id B61BF101A539 for ; Thu, 22 Apr 2021 07:43:12 +0000 (UTC) Received: from m97136.mail.qiye.163.com (m97136.mail.qiye.163.com [220.181.97.136]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-182-yVwwqBJ4OJqaCIF7VMyrwA-1; Thu, 22 Apr 2021 03:43:05 -0400 Received: from localhost.localdomain (unknown [58.56.27.130]) by smtp2 (Coremail) with SMTP id iOCowAA3HLYJJYFgMwTJAQ--.5876S16; Thu, 22 Apr 2021 15:26:07 +0800 (CST) X-MC-Unique: ssKLw4KtMZeAbIxVGY5YFg-1 X-MC-Unique: yVwwqBJ4OJqaCIF7VMyrwA-1 From: Shi Lei To: libvir-list@redhat.com Subject: [RFCv3 14/25] conf: Extract error-checking code from virNetworkDNSSrvDefParseXML Date: Thu, 22 Apr 2021 15:25:22 +0800 Message-Id: <20210422072533.312211-15-shi_lei@massclouds.com> In-Reply-To: <20210422072533.312211-1-shi_lei@massclouds.com> References: <20210422072533.312211-1-shi_lei@massclouds.com> MIME-Version: 1.0 X-CM-TRANSID: iOCowAA3HLYJJYFgMwTJAQ--.5876S16 X-Coremail-Antispam: 1Uf129KBjvJXoW3JryUXFy7JrWDWrW3XryxXwb_yoW7tryfpF s5Ja98GrWrGr1fKrWjkFyrCw15Wwn5tr45C3s3Za4Ik3y3Xwn7Cw47ZFyDW3y7Cry5Jr4a yFy3Zws5Wrn8Z3JanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0Jb_pBgUUUUU= X-Originating-IP: [58.56.27.130] X-CM-SenderInfo: pvklsz1hl6ztxvvfz0xxgvhudrp/1tbiPw98T1bdHPqnVwAAse X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-loop: libvir-list@redhat.com Cc: Shi Lei X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Signed-off-by: Shi Lei --- src/conf/network_conf.c | 107 +++++++++++++++++++++++++++++++--------- 1 file changed, 83 insertions(+), 24 deletions(-) diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c index bb976a78..20128af0 100644 --- a/src/conf/network_conf.c +++ b/src/conf/network_conf.c @@ -768,23 +768,26 @@ virNetworkDNSHostDefParseXML(const char *networkName, "_-+/*" =20 static int -virNetworkDNSSrvDefParseXML(const char *networkName, - xmlNodePtr node, - xmlXPathContextPtr ctxt, - virNetworkDNSSrvDef *def, - bool partialOkay) +virNetworkDNSSrvDefParseHook(xmlNodePtr node G_GNUC_UNUSED, + virNetworkDNSSrvDef *def, + const char *networkName, + void *parent G_GNUC_UNUSED, + void *opaque, + const char *portStr, + const char *priorityStr, + const char *weightStr) { - int ret; - VIR_XPATH_NODE_AUTORESTORE(ctxt) - - ctxt->node =3D node; + bool partialOkay =3D false; + if (opaque) + partialOkay =3D *((bool *) opaque); =20 - if (!(def->service =3D virXMLPropString(node, "service")) && !partialO= kay) { + if (!def->service && !partialOkay) { virReportError(VIR_ERR_XML_DETAIL, _("missing required service attribute in DNS SRV re= cord " "of network '%s'"), networkName); goto error; } + if (def->service) { if (strlen(def->service) > DNS_RECORD_LENGTH_SRV) { virReportError(VIR_ERR_XML_DETAIL, @@ -802,13 +805,14 @@ virNetworkDNSSrvDefParseXML(const char *networkName, } } =20 - if (!(def->protocol =3D virXMLPropString(node, "protocol")) && !partia= lOkay) { + if (!def->protocol && !partialOkay) { virReportError(VIR_ERR_XML_DETAIL, _("missing required protocol attribute " "in DNS SRV record '%s' of network '%s'"), def->service, networkName); goto error; } + if (def->protocol && strspn(def->protocol, PROTOCOL_CHARS) < strlen(def->protocol)) { virReportError(VIR_ERR_XML_DETAIL, @@ -818,19 +822,14 @@ virNetworkDNSSrvDefParseXML(const char *networkName, goto error; } =20 - /* Following attributes are optional */ - def->domain =3D virXMLPropString(node, "domain"); - def->target =3D virXMLPropString(node, "target"); - - ret =3D virXPathUInt("string(./@port)", ctxt, &def->port); - if (ret >=3D 0 && !def->target) { + if (portStr && !def->target) { virReportError(VIR_ERR_XML_DETAIL, _("DNS SRV port attribute not permitted without " "target for service '%s' in network '%s'"), def->service, networkName); goto error; } - if (ret =3D=3D -2 || (ret >=3D 0 && (def->port < 1 || def->port > 6553= 5))) { + if (portStr && (def->port < 1 || def->port > 65535)) { virReportError(VIR_ERR_XML_DETAIL, _("invalid DNS SRV port attribute " "for service '%s' in network '%s'"), @@ -838,15 +837,14 @@ virNetworkDNSSrvDefParseXML(const char *networkName, goto error; } =20 - ret =3D virXPathUInt("string(./@priority)", ctxt, &def->priority); - if (ret >=3D 0 && !def->target) { + if (priorityStr && !def->target) { virReportError(VIR_ERR_XML_DETAIL, _("DNS SRV priority attribute not permitted without= " "target for service '%s' in network '%s'"), def->service, networkName); goto error; } - if (ret =3D=3D -2 || (ret >=3D 0 && def->priority > 65535)) { + if (priorityStr && def->priority > 65535) { virReportError(VIR_ERR_XML_DETAIL, _("Invalid DNS SRV priority attribute " "for service '%s' in network '%s'"), @@ -854,15 +852,14 @@ virNetworkDNSSrvDefParseXML(const char *networkName, goto error; } =20 - ret =3D virXPathUInt("string(./@weight)", ctxt, &def->weight); - if (ret >=3D 0 && !def->target) { + if (weightStr && !def->target) { virReportError(VIR_ERR_XML_DETAIL, _("DNS SRV weight attribute not permitted without " "target for service '%s' in network '%s'"), def->service, networkName); goto error; } - if (ret =3D=3D -2 || (ret >=3D 0 && def->weight > 65535)) { + if (weightStr && def->weight > 65535) { virReportError(VIR_ERR_XML_DETAIL, _("invalid DNS SRV weight attribute " "for service '%s' in network '%s'"), @@ -872,6 +869,68 @@ virNetworkDNSSrvDefParseXML(const char *networkName, =20 return 0; =20 + error: + return -1; +} + + +static int +virNetworkDNSSrvDefParseXML(const char *networkName, + xmlNodePtr node, + xmlXPathContextPtr ctxt G_GNUC_UNUSED, + virNetworkDNSSrvDef *def, + bool partialOkay) +{ + g_autofree char *portStr =3D NULL; + g_autofree char *priorityStr =3D NULL; + g_autofree char *weightStr =3D NULL; + + def->service =3D virXMLPropString(node, "service"); + def->protocol =3D virXMLPropString(node, "protocol"); + + /* Following attributes are optional */ + def->domain =3D virXMLPropString(node, "domain"); + def->target =3D virXMLPropString(node, "target"); + + portStr =3D virXMLPropString(node, "port"); + if (portStr) { + if (virStrToLong_uip(portStr, NULL, 0, &def->port) < 0) { + virReportError(VIR_ERR_XML_DETAIL, + _("invalid DNS SRV port attribute " + "for service '%s' in network '%s'"), + def->service, networkName); + goto error; + } + } + + priorityStr =3D virXMLPropString(node, "priority"); + if (priorityStr) { + if (virStrToLong_uip(priorityStr, NULL, 0, &def->priority) < 0) { + virReportError(VIR_ERR_XML_DETAIL, + _("Invalid DNS SRV priority attribute " + "for service '%s' in network '%s'"), + def->service, networkName); + goto error; + } + } + + weightStr =3D virXMLPropString(node, "weight"); + if (weightStr) { + if (virStrToLong_uip(weightStr, NULL, 0, &def->weight) < 0) { + virReportError(VIR_ERR_XML_DETAIL, + _("invalid DNS SRV weight attribute " + "for service '%s' in network '%s'"), + def->service, networkName); + goto error; + } + } + + if (virNetworkDNSSrvDefParseHook(node, def, networkName, def, &partial= Okay, + portStr, priorityStr, weightStr) < 0) + goto error; + + return 0; + error: virNetworkDNSSrvDefClear(def); return -1; --=20 2.25.1