IPv4 socket bind using IPv6 socket on openjdk6 breaks udp send

Matthias Andree matthias.andree at gmx.de
Fri Jun 24 23:20:26 UTC 2011


Removing -java@ list because the VM is an application on top of the
kernel's network stack, and the issue isn't Java-specific.

Am 24.06.2011 23:11, schrieb Steven Hartland:
> We're trying to get our machines IPv6 enabled but in doing so this
> seems to break java apps using openjdk6 for UDP sends.
> 
> The server seems quite happy to send and receive TCP packets on
> IPv6 socket that are bound to IPv4 addresses, but the same is not
> true for UDP.

Coincidence, and not guaranteed to work, and possibly using IPv4-mapped
IPv4 addresses (i. e. ::ffff:10.11.12.13 style).

See the v6-related sections of
<http://www.freebsd.org/doc/en/books/developers-handbook/ipv6.html>

> The socket bind works fine and the packets sent to the server arrive
> and are processed by the app but when it tries to reply using
> send the result is:-
> java.io.IOException: Invalid argument
>        at java.net.PlainDatagramSocketImpl.send(Native Method)
>        at java.net.DatagramSocket.send(DatagramSocket.java:629)
> 
> using truss we see the following:-
> socket(PF_INET6,SOCK_DGRAM,0)            = 20 (0x14)
> setsockopt(0x14,0x29,0x1b,0x7ffffedf0318,0x4,0x0) = 0 (0x0)
> setsockopt(0x14,0xffff,0x20,0x7ffffedf031c,0x4,0x0) = 0 (0x0)
> bind(20,{ AF_INET6 [3800::10:0:0:0]:20736 },28)  = 0 (0x0)
> ..
> sendto(20,"\M^?\M^?\M^?\M^?I\aMultiplay :: "...,82,0x0,{ AF_INET6
> [3800::10:0:0:0]:20736 },0x1c) ERR#22 'Invalid argument'

You're trying to send to your own address, but you're likely not using
the loopback interface for that.  Is that permitted by your firewall
configuration and routing?

> sockstat shows it binding correctly
> root     java       894   21 tcp4   85.236.109.212:25675  *:*

This is unrelated, as it has fd #21 not #20 as in the socket/bind/sendto
calls.  You've quoted the wrong line from sockstat output.

> Note: net.inet6.ip6.v6only was set to the default 1 but changing
> it to 0 has no effect on the issue.

You aren't using IPv4 mapped addresses, and you haven't stated whether
you're using wildcard listeners. Only in that case would it matter.

inet6(4) reads:

  IPV6CTL_V6ONLY    (ip6.v6only) Boolean: enable/disable the prohib-
                    ited use of IPv4 mapped address on AF_INET6 sock-
                    ets.  Defaults to on.

> An ideas why tcp in this setup works fine for udp fails only on
> send?

Are you sure that's what you seeing?  It's not a match for what you give
above, but anyways it's an implementation artifact because the tcp code
for v4 and v6 used to be shared and the udp code separate.

It is best to set up one IPv4 and one IPv6 listening socket.

Check the URL above, perhaps that helps your understanding a bit.  I
presume 3800::10:0:0:0 is your server?


More information about the freebsd-net mailing list