Skip to content

Commit 694139b

Browse files
patternihaMeo597
authored andcommitted
DNS: Use cache for NXDOMAIN (rcode 3 error) (#4560)
XTLS/Xray-core#4558 (comment)
1 parent 2c18647 commit 694139b

4 files changed

Lines changed: 4 additions & 4 deletions

File tree

app/dns/nameserver_doh.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ func (s *DoHNameServer) QueryIP(ctx context.Context, domain string, clientIP net
355355
errors.LogDebug(ctx, "DNS cache is disabled. Querying IP for ", domain, " at ", s.name)
356356
} else {
357357
ips, ttl, err := s.findIPsForDomain(fqdn, option)
358-
if err == nil || err == dns_feature.ErrEmptyResponse {
358+
if err == nil || err == dns_feature.ErrEmptyResponse || dns_feature.RCodeFromError(err) == 3 {
359359
errors.LogDebugInner(ctx, err, s.name, " cache HIT ", domain, " -> ", ips)
360360
log.Record(&log.DNSLog{Server: s.name, Domain: domain, Result: ips, Status: log.DNSCacheHit, Elapsed: 0, Error: err})
361361
return ips, ttl, err

app/dns/nameserver_quic.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ func (s *QUICNameServer) QueryIP(ctx context.Context, domain string, clientIP ne
300300
errors.LogDebug(ctx, "DNS cache is disabled. Querying IP for ", domain, " at ", s.name)
301301
} else {
302302
ips, ttl, err := s.findIPsForDomain(fqdn, option)
303-
if err == nil || err == dns_feature.ErrEmptyResponse {
303+
if err == nil || err == dns_feature.ErrEmptyResponse || dns_feature.RCodeFromError(err) == 3 {
304304
errors.LogDebugInner(ctx, err, s.name, " cache HIT ", domain, " -> ", ips)
305305
log.Record(&log.DNSLog{Server: s.name, Domain: domain, Result: ips, Status: log.DNSCacheHit, Elapsed: 0, Error: err})
306306
return ips, ttl, err

app/dns/nameserver_tcp.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ func (s *TCPNameServer) QueryIP(ctx context.Context, domain string, clientIP net
325325
errors.LogDebug(ctx, "DNS cache is disabled. Querying IP for ", domain, " at ", s.name)
326326
} else {
327327
ips, ttl, err := s.findIPsForDomain(fqdn, option)
328-
if err == nil || err == dns_feature.ErrEmptyResponse {
328+
if err == nil || err == dns_feature.ErrEmptyResponse || dns_feature.RCodeFromError(err) == 3 {
329329
errors.LogDebugInner(ctx, err, s.name, " cache HIT ", domain, " -> ", ips)
330330
log.Record(&log.DNSLog{Server: s.name, Domain: domain, Result: ips, Status: log.DNSCacheHit, Elapsed: 0, Error: err})
331331
return ips, ttl, err

app/dns/nameserver_udp.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ func (s *ClassicNameServer) QueryIP(ctx context.Context, domain string, clientIP
252252
errors.LogDebug(ctx, "DNS cache is disabled. Querying IP for ", domain, " at ", s.name)
253253
} else {
254254
ips, ttl, err := s.findIPsForDomain(fqdn, option)
255-
if err == nil || err == dns_feature.ErrEmptyResponse {
255+
if err == nil || err == dns_feature.ErrEmptyResponse || dns_feature.RCodeFromError(err) == 3 {
256256
errors.LogDebugInner(ctx, err, s.name, " cache HIT ", domain, " -> ", ips)
257257
log.Record(&log.DNSLog{Server: s.name, Domain: domain, Result: ips, Status: log.DNSCacheHit, Elapsed: 0, Error: err})
258258
return ips, ttl, err

0 commit comments

Comments
 (0)