plugin/forward: expose TLSConfig and error messages to public (#1781)
* plugin/forward: expose TLSConfig and error messages to public * Add IsTLS() instead of TLSConfig()
This commit is contained in:
parent
0e5e59c327
commit
b9f0d55fc9
4 changed files with 16 additions and 11 deletions
|
@ -58,7 +58,7 @@ func (p *Proxy) Connect(ctx context.Context, state request.Request, forceTCP, me
|
||||||
if err := conn.WriteMsg(state.Req); err != nil {
|
if err := conn.WriteMsg(state.Req); err != nil {
|
||||||
conn.Close() // not giving it back
|
conn.Close() // not giving it back
|
||||||
if err == io.EOF && cached {
|
if err == io.EOF && cached {
|
||||||
return nil, errCachedClosed
|
return nil, ErrCachedClosed
|
||||||
}
|
}
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -69,7 +69,7 @@ func (p *Proxy) Connect(ctx context.Context, state request.Request, forceTCP, me
|
||||||
p.updateRtt(timeout)
|
p.updateRtt(timeout)
|
||||||
conn.Close() // not giving it back
|
conn.Close() // not giving it back
|
||||||
if err == io.EOF && cached {
|
if err == io.EOF && cached {
|
||||||
return nil, errCachedClosed
|
return nil, ErrCachedClosed
|
||||||
}
|
}
|
||||||
return ret, err
|
return ret, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -104,7 +104,7 @@ func (f *Forward) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg
|
||||||
)
|
)
|
||||||
for {
|
for {
|
||||||
ret, err = proxy.Connect(ctx, state, f.forceTCP, true)
|
ret, err = proxy.Connect(ctx, state, f.forceTCP, true)
|
||||||
if err != nil && err == errCachedClosed { // Remote side closed conn, can only happen with TCP.
|
if err != nil && err == ErrCachedClosed { // Remote side closed conn, can only happen with TCP.
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
|
@ -150,7 +150,7 @@ func (f *Forward) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg
|
||||||
return dns.RcodeServerFailure, upstreamErr
|
return dns.RcodeServerFailure, upstreamErr
|
||||||
}
|
}
|
||||||
|
|
||||||
return dns.RcodeServerFailure, errNoHealthy
|
return dns.RcodeServerFailure, ErrNoHealthy
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Forward) match(state request.Request) bool {
|
func (f *Forward) match(state request.Request) bool {
|
||||||
|
@ -186,10 +186,12 @@ func (f *Forward) ForceTCP() bool { return f.forceTCP }
|
||||||
func (f *Forward) List() []*Proxy { return f.p.List(f.proxies) }
|
func (f *Forward) List() []*Proxy { return f.p.List(f.proxies) }
|
||||||
|
|
||||||
var (
|
var (
|
||||||
errInvalidDomain = errors.New("invalid domain for forward")
|
// ErrNoHealthy means no healthy proxies left
|
||||||
errNoHealthy = errors.New("no healthy proxies")
|
ErrNoHealthy = errors.New("no healthy proxies")
|
||||||
errNoForward = errors.New("no forwarder defined")
|
// ErrNoForward means no forwarder defined
|
||||||
errCachedClosed = errors.New("cached connection was closed by peer")
|
ErrNoForward = errors.New("no forwarder defined")
|
||||||
|
// ErrCachedClosed means cached connection was closed by peer
|
||||||
|
ErrCachedClosed = errors.New("cached connection was closed by peer")
|
||||||
)
|
)
|
||||||
|
|
||||||
// policy tells forward what policy for selecting upstream it uses.
|
// policy tells forward what policy for selecting upstream it uses.
|
||||||
|
|
|
@ -16,7 +16,7 @@ import (
|
||||||
// Forward may be called with a nil f, an error is returned in that case.
|
// Forward may be called with a nil f, an error is returned in that case.
|
||||||
func (f *Forward) Forward(state request.Request) (*dns.Msg, error) {
|
func (f *Forward) Forward(state request.Request) (*dns.Msg, error) {
|
||||||
if f == nil {
|
if f == nil {
|
||||||
return nil, errNoForward
|
return nil, ErrNoForward
|
||||||
}
|
}
|
||||||
|
|
||||||
fails := 0
|
fails := 0
|
||||||
|
@ -56,7 +56,7 @@ func (f *Forward) Forward(state request.Request) (*dns.Msg, error) {
|
||||||
return nil, upstreamErr
|
return nil, upstreamErr
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil, errNoHealthy
|
return nil, ErrNoHealthy
|
||||||
}
|
}
|
||||||
|
|
||||||
// Lookup will use name and type to forge a new message and will send that upstream. It will
|
// Lookup will use name and type to forge a new message and will send that upstream. It will
|
||||||
|
@ -64,7 +64,7 @@ func (f *Forward) Forward(state request.Request) (*dns.Msg, error) {
|
||||||
// Lookup may be called with a nil f, an error is returned in that case.
|
// Lookup may be called with a nil f, an error is returned in that case.
|
||||||
func (f *Forward) Lookup(state request.Request, name string, typ uint16) (*dns.Msg, error) {
|
func (f *Forward) Lookup(state request.Request, name string, typ uint16) (*dns.Msg, error) {
|
||||||
if f == nil {
|
if f == nil {
|
||||||
return nil, errNoForward
|
return nil, ErrNoForward
|
||||||
}
|
}
|
||||||
|
|
||||||
req := new(dns.Msg)
|
req := new(dns.Msg)
|
||||||
|
|
|
@ -63,6 +63,9 @@ func (p *Proxy) SetTLSConfig(cfg *tls.Config) {
|
||||||
p.client = dnsClient(cfg)
|
p.client = dnsClient(cfg)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsTLS returns true if proxy uses tls.
|
||||||
|
func (p *Proxy) IsTLS() bool { return p.transport.tlsConfig != nil }
|
||||||
|
|
||||||
// SetExpire sets the expire duration in the lower p.transport.
|
// SetExpire sets the expire duration in the lower p.transport.
|
||||||
func (p *Proxy) SetExpire(expire time.Duration) { p.transport.SetExpire(expire) }
|
func (p *Proxy) SetExpire(expire time.Duration) { p.transport.SetExpire(expire) }
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue