aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Miek Gieben <miek@miek.nl> 2021-01-10 08:30:00 +0100
committerGravatar GitHub <noreply@github.com> 2021-01-10 08:30:00 +0100
commit296222d613ee2dd52b0916ccb515cc44efc4b37e (patch)
treec1be326266ec7d5feba29d4425df55122876565d
parent15ff9f37957b60f58cc6b5b2ea8e6fd27ca461d5 (diff)
downloadcoredns-296222d613ee2dd52b0916ccb515cc44efc4b37e.tar.gz
coredns-296222d613ee2dd52b0916ccb515cc44efc4b37e.tar.zst
coredns-296222d613ee2dd52b0916ccb515cc44efc4b37e.zip
plugin/dnssec: Change hash key input (#4372)
Make this vastly simpler and more efficient. Adding all the bytes and then letting loose fnv doesn't add anything and may actually do the wrong thing. See: #3953 Fixes: #3953 Signed-off-by: Miek Gieben <miek@miek.nl>
-rw-r--r--plugin/dnssec/cache.go19
1 files changed, 12 insertions, 7 deletions
diff --git a/plugin/dnssec/cache.go b/plugin/dnssec/cache.go
index bfc2dcdcf..d93cdabd1 100644
--- a/plugin/dnssec/cache.go
+++ b/plugin/dnssec/cache.go
@@ -2,6 +2,9 @@ package dnssec
import (
"hash/fnv"
+ "io"
+ "strconv"
+ "strings"
"github.com/miekg/dns"
)
@@ -9,14 +12,16 @@ import (
// hash serializes the RRset and returns a signature cache key.
func hash(rrs []dns.RR) uint64 {
h := fnv.New64()
- buf := make([]byte, 256)
- for _, r := range rrs {
- off, err := dns.PackRR(r, buf, 0, nil, false)
- if err == nil {
- h.Write(buf[:off])
- }
+ // Only need this to be unique for ownername + qtype (+class), but we
+ // only care about IN. Its already an RRSet, so the ownername is the
+ // same as is the qtype. Take the first one and construct the hash
+ // string that creates the key
+ io.WriteString(h, strings.ToLower(rrs[0].Header().Name))
+ typ, ok := dns.TypeToString[rrs[0].Header().Rrtype]
+ if !ok {
+ typ = "TYPE" + strconv.FormatUint(uint64(rrs[0].Header().Rrtype), 10)
}
-
+ io.WriteString(h, typ)
i := h.Sum64()
return i
}