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 ¶
- Variables
- type Forwarder
- func (f *Forwarder) Age(index uint32) (time.Duration, bool, error)
- func (f *Forwarder) Ages() (map[uint32]time.Duration, error)
- func (f *Forwarder) Attach(ifindex int) error
- func (f *Forwarder) Close() error
- func (f *Forwarder) Counters() (map[string]uint64, error)
- func (f *Forwarder) Delete(index uint32) error
- func (f *Forwarder) Put(index uint32, s Session) error
- type Session
Constants ¶
This section is empty.
Variables ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
Close closes every link, which detaches the program from its interface, then the program and its maps.
func (*Forwarder) Counters ¶
Counters returns the program's counters, keyed by CounterNames. Each counter is the sum of its slot over all CPUs.
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.