diff --git a/pkg/elfparser/elf.go b/pkg/elfparser/elf.go index 1fd700d..a4dd756 100644 --- a/pkg/elfparser/elf.go +++ b/pkg/elfparser/elf.go @@ -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 + 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") diff --git a/pkg/progs/loader.go b/pkg/progs/loader.go index dc6b141..2227a2c 100644 --- a/pkg/progs/loader.go +++ b/pkg/progs/loader.go @@ -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) } @@ -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": @@ -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 } diff --git a/pkg/progs/mocks/ebpf_mocks.go b/pkg/progs/mocks/ebpf_mocks.go index e2ec9a6..93775d6 100644 --- a/pkg/progs/mocks/ebpf_mocks.go +++ b/pkg/progs/mocks/ebpf_mocks.go @@ -80,6 +80,21 @@ func (mr *MockBpfProgAPIsMockRecorder) LoadProg(arg0 interface{}) *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "LoadProg", reflect.TypeOf((*MockBpfProgAPIs)(nil).LoadProg), arg0) } +// LoadProgWithNonePinType mocks base method. +func (m *MockBpfProgAPIs) LoadProgWithNonePinType(arg0 progs.CreateEBPFProgInput, arg1 uint32) (int, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "LoadProgWithNonePinType", arg0, arg1) + ret0, _ := ret[0].(int) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// LoadProgWithNonePinType indicates an expected call of LoadProgWithNonePinType. +func (mr *MockBpfProgAPIsMockRecorder) LoadProgWithNonePinType(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "LoadProgWithNonePinType", reflect.TypeOf((*MockBpfProgAPIs)(nil).LoadProgWithNonePinType), arg0, arg1) +} + // PinProg mocks base method. func (m *MockBpfProgAPIs) PinProg(arg0 uint32, arg1 string) error { m.ctrl.T.Helper()