Help us shape the future of Go! Take the 2026 Go Developer Survey

mtu

package
v1.19.9 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2026 License: Apache-2.0 Imports: 44 Imported by: 23

Documentation

Overview

Package mtu is a library for tracking and configuring MTU for devices and routes.

Index

Constants

View Source
const (
	// MaxMTU is the highest MTU that can be used for devices and routes
	// handled by Cilium. It will typically be used to configure inbound
	// paths towards containers where it is guaranteed that the packet will
	// not be rerouted to another node, and therefore will not lead to
	// any form of IP fragmentation.
	// One might expect this to be 65535, however Linux seems to cap the
	// MTU of routes at 65520, so we use this value below.
	MaxMTU = 65520

	// EthernetMTU is the standard MTU for Ethernet devices. It is used
	// as the MTU for container devices when running direct routing mode.
	EthernetMTU = 1500

	// TunnelOverheadIPv{4,6} is an approximation for bytes used for tunnel
	// encapsulation. It accounts for:
	//                       IPv4  IPv6
	//    (Outer ethernet is not accounted against MTU size)
	//    Outer IP header:    20B  40B
	//    Outer UDP header:    8B   8B
	//    Outer VXLAN header:  8B   8B
	//    Original Ethernet:  14B  14B
	//                        ---  ---
	//    Total extra bytes:  50B  70B
	TunnelOverheadIPv4 = 50
	TunnelOverheadIPv6 = 70

	// DsrTunnelOverhead is about the GENEVE DSR option that gets inserted
	// by the LB, when addressing a Service in hs-ipcache mode
	DsrTunnelOverhead = 12

	// EncryptionIPsecOverhead is an approximation for bytes used for
	// encryption. Depending on key size and encryption type the actual
	// size may vary here we do calculations for 128B keys and Auth. The
	// overhead is accounted for as:
	//    Outer IP header:    20B
	//    SPI:		   4B
	//    Sequece Numbers:	   4B
	//    Next Header:         1B
	//    ICV:		  16B
	//    Padding:            16B
	//    128bit Auth:        16B
	//			  ---
	//    Total extra bytes:  77B
	EncryptionIPsecOverhead = 77

	// EncryptionDefaultAuthKeyLength is 16 representing 128B key recommended
	// size for GCM(AES*) in RFC4106. Users may input other lengths via
	// key secrets.
	EncryptionDefaultAuthKeyLength = 16

	// WireguardOverhead is an approximation for the overhead of WireGuard
	// encapsulation.
	//
	// https://github.com/torvalds/linux/blob/v5.12/drivers/net/wireguard/device.c#L262:
	// https://github.com/torvalds/linux/blob/v5.12/drivers/net/wireguard/send.c#L141
	//      MESSAGE_MINIMUM_LENGTH:    32B
	//      Outer IPv4 or IPv6 header: 40B
	//      Outer UDP header:           8B
	//      Maximum padding:           15B
	//                                 ---
	//      Total extra bytes:         80B
	WireguardOverhead = 95

	// IPv6MinMTU is the minimum MTU required for IPv6 to function on a
	// network interface, as defined in RFC 8200 section 5. The Linux kernel
	// refuses to initialize inet6_dev on interfaces with MTU below this
	// value, causing all IPv6 packet reception to be silently discarded.
	IPv6MinMTU = 1280

	// IPIPv4Overhead is the overhead for the IPv4 header used in IPIP devices.
	// sizeof(struct iphdr)
	IPIPv4Overhead = 20

	// IPIPv6Overhead is the overhead for the IPv6 header (40B) as well as tunnel
	// encap limit option used in IP6IP6 devices.
	// sizeof(struct ipv6hdr) + 8
	// See kernel commit 381601e5bbae ("Make the ip6_tunnel reflect the true mtu.")
	// for details.
	IPIPv6Overhead = 48
)

Variables

View Source
var Cell = cell.Module(
	"mtu",
	"MTU discovery",

	cell.ProvidePrivate(NewMTUTable),
	cell.Provide(
		statedb.RWTable[RouteMTU].ToTable,
		newForCell,
	),
	cell.Invoke(newEndpointUpdater),
	cell.Config(defaultConfig),
)
View Source
var DefaultPrefixV4 = netip.MustParsePrefix("0.0.0.0/0")
View Source
var DefaultPrefixV6 = netip.MustParsePrefix("::/0")
View Source
var (
	MTURouteIndex = statedb.Index[RouteMTU, netip.Prefix]{
		Name: "cidr",
		FromObject: func(rm RouteMTU) index.KeySet {
			return index.NewKeySet(index.NetIPPrefix(rm.Prefix))
		},
		FromKey:    index.NetIPPrefix,
		FromString: index.NetIPPrefixString,
		Unique:     true,
	}
)

Functions

func NewMTUTable added in v1.17.0

func NewMTUTable(db *statedb.DB) (statedb.RWTable[RouteMTU], error)

Types

type Config added in v1.16.0

type Config struct {
	// Enable route MTU for pod netns when CNI chaining is used
	EnableRouteMTUForCNIChaining bool
	MTU                          int
	// PacketizationLayerPMTUDMode configures kernel packetization layer path mtu discovery on Pod netns.
	PacketizationLayerPMTUDMode string
}

func (Config) Flags added in v1.16.0

func (c Config) Flags(flags *pflag.FlagSet)

type Configuration

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

Configuration is an MTU configuration as returned by NewConfiguration

func NewConfiguration

func NewConfiguration(authKeySize int, encryptEnabled, encapEnabled, wireguardEnabled, tunnelOverIPv6 bool) Configuration

NewConfiguration returns a new MTU configuration which is used to calculate MTU values from a base MTU based on the config.

func (Configuration) Calculate added in v1.17.0

func (c Configuration) Calculate(baseMTU int) RouteMTU

type EndpointMTUUpdateHook added in v1.17.0

type EndpointMTUUpdateHook func(routeMTUs []RouteMTU) error

type EndpointMTUUpdater added in v1.17.0

type EndpointMTUUpdater interface {
	// RegisterHook registers a hook to be called when updating the MTU of endpoints.
	// The hook is called from within the network namespace of each endpoint.
	RegisterHook(hook EndpointMTUUpdateHook)
}

type LatestMTUGetter added in v1.17.0

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

func (*LatestMTUGetter) GetDeviceMTU added in v1.17.0

func (m *LatestMTUGetter) GetDeviceMTU() int

func (*LatestMTUGetter) GetRouteMTU added in v1.17.0

func (m *LatestMTUGetter) GetRouteMTU() int

func (*LatestMTUGetter) GetRoutePostEncryptMTU added in v1.17.0

func (m *LatestMTUGetter) GetRoutePostEncryptMTU() int

func (*LatestMTUGetter) IsEnableRouteMTUForCNIChaining added in v1.17.0

func (m *LatestMTUGetter) IsEnableRouteMTUForCNIChaining() bool

func (*LatestMTUGetter) PacketizationLayerPMTUDMode added in v1.19.0

func (m *LatestMTUGetter) PacketizationLayerPMTUDMode() string

type MTU added in v1.15.0

type MTU interface {
	GetDeviceMTU() int
	GetRouteMTU() int
	GetRoutePostEncryptMTU() int
	IsEnableRouteMTUForCNIChaining() bool
	// PacketizationLayerPMTUDMode returns valid plpmtud mode as string (empty means: do not set).
	PacketizationLayerPMTUDMode() string
}

type MTUManager added in v1.17.0

type MTUManager struct {
	Config *Configuration
	// contains filtered or unexported fields
}

func (*MTUManager) Updater added in v1.17.0

func (m *MTUManager) Updater(ctx context.Context, health cell.Health) error

type RouteMTU added in v1.17.0

type RouteMTU struct {
	Prefix              netip.Prefix
	DeviceMTU           int
	RouteMTU            int
	RoutePostEncryptMTU int
}

func (RouteMTU) TableHeader added in v1.17.0

func (RouteMTU) TableHeader() []string

func (RouteMTU) TableRow added in v1.17.0

func (r RouteMTU) TableRow() []string

Jump to

Keyboard shortcuts

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