tun

package
v0.23.0 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2024 License: MPL-2.0 Imports: 21 Imported by: 3

README

TUN Interface For Linux

In general Noisy Sockets uses a userspace network stack, however on Linux with user namspaces it is possible to create an in-kernel TUN interface without elevated priviliges.

The userspace network stack, while optimized, is still slower than the kernel network stack. So on Linux hosts where performance (and not portability) is the primary concern, it is recommended to use the TUN interface.

Note: This is explicitly a Linux only feature, and we have no plans to support other OS's (as the complexity is not worth it, and we aren't trying to build a general purpose VPN, just use upstream WireGuard instead).

Documentation

Overview

Package tun provides a TUN device implementation for noisysockets.

Index

Constants

View Source
const (
	// VirtioNetHdrLen is the length in bytes of virtioNetHdr. This matches the
	// shape of the C ABI for its kernel counterpart -- sizeof(virtio_net_hdr).
	VirtioNetHdrLen = int(unsafe.Sizeof(virtioNetHdr{}))
)

Variables

This section is empty.

Functions

func Create added in v0.18.1

func Create(ctx context.Context, logger *slog.Logger, name string, conf *Configuration) (network.Interface, error)

Create creates a new TUN device with the specified configuration.

Types

type Configuration added in v0.18.1

type Configuration struct {
	// BatchSize is the number of packets to read in a single syscall.
	// This is only used when the TUN device supports IFF_VNET_HDR.
	BatchSize *int
	// MTU is the maximum transmission unit of the TUN device.
	// If not specified, the default is 1500.
	MTU *int
	// PacketPool is the pool from which packets are borrowed.
	// If not specified, an unbounded pool will be created.
	PacketPool *network.PacketPool
	// Fd is optionally the file descriptor of an existing TUN device.
	Fd *int
	// Unmanaged is a flag to indicate if the TUN device is unmanaged
	// eg. we are not responsible for setting the MTU or bringing the
	// link up.
	Unmanaged bool
}

Configuration is the configuration for a TUN device.

type Interface added in v0.19.0

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

Interface is a TUN network interface implementation for linux.

func (*Interface) BatchSize added in v0.19.0

func (nic *Interface) BatchSize() int

func (*Interface) Close added in v0.19.0

func (nic *Interface) Close() error

func (*Interface) MTU added in v0.19.0

func (nic *Interface) MTU() (int, error)

func (*Interface) Read added in v0.19.0

func (nic *Interface) Read(ctx context.Context, packets []*network.Packet, offset int) ([]*network.Packet, error)

func (*Interface) Write added in v0.19.0

func (nic *Interface) Write(ctx context.Context, packets []*network.Packet) error

Jump to

Keyboard shortcuts

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