summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2024-02-13 19:11:52 +0200
committerPaul Buetow <paul@buetow.org>2024-02-13 19:11:52 +0200
commit6c1335b3538dabc82b4931d4bf13a36f86c4666e (patch)
tree3f8971f8b3d81ba09637ee39c9f5e238072edb51
parentef80f577771e95c0843658d65ced3dd069634471 (diff)
can pass flags to BPF
-rw-r--r--Makefile2
-rw-r--r--cmd/ioriotng/main.go5
-rw-r--r--internal/ioriotng.go22
-rw-r--r--ioriotng.bpf.c4
-rw-r--r--maps.bpf.h6
5 files changed, 11 insertions, 28 deletions
diff --git a/Makefile b/Makefile
index c2c7bad..c47a371 100644
--- a/Makefile
+++ b/Makefile
@@ -29,4 +29,4 @@ clean:
.PHONY: run
run:
- sudo ./ioriotng
+ sudo ./ioriotng -uid $$(id -u)
diff --git a/cmd/ioriotng/main.go b/cmd/ioriotng/main.go
index 16771a0..5173cbb 100644
--- a/cmd/ioriotng/main.go
+++ b/cmd/ioriotng/main.go
@@ -2,10 +2,9 @@ package main
import (
"ioriotng/internal"
+ "ioriotng/internal/flags"
)
func main() {
- // Here could be some flag parsing....
-
- internal.Run()
+ internal.Run(flags.New())
}
diff --git a/internal/ioriotng.go b/internal/ioriotng.go
index b34a5cf..94c8030 100644
--- a/internal/ioriotng.go
+++ b/internal/ioriotng.go
@@ -10,9 +10,9 @@ import (
"log"
"runtime"
"sync"
- "unsafe"
"ioriotng/internal/debugfs"
+ "ioriotng/internal/flags"
"ioriotng/internal/tracepoints"
bpf "github.com/aquasecurity/libbpfgo"
@@ -70,23 +70,7 @@ func resizeMap(module *bpf.Module, name string, size uint32) error {
return nil
}
-func config(bpfModule *bpf.Module) error {
- configMap, err := bpfModule.GetMap("config_map")
- if err != nil {
- return err
- }
-
- config := struct {
- UidFilter int32
- }{
- UidFilter: 1001, // TODO: Make configurable via flag,
- }
-
- key := uint32(1)
- return configMap.Update(unsafe.Pointer(&key), unsafe.Pointer(&config))
-}
-
-func Run() {
+func Run(flags flags.Flags) {
// To consider for implementation!
log.Println(debugfs.TracepointsWithFd())
@@ -108,7 +92,7 @@ func Run() {
log.Fatal(err)
}
- if err := config(bpfModule); err != nil {
+ if err := flags.SetBPF(bpfModule); err != nil {
log.Fatal(err)
}
diff --git a/ioriotng.bpf.c b/ioriotng.bpf.c
index c064364..3eb2e93 100644
--- a/ioriotng.bpf.c
+++ b/ioriotng.bpf.c
@@ -7,8 +7,8 @@
static inline int filter() {
u32 key = 1;
- struct config *c = bpf_map_lookup_elem(&config_map, &key);
- return c == NULL || (bpf_get_current_uid_gid() & 0xFFFFFFFF) != c->uid_filter;
+ struct flags *flagsp = bpf_map_lookup_elem(&flags_map, &key);
+ return flagsp == NULL || (bpf_get_current_uid_gid() & 0xFFFFFFFF) != flagsp->uid_filter;
}
SEC("tracepoint/syscalls/sys_enter_open")
diff --git a/maps.bpf.h b/maps.bpf.h
index 9e3d65f..d725a1c 100644
--- a/maps.bpf.h
+++ b/maps.bpf.h
@@ -4,16 +4,16 @@
#define MAX_FILENAME_LENGTH 256
#define MAX_PROGNAME_LENGTH 16
-struct config {
+struct flags {
__u32 uid_filter;
};
struct {
__uint(type, BPF_MAP_TYPE_HASH);
__type(key, u32);
- __type(value, struct config);
+ __type(value, struct flags);
__uint(max_entries, 1 << 24);
-} config_map SEC(".maps");
+} flags_map SEC(".maps");
struct open_event {
__s32 fd;