-
-
Notifications
You must be signed in to change notification settings - Fork 199
/
fqdn_only_resolver.go
43 lines (34 loc) · 915 Bytes
/
fqdn_only_resolver.go
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
package resolver
import (
"strings"
"github.com/0xERR0R/blocky/config"
"github.com/0xERR0R/blocky/model"
"github.com/0xERR0R/blocky/util"
"github.com/miekg/dns"
)
type FqdnOnlyResolver struct {
NextResolver
enabled bool
}
func NewFqdnOnlyResolver(cfg config.Config) ChainedResolver {
return &FqdnOnlyResolver{
enabled: cfg.FqdnOnly,
}
}
func (r *FqdnOnlyResolver) Resolve(request *model.Request) (*model.Response, error) {
if r.enabled {
domainFromQuestion := util.ExtractDomain(request.Req.Question[0])
if !strings.Contains(domainFromQuestion, ".") {
response := new(dns.Msg)
response.Rcode = dns.RcodeNameError
return &model.Response{Res: response, RType: model.ResponseTypeNOTFQDN, Reason: "NOTFQDN"}, nil
}
}
return r.next.Resolve(request)
}
func (r *FqdnOnlyResolver) Configuration() (result []string) {
if !r.enabled {
return configDisabled
}
return configEnabled
}