tun

package
v0.2.5 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2025 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EventUp = 1 << iota
	EventDown
	EventMTUUpdate
)

Variables

View Source
var (
	// ErrTooManySegments is returned by Device.Read() when segmentation
	// overflows the length of supplied buffers. This error should not cause
	// reads to cease.
	ErrTooManySegments = errors.New("too many segments")
)

Functions

This section is empty.

Types

type Device

type Device interface {
	// File returns the file descriptor of the device.
	File() *os.File

	// Read one packet from the Device (without any additional headers).
	// On a successful read it returns the number of bytes read.
	Read(b []byte) (int, error)

	// Write one packet to the device (without any additional headers).
	// On a successful write it returns the number of bytes written.
	Write(b []byte) (int, error)

	// Set MTU on the device.
	SetMTU(int) error

	// MTU returns the MTU of the Device.
	MTU() (int, error)

	// Name returns the current name of the Device.
	Name() (string, error)

	// Set IP Addresses for the device.
	SetIPAddresses(addresses []netip.Prefix) error

	// Get IP Addresses for the device.
	GetIPAddresses() ([]netip.Prefix, error)

	// Add static route.
	AddRoute(destination netip.Prefix, gateway netip.Addr, metric int) error

	// Remove static route.
	RemoveRoute(destination netip.Prefix, gateway netip.Addr) error

	// Events returns a channel of type Event, which is fed Device events.
	Events() <-chan Event

	// Close stops the Device and closes the Event channel.
	Close() error
}

func CreateTUN

func CreateTUN(name string, mtu int) (Device, error)

CreateTUN creates a Device with the provided name and MTU.

func CreateTUNFromFile

func CreateTUNFromFile(file *os.File, mtu int) (Device, error)

CreateTUNFromFile creates a Device from an os.File with the provided MTU.

func CreateUnmonitoredTUNFromFD

func CreateUnmonitoredTUNFromFD(fd int) (Device, string, error)

CreateUnmonitoredTUNFromFD creates a Device from the provided file descriptor.

type Event

type Event int

type NativeTun

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

func (*NativeTun) AddRoute added in v0.2.1

func (tun *NativeTun) AddRoute(destination netip.Prefix, gateway netip.Addr, metric int) error

func (*NativeTun) Close

func (tun *NativeTun) Close() error

func (*NativeTun) Events

func (tun *NativeTun) Events() <-chan Event

func (*NativeTun) File

func (tun *NativeTun) File() *os.File

func (*NativeTun) GetIPAddresses

func (tun *NativeTun) GetIPAddresses() ([]netip.Prefix, error)

func (*NativeTun) MTU

func (tun *NativeTun) MTU() (int, error)

func (*NativeTun) Name

func (tun *NativeTun) Name() (string, error)

func (*NativeTun) Read

func (tun *NativeTun) Read(b []byte) (int, error)

func (*NativeTun) RemoveRoute added in v0.2.1

func (tun *NativeTun) RemoveRoute(destination netip.Prefix, gateway netip.Addr) error

func (*NativeTun) SetIPAddresses

func (tun *NativeTun) SetIPAddresses(addresses []netip.Prefix) error

func (*NativeTun) SetMTU

func (tun *NativeTun) SetMTU(mtu int) error

func (*NativeTun) Write

func (tun *NativeTun) Write(b []byte) (int, error)

Jump to

Keyboard shortcuts

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