History

libbpf: Add support for bpf_link-based cgroup attachment

Add bpf_program__attach_cgroup(), which uses BPF_LINK_CREATE subcommand to create an FD-based kernel bpf_link. Also add low-level bpf_link_create() API. If expected_attach_type is not specified explicitly with bpf_program__set_expected_attach_type(), libbpf will try to determine proper attach type from BPF program's section definition. Also add support for bpf_link's underlying BPF program replacement: - unconditional through high-level bpf_link__update_program() API; - cmpxchg-like with specifying expected current BPF program through low-level bpf_link_update() API.

Andrii Nakryiko committed 6 years ago

Commit cc4f8641 parent 0c991eb6 files · +122 −1Browse files

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

Unified · Split

tools/include/uapi/linux/bpf.h+12−0
@@ -112,6 +112,7 @@ enum bpf_cmd { · 111 unmodified lines
112 BPF_MAP_UPDATE_BATCH,112 BPF_MAP_UPDATE_BATCH,
113 BPF_MAP_DELETE_BATCH,113 BPF_MAP_DELETE_BATCH,
114 BPF_LINK_CREATE,114 BPF_LINK_CREATE,
115 BPF_LINK_UPDATE,
115};116};
116 117
117enum bpf_map_type {118enum bpf_map_type {
@@ -577,6 +578,17 @@ union bpf_attr { · 459 unmodified lines
577 __u32 attach_type; /* attach type */578 __u32 attach_type; /* attach type */
578 __u32 flags; /* extra flags */579 __u32 flags; /* extra flags */
579 } link_create;580 } link_create;
581
582 struct { /* struct used by BPF_LINK_UPDATE command */
583 __u32 link_fd; /* link fd */
584 /* new program fd to update link with */
585 __u32 new_prog_fd;
586 __u32 flags; /* extra flags */
587 /* expected link's program fd; is specified only if
588 * BPF_F_REPLACE flag is set in flags */
589 __u32 old_prog_fd;
590 } link_update;
591
580} __attribute__((aligned(8)));592} __attribute__((aligned(8)));
581 593
582/* The description below is an attempt at providing documentation to eBPF594/* The description below is an attempt at providing documentation to eBPF