netstack

package
v0.21.0 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2026 License: AGPL-3.0 Imports: 35 Imported by: 0

Documentation

Overview

icx_network.go

Index

Constants

View Source
const IPv6MinMTU = 1280 // IPv6 minimum MTU, required for some PPPoE links.
View Source
const TunnelMTU = 1420

TunnelMTU is the MTU used for tunnel TUN devices. Sized to fit in a single QUIC datagram after PMTUD on a typical 1500-byte internet path: 1500 (Ethernet) - 20 (IP) - 8 (UDP) - ~26 (QUIC framing) - 1 (contextID) ≈ 1445. We use 1420 to leave headroom for path variance.

Variables

This section is empty.

Functions

func ToFullAddress

func ToFullAddress(addrPort netip.AddrPort) *tcpip.FullAddress

func Unmap4in6

func Unmap4in6(addr netip.Addr) netip.Addr

Unmap4in6 converts an IPv6 address to an IPv4 address if it is an IPv4-mapped IPv6 address. If the address is not an IPv4-mapped IPv6 address, it is returned unchanged. If the IPv4 address is zero, returns 127.0.0.1. It is following /96 embedding scheme from RFC 6052 (https://datatracker.ietf.org/doc/html/rfc6052#section-2.2).

Types

type ICXNetwork

type ICXNetwork struct {
	network.Network
	// contains filtered or unexported fields
}

TODO (dpeckett): nuke this at some point and merge the logic into the router.

func NewICXNetwork

func NewICXNetwork(handler *icx.Handler, phy *l2pc.L2PacketConn, mtu int, resolveConf *network.ResolveConfig, pcapPath string) (*ICXNetwork, error)

NewICXNetwork creates a new ICXNetwork instance with the given handler, physical connection, MTU, and resolve configuration. If pcapPath is provided, it will create a packet sniffer that writes to the specified file. The handler must be configured in layer3 mode.

func (*ICXNetwork) AddAddr

func (net *ICXNetwork) AddAddr(addr netip.Prefix) error

func (*ICXNetwork) Close

func (net *ICXNetwork) Close() error

Close cleans up the network stack and closes the underlying resources.

func (*ICXNetwork) DelAddr

func (net *ICXNetwork) DelAddr(addr netip.Prefix) error

func (*ICXNetwork) ForwardTo

func (net *ICXNetwork) ForwardTo(ctx context.Context, upstream network.Network) error

ForwardTo forwards all inbound TCP traffic to the upstream network.

func (*ICXNetwork) Start

func (net *ICXNetwork) Start(ctx context.Context) error

Start copies packets to and from netstack and icx. Start runs the netstack <-> ICX datapath until ctx is cancelled or the underlying transport (phy) is closed. It blocks and should run in its own goroutine. The two pump loops (channel.Endpoint <-> engine <-> underlay) now live in the shared icx/vtep/netstack driver; this method just drives it.

type IPTables

type IPTables struct {
	SNATv4 *randSNATTarget
	SNATv6 *randSNATTarget
}

type ProtocolHandler

type ProtocolHandler func(stack.TransportEndpointID, *stack.PacketBuffer) bool

ProtocolHandler is a function that handles packets for a specific protocol.

func TCPForwarder

func TCPForwarder(ctx context.Context, ipstack *stack.Stack, upstream network.Network) ProtocolHandler

TCPForwarder forwards TCP connections to an upstream network.

func UDPForwarder

func UDPForwarder(ctx context.Context, ipstack *stack.Stack, upstream network.Network) ProtocolHandler

UDPForwarder forwards UDP packets to an upstream network.

type TunDevice

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

func NewTunDevice

func NewTunDevice(pcapPath string) (*TunDevice, error)

func (*TunDevice) AddAddr

func (tun *TunDevice) AddAddr(addr netip.Prefix) error

func (*TunDevice) BatchSize

func (tun *TunDevice) BatchSize() int

func (*TunDevice) Close

func (tun *TunDevice) Close() error

func (*TunDevice) DelAddr

func (tun *TunDevice) DelAddr(addr netip.Prefix) error

func (*TunDevice) Events

func (tun *TunDevice) Events() <-chan tun.Event

func (*TunDevice) File

func (tun *TunDevice) File() *os.File

func (*TunDevice) ForwardTo

func (tun *TunDevice) ForwardTo(ctx context.Context, upstream network.Network) error

ForwardTo forwards all inbound traffic to the upstream network.

func (*TunDevice) ListenPacket

func (tun *TunDevice) ListenPacket(addr netip.AddrPort) (net.PacketConn, error)

ListenPacket creates an unconnected UDP PacketConn bound to the given overlay address inside the gvisor network stack.

func (*TunDevice) LocalAddresses

func (tun *TunDevice) LocalAddresses() ([]netip.Prefix, error)

LocalAddresses returns the list of local addresses assigned to the TUN device.

func (*TunDevice) MTU

func (tun *TunDevice) MTU() (int, error)

func (*TunDevice) Name

func (tun *TunDevice) Name() (string, error)

func (*TunDevice) Network

func (tun *TunDevice) Network(resolveConf *network.ResolveConfig) *network.NetstackNetwork

Network returns the network abstraction for the TUN device.

func (*TunDevice) Read

func (tun *TunDevice) Read(buf [][]byte, sizes []int, offset int) (int, error)

func (*TunDevice) RegisterTCPStatsMetrics

func (tun *TunDevice) RegisterTCPStatsMetrics(reg prometheus.Registerer)

RegisterTCPStatsMetrics registers netstack TCP stats as Prometheus gauges that are read at push/scrape time. Call once after creating the TunDevice.

func (*TunDevice) Write

func (tun *TunDevice) Write(buf [][]byte, offset int) (int, error)

func (*TunDevice) WriteNotify

func (tun *TunDevice) WriteNotify()

Jump to

Keyboard shortcuts

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