device

package
v0.30.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var CustomWindowsGUIDString string

CustomWindowsGUIDString is a custom GUID string for the interface

Functions

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 TunDevice

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

func NewTunDevice

func NewTunDevice(name string, address WGAddress, port int, key string, mtu int, transportNet transport.Net, filterFn bind.FilterFn) *TunDevice

func (*TunDevice) Close

func (t *TunDevice) Close() error

func (*TunDevice) Create

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

func (*TunDevice) DeviceName

func (t *TunDevice) DeviceName() string

func (*TunDevice) FilteredDevice

func (t *TunDevice) FilteredDevice() *FilteredDevice

func (*TunDevice) Up

func (*TunDevice) UpdateAddr

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

func (*TunDevice) WgAddress

func (t *TunDevice) 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, transportNet transport.Net, listenAddress string, filterFn bind.FilterFn) *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 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