Documentation ¶
Index ¶
- Variables
- func MustRegMiddleware(typ string, fn NewMiddlewareFunc)
- func RegMetrics(r prometheus.Registerer, cs ...prometheus.Collector) error
- func RegMiddleware(typ string, fn NewMiddlewareFunc) bool
- func ReleaseQueryCtx(q *QueryCtx)
- func SetEmptyRespMQ(q *QueryCtx, rcode dnsmsg.RCode)
- func WakeDecode(dst any, src map[string]any, tagName string) error
- type APIConfig
- type AddonsConfig
- type CacheConfig
- type CacheCtl
- type Config
- type DataProvider
- type Dataloader
- type DomainSet
- type DomainSetConfig
- type ECSConfig
- type ECSZone
- type ECSZoneOverWrite
- type HealthCheckConfig
- type HttpConfig
- type LoadBalancer
- type LoadBalancerBackendConfig
- type LoadBalancerConfig
- type LogConfig
- type Middleware
- type NewMiddlewareFunc
- type PluginCtx
- type Proto
- type QueryCtx
- func (q *QueryCtx) Copy() *QueryCtx
- func (q *QueryCtx) LogQuery() *zerolog.Event
- func (q *QueryCtx) LogResp() *zerolog.Event
- func (q *QueryCtx) LogServerMeta() *zerolog.Event
- func (q *QueryCtx) Reset()
- func (q *QueryCtx) Resp() *dnsmsg.Msg
- func (q *QueryCtx) RespFrom() (resp *dnsmsg.Msg, from string)
- func (q *QueryCtx) SetResp(resp *dnsmsg.Msg)
- func (q *QueryCtx) SetRespFrom(resp *dnsmsg.Msg, from string)
- type QuicConfig
- type RespWriter
- type Router
- func (r *Router) AsyncSingleFlightPrefetch(key []byte, q *QueryCtx, u Upstream)
- func (r *Router) BuiltInHandler(ctx context.Context, q *QueryCtx)
- func (r *Router) Close(err error)
- func (r *Router) Context() context.Context
- func (r *Router) DoPrefetch(key []byte, q *QueryCtx, u Upstream)
- func (r *Router) GetApiMux() *chi.Mux
- func (r *Router) GetCache() *CacheCtl
- func (r *Router) GetDomainSet(tag string) *DomainSet
- func (r *Router) GetECSZone() *ECSZone
- func (r *Router) GetECSZoneOverwrite() *ECSZoneOverWrite
- func (r *Router) GetLoadBalancer(tag string) *LoadBalancer
- func (r *Router) GetMetricsReg() *prometheus.Registry
- func (r *Router) GetUpstream(tag string) *UpstreamWrapper
- func (r *Router) MakeQueryMsg(q *QueryCtx) *dnsmsg.Msg
- func (r *Router) RegMiddlewareReloader(impl Dataloader)
- func (r *Router) Reload() (err error)
- type RuleConfig
- type ServerConfig
- type SocketConfig
- type TcpConfig
- type TlsConfig
- type UdpConfig
- type Upstream
- type UpstreamConfig
- type UpstreamWrapper
- func (uw *UpstreamWrapper) Exchange(ctx context.Context, q *QueryCtx, m *dnsmsg.Msg) error
- func (b *UpstreamWrapper) HcEnabled() bool
- func (b *UpstreamWrapper) HcOffline() bool
- func (b *UpstreamWrapper) HcTryStartPing()
- func (uw *UpstreamWrapper) Ping(ctx context.Context) error
- func (uw *UpstreamWrapper) RegisterMetricsTo(r prometheus.Registerer) error
- func (uw *UpstreamWrapper) Tag() string
Constants ¶
This section is empty.
Variables ¶
var (
ErrConcurrentReload = errors.New("concurrent reloading call")
)
var (
ErrUpstreamOffline = errors.New("upstream is currently offline")
)
Functions ¶
func MustRegMiddleware ¶
func MustRegMiddleware(typ string, fn NewMiddlewareFunc)
func RegMetrics ¶
func RegMetrics(r prometheus.Registerer, cs ...prometheus.Collector) error
func RegMiddleware ¶
func RegMiddleware(typ string, fn NewMiddlewareFunc) bool
func ReleaseQueryCtx ¶
func ReleaseQueryCtx(q *QueryCtx)
func SetEmptyRespMQ ¶
Types ¶
type AddonsConfig ¶
type AddonsConfig struct{}
type CacheConfig ¶
type CacheCtl ¶
type CacheCtl struct {
// contains filtered or unexported fields
}
type Config ¶
type Config struct { Servers []ServerConfig `yaml:"servers"` Upstreams []UpstreamConfig `yaml:"upstreams"` LoadBalancers []LoadBalancerConfig `yaml:"load_balancers"` 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"` API APIConfig `yaml:"api"` Middleware []map[string]any `yaml:"middleware"` }
type DataProvider ¶
type DataProvider[V any] interface { V() *V }
Provider data. Do not retain the result of V(), it may change after router reloaded.
type Dataloader ¶
type Dataloader interface { // Load T and stage the T. Return false if error ocurred. LoadAndStage() (ok bool) // Commit the change. If no T staged, this call is noop. Commit() // Discard the change. If no T staged, this call is noop. Discard() }
type DomainSet ¶
type DomainSet struct {
// contains filtered or unexported fields
}
func (DomainSet) LoadAndStage ¶
func (g DomainSet) LoadAndStage() bool
type DomainSetConfig ¶
type ECSZone ¶
type ECSZone struct {
// contains filtered or unexported fields
}
func (ECSZone) LoadAndStage ¶
func (g ECSZone) LoadAndStage() bool
type ECSZoneOverWrite ¶
type ECSZoneOverWrite struct {
// contains filtered or unexported fields
}
func (ECSZoneOverWrite) LoadAndStage ¶
func (g ECSZoneOverWrite) LoadAndStage() bool
type HealthCheckConfig ¶
type HttpConfig ¶
type LoadBalancer ¶
type LoadBalancer struct {
// contains filtered or unexported fields
}
func (*LoadBalancer) Tag ¶
func (lb *LoadBalancer) Tag() string
type LoadBalancerConfig ¶
type LoadBalancerConfig struct { Tag string `yaml:"tag"` Method string `yaml:"method"` Backends []LoadBalancerBackendConfig `yaml:"backends"` }
type Middleware ¶
type NewMiddlewareFunc ¶
type NewMiddlewareFunc func(ctx PluginCtx, args map[string]any, next Middleware) (Middleware, error)
func GetMiddleware ¶
func GetMiddleware(typ string) NewMiddlewareFunc
type QueryCtx ¶
type QueryCtx struct { Qid uint32 // rand id for logging only. Not the dns msg id. Start time.Time Prefetch bool // This is a prefetch query. // DNS query Question dnsmsg.Question // Always valid. ClientECS netip.Prefix // ECS from client query. Invalid if client query does not have ECS. // Server side info ServerTag string // Which server the query comes from. Maybe empty if not set. Protocol Proto // Server protocol. RemoteAddr netip.AddrPort // Client addr, maybe invalid. e.g from unix socket. ServerName []byte // TLS servername, if protocol is based on TLS (DoT,DoH,DoQ) Host []byte // HTTP host (if protocol is based on HTTP) Path []byte // HTTP path (if protocol is based on HTTP) // Other info ECS2Upstream netip.Prefix // ECS that is going to send to upstream. ECSZone string // zone name for the ECS addr. // contains filtered or unexported fields }
func NewQueryCtx ¶
func NewQueryCtx() *QueryCtx
func (*QueryCtx) LogServerMeta ¶
type QuicConfig ¶
type QuicConfig struct {
MaxStreams int64 `yaml:"max_streams"`
}
type RespWriter ¶
type Router ¶
type Router struct {
// contains filtered or unexported fields
}
func (*Router) AsyncSingleFlightPrefetch ¶
Prefetching q in other goroutine. If a query with same key is currently prefetching, do nothing.
func (*Router) BuiltInHandler ¶
router main handle func.
func (*Router) DoPrefetch ¶
Send q to u, and save response under key.
func (*Router) GetDomainSet ¶
Nil if not configured.
func (*Router) GetECSZoneOverwrite ¶
func (r *Router) GetECSZoneOverwrite() *ECSZoneOverWrite
Nil if not configured.
func (*Router) GetLoadBalancer ¶
func (r *Router) GetLoadBalancer(tag string) *LoadBalancer
Nil if not configured.
func (*Router) GetMetricsReg ¶
func (r *Router) GetMetricsReg() *prometheus.Registry
func (*Router) GetUpstream ¶
func (r *Router) GetUpstream(tag string) *UpstreamWrapper
Nil if not configured.
func (*Router) MakeQueryMsg ¶
Make a dns msg from q, according to r's settings.
func (*Router) RegMiddlewareReloader ¶
func (r *Router) RegMiddlewareReloader(impl Dataloader)
Register a reloader so that it will be reloaded with api /reload. impl must be comparable. This func is not concurrent safe. Should only be called when middleware is initializing.
type RuleConfig ¶
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"`
}
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"` HealthCheck HealthCheckConfig `yaml:"health_check"` }
type UpstreamWrapper ¶
type UpstreamWrapper struct {
// contains filtered or unexported fields
}
Wrapper for upstream.Upstream, with tag info and metrics.
func (*UpstreamWrapper) HcEnabled ¶
func (b *UpstreamWrapper) HcEnabled() bool
func (*UpstreamWrapper) HcOffline ¶
func (b *UpstreamWrapper) HcOffline() bool
Is upstream currently offline. Always return false if health check is disabled.
func (*UpstreamWrapper) HcTryStartPing ¶
func (b *UpstreamWrapper) HcTryStartPing()
Try to start a health check ping asynchronously if upstream is offline. This is useful if caller want trigger the ping test more frequently. e.g. After query failed. 5s minimal ping interval limit applied.
func (*UpstreamWrapper) RegisterMetricsTo ¶
func (uw *UpstreamWrapper) RegisterMetricsTo(r prometheus.Registerer) error
func (*UpstreamWrapper) Tag ¶
func (uw *UpstreamWrapper) Tag() string
Source Files ¶
- api.go
- api_reload.go
- cache.go
- config.go
- context.go
- data_loader.go
- domain_set.go
- ecs.go
- ecs_zone.go
- log.go
- metrics.go
- router.go
- router_handle.go
- router_middleware.go
- router_utils.go
- rule.go
- server_http.go
- server_http_fasthttp.go
- server_http_gohttp.go
- server_quic.go
- server_tcp.go
- server_udp.go
- server_utils.go
- sever.go
- signal_linux.go
- socket_ctl.go
- socket_ctl_linux.go
- tls.go
- upstream.go
- upstream_lb.go
- utils.go