package tun

import "gvisor.dev/gvisor/pkg/tcpip/link/tun"

Package tun contains methods to open TAP and TUN devices.

Index

Constants

const (
	// PacketInfoHeaderSize is the size of the packet information header.
	PacketInfoHeaderSize = 4
)

Functions

func Open

func Open(name string) (int, error)

Open opens the specified TUN device, sets it to non-blocking mode, and returns its file descriptor.

func OpenTAP

func OpenTAP(name string) (int, error)

OpenTAP opens the specified TAP device, sets it to non-blocking mode, and returns its file descriptor.

Types

type Device

type Device struct {
	waiter.Queue
	// contains filtered or unexported fields
}

Device is an opened /dev/net/tun device.

+stateify savable

func (*Device) Flags

func (d *Device) Flags() Flags

Flags returns the flags set for d. Zero value if unset.

func (*Device) MTU

func (d *Device) MTU() (uint32, error)

MTU returns the tun endpoint MTU (maximum transmission unit).

func (*Device) Name

func (d *Device) Name() string

Name returns the name of the attached network interface. Empty string if unattached.

func (*Device) Read

func (d *Device) Read() (*buffer.View, error)

Read reads one outgoing packet from the network interface.

func (*Device) Readiness

func (d *Device) Readiness(mask waiter.EventMask) waiter.EventMask

Readiness implements watier.Waitable.Readiness.

func (*Device) Release

func (d *Device) Release(ctx context.Context)

Release implements fs.FileOperations.Release.

func (*Device) SetIff

func (d *Device) SetIff(ctx context.Context, s *stack.Stack, name string, flags Flags) error

SetIff services TUNSETIFF ioctl(2) request.

func (*Device) SetPersistent

func (d *Device) SetPersistent(v bool) error

func (*Device) Write

func (d *Device) Write(data *buffer.View) (int64, error)

Write inject one inbound packet to the network interface.

func (*Device) WriteNotify

func (d *Device) WriteNotify()

WriteNotify implements channel.Notification.WriteNotify.

type Flags

type Flags struct {
	TUN          bool
	TAP          bool
	NoPacketInfo bool
	Exclusive    bool
}

Flags set properties of a Device

+stateify savable

type PacketInfoFields

type PacketInfoFields struct {
	Flags    uint16
	Protocol tcpip.NetworkProtocolNumber
}

PacketInfoFields contains fields sent through the wire if IFF_NO_PI flag is not set.

type PacketInfoHeader

type PacketInfoHeader []byte

PacketInfoHeader is the wire representation of the packet information sent if IFF_NO_PI flag is not set.

func (PacketInfoHeader) Encode

func (h PacketInfoHeader) Encode(f *PacketInfoFields)

Encode encodes f into h.

func (PacketInfoHeader) Flags

func (h PacketInfoHeader) Flags() uint16

Flags returns the flag field in h.

func (PacketInfoHeader) Protocol

Protocol returns the protocol field in h.

Source Files

device.go protocol.go tun_unsafe.go

Version
v0.0.0-20250605235530-a6711d1e1dc6 (latest)
Published
Jun 5, 2025
Platform
linux/amd64
Imports
14 packages
Last checked
4 hours ago

Tools for package owners.