* Run gostaticheck Run gostaticcheck on the codebase and fix almost all flagged items. Only keep * coremain/run.go:192:2: var appVersion is unused (U1000) * plugin/chaos/setup.go:54:3: the surrounding loop is unconditionally terminated (SA4004) * plugin/etcd/setup.go:103:3: the surrounding loop is unconditionally terminated (SA4004) * plugin/pkg/replacer/replacer.go:274:13: argument should be pointer-like to avoid allocations (SA6002) * plugin/route53/setup.go:124:28: session.New is deprecated: Use NewSession functions to create sessions instead. NewSession has the same functionality as New except an error can be returned when the func is called instead of waiting to receive an error until a request is made. (SA1019) * test/grpc_test.go:25:69: grpc.WithTimeout is deprecated: use DialContext and context.WithTimeout instead. Will be supported throughout 1.x. (SA1019) The first one isn't true, as this is set via ldflags. The rest is minor. The deprecation should be fixed at some point; I'll file some issues. Signed-off-by: Miek Gieben <miek@miek.nl> * Make sure to plug in the plugins import the plugins, that file that did this was removed, put it in the reload test as this requires an almost complete coredns server. Signed-off-by: Miek Gieben <miek@miek.nl>
85 lines
1.5 KiB
Go
85 lines
1.5 KiB
Go
package dnstap
|
|
|
|
import (
|
|
"strings"
|
|
|
|
"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"
|
|
|
|
"github.com/caddyserver/caddy"
|
|
)
|
|
|
|
func init() { plugin.Register("dnstap", wrapSetup) }
|
|
|
|
func wrapSetup(c *caddy.Controller) error {
|
|
if err := setup(c); err != nil {
|
|
return plugin.Error("dnstap", err)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
type config struct {
|
|
target string
|
|
socket bool
|
|
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]
|
|
} else {
|
|
// default to UNIX socket
|
|
c.target = strings.TrimPrefix(c.target, "unix://")
|
|
c.socket = true
|
|
}
|
|
|
|
c.full = d.NextArg() && d.Val() == "full"
|
|
|
|
return
|
|
}
|
|
|
|
func setup(c *caddy.Controller) error {
|
|
conf, err := parseConfig(c)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
dio := dnstapio.New(conf.target, conf.socket)
|
|
dnstap := Dnstap{IO: dio, JoinRawMessage: 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
|
|
}
|