tun

package
v0.3.15 Latest Latest
Warning

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

Go to latest
Published: Jun 9, 2025 License: MPL-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package tun wraps the wg tunnel implementation and adds packet filters.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Device

type Device struct {
	tun.Device
	InputPacketFilters []InputPacketFilter
}

Device wraps wg tunnel device.

func CreateTUN

func CreateTUN(iface string, mtu int, packetFilters ...InputPacketFilter) (*Device, error)

CreateTUN creates a Device with the provided name and MTU.

func (*Device) Write

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

Write one or more packets to the device (without any additional headers). On a successful write it returns the number of packets written. A nonzero offset can be used to instruct the Device on where to begin writing from each packet contained within the bufs slice.

type InputPacketFilter

type InputPacketFilter func(PacketHeader) bool

InputPacketFilter is the function for filtering the packets going through the wireguard tunnel.

func FilterAllExceptIP

func FilterAllExceptIP(ip netip.Addr) InputPacketFilter

FilterAllExceptIP drops all packets that have the destination different from the ip specified.

type PacketHeader

type PacketHeader struct {
	SourceAddr      netip.Addr
	DestinationAddr netip.Addr
	FlowLabel       uint32
	PayloadLength   uint16
	Version         uint8
	TrafficClass    uint8
	NextHeader      uint8
	HopLimit        uint8
}

PacketHeader is the decoded representation of the wireguard packet.

Jump to

Keyboard shortcuts

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