@@ -605,7 +605,7 @@ func (p *xdomains) String() string {
605605 return fmt .Sprintf ("xdomains: pri(%v)" , p .pri )
606606}
607607
608- func (p * xdomains ) domainsFor (tid , uid string , s xaddrstatus ) (out []string ) {
608+ func (p * xdomains ) domainsFor (tid , uid string , forIP netip. Addr , s xaddrstatus ) (out []string ) {
609609 if p == nil {
610610 return nil
611611 }
@@ -637,7 +637,7 @@ func (p *xdomains) domainsFor(tid, uid string, s xaddrstatus) (out []string) {
637637 }
638638
639639 if settings .Debug {
640- log .VV ("alg: xdomains: xof(%s): %s => %v [%v]" , s , key , out , core .Map (ttls , core .FmtTimeAsPeriod ))
640+ log .VV ("alg: xdomains: xof(%s/%s ): %s => %v [%v]" , s , forIP , key , out , core .Map (ttls , core .FmtTimeAsPeriod ))
641641 }
642642 return
643643}
@@ -783,11 +783,11 @@ func (a *algans) merge(b *algans) {
783783 }
784784}
785785
786- func domainsFor (base * baseans , tid , uid string , s xaddrstatus ) []string {
786+ func domainsFor (base * baseans , tid , uid string , forIP netip. Addr , s xaddrstatus ) []string {
787787 if base == nil || base .domains == nil {
788788 return nil
789789 }
790- return base .domains .domainsFor (tid , uid , s )
790+ return base .domains .domainsFor (tid , uid , forIP , s )
791791}
792792
793793type dnsgateway struct {
@@ -1855,7 +1855,7 @@ func (t *dnsgateway) xLocked(maybeAlg netip.Addr, usestale bool, uid string, tid
18551855 } // else: send realips as is
18561856
18571857 logeif (! hasrealips && (! usestale && (! undidAlg || ! undidPtr )))("alg: dns64: for %v[%s] (didnotAlg? %t / fresh? %t / undidAlg? %t / undidPtr? %t / staleok? %t) algip(%v) => realips(%v) => unnated(%v); until: %s" ,
1858- tids , uid , didnotAlg , fresh , undidPtr , undidAlg , usestale , unmapped , realips , unnated , until )
1858+ tids , uid , didnotAlg , fresh , undidAlg , undidPtr , usestale , unmapped , realips , unnated , until )
18591859
18601860 if len (unnated ) > 0 { // unnated is already de-duplicated
18611861 return unnated , undidAlg
@@ -1915,13 +1915,13 @@ func (t *dnsgateway) ptrLocked(maybeAlg netip.Addr, uid, tid string, useptr bool
19151915 tid = notransport
19161916 }
19171917 if ans , ok := t .nat [unmapped ]; ok {
1918- domains = domainsFor (ans , tid , uid , xalive )
1918+ domains = domainsFor (ans , tid , uid , unmapped , xalive )
19191919 } else if ans , ok := t .ptr [unmapped ]; useptr && ok {
19201920 // translate from realip only if not in mod mode
19211921 // for useptr, s/xalive/xall/
1922- domains = domainsFor (ans , tid , uid , xalive /*prefer fresh mapping */ )
1922+ domains = domainsFor (ans , tid , uid , unmapped , xalive /*prefer fresh mapping */ )
19231923 if len (domains ) <= 0 {
1924- domains = domainsFor (ans , tid , uid , xall /*useptr == true */ )
1924+ domains = domainsFor (ans , tid , uid , unmapped , xall /*useptr == true */ )
19251925 }
19261926 }
19271927 return copyUniq (domains )
@@ -1949,7 +1949,7 @@ func (t *dnsgateway) resolvLocked(domain string, typ iptype, tid, uid string) (i
19491949 if ans , ok := t .alg [k4 ]; ok {
19501950 if life , fresh := ans .fresh (); fresh { // not stale
19511951 ip4s = append (ip4s , ans .algip )
1952- targets = append (targets , domainsFor (ans .baseans , tid , uid , xalive )... )
1952+ targets = append (targets , domainsFor (ans .baseans , tid , uid , ans . algip , xalive )... )
19531953 until = min (until , life )
19541954 } else {
19551955 staleips = append (staleips , ans .algip )
@@ -1963,7 +1963,7 @@ func (t *dnsgateway) resolvLocked(domain string, typ iptype, tid, uid string) (i
19631963 if ans , ok := t .alg [k6 ]; ok {
19641964 if life , fresh := ans .fresh (); fresh { // not stale
19651965 ip6s = append (ip6s , ans .algip )
1966- targets = append (targets , domainsFor (ans .baseans , tid , uid , xalive )... )
1966+ targets = append (targets , domainsFor (ans .baseans , tid , uid , ans . algip , xalive )... )
19671967 until = min (until , life )
19681968 } else {
19691969 staleips = append (staleips , ans .algip )
@@ -1981,8 +1981,9 @@ func (t *dnsgateway) resolvLocked(domain string, typ iptype, tid, uid string) (i
19811981 k4 := partkey4 + strconv .Itoa (i )
19821982 if ans , ok := t .alg [k4 ]; ok {
19831983 if life , fresh := ans .fresh (); fresh { // not stale
1984- ip4s = append (ip4s , v4only (ans .ips .realipsFor (tid , uid , xalive ))... )
1985- targets = append (targets , domainsFor (ans .baseans , tid , uid , xalive )... )
1984+ all4s := v4only (ans .ips .realipsFor (tid , uid , xalive ))
1985+ ip4s = append (ip4s , all4s ... )
1986+ targets = append (targets , domainsFor (ans .baseans , tid , uid , core .FirstOf (all4s ), xalive )... )
19861987 until = min (until , life )
19871988 } else {
19881989 staleips = append (staleips , ans .ips .realipsFor (tid , uid , xall )... )
@@ -1995,8 +1996,9 @@ func (t *dnsgateway) resolvLocked(domain string, typ iptype, tid, uid string) (i
19951996 k6 := partkey6 + strconv .Itoa (i )
19961997 if ans , ok := t .alg [k6 ]; ok {
19971998 if life , fresh := ans .fresh (); fresh { // not stale
1998- ip6s = append (ip6s , v6only (ans .ips .realipsFor (tid , uid , xalive ))... )
1999- targets = append (targets , domainsFor (ans .baseans , tid , uid , xalive )... )
1999+ all6s := v6only (ans .ips .realipsFor (tid , uid , xalive ))
2000+ ip6s = append (ip6s , all6s ... )
2001+ targets = append (targets , domainsFor (ans .baseans , tid , uid , core .FirstOf (all6s ), xalive )... )
20002002 until = min (until , life )
20012003 } else {
20022004 staleips = append (staleips , ans .ips .realipsFor (tid , uid , xall )... )
@@ -2014,8 +2016,9 @@ func (t *dnsgateway) resolvLocked(domain string, typ iptype, tid, uid string) (i
20142016 k4 := partkey4 + strconv .Itoa (i )
20152017 if ans , ok := t .alg [k4 ]; ok {
20162018 if life , fresh := ans .fresh (); fresh { // not stale
2017- ip4s = append (ip4s , v4only (ans .ips .secipsFor (tid , uid ))... )
2018- targets = append (targets , domainsFor (ans .baseans , tid , uid , xalive )... )
2019+ all4s := v4only (ans .ips .secipsFor (tid , uid ))
2020+ ip4s = append (ip4s , all4s ... )
2021+ targets = append (targets , domainsFor (ans .baseans , tid , uid , core .FirstOf (all4s ), xalive )... )
20192022 until = min (until , life )
20202023 } else {
20212024 staleips = append (staleips , ans .ips .secips (xall )... )
@@ -2028,8 +2031,9 @@ func (t *dnsgateway) resolvLocked(domain string, typ iptype, tid, uid string) (i
20282031 k6 := partkey6 + strconv .Itoa (i )
20292032 if ans , ok := t .alg [k6 ]; ok {
20302033 if life , fresh := ans .fresh (); fresh { // not stale
2031- ip6s = append (ip6s , v6only (ans .ips .secipsFor (tid , uid ))... )
2032- targets = append (targets , domainsFor (ans .baseans , tid , uid , xalive )... )
2034+ all6s := v6only (ans .ips .secipsFor (tid , uid ))
2035+ ip6s = append (ip6s , all6s ... )
2036+ targets = append (targets , domainsFor (ans .baseans , tid , uid , core .FirstOf (all6s ), xalive )... )
20332037 until = min (until , life )
20342038 } else {
20352039 // TODO: stale targets?
0 commit comments