ebpf

package
v0.0.0-...-51bb0a0 Latest Latest
Warning

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

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

Documentation

Overview

Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0. This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2024 Datadog, Inc.

Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0. This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2024 Datadog, Inc.

Index

Constants

View Source
const BpftoolBinary = "bpftool"
View Source
const SysOpenat = "__x64_sys_openat"

Variables

This section is empty.

Functions

This section is empty.

Types

type ConfigInformer

type ConfigInformer interface {
	// GetKernelFeatures retrieves kernel features and returns them as a 'Features' struct,
	// along with any encountered error.
	GetKernelFeatures() (Features, error)

	// ValidateRequiredSystemConfig validates the required system configuration.
	// It returns an error if the validation fails.
	ValidateRequiredSystemConfig() error

	// GetRequiredSystemConfig retrieves the required system configuration parameters as
	// a 'KernelParams' struct.
	GetRequiredSystemConfig() KernelParams

	// GetMapTypes retrieves information about available map types and returns them as a 'MapTypes' struct.
	GetMapTypes() MapTypes

	// IsKernelConfigAvailable checks if the kernel configuration is available
	IsKernelConfigAvailable() bool
}

ConfigInformer is an interface that defines a set of methods for retrieving and validating system configuration information related to kernel features and maps.

func NewConfigInformer

func NewConfigInformer(log *zap.SugaredLogger, dryRun bool, executor Executor, fsMock fs.StatFS, unameFuncMock func() (unix.Utsname, error)) (ConfigInformer, error)

NewConfigInformer creates and returns a new instance of a ConfigInformer, which is an interface that provides methods to retrieve system configuration information.

Parameters:

  • log: Required - A SugaredLogger from the zap library used for logging.
  • dryRun: Required - A boolean flag indicating whether the operations should be executed as a dry run.
  • executor: An Executor interface that defines how system commands are executed. If nil, a default BpftoolExecutor is created.
  • FSMock: A FileSystem interface used for file operations. If nil, the default osFS implementation is used.
  • unameFuncMock: A function that provides Utsname information. If nil, the system's Uname function is used.

Returns:

  • ConfigInformer: An interface for retrieving system configuration information.
  • error: An error, if any, encountered during the creation and initialization of the ConfigInformer.

type ConfigInformerMock

type ConfigInformerMock struct {
	mock.Mock
}

ConfigInformerMock is an autogenerated mock type for the ConfigInformer type

func NewConfigInformerMock

func NewConfigInformerMock(t interface {
	mock.TestingT
	Cleanup(func())
}) *ConfigInformerMock

NewConfigInformerMock creates a new instance of ConfigInformerMock. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. The first argument is typically a *testing.T value.

func (*ConfigInformerMock) EXPECT

func (*ConfigInformerMock) GetKernelFeatures

func (_m *ConfigInformerMock) GetKernelFeatures() (Features, error)

GetKernelFeatures provides a mock function with given fields:

func (*ConfigInformerMock) GetMapTypes

func (_m *ConfigInformerMock) GetMapTypes() MapTypes

GetMapTypes provides a mock function with given fields:

func (*ConfigInformerMock) GetRequiredSystemConfig

func (_m *ConfigInformerMock) GetRequiredSystemConfig() KernelParams

GetRequiredSystemConfig provides a mock function with given fields:

func (*ConfigInformerMock) IsKernelConfigAvailable

func (_m *ConfigInformerMock) IsKernelConfigAvailable() bool

IsKernelConfigAvailable provides a mock function with given fields:

func (*ConfigInformerMock) ValidateRequiredSystemConfig

func (_m *ConfigInformerMock) ValidateRequiredSystemConfig() error

ValidateRequiredSystemConfig provides a mock function with given fields:

type ConfigInformerMock_Expecter

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

func (*ConfigInformerMock_Expecter) GetKernelFeatures

GetKernelFeatures is a helper method to define mock.On call

func (*ConfigInformerMock_Expecter) GetMapTypes

GetMapTypes is a helper method to define mock.On call

func (*ConfigInformerMock_Expecter) GetRequiredSystemConfig

GetRequiredSystemConfig is a helper method to define mock.On call

func (*ConfigInformerMock_Expecter) IsKernelConfigAvailable

IsKernelConfigAvailable is a helper method to define mock.On call

func (*ConfigInformerMock_Expecter) ValidateRequiredSystemConfig

ValidateRequiredSystemConfig is a helper method to define mock.On call

type ConfigInformerMock_GetKernelFeatures_Call

type ConfigInformerMock_GetKernelFeatures_Call struct {
	*mock.Call
}

ConfigInformerMock_GetKernelFeatures_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetKernelFeatures'

func (*ConfigInformerMock_GetKernelFeatures_Call) Return

func (*ConfigInformerMock_GetKernelFeatures_Call) Run

func (*ConfigInformerMock_GetKernelFeatures_Call) RunAndReturn

type ConfigInformerMock_GetMapTypes_Call

type ConfigInformerMock_GetMapTypes_Call struct {
	*mock.Call
}

ConfigInformerMock_GetMapTypes_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetMapTypes'

func (*ConfigInformerMock_GetMapTypes_Call) Return

func (*ConfigInformerMock_GetMapTypes_Call) Run

func (*ConfigInformerMock_GetMapTypes_Call) RunAndReturn

type ConfigInformerMock_GetRequiredSystemConfig_Call

type ConfigInformerMock_GetRequiredSystemConfig_Call struct {
	*mock.Call
}

ConfigInformerMock_GetRequiredSystemConfig_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetRequiredSystemConfig'

func (*ConfigInformerMock_GetRequiredSystemConfig_Call) Return

func (*ConfigInformerMock_GetRequiredSystemConfig_Call) Run

func (*ConfigInformerMock_GetRequiredSystemConfig_Call) RunAndReturn

type ConfigInformerMock_IsKernelConfigAvailable_Call

type ConfigInformerMock_IsKernelConfigAvailable_Call struct {
	*mock.Call
}

ConfigInformerMock_IsKernelConfigAvailable_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'IsKernelConfigAvailable'

func (*ConfigInformerMock_IsKernelConfigAvailable_Call) Return

func (*ConfigInformerMock_IsKernelConfigAvailable_Call) Run

func (*ConfigInformerMock_IsKernelConfigAvailable_Call) RunAndReturn

type ConfigInformerMock_ValidateRequiredSystemConfig_Call

type ConfigInformerMock_ValidateRequiredSystemConfig_Call struct {
	*mock.Call
}

ConfigInformerMock_ValidateRequiredSystemConfig_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ValidateRequiredSystemConfig'

func (*ConfigInformerMock_ValidateRequiredSystemConfig_Call) Return

func (*ConfigInformerMock_ValidateRequiredSystemConfig_Call) Run

func (*ConfigInformerMock_ValidateRequiredSystemConfig_Call) RunAndReturn

type Executor

type Executor interface {
	Run(args []string) (exitCode int, stdout string, stderr error)
}

func NewBpftoolExecutor

func NewBpftoolExecutor(log *zap.SugaredLogger, dryRun bool) Executor

NewBpftoolExecutor create a new instance of an Executor responsible of running bpftool command

type ExecutorMock

type ExecutorMock struct {
	mock.Mock
}

ExecutorMock is an autogenerated mock type for the Executor type

func NewExecutorMock

func NewExecutorMock(t interface {
	mock.TestingT
	Cleanup(func())
}) *ExecutorMock

NewExecutorMock creates a new instance of ExecutorMock. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. The first argument is typically a *testing.T value.

func (*ExecutorMock) EXPECT

func (_m *ExecutorMock) EXPECT() *ExecutorMock_Expecter

func (*ExecutorMock) Run

func (_m *ExecutorMock) Run(args []string) (int, string, error)

Run provides a mock function with given fields: args

type ExecutorMock_Expecter

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

func (*ExecutorMock_Expecter) Run

func (_e *ExecutorMock_Expecter) Run(args interface{}) *ExecutorMock_Run_Call

Run is a helper method to define mock.On call

  • args []string

type ExecutorMock_Run_Call

type ExecutorMock_Run_Call struct {
	*mock.Call
}

ExecutorMock_Run_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Run'

func (*ExecutorMock_Run_Call) Return

func (_c *ExecutorMock_Run_Call) Return(exitCode int, stdout string, stderr error) *ExecutorMock_Run_Call

func (*ExecutorMock_Run_Call) Run

func (_c *ExecutorMock_Run_Call) Run(run func(args []string)) *ExecutorMock_Run_Call

func (*ExecutorMock_Run_Call) RunAndReturn

func (_c *ExecutorMock_Run_Call) RunAndReturn(run func([]string) (int, string, error)) *ExecutorMock_Run_Call

type Features

type Features struct {
	// SystemConfig represents a system's configuration information.
	SystemConfig `json:"system_config"`

	// MapTypes represents information about available map types.
	MapTypes `json:"map_types"`
}

Features is a struct that represents a collection of features.

type KernelOption

type KernelOption struct {
	Description string
	Enabled     bool
}

KernelOption holds information about kernel parameters to probe.

type KernelParam

type KernelParam string

KernelParam is a type based on string which represents CONFIG_* kernel parameters which usually have values "y", "n" or "m".

func (KernelParam) Enabled

func (kp KernelParam) Enabled() bool

Enabled checks whether the kernel parameter is enabled.

type KernelParams

type KernelParams map[KernelParam]KernelOption

KernelParams is a map that associates KernelParam keys with their corresponding KernelOption values. It is used to store and manage kernel parameters and their options.

type MapTypes

type MapTypes struct {
	HaveHashMapType                bool `json:"have_hash_map_type"`
	HaveArrayMapType               bool `json:"have_array_map_type"`
	HaveProgArrayMapType           bool `json:"have_prog_array_map_type"`
	HavePerfEventArrayMapType      bool `json:"have_perf_event_array_map_type"`
	HavePercpuHashMapType          bool `json:"have_percpu_hash_map_type"`
	HavePercpuArrayMapType         bool `json:"have_percpu_array_map_type"`
	HaveStackTraceMapType          bool `json:"have_stack_trace_map_type"`
	HaveCgroupArrayMapType         bool `json:"have_cgroup_array_map_type"`
	HaveLruHashMapType             bool `json:"have_lru_hash_map_type"`
	HaveLruPercpuHashMapType       bool `json:"have_lru_percpu_hash_map_type"`
	HaveLpmTrieMapType             bool `json:"have_lpm_trie_map_type"`
	HaveArrayOfMapsMapType         bool `json:"have_array_of_maps_map_type"`
	HaveHashOfMapsMapType          bool `json:"have_hash_of_maps_map_type"`
	HaveDevmapMapType              bool `json:"have_devmap_map_type"`
	HaveSockmapMapType             bool `json:"have_sockmap_map_type"`
	HaveCpumapMapType              bool `json:"have_cpumap_map_type"`
	HaveXskmapMapType              bool `json:"have_xskmap_map_type"`
	HaveSockhashMapType            bool `json:"have_sockhash_map_type"`
	HaveCgroupStorageMapType       bool `json:"have_cgroup_storage_map_type"`
	HaveReuseportSockarrayMapType  bool `json:"have_reuseport_sockarray_map_type"`
	HavePercpuCgroupStorageMapType bool `json:"have_percpu_cgroup_storage_map_type"`
	HaveQueueMapType               bool `json:"have_queue_map_type"`
	HaveStackMapType               bool `json:"have_stack_map_type"`
}

MapTypes contains bools indicating which types of BPF maps the currently running kernel supports.

type SystemConfig

type SystemConfig struct {
	UnprivilegedBpfDisabled      int         `json:"unprivileged_bpf_disabled"`
	BpfJitEnable                 int         `json:"bpf_jit_enable"`
	BpfJitHarden                 int         `json:"bpf_jit_harden"`
	BpfJitKallsyms               int         `json:"bpf_jit_kallsyms"`
	BpfJitLimit                  int         `json:"bpf_jit_limit"`
	ConfigBpf                    KernelParam `json:"CONFIG_BPF"`
	ConfigBpfSyscall             KernelParam `json:"CONFIG_BPF_SYSCALL"`
	ConfigHaveEbpfJit            KernelParam `json:"CONFIG_HAVE_EBPF_JIT"`
	ConfigBpfJit                 KernelParam `json:"CONFIG_BPF_JIT"`
	ConfigBpfJitAlwaysOn         KernelParam `json:"CONFIG_BPF_JIT_ALWAYS_ON"`
	ConfigCgroups                KernelParam `json:"CONFIG_CGROUPS"`
	ConfigCgroupBpf              KernelParam `json:"CONFIG_CGROUP_BPF"`
	ConfigCgroupNetClassID       KernelParam `json:"CONFIG_CGROUP_NET_CLASSID"`
	ConfigSockCgroupData         KernelParam `json:"CONFIG_SOCK_CGROUP_DATA"`
	ConfigBpfEvents              KernelParam `json:"CONFIG_BPF_EVENTS"`
	ConfigKprobeEvents           KernelParam `json:"CONFIG_KPROBE_EVENTS"`
	ConfigUprobeEvents           KernelParam `json:"CONFIG_UPROBE_EVENTS"`
	ConfigTracing                KernelParam `json:"CONFIG_TRACING"`
	ConfigFtraceSyscalls         KernelParam `json:"CONFIG_FTRACE_SYSCALLS"`
	ConfigFunctionErrorInjection KernelParam `json:"CONFIG_FUNCTION_ERROR_INJECTION"`
	ConfigBpfKprobeOverride      KernelParam `json:"CONFIG_BPF_KPROBE_OVERRIDE"`
	ConfigNet                    KernelParam `json:"CONFIG_NET"`
	ConfigXdpSockets             KernelParam `json:"CONFIG_XDP_SOCKETS"`
	ConfigLwtunnelBpf            KernelParam `json:"CONFIG_LWTUNNEL_BPF"`
	ConfigNetActBpf              KernelParam `json:"CONFIG_NET_ACT_BPF"`
	ConfigNetClsBpf              KernelParam `json:"CONFIG_NET_CLS_BPF"`
	ConfigNetClsAct              KernelParam `json:"CONFIG_NET_CLS_ACT"`
	ConfigNetSchIngress          KernelParam `json:"CONFIG_NET_SCH_INGRESS"`
	ConfigXfrm                   KernelParam `json:"CONFIG_XFRM"`
	ConfigIPRouteClassID         KernelParam `json:"CONFIG_IP_ROUTE_CLASSID"`
	ConfigIPv6Seg6Bpf            KernelParam `json:"CONFIG_IPV6_SEG6_BPF"`
	ConfigBpfLircMode2           KernelParam `json:"CONFIG_BPF_LIRC_MODE2"`
	ConfigBpfStreamParser        KernelParam `json:"CONFIG_BPF_STREAM_PARSER"`
	ConfigNetfilterXtMatchBpf    KernelParam `json:"CONFIG_NETFILTER_XT_MATCH_BPF"`
	ConfigBpfilter               KernelParam `json:"CONFIG_BPFILTER"`
	ConfigBpfilterUmh            KernelParam `json:"CONFIG_BPFILTER_UMH"`
	ConfigTestBpf                KernelParam `json:"CONFIG_TEST_BPF"`
	ConfigKernelHz               KernelParam `json:"CONFIG_HZ"`
}

SystemConfig contains kernel configuration and sysctl parameters related to BPF functionality.

Jump to

Keyboard shortcuts

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