JDK-8272476 : (dc) DatagramChannel.setOption(IP_MULTICAST_IF) fails if IPv6 disabled on interface (win)
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.nio
  • Affected Version: 15,18,23
  • Priority: P4
  • Status: In Progress
  • Resolution: Unresolved
  • Submitted: 2021-08-14
  • Updated: 2024-03-21
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
tbdUnresolved
Related Reports
Duplicate :  
Duplicate :  
Relates :  
Relates :  
Relates :  
Relates :  
Description
This issue came up on SO here:
https://stackoverflow.com/questions/68769776/socketexception-when-calling-setnetworkinterface-on-a-multicastsocket-with-an-ip

The environment is Windows with IPv6 enabled but disabled on a specific network interface, say "eth1".

A DatagramChannel (or DatagramSocket or MulticastSocket) to an IPv6 socket is created. The setOption method is invoked to set the outgoing interface for multicast datagrams to be "eth1". The expectation is that it should succeed because it has IPv4 enabled but it fails because IPv6 is disabled.

The issue can be worked by running with IPv6 disabled (-Djava.net.preferIPv4Stack=true). For DatagramChannel, the issue can be worked around by specifying the INET protocol family when creating the DatagramChannel. For MulticastSocket, the issue can be worked around in JDK 15 to 17 by running with the old DatagramSocketImpl (-Djdk.net.usePlainDatagramSocketImpl=true).
Comments
https://bugs.openjdk.org/browse/JDK-8328615 8328615: Various java.net and java.nio tests fail with Invalid argument: setsockopt on Ipv6 able machine without Ipv6 interface might be a similar (or the same? I am not sure) issue.
21-03-2024

[~azeller] Thanks for the reminder, this one is still on my list. I've tested several patches for this but they created inconsistencies between the setter/getter in some configurations and broadens the impact to other platforms. I do plan to create a PR for this, TBD on whether it will include spec changes.
05-02-2024

Hi Alan, you mention a patch - but I cannot see an attachment. Are you planning to create a PR? Best regards Arno
05-02-2024

I duplicated the error by disabling IPv6 with the following command in powershell Disable-NetAdapterBinding -Name "Ethernet" -ComponentID ms_tcpip6 On Windows, when the socket is IPv6 and not bound to a specific address, setOption(IP_MULTICAST_IF) maps to IPV6_MULTICAST_IF to set the outgoing interface for IPv6 multicast datagrams and IP_MULTICAST_IF to set the outgoing interface for IPv4 multicast datagrams. The former is always called, the latter is only called when there is at least one IPv4 address configured. The implementation can be improved to only attempt the former when there is an IPv6 address configured. I attach an initial patch that address the issue. It may require manual verification. I've set the Introduced-In-Version to 15 as that is the first release where it will be observed with MulticastSocket. I don't think the scenario ever worked when using DatagramChannel directly.
15-08-2021