Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_jdk
提交
e987f0da
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看板
提交
e987f0da
编写于
1月 21, 2014
作者:
V
vinnie
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
8030731: Improve name service robustness
Reviewed-by: weijun, michaelm, skoivu
上级
7d7a2180
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
67 addition
and
29 deletion
+67
-29
src/share/classes/com/sun/jndi/dns/DnsClient.java
src/share/classes/com/sun/jndi/dns/DnsClient.java
+67
-29
未找到文件。
src/share/classes/com/sun/jndi/dns/DnsClient.java
浏览文件 @
e987f0da
/*
/*
* Copyright (c) 2000, 201
2
, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2000, 201
4
, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
*
* This code is free software; you can redistribute it and/or modify it
* This code is free software; you can redistribute it and/or modify it
...
@@ -30,13 +30,14 @@ import java.net.DatagramSocket;
...
@@ -30,13 +30,14 @@ import java.net.DatagramSocket;
import
java.net.DatagramPacket
;
import
java.net.DatagramPacket
;
import
java.net.InetAddress
;
import
java.net.InetAddress
;
import
java.net.Socket
;
import
java.net.Socket
;
import
java.security.SecureRandom
;
import
javax.naming.*
;
import
javax.naming.*
;
import
java.util.Collections
;
import
java.util.Collections
;
import
java.util.Map
;
import
java.util.Map
;
import
java.util.HashMap
;
import
java.util.HashMap
;
import
java.util.Set
;
import
java.util.HashSet
;
import
sun.security.jca.JCAUtil
;
// Some of this code began life as part of sun.javaos.net.DnsClient
// Some of this code began life as part of sun.javaos.net.DnsClient
// originally by sritchie@eng 1/96. It was first hacked up for JNDI
// originally by sritchie@eng 1/96. It was first hacked up for JNDI
...
@@ -77,6 +78,8 @@ public class DnsClient {
...
@@ -77,6 +78,8 @@ public class DnsClient {
};
};
private
static
final
int
DEFAULT_PORT
=
53
;
private
static
final
int
DEFAULT_PORT
=
53
;
private
static
final
int
TRANSACTION_ID_BOUND
=
0x10000
;
private
static
final
SecureRandom
random
=
JCAUtil
.
getSecureRandom
();
private
InetAddress
[]
servers
;
private
InetAddress
[]
servers
;
private
int
[]
serverPorts
;
private
int
[]
serverPorts
;
private
int
timeout
;
// initial timeout on UDP queries in ms
private
int
timeout
;
// initial timeout on UDP queries in ms
...
@@ -85,7 +88,7 @@ public class DnsClient {
...
@@ -85,7 +88,7 @@ public class DnsClient {
private
DatagramSocket
udpSocket
;
private
DatagramSocket
udpSocket
;
// Requests sent
// Requests sent
private
Set
<
Integer
>
reqs
;
private
Map
<
Integer
,
ResourceRecord
>
reqs
;
// Responses received
// Responses received
private
Map
<
Integer
,
byte
[]>
resps
;
private
Map
<
Integer
,
byte
[]>
resps
;
...
@@ -134,7 +137,8 @@ public class DnsClient {
...
@@ -134,7 +137,8 @@ public class DnsClient {
throw
ne
;
throw
ne
;
}
}
}
}
reqs
=
Collections
.
synchronizedSet
(
new
HashSet
<
Integer
>());
reqs
=
Collections
.
synchronizedMap
(
new
HashMap
<
Integer
,
ResourceRecord
>());
resps
=
Collections
.
synchronizedMap
(
new
HashMap
<
Integer
,
byte
[]>());
resps
=
Collections
.
synchronizedMap
(
new
HashMap
<
Integer
,
byte
[]>());
}
}
...
@@ -153,10 +157,6 @@ public class DnsClient {
...
@@ -153,10 +157,6 @@ public class DnsClient {
}
}
}
}
private
int
ident
=
0
;
// used to set the msg ID field
private
Object
identLock
=
new
Object
();
/*
/*
* If recursion is true, recursion is requested on the query.
* If recursion is true, recursion is requested on the query.
* If auth is true, only authoritative responses are accepted; other
* If auth is true, only authoritative responses are accepted; other
...
@@ -167,15 +167,19 @@ public class DnsClient {
...
@@ -167,15 +167,19 @@ public class DnsClient {
throws
NamingException
{
throws
NamingException
{
int
xid
;
int
xid
;
synchronized
(
identLock
)
{
Packet
pkt
;
ident
=
0xFFFF
&
(
ident
+
1
);
ResourceRecord
collision
;
xid
=
ident
;
}
do
{
// Generate a random transaction ID
xid
=
random
.
nextInt
(
TRANSACTION_ID_BOUND
);
pkt
=
makeQueryPacket
(
fqdn
,
xid
,
qclass
,
qtype
,
recursion
);
// enqueue the outstanding request
// enqueue the outstanding request
reqs
.
add
(
xid
);
collision
=
reqs
.
putIfAbsent
(
xid
,
new
ResourceRecord
(
pkt
.
getData
(),
pkt
.
length
(),
Header
.
HEADER_SIZE
,
true
,
false
));
Packet
pkt
=
makeQueryPacket
(
fqdn
,
xid
,
qclass
,
qtype
,
recursion
);
}
while
(
collision
!=
null
);
Exception
caughtException
=
null
;
Exception
caughtException
=
null
;
boolean
[]
doNotRetry
=
new
boolean
[
servers
.
length
];
boolean
[]
doNotRetry
=
new
boolean
[
servers
.
length
];
...
@@ -305,11 +309,8 @@ public class DnsClient {
...
@@ -305,11 +309,8 @@ public class DnsClient {
ResourceRecords
queryZone
(
DnsName
zone
,
int
qclass
,
boolean
recursion
)
ResourceRecords
queryZone
(
DnsName
zone
,
int
qclass
,
boolean
recursion
)
throws
NamingException
{
throws
NamingException
{
int
xid
;
int
xid
=
random
.
nextInt
(
TRANSACTION_ID_BOUND
);
synchronized
(
identLock
)
{
ident
=
0xFFFF
&
(
ident
+
1
);
xid
=
ident
;
}
Packet
pkt
=
makeQueryPacket
(
zone
,
xid
,
qclass
,
Packet
pkt
=
makeQueryPacket
(
zone
,
xid
,
qclass
,
ResourceRecord
.
QTYPE_AXFR
,
recursion
);
ResourceRecord
.
QTYPE_AXFR
,
recursion
);
Exception
caughtException
=
null
;
Exception
caughtException
=
null
;
...
@@ -390,6 +391,7 @@ public class DnsClient {
...
@@ -390,6 +391,7 @@ public class DnsClient {
DatagramPacket
opkt
=
new
DatagramPacket
(
DatagramPacket
opkt
=
new
DatagramPacket
(
pkt
.
getData
(),
pkt
.
length
(),
server
,
port
);
pkt
.
getData
(),
pkt
.
length
(),
server
,
port
);
DatagramPacket
ipkt
=
new
DatagramPacket
(
new
byte
[
8000
],
8000
);
DatagramPacket
ipkt
=
new
DatagramPacket
(
new
byte
[
8000
],
8000
);
// Packets may only be sent to or received from this server address
udpSocket
.
connect
(
server
,
port
);
udpSocket
.
connect
(
server
,
port
);
int
pktTimeout
=
(
timeout
*
(
1
<<
retry
));
int
pktTimeout
=
(
timeout
*
(
1
<<
retry
));
try
{
try
{
...
@@ -543,6 +545,9 @@ public class DnsClient {
...
@@ -543,6 +545,9 @@ public class DnsClient {
* Checks the header of an incoming DNS response.
* Checks the header of an incoming DNS response.
* Returns true if it matches the given xid and throws a naming
* Returns true if it matches the given xid and throws a naming
* exception, if appropriate, based on the response code.
* exception, if appropriate, based on the response code.
*
* Also checks that the domain name, type and class in the response
* match those in the original query.
*/
*/
private
boolean
isMatchResponse
(
byte
[]
pkt
,
int
xid
)
private
boolean
isMatchResponse
(
byte
[]
pkt
,
int
xid
)
throws
NamingException
{
throws
NamingException
{
...
@@ -552,7 +557,7 @@ public class DnsClient {
...
@@ -552,7 +557,7 @@ public class DnsClient {
throw
new
CommunicationException
(
"DNS error: expecting response"
);
throw
new
CommunicationException
(
"DNS error: expecting response"
);
}
}
if
(!
reqs
.
contains
(
xid
))
{
// already received, ignore the response
if
(!
reqs
.
contains
Key
(
xid
))
{
// already received, ignore the response
return
false
;
return
false
;
}
}
...
@@ -561,14 +566,47 @@ public class DnsClient {
...
@@ -561,14 +566,47 @@ public class DnsClient {
if
(
debug
)
{
if
(
debug
)
{
dprint
(
"XID MATCH:"
+
xid
);
dprint
(
"XID MATCH:"
+
xid
);
}
}
checkResponseCode
(
hdr
);
checkResponseCode
(
hdr
);
// remove the response for the xid if received by some other thread.
if
(!
hdr
.
query
&&
hdr
.
numQuestions
==
1
)
{
ResourceRecord
rr
=
new
ResourceRecord
(
pkt
,
pkt
.
length
,
Header
.
HEADER_SIZE
,
true
,
false
);
// Retrieve the original query
ResourceRecord
query
=
reqs
.
get
(
xid
);
int
qtype
=
query
.
getType
();
int
qclass
=
query
.
getRrclass
();
DnsName
qname
=
query
.
getName
();
// Check that the type/class/name in the query section of the
// response match those in the original query
if
((
qtype
==
ResourceRecord
.
QTYPE_STAR
||
qtype
==
rr
.
getType
())
&&
(
qclass
==
ResourceRecord
.
QCLASS_STAR
||
qclass
==
rr
.
getRrclass
())
&&
qname
.
equals
(
rr
.
getName
()))
{
if
(
debug
)
{
dprint
(
"MATCH NAME:"
+
qname
+
" QTYPE:"
+
qtype
+
" QCLASS:"
+
qclass
);
}
// Remove the response for the xid if received by some other
// thread.
synchronized
(
queuesLock
)
{
synchronized
(
queuesLock
)
{
resps
.
remove
(
xid
);
resps
.
remove
(
xid
);
reqs
.
remove
(
xid
);
reqs
.
remove
(
xid
);
}
}
return
true
;
return
true
;
}
else
{
if
(
debug
)
{
dprint
(
"NO-MATCH NAME:"
+
qname
+
" QTYPE:"
+
qtype
+
" QCLASS:"
+
qclass
);
}
}
}
return
false
;
}
}
//
//
...
@@ -577,7 +615,7 @@ public class DnsClient {
...
@@ -577,7 +615,7 @@ public class DnsClient {
// enqueue only the first response, responses for retries are ignored.
// enqueue only the first response, responses for retries are ignored.
//
//
synchronized
(
queuesLock
)
{
synchronized
(
queuesLock
)
{
if
(
reqs
.
contains
(
hdr
.
xid
))
{
// enqueue only the first response
if
(
reqs
.
contains
Key
(
hdr
.
xid
))
{
// enqueue only the first response
resps
.
put
(
hdr
.
xid
,
pkt
);
resps
.
put
(
hdr
.
xid
,
pkt
);
}
}
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录