tap

package module
v0.0.0-...-cdfe3f2 Latest Latest
Warning

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

Go to latest
Published: May 26, 2023 License: MIT Imports: 9 Imported by: 0

README

hz.tools/tap

⚠ Please read Expectations within this Organization before using it.

Go Reference Go Report Card

Linux

$ sudo setcap cap_net_admin=+ep $(which binary)
Linux specific API

OpenBSD

While this code may compile and run on other BSD flavors, only OpenBSD is supported. OpenBSD-specific toggles may be added at any point without effort to keep other BSDs working.

OpenBSD specific API
// SetDescription will set the network interface description to the provided
// string.
func (i Interface) SetDescription(descr string) error

// AddGroup will add the provided group name to the underlying TAP
// interface.
func (i Interface) AddGroup(name string) error

// RemoveGroup will remove the group name from the TAP interface.
func (i Interface) RemoveGroup(name string) error

Documentation

Overview

Package tap contains bindings to create TAP/TUN interfaces on Linux and OpenBSD.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Interface

type Interface struct {
	// contains filtered or unexported fields
}

Interface is a handle to a created TAP/TUN interface.

func New

func New(ctx context.Context, o Options) (*Interface, error)

New will create a new TAP interface.

func (Interface) AddAddr

func (i Interface) AddAddr(ip net.IP, network *net.IPNet) error

AddAddr will add the provided IP Address and Network (CIDR/Netmask) to the TAP device. Both IPv4 and IPv6 are supported.

Under the hood this uses The Linux netlink interface to add the IP Address to the interface.

func (Interface) AddNeighbor

func (i Interface) AddNeighbor(mac net.HardwareAddr, ip net.IP) error

AddNeighbor will add an entry into the ARP / NDP table

func (Interface) Close

func (i Interface) Close() error

Close will release all resources held by this Interface.

func (Interface) Name

func (i Interface) Name() string

Name will return the UNIX interface name for the TAP/TUN interface.

func (Interface) Read

func (i Interface) Read() (*ethernet.Frame, error)

Read will read and parse the next Ethernet Frame from the TAP.

func (Interface) SetHardwareAddr

func (i Interface) SetHardwareAddr(addr net.HardwareAddr) error

SetHardwareAddr will set the link state to up or down.

func (Interface) SetMTU

func (i Interface) SetMTU(sz uint) error

SetMTU will set the MTU for the created TAP interface.

func (Interface) SetUp

func (i Interface) SetUp(updown bool) error

SetUp will set the link state to up or down.

func (Interface) Write

func (i Interface) Write(frame *ethernet.Frame) error

Write will encode the passed ethernet.Frame to the TAP.

type Options

type Options struct {
	PlatformOptions PlatformOptions
}

Options contains a number of configuration params for the creation of the TAP/TUN interface. The PlatformOptions struct is OS dependent, and may contain options on your OS that are not present on other OSs.

type PlatformOptions

type PlatformOptions struct {
	// Name will set the name of the TAP interface to override the default
	// of a tap* name (like tap0, tap5, tap3)
	Name string
}

PlatformOptions are the Linux specific TAP Interface options that we're able to use during the TAP inteface creation. This is different per-host, and needs to be used carefully.

Jump to

Keyboard shortcuts

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