This commit explains how to manually compile the C source file
tap_bpf_program.c into an ELF file using the clang compiler.
The code in tap_bpf_program.c requires definitions found in iproute2
source code. This commit suggests cloning the iproute2 git tree and
include its path in the clang command. It also adds inclusion of file
bpf_api.h (required for eBPF definitions) which is located in iproute2
source tree. For more details refer to TAP documentation.
This commit is related to commits [1] and [2].

[1] commit cdc07e83bb24 ("net/tap: add eBPF program file")
[2] commit aabe70df73a3 ("net/tap: add eBPF bytes code")

Signed-off-by: Ophir Munk <ophi...@mellanox.com>
---
 doc/guides/nics/tap.rst           | 21 +++++++++++++++++----
 drivers/net/tap/tap_bpf_program.c |  5 +++++
 2 files changed, 22 insertions(+), 4 deletions(-)

diff --git a/doc/guides/nics/tap.rst b/doc/guides/nics/tap.rst
index 2714868..af6c534 100644
--- a/doc/guides/nics/tap.rst
+++ b/doc/guides/nics/tap.rst
@@ -234,13 +234,26 @@ C functions under different ELF sections.
 
 2. Install ``LLVM`` library and ``clang`` compiler versions 3.7 and above
 
-3. Compile ``tap_bpf_program.c`` via ``LLVM`` into an object file::
+3. The code in ``tap_bpf_program.c`` requires definitions found in iproute2
+source code.
 
-    clang -O2 -emit-llvm -c tap_bpf_program.c -o - | llc -march=bpf \
-    -filetype=obj -o <tap_bpf_program.o>
+Clone the iproute2 git tree and make it accessible to the build environment, 
say
+under directory ``<iproute2_root_tree>`` ::
+
+    git clone https://git.kernel.org/pub/scm/network/iproute2/iproute2.git/ \
+    <iproute2_root_tree>
+
+The code in ``tap_bpf_program.c`` must include file ``bpf_api.h`` which is
+located under ``<iproute2_root_tree>`` directory. This file contains eBPF
+related definitions.
 
+4. Compile ``tap_bpf_program.c`` via ``LLVM`` into an object file::
+
+    clang -I <iproute2_root_tree>/iproute2/include \
+    -O2 -emit-llvm -c tap_bpf_program.c -o - | llc -march=bpf \
+    -filetype=obj -o <tap_bpf_program.o>
 
-4. Use a tool that receives two parameters: an eBPF object file and a section
+5. Use a tool that receives two parameters: an eBPF object file and a section
 name, and prints out the section as a C array of eBPF instructions.
 Embed the C array in your TAP PMD tree.
 
diff --git a/drivers/net/tap/tap_bpf_program.c 
b/drivers/net/tap/tap_bpf_program.c
index 1cb7382..60b069b 100644
--- a/drivers/net/tap/tap_bpf_program.c
+++ b/drivers/net/tap/tap_bpf_program.c
@@ -17,6 +17,11 @@
 #include <linux/bpf.h>
 
 #include "tap_rss.h"
+/*
+ * bpf_api.h file is located under iproute2
+ * tree, see TAP documentation.
+ */
+#include "bpf_api.h"
 
 /** Create IPv4 address */
 #define IPv4(a, b, c, d) ((__u32)(((a) & 0xff) << 24) | \
-- 
1.8.3.1

Reply via email to