Received: from eggs.gnu.org ([2001:4830:134:3::10]:57854) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WJMTU-0005dz-ES for qemu-devel@nongnu.org; Fri, 28 Feb 2014 07:23:38 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WJMTO-00046H-GX for qemu-devel@nongnu.org; Fri, 28 Feb 2014 07:23:32 -0500 Received: from mx1.redhat.com ([209.132.183.28]:35704) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WJMTO-00046C-77 for qemu-devel@nongnu.org; Fri, 28 Feb 2014 07:23:26 -0500 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s1SCNP7G029774 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 28 Feb 2014 07:23:25 -0500 Message-ID: <1393590201.3364.44.camel@nilsson.home.kraxel.org> From: Gerd Hoffmann Date: Fri, 28 Feb 2014 13:23:21 +0100 In-Reply-To: <1393582579-10366-2-git-send-email-pbonzini@redhat.com> References: <1393582579-10366-1-git-send-email-pbonzini@redhat.com> <1393582579-10366-2-git-send-email-pbonzini@redhat.com> Content-Type: text/plain; charset="UTF-8" Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH 1/2] socket: treat ipv4=on, ipv6=on uniformly List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Paolo Bonzini Cc: qemu-devel@nongnu.org, stefanha@redhat.com On Fr, 2014-02-28 at 11:16 +0100, Paolo Bonzini wrote: > In some cases, "ipv4=on,ipv6=on" means "try both kinds of address"; > in others, it means "try IPv6 only" just by virtue of how the code > is structured. > @@ -127,10 +127,13 @@ int inet_listen_opts(QemuOpts *opts, int port_offset, Error **errp) > - if (qemu_opt_get_bool(opts, "ipv4", 0)) > - ai.ai_family = PF_INET; > - if (qemu_opt_get_bool(opts, "ipv6", 0)) > - ai.ai_family = PF_INET6; > + if (qemu_opt_get_bool(opts, "ipv4", 0) != qemu_opt_get_bool(opts, "ipv6", 0)) { > + if (qemu_opt_get_bool(opts, "ipv4", 0)) { > + ai.ai_family = PF_INET; > + } else { > + ai.ai_family = PF_INET6; > + } > + } This is wrong for the listening side. ipv6 sockets can listen on both ipv4 and ipv6. qemu configures ipv6 sockets to do that, unconditionally. So ipv4=yes,ipv6=no works correctly. ipv4=yes,ipv6=yes works too. ipv4=no,ipv6=yes doesn't work, but to fix that you have to set the IPV6_V6ONLY socket option according to the ipv4 option. Canevat: Listening on both ipv4+ipv6 with a single file handle works for the wildcard address only. Specifying -- say -- host=localhost,ipv4=yes,ipv6=yes, then expect qemu to listen on both 127.0.0.1 and ::1 doesn't work. This can only be fixed by allowing multiple listening filehandles. Which is a non-trivial change as this also affects the public api (which will have to report a list of listening addresses instead of a single address). > @@ -319,11 +322,12 @@ static struct addrinfo *inet_parse_connect_opts(QemuOpts *opts, Error **errp) > - if (qemu_opt_get_bool(opts, "ipv4", 0)) { > - ai.ai_family = PF_INET; > - } > - if (qemu_opt_get_bool(opts, "ipv6", 0)) { > - ai.ai_family = PF_INET6; > + if (qemu_opt_get_bool(opts, "ipv4", 0) != qemu_opt_get_bool(opts, "ipv6", 0)) { > + if (qemu_opt_get_bool(opts, "ipv4", 0)) { > + ai.ai_family = PF_INET; > + } else { > + ai.ai_family = PF_INET6; > + } For connect this change is fine I think. > @@ -418,10 +422,13 @@ int inet_dgram_opts(QemuOpts *opts, Error **errp) > - if (qemu_opt_get_bool(opts, "ipv4", 0)) > - ai.ai_family = PF_INET; > - if (qemu_opt_get_bool(opts, "ipv6", 0)) > - ai.ai_family = PF_INET6; > + if (qemu_opt_get_bool(opts, "ipv4", 0) != qemu_opt_get_bool(opts, "ipv6", 0)) { > + if (qemu_opt_get_bool(opts, "ipv4", 0)) { > + ai.ai_family = PF_INET; > + } else { > + ai.ai_family = PF_INET6; > + } > + } Not fully sure, but I think this is fine too. cheers, Gerd