mirror of
https://github.com/coredns/coredns.git
synced 2025-11-10 14:02:16 -05:00
plugin/view: Advanced routing interface and new 'view' plugin (#5538)
* introduce new interface "dnsserver.Viewer", that allows a plugin implementing it to decide if a query should be routed into its server block. * add new plugin "view", that uses the new interface to enable a user to define expression based conditions that must be met for a query to be routed to its server block. Signed-off-by: Chris O'Haver <cohaver@infoblox.com>
This commit is contained in:
@@ -138,13 +138,6 @@ func (h *dnsContext) InspectServerBlocks(sourceFile string, serverBlocks []caddy
|
||||
|
||||
// MakeServers uses the newly-created siteConfigs to create and return a list of server instances.
|
||||
func (h *dnsContext) MakeServers() ([]caddy.Server, error) {
|
||||
// Now that all Keys and Directives are parsed and initialized
|
||||
// lets verify that there is no overlap on the zones and addresses to listen for
|
||||
errValid := h.validateZonesAndListeningAddresses()
|
||||
if errValid != nil {
|
||||
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
|
||||
@@ -198,6 +191,27 @@ func (h *dnsContext) MakeServers() ([]caddy.Server, error) {
|
||||
}
|
||||
}
|
||||
|
||||
// For each server config, check for View Filter plugins
|
||||
for _, c := range h.configs {
|
||||
// Add filters in the plugin.cfg order for consistent filter func evaluation order.
|
||||
for _, d := range Directives {
|
||||
if vf, ok := c.registry[d].(Viewer); ok {
|
||||
if c.ViewName != "" {
|
||||
return nil, fmt.Errorf("multiple views defined in server block")
|
||||
}
|
||||
c.ViewName = vf.ViewName()
|
||||
c.FilterFuncs = append(c.FilterFuncs, vf.Filter)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Verify that there is no overlap on the zones and listen addresses
|
||||
// for unfiltered server configs
|
||||
errValid := h.validateZonesAndListeningAddresses()
|
||||
if errValid != nil {
|
||||
return nil, errValid
|
||||
}
|
||||
|
||||
return servers, nil
|
||||
}
|
||||
|
||||
@@ -253,7 +267,15 @@ func (h *dnsContext) validateZonesAndListeningAddresses() error {
|
||||
for _, h := range conf.ListenHosts {
|
||||
// Validate the overlapping of ZoneAddr
|
||||
akey := zoneAddr{Transport: conf.Transport, Zone: conf.Zone, Address: h, Port: conf.Port}
|
||||
existZone, overlapZone := checker.registerAndCheck(akey)
|
||||
var existZone, overlapZone *zoneAddr
|
||||
if len(conf.FilterFuncs) > 0 {
|
||||
// This config has filters. Check for overlap with other (unfiltered) configs.
|
||||
existZone, overlapZone = checker.check(akey)
|
||||
} else {
|
||||
// This config has no filters. Check for overlap with other (unfiltered) configs,
|
||||
// and register the zone to prevent subsequent zones from overlapping with it.
|
||||
existZone, overlapZone = checker.registerAndCheck(akey)
|
||||
}
|
||||
if existZone != nil {
|
||||
return fmt.Errorf("cannot serve %s - it is already defined", akey.String())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user