| 
									
										
										
										
											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" | 
					
						
							|  |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											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
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											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" } |