mirror of
https://github.com/coredns/coredns.git
synced 2025-11-24 20:54:02 -05:00
Plugin dnstap: add support for "extra" field in payload (#6226)
* dnstap: add 'extra' field Signed-off-by: chenyuheng <chenyuheng99@qq.com> * dnstap: add setup_test for 'extra' field Signed-off-by: chenyuheng <chenyuheng99@qq.com> * udnstap: update document and test Signed-off-by: chenyuheng <chenyuheng99@qq.com> * dnstap: update setup_test for more coverage Signed-off-by: chenyuheng <chenyuheng99@qq.com> * dnstap: add TapMessageWithMetadata function to Dnstap Signed-off-by: chenyuheng <chenyuheng99@qq.com> * dnstap: adapt dnstap and forward plugins to use TapMessageWithMetadata Signed-off-by: chenyuheng <chenyuheng99@qq.com> * change TapMessageWithMetadata function Signed-off-by: chenyuheng <chenyuheng99@qq.com> * tab inconsistency fix Signed-off-by: chenyuheng <chenyuheng99@qq.com> * fix replacer to support empty state Signed-off-by: chenyuheng <chenyuheng99@qq.com> * add replacer test for empty status parameter Signed-off-by: chenyuheng <chenyuheng99@qq.com> * dnstap: update unit test for 'extra' field Signed-off-by: chenyuheng <chenyuheng99@qq.com> * clean up code Signed-off-by: chenyuheng <chenyuheng99@qq.com> * gofmt fix & static analysis fix Signed-off-by: chenyuheng <chenyuheng99@qq.com> * dnstap: refactor Signed-off-by: chenyuheng <chenyuheng99@qq.com> --------- Signed-off-by: chenyuheng <chenyuheng99@qq.com>
This commit is contained in:
@@ -18,6 +18,7 @@ Every message is sent to the socket as soon as it comes in, the *dnstap* plugin
|
||||
dnstap SOCKET [full] {
|
||||
[identity IDENTITY]
|
||||
[version VERSION]
|
||||
[extra EXTRA]
|
||||
[skipverify]
|
||||
}
|
||||
~~~
|
||||
@@ -26,6 +27,7 @@ dnstap SOCKET [full] {
|
||||
* `full` to include the wire-format DNS message.
|
||||
* **IDENTITY** to override the identity of the server. Defaults to the hostname.
|
||||
* **VERSION** to override the version field. Defaults to the CoreDNS version.
|
||||
* **EXTRA** to define "extra" field in dnstap payload, [metadata](../metadata/) replacement available here.
|
||||
* `skipverify` to skip tls verification during connection. Default to be secure
|
||||
|
||||
## Examples
|
||||
@@ -63,6 +65,16 @@ dnstap /tmp/dnstap.sock {
|
||||
}
|
||||
~~~
|
||||
|
||||
Log to a socket, customize the "extra" field in dnstap payload. You may use metadata provided by other plugins in the extra field.
|
||||
|
||||
~~~ txt
|
||||
forward . 8.8.8.8
|
||||
metadata
|
||||
dnstap /tmp/dnstap.sock {
|
||||
extra "upstream: {/forward/upstream}"
|
||||
}
|
||||
~~~
|
||||
|
||||
Log to a remote TLS endpoint.
|
||||
|
||||
~~~ txt
|
||||
@@ -124,7 +136,9 @@ And then in your plugin:
|
||||
|
||||
~~~ go
|
||||
import (
|
||||
github.com/coredns/coredns/plugin/dnstap/msg
|
||||
"github.com/coredns/coredns/plugin/dnstap/msg"
|
||||
"github.com/coredns/coredns/request"
|
||||
|
||||
tap "github.com/dnstap/golang-dnstap"
|
||||
)
|
||||
|
||||
@@ -138,7 +152,12 @@ func (x ExamplePlugin) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dn
|
||||
q.QueryMessage = buf
|
||||
}
|
||||
msg.SetType(q, tap.Message_CLIENT_QUERY)
|
||||
|
||||
// if no metadata interpretation is needed, just send the message
|
||||
tapPlugin.TapMessage(q)
|
||||
|
||||
// OR: to interpret the metadata in "extra" field, give more context info
|
||||
tapPlugin.TapMessageWithMetadata(ctx, q, request.Request{W: w, Req: query})
|
||||
}
|
||||
// ...
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user