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},
|
||||
|
||||
// Directives that inject handlers (middleware)
|
||||
{"log", setup.Log},
|
||||
{"prometheus", setup.Prometheus},
|
||||
{"log", setup.Log},
|
||||
{"rewrite", setup.Rewrite},
|
||||
{"loadbalance", setup.Loadbalance},
|
||||
{"file", setup.File},
|
||||
|
|
|
@ -32,17 +32,17 @@ func Prometheus(c *Controller) (middleware.Middleware, error) {
|
|||
}, nil
|
||||
}
|
||||
|
||||
func parsePrometheus(c *Controller) (*prom.Metrics, error) {
|
||||
func parsePrometheus(c *Controller) (prom.Metrics, error) {
|
||||
var (
|
||||
metrics *prom.Metrics
|
||||
metrics prom.Metrics
|
||||
err error
|
||||
)
|
||||
|
||||
for c.Next() {
|
||||
if metrics != nil {
|
||||
return nil, c.Err("prometheus: can only have one metrics module per server")
|
||||
if metrics.Addr != "" {
|
||||
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()
|
||||
|
||||
switch len(args) {
|
||||
|
@ -50,18 +50,18 @@ func parsePrometheus(c *Controller) (*prom.Metrics, error) {
|
|||
case 1:
|
||||
metrics.Addr = args[0]
|
||||
default:
|
||||
return nil, c.ArgErr()
|
||||
return prom.Metrics{}, c.ArgErr()
|
||||
}
|
||||
for c.NextBlock() {
|
||||
switch c.Val() {
|
||||
case "address":
|
||||
args = c.RemainingArgs()
|
||||
if len(args) != 1 {
|
||||
return nil, c.ArgErr()
|
||||
return prom.Metrics{}, c.ArgErr()
|
||||
}
|
||||
metrics.Addr = args[0]
|
||||
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
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"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) {
|
||||
state := middleware.State{W: w, Req: r}
|
||||
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
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package file
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
|
||||
|
@ -26,7 +25,7 @@ type (
|
|||
func (f File) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (int, error) {
|
||||
state := middleware.State{W: w, Req: r}
|
||||
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()
|
||||
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
|
||||
}
|
||||
|
||||
if state.Proto() != "udp" && state.QType() == dns.TypeAXFR {
|
||||
if state.QType() == dns.TypeAXFR || state.QType() == dns.TypeIXFR {
|
||||
xfr := Xfr{z}
|
||||
return xfr.ServeDNS(ctx, w, r)
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package file
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
|
||||
"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 {
|
||||
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()
|
||||
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
|
||||
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 {
|
||||
l += dns.Len(r)
|
||||
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
|
||||
}
|
||||
|
||||
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"
|
||||
)
|
||||
|
||||
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}
|
||||
|
||||
qname := state.Name()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue