Skip to content

Commit 0efdd8b

Browse files
committed
dnsx/alg: m get all domains from ptr cache
freshness can be ignored when ptr is being required (that is, alg translation is disabled), as some firewall functionality depends on some/any mapping between domains and a given ip.
1 parent d762e71 commit 0efdd8b

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

intra/dnsx/alg.go

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -613,6 +613,7 @@ func (p *xdomains) domainsFor(tid, uid string, s xaddrstatus) (out []string) {
613613
uid = core.UNKNOWN_UID_STR
614614
}
615615

616+
ttls := []time.Time{}
616617
key := tid + uid
617618

618619
p.pmu.RLock()
@@ -623,11 +624,21 @@ func (p *xdomains) domainsFor(tid, uid string, s xaddrstatus) (out []string) {
623624
if !strings.HasSuffix(k, uid) {
624625
continue
625626
}
627+
if settings.Debug {
628+
ttls = append(ttls, v.ttl)
629+
}
626630
out = append(out, v.get(s)...)
627631
}
628632
} else if v, ok := p.pri[key]; ok {
633+
if settings.Debug {
634+
ttls = append(ttls, v.ttl)
635+
}
629636
out = v.get(s)
630637
}
638+
639+
if settings.Debug {
640+
log.VV("alg: xdomains: xof(%s): %s => %v [%v]", s, key, out, core.Map(ttls, core.FmtTimeAsPeriod))
641+
}
631642
return
632643
}
633644

@@ -1075,6 +1086,7 @@ func (t *dnsgateway) q(t1, t2 Transport, preset []netip.Addr, network, uid strin
10751086
// should not be alg'd as the alg'd ips will end up as "realips" in xips caches.
10761087
// nb: setting mod = false will achieve the same effect but it goes through
10771088
// the effort of setting up alg/ptr/nat caches which is wasteful in this case.
1089+
// TODO: handle Loopback scenario for uidself (which probably should be alg'd?)
10781090
dontalg := usepreset || skipcache || uidself || hasblock
10791091
synthAns := usepreset || usefixed
10801092
hasdnssec := xdns.IsDNSSECRequested(q)
@@ -1900,8 +1912,11 @@ func (t *dnsgateway) ptrLocked(maybeAlg netip.Addr, uid, tid string, useptr bool
19001912
domains = domainsFor(ans, tid, uid, xalive)
19011913
} else if ans, ok := t.ptr[unmapped]; useptr && ok {
19021914
// translate from realip only if not in mod mode
1903-
// XXX: for useptr, s/xalive/xall/?
1904-
domains = domainsFor(ans, tid, uid, xalive)
1915+
// for useptr, s/xalive/xall/
1916+
domains = domainsFor(ans, tid, uid, xalive /*prefer fresh mapping */)
1917+
if len(domains) <= 0 {
1918+
domains = domainsFor(ans, tid, uid, xall /*useptr == true */)
1919+
}
19051920
}
19061921
return copyUniq(domains)
19071922
}

0 commit comments

Comments
 (0)