Documentation
¶
Index ¶
- Constants
- Variables
- func AddIPv4IncludedRoute(route IPv4Route)
- func AddRouteForNetworkConfig(destination string) error
- func AddRouteForServerIP(serverIP, interfaceName string) error
- func AddRoutes(remoteSubnets []string, interfaceName string) error
- func ClearNetworkSettings()
- func ConfigureInterface(interfaceName string, tunnelIp string, mtu int) error
- func DarwinAddRoute(destination string, gateway string, interfaceName string) error
- func DarwinRemoveRoute(destination string) error
- func FindUnusedUTUN() (string, error)
- func GetIncrementor() int
- func GetJSON() (string, error)
- func GetLocalEndpoints(port uint16, excludeInterface string) []string
- func LinuxAddRoute(destination string, gateway string, interfaceName string) error
- func LinuxRemoveRoute(destination string, interfaceName string) error
- func RemoveIPv4IncludedRoute(route IPv4Route)
- func RemoveRouteForNetworkConfig(destination string) error
- func RemoveRouteForServerIP(serverIP string, interfaceName string) error
- func RemoveRoutes(remoteSubnets []string, interfaceName string) error
- func SetDNSServers(servers []string)
- func SetIPv4ExcludedRoutes(routes []IPv4Route)
- func SetIPv4IncludedRoutes(routes []IPv4Route)
- func SetIPv4Settings(addresses []string, subnetMasks []string)
- func SetIPv6ExcludedRoutes(routes []IPv6Route)
- func SetIPv6IncludedRoutes(routes []IPv6Route)
- func SetIPv6Settings(addresses []string, networkPrefixes []string)
- func SetMTU(mtu int)
- func SetTunnelRemoteAddress(address string)
- func WindowsAddRoute(destination string, gateway string, interfaceName string) error
- func WindowsRemoveRoute(destination string, interfaceName string) error
- type IPv4Route
- type IPv6Route
- type NetworkSettings
Constants ¶
const VPNRouteMetric = 9999
VPNRouteMetric is the route metric/priority assigned to routes we add for the tunnel, so that an overlapping local/connected route is always preferred over the VPN route to the same destination rather than the two silently racing based on insertion order. It needs to be higher than any metric a local route is realistically going to have: on Linux, automatic metrics assigned by NetworkManager (which also apply to the connected subnet route, not just the default route) go up to 600 for Wi-Fi; on Windows, automatic interface metrics plus route metric rarely exceed a few hundred. 9999 comfortably clears both without needing to query the local routing table at add-time.
Variables ¶
var PreferLocalRoutes = false
PreferLocalRoutes controls whether routes added by AddRoutes are given the explicit high VPNRouteMetric priority, so that an overlapping local/ connected route always takes precedence over the VPN route to the same destination. Defaults to false (routes are added with the OS default metric/priority, matching behavior prior to the introduction of VPNRouteMetric); callers that want local routes to win opt in by setting this to true (e.g. from a config value) before routes are added.
Functions ¶
func AddIPv4IncludedRoute ¶ added in v1.8.0
func AddIPv4IncludedRoute(route IPv4Route)
func AddRouteForNetworkConfig ¶ added in v1.8.0
func AddRouteForServerIP ¶ added in v1.8.0
addRouteForServerIP adds an OS-specific route for the server IP
func ClearNetworkSettings ¶ added in v1.8.0
func ClearNetworkSettings()
ClearNetworkSettings clears all network settings
func ConfigureInterface ¶ added in v1.8.0
ConfigureInterface configures a network interface with an IP address and brings it up
func DarwinAddRoute ¶ added in v1.8.0
DarwinAddRoute adds a route via the BSD routing table. Unlike Linux/Windows, BSD's routing table has no per-route metric - preference between an overlapping local route and this VPN route is instead resolved by longest-prefix-match, and `route add` (as opposed to `route change`) fails rather than replacing an existing route to the same destination, so a local route is never displaced by one we add here.
func DarwinRemoveRoute ¶ added in v1.8.0
func FindUnusedUTUN ¶ added in v1.8.0
func GetIncrementor ¶ added in v1.8.0
func GetIncrementor() int
func GetLocalEndpoints ¶ added in v1.15.0
GetLocalEndpoints returns "ip:port" strings (bracketed for IPv6, e.g. "[fe80::1]:51820") for every usable, non-loopback IP address bound to a network interface on this host. The list is ordered with interfaces most likely to be a genuine host network (wired/Wi-Fi) first, and interfaces that are typically synthetic (Docker, VPN tunnels, hypervisor bridges, etc.) last, so callers should try the results roughly in order.
excludeInterface, if non-empty, is skipped entirely - this is normally the name of our own WireGuard/TUN interface, whose address is the tunnel IP and not a useful endpoint to advertise.
If interfaces cannot be enumerated (e.g. insufficient OS permissions), an info message is logged and an empty slice is returned.
func LinuxAddRoute ¶ added in v1.8.0
func LinuxRemoveRoute ¶ added in v1.8.0
func RemoveIPv4IncludedRoute ¶ added in v1.8.0
func RemoveIPv4IncludedRoute(route IPv4Route)
func RemoveRouteForNetworkConfig ¶ added in v1.8.0
func RemoveRouteForServerIP ¶ added in v1.8.0
removeRouteForServerIP removes an OS-specific route for the server IP
func RemoveRoutes ¶ added in v1.8.0
removeRoutesForRemoteSubnets removes routes for each subnet in RemoteSubnets. interfaceName must match the interface the routes were added on (see AddRoutes) so that only the routes we own are deleted, never an unrelated local/native route to the same destination on another interface.
func SetDNSServers ¶ added in v1.8.0
func SetDNSServers(servers []string)
SetDNSServers sets the DNS servers
func SetIPv4ExcludedRoutes ¶ added in v1.8.0
func SetIPv4ExcludedRoutes(routes []IPv4Route)
func SetIPv4IncludedRoutes ¶ added in v1.8.0
func SetIPv4IncludedRoutes(routes []IPv4Route)
SetIPv4IncludedRoutes sets the included IPv4 routes
func SetIPv4Settings ¶ added in v1.8.0
SetIPv4Settings sets IPv4 addresses and subnet masks
func SetIPv6ExcludedRoutes ¶ added in v1.8.0
func SetIPv6ExcludedRoutes(routes []IPv6Route)
SetIPv6ExcludedRoutes sets the excluded IPv6 routes
func SetIPv6IncludedRoutes ¶ added in v1.8.0
func SetIPv6IncludedRoutes(routes []IPv6Route)
SetIPv6IncludedRoutes sets the included IPv6 routes
func SetIPv6Settings ¶ added in v1.8.0
SetIPv6Settings sets IPv6 addresses and network prefixes
func SetTunnelRemoteAddress ¶ added in v1.8.0
func SetTunnelRemoteAddress(address string)
SetTunnelRemoteAddress sets the tunnel remote address
func WindowsAddRoute ¶ added in v1.8.0
func WindowsRemoveRoute ¶ added in v1.8.0
Types ¶
type IPv4Route ¶ added in v1.8.0
type IPv4Route struct {
DestinationAddress string `json:"destination_address"`
SubnetMask string `json:"subnet_mask,omitempty"`
GatewayAddress string `json:"gateway_address,omitempty"`
IsDefault bool `json:"is_default,omitempty"`
}
IPv4Route represents an IPv4 route
type IPv6Route ¶ added in v1.8.0
type IPv6Route struct {
DestinationAddress string `json:"destination_address"`
NetworkPrefixLength int `json:"network_prefix_length,omitempty"`
GatewayAddress string `json:"gateway_address,omitempty"`
IsDefault bool `json:"is_default,omitempty"`
}
IPv6Route represents an IPv6 route
type NetworkSettings ¶ added in v1.8.0
type NetworkSettings struct {
TunnelRemoteAddress string `json:"tunnel_remote_address,omitempty"`
MTU *int `json:"mtu,omitempty"`
DNSServers []string `json:"dns_servers,omitempty"`
IPv4Addresses []string `json:"ipv4_addresses,omitempty"`
IPv4SubnetMasks []string `json:"ipv4_subnet_masks,omitempty"`
IPv4IncludedRoutes []IPv4Route `json:"ipv4_included_routes,omitempty"`
IPv4ExcludedRoutes []IPv4Route `json:"ipv4_excluded_routes,omitempty"`
IPv6Addresses []string `json:"ipv6_addresses,omitempty"`
IPv6NetworkPrefixes []string `json:"ipv6_network_prefixes,omitempty"`
IPv6IncludedRoutes []IPv6Route `json:"ipv6_included_routes,omitempty"`
IPv6ExcludedRoutes []IPv6Route `json:"ipv6_excluded_routes,omitempty"`
}
NetworkSettings represents the network configuration for the tunnel
func GetSettings ¶ added in v1.8.0
func GetSettings() NetworkSettings