tun

package
v0.0.0-...-12269c2 Latest Latest
Warning

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

Go to latest
Published: Dec 11, 2023 License: MIT Imports: 13 Imported by: 254

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 added in v0.0.20190805

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

	// Read one or more packets from the Device (without any additional headers).
	// On a successful read it returns the number of packets read, and sets
	// packet lengths within the sizes slice. len(sizes) must be >= len(bufs).
	// A nonzero offset can be used to instruct the Device on where to begin
	// reading into each element of the bufs slice.
	Read(bufs [][]byte, sizes []int, offset int) (n int, err 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.
	Write(bufs [][]byte, offset int) (int, error)

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

	// Name returns the current name of the Device.
	Name() (string, 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

	// BatchSize returns the preferred/max number of packets that can be read or
	// written in a single read/write call. BatchSize must not change over the
	// lifetime of a Device.
	BatchSize() int
}

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 added in v0.0.20190409

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

CreateUnmonitoredTUNFromFD creates a Device from the provided file descriptor.

type Event added in v0.0.20190805

type Event int

type NativeTun added in v0.0.20190409

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

func (*NativeTun) BatchSize

func (tun *NativeTun) BatchSize() int

func (*NativeTun) Close added in v0.0.20190409

func (tun *NativeTun) Close() error

func (*NativeTun) Events added in v0.0.20190409

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

func (*NativeTun) File added in v0.0.20190409

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

func (*NativeTun) MTU added in v0.0.20190409

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

func (*NativeTun) Name added in v0.0.20190409

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

func (*NativeTun) Read added in v0.0.20190409

func (tun *NativeTun) Read(bufs [][]byte, sizes []int, offset int) (int, error)

func (*NativeTun) Write added in v0.0.20190409

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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