Skip to content

Commit 0a27d5a

Browse files
add destroy function
1 parent aa3bd82 commit 0a27d5a

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/core/bpf_program.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ BpfProgram::BpfProgram(std::string object_path, std::string program_name)
99
}
1010

1111
BpfProgram::~BpfProgram() {
12-
//TODO: detach here as well
12+
destroy();
1313
if (obj_) {
1414
bpf_object__close(obj_);
1515
}
@@ -64,6 +64,17 @@ bool BpfProgram::attach() {
6464
return true;
6565
}
6666

67+
bool BpfProgram::destroy() {
68+
bool success = true;
69+
for (auto [prog, link] : programs) {
70+
if (!prog) {
71+
throw BpfException("Program not loaded");
72+
}
73+
success = success & bpf_link__destroy(link);
74+
}
75+
return success;
76+
}
77+
6778
void BpfProgram::load_and_attach() {
6879
load();
6980
attach();

src/core/bpf_program.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ class BpfProgram {
2121

2222
bool load();
2323
bool attach();
24+
bool destroy();
2425
void load_and_attach();
2526

2627
[[nodiscard]] bool is_loaded() const { return obj_ != nullptr; }

0 commit comments

Comments
 (0)