properly assign key for address mapping
This commit is contained in:
parent
dd278b7374
commit
a0fabf96f2
11
addr-map.go
11
addr-map.go
@ -90,13 +90,6 @@ func addrMapGet(srcIp net.IP, dstCidr *net.IPNet, ttl uint32) net.IP {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("rand.Read(): error %v", err)
|
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
|
// adjust random bytes to dstCidr
|
||||||
for i := range addrlen / 4 {
|
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()
|
curr.Created = time.Now()
|
||||||
|
|
||||||
var xprev any
|
var hkey, xprev any
|
||||||
var loaded bool
|
var loaded bool
|
||||||
switch addrlen {
|
switch addrlen {
|
||||||
case net.IPv4len:
|
case net.IPv4len:
|
||||||
|
hkey = binary.NativeEndian.Uint32(curr.SrcAddr)
|
||||||
xprev, loaded = addr4.LoadOrStore(hkey, curr)
|
xprev, loaded = addr4.LoadOrStore(hkey, curr)
|
||||||
case net.IPv6len:
|
case net.IPv6len:
|
||||||
|
hkey = binary.NativeEndian.Uint64(curr.SrcAddr[net.IPv6len/2:])
|
||||||
xprev, loaded = addr6.LoadOrStore(hkey, curr)
|
xprev, loaded = addr6.LoadOrStore(hkey, curr)
|
||||||
}
|
}
|
||||||
if !loaded {
|
if !loaded {
|
||||||
|
Loading…
Reference in New Issue
Block a user