water: github.com/songgao/water Index | Files | Directories

package water

import "github.com/songgao/water"

Package water 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

Package Files

doc.go if.go if_linux.go params_linux.go syscalls_linux.go syscalls_linux_go1.11.go

Constants

const (
    TUN
    TAP
)

TUN and TAP device types.

type Config Uses

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 Uses

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 Uses

type DeviceType int

DeviceType is the type for specifying device types.

type Interface Uses

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 Uses

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

New creates a new TUN/TAP interface using config.

func NewTAP Uses

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 Uses

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 Uses

func (ifce *Interface) IsTAP() bool

IsTAP returns true if ifce is a TAP interface.

func (*Interface) IsTUN Uses

func (ifce *Interface) IsTUN() bool

IsTUN returns true if ifce is a TUN interface.

func (*Interface) Name Uses

func (ifce *Interface) Name() string

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

type PlatformSpecificParams Uses

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.

Directories

PathSynopsis
waterutilPackage waterutil provides utility functions for interpreting TUN/TAP MAC farme headers and IP packet headers.

Package water imports 7 packages (graph) and is imported by 30 packages. Updated 2019-04-02. Refresh now. Tools for package owners.