-
Notifications
You must be signed in to change notification settings - Fork 0
/
plugin.go
45 lines (36 loc) · 1.01 KB
/
plugin.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
44
45
package allowlist
import (
"context"
"fmt"
corednsplugin "github.com/coredns/coredns/plugin"
"github.com/coredns/coredns/request"
"github.com/miekg/dns"
)
// Add here the domains that you want to be allowed.
var allowlist = map[string]struct{}{
"slok.dev.": {},
"xabi.dev.": {},
"cloudwarlocks.com.": {},
}
type plugin struct {
next corednsplugin.Handler
}
func NewPlugin(next corednsplugin.Handler, rawOpts string) corednsplugin.Handler {
return plugin{next: next}
}
func (p plugin) Name() string { return "allowlist" }
func (p plugin) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (int, error) {
state := request.Request{W: w, Req: r}
_, ok := allowlist[state.Name()]
if !ok {
resp := new(dns.Msg)
resp.SetRcode(r, dns.RcodeNameError)
err := w.WriteMsg(resp)
if err != nil {
fmt.Println(err)
return corednsplugin.NextOrFailure(p.Name(), p.next, ctx, w, r)
}
return dns.RcodeNameError, nil
}
return corednsplugin.NextOrFailure(p.Name(), p.next, ctx, w, r)
}