Documentation
¶
Overview ¶
Package iface provides wireguard network interface creation and management
Index ¶
- Variables
- func ModuleTunIsLoaded() bool
- func WireGuardModuleIsLoaded() bool
- type Bind
- type EndpointManager
- type FilteredDevice
- func (d *FilteredDevice) Close() error
- func (d *FilteredDevice) Read(bufs [][]byte, sizes []int, offset int) (n int, err error)
- func (d *FilteredDevice) SetCapture(pc PacketCapture)
- func (d *FilteredDevice) SetFilter(filter PacketFilter)
- func (d *FilteredDevice) Write(bufs [][]byte, offset int) (int, error)
- type MobileIFaceArguments
- type PacketCapture
- type PacketFilter
- type TunAdapter
- type TunDevice
- func (t *TunDevice) Close() error
- func (t *TunDevice) Create() (WGConfigurer, error)
- func (t *TunDevice) Device() *device.Device
- func (t *TunDevice) DeviceName() string
- func (t *TunDevice) FilteredDevice() *FilteredDevice
- func (t *TunDevice) GetICEBind() EndpointManager
- func (t *TunDevice) GetNet() *netstack.Net
- func (t *TunDevice) MTU() uint16
- func (t *TunDevice) Up() (*udpmux.UniversalUDPMuxDefault, error)
- func (t *TunDevice) UpdateAddr(address wgaddr.Address) error
- func (t *TunDevice) WgAddress() wgaddr.Address
- type TunKernelDevice
- func (t *TunKernelDevice) Close() error
- func (t *TunKernelDevice) Create() (WGConfigurer, error)
- func (t *TunKernelDevice) Device() *device.Device
- func (t *TunKernelDevice) DeviceName() string
- func (t *TunKernelDevice) FilteredDevice() *FilteredDevice
- func (t *TunKernelDevice) GetICEBind() EndpointManager
- func (t *TunKernelDevice) GetNet() *netstack.Net
- func (t *TunKernelDevice) MTU() uint16
- func (t *TunKernelDevice) Up() (*udpmux.UniversalUDPMuxDefault, error)
- func (t *TunKernelDevice) UpdateAddr(address wgaddr.Address) error
- func (t *TunKernelDevice) WgAddress() wgaddr.Address
- type TunNetstackDevice
- func (t *TunNetstackDevice) Close() error
- func (t *TunNetstackDevice) Create() (WGConfigurer, error)
- func (t *TunNetstackDevice) Device() *device.Device
- func (t *TunNetstackDevice) DeviceName() string
- func (t *TunNetstackDevice) FilteredDevice() *FilteredDevice
- func (t *TunNetstackDevice) GetICEBind() EndpointManager
- func (t *TunNetstackDevice) GetNet() *netstack.Net
- func (t *TunNetstackDevice) MTU() uint16
- func (t *TunNetstackDevice) Up() (*udpmux.UniversalUDPMuxDefault, error)
- func (t *TunNetstackDevice) UpdateAddr(wgaddr.Address) error
- func (t *TunNetstackDevice) WgAddress() wgaddr.Address
- type WGConfigurer
Constants ¶
This section is empty.
Variables ¶
var CustomWindowsGUIDString string
CustomWindowsGUIDString is a custom GUID string for the interface
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 Bind ¶ added in v0.59.0
type Bind interface {
conn.Bind
GetICEMux() (*udpmux.UniversalUDPMuxDefault, error)
ActivityRecorder() *bind.ActivityRecorder
EndpointManager
}
type EndpointManager ¶ added in v0.59.7
type EndpointManager interface {
SetEndpoint(fakeIP netip.Addr, conn net.Conn)
RemoveEndpoint(fakeIP netip.Addr)
}
EndpointManager manages fake IP to connection mappings for userspace bind implementations. Implemented by bind.ICEBind and bind.RelayBindJS.
type FilteredDevice ¶
FilteredDevice to override Read or Write of packets
func (*FilteredDevice) Close ¶ added in v0.64.6
func (d *FilteredDevice) Close() error
Close closes the underlying tun device exactly once. wireguard-go's netTun.Close() panics on double-close due to a bare close(channel), and multiple code paths can trigger Close on the same device.
func (*FilteredDevice) SetCapture ¶ added in v0.70.5
func (d *FilteredDevice) SetCapture(pc PacketCapture)
SetCapture sets or clears the packet capture sink. Pass nil to disable. Uses atomic store so the hot path (Read/Write) is a single pointer load with no locking overhead when capture is off.
func (*FilteredDevice) SetFilter ¶
func (d *FilteredDevice) SetFilter(filter PacketFilter)
SetFilter sets packet filter to device
type MobileIFaceArguments ¶
type MobileIFaceArguments struct {
TunAdapter TunAdapter // only for Android
TunFd int // only for iOS
}
type PacketCapture ¶ added in v0.70.5
type PacketCapture interface {
// Offer submits a packet for capture. outbound is true for packets
// leaving the host (Read path), false for packets arriving (Write path).
Offer(data []byte, outbound bool)
}
PacketCapture captures raw packets for debugging. Implementations must be safe for concurrent use and must not block.
type PacketFilter ¶
type PacketFilter interface {
// FilterOutbound filter outgoing packets from host to external destinations
FilterOutbound(packetData []byte, size int) bool
// FilterInbound filter incoming packets from external sources to host
FilterInbound(packetData []byte, size int) bool
// SetUDPPacketHook registers a hook for outbound UDP packets matching the given IP and port.
// Hook function returns true if the packet should be dropped.
// Only one UDP hook is supported; calling again replaces the previous hook.
// Pass nil hook to remove.
SetUDPPacketHook(ip netip.Addr, dPort uint16, hook func(packet []byte) bool)
// SetTCPPacketHook registers a hook for outbound TCP packets matching the given IP and port.
// Hook function returns true if the packet should be dropped.
// Only one TCP hook is supported; calling again replaces the previous hook.
// Pass nil hook to remove.
SetTCPPacketHook(ip netip.Addr, dPort uint16, hook func(packet []byte) bool)
}
PacketFilter interface for firewall abilities
type TunAdapter ¶
type TunAdapter interface {
ConfigureInterface(address string, addressV6 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 ¶ added in v0.71.0
type TunDevice struct {
// contains filtered or unexported fields
}
func NewTunDevice ¶ added in v0.71.0
func (*TunDevice) Create ¶ added in v0.71.0
func (t *TunDevice) Create() (WGConfigurer, error)
func (*TunDevice) DeviceName ¶ added in v0.71.0
func (*TunDevice) FilteredDevice ¶ added in v0.71.0
func (t *TunDevice) FilteredDevice() *FilteredDevice
func (*TunDevice) GetICEBind ¶ added in v0.71.0
func (t *TunDevice) GetICEBind() EndpointManager
GetICEBind returns the ICEBind instance
func (*TunDevice) Up ¶ added in v0.71.0
func (t *TunDevice) Up() (*udpmux.UniversalUDPMuxDefault, error)
func (*TunDevice) UpdateAddr ¶ added in v0.71.0
type TunKernelDevice ¶
type TunKernelDevice struct {
// contains filtered or unexported fields
}
func NewKernelDevice ¶
func (*TunKernelDevice) Close ¶
func (t *TunKernelDevice) Close() error
func (*TunKernelDevice) Create ¶
func (t *TunKernelDevice) Create() (WGConfigurer, error)
func (*TunKernelDevice) Device ¶ added in v0.36.6
func (t *TunKernelDevice) Device() *device.Device
Device returns the wireguard device, not applicable for kernel devices
func (*TunKernelDevice) DeviceName ¶
func (t *TunKernelDevice) DeviceName() string
func (*TunKernelDevice) FilteredDevice ¶
func (t *TunKernelDevice) FilteredDevice() *FilteredDevice
func (*TunKernelDevice) GetICEBind ¶ added in v0.59.7
func (t *TunKernelDevice) GetICEBind() EndpointManager
GetICEBind returns nil for kernel mode devices
func (*TunKernelDevice) GetNet ¶ added in v0.37.0
func (t *TunKernelDevice) GetNet() *netstack.Net
func (*TunKernelDevice) MTU ¶ added in v0.56.0
func (t *TunKernelDevice) MTU() uint16
func (*TunKernelDevice) Up ¶
func (t *TunKernelDevice) Up() (*udpmux.UniversalUDPMuxDefault, error)
func (*TunKernelDevice) UpdateAddr ¶
func (t *TunKernelDevice) UpdateAddr(address wgaddr.Address) error
func (*TunKernelDevice) WgAddress ¶
func (t *TunKernelDevice) WgAddress() wgaddr.Address
type TunNetstackDevice ¶
type TunNetstackDevice struct {
// contains filtered or unexported fields
}
func NewNetstackDevice ¶
func (*TunNetstackDevice) Close ¶
func (t *TunNetstackDevice) Close() error
func (*TunNetstackDevice) Create ¶
func (t *TunNetstackDevice) Create() (WGConfigurer, error)
func (*TunNetstackDevice) Device ¶ added in v0.36.6
func (t *TunNetstackDevice) Device() *device.Device
Device returns the wireguard device
func (*TunNetstackDevice) DeviceName ¶
func (t *TunNetstackDevice) DeviceName() string
func (*TunNetstackDevice) FilteredDevice ¶
func (t *TunNetstackDevice) FilteredDevice() *FilteredDevice
func (*TunNetstackDevice) GetICEBind ¶ added in v0.59.7
func (t *TunNetstackDevice) GetICEBind() EndpointManager
GetICEBind returns the bind instance
func (*TunNetstackDevice) GetNet ¶ added in v0.37.0
func (t *TunNetstackDevice) GetNet() *netstack.Net
func (*TunNetstackDevice) MTU ¶ added in v0.56.0
func (t *TunNetstackDevice) MTU() uint16
func (*TunNetstackDevice) Up ¶
func (t *TunNetstackDevice) Up() (*udpmux.UniversalUDPMuxDefault, error)
func (*TunNetstackDevice) UpdateAddr ¶
func (t *TunNetstackDevice) UpdateAddr(wgaddr.Address) error
func (*TunNetstackDevice) WgAddress ¶
func (t *TunNetstackDevice) WgAddress() wgaddr.Address
type WGConfigurer ¶
type WGConfigurer interface {
ConfigureInterface(privateKey string, port int) error
UpdatePeer(peerKey string, allowedIps []netip.Prefix, keepAlive time.Duration, endpoint *net.UDPAddr, preSharedKey *wgtypes.Key) error
RemovePeer(peerKey string) error
AddAllowedIP(peerKey string, allowedIP netip.Prefix) error
RemoveAllowedIP(peerKey string, allowedIP netip.Prefix) error
Close()
GetStats() (map[string]configurer.WGStats, error)
FullStats() (*configurer.Stats, error)
LastActivities() map[string]monotime.Time
RemoveEndpointAddress(peerKey string) error
}