Documentation ¶
Index ¶
- Constants
- Variables
- func BPF(cmd BPFCmd, attr unsafe.Pointer, size uintptr) (uintptr, error)
- func BPFObjGetInfoByFD(fd *FD, info unsafe.Pointer, size uintptr) error
- func BPFObjPin(fileName string, fd *FD) error
- func BPFProgAttach(attr *BPFProgAttachAttr) error
- func BPFProgDetach(attr *BPFProgDetachAttr) error
- func CString(in []byte) string
- func ErrorWithLog(err error, log []byte, logErr error) error
- func FeatureTest(name, version string, fn FeatureTestFn) func() error
- func Pin(currentPath, newPath string, fd *FD) error
- func PossibleCPUs() (int, error)
- func Unpin(pinnedPath string) error
- type BPFCmd
- type BPFEnableStatsAttr
- type BPFProgAttachAttr
- type BPFProgDetachAttr
- type DiscardZeroes
- type FD
- type FeatureTestFn
- type Pointer
- type SafeELFFile
- type UnsupportedFeatureError
- type VerifierError
- type Version
Constants ¶
const ( // Version constant used in ELF binaries indicating that the loader needs to // substitute the eBPF program's version with the value of the kernel's // KERNEL_VERSION compile-time macro. Used for compatibility with BCC, gobpf // and RedSift. MagicKernelVersion = 0xFFFFFFFE )
Variables ¶
var ErrClosedFd = errors.New("use of closed file descriptor")
var ErrNotSupported = errors.New("not supported")
ErrNotSupported indicates that a feature is not supported by the current kernel.
var NativeEndian binary.ByteOrder
NativeEndian is set to either binary.BigEndian or binary.LittleEndian, depending on the host's endianness.
Functions ¶
func BPF ¶
BPF wraps SYS_BPF.
Any pointers contained in attr must use the Pointer type from this package.
func BPFObjGetInfoByFD ¶ added in v0.2.0
BPFObjGetInfoByFD wraps BPF_OBJ_GET_INFO_BY_FD.
Available from 4.13.
func BPFProgAttach ¶
func BPFProgAttach(attr *BPFProgAttachAttr) error
func BPFProgDetach ¶
func BPFProgDetach(attr *BPFProgDetachAttr) error
func ErrorWithLog ¶
ErrorWithLog returns an error that includes logs from the kernel verifier.
logErr should be the error returned by the syscall that generated the log. It is used to check for truncation of the output.
func FeatureTest ¶
func FeatureTest(name, version string, fn FeatureTestFn) func() error
FeatureTest wraps a function so that it is run at most once.
name should identify the tested feature, while version must be in the form Major.Minor[.Patch].
Returns an error wrapping ErrNotSupported if the feature is not supported.
func PossibleCPUs ¶
PossibleCPUs returns the max number of CPUs a system may possibly have Logical CPU numbers must be of the form 0-n
Types ¶
type BPFCmd ¶
type BPFCmd int
BPFCmd identifies a subcommand of the bpf syscall.
const ( BPF_MAP_CREATE BPFCmd = iota BPF_MAP_LOOKUP_ELEM BPF_MAP_UPDATE_ELEM BPF_MAP_DELETE_ELEM BPF_MAP_GET_NEXT_KEY BPF_PROG_LOAD BPF_OBJ_PIN BPF_OBJ_GET BPF_PROG_ATTACH BPF_PROG_DETACH BPF_PROG_TEST_RUN BPF_PROG_GET_NEXT_ID BPF_MAP_GET_NEXT_ID BPF_PROG_GET_FD_BY_ID BPF_MAP_GET_FD_BY_ID BPF_OBJ_GET_INFO_BY_FD BPF_PROG_QUERY BPF_RAW_TRACEPOINT_OPEN BPF_BTF_LOAD BPF_BTF_GET_FD_BY_ID BPF_TASK_FD_QUERY BPF_MAP_LOOKUP_AND_DELETE_ELEM BPF_MAP_FREEZE BPF_BTF_GET_NEXT_ID BPF_MAP_LOOKUP_BATCH BPF_MAP_LOOKUP_AND_DELETE_BATCH BPF_MAP_UPDATE_BATCH BPF_MAP_DELETE_BATCH BPF_LINK_CREATE BPF_LINK_UPDATE BPF_LINK_GET_FD_BY_ID BPF_LINK_GET_NEXT_ID BPF_ENABLE_STATS BPF_ITER_CREATE )
Well known BPF commands.
type BPFEnableStatsAttr ¶ added in v0.4.0
type BPFEnableStatsAttr struct {
StatsType uint32
}
type BPFProgAttachAttr ¶
type BPFProgDetachAttr ¶
type DiscardZeroes ¶
type DiscardZeroes struct{}
DiscardZeroes makes sure that all written bytes are zero before discarding them.
type FD ¶
type FD struct {
// contains filtered or unexported fields
}
func BPFEnableStats ¶ added in v0.4.0
func BPFEnableStats(attr *BPFEnableStatsAttr) (*FD, error)
type FeatureTestFn ¶
type FeatureTestFn func() error
FeatureTestFn is used to determine whether the kernel supports a certain feature.
The return values have the following semantics:
err == ErrNotSupported: the feature is not available err == nil: the feature is available err != nil: the test couldn't be executed
type Pointer ¶
type Pointer struct {
// contains filtered or unexported fields
}
Pointer wraps an unsafe.Pointer to be 64bit to conform to the syscall specification.
func NewPointer ¶
NewPointer creates a 64-bit pointer from an unsafe Pointer.
func NewSlicePointer ¶
NewSlicePointer creates a 64-bit pointer from a byte slice.
func NewStringPointer ¶
NewStringPointer creates a 64-bit pointer from a string.
type SafeELFFile ¶ added in v0.4.0
func NewSafeELFFile ¶ added in v0.4.0
func NewSafeELFFile(r io.ReaderAt) (safe *SafeELFFile, err error)
NewSafeELFFile reads an ELF safely.
Any panic during parsing is turned into an error. This is necessary since there are a bunch of unfixed bugs in debug/elf.
https://github.com/golang/go/issues?q=is%3Aissue+is%3Aopen+debug%2Felf+in%3Atitle
type UnsupportedFeatureError ¶
type UnsupportedFeatureError struct { // The minimum Linux mainline version required for this feature. // Used for the error string, and for sanity checking during testing. MinimumVersion Version // The name of the feature that isn't supported. Name string }
UnsupportedFeatureError is returned by FeatureTest() functions.
func (*UnsupportedFeatureError) Error ¶
func (ufe *UnsupportedFeatureError) Error() string
func (*UnsupportedFeatureError) Is ¶
func (ufe *UnsupportedFeatureError) Is(target error) bool
Is indicates that UnsupportedFeatureError is ErrNotSupported.
type VerifierError ¶
type VerifierError struct {
// contains filtered or unexported fields
}
VerifierError includes information from the eBPF verifier.
func (*VerifierError) Error ¶
func (le *VerifierError) Error() string
type Version ¶
type Version [3]uint16
A Version in the form Major.Minor.Patch.
func KernelVersion ¶ added in v0.5.0
KernelVersion returns the version of the currently running kernel.
func NewVersion ¶
NewVersion creates a version from a string like "Major.Minor.Patch".
Patch is optional.
func (Version) Kernel ¶ added in v0.5.0
Kernel implements the kernel's KERNEL_VERSION macro from linux/version.h. It represents the kernel version and patch level as a single value.
func (Version) Unspecified ¶ added in v0.2.0
Unspecified returns true if the version is all zero.