History

bpf: Support GET_FD_BY_ID and GET_NEXT_ID for bpf_link

Add support to look up bpf_link by ID and iterate over all existing bpf_links in the system. GET_FD_BY_ID code handles not-yet-ready bpf_link by checking that its ID hasn't been set to non-zero value yet. Setting bpf_link's ID is done as the very last step in finalizing bpf_link, together with installing FD. This approach allows users of bpf_link in kernel code to not worry about races between user-space and kernel code that hasn't finished attaching and initializing bpf_link.

Andrii Nakryiko committed 6 years ago

Commit 2d602c81 parent a3b80e12 files · +51 −0Browse files

Showing the changes to include/uapi/linux (1 of 2 files). Show all

Unified · Split

include/uapi/linux/bpf.h+2−0
@@ -113,6 +113,8 @@ enum bpf_cmd { · 112 unmodified lines
113113 BPF_MAP_DELETE_BATCH,
114114 BPF_LINK_CREATE,
115115 BPF_LINK_UPDATE,
116+ BPF_LINK_GET_FD_BY_ID,
117+ BPF_LINK_GET_NEXT_ID,
116118 };
117119
118120 enum bpf_map_type {