Documentation
¶
Index ¶
- Constants
- Variables
- func BPFHelperIsSupported(progType BPFProgType, funcId BPFFunc) (bool, error)
- func BPFMapTypeIsSupported(mapType MapType) (bool, error)
- func BPFProgramTypeIsSupported(progType BPFProgType) (bool, error)
- func CalcMapValueSize(valueSize int, mapType MapType) (int, error)
- func GetBTFFDByID(id uint32) (int, error)
- func GetMapFDByID(id uint32) (int, error)
- func GetMapNextID(startId uint32) (uint32, error)
- func GetMapsIDsByName(name string, startId *uint32) ([]uint32, error)
- func LibbpfVersionString() string
- func MajorVersion() int
- func MinorVersion() int
- func NumPossibleCPUs() (int, error)
- func SetLoggerCbs(cbs Callbacks)
- func SetStrictMode(mode LibbpfStrictMode)
- type AttachFlag
- type BPFAttachType
- type BPFCgroupIterOrder
- type BPFFunc
- type BPFLink
- type BPFLinkReader
- type BPFMap
- func (m *BPFMap) AttachStructOps() (*BPFLink, error)
- func (m *BPFMap) Autocreate() bool
- func (m *BPFMap) BTFKeyTypeID() uint32
- func (m *BPFMap) BTFValueTypeID() uint32
- func (m *BPFMap) DeleteKey(key unsafe.Pointer) error
- func (m *BPFMap) DeleteKeyBatch(keys unsafe.Pointer, count uint32) (uint32, error)
- func (m *BPFMap) FileDescriptor() int
- func (m *BPFMap) GetFd() intdeprecated
- func (m *BPFMap) GetMaxEntries() uint32deprecated
- func (m *BPFMap) GetModule() *Moduledeprecated
- func (m *BPFMap) GetName() stringdeprecated
- func (m *BPFMap) GetNextKey(key unsafe.Pointer, nextKey unsafe.Pointer) error
- func (m *BPFMap) GetPinPath() stringdeprecated
- func (m *BPFMap) GetValue(key unsafe.Pointer) ([]byte, error)
- func (m *BPFMap) GetValueAndDeleteBatch(keys, startKey, nextKey unsafe.Pointer, count uint32) ([][]byte, uint32, error)
- func (m *BPFMap) GetValueAndDeleteKey(key unsafe.Pointer) ([]byte, error)
- func (m *BPFMap) GetValueAndDeleteKeyFlags(key unsafe.Pointer, flags MapFlag) ([]byte, error)
- func (m *BPFMap) GetValueBatch(keys, startKey, nextKey unsafe.Pointer, count uint32) ([][]byte, uint32, error)
- func (m *BPFMap) GetValueFlags(key unsafe.Pointer, flags MapFlag) ([]byte, error)
- func (m *BPFMap) GetValueReadInto(key unsafe.Pointer, value *[]byte) errordeprecated
- func (m *BPFMap) IfIndex() uint32
- func (m *BPFMap) InitialValue() ([]byte, error)
- func (m *BPFMap) InnerMapInfo() (*BPFMapInfo, error)
- func (m *BPFMap) IsPinned() bool
- func (m *BPFMap) Iterator() *BPFMapIterator
- func (m *BPFMap) KeySize() int
- func (m *BPFMap) LookupAndDeleteElem(key unsafe.Pointer, value unsafe.Pointer, valueSize uint64, flags MapFlag) error
- func (m *BPFMap) MapExtra() uint64
- func (m *BPFMap) MapFlags() MapFlag
- func (m *BPFMap) MaxEntries() uint32
- func (m *BPFMap) Module() *Module
- func (m *BPFMap) Name() string
- func (m *BPFMap) Pin(pinPath string) error
- func (m *BPFMap) PinPath() string
- func (m *BPFMap) Resize(maxEntries uint32) errordeprecated
- func (m *BPFMap) ReuseFD(fd int) error
- func (m *BPFMap) SetAutocreate(autocreate bool) error
- func (m *BPFMap) SetInitialValue(value unsafe.Pointer) error
- func (m *BPFMap) SetInnerMap(templateMapFD int) error
- func (m *BPFMap) SetKeySize(size uint32) error
- func (m *BPFMap) SetMaxEntries(maxEntries uint32) error
- func (m *BPFMap) SetPinPath(pinPath string) error
- func (m *BPFMap) SetType(mapType MapType) error
- func (m *BPFMap) SetValueSize(size uint32) error
- func (m *BPFMap) Type() MapType
- func (m *BPFMap) Unpin(pinPath string) error
- func (m *BPFMap) Update(key, value unsafe.Pointer) error
- func (m *BPFMap) UpdateBatch(keys, values unsafe.Pointer, count uint32) (uint32, error)
- func (m *BPFMap) UpdateValueFlags(key, value unsafe.Pointer, flags MapFlag) error
- func (m *BPFMap) ValueSize() int
- type BPFMapCreateOpts
- type BPFMapInfo
- type BPFMapIterator
- type BPFMapLow
- func (m *BPFMapLow) DeleteKey(key unsafe.Pointer) error
- func (m *BPFMapLow) DeleteKeyBatch(keys unsafe.Pointer, count uint32) (uint32, error)
- func (m *BPFMapLow) FileDescriptor() int
- func (m *BPFMapLow) GetNextKey(key unsafe.Pointer, nextKey unsafe.Pointer) error
- func (m *BPFMapLow) GetValue(key unsafe.Pointer) ([]byte, error)
- func (m *BPFMapLow) GetValueAndDeleteBatch(keys, startKey, nextKey unsafe.Pointer, count uint32) ([][]byte, uint32, error)
- func (m *BPFMapLow) GetValueAndDeleteKey(key unsafe.Pointer) ([]byte, error)
- func (m *BPFMapLow) GetValueAndDeleteKeyFlags(key unsafe.Pointer, flags MapFlag) ([]byte, error)
- func (m *BPFMapLow) GetValueBatch(keys, startKey, nextKey unsafe.Pointer, count uint32) ([][]byte, uint32, error)
- func (m *BPFMapLow) GetValueFlags(key unsafe.Pointer, flags MapFlag) ([]byte, error)
- func (m *BPFMapLow) Iterator() *BPFMapIterator
- func (m *BPFMapLow) KeySize() int
- func (m *BPFMapLow) LookupAndDeleteElem(key unsafe.Pointer, value unsafe.Pointer) error
- func (m *BPFMapLow) LookupAndDeleteElemFlags(key unsafe.Pointer, value unsafe.Pointer, flags MapFlag) error
- func (m *BPFMapLow) MaxEntries() uint32
- func (m *BPFMapLow) Name() string
- func (m *BPFMapLow) ReuseFD(fd int) error
- func (m *BPFMapLow) Type() MapType
- func (m *BPFMapLow) Update(key, value unsafe.Pointer) error
- func (m *BPFMapLow) UpdateBatch(keys, values unsafe.Pointer, count uint32) (uint32, error)
- func (m *BPFMapLow) UpdateValueFlags(key, value unsafe.Pointer, flags MapFlag) error
- func (m *BPFMapLow) ValueSize() int
- type BPFObjectIterator
- type BPFProg
- func (p *BPFProg) AttachCgroup(cgroupV2DirPath string) (*BPFLink, error)
- func (p *BPFProg) AttachCgroupLegacy(cgroupV2DirPath string, attachType BPFAttachType) (*BPFLink, error)
- func (p *BPFProg) AttachGeneric() (*BPFLink, error)
- func (p *BPFProg) AttachGenericFD(targetFd int, attachType BPFAttachType, flags AttachFlag) error
- func (p *BPFProg) AttachIter(opts IterOpts) (*BPFLink, error)
- func (p *BPFProg) AttachKprobe(symbol string) (*BPFLink, error)
- func (p *BPFProg) AttachKprobeOffset(offset uint64) (*BPFLink, error)
- func (p *BPFProg) AttachKretprobe(symbol string) (*BPFLink, error)
- func (p *BPFProg) AttachKretprobeOnOffset(offset uint64) (*BPFLink, error)
- func (p *BPFProg) AttachLSM() (*BPFLink, error)
- func (p *BPFProg) AttachNetns(networkNamespacePath string) (*BPFLink, error)
- func (p *BPFProg) AttachPerfEvent(fd int) (*BPFLink, error)
- func (p *BPFProg) AttachRawTracepoint(tpEvent string) (*BPFLink, error)
- func (p *BPFProg) AttachTCX(deviceName string) (*BPFLink, error)
- func (p *BPFProg) AttachTracepoint(category, name string) (*BPFLink, error)
- func (p *BPFProg) AttachURetprobe(pid int, path string, offset uint64) (*BPFLink, error)
- func (p *BPFProg) AttachURetprobeMulti(pid int, path string, offsets, cookies []uint64) (*BPFLink, error)
- func (p *BPFProg) AttachUSDT(pid int, binaryPath string, provider string, name string) (*BPFLink, error)
- func (p *BPFProg) AttachUprobe(pid int, path string, offset uint64) (*BPFLink, error)
- func (p *BPFProg) AttachUprobeMulti(pid int, path string, offsets, cookies []uint64) (*BPFLink, error)
- func (p *BPFProg) AttachXDP(deviceName string) (*BPFLink, error)
- func (p *BPFProg) AttachXDPLegacy(deviceName string, flag XDPFlags) error
- func (p *BPFProg) Autoattach() bool
- func (p *BPFProg) Autoload() bool
- func (p *BPFProg) DetachCgroupLegacy(cgroupV2DirPath string, attachType BPFAttachType) error
- func (p *BPFProg) DetachGenericFD(targetFd int, attachType BPFAttachType) error
- func (p *BPFProg) DetachXDPLegacy(deviceName string, flag XDPFlags) error
- func (p *BPFProg) FileDescriptor() int
- func (p *BPFProg) GetFd() intdeprecated
- func (p *BPFProg) GetModule() *Module
- func (p *BPFProg) GetName() stringdeprecated
- func (p *BPFProg) GetPinPath() stringdeprecated
- func (p *BPFProg) GetSectionName() stringdeprecated
- func (p *BPFProg) GetType() BPFProgType
- func (p *BPFProg) Name() string
- func (p *BPFProg) Pin(path string) error
- func (p *BPFProg) PinPath() string
- func (p *BPFProg) Run(opts *RunOpts) error
- func (p *BPFProg) SectionName() string
- func (p *BPFProg) SetAttachTarget(attachProgFD int, attachFuncName string) error
- func (p *BPFProg) SetAttachType(attachType BPFAttachType)deprecated
- func (p *BPFProg) SetAutoattach(autoload bool)
- func (p *BPFProg) SetAutoload(autoload bool) error
- func (p *BPFProg) SetExpectedAttachType(attachType BPFAttachType) error
- func (p *BPFProg) SetProgramType(progType BPFProgType)deprecated
- func (p *BPFProg) SetType(progType BPFProgType) error
- func (p *BPFProg) Unpin(path string) error
- type BPFProgType
- type Callbacks
- type IterOpts
- type LibbpfStrictMode
- type LinkType
- type MapFlag
- type MapType
- type Module
- func (m *Module) AddRingBuf(ringBuf *RingBuffer, mapName string, eventsChan chan []byte) (bool, error)
- func (m *Module) AttachPrograms() error
- func (m *Module) BPFLoadObject() error
- func (m *Module) Close()
- func (m *Module) DetachPrograms() error
- func (m *Module) GetMap(mapName string) (*BPFMap, error)
- func (m *Module) GetProgram(progName string) (*BPFProg, error)
- func (m *Module) InitGlobalVariable(name string, value interface{}) error
- func (m *Module) InitPerfBuf(mapName string, eventsChan chan []byte, lostChan chan uint64, pageCnt int) (*PerfBuffer, error)
- func (m *Module) InitRingBuf(mapName string, eventsChan chan []byte) (*RingBuffer, error)
- func (m *Module) InitUserRingBuf(mapName string, eventsChan chan []byte) (*UserRingBuffer, error)
- func (m *Module) Iterator() *BPFObjectIterator
- func (m *Module) TcHookInit() *TcHook
- type NewModuleArgs
- type PerfBuffer
- type RingBuffer
- type RunFlag
- type RunOpts
- type Symbol
- type TcAttachPoint
- type TcFlags
- type TcHook
- func (hook *TcHook) Attach(tcOpts *TcOpts) error
- func (hook *TcHook) Create() error
- func (hook *TcHook) Destroy() error
- func (hook *TcHook) Detach(tcOpts *TcOpts) error
- func (hook *TcHook) GetInterfaceIndex() int
- func (hook *TcHook) Query(tcOpts *TcOpts) error
- func (hook *TcHook) SetAttachPoint(attachPoint TcAttachPoint)
- func (hook *TcHook) SetInterfaceByIndex(ifaceIdx int)
- func (hook *TcHook) SetInterfaceByName(ifaceName string) error
- func (hook *TcHook) SetParent(a int, b int)
- type TcOpts
- type UserRingBuffer
- type XDPFlags
Constants ¶
const ( // libbpf print levels LibbpfWarnLevel = int(C.LIBBPF_WARN) LibbpfInfoLevel = int(C.LIBBPF_INFO) LibbpfDebugLevel = int(C.LIBBPF_DEBUG) )
Variables ¶
var ErrNoInnerMap = errors.New("map has no inner map")
Functions ¶
func BPFHelperIsSupported ¶
func BPFHelperIsSupported(progType BPFProgType, funcId BPFFunc) (bool, error)
BPFHelperIsSupported checks if a specific BPF helper function is supported for a given program type. This function probes the BPF helper using libbpf and returns whether the helper is supported.
Important Notes for the Caller:
libbpf probes may return success (`true`) even if the BPF program load would fail due to permission issues (EPERM). To ensure reliability, it is necessary to either run with sufficient capabilities or explicitly check for EPERM. Reference: https://github.com/libbpf/bpftool/blob/a5c058054cc71836930e232162e8bd1ec6705eaf/src/feature.c#L694-L701
libbpf does not always clear `errno` in certain scenarios. For example, if the file `/proc/version_signature` is missing, libbpf may set `errno` to ENOENT (errno=2) and leave it uncleared, even if the helper is supported. Reference: https://github.com/libbpf/libbpf/blob/09b9e83102eb8ab9e540d36b4559c55f3bcdb95d/src/libbpf_probes.c#L33-L39
If the function returns `true` while running with appropriate capabilities, the helper is assumed to be supported. This behavior is documented in libbpf: Reference: https://github.com/libbpf/libbpf/blob/09b9e83102eb8ab9e540d36b4559c55f3bcdb95d/src/libbpf_probes.c#L448-L464
Caveats:
- A return value of `true` does not guarantee that the BPF program will load successfully. It is critical to verify permissions or run with sufficient capabilities for accurate results.
- If `retC < 0`, the helper is not supported. In such cases, additional details can be found in `errno`.
func BPFMapTypeIsSupported ¶
func BPFProgramTypeIsSupported ¶
func BPFProgramTypeIsSupported(progType BPFProgType) (bool, error)
func CalcMapValueSize ¶
CalcMapValueSize calculates the size of the value for a map. For per-CPU maps, it is calculated based on the number of possible CPUs.
func GetBTFFDByID ¶
GetBTFFDByID returns a file descriptor for the BTF with the given ID.
func GetMapFDByID ¶
GetMapFDByID returns a file descriptor for the map with the given ID.
func GetMapNextID ¶
GetMapNextID retrieves the next available map ID after the given startID. It returns the next map ID and an error if one occurs during the operation.
func GetMapsIDsByName ¶
GetMapsIDsByName searches for maps with a specified name and collects their IDs. It starts the search from the given 'startId' and continues until no more matching maps are found. The function returns a slice of unsigned 32-bit integers representing the IDs of matching maps. If no maps with the provided 'name' are found, it returns an empty slice and no error. The 'startId' is modified and returned as the last processed map ID.
Example Usage:
name := "myMap" // The name of the map you want to find.
startId := uint32(0) // The map ID to start the search from.
var mapIDs []uint32 // Initialize an empty slice to collect map IDs.
var err error // Initialize an error variable.
// Retry mechanism in case of errors using the last processed 'startId'.
for {
mapIDs, err = GetMapsIDsByName(name, startId)
if err != nil {
// Handle other errors, possibly with a retry mechanism.
// You can use the 'startId' who contains the last processed map ID to continue the search.
} else {
// Successful search, use the 'mapIDs' slice containing the IDs of matching maps.
// Update 'startId' to the last processed map ID to continue the search.
}
}
func LibbpfVersionString ¶
func LibbpfVersionString() string
LibbpfVersionString returns the string representation of the libbpf version which libbpfgo is linked against
func MajorVersion ¶
func MajorVersion() int
MajorVersion returns the major semver version of libbpf.
func MinorVersion ¶
func MinorVersion() int
MinorVersion returns the minor semver version of libbpf.
func NumPossibleCPUs ¶
func SetLoggerCbs ¶
func SetLoggerCbs(cbs Callbacks)
SetLoggerCbs receives Callbacks type to be used to log libbpf outputs and to filter out those outputs
func SetStrictMode ¶
func SetStrictMode(mode LibbpfStrictMode)
SetStrictMode is no-op as of libbpf v1.0
Types ¶
type AttachFlag ¶
type AttachFlag uint32
const ( BPFFNone AttachFlag = 0 BPFFAllowOverride AttachFlag = C.BPF_F_ALLOW_OVERRIDE BPFFAllowMulti AttachFlag = C.BPF_F_ALLOW_MULTI BPFFReplace AttachFlag = C.BPF_F_REPLACE BPFFBefore AttachFlag = C.BPF_F_BEFORE BPFFAfter AttachFlag = C.BPF_F_AFTER BPFFID AttachFlag = C.BPF_F_ID BPFFLink AttachFlag = C.BPF_F_LINK )
type BPFAttachType ¶
type BPFAttachType uint32
const ( BPFAttachTypeCgroupInetIngress BPFAttachType = C.BPF_CGROUP_INET_INGRESS BPFAttachTypeCgroupInetEgress BPFAttachType = C.BPF_CGROUP_INET_EGRESS BPFAttachTypeCgroupInetSockCreate BPFAttachType = C.BPF_CGROUP_INET_SOCK_CREATE BPFAttachTypeCgroupSockOps BPFAttachType = C.BPF_CGROUP_SOCK_OPS BPFAttachTypeSKSKBStreamParser BPFAttachType = C.BPF_SK_SKB_STREAM_PARSER BPFAttachTypeSKSKBStreamVerdict BPFAttachType = C.BPF_SK_SKB_STREAM_VERDICT BPFAttachTypeCgroupDevice BPFAttachType = C.BPF_CGROUP_DEVICE BPFAttachTypeSKMSGVerdict BPFAttachType = C.BPF_SK_MSG_VERDICT BPFAttachTypeCgroupInet4Bind BPFAttachType = C.BPF_CGROUP_INET4_BIND BPFAttachTypeCgroupInet6Bind BPFAttachType = C.BPF_CGROUP_INET6_BIND BPFAttachTypeCgroupInet4Connect BPFAttachType = C.BPF_CGROUP_INET4_CONNECT BPFAttachTypeCgroupInet6Connect BPFAttachType = C.BPF_CGROUP_INET6_CONNECT BPFAttachTypeCgroupInet4PostBind BPFAttachType = C.BPF_CGROUP_INET4_POST_BIND BPFAttachTypeCgroupInet6PostBind BPFAttachType = C.BPF_CGROUP_INET6_POST_BIND BPFAttachTypeCgroupUDP4SendMsg BPFAttachType = C.BPF_CGROUP_UDP4_SENDMSG BPFAttachTypeCgroupUDP6SendMsg BPFAttachType = C.BPF_CGROUP_UDP6_SENDMSG BPFAttachTypeLircMode2 BPFAttachType = C.BPF_LIRC_MODE2 BPFAttachTypeFlowDissector BPFAttachType = C.BPF_FLOW_DISSECTOR BPFAttachTypeCgroupSysctl BPFAttachType = C.BPF_CGROUP_SYSCTL BPFAttachTypeCgroupUDP4RecvMsg BPFAttachType = C.BPF_CGROUP_UDP4_RECVMSG BPFAttachTypeCgroupUDP6RecvMsg BPFAttachType = C.BPF_CGROUP_UDP6_RECVMSG BPFAttachTypeCgroupGetSockOpt BPFAttachType = C.BPF_CGROUP_GETSOCKOPT BPFAttachTypeCgroupSetSockOpt BPFAttachType = C.BPF_CGROUP_SETSOCKOPT BPFAttachTypeTraceRawTP BPFAttachType = C.BPF_TRACE_RAW_TP BPFAttachTypeTraceFentry BPFAttachType = C.BPF_TRACE_FENTRY BPFAttachTypeTraceFexit BPFAttachType = C.BPF_TRACE_FEXIT BPFAttachTypeModifyReturn BPFAttachType = C.BPF_MODIFY_RETURN BPFAttachTypeLSMMac BPFAttachType = C.BPF_LSM_MAC BPFAttachTypeTraceIter BPFAttachType = C.BPF_TRACE_ITER BPFAttachTypeCgroupInet4GetPeerName BPFAttachType = C.BPF_CGROUP_INET4_GETPEERNAME BPFAttachTypeCgroupInet6GetPeerName BPFAttachType = C.BPF_CGROUP_INET6_GETPEERNAME BPFAttachTypeCgroupInet4GetSockName BPFAttachType = C.BPF_CGROUP_INET4_GETSOCKNAME BPFAttachTypeCgroupInet6GetSockName BPFAttachType = C.BPF_CGROUP_INET6_GETSOCKNAME BPFAttachTypeXDPDevMap BPFAttachType = C.BPF_XDP_DEVMAP BPFAttachTypeCgroupInetSockRelease BPFAttachType = C.BPF_CGROUP_INET_SOCK_RELEASE BPFAttachTypeXDPCPUMap BPFAttachType = C.BPF_XDP_CPUMAP BPFAttachTypeSKLookup BPFAttachType = C.BPF_SK_LOOKUP BPFAttachTypeXDP BPFAttachType = C.BPF_XDP BPFAttachTypeSKSKBVerdict BPFAttachType = C.BPF_SK_SKB_VERDICT BPFAttachTypeSKReusePortSelect BPFAttachType = C.BPF_SK_REUSEPORT_SELECT BPFAttachTypeSKReusePortSelectorMigrate BPFAttachType = C.BPF_SK_REUSEPORT_SELECT_OR_MIGRATE BPFAttachTypePerfEvent BPFAttachType = C.BPF_PERF_EVENT BPFAttachTypeTraceKprobeMulti BPFAttachType = C.BPF_TRACE_KPROBE_MULTI BPFAttachTypeLSMCgroup BPFAttachType = C.BPF_LSM_CGROUP BPFAttachTypeStructOps BPFAttachType = C.BPF_STRUCT_OPS BPFAttachTypeNetfilter BPFAttachType = C.BPF_NETFILTER BPFAttachTypeTCXIngress BPFAttachType = C.BPF_TCX_INGRESS BPFAttachTypeTCXEgress BPFAttachType = C.BPF_TCX_EGRESS BPFAttachTypeTraceUprobeMulti BPFAttachType = C.BPF_TRACE_UPROBE_MULTI BPFAttachTypeCgroupUnixConnect BPFAttachType = C.BPF_CGROUP_UNIX_CONNECT BPFAttachTypeCgroupUnixSendMsg BPFAttachType = C.BPF_CGROUP_UNIX_SENDMSG BPFAttachTypeCgroupUnixRecvMsg BPFAttachType = C.BPF_CGROUP_UNIX_RECVMSG BPFAttachTypeCgroupUnixGetPeerName BPFAttachType = C.BPF_CGROUP_UNIX_GETPEERNAME BPFAttachTypeCgroupUnixGetSockName BPFAttachType = C.BPF_CGROUP_UNIX_GETSOCKNAME BPFAttachTypeNetkitPrimary BPFAttachType = C.BPF_NETKIT_PRIMARY BPFAttachTypeNetkitPeer BPFAttachType = C.BPF_NETKIT_PEER BPFAttachTypeTraceKprobeSession BPFAttachType = C.BPF_TRACE_KPROBE_SESSION )
func (BPFAttachType) Name ¶
func (t BPFAttachType) Name() string
func (BPFAttachType) String ¶
func (t BPFAttachType) String() string
type BPFCgroupIterOrder ¶
type BPFCgroupIterOrder uint32
const ( BPFIterOrderUnspec BPFCgroupIterOrder = iota BPFIterSelfOnly BPFIterDescendantsPre BPFIterDescendantsPost BPFIterAncestorsUp )
type BPFFunc ¶
type BPFFunc uint32
BPFFunc is an enum as defined in https://elixir.bootlin.com/linux/latest/source/include/uapi/linux/bpf.h
const ( BPFFuncUnspec BPFFunc = iota BPFFuncMapLookupElem BPFFuncMapUpdateElem BPFFuncMapDeleteElem BPFFuncProbeRead BPFFuncKtimeGetNs BPFFuncTracePrintk BPFFuncGetPrandomU32 BPFFuncGetSmpProcessorId BPFFuncSkbStoreBytes BPFFuncL3CsumReplace BPFFuncL4CsumReplace BPFFuncTailCall BPFFuncCloneRedirect BPFFuncGetCurrentPidTgid BPFFuncGetCurrentUidGid BPFFuncGetCurrentComm BPFFuncGetCgroupClassid BPFFuncSkbVlanPush BPFFuncSkbVlanPop BPFFuncSkbGetTunnelKey BPFFuncSkbSetTunnelKey BPFFuncPerfEventRead BPFFuncRedirect BPFFuncGetRouteRealm BPFFuncPerfEventOutput BPFFuncSkbLoadBytes BPFFuncGetStackid BPFFuncCsumDiff BPFFuncSkbGetTunnelOpt BPFFuncSkbSetTunnelOpt BPFFuncSkbChangeProto BPFFuncSkbChangeType BPFFuncSkbUnderCgroup BPFFuncGetHashRecalc BPFFuncGetCurrentTask BPFFuncProbeWriteUser BPFFuncCurrentTaskUnderCgroup BPFFuncSkbChangeTail BPFFuncSkbPullData BPFFuncCsumUpdate BPFFuncSetHashInvalid BPFFuncGetNumaNodeId BPFFuncSkbChangeHead BPFFuncXdpAdjustHead BPFFuncProbeReadStr BPFFuncGetSocketCookie BPFFuncGetSocketUid BPFFuncSetHash BPFFuncSetsockopt BPFFuncSkbAdjustRoom BPFFuncRedirectMap BPFFuncSkRedirectMap BPFFuncSockMapUpdate BPFFuncXdpAdjustMeta BPFFuncPerfEventReadValue BPFFuncPerfProgReadValue BPFFuncGetsockopt BPFFuncOverrideReturn BPFFuncSockOpsCbFlagsSet BPFFuncMsgRedirectMap BPFFuncMsgApplyBytes BPFFuncMsgCorkBytes BPFFuncMsgPullData BPFFuncBind BPFFuncXdpAdjustTail BPFFuncSkbGetXfrmState BPFFuncGetStack BPFFuncSkbLoadBytesRelative BPFFuncFibLookup BPFFuncSockHashUpdate BPFFuncMsgRedirectHash BPFFuncSkRedirectHash BPFFuncLwtPushEncap BPFFuncLwtSeg6StoreBytes BPFFuncLwtSeg6AdjustSrh BPFFuncLwtSeg6Action BPFFuncRcRepeat BPFFuncRcKeydown BPFFuncSkbCgroupId BPFFuncGetCurrentCgroupId BPFFuncGetLocalStorage BPFFuncSkSelectReuseport BPFFuncSkbAncestorCgroupId BPFFuncSkLookupTcp BPFFuncSkLookupUdp BPFFuncSkRelease BPFFuncMapPushElem BPFFuncMapPopElem BPFFuncMapPeekElem BPFFuncMsgPushData BPFFuncMsgPopData BPFFuncRcPointerRel BPFFuncSpinLock BPFFuncSpinUnlock BPFFuncSkFullsock BPFFuncTcpSock BPFFuncSkbEcnSetCe BPFFuncGetListenerSock BPFFuncSkcLookupTcp BPFFuncSysctlGetName BPFFuncSysctlGetCurrentValue BPFFuncSysctlGetNewValue BPFFuncSysctlSetNewValue BPFFuncStrtol BPFFuncStrtoul BPFFuncSkStorageGet BPFFuncSkStorageDelete BPFFuncSendSignal BPFFuncSkbOutput BPFFuncProbeReadUser BPFFuncProbeReadKernel BPFFuncProbeReadUserStr BPFFuncProbeReadKernelStr BPFFuncTcpSendAck BPFFuncSendSignalThread BPFFuncJiffies64 BPFFuncReadBranchRecords BPFFuncGetNsCurrentPidTgid BPFFuncXdpOutput BPFFuncGetNetnsCookie BPFFuncGetCurrentAncestorCgroupId BPFFuncSkAssign BPFFuncKtimeGetBootNs BPFFuncSeqPrintf BPFFuncSeqWrite BPFFuncSkCgroupId BPFFuncSkAncestorCgroupId BPFFuncRingbufOutput BPFFuncRingbufReserve BPFFuncRingbufSubmit BPFFuncRingbufDiscard BPFFuncRingbufQuery BPFFuncCsumLevel BPFFuncSkcToTcp6Sock BPFFuncSkcToTcpSock BPFFuncSkcToTcpTimewaitSock BPFFuncSkcToTcpRequestSock BPFFuncSkcToUdp6Sock BPFFuncGetTaskStack BPFFuncLoadHdrOpt BPFFuncStoreHdrOpt BPFFuncReserveHdrOpt BPFFuncInodeStorageGet BPFFuncInodeStorageDelete BPFFuncDPath BPFFuncCopyFromUser BPFFuncSnprintfBtf BPFFuncSeqPrintfBtf BPFFuncSkbCgroupClassid BPFFuncRedirectNeigh BPFFuncPerCpuPtr BPFFuncThisCpuPtr BPFFuncRedirectPeer BPFFuncTaskStorageGet BPFFuncTaskStorageDelete BPFFuncGetCurrentTaskBtf BPFFuncBprmOptsSet BPFFuncKtimeGetCoarseNs BPFFuncImaInodeHash BPFFuncSockFromFile BPFFuncCheckMtu BPFFuncForEachMapElem BPFFuncSnprintf BPFFuncSysBpf BPFFuncBtfFindByNameKind BPFFuncSysClose BPFFuncTimerInit BPFFuncTimerSetCallback BPFFuncTimerStart BPFFuncTimerCancel BPFFuncGetFuncIp BPFFuncGetAttachCookie BPFFuncTaskPtRegs BPFFuncGetBranchSnapshot BPFFuncTraceVprintk BPFFuncSkcToUnixSock BPFFuncKallsymsLookupName BPFFuncFindVma BPFFuncLoop BPFFuncStrncmp BPFFuncGetFuncArg BPFFuncGetFuncRet BPFFuncGetFuncArgCnt BPFFuncGetRetval BPFFuncSetRetval BPFFuncXdpGetBuffLen BPFFuncXdpLoadBytes BPFFuncXdpStoreBytes BPFFuncCopyFromUserTask BPFFuncSkbSetTstamp BPFFuncImaFileHash BPFFuncKptrXchg BPFFuncMapLookupPercpuElem BPFFuncSkcToMptcpSock BPFFuncDynptrFromMem BPFFuncRingbufReserveDynptr BPFFuncRingbufSubmitDynptr BPFFuncRingbufDiscardDynptr BPFFuncDynptrRead BPFFuncDynptrWrite BPFFuncDynptrData BPFFuncKtimeGetTaiNs BPFFuncUserRingbufDrain BPFFuncCgrpStorageGet BPFFuncCgrpStorageDelete )
type BPFLink ¶
type BPFLink struct {
// contains filtered or unexported fields
}
func (*BPFLink) DestroyLegacy ¶
func (*BPFLink) FileDescriptor ¶
func (*BPFLink) Reader ¶
func (l *BPFLink) Reader() (*BPFLinkReader, error)
type BPFLinkReader ¶
type BPFLinkReader struct {
// contains filtered or unexported fields
}
BPFLinkReader read data from a BPF link
func (*BPFLinkReader) Close ¶
func (i *BPFLinkReader) Close() error
type BPFMap ¶
type BPFMap struct {
// contains filtered or unexported fields
}
BPFMap is a wrapper around a libbpf bpf_map.
func (*BPFMap) AttachStructOps ¶
func (*BPFMap) Autocreate ¶
func (*BPFMap) BTFKeyTypeID ¶
func (*BPFMap) BTFValueTypeID ¶
func (*BPFMap) DeleteKey ¶
DeleteKey removes a specified key and its associated value from the BPFMap.
This function accepts an unsafe.Pointer that references the key to be removed from the map. All basic types, and structs are supported as keys.
NOTE: Slices and arrays are supported, but references should point to the first element in the slice or array, instead of the slice or array itself. This is crucial to prevent undefined behavior.
func (*BPFMap) DeleteKeyBatch ¶
DeleteKeyBatch deletes multiple elements from the map by specified keys.
The first argument, keys, is a pointer to an array or slice of keys which will be deleted.
The last argument, count, is the number of keys to delete.
It returns the number of elements that were deleted.
The API can delete fewer elements than requested even though the underlying logic received -1. For checking if the deleted elements are partial, you can compare the number of elements returned with the passed count. See the comment in `BPFMapLow.GetValueBatch` for more context.
func (*BPFMap) FileDescriptor ¶
func (*BPFMap) GetMaxEntries
deprecated
func (*BPFMap) GetNextKey ¶
GetNextKey allows to iterate BPF map keys by fetching next key that follows current key.
func (*BPFMap) GetPinPath
deprecated
func (*BPFMap) GetValue ¶
GetValue retrieves the value associated with a given key in the BPFMap.
This function accepts an unsafe.Pointer to the key value to be searched in the map, and it returns the corresponding value as a slice of bytes. All basic types, and structs are supported as keys.
NOTE: Slices and arrays are supported, but references should point to the first element in the slice or array, instead of the slice or array itself. This is crucial to prevent undefined behavior.
For example:
key := []byte{'a', 'b', 'c'} keyPtr := unsafe.Pointer(&key[0]) bpfmap.GetValue(keyPtr)
func (*BPFMap) GetValueAndDeleteBatch ¶
func (m *BPFMap) GetValueAndDeleteBatch(keys, startKey, nextKey unsafe.Pointer, count uint32) ([][]byte, uint32, error)
GetValueAndDeleteBatch allows for batch lookup and deletion of elements where each element is deleted after being retrieved from the map.
The first argument, keys, is a pointer to an array or slice of keys which will be populated with the keys returned from this operation.
This API allows for batch lookups and deletion of multiple keys, potentially in steps over multiple iterations. For example, you provide the last key seen (or nil) for the startKey, and the first key to start the next iteration with in nextKey. Once the first iteration is complete you can provide the last key seen in the previous iteration as the startKey for the next iteration and repeat until nextKey is nil.
The last argument, count, is the number of keys to lookup and delete.
It returns the associated values as a slice of slices of bytes and the number of elements that were retrieved and deleted.
The API can return partial results even though the underlying logic received -1. In this case, no error will be returned. For checking if the returned values are partial, you can compare the number of elements returned with the passed count. See the comment in `BPFMapLow.GetValueBatch` for more context.
func (*BPFMap) GetValueAndDeleteKey ¶
GetValueAndDeleteKey retrieves the value associated with a given key and delete the key in the BPFMap. It returns the value as a slice of bytes.
func (*BPFMap) GetValueAndDeleteKeyFlags ¶
GetValueAndDeleteKeyFlags retrieves the value associated with a given key and delete the key in the BPFMap, with the specified flags. It returns the value as a slice of bytes.
func (*BPFMap) GetValueBatch ¶
func (m *BPFMap) GetValueBatch(keys, startKey, nextKey unsafe.Pointer, count uint32) ([][]byte, uint32, error)
GetValueBatch allows for batch lookups of multiple keys from the map.
The first argument, keys, is a pointer to an array or slice of keys which will be populated with the keys returned from this operation.
This API allows for batch lookups of multiple keys, potentially in steps over multiple iterations. For example, you provide the last key seen (or nil) for the startKey, and the first key to start the next iteration with in nextKey. Once the first iteration is complete you can provide the last key seen in the previous iteration as the startKey for the next iteration and repeat until nextKey is nil.
The last argument, count, is the number of keys to lookup.
It returns the associated values as a slice of slices of bytes and the number of elements that were retrieved.
The API can return partial results even though the underlying logic received -1. In this case, no error will be returned. For checking if the returned values are partial, you can compare the number of elements returned with the passed count. See the comment in `BPFMapLow.GetValueBatch` for more context.
func (*BPFMap) GetValueFlags ¶
func (*BPFMap) InitialValue ¶
func (*BPFMap) InnerMapInfo ¶
func (m *BPFMap) InnerMapInfo() (*BPFMapInfo, error)
InnerMap retrieves the inner map prototype information associated with a BPFMap that represents a map of maps.
NOTE: It must be called before the module is loaded, since it is a prototype destroyed right after the outer map is created.
Reference: https://lore.kernel.org/bpf/20200429002739.48006-4-andriin@fb.com/
func (*BPFMap) Iterator ¶
func (m *BPFMap) Iterator() *BPFMapIterator
func (*BPFMap) LookupAndDeleteElem ¶
func (m *BPFMap) LookupAndDeleteElem( key unsafe.Pointer, value unsafe.Pointer, valueSize uint64, flags MapFlag, ) error
LookupAndDeleteElem stores the value associated with a given key into the provided unsafe.Pointer and deletes the key from the BPFMap.
func (*BPFMap) MaxEntries ¶
MaxEntries returns the capacity of the BPFMap.
For ring and perf buffer types, this returns the capacity in bytes.
func (*BPFMap) ReuseFD ¶
ReuseFD associates the BPFMap instance with the provided map file descriptor.
This function is useful for reusing a map that was previously created by a different process. By passing the file descriptor of the existing map, the current BPFMap instance becomes linked to that map.
NOTE: The function closes the current file descriptor associated with the BPFMap instance and replaces it with a duplicated descriptor pointing to the given fd. As a result, the instance original file descriptor becomes invalid, and all associated information is overwritten.
func (*BPFMap) SetAutocreate ¶
Autocreate sets whether libbpf has to auto-create BPF map during BPF object load phase.
func (*BPFMap) SetInnerMap ¶
SetInnerMap configures the inner map prototype for a BPFMap that represents a map of maps.
This function accepts the file descriptor of another map, which will serve as a prototype.
NOTE: It must be called before the module is loaded.
func (*BPFMap) SetKeySize ¶
SetKeySize sets the key size to a BPFMap instance that is not yet associated with a file descriptor.
func (*BPFMap) SetMaxEntries ¶
SetMaxEntries sets the capacity of the BPFMap to the given maxEntries value.
This function must be called after BPF module initialization and before loading the module with BPFLoadObject, enabling customization of the map capacity.
For ring and perf buffer types, maxEntries represents the capacity in bytes.
func (*BPFMap) SetPinPath ¶
func (*BPFMap) SetType ¶
SetType assigns a specific type to a BPFMap instance that is not yet associated with a file descriptor.
func (*BPFMap) SetValueSize ¶
SetValueSize sets the value size to a BPFMap instance that is not yet associated with a file descriptor.
func (*BPFMap) Update ¶
Update inserts or updates value in BPFMap that corresponds to a given key.
This function accepts unsafe.Pointer references to both the key and value. All basic types, and structs are supported.
NOTE: Slices and arrays are supported, but references should point to the first element in the slice or array, instead of the slice or array itself. This is crucial to prevent undefined behavior.
For example:
key := 1 value := []byte{'a', 'b', 'c'} keyPtr := unsafe.Pointer(&key) valuePtr := unsafe.Pointer(&value[0]) bpfmap.Update(keyPtr, valuePtr)
func (*BPFMap) UpdateBatch ¶
UpdateBatch updates multiple elements in the map by specified keys and their corresponding values.
The first argument, keys, is a pointer to an array or slice of keys which will be updated using the second argument, values.
The last argument, count, is the number of keys to update.
It returns the number of elements that were updated.
The API can update fewer elements than requested even though the underlying logic received -1. This can happen if the map is full and the update operation fails for some of the keys. In this case, no error will be returned. For checking if the updated values are partial, you can compare the number of elements returned with the passed count. See the comment in `BPFMapLow.GetValueBatch` and `BPFMapLow.UpdateBatch` for more context.
func (*BPFMap) UpdateValueFlags ¶
type BPFMapCreateOpts ¶
type BPFMapCreateOpts struct {
BTFFD uint32
BTFKeyTypeID uint32
BTFValueTypeID uint32
BTFVmlinuxValueTypeID uint32
InnerMapFD uint32
MapFlags uint32
MapExtra uint64
NumaNode uint32
MapIfIndex uint32
}
BPFMapCreateOpts mirrors the C structure bpf_map_create_opts.
type BPFMapInfo ¶
type BPFMapInfo struct {
Type MapType
ID uint32
KeySize uint32
ValueSize uint32
MaxEntries uint32
MapFlags uint32
Name string
IfIndex uint32
BTFVmlinuxValueTypeID uint32
NetnsDev uint64
NetnsIno uint64
BTFID uint32
BTFKeyTypeID uint32
BTFValueTypeID uint32
MapExtra uint64
}
BPFMapInfo mirrors the C structure bpf_map_info.
func GetMapInfoByFD ¶
func GetMapInfoByFD(fd int) (*BPFMapInfo, error)
GetMapInfoByFD returns the BPFMapInfo for the map with the given file descriptor.
type BPFMapIterator ¶
type BPFMapIterator struct {
// contains filtered or unexported fields
}
BPFMapIterator iterates over keys in a BPF map.
func (*BPFMapIterator) Err ¶
func (it *BPFMapIterator) Err() error
Err returns the last error that ocurred while table.Iter or iter.Next.
func (*BPFMapIterator) Key ¶
func (it *BPFMapIterator) Key() []byte
Key returns the current key value of the iterator, if the most recent call to Next returned true. The slice is valid only until the next call to Next.
func (*BPFMapIterator) Next ¶
func (it *BPFMapIterator) Next() bool
Next advances the iterator to the next key in the map.
type BPFMapLow ¶
type BPFMapLow struct {
// contains filtered or unexported fields
}
BPFMapLow provides a low-level interface to BPF maps. Its methods follow the BPFMap naming convention.
func CreateMap ¶
func CreateMap(mapType MapType, mapName string, keySize, valueSize, maxEntries int, opts *BPFMapCreateOpts) (*BPFMapLow, error)
CreateMap creates a new BPF map with the given parameters.
func GetMapByID ¶
GetMapByID returns a BPFMapLow instance for the map with the given ID.
func (*BPFMapLow) DeleteKeyBatch ¶
DeleteKeyBatch deletes the elements with the given keys from the map. It returns the number of deleted elements.
func (*BPFMapLow) FileDescriptor ¶
func (*BPFMapLow) GetNextKey ¶
func (*BPFMapLow) GetValueAndDeleteBatch ¶
func (m *BPFMapLow) GetValueAndDeleteBatch(keys, startKey, nextKey unsafe.Pointer, count uint32) ([][]byte, uint32, error)
GetValueAndDeleteBatch gets the values with the given keys from the map and deletes them. It returns the values and the number of deleted elements.
func (*BPFMapLow) GetValueAndDeleteKey ¶
func (*BPFMapLow) GetValueAndDeleteKeyFlags ¶
func (*BPFMapLow) GetValueBatch ¶
func (m *BPFMapLow) GetValueBatch(keys, startKey, nextKey unsafe.Pointer, count uint32) ([][]byte, uint32, error)
GetValueBatch gets the values with the given keys from the map. It returns the values and the number of read elements.
func (*BPFMapLow) GetValueFlags ¶
func (*BPFMapLow) Iterator ¶
func (m *BPFMapLow) Iterator() *BPFMapIterator
func (*BPFMapLow) LookupAndDeleteElem ¶
func (*BPFMapLow) LookupAndDeleteElemFlags ¶
func (*BPFMapLow) MaxEntries ¶
func (*BPFMapLow) UpdateBatch ¶
UpdateBatch updates the elements with the given keys and values in the map. It returns the number of updated elements.
func (*BPFMapLow) UpdateValueFlags ¶
type BPFObjectIterator ¶
type BPFObjectIterator struct {
// contains filtered or unexported fields
}
BPFObjectProgramIterator iterates over programs and maps in a BPF object
func (*BPFObjectIterator) NextMap ¶
func (it *BPFObjectIterator) NextMap() *BPFMap
func (*BPFObjectIterator) NextProgram ¶
func (it *BPFObjectIterator) NextProgram() *BPFProg
type BPFProg ¶
type BPFProg struct {
// contains filtered or unexported fields
}
func (*BPFProg) AttachCgroup ¶
AttachCgroup attaches the BPFProg to a cgroup described by given fd.
func (*BPFProg) AttachCgroupLegacy ¶
func (p *BPFProg) AttachCgroupLegacy(cgroupV2DirPath string, attachType BPFAttachType) (*BPFLink, error)
AttachCgroupLegacy attaches the BPFProg to a cgroup described by the given fd. It first tries to use the most recent attachment method and, if that does not work, instead of failing, it tries the legacy way: to attach the cgroup eBPF program without previously creating a link. This allows attaching cgroup eBPF ingress/egress in older kernels. Note: the first attempt error message is filtered out inside libbpf_print_fn() as it is actually a feature probe attempt as well.
Related kernel commit: https://github.com/torvalds/linux/commit/af6eea57437a
func (*BPFProg) AttachGeneric ¶
AttachGeneric is used to attach the BPF program using autodetection for the attach target. You can specify the destination in BPF code via the SEC() such as `SEC("fentry/some_kernel_func")`
func (*BPFProg) AttachGenericFD ¶
func (p *BPFProg) AttachGenericFD(targetFd int, attachType BPFAttachType, flags AttachFlag) error
AttachGenericFD attaches the BPFProgram to a targetFd at the specified attachType hook.
func (*BPFProg) AttachKprobe ¶
AttachKprobe attaches the BPFProgram to the given symbol name.
func (*BPFProg) AttachKprobeOffset ¶
AttachKprobeOnOffset attaches the BPFProgram to the given offset.
func (*BPFProg) AttachKretprobe ¶
AttachKretprobe attaches the BPFProgram to the given symbol name (for return).
func (*BPFProg) AttachKretprobeOnOffset ¶
AttachKretprobeOnOffset attaches the BPFProgram to the given offset (for return).
func (*BPFProg) AttachNetns ¶
func (*BPFProg) AttachRawTracepoint ¶
func (*BPFProg) AttachTCX ¶
AttachTCX attaches the BPF program via the TCX helper. The behaviour is analogous to AttachXDP but uses the `bpf_program__attach_tcx` call introduced in newer kernels. The resulting BPFLink has its linkType set to TCX so consumers can distinguish these links when iterating or printing debug information.
func (*BPFProg) AttachTracepoint ¶
func (*BPFProg) AttachURetprobe ¶
AttachURetprobe attaches the BPFProgram to exit of the symbol in the library or binary at 'path' which can be relative or absolute. A pid can be provided to attach to, or -1 can be specified to attach to all processes
func (*BPFProg) AttachURetprobeMulti ¶
func (p *BPFProg) AttachURetprobeMulti(pid int, path string, offsets, cookies []uint64) (*BPFLink, error)
AttachURetprobeMulti attaches the BPFProgram to exit of the symbol in the library or binary at 'path' which can be relative or absolute, using the uprobe_multi link, allowing to specify multiple offsets. A pid can be provided to attach to, or -1 can be specified to attach to all processes. func_pattern argument to libbpf bpf_program__attach_uprobe_multi() which accepts a regular expression to specify functions to attach BPF program to, is currently not supported.
func (*BPFProg) AttachUSDT ¶
func (p *BPFProg) AttachUSDT(pid int, binaryPath string, provider string, name string) (*BPFLink, error)
AttachUSDT attaches the BPFProgram to the USDT static marker in the library or binary at 'binaryPath' which can be relative or absolute. A pid can be provided to attach to, or -1 can be specified to attach to all processes.
func (*BPFProg) AttachUprobe ¶
AttachUprobe attaches the BPFProgram to entry of the symbol in the library or binary at 'path' which can be relative or absolute. A pid can be provided to attach to, or -1 can be specified to attach to all processes
func (*BPFProg) AttachUprobeMulti ¶
func (p *BPFProg) AttachUprobeMulti(pid int, path string, offsets, cookies []uint64) (*BPFLink, error)
AttachUprobeMulti attaches the BPFProgram to entry of the symbol in the library or binary at 'path' which can be relative or absolute, using the uprobe_multi link, allowing to specify multiple offsets. A pid can be provided to attach to, or -1 can be specified to attach to all processes. func_pattern argument to libbpf bpf_program__attach_uprobe_multi() which accepts a regular expression to specify functions to attach BPF program to, is currently not supported.
func (*BPFProg) AttachXDPLegacy ¶
func (*BPFProg) Autoattach ¶
func (*BPFProg) DetachCgroupLegacy ¶
func (p *BPFProg) DetachCgroupLegacy(cgroupV2DirPath string, attachType BPFAttachType) error
DetachCgroupLegacy detaches the BPFProg from a cgroup described by the given fd. This is needed because in legacy attachment there is no BPFLink, just a fake one (kernel did not support it, nor libbpf). This function should be called by the (*BPFLink)->Destroy() function, since BPFLink is emulated (so users don´t need to distinguish between regular and legacy cgroup detachments).
func (*BPFProg) DetachGenericFD ¶
func (p *BPFProg) DetachGenericFD(targetFd int, attachType BPFAttachType) error
DetachGenericFD detaches the BPFProgram associated with the targetFd at the hook specified by attachType.
func (*BPFProg) DetachXDPLegacy ¶
func (*BPFProg) FileDescriptor ¶
func (*BPFProg) GetPinPath
deprecated
func (*BPFProg) GetSectionName
deprecated
func (*BPFProg) GetType ¶
func (p *BPFProg) GetType() BPFProgType
func (*BPFProg) Run ¶
Run executes the eBPF program without attaching it to actual hooks, filling the results in the provided RunOpts. Reference:
- https://docs.kernel.org/bpf/bpf_prog_run.html
- https://docs.kernel.org/userspace-api/ebpf/syscall.html
Example Usage:
/*
SEC("tc")
int test(struct __sk_buff *skb)
{
return foo() ? 1 : 0;
}
*/
func TestFunc(t *testing.T) {
...
prog, _ := module.GetProgram("test")
opts := RunOpts{
DataIn: make([]byte, 0, 14),
DataSizeIn: 14,
DataOut: make([]byte, 0, 14),
DataSizeOut: 14,
Repeat: 1,
}
prog.Run(&opts)
if opts.RetVal != 1 {
t.Errorf("result = %d; want 1", opts.RetVal)
}
}
func (*BPFProg) SectionName ¶
func (*BPFProg) SetAttachTarget ¶
SetAttachTarget can be used to specify the program and/or function to attach the BPF program to. To attach to a kernel function specify attachProgFD as 0
func (*BPFProg) SetAttachType
deprecated
func (p *BPFProg) SetAttachType(attachType BPFAttachType)
Deprecated: use BPFProg.SetExpectedAttachType() instead.
func (*BPFProg) SetAutoattach ¶
func (*BPFProg) SetAutoload ¶
func (*BPFProg) SetExpectedAttachType ¶
func (p *BPFProg) SetExpectedAttachType(attachType BPFAttachType) error
func (*BPFProg) SetProgramType
deprecated
func (p *BPFProg) SetProgramType(progType BPFProgType)
Deprecated: use BPFProg.SetType() instead.
func (*BPFProg) SetType ¶
func (p *BPFProg) SetType(progType BPFProgType) error
type BPFProgType ¶
type BPFProgType uint32
BPFProgType is an enum as defined in https://elixir.bootlin.com/linux/latest/source/include/uapi/linux/bpf.h
const ( BPFProgTypeUnspec BPFProgType = C.BPF_PROG_TYPE_UNSPEC BPFProgTypeSocketFilter BPFProgType = C.BPF_PROG_TYPE_SOCKET_FILTER BPFProgTypeKprobe BPFProgType = C.BPF_PROG_TYPE_KPROBE BPFProgTypeSchedCls BPFProgType = C.BPF_PROG_TYPE_SCHED_CLS BPFProgTypeSchedAct BPFProgType = C.BPF_PROG_TYPE_SCHED_ACT BPFProgTypeTracepoint BPFProgType = C.BPF_PROG_TYPE_TRACEPOINT BPFProgTypeXdp BPFProgType = C.BPF_PROG_TYPE_XDP BPFProgTypePerfEvent BPFProgType = C.BPF_PROG_TYPE_PERF_EVENT BPFProgTypeCgroupSkb BPFProgType = C.BPF_PROG_TYPE_CGROUP_SKB BPFProgTypeCgroupSock BPFProgType = C.BPF_PROG_TYPE_CGROUP_SOCK BPFProgTypeLwtIn BPFProgType = C.BPF_PROG_TYPE_LWT_IN BPFProgTypeLwtOut BPFProgType = C.BPF_PROG_TYPE_LWT_OUT BPFProgTypeLwtXmit BPFProgType = C.BPF_PROG_TYPE_LWT_XMIT BPFProgTypeSockOps BPFProgType = C.BPF_PROG_TYPE_SOCK_OPS BPFProgTypeSkSkb BPFProgType = C.BPF_PROG_TYPE_SK_SKB BPFProgTypeCgroupDevice BPFProgType = C.BPF_PROG_TYPE_CGROUP_DEVICE BPFProgTypeSkMsg BPFProgType = C.BPF_PROG_TYPE_SK_MSG BPFProgTypeRawTracepoint BPFProgType = C.BPF_PROG_TYPE_RAW_TRACEPOINT BPFProgTypeCgroupSockAddr BPFProgType = C.BPF_PROG_TYPE_CGROUP_SOCK_ADDR BPFProgTypeLwtSeg6Local BPFProgType = C.BPF_PROG_TYPE_LWT_SEG6LOCAL BPFProgTypeLircMode2 BPFProgType = C.BPF_PROG_TYPE_LIRC_MODE2 BPFProgTypeSkReuseport BPFProgType = C.BPF_PROG_TYPE_SK_REUSEPORT BPFProgTypeFlowDissector BPFProgType = C.BPF_PROG_TYPE_FLOW_DISSECTOR BPFProgTypeCgroupSysctl BPFProgType = C.BPF_PROG_TYPE_CGROUP_SYSCTL BPFProgTypeRawTracepointWritable BPFProgType = C.BPF_PROG_TYPE_RAW_TRACEPOINT_WRITABLE BPFProgTypeCgroupSockopt BPFProgType = C.BPF_PROG_TYPE_CGROUP_SOCKOPT BPFProgTypeTracing BPFProgType = C.BPF_PROG_TYPE_TRACING BPFProgTypeStructOps BPFProgType = C.BPF_PROG_TYPE_STRUCT_OPS BPFProgTypeExt BPFProgType = C.BPF_PROG_TYPE_EXT BPFProgTypeLsm BPFProgType = C.BPF_PROG_TYPE_LSM BPFProgTypeSkLookup BPFProgType = C.BPF_PROG_TYPE_SK_LOOKUP BPFProgTypeSyscall BPFProgType = C.BPF_PROG_TYPE_SYSCALL BPFProgTypeNetfilter BPFProgType = C.BPF_PROG_TYPE_NETFILTER )
func (BPFProgType) Name ¶
func (t BPFProgType) Name() string
func (BPFProgType) String ¶
func (t BPFProgType) String() string
func (BPFProgType) Value
deprecated
func (t BPFProgType) Value() uint64
Deprecated: Convert type directly instead.
type Callbacks ¶
type Callbacks struct {
Log func(level int, msg string)
LogFilters []func(libLevel int, msg string) bool
}
Callbacks stores the callbacks to be used by libbpfgo
type LibbpfStrictMode ¶
type LibbpfStrictMode uint32
LibbpfStrictMode is an enum as defined in https://github.com/libbpf/libbpf/blob/2cd2d03f63242c048a896179398c68d2dbefe3d6/src/libbpf_legacy.h#L23
const ( LibbpfStrictModeAll LibbpfStrictMode = C.LIBBPF_STRICT_ALL LibbpfStrictModeNone LibbpfStrictMode = C.LIBBPF_STRICT_NONE LibbpfStrictModeCleanPtrs LibbpfStrictMode = C.LIBBPF_STRICT_CLEAN_PTRS LibbpfStrictModeDirectErrs LibbpfStrictMode = C.LIBBPF_STRICT_DIRECT_ERRS LibbpfStrictModeSecName LibbpfStrictMode = C.LIBBPF_STRICT_SEC_NAME LibbpfStrictModeNoObjectList LibbpfStrictMode = C.LIBBPF_STRICT_NO_OBJECT_LIST LibbpfStrictModeAutoRlimitMemlock LibbpfStrictMode = C.LIBBPF_STRICT_AUTO_RLIMIT_MEMLOCK LibbpfStrictModeMapDefinitions LibbpfStrictMode = C.LIBBPF_STRICT_MAP_DEFINITIONS )
func (LibbpfStrictMode) String ¶
func (b LibbpfStrictMode) String() (str string)
type MapType ¶
type MapType uint32
const ( MapTypeUnspec MapType = C.BPF_MAP_TYPE_UNSPEC MapTypeHash MapType = C.BPF_MAP_TYPE_HASH MapTypeArray MapType = C.BPF_MAP_TYPE_ARRAY MapTypeProgArray MapType = C.BPF_MAP_TYPE_PROG_ARRAY MapTypePerfEventArray MapType = C.BPF_MAP_TYPE_PERF_EVENT_ARRAY MapTypePerCPUHash MapType = C.BPF_MAP_TYPE_PERCPU_HASH MapTypePerCPUArray MapType = C.BPF_MAP_TYPE_PERCPU_ARRAY MapTypeStackTrace MapType = C.BPF_MAP_TYPE_STACK_TRACE MapTypeCgroupArray MapType = C.BPF_MAP_TYPE_CGROUP_ARRAY MapTypeLRUHash MapType = C.BPF_MAP_TYPE_LRU_HASH MapTypeLRUPerCPUHash MapType = C.BPF_MAP_TYPE_LRU_PERCPU_HASH MapTypeLPMTrie MapType = C.BPF_MAP_TYPE_LPM_TRIE MapTypeArrayOfMaps MapType = C.BPF_MAP_TYPE_ARRAY_OF_MAPS MapTypeHashOfMaps MapType = C.BPF_MAP_TYPE_HASH_OF_MAPS MapTypeDevMap MapType = C.BPF_MAP_TYPE_DEVMAP MapTypeSockMap MapType = C.BPF_MAP_TYPE_SOCKMAP MapTypeCPUMap MapType = C.BPF_MAP_TYPE_CPUMAP MapTypeXSKMap MapType = C.BPF_MAP_TYPE_XSKMAP MapTypeSockHash MapType = C.BPF_MAP_TYPE_SOCKHASH MapTypeCgroupStorage MapType = C.BPF_MAP_TYPE_CGROUP_STORAGE MapTypeReusePortSockArray MapType = C.BPF_MAP_TYPE_REUSEPORT_SOCKARRAY MapTypePerCPUCgroupStorage MapType = C.BPF_MAP_TYPE_PERCPU_CGROUP_STORAGE MapTypeQueue MapType = C.BPF_MAP_TYPE_QUEUE MapTypeStack MapType = C.BPF_MAP_TYPE_STACK MapTypeSKStorage MapType = C.BPF_MAP_TYPE_SK_STORAGE MapTypeDevmapHash MapType = C.BPF_MAP_TYPE_DEVMAP_HASH MapTypeStructOps MapType = C.BPF_MAP_TYPE_STRUCT_OPS MapTypeRingbuf MapType = C.BPF_MAP_TYPE_RINGBUF MapTypeInodeStorage MapType = C.BPF_MAP_TYPE_INODE_STORAGE MapTypeTaskStorage MapType = C.BPF_MAP_TYPE_TASK_STORAGE MapTypeBloomFilter MapType = C.BPF_MAP_TYPE_BLOOM_FILTER MapTypeUserRingbuf MapType = C.BPF_MAP_TYPE_USER_RINGBUF MapTypeCgrpStorage MapType = C.BPF_MAP_TYPE_CGRP_STORAGE MapTypeArena MapType = C.BPF_MAP_TYPE_ARENA )
type Module ¶
type Module struct {
// contains filtered or unexported fields
}
func NewModuleFromBuffer ¶
func NewModuleFromBufferArgs ¶
func NewModuleFromBufferArgs(args NewModuleArgs) (*Module, error)
func NewModuleFromFile ¶
func NewModuleFromFileArgs ¶
func NewModuleFromFileArgs(args NewModuleArgs) (*Module, error)
func (*Module) AddRingBuf ¶
func (*Module) AttachPrograms ¶
AttachPrograms attach all loaded and no attached progs once like bpf_object__attach_skeleton
func (*Module) BPFLoadObject ¶
func (*Module) DetachPrograms ¶
DetachPrograms detach all attached progs once like bpf_object__detach_skeleton
func (*Module) InitGlobalVariable ¶
InitGlobalVariable sets global variables (defined in .data or .rodata) in bpf code. It must be called before the BPF object is loaded.
func (*Module) InitPerfBuf ¶
func (*Module) InitRingBuf ¶
func (m *Module) InitRingBuf(mapName string, eventsChan chan []byte) (*RingBuffer, error)
func (*Module) InitUserRingBuf ¶
func (m *Module) InitUserRingBuf(mapName string, eventsChan chan []byte) (*UserRingBuffer, error)
func (*Module) Iterator ¶
func (m *Module) Iterator() *BPFObjectIterator
func (*Module) TcHookInit ¶
type NewModuleArgs ¶
type PerfBuffer ¶
type PerfBuffer struct {
// contains filtered or unexported fields
}
func (*PerfBuffer) Close ¶
func (pb *PerfBuffer) Close()
func (*PerfBuffer) Poll ¶
func (pb *PerfBuffer) Poll(timeout int)
Poll will wait until timeout in milliseconds to gather data from the perf buffer.
func (*PerfBuffer) Start
deprecated
func (pb *PerfBuffer) Start()
Deprecated: use PerfBuffer.Poll() instead.
func (*PerfBuffer) Stop ¶
func (pb *PerfBuffer) Stop()
type RingBuffer ¶
type RingBuffer struct {
// contains filtered or unexported fields
}
func (*RingBuffer) Close ¶
func (rb *RingBuffer) Close()
func (*RingBuffer) Poll ¶
func (rb *RingBuffer) Poll(timeout int)
Poll will wait until timeout in milliseconds to gather data from the ring buffer.
func (*RingBuffer) Start
deprecated
func (rb *RingBuffer) Start()
Deprecated: use RingBuffer.Poll() instead.
func (*RingBuffer) Stop ¶
func (rb *RingBuffer) Stop()
type RunFlag ¶
type RunFlag uint32
const ( RunFlagRunOnCPU RunFlag = C.BPF_F_TEST_RUN_ON_CPU RunFlagXDPLiveFrames RunFlag = C.BPF_F_TEST_XDP_LIVE_FRAMES )
type RunOpts ¶
type RunOpts struct {
DataIn []byte
DataOut []byte
DataSizeIn uint32
DataSizeOut uint32
CtxIn []byte
CtxOut []byte
CtxSizeIn uint32
CtxSizeOut uint32
RetVal uint32
Repeat int
Duration time.Duration
Flags RunFlag
CPU uint32
BatchSize uint32
}
RunOpts mirrors the C structure bpf_test_run_opts.
type TcAttachPoint ¶
type TcAttachPoint uint32
const ( BPFTcIngress TcAttachPoint = C.BPF_TC_INGRESS BPFTcEgress TcAttachPoint = C.BPF_TC_EGRESS BPFTcIngressEgress TcAttachPoint = C.BPF_TC_INGRESS | C.BPF_TC_EGRESS BPFTcCustom TcAttachPoint = C.BPF_TC_CUSTOM )
type TcHook ¶
type TcHook struct {
// contains filtered or unexported fields
}
func (*TcHook) GetInterfaceIndex ¶
func (*TcHook) SetAttachPoint ¶
func (hook *TcHook) SetAttachPoint(attachPoint TcAttachPoint)
func (*TcHook) SetInterfaceByIndex ¶
func (*TcHook) SetInterfaceByName ¶
type UserRingBuffer ¶
type UserRingBuffer struct {
// contains filtered or unexported fields
}
func (*UserRingBuffer) Close ¶
func (rb *UserRingBuffer) Close()
func (*UserRingBuffer) Error ¶
func (rb *UserRingBuffer) Error() error
func (*UserRingBuffer) Start ¶
func (rb *UserRingBuffer) Start()
func (*UserRingBuffer) Stop ¶
func (rb *UserRingBuffer) Stop()
type XDPFlags ¶
type XDPFlags uint32
const ( XDPFlagsUpdateIfNoExist XDPFlags = C.XDP_FLAGS_UPDATE_IF_NOEXIST XDPFlagsSkbMode XDPFlags = C.XDP_FLAGS_SKB_MODE XDPFlagsDrvMode XDPFlags = C.XDP_FLAGS_DRV_MODE XDPFlagsHwMode XDPFlags = C.XDP_FLAGS_HW_MODE XDPFlagsReplace XDPFlags = C.XDP_FLAGS_REPLACE XDPFlagsModes XDPFlags = C.XDP_FLAGS_MODES XDPFlagsMask XDPFlags = C.XDP_FLAGS_MASK )