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

Commit17575b3

Browse files
committed
Implement correct handling of recursive DNS,closeAsyncHttpClient#1329
Motivation:DnsNameResolver does not handle recursive DNS and so fails if you querya DNS server (for example a ROOT dns server) which provides the correctredirect for a domain.Modification:Add support for redirects (a.k.a. handling of AUTHORITY section').Result:Its now possible to use a DNS server that redirects.
1 parent3e6c674 commit17575b3

File tree

6 files changed

+578
-76
lines changed

6 files changed

+578
-76
lines changed

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

Lines changed: 35 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ public class DnsNameResolver extends InetNameResolver {
134134
* Cache for {@link #doResolve(String, Promise)} and {@link #doResolveAll(String, Promise)}.
135135
*/
136136
privatefinalDnsCacheresolveCache;
137+
privatefinalDnsCacheauthoritativeDnsServerCache;
137138

138139
privatefinalFastThreadLocal<DnsServerAddressStream>nameServerAddrStream =
139140
newFastThreadLocal<DnsServerAddressStream>() {
@@ -153,8 +154,8 @@ protected DnsServerAddressStream initialValue() throws Exception {
153154
privatefinalHostsFileEntriesResolverhostsFileEntriesResolver;
154155
privatefinalString[]searchDomains;
155156
privatefinalintndots;
156-
privatefinalbooleancnameFollowARecords;
157-
privatefinalbooleancnameFollowAAAARecords;
157+
privatefinalbooleansupportsAAAARecords;
158+
privatefinalbooleansupportsARecords;
158159
privatefinalInternetProtocolFamily2preferredAddressType;
159160
privatefinalDnsRecordType[]resolveRecordTypes;
160161
privatefinalbooleandecodeIdn;
@@ -178,9 +179,9 @@ protected DnsServerAddressStream initialValue() throws Exception {
178179
* @param hostsFileEntriesResolver the {@link HostsFileEntriesResolver} used to check for local aliases
179180
* @param searchDomains the list of search domain
180181
* @param ndots the ndots value
181-
* @deprecated use {@link #DnsNameResolver(EventLoop, ChannelFactory, DnsServerAddresses, DnsCache, long,
182-
* InternetProtocolFamily2[], boolean, int, boolean, int,
183-
*boolean, HostsFileEntriesResolver, String[], int, boolean)}
182+
* @deprecated use {@linkDnsNameResolver#DnsNameResolver(EventLoop, ChannelFactory, DnsServerAddresses, DnsCache,
183+
* DnsCache, long,InternetProtocolFamily2[], boolean, int, boolean, int, boolean,
184+
* HostsFileEntriesResolver, String[], int, boolean)}
184185
*/
185186
@Deprecated
186187
publicDnsNameResolver(
@@ -198,11 +199,10 @@ public DnsNameResolver(
198199
HostsFileEntriesResolverhostsFileEntriesResolver,
199200
String[]searchDomains,
200201
intndots) {
201-
this(eventLoop,channelFactory,nameServerAddresses,resolveCache,queryTimeoutMillis,resolvedAddressTypes,
202-
recursionDesired,maxQueriesPerResolve,traceEnabled,maxPayloadSize,optResourceEnabled,
203-
hostsFileEntriesResolver,searchDomains,ndots,true);
202+
this(eventLoop,channelFactory,nameServerAddresses,resolveCache,NoopDnsCache.INSTANCE,queryTimeoutMillis,
203+
resolvedAddressTypes,recursionDesired,maxQueriesPerResolve,traceEnabled,maxPayloadSize,
204+
optResourceEnabled,hostsFileEntriesResolver,searchDomains,ndots,true);
204205
}
205-
206206
/**
207207
* Creates a new DNS-based name resolver that communicates with the specified list of DNS servers.
208208
*
@@ -212,6 +212,7 @@ public DnsNameResolver(
212212
* this to determine which DNS server should be contacted for the next retry in case
213213
* of failure.
214214
* @param resolveCache the DNS resolved entries cache
215+
* @param authoritativeDnsServerCache the cache used to find the authoritative DNS server for a domain
215216
* @param queryTimeoutMillis timeout of each DNS query in millis
216217
* @param resolvedAddressTypes list of the protocol families
217218
* @param recursionDesired if recursion desired flag must be set
@@ -230,6 +231,7 @@ public DnsNameResolver(
230231
ChannelFactory<?extendsDatagramChannel>channelFactory,
231232
DnsServerAddressesnameServerAddresses,
232233
finalDnsCacheresolveCache,
234+
DnsCacheauthoritativeDnsServerCache,
233235
longqueryTimeoutMillis,
234236
InternetProtocolFamily2[]resolvedAddressTypes,
235237
booleanrecursionDesired,
@@ -241,7 +243,6 @@ public DnsNameResolver(
241243
String[]searchDomains,
242244
intndots,
243245
booleandecodeIdn) {
244-
245246
super(eventLoop);
246247
checkNotNull(channelFactory,"channelFactory");
247248
this.nameServerAddresses =checkNotNull(nameServerAddresses,"nameServerAddresses");
@@ -254,22 +255,23 @@ public DnsNameResolver(
254255
this.optResourceEnabled =optResourceEnabled;
255256
this.hostsFileEntriesResolver =checkNotNull(hostsFileEntriesResolver,"hostsFileEntriesResolver");
256257
this.resolveCache =checkNotNull(resolveCache,"resolveCache");
258+
this.authoritativeDnsServerCache =checkNotNull(authoritativeDnsServerCache,"authoritativeDnsServerCache");
257259
this.searchDomains =checkNotNull(searchDomains,"searchDomains").clone();
258260
this.ndots =checkPositiveOrZero(ndots,"ndots");
259261
this.decodeIdn =decodeIdn;
260262

261-
booleancnameFollowARecords =false;
262-
booleancnameFollowAAAARecords =false;
263+
booleansupportsARecords =false;
264+
booleansupportsAAAARecords =false;
263265
// Use LinkedHashSet to maintain correct ordering.
264266
Set<DnsRecordType>recordTypes =newLinkedHashSet<DnsRecordType>(resolvedAddressTypes.length);
265267
for (InternetProtocolFamily2family:resolvedAddressTypes) {
266268
switch (family) {
267269
caseIPv4:
268-
cnameFollowARecords =true;
270+
supportsARecords =true;
269271
recordTypes.add(DnsRecordType.A);
270272
break;
271273
caseIPv6:
272-
cnameFollowAAAARecords =true;
274+
supportsAAAARecords =true;
273275
recordTypes.add(DnsRecordType.AAAA);
274276
break;
275277
default:
@@ -278,9 +280,9 @@ public DnsNameResolver(
278280
}
279281

280282
// One of both must be always true.
281-
assertcnameFollowARecords ||cnameFollowAAAARecords;
282-
this.cnameFollowAAAARecords =cnameFollowAAAARecords;
283-
this.cnameFollowARecords =cnameFollowARecords;
283+
assertsupportsARecords ||supportsAAAARecords;
284+
this.supportsAAAARecords =supportsAAAARecords;
285+
this.supportsARecords =supportsARecords;
284286
resolveRecordTypes =recordTypes.toArray(newDnsRecordType[recordTypes.size()]);
285287
preferredAddressType =resolvedAddressTypes[0];
286288

@@ -308,13 +310,25 @@ public void operationComplete(ChannelFuture future) throws Exception {
308310
});
309311
}
310312

313+
// Only here to override in unit tests.
314+
intdnsRedirectPort(@SuppressWarnings("unused")InetAddressserver) {
315+
returnDnsServerAddresses.DNS_PORT;
316+
}
317+
311318
/**
312319
* Returns the resolution cache.
313320
*/
314321
publicDnsCacheresolveCache() {
315322
returnresolveCache;
316323
}
317324

325+
/**
326+
* Returns the cache used for authoritative DNS servers for a domain.
327+
*/
328+
publicDnsCacheauthoritativeDnsServerCache() {
329+
returnauthoritativeDnsServerCache;
330+
}
331+
318332
/**
319333
* Returns the timeout of each DNS query performed by this resolver (in milliseconds).
320334
* The default value is 5 seconds.
@@ -344,12 +358,12 @@ final int ndots() {
344358
returnndots;
345359
}
346360

347-
finalbooleanisCnameFollowAAAARecords() {
348-
returncnameFollowAAAARecords;
361+
finalbooleansupportsAAAARecords() {
362+
returnsupportsAAAARecords;
349363
}
350364

351-
finalbooleanisCnameFollowARecords() {
352-
returncnameFollowARecords;
365+
finalbooleansupportsARecords() {
366+
returnsupportsARecords;
353367
}
354368

355369
finalInternetProtocolFamily2preferredAddressType() {

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

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ public final class DnsNameResolverBuilder {
4040
privateChannelFactory<?extendsDatagramChannel>channelFactory;
4141
privateDnsServerAddressesnameServerAddresses =DnsServerAddresses.defaultAddresses();
4242
privateDnsCacheresolveCache;
43+
privateDnsCacheauthoritativeDnsServerCache;
4344
privateIntegerminTtl;
4445
privateIntegermaxTtl;
4546
privateIntegernegativeTtl;
@@ -109,6 +110,17 @@ public DnsNameResolverBuilder resolveCache(DnsCache resolveCache) {
109110
returnthis;
110111
}
111112

113+
/**
114+
* Sets the cache for authoritive NS servers
115+
*
116+
* @param authoritativeDnsServerCache the authoritive NS servers cache
117+
* @return {@code this}
118+
*/
119+
publicDnsNameResolverBuilderauthoritativeDnsServerCache(DnsCacheauthoritativeDnsServerCache) {
120+
this.authoritativeDnsServerCache =authoritativeDnsServerCache;
121+
returnthis;
122+
}
123+
112124
/**
113125
* Sets the minimum and maximum TTL of the cached DNS resource records (in seconds). If the TTL of the DNS
114126
* resource record returned by the DNS server is less than the minimum TTL or greater than the maximum TTL,
@@ -331,6 +343,10 @@ public DnsNameResolverBuilder ndots(int ndots) {
331343
returnthis;
332344
}
333345

346+
privateDnsCachenewCache() {
347+
returnnewDefaultDnsCache(intValue(minTtl,0),intValue(maxTtl,Integer.MAX_VALUE),intValue(negativeTtl,0));
348+
}
349+
334350
/**
335351
* Set if domain / host names should be decoded to unicode when received.
336352
* See <a href="https://tools.ietf.org/html/rfc3492">rfc3492</a>.
@@ -349,19 +365,23 @@ public DnsNameResolverBuilder decodeIdn(boolean decodeIdn) {
349365
* @return a {@link DnsNameResolver}
350366
*/
351367
publicDnsNameResolverbuild() {
352-
353368
if (resolveCache !=null && (minTtl !=null ||maxTtl !=null ||negativeTtl !=null)) {
354369
thrownewIllegalStateException("resolveCache and TTLs are mutually exclusive");
355370
}
356371

357-
DnsCachecache =resolveCache !=null ?resolveCache :
358-
newDefaultDnsCache(intValue(minTtl,0),intValue(maxTtl,Integer.MAX_VALUE),intValue(negativeTtl,0));
372+
if (authoritativeDnsServerCache !=null && (minTtl !=null ||maxTtl !=null ||negativeTtl !=null)) {
373+
thrownewIllegalStateException("authoritativeDnsServerCache and TTLs are mutually exclusive");
374+
}
359375

376+
DnsCacheresolveCache =this.resolveCache !=null ?this.resolveCache :newCache();
377+
DnsCacheauthoritativeDnsServerCache =this.authoritativeDnsServerCache !=null ?
378+
this.authoritativeDnsServerCache :newCache();
360379
returnnewDnsNameResolver(
361380
eventLoop,
362381
channelFactory,
363382
nameServerAddresses,
364-
cache,
383+
resolveCache,
384+
authoritativeDnsServerCache,
365385
queryTimeoutMillis,
366386
resolvedAddressTypes,
367387
recursionDesired,

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp