Repository navigation
Expand file tree
/
Copy pathprocess_query.go
More file actions
118 lines (102 loc) · 4.15 KB
/
Copy pathprocess_query.go
File metadata and controls
118 lines (102 loc) · 4.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/*
File: process_query.go
Version: 1.5.0
Last Updated: 04-Nov-2026 17:20 CET
Description:
Per-query execution context for the sdproxy resolution pipeline.
Changes:
1.5.0 - [FEAT] Added `protoEndpoint` and `effectivePolicyLabel` helpers to
`queryCtx` for Simple Logging Mode.
1.4.0 - [FEAT] Added `ednsMAC` to `queryCtx` so post-cache and post-upstream
policy and filter stages can pass the incoming EDNS0 Option 65001 MAC
to `CheckParental` when `device` budget tracking is used on `mac:` routes.
1.3.0 - [FIX] Added `ecsAddr` and `ecsPrefix` to `queryCtx` so post-cache and
post-upstream policy and filter stages can pass the incoming EDNS0
Client Subnet to `CheckParental` when `device` budget tracking is used
on `ecs:` routes.
1.2.0 - [FIX] Added `localPort` to `queryCtx` so downstream policy and filter
stages can pass it to `CheckParental` when `device` budget tracking
is used on port-based parental routes.
1.1.0 - [FIX] `group` is now populated at stage 4 (cache-key derivation)
rather than stage 7, and its field documentation says so.
- [CLEANUP] Deleted itoaU16 in favour of the identical itoa64
(stats_lastseen.go).
1.0.0 - [REFACTOR] Extracted from process.go 3.90.0 as part of splitting a
1.031-line file.
*/
package main
import (
"net/netip"
"github.com/miekg/dns"
)
type queryCtx struct {
// ── Transport (populated at entry) ────────────────────────────────────
w dns.ResponseWriter
r *dns.Msg
q dns.Question
// ── Question (populated at entry) ─────────────────────────────────────
qNameTrimmed string
originalQName string
originalQNameTrimmed string
originalID uint16
doBit bool
// ── Client identity (populated at entry) ──────────────────────────────
clientIP string
clientAddr netip.Addr
ecsAddr netip.Addr
ecsPrefix netip.Prefix
clientMAC string
ednsMAC string
clientName string
clientID string
clientNameLower string
// ── Transport metadata (populated at entry) ───────────────────────────
protocol string
protoEndpoint string
sni string
sniLower string
path string
pathLower string
localPort string
// ── Populated by stage 1.5: identity resolution ───────────────────────
sk string
clientGroup string
// ── Populated by stages 1.6-1.8: overrides ────────────────────────────
bypassGlobal bool
bypassPolicies bool
spoofedAlias string
// ── Populated by stage 2: routing ─────────────────────────────────────
route routingContext
// ── Populated by stage 3: parental controls ───────────────────────────
parentalForcedTTL uint32
parentalReason string
parentalCategory string
parentalMatchedApex string
// ── Populated by stage 4: cache key derivation ────────────────────────
cacheKey DNSCacheKey
group *UpstreamGroup
}
func (qc *queryCtx) qtypeStr() string {
return qtypeName(qc.q.Qtype)
}
func (qc *queryCtx) effectivePolicyLabel() string {
if qc.spoofedAlias != "" {
return "RRs (" + qc.spoofedAlias + ")"
}
if qc.bypassPolicies {
return "Custom Rule ALLOW"
}
if qc.parentalCategory != "" {
return "Parental (" + qc.parentalCategory + ")"
}
if qc.clientGroup != "" && qc.clientGroup != "default" {
return "Group (" + qc.clientGroup + ")"
}
if qc.route.routeName != "" {
if qc.route.routeOriginType != "" && qc.route.routeOriginType != "DEFAULT" {
return qc.route.routeName + " (" + qc.route.routeOriginType + ")"
}
return qc.route.routeName
}
return "default"
}