bpf

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jun 4, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

README

bpf

libbpf for Go, transpiled, CGo-free.

Can be built with CGO_ENABLED=0 and does not need a system libbpf, libelf, zlib, pkg-config, C compiler, or dynamic C library for ordinary Go builds.

The module exposes two packages:

  • go.dw1.io/bpf: the Go API for object, map, program, link, BTF, buffer, skeleton, and low-level libbpf workflows.
  • go.dw1.io/bpf/abi: the low-level generated libbpf ABI for generated packages and advanced interop.

Generated ABI output is checked in. Users do not need to run the generator to import the module.

Status

This repository currently generates ABI files for:

  • linux/amd64
  • linux/arm64

Other targets fail clearly from go.dw1.io/bpf/abi instead of silently using a different implementation.

The checked-in source baseline is upstream libbpf v1.7.0 at commit f5dcbae736e5d7f83a35718e01be1a8e3010fa39.

The root package is intended for Go application code that wants libbpf-style loading and attachment without cgo. It is not an eBPF bytecode compiler. Runtime operations still use kernel BPF facilities, so loading programs, attaching links, pinning objects, or changing network hooks can require privileges such as CAP_BPF, CAP_NET_ADMIN, CAP_SYS_ADMIN, or root depending on the kernel and operation.

The module is pre-v1. Public APIs should be treated as usable but still subject to compatibility cleanup before a stable release.

Install

go get go.dw1.io/bpf

Opening Objects

Open ELF object files with OpenObjectFile or in-memory object bytes with OpenObjectMem:

package main

import (
	"fmt"

	"go.dw1.io/bpf"
)

func main() {
	obj, err := bpf.OpenObjectFile("program.bpf.o", bpf.ObjectOptions{})
	if err != nil {
		panic(err)
	}
	defer obj.Close()

	prog, err := obj.Program("handle_packet")
	if err != nil {
		panic(err)
	}

	fmt.Println(prog.Name(), prog.SectionName())

	if err := obj.Load(); err != nil {
		panic(err)
	}
}

Object exposes loaded maps, programs, BTF, kernel logs, pinning helpers, and access to the wrapped generated ABI handle when lower-level interop is required.

Programs expose libbpf attachment workflows as Go methods:

obj, err := bpf.OpenObjectFile("trace.bpf.o", bpf.ObjectOptions{})
if err != nil {
	panic(err)
}
defer obj.Close()

if err := obj.Load(); err != nil {
	panic(err)
}

prog, err := obj.Program("trace_openat")
if err != nil {
	panic(err)
}

link, err := prog.AttachTracepoint("syscalls", "sys_enter_openat")
if err != nil {
	panic(err)
}
defer link.Close()

Available attachment helpers include kprobes, uprobes, tracepoints, raw tracepoints, perf events, cgroups, XDP, TCX, netfilter, netkit, LSM, struct_ops, USDT, and libbpf's generic auto-attach path.

Maps

Maps can be discovered from an opened object and manipulated through Go-shaped methods:

cfg, err := obj.Map("config")
if err != nil {
	panic(err)
}

key := make([]byte, cfg.KeySize())
value := make([]byte, cfg.ValueSize())
copy(value, []byte{1})

if err := cfg.Update(key, value, bpf.UpdateAny); err != nil {
	panic(err)
}

current, err := cfg.Lookup(key, 0)
if err != nil {
	panic(err)
}
_ = current

The package also exposes lower-level helpers such as CreateMap, LookupMapElement, and UpdateMapElement for code that works directly with file descriptors.

Ring Buffers

Ring-buffer callbacks receive a borrowed view into libbpf-owned memory. Copy the sample if it needs to outlive the callback:

events, err := obj.Map("events")
if err != nil {
	panic(err)
}

rb, err := bpf.NewRingBuffer(events.FD(), func(sample bpf.RingBufferSample) error {
	data := append([]byte(nil), sample.Data...)
	_ = data
	return nil
})
if err != nil {
	panic(err)
}
defer rb.Close()

if _, err := rb.Poll(100); err != nil {
	panic(err)
}

Perf buffers, raw perf buffers, and user ring buffers are available through the same root package.

BTF

The root package includes BTF construction, parsing, kernel loading, lookup, and mutation helpers:

btf, err := bpf.LoadKernelBTF()
if err != nil {
	panic(err)
}
defer btf.Close()

_ = btf.TypeCount()

Use ParseBTFFile, ParseBTFELF, LoadKernelBTF, and related helpers for BTF workflows. BTFDump wraps libbpf's C declaration dumping APIs.

Raw ABI Package

go.dw1.io/bpf/abi exposes the generated libbpf-like ABI. It is intentionally version-coupled to the pinned upstream source and uses ccgo/modernc runtime conventions.

Application code should prefer the root package. Generated packages or systems code that need raw libbpf symbols can depend on go.dw1.io/bpf/abi instead of carrying a private libbpf copy.

Generation

The generator lives in internal/cmd/genbpf and is wired through go generate:

go generate ./...

The generated package includes:

  • abi/libbpf_linux_amd64.go
  • abi/libbpf_linux_arm64.go
  • abi/SOURCE-MANIFEST.txt
  • abi/SYMBOLS.txt
  • abi/BEHAVIOR-COVERAGE.txt
  • ABI option, record, callback, skeleton, and symbol tests
  • unsupported-target build failure stubs

SOURCE-MANIFEST.txt records the libbpf source commit, selected headers and sources, target list, source adjustments, local bridge files, upstream license inputs, generated files, and ccgo/modernc tool versions. SYMBOLS.txt records the public libbpf symbols expected in the ABI package. BEHAVIOR-COVERAGE.txt records which libbpf exports are implemented through root-package workflows, root low-level helpers, or ABI-only support.

Check that committed generated output is current with:

go run ./internal/cmd/genbpf -check

Verification

Useful local checks:

make check
go test ./...
CGO_ENABLED=0 go test ./...
go run ./internal/cmd/genbpf -check

make check runs the generator freshness check, the regular Go test suite, and the CGO_ENABLED=0 test suite. Some runtime behavior depends on the local Linux kernel and available BPF privileges.

License

This module is licensed under the Apache License, Version 2.0. See the LICENSE.

Documentation

Overview

Package bpf exposes Go-native, cgo-free libbpf workflows.

Index

Constants

View Source
const (
	UpdateAny     uint64 = abi.BPF_ANY
	UpdateNoExist uint64 = abi.BPF_NOEXIST
	UpdateExist   uint64 = abi.BPF_EXIST
	UpdateLock    uint64 = abi.BPF_F_LOCK
)
View Source
const (
	BTFIntSigned int32 = abi.BTF_INT_SIGNED
	BTFIntChar   int32 = abi.BTF_INT_CHAR
	BTFIntBool   int32 = abi.BTF_INT_BOOL
)

Variables

View Source
var (
	ErrClosed   = errors.New("bpf: closed handle")
	ErrNotFound = errors.New("bpf: not found")
)

Functions

func AssociateProgramStructOps

func AssociateProgramStructOps(progFD, mapFD int, opts StructOpsAssociationOptions) error

func AttachProgram

func AttachProgram(progFD, targetFD int, attachType AttachType, flags uint32) error

func AttachProgramWithOptions

func AttachProgramWithOptions(progFD, targetFD int, attachType AttachType, opts ProgramAttachOptions) error

func BTFFDByID

func BTFFDByID(id uint32) (int, error)

func BTFFDByIDWithOptions

func BTFFDByIDWithOptions(id uint32, opts GetFDByIDOptions) (int, error)

func BTFInfoByFD

func BTFInfoByFD(fd int, info []byte) (uint32, error)

func BindProgramMap

func BindProgramMap(progFD, mapFD int) error

func BindProgramMapWithOptions

func BindProgramMapWithOptions(progFD, mapFD int, opts ProgramBindOptions) error

func CreateIterator

func CreateIterator(linkFD int) (int, error)
func CreateLink(progFD, targetFD int, attachType AttachType) (int, error)

func CreateMap

func CreateMap(opts MapCreateOptions) (int, error)

func CreateTCHook

func CreateTCHook(hook TCHook) error

func CreateToken

func CreateToken(bpffsFD int) (int, error)

func CreateTokenWithOptions

func CreateTokenWithOptions(bpffsFD int, opts TokenCreateOptions) (int, error)

func DeleteMapBatch

func DeleteMapBatch(fd int, keys []byte, opts MapBatchDeleteOptions) (uint32, error)

func DeleteMapElement

func DeleteMapElement(fd int, key []byte, flags uint64) error

func DestroyTCHook

func DestroyTCHook(hook TCHook) error

func DetachLinkFD

func DetachLinkFD(linkFD int) error

func DetachProgram

func DetachProgram(targetFD int, attachType AttachType) error

func DetachProgram2

func DetachProgram2(progFD, targetFD int, attachType AttachType) error

func DetachProgramWithOptions

func DetachProgramWithOptions(progFD, targetFD int, attachType AttachType, opts ProgramDetachOptions) error

func DistillBase

func DistillBase(src, newBase, newSplit *BTF) error

func EnableStats

func EnableStats(statsType StatsType) (int, error)

func ErrorString

func ErrorString(code int) (string, error)

func FindVmlinuxBTFID

func FindVmlinuxBTFID(name string, attachType AttachType) (int, error)

func FreezeMap

func FreezeMap(fd int) error

func LinkFDByID

func LinkFDByID(id uint32) (int, error)

func LinkFDByIDWithOptions

func LinkFDByIDWithOptions(id uint32, opts GetFDByIDOptions) (int, error)

func LinkInfoByFD

func LinkInfoByFD(fd int, info []byte) (uint32, error)

func LoadBTF

func LoadBTF(data []byte) (int, error)

func LoadProgram

func LoadProgram(opts ProgramLoadOptions) (int, error)

func LoadRawBTF

func LoadRawBTF(types, strings []byte, tokenFD int) (int, error)

func LookupAndDeleteMapElement

func LookupAndDeleteMapElement(fd int, key []byte, valueSize int, flags uint64) ([]byte, error)

func LookupMapElement

func LookupMapElement(fd int, key []byte, valueSize int, flags uint64) ([]byte, error)

func MajorVersion

func MajorVersion() uint32

func MapFDByID

func MapFDByID(id uint32) (int, error)

func MapFDByIDWithOptions

func MapFDByIDWithOptions(id uint32, opts GetFDByIDOptions) (int, error)

func MapInfoByFD

func MapInfoByFD(fd int, info []byte) (uint32, error)

func MinorVersion

func MinorVersion() uint32

func NextBTFID

func NextBTFID(startID uint32) (uint32, error)

func NextLinkID

func NextLinkID(startID uint32) (uint32, error)

func NextMapID

func NextMapID(startID uint32) (uint32, error)

func NextMapKey

func NextMapKey(fd int, current []byte, keySize int) ([]byte, error)

func NextProgramID

func NextProgramID(startID uint32) (uint32, error)

func NumPossibleCPUs

func NumPossibleCPUs() (int, error)

func ObjectInfoByFD

func ObjectInfoByFD(fd int, info []byte) (uint32, error)

func OpenPinnedObject

func OpenPinnedObject(path string) (int, error)

func OpenPinnedObjectWithOptions

func OpenPinnedObjectWithOptions(path string, opts ObjectGetOptions) (int, error)

func OpenRawTracepoint

func OpenRawTracepoint(name string, progFD int) (int, error)

func OpenRawTracepointWithOptions

func OpenRawTracepointWithOptions(name string, progFD int, opts RawTracepointOptions) (int, error)

func PinObject

func PinObject(fd int, path string) error

func PinObjectWithOptions

func PinObjectWithOptions(fd int, path string, opts ObjectPinOptions) error

func ProbeHelper

func ProbeHelper(programType ProgramType, helper HelperID) (bool, error)

func ProbeMapType

func ProbeMapType(t MapType) (bool, error)

func ProbeProgramType

func ProbeProgramType(t ProgramType) (bool, error)

func ProgramFDByID

func ProgramFDByID(id uint32) (int, error)

func ProgramFDByIDWithOptions

func ProgramFDByIDWithOptions(id uint32, opts GetFDByIDOptions) (int, error)

func ProgramInfoByFD

func ProgramInfoByFD(fd int, info []byte) (uint32, error)

func ProgramStreamRead

func ProgramStreamRead(progFD int, streamID uint32, buf []byte) (int, error)

func ProgramTypeByName

func ProgramTypeByName(name string) (ProgramType, AttachType, error)

func SetLogger

func SetLogger(logger Logger)

SetLogger installs a process-wide libbpf logger. Passing nil disables libbpf logging through this package.

func SetMemlockRlimit

func SetMemlockRlimit(bytes uint64) error

func SetStrictMode

func SetStrictMode(mode StrictMode) error

func TCDetach

func TCDetach(hook TCHook, opts TCOptions) error

func TCParent

func TCParent(major, minor uint32) uint32

func UpdateLinkFD

func UpdateLinkFD(linkFD, newProgramFD int) error

func UpdateLinkFDWithOptions

func UpdateLinkFDWithOptions(linkFD, newProgramFD int, opts LinkUpdateOptions) error

func UpdateMapBatch

func UpdateMapBatch(fd int, keys, values []byte, opts MapBatchUpdateOptions) (uint32, error)

func UpdateMapElement

func UpdateMapElement(fd int, key, value []byte, flags uint64) error

func VersionString

func VersionString() string

func XDPAttach

func XDPAttach(ifindex, progFD int, flags uint32) error

func XDPDetach

func XDPDetach(ifindex int, flags uint32) error

func XDPQueryID

func XDPQueryID(ifindex int, flags int) (uint32, error)

Types

type AttachType

type AttachType int32
const (
	AttachCgroupInetIngress  AttachType = abi.BPF_CGROUP_INET_INGRESS
	AttachCgroupInetEgress   AttachType = abi.BPF_CGROUP_INET_EGRESS
	AttachTraceRawTracepoint AttachType = abi.BPF_TRACE_RAW_TP
	AttachTraceFEntry        AttachType = abi.BPF_TRACE_FENTRY
	AttachTraceFExit         AttachType = abi.BPF_TRACE_FEXIT
	AttachModifyReturn       AttachType = abi.BPF_MODIFY_RETURN
	AttachLSMMac             AttachType = abi.BPF_LSM_MAC
	AttachTraceIterator      AttachType = abi.BPF_TRACE_ITER
	AttachXDP                AttachType = abi.BPF_XDP
	AttachPerfEvent          AttachType = abi.BPF_PERF_EVENT
	AttachTraceKprobeMulti   AttachType = abi.BPF_TRACE_KPROBE_MULTI
	AttachStructOps          AttachType = abi.BPF_STRUCT_OPS
	AttachNetfilter          AttachType = abi.BPF_NETFILTER
	AttachTCXIngress         AttachType = abi.BPF_TCX_INGRESS
	AttachTCXEgress          AttachType = abi.BPF_TCX_EGRESS
	AttachTraceUprobeMulti   AttachType = abi.BPF_TRACE_UPROBE_MULTI
	AttachNetkitPrimary      AttachType = abi.BPF_NETKIT_PRIMARY
	AttachNetkitPeer         AttachType = abi.BPF_NETKIT_PEER
)

func AttachTypeByName

func AttachTypeByName(name string) (AttachType, error)

func (AttachType) String

func (t AttachType) String() string

type BTF

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

func BTFByFD

func BTFByFD(fd int) (*BTF, error)

func LoadBTFByID

func LoadBTFByID(id uint32) (*BTF, error)

func LoadKernelBTF

func LoadKernelBTF() (*BTF, error)

func LoadModuleBTF

func LoadModuleBTF(module string, vmlinux *BTF) (*BTF, error)

func LoadSplitBTFByID

func LoadSplitBTFByID(id uint32, base *BTF) (*BTF, error)

func NewBTF

func NewBTF() (*BTF, error)

func NewBTFBytes

func NewBTFBytes(data []byte) (*BTF, error)

func NewBTFSplit

func NewBTFSplit(base *BTF) (*BTF, error)

func NewBTFSplitBytes

func NewBTFSplitBytes(data []byte, base *BTF) (*BTF, error)

func ParseBTFELF

func ParseBTFELF(path string) (*BTF, error)

func ParseBTFELFSplit

func ParseBTFELFSplit(path string, base *BTF) (*BTF, error)

func ParseBTFFile

func ParseBTFFile(path string) (*BTF, error)

func ParseBTFRaw

func ParseBTFRaw(path string) (*BTF, error)

func ParseBTFRawSplit

func ParseBTFRawSplit(path string, base *BTF) (*BTF, error)

func ParseBTFSplit

func ParseBTFSplit(path string, base *BTF) (*BTF, error)

func (*BTF) ABIHandle

func (b *BTF) ABIHandle() abi.BTFHandle

func (*BTF) AddArray

func (b *BTF) AddArray(indexTypeID, elemTypeID int, elements uint32) (int, error)

func (*BTF) AddConst

func (b *BTF) AddConst(refTypeID int) (int, error)

func (*BTF) AddDataSec

func (b *BTF) AddDataSec(name string, byteSize uint32) (int, error)

func (*BTF) AddDataSecVarInfo

func (b *BTF) AddDataSecVarInfo(varTypeID int, offset, byteSize uint32) (int, error)

func (*BTF) AddDeclAttr

func (b *BTF) AddDeclAttr(value string, refTypeID, componentIndex int) (int, error)

func (*BTF) AddDeclTag

func (b *BTF) AddDeclTag(value string, refTypeID, componentIndex int) (int, error)

func (*BTF) AddEnum

func (b *BTF) AddEnum(name string, byteSize uint32) (int, error)

func (*BTF) AddEnum64

func (b *BTF) AddEnum64(name string, byteSize uint32, signed bool) (int, error)

func (*BTF) AddEnum64Value

func (b *BTF) AddEnum64Value(name string, value uint64) (int, error)

func (*BTF) AddEnumValue

func (b *BTF) AddEnumValue(name string, value int64) (int, error)

func (*BTF) AddField

func (b *BTF) AddField(name string, typeID int, bitOffset, bitSize uint32) (int, error)

func (*BTF) AddFloat

func (b *BTF) AddFloat(name string, byteSize uint64) (int, error)

func (*BTF) AddForward

func (b *BTF) AddForward(name string, kind BTFFwdKind) (int, error)

func (*BTF) AddFunc

func (b *BTF) AddFunc(name string, linkage BTFFuncLinkage, protoTypeID int) (int, error)

func (*BTF) AddFuncParam

func (b *BTF) AddFuncParam(name string, typeID int) (int, error)

func (*BTF) AddFuncProto

func (b *BTF) AddFuncProto(retTypeID int) (int, error)

func (*BTF) AddInt

func (b *BTF) AddInt(name string, byteSize uint64, encoding int32) (int, error)

func (*BTF) AddPointer

func (b *BTF) AddPointer(refTypeID int) (int, error)

func (*BTF) AddRestrict

func (b *BTF) AddRestrict(refTypeID int) (int, error)

func (*BTF) AddString

func (b *BTF) AddString(s string) (int, error)

func (*BTF) AddStruct

func (b *BTF) AddStruct(name string, byteSize uint32) (int, error)

func (*BTF) AddTypeAttr

func (b *BTF) AddTypeAttr(value string, refTypeID int) (int, error)

func (*BTF) AddTypeFrom

func (b *BTF) AddTypeFrom(src *BTF, typeID uint32) (int, error)

func (*BTF) AddTypeTag

func (b *BTF) AddTypeTag(value string, refTypeID int) (int, error)

func (*BTF) AddTypedef

func (b *BTF) AddTypedef(name string, refTypeID int) (int, error)

func (*BTF) AddUnion

func (b *BTF) AddUnion(name string, byteSize uint32) (int, error)

func (*BTF) AddVar

func (b *BTF) AddVar(name string, linkage int32, typeID int) (int, error)

func (*BTF) AddVolatile

func (b *BTF) AddVolatile(refTypeID int) (int, error)

func (*BTF) AlignOf

func (b *BTF) AlignOf(typeID uint32) (int, error)

func (*BTF) Append

func (b *BTF) Append(src *BTF) (int, error)

func (*BTF) Base

func (b *BTF) Base() *BTF

func (*BTF) Close

func (b *BTF) Close() error

func (*BTF) Dedup

func (b *BTF) Dedup() error

func (*BTF) Endianness

func (b *BTF) Endianness() BTFEndianness

func (*BTF) FD

func (b *BTF) FD() int

func (*BTF) FindByName

func (b *BTF) FindByName(name string) (int, error)

func (*BTF) FindByNameKind

func (b *BTF) FindByNameKind(name string, kind BTFKind) (int, error)

func (*BTF) FindString

func (b *BTF) FindString(s string) (int, error)

func (*BTF) LoadIntoKernel

func (b *BTF) LoadIntoKernel() error

func (*BTF) NameByOffset

func (b *BTF) NameByOffset(offset uint32) string

func (*BTF) Permute

func (b *BTF) Permute(idMap []uint32, opts BTFPermuteOptions) error

func (*BTF) PointerSize

func (b *BTF) PointerSize() uint64

func (*BTF) RawData

func (b *BTF) RawData() []byte

func (*BTF) Relocate

func (b *BTF) Relocate(base *BTF) error

func (*BTF) ResolveSize

func (b *BTF) ResolveSize(typeID uint32) (int64, error)

func (*BTF) ResolveType

func (b *BTF) ResolveType(typeID uint32) (int, error)

func (*BTF) SetEndianness

func (b *BTF) SetEndianness(endian BTFEndianness) error

func (*BTF) SetFD

func (b *BTF) SetFD(fd int) error

func (*BTF) SetPointerSize

func (b *BTF) SetPointerSize(size uint64) error

func (*BTF) StringByOffset

func (b *BTF) StringByOffset(offset uint32) string

func (*BTF) TypeByID

func (b *BTF) TypeByID(typeID uint32) (BTFType, error)

func (*BTF) TypeCount

func (b *BTF) TypeCount() uint32

type BTFDump

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

func NewBTFDump

func NewBTFDump(btf *BTF, w io.Writer) (*BTFDump, error)

NewBTFDump creates a BTF dump handle that writes rendered text to w. The BTF handle is borrowed by libbpf and must remain open until the dump is closed.

func (*BTFDump) Close

func (d *BTFDump) Close() error

func (*BTFDump) DumpType

func (d *BTFDump) DumpType(typeID uint32) error

func (*BTFDump) DumpTypeData

func (d *BTFDump) DumpTypeData(typeID uint32, data []byte, opts BTFTypeDataOptions) error

func (*BTFDump) EmitTypeDeclaration

func (d *BTFDump) EmitTypeDeclaration(typeID uint32, opts BTFTypeDeclarationOptions) error

type BTFEndianness

type BTFEndianness int32
const (
	BTFLittleEndian BTFEndianness = abi.BTF_LITTLE_ENDIAN
	BTFBigEndian    BTFEndianness = abi.BTF_BIG_ENDIAN
)

type BTFExt

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

func NewBTFExt

func NewBTFExt(data []byte) (*BTFExt, error)

func (*BTFExt) Close

func (e *BTFExt) Close() error

func (*BTFExt) Endianness

func (e *BTFExt) Endianness() BTFEndianness

func (*BTFExt) RawData

func (e *BTFExt) RawData() []byte

func (*BTFExt) SetEndianness

func (e *BTFExt) SetEndianness(endian BTFEndianness) error

type BTFFuncLinkage

type BTFFuncLinkage int32
const (
	BTFFuncStatic BTFFuncLinkage = abi.BTF_FUNC_STATIC
	BTFFuncGlobal BTFFuncLinkage = abi.BTF_FUNC_GLOBAL
	BTFFuncExtern BTFFuncLinkage = abi.BTF_FUNC_EXTERN
)

type BTFFwdKind

type BTFFwdKind int32
const (
	BTFFwdStruct BTFFwdKind = abi.BTF_FWD_STRUCT
	BTFFwdUnion  BTFFwdKind = abi.BTF_FWD_UNION
	BTFFwdEnum   BTFFwdKind = abi.BTF_FWD_ENUM
)

type BTFKind

type BTFKind uint32
const (
	BTFKindUnknown   BTFKind = abi.BTF_KIND_UNKN
	BTFKindInt       BTFKind = abi.BTF_KIND_INT
	BTFKindPointer   BTFKind = abi.BTF_KIND_PTR
	BTFKindArray     BTFKind = abi.BTF_KIND_ARRAY
	BTFKindStruct    BTFKind = abi.BTF_KIND_STRUCT
	BTFKindUnion     BTFKind = abi.BTF_KIND_UNION
	BTFKindEnum      BTFKind = abi.BTF_KIND_ENUM
	BTFKindForward   BTFKind = abi.BTF_KIND_FWD
	BTFKindTypedef   BTFKind = abi.BTF_KIND_TYPEDEF
	BTFKindVolatile  BTFKind = abi.BTF_KIND_VOLATILE
	BTFKindConst     BTFKind = abi.BTF_KIND_CONST
	BTFKindRestrict  BTFKind = abi.BTF_KIND_RESTRICT
	BTFKindFunc      BTFKind = abi.BTF_KIND_FUNC
	BTFKindFuncProto BTFKind = abi.BTF_KIND_FUNC_PROTO
	BTFKindVar       BTFKind = abi.BTF_KIND_VAR
	BTFKindDataSec   BTFKind = abi.BTF_KIND_DATASEC
	BTFKindFloat     BTFKind = abi.BTF_KIND_FLOAT
	BTFKindDeclTag   BTFKind = abi.BTF_KIND_DECL_TAG
	BTFKindTypeTag   BTFKind = abi.BTF_KIND_TYPE_TAG
	BTFKindEnum64    BTFKind = abi.BTF_KIND_ENUM64
)

type BTFPermuteOptions

type BTFPermuteOptions struct {
	Ext *BTFExt
}

type BTFType

type BTFType struct {
	ID         uint32
	Name       string
	NameOffset uint32
	Kind       BTFKind
	ValueCount uint32
	KindFlag   bool
	Size       uint32
	TypeID     uint32
}

type BTFTypeDataOptions

type BTFTypeDataOptions struct {
	Indent      string
	IndentLevel int
	Compact     bool
	SkipNames   bool
	EmitZeroes  bool
	EmitStrings bool
}

type BTFTypeDeclarationOptions

type BTFTypeDeclarationOptions struct {
	FieldName      string
	IndentLevel    int
	StripModifiers bool
}

type CgroupOptions

type CgroupOptions struct {
	Flags            uint32
	RelativeFD       uint32
	RelativeID       uint32
	ExpectedRevision uint64
}

type Error

type Error struct {
	Op       string
	Errno    syscall.Errno
	Message  string
	Path     string
	Name     string
	Callback string
	FD       int
}

func (*Error) Error

func (e *Error) Error() string

func (*Error) Unwrap

func (e *Error) Unwrap() error

type FuncInfo

type FuncInfo struct {
	InstructionOffset uint32
	TypeID            uint32
}

type GetFDByIDOptions

type GetFDByIDOptions struct {
	OpenFlags uint32
	TokenFD   uint32
}

type HandleOwnership

type HandleOwnership int
const (
	BorrowHandle HandleOwnership = iota
	OwnHandle
)

type HelperID

type HelperID int32

type KprobeOptions

type KprobeOptions struct {
	Cookie     uint64
	Offset     uint64
	Retprobe   bool
	AttachMode ProbeAttachMode
}

type LineInfo

type LineInfo struct {
	InstructionOffset uint32
	FileNameOffset    uint32
	LineOffset        uint32
	LineColumn        uint32
}
type Link struct {
	// contains filtered or unexported fields
}
func OpenLink(path string) (*Link, error)

func (*Link) ABIHandle

func (l *Link) ABIHandle() abi.LinkHandle

func (*Link) Close

func (l *Link) Close() error

func (*Link) Destroy

func (l *Link) Destroy() error

func (*Link) Detach

func (l *Link) Detach() error

func (*Link) Disconnect

func (l *Link) Disconnect()

func (*Link) FD

func (l *Link) FD() int

func (*Link) Pin

func (l *Link) Pin(path string) error

func (*Link) PinPath

func (l *Link) PinPath() string

func (*Link) Unpin

func (l *Link) Unpin() error

func (*Link) UpdateMap

func (l *Link) UpdateMap(m *Map) error

func (*Link) UpdateProgram

func (l *Link) UpdateProgram(prog *Program) error

type LinkType

type LinkType int32
const (
	LinkTypeUnspec        LinkType = abi.BPF_LINK_TYPE_UNSPEC
	LinkTypeRawTracepoint LinkType = abi.BPF_LINK_TYPE_RAW_TRACEPOINT
	LinkTypeTracing       LinkType = abi.BPF_LINK_TYPE_TRACING
	LinkTypeCgroup        LinkType = abi.BPF_LINK_TYPE_CGROUP
	LinkTypeIterator      LinkType = abi.BPF_LINK_TYPE_ITER
	LinkTypeNetNS         LinkType = abi.BPF_LINK_TYPE_NETNS
	LinkTypeXDP           LinkType = abi.BPF_LINK_TYPE_XDP
	LinkTypePerfEvent     LinkType = abi.BPF_LINK_TYPE_PERF_EVENT
	LinkTypeKprobeMulti   LinkType = abi.BPF_LINK_TYPE_KPROBE_MULTI
	LinkTypeStructOps     LinkType = abi.BPF_LINK_TYPE_STRUCT_OPS
	LinkTypeNetfilter     LinkType = abi.BPF_LINK_TYPE_NETFILTER
	LinkTypeTCX           LinkType = abi.BPF_LINK_TYPE_TCX
	LinkTypeUprobeMulti   LinkType = abi.BPF_LINK_TYPE_UPROBE_MULTI
	LinkTypeNetkit        LinkType = abi.BPF_LINK_TYPE_NETKIT
	LinkTypeSockMap       LinkType = abi.BPF_LINK_TYPE_SOCKMAP
)

func (LinkType) String

func (t LinkType) String() string

type LinkUpdateOptions

type LinkUpdateOptions struct {
	Flags        uint32
	OldProgramFD int
	OldMapFD     int
}

type Linker

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

func NewLinker

func NewLinker(path string) (*Linker, error)

func NewLinkerFD

func NewLinkerFD(fd int) (*Linker, error)

func (*Linker) AddBuffer

func (l *Linker) AddBuffer(data []byte) error

func (*Linker) AddFD

func (l *Linker) AddFD(fd int) error

func (*Linker) AddFile

func (l *Linker) AddFile(path string) error

func (*Linker) Close

func (l *Linker) Close() error

func (*Linker) Finalize

func (l *Linker) Finalize() error

type LogLevel

type LogLevel int32

LogLevel is a libbpf log severity.

const (
	LogLevelWarn  LogLevel = abi.LIBBPF_WARN
	LogLevelInfo  LogLevel = abi.LIBBPF_INFO
	LogLevelDebug LogLevel = abi.LIBBPF_DEBUG
)

func (LogLevel) String

func (level LogLevel) String() string

type Logger

type Logger interface {
	Log(level LogLevel, message string)
}

Logger receives rendered libbpf log messages.

type LoggerFunc

type LoggerFunc func(LogLevel, string)

LoggerFunc adapts a function to Logger.

func (LoggerFunc) Log

func (fn LoggerFunc) Log(level LogLevel, message string)

type Map

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

func (*Map) ABIHandle

func (m *Map) ABIHandle() abi.MapHandle

func (*Map) AttachStructOps

func (m *Map) AttachStructOps() (*Link, error)

func (*Map) Autoattach

func (m *Map) Autoattach() bool

func (*Map) Autocreate

func (m *Map) Autocreate() bool

func (*Map) BTFKeyTypeID

func (m *Map) BTFKeyTypeID() uint32

func (*Map) BTFValueTypeID

func (m *Map) BTFValueTypeID() uint32

func (*Map) Delete

func (m *Map) Delete(key []byte, flags uint64) error

func (*Map) ExclusiveProgram

func (m *Map) ExclusiveProgram() *Program

func (*Map) Extra

func (m *Map) Extra() uint64

func (*Map) FD

func (m *Map) FD() int

func (*Map) Flags

func (m *Map) Flags() uint32

func (*Map) Ifindex

func (m *Map) Ifindex() uint32

func (*Map) InitialValue

func (m *Map) InitialValue() []byte

func (*Map) InnerMap

func (m *Map) InnerMap() *Map

func (*Map) IsInternal

func (m *Map) IsInternal() bool

func (*Map) IsPinned

func (m *Map) IsPinned() bool

func (*Map) KeySize

func (m *Map) KeySize() uint32

func (*Map) Lookup

func (m *Map) Lookup(key []byte, flags uint64) ([]byte, error)

func (*Map) LookupAndDelete

func (m *Map) LookupAndDelete(key []byte, flags uint64) ([]byte, error)

func (*Map) MaxEntries

func (m *Map) MaxEntries() uint32

func (*Map) NUMANode

func (m *Map) NUMANode() uint32

func (*Map) Name

func (m *Map) Name() string

func (*Map) NextKey

func (m *Map) NextKey(current []byte) ([]byte, error)

func (*Map) Pin

func (m *Map) Pin(path string) error

func (*Map) PinPath

func (m *Map) PinPath() string

func (*Map) ReuseFD

func (m *Map) ReuseFD(fd int) error

func (*Map) SetAutoattach

func (m *Map) SetAutoattach(autoattach bool) error

func (*Map) SetAutocreate

func (m *Map) SetAutocreate(autocreate bool) error

func (*Map) SetExclusiveProgram

func (m *Map) SetExclusiveProgram(prog *Program) error

func (*Map) SetExtra

func (m *Map) SetExtra(extra uint64) error

func (*Map) SetFlags

func (m *Map) SetFlags(flags uint32) error

func (*Map) SetIfindex

func (m *Map) SetIfindex(ifindex uint32) error

func (*Map) SetInitialValue

func (m *Map) SetInitialValue(value []byte) error

func (*Map) SetInnerMapFD

func (m *Map) SetInnerMapFD(fd int) error

func (*Map) SetKeySize

func (m *Map) SetKeySize(size uint32) error

func (*Map) SetMaxEntries

func (m *Map) SetMaxEntries(maxEntries uint32) error

func (*Map) SetNUMANode

func (m *Map) SetNUMANode(numaNode uint32) error

func (*Map) SetPinPath

func (m *Map) SetPinPath(path string) error

func (*Map) SetType

func (m *Map) SetType(t MapType) error

func (*Map) SetValueSize

func (m *Map) SetValueSize(size uint32) error

func (*Map) Type

func (m *Map) Type() MapType

func (*Map) Unpin

func (m *Map) Unpin(path string) error

func (*Map) Update

func (m *Map) Update(key, value []byte, flags uint64) error

func (*Map) ValueSize

func (m *Map) ValueSize() uint32

type MapBatchDeleteOptions

type MapBatchDeleteOptions struct {
	KeySize int
	MapBatchOptions
}

type MapBatchLookupOptions

type MapBatchLookupOptions struct {
	InBatch    []byte
	CursorSize int
	KeySize    int
	ValueSize  int
	MaxEntries int
	MapBatchOptions
}

type MapBatchLookupResult

type MapBatchLookupResult struct {
	OutBatch []byte
	Keys     []byte
	Values   []byte
	Count    uint32
}

func LookupAndDeleteMapBatch

func LookupAndDeleteMapBatch(fd int, opts MapBatchLookupOptions) (MapBatchLookupResult, error)

func LookupMapBatch

func LookupMapBatch(fd int, opts MapBatchLookupOptions) (MapBatchLookupResult, error)

type MapBatchOptions

type MapBatchOptions struct {
	ElementFlags uint64
	Flags        uint64
}

type MapBatchUpdateOptions

type MapBatchUpdateOptions struct {
	KeySize   int
	ValueSize int
	MapBatchOptions
}

type MapCreateOptions

type MapCreateOptions struct {
	Type       MapType
	Name       string
	KeySize    uint32
	ValueSize  uint32
	MaxEntries uint32
}

type MapType

type MapType int32
const (
	MapTypeUnspec           MapType = abi.BPF_MAP_TYPE_UNSPEC
	MapTypeHash             MapType = abi.BPF_MAP_TYPE_HASH
	MapTypeArray            MapType = abi.BPF_MAP_TYPE_ARRAY
	MapTypeProgramArray     MapType = abi.BPF_MAP_TYPE_PROG_ARRAY
	MapTypePerfEventArray   MapType = abi.BPF_MAP_TYPE_PERF_EVENT_ARRAY
	MapTypePerCPUHash       MapType = abi.BPF_MAP_TYPE_PERCPU_HASH
	MapTypePerCPUArray      MapType = abi.BPF_MAP_TYPE_PERCPU_ARRAY
	MapTypeStackTrace       MapType = abi.BPF_MAP_TYPE_STACK_TRACE
	MapTypeArrayOfMaps      MapType = abi.BPF_MAP_TYPE_ARRAY_OF_MAPS
	MapTypeHashOfMaps       MapType = abi.BPF_MAP_TYPE_HASH_OF_MAPS
	MapTypeSockMap          MapType = abi.BPF_MAP_TYPE_SOCKMAP
	MapTypeSockHash         MapType = abi.BPF_MAP_TYPE_SOCKHASH
	MapTypeQueue            MapType = abi.BPF_MAP_TYPE_QUEUE
	MapTypeStack            MapType = abi.BPF_MAP_TYPE_STACK
	MapTypeStructOps        MapType = abi.BPF_MAP_TYPE_STRUCT_OPS
	MapTypeRingBuffer       MapType = abi.BPF_MAP_TYPE_RINGBUF
	MapTypeUserRingBuffer   MapType = abi.BPF_MAP_TYPE_USER_RINGBUF
	MapTypeArena            MapType = abi.BPF_MAP_TYPE_ARENA
	MapTypeInstructionArray MapType = abi.BPF_MAP_TYPE_INSN_ARRAY
)

func (MapType) String

func (t MapType) String() string

type NetfilterOptions

type NetfilterOptions struct {
	ProtocolFamily uint32
	HookNumber     uint32
	Priority       int32
	Flags          uint32
}

type NetkitOptions

type NetkitOptions struct {
	Flags            uint32
	RelativeFD       uint32
	RelativeID       uint32
	ExpectedRevision uint64
}

type Object

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

func OpenObjectFile

func OpenObjectFile(path string, opts ObjectOptions) (*Object, error)

func OpenObjectMem

func OpenObjectMem(data []byte, opts ObjectOptions) (*Object, error)

func WrapObject

func WrapObject(handle abi.ObjectHandle, opts WrapObjectOptions) (*Object, error)

func (*Object) ABIHandle

func (o *Object) ABIHandle() abi.ObjectHandle

func (*Object) BTF

func (o *Object) BTF() (*BTF, error)

func (*Object) BTFFD

func (o *Object) BTFFD() int

func (*Object) Close

func (o *Object) Close() error

func (*Object) GenerateLoader

func (o *Object) GenerateLoader() error

func (*Object) KernelLog

func (o *Object) KernelLog() string

func (*Object) KernelVersion

func (o *Object) KernelVersion() uint32

func (*Object) Load

func (o *Object) Load() error

func (*Object) Map

func (o *Object) Map(name string) (*Map, error)

func (*Object) MapFD

func (o *Object) MapFD(name string) (int, error)

func (*Object) Maps

func (o *Object) Maps() ([]*Map, error)

func (*Object) MapsReverse

func (o *Object) MapsReverse() ([]*Map, error)

func (*Object) Name

func (o *Object) Name() string

func (*Object) Pin

func (o *Object) Pin(path string) error

func (*Object) PinMaps

func (o *Object) PinMaps(path string) error

func (*Object) PinPrograms

func (o *Object) PinPrograms(path string) error

func (*Object) Prepare

func (o *Object) Prepare() error

func (*Object) Program

func (o *Object) Program(name string) (*Program, error)

func (*Object) Programs

func (o *Object) Programs() ([]*Program, error)

func (*Object) ProgramsReverse

func (o *Object) ProgramsReverse() ([]*Program, error)

func (*Object) SetKernelVersion

func (o *Object) SetKernelVersion(version uint32) error

func (*Object) TokenFD

func (o *Object) TokenFD() int

func (*Object) Unpin

func (o *Object) Unpin(path string) error

func (*Object) UnpinMaps

func (o *Object) UnpinMaps(path string) error

func (*Object) UnpinPrograms

func (o *Object) UnpinPrograms(path string) error

type ObjectGetOptions

type ObjectGetOptions struct {
	FileFlags uint32
	PathFD    int
}

type ObjectOptions

type ObjectOptions struct {
	// Name overrides libbpf's object name derived from the path or memory
	// buffer.
	Name string
	// RelaxedMaps allows non-strict map definition parsing.
	RelaxedMaps bool
	// PinRootPath is the root directory for maps with pinning metadata.
	PinRootPath string
	// KConfig is additional kernel config content for CONFIG_* externs.
	KConfig string
	// BTFCustomPath replaces vmlinux BTF for CO-RE relocations.
	BTFCustomPath string
	// KernelLogSize allocates an object-owned verifier/BTF log buffer.
	KernelLogSize uint32
	// KernelLogLevel requests kernel verifier/BTF logging.
	KernelLogLevel uint32
	// BPFTokenPath derives a BPF token from the given BPF filesystem path.
	BPFTokenPath string
	// DisableBPFToken sets an explicit empty BPF token path, disabling
	// libbpf's implicit token creation and environment-variable fallback.
	DisableBPFToken bool
}

type ObjectPinOptions

type ObjectPinOptions struct {
	FileFlags uint32
	PathFD    int
}

type PerfBuffer

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

func NewPerfBuffer

func NewPerfBuffer(mapFD int, pageCount uint64, sampleCallback PerfBufferSampleCallback, lostCallback PerfBufferLostCallback) (*PerfBuffer, error)

func NewRawPerfBuffer

func NewRawPerfBuffer(mapFD int, pageCount uint64, attr PerfEventAttr, eventCallback PerfBufferEventCallback, opts RawPerfBufferOptions) (*PerfBuffer, error)

NewRawPerfBuffer creates a raw perf buffer using caller-supplied perf event attributes and a raw event callback.

func (*PerfBuffer) Buffer

func (pb *PerfBuffer) Buffer(index int) ([]byte, error)

func (*PerfBuffer) BufferCount

func (pb *PerfBuffer) BufferCount() uint64

func (*PerfBuffer) BufferFD

func (pb *PerfBuffer) BufferFD(index uint64) int

func (*PerfBuffer) Close

func (pb *PerfBuffer) Close() error

func (*PerfBuffer) Consume

func (pb *PerfBuffer) Consume() error

func (*PerfBuffer) ConsumeBuffer

func (pb *PerfBuffer) ConsumeBuffer(index uint64) error

func (*PerfBuffer) EpollFD

func (pb *PerfBuffer) EpollFD() int

func (*PerfBuffer) Poll

func (pb *PerfBuffer) Poll(timeoutMillis int) (int, error)

type PerfBufferEvent

type PerfBufferEvent struct {
	CPU    int
	Header PerfEventHeader
	// Data is a borrowed view over the full event record, including Header,
	// and is only valid during the callback. Copy it before retaining it.
	Data []byte
}

PerfBufferEvent is a raw perf event record passed to a raw perf buffer callback.

type PerfBufferEventCallback

type PerfBufferEventCallback func(PerfBufferEvent) (PerfBufferEventResult, error)

PerfBufferEventCallback is called synchronously from Poll, Consume, or ConsumeBuffer for raw perf buffers. It must not call methods on the same PerfBuffer.

type PerfBufferEventResult

type PerfBufferEventResult int32

PerfBufferEventResult controls raw perf event iteration.

const (
	// PerfEventDone stops event processing successfully.
	PerfEventDone PerfBufferEventResult = abi.LIBBPF_PERF_EVENT_DONE
	// PerfEventError stops event processing with an error.
	PerfEventError PerfBufferEventResult = abi.LIBBPF_PERF_EVENT_ERROR
	// PerfEventContinue continues event processing.
	PerfEventContinue PerfBufferEventResult = abi.LIBBPF_PERF_EVENT_CONT
)

type PerfBufferLostCallback

type PerfBufferLostCallback func(cpu int, lost uint64) error

PerfBufferLostCallback is called synchronously from Poll, Consume, or ConsumeBuffer. It must not call methods on the same PerfBuffer.

type PerfBufferSample

type PerfBufferSample struct {
	CPU int
	// Data is a borrowed view into libbpf-owned memory and is only valid
	// during the callback. Copy it before retaining it.
	Data []byte
}

type PerfBufferSampleCallback

type PerfBufferSampleCallback func(PerfBufferSample) error

PerfBufferSampleCallback is called synchronously from Poll, Consume, or ConsumeBuffer. It must not call methods on the same PerfBuffer.

type PerfEventAttachOptions

type PerfEventAttachOptions struct {
	Cookie           uint64
	ForceIOCTLAttach bool
	DontEnable       bool
}

type PerfEventAttr

type PerfEventAttr struct {
	Type                    PerfEventType
	Config                  uint64
	SamplePeriodOrFrequency uint64
	SampleType              PerfSampleType
	ReadFormat              uint64
	Flags                   PerfEventAttrFlags
	WakeupEventsOrWatermark uint32
	BPType                  uint32
	Config1                 uint64
	Config2                 uint64
	BranchSampleType        uint64
	SampleRegsUser          uint64
	SampleStackUser         uint32
	ClockID                 int32
	SampleRegsIntr          uint64
	AuxWatermark            uint32
	SampleMaxStack          uint16
	AuxSampleSize           uint32
	AuxAction               uint32
	SigData                 uint64
	Config3                 uint64
	Config4                 uint64
}

PerfEventAttr describes the perf event attributes used by NewRawPerfBuffer. The generated ABI sets the kernel size field automatically. Fields ending in "Or" select the corresponding perf_event_attr union member according to the flag bits, as Linux does.

type PerfEventAttrFlags

type PerfEventAttrFlags uint64

PerfEventAttrFlags is the Linux perf_event_attr flag bitmask.

const (
	PerfEventAttrDisabled               PerfEventAttrFlags = 1 << 0
	PerfEventAttrInherit                PerfEventAttrFlags = 1 << 1
	PerfEventAttrPinned                 PerfEventAttrFlags = 1 << 2
	PerfEventAttrExclusive              PerfEventAttrFlags = 1 << 3
	PerfEventAttrExcludeUser            PerfEventAttrFlags = 1 << 4
	PerfEventAttrExcludeKernel          PerfEventAttrFlags = 1 << 5
	PerfEventAttrExcludeHV              PerfEventAttrFlags = 1 << 6
	PerfEventAttrExcludeIdle            PerfEventAttrFlags = 1 << 7
	PerfEventAttrMmap                   PerfEventAttrFlags = 1 << 8
	PerfEventAttrComm                   PerfEventAttrFlags = 1 << 9
	PerfEventAttrFreq                   PerfEventAttrFlags = 1 << 10
	PerfEventAttrInheritStat            PerfEventAttrFlags = 1 << 11
	PerfEventAttrEnableOnExec           PerfEventAttrFlags = 1 << 12
	PerfEventAttrTask                   PerfEventAttrFlags = 1 << 13
	PerfEventAttrWatermark              PerfEventAttrFlags = 1 << 14
	PerfEventAttrPreciseIPConstantSkid  PerfEventAttrFlags = 1 << 15
	PerfEventAttrPreciseIPZeroRequested PerfEventAttrFlags = 2 << 15
	PerfEventAttrPreciseIPZeroRequired  PerfEventAttrFlags = 3 << 15
	PerfEventAttrMmapData               PerfEventAttrFlags = 1 << 17
	PerfEventAttrSampleIDAll            PerfEventAttrFlags = 1 << 18
	PerfEventAttrExcludeHost            PerfEventAttrFlags = 1 << 19
	PerfEventAttrExcludeGuest           PerfEventAttrFlags = 1 << 20
	PerfEventAttrExcludeCallchainKernel PerfEventAttrFlags = 1 << 21
	PerfEventAttrExcludeCallchainUser   PerfEventAttrFlags = 1 << 22
	PerfEventAttrMmap2                  PerfEventAttrFlags = 1 << 23
	PerfEventAttrCommExec               PerfEventAttrFlags = 1 << 24
	PerfEventAttrUseClockID             PerfEventAttrFlags = 1 << 25
	PerfEventAttrContextSwitch          PerfEventAttrFlags = 1 << 26
	PerfEventAttrWriteBackward          PerfEventAttrFlags = 1 << 27
	PerfEventAttrNamespaces             PerfEventAttrFlags = 1 << 28
	PerfEventAttrKSymbol                PerfEventAttrFlags = 1 << 29
	PerfEventAttrBPFEvent               PerfEventAttrFlags = 1 << 30
	PerfEventAttrAuxOutput              PerfEventAttrFlags = 1 << 31
	PerfEventAttrCgroup                 PerfEventAttrFlags = 1 << 32
	PerfEventAttrTextPoke               PerfEventAttrFlags = 1 << 33
	PerfEventAttrBuildID                PerfEventAttrFlags = 1 << 34
	PerfEventAttrInheritThread          PerfEventAttrFlags = 1 << 35
	PerfEventAttrRemoveOnExec           PerfEventAttrFlags = 1 << 36
	PerfEventAttrSigtrap                PerfEventAttrFlags = 1 << 37
	PerfEventAttrDeferCallchain         PerfEventAttrFlags = 1 << 38
	PerfEventAttrDeferOutput            PerfEventAttrFlags = 1 << 39
)

type PerfEventHeader

type PerfEventHeader struct {
	Type uint32
	Misc uint16
	Size uint16
}

PerfEventHeader describes the header at the start of a raw perf event.

type PerfEventType

type PerfEventType uint32

PerfEventType is the Linux perf_event_attr type field.

const (
	PerfEventTypeHardware   PerfEventType = abi.PERF_TYPE_HARDWARE
	PerfEventTypeSoftware   PerfEventType = abi.PERF_TYPE_SOFTWARE
	PerfEventTypeTracepoint PerfEventType = abi.PERF_TYPE_TRACEPOINT
	PerfEventTypeHWCache    PerfEventType = abi.PERF_TYPE_HW_CACHE
	PerfEventTypeRaw        PerfEventType = abi.PERF_TYPE_RAW
	PerfEventTypeBreakpoint PerfEventType = abi.PERF_TYPE_BREAKPOINT
)

type PerfSampleType

type PerfSampleType uint64

PerfSampleType is a Linux perf sample_type bitmask.

type PerfSoftwareEvent

type PerfSoftwareEvent uint64

PerfSoftwareEvent is a software perf event config value.

type ProbeAttachMode

type ProbeAttachMode int32

type Program

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

func (*Program) ABIHandle

func (p *Program) ABIHandle() abi.ProgramHandle

func (*Program) AssociateStructOps

func (p *Program) AssociateStructOps(m *Map, opts StructOpsAssociationOptions) error

func (*Program) Attach

func (p *Program) Attach() (*Link, error)

func (*Program) AttachCgroup

func (p *Program) AttachCgroup(cgroupFD int) (*Link, error)

func (*Program) AttachCgroupWithOptions

func (p *Program) AttachCgroupWithOptions(cgroupFD int, opts CgroupOptions) (*Link, error)

func (*Program) AttachFreplace

func (p *Program) AttachFreplace(targetFD int, function string) (*Link, error)

func (*Program) AttachIterator

func (p *Program) AttachIterator() (*Link, error)

func (*Program) AttachKprobe

func (p *Program) AttachKprobe(function string, retprobe bool) (*Link, error)

func (*Program) AttachKprobeMulti

func (p *Program) AttachKprobeMulti(pattern string) (*Link, error)

func (*Program) AttachKprobeWithOptions

func (p *Program) AttachKprobeWithOptions(function string, opts KprobeOptions) (*Link, error)

func (*Program) AttachKsyscall

func (p *Program) AttachKsyscall(syscall string) (*Link, error)

func (*Program) AttachLSM

func (p *Program) AttachLSM() (*Link, error)

func (*Program) AttachNetNS

func (p *Program) AttachNetNS(netnsFD int) (*Link, error)

func (*Program) AttachNetfilter

func (p *Program) AttachNetfilter(opts NetfilterOptions) (*Link, error)

func (*Program) AttachNetkit

func (p *Program) AttachNetkit(ifindex int, opts NetkitOptions) (*Link, error)

func (*Program) AttachPerfEvent

func (p *Program) AttachPerfEvent(perfEventFD int) (*Link, error)

func (*Program) AttachPerfEventWithOptions

func (p *Program) AttachPerfEventWithOptions(perfEventFD int, opts PerfEventAttachOptions) (*Link, error)

func (*Program) AttachRawTracepoint

func (p *Program) AttachRawTracepoint(name string) (*Link, error)

func (*Program) AttachRawTracepointWithOptions

func (p *Program) AttachRawTracepointWithOptions(name string, opts RawTracepointOptions) (*Link, error)

func (*Program) AttachSockMap

func (p *Program) AttachSockMap(mapFD int) (*Link, error)

func (*Program) AttachTCX

func (p *Program) AttachTCX(ifindex int, opts TCXOptions) (*Link, error)

func (*Program) AttachTrace

func (p *Program) AttachTrace() (*Link, error)

func (*Program) AttachTraceWithOptions

func (p *Program) AttachTraceWithOptions(opts TraceOptions) (*Link, error)

func (*Program) AttachTracepoint

func (p *Program) AttachTracepoint(category, name string) (*Link, error)

func (*Program) AttachTracepointWithOptions

func (p *Program) AttachTracepointWithOptions(category, name string, opts TracepointOptions) (*Link, error)

func (*Program) AttachUSDT

func (p *Program) AttachUSDT(pid int, binaryPath, provider, name string) (*Link, error)

func (*Program) AttachUprobe

func (p *Program) AttachUprobe(pid int, binaryPath string, offset uint64, retprobe bool) (*Link, error)

func (*Program) AttachUprobeMulti

func (p *Program) AttachUprobeMulti(pid int, binaryPath, pattern string) (*Link, error)

func (*Program) AttachUprobeWithOptions

func (p *Program) AttachUprobeWithOptions(pid int, binaryPath string, offset uint64, opts UprobeOptions) (*Link, error)

func (*Program) AttachXDP

func (p *Program) AttachXDP(ifindex int) (*Link, error)

func (*Program) Autoattach

func (p *Program) Autoattach() bool

func (*Program) Autoload

func (p *Program) Autoload() bool

func (*Program) ExpectedAttachType

func (p *Program) ExpectedAttachType() AttachType

func (*Program) FD

func (p *Program) FD() int

func (*Program) Flags

func (p *Program) Flags() uint32

func (*Program) FuncInfo

func (p *Program) FuncInfo() ([]FuncInfo, error)

func (*Program) FuncInfoCount

func (p *Program) FuncInfoCount() uint32

func (*Program) Instructions

func (p *Program) Instructions() []byte

func (*Program) LineInfo

func (p *Program) LineInfo() (*ProgramLineInfo, error)

func (*Program) LineInfoCount

func (p *Program) LineInfoCount() uint32

func (*Program) LogBuffer

func (p *Program) LogBuffer() []byte

func (*Program) LogLevel

func (p *Program) LogLevel() uint32

func (*Program) LogString

func (p *Program) LogString() string

func (*Program) Name

func (p *Program) Name() string

func (*Program) Pin

func (p *Program) Pin(path string) error

func (*Program) SectionName

func (p *Program) SectionName() string

func (*Program) SetAttachTarget

func (p *Program) SetAttachTarget(targetFD int, function string) error

func (*Program) SetAutoattach

func (p *Program) SetAutoattach(autoattach bool) error

func (*Program) SetAutoload

func (p *Program) SetAutoload(autoload bool) error

func (*Program) SetExpectedAttachType

func (p *Program) SetExpectedAttachType(t AttachType) error

func (*Program) SetFlags

func (p *Program) SetFlags(flags uint32) error

func (*Program) SetIfindex

func (p *Program) SetIfindex(ifindex uint32) error

func (*Program) SetInstructions

func (p *Program) SetInstructions(insns []byte) error

func (*Program) SetLogBuffer

func (p *Program) SetLogBuffer(size uint32) error

SetLogBuffer installs an object-owned verifier log buffer for this program. Passing zero clears the program log buffer.

func (*Program) SetLogLevel

func (p *Program) SetLogLevel(level uint32) error

func (*Program) SetType

func (p *Program) SetType(t ProgramType) error

func (*Program) SourceLineInfo

func (p *Program) SourceLineInfo() ([]LineInfo, error)

SourceLineInfo returns source line-info records stored on the libbpf program.

func (*Program) TestRun

func (*Program) Type

func (p *Program) Type() ProgramType

func (*Program) Unload

func (p *Program) Unload() error

func (*Program) Unpin

func (p *Program) Unpin(path string) error

type ProgramAttachOptions

type ProgramAttachOptions struct {
	Flags            uint32
	ReplaceProgramFD int
	RelativeFD       int
	RelativeID       uint32
	ExpectedRevision uint64
}

type ProgramBindOptions

type ProgramBindOptions struct {
	Flags uint32
}

type ProgramDetachOptions

type ProgramDetachOptions struct {
	Flags            uint32
	RelativeFD       int
	RelativeID       uint32
	ExpectedRevision uint64
}

type ProgramLineInfo

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

func ProgramLineInfoByFD

func ProgramLineInfoByFD(fd int) (*ProgramLineInfo, error)

func (*ProgramLineInfo) Close

func (l *ProgramLineInfo) Close() error

func (*ProgramLineInfo) LookupInstruction

func (l *ProgramLineInfo) LookupInstruction(insnOffset uint32, skip uint32) (LineInfo, error)

func (*ProgramLineInfo) LookupJitedAddress

func (l *ProgramLineInfo) LookupJitedAddress(addr uint64, funcIndex uint32, skip uint32) (LineInfo, error)

type ProgramLoadOptions

type ProgramLoadOptions struct {
	Type         ProgramType
	Name         string
	License      string
	Instructions []byte
}

type ProgramQueryOptions

type ProgramQueryOptions struct {
	QueryFlags uint32
	MaxEntries int
}

type ProgramQueryResult

type ProgramQueryResult struct {
	AttachFlags        uint32
	ProgramIDs         []uint32
	ProgramAttachFlags []uint32
	LinkIDs            []uint32
	LinkAttachFlags    []uint32
	Count              uint32
	Revision           uint64
}

func QueryPrograms

func QueryPrograms(targetFD int, attachType AttachType, queryFlags uint32, maxPrograms int) (ProgramQueryResult, error)

func QueryProgramsWithOptions

func QueryProgramsWithOptions(target int, attachType AttachType, opts ProgramQueryOptions) (ProgramQueryResult, error)

type ProgramSectionHandler

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

ProgramSectionHandler owns a registered process-wide custom BPF SEC() handler.

func RegisterProgramSectionHandler

func RegisterProgramSectionHandler(opts ProgramSectionHandlerOptions) (*ProgramSectionHandler, error)

RegisterProgramSectionHandler registers a process-wide custom BPF SEC() handler. The returned handler must be closed to unregister it.

func (*ProgramSectionHandler) Close

func (h *ProgramSectionHandler) Close() error

Close unregisters the custom BPF SEC() handler. Close is idempotent.

func (*ProgramSectionHandler) ID

func (h *ProgramSectionHandler) ID() int

ID returns the registered libbpf handler ID, or zero after Close.

type ProgramSectionHandlerOptions

type ProgramSectionHandlerOptions struct {
	Section            string
	Fallback           bool
	ProgramType        ProgramType
	ExpectedAttachType AttachType
}

ProgramSectionHandlerOptions configures a process-wide custom BPF SEC() handler without custom callbacks.

type ProgramTestRunOptions

type ProgramTestRunOptions struct {
	Data           []byte
	DataOutSize    int
	Context        []byte
	ContextOutSize int
	Repeat         int
	Flags          uint32
	CPU            uint32
	BatchSize      uint32
}

type ProgramTestRunResult

type ProgramTestRunResult struct {
	Data        []byte
	Context     []byte
	ReturnValue uint32
	Duration    uint32
}

func TestRunProgram

func TestRunProgram(fd int, opts ProgramTestRunOptions) (ProgramTestRunResult, error)

type ProgramType

type ProgramType int32
const (
	ProgramTypeUnspec        ProgramType = abi.BPF_PROG_TYPE_UNSPEC
	ProgramTypeSocketFilter  ProgramType = abi.BPF_PROG_TYPE_SOCKET_FILTER
	ProgramTypeKprobe        ProgramType = abi.BPF_PROG_TYPE_KPROBE
	ProgramTypeSchedClass    ProgramType = abi.BPF_PROG_TYPE_SCHED_CLS
	ProgramTypeSchedAction   ProgramType = abi.BPF_PROG_TYPE_SCHED_ACT
	ProgramTypeTracepoint    ProgramType = abi.BPF_PROG_TYPE_TRACEPOINT
	ProgramTypeXDP           ProgramType = abi.BPF_PROG_TYPE_XDP
	ProgramTypePerfEvent     ProgramType = abi.BPF_PROG_TYPE_PERF_EVENT
	ProgramTypeRawTracepoint ProgramType = abi.BPF_PROG_TYPE_RAW_TRACEPOINT
	ProgramTypeTracing       ProgramType = abi.BPF_PROG_TYPE_TRACING
	ProgramTypeStructOps     ProgramType = abi.BPF_PROG_TYPE_STRUCT_OPS
	ProgramTypeExtension     ProgramType = abi.BPF_PROG_TYPE_EXT
	ProgramTypeLSM           ProgramType = abi.BPF_PROG_TYPE_LSM
	ProgramTypeSyscall       ProgramType = abi.BPF_PROG_TYPE_SYSCALL
	ProgramTypeNetfilter     ProgramType = abi.BPF_PROG_TYPE_NETFILTER
)

func (ProgramType) String

func (t ProgramType) String() string

type RawPerfBufferOptions

type RawPerfBufferOptions struct {
	CPUs    []int
	MapKeys []int
}

RawPerfBufferOptions configures raw perf-buffer CPU and map-key selection. CPUs and MapKeys must both be empty or have matching lengths.

type RawTracepointOptions

type RawTracepointOptions struct {
	Cookie uint64
}

type Ring

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

func (*Ring) AvailableDataSize

func (r *Ring) AvailableDataSize() uint64

func (*Ring) Consume

func (r *Ring) Consume() (int, error)

func (*Ring) ConsumeN

func (r *Ring) ConsumeN(n uint64) (int, error)

func (*Ring) ConsumerPosition

func (r *Ring) ConsumerPosition() uint64

func (*Ring) MapFD

func (r *Ring) MapFD() int

func (*Ring) ProducerPosition

func (r *Ring) ProducerPosition() uint64

func (*Ring) Size

func (r *Ring) Size() uint64

type RingBuffer

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

func NewRingBuffer

func NewRingBuffer(mapFD int, callback RingBufferCallback) (*RingBuffer, error)

func (*RingBuffer) Add

func (rb *RingBuffer) Add(mapFD int, callback RingBufferCallback) error

func (*RingBuffer) Close

func (rb *RingBuffer) Close() error

func (*RingBuffer) Consume

func (rb *RingBuffer) Consume() (int, error)

func (*RingBuffer) ConsumeN

func (rb *RingBuffer) ConsumeN(n uint64) (int, error)

func (*RingBuffer) EpollFD

func (rb *RingBuffer) EpollFD() int

func (*RingBuffer) Poll

func (rb *RingBuffer) Poll(timeoutMillis int) (int, error)

func (*RingBuffer) Ring

func (rb *RingBuffer) Ring(index uint32) (*Ring, error)

type RingBufferCallback

type RingBufferCallback func(RingBufferSample) error

RingBufferCallback is called synchronously from Poll, Consume, or ConsumeN. It must not call methods on the same RingBuffer.

type RingBufferSample

type RingBufferSample struct {
	// Data is a borrowed view into libbpf-owned memory and is only valid
	// during the callback. Copy it before retaining it.
	Data []byte
}

type Skeleton

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

Skeleton owns a libbpf skeleton descriptor and its opened object.

func NewSkeleton

func NewSkeleton(spec SkeletonSpec) (*Skeleton, error)

NewSkeleton creates a skeleton descriptor from object bytes.

func (*Skeleton) Attach

func (s *Skeleton) Attach() error

func (*Skeleton) Close

func (s *Skeleton) Close() error

func (*Skeleton) Detach

func (s *Skeleton) Detach() error

func (*Skeleton) Load

func (s *Skeleton) Load() error

func (*Skeleton) Map

func (s *Skeleton) Map(name string) (*Map, error)
func (s *Skeleton) MapLink(name string) (*Link, error)

func (*Skeleton) MappedValue

func (s *Skeleton) MappedValue(name string) ([]byte, error)

MappedValue returns a borrowed view of an mmaped skeleton map value. The returned slice is valid only while the skeleton and object remain open.

func (*Skeleton) Object

func (s *Skeleton) Object() (*Object, error)

func (*Skeleton) Open

func (s *Skeleton) Open(opts ObjectOptions) (*Object, error)

func (*Skeleton) Program

func (s *Skeleton) Program(name string) (*Program, error)
func (s *Skeleton) ProgramLink(name string) (*Link, error)

type SkeletonMapSpec

type SkeletonMapSpec struct {
	Name            string
	MappedValueSize int
}

SkeletonMapSpec describes a map entry expected in a BPF skeleton.

type SkeletonProgramSpec

type SkeletonProgramSpec struct {
	Name string
}

SkeletonProgramSpec describes a program entry expected in a BPF skeleton.

type SkeletonSpec

type SkeletonSpec struct {
	Name     string
	Data     []byte
	Maps     []SkeletonMapSpec
	Programs []SkeletonProgramSpec
}

SkeletonSpec describes a libbpf-style skeleton backed by object bytes.

type SkeletonVariableSpec

type SkeletonVariableSpec struct {
	Name    string
	MapName string
	Size    int
}

SkeletonVariableSpec describes a subskeleton variable and its backing map.

type StatsType

type StatsType int32
const (
	StatsRunTime StatsType = abi.BPF_STATS_RUN_TIME
)

type StrictMode

type StrictMode uint32

type StructOpsAssociationOptions

type StructOpsAssociationOptions struct {
	Flags uint32
}

type Subskeleton

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

Subskeleton owns a libbpf subskeleton descriptor for a borrowed object.

func OpenSubskeleton

func OpenSubskeleton(spec SubskeletonSpec) (*Subskeleton, error)

OpenSubskeleton opens a subskeleton against an already-open BPF object.

func (*Subskeleton) Close

func (ss *Subskeleton) Close() error

func (*Subskeleton) Map

func (ss *Subskeleton) Map(name string) (*Map, error)

func (*Subskeleton) Program

func (ss *Subskeleton) Program(name string) (*Program, error)

func (*Subskeleton) VariableData

func (ss *Subskeleton) VariableData(name string) ([]byte, error)

VariableData returns a borrowed view of a subskeleton variable. The returned slice is valid only while the subskeleton and object remain open.

type SubskeletonSpec

type SubskeletonSpec struct {
	Object    *Object
	Maps      []SkeletonMapSpec
	Programs  []SkeletonProgramSpec
	Variables []SkeletonVariableSpec
}

SubskeletonSpec describes a subskeleton for an already-open BPF object.

type TCAttachPoint

type TCAttachPoint int32

type TCHook

type TCHook struct {
	Ifindex     int
	AttachPoint TCAttachPoint
	Parent      uint32
	Handle      uint32
	Qdisc       string
}

type TCOptions

type TCOptions struct {
	ProgramFD int
	Flags     uint32
	ProgramID uint32
	Handle    uint32
	Priority  uint32
}

func TCAttach

func TCAttach(hook TCHook, opts TCOptions) (TCOptions, error)

func TCQuery

func TCQuery(hook TCHook, opts TCOptions) (TCOptions, error)

type TCXOptions

type TCXOptions struct {
	Flags            uint32
	RelativeFD       uint32
	RelativeID       uint32
	ExpectedRevision uint64
}

type TaskFDQueryOptions

type TaskFDQueryOptions struct {
	Flags    uint32
	NameSize int
}

type TaskFDQueryResult

type TaskFDQueryResult struct {
	Name         string
	NameLength   uint32
	ProgramID    uint32
	FDType       uint32
	ProbeOffset  uint64
	ProbeAddress uint64
}

func TaskFDQuery

func TaskFDQuery(pid, fd int, opts TaskFDQueryOptions) (TaskFDQueryResult, error)

type TokenCreateOptions

type TokenCreateOptions struct {
	Flags uint32
}

type TraceOptions

type TraceOptions struct {
	Cookie uint64
}

type TracepointOptions

type TracepointOptions struct {
	Cookie uint64
}

type UprobeOptions

type UprobeOptions struct {
	RefCounterOffset uint64
	Cookie           uint64
	Retprobe         bool
	FunctionName     string
	AttachMode       ProbeAttachMode
}

type UserRingBuffer

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

func NewUserRingBuffer

func NewUserRingBuffer(mapFD int) (*UserRingBuffer, error)

func (*UserRingBuffer) Close

func (rb *UserRingBuffer) Close() error

func (*UserRingBuffer) Reserve

func (rb *UserRingBuffer) Reserve(size uint32) (*UserRingSample, error)

Reserve reserves a sample. The returned sample holds ring capacity until it is submitted or discarded.

func (*UserRingBuffer) ReserveBlocking

func (rb *UserRingBuffer) ReserveBlocking(size uint32, timeoutMillis int) (*UserRingSample, error)

ReserveBlocking reserves a sample, waiting up to timeoutMillis according to libbpf's user-ring-buffer rules.

type UserRingSample

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

UserRingSample is a reserved user-ring record. It must be submitted or discarded exactly once.

func (*UserRingSample) Bytes

func (s *UserRingSample) Bytes() []byte

Bytes returns a borrowed view that is valid only until Submit, Discard, or the parent ring buffer is closed.

func (*UserRingSample) Discard

func (s *UserRingSample) Discard() error

Discard releases the reserved sample without publishing it.

func (*UserRingSample) Submit

func (s *UserRingSample) Submit() error

Submit publishes the reserved sample to the ring buffer.

type WrapObjectOptions

type WrapObjectOptions struct {
	Ownership HandleOwnership
}

type XDPAttachMode

type XDPAttachMode uint8
const (
	XDPAttachedNone   XDPAttachMode = abi.XDP_ATTACHED_NONE
	XDPAttachedDriver XDPAttachMode = abi.XDP_ATTACHED_DRV
	XDPAttachedSKB    XDPAttachMode = abi.XDP_ATTACHED_SKB
	XDPAttachedHW     XDPAttachMode = abi.XDP_ATTACHED_HW
	XDPAttachedMulti  XDPAttachMode = abi.XDP_ATTACHED_MULTI
)

type XDPQueryResult

type XDPQueryResult struct {
	ProgramID           uint32
	DriverProgramID     uint32
	HardwareProgramID   uint32
	SKBProgramID        uint32
	AttachMode          XDPAttachMode
	FeatureFlags        uint64
	ZeroCopyMaxSegments uint32
}

func XDPQuery

func XDPQuery(ifindex, flags int) (XDPQueryResult, error)

Directories

Path Synopsis
Package abi exposes the generated libbpf ABI for the pinned libbpf source revision.
Package abi exposes the generated libbpf ABI for the pinned libbpf source revision.
internal
cmd/genbpf command

Jump to

Keyboard shortcuts

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