mirror of
https://github.com/coredns/coredns.git
synced 2025-12-09 03:45:11 -05:00
Add secondary support
Allow specifying a primary server and retrieve the zone's content. Add tests and an Expired bool to zone struct, to stop server zones that are expired. The zone is retrieved on Startup, no updates of changed content are done. We also don't respond to notifies yet.
This commit is contained in:
59
core/setup/secondary.go
Normal file
59
core/setup/secondary.go
Normal file
@@ -0,0 +1,59 @@
|
||||
package setup
|
||||
|
||||
import (
|
||||
"github.com/miekg/coredns/middleware"
|
||||
"github.com/miekg/coredns/middleware/file"
|
||||
"github.com/miekg/coredns/middleware/secondary"
|
||||
)
|
||||
|
||||
// Secondary sets up the secondary middleware.
|
||||
func Secondary(c *Controller) (middleware.Middleware, error) {
|
||||
zones, err := secondaryParse(c)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Setup retrieve the zone.
|
||||
for _, n := range zones.Names {
|
||||
if len(zones.Z[n].TransferFrom) > 0 {
|
||||
c.Startup = append(c.Startup, func() error {
|
||||
err := zones.Z[n].TransferIn()
|
||||
return err
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
return func(next middleware.Handler) middleware.Handler {
|
||||
return secondary.Secondary{file.File{Next: next, Zones: zones}}
|
||||
}, nil
|
||||
|
||||
}
|
||||
|
||||
func secondaryParse(c *Controller) (file.Zones, error) {
|
||||
z := make(map[string]*file.Zone)
|
||||
names := []string{}
|
||||
for c.Next() {
|
||||
if c.Val() == "secondary" {
|
||||
// secondary [origin]
|
||||
origin := c.ServerBlockHosts[c.ServerBlockHostIndex]
|
||||
if c.NextArg() {
|
||||
origin = c.Val()
|
||||
}
|
||||
// TODO(miek): we should allow more. Issue #54.
|
||||
origin = middleware.Host(origin).Normalize()
|
||||
|
||||
z[origin] = file.NewZone(origin)
|
||||
names = append(names, origin)
|
||||
|
||||
for c.NextBlock() {
|
||||
t, f, e := parseTransfer(c)
|
||||
if e != nil {
|
||||
return file.Zones{}, e
|
||||
}
|
||||
z[origin].TransferTo = append(z[origin].TransferTo, t)
|
||||
z[origin].TransferFrom = append(z[origin].TransferFrom, f)
|
||||
}
|
||||
}
|
||||
}
|
||||
return file.Zones{Z: z, Names: names}, nil
|
||||
}
|
||||
Reference in New Issue
Block a user