net

package
v0.22.0 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2026 License: AGPL-3.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// ApoxyULAAddr is the base address of the ApoxyNet ULA prefix.
	// Used as the server-side address for overlay services (e.g. BFD).
	ApoxyULAAddr = "fd61:706f:7879::"
)
View Source
const (
	IPv4CidrPrefix = "100.64.0.0/10"
)

Variables

View Source
var (
	// ProxyEndpointID is the endpoint ID for the proxy.
	ProxyEndpointID = EndpointID{0x00, 0x00}
)
View Source
var (
	// SystemNetworkID is the network ID for the system network (as opposed to a user network).
	SystemNetworkID = NetworkID{0x00, 0x00, 0x00}
)

Functions

func GetAllGlobalUnicastAddresses

func GetAllGlobalUnicastAddresses(includeLoopback bool) ([]netip.Prefix, error)

GetAllGlobalUnicastAddresses returns the global unicast IPv4/IPv6 addresses across all non-loopback, up interfaces by calling GetGlobalUnicastAddresses for each interface.

func GetGlobalUnicastAddresses

func GetGlobalUnicastAddresses(ifcName string, includeLoopback bool) ([]netip.Prefix, error)

GetGlobalUnicastAddresses returns the global unicast IPv4/IPv6 address of the specified interface.

func GetTCPChecksum

func GetTCPChecksum(packetData []byte) (uint16, error)

GetTCPChecksum extracts the TCP checksum from a packet without modifying it

func LastIP

func LastIP(prefix netip.Prefix) netip.Addr

LastIP returns the last IP address in the given prefix.

func NetworkPrefix

func NetworkPrefix(id NetworkID) netip.Prefix

NetworkPrefix returns the overlay /72 for a NetworkID. Unlike NewULA(ctx, id).NetPrefix(), it constructs no go-ipam instance — it is pure address arithmetic, safe on hot paths.

func NetworkPrefixOf

func NetworkPrefixOf(addr netip.Addr) netip.Prefix

NetworkPrefixOf returns the overlay /72 containing addr (its network portion).

func RecalculateTCPChecksum

func RecalculateTCPChecksum(packetData []byte) error

RecalculateTCPChecksum manually recalculates and updates the TCP checksum in a raw packet

func ULAPrefix

func ULAPrefix() netip.Prefix

ULAPrefix returns the Apoxy overlay ULA prefix (fd61:706f:7879::/48). Every project overlay /72 and endpoint /96 is carved from within it; callers use it to bound-check addresses that claim to be overlay space (e.g. the resident egress SSRF carve-out, which must only ever relax destinations inside it).

func VerifyTCPChecksum

func VerifyTCPChecksum(packetData []byte) (bool, error)

VerifyTCPChecksum verifies if the TCP checksum in a packet is correct

Types

type EndpointID

type EndpointID [2]byte

EndpointID is and endpoint (e.g a Tunnel Agent, Backplane) which is unique within the network.

type IPAM

type IPAM interface {
	// Allocate allocates a prefix.
	Allocate() (netip.Prefix, error)

	// Release releases an IP address. No-op if the address is not allocated
	// (returns nil).
	Release(peerPrefix netip.Prefix) error
}

IPAM interface defines the methods for managing IP addresses.

func NewIPAMv4

func NewIPAMv4(ctx context.Context) IPAM

type NetULA

type NetULA struct {
	NetID      NetworkID
	EndpointID EndpointID
	// contains filtered or unexported fields
}

NetULA represents a ULA prefix for a network.

func NewULA

func NewULA(ctx context.Context, id NetworkID) *NetULA

NewULA returns the IPv6 ULA prefix for a project.

func ULAFromPrefix

func ULAFromPrefix(ctx context.Context, prefix netip.Prefix) (*NetULA, error)

ULAFromPrefix creates a new NetULA from an IPv6 address.

func (*NetULA) FullPrefix

func (u *NetULA) FullPrefix() netip.Prefix

FullPrefix returns the IPv6 ULA prefix for the network.

func (*NetULA) IPAM

func (u *NetULA) IPAM(ctx context.Context, bits uint8) (IPAM, error)

IPAM returns an IPAM that allocates bits-sized ULA prefixes.

func (*NetULA) NetPrefix

func (u *NetULA) NetPrefix() netip.Prefix

NetPrefix returns a prefix with just the network portion.

func (*NetULA) WithEndpoint

func (u *NetULA) WithEndpoint(ctx context.Context, epID EndpointID) (*NetULA, error)

WithEndpoint returns the IPv6 ULA prefix for an endpoint.

type NetworkID

type NetworkID [3]byte

NetworkID represents a unique identifier for a network.

func NetworkIDFromCIDR

func NetworkIDFromCIDR(cidr string) (NetworkID, error)

NetworkIDFromCIDR extracts the 24-bit NetworkID (ULA bytes 6-8) from a network's overlay /72 prefix in CIDR string form.

func NetworkIDHexToBytes

func NetworkIDHexToBytes(h string) (NetworkID, error)

NetworkIDHexToBytes converts a hexadecimal network id representation to a byte array. Example: NetworkIDHexToBytes("123456") returns [18, 52, 86]

type PcapDevice

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

func NewPcapDevice

func NewPcapDevice(dev tun.Device, pcapPath string) (*PcapDevice, error)

func (*PcapDevice) BatchSize

func (d *PcapDevice) BatchSize() int

func (*PcapDevice) Close

func (d *PcapDevice) Close() error

func (*PcapDevice) Events

func (d *PcapDevice) Events() <-chan tun.Event

func (*PcapDevice) File

func (d *PcapDevice) File() *os.File

func (*PcapDevice) MTU

func (d *PcapDevice) MTU() (int, error)

func (*PcapDevice) Name

func (d *PcapDevice) Name() (string, error)

func (*PcapDevice) Read

func (d *PcapDevice) Read(bufs [][]byte, sizes []int, offset int) (n int, err error)

func (*PcapDevice) Write

func (d *PcapDevice) Write(bufs [][]byte, offset int) (int, error)

Jump to

Keyboard shortcuts

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