Skip to content

Commit 31d22a7

Browse files
committed
syscalls: simplify nested map feature test
We can detect support for nested maps using a single instead of three syscalls.
1 parent a444517 commit 31d22a7

File tree

1 file changed

+8
-18
lines changed

1 file changed

+8
-18
lines changed

syscalls.go

+8-18
Original file line numberDiff line numberDiff line change
@@ -204,31 +204,21 @@ func bpfMapCreate(attr *bpfMapCreateAttr) (*internal.FD, error) {
204204
}
205205

206206
var haveNestedMaps = internal.FeatureTest("nested maps", "4.12", func() error {
207-
inner, err := bpfMapCreate(&bpfMapCreateAttr{
208-
mapType: Array,
209-
keySize: 4,
210-
valueSize: 4,
211-
maxEntries: 1,
212-
})
213-
if err != nil {
214-
return err
215-
}
216-
defer inner.Close()
217-
218-
innerFd, _ := inner.Value()
219-
nested, err := bpfMapCreate(&bpfMapCreateAttr{
207+
_, err := bpfMapCreate(&bpfMapCreateAttr{
220208
mapType: ArrayOfMaps,
221209
keySize: 4,
222210
valueSize: 4,
223211
maxEntries: 1,
224-
innerMapFd: innerFd,
212+
// Invalid file descriptor.
213+
innerMapFd: ^uint32(0),
225214
})
226-
if err != nil {
215+
if errors.Is(err, unix.EINVAL) {
227216
return internal.ErrNotSupported
228217
}
229-
230-
_ = nested.Close()
231-
return nil
218+
if errors.Is(err, unix.EBADF) {
219+
return nil
220+
}
221+
return err
232222
})
233223

234224
var haveMapMutabilityModifiers = internal.FeatureTest("read- and write-only maps", "5.2", func() error {

0 commit comments

Comments
 (0)