dohProxy

package module
v5.0.3 Latest Latest
Warning

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

Go to latest
Published: May 28, 2020 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// MaxBytesOfDNSName is the maximum number of bytes a DNS name may contain
	MaxBytesOfDNSName = 253
	// EDNSSentinelValue is the value that when sent to Google as the
	// EDNS value, means "do not use EDNS".
	EDNSSentinelValue    = "0.0.0.0/0"
	PaddingParameter     = "random_padding"
	ContentType          = "application/dns-message"
	MaxBytesOfDNSMessage = 512
)

Variables

View Source
var (
	Log = NewLogger()
)

Functions

func CSVtoIPs

func CSVtoIPs(csv string) (ips []net.IP, err error)

CSVtoIPs takes a comma-separated string of IPs, and parses to a []net.IP

func CalculatePaddingLength

func CalculatePaddingLength(preAllocatedLen int, least int, gain int) int

func GenerateUrlSafeString

func GenerateUrlSafeString(n int) string

func GetMinTTLFromDnsMsg

func GetMinTTLFromDnsMsg(msg *dns.Msg) (minTTL uint32)

func InsertIntoSlice

func InsertIntoSlice(to []interface{}, from interface{}, inex int) []interface{}

func IsLocalListen

func IsLocalListen(addr string) bool

func NewLogger

func NewLogger() *logrus.Logger

func ObtainEDN0Subnet

func ObtainEDN0Subnet(msg *dns.Msg) (edns0Subnet dns.EDNS0_SUBNET)

func ReplaceEDNS0Padding

func ReplaceEDNS0Padding(msg *dns.Msg, padding *dns.EDNS0_PADDING)

func ReplaceEDNS0Subnet

func ReplaceEDNS0Subnet(msg *dns.Msg, subnet *dns.EDNS0_SUBNET)

func ResolveHostToIPClosure

func ResolveHostToIPClosure(name string, resolver string) (closure func() (ip4s []string, ip6s []string))

resolve domain name to ips (ipv4 + ipv6) using traditional udp+tcp, fixed 60s ttl

Types

type Cache

type Cache struct {
	// contains filtered or unexported fields
}

Use map to store cache, red-black tree to index cache. red-black tree also used to implement the cache expire mechanism.

func NewCache

func NewCache() *Cache

func (*Cache) Get

func (c *Cache) Get(msgQ *dns.Msg) (rMsg *dns.Msg)

func (*Cache) Insert

func (c *Cache) Insert(msgCh <-chan *dns.Msg)

type DMProvider

type DMProvider struct {
	// contains filtered or unexported fields
}

DMProvider is the Google DNS-over-HTTPS provider; it implements the Provider interface, the abbreviation "DM" stands for dns-message.

func NewDMProvider

func NewDMProvider(endpoint string, opts *DMProviderOptions) (*DMProvider, error)

NewDMProvider creates a DMProvider

func (*DMProvider) GetIPsClosure

func (provider *DMProvider) GetIPsClosure(name string) (closure func() (ip4s []string, ip16s []string))

resolve domain name to ips (ipv4 and ipv6) using Dns over HTTPS.

func (*DMProvider) ObtainCurrentExternalIP

func (provider *DMProvider) ObtainCurrentExternalIP(dnsResolver string) (string, error)

obtain external ip through some public apis.

func (DMProvider) Query

func (provider DMProvider) Query(msg *dns.Msg) (*dns.Msg, error)

type DMProviderOptions

type DMProviderOptions struct {
	EndpointIPs []net.IP

	EDNSSubnet string
	// Additional headers to be sent with requests to the DNS provider
	Headers http.Header

	// Additional query parameters to be sent with requests to the DNS provider
	QueryParameters map[string][]string

	// if using http2 for query
	HTTP2 bool

	// using specific CA cert file for TLS establishment
	CACertFilePath string

	// Reply All AAAA Questions with a Empty Answer
	NoAAAA bool

	// use https://dns.google/resolve like endpoint
	Alternative bool

	// dns resolver for retrieve ip of DoH enpoint host
	DnsResolver string

	DnsMsgEncoder base64.Encoding
}

DMProviderOptions is a configuration object for optional DMProvider configuration

type Handler

type Handler struct {
	// contains filtered or unexported fields
}

Handler represents a DNS handler

func NewHandler

func NewHandler(provider Provider, options *HandlerOptions) *Handler

NewHandler creates a new Handler

func (*Handler) AnswerByDoH

func (h *Handler) AnswerByDoH(writer *dns.ResponseWriter, ctx *writerCtx)

func (*Handler) AnswerByHostsFile

func (h *Handler) AnswerByHostsFile(writer *dns.ResponseWriter, ctx *writerCtx)

func (*Handler) Handle

func (h *Handler) Handle(writer dns.ResponseWriter, msg *dns.Msg)

Handle handles a DNS request

func (*Handler) TryWriteAnswer

func (h *Handler) TryWriteAnswer(writer *dns.ResponseWriter, ctx *writerCtx)

type HandlerOptions

type HandlerOptions struct {
	Cache bool
}

HandlerOptions specifies options to be used when instantiating a handler

type HostsFileProvider

type HostsFileProvider struct {
	// contains filtered or unexported fields
}

func NewHostsFileProvider

func NewHostsFileProvider() *HostsFileProvider

func (*HostsFileProvider) Query

func (provider *HostsFileProvider) Query(msg *dns.Msg) (*dns.Msg, error)

type HostsFileResolver

type HostsFileResolver struct {
	sync.Mutex
	// contains filtered or unexported fields
}

hosts contains known host entries.

func (*HostsFileResolver) LookupStaticAddr

func (hosts *HostsFileResolver) LookupStaticAddr(addr string) []string

LookupStaticAddr looks up the hosts for the given address from /etc/hosts.

func (*HostsFileResolver) LookupStaticHost

func (hosts *HostsFileResolver) LookupStaticHost(host string) []string

LookupStaticHost looks up the addresses for the given host from /etc/hosts.

type KeyValue

type KeyValue map[string][]string

func (KeyValue) Set

func (k KeyValue) Set(kv string) error

func (KeyValue) String

func (k KeyValue) String() string

type Provider

type Provider interface {
	Query(msg *dns.Msg) (*dns.Msg, error)
}

Provider is an interface representing a service of DNS queries.

type RedBlackTreeExtended

type RedBlackTreeExtended struct {
	*rbt.Tree
}

RedBlackTreeExtended to demonstrate how to extend a RedBlackTree to include new functions

func (*RedBlackTreeExtended) GetMax

func (tree *RedBlackTreeExtended) GetMax() (value interface{}, found bool)

GetMax gets the max value and flag if found

func (*RedBlackTreeExtended) GetMin

func (tree *RedBlackTreeExtended) GetMin() (value interface{}, found bool)

GetMin gets the min value and flag if found

func (*RedBlackTreeExtended) RemoveMax

func (tree *RedBlackTreeExtended) RemoveMax() (value interface{}, deleted bool)

RemoveMax removes the max value and flag if found

func (*RedBlackTreeExtended) RemoveMin

func (tree *RedBlackTreeExtended) RemoveMin() (value interface{}, deleted bool)

RemoveMin removes the min value and flag if found

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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