From cabd6955d3c3048bb2ba19032b504eeb3776a86f Mon Sep 17 00:00:00 2001 From: "Dmitry V. Levin" Date: Tue, 12 Mar 2019 11:17:20 +0000 Subject: [PATCH] bpf: print struct bpf_prog_info.gpl_compatible This bit field was added by Linux commit v4.18-rc1~114^2~376^2~6. * bpf_attr.h (struct bpf_prog_info_struct): Add gpl_compatible field. * bpf.c (print_bpf_prog_info): Print gpl_compatible field. * tests/bpf-obj_get_info_by_fd.c (main): Update expected output. --- bpf.c | 5 ++++- bpf_attr.h | 1 + tests/bpf-obj_get_info_by_fd.c | 3 +++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/bpf.c b/bpf.c index 397521e8..6fb4c2c2 100644 --- a/bpf.c +++ b/bpf.c @@ -525,11 +525,14 @@ print_bpf_prog_info(struct tcb * const tcp, uint32_t bpf_fd, /* * ifindex, netns_dev, and netns_ino fields were introduced - * by Linux commit v4.16-rc1~123^2~227^2~5^2~2. + * by Linux commit v4.16-rc1~123^2~227^2~5^2~2, and + * gpl_compatible was added later by Linux commit + * v4.18-rc1~114^2~376^2~6. */ if (len <= offsetof(struct bpf_prog_info_struct, ifindex)) goto print_bpf_prog_info_end; PRINT_FIELD_IFINDEX(", ", info, ifindex); + tprintf(", gpl_compatible=%u", info.gpl_compatible); PRINT_FIELD_DEV(", ", info, netns_dev); PRINT_FIELD_U(", ", info, netns_ino); diff --git a/bpf_attr.h b/bpf_attr.h index dc7694cc..cb498963 100644 --- a/bpf_attr.h +++ b/bpf_attr.h @@ -259,6 +259,7 @@ struct bpf_prog_info_struct { uint64_t ATTRIBUTE_ALIGNED(8) map_ids; char name[BPF_OBJ_NAME_LEN]; uint32_t ifindex; + uint32_t gpl_compatible:1; /* * The kernel UAPI is broken by Linux commit * v4.16-rc1~123^2~227^2~5^2~2 . diff --git a/tests/bpf-obj_get_info_by_fd.c b/tests/bpf-obj_get_info_by_fd.c index fba0e75b..ff06e27d 100644 --- a/tests/bpf-obj_get_info_by_fd.c +++ b/tests/bpf-obj_get_info_by_fd.c @@ -460,6 +460,9 @@ main(void) if (bpf_prog_get_info_attr.info_len > offsetof(struct bpf_prog_info_struct, ifindex)) printf(", ifindex=%u", prog_info->ifindex); + if (bpf_prog_get_info_attr.info_len > + offsetofend(struct bpf_prog_info_struct, ifindex)) + printf(", gpl_compatible=%u", prog_info->gpl_compatible); if (bpf_prog_get_info_attr.info_len > offsetof(struct bpf_prog_info_struct, netns_dev)) printf(", netns_dev=makedev(%#x, %#x)", -- 2.50.1