samples/bpf: xdpsock: Make the sample more useful outside the tree
authorNiklas Söderlund <niklas.soderlund@corigine.com>
Fri, 6 Aug 2021 12:28:54 +0000 (14:28 +0200)
committerAndrii Nakryiko <andrii@kernel.org>
Fri, 6 Aug 2021 23:53:27 +0000 (16:53 -0700)
commit29f24c43cbe09b83162776a370848d5a782dc3b7
treeef9000e8598e56428ed9bb2aff253b13a37fa4a2
parent579345e7f2190c1ee97f44154526dcd458ea790d
samples/bpf: xdpsock: Make the sample more useful outside the tree

The xdpsock sample application is a useful base for experiment's around
AF_XDP sockets. Compiling the sample outside of the kernel tree is made
harder then it has to be as the sample includes two headers and that are
not installed by 'make install_header' nor are usually part of
distributions kernel headers.

The first header asm/barrier.h is not used and can just be dropped.

The second linux/compiler.h are only needed for the decorator __force
and are only used in ip_fast_csum(), csum_fold() and
csum_tcpudp_nofold(). These functions are copied verbatim from
include/asm-generic/checksum.h and lib/checksum.c. While it's fine to
copy and use these functions in the sample application the decorator
brings no value and can be dropped together with the include.

With this change it's trivial to compile the xdpsock sample outside the
kernel tree from xdpsock_user.c and xdpsock.h.

    $ gcc -o xdpsock xdpsock_user.c -lbpf -lpthread

Signed-off-by: Niklas Söderlund <niklas.soderlund@corigine.com>
Signed-off-by: Simon Horman <simon.horman@corigine.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Reviewed-by: Louis Peens <louis.peens@corigine.com>
Link: https://lore.kernel.org/bpf/20210806122855.26115-2-simon.horman@corigine.com
samples/bpf/xdpsock_user.c