libbpf: Auto-attach struct_ops BPF maps in BPF skeleton
authorMykyta Yatsenko <yatsenko@meta.com>
Wed, 5 Jun 2024 17:51:35 +0000 (18:51 +0100)
committerAndrii Nakryiko <andrii@kernel.org>
Thu, 6 Jun 2024 17:06:05 +0000 (10:06 -0700)
commit08ac454e258e38813afb906650f19acce3afd982
treed98f6e8a40758535eb8141f2575096b939ae8628
parentb24862bac7b5db326716ad07bbff7b6ee3b09a59
libbpf: Auto-attach struct_ops BPF maps in BPF skeleton

Similarly to `bpf_program`, support `bpf_map` automatic attachment in
`bpf_object__attach_skeleton`. Currently only struct_ops maps could be
attached.

On bpftool side, code-generate links in skeleton struct for struct_ops maps.
Similarly to `bpf_program_skeleton`, set links in `bpf_map_skeleton`.

On libbpf side, extend `bpf_map` with new `autoattach` field to support
enabling or disabling autoattach functionality, introducing
getter/setter for this field.

`bpf_object__(attach|detach)_skeleton` is extended with
attaching/detaching struct_ops maps logic.

Signed-off-by: Mykyta Yatsenko <yatsenko@meta.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/20240605175135.117127-1-yatsenko@meta.com
tools/bpf/bpftool/gen.c
tools/lib/bpf/libbpf.c
tools/lib/bpf/libbpf.h
tools/lib/bpf/libbpf.map