relaybpf

package
v0.42.0 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2026 License: Apache-2.0 Imports: 10 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package relaybpf loads the eBPF program that forwards the WireGuard transport datagrams of the relay's placed sessions at tc ingress on Linux, and reads and writes its session table and its counters.

The program's source is relay.bpf.c. `make bpf` compiles it with a pinned toolchain into relay_bpfel.o, which is committed, so a build needs no clang. Only the files built for Linux import github.com/cilium/ebpf; this file has no build tag, so the package, and CounterNames with it, exist on every platform.

Index

Constants

This section is empty.

Variables

View Source
var CounterNames = [...]string{"forwarded", "no_session", "mismatch", "fib_fwd_disabled",
	"fib_frag_needed", "fib_no_neigh", "fib_other", "route_changed", "gso"}

CounterNames are the keys Counters returns, in the program's slot order.

Functions

This section is empty.

Types

type Forwarder

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

Forwarder is the loaded program with its maps and the links that attach it to interfaces. Closing it, or the end of the process, detaches the program from every interface: nothing is pinned to bpffs. A Forwarder is not safe for concurrent use; the relay calls it with its own lock held.

func Load

func Load(port uint16, lookupIfindex int) (*Forwarder, error)

Load loads the program into the kernel for a relay that listens on port and routes through the interface with index lookupIfindex, which is the mesh interface. It does not raise RLIMIT_MEMLOCK: the kernels with tcx account BPF memory to the cgroup instead.

Load attaches the program to the loopback interface and detaches it at once, so a kernel without tcx fails here, at the start, with a named error. The session table is still empty then, so the probe forwards nothing.

func (*Forwarder) Age

func (f *Forwarder) Age(index uint32) (time.Duration, bool, error)

Age returns how long ago the program last forwarded a datagram naming index, or Put installed it when none has been forwarded since. It reports false when the table does not hold index.

func (*Forwarder) Ages

func (f *Forwarder) Ages() (map[uint32]time.Duration, error)

Ages returns Age for every index the table holds. It reads the table in batches, which takes a few system calls for a full table where an iteration takes two per entry.

func (*Forwarder) Attach

func (f *Forwarder) Attach(ifindex int) error

Attach attaches the program at tcx ingress of the interface with index ifindex. A second call for the same interface returns nil and attaches nothing more.

func (*Forwarder) Close

func (f *Forwarder) Close() error

Close closes every link, which detaches the program from its interface, then the program and its maps.

func (*Forwarder) Counters

func (f *Forwarder) Counters() (map[string]uint64, error)

Counters returns the program's counters, keyed by CounterNames. Each counter is the sum of its slot over all CPUs.

func (*Forwarder) Delete

func (f *Forwarder) Delete(index uint32) error

Delete removes the session of index. An index the table does not hold is no error.

func (*Forwarder) Put

func (f *Forwarder) Put(index uint32, s Session) error

Put installs s as the session of index, replacing an entry the table already holds for it. The entry counts as used now, so its age starts at 0.

type Session

type Session struct {
	Partner    netip.AddrPort // the datagram's source
	PartnerDst netip.Addr     // the local address the partner sends to
	Owner      netip.AddrPort // the new destination
	OwnerSrc   netip.Addr     // the new source
	OwnerIf    int            // the interface the route to Owner leaves by
}

Session is one entry of the program's session table.

Jump to

Keyboard shortcuts

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