From nobody Mon Apr 29 03:38:21 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; dkim=fail; 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 1527163794759958.9559901694587; Thu, 24 May 2018 05:09:54 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 25DF930B9515; Thu, 24 May 2018 12:09:52 +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 9503045BC; Thu, 24 May 2018 12:09:50 +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 D132F4BB78; Thu, 24 May 2018 12:09:47 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w4OC0YAw023127 for ; Thu, 24 May 2018 08:00:36 -0400 Received: by smtp.corp.redhat.com (Postfix) id 80FBB3083323; Thu, 24 May 2018 12:00:33 +0000 (UTC) Received: from mx1.redhat.com (ext-mx06.extmail.prod.ext.phx2.redhat.com [10.5.110.30]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7A87E307D98E for ; Thu, 24 May 2018 12:00:27 +0000 (UTC) Received: from mo4-p00-ob.smtp.rzone.de (mo4-p00-ob.smtp.rzone.de [85.215.255.21]) (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 2C7B2F8795 for ; Thu, 24 May 2018 12:00:11 +0000 (UTC) Received: from sender by smtp.strato.de (RZmta 43.8 AUTH) with ESMTPSA id h032f7u4OC09f50 (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (curve secp521r1 with 521 ECDH bits, eq. 15360 bits RSA)) (Client did not present a certificate); Thu, 24 May 2018 14:00:09 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1527163209; s=strato-dkim-0002; d=aepfle.de; h=Message-Id:Date:Subject:Cc:To:From:X-RZG-CLASS-ID:X-RZG-AUTH:From: Subject:Sender; bh=7xb5GcAMON+wcqL/i3dy8fLSxI/Q8v1ChwBFAgjwZBA=; b=WrxpCPTQRR8AAoO7E665E8iI1i0NIwEUjol/srLhsFzT9IeWozbkiFnUrDyq40n/kw fxQ244b+FYLbZscJGuP8urwCNF8lfE/MAeviDqJiDd9RrO8ZmoyWpQhLmwUwEHMD4XJ8 EtYAAdkf2HoMhmXQCwM+PMGoFXtbirzcfSDlKeBFhvMfoVFJTvA30Xs78ky/foervFas NXTtXosd+RKb7WTyQWcYcJOxFh3k2NrnRi7mWbwfMZBj2ozB4fnVXqQEiNmsbscmWZRY TmBNIElBZLOZQzevjUkQHqSSJAviCQ8+bgROPzGAShtfAu7rwryWU3Xt6qdz8Cuu6i8b g+mg== X-RZG-AUTH: ":P2EQZWCpfu+qG7CngxMFH1J+3q8wa/QXkBR9MXjAuzpIG0mv9coXAgc09VbzR8stxx+XNVGnx9ZX3co74kFtJGu5gyLH" X-RZG-CLASS-ID: mo00 From: Olaf Hering To: libvir-list@redhat.com Date: Thu, 24 May 2018 14:00:06 +0200 Message-Id: <20180524120006.2694-1-olaf@aepfle.de> MIME-Version: 1.0 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.30]); Thu, 24 May 2018 12:00:12 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Thu, 24 May 2018 12:00:12 +0000 (UTC) for IP:'85.215.255.21' DOMAIN:'mo4-p00-ob.smtp.rzone.de' HELO:'mo4-p00-ob.smtp.rzone.de' FROM:'olaf@aepfle.de' RCPT:'' X-RedHat-Spam-Score: -0.111 (DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS) 85.215.255.21 mo4-p00-ob.smtp.rzone.de 85.215.255.21 mo4-p00-ob.smtp.rzone.de X-Scanned-By: MIMEDefang 2.78 on 10.5.110.30 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.26 X-loop: libvir-list@redhat.com Cc: Olaf Hering Subject: [libvirt] [PATCH v2] util: Loop through all resolved addresses in virNetSocketNewListenTCP 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: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.47]); Thu, 24 May 2018 12:09:53 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Currently virNetSocketNewListenTCP bails out early under the following conditions: - the hostname resolves to at least one IPv4 and at least one IPv6 address - the local interfaces have that one IPv4 address assigned, but not any of the IPv6 addresses - the local interfaces have just IPv6 link-local addresses In this case the resolver returns not only the IPv4 addresses but also IPv6. Binding the IPv6 address will obviously fail. But this terminates the entire loop, even if binding to IPv4 succeeded. To fix this error, just keep going and loop through all returned addresses. In case none of the attempts to bind to some address succeeded, try to report the appropriate error. Signed-off-by: Olaf Hering --- v2: whitespace fixes, as suggested by John Ferlan src/rpc/virnetsocket.c | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/src/rpc/virnetsocket.c b/src/rpc/virnetsocket.c index 7087abec9c..60a7187348 100644 --- a/src/rpc/virnetsocket.c +++ b/src/rpc/virnetsocket.c @@ -382,11 +382,8 @@ int virNetSocketNewListenTCP(const char *nodename, #endif =20 if (bind(fd, runp->ai_addr, runp->ai_addrlen) < 0) { - if (errno !=3D EADDRINUSE) { - virReportSystemError(errno, "%s", _("Unable to bind to por= t")); - goto error; - } - addrInUse =3D true; + if (errno =3D=3D EADDRINUSE) + addrInUse =3D true; VIR_FORCE_CLOSE(fd); runp =3D runp->ai_next; continue; @@ -409,14 +406,14 @@ int virNetSocketNewListenTCP(const char *nodename, fd =3D -1; } =20 - if (nsocks =3D=3D 0 && familyNotSupported) { - virReportSystemError(EAFNOSUPPORT, "%s", _("Unable to bind to port= ")); - goto error; - } - - if (nsocks =3D=3D 0 && - addrInUse) { - virReportSystemError(EADDRINUSE, "%s", _("Unable to bind to port")= ); + if (nsocks =3D=3D 0) { + if (familyNotSupported) + errno =3D EAFNOSUPPORT; + else if (addrInUse) + errno =3D EADDRINUSE; + else + errno =3D EDESTADDRREQ; + virReportSystemError(errno, "%s", _("Unable to bind to port")); goto error; } =20 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list