Documentation ¶
Index ¶
Constants ¶
const DEFAULT_MTU = 1420 // MTU is not typically present in WireGuard config files, so a default is provided
Variables ¶
var VALID_INTERFACE_KEYS = ConfigurationKeys{"PrivateKey", "Address", "DNS", "ListenPort", "MTU", "SaveConfig", "PreUp", "PostUp", "PreDown", "PostDown", "Table", "FwMark"}
This is probably not a comprehensive list of all valid keys, but its sufficient for most cases
var VALID_PEER_KEYS = ConfigurationKeys{"PublicKey", "AllowedIPs", "Endpoint", "PersistentKeepalive", "PresharedKey"}
Functions ¶
func ParseConfig ¶
func ParseConfig(config io.Reader) (ifaceAddresses, dnsAddresses []netip.Addr, mtu int, ipcConfig string, err error)
This function reads a configuration and returns the following parsed values: - ifaceAddresses: IP addresses with which to configure the local WireGuard interface - dnsAddresses: The DNS server to be used by the local WireGuard interface - mtu: MTU to be configured for the local WireGuard interface - ipcConfig: a string that can be used to configure the WireGuard UAPI via the IPC socket If the configuration file is incomplete, e.g. it is missing any fields mandatory for starting the tunnel, an error is returned At the moment, only one [Interface] and one [Peer] section is supported, as that is the most common use case
Types ¶
type ConfigSection ¶
type ConfigSection int
Enum for the different sections in the config file, this is later when parsing a config file to determine the state
const ( SECTION_INTERFACE ConfigSection = iota SECTION_PEER SECTION_NONE )
func (ConfigSection) IsElementValid ¶
func (s ConfigSection) IsElementValid(key string) bool
func (ConfigSection) String ¶
func (s ConfigSection) String() string
type ConfigurationKeys ¶
type ConfigurationKeys []string
Helper type to check if a key is valid for a given section