Skip to content

Commit

Permalink
set kernel_log_level in helper function
Browse files Browse the repository at this point in the history
  • Loading branch information
umanwizard committed Apr 2, 2024
1 parent bbe735e commit aa5983d
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
4 changes: 3 additions & 1 deletion libbpfgo.c
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,8 @@ void cgo_bpf_iter_attach_opts_free(struct bpf_iter_attach_opts *opts)

struct bpf_object_open_opts *cgo_bpf_object_open_opts_new(const char *btf_file_path,
const char *kconfig_path,
const char *bpf_obj_name)
const char *bpf_obj_name,
__u32 kernel_log_level)
{
struct bpf_object_open_opts *opts;
opts = calloc(1, sizeof(*opts));
Expand All @@ -178,6 +179,7 @@ struct bpf_object_open_opts *cgo_bpf_object_open_opts_new(const char *btf_file_p
opts->btf_custom_path = btf_file_path;
opts->kconfig = kconfig_path;
opts->object_name = bpf_obj_name;
opts->kernel_log_level = kernel_log_level;

return opts;
}
Expand Down
3 changes: 2 additions & 1 deletion libbpfgo.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ void cgo_bpf_iter_attach_opts_free(struct bpf_iter_attach_opts *opts);

struct bpf_object_open_opts *cgo_bpf_object_open_opts_new(const char *btf_file_path,
const char *kconfig_path,
const char *bpf_obj_name);
const char *bpf_obj_name,
__u32 kernel_log_level);
void cgo_bpf_object_open_opts_free(struct bpf_object_open_opts *opts);

struct bpf_map_create_opts *cgo_bpf_map_create_opts_new(__u32 btf_fd,
Expand Down
6 changes: 3 additions & 3 deletions module.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ type NewModuleArgs struct {
BPFObjPath string
BPFObjBuff []byte
SkipMemlockBump bool
KernelLogLevel C.uint
KernelLogLevel u32
}

func NewModuleFromFile(bpfObjPath string) (*Module, error) {
Expand Down Expand Up @@ -130,16 +130,16 @@ func NewModuleFromBufferArgs(args NewModuleArgs) (*Module, error) {
bpfBuffC := unsafe.Pointer(C.CBytes(args.BPFObjBuff))
defer C.free(bpfBuffC)
bpfBuffSizeC := C.size_t(len(args.BPFObjBuff))
kernelLogLevelC := C.uint(args.KernelLogLevel)

if len(args.KConfigFilePath) <= 2 {
kConfigPathC = nil
}

optsC, errno := C.cgo_bpf_object_open_opts_new(btfFilePathC, kConfigPathC, bpfObjNameC)
optsC, errno := C.cgo_bpf_object_open_opts_new(btfFilePathC, kConfigPathC, bpfObjNameC, kernelLogLevelC)
if optsC == nil {
return nil, fmt.Errorf("failed to create bpf_object_open_opts: %w", errno)
}
optsC.kernel_log_level = args.KernelLogLevel
defer C.cgo_bpf_object_open_opts_free(optsC)

objC, errno := C.bpf_object__open_mem(bpfBuffC, bpfBuffSizeC, optsC)
Expand Down

0 comments on commit aa5983d

Please sign in to comment.