ebpf

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2025 License: Apache-2.0 Imports: 16 Imported by: 0

README

Ella Core UPF XDP implementation

This directory contains the XDP implementation of the UPF. It contains both the userspace go code and the kernel space XDP code.

Compilation

In most cases, you should use go generate from the top-level directory to build the project.

For development of the C XDP code, cmake can be used to create files to support the clangd LSP. Run the following command in this directory to generate the files:

cmake .

Inspecting UPF state

Maps used to drive the XDP code are pinned in the sysfs filesystem under /sys/fs/bpf/upf_pipeline/. They can be inspected with bpftool.

For example, it is possible to list all the uplink PDRs with the following command:

sudo bpftool map dump pinned /sys/fs/bpf/upf_pipeline/pdrs_uplink

Documentation

Index

Constants

View Source
const (
	PinPath = "/sys/fs/bpf/upf_pipeline"
)

Variables

This section is empty.

Functions

func CloseAllObjects

func CloseAllObjects(closers ...io.Closer) error

func Copy16Ip

func Copy16Ip[T ~[]byte](arr T) [16]byte

func LoadN3Entrypoint

func LoadN3Entrypoint() (*ebpf.CollectionSpec, error)

LoadN3Entrypoint returns the embedded CollectionSpec for N3Entrypoint.

func LoadN3EntrypointObjects

func LoadN3EntrypointObjects(obj interface{}, opts *ebpf.CollectionOptions) error

LoadN3EntrypointObjects loads N3Entrypoint and converts it into a struct.

The following types are suitable as obj argument:

*N3EntrypointObjects
*N3EntrypointPrograms
*N3EntrypointMaps

See ebpf.CollectionSpec.LoadAndAssign documentation for details.

func LoadN6Entrypoint

func LoadN6Entrypoint() (*ebpf.CollectionSpec, error)

LoadN6Entrypoint returns the embedded CollectionSpec for N6Entrypoint.

func LoadN6EntrypointObjects

func LoadN6EntrypointObjects(obj interface{}, opts *ebpf.CollectionOptions) error

LoadN6EntrypointObjects loads N6Entrypoint and converts it into a struct.

The following types are suitable as obj argument:

*N6EntrypointObjects
*N6EntrypointPrograms
*N6EntrypointMaps

See ebpf.CollectionSpec.LoadAndAssign documentation for details.

func PinMaps added in v0.3.0

func PinMaps() error

Types

type BpfObjects

type BpfObjects struct {
	N3EntrypointObjects
	N6EntrypointObjects

	FarIDTracker *IDTracker
	QerIDTracker *IDTracker
	Masquerade   bool
}

func NewBpfObjects

func NewBpfObjects(farMapSize uint32, qerMapSize uint32, masquerade bool) *BpfObjects

func (*BpfObjects) Close

func (bpfObjects *BpfObjects) Close() error

func (*BpfObjects) DeleteDownlinkPdrIP6 added in v0.0.11

func (bpfObjects *BpfObjects) DeleteDownlinkPdrIP6(ipv6 net.IP) error

func (*BpfObjects) DeleteFar

func (bpfObjects *BpfObjects) DeleteFar(internalID uint32) error
func (bpfObjects *BpfObjects) DeletePdrDownlink(ipv4 net.IP) error
func (bpfObjects *BpfObjects) DeletePdrUplink(teid uint32) error

func (*BpfObjects) DeleteQer

func (bpfObjects *BpfObjects) DeleteQer(internalID uint32) error

func (*BpfObjects) Load

func (bpfObjects *BpfObjects) Load() error

func (*BpfObjects) NewFar

func (bpfObjects *BpfObjects) NewFar(farInfo FarInfo) (uint32, error)

func (*BpfObjects) NewQer

func (bpfObjects *BpfObjects) NewQer(qerInfo QerInfo) (uint32, error)

func (*BpfObjects) PutDownlinkPdrIP6 added in v0.0.11

func (bpfObjects *BpfObjects) PutDownlinkPdrIP6(ipv6 net.IP, pdrInfo PdrInfo) error
func (bpfObjects *BpfObjects) PutPdrDownlink(ipv4 net.IP, pdrInfo PdrInfo) error
func (bpfObjects *BpfObjects) PutPdrUplink(teid uint32, pdrInfo PdrInfo) error

func (*BpfObjects) UpdateFar

func (bpfObjects *BpfObjects) UpdateFar(internalID uint32, farInfo FarInfo) error

func (*BpfObjects) UpdateQer

func (bpfObjects *BpfObjects) UpdateQer(internalID uint32, qerInfo QerInfo) error

type FarInfo

type FarInfo struct {
	Action                uint8
	OuterHeaderCreation   uint8
	TeID                  uint32
	RemoteIP              uint32
	LocalIP               uint32
	TransportLevelMarking uint16
}

func (FarInfo) MarshalJSON

func (f FarInfo) MarshalJSON() ([]byte, error)

type IDTracker added in v0.0.11

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

func NewIDTracker added in v0.0.11

func NewIDTracker(size uint32) *IDTracker

func (*IDTracker) GetNext added in v0.0.11

func (t *IDTracker) GetNext() (next uint32, err error)

func (*IDTracker) Release added in v0.0.11

func (t *IDTracker) Release(id uint32)

type IPWMask added in v0.0.11

type IPWMask struct {
	Type uint8 // 0: any, 1: ip4, 2: ip6
	IP   net.IP
	Mask net.IPMask
}

type N3EntrypointFarInfo added in v0.0.8

type N3EntrypointFarInfo struct {
	Action              uint8
	OuterHeaderCreation uint8

	Teid                  uint32
	Remoteip              uint32
	Localip               uint32
	TransportLevelMarking uint16
	// contains filtered or unexported fields
}

type N3EntrypointFiveTuple added in v0.3.0

type N3EntrypointFiveTuple struct {
	Saddr uint32
	Daddr uint32
	Sport uint16
	Dport uint16
	Proto uint16
	// contains filtered or unexported fields
}

type N3EntrypointMapSpecs

type N3EntrypointMapSpecs struct {
	FarMap           *ebpf.MapSpec `ebpf:"far_map"`
	NatCt            *ebpf.MapSpec `ebpf:"nat_ct"`
	PdrsUplink       *ebpf.MapSpec `ebpf:"pdrs_uplink"`
	QerMap           *ebpf.MapSpec `ebpf:"qer_map"`
	UplinkRouteStats *ebpf.MapSpec `ebpf:"uplink_route_stats"`
	UplinkStatistics *ebpf.MapSpec `ebpf:"uplink_statistics"`
}

N3EntrypointMapSpecs contains maps before they are loaded into the kernel.

It can be passed ebpf.CollectionSpec.Assign.

type N3EntrypointMaps

type N3EntrypointMaps struct {
	FarMap           *ebpf.Map `ebpf:"far_map"`
	NatCt            *ebpf.Map `ebpf:"nat_ct"`
	PdrsUplink       *ebpf.Map `ebpf:"pdrs_uplink"`
	QerMap           *ebpf.Map `ebpf:"qer_map"`
	UplinkRouteStats *ebpf.Map `ebpf:"uplink_route_stats"`
	UplinkStatistics *ebpf.Map `ebpf:"uplink_statistics"`
}

N3EntrypointMaps contains all maps after they have been loaded into the kernel.

It can be passed to LoadN3EntrypointObjects or ebpf.CollectionSpec.LoadAndAssign.

func (*N3EntrypointMaps) Close

func (m *N3EntrypointMaps) Close() error

type N3EntrypointNatEntry added in v0.3.0

type N3EntrypointNatEntry struct {
	Src       N3EntrypointFiveTuple
	RefreshTs uint64
	// contains filtered or unexported fields
}

type N3EntrypointObjects

type N3EntrypointObjects struct {
	N3EntrypointPrograms
	N3EntrypointMaps
	N3EntrypointVariables
}

N3EntrypointObjects contains all objects after they have been loaded into the kernel.

It can be passed to LoadN3EntrypointObjects or ebpf.CollectionSpec.LoadAndAssign.

func (*N3EntrypointObjects) Close

func (o *N3EntrypointObjects) Close() error

type N3EntrypointPdrInfo added in v0.3.0

type N3EntrypointPdrInfo struct {
	FarId              uint32
	QerId              uint32
	OuterHeaderRemoval uint8
	SdfMode            uint8

	SdfRules struct {
		SdfFilter struct {
			SrcAddr struct {
				Type uint8

				Ip   [16]byte /* uint128 */
				Mask [16]byte /* uint128 */
				// contains filtered or unexported fields
			}
			DstAddr struct {
				Type uint8

				Ip   [16]byte /* uint128 */
				Mask [16]byte /* uint128 */
				// contains filtered or unexported fields
			}
			SrcPort struct {
				LowerBound uint16
				UpperBound uint16
				// contains filtered or unexported fields
			}
			DstPort struct {
				LowerBound uint16
				UpperBound uint16
				// contains filtered or unexported fields
			}
			Protocol uint8
			// contains filtered or unexported fields
		}
		OuterHeaderRemoval uint8

		FarId uint32
		QerId uint32
		// contains filtered or unexported fields
	}
	// contains filtered or unexported fields
}

func CombineN3PdrWithSdf added in v0.0.8

func CombineN3PdrWithSdf(defaultPdr *N3EntrypointPdrInfo, sdfPdr PdrInfo) N3EntrypointPdrInfo

func PreprocessN3PdrWithSdf added in v0.0.8

func PreprocessN3PdrWithSdf(lookup func(interface{}, interface{}) error, key interface{}, pdrInfo PdrInfo) (N3EntrypointPdrInfo, error)

func ToN3EntrypointPdrInfo added in v0.0.8

func ToN3EntrypointPdrInfo(defaultPdr PdrInfo) N3EntrypointPdrInfo

type N3EntrypointProgramSpecs

type N3EntrypointProgramSpecs struct {
	UpfN3EntrypointFunc *ebpf.ProgramSpec `ebpf:"upf_n3_entrypoint_func"`
}

N3EntrypointProgramSpecs contains programs before they are loaded into the kernel.

It can be passed ebpf.CollectionSpec.Assign.

type N3EntrypointPrograms

type N3EntrypointPrograms struct {
	UpfN3EntrypointFunc *ebpf.Program `ebpf:"upf_n3_entrypoint_func"`
}

N3EntrypointPrograms contains all programs after they have been loaded into the kernel.

It can be passed to LoadN3EntrypointObjects or ebpf.CollectionSpec.LoadAndAssign.

func (*N3EntrypointPrograms) Close

func (p *N3EntrypointPrograms) Close() error

type N3EntrypointQerInfo added in v0.0.8

type N3EntrypointQerInfo struct {
	UlGateStatus uint8
	DlGateStatus uint8
	Qfi          uint8

	UlMaximumBitrate uint32
	DlMaximumBitrate uint32

	UlStart uint64
	DlStart uint64
	// contains filtered or unexported fields
}

type N3EntrypointRouteStat added in v0.0.8

type N3EntrypointRouteStat struct {
	FibLookupIp4Cache     uint64
	FibLookupIp4Ok        uint64
	FibLookupIp4ErrorDrop uint64
	FibLookupIp4ErrorPass uint64
	FibLookupIp6Cache     uint64
	FibLookupIp6Ok        uint64
	FibLookupIp6ErrorDrop uint64
	FibLookupIp6ErrorPass uint64
	// contains filtered or unexported fields
}

type N3EntrypointSpecs

N3EntrypointSpecs contains maps and programs before they are loaded into the kernel.

It can be passed ebpf.CollectionSpec.Assign.

type N3EntrypointUpfStatistic added in v0.3.0

type N3EntrypointUpfStatistic struct {
	UpfCounters struct {
		Bytes uint64
		// contains filtered or unexported fields
	}
	UpfCounter struct {
		Rx uint64
		Tx uint64
		// contains filtered or unexported fields
	}
	XdpActions [8]uint64
	// contains filtered or unexported fields
}

type N3EntrypointVariableSpecs added in v0.0.7

type N3EntrypointVariableSpecs struct {
	Masquerade *ebpf.VariableSpec `ebpf:"masquerade"`
}

N3EntrypointVariableSpecs contains global variables before they are loaded into the kernel.

It can be passed ebpf.CollectionSpec.Assign.

type N3EntrypointVariables added in v0.0.7

type N3EntrypointVariables struct {
	Masquerade *ebpf.Variable `ebpf:"masquerade"`
}

N3EntrypointVariables contains all global variables after they have been loaded into the kernel.

It can be passed to LoadN3EntrypointObjects or ebpf.CollectionSpec.LoadAndAssign.

type N6EntrypointFarInfo added in v0.0.8

type N6EntrypointFarInfo struct {
	Action              uint8
	OuterHeaderCreation uint8

	Teid                  uint32
	Remoteip              uint32
	Localip               uint32
	TransportLevelMarking uint16
	// contains filtered or unexported fields
}

type N6EntrypointFiveTuple added in v0.3.0

type N6EntrypointFiveTuple struct {
	Saddr uint32
	Daddr uint32
	Sport uint16
	Dport uint16
	Proto uint16
	// contains filtered or unexported fields
}

type N6EntrypointIn6Addr added in v0.0.8

type N6EntrypointIn6Addr struct {
	In6U struct {
		U6Addr8 [16]uint8
		// contains filtered or unexported fields
	}
	// contains filtered or unexported fields
}

type N6EntrypointMapSpecs

type N6EntrypointMapSpecs struct {
	DownlinkRouteStats *ebpf.MapSpec `ebpf:"downlink_route_stats"`
	DownlinkStatistics *ebpf.MapSpec `ebpf:"downlink_statistics"`
	FarMap             *ebpf.MapSpec `ebpf:"far_map"`
	NatCt              *ebpf.MapSpec `ebpf:"nat_ct"`
	PdrsDownlinkIp4    *ebpf.MapSpec `ebpf:"pdrs_downlink_ip4"`
	PdrsDownlinkIp6    *ebpf.MapSpec `ebpf:"pdrs_downlink_ip6"`
	QerMap             *ebpf.MapSpec `ebpf:"qer_map"`
}

N6EntrypointMapSpecs contains maps before they are loaded into the kernel.

It can be passed ebpf.CollectionSpec.Assign.

type N6EntrypointMaps

type N6EntrypointMaps struct {
	DownlinkRouteStats *ebpf.Map `ebpf:"downlink_route_stats"`
	DownlinkStatistics *ebpf.Map `ebpf:"downlink_statistics"`
	FarMap             *ebpf.Map `ebpf:"far_map"`
	NatCt              *ebpf.Map `ebpf:"nat_ct"`
	PdrsDownlinkIp4    *ebpf.Map `ebpf:"pdrs_downlink_ip4"`
	PdrsDownlinkIp6    *ebpf.Map `ebpf:"pdrs_downlink_ip6"`
	QerMap             *ebpf.Map `ebpf:"qer_map"`
}

N6EntrypointMaps contains all maps after they have been loaded into the kernel.

It can be passed to LoadN6EntrypointObjects or ebpf.CollectionSpec.LoadAndAssign.

func (*N6EntrypointMaps) Close

func (m *N6EntrypointMaps) Close() error

type N6EntrypointNatEntry added in v0.3.0

type N6EntrypointNatEntry struct {
	Src       N6EntrypointFiveTuple
	RefreshTs uint64
	// contains filtered or unexported fields
}

type N6EntrypointObjects

type N6EntrypointObjects struct {
	N6EntrypointPrograms
	N6EntrypointMaps
	N6EntrypointVariables
}

N6EntrypointObjects contains all objects after they have been loaded into the kernel.

It can be passed to LoadN6EntrypointObjects or ebpf.CollectionSpec.LoadAndAssign.

func (*N6EntrypointObjects) Close

func (o *N6EntrypointObjects) Close() error

type N6EntrypointPdrInfo added in v0.0.8

type N6EntrypointPdrInfo struct {
	FarId              uint32
	QerId              uint32
	OuterHeaderRemoval uint8
	SdfMode            uint8

	SdfRules struct {
		SdfFilter struct {
			SrcAddr struct {
				Type uint8

				Ip   [16]byte /* uint128 */
				Mask [16]byte /* uint128 */
				// contains filtered or unexported fields
			}
			DstAddr struct {
				Type uint8

				Ip   [16]byte /* uint128 */
				Mask [16]byte /* uint128 */
				// contains filtered or unexported fields
			}
			SrcPort struct {
				LowerBound uint16
				UpperBound uint16
				// contains filtered or unexported fields
			}
			DstPort struct {
				LowerBound uint16
				UpperBound uint16
				// contains filtered or unexported fields
			}
			Protocol uint8
			// contains filtered or unexported fields
		}
		OuterHeaderRemoval uint8

		FarId uint32
		QerId uint32
		// contains filtered or unexported fields
	}
	// contains filtered or unexported fields
}

func CombineN6PdrWithSdf added in v0.0.8

func CombineN6PdrWithSdf(defaultPdr *N6EntrypointPdrInfo, sdfPdr PdrInfo) N6EntrypointPdrInfo

func PreprocessN6PdrWithSdf added in v0.0.8

func PreprocessN6PdrWithSdf(lookup func(interface{}, interface{}) error, key interface{}, pdrInfo PdrInfo) (N6EntrypointPdrInfo, error)

func ToN6EntrypointPdrInfo added in v0.0.8

func ToN6EntrypointPdrInfo(defaultPdr PdrInfo) N6EntrypointPdrInfo

type N6EntrypointProgramSpecs

type N6EntrypointProgramSpecs struct {
	UpfN6EntrypointFunc *ebpf.ProgramSpec `ebpf:"upf_n6_entrypoint_func"`
}

N6EntrypointProgramSpecs contains programs before they are loaded into the kernel.

It can be passed ebpf.CollectionSpec.Assign.

type N6EntrypointPrograms

type N6EntrypointPrograms struct {
	UpfN6EntrypointFunc *ebpf.Program `ebpf:"upf_n6_entrypoint_func"`
}

N6EntrypointPrograms contains all programs after they have been loaded into the kernel.

It can be passed to LoadN6EntrypointObjects or ebpf.CollectionSpec.LoadAndAssign.

func (*N6EntrypointPrograms) Close

func (p *N6EntrypointPrograms) Close() error

type N6EntrypointQerInfo added in v0.0.8

type N6EntrypointQerInfo struct {
	UlGateStatus uint8
	DlGateStatus uint8
	Qfi          uint8

	UlMaximumBitrate uint32
	DlMaximumBitrate uint32

	UlStart uint64
	DlStart uint64
	// contains filtered or unexported fields
}

type N6EntrypointRouteStat added in v0.0.8

type N6EntrypointRouteStat struct {
	FibLookupIp4Cache     uint64
	FibLookupIp4Ok        uint64
	FibLookupIp4ErrorDrop uint64
	FibLookupIp4ErrorPass uint64
	FibLookupIp6Cache     uint64
	FibLookupIp6Ok        uint64
	FibLookupIp6ErrorDrop uint64
	FibLookupIp6ErrorPass uint64
	// contains filtered or unexported fields
}

type N6EntrypointSpecs

N6EntrypointSpecs contains maps and programs before they are loaded into the kernel.

It can be passed ebpf.CollectionSpec.Assign.

type N6EntrypointUpfStatistic added in v0.3.0

type N6EntrypointUpfStatistic struct {
	UpfCounters struct {
		Bytes uint64
		// contains filtered or unexported fields
	}
	UpfCounter struct {
		Rx uint64
		Tx uint64
		// contains filtered or unexported fields
	}
	XdpActions [8]uint64
	// contains filtered or unexported fields
}

type N6EntrypointVariableSpecs added in v0.0.7

type N6EntrypointVariableSpecs struct {
	Masquerade *ebpf.VariableSpec `ebpf:"masquerade"`
}

N6EntrypointVariableSpecs contains global variables before they are loaded into the kernel.

It can be passed ebpf.CollectionSpec.Assign.

type N6EntrypointVariables added in v0.0.7

type N6EntrypointVariables struct {
	Masquerade *ebpf.Variable `ebpf:"masquerade"`
}

N6EntrypointVariables contains all global variables after they have been loaded into the kernel.

It can be passed to LoadN6EntrypointObjects or ebpf.CollectionSpec.LoadAndAssign.

type PdrInfo

type PdrInfo struct {
	OuterHeaderRemoval uint8
	FarID              uint32
	QerID              uint32
	SdfFilter          *SdfFilter
}

type PortRange

type PortRange struct {
	LowerBound uint16
	UpperBound uint16
}

type QerInfo

type QerInfo struct {
	GateStatusUL uint8
	GateStatusDL uint8
	Qfi          uint8
	MaxBitrateUL uint32
	MaxBitrateDL uint32
	StartUL      uint64
	StartDL      uint64
}

type SdfFilter

type SdfFilter struct {
	Protocol     uint8 // 0: icmp, 1: ip, 2: tcp, 3: udp, 4: icmp6
	SrcAddress   IPWMask
	SrcPortRange PortRange
	DstAddress   IPWMask
	DstPortRange PortRange
}

func (*SdfFilter) String

func (sdfFilter *SdfFilter) String() string

type UpfN3Counters added in v0.0.8

type UpfN3Counters struct {
	RxArp      uint64
	RxIcmp     uint64
	RxIcmp6    uint64
	RxIP4      uint64
	RxIP6      uint64
	RxTCP      uint64
	RxUDP      uint64
	RxOther    uint64
	RxGtpEcho  uint64
	RxGtpPdu   uint64
	RxGtpOther uint64
	RxGtpUnexp uint64
	UlBytes    uint64
}

type UpfStatistic

type UpfStatistic struct {
	N3Counters UpfN3Counters
	XdpStats   [5]uint64
}

type UpfXdpActionStatistic

type UpfXdpActionStatistic struct {
	BpfObjects *BpfObjects
}

func (*UpfXdpActionStatistic) GetN3Aborted added in v0.0.8

func (stat *UpfXdpActionStatistic) GetN3Aborted() uint64

func (*UpfXdpActionStatistic) GetN3Drop added in v0.0.8

func (stat *UpfXdpActionStatistic) GetN3Drop() uint64

func (*UpfXdpActionStatistic) GetN3Pass added in v0.0.8

func (stat *UpfXdpActionStatistic) GetN3Pass() uint64

func (*UpfXdpActionStatistic) GetN3Redirect added in v0.0.8

func (stat *UpfXdpActionStatistic) GetN3Redirect() uint64

func (*UpfXdpActionStatistic) GetN3Tx added in v0.0.8

func (stat *UpfXdpActionStatistic) GetN3Tx() uint64

func (*UpfXdpActionStatistic) GetN3UplinkThroughputStats added in v0.0.8

func (stat *UpfXdpActionStatistic) GetN3UplinkThroughputStats() uint64

func (*UpfXdpActionStatistic) GetN6Aborted added in v0.0.8

func (stat *UpfXdpActionStatistic) GetN6Aborted() uint64

func (*UpfXdpActionStatistic) GetN6DownlinkThroughputStats added in v0.0.8

func (stat *UpfXdpActionStatistic) GetN6DownlinkThroughputStats() uint64

func (*UpfXdpActionStatistic) GetN6Drop added in v0.0.8

func (stat *UpfXdpActionStatistic) GetN6Drop() uint64

func (*UpfXdpActionStatistic) GetN6Redirect added in v0.0.8

func (stat *UpfXdpActionStatistic) GetN6Redirect() uint64

func (*UpfXdpActionStatistic) GetN6Tx added in v0.0.8

func (stat *UpfXdpActionStatistic) GetN6Tx() uint64

Jump to

Keyboard shortcuts

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