Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

libbpf: Add low-level APIs for new bpf_link commands

Add low-level API calls for bpf_link_get_next_id() and
bpf_link_get_fd_by_id().

Signed-off-by: Andrii Nakryiko <andriin@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Link: https://lore.kernel.org/bpf/20200429001614.1544-6-andriin@fb.com

authored by

Andrii Nakryiko and committed by
Alexei Starovoitov
0dbc8668 f2e10bff

+26 -3
+17 -2
tools/lib/bpf/bpf.c
··· 721 721 return bpf_obj_get_next_id(start_id, next_id, BPF_BTF_GET_NEXT_ID); 722 722 } 723 723 724 + int bpf_link_get_next_id(__u32 start_id, __u32 *next_id) 725 + { 726 + return bpf_obj_get_next_id(start_id, next_id, BPF_LINK_GET_NEXT_ID); 727 + } 728 + 724 729 int bpf_prog_get_fd_by_id(__u32 id) 725 730 { 726 731 union bpf_attr attr; ··· 756 751 return sys_bpf(BPF_BTF_GET_FD_BY_ID, &attr, sizeof(attr)); 757 752 } 758 753 759 - int bpf_obj_get_info_by_fd(int prog_fd, void *info, __u32 *info_len) 754 + int bpf_link_get_fd_by_id(__u32 id) 755 + { 756 + union bpf_attr attr; 757 + 758 + memset(&attr, 0, sizeof(attr)); 759 + attr.link_id = id; 760 + 761 + return sys_bpf(BPF_LINK_GET_FD_BY_ID, &attr, sizeof(attr)); 762 + } 763 + 764 + int bpf_obj_get_info_by_fd(int bpf_fd, void *info, __u32 *info_len) 760 765 { 761 766 union bpf_attr attr; 762 767 int err; 763 768 764 769 memset(&attr, 0, sizeof(attr)); 765 - attr.info.bpf_fd = prog_fd; 770 + attr.info.bpf_fd = bpf_fd; 766 771 attr.info.info_len = *info_len; 767 772 attr.info.info = ptr_to_u64(info); 768 773
+3 -1
tools/lib/bpf/bpf.h
··· 216 216 LIBBPF_API int bpf_prog_get_next_id(__u32 start_id, __u32 *next_id); 217 217 LIBBPF_API int bpf_map_get_next_id(__u32 start_id, __u32 *next_id); 218 218 LIBBPF_API int bpf_btf_get_next_id(__u32 start_id, __u32 *next_id); 219 + LIBBPF_API int bpf_link_get_next_id(__u32 start_id, __u32 *next_id); 219 220 LIBBPF_API int bpf_prog_get_fd_by_id(__u32 id); 220 221 LIBBPF_API int bpf_map_get_fd_by_id(__u32 id); 221 222 LIBBPF_API int bpf_btf_get_fd_by_id(__u32 id); 222 - LIBBPF_API int bpf_obj_get_info_by_fd(int prog_fd, void *info, __u32 *info_len); 223 + LIBBPF_API int bpf_link_get_fd_by_id(__u32 id); 224 + LIBBPF_API int bpf_obj_get_info_by_fd(int bpf_fd, void *info, __u32 *info_len); 223 225 LIBBPF_API int bpf_prog_query(int target_fd, enum bpf_attach_type type, 224 226 __u32 query_flags, __u32 *attach_flags, 225 227 __u32 *prog_ids, __u32 *prog_cnt);
+6
tools/lib/bpf/libbpf.map
··· 254 254 bpf_program__set_lsm; 255 255 bpf_set_link_xdp_fd_opts; 256 256 } LIBBPF_0.0.7; 257 + 258 + LIBBPF_0.0.9 { 259 + global: 260 + bpf_link_get_fd_by_id; 261 + bpf_link_get_next_id; 262 + } LIBBPF_0.0.8;