aboutsummaryrefslogtreecommitdiff
path: root/lib/dns/server.go
diff options
context:
space:
mode:
authorShulhan <ms@kilabit.info>2026-01-26 22:15:23 +0700
committerShulhan <ms@kilabit.info>2026-02-02 16:28:11 +0700
commitec3f606769672da427080d0ccdd5dcd100d63f17 (patch)
tree8102563784aabaf85e530825903dc41602195a80 /lib/dns/server.go
parent85b44587e111fb92722f436ebf9dddbb68556895 (diff)
downloadpakakeh.go-ec3f606769672da427080d0ccdd5dcd100d63f17.tar.xz
lib/dns: skip caching empty answer only for query type A
Previously, we did not store response with empty RR answer for all record types. Meanwhile, some domains still does not have AAAA(28) and HTTPS(65) records set, but browser will requesting them. So, to minimize traffic for those query we skip caching only for query type A and cache the rest of types.
Diffstat (limited to 'lib/dns/server.go')
-rw-r--r--lib/dns/server.go11
1 files changed, 7 insertions, 4 deletions
diff --git a/lib/dns/server.go b/lib/dns/server.go
index e4dcbac5..075eecb9 100644
--- a/lib/dns/server.go
+++ b/lib/dns/server.go
@@ -668,16 +668,19 @@ func (srv *Server) processResponse(req *request, res *Message) (an *Answer, inse
err = errors.New(`response truncated`)
return nil, false, err
}
- if res.Header.ANCount == 0 {
- // Ignore empty answers.
+ if res.Header.ANCount == 0 && res.Question.Type == RecordTypeA {
+ // Ignore empty answers only for query type A (IPv4).
+ //
// The use case if one use and switch between two different
// networks with internal zone, frequently.
// For example, if on network Y they have domain MY.Y and
// current connection is X, request to MY.Y will return an
// empty answers.
// Once they connect to Y again, any request to MY.Y will not
- // be possible because rescached caches contains empty answer
- // for MY.Y.
+ // be possible because caches contains empty answer for MY.Y.
+ //
+ // Some domains that still have an empty answer for AAAA(28)
+ // and HTTPS(65) will get cached.
err = errors.New(`empty RR answer`)
return nil, false, err
}