device

package
v1.4.3 Latest Latest
Warning

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

Go to latest
Published: Feb 25, 2026 License: AGPL-3.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateTUNFromFD

func CreateTUNFromFD(tunFd uint32, mtuInt int) (tun.Device, error)

func UapiListen

func UapiListen(interfaceName string, fileUAPI *os.File) (net.Listener, error)

func UapiOpen

func UapiOpen(interfaceName string) (*os.File, error)

Types

type FilterRule

type FilterRule struct {
	DestIP  netip.Addr
	Handler PacketHandler
}

FilterRule defines a rule for packet filtering

type MiddleDevice

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

MiddleDevice wraps a TUN device with packet filtering capabilities and supports swapping the underlying device.

func NewMiddleDevice

func NewMiddleDevice(device tun.Device) *MiddleDevice

NewMiddleDevice creates a new filtered TUN device wrapper

func (*MiddleDevice) AddDevice added in v1.4.0

func (d *MiddleDevice) AddDevice(device tun.Device)

AddDevice adds a new underlying TUN device, closing any previous one

func (*MiddleDevice) AddRule

func (d *MiddleDevice) AddRule(destIP netip.Addr, handler PacketHandler)

AddRule adds a packet filtering rule

func (*MiddleDevice) BatchSize added in v1.4.0

func (d *MiddleDevice) BatchSize() int

BatchSize returns the batch size

func (*MiddleDevice) Close

func (d *MiddleDevice) Close() error

Close stops the device

func (*MiddleDevice) Events added in v1.4.0

func (d *MiddleDevice) Events() <-chan tun.Event

Events returns the events channel

func (*MiddleDevice) File added in v1.4.0

func (d *MiddleDevice) File() *os.File

File returns the underlying file descriptor

func (*MiddleDevice) InjectOutbound

func (d *MiddleDevice) InjectOutbound(packet []byte)

InjectOutbound injects a packet to be read by WireGuard (as if it came from TUN)

func (*MiddleDevice) MTU added in v1.4.0

func (d *MiddleDevice) MTU() (int, error)

MTU returns the MTU of the underlying device

func (*MiddleDevice) Name added in v1.4.0

func (d *MiddleDevice) Name() (string, error)

Name returns the name of the underlying device

func (*MiddleDevice) Read

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

Read intercepts packets going UP from the TUN device (towards WireGuard)

func (*MiddleDevice) RemoveRule

func (d *MiddleDevice) RemoveRule(destIP netip.Addr)

RemoveRule removes all rules for a given destination IP

func (*MiddleDevice) Write

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

Write intercepts packets going DOWN to the TUN device (from WireGuard)

func (*MiddleDevice) WriteToTun added in v1.4.0

func (d *MiddleDevice) WriteToTun(bufs [][]byte, offset int) (int, error)

WriteToTun writes packets directly to the underlying TUN device, bypassing WireGuard. This is useful for sending packets that should appear to come from the TUN interface (e.g., DNS responses from a proxy). Unlike Write(), this does not go through packet filtering rules.

type PacketHandler

type PacketHandler func(packet []byte) bool

PacketHandler processes intercepted packets and returns true if packet should be dropped

Jump to

Keyboard shortcuts

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