]> granicus.if.org Git - strace/commitdiff
bpf: update BPF_PROG_LOAD decoding
authorDmitry V. Levin <ldv@altlinux.org>
Thu, 27 Jul 2017 00:44:31 +0000 (00:44 +0000)
committerDmitry V. Levin <ldv@altlinux.org>
Thu, 27 Jul 2017 00:44:31 +0000 (00:44 +0000)
Implement decoding of union bpf_attr.prog_flags field for BPF_PROG_LOAD
command introduced by linux kernel commit v4.12-rc2~34^2~29^2~2.

* configure.ac: Check for prog_flags member of union bpf_attr
instead of kern_version.
* xlat/bpf_prog_flags.in: New file.
* bpf.c: Include "xlat/bpf_prog_flags.h".
(decode_BPF_PROG_LOAD): Add prog_flags field to the structure, print it.
* tests/bpf.c: Update macro guards of BPF_PROG_LOAD decoder test.
(init_BPF_PROG_LOAD_first, print_BPF_PROG_LOAD_attr): Update expected
output.
(init_BPF_PROG_LOAD_attr): Initialize prog_flags field, update offset.

bpf.c
configure.ac
tests/bpf.c
xlat/bpf_prog_flags.in [new file with mode: 0644]

diff --git a/bpf.c b/bpf.c
index 676ab85e1272efa872e1030f45756ddd8b44bc08..19109b5de10a1bfcd1bc8e0a85a207d55c84c6d4 100644 (file)
--- a/bpf.c
+++ b/bpf.c
@@ -36,6 +36,7 @@
 #include "xlat/bpf_commands.h"
 #include "xlat/bpf_map_types.h"
 #include "xlat/bpf_prog_types.h"
+#include "xlat/bpf_prog_flags.h"
 #include "xlat/bpf_map_update_elem_flags.h"
 #include "xlat/bpf_attach_type.h"
 #include "xlat/bpf_attach_flags.h"
@@ -202,11 +203,9 @@ DEF_BPF_CMD_DECODER(BPF_PROG_LOAD)
                uint64_t ATTRIBUTE_ALIGNED(8) insns, license;
                uint32_t log_level, log_size;
                uint64_t ATTRIBUTE_ALIGNED(8) log_buf;
-               uint32_t kern_version;
+               uint32_t kern_version, prog_flags;
        } attr = {};
-       const size_t attr_size =
-               offsetofend(struct bpf_prog_load, kern_version);
-       const unsigned int len = size < attr_size ? size : attr_size;
+       const unsigned int len = size < sizeof(attr) ? size : sizeof(attr);
 
        memcpy(&attr, data, len);
 
@@ -219,7 +218,8 @@ DEF_BPF_CMD_DECODER(BPF_PROG_LOAD)
        PRINT_FIELD_U(", ", attr, log_size);
        PRINT_FIELD_X(", ", attr, log_buf);
        PRINT_FIELD_U(", ", attr, kern_version);
-       decode_attr_extra_data(tcp, data, size, attr_size);
+       PRINT_FIELD_FLAGS(", ", attr, prog_flags, bpf_prog_flags, "BPF_F_???");
+       decode_attr_extra_data(tcp, data, size, sizeof(attr));
        tprints("}");
 
        return RVAL_DECODED | RVAL_FD;
index 19d5f19a17ddf49cd30705899831a1072ce263a2..27a2ea12df8f3f0e3d92fe35d584e09b51ddde4e 100644 (file)
@@ -431,8 +431,8 @@ AC_CHECK_HEADERS([linux/bpf.h], [
        st_CHECK_UNION_BPF_ATTR([attach_flags])
        st_CHECK_UNION_BPF_ATTR([bpf_fd])
        st_CHECK_UNION_BPF_ATTR([flags])
-       st_CHECK_UNION_BPF_ATTR([kern_version])
        st_CHECK_UNION_BPF_ATTR([max_entries])
+       st_CHECK_UNION_BPF_ATTR([prog_flags])
 ])
 
 AC_CHECK_TYPES([struct statfs], [
index fc03879795e855c6b1bcb2b8aea071445ab92380..83a92a901a052b7bf19fc00bf564ddfb8e519923 100644 (file)
@@ -34,8 +34,8 @@
  && (defined HAVE_UNION_BPF_ATTR_ATTACH_FLAGS  \
   || defined HAVE_UNION_BPF_ATTR_BPF_FD                \
   || defined HAVE_UNION_BPF_ATTR_FLAGS         \
-  || defined HAVE_UNION_BPF_ATTR_KERN_VERSION  \
-  || defined HAVE_UNION_BPF_ATTR_MAX_ENTRIES)
+  || defined HAVE_UNION_BPF_ATTR_MAX_ENTRIES   \
+  || defined HAVE_UNION_BPF_ATTR_PROG_FLAGS)
 
 # include <stddef.h>
 # include <stdio.h>
@@ -344,7 +344,7 @@ init_BPF_MAP_GET_NEXT_KEY_attr(const unsigned long eop)
 
 # endif /* HAVE_UNION_BPF_ATTR_FLAGS */
 
-# ifdef HAVE_UNION_BPF_ATTR_KERN_VERSION
+# ifdef HAVE_UNION_BPF_ATTR_PROG_FLAGS
 
 static unsigned int
 init_BPF_PROG_LOAD_first(const unsigned long eop)
@@ -363,7 +363,7 @@ print_BPF_PROG_LOAD_first(const unsigned long addr)
 
        printf("prog_type=BPF_PROG_TYPE_SOCKET_FILTER, insn_cnt=0, insns=0"
               ", license=NULL, log_level=0, log_size=0, log_buf=0"
-              ", kern_version=0");
+              ", kern_version=0, prog_flags=0");
 }
 
 static const struct bpf_insn insns[] = {
@@ -382,10 +382,11 @@ init_BPF_PROG_LOAD_attr(const unsigned long eop)
                .log_level = 42,
                .log_size = sizeof(log_buf),
                .log_buf = (uintptr_t) log_buf,
-               .kern_version = 0xcafef00d
+               .kern_version = 0xcafef00d,
+               .prog_flags = 1
        };
        static const unsigned int offset =
-               offsetofend(union bpf_attr, kern_version);
+               offsetofend(union bpf_attr, prog_flags);
        const unsigned long addr = eop - offset;
 
        memcpy((void *) addr, &attr, offset);
@@ -397,12 +398,12 @@ print_BPF_PROG_LOAD_attr(const unsigned long addr)
 {
        printf("prog_type=BPF_PROG_TYPE_SOCKET_FILTER, insn_cnt=%u, insns=%p"
               ", license=\"GPL\", log_level=42, log_size=4096, log_buf=%p"
-              ", kern_version=%u",
+              ", kern_version=%u, prog_flags=BPF_F_STRICT_ALIGNMENT",
               (unsigned int) ARRAY_SIZE(insns), insns,
               log_buf, 0xcafef00d);
 }
 
-# endif /* HAVE_UNION_BPF_ATTR_KERN_VERSION */
+# endif /* HAVE_UNION_BPF_ATTR_PROG_FLAGS */
 
 /*
  * bpf() syscall and its first six commands were introduced in Linux kernel
@@ -554,7 +555,7 @@ main(void)
        TEST_BPF(BPF_MAP_GET_NEXT_KEY);
 # endif
 
-# ifdef HAVE_UNION_BPF_ATTR_KERN_VERSION
+# ifdef HAVE_UNION_BPF_ATTR_PROG_FLAGS
        TEST_BPF(BPF_PROG_LOAD);
 # endif
 
diff --git a/xlat/bpf_prog_flags.in b/xlat/bpf_prog_flags.in
new file mode 100644 (file)
index 0000000..7fcf3a7
--- /dev/null
@@ -0,0 +1 @@
+BPF_F_STRICT_ALIGNMENT 1