8236184: (dc) IP_MULTICAST_* and IP_TOS socket options not effective

Alan Bateman Alan.Bateman at oracle.com
Wed Dec 18 16:47:33 UTC 2019


This is another update to the DatagramChannel implementation so that it 
can be used by the upcoming re-implementation of DatagramSocket and 
MulticastSocket.

DatagramChannel has good multicast support but some of the IP_ socket 
options are only are effective for IPv6 datagrams when the channel's 
socket is IPv6, e.g. IP_MUILTICAST_IF sets the outgoing multicast 
interface for IPv6 multicast datagrams but not IPv4 multicast datagrams. 
The javadoc is clear that many aspects of multicasting are platform 
dependent and all of the IP_ socket options are clear that it is 
platform specific as to whether they apply to IPv4 datagrams when the 
socket is IPv6. So not a concern for DatagramChannel as the protocol 
family is specified as creation time. However it is a concern for code 
using the existing MulticastSocket API as the protocol family cannot be 
specified.

The patch proposed here updates DatagramChannel's setOption 
implementation to set both the IPv4 and IPv6 sockets on platforms that 
support this. For example, setOption(IP_MULTICAST_TTL, 8) will attempt 
to set both IP_TOS and IPV6_TCLASS when the socket is IPv6 on platforms 
that allow IP_TOS to set the ToS field of IPv4 datagrams sent with the 
socket. Legacy networking has been doing the same on Linux for many 
releases. The change does the same on Windows, something legacy 
networking doesn't need to do because MulticastSocket uses two sockets 
on Windows.

The webrev with the changes is here:
   http://cr.openjdk.java.net/~alanb/8236184/webrev/

Testing these changes is difficult and requires using tcpdump/equivalent 
to look at the network. However we can test IP_MULTICAST_LOOP so I've 
added a test for that.


-Alan


More information about the nio-dev mailing list