Skip to content

Commit b7642c1

Browse files
committed
x64: protect map contents from race
1 parent 81d9105 commit b7642c1

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

intra/x64/dns64.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,9 +178,9 @@ func (d *dns64) eval(network string, force64 bool, ansin *dns.Msg, r, uid string
178178
id := id64(r)
179179
ip64 := d.get(id)
180180
if len(ip64) <= 0 {
181-
if ip64 = d.ip64[dnsx.UnderlayResolver]; len(ip64) <= 0 {
182-
if ip64 = d.ip64[dnsx.OverlayResolver]; len(ip64) <= 0 {
183-
ip64 = d.ip64[dnsx.Local464Resolver]
181+
if ip64 = d.get(dnsx.UnderlayResolver); len(ip64) <= 0 {
182+
if ip64 = d.get(dnsx.OverlayResolver); len(ip64) <= 0 {
183+
ip64 = d.get(dnsx.Local464Resolver)
184184
}
185185
}
186186
log.D("dns64: attempt underlay/local464 resolver [%s@%s] ip64 (ad? %t) w len(%d)", r, uid, hasauth, len(ip64))

intra/x64/natpt.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
package x64
88

99
import (
10+
"maps"
1011
"net"
1112
"net/netip"
1213

@@ -90,7 +91,12 @@ func (n *natPt) X64(id string, ip6 netip.Addr) (ip4 netip.Addr) {
9091

9192
rawip := addr2ip(ip6)
9293
if id == dnsx.AnyResolver {
93-
for tid, prefixes := range n.ip64 {
94+
n.RLock()
95+
all := make(map[string][]*net.IPNet, len(n.ip64))
96+
maps.Copy(all, n.ip64)
97+
n.RUnlock()
98+
99+
for tid, prefixes := range all {
94100
if len(prefixes) <= 0 {
95101
continue
96102
}
@@ -157,11 +163,7 @@ func (n *natPt) UIP(network string) []byte {
157163
}
158164

159165
func (n *natPt) nat64PrefixForResolver(id string) []*net.IPNet {
160-
if ips, ok := n.ip64[id]; !ok {
161-
return nil
162-
} else {
163-
return ips
164-
}
166+
return n.get(id)
165167
}
166168

167169
// match returns the first matching prefix for ip in nets.

0 commit comments

Comments
 (0)