Documentation ¶
Overview ¶
Package config defines, loads and parses project wide configuration settings from various sources
Index ¶
- Constants
- Variables
- func DecoderConfig(result any) *mapstructure.DecoderConfig
- func ExtractInterfaceOrder(buf []byte) ([]string, error)
- func InitDefaults() error
- func Map(v any, tagName string) map[string]any
- type BaseHookSetting
- type ChangedHandler
- type Config
- func (c *Config) AddProvider(provider koanf.Provider) error
- func (c *Config) AddSource(source Source) error
- func (c *Config) Init(args []string) (err error)
- func (c *Config) InterfaceFilter(name string) bool
- func (c *Config) InterfaceOrderByName(name string) []string
- func (c *Config) InterfaceSettings(name string) (cfg *InterfaceSettings)
- func (c *Config) InvokeChangedHandlers(key string, change types.Change) error
- func (c *Config) Marshal(wr io.Writer) error
- func (c *Config) ReloadAllSources() (map[string]types.Change, error)
- func (c *Config) Update(sets map[string]any) (map[string]types.Change, error)
- type ExecHookSetting
- type HookSetting
- type ICESettings
- type InterfaceSettings
- type LocalFileProvider
- type LogSettings
- type LookupProvider
- type Meta
- type Orderable
- type OutputFormat
- type PeerSettings
- type PortRangeSettings
- type RPCSettings
- type RemoteFileProvider
- type Settings
- type Source
- type StructsProvider
- type SubProvidable
- type Versioned
- type Watchable
- type WebHookSetting
- type WireGuardProvider
Constants ¶
const ( DefaultSocketPath = "/var/run/cunicu.sock" // Ephemeral Port Range (RFC6056 Sect. 2.1) EphemeralPortMin = (1 << 15) + (1 << 14) EphemeralPortMax = (1 << 16) - 1 )
const (
DefaultRouteTable = 254 // main table
)
Variables ¶
var ( DefaultPrefixes = []string{"fc2f:9a4d::/32", "10.237.0.0/16"} DefaultBackends = []url.URL{ { Scheme: "grpc", Host: "signal.cunicu.li:443", }, } DefaultICEURLs = []url.URL{ { Scheme: "grpc", Host: "relay.cunicu.li:443", }, } DefaultSettings = Settings{ Backends: DefaultBackends, RPC: RPCSettings{ Socket: DefaultSocketPath, Wait: false, }, Log: LogSettings{ Banner: true, }, WatchInterval: 1 * time.Second, DefaultInterfaceSettings: InterfaceSettings{ DiscoverPeers: true, DiscoverEndpoints: true, SyncConfig: true, SyncHosts: true, SyncRoutes: true, WatchRoutes: true, PortForwarding: true, ICE: ICESettings{ URLs: DefaultICEURLs, CheckInterval: 200 * time.Millisecond, DisconnectedTimeout: 5 * time.Second, FailedTimeout: 25 * time.Second, RestartTimeout: 10 * time.Second, InterfaceFilter: "*", KeepaliveInterval: 2 * time.Second, MaxBindingRequests: 7, PortRange: PortRangeSettings{ Min: EphemeralPortMin, Max: EphemeralPortMax, }, CandidateTypes: []ice.CandidateType{ ice.CandidateTypeHost, ice.CandidateTypeServerReflexive, ice.CandidateTypePeerReflexive, ice.CandidateTypeRelay, }, NetworkTypes: []ice.NetworkType{ ice.NetworkTypeUDP4, ice.NetworkTypeUDP6, ice.NetworkTypeTCP4, ice.NetworkTypeTCP6, }, }, RoutingTable: DefaultRouteTable, ListenPortRange: &PortRangeSettings{ Min: wg.DefaultPort, Max: EphemeralPortMax, }, }, } )
var OutputFormats = []OutputFormat{ OutputFormatJSON, OutputFormatLogger, OutputFormatHuman, }
var RuntimeConfigFile = "/var/lib/cunicu.runtime.yaml"
Functions ¶
func DecoderConfig ¶
func DecoderConfig(result any) *mapstructure.DecoderConfig
DecoderConfig returns the mapstructure DecoderConfig which is used by cunicu
func ExtractInterfaceOrder ¶
func InitDefaults ¶
func InitDefaults() error
Types ¶
type BaseHookSetting ¶
type BaseHookSetting struct {
Type string `koanf:"type"`
}
type ChangedHandler ¶
type Config ¶
type Config struct { *Settings *Meta *koanf.Koanf Runtime *runtimeSource Sources []Source // Settings which are not configurable via configuration file Files []string Domains []string Watch bool Providers []koanf.Provider InterfaceOrder []string InterfaceOrderCLI []string // contains filtered or unexported fields }
func (*Config) AddProvider ¶
func (*Config) InterfaceFilter ¶
InterfaceFilter checks if the provided interface name is matched by any configuration.
func (*Config) InterfaceOrderByName ¶
InterfaceOrderByName returns a list of interface config sections which are used by a given interface
func (*Config) InterfaceSettings ¶
func (c *Config) InterfaceSettings(name string) (cfg *InterfaceSettings)
InterfaceSettings returns interface specific settings These settings are constructed by merging the settings of each interface section which matches the name. This behavior is quite similar to the OpenSSH client configuration file.
func (*Config) InvokeChangedHandlers ¶
func (*Config) ReloadAllSources ¶
ReloadAllSources reloads all configuration sources
type ExecHookSetting ¶
type HookSetting ¶
type HookSetting any
type ICESettings ¶
type ICESettings struct { URLs []url.URL `koanf:"urls,omitempty"` CandidateTypes []ice.CandidateType `koanf:"candidate_types,omitempty"` NetworkTypes []ice.NetworkType `koanf:"network_types,omitempty"` NAT1to1IPs []string `koanf:"nat_1to1_ips,omitempty"` RelayTCP *bool `koanf:"relay_tcp,omitempty"` RelayTLS *bool `koanf:"relay_tls,omitempty"` PortRange PortRangeSettings `koanf:"port_range,omitempty"` Lite bool `koanf:"lite,omitempty"` MDNS bool `koanf:"mdns,omitempty"` MaxBindingRequests int `koanf:"max_binding_requests,omitempty"` InsecureSkipVerify bool `koanf:"insecure_skip_verify,omitempty"` InterfaceFilter string `koanf:"interface_filter,omitempty"` DisconnectedTimeout time.Duration `koanf:"disconnected_timeout,omitempty"` FailedTimeout time.Duration `koanf:"failed_timeout,omitempty"` // KeepaliveInterval used to keep candidates alive KeepaliveInterval time.Duration `koanf:"keepalive_interval,omitempty"` // CheckInterval is the interval at which the agent performs candidate checks in the connecting phase CheckInterval time.Duration `koanf:"check_interval,omitempty"` RestartTimeout time.Duration `koanf:"restart_timeout,omitempty"` Username string `koanf:"username,omitempty"` Password string `koanf:"password,omitempty"` }
func (*ICESettings) HasCandidateType ¶
func (s *ICESettings) HasCandidateType(ct ice.CandidateType) bool
func (*ICESettings) HasNetworkType ¶
func (s *ICESettings) HasNetworkType(nt ice.NetworkType) bool
type InterfaceSettings ¶
type InterfaceSettings struct { HostName string `koanf:"hostname,omitempty"` Domain string `koanf:"domain,omitempty"` ExtraHosts map[string][]net.IPAddr `koanf:"extra_hosts,omitempty"` MTU int `koanf:"mtu,omitempty"` DNS []net.IPAddr `koanf:"dns,omitempty"` Addresses []net.IPNet `koanf:"addresses,omitempty"` Prefixes []net.IPNet `koanf:"prefixes"` Networks []net.IPNet `koanf:"networks,omitempty"` // Peer discovery Community crypto.KeyPassphrase `koanf:"community,omitempty"` Whitelist []crypto.Key `koanf:"whitelist,omitempty"` Blacklist []crypto.Key `koanf:"blacklist,omitempty"` // Endpoint discovery ICE ICESettings `koanf:"ice,omitempty"` PortForwarding bool `koanf:"port_forwarding,omitempty"` // Route sync RoutingTable int `koanf:"routing_table,omitempty"` // Hooks Hooks []HookSetting `koanf:"hooks,omitempty"` // WireGuard UserSpace bool `koanf:"userspace,omitempty"` PrivateKey crypto.Key `koanf:"private_key,omitempty"` ListenPort *int `koanf:"listen_port,omitempty"` ListenPortRange *PortRangeSettings `koanf:"listen_port_range,omitempty"` FirewallMark int `koanf:"fwmark,omitempty"` Peers map[string]PeerSettings `koanf:"peers,omitempty"` // Feature flags DiscoverEndpoints bool `koanf:"discover_endpoints,omitempty"` DiscoverPeers bool `koanf:"discover_peers,omitempty"` SyncConfig bool `koanf:"sync_config,omitempty"` SyncRoutes bool `koanf:"sync_routes,omitempty"` SyncHosts bool `koanf:"sync_hosts,omitempty"` WatchConfig bool `koanf:"watch_config,omitempty"` WatchRoutes bool `koanf:"watch_routes,omitempty"` }
func NewInterfaceSettingsFromConfig ¶
func NewInterfaceSettingsFromConfig(c *wg.Config) (*InterfaceSettings, error)
func (*InterfaceSettings) AgentConfig ¶
func (*InterfaceSettings) Check ¶
func (c *InterfaceSettings) Check() error
type LocalFileProvider ¶
func NewLocalFileProvider ¶
func NewLocalFileProvider(path string) *LocalFileProvider
func (*LocalFileProvider) Order ¶
func (p *LocalFileProvider) Order() []string
func (*LocalFileProvider) ReadBytes ¶
func (p *LocalFileProvider) ReadBytes() ([]byte, error)
type LogSettings ¶
type LookupProvider ¶
type LookupProvider struct {
// contains filtered or unexported fields
}
func NewLookupProvider ¶
func NewLookupProvider(domain string) *LookupProvider
func (*LookupProvider) ReadBytes ¶
func (p *LookupProvider) ReadBytes() ([]byte, error)
func (*LookupProvider) SubProviders ¶
func (p *LookupProvider) SubProviders() []koanf.Provider
func (*LookupProvider) Version ¶
func (p *LookupProvider) Version() any
type Meta ¶
type Meta struct { Fields map[string]*Meta Parent *Meta Type reflect.Type // contains filtered or unexported fields }
func (*Meta) AddChangedHandler ¶
func (m *Meta) AddChangedHandler(key string, h ChangedHandler)
func (*Meta) CompletionOptions ¶
func (*Meta) InvokeChangedHandlers ¶
type OutputFormat ¶
type OutputFormat string
const ( OutputFormatJSON OutputFormat = "json" OutputFormatLogger OutputFormat = "logger" OutputFormatHuman OutputFormat = "human" )
func (OutputFormat) MarshalText ¶
func (f OutputFormat) MarshalText() ([]byte, error)
func (*OutputFormat) Set ¶
func (f *OutputFormat) Set(str string) error
func (OutputFormat) String ¶
func (f OutputFormat) String() string
func (*OutputFormat) Type ¶
func (f *OutputFormat) Type() string
func (*OutputFormat) UnmarshalText ¶
func (f *OutputFormat) UnmarshalText(text []byte) error
type PeerSettings ¶
type PortRangeSettings ¶
type RPCSettings ¶
type RemoteFileProvider ¶
type RemoteFileProvider struct {
// contains filtered or unexported fields
}
func NewRemoteFileProvider ¶
func NewRemoteFileProvider(u *url.URL) *RemoteFileProvider
func (*RemoteFileProvider) Order ¶
func (p *RemoteFileProvider) Order() []string
func (*RemoteFileProvider) Read ¶
func (p *RemoteFileProvider) Read() (map[string]interface{}, error)
func (*RemoteFileProvider) ReadBytes ¶
func (p *RemoteFileProvider) ReadBytes() ([]byte, error)
func (*RemoteFileProvider) Version ¶
func (p *RemoteFileProvider) Version() any
type Settings ¶
type Settings struct { Experimental bool `koanf:"experimental,omitempty"` WatchInterval time.Duration `koanf:"watch_interval,omitempty"` Backends []url.URL `koanf:"backends,omitempty"` Log LogSettings `koanf:"log,omitempty"` RPC RPCSettings `koanf:"rpc,omitempty"` DefaultInterfaceSettings InterfaceSettings `koanf:",squash"` Interfaces map[string]InterfaceSettings `koanf:"interfaces"` }
type StructsProvider ¶
type StructsProvider struct {
// contains filtered or unexported fields
}
func NewStructsProvider ¶
func NewStructsProvider(v any, t string) *StructsProvider
StructsProvider is very similar koanf's struct provider but slightly adjusted to our needs.
func (*StructsProvider) ReadBytes ¶
func (p *StructsProvider) ReadBytes() ([]byte, error)
type SubProvidable ¶
type SubProvidable interface {
SubProviders() []koanf.Provider
}
type WebHookSetting ¶
type WireGuardProvider ¶
type WireGuardProvider struct {
// contains filtered or unexported fields
}
func NewWireGuardProvider ¶
func NewWireGuardProvider() *WireGuardProvider
func (*WireGuardProvider) Order ¶
func (p *WireGuardProvider) Order() []string
func (*WireGuardProvider) Read ¶
func (p *WireGuardProvider) Read() (map[string]interface{}, error)
func (*WireGuardProvider) ReadBytes ¶
func (p *WireGuardProvider) ReadBytes() ([]byte, error)
Source Files ¶
- agent.go
- config.go
- defaults.go
- defaults_linux.go
- defaults_unix.go
- handlers.go
- hooks.go
- map.go
- meta.go
- order.go
- provider_env.go
- provider_file.go
- provider_flags.go
- provider_lookup.go
- provider_lookup_others.go
- provider_structs.go
- provider_wg.go
- providers.go
- settings.go
- source.go
- source_runtime.go
- types.go