tun

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2024 License: BSD-3-Clause Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultTunName = "mycoria"

DefaultTunName is the default interface name for the tunnel interface.

Variables

This section is empty.

Functions

This section is empty.

Types

type Device

type Device struct {
	RecvRaw   chan []byte
	SendRaw   chan []byte
	SendFrame chan frame.Frame
	// contains filtered or unexported fields
}

Device represents a tun device.

func Create

func Create(instance instance) (*Device, error)

Create creates a tun device and returns it.

func (*Device) AddAddress

func (d *Device) AddAddress(prefix netip.Prefix) error

AddAddress adds an address to the interface.

func (*Device) AddRoute added in v0.1.0

func (d *Device) AddRoute(prefix netip.Prefix, highPrio bool) error

AddRoute adds a route to the interface.

func (*Device) AddSendRawOffset added in v0.1.0

func (d *Device) AddSendRawOffset(data []byte) (withOffset []byte, copied bool)

AddSendRawOffset returns the given data with the required offset of packets submitted via SendRaw.

func (*Device) BatchSize

func (d *Device) BatchSize() int

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.

func (*Device) CheckWorkarounds added in v0.4.0

func (d *Device) CheckWorkarounds()

CheckWorkarounds may be called to make sure any workarounds are correctly applied after the network or related resources have changed.

func (*Device) Close

func (d *Device) Close() error

Close stops the Device and closes the Event channel.

func (*Device) InitInterface

func (d *Device) InitInterface(prefix netip.Prefix) error

InitInterface initializes the interface.

func (*Device) PrepTUN added in v0.1.0

func (d *Device) PrepTUN()

PrepTUN prepares the creation of the TUN device.

func (*Device) Read

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

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.

func (*Device) RemoveAddress

func (d *Device) RemoveAddress(prefix netip.Prefix) error

RemoveAddress removes an address from the interface.

func (*Device) RemoveRoute added in v0.1.0

func (d *Device) RemoveRoute(prefix netip.Prefix) error

RemoveRoute removes a route to the interface.

func (*Device) SendRawOffset added in v0.1.0

func (d *Device) SendRawOffset() int

SendRawOffset returns the required offset of packets submitted via SendRaw.

func (*Device) Start

func (d *Device) Start(mgr *mgr.Manager) error

Start starts brings the device online and starts workers.

func (*Device) StartInterface

func (d *Device) StartInterface() error

StartInterface starts the interface and brings it online.

func (*Device) Stop

func (d *Device) Stop(mgr *mgr.Manager) error

Stop closes the interface and stops workers.

func (*Device) TunEvents

func (d *Device) TunEvents() <-chan tun.Event

TunEvents returns a channel of type Event, which is fed Device events.

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.

Jump to

Keyboard shortcuts

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