tunnels

package
v2.6.1 Latest Latest
Warning

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

Go to latest
Published: Oct 4, 2025 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package tunnels provides functionality for setting up and managing overlay tunnels in Linux. It includes support for both IPIP and FOU (Foo over Ethernet) encapsulation types.

As much functionality as possible is done via the netlink library, however, FOU tunnels require using the iproute2 user space tooling since they are not currently supported by the netlink library.

Index

Constants

View Source
const (
	EncapTypeFOU  = EncapType("fou")
	EncapTypeIPIP = EncapType("ipip")

	// Unix tunnel encap types, unfortunately, these are not understood by the netlink library, so we need to use
	// our own enums which as far as I can tell come from here:
	//nolint:lll // URL is long
	// https://github.com/iproute2/iproute2/blob/e6a170a9d4e75d206631da77e469813279c12134/include/uapi/linux/if_tunnel.h#L84-L89
	UnixTunnelEncapTypeNone uint16 = 0
	UnixTunnelEncapTypeFOU  uint16 = 1
	UnixTunnelEncapTypeGUE  uint16 = 2
	UnixTunnelEncapTypeMPLS uint16 = 3
)

Variables

This section is empty.

Functions

func CleanupTunnel

func CleanupTunnel(destinationSubnet *net.IPNet, tunnelName string)

cleanupTunnel removes any traces of tunnels / routes that were setup by nrc.setupOverlayTunnel() and are no longer needed. All errors are logged only, as we want to attempt to perform all cleanup actions regardless of their success

func GenerateTunnelName

func GenerateTunnelName(nodeIP string) string

GenerateTunnelName will generate a name for a tunnel interface given a node IP Since linux restricts interface names to 15 characters, we take the sha-256 of the node IP after removing non-entropic characters like '.' and ':', and then use the first 12 bytes of it. This allows us to cater to both long IPv4 addresses and much longer IPv6 addresses.

TODO: In the future, we should consider using the hexadecimal byte representation of IPv4 addresses and using a the SHA256 of the hash. Additionally, we should not remove non-entropic characters as it can cause hash collisions as "21.3.0.4" would has the same as "2.13.0.4" without "."'s.

Types

type EncapPort

type EncapPort uint16

func ParseEncapPort

func ParseEncapPort(encapPort uint16) (EncapPort, error)

type EncapType

type EncapType string

EncapType represents the type of encapsulation used for an overlay tunnel in kube-router.

func ParseEncapType

func ParseEncapType(encapType string) (EncapType, bool)

ParseEncapType parses the given string and returns an Encap type if valid. It returns an error if the encapsulation type is invalid.

Parameters:

  • s: A string representing the encapsulation type.

Returns:

  • Encap: The parsed encapsulation type.
  • bool: A boolean indicating whether the encapsulation type is valid.

type OverlayTunnel

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

func NewOverlayTunnel

func NewOverlayTunnel(krNode utils.NodeIPAware, encapType EncapType, encapPort EncapPort) *OverlayTunnel

func (*OverlayTunnel) EncapPort

func (o *OverlayTunnel) EncapPort() EncapPort

func (*OverlayTunnel) EncapType

func (o *OverlayTunnel) EncapType() EncapType

func (*OverlayTunnel) SetupOverlayTunnel

func (o *OverlayTunnel) SetupOverlayTunnel(tunnelName string, nextHop net.IP,
	nextHopSubnet *net.IPNet) (netlink.Link, error)

setupOverlayTunnel attempts to create a tunnel link and corresponding routes for IPIP based overlay networks

type Tunneler

type Tunneler interface {
	SetupOverlayTunnel(tunnelName string, nextHop net.IP, nextHopSubnet *net.IPNet) (netlink.Link, error)
	EncapType() EncapType
	EncapPort() EncapPort
}

Jump to

Keyboard shortcuts

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