-
Notifications
You must be signed in to change notification settings - Fork 0
/
acl.go
36 lines (29 loc) 路 817 Bytes
/
acl.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
package acl
import (
"context"
"github.com/miekg/dns"
"github.com/rs/zerolog/log"
"github.com/ferama/pigdns/pkg/handlers/collector"
"github.com/ferama/pigdns/pkg/pigdns"
"github.com/ferama/pigdns/pkg/utils"
)
const handlerName = "acl"
type Handler struct {
Next pigdns.Handler
AllowedNets []string
}
func (h *Handler) ServeDNS(c context.Context, r *pigdns.Request) {
allowed, err := utils.IsClientAllowed(r.ResponseWriter.RemoteAddr(), h.AllowedNets)
if err != nil {
log.Fatal().Err(err)
}
if !allowed {
log.Printf("[acl handler] client '%s' is not allowed", r.ResponseWriter.RemoteAddr())
cc := c.Value(collector.CollectorContextKey).(*collector.CollectorContext)
cc.AnweredBy = handlerName
m := new(dns.Msg)
r.ReplyWithStatus(m, dns.RcodeRefused)
return
}
h.Next.ServeDNS(c, r)
}