kernelsupport

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Jan 22, 2022 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

package kernelsupport is used to query what eBPF features are supported for different version of the linux kernel

Index

Constants

This section is empty.

Variables

View Source
var CurrentFeatures = MustGetKernelFeatures()

CurrentFeatures is a singleton containing the result of MustGetKernelFeatures. Assuming kernel features don't change during the lifetime. Using this singleton saves a lot of performance.

View Source
var CurrentVersion = MustGetKernelVersion()

CurrentVersion is a singleton containing the result of MustGetKernelVersion. Assuming the kernel version doesn't change during the lifetime. Using this singleton saves a lot of performance.

Functions

This section is empty.

Types

type APISupport

type APISupport uint64

APISupport is a flagset which describes which features related to the bpf syscall API are supported

const (
	// KFeatAPIBasic includes: map create, map lookup, map update, map delete, map getnext
	// prog load
	KFeatAPIBasic APISupport = 1 << iota
	KFeatAPIMapGetNextNull
	KFeatAPIMapNumaCreate
	KFeatAPIMapSyscallRW
	KFeatAPIMapName
	KFeatAPIMapLookupAndDelete
	KFeatAPIMapZeroSeed
	KFeatAPIMapLock
	KFeatAPIMapBPFRW
	KFeatAPIMapFreeze
	KFeatAPIMapMMap
	KFeatAPIMapBatchOps
	// 4.4 OBJ_PIN and OBJ_GET
	KFeatAPIObjPinGet
	// 4.10 PROG_ATTACH and PROG_DETACH
	KFeatAPIProgramAttachDetach
	// 4.12
	KFeatAPIProgramTestRun
	// 4.13
	KFeatAPIProgramGetNextID
	// 4.13
	KFeatAPIMapGetNextID
	// 4.13
	KFeatAPIProgramGetFDByID
	// 4.13
	KFeatAPIMapGetFDByID
	// 4.13
	KFeatAPIObjectGetInfoByFD
	// 4.15
	KFeatAPIProgramQuery
	// 4.17
	KFeatAPIRawTracepointOpen
	// 4.18
	KFeatAPIBTFLoad
	// 4.18
	KFeatAPIBTFGetFDByID
	// 4.18
	KFeatAPITaskFDQuery
	// 5.4
	KFeatAPIBTFGetNextID
	// 5.7
	KFeatAPILinkCreate
	// 5.7
	KFeatAPILinkUpdate
	// 5.8
	KFeatAPILinkGetFDByID
	// 5.8
	KFeatAPILinkGetNextID
	// 5.8
	KFeatAPIEnableStats
	// 5.8
	KFeatAPIIterCreate
	// 5.9
	KFeatAPILinkDetach
	// 5.10
	KFeatAPIProgBindMap
)

TODO add comments

func (APISupport) Has

func (as APISupport) Has(flags APISupport) bool

Has returns true if 'as' has all the specified flags

func (APISupport) String

func (as APISupport) String() string

type ArchSupport

type ArchSupport uint64

ArchSupport is a flagset which describes on which architectures eBPF is supported

const (
	// KFeatArchx86_64 means the kernel has eBPF support on the x86_64 architecture
	KFeatArchx86_64 ArchSupport = 1 << iota
	// KFeatArchARM64 means the kernel has eBPF support on the ARM64 architecture
	KFeatArchARM64
	// KFeatArchs390 means the kernel has eBPF support on the s390 architecture
	KFeatArchs390
	// KFeatArchPP64 means the kernel has eBPF support on the PowerPC64 architecture
	KFeatArchPP64
	// KFeatArchSparc64 means the kernel has eBPF support on the Sparc64 architecture
	KFeatArchSparc64
	// KFeatArchMIPS means the kernel has eBPF support on the MIPS architecture
	KFeatArchMIPS
	// KFeatArchARM32 means the kernel has eBPF support on the ARM32 architecture
	KFeatArchARM32
	// KFeatArchx86 means the kernel has eBPF support on the x86_32 architecture
	KFeatArchx86
	// KFeatArchRiscVRV64G means the kernel has eBPF support on the RISC-V RV64G architecture
	KFeatArchRiscVRV64G
	// KFeatArchRiscVRV32G means the kernel has eBPF support on the RISC-V RV32G architecture
	KFeatArchRiscVRV32G
)

func (ArchSupport) Has

func (as ArchSupport) Has(flags ArchSupport) bool

Has returns true if 'as' has all the specified flags

func (ArchSupport) String

func (as ArchSupport) String() string

type AttachSupport

type AttachSupport uint64

AttachSupport is a flagset that describes which attach types are supported

const (
	// 3.19 Ingress and Egress
	KFeatAttachINetIngressEgress AttachSupport = 1 << iota
	// 4.10
	KFeatAttachInetSocketCreate
	// 4.13
	KFeatAttachSocketOps
	// 4.14 stream parser and stream verdict
	KFeatAttachStreamParserVerdict
	// 4.15
	KFeatAttachCGroupDevice
	// 4.17
	KFeatAttachSKMsgVerdict
	// 4.17 inet4 + inet6
	KFeatAttachCGroupInetBind
	// 4.17 inet4 + inet6
	KFeatAttachCGroupInetConnect
	// 4.17 inet4 + inet6
	KFeatAttachCGroupInetPostBind
	// 4.18 udp4 + udp6
	KFeatAttachCGroupUDPSendMsg
	// 4.18
	KFeatAttachLIRCMode2
	// 4.20
	KFeatAttachFlowDissector
	// 5.2
	KFeatAttachCGroupSysctl
	// 5.2 udp4 + udp6
	KFeatAttachCGroupUDPRecvMsg
	// 5.3 CGroupGetSocket + CGroupSetSocket
	KFeatAttachCGroupGetSetSocket
	// 5.5
	KFeatAttachTraceRawTP
	// 5.5
	KFeatAttachTraceFentry
	// 5.5
	KFeatAttachTraceFExit
	// 5.7
	KFeatAttachModifyReturn
	// 5.7
	KFeatAttachLSMMAC
	// 5.8
	KFeatAttachTraceIter
	// 5.8 inet4 + inet6
	KFeatAttachCGroupINetGetPeerName
	// 5.8 inet4 + inet6
	KFeatAttachCGroupINetGetSocketName
	// 5.8
	KFeatAttachXDPDevMap
	// 5.9
	KFeatAttachCGroupInetSocketRelease
	// 5.9
	KFeatAttachXDPCPUMap
	// 5.9
	KFeatAttachSKLookup
	// 5.9
	KFeatAttachXDP
)

TODO add comments

func (AttachSupport) Has

func (as AttachSupport) Has(flags AttachSupport) bool

Has returns true if 'as' has all the specified flags

func (AttachSupport) String

func (as AttachSupport) String() string

type KernelFeatures

type KernelFeatures struct {
	// BPF is set to true if eBPF is supported on the current kernel version and arch combo
	BPF     bool
	Arch    ArchSupport
	Map     MapSupport
	API     APISupport
	Program ProgramSupport
	Attach  AttachSupport
	// TODO helper functions
	Misc MiscSupport
}

KernelFeatures is a set of flagsets which describe the eBPF support of a kernel version. Flags are split amount several sets since the won't all fit in one uint64

func GetKernelFeatures

func GetKernelFeatures() (KernelFeatures, error)

GetKernelFeatures returns a list of kernel features for the kernel on which the current program is currently running.

func MustGetKernelFeatures

func MustGetKernelFeatures() KernelFeatures

MustGetKernelFeatures runs GetKernelFeatures but panics if any error is detected

type KernelVersion added in v0.6.0

type KernelVersion struct {
	Major int
	Minor int
	Patch int
}

func GetKernelVersion added in v0.6.0

func GetKernelVersion() (KernelVersion, error)

func MustGetKernelVersion added in v0.6.0

func MustGetKernelVersion() KernelVersion

MustGetKernelVersion runs GetKernelFeatures but panics if any error is detected

func ParseKernelVersion added in v0.6.0

func ParseKernelVersion(release string, must bool) (version KernelVersion, err error)

func Version added in v0.6.0

func Version(major, minor, patch int) KernelVersion

func (KernelVersion) Higher added in v0.6.0

func (kv KernelVersion) Higher(cmp KernelVersion) bool

Higher returns true if the 'cmp' version is higher than the 'kv' version

type MapSupport

type MapSupport uint64

MapSupport is a flagset that describes which map types are supported

const (
	// KFeatMapHash means the kernel supports Hash maps
	KFeatMapHash MapSupport = 1 << iota
	KFeatMapArray
	KFeatMapTailCall
	KFeatMapPerfEvent
	KFeatMapPerCPUHash
	KFeatMapPerCPUArray
	KFeatMapStackTrace
	KFeatMapCGroupArray
	KFeatMapLRUHash
	KFeatMapLRUPerCPUHash
	KFeatMapLPMTrie
	// KFeatMapLPMTrieNextKey indicates that the MapGetNextKey command is for the LPM trie map type is implemented
	// by the kernel.
	KFeatMapLPMTrieNextKey
	KFeatMapArrayOfMaps
	KFeatMapHashOfMaps
	KFeatMapNetdevArray
	KFeatMapSocketArray
	KFeatMapCPU
	KFeatMapAFXDP
	KFeatMapSocketHash
	KFeatMapCGroupStorage
	KFeatMapReuseportSocketArray
	KFeatMapPerCPUCGroupStorage
	KFeatMapQueue
	KFeatMapStack
	KFeatMapSocketLocalStorage
	KFeatMapNetdevHash
	KFeatMapStructOps
	KFeatMapRingBuffer
	KFeatMapINodeStorage
	KFeatMapTaskStorage
	// KFeatMapPerCPUArrayBatchOps means batch operations are supported on Per CPU array maps
	KFeatMapPerCPUArrayBatchOps
	// KFeatMapLPMTrieBatchOps means batch operations are supported on LPM trie's
	KFeatMapLPMTrieBatchOps
	// KFeatMapDynamicInnerMap means that inner-maps of map-in-map types can have dynamic size
	KFeatMapDynamicInnerMap
)

TODO add comments

func (MapSupport) Has

func (ms MapSupport) Has(flags MapSupport) bool

Has returns true if 'ms' has all the specified flags

func (MapSupport) String

func (ms MapSupport) String() string

type MiscSupport

type MiscSupport uint64

MiscSupport is a flagset that describes features that don't neatly fit into any other category

const (
	// KFeatMiscXSKRingFlags indicates that the kernel version has flags in AF_XDP rings
	// https://github.com/torvalds/linux/commit/77cd0d7b3f257fd0e3096b4fdcff1a7d38e99e10
	KFeatMiscXSKRingFlags MiscSupport = iota
	// KFeatBTFFuncScope indicates that the kernel doesn't require BTF FUNC types to have a vlen of 0.
	// Since kernel 5.6, the scope of functions is encoded in vlen.
	// https://github.com/cilium/ebpf/issues/43
	// https://github.com/llvm/llvm-project/commit/fbb64aa69835c8e3e9efe0afc8a73058b5a0fb3c
	KFeatBTFFuncScope
	// KFeatGlobalData indicates that the kernel supports global data sections.
	// https://lwn.net/Articles/784936/
	// https://github.com/torvalds/linux/commit/d8eca5bbb2be9bc7546f9e733786fa2f1a594c67
	KFeatGlobalData
)

func (MiscSupport) Has

func (ms MiscSupport) Has(flags MiscSupport) bool

Has returns true if 'as' has all the specified flags

func (MiscSupport) String

func (ms MiscSupport) String() string

type ProgramSupport

type ProgramSupport uint64

ProgramSupport is a flagset that describes which programs types are supported

const (
	// 3.19
	KFeatProgSocketFilter ProgramSupport = 1 << iota
	// 4.1
	KFeatProgKProbe
	// 4.1
	KFeatProgSchedCLS
	// 4.1
	KFeatProgSchedACT
	// 4.7
	KFeatProgTracepoint
	// 4.8
	KFeatProgXDP
	// 4.9
	KFeatProgPerfEvent
	// 4.10
	KFeatProgCGroupSKB
	// 4.10
	KFeatProgCGroupSocket
	// 4.10
	KFeatProgLWTIn
	KFeatProgLWTOut
	KFeatProgLWTXmit
	// 4.13
	KFeatProgSocketOps
	// 4.14
	KFeatProgSKSKB
	// 4.15
	KFeatProgCGroupDevice
	// 4.17
	KFeatProgSKMsg
	// 4.17
	KFeatProgRawTracepoint
	// 4.17
	KFeatProgCGroupSocketAddr
	// 4.18
	KFeatProgLWTSeg6Local
	// 4.18
	KFeatProgLIRCMode2
	// 4.19
	KFeatProgSKReusePort
	// 4.20
	KFeatProgFlowDissector
	// 5.2
	KFeatProgCGroupSysctl
	// 5.2
	KFeatProgRawTracepointWritable
	// 5.3
	KFeatProgCgroupSocketOpt
	// 5.5
	KFeatProgTracing
	// 5.6
	KFeatProgStructOps
	// 5.6
	KFeatProgExt
	// 5.7
	KFeatProgLSM
	// 5.9
	KFeatProgSKLookup
)

TODO add comments

func (ProgramSupport) Has

func (ps ProgramSupport) Has(flags ProgramSupport) bool

Has returns true if 'ps' has all the specified flags

func (ProgramSupport) String

func (ps ProgramSupport) String() string

Jump to

Keyboard shortcuts

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