From nobody Mon Feb 9 13:38:56 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) client-ip=207.211.31.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1599190936; cv=none; d=zohomail.com; s=zohoarc; b=Dy1d9tJVWhrIM3w8troovWXMPwUbNYTZAimSLCpgT5qISSE2nKuY3Hry8qFrifKJHxm3U52k2950p72mC4uAYY2mbwh3IRaNlyUsR+MfKLb0kx9CjzOKmbFxMzEyeVhW9NQLgWDd0dUeOL33kZ4GMY/oJJclh/QwiMe9Vj8t3Js= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1599190936; h=Content-Type:Content-Transfer-Encoding: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=X+C8um3wZ5Ccw/DOmccdQzATybGwYII9i9rBxSuq83g=; b=Q9NpDqRYfF3ondK9gd5PF5zQgZCBwHHEephZmmynO6XYZ41iTwvCAK9QEVl6QPxQfmgA62Hs4GvcCgUAMsnSdhfgSjItF9Ki4sKztYMzcCppFNOLq7htQvhlbdiSABtxOwGYdKGIuOHeC6DrI7uz1KuLq+RTJ/LGS4dLHIHfhpg= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) by mx.zohomail.com with SMTPS id 1599190936416461.3345119317229; Thu, 3 Sep 2020 20:42:16 -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-403-5DRgDJueNC-pPGW_Dzzofw-1; Thu, 03 Sep 2020 23:42:13 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 8B01385EE94; Fri, 4 Sep 2020 03:42:08 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 6E1405D9DC; Fri, 4 Sep 2020 03:42:08 +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 3C750181A884; Fri, 4 Sep 2020 03:42:08 +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 0843fBgu030603 for ; Thu, 3 Sep 2020 23:41:11 -0400 Received: by smtp.corp.redhat.com (Postfix) id AF4D9117DB06; Fri, 4 Sep 2020 03:41:10 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast05.extmail.prod.ext.rdu2.redhat.com [10.11.55.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A4F5B117A97D for ; Fri, 4 Sep 2020 03:41:09 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 5ECF5805B0E for ; Fri, 4 Sep 2020 03:41:09 +0000 (UTC) Received: from mail-m24147.qiye.163.com (mail-m24147.qiye.163.com [220.194.24.147]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-350-yfTSVrr0MHGk-8BQ6a-0LA-1; Thu, 03 Sep 2020 23:41:06 -0400 Received: from localhost.localdomain (unknown [58.56.27.130]) by smtp4 (Coremail) with SMTP id JedpCgAHcNgStlFfYHYgCg--.1426S15; Fri, 04 Sep 2020 11:35:50 +0800 (CST) X-MC-Unique: 5DRgDJueNC-pPGW_Dzzofw-1 X-MC-Unique: yfTSVrr0MHGk-8BQ6a-0LA-1 From: Shi Lei To: libvir-list@redhat.com Subject: [RFCv2 13/46] conf: Extract error-checking code from virNetworkDNSHostDefParseXML Date: Fri, 4 Sep 2020 11:35:05 +0800 Message-Id: <20200904033538.418579-14-shi_lei@massclouds.com> In-Reply-To: <20200904033538.418579-1-shi_lei@massclouds.com> References: <20200904033538.418579-1-shi_lei@massclouds.com> MIME-Version: 1.0 X-CM-TRANSID: JedpCgAHcNgStlFfYHYgCg--.1426S15 X-Coremail-Antispam: 1Uf129KBjvJXoWxCF45WrWDtrW5JF4xAFy7KFg_yoW5GF4DpF 4fJa98JF4kWr1ak397KF10kw15Wrykt345Kryfuw1UZFy3Xw18Gws7ZFy3WasxGry5Xr4a yF4ayws8Gr4UA3JanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0zMq2NLUUUUU= X-Originating-IP: [58.56.27.130] X-CM-SenderInfo: pvklsz1hl6ztxvvfz0xxgvhudrp/1tbiEBeVT1nxrfy0RwAAsX 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 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.14 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0.002 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 | 63 +++++++++++++++++++++++++++++------------ 1 file changed, 45 insertions(+), 18 deletions(-) diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c index 518f6da..44032e6 100644 --- a/src/conf/network_conf.c +++ b/src/conf/network_conf.c @@ -675,21 +675,57 @@ virNetworkDHCPDefParseXML(const char *networkName, =20 =20 static int -virNetworkDNSHostDefParseXML(const char *networkName, - xmlNodePtr node, - virNetworkDNSHostDefPtr def, - bool partialOkay) +virNetworkDNSHostDefParseXMLHook(xmlNodePtr node G_GNUC_UNUSED, + virNetworkDNSHostDefPtr def, + const char *networkName, + void *parent G_GNUC_UNUSED, + void *opaque, + const char *ip, + int nHostnameNodes G_GNUC_UNUSED) { - xmlNodePtr cur; - g_autofree char *ip =3D NULL; + bool partialOkay =3D false; =20 - if (!(ip =3D virXMLPropString(node, "ip")) && !partialOkay) { + if (opaque) + partialOkay =3D *((bool *) opaque); + + if (!ip && !partialOkay) { virReportError(VIR_ERR_XML_DETAIL, _("Missing IP address in network '%s' DNS HOST reco= rd"), networkName); goto error; } =20 + if (def->nnames =3D=3D 0 && !partialOkay) { + virReportError(VIR_ERR_XML_DETAIL, + _("Missing hostname in network '%s' DNS HOST record= "), + networkName); + goto error; + } + + if (!VIR_SOCKET_ADDR_VALID(&def->ip) && def->nnames =3D=3D 0) { + virReportError(VIR_ERR_XML_DETAIL, + _("Missing ip and hostname in network '%s' DNS HOST= record"), + networkName); + goto error; + } + + return 0; + + error: + return -1; +} + + +static int +virNetworkDNSHostDefParseXML(const char *networkName, + xmlNodePtr node, + virNetworkDNSHostDefPtr def, + bool partialOkay) +{ + xmlNodePtr cur; + g_autofree char *ip =3D NULL; + + ip =3D virXMLPropString(node, "ip"); if (ip && (virSocketAddrParse(&def->ip, ip, AF_UNSPEC) < 0)) { virReportError(VIR_ERR_XML_DETAIL, _("Invalid IP address in network '%s' DNS HOST reco= rd"), @@ -719,19 +755,10 @@ virNetworkDNSHostDefParseXML(const char *networkName, } cur =3D cur->next; } - if (def->nnames =3D=3D 0 && !partialOkay) { - virReportError(VIR_ERR_XML_DETAIL, - _("Missing hostname in network '%s' DNS HOST record= "), - networkName); - goto error; - } =20 - if (!VIR_SOCKET_ADDR_VALID(&def->ip) && def->nnames =3D=3D 0) { - virReportError(VIR_ERR_XML_DETAIL, - _("Missing ip and hostname in network '%s' DNS HOST= record"), - networkName); + if (virNetworkDNSHostDefParseXMLHook(node, def, networkName, def, &par= tialOkay, + ip, def->nnames) < 0) goto error; - } =20 return 0; =20 --=20 2.25.1