diff options
Diffstat (limited to 'plugin/forward/connect.go')
-rw-r--r-- | plugin/forward/connect.go | 27 |
1 files changed, 15 insertions, 12 deletions
diff --git a/plugin/forward/connect.go b/plugin/forward/connect.go index 3259fda5e..4a0a7141e 100644 --- a/plugin/forward/connect.go +++ b/plugin/forward/connect.go @@ -78,12 +78,17 @@ func (p *Proxy) updateRtt(newRtt time.Duration) { } // Connect selects an upstream, sends the request and waits for a response. -func (p *Proxy) Connect(ctx context.Context, state request.Request, forceTCP, metric bool) (*dns.Msg, error) { +func (p *Proxy) Connect(ctx context.Context, state request.Request, opts options) (*dns.Msg, error) { start := time.Now() - proto := state.Proto() - if forceTCP { + proto := "" + switch { + case opts.forceTCP: // TCP flag has precedence over UDP flag proto = "tcp" + case opts.preferUDP: + proto = "udp" + default: + proto = state.Proto() } conn, cached, err := p.Dial(proto) @@ -122,17 +127,15 @@ func (p *Proxy) Connect(ctx context.Context, state request.Request, forceTCP, me p.Yield(conn) - if metric { - rc, ok := dns.RcodeToString[ret.Rcode] - if !ok { - rc = strconv.Itoa(ret.Rcode) - } - - RequestCount.WithLabelValues(p.addr).Add(1) - RcodeCount.WithLabelValues(rc, p.addr).Add(1) - RequestDuration.WithLabelValues(p.addr).Observe(time.Since(start).Seconds()) + rc, ok := dns.RcodeToString[ret.Rcode] + if !ok { + rc = strconv.Itoa(ret.Rcode) } + RequestCount.WithLabelValues(p.addr).Add(1) + RcodeCount.WithLabelValues(rc, p.addr).Add(1) + RequestDuration.WithLabelValues(p.addr).Observe(time.Since(start).Seconds()) + return ret, nil } |