plugin/dnstap: support FQDN TCP endpoint (#5377)
* plugin/dnstap: support FQDN TCP endpoint Signed-off-by: lob <pengyu@pingcap.com> * plugin/dnstap: remove unused variable Signed-off-by: lob <pengyu@pingcap.com>
This commit is contained in:
parent
092c144491
commit
dbb8a12394
4 changed files with 12 additions and 5 deletions
|
@ -41,6 +41,12 @@ Log to a remote endpoint.
|
||||||
dnstap tcp://127.0.0.1:6000 full
|
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
|
## Command Line Tool
|
||||||
|
|
||||||
Dnstap has a command line tool that can be used to inspect the logging. The tool can be found
|
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 {
|
type dio struct {
|
||||||
endpoint string
|
endpoint string
|
||||||
proto string
|
proto string
|
||||||
conn net.Conn
|
|
||||||
enc *encoder
|
enc *encoder
|
||||||
queue chan tap.Dnstap
|
queue chan tap.Dnstap
|
||||||
dropped uint32
|
dropped uint32
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
package dnstap
|
package dnstap
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"net/url"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/coredns/caddy"
|
"github.com/coredns/caddy"
|
||||||
"github.com/coredns/coredns/core/dnsserver"
|
"github.com/coredns/coredns/core/dnsserver"
|
||||||
"github.com/coredns/coredns/plugin"
|
"github.com/coredns/coredns/plugin"
|
||||||
clog "github.com/coredns/coredns/plugin/pkg/log"
|
clog "github.com/coredns/coredns/plugin/pkg/log"
|
||||||
"github.com/coredns/coredns/plugin/pkg/parse"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var log = clog.NewWithPlugin("dnstap")
|
var log = clog.NewWithPlugin("dnstap")
|
||||||
|
@ -24,12 +24,12 @@ func parseConfig(c *caddy.Controller) (Dnstap, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if strings.HasPrefix(endpoint, "tcp://") {
|
if strings.HasPrefix(endpoint, "tcp://") {
|
||||||
// remote IP endpoint
|
// remote network endpoint
|
||||||
servers, err := parse.HostPortOrFile(endpoint[6:])
|
endpointURL, err := url.Parse(endpoint)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return d, c.ArgErr()
|
return d, c.ArgErr()
|
||||||
}
|
}
|
||||||
dio := newIO("tcp", servers[0])
|
dio := newIO("tcp", endpointURL.Host)
|
||||||
d = Dnstap{io: dio}
|
d = Dnstap{io: dio}
|
||||||
} else {
|
} else {
|
||||||
endpoint = strings.TrimPrefix(endpoint, "unix://")
|
endpoint = strings.TrimPrefix(endpoint, "unix://")
|
||||||
|
|
|
@ -17,6 +17,8 @@ func TestConfig(t *testing.T) {
|
||||||
{"dnstap dnstap.sock full", "dnstap.sock", true, "unix", false},
|
{"dnstap dnstap.sock full", "dnstap.sock", true, "unix", false},
|
||||||
{"dnstap unix://dnstap.sock", "dnstap.sock", false, "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://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},
|
{"dnstap", "fail", false, "tcp", true},
|
||||||
}
|
}
|
||||||
for i, tc := range tests {
|
for i, tc := range tests {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue