From nobody Mon Feb 9 14:34:07 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; dkim=pass; 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=1591752429; cv=none; d=zohomail.com; s=zohoarc; b=N1TXQqxPAEto5t3GrBVhmyEbZlVpnouAYJZJ2/S4pRhtvaLX4+Bv5vX6LJLjtEyGpyNEGAj0tpQ2qihlnJfYwICIO9xi4QvEalqfzaqBuGakCsI0BLtg9bN7N3+Qv3ys7of7Hbs8UU0bzJEwHs41NP8LxoMi4XJ6fxILh2MsgtU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1591752429; h=Content-Type:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=3jzqT1Y+MurOGDmmlte4dGMOpVEl067roTWHYcOWyIg=; b=XD+oEg1P2rEUB7cJYS4Ey6lO+Y+7MxA/BllYRcU7ohj9cV0JJP7lSDTk7muIX4RmbyZnlIziy/+/0Le1z4GQcBTaCmKM5kIbVusU10gSVtY3T1yohKcXhbAQNn4vS/nBF3RbnkNn81wUJg2y6r/SDGP97OvAtRL8TjZ+PRbv+Xc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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 1591752429780924.1700154528146; Tue, 9 Jun 2020 18:27:09 -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-139-mLOKcnbWNrO18ChadS41rw-1; Tue, 09 Jun 2020 21:27:06 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 84D661054FA1; Wed, 10 Jun 2020 01:26:59 +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 63C5218A56; Wed, 10 Jun 2020 01:26:59 +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 393DBB34AE; Wed, 10 Jun 2020 01:26:59 +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 05A1Qvsl027373 for ; Tue, 9 Jun 2020 21:26:57 -0400 Received: by smtp.corp.redhat.com (Postfix) id 96EFE9D77; Wed, 10 Jun 2020 01:26:57 +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 9193B8054B for ; Wed, 10 Jun 2020 01:26:54 +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-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id D29F180CDB5 for ; Wed, 10 Jun 2020 01:26:54 +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-22-iaNWdsmsOfalDVHDoSUJWw-1; Tue, 09 Jun 2020 21:26:51 -0400 Received: from localhost.localdomain (unknown [58.56.27.130]) by smtp4 (Coremail) with SMTP id JedpCgCnxdh_NeBeVKS4Bw--.7295S16; Wed, 10 Jun 2020 09:21:42 +0800 (CST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1591752428; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:content-type:content-type: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=3jzqT1Y+MurOGDmmlte4dGMOpVEl067roTWHYcOWyIg=; b=f1Ps4N/ie1G9I5yGg8iuD2zlatJMD8G6tlH9kYbpBINalQy95wLMW7DOFZAeYskiVlFPE6 fu47UsTd+k541DKEif+TR9QOgvkmqlzzkESNx3DV1HoCrJcEk9Fj+XFj6y1Z2yCgkQkFME hHARGl/No3cUsNIk/9hRRpfw9LkfJnA= X-MC-Unique: mLOKcnbWNrO18ChadS41rw-1 X-MC-Unique: iaNWdsmsOfalDVHDoSUJWw-1 From: Shi Lei To: libvir-list@redhat.com Subject: [RFC 14/21] conf: Replace virNetworkDNSHostDefParseXML(hardcoded) with namesake(generated) Date: Wed, 10 Jun 2020 09:20:42 +0800 Message-Id: <20200610012049.10774-15-shi_lei@massclouds.com> In-Reply-To: <20200610012049.10774-1-shi_lei@massclouds.com> References: <20200610012049.10774-1-shi_lei@massclouds.com> X-CM-TRANSID: JedpCgCnxdh_NeBeVKS4Bw--.7295S16 X-Coremail-Antispam: 1Uf129KBjvJXoWxCry8Jw43Cryrur4xurykKrg_yoWrAF4fpF sxXanrAw48Wa1fKrW2yrnakrnxurykJw1Ykryfuw4fA3yUXr1xGws7uF1xWa98GryYyr13 CF4Yvws8GrW7XF7anT9S1TB71UUUUUDqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0pRrb15UUUUU= X-Originating-IP: [58.56.27.130] X-CM-SenderInfo: pvklsz1hl6ztxvvfz0xxgvhudrp/1tbiUAY-T1f4p9wAkQAAsj 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.12 X-Mimecast-Spam-Score: 2 X-Mimecast-Originator: redhat.com X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Shi Lei --- src/conf/network_conf.c | 72 ++++------------------------------------- src/conf/network_conf.h | 6 ++-- 2 files changed, 10 insertions(+), 68 deletions(-) diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c index 7a3dcd4..29ef3cf 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) { @@ -691,12 +682,12 @@ virNetworkDHCPDefParseXML(const char *networkName, } =20 =20 -static int +int virNetworkDNSHostDefParseXMLHook(xmlNodePtr node G_GNUC_UNUSED, virNetworkDNSHostDefPtr def, const char *networkName, void *opaque, - char *ip, + const char *ip, int nHostnameNodes G_GNUC_UNUSED) { bool partialOkay =3D false; @@ -732,57 +723,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) { - char *name =3D (char *) xmlNodeGetContent(cur); - - if (!name) { - 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) { - VIR_FREE(name); - goto error; - } - } - } - cur =3D cur->next; - } - - if (virNetworkDNSHostDefParseXMLHook(node, def, networkName, &partialO= kay, - 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 "." @@ -1038,8 +978,8 @@ virNetworkDNSDefParseXML(const char *networkName, goto cleanup; =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, NULL) < 0) { goto cleanup; } def->nhosts++; @@ -3498,6 +3438,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 @@ -3511,7 +3452,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, ¬Add= ) < 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 c867f27..b715dc3 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.17.1