-
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.
Introduce SetKeySize, Autocreate and SetAutocreate
Co-authored-by: sc07kvm <[email protected]>
- Loading branch information
Showing
13 changed files
with
173 additions
and
3 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,11 @@ | ||
//+build ignore | ||
|
||
#include <vmlinux.h> | ||
|
||
#include <bpf/bpf_helpers.h> | ||
|
||
struct { | ||
__uint(type, ~0U); | ||
} 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,58 @@ | ||
package main | ||
|
||
import "C" | ||
|
||
import ( | ||
"log" | ||
|
||
bpf "github.com/aquasecurity/libbpfgo" | ||
) | ||
|
||
func main() { | ||
bpfModuleWithAutocreate, err := bpf.NewModuleFromFile("main.bpf.o") | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
defer bpfModuleWithAutocreate.Close() | ||
|
||
testerMapWithAutocreate, err := bpfModuleWithAutocreate.GetMap("tester") | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
isAutocreate := testerMapWithAutocreate.Autocreate() | ||
if !isAutocreate { | ||
log.Fatal("Autocreate is false") | ||
} | ||
|
||
err = bpfModuleWithAutocreate.BPFLoadObject() | ||
if err == nil { | ||
log.Fatal("Was able to load with a bad type of map") | ||
} | ||
|
||
bpfModuleWithoutAutocreate, err := bpf.NewModuleFromFile("main.bpf.o") | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
defer bpfModuleWithoutAutocreate.Close() | ||
|
||
testerMapWithoutAutocreate, err := bpfModuleWithoutAutocreate.GetMap("tester") | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
err = testerMapWithoutAutocreate.SetAutocreate(false) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
isAutocreate = testerMapWithoutAutocreate.Autocreate() | ||
if isAutocreate { | ||
log.Fatal("Autocreate is true") | ||
} | ||
|
||
err = bpfModuleWithoutAutocreate.BPFLoadObject() | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
} |
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 |
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,39 @@ | ||
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() | ||
|
||
testerMap, err := bpfModule.GetMap("tester") | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
keySize := testerMap.KeySize() | ||
if keySize != 4 { | ||
log.Fatal("keySize do not match") | ||
} | ||
|
||
err = testerMap.SetKeySize(8) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
keySize = testerMap.KeySize() | ||
if keySize != 8 { | ||
log.Fatal("keySize do not match") | ||
} | ||
|
||
bpfModule.BPFLoadObject() | ||
} |
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 |