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 ¶
- type Config
- type L2Dev
- func (d *L2Dev) AddRoute(dst netip.Prefix, gw netip.Addr) error
- func (d *L2Dev) Close() error
- func (d *L2Dev) Done() <-chan struct{}
- func (d *L2Dev) HWAddr() net.HardwareAddr
- func (d *L2Dev) Name() string
- func (d *L2Dev) Send(f pktkit.Frame) error
- func (d *L2Dev) SetHandler(h func(pktkit.Frame) error)
- func (d *L2Dev) SetIPv4(addr netip.Prefix) error
- func (d *L2Dev) SetIPv6(addr netip.Prefix) error
- func (d *L2Dev) SetMTU(mtu int) error
- type L3Dev
- func (d *L3Dev) AddRoute(dst netip.Prefix, gw netip.Addr) error
- func (d *L3Dev) Addr() netip.Prefix
- func (d *L3Dev) Close() error
- func (d *L3Dev) Done() <-chan struct{}
- func (d *L3Dev) Name() string
- func (d *L3Dev) Send(pkt pktkit.Packet) error
- func (d *L3Dev) SetAddr(p netip.Prefix) error
- func (d *L3Dev) SetHandler(h func(pktkit.Packet) error)
- func (d *L3Dev) SetIPv4(addr netip.Prefix) error
- func (d *L3Dev) SetIPv6(addr netip.Prefix) error
- func (d *L3Dev) SetMTU(mtu int) error
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 (*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
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 (*L3Dev) Done ¶
func (d *L3Dev) Done() <-chan struct{}
Done returns a channel that is closed when the device is closed.