Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added LoadProgWithPinType method to support NONE pinType #98

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion pkg/elfparser/elf.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,10 +284,21 @@ func (e *elfLoader) parseRelocationSection(reloSection *elf.Section, elfFile *el
func (e *elfLoader) loadProg(loadedProgData map[string]ebpf_progs.CreateEBPFProgInput, loadedMaps map[string]ebpf_maps.BpfMap) (map[string]BpfData, error) {

loadedprog := make(map[string]BpfData)
var pinType uint32
for mapName, bpfMap := range loadedMaps {
pinType = bpfMap.MapMetaData.PinOptions.Type
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like you are using maps pin option to decide if the program needs pinning? I think we should discuss this..

log.Infof("Map: %s, Pin Type: %d", mapName, pinType)
}

for _, pgmInput := range loadedProgData {
bpfData := BpfData{}
progFD, errno := e.bpfProgApi.LoadProg(pgmInput)
var progFD int
var errno error
if pinType == constdef.PIN_NONE.Index() {
progFD, errno = e.bpfProgApi.LoadProgWithNonePinType(pgmInput, pinType)
} else {
progFD, errno = e.bpfProgApi.LoadProg(pgmInput)
}
if progFD == -1 {
log.Infof("Failed to load prog", "error", errno)
return nil, fmt.Errorf("failed to Load the prog")
Expand Down
18 changes: 14 additions & 4 deletions pkg/progs/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ type BpfProgAPIs interface {
PinProg(progFD uint32, pinPath string) error
UnPinProg(pinPath string) error
LoadProg(progMetaData CreateEBPFProgInput) (int, error)
LoadProgWithNonePinType(progMetaData CreateEBPFProgInput, pinType uint32) (int, error)
GetProgFromPinPath(pinPath string) (BpfProgInfo, int, error)
GetBPFProgAssociatedMapsIDs(progFD int) ([]uint32, error)
}
Expand Down Expand Up @@ -194,7 +195,14 @@ func parseLogs(log []byte) []string {
}

func (m *BpfProgram) LoadProg(progMetaData CreateEBPFProgInput) (int, error) {
fdInt, err := m.LoadProgWithNonePinType(progMetaData, uint32(0))
if err != nil {
return -1, err
}
return fdInt, nil
}

func (m *BpfProgram) LoadProgWithNonePinType(progMetaData CreateEBPFProgInput, pinType uint32) (int, error) {
var prog_type uint32
switch progMetaData.ProgType {
case "xdp":
Expand Down Expand Up @@ -244,10 +252,12 @@ func (m *BpfProgram) LoadProg(progMetaData CreateEBPFProgInput) (int, error) {
}

//Pin the prog
err := m.PinProg(uint32(fd), progMetaData.PinPath)
if err != nil {
log.Errorf("pin prog failed %v", err)
return -1, err
if pinType != constdef.PIN_NONE.Index() {
err := m.PinProg(uint32(fd), progMetaData.PinPath)
if err != nil {
log.Errorf("pin prog failed %v", err)
return -1, err
}
}
return int(fd), nil
}
Expand Down
15 changes: 15 additions & 0 deletions pkg/progs/mocks/ebpf_mocks.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading