mirror of
https://github.com/varun-r-mallya/pylibbpf.git
synced 2026-03-23 13:41:31 +00:00
add destroy function
This commit is contained in:
@ -9,7 +9,7 @@ BpfProgram::BpfProgram(std::string object_path, std::string program_name)
|
|||||||
}
|
}
|
||||||
|
|
||||||
BpfProgram::~BpfProgram() {
|
BpfProgram::~BpfProgram() {
|
||||||
//TODO: detach here as well
|
destroy();
|
||||||
if (obj_) {
|
if (obj_) {
|
||||||
bpf_object__close(obj_);
|
bpf_object__close(obj_);
|
||||||
}
|
}
|
||||||
@ -64,6 +64,17 @@ bool BpfProgram::attach() {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool BpfProgram::destroy() {
|
||||||
|
bool success = true;
|
||||||
|
for (auto [prog, link] : programs) {
|
||||||
|
if (!prog) {
|
||||||
|
throw BpfException("Program not loaded");
|
||||||
|
}
|
||||||
|
success = success & bpf_link__destroy(link);
|
||||||
|
}
|
||||||
|
return success;
|
||||||
|
}
|
||||||
|
|
||||||
void BpfProgram::load_and_attach() {
|
void BpfProgram::load_and_attach() {
|
||||||
load();
|
load();
|
||||||
attach();
|
attach();
|
||||||
|
|||||||
@ -21,6 +21,7 @@ public:
|
|||||||
|
|
||||||
bool load();
|
bool load();
|
||||||
bool attach();
|
bool attach();
|
||||||
|
bool destroy();
|
||||||
void load_and_attach();
|
void load_and_attach();
|
||||||
|
|
||||||
[[nodiscard]] bool is_loaded() const { return obj_ != nullptr; }
|
[[nodiscard]] bool is_loaded() const { return obj_ != nullptr; }
|
||||||
|
|||||||
Reference in New Issue
Block a user