bpf: add support for map_name and map_ifindex fields in BPF_MAP_CREATE

* bpf.c (BEGIN_BPF_CMD_DECODER(BPF_MAP_CREATE)): Decode map_name
and map_ifindex fields that were added in Linux commits
v4.15-rc1~84^2~605^2~3 and v4.16-rc1~123^2~145^2~5^2~8, respectively.
* bpf_attr.h (struct BPF_MAP_CREATE_struct): Add map_name
and map_ifindex fields.
* tests/bpf.c (init_BPF_MAP_CREATE_attr7): New function.
(BPF_MAP_CREATE_checks): Remove const qualifier, add two more checks.
This commit is contained in:
Eugene Syromyatnikov 2018-03-05 15:53:48 +01:00 committed by Dmitry V. Levin
parent b20f744662
commit 25a5961610
3 changed files with 82 additions and 6 deletions

16
bpf.c
View File

@ -166,6 +166,22 @@ BEGIN_BPF_CMD_DECODER(BPF_MAP_CREATE)
XLAT_STYLE_FMT_U | XLAT_STYLE_VERBOSE,
numa_node, NULL);
}
/* map_name field was added in Linux commit v4.15-rc1~84^2~605^2~3. */
if (len <= offsetof(struct BPF_MAP_CREATE_struct, map_name))
break;
PRINT_FIELD_CSTRING_SZ(", ", attr, map_name,
MIN(sizeof(attr.map_name),
len - offsetof(struct BPF_MAP_CREATE_struct,
map_name)));
/*
* map_ifindex field was added in Linux commit
* v4.16-rc1~123^2~145^2~5^2~8.
*/
if (len <= offsetof(struct BPF_MAP_CREATE_struct, map_ifindex))
break;
PRINT_FIELD_IFINDEX(", ", attr, map_ifindex);
}
END_BPF_CMD_DECODER(RVAL_DECODED | RVAL_FD)

View File

@ -44,11 +44,13 @@ struct BPF_MAP_CREATE_struct {
uint32_t map_flags;
uint32_t inner_map_fd;
uint32_t numa_node;
char map_name[BPF_OBJ_NAME_LEN];
uint32_t map_ifindex;
};
#define BPF_MAP_CREATE_struct_size \
sizeof(struct BPF_MAP_CREATE_struct)
#define expected_BPF_MAP_CREATE_struct_size 28
#define expected_BPF_MAP_CREATE_struct_size 48
struct BPF_MAP_LOOKUP_ELEM_struct {
uint32_t map_fd;

View File

@ -233,7 +233,14 @@ test_bpf(const struct bpf_check *cmd_check)
cmd_check->cmd_str, addr, page_size + 1, errstr);
}
static const struct bpf_attr_check BPF_MAP_CREATE_checks[] = {
static void
init_BPF_MAP_CREATE_attr7(struct bpf_attr_check *check)
{
struct BPF_MAP_CREATE_struct *attr = &check->data.BPF_MAP_CREATE_data;
attr->map_ifindex = ifindex_lo();
}
static struct bpf_attr_check BPF_MAP_CREATE_checks[] = {
{
.data = { .BPF_MAP_CREATE_data = { .map_type = 2 } },
.size = offsetofend(struct BPF_MAP_CREATE_struct, map_type),
@ -249,13 +256,16 @@ static const struct bpf_attr_check BPF_MAP_CREATE_checks[] = {
.map_flags = 7,
.inner_map_fd = -1,
.numa_node = 3141592653,
.map_name = "0123456789abcde",
} },
.size = offsetofend(struct BPF_MAP_CREATE_struct, numa_node),
.size = offsetof(struct BPF_MAP_CREATE_struct, map_name) + 8,
.str = "map_type=BPF_MAP_TYPE_CPUMAP, key_size=4"
", value_size=8, max_entries=256"
", map_flags=BPF_F_NO_PREALLOC|BPF_F_NO_COMMON_LRU"
"|BPF_F_NUMA_NODE, inner_map_fd=-1"
", numa_node=3141592653",
", numa_node=3141592653"
", map_name=\"0123456\"...",
},
{ /* 2 */
.data = { .BPF_MAP_CREATE_data = {
@ -266,13 +276,17 @@ static const struct bpf_attr_check BPF_MAP_CREATE_checks[] = {
.map_flags = 0xfffffff8,
.inner_map_fd = 2718281828,
.numa_node = -1,
.map_name = "",
.map_ifindex = 3141592653,
} },
.size = offsetofend(struct BPF_MAP_CREATE_struct, numa_node),
.size = offsetofend(struct BPF_MAP_CREATE_struct, map_ifindex),
.str = "map_type=0x11 /* BPF_MAP_TYPE_??? */"
", key_size=4207812181, value_size=3134983661"
", max_entries=3203386110"
", map_flags=0xfffffff8 /* BPF_F_??? */"
", inner_map_fd=-1576685468",
", inner_map_fd=-1576685468"
", map_name=\"\", map_ifindex=3141592653",
},
{ /* 3 */
.data = { .BPF_MAP_CREATE_data = {
@ -328,6 +342,50 @@ static const struct bpf_attr_check BPF_MAP_CREATE_checks[] = {
", inner_map_fd=-1576685468"
", numa_node=4294967295 /* NUMA_NO_NODE */",
},
{ /* 6 */
.data = { .BPF_MAP_CREATE_data = {
.map_type = 0xdeadf00d,
.key_size = 0xface1e55,
.value_size = 0xbadc0ded,
.max_entries = 0xbeefcafe,
.map_flags = 0xc0dedead,
.inner_map_fd = 2718281828,
.numa_node = -1,
.map_name = "fedcba9876543210",
} },
.size = offsetofend(struct BPF_MAP_CREATE_struct, map_name),
.str = "map_type=0xdeadf00d /* BPF_MAP_TYPE_??? */"
", key_size=4207812181, value_size=3134983661"
", max_entries=3203386110"
", map_flags=BPF_F_NO_PREALLOC|BPF_F_NUMA_NODE"
"|0xc0dedea8"
", inner_map_fd=-1576685468"
", numa_node=4294967295 /* NUMA_NO_NODE */"
", map_name=\"fedcba987654321\"...",
},
{ /* 7 */
.data = { .BPF_MAP_CREATE_data = {
.map_type = 0xdeadf00d,
.key_size = 0xface1e55,
.value_size = 0xbadc0ded,
.max_entries = 0xbeefcafe,
.map_flags = 0xc0dedead,
.inner_map_fd = 2718281828,
.numa_node = -1,
.map_name = "0123456789abcde",
} },
.size = offsetofend(struct BPF_MAP_CREATE_struct, map_ifindex),
.str = "map_type=0xdeadf00d /* BPF_MAP_TYPE_??? */"
", key_size=4207812181, value_size=3134983661"
", max_entries=3203386110"
", map_flags=BPF_F_NO_PREALLOC|BPF_F_NUMA_NODE"
"|0xc0dedea8"
", inner_map_fd=-1576685468"
", numa_node=4294967295 /* NUMA_NO_NODE */"
", map_name=\"0123456789abcde\""
", map_ifindex=" IFINDEX_LO_STR,
.init_fn = init_BPF_MAP_CREATE_attr7,
},
};
static const struct bpf_attr_check BPF_MAP_LOOKUP_ELEM_checks[] = {