hive

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 22, 2026 License: MPL-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package hive wraps the kernel BPF object lifecycle shared by all terrahive resources: pinning, loading, reading back, and unpinning.

Index

Constants

View Source
const DefaultPinDir = "/sys/fs/bpf/terrahive"

DefaultPinDir is used when the provider block sets no pin_dir.

Variables

This section is empty.

Functions

func CompileC

func CompileC(source string) ([]byte, error)

CompileC compiles BPF C source with the system clang.

func LoadELF

func LoadELF(obj []byte) (*ebpf.ProgramSpec, error)

LoadELF parses a BPF object file and returns its single program spec, with the program type already inferred from the ELF section name.

func ProgramTypeString

func ProgramTypeString(t ebpf.ProgramType) string

ProgramTypeString renders a program type in the lowercase form used by the ebpf_program `type` attribute.

func SourceHash

func SourceHash(data []byte) string

SourceHash fingerprints program source bytes so plans can force replacement when content changes behind a stable path.

Types

type Hive

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

Hive is the handle every resource uses to talk to the kernel.

func New

func New(pinDir string) (*Hive, error)

New validates the environment and returns a Hive rooted at pinDir. It fails if pinDir is not on bpffs or the process lacks BPF privileges, so misconfiguration surfaces at provider configure time, not mid-apply.

func (*Hive) LoadAndPinProgram

func (h *Hive) LoadAndPinProgram(obj []byte, pinPath string) (string, error)

LoadAndPinProgram loads the object's single program together with the maps it references and pins the program, returning the kernel-computed tag. Referenced maps are pinned by name under the hive map directory, so several programs (and an ebpf_map of the same name) share one kernel map through a stable bpffs pin. The object must hold exactly one program; callers gate that with LoadELF.

func (h *Hive) LoadPinnedLink(pinPath string) (link.Link, error)

LoadPinnedLink resolves a pinned link for Read and import.

func (*Hive) LoadPinnedMap

func (h *Hive) LoadPinnedMap(pinPath string) (*ebpf.Map, error)

LoadPinnedMap resolves a pinned map for Read and import.

func (*Hive) LoadPinnedProgram

func (h *Hive) LoadPinnedProgram(pinPath string) (*ebpf.Program, error)

LoadPinnedProgram resolves a pinned program for Read and import.

func (*Hive) PinDir

func (h *Hive) PinDir() string

PinDir returns the root pin directory.

func (*Hive) PinExists

func (h *Hive) PinExists(pinPath string) (bool, error)

PinExists reports whether a pin path resolves, without opening it.

func (h *Hive) PinLink(l link.Link, pinPath string) error

PinLink pins l at pinPath, creating parent directories on bpffs so resources can pin under per-kind subdirectories.

func (*Hive) PinPath

func (h *Hive) PinPath(parts ...string) string

PinPath derives the bpffs pin path that doubles as the Terraform resource ID. Parts typically encode kind and resource name.

func (*Hive) PinnedProgramInfo

func (h *Hive) PinnedProgramInfo(pinPath string) (typ, tag string, err error)

PinnedProgramInfo returns the type and tag of a pinned program.

func (*Hive) Unpin

func (h *Hive) Unpin(pinPath string) error

Unpin removes a pin, dropping the last user-visible reference. A missing pin is not an error: destroy must be idempotent.

type USDT

type USDT struct {
	// Address is the probe location as an offset into the executable
	// file, ready for a uprobe attach.
	Address uint64
	// SemaphoreOffset is the file offset of the probe semaphore, zero
	// when the probe has none.
	SemaphoreOffset uint64
}

USDT locates a statically defined tracepoint inside an executable.

func ResolveUSDT

func ResolveUSDT(path, provider, name string) (*USDT, error)

ResolveUSDT parses the .note.stapsdt section of the executable at path and returns the location of the probe identified by provider and name. terrahive resolves the note itself and attaches a plain uprobe at the resulting offset.

Directories

Path Synopsis
Package tinygo extracts a bundled TinyGo toolchain to a local cache directory and compiles BPF Go source with it.
Package tinygo extracts a bundled TinyGo toolchain to a local cache directory and compiles BPF Go source with it.

Jump to

Keyboard shortcuts

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