mirror of
				https://github.com/coredns/coredns.git
				synced 2025-10-31 10:13:14 -04:00 
			
		
		
		
	* Fix linter errors * More linting fixes * More docs and making members private that dont need to be public * Fix linter errors * More linting fixes * More docs and making members private that dont need to be public * More lint fixes This leaves: ~~~ middleware/kubernetes/nametemplate/nametemplate.go:64:6: exported type NameTemplate should have comment or be unexported middleware/kubernetes/nametemplate/nametemplate.go:71:1: exported method NameTemplate.SetTemplate should have comment or be unexported middleware/kubernetes/nametemplate/nametemplate.go:108:1: exported method NameTemplate.GetZoneFromSegmentArray should have comment or be unexported middleware/kubernetes/nametemplate/nametemplate.go:116:1: exported method NameTemplate.GetNamespaceFromSegmentArray should have comment or be unexported middleware/kubernetes/nametemplate/nametemplate.go:120:1: exported method NameTemplate.GetServiceFromSegmentArray should have comment or be unexported middleware/kubernetes/nametemplate/nametemplate.go:124:1: exported method NameTemplate.GetTypeFromSegmentArray should have comment or be unexported middleware/kubernetes/nametemplate/nametemplate.go:135:1: exported method NameTemplate.GetSymbolFromSegmentArray should have comment or be unexported middleware/kubernetes/nametemplate/nametemplate.go:167:1: exported method NameTemplate.IsValid should have comment or be unexported middleware/kubernetes/nametemplate/nametemplate.go:182:6: exported type NameValues should have comment or be unexported middleware/kubernetes/util/util.go:1:1: package comment should be of the form "Package util ..." middleware/kubernetes/util/util.go:27:2: exported const WildcardStar should have comment (or a comment on this block) or be unexported middleware/proxy/lookup.go:66:1: exported method Proxy.Forward should have comment or be unexported middleware/proxy/proxy.go:24:6: exported type Client should have comment or be unexported middleware/proxy/proxy.go:107:1: exported function Clients should have comment or be unexported middleware/proxy/reverseproxy.go:10:6: exported type ReverseProxy should have comment or be unexported middleware/proxy/reverseproxy.go:16:1: exported method ReverseProxy.ServeDNS should have comment or be unexported middleware/proxy/upstream.go:42:6: exported type Options should have comment or be unexported ~~~ I plan on reworking the proxy anyway, so I'll leave that be.
		
			
				
	
	
		
			124 lines
		
	
	
		
			3.0 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			124 lines
		
	
	
		
			3.0 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
| package file
 | |
| 
 | |
| import (
 | |
| 	"errors"
 | |
| 	"io"
 | |
| 	"log"
 | |
| 
 | |
| 	"github.com/miekg/coredns/middleware"
 | |
| 	"github.com/miekg/coredns/request"
 | |
| 
 | |
| 	"github.com/miekg/dns"
 | |
| 	"golang.org/x/net/context"
 | |
| )
 | |
| 
 | |
| type (
 | |
| 	// File is the middleware that reads zone data from disk.
 | |
| 	File struct {
 | |
| 		Next  middleware.Handler
 | |
| 		Zones Zones
 | |
| 	}
 | |
| 
 | |
| 	// Zones maps zone names to a *Zone.
 | |
| 	Zones struct {
 | |
| 		Z     map[string]*Zone
 | |
| 		Names []string
 | |
| 	}
 | |
| )
 | |
| 
 | |
| // ServeDNS implements the middleware.Handle interface.
 | |
| func (f File) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (int, error) {
 | |
| 	state := request.Request{W: w, Req: r}
 | |
| 
 | |
| 	if state.QClass() != dns.ClassINET {
 | |
| 		return dns.RcodeServerFailure, errors.New("can only deal with ClassINET")
 | |
| 	}
 | |
| 	qname := state.Name()
 | |
| 	zone := middleware.Zones(f.Zones.Names).Matches(qname)
 | |
| 	if zone == "" {
 | |
| 		if f.Next != nil {
 | |
| 			return f.Next.ServeDNS(ctx, w, r)
 | |
| 		}
 | |
| 		return dns.RcodeServerFailure, errors.New("no next middleware found")
 | |
| 	}
 | |
| 	z, ok := f.Zones.Z[zone]
 | |
| 	if !ok {
 | |
| 		return f.Next.ServeDNS(ctx, w, r)
 | |
| 	}
 | |
| 	if z == nil {
 | |
| 		return dns.RcodeServerFailure, nil
 | |
| 	}
 | |
| 	if r.Opcode == dns.OpcodeNotify {
 | |
| 		if z.isNotify(state) {
 | |
| 			m := new(dns.Msg)
 | |
| 			m.SetReply(r)
 | |
| 			m.Authoritative, m.RecursionAvailable, m.Compress = true, true, true
 | |
| 			state.SizeAndDo(m)
 | |
| 			w.WriteMsg(m)
 | |
| 
 | |
| 			log.Printf("[INFO] Notify from %s for %s: checking transfer", state.IP(), zone)
 | |
| 			ok, err := z.shouldTransfer()
 | |
| 			if ok {
 | |
| 				z.TransferIn()
 | |
| 			} else {
 | |
| 				log.Printf("[INFO] Notify from %s for %s: no serial increase seen", state.IP(), zone)
 | |
| 			}
 | |
| 			if err != nil {
 | |
| 				log.Printf("[WARNING] Notify from %s for %s: failed primary check: %s", state.IP(), zone, err)
 | |
| 			}
 | |
| 			return dns.RcodeSuccess, nil
 | |
| 		}
 | |
| 		log.Printf("[INFO] Dropping notify from %s for %s", state.IP(), zone)
 | |
| 		return dns.RcodeSuccess, nil
 | |
| 	}
 | |
| 
 | |
| 	if z.Expired != nil && *z.Expired {
 | |
| 		log.Printf("[ERROR] Zone %s is expired", zone)
 | |
| 		return dns.RcodeServerFailure, nil
 | |
| 	}
 | |
| 
 | |
| 	if state.QType() == dns.TypeAXFR || state.QType() == dns.TypeIXFR {
 | |
| 		xfr := Xfr{z}
 | |
| 		return xfr.ServeDNS(ctx, w, r)
 | |
| 	}
 | |
| 
 | |
| 	answer, ns, extra, result := z.Lookup(qname, state.QType(), state.Do())
 | |
| 
 | |
| 	m := new(dns.Msg)
 | |
| 	m.SetReply(r)
 | |
| 	m.Authoritative, m.RecursionAvailable, m.Compress = true, true, true
 | |
| 	m.Answer, m.Ns, m.Extra = answer, ns, extra
 | |
| 
 | |
| 	switch result {
 | |
| 	case Success:
 | |
| 	case NoData:
 | |
| 	case NameError:
 | |
| 		m.Rcode = dns.RcodeNameError
 | |
| 	case Delegation:
 | |
| 		m.Authoritative = false
 | |
| 	case ServerFailure:
 | |
| 		return dns.RcodeServerFailure, nil
 | |
| 	}
 | |
| 
 | |
| 	state.SizeAndDo(m)
 | |
| 	m, _ = state.Scrub(m)
 | |
| 	w.WriteMsg(m)
 | |
| 	return dns.RcodeSuccess, nil
 | |
| }
 | |
| 
 | |
| // Parse parses the zone in filename and returns a new Zone or an error.
 | |
| func Parse(f io.Reader, origin, fileName string) (*Zone, error) {
 | |
| 	tokens := dns.ParseZone(f, dns.Fqdn(origin), fileName)
 | |
| 	z := NewZone(origin, fileName)
 | |
| 	for x := range tokens {
 | |
| 		if x.Error != nil {
 | |
| 			log.Printf("[ERROR] Failed to parse `%s': %v", origin, x.Error)
 | |
| 			return nil, x.Error
 | |
| 		}
 | |
| 		if err := z.Insert(x.RR); err != nil {
 | |
| 			return nil, err
 | |
| 		}
 | |
| 	}
 | |
| 	return z, nil
 | |
| }
 |