* plugin/dnstap: remove encoder*.go Those files reimplemented parts of the dnstap spec, we can just use the dnstap functions for that. This leaves all the queuing that is enabled and drops messages if the dnstap reader can't keep up. In the new code flush() would never return an error (at least I couldn't make it do so), so the reconnect functionally is moved to kick off when we get write errors. Some smaller cosmetic changes as well, `d.socket` is now `proto`, which makes the dial() function smaller. Total testing time is now <1s (which was the impetus to look into this plugin *again*). See #4238 The buffered channel needs to be sized correctly, as we may need to do some queing if the dnstap reader can't keep up. Signed-off-by: Miek Gieben <miek@miek.nl> * add missing file Signed-off-by: Miek Gieben <miek@miek.nl> * update doc on queing Signed-off-by: Miek Gieben <miek@miek.nl>
77 lines
1.4 KiB
Go
77 lines
1.4 KiB
Go
package dnstap
|
|
|
|
import (
|
|
"strings"
|
|
|
|
"github.com/coredns/caddy"
|
|
"github.com/coredns/coredns/core/dnsserver"
|
|
"github.com/coredns/coredns/plugin"
|
|
"github.com/coredns/coredns/plugin/dnstap/dnstapio"
|
|
"github.com/coredns/coredns/plugin/pkg/parse"
|
|
)
|
|
|
|
func init() { plugin.Register("dnstap", setup) }
|
|
|
|
type config struct {
|
|
proto string
|
|
target string
|
|
full bool
|
|
}
|
|
|
|
func parseConfig(d *caddy.Controller) (c config, err error) {
|
|
d.Next() // directive name
|
|
|
|
if !d.Args(&c.target) {
|
|
return c, d.ArgErr()
|
|
}
|
|
|
|
if strings.HasPrefix(c.target, "tcp://") {
|
|
// remote IP endpoint
|
|
servers, err := parse.HostPortOrFile(c.target[6:])
|
|
if err != nil {
|
|
return c, d.ArgErr()
|
|
}
|
|
c.target = servers[0]
|
|
c.proto = "tcp"
|
|
} else {
|
|
c.target = strings.TrimPrefix(c.target, "unix://")
|
|
c.proto = "unix"
|
|
}
|
|
|
|
c.full = d.NextArg() && d.Val() == "full"
|
|
|
|
return
|
|
}
|
|
|
|
func setup(c *caddy.Controller) error {
|
|
conf, err := parseConfig(c)
|
|
if err != nil {
|
|
return plugin.Error("dnstap", err)
|
|
}
|
|
|
|
dio := dnstapio.New(conf.proto, conf.target)
|
|
dnstap := Dnstap{io: dio, IncludeRawMessage: conf.full}
|
|
|
|
c.OnStartup(func() error {
|
|
dio.Connect()
|
|
return nil
|
|
})
|
|
|
|
c.OnRestart(func() error {
|
|
dio.Close()
|
|
return nil
|
|
})
|
|
|
|
c.OnFinalShutdown(func() error {
|
|
dio.Close()
|
|
return nil
|
|
})
|
|
|
|
dnsserver.GetConfig(c).AddPlugin(
|
|
func(next plugin.Handler) plugin.Handler {
|
|
dnstap.Next = next
|
|
return dnstap
|
|
})
|
|
|
|
return nil
|
|
}
|