| 
									
										
										
										
											2017-07-24 23:12:50 +02:00
										 |  |  | package dnstap
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import (
 | 
					
						
							| 
									
										
										
										
											2018-04-22 08:34:35 +01:00
										 |  |  | 	"context"
 | 
					
						
							| 
									
										
										
										
											2018-03-01 03:19:01 +01:00
										 |  |  | 	"time"
 | 
					
						
							| 
									
										
										
										
											2017-07-24 23:12:50 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-14 09:36:06 +01:00
										 |  |  | 	"github.com/coredns/coredns/plugin"
 | 
					
						
							| 
									
										
										
										
											2017-07-24 23:12:50 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	tap "github.com/dnstap/golang-dnstap"
 | 
					
						
							|  |  |  | 	"github.com/miekg/dns"
 | 
					
						
							|  |  |  | )
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-01 12:41:41 +02:00
										 |  |  | // Dnstap is the dnstap handler.
 | 
					
						
							| 
									
										
										
										
											2017-07-24 23:12:50 +02:00
										 |  |  | type Dnstap struct {
 | 
					
						
							| 
									
										
										
										
											2017-09-14 09:36:06 +01:00
										 |  |  | 	Next plugin.Handler
 | 
					
						
							| 
									
										
										
										
											2020-11-05 14:37:16 +01:00
										 |  |  | 	io   tapper
 | 
					
						
							| 
									
										
										
										
											2018-03-01 03:19:01 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-12 19:10:35 +02:00
										 |  |  | 	// IncludeRawMessage will include the raw DNS message into the dnstap messages if true.
 | 
					
						
							|  |  |  | 	IncludeRawMessage bool
 | 
					
						
							| 
									
										
										
										
											2017-07-24 23:12:50 +02:00
										 |  |  | }
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-12 19:10:35 +02:00
										 |  |  | // TapMessage sends the message m to the dnstap interface.
 | 
					
						
							| 
									
										
										
										
											2018-08-02 00:58:23 +02:00
										 |  |  | func (h Dnstap) TapMessage(m *tap.Message) {
 | 
					
						
							| 
									
										
										
										
											2018-03-01 03:19:01 +01:00
										 |  |  | 	t := tap.Dnstap_MESSAGE
 | 
					
						
							| 
									
										
										
										
											2020-10-12 19:10:35 +02:00
										 |  |  | 	h.io.Dnstap(tap.Dnstap{Type: &t, Message: m})
 | 
					
						
							| 
									
										
										
										
											2017-09-01 12:41:41 +02:00
										 |  |  | }
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // ServeDNS logs the client query and response to dnstap and passes the dnstap Context.
 | 
					
						
							| 
									
										
										
										
											2017-07-24 23:12:50 +02:00
										 |  |  | func (h Dnstap) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (int, error) {
 | 
					
						
							| 
									
										
										
										
											2020-10-12 19:10:35 +02:00
										 |  |  | 	rw := &ResponseWriter{
 | 
					
						
							| 
									
										
										
										
											2018-03-01 03:19:01 +01:00
										 |  |  | 		ResponseWriter: w,
 | 
					
						
							| 
									
										
										
										
											2020-10-12 19:10:35 +02:00
										 |  |  | 		Dnstap:         h,
 | 
					
						
							| 
									
										
										
										
											2020-11-05 14:37:16 +01:00
										 |  |  | 		query:          r,
 | 
					
						
							|  |  |  | 		queryTime:      time.Now(),
 | 
					
						
							| 
									
										
										
										
											2017-07-24 23:12:50 +02:00
										 |  |  | 	}
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-12 19:10:35 +02:00
										 |  |  | 	return plugin.NextOrFailure(h.Name(), h.Next, ctx, rw, r)
 | 
					
						
							| 
									
										
										
										
											2017-07-24 23:12:50 +02:00
										 |  |  | }
 | 
					
						
							| 
									
										
										
										
											2017-09-01 12:41:41 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-12 19:10:35 +02:00
										 |  |  | // Name implements the plugin.Plugin interface.
 | 
					
						
							| 
									
										
										
										
											2017-07-24 23:12:50 +02:00
										 |  |  | func (h Dnstap) Name() string { return "dnstap" }
 |