From: Toke Høiland-Jørgensen <toke@xxxxxxxxxx> This adds simple syscall wrappers for the new BPF_PROG_CHAIN_* commands to libbpf. Signed-off-by: Toke Høiland-Jørgensen <toke@xxxxxxxxxx> --- tools/lib/bpf/bpf.c | 34 ++++++++++++++++++++++++++++++++++ tools/lib/bpf/bpf.h | 4 ++++ tools/lib/bpf/libbpf.map | 3 +++ 3 files changed, 41 insertions(+) diff --git a/tools/lib/bpf/bpf.c b/tools/lib/bpf/bpf.c index cbb933532981..23246fa169e7 100644 --- a/tools/lib/bpf/bpf.c +++ b/tools/lib/bpf/bpf.c @@ -703,3 +703,37 @@ int bpf_task_fd_query(int pid, int fd, __u32 flags, char *buf, __u32 *buf_len, return err; } + +int bpf_prog_chain_add(int prev_prog_fd, __u32 retcode, int next_prog_fd) { + union bpf_attr attr = {}; + + attr.prev_prog_fd = prev_prog_fd; + attr.next_prog_fd = next_prog_fd; + attr.retcode = retcode; + + return sys_bpf(BPF_PROG_CHAIN_ADD, &attr, sizeof(attr)); +} + +int bpf_prog_chain_del(int prev_prog_fd, __u32 retcode) { + union bpf_attr attr = {}; + + attr.prev_prog_fd = prev_prog_fd; + attr.retcode = retcode; + + return sys_bpf(BPF_PROG_CHAIN_DEL, &attr, sizeof(attr)); +} + +int bpf_prog_chain_get(int prev_prog_fd, __u32 retcode, __u32 *prog_id) { + union bpf_attr attr = {}; + int err; + + attr.prev_prog_fd = prev_prog_fd; + attr.retcode = retcode; + + err = sys_bpf(BPF_PROG_CHAIN_GET, &attr, sizeof(attr)); + + if (!err) + *prog_id = attr.next_prog_id; + + return err; +} diff --git a/tools/lib/bpf/bpf.h b/tools/lib/bpf/bpf.h index 0db01334740f..0300cb8c8bed 100644 --- a/tools/lib/bpf/bpf.h +++ b/tools/lib/bpf/bpf.h @@ -171,6 +171,10 @@ LIBBPF_API int bpf_task_fd_query(int pid, int fd, __u32 flags, char *buf, __u32 *buf_len, __u32 *prog_id, __u32 *fd_type, __u64 *probe_offset, __u64 *probe_addr); +LIBBPF_API int bpf_prog_chain_add(int prev_prog_fd, __u32 retcode, int next_prog_fd); +LIBBPF_API int bpf_prog_chain_del(int prev_prog_fd, __u32 retcode); +LIBBPF_API int bpf_prog_chain_get(int prev_prog_fd, __u32 retcode, __u32 *prog_id); + #ifdef __cplusplus } /* extern "C" */ #endif diff --git a/tools/lib/bpf/libbpf.map b/tools/lib/bpf/libbpf.map index 8d10ca03d78d..9c483c554054 100644 --- a/tools/lib/bpf/libbpf.map +++ b/tools/lib/bpf/libbpf.map @@ -192,4 +192,7 @@ LIBBPF_0.0.5 { } LIBBPF_0.0.4; LIBBPF_0.0.6 { + bpf_prog_chain_add; + bpf_prog_chain_del; + bpf_prog_chain_get; } LIBBPF_0.0.5;