-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdnsfilter.go
More file actions
36 lines (33 loc) · 1.04 KB
/
dnsfilter.go
File metadata and controls
36 lines (33 loc) · 1.04 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
package main
// filterAnswers filters DNS records according to RFC CNAME rules - need to still understand the RFC
// like why txxt and all records should also be like returned by the cname server
func filterAnswers(qType uint16, answers []rr) []rr {
var cnameAnswers []rr
for _, r := range answers {
if r.Type_ == 5 { // CNAME
cnameAnswers = append(cnameAnswers, r)
}
}
var filteredAnswers []rr
if qType == 255 { // ANY
filteredAnswers = answers
} else if qType == 5 { // CNAME query
for _, r := range answers {
if r.Type_ == 5 {
filteredAnswers = append(filteredAnswers, r)
}
}
} else if len(cnameAnswers) > 0 {
// for non-CNAME queries, if CNAME exists, return only CNAME
filteredAnswers = cnameAnswers
} else {
for _, r := range answers {
if r.Type_ == qType {
filteredAnswers = append(filteredAnswers, r)
}
}
}
return filteredAnswers
}
//this entire codebase is just patch upon patch cause i am figuring out dns specs and as i do and understand just adding a patch
// TODO: refactor this into proper functions