@@ -9,7 +9,31 @@ import (
9
9
"github.com/miekg/dns"
10
10
)
11
11
12
+ var whitelistedDomains = []string {
13
+ "github.com" ,
14
+ "nginx.com" ,
15
+ }
16
+
17
+ // Function to check if the domain is whitelisted
18
+ func isWhitelistedDomain (domain string ) bool {
19
+ for _ , whitelisted := range whitelistedDomains {
20
+ if strings .HasSuffix (domain , whitelisted ) {
21
+ return true
22
+ }
23
+ }
24
+ return false
25
+ }
26
+
27
+ // Function to forward DNS query to external DNS server
12
28
func forwardToExternalDNS (q dns.Question ) ([]dns.RR , error ) {
29
+ // Extract the domain name from the question
30
+ domain := strings .TrimSuffix (q .Name , "." )
31
+
32
+ // Check if the domain is whitelisted
33
+ if ! isWhitelistedDomain (domain ) {
34
+ return nil , fmt .Errorf ("domain %s is not whitelisted" , domain )
35
+ }
36
+
13
37
// Query the external DNS server (e.g., 1.1.1.1)
14
38
client := new (dns.Client )
15
39
message := new (dns.Msg )
@@ -23,6 +47,7 @@ func forwardToExternalDNS(q dns.Question) ([]dns.RR, error) {
23
47
return resp .Answer , nil
24
48
}
25
49
50
+
26
51
func parseQuery (m * dns.Msg , qdns * QuickDNSResolver ) {
27
52
for _ , q := range m .Question {
28
53
println ("Query: " , q .Name , q .Qtype , q .Qclass )
0 commit comments