6633549: (dc) Include-mode filtering of IPv6 sources does not block datagrams on Linux
authoralanb
Sun, 22 Jul 2012 20:32:12 +0100
changeset 13363 065e0e3545a3
parent 13362 ff59dd695fc0
child 13364 67ebd60432ce
6633549: (dc) Include-mode filtering of IPv6 sources does not block datagrams on Linux Reviewed-by: chegar
jdk/src/solaris/native/sun/nio/ch/DatagramDispatcher.c
jdk/src/solaris/native/sun/nio/ch/Net.c
jdk/test/java/nio/channels/DatagramChannel/MulticastSendReceiveTests.java
--- a/jdk/src/solaris/native/sun/nio/ch/DatagramDispatcher.c	Sat Jul 21 19:56:55 2012 +0800
+++ b/jdk/src/solaris/native/sun/nio/ch/DatagramDispatcher.c	Sun Jul 22 20:32:12 2012 +0100
@@ -34,6 +34,7 @@
 #include <sys/types.h>
 #include <sys/uio.h>
 #include <sys/socket.h>
+#include <string.h>
 
 #include "nio_util.h"
 #include <limits.h>
--- a/jdk/src/solaris/native/sun/nio/ch/Net.c	Sat Jul 21 19:56:55 2012 +0800
+++ b/jdk/src/solaris/native/sun/nio/ch/Net.c	Sun Jul 22 20:32:12 2012 +0100
@@ -39,83 +39,6 @@
 #include "nio_util.h"
 #include "nio.h"
 
-/**
- * Definitions for source-specific multicast to allow for building
- * with older header files.
- */
-
-#ifdef __solaris__
-
-#ifndef IP_BLOCK_SOURCE
-
-#define IP_BLOCK_SOURCE                 0x15
-#define IP_UNBLOCK_SOURCE               0x16
-#define IP_ADD_SOURCE_MEMBERSHIP        0x17
-#define IP_DROP_SOURCE_MEMBERSHIP       0x18
-
-#define MCAST_BLOCK_SOURCE              0x2b
-#define MCAST_UNBLOCK_SOURCE            0x2c
-#define MCAST_JOIN_SOURCE_GROUP         0x2d
-#define MCAST_LEAVE_SOURCE_GROUP        0x2e
-
-#endif  /* IP_BLOCK_SOURCE */
-
-struct my_ip_mreq_source {
-        struct in_addr  imr_multiaddr;
-        struct in_addr  imr_sourceaddr;
-        struct in_addr  imr_interface;
-};
-
-/*
- * Use #pragma pack() construct to force 32-bit alignment on amd64.
- */
-#if defined(amd64)
-#pragma pack(4)
-#endif
-
-struct my_group_source_req {
-        uint32_t                gsr_interface;  /* interface index */
-        struct sockaddr_storage gsr_group;      /* group address */
-        struct sockaddr_storage gsr_source;     /* source address */
-};
-
-#if defined(amd64)
-#pragma pack()
-#endif
-
-#endif  /* __solaris__ */
-
-
-#ifdef __linux__
-
-#ifndef IP_BLOCK_SOURCE
-
-#define IP_BLOCK_SOURCE                 38
-#define IP_UNBLOCK_SOURCE               37
-#define IP_ADD_SOURCE_MEMBERSHIP        39
-#define IP_DROP_SOURCE_MEMBERSHIP       40
-
-#define MCAST_BLOCK_SOURCE              43
-#define MCAST_UNBLOCK_SOURCE            44
-#define MCAST_JOIN_SOURCE_GROUP         42
-#define MCAST_LEAVE_SOURCE_GROUP        45
-
-#endif  /* IP_BLOCK_SOURCE */
-
-struct my_ip_mreq_source {
-        struct in_addr  imr_multiaddr;
-        struct in_addr  imr_interface;
-        struct in_addr  imr_sourceaddr;
-};
-
-struct my_group_source_req {
-        uint32_t                gsr_interface;  /* interface index */
-        struct sockaddr_storage gsr_group;      /* group address */
-        struct sockaddr_storage gsr_source;     /* source address */
-};
-
-#endif   /* __linux__ */
-
 #ifdef _ALLBSD_SOURCE
 
 #ifndef IP_BLOCK_SOURCE
@@ -155,7 +78,12 @@
         struct sockaddr_storage gsr_source;     /* source address */
 };
 
-#endif   /* _ALLBSD_SOURCE */
+#else   /* _ALLBSD_SOURCE */
+
+#define my_ip_mreq_source         ip_mreq_source
+#define my_group_source_req       group_source_req
+
+#endif
 
 
 #define COPY_INET6_ADDRESS(env, source, target) \
@@ -576,8 +504,8 @@
         optval = (void*)&mreq6;
         optlen = sizeof(mreq6);
     } else {
-#if defined (__linux__) || defined(MACOSX)
-        /* Include-mode filtering broken on Mac OS & Linux at least to 2.6.24 */
+#ifdef MACOSX
+        /* no IPv6 include-mode filtering for now */
         return IOS_UNAVAILABLE;
 #else
         initGroupSourceReq(env, group, index, source, &req);
--- a/jdk/test/java/nio/channels/DatagramChannel/MulticastSendReceiveTests.java	Sat Jul 21 19:56:55 2012 +0800
+++ b/jdk/test/java/nio/channels/DatagramChannel/MulticastSendReceiveTests.java	Sun Jul 22 20:32:12 2012 +0100
@@ -22,10 +22,11 @@
  */
 
 /* @test
- * @bug 4527345 7026376
+ * @bug 4527345 7026376 6633549
  * @summary Unit test for DatagramChannel's multicast support
  * @build MulticastSendReceiveTests NetworkConfiguration
  * @run main MulticastSendReceiveTests
+ * @run main/othervm -Djava.net.preferIPv4Stack=true MulticastSendReceiveTests
  */
 
 import java.nio.ByteBuffer;
@@ -186,6 +187,10 @@
                 id = sendDatagram(source, nif, group, port);
                 receiveDatagram(dc, source, id);
             } catch (UnsupportedOperationException x) {
+                String os = System.getProperty("os.name");
+                // Exclude-mode filtering supported on these platforms so UOE should never be thrown
+                if (os.equals("SunOS") || os.equals("Linux"))
+                    throw x;
                 System.out.println("Exclude-mode filtering not supported!");
             }
 
@@ -212,6 +217,10 @@
                 id = sendDatagram(source, nif, group, port);
                 receiveDatagram(dc, source, id);
             } catch (UnsupportedOperationException x) {
+                String os = System.getProperty("os.name");
+                // Include-mode filtering supported on these platforms so UOE should never be thrown
+                if (os.equals("SunOS") || os.equals("Linux"))
+                    throw x;
                 System.out.println("Include-mode filtering not supported!");
             }
         }