router

package
v0.0.0-...-264f9d0 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2024 License: GPL-3.0 Imports: 56 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrConcurrentReload = errors.New("concurrent reloading call")
)

Functions

func SetMiddleware

func SetMiddleware(m Middleware)

Types

type APIConfig

type APIConfig struct {
	Addr string `yaml:"addr"`
}

type AddonsConfig

type AddonsConfig struct{}

type CacheConfig

type CacheConfig struct {
	MemSize    int    `yaml:"mem_size"`
	Redis      string `yaml:"redis"`
	MaximumTTL int    `yaml:"maximum_ttl"`
	IpMarker   string `yaml:"ip_marker"`
}

type ClientLimiterConfig

type ClientLimiterConfig struct {
	Limit  int `yaml:"limit"`
	Burst  int `yaml:"burst"`
	V4Mask int `yaml:"v4_mask"`
	V6Mask int `yaml:"v6_mask"`
}

type Config

type Config struct {
	Servers   []ServerConfig   `yaml:"servers"`
	Upstreams []UpstreamConfig `yaml:"upstreams"`

	DomainSets []DomainSetConfig `yaml:"domain_sets"`
	Rules      []RuleConfig      `yaml:"rules"`

	Addons AddonsConfig `yaml:"addons"`

	Log     LogConfig     `yaml:"log"`
	Cache   CacheConfig   `yaml:"cache"`
	ECS     ECSConfig     `yaml:"ecs"`
	Limiter LimiterConfig `yaml:"limiter"`
	API     APIConfig     `yaml:"api"`
}

type DomainSetConfig

type DomainSetConfig struct {
	Tag   string   `yaml:"tag"`
	Files []string `yaml:"files"`
}

type ECSConfig

type ECSConfig struct {
	Enabled bool `yaml:"enabled"`
}

type HttpConfig

type HttpConfig struct {
	Path             string `yaml:"path"`
	ClientAddrHeader string `yaml:"client_addr_header"`

	DebugMaxStreams uint32 `yaml:"debug_max_streams,omitempty"`
}

type LimiterConfig

type LimiterConfig struct {
	GlobalLimit int                 `yaml:"global_limit"`
	Client      ClientLimiterConfig `yaml:"client"`
}

type LogConfig

type LogConfig struct {
	Queries   bool `yaml:"queries"`
	TraceMsgs bool `yaml:"trace_msgs"`
}

type Middleware

type Middleware interface {
	// Handle query msg right after receiving.
	// Note: This func should be fast and MUST NOT contain block operations. It will
	// be called directly in the main network thread in UDP/Gnet server.
	PreHandling(m *dnsmsg.Msg, qMeta QueryMeta) (resp *dnsmsg.Msg, err error)

	// Handle query msg before sending to upstream.
	PreForwarding(ctx context.Context, m *dnsmsg.Msg, qMeta QueryMeta, qInfo QueryInfo) (resp *dnsmsg.Msg, err error)

	// Handle query and response after received from upstream.
	PostForwarding(ctx context.Context, q *dnsmsg.Question, qMeta QueryMeta, qInfo QueryInfo, resp *dnsmsg.Msg) error
}

type QueryInfo

type QueryInfo struct {
	Id     uint16
	OpCode dnsmsg.OpCode
	Rd     bool         // RecursionDesired
	EDNS0  bool         // Has EDNS0 section
	ECS    netip.Prefix // EDNS0 Client subnet
}

Query info.

type QueryMeta

type QueryMeta struct {
	RemoteAddr netip.AddrPort // client addr, maybe invalid
	LocalAddr  netip.AddrPort // inbound/server addr, maybe invalid
}

Query meta data from server side.

type QuicConfig

type QuicConfig struct {
	MaxStreams int64 `yaml:"max_streams"`
}

type RespMeta

type RespMeta struct {
	RuleIdx int
	Cached  bool
	IpMark  string
}

type RespWriter

type RespWriter interface {
	// Must be called once.
	WriteResp(m *dnsmsg.Msg)
}

type Router

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

func Run

func Run(ctx context.Context, cfg *Config) (_ *Router, err error)

func (*Router) Close

func (r *Router) Close(err error)

func (*Router) Reload

func (r *Router) Reload() (err error)

type RuleConfig

type RuleConfig struct {
	Reverse bool   `yaml:"reverse"`
	Domain  string `yaml:"domain"`
	Reject  uint16 `yaml:"reject"`
	Forward string `yaml:"forward"`
}

type ServerConfig

type ServerConfig struct {
	Tag         string       `yaml:"tag"`
	Protocol    string       `yaml:"protocol"`
	Listen      string       `yaml:"listen"`
	IdleTimeout int          `yaml:"idle_timeout"`
	Udp         UdpConfig    `yaml:"udp"`
	Tcp         TcpConfig    `yaml:"tcp"`
	Tls         TlsConfig    `yaml:"tls"`
	Http        HttpConfig   `yaml:"http"`
	Quic        QuicConfig   `yaml:"quic"`
	Socket      SocketConfig `yaml:"socket"`
}

type SocketConfig

type SocketConfig struct {
	SO_REUSEPORT    bool   `yaml:"so_reuseport"` // tcp/udp
	SO_RCVBUF       int    `yaml:"so_rcvbuf"`
	SO_SNDBUF       int    `yaml:"so_sndbuf"`
	SO_MARK         int    `yaml:"so_mark"`
	SO_BINDTODEVICE string `yaml:"so_bindtodevice"`
	// contains filtered or unexported fields
}

Only support linux.

type TcpConfig

type TcpConfig struct {
	MaxConcurrentQueries int32 `yaml:"max_concurrent_queries"`
	Threads              int   `yaml:"threads"`
}

type TlsConfig

type TlsConfig struct {
	Cert               string `yaml:"cert"`
	Key                string `yaml:"key"`
	CA                 string `yaml:"ca"`
	InsecureSkipVerify bool   `yaml:"insecure_skip_verify"`
	VerifyClientCert   bool   `yaml:"verify_client_cert"`

	DebugUseTempCert bool `yaml:"debug_use_temp_cert,omitempty"`
}

type UdpConfig

type UdpConfig struct {
	MultiRoutes bool `yaml:"multi_routes"`
	Threads     int  `yaml:"threads"`
}

type UpstreamConfig

type UpstreamConfig struct {
	Tag      string       `yaml:"tag"`
	Addr     string       `yaml:"addr"`
	DialAddr string       `yaml:"dial_addr"`
	Tls      TlsConfig    `yaml:"tls"`
	Socket   SocketConfig `yaml:"socket"`
}

Jump to

Keyboard shortcuts

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