Documentation
¶
Overview ¶
Package config provides functions for reading the config.
Package config provides functions for reading the config.
Package config provides functions for reading the config.
Index ¶
- Constants
- Variables
- func APIBaseURL(api string) string
- func AlignCurrServer()
- func AnyNodeConnected() bool
- func CheckUID()
- func ClearAllDesiredConnections() error
- func ClearDesiredExitNode(username, tenantID string) error
- func ClearDesiredState(username, tenantID string) error
- func ClearUserDesiredConnections(username string) error
- func ConsumeServerContextChanged() bool
- func ControlPlaneHostnames() []string
- func ControlPlaneIPsForHost(name string) []net.IP
- func ControlPlanePinIPs() []net.IP
- func Convert(h *Config, n *Node) (models.Host, models.Node)
- func CopyWindowsLegacyState() error
- func DeleteClientNodes()
- func DeleteNode(k string)
- func DeleteNodes()
- func DeleteServer(k string)
- func DeleteServerHostPeerCfg()
- func DemoteServerToPartial(id string) string
- func FirewallHasChanged() bool
- func ForgetDesiredNetwork(username, tenantID, network string) error
- func FormatName(name string) string
- func GetCurrServerCtxFromFile() (string, error)
- func GetDesiredAutoExit(username, tenantID string) bool
- func GetDesiredEgressID(username, tenantID string) string
- func GetDesiredExitNetwork(username, tenantID string) string
- func GetDesiredNetworks(username, tenantID string) []string
- func GetDesiredWantIGW(username, tenantID string) bool
- func GetNetclientInstallDir() string
- func GetNetclientInstallPath() string
- func GetNetclientPath() string
- func GetServers() (servers []string)
- func InCharSet(name string) bool
- func IsControlPlaneHostname(name string) bool
- func IsPidDead(pid int) bool
- func IsRegistered() bool
- func IsRegisteredToServer(server string) bool
- func IsTenantServerKey(id string) bool
- func IsUsableServerAPI(api, serverKey string) bool
- func IsUserOwnedDevice() bool
- func Lock(lockfile string) error
- func MarkServerContextChanged()
- func NormalizeServerAPI(id string) string
- func NormalizeServerHost(id string) string
- func PreferExistingServerAPI(existing, incoming string) string
- func ReadNodeConfig() error
- func ReadServerConf() error
- func RefreshControlPlaneEndpoints(server *Server) (changed bool)
- func RememberDesiredNetwork(username, tenantID, network string) error
- func RemoveServerHostPeerCfg()
- func ResolveServerKey(id string) string
- func SaveServer(name string, server Server) error
- func SeedControlPlaneEndpointsFromServers()
- func SetCurrServerCtxInFile(server string) error
- func SetDesiredAutoExitNode(username, tenantID, network, egressID string) error
- func SetDesiredConnectionsDirForTest(dir string)
- func SetDesiredExitNode(username, tenantID, network, egressID string) error
- func SetDesiredNetworks(username, tenantID string, networks []string) error
- func SetDesiredWantIGW(username, tenantID string, wantIGW bool) error
- func SetFirewall()
- func SetLookupControlPlaneIPsForTest(fn func(host string) ([]net.IP, error))
- func SetNetclientServerContext(id uuid.UUID, tenantID string)
- func SetNodes(nodes []models.Node)
- func SetServerCtx()
- func SetVersion(ver string)
- func SnapshotDesiredState(username, tenantID string, networks []string, wantIGW, autoExit bool, ...) error
- func SwitchToRemainingServer()
- func SyncTenantID(hostID uuid.UUID, tenantID string) bool
- func ToIPNet(cidr string) net.IPNet
- func Unlock(lockfile string) error
- func UpdateHost(host *schema.Host) (resetInterface, restart, sendHostUpdate bool)
- func UpdateHostPeers(peers []wgtypes.PeerConfig)
- func UpdateNetclient(c Config)
- func UpdateNodeMap(k string, value Node)
- func UpdateServer(name string, server Server)
- func UpdateServerConfig(cfg *models.ServerConfig)
- func UpsertPartialServer(domain, api string) error
- func WindowsShouldCopyState(name string) bool
- func WriteJSONAtomic(filePath string, data any, lockfile string, perm os.FileMode) error
- func WriteNetclientConfig() error
- func WriteNodeConfig() error
- func WriteServerConfig() error
- type Config
- type DesiredState
- type InitType
- type Node
- type NodeMap
- type Server
- type TurnConfig
- type UnderlayPin
Constants ¶
const ( // LinuxAppDataPath - linux path LinuxAppDataPath = "/etc/netclient/" // MacAppDataPath - mac path MacAppDataPath = "/Applications/Netclient/" // WindowsInstallDir holds the 64-bit binary, WinSW, config, and logs. WindowsInstallDir = `C:\Program Files\Netclient\` // WindowsLegacyDir is the previous install under Program Files (x86). WindowsLegacyDir = `C:\Program Files (x86)\Netclient\` // Timeout timelimit for obtaining/releasing lockfile Timeout = time.Second * 5 // ConfigLockfile lockfile to control access to config file ConfigLockfile = "config.lck" // MaxNameLength maximum length of a node name MaxNameLength = 62 // DefaultListenPort default port for wireguard DefaultListenPort = 51821 // DefaultMTU default MTU for wireguard DefaultMTU = 1420 )
const ( // DefaultHostID {0EF230F0-2EAD-4370-B0F9-AFC2D2A039E6} is a fixed string, // for creating the unique GUID. It's a meaningless unique GUID here to // make sure only one network profile is created. DefaultHostID = "0EF230F0-2EAD-4370-B0F9-AFC2D2A039E6" )
const NodeLockfile = "netclient-nodes.lck"
NodeLockFile is name of lockfile for controlling access to node config file on disk
const ServerLockfile = "netclient-servers.lck"
ServerLockFile is a lockfile for controlling access to the server map file on disk
Variables ¶
var ( // Version - default version string Version = "dev" // FwClose - firewall manager shutdown func FwClose func() = func() {} // WgPublicListenPort - host's wireguard public listen port WgPublicListenPort int // HostPublicIP - host's public ipv4 endpoint HostPublicIP net.IP // HostPublicIP6 - host's public ipv6 endpoint HostPublicIP6 net.IP // HostNatType - host's NAT type HostNatType string )
var CurrServer string
CurrServer - holds the value of current server of client
var Servers map[string]Server
Servers is map of servers indexed by server name
Functions ¶
func APIBaseURL ¶ added in v1.8.0
APIBaseURL returns https://<api> where api is host:port.
func AlignCurrServer ¶ added in v1.8.0
func AlignCurrServer()
AlignCurrServer sets CurrServer to the resolved servers.json key when possible.
func AnyNodeConnected ¶ added in v1.8.0
func AnyNodeConnected() bool
AnyNodeConnected reports whether any network is locally marked connected.
func CheckUID ¶ added in v0.20.5
func CheckUID()
CheckUID - Checks to make sure user has root privileges
func ClearAllDesiredConnections ¶ added in v1.8.0
func ClearAllDesiredConnections() error
ClearAllDesiredConnections drops every user's restore snapshot. Call when CurrServer changes so login on the new host does not reconnect networks/exit nodes that belonged to the previous server (desired state is keyed only by username+tenant, not by server).
func ClearDesiredExitNode ¶ added in v1.8.0
ClearDesiredExitNode clears exit restore intent for a user+tenant.
func ClearDesiredState ¶ added in v1.8.0
ClearDesiredState drops networks + exit restore intent for one user+tenant.
func ClearUserDesiredConnections ¶ added in v1.8.0
ClearUserDesiredConnections drops every tenant restore snapshot for username. Used when switching Desktop accounts so the next login does not reconnect networks that belonged to the previous user on this device.
func ConsumeServerContextChanged ¶ added in v1.8.0
func ConsumeServerContextChanged() bool
ConsumeServerContextChanged reports and clears the server-switch flag.
func ControlPlaneHostnames ¶ added in v1.8.0
func ControlPlaneHostnames() []string
ControlPlaneHostnames returns unique API/broker hostnames for the current server.
func ControlPlaneIPsForHost ¶ added in v1.8.0
ControlPlaneIPsForHost returns cached IPs for a hostname (DNS question OK).
func ControlPlanePinIPs ¶ added in v1.8.0
ControlPlanePinIPs returns all cached control-plane IPs for underlay pinning.
func CopyWindowsLegacyState ¶ added in v1.8.0
func CopyWindowsLegacyState() error
CopyWindowsLegacyState copies config from Program Files (x86)\Netclient into Program Files\Netclient. The copy is finished only after .state-migrated is written. A no-op when there is nothing to copy, including on non-Windows hosts.
func DeleteClientNodes ¶ added in v0.24.2
func DeleteClientNodes()
DeleteClientNodes - delete the nodes in client config
func DeleteNode ¶
func DeleteNode(k string)
DeleteNode deletes the node from the nodemap for the specified network
func DeleteServer ¶
func DeleteServer(k string)
DeleteServer deletes the specified server name from the server map
func DeleteServerHostPeerCfg ¶
func DeleteServerHostPeerCfg()
DeleteServerHostPeerCfg - deletes the host peers for the server
func DemoteServerToPartial ¶ added in v1.8.0
DemoteServerToPartial turns a fully registered server entry into a Settings- style partial (domain + API only, Server and TenantID cleared). Desktop can still show the saved server after the host is deleted remotely; IsRegisteredToServer becomes false so the next login re-registers. Returns the map key kept, or "" if demotion was not possible (missing entry / no API).
func FirewallHasChanged ¶ added in v0.19.0
func FirewallHasChanged() bool
FirewallHasChanged - checks if the configured firewall still matches what is available on the system.
func ForgetDesiredNetwork ¶ added in v1.8.0
ForgetDesiredNetwork records that the user disconnected or left this network.
func FormatName ¶
FormatName ensures name is in character set and is proper length Sets name to blank on failure
func GetCurrServerCtxFromFile ¶ added in v0.20.2
GetCurrServerCtxFromFile - gets current server context from file
func GetDesiredAutoExit ¶ added in v1.8.0
GetDesiredAutoExit reports whether restore should auto-pick the nearest exit.
func GetDesiredEgressID ¶ added in v1.8.0
GetDesiredEgressID returns the exit node egress id to re-select on restore.
func GetDesiredExitNetwork ¶ added in v1.8.0
GetDesiredExitNetwork returns the network where the exit node was selected.
func GetDesiredNetworks ¶ added in v1.8.0
GetDesiredNetworks returns networks this user should auto-connect on login/reboot.
func GetDesiredWantIGW ¶ added in v1.8.0
GetDesiredWantIGW reports whether this user should restore internet-exit routing.
func GetNetclientInstallDir ¶ added in v1.8.0
func GetNetclientInstallDir() string
GetNetclientInstallDir returns the directory that holds the Windows binary and WinSW files. It is empty on other platforms.
func GetNetclientInstallPath ¶
func GetNetclientInstallPath() string
GetNetclientInstallPath returns the full path where netclient should be installed based on OS
func GetNetclientPath ¶
func GetNetclientPath() string
GetNetclientPath - returns path to netclient config directory
func GetServers ¶
func GetServers() (servers []string)
GetServers - gets all the server names host has registered to.
func IsControlPlaneHostname ¶ added in v1.8.0
IsControlPlaneHostname reports whether name (DNS question form OK) is the current server's API or broker host. Used to scope public-DNS fallback.
func IsRegistered ¶ added in v1.8.0
func IsRegistered() bool
IsRegistered reports a tenant-bound enrollment for CurrServer.
func IsRegisteredToServer ¶ added in v1.8.0
IsRegisteredToServer reports whether netclient has a full enrollment for the given server. Classic (non-MSP) enrollments set ServerConfig.Server but may leave TenantID empty; MSP/SaaS sets TenantID. Partial Settings entries from UpsertPartialServer / DemoteServerToPartial leave both empty so they do not count until register/pull.
func IsTenantServerKey ¶ added in v1.8.0
IsTenantServerKey reports whether id is a SaaS/MSP tenant map key (no DNS dots — typically a UUID) rather than a hostname.
func IsUsableServerAPI ¶ added in v1.8.0
IsUsableServerAPI reports whether api is a dialable HTTPS host:port. Bare tenant map keys (UUID:443) are not usable.
func IsUserOwnedDevice ¶ added in v1.8.0
func IsUserOwnedDevice() bool
IsUserOwnedDevice reports whether this host was registered by an end user (Desktop/device flow). User devices are not gateways/relays/egress routers.
func Lock ¶
Lock creates a lockfile with pid as contents if lockfile exists but belongs to defunct process the existing lockfile will be deleted and new one created if unable to create within TIMEOUT returns error
func MarkServerContextChanged ¶ added in v1.8.0
func MarkServerContextChanged()
MarkServerContextChanged records that CurrServer was changed outside of a full register/pull cycle (e.g. desktop POST /server).
func NormalizeServerAPI ¶ added in v1.8.0
NormalizeServerAPI returns host:port for HTTPS API calls. If the input has no port, :443 is appended.
func NormalizeServerHost ¶ added in v1.8.0
NormalizeServerHost returns a server identity with no scheme and no port. Used for .serverctx, servers.json keys, Name, and MQTT topics.
func PreferExistingServerAPI ¶ added in v1.8.0
PreferExistingServerAPI keeps a known-good API when the incoming value is empty, a bare tenant key, or the base domain of an existing api.<base> host.
func ReadServerConf ¶
func ReadServerConf() error
ReadServerConf reads the servers configuration file and populates the server map
func RefreshControlPlaneEndpoints ¶ added in v1.8.0
RefreshControlPlaneEndpoints resolves API/broker IPs, updates the in-memory map, and persists them on the server config when they change. On resolve failure, keeps prior memory/persisted values. Returns true if servers.json should be written.
func RememberDesiredNetwork ¶ added in v1.8.0
RememberDesiredNetwork records that the user connected this network.
func RemoveServerHostPeerCfg ¶ added in v0.18.4
func RemoveServerHostPeerCfg()
RemoveServerHostPeerCfg - sets remove flag for all peers on the given server peers
func ResolveServerKey ¶ added in v1.8.0
ResolveServerKey returns the servers.json map key for the given identifier.
func SaveServer ¶
SaveServer updates the server map with current server struct and writes map to disk
func SeedControlPlaneEndpointsFromServers ¶ added in v1.8.0
func SeedControlPlaneEndpointsFromServers()
SeedControlPlaneEndpointsFromServers loads persisted API/broker IPs into memory.
func SetCurrServerCtxInFile ¶ added in v0.20.2
SetCurrServerCtxInFile - sets the current server context in the file
func SetDesiredAutoExitNode ¶ added in v1.8.0
SetDesiredAutoExitNode records auto-nearest exit intent for restore. egressID is the last chosen node (for display); restore re-picks nearest.
func SetDesiredConnectionsDirForTest ¶ added in v1.8.0
func SetDesiredConnectionsDirForTest(dir string)
SetDesiredConnectionsDirForTest overrides where desired_connections.json is read and written. Pass "" to restore the production path.
func SetDesiredExitNode ¶ added in v1.8.0
SetDesiredExitNode records a manual exit selection for restore (sets want_igw, clears auto_exit).
func SetDesiredNetworks ¶ added in v1.8.0
SetDesiredNetworks replaces the auto-connect list for a user+tenant.
func SetDesiredWantIGW ¶ added in v1.8.0
SetDesiredWantIGW updates only the exit-restore flag for a user+tenant. Clearing want_igw also drops auto_exit and a stored egress id.
func SetFirewall ¶ added in v0.19.0
func SetFirewall()
SetFirewall - determine and record firewall in use. Respects user's explicit choice if that firewall is still available; only auto-detects when no valid firewall has been configured.
func SetLookupControlPlaneIPsForTest ¶ added in v1.8.0
SetLookupControlPlaneIPsForTest replaces the resolver used by RefreshControlPlaneEndpoints. Pass nil to restore the default bounded resolver.
func SetNetclientServerContext ¶ added in v1.7.0
func SetServerCtx ¶ added in v0.20.2
func SetServerCtx()
SetServerCtx - sets netclient's server context
func SnapshotDesiredState ¶ added in v1.8.0
func SnapshotDesiredState(username, tenantID string, networks []string, wantIGW, autoExit bool, egressID, exitNetwork string) error
SnapshotDesiredState records networks to restore and exit-node intent (want_igw + auto_exit + optional egress id) so login can re-select and apply routes.
func SwitchToRemainingServer ¶ added in v1.7.0
func SwitchToRemainingServer()
func Unlock ¶
Unlock removes a lockfile if contents of lockfile match current pid also removes lockfile if owner process is no longer running will return TIMEOUT error if timeout exceeded
func UpdateHost ¶ added in v0.18.4
func UpdateHostPeers ¶
func UpdateHostPeers(peers []wgtypes.PeerConfig)
UpdateHostPeers - updates host peer map in the netclient config
func UpdateNetclient ¶
func UpdateNetclient(c Config)
UpdateNetclient updates the in memory version of the host configuration
func UpdateNodeMap ¶
UpdateNodeMap updates the in memory nodemap for the specified network
func UpdateServer ¶
UpdateServer updates the in-memory server map
func UpdateServerConfig ¶
func UpdateServerConfig(cfg *models.ServerConfig)
UpdateServerConfig updates the in memory server map with values provided from netmaker server
func UpsertPartialServer ¶ added in v1.8.0
UpsertPartialServer stores domain identity + API host:port before full registration. Leaves ServerConfig.Server and TenantID empty so IsRegisteredToServer stays false until register. domain is stored without a leading "api." label (Name / map key); api keeps the full API host.
func WindowsShouldCopyState ¶ added in v1.8.0
WindowsShouldCopyState reports whether a legacy install file is config rather than a binary. Executables, driver DLLs, and the WinSW xml stay in the install directory.
func WriteJSONAtomic ¶ added in v1.1.0
func WriteNetclientConfig ¶
func WriteNetclientConfig() error
WriteNetclientConfiig writes the in memory host configuration to disk
Types ¶
type Config ¶
type Config struct {
schema.Host
PrivateKey wgtypes.Key `json:"privatekey" yaml:"privatekey"`
TrafficKeyPrivate []byte `json:"traffickeyprivate" yaml:"traffickeyprivate"`
HostPeers []wgtypes.PeerConfig `json:"-" yaml:"-"`
InitType InitType `json:"inittype" yaml:"inittype"`
//for Internet gateway
OriginalDefaultGatewayIp net.IP `json:"original_default_gateway_ip_old" yaml:"original_default_gateway_ip_old"`
OriginalDefaultGatewayIp6 net.IP `json:"original_default_gateway_ip6_old" yaml:"original_default_gateway_ip6_old"`
CurrGwNmIP net.IP `json:"curr_gw_nm_ip" yaml:"curr_gw_nm_ip"`
CurrGwNmIP6 net.IP `json:"curr_gw_nm_ip6" yaml:"curr_gw_nm_ip6"`
// UnderlayPins - host routes installed via the LAN gateway while an exit is
// active; persisted so teardown removes exactly these even after a restart.
UnderlayPins []UnderlayPin `json:"underlay_pins,omitempty" yaml:"underlay_pins,omitempty"`
//for manage DNS
DNSManagerType string `json:"dns_manager_type" yaml:"dns_manager_type"`
NameServers []string `json:"name_servers" yaml:"name_servers"`
DNSSearch string `json:"dns_search" yaml:"dns_search"`
DNSOptions string `json:"dns_options" yaml:"dns_options"`
FwMark int `json:"fwmark" yaml:"fwmark"`
}
Config configuration for netclient and host as a whole
func Netclient ¶
func Netclient() *Config
Netclient returns a pointer to the im memory version of the host configuration
func ReadNetclientConfig ¶
ReadNetclientConfig reads the host configuration file and returns it as an instance.
type DesiredState ¶ added in v1.8.0
type DesiredState struct {
Networks []string `json:"networks"`
WantIGW bool `json:"want_igw"`
// AutoExit means restore should pick the nearest available exit node
// (latency/geo) instead of re-selecting a fixed egress_id.
AutoExit bool `json:"auto_exit,omitempty"`
EgressID string `json:"egress_id,omitempty"`
ExitNetwork string `json:"exit_network,omitempty"`
}
DesiredState is the reconnect record for one user+tenant on this host.
type Node ¶
type Node struct {
models.CommonNode
}
Node provides configuration of a node
func GetConnectedNodes ¶ added in v1.8.0
func GetConnectedNodes() []Node
GetConnectedNodes returns the nodes that are connected to their network
func (*Node) PrimaryAddress ¶
PrimaryAddress returns the primary address of a node
type NodeMap ¶
NodeMap is an in memory map of the all nodes indexed by network name
var Nodes NodeMap
Nodes provides a map of node configurations indexed by network name
type Server ¶
type Server struct {
models.ServerConfig
Name string `json:"name" yaml:"name"`
MQID uuid.UUID `json:"mqid" yaml:"mqid"`
Nodes map[string]bool `json:"nodes" yaml:"nodes"`
AccessKey string `json:"accesskey" yaml:"accesskey"`
NameServers []string `json:"name_servers"`
DnsNameservers []models.Nameserver `json:"dns_nameservers"`
// CachedAPIAddrs / CachedBrokerAddrs are last-known control-plane IPs used
// for LAN underlay pins (and DNS answers) while an internet exit is active.
CachedAPIAddrs []string `json:"cached_api_addrs,omitempty"`
CachedBrokerAddrs []string `json:"cached_broker_addrs,omitempty"`
}
Server represents a server configuration
func GetServerByAPIHost ¶ added in v1.7.0
func ResolveServer ¶ added in v1.8.0
ResolveServer finds a server by map key or by API/Name/Server fields. The returned key is always a bare domain (no port) for MQTT / .serverctx identity.
When id is empty, a single configured server is returned (current-context lookup). A non-empty id that does not match must not fall back to that single server — otherwise POST /server for a new host rewrites the existing entry's API while leaving .serverctx unchanged.
type TurnConfig ¶ added in v0.19.0
TurnConfig - struct to hold turn server config
type UnderlayPin ¶ added in v1.8.0
UnderlayPin is one host route installed via the LAN. Via is the platform-specific next hop the route was installed with.