tun

package
v0.0.0-...-9ec6d29 Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2022 License: Apache-2.0, MIT Imports: 14 Imported by: 0

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 enpoint 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() (*bufferv2.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) Write

func (d *Device) Write(data *bufferv2.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

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