interfaces

package
v0.0.0-...-e5bad9c Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2020 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultWireGuardInterfaceName = "wg+"

DefaultWireGuardInterfaceName provides a reasonable default interface name for this platform.

Variables

This section is empty.

Functions

func GetLocalSourceIP

func GetLocalSourceIP(dest string) (string, error)

GetLocalSourceIP returns a source IP.

func GetValidWireGuardDrivers

func GetValidWireGuardDrivers() []string

GetValidWireGuardDrivers returns a list of available WireGuardDrivers for the current platform.

func IsWireGuardInterfaceNameValid

func IsWireGuardInterfaceNameValid(name string) error

IsWireGuardInterfaceNameValid returns an error if the name is invalid.

Types

type Interface

type Interface interface {
	// Close deletes the interface and stops any drivers from servicing it.
	Close() error

	// EnsureIP adds an IP address to the specified interface if it does not already exist.
	EnsureIP(ip *net.IPNet) error

	// EnsureUp sets an interface into the UP state if it is not already UP. This begins
	// communication over the WireGuard protocol w/ any listed peers.
	EnsureUp() error

	// GetName returns the name used to identify the interface.
	GetName() string

	// GetIPs returns a list of IP addresses assigned to the specified interface.
	GetIPs() ([]string, error)
}

Interface describes actions which can be performed against a network interface.

type WireGuardDriver

type WireGuardDriver string

WireGuardDriver describes how the WireGuard interface should be created and managed.

const (
	// AutoSelect will try to find a working driver, first trying to use
	// the existing interface, then creating a new interface via the kernel driver,
	// then boringtun, then wireguard-go.
	AutoSelect WireGuardDriver = "auto"
	// ExistingInterface will succeed only if an interface is explicitly specified,
	// exists, and we have sufficient permissions.
	ExistingInterface WireGuardDriver = "existing"
	// KernelDriver attempts to create an interface using the WireGuard kernel module.
	// At the time of this writing, kernel support is only available in Linux, and
	// has not yet been merged into the mainstream kernel. Even after merge it will likely
	// remain an optional module, not loaded by default on most hosts. Security and logistical
	// concerns may prevent loading the module.
	KernelDriver WireGuardDriver = "kernel"
	// BoringTunDriver attempts to create a WireGuard interface using the BoringTun
	// userspace driver. The process will be run as a child of this process.
	BoringTunDriver WireGuardDriver = "boringtun"
	// WireGuardGoDriver attempts to create a WireGuard interface using the wireguard-go
	// userspace driver. The process will be run as a child of this process.
	WireGuardGoDriver WireGuardDriver = "wireguard-go"
)

func WireGuardDriverFromString

func WireGuardDriverFromString(driver string) (WireGuardDriver, error)

WireGuardDriverFromString returns a valid WireGuardDriver, or a descriptive error if the specified driver is invalid.

type WireGuardInterface

type WireGuardInterface interface {
	// Inherit everything from the non-WireGuard specific Interface interface.
	Interface

	// ConfigureWireGuard configures WireGuard on the specified interface. See:
	// https://godoc.org/golang.zx2c4.com/wireguard/wgctrl#Client.ConfigureDevice
	ConfigureWireGuard(cfg wgtypes.Config) error

	// GetListenPort returns the UDP port where the WireGuard driver is listening. The
	// interface must be in the UP state.
	GetListenPort() (int, error)
}

WireGuardInterface defines the common set of actions which can be taken against a network interface.

func EnsureWireGuardInterface

func EnsureWireGuardInterface(
	ctx context.Context,
	options *WireGuardInterfaceOptions,
) (_ WireGuardInterface, rErr error)

EnsureWireGuardInterface creates or reuses a WireGuard interface based upon the options.

type WireGuardInterfaceOptions

type WireGuardInterfaceOptions struct {
	InterfaceName        string
	Driver               WireGuardDriver
	Port                 int
	ReuseExisting        bool
	WireGuardGoPath      string
	WireGuardGoExtraArgs string
	BoringTunPath        string
	BoringTunExtraArgs   string
}

WireGuardInterfaceOptions ...

Jump to

Keyboard shortcuts

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