[PATCH 4/5] samples/bpf: fix tracex5_user build error
From: Matteo Croce
Date: Fri May 17 2019 - 20:49:30 EST
Add missing symbols to tools/include/linux/filter.h to fix a build failure:
make -C samples/bpf/../../tools/lib/bpf/ RM='rm -rf' LDFLAGS= srctree=samples/bpf/../../ O=
HOSTCC samples/bpf/tracex5_user.o
samples/bpf/tracex5_user.c: In function âinstall_accept_all_seccompâ:
samples/bpf/tracex5_user.c:17:21: error: array type has incomplete element type âstruct sock_filterâ
17 | struct sock_filter filter[] = {
| ^~~~~~
samples/bpf/tracex5_user.c:18:3: warning: implicit declaration of function âBPF_STMTâ; did you mean âBPF_STXâ? [-Wimplicit-function-declaration]
18 | BPF_STMT(BPF_RET+BPF_K, SECCOMP_RET_ALLOW),
| ^~~~~~~~
| BPF_STX
samples/bpf/tracex5_user.c:20:9: error: variable âprogâ has initializer but incomplete type
20 | struct sock_fprog prog = {
| ^~~~~~~~~~
samples/bpf/tracex5_user.c:21:4: error: âstruct sock_fprogâ has no member named âlenâ
21 | .len = (unsigned short)(sizeof(filter)/sizeof(filter[0])),
| ^~~
samples/bpf/tracex5_user.c:21:10: warning: excess elements in struct initializer
21 | .len = (unsigned short)(sizeof(filter)/sizeof(filter[0])),
| ^
samples/bpf/tracex5_user.c:21:10: note: (near initialization for âprogâ)
samples/bpf/tracex5_user.c:22:4: error: âstruct sock_fprogâ has no member named âfilterâ
22 | .filter = filter,
| ^~~~~~
samples/bpf/tracex5_user.c:22:13: warning: excess elements in struct initializer
22 | .filter = filter,
| ^~~~~~
samples/bpf/tracex5_user.c:22:13: note: (near initialization for âprogâ)
samples/bpf/tracex5_user.c:20:20: error: storage size of âprogâ isnât known
20 | struct sock_fprog prog = {
| ^~~~
samples/bpf/tracex5_user.c:20:20: warning: unused variable âprogâ [-Wunused-variable]
samples/bpf/tracex5_user.c:17:21: warning: unused variable âfilterâ [-Wunused-variable]
17 | struct sock_filter filter[] = {
| ^~~~~~
make[2]: *** [scripts/Makefile.host:109: samples/bpf/tracex5_user.o] Error 1
make[1]: *** [Makefile:1763: samples/bpf/] Error 2
Signed-off-by: Matteo Croce <mcroce@xxxxxxxxxx>
---
tools/include/linux/filter.h | 27 +++++++++++++++++++++++++++
1 file changed, 27 insertions(+)
diff --git a/tools/include/linux/filter.h b/tools/include/linux/filter.h
index ca28b6ab8db7..6b2ed7eccfa5 100644
--- a/tools/include/linux/filter.h
+++ b/tools/include/linux/filter.h
@@ -7,6 +7,33 @@
#include <linux/bpf.h>
+/*
+ * Try and keep these values and structures similar to BSD, especially
+ * the BPF code definitions which need to match so you can share filters
+ */
+
+struct sock_filter { /* Filter block */
+ __u16 code; /* Actual filter code */
+ __u8 jt; /* Jump true */
+ __u8 jf; /* Jump false */
+ __u32 k; /* Generic multiuse field */
+};
+
+struct sock_fprog { /* Required for SO_ATTACH_FILTER. */
+ unsigned short len; /* Number of filter blocks */
+ struct sock_filter __user *filter;
+};
+
+/*
+ * Macros for filter block array initializers.
+ */
+#ifndef BPF_STMT
+#define BPF_STMT(code, k) { (unsigned short)(code), 0, 0, k }
+#endif
+#ifndef BPF_JUMP
+#define BPF_JUMP(code, k, jt, jf) { (unsigned short)(code), jt, jf, k }
+#endif
+
/* ArgX, context and stack frame pointer register positions. Note,
* Arg1, Arg2, Arg3, etc are used as argument mappings of function
* calls in BPF_CALL instruction.
--
2.21.0