Documentation
¶
Index ¶
- func CreateTUNFromFD(tunFd uint32, mtuInt int) (tun.Device, error)
- func UapiListen(interfaceName string, fileUAPI *os.File) (net.Listener, error)
- func UapiOpen(interfaceName string) (*os.File, error)
- type FilterRule
- type MiddleDevice
- func (d *MiddleDevice) AddDevice(device tun.Device)
- func (d *MiddleDevice) AddRule(destIP netip.Addr, handler PacketHandler)
- func (d *MiddleDevice) BatchSize() int
- func (d *MiddleDevice) Close() error
- func (d *MiddleDevice) Events() <-chan tun.Event
- func (d *MiddleDevice) File() *os.File
- func (d *MiddleDevice) InjectOutbound(packet []byte)
- func (d *MiddleDevice) MTU() (int, error)
- func (d *MiddleDevice) Name() (string, error)
- func (d *MiddleDevice) Read(bufs [][]byte, sizes []int, offset int) (n int, err error)
- func (d *MiddleDevice) RemoveRule(destIP netip.Addr)
- func (d *MiddleDevice) Write(bufs [][]byte, offset int) (int, error)
- func (d *MiddleDevice) WriteToTun(bufs [][]byte, offset int) (int, error)
- type PacketHandler
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
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) 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 ¶
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 ¶
PacketHandler processes intercepted packets and returns true if packet should be dropped