project init
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
package synthetic
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/coredns/caddy"
|
||||
"github.com/coredns/coredns/core/dnsserver"
|
||||
"github.com/coredns/coredns/plugin"
|
||||
"net"
|
||||
)
|
||||
|
||||
// syntheticConfig holds the configuration options for the synthetic plugin.
|
||||
type syntheticConfig struct {
|
||||
net []*net.IPNet
|
||||
forward string
|
||||
}
|
||||
|
||||
// init registers this plugin.
|
||||
func init() { plugin.Register("synthetic", setup) }
|
||||
|
||||
// setup is the function that gets called when the config parser see the token "synthetic".
|
||||
func setup(c *caddy.Controller) error {
|
||||
var config syntheticConfig
|
||||
|
||||
// Parse the configuration file
|
||||
for c.Next() {
|
||||
for c.NextBlock() {
|
||||
switch v := c.Val(); v {
|
||||
|
||||
// Configuration for forward lookup zones for which to do resolution
|
||||
case "net":
|
||||
args := c.RemainingArgs()
|
||||
for _, arg := range args {
|
||||
_, cidr, err := net.ParseCIDR(arg)
|
||||
if err == nil {
|
||||
config.net = append(config.net, cidr)
|
||||
} else {
|
||||
return fmt.Errorf("synthetic: invalid reverse lookup cidr: %v", arg)
|
||||
}
|
||||
}
|
||||
|
||||
// Configuration for reverse lookup zones for the forward lookup zone name
|
||||
case "forward":
|
||||
args := c.RemainingArgs()
|
||||
for _, arg := range args {
|
||||
config.forward = arg
|
||||
}
|
||||
|
||||
default:
|
||||
return c.Errf("unknown property '%s'", v)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dnsserver.GetConfig(c).AddPlugin(func(next plugin.Handler) plugin.Handler {
|
||||
return synthetic{Next: next, Config: config}
|
||||
})
|
||||
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user