Remove the word middleware (#1067)
* Rename middleware to plugin first pass; mostly used 'sed', few spots where I manually changed text. This still builds a coredns binary. * fmt error * Rename AddMiddleware to AddPlugin * Readd AddMiddleware to remain backwards compat
This commit is contained in:
parent
b984aa4559
commit
d8714e64e4
354 changed files with 974 additions and 969 deletions
|
@ -18,7 +18,7 @@ env:
|
||||||
- TEST_TYPE=coverage ETCD_VERSION=2.3.1 K8S_VERSION=1.5.0 KUBECTL="docker exec hyperkube /hyperkube kubectl"
|
- TEST_TYPE=coverage ETCD_VERSION=2.3.1 K8S_VERSION=1.5.0 KUBECTL="docker exec hyperkube /hyperkube kubectl"
|
||||||
- TEST_TYPE=integration ETCD_VERSION=2.3.1 K8S_VERSION=1.5.0 KUBECTL="docker exec hyperkube /hyperkube kubectl"
|
- TEST_TYPE=integration ETCD_VERSION=2.3.1 K8S_VERSION=1.5.0 KUBECTL="docker exec hyperkube /hyperkube kubectl"
|
||||||
- TEST_TYPE=core ETCD_VERSION=2.3.1 K8S_VERSION=1.5.0 KUBECTL="docker exec hyperkube /hyperkube kubectl"
|
- TEST_TYPE=core ETCD_VERSION=2.3.1 K8S_VERSION=1.5.0 KUBECTL="docker exec hyperkube /hyperkube kubectl"
|
||||||
- TEST_TYPE=middleware ETCD_VERSION=2.3.1 K8S_VERSION=1.5.0 KUBECTL="docker exec hyperkube /hyperkube kubectl"
|
- TEST_TYPE=plugin ETCD_VERSION=2.3.1 K8S_VERSION=1.5.0 KUBECTL="docker exec hyperkube /hyperkube kubectl"
|
||||||
|
|
||||||
# In the Travis VM-based build environment, IPv6 networking is not
|
# In the Travis VM-based build environment, IPv6 networking is not
|
||||||
# enabled by default. The sysctl operations below enable IPv6.
|
# enabled by default. The sysctl operations below enable IPv6.
|
||||||
|
|
12
Makefile
12
Makefile
|
@ -11,15 +11,15 @@ coredns: check godeps
|
||||||
CGO_ENABLED=0 $(SYSTEM) go build -v -ldflags="-s -w -X github.com/coredns/coredns/coremain.gitCommit=$(GITCOMMIT)" -o $(BINARY)
|
CGO_ENABLED=0 $(SYSTEM) go build -v -ldflags="-s -w -X github.com/coredns/coredns/coremain.gitCommit=$(GITCOMMIT)" -o $(BINARY)
|
||||||
|
|
||||||
.PHONY: check
|
.PHONY: check
|
||||||
check: fmt core/zmiddleware.go core/dnsserver/zdirectives.go godeps
|
check: fmt core/zplugin.go core/dnsserver/zdirectives.go godeps
|
||||||
|
|
||||||
.PHONY: test
|
.PHONY: test
|
||||||
test: check
|
test: check
|
||||||
go test -race -v ./test ./middleware/...
|
go test -race -v ./test ./plugin/...
|
||||||
|
|
||||||
.PHONY: testk8s
|
.PHONY: testk8s
|
||||||
testk8s: check
|
testk8s: check
|
||||||
go test -race -v -tags=k8s -run 'TestKubernetes' ./test ./middleware/kubernetes/...
|
go test -race -v -tags=k8s -run 'TestKubernetes' ./test ./plugin/kubernetes/...
|
||||||
|
|
||||||
.PHONY: godeps
|
.PHONY: godeps
|
||||||
godeps:
|
godeps:
|
||||||
|
@ -38,8 +38,8 @@ endif
|
||||||
ifeq ($(TEST_TYPE),integration)
|
ifeq ($(TEST_TYPE),integration)
|
||||||
( cd test ; go test -v -tags 'etcd k8s' -race ./... )
|
( cd test ; go test -v -tags 'etcd k8s' -race ./... )
|
||||||
endif
|
endif
|
||||||
ifeq ($(TEST_TYPE),middleware)
|
ifeq ($(TEST_TYPE),plugin)
|
||||||
( cd middleware ; go test -v -tags 'etcd k8s' -race ./... )
|
( cd plugin ; go test -v -tags 'etcd k8s' -race ./... )
|
||||||
endif
|
endif
|
||||||
ifeq ($(TEST_TYPE),coverage)
|
ifeq ($(TEST_TYPE),coverage)
|
||||||
for d in `go list ./... | grep -v vendor`; do \
|
for d in `go list ./... | grep -v vendor`; do \
|
||||||
|
@ -55,7 +55,7 @@ ifeq ($(TEST_TYPE),coverage)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
|
||||||
core/zmiddleware.go core/dnsserver/zdirectives.go: middleware.cfg
|
core/zplugin.go core/dnsserver/zdirectives.go: plugin.cfg
|
||||||
go generate coredns.go
|
go generate coredns.go
|
||||||
|
|
||||||
.PHONY: gen
|
.PHONY: gen
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
[](https://bestpractices.coreinfrastructure.org/projects/1250)
|
[](https://bestpractices.coreinfrastructure.org/projects/1250)
|
||||||
|
|
||||||
CoreDNS is a DNS server that started as a fork of [Caddy](https://github.com/mholt/caddy/). It has
|
CoreDNS is a DNS server that started as a fork of [Caddy](https://github.com/mholt/caddy/). It has
|
||||||
the same model: it chains middleware. In fact it's so similar that CoreDNS is now a server type
|
the same model: it chains plugins. In fact it's so similar that CoreDNS is now a server type
|
||||||
plugin for Caddy.
|
plugin for Caddy.
|
||||||
|
|
||||||
CoreDNS is also a [Cloud Native Computing Foundation](https://cncf.io) inception level project.
|
CoreDNS is also a [Cloud Native Computing Foundation](https://cncf.io) inception level project.
|
||||||
|
@ -18,7 +18,7 @@ layer that exposes services in etcd in the DNS. CoreDNS builds on this idea and
|
||||||
server that can talk to multiple backends (etcd, kubernetes, etc.).
|
server that can talk to multiple backends (etcd, kubernetes, etc.).
|
||||||
|
|
||||||
CoreDNS aims to be a fast and flexible DNS server. The keyword here is *flexible*: with CoreDNS you
|
CoreDNS aims to be a fast and flexible DNS server. The keyword here is *flexible*: with CoreDNS you
|
||||||
are able to do what you want with your DNS data. And if not: write some middleware!
|
are able to do what you want with your DNS data. And if not: write some plugin!
|
||||||
|
|
||||||
CoreDNS can listen for DNS request coming in over UDP/TCP (go'old DNS), TLS ([RFC
|
CoreDNS can listen for DNS request coming in over UDP/TCP (go'old DNS), TLS ([RFC
|
||||||
7858](https://tools.ietf.org/html/rfc7858)) and gRPC (not a standard).
|
7858](https://tools.ietf.org/html/rfc7858)) and gRPC (not a standard).
|
||||||
|
@ -44,7 +44,7 @@ Currently CoreDNS is able to:
|
||||||
* Rewrite queries (qtype, qclass and qname) (*rewrite*).
|
* Rewrite queries (qtype, qclass and qname) (*rewrite*).
|
||||||
* Echo back the IP address, transport and port number used (*whoami*).
|
* Echo back the IP address, transport and port number used (*whoami*).
|
||||||
|
|
||||||
Each of the middlewares has a README.md of its own.
|
Each of the plugins has a README.md of its own.
|
||||||
|
|
||||||
## Status
|
## Status
|
||||||
|
|
||||||
|
@ -92,7 +92,7 @@ The above command alone will have `coredns` binary generated.
|
||||||
|
|
||||||
## Examples
|
## Examples
|
||||||
|
|
||||||
When starting CoreDNS without any configuration, it loads the `whoami` middleware and starts
|
When starting CoreDNS without any configuration, it loads the `whoami` plugin and starts
|
||||||
listening on port 53 (override with `-dns.port`), it should show the following:
|
listening on port 53 (override with `-dns.port`), it should show the following:
|
||||||
|
|
||||||
~~~ txt
|
~~~ txt
|
||||||
|
|
|
@ -6,27 +6,27 @@ import (
|
||||||
_ "github.com/coredns/coredns/core/dnsserver"
|
_ "github.com/coredns/coredns/core/dnsserver"
|
||||||
|
|
||||||
// plug in the standard directives (sorted)
|
// plug in the standard directives (sorted)
|
||||||
_ "github.com/coredns/coredns/middleware/auto"
|
_ "github.com/coredns/coredns/plugin/auto"
|
||||||
_ "github.com/coredns/coredns/middleware/bind"
|
_ "github.com/coredns/coredns/plugin/bind"
|
||||||
_ "github.com/coredns/coredns/middleware/cache"
|
_ "github.com/coredns/coredns/plugin/cache"
|
||||||
_ "github.com/coredns/coredns/middleware/chaos"
|
_ "github.com/coredns/coredns/plugin/chaos"
|
||||||
_ "github.com/coredns/coredns/middleware/dnssec"
|
_ "github.com/coredns/coredns/plugin/dnssec"
|
||||||
_ "github.com/coredns/coredns/middleware/dnstap"
|
_ "github.com/coredns/coredns/plugin/dnstap"
|
||||||
_ "github.com/coredns/coredns/middleware/erratic"
|
_ "github.com/coredns/coredns/plugin/erratic"
|
||||||
_ "github.com/coredns/coredns/middleware/errors"
|
_ "github.com/coredns/coredns/plugin/errors"
|
||||||
_ "github.com/coredns/coredns/middleware/etcd"
|
_ "github.com/coredns/coredns/plugin/etcd"
|
||||||
_ "github.com/coredns/coredns/middleware/file"
|
_ "github.com/coredns/coredns/plugin/file"
|
||||||
_ "github.com/coredns/coredns/middleware/health"
|
_ "github.com/coredns/coredns/plugin/health"
|
||||||
_ "github.com/coredns/coredns/middleware/kubernetes"
|
_ "github.com/coredns/coredns/plugin/kubernetes"
|
||||||
_ "github.com/coredns/coredns/middleware/loadbalance"
|
_ "github.com/coredns/coredns/plugin/loadbalance"
|
||||||
_ "github.com/coredns/coredns/middleware/log"
|
_ "github.com/coredns/coredns/plugin/log"
|
||||||
_ "github.com/coredns/coredns/middleware/metrics"
|
_ "github.com/coredns/coredns/plugin/metrics"
|
||||||
_ "github.com/coredns/coredns/middleware/pprof"
|
_ "github.com/coredns/coredns/plugin/pprof"
|
||||||
_ "github.com/coredns/coredns/middleware/proxy"
|
_ "github.com/coredns/coredns/plugin/proxy"
|
||||||
_ "github.com/coredns/coredns/middleware/reverse"
|
_ "github.com/coredns/coredns/plugin/reverse"
|
||||||
_ "github.com/coredns/coredns/middleware/rewrite"
|
_ "github.com/coredns/coredns/plugin/rewrite"
|
||||||
_ "github.com/coredns/coredns/middleware/root"
|
_ "github.com/coredns/coredns/plugin/root"
|
||||||
_ "github.com/coredns/coredns/middleware/secondary"
|
_ "github.com/coredns/coredns/plugin/secondary"
|
||||||
_ "github.com/coredns/coredns/middleware/trace"
|
_ "github.com/coredns/coredns/plugin/trace"
|
||||||
_ "github.com/coredns/coredns/middleware/whoami"
|
_ "github.com/coredns/coredns/plugin/whoami"
|
||||||
)
|
)
|
||||||
|
|
|
@ -3,7 +3,7 @@ package dnsserver
|
||||||
import (
|
import (
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/coredns/coredns/middleware"
|
"github.com/coredns/coredns/plugin"
|
||||||
|
|
||||||
"github.com/miekg/dns"
|
"github.com/miekg/dns"
|
||||||
)
|
)
|
||||||
|
@ -50,7 +50,7 @@ func normalizeZone(str string) (zoneAddr, error) {
|
||||||
str = str[len(TransportGRPC+"://"):]
|
str = str[len(TransportGRPC+"://"):]
|
||||||
}
|
}
|
||||||
|
|
||||||
host, port, err := middleware.SplitHostPort(str)
|
host, port, err := plugin.SplitHostPort(str)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return zoneAddr{}, err
|
return zoneAddr{}, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,8 +3,7 @@ package dnsserver
|
||||||
import (
|
import (
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
|
|
||||||
"github.com/coredns/coredns/middleware"
|
"github.com/coredns/coredns/plugin"
|
||||||
|
|
||||||
"github.com/mholt/caddy"
|
"github.com/mholt/caddy"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -20,7 +19,7 @@ type Config struct {
|
||||||
Port string
|
Port string
|
||||||
|
|
||||||
// Root points to a base directory we we find user defined "things".
|
// Root points to a base directory we we find user defined "things".
|
||||||
// First consumer is the file middleware to looks for zone files in this place.
|
// First consumer is the file plugin to looks for zone files in this place.
|
||||||
Root string
|
Root string
|
||||||
|
|
||||||
// Debug controls the panic/recover mechanism that is enabled by default.
|
// Debug controls the panic/recover mechanism that is enabled by default.
|
||||||
|
@ -33,16 +32,16 @@ type Config struct {
|
||||||
// TLSConfig when listening for encrypted connections (gRPC, DNS-over-TLS).
|
// TLSConfig when listening for encrypted connections (gRPC, DNS-over-TLS).
|
||||||
TLSConfig *tls.Config
|
TLSConfig *tls.Config
|
||||||
|
|
||||||
// Middleware stack.
|
// Plugin stack.
|
||||||
Middleware []middleware.Middleware
|
Plugin []plugin.Plugin
|
||||||
|
|
||||||
// Compiled middleware stack.
|
// Compiled plugin stack.
|
||||||
middlewareChain middleware.Handler
|
pluginChain plugin.Handler
|
||||||
|
|
||||||
// Middleware interested in announcing that they exist, so other middleware can call methods
|
// Plugin interested in announcing that they exist, so other plugin can call methods
|
||||||
// on them should register themselves here. The name should be the name as return by the
|
// on them should register themselves here. The name should be the name as return by the
|
||||||
// Handler's Name method.
|
// Handler's Name method.
|
||||||
registry map[string]middleware.Handler
|
registry map[string]plugin.Handler
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetConfig gets the Config that corresponds to c.
|
// GetConfig gets the Config that corresponds to c.
|
||||||
|
|
|
@ -6,7 +6,7 @@ import (
|
||||||
"net"
|
"net"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/coredns/coredns/middleware"
|
"github.com/coredns/coredns/plugin"
|
||||||
|
|
||||||
"github.com/mholt/caddy"
|
"github.com/mholt/caddy"
|
||||||
"github.com/mholt/caddy/caddyfile"
|
"github.com/mholt/caddy/caddyfile"
|
||||||
|
@ -119,27 +119,33 @@ func (h *dnsContext) MakeServers() ([]caddy.Server, error) {
|
||||||
return servers, nil
|
return servers, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddMiddleware adds a middleware to a site's middleware stack.
|
// AddPlugin adds a plugin to a site's plugin stack.
|
||||||
func (c *Config) AddMiddleware(m middleware.Middleware) {
|
func (c *Config) AddPlugin(m plugin.Plugin) {
|
||||||
c.Middleware = append(c.Middleware, m)
|
c.Plugin = append(c.Plugin, m)
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddMiddleware adds a plugin to a site's plugin stack. This method is deprecated, use AddPlugin.
|
||||||
|
func (c *Config) AddMiddleware(m plugin.Plugin) {
|
||||||
|
println("deprecated: use AddPlugin")
|
||||||
|
c.AddPlugin(m)
|
||||||
}
|
}
|
||||||
|
|
||||||
// registerHandler adds a handler to a site's handler registration. Handlers
|
// registerHandler adds a handler to a site's handler registration. Handlers
|
||||||
// use this to announce that they exist to other middleware.
|
// use this to announce that they exist to other plugin.
|
||||||
func (c *Config) registerHandler(h middleware.Handler) {
|
func (c *Config) registerHandler(h plugin.Handler) {
|
||||||
if c.registry == nil {
|
if c.registry == nil {
|
||||||
c.registry = make(map[string]middleware.Handler)
|
c.registry = make(map[string]plugin.Handler)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Just overwrite...
|
// Just overwrite...
|
||||||
c.registry[h.Name()] = h
|
c.registry[h.Name()] = h
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handler returns the middleware handler that has been added to the config under its name.
|
// Handler returns the plugin handler that has been added to the config under its name.
|
||||||
// This is useful to inspect if a certain middleware is active in this server.
|
// This is useful to inspect if a certain plugin is active in this server.
|
||||||
// Note that this is order dependent and the order is defined in directives.go, i.e. if your middleware
|
// Note that this is order dependent and the order is defined in directives.go, i.e. if your plugin
|
||||||
// comes before the middleware you are checking; it will not be there (yet).
|
// comes before the plugin you are checking; it will not be there (yet).
|
||||||
func (c *Config) Handler(name string) middleware.Handler {
|
func (c *Config) Handler(name string) plugin.Handler {
|
||||||
if c.registry == nil {
|
if c.registry == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,7 +24,7 @@ type ServergRPC struct {
|
||||||
listenAddr net.Addr
|
listenAddr net.Addr
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewServergRPC returns a new CoreDNS GRPC server and compiles all middleware in to it.
|
// NewServergRPC returns a new CoreDNS GRPC server and compiles all plugin in to it.
|
||||||
func NewServergRPC(addr string, group []*Config) (*ServergRPC, error) {
|
func NewServergRPC(addr string, group []*Config) (*ServergRPC, error) {
|
||||||
|
|
||||||
s, err := NewServer(addr, group)
|
s, err := NewServer(addr, group)
|
||||||
|
@ -62,7 +62,7 @@ func (s *ServergRPC) ServePacket(p net.PacketConn) error { return nil }
|
||||||
// Listen implements caddy.TCPServer interface.
|
// Listen implements caddy.TCPServer interface.
|
||||||
func (s *ServergRPC) Listen() (net.Listener, error) {
|
func (s *ServergRPC) Listen() (net.Listener, error) {
|
||||||
|
|
||||||
// The *tls* middleware must make sure that multiple conflicting
|
// The *tls* plugin must make sure that multiple conflicting
|
||||||
// TLS configuration return an error: it can only be specified once.
|
// TLS configuration return an error: it can only be specified once.
|
||||||
tlsConfig := new(tls.Config)
|
tlsConfig := new(tls.Config)
|
||||||
for _, conf := range s.zones {
|
for _, conf := range s.zones {
|
||||||
|
|
|
@ -14,7 +14,7 @@ type ServerTLS struct {
|
||||||
*Server
|
*Server
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewServerTLS returns a new CoreDNS TLS server and compiles all middleware in to it.
|
// NewServerTLS returns a new CoreDNS TLS server and compiles all plugin in to it.
|
||||||
func NewServerTLS(addr string, group []*Config) (*ServerTLS, error) {
|
func NewServerTLS(addr string, group []*Config) (*ServerTLS, error) {
|
||||||
s, err := NewServer(addr, group)
|
s, err := NewServer(addr, group)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -43,7 +43,7 @@ func (s *ServerTLS) ServePacket(p net.PacketConn) error { return nil }
|
||||||
|
|
||||||
// Listen implements caddy.TCPServer interface.
|
// Listen implements caddy.TCPServer interface.
|
||||||
func (s *ServerTLS) Listen() (net.Listener, error) {
|
func (s *ServerTLS) Listen() (net.Listener, error) {
|
||||||
// The *tls* middleware must make sure that multiple conflicting
|
// The *tls* plugin must make sure that multiple conflicting
|
||||||
// TLS configuration return an error: it can only be specified once.
|
// TLS configuration return an error: it can only be specified once.
|
||||||
tlsConfig := new(tls.Config)
|
tlsConfig := new(tls.Config)
|
||||||
for _, conf := range s.zones {
|
for _, conf := range s.zones {
|
||||||
|
|
|
@ -9,11 +9,11 @@ import (
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/coredns/coredns/middleware"
|
"github.com/coredns/coredns/plugin"
|
||||||
"github.com/coredns/coredns/middleware/metrics/vars"
|
"github.com/coredns/coredns/plugin/metrics/vars"
|
||||||
"github.com/coredns/coredns/middleware/pkg/edns"
|
"github.com/coredns/coredns/plugin/pkg/edns"
|
||||||
"github.com/coredns/coredns/middleware/pkg/rcode"
|
"github.com/coredns/coredns/plugin/pkg/rcode"
|
||||||
"github.com/coredns/coredns/middleware/pkg/trace"
|
"github.com/coredns/coredns/plugin/pkg/trace"
|
||||||
"github.com/coredns/coredns/request"
|
"github.com/coredns/coredns/request"
|
||||||
|
|
||||||
"github.com/miekg/dns"
|
"github.com/miekg/dns"
|
||||||
|
@ -35,12 +35,12 @@ type Server struct {
|
||||||
zones map[string]*Config // zones keyed by their address
|
zones map[string]*Config // zones keyed by their address
|
||||||
dnsWg sync.WaitGroup // used to wait on outstanding connections
|
dnsWg sync.WaitGroup // used to wait on outstanding connections
|
||||||
connTimeout time.Duration // the maximum duration of a graceful shutdown
|
connTimeout time.Duration // the maximum duration of a graceful shutdown
|
||||||
trace trace.Trace // the trace middleware for the server
|
trace trace.Trace // the trace plugin for the server
|
||||||
debug bool // disable recover()
|
debug bool // disable recover()
|
||||||
classChaos bool // allow non-INET class queries
|
classChaos bool // allow non-INET class queries
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewServer returns a new CoreDNS server and compiles all middleware in to it. By default CH class
|
// NewServer returns a new CoreDNS server and compiles all plugin in to it. By default CH class
|
||||||
// queries are blocked unless the chaos or proxy is loaded.
|
// queries are blocked unless the chaos or proxy is loaded.
|
||||||
func NewServer(addr string, group []*Config) (*Server, error) {
|
func NewServer(addr string, group []*Config) (*Server, error) {
|
||||||
|
|
||||||
|
@ -64,16 +64,16 @@ func NewServer(addr string, group []*Config) (*Server, error) {
|
||||||
}
|
}
|
||||||
// set the config per zone
|
// set the config per zone
|
||||||
s.zones[site.Zone] = site
|
s.zones[site.Zone] = site
|
||||||
// compile custom middleware for everything
|
// compile custom plugin for everything
|
||||||
var stack middleware.Handler
|
var stack plugin.Handler
|
||||||
for i := len(site.Middleware) - 1; i >= 0; i-- {
|
for i := len(site.Plugin) - 1; i >= 0; i-- {
|
||||||
stack = site.Middleware[i](stack)
|
stack = site.Plugin[i](stack)
|
||||||
|
|
||||||
// register the *handler* also
|
// register the *handler* also
|
||||||
site.registerHandler(stack)
|
site.registerHandler(stack)
|
||||||
|
|
||||||
if s.trace == nil && stack.Name() == "trace" {
|
if s.trace == nil && stack.Name() == "trace" {
|
||||||
// we have to stash away the middleware, not the
|
// we have to stash away the plugin, not the
|
||||||
// Tracer object, because the Tracer won't be initialized yet
|
// Tracer object, because the Tracer won't be initialized yet
|
||||||
if t, ok := stack.(trace.Trace); ok {
|
if t, ok := stack.(trace.Trace); ok {
|
||||||
s.trace = t
|
s.trace = t
|
||||||
|
@ -83,7 +83,7 @@ func NewServer(addr string, group []*Config) (*Server, error) {
|
||||||
s.classChaos = true
|
s.classChaos = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
site.middlewareChain = stack
|
site.pluginChain = stack
|
||||||
}
|
}
|
||||||
|
|
||||||
return s, nil
|
return s, nil
|
||||||
|
@ -177,11 +177,11 @@ func (s *Server) Address() string { return s.Addr }
|
||||||
// ServeDNS is the entry point for every request to the address that s
|
// ServeDNS is the entry point for every request to the address that s
|
||||||
// is bound to. It acts as a multiplexer for the requests zonename as
|
// is bound to. It acts as a multiplexer for the requests zonename as
|
||||||
// defined in the request so that the correct zone
|
// defined in the request so that the correct zone
|
||||||
// (configuration and middleware stack) will handle the request.
|
// (configuration and plugin stack) will handle the request.
|
||||||
func (s *Server) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) {
|
func (s *Server) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) {
|
||||||
if !s.debug {
|
if !s.debug {
|
||||||
defer func() {
|
defer func() {
|
||||||
// In case the user doesn't enable error middleware, we still
|
// In case the user doesn't enable error plugin, we still
|
||||||
// need to make sure that we stay alive up here
|
// need to make sure that we stay alive up here
|
||||||
if rec := recover(); rec != nil {
|
if rec := recover(); rec != nil {
|
||||||
DefaultErrorFunc(w, r, dns.RcodeServerFailure)
|
DefaultErrorFunc(w, r, dns.RcodeServerFailure)
|
||||||
|
@ -218,8 +218,8 @@ func (s *Server) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg)
|
||||||
|
|
||||||
if h, ok := s.zones[string(b[:l])]; ok {
|
if h, ok := s.zones[string(b[:l])]; ok {
|
||||||
if r.Question[0].Qtype != dns.TypeDS {
|
if r.Question[0].Qtype != dns.TypeDS {
|
||||||
rcode, _ := h.middlewareChain.ServeDNS(ctx, w, r)
|
rcode, _ := h.pluginChain.ServeDNS(ctx, w, r)
|
||||||
if !middleware.ClientWrite(rcode) {
|
if !plugin.ClientWrite(rcode) {
|
||||||
DefaultErrorFunc(w, r, rcode)
|
DefaultErrorFunc(w, r, rcode)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
|
@ -239,8 +239,8 @@ func (s *Server) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg)
|
||||||
|
|
||||||
if dshandler != nil {
|
if dshandler != nil {
|
||||||
// DS request, and we found a zone, use the handler for the query
|
// DS request, and we found a zone, use the handler for the query
|
||||||
rcode, _ := dshandler.middlewareChain.ServeDNS(ctx, w, r)
|
rcode, _ := dshandler.pluginChain.ServeDNS(ctx, w, r)
|
||||||
if !middleware.ClientWrite(rcode) {
|
if !plugin.ClientWrite(rcode) {
|
||||||
DefaultErrorFunc(w, r, rcode)
|
DefaultErrorFunc(w, r, rcode)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
|
@ -248,8 +248,8 @@ func (s *Server) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg)
|
||||||
|
|
||||||
// Wildcard match, if we have found nothing try the root zone as a last resort.
|
// Wildcard match, if we have found nothing try the root zone as a last resort.
|
||||||
if h, ok := s.zones["."]; ok {
|
if h, ok := s.zones["."]; ok {
|
||||||
rcode, _ := h.middlewareChain.ServeDNS(ctx, w, r)
|
rcode, _ := h.pluginChain.ServeDNS(ctx, w, r)
|
||||||
if !middleware.ClientWrite(rcode) {
|
if !plugin.ClientWrite(rcode) {
|
||||||
DefaultErrorFunc(w, r, rcode)
|
DefaultErrorFunc(w, r, rcode)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
|
|
|
@ -5,10 +5,10 @@ package dnsserver
|
||||||
// Directives are registered in the order they should be
|
// Directives are registered in the order they should be
|
||||||
// executed.
|
// executed.
|
||||||
//
|
//
|
||||||
// Ordering is VERY important. Every middleware will
|
// Ordering is VERY important. Every plugin will
|
||||||
// feel the effects of all other middleware below
|
// feel the effects of all other plugin below
|
||||||
// (after) them during a request, but they must not
|
// (after) them during a request, but they must not
|
||||||
// care what middleware above them are doing.
|
// care what plugin above them are doing.
|
||||||
|
|
||||||
var directives = []string{
|
var directives = []string{
|
||||||
"tls",
|
"tls",
|
||||||
|
|
|
@ -1,36 +0,0 @@
|
||||||
// generated by directives_generate.go; DO NOT EDIT
|
|
||||||
|
|
||||||
package core
|
|
||||||
|
|
||||||
import (
|
|
||||||
// Include all middleware.
|
|
||||||
_ "github.com/coredns/coredns/middleware/auto"
|
|
||||||
_ "github.com/coredns/coredns/middleware/autopath"
|
|
||||||
_ "github.com/coredns/coredns/middleware/bind"
|
|
||||||
_ "github.com/coredns/coredns/middleware/cache"
|
|
||||||
_ "github.com/coredns/coredns/middleware/chaos"
|
|
||||||
_ "github.com/coredns/coredns/middleware/debug"
|
|
||||||
_ "github.com/coredns/coredns/middleware/dnssec"
|
|
||||||
_ "github.com/coredns/coredns/middleware/dnstap"
|
|
||||||
_ "github.com/coredns/coredns/middleware/erratic"
|
|
||||||
_ "github.com/coredns/coredns/middleware/errors"
|
|
||||||
_ "github.com/coredns/coredns/middleware/etcd"
|
|
||||||
_ "github.com/coredns/coredns/middleware/federation"
|
|
||||||
_ "github.com/coredns/coredns/middleware/file"
|
|
||||||
_ "github.com/coredns/coredns/middleware/health"
|
|
||||||
_ "github.com/coredns/coredns/middleware/hosts"
|
|
||||||
_ "github.com/coredns/coredns/middleware/kubernetes"
|
|
||||||
_ "github.com/coredns/coredns/middleware/loadbalance"
|
|
||||||
_ "github.com/coredns/coredns/middleware/log"
|
|
||||||
_ "github.com/coredns/coredns/middleware/metrics"
|
|
||||||
_ "github.com/coredns/coredns/middleware/pprof"
|
|
||||||
_ "github.com/coredns/coredns/middleware/proxy"
|
|
||||||
_ "github.com/coredns/coredns/middleware/reverse"
|
|
||||||
_ "github.com/coredns/coredns/middleware/rewrite"
|
|
||||||
_ "github.com/coredns/coredns/middleware/root"
|
|
||||||
_ "github.com/coredns/coredns/middleware/secondary"
|
|
||||||
_ "github.com/coredns/coredns/middleware/tls"
|
|
||||||
_ "github.com/coredns/coredns/middleware/trace"
|
|
||||||
_ "github.com/coredns/coredns/middleware/whoami"
|
|
||||||
_ "github.com/mholt/caddy/startupshutdown"
|
|
||||||
)
|
|
36
core/zplugin.go
Normal file
36
core/zplugin.go
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
// generated by directives_generate.go; DO NOT EDIT
|
||||||
|
|
||||||
|
package core
|
||||||
|
|
||||||
|
import (
|
||||||
|
// Include all plugin.
|
||||||
|
_ "github.com/coredns/coredns/plugin/auto"
|
||||||
|
_ "github.com/coredns/coredns/plugin/autopath"
|
||||||
|
_ "github.com/coredns/coredns/plugin/bind"
|
||||||
|
_ "github.com/coredns/coredns/plugin/cache"
|
||||||
|
_ "github.com/coredns/coredns/plugin/chaos"
|
||||||
|
_ "github.com/coredns/coredns/plugin/debug"
|
||||||
|
_ "github.com/coredns/coredns/plugin/dnssec"
|
||||||
|
_ "github.com/coredns/coredns/plugin/dnstap"
|
||||||
|
_ "github.com/coredns/coredns/plugin/erratic"
|
||||||
|
_ "github.com/coredns/coredns/plugin/errors"
|
||||||
|
_ "github.com/coredns/coredns/plugin/etcd"
|
||||||
|
_ "github.com/coredns/coredns/plugin/federation"
|
||||||
|
_ "github.com/coredns/coredns/plugin/file"
|
||||||
|
_ "github.com/coredns/coredns/plugin/health"
|
||||||
|
_ "github.com/coredns/coredns/plugin/hosts"
|
||||||
|
_ "github.com/coredns/coredns/plugin/kubernetes"
|
||||||
|
_ "github.com/coredns/coredns/plugin/loadbalance"
|
||||||
|
_ "github.com/coredns/coredns/plugin/log"
|
||||||
|
_ "github.com/coredns/coredns/plugin/metrics"
|
||||||
|
_ "github.com/coredns/coredns/plugin/pprof"
|
||||||
|
_ "github.com/coredns/coredns/plugin/proxy"
|
||||||
|
_ "github.com/coredns/coredns/plugin/reverse"
|
||||||
|
_ "github.com/coredns/coredns/plugin/rewrite"
|
||||||
|
_ "github.com/coredns/coredns/plugin/root"
|
||||||
|
_ "github.com/coredns/coredns/plugin/secondary"
|
||||||
|
_ "github.com/coredns/coredns/plugin/tls"
|
||||||
|
_ "github.com/coredns/coredns/plugin/trace"
|
||||||
|
_ "github.com/coredns/coredns/plugin/whoami"
|
||||||
|
_ "github.com/mholt/caddy/startupshutdown"
|
||||||
|
)
|
|
@ -17,7 +17,7 @@ func main() {
|
||||||
mi := make(map[string]string, 0)
|
mi := make(map[string]string, 0)
|
||||||
md := make(map[int]string, 0)
|
md := make(map[int]string, 0)
|
||||||
|
|
||||||
file, err := os.Open(middlewareFile)
|
file, err := os.Open(pluginFile)
|
||||||
fatalIfErr(err)
|
fatalIfErr(err)
|
||||||
|
|
||||||
defer file.Close()
|
defer file.Close()
|
||||||
|
@ -41,14 +41,14 @@ func main() {
|
||||||
log.Fatalf("Duplicate priority '%d', slot already taken by %q", priority, v)
|
log.Fatalf("Duplicate priority '%d', slot already taken by %q", priority, v)
|
||||||
}
|
}
|
||||||
md[priority] = items[1]
|
md[priority] = items[1]
|
||||||
mi[items[1]] = middlewarePath + items[2] // Default, unless overridden by 3rd arg
|
mi[items[1]] = pluginPath + items[2] // Default, unless overridden by 3rd arg
|
||||||
|
|
||||||
if _, err := os.Stat(middlewareFSPath + items[2]); err != nil { // External package has been given
|
if _, err := os.Stat(pluginFSPath + items[2]); err != nil { // External package has been given
|
||||||
mi[items[1]] = items[2]
|
mi[items[1]] = items[2]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
genImports("core/zmiddleware.go", "core", mi)
|
genImports("core/zplugin.go", "core", mi)
|
||||||
genDirectives("core/dnsserver/zdirectives.go", "dnsserver", md)
|
genDirectives("core/dnsserver/zdirectives.go", "dnsserver", md)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -59,7 +59,7 @@ func genImports(file, pack string, mi map[string]string) {
|
||||||
outs += "\n"
|
outs += "\n"
|
||||||
}
|
}
|
||||||
|
|
||||||
outs += "// Include all middleware.\n"
|
outs += "// Include all plugin.\n"
|
||||||
for _, v := range mi {
|
for _, v := range mi {
|
||||||
outs += `_ "` + v + `"` + "\n"
|
outs += `_ "` + v + `"` + "\n"
|
||||||
}
|
}
|
||||||
|
@ -79,10 +79,10 @@ func genDirectives(file, pack string, md map[int]string) {
|
||||||
// Directives are registered in the order they should be
|
// Directives are registered in the order they should be
|
||||||
// executed.
|
// executed.
|
||||||
//
|
//
|
||||||
// Ordering is VERY important. Every middleware will
|
// Ordering is VERY important. Every plugin will
|
||||||
// feel the effects of all other middleware below
|
// feel the effects of all other plugin below
|
||||||
// (after) them during a request, but they must not
|
// (after) them during a request, but they must not
|
||||||
// care what middleware above them are doing.
|
// care what plugin above them are doing.
|
||||||
|
|
||||||
var directives = []string{
|
var directives = []string{
|
||||||
`
|
`
|
||||||
|
@ -113,8 +113,8 @@ func fatalIfErr(err error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
middlewarePath = "github.com/coredns/coredns/middleware/"
|
pluginPath = "github.com/coredns/coredns/plugin/"
|
||||||
middlewareFile = "middleware.cfg"
|
pluginFile = "plugin.cfg"
|
||||||
middlewareFSPath = "middleware/" // Where the middleware packages are located on the file system
|
pluginFSPath = "plugin/" // Where the plugins are located on the file system
|
||||||
header = "// generated by directives_generate.go; DO NOT EDIT\n\n"
|
header = "// generated by directives_generate.go; DO NOT EDIT\n\n"
|
||||||
)
|
)
|
||||||
|
|
|
@ -1,86 +0,0 @@
|
||||||
package kubernetes
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/coredns/coredns/middleware"
|
|
||||||
"github.com/coredns/coredns/middleware/pkg/dnsutil"
|
|
||||||
"github.com/coredns/coredns/request"
|
|
||||||
|
|
||||||
"github.com/miekg/dns"
|
|
||||||
"golang.org/x/net/context"
|
|
||||||
)
|
|
||||||
|
|
||||||
// ServeDNS implements the middleware.Handler interface.
|
|
||||||
func (k Kubernetes) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (int, error) {
|
|
||||||
state := request.Request{W: w, Req: r}
|
|
||||||
|
|
||||||
m := new(dns.Msg)
|
|
||||||
m.SetReply(r)
|
|
||||||
m.Authoritative, m.RecursionAvailable, m.Compress = true, true, true
|
|
||||||
|
|
||||||
zone := middleware.Zones(k.Zones).Matches(state.Name())
|
|
||||||
if zone == "" {
|
|
||||||
return middleware.NextOrFailure(k.Name(), k.Next, ctx, w, r)
|
|
||||||
}
|
|
||||||
|
|
||||||
state.Zone = zone
|
|
||||||
|
|
||||||
var (
|
|
||||||
records []dns.RR
|
|
||||||
extra []dns.RR
|
|
||||||
err error
|
|
||||||
)
|
|
||||||
|
|
||||||
switch state.Type() {
|
|
||||||
case "A":
|
|
||||||
records, err = middleware.A(&k, zone, state, nil, middleware.Options{})
|
|
||||||
case "AAAA":
|
|
||||||
records, err = middleware.AAAA(&k, zone, state, nil, middleware.Options{})
|
|
||||||
case "TXT":
|
|
||||||
records, err = middleware.TXT(&k, zone, state, middleware.Options{})
|
|
||||||
case "CNAME":
|
|
||||||
records, err = middleware.CNAME(&k, zone, state, middleware.Options{})
|
|
||||||
case "PTR":
|
|
||||||
records, err = middleware.PTR(&k, zone, state, middleware.Options{})
|
|
||||||
case "MX":
|
|
||||||
records, extra, err = middleware.MX(&k, zone, state, middleware.Options{})
|
|
||||||
case "SRV":
|
|
||||||
records, extra, err = middleware.SRV(&k, zone, state, middleware.Options{})
|
|
||||||
case "SOA":
|
|
||||||
records, err = middleware.SOA(&k, zone, state, middleware.Options{})
|
|
||||||
case "NS":
|
|
||||||
if state.Name() == zone {
|
|
||||||
records, extra, err = middleware.NS(&k, zone, state, middleware.Options{})
|
|
||||||
break
|
|
||||||
}
|
|
||||||
fallthrough
|
|
||||||
default:
|
|
||||||
// Do a fake A lookup, so we can distinguish between NODATA and NXDOMAIN
|
|
||||||
_, err = middleware.A(&k, zone, state, nil, middleware.Options{})
|
|
||||||
}
|
|
||||||
|
|
||||||
if k.IsNameError(err) {
|
|
||||||
if k.Fallthrough {
|
|
||||||
return middleware.NextOrFailure(k.Name(), k.Next, ctx, w, r)
|
|
||||||
}
|
|
||||||
return middleware.BackendError(&k, zone, dns.RcodeNameError, state, nil /* err */, middleware.Options{})
|
|
||||||
}
|
|
||||||
if err != nil {
|
|
||||||
return dns.RcodeServerFailure, err
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(records) == 0 {
|
|
||||||
return middleware.BackendError(&k, zone, dns.RcodeSuccess, state, nil, middleware.Options{})
|
|
||||||
}
|
|
||||||
|
|
||||||
m.Answer = append(m.Answer, records...)
|
|
||||||
m.Extra = append(m.Extra, extra...)
|
|
||||||
|
|
||||||
m = dnsutil.Dedup(m)
|
|
||||||
state.SizeAndDo(m)
|
|
||||||
m, _ = state.Scrub(m)
|
|
||||||
w.WriteMsg(m)
|
|
||||||
return dns.RcodeSuccess, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Name implements the Handler interface.
|
|
||||||
func (k Kubernetes) Name() string { return "kubernetes" }
|
|
|
@ -1 +0,0 @@
|
||||||
package middleware
|
|
|
@ -1,10 +0,0 @@
|
||||||
// Package secondary implements a secondary middleware.
|
|
||||||
package secondary
|
|
||||||
|
|
||||||
import "github.com/coredns/coredns/middleware/file"
|
|
||||||
|
|
||||||
// Secondary implements a secondary middleware that allows CoreDNS to retrieve (via AXFR)
|
|
||||||
// zone information from a primary server.
|
|
||||||
type Secondary struct {
|
|
||||||
file.File
|
|
||||||
}
|
|
|
@ -1,2 +0,0 @@
|
||||||
// Package test contains helper functions for writing middleware tests.
|
|
||||||
package test
|
|
|
@ -1,22 +1,22 @@
|
||||||
# Directives are registered in the order they should be
|
# Directives are registered in the order they should be
|
||||||
# executed.
|
# executed.
|
||||||
#
|
#
|
||||||
# Ordering is VERY important. Every middleware will
|
# Ordering is VERY important. Every plugin will
|
||||||
# feel the effects of all other middleware below
|
# feel the effects of all other plugin below
|
||||||
# (after) them during a request, but they must not
|
# (after) them during a request, but they must not
|
||||||
# care what middleware above them are doing.
|
# care what plugin above them are doing.
|
||||||
|
|
||||||
# How to rebuild with updated middleware configurations:
|
# How to rebuild with updated plugin configurations:
|
||||||
# Modify the list below and run `go gen && go build`
|
# Modify the list below and run `go gen && go build`
|
||||||
|
|
||||||
# The parser takes the input format of
|
# The parser takes the input format of
|
||||||
# <order>:<middleware-name>:<package-name>
|
# <order>:<plugin-name>:<package-name>
|
||||||
# Or
|
# Or
|
||||||
# <order>:<middleware-name>:<fully-qualified-package-name>
|
# <order>:<plugin-name>:<fully-qualified-package-name>
|
||||||
#
|
#
|
||||||
# External middleware example:
|
# External plugin example:
|
||||||
# 80:log:github.com/coredns/coredns/middleware/log
|
# 80:log:github.com/coredns/coredns/plugin/log
|
||||||
# Local middleware example:
|
# Local plugin example:
|
||||||
# 80:log:log
|
# 80:log:log
|
||||||
|
|
||||||
1:tls:tls
|
1:tls:tls
|
|
@ -5,14 +5,14 @@
|
||||||
From the Caddy docs:
|
From the Caddy docs:
|
||||||
|
|
||||||
> Oh yes, those pesky return values on ServeHTTP(). You read the documentation so you already know
|
> Oh yes, those pesky return values on ServeHTTP(). You read the documentation so you already know
|
||||||
> what they mean. But what does that imply for the behavior of your middleware?
|
> what they mean. But what does that imply for the behavior of your plugin?
|
||||||
>
|
>
|
||||||
> Basically, return a status code only if you did NOT write to the response body. If you DO write to
|
> Basically, return a status code only if you did NOT write to the response body. If you DO write to
|
||||||
> the response body, return a status code of 0. Return an error value if your middleware encountered
|
> the response body, return a status code of 0. Return an error value if your plugin encountered
|
||||||
> an error that you want logged. It is common to return an error status and an error value together,
|
> an error that you want logged. It is common to return an error status and an error value together,
|
||||||
> so that the error handler up the chain can write the correct error page.
|
> so that the error handler up the chain can write the correct error page.
|
||||||
>
|
>
|
||||||
> The returned status code is not logged directly; rather, it tells middleware higher up the chain
|
> The returned status code is not logged directly; rather, it tells plugin higher up the chain
|
||||||
> what status code to use if/when the response body is written. Again, return a 0 status if you've
|
> what status code to use if/when the response body is written. Again, return a 0 status if you've
|
||||||
> already written a body!
|
> already written a body!
|
||||||
|
|
||||||
|
@ -27,28 +27,28 @@ So CoreDNS treats:
|
||||||
* NOTIMP (dns.RcodeNotImplemented)
|
* NOTIMP (dns.RcodeNotImplemented)
|
||||||
|
|
||||||
as special and will then assume nothing has written to the client. In all other cases it is assumes
|
as special and will then assume nothing has written to the client. In all other cases it is assumes
|
||||||
something has been written to the client (by the middleware).
|
something has been written to the client (by the plugin).
|
||||||
|
|
||||||
## Hooking It Up
|
## Hooking It Up
|
||||||
|
|
||||||
See a couple of blog posts on how to write and add middleware to CoreDNS:
|
See a couple of blog posts on how to write and add plugin to CoreDNS:
|
||||||
|
|
||||||
* <https://blog.coredns.io/2017/03/01/how-to-add-middleware-to-coredns/>
|
* <https://blog.coredns.io/2017/03/01/how-to-add-plugin-to-coredns/>
|
||||||
* <https://blog.coredns.io/2016/12/19/writing-middleware-for-coredns/>, slightly older, but useful.
|
* <https://blog.coredns.io/2016/12/19/writing-plugin-for-coredns/>, slightly older, but useful.
|
||||||
|
|
||||||
## Metrics
|
## Metrics
|
||||||
|
|
||||||
When exporting metrics the *Namespace* should be `middleware.Namespace` (="coredns"), and the
|
When exporting metrics the *Namespace* should be `plugin.Namespace` (="coredns"), and the
|
||||||
*Subsystem* should be the name of the middleware. The README.md for the middleware should then
|
*Subsystem* should be the name of the plugin. The README.md for the plugin should then
|
||||||
also contain a *Metrics* section detailing the metrics. If the middleware supports dynamic health
|
also contain a *Metrics* section detailing the metrics. If the plugin supports dynamic health
|
||||||
reporting it should also have *Health* section detailing on its inner workings.
|
reporting it should also have *Health* section detailing on its inner workings.
|
||||||
|
|
||||||
## Documentation
|
## Documentation
|
||||||
|
|
||||||
Each middleware should have a README.md explaining what the middleware does and how it is
|
Each plugin should have a README.md explaining what the plugin does and how it is
|
||||||
configured. The file should have the following layout:
|
configured. The file should have the following layout:
|
||||||
|
|
||||||
* Title: use the middleware's name
|
* Title: use the plugin's name
|
||||||
* Subsection titled: "Syntax"
|
* Subsection titled: "Syntax"
|
||||||
* Subsection titled: "Examples"
|
* Subsection titled: "Examples"
|
||||||
|
|
||||||
|
@ -58,7 +58,7 @@ More sections are of course possible.
|
||||||
|
|
||||||
We use the Unix manual page style:
|
We use the Unix manual page style:
|
||||||
|
|
||||||
* The name of middleware in the running text should be italic: *middleware*.
|
* The name of plugin in the running text should be italic: *plugin*.
|
||||||
* all CAPITAL: user supplied argument, in the running text references this use strong text: `**`:
|
* all CAPITAL: user supplied argument, in the running text references this use strong text: `**`:
|
||||||
**EXAMPLE**.
|
**EXAMPLE**.
|
||||||
* Optional text: in block quotes: `[optional]`.
|
* Optional text: in block quotes: `[optional]`.
|
||||||
|
@ -72,8 +72,8 @@ standard domain names created for this purpose.
|
||||||
|
|
||||||
## Fallthrough
|
## Fallthrough
|
||||||
|
|
||||||
In a perfect world the following would be true for middleware: "Either you are responsible for
|
In a perfect world the following would be true for plugin: "Either you are responsible for
|
||||||
a zone or not". If the answer is "not", the middleware should call the next middleware in the chain.
|
a zone or not". If the answer is "not", the plugin should call the next plugin in the chain.
|
||||||
If "yes" it should handle *all* names that fall in this zone and the names below - i.e. it should
|
If "yes" it should handle *all* names that fall in this zone and the names below - i.e. it should
|
||||||
handle the entire domain.
|
handle the entire domain.
|
||||||
|
|
||||||
|
@ -82,24 +82,24 @@ handle the entire domain.
|
||||||
file example.org db.example
|
file example.org db.example
|
||||||
}
|
}
|
||||||
~~~
|
~~~
|
||||||
In this example the *file* middleware is handling all names below (and including) `example.org`. If
|
In this example the *file* plugin is handling all names below (and including) `example.org`. If
|
||||||
a query comes in that is not a subdomain (or equal to) `example.org` the next middleware is called.
|
a query comes in that is not a subdomain (or equal to) `example.org` the next plugin is called.
|
||||||
|
|
||||||
Now, the world isn't perfect, and there are good reasons to "fallthrough" to the next middlware,
|
Now, the world isn't perfect, and there are good reasons to "fallthrough" to the next middlware,
|
||||||
meaning a middleware is only responsible for a subset of names within the zone. The first of these
|
meaning a plugin is only responsible for a subset of names within the zone. The first of these
|
||||||
to appear was the *reverse* middleware that synthesis PTR and A/AAAA responses (useful with IPv6).
|
to appear was the *reverse* plugin that synthesis PTR and A/AAAA responses (useful with IPv6).
|
||||||
|
|
||||||
The nature of the *reverse* middleware is such that it only deals with A,AAAA and PTR and then only
|
The nature of the *reverse* plugin is such that it only deals with A,AAAA and PTR and then only
|
||||||
for a subset of the names. Ideally you would want to layer *reverse* **in front off** another
|
for a subset of the names. Ideally you would want to layer *reverse* **in front off** another
|
||||||
middleware such as *file* or *auto* (or even *proxy*). This means *reverse* handles some special
|
plugin such as *file* or *auto* (or even *proxy*). This means *reverse* handles some special
|
||||||
reverse cases and **all other** request are handled by the backing middleware. This is exactly what
|
reverse cases and **all other** request are handled by the backing plugin. This is exactly what
|
||||||
"fallthrough" does. To keep things explicit we've opted that middlewares implement such behavior
|
"fallthrough" does. To keep things explicit we've opted that plugins implement such behavior
|
||||||
should implement a `fallthrough` keyword.
|
should implement a `fallthrough` keyword.
|
||||||
|
|
||||||
### Example Fallthrough Usage
|
### Example Fallthrough Usage
|
||||||
|
|
||||||
The following Corefile example, sets up the *reverse* middleware, but disables fallthrough. It
|
The following Corefile example, sets up the *reverse* plugin, but disables fallthrough. It
|
||||||
also defines a zonefile for use with the *file* middleware for other names in the `compute.internal`.
|
also defines a zonefile for use with the *file* plugin for other names in the `compute.internal`.
|
||||||
|
|
||||||
~~~ txt
|
~~~ txt
|
||||||
arpa compute.internal {
|
arpa compute.internal {
|
||||||
|
@ -136,13 +136,13 @@ compute.internal. 3600 IN MX 10 mx.compute.internal.
|
||||||
|
|
||||||
## Qualifying for main repo
|
## Qualifying for main repo
|
||||||
|
|
||||||
Middleware for CoreDNS can live out-of-tree, `middleware.cfg` defaults to CoreDNS' repo but other
|
Middleware for CoreDNS can live out-of-tree, `plugin.cfg` defaults to CoreDNS' repo but other
|
||||||
repos work just as well. So when do we consider the inclusion of a new middleware in the main repo?
|
repos work just as well. So when do we consider the inclusion of a new plugin in the main repo?
|
||||||
|
|
||||||
* First, the middleware should be useful for other people. "Useful" is a subjective term. We will
|
* First, the plugin should be useful for other people. "Useful" is a subjective term. We will
|
||||||
probably need to further refine this.
|
probably need to further refine this.
|
||||||
* It should be sufficiently different from other middleware to warrant inclusion.
|
* It should be sufficiently different from other plugin to warrant inclusion.
|
||||||
* Current internet standards need be supported: IPv4 and IPv6, so A and AAAA records should be
|
* Current internet standards need be supported: IPv4 and IPv6, so A and AAAA records should be
|
||||||
handled (if your middleware is in the business of dealing with address records that is).
|
handled (if your plugin is in the business of dealing with address records that is).
|
||||||
* It must have tests.
|
* It must have tests.
|
||||||
* It must have a README.md for documentation.
|
* It must have a README.md for documentation.
|
|
@ -3,7 +3,7 @@
|
||||||
*auto* enables serving zone data from an RFC 1035-style master file which is automatically picked
|
*auto* enables serving zone data from an RFC 1035-style master file which is automatically picked
|
||||||
up from disk.
|
up from disk.
|
||||||
|
|
||||||
The *auto* middleware is used for an "old-style" DNS server. It serves from a preloaded file that exists
|
The *auto* plugin is used for an "old-style" DNS server. It serves from a preloaded file that exists
|
||||||
on disk. If the zone file contains signatures (i.e. is signed, i.e. DNSSEC) correct DNSSEC answers
|
on disk. If the zone file contains signatures (i.e. is signed, i.e. DNSSEC) correct DNSSEC answers
|
||||||
are returned. Only NSEC is supported! If you use this setup *you* are responsible for resigning the
|
are returned. Only NSEC is supported! If you use this setup *you* are responsible for resigning the
|
||||||
zonefile. New zones or changed zone are automatically picked up from disk.
|
zonefile. New zones or changed zone are automatically picked up from disk.
|
||||||
|
@ -34,7 +34,7 @@ are used.
|
||||||
pointing to external names. **ADDRESS** can be an IP address, and IP:port or a string pointing to
|
pointing to external names. **ADDRESS** can be an IP address, and IP:port or a string pointing to
|
||||||
a file that is structured as /etc/resolv.conf.
|
a file that is structured as /etc/resolv.conf.
|
||||||
|
|
||||||
All directives from the *file* middleware are supported. Note that *auto* will load all zones found,
|
All directives from the *file* plugin are supported. Note that *auto* will load all zones found,
|
||||||
even though the directive might only receive queries for a specific zone. I.e:
|
even though the directive might only receive queries for a specific zone. I.e:
|
||||||
|
|
||||||
~~~
|
~~~
|
|
@ -5,10 +5,10 @@ import (
|
||||||
"regexp"
|
"regexp"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/coredns/coredns/middleware"
|
"github.com/coredns/coredns/plugin"
|
||||||
"github.com/coredns/coredns/middleware/file"
|
"github.com/coredns/coredns/plugin/file"
|
||||||
"github.com/coredns/coredns/middleware/metrics"
|
"github.com/coredns/coredns/plugin/metrics"
|
||||||
"github.com/coredns/coredns/middleware/proxy"
|
"github.com/coredns/coredns/plugin/proxy"
|
||||||
"github.com/coredns/coredns/request"
|
"github.com/coredns/coredns/request"
|
||||||
|
|
||||||
"github.com/miekg/dns"
|
"github.com/miekg/dns"
|
||||||
|
@ -18,7 +18,7 @@ import (
|
||||||
type (
|
type (
|
||||||
// Auto holds the zones and the loader configuration for automatically loading zones.
|
// Auto holds the zones and the loader configuration for automatically loading zones.
|
||||||
Auto struct {
|
Auto struct {
|
||||||
Next middleware.Handler
|
Next plugin.Handler
|
||||||
*Zones
|
*Zones
|
||||||
|
|
||||||
metrics *metrics.Metrics
|
metrics *metrics.Metrics
|
||||||
|
@ -39,7 +39,7 @@ type (
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
// ServeDNS implements the middleware.Handle interface.
|
// ServeDNS implements the plugin.Handle interface.
|
||||||
func (a Auto) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (int, error) {
|
func (a Auto) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (int, error) {
|
||||||
state := request.Request{W: w, Req: r}
|
state := request.Request{W: w, Req: r}
|
||||||
qname := state.Name()
|
qname := state.Name()
|
||||||
|
@ -47,13 +47,13 @@ func (a Auto) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (i
|
||||||
// TODO(miek): match the qname better in the map
|
// TODO(miek): match the qname better in the map
|
||||||
|
|
||||||
// Precheck with the origins, i.e. are we allowed to looks here.
|
// Precheck with the origins, i.e. are we allowed to looks here.
|
||||||
zone := middleware.Zones(a.Zones.Origins()).Matches(qname)
|
zone := plugin.Zones(a.Zones.Origins()).Matches(qname)
|
||||||
if zone == "" {
|
if zone == "" {
|
||||||
return middleware.NextOrFailure(a.Name(), a.Next, ctx, w, r)
|
return plugin.NextOrFailure(a.Name(), a.Next, ctx, w, r)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now the real zone.
|
// Now the real zone.
|
||||||
zone = middleware.Zones(a.Zones.Names()).Matches(qname)
|
zone = plugin.Zones(a.Zones.Names()).Matches(qname)
|
||||||
|
|
||||||
a.Zones.RLock()
|
a.Zones.RLock()
|
||||||
z, ok := a.Zones.Z[zone]
|
z, ok := a.Zones.Z[zone]
|
|
@ -9,11 +9,11 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/coredns/coredns/core/dnsserver"
|
"github.com/coredns/coredns/core/dnsserver"
|
||||||
"github.com/coredns/coredns/middleware"
|
"github.com/coredns/coredns/plugin"
|
||||||
"github.com/coredns/coredns/middleware/file"
|
"github.com/coredns/coredns/plugin/file"
|
||||||
"github.com/coredns/coredns/middleware/metrics"
|
"github.com/coredns/coredns/plugin/metrics"
|
||||||
"github.com/coredns/coredns/middleware/pkg/dnsutil"
|
"github.com/coredns/coredns/plugin/pkg/dnsutil"
|
||||||
"github.com/coredns/coredns/middleware/proxy"
|
"github.com/coredns/coredns/plugin/proxy"
|
||||||
|
|
||||||
"github.com/mholt/caddy"
|
"github.com/mholt/caddy"
|
||||||
)
|
)
|
||||||
|
@ -28,7 +28,7 @@ func init() {
|
||||||
func setup(c *caddy.Controller) error {
|
func setup(c *caddy.Controller) error {
|
||||||
a, err := autoParse(c)
|
a, err := autoParse(c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return middleware.Error("auto", err)
|
return plugin.Error("auto", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
c.OnStartup(func() error {
|
c.OnStartup(func() error {
|
||||||
|
@ -67,7 +67,7 @@ func setup(c *caddy.Controller) error {
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
|
|
||||||
dnsserver.GetConfig(c).AddMiddleware(func(next middleware.Handler) middleware.Handler {
|
dnsserver.GetConfig(c).AddPlugin(func(next plugin.Handler) plugin.Handler {
|
||||||
a.Next = next
|
a.Next = next
|
||||||
return a
|
return a
|
||||||
})
|
})
|
||||||
|
@ -93,7 +93,7 @@ func autoParse(c *caddy.Controller) (Auto, error) {
|
||||||
a.Zones.origins = args
|
a.Zones.origins = args
|
||||||
}
|
}
|
||||||
for i := range a.Zones.origins {
|
for i := range a.Zones.origins {
|
||||||
a.Zones.origins[i] = middleware.Host(a.Zones.origins[i]).Normalize()
|
a.Zones.origins[i] = plugin.Host(a.Zones.origins[i]).Normalize()
|
||||||
}
|
}
|
||||||
|
|
||||||
for c.NextBlock() {
|
for c.NextBlock() {
|
|
@ -7,7 +7,7 @@ import (
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
|
||||||
"github.com/coredns/coredns/middleware/file"
|
"github.com/coredns/coredns/plugin/file"
|
||||||
|
|
||||||
"github.com/miekg/dns"
|
"github.com/miekg/dns"
|
||||||
)
|
)
|
|
@ -4,7 +4,7 @@ package auto
|
||||||
import (
|
import (
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/coredns/coredns/middleware/file"
|
"github.com/coredns/coredns/plugin/file"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Zones maps zone names to a *Zone. This keep track of what we zones we have loaded at
|
// Zones maps zone names to a *Zone. This keep track of what we zones we have loaded at
|
|
@ -1,6 +1,6 @@
|
||||||
# autopath
|
# autopath
|
||||||
|
|
||||||
The *autopath* middleware allows CoreDNS to perform server side search path completion.
|
The *autopath* plugin allows CoreDNS to perform server side search path completion.
|
||||||
If it sees a query that matches the first element of the configured search path, *autopath* will
|
If it sees a query that matches the first element of the configured search path, *autopath* will
|
||||||
follow the chain of search path elements and returns the first reply that is not NXDOMAIN.
|
follow the chain of search path elements and returns the first reply that is not NXDOMAIN.
|
||||||
On any failures the original reply is returned.
|
On any failures the original reply is returned.
|
||||||
|
@ -16,10 +16,10 @@ autopath [ZONE..] RESOLV-CONF
|
||||||
|
|
||||||
* **ZONES** zones *autopath* should be authoritative for.
|
* **ZONES** zones *autopath* should be authoritative for.
|
||||||
* **RESOLV-CONF** points to a `resolv.conf` like file or uses a special syntax to point to another
|
* **RESOLV-CONF** points to a `resolv.conf` like file or uses a special syntax to point to another
|
||||||
middleware. For instance `@kubernetes`, will call out to the kubernetes middleware (for each
|
plugin. For instance `@kubernetes`, will call out to the kubernetes plugin (for each
|
||||||
query) to retrieve the search list it should use.
|
query) to retrieve the search list it should use.
|
||||||
|
|
||||||
Currently the following set of middleware has implemented *autopath*:
|
Currently the following set of plugin has implemented *autopath*:
|
||||||
|
|
||||||
* *kubernetes*
|
* *kubernetes*
|
||||||
* *erratic*
|
* *erratic*
|
||||||
|
@ -37,9 +37,9 @@ Use `my-resolv.conf` as the file to get the search path from. This file only nee
|
||||||
autopath @kubernetes
|
autopath @kubernetes
|
||||||
~~~
|
~~~
|
||||||
|
|
||||||
Use the search path dynamically retrieved from the kubernetes middleware.
|
Use the search path dynamically retrieved from the kubernetes plugin.
|
||||||
|
|
||||||
## Bugs
|
## Bugs
|
||||||
|
|
||||||
When the *cache* middleware is enabled it is possible for pods in different namespaces to get the
|
When the *cache* plugin is enabled it is possible for pods in different namespaces to get the
|
||||||
same answer.
|
same answer.
|
|
@ -4,7 +4,7 @@ client's search path resolution by performing these lookups on the server...
|
||||||
|
|
||||||
The server has a copy (via AutoPathFunc) of the client's search path and on
|
The server has a copy (via AutoPathFunc) of the client's search path and on
|
||||||
receiving a query it first establish if the suffix matches the FIRST configured
|
receiving a query it first establish if the suffix matches the FIRST configured
|
||||||
element. If no match can be found the query will be forwarded up the middleware
|
element. If no match can be found the query will be forwarded up the plugin
|
||||||
chain without interference (iff 'fallthrough' has been set).
|
chain without interference (iff 'fallthrough' has been set).
|
||||||
|
|
||||||
If the query is deemed to fall in the search path the server will perform the
|
If the query is deemed to fall in the search path the server will perform the
|
||||||
|
@ -34,23 +34,23 @@ package autopath
|
||||||
import (
|
import (
|
||||||
"log"
|
"log"
|
||||||
|
|
||||||
"github.com/coredns/coredns/middleware"
|
"github.com/coredns/coredns/plugin"
|
||||||
"github.com/coredns/coredns/middleware/pkg/dnsutil"
|
"github.com/coredns/coredns/plugin/pkg/dnsutil"
|
||||||
"github.com/coredns/coredns/middleware/pkg/nonwriter"
|
"github.com/coredns/coredns/plugin/pkg/nonwriter"
|
||||||
"github.com/coredns/coredns/request"
|
"github.com/coredns/coredns/request"
|
||||||
|
|
||||||
"github.com/miekg/dns"
|
"github.com/miekg/dns"
|
||||||
"golang.org/x/net/context"
|
"golang.org/x/net/context"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Func defines the function middleware should implement to return a search
|
// Func defines the function plugin should implement to return a search
|
||||||
// path to the autopath middleware. The last element of the slice must be the empty string.
|
// path to the autopath plugin. The last element of the slice must be the empty string.
|
||||||
// If Func returns a nil slice, no autopathing will be done.
|
// If Func returns a nil slice, no autopathing will be done.
|
||||||
type Func func(request.Request) []string
|
type Func func(request.Request) []string
|
||||||
|
|
||||||
// AutoPath perform autopath: service side search path completion.
|
// AutoPath perform autopath: service side search path completion.
|
||||||
type AutoPath struct {
|
type AutoPath struct {
|
||||||
Next middleware.Handler
|
Next plugin.Handler
|
||||||
Zones []string
|
Zones []string
|
||||||
|
|
||||||
// Search always includes "" as the last element, so we try the base query with out any search paths added as well.
|
// Search always includes "" as the last element, so we try the base query with out any search paths added as well.
|
||||||
|
@ -58,13 +58,13 @@ type AutoPath struct {
|
||||||
searchFunc Func
|
searchFunc Func
|
||||||
}
|
}
|
||||||
|
|
||||||
// ServeDNS implements the middleware.Handle interface.
|
// ServeDNS implements the plugin.Handle interface.
|
||||||
func (a *AutoPath) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (int, error) {
|
func (a *AutoPath) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (int, error) {
|
||||||
state := request.Request{W: w, Req: r}
|
state := request.Request{W: w, Req: r}
|
||||||
|
|
||||||
zone := middleware.Zones(a.Zones).Matches(state.Name())
|
zone := plugin.Zones(a.Zones).Matches(state.Name())
|
||||||
if zone == "" {
|
if zone == "" {
|
||||||
return middleware.NextOrFailure(a.Name(), a.Next, ctx, w, r)
|
return plugin.NextOrFailure(a.Name(), a.Next, ctx, w, r)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if autopath should be done, searchFunc takes precedence over the local configured search path.
|
// Check if autopath should be done, searchFunc takes precedence over the local configured search path.
|
||||||
|
@ -77,11 +77,11 @@ func (a *AutoPath) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Ms
|
||||||
|
|
||||||
if len(searchpath) == 0 {
|
if len(searchpath) == 0 {
|
||||||
log.Printf("[WARNING] No search path available for autopath")
|
log.Printf("[WARNING] No search path available for autopath")
|
||||||
return middleware.NextOrFailure(a.Name(), a.Next, ctx, w, r)
|
return plugin.NextOrFailure(a.Name(), a.Next, ctx, w, r)
|
||||||
}
|
}
|
||||||
|
|
||||||
if !firstInSearchPath(state.Name(), searchpath) {
|
if !firstInSearchPath(state.Name(), searchpath) {
|
||||||
return middleware.NextOrFailure(a.Name(), a.Next, ctx, w, r)
|
return plugin.NextOrFailure(a.Name(), a.Next, ctx, w, r)
|
||||||
}
|
}
|
||||||
|
|
||||||
origQName := state.QName()
|
origQName := state.QName()
|
||||||
|
@ -104,7 +104,7 @@ func (a *AutoPath) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Ms
|
||||||
ar.Question[0].Name = newQName
|
ar.Question[0].Name = newQName
|
||||||
nw := nonwriter.New(w)
|
nw := nonwriter.New(w)
|
||||||
|
|
||||||
rcode, err := middleware.NextOrFailure(a.Name(), a.Next, ctx, nw, ar)
|
rcode, err := plugin.NextOrFailure(a.Name(), a.Next, ctx, nw, ar)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// Return now - not sure if this is the best. We should also check if the write has happened.
|
// Return now - not sure if this is the best. We should also check if the write has happened.
|
||||||
return rcode, err
|
return rcode, err
|
||||||
|
@ -115,7 +115,7 @@ func (a *AutoPath) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Ms
|
||||||
firstErr = err
|
firstErr = err
|
||||||
}
|
}
|
||||||
|
|
||||||
if !middleware.ClientWrite(rcode) {
|
if !plugin.ClientWrite(rcode) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -131,7 +131,7 @@ func (a *AutoPath) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Ms
|
||||||
return rcode, err
|
return rcode, err
|
||||||
|
|
||||||
}
|
}
|
||||||
if middleware.ClientWrite(firstRcode) {
|
if plugin.ClientWrite(firstRcode) {
|
||||||
w.WriteMsg(firstReply)
|
w.WriteMsg(firstReply)
|
||||||
}
|
}
|
||||||
return firstRcode, firstErr
|
return firstRcode, firstErr
|
|
@ -3,9 +3,9 @@ package autopath
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/coredns/coredns/middleware"
|
"github.com/coredns/coredns/plugin"
|
||||||
"github.com/coredns/coredns/middleware/pkg/dnsrecorder"
|
"github.com/coredns/coredns/plugin/pkg/dnsrecorder"
|
||||||
"github.com/coredns/coredns/middleware/test"
|
"github.com/coredns/coredns/plugin/test"
|
||||||
|
|
||||||
"github.com/miekg/dns"
|
"github.com/miekg/dns"
|
||||||
"golang.org/x/net/context"
|
"golang.org/x/net/context"
|
||||||
|
@ -100,7 +100,7 @@ func TestAutoPathNoAnswer(t *testing.T) {
|
||||||
t.Errorf("expected no error, got %v\n", err)
|
t.Errorf("expected no error, got %v\n", err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if middleware.ClientWrite(rcode) {
|
if plugin.ClientWrite(rcode) {
|
||||||
t.Fatalf("expected no client write, got one for rcode %d", rcode)
|
t.Fatalf("expected no client write, got one for rcode %d", rcode)
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -4,9 +4,9 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/coredns/coredns/core/dnsserver"
|
"github.com/coredns/coredns/core/dnsserver"
|
||||||
"github.com/coredns/coredns/middleware"
|
"github.com/coredns/coredns/plugin"
|
||||||
"github.com/coredns/coredns/middleware/erratic"
|
"github.com/coredns/coredns/plugin/erratic"
|
||||||
"github.com/coredns/coredns/middleware/kubernetes"
|
"github.com/coredns/coredns/plugin/kubernetes"
|
||||||
|
|
||||||
"github.com/mholt/caddy"
|
"github.com/mholt/caddy"
|
||||||
"github.com/miekg/dns"
|
"github.com/miekg/dns"
|
||||||
|
@ -23,10 +23,10 @@ func init() {
|
||||||
func setup(c *caddy.Controller) error {
|
func setup(c *caddy.Controller) error {
|
||||||
ap, mw, err := autoPathParse(c)
|
ap, mw, err := autoPathParse(c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return middleware.Error("autopath", err)
|
return plugin.Error("autopath", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Do this in OnStartup, so all middleware has been initialized.
|
// Do this in OnStartup, so all plugin has been initialized.
|
||||||
c.OnStartup(func() error {
|
c.OnStartup(func() error {
|
||||||
m := dnsserver.GetConfig(c).Handler(mw)
|
m := dnsserver.GetConfig(c).Handler(mw)
|
||||||
if m == nil {
|
if m == nil {
|
||||||
|
@ -41,7 +41,7 @@ func setup(c *caddy.Controller) error {
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
|
|
||||||
dnsserver.GetConfig(c).AddMiddleware(func(next middleware.Handler) middleware.Handler {
|
dnsserver.GetConfig(c).AddPlugin(func(next plugin.Handler) plugin.Handler {
|
||||||
ap.Next = next
|
ap.Next = next
|
||||||
return ap
|
return ap
|
||||||
})
|
})
|
||||||
|
@ -49,7 +49,7 @@ func setup(c *caddy.Controller) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// allowedMiddleware has a list of middleware that can be used by autopath.
|
// allowedMiddleware has a list of plugin that can be used by autopath.
|
||||||
var allowedMiddleware = map[string]bool{
|
var allowedMiddleware = map[string]bool{
|
||||||
"@kubernetes": true,
|
"@kubernetes": true,
|
||||||
"@erratic": true,
|
"@erratic": true,
|
||||||
|
@ -77,7 +77,7 @@ func autoPathParse(c *caddy.Controller) (*AutoPath, string, error) {
|
||||||
return ap, "", fmt.Errorf("failed to parse %q: %v", resolv, err)
|
return ap, "", fmt.Errorf("failed to parse %q: %v", resolv, err)
|
||||||
}
|
}
|
||||||
ap.search = rc.Search
|
ap.search = rc.Search
|
||||||
middleware.Zones(ap.search).Normalize()
|
plugin.Zones(ap.search).Normalize()
|
||||||
ap.search = append(ap.search, "") // sentinal value as demanded.
|
ap.search = append(ap.search, "") // sentinal value as demanded.
|
||||||
}
|
}
|
||||||
ap.Zones = zoneAndresolv[:len(zoneAndresolv)-1]
|
ap.Zones = zoneAndresolv[:len(zoneAndresolv)-1]
|
||||||
|
@ -86,7 +86,7 @@ func autoPathParse(c *caddy.Controller) (*AutoPath, string, error) {
|
||||||
copy(ap.Zones, c.ServerBlockKeys)
|
copy(ap.Zones, c.ServerBlockKeys)
|
||||||
}
|
}
|
||||||
for i, str := range ap.Zones {
|
for i, str := range ap.Zones {
|
||||||
ap.Zones[i] = middleware.Host(str).Normalize()
|
ap.Zones[i] = plugin.Host(str).Normalize()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ap, mw, nil
|
return ap, mw, nil
|
|
@ -6,7 +6,7 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/coredns/coredns/middleware/test"
|
"github.com/coredns/coredns/plugin/test"
|
||||||
|
|
||||||
"github.com/mholt/caddy"
|
"github.com/mholt/caddy"
|
||||||
)
|
)
|
||||||
|
@ -22,7 +22,7 @@ func TestSetupAutoPath(t *testing.T) {
|
||||||
input string
|
input string
|
||||||
shouldErr bool
|
shouldErr bool
|
||||||
expectedZone string
|
expectedZone string
|
||||||
expectedMw string // expected middleware.
|
expectedMw string // expected plugin.
|
||||||
expectedSearch []string // expected search path
|
expectedSearch []string // expected search path
|
||||||
expectedErrContent string // substring from the expected error. Empty for positive cases.
|
expectedErrContent string // substring from the expected error. Empty for positive cases.
|
||||||
}{
|
}{
|
|
@ -1,7 +1,7 @@
|
||||||
package middleware
|
package plugin
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/coredns/coredns/middleware/etcd/msg"
|
"github.com/coredns/coredns/plugin/etcd/msg"
|
||||||
"github.com/coredns/coredns/request"
|
"github.com/coredns/coredns/request"
|
||||||
|
|
||||||
"github.com/miekg/dns"
|
"github.com/miekg/dns"
|
|
@ -1,4 +1,4 @@
|
||||||
package middleware
|
package plugin
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
@ -6,8 +6,8 @@ import (
|
||||||
"net"
|
"net"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/coredns/coredns/middleware/etcd/msg"
|
"github.com/coredns/coredns/plugin/etcd/msg"
|
||||||
"github.com/coredns/coredns/middleware/pkg/dnsutil"
|
"github.com/coredns/coredns/plugin/pkg/dnsutil"
|
||||||
"github.com/coredns/coredns/request"
|
"github.com/coredns/coredns/request"
|
||||||
|
|
||||||
"github.com/miekg/dns"
|
"github.com/miekg/dns"
|
|
@ -5,7 +5,7 @@ import (
|
||||||
"net"
|
"net"
|
||||||
|
|
||||||
"github.com/coredns/coredns/core/dnsserver"
|
"github.com/coredns/coredns/core/dnsserver"
|
||||||
"github.com/coredns/coredns/middleware"
|
"github.com/coredns/coredns/plugin"
|
||||||
|
|
||||||
"github.com/mholt/caddy"
|
"github.com/mholt/caddy"
|
||||||
)
|
)
|
||||||
|
@ -14,11 +14,11 @@ func setupBind(c *caddy.Controller) error {
|
||||||
config := dnsserver.GetConfig(c)
|
config := dnsserver.GetConfig(c)
|
||||||
for c.Next() {
|
for c.Next() {
|
||||||
if !c.Args(&config.ListenHost) {
|
if !c.Args(&config.ListenHost) {
|
||||||
return middleware.Error("bind", c.ArgErr())
|
return plugin.Error("bind", c.ArgErr())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if net.ParseIP(config.ListenHost) == nil {
|
if net.ParseIP(config.ListenHost) == nil {
|
||||||
return middleware.Error("bind", fmt.Errorf("not a valid IP address: %s", config.ListenHost))
|
return plugin.Error("bind", fmt.Errorf("not a valid IP address: %s", config.ListenHost))
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
|
@ -7,17 +7,17 @@ import (
|
||||||
"log"
|
"log"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/coredns/coredns/middleware"
|
"github.com/coredns/coredns/plugin"
|
||||||
"github.com/coredns/coredns/middleware/pkg/cache"
|
"github.com/coredns/coredns/plugin/pkg/cache"
|
||||||
"github.com/coredns/coredns/middleware/pkg/response"
|
"github.com/coredns/coredns/plugin/pkg/response"
|
||||||
|
|
||||||
"github.com/miekg/dns"
|
"github.com/miekg/dns"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Cache is middleware that looks up responses in a cache and caches replies.
|
// Cache is plugin that looks up responses in a cache and caches replies.
|
||||||
// It has a success and a denial of existence cache.
|
// It has a success and a denial of existence cache.
|
||||||
type Cache struct {
|
type Cache struct {
|
||||||
Next middleware.Handler
|
Next plugin.Handler
|
||||||
Zones []string
|
Zones []string
|
||||||
|
|
||||||
ncache *cache.Cache
|
ncache *cache.Cache
|
|
@ -8,10 +8,10 @@ import (
|
||||||
|
|
||||||
"golang.org/x/net/context"
|
"golang.org/x/net/context"
|
||||||
|
|
||||||
"github.com/coredns/coredns/middleware"
|
"github.com/coredns/coredns/plugin"
|
||||||
"github.com/coredns/coredns/middleware/pkg/cache"
|
"github.com/coredns/coredns/plugin/pkg/cache"
|
||||||
"github.com/coredns/coredns/middleware/pkg/response"
|
"github.com/coredns/coredns/plugin/pkg/response"
|
||||||
"github.com/coredns/coredns/middleware/test"
|
"github.com/coredns/coredns/plugin/test"
|
||||||
|
|
||||||
"github.com/miekg/dns"
|
"github.com/miekg/dns"
|
||||||
)
|
)
|
||||||
|
@ -175,7 +175,7 @@ func TestCache(t *testing.T) {
|
||||||
|
|
||||||
crr.set(m, k, mt, c.pttl)
|
crr.set(m, k, mt, c.pttl)
|
||||||
|
|
||||||
name := middleware.Name(m.Question[0].Name).Normalize()
|
name := plugin.Name(m.Question[0].Name).Normalize()
|
||||||
qtype := m.Question[0].Qtype
|
qtype := m.Question[0].Qtype
|
||||||
|
|
||||||
i, _ := c.get(time.Now().UTC(), name, qtype, do)
|
i, _ := c.get(time.Now().UTC(), name, qtype, do)
|
||||||
|
@ -235,8 +235,8 @@ func BenchmarkCacheResponse(b *testing.B) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func BackendHandler() middleware.Handler {
|
func BackendHandler() plugin.Handler {
|
||||||
return middleware.HandlerFunc(func(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (int, error) {
|
return plugin.HandlerFunc(func(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (int, error) {
|
||||||
m := new(dns.Msg)
|
m := new(dns.Msg)
|
||||||
m.SetReply(r)
|
m.SetReply(r)
|
||||||
m.Response = true
|
m.Response = true
|
|
@ -3,7 +3,7 @@ package cache
|
||||||
import (
|
import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/coredns/coredns/middleware"
|
"github.com/coredns/coredns/plugin"
|
||||||
"github.com/coredns/coredns/request"
|
"github.com/coredns/coredns/request"
|
||||||
|
|
||||||
"github.com/miekg/dns"
|
"github.com/miekg/dns"
|
||||||
|
@ -11,13 +11,13 @@ import (
|
||||||
"golang.org/x/net/context"
|
"golang.org/x/net/context"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ServeDNS implements the middleware.Handler interface.
|
// ServeDNS implements the plugin.Handler interface.
|
||||||
func (c *Cache) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (int, error) {
|
func (c *Cache) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (int, error) {
|
||||||
state := request.Request{W: w, Req: r}
|
state := request.Request{W: w, Req: r}
|
||||||
|
|
||||||
qname := state.Name()
|
qname := state.Name()
|
||||||
qtype := state.QType()
|
qtype := state.QType()
|
||||||
zone := middleware.Zones(c.Zones).Matches(qname)
|
zone := plugin.Zones(c.Zones).Matches(qname)
|
||||||
if zone == "" {
|
if zone == "" {
|
||||||
return c.Next.ServeDNS(ctx, w, r)
|
return c.Next.ServeDNS(ctx, w, r)
|
||||||
}
|
}
|
||||||
|
@ -46,7 +46,7 @@ func (c *Cache) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg)
|
||||||
// that we've gathered sofar. See we copy the frequencies info back
|
// that we've gathered sofar. See we copy the frequencies info back
|
||||||
// into the new item that was stored in the cache.
|
// into the new item that was stored in the cache.
|
||||||
prr := &ResponseWriter{ResponseWriter: w, Cache: c, prefetch: true}
|
prr := &ResponseWriter{ResponseWriter: w, Cache: c, prefetch: true}
|
||||||
middleware.NextOrFailure(c.Name(), c.Next, ctx, prr, r)
|
plugin.NextOrFailure(c.Name(), c.Next, ctx, prr, r)
|
||||||
|
|
||||||
if i1, _ := c.get(now, qname, qtype, do); i1 != nil {
|
if i1, _ := c.get(now, qname, qtype, do); i1 != nil {
|
||||||
i1.Freq.Reset(now, i.Freq.Hits())
|
i1.Freq.Reset(now, i.Freq.Hits())
|
||||||
|
@ -57,7 +57,7 @@ func (c *Cache) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
crr := &ResponseWriter{ResponseWriter: w, Cache: c}
|
crr := &ResponseWriter{ResponseWriter: w, Cache: c}
|
||||||
return middleware.NextOrFailure(c.Name(), c.Next, ctx, crr, r)
|
return plugin.NextOrFailure(c.Name(), c.Next, ctx, crr, r)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Name implements the Handler interface.
|
// Name implements the Handler interface.
|
||||||
|
@ -81,28 +81,28 @@ func (c *Cache) get(now time.Time, qname string, qtype uint16, do bool) (*item,
|
||||||
|
|
||||||
var (
|
var (
|
||||||
cacheSize = prometheus.NewGaugeVec(prometheus.GaugeOpts{
|
cacheSize = prometheus.NewGaugeVec(prometheus.GaugeOpts{
|
||||||
Namespace: middleware.Namespace,
|
Namespace: plugin.Namespace,
|
||||||
Subsystem: subsystem,
|
Subsystem: subsystem,
|
||||||
Name: "size",
|
Name: "size",
|
||||||
Help: "The number of elements in the cache.",
|
Help: "The number of elements in the cache.",
|
||||||
}, []string{"type"})
|
}, []string{"type"})
|
||||||
|
|
||||||
cacheCapacity = prometheus.NewGaugeVec(prometheus.GaugeOpts{
|
cacheCapacity = prometheus.NewGaugeVec(prometheus.GaugeOpts{
|
||||||
Namespace: middleware.Namespace,
|
Namespace: plugin.Namespace,
|
||||||
Subsystem: subsystem,
|
Subsystem: subsystem,
|
||||||
Name: "capacity",
|
Name: "capacity",
|
||||||
Help: "The cache's capacity.",
|
Help: "The cache's capacity.",
|
||||||
}, []string{"type"})
|
}, []string{"type"})
|
||||||
|
|
||||||
cacheHits = prometheus.NewCounterVec(prometheus.CounterOpts{
|
cacheHits = prometheus.NewCounterVec(prometheus.CounterOpts{
|
||||||
Namespace: middleware.Namespace,
|
Namespace: plugin.Namespace,
|
||||||
Subsystem: subsystem,
|
Subsystem: subsystem,
|
||||||
Name: "hits_total",
|
Name: "hits_total",
|
||||||
Help: "The count of cache hits.",
|
Help: "The count of cache hits.",
|
||||||
}, []string{"type"})
|
}, []string{"type"})
|
||||||
|
|
||||||
cacheMisses = prometheus.NewCounter(prometheus.CounterOpts{
|
cacheMisses = prometheus.NewCounter(prometheus.CounterOpts{
|
||||||
Namespace: middleware.Namespace,
|
Namespace: plugin.Namespace,
|
||||||
Subsystem: subsystem,
|
Subsystem: subsystem,
|
||||||
Name: "misses_total",
|
Name: "misses_total",
|
||||||
Help: "The count of cache misses.",
|
Help: "The count of cache misses.",
|
|
@ -3,8 +3,8 @@ package cache
|
||||||
import (
|
import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/coredns/coredns/middleware/cache/freq"
|
"github.com/coredns/coredns/plugin/cache/freq"
|
||||||
"github.com/coredns/coredns/middleware/pkg/response"
|
"github.com/coredns/coredns/plugin/pkg/response"
|
||||||
"github.com/miekg/dns"
|
"github.com/miekg/dns"
|
||||||
)
|
)
|
||||||
|
|
|
@ -5,11 +5,11 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/coredns/coredns/middleware"
|
"github.com/coredns/coredns/plugin"
|
||||||
"github.com/coredns/coredns/middleware/pkg/cache"
|
"github.com/coredns/coredns/plugin/pkg/cache"
|
||||||
"github.com/coredns/coredns/middleware/pkg/dnsrecorder"
|
"github.com/coredns/coredns/plugin/pkg/dnsrecorder"
|
||||||
|
|
||||||
"github.com/coredns/coredns/middleware/test"
|
"github.com/coredns/coredns/plugin/test"
|
||||||
"github.com/miekg/dns"
|
"github.com/miekg/dns"
|
||||||
"golang.org/x/net/context"
|
"golang.org/x/net/context"
|
||||||
)
|
)
|
||||||
|
@ -36,8 +36,8 @@ func TestPrefetch(t *testing.T) {
|
||||||
c.ServeDNS(ctx, rec, req)
|
c.ServeDNS(ctx, rec, req)
|
||||||
}
|
}
|
||||||
|
|
||||||
func PrefetchHandler(t *testing.T, rcode int, err error) middleware.Handler {
|
func PrefetchHandler(t *testing.T, rcode int, err error) plugin.Handler {
|
||||||
return middleware.HandlerFunc(func(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (int, error) {
|
return plugin.HandlerFunc(func(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (int, error) {
|
||||||
m := new(dns.Msg)
|
m := new(dns.Msg)
|
||||||
m.SetQuestion("lowttl.example.org.", dns.TypeA)
|
m.SetQuestion("lowttl.example.org.", dns.TypeA)
|
||||||
m.Response = true
|
m.Response = true
|
|
@ -6,8 +6,8 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/coredns/coredns/core/dnsserver"
|
"github.com/coredns/coredns/core/dnsserver"
|
||||||
"github.com/coredns/coredns/middleware"
|
"github.com/coredns/coredns/plugin"
|
||||||
"github.com/coredns/coredns/middleware/pkg/cache"
|
"github.com/coredns/coredns/plugin/pkg/cache"
|
||||||
|
|
||||||
"github.com/mholt/caddy"
|
"github.com/mholt/caddy"
|
||||||
)
|
)
|
||||||
|
@ -22,9 +22,9 @@ func init() {
|
||||||
func setup(c *caddy.Controller) error {
|
func setup(c *caddy.Controller) error {
|
||||||
ca, err := cacheParse(c)
|
ca, err := cacheParse(c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return middleware.Error("cache", err)
|
return plugin.Error("cache", err)
|
||||||
}
|
}
|
||||||
dnsserver.GetConfig(c).AddMiddleware(func(next middleware.Handler) middleware.Handler {
|
dnsserver.GetConfig(c).AddPlugin(func(next plugin.Handler) plugin.Handler {
|
||||||
ca.Next = next
|
ca.Next = next
|
||||||
return ca
|
return ca
|
||||||
})
|
})
|
||||||
|
@ -155,7 +155,7 @@ func cacheParse(c *caddy.Controller) (*Cache, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := range origins {
|
for i := range origins {
|
||||||
origins[i] = middleware.Host(origins[i]).Normalize()
|
origins[i] = plugin.Host(origins[i]).Normalize()
|
||||||
}
|
}
|
||||||
|
|
||||||
ca.Zones = origins
|
ca.Zones = origins
|
|
@ -1,6 +1,6 @@
|
||||||
# chaos
|
# chaos
|
||||||
|
|
||||||
The *chaos* middleware allows CoreDNS to respond to TXT queries in the CH class.
|
The *chaos* plugin allows CoreDNS to respond to TXT queries in the CH class.
|
||||||
|
|
||||||
This is useful for retrieving version or author information from the server.
|
This is useful for retrieving version or author information from the server.
|
||||||
|
|
||||||
|
@ -13,7 +13,7 @@ chaos [VERSION] [AUTHORS...]
|
||||||
* **VERSION** is the version to return. Defaults to `CoreDNS-<version>`, if not set.
|
* **VERSION** is the version to return. Defaults to `CoreDNS-<version>`, if not set.
|
||||||
* **AUTHORS** is what authors to return. No default.
|
* **AUTHORS** is what authors to return. No default.
|
||||||
|
|
||||||
Note that you have to make sure that this middleware will get actual queries for the
|
Note that you have to make sure that this plugin will get actual queries for the
|
||||||
following zones: `version.bind`, `version.server`, `authors.bind`, `hostname.bind` and
|
following zones: `version.bind`, `version.server`, `authors.bind`, `hostname.bind` and
|
||||||
`id.server`.
|
`id.server`.
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
// Package chaos implements a middleware that answer to 'CH version.bind TXT' type queries.
|
// Package chaos implements a plugin that answer to 'CH version.bind TXT' type queries.
|
||||||
package chaos
|
package chaos
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/coredns/coredns/middleware"
|
"github.com/coredns/coredns/plugin"
|
||||||
"github.com/coredns/coredns/request"
|
"github.com/coredns/coredns/request"
|
||||||
|
|
||||||
"github.com/miekg/dns"
|
"github.com/miekg/dns"
|
||||||
|
@ -14,16 +14,16 @@ import (
|
||||||
// Chaos allows CoreDNS to reply to CH TXT queries and return author or
|
// Chaos allows CoreDNS to reply to CH TXT queries and return author or
|
||||||
// version information.
|
// version information.
|
||||||
type Chaos struct {
|
type Chaos struct {
|
||||||
Next middleware.Handler
|
Next plugin.Handler
|
||||||
Version string
|
Version string
|
||||||
Authors map[string]bool
|
Authors map[string]bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// ServeDNS implements the middleware.Handler interface.
|
// ServeDNS implements the plugin.Handler interface.
|
||||||
func (c Chaos) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (int, error) {
|
func (c Chaos) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (int, error) {
|
||||||
state := request.Request{W: w, Req: r}
|
state := request.Request{W: w, Req: r}
|
||||||
if state.QClass() != dns.ClassCHAOS || state.QType() != dns.TypeTXT {
|
if state.QClass() != dns.ClassCHAOS || state.QType() != dns.TypeTXT {
|
||||||
return middleware.NextOrFailure(c.Name(), c.Next, ctx, w, r)
|
return plugin.NextOrFailure(c.Name(), c.Next, ctx, w, r)
|
||||||
}
|
}
|
||||||
|
|
||||||
m := new(dns.Msg)
|
m := new(dns.Msg)
|
|
@ -3,9 +3,9 @@ package chaos
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/coredns/coredns/middleware"
|
"github.com/coredns/coredns/plugin"
|
||||||
"github.com/coredns/coredns/middleware/pkg/dnsrecorder"
|
"github.com/coredns/coredns/plugin/pkg/dnsrecorder"
|
||||||
"github.com/coredns/coredns/middleware/test"
|
"github.com/coredns/coredns/plugin/test"
|
||||||
|
|
||||||
"github.com/miekg/dns"
|
"github.com/miekg/dns"
|
||||||
"golang.org/x/net/context"
|
"golang.org/x/net/context"
|
||||||
|
@ -18,7 +18,7 @@ func TestChaos(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
next middleware.Handler
|
next plugin.Handler
|
||||||
qname string
|
qname string
|
||||||
qtype uint16
|
qtype uint16
|
||||||
expectedCode int
|
expectedCode int
|
|
@ -2,7 +2,7 @@ package chaos
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/coredns/coredns/core/dnsserver"
|
"github.com/coredns/coredns/core/dnsserver"
|
||||||
"github.com/coredns/coredns/middleware"
|
"github.com/coredns/coredns/plugin"
|
||||||
|
|
||||||
"github.com/mholt/caddy"
|
"github.com/mholt/caddy"
|
||||||
)
|
)
|
||||||
|
@ -18,10 +18,10 @@ func init() {
|
||||||
func setup(c *caddy.Controller) error {
|
func setup(c *caddy.Controller) error {
|
||||||
version, authors, err := chaosParse(c)
|
version, authors, err := chaosParse(c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return middleware.Error("chaos", err)
|
return plugin.Error("chaos", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
dnsserver.GetConfig(c).AddMiddleware(func(next middleware.Handler) middleware.Handler {
|
dnsserver.GetConfig(c).AddPlugin(func(next plugin.Handler) plugin.Handler {
|
||||||
return Chaos{Next: next, Version: version, Authors: authors}
|
return Chaos{Next: next, Version: version, Authors: authors}
|
||||||
})
|
})
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
*debug* disables the automatic recovery upon a CoreDNS crash so that you'll get a nice stack trace.
|
*debug* disables the automatic recovery upon a CoreDNS crash so that you'll get a nice stack trace.
|
||||||
|
|
||||||
Note that the *errors* middleware (if loaded) will also set a `recover` negating this setting.
|
Note that the *errors* plugin (if loaded) will also set a `recover` negating this setting.
|
||||||
The main use of *debug* is to help testing.
|
The main use of *debug* is to help testing.
|
||||||
|
|
||||||
## Syntax
|
## Syntax
|
|
@ -2,7 +2,7 @@ package debug
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/coredns/coredns/core/dnsserver"
|
"github.com/coredns/coredns/core/dnsserver"
|
||||||
"github.com/coredns/coredns/middleware"
|
"github.com/coredns/coredns/plugin"
|
||||||
|
|
||||||
"github.com/mholt/caddy"
|
"github.com/mholt/caddy"
|
||||||
)
|
)
|
||||||
|
@ -19,7 +19,7 @@ func setup(c *caddy.Controller) error {
|
||||||
|
|
||||||
for c.Next() {
|
for c.Next() {
|
||||||
if c.NextArg() {
|
if c.NextArg() {
|
||||||
return middleware.Error("debug", c.ArgErr())
|
return plugin.Error("debug", c.ArgErr())
|
||||||
}
|
}
|
||||||
config.Debug = true
|
config.Debug = true
|
||||||
}
|
}
|
|
@ -16,7 +16,7 @@ CSK (common signing key), forgoing the ZSK/KSK split. All signing operations are
|
||||||
Authenticated denial of existence is implemented with NSEC black lies. Using ECDSA as an algorithm
|
Authenticated denial of existence is implemented with NSEC black lies. Using ECDSA as an algorithm
|
||||||
is preferred as this leads to smaller signatures (compared to RSA). NSEC3 is *not* supported.
|
is preferred as this leads to smaller signatures (compared to RSA). NSEC3 is *not* supported.
|
||||||
|
|
||||||
If multiple *dnssec* middlewares are specified in the same zone, the last one specified will be
|
If multiple *dnssec* plugins are specified in the same zone, the last one specified will be
|
||||||
used ( see [bugs](#bugs) ).
|
used ( see [bugs](#bugs) ).
|
||||||
|
|
||||||
* `ZONES` zones that should be signed. If empty, the zones from the configuration block
|
* `ZONES` zones that should be signed. If empty, the zones from the configuration block
|
||||||
|
@ -33,7 +33,7 @@ used ( see [bugs](#bugs) ).
|
||||||
|
|
||||||
* generated private key `Kexample.org+013+45330.private`
|
* generated private key `Kexample.org+013+45330.private`
|
||||||
|
|
||||||
* `cache_capacity` indicates the capacity of the cache. The dnssec middleware uses a cache to store
|
* `cache_capacity` indicates the capacity of the cache. The dnssec plugin uses a cache to store
|
||||||
RRSIGs. The default capacity is 10000.
|
RRSIGs. The default capacity is 10000.
|
||||||
|
|
||||||
## Metrics
|
## Metrics
|
||||||
|
@ -71,7 +71,7 @@ cluster.local:53 {
|
||||||
|
|
||||||
## Bugs
|
## Bugs
|
||||||
|
|
||||||
Multiple *dnssec* middlewares inside one server stanza will silently overwrite earlier ones, here
|
Multiple *dnssec* plugins inside one server stanza will silently overwrite earlier ones, here
|
||||||
`example.local` will overwrite the one for `cluster.local`.
|
`example.local` will overwrite the one for `cluster.local`.
|
||||||
|
|
||||||
~~~
|
~~~
|
|
@ -4,7 +4,7 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/coredns/coredns/middleware/test"
|
"github.com/coredns/coredns/plugin/test"
|
||||||
"github.com/coredns/coredns/request"
|
"github.com/coredns/coredns/request"
|
||||||
|
|
||||||
"github.com/miekg/dns"
|
"github.com/miekg/dns"
|
|
@ -4,8 +4,8 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/coredns/coredns/middleware/pkg/cache"
|
"github.com/coredns/coredns/plugin/pkg/cache"
|
||||||
"github.com/coredns/coredns/middleware/test"
|
"github.com/coredns/coredns/plugin/test"
|
||||||
"github.com/coredns/coredns/request"
|
"github.com/coredns/coredns/request"
|
||||||
)
|
)
|
||||||
|
|
|
@ -1,14 +1,14 @@
|
||||||
// Package dnssec implements a middleware that signs responses on-the-fly using
|
// Package dnssec implements a plugin that signs responses on-the-fly using
|
||||||
// NSEC black lies.
|
// NSEC black lies.
|
||||||
package dnssec
|
package dnssec
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/coredns/coredns/middleware"
|
"github.com/coredns/coredns/plugin"
|
||||||
"github.com/coredns/coredns/middleware/pkg/cache"
|
"github.com/coredns/coredns/plugin/pkg/cache"
|
||||||
"github.com/coredns/coredns/middleware/pkg/response"
|
"github.com/coredns/coredns/plugin/pkg/response"
|
||||||
"github.com/coredns/coredns/middleware/pkg/singleflight"
|
"github.com/coredns/coredns/plugin/pkg/singleflight"
|
||||||
"github.com/coredns/coredns/request"
|
"github.com/coredns/coredns/request"
|
||||||
|
|
||||||
"github.com/miekg/dns"
|
"github.com/miekg/dns"
|
||||||
|
@ -16,7 +16,7 @@ import (
|
||||||
|
|
||||||
// Dnssec signs the reply on-the-fly.
|
// Dnssec signs the reply on-the-fly.
|
||||||
type Dnssec struct {
|
type Dnssec struct {
|
||||||
Next middleware.Handler
|
Next plugin.Handler
|
||||||
|
|
||||||
zones []string
|
zones []string
|
||||||
keys []*DNSKEY
|
keys []*DNSKEY
|
||||||
|
@ -25,7 +25,7 @@ type Dnssec struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// New returns a new Dnssec.
|
// New returns a new Dnssec.
|
||||||
func New(zones []string, keys []*DNSKEY, next middleware.Handler, c *cache.Cache) Dnssec {
|
func New(zones []string, keys []*DNSKEY, next plugin.Handler, c *cache.Cache) Dnssec {
|
||||||
return Dnssec{Next: next,
|
return Dnssec{Next: next,
|
||||||
zones: zones,
|
zones: zones,
|
||||||
keys: keys,
|
keys: keys,
|
|
@ -4,8 +4,8 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/coredns/coredns/middleware/pkg/cache"
|
"github.com/coredns/coredns/plugin/pkg/cache"
|
||||||
"github.com/coredns/coredns/middleware/test"
|
"github.com/coredns/coredns/plugin/test"
|
||||||
"github.com/coredns/coredns/request"
|
"github.com/coredns/coredns/request"
|
||||||
|
|
||||||
"github.com/miekg/dns"
|
"github.com/miekg/dns"
|
|
@ -1,7 +1,7 @@
|
||||||
package dnssec
|
package dnssec
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/coredns/coredns/middleware"
|
"github.com/coredns/coredns/plugin"
|
||||||
"github.com/coredns/coredns/request"
|
"github.com/coredns/coredns/request"
|
||||||
|
|
||||||
"github.com/miekg/dns"
|
"github.com/miekg/dns"
|
||||||
|
@ -9,16 +9,16 @@ import (
|
||||||
"golang.org/x/net/context"
|
"golang.org/x/net/context"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ServeDNS implements the middleware.Handler interface.
|
// ServeDNS implements the plugin.Handler interface.
|
||||||
func (d Dnssec) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (int, error) {
|
func (d Dnssec) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (int, error) {
|
||||||
state := request.Request{W: w, Req: r}
|
state := request.Request{W: w, Req: r}
|
||||||
|
|
||||||
do := state.Do()
|
do := state.Do()
|
||||||
qname := state.Name()
|
qname := state.Name()
|
||||||
qtype := state.QType()
|
qtype := state.QType()
|
||||||
zone := middleware.Zones(d.zones).Matches(qname)
|
zone := plugin.Zones(d.zones).Matches(qname)
|
||||||
if zone == "" {
|
if zone == "" {
|
||||||
return middleware.NextOrFailure(d.Name(), d.Next, ctx, w, r)
|
return plugin.NextOrFailure(d.Name(), d.Next, ctx, w, r)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Intercept queries for DNSKEY, but only if one of the zones matches the qname, otherwise we let
|
// Intercept queries for DNSKEY, but only if one of the zones matches the qname, otherwise we let
|
||||||
|
@ -36,33 +36,33 @@ func (d Dnssec) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
drr := &ResponseWriter{w, d}
|
drr := &ResponseWriter{w, d}
|
||||||
return middleware.NextOrFailure(d.Name(), d.Next, ctx, drr, r)
|
return plugin.NextOrFailure(d.Name(), d.Next, ctx, drr, r)
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
cacheSize = prometheus.NewGaugeVec(prometheus.GaugeOpts{
|
cacheSize = prometheus.NewGaugeVec(prometheus.GaugeOpts{
|
||||||
Namespace: middleware.Namespace,
|
Namespace: plugin.Namespace,
|
||||||
Subsystem: subsystem,
|
Subsystem: subsystem,
|
||||||
Name: "cache_size",
|
Name: "cache_size",
|
||||||
Help: "The number of elements in the dnssec cache.",
|
Help: "The number of elements in the dnssec cache.",
|
||||||
}, []string{"type"})
|
}, []string{"type"})
|
||||||
|
|
||||||
cacheCapacity = prometheus.NewGaugeVec(prometheus.GaugeOpts{
|
cacheCapacity = prometheus.NewGaugeVec(prometheus.GaugeOpts{
|
||||||
Namespace: middleware.Namespace,
|
Namespace: plugin.Namespace,
|
||||||
Subsystem: subsystem,
|
Subsystem: subsystem,
|
||||||
Name: "cache_capacity",
|
Name: "cache_capacity",
|
||||||
Help: "The dnssec cache's capacity.",
|
Help: "The dnssec cache's capacity.",
|
||||||
}, []string{"type"})
|
}, []string{"type"})
|
||||||
|
|
||||||
cacheHits = prometheus.NewCounter(prometheus.CounterOpts{
|
cacheHits = prometheus.NewCounter(prometheus.CounterOpts{
|
||||||
Namespace: middleware.Namespace,
|
Namespace: plugin.Namespace,
|
||||||
Subsystem: subsystem,
|
Subsystem: subsystem,
|
||||||
Name: "cache_hits_total",
|
Name: "cache_hits_total",
|
||||||
Help: "The count of cache hits.",
|
Help: "The count of cache hits.",
|
||||||
})
|
})
|
||||||
|
|
||||||
cacheMisses = prometheus.NewCounter(prometheus.CounterOpts{
|
cacheMisses = prometheus.NewCounter(prometheus.CounterOpts{
|
||||||
Namespace: middleware.Namespace,
|
Namespace: plugin.Namespace,
|
||||||
Subsystem: subsystem,
|
Subsystem: subsystem,
|
||||||
Name: "cache_misses_total",
|
Name: "cache_misses_total",
|
||||||
Help: "The count of cache misses.",
|
Help: "The count of cache misses.",
|
|
@ -4,10 +4,10 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/coredns/coredns/middleware/file"
|
"github.com/coredns/coredns/plugin/file"
|
||||||
"github.com/coredns/coredns/middleware/pkg/cache"
|
"github.com/coredns/coredns/plugin/pkg/cache"
|
||||||
"github.com/coredns/coredns/middleware/pkg/dnsrecorder"
|
"github.com/coredns/coredns/plugin/pkg/dnsrecorder"
|
||||||
"github.com/coredns/coredns/middleware/test"
|
"github.com/coredns/coredns/plugin/test"
|
||||||
|
|
||||||
"github.com/miekg/dns"
|
"github.com/miekg/dns"
|
||||||
"golang.org/x/net/context"
|
"golang.org/x/net/context"
|
|
@ -4,7 +4,7 @@ import (
|
||||||
"log"
|
"log"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/coredns/coredns/middleware"
|
"github.com/coredns/coredns/plugin"
|
||||||
"github.com/coredns/coredns/request"
|
"github.com/coredns/coredns/request"
|
||||||
|
|
||||||
"github.com/miekg/dns"
|
"github.com/miekg/dns"
|
||||||
|
@ -23,7 +23,7 @@ func (d *ResponseWriter) WriteMsg(res *dns.Msg) error {
|
||||||
state := request.Request{W: d.ResponseWriter, Req: res}
|
state := request.Request{W: d.ResponseWriter, Req: res}
|
||||||
|
|
||||||
qname := state.Name()
|
qname := state.Name()
|
||||||
zone := middleware.Zones(d.d.zones).Matches(qname)
|
zone := plugin.Zones(d.d.zones).Matches(qname)
|
||||||
if zone == "" {
|
if zone == "" {
|
||||||
return d.ResponseWriter.WriteMsg(res)
|
return d.ResponseWriter.WriteMsg(res)
|
||||||
}
|
}
|
|
@ -6,8 +6,8 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/coredns/coredns/core/dnsserver"
|
"github.com/coredns/coredns/core/dnsserver"
|
||||||
"github.com/coredns/coredns/middleware"
|
"github.com/coredns/coredns/plugin"
|
||||||
"github.com/coredns/coredns/middleware/pkg/cache"
|
"github.com/coredns/coredns/plugin/pkg/cache"
|
||||||
|
|
||||||
"github.com/mholt/caddy"
|
"github.com/mholt/caddy"
|
||||||
)
|
)
|
||||||
|
@ -22,11 +22,11 @@ func init() {
|
||||||
func setup(c *caddy.Controller) error {
|
func setup(c *caddy.Controller) error {
|
||||||
zones, keys, capacity, err := dnssecParse(c)
|
zones, keys, capacity, err := dnssecParse(c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return middleware.Error("dnssec", err)
|
return plugin.Error("dnssec", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
ca := cache.New(capacity)
|
ca := cache.New(capacity)
|
||||||
dnsserver.GetConfig(c).AddMiddleware(func(next middleware.Handler) middleware.Handler {
|
dnsserver.GetConfig(c).AddPlugin(func(next plugin.Handler) plugin.Handler {
|
||||||
return New(zones, keys, next, ca)
|
return New(zones, keys, next, ca)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -74,12 +74,12 @@ func dnssecParse(c *caddy.Controller) ([]string, []*DNSKEY, int, error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for i := range zones {
|
for i := range zones {
|
||||||
zones[i] = middleware.Host(zones[i]).Normalize()
|
zones[i] = plugin.Host(zones[i]).Normalize()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if each keys owner name can actually sign the zones we want them to sign
|
// Check if each keys owner name can actually sign the zones we want them to sign
|
||||||
for _, k := range keys {
|
for _, k := range keys {
|
||||||
kname := middleware.Name(k.K.Header().Name)
|
kname := plugin.Name(k.K.Header().Name)
|
||||||
ok := false
|
ok := false
|
||||||
for i := range zones {
|
for i := range zones {
|
||||||
if kname.Matches(zones[i]) {
|
if kname.Matches(zones[i]) {
|
|
@ -4,9 +4,9 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
|
||||||
"github.com/coredns/coredns/middleware"
|
"github.com/coredns/coredns/plugin"
|
||||||
"github.com/coredns/coredns/middleware/dnstap/msg"
|
"github.com/coredns/coredns/plugin/dnstap/msg"
|
||||||
"github.com/coredns/coredns/middleware/dnstap/taprw"
|
"github.com/coredns/coredns/plugin/dnstap/taprw"
|
||||||
|
|
||||||
tap "github.com/dnstap/golang-dnstap"
|
tap "github.com/dnstap/golang-dnstap"
|
||||||
"github.com/miekg/dns"
|
"github.com/miekg/dns"
|
||||||
|
@ -15,7 +15,7 @@ import (
|
||||||
|
|
||||||
// Dnstap is the dnstap handler.
|
// Dnstap is the dnstap handler.
|
||||||
type Dnstap struct {
|
type Dnstap struct {
|
||||||
Next middleware.Handler
|
Next plugin.Handler
|
||||||
Out io.Writer
|
Out io.Writer
|
||||||
Pack bool
|
Pack bool
|
||||||
}
|
}
|
||||||
|
@ -32,7 +32,7 @@ type (
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
// TapperFromContext will return a Tapper if the dnstap middleware is enabled.
|
// TapperFromContext will return a Tapper if the dnstap plugin is enabled.
|
||||||
func TapperFromContext(ctx context.Context) (t Tapper) {
|
func TapperFromContext(ctx context.Context) (t Tapper) {
|
||||||
t, _ = ctx.(Tapper)
|
t, _ = ctx.(Tapper)
|
||||||
return
|
return
|
||||||
|
@ -62,14 +62,14 @@ func (h Dnstap) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg)
|
||||||
rw := &taprw.ResponseWriter{ResponseWriter: w, Tapper: &h, Query: r}
|
rw := &taprw.ResponseWriter{ResponseWriter: w, Tapper: &h, Query: r}
|
||||||
rw.QueryEpoch()
|
rw.QueryEpoch()
|
||||||
|
|
||||||
code, err := middleware.NextOrFailure(h.Name(), h.Next, tapContext{ctx, h}, rw, r)
|
code, err := plugin.NextOrFailure(h.Name(), h.Next, tapContext{ctx, h}, rw, r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// ignore dnstap errors
|
// ignore dnstap errors
|
||||||
return code, err
|
return code, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := rw.DnstapError(); err != nil {
|
if err := rw.DnstapError(); err != nil {
|
||||||
return code, middleware.Error("dnstap", err)
|
return code, plugin.Error("dnstap", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return code, nil
|
return code, nil
|
|
@ -5,8 +5,8 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/coredns/coredns/middleware/dnstap/test"
|
"github.com/coredns/coredns/plugin/dnstap/test"
|
||||||
mwtest "github.com/coredns/coredns/middleware/test"
|
mwtest "github.com/coredns/coredns/plugin/test"
|
||||||
|
|
||||||
tap "github.com/dnstap/golang-dnstap"
|
tap "github.com/dnstap/golang-dnstap"
|
||||||
"github.com/golang/protobuf/proto"
|
"github.com/golang/protobuf/proto"
|
|
@ -11,7 +11,7 @@ import (
|
||||||
"github.com/miekg/dns"
|
"github.com/miekg/dns"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Builder helps to build Data by being aware of the dnstap middleware configuration.
|
// Builder helps to build Data by being aware of the dnstap plugin configuration.
|
||||||
type Builder struct {
|
type Builder struct {
|
||||||
Full bool
|
Full bool
|
||||||
Data
|
Data
|
|
@ -5,7 +5,7 @@ import (
|
||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/coredns/coredns/middleware/test"
|
"github.com/coredns/coredns/plugin/test"
|
||||||
"github.com/coredns/coredns/request"
|
"github.com/coredns/coredns/request"
|
||||||
|
|
||||||
tap "github.com/dnstap/golang-dnstap"
|
tap "github.com/dnstap/golang-dnstap"
|
|
@ -7,9 +7,9 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/coredns/coredns/core/dnsserver"
|
"github.com/coredns/coredns/core/dnsserver"
|
||||||
"github.com/coredns/coredns/middleware"
|
"github.com/coredns/coredns/plugin"
|
||||||
"github.com/coredns/coredns/middleware/dnstap/out"
|
"github.com/coredns/coredns/plugin/dnstap/out"
|
||||||
"github.com/coredns/coredns/middleware/pkg/dnsutil"
|
"github.com/coredns/coredns/plugin/pkg/dnsutil"
|
||||||
|
|
||||||
"github.com/mholt/caddy"
|
"github.com/mholt/caddy"
|
||||||
"github.com/mholt/caddy/caddyfile"
|
"github.com/mholt/caddy/caddyfile"
|
||||||
|
@ -24,7 +24,7 @@ func init() {
|
||||||
|
|
||||||
func wrapSetup(c *caddy.Controller) error {
|
func wrapSetup(c *caddy.Controller) error {
|
||||||
if err := setup(c); err != nil {
|
if err := setup(c); err != nil {
|
||||||
return middleware.Error("dnstap", err)
|
return plugin.Error("dnstap", err)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -88,8 +88,8 @@ func setup(c *caddy.Controller) error {
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
|
|
||||||
dnsserver.GetConfig(c).AddMiddleware(
|
dnsserver.GetConfig(c).AddPlugin(
|
||||||
func(next middleware.Handler) middleware.Handler {
|
func(next plugin.Handler) plugin.Handler {
|
||||||
dnstap.Next = next
|
dnstap.Next = next
|
||||||
return dnstap
|
return dnstap
|
||||||
})
|
})
|
|
@ -5,7 +5,7 @@ package taprw
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/coredns/coredns/middleware/dnstap/msg"
|
"github.com/coredns/coredns/plugin/dnstap/msg"
|
||||||
|
|
||||||
tap "github.com/dnstap/golang-dnstap"
|
tap "github.com/dnstap/golang-dnstap"
|
||||||
"github.com/miekg/dns"
|
"github.com/miekg/dns"
|
|
@ -4,9 +4,9 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/coredns/coredns/middleware/dnstap/msg"
|
"github.com/coredns/coredns/plugin/dnstap/msg"
|
||||||
"github.com/coredns/coredns/middleware/dnstap/test"
|
"github.com/coredns/coredns/plugin/dnstap/test"
|
||||||
mwtest "github.com/coredns/coredns/middleware/test"
|
mwtest "github.com/coredns/coredns/plugin/test"
|
||||||
|
|
||||||
tap "github.com/dnstap/golang-dnstap"
|
tap "github.com/dnstap/golang-dnstap"
|
||||||
"github.com/miekg/dns"
|
"github.com/miekg/dns"
|
|
@ -4,7 +4,7 @@ import (
|
||||||
"net"
|
"net"
|
||||||
"reflect"
|
"reflect"
|
||||||
|
|
||||||
"github.com/coredns/coredns/middleware/dnstap/msg"
|
"github.com/coredns/coredns/plugin/dnstap/msg"
|
||||||
|
|
||||||
tap "github.com/dnstap/golang-dnstap"
|
tap "github.com/dnstap/golang-dnstap"
|
||||||
"golang.org/x/net/context"
|
"golang.org/x/net/context"
|
|
@ -1,13 +1,13 @@
|
||||||
# erratic
|
# erratic
|
||||||
|
|
||||||
*erratic* is a middleware useful for testing client behavior. It returns a static response to all
|
*erratic* is a plugin useful for testing client behavior. It returns a static response to all
|
||||||
queries, but the responses can be delayed, dropped or truncated.
|
queries, but the responses can be delayed, dropped or truncated.
|
||||||
|
|
||||||
The *erratic* middleware will respond to every A or AAAA query. For any other type it will return
|
The *erratic* plugin will respond to every A or AAAA query. For any other type it will return
|
||||||
a SERVFAIL response. The reply for A will return 192.0.2.53 (see RFC 5737), for AAAA it returns
|
a SERVFAIL response. The reply for A will return 192.0.2.53 (see RFC 5737), for AAAA it returns
|
||||||
2001:DB8::53 (see RFC 3849).
|
2001:DB8::53 (see RFC 3849).
|
||||||
|
|
||||||
*erratic* can also be used in conjunction with the *autopath* middleware. This is mostly to aid in
|
*erratic* can also be used in conjunction with the *autopath* plugin. This is mostly to aid in
|
||||||
testing.
|
testing.
|
||||||
|
|
||||||
## Syntax
|
## Syntax
|
|
@ -2,7 +2,7 @@ package erratic
|
||||||
|
|
||||||
import "github.com/coredns/coredns/request"
|
import "github.com/coredns/coredns/request"
|
||||||
|
|
||||||
// AutoPath implements the AutoPathFunc call from the autopath middleware.
|
// AutoPath implements the AutoPathFunc call from the autopath plugin.
|
||||||
func (e *Erratic) AutoPath(state request.Request) []string {
|
func (e *Erratic) AutoPath(state request.Request) []string {
|
||||||
return []string{"a.example.org.", "b.example.org.", ""}
|
return []string{"a.example.org.", "b.example.org.", ""}
|
||||||
}
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
// Package erratic implements a middleware that returns erratic answers (delayed, dropped).
|
// Package erratic implements a plugin that returns erratic answers (delayed, dropped).
|
||||||
package erratic
|
package erratic
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
@ -11,7 +11,7 @@ import (
|
||||||
"golang.org/x/net/context"
|
"golang.org/x/net/context"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Erratic is a middleware that returns erratic repsonses to each client.
|
// Erratic is a plugin that returns erratic repsonses to each client.
|
||||||
type Erratic struct {
|
type Erratic struct {
|
||||||
drop uint64
|
drop uint64
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@ type Erratic struct {
|
||||||
q uint64 // counter of queries
|
q uint64 // counter of queries
|
||||||
}
|
}
|
||||||
|
|
||||||
// ServeDNS implements the middleware.Handler interface.
|
// ServeDNS implements the plugin.Handler interface.
|
||||||
func (e *Erratic) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (int, error) {
|
func (e *Erratic) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (int, error) {
|
||||||
state := request.Request{W: w, Req: r}
|
state := request.Request{W: w, Req: r}
|
||||||
drop := false
|
drop := false
|
|
@ -3,8 +3,8 @@ package erratic
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/coredns/coredns/middleware/pkg/dnsrecorder"
|
"github.com/coredns/coredns/plugin/pkg/dnsrecorder"
|
||||||
"github.com/coredns/coredns/middleware/test"
|
"github.com/coredns/coredns/plugin/test"
|
||||||
|
|
||||||
"github.com/miekg/dns"
|
"github.com/miekg/dns"
|
||||||
"golang.org/x/net/context"
|
"golang.org/x/net/context"
|
|
@ -6,7 +6,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/coredns/coredns/core/dnsserver"
|
"github.com/coredns/coredns/core/dnsserver"
|
||||||
"github.com/coredns/coredns/middleware"
|
"github.com/coredns/coredns/plugin"
|
||||||
|
|
||||||
"github.com/mholt/caddy"
|
"github.com/mholt/caddy"
|
||||||
)
|
)
|
||||||
|
@ -21,10 +21,10 @@ func init() {
|
||||||
func setupErratic(c *caddy.Controller) error {
|
func setupErratic(c *caddy.Controller) error {
|
||||||
e, err := parseErratic(c)
|
e, err := parseErratic(c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return middleware.Error("erratic", err)
|
return plugin.Error("erratic", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
dnsserver.GetConfig(c).AddMiddleware(func(next middleware.Handler) middleware.Handler {
|
dnsserver.GetConfig(c).AddPlugin(func(next plugin.Handler) plugin.Handler {
|
||||||
return e
|
return e
|
||||||
})
|
})
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
// Package errors implements an HTTP error handling middleware.
|
// Package errors implements an HTTP error handling plugin.
|
||||||
package errors
|
package errors
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
@ -8,25 +8,25 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/coredns/coredns/middleware"
|
"github.com/coredns/coredns/plugin"
|
||||||
"github.com/coredns/coredns/request"
|
"github.com/coredns/coredns/request"
|
||||||
|
|
||||||
"github.com/miekg/dns"
|
"github.com/miekg/dns"
|
||||||
"golang.org/x/net/context"
|
"golang.org/x/net/context"
|
||||||
)
|
)
|
||||||
|
|
||||||
// errorHandler handles DNS errors (and errors from other middleware).
|
// errorHandler handles DNS errors (and errors from other plugin).
|
||||||
type errorHandler struct {
|
type errorHandler struct {
|
||||||
Next middleware.Handler
|
Next plugin.Handler
|
||||||
LogFile string
|
LogFile string
|
||||||
Log *log.Logger
|
Log *log.Logger
|
||||||
}
|
}
|
||||||
|
|
||||||
// ServeDNS implements the middleware.Handler interface.
|
// ServeDNS implements the plugin.Handler interface.
|
||||||
func (h errorHandler) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (int, error) {
|
func (h errorHandler) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (int, error) {
|
||||||
defer h.recovery(ctx, w, r)
|
defer h.recovery(ctx, w, r)
|
||||||
|
|
||||||
rcode, err := middleware.NextOrFailure(h.Name(), h.Next, ctx, w, r)
|
rcode, err := plugin.NextOrFailure(h.Name(), h.Next, ctx, w, r)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
state := request.Request{W: w, Req: r}
|
state := request.Request{W: w, Req: r}
|
|
@ -8,9 +8,9 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/coredns/coredns/middleware"
|
"github.com/coredns/coredns/plugin"
|
||||||
"github.com/coredns/coredns/middleware/pkg/dnsrecorder"
|
"github.com/coredns/coredns/plugin/pkg/dnsrecorder"
|
||||||
"github.com/coredns/coredns/middleware/test"
|
"github.com/coredns/coredns/plugin/test"
|
||||||
|
|
||||||
"github.com/miekg/dns"
|
"github.com/miekg/dns"
|
||||||
"golang.org/x/net/context"
|
"golang.org/x/net/context"
|
||||||
|
@ -22,7 +22,7 @@ func TestErrors(t *testing.T) {
|
||||||
|
|
||||||
testErr := errors.New("test error")
|
testErr := errors.New("test error")
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
next middleware.Handler
|
next plugin.Handler
|
||||||
expectedCode int
|
expectedCode int
|
||||||
expectedLog string
|
expectedLog string
|
||||||
expectedErr error
|
expectedErr error
|
||||||
|
@ -66,8 +66,8 @@ func TestErrors(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func genErrorHandler(rcode int, err error) middleware.Handler {
|
func genErrorHandler(rcode int, err error) plugin.Handler {
|
||||||
return middleware.HandlerFunc(func(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (int, error) {
|
return plugin.HandlerFunc(func(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (int, error) {
|
||||||
return rcode, err
|
return rcode, err
|
||||||
})
|
})
|
||||||
}
|
}
|
|
@ -6,7 +6,7 @@ import (
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/coredns/coredns/core/dnsserver"
|
"github.com/coredns/coredns/core/dnsserver"
|
||||||
"github.com/coredns/coredns/middleware"
|
"github.com/coredns/coredns/plugin"
|
||||||
|
|
||||||
"github.com/mholt/caddy"
|
"github.com/mholt/caddy"
|
||||||
)
|
)
|
||||||
|
@ -21,12 +21,12 @@ func init() {
|
||||||
func setup(c *caddy.Controller) error {
|
func setup(c *caddy.Controller) error {
|
||||||
handler, err := errorsParse(c)
|
handler, err := errorsParse(c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return middleware.Error("errors", err)
|
return plugin.Error("errors", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
handler.Log = log.New(os.Stdout, "", 0)
|
handler.Log = log.New(os.Stdout, "", 0)
|
||||||
|
|
||||||
dnsserver.GetConfig(c).AddMiddleware(func(next middleware.Handler) middleware.Handler {
|
dnsserver.GetConfig(c).AddPlugin(func(next plugin.Handler) plugin.Handler {
|
||||||
handler.Next = next
|
handler.Next = next
|
||||||
return handler
|
return handler
|
||||||
})
|
})
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Reference in a new issue