-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.go
50 lines (39 loc) · 968 Bytes
/
setup.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
46
47
48
49
50
package nsip
import (
"github.com/coredns/caddy"
"github.com/coredns/coredns/core/dnsserver"
"github.com/coredns/coredns/plugin"
"github.com/coredns/coredns/plugin/pkg/log"
"strings"
)
const pluginName = "nsip"
func init() { plugin.Register(pluginName, setup) }
func setup(c *caddy.Controller) error {
a, err := parse(c)
if err != nil {
log.Error(err)
return plugin.Error(pluginName, err)
}
dnsserver.GetConfig(c).AddPlugin(func(next plugin.Handler) plugin.Handler {
a.Next = next
return a
})
return nil
}
func parse(c *caddy.Controller) (Record, error) {
a := Record{}
for c.Next() {
r := rule{}
args := c.RemainingArgs()
r.zones = plugin.OriginsFromArgsOrServerBlock(args, c.ServerBlockKeys)
for c.NextBlock() {
p := policy{}
p.ns = strings.ToLower(c.Val())
remainingTokens := c.RemainingArgs()
p.ip = remainingTokens[0]
r.policies = append(r.policies, p)
}
a.Rules = append(a.Rules, r)
}
return a, nil
}