From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1KupbQ-0000vz-Aj for qemu-devel@nongnu.org; Tue, 28 Oct 2008 10:31:24 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1KupbP-0000tk-9V for qemu-devel@nongnu.org; Tue, 28 Oct 2008 10:31:23 -0400 Received: from [199.232.76.173] (port=43681 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KupbP-0000tP-44 for qemu-devel@nongnu.org; Tue, 28 Oct 2008 10:31:23 -0400 Received: from mx1.redhat.com ([66.187.233.31]:55785) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1KupbO-0007s7-PY for qemu-devel@nongnu.org; Tue, 28 Oct 2008 10:31:22 -0400 Received: from int-mx1.corp.redhat.com (int-mx1.corp.redhat.com [172.16.52.254]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id m9SEVLNI021247 for ; Tue, 28 Oct 2008 10:31:22 -0400 Date: Tue, 28 Oct 2008 14:31:19 +0000 From: "Daniel P. Berrange" Subject: Re: [Qemu-devel] [PATCH 2/4] sockets: helper functions for qemu. Message-ID: <20081028143119.GX18016@redhat.com> References: <1225198518-16529-1-git-send-email-kraxel@redhat.com> <1225198518-16529-3-git-send-email-kraxel@redhat.com> <20081028131554.GV18016@redhat.com> <4907202B.9090703@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <4907202B.9090703@redhat.com> Reply-To: "Daniel P. Berrange" , qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Gerd Hoffmann Cc: qemu-devel@nongnu.org On Tue, Oct 28, 2008 at 03:22:35PM +0100, Gerd Hoffmann wrote: > Daniel P. Berrange wrote: > >> + memset(&ai,0, sizeof(ai)); > >> + ai.ai_flags = AI_PASSIVE; > > > > You should also set AI_ADDRCONFIG here. This ensure that it only > > returns IPv6 addresses if a network interface actally has IPv6 > > enabled. So if someone's disabled IPv6 on a machine, and DNS still > > has IPv6 addrs, AI_ADDRCONFIG will stop QEMU pointlessly attempting > > to create IPv6 sockets that won't do anything > > Done. > > >> + if (e->ai_family == PF_INET6) { > >> + if (default_family == PF_INET6) > >> + setsockopt(slisten,IPPROTO_IPV6,IPV6_V6ONLY,&on,sizeof(on)); > >> + else > >> + setsockopt(slisten,IPPROTO_IPV6,IPV6_V6ONLY,&off,sizeof(off)); > >> + } > > > One small problem here - for a server you need to expect more than one > > socket will be required. This is because some operating systems require > > you to bind to IPv4 and IPv6 sockets separately. > > Sure? I've googled a bit on this issue, looked what apache does here. > I've figured this can be changed per socket, with a system-wide default > configurable via sysctl (and different OSes have different default > configs here). Ah, I was mis-understanding what IPV6_V6ONLY was doing here. If that's portable to BSD like OS too, then I reckon that's sufficient and would avoid need for separate sockets. > The setsockopt code snippet quoted above should take care about that > issue and turn off the v6only option for the socket (unless the user > explicitly asked for IPv6 using the '-ipv6' command line option). > > > So we really need an array of server sockets, and attempt to > > bind to all addresses returned by getaddrinfo(). > > I'm trying to get around that if possible ... > > > There's more info on this here > > > > http://people.redhat.com/drepper/userapi-ipv6.html > > Hmm, IPV6_V6ONLY not mentioned there ... Uli was demonstrating how to achieve total protocol independance in your code. So if someone invents something better even than IPv6 your code would still work. If you're happy to limit yourself to just IPv4 & IPv6, then the IPV6_V6ONLY trick would work. Daniel -- |: Red Hat, Engineering, London -o- http://people.redhat.com/berrange/ :| |: http://libvirt.org -o- http://virt-manager.org -o- http://ovirt.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|