Skip to content

Commit f16abc8

Browse files
committed
dnsx/alg: per-tid per-uid ip to domain mapping
1 parent 699356c commit f16abc8

File tree

5 files changed

+278
-27
lines changed

5 files changed

+278
-27
lines changed

intra/backend/netstat.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ type RDNSInfo struct {
171171
DNSDefault string
172172
DNSSystem string
173173
DNS string
174+
ALG string
174175

175176
ProxiesHas4 bool
176177
ProxiesHas6 bool

intra/common.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -519,16 +519,18 @@ func makeIPPorts(ips []netip.Addr, origipp netip.AddrPort, cap int) []netip.Addr
519519
// returned realips may be incoming algip itself or translated from algip,
520520
// depending on whether alg is enabled (ref: undidAlg).
521521
func (h *baseHandler) undoAlg(algip netip.Addr, uid string) (undidAlg bool, realips, domains, probableDomains, blocklists string) {
522+
const forcePTR = true // force PTR (realip => algans) translation?
523+
anyTransport := dnsx.NoDNS
522524
r := h.resolver
523-
didForce := false
524-
forcePTR := true // force PTR (realip => algans) translation?
525525
gw := r.Gateway()
526+
526527
ipok := !algip.IsUnspecified() && algip.IsValid()
528+
didForce := false
527529
hasreal := false
528530
if ipok && gw != nil {
529-
domains, didForce = gw.PTR(algip, !forcePTR) // does NAT (algip => algans) translation
531+
domains, didForce = gw.PTR(algip, uid, anyTransport, !forcePTR) // does NAT (algip => algans) translation
530532
if !didForce && len(domains) <= 0 {
531-
probableDomains, _ = gw.PTR(algip, forcePTR)
533+
probableDomains, _ = gw.PTR(algip, uid, anyTransport, forcePTR)
532534
}
533535
var ips []netip.Addr
534536
// ips will contain the incoming "algip" arg, in cases where alg is NOT enabled.
@@ -537,6 +539,7 @@ func (h *baseHandler) undoAlg(algip netip.Addr, uid string) (undidAlg bool, real
537539
hasreal = len(realips) > 0
538540
blocklists = gw.RDNSBL(algip)
539541
}
542+
// pick up corresponding domains from dialer's ipmap cache if none from gw.PTR
540543
if ipok && len(domains) <= 0 && len(probableDomains) <= 0 {
541544
if hosts := dialers.Ptr(algip); len(hosts) > 0 {
542545
probableDomains = strings.Join(hosts, ",")

0 commit comments

Comments
 (0)