mirror of
https://github.com/coredns/coredns.git
synced 2025-12-03 00:54:01 -05:00
auto make -f Makefile.doc
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
.\" Generated by Mmark Markdown Processer - mmark.miek.nl
|
||||
.TH "COREDNS-DNSTAP" 7 "September 2020" "CoreDNS" "CoreDNS Plugins"
|
||||
.TH "COREDNS-DNSTAP" 7 "October 2020" "CoreDNS" "CoreDNS Plugins"
|
||||
|
||||
.SH "NAME"
|
||||
.PP
|
||||
@@ -111,27 +111,44 @@ $ dnstap \-l 127.0.0.1:6000
|
||||
.RE
|
||||
|
||||
.SH "USING DNSTAP IN YOUR PLUGIN"
|
||||
.PP
|
||||
In your setup function, check to see if the \fIdnstap\fP plugin is loaded:
|
||||
|
||||
.PP
|
||||
.RS
|
||||
|
||||
.nf
|
||||
import (
|
||||
"github.com/coredns/coredns/plugin/dnstap"
|
||||
"github.com/coredns/coredns/plugin/dnstap/msg"
|
||||
)
|
||||
|
||||
func (h Dnstap) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (int, error) {
|
||||
// log client query to Dnstap
|
||||
if t := dnstap.TapperFromContext(ctx); t != nil {
|
||||
b := msg.New().Time(time.Now()).Addr(w.RemoteAddr())
|
||||
if t.Pack() {
|
||||
b.Msg(r)
|
||||
}
|
||||
if m, err := b.ToClientQuery(); err == nil {
|
||||
t.TapMessage(m)
|
||||
c.OnStartup(func() error {
|
||||
if taph := dnsserver.GetConfig(c).Handler("dnstap"); taph != nil {
|
||||
if tapPlugin, ok := taph.(dnstap.Dnstap); ok {
|
||||
f.tapPlugin = \&tapPlugin
|
||||
}
|
||||
}
|
||||
return nil
|
||||
})
|
||||
|
||||
.fi
|
||||
.RE
|
||||
|
||||
.PP
|
||||
And then in your plugin:
|
||||
|
||||
.PP
|
||||
.RS
|
||||
|
||||
.nf
|
||||
func (x RandomPlugin) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (int, error) {
|
||||
if tapPlugin != nil {
|
||||
q := new(msg.Msg)
|
||||
msg.SetQueryTime(q, time.Now())
|
||||
msg.SetQueryAddress(q, w.RemoteAddr())
|
||||
if tapPlugin.IncludeRawMessage {
|
||||
buf, \_ := r.Pack() // r has been seen packed/unpacked before, this should not fail
|
||||
q.QueryMessage = buf
|
||||
}
|
||||
msg.SetType(q, tap.Message\_CLIENT\_QUERY)
|
||||
tapPlugin.TapMessage(q)
|
||||
}
|
||||
// ...
|
||||
}
|
||||
|
||||
@@ -140,6 +157,7 @@ func (h Dnstap) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg)
|
||||
|
||||
.SH "SEE ALSO"
|
||||
.PP
|
||||
dnstap.info
|
||||
\[la]https://dnstap.info\[ra].
|
||||
The website dnstap.info
|
||||
\[la]https://dnstap.info\[ra] has info on the dnstap protocol.
|
||||
The \fIforward\fP plugin's \fB\fCdnstap.go\fR uses dnstap to tap messages sent to an upstream.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user