bpfprogs

package
v2.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2024 License: Apache-2.0 Imports: 41 Imported by: 0

Documentation

Overview

Package bpfprogs provides primitives for BPF programs / Network Functions.

Package bpfprogs provides primitives for l3afd's network function configs.

Package bpfprogs provides primitives for NF process monitoring.

Package bpfprogs provides primitives for l3afd's network function configs.

Package bpfprogs provides primitives for BPF process monitoring.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BinarySearch

func BinarySearch(names []string, target string) bool

BinarySearch: It is checking a target string exists in sorted slice of strings

func DisableLRO

func DisableLRO(ifaceName string) error

DisableLRO - XDP programs are failing when LRO is enabled, to fix this we use to manually disable. # ethtool -K ens7 lro off # ethtool -k ens7 | grep large-receive-offload large-receive-offload: off

func DownloadArtifact

func DownloadArtifact(urlpath string, timeout time.Duration, buf *bytes.Buffer) error

DownloadArtifact will download artifact from provided urlpath and store it in buffer

func ExtractArtifact

func ExtractArtifact(artifactName string, buf *bytes.Buffer, tempDir string) error

ExtractArtifact will extract artifact to given tempDir

func GetPlatform

func GetPlatform() (string, error)

This method get the Linux distribution Codename. This logic works on ubuntu Here assumption is all edge nodes are running with lsb modules. It returns empty string in case of error

func GetProgramSectionDetails

func GetProgramSectionDetails(sectionName string) (string, string)

GetProgramSectionDetails returns group and name details Section name format /prob type/group/name e.g.: tracepoint/sock/inet_sock_set_state e.g.: kprobe/sys_execve

func GetTestExecutableName

func GetTestExecutableName() string

func GetTestExecutablePath

func GetTestExecutablePath() string

func GetTestExecutablePathName

func GetTestExecutablePathName() string

func GetTestNonexecutablePathName

func GetTestNonexecutablePathName() string

func IsProcessRunning

func IsProcessRunning(pid int, name string) (bool, error)

func SerialzeProgram

func SerialzeProgram(e *list.Element) *models.L3AFMetaData

SerialzeProgram this function wil serialize the program

func SetupBPFDebug

func SetupBPFDebug(ebpfChainDebugAddr string, BPFConfigs *NFConfigs)

func StopExternalRunningProcess

func StopExternalRunningProcess(processName string) error

Stop the NF process if running outside l3afd

func ValidatePath

func ValidatePath(filePath string, destination string) (string, error)

ValidatePath will validate any illegal file path

func VerifyNCreateTCDirs

func VerifyNCreateTCDirs() error

VerifyNCreateTCDirs - Creating BPF sudo FS for pinning TC maps

func VerifyNMountBPFFS

func VerifyNMountBPFFS() error

VerifyNMountBPFFS - Mounting bpf filesystem

func VerifyNMountTraceFS

func VerifyNMountTraceFS() error

VerifyNMounTraceFS - Mounting trace filesystem

func ViewHandler

func ViewHandler(w http.ResponseWriter, r *http.Request)

Types

type BPF

type BPF struct {
	Program           models.BPFProgram
	Cmd               *exec.Cmd                 `json:"-"`
	FilePath          string                    // Binary file path
	RestartCount      int                       // To track restart count
	PrevMapNamePath   string                    // Previous Map name with path to link
	MapNamePath       string                    // Map name with path
	ProgID            ebpf.ProgramID            // eBPF Program ID
	BpfMaps           map[string]BPFMap         // Config maps passed as map-args, Map name is Key
	MetricsBpfMaps    map[string]*MetricsBPFMap // Metrics map name+key+aggregator is key
	Ctx               context.Context           `json:"-"`
	Done              chan bool                 `json:"-"`
	ProgMapCollection *ebpf.Collection          `json:"_"` // eBPF Collection reference
	ProgMapID         ebpf.MapID                // Prog map id
	PrevProgMapID     ebpf.MapID                // Prev prog map id
	HostConfig        *config.Config
	XDPLink           link.Link `json:"-"` // handle xdp link object
	ProbeLinks        []*link.Link
}

BPF defines run time details for BPFProgram.

func LoadRootProgram

func LoadRootProgram(ifaceName string, direction string, progType string, conf *config.Config) (*BPF, error)

LoadRootProgram - Loading the Root Program for a given interface.

func NewBpfProgram

func NewBpfProgram(ctx context.Context, program models.BPFProgram, conf *config.Config, ifaceName string) *BPF

func (*BPF) AddBPFMap

func (b *BPF) AddBPFMap(mapName string) error

Add eBPF map into BPFMaps list

func (*BPF) AddMetricsBPFMap

func (b *BPF) AddMetricsBPFMap(mapName, aggregator string, key, samplesLength int) error

Add eBPF map into BPFMaps list

func (*BPF) AttachBPFProgram

func (b *BPF) AttachBPFProgram(ifaceName, direction string) error

AttachBPFProgram - method to attach bpf program to interface

func (*BPF) CreatePinDirectories

func (b *BPF) CreatePinDirectories(ifaceName string) error

CreatePinDirectories - This method creates directory for ebpf objects TC maps are pinned to directory /sys/fs/bpf/tc/globals/<ifaceName> XDP maps are pinned to directory /sys/fs/bpf/<ifaceName> links are pinned to directory /sys/fs/bpf/links/<ifaceName> Program are pinned to directory /sys/fs/bpf/progs/<ifaceName>

func (*BPF) GetArtifacts

func (b *BPF) GetArtifacts(conf *config.Config) error

GetArtifacts downloads artifacts from the specified eBPF repo

func (*BPF) GetBPFMap

func (b *BPF) GetBPFMap(mapName string) (*BPFMap, error)

func (*BPF) GetProgID

func (b *BPF) GetProgID() (ebpf.ProgramID, error)

GetProgID - This returns ID of the bpf program

func (*BPF) InitialiseMetricMaps

func (b *BPF) InitialiseMetricMaps() error

InitialiseMetricMaps - This method initialises all the monitor maps

func (*BPF) IsLoaded

func (b *BPF) IsLoaded() bool

IsLoaded - Method verifies whether bpf program is loaded or not Here it checks whether prog ID is valid and active

func (*BPF) LoadBPFProgram

func (b *BPF) LoadBPFProgram(ifaceName string) error

LoadBPFProgram - This method loads the eBPF program natively.

func (*BPF) LoadBPFProgramChain

func (b *BPF) LoadBPFProgramChain(ifaceName, direction string) error

LoadBPFProgramChain - Load the BPF program and chain it.

func (*BPF) LoadBPFProgramProbeType

func (b *BPF) LoadBPFProgramProbeType(prog *ebpf.Program, sectionName string) error

func (*BPF) LoadBPFProgramProbeTypes

func (b *BPF) LoadBPFProgramProbeTypes(objSpec *ebpf.CollectionSpec) error

LoadBPFProgramProbeTypes - Load the BPF programs of probe types - TracePoint

func (*BPF) LoadTCAttachProgram

func (b *BPF) LoadTCAttachProgram(ifaceName, direction string) error

LoadTCAttachProgram - Load and attach tc root program filters or any tc program when chaining is disabled

func (*BPF) LoadXDPAttachProgram

func (b *BPF) LoadXDPAttachProgram(ifaceName string) error

LoadXDPAttachProgram - Load and attach xdp root program or any xdp program when chaining is disabled

func (*BPF) MonitorMaps

func (b *BPF) MonitorMaps(ifaceName string, intervals int) error

This method to fetch values from bpf maps and publish to metrics

func (*BPF) PinBpfMaps

func (b *BPF) PinBpfMaps(ifaceName string) error

PinBpfMaps - Pinning tc and xdp maps

func (*BPF) ProcessTerminate

func (b *BPF) ProcessTerminate() error

ProcessTerminate - Send sigterm to the process

func (*BPF) PutNextProgFDFromID

func (b *BPF) PutNextProgFDFromID(progID int) error

Updating next program FD from program ID

func (*BPF) RemoveNextProgFD

func (b *BPF) RemoveNextProgFD() error

RemoveNextProgFD Delete the entry if its last program in the chain. This method is called when sequence of the program changed to last in the chain

func (*BPF) RemovePinnedFiles

func (b *BPF) RemovePinnedFiles(ifaceName string) error

RemovePinnedFiles - removes all the pinned files

func (*BPF) RemovePrevProgFD

func (b *BPF) RemovePrevProgFD() error

RemovePrevProgFD Delete the entry if the last element

func (*BPF) RemoveRootProgMapFile

func (b *BPF) RemoveRootProgMapFile(ifacename string) error

RemoveRootProgMapFile - removes root pinned prog map file This is invoked if any stale map file persists for root map

func (*BPF) RunBPFConfigs

func (b *BPF) RunBPFConfigs() error

func (*BPF) SetPrLimits

func (b *BPF) SetPrLimits() error

Set process resource limits only non-zero value

func (*BPF) Start

func (b *BPF) Start(ifaceName, direction string, chain bool) error

Start returns the last error seen, but starts bpf program. Here initially prevprogmap entry is removed and passed to the bpf program After starting the user program, will update the kernel progam fd into prevprogram map. This method waits till prog fd entry is updated, else returns error assuming kernel program is not loaded. It also verifies the next program pinned map is created or not.

func (*BPF) StartUserProgram

func (b *BPF) StartUserProgram(ifaceName, direction string, chain bool) error

func (*BPF) Stop

func (b *BPF) Stop(ifaceName, direction string, chain bool) error

Stop returns the last error seen, but stops bpf program. Stops the user programs if any, and unloads the BPF program. Clean up all map handles. Verify next program pinned map file is removed

func (*BPF) StopUserProgram

func (b *BPF) StopUserProgram(ifaceName, direction string) error

func (*BPF) UnloadProgram

func (b *BPF) UnloadProgram(ifaceName, direction string) error

UnloadProgram - Unload or detach the program from the interface and close all the program resources

func (*BPF) UnloadTCProgram

func (b *BPF) UnloadTCProgram(ifaceName, direction string) error

UnloadTCProgram - Remove TC filters

func (*BPF) UpdateArgs

func (b *BPF) UpdateArgs(ifaceName, direction string) error

Update config arguments using user program

func (*BPF) UpdateBPFMaps

func (b *BPF) UpdateBPFMaps(ifaceName, direction string) error

UpdateBPFMaps - Update the config ebpf maps via map arguments

func (*BPF) UpdateProgramMap

func (b *BPF) UpdateProgramMap(ifaceName string) error

UpdateProgramMap - Store the program map reference

func (*BPF) VerifyAndGetArtifacts

func (b *BPF) VerifyAndGetArtifacts(conf *config.Config) error

VerifyAndGetArtifacts -Check binary already exists

func (*BPF) VerifyCleanupMaps

func (b *BPF) VerifyCleanupMaps(chain bool) error

VerifyCleanupMaps - This method verifies map entries in the fs is removed

func (*BPF) VerifyMetricsMapsVanish

func (b *BPF) VerifyMetricsMapsVanish() error

VerifyMetricsMapsVanish - checks for all metrics maps references are removed from the kernel

func (*BPF) VerifyPinnedProgMap

func (b *BPF) VerifyPinnedProgMap(chain, exists bool) error

VerifyPinnedProgMap - making sure program fd map's pinned file is created if exists flag is true

func (*BPF) VerifyProcessObject

func (b *BPF) VerifyProcessObject() error

VerifyProcessObject - This method to verify cmd and process object is populated or not

type BPFMap

type BPFMap struct {
	Name  string
	MapID ebpf.MapID
	Type  ebpf.MapType

	// BPFProg reference in case of stale map id
	BPFProg *BPF `json:"-"`
}

func (*BPFMap) RemoveMissingKeys

func (b *BPFMap) RemoveMissingKeys(args []models.KeyValue) error

The RemoveMissingKeys function is used to delete missing entries of eBPF maps, which are used by eBPF Programs.

func (*BPFMap) Update

func (b *BPFMap) Update(key, value int) error

The update function is used to update eBPF maps, which are used by eBPF programs.

type BpfMetrics

type BpfMetrics struct {
	Chain     bool
	Intervals int
}

func NewpBpfMetrics

func NewpBpfMetrics(chain bool, interval int) *BpfMetrics

func (*BpfMetrics) BpfMetricsProbeWorker

func (c *BpfMetrics) BpfMetricsProbeWorker(bpfProgs *list.List)

func (*BpfMetrics) BpfMetricsStart

func (c *BpfMetrics) BpfMetricsStart(xdpProgs, ingressTCProgs, egressTCProgs map[string]*list.List, probes *list.List)

func (*BpfMetrics) BpfMetricsWorker

func (c *BpfMetrics) BpfMetricsWorker(bpfProgs map[string]*list.List)

type MetricsBPFMap

type MetricsBPFMap struct {
	BPFMap
	Key        int
	Values     *ring.Ring
	Aggregator string
	LastValue  float64
}

This stores Metrics map details.

func (*MetricsBPFMap) AvgValue

func (b *MetricsBPFMap) AvgValue() float64

This method calculates the average

func (*MetricsBPFMap) GetValue

func (b *MetricsBPFMap) GetValue() float64

Get value of the map for given key There are 2 aggregators are supported here max-rate - this calculates delta requests / sec and stores absolute value. avg - stores the values in the circular queue We can implement more aggregate function as needed.

func (*MetricsBPFMap) MaxValue

func (b *MetricsBPFMap) MaxValue() float64

This method finds the max value in the circular list

type NFConfigs

type NFConfigs struct {
	Ctx            context.Context
	HostName       string
	HostInterfaces map[string]bool
	//	configs        sync.Map // key: string, val: *models.L3afDNFConfigDetail
	// These holds bpf programs in the list
	// map keys are network iface names index's are seq_id, position in the chain
	// root element will be root program
	IngressXDPBpfs map[string]*list.List
	IngressTCBpfs  map[string]*list.List
	EgressTCBpfs   map[string]*list.List
	ProbesBpfs     list.List

	HostConfig    *config.Config
	ProcessMon    *PCheck
	BpfMetricsMon *BpfMetrics

	// keep track of interfaces
	Ifaces map[string]string

	Mu *sync.Mutex
}

func NewNFConfigs

func NewNFConfigs(ctx context.Context, host string, hostConf *config.Config, pMon *PCheck, metricsMon *BpfMetrics) (*NFConfigs, error)

func (*NFConfigs) AddAndStartBPF

func (c *NFConfigs) AddAndStartBPF(bpfProg *models.BPFProgram, ifaceName string, direction string) error

func (*NFConfigs) AddProbePrograms

func (c *NFConfigs) AddProbePrograms(HostName string, bpfProgs []*models.BPFProgram) error

func (*NFConfigs) AddProgramWithoutChaining

func (c *NFConfigs) AddProgramWithoutChaining(ifaceName string, bpfProgs *models.BPFPrograms) error

AddProgramWithoutChaining : add eBPF program on given interface when chaining is not enabled

func (*NFConfigs) AddProgramsOnInterface

func (c *NFConfigs) AddProgramsOnInterface(ifaceName, HostName string, bpfProgs *models.BPFPrograms) error

AddProgramsOnInterface will add given ebpf programs on given interface

func (*NFConfigs) AddeBPFPrograms

func (c *NFConfigs) AddeBPFPrograms(bpfProgs []models.L3afBPFPrograms) error

AddeBPFPrograms - Starts eBPF programs on the node if they are not running

func (*NFConfigs) BPFDetails

func (c *NFConfigs) BPFDetails(iface string) []*BPF

BPFDetails - Method provides dump of BPFs for debug purpose

func (*NFConfigs) CleanupProgramsOnInterface

func (c *NFConfigs) CleanupProgramsOnInterface(ifaceName string)

CleanupProgramsOnInterface removes all EBPF program and its metadata, on the network interface provided

func (*NFConfigs) Close

func (c *NFConfigs) Close(ctx context.Context) error

Close stop all the eBPF Programs and delete elements in the list

func (*NFConfigs) DeleteEbpfPrograms

func (c *NFConfigs) DeleteEbpfPrograms(bpfProgs []models.L3afBPFProgramNames) error

DeleteEbpfPrograms - Delete eBPF programs on the node if they are running

func (*NFConfigs) DeleteProgramsOnInterface

func (c *NFConfigs) DeleteProgramsOnInterface(ifaceName, HostName string, bpfProgs *models.BPFProgramNames) error

DeleteProgramsOnInterface : It will delete ebpf Programs on the given interface

func (*NFConfigs) DeleteProgramsOnInterfaceHelper

func (c *NFConfigs) DeleteProgramsOnInterfaceHelper(e *list.Element, ifaceName string, direction string, bpfList *list.List) error

DeleteProgramsOnInterfaceHelper : helper function for DeleteProgramsOnInterface function

func (*NFConfigs) Deploy

func (c *NFConfigs) Deploy(ifaceName, HostName string, bpfProgs *models.BPFPrograms) error

func (*NFConfigs) DeployeBPFPrograms

func (c *NFConfigs) DeployeBPFPrograms(bpfProgs []models.L3afBPFPrograms) error

DeployeBPFPrograms - Starts eBPF programs on the node if they are not running

func (*NFConfigs) DownloadAndStartBPFProgram

func (c *NFConfigs) DownloadAndStartBPFProgram(element *list.Element, ifaceName, direction string) error

func (*NFConfigs) DownloadAndStartProbes

func (c *NFConfigs) DownloadAndStartProbes(element *list.Element) error

func (*NFConfigs) EBPFPrograms

func (c *NFConfigs) EBPFPrograms(iface string) models.L3afBPFPrograms

EBPFPrograms - Method provides list of eBPF Programs running on iface

func (*NFConfigs) EBPFProgramsAll

func (c *NFConfigs) EBPFProgramsAll() []models.L3afBPFPrograms

EBPFProgramsAll - Method provides list of eBPF Programs running on all ifaces on the host

func (*NFConfigs) GetL3AFHOSTDATA

func (c *NFConfigs) GetL3AFHOSTDATA() models.L3AFALLHOSTDATA

GetL3AFHOSTDATA this function will give serialize form of current l3afd state

func (*NFConfigs) InsertAndStartBPFProgram

func (c *NFConfigs) InsertAndStartBPFProgram(bpfProg *models.BPFProgram, ifaceName, direction string) error

InsertAndStartBPFProgram method for tc programs

func (*NFConfigs) LinkBPFPrograms

func (c *NFConfigs) LinkBPFPrograms(leftBPF, rightBPF *BPF) error

Link BPF programs

func (*NFConfigs) MoveToLocation

func (c *NFConfigs) MoveToLocation(element *list.Element, bpfList *list.List) error

func (*NFConfigs) PushBackAndStartBPF

func (c *NFConfigs) PushBackAndStartBPF(bpfProg *models.BPFProgram, ifaceName, direction string) error

This method inserts the element at the end of the list

func (*NFConfigs) PushBackAndStartProbe

func (c *NFConfigs) PushBackAndStartProbe(bpfProg *models.BPFProgram) error

PushBackAndStartProbe method inserts the element at the end of the list

func (*NFConfigs) RemoveMissingBPFProgramsInConfig

func (c *NFConfigs) RemoveMissingBPFProgramsInConfig(bpfProg models.L3afBPFPrograms, ifaceName, direction string) error

RemoveMissingBPFProgramsInConfig - This method to stop the eBPF programs which are not listed in the config.

func (*NFConfigs) RemoveMissingNetIfacesNBPFProgsInConfig

func (c *NFConfigs) RemoveMissingNetIfacesNBPFProgsInConfig(bpfProgCfgs []models.L3afBPFPrograms) error

RemoveMissingNetIfacesNBPFProgsInConfig - Stops running eBPF programs which are missing in the config

func (*NFConfigs) SaveConfigsToConfigStore

func (c *NFConfigs) SaveConfigsToConfigStore() error

SaveConfigsToConfigStore - Writes configs to persistent store

func (*NFConfigs) StartAllUserProgramsAndProbes

func (c *NFConfigs) StartAllUserProgramsAndProbes() error

StartAllUserProgramsAndProbes this function will restart all the User Programs and probes

func (*NFConfigs) StopAllProbesAndUserPrograms

func (c *NFConfigs) StopAllProbesAndUserPrograms() error

StopAllProbesAndUserPrograms this function will stop all the probes & stops user programs

func (*NFConfigs) StopNRemoveAllBPFProbePrograms

func (c *NFConfigs) StopNRemoveAllBPFProbePrograms() error

StopNRemoveAllBPFProbePrograms Stopping all probe programs in order

func (*NFConfigs) StopNRemoveAllBPFPrograms

func (c *NFConfigs) StopNRemoveAllBPFPrograms(ifaceName, direction string) error

Stopping all programs in order

func (*NFConfigs) StopRootProgram

func (c *NFConfigs) StopRootProgram(ifaceName, direction string) error

StopRootProgram -This method stops the root program, removes the root node from the list and reset the list to nil

func (*NFConfigs) VerifyAndStartTCRootProgram

func (c *NFConfigs) VerifyAndStartTCRootProgram(ifaceName, direction string) error

Check for TC root program is running for a interface. If not start it

func (*NFConfigs) VerifyAndStartXDPRootProgram

func (c *NFConfigs) VerifyAndStartXDPRootProgram(ifaceName, direction string) error

Check for XDP programs are not loaded then initialise the array Check for XDP root program is running for a interface. if not loaded it

func (*NFConfigs) VerifyNUpdateBPFProgram

func (c *NFConfigs) VerifyNUpdateBPFProgram(bpfProg *models.BPFProgram, ifaceName, direction string) error

VerifyNUpdateBPFProgram - This method checks the following conditions 1. BPF Program already running with no change 2. BPF Program running but needs to stop (admin_status == disabled) 3. BPF Program running but needs version update 4. BPF Program running but position change (seq_id change) 5. BPF Program not running but needs to start. 6. BPF Program running but map args change, will update the map values (i.e. Array and Hash maps only) 7. BPF Program running but update args change, will invoke cmd_update with additional option --cmd=update

type PCheck

type PCheck struct {
	MaxRetryCount     int
	Chain             bool
	RetryMonitorDelay time.Duration
}

func NewPCheck

func NewPCheck(rc int, chain bool, interval time.Duration) *PCheck

func (*PCheck) PCheckStart

func (c *PCheck) PCheckStart(xdpProgs, ingressTCProgs, egressTCProgs map[string]*list.List, probes *list.List)

Jump to

Keyboard shortcuts

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