aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGary Lin <glin@suse.com>2018-06-07 16:08:46 +0800
committerGary Lin <glin@suse.com>2018-06-11 12:08:41 +0800
commitdb410bf3484df3febbc51fe64463677f8a93529a (patch)
tree0735d4fb4d450a8e73d9b37e1a09ad607fc32f82 /src
parent3ae15d60bd655a2570aecf374db6dd11a6c690cd (diff)
downloadbcc-db410bf3484df3febbc51fe64463677f8a93529a.tar.gz
Add two new map types: DEVMAP and CPUMAP
Those two map types are necessary to support bpf_redirect_map() in XDP. v2: Use ArrayBase as the base class of DevMap and CpuMap Signed-off-by: Gary Lin <glin@suse.com>
Diffstat (limited to 'src')
-rw-r--r--src/cc/export/helpers.h17
-rw-r--r--src/cc/frontends/clang/b_frontend_action.cc7
-rw-r--r--src/python/bcc/table.py19
3 files changed, 43 insertions, 0 deletions
diff --git a/src/cc/export/helpers.h b/src/cc/export/helpers.h
index 411c6e8f..a05a9f74 100644
--- a/src/cc/export/helpers.h
+++ b/src/cc/export/helpers.h
@@ -201,6 +201,23 @@ struct bpf_stacktrace {
#define BPF_PROG_ARRAY(_name, _max_entries) \
BPF_TABLE("prog", u32, u32, _name, _max_entries)
+#define BPF_XDP_REDIRECT_MAP(_table_type, _leaf_type, _name, _max_entries) \
+struct _name##_table_t { \
+ u32 key; \
+ _leaf_type leaf; \
+ /* xdp_act = map.redirect_map(index, flag) */ \
+ u64 (*redirect_map) (int, int); \
+ u32 max_entries; \
+}; \
+__attribute__((section("maps/"_table_type))) \
+struct _name##_table_t _name = { .max_entries = (_max_entries) }
+
+#define BPF_DEVMAP(_name, _max_entries) \
+ BPF_XDP_REDIRECT_MAP("devmap", int, _name, _max_entries)
+
+#define BPF_CPUMAP(_name, _max_entries) \
+ BPF_XDP_REDIRECT_MAP("cpumap", u32, _name, _max_entries)
+
// packet parsing state machine helpers
#define cursor_advance(_cursor, _len) \
({ void *_tmp = _cursor; _cursor += _len; _tmp; })
diff --git a/src/cc/frontends/clang/b_frontend_action.cc b/src/cc/frontends/clang/b_frontend_action.cc
index e793ac95..9baec723 100644
--- a/src/cc/frontends/clang/b_frontend_action.cc
+++ b/src/cc/frontends/clang/b_frontend_action.cc
@@ -609,6 +609,9 @@ bool BTypeVisitor::VisitCallExpr(CallExpr *Call) {
} else if (memb_name == "check_current_task") {
prefix = "bpf_current_task_under_cgroup";
suffix = ")";
+ } else if (memb_name == "redirect_map") {
+ prefix = "bpf_redirect_map";
+ suffix = ")";
} else {
error(Call->getLocStart(), "invalid bpf_table operation %0") << memb_name;
return false;
@@ -920,6 +923,10 @@ bool BTypeVisitor::VisitVarDecl(VarDecl *Decl) {
map_type = BPF_MAP_TYPE_CGROUP_ARRAY;
} else if (A->getName() == "maps/stacktrace") {
map_type = BPF_MAP_TYPE_STACK_TRACE;
+ } else if (A->getName() == "maps/devmap") {
+ map_type = BPF_MAP_TYPE_DEVMAP;
+ } else if (A->getName() == "maps/cpumap") {
+ map_type = BPF_MAP_TYPE_CPUMAP;
} else if (A->getName() == "maps/extern") {
if (!fe_.table_storage().Find(global_path, table_it)) {
error(Decl->getLocStart(), "reference to undefined table");
diff --git a/src/python/bcc/table.py b/src/python/bcc/table.py
index d26c315d..f1633217 100644
--- a/src/python/bcc/table.py
+++ b/src/python/bcc/table.py
@@ -36,6 +36,13 @@ BPF_MAP_TYPE_CGROUP_ARRAY = 8
BPF_MAP_TYPE_LRU_HASH = 9
BPF_MAP_TYPE_LRU_PERCPU_HASH = 10
BPF_MAP_TYPE_LPM_TRIE = 11
+BPF_MAP_TYPE_ARRAY_OF_MAPS = 12
+BPF_MAP_TYPE_HASH_OF_MAPS = 13
+BPF_MAP_TYPE_DEVMAP = 14
+BPF_MAP_TYPE_SOCKMAP = 15
+BPF_MAP_TYPE_CPUMAP = 16
+BPF_MAP_TYPE_XSKMAP = 17
+BPF_MAP_TYPE_SOCKHASH = 18
stars_max = 40
log2_index_max = 65
@@ -144,6 +151,10 @@ def Table(bpf, map_id, map_fd, keytype, leaftype, **kwargs):
t = LruPerCpuHash(bpf, map_id, map_fd, keytype, leaftype)
elif ttype == BPF_MAP_TYPE_CGROUP_ARRAY:
t = CgroupArray(bpf, map_id, map_fd, keytype, leaftype)
+ elif ttype == BPF_MAP_TYPE_DEVMAP:
+ t = DevMap(bpf, map_id, map_fd, keytype, leaftype)
+ elif ttype == BPF_MAP_TYPE_CPUMAP:
+ t = CpuMap(bpf, map_id, map_fd, keytype, leaftype)
if t == None:
raise Exception("Unknown table type %d" % ttype)
return t
@@ -766,3 +777,11 @@ class StackTrace(TableBase):
def clear(self):
pass
+
+class DevMap(ArrayBase):
+ def __init__(self, *args, **kwargs):
+ super(DevMap, self).__init__(*args, **kwargs)
+
+class CpuMap(ArrayBase):
+ def __init__(self, *args, **kwargs):
+ super(CpuMap, self).__init__(*args, **kwargs)