device

package
v0.30.3 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2024 License: BSD-3-Clause Imports: 26 Imported by: 0

Documentation

Overview

Package iface provides wireguard network interface creation and management

Index

Constants

This section is empty.

Variables

View Source
var CustomWindowsGUIDString string

CustomWindowsGUIDString is a custom GUID string for the interface

View Source
var (
	// ErrModuleNotFound is the error resulting if a module can't be found.
	ErrModuleNotFound = errors.New("module not found")
)

Functions

func ModuleTunIsLoaded

func ModuleTunIsLoaded() bool

ModuleTunIsLoaded check if tun module exist, if is not attempt to load it

func WireGuardModuleIsLoaded

func WireGuardModuleIsLoaded() bool

WireGuardModuleIsLoaded check if we can load WireGuard mod (linux only)

Types

type FilteredDevice

type FilteredDevice struct {
	tun.Device
	// contains filtered or unexported fields
}

FilteredDevice to override Read or Write of packets

func (*FilteredDevice) Read

func (d *FilteredDevice) Read(bufs [][]byte, sizes []int, offset int) (n int, err error)

Read wraps read method with filtering feature

func (*FilteredDevice) SetFilter

func (d *FilteredDevice) SetFilter(filter PacketFilter)

SetFilter sets packet filter to device

func (*FilteredDevice) Write

func (d *FilteredDevice) Write(bufs [][]byte, offset int) (int, error)

Write wraps write method with filtering feature

type MobileIFaceArguments

type MobileIFaceArguments struct {
	TunAdapter TunAdapter // only for Android
	TunFd      int        // only for iOS
}

type PacketFilter

type PacketFilter interface {
	// DropOutgoing filter outgoing packets from host to external destinations
	DropOutgoing(packetData []byte) bool

	// DropIncoming filter incoming packets from external sources to host
	DropIncoming(packetData []byte) bool

	// AddUDPPacketHook calls hook when UDP packet from given direction matched
	//
	// Hook function returns flag which indicates should be the matched package dropped or not.
	// Hook function receives raw network packet data as argument.
	AddUDPPacketHook(in bool, ip net.IP, dPort uint16, hook func(packet []byte) bool) string

	// RemovePacketHook removes hook by ID
	RemovePacketHook(hookID string) error

	// SetNetwork of the wireguard interface to which filtering applied
	SetNetwork(*net.IPNet)
}

PacketFilter interface for firewall abilities

type TunAdapter

type TunAdapter interface {
	ConfigureInterface(address string, mtu int, dns string, searchDomains string, routes string) (int, error)
	UpdateAddr(address string) error
	ProtectSocket(fd int32) bool
}

TunAdapter is an interface for create tun device from external service

type TunKernelDevice

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

func NewKernelDevice

func NewKernelDevice(name string, address WGAddress, wgPort int, key string, mtu int, transportNet transport.Net) *TunKernelDevice

func (*TunKernelDevice) Close

func (t *TunKernelDevice) Close() error

func (*TunKernelDevice) Create

func (t *TunKernelDevice) Create() (WGConfigurer, error)

func (*TunKernelDevice) DeviceName

func (t *TunKernelDevice) DeviceName() string

func (*TunKernelDevice) FilteredDevice

func (t *TunKernelDevice) FilteredDevice() *FilteredDevice

func (*TunKernelDevice) Up

func (*TunKernelDevice) UpdateAddr

func (t *TunKernelDevice) UpdateAddr(address WGAddress) error

func (*TunKernelDevice) WgAddress

func (t *TunKernelDevice) WgAddress() WGAddress

type TunNetstackDevice

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

func NewNetstackDevice

func NewNetstackDevice(name string, address WGAddress, wgPort int, key string, mtu int, iceBind *bind.ICEBind, listenAddress string) *TunNetstackDevice

func (*TunNetstackDevice) Close

func (t *TunNetstackDevice) Close() error

func (*TunNetstackDevice) Create

func (t *TunNetstackDevice) Create() (WGConfigurer, error)

func (*TunNetstackDevice) DeviceName

func (t *TunNetstackDevice) DeviceName() string

func (*TunNetstackDevice) FilteredDevice

func (t *TunNetstackDevice) FilteredDevice() *FilteredDevice

func (*TunNetstackDevice) Up

func (*TunNetstackDevice) UpdateAddr

func (t *TunNetstackDevice) UpdateAddr(WGAddress) error

func (*TunNetstackDevice) WgAddress

func (t *TunNetstackDevice) WgAddress() WGAddress

type USPDevice

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

func NewUSPDevice

func NewUSPDevice(name string, address WGAddress, port int, key string, mtu int, iceBind *bind.ICEBind) *USPDevice

func (*USPDevice) Close

func (t *USPDevice) Close() error

func (*USPDevice) Create

func (t *USPDevice) Create() (WGConfigurer, error)

func (*USPDevice) DeviceName

func (t *USPDevice) DeviceName() string

func (*USPDevice) FilteredDevice

func (t *USPDevice) FilteredDevice() *FilteredDevice

func (*USPDevice) Up

func (*USPDevice) UpdateAddr

func (t *USPDevice) UpdateAddr(address WGAddress) error

func (*USPDevice) WgAddress

func (t *USPDevice) WgAddress() WGAddress

type WGAddress

type WGAddress struct {
	IP      net.IP
	Network *net.IPNet
}

WGAddress WireGuard parsed address

func ParseWGAddress

func ParseWGAddress(address string) (WGAddress, error)

ParseWGAddress parse a string ("1.2.3.4/24") address to WG Address

func (WGAddress) String

func (addr WGAddress) String() string

type WGConfigurer

type WGConfigurer interface {
	ConfigureInterface(privateKey string, port int) error
	UpdatePeer(peerKey string, allowedIps string, keepAlive time.Duration, endpoint *net.UDPAddr, preSharedKey *wgtypes.Key) error
	RemovePeer(peerKey string) error
	AddAllowedIP(peerKey string, allowedIP string) error
	RemoveAllowedIP(peerKey string, allowedIP string) error
	Close()
	GetStats(peerKey string) (configurer.WGStats, error)
}

Jump to

Keyboard shortcuts

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