@@ -835,6 +835,9 @@ func (t *dnsgateway) q(t1, t2 Transport, preset []netip.Addr, network, uid strin
835835 // the effort of setting up alg/ptr/nat caches which is wasteful in this case.
836836 dontalg := usepreset || skipcache || uidself
837837 synthAns := usepreset || usefixed
838+ hasdnssec := xdns .IsDNSSECRequested (q )
839+
840+ smm .DO = hasdnssec
838841
839842 if discarduid {
840843 uid = core .UNKNOWN_UID_STR
@@ -888,14 +891,17 @@ func (t *dnsgateway) q(t1, t2 Transport, preset []netip.Addr, network, uid strin
888891 if ! xdns .HasRcodeSuccess (ansin ) {
889892 return ansin , err
890893 }
891- log .D ("alg: err but ans ok: %d; self? %t synth? %t; qerr %v" ,
892- xdns .Len (ansin ), uidself , synthAns , err )
894+ log .D ("alg: for %s:%s err but ans ok: %d; do? %t, self? %t synth? %t; qerr %v" ,
895+ qname ( q ), qtype ( q ), xdns .Len (ansin ), hasdnssec , uidself , synthAns , err )
893896 }
894897
895898 if ansin == nil { // may be nil on errors
896899 return nil , errNoAnswer // err is nil
897900 }
898901
902+ hasauth64 := false
903+ hasauth := xdns .IsDNSSECAnswerAuthenticated (ansin )
904+
899905 qname := qname (ansin )
900906 qtyp := qtype (ansin )
901907 smm .QName = qname
@@ -904,14 +910,19 @@ func (t *dnsgateway) q(t1, t2 Transport, preset []netip.Addr, network, uid strin
904910 // if usefixed is true, then d64 is no-op, as preset fixed ip does have ipv6
905911 ans64 := t .dns64 .D64 (network , t1 .ID ().V (), uid , ansin ) // ans64 may be nil if no D64 or error
906912 if ans64 != nil {
907- log .D ("alg: %s<>%s:%s[%s] %d dns64; s/ans(%d)/ans64(%d)" ,
908- qname , smm .ID , idstr (t1 ), uid , qtyp , xdns .Len (ansin ), xdns .Len (ans64 ))
913+ log .D ("alg: %s<>%s:%s[%s] %d dns64; dnssec? %t; s/ans(%d)/ans64(%d)" ,
914+ qname , smm .ID , idstr (t1 ), uid , qtyp , hasdnssec , xdns .Len (ansin ), xdns .Len (ans64 ))
909915 withDNS64Summary (ans64 , smm )
910916 // todo: for uidself, skip dns64? see: ipmapper.go:undoAlgAndOrNat64
911917 // todo: skip for for undelegated domains like ipv4only.arpa?
912918 ansin = ans64
919+ // false if ans64 is synthesized or nil
920+ // or its value matches hasauth
921+ hasauth64 = xdns .IsDNSSECAnswerAuthenticated (ans64 )
913922 } // else: no dns64, or error; continue with ansin
914923
924+ smm .AD = hasauth && hasauth64 // true if both ansin and ans64 are authenticated
925+
915926 hasq := xdns .HasAAAAQuestion (ansin ) || xdns .HasAQuestion (ansin ) ||
916927 xdns .HasSVCBQuestion (ansin ) || xdns .HasHTTPQuestion (ansin )
917928 hasans := xdns .HasAnyAnswer (ansin )
@@ -927,8 +938,8 @@ func (t *dnsgateway) q(t1, t2 Transport, preset []netip.Addr, network, uid strin
927938
928939 // todo: skip alg for undelegated domains like ipv4only.arpa?
929940 if ! hasq || ! hasans || ! rgood || ans0000 || dontalg {
930- log .D ("alg: skip; query %s<>%s[%s]:%s:%d / a:%d, self(%t) dontalg(%t) hasq(%t) hasans(%t) rgood(%t), ans0000(%t)" ,
931- smm .ID , idstr (t1 ), uid , qname , qtyp , xdns .Len (ansin ), uidself , dontalg , hasq , hasans , rgood , ans0000 )
941+ log .D ("alg: skip; query %s<>%s[%s]:%s:%d / a:%d, dnssec(do? %t /ad? %t) self(%t) dontalg(%t) hasq(%t) hasans(%t) rgood(%t), ans0000(%t)" ,
942+ smm .ID , idstr (t1 ), uid , qname , qtyp , xdns .Len (ansin ), smm . DO , smm . AD , uidself , dontalg , hasq , hasans , rgood , ans0000 )
932943 return ansin , nil
933944 }
934945
@@ -1044,8 +1055,8 @@ func (t *dnsgateway) q(t1, t2 Transport, preset []netip.Addr, network, uid strin
10441055 mustsubst = true
10451056 }
10461057
1047- log .D ("alg: %s<>%s[%s]; %s:%d a6(a %d / h %d / s %t) : a4(a %d / h %d / s %t); ttl: %s" ,
1048- smm .ID , idstr (t1 ), uid , qname , qtyp , len (a6 ), len (ip6hints ), substok6 , len (a4 ), len (ip4hints ), substok4 , ansttl )
1058+ log .D ("alg: %s<>%s[%s]; %s:%d (do? %t / ad? %t) a6(a %d / h %d / s %t) : a4(a %d / h %d / s %t); ttl: %s" ,
1059+ smm .ID , idstr (t1 ), uid , qname , qtyp , smm . DO , smm . AD , len (a6 ), len (ip6hints ), substok6 , len (a4 ), len (ip4hints ), substok4 , ansttl )
10491060 if ! substok4 && ! substok6 {
10501061 if mustsubst {
10511062 err = errAlgCannotSubst
@@ -1084,13 +1095,13 @@ func (t *dnsgateway) q(t1, t2 Transport, preset []netip.Addr, network, uid strin
10841095 // the answer, whose ID != to t1 (cacher) itself. OTOH, dnsx.Resolver
10851096 // uses DNSSummary.ID when returning ans to the caller (ex: ipmapper)
10861097 tidToReg := smm .ID
1087- log .D ("alg: ok; for %s<>%s[%s]:%s:%d, domains %s real: %s / fix: %s => subst %s | %s; (mod? %t / fix? %t / synth? %t); sec %s; ttl %s" ,
1088- tidToReg , idstr (t1 ), uid , qname , qtyp , targets , realip , fixedips , algip4 , algip6 , mod , usefixed , synthAns , secres .ips , ansttl )
1098+ log .D ("alg: ok; for %s<>%s[%s]:%s:%d (do? %t / ad? %t) , domains %s real: %s / fix: %s => subst %s | %s; (mod? %t / fix? %t / synth? %t); sec %s; ttl %s" ,
1099+ tidToReg , idstr (t1 ), uid , qname , qtyp , smm . DO , smm . AD , targets , realip , fixedips , algip4 , algip6 , mod , usefixed , synthAns , secres .ips , ansttl )
10891100
10901101 if t .registerLocked (qname , tidToReg , uid , algip4 , algip6 , realip , ansttl , targets , secres ) {
10911102 // if mod is set, send modified answer
10921103 if mod {
1093- withAlgSummaryIfNeeded (smm , algip4 , algip6 )
1104+ withAlgSummary (smm , algip4 , algip6 )
10941105 return ansmod , nil
10951106 } else {
10961107 return ansin , nil
@@ -1130,7 +1141,7 @@ func withDNS64Summary(ans64 *dns.Msg, s *x.DNSSummary) {
11301141 }
11311142}
11321143
1133- func withAlgSummaryIfNeeded (s * x.DNSSummary , algips ... netip.Addr ) {
1144+ func withAlgSummary (s * x.DNSSummary , algips ... netip.Addr ) {
11341145 if settings .Debug {
11351146 // convert algips to ipcsv; any algips may be invalid
11361147 ipcsv := Netip2Csv (algips )
@@ -1147,6 +1158,8 @@ func withAlgSummaryIfNeeded(s *x.DNSSummary, algips ...netip.Addr) {
11471158 s .Server = prefix + notransport
11481159 }
11491160 }
1161+ // if modified alg ips are being returned, then these are not authentic
1162+ s .AD = len (algips ) > 0
11501163}
11511164
11521165func (t * dnsgateway ) registerLocked (q , tid , uid string , algip4 , algip6 netip.Addr , realips []netip.Addr , ttl time.Duration , targets []string , secres secans ) bool {
0 commit comments