Commit 6ce918bd authored by Sebastiano Miano's avatar Sebastiano Miano Committed by yonghong-song

Add C++ api support for devmap (#1979)

Adds the support for the DEVMAP in the C++ APIs, which was missing in #1810
parent fc245dfe
......@@ -634,6 +634,13 @@ BPFCgroupArray BPF::get_cgroup_array(const std::string& name) {
return BPFCgroupArray({});
}
BPFDevmapTable BPF::get_devmap_table(const std::string& name) {
TableStorage::iterator it;
if (bpf_module_->table_storage().Find(Path({bpf_module_->id(), name}), it))
return BPFDevmapTable(it->second);
return BPFDevmapTable({});
}
BPFStackTable BPF::get_stack_table(const std::string& name, bool use_debug_file,
bool check_debug_file_crc) {
TableStorage::iterator it;
......
......@@ -140,6 +140,8 @@ class BPF {
BPFCgroupArray get_cgroup_array(const std::string& name);
BPFDevmapTable get_devmap_table(const std::string& name);
BPFStackTable get_stack_table(const std::string& name,
bool use_debug_file = true,
bool check_debug_file_crc = true);
......
......@@ -495,4 +495,31 @@ StatusTuple BPFCgroupArray::remove_value(const int& index) {
return StatusTuple(0);
}
BPFDevmapTable::BPFDevmapTable(const TableDesc& desc)
: BPFTableBase<int, int>(desc) {
if(desc.type != BPF_MAP_TYPE_DEVMAP)
throw std::invalid_argument("Table '" + desc.name +
"' is not a devmap table");
}
StatusTuple BPFDevmapTable::update_value(const int& index,
const int& value) {
if (!this->update(const_cast<int*>(&index), const_cast<int*>(&value)))
return StatusTuple(-1, "Error updating value: %s", std::strerror(errno));
return StatusTuple(0);
}
StatusTuple BPFDevmapTable::get_value(const int& index,
int& value) {
if (!this->lookup(const_cast<int*>(&index), &value))
return StatusTuple(-1, "Error getting value: %s", std::strerror(errno));
return StatusTuple(0);
}
StatusTuple BPFDevmapTable::remove_value(const int& index) {
if (!this->remove(const_cast<int*>(&index)))
return StatusTuple(-1, "Error removing value: %s", std::strerror(errno));
return StatusTuple(0);
}
} // namespace ebpf
......@@ -367,4 +367,14 @@ class BPFCgroupArray : public BPFTableBase<int, int> {
StatusTuple remove_value(const int& index);
};
class BPFDevmapTable : public BPFTableBase<int, int> {
public:
BPFDevmapTable(const TableDesc& desc);
StatusTuple update_value(const int& index, const int& value);
StatusTuple get_value(const int& index, int& value);
StatusTuple remove_value(const int& index);
};
} // namespace ebpf
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment