You need to sign in or sign up before continuing.
Commit 296222d6 authored by Miek Gieben's avatar Miek Gieben Committed by GitHub

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: default avatarMiek Gieben <miek@miek.nl>
parent 15ff9f37
...@@ -2,6 +2,9 @@ package dnssec ...@@ -2,6 +2,9 @@ package dnssec
import ( import (
"hash/fnv" "hash/fnv"
"io"
"strconv"
"strings"
"github.com/miekg/dns" "github.com/miekg/dns"
) )
...@@ -9,14 +12,16 @@ import ( ...@@ -9,14 +12,16 @@ import (
// hash serializes the RRset and returns a signature cache key. // hash serializes the RRset and returns a signature cache key.
func hash(rrs []dns.RR) uint64 { func hash(rrs []dns.RR) uint64 {
h := fnv.New64() h := fnv.New64()
buf := make([]byte, 256) // Only need this to be unique for ownername + qtype (+class), but we
for _, r := range rrs { // only care about IN. Its already an RRSet, so the ownername is the
off, err := dns.PackRR(r, buf, 0, nil, false) // same as is the qtype. Take the first one and construct the hash
if err == nil { // string that creates the key
h.Write(buf[:off]) 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() i := h.Sum64()
return i return i
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment