DPDK patches and discussions
 help / color / mirror / Atom feed
* [dpdk-dev] [PATCH v1] net/tap: explain how to compile eBPF C file
@ 2018-06-11 16:06 Ophir Munk
       [not found] ` <A1755B7A-CDB5-4A55-9B44-9C9DEFDA9C88@intel.com>
  0 siblings, 1 reply; 12+ messages in thread
From: Ophir Munk @ 2018-06-11 16:06 UTC (permalink / raw)
  To: dev, Pascal Mazon, Keith Wiles; +Cc: Thomas Monjalon, Olga Shern, Ophir Munk

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 <ophirmu@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

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2018-08-23 12:10 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-06-11 16:06 [dpdk-dev] [PATCH v1] net/tap: explain how to compile eBPF C file Ophir Munk
     [not found] ` <A1755B7A-CDB5-4A55-9B44-9C9DEFDA9C88@intel.com>
2018-06-12 12:26   ` Thomas Monjalon
2018-06-12 12:36     ` Wiles, Keith
2018-06-12 12:58       ` Thomas Monjalon
2018-06-12 13:33         ` Wiles, Keith
2018-06-12 13:44           ` Thomas Monjalon
2018-06-12 13:52             ` Wiles, Keith
2018-06-12 14:02               ` Ophir Munk
2018-07-04 19:47                 ` Ferruh Yigit
2018-07-04 20:11                   ` Thomas Monjalon
2018-07-05 12:34                     ` Wiles, Keith
2018-08-23 12:09                       ` Ferruh Yigit

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).