in pkg/elfparser/elf.go [404:460]
func (e *elfLoader) parseMap(customData BpfCustomData) ([]ebpf_maps.CreateEBPFMapInput, error) {
mapDefinitionSize := bpfMapDefSize
parsedMapData := []ebpf_maps.CreateEBPFMapInput{}
if e.mapSection == nil {
log.Infof("Bpf file has no map section so skipping parse")
return nil, nil
}
data, err := e.mapSection.Data()
if err != nil {
log.Infof("Error while loading section")
return nil, fmt.Errorf("error while loading section : %w", err)
}
if len(data) == 0 {
log.Infof("Missing data in mapsection")
return nil, fmt.Errorf("missing data in map section")
}
symbols, err := e.elfFile.Symbols()
if err != nil {
log.Infof("Get symbol failed")
return nil, fmt.Errorf("get symbols: %w", err)
}
for offset := 0; offset < len(data); offset += mapDefinitionSize {
mapData := ebpf_maps.CreateEBPFMapInput{
Type: uint32(binary.LittleEndian.Uint32(data[offset : offset+4])),
KeySize: uint32(binary.LittleEndian.Uint32(data[offset+4 : offset+8])),
ValueSize: uint32(binary.LittleEndian.Uint32(data[offset+8 : offset+12])),
MaxEntries: uint32(binary.LittleEndian.Uint32(data[offset+12 : offset+16])),
Flags: uint32(binary.LittleEndian.Uint32(data[offset+16 : offset+20])),
}
pinOptions := ebpf_maps.BpfMapPinOptions{
Type: uint32(binary.LittleEndian.Uint32(data[offset+20 : offset+24])),
}
mapData.PinOptions = &pinOptions
for _, sym := range symbols {
if int(sym.Section) == e.mapSectionIndex && int(sym.Value) == offset {
mapName := path.Base(sym.Name)
mapData.Name = mapName
}
}
log.Infof("Found map name %s", mapData.Name)
if len(customData.CustomMapSize) != 0 {
//Update the MaxEntries
if customSize, ok := customData.CustomMapSize[mapData.Name]; ok {
mapData.MaxEntries = uint32(customSize)
}
}
parsedMapData = append(parsedMapData, mapData)
}
return parsedMapData, nil
}