tuntap

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package tuntap provides OS-level TUN and TAP devices implementing pktkit's pktkit.L3Device and pktkit.L2Device interfaces.

TUN devices operate at L3 (raw IP packets) and TAP devices at L2 (Ethernet frames). Both support IP address and route configuration on the underlying OS interface.

On Linux, both TUN and TAP modes are supported via /dev/net/tun. On macOS, only TUN mode is supported via the utun kernel control.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// Name is the desired interface name (e.g. "tun0").
	// On macOS, this is ignored (utun names are auto-assigned).
	// If empty on Linux, the kernel assigns a name.
	Name string
}

Config configures a TUN or TAP device.

type L2Dev

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

L2Dev is a TAP device implementing pktkit.L2Device. It reads and writes Ethernet frames from/to the OS network stack. TAP mode is not supported on macOS.

func TAP

func TAP(cfg Config) (*L2Dev, error)

TAP opens a TAP device (L2, Ethernet frames).

func (*L2Dev) AddRoute

func (d *L2Dev) AddRoute(dst netip.Prefix, gw netip.Addr) error

AddRoute adds a route via this interface.

func (*L2Dev) Close

func (d *L2Dev) Close() error

func (*L2Dev) Done

func (d *L2Dev) Done() <-chan struct{}

Done returns a channel that is closed when the device is closed.

func (*L2Dev) HWAddr

func (d *L2Dev) HWAddr() net.HardwareAddr

func (*L2Dev) Name

func (d *L2Dev) Name() string

Name returns the OS interface name (e.g. "tap0").

func (*L2Dev) Send

func (d *L2Dev) Send(f pktkit.Frame) error

func (*L2Dev) SetHandler

func (d *L2Dev) SetHandler(h func(pktkit.Frame) error)

func (*L2Dev) SetIPv4

func (d *L2Dev) SetIPv4(addr netip.Prefix) error

SetIPv4 configures an IPv4 address on the interface and brings it up.

func (*L2Dev) SetIPv6

func (d *L2Dev) SetIPv6(addr netip.Prefix) error

SetIPv6 configures an IPv6 address on the interface and brings it up.

func (*L2Dev) SetMTU

func (d *L2Dev) SetMTU(mtu int) error

SetMTU sets the interface MTU.

type L3Dev

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

L3Dev is a TUN device implementing pktkit.L3Device. It reads and writes raw IP packets from/to the OS network stack.

func TUN

func TUN(cfg Config) (*L3Dev, error)

TUN opens a TUN device (L3, raw IP packets).

func (*L3Dev) AddRoute

func (d *L3Dev) AddRoute(dst netip.Prefix, gw netip.Addr) error

AddRoute adds a route via this interface.

func (*L3Dev) Addr

func (d *L3Dev) Addr() netip.Prefix

func (*L3Dev) Close

func (d *L3Dev) Close() error

func (*L3Dev) Done

func (d *L3Dev) Done() <-chan struct{}

Done returns a channel that is closed when the device is closed.

func (*L3Dev) Name

func (d *L3Dev) Name() string

Name returns the OS interface name (e.g. "tun0", "utun3").

func (*L3Dev) Send

func (d *L3Dev) Send(pkt pktkit.Packet) error

func (*L3Dev) SetAddr

func (d *L3Dev) SetAddr(p netip.Prefix) error

func (*L3Dev) SetHandler

func (d *L3Dev) SetHandler(h func(pktkit.Packet) error)

func (*L3Dev) SetIPv4

func (d *L3Dev) SetIPv4(addr netip.Prefix) error

SetIPv4 configures an IPv4 address on the interface and brings it up.

func (*L3Dev) SetIPv6

func (d *L3Dev) SetIPv6(addr netip.Prefix) error

SetIPv6 configures an IPv6 address on the interface and brings it up.

func (*L3Dev) SetMTU

func (d *L3Dev) SetMTU(mtu int) error

SetMTU sets the interface MTU.

Jump to

Keyboard shortcuts

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