iface

package
v0.83.2 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2026 License: BSD-3-Clause Imports: 21 Imported by: 1 module, 0 packages

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

Index

Constants

View Source
const (
	DefaultMTU         = 1280
	MinMTU             = 576
	MaxMTU             = 8192
	DefaultWgPort      = 51820
	WgInterfaceDefault = configurer.WgInterfaceDefault
)

Variables

View Source
var (
	// ErrIfaceNotFound is returned when the WireGuard interface is not found
	ErrIfaceNotFound = fmt.Errorf("wireguard interface not found")
)

Functions

func ValidateMTU added in v0.56.0

func ValidateMTU(mtu uint16) error

ValidateMTU validates that MTU is within acceptable range

Types

type WGIFaceOpts added in v0.30.3

type WGIFaceOpts struct {
	IFaceName    string
	Address      wgaddr.Address
	WGPort       int
	WGPrivKey    string
	MTU          uint16
	MobileArgs   *device.MobileIFaceArguments
	TransportNet transport.Net
	DisableDNS   bool
}

type WGIface

type WGIface struct {
	// contains filtered or unexported fields
}

WGIface represents an interface instance

func NewWGIFace

func NewWGIFace(opts WGIFaceOpts) (*WGIface, error)

NewWGIFace Creates a new WireGuard interface instance

func (*WGIface) AddAllowedIP

func (w *WGIface) AddAllowedIP(peerKey string, allowedIP netip.Prefix) error

AddAllowedIP adds a prefix to the allowed IPs list of peer

func (*WGIface) Address

func (w *WGIface) Address() wgaddr.Address

Address returns the interface address

func (*WGIface) Close

func (w *WGIface) Close() error

Close closes the tunnel interface

func (*WGIface) Create

func (w *WGIface) Create() error

Create creates a new Wireguard interface, sets a given IP and brings it up. Will reuse an existing one. this function is different on Android

func (*WGIface) CreateOnAndroid

func (w *WGIface) CreateOnAndroid([]string, string, []string) error

CreateOnAndroid this function make sense on mobile only

func (*WGIface) Destroy

func (w *WGIface) Destroy() error

func (*WGIface) FullStats added in v0.46.0

func (w *WGIface) FullStats() (*configurer.Stats, error)

func (*WGIface) GetBind added in v0.59.7

func (w *WGIface) GetBind() device.EndpointManager

GetBind returns the EndpointManager userspace bind mode.

func (*WGIface) GetDevice

func (w *WGIface) GetDevice() *device.FilteredDevice

GetDevice to interact with raw device (with filtering)

func (*WGIface) GetFilter

func (w *WGIface) GetFilter() device.PacketFilter

GetFilter returns packet filter used by interface if it uses userspace device implementation

func (*WGIface) GetNet added in v0.37.0

func (w *WGIface) GetNet() *wgbackend.NetstackNet

GetNet returns the netstack.Net for the netstack device

func (*WGIface) GetProxy added in v0.30.3

func (w *WGIface) GetProxy() wgproxy.Proxy

func (*WGIface) GetStats

func (w *WGIface) GetStats() (map[string]configurer.WGStats, error)

GetStats returns the last handshake time, rx and tx bytes

func (*WGIface) GetWGDevice added in v0.36.6

func (w *WGIface) GetWGDevice() *wgbackend.Device

GetWGDevice returns the WireGuard device

func (*WGIface) IsUserspaceBind

func (w *WGIface) IsUserspaceBind() bool

IsUserspaceBind indicates whether this interfaces is userspace with bind.ICEBind

func (*WGIface) LastActivities added in v0.50.0

func (w *WGIface) LastActivities() map[string]monotime.Time

func (*WGIface) MTU added in v0.56.0

func (w *WGIface) MTU() uint16

func (*WGIface) Name

func (w *WGIface) Name() string

Name returns the interface name

func (*WGIface) RemoveAllowedIP

func (w *WGIface) RemoveAllowedIP(peerKey string, allowedIP netip.Prefix) error

RemoveAllowedIP removes a prefix from the allowed IPs list of peer

func (*WGIface) RemoveEndpointAddress added in v0.59.4

func (w *WGIface) RemoveEndpointAddress(peerKey string) error

func (*WGIface) RemovePeer

func (w *WGIface) RemovePeer(peerKey string) error

RemovePeer removes a Wireguard Peer from the interface iface

func (*WGIface) RenewTun added in v0.60.3

func (w *WGIface) RenewTun(fd int) error

func (*WGIface) SetFilter

func (w *WGIface) SetFilter(filter device.PacketFilter) error

SetFilter sets packet filters for the userspace implementation

func (*WGIface) SetPresharedKey added in v0.64.0

func (w *WGIface) SetPresharedKey(peerKey string, psk wgtypes.Key, updateOnly bool) error

SetPresharedKey sets or updates the preshared key for a peer. If updateOnly is true, only updates existing peer; if false, creates or updates.

func (*WGIface) ToInterface

func (r *WGIface) ToInterface() *net.Interface

ToInterface returns the net.Interface for the Wireguard interface

func (*WGIface) Up

Up configures a Wireguard interface The interface must exist before calling this method (e.g. call interface.Create() before)

func (*WGIface) UpdateAddr

func (w *WGIface) UpdateAddr(newAddr wgaddr.Address) error

UpdateAddr updates address of the interface

func (*WGIface) UpdatePeer

func (w *WGIface) UpdatePeer(peerKey string, allowedIps []netip.Prefix, keepAlive time.Duration, endpoint *net.UDPAddr, preSharedKey *wgtypes.Key) error

UpdatePeer updates existing Wireguard Peer or creates a new one if doesn't exist Endpoint is optional. If allowedIps is given it will be added to the existing ones.

type WGTunDevice

type WGTunDevice interface {
	Create() (device.WGConfigurer, error)
	Up() (*udpmux.UniversalUDPMuxDefault, error)
	UpdateAddr(address wgaddr.Address) error
	WgAddress() wgaddr.Address
	MTU() uint16
	DeviceName() string
	Close() error
	FilteredDevice() *device.FilteredDevice
	Device() *wgbackend.Device
	GetNet() *wgbackend.NetstackNet
	GetICEBind() device.EndpointManager
}

Directories

Path Synopsis
Package iface provides wireguard network interface creation and management
Package iface provides wireguard network interface creation and management
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.
Package udpmux provides a custom implementation of a UDP multiplexer that allows multiple logical ICE connections to share a single underlying UDP socket.
Package udpmux provides a custom implementation of a UDP multiplexer that allows multiple logical ICE connections to share a single underlying UDP socket.
Package wgbackend is the single place in the client's hand-written code that names the WireGuard implementation.
Package wgbackend is the single place in the client's hand-written code that names the WireGuard implementation.
udp

Jump to

Keyboard shortcuts

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