kf

package
v2.0.1-0...-1980a61 Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2024 License: Apache-2.0 Imports: 39 Imported by: 0

Documentation

Overview

Package kf provides primitives for BPF programs / Network Functions.

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

Package kf provides primitives for NF process monitoring.

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

Package kf 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 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 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 NewpCheck

func NewpCheck(rc int, chain bool, interval time.Duration) *pCheck

func NewpKFMetrics

func NewpKFMetrics(chain bool, interval int) *kfMetrics

func SetupKFDebug

func SetupKFDebug(ebpfChainDebugAddr string, kfConfigs *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)

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

	TCFilter *tc.Filter `json:"-"` // handle to tc filter
	XDPLink  link.Link  `json:"-"` // handle xdp link object
	// contains filtered or unexported fields
}

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) CreateMapPinDirectory

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

CreateMapPinDirectory - This method creates directory for pinning maps TC maps are pinned to directory /sys/fs/bpf/tc/globals/<ifaceName> XDP maps are pinned to directory /sys/fs/bpf/<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) 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) RemoveMapFiles

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

RemoveMapFiles - removes all the pinned map files

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) 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) RunKFConfigs

func (b *BPF) RunKFConfigs() 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) 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) Update

func (b *BPFMap) Update(value string) error

The update function is used to update eBPF maps, which are used by network functions. Supported types are Array and Hash Multiple values are comma separated Hashmap can be multiple values or single values. If hash map entries then key will be values and value will be set to 1 In case of Array then key will be index starting from 0 and values are stored. for e.g.

HashMap scenario 1. --ports="80,443" values are stored in rl_ports_map BPF map
	key => 80 value => 1
	key => 443 value => 1
HashMap scenario 2. --ports="443" value is stored in rl_ports_map BPF map
	key => 443 value => 1
Array scenario 1. --ports="80,443" values are stored in rl_ports_map BPF map
	key => 0 value => 80
	key => 1 value => 443
Array scenario 2. --rate="10000" value is stored in rl_config_map BPF map
	key => 0 value => 10000

type MetricsBPFMap

type MetricsBPFMap struct {
	BPFMap

	Values *ring.Ring
	// contains filtered or unexported fields
}

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 {
	HostName string

	//	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

	HostConfig *config.Config
	// contains filtered or unexported fields
}

func NewNFConfigs

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

func (*NFConfigs) AddAndStartBPF

func (c *NFConfigs) AddAndStartBPF(bpfProg *models.BPFProgram, ifaceName string, direction string) 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: 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) 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) 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) InsertAndStartBPFProgram

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

InsertAndStartBPFProgram method for tc programs

func (*NFConfigs) KFDetails

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

KFDetails - Method provides dump of KFs for debug purpose

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) 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) 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

Jump to

Keyboard shortcuts

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