]> granicus.if.org Git - strace/commitdiff
bpf: add support for map_name and map_ifindex fields in BPF_MAP_CREATE
authorEugene Syromyatnikov <evgsyr@gmail.com>
Mon, 5 Mar 2018 14:53:48 +0000 (15:53 +0100)
committerDmitry V. Levin <ldv@altlinux.org>
Thu, 12 Apr 2018 23:00:29 +0000 (23:00 +0000)
* 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.

bpf.c
bpf_attr.h
tests/bpf.c

diff --git a/bpf.c b/bpf.c
index 60b55d1639db09f17dfc1afec10c15daf247b48f..dc5df34559ddd00b15ab17b873785a2f87f3f0ee 100644 (file)
--- a/bpf.c
+++ b/bpf.c
@@ -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)
 
index ccf3e082c0d780c2877223583654eaba7bf7fd7c..cc78d50af4ac7391b8e28c22c391541f803a7c90 100644 (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;
index 7dd4ba4a1136b5fea8c57e2d73eda3fbda175b92..00cf8fedccb86ce1ae59bcf8470c3975700b6d08 100644 (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[] = {