Skip to content

Commit 0e5464f

Browse files
committed
[bcc] Support for new bcc_func_load signature.
iovisor/bcc@ffff0ed a new parameter was added to control the attach type. Subsequently, in iovisor/bcc@815d1b8 , `-1` was used to signal the default behaviour. This change adds this new parameter to the call to `C.bcc_func_load` when LIBBCC_VERSION_CODE is greater or equal than 0.25.0, the next version to include the aforementioned change. Test plan: Against v0.25.0 is being tested as part of this project CI. also ran against the current v0.20.0 and ran CI: https://github.com/chantra/gobpf/runs/7436803048
1 parent 5da0f6f commit 0e5464f

1 file changed

Lines changed: 24 additions & 1 deletion

File tree

bcc/module.go

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,29 @@ import (
3131
#cgo LDFLAGS: -lbcc
3232
#include <bcc/bcc_common.h>
3333
#include <bcc/libbpf.h>
34+
#include <bcc/bcc_version.h>
35+
36+
#ifndef LIBBCC_VERSION_GEQ
37+
#define LIBBCC_VERSION_GEQ(a, b, c) 0
38+
#endif
39+
40+
int bcc_func_load_wrapper(void *program, int prog_type, const char *name,
41+
const struct bpf_insn *insns, int prog_len,
42+
const char *license, unsigned kern_version,
43+
int log_level, char *log_buf, unsigned log_buf_size,
44+
const char *dev_name, int attach_type){
45+
46+
#if LIBBCC_VERSION_GEQ(0, 25, 0)
47+
return bcc_func_load(program, prog_type, name, insns, prog_len, license,
48+
kern_version, log_level, log_buf, log_buf_size,
49+
dev_name, attach_type);
50+
#else
51+
return bcc_func_load(program, prog_type, name, insns, prog_len, license,
52+
kern_version, log_level, log_buf, log_buf_size,
53+
dev_name);
54+
#endif
55+
}
56+
3457
*/
3558
import "C"
3659

@@ -227,7 +250,7 @@ func (bpf *Module) load(name string, progType int, logLevel, logSize uint) (int,
227250
logBuf = make([]byte, logSize)
228251
logBufP = (*C.char)(unsafe.Pointer(&logBuf[0]))
229252
}
230-
fd, err := C.bcc_func_load(bpf.p, C.int(uint32(progType)), nameCS, start, size, license, version, C.int(logLevel), logBufP, C.uint(len(logBuf)), nil)
253+
fd, err := C.bcc_func_load_wrapper(bpf.p, C.int(uint32(progType)), nameCS, start, size, license, version, C.int(logLevel), logBufP, C.uint(len(logBuf)), nil, C.int(-1))
231254
if fd < 0 {
232255
return -1, fmt.Errorf("error loading BPF program: %v", err)
233256
}

0 commit comments

Comments
 (0)