aboutsummaryrefslogtreecommitdiff
path: root/plugin/reverse/setup.go
diff options
context:
space:
mode:
authorGravatar Miek Gieben <miek@miek.nl> 2018-05-24 14:30:01 +0100
committerGravatar GitHub <noreply@github.com> 2018-05-24 14:30:01 +0100
commit2758a756dd32197fdc20e0094ea9a22227649da4 (patch)
tree519776ee52b7364a9029daf76ee8447b97518ae2 /plugin/reverse/setup.go
parentb0fd575c658c22d082e1ac776a15ad8d188e76f7 (diff)
downloadcoredns-2758a756dd32197fdc20e0094ea9a22227649da4.tar.gz
coredns-2758a756dd32197fdc20e0094ea9a22227649da4.tar.zst
coredns-2758a756dd32197fdc20e0094ea9a22227649da4.zip
Implement deprecation notice for 1.1.4 (#1833)
* Implement deprecation notice for 1.1.4 This still allows all the config to be parsed, but noops it: * -log; always set the log to stdout; no matter what. * https_google; removed from the proxy implementation. * reverse plugin: set to deprecated. * Whole of reverse can go * Remove test for deprecated plugin
Diffstat (limited to 'plugin/reverse/setup.go')
-rw-r--r--plugin/reverse/setup.go154
1 files changed, 0 insertions, 154 deletions
diff --git a/plugin/reverse/setup.go b/plugin/reverse/setup.go
deleted file mode 100644
index 1033a0de4..000000000
--- a/plugin/reverse/setup.go
+++ /dev/null
@@ -1,154 +0,0 @@
-package reverse
-
-import (
- "net"
- "regexp"
- "sort"
- "strconv"
- "strings"
-
- "github.com/coredns/coredns/core/dnsserver"
- "github.com/coredns/coredns/plugin"
- "github.com/coredns/coredns/plugin/pkg/fall"
- clog "github.com/coredns/coredns/plugin/pkg/log"
-
- "github.com/mholt/caddy"
-)
-
-var log = clog.NewWithPlugin("reverse")
-
-func init() {
- caddy.RegisterPlugin("reverse", caddy.Plugin{
- ServerType: "dns",
- Action: setup,
- })
-}
-
-func setup(c *caddy.Controller) error {
- networks, fall, err := reverseParse(c)
- if err != nil {
- return plugin.Error("reverse", err)
- }
-
- dnsserver.GetConfig(c).AddPlugin(func(next plugin.Handler) plugin.Handler {
- return Reverse{Next: next, Networks: networks, Fall: fall}
- })
-
- // TODO(miek): Deprecate after 1.1.3 (that would be 1.2.0)
- log.Warning("reverse will be deprecated in the next release")
-
- return nil
-}
-
-func reverseParse(c *caddy.Controller) (nets networks, f fall.F, err error) {
- zones := make([]string, len(c.ServerBlockKeys))
- wildcard := false
-
- // We copy from the serverblock, these contains Hosts.
- for i, str := range c.ServerBlockKeys {
- zones[i] = plugin.Host(str).Normalize()
- }
-
- for c.Next() {
- var cidrs []*net.IPNet
-
- // parse all networks
- for _, cidr := range c.RemainingArgs() {
- if cidr == "{" {
- break
- }
- _, ipnet, err := net.ParseCIDR(cidr)
- if err != nil {
- return nil, f, c.Errf("network needs to be CIDR formatted: %q\n", cidr)
- }
- cidrs = append(cidrs, ipnet)
- }
- if len(cidrs) == 0 {
- return nil, f, c.ArgErr()
- }
-
- // set defaults
- var (
- template = "ip-" + templateNameIP + ".{zone[1]}"
- ttl = 60
- )
- for c.NextBlock() {
- switch c.Val() {
- case "hostname":
- if !c.NextArg() {
- return nil, f, c.ArgErr()
- }
- template = c.Val()
-
- case "ttl":
- if !c.NextArg() {
- return nil, f, c.ArgErr()
- }
- ttl, err = strconv.Atoi(c.Val())
- if err != nil {
- return nil, f, err
- }
-
- case "wildcard":
- wildcard = true
-
- case "fallthrough":
- f.SetZonesFromArgs(c.RemainingArgs())
-
- default:
- return nil, f, c.ArgErr()
- }
- }
-
- // prepare template
- // replace {zone[index]} by the listen zone/domain of this config block
- for i, zone := range zones {
- // TODO: we should be smarter about actually replacing this. This works, but silently allows "zone[-1]"
- // for instance.
- template = strings.Replace(template, "{zone["+strconv.Itoa(i+1)+"]}", zone, 1)
- }
- if !strings.HasSuffix(template, ".") {
- template += "."
- }
-
- // extract zone from template
- templateZone := strings.SplitAfterN(template, ".", 2)
- if len(templateZone) != 2 || templateZone[1] == "" {
- return nil, f, c.Errf("cannot find domain in template '%v'", template)
- }
-
- // Create for each configured network in this stanza
- for _, ipnet := range cidrs {
- // precompile regex for hostname to ip matching
- regexIP := regexMatchV4
- if ipnet.IP.To4() == nil {
- regexIP = regexMatchV6
- }
- prefix := "^"
- if wildcard {
- prefix += ".*"
- }
- regex, err := regexp.Compile(
- prefix + strings.Replace( // inject ip regex into template
- regexp.QuoteMeta(template), // escape dots
- regexp.QuoteMeta(templateNameIP),
- regexIP,
- 1) + "$")
- if err != nil {
- return nil, f, err
- }
-
- nets = append(nets, network{
- IPnet: ipnet,
- Zone: templateZone[1],
- Template: template,
- RegexMatchIP: regex,
- TTL: uint32(ttl),
- })
- }
- }
-
- // sort by cidr
- sort.Sort(nets)
- return nets, f, nil
-}