Skip to contentSkip to conversation

IPv6 multicast bind(), esp. v4-mapped addresses

DISCUSSION Pekka Savola 3 participants 5 messages Dec 5, 2008 – Dec 10, 2008

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

Hi,

Java multicast API uses IPv6 sockets internally unless IPv6 is disabled. In other APIs as well it might be beneficial to be able to use IPv4 through IPv6 mapped addresses. This works fine with unicast, but there are problems with this in multicast (I've also included broadcast here because ipv4 side does that, I don't see the case for it myself).

Specifically, bind() to a v6-mapped v4 multicast address fails with EADDRNOTAVAIL:

bind(7, {sa_family=AF_INET6, sin6_port=htons(2000), inet_pton(AF_INET6, "::ffff:233.12.174.101", &sin6_addr), sin6_flowinfo=0, sin6_scope_id=0}, 28) = -1 EADDRNOTAVAIL (Cannot assign requested address).

Two questions:

1) should this be supported? I think we're talking about a change in net/ipv6/af_inet6.c, replacing something like (not tested, adapted from net/ipv4/af_inet.c):

273 if (addr_type == IPV6_ADDR_MAPPED) {
274 v4addr = addr->sin6_addr.s6_addr32[3];
275 if (inet_addr_type(net, v4addr) != RTN_LOCAL) {
276 err = -EADDRNOTAVAIL;
277 goto out;
278 }
279 } else {

with:

         if (addr_type == IPV6_ADDR_MAPPED) {
                 v4addr = addr->sin6_addr.s6_addr32[3];
		 if (inet_addr_type(net, v4addr) == RTN_MULTICAST ||
		     inet_addr_type(net, v4addr) == RTN_BROADCAST) {
			inet->saddr = 0; /* Use device */
                 } else {
	                 if (inet_addr_type(net, v4addr) != RTN_LOCAL) {
	                         err = -EADDRNOTAVAIL;
	                         goto out;
	                 }
		}
         } else {

2) it appears that ip_nonlocal_bind sysctl only supports ipv4. Similar option or applying the same for v6 may be useful, especially if 1) is not changed, such a toggle might be useful with v6 as well.

You can see some specification discussion on this topic here:
http://www.mail-archive.com/[email protected]/msg02134.html

Signature · 3 lines
Pekka Savola                 "You each name yourselves king, yet the
Netcore Oy                    kingdom bleeds."
Systems. Networks. Security. -- George R.R. Martin: A Clash of Kings
#1 lore raw

Hello.

In article <[email protected]> (at Fri, 5 Dec 2008 08:42:37 +0200 (EET)), Pekka Savola <[email protected]> says:

Quoted 18 lines

Two questions:

1) should this be supported? I think we're talking about a change in net/ipv6/af_inet6.c, replacing something like (not tested, adapted from net/ipv4/af_inet.c):

273 if (addr_type == IPV6_ADDR_MAPPED) {
274 v4addr = addr->sin6_addr.s6_addr32[3];
275 if (inet_addr_type(net, v4addr) != RTN_LOCAL) {
276 err = -EADDRNOTAVAIL;
277 goto out;
278 }
279 } else {

with:

          if (addr_type == IPV6_ADDR_MAPPED) {
                  v4addr = addr->sin6_addr.s6_addr32[3];

Review

Quoted 10 lines
(quoted diff) +0 -0
 		 if (inet_addr_type(net, v4addr) == RTN_MULTICAST ||
 		     inet_addr_type(net, v4addr) == RTN_BROADCAST) {
 			inet->saddr = 0; /* Use device */
                  } else {
 	                 if (inet_addr_type(net, v4addr) != RTN_LOCAL) {
 	                         err = -EADDRNOTAVAIL;
 	                         goto out;
 	                 }
 		}
          } else {

I think similar issue(s) have been pointed out several times. IPv4-mapped addresses are not portable, unfortunately, anyway, and people should use native interface, especially for multicasts.

BTW, do you know what kind of socket option do they use for setting/getting ttl etc?

If we fully support "IPv4-Mapped" function, we should transparently configure ipv4-multicast parameters etc. as well.

Quoted 4 lines

2) it appears that ip_nonlocal_bind sysctl only supports ipv4. Similar option or applying the same for v6 may be useful, especially if 1) is not changed, such a toggle might be useful with v6 as well.

I don't think this could not be an answer.

--yoshfuji

#2 lore raw
Quoted 3 lines · YOSHIFUJI Hideaki / ????

I think similar issue(s) have been pointed out several times. IPv4-mapped addresses are not portable, unfortunately, anyway, and people should use native interface, especially for multicasts.

Yes, there are problems with portability of mapped address usage, but that doesn't have to mean that we shouldn't try to make it as useful as reasonable.

Quoted 4 lines

BTW, do you know what kind of socket option do they use for setting/getting ttl etc?

If we fully support "IPv4-Mapped" function, we should transparently configure ipv4-multicast parameters etc. as well.

It does this:

setsockopt(7, SOL_IPV6, IPV6_MULTICAST_HOPS, [1], 4) = 0

In Java MulticastSocket API, if you only specify the port and not multicast group, it will bind to "::", and it succeeds. Afterwards Java issues an IPv4 IGMP join:

setsockopt(7, SOL_IP, IP_ADD_MEMBERSHIP, "\351\f\f\f\0\0\0\0\0\0\0\0", 12) = 0

So Java implementation will parse whether the group is IPv4 or IPv6 multicast -- it isn't using MCAST_JOIN_GROUP API. It could be argued that if it already knows the protocol, it _could_ create IPv4 socket from the start, instead of doing this via a mapped v6 socket.

Of course, if Java used the protocol-independent MCAST_JOIN_GROUP etc. API, it would not need to even know whether the group was v4 or v6. And from that perspective also it would probably make sense to support a v4-mapped-address bind().

Signature · 3 lines
Pekka Savola                 "You each name yourselves king, yet the
Netcore Oy                    kingdom bleeds."
Systems. Networks. Security. -- George R.R. Martin: A Clash of Kings
maintainer
#3 lore raw

From: Pekka Savola <[email protected]>
Date: Fri, 5 Dec 2008 09:42:43 +0200 (EET)

Quoted 8 lines

It does this:

setsockopt(7, SOL_IPV6, IPV6_MULTICAST_HOPS, [1], 4) = 0

In Java MulticastSocket API, if you only specify the port and not multicast group, it will bind to "::", and it succeeds. Afterwards Java issues an IPv4 IGMP join:

Quoted 8 lines

setsockopt(7, SOL_IP, IP_ADD_MEMBERSHIP, "\351\f\f\f\0\0\0\0\0\0\0\0", 12) = 0

So Java implementation will parse whether the group is IPv4 or IPv6 multicast -- it isn't using MCAST_JOIN_GROUP API. It could be argued that if it already knows the protocol, it _could_ create IPv4 socket from the start, instead of doing this via a mapped v6 socket.

From what I've read, ipv4 mapped addresses are full of all kinds of

tricky cases and issues. And, given that, using ipv4 mapped address for ipv4 multicast is just asking for trouble in my opinion.

#4 lore raw
Quoted 3 lines · David Miller

From what I've read, ipv4 mapped addresses are full of all kinds of tricky cases and issues. And, given that, using ipv4 mapped address for ipv4 multicast is just asking for trouble in my opinion.

FWIW, I've communicated this issue to Java developers. Let's hope they'll enhance their Java shim layer to avoid mapped addresses some time in the future:

http://mail.openjdk.java.net/pipermail/net-dev/2008-December/000494.html

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