From c01b8c586102117fe6d2b7b5fbf3b49a174b3962 Mon Sep 17 00:00:00 2001 From: alanb Date: Sun, 22 Jul 2012 20:32:12 +0100 Subject: [PATCH] 6633549: (dc) Include-mode filtering of IPv6 sources does not block datagrams on Linux Reviewed-by: chegar --- .../native/sun/nio/ch/DatagramDispatcher.c | 1 + src/solaris/native/sun/nio/ch/Net.c | 88 ++----------------- .../MulticastSendReceiveTests.java | 11 ++- 3 files changed, 19 insertions(+), 81 deletions(-) diff --git a/src/solaris/native/sun/nio/ch/DatagramDispatcher.c b/src/solaris/native/sun/nio/ch/DatagramDispatcher.c index c37686bf9..594ef9ffe 100644 --- a/src/solaris/native/sun/nio/ch/DatagramDispatcher.c +++ b/src/solaris/native/sun/nio/ch/DatagramDispatcher.c @@ -34,6 +34,7 @@ #include #include #include +#include #include "nio_util.h" #include diff --git a/src/solaris/native/sun/nio/ch/Net.c b/src/solaris/native/sun/nio/ch/Net.c index 45c09c359..2f01af33e 100644 --- a/src/solaris/native/sun/nio/ch/Net.c +++ b/src/solaris/native/sun/nio/ch/Net.c @@ -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 my_group_source_req { 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 @@ Java_sun_nio_ch_Net_joinOrDrop6(JNIEnv *env, jobject this, jboolean join, jobjec 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); diff --git a/test/java/nio/channels/DatagramChannel/MulticastSendReceiveTests.java b/test/java/nio/channels/DatagramChannel/MulticastSendReceiveTests.java index 8e6251d95..3591e8345 100644 --- a/test/java/nio/channels/DatagramChannel/MulticastSendReceiveTests.java +++ b/test/java/nio/channels/DatagramChannel/MulticastSendReceiveTests.java @@ -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 @@ public class MulticastSendReceiveTests { 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 @@ public class MulticastSendReceiveTests { 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!"); } } -- GitLab