mirror of
https://github.com/coredns/coredns.git
synced 2025-10-27 16:24:19 -04:00
plugin/forward: add prefer_udp option (#1944)
* plugin/forward: add prefer_udp option * updated according to code review - fixed linter warning - removed metric parameter in Proxy.Connect()
This commit is contained in:
committed by
Miek Gieben
parent
7c41f2ce9f
commit
bc50901234
@@ -33,7 +33,7 @@ type Forward struct {
|
||||
maxfails uint32
|
||||
expire time.Duration
|
||||
|
||||
forceTCP bool // also here for testing
|
||||
opts options // also here for testing
|
||||
|
||||
Next plugin.Handler
|
||||
}
|
||||
@@ -103,9 +103,18 @@ func (f *Forward) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg
|
||||
ret *dns.Msg
|
||||
err error
|
||||
)
|
||||
opts := f.opts
|
||||
for {
|
||||
ret, err = proxy.Connect(ctx, state, f.forceTCP, true)
|
||||
if err != nil && err == ErrCachedClosed { // Remote side closed conn, can only happen with TCP.
|
||||
ret, err = proxy.Connect(ctx, state, opts)
|
||||
if err == nil {
|
||||
break
|
||||
}
|
||||
if err == ErrCachedClosed { // Remote side closed conn, can only happen with TCP.
|
||||
continue
|
||||
}
|
||||
// Retry with TCP if truncated and prefer_udp configured
|
||||
if err == dns.ErrTruncated && !opts.forceTCP && f.opts.preferUDP {
|
||||
opts.forceTCP = true
|
||||
continue
|
||||
}
|
||||
break
|
||||
@@ -183,7 +192,10 @@ func (f *Forward) isAllowedDomain(name string) bool {
|
||||
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.
|
||||
func (f *Forward) ForceTCP() bool { return f.forceTCP }
|
||||
func (f *Forward) ForceTCP() bool { return f.opts.forceTCP }
|
||||
|
||||
// PreferUDP returns if UDP is preferred to be used even when the request comes in over TCP.
|
||||
func (f *Forward) PreferUDP() bool { return f.opts.preferUDP }
|
||||
|
||||
// List returns a set of proxies to be used for this client depending on the policy in f.
|
||||
func (f *Forward) List() []*Proxy { return f.p.List(f.proxies) }
|
||||
@@ -206,4 +218,9 @@ const (
|
||||
sequentialPolicy
|
||||
)
|
||||
|
||||
type options struct {
|
||||
forceTCP bool
|
||||
preferUDP bool
|
||||
}
|
||||
|
||||
const defaultTimeout = 5 * time.Second
|
||||
|
||||
Reference in New Issue
Block a user