-
Notifications
You must be signed in to change notification settings - Fork 93
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add InitGlobalVariable
to support setting global variables in bpf code
#258
Add InitGlobalVariable
to support setting global variables in bpf code
#258
Conversation
InitGlobalVariable
to support setting global variables in bpf code
I think this approach isn't quite correct. When I've used global variables like this in pure C libbpf, the variables are stored as key/value pairs in a map just called |
@grantseltzer We can't init multiple global variables like the pure C way with |
Is it possible to get a handle on the '.rodata' map and iterate over the
keys or just set the values directly with this set initial value API
function?
…On Tue, Oct 11, 2022 at 9:15 PM Huang Huang ***@***.***> wrote:
I think this approach isn't quite correct. When I've used global variables
like this in pure C libbpf, the variables are stored as key/value pairs in
a map just called .rodata. The way you show your approach working in the
selftest creates a new map for each variable with one entry in each map.
@grantseltzer <https://github.com/grantseltzer> We can't init multiple
global variables like the pure C way with skel->rodata->foobar due to
can't update the internet map with a global variable name, so I use
multiple internal maps to workaround. Do you know any better way to support
multiple global variables?
—
Reply to this email directly, view it on GitHub
<#258 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ACS2XBICYWFZ52REBC2WGDDWCYGLRANCNFSM6AAAAAAQ6LZCB4>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
@mozillazg I've opened mozillazg#2 with a POC of what I have in mind. It works with the selftest as is, but it fails if you change one of the data types to not match the others (bpf_map__set_initial_value returns errno 22 (invalid arg)) Any thoughts? |
We can't iterate the map before load bpf object. The '.rodata' map only has one element and the value don't have a well-known struct
It looks like we can't use normal way to update the map value. Is it possible to update the memory of value?
|
The error in my approach appears to be an issue with struct memory alignment. If the types add up to a perfect alignment of 8 bytes it works, otherwise it gives the "invalid argument" error. |
A POC of this way: mozillazg#3 |
@grantseltzer Which solution would you prefer? |
@mozillazg Your solution in mozillazg#3 works great! Nicely done, really enjoyed collaborating with you on this! Only thing is I kindly ask you remove the print statements and get the selftest working (remove time.Sleep). Also my suggestion for the GoDoc comment about InitGlobalVariable to something like:
|
@grantseltzer updated codes to use solution like mozillazg#3 . please review it again. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great, well done and thank you very much @mozillazg!
We needed aquasecurity/libbpfgo#258 and it's there now.
closes #27