mtu

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Jan 11, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// IP_MTU_DISCOVER is the Linux socket option for MTU discovery
	IP_MTU_DISCOVER = 10
	// IP_PMTUDISC_DO enables PMTU discovery and sets Don't Fragment bit
	IP_PMTUDISC_DO = 2
)
View Source
const (
	// MinMTU_IPv4 is the minimum MTU for IPv4 networks (RFC 791)
	MinMTU_IPv4 = 576
	// MinMTU_IPv6 is the minimum MTU for IPv6 networks (RFC 8200)
	MinMTU_IPv6 = 1280
	// MaxMTU is the standard Ethernet MTU
	MaxMTU = 1500
	// ICMPHeaderSize is the size of ICMP header
	ICMPHeaderSize = 8
	// IPv4HeaderSize is the size of IPv4 header
	IPv4HeaderSize = 20
	// IPv6HeaderSize is the size of IPv6 header
	IPv6HeaderSize = 40
)
View Source
const (
	// WireGuardOverheadIPv4 is the overhead for WireGuard over IPv4
	// (20 bytes IPv4 + 8 bytes UDP + 32 bytes WireGuard)
	WireGuardOverheadIPv4 = 60

	// WireGuardOverheadIPv6 is the overhead for WireGuard over IPv6
	// (40 bytes IPv6 + 8 bytes UDP + 32 bytes WireGuard)
	WireGuardOverheadIPv6 = 80
)

WireGuard overhead constants WireGuard adds the following overhead to each packet: - IPv4/IPv6 header (20/40 bytes) - UDP header (8 bytes) - WireGuard header (32 bytes)

Total overhead: - IPv4: 20 + 8 + 32 = 60 bytes - IPv6: 40 + 8 + 32 = 80 bytes

Variables

This section is empty.

Functions

func CalculateMTU added in v0.4.0

func CalculateMTU(pathMTU int, isIPv6 bool, tunnelMode bool) int

CalculateMTU returns the appropriate MTU based on whether we're testing through an existing tunnel or to a WireGuard endpoint.

When tunnelMode is true, the path MTU is returned as-is because the WireGuard overhead is already applied by the tunnel.

When tunnelMode is false, the WireGuard overhead is subtracted to give the optimal MTU setting for a new tunnel.

func CalculateWireGuardMTU

func CalculateWireGuardMTU(pathMTU int, isIPv6 bool) int

CalculateWireGuardMTU calculates the optimal WireGuard interface MTU given the path MTU and IP version

Types

type Discoverer

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

Discoverer handles MTU discovery operations

func NewDiscoverer

func NewDiscoverer(target net.IP, log *output.Logger, minMTU, maxMTU int) *Discoverer

NewDiscoverer creates a new MTU discoverer for the given target

func (*Discoverer) FindPathMTU

func (d *Discoverer) FindPathMTU() (int, error)

FindPathMTU uses binary search to find the path MTU to the target

Jump to

Keyboard shortcuts

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