| 
									
										
										
										
											2016-04-26 17:57:11 +01:00
										 |  |  | package dnssec
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import (
 | 
					
						
							| 
									
										
										
										
											2018-04-22 08:34:35 +01:00
										 |  |  | 	"context"
 | 
					
						
							| 
									
										
										
										
											2017-12-27 15:48:14 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-14 09:36:06 +01:00
										 |  |  | 	"github.com/coredns/coredns/plugin"
 | 
					
						
							| 
									
										
										
										
											2018-04-27 19:37:31 +01:00
										 |  |  | 	"github.com/coredns/coredns/plugin/metrics"
 | 
					
						
							| 
									
										
										
										
											2017-02-21 22:51:47 -08:00
										 |  |  | 	"github.com/coredns/coredns/request"
 | 
					
						
							| 
									
										
										
										
											2016-04-26 17:57:11 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	"github.com/miekg/dns"
 | 
					
						
							|  |  |  | 	"github.com/prometheus/client_golang/prometheus"
 | 
					
						
							|  |  |  | )
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-14 09:36:06 +01:00
										 |  |  | // ServeDNS implements the plugin.Handler interface.
 | 
					
						
							| 
									
										
										
										
											2016-04-26 17:57:11 +01:00
										 |  |  | func (d Dnssec) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (int, error) {
 | 
					
						
							| 
									
										
										
										
											2016-09-07 11:10:16 +01:00
										 |  |  | 	state := request.Request{W: w, Req: r}
 | 
					
						
							| 
									
										
										
										
											2016-04-26 17:57:11 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	do := state.Do()
 | 
					
						
							|  |  |  | 	qname := state.Name()
 | 
					
						
							|  |  |  | 	qtype := state.QType()
 | 
					
						
							| 
									
										
										
										
											2017-09-14 09:36:06 +01:00
										 |  |  | 	zone := plugin.Zones(d.zones).Matches(qname)
 | 
					
						
							| 
									
										
										
										
											2016-04-26 17:57:11 +01:00
										 |  |  | 	if zone == "" {
 | 
					
						
							| 
									
										
										
										
											2017-09-14 09:36:06 +01:00
										 |  |  | 		return plugin.NextOrFailure(d.Name(), d.Next, ctx, w, r)
 | 
					
						
							| 
									
										
										
										
											2016-04-26 17:57:11 +01:00
										 |  |  | 	}
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-03 11:11:56 +00:00
										 |  |  | 	state.Zone = zone
 | 
					
						
							| 
									
										
										
										
											2018-04-27 19:37:31 +01:00
										 |  |  | 	server := metrics.WithServer(ctx)
 | 
					
						
							| 
									
										
										
										
											2018-01-03 11:11:56 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-26 17:57:11 +01:00
										 |  |  | 	// Intercept queries for DNSKEY, but only if one of the zones matches the qname, otherwise we let
 | 
					
						
							|  |  |  | 	// the query through.
 | 
					
						
							|  |  |  | 	if qtype == dns.TypeDNSKEY {
 | 
					
						
							|  |  |  | 		for _, z := range d.zones {
 | 
					
						
							|  |  |  | 			if qname == z {
 | 
					
						
							| 
									
										
										
										
											2018-04-27 19:37:31 +01:00
										 |  |  | 				resp := d.getDNSKEY(state, z, do, server)
 | 
					
						
							| 
									
										
										
										
											2016-08-14 20:19:36 +02:00
										 |  |  | 				resp.Authoritative = true
 | 
					
						
							| 
									
										
										
										
											2016-04-26 17:57:11 +01:00
										 |  |  | 				w.WriteMsg(resp)
 | 
					
						
							|  |  |  | 				return dns.RcodeSuccess, nil
 | 
					
						
							|  |  |  | 			}
 | 
					
						
							|  |  |  | 		}
 | 
					
						
							|  |  |  | 	}
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-29 12:26:22 +01:00
										 |  |  | 	if do {
 | 
					
						
							|  |  |  | 		drr := &ResponseWriter{w, d, server}
 | 
					
						
							|  |  |  | 		return plugin.NextOrFailure(d.Name(), d.Next, ctx, drr, r)
 | 
					
						
							|  |  |  | 	}
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return plugin.NextOrFailure(d.Name(), d.Next, ctx, w, r)
 | 
					
						
							| 
									
										
										
										
											2016-04-26 17:57:11 +01:00
										 |  |  | }
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | var (
 | 
					
						
							| 
									
										
										
										
											2016-10-26 10:01:52 +01:00
										 |  |  | 	cacheSize = prometheus.NewGaugeVec(prometheus.GaugeOpts{
 | 
					
						
							| 
									
										
										
										
											2017-09-14 09:36:06 +01:00
										 |  |  | 		Namespace: plugin.Namespace,
 | 
					
						
							| 
									
										
										
										
											2017-12-27 15:48:14 +00:00
										 |  |  | 		Subsystem: "dnssec",
 | 
					
						
							| 
									
										
										
										
											2016-10-30 10:06:57 +01:00
										 |  |  | 		Name:      "cache_size",
 | 
					
						
							|  |  |  | 		Help:      "The number of elements in the dnssec cache.",
 | 
					
						
							| 
									
										
										
										
											2018-04-27 19:37:31 +01:00
										 |  |  | 	}, []string{"server", "type"})
 | 
					
						
							| 
									
										
										
										
											2016-04-26 17:57:11 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-26 10:01:52 +01:00
										 |  |  | 	cacheCapacity = prometheus.NewGaugeVec(prometheus.GaugeOpts{
 | 
					
						
							| 
									
										
										
										
											2017-09-14 09:36:06 +01:00
										 |  |  | 		Namespace: plugin.Namespace,
 | 
					
						
							| 
									
										
										
										
											2017-12-27 15:48:14 +00:00
										 |  |  | 		Subsystem: "dnssec",
 | 
					
						
							| 
									
										
										
										
											2016-10-30 10:06:57 +01:00
										 |  |  | 		Name:      "cache_capacity",
 | 
					
						
							|  |  |  | 		Help:      "The dnssec cache's capacity.",
 | 
					
						
							| 
									
										
										
										
											2018-04-27 19:37:31 +01:00
										 |  |  | 	}, []string{"server", "type"})
 | 
					
						
							| 
									
										
										
										
											2016-10-31 19:50:50 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-27 19:37:31 +01:00
										 |  |  | 	cacheHits = prometheus.NewCounterVec(prometheus.CounterOpts{
 | 
					
						
							| 
									
										
										
										
											2017-09-14 09:36:06 +01:00
										 |  |  | 		Namespace: plugin.Namespace,
 | 
					
						
							| 
									
										
										
										
											2017-12-27 15:48:14 +00:00
										 |  |  | 		Subsystem: "dnssec",
 | 
					
						
							| 
									
										
										
										
											2016-10-31 19:50:50 +01:00
										 |  |  | 		Name:      "cache_hits_total",
 | 
					
						
							|  |  |  | 		Help:      "The count of cache hits.",
 | 
					
						
							| 
									
										
										
										
											2018-04-27 19:37:31 +01:00
										 |  |  | 	}, []string{"server"})
 | 
					
						
							| 
									
										
										
										
											2016-10-31 19:50:50 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-27 19:37:31 +01:00
										 |  |  | 	cacheMisses = prometheus.NewCounterVec(prometheus.CounterOpts{
 | 
					
						
							| 
									
										
										
										
											2017-09-14 09:36:06 +01:00
										 |  |  | 		Namespace: plugin.Namespace,
 | 
					
						
							| 
									
										
										
										
											2017-12-27 15:48:14 +00:00
										 |  |  | 		Subsystem: "dnssec",
 | 
					
						
							| 
									
										
										
										
											2016-10-31 19:50:50 +01:00
										 |  |  | 		Name:      "cache_misses_total",
 | 
					
						
							|  |  |  | 		Help:      "The count of cache misses.",
 | 
					
						
							| 
									
										
										
										
											2018-04-27 19:37:31 +01:00
										 |  |  | 	}, []string{"server"})
 | 
					
						
							| 
									
										
										
										
											2016-04-26 17:57:11 +01:00
										 |  |  | )
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-27 11:48:37 +00:00
										 |  |  | // Name implements the Handler interface.
 | 
					
						
							| 
									
										
										
										
											2016-10-26 10:01:52 +01:00
										 |  |  | func (d Dnssec) Name() string { return "dnssec" }
 |