Commit dbb8a123 authored by lobshunter's avatar lobshunter Committed by GitHub

plugin/dnstap: support FQDN TCP endpoint (#5377)

* plugin/dnstap: support FQDN TCP endpoint
Signed-off-by: default avatarlob <pengyu@pingcap.com>

* plugin/dnstap: remove unused variable
Signed-off-by: default avatarlob <pengyu@pingcap.com>
parent 092c1444
......@@ -41,6 +41,12 @@ Log to a remote endpoint.
dnstap tcp://127.0.0.1:6000 full
~~~
Log to a remote endpoint by FQDN.
~~~ txt
dnstap tcp://example.com:6000 full
~~~
## Command Line Tool
Dnstap has a command line tool that can be used to inspect the logging. The tool can be found
......
......@@ -25,7 +25,6 @@ type tapper interface {
type dio struct {
endpoint string
proto string
conn net.Conn
enc *encoder
queue chan tap.Dnstap
dropped uint32
......
package dnstap
import (
"net/url"
"strings"
"github.com/coredns/caddy"
"github.com/coredns/coredns/core/dnsserver"
"github.com/coredns/coredns/plugin"
clog "github.com/coredns/coredns/plugin/pkg/log"
"github.com/coredns/coredns/plugin/pkg/parse"
)
var log = clog.NewWithPlugin("dnstap")
......@@ -24,12 +24,12 @@ func parseConfig(c *caddy.Controller) (Dnstap, error) {
}
if strings.HasPrefix(endpoint, "tcp://") {
// remote IP endpoint
servers, err := parse.HostPortOrFile(endpoint[6:])
// remote network endpoint
endpointURL, err := url.Parse(endpoint)
if err != nil {
return d, c.ArgErr()
}
dio := newIO("tcp", servers[0])
dio := newIO("tcp", endpointURL.Host)
d = Dnstap{io: dio}
} else {
endpoint = strings.TrimPrefix(endpoint, "unix://")
......
......@@ -17,6 +17,8 @@ func TestConfig(t *testing.T) {
{"dnstap dnstap.sock full", "dnstap.sock", true, "unix", false},
{"dnstap unix://dnstap.sock", "dnstap.sock", false, "unix", false},
{"dnstap tcp://127.0.0.1:6000", "127.0.0.1:6000", false, "tcp", false},
{"dnstap tcp://[::1]:6000", "[::1]:6000", false, "tcp", false},
{"dnstap tcp://example.com:6000", "example.com:6000", false, "tcp", false},
{"dnstap", "fail", false, "tcp", true},
}
for i, tc := range tests {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment