Skip to content

Commit 0e13f9f

Browse files
committed
dnsx/alg: m use ptr mapping when required
1 parent 742b686 commit 0e13f9f

1 file changed

Lines changed: 22 additions & 6 deletions

File tree

intra/dnsx/alg.go

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2167,6 +2167,10 @@ func (t *dnsgateway) maybeUndoNat64Locked(realips ...netip.Addr) (unnateds []net
21672167
}
21682168

21692169
func (t *dnsgateway) ptrLocked(maybeAlg netip.Addr, uid, tid string, useptr bool) (domains []string) {
2170+
alivedoms := true
2171+
hasnatdoms := false
2172+
hasdoms := false
2173+
21702174
// alg ips are always unmapped; see take4Locked
21712175
unmapped := maybeAlg.Unmap()
21722176
if len(uid) <= 0 {
@@ -2177,13 +2181,25 @@ func (t *dnsgateway) ptrLocked(maybeAlg netip.Addr, uid, tid string, useptr bool
21772181
}
21782182
if ans, ok := t.nat[unmapped]; ok {
21792183
domains = domainsFor(ans, tid, uid, unmapped, xalive)
2180-
} else if ans, ok := t.ptr[unmapped]; useptr && ok {
2181-
// translate from realip only if not in mod mode
2182-
// for useptr, s/xalive/xall/
2183-
domains = domainsFor(ans, tid, uid, unmapped, xalive /*prefer fresh mapping */)
2184-
if len(domains) <= 0 {
2185-
domains = domainsFor(ans, tid, uid, unmapped, xall /*useptr == true */)
2184+
hasnatdoms = len(domains) > 0
2185+
hasdoms = hasnatdoms
2186+
}
2187+
if useptr && !hasnatdoms {
2188+
if ans, ok := t.ptr[unmapped]; ok {
2189+
// translate from realip only if not in mod mode
2190+
// for useptr, s/xalive/xall/
2191+
domains = domainsFor(ans, tid, uid, unmapped, xalive /*prefer fresh mapping */)
2192+
hasdoms = len(domains) > 0
2193+
if !hasdoms {
2194+
domains = domainsFor(ans, tid, uid, unmapped, xall /*useptr == true */)
2195+
alivedoms = false
2196+
}
21862197
}
2198+
hasdoms = len(domains) > 0
2199+
}
2200+
if log.Debug || !hasdoms {
2201+
loged(!hasdoms)("alg: ptr: in nat? (natdoms? %t / doms? %t) for %v[%s@%s] => in ptr? (useptr? %t / gotalive? %t)? (%v)",
2202+
hasnatdoms, hasdoms, unmapped, tid, uid, useptr, alivedoms, domains)
21872203
}
21882204
return copyUniq(domains)
21892205
}

0 commit comments

Comments
 (0)