coremain

package
v4.5.2 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2022 License: GPL-3.0 Imports: 33 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddSubCmd

func AddSubCmd(c *cobra.Command)

func DelPluginType

func DelPluginType(typ string)

DelPluginType deletes the init func for this plugin type. It is a noop if pluginType is not registered.

func GetAllPluginTypes

func GetAllPluginTypes() []string

GetAllPluginTypes returns all plugin types which are configurable.

func LoadNewPersetPluginFuncs

func LoadNewPersetPluginFuncs() map[string]NewPersetPluginFunc

func RegNewPersetPluginFunc

func RegNewPersetPluginFunc(tag string, f NewPersetPluginFunc)

func RegNewPluginFunc

func RegNewPluginFunc(typ string, initFunc NewPluginFunc, argsType NewPluginArgsFunc)

RegNewPluginFunc registers the type. If the type has been registered. RegNewPluginFunc will panic.

func Run

func Run() error

func RunMosdns

func RunMosdns(cfg *Config) error

func StartServer

func StartServer(sf *serverFlags) error

Types

type APIConfig

type APIConfig struct {
	HTTP string `yaml:"http"`
}

type BP

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

BP represents a basic plugin, which implements Plugin. It also has an internal logger, for convenience.

func NewBP

func NewBP(tag string, typ string, lg *zap.Logger, m *Mosdns) *BP

NewBP creates a new BP and initials its logger.

func (*BP) Close

func (p *BP) Close() error

func (*BP) GetMetricsReg

func (p *BP) GetMetricsReg() prometheus.Registerer

GetMetricsReg return a prometheus.Registerer with a prefix of "plugin_${plugin_tag}_]"

func (*BP) L

func (p *BP) L() *zap.Logger

func (*BP) M

func (p *BP) M() *Mosdns

func (*BP) S

func (p *BP) S() *zap.SugaredLogger

func (*BP) Tag

func (p *BP) Tag() string

func (*BP) Type

func (p *BP) Type() string

type BadIPObserverConfig added in v4.3.0

type BadIPObserverConfig struct {
	Threshold        int    `yaml:"threshold"` // Zero Threshold will disable the bad ip observer.
	Interval         int    `yaml:"interval"`  // (sec) Default is 10.
	TTL              int    `yaml:"ttl"`       // (sec) Default is 600 (10min).
	OnUpdateCallBack string `yaml:"on_update_callback"`
	// IP masks to aggregate an IP range.
	IPv4Mask int `yaml:"ipv4_mask"` // Default is 32.
	IPv6Mask int `yaml:"ipv6_mask"` // Default is 48.
}

BadIPObserverConfig is a copy of ip_observer.BadIPObserverOpts.

func (*BadIPObserverConfig) Init added in v4.3.0

func (c *BadIPObserverConfig) Init()

type Config

type Config struct {
	Log           mlog.LogConfig                     `yaml:"log"`
	Include       []string                           `yaml:"include"`
	DataProviders []data_provider.DataProviderConfig `yaml:"data_providers"`
	Plugins       []PluginConfig                     `yaml:"plugins"`
	Servers       []ServerConfig                     `yaml:"servers"`
	API           APIConfig                          `yaml:"api"`

	// Experimental
	Security SecurityConfig `yaml:"security"`
}

type ExecutablePlugin

type ExecutablePlugin interface {
	Plugin
	executable_seq.Executable
}

ExecutablePlugin represents a Plugin that is Executable.

type MatcherPlugin

type MatcherPlugin interface {
	Plugin
	executable_seq.Matcher
}

MatcherPlugin represents a Plugin that is a Matcher.

type Mosdns

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

func (*Mosdns) GetBadIPObserver added in v4.3.0

func (m *Mosdns) GetBadIPObserver() ip_observer.IPObserver

GetBadIPObserver returns the ip_observer.BadIPObserver. It returns nil if is not enabled.

func (*Mosdns) GetDataManager

func (m *Mosdns) GetDataManager() *data_provider.DataManager

func (*Mosdns) GetExecutables

func (m *Mosdns) GetExecutables() map[string]executable_seq.Executable

func (*Mosdns) GetHTTPAPIMux

func (m *Mosdns) GetHTTPAPIMux() *http.ServeMux

GetHTTPAPIMux returns the api http.ServeMux. The pattern "/plugins/plugin_tag/" has been registered if Plugin implements http.Handler interface. Plugin caller should register path that has "/plugins/plugin_tag/" prefix only.

func (*Mosdns) GetMatchers

func (m *Mosdns) GetMatchers() map[string]executable_seq.Matcher

func (*Mosdns) GetMetricsReg added in v4.2.0

func (m *Mosdns) GetMetricsReg() prometheus.Registerer

GetMetricsReg returns a prometheus.Registerer with a prefix of "mosdns_"

func (*Mosdns) GetSafeClose

func (m *Mosdns) GetSafeClose() *safe_close.SafeClose

type NewPersetPluginFunc

type NewPersetPluginFunc func(bp *BP) (Plugin, error)

type NewPluginArgsFunc

type NewPluginArgsFunc func() interface{}

NewPluginArgsFunc represents a func that creates a new args object.

type NewPluginFunc

type NewPluginFunc func(bp *BP, args interface{}) (p Plugin, err error)

NewPluginFunc represents a func that can init a Plugin. args is the object created by NewPluginArgsFunc.

type Plugin

type Plugin interface {
	Tag() string
	Type() string
	io.Closer
}

Plugin represents the basic plugin.

func NewPlugin

func NewPlugin(c *PluginConfig, lg *zap.Logger, m *Mosdns) (p Plugin, err error)

NewPlugin initialize a Plugin from c.

type PluginConfig

type PluginConfig struct {
	// Tag, required
	Tag string `yaml:"tag"`

	// Type, required
	Type string `yaml:"type"`

	// Args, might be required by some plugins.
	// The type of Args is depended on RegNewPluginFunc.
	// If it's a map[string]interface{}, it will be converted by mapstruct.
	Args interface{} `yaml:"args"`
}

PluginConfig represents a plugin config

type PluginTypeInfo

type PluginTypeInfo struct {
	NewPlugin NewPluginFunc
	NewArgs   NewPluginArgsFunc
}

func GetPluginType

func GetPluginType(typ string) (PluginTypeInfo, bool)

GetPluginType gets the registered type init func.

type SecurityConfig added in v4.3.0

type SecurityConfig struct {
	BadIPObserver BadIPObserverConfig `yaml:"bad_ip_observer"`
}

type ServerConfig

type ServerConfig struct {
	Exec      string                  `yaml:"exec"`
	Timeout   uint                    `yaml:"timeout"` // (sec) query timeout.
	Listeners []*ServerListenerConfig `yaml:"listeners"`
}

type ServerListenerConfig

type ServerListenerConfig struct {
	// Protocol: server protocol, can be:
	// "", "udp" -> udp
	// "tcp" -> tcp
	// "dot", "tls" -> dns over tls
	// "doh", "https" -> dns over https (rfc 8844)
	// "http" -> dns over https (rfc 8844) but without tls
	Protocol string `yaml:"protocol"`

	// Addr: server "host:port" addr.
	// Addr cannot be empty.
	Addr string `yaml:"addr"`

	Cert                string `yaml:"cert"`                    // certificate path, used by dot, doh
	Key                 string `yaml:"key"`                     // certificate key path, used by dot, doh
	URLPath             string `yaml:"url_path"`                // used by doh, http. If it's empty, any path will be handled.
	GetUserIPFromHeader string `yaml:"get_user_ip_from_header"` // used by doh, http.
	ProxyProtocol       bool   `yaml:"proxy_protocol"`          // accepting the PROXYProtocol

	IdleTimeout uint `yaml:"idle_timeout"` // (sec) used by tcp, dot, doh as connection idle timeout.
}

Jump to

Keyboard shortcuts

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