config

package
v1.8.0 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2026 License: Apache-2.0 Imports: 26 Imported by: 2 modules, 1 package

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
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
)
View Source
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"
)
View Source
const NodeLockfile = "netclient-nodes.lck"

NodeLockFile is name of lockfile for controlling access to node config file on disk

View Source
const ServerLockfile = "netclient-servers.lck"

ServerLockFile is a lockfile for controlling access to the server map file on disk

Variables

View Source
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
)
View Source
var CurrServer string

CurrServer - holds the value of current server of client

View Source
var Servers map[string]Server

Servers is map of servers indexed by server name

Functions

func APIBaseURL added in v1.8.0

func APIBaseURL(api string) string

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

func ClearDesiredExitNode(username, tenantID string) error

ClearDesiredExitNode clears exit restore intent for a user+tenant.

func ClearDesiredState added in v1.8.0

func ClearDesiredState(username, tenantID string) error

ClearDesiredState drops networks + exit restore intent for one user+tenant.

func ClearUserDesiredConnections added in v1.8.0

func ClearUserDesiredConnections(username string) error

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

func ControlPlaneIPsForHost(name string) []net.IP

ControlPlaneIPsForHost returns cached IPs for a hostname (DNS question OK).

func ControlPlanePinIPs added in v1.8.0

func ControlPlanePinIPs() []net.IP

ControlPlanePinIPs returns all cached control-plane IPs for underlay pinning.

func Convert

func Convert(h *Config, n *Node) (models.Host, models.Node)

Convert converts netclient host/node struct to netmaker host/node structs

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 DeleteNodes added in v0.22.0

func DeleteNodes()

DeleteNodes - removes all nodes

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

func DemoteServerToPartial(id string) string

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

func ForgetDesiredNetwork(username, tenantID, network string) error

ForgetDesiredNetwork records that the user disconnected or left this network.

func FormatName

func FormatName(name string) string

FormatName ensures name is in character set and is proper length Sets name to blank on failure

func GetCurrServerCtxFromFile added in v0.20.2

func GetCurrServerCtxFromFile() (string, error)

GetCurrServerCtxFromFile - gets current server context from file

func GetDesiredAutoExit added in v1.8.0

func GetDesiredAutoExit(username, tenantID string) bool

GetDesiredAutoExit reports whether restore should auto-pick the nearest exit.

func GetDesiredEgressID added in v1.8.0

func GetDesiredEgressID(username, tenantID string) string

GetDesiredEgressID returns the exit node egress id to re-select on restore.

func GetDesiredExitNetwork added in v1.8.0

func GetDesiredExitNetwork(username, tenantID string) string

GetDesiredExitNetwork returns the network where the exit node was selected.

func GetDesiredNetworks added in v1.8.0

func GetDesiredNetworks(username, tenantID string) []string

GetDesiredNetworks returns networks this user should auto-connect on login/reboot.

func GetDesiredWantIGW added in v1.8.0

func GetDesiredWantIGW(username, tenantID string) bool

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 InCharSet

func InCharSet(name string) bool

InCharSet verifies if all chars in string are part of defined charset

func IsControlPlaneHostname added in v1.8.0

func IsControlPlaneHostname(name string) bool

IsControlPlaneHostname reports whether name (DNS question form OK) is the current server's API or broker host. Used to scope public-DNS fallback.

func IsPidDead

func IsPidDead(pid int) bool

IsPidDead checks if given pid is not running

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

func IsRegisteredToServer(server string) bool

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

func IsTenantServerKey(id string) bool

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

func IsUsableServerAPI(api, serverKey string) bool

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

func Lock(lockfile string) error

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

func NormalizeServerAPI(id string) string

NormalizeServerAPI returns host:port for HTTPS API calls. If the input has no port, :443 is appended.

func NormalizeServerHost added in v1.8.0

func NormalizeServerHost(id string) string

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

func PreferExistingServerAPI(existing, incoming string) string

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 ReadNodeConfig

func ReadNodeConfig() error

ReadNodeConfig reads node configuration from disk

func ReadServerConf

func ReadServerConf() error

ReadServerConf reads the servers configuration file and populates the server map

func RefreshControlPlaneEndpoints added in v1.8.0

func RefreshControlPlaneEndpoints(server *Server) (changed bool)

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

func RememberDesiredNetwork(username, tenantID, network string) error

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

func ResolveServerKey(id string) string

ResolveServerKey returns the servers.json map key for the given identifier.

func SaveServer

func SaveServer(name string, server Server) error

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

func SetCurrServerCtxInFile(server string) error

SetCurrServerCtxInFile - sets the current server context in the file

func SetDesiredAutoExitNode added in v1.8.0

func SetDesiredAutoExitNode(username, tenantID, network, egressID string) error

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

func SetDesiredExitNode(username, tenantID, network, egressID string) error

SetDesiredExitNode records a manual exit selection for restore (sets want_igw, clears auto_exit).

func SetDesiredNetworks added in v1.8.0

func SetDesiredNetworks(username, tenantID string, networks []string) error

SetDesiredNetworks replaces the auto-connect list for a user+tenant.

func SetDesiredWantIGW added in v1.8.0

func SetDesiredWantIGW(username, tenantID string, wantIGW bool) error

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

func SetLookupControlPlaneIPsForTest(fn func(host string) ([]net.IP, error))

SetLookupControlPlaneIPsForTest replaces the resolver used by RefreshControlPlaneEndpoints. Pass nil to restore the default bounded resolver.

func SetNetclientServerContext added in v1.7.0

func SetNetclientServerContext(id uuid.UUID, tenantID string)

func SetNodes added in v0.20.2

func SetNodes(nodes []models.Node)

SetNodes - sets server nodes in client config

func SetServerCtx added in v0.20.2

func SetServerCtx()

SetServerCtx - sets netclient's server context

func SetVersion

func SetVersion(ver string)

SetVersion - sets version for use by other packages

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 SyncTenantID added in v1.8.0

func SyncTenantID(hostID uuid.UUID, tenantID string) bool

func ToIPNet

func ToIPNet(cidr string) net.IPNet

ToIPNet parses a cidr string and returns a net.IPNet

func Unlock

func Unlock(lockfile string) error

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 UpdateHost(host *schema.Host) (resetInterface, restart, sendHostUpdate bool)

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

func UpdateNodeMap(k string, value Node)

UpdateNodeMap updates the in memory nodemap for the specified network

func UpdateServer

func UpdateServer(name string, server Server)

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

func UpsertPartialServer(domain, api string) error

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

func WindowsShouldCopyState(name string) bool

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 WriteJSONAtomic(filePath string, data any, lockfile string, perm os.FileMode) error

func WriteNetclientConfig

func WriteNetclientConfig() error

WriteNetclientConfiig writes the in memory host configuration to disk

func WriteNodeConfig

func WriteNodeConfig() error

WriteNodeConfig writes the node map to disk

func WriteServerConfig

func WriteServerConfig() error

WriteServerConfig writes server map 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

func ReadNetclientConfig() (*Config, error)

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 InitType added in v0.20.5

type InitType int

Initype - the type of init system in use

const (
	UnKnown InitType = iota
	Systemd
	SysVInit
	Runit
	OpenRC
	Initd
)

func (InitType) String added in v0.20.5

func (i InitType) String() string

String - returns the string representation of the init type

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 GetNode

func GetNode(k string) Node

GetNode returns returns the node configuation of the specified network name

func (*Node) PrimaryAddress

func (node *Node) PrimaryAddress() net.IPNet

PrimaryAddress returns the primary address of a node

type NodeMap

type NodeMap map[string]Node

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

func GetNodes

func GetNodes() NodeMap

GetNodes returns a shallow copy of the node map. Callers can range the result while UpdateNodeMap replaces the live map.

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 GetServer

func GetServer(name string) *Server

GetServer returns the server struct for the given server name

func GetServerByAPIHost added in v1.7.0

func GetServerByAPIHost(apiHost string) *Server

func ResolveServer added in v1.8.0

func ResolveServer(id string) (*Server, string)

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

type TurnConfig struct {
	Server string
	Domain string
	Port   int
}

TurnConfig - struct to hold turn server config

type UnderlayPin added in v1.8.0

type UnderlayPin struct {
	IP  string `json:"ip" yaml:"ip"`
	Via string `json:"via" yaml:"via"`
}

UnderlayPin is one host route installed via the LAN. Via is the platform-specific next hop the route was installed with.

Jump to

Keyboard shortcuts

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