-
Notifications
You must be signed in to change notification settings - Fork 95
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This function allows to get a file descriptor of a map by its ID.
- Loading branch information
Showing
7 changed files
with
122 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../common/Makefile |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
module github.com/aquasecurity/libbpfgo/selftest/map-update | ||
|
||
go 1.18 | ||
|
||
require github.com/aquasecurity/libbpfgo v0.4.7-libbpf-1.2.0-b2e29a1 | ||
|
||
replace github.com/aquasecurity/libbpfgo => ../../ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= | ||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= | ||
github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8= | ||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
//+build ignore | ||
|
||
#include <vmlinux.h> | ||
|
||
#include <bpf/bpf_helpers.h> | ||
|
||
struct { | ||
__uint(type, BPF_MAP_TYPE_HASH); | ||
__type(key, u32); | ||
__type(value, u32); | ||
__uint(max_entries, 1); | ||
} tester SEC(".maps"); | ||
|
||
char LICENSE[] SEC("license") = "Dual BSD/GPL"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
package main | ||
|
||
import "C" | ||
|
||
import ( | ||
"log" | ||
|
||
bpf "github.com/aquasecurity/libbpfgo" | ||
) | ||
|
||
func main() { | ||
bpfModule, err := bpf.NewModuleFromFile("main.bpf.o") | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
defer bpfModule.Close() | ||
|
||
bpfModule.BPFLoadObject() | ||
|
||
testerMap, err := bpfModule.GetMap("tester") | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
// Get info about the "tester" map | ||
infoTester, err := bpf.GetMapInfoByFD(testerMap.FileDescriptor()) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
// Get a new FD pointing to the "tester" map | ||
newFD, err := bpf.GetMapFDByID(infoTester.ID) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
// Get info about the "tester" map again, this time using the new FD | ||
infoNewFD, err := bpf.GetMapInfoByFD(newFD) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
if infoTester.Type != infoNewFD.Type { | ||
log.Fatal("Types do not match") | ||
} | ||
if infoTester.ID != infoNewFD.ID { | ||
log.Fatal("IDs do not match") | ||
} | ||
if infoTester.KeySize != infoNewFD.KeySize { | ||
log.Fatal("Key sizes do not match") | ||
} | ||
if infoTester.ValueSize != infoNewFD.ValueSize { | ||
log.Fatal("Value sizes do not match") | ||
} | ||
if infoTester.MaxEntries != infoNewFD.MaxEntries { | ||
log.Fatal("Max entries do not match") | ||
} | ||
if infoTester.MapFlags != infoNewFD.MapFlags { | ||
log.Fatal("Map flags do not match") | ||
} | ||
if infoTester.Name != infoNewFD.Name { | ||
log.Fatal("Names do not match") | ||
} | ||
if infoTester.IfIndex != infoNewFD.IfIndex { | ||
log.Fatal("Ifindexes do not match") | ||
} | ||
if infoTester.NetnsDev != infoNewFD.NetnsDev { | ||
log.Fatal("Netns do not match") | ||
} | ||
if infoTester.NetnsIno != infoNewFD.NetnsIno { | ||
log.Fatal("Netns inodes do not match") | ||
} | ||
if infoTester.BTFID != infoNewFD.BTFID { | ||
log.Fatal("BTF IDs do not match") | ||
} | ||
if infoTester.BTFKeyTypeID != infoNewFD.BTFKeyTypeID { | ||
log.Fatal("BTF key type IDs do not match") | ||
} | ||
if infoTester.BTFValueTypeID != infoNewFD.BTFValueTypeID { | ||
log.Fatal("BTF value type IDs do not match") | ||
} | ||
if infoTester.MapExtra != infoNewFD.MapExtra { | ||
log.Fatal("Map extras do not match") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../common/run.sh |