Skip to content

Commit

Permalink
extern BPF_TABLE_PINNED to include an optional flags argument
Browse files Browse the repository at this point in the history
BPF_TABLE_PINNED has a feature to create a map and pin it if
the pinned map doesn't exist. Some maps, e.g., bpf_sk_storage map,
requires a non-zero flag for map creation. This patch extended
the BPF_TABLE_PINNED map to include an optional flags argument
for any pinned map which my require a non-zero flags.

Signed-off-by: Yonghong Song <[email protected]>
  • Loading branch information
yonghong-song committed Feb 8, 2022
1 parent 63de4c5 commit fff25a8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
13 changes: 11 additions & 2 deletions src/cc/export/helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,17 @@ struct _name##_table_t __##_name
#define BPF_TABLE(_table_type, _key_type, _leaf_type, _name, _max_entries) \
BPF_F_TABLE(_table_type, _key_type, _leaf_type, _name, _max_entries, 0)

#define BPF_TABLE_PINNED(_table_type, _key_type, _leaf_type, _name, _max_entries, _pinned) \
BPF_TABLE(_table_type ":" _pinned, _key_type, _leaf_type, _name, _max_entries)
#define BPF_TABLE_PINNED7(_table_type, _key_type, _leaf_type, _name, _max_entries, _pinned, _flags) \
BPF_F_TABLE(_table_type ":" _pinned, _key_type, _leaf_type, _name, _max_entries, _flags)

#define BPF_TABLE_PINNED6(_table_type, _key_type, _leaf_type, _name, _max_entries, _pinned) \
BPF_F_TABLE(_table_type ":" _pinned, _key_type, _leaf_type, _name, _max_entries, 0)

#define BPF_TABLE_PINNEDX(_1, _2, _3, _4, _5, _6, _7, NAME, ...) NAME

// Define a pinned table with optional flags argument
#define BPF_TABLE_PINNED(...) \
BPF_TABLE_PINNEDX(__VA_ARGS__, BPF_TABLE_PINNED7, BPF_TABLE_PINNED6)(__VA_ARGS__)

// define a table same as above but allow it to be referenced by other modules
#define BPF_TABLE_PUBLIC(_table_type, _key_type, _leaf_type, _name, _max_entries) \
Expand Down
2 changes: 1 addition & 1 deletion tests/cc/test_pinned_table.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ TEST_CASE("test pinned table", "[pinned_table]") {
// test table access
{
const std::string BPF_PROGRAM = R"(
BPF_TABLE_PINNED("hash", u64, u64, ids, 1024, "/sys/fs/bpf/test_pinned_table");
BPF_TABLE_PINNED("hash", u64, u64, ids, 0, "/sys/fs/bpf/test_pinned_table", BPF_F_NO_PREALLOC);
)";

ebpf::BPF bpf;
Expand Down

0 comments on commit fff25a8

Please sign in to comment.