Allow overlapping Zones if binding addresses are different (#1530)

* add OverlapChecker, move the test of overlap AFTER the directive setup process, change key of configs to allow multiple same key

* glitch when rebase. init of Config should include the default host

* add tests for the registering of configuration
rename multicast in 'unbound'.
add comments on the validator

* - merged zoneAddr and addrKey that are very similar
- move maps of Validator to zoneAddr, avoinding need to have string representation of zoneaddr
- moving key build for saving Config at Config side instead of dnsContext

* - UT on saving config is now useless.

* - cannot cleanup access to Configs after setup. Deferred function to Start, use it

* - cleanup register unit tests. remove useless function

* - address comments of review. name of validator, comments, simplify registerAndCheck

* - fixes after review. renaming a function and a comment
This commit is contained in:
Francois Tur
2018-02-23 11:54:42 -05:00
committed by Miek Gieben
parent 455040c143
commit 9047bdf3a0
6 changed files with 164 additions and 19 deletions

View File

@@ -2,6 +2,7 @@ package dnsserver
import (
"crypto/tls"
"fmt"
"net"
"github.com/coredns/coredns/plugin"
@@ -68,16 +69,22 @@ func (c *Config) HostAddresses() string {
return all
}
// keyForConfig build a key for identifying the configs during setup time
func keyForConfig(blocIndex int, blocKeyIndex int) string {
return fmt.Sprintf("%d:%d", blocIndex, blocKeyIndex)
}
// GetConfig gets the Config that corresponds to c.
// If none exist nil is returned.
func GetConfig(c *caddy.Controller) *Config {
ctx := c.Context().(*dnsContext)
if cfg, ok := ctx.keysToConfigs[c.Key]; ok {
key := keyForConfig(c.ServerBlockIndex, c.ServerBlockKeyIndex)
if cfg, ok := ctx.keysToConfigs[key]; ok {
return cfg
}
// we should only get here during tests because directive
// actions typically skip the server blocks where we make
// the configs.
ctx.saveConfig(c.Key, &Config{ListenHosts: []string{""}})
ctx.saveConfig(key, &Config{ListenHosts: []string{""}})
return GetConfig(c)
}