Documentation ¶
Index ¶
- Constants
- Variables
- func InitConfig(v *viper.Viper, name string)
- func Log(ctx context.Context, e *zerolog.Event, format string, v ...any)
- func LookupIP(domain string) []string
- func ResolverTypeFromEndpoint(endpoint string) string
- func SetConfigName(v *viper.Viper, name string)
- func SetConfigNameWithPath(v *viper.Viper, name, configPath string)
- func ValidateConfig(validate *validator.Validate, cfg *Config) error
- type ClientInfo
- type ClientInfoCtxKey
- type Config
- type ListenerConfig
- type ListenerPolicyConfig
- type NetworkConfig
- type ReqIdCtxKey
- type Resolver
- type Rule
- type ServiceConfig
- type UpstreamConfig
- func (uc *UpstreamConfig) BootstrapIPs() []string
- func (uc *UpstreamConfig) Init()
- func (uc *UpstreamConfig) ReBootstrap()
- func (uc *UpstreamConfig) SetCertPool(cp *x509.CertPool)
- func (uc *UpstreamConfig) SetupBootstrapIP()
- func (uc *UpstreamConfig) SetupTransport()
- func (uc *UpstreamConfig) UpstreamSendClientInfo() bool
- func (uc *UpstreamConfig) VerifyDomain() string
Constants ¶
const ( // IpStackBoth indicates that ctrld will use either ipv4 or ipv6 for connecting to upstream, // depending on which stack is available when receiving the DNS query. IpStackBoth = "both" // IpStackV4 indicates that ctrld will use only ipv4 for connecting to upstream. IpStackV4 = "v4" // IpStackV6 indicates that ctrld will use only ipv6 for connecting to upstream. IpStackV6 = "v6" // IpStackSplit indicates that ctrld will use either ipv4 or ipv6 for connecting to upstream, // depending on the record type of the DNS query. IpStackSplit = "split" )
IpStackBoth ...
const ( // ResolverTypeDOH specifies DoH resolver. ResolverTypeDOH = "doh" // ResolverTypeDOH3 specifies DoH3 resolver. ResolverTypeDOH3 = "doh3" // ResolverTypeDOT specifies DoT resolver. ResolverTypeDOT = "dot" // ResolverTypeDOQ specifies DoQ resolver. ResolverTypeDOQ = "doq" // ResolverTypeOS specifies OS resolver. ResolverTypeOS = "os" // ResolverTypeLegacy specifies legacy resolver. ResolverTypeLegacy = "legacy" )
Variables ¶
var ProxyLog = zerolog.New(io.Discard)
ProxyLog emits the log record for proxy operations. The caller should set it only once.
Functions ¶
func InitConfig ¶
InitConfig initializes default config values for given *viper.Viper instance.
func Log ¶
Log emits the logs for a particular zerolog event. The request id associated with the context will be included if presents.
func LookupIP ¶ added in v1.2.0
LookupIP looks up host using OS resolver. It returns a slice of that host's IPv4 and IPv6 addresses.
func ResolverTypeFromEndpoint ¶ added in v1.1.4
ResolverTypeFromEndpoint tries guessing the resolver type with a given endpoint using following rules:
- If endpoint is an IP address -> ResolverTypeLegacy - If endpoint starts with "https://" -> ResolverTypeDOH - If endpoint starts with "quic://" -> ResolverTypeDOQ - For anything else -> ResolverTypeDOT
func SetConfigName ¶ added in v1.1.0
SetConfigName set the config name that ctrld will look for. DEPRECATED: use SetConfigNameWithPath instead.
func SetConfigNameWithPath ¶ added in v1.2.0
SetConfigNameWithPath set the config path and name that ctrld will look for.
func ValidateConfig ¶
ValidateConfig validates the given config.
Types ¶
type ClientInfo ¶ added in v1.2.0
ClientInfo represents ctrld's clients information.
type ClientInfoCtxKey ¶ added in v1.2.0
type ClientInfoCtxKey struct{}
ClientInfoCtxKey is the context key to store client info.
type Config ¶
type Config struct { Service ServiceConfig `mapstructure:"service" toml:"service,omitempty"` Listener map[string]*ListenerConfig `mapstructure:"listener" toml:"listener" validate:"min=1,dive"` Network map[string]*NetworkConfig `mapstructure:"network" toml:"network" validate:"min=1,dive"` Upstream map[string]*UpstreamConfig `mapstructure:"upstream" toml:"upstream" validate:"min=1,dive"` }
Config represents ctrld supported configuration.
func (*Config) HasUpstreamSendClientInfo ¶ added in v1.2.0
HasUpstreamSendClientInfo reports whether the config has any upstream is configured to send client info to Control D DNS server.
type ListenerConfig ¶
type ListenerConfig struct { IP string `mapstructure:"ip" toml:"ip,omitempty" validate:"iporempty"` Port int `mapstructure:"port" toml:"port,omitempty" validate:"gte=0"` Restricted bool `mapstructure:"restricted" toml:"restricted,omitempty"` Policy *ListenerPolicyConfig `mapstructure:"policy" toml:"policy,omitempty"` }
ListenerConfig specifies the networks configuration that ctrld will run on.
func (*ListenerConfig) Init ¶
func (lc *ListenerConfig) Init()
Init initialized necessary values for an ListenerConfig.
type ListenerPolicyConfig ¶
type ListenerPolicyConfig struct { Name string `mapstructure:"name" toml:"name,omitempty"` Networks []Rule `mapstructure:"networks" toml:"networks,omitempty,inline,multiline" validate:"dive,len=1"` Rules []Rule `mapstructure:"rules" toml:"rules,omitempty,inline,multiline" validate:"dive,len=1"` FailoverRcodes []string `mapstructure:"failover_rcodes" toml:"failover_rcodes,omitempty" validate:"dive,dnsrcode"` FailoverRcodeNumbers []int `mapstructure:"-" toml:"-"` }
ListenerPolicyConfig specifies the policy rules for ctrld to filter incoming requests.
type NetworkConfig ¶
type NetworkConfig struct { Name string `mapstructure:"name" toml:"name,omitempty"` Cidrs []string `mapstructure:"cidrs" toml:"cidrs,omitempty" validate:"dive,cidr"` IPNets []*net.IPNet `mapstructure:"-" toml:"-"` }
NetworkConfig specifies configuration for networks where ctrld will handle requests.
type ReqIdCtxKey ¶
type ReqIdCtxKey struct{}
ReqIdCtxKey is the context.Context key for a request id.
type Resolver ¶
Resolver is the interface that wraps the basic DNS operations.
Resolve resolves the DNS query, return the result and the corresponding error.
func NewBootstrapResolver ¶ added in v1.2.1
NewBootstrapResolver returns an OS resolver, which use following nameservers:
- ControlD bootstrap DNS server.
- Gateway IP address (depends on OS).
- Input servers.
func NewResolver ¶
func NewResolver(uc *UpstreamConfig) (Resolver, error)
NewResolver creates a Resolver based on the given upstream config.
type Rule ¶
Rule is a map from source to list of upstreams. ctrld uses rule to perform requests matching and forward the request to corresponding upstreams if it's matched.
type ServiceConfig ¶
type ServiceConfig struct { LogLevel string `mapstructure:"log_level" toml:"log_level,omitempty"` LogPath string `mapstructure:"log_path" toml:"log_path,omitempty"` CacheEnable bool `mapstructure:"cache_enable" toml:"cache_enable,omitempty"` CacheSize int `mapstructure:"cache_size" toml:"cache_size,omitempty"` CacheTTLOverride int `mapstructure:"cache_ttl_override" toml:"cache_ttl_override,omitempty"` CacheServeStale bool `mapstructure:"cache_serve_stale" toml:"cache_serve_stale,omitempty"` Daemon bool `mapstructure:"-" toml:"-"` AllocateIP bool `mapstructure:"-" toml:"-"` }
ServiceConfig specifies the general ctrld config.
type UpstreamConfig ¶
type UpstreamConfig struct { Name string `mapstructure:"name" toml:"name,omitempty"` Type string `mapstructure:"type" toml:"type,omitempty" validate:"oneof=doh doh3 dot doq os legacy"` Endpoint string `mapstructure:"endpoint" toml:"endpoint,omitempty" validate:"required_unless=Type os"` BootstrapIP string `mapstructure:"bootstrap_ip" toml:"bootstrap_ip,omitempty"` Domain string `mapstructure:"-" toml:"-"` IPStack string `mapstructure:"ip_stack" toml:"ip_stack,omitempty" validate:"ipstack"` Timeout int `mapstructure:"timeout" toml:"timeout,omitempty" validate:"gte=0"` // The caller should not access this field directly. // Use UpstreamSendClientInfo instead. SendClientInfo *bool `mapstructure:"send_client_info" toml:"send_client_info,omitempty"` // contains filtered or unexported fields }
UpstreamConfig specifies configuration for upstreams that ctrld will forward requests to.
func (*UpstreamConfig) BootstrapIPs ¶ added in v1.2.0
func (uc *UpstreamConfig) BootstrapIPs() []string
BootstrapIPs returns the bootstrap IPs list of upstreams.
func (*UpstreamConfig) Init ¶
func (uc *UpstreamConfig) Init()
Init initialized necessary values for an UpstreamConfig.
func (*UpstreamConfig) ReBootstrap ¶ added in v1.1.1
func (uc *UpstreamConfig) ReBootstrap()
ReBootstrap re-setup the bootstrap IP and the transport.
func (*UpstreamConfig) SetCertPool ¶ added in v1.2.0
func (uc *UpstreamConfig) SetCertPool(cp *x509.CertPool)
SetCertPool sets the system cert pool used for TLS connections.
func (*UpstreamConfig) SetupBootstrapIP ¶ added in v1.1.1
func (uc *UpstreamConfig) SetupBootstrapIP()
SetupBootstrapIP manually find all available IPs of the upstream. The first usable IP will be used as bootstrap IP of the upstream.
func (*UpstreamConfig) SetupTransport ¶ added in v1.1.0
func (uc *UpstreamConfig) SetupTransport()
SetupTransport initializes the network transport used to connect to upstream server. For now, only DoH upstream is supported.
func (*UpstreamConfig) UpstreamSendClientInfo ¶ added in v1.2.0
func (uc *UpstreamConfig) UpstreamSendClientInfo() bool
UpstreamSendClientInfo reports whether the upstream is configured to send client info to Control D DNS server.
Client info includes:
- MAC
- Lan IP
- Hostname
func (*UpstreamConfig) VerifyDomain ¶ added in v1.2.1
func (uc *UpstreamConfig) VerifyDomain() string
VerifyDomain returns the domain name that could be resolved by the upstream endpoint. It returns empty for non-ControlD upstream endpoint.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
cmd
|
|
internal
|
|
dns/resolvconffile
Package resolvconffile parses & serializes /etc/resolv.conf-style files.
|
Package resolvconffile parses & serializes /etc/resolv.conf-style files. |