cloudflare/cloudflared

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
2019.3.0

Branches

Tags

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

Clone

HTTPS

Download ZIP

tunneldns/https_proxy.go

39lines · modeblame

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