properly assign key for address mapping

This commit is contained in:
Konstantin Demin 2024-06-06 09:57:13 +03:00
parent dd278b7374
commit a0fabf96f2
Signed by: krd
GPG Key ID: 4D56F87A8BA65FD0

View File

@ -90,13 +90,6 @@ func addrMapGet(srcIp net.IP, dstCidr *net.IPNet, ttl uint32) net.IP {
if err != nil {
log.Fatalf("rand.Read(): error %v", err)
}
var hkey any
switch addrlen {
case net.IPv4len:
hkey = binary.NativeEndian.Uint32(curr.SrcAddr)
case net.IPv6len:
hkey = binary.NativeEndian.Uint64(curr.SrcAddr[net.IPv6len/2:])
}
// adjust random bytes to dstCidr
for i := range addrlen / 4 {
@ -109,12 +102,14 @@ func addrMapGet(srcIp net.IP, dstCidr *net.IPNet, ttl uint32) net.IP {
curr.Created = time.Now()
var xprev any
var hkey, xprev any
var loaded bool
switch addrlen {
case net.IPv4len:
hkey = binary.NativeEndian.Uint32(curr.SrcAddr)
xprev, loaded = addr4.LoadOrStore(hkey, curr)
case net.IPv6len:
hkey = binary.NativeEndian.Uint64(curr.SrcAddr[net.IPv6len/2:])
xprev, loaded = addr6.LoadOrStore(hkey, curr)
}
if !loaded {