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 ¶
- func BinarySearch(names []string, target string) bool
- func DisableLRO(ifaceName string) error
- func DownloadArtifact(urlpath string, timeout time.Duration, buf *bytes.Buffer) error
- func ExtractArtifact(artifactName string, buf *bytes.Buffer, tempDir string) error
- func GetPlatform() (string, error)
- func GetProgramSectionDetails(sectionName string) (string, string)
- func GetTestExecutableName() string
- func GetTestExecutablePath() string
- func GetTestExecutablePathName() string
- func GetTestNonexecutablePathName() string
- func IsProcessRunning(pid int, name string) (bool, error)
- func SerialzeProgram(e *list.Element) *models.L3AFMetaData
- func SetupBPFDebug(ebpfChainDebugAddr string, BPFConfigs *NFConfigs)
- func StopExternalRunningProcess(processName string) error
- func ValidatePath(filePath string, destination string) (string, error)
- func VerifyNCreateTCDirs() error
- func VerifyNMountBPFFS() error
- func VerifyNMountTraceFS() error
- func ViewHandler(w http.ResponseWriter, r *http.Request)
- type BPF
- func (b *BPF) AddBPFMap(mapName string) error
- func (b *BPF) AddMetricsBPFMap(mapName, aggregator string, key, samplesLength int) error
- func (b *BPF) AttachBPFProgram(ifaceName, direction string) error
- func (b *BPF) CreatePinDirectories(ifaceName string) error
- func (b *BPF) GetArtifacts(conf *config.Config) error
- func (b *BPF) GetBPFMap(mapName string) (*BPFMap, error)
- func (b *BPF) GetProgID() (ebpf.ProgramID, error)
- func (b *BPF) InitialiseMetricMaps() error
- func (b *BPF) IsLoaded() bool
- func (b *BPF) LoadBPFProgram(ifaceName string) error
- func (b *BPF) LoadBPFProgramChain(ifaceName, direction string) error
- func (b *BPF) LoadBPFProgramProbeType(prog *ebpf.Program, sectionName string) error
- func (b *BPF) LoadBPFProgramProbeTypes(objSpec *ebpf.CollectionSpec) error
- func (b *BPF) LoadTCAttachProgram(ifaceName, direction string) error
- func (b *BPF) LoadXDPAttachProgram(ifaceName string) error
- func (b *BPF) MonitorMaps(ifaceName string, intervals int) error
- func (b *BPF) PinBpfMaps(ifaceName string) error
- func (b *BPF) ProcessTerminate() error
- func (b *BPF) PutNextProgFDFromID(progID int) error
- func (b *BPF) RemoveNextProgFD() error
- func (b *BPF) RemovePinnedFiles(ifaceName string) error
- func (b *BPF) RemovePrevProgFD() error
- func (b *BPF) RemoveRootProgMapFile(ifacename string) error
- func (b *BPF) RunBPFConfigs() error
- func (b *BPF) SetPrLimits() error
- func (b *BPF) Start(ifaceName, direction string, chain bool) error
- func (b *BPF) StartUserProgram(ifaceName, direction string, chain bool) error
- func (b *BPF) Stop(ifaceName, direction string, chain bool) error
- func (b *BPF) StopUserProgram(ifaceName, direction string) error
- func (b *BPF) UnloadProgram(ifaceName, direction string) error
- func (b *BPF) UnloadTCProgram(ifaceName, direction string) error
- func (b *BPF) UpdateArgs(ifaceName, direction string) error
- func (b *BPF) UpdateBPFMaps(ifaceName, direction string) error
- func (b *BPF) UpdateProgramMap(ifaceName string) error
- func (b *BPF) VerifyAndGetArtifacts(conf *config.Config) error
- func (b *BPF) VerifyCleanupMaps(chain bool) error
- func (b *BPF) VerifyMetricsMapsVanish() error
- func (b *BPF) VerifyPinnedProgMap(chain, exists bool) error
- func (b *BPF) VerifyProcessObject() error
- type BPFMap
- type BpfMetrics
- type MetricsBPFMap
- type NFConfigs
- func (c *NFConfigs) AddAndStartBPF(bpfProg *models.BPFProgram, ifaceName string, direction string) error
- func (c *NFConfigs) AddProbePrograms(HostName string, bpfProgs []*models.BPFProgram) error
- func (c *NFConfigs) AddProgramWithoutChaining(ifaceName string, bpfProgs *models.BPFPrograms) error
- func (c *NFConfigs) AddProgramsOnInterface(ifaceName, HostName string, bpfProgs *models.BPFPrograms) error
- func (c *NFConfigs) AddeBPFPrograms(bpfProgs []models.L3afBPFPrograms) error
- func (c *NFConfigs) BPFDetails(iface string) []*BPF
- func (c *NFConfigs) CleanupProgramsOnInterface(ifaceName string)
- func (c *NFConfigs) Close(ctx context.Context) error
- func (c *NFConfigs) DeleteEbpfPrograms(bpfProgs []models.L3afBPFProgramNames) error
- func (c *NFConfigs) DeleteProgramsOnInterface(ifaceName, HostName string, bpfProgs *models.BPFProgramNames) error
- func (c *NFConfigs) DeleteProgramsOnInterfaceHelper(e *list.Element, ifaceName string, direction string, bpfList *list.List) error
- func (c *NFConfigs) Deploy(ifaceName, HostName string, bpfProgs *models.BPFPrograms) error
- func (c *NFConfigs) DeployeBPFPrograms(bpfProgs []models.L3afBPFPrograms) error
- func (c *NFConfigs) DownloadAndStartBPFProgram(element *list.Element, ifaceName, direction string) error
- func (c *NFConfigs) DownloadAndStartProbes(element *list.Element) error
- func (c *NFConfigs) EBPFPrograms(iface string) models.L3afBPFPrograms
- func (c *NFConfigs) EBPFProgramsAll() []models.L3afBPFPrograms
- func (c *NFConfigs) GetL3AFHOSTDATA() models.L3AFALLHOSTDATA
- func (c *NFConfigs) InsertAndStartBPFProgram(bpfProg *models.BPFProgram, ifaceName, direction string) error
- func (c *NFConfigs) LinkBPFPrograms(leftBPF, rightBPF *BPF) error
- func (c *NFConfigs) MoveToLocation(element *list.Element, bpfList *list.List) error
- func (c *NFConfigs) PushBackAndStartBPF(bpfProg *models.BPFProgram, ifaceName, direction string) error
- func (c *NFConfigs) PushBackAndStartProbe(bpfProg *models.BPFProgram) error
- func (c *NFConfigs) RemoveMissingBPFProgramsInConfig(bpfProg models.L3afBPFPrograms, ifaceName, direction string) error
- func (c *NFConfigs) RemoveMissingNetIfacesNBPFProgsInConfig(bpfProgCfgs []models.L3afBPFPrograms) error
- func (c *NFConfigs) SaveConfigsToConfigStore() error
- func (c *NFConfigs) StartAllUserProgramsAndProbes() error
- func (c *NFConfigs) StopAllProbesAndUserPrograms() error
- func (c *NFConfigs) StopNRemoveAllBPFProbePrograms() error
- func (c *NFConfigs) StopNRemoveAllBPFPrograms(ifaceName, direction string) error
- func (c *NFConfigs) StopRootProgram(ifaceName, direction string) error
- func (c *NFConfigs) VerifyAndStartTCRootProgram(ifaceName, direction string) error
- func (c *NFConfigs) VerifyAndStartXDPRootProgram(ifaceName, direction string) error
- func (c *NFConfigs) VerifyNUpdateBPFProgram(bpfProg *models.BPFProgram, ifaceName, direction string) error
- type PCheck
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BinarySearch ¶
BinarySearch: It is checking a target string exists in sorted slice of strings
func DisableLRO ¶
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 ¶
DownloadArtifact will download artifact from provided urlpath and store it in buffer
func ExtractArtifact ¶
ExtractArtifact will extract artifact to given tempDir
func GetPlatform ¶
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 ¶
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 SerialzeProgram ¶
func SerialzeProgram(e *list.Element) *models.L3AFMetaData
SerialzeProgram this function wil serialize the program
func SetupBPFDebug ¶
func StopExternalRunningProcess ¶
Stop the NF process if running outside l3afd
func ValidatePath ¶
ValidatePath will validate any illegal file path
func VerifyNCreateTCDirs ¶
func VerifyNCreateTCDirs() error
VerifyNCreateTCDirs - Creating BPF sudo FS for pinning TC maps
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 (*BPF) AddMetricsBPFMap ¶
Add eBPF map into BPFMaps list
func (*BPF) AttachBPFProgram ¶
AttachBPFProgram - method to attach bpf program to interface
func (*BPF) CreatePinDirectories ¶
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 ¶
GetArtifacts downloads artifacts from the specified eBPF repo
func (*BPF) InitialiseMetricMaps ¶
InitialiseMetricMaps - This method initialises all the monitor maps
func (*BPF) IsLoaded ¶
IsLoaded - Method verifies whether bpf program is loaded or not Here it checks whether prog ID is valid and active
func (*BPF) LoadBPFProgram ¶
LoadBPFProgram - This method loads the eBPF program natively.
func (*BPF) LoadBPFProgramChain ¶
LoadBPFProgramChain - Load the BPF program and chain it.
func (*BPF) LoadBPFProgramProbeType ¶
func (*BPF) LoadBPFProgramProbeTypes ¶
func (b *BPF) LoadBPFProgramProbeTypes(objSpec *ebpf.CollectionSpec) error
LoadBPFProgramProbeTypes - Load the BPF programs of probe types - TracePoint
func (*BPF) LoadTCAttachProgram ¶
LoadTCAttachProgram - Load and attach tc root program filters or any tc program when chaining is disabled
func (*BPF) LoadXDPAttachProgram ¶
LoadXDPAttachProgram - Load and attach xdp root program or any xdp program when chaining is disabled
func (*BPF) MonitorMaps ¶
This method to fetch values from bpf maps and publish to metrics
func (*BPF) PinBpfMaps ¶
PinBpfMaps - Pinning tc and xdp maps
func (*BPF) ProcessTerminate ¶
ProcessTerminate - Send sigterm to the process
func (*BPF) PutNextProgFDFromID ¶
Updating next program FD from program ID
func (*BPF) RemoveNextProgFD ¶
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 ¶
RemovePinnedFiles - removes all the pinned files
func (*BPF) RemovePrevProgFD ¶
RemovePrevProgFD Delete the entry if the last element
func (*BPF) RemoveRootProgMapFile ¶
RemoveRootProgMapFile - removes root pinned prog map file This is invoked if any stale map file persists for root map
func (*BPF) RunBPFConfigs ¶
func (*BPF) SetPrLimits ¶
Set process resource limits only non-zero value
func (*BPF) Start ¶
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 (*BPF) Stop ¶
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 (*BPF) UnloadProgram ¶
UnloadProgram - Unload or detach the program from the interface and close all the program resources
func (*BPF) UnloadTCProgram ¶
UnloadTCProgram - Remove TC filters
func (*BPF) UpdateArgs ¶
Update config arguments using user program
func (*BPF) UpdateBPFMaps ¶
UpdateBPFMaps - Update the config ebpf maps via map arguments
func (*BPF) UpdateProgramMap ¶
UpdateProgramMap - Store the program map reference
func (*BPF) VerifyAndGetArtifacts ¶
VerifyAndGetArtifacts -Check binary already exists
func (*BPF) VerifyCleanupMaps ¶
VerifyCleanupMaps - This method verifies map entries in the fs is removed
func (*BPF) VerifyMetricsMapsVanish ¶
VerifyMetricsMapsVanish - checks for all metrics maps references are removed from the kernel
func (*BPF) VerifyPinnedProgMap ¶
VerifyPinnedProgMap - making sure program fd map's pinned file is created if exists flag is true
func (*BPF) VerifyProcessObject ¶
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 ¶
The RemoveMissingKeys function is used to delete missing entries of eBPF maps, which are used by eBPF Programs.
type BpfMetrics ¶
func NewpBpfMetrics ¶
func NewpBpfMetrics(chain bool, interval int) *BpfMetrics
func (*BpfMetrics) BpfMetricsProbeWorker ¶
func (c *BpfMetrics) BpfMetricsProbeWorker(bpfProgs *list.List)
func (*BpfMetrics) BpfMetricsStart ¶
func (*BpfMetrics) BpfMetricsWorker ¶
func (c *BpfMetrics) BpfMetricsWorker(bpfProgs map[string]*list.List)
type MetricsBPFMap ¶
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 (*NFConfigs) AddAndStartBPF ¶
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 ¶
BPFDetails - Method provides dump of BPFs for debug purpose
func (*NFConfigs) CleanupProgramsOnInterface ¶
CleanupProgramsOnInterface removes all EBPF program and its metadata, on the network interface provided
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 (*NFConfigs) DownloadAndStartProbes ¶
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 ¶
Link BPF programs
func (*NFConfigs) MoveToLocation ¶
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 ¶
SaveConfigsToConfigStore - Writes configs to persistent store
func (*NFConfigs) StartAllUserProgramsAndProbes ¶
StartAllUserProgramsAndProbes this function will restart all the User Programs and probes
func (*NFConfigs) StopAllProbesAndUserPrograms ¶
StopAllProbesAndUserPrograms this function will stop all the probes & stops user programs
func (*NFConfigs) StopNRemoveAllBPFProbePrograms ¶
StopNRemoveAllBPFProbePrograms Stopping all probe programs in order
func (*NFConfigs) StopNRemoveAllBPFPrograms ¶
Stopping all programs in order
func (*NFConfigs) StopRootProgram ¶
StopRootProgram -This method stops the root program, removes the root node from the list and reset the list to nil
func (*NFConfigs) VerifyAndStartTCRootProgram ¶
Check for TC root program is running for a interface. If not start it
func (*NFConfigs) VerifyAndStartXDPRootProgram ¶
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