AltraMayor / gatekeeper

The first open-source DDoS protection system
https://github.com/AltraMayor/gatekeeper/wiki
GNU General Public License v3.0
1.3k stars 227 forks source link

bpf: one cannot compile BPFs that include rte_mbuf_core.h #672

Open AltraMayor opened 8 months ago

AltraMayor commented 8 months ago

A BPF needs to include the header <rte_mbuf_core.h> to access struct rte_mbuf. But the current version of the header <rte_mbuf_core.h> cannot be included in a BPF. This bug is present in the latest DPDK (i.e. 23.11) and a bug report has been filed.

Here's the error one gets while compiling the BPFs included with Gatekeeper:

~/gatekeeper/bpf$ make
clang -O2 -g -target bpf -I../include -Wall -Wextra -Wno-int-to-void-pointer-cast -o granted.bpf -c granted.c
In file included from granted.c:29:
In file included from /usr/local/include/rte_mbuf_core.h:21:
/usr/local/include/rte_byteorder.h:31:16: error: invalid output constraint '=Q' in asm
                      : [x1] "=Q" (x)
                             ^
1 error generated.
make: *** [Makefile:17: granted.bpf] Error 1
AltraMayor commented 8 months ago

The following patch works around the bug while the problem is being fixed in DPDK:

diff --git a/bpf/Makefile b/bpf/Makefile
index d98f52b..c426214 100644
--- a/bpf/Makefile
+++ b/bpf/Makefile
@@ -14,7 +14,7 @@ copy: all
        $(INSTALL) -m660 $(TARGETS) $(DESTDIR)

 %.bpf: %.c
-       $(CC) $(CFLAGS) -o $@ -c $^
+       $(CC) $(CFLAGS) -o $@ -D RTE_FORCE_INTRINSICS -c $^

 PHONY: cscope clean

This workaround is based on Tyler Retzlaff's comment.

AltraMayor commented 6 months ago

Pull request #680 has applied the workaround. We are going to wait for DPDK to fix the issue upstream before removing the workaround.