mirror of
				https://github.com/coredns/coredns.git
				synced 2025-10-30 17:53:21 -04:00 
			
		
		
		
	* core: add listening for other protocols
Allow CoreDNS to listen for TLS request coming over port 853. This can
be enabled with `tls://` in the config file.
Implement listening for grps:// as well.
a Corefile like:
~~~
. tls://.:1853 {
    whoami
    tls
}
~~~
Means we listen on 1853 for tls requests, the `tls` config item allows
configuration for TLS parameters. We *might* be tempted to use Caddy's
Let's Encrypt implementation here.
* Refactor coredns/grpc into CoreDNS
This makes gRPC a first class citizen in CoreDNS. Add defines as being
just another server.
* some cleanups
* unexport the servers
* Move protobuf dir
* Hook up TLS properly
* Fix test
* listen for TLS as well. README updates
* disable test, fix package
* fix test
* Fix tests
* Fix remaining test
* Some tests
* Make the test work
* Add grpc test from #580
* fix crash
* Fix tests
* Close conn
* README cleanups
* README
* link RFC
		
	
		
			
				
	
	
		
			75 lines
		
	
	
		
			1.5 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			75 lines
		
	
	
		
			1.5 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
| // Package erratic implements a middleware that returns erratic answers (delayed, dropped).
 | |
| package erratic
 | |
| 
 | |
| import (
 | |
| 	"sync/atomic"
 | |
| 
 | |
| 	"github.com/coredns/coredns/request"
 | |
| 
 | |
| 	"github.com/miekg/dns"
 | |
| 	"golang.org/x/net/context"
 | |
| )
 | |
| 
 | |
| // Erratic is a middleware that returns erratic repsonses to each client.
 | |
| type Erratic struct {
 | |
| 	amount uint64
 | |
| 
 | |
| 	q uint64 // counter of queries
 | |
| }
 | |
| 
 | |
| // ServeDNS implements the middleware.Handler interface.
 | |
| func (e *Erratic) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (int, error) {
 | |
| 	state := request.Request{W: w, Req: r}
 | |
| 
 | |
| 	drop := false
 | |
| 	if e.amount > 0 {
 | |
| 		queryNr := atomic.LoadUint64(&e.q)
 | |
| 
 | |
| 		if queryNr%e.amount == 0 {
 | |
| 			drop = true
 | |
| 		}
 | |
| 
 | |
| 		atomic.AddUint64(&e.q, 1)
 | |
| 	}
 | |
| 
 | |
| 	m := new(dns.Msg)
 | |
| 	m.SetReply(r)
 | |
| 	m.Compress = true
 | |
| 	m.Authoritative = true
 | |
| 
 | |
| 	// small dance to copy rrA or rrAAAA into a non-pointer var that allows us to overwrite the ownername
 | |
| 	// in a non-racy way.
 | |
| 	switch state.QType() {
 | |
| 	case dns.TypeA:
 | |
| 		rr := *(rrA.(*dns.A))
 | |
| 		rr.Header().Name = state.QName()
 | |
| 		m.Answer = append(m.Answer, &rr)
 | |
| 	case dns.TypeAAAA:
 | |
| 		rr := *(rrAAAA.(*dns.AAAA))
 | |
| 		rr.Header().Name = state.QName()
 | |
| 		m.Answer = append(m.Answer, &rr)
 | |
| 	default:
 | |
| 		if !drop {
 | |
| 			// coredns will return error.
 | |
| 			return dns.RcodeServerFailure, nil
 | |
| 		}
 | |
| 	}
 | |
| 
 | |
| 	if drop {
 | |
| 		return 0, nil
 | |
| 	}
 | |
| 
 | |
| 	state.SizeAndDo(m)
 | |
| 	w.WriteMsg(m)
 | |
| 
 | |
| 	return 0, nil
 | |
| }
 | |
| 
 | |
| // Name implements the Handler interface.
 | |
| func (e *Erratic) Name() string { return "erratic" }
 | |
| 
 | |
| var (
 | |
| 	rrA, _    = dns.NewRR(". IN 0 A 192.0.2.53")
 | |
| 	rrAAAA, _ = dns.NewRR(". IN 0 AAAA 2001:DB8::53")
 | |
| )
 |