From nobody Thu May 2 06:26:58 2024 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 1522096247081373.954377968049; Mon, 26 Mar 2018 13:30:47 -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 C54D22820A; Mon, 26 Mar 2018 20:30:45 +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 968FD5C25A; Mon, 26 Mar 2018 20:30:45 +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 601544CA9B; Mon, 26 Mar 2018 20:30:45 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w2QKUIRP021283 for ; Mon, 26 Mar 2018 16:30:18 -0400 Received: by smtp.corp.redhat.com (Postfix) id B1CBE2D340; Mon, 26 Mar 2018 20:30:18 +0000 (UTC) Received: from mx1.redhat.com (ext-mx09.extmail.prod.ext.phx2.redhat.com [10.5.110.38]) by smtp.corp.redhat.com (Postfix) with ESMTPS id AB2D560930 for ; Mon, 26 Mar 2018 20:30:15 +0000 (UTC) Received: from smtp2.provo.novell.com (smtp2.provo.novell.com [137.65.250.81]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id DBBD3680F9 for ; Mon, 26 Mar 2018 20:30:13 +0000 (UTC) Received: from linux-tbji.provo.novell.com (prv-ext-foundry1int.gns.novell.com [137.65.251.240]) by smtp2.provo.novell.com with ESMTP (NOT encrypted); Mon, 26 Mar 2018 14:30:10 -0600 From: Jim Fehlig To: libvir-list@redhat.com Date: Mon, 26 Mar 2018 14:29:39 -0600 Message-Id: <20180326202940.25697-2-jfehlig@suse.com> In-Reply-To: <20180326202940.25697-1-jfehlig@suse.com> References: <20180326202940.25697-1-jfehlig@suse.com> X-Greylist: Sender passed SPF test, Sender IP whitelisted by DNSRBL, ACL 207 matched, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Mon, 26 Mar 2018 20:30:14 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Mon, 26 Mar 2018 20:30:14 +0000 (UTC) for IP:'137.65.250.81' DOMAIN:'smtp2.provo.novell.com' HELO:'smtp2.provo.novell.com' FROM:'jfehlig@suse.com' RCPT:'' X-RedHat-Spam-Score: -2.301 (RCVD_IN_DNSWL_MED, SPF_PASS) 137.65.250.81 smtp2.provo.novell.com 137.65.250.81 smtp2.provo.novell.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.38 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 1/2] util: honor reportError parameter in virSocketAddrParseInternal 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.30]); Mon, 26 Mar 2018 20:30:46 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Jim Fehlig Reviewed-by: John Ferlan --- src/util/virsocketaddr.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/util/virsocketaddr.c b/src/util/virsocketaddr.c index 95b527436..31a740cb8 100644 --- a/src/util/virsocketaddr.c +++ b/src/util/virsocketaddr.c @@ -107,7 +107,8 @@ virSocketAddrParseInternal(struct addrinfo **res, int err; =20 if (val =3D=3D NULL) { - virReportError(VIR_ERR_INVALID_ARG, "%s", _("Missing address")); + if (reportError) + virReportError(VIR_ERR_INVALID_ARG, "%s", _("Missing address")= ); return -1; } =20 --=20 2.16.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu May 2 06:26:58 2024 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 1522096227217406.91117063587524; Mon, 26 Mar 2018 13:30:27 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id 87A7243A46; Mon, 26 Mar 2018 20:30:25 +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 7B3335D6A8; Mon, 26 Mar 2018 20:30:24 +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 C66F14CA96; Mon, 26 Mar 2018 20:30:20 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w2QKUIRr021284 for ; Mon, 26 Mar 2018 16:30:18 -0400 Received: by smtp.corp.redhat.com (Postfix) id B15E760A9E; Mon, 26 Mar 2018 20:30:18 +0000 (UTC) Received: from mx1.redhat.com (ext-mx04.extmail.prod.ext.phx2.redhat.com [10.5.110.28]) by smtp.corp.redhat.com (Postfix) with ESMTPS id AB27B608EE for ; Mon, 26 Mar 2018 20:30:15 +0000 (UTC) Received: from smtp2.provo.novell.com (smtp2.provo.novell.com [137.65.250.81]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 07CBB85545 for ; Mon, 26 Mar 2018 20:30:14 +0000 (UTC) Received: from linux-tbji.provo.novell.com (prv-ext-foundry1int.gns.novell.com [137.65.251.240]) by smtp2.provo.novell.com with ESMTP (NOT encrypted); Mon, 26 Mar 2018 14:30:11 -0600 From: Jim Fehlig To: libvir-list@redhat.com Date: Mon, 26 Mar 2018 14:29:40 -0600 Message-Id: <20180326202940.25697-3-jfehlig@suse.com> In-Reply-To: <20180326202940.25697-1-jfehlig@suse.com> References: <20180326202940.25697-1-jfehlig@suse.com> X-Greylist: Sender passed SPF test, Sender IP whitelisted by DNSRBL, ACL 207 matched, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Mon, 26 Mar 2018 20:30:14 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Mon, 26 Mar 2018 20:30:14 +0000 (UTC) for IP:'137.65.250.81' DOMAIN:'smtp2.provo.novell.com' HELO:'smtp2.provo.novell.com' FROM:'jfehlig@suse.com' RCPT:'' X-RedHat-Spam-Score: -2.301 (RCVD_IN_DNSWL_MED, SPF_PASS) 137.65.250.81 smtp2.provo.novell.com 137.65.250.81 smtp2.provo.novell.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.28 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 2/2] util: introduce virSocketAddrParseAny 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.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Mon, 26 Mar 2018 20:30:25 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" When preparing for migration, the libxl driver creates a new TCP listen socket for the incoming migration by calling virNetSocketNewListenTCP, passing the destination host name. virNetSocketNewListenTCP calls virSocketAddrParse to check if the host name is a wildcard address, in which case it avoids adding the AI_ADDRCONFIG flag to the hints passed to getaddrinfo. If the host name is not an IP address, virSocketAddrParse reports an error error : virSocketAddrParseInternal:121 : Cannot parse socket address 'myhost.example.com': Name or service not known But virNetSocketNewListenTCP succeeds regardless and the overall migration operation succeeds. Introduce virSocketAddrParseAny and use it when simply testing if a host name/addr is parsable. Signed-off-by: Jim Fehlig Reviewed-by: John Ferlan --- Essentially a V2 of https://www.redhat.com/archives/libvir-list/2018-March/msg01120.html It takes a slightly different approach by creating a function that can parse host names or IP addresses. src/libvirt_private.syms | 1 + src/rpc/virnetsocket.c | 2 +- src/util/virsocketaddr.c | 50 ++++++++++++++++++++++++++++++++++++++++++++= +--- src/util/virsocketaddr.h | 5 +++++ 4 files changed, 54 insertions(+), 4 deletions(-) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 03fe3b315..f6cdcde72 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -2725,6 +2725,7 @@ virSocketAddrMask; virSocketAddrMaskByPrefix; virSocketAddrNumericFamily; virSocketAddrParse; +virSocketAddrParseAny; virSocketAddrParseIPv4; virSocketAddrParseIPv6; virSocketAddrPrefixToNetmask; diff --git a/src/rpc/virnetsocket.c b/src/rpc/virnetsocket.c index 2d41a716b..f362a0955 100644 --- a/src/rpc/virnetsocket.c +++ b/src/rpc/virnetsocket.c @@ -333,7 +333,7 @@ int virNetSocketNewListenTCP(const char *nodename, * startup in most cases. */ if (nodename && - !(virSocketAddrParse(&tmp_addr, nodename, AF_UNSPEC) > 0 && + !(virSocketAddrParseAny(&tmp_addr, nodename, AF_UNSPEC, false) > 0= && virSocketAddrIsWildcard(&tmp_addr))) hints.ai_flags |=3D AI_ADDRCONFIG; =20 diff --git a/src/util/virsocketaddr.c b/src/util/virsocketaddr.c index 31a740cb8..84610560f 100644 --- a/src/util/virsocketaddr.c +++ b/src/util/virsocketaddr.c @@ -101,6 +101,7 @@ static int virSocketAddrParseInternal(struct addrinfo **res, const char *val, int family, + int ai_flags, bool reportError) { struct addrinfo hints; @@ -114,7 +115,7 @@ virSocketAddrParseInternal(struct addrinfo **res, =20 memset(&hints, 0, sizeof(hints)); hints.ai_family =3D family; - hints.ai_flags =3D AI_NUMERICHOST; + hints.ai_flags =3D ai_flags; if ((err =3D getaddrinfo(val, NULL, &hints, res)) !=3D 0) { if (reportError) virReportError(VIR_ERR_SYSTEM_ERROR, @@ -143,7 +144,7 @@ int virSocketAddrParse(virSocketAddrPtr addr, const cha= r *val, int family) int len; struct addrinfo *res; =20 - if (virSocketAddrParseInternal(&res, val, family, true) < 0) + if (virSocketAddrParseInternal(&res, val, family, AI_NUMERICHOST, true= ) < 0) return -1; =20 if (res =3D=3D NULL) { @@ -163,6 +164,49 @@ int virSocketAddrParse(virSocketAddrPtr addr, const ch= ar *val, int family) return len; } =20 +/** + * virSocketAddrParseAny: + * @addr: where to store the return value, optional. + * @val: a network host name or a numeric network address IPv4 or IPv6 + * @family: address family to pass down to getaddrinfo + * @reportError: boolean to control error reporting + * + * Mostly a wrapper for getaddrinfo() extracting the address storage + * from a host name like acme.example.com or a numeric string like 1.2.3.4 + * or 2001:db8:85a3:0:0:8a2e:370:7334 + * + * Returns the length of the network address or -1 in case of error. + */ +int virSocketAddrParseAny(virSocketAddrPtr addr, + const char *val, + int family, + bool reportError) +{ + int len; + struct addrinfo *res; + + if (virSocketAddrParseInternal(&res, val, family, 0, reportError) < 0) + return -1; + + if (res =3D=3D NULL) { + if (reportError) { + virReportError(VIR_ERR_SYSTEM_ERROR, + _("No socket addresses found for '%s'"), + val); + } + return -1; + } + + len =3D res->ai_addrlen; + if (addr !=3D NULL) { + memcpy(&addr->data.stor, res->ai_addr, len); + addr->len =3D res->ai_addrlen; + } + + freeaddrinfo(res); + return len; +} + /* * virSocketAddrParseIPv4: * @val: an IPv4 numeric address @@ -1105,7 +1149,7 @@ virSocketAddrNumericFamily(const char *address) struct addrinfo *res; unsigned short family; =20 - if (virSocketAddrParseInternal(&res, address, AF_UNSPEC, false) < 0) + if (virSocketAddrParseInternal(&res, address, AF_UNSPEC, AI_NUMERICHOS= T, false) < 0) return -1; =20 family =3D res->ai_addr->sa_family; diff --git a/src/util/virsocketaddr.h b/src/util/virsocketaddr.h index 80e792618..302933848 100644 --- a/src/util/virsocketaddr.h +++ b/src/util/virsocketaddr.h @@ -92,6 +92,11 @@ int virSocketAddrParse(virSocketAddrPtr addr, const char *val, int family); =20 +int virSocketAddrParseAny(virSocketAddrPtr addr, + const char *val, + int family, + bool reportError); + int virSocketAddrParseIPv4(virSocketAddrPtr addr, const char *val); =20 --=20 2.16.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list