cloudflare/cloudflared

Public

mirrored from https://github.com/cloudflare/cloudflaredAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
2018.9.0

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

tunneldns/https_proxy.go

38lines · modecode

1package tunneldns
2
3import (
4 "github.com/coredns/coredns/plugin"
5 "github.com/miekg/dns"
6 "github.com/pkg/errors"
7 "golang.org/x/net/context"
8)
9
10// Upstream is a simplified interface for proxy destination
11type Upstream interface {
12 Exchange(ctx context.Context, query *dns.Msg) (*dns.Msg, error)
13}
14
15// ProxyPlugin is a simplified DNS proxy using a generic upstream interface
16type ProxyPlugin struct {
17 Upstreams []Upstream
18 Next plugin.Handler
19}
20
21// ServeDNS implements interface for CoreDNS plugin
22func (p ProxyPlugin) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (int, error) {
23 var reply *dns.Msg
24 var backendErr error
25
26 for _, upstream := range p.Upstreams {
27 reply, backendErr = upstream.Exchange(ctx, r)
28 if backendErr == nil {
29 w.WriteMsg(reply)
30 return 0, nil
31 }
32 }
33
34 return dns.RcodeServerFailure, errors.Wrap(backendErr, "failed to contact any of the upstreams")
35}
36
37// Name implements interface for CoreDNS plugin
38func (p ProxyPlugin) Name() string { return "proxy" }
39