Skip to content

Commit 88f158e

Browse files
committed
dnsx: Start time in summary
1 parent 8ad9faf commit 88f158e

4 files changed

Lines changed: 30 additions & 23 deletions

File tree

intra/backend/dnsx_listener.go

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,17 @@ type DNSSummary struct {
1919
// Flow ID that spawned this DNS query, if Origin is "tunnel".
2020
// Otherwise, it is randomly generated uint64 as hex.
2121
FID string
22-
// DNS Transport ID
22+
// DNS Transport ID.
2323
ID string
2424
// owner uid that sent this request. May be empty.
2525
UID string
26-
// tunnel or internal originated query
26+
// tunnel or internal originated query.
2727
Origin string
28-
// Response (or failure) latency in seconds
28+
// Time this query was received (unix millis).
29+
Start int64
30+
// Response (or failure) latency in seconds.
2931
Latency float64
30-
// Queried domain name
32+
// Queried domain name.
3133
QName string
3234
// Query type: A, AAAA, SVCB, HTTPS, etc. May be 0.
3335
QType int
@@ -37,21 +39,21 @@ type DNSSummary struct {
3739
Cached bool
3840
// DNS Response data, ex: a csv of ips for A, AAAA.
3941
RData string
40-
// DNS Response code
42+
// DNS Response code.
4143
RCode int
42-
// DNS Response TTL
44+
// DNS Response TTL.
4345
RTtl int
44-
// DNS Server (ip, ip:port, host, host:port)
46+
// DNS Server (ip, ip:port, host, host:port).
4547
Server string
46-
// Proxy or a relay server address
48+
// Proxy or a relay server address.
4749
PID string
48-
// Relay server PID hops over, if any
50+
// Relay server PID hops over, if any.
4951
RPID string
50-
// Transport status (Start, Complete, SendFailed, NoResponse, BadQuery, BadResponse, etc)
52+
// Transport status (Start, Complete, SendFailed, NoResponse, BadQuery, BadResponse, etc).
5153
Status int
5254
// CSV of Rethink DNS+ blocklists (local or remote) names (if used).
5355
Blocklists string
54-
// Actual target (domain name) that was blocked (could be a CNAME or HTTPS/SVCB alias) by Blocklists
56+
// Actual target (domain name) that was blocked (could be a CNAME or HTTPS/SVCB alias) by Blocklists.
5557
BlockedTarget string
5658
// True if any among upstream transports (primary or secondary) returned blocked ans.
5759
// Only valid for A/AAAA queries. Unspecified IPs are considered as "blocked ans".
@@ -62,11 +64,11 @@ type DNSSummary struct {
6264
AD bool
6365
// True if TLS Encrypted Client Hello was used by this transport, if applicable.
6466
ECH bool
65-
// Diag message from Transport, if any. Typically, "no error"
67+
// Diag message from Transport, if any. Typically, "no error".
6668
Msg string
6769
// Diag extras, if any. For example, list of proxy & transport overrides.
6870
Extra string
69-
// Region of the Rethink DNS+ server (if used)
71+
// Region of the Rethink DNS+ server (if used).
7072
Region string
7173
}
7274

intra/dnscrypt/servers_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"net"
1414
"net/netip"
1515
"testing"
16+
"time"
1617

1718
x "github.com/celzero/firestack/intra/backend"
1819
"github.com/celzero/firestack/intra/dialers"
@@ -132,7 +133,7 @@ func TestOne(t *testing.T) {
132133
t.Fatal(errors.Join(dnsx.ErrAddFailed, err))
133134
}
134135
q := aquery("google.com")
135-
smm := &x.DNSSummary{}
136+
smm := &x.DNSSummary{Start: time.Now().UnixMilli()}
136137
netw := xdns.NetAndProxyID("udp", ipn.Base)
137138
// FIXME: querying always fails with EOF
138139
ans, err := tr.Query(netw, q, smm)

intra/dnsx/cacher.go

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -572,22 +572,23 @@ func fillSummary(s *x.DNSSummary, out *x.DNSSummary) {
572572
if len(out.Origin) <= 0 {
573573
out.Origin = s.Origin
574574
}
575+
575576
if len(out.ID) <= 0 {
576577
out.ID = s.ID
577578
out.Server = s.Server
578-
out.PID = s.PID
579-
out.RPID = s.RPID
580579
} else if len(out.Server) <= 0 {
581580
out.Server = s.Server
582-
out.PID = s.PID
583-
out.RPID = s.RPID
584-
} else if len(out.PID) <= 0 {
585-
out.PID = s.PID
586-
out.RPID = s.RPID
587581
}
582+
588583
if len(out.FID) <= 0 {
589584
out.FID = s.FID
590585
}
586+
if len(out.Origin) <= 0 {
587+
out.Origin = s.Origin
588+
}
589+
if out.Start <= 0 {
590+
out.Start = s.Start
591+
}
591592
if out.Latency <= 0 {
592593
out.Latency = s.Latency
593594
}
@@ -613,7 +614,10 @@ func fillSummary(s *x.DNSSummary, out *x.DNSSummary) {
613614
out.DO = s.DO
614615
}
615616

616-
out.Origin = s.Origin
617+
if len(s.PID) > 0 {
618+
out.PID = s.PID
619+
out.RPID = s.RPID
620+
}
617621
out.ECH = s.ECH
618622
out.Cached = s.Cached
619623
out.RCode = s.RCode
@@ -624,7 +628,6 @@ func fillSummary(s *x.DNSSummary, out *x.DNSSummary) {
624628
out.Msg = s.Msg
625629
out.UpstreamBlocks = s.UpstreamBlocks
626630
out.Extra = s.Extra
627-
out.Region = s.Region
628631
}
629632

630633
func rand33pc() bool {

intra/dnsx/transport.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,7 @@ func (r *resolver) forward(q []byte, who, fid, uid string, chosenids ...string)
542542
ID: NoDNS,
543543
FID: fid,
544544
Origin: who,
545+
Start: starttime.UnixMilli(),
545546
UID: uid, // may be overwritten to by Cacher via fillSummary
546547
QName: invalidQname,
547548
Status: Start,

0 commit comments

Comments
 (0)