diff --git a/setup.go b/setup.go index 7025026..3ef0d3d 100644 --- a/setup.go +++ b/setup.go @@ -6,8 +6,11 @@ import ( "github.com/coredns/caddy" "github.com/coredns/coredns/core/dnsserver" "github.com/coredns/coredns/plugin" + clog "github.com/coredns/coredns/plugin/pkg/log" ) +var log = clog.NewWithPlugin("overide") + func init() { plugin.Register("override", setup) } @@ -31,10 +34,25 @@ func setup(c *caddy.Controller) error { func parseRules(c *caddy.Controller) ([]Rule, error) { var rules []Rule - rules = append(rules, Rule{ - Search: net.ParseIP("45.9.63.244"), - Override: net.ParseIP("10.0.0.1"), - }) + for c.Next() { + for c.NextBlock() { + searchIP := net.ParseIP(c.Val()) + if searchIP == nil { + return nil, c.Errf("invalid search IP: %s", c.Val()) + } + + if !c.NextArg() { + return nil, c.ArgErr() + } + + overrideIP := net.ParseIP(c.Val()) + if overrideIP == nil { + return nil, c.Errf("invalid override IP: %s", c.Val()) + } + + rules = append(rules, Rule{Search: searchIP, Override: overrideIP}) + } + } return rules, nil }