linux/samples/bpf
Martin KaFai Lau 90e02896f1 bpf: Add test for bpf_redirect to ipip/ip6tnl
The test creates two netns, ns1 and ns2.  The host (the default netns)
has an ipip or ip6tnl dev configured for tunneling traffic to the ns2.

    ping VIPS from ns1 <----> host <--tunnel--> ns2 (VIPs at loopback)

The test is to have ns1 pinging VIPs configured at the loopback
interface in ns2.

The VIPs are 10.10.1.102 and 2401:face::66 (which are configured
at lo@ns2). [Note: 0x66 => 102].

At ns1, the VIPs are routed _via_ the host.

At the host, bpf programs are installed at the veth to redirect packets
from a veth to the ipip/ip6tnl.  The test is configured in a way so
that both ingress and egress can be tested.

At ns2, the ipip/ip6tnl dev is configured with the local and remote address
specified.  The return path is routed to the dev ipip/ip6tnl.

During egress test, the host also locally tests pinging the VIPs to ensure
that bpf_redirect at egress also works for the direct egress (i.e. not
forwarding from dev ve1 to ve2).

Acked-by: Alexei Starovoitov <ast@fb.com>
Signed-off-by: Martin KaFai Lau <kafai@fb.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2016-11-12 23:38:07 -05:00
..
Makefile bpf: Add test for bpf_redirect to ipip/ip6tnl 2016-11-12 23:38:07 -05:00
README.rst
bpf_helpers.h samples/bpf: add perf_event+bpf example 2016-09-02 10:46:45 -07:00
bpf_load.c samples/bpf: add perf_event+bpf example 2016-09-02 10:46:45 -07:00
bpf_load.h
fds_example.c
lathist_kern.c
lathist_user.c
libbpf.c
libbpf.h bpf: allow access into map value arrays 2016-09-29 01:35:35 -04:00
map_perf_test_kern.c
map_perf_test_user.c
offwaketime_kern.c
offwaketime_user.c
parse_ldabs.c bpf: fix samples to add fake KBUILD_MODNAME 2016-10-29 14:46:12 -04:00
parse_simple.c bpf: fix samples to add fake KBUILD_MODNAME 2016-10-29 14:46:12 -04:00
parse_varlen.c bpf: fix samples to add fake KBUILD_MODNAME 2016-10-29 14:46:12 -04:00
sampleip_kern.c samples/bpf: add sampleip example 2016-09-02 10:46:45 -07:00
sampleip_user.c samples/bpf: add sampleip example 2016-09-02 10:46:45 -07:00
sock_example.c
sockex1_kern.c
sockex1_user.c
sockex2_kern.c bpf samples: fix compiler errors with sockex2 and sockex3 2016-09-27 03:48:58 -04:00
sockex2_user.c
sockex3_kern.c bpf samples: fix compiler errors with sockex2 and sockex3 2016-09-27 03:48:58 -04:00
sockex3_user.c bpf samples: fix compiler errors with sockex2 and sockex3 2016-09-27 03:48:58 -04:00
spintest_kern.c
spintest_user.c
tc_l2_redirect.sh bpf: Add test for bpf_redirect to ipip/ip6tnl 2016-11-12 23:38:07 -05:00
tc_l2_redirect_kern.c bpf: Add test for bpf_redirect to ipip/ip6tnl 2016-11-12 23:38:07 -05:00
tc_l2_redirect_user.c bpf: Add test for bpf_redirect to ipip/ip6tnl 2016-11-12 23:38:07 -05:00
tcbpf1_kern.c bpf: fix samples to add fake KBUILD_MODNAME 2016-10-29 14:46:12 -04:00
tcbpf2_kern.c bpf: fix samples to add fake KBUILD_MODNAME 2016-10-29 14:46:12 -04:00
test_cgrp2_array_pin.c
test_cgrp2_tc.sh
test_cgrp2_tc_kern.c bpf: fix samples to add fake KBUILD_MODNAME 2016-10-29 14:46:12 -04:00
test_cls_bpf.sh
test_current_task_under_cgroup_kern.c samples/bpf: Add test_current_task_under_cgroup test 2016-08-12 21:49:42 -07:00
test_current_task_under_cgroup_user.c samples/bpf: Add test_current_task_under_cgroup test 2016-08-12 21:49:42 -07:00
test_ipip.sh samples/bpf: add comprehensive ipip, ipip6, ip6ip6 test 2016-09-17 10:13:07 -04:00
test_maps.c samples/bpf: add bpf_map_update_elem() tests 2016-08-06 20:49:19 -04:00
test_overhead_kprobe_kern.c
test_overhead_tp_kern.c
test_overhead_user.c
test_probe_write_user_kern.c samples/bpf: Add test/example of using bpf_probe_write_user bpf helper 2016-07-25 18:07:48 -07:00
test_probe_write_user_user.c samples/bpf: Add test/example of using bpf_probe_write_user bpf helper 2016-07-25 18:07:48 -07:00
test_tunnel_bpf.sh samples/bpf: extend test_tunnel_bpf.sh with IPIP test 2016-09-17 10:13:07 -04:00
test_verifier.c bpf: allow access into map value arrays 2016-09-29 01:35:35 -04:00
trace_event_kern.c samples/bpf: add perf_event+bpf example 2016-09-02 10:46:45 -07:00
trace_event_user.c samples/bpf: add perf_event+bpf example 2016-09-02 10:46:45 -07:00
trace_output_kern.c
trace_output_user.c
tracex1_kern.c
tracex1_user.c
tracex2_kern.c
tracex2_user.c
tracex3_kern.c
tracex3_user.c
tracex4_kern.c
tracex4_user.c
tracex5_kern.c bpf samples: update tracex5 sample to use __seccomp_filter 2016-09-27 03:48:58 -04:00
tracex5_user.c bpf samples: update tracex5 sample to use __seccomp_filter 2016-09-27 03:48:58 -04:00
tracex6_kern.c
tracex6_user.c
xdp1_kern.c bpf: make xdp sample variable names more meaningful 2016-07-20 22:07:24 -07:00
xdp1_user.c
xdp2_kern.c bpf: make xdp sample variable names more meaningful 2016-07-20 22:07:24 -07:00

README.rst

eBPF sample programs
====================

This directory contains a mini eBPF library, test stubs, verifier
test-suite and examples for using eBPF.

Build dependencies
==================

Compiling requires having installed:
 * clang >= version 3.4.0
 * llvm >= version 3.7.1

Note that LLVM's tool 'llc' must support target 'bpf', list version
and supported targets with command: ``llc --version``

Kernel headers
--------------

There are usually dependencies to header files of the current kernel.
To avoid installing devel kernel headers system wide, as a normal
user, simply call::

 make headers_install

This will creates a local "usr/include" directory in the git/build top
level directory, that the make system automatically pickup first.

Compiling
=========

For building the BPF samples, issue the below command from the kernel
top level directory::

 make samples/bpf/

Do notice the "/" slash after the directory name.

It is also possible to call make from this directory.  This will just
hide the the invocation of make as above with the appended "/".

Manually compiling LLVM with 'bpf' support
------------------------------------------

Since version 3.7.0, LLVM adds a proper LLVM backend target for the
BPF bytecode architecture.

By default llvm will build all non-experimental backends including bpf.
To generate a smaller llc binary one can use::

 -DLLVM_TARGETS_TO_BUILD="BPF"

Quick sniplet for manually compiling LLVM and clang
(build dependencies are cmake and gcc-c++)::

 $ git clone http://llvm.org/git/llvm.git
 $ cd llvm/tools
 $ git clone --depth 1 http://llvm.org/git/clang.git
 $ cd ..; mkdir build; cd build
 $ cmake .. -DLLVM_TARGETS_TO_BUILD="BPF;X86"
 $ make -j $(getconf _NPROCESSORS_ONLN)

It is also possible to point make to the newly compiled 'llc' or
'clang' command via redefining LLC or CLANG on the make command line::

 make samples/bpf/ LLC=~/git/llvm/build/bin/llc CLANG=~/git/llvm/build/bin/clang