plugin/forward: various cleanup (#1949)
Fix documentation and remove the unused From method. Signed-off-by: Miek Gieben <miek@miek.nl>
This commit is contained in:
parent
41c2871907
commit
6ec1978340
2 changed files with 7 additions and 12 deletions
|
@ -63,8 +63,7 @@ forward FROM TO... {
|
||||||
* `force_tcp`, use TCP even when the request comes in over UDP.
|
* `force_tcp`, use TCP even when the request comes in over UDP.
|
||||||
* `prefer_udp`, try first using UDP even when the request comes in over TCP. If response is truncated
|
* `prefer_udp`, try first using UDP even when the request comes in over TCP. If response is truncated
|
||||||
(TC flag set in response) then do another attempt over TCP. In case if both `force_tcp` and
|
(TC flag set in response) then do another attempt over TCP. In case if both `force_tcp` and
|
||||||
`prefer_udp`.
|
`prefer_udp` options specified the `force_tcp` takes precedence.
|
||||||
options specified the `force_tcp` takes precedence.
|
|
||||||
* `max_fails` is the number of subsequent failed health checks that are needed before considering
|
* `max_fails` is the number of subsequent failed health checks that are needed before considering
|
||||||
an upstream to be down. If 0, the upstream will never be marked as down (nor health checked).
|
an upstream to be down. If 0, the upstream will never be marked as down (nor health checked).
|
||||||
Default is 2.
|
Default is 2.
|
||||||
|
|
|
@ -112,7 +112,7 @@ func (f *Forward) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg
|
||||||
if err == ErrCachedClosed { // Remote side closed conn, can only happen with TCP.
|
if err == ErrCachedClosed { // Remote side closed conn, can only happen with TCP.
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
// Retry with TCP if truncated and prefer_udp configured
|
// Retry with TCP if truncated and prefer_udp configured.
|
||||||
if err == dns.ErrTruncated && !opts.forceTCP && f.opts.preferUDP {
|
if err == dns.ErrTruncated && !opts.forceTCP && f.opts.preferUDP {
|
||||||
opts.forceTCP = true
|
opts.forceTCP = true
|
||||||
continue
|
continue
|
||||||
|
@ -166,9 +166,7 @@ func (f *Forward) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Forward) match(state request.Request) bool {
|
func (f *Forward) match(state request.Request) bool {
|
||||||
from := f.from
|
if !plugin.Name(f.from).Matches(state.Name()) || !f.isAllowedDomain(state.Name()) {
|
||||||
|
|
||||||
if !plugin.Name(from).Matches(state.Name()) || !f.isAllowedDomain(state.Name()) {
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -188,9 +186,6 @@ func (f *Forward) isAllowedDomain(name string) bool {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
// From returns the base domain to match for the request to be forwarded.
|
|
||||||
func (f *Forward) From() string { return f.from }
|
|
||||||
|
|
||||||
// ForceTCP returns if TCP is forced to be used even when the request comes in over UDP.
|
// ForceTCP returns if TCP is forced to be used even when the request comes in over UDP.
|
||||||
func (f *Forward) ForceTCP() bool { return f.opts.forceTCP }
|
func (f *Forward) ForceTCP() bool { return f.opts.forceTCP }
|
||||||
|
|
||||||
|
@ -201,11 +196,11 @@ func (f *Forward) PreferUDP() bool { return f.opts.preferUDP }
|
||||||
func (f *Forward) List() []*Proxy { return f.p.List(f.proxies) }
|
func (f *Forward) List() []*Proxy { return f.p.List(f.proxies) }
|
||||||
|
|
||||||
var (
|
var (
|
||||||
// ErrNoHealthy means no healthy proxies left
|
// ErrNoHealthy means no healthy proxies left.
|
||||||
ErrNoHealthy = errors.New("no healthy proxies")
|
ErrNoHealthy = errors.New("no healthy proxies")
|
||||||
// ErrNoForward means no forwarder defined
|
// ErrNoForward means no forwarder defined.
|
||||||
ErrNoForward = errors.New("no forwarder defined")
|
ErrNoForward = errors.New("no forwarder defined")
|
||||||
// ErrCachedClosed means cached connection was closed by peer
|
// ErrCachedClosed means cached connection was closed by peer.
|
||||||
ErrCachedClosed = errors.New("cached connection was closed by peer")
|
ErrCachedClosed = errors.New("cached connection was closed by peer")
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -218,6 +213,7 @@ const (
|
||||||
sequentialPolicy
|
sequentialPolicy
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// options holds various options that can be set.
|
||||||
type options struct {
|
type options struct {
|
||||||
forceTCP bool
|
forceTCP bool
|
||||||
preferUDP bool
|
preferUDP bool
|
||||||
|
|
Loading…
Add table
Reference in a new issue