program

package
v1.3.2 Latest Latest
Warning

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

Go to latest
Published: Dec 23, 2024 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	KeepCollection bool
)

Functions

func AddGlobalMap added in v1.3.2

func AddGlobalMap(name string)

func DeleteGlobMap added in v1.3.2

func DeleteGlobMap(name string)

func GetMaxEntriesPinnedMap added in v1.3.2

func GetMaxEntriesPinnedMap(pinPath string) (uint32, error)

func GetProgramInfo

func GetProgramInfo(l *Program) (program, label, prog string)

func IsGlobalMap added in v1.3.2

func IsGlobalMap(name string) bool

func LoadFmodRetProgram added in v1.3.2

func LoadFmodRetProgram(bpfDir string, load *Program, progName string, verbose int) error

func LoadKprobeProgram

func LoadKprobeProgram(bpfDir string, load *Program, verbose int) error

func LoadKprobeProgramAttachMany added in v1.3.2

func LoadKprobeProgramAttachMany(bpfDir string, load *Program, syms []string, verbose int) error

func LoadLSMProgram added in v1.3.2

func LoadLSMProgram(bpfDir string, load *Program, verbose int) error

func LoadLSMProgramSimple added in v1.3.2

func LoadLSMProgramSimple(bpfDir string, load *Program, verbose int) error

func LoadMultiKprobeProgram

func LoadMultiKprobeProgram(bpfDir string, load *Program, verbose int) error

func LoadMultiUprobeProgram added in v1.3.2

func LoadMultiUprobeProgram(bpfDir string, load *Program, verbose int) error

func LoadOrCreatePinnedMap added in v0.8.20

func LoadOrCreatePinnedMap(pinPath string, mapSpec *ebpf.MapSpec, create bool) (*ebpf.Map, error)

func LoadProgram

func LoadProgram(
	bpfDir string,
	load *Program,
	attach AttachFunc,
	verbose int,
) error

func LoadProgramOpts added in v1.3.2

func LoadProgramOpts(
	bpfDir string,
	load *Program,
	opts *LoadOpts,
	verbose int,
) error

func LoadRawTracepointProgram

func LoadRawTracepointProgram(bpfDir string, load *Program, verbose int) error

func LoadTracepointProgram

func LoadTracepointProgram(bpfDir string, load *Program, verbose int) error

func LoadTracingProgram added in v1.3.2

func LoadTracingProgram(bpfDir string, load *Program, verbose int) error

func LoadUprobeProgram added in v1.3.2

func LoadUprobeProgram(bpfDir string, load *Program, verbose int) error

func PolicyMapPath added in v1.3.2

func PolicyMapPath(mapDir, policy, name string) string

Types

type AttachFunc

AttachFunc is the type for the various attachment functions. The function is given the program and it's up to it to close it.

func KprobeAttach

func KprobeAttach(load *Program, bpfDir string) AttachFunc

func KprobeAttachMany added in v1.3.2

func KprobeAttachMany(load *Program, syms []string, bpfDir string) AttachFunc

func LSMAttach added in v1.3.2

func LSMAttach() AttachFunc

func MultiKprobeAttach

func MultiKprobeAttach(load *Program, bpfDir string) AttachFunc

func MultiUprobeAttach added in v1.3.2

func MultiUprobeAttach(load *Program) AttachFunc

func NoAttach

func NoAttach() AttachFunc

func RawAttach

func RawAttach(targetFD int) AttachFunc

func RawAttachWithFlags added in v1.3.2

func RawAttachWithFlags(targetFD int, flags uint32) AttachFunc

func RawTracepointAttach

func RawTracepointAttach(load *Program) AttachFunc

func TracepointAttach

func TracepointAttach(load *Program, bpfDir string) AttachFunc

func TracingAttach added in v1.3.2

func TracingAttach() AttachFunc

func UprobeAttach added in v1.3.2

func UprobeAttach(load *Program) AttachFunc

type LoadOpts added in v1.3.2

type LoadOpts struct {
	Attach AttachFunc
	Open   OpenFunc
}

type LoadedCollection

type LoadedCollection struct {
	Programs map[string]*LoadedProgram
	Maps     map[string]*LoadedMap
}

type LoadedMap

type LoadedMap struct {
	ID ebpf.MapID
}

type LoadedProgram

type LoadedProgram struct {
	ID     ebpf.ProgramID
	MapIDs []ebpf.MapID
	Type   ebpf.ProgramType
}

type Map

type Map struct {
	Name         string
	PinPath      string
	Prog         *Program
	PinState     State
	MapHandle    *ebpf.Map
	Entries      MaxEntries
	InnerEntries MaxEntries
	Type         MapType
	Owner        bool
}

Map represents BPF maps.

func MapBuilder

func MapBuilder(name string, lds ...*Program) *Map

func MapBuilderOpts added in v1.3.2

func MapBuilderOpts(name string, opts MapOpts, lds ...*Program) *Map

func MapBuilderPolicy added in v1.3.2

func MapBuilderPolicy(name string, lds ...*Program) *Map

func MapBuilderProgram added in v1.3.2

func MapBuilderProgram(name string, lds ...*Program) *Map

func MapBuilderSensor added in v1.3.2

func MapBuilderSensor(name string, lds ...*Program) *Map

func MapBuilderType added in v1.3.2

func MapBuilderType(name string, ty MapType, lds ...*Program) *Map

func MapUser added in v1.3.2

func MapUser(name string, lds ...*Program) *Map

func MapUserPolicy added in v1.3.2

func MapUserPolicy(name string, lds ...*Program) *Map

func MapUserProgram added in v1.3.2

func MapUserProgram(name string, lds ...*Program) *Map

func MapUserSensor added in v1.3.2

func MapUserSensor(name string, lds ...*Program) *Map

func (*Map) Close

func (m *Map) Close() error

func (*Map) GetFD

func (m *Map) GetFD() (int, error)

func (*Map) GetMaxEntries added in v1.3.2

func (m *Map) GetMaxEntries() (uint32, bool)

func (*Map) GetMaxInnerEntries added in v1.3.2

func (m *Map) GetMaxInnerEntries() (uint32, bool)

func (*Map) IsCompatibleWith

func (m *Map) IsCompatibleWith(spec *ebpf.MapSpec) error

func (*Map) IsOwner added in v1.3.2

func (m *Map) IsOwner() bool

func (*Map) LoadOrCreatePinnedMap added in v0.8.20

func (m *Map) LoadOrCreatePinnedMap(pinPath string, mapSpec *ebpf.MapSpec) error

func (*Map) LoadPinnedMap

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

func (*Map) New

func (m *Map) New(spec *ebpf.MapSpec) error

func (*Map) Pin

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

func (*Map) SetInnerMaxEntries added in v1.3.2

func (m *Map) SetInnerMaxEntries(maximum int)

func (*Map) SetMaxEntries added in v1.3.2

func (m *Map) SetMaxEntries(maximum int)

func (*Map) String added in v1.3.2

func (m *Map) String() string

func (*Map) Unload

func (m *Map) Unload(unpin bool) error

type MapLoad

type MapLoad struct {
	Index uint32
	Name  string
	Load  func(m *ebpf.Map, pinPathPrefix string, index uint32) error
}

type MapOpts added in v1.3.2

type MapOpts struct {
	Type  MapType
	Owner bool
}

type MapType added in v1.3.2

type MapType int
const (
	MapTypeGlobal MapType = iota
	MapTypePolicy
	MapTypeSensor
	MapTypeProgram
)

type MaxEntries added in v1.3.2

type MaxEntries struct {
	Val uint32
	Set bool
}

type MissingConstantsError added in v1.3.2

type MissingConstantsError struct {
	// The constants missing from .rodata.
	Constants []string
}

MissingConstantsError is returned by [rewriteConstants].

func (*MissingConstantsError) Error added in v1.3.2

func (m *MissingConstantsError) Error() string

type MultiKprobeAttachData added in v1.3.2

type MultiKprobeAttachData struct {
	Symbols   []string
	Cookies   []uint64
	Overrides []string
}

type MultiUprobeAttachData added in v1.3.2

type MultiUprobeAttachData struct {
	// Path -> []{Symbol,Cookie}
	Attach map[string]*MultiUprobeAttachSymbolsCookies
}

type MultiUprobeAttachSymbolsCookies added in v1.3.2

type MultiUprobeAttachSymbolsCookies struct {
	Symbols []string
	Cookies []uint64
}

type OpenFunc added in v1.3.2

type OpenFunc func(*ebpf.CollectionSpec) error

func KprobeOpen added in v1.3.2

func KprobeOpen(load *Program) OpenFunc

func LSMOpen added in v1.3.2

func LSMOpen(load *Program) OpenFunc

type Program

type Program struct {
	// Name is the name of the BPF object file.
	Name string
	// Attach is the attachment point, e.g. the kernel function.
	Attach string
	// Label is the program section name to load from program.
	Label string
	// PinPath is the pinned path to this program. Note this is a relative path
	// based on the BPF directory FGS is running under.
	PinPath string
	// PinName
	PinName string

	// RetProbe indicates whether a kprobe is a kretprobe.
	RetProbe bool
	// ErrorFatal indicates whether a program must load and fatal otherwise.
	// Most program will set this to true. For example, kernel functions hooks
	// may change across verions so different names are attempted, hence
	// avoiding fataling when the first attempt fails.
	ErrorFatal bool

	// Needs override bpf program
	Override        bool
	OverrideFmodRet bool

	// Type is the type of BPF program. For example, tc, skb, tracepoint,
	// etc.
	Type      string
	LoadState State

	// LoaderData represents per-type specific fields.
	LoaderData interface{}

	// AttachData represents specific data for attaching probe
	AttachData interface{}

	// Functions to call after loading maps to populate them
	MapLoad []*MapLoad

	PinMap map[string]*Map

	// available when program.KeepCollection is true
	LC *LoadedCollection

	RewriteConstants map[string]interface{}

	// Type information used for CO-RE relocations.
	KernelTypes *btf.Spec

	// Tail call prefix/map
	TcPrefix string
	TcMap    *Map

	Link link.Link
	Prog *ebpf.Program

	// policy name the program belongs to
	Policy string

	// Information of all maps used and loaded by this program by map ID. This
	// is populated after load and used for map memlock accounting.
	LoadedMapsInfo map[int]bpf.ExtendedMapInfo
	// contains filtered or unexported fields
}

Program reprents a BPF program.

func Builder

func Builder(
	objFile, attach, label, pinName string,
	ty string,
) *Program
func (p *Program) Relink() error

func (*Program) SetAttachData added in v1.3.2

func (p *Program) SetAttachData(d interface{}) *Program

func (*Program) SetLoaderData

func (p *Program) SetLoaderData(d interface{}) *Program

func (*Program) SetPolicy added in v1.3.2

func (p *Program) SetPolicy(policy string) *Program

func (*Program) SetRetProbe

func (p *Program) SetRetProbe(ret bool) *Program

func (*Program) SetTailCall added in v1.3.2

func (p *Program) SetTailCall(prefix string, m *Map) *Program

func (*Program) String added in v1.3.2

func (p *Program) String() string
func (p *Program) Unlink() error

func (*Program) Unload

func (p *Program) Unload(unpin bool) error

type State

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

State represents the state of a BPF program or map.

NB: Currently there is no case where we attempt to load a program that is already loaded. If this changes, we can use the count as a reference count to track users of a bpf program.

func Idle

func Idle() State

func (*State) IsLoaded

func (s *State) IsLoaded() bool

func (*State) RefDec

func (s *State) RefDec() int

func (*State) RefInc

func (s *State) RefInc()

type UprobeAttachData added in v1.3.2

type UprobeAttachData struct {
	Path   string
	Symbol string
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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