mirror of
https://github.com/coredns/coredns.git
synced 2025-10-27 08:14:18 -04:00
Cleanup and fixes (#223)
* Set version to 001 * Remove k8stest, test fails is k8s is not there: touch luck * Remove server directory: not used anymore * Disable k8s test (for now) * gometalinter changes
This commit is contained in:
@@ -6,21 +6,19 @@ import (
|
||||
|
||||
// plug in the standard directives
|
||||
_ "github.com/miekg/coredns/middleware/bind"
|
||||
_ "github.com/miekg/coredns/middleware/health"
|
||||
_ "github.com/miekg/coredns/middleware/pprof"
|
||||
|
||||
_ "github.com/miekg/coredns/middleware/errors"
|
||||
_ "github.com/miekg/coredns/middleware/loadbalance"
|
||||
_ "github.com/miekg/coredns/middleware/log"
|
||||
_ "github.com/miekg/coredns/middleware/metrics"
|
||||
_ "github.com/miekg/coredns/middleware/rewrite"
|
||||
|
||||
_ "github.com/miekg/coredns/middleware/cache"
|
||||
_ "github.com/miekg/coredns/middleware/chaos"
|
||||
_ "github.com/miekg/coredns/middleware/dnssec"
|
||||
_ "github.com/miekg/coredns/middleware/errors"
|
||||
_ "github.com/miekg/coredns/middleware/etcd"
|
||||
_ "github.com/miekg/coredns/middleware/file"
|
||||
_ "github.com/miekg/coredns/middleware/health"
|
||||
_ "github.com/miekg/coredns/middleware/kubernetes"
|
||||
_ "github.com/miekg/coredns/middleware/loadbalance"
|
||||
_ "github.com/miekg/coredns/middleware/log"
|
||||
_ "github.com/miekg/coredns/middleware/metrics"
|
||||
_ "github.com/miekg/coredns/middleware/pprof"
|
||||
_ "github.com/miekg/coredns/middleware/proxy"
|
||||
_ "github.com/miekg/coredns/middleware/rewrite"
|
||||
_ "github.com/miekg/coredns/middleware/secondary"
|
||||
)
|
||||
|
||||
@@ -9,7 +9,7 @@ package dnsserver
|
||||
// feel the effects of all other middleware below
|
||||
// (after) them during a request, but they must not
|
||||
// care what middleware above them are doing.
|
||||
var Directives = []string{
|
||||
var directives = []string{
|
||||
"bind",
|
||||
"health",
|
||||
"pprof",
|
||||
|
||||
@@ -13,7 +13,7 @@ const serverType = "dns"
|
||||
|
||||
func init() {
|
||||
caddy.RegisterServerType(serverType, caddy.ServerType{
|
||||
Directives: Directives,
|
||||
Directives: directives,
|
||||
DefaultInput: func() caddy.Input {
|
||||
if Port == DefaultPort && Zone != "" {
|
||||
return caddy.CaddyfileInput{
|
||||
@@ -32,8 +32,6 @@ func init() {
|
||||
})
|
||||
}
|
||||
|
||||
var TestNewContext = newContext
|
||||
|
||||
func newContext() caddy.Context {
|
||||
return &dnsContext{keysToConfigs: make(map[string]*Config)}
|
||||
}
|
||||
@@ -103,8 +101,8 @@ func (h *dnsContext) MakeServers() ([]caddy.Server, error) {
|
||||
}
|
||||
|
||||
// AddMiddleware adds a middleware to a site's middleware stack.
|
||||
func (sc *Config) AddMiddleware(m Middleware) {
|
||||
sc.Middleware = append(sc.Middleware, m)
|
||||
func (c *Config) AddMiddleware(m Middleware) {
|
||||
c.Middleware = append(c.Middleware, m)
|
||||
}
|
||||
|
||||
// groupSiteConfigsByListenAddr groups site configs by their listen
|
||||
|
||||
@@ -32,6 +32,7 @@ type Server struct {
|
||||
connTimeout time.Duration // the maximum duration of a graceful shutdown
|
||||
}
|
||||
|
||||
// NewServer returns a new CoreDNS server and compiles all middleware in to it.
|
||||
func NewServer(addr string, group []*Config) (*Server, error) {
|
||||
|
||||
s := &Server{
|
||||
@@ -65,20 +66,6 @@ func NewServer(addr string, group []*Config) (*Server, error) {
|
||||
return s, nil
|
||||
}
|
||||
|
||||
// LocalAddr return the addresses where the server is bound to.
|
||||
func (s *Server) LocalAddr() net.Addr {
|
||||
s.m.Lock()
|
||||
defer s.m.Unlock()
|
||||
return s.l.Addr()
|
||||
}
|
||||
|
||||
// LocalAddrPacket return the net.PacketConn address where the server is bound to.
|
||||
func (s *Server) LocalAddrPacket() net.Addr {
|
||||
s.m.Lock()
|
||||
defer s.m.Unlock()
|
||||
return s.p.LocalAddr()
|
||||
}
|
||||
|
||||
// Serve starts the server with an existing listener. It blocks until the server stops.
|
||||
func (s *Server) Serve(l net.Listener) error {
|
||||
s.m.Lock()
|
||||
@@ -97,6 +84,7 @@ func (s *Server) ServePacket(p net.PacketConn) error {
|
||||
return s.server[udp].ActivateAndServe()
|
||||
}
|
||||
|
||||
// Listen implements caddy.TCPServer interface.
|
||||
func (s *Server) Listen() (net.Listener, error) {
|
||||
l, err := net.Listen("tcp", s.Addr)
|
||||
if err != nil {
|
||||
@@ -108,6 +96,7 @@ func (s *Server) Listen() (net.Listener, error) {
|
||||
return l, nil
|
||||
}
|
||||
|
||||
// ListenPacket implements caddy.UDPServer interface.
|
||||
func (s *Server) ListenPacket() (net.PacketConn, error) {
|
||||
p, err := net.ListenPacket("udp", s.Addr)
|
||||
if err != nil {
|
||||
@@ -197,7 +186,7 @@ func (s *Server) ServeDNS(w dns.ResponseWriter, r *dns.Msg) {
|
||||
if h, ok := s.zones[string(b[:l])]; ok {
|
||||
if r.Question[0].Qtype != dns.TypeDS {
|
||||
rcode, _ := h.middlewareChain.ServeDNS(ctx, w, r)
|
||||
if RcodeNoClientWrite(rcode) {
|
||||
if rcodeNoClientWrite(rcode) {
|
||||
DefaultErrorFunc(w, r, rcode)
|
||||
}
|
||||
return
|
||||
@@ -211,7 +200,7 @@ func (s *Server) ServeDNS(w dns.ResponseWriter, r *dns.Msg) {
|
||||
// Wildcard match, if we have found nothing try the root zone as a last resort.
|
||||
if h, ok := s.zones["."]; ok {
|
||||
rcode, _ := h.middlewareChain.ServeDNS(ctx, w, r)
|
||||
if RcodeNoClientWrite(rcode) {
|
||||
if rcodeNoClientWrite(rcode) {
|
||||
DefaultErrorFunc(w, r, rcode)
|
||||
}
|
||||
return
|
||||
@@ -234,7 +223,7 @@ func DefaultErrorFunc(w dns.ResponseWriter, r *dns.Msg, rcode int) {
|
||||
w.WriteMsg(answer)
|
||||
}
|
||||
|
||||
func RcodeNoClientWrite(rcode int) bool {
|
||||
func rcodeNoClientWrite(rcode int) bool {
|
||||
switch rcode {
|
||||
case dns.RcodeServerFailure:
|
||||
fallthrough
|
||||
|
||||
Reference in New Issue
Block a user