Skip to content

Commit

Permalink
Fix IP hash
Browse files Browse the repository at this point in the history
Select the correct slice of bytes to hash based on IPv4 or IPv6 address
family.

Signed-off-by: SuperQ <[email protected]>
  • Loading branch information
SuperQ committed Jan 22, 2022
1 parent 70bff79 commit 3383091
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion prober/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}

0 comments on commit 3383091

Please sign in to comment.