mirror of
				https://github.com/coredns/coredns.git
				synced 2025-10-31 18:23:13 -04:00 
			
		
		
		
	* Update all plugins to use plugin/pkg/log I wish this could have been done with sed. Alas manually changed all callers to use the new plugin/pkg/log package. * Error -> Info * Add docs to debug plugin as well
		
			
				
	
	
		
			50 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			50 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
| package dnssec
 | |
| 
 | |
| import (
 | |
| 	"time"
 | |
| 
 | |
| 	"github.com/coredns/coredns/plugin"
 | |
| 	"github.com/coredns/coredns/plugin/pkg/log"
 | |
| 	"github.com/coredns/coredns/request"
 | |
| 
 | |
| 	"github.com/miekg/dns"
 | |
| )
 | |
| 
 | |
| // ResponseWriter sign the response on the fly.
 | |
| type ResponseWriter struct {
 | |
| 	dns.ResponseWriter
 | |
| 	d Dnssec
 | |
| }
 | |
| 
 | |
| // WriteMsg implements the dns.ResponseWriter interface.
 | |
| func (d *ResponseWriter) WriteMsg(res *dns.Msg) error {
 | |
| 	// By definition we should sign anything that comes back, we should still figure out for
 | |
| 	// which zone it should be.
 | |
| 	state := request.Request{W: d.ResponseWriter, Req: res}
 | |
| 
 | |
| 	zone := plugin.Zones(d.d.zones).Matches(state.Name())
 | |
| 	if zone == "" {
 | |
| 		return d.ResponseWriter.WriteMsg(res)
 | |
| 	}
 | |
| 	state.Zone = zone
 | |
| 
 | |
| 	if state.Do() {
 | |
| 		res = d.d.Sign(state, time.Now().UTC())
 | |
| 
 | |
| 		cacheSize.WithLabelValues("signature").Set(float64(d.d.cache.Len()))
 | |
| 	}
 | |
| 	state.SizeAndDo(res)
 | |
| 
 | |
| 	return d.ResponseWriter.WriteMsg(res)
 | |
| }
 | |
| 
 | |
| // Write implements the dns.ResponseWriter interface.
 | |
| func (d *ResponseWriter) Write(buf []byte) (int, error) {
 | |
| 	log.Warning("Dnssec called with Write: not signing reply")
 | |
| 	n, err := d.ResponseWriter.Write(buf)
 | |
| 	return n, err
 | |
| }
 | |
| 
 | |
| // Hijack implements the dns.ResponseWriter interface.
 | |
| func (d *ResponseWriter) Hijack() { d.ResponseWriter.Hijack() }
 |