Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit549fb25

Browse files
committed
Disable IPv6 address lookups when -Djava.net.preferIPv4Stack=true,closeAsyncHttpClient#1336
Motivation:According to the Oracle documentation:> java.net.preferIPv4Stack (default: false)>> If IPv6 is available on the operating system, the underlying native> socket will be an IPv6 socket. This allows Java applications toconnect> to, and accept connections from, both IPv4 and IPv6 hosts.>> If an application has a preference to only use IPv4 sockets, then this> property can be set to true. The implication is that the application> will not be able to communicate with IPv6 hosts.which means, if DnsNameResolver returns an IPv6 address, a user (orNetty) will not be able to connect to it.Modifications:- Move the code that retrieves java.net.prefer* properties from DnsNameResolver to NetUtil- Add NetUtil.isIpV6AddressesPreferred()- Revise the API documentation of NetUtil.isIpV*Preferred()- Set the default resolveAddressTypes to IPv4 only when NetUtil.isIpv4StackPreferred() returns trueResult:-FixesAsyncHttpClient#1336
1 parent2fd2d86 commit549fb25

File tree

2 files changed

+1111
-14
lines changed

2 files changed

+1111
-14
lines changed

‎netty-bp/resolver-dns/src/main/java/io/netty/resolver/dns/DnsNameResolver.java‎

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
importio.netty.handler.codec.dns.DnsResponse;
3838
importio.netty.resolver.HostsFileEntriesResolver;
3939
importio.netty.resolver.InetNameResolver;
40-
importio.netty.util.NetUtil;
40+
importio.netty.util.NetUtil2;
4141
importio.netty.util.ReferenceCountUtil;
4242
importio.netty.util.concurrent.FastThreadLocal;
4343
importio.netty.util.concurrent.Future;
@@ -69,21 +69,24 @@ public class DnsNameResolver extends InetNameResolver {
6969
privatestaticfinalStringLOCALHOST ="localhost";
7070
privatestaticfinalInetAddressLOCALHOST_ADDRESS;
7171

72-
staticfinalInternetProtocolFamily[]DEFAULT_RESOLVE_ADDRESS_TYPES =newInternetProtocolFamily[2];
72+
staticfinalInternetProtocolFamily[]DEFAULT_RESOLVE_ADDRESS_TYPES;
7373
staticfinalString[]DEFAULT_SEACH_DOMAINS;
7474

7575
static {
76-
// Note that we did not use SystemPropertyUtil.getBoolean() here to emulate the behavior of JDK.
77-
if (Boolean.getBoolean("java.net.preferIPv6Addresses")) {
78-
DEFAULT_RESOLVE_ADDRESS_TYPES[0] =InternetProtocolFamily.IPv6;
79-
DEFAULT_RESOLVE_ADDRESS_TYPES[1] =InternetProtocolFamily.IPv4;
80-
LOCALHOST_ADDRESS =NetUtil.LOCALHOST6;
81-
logger.debug("-Djava.net.preferIPv6Addresses: true");
76+
if (NetUtil2.isIpV4StackPreferred()) {
77+
DEFAULT_RESOLVE_ADDRESS_TYPES =newInternetProtocolFamily[] {InternetProtocolFamily.IPv4 };
78+
LOCALHOST_ADDRESS =NetUtil2.LOCALHOST4;
8279
}else {
83-
DEFAULT_RESOLVE_ADDRESS_TYPES[0] =InternetProtocolFamily.IPv4;
84-
DEFAULT_RESOLVE_ADDRESS_TYPES[1] =InternetProtocolFamily.IPv6;
85-
LOCALHOST_ADDRESS =NetUtil.LOCALHOST4;
86-
logger.debug("-Djava.net.preferIPv6Addresses: false");
80+
DEFAULT_RESOLVE_ADDRESS_TYPES =newInternetProtocolFamily[2];
81+
if (NetUtil2.isIpV6AddressesPreferred()) {
82+
DEFAULT_RESOLVE_ADDRESS_TYPES[0] =InternetProtocolFamily.IPv6;
83+
DEFAULT_RESOLVE_ADDRESS_TYPES[1] =InternetProtocolFamily.IPv4;
84+
LOCALHOST_ADDRESS =NetUtil2.LOCALHOST6;
85+
}else {
86+
DEFAULT_RESOLVE_ADDRESS_TYPES[0] =InternetProtocolFamily.IPv4;
87+
DEFAULT_RESOLVE_ADDRESS_TYPES[1] =InternetProtocolFamily.IPv6;
88+
LOCALHOST_ADDRESS =NetUtil2.LOCALHOST4;
89+
}
8790
}
8891
}
8992

@@ -343,7 +346,7 @@ protected void doResolve(String inetHost, Promise<InetAddress> promise) throws E
343346
protectedvoiddoResolve(StringinetHost,
344347
Promise<InetAddress>promise,
345348
DnsCacheresolveCache)throwsException {
346-
finalbyte[]bytes =NetUtil.createByteArrayFromIpAddressString(inetHost);
349+
finalbyte[]bytes =NetUtil2.createByteArrayFromIpAddressString(inetHost);
347350
if (bytes !=null) {
348351
// The inetHost is actually an ipaddress.
349352
promise.setSuccess(InetAddress.getByAddress(bytes));
@@ -461,7 +464,7 @@ protected void doResolveAll(String inetHost,
461464
Promise<List<InetAddress>>promise,
462465
DnsCacheresolveCache)throwsException {
463466

464-
finalbyte[]bytes =NetUtil.createByteArrayFromIpAddressString(inetHost);
467+
finalbyte[]bytes =NetUtil2.createByteArrayFromIpAddressString(inetHost);
465468
if (bytes !=null) {
466469
// The unresolvedAddress was created via a String that contains an ipaddress.
467470
promise.setSuccess(Collections.singletonList(InetAddress.getByAddress(bytes)));

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp