From af36d23f4537b446477e5b6e387464c776d6db24 Mon Sep 17 00:00:00 2001 From: aymericdd Date: Fri, 20 Oct 2023 18:28:43 +0200 Subject: [PATCH] fix: defined the startId as a pointer The startId was not a pointer, so its value was never updated for the caller of the GetMapsIDsByName function. --- map-low.go | 6 +++--- selftest/map-getmapsbyname/main.go | 9 ++++++--- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/map-low.go b/map-low.go index b43fcd5c..523a8568 100644 --- a/map-low.go +++ b/map-low.go @@ -137,14 +137,14 @@ func GetMapNextID(startId uint32) (uint32, error) { // // Update 'startId' to the last processed map ID to continue the search. // } // } -func GetMapsIDsByName(name string, startId uint32) ([]uint32, error) { +func GetMapsIDsByName(name string, startId *uint32) ([]uint32, error) { var ( bpfMapsIds []uint32 err error ) for { - startId, err = GetMapNextID(startId) + *startId, err = GetMapNextID(*startId) if err != nil { if errors.Is(err, syscall.ENOENT) { return bpfMapsIds, nil @@ -153,7 +153,7 @@ func GetMapsIDsByName(name string, startId uint32) ([]uint32, error) { return bpfMapsIds, err } - bpfMapLow, err := GetMapByID(startId) + bpfMapLow, err := GetMapByID(*startId) if err != nil { return bpfMapsIds, err } diff --git a/selftest/map-getmapsbyname/main.go b/selftest/map-getmapsbyname/main.go index 6416ccc9..ab945546 100644 --- a/selftest/map-getmapsbyname/main.go +++ b/selftest/map-getmapsbyname/main.go @@ -30,12 +30,14 @@ func main() { bpfModule.BPFLoadObject() - notFoundMapsIDs, err := bpf.GetMapsIDsByName(BPFMapNameToNotFind, 0) + startId := 0 + notFoundMapsIDs, err := bpf.GetMapsIDsByName(BPFMapNameToNotFind, &startId) if len(notFoundMapsIDs) != 0 { log.Fatalf("the %s map should not be found, but it was found with ids: %v", BPFMapNameToNotFind, notFoundMapsIDs) } - bpfHashMapsIDs, err := bpf.GetMapsIDsByName(BPFHashMapNameToFind, 0) + startId = 0 + bpfHashMapsIDs, err := bpf.GetMapsIDsByName(BPFHashMapNameToFind, &startId) if err != nil { log.Fatal(err) } @@ -43,7 +45,8 @@ func main() { log.Fatalf("the %s map should be found", BPFHashMapNameToFind) } - mapsIDs, err := bpf.GetMapsIDsByName(BPFMapNameToFind, 0) + startId = 0 + mapsIDs, err := bpf.GetMapsIDsByName(BPFMapNameToFind, &startId) if err != nil { log.Fatal(err) }