bpf_xdp_redirect_map: Perform map lookup in eBPF helper
authorToke Høiland-Jørgensen <toke@redhat.com>
Fri, 28 Jun 2019 09:12:34 +0000 (11:12 +0200)
committerDaniel Borkmann <daniel@iogearbox.net>
Fri, 28 Jun 2019 23:31:09 +0000 (01:31 +0200)
commit43e74c0267a35d6f5127218054b2d80c7fe801f5
tree8d2445e0be167139975629e9eb604c3506ee0164
parent4b55cf290dc6bd3a9e5da26d1ad60e77aa88c8cf
bpf_xdp_redirect_map: Perform map lookup in eBPF helper

The bpf_redirect_map() helper used by XDP programs doesn't return any
indication of whether it can successfully redirect to the map index it was
given. Instead, BPF programs have to track this themselves, leading to
programs using duplicate maps to track which entries are populated in the
devmap.

This patch fixes this by moving the map lookup into the bpf_redirect_map()
helper, which makes it possible to return failure to the eBPF program. The
lower bits of the flags argument is used as the return code, which means
that existing users who pass a '0' flag argument will get XDP_ABORTED.

With this, a BPF program can check the return code from the helper call and
react by, for instance, substituting a different redirect. This works for
any type of map used for redirect.

Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com>
Acked-by: Jonathan Lemon <jonathan.lemon@gmail.com>
Acked-by: Andrii Nakryiko <andriin@fb.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
include/linux/filter.h
include/trace/events/xdp.h
include/uapi/linux/bpf.h
net/core/filter.c