tun

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Jun 23, 2026 License: GPL-3.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddTunAddr

func AddTunAddr(tun gtun.Tun, addr string) error

AddTunAddr updates list off addrs of provided Tun.

The address must be a CIDR prefix such as "10.0.0.1/32" or "fd00::1/128". The Tun must expose a non-nil File; otherwise sysnet.ErrUnknownTun is returned.

func AddTunRoute

func AddTunRoute(tun gtun.Tun, route string) error

AddTunRoute updates list off routes of provided Tun.

The route must be a CIDR prefix such as "10.0.0.0/24" or "fd00::/64". The Tun must expose a non-nil File; otherwise sysnet.ErrUnknownTun is returned.

func CreateDefaultTUN

func CreateDefaultTUN(base string, mtu int) (gtun.Tun, error)

CreateDefaultTUN creates a TUN device whose name is generated from base.

Unlike tuntap.CreateTUN, base is not used as the exact interface name. Instead, each attempt uses the template "<base>-<rand>", where rand is a freshly generated alpha-numeric string sized to consume the space left by the base name and Linux's 15-character interface name limit. The final name is truncated to Linux's limit after base and rand are concatenated.

If the generated name is already occupied, CreateDefaultTUN generates another random suffix and tries again, up to a fixed attempt limit. Only name-occupied errors are retryable; random generation failures, invalid names, permission errors, missing /dev/net/tun, unsupported MTU values, and all other tuntap.CreateTUN errors are returned immediately.

func GetTunAddrs

func GetTunAddrs(tun gtun.Tun) ([]string, error)

GetTunAddrs returns list off addrs of provided Tun.

Returned entries are CIDR prefixes assigned to the interface. The Tun must expose a non-nil File; otherwise sysnet.ErrUnknownTun is returned.

func GetTunRotue

func GetTunRotue(tun gtun.Tun) ([]string, error)

GetTunRotue returns list off routes of provided Tun.

The misspelling is kept to match the gonnect sysnet.System interface. The Tun must expose a non-nil File; otherwise sysnet.ErrUnknownTun is returned.

func NormalizeMTU added in v0.1.3

func NormalizeMTU(mtu int) int

NormalizeMTU returns the effective TUN MTU used by Linux configuration.

func SetTunAddrs

func SetTunAddrs(tun gtun.Tun, addrs []string) error

SetTunAddrs updates list off addrs of provided Tun.

Existing interface addresses are removed before the new CIDR addresses are added. The Tun must expose a non-nil File; otherwise sysnet.ErrUnknownTun is returned.

func SetTunMTU

func SetTunMTU(tun gtun.Tun, mtu int) error

SetTunMTU updates MTU of provided Tun.

The Tun must expose a non-nil File; otherwise sysnet.ErrUnknownTun is returned. Values lower than the IPv4 minimum MTU are replaced with a sensible default of 1420 bytes.

func SetTunName

func SetTunName(tun gtun.Tun, name string) ([]string, error)

SetTunName updates name of provided Tun.

The Tun must expose a non-nil File; otherwise sysnet.ErrUnknownTun is returned.

func SetTunRoutes

func SetTunRoutes(tun gtun.Tun, routes []string) error

SetTunRoutes updates list off routes of provided Tun.

Existing main-table routes whose output interface is the Tun are removed before the provided CIDR routes are added. The Tun must expose a non-nil File; otherwise sysnet.ErrUnknownTun is returned.

Types

This section is empty.

Jump to

Keyboard shortcuts

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