diff options
author | 2022-04-13 00:39:48 +0800 | |
---|---|---|
committer | 2022-04-12 12:39:48 -0400 | |
commit | 0622a6c66c6c0c6659ece5e6e41ea218912b0ed2 (patch) | |
tree | c0532dbe57397cb6b40e70bc543b6aa3e7426117 /plugin/forward/health.go | |
parent | e60c179194cc1ff85d24fe9b887d901aea74641d (diff) | |
download | coredns-0622a6c66c6c0c6659ece5e6e41ea218912b0ed2.tar.gz coredns-0622a6c66c6c0c6659ece5e6e41ea218912b0ed2.tar.zst coredns-0622a6c66c6c0c6659ece5e6e41ea218912b0ed2.zip |
plugin/forward: configurable domain support for healthcheck (#5281)
* plugin/forward: configurable domain support for healthcheck
Signed-off-by: hansedong <admin@yinxiaoluo.com>
Diffstat (limited to 'plugin/forward/health.go')
-rw-r--r-- | plugin/forward/health.go | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/plugin/forward/health.go b/plugin/forward/health.go index f4cfab834..ec0b48143 100644 --- a/plugin/forward/health.go +++ b/plugin/forward/health.go @@ -16,6 +16,8 @@ type HealthChecker interface { SetTLSConfig(*tls.Config) SetRecursionDesired(bool) GetRecursionDesired() bool + SetDomain(domain string) + GetDomain() string SetTCPTransport() } @@ -23,6 +25,7 @@ type HealthChecker interface { type dnsHc struct { c *dns.Client recursionDesired bool + domain string } var ( @@ -31,7 +34,7 @@ var ( ) // NewHealthChecker returns a new HealthChecker based on transport. -func NewHealthChecker(trans string, recursionDesired bool) HealthChecker { +func NewHealthChecker(trans string, recursionDesired bool, domain string) HealthChecker { switch trans { case transport.DNS, transport.TLS: c := new(dns.Client) @@ -39,7 +42,7 @@ func NewHealthChecker(trans string, recursionDesired bool) HealthChecker { c.ReadTimeout = hcReadTimeout c.WriteTimeout = hcWriteTimeout - return &dnsHc{c: c, recursionDesired: recursionDesired} + return &dnsHc{c: c, recursionDesired: recursionDesired, domain: domain} } log.Warningf("No healthchecker for transport %q", trans) @@ -58,6 +61,13 @@ func (h *dnsHc) GetRecursionDesired() bool { return h.recursionDesired } +func (h *dnsHc) SetDomain(domain string) { + h.domain = domain +} +func (h *dnsHc) GetDomain() string { + return h.domain +} + func (h *dnsHc) SetTCPTransport() { h.c.Net = "tcp" } @@ -80,7 +90,7 @@ func (h *dnsHc) Check(p *Proxy) error { func (h *dnsHc) send(addr string) error { ping := new(dns.Msg) - ping.SetQuestion(".", dns.TypeNS) + ping.SetQuestion(h.domain, dns.TypeNS) ping.MsgHdr.RecursionDesired = h.recursionDesired m, _, err := h.c.Exchange(ping, addr) |