dispatcher

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2020 License: GPL-3.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// MaxUDPSize max udp packet size
	MaxUDPSize = 1480
)

Variables

View Source
var (
	// ErrServerFailed all upstreams are failed
	ErrServerFailed = errors.New("server failed")
)

Functions

func GenConfig

func GenConfig(p string) error

GenConfig generates a template config to path p.

Types

type BasicServerConfig

type BasicServerConfig struct {
	Addr     string `yaml:"addr"`
	Protocol string `yaml:"protocol"`
	Socks5   string `yaml:"socks5"`

	TCP struct {
		IdleTimeout uint `yaml:"idle_timeout"`
	} `yaml:"tcp"`

	DoT struct {
		ServerName  string `yaml:"server_name"`
		IdleTimeout uint   `yaml:"idle_timeout"`
	} `yaml:"dot"`

	DoH struct {
		URL string `yaml:"url"`
	} `yaml:"doh"`

	// for test and experts only
	InsecureSkipVerify bool `yaml:"insecure_skip_verify,omitempty"`
}

BasicServerConfig is a basic config for a upstream dns server.

type Config

type Config struct {
	Bind struct {
		Addr     string `yaml:"addr"`
		Protocol string `yaml:"protocol"`
	} `yaml:"bind"`

	Dispatcher struct {
		MaxConcurrentQueries int `yaml:"max_concurrent_queries"`
	} `yaml:"dispatcher"`

	Server struct {
		Local struct {
			BasicServerConfig `yaml:"basic,inline"`

			DenyUnusualTypes     bool `yaml:"deny_unusual_types"`
			DenyResultsWithoutIP bool `yaml:"deny_results_without_ip"`
			CheckCNAME           bool `yaml:"check_cname"`

			IPPolicies     string `yaml:"ip_policies"`
			DomainPolicies string `yaml:"domain_policies"`
		} `yaml:"local"`

		Remote struct {
			BasicServerConfig `yaml:"basic,inline"`
			DelayStart        int `yaml:"delay_start"`
		} `yaml:"remote"`
	} `yaml:"server"`

	ECS struct {
		Local  string `yaml:"local"`
		Remote string `yaml:"remote"`
	} `yaml:"ecs"`

	CA struct {
		Path string `yaml:"path"`
	} `yaml:"ca"`
}

Config is config

func LoadConfig

func LoadConfig(p string) (*Config, error)

LoadConfig loads a yaml config from path p.

type Dispatcher

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

Dispatcher represents a dns query dispatcher

func InitDispatcher

func InitDispatcher(conf *Config, entry *logrus.Entry) (*Dispatcher, error)

InitDispatcher inits a dispatche from configuration

func (*Dispatcher) ListenAndServe

func (d *Dispatcher) ListenAndServe(network, addr string, maxUDPSize int) error

ListenAndServe listen on a port and start the server. Only support tcp and udp network. Will always return a non-nil err.

func (*Dispatcher) ServeDNS

func (d *Dispatcher) ServeDNS(ctx context.Context, q *dns.Msg) (r *dns.Msg, err error)

ServeDNS send q to upstreams and return first valid result.

type Upstream

type Upstream interface {
	// Exchange sends qRaw to upstream and return its reply. For better preformence, release the rRaw.
	Exchange(ctx context.Context, qRaw []byte) (rRaw *bufpool.MsgBuf, err error)
}

Upstream reprenses a dns upsteam

func NewUpstream

func NewUpstream(sc *BasicServerConfig, maxConcurrentQueries int, rootCAs *x509.CertPool) (Upstream, error)

NewUpstream inits a upstream instance base on the config. maxConcurrentQueries limits the max concurrent queries for this upstream. 0 means disable the limit. rootCAs will be used in dot/doh upstream in tls server verification.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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