From nobody Tue Dec 16 08:04:47 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1503302858855410.2510377047; Mon, 21 Aug 2017 01:07:38 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 94037883DC; Mon, 21 Aug 2017 08:07:36 +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 6799966835; Mon, 21 Aug 2017 08:07:36 +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 2171D1800C96; Mon, 21 Aug 2017 08:07:36 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v7L87WOn002480 for ; Mon, 21 Aug 2017 04:07:32 -0400 Received: by smtp.corp.redhat.com (Postfix) id E08756F926; Mon, 21 Aug 2017 08:07:32 +0000 (UTC) Received: from antique-work.brq.redhat.com (unknown [10.43.2.152]) by smtp.corp.redhat.com (Postfix) with ESMTP id 679F06F924 for ; Mon, 21 Aug 2017 08:07:32 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 94037883DC Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=libvir-list-bounces@redhat.com From: Pavel Hrdina To: libvir-list@redhat.com Date: Mon, 21 Aug 2017 10:07:11 +0200 Message-Id: <3cc946bdb022e39b55d7aac4f437440fd63694da.1503302799.git.phrdina@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 11/17] conf: move TCP chardev source parsing to separate function 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: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Mon, 21 Aug 2017 08:07:37 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Pavel Hrdina --- src/conf/domain_conf.c | 121 +++++++++++++++++++++++----------------------= ---- 1 file changed, 57 insertions(+), 64 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index e0045eba19..023d86cec5 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -10920,6 +10920,52 @@ virDomainChrSourceDefParseMode(xmlNodePtr source) =20 =20 static int +virDomainChrSourceDefParseTCP(virDomainChrSourceDefPtr def, + xmlNodePtr source, + unsigned int flags) +{ + int mode; + char *tmp =3D NULL; + int tmpVal; + + if ((mode =3D virDomainChrSourceDefParseMode(source)) < 0) + goto error; + + def->data.tcp.listen =3D mode =3D=3D VIR_DOMAIN_CHR_SOURCE_MODE_BIND; + def->data.tcp.host =3D virXMLPropString(source, "host"); + def->data.tcp.service =3D virXMLPropString(source, "service"); + + if ((tmp =3D virXMLPropString(source, "tls"))) { + if ((def->data.tcp.haveTLS =3D virTristateBoolTypeFromString(tmp))= <=3D 0) { + virReportError(VIR_ERR_XML_ERROR, + _("unknown chardev 'tls' setting '%s'"), + tmp); + goto error; + } + VIR_FREE(tmp); + } + + if ((flags & VIR_DOMAIN_DEF_PARSE_STATUS) && + (tmp =3D virXMLPropString(source, "tlsFromConfig"))) { + if (virStrToLong_i(tmp, NULL, 10, &tmpVal) < 0) { + virReportError(VIR_ERR_XML_ERROR, + _("Invalid tlsFromConfig value: %s"), + tmp); + goto error; + } + def->data.tcp.tlsFromConfig =3D !!tmpVal; + VIR_FREE(tmp); + } + + return 0; + + error: + VIR_FREE(tmp); + return -1; +} + + +static int virDomainChrSourceDefParseProtocol(virDomainChrSourceDefPtr def, xmlNodePtr protocol) { @@ -10991,8 +11037,6 @@ virDomainChrSourceDefParseXML(virDomainChrSourceDef= Ptr def, char *master =3D NULL; char *slave =3D NULL; char *append =3D NULL; - char *haveTLS =3D NULL; - char *tlsFromConfig =3D NULL; bool logParsed =3D false; bool protocolParsed =3D false; int sourceParsed =3D 0; @@ -11018,11 +11062,6 @@ virDomainChrSourceDefParseXML(virDomainChrSourceDe= fPtr def, } sourceParsed++; =20 - if (!haveTLS) - haveTLS =3D virXMLPropString(cur, "tls"); - if (!tlsFromConfig) - tlsFromConfig =3D virXMLPropString(cur, "tlsFromConfig"); - switch ((virDomainChrType) def->type) { case VIR_DOMAIN_CHR_TYPE_FILE: case VIR_DOMAIN_CHR_TYPE_PTY: @@ -11044,7 +11083,6 @@ virDomainChrSourceDefParseXML(virDomainChrSourceDef= Ptr def, break; =20 case VIR_DOMAIN_CHR_TYPE_UDP: - case VIR_DOMAIN_CHR_TYPE_TCP: if ((mode =3D virDomainChrSourceDefParseMode(cur)) < 0) goto error; if (mode =3D=3D VIR_DOMAIN_CHR_SOURCE_MODE_CONNECT) { @@ -11058,7 +11096,11 @@ virDomainChrSourceDefParseXML(virDomainChrSourceDe= fPtr def, if (!bindService) bindService =3D virXMLPropString(cur, "service"); } + break; =20 + case VIR_DOMAIN_CHR_TYPE_TCP: + if (virDomainChrSourceDefParseTCP(def, cur, flags) < 0) + goto error; break; =20 case VIR_DOMAIN_CHR_TYPE_SPICEPORT: @@ -11168,63 +11210,16 @@ virDomainChrSourceDefParseXML(virDomainChrSourceD= efPtr def, break; =20 case VIR_DOMAIN_CHR_TYPE_TCP: - if (mode =3D=3D VIR_DOMAIN_CHR_SOURCE_MODE_CONNECT) { - if (!connectHost) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("Missing source host attribute for char d= evice")); - goto error; - } - - if (!connectService) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("Missing source service attribute for cha= r device")); - goto error; - } - - def->data.tcp.host =3D connectHost; - connectHost =3D NULL; - def->data.tcp.service =3D connectService; - connectService =3D NULL; - def->data.tcp.listen =3D false; - } else if (mode =3D=3D VIR_DOMAIN_CHR_SOURCE_MODE_BIND) { - if (!bindHost) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("Missing source host attribute for char d= evice")); - goto error; - } - - if (!bindService) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("Missing source service attribute for cha= r device")); - goto error; - } - - def->data.tcp.host =3D bindHost; - bindHost =3D NULL; - def->data.tcp.service =3D bindService; - bindService =3D NULL; - def->data.tcp.listen =3D true; - } - - if (haveTLS && - (def->data.tcp.haveTLS =3D - virTristateBoolTypeFromString(haveTLS)) <=3D 0) { - virReportError(VIR_ERR_XML_ERROR, - _("unknown chardev 'tls' setting '%s'"), - haveTLS); + if (!def->data.tcp.host) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Missing source host attribute for char devic= e")); goto error; } =20 - if (tlsFromConfig && - flags & VIR_DOMAIN_DEF_PARSE_STATUS) { - int tmp; - if (virStrToLong_i(tlsFromConfig, NULL, 10, &tmp) < 0) { - virReportError(VIR_ERR_XML_ERROR, - _("Invalid tlsFromConfig value: %s"), - tlsFromConfig); - goto error; - } - def->data.tcp.tlsFromConfig =3D !!tmp; + if (!def->data.tcp.service) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Missing source service attribute for char de= vice")); + goto error; } break; =20 @@ -11288,8 +11283,6 @@ virDomainChrSourceDefParseXML(virDomainChrSourceDef= Ptr def, VIR_FREE(path); VIR_FREE(channel); VIR_FREE(append); - VIR_FREE(haveTLS); - VIR_FREE(tlsFromConfig); =20 return ret; =20 --=20 2.13.5 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list