JDK-8032451 : (dc) DatagramChannel.join should support include-mode filtering on OS X
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: java.nio
  • Affected Version: 7u45
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: os_x
  • Submitted: 2014-01-21
  • Updated: 2014-10-14
  • Resolved: 2014-01-24
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.
JDK 9
9 b03Fixed
Related Reports
Relates :  
Description
FULL PRODUCT VERSION :
js$ java -version
java version "1.7.0_45"
Java(TM) SE Runtime Environment (build 1.7.0_45-b18)
Java HotSpot(TM) 64-Bit Server VM (build 24.45-b08, mixed mode)


ADDITIONAL OS VERSION INFORMATION :
js$ sw_vers
ProductName:Mac OS X
ProductVersion:10.7.5
BuildVersion:11G63b


A DESCRIPTION OF THE PROBLEM :
Subscribing to source-specific multicast with an IP4 configured network address fails with the following exception:

Exception in thread "Thread-1" java.lang.UnsupportedOperationException
at sun.nio.ch.DatagramChannelImpl.innerJoin(DatagramChannelImpl.java:869)
at sun.nio.ch.DatagramChannelImpl.join(DatagramChannelImpl.java:896)

The join method is called with the following Java init code:

            NetworkInterface nif = getNetworkInterface();
            InetAddress groupa = InetAddress.getByName(ip);
            DatagramChannel dc = DatagramChannel.open(StandardProtocolFamily.INET)
                    .setOption(StandardSocketOptions.SO_REUSEADDR, true)
                    .bind(new InetSocketAddress(port))
                    .setOption(StandardSocketOptions.IP_MULTICAST_IF, nif);
            dc.configureBlocking(false);
            for (String source : sources) {
                InetAddress sourcea = InetAddress.getByName(source);
                MembershipKey key = dc.join(groupa, nif, sourcea);
            }

ip is set to a value such as "232.1.1.5", port is set to a value such as '9991' and source is set to a value such as '10.0.1.200'

javadocs at http://docs.oracle.com/javase/7/docs/api/java/nio/channels/DatagramChannel.html show similar invocation sequence.

The same code works on linux and windows platforms without the exception so it sounds likely the native C code for Java_sun_nio_ch_Net_joinOrDrop4 has specific code for MACOSX.



ADDITIONAL REGRESSION INFORMATION:
Source-Specific Multicast (SSM) via DatagramChannel class is available only in JDK7 so I cannot say this would have ever worked on macos before.


EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
My expectation is that no exception would be thrown and subscription via the 3 parameter join() is supported on macos.

ACTUAL -
Exception in thread "Thread-1" java.lang.UnsupportedOperationException
at sun.nio.ch.DatagramChannelImpl.innerJoin(DatagramChannelImpl.java:869)
at sun.nio.ch.DatagramChannelImpl.join(DatagramChannelImpl.java:896)


REPRODUCIBILITY :
This bug can be reproduced always.

CUSTOMER SUBMITTED WORKAROUND :
I have tested this C code to work correctly on macos so I would suggest the same source code would find its way to the Java_sun_nio_ch_Net_joinOrDrop4.c source code for JVM.

    struct ip_mreq_source imsr;
    memset(&imsr, 0, sizeof(imsr));
    imsr.imr_multiaddr.s_addr = inet_addr(g_addr_s);
    imsr.imr_sourceaddr.s_addr = inet_addr(s_addr_s);
    imsr.imr_interface.s_addr = INADDR_ANY;


    err = setsockopt(con->fd, IPPROTO_IP, IP_ADD_SOURCE_MEMBERSHIP,
                  (char*) &imsr, sizeof(imsr));
Comments
I've added noreg-other to this bug because it is automatically covered by existing test cases (MulticastSendReceiveTests in particular will exercise source specific multicast where supported)
24-01-2014

Source-specific multicasting is optional and is not currently supported by the JDK on OS X. There were a number of issues when it was attempted in the initial port (7u4) so is was disabled. Looking at it again now (with 10.8) we have: 1. IPv4 include-mode filtering: OK 2. IPv4 exclude-mode filtering: IP_BLOCK_SOURCE succeeds but packets from the source are still received 3. IPv6 include mode: MCAST_JOIN_SOURCE_GROUP fails 4. IPv6 exclude-mode filtering: MCAST_BLOCK_SOURCE fails So for now then I think all we can do is enable IPv4 include-mode filtering, I've changed the bug summary to reflect this.
22-01-2014