From nobody Mon Feb 9 16:45:14 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=1599190983; cv=none; d=zohomail.com; s=zohoarc; b=UQhylBixVMILmN4jSmyXAOcO2UWrjaQNS5JI9755FB40xdL3GsG7qaWWfWatipEXZ4iXbsB5ynyVrAG7n/o+j1pjOmEkyuTDhQWS9MLpEL0iUQfe++NLXfORb6A1YUEQFJCL0vQSbRZ1c/3LSkEPfLUGvb51j4Q+gG2+FnvTlos= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1599190983; 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=uEZUDIdMqU2aPoHbEX298UaKIWdFeRPoBVmuJAjFeok=; b=TzC1xF5Y/gjUbBM8FpXq0VKX5LXXLZKRaNThOQ8Gls3QdrUDv/Jz/6K+GBAMtgR2ZmR9r/yQ0qGvUMwSQHzmMuZjKx6/AteYGGhZ9vI8g4t3lwQpFWvpa8bPjvpfAPAzSXdzks2kC5Gbl46L+jAGfTeoXr9JNE+a0qOP6iO4fRw= 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 1599190983576111.64752674435442; Thu, 3 Sep 2020 20:43:03 -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-515-Ak5kWXsrPTOILiwt8D6rLA-1; Thu, 03 Sep 2020 23:42:03 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id CD29580733D; Fri, 4 Sep 2020 03:41:56 +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 ABD4A7C0B3; Fri, 4 Sep 2020 03:41:56 +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 796BA972FD; Fri, 4 Sep 2020 03:41:56 +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 0843fA3r030558 for ; Thu, 3 Sep 2020 23:41:11 -0400 Received: by smtp.corp.redhat.com (Postfix) id 1A9DC1037A7; Fri, 4 Sep 2020 03:41:10 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast01.extmail.prod.ext.rdu2.redhat.com [10.11.55.17]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1030D10379B for ; Fri, 4 Sep 2020 03:41:07 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.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 0D54488296A for ; Fri, 4 Sep 2020 03:41:07 +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-303-G09LXhwUP1ygiVZLLpVDCA-1; Thu, 03 Sep 2020 23:41:03 -0400 Received: from localhost.localdomain (unknown [58.56.27.130]) by smtp4 (Coremail) with SMTP id JedpCgAHcNgStlFfYHYgCg--.1426S16; Fri, 04 Sep 2020 11:35:51 +0800 (CST) X-MC-Unique: Ak5kWXsrPTOILiwt8D6rLA-1 X-MC-Unique: G09LXhwUP1ygiVZLLpVDCA-1 From: Shi Lei To: libvir-list@redhat.com Subject: [RFCv2 14/46] conf: Replace virNetworkDNSHostDefParseXML(hardcoded) with namesake(generated) Date: Fri, 4 Sep 2020 11:35:06 +0800 Message-Id: <20200904033538.418579-15-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--.1426S16 X-Coremail-Antispam: 1Uf129KBjvJXoWxCrWxGFWUXF1DXrWrtw48tFb_yoWrWw13pF sxJa1DA3y8W3WfK3y2yr1SkrnxurykXw45Gryfuw13A3yUXr1xGws7uF1xWan8GryYyr15 AF4Yvws8GrW7JFUanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0piAnY3UUUUU= X-Originating-IP: [58.56.27.130] X-CM-SenderInfo: pvklsz1hl6ztxvvfz0xxgvhudrp/1tbiihyVT1tVhJllTgAAs0 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 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.11 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 | 71 ++++------------------------------------- src/conf/network_conf.h | 6 ++-- 2 files changed, 9 insertions(+), 68 deletions(-) diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c index 44032e6..e2d0297 100644 --- a/src/conf/network_conf.c +++ b/src/conf/network_conf.c @@ -174,15 +174,6 @@ virNetworkIPDefClear(virNetworkIPDefPtr def) } =20 =20 -static void -virNetworkDNSHostDefClear(virNetworkDNSHostDefPtr def) -{ - while (def->nnames) - VIR_FREE(def->names[--def->nnames]); - VIR_FREE(def->names); -} - - static void virNetworkDNSForwarderClear(virNetworkDNSForwarderPtr def) { @@ -674,7 +665,7 @@ virNetworkDHCPDefParseXML(const char *networkName, } =20 =20 -static int +int virNetworkDNSHostDefParseXMLHook(xmlNodePtr node G_GNUC_UNUSED, virNetworkDNSHostDefPtr def, const char *networkName, @@ -716,58 +707,6 @@ virNetworkDNSHostDefParseXMLHook(xmlNodePtr node G_GNU= C_UNUSED, } =20 =20 -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"), - networkName); - goto error; - } - - cur =3D node->children; - while (cur !=3D NULL) { - if (cur->type =3D=3D XML_ELEMENT_NODE && - virXMLNodeNameEqual(cur, "hostname")) { - if (cur->children !=3D NULL) { - g_autofree char *name =3D virXMLNodeContentString(cur); - - if (!name) - goto error; - - if (!name[0]) { - virReportError(VIR_ERR_XML_DETAIL, - _("Missing hostname in network '%s' D= NS HOST record"), - networkName); - goto error; - } - if (VIR_APPEND_ELEMENT(def->names, def->nnames, name) < = 0) - goto error; - } - } - cur =3D cur->next; - } - - if (virNetworkDNSHostDefParseXMLHook(node, def, networkName, def, &par= tialOkay, - ip, def->nnames) < 0) - goto error; - - return 0; - - error: - virNetworkDNSHostDefClear(def); - return -1; -} - - /* This includes all characters used in the names of current * /etc/services and /etc/protocols files (on Fedora 20), except ".", * which we can't allow because it would conflict with the use of "." @@ -1018,8 +957,8 @@ virNetworkDNSDefParseXML(const char *networkName, return -1; =20 for (i =3D 0; i < nhosts; i++) { - if (virNetworkDNSHostDefParseXML(networkName, hostNodes[i], - &def->hosts[def->nhosts], fal= se) < 0) { + if (virNetworkDNSHostDefParseXML(hostNodes[i], &def->hosts[def= ->nhosts], + networkName, def, NULL) < 0) { return -1; } def->nhosts++; @@ -3421,6 +3360,7 @@ virNetworkDefUpdateDNSHost(virNetworkDefPtr def, bool isAdd =3D (command =3D=3D VIR_NETWORK_UPDATE_COMMAND_ADD_FIRST || command =3D=3D VIR_NETWORK_UPDATE_COMMAND_ADD_LAST); int foundCt =3D 0; + bool notAdd; =20 memset(&host, 0, sizeof(host)); =20 @@ -3434,7 +3374,8 @@ virNetworkDefUpdateDNSHost(virNetworkDefPtr def, if (virNetworkDefUpdateCheckElementName(def, ctxt->node, "host") < 0) goto cleanup; =20 - if (virNetworkDNSHostDefParseXML(def->name, ctxt->node, &host, !isAdd)= < 0) + notAdd =3D !isAdd; + if (virNetworkDNSHostDefParseXML(ctxt->node, &host, def->name, def, &n= otAdd) < 0) goto cleanup; =20 for (i =3D 0; i < dns->nhosts; i++) { diff --git a/src/conf/network_conf.h b/src/conf/network_conf.h index 041119e..c30fd4f 100644 --- a/src/conf/network_conf.h +++ b/src/conf/network_conf.h @@ -149,10 +149,10 @@ struct _virNetworkDNSSrvDef { /* genparse:withhook,= genformat */ =20 typedef struct _virNetworkDNSHostDef virNetworkDNSHostDef; typedef virNetworkDNSHostDef *virNetworkDNSHostDefPtr; -struct _virNetworkDNSHostDef { - virSocketAddr ip; +struct _virNetworkDNSHostDef { /* genparse:withhook */ + virSocketAddr ip; /* xmlattr */ size_t nnames; - char **names; + char **names; /* xmlelem:hostname, array */ }; =20 =20 --=20 2.25.1