tun

package
v0.0.0-...-ce67fbc Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2024 License: Apache-2.0, MIT Imports: 20 Imported by: 31

Documentation

Overview

Package tun contains methods to open TAP and TUN devices.

Index

Constants

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

Variables

This section is empty.

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(s *stack.Stack, name string, flags Flags) error

SetIff services TUNSETIFF ioctl(2) request.

func (*Device) StateFields

func (d *Device) StateFields() []string

func (*Device) StateLoad

func (d *Device) StateLoad(ctx context.Context, stateSourceObject state.Source)

+checklocksignore

func (*Device) StateSave

func (d *Device) StateSave(stateSinkObject state.Sink)

+checklocksignore

func (*Device) StateTypeName

func (d *Device) StateTypeName() string

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
}

Flags set properties of a Device

+stateify savable

func (*Flags) StateFields

func (f *Flags) StateFields() []string

func (*Flags) StateLoad

func (f *Flags) StateLoad(ctx context.Context, stateSourceObject state.Source)

+checklocksignore

func (*Flags) StateSave

func (f *Flags) StateSave(stateSinkObject state.Sink)

+checklocksignore

func (*Flags) StateTypeName

func (f *Flags) StateTypeName() string

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.

Jump to

Keyboard shortcuts

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