]> granicus.if.org Git - strace/commitdiff
bpf: add support for decoding struct bpf_attr.expected_attach_type field
authorEugene Syromyatnikov <evgsyr@gmail.com>
Tue, 15 May 2018 12:19:01 +0000 (14:19 +0200)
committerDmitry V. Levin <ldv@altlinux.org>
Wed, 23 May 2018 23:27:43 +0000 (23:27 +0000)
* bpf_attr.h (struct BPF_PROG_LOAD_struct): Add expected_attach_type
field.
(BPF_PROG_LOAD_struct_size): Update to offsetofend of
expected_attach_type field.
(expected_BPF_PROG_LOAD_struct_size): Update to 72.
* bpf.c (BEGIN_BPF_CMD_DECODER(BPF_PROG_LOAD)): Decode
expected_attach_type field.
* tests/bpf.c: Update expected output.

bpf.c
bpf_attr.h
tests/bpf.c

diff --git a/bpf.c b/bpf.c
index a1eb635bd1abf979e77913a406402efd27864065..85cf6b4662686370287bb62b9b13214f83e161aa 100644 (file)
--- a/bpf.c
+++ b/bpf.c
@@ -265,6 +265,15 @@ BEGIN_BPF_CMD_DECODER(BPF_PROG_LOAD)
        if (len <= offsetof(struct BPF_PROG_LOAD_struct, prog_ifindex))
                break;
        PRINT_FIELD_IFINDEX(", ", attr, prog_ifindex);
+
+       /*
+        * expected_attach_type was added in Linux commit
+        * v4.17-rc1~148^2~19^2^2~8.
+        */
+       if (len <= offsetof(struct BPF_PROG_LOAD_struct, expected_attach_type))
+               break;
+       PRINT_FIELD_XVAL(", ", attr, expected_attach_type, bpf_attach_type,
+                        "BPF_???");
 }
 END_BPF_CMD_DECODER(RVAL_DECODED | RVAL_FD)
 
index cc78d50af4ac7391b8e28c22c391541f803a7c90..00beef118c4c3e6a5e7519cb3f74c562bb99ac9c 100644 (file)
@@ -104,11 +104,12 @@ struct BPF_PROG_LOAD_struct {
        uint32_t prog_flags;
        char     prog_name[BPF_OBJ_NAME_LEN];
        uint32_t prog_ifindex;
+       uint32_t expected_attach_type;
 };
 
 #define BPF_PROG_LOAD_struct_size \
-       offsetofend(struct BPF_PROG_LOAD_struct, prog_ifindex)
-#define expected_BPF_PROG_LOAD_struct_size 68
+       offsetofend(struct BPF_PROG_LOAD_struct, expected_attach_type)
+#define expected_BPF_PROG_LOAD_struct_size 72
 
 struct BPF_OBJ_PIN_struct {
        uint64_t ATTRIBUTE_ALIGNED(8) pathname;
index df63b38ad83173cc160ce8ed0648cfc1c1deba87..be2310bd6fd4112853580fd164a3aced15006a51 100644 (file)
@@ -509,7 +509,8 @@ print_BPF_PROG_LOAD_attr4(const struct bpf_attr_check *check, unsigned long addr
               ", license=\"%s\", log_level=2718281828, log_size=4096"
               ", log_buf=%p, kern_version=KERNEL_VERSION(51966, 240, 13)"
               ", prog_flags=BPF_F_STRICT_ALIGNMENT|0x2"
-              ", prog_name=\"0123456789abcde\"..., prog_ifindex=%s",
+              ", prog_name=\"0123456789abcde\"..., prog_ifindex=%s"
+              ", expected_attach_type=BPF_CGROUP_INET6_BIND",
               (unsigned int) ARRAY_SIZE(insns), insns,
               license, log_buf, IFINDEX_LO_STR);
 }
@@ -595,8 +596,10 @@ static struct bpf_attr_check BPF_PROG_LOAD_checks[] = {
                        .kern_version = 0xcafef00d,
                        .prog_flags = 3,
                        .prog_name = "0123456789abcdef",
+                       .expected_attach_type = 9,
                } },
-               .size = offsetofend(struct BPF_PROG_LOAD_struct, prog_ifindex),
+               .size = offsetofend(struct BPF_PROG_LOAD_struct,
+                                   expected_attach_type),
                .init_fn = init_BPF_PROG_LOAD_attr4,
                .print_fn = print_BPF_PROG_LOAD_attr4
        },