MulticastSocket(group,port) problems with bind() with IPv6 enabled

Pekka Savola pekkas at netcore.fi
Fri Dec 5 04:14:39 PST 2008


Hi,

I've looked through the Sun bug database and AFAICS this is not 
listed.  I've also looked through the latest source code to see if 
this is addressed [1], but apparently not.  I'm trying to find a way 
to get this addressed.

When you create a MulticastSocket(new InetSocketAddress(group, port)) 
with an IPv4 address as a string in 'group' on an IPv6-enabled system, 
the socket is created as PF_INET6.  This results in mapping the 
address to mapped address format (e.g. "::ffff:233.1.2.3").

This also results in a bind() system call to the ipv6 mapped address.

On Linux, this fails due to EADDRNOTAVAIL; the kernel does not support 
IPv4 multicast addresses through PF_INET6 socket.  In any case, Java 
doing this is not very portable -- there is huge variance on how 
various implementations treat the mapped addresses; Linux kernel 
implementations are not going to change [2] and as a result, 
applications using MulticastSocket when an ipv4 group is specified on 
IPv6 systems is failing.

The problems here were already identified 7+ years ago (e.g. an IETF 
discussion [3]).

If you don't specify the group, this results in a PF_INET6 socket with 
wildcard bind ("::"), and works to a degree but this has other, 
already known, problems when multiple receivers exist on the saem 
system.

What needs to, IMHO, happen is that at least when creating 
MulticastSocket with a specified group, Java implementation should 
check whether the address is IPv4 or IPv6, and create a PF_INET6 or 
PF_INET socket, instead of always creating PF_INET6 socket if IPv6 is 
enabled.

Another thing that could be useful would be to modify socket creation 
mechanisms so that you could specify whether you want an ipv4 or ipv6 
socket if you know which one you need.

[1]
http://hg.openjdk.java.net/nio/nio/jdk/annotate/0a384911d4e6/src/solaris/native/java/net/PlainSocketImpl.c

[2]
http://www.spinics.net/lists/netdev/msg82611.html

[3]
http://www.mail-archive.com/ipng@sunroof.eng.sun.com/msg02134.html


-- 
Pekka Savola                 "You each name yourselves king, yet the
Netcore Oy                    kingdom bleeds."
Systems. Networks. Security. -- George R.R. Martin: A Clash of Kings



More information about the net-dev mailing list