8236184: (dc) IP_MULTICAST_* and IP_TOS socket options not effective
Daniel Fuchs
daniel.fuchs at oracle.com
Wed Dec 18 17:10:58 UTC 2019
Hi Alan,
DatagramChannelImpl:
382 // remaining options don't need any special handling
383 Net.setSocketOption(fd, family, name, value);
384 if (needToSetIPv4Option) {
385 try {
386 Net.setSocketOption(fd,
StandardProtocolFamily.INET, name, value);
387 } catch (IOException ignore) { }
388 }
If family == StandardProtocolFamily.INET && needToSetIPv4Option
won't that set the option twice?
If this is impossible - maybe an assert could make it explicit:
assert family != StandardProtocolFamily.INET || !needToSetIPv4Option
Otherwise looks reasonable to me.
Does the new test pass reliably on macOS? We already have some
multicast tests in the ProblemList.txt for that platform.
best regards,
-- daniel
On 18/12/2019 17:47, Alan Bateman wrote:
>
> 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