Skip to content

Commit

Permalink
dns: only cache records we can return
Browse files Browse the repository at this point in the history
  • Loading branch information
BeryJu committed Dec 12, 2024
1 parent 7f5fb81 commit 5b53b92
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion pkg/roles/dns/handler_forward_ip.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,27 @@ func (ipf *IPForwarderHandler) Identifier() string {
return IPForwarderType
}

// Only cache records we can handle
func (ipf *IPForwarderHandler) canCacheRecord(ans dns.RR) bool {
switch ans.(type) {
case *dns.A:
case *dns.AAAA:
case *dns.TXT:
case *dns.PTR:
case *dns.CNAME:
case *dns.MX:
case *dns.SRV:
return true
}
return false
}

func (ipf *IPForwarderHandler) cacheToEtcd(r *utils.DNSRequest, query dns.Question, ans dns.RR, idx int) {
cs := sentry.TransactionFromContext(r.Context()).StartChild("gravity.dns.handler.forward_ip.cache")
cs.SetTag("gravity.dns.handler.forward_ip.cache.query", query.String())
cs.SetTag("gravity.dns.handler.forward_ip.cache.ans", ans.String())
defer cs.Finish()
if ans == nil {
if ans == nil || !ipf.canCacheRecord(ans) {
return
}
cacheTtl := ans.Header().Ttl
Expand Down

0 comments on commit 5b53b92

Please sign in to comment.