TencentOS-kernel/tools
Jakub Sitnicki d045fee4f1 bpf: Add link-based BPF program attachment to network namespace
[upstream commit 7f045a49fee04b5662cbdeaf0838f9322ae8c63a]

Extend bpf() syscall subcommands that operate on bpf_link, that is
LINK_CREATE, LINK_UPDATE, OBJ_GET_INFO, to accept attach types tied to
network namespaces (only flow dissector at the moment).

Link-based and prog-based attachment can be used interchangeably, but only
one can exist at a time. Attempts to attach a link when a prog is already
attached directly, and the other way around, will be met with -EEXIST.
Attempts to detach a program when link exists result in -EINVAL.

Attachment of multiple links of same attach type to one netns is not
supported with the intention to lift the restriction when a use-case
presents itself. Because of that link create returns -E2BIG when trying to
create another netns link, when one already exists.

Link-based attachments to netns don't keep a netns alive by holding a ref
to it. Instead links get auto-detached from netns when the latter is being
destroyed, using a pernet pre_exit callback.

When auto-detached, link lives in defunct state as long there are open FDs
for it. -ENOLINK is returned if a user tries to update a defunct link.

Because bpf_link to netns doesn't hold a ref to struct net, special care is
taken when releasing, updating, or filling link info. The netns might be
getting torn down when any of these link operations are in progress. That
is why auto-detach and update/release/fill_info are synchronized by the
same mutex. Also, link ops have to always check if auto-detach has not
happened yet and if netns is still alive (refcnt > 0).

Signed-off-by: Jakub Sitnicki <jakub@cloudflare.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Link: https://lore.kernel.org/bpf/20200531082846.2117903-5-jakub@cloudflare.com
2022-08-30 11:33:23 +08:00
..
accounting Init Repo base on linux 5.4.32 long term, and add base tlinux kernel interfaces. 2021-03-16 11:01:34 +08:00
arch ia64: tools: remove duplicate definition of ia64_mf() on ia64 2021-05-20 16:07:15 +08:00
bpf bpftool: Fix compilation failure for net.o with older glibc 2021-04-12 12:51:19 +08:00
build tools: Factor HOSTCC, HOSTLD, HOSTAR definitions 2021-04-12 12:51:42 +08:00
cgroup iocost_monitor: drop string wrap around numbers when outputting json 2021-03-16 16:29:27 +08:00
debugging Init Repo base on linux 5.4.32 long term, and add base tlinux kernel interfaces. 2021-03-16 11:01:34 +08:00
firewire Init Repo base on linux 5.4.32 long term, and add base tlinux kernel interfaces. 2021-03-16 11:01:34 +08:00
firmware Init Repo base on linux 5.4.32 long term, and add base tlinux kernel interfaces. 2021-03-16 11:01:34 +08:00
gpio tools: gpio-hammer: Avoid potential overflow in main 2021-03-16 16:37:05 +08:00
hv Init Repo base on linux 5.4.32 long term, and add base tlinux kernel interfaces. 2021-03-16 11:01:34 +08:00
iio Init Repo base on linux 5.4.32 long term, and add base tlinux kernel interfaces. 2021-03-16 11:01:34 +08:00
include bpf: Add link-based BPF program attachment to network namespace 2022-08-30 11:33:23 +08:00
io_uring tools/io_uring: fix compile breakage 2021-03-16 16:37:47 +08:00
kvm/kvm_stat Init Repo base on linux 5.4.32 long term, and add base tlinux kernel interfaces. 2021-03-16 11:01:34 +08:00
laptop Init Repo base on linux 5.4.32 long term, and add base tlinux kernel interfaces. 2021-03-16 11:01:34 +08:00
leds Init Repo base on linux 5.4.32 long term, and add base tlinux kernel interfaces. 2021-03-16 11:01:34 +08:00
lib libbpf: Fix BTF dump of pointer-to-array-of-struct 2021-04-12 12:53:30 +08:00
memory-model Init Repo base on linux 5.4.32 long term, and add base tlinux kernel interfaces. 2021-03-16 11:01:34 +08:00
nfsd Init Repo base on linux 5.4.32 long term, and add base tlinux kernel interfaces. 2021-03-16 11:01:34 +08:00
objtool objtool: Fix ".cold" section suffix check for newer versions of GCC 2021-04-12 12:52:25 +08:00
pci Init Repo base on linux 5.4.32 long term, and add base tlinux kernel interfaces. 2021-03-16 11:01:34 +08:00
pcmcia Init Repo base on linux 5.4.32 long term, and add base tlinux kernel interfaces. 2021-03-16 11:01:34 +08:00
perf perf beauty: Fix fsconfig generator 2021-05-20 16:07:58 +08:00
power tools: Factor HOSTCC, HOSTLD, HOSTAR definitions 2021-04-12 12:51:42 +08:00
scripts tools: Factor HOSTCC, HOSTLD, HOSTAR definitions 2021-04-12 12:51:42 +08:00
spi Init Repo base on linux 5.4.32 long term, and add base tlinux kernel interfaces. 2021-03-16 11:01:34 +08:00
testing bpf, sockmap: Allow inserting listening TCP sockets into sockmap 2022-08-30 11:33:20 +08:00
thermal/tmon Init Repo base on linux 5.4.32 long term, and add base tlinux kernel interfaces. 2021-03-16 11:01:34 +08:00
time Init Repo base on linux 5.4.32 long term, and add base tlinux kernel interfaces. 2021-03-16 11:01:34 +08:00
usb usbip: tools: fix build error for multiple definition 2021-04-12 12:52:52 +08:00
virtio Init Repo base on linux 5.4.32 long term, and add base tlinux kernel interfaces. 2021-03-16 11:01:34 +08:00
vm tools/vm: fix cross-compile build 2021-03-16 16:26:57 +08:00
wmi Init Repo base on linux 5.4.32 long term, and add base tlinux kernel interfaces. 2021-03-16 11:01:34 +08:00
Makefile Init Repo base on linux 5.4.32 long term, and add base tlinux kernel interfaces. 2021-03-16 11:01:34 +08:00