How do I rewrite global variables before loading a BPF object? #795
Answered
by
ti-mo
Ephemeraler
asked this question in
Q&A
|
Before that, I use libbpf and C to write bpf controller. In *.bpf.c, I declare a global variable (filter_pid). and I set value (skel->bss->filter_pid = 1234) in *.c. Now, what should I do in cilium/ebpf. when I executed go generate, I might not find this variable In bpf_**.go. 3Q. |
Answered by
ti-mo
Sep 20, 2022
Replies: 1 comment 19 replies
|
@Ephemeraler ebpf-go implements this using Given the following global variable in C: volatile const uint32_t arg;The following Go code takes care of rewriting that constant to hold the value err := spec.RewriteConstants(map[string]interface{}{
"arg": uint32(1),
}) |
19 replies
Answer selected by
ti-mo
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@Ephemeraler ebpf-go implements this using
CollectionSpec.RewriteConstants().Given the following global variable in C:
The following Go code takes care of rewriting that constant to hold the value
1at runtime: