aboutsummaryrefslogtreecommitdiff
path: root/core/dnsserver
diff options
context:
space:
mode:
Diffstat (limited to 'core/dnsserver')
-rw-r--r--core/dnsserver/config.go4
-rw-r--r--core/dnsserver/register.go22
2 files changed, 26 insertions, 0 deletions
diff --git a/core/dnsserver/config.go b/core/dnsserver/config.go
index d0a432a85..e5200d67c 100644
--- a/core/dnsserver/config.go
+++ b/core/dnsserver/config.go
@@ -50,6 +50,10 @@ type Config struct {
// on them should register themselves here. The name should be the name as return by the
// Handler's Name method.
registry map[string]plugin.Handler
+
+ // firstConfigInBlock is used to reference the first config in a server block, for the
+ // purpose of sharing single instance of each plugin among all zones in a server block.
+ firstConfigInBlock *Config
}
// keyForConfig builds a key for identifying the configs during setup time
diff --git a/core/dnsserver/register.go b/core/dnsserver/register.go
index 15772a248..ec254085e 100644
--- a/core/dnsserver/register.go
+++ b/core/dnsserver/register.go
@@ -108,6 +108,8 @@ func (h *dnsContext) InspectServerBlocks(sourceFile string, serverBlocks []caddy
serverBlocks[ib].Keys = s.Keys // important to save back the new keys that are potentially created here.
+ var firstConfigInBlock *Config
+
for ik := range s.Keys {
za := zoneAddrs[ik]
s.Keys[ik] = za.String()
@@ -118,6 +120,15 @@ func (h *dnsContext) InspectServerBlocks(sourceFile string, serverBlocks []caddy
Port: za.Port,
Transport: za.Transport,
}
+
+ // Set reference to the first config in the current block.
+ // This is used later by MakeServers to share a single plugin list
+ // for all zones in a server block.
+ if ik == 0 {
+ firstConfigInBlock = cfg
+ }
+ cfg.firstConfigInBlock = firstConfigInBlock
+
keyConfig := keyForConfig(ib, ik)
h.saveConfig(keyConfig, cfg)
}
@@ -135,6 +146,17 @@ func (h *dnsContext) MakeServers() ([]caddy.Server, error) {
return nil, errValid
}
+ // Copy the Plugin, ListenHosts and Debug from first config in the block
+ // to all other config in the same block . Doing this results in zones
+ // sharing the same plugin instances and settings as other zones in
+ // the same block.
+ for _, c := range h.configs {
+ c.Plugin = c.firstConfigInBlock.Plugin
+ c.ListenHosts = c.firstConfigInBlock.ListenHosts
+ c.Debug = c.firstConfigInBlock.Debug
+ c.TLSConfig = c.firstConfigInBlock.TLSConfig
+ }
+
// we must map (group) each config to a bind address
groups, err := groupConfigsByListenAddr(h.configs)
if err != nil {