Generate ID for each bpf_link using IDR, similarly to bpf_map and bpf_prog. bpf_link creation, initialization, attachment, and exposing to user-space through FD and ID is a complicated multi-step process, abstract it away through bpf_link_primer and bpf_link_prime(), bpf_link_settle(), and bpf_link_cleanup() internal API. They guarantee that until bpf_link is properly attached, user-space won't be able to access partially-initialized bpf_link either from FD or ID. All this allows to simplify bpf_link attachment and error handling code.
Showing the changes to include/uapi/linux (1 of 4 files). Show all
Unified · Split
| @@ -523,6 +523,7 @@ union bpf_attr { · 522 unmodified lines | |||
| 523 | __u32 prog_id; | 523 | __u32 prog_id; |
| 524 | __u32 map_id; | 524 | __u32 map_id; |
| 525 | __u32 btf_id; | 525 | __u32 btf_id; |
| 526 | __u32 link_id; | ||
| 526 | }; | 527 | }; |
| 527 | __u32 next_id; | 528 | __u32 next_id; |
| 528 | __u32 open_flags; | 529 | __u32 open_flags; |