mirror of
				https://github.com/coredns/coredns.git
				synced 2025-10-30 17:53:21 -04:00 
			
		
		
		
	middleware/file|auto: Notifies and AXFR (#399)
Be more explicit in the logs when a notify fails. New notify error message looks like: 2016/11/07 18:21:42 [ERROR] Notify for zone "example.org." was not accepted by "8.8.8.8:53": rcode was "SERVFAIL" Correctly pick up secondaries When multiple secondary are specified make sure they are picked up. Fixes #393 #398
This commit is contained in:
		| @@ -127,7 +127,7 @@ func autoParse(c *caddy.Controller) (Auto, error) { | |||||||
| 						a.loader.template = rewriteToExpand(c.Val()) | 						a.loader.template = rewriteToExpand(c.Val()) | ||||||
| 					} | 					} | ||||||
|  |  | ||||||
| 					// template | 					// duration | ||||||
| 					if c.NextArg() { | 					if c.NextArg() { | ||||||
| 						i, err := strconv.Atoi(c.Val()) | 						i, err := strconv.Atoi(c.Val()) | ||||||
| 						if err != nil { | 						if err != nil { | ||||||
| @@ -147,7 +147,9 @@ func autoParse(c *caddy.Controller) (Auto, error) { | |||||||
| 					if e != nil { | 					if e != nil { | ||||||
| 						return a, e | 						return a, e | ||||||
| 					} | 					} | ||||||
| 					a.loader.transferTo = t | 					if t != nil { | ||||||
|  | 						a.loader.transferTo = append(a.loader.transferTo, t...) | ||||||
|  | 					} | ||||||
| 				} | 				} | ||||||
| 			} | 			} | ||||||
|  |  | ||||||
|   | |||||||
| @@ -13,45 +13,53 @@ func TestAutoParse(t *testing.T) { | |||||||
| 		expectedDirectory string | 		expectedDirectory string | ||||||
| 		expectedTempl     string | 		expectedTempl     string | ||||||
| 		expectedRe        string | 		expectedRe        string | ||||||
| 		expectedTo        string | 		expectedTo        []string | ||||||
| 	}{ | 	}{ | ||||||
| 		{ | 		{ | ||||||
| 			`auto example.org { | 			`auto example.org { | ||||||
| 				directory /tmp | 				directory /tmp | ||||||
| 				transfer to 127.0.0.1 | 				transfer to 127.0.0.1 | ||||||
| 			}`, | 			}`, | ||||||
| 			false, "/tmp", "${1}", `db\.(.*)`, "127.0.0.1:53", | 			false, "/tmp", "${1}", `db\.(.*)`, []string{"127.0.0.1:53"}, | ||||||
| 		}, | 		}, | ||||||
| 		{ | 		{ | ||||||
| 			`auto { | 			`auto { | ||||||
| 				directory /tmp | 				directory /tmp | ||||||
| 			}`, | 			}`, | ||||||
| 			false, "/tmp", "${1}", `db\.(.*)`, "", | 			false, "/tmp", "${1}", `db\.(.*)`, nil, | ||||||
| 		}, | 		}, | ||||||
| 		{ | 		{ | ||||||
| 			`auto { | 			`auto { | ||||||
| 				directory /tmp (.*) bliep | 				directory /tmp (.*) bliep | ||||||
| 			}`, | 			}`, | ||||||
| 			false, "/tmp", "bliep", `(.*)`, "", | 			false, "/tmp", "bliep", `(.*)`, nil, | ||||||
|  | 		}, | ||||||
|  | 		{ | ||||||
|  | 			`auto { | ||||||
|  | 				directory /tmp (.*) bliep | ||||||
|  | 				transfer to 127.0.0.1 | ||||||
|  | 				transfer to 127.0.0.2 | ||||||
|  | 			}`, | ||||||
|  | 			false, "/tmp", "bliep", `(.*)`, []string{"127.0.0.1:53", "127.0.0.2:53"}, | ||||||
| 		}, | 		}, | ||||||
| 		// errors | 		// errors | ||||||
| 		{ | 		{ | ||||||
| 			`auto example.org { | 			`auto example.org { | ||||||
| 				directory | 				directory | ||||||
| 			}`, | 			}`, | ||||||
| 			true, "", "${1}", `db\.(.*)`, "", | 			true, "", "${1}", `db\.(.*)`, nil, | ||||||
| 		}, | 		}, | ||||||
| 		{ | 		{ | ||||||
| 			`auto example.org { | 			`auto example.org { | ||||||
| 				directory /tmp * {1} | 				directory /tmp * {1} | ||||||
| 			}`, | 			}`, | ||||||
| 			true, "", "${1}", ``, "", | 			true, "", "${1}", ``, nil, | ||||||
| 		}, | 		}, | ||||||
| 		{ | 		{ | ||||||
| 			`auto example.org { | 			`auto example.org { | ||||||
| 				directory /tmp .* {1} | 				directory /tmp .* {1} | ||||||
| 			}`, | 			}`, | ||||||
| 			true, "", "${1}", ``, "", | 			true, "", "${1}", ``, nil, | ||||||
| 		}, | 		}, | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| @@ -73,8 +81,12 @@ func TestAutoParse(t *testing.T) { | |||||||
| 			if a.loader.re.String() != test.expectedRe { | 			if a.loader.re.String() != test.expectedRe { | ||||||
| 				t.Fatalf("Test %d expected %v, got %v", i, test.expectedRe, a.loader.re) | 				t.Fatalf("Test %d expected %v, got %v", i, test.expectedRe, a.loader.re) | ||||||
| 			} | 			} | ||||||
| 			if test.expectedTo != "" && a.loader.transferTo[0] != test.expectedTo { | 			if test.expectedTo != nil { | ||||||
| 				t.Fatalf("Test %d expected %v, got %v", i, test.expectedTo, a.loader.transferTo[0]) | 				for j, got := range a.loader.transferTo { | ||||||
|  | 					if got != test.expectedTo[j] { | ||||||
|  | 						t.Fatalf("Test %d expected %v, got %v", i, test.expectedTo[j], got) | ||||||
|  | 					} | ||||||
|  | 				} | ||||||
| 			} | 			} | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
|   | |||||||
| @@ -5,6 +5,7 @@ import ( | |||||||
| 	"log" | 	"log" | ||||||
|  |  | ||||||
| 	"github.com/miekg/coredns/middleware" | 	"github.com/miekg/coredns/middleware" | ||||||
|  | 	"github.com/miekg/coredns/middleware/pkg/rcode" | ||||||
| 	"github.com/miekg/coredns/request" | 	"github.com/miekg/coredns/request" | ||||||
|  |  | ||||||
| 	"github.com/miekg/dns" | 	"github.com/miekg/dns" | ||||||
| @@ -49,21 +50,23 @@ func notify(zone string, to []string) error { | |||||||
| 		if err := notifyAddr(c, m, t); err != nil { | 		if err := notifyAddr(c, m, t); err != nil { | ||||||
| 			log.Printf("[ERROR] " + err.Error()) | 			log.Printf("[ERROR] " + err.Error()) | ||||||
| 		} else { | 		} else { | ||||||
| 			log.Printf("[INFO] Sent notify for zone %s to %s", zone, t) | 			log.Printf("[INFO] Sent notify for zone %q to %q", zone, t) | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| 	return nil | 	return nil | ||||||
| } | } | ||||||
|  |  | ||||||
| func notifyAddr(c *dns.Client, m *dns.Msg, s string) error { | func notifyAddr(c *dns.Client, m *dns.Msg, s string) error { | ||||||
|  | 	code := dns.RcodeSuccess | ||||||
| 	for i := 0; i < 3; i++ { | 	for i := 0; i < 3; i++ { | ||||||
| 		ret, _, err := c.Exchange(m, s) | 		ret, _, err := c.Exchange(m, s) | ||||||
| 		if err != nil { | 		if err != nil { | ||||||
| 			continue | 			continue | ||||||
| 		} | 		} | ||||||
| 		if ret.Rcode == dns.RcodeSuccess || ret.Rcode == dns.RcodeNotImplemented { | 		code = ret.Rcode | ||||||
|  | 		if code == dns.RcodeSuccess { | ||||||
| 			return nil | 			return nil | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| 	return fmt.Errorf("Failed to send notify for zone '%s' to '%s'", m.Question[0].Name, s) | 	return fmt.Errorf("Notify for zone %q was not accepted by %q: rcode was %q", m.Question[0].Name, s, rcode.ToString(code)) | ||||||
| } | } | ||||||
|   | |||||||
| @@ -97,7 +97,7 @@ func serviceListFunc(c *kubernetes.Clientset, ns string, s *labels.Selector) fun | |||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
| func v1ToApiFilter(in watch.Event) (out watch.Event, keep bool) { | func v1ToAPIFilter(in watch.Event) (out watch.Event, keep bool) { | ||||||
| 	if in.Type == watch.Error { | 	if in.Type == watch.Error { | ||||||
| 		return in, true | 		return in, true | ||||||
| 	} | 	} | ||||||
| @@ -134,7 +134,7 @@ func serviceWatchFunc(c *kubernetes.Clientset, ns string, s *labels.Selector) fu | |||||||
| 		if err != nil { | 		if err != nil { | ||||||
| 			return nil, err | 			return nil, err | ||||||
| 		} | 		} | ||||||
| 		return watch.Filter(w, v1ToApiFilter), nil | 		return watch.Filter(w, v1ToAPIFilter), nil | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
| @@ -165,7 +165,7 @@ func namespaceWatchFunc(c *kubernetes.Clientset, s *labels.Selector) func(option | |||||||
| 		if err != nil { | 		if err != nil { | ||||||
| 			return nil, err | 			return nil, err | ||||||
| 		} | 		} | ||||||
| 		return watch.Filter(w, v1ToApiFilter), nil | 		return watch.Filter(w, v1ToAPIFilter), nil | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user