diff options
author | Dmitrii Dolgov <9erthalion6@gmail.com> | 2022-05-10 18:52:30 +0300 |
---|---|---|
committer | Alexei Starovoitov <ast@kernel.org> | 2022-05-10 21:20:45 +0300 |
commit | 9f88361273082825d9f0d13a543d49f9fa0d44a8 (patch) | |
tree | 485b123ad10201fdb1bf16af6402bd419f8b4af9 /kernel/bpf/syscall.c | |
parent | c4423a174d2926c1c165176d17383631d75dfbec (diff) | |
download | linux-9f88361273082825d9f0d13a543d49f9fa0d44a8.tar.xz |
bpf: Add bpf_link iterator
Implement bpf_link iterator to traverse links via bpf_seq_file
operations. The changeset is mostly shamelessly copied from
commit a228a64fc1e4 ("bpf: Add bpf_prog iterator")
Signed-off-by: Dmitrii Dolgov <9erthalion6@gmail.com>
Acked-by: Yonghong Song <yhs@fb.com>
Link: https://lore.kernel.org/r/20220510155233.9815-2-9erthalion6@gmail.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Diffstat (limited to 'kernel/bpf/syscall.c')
-rw-r--r-- | kernel/bpf/syscall.c | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c index e0aead17dff4..50164d324eaf 100644 --- a/kernel/bpf/syscall.c +++ b/kernel/bpf/syscall.c @@ -4680,6 +4680,25 @@ struct bpf_link *bpf_link_by_id(u32 id) return link; } +struct bpf_link *bpf_link_get_curr_or_next(u32 *id) +{ + struct bpf_link *link; + + spin_lock_bh(&link_idr_lock); +again: + link = idr_get_next(&link_idr, id); + if (link) { + link = bpf_link_inc_not_zero(link); + if (IS_ERR(link)) { + (*id)++; + goto again; + } + } + spin_unlock_bh(&link_idr_lock); + + return link; +} + #define BPF_LINK_GET_FD_BY_ID_LAST_FIELD link_id static int bpf_link_get_fd_by_id(const union bpf_attr *attr) |