Skip to content
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 CloneProgramWithSpecEditor allowing to edit the program spec during program copy #189

Merged
merged 2 commits into from
Jul 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -1176,6 +1176,12 @@ func (m *Manager) DetachHook(id ProbeIdentificationPair) error {
// using a MapEditor. The original program is selected using the provided UID and the section provided in the new probe.
// Note that the BTF based constant edition will not work with this method.
func (m *Manager) CloneProgram(UID string, newProbe *Probe, constantsEditors []ConstantEditor, mapEditors map[string]*ebpf.Map) error {
return m.CloneProgramWithSpecEditor(UID, newProbe, constantsEditors, mapEditors, nil)
}

// CloneProgramWithSpecEditor - does the same thing as CloneProgram, but allows to intercept the new program spec before the probe
// is initialized. This is useful for example to clone an fentry probe, and edit the AttachTo field before the init of the new probe.
func (m *Manager) CloneProgramWithSpecEditor(UID string, newProbe *Probe, constantsEditors []ConstantEditor, mapEditors map[string]*ebpf.Map, specEditor func(spec *ebpf.ProgramSpec)) error {
m.stateLock.Lock()
defer m.stateLock.Unlock()
if m.collection == nil || m.state < initialized {
Expand Down Expand Up @@ -1220,6 +1226,9 @@ func (m *Manager) CloneProgram(UID string, newProbe *Probe, constantsEditors []C

// Clone the program
clonedSpec := oldProgramSpec.Copy()
if specEditor != nil {
specEditor(clonedSpec)
}
newProbe.programSpec = clonedSpec

// newEditor constants
Expand Down
Loading