mirror of
				https://github.com/coredns/coredns.git
				synced 2025-11-03 10:43:20 -05:00 
			
		
		
		
	Random fixes and make servfail the special return code
This commit is contained in:
		@@ -48,13 +48,17 @@ func NewReplacer(r *dns.Msg, rr *ResponseRecorder, emptyValue string) Replacer {
 | 
				
			|||||||
		emptyValue: emptyValue,
 | 
							emptyValue: emptyValue,
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	if rr != nil {
 | 
						if rr != nil {
 | 
				
			||||||
		rep.replacements["{rcode}"] = strconv.Itoa(rr.rcode)
 | 
							rcode := dns.RcodeToString[rr.rcode]
 | 
				
			||||||
 | 
							if rcode == "" {
 | 
				
			||||||
 | 
								rcode = strconv.Itoa(rr.rcode)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							rep.replacements["{rcode}"] = rcode
 | 
				
			||||||
		rep.replacements["{size}"] = strconv.Itoa(rr.size)
 | 
							rep.replacements["{size}"] = strconv.Itoa(rr.size)
 | 
				
			||||||
		rep.replacements["{latency}"] = time.Since(rr.start).String()
 | 
							rep.replacements["{latency}"] = time.Since(rr.start).String()
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Header placeholders (case-insensitive)
 | 
						// Header placeholders (case-insensitive)
 | 
				
			||||||
	// TODO(miek): syntax for flags
 | 
						// TODO(miek): syntax for flags and document it
 | 
				
			||||||
	rep.replacements[headerReplacer+"id}"] = strconv.Itoa(int(r.Id))
 | 
						rep.replacements[headerReplacer+"id}"] = strconv.Itoa(int(r.Id))
 | 
				
			||||||
	rep.replacements[headerReplacer+"opcode}"] = strconv.Itoa(int(r.Opcode))
 | 
						rep.replacements[headerReplacer+"opcode}"] = strconv.Itoa(int(r.Opcode))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -260,7 +260,7 @@ func (s *Server) ServeDNS(w dns.ResponseWriter, r *dns.Msg) {
 | 
				
			|||||||
		// In case the user doesn't enable error middleware, we still
 | 
							// In case the user doesn't enable error middleware, we still
 | 
				
			||||||
		// need to make sure that we stay alive up here
 | 
							// need to make sure that we stay alive up here
 | 
				
			||||||
		if rec := recover(); rec != nil {
 | 
							if rec := recover(); rec != nil {
 | 
				
			||||||
			// TODO(miek): serverfailure return?
 | 
								DefaultErrorFunc(w, r, rcode)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}()
 | 
						}()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -286,7 +286,7 @@ func (s *Server) ServeDNS(w dns.ResponseWriter, r *dns.Msg) {
 | 
				
			|||||||
		if h, ok := s.zones[string(b[:l])]; ok {
 | 
							if h, ok := s.zones[string(b[:l])]; ok {
 | 
				
			||||||
			if r.Question[0].Qtype != dns.TypeDS {
 | 
								if r.Question[0].Qtype != dns.TypeDS {
 | 
				
			||||||
				rcode, _ := h.stack.ServeDNS(ctx, w, r)
 | 
									rcode, _ := h.stack.ServeDNS(ctx, w, r)
 | 
				
			||||||
				if rcode > 0 {
 | 
									if rcode == dns.RcodeServerFailure {
 | 
				
			||||||
					DefaultErrorFunc(w, r, rcode)
 | 
										DefaultErrorFunc(w, r, rcode)
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
				return
 | 
									return
 | 
				
			||||||
@@ -300,8 +300,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.
 | 
						// Wildcard match, if we have found nothing try the root zone as a last resort.
 | 
				
			||||||
	if h, ok := s.zones["."]; ok {
 | 
						if h, ok := s.zones["."]; ok {
 | 
				
			||||||
		rcode, _ := h.stack.ServeDNS(ctx, w, r)
 | 
							rcode, _ := h.stack.ServeDNS(ctx, w, r)
 | 
				
			||||||
		// TODO(miek): Double check if we have written something.
 | 
							if rcode == dns.RcodeServerFailure {
 | 
				
			||||||
		if rcode > 0 {
 | 
					 | 
				
			||||||
			DefaultErrorFunc(w, r, rcode)
 | 
								DefaultErrorFunc(w, r, rcode)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		return
 | 
							return
 | 
				
			||||||
@@ -310,8 +309,6 @@ func (s *Server) ServeDNS(w dns.ResponseWriter, r *dns.Msg) {
 | 
				
			|||||||
	// Still here? Error out with SERVFAIL and some logging
 | 
						// Still here? Error out with SERVFAIL and some logging
 | 
				
			||||||
	remoteHost := w.RemoteAddr().String()
 | 
						remoteHost := w.RemoteAddr().String()
 | 
				
			||||||
	DefaultErrorFunc(w, r, dns.RcodeServerFailure)
 | 
						DefaultErrorFunc(w, r, dns.RcodeServerFailure)
 | 
				
			||||||
 | 
					 | 
				
			||||||
	fmt.Fprintf(w, "No such zone at %s", s.Addr)
 | 
					 | 
				
			||||||
	log.Printf("[INFO] %s - No such zone at %s (Remote: %s)", q, s.Addr, remoteHost)
 | 
						log.Printf("[INFO] %s - No such zone at %s (Remote: %s)", q, s.Addr, remoteHost)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user