Skip to content

Commit

Permalink
fix: defined the startId as a pointer
Browse files Browse the repository at this point in the history
The startId was not a pointer, so its value was never updated for the caller of the GetMapsIDsByName function.
  • Loading branch information
aymericDD committed Oct 20, 2023
1 parent 0f25247 commit af36d23
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
6 changes: 3 additions & 3 deletions map-low.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
Expand Down
9 changes: 6 additions & 3 deletions selftest/map-getmapsbyname/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,23 @@ 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)
}
if len(bpfHashMapsIDs) == 0 {
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)
}
Expand Down

0 comments on commit af36d23

Please sign in to comment.