-
Notifications
You must be signed in to change notification settings - Fork 101
feat: added BPFReplaceExistedObject #506
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
base: main
Are you sure you want to change the base?
feat: added BPFReplaceExistedObject #506
Conversation
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.
Pull Request Overview
This PR adds a new method BPFReplaceExistedObject to the Module struct that allows replacing an existing BPF object with one passed from external code (e.g., CGO). This enables modifying rodata section variables before program attachment, which is particularly useful for user-space schedulers that need to configure BPF programs through C skeleton APIs.
- Adds
BPFReplaceExistedObjectmethod to replace the internal BPF object pointer - Enables modification of rodata section variables before program attachment
- Supports integration with CGO-based BPF skeleton workflows
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
module.go
Outdated
| return nil | ||
| } | ||
|
|
||
| func (m *Module) BPFReplaceExistedObject(obj unsafe.Pointer) error { |
Copilot
AI
Sep 1, 2025
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.
The method name contains a spelling error. 'ExistedObject' should be 'ExistingObject'. The correct name should be BPFReplaceExistingObject.
| func (m *Module) BPFReplaceExistedObject(obj unsafe.Pointer) error { | |
| func (m *Module) BPFReplaceExistingObject(obj unsafe.Pointer) error { |
module.go
Outdated
| return nil | ||
| } | ||
|
|
||
| func (m *Module) BPFReplaceExistedObject(obj unsafe.Pointer) error { |
Copilot
AI
Sep 1, 2025
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.
The method lacks input validation. It should check if the obj parameter is nil before casting and assignment to prevent potential runtime panics.
| func (m *Module) BPFReplaceExistedObject(obj unsafe.Pointer) error { | |
| func (m *Module) BPFReplaceExistedObject(obj unsafe.Pointer) error { | |
| if obj == nil { | |
| return errors.New("obj parameter is nil") | |
| } |
|
Hi @geyslan The Gthulhu is now able to be used in 5G Data Plane optimization! For more details, please visit https://free5gc.org/blog/20250726/index.en. Thanks a lot! |
|
Hi @ianchen0119 thanks again for contributing to libbpfgo.
Wouldn't Do you have plans of bringing such functionality into the libbpfgo? |
Sorry for the late reply. Thank you! |
|
Hi @geyslan Thank you! |
|
@ianchen0119 no worries. I'll revisit this soon but I think, for now, that perhaps we could provide a NewModuleFromSkel() which could straightforwardly instantiate the module taking care of setting *C.struct_bpf_object. Please be my guest for testing it. |
All of the variables located in the rodata/bss section will be mapped into an eBPF map during the eBPF program's runtime.
And there are some known limitations:
It was a significant challenge when I attempted to implement the user-space scheduler in Go.
My solution is to use the cgo to call eBPF skeleton APIs, so I need an additional wrapper to replace the existing eBPF object before the program attaches.
=== example ===
Therefore, I can call
SetBuiltinIdle()beforeAttach()to modify the target variablebuiltin_idlein the rodata section.