plugin/forward: Allow Proxy to be used outside of forward plugin. (#5951)
* plugin/forward: Move Proxy into pkg/plugin/proxy, to allow forward.Proxy to be used outside of forward plugin. Signed-off-by: Patrick Downey <patrick.downey@dioadconsulting.com>
This commit is contained in:
parent
47dceabfc6
commit
f823825f8a
19 changed files with 529 additions and 210 deletions
|
@ -12,6 +12,7 @@ import (
|
|||
"github.com/coredns/coredns/plugin"
|
||||
"github.com/coredns/coredns/plugin/dnstap"
|
||||
"github.com/coredns/coredns/plugin/pkg/parse"
|
||||
"github.com/coredns/coredns/plugin/pkg/proxy"
|
||||
pkgtls "github.com/coredns/coredns/plugin/pkg/tls"
|
||||
"github.com/coredns/coredns/plugin/pkg/transport"
|
||||
|
||||
|
@ -67,7 +68,7 @@ func setup(c *caddy.Controller) error {
|
|||
// OnStartup starts a goroutines for all proxies.
|
||||
func (f *Forward) OnStartup() (err error) {
|
||||
for _, p := range f.proxies {
|
||||
p.start(f.hcInterval)
|
||||
p.Start(f.hcInterval)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
@ -75,7 +76,7 @@ func (f *Forward) OnStartup() (err error) {
|
|||
// OnShutdown stops all configured proxies.
|
||||
func (f *Forward) OnShutdown() error {
|
||||
for _, p := range f.proxies {
|
||||
p.stop()
|
||||
p.Stop()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
@ -127,7 +128,7 @@ func parseStanza(c *caddy.Controller) (*Forward, error) {
|
|||
if !allowedTrans[trans] {
|
||||
return f, fmt.Errorf("'%s' is not supported as a destination protocol in forward: %s", trans, host)
|
||||
}
|
||||
p := NewProxy(h, trans)
|
||||
p := proxy.NewProxy(h, trans)
|
||||
f.proxies = append(f.proxies, p)
|
||||
transports[i] = trans
|
||||
}
|
||||
|
@ -152,12 +153,12 @@ func parseStanza(c *caddy.Controller) (*Forward, error) {
|
|||
f.proxies[i].SetTLSConfig(f.tlsConfig)
|
||||
}
|
||||
f.proxies[i].SetExpire(f.expire)
|
||||
f.proxies[i].health.SetRecursionDesired(f.opts.hcRecursionDesired)
|
||||
f.proxies[i].GetHealthchecker().SetRecursionDesired(f.opts.HCRecursionDesired)
|
||||
// when TLS is used, checks are set to tcp-tls
|
||||
if f.opts.forceTCP && transports[i] != transport.TLS {
|
||||
f.proxies[i].health.SetTCPTransport()
|
||||
if f.opts.ForceTCP && transports[i] != transport.TLS {
|
||||
f.proxies[i].GetHealthchecker().SetTCPTransport()
|
||||
}
|
||||
f.proxies[i].health.SetDomain(f.opts.hcDomain)
|
||||
f.proxies[i].GetHealthchecker().SetDomain(f.opts.HCDomain)
|
||||
}
|
||||
|
||||
return f, nil
|
||||
|
@ -194,12 +195,12 @@ func parseBlock(c *caddy.Controller, f *Forward) error {
|
|||
return fmt.Errorf("health_check can't be negative: %d", dur)
|
||||
}
|
||||
f.hcInterval = dur
|
||||
f.opts.hcDomain = "."
|
||||
f.opts.HCDomain = "."
|
||||
|
||||
for c.NextArg() {
|
||||
switch hcOpts := c.Val(); hcOpts {
|
||||
case "no_rec":
|
||||
f.opts.hcRecursionDesired = false
|
||||
f.opts.HCRecursionDesired = false
|
||||
case "domain":
|
||||
if !c.NextArg() {
|
||||
return c.ArgErr()
|
||||
|
@ -208,7 +209,7 @@ func parseBlock(c *caddy.Controller, f *Forward) error {
|
|||
if _, ok := dns.IsDomainName(hcDomain); !ok {
|
||||
return fmt.Errorf("health_check: invalid domain name %s", hcDomain)
|
||||
}
|
||||
f.opts.hcDomain = plugin.Name(hcDomain).Normalize()
|
||||
f.opts.HCDomain = plugin.Name(hcDomain).Normalize()
|
||||
default:
|
||||
return fmt.Errorf("health_check: unknown option %s", hcOpts)
|
||||
}
|
||||
|
@ -218,12 +219,12 @@ func parseBlock(c *caddy.Controller, f *Forward) error {
|
|||
if c.NextArg() {
|
||||
return c.ArgErr()
|
||||
}
|
||||
f.opts.forceTCP = true
|
||||
f.opts.ForceTCP = true
|
||||
case "prefer_udp":
|
||||
if c.NextArg() {
|
||||
return c.ArgErr()
|
||||
}
|
||||
f.opts.preferUDP = true
|
||||
f.opts.PreferUDP = true
|
||||
case "tls":
|
||||
args := c.RemainingArgs()
|
||||
if len(args) > 3 {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue