diff options
author | Sebastiano Miano <mianosebastiano@gmail.com> | 2018-09-20 06:48:52 +0200 |
---|---|---|
committer | yonghong-song <ys114321@gmail.com> | 2018-09-19 21:48:52 -0700 |
commit | 6ce918bd7030241f0598ee6b1107940bf8480085 (patch) | |
tree | c40216a54389b17bd5543c0879f516394026f004 | |
parent | fc245dfe9dabbd77e3adbf89a45aaab0cb1552fd (diff) | |
download | bcc-6ce918bd7030241f0598ee6b1107940bf8480085.zip bcc-6ce918bd7030241f0598ee6b1107940bf8480085.tar.gz bcc-6ce918bd7030241f0598ee6b1107940bf8480085.tar.bz2 |
Add C++ api support for devmap (#1979)
Adds the support for the DEVMAP in the C++ APIs, which was missing in #1810
-rw-r--r-- | src/cc/api/BPF.cc | 7 | ||||
-rw-r--r-- | src/cc/api/BPF.h | 2 | ||||
-rw-r--r-- | src/cc/api/BPFTable.cc | 27 | ||||
-rw-r--r-- | src/cc/api/BPFTable.h | 10 |
4 files changed, 46 insertions, 0 deletions
diff --git a/src/cc/api/BPF.cc b/src/cc/api/BPF.cc index cc3bf75..5f451f7 100644 --- a/src/cc/api/BPF.cc +++ b/src/cc/api/BPF.cc @@ -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; diff --git a/src/cc/api/BPF.h b/src/cc/api/BPF.h index b073fc2..8dd5f84 100644 --- a/src/cc/api/BPF.h +++ b/src/cc/api/BPF.h @@ -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); diff --git a/src/cc/api/BPFTable.cc b/src/cc/api/BPFTable.cc index 718dabd..5a3d77e 100644 --- a/src/cc/api/BPFTable.cc +++ b/src/cc/api/BPFTable.cc @@ -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 diff --git a/src/cc/api/BPFTable.h b/src/cc/api/BPFTable.h index a8e9566..ad3651b 100644 --- a/src/cc/api/BPFTable.h +++ b/src/cc/api/BPFTable.h @@ -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 |