Skip to content

Commit 4ead5d0

Browse files
NoNickeDti-mo
andcommitted
map: parse map_extra field and expose in MapSpec
Bloom filter maps were introduced in Linux 5.16 and use the map_extra field to specify the number of hash functions (lower 4 bits, 1-15 range). Parse this field from the ELF and pass it through to the kernel. Fixes #669 Signed-off-by: nikos.nikolakakis <[email protected]> Co-authored-by: Timo Beckers <[email protected]>
1 parent ae3ab27 commit 4ead5d0

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

elf_reader.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -877,6 +877,7 @@ func mapSpecFromBTF(es *elfSection, vs *btf.VarSecinfo, def *btf.Struct, spec *b
877877
mapType MapType
878878
flags, maxEntries uint32
879879
pinType PinType
880+
mapExtra uint64
880881
innerMapSpec *MapSpec
881882
contents []MapKV
882883
err error
@@ -1035,7 +1036,10 @@ func mapSpecFromBTF(es *elfSection, vs *btf.VarSecinfo, def *btf.Struct, spec *b
10351036
}
10361037

10371038
case "map_extra":
1038-
return nil, fmt.Errorf("BTF map definition: field %s: %w", member.Name, ErrNotSupported)
1039+
mapExtra, err = uintFromBTF(member.Type)
1040+
if err != nil {
1041+
return nil, fmt.Errorf("resolving map_extra: %w", err)
1042+
}
10391043

10401044
default:
10411045
return nil, fmt.Errorf("unrecognized field %s in BTF map definition", member.Name)
@@ -1067,6 +1071,7 @@ func mapSpecFromBTF(es *elfSection, vs *btf.VarSecinfo, def *btf.Struct, spec *b
10671071
InnerMap: innerMapSpec,
10681072
Contents: contents,
10691073
Tags: slices.Clone(v.Tags),
1074+
MapExtra: mapExtra,
10701075
}, nil
10711076
}
10721077

map.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,11 @@ type MapSpec struct {
7878
// InnerMap is used as a template for ArrayOfMaps and HashOfMaps
7979
InnerMap *MapSpec
8080

81+
// MapExtra is an opaque field whose meaning is map-specific.
82+
//
83+
// Available from 5.16.
84+
MapExtra uint64
85+
8186
// Extra trailing bytes found in the ELF map definition when using structs
8287
// larger than libbpf's bpf_map_def. nil if no trailing bytes were present.
8388
// Must be nil or empty before instantiating the MapSpec into a Map.
@@ -534,6 +539,7 @@ func (spec *MapSpec) createMap(inner *sys.FD) (_ *Map, err error) {
534539
MaxEntries: spec.MaxEntries,
535540
MapFlags: spec.Flags,
536541
NumaNode: spec.NumaNode,
542+
MapExtra: spec.MapExtra,
537543
}
538544

539545
if inner != nil {

map_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ func TestMapSpecCopy(t *testing.T) {
9393
1,
9494
[]MapKV{{1, 2}}, // Can't copy Contents, use value types
9595
nil, // InnerMap
96+
0, // MapExtra
9697
bytes.NewReader(nil),
9798
&btf.Int{},
9899
&btf.Int{},

0 commit comments

Comments
 (0)