From patchwork Tue Jun 23 17:22:02 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Tokarev X-Patchwork-Id: 487743 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id B5863140157 for ; Wed, 24 Jun 2015 03:22:40 +1000 (AEST) Received: from localhost ([::1]:46625 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z7RuA-0005zx-Ro for incoming@patchwork.ozlabs.org; Tue, 23 Jun 2015 13:22:38 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45759) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z7Rtk-0005FY-3b for qemu-devel@nongnu.org; Tue, 23 Jun 2015 13:22:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Z7Rtc-0001V4-Ux for qemu-devel@nongnu.org; Tue, 23 Jun 2015 13:22:12 -0400 Received: from isrv.corpit.ru ([86.62.121.231]:44577) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z7Rtc-0001Uk-O3; Tue, 23 Jun 2015 13:22:04 -0400 Received: from tsrv.tls.msk.ru (tsrv.tls.msk.ru [192.168.177.2]) by isrv.corpit.ru (Postfix) with ESMTP id 29121420E4; Tue, 23 Jun 2015 20:22:04 +0300 (MSK) Received: from tls.msk.ru (mjt.vpn.tls.msk.ru [192.168.177.99]) by tsrv.tls.msk.ru (Postfix) with SMTP id 1778D951; Tue, 23 Jun 2015 20:22:04 +0300 (MSK) Received: (nullmailer pid 14730 invoked by uid 1000); Tue, 23 Jun 2015 17:22:04 -0000 From: Michael Tokarev To: qemu-devel@nongnu.org Date: Tue, 23 Jun 2015 20:22:02 +0300 Message-Id: <2bf6b5e90b4226d67c05fadbe105265b4c8e39ea.1435079841.git.mjt@msgid.tls.msk.ru> X-Mailer: git-send-email 2.1.4 In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 86.62.121.231 Cc: qemu-trivial@nongnu.org, Wolfgang Bumiller , Michael Tokarev Subject: [Qemu-devel] [PULL 21/21] util/qemu-sockets: improve ai_flag hints for ipv6 hosts 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Wolfgang Bumiller *) Do not use AI_ADDRCONFIG on listening sockets, because this flag makes it impossible to explicitly listen on '127.0.0.1' if no global ipv4 address is configured additionally, making this a very uncomfortable option. *) Add AI_V4MAPPED hint for connecting sockets. If your system is globally only connected via ipv6 you often still want to be able to use '127.0.0.1' and 'localhost' (even if localhost doesn't also have an ipv6 entry). For example, PVE - unless explicitly asking for insecure mode - uses ipv4 loopback addresses with QEMU for live migrations tunneled over SSH. These fail to start because AI_ADDRCONFIG makes getaddrinfo refuse to work with '127.0.0.1'. As for the AI_V4MAPPED flag: glibc uses it by default, and providing non-0 flags removes it. I think it makes sense to use it. I also want to point out that glibc explicitly sidesteps POSIX standards when passing 0 as hints by then assuming both AI_V4MAPPED and AI_ADDRCONFIG (the latter being a rather weird choice IMO), while according to POSIX.1-2001 it should be assumed 0. (glibc considers its choice an improvement.) Since either AI_CANONNAME or AI_PASSIVE are passed in our cases, glibc's default flags in turn are disabled again unless explicitly added, which I do with this patch. Signed-off-by: Wolfgang Bumiller Signed-off-by: Michael Tokarev --- util/qemu-sockets.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/util/qemu-sockets.c b/util/qemu-sockets.c index 4026314..2add83a 100644 --- a/util/qemu-sockets.c +++ b/util/qemu-sockets.c @@ -29,6 +29,9 @@ #ifndef AI_ADDRCONFIG # define AI_ADDRCONFIG 0 #endif +#ifndef AI_V4MAPPED +# define AI_V4MAPPED 0 +#endif /* used temporarily until all users are converted to QemuOpts */ QemuOptsList socket_optslist = { @@ -118,7 +121,7 @@ int inet_listen_opts(QemuOpts *opts, int port_offset, Error **errp) int slisten, rc, to, port_min, port_max, p; memset(&ai,0, sizeof(ai)); - ai.ai_flags = AI_PASSIVE | AI_ADDRCONFIG; + ai.ai_flags = AI_PASSIVE; ai.ai_family = PF_UNSPEC; ai.ai_socktype = SOCK_STREAM; @@ -335,7 +338,7 @@ static struct addrinfo *inet_parse_connect_opts(QemuOpts *opts, Error **errp) memset(&ai, 0, sizeof(ai)); - ai.ai_flags = AI_CANONNAME | AI_ADDRCONFIG; + ai.ai_flags = AI_CANONNAME | AI_V4MAPPED | AI_ADDRCONFIG; ai.ai_family = PF_UNSPEC; ai.ai_socktype = SOCK_STREAM; @@ -435,7 +438,7 @@ int inet_dgram_opts(QemuOpts *opts, Error **errp) /* lookup peer addr */ memset(&ai,0, sizeof(ai)); - ai.ai_flags = AI_CANONNAME | AI_ADDRCONFIG; + ai.ai_flags = AI_CANONNAME | AI_V4MAPPED | AI_ADDRCONFIG; ai.ai_family = PF_UNSPEC; ai.ai_socktype = SOCK_DGRAM;