proxy

package
v0.11.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 27, 2019 License: Apache-2.0 Imports: 20 Imported by: 10

Documentation

Index

Constants

View Source
const (
	// ProtoUDP is plain DNS-over-UDP
	ProtoUDP = "udp"
	// ProtoTCP is plain DNS-over-TCP
	ProtoTCP = "tcp"
	// ProtoTLS is DNS-over-TLS
	ProtoTLS = "tls"
	// ProtoHTTPS is DNS-over-HTTPS
	ProtoHTTPS = "https"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	UDPListenAddr *net.UDPAddr // if nil, then it does not listen for UDP
	TCPListenAddr *net.TCPAddr // if nil, then it does not listen for TCP

	HTTPSListenAddr *net.TCPAddr // if nil, then it does not listen for HTTPS (DoH)
	TLSListenAddr   *net.TCPAddr // if nil, then it does not listen for TLS (DoT)
	TLSConfig       *tls.Config  // necessary for listening for TLS

	Ratelimit          int      // max number of requests per second from a given IP (0 to disable)
	RatelimitWhitelist []string // a list of whitelisted client IP addresses

	RefuseAny  bool // if true, refuse ANY requests
	AllServers bool // if true, parallel queries to all configured upstream servers are enabled

	CacheEnabled bool // cache status

	Upstreams []upstream.Upstream // list of upstreams
	Fallbacks []upstream.Upstream // list of fallback resolvers (which will be used if regular upstream failed to answer)
	Handler   Handler             // custom middleware (optional)
}

Config contains all the fields necessary for proxy configuration

type DNSContext

type DNSContext struct {
	Proto              string              // "udp", "tcp", "tls", "https"
	Req                *dns.Msg            // DNS request
	Res                *dns.Msg            // DNS response from an upstream
	Conn               net.Conn            // underlying client connection. Can be null in the case of DOH.
	Addr               net.Addr            // client address.
	HTTPRequest        *http.Request       // HTTP request (for DOH only)
	HTTPResponseWriter http.ResponseWriter // HTTP response writer (for DOH only)
	StartTime          time.Time           // processing start time
	Upstream           upstream.Upstream   // upstream that resolved DNS request
}

DNSContext represents a DNS request message context

type Handler

type Handler func(p *Proxy, d *DNSContext) error

Handler is an optional custom handler for DNS requests It is called instead of the default method (Proxy.Resolve()) See handler_test.go for examples

type Proxy

type Proxy struct {
	sync.RWMutex
	Config
	// contains filtered or unexported fields
}

Proxy combines the proxy server state and configuration

func (*Proxy) Addr added in v0.9.1

func (p *Proxy) Addr(proto string) net.Addr

Addr returns the listen address for the specified proto or null if the proxy does not listen to it proto must be "tcp", "tls", "https" or "udp"

func (*Proxy) Resolve added in v0.9.1

func (p *Proxy) Resolve(d *DNSContext) error

Resolve is the default resolving method used by the DNS proxy to query upstreams

func (*Proxy) ServeHTTP added in v0.9.11

func (p *Proxy) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP is the http.Handler implementation that handles DOH queries Here is what it returns: http.StatusBadRequest - if there is no DNS request data http.StatusUnsupportedMediaType - if request content type is not application/dns-message http.StatusMethodNotAllowed - if request method is not GET or POST

func (*Proxy) Start

func (p *Proxy) Start() error

Start initializes the proxy server and starts listening

func (*Proxy) Stop

func (p *Proxy) Stop() error

Stop stops the proxy server including all its listeners

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL