From nobody Tue Feb 10 03:37:33 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=1619077400; cv=none; d=zohomail.com; s=zohoarc; b=j0lN2y+4ZD4hyCZM+iBrykX+dmKba0zdxxq4hUYzrU4IMxV7uyKUgf7J5fIuethaCntoG9IfbfR3r6fgYz5xb8zSs845fYK2QNAnzT8qLK+YVtf0Y66RMnKzvRVfrWi6Mi4iECGVR4smwuTODSCyn4u0+/HT0GcxueAJx2nlzQA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1619077400; 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=6HB9O0msgl/0nFvF1oVU5GvoJ+vPk91aOUWrXoHYl1g=; b=V+HnG5iq3z9rEHC1QItfXC+KgKUtUm618ev0u5dTECbfdfn331ZQYwXpGPnLr1zXowg7XDVza16a/O864JpBYwPEQk07+hOJ2tC6PKH4nIDkwzhy9niYuevH1HVaPMlkSVEl3eQOz8MwvjZXV/3F+Z9k6au9wBg9Ipnz2f9KaF4= 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 1619077400729689.1095758642256; Thu, 22 Apr 2021 00:43:20 -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-438-Jt6b0PQTMbqXJV85I-f8TA-1; Thu, 22 Apr 2021 03:43:17 -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 08D7219253D7; Thu, 22 Apr 2021 07:43:13 +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 DF48A2D080; Thu, 22 Apr 2021 07:43:12 +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 AC1421806D1D; Thu, 22 Apr 2021 07:43:12 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 13M7hBtm025516 for ; Thu, 22 Apr 2021 03:43:11 -0400 Received: by smtp.corp.redhat.com (Postfix) id 546D2F8965; Thu, 22 Apr 2021 07:43:11 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast02.extmail.prod.ext.rdu2.redhat.com [10.11.55.18]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 509DCF896A for ; Thu, 22 Apr 2021 07:43:11 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-2.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 3A8D48027E6 for ; Thu, 22 Apr 2021 07:43:11 +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-502-u86t8umrO1O2z0EwiX2ISA-1; Thu, 22 Apr 2021 03:43:07 -0400 Received: from localhost.localdomain (unknown [58.56.27.130]) by smtp2 (Coremail) with SMTP id iOCowAA3HLYJJYFgMwTJAQ--.5876S19; Thu, 22 Apr 2021 15:26:08 +0800 (CST) X-MC-Unique: Jt6b0PQTMbqXJV85I-f8TA-1 X-MC-Unique: u86t8umrO1O2z0EwiX2ISA-1 From: Shi Lei To: libvir-list@redhat.com Subject: [RFCv3 17/25] conf: Extract error-checking code from virNetworkDNSHostDefParseXML Date: Thu, 22 Apr 2021 15:25:25 +0800 Message-Id: <20210422072533.312211-18-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--.5876S19 X-Coremail-Antispam: 1Uf129KBjvJXoWxCF48tryfJrW7WF1fAr15XFb_yoW5GF1DpF 1fJa98JF4kWr1ak397KF18Kw15JrykJ345Kryfuw1UZFy3Xw18Grs7Zry7WasxWry5XrWY yF4ayws8Gr4UA3JanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0JbKv35UUUUU= X-Originating-IP: [58.56.27.130] X-CM-SenderInfo: pvklsz1hl6ztxvvfz0xxgvhudrp/1tbigBB8T1rpO43S6AAAsc 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.79 on 10.11.54.5 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 | 63 +++++++++++++++++++++++++++++------------ 1 file changed, 45 insertions(+), 18 deletions(-) diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c index 146c4977..b326ef5f 100644 --- a/src/conf/network_conf.c +++ b/src/conf/network_conf.c @@ -676,21 +676,57 @@ virNetworkDHCPDefParseXML(const char *networkName, =20 =20 static int -virNetworkDNSHostDefParseXML(const char *networkName, - xmlNodePtr node, - virNetworkDNSHostDef *def, - bool partialOkay) +virNetworkDNSHostDefParseHook(xmlNodePtr node G_GNUC_UNUSED, + virNetworkDNSHostDef *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, + virNetworkDNSHostDef *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"), @@ -720,19 +756,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 (virNetworkDNSHostDefParseHook(node, def, networkName, def, &partia= lOkay, + ip, def->nnames) < 0) goto error; - } =20 return 0; =20 --=20 2.25.1