| 
									
										
										
										
											2019-08-30 15:58:25 +01:00
										 |  |  | .\" Generated by Mmark Markdown Processer - mmark.miek.nl | 
					
						
							| 
									
										
										
										
											2021-03-08 11:15:45 +00:00
										 |  |  | .TH "COREDNS-DNSTAP" 7 "March 2021" "CoreDNS" "CoreDNS Plugins" | 
					
						
							| 
									
										
										
										
											2019-04-06 08:42:40 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-24 12:37:27 +01:00
										 |  |  | .SH "NAME" | 
					
						
							| 
									
										
										
										
											2019-04-06 08:42:40 +01:00
										 |  |  | .PP | 
					
						
							| 
									
										
										
										
											2019-09-27 13:30:22 +01:00
										 |  |  | \fIdnstap\fP - enables logging to dnstap. | 
					
						
							| 
									
										
										
										
											2019-04-06 08:42:40 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-24 12:37:27 +01:00
										 |  |  | .SH "DESCRIPTION" | 
					
						
							| 
									
										
										
										
											2019-04-06 08:42:40 +01:00
										 |  |  | .PP | 
					
						
							| 
									
										
										
										
											2020-03-06 11:11:45 +00:00
										 |  |  | dnstap is a flexible, structured binary log format for DNS software; see https://dnstap.info | 
					
						
							|  |  |  | \[la]https://dnstap.info\[ra]. With this | 
					
						
							| 
									
										
										
										
											2019-04-06 08:42:40 +01:00
										 |  |  | plugin you make CoreDNS output dnstap logging. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | .PP | 
					
						
							| 
									
										
										
										
											2020-11-05 13:37:38 +00:00
										 |  |  | Every message is sent to the socket as soon as it comes in, the \fIdnstap\fP plugin has a buffer of | 
					
						
							|  |  |  | 10000 messages, above that number dnstap messages will be dropped (this is logged). | 
					
						
							| 
									
										
										
										
											2019-04-06 08:42:40 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-24 12:37:27 +01:00
										 |  |  | .SH "SYNTAX" | 
					
						
							| 
									
										
										
										
											2019-04-06 08:42:40 +01:00
										 |  |  | .PP | 
					
						
							|  |  |  | .RS | 
					
						
							| 
									
										
										
										
											2018-01-04 12:53:07 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-06 08:42:40 +01:00
										 |  |  | .nf | 
					
						
							| 
									
										
										
										
											2018-01-04 12:53:07 +00:00
										 |  |  | dnstap SOCKET [full] | 
					
						
							| 
									
										
										
										
											2019-04-06 08:42:40 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-04 12:53:07 +00:00
										 |  |  | .fi | 
					
						
							| 
									
										
										
										
											2019-04-06 08:42:40 +01:00
										 |  |  | .RE | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | .IP \(bu 4 | 
					
						
							| 
									
										
										
										
											2020-11-05 13:37:38 +00:00
										 |  |  | \fBSOCKET\fP is the socket (path) supplied to the dnstap command line tool. | 
					
						
							| 
									
										
										
										
											2019-04-06 08:42:40 +01:00
										 |  |  | .IP \(bu 4 | 
					
						
							|  |  |  | \fB\fCfull\fR to include the wire-format DNS message. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-24 12:37:27 +01:00
										 |  |  | .SH "EXAMPLES" | 
					
						
							| 
									
										
										
										
											2019-04-06 08:42:40 +01:00
										 |  |  | .PP | 
					
						
							|  |  |  | Log information about client requests and responses to \fI/tmp/dnstap.sock\fP. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | .PP | 
					
						
							|  |  |  | .RS | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-04 12:53:07 +00:00
										 |  |  | .nf | 
					
						
							| 
									
										
										
										
											2019-04-06 08:42:40 +01:00
										 |  |  | dnstap /tmp/dnstap.sock | 
					
						
							| 
									
										
										
										
											2018-01-04 12:53:07 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | .fi | 
					
						
							| 
									
										
										
										
											2019-04-06 08:42:40 +01:00
										 |  |  | .RE | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | .PP | 
					
						
							|  |  |  | Log information including the wire-format DNS message about client requests and responses to \fI/tmp/dnstap.sock\fP. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | .PP | 
					
						
							|  |  |  | .RS | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-04 12:53:07 +00:00
										 |  |  | .nf | 
					
						
							| 
									
										
										
										
											2019-04-06 08:42:40 +01:00
										 |  |  | dnstap unix:///tmp/dnstap.sock full | 
					
						
							| 
									
										
										
										
											2018-01-04 12:53:07 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | .fi | 
					
						
							| 
									
										
										
										
											2019-04-06 08:42:40 +01:00
										 |  |  | .RE | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | .PP | 
					
						
							|  |  |  | Log to a remote endpoint. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | .PP | 
					
						
							|  |  |  | .RS | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-04 12:53:07 +00:00
										 |  |  | .nf | 
					
						
							| 
									
										
										
										
											2019-04-06 08:42:40 +01:00
										 |  |  | dnstap tcp://127.0.0.1:6000 full | 
					
						
							| 
									
										
										
										
											2018-01-04 12:53:07 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | .fi | 
					
						
							| 
									
										
										
										
											2019-04-06 08:42:40 +01:00
										 |  |  | .RE | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-24 12:37:27 +01:00
										 |  |  | .SH "COMMAND LINE TOOL" | 
					
						
							| 
									
										
										
										
											2019-04-06 08:42:40 +01:00
										 |  |  | .PP | 
					
						
							|  |  |  | Dnstap has a command line tool that can be used to inspect the logging. The tool can be found | 
					
						
							| 
									
										
										
										
											2024-10-02 01:15:42 +09:00
										 |  |  | at GitHub: https://github.com/dnstap/golang-dnstap | 
					
						
							| 
									
										
										
										
											2019-04-06 08:42:40 +01:00
										 |  |  | \[la]https://github.com/dnstap/golang-dnstap\[ra]. It's written in Go. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | .PP | 
					
						
							|  |  |  | The following command listens on the given socket and decodes messages to stdout. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | .PP | 
					
						
							|  |  |  | .RS | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-04 12:53:07 +00:00
										 |  |  | .nf | 
					
						
							| 
									
										
										
										
											2019-04-06 08:42:40 +01:00
										 |  |  | $ dnstap \-u /tmp/dnstap.sock | 
					
						
							| 
									
										
										
										
											2018-01-04 12:53:07 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | .fi | 
					
						
							| 
									
										
										
										
											2019-04-06 08:42:40 +01:00
										 |  |  | .RE | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | .PP | 
					
						
							|  |  |  | The following command listens on the given socket and saves message payloads to a binary dnstap-format log file. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | .PP | 
					
						
							|  |  |  | .RS | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-04 12:53:07 +00:00
										 |  |  | .nf | 
					
						
							| 
									
										
										
										
											2019-04-06 08:42:40 +01:00
										 |  |  | $ dnstap \-u /tmp/dnstap.sock \-w /tmp/test.dnstap | 
					
						
							| 
									
										
										
										
											2018-01-04 12:53:07 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | .fi | 
					
						
							| 
									
										
										
										
											2019-04-06 08:42:40 +01:00
										 |  |  | .RE | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | .PP | 
					
						
							|  |  |  | Listen for dnstap messages on port 6000. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | .PP | 
					
						
							|  |  |  | .RS | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-04 12:53:07 +00:00
										 |  |  | .nf | 
					
						
							| 
									
										
										
										
											2019-04-06 08:42:40 +01:00
										 |  |  | $ dnstap \-l 127.0.0.1:6000 | 
					
						
							| 
									
										
										
										
											2018-01-04 12:53:07 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | .fi | 
					
						
							| 
									
										
										
										
											2019-04-06 08:42:40 +01:00
										 |  |  | .RE | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-24 12:37:27 +01:00
										 |  |  | .SH "USING DNSTAP IN YOUR PLUGIN" | 
					
						
							| 
									
										
										
										
											2020-10-12 17:10:58 +00:00
										 |  |  | .PP | 
					
						
							|  |  |  | In your setup function, check to see if the \fIdnstap\fP plugin is loaded: | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-06 08:42:40 +01:00
										 |  |  | .PP | 
					
						
							|  |  |  | .RS | 
					
						
							| 
									
										
										
										
											2018-03-05 19:58:28 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-06 08:42:40 +01:00
										 |  |  | .nf | 
					
						
							| 
									
										
										
										
											2020-10-12 17:10:58 +00:00
										 |  |  | c.OnStartup(func() error { | 
					
						
							|  |  |  |     if taph := dnsserver.GetConfig(c).Handler("dnstap"); taph != nil { | 
					
						
							|  |  |  |         if tapPlugin, ok := taph.(dnstap.Dnstap); ok { | 
					
						
							|  |  |  |             f.tapPlugin = \&tapPlugin | 
					
						
							| 
									
										
										
										
											2018-03-05 19:58:28 +00:00
										 |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-10-12 17:10:58 +00:00
										 |  |  |     return nil | 
					
						
							|  |  |  | }) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | .fi | 
					
						
							|  |  |  | .RE | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | .PP | 
					
						
							|  |  |  | And then in your plugin: | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | .PP | 
					
						
							|  |  |  | .RS | 
					
						
							| 
									
										
										
										
											2018-03-05 19:58:28 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-12 17:10:58 +00:00
										 |  |  | .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) | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-04-06 08:42:40 +01:00
										 |  |  |     // ... | 
					
						
							| 
									
										
										
										
											2018-03-05 19:58:28 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2019-04-06 08:42:40 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-05 19:58:28 +00:00
										 |  |  | .fi | 
					
						
							| 
									
										
										
										
											2019-04-06 08:42:40 +01:00
										 |  |  | .RE | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-24 12:37:27 +01:00
										 |  |  | .SH "SEE ALSO" | 
					
						
							| 
									
										
										
										
											2019-04-06 08:42:40 +01:00
										 |  |  | .PP | 
					
						
							| 
									
										
										
										
											2020-10-12 17:10:58 +00:00
										 |  |  | The website dnstap.info | 
					
						
							| 
									
										
										
										
											2020-11-05 13:37:38 +00:00
										 |  |  | \[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. | 
					
						
							| 
									
										
										
										
											2019-04-06 08:42:40 +01:00
										 |  |  | 
 |