tuntap

package
v0.0.0-...-28f4c0d Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2023 License: BSD-3-Clause Imports: 7 Imported by: 0

Documentation

Overview

package tuntap is a simple TUN/TAP interface library that efficiently works with standard packages like io, bufio, etc.. Use waterutil with it to work with TUN/TAP packets/frames.

Index

Constants

View Source
const (
	TUN
	TAP
)

TUN and TAP device types.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// DeviceType specifies whether the device is a TUN or TAP interface. A
	// zero-value is treated as TUN.
	DeviceType DeviceType

	// PlatformSpecificParams defines parameters that differ on different
	// platforms. See comments for the type for more details.
	PlatformSpecificParams
}

Config defines parameters required to create a TUN/TAP interface. It's only used when the device is initialized. A zero-value Config is a valid configuration.

type DevicePermissions

type DevicePermissions struct {
	// Owner is the ID of the user which will be granted ownership of the
	// device.  If set to a negative value, the owner value will not be
	// changed.  By default, Linux sets the owner to -1, which allows any user.
	Owner uint

	// Group is the ID of the group which will be granted access to the device.
	// If set to a negative value, the group value will not be changed.  By
	// default, Linux sets the group to -1, which allows any group.
	Group uint
}

DevicePermissions determines the owner and group owner for the newly created interface.

type DeviceType

type DeviceType int

DeviceType is the type for specifying device types.

type Interface

type Interface struct {
	io.ReadWriteCloser
	// contains filtered or unexported fields
}

Interface is a TUN/TAP interface.

MultiQueue(Linux kernel > 3.8): With MultiQueue enabled, user should hold multiple interfaces to send/receive packet in parallel. Kernel document about MultiQueue: https://www.kernel.org/doc/Documentation/networking/tuntap.txt

func New

func New(config Config) (ifce *Interface, err error)

New creates a new TUN/TAP interface using config.

func NewTAP deprecated

func NewTAP(ifName string) (ifce *Interface, err error)

NewTAP creates a new TAP interface whose name is ifName. If ifName is empty, a default name (tap0, tap1, ... ) will be assigned. ifName should not exceed 16 bytes. TAP interfaces are not supported on darwin. ifName cannot be specified on windows, you will need ifce.Name() to use some cmds.

Deprecated: This function may be removed in the future. Please use New() instead.

func NewTUN deprecated

func NewTUN(ifName string) (ifce *Interface, err error)

NewTUN creates a new TUN interface whose name is ifName. If ifName is empty, a default name (tap0, tap1, ... ) will be assigned. ifName should not exceed ifName cannot be specified on windows, you will need ifce.Name() to use some cmds.

Deprecated: This function will be removed in the future. Please use New() instead.

func (*Interface) IsTAP

func (ifce *Interface) IsTAP() bool

IsTAP returns true if ifce is a TAP interface.

func (*Interface) IsTUN

func (ifce *Interface) IsTUN() bool

IsTUN returns true if ifce is a TUN interface.

func (*Interface) Name

func (ifce *Interface) Name() string

Name returns the interface name of ifce, e.g. tun0, tap1, tun0, etc..

func (*Interface) SetIP

func (ifce *Interface) SetIP()

type PlatformSpecificParams

type PlatformSpecificParams struct {
	// Name is the name to be set for the interface to be created. This overrides
	// the default name assigned by OS such as tap0 or tun0. A zero-value of this
	// field, i.e. an empty string, indicates that the default name should be
	// used.
	Name string

	// Persist specifies whether persistence mode for the interface device
	// should be enabled or disabled.
	Persist bool

	// Permissions, if non-nil, specifies the owner and group owner for the
	// interface.  A zero-value of this field, i.e. nil, indicates that no
	// changes to owner or group will be made.
	Permissions *DevicePermissions

	// MultiQueue specifies whether the multiqueue flag should be set on the
	// interface.  From version 3.8, Linux supports multiqueue tuntap which can
	// uses multiple file descriptors (queues) to parallelize packets sending
	// or receiving.
	MultiQueue bool
}

PlatformSpecificParams defines parameters in Config that are specific to Linux. A zero-value of such type is valid, yielding an interface with OS defined name.

Jump to

Keyboard shortcuts

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