From patchwork Tue Apr 5 09:50:10 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 8749291 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id E102D9F36E for ; Tue, 5 Apr 2016 09:56:28 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 2FD4D20268 for ; Tue, 5 Apr 2016 09:56:28 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 7249220220 for ; Tue, 5 Apr 2016 09:56:27 +0000 (UTC) Received: from localhost ([::1]:35692 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1anNik-0005VO-VW for patchwork-qemu-devel@patchwork.kernel.org; Tue, 05 Apr 2016 05:56:26 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54866) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1anNd5-0003ZN-Ot for qemu-devel@nongnu.org; Tue, 05 Apr 2016 05:50:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1anNd2-0001Am-Ls for qemu-devel@nongnu.org; Tue, 05 Apr 2016 05:50:35 -0400 Received: from mail-wm0-x242.google.com ([2a00:1450:400c:c09::242]:36592) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1anNd2-00019Z-67 for qemu-devel@nongnu.org; Tue, 05 Apr 2016 05:50:32 -0400 Received: by mail-wm0-x242.google.com with SMTP id 20so2670492wmh.3 for ; Tue, 05 Apr 2016 02:50:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=zKXGKFtsNiXSHE8VpoieYoe/iXW2krLPg3ibdYX6t5k=; b=CPnF5ELbq4mLb2So3ZB0Abs61lWnoTx4v7KpYwSv+kdkr1fiBknzxIxex3pPjzgrzj mMQldTdZbqRUjm8sXfjHjilV4NtVvmkLciJJpaXWYIouibom+lehEKb3e50zjMbYFgMC qDKQmxILyvwT648W4f1ZIgVSM8k8QZF58VMsf6nDHs49HlRNi8XjdcaBXt93tE7SefCe D5Sj48NVYZmLt5lgsyte1yIvevxeITervwgPz0f/JJCyHXChQb7YBrHtMKeq814474Fb c3/i/nLu8qamjBWhMmliahFydB29ia0BvkHwZAfvEL7+1Jmrc222jLYyUY3l1XgmPxyj 2/Cg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=zKXGKFtsNiXSHE8VpoieYoe/iXW2krLPg3ibdYX6t5k=; b=euqpV8bh30WKtMUtYAfX5POTG/YyiZPQE4tSd6acq7bEvJEZnerbOvlFMGzwmXh7d2 +NRKkdgGeGa+XgkJasO7QsoCXB1HkcMjryhNMFwPzzvmu5IsVptd/scCC1MdAY63wM2i Upnnm8gW83CqMsXGZ2sw4Od6EvRiLaIRD+J7UXVbUfHw1QkyWMGuCOdlW0sDojJ3LqCB nKa9SZGrkE0Vn54B6eXEX7HcdNiptuMJn4jOIeRUJq0MkITueoY42IyCpvywiateVNN4 VAt9rfLRx7tcwPkvjxQ9OZzQfcOzrxc4fxY7TRgiOeGm45JiQUH5ODLiENQ5nv4YOOOm RUqg== X-Gm-Message-State: AD7BkJIvkVTQzQk5O4JP8knxWlADC3VW7yoxYwuTVjb+0pRS4Gw0+NiLudWrc9NMcdtoHw== X-Received: by 10.194.236.198 with SMTP id uw6mr12069716wjc.42.1459849831480; Tue, 05 Apr 2016 02:50:31 -0700 (PDT) Received: from donizetti.lan (94-39-141-76.adsl-ull.clienti.tiscali.it. [94.39.141.76]) by smtp.gmail.com with ESMTPSA id ka4sm33721377wjc.47.2016.04.05.02.50.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 05 Apr 2016 02:50:30 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Tue, 5 Apr 2016 11:50:10 +0200 Message-Id: <1459849818-26649-8-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 2.5.5 In-Reply-To: <1459849818-26649-1-git-send-email-pbonzini@redhat.com> References: <1459849818-26649-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:400c:c09::242 Cc: Paolo Bonzini Subject: [Qemu-devel] [PULL 07/15] util: retry getaddrinfo if getting EAI_BADFLAGS with AI_V4MAPPED X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: "Daniel P. Berrange" The FreeBSD header files define the AI_V4MAPPED but its implementation of getaddrinfo() always returns an error when that flag is set. eg address resolution failed for localhost:9000: Invalid value for ai_flags There are also reports of the same problem on OS-X 10.6 Since AI_V4MAPPED is not critical functionality, if we get an EAI_BADFLAGS error then just retry without the AI_V4MAPPED flag set. Use a static var to cache this status so we don't have to retry on every single call. Also remove its use from the test suite since it serves no useful purpose there. Signed-off-by: Daniel P. Berrange Message-Id: <1459786920-15961-1-git-send-email-berrange@redhat.com> Signed-off-by: Paolo Bonzini --- tests/test-io-channel-socket.c | 5 +---- util/qemu-sockets.c | 19 ++++++++++++++++++- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/tests/test-io-channel-socket.c b/tests/test-io-channel-socket.c index 9d94adb..855306b 100644 --- a/tests/test-io-channel-socket.c +++ b/tests/test-io-channel-socket.c @@ -27,9 +27,6 @@ #ifndef AI_ADDRCONFIG # define AI_ADDRCONFIG 0 #endif -#ifndef AI_V4MAPPED -# define AI_V4MAPPED 0 -#endif #ifndef EAI_ADDRFAMILY # define EAI_ADDRFAMILY 0 #endif @@ -42,7 +39,7 @@ static int check_bind(const char *hostname, bool *has_proto) int ret = -1; memset(&ai, 0, sizeof(ai)); - ai.ai_flags = AI_CANONNAME | AI_V4MAPPED | AI_ADDRCONFIG; + ai.ai_flags = AI_CANONNAME | AI_ADDRCONFIG; ai.ai_family = AF_UNSPEC; ai.ai_socktype = SOCK_STREAM; diff --git a/util/qemu-sockets.c b/util/qemu-sockets.c index b87e17f..0d53691 100644 --- a/util/qemu-sockets.c +++ b/util/qemu-sockets.c @@ -29,6 +29,7 @@ #ifndef AI_ADDRCONFIG # define AI_ADDRCONFIG 0 #endif + #ifndef AI_V4MAPPED # define AI_V4MAPPED 0 #endif @@ -354,10 +355,14 @@ static struct addrinfo *inet_parse_connect_saddr(InetSocketAddress *saddr, struct addrinfo ai, *res; int rc; Error *err = NULL; + static int useV4Mapped = 1; memset(&ai, 0, sizeof(ai)); - ai.ai_flags = AI_CANONNAME | AI_V4MAPPED | AI_ADDRCONFIG; + ai.ai_flags = AI_CANONNAME | AI_ADDRCONFIG; + if (atomic_read(&useV4Mapped)) { + ai.ai_flags |= AI_V4MAPPED; + } ai.ai_family = inet_ai_family_from_address(saddr, &err); ai.ai_socktype = SOCK_STREAM; @@ -373,6 +378,18 @@ static struct addrinfo *inet_parse_connect_saddr(InetSocketAddress *saddr, /* lookup */ rc = getaddrinfo(saddr->host, saddr->port, &ai, &res); + + /* At least FreeBSD and OS-X 10.6 declare AI_V4MAPPED but + * then don't implement it in their getaddrinfo(). Detect + * this and retry without the flag since that's preferrable + * to a fatal error + */ + if (rc == EAI_BADFLAGS && + (ai.ai_flags & AI_V4MAPPED)) { + atomic_set(&useV4Mapped, 0); + ai.ai_flags &= ~AI_V4MAPPED; + rc = getaddrinfo(saddr->host, saddr->port, &ai, &res); + } if (rc != 0) { error_setg(errp, "address resolution failed for %s:%s: %s", saddr->host, saddr->port, gai_strerror(rc));