feat(dns): expose more low-level fields (#873)
This pull request started as a draft to enable users to see CNAME answers. It contained several patches which we merged separately (see https://github.com/ooni/probe-cli/pull/873#issuecomment-1222406732 and https://github.com/ooni/probe-cli/compare/2301a30630577637e5ec9912b027584e5ab4eebc...60b7d1f87be4b088929048edfb950dc93146a01f for details on what has actually changed, which is based on patches originally part of this PR). In its final form, however, this PR only deals with exposing more low-level DNS fields to the archival data format. Closes: https://github.com/ooni/probe/issues/2228 Related PR spec: https://github.com/ooni/spec/pull/256
This commit is contained in:
@@ -117,14 +117,35 @@ func NewArchivalDNSLookupResultFromRoundTrip(index int64, started time.Duration,
|
||||
Answers: newArchivalDNSAnswers(addrs, response),
|
||||
Engine: reso.Network(),
|
||||
Failure: tracex.NewFailure(err),
|
||||
GetaddrinfoError: netxlite.ErrorToGetaddrinfoRetvalOrZero(err),
|
||||
Hostname: query.Domain(),
|
||||
QueryType: dns.TypeToString[query.Type()],
|
||||
RawResponse: maybeRawResponse(response),
|
||||
Rcode: maybeResponseRcode(response),
|
||||
ResolverHostname: nil,
|
||||
ResolverPort: nil,
|
||||
ResolverAddress: reso.Address(),
|
||||
T0: started.Seconds(),
|
||||
T: finished.Seconds(),
|
||||
}
|
||||
}
|
||||
|
||||
// maybeResponseRcode returns the response rcode (when available)
|
||||
func maybeResponseRcode(resp model.DNSResponse) (out int64) {
|
||||
if resp != nil {
|
||||
out = int64(resp.Rcode())
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// maybeRawResponse returns either the raw response (when available) or nil.
|
||||
func maybeRawResponse(resp model.DNSResponse) (out []byte) {
|
||||
if resp != nil {
|
||||
out = resp.Bytes()
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// newArchivalDNSAnswers generates []model.ArchivalDNSAnswer from [addrs] and [resp].
|
||||
func newArchivalDNSAnswers(addrs []string, resp model.DNSResponse) (out []model.ArchivalDNSAnswer) {
|
||||
// Design note: in principle we might want to extract everything from the
|
||||
|
||||
@@ -138,6 +138,12 @@ func TestNewResolver(t *testing.T) {
|
||||
MockDecodeCNAME: func() (string, error) {
|
||||
return "dns.google.", nil
|
||||
},
|
||||
MockRcode: func() int {
|
||||
return 0
|
||||
},
|
||||
MockBytes: func() []byte {
|
||||
return []byte{}
|
||||
},
|
||||
}
|
||||
return response, nil
|
||||
},
|
||||
@@ -214,6 +220,12 @@ func TestNewResolver(t *testing.T) {
|
||||
MockDecodeCNAME: func() (string, error) {
|
||||
return "dns.google.", nil
|
||||
},
|
||||
MockRcode: func() int {
|
||||
return 0
|
||||
},
|
||||
MockBytes: func() []byte {
|
||||
return []byte{}
|
||||
},
|
||||
}
|
||||
return response, nil
|
||||
},
|
||||
@@ -363,6 +375,12 @@ func TestDelayedDNSResponseWithTimeout(t *testing.T) {
|
||||
MockDecodeCNAME: func() (string, error) {
|
||||
return "", netxlite.ErrOODNSNoAnswer
|
||||
},
|
||||
MockRcode: func() int {
|
||||
return 0
|
||||
},
|
||||
MockBytes: func() []byte {
|
||||
return []byte{}
|
||||
},
|
||||
}
|
||||
err := trace.OnDelayedDNSResponse(started, txp, query, dnsResponse, addrs, nil, finished)
|
||||
// 2. read the trace
|
||||
@@ -405,6 +423,12 @@ func TestDelayedDNSResponseWithTimeout(t *testing.T) {
|
||||
MockDecodeCNAME: func() (string, error) {
|
||||
return "", netxlite.ErrOODNSNoAnswer
|
||||
},
|
||||
MockRcode: func() int {
|
||||
return 0
|
||||
},
|
||||
MockBytes: func() []byte {
|
||||
return []byte{}
|
||||
},
|
||||
}
|
||||
err := trace.OnDelayedDNSResponse(started, txp, query, dnsResponse, addrs, nil, finished)
|
||||
if !errors.Is(err, ErrDelayedDNSResponseBufferFull) {
|
||||
@@ -448,6 +472,12 @@ func TestDelayedDNSResponseWithTimeout(t *testing.T) {
|
||||
MockDecodeCNAME: func() (string, error) {
|
||||
return "", netxlite.ErrOODNSNoAnswer
|
||||
},
|
||||
MockRcode: func() int {
|
||||
return 0
|
||||
},
|
||||
MockBytes: func() []byte {
|
||||
return []byte{}
|
||||
},
|
||||
}
|
||||
for i := 0; i < events; i++ {
|
||||
// fill the trace
|
||||
@@ -491,6 +521,12 @@ func TestDelayedDNSResponseWithTimeout(t *testing.T) {
|
||||
MockDecodeCNAME: func() (string, error) {
|
||||
return "", netxlite.ErrOODNSNoAnswer
|
||||
},
|
||||
MockRcode: func() int {
|
||||
return 0
|
||||
},
|
||||
MockBytes: func() []byte {
|
||||
return []byte{}
|
||||
},
|
||||
}
|
||||
trace.delayedDNSResponse <- NewArchivalDNSLookupResultFromRoundTrip(trace.Index, started.Sub(trace.ZeroTime),
|
||||
txp, query, dnsResponse, addrs, nil, finished.Sub(trace.ZeroTime))
|
||||
|
||||
Reference in New Issue
Block a user