Middleware chaining fixes
For prometheus use the plain value, not a pointer and change all usages. Allow AXFR to be requested over udp as well and some other more log printed when commencing an AXFR.
This commit is contained in:
parent
c961acbb6e
commit
8892a1b490
6 changed files with 16 additions and 19 deletions
|
@ -51,8 +51,8 @@ var directiveOrder = []directive{
|
||||||
{"shutdown", setup.Shutdown},
|
{"shutdown", setup.Shutdown},
|
||||||
|
|
||||||
// Directives that inject handlers (middleware)
|
// Directives that inject handlers (middleware)
|
||||||
{"log", setup.Log},
|
|
||||||
{"prometheus", setup.Prometheus},
|
{"prometheus", setup.Prometheus},
|
||||||
|
{"log", setup.Log},
|
||||||
{"rewrite", setup.Rewrite},
|
{"rewrite", setup.Rewrite},
|
||||||
{"loadbalance", setup.Loadbalance},
|
{"loadbalance", setup.Loadbalance},
|
||||||
{"file", setup.File},
|
{"file", setup.File},
|
||||||
|
|
|
@ -32,17 +32,17 @@ func Prometheus(c *Controller) (middleware.Middleware, error) {
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func parsePrometheus(c *Controller) (*prom.Metrics, error) {
|
func parsePrometheus(c *Controller) (prom.Metrics, error) {
|
||||||
var (
|
var (
|
||||||
metrics *prom.Metrics
|
metrics prom.Metrics
|
||||||
err error
|
err error
|
||||||
)
|
)
|
||||||
|
|
||||||
for c.Next() {
|
for c.Next() {
|
||||||
if metrics != nil {
|
if metrics.Addr != "" {
|
||||||
return nil, c.Err("prometheus: can only have one metrics module per server")
|
return prom.Metrics{}, c.Err("prometheus: can only have one metrics module per server")
|
||||||
}
|
}
|
||||||
metrics = &prom.Metrics{ZoneNames: c.ServerBlockHosts}
|
metrics = prom.Metrics{ZoneNames: c.ServerBlockHosts}
|
||||||
args := c.RemainingArgs()
|
args := c.RemainingArgs()
|
||||||
|
|
||||||
switch len(args) {
|
switch len(args) {
|
||||||
|
@ -50,18 +50,18 @@ func parsePrometheus(c *Controller) (*prom.Metrics, error) {
|
||||||
case 1:
|
case 1:
|
||||||
metrics.Addr = args[0]
|
metrics.Addr = args[0]
|
||||||
default:
|
default:
|
||||||
return nil, c.ArgErr()
|
return prom.Metrics{}, c.ArgErr()
|
||||||
}
|
}
|
||||||
for c.NextBlock() {
|
for c.NextBlock() {
|
||||||
switch c.Val() {
|
switch c.Val() {
|
||||||
case "address":
|
case "address":
|
||||||
args = c.RemainingArgs()
|
args = c.RemainingArgs()
|
||||||
if len(args) != 1 {
|
if len(args) != 1 {
|
||||||
return nil, c.ArgErr()
|
return prom.Metrics{}, c.ArgErr()
|
||||||
}
|
}
|
||||||
metrics.Addr = args[0]
|
metrics.Addr = args[0]
|
||||||
default:
|
default:
|
||||||
return nil, c.Errf("prometheus: unknown item: %s", c.Val())
|
return prom.Metrics{}, c.Errf("prometheus: unknown item: %s", c.Val())
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package etcd
|
package etcd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/miekg/coredns/middleware"
|
"github.com/miekg/coredns/middleware"
|
||||||
|
@ -13,7 +12,7 @@ import (
|
||||||
func (e Etcd) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (int, error) {
|
func (e Etcd) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (int, error) {
|
||||||
state := middleware.State{W: w, Req: r}
|
state := middleware.State{W: w, Req: r}
|
||||||
if state.QClass() != dns.ClassINET {
|
if state.QClass() != dns.ClassINET {
|
||||||
return dns.RcodeServerFailure, fmt.Errorf("etcd: can only deal with ClassINET")
|
return e.Next.ServeDNS(ctx, w, r)
|
||||||
}
|
}
|
||||||
|
|
||||||
// We need to check stubzones first, because we may get a request for a zone we
|
// We need to check stubzones first, because we may get a request for a zone we
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package file
|
package file
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"io"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
|
|
||||||
|
@ -26,7 +25,7 @@ type (
|
||||||
func (f File) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (int, error) {
|
func (f File) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (int, error) {
|
||||||
state := middleware.State{W: w, Req: r}
|
state := middleware.State{W: w, Req: r}
|
||||||
if state.QClass() != dns.ClassINET {
|
if state.QClass() != dns.ClassINET {
|
||||||
return dns.RcodeServerFailure, fmt.Errorf("file: can only deal with ClassINET")
|
return f.Next.ServeDNS(ctx, w, r)
|
||||||
}
|
}
|
||||||
qname := state.Name()
|
qname := state.Name()
|
||||||
zone := middleware.Zones(f.Zones.Names).Matches(qname)
|
zone := middleware.Zones(f.Zones.Names).Matches(qname)
|
||||||
|
@ -63,7 +62,7 @@ func (f File) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (i
|
||||||
return dns.RcodeServerFailure, nil
|
return dns.RcodeServerFailure, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if state.Proto() != "udp" && state.QType() == dns.TypeAXFR {
|
if state.QType() == dns.TypeAXFR || state.QType() == dns.TypeIXFR {
|
||||||
xfr := Xfr{z}
|
xfr := Xfr{z}
|
||||||
return xfr.ServeDNS(ctx, w, r)
|
return xfr.ServeDNS(ctx, w, r)
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ package file
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"log"
|
||||||
|
|
||||||
"github.com/miekg/coredns/middleware"
|
"github.com/miekg/coredns/middleware"
|
||||||
|
|
||||||
|
@ -24,9 +25,6 @@ func (x Xfr) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (in
|
||||||
if state.QType() != dns.TypeAXFR {
|
if state.QType() != dns.TypeAXFR {
|
||||||
return 0, fmt.Errorf("xfr called with non transfer type: %d", state.QType())
|
return 0, fmt.Errorf("xfr called with non transfer type: %d", state.QType())
|
||||||
}
|
}
|
||||||
if state.Proto() == "udp" {
|
|
||||||
return 0, fmt.Errorf("xfr called with udp")
|
|
||||||
}
|
|
||||||
|
|
||||||
records := x.All()
|
records := x.All()
|
||||||
if len(records) == 0 {
|
if len(records) == 0 {
|
||||||
|
@ -40,6 +38,7 @@ func (x Xfr) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (in
|
||||||
|
|
||||||
j, l := 0, 0
|
j, l := 0, 0
|
||||||
records = append(records, records[0]) // add closing SOA to the end
|
records = append(records, records[0]) // add closing SOA to the end
|
||||||
|
log.Printf("[INFO] Outgoing transfer of %d records of zone %s to %s started", len(records), x.name, state.IP())
|
||||||
for i, r := range records {
|
for i, r := range records {
|
||||||
l += dns.Len(r)
|
l += dns.Len(r)
|
||||||
if l > transferLength {
|
if l > transferLength {
|
||||||
|
@ -57,4 +56,4 @@ func (x Xfr) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (in
|
||||||
return dns.RcodeSuccess, nil
|
return dns.RcodeSuccess, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
const transferLength = 100 // Start a new envelop after message reaches this size. Intentionally small to test multi envelope parsing
|
const transferLength = 1000 // Start a new envelop after message reaches this size in bytes. Intentionally small to test multi envelope parsing.
|
||||||
|
|
|
@ -10,7 +10,7 @@ import (
|
||||||
"github.com/miekg/dns"
|
"github.com/miekg/dns"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (m *Metrics) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (int, error) {
|
func (m Metrics) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (int, error) {
|
||||||
state := middleware.State{W: w, Req: r}
|
state := middleware.State{W: w, Req: r}
|
||||||
|
|
||||||
qname := state.Name()
|
qname := state.Name()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue