plugin/dnstap: remove config struct (#4258)

* plugin/dnstap: remove config struct

this struct is an uneeded intermidiate to get a dnstap it can be
removed. Remove the dnstapio subpkg: it's also not needed. Make *many*
functions and structs private now that we can.

Signed-off-by: Miek Gieben <miek@miek.nl>

* correct logging

Signed-off-by: Miek Gieben <miek@miek.nl>
This commit is contained in:
Miek Gieben 2020-11-05 14:37:16 +01:00 committed by GitHub
parent fb5efa203d
commit 123da4c844
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 102 additions and 102 deletions

View file

@ -6,64 +6,62 @@ import (
"github.com/coredns/caddy"
"github.com/coredns/coredns/core/dnsserver"
"github.com/coredns/coredns/plugin"
"github.com/coredns/coredns/plugin/dnstap/dnstapio"
clog "github.com/coredns/coredns/plugin/pkg/log"
"github.com/coredns/coredns/plugin/pkg/parse"
)
var log = clog.NewWithPlugin("dnstap")
func init() { plugin.Register("dnstap", setup) }
type config struct {
proto string
target string
full bool
}
func parseConfig(c *caddy.Controller) (Dnstap, error) {
c.Next() // directive name
d := Dnstap{}
endpoint := ""
func parseConfig(d *caddy.Controller) (c config, err error) {
d.Next() // directive name
if !d.Args(&c.target) {
return c, d.ArgErr()
if !c.Args(&endpoint) {
return d, c.ArgErr()
}
if strings.HasPrefix(c.target, "tcp://") {
if strings.HasPrefix(endpoint, "tcp://") {
// remote IP endpoint
servers, err := parse.HostPortOrFile(c.target[6:])
servers, err := parse.HostPortOrFile(endpoint[6:])
if err != nil {
return c, d.ArgErr()
return d, c.ArgErr()
}
c.target = servers[0]
c.proto = "tcp"
dio := newIO("tcp", servers[0])
d = Dnstap{io: dio}
} else {
c.target = strings.TrimPrefix(c.target, "unix://")
c.proto = "unix"
endpoint = strings.TrimPrefix(endpoint, "unix://")
dio := newIO("unix", endpoint)
d = Dnstap{io: dio}
}
c.full = d.NextArg() && d.Val() == "full"
d.IncludeRawMessage = c.NextArg() && c.Val() == "full"
return
return d, nil
}
func setup(c *caddy.Controller) error {
conf, err := parseConfig(c)
dnstap, 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()
if err := dnstap.io.(*dio).connect(); err != nil {
log.Errorf("No connection to dnstap endpoint: %s", err)
}
return nil
})
c.OnRestart(func() error {
dio.Close()
dnstap.io.(*dio).close()
return nil
})
c.OnFinalShutdown(func() error {
dio.Close()
dnstap.io.(*dio).close()
return nil
})