Skip to content

Commit

Permalink
cc: add support for prog table
Browse files Browse the repository at this point in the history
Signed-off-by: Mauricio Vasquez B <[email protected]>
  • Loading branch information
mauriciovasquezbernal committed Apr 4, 2017
1 parent 0f3787f commit b8af171
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/cc/BPF.cc
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,13 @@ std::string BPF::get_kprobe_event(const std::string& kernel_func,
return res;
}

BPFProgTable BPF::get_prog_table(const std::string& name) {
TableStorage::iterator it;
if (bpf_module_->table_storage().Find(Path({bpf_module_->id(), name}), it))
return BPFProgTable(it->second);
return BPFProgTable({});
}

std::string BPF::get_uprobe_event(const std::string& binary_path,
uint64_t offset, bpf_probe_attach_type type) {
std::string res = attach_type_prefix(type) + "_";
Expand Down
2 changes: 2 additions & 0 deletions src/cc/BPF.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ class BPF {
return BPFHashTable<KeyType, ValueType>({});
}

BPFProgTable get_prog_table(const std::string& name);

BPFStackTable get_stack_table(const std::string& name) {
TableStorage::iterator it;
if (bpf_module_->table_storage().Find(Path({bpf_module_->id(), name}), it))
Expand Down
16 changes: 16 additions & 0 deletions src/cc/BPFTable.h
Original file line number Diff line number Diff line change
Expand Up @@ -202,4 +202,20 @@ class BPFPerfBuffer : protected BPFTableBase<int, int> {
std::unique_ptr<epoll_event[]> ep_events_;
};

class BPFProgTable : protected BPFTableBase<int, int> {
public:
BPFProgTable(const TableDesc& desc)
: BPFTableBase<int, int>(desc) {
if (desc.type != BPF_MAP_TYPE_PROG_ARRAY)
throw std::invalid_argument("Table '" + desc.name + "' is not a prog table");
}

// updates an element
StatusTuple 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);
}
};

} // namespace ebpf

0 comments on commit b8af171

Please sign in to comment.