Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_jdk
提交
11d0f16c
D
dragonwell8_jdk
项目概览
openanolis
/
dragonwell8_jdk
通知
4
Star
2
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
dragonwell8_jdk
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
11d0f16c
编写于
6月 20, 2013
作者:
A
alanb
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
8014377: (dc) DatagramChannel should set IP_MULTICAST_ALL=0 (lnx)
Reviewed-by: chegar, jzavgren
上级
5a8be60c
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
245 addition
and
4 deletion
+245
-4
src/solaris/native/sun/nio/ch/Net.c
src/solaris/native/sun/nio/ch/Net.c
+31
-4
test/java/nio/channels/DatagramChannel/Promiscuous.java
test/java/nio/channels/DatagramChannel/Promiscuous.java
+214
-0
未找到文件。
src/solaris/native/sun/nio/ch/Net.c
浏览文件 @
11d0f16c
...
@@ -40,6 +40,17 @@
...
@@ -40,6 +40,17 @@
#include "nio.h"
#include "nio.h"
#include "sun_nio_ch_PollArrayWrapper.h"
#include "sun_nio_ch_PollArrayWrapper.h"
/**
* IP_MULTICAST_ALL supported since 2.6.31 but may not be available at
* build time.
*/
#ifdef __linux__
#ifndef IP_MULTICAST_ALL
#define IP_MULTICAST_ALL 49
#endif
#endif
#ifdef _ALLBSD_SOURCE
#ifdef _ALLBSD_SOURCE
#ifndef IP_BLOCK_SOURCE
#ifndef IP_BLOCK_SOURCE
...
@@ -175,7 +186,7 @@ Java_sun_nio_ch_Net_socket0(JNIEnv *env, jclass cl, jboolean preferIPv6,
...
@@ -175,7 +186,7 @@ Java_sun_nio_ch_Net_socket0(JNIEnv *env, jclass cl, jboolean preferIPv6,
sizeof
(
int
))
<
0
)
{
sizeof
(
int
))
<
0
)
{
JNU_ThrowByNameWithLastError
(
env
,
JNU_ThrowByNameWithLastError
(
env
,
JNU_JAVANETPKG
"SocketException"
,
JNU_JAVANETPKG
"SocketException"
,
"
sun.nio.ch.Net.setIntOption
"
);
"
Unable to set IPV6_V6ONLY
"
);
close
(
fd
);
close
(
fd
);
return
-
1
;
return
-
1
;
}
}
...
@@ -188,11 +199,27 @@ Java_sun_nio_ch_Net_socket0(JNIEnv *env, jclass cl, jboolean preferIPv6,
...
@@ -188,11 +199,27 @@ Java_sun_nio_ch_Net_socket0(JNIEnv *env, jclass cl, jboolean preferIPv6,
sizeof
(
arg
))
<
0
)
{
sizeof
(
arg
))
<
0
)
{
JNU_ThrowByNameWithLastError
(
env
,
JNU_ThrowByNameWithLastError
(
env
,
JNU_JAVANETPKG
"SocketException"
,
JNU_JAVANETPKG
"SocketException"
,
"sun.nio.ch.Net.setIntOption"
);
"Unable to set SO_REUSEADDR"
);
close
(
fd
);
return
-
1
;
}
}
#if defined(__linux__)
if
(
type
==
SOCK_DGRAM
)
{
int
arg
=
0
;
int
level
=
(
domain
==
AF_INET6
)
?
IPPROTO_IPV6
:
IPPROTO_IP
;
if
((
setsockopt
(
fd
,
level
,
IP_MULTICAST_ALL
,
(
char
*
)
&
arg
,
sizeof
(
arg
))
<
0
)
&&
(
errno
!=
ENOPROTOOPT
))
{
JNU_ThrowByNameWithLastError
(
env
,
JNU_JAVANETPKG
"SocketException"
,
"Unable to set IP_MULTICAST_ALL"
);
close
(
fd
);
close
(
fd
);
return
-
1
;
return
-
1
;
}
}
}
}
#endif
#if defined(__linux__) && defined(AF_INET6)
#if defined(__linux__) && defined(AF_INET6)
/* By default, Linux uses the route default */
/* By default, Linux uses the route default */
if
(
domain
==
AF_INET6
&&
type
==
SOCK_DGRAM
)
{
if
(
domain
==
AF_INET6
&&
type
==
SOCK_DGRAM
)
{
...
@@ -201,7 +228,7 @@ Java_sun_nio_ch_Net_socket0(JNIEnv *env, jclass cl, jboolean preferIPv6,
...
@@ -201,7 +228,7 @@ Java_sun_nio_ch_Net_socket0(JNIEnv *env, jclass cl, jboolean preferIPv6,
sizeof
(
arg
))
<
0
)
{
sizeof
(
arg
))
<
0
)
{
JNU_ThrowByNameWithLastError
(
env
,
JNU_ThrowByNameWithLastError
(
env
,
JNU_JAVANETPKG
"SocketException"
,
JNU_JAVANETPKG
"SocketException"
,
"
sun.nio.ch.Net.setIntOption
"
);
"
Unable to set IPV6_MULTICAST_HOPS
"
);
close
(
fd
);
close
(
fd
);
return
-
1
;
return
-
1
;
}
}
...
@@ -646,7 +673,7 @@ Java_sun_nio_ch_Net_poll(JNIEnv* env, jclass this, jobject fdo, jint events, jlo
...
@@ -646,7 +673,7 @@ Java_sun_nio_ch_Net_poll(JNIEnv* env, jclass this, jobject fdo, jint events, jlo
return
pfd
.
revents
;
return
pfd
.
revents
;
}
else
if
(
errno
==
EINTR
)
{
}
else
if
(
errno
==
EINTR
)
{
return
IOS_INTERRUPTED
;
return
IOS_INTERRUPTED
;
}
else
if
(
rv
<
0
)
{
}
else
{
handleSocketError
(
env
,
errno
);
handleSocketError
(
env
,
errno
);
return
IOS_THROWN
;
return
IOS_THROWN
;
}
}
...
...
test/java/nio/channels/DatagramChannel/Promiscuous.java
0 → 100644
浏览文件 @
11d0f16c
/*
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
/* @test
* @bug 8014377
* @summary Test for interference when two sockets are bound to the same
* port but joined to different multicast groups
* @build Promiscuous NetworkConfiguration
* @run main Promiscuous
* @run main/othervm -Djava.net.preferIPv4Stack=true Promiscuous
*/
import
java.nio.ByteBuffer
;
import
java.nio.channels.*
;
import
java.net.*
;
import
static
java
.
net
.
StandardProtocolFamily
.*;
import
java.util.*
;
import
java.io.IOException
;
public
class
Promiscuous
{
static
final
Random
rand
=
new
Random
();
static
final
ProtocolFamily
UNSPEC
=
new
ProtocolFamily
()
{
public
String
name
()
{
return
"UNSPEC"
;
}
};
/**
* Sends a datagram to the given multicast group
*/
static
int
sendDatagram
(
NetworkInterface
nif
,
InetAddress
group
,
int
port
)
throws
IOException
{
ProtocolFamily
family
=
(
group
instanceof
Inet6Address
)
?
StandardProtocolFamily
.
INET6
:
StandardProtocolFamily
.
INET
;
DatagramChannel
dc
=
DatagramChannel
.
open
(
family
)
.
setOption
(
StandardSocketOptions
.
IP_MULTICAST_IF
,
nif
);
int
id
=
rand
.
nextInt
();
byte
[]
msg
=
Integer
.
toString
(
id
).
getBytes
(
"UTF-8"
);
ByteBuffer
buf
=
ByteBuffer
.
wrap
(
msg
);
System
.
out
.
format
(
"Send message -> group %s (id=0x%x)\n"
,
group
.
getHostAddress
(),
id
);
dc
.
send
(
buf
,
new
InetSocketAddress
(
group
,
port
));
dc
.
close
();
return
id
;
}
/**
* Wait (with timeout) for datagram. The {@code datagramExepcted}
* parameter indicates whether a datagram is expected, and if
* {@true} then {@code id} is the identifier in the payload.
*/
static
void
receiveDatagram
(
DatagramChannel
dc
,
String
name
,
boolean
datagramExepcted
,
int
id
)
throws
IOException
{
System
.
out
.
println
(
"Checking if received by "
+
name
);
Selector
sel
=
Selector
.
open
();
dc
.
configureBlocking
(
false
);
dc
.
register
(
sel
,
SelectionKey
.
OP_READ
);
ByteBuffer
buf
=
ByteBuffer
.
allocateDirect
(
100
);
try
{
for
(;;)
{
System
.
out
.
println
(
"Waiting to receive message"
);
sel
.
select
(
5
*
1000
);
SocketAddress
sa
=
dc
.
receive
(
buf
);
// no datagram received
if
(
sa
==
null
)
{
if
(
datagramExepcted
)
{
throw
new
RuntimeException
(
"Expected message not recieved"
);
}
System
.
out
.
println
(
"No message received (correct)"
);
return
;
}
// datagram received
InetAddress
sender
=
((
InetSocketAddress
)
sa
).
getAddress
();
buf
.
flip
();
byte
[]
bytes
=
new
byte
[
buf
.
remaining
()];
buf
.
get
(
bytes
);
int
receivedId
=
Integer
.
parseInt
(
new
String
(
bytes
));
System
.
out
.
format
(
"Received message from %s (id=0x%x)\n"
,
sender
,
receivedId
);
if
(!
datagramExepcted
)
{
if
(
receivedId
==
id
)
throw
new
RuntimeException
(
"Message not expected"
);
System
.
out
.
println
(
"Message ignored (has wrong id)"
);
}
else
{
if
(
receivedId
==
id
)
{
System
.
out
.
println
(
"Message expected"
);
return
;
}
System
.
out
.
println
(
"Message ignored (wrong sender)"
);
}
sel
.
selectedKeys
().
clear
();
buf
.
rewind
();
}
}
finally
{
sel
.
close
();
}
}
static
void
test
(
ProtocolFamily
family
,
NetworkInterface
nif
,
InetAddress
group1
,
InetAddress
group2
)
throws
IOException
{
System
.
out
.
format
(
"%nTest family=%s%n"
,
family
.
name
());
DatagramChannel
dc1
=
(
family
==
UNSPEC
)
?
DatagramChannel
.
open
()
:
DatagramChannel
.
open
(
family
);
DatagramChannel
dc2
=
(
family
==
UNSPEC
)
?
DatagramChannel
.
open
()
:
DatagramChannel
.
open
(
family
);
try
{
dc1
.
setOption
(
StandardSocketOptions
.
SO_REUSEADDR
,
true
);
dc2
.
setOption
(
StandardSocketOptions
.
SO_REUSEADDR
,
true
);
dc1
.
bind
(
new
InetSocketAddress
(
0
));
int
port
=
dc1
.
socket
().
getLocalPort
();
dc2
.
bind
(
new
InetSocketAddress
(
port
));
System
.
out
.
format
(
"dc1 joining [%s]:%d @ %s\n"
,
group1
.
getHostAddress
(),
port
,
nif
.
getName
());
System
.
out
.
format
(
"dc2 joining [%s]:%d @ %s\n"
,
group2
.
getHostAddress
(),
port
,
nif
.
getName
());
dc1
.
join
(
group1
,
nif
);
dc2
.
join
(
group2
,
nif
);
int
id
=
sendDatagram
(
nif
,
group1
,
port
);
receiveDatagram
(
dc1
,
"dc1"
,
true
,
id
);
receiveDatagram
(
dc2
,
"dc2"
,
false
,
id
);
id
=
sendDatagram
(
nif
,
group2
,
port
);
receiveDatagram
(
dc1
,
"dc1"
,
false
,
id
);
receiveDatagram
(
dc2
,
"dc2"
,
true
,
id
);
}
finally
{
dc1
.
close
();
dc2
.
close
();
}
}
public
static
void
main
(
String
[]
args
)
throws
IOException
{
String
os
=
System
.
getProperty
(
"os.name"
);
// Requires IP_MULTICAST_ALL on Linux (new since 2.6.31) so skip
// on older kernels. Note that we skip on <= version 3 to keep the
// parsing simple
if
(
os
.
equals
(
"Linux"
))
{
String
osversion
=
System
.
getProperty
(
"os.version"
);
String
[]
vers
=
osversion
.
split
(
"\\."
,
0
);
int
major
=
Integer
.
parseInt
(
vers
[
0
]);
if
(
major
<
3
)
{
System
.
out
.
format
(
"Kernel version is %s, test skipped%n"
,
osversion
);
return
;
}
}
// get local network configuration to use
NetworkConfiguration
config
=
NetworkConfiguration
.
probe
();
// multicast groups used for the test
InetAddress
ip4Group1
=
InetAddress
.
getByName
(
"225.4.5.6"
);
InetAddress
ip4Group2
=
InetAddress
.
getByName
(
"225.4.6.6"
);
for
(
NetworkInterface
nif:
config
.
ip4Interfaces
())
{
InetAddress
source
=
config
.
ip4Addresses
(
nif
).
iterator
().
next
();
test
(
INET
,
nif
,
ip4Group1
,
ip4Group2
);
// Solaris and Linux allow IPv6 sockets join IPv4 multicast groups
if
(
os
.
equals
(
"SunOS"
)
||
os
.
equals
(
"Linux"
))
test
(
UNSPEC
,
nif
,
ip4Group1
,
ip4Group2
);
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录