cloudflare/cloudflared

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
2018.8.0

Branches

Tags

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

Clone

HTTPS

Download ZIP

tunneldns/https_proxy.go

38lines · modeblame

d06fc520Areg Harutyunyan8 years ago1package 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 {
12Exchange(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 {
17Upstreams []Upstream
18Next 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) {
23var reply *dns.Msg
24var backendErr error
25
26for _, upstream := range p.Upstreams {
27reply, backendErr = upstream.Exchange(ctx, r)
28if backendErr == nil {
29w.WriteMsg(reply)
30return 0, nil
31}
32}
33
34return 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" }