Add iter.info and iter.len to pass iterator information separately from log_opts. Keep the existing iter_info and iter_info_len fields working for callers that do not request logs. Thereafter, log_opts can work for iter link_create. Signed-off-by: Leon Hwang --- tools/lib/bpf/bpf.c | 17 +++++++++++------ tools/lib/bpf/bpf.h | 8 ++++++++ 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/tools/lib/bpf/bpf.c b/tools/lib/bpf/bpf.c index 38dcb31e8c0e..174a8bfaf663 100644 --- a/tools/lib/bpf/bpf.c +++ b/tools/lib/bpf/bpf.c @@ -808,11 +808,6 @@ int bpf_link_create(int prog_fd, int target_fd, if (iter_info_len && attach_type != BPF_TRACE_ITER) return libbpf_err(-EINVAL); - if (iter_info_len) - iter_info = OPTS_GET(opts, iter_info, (void *)0); - else - log_opts = OPTS_GET(opts, log_opts, (void *)0); - /* validate we don't have unexpected combinations of non-zero fields */ if (iter_info_len || target_btf_id) { if (iter_info_len && target_btf_id) @@ -821,6 +816,16 @@ int bpf_link_create(int prog_fd, int target_fd, return libbpf_err(-EINVAL); } + if (iter_info_len) { + if (OPTS_GET(opts, iter.len, 0)) + return libbpf_err(-EINVAL); + iter_info = OPTS_GET(opts, iter_info, (void *)0); + } else { + log_opts = OPTS_GET(opts, log_opts, (void *)0); + iter_info = OPTS_GET(opts, iter.info, (void *)0); + iter_info_len = OPTS_GET(opts, iter.len, 0); + } + memset(&attr, 0, attr_sz); attr.link_create.prog_fd = prog_fd; attr.link_create.target_fd = target_fd; @@ -970,7 +975,7 @@ int bpf_link_create(int prog_fd, int target_fd, return libbpf_err(-EINVAL); break; default: - if (!OPTS_ZEROED(opts, iter_info_len)) + if (!OPTS_ZEROED(opts, log_opts)) return libbpf_err(-EINVAL); break; } diff --git a/tools/lib/bpf/bpf.h b/tools/lib/bpf/bpf.h index fe3b7fd8512b..2ac143fd1102 100644 --- a/tools/lib/bpf/bpf.h +++ b/tools/lib/bpf/bpf.h @@ -422,6 +422,10 @@ union bpf_iter_link_info; /* defined in up-to-date linux/bpf.h */ struct bpf_link_create_opts { size_t sz; /* size of this struct for forward/backward compatibility */ __u32 flags; + /* + * iter_info and iter_info_len are deprecated, use iter.info and + * iter.len instead. + */ union { union bpf_iter_link_info *iter_info; struct bpf_log_opts *log_opts; @@ -478,6 +482,10 @@ struct bpf_link_create_opts { const __u64 *cookies; __u32 cnt; } tracing_multi; + struct { + union bpf_iter_link_info *info; + __u32 len; + } iter; }; size_t :0; }; -- 2.55.0