From: SuperQ Date: Sat, 22 Jan 2022 15:37:30 +0000 (+0100) Subject: Fix IP hash X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=338309104e6c00fa6be6f27dcc05ee34c2e16b01;p=blackbox_exporter.git Fix IP hash Select the correct slice of bytes to hash based on IPv4 or IPv6 address family. Signed-off-by: SuperQ --- diff --git a/prober/utils.go b/prober/utils.go index 74fb41d..52f9f34 100644 --- a/prober/utils.go +++ b/prober/utils.go @@ -135,6 +135,10 @@ func chooseProtocol(ctx context.Context, IPProtocol string, fallbackIPProtocol b func ipHash(ip net.IP) float64 { h := fnv.New32a() - h.Write(ip) + if ip.To4() != nil { + h.Write(ip.To4()) + } else { + h.Write(ip.To16()) + } return float64(h.Sum32()) }