tun

package
v0.0.0-...-ff2c174 Latest Latest
Warning

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

Go to latest
Published: May 9, 2021 License: Apache-2.0, MIT Imports: 15 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) 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() ([]byte, 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(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 []byte) (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