aboutsummaryrefslogtreecommitdiff
path: root/core/dnsserver/server.go
diff options
context:
space:
mode:
authorGravatar Miek Gieben <miek@miek.nl> 2017-10-24 10:16:03 +0100
committerGravatar GitHub <noreply@github.com> 2017-10-24 10:16:03 +0100
commitfcd0342e42a8be5a1cfe41304f0a8099b1bc0e06 (patch)
tree5fa74c98e7a4c729cd8597f477c14a41ca7503cc /core/dnsserver/server.go
parent5f813bcc216642021ae50b07a8aead2e73e9d059 (diff)
downloadcoredns-fcd0342e42a8be5a1cfe41304f0a8099b1bc0e06.tar.gz
coredns-fcd0342e42a8be5a1cfe41304f0a8099b1bc0e06.tar.zst
coredns-fcd0342e42a8be5a1cfe41304f0a8099b1bc0e06.zip
CIDR query routing (#1159)
* core: allow all CIDR ranges in zone specifications Allow (e.g.) a v4 reverse on a /17. If a zone is specified in such a way a FilterFunc is set in the config. This filter is checked against incoming queries. For all other queries this adds a 'x != nil' check which will not impact performace too much. Benchmark function is added as well to check for this as wel. Add multiple tests in tests/server_reverse_test.go. Benchmark shows in the non-reverse case this hardly impact the speed: ~~~ classless: pkg: github.com/coredns/coredns/core/dnsserver BenchmarkCoreServeDNS-4 1000000 1431 ns/op 16 B/op 1 allocs/op pkg: github.com/coredns/coredns/core/dnsserver BenchmarkCoreServeDNS-4 1000000 1429 ns/op 16 B/op 1 allocs/op master: pkg: github.com/coredns/coredns/core/dnsserver BenchmarkCoreServeDNS-4 1000000 1412 ns/op 16 B/op 1 allocs/op pkg: github.com/coredns/coredns/core/dnsserver BenchmarkCoreServeDNS-4 1000000 1429 ns/op 16 B/op 1 allocs/op ~~~ * README.md updates
Diffstat (limited to 'core/dnsserver/server.go')
-rw-r--r--core/dnsserver/server.go25
1 files changed, 18 insertions, 7 deletions
diff --git a/core/dnsserver/server.go b/core/dnsserver/server.go
index bb9a87a12..38d8600c7 100644
--- a/core/dnsserver/server.go
+++ b/core/dnsserver/server.go
@@ -40,7 +40,7 @@ type Server struct {
classChaos bool // allow non-INET class queries
}
-// NewServer returns a new CoreDNS server and compiles all plugin in to it. By default CH class
+// NewServer returns a new CoreDNS server and compiles all plugins in to it. By default CH class
// queries are blocked unless the chaos or proxy is loaded.
func NewServer(addr string, group []*Config) (*Server, error) {
@@ -225,11 +225,22 @@ func (s *Server) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg)
if h, ok := s.zones[string(b[:l])]; ok {
if r.Question[0].Qtype != dns.TypeDS {
- rcode, _ := h.pluginChain.ServeDNS(ctx, w, r)
- if !plugin.ClientWrite(rcode) {
- DefaultErrorFunc(w, r, rcode)
+ if h.FilterFunc == nil {
+ rcode, _ := h.pluginChain.ServeDNS(ctx, w, r)
+ if !plugin.ClientWrite(rcode) {
+ DefaultErrorFunc(w, r, rcode)
+ }
+ return
+ }
+ // FilterFunc is set, call it to see if we should use this handler.
+ // This is given to full query name.
+ if h.FilterFunc(q) {
+ rcode, _ := h.pluginChain.ServeDNS(ctx, w, r)
+ if !plugin.ClientWrite(rcode) {
+ DefaultErrorFunc(w, r, rcode)
+ }
+ return
}
- return
}
// The type is DS, keep the handler, but keep on searching as maybe we are serving
// the parent as well and the DS should be routed to it - this will probably *misroute* DS
@@ -244,8 +255,8 @@ func (s *Server) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg)
}
}
- if dshandler != nil {
- // DS request, and we found a zone, use the handler for the query
+ if r.Question[0].Qtype == dns.TypeDS && dshandler != nil {
+ // DS request, and we found a zone, use the handler for the query.
rcode, _ := dshandler.pluginChain.ServeDNS(ctx, w, r)
if !plugin.ClientWrite(rcode) {
DefaultErrorFunc(w, r, rcode)