aboutsummaryrefslogtreecommitdiffstats
path: root/tools/testing/selftests/bpf/test_verifier.c
diff options
context:
space:
mode:
authorJoe Stringer <joe@wand.net.nz>2018-10-02 13:35:36 -0700
committerDaniel Borkmann <daniel@iogearbox.net>2018-10-03 02:53:47 +0200
commit6acc9b432e6714d72d7d77ec7c27f6f8358d0c71 (patch)
tree1b5ac6b607e8d88a815c8b88d795e71a18260f31 /tools/testing/selftests/bpf/test_verifier.c
parentbpf: Add reference tracking to verifier (diff)
downloadlinux-dev-6acc9b432e6714d72d7d77ec7c27f6f8358d0c71.tar.xz
linux-dev-6acc9b432e6714d72d7d77ec7c27f6f8358d0c71.zip
bpf: Add helper to retrieve socket in BPF
This patch adds new BPF helper functions, bpf_sk_lookup_tcp() and bpf_sk_lookup_udp() which allows BPF programs to find out if there is a socket listening on this host, and returns a socket pointer which the BPF program can then access to determine, for instance, whether to forward or drop traffic. bpf_sk_lookup_xxx() may take a reference on the socket, so when a BPF program makes use of this function, it must subsequently pass the returned pointer into the newly added sk_release() to return the reference. By way of example, the following pseudocode would filter inbound connections at XDP if there is no corresponding service listening for the traffic: struct bpf_sock_tuple tuple; struct bpf_sock_ops *sk; populate_tuple(ctx, &tuple); // Extract the 5tuple from the packet sk = bpf_sk_lookup_tcp(ctx, &tuple, sizeof tuple, netns, 0); if (!sk) { // Couldn't find a socket listening for this traffic. Drop. return TC_ACT_SHOT; } bpf_sk_release(sk, 0); return TC_ACT_OK; Signed-off-by: Joe Stringer <joe@wand.net.nz> Acked-by: Alexei Starovoitov <ast@kernel.org> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Diffstat (limited to 'tools/testing/selftests/bpf/test_verifier.c')
0 files changed, 0 insertions, 0 deletions