plugins

package
v0.0.0-...-30efb34 Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2024 License: Apache-2.0 Imports: 31 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrBreakProcessing = errors.New("processing stopped")
)

Functions

func CreateNewHandlerCtx

func CreateNewHandlerCtx() context.Context

func IsNoCache

func IsNoCache(ctx context.Context) bool

func LogMsgWithPrefix

func LogMsgWithPrefix(prefixKey, prefixVal string, ctx context.Context, msg *dns.Msg) error

func LogRfc8427Style

func LogRfc8427Style(ctx context.Context, msg *dns.Msg) error

func LogRfc8427StyleWithPrefix

func LogRfc8427StyleWithPrefix(prefixKey, prefixVal string, ctx context.Context, msg *dns.Msg) error

This version is significantly slower (~6x) than the text-based version

func LogTextStyle

func LogTextStyle(ctx context.Context, msg *dns.Msg) error

func PrintPluginHelp

func PrintPluginHelp(pluginName string, config interface{}, out io.Writer)

Add a "comment" tag to the plugin configuration struct to provide help

func PrintPlugins

func PrintPlugins[P Plugin](out io.Writer)

func QueryCtx

func QueryCtx(ctx context.Context) context.Context

func QueryMetadata

func QueryMetadata(ctx context.Context) map[string]interface{}

func RegisterPlugin

func RegisterPlugin(plugin Plugin)

RegisterPlugin registers a plugin

func ResponseCtx

func ResponseCtx(ctx context.Context) context.Context

func ResponseMetadata

func ResponseMetadata(ctx context.Context) map[string]interface{}

func RunForAllPlugins

func RunForAllPlugins(f func(p Plugin) error) error

func SetNoCache

func SetNoCache(ctx context.Context, val bool)

func UnmarshalConfiguration

func UnmarshalConfiguration(config map[string]interface{}, v interface{}) error

Types

type CacheKeyFunc

type CacheKeyFunc func(context.Context, *dns.Msg) (string, error)

type CachePlugin

type CachePlugin struct {
	CacheKey CacheKeyFunc
	// contains filtered or unexported fields
}

func (*CachePlugin) Configure

func (c *CachePlugin) Configure(ctx context.Context, config map[string]interface{}) error

Configure the plugin.

func (*CachePlugin) Name

func (q *CachePlugin) Name() string

func (*CachePlugin) PrintHelp

func (c *CachePlugin) PrintHelp(out io.Writer)

PrintHelp prints the configuration help for the plugin.

func (*CachePlugin) Query

func (c *CachePlugin) Query(ctx context.Context, msg *dns.Msg) error

func (*CachePlugin) Response

func (c *CachePlugin) Response(ctx context.Context, msg *dns.Msg) error

func (*CachePlugin) StartClient

func (c *CachePlugin) StartClient(ctx context.Context, handler Handler) error

Start the protocol plugin.

func (*CachePlugin) StopClient

func (c *CachePlugin) StopClient(ctx context.Context) error

Stop the protocol plugin.

type CachePluginConfig

type CachePluginConfig struct {
	MaxElements      int           `toml:"maxElements" comment:"Max Elements in cache" default:"1000"`
	MaxStaleElements int           `toml:"maxStaleElements" comment:"Max Elements in stale cache" default:"10000"`
	StaleDuration    time.Duration `toml:"staleDuration" comment:"Duration of stale cache" default:"24h"`
	StaleCache       bool          `toml:"staleCache" comment:"Enable Stale Caching" default:"false"`
	StaleTTL         time.Duration `toml:"staleTTL" comment:"Max TTL of record for a Stale Cache response" default:"30s"`
	NegativeAnswers  bool          `toml:"negativeAnswers" comment:"Enable Negative Answers Caching" default:"false"`
}

type DO53ClientPlugin

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

func (*DO53ClientPlugin) Configure

func (d *DO53ClientPlugin) Configure(ctx context.Context, config map[string]interface{}) error

Configure the plugin.

func (*DO53ClientPlugin) Name

func (d *DO53ClientPlugin) Name() string

func (*DO53ClientPlugin) PrintHelp

func (d *DO53ClientPlugin) PrintHelp(out io.Writer)

PrintHelp prints the configuration help for the plugin.

func (*DO53ClientPlugin) Query

func (d *DO53ClientPlugin) Query(ctx context.Context, msg *dns.Msg) error

func (*DO53ClientPlugin) StartClient

func (d *DO53ClientPlugin) StartClient(ctx context.Context, handler Handler) error

Start the protocol plugin.

func (*DO53ClientPlugin) StopClient

func (d *DO53ClientPlugin) StopClient(ctx context.Context) error
func createTCPConn() *net.TCPConn {
	lAddr, err := net.ResolveTCPAddr(tcpProto, ":0")
	if err != nil {
		log.Error().Err(err).Msg("ResolveTCPAddr failed")
	}
	conn, err := net.ListenTCP(tcpProto, lAddr)
	if err != nil {
		log.Error().Err(err).Msg("ListenTCP failed")
	}
	return conn
}

Stop the protocol plugin.

type DO53ClientPluginConfig

type DO53ClientPluginConfig struct {
	AlwaysRetryOverTcp bool     `toml:"alwaysRetryOverTCP" comment:"Always Retry a Failed UDP Query over TCP" default:"true"`
	Upstream           []string `toml:"upstream" comment:"Address and Port of upstream nameserver"`
	UdpConnPoolSize    int      `toml:"udpConnectionPoolSize" comment:"UDP Connection Pool Size" default:"8000"`
	Timeout            string   `toml:"timeout" comment:"Timeout duration" default:"2s"`
	// contains filtered or unexported fields
}

type DO53GnetServerPlugin

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

func (*DO53GnetServerPlugin) Configure

func (d *DO53GnetServerPlugin) Configure(ctx context.Context, config map[string]interface{}) error

Configure the plugin.

func (*DO53GnetServerPlugin) ListenTCP

func (d *DO53GnetServerPlugin) ListenTCP() error

func (*DO53GnetServerPlugin) ListenUDP

func (d *DO53GnetServerPlugin) ListenUDP() error

func (*DO53GnetServerPlugin) Name

func (d *DO53GnetServerPlugin) Name() string

func (*DO53GnetServerPlugin) OnBoot

func (d *DO53GnetServerPlugin) OnBoot(eng gnet.Engine) (action gnet.Action)

Gnet Events

func (*DO53GnetServerPlugin) OnClose

func (d *DO53GnetServerPlugin) OnClose(c gnet.Conn, err error) (action gnet.Action)

func (*DO53GnetServerPlugin) OnOpen

func (d *DO53GnetServerPlugin) OnOpen(c gnet.Conn) (out []byte, action gnet.Action)

func (*DO53GnetServerPlugin) OnShutdown

func (d *DO53GnetServerPlugin) OnShutdown(eng gnet.Engine)

func (*DO53GnetServerPlugin) OnTick

func (d *DO53GnetServerPlugin) OnTick() (delay time.Duration, action gnet.Action)

func (*DO53GnetServerPlugin) OnTraffic

func (d *DO53GnetServerPlugin) OnTraffic(c gnet.Conn) (action gnet.Action)

func (*DO53GnetServerPlugin) PrintHelp

func (d *DO53GnetServerPlugin) PrintHelp(out io.Writer)

PrintHelp prints the configuration help for the plugin.

func (*DO53GnetServerPlugin) Response

func (d *DO53GnetServerPlugin) Response(ctx context.Context, msg *dns.Msg) error

func (*DO53GnetServerPlugin) StartServer

func (d *DO53GnetServerPlugin) StartServer(sctx context.Context, handler Handler) error

Start the protocol plugin.

func (*DO53GnetServerPlugin) StopServer

func (d *DO53GnetServerPlugin) StopServer(ctx context.Context) error

Stop the protocol plugin.

type DO53GnetServerPluginConfig

type DO53GnetServerPluginConfig struct {
	Listen            string        `toml:"listen" comment:"Listen Address and Port" default:"53"`
	PoolSizeTCP       int           `toml:"tcpPoolSize" comment:"Worker Pool Size" default:"10"`
	PoolSizeUDP       int           `toml:"udpPoolSize" comment:"Worker Pool Size" default:"10"`
	TcpEventLoopCount int           `toml:"tcpEventLoopCount" comment:"Count of TCP Event Loops"`
	UdpEventLoopCount int           `toml:"udpEventLoopCount" comment:"Count of TCP Event Loops"`
	TcpBufferSize     int           `toml:"tcpBufferSize" comment:"Size TCP socket buffers" default:"10240"`
	UdpBufferSize     int           `toml:"udpBufferSize" comment:"Size UDP socket buffers" default:"10240"`
	MaxQueriesPerTCP  int           `toml:"maxQueriesPerTCPStream" comment:"Size UDP socket buffers" default:"50"`
	TcpKeepAlive      time.Duration `toml:"tcpKeepAlive" comment:"time to maintain tcp keep-alive" default:"10s"`
	EnableLogging     bool          `toml:"enableLogging" comment:"Enable Logging on gnet" default:"false"`
}

type DO53ServerPlugin

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

func (*DO53ServerPlugin) Configure

func (d *DO53ServerPlugin) Configure(ctx context.Context, config map[string]interface{}) error

Configure the plugin.

func (*DO53ServerPlugin) ListenTCP

func (d *DO53ServerPlugin) ListenTCP() (*dns.Server, error)

func (*DO53ServerPlugin) ListenUDP

func (d *DO53ServerPlugin) ListenUDP() (*dns.Server, error)

func (*DO53ServerPlugin) Name

func (d *DO53ServerPlugin) Name() string

func (*DO53ServerPlugin) PrintHelp

func (d *DO53ServerPlugin) PrintHelp(out io.Writer)

PrintHelp prints the configuration help for the plugin.

func (*DO53ServerPlugin) Response

func (d *DO53ServerPlugin) Response(ctx context.Context, msg *dns.Msg) error

func (*DO53ServerPlugin) StartServer

func (d *DO53ServerPlugin) StartServer(sctx context.Context, handler Handler) error

Start the protocol plugin.

func (*DO53ServerPlugin) StopServer

func (d *DO53ServerPlugin) StopServer(ctx context.Context) error

Stop the protocol plugin.

type DO53ServerPluginConfig

type DO53ServerPluginConfig struct {
	Listen   string `toml:"listen" comment:"Listen Address and Port" default:"53"`
	PoolSize int    `toml:"workerPoolSize" comment:"Worker Pool Size" default:"10"`
}

type Handler

type Handler interface {
	Handle(ctx context.Context, msg *dns.Msg) (*dns.Msg, error)
}

type HandlerFunc

type HandlerFunc func(ctx context.Context, msg *dns.Msg) (*dns.Msg, error)

func (HandlerFunc) Handle

func (f HandlerFunc) Handle(ctx context.Context, msg *dns.Msg) (*dns.Msg, error)

type MemoryPlugin

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

func (*MemoryPlugin) Configure

func (m *MemoryPlugin) Configure(ctx context.Context, config map[string]interface{}) (err error)

Configure the plugin.

func (*MemoryPlugin) Name

func (m *MemoryPlugin) Name() string

func (*MemoryPlugin) PrintHelp

func (c *MemoryPlugin) PrintHelp(out io.Writer)

PrintHelp prints the configuration help for the plugin.

type MemoryPluginConfig

type MemoryPluginConfig struct {
	Cap string `toml:"cap" comment:"Cap Memory Use, either size (10MB) or % of available" default:"0b"`
	// contains filtered or unexported fields
}

type MetricsPlugin

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

func (*MetricsPlugin) Configure

func (c *MetricsPlugin) Configure(ctx context.Context, config map[string]interface{}) error

Configure the plugin.

func (*MetricsPlugin) Name

func (q *MetricsPlugin) Name() string

func (*MetricsPlugin) PrintHelp

func (c *MetricsPlugin) PrintHelp(out io.Writer)

PrintHelp prints the configuration help for the plugin.

func (*MetricsPlugin) StartHttpEndpoint

func (c *MetricsPlugin) StartHttpEndpoint()

type MetricsPluginConfig

type MetricsPluginConfig struct {
	Port int `toml:"port" comment:"Metrics HTTP Port" default:"8080"`
}

type Plugin

type Plugin interface {
	Name() string

	// PrintHelp prints the configuration help for the plugin.
	PrintHelp(out io.Writer)

	// Configure the plugin.
	Configure(ctx context.Context, config map[string]interface{}) error
}

Plugin is a DNS plugin

func GetPlugins

func GetPlugins() []Plugin

GetPlugins returns all of the registered plugins

type ProtocolClientPlugin

type ProtocolClientPlugin interface {
	QueryPlugin

	// Start the protocol plugin.
	StartClient(ctx context.Context, handler Handler) error

	// Stop the protocol plugin.
	StopClient(ctx context.Context) error
}

func GetClientPlugins

func GetClientPlugins() []ProtocolClientPlugin

type ProtocolServerPlugin

type ProtocolServerPlugin interface {
	ResponsePlugin

	// Start the protocol plugin.
	StartServer(ctx context.Context, handler Handler) error

	// Stop the protocol plugin.
	StopServer(ctx context.Context) error
}

ProtocolPlugin is a plugin that handles DNS protocol specific logic.

func GetServerPlugins

func GetServerPlugins() []ProtocolServerPlugin

type QueryLoggerPlugin

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

func (*QueryLoggerPlugin) Configure

func (q *QueryLoggerPlugin) Configure(ctx context.Context, config map[string]interface{}) error

Configure the plugin.

func (*QueryLoggerPlugin) Name

func (q *QueryLoggerPlugin) Name() string

func (*QueryLoggerPlugin) PrintHelp

func (q *QueryLoggerPlugin) PrintHelp(out io.Writer)

PrintHelp prints the configuration help for the plugin.

func (*QueryLoggerPlugin) Query

func (q *QueryLoggerPlugin) Query(ctx context.Context, msg *dns.Msg) error

func (*QueryLoggerPlugin) Response

func (q *QueryLoggerPlugin) Response(ctx context.Context, msg *dns.Msg) error

type QueryLoggerPluginConfig

type QueryLoggerPluginConfig struct {
	Format string `toml:"format" comment:"Query logging format (text, rfc8427)" default:"text"`
	// contains filtered or unexported fields
}

type QueryPlugin

type QueryPlugin interface {
	Plugin

	// Process a Query before it is sent to the upstream server.
	Query(ctx context.Context, msg *dns.Msg) error
}

func GetQueryPlugins

func GetQueryPlugins() []QueryPlugin

type ReconfigurablePlugin

type ReconfigurablePlugin interface {
	Plugin

	// Reconfigure the plugin.
	Reconfigure(ctx context.Context, config map[string]interface{}) error
}

type ResponsePlugin

type ResponsePlugin interface {
	Plugin

	// Process a Response from the upstream server.
	Response(ctx context.Context, msg *dns.Msg) error
}

func GetResponsePlugins

func GetResponsePlugins() []ResponsePlugin

Jump to

Keyboard shortcuts

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