Skip to content

Commit 29f24c4

Browse files
Niklas Söderlundanakryiko
authored andcommitted
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 <[email protected]> Signed-off-by: Simon Horman <[email protected]> Signed-off-by: Andrii Nakryiko <[email protected]> Reviewed-by: Louis Peens <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent 579345e commit 29f24c4

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

samples/bpf/xdpsock_user.c

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
// SPDX-License-Identifier: GPL-2.0
22
/* Copyright(c) 2017 - 2018 Intel Corporation. */
33

4-
#include <asm/barrier.h>
54
#include <errno.h>
65
#include <getopt.h>
76
#include <libgen.h>
87
#include <linux/bpf.h>
9-
#include <linux/compiler.h>
108
#include <linux/if_link.h>
119
#include <linux/if_xdp.h>
1210
#include <linux/if_ether.h>
@@ -663,7 +661,7 @@ __sum16 ip_fast_csum(const void *iph, unsigned int ihl);
663661
*/
664662
__sum16 ip_fast_csum(const void *iph, unsigned int ihl)
665663
{
666-
return (__force __sum16)~do_csum(iph, ihl * 4);
664+
return (__sum16)~do_csum(iph, ihl * 4);
667665
}
668666

669667
/*
@@ -673,11 +671,11 @@ __sum16 ip_fast_csum(const void *iph, unsigned int ihl)
673671
*/
674672
static inline __sum16 csum_fold(__wsum csum)
675673
{
676-
u32 sum = (__force u32)csum;
674+
u32 sum = (u32)csum;
677675

678676
sum = (sum & 0xffff) + (sum >> 16);
679677
sum = (sum & 0xffff) + (sum >> 16);
680-
return (__force __sum16)~sum;
678+
return (__sum16)~sum;
681679
}
682680

683681
/*
@@ -703,16 +701,16 @@ __wsum csum_tcpudp_nofold(__be32 saddr, __be32 daddr,
703701
__wsum csum_tcpudp_nofold(__be32 saddr, __be32 daddr,
704702
__u32 len, __u8 proto, __wsum sum)
705703
{
706-
unsigned long long s = (__force u32)sum;
704+
unsigned long long s = (u32)sum;
707705

708-
s += (__force u32)saddr;
709-
s += (__force u32)daddr;
706+
s += (u32)saddr;
707+
s += (u32)daddr;
710708
#ifdef __BIG_ENDIAN__
711709
s += proto + len;
712710
#else
713711
s += (proto + len) << 8;
714712
#endif
715-
return (__force __wsum)from64to32(s);
713+
return (__wsum)from64to32(s);
716714
}
717715

718716
/*

0 commit comments

Comments
 (0)